summaryrefslogtreecommitdiffstats
path: root/src/h.c
diff options
context:
space:
mode:
authorAnton Luka Šijanec <anton@sijanec.eu>2022-02-14 21:24:37 +0100
committerAnton Luka Šijanec <anton@sijanec.eu>2022-02-14 21:24:37 +0100
commitaaff3fb225290e639780bbdcd0a8d0f5c0121a50 (patch)
treec1c8b763a803706e6f27c89f4914046c13b4e8d4 /src/h.c
parentgrem spat, ni testirano (diff)
downloaddiscord.c-aaff3fb225290e639780bbdcd0a8d0f5c0121a50.tar
discord.c-aaff3fb225290e639780bbdcd0a8d0f5c0121a50.tar.gz
discord.c-aaff3fb225290e639780bbdcd0a8d0f5c0121a50.tar.bz2
discord.c-aaff3fb225290e639780bbdcd0a8d0f5c0121a50.tar.lz
discord.c-aaff3fb225290e639780bbdcd0a8d0f5c0121a50.tar.xz
discord.c-aaff3fb225290e639780bbdcd0a8d0f5c0121a50.tar.zst
discord.c-aaff3fb225290e639780bbdcd0a8d0f5c0121a50.zip
Diffstat (limited to 'src/h.c')
-rw-r--r--src/h.c58
1 files changed, 35 insertions, 23 deletions
diff --git a/src/h.c b/src/h.c
index 81d7179..b08861e 100644
--- a/src/h.c
+++ b/src/h.c
@@ -62,27 +62,31 @@ enum dc_status { /* theese are flags and should be and-checked */
#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 */
- DC_VOICE = 2, /* all enum fields here have values same as the values that the server sends */
- DC_GROUP_DM = 3
+ DC_GC, /* guild channel */
+ DC_DM, /* direct messages channel */
+ DC_VOICE, /* all enum fields here have values same as the values that the server sends */
+ DC_GROUP_DM
};
#define DC_CHANNEL_SUPPORTED(x) (x == DC_GC || x == DC_DM || x == DC_VOICE || x == DC_GROUP_DM)
enum dc_ws_packet { /* op numbers of websocket packets or json objects in other words */
DC_PING = 1,
DC_STRPKTOFF = 100, /* here follow string types (t) */
DC_NONE = DC_STRPKTOFF + 0, /* unknown packet or packet type not yet defermined */
- DC_MESSAGE_CREATE = DC_STRPKTOFF + 1,
+ DC_MESSAGE_CREATE,
}; /* intents enum was removed - intents're for bots, clients have capabilities - are not understood */
char * dc_ws_packet[] = {
"",
"MESSAGE_CREATE"
};
enum dc_message_type { /* other types exist, but are not implemented/understood, same values as server */
- DC_MESSAGE = 0,
+ DC_MESSAGE,
DC_REPLY = 19,
};
#define DC_MESSAGE_SUPPORTED(x) (x == DC_MESSAGE || x == DC_REPLY)
+enum dc_permission_type { /* same values as server */
+ DC_ROLE,
+ DC_USER
+};
enum dc_api_io_type {
/* all output structs have important structs set when an output is broadcast, for example if we get a channel from server but we don't possess it's guild (by id), api will wait for the guild and hold the channel in it's cache. for messages, tags in message are also parsed and queried. roles in premissions in channels are also fetched but not users in permissions, because permissions are currently only used for checking our permissions, not others' */
/* none of the outputs transfer memory ownership. tr0 for inputs means transfer none, trp means pointer to struct owned by library is to be passed, tr1 means transfer of ownership to library */
@@ -423,7 +427,6 @@ struct dc_guild {
DC_STRUCT_PREFIX
char * name; /* yesfree */
unsigned long long int id; /* 0 for virtual DMs guild */
- struct dc_client * client; /* nofree */
struct dc_channel * channel; /* nofree - first channel */
struct dc_role * role; /* nofree - first role. NOTE: role->id == guild->id => @everyone role */
enum dc_status status; /* /\ if NULL then assume all permissions - a DM guild */
@@ -453,7 +456,6 @@ struct dc_client * dc_client_init () {
s->guilds_length = 1; /* because of duplicated 0 id value; freeing is therefore done from */
s->guilds[0] = dc_guild_init(); /* dc_client_free */
s->guilds[0]->name = strdup("Direct messages"); /* TODO: use gettext or similar for t9ns */
- s->guilds[0]->client = s;
return s;
}
void dc_client_free (struct dc_client * s, enum dc_status t) {
@@ -489,7 +491,7 @@ struct dc_channel {
struct dc_guild * guild; /* nofree */
struct dc_channel * next; /* nofree - next channel (linked list of all channel of dc_guild) */
struct dc_message * message; /* nofree - first message (ordered by time) */
- struct dc_permission * permission; /* nofree - first permission */
+ DC_ISASQ(permission); /* yesfree array and members - ch permissions for users/roles */
enum dc_status status;
DC_ISASQ(user); /* yesfree array only - participants in DM channels */
#ifdef DC_UI_GTK
@@ -500,14 +502,17 @@ struct dc_channel {
struct dc_channel * dc_channel_init () {
struct dc_channel * s = calloc(1, sizeof(*s));
DC_ISASIQ(user);
+ DC_ISASIQ(permission);
return s;
}
+void dc_permission_free (struct dc_permission *, enum dc_status);
void dc_channel_free (struct dc_channel * s, enum dc_status t) {
if (!s)
return;
free(s->name);
free(s->topic);
free(s->users);
+ DC_ISAF(permission);
if (!(t & DC_REPLACE))
free(s);
}
@@ -522,6 +527,7 @@ struct dc_message {
struct dc_message * reply; /* nofree - this message replies to another message or NULL */
enum dc_status status;
enum dc_message_type type;
+ struct dc_client * client; /* nofree - set when sending message to the client that should send */
DC_ISASQ(user); /* yesfree pointer array only - mentions */
DC_ISASQ(role); /* yesfree pointer array only - mentions */
DC_ISASQ(channel); /* yesfree pointer array only - mentions */
@@ -571,6 +577,7 @@ struct dc_user {
char * username; /* yesfree */
unsigned long long int id;
short int discriminator;
+ struct dc_program * program; /* nofree - for dc_calculate_permissions */
enum dc_status status;
};
struct dc_user * dc_user_init () {
@@ -588,10 +595,10 @@ struct dc_permission { /* permissions can be individual on a per-channel basis *
DC_STRUCT_PREFIX /* assume all permissions */
unsigned long long int allow;
unsigned long long int deny;
+ enum dc_permission_type type;
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 */
- struct dc_permission * next; /* nexrt permission in ll in channel */
enum dc_status status;
}; /* permissions are only useful for checking OUR permissions, not others'. keep that in mind. */
struct dc_permission * dc_permission_init () {
@@ -643,7 +650,6 @@ struct dc_program { /* data storage and token used for communication with the li
DC_ISASQ(message); /* yesfree */
DC_ISASQ(role); /* yesfree */
DC_ISASQ(user); /* yesfree */
- DC_ISASQ(permission); /* yesfree */
DC_ISASQ(attached_function); /* yesfree */
DC_ISASQ(api_io); /* yesfree */
struct lws_context * lws_context; /* yesfree */
@@ -691,13 +697,12 @@ struct dc_program * dc_program_init () {
DC_ISASIQ(message);
DC_ISASIQ(role);
DC_ISASIQ(user);
- DC_ISASIQ(permission);
DC_ISASIQ(attached_function);
DC_ISASIQ(api_io);
struct dc_api_io io; /* attach a function for pinging wss of every client */
memset(&io, 0, sizeof(io));
io.type = DC_API_ATTACH;
- io.attached_function = calloc(1, sizeof(struct dc_attached_function));
+ io.attached_function = dc_attached_function_init();
io.attached_function->type = DC_API_TIMEOUT;
io.attached_function->every = 0; /* repediately call, handle_ping handles timing */
io.attached_function->function = dc_handle_ping;
@@ -715,7 +720,6 @@ void dc_program_free (struct dc_program * s, enum dc_status t) {
DC_ISAF(message);
DC_ISAF(role);
DC_ISAF(user);
- DC_ISAF(permission);
DC_ISAF(attached_function);
DC_ISAF(api_io);
if (!(t & DC_REPLACE))
@@ -723,7 +727,6 @@ void dc_program_free (struct dc_program * s, enum dc_status t) {
}
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) { \
- assert(id); \
for (size_t i = 0; i < l; i++) \
if (p[i]->id == id) { \
/* fprintf(stderr, "id %llu was found!\n", id); */ /* too much */ \
@@ -796,14 +799,23 @@ DC_GEN_X(message, MESSAGE)
DC_FIND_LL_X(message)
#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; /* don't transfer perms because we get them in the new */ \
- (n)->next = o->next; /* new channel object */ \
- DC_IF_UI_GTK( \
- memmove(&(n)->iter, &(o)->iter, sizeof(GtkTreeIter)); \
- (n)->is_iter = (o)->is_iter; \
- ) \
- } while(0)
+void dc_transfer_channel(struct dc_channel * n, struct dc_channel * o) { /* n is going to _REPLACE o */ \
+ 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(
+ memmove(&n->iter, &o->iter, sizeof(GtkTreeIter));
+ n->is_iter = o->is_iter;
+ )
+ if (!n->permissions_length) {
+ free(n->permissions);
+ n->permissions = o->permissions;
+ n->permissions_sizeof = o->permissions_sizeof;
+ n->permissions_length = o->permissions_length;
+ o->permissions = NULL;
+ o->permissions_sizeof = 0;
+ o->permissions_length = 0;
+ }
+}
#define DC_TRANSFER_GUILD(n, o) do { \
DC_IF_UI_GTK( \
memmove(&(n)->iter, &(o)->iter, sizeof(GtkTreeIter)); \