summaryrefslogtreecommitdiff
path: root/data.c
diff options
context:
space:
mode:
Diffstat (limited to 'data.c')
-rw-r--r--data.c65
1 files changed, 65 insertions, 0 deletions
diff --git a/data.c b/data.c
new file mode 100644
index 0000000..e9c4039
--- /dev/null
+++ b/data.c
@@ -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
+
+}