summaryrefslogtreecommitdiffstats
path: root/src/h.c
diff options
context:
space:
mode:
authorAnton Luka Šijanec <anton@sijanec.eu>2021-09-25 18:29:34 +0200
committerAnton Luka Šijanec <anton@sijanec.eu>2021-09-25 18:29:34 +0200
commit7877e512c2f228e0e98340d30cfee44e14c29cd6 (patch)
treeb8d47722a7102c1a504f2aae827a271b23d9a1f2 /src/h.c
parenti hope it's fixed now (magic?), though there's still a memory leak (diff)
downloaddiscord.c-7877e512c2f228e0e98340d30cfee44e14c29cd6.tar
discord.c-7877e512c2f228e0e98340d30cfee44e14c29cd6.tar.gz
discord.c-7877e512c2f228e0e98340d30cfee44e14c29cd6.tar.bz2
discord.c-7877e512c2f228e0e98340d30cfee44e14c29cd6.tar.lz
discord.c-7877e512c2f228e0e98340d30cfee44e14c29cd6.tar.xz
discord.c-7877e512c2f228e0e98340d30cfee44e14c29cd6.tar.zst
discord.c-7877e512c2f228e0e98340d30cfee44e14c29cd6.zip
Diffstat (limited to '')
-rw-r--r--src/h.c28
1 files changed, 16 insertions, 12 deletions
diff --git a/src/h.c b/src/h.c
index bd20bf8..df7907f 100644
--- a/src/h.c
+++ b/src/h.c
@@ -51,6 +51,7 @@ enum dc_status { /* theese are flags and should be and-checked */
DC_REPLACE = 1 << 23, /* dc_add_x replace old with new on found, _free: only free members */
DC_EXPLICIT_NULL = 1 << 24, /* MEMB_GC will NULL this member (PROGRES?aftr free) (& clear bit) */
DC_EVERYONE = 1 << 25, /* role applies to all guild users */
+ DC_USER_ERROR = 1 << 26, /* lib user made an error, passed NULL pointer to _o for example */
DC_INTERNAL = DC_FROM_LWS | DC_FROM_API, /* call originates from an internal function */
}; /* note: when checking status, first check for DC_OK, if it's set then disregard errors! */
#define DC_ADMIN (1 << 3) /* not all enum fields are implemented/understood */
@@ -108,7 +109,7 @@ enum dc_api_io_type {
DC_API_REGISTER,/* i: pass a dc_client, to relogin FIX pr rt cl&cl->user not creat new */
/* o: the previously passed dc_client with set status */
DC_API_STATUS, /* i: N/A */
- /* o: new status message, pointer to internal string - tr0 */
+ /* o: check ->status */
DC_API_USER, /* i: query for user by id, pass dc_user-tr1 */
/* o: prev passed dc_user but filled (or not: ->status may indicate error) */
DC_API_ROLE, /* i: query for role by id, pass dc_role-tr1 */
@@ -665,6 +666,18 @@ enum dc_status dc_handle_ping (struct dc_api_io io, void * userdata) { /* tries
}
struct dc_program * dc_program_init () {
struct dc_program * s = calloc(1, sizeof(struct dc_program));
+ /* lws init, it may fail so we first do this to return NULL without memleak (thanks, clang) */
+ struct lws_context_creation_info info;
+ memset(&info, 0, sizeof(info));
+ info.options = LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT;
+ info.port = CONTEXT_PORT_NO_LISTEN; /* we are not listening - we are a client */
+ info.protocols = dc_lws_protocols;
+ info.fd_limit_per_thread = DC_LWS_MAX_FD;
+ if (!(s->lws_context = lws_create_context(&info))) {
+ lwsl_err("lws init failed\n");
+ free(s);
+ return NULL; /* of course our UI does not check for failure of init function, so the */
+ } /* program will just crash, but I assume lws init will never fail (correct me if I'm wrong) */
DC_ISASIQ(client);
DC_ISASIQ(guild);
DC_ISASIQ(channel);
@@ -674,17 +687,6 @@ struct dc_program * dc_program_init () {
DC_ISASIQ(permission);
DC_ISASIQ(attached_function);
DC_ISASIQ(api_io);
- /* lws init */
- struct lws_context_creation_info info;
- memset(&info, 0, sizeof(info));
- info.options = LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT;
- info.port = CONTEXT_PORT_NO_LISTEN; /* we are not listening - we are a client */
- info.protocols = dc_lws_protocols;
- info.fd_limit_per_thread = DC_LWS_MAX_FD;
- if (!(s->lws_context = lws_create_context(&info))) {
- lwsl_err("lws init failed\n");
- return NULL;
- }
struct dc_api_io io; /* attach a function for pinging wss of every client */
memset(&io, 0, sizeof(io));
io.type = DC_API_ATTACH;
@@ -780,6 +782,7 @@ DC_GEN_X(channel, CHANNEL)
DC_FIND_LL_X(channel)
DC_GEN_X(guild, GUILD)
DC_GEN_X(role, ROLE)
+DC_FIND_LL_X(role)
#define DC_ISAE(a) &(a), &(a##_sizeof), &(a##_length) /* ISA Expand */
#define DC_ISAN NULL, NULL, NULL /* ISA NULL */
#define DC_TRANSFER_CHANNEL(n, o) do { /* n is going to DC_REPLACE o, transfer important data */ \
@@ -799,6 +802,7 @@ DC_GEN_X(role, ROLE)
void dc_transfer_role (struct dc_role * n, struct dc_role * o) {
n->next = o->next;
if (!n->users_length) { /* if we didn't update users array in the new role object */
+ free(n->users); /* thanks, clang, we have to free pointer array before overwriting it! */
n->users = o->users;
n->users_sizeof = o->users_sizeof;
n->users_length = o->users_sizeof;