#include #include #include #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; // the roster item in the contact list view void* page_widget; // the chat page corresponding to this roster item 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 item->widget = gui_add_roster_item(jid, subscription, name); item->page_widget = gui_add_chat(); }