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