summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/api.c28
-rw-r--r--src/h.c37
2 files changed, 38 insertions, 27 deletions
diff --git a/src/api.c b/src/api.c
index 32a2058..c5fb0b3 100644
--- a/src/api.c
+++ b/src/api.c
@@ -227,7 +227,7 @@ static int dc_lws_cb (struct lws * wsi, enum lws_callback_reasons rs, void * us,
fprintf(stdout, "%.*s", len, (const unsigned char *) in);
char * serialized = dc_json(pass->json, in, len);
while (serialized) {
- cJSON * obj, * obje, * json = cJSON_Parse(serialized);
+ cJSON * ob, * obj, * obje, * json = cJSON_Parse(serialized);
char * st;
if (getenv("DC_J")) {
st = cJSON_Print(json);
@@ -291,8 +291,10 @@ static int dc_lws_cb (struct lws * wsi, enum lws_callback_reasons rs, void * us,
ch->type = cJSON_GNV(cJSON_GOI(obj, "type"));
ch->id = strtoull(cJSON_GSV(cJSON_GOI(obj, "id")), NULL, 10);
cJSON_AFE(obje, cJSON_GOI(obj, "recipient_ids")) {
+ if (!(st = cJSON_GSV(obje)))
+ continue;
struct dc_user * part = dc_user_init();
- part->username = strdup("Private channel recipient");
+ part->id = strtoull(st, NULL, 10);
part = dc_add_user(
DC_ISAE(pass->api_io.program->users),
/* no replace here. stored user can be better. */ part, DC_MAY_FREE);
@@ -304,23 +306,27 @@ static int dc_lws_cb (struct lws * wsi, enum lws_callback_reasons rs, void * us,
/* replace here. ours is better - fresher. */ DC_MAY_FREE | DC_REPLACE | DC_INCOMPLETE);
ch->guild = pass->api_io.client->guilds[0];
}
- cJSON_AFE(obj, cJSON_GOI2(json, "d", "merged_members"))
+ cJSON_AFE(ob, cJSON_GOI2(json, "d", "merged_members")) {
+ obj = cJSON_GetArrayItem(ob, 0);
+ if (!cJSON_GAS(cJSON_GOI(obj, "roles")))
+ continue;
+ struct dc_user * user = dc_user_init();
+ user->id = strtoull(cJSON_GSV(cJSON_GOI(obj, "user_id")),
+ NULL, 10);
+ user = dc_addr_user(
+ DC_ISAE(pass->api_io.program->users), user,
+ /* again, no replace here, only ID */ DC_MAY_FREE);
cJSON_AFE(obje, cJSON_GOI(obj, "roles")) {
if (!(st = cJSON_GSV(obje)))
continue;
struct dc_role * role = dc_role_init();
role->id = strtoull(st, NULL, 10);
- role = dc_add_role(
+ role = dc_addr_role(
DC_ISAE(pass->api_io.program->roles),
role, DC_MAY_FREE);
- struct dc_user * user = dc_user_init();
- user->id = strtoull(cJSON_GSV(cJSON_GOI(
- obj, "user_id")), NULL, 10);
- user = dc_add_user(
- DC_ISAE(pass->api_io.program->users),
- /* again, no replace here, because we only have ID */ user, DC_MAY_FREE);
- /* role may have users */ dc_add_user(DC_ISAE(role->users), user, DC_UNSET);
+ /* role may have users. NO FREE! */ dc_add_user(DC_ISAE(role->users), user, DC_UNSET);
}
+ }
cJSON_Delete(json);
json = NULL;
serialized = dc_json(pass->json, NULL, 0);
diff --git a/src/h.c b/src/h.c
index ae6c8e0..8713d9d 100644
--- a/src/h.c
+++ b/src/h.c
@@ -1,24 +1,24 @@
/* ISAs: _sizeof means size of array, _length means usable/initialized members in array */
-#define DC_ISA(type, name) type ** name; size_t name##_sizeof; size_t name##_length /* in struct array */
+#define DC_ISA(type, name) type ** name; size_t name##_sizeof; size_t name##_length /* struct arr */
#define DC_ALLOC_CHUNK 1
#define DC_REALLOC_K 1.5
#define DC_BIGGER_ARRAY(name) do { /* unlike in previous programs, _BIGGER_ARRAY */ \
name = realloc(name, sizeof(name[0])*ceil(name##_sizeof*DC_REALLOC_K)); \
- for (int DC_BIGGER_ARRAY_i = name##_sizeof; DC_BIGGER_ARRAY_i < ceil(name##_sizeof*DC_REALLOC_K); DC_BIGGER_ARRAY_i++) \
- name[DC_BIGGER_ARRAY_i] = NULL; \
+ for (int DC_BA = name##_sizeof; DC_BA < ceil(name##_sizeof*DC_REALLOC_K); DC_BA++) \
+ name[DC_BA] = NULL; \
name##_sizeof = ceil(name##_sizeof*DC_REALLOC_K); /* no longer initializes */ \
} while (0) /* note that sizeof(name[0]) does not dereferencec name */
#define DC_MR(n) if (n##_sizeof <= n##_length) /* make room */ \
DC_BIGGER_ARRAY(n)
#define DC_STRUCT_PREFIX void * data; /* some user data to be kind to api library users ... */
#define DC_TRANSFER_PREFIX if (!n->data) { \
- n->data = o->data; \
- o->data = NULL; \
- } /* ... and what happens with this data with _transfer_ */
-#define DC_LWS_BUF 65535 /* 2^16 SMALL FUCKING HINT: ^ je XOR operator v C (in povsod drugje) */
+ n->data = o->data; \
+/* | | */ o->data = NULL; \
+/* V KEEP LOW! is on stack V */ } /* ... and what happens with this data with _transfer_ */
+#define DC_LWS_BUF 65536 /* don't worry. larger payloads still work and are joined by dc_json */
#define DC_LWS_MAX_RX DC_LWS_BUF /* max bytes a websocket may handle in a single receive */
-#define DC_LWS_MAX_FD 64 /* max file descriptors LWS will have open. if unset, LWS acquires all unused */
-#define DC_LWS_MAX_HEADER_LENGTH 64 /* _MAX_HEADER_LENGTH*_HEADERS_LENGTH is allocated for every reque */
+#define DC_LWS_MAX_FD 64 /* max file descriptors LWS will open. unset: LWS acquires all unused */
+#define DC_LWS_MAX_HEADER_LENGTH 64 /* _MAX_HEADER_LENGTH*_HEADERS_LENGTH is allocated on request */
#define DC_WS_PING_FORMAT "{\"op\":1,\"d\":%lld}"
#define DC_ID2TIME(x) ((x >> 22 /* this gives us ms since 2015 */)/1000 + 1420070400 /* UNIX 2015 */)
#ifdef DC_UI_GTK
@@ -429,6 +429,7 @@ struct dc_client {
struct dc_guild {
DC_STRUCT_PREFIX
char * name; /* yesfree */
+ char * description; /* yesfree */
unsigned long long int id; /* 0 for virtual DMs guild */
struct dc_channel * channel; /* nofree - first channel */
struct dc_role * role; /* nofree - first role. NOTE: role->id==guild->id => @everyone */
@@ -446,6 +447,7 @@ void dc_guild_free (struct dc_guild * s, enum dc_status t) {
if (!s)
return;
free(s->name);
+ free(s->description);
if (!(t & DC_REPLACE)) /* we do this because we want to keep the pointer intact sometimes and */
free(s); /* reused; for example when replacing/updating structs */
}
@@ -751,7 +753,7 @@ void dc_api_stack (struct dc_api_io);
assert(u); \
if ((us = dc_find_##x(*p, *l, u->id))) { \
if (getenv("DC_I")) \
- fprintf(stderr, "debug: %s found already existing member\n", __func__); \
+ fprintf(stderr, "debug: %s found existing. id = %llu\n", __func__, u->id); \
if (us == u) \
return us; \
if (s & DC_REPLACE) { \
@@ -772,7 +774,7 @@ void dc_api_stack (struct dc_api_io);
*p = realloc(*p, sizeof(**p) * *so); \
} \
if (getenv("DC_I")) \
- fprintf(stderr, "debug: %s inserted into ISA\n", __func__); \
+ fprintf(stderr, "debug: %s inserted into ISA. id = %llu\n", __func__, u->id); \
(*p)[(*l)++] = u; \
return u; \
}
@@ -827,10 +829,11 @@ void dc_transfer_channel (struct dc_channel * n, struct dc_channel * o) { /* n w
void dc_transfer_guild (struct dc_guild * n, struct dc_guild * o) {
DC_TRANSFER_PREFIX
DC_TRANSFER_MEMBER(name)
+ DC_TRANSFER_MEMBER(description)
DC_TRANSFER_MEMBER(id)
- DC_TRANSFER_MEMBER(channel);
- DC_TRANSFER_MEMBER(role);
- DC_TRANSFER_MEMBER(status);
+ DC_TRANSFER_MEMBER(channel)
+ DC_TRANSFER_MEMBER(role)
+ DC_TRANSFER_MEMBER(status)
DC_IF_UI_GTK(
memmove(&n->iter, &o->iter, sizeof(GtkTreeIter));
n->is_iter = o->is_iter;
@@ -863,8 +866,10 @@ void dc_transfer_user (struct dc_user * n, struct dc_user * o) {
DC_TRANSFER_PREFIX
DC_TRANSFER_MEMBER(username)
DC_TRANSFER_MEMBER(id)
- DC_TRANSFER_MEMBER(discriminator)
- DC_TRANSFER_MEMBER(status)
+ if (n->discriminator == -1) { /* zero is a valid discriminator - AFAIK - it seems like it */
+ n->discriminator = o->discriminator;
+ o->discriminator = -1;
+ }
}
DC_GEN_X(user, USER)
DC_GEN_X(channel, CHANNEL)