author | franky |
Tue, 23 Sep 2008 10:59:25 +0200 | |
changeset 1600 | c5ee395fbc8c |
parent 1599 | dcd5d4c75199 |
permissions | -rw-r--r-- |
72 | 1 |
/* |
2 |
* roster.c -- Local roster implementation |
|
393 | 3 |
* |
1599 | 4 |
* Copyright (C) 2005-2009 Mikael Berthe <mikael@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 |
||
22 |
#include <string.h> |
|
23 |
||
24 |
#include "roster.h" |
|
772
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
25 |
#include "utils.h" |
1444
3bf11085c6a5
New external "UNREAD" event (suggested by Viacheslav Chumushuk)
Mikael Berthe <mikael@lilotux.net>
parents:
1438
diff
changeset
|
26 |
#include "hooks.h" |
72 | 27 |
|
1437
071c8170b7de
Add option 'statefile' to keep track of unread messages across restarts
Mikael Berthe <mikael@lilotux.net>
parents:
1431
diff
changeset
|
28 |
extern void hlog_save_state(void); |
72 | 29 |
|
1377
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1366
diff
changeset
|
30 |
char *strrole[] = { /* Should match enum in roster.h */ |
584 | 31 |
"none", |
32 |
"moderator", |
|
33 |
"participant", |
|
34 |
"visitor" |
|
35 |
}; |
|
36 |
||
1377
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1366
diff
changeset
|
37 |
char *straffil[] = { /* Should match enum in roster.h */ |
584 | 38 |
"none", |
39 |
"owner", |
|
40 |
"admin", |
|
1331
a97701d8d735
Fix typo in the straffil structure (reported by gst)
Mikael Berthe <mikael@lilotux.net>
parents:
1311
diff
changeset
|
41 |
"member", |
584 | 42 |
"outcast" |
43 |
}; |
|
44 |
||
1377
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1366
diff
changeset
|
45 |
char *strprintstatus[] = { /* Should match enum in roster.h */ |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1366
diff
changeset
|
46 |
"default", |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1366
diff
changeset
|
47 |
"none", |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1366
diff
changeset
|
48 |
"in_and_out", |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1366
diff
changeset
|
49 |
"all" |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1366
diff
changeset
|
50 |
}; |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1366
diff
changeset
|
51 |
|
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1366
diff
changeset
|
52 |
char *strautowhois[] = { /* Should match enum in roster.h */ |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1366
diff
changeset
|
53 |
"default", |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1366
diff
changeset
|
54 |
"off", |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1366
diff
changeset
|
55 |
"on", |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1366
diff
changeset
|
56 |
}; |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1366
diff
changeset
|
57 |
|
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
58 |
/* Resource structure */ |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
59 |
|
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
60 |
typedef struct { |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
61 |
gchar *name; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
62 |
gchar prio; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
63 |
enum imstatus status; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
64 |
gchar *status_msg; |
625
028c01940490
Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
621
diff
changeset
|
65 |
time_t status_timestamp; |
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
66 |
enum imrole role; |
572
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
67 |
enum imaffiliation affil; |
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
68 |
gchar *realjid; /* for chatrooms, if buddy's real jid is known */ |
986
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
69 |
guint events; |
1600 | 70 |
char *caps; |
987
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
71 |
#ifdef JEP0022 |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
72 |
struct jep0022 jep22; |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
73 |
#endif |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
74 |
#ifdef JEP0085 |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
75 |
struct jep0085 jep85; |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
76 |
#endif |
1043
ebbde723614b
Store contacts PGP keys
Mikael Berthe <mikael@lilotux.net>
parents:
1010
diff
changeset
|
77 |
#ifdef HAVE_GPGME |
ebbde723614b
Store contacts PGP keys
Mikael Berthe <mikael@lilotux.net>
parents:
1010
diff
changeset
|
78 |
struct pgp_data pgpdata; |
ebbde723614b
Store contacts PGP keys
Mikael Berthe <mikael@lilotux.net>
parents:
1010
diff
changeset
|
79 |
#endif |
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
80 |
} res; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
81 |
|
72 | 82 |
/* This is a private structure type for the roster */ |
83 |
||
84 |
typedef struct { |
|
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
85 |
gchar *name; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
86 |
gchar *jid; |
72 | 87 |
guint type; |
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
88 |
enum subscr subscription; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
89 |
GSList *resource; |
644
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
625
diff
changeset
|
90 |
|
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
625
diff
changeset
|
91 |
/* For groupchats */ |
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
625
diff
changeset
|
92 |
gchar *nickname; |
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
625
diff
changeset
|
93 |
gchar *topic; |
952 | 94 |
guint inside_room; |
1377
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1366
diff
changeset
|
95 |
guint print_status; |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1366
diff
changeset
|
96 |
guint auto_whois; |
644
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
625
diff
changeset
|
97 |
|
1355 | 98 |
/* on_server is TRUE if the item is present on the server roster */ |
99 |
guint on_server; |
|
100 |
||
843
915a7f17474a
Remember the status message when a buddy goes offline
Mikael Berthe <mikael@lilotux.net>
parents:
819
diff
changeset
|
101 |
/* 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
|
102 |
gchar *offline_status_message; |
915a7f17474a
Remember the status message when a buddy goes offline
Mikael Berthe <mikael@lilotux.net>
parents:
819
diff
changeset
|
103 |
|
644
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
625
diff
changeset
|
104 |
/* Flag used for the UI */ |
72 | 105 |
guint flags; |
644
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
625
diff
changeset
|
106 |
|
72 | 107 |
// list: user -> points to his group; group -> points to its users list |
108 |
GSList *list; |
|
109 |
} roster; |
|
110 |
||
111 |
||
112 |
/* ### Variables ### */ |
|
113 |
||
1311
0dda8238af21
Implement "/roster display"
Mikael Berthe <mikael@lilotux.net>
parents:
1292
diff
changeset
|
114 |
static guchar display_filter; |
72 | 115 |
static GSList *groups; |
236 | 116 |
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
|
117 |
static GHashTable *unread_jids; |
72 | 118 |
GList *buddylist; |
78 | 119 |
GList *current_buddy; |
330 | 120 |
GList *alternate_buddy; |
72 | 121 |
|
848
a9161d2dc414
Introduce special buffer stuff
Mikael Berthe <mikael@lilotux.net>
parents:
843
diff
changeset
|
122 |
static roster roster_special; |
a9161d2dc414
Introduce special buffer stuff
Mikael Berthe <mikael@lilotux.net>
parents:
843
diff
changeset
|
123 |
|
1437
071c8170b7de
Add option 'statefile' to keep track of unread messages across restarts
Mikael Berthe <mikael@lilotux.net>
parents:
1431
diff
changeset
|
124 |
static int unread_jid_del(const char *jid); |
662
4111ff4cdd15
Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents:
652
diff
changeset
|
125 |
|
1311
0dda8238af21
Implement "/roster display"
Mikael Berthe <mikael@lilotux.net>
parents:
1292
diff
changeset
|
126 |
#define DFILTER_ALL 63 |
0dda8238af21
Implement "/roster display"
Mikael Berthe <mikael@lilotux.net>
parents:
1292
diff
changeset
|
127 |
#define DFILTER_ONLINE 62 |
0dda8238af21
Implement "/roster display"
Mikael Berthe <mikael@lilotux.net>
parents:
1292
diff
changeset
|
128 |
|
72 | 129 |
|
848
a9161d2dc414
Introduce special buffer stuff
Mikael Berthe <mikael@lilotux.net>
parents:
843
diff
changeset
|
130 |
/* ### Initialization ### */ |
a9161d2dc414
Introduce special buffer stuff
Mikael Berthe <mikael@lilotux.net>
parents:
843
diff
changeset
|
131 |
|
a9161d2dc414
Introduce special buffer stuff
Mikael Berthe <mikael@lilotux.net>
parents:
843
diff
changeset
|
132 |
void roster_init(void) |
a9161d2dc414
Introduce special buffer stuff
Mikael Berthe <mikael@lilotux.net>
parents:
843
diff
changeset
|
133 |
{ |
889
ae93e69aaaaf
Fix up pending message flag for the status special buffer
Mikael Berthe <mikael@lilotux.net>
parents:
885
diff
changeset
|
134 |
roster_special.name = SPECIAL_BUFFER_STATUS_ID; |
848
a9161d2dc414
Introduce special buffer stuff
Mikael Berthe <mikael@lilotux.net>
parents:
843
diff
changeset
|
135 |
roster_special.type = ROSTER_TYPE_SPECIAL; |
a9161d2dc414
Introduce special buffer stuff
Mikael Berthe <mikael@lilotux.net>
parents:
843
diff
changeset
|
136 |
} |
a9161d2dc414
Introduce special buffer stuff
Mikael Berthe <mikael@lilotux.net>
parents:
843
diff
changeset
|
137 |
|
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
138 |
/* ### Resources functions ### */ |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
139 |
|
1063
4e62941df777
roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents:
1058
diff
changeset
|
140 |
static inline void free_resource_data(res *p_res) |
4e62941df777
roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents:
1058
diff
changeset
|
141 |
{ |
4e62941df777
roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents:
1058
diff
changeset
|
142 |
if (!p_res) |
4e62941df777
roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents:
1058
diff
changeset
|
143 |
return; |
4e62941df777
roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents:
1058
diff
changeset
|
144 |
g_free((gchar*)p_res->status_msg); |
4e62941df777
roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents:
1058
diff
changeset
|
145 |
g_free((gchar*)p_res->name); |
4e62941df777
roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents:
1058
diff
changeset
|
146 |
g_free((gchar*)p_res->realjid); |
4e62941df777
roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents:
1058
diff
changeset
|
147 |
#ifdef JEP0022 |
4e62941df777
roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents:
1058
diff
changeset
|
148 |
g_free(p_res->jep22.last_msgid_sent); |
4e62941df777
roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents:
1058
diff
changeset
|
149 |
g_free(p_res->jep22.last_msgid_rcvd); |
4e62941df777
roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents:
1058
diff
changeset
|
150 |
#endif |
4e62941df777
roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents:
1058
diff
changeset
|
151 |
#ifdef HAVE_GPGME |
4e62941df777
roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents:
1058
diff
changeset
|
152 |
g_free(p_res->pgpdata.sign_keyid); |
4e62941df777
roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents:
1058
diff
changeset
|
153 |
#endif |
1600 | 154 |
g_free(p_res->caps); |
1063
4e62941df777
roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents:
1058
diff
changeset
|
155 |
g_free(p_res); |
4e62941df777
roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents:
1058
diff
changeset
|
156 |
} |
4e62941df777
roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents:
1058
diff
changeset
|
157 |
|
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
158 |
static void free_all_resources(GSList **reslist) |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
159 |
{ |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
160 |
GSList *lip; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
161 |
|
1063
4e62941df777
roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents:
1058
diff
changeset
|
162 |
for (lip = *reslist; lip ; lip = g_slist_next(lip)) |
4e62941df777
roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents:
1058
diff
changeset
|
163 |
free_resource_data((res*)lip->data); |
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
164 |
// 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
|
165 |
g_slist_free(*reslist); |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
166 |
*reslist = 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 |
|
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
169 |
// Resources are sorted in ascending order |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
170 |
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
|
171 |
//return (a->prio - b->prio); |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
172 |
if (a->prio < b->prio) return -1; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
173 |
else return 1; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
174 |
} |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
175 |
|
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
176 |
// get_resource(rost, resname) |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
177 |
// 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
|
178 |
// - if rost has no resources, return NULL |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
179 |
// - 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
|
180 |
// - 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
|
181 |
// 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
|
182 |
// (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
|
183 |
// |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
184 |
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
|
185 |
{ |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
186 |
GSList *p; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
187 |
res *r = NULL; |
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 |
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
|
190 |
r = p->data; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
191 |
if (resname && !strcmp(r->name, resname)) |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
192 |
return r; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
193 |
} |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
194 |
|
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
195 |
// 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
|
196 |
// 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
|
197 |
if (!resname) return r; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
198 |
return NULL; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
199 |
} |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
200 |
|
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
201 |
// get_or_add_resource(rost, resname, priority) |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
202 |
// - 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
|
203 |
// on this resource |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
204 |
// - 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
|
205 |
// new resource |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
206 |
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
|
207 |
{ |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
208 |
GSList *p; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
209 |
res *nres; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
210 |
|
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
211 |
if (!resname) return NULL; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
212 |
|
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
213 |
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
|
214 |
res *r = p->data; |
1092
1ef7572c3096
Sort the resources again when a priority changes
Mikael Berthe <mikael@lilotux.net>
parents:
1088
diff
changeset
|
215 |
if (!strcmp(r->name, resname)) { |
1ef7572c3096
Sort the resources again when a priority changes
Mikael Berthe <mikael@lilotux.net>
parents:
1088
diff
changeset
|
216 |
if (prio != r->prio) { |
1ef7572c3096
Sort the resources again when a priority changes
Mikael Berthe <mikael@lilotux.net>
parents:
1088
diff
changeset
|
217 |
r->prio = prio; |
1ef7572c3096
Sort the resources again when a priority changes
Mikael Berthe <mikael@lilotux.net>
parents:
1088
diff
changeset
|
218 |
rost->resource = g_slist_sort(rost->resource, |
1ef7572c3096
Sort the resources again when a priority changes
Mikael Berthe <mikael@lilotux.net>
parents:
1088
diff
changeset
|
219 |
(GCompareFunc)&resource_compare_prio); |
1ef7572c3096
Sort the resources again when a priority changes
Mikael Berthe <mikael@lilotux.net>
parents:
1088
diff
changeset
|
220 |
} |
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
221 |
return r; |
1092
1ef7572c3096
Sort the resources again when a priority changes
Mikael Berthe <mikael@lilotux.net>
parents:
1088
diff
changeset
|
222 |
} |
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
223 |
} |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
224 |
|
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
225 |
// Resource not found |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
226 |
nres = g_new0(res, 1); |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
227 |
nres->name = g_strdup(resname); |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
228 |
nres->prio = prio; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
229 |
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
|
230 |
(GCompareFunc)&resource_compare_prio); |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
231 |
return nres; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
232 |
} |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
233 |
|
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
234 |
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
|
235 |
{ |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
236 |
GSList *p; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
237 |
GSList *p_res_elt = NULL; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
238 |
res *p_res; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
239 |
|
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
240 |
if (!resname) return; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
241 |
|
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
242 |
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
|
243 |
res *r = p->data; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
244 |
if (!strcmp(r->name, resname)) |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
245 |
p_res_elt = p; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
246 |
} |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
247 |
|
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
248 |
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
|
249 |
|
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
250 |
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
|
251 |
|
915a7f17474a
Remember the status message when a buddy goes offline
Mikael Berthe <mikael@lilotux.net>
parents:
819
diff
changeset
|
252 |
// 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
|
253 |
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
|
254 |
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
|
255 |
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
|
256 |
p_res->status_msg = NULL; |
915a7f17474a
Remember the status message when a buddy goes offline
Mikael Berthe <mikael@lilotux.net>
parents:
819
diff
changeset
|
257 |
} |
915a7f17474a
Remember the status message when a buddy goes offline
Mikael Berthe <mikael@lilotux.net>
parents:
819
diff
changeset
|
258 |
|
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
259 |
// Free allocations and delete resource node |
1063
4e62941df777
roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents:
1058
diff
changeset
|
260 |
free_resource_data(p_res); |
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
261 |
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
|
262 |
return; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
263 |
} |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
264 |
|
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
265 |
|
72 | 266 |
/* ### Roster functions ### */ |
267 |
||
1063
4e62941df777
roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents:
1058
diff
changeset
|
268 |
static inline void free_roster_user_data(roster *roster_usr) |
4e62941df777
roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents:
1058
diff
changeset
|
269 |
{ |
4e62941df777
roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents:
1058
diff
changeset
|
270 |
if (!roster_usr) |
4e62941df777
roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents:
1058
diff
changeset
|
271 |
return; |
4e62941df777
roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents:
1058
diff
changeset
|
272 |
g_free((gchar*)roster_usr->jid); |
4e62941df777
roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents:
1058
diff
changeset
|
273 |
g_free((gchar*)roster_usr->name); |
4e62941df777
roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents:
1058
diff
changeset
|
274 |
g_free((gchar*)roster_usr->nickname); |
4e62941df777
roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents:
1058
diff
changeset
|
275 |
g_free((gchar*)roster_usr->topic); |
4e62941df777
roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents:
1058
diff
changeset
|
276 |
g_free((gchar*)roster_usr->offline_status_message); |
4e62941df777
roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents:
1058
diff
changeset
|
277 |
free_all_resources(&roster_usr->resource); |
4e62941df777
roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents:
1058
diff
changeset
|
278 |
g_free(roster_usr); |
4e62941df777
roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents:
1058
diff
changeset
|
279 |
} |
4e62941df777
roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents:
1058
diff
changeset
|
280 |
|
72 | 281 |
// 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
|
282 |
static gint roster_compare_jid_type(roster *a, roster *b) { |
89 | 283 |
if (! (a->type & b->type)) |
480 | 284 |
return -1; // arbitrary (but should be != 0, of course) |
72 | 285 |
return strcasecmp(a->jid, b->jid); |
286 |
} |
|
287 |
||
670
2cd0805515a4
Fix a bug in roster_find()
Mikael Berthe <mikael@lilotux.net>
parents:
669
diff
changeset
|
288 |
// 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
|
289 |
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
|
290 |
if (! (a->type & b->type)) |
2cd0805515a4
Fix a bug in roster_find()
Mikael Berthe <mikael@lilotux.net>
parents:
669
diff
changeset
|
291 |
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
|
292 |
return strcmp(a->name, b->name); |
670
2cd0805515a4
Fix a bug in roster_find()
Mikael Berthe <mikael@lilotux.net>
parents:
669
diff
changeset
|
293 |
} |
2cd0805515a4
Fix a bug in roster_find()
Mikael Berthe <mikael@lilotux.net>
parents:
669
diff
changeset
|
294 |
|
72 | 295 |
// Comparison function used to sort the roster (by name) |
336
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
331
diff
changeset
|
296 |
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
|
297 |
return strcmp(a->name, b->name); |
72 | 298 |
} |
299 |
||
300 |
// Finds a roster element (user, group, agent...), by jid or name |
|
89 | 301 |
// If roster_type is 0, returns match of any type. |
72 | 302 |
// Returns the roster GSList element, or NULL if jid/name not found |
78 | 303 |
GSList *roster_find(const char *jidname, enum findwhat type, guint roster_type) |
72 | 304 |
{ |
305 |
GSList *sl_roster_elt = groups; |
|
1058 | 306 |
GSList *resource; |
72 | 307 |
roster sample; |
308 |
GCompareFunc comp; |
|
309 |
||
192 | 310 |
if (!jidname) return NULL; |
72 | 311 |
|
89 | 312 |
if (!roster_type) |
480 | 313 |
roster_type = ROSTER_TYPE_USER | ROSTER_TYPE_ROOM | |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
314 |
ROSTER_TYPE_AGENT | ROSTER_TYPE_GROUP; |
89 | 315 |
|
72 | 316 |
sample.type = roster_type; |
317 |
if (type == jidsearch) { |
|
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
318 |
sample.jid = (gchar*)jidname; |
72 | 319 |
comp = (GCompareFunc)&roster_compare_jid_type; |
320 |
} else if (type == namesearch) { |
|
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
321 |
sample.name = (gchar*)jidname; |
670
2cd0805515a4
Fix a bug in roster_find()
Mikael Berthe <mikael@lilotux.net>
parents:
669
diff
changeset
|
322 |
comp = (GCompareFunc)&roster_compare_name_type; |
72 | 323 |
} else |
885
afdd81c2c44d
Allow /rename for groups
Mikael Berthe <mikael@lilotux.net>
parents:
863
diff
changeset
|
324 |
return NULL; // Should not happen... |
72 | 325 |
|
326 |
while (sl_roster_elt) { |
|
327 |
roster *roster_elt = (roster*)sl_roster_elt->data; |
|
328 |
if (roster_type & ROSTER_TYPE_GROUP) { |
|
783
25022410f80f
Use case sensitive group names
Mikael Berthe <mikael@lilotux.net>
parents:
774
diff
changeset
|
329 |
if ((type == namesearch) && !strcmp(jidname, roster_elt->name)) |
72 | 330 |
return sl_roster_elt; |
331 |
} |
|
1058 | 332 |
resource = g_slist_find_custom(roster_elt->list, &sample, comp); |
333 |
if (resource) return resource; |
|
72 | 334 |
sl_roster_elt = g_slist_next(sl_roster_elt); |
335 |
} |
|
336 |
return NULL; |
|
337 |
} |
|
338 |
||
339 |
// Returns pointer to new group, or existing group with that name |
|
78 | 340 |
GSList *roster_add_group(const char *name) |
72 | 341 |
{ |
342 |
roster *roster_grp; |
|
669
2b87065270f3
roster_add_group(): do not call roster_find() twice
Mikael Berthe <mikael@lilotux.net>
parents:
662
diff
changeset
|
343 |
GSList *p_group; |
2b87065270f3
roster_add_group(): do not call roster_find() twice
Mikael Berthe <mikael@lilotux.net>
parents:
662
diff
changeset
|
344 |
|
72 | 345 |
// #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
|
346 |
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
|
347 |
if (!p_group) { |
72 | 348 |
// #2 Create the group node |
349 |
roster_grp = g_new0(roster, 1); |
|
350 |
roster_grp->name = g_strdup(name); |
|
351 |
roster_grp->type = ROSTER_TYPE_GROUP; |
|
352 |
// #3 Insert (sorted) |
|
353 |
groups = g_slist_insert_sorted(groups, roster_grp, |
|
354 |
(GCompareFunc)&roster_compare_name); |
|
669
2b87065270f3
roster_add_group(): do not call roster_find() twice
Mikael Berthe <mikael@lilotux.net>
parents:
662
diff
changeset
|
355 |
p_group = roster_find(name, namesearch, ROSTER_TYPE_GROUP); |
72 | 356 |
} |
669
2b87065270f3
roster_add_group(): do not call roster_find() twice
Mikael Berthe <mikael@lilotux.net>
parents:
662
diff
changeset
|
357 |
return p_group; |
72 | 358 |
} |
359 |
||
360 |
// Returns a pointer to the new user, or existing user with that name |
|
1355 | 361 |
// Note: if onserver is -1, the flag won't be changed. |
78 | 362 |
GSList *roster_add_user(const char *jid, const char *name, const char *group, |
1355 | 363 |
guint type, enum subscr esub, gint onserver) |
72 | 364 |
{ |
365 |
roster *roster_usr; |
|
366 |
roster *my_group; |
|
367 |
GSList *slist; |
|
368 |
||
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
369 |
if ((type != ROSTER_TYPE_USER) && |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
370 |
(type != ROSTER_TYPE_ROOM) && |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
371 |
(type != ROSTER_TYPE_AGENT)) { |
72 | 372 |
// XXX Error message? |
373 |
return NULL; |
|
374 |
} |
|
375 |
||
78 | 376 |
// Let's be arbitrary: default group has an empty name (""). |
377 |
if (!group) group = ""; |
|
378 |
||
72 | 379 |
// #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
|
380 |
slist = roster_find(jid, jidsearch, 0); |
607 | 381 |
if (slist) { |
382 |
char *oldgroupname; |
|
383 |
// That's an update |
|
384 |
roster_usr = slist->data; |
|
385 |
roster_usr->subscription = esub; |
|
1366
01e558748379
Fix a race in roster_add_user()
Mikael Berthe <mikael@lilotux.net>
parents:
1355
diff
changeset
|
386 |
if (onserver >= 0) |
01e558748379
Fix a race in roster_add_user()
Mikael Berthe <mikael@lilotux.net>
parents:
1355
diff
changeset
|
387 |
buddy_setonserverflag(slist->data, onserver); |
607 | 388 |
if (name) |
389 |
buddy_setname(slist->data, (char*)name); |
|
390 |
// Let's check if the group name has changed |
|
391 |
oldgroupname = ((roster*)((GSList*)roster_usr->list)->data)->name; |
|
1366
01e558748379
Fix a race in roster_add_user()
Mikael Berthe <mikael@lilotux.net>
parents:
1355
diff
changeset
|
392 |
if (group && strcmp(oldgroupname, group)) { |
607 | 393 |
buddy_setgroup(slist->data, (char*)group); |
1366
01e558748379
Fix a race in roster_add_user()
Mikael Berthe <mikael@lilotux.net>
parents:
1355
diff
changeset
|
394 |
// Note: buddy_setgroup() updates the user lists so we cannot |
01e558748379
Fix a race in roster_add_user()
Mikael Berthe <mikael@lilotux.net>
parents:
1355
diff
changeset
|
395 |
// use slist anymore. |
01e558748379
Fix a race in roster_add_user()
Mikael Berthe <mikael@lilotux.net>
parents:
1355
diff
changeset
|
396 |
return roster_find(jid, jidsearch, 0); |
01e558748379
Fix a race in roster_add_user()
Mikael Berthe <mikael@lilotux.net>
parents:
1355
diff
changeset
|
397 |
} |
607 | 398 |
return slist; |
399 |
} |
|
72 | 400 |
// #2 add group if necessary |
401 |
slist = roster_add_group(group); |
|
402 |
if (!slist) return NULL; |
|
403 |
my_group = (roster*)slist->data; |
|
404 |
// #3 Create user node |
|
405 |
roster_usr = g_new0(roster, 1); |
|
406 |
roster_usr->jid = g_strdup(jid); |
|
78 | 407 |
if (name) { |
408 |
roster_usr->name = g_strdup(name); |
|
409 |
} else { |
|
410 |
gchar *p, *str = g_strdup(jid); |
|
977
5b01de4ac5e1
Cosmetic changes
Alexis Hildebrandt <afh [at] 2drop [dot] net>
parents:
974
diff
changeset
|
411 |
p = strchr(str, JID_RESOURCE_SEPARATOR); |
78 | 412 |
if (p) *p = '\0'; |
413 |
roster_usr->name = g_strdup(str); |
|
414 |
g_free(str); |
|
415 |
} |
|
662
4111ff4cdd15
Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents:
652
diff
changeset
|
416 |
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
|
417 |
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
|
418 |
// 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
|
419 |
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
|
420 |
} |
603 | 421 |
roster_usr->type = type; |
422 |
roster_usr->subscription = esub; |
|
423 |
roster_usr->list = slist; // (my_group SList element) |
|
1355 | 424 |
if (onserver == 1) |
425 |
roster_usr->on_server = TRUE; |
|
72 | 426 |
// #4 Insert node (sorted) |
427 |
my_group->list = g_slist_insert_sorted(my_group->list, roster_usr, |
|
564 | 428 |
(GCompareFunc)&roster_compare_name); |
72 | 429 |
return roster_find(jid, jidsearch, type); |
430 |
} |
|
431 |
||
432 |
// Removes user (jid) from roster, frees allocated memory |
|
78 | 433 |
void roster_del_user(const char *jid) |
72 | 434 |
{ |
435 |
GSList *sl_user, *sl_group; |
|
436 |
GSList **sl_group_listptr; |
|
437 |
roster *roster_usr; |
|
246 | 438 |
GSList *node; |
72 | 439 |
|
1431
486809ccffc0
Let /del remove a MUC entry from the roster
Mikael Berthe <mikael@lilotux.net>
parents:
1414
diff
changeset
|
440 |
sl_user = roster_find(jid, jidsearch, |
486809ccffc0
Let /del remove a MUC entry from the roster
Mikael Berthe <mikael@lilotux.net>
parents:
1414
diff
changeset
|
441 |
ROSTER_TYPE_USER|ROSTER_TYPE_AGENT|ROSTER_TYPE_ROOM); |
89 | 442 |
if (sl_user == NULL) |
72 | 443 |
return; |
444 |
roster_usr = (roster*)sl_user->data; |
|
246 | 445 |
|
446 |
// Remove (if present) from unread messages list |
|
447 |
node = g_slist_find(unread_list, roster_usr); |
|
448 |
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
|
449 |
// 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
|
450 |
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
|
451 |
unread_jid_add(roster_usr->jid); |
246 | 452 |
|
1389
cefda9174d62
Fix an old bug in roster_del_user()
Mikael Berthe <mikael@lilotux.net>
parents:
1377
diff
changeset
|
453 |
sl_group = roster_usr->list; |
cefda9174d62
Fix an old bug in roster_del_user()
Mikael Berthe <mikael@lilotux.net>
parents:
1377
diff
changeset
|
454 |
|
1063
4e62941df777
roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents:
1058
diff
changeset
|
455 |
// Let's free roster_usr memory (jid, name, status message...) |
4e62941df777
roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents:
1058
diff
changeset
|
456 |
free_roster_user_data(roster_usr); |
72 | 457 |
|
458 |
// That's a little complex, we need to dereference twice |
|
459 |
sl_group_listptr = &((roster*)(sl_group->data))->list; |
|
460 |
*sl_group_listptr = g_slist_delete_link(*sl_group_listptr, sl_user); |
|
78 | 461 |
|
462 |
// We need to rebuild the list |
|
463 |
if (current_buddy) |
|
464 |
buddylist_build(); |
|
210 | 465 |
// TODO What we could do, too, is to check if the deleted node is |
78 | 466 |
// current_buddy, in which case we could move current_buddy to the |
467 |
// previous (or next) node. |
|
72 | 468 |
} |
469 |
||
210 | 470 |
// Free all roster data and call buddylist_build() to free the buddylist. |
164 | 471 |
void roster_free(void) |
472 |
{ |
|
473 |
GSList *sl_grp = groups; |
|
474 |
||
301
efcbd3c1ad15
Free unread_list when the roster is freed
Mikael Berthe <mikael@lilotux.net>
parents:
265
diff
changeset
|
475 |
// Free unread_list |
efcbd3c1ad15
Free unread_list when the roster is freed
Mikael Berthe <mikael@lilotux.net>
parents:
265
diff
changeset
|
476 |
if (unread_list) { |
efcbd3c1ad15
Free unread_list when the roster is freed
Mikael Berthe <mikael@lilotux.net>
parents:
265
diff
changeset
|
477 |
g_slist_free(unread_list); |
efcbd3c1ad15
Free unread_list when the roster is freed
Mikael Berthe <mikael@lilotux.net>
parents:
265
diff
changeset
|
478 |
unread_list = NULL; |
efcbd3c1ad15
Free unread_list when the roster is freed
Mikael Berthe <mikael@lilotux.net>
parents:
265
diff
changeset
|
479 |
} |
efcbd3c1ad15
Free unread_list when the roster is freed
Mikael Berthe <mikael@lilotux.net>
parents:
265
diff
changeset
|
480 |
|
164 | 481 |
// Walk through groups |
482 |
while (sl_grp) { |
|
483 |
roster *roster_grp = (roster*)sl_grp->data; |
|
484 |
GSList *sl_usr = roster_grp->list; |
|
485 |
// Walk through this group users |
|
486 |
while (sl_usr) { |
|
487 |
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
|
488 |
// 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
|
489 |
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
|
490 |
unread_jid_add(roster_usr->jid); |
1063
4e62941df777
roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents:
1058
diff
changeset
|
491 |
// Free roster_usr data (jid, name, status message...) |
4e62941df777
roster.c: refactor some functions
Mikael Berthe <mikael@lilotux.net>
parents:
1058
diff
changeset
|
492 |
free_roster_user_data(roster_usr); |
164 | 493 |
sl_usr = g_slist_next(sl_usr); |
494 |
} |
|
495 |
// Free group's users list |
|
496 |
if (roster_grp->list) |
|
497 |
g_slist_free(roster_grp->list); |
|
498 |
// Free group's name and jid |
|
774
46304b773a44
Remove useless checks before g_free() calls
Mikael Berthe <mikael@lilotux.net>
parents:
772
diff
changeset
|
499 |
g_free((gchar*)roster_grp->jid); |
46304b773a44
Remove useless checks before g_free() calls
Mikael Berthe <mikael@lilotux.net>
parents:
772
diff
changeset
|
500 |
g_free((gchar*)roster_grp->name); |
214 | 501 |
g_free(roster_grp); |
164 | 502 |
sl_grp = g_slist_next(sl_grp); |
503 |
} |
|
504 |
// Free groups list |
|
505 |
if (groups) { |
|
506 |
g_slist_free(groups); |
|
507 |
groups = NULL; |
|
508 |
// Update (i.e. free) buddylist |
|
509 |
if (buddylist) |
|
510 |
buddylist_build(); |
|
511 |
} |
|
512 |
} |
|
513 |
||
468
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
514 |
// roster_setstatus() |
572
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
515 |
// 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
|
516 |
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
|
517 |
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
|
518 |
time_t status_time, |
572
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
519 |
enum imrole role, enum imaffiliation affil, |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
520 |
const char *realjid) |
72 | 521 |
{ |
522 |
GSList *sl_user; |
|
523 |
roster *roster_usr; |
|
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
524 |
res *p_res; |
72 | 525 |
|
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
526 |
sl_user = roster_find(jid, jidsearch, |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
527 |
ROSTER_TYPE_USER|ROSTER_TYPE_ROOM|ROSTER_TYPE_AGENT); |
92 | 528 |
// If we can't find it, we add it |
89 | 529 |
if (sl_user == NULL) |
1355 | 530 |
sl_user = roster_add_user(jid, NULL, NULL, ROSTER_TYPE_USER, |
531 |
sub_none, -1); |
|
72 | 532 |
|
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
533 |
// 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
|
534 |
if (!resname) return; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
535 |
|
72 | 536 |
roster_usr = (roster*)sl_user->data; |
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
537 |
|
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
538 |
// New or updated resource |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
539 |
p_res = get_or_add_resource(roster_usr, resname, prio); |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
540 |
p_res->status = bstat; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
541 |
if (p_res->status_msg) { |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
542 |
g_free((gchar*)p_res->status_msg); |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
543 |
p_res->status_msg = NULL; |
221 | 544 |
} |
545 |
if (status_msg) |
|
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
546 |
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
|
547 |
if (!status_time) |
028c01940490
Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
621
diff
changeset
|
548 |
time(&status_time); |
028c01940490
Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
621
diff
changeset
|
549 |
p_res->status_timestamp = status_time; |
468
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
550 |
|
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
551 |
p_res->role = role; |
572
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
552 |
p_res->affil = affil; |
468
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
553 |
|
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
554 |
if (p_res->realjid) { |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
555 |
g_free((gchar*)p_res->realjid); |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
556 |
p_res->realjid = NULL; |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
557 |
} |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
558 |
if (realjid) |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
559 |
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
|
560 |
|
915a7f17474a
Remember the status message when a buddy goes offline
Mikael Berthe <mikael@lilotux.net>
parents:
819
diff
changeset
|
561 |
// 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
|
562 |
if (bstat == offline) { |
915a7f17474a
Remember the status message when a buddy goes offline
Mikael Berthe <mikael@lilotux.net>
parents:
819
diff
changeset
|
563 |
del_resource(roster_usr, resname); |
915a7f17474a
Remember the status message when a buddy goes offline
Mikael Berthe <mikael@lilotux.net>
parents:
819
diff
changeset
|
564 |
return; |
915a7f17474a
Remember the status message when a buddy goes offline
Mikael Berthe <mikael@lilotux.net>
parents:
819
diff
changeset
|
565 |
} |
72 | 566 |
} |
567 |
||
78 | 568 |
// roster_setflags() |
569 |
// Set one or several flags to value (TRUE/FALSE) |
|
80 | 570 |
void roster_setflags(const char *jid, guint flags, guint value) |
78 | 571 |
{ |
572 |
GSList *sl_user; |
|
573 |
roster *roster_usr; |
|
574 |
||
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
575 |
sl_user = roster_find(jid, jidsearch, |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
576 |
ROSTER_TYPE_USER|ROSTER_TYPE_ROOM|ROSTER_TYPE_AGENT); |
89 | 577 |
if (sl_user == NULL) |
78 | 578 |
return; |
579 |
||
580 |
roster_usr = (roster*)sl_user->data; |
|
581 |
if (value) |
|
582 |
roster_usr->flags |= flags; |
|
583 |
else |
|
584 |
roster_usr->flags &= ~flags; |
|
585 |
} |
|
148 | 586 |
|
587 |
// roster_msg_setflag() |
|
588 |
// Set the ROSTER_FLAG_MSG to the given value for the given jid. |
|
589 |
// It will update the buddy's group message flag. |
|
236 | 590 |
// Update the unread messages list too. |
889
ae93e69aaaaf
Fix up pending message flag for the status special buffer
Mikael Berthe <mikael@lilotux.net>
parents:
885
diff
changeset
|
591 |
void roster_msg_setflag(const char *jid, guint special, guint value) |
148 | 592 |
{ |
593 |
GSList *sl_user; |
|
594 |
roster *roster_usr, *roster_grp; |
|
860
a8fadbd97858
Rebuild buddylist when setting a new message flag
Mikael Berthe <mikael@lilotux.net>
parents:
848
diff
changeset
|
595 |
int new_roster_item = FALSE; |
1437
071c8170b7de
Add option 'statefile' to keep track of unread messages across restarts
Mikael Berthe <mikael@lilotux.net>
parents:
1431
diff
changeset
|
596 |
guint unread_list_modified = FALSE; |
148 | 597 |
|
889
ae93e69aaaaf
Fix up pending message flag for the status special buffer
Mikael Berthe <mikael@lilotux.net>
parents:
885
diff
changeset
|
598 |
if (special) { |
ae93e69aaaaf
Fix up pending message flag for the status special buffer
Mikael Berthe <mikael@lilotux.net>
parents:
885
diff
changeset
|
599 |
//sl_user = roster_find(jid, namesearch, ROSTER_TYPE_SPECIAL); |
ae93e69aaaaf
Fix up pending message flag for the status special buffer
Mikael Berthe <mikael@lilotux.net>
parents:
885
diff
changeset
|
600 |
//if (!sl_user) return; |
ae93e69aaaaf
Fix up pending message flag for the status special buffer
Mikael Berthe <mikael@lilotux.net>
parents:
885
diff
changeset
|
601 |
//roster_usr = (roster*)sl_user->data; |
ae93e69aaaaf
Fix up pending message flag for the status special buffer
Mikael Berthe <mikael@lilotux.net>
parents:
885
diff
changeset
|
602 |
roster_usr = &roster_special; |
ae93e69aaaaf
Fix up pending message flag for the status special buffer
Mikael Berthe <mikael@lilotux.net>
parents:
885
diff
changeset
|
603 |
if (value) { |
1581
b29ac1f171ea
Fix UNREAD event when a special buffer changes
Mikael Berthe <mikael@lilotux.net>
parents:
1504
diff
changeset
|
604 |
if (!(roster_usr->flags & ROSTER_FLAG_MSG)) |
b29ac1f171ea
Fix UNREAD event when a special buffer changes
Mikael Berthe <mikael@lilotux.net>
parents:
1504
diff
changeset
|
605 |
unread_list_modified = TRUE; |
889
ae93e69aaaaf
Fix up pending message flag for the status special buffer
Mikael Berthe <mikael@lilotux.net>
parents:
885
diff
changeset
|
606 |
roster_usr->flags |= ROSTER_FLAG_MSG; |
ae93e69aaaaf
Fix up pending message flag for the status special buffer
Mikael Berthe <mikael@lilotux.net>
parents:
885
diff
changeset
|
607 |
// Append the roster_usr to unread_list, but avoid duplicates |
ae93e69aaaaf
Fix up pending message flag for the status special buffer
Mikael Berthe <mikael@lilotux.net>
parents:
885
diff
changeset
|
608 |
if (!g_slist_find(unread_list, roster_usr)) |
ae93e69aaaaf
Fix up pending message flag for the status special buffer
Mikael Berthe <mikael@lilotux.net>
parents:
885
diff
changeset
|
609 |
unread_list = g_slist_append(unread_list, roster_usr); |
ae93e69aaaaf
Fix up pending message flag for the status special buffer
Mikael Berthe <mikael@lilotux.net>
parents:
885
diff
changeset
|
610 |
} else { |
1581
b29ac1f171ea
Fix UNREAD event when a special buffer changes
Mikael Berthe <mikael@lilotux.net>
parents:
1504
diff
changeset
|
611 |
if (roster_usr->flags & ROSTER_FLAG_MSG) |
b29ac1f171ea
Fix UNREAD event when a special buffer changes
Mikael Berthe <mikael@lilotux.net>
parents:
1504
diff
changeset
|
612 |
unread_list_modified = TRUE; |
889
ae93e69aaaaf
Fix up pending message flag for the status special buffer
Mikael Berthe <mikael@lilotux.net>
parents:
885
diff
changeset
|
613 |
roster_usr->flags &= ~ROSTER_FLAG_MSG; |
ae93e69aaaaf
Fix up pending message flag for the status special buffer
Mikael Berthe <mikael@lilotux.net>
parents:
885
diff
changeset
|
614 |
if (unread_list) { |
ae93e69aaaaf
Fix up pending message flag for the status special buffer
Mikael Berthe <mikael@lilotux.net>
parents:
885
diff
changeset
|
615 |
GSList *node = g_slist_find(unread_list, roster_usr); |
1581
b29ac1f171ea
Fix UNREAD event when a special buffer changes
Mikael Berthe <mikael@lilotux.net>
parents:
1504
diff
changeset
|
616 |
if (node) |
b29ac1f171ea
Fix UNREAD event when a special buffer changes
Mikael Berthe <mikael@lilotux.net>
parents:
1504
diff
changeset
|
617 |
unread_list = g_slist_delete_link(unread_list, node); |
889
ae93e69aaaaf
Fix up pending message flag for the status special buffer
Mikael Berthe <mikael@lilotux.net>
parents:
885
diff
changeset
|
618 |
} |
ae93e69aaaaf
Fix up pending message flag for the status special buffer
Mikael Berthe <mikael@lilotux.net>
parents:
885
diff
changeset
|
619 |
} |
1581
b29ac1f171ea
Fix UNREAD event when a special buffer changes
Mikael Berthe <mikael@lilotux.net>
parents:
1504
diff
changeset
|
620 |
goto roster_msg_setflag_return; |
889
ae93e69aaaaf
Fix up pending message flag for the status special buffer
Mikael Berthe <mikael@lilotux.net>
parents:
885
diff
changeset
|
621 |
} |
ae93e69aaaaf
Fix up pending message flag for the status special buffer
Mikael Berthe <mikael@lilotux.net>
parents:
885
diff
changeset
|
622 |
|
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
623 |
sl_user = roster_find(jid, jidsearch, |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
624 |
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
|
625 |
// 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
|
626 |
if (sl_user == NULL) { |
1355 | 627 |
sl_user = roster_add_user(jid, NULL, NULL, ROSTER_TYPE_USER, sub_none, -1); |
860
a8fadbd97858
Rebuild buddylist when setting a new message flag
Mikael Berthe <mikael@lilotux.net>
parents:
848
diff
changeset
|
628 |
new_roster_item = TRUE; |
678
e175f5d96f04
Fix a small issue in roster_msg_setflag()
Mikael Berthe <mikael@lilotux.net>
parents:
670
diff
changeset
|
629 |
} |
148 | 630 |
|
631 |
roster_usr = (roster*)sl_user->data; |
|
632 |
roster_grp = (roster*)roster_usr->list->data; |
|
633 |
if (value) { |
|
1437
071c8170b7de
Add option 'statefile' to keep track of unread messages across restarts
Mikael Berthe <mikael@lilotux.net>
parents:
1431
diff
changeset
|
634 |
if (!(roster_usr->flags & ROSTER_FLAG_MSG)) |
071c8170b7de
Add option 'statefile' to keep track of unread messages across restarts
Mikael Berthe <mikael@lilotux.net>
parents:
1431
diff
changeset
|
635 |
unread_list_modified = TRUE; |
148 | 636 |
// Message flag is TRUE. This is easy, we just have to set both flags |
637 |
// to TRUE... |
|
638 |
roster_usr->flags |= ROSTER_FLAG_MSG; |
|
639 |
roster_grp->flags |= ROSTER_FLAG_MSG; // group |
|
236 | 640 |
// Append the roster_usr to unread_list, but avoid duplicates |
641 |
if (!g_slist_find(unread_list, roster_usr)) |
|
642 |
unread_list = g_slist_append(unread_list, roster_usr); |
|
148 | 643 |
} else { |
644 |
// Message flag is FALSE. |
|
645 |
guint msg = FALSE; |
|
1437
071c8170b7de
Add option 'statefile' to keep track of unread messages across restarts
Mikael Berthe <mikael@lilotux.net>
parents:
1431
diff
changeset
|
646 |
if (roster_usr->flags & ROSTER_FLAG_MSG) |
071c8170b7de
Add option 'statefile' to keep track of unread messages across restarts
Mikael Berthe <mikael@lilotux.net>
parents:
1431
diff
changeset
|
647 |
unread_list_modified = TRUE; |
148 | 648 |
roster_usr->flags &= ~ROSTER_FLAG_MSG; |
236 | 649 |
if (unread_list) { |
650 |
GSList *node = g_slist_find(unread_list, roster_usr); |
|
1581
b29ac1f171ea
Fix UNREAD event when a special buffer changes
Mikael Berthe <mikael@lilotux.net>
parents:
1504
diff
changeset
|
651 |
if (node) |
b29ac1f171ea
Fix UNREAD event when a special buffer changes
Mikael Berthe <mikael@lilotux.net>
parents:
1504
diff
changeset
|
652 |
unread_list = g_slist_delete_link(unread_list, node); |
236 | 653 |
} |
148 | 654 |
// For the group value we need to watch all buddies in this group; |
655 |
// if one is flagged, then the group will be flagged. |
|
656 |
// I will re-use sl_user and roster_usr here, as they aren't used |
|
657 |
// anymore. |
|
658 |
sl_user = roster_grp->list; |
|
659 |
while (sl_user) { |
|
660 |
roster_usr = (roster*)sl_user->data; |
|
661 |
if (roster_usr->flags & ROSTER_FLAG_MSG) { |
|
662 |
msg = TRUE; |
|
663 |
break; |
|
664 |
} |
|
665 |
sl_user = g_slist_next(sl_user); |
|
666 |
} |
|
667 |
if (!msg) |
|
668 |
roster_grp->flags &= ~ROSTER_FLAG_MSG; |
|
669 |
else |
|
670 |
roster_grp->flags |= ROSTER_FLAG_MSG; |
|
671 |
// Actually the "else" part is useless, because the group |
|
672 |
// ROSTER_FLAG_MSG should already be set... |
|
673 |
} |
|
860
a8fadbd97858
Rebuild buddylist when setting a new message flag
Mikael Berthe <mikael@lilotux.net>
parents:
848
diff
changeset
|
674 |
|
1010
54405d09b15a
Add a call to buddylist_build()
Mikael Berthe <mikael@lilotux.net>
parents:
987
diff
changeset
|
675 |
if (buddylist && (new_roster_item || !g_list_find(buddylist, roster_usr))) |
860
a8fadbd97858
Rebuild buddylist when setting a new message flag
Mikael Berthe <mikael@lilotux.net>
parents:
848
diff
changeset
|
676 |
buddylist_build(); |
1437
071c8170b7de
Add option 'statefile' to keep track of unread messages across restarts
Mikael Berthe <mikael@lilotux.net>
parents:
1431
diff
changeset
|
677 |
|
1581
b29ac1f171ea
Fix UNREAD event when a special buffer changes
Mikael Berthe <mikael@lilotux.net>
parents:
1504
diff
changeset
|
678 |
roster_msg_setflag_return: |
1444
3bf11085c6a5
New external "UNREAD" event (suggested by Viacheslav Chumushuk)
Mikael Berthe <mikael@lilotux.net>
parents:
1438
diff
changeset
|
679 |
if (unread_list_modified) { |
1476
77afd831f8f7
Avoid mixed declarations and code
Mikael Berthe <mikael@lilotux.net>
parents:
1475
diff
changeset
|
680 |
guint unread_count = g_slist_length(unread_list); |
1437
071c8170b7de
Add option 'statefile' to keep track of unread messages across restarts
Mikael Berthe <mikael@lilotux.net>
parents:
1431
diff
changeset
|
681 |
hlog_save_state(); |
1444
3bf11085c6a5
New external "UNREAD" event (suggested by Viacheslav Chumushuk)
Mikael Berthe <mikael@lilotux.net>
parents:
1438
diff
changeset
|
682 |
/* Call external command */ |
3bf11085c6a5
New external "UNREAD" event (suggested by Viacheslav Chumushuk)
Mikael Berthe <mikael@lilotux.net>
parents:
1438
diff
changeset
|
683 |
hk_ext_cmd("", 'U', (guchar)MIN(255, unread_count), NULL); |
3bf11085c6a5
New external "UNREAD" event (suggested by Viacheslav Chumushuk)
Mikael Berthe <mikael@lilotux.net>
parents:
1438
diff
changeset
|
684 |
} |
148 | 685 |
} |
686 |
||
510
6c3cd3aa4a91
New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents:
509
diff
changeset
|
687 |
const char *roster_getname(const char *jid) |
6c3cd3aa4a91
New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents:
509
diff
changeset
|
688 |
{ |
6c3cd3aa4a91
New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents:
509
diff
changeset
|
689 |
GSList *sl_user; |
6c3cd3aa4a91
New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents:
509
diff
changeset
|
690 |
roster *roster_usr; |
6c3cd3aa4a91
New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents:
509
diff
changeset
|
691 |
|
6c3cd3aa4a91
New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents:
509
diff
changeset
|
692 |
sl_user = roster_find(jid, jidsearch, |
6c3cd3aa4a91
New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents:
509
diff
changeset
|
693 |
ROSTER_TYPE_USER|ROSTER_TYPE_ROOM|ROSTER_TYPE_AGENT); |
6c3cd3aa4a91
New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents:
509
diff
changeset
|
694 |
if (sl_user == NULL) |
6c3cd3aa4a91
New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents:
509
diff
changeset
|
695 |
return NULL; // Not in the roster... |
6c3cd3aa4a91
New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents:
509
diff
changeset
|
696 |
|
6c3cd3aa4a91
New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents:
509
diff
changeset
|
697 |
roster_usr = (roster*)sl_user->data; |
6c3cd3aa4a91
New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents:
509
diff
changeset
|
698 |
return roster_usr->name; |
6c3cd3aa4a91
New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents:
509
diff
changeset
|
699 |
} |
6c3cd3aa4a91
New 'buddy_format' option
Mikael Berthe <mikael@lilotux.net>
parents:
509
diff
changeset
|
700 |
|
863
4f1a93faffea
Add roster_getnickname()
Mikael Berthe <mikael@lilotux.net>
parents:
860
diff
changeset
|
701 |
const char *roster_getnickname(const char *jid) |
4f1a93faffea
Add roster_getnickname()
Mikael Berthe <mikael@lilotux.net>
parents:
860
diff
changeset
|
702 |
{ |
4f1a93faffea
Add roster_getnickname()
Mikael Berthe <mikael@lilotux.net>
parents:
860
diff
changeset
|
703 |
GSList *sl_user; |
4f1a93faffea
Add roster_getnickname()
Mikael Berthe <mikael@lilotux.net>
parents:
860
diff
changeset
|
704 |
roster *roster_usr; |
4f1a93faffea
Add roster_getnickname()
Mikael Berthe <mikael@lilotux.net>
parents:
860
diff
changeset
|
705 |
|
4f1a93faffea
Add roster_getnickname()
Mikael Berthe <mikael@lilotux.net>
parents:
860
diff
changeset
|
706 |
sl_user = roster_find(jid, jidsearch, |
4f1a93faffea
Add roster_getnickname()
Mikael Berthe <mikael@lilotux.net>
parents:
860
diff
changeset
|
707 |
ROSTER_TYPE_USER|ROSTER_TYPE_ROOM|ROSTER_TYPE_AGENT); |
4f1a93faffea
Add roster_getnickname()
Mikael Berthe <mikael@lilotux.net>
parents:
860
diff
changeset
|
708 |
if (sl_user == NULL) |
4f1a93faffea
Add roster_getnickname()
Mikael Berthe <mikael@lilotux.net>
parents:
860
diff
changeset
|
709 |
return NULL; // Not in the roster... |
4f1a93faffea
Add roster_getnickname()
Mikael Berthe <mikael@lilotux.net>
parents:
860
diff
changeset
|
710 |
|
4f1a93faffea
Add roster_getnickname()
Mikael Berthe <mikael@lilotux.net>
parents:
860
diff
changeset
|
711 |
roster_usr = (roster*)sl_user->data; |
4f1a93faffea
Add roster_getnickname()
Mikael Berthe <mikael@lilotux.net>
parents:
860
diff
changeset
|
712 |
return roster_usr->nickname; |
4f1a93faffea
Add roster_getnickname()
Mikael Berthe <mikael@lilotux.net>
parents:
860
diff
changeset
|
713 |
} |
4f1a93faffea
Add roster_getnickname()
Mikael Berthe <mikael@lilotux.net>
parents:
860
diff
changeset
|
714 |
|
89 | 715 |
void roster_settype(const char *jid, guint type) |
716 |
{ |
|
717 |
GSList *sl_user; |
|
718 |
roster *roster_usr; |
|
719 |
||
720 |
if ((sl_user = roster_find(jid, jidsearch, 0)) == NULL) |
|
721 |
return; |
|
722 |
||
723 |
roster_usr = (roster*)sl_user->data; |
|
724 |
roster_usr->type = type; |
|
725 |
} |
|
726 |
||
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
727 |
enum imstatus roster_getstatus(const char *jid, const char *resname) |
90 | 728 |
{ |
729 |
GSList *sl_user; |
|
730 |
roster *roster_usr; |
|
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
731 |
res *p_res; |
90 | 732 |
|
733 |
sl_user = roster_find(jid, jidsearch, ROSTER_TYPE_USER|ROSTER_TYPE_AGENT); |
|
734 |
if (sl_user == NULL) |
|
735 |
return offline; // Not in the roster, anyway... |
|
736 |
||
737 |
roster_usr = (roster*)sl_user->data; |
|
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
738 |
p_res = get_resource(roster_usr, resname); |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
739 |
if (p_res) |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
740 |
return p_res->status; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
741 |
return offline; |
90 | 742 |
} |
743 |
||
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
744 |
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
|
745 |
{ |
45076d02eeef
The /status command can specify a status message
Mikael Berthe <mikael@lilotux.net>
parents:
301
diff
changeset
|
746 |
GSList *sl_user; |
45076d02eeef
The /status command can specify a status message
Mikael Berthe <mikael@lilotux.net>
parents:
301
diff
changeset
|
747 |
roster *roster_usr; |
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
748 |
res *p_res; |
318
45076d02eeef
The /status command can specify a status message
Mikael Berthe <mikael@lilotux.net>
parents:
301
diff
changeset
|
749 |
|
45076d02eeef
The /status command can specify a status message
Mikael Berthe <mikael@lilotux.net>
parents:
301
diff
changeset
|
750 |
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
|
751 |
if (sl_user == NULL) |
425
03f1e37759a6
roster_getstatusmsg() should return a pointer
Mikael Berthe <mikael@lilotux.net>
parents:
393
diff
changeset
|
752 |
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
|
753 |
|
45076d02eeef
The /status command can specify a status message
Mikael Berthe <mikael@lilotux.net>
parents:
301
diff
changeset
|
754 |
roster_usr = (roster*)sl_user->data; |
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
755 |
p_res = get_resource(roster_usr, resname); |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
756 |
if (p_res) |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
757 |
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
|
758 |
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
|
759 |
} |
45076d02eeef
The /status command can specify a status message
Mikael Berthe <mikael@lilotux.net>
parents:
301
diff
changeset
|
760 |
|
89 | 761 |
guint roster_gettype(const char *jid) |
762 |
{ |
|
763 |
GSList *sl_user; |
|
764 |
roster *roster_usr; |
|
765 |
||
766 |
if ((sl_user = roster_find(jid, jidsearch, 0)) == NULL) |
|
767 |
return 0; |
|
768 |
||
769 |
roster_usr = (roster*)sl_user->data; |
|
770 |
return roster_usr->type; |
|
771 |
} |
|
772 |
||
819
c2d7d9dd4193
New option 'block_unsubscribed'
Mikael Berthe <mikael@lilotux.net>
parents:
792
diff
changeset
|
773 |
guint roster_getsubscription(const char *jid) |
c2d7d9dd4193
New option 'block_unsubscribed'
Mikael Berthe <mikael@lilotux.net>
parents:
792
diff
changeset
|
774 |
{ |
c2d7d9dd4193
New option 'block_unsubscribed'
Mikael Berthe <mikael@lilotux.net>
parents:
792
diff
changeset
|
775 |
GSList *sl_user; |
c2d7d9dd4193
New option 'block_unsubscribed'
Mikael Berthe <mikael@lilotux.net>
parents:
792
diff
changeset
|
776 |
roster *roster_usr; |
c2d7d9dd4193
New option 'block_unsubscribed'
Mikael Berthe <mikael@lilotux.net>
parents:
792
diff
changeset
|
777 |
|
c2d7d9dd4193
New option 'block_unsubscribed'
Mikael Berthe <mikael@lilotux.net>
parents:
792
diff
changeset
|
778 |
if ((sl_user = roster_find(jid, jidsearch, 0)) == NULL) |
c2d7d9dd4193
New option 'block_unsubscribed'
Mikael Berthe <mikael@lilotux.net>
parents:
792
diff
changeset
|
779 |
return 0; |
c2d7d9dd4193
New option 'block_unsubscribed'
Mikael Berthe <mikael@lilotux.net>
parents:
792
diff
changeset
|
780 |
|
c2d7d9dd4193
New option 'block_unsubscribed'
Mikael Berthe <mikael@lilotux.net>
parents:
792
diff
changeset
|
781 |
roster_usr = (roster*)sl_user->data; |
c2d7d9dd4193
New option 'block_unsubscribed'
Mikael Berthe <mikael@lilotux.net>
parents:
792
diff
changeset
|
782 |
return roster_usr->subscription; |
c2d7d9dd4193
New option 'block_unsubscribed'
Mikael Berthe <mikael@lilotux.net>
parents:
792
diff
changeset
|
783 |
} |
c2d7d9dd4193
New option 'block_unsubscribed'
Mikael Berthe <mikael@lilotux.net>
parents:
792
diff
changeset
|
784 |
|
610
0e8247cf2bd1
Consider buddies as offline when they have cancelled our subscription
Mikael Berthe <mikael@lilotux.net>
parents:
607
diff
changeset
|
785 |
// roster_unsubscribed() |
0e8247cf2bd1
Consider buddies as offline when they have cancelled our subscription
Mikael Berthe <mikael@lilotux.net>
parents:
607
diff
changeset
|
786 |
// 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
|
787 |
// 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
|
788 |
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
|
789 |
{ |
0e8247cf2bd1
Consider buddies as offline when they have cancelled our subscription
Mikael Berthe <mikael@lilotux.net>
parents:
607
diff
changeset
|
790 |
GSList *sl_user; |
0e8247cf2bd1
Consider buddies as offline when they have cancelled our subscription
Mikael Berthe <mikael@lilotux.net>
parents:
607
diff
changeset
|
791 |
roster *roster_usr; |
0e8247cf2bd1
Consider buddies as offline when they have cancelled our subscription
Mikael Berthe <mikael@lilotux.net>
parents:
607
diff
changeset
|
792 |
|
0e8247cf2bd1
Consider buddies as offline when they have cancelled our subscription
Mikael Berthe <mikael@lilotux.net>
parents:
607
diff
changeset
|
793 |
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
|
794 |
if (sl_user == NULL) |
0e8247cf2bd1
Consider buddies as offline when they have cancelled our subscription
Mikael Berthe <mikael@lilotux.net>
parents:
607
diff
changeset
|
795 |
return; |
0e8247cf2bd1
Consider buddies as offline when they have cancelled our subscription
Mikael Berthe <mikael@lilotux.net>
parents:
607
diff
changeset
|
796 |
|
0e8247cf2bd1
Consider buddies as offline when they have cancelled our subscription
Mikael Berthe <mikael@lilotux.net>
parents:
607
diff
changeset
|
797 |
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
|
798 |
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
|
799 |
} |
0e8247cf2bd1
Consider buddies as offline when they have cancelled our subscription
Mikael Berthe <mikael@lilotux.net>
parents:
607
diff
changeset
|
800 |
|
72 | 801 |
|
802 |
/* ### BuddyList functions ### */ |
|
803 |
||
120 | 804 |
// buddylist_set_hide_offline_buddies(hide) |
72 | 805 |
// "hide" values: 1=hide 0=show_all -1=invert |
120 | 806 |
void buddylist_set_hide_offline_buddies(int hide) |
72 | 807 |
{ |
1311
0dda8238af21
Implement "/roster display"
Mikael Berthe <mikael@lilotux.net>
parents:
1292
diff
changeset
|
808 |
if (hide < 0) { // NEG (invert) |
0dda8238af21
Implement "/roster display"
Mikael Berthe <mikael@lilotux.net>
parents:
1292
diff
changeset
|
809 |
if (display_filter == DFILTER_ALL) |
0dda8238af21
Implement "/roster display"
Mikael Berthe <mikael@lilotux.net>
parents:
1292
diff
changeset
|
810 |
display_filter = DFILTER_ONLINE; |
0dda8238af21
Implement "/roster display"
Mikael Berthe <mikael@lilotux.net>
parents:
1292
diff
changeset
|
811 |
else |
0dda8238af21
Implement "/roster display"
Mikael Berthe <mikael@lilotux.net>
parents:
1292
diff
changeset
|
812 |
display_filter = DFILTER_ALL; |
0dda8238af21
Implement "/roster display"
Mikael Berthe <mikael@lilotux.net>
parents:
1292
diff
changeset
|
813 |
} else if (hide == 0) { // FALSE (don't hide -- andfo_) |
0dda8238af21
Implement "/roster display"
Mikael Berthe <mikael@lilotux.net>
parents:
1292
diff
changeset
|
814 |
display_filter = DFILTER_ALL; |
0dda8238af21
Implement "/roster display"
Mikael Berthe <mikael@lilotux.net>
parents:
1292
diff
changeset
|
815 |
} else { // TRUE (hide -- andfo) |
0dda8238af21
Implement "/roster display"
Mikael Berthe <mikael@lilotux.net>
parents:
1292
diff
changeset
|
816 |
display_filter = DFILTER_ONLINE; |
0dda8238af21
Implement "/roster display"
Mikael Berthe <mikael@lilotux.net>
parents:
1292
diff
changeset
|
817 |
} |
72 | 818 |
} |
819 |
||
1413 | 820 |
int buddylist_isset_filter(void) |
1311
0dda8238af21
Implement "/roster display"
Mikael Berthe <mikael@lilotux.net>
parents:
1292
diff
changeset
|
821 |
{ |
0dda8238af21
Implement "/roster display"
Mikael Berthe <mikael@lilotux.net>
parents:
1292
diff
changeset
|
822 |
return (display_filter != DFILTER_ALL); |
0dda8238af21
Implement "/roster display"
Mikael Berthe <mikael@lilotux.net>
parents:
1292
diff
changeset
|
823 |
} |
0dda8238af21
Implement "/roster display"
Mikael Berthe <mikael@lilotux.net>
parents:
1292
diff
changeset
|
824 |
|
1504
9fafea381eb8
Show the number of unfiltered contacts in folded groups
franky
parents:
1476
diff
changeset
|
825 |
int buddylist_is_status_filtered(enum imstatus status) |
9fafea381eb8
Show the number of unfiltered contacts in folded groups
franky
parents:
1476
diff
changeset
|
826 |
{ |
9fafea381eb8
Show the number of unfiltered contacts in folded groups
franky
parents:
1476
diff
changeset
|
827 |
return display_filter & (1 << status); |
9fafea381eb8
Show the number of unfiltered contacts in folded groups
franky
parents:
1476
diff
changeset
|
828 |
} |
9fafea381eb8
Show the number of unfiltered contacts in folded groups
franky
parents:
1476
diff
changeset
|
829 |
|
1311
0dda8238af21
Implement "/roster display"
Mikael Berthe <mikael@lilotux.net>
parents:
1292
diff
changeset
|
830 |
void buddylist_set_filter(guchar filter) |
120 | 831 |
{ |
1311
0dda8238af21
Implement "/roster display"
Mikael Berthe <mikael@lilotux.net>
parents:
1292
diff
changeset
|
832 |
display_filter = filter; |
0dda8238af21
Implement "/roster display"
Mikael Berthe <mikael@lilotux.net>
parents:
1292
diff
changeset
|
833 |
} |
0dda8238af21
Implement "/roster display"
Mikael Berthe <mikael@lilotux.net>
parents:
1292
diff
changeset
|
834 |
|
0dda8238af21
Implement "/roster display"
Mikael Berthe <mikael@lilotux.net>
parents:
1292
diff
changeset
|
835 |
guchar buddylist_get_filter(void) |
0dda8238af21
Implement "/roster display"
Mikael Berthe <mikael@lilotux.net>
parents:
1292
diff
changeset
|
836 |
{ |
0dda8238af21
Implement "/roster display"
Mikael Berthe <mikael@lilotux.net>
parents:
1292
diff
changeset
|
837 |
return display_filter; |
120 | 838 |
} |
839 |
||
72 | 840 |
// buddylist_build() |
841 |
// Creates the buddylist from the roster entries. |
|
842 |
void buddylist_build(void) |
|
843 |
{ |
|
844 |
GSList *sl_roster_elt = groups; |
|
845 |
roster *roster_elt; |
|
81 | 846 |
roster *roster_current_buddy = NULL; |
330 | 847 |
roster *roster_alternate_buddy = NULL; |
128 | 848 |
int shrunk_group; |
72 | 849 |
|
81 | 850 |
// We need to remember which buddy is selected. |
851 |
if (current_buddy) |
|
852 |
roster_current_buddy = BUDDATA(current_buddy); |
|
853 |
current_buddy = NULL; |
|
330 | 854 |
if (alternate_buddy) |
855 |
roster_alternate_buddy = BUDDATA(alternate_buddy); |
|
856 |
alternate_buddy = NULL; |
|
81 | 857 |
|
72 | 858 |
// Destroy old buddylist |
859 |
if (buddylist) { |
|
860 |
g_list_free(buddylist); |
|
861 |
buddylist = NULL; |
|
862 |
} |
|
863 |
||
848
a9161d2dc414
Introduce special buffer stuff
Mikael Berthe <mikael@lilotux.net>
parents:
843
diff
changeset
|
864 |
buddylist = g_list_append(buddylist, &roster_special); |
a9161d2dc414
Introduce special buffer stuff
Mikael Berthe <mikael@lilotux.net>
parents:
843
diff
changeset
|
865 |
|
72 | 866 |
// Create the new list |
867 |
while (sl_roster_elt) { |
|
868 |
GSList *sl_roster_usrelt; |
|
869 |
roster *roster_usrelt; |
|
1311
0dda8238af21
Implement "/roster display"
Mikael Berthe <mikael@lilotux.net>
parents:
1292
diff
changeset
|
870 |
guint pending_group = TRUE; |
72 | 871 |
roster_elt = (roster*) sl_roster_elt->data; |
872 |
||
128 | 873 |
shrunk_group = roster_elt->flags & ROSTER_FLAG_HIDE; |
874 |
||
72 | 875 |
sl_roster_usrelt = roster_elt->list; |
876 |
while (sl_roster_usrelt) { |
|
877 |
roster_usrelt = (roster*) sl_roster_usrelt->data; |
|
878 |
||
879 |
// Buddy will be added if either: |
|
1311
0dda8238af21
Implement "/roster display"
Mikael Berthe <mikael@lilotux.net>
parents:
1292
diff
changeset
|
880 |
// - buddy's status matches the display_filter |
72 | 881 |
// - buddy has a lock (for example the buddy window is currently open) |
882 |
// - buddy has a pending (non-read) message |
|
128 | 883 |
// - group isn't hidden (shrunk) |
147 | 884 |
// - this is the current_buddy |
1311
0dda8238af21
Implement "/roster display"
Mikael Berthe <mikael@lilotux.net>
parents:
1292
diff
changeset
|
885 |
if (roster_usrelt == roster_current_buddy || |
1504
9fafea381eb8
Show the number of unfiltered contacts in folded groups
franky
parents:
1476
diff
changeset
|
886 |
buddylist_is_status_filtered(buddy_getstatus((gpointer)roster_usrelt, |
9fafea381eb8
Show the number of unfiltered contacts in folded groups
franky
parents:
1476
diff
changeset
|
887 |
NULL)) || |
72 | 888 |
(buddy_getflags((gpointer)roster_usrelt) & |
974
36f7753dfb59
Add /roster item_{lock,unlock}
Mikael Berthe <mikael@lilotux.net>
parents:
952
diff
changeset
|
889 |
(ROSTER_FLAG_LOCK | ROSTER_FLAG_USRLOCK | ROSTER_FLAG_MSG))) { |
72 | 890 |
// This user should be added. Maybe the group hasn't been added yet? |
1311
0dda8238af21
Implement "/roster display"
Mikael Berthe <mikael@lilotux.net>
parents:
1292
diff
changeset
|
891 |
if (pending_group) { |
72 | 892 |
// It hasn't been done yet |
893 |
buddylist = g_list_append(buddylist, roster_elt); |
|
894 |
pending_group = FALSE; |
|
895 |
} |
|
896 |
// Add user |
|
128 | 897 |
// XXX Should we add the user if there is a message and |
898 |
// the group is shrunk? If so, we'd need to check LOCK flag too, |
|
899 |
// perhaps... |
|
900 |
if (!shrunk_group) |
|
901 |
buddylist = g_list_append(buddylist, roster_usrelt); |
|
72 | 902 |
} |
903 |
||
904 |
sl_roster_usrelt = g_slist_next(sl_roster_usrelt); |
|
905 |
} |
|
906 |
sl_roster_elt = g_slist_next(sl_roster_elt); |
|
907 |
} |
|
78 | 908 |
|
81 | 909 |
// Check if we can find our saved current_buddy... |
910 |
if (roster_current_buddy) |
|
911 |
current_buddy = g_list_find(buddylist, roster_current_buddy); |
|
330 | 912 |
if (roster_alternate_buddy) |
913 |
alternate_buddy = g_list_find(buddylist, roster_alternate_buddy); |
|
78 | 914 |
// current_buddy initialization |
915 |
if (!current_buddy || (g_list_position(buddylist, current_buddy) == -1)) |
|
81 | 916 |
current_buddy = g_list_first(buddylist); |
72 | 917 |
} |
918 |
||
919 |
// buddy_hide_group(roster, hide) |
|
920 |
// "hide" values: 1=hide 0=show_all -1=invert |
|
921 |
void buddy_hide_group(gpointer rosterdata, int hide) |
|
922 |
{ |
|
207 | 923 |
roster *roster_usr = rosterdata; |
72 | 924 |
if (hide > 0) // TRUE (hide) |
207 | 925 |
roster_usr->flags |= ROSTER_FLAG_HIDE; |
72 | 926 |
else if (hide < 0) // NEG (invert) |
207 | 927 |
roster_usr->flags ^= ROSTER_FLAG_HIDE; |
72 | 928 |
else // FALSE (don't hide) |
207 | 929 |
roster_usr->flags &= ~ROSTER_FLAG_HIDE; |
72 | 930 |
} |
931 |
||
932 |
const char *buddy_getjid(gpointer rosterdata) |
|
933 |
{ |
|
1475
ef09de538e8f
Fix compilation error (reported by H. D. Oezbilen)
Mikael Berthe <mikael@lilotux.net>
parents:
1444
diff
changeset
|
934 |
roster *roster_usr = rosterdata; |
1292
382ec54b584e
Muc nick coloring functionality
Michal 'vorner' Vaner <vorner@ucw.cz>
parents:
1205
diff
changeset
|
935 |
if (!rosterdata) |
382ec54b584e
Muc nick coloring functionality
Michal 'vorner' Vaner <vorner@ucw.cz>
parents:
1205
diff
changeset
|
936 |
return NULL; |
207 | 937 |
return roster_usr->jid; |
938 |
} |
|
939 |
||
210 | 940 |
// buddy_setgroup() |
941 |
// Change the group of current buddy |
|
942 |
// |
|
1366
01e558748379
Fix a race in roster_add_user()
Mikael Berthe <mikael@lilotux.net>
parents:
1355
diff
changeset
|
943 |
// Note: buddy_setgroup() updates the user lists. |
01e558748379
Fix a race in roster_add_user()
Mikael Berthe <mikael@lilotux.net>
parents:
1355
diff
changeset
|
944 |
// |
210 | 945 |
void buddy_setgroup(gpointer rosterdata, char *newgroupname) |
946 |
{ |
|
947 |
roster *roster_usr = rosterdata; |
|
948 |
GSList **sl_group; |
|
620
97dd14e22b2a
Rewrite buddy_setgroup()
Mikael Berthe <mikael@lilotux.net>
parents:
610
diff
changeset
|
949 |
GSList *sl_newgroup; |
97dd14e22b2a
Rewrite buddy_setgroup()
Mikael Berthe <mikael@lilotux.net>
parents:
610
diff
changeset
|
950 |
roster *my_newgroup; |
210 | 951 |
|
952 |
// A group has no group :) |
|
953 |
if (roster_usr->type & ROSTER_TYPE_GROUP) return; |
|
954 |
||
620
97dd14e22b2a
Rewrite buddy_setgroup()
Mikael Berthe <mikael@lilotux.net>
parents:
610
diff
changeset
|
955 |
// Add newgroup if necessary |
97dd14e22b2a
Rewrite buddy_setgroup()
Mikael Berthe <mikael@lilotux.net>
parents:
610
diff
changeset
|
956 |
if (!newgroupname) newgroupname = ""; |
97dd14e22b2a
Rewrite buddy_setgroup()
Mikael Berthe <mikael@lilotux.net>
parents:
610
diff
changeset
|
957 |
sl_newgroup = roster_add_group(newgroupname); |
97dd14e22b2a
Rewrite buddy_setgroup()
Mikael Berthe <mikael@lilotux.net>
parents:
610
diff
changeset
|
958 |
if (!sl_newgroup) return; |
97dd14e22b2a
Rewrite buddy_setgroup()
Mikael Berthe <mikael@lilotux.net>
parents:
610
diff
changeset
|
959 |
my_newgroup = (roster*)sl_newgroup->data; |
97dd14e22b2a
Rewrite buddy_setgroup()
Mikael Berthe <mikael@lilotux.net>
parents:
610
diff
changeset
|
960 |
|
210 | 961 |
// Remove the buddy from current group |
962 |
sl_group = &((roster*)((GSList*)roster_usr->list)->data)->list; |
|
963 |
*sl_group = g_slist_remove(*sl_group, rosterdata); |
|
393 | 964 |
|
621
f20c1934a8a7
"/move": remove old group if it is empty
Mikael Berthe <mikael@lilotux.net>
parents:
620
diff
changeset
|
965 |
// 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
|
966 |
if (!*sl_group) { |
f20c1934a8a7
"/move": remove old group if it is empty
Mikael Berthe <mikael@lilotux.net>
parents:
620
diff
changeset
|
967 |
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
|
968 |
g_free((gchar*)roster_grp->jid); |
46304b773a44
Remove useless checks before g_free() calls
Mikael Berthe <mikael@lilotux.net>
parents:
772
diff
changeset
|
969 |
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
|
970 |
g_free(roster_grp); |
f20c1934a8a7
"/move": remove old group if it is empty
Mikael Berthe <mikael@lilotux.net>
parents:
620
diff
changeset
|
971 |
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
|
972 |
} |
f20c1934a8a7
"/move": remove old group if it is empty
Mikael Berthe <mikael@lilotux.net>
parents:
620
diff
changeset
|
973 |
|
620
97dd14e22b2a
Rewrite buddy_setgroup()
Mikael Berthe <mikael@lilotux.net>
parents:
610
diff
changeset
|
974 |
// Add the buddy to its new group |
97dd14e22b2a
Rewrite buddy_setgroup()
Mikael Berthe <mikael@lilotux.net>
parents:
610
diff
changeset
|
975 |
roster_usr->list = sl_newgroup; // (my_newgroup SList element) |
97dd14e22b2a
Rewrite buddy_setgroup()
Mikael Berthe <mikael@lilotux.net>
parents:
610
diff
changeset
|
976 |
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
|
977 |
(GCompareFunc)&roster_compare_name); |
212 | 978 |
|
210 | 979 |
buddylist_build(); |
980 |
} |
|
981 |
||
207 | 982 |
void buddy_setname(gpointer rosterdata, char *newname) |
983 |
{ |
|
984 |
roster *roster_usr = rosterdata; |
|
209 | 985 |
GSList **sl_group; |
207 | 986 |
|
987 |
// TODO For groups, we need to check for unicity |
|
988 |
// However, renaming a group boils down to moving all its buddies to |
|
989 |
// another group, so calling this function is not really necessary... |
|
990 |
if (roster_usr->type & ROSTER_TYPE_GROUP) return; |
|
991 |
||
992 |
if (roster_usr->name) { |
|
993 |
g_free((gchar*)roster_usr->name); |
|
994 |
roster_usr->name = NULL; |
|
995 |
} |
|
996 |
if (newname) |
|
997 |
roster_usr->name = g_strdup(newname); |
|
209 | 998 |
|
999 |
// We need to resort the group list |
|
1000 |
sl_group = &((roster*)((GSList*)roster_usr->list)->data)->list; |
|
1001 |
*sl_group = g_slist_sort(*sl_group, (GCompareFunc)&roster_compare_name); |
|
1002 |
||
1003 |
buddylist_build(); |
|
72 | 1004 |
} |
1005 |
||
1006 |
const char *buddy_getname(gpointer rosterdata) |
|
1007 |
{ |
|
207 | 1008 |
roster *roster_usr = rosterdata; |
1009 |
return roster_usr->name; |
|
1010 |
} |
|
1011 |
||
548
265c50238a48
Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1012 |
// buddy_setnickname(buddy, newnickname) |
265c50238a48
Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1013 |
// Only for chatrooms |
469
a926523d2392
Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
468
diff
changeset
|
1014 |
void buddy_setnickname(gpointer rosterdata, const char *newname) |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
1015 |
{ |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
1016 |
roster *roster_usr = rosterdata; |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
1017 |
|
649
3ad6675caaf1
MUC: fix join bug when the conference is in the roster
Mikael Berthe <mikael@lilotux.net>
parents:
644
diff
changeset
|
1018 |
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
|
1019 |
|
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
1020 |
if (roster_usr->nickname) { |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
1021 |
g_free((gchar*)roster_usr->nickname); |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
1022 |
roster_usr->nickname = NULL; |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
1023 |
} |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
1024 |
if (newname) |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
1025 |
roster_usr->nickname = g_strdup(newname); |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
1026 |
} |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
1027 |
|
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
1028 |
const char *buddy_getnickname(gpointer rosterdata) |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
1029 |
{ |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
1030 |
roster *roster_usr = rosterdata; |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
1031 |
return roster_usr->nickname; |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
1032 |
} |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
1033 |
|
644
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
625
diff
changeset
|
1034 |
// buddy_setinsideroom(buddy, inside) |
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
625
diff
changeset
|
1035 |
// Only for chatrooms |
952 | 1036 |
void buddy_setinsideroom(gpointer rosterdata, guint inside) |
644
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
625
diff
changeset
|
1037 |
{ |
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
625
diff
changeset
|
1038 |
roster *roster_usr = rosterdata; |
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
625
diff
changeset
|
1039 |
|
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
625
diff
changeset
|
1040 |
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
|
1041 |
|
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
625
diff
changeset
|
1042 |
roster_usr->inside_room = inside; |
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
625
diff
changeset
|
1043 |
} |
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
625
diff
changeset
|
1044 |
|
952 | 1045 |
guint buddy_getinsideroom(gpointer rosterdata) |
644
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
625
diff
changeset
|
1046 |
{ |
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
625
diff
changeset
|
1047 |
roster *roster_usr = rosterdata; |
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
625
diff
changeset
|
1048 |
return roster_usr->inside_room; |
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
625
diff
changeset
|
1049 |
} |
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
625
diff
changeset
|
1050 |
|
548
265c50238a48
Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1051 |
// buddy_settopic(buddy, newtopic) |
265c50238a48
Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1052 |
// Only for chatrooms |
265c50238a48
Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1053 |
void buddy_settopic(gpointer rosterdata, const char *newtopic) |
265c50238a48
Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1054 |
{ |
265c50238a48
Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1055 |
roster *roster_usr = rosterdata; |
265c50238a48
Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1056 |
|
265c50238a48
Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1057 |
if (!(roster_usr->type & ROSTER_TYPE_ROOM)) return; |
265c50238a48
Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1058 |
|
265c50238a48
Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1059 |
if (roster_usr->topic) { |
265c50238a48
Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1060 |
g_free((gchar*)roster_usr->topic); |
265c50238a48
Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1061 |
roster_usr->topic = NULL; |
265c50238a48
Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1062 |
} |
265c50238a48
Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1063 |
if (newtopic) |
265c50238a48
Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1064 |
roster_usr->topic = g_strdup(newtopic); |
265c50238a48
Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1065 |
} |
265c50238a48
Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1066 |
|
265c50238a48
Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1067 |
const char *buddy_gettopic(gpointer rosterdata) |
265c50238a48
Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1068 |
{ |
265c50238a48
Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1069 |
roster *roster_usr = rosterdata; |
265c50238a48
Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1070 |
return roster_usr->topic; |
265c50238a48
Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1071 |
} |
265c50238a48
Add buddy_{get,set}topic()
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1072 |
|
1377
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1366
diff
changeset
|
1073 |
void buddy_setprintstatus(gpointer rosterdata, enum room_printstatus pstatus) |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1366
diff
changeset
|
1074 |
{ |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1366
diff
changeset
|
1075 |
roster *roster_usr = rosterdata; |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1366
diff
changeset
|
1076 |
roster_usr->print_status = pstatus; |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1366
diff
changeset
|
1077 |
} |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1366
diff
changeset
|
1078 |
|
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1366
diff
changeset
|
1079 |
enum room_printstatus buddy_getprintstatus(gpointer rosterdata) |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1366
diff
changeset
|
1080 |
{ |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1366
diff
changeset
|
1081 |
roster *roster_usr = rosterdata; |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1366
diff
changeset
|
1082 |
return roster_usr->print_status; |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1366
diff
changeset
|
1083 |
} |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1366
diff
changeset
|
1084 |
|
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1366
diff
changeset
|
1085 |
void buddy_setautowhois(gpointer rosterdata, enum room_autowhois awhois) |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1366
diff
changeset
|
1086 |
{ |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1366
diff
changeset
|
1087 |
roster *roster_usr = rosterdata; |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1366
diff
changeset
|
1088 |
roster_usr->auto_whois = awhois; |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1366
diff
changeset
|
1089 |
} |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1366
diff
changeset
|
1090 |
|
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1366
diff
changeset
|
1091 |
enum room_autowhois buddy_getautowhois(gpointer rosterdata) |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1366
diff
changeset
|
1092 |
{ |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1366
diff
changeset
|
1093 |
roster *roster_usr = rosterdata; |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1366
diff
changeset
|
1094 |
return roster_usr->auto_whois; |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1366
diff
changeset
|
1095 |
} |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1366
diff
changeset
|
1096 |
|
207 | 1097 |
// buddy_getgroupname() |
1098 |
// Returns a pointer on buddy's group name. |
|
1099 |
const char *buddy_getgroupname(gpointer rosterdata) |
|
1100 |
{ |
|
1101 |
roster *roster_usr = rosterdata; |
|
1102 |
||
1103 |
if (roster_usr->type & ROSTER_TYPE_GROUP) |
|
1104 |
return roster_usr->name; |
|
1105 |
||
848
a9161d2dc414
Introduce special buffer stuff
Mikael Berthe <mikael@lilotux.net>
parents:
843
diff
changeset
|
1106 |
if (roster_usr->type & ROSTER_TYPE_SPECIAL) |
a9161d2dc414
Introduce special buffer stuff
Mikael Berthe <mikael@lilotux.net>
parents:
843
diff
changeset
|
1107 |
return NULL; |
a9161d2dc414
Introduce special buffer stuff
Mikael Berthe <mikael@lilotux.net>
parents:
843
diff
changeset
|
1108 |
|
207 | 1109 |
// This is a user |
1110 |
return ((roster*)((GSList*)roster_usr->list)->data)->name; |
|
72 | 1111 |
} |
1112 |
||
166 | 1113 |
// buddy_getgroup() |
1114 |
// Returns a pointer on buddy's group. |
|
1115 |
gpointer buddy_getgroup(gpointer rosterdata) |
|
1116 |
{ |
|
207 | 1117 |
roster *roster_usr = rosterdata; |
166 | 1118 |
|
207 | 1119 |
if (roster_usr->type & ROSTER_TYPE_GROUP) |
166 | 1120 |
return rosterdata; |
1121 |
||
848
a9161d2dc414
Introduce special buffer stuff
Mikael Berthe <mikael@lilotux.net>
parents:
843
diff
changeset
|
1122 |
if (roster_usr->type & ROSTER_TYPE_SPECIAL) |
a9161d2dc414
Introduce special buffer stuff
Mikael Berthe <mikael@lilotux.net>
parents:
843
diff
changeset
|
1123 |
return NULL; |
a9161d2dc414
Introduce special buffer stuff
Mikael Berthe <mikael@lilotux.net>
parents:
843
diff
changeset
|
1124 |
|
166 | 1125 |
// This is a user |
207 | 1126 |
return (gpointer)((GSList*)roster_usr->list)->data; |
166 | 1127 |
} |
1128 |
||
489
21ab22a60bcb
Auto-convert a roster item to "room" type when receiving a groupchat message
Mikael Berthe <mikael@lilotux.net>
parents:
483
diff
changeset
|
1129 |
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
|
1130 |
{ |
21ab22a60bcb
Auto-convert a roster item to "room" type when receiving a groupchat message
Mikael Berthe <mikael@lilotux.net>
parents:
483
diff
changeset
|
1131 |
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
|
1132 |
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
|
1133 |
} |
21ab22a60bcb
Auto-convert a roster item to "room" type when receiving a groupchat message
Mikael Berthe <mikael@lilotux.net>
parents:
483
diff
changeset
|
1134 |
|
72 | 1135 |
guint buddy_gettype(gpointer rosterdata) |
1136 |
{ |
|
207 | 1137 |
roster *roster_usr = rosterdata; |
1138 |
return roster_usr->type; |
|
72 | 1139 |
} |
1140 |
||
603 | 1141 |
guint buddy_getsubscription(gpointer rosterdata) |
1142 |
{ |
|
1143 |
roster *roster_usr = rosterdata; |
|
1144 |
return roster_usr->subscription; |
|
1145 |
} |
|
1146 |
||
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
1147 |
enum imstatus buddy_getstatus(gpointer rosterdata, const char *resname) |
72 | 1148 |
{ |
207 | 1149 |
roster *roster_usr = rosterdata; |
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
1150 |
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
|
1151 |
if (p_res) |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
1152 |
return p_res->status; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
1153 |
return offline; |
72 | 1154 |
} |
1155 |
||
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
1156 |
const char *buddy_getstatusmsg(gpointer rosterdata, const char *resname) |
221 | 1157 |
{ |
1158 |
roster *roster_usr = rosterdata; |
|
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
1159 |
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
|
1160 |
if (p_res) |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
425
diff
changeset
|
1161 |
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
|
1162 |
return roster_usr->offline_status_message; |
221 | 1163 |
} |
1164 |
||
625
028c01940490
Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
621
diff
changeset
|
1165 |
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
|
1166 |
{ |
028c01940490
Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
621
diff
changeset
|
1167 |
roster *roster_usr = rosterdata; |
028c01940490
Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
621
diff
changeset
|
1168 |
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
|
1169 |
if (p_res) |
028c01940490
Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
621
diff
changeset
|
1170 |
return p_res->status_timestamp; |
028c01940490
Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
621
diff
changeset
|
1171 |
return 0; |
028c01940490
Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
621
diff
changeset
|
1172 |
} |
028c01940490
Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
621
diff
changeset
|
1173 |
|
439
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
1174 |
gchar buddy_getresourceprio(gpointer rosterdata, const char *resname) |
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
1175 |
{ |
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
1176 |
roster *roster_usr = rosterdata; |
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
1177 |
res *p_res = get_resource(roster_usr, resname); |
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
1178 |
if (p_res) |
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
1179 |
return p_res->prio; |
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
1180 |
return 0; |
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
1181 |
} |
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
1182 |
|
986
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1183 |
guint buddy_resource_getevents(gpointer rosterdata, const char *resname) |
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1184 |
{ |
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1185 |
roster *roster_usr = rosterdata; |
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1186 |
res *p_res = get_resource(roster_usr, resname); |
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1187 |
if (p_res) |
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1188 |
return p_res->events; |
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1189 |
return ROSTER_EVENT_NONE; |
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1190 |
} |
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1191 |
|
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1192 |
void buddy_resource_setevents(gpointer rosterdata, const char *resname, |
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1193 |
guint events) |
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1194 |
{ |
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1195 |
roster *roster_usr = rosterdata; |
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1196 |
res *p_res = get_resource(roster_usr, resname); |
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1197 |
if (p_res) |
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1198 |
p_res->events = events; |
987
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
1199 |
} |
986
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1200 |
|
1600 | 1201 |
char *buddy_resource_getcaps(gpointer rosterdata, const char *resname) |
1202 |
{ |
|
1203 |
roster *roster_usr = rosterdata; |
|
1204 |
res *p_res = get_resource(roster_usr, resname); |
|
1205 |
if (p_res) |
|
1206 |
return p_res->caps; |
|
1207 |
return NULL; |
|
1208 |
} |
|
1209 |
||
1210 |
void buddy_resource_setcaps(gpointer rosterdata, const char *resname, |
|
1211 |
const char *caps) |
|
1212 |
{ |
|
1213 |
roster *roster_usr = rosterdata; |
|
1214 |
res *p_res = get_resource(roster_usr, resname); |
|
1215 |
if (p_res) { |
|
1216 |
g_free(p_res->caps); |
|
1217 |
p_res->caps = g_strdup(caps); |
|
1218 |
} |
|
1219 |
} |
|
1220 |
||
987
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
1221 |
struct jep0022 *buddy_resource_jep22(gpointer rosterdata, const char *resname) |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
1222 |
{ |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
1223 |
#ifdef JEP0022 |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
1224 |
roster *roster_usr = rosterdata; |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
1225 |
res *p_res = get_resource(roster_usr, resname); |
986
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1226 |
if (p_res) |
987
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
1227 |
return &p_res->jep22; |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
1228 |
#endif |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
1229 |
return NULL; |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
1230 |
} |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
1231 |
|
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
1232 |
struct jep0085 *buddy_resource_jep85(gpointer rosterdata, const char *resname) |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
1233 |
{ |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
1234 |
#ifdef JEP0085 |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
1235 |
roster *roster_usr = rosterdata; |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
1236 |
res *p_res = get_resource(roster_usr, resname); |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
1237 |
if (p_res) |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
1238 |
return &p_res->jep85; |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
1239 |
#endif |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
1240 |
return NULL; |
986
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1241 |
} |
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1242 |
|
1043
ebbde723614b
Store contacts PGP keys
Mikael Berthe <mikael@lilotux.net>
parents:
1010
diff
changeset
|
1243 |
struct pgp_data *buddy_resource_pgp(gpointer rosterdata, const char *resname) |
ebbde723614b
Store contacts PGP keys
Mikael Berthe <mikael@lilotux.net>
parents:
1010
diff
changeset
|
1244 |
{ |
ebbde723614b
Store contacts PGP keys
Mikael Berthe <mikael@lilotux.net>
parents:
1010
diff
changeset
|
1245 |
#ifdef HAVE_GPGME |
ebbde723614b
Store contacts PGP keys
Mikael Berthe <mikael@lilotux.net>
parents:
1010
diff
changeset
|
1246 |
roster *roster_usr = rosterdata; |
ebbde723614b
Store contacts PGP keys
Mikael Berthe <mikael@lilotux.net>
parents:
1010
diff
changeset
|
1247 |
res *p_res = get_resource(roster_usr, resname); |
ebbde723614b
Store contacts PGP keys
Mikael Berthe <mikael@lilotux.net>
parents:
1010
diff
changeset
|
1248 |
if (p_res) |
ebbde723614b
Store contacts PGP keys
Mikael Berthe <mikael@lilotux.net>
parents:
1010
diff
changeset
|
1249 |
return &p_res->pgpdata; |
ebbde723614b
Store contacts PGP keys
Mikael Berthe <mikael@lilotux.net>
parents:
1010
diff
changeset
|
1250 |
#endif |
ebbde723614b
Store contacts PGP keys
Mikael Berthe <mikael@lilotux.net>
parents:
1010
diff
changeset
|
1251 |
return NULL; |
ebbde723614b
Store contacts PGP keys
Mikael Berthe <mikael@lilotux.net>
parents:
1010
diff
changeset
|
1252 |
} |
ebbde723614b
Store contacts PGP keys
Mikael Berthe <mikael@lilotux.net>
parents:
1010
diff
changeset
|
1253 |
|
572
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
1254 |
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
|
1255 |
{ |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
1256 |
roster *roster_usr = rosterdata; |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
1257 |
res *p_res = get_resource(roster_usr, resname); |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
1258 |
if (p_res) |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
1259 |
return p_res->role; |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
1260 |
return role_none; |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
1261 |
} |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
1262 |
|
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
1263 |
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
|
1264 |
{ |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
1265 |
roster *roster_usr = rosterdata; |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
1266 |
res *p_res = get_resource(roster_usr, resname); |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
1267 |
if (p_res) |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
1268 |
return p_res->affil; |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
1269 |
return affil_none; |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
1270 |
} |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
1271 |
|
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
1272 |
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
|
1273 |
{ |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
1274 |
roster *roster_usr = rosterdata; |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
1275 |
res *p_res = get_resource(roster_usr, resname); |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
1276 |
if (p_res) |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
1277 |
return p_res->realjid; |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
1278 |
return NULL; |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
1279 |
} |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
564
diff
changeset
|
1280 |
|
439
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
1281 |
// buddy_getresources(roster_data) |
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
1282 |
// Return a singly-linked-list of resource names |
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
1283 |
// 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
|
1284 |
// 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
|
1285 |
GSList *buddy_getresources(gpointer rosterdata) |
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
1286 |
{ |
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
1287 |
roster *roster_usr = rosterdata; |
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
1288 |
GSList *reslist = NULL, *lp; |
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
1289 |
|
501
7c1ca00070e8
Add COMPL_RESOURCE (resource completion category)
Mikael Berthe <mikael@lilotux.net>
parents:
494
diff
changeset
|
1290 |
if (!roster_usr) { |
7c1ca00070e8
Add COMPL_RESOURCE (resource completion category)
Mikael Berthe <mikael@lilotux.net>
parents:
494
diff
changeset
|
1291 |
if (!current_buddy) return NULL; |
7c1ca00070e8
Add COMPL_RESOURCE (resource completion category)
Mikael Berthe <mikael@lilotux.net>
parents:
494
diff
changeset
|
1292 |
roster_usr = BUDDATA(current_buddy); |
7c1ca00070e8
Add COMPL_RESOURCE (resource completion category)
Mikael Berthe <mikael@lilotux.net>
parents:
494
diff
changeset
|
1293 |
} |
439
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
1294 |
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
|
1295 |
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
|
1296 |
|
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
1297 |
return reslist; |
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
1298 |
} |
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
1299 |
|
792
89ad7b530b3c
MUC: Fix completion for UTF-8 nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
783
diff
changeset
|
1300 |
// buddy_getresources_locale(roster_data) |
89ad7b530b3c
MUC: Fix completion for UTF-8 nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
783
diff
changeset
|
1301 |
// 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
|
1302 |
// 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
|
1303 |
GSList *buddy_getresources_locale(gpointer rosterdata) |
89ad7b530b3c
MUC: Fix completion for UTF-8 nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
783
diff
changeset
|
1304 |
{ |
89ad7b530b3c
MUC: Fix completion for UTF-8 nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
783
diff
changeset
|
1305 |
GSList *reslist, *lp; |
89ad7b530b3c
MUC: Fix completion for UTF-8 nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
783
diff
changeset
|
1306 |
|
89ad7b530b3c
MUC: Fix completion for UTF-8 nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
783
diff
changeset
|
1307 |
reslist = buddy_getresources(rosterdata); |
89ad7b530b3c
MUC: Fix completion for UTF-8 nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
783
diff
changeset
|
1308 |
// Convert each item to UI's locale |
89ad7b530b3c
MUC: Fix completion for UTF-8 nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
783
diff
changeset
|
1309 |
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
|
1310 |
gchar *oldname = lp->data; |
89ad7b530b3c
MUC: Fix completion for UTF-8 nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
783
diff
changeset
|
1311 |
lp->data = from_utf8(oldname); |
89ad7b530b3c
MUC: Fix completion for UTF-8 nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
783
diff
changeset
|
1312 |
if (lp->data) |
89ad7b530b3c
MUC: Fix completion for UTF-8 nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
783
diff
changeset
|
1313 |
g_free(oldname); |
89ad7b530b3c
MUC: Fix completion for UTF-8 nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
783
diff
changeset
|
1314 |
else |
89ad7b530b3c
MUC: Fix completion for UTF-8 nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
783
diff
changeset
|
1315 |
lp->data = oldname; |
89ad7b530b3c
MUC: Fix completion for UTF-8 nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
783
diff
changeset
|
1316 |
} |
89ad7b530b3c
MUC: Fix completion for UTF-8 nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
783
diff
changeset
|
1317 |
return reslist; |
89ad7b530b3c
MUC: Fix completion for UTF-8 nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
783
diff
changeset
|
1318 |
} |
89ad7b530b3c
MUC: Fix completion for UTF-8 nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
783
diff
changeset
|
1319 |
|
652
b243d3b3ff1b
We do not need buddy_isresource() anymore
Mikael Berthe <mikael@lilotux.net>
parents:
649
diff
changeset
|
1320 |
/* |
539 | 1321 |
// buddy_isresource(roster_data) |
1322 |
// Return true if there is at least one resource |
|
1323 |
// (which means, for a room, that it isn't empty) |
|
1324 |
int buddy_isresource(gpointer rosterdata) |
|
1325 |
{ |
|
1326 |
roster *roster_usr = rosterdata; |
|
1327 |
if (!roster_usr) |
|
1328 |
return FALSE; |
|
1329 |
if (roster_usr->resource) |
|
1330 |
return TRUE; |
|
1331 |
return FALSE; |
|
1332 |
} |
|
652
b243d3b3ff1b
We do not need buddy_isresource() anymore
Mikael Berthe <mikael@lilotux.net>
parents:
649
diff
changeset
|
1333 |
*/ |
539 | 1334 |
|
468
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
1335 |
// buddy_resource_setname(roster_data, oldname, newname) |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
1336 |
// Useful for nickname change in a MUC room |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
1337 |
void buddy_resource_setname(gpointer rosterdata, const char *resname, |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
1338 |
const char *newname) |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
1339 |
{ |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
1340 |
roster *roster_usr = rosterdata; |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
1341 |
res *p_res = get_resource(roster_usr, resname); |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
1342 |
if (p_res) { |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
1343 |
if (p_res->name) { |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
1344 |
g_free((gchar*)p_res->name); |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
1345 |
p_res->name = NULL; |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
1346 |
} |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
1347 |
if (newname) |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
1348 |
p_res->name = g_strdup(newname); |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
1349 |
} |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
1350 |
} |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
1351 |
|
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
1352 |
// buddy_del_all_resources() |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
1353 |
// Remove all resources from the specified buddy |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
1354 |
void buddy_del_all_resources(gpointer rosterdata) |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
1355 |
{ |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
1356 |
roster *roster_usr = rosterdata; |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
1357 |
|
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
1358 |
while (roster_usr->resource) { |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
1359 |
res *r = roster_usr->resource->data; |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
1360 |
del_resource(roster_usr, r->name); |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
1361 |
} |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
1362 |
} |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
439
diff
changeset
|
1363 |
|
119 | 1364 |
// buddy_setflags() |
1365 |
// Set one or several flags to value (TRUE/FALSE) |
|
1366 |
void buddy_setflags(gpointer rosterdata, guint flags, guint value) |
|
1367 |
{ |
|
207 | 1368 |
roster *roster_usr = rosterdata; |
119 | 1369 |
if (value) |
207 | 1370 |
roster_usr->flags |= flags; |
119 | 1371 |
else |
207 | 1372 |
roster_usr->flags &= ~flags; |
119 | 1373 |
} |
1374 |
||
72 | 1375 |
guint buddy_getflags(gpointer rosterdata) |
1376 |
{ |
|
207 | 1377 |
roster *roster_usr = rosterdata; |
1378 |
return roster_usr->flags; |
|
72 | 1379 |
} |
1380 |
||
1355 | 1381 |
// buddy_setonserverflag() |
1382 |
// Set the on_server flag |
|
1383 |
void buddy_setonserverflag(gpointer rosterdata, guint onserver) |
|
1384 |
{ |
|
1385 |
roster *roster_usr = rosterdata; |
|
1386 |
roster_usr->on_server = onserver; |
|
1387 |
} |
|
1388 |
||
1389 |
guint buddy_getonserverflag(gpointer rosterdata) |
|
1390 |
{ |
|
1391 |
roster *roster_usr = rosterdata; |
|
1392 |
return roster_usr->on_server; |
|
1393 |
} |
|
1394 |
||
480 | 1395 |
// buddy_search_jid(jid) |
1396 |
// Look for a buddy with specified jid. |
|
1397 |
// Search begins at buddylist; if no match is found in the the buddylist, |
|
1398 |
// return NULL; |
|
1292
382ec54b584e
Muc nick coloring functionality
Michal 'vorner' Vaner <vorner@ucw.cz>
parents:
1205
diff
changeset
|
1399 |
GList *buddy_search_jid(const char *jid) |
480 | 1400 |
{ |
1401 |
GList *buddy; |
|
1402 |
roster *roster_usr; |
|
1403 |
||
1404 |
if (!buddylist) return NULL; |
|
1405 |
||
1406 |
for (buddy = buddylist; buddy; buddy = g_list_next(buddy)) { |
|
1407 |
roster_usr = (roster*)buddy->data; |
|
1408 |
if (roster_usr->jid && !strcasecmp(roster_usr->jid, jid)) |
|
1409 |
return buddy; |
|
1410 |
} |
|
1411 |
return NULL; |
|
1412 |
} |
|
1413 |
||
265 | 1414 |
// buddy_search(string) |
1415 |
// Look for a buddy whose name or jid contains string. |
|
1416 |
// Search begins at current_buddy; if no match is found in the the buddylist, |
|
1417 |
// return NULL; |
|
1418 |
GList *buddy_search(char *string) |
|
1419 |
{ |
|
1420 |
GList *buddy = current_buddy; |
|
1421 |
roster *roster_usr; |
|
1422 |
if (!buddylist || !current_buddy) return NULL; |
|
1423 |
for (;;) { |
|
772
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
1424 |
gchar *jid_locale, *name_locale; |
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
1425 |
char *found = NULL; |
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
1426 |
|
265 | 1427 |
buddy = g_list_next(buddy); |
1428 |
if (!buddy) |
|
1429 |
buddy = buddylist; |
|
1430 |
||
1431 |
roster_usr = (roster*)buddy->data; |
|
772
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
1432 |
|
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
1433 |
jid_locale = from_utf8(roster_usr->jid); |
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
1434 |
if (jid_locale) { |
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
1435 |
found = strcasestr(jid_locale, string); |
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
1436 |
g_free(jid_locale); |
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
1437 |
if (found) |
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
1438 |
return buddy; |
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
1439 |
} |
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
1440 |
name_locale = from_utf8(roster_usr->name); |
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
1441 |
if (name_locale) { |
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
1442 |
found = strcasestr(name_locale, string); |
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
1443 |
g_free(name_locale); |
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
1444 |
if (found) |
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
1445 |
return buddy; |
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
1446 |
} |
265 | 1447 |
|
1448 |
if (buddy == current_buddy) |
|
1449 |
return NULL; // Back to the beginning, and no match found |
|
1450 |
} |
|
1451 |
} |
|
1452 |
||
532
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
520
diff
changeset
|
1453 |
// foreach_buddy(roster_type, pfunction, param) |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
520
diff
changeset
|
1454 |
// 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
|
1455 |
// type matching roster_type. |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
520
diff
changeset
|
1456 |
void foreach_buddy(guint roster_type, |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
520
diff
changeset
|
1457 |
void (*pfunc)(gpointer rosterdata, void *param), |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
520
diff
changeset
|
1458 |
void *param) |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
520
diff
changeset
|
1459 |
{ |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
520
diff
changeset
|
1460 |
GSList *sl_roster_elt = groups; |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
520
diff
changeset
|
1461 |
roster *roster_elt; |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
520
diff
changeset
|
1462 |
GSList *sl_roster_usrelt; |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
520
diff
changeset
|
1463 |
roster *roster_usrelt; |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
520
diff
changeset
|
1464 |
|
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
520
diff
changeset
|
1465 |
while (sl_roster_elt) { // group list loop |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
520
diff
changeset
|
1466 |
roster_elt = (roster*) sl_roster_elt->data; |
848
a9161d2dc414
Introduce special buffer stuff
Mikael Berthe <mikael@lilotux.net>
parents:
843
diff
changeset
|
1467 |
if (roster_elt->type & ROSTER_TYPE_SPECIAL) |
a9161d2dc414
Introduce special buffer stuff
Mikael Berthe <mikael@lilotux.net>
parents:
843
diff
changeset
|
1468 |
continue; // Skip special items |
532
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
520
diff
changeset
|
1469 |
sl_roster_usrelt = roster_elt->list; |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
520
diff
changeset
|
1470 |
while (sl_roster_usrelt) { // user list loop |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
520
diff
changeset
|
1471 |
roster_usrelt = (roster*) sl_roster_usrelt->data; |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
520
diff
changeset
|
1472 |
|
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
520
diff
changeset
|
1473 |
if (roster_usrelt->type & roster_type) |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
520
diff
changeset
|
1474 |
pfunc(roster_usrelt, param); |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
520
diff
changeset
|
1475 |
|
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
520
diff
changeset
|
1476 |
sl_roster_usrelt = g_slist_next(sl_roster_usrelt); |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
520
diff
changeset
|
1477 |
} |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
520
diff
changeset
|
1478 |
sl_roster_elt = g_slist_next(sl_roster_elt); |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
520
diff
changeset
|
1479 |
} |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
520
diff
changeset
|
1480 |
} |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
520
diff
changeset
|
1481 |
|
885
afdd81c2c44d
Allow /rename for groups
Mikael Berthe <mikael@lilotux.net>
parents:
863
diff
changeset
|
1482 |
// foreach_group_member(group, pfunction, param) |
afdd81c2c44d
Allow /rename for groups
Mikael Berthe <mikael@lilotux.net>
parents:
863
diff
changeset
|
1483 |
// 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
|
1484 |
void foreach_group_member(gpointer groupdata, |
afdd81c2c44d
Allow /rename for groups
Mikael Berthe <mikael@lilotux.net>
parents:
863
diff
changeset
|
1485 |
void (*pfunc)(gpointer rosterdata, void *param), |
afdd81c2c44d
Allow /rename for groups
Mikael Berthe <mikael@lilotux.net>
parents:
863
diff
changeset
|
1486 |
void *param) |
afdd81c2c44d
Allow /rename for groups
Mikael Berthe <mikael@lilotux.net>
parents:
863
diff
changeset
|
1487 |
{ |
afdd81c2c44d
Allow /rename for groups
Mikael Berthe <mikael@lilotux.net>
parents:
863
diff
changeset
|
1488 |
roster *roster_elt; |
afdd81c2c44d
Allow /rename for groups
Mikael Berthe <mikael@lilotux.net>
parents:
863
diff
changeset
|
1489 |
GSList *sl_roster_usrelt; |
afdd81c2c44d
Allow /rename for groups
Mikael Berthe <mikael@lilotux.net>
parents:
863
diff
changeset
|
1490 |
roster *roster_usrelt; |
afdd81c2c44d
Allow /rename for groups
Mikael Berthe <mikael@lilotux.net>
parents:
863
diff
changeset
|
1491 |
|
afdd81c2c44d
Allow /rename for groups
Mikael Berthe <mikael@lilotux.net>
parents:
863
diff
changeset
|
1492 |
roster_elt = groupdata; |
afdd81c2c44d
Allow /rename for groups
Mikael Berthe <mikael@lilotux.net>
parents:
863
diff
changeset
|
1493 |
|
afdd81c2c44d
Allow /rename for groups
Mikael Berthe <mikael@lilotux.net>
parents:
863
diff
changeset
|
1494 |
if (!(roster_elt->type & ROSTER_TYPE_GROUP)) |
afdd81c2c44d
Allow /rename for groups
Mikael Berthe <mikael@lilotux.net>
parents:
863
diff
changeset
|
1495 |
return; |
afdd81c2c44d
Allow /rename for groups
Mikael Berthe <mikael@lilotux.net>
parents:
863
diff
changeset
|
1496 |
|
afdd81c2c44d
Allow /rename for groups
Mikael Berthe <mikael@lilotux.net>
parents:
863
diff
changeset
|
1497 |
sl_roster_usrelt = roster_elt->list; |
afdd81c2c44d
Allow /rename for groups
Mikael Berthe <mikael@lilotux.net>
parents:
863
diff
changeset
|
1498 |
while (sl_roster_usrelt) { // user list loop |
afdd81c2c44d
Allow /rename for groups
Mikael Berthe <mikael@lilotux.net>
parents:
863
diff
changeset
|
1499 |
roster_usrelt = (roster*) sl_roster_usrelt->data; |
afdd81c2c44d
Allow /rename for groups
Mikael Berthe <mikael@lilotux.net>
parents:
863
diff
changeset
|
1500 |
|
afdd81c2c44d
Allow /rename for groups
Mikael Berthe <mikael@lilotux.net>
parents:
863
diff
changeset
|
1501 |
pfunc(roster_usrelt, param); |
afdd81c2c44d
Allow /rename for groups
Mikael Berthe <mikael@lilotux.net>
parents:
863
diff
changeset
|
1502 |
sl_roster_usrelt = g_slist_next(sl_roster_usrelt); |
afdd81c2c44d
Allow /rename for groups
Mikael Berthe <mikael@lilotux.net>
parents:
863
diff
changeset
|
1503 |
} |
afdd81c2c44d
Allow /rename for groups
Mikael Berthe <mikael@lilotux.net>
parents:
863
diff
changeset
|
1504 |
} |
afdd81c2c44d
Allow /rename for groups
Mikael Berthe <mikael@lilotux.net>
parents:
863
diff
changeset
|
1505 |
|
225 | 1506 |
// compl_list(type) |
1507 |
// Returns a list of jid's or groups. (For commands completion) |
|
1508 |
// type: ROSTER_TYPE_USER (jid's) or ROSTER_TYPE_GROUP (group names) |
|
1509 |
// The list should be freed by the caller after use. |
|
1510 |
GSList *compl_list(guint type) |
|
1511 |
{ |
|
1512 |
GSList *list = NULL; |
|
1088
c55b24818546
Enable jid completion for hidden buddies (e.g. offline contacts)
Mikael Berthe <mikael@lilotux.net>
parents:
1065
diff
changeset
|
1513 |
GSList *sl_roster_elt = groups; |
c55b24818546
Enable jid completion for hidden buddies (e.g. offline contacts)
Mikael Berthe <mikael@lilotux.net>
parents:
1065
diff
changeset
|
1514 |
roster *roster_elt; |
c55b24818546
Enable jid completion for hidden buddies (e.g. offline contacts)
Mikael Berthe <mikael@lilotux.net>
parents:
1065
diff
changeset
|
1515 |
GSList *sl_roster_usrelt; |
c55b24818546
Enable jid completion for hidden buddies (e.g. offline contacts)
Mikael Berthe <mikael@lilotux.net>
parents:
1065
diff
changeset
|
1516 |
roster *roster_usrelt; |
225 | 1517 |
|
1088
c55b24818546
Enable jid completion for hidden buddies (e.g. offline contacts)
Mikael Berthe <mikael@lilotux.net>
parents:
1065
diff
changeset
|
1518 |
while (sl_roster_elt) { // group list loop |
c55b24818546
Enable jid completion for hidden buddies (e.g. offline contacts)
Mikael Berthe <mikael@lilotux.net>
parents:
1065
diff
changeset
|
1519 |
roster_elt = (roster*) sl_roster_elt->data; |
c55b24818546
Enable jid completion for hidden buddies (e.g. offline contacts)
Mikael Berthe <mikael@lilotux.net>
parents:
1065
diff
changeset
|
1520 |
|
c55b24818546
Enable jid completion for hidden buddies (e.g. offline contacts)
Mikael Berthe <mikael@lilotux.net>
parents:
1065
diff
changeset
|
1521 |
if (roster_elt->type & ROSTER_TYPE_SPECIAL) |
c55b24818546
Enable jid completion for hidden buddies (e.g. offline contacts)
Mikael Berthe <mikael@lilotux.net>
parents:
1065
diff
changeset
|
1522 |
continue; // Skip special items |
225 | 1523 |
|
1524 |
if (type == ROSTER_TYPE_GROUP) { // (group names) |
|
1088
c55b24818546
Enable jid completion for hidden buddies (e.g. offline contacts)
Mikael Berthe <mikael@lilotux.net>
parents:
1065
diff
changeset
|
1525 |
if (roster_elt->name && *(roster_elt->name)) |
c55b24818546
Enable jid completion for hidden buddies (e.g. offline contacts)
Mikael Berthe <mikael@lilotux.net>
parents:
1065
diff
changeset
|
1526 |
list = g_slist_append(list, from_utf8(roster_elt->name)); |
c55b24818546
Enable jid completion for hidden buddies (e.g. offline contacts)
Mikael Berthe <mikael@lilotux.net>
parents:
1065
diff
changeset
|
1527 |
} else { // ROSTER_TYPE_USER (jid) (or agent, or chatroom...) |
c55b24818546
Enable jid completion for hidden buddies (e.g. offline contacts)
Mikael Berthe <mikael@lilotux.net>
parents:
1065
diff
changeset
|
1528 |
sl_roster_usrelt = roster_elt->list; |
c55b24818546
Enable jid completion for hidden buddies (e.g. offline contacts)
Mikael Berthe <mikael@lilotux.net>
parents:
1065
diff
changeset
|
1529 |
while (sl_roster_usrelt) { // user list loop |
c55b24818546
Enable jid completion for hidden buddies (e.g. offline contacts)
Mikael Berthe <mikael@lilotux.net>
parents:
1065
diff
changeset
|
1530 |
roster_usrelt = (roster*) sl_roster_usrelt->data; |
c55b24818546
Enable jid completion for hidden buddies (e.g. offline contacts)
Mikael Berthe <mikael@lilotux.net>
parents:
1065
diff
changeset
|
1531 |
|
c55b24818546
Enable jid completion for hidden buddies (e.g. offline contacts)
Mikael Berthe <mikael@lilotux.net>
parents:
1065
diff
changeset
|
1532 |
if (roster_usrelt->jid) |
c55b24818546
Enable jid completion for hidden buddies (e.g. offline contacts)
Mikael Berthe <mikael@lilotux.net>
parents:
1065
diff
changeset
|
1533 |
list = g_slist_append(list, from_utf8(roster_usrelt->jid)); |
c55b24818546
Enable jid completion for hidden buddies (e.g. offline contacts)
Mikael Berthe <mikael@lilotux.net>
parents:
1065
diff
changeset
|
1534 |
|
c55b24818546
Enable jid completion for hidden buddies (e.g. offline contacts)
Mikael Berthe <mikael@lilotux.net>
parents:
1065
diff
changeset
|
1535 |
sl_roster_usrelt = g_slist_next(sl_roster_usrelt); |
225 | 1536 |
} |
1537 |
} |
|
1088
c55b24818546
Enable jid completion for hidden buddies (e.g. offline contacts)
Mikael Berthe <mikael@lilotux.net>
parents:
1065
diff
changeset
|
1538 |
sl_roster_elt = g_slist_next(sl_roster_elt); |
225 | 1539 |
} |
1540 |
||
1541 |
return list; |
|
1542 |
} |
|
1543 |
||
236 | 1544 |
// unread_msg(rosterdata) |
1545 |
// Return the next buddy with an unread message. If the parameter is NULL, |
|
1546 |
// return the first buddy with an unread message. |
|
1547 |
gpointer unread_msg(gpointer rosterdata) |
|
1548 |
{ |
|
1549 |
GSList *unread, *next_unread; |
|
1550 |
||
564 | 1551 |
if (!unread_list) |
1552 |
return NULL; |
|
1553 |
||
236 | 1554 |
// First unread message |
564 | 1555 |
if (!rosterdata) |
1556 |
return unread_list->data; |
|
236 | 1557 |
|
1558 |
unread = g_slist_find(unread_list, rosterdata); |
|
564 | 1559 |
if (!unread) |
1560 |
return unread_list->data; |
|
236 | 1561 |
|
1562 |
next_unread = g_slist_next(unread); |
|
564 | 1563 |
if (next_unread) |
1564 |
return next_unread->data; |
|
236 | 1565 |
return unread_list->data; |
1566 |
} |
|
576 | 1567 |
|
662
4111ff4cdd15
Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents:
652
diff
changeset
|
1568 |
|
4111ff4cdd15
Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents:
652
diff
changeset
|
1569 |
/* ### "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
|
1570 |
* |
4111ff4cdd15
Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents:
652
diff
changeset
|
1571 |
* 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
|
1572 |
* 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
|
1573 |
* 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
|
1574 |
* 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
|
1575 |
* 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
|
1576 |
*/ |
4111ff4cdd15
Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents:
652
diff
changeset
|
1577 |
|
4111ff4cdd15
Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents:
652
diff
changeset
|
1578 |
// 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
|
1579 |
// 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
|
1580 |
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
|
1581 |
{ |
4111ff4cdd15
Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents:
652
diff
changeset
|
1582 |
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
|
1583 |
// 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
|
1584 |
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
|
1585 |
} |
4111ff4cdd15
Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents:
652
diff
changeset
|
1586 |
// 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
|
1587 |
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
|
1588 |
} |
4111ff4cdd15
Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents:
652
diff
changeset
|
1589 |
|
4111ff4cdd15
Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents:
652
diff
changeset
|
1590 |
// 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
|
1591 |
// Return TRUE if jid is found in the table (and remove it), FALSE if not |
1437
071c8170b7de
Add option 'statefile' to keep track of unread messages across restarts
Mikael Berthe <mikael@lilotux.net>
parents:
1431
diff
changeset
|
1592 |
static int unread_jid_del(const char *jid) |
662
4111ff4cdd15
Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents:
652
diff
changeset
|
1593 |
{ |
4111ff4cdd15
Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents:
652
diff
changeset
|
1594 |
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
|
1595 |
return FALSE; |
4111ff4cdd15
Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents:
652
diff
changeset
|
1596 |
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
|
1597 |
} |
4111ff4cdd15
Do not loose the unread_message flag when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents:
652
diff
changeset
|
1598 |
|
1438
c5d937d5530b
g_hash_table_get_keys() is only in glib >= 2.14
Mikael Berthe <mikael@lilotux.net>
parents:
1437
diff
changeset
|
1599 |
// Helper function for unread_jid_get_list() |
c5d937d5530b
g_hash_table_get_keys() is only in glib >= 2.14
Mikael Berthe <mikael@lilotux.net>
parents:
1437
diff
changeset
|
1600 |
static void add_to_unreadjids(gpointer key, gpointer value, gpointer udata) |
c5d937d5530b
g_hash_table_get_keys() is only in glib >= 2.14
Mikael Berthe <mikael@lilotux.net>
parents:
1437
diff
changeset
|
1601 |
{ |
c5d937d5530b
g_hash_table_get_keys() is only in glib >= 2.14
Mikael Berthe <mikael@lilotux.net>
parents:
1437
diff
changeset
|
1602 |
GList **listp = udata; |
c5d937d5530b
g_hash_table_get_keys() is only in glib >= 2.14
Mikael Berthe <mikael@lilotux.net>
parents:
1437
diff
changeset
|
1603 |
*listp = g_list_append(*listp, key); |
c5d937d5530b
g_hash_table_get_keys() is only in glib >= 2.14
Mikael Berthe <mikael@lilotux.net>
parents:
1437
diff
changeset
|
1604 |
} |
c5d937d5530b
g_hash_table_get_keys() is only in glib >= 2.14
Mikael Berthe <mikael@lilotux.net>
parents:
1437
diff
changeset
|
1605 |
|
1437
071c8170b7de
Add option 'statefile' to keep track of unread messages across restarts
Mikael Berthe <mikael@lilotux.net>
parents:
1431
diff
changeset
|
1606 |
// unread_jid_get_list() |
071c8170b7de
Add option 'statefile' to keep track of unread messages across restarts
Mikael Berthe <mikael@lilotux.net>
parents:
1431
diff
changeset
|
1607 |
// Return the JID list. |
071c8170b7de
Add option 'statefile' to keep track of unread messages across restarts
Mikael Berthe <mikael@lilotux.net>
parents:
1431
diff
changeset
|
1608 |
// The content of the list should not be modified or freed. |
071c8170b7de
Add option 'statefile' to keep track of unread messages across restarts
Mikael Berthe <mikael@lilotux.net>
parents:
1431
diff
changeset
|
1609 |
// The caller should call g_list_free() after use. |
071c8170b7de
Add option 'statefile' to keep track of unread messages across restarts
Mikael Berthe <mikael@lilotux.net>
parents:
1431
diff
changeset
|
1610 |
GList *unread_jid_get_list(void) |
071c8170b7de
Add option 'statefile' to keep track of unread messages across restarts
Mikael Berthe <mikael@lilotux.net>
parents:
1431
diff
changeset
|
1611 |
{ |
1438
c5d937d5530b
g_hash_table_get_keys() is only in glib >= 2.14
Mikael Berthe <mikael@lilotux.net>
parents:
1437
diff
changeset
|
1612 |
GList *list = NULL; |
c5d937d5530b
g_hash_table_get_keys() is only in glib >= 2.14
Mikael Berthe <mikael@lilotux.net>
parents:
1437
diff
changeset
|
1613 |
|
1437
071c8170b7de
Add option 'statefile' to keep track of unread messages across restarts
Mikael Berthe <mikael@lilotux.net>
parents:
1431
diff
changeset
|
1614 |
if (!unread_jids) |
071c8170b7de
Add option 'statefile' to keep track of unread messages across restarts
Mikael Berthe <mikael@lilotux.net>
parents:
1431
diff
changeset
|
1615 |
return NULL; |
1438
c5d937d5530b
g_hash_table_get_keys() is only in glib >= 2.14
Mikael Berthe <mikael@lilotux.net>
parents:
1437
diff
changeset
|
1616 |
|
c5d937d5530b
g_hash_table_get_keys() is only in glib >= 2.14
Mikael Berthe <mikael@lilotux.net>
parents:
1437
diff
changeset
|
1617 |
// g_hash_table_get_keys() is only in glib >= 2.14 |
c5d937d5530b
g_hash_table_get_keys() is only in glib >= 2.14
Mikael Berthe <mikael@lilotux.net>
parents:
1437
diff
changeset
|
1618 |
//return g_hash_table_get_keys(unread_jids); |
c5d937d5530b
g_hash_table_get_keys() is only in glib >= 2.14
Mikael Berthe <mikael@lilotux.net>
parents:
1437
diff
changeset
|
1619 |
|
c5d937d5530b
g_hash_table_get_keys() is only in glib >= 2.14
Mikael Berthe <mikael@lilotux.net>
parents:
1437
diff
changeset
|
1620 |
g_hash_table_foreach(unread_jids, add_to_unreadjids, &list); |
c5d937d5530b
g_hash_table_get_keys() is only in glib >= 2.14
Mikael Berthe <mikael@lilotux.net>
parents:
1437
diff
changeset
|
1621 |
return list; |
1437
071c8170b7de
Add option 'statefile' to keep track of unread messages across restarts
Mikael Berthe <mikael@lilotux.net>
parents:
1431
diff
changeset
|
1622 |
} |
071c8170b7de
Add option 'statefile' to keep track of unread messages across restarts
Mikael Berthe <mikael@lilotux.net>
parents:
1431
diff
changeset
|
1623 |
|
580 | 1624 |
/* vim: set expandtab cindent cinoptions=>2\:2(0: For Vim users... */ |