blob: e2bfc30fbada577b5050d623faa64c8f9b8c2e58 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
#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; // 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();
}
|