summaryrefslogtreecommitdiffstats
path: root/src/h.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/h.c')
-rw-r--r--src/h.c37
1 files changed, 21 insertions, 16 deletions
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)