diff options
author | Anton Luka Šijanec <anton@sijanec.eu> | 2021-09-16 20:43:23 +0200 |
---|---|---|
committer | Anton Luka Šijanec <anton@sijanec.eu> | 2021-09-16 20:43:23 +0200 |
commit | 05a742b954d69b78e41d95ec2d5d07d127712cd5 (patch) | |
tree | aaf6f55b3f51f8421b43129bf7b73c1068c41975 /src | |
parent | added json parsing mechanism (diff) | |
download | discord.c-05a742b954d69b78e41d95ec2d5d07d127712cd5.tar discord.c-05a742b954d69b78e41d95ec2d5d07d127712cd5.tar.gz discord.c-05a742b954d69b78e41d95ec2d5d07d127712cd5.tar.bz2 discord.c-05a742b954d69b78e41d95ec2d5d07d127712cd5.tar.lz discord.c-05a742b954d69b78e41d95ec2d5d07d127712cd5.tar.xz discord.c-05a742b954d69b78e41d95ec2d5d07d127712cd5.tar.zst discord.c-05a742b954d69b78e41d95ec2d5d07d127712cd5.zip |
Diffstat (limited to '')
-rw-r--r-- | src/api.c | 20 | ||||
-rw-r--r-- | src/h.c | 2 |
2 files changed, 20 insertions, 2 deletions
@@ -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 */); @@ -323,6 +323,7 @@ struct dc_user { unsigned long long int id; short int discriminator; enum dc_status status; + char * path; /* yesfree, internal, so parser knows what object this user is from */ }; struct dc_user * dc_user_init () { struct dc_user * s = calloc(1, sizeof(*s)); @@ -332,6 +333,7 @@ void dc_user_free (struct dc_user * s) { if (!s) return; free(s->username); + free(s->path); free(s); } struct dc_permission { /* permissions can be individual on a per-channel basis */ |