1 | #include "owl.h" |
---|
2 | |
---|
3 | void owl_buddylist_init(owl_buddylist *b) |
---|
4 | { |
---|
5 | owl_list_create(&(b->buddies)); |
---|
6 | } |
---|
7 | |
---|
8 | /* Deal with an "oncoming" message. This means recognizing the user |
---|
9 | * has logged in, and sending a message if they were not already |
---|
10 | * logged in. |
---|
11 | */ |
---|
12 | void owl_buddylist_oncoming(owl_buddylist *b, char *screenname) |
---|
13 | { |
---|
14 | int i, j, found; |
---|
15 | owl_message *m; |
---|
16 | |
---|
17 | found=0; |
---|
18 | j=owl_list_get_size(&(b->buddies)); |
---|
19 | for (i=0; i<j; i++) { |
---|
20 | if (!strcasecmp(owl_list_get_element(&(b->buddies), i), screenname)) { |
---|
21 | found=1; |
---|
22 | break; |
---|
23 | } |
---|
24 | } |
---|
25 | |
---|
26 | if (!found) { |
---|
27 | owl_list_append_element(&(b->buddies), owl_strdup(screenname)); |
---|
28 | |
---|
29 | m=owl_malloc(sizeof(owl_message)); |
---|
30 | owl_message_create_aim_login(m, 0, screenname); |
---|
31 | owl_global_messagequeue_addmsg(&g, m); |
---|
32 | } |
---|
33 | } |
---|
34 | |
---|
35 | |
---|
36 | |
---|
37 | /* Deal with an "offgoing" message. This means recognizing the user |
---|
38 | * has logged out, and sending a message if they were logged in. |
---|
39 | */ |
---|
40 | void owl_buddylist_offgoing(owl_buddylist *b, char *screenname) |
---|
41 | { |
---|
42 | int i, j, found; |
---|
43 | owl_message *m; |
---|
44 | |
---|
45 | found=0; |
---|
46 | j=owl_list_get_size(&(b->buddies)); |
---|
47 | for (i=0; i<j; i++) { |
---|
48 | if (!strcasecmp(owl_list_get_element(&(b->buddies), i), screenname)) { |
---|
49 | found=1; |
---|
50 | owl_free(owl_list_get_element(&(b->buddies), i)); |
---|
51 | owl_list_remove_element(&(b->buddies), i); |
---|
52 | break; |
---|
53 | } |
---|
54 | } |
---|
55 | |
---|
56 | if (found) { |
---|
57 | m=owl_malloc(sizeof(owl_message)); |
---|
58 | owl_message_create_aim_login(m, 1, screenname); |
---|
59 | owl_global_messagequeue_addmsg(&g, m); |
---|
60 | } |
---|
61 | } |
---|
62 | |
---|
63 | int owl_buddylist_get_size(owl_buddylist *b) |
---|
64 | { |
---|
65 | return(owl_list_get_size(&(b->buddies))); |
---|
66 | } |
---|
67 | |
---|
68 | char *owl_buddylist_get_buddy(owl_buddylist *b, int n) |
---|
69 | { |
---|
70 | return(owl_list_get_element(&(b->buddies), n)); |
---|
71 | } |
---|
72 | |
---|
73 | void owl_buddylist_clear(owl_buddylist *b) { |
---|
74 | owl_list_free_all(&(b->buddies), owl_free); |
---|
75 | owl_list_create(&(b->buddies)); |
---|
76 | } |
---|