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