diff options
author | xengineering <me@xengineering.eu> | 2022-08-17 11:39:16 +0200 |
---|---|---|
committer | xengineering <me@xengineering.eu> | 2022-08-17 11:39:16 +0200 |
commit | d82f48718bc6c69d734d0306867b866efc2f9719 (patch) | |
tree | 6f0d3798018af0c41729810c55546b89450e16f3 /data.c | |
parent | 94cca91f9c0036a5ceb95ff4099d2cdc3d9265af (diff) | |
download | limox-d82f48718bc6c69d734d0306867b866efc2f9719.tar limox-d82f48718bc6c69d734d0306867b866efc2f9719.tar.zst limox-d82f48718bc6c69d734d0306867b866efc2f9719.zip |
Implement datastructure for roster
Diffstat (limited to 'data.c')
-rw-r--r-- | data.c | 65 |
1 files changed, 65 insertions, 0 deletions
@@ -0,0 +1,65 @@ + + +#include <string.h> +#include <stdlib.h> +#include <stdio.h> + +#include "gui.h" + + +// https://www.rfc-editor.org/rfc/rfc6121#section-2.1.2.5 +typedef enum { + SUB_NONE, + SUB_TO, + SUB_FROM, + SUB_BOTH +} subscription_t; + +typedef struct _roster_item_t { + const char* name; + const char* jid; + subscription_t sub; + void* widget; // GUI widget as generic void* + struct _roster_item_t* next; +} roster_item_t; + + +// the RAM-stored data payload +static roster_item_t* roster = NULL; + + +void add_roster_item(const char* jid, const char* subscription, const char* name) { + + // parse roster item + roster_item_t* item = malloc(sizeof(roster_item_t)); + item->name = name; + item->jid = jid; + if (strcmp(subscription, "none") == 0) { + item->sub = SUB_NONE; + } else if (strcmp(subscription, "to") == 0) { + item->sub = SUB_TO; + } else if (strcmp(subscription, "from") == 0) { + item->sub = SUB_FROM; + } else if (strcmp(subscription, "both") == 0) { + item->sub = SUB_BOTH; + } else { + printf("Invalid subscription '%s'!\n", subscription); + return; + } + item->next = NULL; + + // add item to roster datastructure + if (roster == NULL) { + roster = item; + } else { + roster_item_t* current = roster; + while (current->next != NULL) // loop until end of linked list + current = current->next; + current->next = item; + } + + // notify GUI + void* widget = gui_add_roster_item(jid, subscription, name); + item->widget = widget; // adds pointer to GUI widget to roster_item_t + +} |