summaryrefslogtreecommitdiffstats
path: root/src/h.c
diff options
context:
space:
mode:
authorAnton Luka Šijanec <anton@sijanec.eu>2021-09-24 22:53:01 +0200
committerAnton Luka Šijanec <anton@sijanec.eu>2021-09-24 22:53:01 +0200
commit605cb0ca371517c7a5cff79b4ef2dfdfe22ab4fe (patch)
treeebe76db9117a7f64f7e958fb264c05f45825d4c6 /src/h.c
parentshit (diff)
downloaddiscord.c-605cb0ca371517c7a5cff79b4ef2dfdfe22ab4fe.tar
discord.c-605cb0ca371517c7a5cff79b4ef2dfdfe22ab4fe.tar.gz
discord.c-605cb0ca371517c7a5cff79b4ef2dfdfe22ab4fe.tar.bz2
discord.c-605cb0ca371517c7a5cff79b4ef2dfdfe22ab4fe.tar.lz
discord.c-605cb0ca371517c7a5cff79b4ef2dfdfe22ab4fe.tar.xz
discord.c-605cb0ca371517c7a5cff79b4ef2dfdfe22ab4fe.tar.zst
discord.c-605cb0ca371517c7a5cff79b4ef2dfdfe22ab4fe.zip
Diffstat (limited to 'src/h.c')
-rw-r--r--src/h.c43
1 files changed, 25 insertions, 18 deletions
diff --git a/src/h.c b/src/h.c
index 499885b..bd20bf8 100644
--- a/src/h.c
+++ b/src/h.c
@@ -53,15 +53,13 @@ enum dc_status { /* theese are flags and should be and-checked */
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 */
- DC_ADMIN = 1 << 3, /* this is incredibly retarded, why is this SEPARATE?!? - admins */
- DC_CHANNEL_VIEW = 1 << 10, /* all enum fields here have values same as the server values */
- DC_MESSAGE_SEND = 1 << 11,
- DC_MESSAGE_READ = 1 << 16, /* na tistem vegova serverju sem lahko pošiljal ne pa bral sporočil */
- DC_VOICE_LISTEN = 1 << 20,
- DC_VOICE_SPEAK = 1 << 21,
- DC_ALL_PERMISSIONS = DC_ADMIN | DC_CHANNEL_VIEW | DC_MESSAGE_SEND | DC_MESSAGE_READ | DC_VOICE_LISTEN | DC_VOICE_SPEAK /* admins get this@parsing, UI need not check admin separatly */
-}; /* all enum fields here have values same as the values that the server sends */
+#define DC_ADMIN (1 << 3) /* not all enum fields are implemented/understood */
+#define DC_CHANNEL_VIEW (1 << 10) /* all enum fields here have values same as the server values */
+#define DC_MESSAGE_SEND (1 << 11) /* this is not an enum as there are over 40 permissions */
+#define DC_MESSAGE_READ (1 << 16) /* na tistem vegova serverju sem lahko pošiljal ne pa bral sporočil */
+#define DC_VOICE_LISTEN (1 << 20) /* ISO C enums are at most int-wide */
+#define DC_VOICE_SPEAK (1 << 21)
+#define DC_ALL_PERMISSIONS (DC_ADMIN | DC_CHANNEL_VIEW | DC_MESSAGE_SEND | DC_MESSAGE_READ | DC_VOICE_LISTEN | DC_VOICE_SPEAK) /* admins get this@parsing, UI need not check admin separatly */
enum dc_channel_type { /* other types exist, but are not implemented/understood */
DC_GC = 0, /* guild channel */
DC_DM = 1, /* direct messages channel */
@@ -515,9 +513,15 @@ struct dc_message {
struct dc_message * next; /* next message (linked list of all messages of dc_channel) */
struct dc_message * reply; /* nofree - this message replies to another message or NULL */
enum dc_status status;
+ DC_ISASQ(user); /* yesfree pointer array only - mentions */
+ DC_ISASQ(role); /* yesfree pointer array only - mentions */
+ DC_ISASQ(channel); /* yesfree pointer array only - mentions */
};
struct dc_message * dc_message_init () {
struct dc_message * s = calloc(1, sizeof(*s));
+ DC_ISASIQ(user);
+ DC_ISASIQ(role);
+ DC_ISASIQ(channel);
return s;
}
void dc_message_free (struct dc_message * s, enum dc_status t) {
@@ -525,6 +529,9 @@ void dc_message_free (struct dc_message * s, enum dc_status t) {
return;
free(s->message);
free(s->attachment);
+ free(s->users);
+ free(s->roles);
+ free(s->channel);
if (!(t & DC_REPLACE))
free(s);
}
@@ -532,7 +539,7 @@ struct dc_role {
DC_STRUCT_PREFIX
char * name; /* yesfree */
unsigned long long int id;
- enum dc_permissions permissions; /* this are guild permission */
+ unsigned long long int 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) */
DC_ISASQ(user); /* yesfree pointer array only - users with this role */
@@ -571,8 +578,8 @@ void dc_user_free (struct dc_user * s, enum dc_status t) {
}
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 allow;
+ unsigned long long int deny;
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 */
@@ -753,12 +760,12 @@ void dc_api_stack (struct dc_api_io);
}
#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))) \
- return us; \
- } else \
- if (u != (us = dc_add_##x(a, so, l, u, s))) \
- return us; \
+ if (!a) \
+ us = dc_add_##x(&p->x##s, &p->x##s_sizeof, &p->x##s_length, u, s); \
+ else \
+ us = dc_add_##x(a, so, l, u, s); \
+ if (us != u) \
+ return us; \
struct dc_api_io io; \
memset(&io, 0, sizeof(io)); \
io.type = DC_API_##y; \