author | Mikael Berthe <mikael@lilotux.net> |
Sun, 28 May 2006 10:42:22 +0200 | |
changeset 885 | afdd81c2c44d |
parent 863 | 4f1a93faffea |
child 889 | ae93e69aaaaf |
permissions | -rw-r--r-- |
72 | 1 |
/* |
2 |
* roster.c -- Local roster implementation |
|
393 | 3 |
* |
699 | 4 |
* Copyright (C) 2005, 2006 Mikael Berthe <bmikael@lists.lilotux.net> |
72 | 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" |
|
772
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
26 |
#include "utils.h" |
72 | 27 |
|
28 |
||
584 | 29 |
char *strrole[] = { /* Should match enum in roster.h */ |
30 |
"none", |
|
31 |
"moderator", |
|
32 |
"participant", |
|
33 |
"visitor" |
|
34 |
}; |
|
35 |
||
36 |
char *straffil[] = { /* Should match enum roster.h */ |
|
37 |
"none", |
|
38 |
"owner", |
|
39 |
"admin", |
|
40 |
"memeber", |
|
41 |
"outcast" |
|
42 |
}; |
|
43 |
||
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
44 |
/* Resource structure */ |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
45 |
|
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
46 |
typedef struct { |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
47 |
gchar *name; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
48 |
gchar prio; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
49 |
enum imstatus status; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
50 |
gchar *status_msg; |
625
028c01940490
Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
621
diff
changeset
|
51 |
time_t status_timestamp; |
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
52 |
enum imrole role; |
572
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
53 |
enum imaffiliation affil; |
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
54 |
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
|
55 |
} res; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
56 |
|
72 | 57 |
/* This is a private structure type for the roster */ |
58 |
||
59 |
typedef struct { |
|
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
60 |
gchar *name; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
61 |
gchar *jid; |
72 | 62 |
guint type; |
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
63 |
enum subscr subscription; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
64 |
GSList *resource; |
644
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
625
diff
changeset
|
65 |
|
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
625
diff
changeset
|
66 |
/* For groupchats */ |
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
625
diff
changeset
|
67 |
gchar *nickname; |
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
625
diff
changeset
|
68 |
gchar *topic; |
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
625
diff
changeset
|
69 |
guint8 inside_room; |
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
625
diff
changeset
|
70 |
|
843
915a7f17474a
Remember the status message when a buddy goes offline
Mikael Berthe <mikael@lilotux.net>
parents:
819
diff
changeset
|
71 |
/* To keep track of last status message */ |
915a7f17474a
Remember the status message when a buddy goes offline
Mikael Berthe <mikael@lilotux.net>
parents:
819
diff
changeset
|
72 |
gchar *offline_status_message; |
915a7f17474a
Remember the status message when a buddy goes offline
Mikael Berthe <mikael@lilotux.net>
parents:
819
diff
changeset
|
73 |
|
644
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
625
diff
changeset
|
74 |
/* Flag used for the UI */ |
72 | 75 |
guint flags; |
644
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
625
diff
changeset
|
76 |
|
72 | 77 |
// list: user -> points to his group; group -> points to its users list |
78 |
GSList *list; |
|
79 |
} roster; |
|
80 |
||
81 |
||
82 |
/* ### Variables ### */ |
|
83 |
||
84 |
static int hide_offline_buddies; |
|
85 |
static GSList *groups; |
|
236 | 86 |
static GSList *unread_list; |
662
4111ff4cdd15
Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents:
652
diff
changeset
|
87 |
static GHashTable *unread_jids; |
72 | 88 |
GList *buddylist; |
78 | 89 |
GList *current_buddy; |
330 | 90 |
GList *alternate_buddy; |
72 | 91 |
|
848
a9161d2dc414
Introduce special buffer stuff
Mikael Berthe <mikael@lilotux.net>
parents:
843
diff
changeset
|
92 |
static roster roster_special; |
a9161d2dc414
Introduce special buffer stuff
Mikael Berthe <mikael@lilotux.net>
parents:
843
diff
changeset
|
93 |
|
662
4111ff4cdd15
Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents:
652
diff
changeset
|
94 |
void unread_jid_add(const char *jid); |
4111ff4cdd15
Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents:
652
diff
changeset
|
95 |
int unread_jid_del(const char *jid); |
4111ff4cdd15
Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents:
652
diff
changeset
|
96 |
|
72 | 97 |
|
848
a9161d2dc414
Introduce special buffer stuff
Mikael Berthe <mikael@lilotux.net>
parents:
843
diff
changeset
|
98 |
/* ### Initialization ### */ |
a9161d2dc414
Introduce special buffer stuff
Mikael Berthe <mikael@lilotux.net>
parents:
843
diff
changeset
|
99 |
|
a9161d2dc414
Introduce special buffer stuff
Mikael Berthe <mikael@lilotux.net>
parents:
843
diff
changeset
|
100 |
void roster_init(void) |
a9161d2dc414
Introduce special buffer stuff
Mikael Berthe <mikael@lilotux.net>
parents:
843
diff
changeset
|
101 |
{ |
a9161d2dc414
Introduce special buffer stuff
Mikael Berthe <mikael@lilotux.net>
parents:
843
diff
changeset
|
102 |
roster_special.name = "[status]"; |
a9161d2dc414
Introduce special buffer stuff
Mikael Berthe <mikael@lilotux.net>
parents:
843
diff
changeset
|
103 |
roster_special.type = ROSTER_TYPE_SPECIAL; |
a9161d2dc414
Introduce special buffer stuff
Mikael Berthe <mikael@lilotux.net>
parents:
843
diff
changeset
|
104 |
} |
a9161d2dc414
Introduce special buffer stuff
Mikael Berthe <mikael@lilotux.net>
parents:
843
diff
changeset
|
105 |
|
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
106 |
/* ### Resources functions ### */ |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
107 |
|
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
108 |
static void free_all_resources(GSList **reslist) |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
109 |
{ |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
110 |
GSList *lip; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
111 |
res *p_res; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
112 |
|
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
113 |
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
|
114 |
p_res = (res*)lip->data; |
774
46304b773a44
Remove useless checks before g_free() calls
Mikael Berthe <mikael@lilotux.net>
parents:
772
diff
changeset
|
115 |
g_free((gchar*)p_res->status_msg); |
46304b773a44
Remove useless checks before g_free() calls
Mikael Berthe <mikael@lilotux.net>
parents:
772
diff
changeset
|
116 |
g_free((gchar*)p_res->name); |
46304b773a44
Remove useless checks before g_free() calls
Mikael Berthe <mikael@lilotux.net>
parents:
772
diff
changeset
|
117 |
g_free((gchar*)p_res->realjid); |
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
118 |
} |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
119 |
// 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
|
120 |
g_slist_free(*reslist); |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
121 |
*reslist = NULL; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
122 |
} |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
123 |
|
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
124 |
// Resources are sorted in ascending order |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
125 |
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
|
126 |
//return (a->prio - b->prio); |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
127 |
if (a->prio < b->prio) return -1; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
128 |
else return 1; |
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 |
// get_resource(rost, resname) |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
132 |
// 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
|
133 |
// - if rost has no resources, return NULL |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
134 |
// - 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
|
135 |
// - 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
|
136 |
// 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
|
137 |
// (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
|
138 |
// |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
139 |
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
|
140 |
{ |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
141 |
GSList *p; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
142 |
res *r = NULL; |
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 |
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
|
145 |
r = p->data; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
146 |
if (resname && !strcmp(r->name, resname)) |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
147 |
return r; |
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 |
|
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
150 |
// 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
|
151 |
// 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
|
152 |
if (!resname) return r; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
153 |
return NULL; |
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 |
|
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
156 |
// get_or_add_resource(rost, resname, priority) |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
157 |
// - 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
|
158 |
// on this resource |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
159 |
// - 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
|
160 |
// new resource |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
161 |
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
|
162 |
{ |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
163 |
GSList *p; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
164 |
res *nres; |
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 |
if (!resname) return NULL; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
167 |
|
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
168 |
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
|
169 |
res *r = p->data; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
170 |
if (!strcmp(r->name, resname)) |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
171 |
return r; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
172 |
} |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
173 |
|
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
174 |
// Resource not found |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
175 |
nres = g_new0(res, 1); |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
176 |
nres->name = g_strdup(resname); |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
177 |
nres->prio = prio; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
178 |
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
|
179 |
(GCompareFunc)&resource_compare_prio); |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
180 |
return nres; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
181 |
} |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
182 |
|
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
183 |
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
|
184 |
{ |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
185 |
GSList *p; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
186 |
GSList *p_res_elt = NULL; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
187 |
res *p_res; |
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 |
if (!resname) return; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
190 |
|
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
191 |
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
|
192 |
res *r = p->data; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
193 |
if (!strcmp(r->name, resname)) |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
194 |
p_res_elt = p; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
195 |
} |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
196 |
|
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
197 |
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
|
198 |
|
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
199 |
p_res = p_res_elt->data; |
843
915a7f17474a
Remember the status message when a buddy goes offline
Mikael Berthe <mikael@lilotux.net>
parents:
819
diff
changeset
|
200 |
|
915a7f17474a
Remember the status message when a buddy goes offline
Mikael Berthe <mikael@lilotux.net>
parents:
819
diff
changeset
|
201 |
// Keep a copy of the status message when a buddy goes offline |
915a7f17474a
Remember the status message when a buddy goes offline
Mikael Berthe <mikael@lilotux.net>
parents:
819
diff
changeset
|
202 |
if (g_slist_length(rost->resource) == 1) { |
915a7f17474a
Remember the status message when a buddy goes offline
Mikael Berthe <mikael@lilotux.net>
parents:
819
diff
changeset
|
203 |
g_free(rost->offline_status_message); |
915a7f17474a
Remember the status message when a buddy goes offline
Mikael Berthe <mikael@lilotux.net>
parents:
819
diff
changeset
|
204 |
rost->offline_status_message = p_res->status_msg; |
915a7f17474a
Remember the status message when a buddy goes offline
Mikael Berthe <mikael@lilotux.net>
parents:
819
diff
changeset
|
205 |
p_res->status_msg = NULL; |
915a7f17474a
Remember the status message when a buddy goes offline
Mikael Berthe <mikael@lilotux.net>
parents:
819
diff
changeset
|
206 |
} |
915a7f17474a
Remember the status message when a buddy goes offline
Mikael Berthe <mikael@lilotux.net>
parents:
819
diff
changeset
|
207 |
|
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
208 |
// Free allocations and delete resource node |
774
46304b773a44
Remove useless checks before g_free() calls
Mikael Berthe <mikael@lilotux.net>
parents:
772
diff
changeset
|
209 |
g_free(p_res->name); |
46304b773a44
Remove useless checks before g_free() calls
Mikael Berthe <mikael@lilotux.net>
parents:
772
diff
changeset
|
210 |
g_free(p_res->status_msg); |
46304b773a44
Remove useless checks before g_free() calls
Mikael Berthe <mikael@lilotux.net>
parents:
772
diff
changeset
|
211 |
g_free(p_res->realjid); |
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
212 |
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
|
213 |
return; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
214 |
} |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
215 |
|
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
216 |
|
72 | 217 |
/* ### Roster functions ### */ |
218 |
||
219 |
// 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
|
220 |
static gint roster_compare_jid_type(roster *a, roster *b) { |
89 | 221 |
if (! (a->type & b->type)) |
480 | 222 |
return -1; // arbitrary (but should be != 0, of course) |
72 | 223 |
return strcasecmp(a->jid, b->jid); |
224 |
} |
|
225 |
||
670
2cd0805515a4
Fix a bug in roster_find()
Mikael Berthe <mikael@lilotux.net>
parents:
669
diff
changeset
|
226 |
// Comparison function used to search in the roster (compares names and types) |
2cd0805515a4
Fix a bug in roster_find()
Mikael Berthe <mikael@lilotux.net>
parents:
669
diff
changeset
|
227 |
static gint roster_compare_name_type(roster *a, roster *b) { |
2cd0805515a4
Fix a bug in roster_find()
Mikael Berthe <mikael@lilotux.net>
parents:
669
diff
changeset
|
228 |
if (! (a->type & b->type)) |
2cd0805515a4
Fix a bug in roster_find()
Mikael Berthe <mikael@lilotux.net>
parents:
669
diff
changeset
|
229 |
return -1; // arbitrary (but should be != 0, of course) |
783
25022410f80f
Use case sensitive group names
Mikael Berthe <mikael@lilotux.net>
parents:
774
diff
changeset
|
230 |
return strcmp(a->name, b->name); |
670
2cd0805515a4
Fix a bug in roster_find()
Mikael Berthe <mikael@lilotux.net>
parents:
669
diff
changeset
|
231 |
} |
2cd0805515a4
Fix a bug in roster_find()
Mikael Berthe <mikael@lilotux.net>
parents:
669
diff
changeset
|
232 |
|
72 | 233 |
// Comparison function used to sort the roster (by name) |
336
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
331
diff
changeset
|
234 |
static gint roster_compare_name(roster *a, roster *b) { |
783
25022410f80f
Use case sensitive group names
Mikael Berthe <mikael@lilotux.net>
parents:
774
diff
changeset
|
235 |
return strcmp(a->name, b->name); |
72 | 236 |
} |
237 |
||
238 |
// Finds a roster element (user, group, agent...), by jid or name |
|
89 | 239 |
// If roster_type is 0, returns match of any type. |
72 | 240 |
// Returns the roster GSList element, or NULL if jid/name not found |
78 | 241 |
GSList *roster_find(const char *jidname, enum findwhat type, guint roster_type) |
72 | 242 |
{ |
243 |
GSList *sl_roster_elt = groups; |
|
244 |
GSList *res; |
|
245 |
roster sample; |
|
246 |
GCompareFunc comp; |
|
247 |
||
192 | 248 |
if (!jidname) return NULL; |
72 | 249 |
|
89 | 250 |
if (!roster_type) |
480 | 251 |
roster_type = ROSTER_TYPE_USER | ROSTER_TYPE_ROOM | |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
252 |
ROSTER_TYPE_AGENT | ROSTER_TYPE_GROUP; |
89 | 253 |
|
72 | 254 |
sample.type = roster_type; |
255 |
if (type == jidsearch) { |
|
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
256 |
sample.jid = (gchar*)jidname; |
72 | 257 |
comp = (GCompareFunc)&roster_compare_jid_type; |
258 |
} else if (type == namesearch) { |
|
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
259 |
sample.name = (gchar*)jidname; |
670
2cd0805515a4
Fix a bug in roster_find()
Mikael Berthe <mikael@lilotux.net>
parents:
669
diff
changeset
|
260 |
comp = (GCompareFunc)&roster_compare_name_type; |
72 | 261 |
} else |
885
afdd81c2c44d
Allow /rename for groups
Mikael Berthe <mikael@lilotux.net>
parents:
863
diff
changeset
|
262 |
return NULL; // Should not happen... |
72 | 263 |
|
264 |
while (sl_roster_elt) { |
|
265 |
roster *roster_elt = (roster*)sl_roster_elt->data; |
|
266 |
if (roster_type & ROSTER_TYPE_GROUP) { |
|
783
25022410f80f
Use case sensitive group names
Mikael Berthe <mikael@lilotux.net>
parents:
774
diff
changeset
|
267 |
if ((type == namesearch) && !strcmp(jidname, roster_elt->name)) |
72 | 268 |
return sl_roster_elt; |
269 |
} |
|
483
4a10c04ac2fb
Fix a bug in roster_find()
Mikael Berthe <mikael@lilotux.net>
parents:
480
diff
changeset
|
270 |
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
|
271 |
if (res) return res; |
72 | 272 |
sl_roster_elt = g_slist_next(sl_roster_elt); |
273 |
} |
|
274 |
return NULL; |
|
275 |
} |
|
276 |
||
277 |
// Returns pointer to new group, or existing group with that name |
|
78 | 278 |
GSList *roster_add_group(const char *name) |
72 | 279 |
{ |
280 |
roster *roster_grp; |
|
669
2b87065270f3
roster_add_group(): do not call roster_find() twice
Mikael Berthe <mikael@lilotux.net>
parents:
662
diff
changeset
|
281 |
GSList *p_group; |
2b87065270f3
roster_add_group(): do not call roster_find() twice
Mikael Berthe <mikael@lilotux.net>
parents:
662
diff
changeset
|
282 |
|
72 | 283 |
// #1 Check name doesn't already exist |
669
2b87065270f3
roster_add_group(): do not call roster_find() twice
Mikael Berthe <mikael@lilotux.net>
parents:
662
diff
changeset
|
284 |
p_group = roster_find(name, namesearch, ROSTER_TYPE_GROUP); |
2b87065270f3
roster_add_group(): do not call roster_find() twice
Mikael Berthe <mikael@lilotux.net>
parents:
662
diff
changeset
|
285 |
if (!p_group) { |
72 | 286 |
// #2 Create the group node |
287 |
roster_grp = g_new0(roster, 1); |
|
288 |
roster_grp->name = g_strdup(name); |
|
289 |
roster_grp->type = ROSTER_TYPE_GROUP; |
|
290 |
// #3 Insert (sorted) |
|
291 |
groups = g_slist_insert_sorted(groups, roster_grp, |
|
292 |
(GCompareFunc)&roster_compare_name); |
|
669
2b87065270f3
roster_add_group(): do not call roster_find() twice
Mikael Berthe <mikael@lilotux.net>
parents:
662
diff
changeset
|
293 |
p_group = roster_find(name, namesearch, ROSTER_TYPE_GROUP); |
72 | 294 |
} |
669
2b87065270f3
roster_add_group(): do not call roster_find() twice
Mikael Berthe <mikael@lilotux.net>
parents:
662
diff
changeset
|
295 |
return p_group; |
72 | 296 |
} |
297 |
||
298 |
// Returns a pointer to the new user, or existing user with that name |
|
78 | 299 |
GSList *roster_add_user(const char *jid, const char *name, const char *group, |
603 | 300 |
guint type, enum subscr esub) |
72 | 301 |
{ |
302 |
roster *roster_usr; |
|
303 |
roster *my_group; |
|
304 |
GSList *slist; |
|
305 |
||
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
306 |
if ((type != ROSTER_TYPE_USER) && |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
307 |
(type != ROSTER_TYPE_ROOM) && |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
308 |
(type != ROSTER_TYPE_AGENT)) { |
72 | 309 |
// XXX Error message? |
310 |
return NULL; |
|
311 |
} |
|
312 |
||
78 | 313 |
// Let's be arbitrary: default group has an empty name (""). |
314 |
if (!group) group = ""; |
|
315 |
||
72 | 316 |
// #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
|
317 |
slist = roster_find(jid, jidsearch, 0); |
607 | 318 |
if (slist) { |
319 |
char *oldgroupname; |
|
320 |
// That's an update |
|
321 |
roster_usr = slist->data; |
|
322 |
roster_usr->subscription = esub; |
|
323 |
if (name) |
|
324 |
buddy_setname(slist->data, (char*)name); |
|
325 |
// Let's check if the group name has changed |
|
326 |
oldgroupname = ((roster*)((GSList*)roster_usr->list)->data)->name; |
|
327 |
if (group && strcmp(oldgroupname, group)) |
|
328 |
buddy_setgroup(slist->data, (char*)group); |
|
329 |
return slist; |
|
330 |
} |
|
72 | 331 |
// #2 add group if necessary |
332 |
slist = roster_add_group(group); |
|
333 |
if (!slist) return NULL; |
|
334 |
my_group = (roster*)slist->data; |
|
335 |
// #3 Create user node |
|
336 |
roster_usr = g_new0(roster, 1); |
|
337 |
roster_usr->jid = g_strdup(jid); |
|
78 | 338 |
if (name) { |
339 |
roster_usr->name = g_strdup(name); |
|
340 |
} else { |
|
341 |
gchar *p, *str = g_strdup(jid); |
|
80 | 342 |
p = strstr(str, "/"); |
78 | 343 |
if (p) *p = '\0'; |
344 |
roster_usr->name = g_strdup(str); |
|
345 |
g_free(str); |
|
346 |
} |
|
662
4111ff4cdd15
Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents:
652
diff
changeset
|
347 |
if (unread_jid_del(jid)) { |
4111ff4cdd15
Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents:
652
diff
changeset
|
348 |
roster_usr->flags |= ROSTER_FLAG_MSG; |
4111ff4cdd15
Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents:
652
diff
changeset
|
349 |
// Append the roster_usr to unread_list |
4111ff4cdd15
Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents:
652
diff
changeset
|
350 |
unread_list = g_slist_append(unread_list, roster_usr); |
4111ff4cdd15
Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents:
652
diff
changeset
|
351 |
} |
603 | 352 |
roster_usr->type = type; |
353 |
roster_usr->subscription = esub; |
|
354 |
roster_usr->list = slist; // (my_group SList element) |
|
72 | 355 |
// #4 Insert node (sorted) |
356 |
my_group->list = g_slist_insert_sorted(my_group->list, roster_usr, |
|
564 | 357 |
(GCompareFunc)&roster_compare_name); |
72 | 358 |
return roster_find(jid, jidsearch, type); |
359 |
} |
|
360 |
||
361 |
// Removes user (jid) from roster, frees allocated memory |
|
78 | 362 |
void roster_del_user(const char *jid) |
72 | 363 |
{ |
364 |
GSList *sl_user, *sl_group; |
|
365 |
GSList **sl_group_listptr; |
|
366 |
roster *roster_usr; |
|
246 | 367 |
GSList *node; |
72 | 368 |
|
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
369 |
sl_user = roster_find(jid, jidsearch, |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
370 |
ROSTER_TYPE_USER|ROSTER_TYPE_AGENT|ROSTER_TYPE_ROOM); |
89 | 371 |
if (sl_user == NULL) |
72 | 372 |
return; |
373 |
roster_usr = (roster*)sl_user->data; |
|
246 | 374 |
|
375 |
// Remove (if present) from unread messages list |
|
376 |
node = g_slist_find(unread_list, roster_usr); |
|
377 |
if (node) unread_list = g_slist_delete_link(unread_list, node); |
|
662
4111ff4cdd15
Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents:
652
diff
changeset
|
378 |
// If there is a pending unread message, keep track of it |
4111ff4cdd15
Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents:
652
diff
changeset
|
379 |
if (roster_usr->flags & ROSTER_FLAG_MSG) |
4111ff4cdd15
Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents:
652
diff
changeset
|
380 |
unread_jid_add(roster_usr->jid); |
246 | 381 |
|
382 |
// Let's free memory (jid, name, status message) |
|
774
46304b773a44
Remove useless checks before g_free() calls
Mikael Berthe <mikael@lilotux.net>
parents:
772
diff
changeset
|
383 |
g_free((gchar*)roster_usr->jid); |
46304b773a44
Remove useless checks before g_free() calls
Mikael Berthe <mikael@lilotux.net>
parents:
772
diff
changeset
|
384 |
g_free((gchar*)roster_usr->name); |
46304b773a44
Remove useless checks before g_free() calls
Mikael Berthe <mikael@lilotux.net>
parents:
772
diff
changeset
|
385 |
g_free((gchar*)roster_usr->nickname); |
46304b773a44
Remove useless checks before g_free() calls
Mikael Berthe <mikael@lilotux.net>
parents:
772
diff
changeset
|
386 |
g_free((gchar*)roster_usr->topic); |
843
915a7f17474a
Remember the status message when a buddy goes offline
Mikael Berthe <mikael@lilotux.net>
parents:
819
diff
changeset
|
387 |
g_free((gchar*)roster_usr->offline_status_message); |
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
388 |
free_all_resources(&roster_usr->resource); |
210 | 389 |
g_free(roster_usr); |
72 | 390 |
|
391 |
// That's a little complex, we need to dereference twice |
|
392 |
sl_group = ((roster*)sl_user->data)->list; |
|
393 |
sl_group_listptr = &((roster*)(sl_group->data))->list; |
|
394 |
*sl_group_listptr = g_slist_delete_link(*sl_group_listptr, sl_user); |
|
78 | 395 |
|
396 |
// We need to rebuild the list |
|
397 |
if (current_buddy) |
|
398 |
buddylist_build(); |
|
210 | 399 |
// TODO What we could do, too, is to check if the deleted node is |
78 | 400 |
// current_buddy, in which case we could move current_buddy to the |
401 |
// previous (or next) node. |
|
72 | 402 |
} |
403 |
||
210 | 404 |
// Free all roster data and call buddylist_build() to free the buddylist. |
164 | 405 |
void roster_free(void) |
406 |
{ |
|
407 |
GSList *sl_grp = groups; |
|
408 |
||
301
efcbd3c1ad15
Free unread_list when the roster is freed
Mikael Berthe <mikael@lilotux.net>
parents:
265
diff
changeset
|
409 |
// Free unread_list |
efcbd3c1ad15
Free unread_list when the roster is freed
Mikael Berthe <mikael@lilotux.net>
parents:
265
diff
changeset
|
410 |
if (unread_list) { |
efcbd3c1ad15
Free unread_list when the roster is freed
Mikael Berthe <mikael@lilotux.net>
parents:
265
diff
changeset
|
411 |
g_slist_free(unread_list); |
efcbd3c1ad15
Free unread_list when the roster is freed
Mikael Berthe <mikael@lilotux.net>
parents:
265
diff
changeset
|
412 |
unread_list = NULL; |
efcbd3c1ad15
Free unread_list when the roster is freed
Mikael Berthe <mikael@lilotux.net>
parents:
265
diff
changeset
|
413 |
} |
efcbd3c1ad15
Free unread_list when the roster is freed
Mikael Berthe <mikael@lilotux.net>
parents:
265
diff
changeset
|
414 |
|
164 | 415 |
// Walk through groups |
416 |
while (sl_grp) { |
|
417 |
roster *roster_grp = (roster*)sl_grp->data; |
|
418 |
GSList *sl_usr = roster_grp->list; |
|
419 |
// Walk through this group users |
|
420 |
while (sl_usr) { |
|
421 |
roster *roster_usr = (roster*)sl_usr->data; |
|
662
4111ff4cdd15
Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents:
652
diff
changeset
|
422 |
// If there is a pending unread message, keep track of it |
4111ff4cdd15
Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents:
652
diff
changeset
|
423 |
if (roster_usr->flags & ROSTER_FLAG_MSG) |
4111ff4cdd15
Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents:
652
diff
changeset
|
424 |
unread_jid_add(roster_usr->jid); |
164 | 425 |
// Free name and jid |
774
46304b773a44
Remove useless checks before g_free() calls
Mikael Berthe <mikael@lilotux.net>
parents:
772
diff
changeset
|
426 |
g_free((gchar*)roster_usr->jid); |
46304b773a44
Remove useless checks before g_free() calls
Mikael Berthe <mikael@lilotux.net>
parents:
772
diff
changeset
|
427 |
g_free((gchar*)roster_usr->name); |
46304b773a44
Remove useless checks before g_free() calls
Mikael Berthe <mikael@lilotux.net>
parents:
772
diff
changeset
|
428 |
g_free((gchar*)roster_usr->nickname); |
46304b773a44
Remove useless checks before g_free() calls
Mikael Berthe <mikael@lilotux.net>
parents:
772
diff
changeset
|
429 |
g_free((gchar*)roster_usr->topic); |
843
915a7f17474a
Remember the status message when a buddy goes offline
Mikael Berthe <mikael@lilotux.net>
parents:
819
diff
changeset
|
430 |
g_free((gchar*)roster_usr->offline_status_message); |
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
431 |
free_all_resources(&roster_usr->resource); |
214 | 432 |
g_free(roster_usr); |
164 | 433 |
sl_usr = g_slist_next(sl_usr); |
434 |
} |
|
435 |
// Free group's users list |
|
436 |
if (roster_grp->list) |
|
437 |
g_slist_free(roster_grp->list); |
|
438 |
// Free group's name and jid |
|
774
46304b773a44
Remove useless checks before g_free() calls
Mikael Berthe <mikael@lilotux.net>
parents:
772
diff
changeset
|
439 |
g_free((gchar*)roster_grp->jid); |
46304b773a44
Remove useless checks before g_free() calls
Mikael Berthe <mikael@lilotux.net>
parents:
772
diff
changeset
|
440 |
g_free((gchar*)roster_grp->name); |
214 | 441 |
g_free(roster_grp); |
164 | 442 |
sl_grp = g_slist_next(sl_grp); |
443 |
} |
|
444 |
// Free groups list |
|
445 |
if (groups) { |
|
446 |
g_slist_free(groups); |
|
447 |
groups = NULL; |
|
448 |
// Update (i.e. free) buddylist |
|
449 |
if (buddylist) |
|
450 |
buddylist_build(); |
|
451 |
} |
|
452 |
} |
|
453 |
||
468
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
454 |
// roster_setstatus() |
572
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
455 |
// 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
|
456 |
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
|
457 |
enum imstatus bstat, const char *status_msg, |
625
028c01940490
Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
621
diff
changeset
|
458 |
time_t status_time, |
572
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
459 |
enum imrole role, enum imaffiliation affil, |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
460 |
const char *realjid) |
72 | 461 |
{ |
462 |
GSList *sl_user; |
|
463 |
roster *roster_usr; |
|
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
464 |
res *p_res; |
72 | 465 |
|
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
466 |
sl_user = roster_find(jid, jidsearch, |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
467 |
ROSTER_TYPE_USER|ROSTER_TYPE_ROOM|ROSTER_TYPE_AGENT); |
92 | 468 |
// If we can't find it, we add it |
89 | 469 |
if (sl_user == NULL) |
603 | 470 |
sl_user = roster_add_user(jid, NULL, NULL, ROSTER_TYPE_USER, sub_none); |
72 | 471 |
|
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
472 |
// 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
|
473 |
if (!resname) return; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
474 |
|
72 | 475 |
roster_usr = (roster*)sl_user->data; |
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
476 |
|
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
477 |
// New or updated resource |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
478 |
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
|
479 |
p_res->prio = prio; |
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
480 |
p_res->status = bstat; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
481 |
if (p_res->status_msg) { |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
482 |
g_free((gchar*)p_res->status_msg); |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
483 |
p_res->status_msg = NULL; |
221 | 484 |
} |
485 |
if (status_msg) |
|
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
486 |
p_res->status_msg = g_strdup(status_msg); |
625
028c01940490
Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
621
diff
changeset
|
487 |
if (!status_time) |
028c01940490
Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
621
diff
changeset
|
488 |
time(&status_time); |
028c01940490
Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
621
diff
changeset
|
489 |
p_res->status_timestamp = status_time; |
468
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
490 |
|
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
491 |
p_res->role = role; |
572
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
492 |
p_res->affil = affil; |
468
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
493 |
|
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
494 |
if (p_res->realjid) { |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
495 |
g_free((gchar*)p_res->realjid); |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
496 |
p_res->realjid = NULL; |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
497 |
} |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
498 |
if (realjid) |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
499 |
p_res->realjid = g_strdup(realjid); |
843
915a7f17474a
Remember the status message when a buddy goes offline
Mikael Berthe <mikael@lilotux.net>
parents:
819
diff
changeset
|
500 |
|
915a7f17474a
Remember the status message when a buddy goes offline
Mikael Berthe <mikael@lilotux.net>
parents:
819
diff
changeset
|
501 |
// If bstat is offline, we MUST delete the resource, actually |
915a7f17474a
Remember the status message when a buddy goes offline
Mikael Berthe <mikael@lilotux.net>
parents:
819
diff
changeset
|
502 |
if (bstat == offline) { |
915a7f17474a
Remember the status message when a buddy goes offline
Mikael Berthe <mikael@lilotux.net>
parents:
819
diff
changeset
|
503 |
del_resource(roster_usr, resname); |
915a7f17474a
Remember the status message when a buddy goes offline
Mikael Berthe <mikael@lilotux.net>
parents:
819
diff
changeset
|
504 |
return; |
915a7f17474a
Remember the status message when a buddy goes offline
Mikael Berthe <mikael@lilotux.net>
parents:
819
diff
changeset
|
505 |
} |
72 | 506 |
} |
507 |
||
78 | 508 |
// roster_setflags() |
509 |
// Set one or several flags to value (TRUE/FALSE) |
|
80 | 510 |
void roster_setflags(const char *jid, guint flags, guint value) |
78 | 511 |
{ |
512 |
GSList *sl_user; |
|
513 |
roster *roster_usr; |
|
514 |
||
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
515 |
sl_user = roster_find(jid, jidsearch, |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
516 |
ROSTER_TYPE_USER|ROSTER_TYPE_ROOM|ROSTER_TYPE_AGENT); |
89 | 517 |
if (sl_user == NULL) |
78 | 518 |
return; |
519 |
||
520 |
roster_usr = (roster*)sl_user->data; |
|
521 |
if (value) |
|
522 |
roster_usr->flags |= flags; |
|
523 |
else |
|
524 |
roster_usr->flags &= ~flags; |
|
525 |
} |
|
148 | 526 |
|
527 |
// roster_msg_setflag() |
|
528 |
// Set the ROSTER_FLAG_MSG to the given value for the given jid. |
|
529 |
// It will update the buddy's group message flag. |
|
236 | 530 |
// Update the unread messages list too. |
148 | 531 |
void roster_msg_setflag(const char *jid, guint value) |
532 |
{ |
|
533 |
GSList *sl_user; |
|
534 |
roster *roster_usr, *roster_grp; |
|
860
a8fadbd97858
Rebuild buddylist when setting a new message flag
Mikael Berthe <mikael@lilotux.net>
parents:
848
diff
changeset
|
535 |
int new_roster_item = FALSE; |
148 | 536 |
|
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
537 |
sl_user = roster_find(jid, jidsearch, |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
538 |
ROSTER_TYPE_USER|ROSTER_TYPE_ROOM|ROSTER_TYPE_AGENT); |
678
e175f5d96f04
Fix a small issue in roster_msg_setflag()
Mikael Berthe <mikael@lilotux.net>
parents:
670
diff
changeset
|
539 |
// If we can't find it, we add it |
e175f5d96f04
Fix a small issue in roster_msg_setflag()
Mikael Berthe <mikael@lilotux.net>
parents:
670
diff
changeset
|
540 |
if (sl_user == NULL) { |
e175f5d96f04
Fix a small issue in roster_msg_setflag()
Mikael Berthe <mikael@lilotux.net>
parents:
670
diff
changeset
|
541 |
sl_user = roster_add_user(jid, NULL, NULL, ROSTER_TYPE_USER, sub_none); |
860
a8fadbd97858
Rebuild buddylist when setting a new message flag
Mikael Berthe <mikael@lilotux.net>
parents:
848
diff
changeset
|
542 |
new_roster_item = TRUE; |
678
e175f5d96f04
Fix a small issue in roster_msg_setflag()
Mikael Berthe <mikael@lilotux.net>
parents:
670
diff
changeset
|
543 |
} |
148 | 544 |
|
545 |
roster_usr = (roster*)sl_user->data; |
|
546 |
roster_grp = (roster*)roster_usr->list->data; |
|
547 |
if (value) { |
|
548 |
// Message flag is TRUE. This is easy, we just have to set both flags |
|
549 |
// to TRUE... |
|
550 |
roster_usr->flags |= ROSTER_FLAG_MSG; |
|
551 |
roster_grp->flags |= ROSTER_FLAG_MSG; // group |
|
236 | 552 |
// Append the roster_usr to unread_list, but avoid duplicates |
553 |
if (!g_slist_find(unread_list, roster_usr)) |
|
554 |
unread_list = g_slist_append(unread_list, roster_usr); |
|
148 | 555 |
} else { |
556 |
// Message flag is FALSE. |
|
557 |
guint msg = FALSE; |
|
558 |
roster_usr->flags &= ~ROSTER_FLAG_MSG; |
|
236 | 559 |
if (unread_list) { |
560 |
GSList *node = g_slist_find(unread_list, roster_usr); |
|
561 |
if (node) unread_list = g_slist_delete_link(unread_list, node); |
|
562 |
} |
|
148 | 563 |
// For the group value we need to watch all buddies in this group; |
564 |
// if one is flagged, then the group will be flagged. |
|
565 |
// I will re-use sl_user and roster_usr here, as they aren't used |
|
566 |
// anymore. |
|
567 |
sl_user = roster_grp->list; |
|
568 |
while (sl_user) { |
|
569 |
roster_usr = (roster*)sl_user->data; |
|
570 |
if (roster_usr->flags & ROSTER_FLAG_MSG) { |
|
571 |
msg = TRUE; |
|
572 |
break; |
|
573 |
} |
|
574 |
sl_user = g_slist_next(sl_user); |
|
575 |
} |
|
576 |
if (!msg) |
|
577 |
roster_grp->flags &= ~ROSTER_FLAG_MSG; |
|
578 |
else |
|
579 |
roster_grp->flags |= ROSTER_FLAG_MSG; |
|
580 |
// Actually the "else" part is useless, because the group |
|
581 |
// ROSTER_FLAG_MSG should already be set... |
|
582 |
} |
|
860
a8fadbd97858
Rebuild buddylist when setting a new message flag
Mikael Berthe <mikael@lilotux.net>
parents:
848
diff
changeset
|
583 |
|
a8fadbd97858
Rebuild buddylist when setting a new message flag
Mikael Berthe <mikael@lilotux.net>
parents:
848
diff
changeset
|
584 |
if (buddylist && new_roster_item) |
a8fadbd97858
Rebuild buddylist when setting a new message flag
Mikael Berthe <mikael@lilotux.net>
parents:
848
diff
changeset
|
585 |
buddylist_build(); |
148 | 586 |
} |
587 |
||
510
6c3cd3aa4a91
New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents:
509
diff
changeset
|
588 |
const char *roster_getname(const char *jid) |
6c3cd3aa4a91
New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents:
509
diff
changeset
|
589 |
{ |
6c3cd3aa4a91
New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents:
509
diff
changeset
|
590 |
GSList *sl_user; |
6c3cd3aa4a91
New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents:
509
diff
changeset
|
591 |
roster *roster_usr; |
6c3cd3aa4a91
New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents:
509
diff
changeset
|
592 |
|
6c3cd3aa4a91
New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents:
509
diff
changeset
|
593 |
sl_user = roster_find(jid, jidsearch, |
6c3cd3aa4a91
New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents:
509
diff
changeset
|
594 |
ROSTER_TYPE_USER|ROSTER_TYPE_ROOM|ROSTER_TYPE_AGENT); |
6c3cd3aa4a91
New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents:
509
diff
changeset
|
595 |
if (sl_user == NULL) |
6c3cd3aa4a91
New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents:
509
diff
changeset
|
596 |
return NULL; // Not in the roster... |
6c3cd3aa4a91
New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents:
509
diff
changeset
|
597 |
|
6c3cd3aa4a91
New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents:
509
diff
changeset
|
598 |
roster_usr = (roster*)sl_user->data; |
6c3cd3aa4a91
New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents:
509
diff
changeset
|
599 |
return roster_usr->name; |
6c3cd3aa4a91
New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents:
509
diff
changeset
|
600 |
} |
6c3cd3aa4a91
New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents:
509
diff
changeset
|
601 |
|
863
4f1a93faffea
Add roster_getnickname()
Mikael Berthe <mikael@lilotux.net>
parents:
860
diff
changeset
|
602 |
const char *roster_getnickname(const char *jid) |
4f1a93faffea
Add roster_getnickname()
Mikael Berthe <mikael@lilotux.net>
parents:
860
diff
changeset
|
603 |
{ |
4f1a93faffea
Add roster_getnickname()
Mikael Berthe <mikael@lilotux.net>
parents:
860
diff
changeset
|
604 |
GSList *sl_user; |
4f1a93faffea
Add roster_getnickname()
Mikael Berthe <mikael@lilotux.net>
parents:
860
diff
changeset
|
605 |
roster *roster_usr; |
4f1a93faffea
Add roster_getnickname()
Mikael Berthe <mikael@lilotux.net>
parents:
860
diff
changeset
|
606 |
|
4f1a93faffea
Add roster_getnickname()
Mikael Berthe <mikael@lilotux.net>
parents:
860
diff
changeset
|
607 |
sl_user = roster_find(jid, jidsearch, |
4f1a93faffea
Add roster_getnickname()
Mikael Berthe <mikael@lilotux.net>
parents:
860
diff
changeset
|
608 |
ROSTER_TYPE_USER|ROSTER_TYPE_ROOM|ROSTER_TYPE_AGENT); |
4f1a93faffea
Add roster_getnickname()
Mikael Berthe <mikael@lilotux.net>
parents:
860
diff
changeset
|
609 |
if (sl_user == NULL) |
4f1a93faffea
Add roster_getnickname()
Mikael Berthe <mikael@lilotux.net>
parents:
860
diff
changeset
|
610 |
return NULL; // Not in the roster... |
4f1a93faffea
Add roster_getnickname()
Mikael Berthe <mikael@lilotux.net>
parents:
860
diff
changeset
|
611 |
|
4f1a93faffea
Add roster_getnickname()
Mikael Berthe <mikael@lilotux.net>
parents:
860
diff
changeset
|
612 |
roster_usr = (roster*)sl_user->data; |
4f1a93faffea
Add roster_getnickname()
Mikael Berthe <mikael@lilotux.net>
parents:
860
diff
changeset
|
613 |
return roster_usr->nickname; |
4f1a93faffea
Add roster_getnickname()
Mikael Berthe <mikael@lilotux.net>
parents:
860
diff
changeset
|
614 |
} |
4f1a93faffea
Add roster_getnickname()
Mikael Berthe <mikael@lilotux.net>
parents:
860
diff
changeset
|
615 |
|
89 | 616 |
void roster_settype(const char *jid, guint type) |
617 |
{ |
|
618 |
GSList *sl_user; |
|
619 |
roster *roster_usr; |
|
620 |
||
621 |
if ((sl_user = roster_find(jid, jidsearch, 0)) == NULL) |
|
622 |
return; |
|
623 |
||
624 |
roster_usr = (roster*)sl_user->data; |
|
625 |
roster_usr->type = type; |
|
626 |
} |
|
627 |
||
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
628 |
enum imstatus roster_getstatus(const char *jid, const char *resname) |
90 | 629 |
{ |
630 |
GSList *sl_user; |
|
631 |
roster *roster_usr; |
|
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
632 |
res *p_res; |
90 | 633 |
|
634 |
sl_user = roster_find(jid, jidsearch, ROSTER_TYPE_USER|ROSTER_TYPE_AGENT); |
|
635 |
if (sl_user == NULL) |
|
636 |
return offline; // Not in the roster, anyway... |
|
637 |
||
638 |
roster_usr = (roster*)sl_user->data; |
|
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
639 |
p_res = get_resource(roster_usr, resname); |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
640 |
if (p_res) |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
641 |
return p_res->status; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
642 |
return offline; |
90 | 643 |
} |
644 |
||
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
645 |
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
|
646 |
{ |
45076d02eeef
The /status command can specify a status message
Mikael Berthe <mikael@lilotux.net>
parents:
301
diff
changeset
|
647 |
GSList *sl_user; |
45076d02eeef
The /status command can specify a status message
Mikael Berthe <mikael@lilotux.net>
parents:
301
diff
changeset
|
648 |
roster *roster_usr; |
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
649 |
res *p_res; |
318
45076d02eeef
The /status command can specify a status message
Mikael Berthe <mikael@lilotux.net>
parents:
301
diff
changeset
|
650 |
|
45076d02eeef
The /status command can specify a status message
Mikael Berthe <mikael@lilotux.net>
parents:
301
diff
changeset
|
651 |
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
|
652 |
if (sl_user == NULL) |
425
03f1e37759a6
roster_getstatusmsg() should return a pointer
Mikael Berthe <mikael@lilotux.net>
parents:
393
diff
changeset
|
653 |
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
|
654 |
|
45076d02eeef
The /status command can specify a status message
Mikael Berthe <mikael@lilotux.net>
parents:
301
diff
changeset
|
655 |
roster_usr = (roster*)sl_user->data; |
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
656 |
p_res = get_resource(roster_usr, resname); |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
657 |
if (p_res) |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
658 |
return p_res->status_msg; |
843
915a7f17474a
Remember the status message when a buddy goes offline
Mikael Berthe <mikael@lilotux.net>
parents:
819
diff
changeset
|
659 |
return roster_usr->offline_status_message; |
318
45076d02eeef
The /status command can specify a status message
Mikael Berthe <mikael@lilotux.net>
parents:
301
diff
changeset
|
660 |
} |
45076d02eeef
The /status command can specify a status message
Mikael Berthe <mikael@lilotux.net>
parents:
301
diff
changeset
|
661 |
|
89 | 662 |
guint roster_gettype(const char *jid) |
663 |
{ |
|
664 |
GSList *sl_user; |
|
665 |
roster *roster_usr; |
|
666 |
||
667 |
if ((sl_user = roster_find(jid, jidsearch, 0)) == NULL) |
|
668 |
return 0; |
|
669 |
||
670 |
roster_usr = (roster*)sl_user->data; |
|
671 |
return roster_usr->type; |
|
672 |
} |
|
673 |
||
819
c2d7d9dd4193
New option 'block_unsubscribed'
Mikael Berthe <mikael@lilotux.net>
parents:
792
diff
changeset
|
674 |
guint roster_getsubscription(const char *jid) |
c2d7d9dd4193
New option 'block_unsubscribed'
Mikael Berthe <mikael@lilotux.net>
parents:
792
diff
changeset
|
675 |
{ |
c2d7d9dd4193
New option 'block_unsubscribed'
Mikael Berthe <mikael@lilotux.net>
parents:
792
diff
changeset
|
676 |
GSList *sl_user; |
c2d7d9dd4193
New option 'block_unsubscribed'
Mikael Berthe <mikael@lilotux.net>
parents:
792
diff
changeset
|
677 |
roster *roster_usr; |
c2d7d9dd4193
New option 'block_unsubscribed'
Mikael Berthe <mikael@lilotux.net>
parents:
792
diff
changeset
|
678 |
|
c2d7d9dd4193
New option 'block_unsubscribed'
Mikael Berthe <mikael@lilotux.net>
parents:
792
diff
changeset
|
679 |
if ((sl_user = roster_find(jid, jidsearch, 0)) == NULL) |
c2d7d9dd4193
New option 'block_unsubscribed'
Mikael Berthe <mikael@lilotux.net>
parents:
792
diff
changeset
|
680 |
return 0; |
c2d7d9dd4193
New option 'block_unsubscribed'
Mikael Berthe <mikael@lilotux.net>
parents:
792
diff
changeset
|
681 |
|
c2d7d9dd4193
New option 'block_unsubscribed'
Mikael Berthe <mikael@lilotux.net>
parents:
792
diff
changeset
|
682 |
roster_usr = (roster*)sl_user->data; |
c2d7d9dd4193
New option 'block_unsubscribed'
Mikael Berthe <mikael@lilotux.net>
parents:
792
diff
changeset
|
683 |
return roster_usr->subscription; |
c2d7d9dd4193
New option 'block_unsubscribed'
Mikael Berthe <mikael@lilotux.net>
parents:
792
diff
changeset
|
684 |
} |
c2d7d9dd4193
New option 'block_unsubscribed'
Mikael Berthe <mikael@lilotux.net>
parents:
792
diff
changeset
|
685 |
|
610
0e8247cf2bd1
Consider buddies as offline when they have cancelled our subscription
Mikael Berthe <mikael@lilotux.net>
parents:
607
diff
changeset
|
686 |
// roster_unsubscribed() |
0e8247cf2bd1
Consider buddies as offline when they have cancelled our subscription
Mikael Berthe <mikael@lilotux.net>
parents:
607
diff
changeset
|
687 |
// We have lost buddy's presence updates; this function clears the status |
0e8247cf2bd1
Consider buddies as offline when they have cancelled our subscription
Mikael Berthe <mikael@lilotux.net>
parents:
607
diff
changeset
|
688 |
// message, sets the buddy offline and frees the resources |
0e8247cf2bd1
Consider buddies as offline when they have cancelled our subscription
Mikael Berthe <mikael@lilotux.net>
parents:
607
diff
changeset
|
689 |
void roster_unsubscribed(const char *jid) |
0e8247cf2bd1
Consider buddies as offline when they have cancelled our subscription
Mikael Berthe <mikael@lilotux.net>
parents:
607
diff
changeset
|
690 |
{ |
0e8247cf2bd1
Consider buddies as offline when they have cancelled our subscription
Mikael Berthe <mikael@lilotux.net>
parents:
607
diff
changeset
|
691 |
GSList *sl_user; |
0e8247cf2bd1
Consider buddies as offline when they have cancelled our subscription
Mikael Berthe <mikael@lilotux.net>
parents:
607
diff
changeset
|
692 |
roster *roster_usr; |
0e8247cf2bd1
Consider buddies as offline when they have cancelled our subscription
Mikael Berthe <mikael@lilotux.net>
parents:
607
diff
changeset
|
693 |
|
0e8247cf2bd1
Consider buddies as offline when they have cancelled our subscription
Mikael Berthe <mikael@lilotux.net>
parents:
607
diff
changeset
|
694 |
sl_user = roster_find(jid, jidsearch, ROSTER_TYPE_USER|ROSTER_TYPE_AGENT); |
0e8247cf2bd1
Consider buddies as offline when they have cancelled our subscription
Mikael Berthe <mikael@lilotux.net>
parents:
607
diff
changeset
|
695 |
if (sl_user == NULL) |
0e8247cf2bd1
Consider buddies as offline when they have cancelled our subscription
Mikael Berthe <mikael@lilotux.net>
parents:
607
diff
changeset
|
696 |
return; |
0e8247cf2bd1
Consider buddies as offline when they have cancelled our subscription
Mikael Berthe <mikael@lilotux.net>
parents:
607
diff
changeset
|
697 |
|
0e8247cf2bd1
Consider buddies as offline when they have cancelled our subscription
Mikael Berthe <mikael@lilotux.net>
parents:
607
diff
changeset
|
698 |
roster_usr = (roster*)sl_user->data; |
0e8247cf2bd1
Consider buddies as offline when they have cancelled our subscription
Mikael Berthe <mikael@lilotux.net>
parents:
607
diff
changeset
|
699 |
free_all_resources(&roster_usr->resource); |
0e8247cf2bd1
Consider buddies as offline when they have cancelled our subscription
Mikael Berthe <mikael@lilotux.net>
parents:
607
diff
changeset
|
700 |
} |
0e8247cf2bd1
Consider buddies as offline when they have cancelled our subscription
Mikael Berthe <mikael@lilotux.net>
parents:
607
diff
changeset
|
701 |
|
72 | 702 |
|
703 |
/* ### BuddyList functions ### */ |
|
704 |
||
120 | 705 |
// buddylist_set_hide_offline_buddies(hide) |
72 | 706 |
// "hide" values: 1=hide 0=show_all -1=invert |
120 | 707 |
void buddylist_set_hide_offline_buddies(int hide) |
72 | 708 |
{ |
709 |
if (hide < 0) // NEG (invert) |
|
710 |
hide_offline_buddies = !hide_offline_buddies; |
|
711 |
else if (hide == 0) // FALSE (don't hide) |
|
712 |
hide_offline_buddies = 0; |
|
713 |
else // TRUE (hide) |
|
714 |
hide_offline_buddies = 1; |
|
715 |
} |
|
716 |
||
120 | 717 |
inline int buddylist_get_hide_offline_buddies(void) |
718 |
{ |
|
719 |
return hide_offline_buddies; |
|
720 |
} |
|
721 |
||
72 | 722 |
// buddylist_build() |
723 |
// Creates the buddylist from the roster entries. |
|
724 |
void buddylist_build(void) |
|
725 |
{ |
|
726 |
GSList *sl_roster_elt = groups; |
|
727 |
roster *roster_elt; |
|
81 | 728 |
roster *roster_current_buddy = NULL; |
330 | 729 |
roster *roster_alternate_buddy = NULL; |
128 | 730 |
int shrunk_group; |
72 | 731 |
|
81 | 732 |
// We need to remember which buddy is selected. |
733 |
if (current_buddy) |
|
734 |
roster_current_buddy = BUDDATA(current_buddy); |
|
735 |
current_buddy = NULL; |
|
330 | 736 |
if (alternate_buddy) |
737 |
roster_alternate_buddy = BUDDATA(alternate_buddy); |
|
738 |
alternate_buddy = NULL; |
|
81 | 739 |
|
72 | 740 |
// Destroy old buddylist |
741 |
if (buddylist) { |
|
742 |
g_list_free(buddylist); |
|
743 |
buddylist = NULL; |
|
744 |
} |
|
745 |
||
848
a9161d2dc414
Introduce special buffer stuff
Mikael Berthe <mikael@lilotux.net>
parents:
843
diff
changeset
|
746 |
buddylist = g_list_append(buddylist, &roster_special); |
a9161d2dc414
Introduce special buffer stuff
Mikael Berthe <mikael@lilotux.net>
parents:
843
diff
changeset
|
747 |
|
72 | 748 |
// Create the new list |
749 |
while (sl_roster_elt) { |
|
750 |
GSList *sl_roster_usrelt; |
|
751 |
roster *roster_usrelt; |
|
147 | 752 |
guint pending_group = FALSE; |
72 | 753 |
roster_elt = (roster*) sl_roster_elt->data; |
754 |
||
755 |
// Add the group now unless hide_offline_buddies is set, |
|
756 |
// in which case we'll add it only if an online buddy belongs to it. |
|
147 | 757 |
// We take care to keep the current_buddy in the list, too. |
758 |
if (!hide_offline_buddies || roster_elt == roster_current_buddy) |
|
72 | 759 |
buddylist = g_list_append(buddylist, roster_elt); |
760 |
else |
|
147 | 761 |
pending_group = TRUE; |
72 | 762 |
|
128 | 763 |
shrunk_group = roster_elt->flags & ROSTER_FLAG_HIDE; |
764 |
||
72 | 765 |
sl_roster_usrelt = roster_elt->list; |
766 |
while (sl_roster_usrelt) { |
|
767 |
roster_usrelt = (roster*) sl_roster_usrelt->data; |
|
768 |
||
769 |
// Buddy will be added if either: |
|
770 |
// - hide_offline_buddies is FALSE |
|
771 |
// - buddy is not offline |
|
772 |
// - buddy has a lock (for example the buddy window is currently open) |
|
773 |
// - buddy has a pending (non-read) message |
|
128 | 774 |
// - group isn't hidden (shrunk) |
147 | 775 |
// - this is the current_buddy |
776 |
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
|
777 |
(buddy_getstatus((gpointer)roster_usrelt, NULL) != offline) || |
72 | 778 |
(buddy_getflags((gpointer)roster_usrelt) & |
779 |
(ROSTER_FLAG_LOCK | ROSTER_FLAG_MSG))) { |
|
780 |
// This user should be added. Maybe the group hasn't been added yet? |
|
147 | 781 |
if (pending_group && |
782 |
(hide_offline_buddies || roster_usrelt == roster_current_buddy)) { |
|
72 | 783 |
// It hasn't been done yet |
784 |
buddylist = g_list_append(buddylist, roster_elt); |
|
785 |
pending_group = FALSE; |
|
786 |
} |
|
787 |
// Add user |
|
128 | 788 |
// XXX Should we add the user if there is a message and |
789 |
// the group is shrunk? If so, we'd need to check LOCK flag too, |
|
790 |
// perhaps... |
|
791 |
if (!shrunk_group) |
|
792 |
buddylist = g_list_append(buddylist, roster_usrelt); |
|
72 | 793 |
} |
794 |
||
795 |
sl_roster_usrelt = g_slist_next(sl_roster_usrelt); |
|
796 |
} |
|
797 |
sl_roster_elt = g_slist_next(sl_roster_elt); |
|
798 |
} |
|
78 | 799 |
|
81 | 800 |
// Check if we can find our saved current_buddy... |
801 |
if (roster_current_buddy) |
|
802 |
current_buddy = g_list_find(buddylist, roster_current_buddy); |
|
330 | 803 |
if (roster_alternate_buddy) |
804 |
alternate_buddy = g_list_find(buddylist, roster_alternate_buddy); |
|
78 | 805 |
// current_buddy initialization |
806 |
if (!current_buddy || (g_list_position(buddylist, current_buddy) == -1)) |
|
81 | 807 |
current_buddy = g_list_first(buddylist); |
72 | 808 |
} |
809 |
||
810 |
// buddy_hide_group(roster, hide) |
|
811 |
// "hide" values: 1=hide 0=show_all -1=invert |
|
812 |
void buddy_hide_group(gpointer rosterdata, int hide) |
|
813 |
{ |
|
207 | 814 |
roster *roster_usr = rosterdata; |
72 | 815 |
if (hide > 0) // TRUE (hide) |
207 | 816 |
roster_usr->flags |= ROSTER_FLAG_HIDE; |
72 | 817 |
else if (hide < 0) // NEG (invert) |
207 | 818 |
roster_usr->flags ^= ROSTER_FLAG_HIDE; |
72 | 819 |
else // FALSE (don't hide) |
207 | 820 |
roster_usr->flags &= ~ROSTER_FLAG_HIDE; |
72 | 821 |
} |
822 |
||
823 |
const char *buddy_getjid(gpointer rosterdata) |
|
824 |
{ |
|
207 | 825 |
roster *roster_usr = rosterdata; |
826 |
return roster_usr->jid; |
|
827 |
} |
|
828 |
||
210 | 829 |
// buddy_setgroup() |
830 |
// Change the group of current buddy |
|
831 |
// |
|
832 |
void buddy_setgroup(gpointer rosterdata, char *newgroupname) |
|
833 |
{ |
|
834 |
roster *roster_usr = rosterdata; |
|
835 |
GSList **sl_group; |
|
620
97dd14e22b2a
Rewrite buddy_setgroup()
Mikael Berthe <mikael@lilotux.net>
parents:
610
diff
changeset
|
836 |
GSList *sl_newgroup; |
97dd14e22b2a
Rewrite buddy_setgroup()
Mikael Berthe <mikael@lilotux.net>
parents:
610
diff
changeset
|
837 |
roster *my_newgroup; |
210 | 838 |
|
839 |
// A group has no group :) |
|
840 |
if (roster_usr->type & ROSTER_TYPE_GROUP) return; |
|
841 |
||
620
97dd14e22b2a
Rewrite buddy_setgroup()
Mikael Berthe <mikael@lilotux.net>
parents:
610
diff
changeset
|
842 |
// Add newgroup if necessary |
97dd14e22b2a
Rewrite buddy_setgroup()
Mikael Berthe <mikael@lilotux.net>
parents:
610
diff
changeset
|
843 |
if (!newgroupname) newgroupname = ""; |
97dd14e22b2a
Rewrite buddy_setgroup()
Mikael Berthe <mikael@lilotux.net>
parents:
610
diff
changeset
|
844 |
sl_newgroup = roster_add_group(newgroupname); |
97dd14e22b2a
Rewrite buddy_setgroup()
Mikael Berthe <mikael@lilotux.net>
parents:
610
diff
changeset
|
845 |
if (!sl_newgroup) return; |
97dd14e22b2a
Rewrite buddy_setgroup()
Mikael Berthe <mikael@lilotux.net>
parents:
610
diff
changeset
|
846 |
my_newgroup = (roster*)sl_newgroup->data; |
97dd14e22b2a
Rewrite buddy_setgroup()
Mikael Berthe <mikael@lilotux.net>
parents:
610
diff
changeset
|
847 |
|
210 | 848 |
// Remove the buddy from current group |
849 |
sl_group = &((roster*)((GSList*)roster_usr->list)->data)->list; |
|
850 |
*sl_group = g_slist_remove(*sl_group, rosterdata); |
|
393 | 851 |
|
621
f20c1934a8a7
"/move": remove old group if it is empty
Mikael Berthe <mikael@lilotux.net>
parents:
620
diff
changeset
|
852 |
// Remove old group if it is empty |
f20c1934a8a7
"/move": remove old group if it is empty
Mikael Berthe <mikael@lilotux.net>
parents:
620
diff
changeset
|
853 |
if (!*sl_group) { |
f20c1934a8a7
"/move": remove old group if it is empty
Mikael Berthe <mikael@lilotux.net>
parents:
620
diff
changeset
|
854 |
roster *roster_grp = (roster*)((GSList*)roster_usr->list)->data; |
774
46304b773a44
Remove useless checks before g_free() calls
Mikael Berthe <mikael@lilotux.net>
parents:
772
diff
changeset
|
855 |
g_free((gchar*)roster_grp->jid); |
46304b773a44
Remove useless checks before g_free() calls
Mikael Berthe <mikael@lilotux.net>
parents:
772
diff
changeset
|
856 |
g_free((gchar*)roster_grp->name); |
621
f20c1934a8a7
"/move": remove old group if it is empty
Mikael Berthe <mikael@lilotux.net>
parents:
620
diff
changeset
|
857 |
g_free(roster_grp); |
f20c1934a8a7
"/move": remove old group if it is empty
Mikael Berthe <mikael@lilotux.net>
parents:
620
diff
changeset
|
858 |
groups = g_slist_remove(groups, roster_grp); |
f20c1934a8a7
"/move": remove old group if it is empty
Mikael Berthe <mikael@lilotux.net>
parents:
620
diff
changeset
|
859 |
} |
f20c1934a8a7
"/move": remove old group if it is empty
Mikael Berthe <mikael@lilotux.net>
parents:
620
diff
changeset
|
860 |
|
620
97dd14e22b2a
Rewrite buddy_setgroup()
Mikael Berthe <mikael@lilotux.net>
parents:
610
diff
changeset
|
861 |
// Add the buddy to its new group |
97dd14e22b2a
Rewrite buddy_setgroup()
Mikael Berthe <mikael@lilotux.net>
parents:
610
diff
changeset
|
862 |
roster_usr->list = sl_newgroup; // (my_newgroup SList element) |
97dd14e22b2a
Rewrite buddy_setgroup()
Mikael Berthe <mikael@lilotux.net>
parents:
610
diff
changeset
|
863 |
my_newgroup->list = g_slist_insert_sorted(my_newgroup->list, roster_usr, |
97dd14e22b2a
Rewrite buddy_setgroup()
Mikael Berthe <mikael@lilotux.net>
parents:
610
diff
changeset
|
864 |
(GCompareFunc)&roster_compare_name); |
212 | 865 |
|
210 | 866 |
buddylist_build(); |
867 |
} |
|
868 |
||
207 | 869 |
void buddy_setname(gpointer rosterdata, char *newname) |
870 |
{ |
|
871 |
roster *roster_usr = rosterdata; |
|
209 | 872 |
GSList **sl_group; |
207 | 873 |
|
874 |
// TODO For groups, we need to check for unicity |
|
875 |
// However, renaming a group boils down to moving all its buddies to |
|
876 |
// another group, so calling this function is not really necessary... |
|
877 |
if (roster_usr->type & ROSTER_TYPE_GROUP) return; |
|
878 |
||
879 |
if (roster_usr->name) { |
|
880 |
g_free((gchar*)roster_usr->name); |
|
881 |
roster_usr->name = NULL; |
|
882 |
} |
|
883 |
if (newname) |
|
884 |
roster_usr->name = g_strdup(newname); |
|
209 | 885 |
|
886 |
// We need to resort the group list |
|
887 |
sl_group = &((roster*)((GSList*)roster_usr->list)->data)->list; |
|
888 |
*sl_group = g_slist_sort(*sl_group, (GCompareFunc)&roster_compare_name); |
|
889 |
||
890 |
buddylist_build(); |
|
72 | 891 |
} |
892 |
||
893 |
const char *buddy_getname(gpointer rosterdata) |
|
894 |
{ |
|
207 | 895 |
roster *roster_usr = rosterdata; |
896 |
return roster_usr->name; |
|
897 |
} |
|
898 |
||
548
265c50238a48
Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
899 |
// buddy_setnickname(buddy, newnickname) |
265c50238a48
Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
900 |
// Only for chatrooms |
469
a926523d2392
Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
468
diff
changeset
|
901 |
void buddy_setnickname(gpointer rosterdata, const char *newname) |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
902 |
{ |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
903 |
roster *roster_usr = rosterdata; |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
904 |
|
649
3ad6675caaf1
MUC: fix join bug when the conference is in the roster
Mikael Berthe <mikael@lilotux.net>
parents:
644
diff
changeset
|
905 |
if (!(roster_usr->type & ROSTER_TYPE_ROOM)) return; // XXX Error message? |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
906 |
|
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
907 |
if (roster_usr->nickname) { |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
908 |
g_free((gchar*)roster_usr->nickname); |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
909 |
roster_usr->nickname = NULL; |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
910 |
} |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
911 |
if (newname) |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
912 |
roster_usr->nickname = g_strdup(newname); |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
913 |
} |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
914 |
|
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
915 |
const char *buddy_getnickname(gpointer rosterdata) |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
916 |
{ |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
917 |
roster *roster_usr = rosterdata; |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
918 |
return roster_usr->nickname; |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
919 |
} |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
920 |
|
644
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
625
diff
changeset
|
921 |
// buddy_setinsideroom(buddy, inside) |
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
625
diff
changeset
|
922 |
// Only for chatrooms |
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
625
diff
changeset
|
923 |
void buddy_setinsideroom(gpointer rosterdata, guint8 inside) |
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
625
diff
changeset
|
924 |
{ |
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
625
diff
changeset
|
925 |
roster *roster_usr = rosterdata; |
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
625
diff
changeset
|
926 |
|
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
625
diff
changeset
|
927 |
if (!(roster_usr->type & ROSTER_TYPE_ROOM)) return; |
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
625
diff
changeset
|
928 |
|
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
625
diff
changeset
|
929 |
roster_usr->inside_room = inside; |
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
625
diff
changeset
|
930 |
} |
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
625
diff
changeset
|
931 |
|
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
625
diff
changeset
|
932 |
guint8 buddy_getinsideroom(gpointer rosterdata) |
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
625
diff
changeset
|
933 |
{ |
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
625
diff
changeset
|
934 |
roster *roster_usr = rosterdata; |
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
625
diff
changeset
|
935 |
return roster_usr->inside_room; |
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
625
diff
changeset
|
936 |
} |
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
625
diff
changeset
|
937 |
|
548
265c50238a48
Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
938 |
// buddy_settopic(buddy, newtopic) |
265c50238a48
Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
939 |
// Only for chatrooms |
265c50238a48
Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
940 |
void buddy_settopic(gpointer rosterdata, const char *newtopic) |
265c50238a48
Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
941 |
{ |
265c50238a48
Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
942 |
roster *roster_usr = rosterdata; |
265c50238a48
Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
943 |
|
265c50238a48
Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
944 |
if (!(roster_usr->type & ROSTER_TYPE_ROOM)) return; |
265c50238a48
Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
945 |
|
265c50238a48
Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
946 |
if (roster_usr->topic) { |
265c50238a48
Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
947 |
g_free((gchar*)roster_usr->topic); |
265c50238a48
Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
948 |
roster_usr->topic = NULL; |
265c50238a48
Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
949 |
} |
265c50238a48
Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
950 |
if (newtopic) |
265c50238a48
Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
951 |
roster_usr->topic = g_strdup(newtopic); |
265c50238a48
Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
952 |
} |
265c50238a48
Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
953 |
|
265c50238a48
Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
954 |
const char *buddy_gettopic(gpointer rosterdata) |
265c50238a48
Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
955 |
{ |
265c50238a48
Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
956 |
roster *roster_usr = rosterdata; |
265c50238a48
Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
957 |
return roster_usr->topic; |
265c50238a48
Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
958 |
} |
265c50238a48
Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
959 |
|
207 | 960 |
// buddy_getgroupname() |
961 |
// Returns a pointer on buddy's group name. |
|
962 |
const char *buddy_getgroupname(gpointer rosterdata) |
|
963 |
{ |
|
964 |
roster *roster_usr = rosterdata; |
|
965 |
||
966 |
if (roster_usr->type & ROSTER_TYPE_GROUP) |
|
967 |
return roster_usr->name; |
|
968 |
||
848
a9161d2dc414
Introduce special buffer stuff
Mikael Berthe <mikael@lilotux.net>
parents:
843
diff
changeset
|
969 |
if (roster_usr->type & ROSTER_TYPE_SPECIAL) |
a9161d2dc414
Introduce special buffer stuff
Mikael Berthe <mikael@lilotux.net>
parents:
843
diff
changeset
|
970 |
return NULL; |
a9161d2dc414
Introduce special buffer stuff
Mikael Berthe <mikael@lilotux.net>
parents:
843
diff
changeset
|
971 |
|
207 | 972 |
// This is a user |
973 |
return ((roster*)((GSList*)roster_usr->list)->data)->name; |
|
72 | 974 |
} |
975 |
||
166 | 976 |
// buddy_getgroup() |
977 |
// Returns a pointer on buddy's group. |
|
978 |
gpointer buddy_getgroup(gpointer rosterdata) |
|
979 |
{ |
|
207 | 980 |
roster *roster_usr = rosterdata; |
166 | 981 |
|
207 | 982 |
if (roster_usr->type & ROSTER_TYPE_GROUP) |
166 | 983 |
return rosterdata; |
984 |
||
848
a9161d2dc414
Introduce special buffer stuff
Mikael Berthe <mikael@lilotux.net>
parents:
843
diff
changeset
|
985 |
if (roster_usr->type & ROSTER_TYPE_SPECIAL) |
a9161d2dc414
Introduce special buffer stuff
Mikael Berthe <mikael@lilotux.net>
parents:
843
diff
changeset
|
986 |
return NULL; |
a9161d2dc414
Introduce special buffer stuff
Mikael Berthe <mikael@lilotux.net>
parents:
843
diff
changeset
|
987 |
|
166 | 988 |
// This is a user |
207 | 989 |
return (gpointer)((GSList*)roster_usr->list)->data; |
166 | 990 |
} |
991 |
||
489
21ab22a60bcb
Auto-convert a roster item to "room" type when receiving a groupchat message
Mikael Berthe <mikael@lilotux.net>
parents:
483
diff
changeset
|
992 |
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
|
993 |
{ |
21ab22a60bcb
Auto-convert a roster item to "room" type when receiving a groupchat message
Mikael Berthe <mikael@lilotux.net>
parents:
483
diff
changeset
|
994 |
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
|
995 |
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
|
996 |
} |
21ab22a60bcb
Auto-convert a roster item to "room" type when receiving a groupchat message
Mikael Berthe <mikael@lilotux.net>
parents:
483
diff
changeset
|
997 |
|
72 | 998 |
guint buddy_gettype(gpointer rosterdata) |
999 |
{ |
|
207 | 1000 |
roster *roster_usr = rosterdata; |
1001 |
return roster_usr->type; |
|
72 | 1002 |
} |
1003 |
||
603 | 1004 |
guint buddy_getsubscription(gpointer rosterdata) |
1005 |
{ |
|
1006 |
roster *roster_usr = rosterdata; |
|
1007 |
return roster_usr->subscription; |
|
1008 |
} |
|
1009 |
||
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
1010 |
enum imstatus buddy_getstatus(gpointer rosterdata, const char *resname) |
72 | 1011 |
{ |
207 | 1012 |
roster *roster_usr = rosterdata; |
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
1013 |
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
|
1014 |
if (p_res) |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
1015 |
return p_res->status; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
1016 |
return offline; |
72 | 1017 |
} |
1018 |
||
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
1019 |
const char *buddy_getstatusmsg(gpointer rosterdata, const char *resname) |
221 | 1020 |
{ |
1021 |
roster *roster_usr = rosterdata; |
|
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
1022 |
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
|
1023 |
if (p_res) |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
1024 |
return p_res->status_msg; |
843
915a7f17474a
Remember the status message when a buddy goes offline
Mikael Berthe <mikael@lilotux.net>
parents:
819
diff
changeset
|
1025 |
return roster_usr->offline_status_message; |
221 | 1026 |
} |
1027 |
||
625
028c01940490
Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
621
diff
changeset
|
1028 |
time_t buddy_getstatustime(gpointer rosterdata, const char *resname) |
028c01940490
Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
621
diff
changeset
|
1029 |
{ |
028c01940490
Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
621
diff
changeset
|
1030 |
roster *roster_usr = rosterdata; |
028c01940490
Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
621
diff
changeset
|
1031 |
res *p_res = get_resource(roster_usr, resname); |
028c01940490
Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
621
diff
changeset
|
1032 |
if (p_res) |
028c01940490
Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
621
diff
changeset
|
1033 |
return p_res->status_timestamp; |
028c01940490
Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
621
diff
changeset
|
1034 |
return 0; |
028c01940490
Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
621
diff
changeset
|
1035 |
} |
028c01940490
Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
621
diff
changeset
|
1036 |
|
439
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
1037 |
gchar buddy_getresourceprio(gpointer rosterdata, const char *resname) |
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
1038 |
{ |
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
1039 |
roster *roster_usr = rosterdata; |
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
1040 |
res *p_res = get_resource(roster_usr, resname); |
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
1041 |
if (p_res) |
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
1042 |
return p_res->prio; |
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
1043 |
return 0; |
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
1044 |
} |
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
1045 |
|
572
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
1046 |
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
|
1047 |
{ |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
1048 |
roster *roster_usr = rosterdata; |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
1049 |
res *p_res = get_resource(roster_usr, resname); |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
1050 |
if (p_res) |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
1051 |
return p_res->role; |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
1052 |
return role_none; |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
1053 |
} |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
1054 |
|
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
1055 |
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
|
1056 |
{ |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
1057 |
roster *roster_usr = rosterdata; |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
1058 |
res *p_res = get_resource(roster_usr, resname); |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
1059 |
if (p_res) |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
1060 |
return p_res->affil; |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
1061 |
return affil_none; |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
1062 |
} |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
1063 |
|
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
1064 |
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
|
1065 |
{ |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
1066 |
roster *roster_usr = rosterdata; |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
1067 |
res *p_res = get_resource(roster_usr, resname); |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
1068 |
if (p_res) |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
1069 |
return p_res->realjid; |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
1070 |
return NULL; |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
1071 |
} |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
1072 |
|
439
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
1073 |
// buddy_getresources(roster_data) |
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
1074 |
// Return a singly-linked-list of resource names |
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
1075 |
// 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
|
1076 |
// 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
|
1077 |
GSList *buddy_getresources(gpointer rosterdata) |
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
1078 |
{ |
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
1079 |
roster *roster_usr = rosterdata; |
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
1080 |
GSList *reslist = NULL, *lp; |
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
1081 |
|
501
7c1ca00070e8
Add COMPL_RESOURCE (resource completion category)
Mikael Berthe <mikael@lilotux.net>
parents:
494
diff
changeset
|
1082 |
if (!roster_usr) { |
7c1ca00070e8
Add COMPL_RESOURCE (resource completion category)
Mikael Berthe <mikael@lilotux.net>
parents:
494
diff
changeset
|
1083 |
if (!current_buddy) return NULL; |
7c1ca00070e8
Add COMPL_RESOURCE (resource completion category)
Mikael Berthe <mikael@lilotux.net>
parents:
494
diff
changeset
|
1084 |
roster_usr = BUDDATA(current_buddy); |
7c1ca00070e8
Add COMPL_RESOURCE (resource completion category)
Mikael Berthe <mikael@lilotux.net>
parents:
494
diff
changeset
|
1085 |
} |
439
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
1086 |
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
|
1087 |
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
|
1088 |
|
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
1089 |
return reslist; |
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
1090 |
} |
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
1091 |
|
792
89ad7b530b3c
MUC: Fix completion for UTF-8 nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
783
diff
changeset
|
1092 |
// buddy_getresources_locale(roster_data) |
89ad7b530b3c
MUC: Fix completion for UTF-8 nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
783
diff
changeset
|
1093 |
// Same as buddy_getresources() but names are converted to user's locale |
89ad7b530b3c
MUC: Fix completion for UTF-8 nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
783
diff
changeset
|
1094 |
// Note: the caller should free the list (and data) after use |
89ad7b530b3c
MUC: Fix completion for UTF-8 nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
783
diff
changeset
|
1095 |
GSList *buddy_getresources_locale(gpointer rosterdata) |
89ad7b530b3c
MUC: Fix completion for UTF-8 nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
783
diff
changeset
|
1096 |
{ |
89ad7b530b3c
MUC: Fix completion for UTF-8 nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
783
diff
changeset
|
1097 |
GSList *reslist, *lp; |
89ad7b530b3c
MUC: Fix completion for UTF-8 nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
783
diff
changeset
|
1098 |
|
89ad7b530b3c
MUC: Fix completion for UTF-8 nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
783
diff
changeset
|
1099 |
reslist = buddy_getresources(rosterdata); |
89ad7b530b3c
MUC: Fix completion for UTF-8 nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
783
diff
changeset
|
1100 |
// Convert each item to UI's locale |
89ad7b530b3c
MUC: Fix completion for UTF-8 nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
783
diff
changeset
|
1101 |
for (lp = reslist; lp; lp = g_slist_next(lp)) { |
89ad7b530b3c
MUC: Fix completion for UTF-8 nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
783
diff
changeset
|
1102 |
gchar *oldname = lp->data; |
89ad7b530b3c
MUC: Fix completion for UTF-8 nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
783
diff
changeset
|
1103 |
lp->data = from_utf8(oldname); |
89ad7b530b3c
MUC: Fix completion for UTF-8 nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
783
diff
changeset
|
1104 |
if (lp->data) |
89ad7b530b3c
MUC: Fix completion for UTF-8 nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
783
diff
changeset
|
1105 |
g_free(oldname); |
89ad7b530b3c
MUC: Fix completion for UTF-8 nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
783
diff
changeset
|
1106 |
else |
89ad7b530b3c
MUC: Fix completion for UTF-8 nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
783
diff
changeset
|
1107 |
lp->data = oldname; |
89ad7b530b3c
MUC: Fix completion for UTF-8 nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
783
diff
changeset
|
1108 |
} |
89ad7b530b3c
MUC: Fix completion for UTF-8 nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
783
diff
changeset
|
1109 |
return reslist; |
89ad7b530b3c
MUC: Fix completion for UTF-8 nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
783
diff
changeset
|
1110 |
} |
89ad7b530b3c
MUC: Fix completion for UTF-8 nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
783
diff
changeset
|
1111 |
|
652
b243d3b3ff1b
We do not need buddy_isresource() anymore
Mikael Berthe <mikael@lilotux.net>
parents:
649
diff
changeset
|
1112 |
/* |
539 | 1113 |
// buddy_isresource(roster_data) |
1114 |
// Return true if there is at least one resource |
|
1115 |
// (which means, for a room, that it isn't empty) |
|
1116 |
int buddy_isresource(gpointer rosterdata) |
|
1117 |
{ |
|
1118 |
roster *roster_usr = rosterdata; |
|
1119 |
if (!roster_usr) |
|
1120 |
return FALSE; |
|
1121 |
if (roster_usr->resource) |
|
1122 |
return TRUE; |
|
1123 |
return FALSE; |
|
1124 |
} |
|
652
b243d3b3ff1b
We do not need buddy_isresource() anymore
Mikael Berthe <mikael@lilotux.net>
parents:
649
diff
changeset
|
1125 |
*/ |
539 | 1126 |
|
468
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
1127 |
// buddy_resource_setname(roster_data, oldname, newname) |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
1128 |
// Useful for nickname change in a MUC room |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
1129 |
void buddy_resource_setname(gpointer rosterdata, const char *resname, |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
1130 |
const char *newname) |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
1131 |
{ |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
1132 |
roster *roster_usr = rosterdata; |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
1133 |
res *p_res = get_resource(roster_usr, resname); |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
1134 |
if (p_res) { |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
1135 |
if (p_res->name) { |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
1136 |
g_free((gchar*)p_res->name); |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
1137 |
p_res->name = NULL; |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
1138 |
} |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
1139 |
if (newname) |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
1140 |
p_res->name = g_strdup(newname); |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
1141 |
} |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
1142 |
} |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
1143 |
|
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
1144 |
// buddy_del_all_resources() |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
1145 |
// Remove all resources from the specified buddy |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
1146 |
void buddy_del_all_resources(gpointer rosterdata) |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
1147 |
{ |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
1148 |
roster *roster_usr = rosterdata; |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
1149 |
|
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
1150 |
while (roster_usr->resource) { |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
1151 |
res *r = roster_usr->resource->data; |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
1152 |
del_resource(roster_usr, r->name); |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
1153 |
} |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
1154 |
} |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
1155 |
|
119 | 1156 |
// buddy_setflags() |
1157 |
// Set one or several flags to value (TRUE/FALSE) |
|
1158 |
void buddy_setflags(gpointer rosterdata, guint flags, guint value) |
|
1159 |
{ |
|
207 | 1160 |
roster *roster_usr = rosterdata; |
119 | 1161 |
if (value) |
207 | 1162 |
roster_usr->flags |= flags; |
119 | 1163 |
else |
207 | 1164 |
roster_usr->flags &= ~flags; |
119 | 1165 |
} |
1166 |
||
72 | 1167 |
guint buddy_getflags(gpointer rosterdata) |
1168 |
{ |
|
207 | 1169 |
roster *roster_usr = rosterdata; |
1170 |
return roster_usr->flags; |
|
72 | 1171 |
} |
1172 |
||
480 | 1173 |
// buddy_search_jid(jid) |
1174 |
// Look for a buddy with specified jid. |
|
1175 |
// Search begins at buddylist; if no match is found in the the buddylist, |
|
1176 |
// return NULL; |
|
1177 |
GList *buddy_search_jid(char *jid) |
|
1178 |
{ |
|
1179 |
GList *buddy; |
|
1180 |
roster *roster_usr; |
|
1181 |
||
1182 |
if (!buddylist) return NULL; |
|
1183 |
||
1184 |
for (buddy = buddylist; buddy; buddy = g_list_next(buddy)) { |
|
1185 |
roster_usr = (roster*)buddy->data; |
|
1186 |
if (roster_usr->jid && !strcasecmp(roster_usr->jid, jid)) |
|
1187 |
return buddy; |
|
1188 |
} |
|
1189 |
return NULL; |
|
1190 |
} |
|
1191 |
||
265 | 1192 |
// buddy_search(string) |
1193 |
// Look for a buddy whose name or jid contains string. |
|
1194 |
// Search begins at current_buddy; if no match is found in the the buddylist, |
|
1195 |
// return NULL; |
|
1196 |
GList *buddy_search(char *string) |
|
1197 |
{ |
|
1198 |
GList *buddy = current_buddy; |
|
1199 |
roster *roster_usr; |
|
1200 |
if (!buddylist || !current_buddy) return NULL; |
|
1201 |
for (;;) { |
|
772
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
1202 |
gchar *jid_locale, *name_locale; |
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
1203 |
char *found = NULL; |
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
1204 |
|
265 | 1205 |
buddy = g_list_next(buddy); |
1206 |
if (!buddy) |
|
1207 |
buddy = buddylist; |
|
1208 |
||
1209 |
roster_usr = (roster*)buddy->data; |
|
772
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
1210 |
|
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
1211 |
jid_locale = from_utf8(roster_usr->jid); |
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
1212 |
if (jid_locale) { |
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
1213 |
found = strcasestr(jid_locale, string); |
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
1214 |
g_free(jid_locale); |
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
1215 |
if (found) |
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
1216 |
return buddy; |
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
1217 |
} |
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
1218 |
name_locale = from_utf8(roster_usr->name); |
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
1219 |
if (name_locale) { |
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
1220 |
found = strcasestr(name_locale, string); |
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
1221 |
g_free(name_locale); |
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
1222 |
if (found) |
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
1223 |
return buddy; |
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
1224 |
} |
265 | 1225 |
|
1226 |
if (buddy == current_buddy) |
|
1227 |
return NULL; // Back to the beginning, and no match found |
|
1228 |
} |
|
1229 |
} |
|
1230 |
||
532
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
520
diff
changeset
|
1231 |
// foreach_buddy(roster_type, pfunction, param) |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
520
diff
changeset
|
1232 |
// 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
|
1233 |
// type matching roster_type. |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
520
diff
changeset
|
1234 |
void foreach_buddy(guint roster_type, |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
520
diff
changeset
|
1235 |
void (*pfunc)(gpointer rosterdata, void *param), |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
520
diff
changeset
|
1236 |
void *param) |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
520
diff
changeset
|
1237 |
{ |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
520
diff
changeset
|
1238 |
GSList *sl_roster_elt = groups; |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
520
diff
changeset
|
1239 |
roster *roster_elt; |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
520
diff
changeset
|
1240 |
GSList *sl_roster_usrelt; |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
520
diff
changeset
|
1241 |
roster *roster_usrelt; |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
520
diff
changeset
|
1242 |
|
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
520
diff
changeset
|
1243 |
while (sl_roster_elt) { // group list loop |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
520
diff
changeset
|
1244 |
roster_elt = (roster*) sl_roster_elt->data; |
848
a9161d2dc414
Introduce special buffer stuff
Mikael Berthe <mikael@lilotux.net>
parents:
843
diff
changeset
|
1245 |
if (roster_elt->type & ROSTER_TYPE_SPECIAL) |
a9161d2dc414
Introduce special buffer stuff
Mikael Berthe <mikael@lilotux.net>
parents:
843
diff
changeset
|
1246 |
continue; // Skip special items |
532
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
520
diff
changeset
|
1247 |
sl_roster_usrelt = roster_elt->list; |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
520
diff
changeset
|
1248 |
while (sl_roster_usrelt) { // user list loop |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
520
diff
changeset
|
1249 |
roster_usrelt = (roster*) sl_roster_usrelt->data; |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
520
diff
changeset
|
1250 |
|
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
520
diff
changeset
|
1251 |
if (roster_usrelt->type & roster_type) |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
520
diff
changeset
|
1252 |
pfunc(roster_usrelt, param); |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
520
diff
changeset
|
1253 |
|
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
520
diff
changeset
|
1254 |
sl_roster_usrelt = g_slist_next(sl_roster_usrelt); |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
520
diff
changeset
|
1255 |
} |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
520
diff
changeset
|
1256 |
sl_roster_elt = g_slist_next(sl_roster_elt); |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
520
diff
changeset
|
1257 |
} |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
520
diff
changeset
|
1258 |
} |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
520
diff
changeset
|
1259 |
|
885
afdd81c2c44d
Allow /rename for groups
Mikael Berthe <mikael@lilotux.net>
parents:
863
diff
changeset
|
1260 |
// foreach_group_member(group, pfunction, param) |
afdd81c2c44d
Allow /rename for groups
Mikael Berthe <mikael@lilotux.net>
parents:
863
diff
changeset
|
1261 |
// Call pfunction(buddy, param) for each buddy in the specified group. |
afdd81c2c44d
Allow /rename for groups
Mikael Berthe <mikael@lilotux.net>
parents:
863
diff
changeset
|
1262 |
void foreach_group_member(gpointer groupdata, |
afdd81c2c44d
Allow /rename for groups
Mikael Berthe <mikael@lilotux.net>
parents:
863
diff
changeset
|
1263 |
void (*pfunc)(gpointer rosterdata, void *param), |
afdd81c2c44d
Allow /rename for groups
Mikael Berthe <mikael@lilotux.net>
parents:
863
diff
changeset
|
1264 |
void *param) |
afdd81c2c44d
Allow /rename for groups
Mikael Berthe <mikael@lilotux.net>
parents:
863
diff
changeset
|
1265 |
{ |
afdd81c2c44d
Allow /rename for groups
Mikael Berthe <mikael@lilotux.net>
parents:
863
diff
changeset
|
1266 |
roster *roster_elt; |
afdd81c2c44d
Allow /rename for groups
Mikael Berthe <mikael@lilotux.net>
parents:
863
diff
changeset
|
1267 |
GSList *sl_roster_usrelt; |
afdd81c2c44d
Allow /rename for groups
Mikael Berthe <mikael@lilotux.net>
parents:
863
diff
changeset
|
1268 |
roster *roster_usrelt; |
afdd81c2c44d
Allow /rename for groups
Mikael Berthe <mikael@lilotux.net>
parents:
863
diff
changeset
|
1269 |
|
afdd81c2c44d
Allow /rename for groups
Mikael Berthe <mikael@lilotux.net>
parents:
863
diff
changeset
|
1270 |
roster_elt = groupdata; |
afdd81c2c44d
Allow /rename for groups
Mikael Berthe <mikael@lilotux.net>
parents:
863
diff
changeset
|
1271 |
|
afdd81c2c44d
Allow /rename for groups
Mikael Berthe <mikael@lilotux.net>
parents:
863
diff
changeset
|
1272 |
if (!(roster_elt->type & ROSTER_TYPE_GROUP)) |
afdd81c2c44d
Allow /rename for groups
Mikael Berthe <mikael@lilotux.net>
parents:
863
diff
changeset
|
1273 |
return; |
afdd81c2c44d
Allow /rename for groups
Mikael Berthe <mikael@lilotux.net>
parents:
863
diff
changeset
|
1274 |
|
afdd81c2c44d
Allow /rename for groups
Mikael Berthe <mikael@lilotux.net>
parents:
863
diff
changeset
|
1275 |
sl_roster_usrelt = roster_elt->list; |
afdd81c2c44d
Allow /rename for groups
Mikael Berthe <mikael@lilotux.net>
parents:
863
diff
changeset
|
1276 |
while (sl_roster_usrelt) { // user list loop |
afdd81c2c44d
Allow /rename for groups
Mikael Berthe <mikael@lilotux.net>
parents:
863
diff
changeset
|
1277 |
roster_usrelt = (roster*) sl_roster_usrelt->data; |
afdd81c2c44d
Allow /rename for groups
Mikael Berthe <mikael@lilotux.net>
parents:
863
diff
changeset
|
1278 |
|
afdd81c2c44d
Allow /rename for groups
Mikael Berthe <mikael@lilotux.net>
parents:
863
diff
changeset
|
1279 |
pfunc(roster_usrelt, param); |
afdd81c2c44d
Allow /rename for groups
Mikael Berthe <mikael@lilotux.net>
parents:
863
diff
changeset
|
1280 |
sl_roster_usrelt = g_slist_next(sl_roster_usrelt); |
afdd81c2c44d
Allow /rename for groups
Mikael Berthe <mikael@lilotux.net>
parents:
863
diff
changeset
|
1281 |
} |
afdd81c2c44d
Allow /rename for groups
Mikael Berthe <mikael@lilotux.net>
parents:
863
diff
changeset
|
1282 |
} |
afdd81c2c44d
Allow /rename for groups
Mikael Berthe <mikael@lilotux.net>
parents:
863
diff
changeset
|
1283 |
|
225 | 1284 |
// compl_list(type) |
1285 |
// Returns a list of jid's or groups. (For commands completion) |
|
1286 |
// type: ROSTER_TYPE_USER (jid's) or ROSTER_TYPE_GROUP (group names) |
|
1287 |
// The list should be freed by the caller after use. |
|
1288 |
GSList *compl_list(guint type) |
|
1289 |
{ |
|
1290 |
GSList *list = NULL; |
|
1291 |
GList *buddy = buddylist; |
|
1292 |
||
1293 |
for ( ; buddy ; buddy = g_list_next(buddy)) { |
|
1294 |
guint btype = buddy_gettype(BUDDATA(buddy)); |
|
1295 |
||
1296 |
if (type == ROSTER_TYPE_GROUP) { // (group names) |
|
1297 |
if (btype == ROSTER_TYPE_GROUP) { |
|
1298 |
const char *bname = buddy_getname(BUDDATA(buddy)); |
|
1299 |
if ((bname) && (*bname)) |
|
772
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
1300 |
list = g_slist_append(list, from_utf8(bname)); |
225 | 1301 |
} |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
1302 |
} else { // ROSTER_TYPE_USER (jid) (or agent, or chatroom...) |
225 | 1303 |
const char *bjid = buddy_getjid(BUDDATA(buddy)); |
1304 |
if (bjid) |
|
772
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
1305 |
list = g_slist_append(list, from_utf8(bjid)); |
225 | 1306 |
} |
1307 |
} |
|
1308 |
||
1309 |
return list; |
|
1310 |
} |
|
1311 |
||
236 | 1312 |
// unread_msg(rosterdata) |
1313 |
// Return the next buddy with an unread message. If the parameter is NULL, |
|
1314 |
// return the first buddy with an unread message. |
|
1315 |
gpointer unread_msg(gpointer rosterdata) |
|
1316 |
{ |
|
1317 |
GSList *unread, *next_unread; |
|
1318 |
||
564 | 1319 |
if (!unread_list) |
1320 |
return NULL; |
|
1321 |
||
236 | 1322 |
// First unread message |
564 | 1323 |
if (!rosterdata) |
1324 |
return unread_list->data; |
|
236 | 1325 |
|
1326 |
unread = g_slist_find(unread_list, rosterdata); |
|
564 | 1327 |
if (!unread) |
1328 |
return unread_list->data; |
|
236 | 1329 |
|
1330 |
next_unread = g_slist_next(unread); |
|
564 | 1331 |
if (next_unread) |
1332 |
return next_unread->data; |
|
236 | 1333 |
return unread_list->data; |
1334 |
} |
|
576 | 1335 |
|
662
4111ff4cdd15
Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents:
652
diff
changeset
|
1336 |
|
4111ff4cdd15
Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents:
652
diff
changeset
|
1337 |
/* ### "unread_jids" functions ### |
4111ff4cdd15
Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents:
652
diff
changeset
|
1338 |
* |
4111ff4cdd15
Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents:
652
diff
changeset
|
1339 |
* The unread_jids hash table is used to keep track of the buddies with |
4111ff4cdd15
Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents:
652
diff
changeset
|
1340 |
* unread messages when a disconnection occurs. |
4111ff4cdd15
Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents:
652
diff
changeset
|
1341 |
* When removing a buddy with an unread message from the roster, the |
4111ff4cdd15
Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents:
652
diff
changeset
|
1342 |
* jid should be added to the unread_jids table. When adding a buddy to |
4111ff4cdd15
Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents:
652
diff
changeset
|
1343 |
* the roster, we check if (s)he had a pending unread message. |
4111ff4cdd15
Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents:
652
diff
changeset
|
1344 |
*/ |
4111ff4cdd15
Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents:
652
diff
changeset
|
1345 |
|
4111ff4cdd15
Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents:
652
diff
changeset
|
1346 |
// unread_jid_add(jid) |
4111ff4cdd15
Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents:
652
diff
changeset
|
1347 |
// Add jid to the unread_jids hash table |
4111ff4cdd15
Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents:
652
diff
changeset
|
1348 |
void unread_jid_add(const char *jid) |
4111ff4cdd15
Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents:
652
diff
changeset
|
1349 |
{ |
4111ff4cdd15
Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents:
652
diff
changeset
|
1350 |
if (!unread_jids) { |
4111ff4cdd15
Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents:
652
diff
changeset
|
1351 |
// Initialize unread_jids hash table |
4111ff4cdd15
Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents:
652
diff
changeset
|
1352 |
unread_jids = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL); |
4111ff4cdd15
Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents:
652
diff
changeset
|
1353 |
} |
4111ff4cdd15
Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents:
652
diff
changeset
|
1354 |
// The 2nd unread_jids is an arbitrary non-null pointer: |
4111ff4cdd15
Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents:
652
diff
changeset
|
1355 |
g_hash_table_insert(unread_jids, g_strdup(jid), unread_jids); |
4111ff4cdd15
Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents:
652
diff
changeset
|
1356 |
} |
4111ff4cdd15
Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents:
652
diff
changeset
|
1357 |
|
4111ff4cdd15
Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents:
652
diff
changeset
|
1358 |
// unread_jid_del(jid) |
4111ff4cdd15
Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents:
652
diff
changeset
|
1359 |
// Return TRUE if jid is found in the table (and remove it), FALSE if not |
4111ff4cdd15
Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents:
652
diff
changeset
|
1360 |
int unread_jid_del(const char *jid) |
4111ff4cdd15
Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents:
652
diff
changeset
|
1361 |
{ |
4111ff4cdd15
Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents:
652
diff
changeset
|
1362 |
if (!unread_jids) |
4111ff4cdd15
Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents:
652
diff
changeset
|
1363 |
return FALSE; |
4111ff4cdd15
Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents:
652
diff
changeset
|
1364 |
return g_hash_table_remove(unread_jids, jid); |
4111ff4cdd15
Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents:
652
diff
changeset
|
1365 |
} |
4111ff4cdd15
Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents:
652
diff
changeset
|
1366 |
|
580 | 1367 |
/* vim: set expandtab cindent cinoptions=>2\:2(0: For Vim users... */ |