summaryrefslogtreecommitdiffstats
path: root/src/h.c
diff options
context:
space:
mode:
authorAnton Luka Šijanec <anton@sijanec.eu>2021-09-23 22:23:05 +0200
committerAnton Luka Šijanec <anton@sijanec.eu>2021-09-23 22:23:05 +0200
commitdacbcc8ff2ee9fd788c946b01335bd94eedbff6e (patch)
tree215438d472c62b59991062895ac06fce2daaeab7 /src/h.c
parentgrem spat. se ne kompajla. bom popravil ju3. zrihtal DM (diff)
downloaddiscord.c-dacbcc8ff2ee9fd788c946b01335bd94eedbff6e.tar
discord.c-dacbcc8ff2ee9fd788c946b01335bd94eedbff6e.tar.gz
discord.c-dacbcc8ff2ee9fd788c946b01335bd94eedbff6e.tar.bz2
discord.c-dacbcc8ff2ee9fd788c946b01335bd94eedbff6e.tar.lz
discord.c-dacbcc8ff2ee9fd788c946b01335bd94eedbff6e.tar.xz
discord.c-dacbcc8ff2ee9fd788c946b01335bd94eedbff6e.tar.zst
discord.c-dacbcc8ff2ee9fd788c946b01335bd94eedbff6e.zip
Diffstat (limited to '')
-rw-r--r--src/h.c86
1 files changed, 50 insertions, 36 deletions
diff --git a/src/h.c b/src/h.c
index fd0d40a..499885b 100644
--- a/src/h.c
+++ b/src/h.c
@@ -50,6 +50,7 @@ enum dc_status { /* theese are flags and should be and-checked */
DC_SET_WS_ACTIVE = 1 << 22, /* whether _CREATE _cb shall set client->status =| DC_WS_ACTIVE */
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_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! */
enum dc_permissions { /* other permissions exist, but are not implemented/understood */
@@ -135,6 +136,7 @@ struct dc_api_io { /* output struct does NOT contain void * data (user pointer)
struct dc_permission * permission;
struct dc_attached_function * attached_function; /* ptr2 heap alloc struct when DC_API_ATTAH */
struct dc_lws_pass * pass;
+ unsigned long long int id;
};
#define DC_API_IO_MEMB_GC(m, t) if (m && m->status & DC_IN_PROGRESS) { \
t##_free(m, DC_UNSET); \
@@ -212,6 +214,14 @@ enum dc_json_paths { /* lws reduces the following char array to uint8_t, so we c
DC_JSON_GUILD_CHANNEL_PERMISSION_ID,
DC_JSON_GUILD_CHANNEL_PERMISSION_DENY,
DC_JSON_GUILD_CHANNEL_PERMISSION_ALLOW,
+ DC_JSON_MEMBERSHIP, /* this object unfortionately only tells us our roles, */
+ DC_JSON_MEMBERSHIP_USER, /* id */ /* though this is enough to calculate permissions */
+ DC_JSON_MEMBERSHIP_ROLE, /* id */
+ DC_JSON_MEMBER, /* guild member object */
+ DC_JSON_MEMBER_USERNAME,
+ DC_JSON_MEMBER_ID,
+ DC_JSON_MEMBER_DISCRIMINATOR,
+ DC_JSON_MEMBER_ROLE, /* id, array */
DC_JSON_MESSAGE,
DC_JSON_MESSAGE_ATTACHMENTS,
DC_JSON_MESSAGE_ID,
@@ -222,7 +232,6 @@ enum dc_json_paths { /* lws reduces the following char array to uint8_t, so we c
DC_JSON_MESSAGE_AUTHOR_USERNAME,
DC_JSON_MESSAGE_AUTHOR_DISCRIMINATOR,
DC_JSON_MESSAGE_AUTHOR_ID,
- DC_JSON_MESSAGE_AUTHOR_ROLES,
DC_JSON_MESSAGE_REFERENCE, /* id */
DC_JSON_MESSAGE_MENTION_CHANNEL, /* TODO: implement role and user mentions fetching */
DC_JSON_MESSAGE_MENTION_CHANNEL_ID,
@@ -294,6 +303,14 @@ char * dc_json_paths[] = { /* array of paths we are interested in */
"d.guilds[].channels[].permission_overwrites.id",
"d.guilds[].channels[].permission_overwrites.deny",
"d.guilds[].channels[].permission_overwrites.allow",
+ "d.merged_members",
+ "d.merged_members[][].user_id",
+ "d.merged_members[][].roles",
+ "d.member",
+ "d.member.user.username",
+ "d.member.user.id",
+ "d.member.user.discriminator",
+ "d.member.roles",
"d",
"d.attachments[]",
"d.id",
@@ -304,7 +321,6 @@ char * dc_json_paths[] = { /* array of paths we are interested in */
"d.author.username",
"d.author.discriminator",
"d.author.id",
- "d.member.roles[]",
"d.message_reference", /* this is ID */
"d.mention_channels[]",
"d.mention_channels[].id",
@@ -350,7 +366,6 @@ struct dc_lws_pass { /* struct that is allocated for in dc_lws_cb unique per con
enum lejp_callbacks json_reason; /* holds last reason sent to json callback */
struct lws * wsi; /* set on ESTABLISHED and NULLed on CLOSED or ERROR */
enum dc_ws_packet packet; /* what type of packet are we currently handling in lejp */
- enum dc_status * parsing_status; /* to remove DC_IN_PROGRESS & signal if call api on COMPL */
uint16_t reason; /* reason for closing connection */
/* temporary debug things */
char * cp;
@@ -378,7 +393,7 @@ void dc_payload_free (struct dc_payload * s, enum dc_status t) {
#define DC_ISAS_INIT(type/* w/o struct */, name) do { name##_sizeof = DC_ALLOC_CHUNK; /* structs ISA */ \
name = calloc(name##_sizeof, sizeof(struct type *)); } while (0) /* prep arr, NO INIT membrs */
#define DC_ISASIQ(shortname) DC_ISAS_INIT(dc_##shortname, s->shortname##s) /* ISAS init quick */
-#define DC_ISAF(shortname) for (size_t i = 0; i < s->shortname##s_sizeof; i++) /* hmm, I used to fre */ \
+#define DC_ISAF(shortname) for (size_t i = 0; i < s->shortname##s_length; i++) /* hmm, I used to fre */ \
dc_##shortname##_free(s->shortname##s[i], DC_UNSET); /* till _sizeof, but now I fixd */ \
free(s->shortname##s); /* to only free till _length. is this problematic in any ways? */
struct dc_client {
@@ -520,34 +535,19 @@ struct dc_role {
enum dc_permissions permissions; /* this are guild permission */
struct dc_guild * guild; /* nofree - owner of the role */
struct dc_role * next; /* nofree - next role (linked list of all roles of dc_guild) */
- struct dc_role_membership * role_membership; /* nofree - first role membership ll) */
+ DC_ISASQ(user); /* yesfree pointer array only - users with this role */
enum dc_status status;
};
struct dc_role * dc_role_init () {
struct dc_role * s = calloc(1, sizeof(*s));
+ DC_ISASIQ(user);
return s;
}
void dc_role_free (struct dc_role * s, enum dc_status t) {
if (!s)
return;
free(s->name);
- if (!(t & DC_REPLACE))
- free(s);
-}
-struct dc_role_membership {
- DC_STRUCT_PREFIX
- struct dc_channel * channel; /* nofree */
- struct dc_user * user; /* nofree */
- struct dc_role * role; /* nofree */
- struct dc_role_membership * next; /* nofree - next role membership (lili in role) */
-};
-struct dc_role_membership * dc_role_membership_init () {
- struct dc_role_membership * s = calloc(1, sizeof(*s));
- return s;
-}
-void dc_role_membership_free (struct dc_role_membership * s, enum dc_status t) {
- if (!s)
- return;
+ free(s->users);
if (!(t & DC_REPLACE))
free(s);
}
@@ -573,7 +573,6 @@ struct dc_permission { /* permissions can be individual on a per-channel basis *
DC_STRUCT_PREFIX /* assume all permissions */
enum dc_permissions allow;
enum dc_permissions deny;
- unsigned long long int id; /* to whom does this permission apply */
struct dc_channel * channel; /* nofree - on which channel does it apply */
struct dc_user * user; /* nofree - non-null if permission applies to a user */
struct dc_role * role; /* nofree - non-null if it applies to a role */
@@ -628,7 +627,6 @@ struct dc_program { /* data storage and token used for communication with the li
DC_ISASQ(channel); /* yesfree */
DC_ISASQ(message); /* yesfree */
DC_ISASQ(role); /* yesfree */
- DC_ISASQ(role_membership); /* yesfree */
DC_ISASQ(user); /* yesfree */
DC_ISASQ(permission); /* yesfree */
DC_ISASQ(attached_function); /* yesfree */
@@ -665,7 +663,6 @@ struct dc_program * dc_program_init () {
DC_ISASIQ(channel);
DC_ISASIQ(message);
DC_ISASIQ(role);
- DC_ISASIQ(role_membership);
DC_ISASIQ(user);
DC_ISASIQ(permission);
DC_ISASIQ(attached_function);
@@ -701,7 +698,6 @@ void dc_program_free (struct dc_program * s, enum dc_status t) {
DC_ISAF(channel);
DC_ISAF(message);
DC_ISAF(role);
- DC_ISAF(role_membership);
DC_ISAF(user);
DC_ISAF(permission);
DC_ISAF(attached_function);
@@ -713,7 +709,7 @@ void dc_api_stack (struct dc_api_io);
#define DC_FIND_X(x) struct dc_##x * dc_find_##x(struct dc_##x ** p, size_t l, unsigned long long int id) { \
for (size_t i = 0; i < l; i++) \
if (p[i]->id == id) { \
- fprintf(stderr, "id %llu was found!\n", id); \
+ /* fprintf(stderr, "id %llu was found!\n", id); */ /* too much */ \
return p[i]; \
} \
return NULL; \
@@ -732,7 +728,7 @@ void dc_api_stack (struct dc_api_io);
#define DC_ADD_X(x) struct dc_##x * dc_add_##x (struct dc_##x *** p, size_t * so, size_t * l, struct dc_##x * u, enum dc_status s) { \
struct dc_##x * us; \
if ((us = dc_find_##x(*p, *l, u->id))) { \
- fprintf(stderr, "debug: %s found already existing member\n", __func__); \
+ /* fprintf(stderr, "debug: %s found already existing member\n", __func__); */ \
if (us == u) \
return us; \
if (s & DC_REPLACE) { \
@@ -751,17 +747,17 @@ void dc_api_stack (struct dc_api_io);
*so = ceil(*so*DC_REALLOC_K); \
*p = realloc(*p, sizeof(**p) * *so); \
} \
- fprintf(stderr, "debug: %s inserted into ISA\n", __func__); \
+ /* fprintf(stderr, "debug: %s inserted into ISA\n", __func__); */ /* too much */ \
(*p)[(*l)++] = u; \
return u; \
}
#define DC_ADDR_X(x, y) struct dc_##x * dc_addr_##x (struct dc_program * p, struct dc_##x *** a, size_t * so, size_t * l, struct dc_##x * u, enum dc_status s) { \
struct dc_##x * us; \
if (!a) { \
- if (u == (us = dc_add_##x(&p->x##s, &p->x##s_sizeof, &p->x##s_length, u, s))) \
+ if (u != (us = dc_add_##x(&p->x##s, &p->x##s_sizeof, &p->x##s_length, u, s))) \
return us; \
} else \
- if (u == (us = dc_add_##x(a, so, l, u, s))) \
+ if (u != (us = dc_add_##x(a, so, l, u, s))) \
return us; \
struct dc_api_io io; \
memset(&io, 0, sizeof(io)); \
@@ -776,13 +772,31 @@ DC_GEN_X(user, USER)
DC_GEN_X(channel, CHANNEL)
DC_FIND_LL_X(channel)
DC_GEN_X(guild, GUILD)
-#define DC_ISAE(a) &a, &a##_sizeof, &a##_length /* ISA Expand */
+DC_GEN_X(role, 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 */ \
- n->message = o->message; \
- n->next = o->next; \
+ (n)->message = (o)->message; /* don't transfer perms because we get them in the new */ \
+ (n)->next = o->next; /* new channel object */ \
DC_IF_UI_GTK( \
- memcpy(pass->api_io.channel->iter, ch->iter, sizeof(GtkTreeIter)); \
- pass->api_io.channel->is_iter = ch->is_iter; \
+ memmove(&(n)->iter, &(o)->iter, sizeof(GtkTreeIter)); \
+ (n)->is_iter = (o)->is_iter; \
) \
} while(0)
+#define DC_TRANSFER_GUILD(n, o) do { \
+ DC_IF_UI_GTK( \
+ memmove(&(n)->iter, &(o)->iter, sizeof(GtkTreeIter)); \
+ (n)->is_iter = (o)->is_iter; \
+ ) \
+ } while (0)
+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 */
+ n->users = o->users;
+ n->users_sizeof = o->users_sizeof;
+ n->users_length = o->users_sizeof;
+ o->users = NULL; /* so that free does not free array of pointers */
+ o->users_sizeof = 0;
+ o->users_length = 0;
+ }
+}