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