72
|
1 /*
|
|
2 * roster.c -- Local roster implementation
|
|
3 *
|
|
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
|
|
22 #include <string.h>
|
|
23
|
|
24 #include "roster.h"
|
|
25
|
|
26
|
|
27 /* This is a private structure type for the roster */
|
|
28
|
|
29 typedef struct {
|
207
|
30 const gchar *name;
|
|
31 const gchar *jid;
|
72
|
32 guint type;
|
|
33 enum imstatus status;
|
|
34 guint flags;
|
|
35 // list: user -> points to his group; group -> points to its users list
|
|
36 GSList *list;
|
|
37 } roster;
|
|
38
|
|
39
|
|
40 /* ### Variables ### */
|
|
41
|
|
42 static int hide_offline_buddies;
|
|
43 static GSList *groups;
|
|
44 GList *buddylist;
|
78
|
45 GList *current_buddy;
|
72
|
46
|
|
47 #ifdef MCABBER_TESTUNIT
|
|
48 // Export groups for testing routines
|
|
49 GSList **pgroups = &groups;
|
|
50 #endif
|
|
51
|
|
52
|
|
53 /* ### Roster functions ### */
|
|
54
|
|
55 // Comparison function used to search in the roster (compares jids and types)
|
|
56 gint roster_compare_jid_type(roster *a, roster *b) {
|
89
|
57 if (! (a->type & b->type))
|
72
|
58 return -1; // arbitrary (but should be != , of course)
|
|
59 return strcasecmp(a->jid, b->jid);
|
|
60 }
|
|
61
|
|
62 // Comparison function used to sort the roster (by name)
|
|
63 gint roster_compare_name(roster *a, roster *b) {
|
|
64 return strcasecmp(a->name, b->name);
|
|
65 }
|
|
66
|
|
67 // Finds a roster element (user, group, agent...), by jid or name
|
89
|
68 // If roster_type is 0, returns match of any type.
|
72
|
69 // Returns the roster GSList element, or NULL if jid/name not found
|
78
|
70 GSList *roster_find(const char *jidname, enum findwhat type, guint roster_type)
|
72
|
71 {
|
|
72 GSList *sl_roster_elt = groups;
|
|
73 GSList *res;
|
|
74 roster sample;
|
|
75 GCompareFunc comp;
|
|
76
|
192
|
77 if (!jidname) return NULL;
|
72
|
78
|
89
|
79 if (!roster_type)
|
|
80 roster_type = ROSTER_TYPE_USER|ROSTER_TYPE_AGENT|ROSTER_TYPE_GROUP;
|
|
81
|
72
|
82 sample.type = roster_type;
|
|
83 if (type == jidsearch) {
|
|
84 sample.jid = jidname;
|
|
85 comp = (GCompareFunc)&roster_compare_jid_type;
|
|
86 } else if (type == namesearch) {
|
|
87 sample.name = jidname;
|
|
88 comp = (GCompareFunc)&roster_compare_name;
|
|
89 } else
|
|
90 return NULL; // should not happen
|
|
91
|
|
92 while (sl_roster_elt) {
|
|
93 roster *roster_elt = (roster*)sl_roster_elt->data;
|
|
94 if (roster_type & ROSTER_TYPE_GROUP) {
|
|
95 if ((type == namesearch) && !strcasecmp(jidname, roster_elt->name))
|
|
96 return sl_roster_elt;
|
|
97 } else {
|
|
98 res = g_slist_find_custom(roster_elt->list, &sample, comp);
|
|
99 if (res)
|
|
100 return res;
|
|
101 }
|
|
102 sl_roster_elt = g_slist_next(sl_roster_elt);
|
|
103 }
|
|
104 return NULL;
|
|
105 }
|
|
106
|
|
107 // Returns pointer to new group, or existing group with that name
|
78
|
108 GSList *roster_add_group(const char *name)
|
72
|
109 {
|
|
110 roster *roster_grp;
|
|
111 // #1 Check name doesn't already exist
|
|
112 if (!roster_find(name, namesearch, ROSTER_TYPE_GROUP)) {
|
|
113 // #2 Create the group node
|
|
114 roster_grp = g_new0(roster, 1);
|
|
115 roster_grp->name = g_strdup(name);
|
|
116 roster_grp->type = ROSTER_TYPE_GROUP;
|
|
117 // #3 Insert (sorted)
|
|
118 groups = g_slist_insert_sorted(groups, roster_grp,
|
|
119 (GCompareFunc)&roster_compare_name);
|
|
120 }
|
|
121 return roster_find(name, namesearch, ROSTER_TYPE_GROUP);
|
|
122 }
|
|
123
|
|
124 // Returns a pointer to the new user, or existing user with that name
|
78
|
125 GSList *roster_add_user(const char *jid, const char *name, const char *group,
|
|
126 guint type)
|
72
|
127 {
|
|
128 roster *roster_usr;
|
|
129 roster *my_group;
|
|
130 GSList *slist;
|
|
131
|
|
132 if ((type != ROSTER_TYPE_USER) && (type != ROSTER_TYPE_AGENT)) {
|
|
133 // XXX Error message?
|
|
134 return NULL;
|
|
135 }
|
|
136
|
78
|
137 // Let's be arbitrary: default group has an empty name ("").
|
|
138 if (!group) group = "";
|
|
139
|
72
|
140 // #1 Check this user doesn't already exist
|
192
|
141 slist = roster_find(jid, jidsearch, ROSTER_TYPE_USER|ROSTER_TYPE_AGENT);
|
|
142 if (slist) return slist;
|
72
|
143 // #2 add group if necessary
|
|
144 slist = roster_add_group(group);
|
|
145 if (!slist) return NULL;
|
|
146 my_group = (roster*)slist->data;
|
|
147 // #3 Create user node
|
|
148 roster_usr = g_new0(roster, 1);
|
|
149 roster_usr->jid = g_strdup(jid);
|
78
|
150 if (name) {
|
|
151 roster_usr->name = g_strdup(name);
|
|
152 } else {
|
|
153 gchar *p, *str = g_strdup(jid);
|
80
|
154 p = strstr(str, "/");
|
78
|
155 if (p) *p = '\0';
|
|
156 roster_usr->name = g_strdup(str);
|
|
157 g_free(str);
|
|
158 }
|
72
|
159 roster_usr->type = type; //ROSTER_TYPE_USER;
|
|
160 roster_usr->list = slist; // (my_group SList element)
|
|
161 // #4 Insert node (sorted)
|
|
162 my_group->list = g_slist_insert_sorted(my_group->list, roster_usr,
|
|
163 (GCompareFunc)&roster_compare_name);
|
|
164 return roster_find(jid, jidsearch, type);
|
|
165 }
|
|
166
|
|
167 // Removes user (jid) from roster, frees allocated memory
|
78
|
168 void roster_del_user(const char *jid)
|
72
|
169 {
|
|
170 GSList *sl_user, *sl_group;
|
|
171 GSList **sl_group_listptr;
|
|
172 roster *roster_usr;
|
|
173
|
89
|
174 sl_user = roster_find(jid, jidsearch, ROSTER_TYPE_USER|ROSTER_TYPE_AGENT);
|
|
175 if (sl_user == NULL)
|
72
|
176 return;
|
|
177 // Let's free memory (jid, name)
|
|
178 roster_usr = (roster*)sl_user->data;
|
|
179 if (roster_usr->jid)
|
78
|
180 g_free((gchar*)roster_usr->jid);
|
72
|
181 if (roster_usr->name)
|
78
|
182 g_free((gchar*)roster_usr->name);
|
210
|
183 g_free(roster_usr);
|
72
|
184
|
|
185 // That's a little complex, we need to dereference twice
|
|
186 sl_group = ((roster*)sl_user->data)->list;
|
|
187 sl_group_listptr = &((roster*)(sl_group->data))->list;
|
|
188 *sl_group_listptr = g_slist_delete_link(*sl_group_listptr, sl_user);
|
78
|
189
|
|
190 // We need to rebuild the list
|
|
191 if (current_buddy)
|
|
192 buddylist_build();
|
210
|
193 // TODO What we could do, too, is to check if the deleted node is
|
78
|
194 // current_buddy, in which case we could move current_buddy to the
|
|
195 // previous (or next) node.
|
72
|
196 }
|
|
197
|
210
|
198 // Free all roster data and call buddylist_build() to free the buddylist.
|
164
|
199 void roster_free(void)
|
|
200 {
|
|
201 GSList *sl_grp = groups;
|
|
202
|
|
203 // Walk through groups
|
|
204 while (sl_grp) {
|
|
205 roster *roster_grp = (roster*)sl_grp->data;
|
|
206 GSList *sl_usr = roster_grp->list;
|
|
207 // Walk through this group users
|
|
208 while (sl_usr) {
|
|
209 roster *roster_usr = (roster*)sl_usr->data;
|
|
210 // Free name and jid
|
|
211 if (roster_usr->jid)
|
|
212 g_free((gchar*)roster_usr->jid);
|
|
213 if (roster_usr->name)
|
|
214 g_free((gchar*)roster_usr->name);
|
|
215 sl_usr = g_slist_next(sl_usr);
|
|
216 }
|
|
217 // Free group's users list
|
|
218 if (roster_grp->list)
|
|
219 g_slist_free(roster_grp->list);
|
|
220 // Free group's name and jid
|
|
221 if (roster_grp->jid)
|
|
222 g_free((gchar*)roster_grp->jid);
|
|
223 if (roster_grp->name)
|
|
224 g_free((gchar*)roster_grp->name);
|
|
225 sl_grp = g_slist_next(sl_grp);
|
|
226 }
|
|
227 // Free groups list
|
|
228 if (groups) {
|
|
229 g_slist_free(groups);
|
|
230 groups = NULL;
|
|
231 // Update (i.e. free) buddylist
|
|
232 if (buddylist)
|
|
233 buddylist_build();
|
|
234 }
|
|
235 }
|
|
236
|
78
|
237 void roster_setstatus(const char *jid, enum imstatus bstat)
|
72
|
238 {
|
|
239 GSList *sl_user;
|
|
240 roster *roster_usr;
|
|
241
|
89
|
242 sl_user = roster_find(jid, jidsearch, ROSTER_TYPE_USER|ROSTER_TYPE_AGENT);
|
92
|
243 // If we can't find it, we add it
|
89
|
244 if (sl_user == NULL)
|
92
|
245 sl_user = roster_add_user(jid, NULL, NULL, ROSTER_TYPE_USER);
|
72
|
246
|
|
247 roster_usr = (roster*)sl_user->data;
|
|
248 roster_usr->status = bstat;
|
|
249 }
|
|
250
|
78
|
251 // roster_setflags()
|
|
252 // Set one or several flags to value (TRUE/FALSE)
|
80
|
253 void roster_setflags(const char *jid, guint flags, guint value)
|
78
|
254 {
|
|
255 GSList *sl_user;
|
|
256 roster *roster_usr;
|
|
257
|
89
|
258 sl_user = roster_find(jid, jidsearch, ROSTER_TYPE_USER|ROSTER_TYPE_AGENT);
|
|
259 if (sl_user == NULL)
|
78
|
260 return;
|
|
261
|
|
262 roster_usr = (roster*)sl_user->data;
|
|
263 if (value)
|
|
264 roster_usr->flags |= flags;
|
|
265 else
|
|
266 roster_usr->flags &= ~flags;
|
|
267 }
|
148
|
268
|
|
269 // roster_msg_setflag()
|
|
270 // Set the ROSTER_FLAG_MSG to the given value for the given jid.
|
|
271 // It will update the buddy's group message flag.
|
|
272 void roster_msg_setflag(const char *jid, guint value)
|
|
273 {
|
|
274 GSList *sl_user;
|
|
275 roster *roster_usr, *roster_grp;
|
|
276
|
|
277 sl_user = roster_find(jid, jidsearch, ROSTER_TYPE_USER|ROSTER_TYPE_AGENT);
|
|
278 if (sl_user == NULL)
|
|
279 return;
|
|
280
|
|
281 roster_usr = (roster*)sl_user->data;
|
|
282 roster_grp = (roster*)roster_usr->list->data;
|
|
283 if (value) {
|
|
284 // Message flag is TRUE. This is easy, we just have to set both flags
|
|
285 // to TRUE...
|
|
286 roster_usr->flags |= ROSTER_FLAG_MSG;
|
|
287 roster_grp->flags |= ROSTER_FLAG_MSG; // group
|
|
288 } else {
|
|
289 // Message flag is FALSE.
|
|
290 guint msg = FALSE;
|
|
291 roster_usr->flags &= ~ROSTER_FLAG_MSG;
|
|
292 // For the group value we need to watch all buddies in this group;
|
|
293 // if one is flagged, then the group will be flagged.
|
|
294 // I will re-use sl_user and roster_usr here, as they aren't used
|
|
295 // anymore.
|
|
296 sl_user = roster_grp->list;
|
|
297 while (sl_user) {
|
|
298 roster_usr = (roster*)sl_user->data;
|
|
299 if (roster_usr->flags & ROSTER_FLAG_MSG) {
|
|
300 msg = TRUE;
|
|
301 break;
|
|
302 }
|
|
303 sl_user = g_slist_next(sl_user);
|
|
304 }
|
|
305 if (!msg)
|
|
306 roster_grp->flags &= ~ROSTER_FLAG_MSG;
|
|
307 else
|
|
308 roster_grp->flags |= ROSTER_FLAG_MSG;
|
|
309 // Actually the "else" part is useless, because the group
|
|
310 // ROSTER_FLAG_MSG should already be set...
|
|
311 }
|
|
312 }
|
|
313
|
89
|
314 void roster_settype(const char *jid, guint type)
|
|
315 {
|
|
316 GSList *sl_user;
|
|
317 roster *roster_usr;
|
|
318
|
|
319 if ((sl_user = roster_find(jid, jidsearch, 0)) == NULL)
|
|
320 return;
|
|
321
|
|
322 roster_usr = (roster*)sl_user->data;
|
|
323 roster_usr->type = type;
|
|
324 }
|
|
325
|
90
|
326 enum imstatus roster_getstatus(const char *jid)
|
|
327 {
|
|
328 GSList *sl_user;
|
|
329 roster *roster_usr;
|
|
330
|
|
331 sl_user = roster_find(jid, jidsearch, ROSTER_TYPE_USER|ROSTER_TYPE_AGENT);
|
|
332 if (sl_user == NULL)
|
|
333 return offline; // Not in the roster, anyway...
|
|
334
|
|
335 roster_usr = (roster*)sl_user->data;
|
|
336 return roster_usr->status;
|
|
337 }
|
|
338
|
89
|
339 guint roster_gettype(const char *jid)
|
|
340 {
|
|
341 GSList *sl_user;
|
|
342 roster *roster_usr;
|
|
343
|
|
344 if ((sl_user = roster_find(jid, jidsearch, 0)) == NULL)
|
|
345 return 0;
|
|
346
|
|
347 roster_usr = (roster*)sl_user->data;
|
|
348 return roster_usr->type;
|
|
349 }
|
|
350
|
141
|
351 inline guint roster_exists(const char *jidname, enum findwhat type,
|
|
352 guint roster_type)
|
|
353 {
|
|
354 if (roster_find(jidname, type, roster_type))
|
|
355 return TRUE;
|
|
356 return FALSE;
|
|
357 }
|
|
358
|
72
|
359
|
|
360 /* ### BuddyList functions ### */
|
|
361
|
120
|
362 // buddylist_set_hide_offline_buddies(hide)
|
72
|
363 // "hide" values: 1=hide 0=show_all -1=invert
|
120
|
364 void buddylist_set_hide_offline_buddies(int hide)
|
72
|
365 {
|
|
366 if (hide < 0) // NEG (invert)
|
|
367 hide_offline_buddies = !hide_offline_buddies;
|
|
368 else if (hide == 0) // FALSE (don't hide)
|
|
369 hide_offline_buddies = 0;
|
|
370 else // TRUE (hide)
|
|
371 hide_offline_buddies = 1;
|
|
372 }
|
|
373
|
120
|
374 inline int buddylist_get_hide_offline_buddies(void)
|
|
375 {
|
|
376 return hide_offline_buddies;
|
|
377 }
|
|
378
|
72
|
379 // buddylist_build()
|
|
380 // Creates the buddylist from the roster entries.
|
|
381 void buddylist_build(void)
|
|
382 {
|
|
383 GSList *sl_roster_elt = groups;
|
|
384 roster *roster_elt;
|
81
|
385 roster *roster_current_buddy = NULL;
|
128
|
386 int shrunk_group;
|
72
|
387
|
81
|
388 // We need to remember which buddy is selected.
|
|
389 if (current_buddy)
|
|
390 roster_current_buddy = BUDDATA(current_buddy);
|
|
391 current_buddy = NULL;
|
|
392
|
72
|
393 // Destroy old buddylist
|
|
394 if (buddylist) {
|
|
395 g_list_free(buddylist);
|
|
396 buddylist = NULL;
|
|
397 }
|
|
398
|
|
399 // Create the new list
|
|
400 while (sl_roster_elt) {
|
|
401 GSList *sl_roster_usrelt;
|
|
402 roster *roster_usrelt;
|
147
|
403 guint pending_group = FALSE;
|
72
|
404 roster_elt = (roster*) sl_roster_elt->data;
|
|
405
|
|
406 // Add the group now unless hide_offline_buddies is set,
|
|
407 // in which case we'll add it only if an online buddy belongs to it.
|
147
|
408 // We take care to keep the current_buddy in the list, too.
|
|
409 if (!hide_offline_buddies || roster_elt == roster_current_buddy)
|
72
|
410 buddylist = g_list_append(buddylist, roster_elt);
|
|
411 else
|
147
|
412 pending_group = TRUE;
|
72
|
413
|
128
|
414 shrunk_group = roster_elt->flags & ROSTER_FLAG_HIDE;
|
|
415
|
72
|
416 sl_roster_usrelt = roster_elt->list;
|
|
417 while (sl_roster_usrelt) {
|
|
418 roster_usrelt = (roster*) sl_roster_usrelt->data;
|
|
419
|
|
420 // Buddy will be added if either:
|
|
421 // - hide_offline_buddies is FALSE
|
|
422 // - buddy is not offline
|
|
423 // - buddy has a lock (for example the buddy window is currently open)
|
|
424 // - buddy has a pending (non-read) message
|
128
|
425 // - group isn't hidden (shrunk)
|
147
|
426 // - this is the current_buddy
|
|
427 if (!hide_offline_buddies || roster_usrelt == roster_current_buddy ||
|
72
|
428 (buddy_getstatus((gpointer)roster_usrelt) != offline) ||
|
|
429 (buddy_getflags((gpointer)roster_usrelt) &
|
|
430 (ROSTER_FLAG_LOCK | ROSTER_FLAG_MSG))) {
|
|
431 // This user should be added. Maybe the group hasn't been added yet?
|
147
|
432 if (pending_group &&
|
|
433 (hide_offline_buddies || roster_usrelt == roster_current_buddy)) {
|
72
|
434 // It hasn't been done yet
|
|
435 buddylist = g_list_append(buddylist, roster_elt);
|
|
436 pending_group = FALSE;
|
|
437 }
|
|
438 // Add user
|
128
|
439 // XXX Should we add the user if there is a message and
|
|
440 // the group is shrunk? If so, we'd need to check LOCK flag too,
|
|
441 // perhaps...
|
|
442 if (!shrunk_group)
|
|
443 buddylist = g_list_append(buddylist, roster_usrelt);
|
72
|
444 }
|
|
445
|
|
446 sl_roster_usrelt = g_slist_next(sl_roster_usrelt);
|
|
447 }
|
|
448 sl_roster_elt = g_slist_next(sl_roster_elt);
|
|
449 }
|
78
|
450
|
81
|
451 // Check if we can find our saved current_buddy...
|
|
452 if (roster_current_buddy)
|
|
453 current_buddy = g_list_find(buddylist, roster_current_buddy);
|
78
|
454 // current_buddy initialization
|
|
455 if (!current_buddy || (g_list_position(buddylist, current_buddy) == -1))
|
81
|
456 current_buddy = g_list_first(buddylist);
|
128
|
457 // XXX Maybe we should set update_roster to TRUE there?
|
72
|
458 }
|
|
459
|
|
460 // buddy_hide_group(roster, hide)
|
|
461 // "hide" values: 1=hide 0=show_all -1=invert
|
|
462 void buddy_hide_group(gpointer rosterdata, int hide)
|
|
463 {
|
207
|
464 roster *roster_usr = rosterdata;
|
72
|
465 if (hide > 0) // TRUE (hide)
|
207
|
466 roster_usr->flags |= ROSTER_FLAG_HIDE;
|
72
|
467 else if (hide < 0) // NEG (invert)
|
207
|
468 roster_usr->flags ^= ROSTER_FLAG_HIDE;
|
72
|
469 else // FALSE (don't hide)
|
207
|
470 roster_usr->flags &= ~ROSTER_FLAG_HIDE;
|
72
|
471 }
|
|
472
|
|
473 const char *buddy_getjid(gpointer rosterdata)
|
|
474 {
|
207
|
475 roster *roster_usr = rosterdata;
|
|
476 return roster_usr->jid;
|
|
477 }
|
|
478
|
210
|
479 // buddy_setgroup()
|
|
480 // Change the group of current buddy
|
|
481 //
|
|
482 // Warning! This function changes current_buddy!
|
|
483 // Warning! Old buddy is deleted, so you can't acces to its jid/name after
|
|
484 // calling this function.
|
|
485 void buddy_setgroup(gpointer rosterdata, char *newgroupname)
|
|
486 {
|
|
487 roster *roster_usr = rosterdata;
|
|
488 GSList **sl_group;
|
|
489 GSList *sl_clone;
|
|
490 roster *roster_clone;
|
|
491
|
|
492 // A group has no group :)
|
|
493 if (roster_usr->type & ROSTER_TYPE_GROUP) return;
|
|
494
|
|
495 // Remove the buddy from current group
|
|
496 sl_group = &((roster*)((GSList*)roster_usr->list)->data)->list;
|
|
497 *sl_group = g_slist_remove(*sl_group, rosterdata);
|
|
498
|
|
499 // Add the buddy to its new group; actually we "clone" this buddy...
|
|
500 sl_clone = roster_add_user(roster_usr->jid, roster_usr->name,
|
|
501 newgroupname, roster_usr->type);
|
|
502 roster_clone = (roster*)sl_clone->data;
|
|
503 roster_clone->status = roster_usr->status;
|
|
504 roster_clone->flags = roster_usr->flags;
|
|
505
|
|
506 // Free old buddy
|
|
507 if (roster_usr->jid) g_free((gchar*)roster_usr->jid);
|
|
508 if (roster_usr->name) g_free((gchar*)roster_usr->name);
|
|
509 g_free(roster_usr);
|
|
510
|
|
511 buddylist_build();
|
|
512 current_buddy = g_list_find(buddylist, roster_clone);
|
|
513 }
|
|
514
|
207
|
515 void buddy_setname(gpointer rosterdata, char *newname)
|
|
516 {
|
|
517 roster *roster_usr = rosterdata;
|
209
|
518 GSList **sl_group;
|
207
|
519
|
|
520 // TODO For groups, we need to check for unicity
|
|
521 // However, renaming a group boils down to moving all its buddies to
|
|
522 // another group, so calling this function is not really necessary...
|
|
523 if (roster_usr->type & ROSTER_TYPE_GROUP) return;
|
|
524
|
|
525 if (roster_usr->name) {
|
|
526 g_free((gchar*)roster_usr->name);
|
|
527 roster_usr->name = NULL;
|
|
528 }
|
|
529 if (newname)
|
|
530 roster_usr->name = g_strdup(newname);
|
209
|
531
|
|
532 // We need to resort the group list
|
|
533 sl_group = &((roster*)((GSList*)roster_usr->list)->data)->list;
|
|
534 *sl_group = g_slist_sort(*sl_group, (GCompareFunc)&roster_compare_name);
|
|
535
|
|
536 buddylist_build();
|
72
|
537 }
|
|
538
|
|
539 const char *buddy_getname(gpointer rosterdata)
|
|
540 {
|
207
|
541 roster *roster_usr = rosterdata;
|
|
542 return roster_usr->name;
|
|
543 }
|
|
544
|
|
545 // buddy_getgroupname()
|
|
546 // Returns a pointer on buddy's group name.
|
|
547 const char *buddy_getgroupname(gpointer rosterdata)
|
|
548 {
|
|
549 roster *roster_usr = rosterdata;
|
|
550
|
|
551 if (roster_usr->type & ROSTER_TYPE_GROUP)
|
|
552 return roster_usr->name;
|
|
553
|
|
554 // This is a user
|
|
555 return ((roster*)((GSList*)roster_usr->list)->data)->name;
|
72
|
556 }
|
|
557
|
166
|
558 // buddy_getgroup()
|
|
559 // Returns a pointer on buddy's group.
|
|
560 gpointer buddy_getgroup(gpointer rosterdata)
|
|
561 {
|
207
|
562 roster *roster_usr = rosterdata;
|
166
|
563
|
207
|
564 if (roster_usr->type & ROSTER_TYPE_GROUP)
|
166
|
565 return rosterdata;
|
|
566
|
|
567 // This is a user
|
207
|
568 return (gpointer)((GSList*)roster_usr->list)->data;
|
166
|
569 }
|
|
570
|
72
|
571 guint buddy_gettype(gpointer rosterdata)
|
|
572 {
|
207
|
573 roster *roster_usr = rosterdata;
|
|
574 return roster_usr->type;
|
72
|
575 }
|
|
576
|
|
577 enum imstatus buddy_getstatus(gpointer rosterdata)
|
|
578 {
|
207
|
579 roster *roster_usr = rosterdata;
|
|
580 return roster_usr->status;
|
72
|
581 }
|
|
582
|
119
|
583 // buddy_setflags()
|
|
584 // Set one or several flags to value (TRUE/FALSE)
|
|
585 void buddy_setflags(gpointer rosterdata, guint flags, guint value)
|
|
586 {
|
207
|
587 roster *roster_usr = rosterdata;
|
119
|
588 if (value)
|
207
|
589 roster_usr->flags |= flags;
|
119
|
590 else
|
207
|
591 roster_usr->flags &= ~flags;
|
119
|
592 }
|
|
593
|
72
|
594 guint buddy_getflags(gpointer rosterdata)
|
|
595 {
|
207
|
596 roster *roster_usr = rosterdata;
|
|
597 return roster_usr->flags;
|
72
|
598 }
|
|
599
|