Mercurial > ~mikael > mcabber > hg
annotate mcabber/src/roster.c @ 580:fed6d1e4d7a9
Fix modelines
:-(
author | Mikael Berthe <mikael@lilotux.net> |
---|---|
date | Mon, 05 Dec 2005 00:01:16 +0100 |
parents | 8b3db0b555a1 |
children | 414fbf558f1e |
rev | line source |
---|---|
72 | 1 /* |
2 * roster.c -- Local roster implementation | |
393 | 3 * |
72 | 4 * Copyright (C) 2005 Mikael Berthe <bmikael@lists.lilotux.net> |
5 * | |
6 * This program is free software; you can redistribute it and/or modify | |
7 * it under the terms of the GNU General Public License as published by | |
8 * the Free Software Foundation; either version 2 of the License, or (at | |
9 * your option) any later version. | |
10 * | |
11 * This program is distributed in the hope that it will be useful, but | |
12 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 * General Public License for more details. | |
15 * | |
16 * You should have received a copy of the GNU General Public License | |
17 * along with this program; if not, write to the Free Software | |
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 | |
19 * USA | |
20 */ | |
21 | |
265 | 22 #define _GNU_SOURCE /* for strcasestr() */ |
72 | 23 #include <string.h> |
24 | |
25 #include "roster.h" | |
26 | |
27 | |
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
28 /* Resource structure */ |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
29 |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
30 typedef struct { |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
31 gchar *name; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
32 gchar prio; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
33 enum imstatus status; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
34 gchar *status_msg; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
35 enum imrole role; |
572
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
36 enum imaffiliation affil; |
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
37 gchar *realjid; /* for chatrooms, if buddy's real jid is known */ |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
38 } res; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
39 |
72 | 40 /* This is a private structure type for the roster */ |
41 | |
42 typedef struct { | |
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
43 gchar *name; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
44 gchar *jid; |
72 | 45 guint type; |
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
46 enum subscr subscription; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
47 GSList *resource; |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
48 gchar *nickname; // For groupchats |
548
265c50238a48
Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
49 gchar *topic; // For groupchats |
72 | 50 guint flags; |
51 // list: user -> points to his group; group -> points to its users list | |
52 GSList *list; | |
53 } roster; | |
54 | |
55 | |
56 /* ### Variables ### */ | |
57 | |
58 static int hide_offline_buddies; | |
59 static GSList *groups; | |
236 | 60 static GSList *unread_list; |
72 | 61 GList *buddylist; |
78 | 62 GList *current_buddy; |
330 | 63 GList *alternate_buddy; |
72 | 64 |
65 | |
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
66 /* ### Resources functions ### */ |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
67 |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
68 static void free_all_resources(GSList **reslist) |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
69 { |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
70 GSList *lip; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
71 res *p_res; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
72 |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
73 for ( lip = *reslist; lip ; lip = g_slist_next(lip)) { |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
74 p_res = (res*)lip->data; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
75 if (p_res->status_msg) { |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
76 g_free((gchar*)p_res->status_msg); |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
77 } |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
78 if (p_res->name) { |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
79 g_free((gchar*)p_res->name); |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
80 } |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
81 if (p_res->realjid) { |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
82 g_free((gchar*)p_res->realjid); |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
83 } |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
84 } |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
85 // Free all nodes but the first (which is static) |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
86 g_slist_free(*reslist); |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
87 *reslist = NULL; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
88 } |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
89 |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
90 // Resources are sorted in ascending order |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
91 static gint resource_compare_prio(res *a, res *b) { |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
92 //return (a->prio - b->prio); |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
93 if (a->prio < b->prio) return -1; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
94 else return 1; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
95 } |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
96 |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
97 // get_resource(rost, resname) |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
98 // Return a pointer to the resource with name resname, in rost's resources list |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
99 // - if rost has no resources, return NULL |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
100 // - if resname is defined, return the match or NULL |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
101 // - if resname is NULL, the last resource is returned, currently |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
102 // This could change in the future, because we should return the best one |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
103 // (priority? last used? and fall back to the first resource) |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
104 // |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
105 static res *get_resource(roster *rost, const char *resname) |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
106 { |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
107 GSList *p; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
108 res *r = NULL; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
109 |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
110 for (p = rost->resource; p; p = g_slist_next(p)) { |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
111 r = p->data; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
112 if (resname && !strcmp(r->name, resname)) |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
113 return r; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
114 } |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
115 |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
116 // The last resource is one of the resources with the highest priority, |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
117 // however, we don't know if it is the more-recently-used. |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
118 if (!resname) return r; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
119 return NULL; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
120 } |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
121 |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
122 // get_or_add_resource(rost, resname, priority) |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
123 // - if there is a "resname" resource in rost's resources, return a pointer |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
124 // on this resource |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
125 // - if not, add the resource, set the name, and return a pointer on this |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
126 // new resource |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
127 static res *get_or_add_resource(roster *rost, const char *resname, gchar prio) |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
128 { |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
129 GSList *p; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
130 res *nres; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
131 |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
132 if (!resname) return NULL; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
133 |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
134 for (p = rost->resource; p; p = g_slist_next(p)) { |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
135 res *r = p->data; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
136 if (!strcmp(r->name, resname)) |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
137 return r; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
138 } |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
139 |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
140 // Resource not found |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
141 nres = g_new0(res, 1); |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
142 nres->name = g_strdup(resname); |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
143 nres->prio = prio; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
144 rost->resource = g_slist_insert_sorted(rost->resource, nres, |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
145 (GCompareFunc)&resource_compare_prio); |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
146 return nres; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
147 } |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
148 |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
149 static void del_resource(roster *rost, const char *resname) |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
150 { |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
151 GSList *p; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
152 GSList *p_res_elt = NULL; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
153 res *p_res; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
154 |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
155 if (!resname) return; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
156 |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
157 for (p = rost->resource; p; p = g_slist_next(p)) { |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
158 res *r = p->data; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
159 if (!strcmp(r->name, resname)) |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
160 p_res_elt = p; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
161 } |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
162 |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
163 if (!p_res_elt) return; // Resource not found |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
164 |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
165 p_res = p_res_elt->data; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
166 // Free allocations and delete resource node |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
167 if (p_res->name) g_free(p_res->name); |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
168 if (p_res->status_msg) g_free(p_res->status_msg); |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
169 if (p_res->realjid) g_free(p_res->realjid); |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
170 rost->resource = g_slist_delete_link(rost->resource, p_res_elt); |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
171 return; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
172 } |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
173 |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
174 |
72 | 175 /* ### Roster functions ### */ |
176 | |
177 // Comparison function used to search in the roster (compares jids and types) | |
336
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
331
diff
changeset
|
178 static gint roster_compare_jid_type(roster *a, roster *b) { |
89 | 179 if (! (a->type & b->type)) |
480 | 180 return -1; // arbitrary (but should be != 0, of course) |
72 | 181 return strcasecmp(a->jid, b->jid); |
182 } | |
183 | |
184 // Comparison function used to sort the roster (by name) | |
336
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
331
diff
changeset
|
185 static gint roster_compare_name(roster *a, roster *b) { |
72 | 186 return strcasecmp(a->name, b->name); |
187 } | |
188 | |
189 // Finds a roster element (user, group, agent...), by jid or name | |
89 | 190 // If roster_type is 0, returns match of any type. |
72 | 191 // Returns the roster GSList element, or NULL if jid/name not found |
78 | 192 GSList *roster_find(const char *jidname, enum findwhat type, guint roster_type) |
72 | 193 { |
194 GSList *sl_roster_elt = groups; | |
195 GSList *res; | |
196 roster sample; | |
197 GCompareFunc comp; | |
198 | |
192 | 199 if (!jidname) return NULL; |
72 | 200 |
89 | 201 if (!roster_type) |
480 | 202 roster_type = ROSTER_TYPE_USER | ROSTER_TYPE_ROOM | |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
203 ROSTER_TYPE_AGENT | ROSTER_TYPE_GROUP; |
89 | 204 |
72 | 205 sample.type = roster_type; |
206 if (type == jidsearch) { | |
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
207 sample.jid = (gchar*)jidname; |
72 | 208 comp = (GCompareFunc)&roster_compare_jid_type; |
209 } else if (type == namesearch) { | |
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
210 sample.name = (gchar*)jidname; |
72 | 211 comp = (GCompareFunc)&roster_compare_name; |
212 } else | |
213 return NULL; // should not happen | |
214 | |
215 while (sl_roster_elt) { | |
216 roster *roster_elt = (roster*)sl_roster_elt->data; | |
217 if (roster_type & ROSTER_TYPE_GROUP) { | |
218 if ((type == namesearch) && !strcasecmp(jidname, roster_elt->name)) | |
219 return sl_roster_elt; | |
220 } | |
483
4a10c04ac2fb
Fix a bug in roster_find()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
221 res = g_slist_find_custom(roster_elt->list, &sample, comp); |
4a10c04ac2fb
Fix a bug in roster_find()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
222 if (res) return res; |
72 | 223 sl_roster_elt = g_slist_next(sl_roster_elt); |
224 } | |
225 return NULL; | |
226 } | |
227 | |
228 // Returns pointer to new group, or existing group with that name | |
78 | 229 GSList *roster_add_group(const char *name) |
72 | 230 { |
231 roster *roster_grp; | |
232 // #1 Check name doesn't already exist | |
233 if (!roster_find(name, namesearch, ROSTER_TYPE_GROUP)) { | |
234 // #2 Create the group node | |
235 roster_grp = g_new0(roster, 1); | |
236 roster_grp->name = g_strdup(name); | |
237 roster_grp->type = ROSTER_TYPE_GROUP; | |
238 // #3 Insert (sorted) | |
239 groups = g_slist_insert_sorted(groups, roster_grp, | |
240 (GCompareFunc)&roster_compare_name); | |
241 } | |
242 return roster_find(name, namesearch, ROSTER_TYPE_GROUP); | |
243 } | |
244 | |
245 // Returns a pointer to the new user, or existing user with that name | |
78 | 246 GSList *roster_add_user(const char *jid, const char *name, const char *group, |
562 | 247 guint type) |
72 | 248 { |
249 roster *roster_usr; | |
250 roster *my_group; | |
251 GSList *slist; | |
252 | |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
253 if ((type != ROSTER_TYPE_USER) && |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
254 (type != ROSTER_TYPE_ROOM) && |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
255 (type != ROSTER_TYPE_AGENT)) { |
72 | 256 // XXX Error message? |
257 return NULL; | |
258 } | |
259 | |
78 | 260 // Let's be arbitrary: default group has an empty name (""). |
261 if (!group) group = ""; | |
262 | |
72 | 263 // #1 Check this user doesn't already exist |
563
b0f1b127bfb6
Prevent from adding a duplicate jid (when types are different)
Mikael Berthe <mikael@lilotux.net>
parents:
562
diff
changeset
|
264 slist = roster_find(jid, jidsearch, 0); |
192 | 265 if (slist) return slist; |
72 | 266 // #2 add group if necessary |
267 slist = roster_add_group(group); | |
268 if (!slist) return NULL; | |
269 my_group = (roster*)slist->data; | |
270 // #3 Create user node | |
271 roster_usr = g_new0(roster, 1); | |
272 roster_usr->jid = g_strdup(jid); | |
78 | 273 if (name) { |
274 roster_usr->name = g_strdup(name); | |
275 } else { | |
276 gchar *p, *str = g_strdup(jid); | |
80 | 277 p = strstr(str, "/"); |
78 | 278 if (p) *p = '\0'; |
279 roster_usr->name = g_strdup(str); | |
280 g_free(str); | |
281 } | |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
282 roster_usr->type = type; |
72 | 283 roster_usr->list = slist; // (my_group SList element) |
284 // #4 Insert node (sorted) | |
285 my_group->list = g_slist_insert_sorted(my_group->list, roster_usr, | |
564 | 286 (GCompareFunc)&roster_compare_name); |
72 | 287 return roster_find(jid, jidsearch, type); |
288 } | |
289 | |
290 // Removes user (jid) from roster, frees allocated memory | |
78 | 291 void roster_del_user(const char *jid) |
72 | 292 { |
293 GSList *sl_user, *sl_group; | |
294 GSList **sl_group_listptr; | |
295 roster *roster_usr; | |
246 | 296 GSList *node; |
72 | 297 |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
298 sl_user = roster_find(jid, jidsearch, |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
299 ROSTER_TYPE_USER|ROSTER_TYPE_AGENT|ROSTER_TYPE_ROOM); |
89 | 300 if (sl_user == NULL) |
72 | 301 return; |
302 roster_usr = (roster*)sl_user->data; | |
246 | 303 |
304 // Remove (if present) from unread messages list | |
305 node = g_slist_find(unread_list, roster_usr); | |
306 if (node) unread_list = g_slist_delete_link(unread_list, node); | |
307 | |
308 // Let's free memory (jid, name, status message) | |
221 | 309 if (roster_usr->jid) g_free((gchar*)roster_usr->jid); |
310 if (roster_usr->name) g_free((gchar*)roster_usr->name); | |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
311 if (roster_usr->nickname) g_free((gchar*)roster_usr->nickname); |
548
265c50238a48
Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
312 if (roster_usr->topic) g_free((gchar*)roster_usr->topic); |
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
313 free_all_resources(&roster_usr->resource); |
210 | 314 g_free(roster_usr); |
72 | 315 |
316 // That's a little complex, we need to dereference twice | |
317 sl_group = ((roster*)sl_user->data)->list; | |
318 sl_group_listptr = &((roster*)(sl_group->data))->list; | |
319 *sl_group_listptr = g_slist_delete_link(*sl_group_listptr, sl_user); | |
78 | 320 |
321 // We need to rebuild the list | |
322 if (current_buddy) | |
323 buddylist_build(); | |
210 | 324 // TODO What we could do, too, is to check if the deleted node is |
78 | 325 // current_buddy, in which case we could move current_buddy to the |
326 // previous (or next) node. | |
72 | 327 } |
328 | |
210 | 329 // Free all roster data and call buddylist_build() to free the buddylist. |
164 | 330 void roster_free(void) |
331 { | |
332 GSList *sl_grp = groups; | |
333 | |
301
efcbd3c1ad15
Free unread_list when the roster is freed
Mikael Berthe <mikael@lilotux.net>
parents:
265
diff
changeset
|
334 // Free unread_list |
efcbd3c1ad15
Free unread_list when the roster is freed
Mikael Berthe <mikael@lilotux.net>
parents:
265
diff
changeset
|
335 if (unread_list) { |
efcbd3c1ad15
Free unread_list when the roster is freed
Mikael Berthe <mikael@lilotux.net>
parents:
265
diff
changeset
|
336 g_slist_free(unread_list); |
efcbd3c1ad15
Free unread_list when the roster is freed
Mikael Berthe <mikael@lilotux.net>
parents:
265
diff
changeset
|
337 unread_list = NULL; |
efcbd3c1ad15
Free unread_list when the roster is freed
Mikael Berthe <mikael@lilotux.net>
parents:
265
diff
changeset
|
338 } |
efcbd3c1ad15
Free unread_list when the roster is freed
Mikael Berthe <mikael@lilotux.net>
parents:
265
diff
changeset
|
339 |
164 | 340 // Walk through groups |
341 while (sl_grp) { | |
342 roster *roster_grp = (roster*)sl_grp->data; | |
343 GSList *sl_usr = roster_grp->list; | |
344 // Walk through this group users | |
345 while (sl_usr) { | |
346 roster *roster_usr = (roster*)sl_usr->data; | |
347 // Free name and jid | |
221 | 348 if (roster_usr->jid) g_free((gchar*)roster_usr->jid); |
349 if (roster_usr->name) g_free((gchar*)roster_usr->name); | |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
350 if (roster_usr->nickname) g_free((gchar*)roster_usr->nickname); |
548
265c50238a48
Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
351 if (roster_usr->topic) g_free((gchar*)roster_usr->topic); |
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
352 free_all_resources(&roster_usr->resource); |
214 | 353 g_free(roster_usr); |
164 | 354 sl_usr = g_slist_next(sl_usr); |
355 } | |
356 // Free group's users list | |
357 if (roster_grp->list) | |
358 g_slist_free(roster_grp->list); | |
359 // Free group's name and jid | |
221 | 360 if (roster_grp->jid) g_free((gchar*)roster_grp->jid); |
361 if (roster_grp->name) g_free((gchar*)roster_grp->name); | |
214 | 362 g_free(roster_grp); |
164 | 363 sl_grp = g_slist_next(sl_grp); |
364 } | |
365 // Free groups list | |
366 if (groups) { | |
367 g_slist_free(groups); | |
368 groups = NULL; | |
369 // Update (i.e. free) buddylist | |
370 if (buddylist) | |
371 buddylist_build(); | |
372 } | |
373 } | |
374 | |
468
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
375 // roster_setstatus() |
572
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
376 // Note: resname, role, affil and realjid are for room members only |
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
377 void roster_setstatus(const char *jid, const char *resname, gchar prio, |
468
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
378 enum imstatus bstat, const char *status_msg, |
572
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
379 enum imrole role, enum imaffiliation affil, |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
380 const char *realjid) |
72 | 381 { |
382 GSList *sl_user; | |
383 roster *roster_usr; | |
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
384 res *p_res; |
72 | 385 |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
386 sl_user = roster_find(jid, jidsearch, |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
387 ROSTER_TYPE_USER|ROSTER_TYPE_ROOM|ROSTER_TYPE_AGENT); |
92 | 388 // If we can't find it, we add it |
89 | 389 if (sl_user == NULL) |
92 | 390 sl_user = roster_add_user(jid, NULL, NULL, ROSTER_TYPE_USER); |
72 | 391 |
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
392 // If there is no resource name, we can leave now |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
393 if (!resname) return; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
394 |
72 | 395 roster_usr = (roster*)sl_user->data; |
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
396 |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
397 // If bstat is offline, we MUST delete the resource, actually |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
398 if (bstat == offline) { |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
399 del_resource(roster_usr, resname); |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
400 return; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
401 } |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
402 |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
403 // New or updated resource |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
404 p_res = get_or_add_resource(roster_usr, resname, prio); |
494
3f5aa4852684
Fix small bug in roster_setstatus()
Mikael Berthe <mikael@lilotux.net>
parents:
489
diff
changeset
|
405 p_res->prio = prio; |
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
406 p_res->status = bstat; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
407 if (p_res->status_msg) { |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
408 g_free((gchar*)p_res->status_msg); |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
409 p_res->status_msg = NULL; |
221 | 410 } |
411 if (status_msg) | |
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
412 p_res->status_msg = g_strdup(status_msg); |
468
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
413 |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
414 p_res->role = role; |
572
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
415 p_res->affil = affil; |
468
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
416 |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
417 if (p_res->realjid) { |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
418 g_free((gchar*)p_res->realjid); |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
419 p_res->realjid = NULL; |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
420 } |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
421 if (realjid) |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
422 p_res->realjid = g_strdup(realjid); |
72 | 423 } |
424 | |
78 | 425 // roster_setflags() |
426 // Set one or several flags to value (TRUE/FALSE) | |
80 | 427 void roster_setflags(const char *jid, guint flags, guint value) |
78 | 428 { |
429 GSList *sl_user; | |
430 roster *roster_usr; | |
431 | |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
432 sl_user = roster_find(jid, jidsearch, |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
433 ROSTER_TYPE_USER|ROSTER_TYPE_ROOM|ROSTER_TYPE_AGENT); |
89 | 434 if (sl_user == NULL) |
78 | 435 return; |
436 | |
437 roster_usr = (roster*)sl_user->data; | |
438 if (value) | |
439 roster_usr->flags |= flags; | |
440 else | |
441 roster_usr->flags &= ~flags; | |
442 } | |
148 | 443 |
444 // roster_msg_setflag() | |
445 // Set the ROSTER_FLAG_MSG to the given value for the given jid. | |
446 // It will update the buddy's group message flag. | |
236 | 447 // Update the unread messages list too. |
148 | 448 void roster_msg_setflag(const char *jid, guint value) |
449 { | |
450 GSList *sl_user; | |
451 roster *roster_usr, *roster_grp; | |
452 | |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
453 sl_user = roster_find(jid, jidsearch, |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
454 ROSTER_TYPE_USER|ROSTER_TYPE_ROOM|ROSTER_TYPE_AGENT); |
148 | 455 if (sl_user == NULL) |
456 return; | |
457 | |
458 roster_usr = (roster*)sl_user->data; | |
459 roster_grp = (roster*)roster_usr->list->data; | |
460 if (value) { | |
461 // Message flag is TRUE. This is easy, we just have to set both flags | |
462 // to TRUE... | |
463 roster_usr->flags |= ROSTER_FLAG_MSG; | |
464 roster_grp->flags |= ROSTER_FLAG_MSG; // group | |
236 | 465 // Append the roster_usr to unread_list, but avoid duplicates |
466 if (!g_slist_find(unread_list, roster_usr)) | |
467 unread_list = g_slist_append(unread_list, roster_usr); | |
148 | 468 } else { |
469 // Message flag is FALSE. | |
470 guint msg = FALSE; | |
471 roster_usr->flags &= ~ROSTER_FLAG_MSG; | |
236 | 472 if (unread_list) { |
473 GSList *node = g_slist_find(unread_list, roster_usr); | |
474 if (node) unread_list = g_slist_delete_link(unread_list, node); | |
475 } | |
148 | 476 // For the group value we need to watch all buddies in this group; |
477 // if one is flagged, then the group will be flagged. | |
478 // I will re-use sl_user and roster_usr here, as they aren't used | |
479 // anymore. | |
480 sl_user = roster_grp->list; | |
481 while (sl_user) { | |
482 roster_usr = (roster*)sl_user->data; | |
483 if (roster_usr->flags & ROSTER_FLAG_MSG) { | |
484 msg = TRUE; | |
485 break; | |
486 } | |
487 sl_user = g_slist_next(sl_user); | |
488 } | |
489 if (!msg) | |
490 roster_grp->flags &= ~ROSTER_FLAG_MSG; | |
491 else | |
492 roster_grp->flags |= ROSTER_FLAG_MSG; | |
493 // Actually the "else" part is useless, because the group | |
494 // ROSTER_FLAG_MSG should already be set... | |
495 } | |
496 } | |
497 | |
510
6c3cd3aa4a91
New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents:
509
diff
changeset
|
498 const char *roster_getname(const char *jid) |
6c3cd3aa4a91
New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents:
509
diff
changeset
|
499 { |
6c3cd3aa4a91
New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents:
509
diff
changeset
|
500 GSList *sl_user; |
6c3cd3aa4a91
New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents:
509
diff
changeset
|
501 roster *roster_usr; |
6c3cd3aa4a91
New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents:
509
diff
changeset
|
502 |
6c3cd3aa4a91
New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents:
509
diff
changeset
|
503 sl_user = roster_find(jid, jidsearch, |
6c3cd3aa4a91
New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents:
509
diff
changeset
|
504 ROSTER_TYPE_USER|ROSTER_TYPE_ROOM|ROSTER_TYPE_AGENT); |
6c3cd3aa4a91
New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents:
509
diff
changeset
|
505 if (sl_user == NULL) |
6c3cd3aa4a91
New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents:
509
diff
changeset
|
506 return NULL; // Not in the roster... |
6c3cd3aa4a91
New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents:
509
diff
changeset
|
507 |
6c3cd3aa4a91
New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents:
509
diff
changeset
|
508 roster_usr = (roster*)sl_user->data; |
6c3cd3aa4a91
New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents:
509
diff
changeset
|
509 return roster_usr->name; |
6c3cd3aa4a91
New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents:
509
diff
changeset
|
510 } |
6c3cd3aa4a91
New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents:
509
diff
changeset
|
511 |
89 | 512 void roster_settype(const char *jid, guint type) |
513 { | |
514 GSList *sl_user; | |
515 roster *roster_usr; | |
516 | |
517 if ((sl_user = roster_find(jid, jidsearch, 0)) == NULL) | |
518 return; | |
519 | |
520 roster_usr = (roster*)sl_user->data; | |
521 roster_usr->type = type; | |
522 } | |
523 | |
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
524 enum imstatus roster_getstatus(const char *jid, const char *resname) |
90 | 525 { |
526 GSList *sl_user; | |
527 roster *roster_usr; | |
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
528 res *p_res; |
90 | 529 |
530 sl_user = roster_find(jid, jidsearch, ROSTER_TYPE_USER|ROSTER_TYPE_AGENT); | |
531 if (sl_user == NULL) | |
532 return offline; // Not in the roster, anyway... | |
533 | |
534 roster_usr = (roster*)sl_user->data; | |
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
535 p_res = get_resource(roster_usr, resname); |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
536 if (p_res) |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
537 return p_res->status; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
538 return offline; |
90 | 539 } |
540 | |
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
541 const char *roster_getstatusmsg(const char *jid, const char *resname) |
318
45076d02eeef
The /status command can specify a status message
Mikael Berthe <mikael@lilotux.net>
parents:
301
diff
changeset
|
542 { |
45076d02eeef
The /status command can specify a status message
Mikael Berthe <mikael@lilotux.net>
parents:
301
diff
changeset
|
543 GSList *sl_user; |
45076d02eeef
The /status command can specify a status message
Mikael Berthe <mikael@lilotux.net>
parents:
301
diff
changeset
|
544 roster *roster_usr; |
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
545 res *p_res; |
318
45076d02eeef
The /status command can specify a status message
Mikael Berthe <mikael@lilotux.net>
parents:
301
diff
changeset
|
546 |
45076d02eeef
The /status command can specify a status message
Mikael Berthe <mikael@lilotux.net>
parents:
301
diff
changeset
|
547 sl_user = roster_find(jid, jidsearch, ROSTER_TYPE_USER|ROSTER_TYPE_AGENT); |
45076d02eeef
The /status command can specify a status message
Mikael Berthe <mikael@lilotux.net>
parents:
301
diff
changeset
|
548 if (sl_user == NULL) |
425
03f1e37759a6
roster_getstatusmsg() should return a pointer
Mikael Berthe <mikael@lilotux.net>
parents:
393
diff
changeset
|
549 return NULL; // Not in the roster, anyway... |
318
45076d02eeef
The /status command can specify a status message
Mikael Berthe <mikael@lilotux.net>
parents:
301
diff
changeset
|
550 |
45076d02eeef
The /status command can specify a status message
Mikael Berthe <mikael@lilotux.net>
parents:
301
diff
changeset
|
551 roster_usr = (roster*)sl_user->data; |
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
552 p_res = get_resource(roster_usr, resname); |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
553 if (p_res) |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
554 return p_res->status_msg; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
555 return NULL; |
318
45076d02eeef
The /status command can specify a status message
Mikael Berthe <mikael@lilotux.net>
parents:
301
diff
changeset
|
556 } |
45076d02eeef
The /status command can specify a status message
Mikael Berthe <mikael@lilotux.net>
parents:
301
diff
changeset
|
557 |
89 | 558 guint roster_gettype(const char *jid) |
559 { | |
560 GSList *sl_user; | |
561 roster *roster_usr; | |
562 | |
563 if ((sl_user = roster_find(jid, jidsearch, 0)) == NULL) | |
564 return 0; | |
565 | |
566 roster_usr = (roster*)sl_user->data; | |
567 return roster_usr->type; | |
568 } | |
569 | |
72 | 570 |
571 /* ### BuddyList functions ### */ | |
572 | |
120 | 573 // buddylist_set_hide_offline_buddies(hide) |
72 | 574 // "hide" values: 1=hide 0=show_all -1=invert |
120 | 575 void buddylist_set_hide_offline_buddies(int hide) |
72 | 576 { |
577 if (hide < 0) // NEG (invert) | |
578 hide_offline_buddies = !hide_offline_buddies; | |
579 else if (hide == 0) // FALSE (don't hide) | |
580 hide_offline_buddies = 0; | |
581 else // TRUE (hide) | |
582 hide_offline_buddies = 1; | |
583 } | |
584 | |
120 | 585 inline int buddylist_get_hide_offline_buddies(void) |
586 { | |
587 return hide_offline_buddies; | |
588 } | |
589 | |
72 | 590 // buddylist_build() |
591 // Creates the buddylist from the roster entries. | |
592 void buddylist_build(void) | |
593 { | |
594 GSList *sl_roster_elt = groups; | |
595 roster *roster_elt; | |
81 | 596 roster *roster_current_buddy = NULL; |
330 | 597 roster *roster_alternate_buddy = NULL; |
128 | 598 int shrunk_group; |
72 | 599 |
81 | 600 // We need to remember which buddy is selected. |
601 if (current_buddy) | |
602 roster_current_buddy = BUDDATA(current_buddy); | |
603 current_buddy = NULL; | |
330 | 604 if (alternate_buddy) |
605 roster_alternate_buddy = BUDDATA(alternate_buddy); | |
606 alternate_buddy = NULL; | |
81 | 607 |
72 | 608 // Destroy old buddylist |
609 if (buddylist) { | |
610 g_list_free(buddylist); | |
611 buddylist = NULL; | |
612 } | |
613 | |
614 // Create the new list | |
615 while (sl_roster_elt) { | |
616 GSList *sl_roster_usrelt; | |
617 roster *roster_usrelt; | |
147 | 618 guint pending_group = FALSE; |
72 | 619 roster_elt = (roster*) sl_roster_elt->data; |
620 | |
621 // Add the group now unless hide_offline_buddies is set, | |
622 // in which case we'll add it only if an online buddy belongs to it. | |
147 | 623 // We take care to keep the current_buddy in the list, too. |
624 if (!hide_offline_buddies || roster_elt == roster_current_buddy) | |
72 | 625 buddylist = g_list_append(buddylist, roster_elt); |
626 else | |
147 | 627 pending_group = TRUE; |
72 | 628 |
128 | 629 shrunk_group = roster_elt->flags & ROSTER_FLAG_HIDE; |
630 | |
72 | 631 sl_roster_usrelt = roster_elt->list; |
632 while (sl_roster_usrelt) { | |
633 roster_usrelt = (roster*) sl_roster_usrelt->data; | |
634 | |
635 // Buddy will be added if either: | |
636 // - hide_offline_buddies is FALSE | |
637 // - buddy is not offline | |
638 // - buddy has a lock (for example the buddy window is currently open) | |
639 // - buddy has a pending (non-read) message | |
128 | 640 // - group isn't hidden (shrunk) |
147 | 641 // - this is the current_buddy |
642 if (!hide_offline_buddies || roster_usrelt == roster_current_buddy || | |
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
643 (buddy_getstatus((gpointer)roster_usrelt, NULL) != offline) || |
72 | 644 (buddy_getflags((gpointer)roster_usrelt) & |
645 (ROSTER_FLAG_LOCK | ROSTER_FLAG_MSG))) { | |
646 // This user should be added. Maybe the group hasn't been added yet? | |
147 | 647 if (pending_group && |
648 (hide_offline_buddies || roster_usrelt == roster_current_buddy)) { | |
72 | 649 // It hasn't been done yet |
650 buddylist = g_list_append(buddylist, roster_elt); | |
651 pending_group = FALSE; | |
652 } | |
653 // Add user | |
128 | 654 // XXX Should we add the user if there is a message and |
655 // the group is shrunk? If so, we'd need to check LOCK flag too, | |
656 // perhaps... | |
657 if (!shrunk_group) | |
658 buddylist = g_list_append(buddylist, roster_usrelt); | |
72 | 659 } |
660 | |
661 sl_roster_usrelt = g_slist_next(sl_roster_usrelt); | |
662 } | |
663 sl_roster_elt = g_slist_next(sl_roster_elt); | |
664 } | |
78 | 665 |
81 | 666 // Check if we can find our saved current_buddy... |
667 if (roster_current_buddy) | |
668 current_buddy = g_list_find(buddylist, roster_current_buddy); | |
330 | 669 if (roster_alternate_buddy) |
670 alternate_buddy = g_list_find(buddylist, roster_alternate_buddy); | |
78 | 671 // current_buddy initialization |
672 if (!current_buddy || (g_list_position(buddylist, current_buddy) == -1)) | |
81 | 673 current_buddy = g_list_first(buddylist); |
72 | 674 } |
675 | |
676 // buddy_hide_group(roster, hide) | |
677 // "hide" values: 1=hide 0=show_all -1=invert | |
678 void buddy_hide_group(gpointer rosterdata, int hide) | |
679 { | |
207 | 680 roster *roster_usr = rosterdata; |
72 | 681 if (hide > 0) // TRUE (hide) |
207 | 682 roster_usr->flags |= ROSTER_FLAG_HIDE; |
72 | 683 else if (hide < 0) // NEG (invert) |
207 | 684 roster_usr->flags ^= ROSTER_FLAG_HIDE; |
72 | 685 else // FALSE (don't hide) |
207 | 686 roster_usr->flags &= ~ROSTER_FLAG_HIDE; |
72 | 687 } |
688 | |
689 const char *buddy_getjid(gpointer rosterdata) | |
690 { | |
207 | 691 roster *roster_usr = rosterdata; |
692 return roster_usr->jid; | |
693 } | |
694 | |
210 | 695 // buddy_setgroup() |
696 // Change the group of current buddy | |
697 // | |
506
74dcd0df532e
"/move" does not jump to the buddy in the new group
Mikael Berthe <mikael@lilotux.net>
parents:
501
diff
changeset
|
698 // Warning! This function changes the specified buddy! |
74dcd0df532e
"/move" does not jump to the buddy in the new group
Mikael Berthe <mikael@lilotux.net>
parents:
501
diff
changeset
|
699 // Warning! Old buddy is deleted, so you can't access to its jid/name after |
74dcd0df532e
"/move" does not jump to the buddy in the new group
Mikael Berthe <mikael@lilotux.net>
parents:
501
diff
changeset
|
700 // calling this function (they are free'd). |
210 | 701 void buddy_setgroup(gpointer rosterdata, char *newgroupname) |
702 { | |
703 roster *roster_usr = rosterdata; | |
704 GSList **sl_group; | |
705 GSList *sl_clone; | |
706 roster *roster_clone; | |
707 | |
708 // A group has no group :) | |
709 if (roster_usr->type & ROSTER_TYPE_GROUP) return; | |
710 | |
711 // Remove the buddy from current group | |
712 sl_group = &((roster*)((GSList*)roster_usr->list)->data)->list; | |
713 *sl_group = g_slist_remove(*sl_group, rosterdata); | |
393 | 714 |
210 | 715 // Add the buddy to its new group; actually we "clone" this buddy... |
716 sl_clone = roster_add_user(roster_usr->jid, roster_usr->name, | |
562 | 717 newgroupname, roster_usr->type); |
210 | 718 roster_clone = (roster*)sl_clone->data; |
509
cd52ddef5ce1
Fix a bug when moving a chatroom to a new group
Mikael Berthe <mikael@lilotux.net>
parents:
506
diff
changeset
|
719 roster_clone->subscription = roster_usr->subscription; |
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
720 roster_clone->flags = roster_usr->flags; |
509
cd52ddef5ce1
Fix a bug when moving a chatroom to a new group
Mikael Berthe <mikael@lilotux.net>
parents:
506
diff
changeset
|
721 |
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
722 roster_clone->resource = roster_usr->resource; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
723 roster_usr->resource = NULL; |
509
cd52ddef5ce1
Fix a bug when moving a chatroom to a new group
Mikael Berthe <mikael@lilotux.net>
parents:
506
diff
changeset
|
724 roster_clone->nickname = roster_usr->nickname; |
cd52ddef5ce1
Fix a bug when moving a chatroom to a new group
Mikael Berthe <mikael@lilotux.net>
parents:
506
diff
changeset
|
725 roster_usr->nickname = NULL; |
548
265c50238a48
Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
726 roster_clone->topic = roster_usr->topic; |
265c50238a48
Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
727 roster_usr->topic = NULL; |
210 | 728 |
729 // Free old buddy | |
221 | 730 if (roster_usr->jid) g_free((gchar*)roster_usr->jid); |
731 if (roster_usr->name) g_free((gchar*)roster_usr->name); | |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
732 if (roster_usr->nickname) g_free((gchar*)roster_usr->nickname); |
548
265c50238a48
Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
733 if (roster_usr->topic) g_free((gchar*)roster_usr->topic); |
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
734 free_all_resources(&roster_usr->resource); |
210 | 735 g_free(roster_usr); |
736 | |
212 | 737 buddylist = g_list_append(buddylist, roster_clone); |
506
74dcd0df532e
"/move" does not jump to the buddy in the new group
Mikael Berthe <mikael@lilotux.net>
parents:
501
diff
changeset
|
738 // We must have current_buddy pointing to the cloned buddy, if this is |
74dcd0df532e
"/move" does not jump to the buddy in the new group
Mikael Berthe <mikael@lilotux.net>
parents:
501
diff
changeset
|
739 // the one we have moved. Same for alternate_buddy. |
74dcd0df532e
"/move" does not jump to the buddy in the new group
Mikael Berthe <mikael@lilotux.net>
parents:
501
diff
changeset
|
740 if (rosterdata == BUDDATA(current_buddy)) { |
74dcd0df532e
"/move" does not jump to the buddy in the new group
Mikael Berthe <mikael@lilotux.net>
parents:
501
diff
changeset
|
741 current_buddy = g_list_find(buddylist, roster_clone); |
74dcd0df532e
"/move" does not jump to the buddy in the new group
Mikael Berthe <mikael@lilotux.net>
parents:
501
diff
changeset
|
742 // If new new group is folded, the current_buddy will be lost, and the |
74dcd0df532e
"/move" does not jump to the buddy in the new group
Mikael Berthe <mikael@lilotux.net>
parents:
501
diff
changeset
|
743 // chat window won't be correctly refreshed. So we make sure it isn't... |
74dcd0df532e
"/move" does not jump to the buddy in the new group
Mikael Berthe <mikael@lilotux.net>
parents:
501
diff
changeset
|
744 ((roster*)((GSList*)roster_clone->list)->data)->flags &= ~ROSTER_FLAG_HIDE; |
74dcd0df532e
"/move" does not jump to the buddy in the new group
Mikael Berthe <mikael@lilotux.net>
parents:
501
diff
changeset
|
745 } |
74dcd0df532e
"/move" does not jump to the buddy in the new group
Mikael Berthe <mikael@lilotux.net>
parents:
501
diff
changeset
|
746 if (alternate_buddy && BUDDATA(alternate_buddy) == rosterdata) |
74dcd0df532e
"/move" does not jump to the buddy in the new group
Mikael Berthe <mikael@lilotux.net>
parents:
501
diff
changeset
|
747 alternate_buddy = g_list_find(buddylist, roster_clone); |
212 | 748 |
210 | 749 buddylist_build(); |
750 } | |
751 | |
207 | 752 void buddy_setname(gpointer rosterdata, char *newname) |
753 { | |
754 roster *roster_usr = rosterdata; | |
209 | 755 GSList **sl_group; |
207 | 756 |
757 // TODO For groups, we need to check for unicity | |
758 // However, renaming a group boils down to moving all its buddies to | |
759 // another group, so calling this function is not really necessary... | |
760 if (roster_usr->type & ROSTER_TYPE_GROUP) return; | |
761 | |
762 if (roster_usr->name) { | |
763 g_free((gchar*)roster_usr->name); | |
764 roster_usr->name = NULL; | |
765 } | |
766 if (newname) | |
767 roster_usr->name = g_strdup(newname); | |
209 | 768 |
769 // We need to resort the group list | |
770 sl_group = &((roster*)((GSList*)roster_usr->list)->data)->list; | |
771 *sl_group = g_slist_sort(*sl_group, (GCompareFunc)&roster_compare_name); | |
772 | |
773 buddylist_build(); | |
72 | 774 } |
775 | |
776 const char *buddy_getname(gpointer rosterdata) | |
777 { | |
207 | 778 roster *roster_usr = rosterdata; |
779 return roster_usr->name; | |
780 } | |
781 | |
548
265c50238a48
Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
782 // buddy_setnickname(buddy, newnickname) |
265c50238a48
Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
783 // Only for chatrooms |
469
a926523d2392
Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
468
diff
changeset
|
784 void buddy_setnickname(gpointer rosterdata, const char *newname) |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
785 { |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
786 roster *roster_usr = rosterdata; |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
787 |
532
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
520
diff
changeset
|
788 if (!(roster_usr->type & ROSTER_TYPE_ROOM)) return; |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
789 |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
790 if (roster_usr->nickname) { |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
791 g_free((gchar*)roster_usr->nickname); |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
792 roster_usr->nickname = NULL; |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
793 } |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
794 if (newname) |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
795 roster_usr->nickname = g_strdup(newname); |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
796 } |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
797 |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
798 const char *buddy_getnickname(gpointer rosterdata) |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
799 { |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
800 roster *roster_usr = rosterdata; |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
801 return roster_usr->nickname; |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
802 } |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
803 |
548
265c50238a48
Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
804 // buddy_settopic(buddy, newtopic) |
265c50238a48
Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
805 // Only for chatrooms |
265c50238a48
Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
806 void buddy_settopic(gpointer rosterdata, const char *newtopic) |
265c50238a48
Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
807 { |
265c50238a48
Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
808 roster *roster_usr = rosterdata; |
265c50238a48
Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
809 |
265c50238a48
Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
810 if (!(roster_usr->type & ROSTER_TYPE_ROOM)) return; |
265c50238a48
Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
811 |
265c50238a48
Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
812 if (roster_usr->topic) { |
265c50238a48
Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
813 g_free((gchar*)roster_usr->topic); |
265c50238a48
Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
814 roster_usr->topic = NULL; |
265c50238a48
Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
815 } |
265c50238a48
Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
816 if (newtopic) |
265c50238a48
Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
817 roster_usr->topic = g_strdup(newtopic); |
265c50238a48
Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
818 } |
265c50238a48
Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
819 |
265c50238a48
Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
820 const char *buddy_gettopic(gpointer rosterdata) |
265c50238a48
Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
821 { |
265c50238a48
Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
822 roster *roster_usr = rosterdata; |
265c50238a48
Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
823 return roster_usr->topic; |
265c50238a48
Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
824 } |
265c50238a48
Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
825 |
207 | 826 // buddy_getgroupname() |
827 // Returns a pointer on buddy's group name. | |
828 const char *buddy_getgroupname(gpointer rosterdata) | |
829 { | |
830 roster *roster_usr = rosterdata; | |
831 | |
832 if (roster_usr->type & ROSTER_TYPE_GROUP) | |
833 return roster_usr->name; | |
834 | |
835 // This is a user | |
836 return ((roster*)((GSList*)roster_usr->list)->data)->name; | |
72 | 837 } |
838 | |
166 | 839 // buddy_getgroup() |
840 // Returns a pointer on buddy's group. | |
841 gpointer buddy_getgroup(gpointer rosterdata) | |
842 { | |
207 | 843 roster *roster_usr = rosterdata; |
166 | 844 |
207 | 845 if (roster_usr->type & ROSTER_TYPE_GROUP) |
166 | 846 return rosterdata; |
847 | |
848 // This is a user | |
207 | 849 return (gpointer)((GSList*)roster_usr->list)->data; |
166 | 850 } |
851 | |
489
21ab22a60bcb
Auto-convert a roster item to "room" type when receiving a groupchat message
Mikael Berthe <mikael@lilotux.net>
parents:
483
diff
changeset
|
852 void buddy_settype(gpointer rosterdata, guint type) |
21ab22a60bcb
Auto-convert a roster item to "room" type when receiving a groupchat message
Mikael Berthe <mikael@lilotux.net>
parents:
483
diff
changeset
|
853 { |
21ab22a60bcb
Auto-convert a roster item to "room" type when receiving a groupchat message
Mikael Berthe <mikael@lilotux.net>
parents:
483
diff
changeset
|
854 roster *roster_usr = rosterdata; |
21ab22a60bcb
Auto-convert a roster item to "room" type when receiving a groupchat message
Mikael Berthe <mikael@lilotux.net>
parents:
483
diff
changeset
|
855 roster_usr->type = type; |
21ab22a60bcb
Auto-convert a roster item to "room" type when receiving a groupchat message
Mikael Berthe <mikael@lilotux.net>
parents:
483
diff
changeset
|
856 } |
21ab22a60bcb
Auto-convert a roster item to "room" type when receiving a groupchat message
Mikael Berthe <mikael@lilotux.net>
parents:
483
diff
changeset
|
857 |
72 | 858 guint buddy_gettype(gpointer rosterdata) |
859 { | |
207 | 860 roster *roster_usr = rosterdata; |
861 return roster_usr->type; | |
72 | 862 } |
863 | |
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
864 enum imstatus buddy_getstatus(gpointer rosterdata, const char *resname) |
72 | 865 { |
207 | 866 roster *roster_usr = rosterdata; |
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
867 res *p_res = get_resource(roster_usr, resname); |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
868 if (p_res) |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
869 return p_res->status; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
870 return offline; |
72 | 871 } |
872 | |
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
873 const char *buddy_getstatusmsg(gpointer rosterdata, const char *resname) |
221 | 874 { |
875 roster *roster_usr = rosterdata; | |
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
876 res *p_res = get_resource(roster_usr, resname); |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
877 if (p_res) |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
878 return p_res->status_msg; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
879 return NULL; |
221 | 880 } |
881 | |
439
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
882 gchar buddy_getresourceprio(gpointer rosterdata, const char *resname) |
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
883 { |
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
884 roster *roster_usr = rosterdata; |
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
885 res *p_res = get_resource(roster_usr, resname); |
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
886 if (p_res) |
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
887 return p_res->prio; |
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
888 return 0; |
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
889 } |
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
890 |
572
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
891 enum imrole buddy_getrole(gpointer rosterdata, const char *resname) |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
892 { |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
893 roster *roster_usr = rosterdata; |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
894 res *p_res = get_resource(roster_usr, resname); |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
895 if (p_res) |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
896 return p_res->role; |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
897 return role_none; |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
898 } |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
899 |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
900 enum imaffiliation buddy_getaffil(gpointer rosterdata, const char *resname) |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
901 { |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
902 roster *roster_usr = rosterdata; |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
903 res *p_res = get_resource(roster_usr, resname); |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
904 if (p_res) |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
905 return p_res->affil; |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
906 return affil_none; |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
907 } |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
908 |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
909 const char *buddy_getrjid(gpointer rosterdata, const char *resname) |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
910 { |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
911 roster *roster_usr = rosterdata; |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
912 res *p_res = get_resource(roster_usr, resname); |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
913 if (p_res) |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
914 return p_res->realjid; |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
915 return NULL; |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
916 } |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
917 |
439
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
918 // buddy_getresources(roster_data) |
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
919 // Return a singly-linked-list of resource names |
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
920 // Note: the caller should free the list (and data) after use |
501
7c1ca00070e8
Add COMPL_RESOURCE (resource completion category)
Mikael Berthe <mikael@lilotux.net>
parents:
494
diff
changeset
|
921 // If roster_data is null, the current buddy is selected |
439
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
922 GSList *buddy_getresources(gpointer rosterdata) |
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
923 { |
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
924 roster *roster_usr = rosterdata; |
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
925 GSList *reslist = NULL, *lp; |
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
926 |
501
7c1ca00070e8
Add COMPL_RESOURCE (resource completion category)
Mikael Berthe <mikael@lilotux.net>
parents:
494
diff
changeset
|
927 if (!roster_usr) { |
7c1ca00070e8
Add COMPL_RESOURCE (resource completion category)
Mikael Berthe <mikael@lilotux.net>
parents:
494
diff
changeset
|
928 if (!current_buddy) return NULL; |
7c1ca00070e8
Add COMPL_RESOURCE (resource completion category)
Mikael Berthe <mikael@lilotux.net>
parents:
494
diff
changeset
|
929 roster_usr = BUDDATA(current_buddy); |
7c1ca00070e8
Add COMPL_RESOURCE (resource completion category)
Mikael Berthe <mikael@lilotux.net>
parents:
494
diff
changeset
|
930 } |
439
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
931 for (lp = roster_usr->resource; lp; lp = g_slist_next(lp)) |
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
932 reslist = g_slist_append(reslist, g_strdup(((res*)lp->data)->name)); |
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
933 |
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
934 return reslist; |
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
935 } |
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
936 |
539 | 937 // buddy_isresource(roster_data) |
938 // Return true if there is at least one resource | |
939 // (which means, for a room, that it isn't empty) | |
940 int buddy_isresource(gpointer rosterdata) | |
941 { | |
942 roster *roster_usr = rosterdata; | |
943 if (!roster_usr) | |
944 return FALSE; | |
945 if (roster_usr->resource) | |
946 return TRUE; | |
947 return FALSE; | |
948 } | |
949 | |
468
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
950 // buddy_resource_setname(roster_data, oldname, newname) |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
951 // Useful for nickname change in a MUC room |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
952 void buddy_resource_setname(gpointer rosterdata, const char *resname, |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
953 const char *newname) |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
954 { |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
955 roster *roster_usr = rosterdata; |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
956 res *p_res = get_resource(roster_usr, resname); |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
957 if (p_res) { |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
958 if (p_res->name) { |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
959 g_free((gchar*)p_res->name); |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
960 p_res->name = NULL; |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
961 } |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
962 if (newname) |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
963 p_res->name = g_strdup(newname); |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
964 } |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
965 } |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
966 |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
967 // buddy_del_all_resources() |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
968 // Remove all resources from the specified buddy |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
969 void buddy_del_all_resources(gpointer rosterdata) |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
970 { |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
971 roster *roster_usr = rosterdata; |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
972 |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
973 while (roster_usr->resource) { |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
974 res *r = roster_usr->resource->data; |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
975 del_resource(roster_usr, r->name); |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
976 } |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
977 } |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
978 |
119 | 979 // buddy_setflags() |
980 // Set one or several flags to value (TRUE/FALSE) | |
981 void buddy_setflags(gpointer rosterdata, guint flags, guint value) | |
982 { | |
207 | 983 roster *roster_usr = rosterdata; |
119 | 984 if (value) |
207 | 985 roster_usr->flags |= flags; |
119 | 986 else |
207 | 987 roster_usr->flags &= ~flags; |
119 | 988 } |
989 | |
72 | 990 guint buddy_getflags(gpointer rosterdata) |
991 { | |
207 | 992 roster *roster_usr = rosterdata; |
993 return roster_usr->flags; | |
72 | 994 } |
995 | |
480 | 996 // buddy_search_jid(jid) |
997 // Look for a buddy with specified jid. | |
998 // Search begins at buddylist; if no match is found in the the buddylist, | |
999 // return NULL; | |
1000 GList *buddy_search_jid(char *jid) | |
1001 { | |
1002 GList *buddy; | |
1003 roster *roster_usr; | |
1004 | |
1005 if (!buddylist) return NULL; | |
1006 | |
1007 for (buddy = buddylist; buddy; buddy = g_list_next(buddy)) { | |
1008 roster_usr = (roster*)buddy->data; | |
1009 if (roster_usr->jid && !strcasecmp(roster_usr->jid, jid)) | |
1010 return buddy; | |
1011 } | |
1012 return NULL; | |
1013 } | |
1014 | |
265 | 1015 // buddy_search(string) |
1016 // Look for a buddy whose name or jid contains string. | |
1017 // Search begins at current_buddy; if no match is found in the the buddylist, | |
1018 // return NULL; | |
1019 GList *buddy_search(char *string) | |
1020 { | |
1021 GList *buddy = current_buddy; | |
1022 roster *roster_usr; | |
1023 if (!buddylist || !current_buddy) return NULL; | |
1024 for (;;) { | |
1025 buddy = g_list_next(buddy); | |
1026 if (!buddy) | |
1027 buddy = buddylist; | |
1028 | |
1029 roster_usr = (roster*)buddy->data; | |
1030 if (roster_usr->jid && strcasestr(roster_usr->jid, string)) | |
1031 return buddy; | |
1032 if (roster_usr->name && strcasestr(roster_usr->name, string)) | |
1033 return buddy; | |
1034 | |
1035 if (buddy == current_buddy) | |
1036 return NULL; // Back to the beginning, and no match found | |
1037 } | |
1038 } | |
1039 | |
532
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
520
diff
changeset
|
1040 // foreach_buddy(roster_type, pfunction, param) |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
520
diff
changeset
|
1041 // Call pfunction(buddy, param) for each buddy from the roster with |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
520
diff
changeset
|
1042 // type matching roster_type. |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
520
diff
changeset
|
1043 void foreach_buddy(guint roster_type, |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
520
diff
changeset
|
1044 void (*pfunc)(gpointer rosterdata, void *param), |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
520
diff
changeset
|
1045 void *param) |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
520
diff
changeset
|
1046 { |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
520
diff
changeset
|
1047 GSList *sl_roster_elt = groups; |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
520
diff
changeset
|
1048 roster *roster_elt; |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
520
diff
changeset
|
1049 GSList *sl_roster_usrelt; |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
520
diff
changeset
|
1050 roster *roster_usrelt; |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
520
diff
changeset
|
1051 |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
520
diff
changeset
|
1052 while (sl_roster_elt) { // group list loop |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
520
diff
changeset
|
1053 roster_elt = (roster*) sl_roster_elt->data; |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
520
diff
changeset
|
1054 sl_roster_usrelt = roster_elt->list; |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
520
diff
changeset
|
1055 while (sl_roster_usrelt) { // user list loop |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
520
diff
changeset
|
1056 roster_usrelt = (roster*) sl_roster_usrelt->data; |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
520
diff
changeset
|
1057 |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
520
diff
changeset
|
1058 if (roster_usrelt->type & roster_type) |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
520
diff
changeset
|
1059 pfunc(roster_usrelt, param); |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
520
diff
changeset
|
1060 |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
520
diff
changeset
|
1061 sl_roster_usrelt = g_slist_next(sl_roster_usrelt); |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
520
diff
changeset
|
1062 } |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
520
diff
changeset
|
1063 sl_roster_elt = g_slist_next(sl_roster_elt); |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
520
diff
changeset
|
1064 } |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
520
diff
changeset
|
1065 } |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
520
diff
changeset
|
1066 |
225 | 1067 // compl_list(type) |
1068 // Returns a list of jid's or groups. (For commands completion) | |
1069 // type: ROSTER_TYPE_USER (jid's) or ROSTER_TYPE_GROUP (group names) | |
1070 // The list should be freed by the caller after use. | |
1071 GSList *compl_list(guint type) | |
1072 { | |
1073 GSList *list = NULL; | |
1074 GList *buddy = buddylist; | |
1075 | |
1076 for ( ; buddy ; buddy = g_list_next(buddy)) { | |
1077 guint btype = buddy_gettype(BUDDATA(buddy)); | |
1078 | |
1079 if (type == ROSTER_TYPE_GROUP) { // (group names) | |
1080 if (btype == ROSTER_TYPE_GROUP) { | |
1081 const char *bname = buddy_getname(BUDDATA(buddy)); | |
1082 if ((bname) && (*bname)) | |
1083 list = g_slist_append(list, g_strdup(bname)); | |
1084 } | |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
1085 } else { // ROSTER_TYPE_USER (jid) (or agent, or chatroom...) |
225 | 1086 const char *bjid = buddy_getjid(BUDDATA(buddy)); |
1087 if (bjid) | |
1088 list = g_slist_append(list, g_strdup(bjid)); | |
1089 } | |
1090 } | |
1091 | |
1092 return list; | |
1093 } | |
1094 | |
236 | 1095 // unread_msg(rosterdata) |
1096 // Return the next buddy with an unread message. If the parameter is NULL, | |
1097 // return the first buddy with an unread message. | |
1098 gpointer unread_msg(gpointer rosterdata) | |
1099 { | |
1100 GSList *unread, *next_unread; | |
1101 | |
564 | 1102 if (!unread_list) |
1103 return NULL; | |
1104 | |
236 | 1105 // First unread message |
564 | 1106 if (!rosterdata) |
1107 return unread_list->data; | |
236 | 1108 |
1109 unread = g_slist_find(unread_list, rosterdata); | |
564 | 1110 if (!unread) |
1111 return unread_list->data; | |
236 | 1112 |
1113 next_unread = g_slist_next(unread); | |
564 | 1114 if (next_unread) |
1115 return next_unread->data; | |
236 | 1116 return unread_list->data; |
1117 } | |
576 | 1118 |
580 | 1119 /* vim: set expandtab cindent cinoptions=>2\:2(0: For Vim users... */ |