summaryrefslogtreecommitdiffstats
path: root/src/api.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/api.c20
1 files changed, 18 insertions, 2 deletions
diff --git a/src/api.c b/src/api.c
index ead58df..d76393b 100644
--- a/src/api.c
+++ b/src/api.c
@@ -23,6 +23,8 @@ void dc_api_stack (struct dc_api_io i) { /* stack output struct to be delivered
signed char dc_json_cb (struct lejp_ctx * ctx, char /* enum lejp_callbacks */ reason) {
enum dc_json_paths path = ctx->path_match-1; /* we assume that the order of incoming data is */
struct dc_lws_pass * pass = ctx->user; /* correct. op should come first, etc. */
+ char * cp;
+ char buf[LEJP_MAX_PATH+1];
pass->json_reason = reason;
if (reason == LEJPCB_FAILED) {
DC_API_IO_GC(pass->api_io);
@@ -56,13 +58,27 @@ signed char dc_json_cb (struct lejp_ctx * ctx, char /* enum lejp_callbacks */ re
return '\0';
}
*pass->parsing_status &= ~DC_IN_PROGRESS;
- pass->api_io.status |= DC_FROM_LWS; /* we callback on FAILED too, so that we don't */
- // dc_api_io(pass->api_io); /* end up with a memory leak if we allocated a struct */
+ pass->api_io.status |= DC_FROM_LWS;
+ // dc_api_io(pass->api_io); /* not implemented, still testing */
pass->api_io.status &= ~DC_FROM_LWS;
pass->parsing_status = NULL;
pass->packet = DC_NONE;
return '\0';
}
+#define DC_IF_NO_INIT(m) if (!pass->api_io.m) if ((pass->api_io.m = dc_##m##_init()) && (pass->api_io.m->path = strdup(ctx->path)) && (cp = strrchr(pass->api_io.m->path, '.'))) cp[0] = '\0';
+#define DC_IF_PATH_MATCHES(m) if (pass->api_io.m && pass->api_io.m->path && strcpy(buf, ctx->path) && (cp = strrchr(buf, '.')) && (cp[0] = '\0') && !strcmp(pass->api_io.m->path, buf))
+ if (reason & LEJP_FLAG_CB_IS_VALUE) {
+ if (strstr(ctx->path, ".username")) { /* checking properties of user objects */
+ DC_IF_NO_INIT(user);
+ pass->api_io.user->username = strdup(ctx->buf);
+ } else if (strstr(ctx->path, ".discriminator")) {
+ DC_IF_NO_INIT(user);
+ pass->api_io.user->discriminator = atoi(ctx->buf);
+ } else DC_IF_PATH_MATCHES(user) {
+ if (strstr(ctx->path, ".id"))
+ pass->api_io.user->discriminator = strtoull(ctx->buf, NULL, 10);
+ } else if (strstr(ctx->path, ""))
+ }
switch (pass->packet) { /* we fill in structs, set DC_INCOMPLETE and pass->parsing_status */
case DC_PING:
dc_handle_ping(pass->api_io, pass /* this is just so it's not NULL */);