Mercurial > hg
annotate mcabber/src/jabglue.c @ 538:6310b928d04a
Hide debug message
author | Mikael Berthe <mikael@lilotux.net> |
---|---|
date | Fri, 25 Nov 2005 23:10:26 +0100 |
parents | 6547fd48fb5e |
children | ffdfddd351b8 |
rev | line source |
---|---|
29 | 1 /* |
2 * jabglue.c -- Jabber protocol handling | |
393 | 3 * |
29 | 4 * Copyright (C) 2005 Mikael Berthe <bmikael@lists.lilotux.net> |
5 * Parts come from the centericq project: | |
6 * Copyright (C) 2002-2005 by Konstantin Klyagin <konst@konst.org.ua> | |
7 * | |
8 * This program is free software; you can redistribute it and/or modify | |
9 * it under the terms of the GNU General Public License as published by | |
10 * the Free Software Foundation; either version 2 of the License, or (at | |
11 * your option) any later version. | |
12 * | |
13 * This program is distributed in the hope that it will be useful, but | |
14 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 * General Public License for more details. | |
17 * | |
18 * You should have received a copy of the GNU General Public License | |
19 * along with this program; if not, write to the Free Software | |
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 | |
21 * USA | |
22 */ | |
23 | |
237 | 24 #define _GNU_SOURCE /* We need glibc for strptime */ |
29 | 25 #include "../libjabber/jabber.h" |
26 #include "jabglue.h" | |
81 | 27 #include "roster.h" |
29 | 28 #include "screen.h" |
113 | 29 #include "hooks.h" |
29 | 30 #include "utils.h" |
294
871e53769084
Allow one status message per Jabber status
Mikael Berthe <mikael@lilotux.net>
parents:
277
diff
changeset
|
31 #include "settings.h" |
441
51b8f10cfeb8
Handle g_locale_from_utf8() failures
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
32 #include "hbuf.h" |
478
47cfa3779549
MUC: log join/nick/leave/topic if log_muc_conf is set
Mikael Berthe <mikael@lilotux.net>
parents:
475
diff
changeset
|
33 #include "histolog.h" |
29 | 34 |
35 #define JABBERPORT 5222 | |
36 #define JABBERSSLPORT 5223 | |
37 | |
194 | 38 #define JABBER_AGENT_GROUP "Jabber Agents" |
39 | |
29 | 40 jconn jc; |
311
1d6b16d9c577
Make some global variables static
Mikael Berthe <mikael@lilotux.net>
parents:
300
diff
changeset
|
41 static time_t LastPingTime; |
1d6b16d9c577
Make some global variables static
Mikael Berthe <mikael@lilotux.net>
parents:
300
diff
changeset
|
42 static unsigned int KeepaliveDelay; |
298
35cda94e570d
Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents:
294
diff
changeset
|
43 static int s_id; |
31 | 44 static int regmode, regdone; |
116 | 45 static enum imstatus mystatus = offline; |
519
5c338d31de56
Show current global status message in "/status"
Mikael Berthe <mikael@lilotux.net>
parents:
513
diff
changeset
|
46 static gchar *mystatusmsg; |
472
75442262c082
Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents:
470
diff
changeset
|
47 static unsigned char online; |
29 | 48 |
353
3fe43f6daa5a
Make imstatus2char a null-terminated string
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
49 char imstatus2char[imstatus_size+1] = { |
3fe43f6daa5a
Make imstatus2char a null-terminated string
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
50 '_', 'o', 'i', 'f', 'd', 'n', 'a', '\0' |
46 | 51 }; |
52 | |
31 | 53 static enum { |
29 | 54 STATE_CONNECTING, |
55 STATE_GETAUTH, | |
56 STATE_SENDAUTH, | |
57 STATE_LOGGED | |
58 } jstate; | |
59 | |
532
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
531
diff
changeset
|
60 struct T_presence { |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
531
diff
changeset
|
61 enum imstatus st; |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
531
diff
changeset
|
62 const char *msg; |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
531
diff
changeset
|
63 }; |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
531
diff
changeset
|
64 |
29 | 65 |
533
c478e8f7f074
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
532
diff
changeset
|
66 static void statehandler(jconn, int); |
c478e8f7f074
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
532
diff
changeset
|
67 static void packethandler(jconn, jpacket); |
31 | 68 |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
69 static void logger(jconn j, int io, const char *buf) |
31 | 70 { |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
71 scr_LogPrint(LPRINT_DEBUG, "%03s: %s", ((io == 0) ? "OUT" : "IN"), buf); |
31 | 72 } |
73 | |
113 | 74 /* |
29 | 75 static void jidsplit(const char *jid, char **user, char **host, |
76 char **res) | |
77 { | |
78 char *tmp, *ptr; | |
79 tmp = strdup(jid); | |
80 | |
81 if ((ptr = strchr(tmp, '/')) != NULL) { | |
82 *res = strdup(ptr+1); | |
83 *ptr = 0; | |
84 } else | |
85 *res = NULL; | |
86 | |
87 if ((ptr = strchr(tmp, '@')) != NULL) { | |
88 *host = strdup(ptr+1); | |
89 *ptr = 0; | |
90 } else | |
91 *host = NULL; | |
92 | |
93 *user = strdup(tmp); | |
94 free(tmp); | |
95 } | |
113 | 96 */ |
29 | 97 |
192 | 98 // jidtodisp(jid) |
99 // Strips the resource part from the jid | |
100 // The caller should g_free the result after use. | |
533
c478e8f7f074
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
532
diff
changeset
|
101 static char *jidtodisp(const char *jid) |
29 | 102 { |
103 char *ptr; | |
165 | 104 char *alias; |
105 | |
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
436
diff
changeset
|
106 alias = g_strdup(jid); |
165 | 107 |
29 | 108 if ((ptr = strchr(alias, '/')) != NULL) { |
109 *ptr = 0; | |
110 } | |
111 return alias; | |
112 } | |
113 | |
298
35cda94e570d
Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents:
294
diff
changeset
|
114 char *compose_jid(const char *username, const char *servername, |
533
c478e8f7f074
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
532
diff
changeset
|
115 const char *resource) |
298
35cda94e570d
Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents:
294
diff
changeset
|
116 { |
393 | 117 char *jid = g_new(char, 3 + |
118 strlen(username) + strlen(servername) + strlen(resource)); | |
298
35cda94e570d
Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents:
294
diff
changeset
|
119 strcpy(jid, username); |
403
17aa60c6dc63
Allow a different server name than the jid domain name
Mikael Berthe <mikael@lilotux.net>
parents:
393
diff
changeset
|
120 if (!strchr(jid, '@')) { |
17aa60c6dc63
Allow a different server name than the jid domain name
Mikael Berthe <mikael@lilotux.net>
parents:
393
diff
changeset
|
121 strcat(jid, "@"); |
17aa60c6dc63
Allow a different server name than the jid domain name
Mikael Berthe <mikael@lilotux.net>
parents:
393
diff
changeset
|
122 strcat(jid, servername); |
17aa60c6dc63
Allow a different server name than the jid domain name
Mikael Berthe <mikael@lilotux.net>
parents:
393
diff
changeset
|
123 } |
298
35cda94e570d
Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents:
294
diff
changeset
|
124 strcat(jid, "/"); |
35cda94e570d
Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents:
294
diff
changeset
|
125 strcat(jid, resource); |
35cda94e570d
Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents:
294
diff
changeset
|
126 return jid; |
35cda94e570d
Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents:
294
diff
changeset
|
127 } |
35cda94e570d
Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents:
294
diff
changeset
|
128 |
472
75442262c082
Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents:
470
diff
changeset
|
129 inline unsigned char jb_getonline(void) |
75442262c082
Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents:
470
diff
changeset
|
130 { |
75442262c082
Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents:
470
diff
changeset
|
131 return online; |
75442262c082
Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents:
470
diff
changeset
|
132 } |
75442262c082
Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents:
470
diff
changeset
|
133 |
403
17aa60c6dc63
Allow a different server name than the jid domain name
Mikael Berthe <mikael@lilotux.net>
parents:
393
diff
changeset
|
134 jconn jb_connect(const char *jid, const char *server, unsigned int port, |
17aa60c6dc63
Allow a different server name than the jid domain name
Mikael Berthe <mikael@lilotux.net>
parents:
393
diff
changeset
|
135 int ssl, const char *pass) |
29 | 136 { |
469
a926523d2392
Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
468
diff
changeset
|
137 char *utf8_jid; |
29 | 138 if (!port) { |
139 if (ssl) | |
140 port = JABBERSSLPORT; | |
141 else | |
142 port = JABBERPORT; | |
143 } | |
144 | |
357
e8adc3c96e68
Better messages for server connection states
Mikael Berthe <mikael@lilotux.net>
parents:
353
diff
changeset
|
145 jb_disconnect(); |
29 | 146 |
469
a926523d2392
Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
468
diff
changeset
|
147 utf8_jid = to_utf8(jid); |
a926523d2392
Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
468
diff
changeset
|
148 if (!utf8_jid) return jc; |
a926523d2392
Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
468
diff
changeset
|
149 |
298
35cda94e570d
Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents:
294
diff
changeset
|
150 s_id = 1; |
469
a926523d2392
Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
468
diff
changeset
|
151 jc = jab_new(utf8_jid, (char*)pass, (char*)server, port, ssl); |
a926523d2392
Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
468
diff
changeset
|
152 g_free(utf8_jid); |
29 | 153 |
298
35cda94e570d
Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents:
294
diff
changeset
|
154 /* These 3 functions can deal with a NULL jc, no worry... */ |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
155 jab_logger(jc, logger); |
29 | 156 jab_packet_handler(jc, &packethandler); |
157 jab_state_handler(jc, &statehandler); | |
158 | |
298
35cda94e570d
Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents:
294
diff
changeset
|
159 if (jc && jc->user) { |
112 | 160 online = TRUE; |
29 | 161 jstate = STATE_CONNECTING; |
162 statehandler(0, -1); | |
163 jab_start(jc); | |
164 } | |
165 | |
166 return jc; | |
167 } | |
168 | |
169 void jb_disconnect(void) | |
170 { | |
298
35cda94e570d
Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents:
294
diff
changeset
|
171 if (!jc) return; |
35cda94e570d
Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents:
294
diff
changeset
|
172 |
416
48e7808c4191
Allow offline status message
Mikael Berthe <mikael@lilotux.net>
parents:
411
diff
changeset
|
173 // announce it to everyone else |
444 | 174 jb_setstatus(offline, NULL, ""); |
416
48e7808c4191
Allow offline status message
Mikael Berthe <mikael@lilotux.net>
parents:
411
diff
changeset
|
175 |
48e7808c4191
Allow offline status message
Mikael Berthe <mikael@lilotux.net>
parents:
411
diff
changeset
|
176 // announce it to the user |
29 | 177 statehandler(jc, JCONN_STATE_OFF); |
416
48e7808c4191
Allow offline status message
Mikael Berthe <mikael@lilotux.net>
parents:
411
diff
changeset
|
178 |
298
35cda94e570d
Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents:
294
diff
changeset
|
179 jab_delete(jc); |
35cda94e570d
Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents:
294
diff
changeset
|
180 //free(jc); XXX |
35cda94e570d
Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents:
294
diff
changeset
|
181 jc = NULL; |
29 | 182 } |
183 | |
112 | 184 inline void jb_reset_keepalive() |
185 { | |
186 time(&LastPingTime); | |
187 } | |
188 | |
436 | 189 void jb_send_raw(const char *str) |
190 { | |
461
1d8f5b3a5f2b
Convert /rawxml argument to UTF8
Mikael Berthe <mikael@lilotux.net>
parents:
449
diff
changeset
|
191 if (jc && online && str) |
436 | 192 jab_send_raw(jc, str); |
193 } | |
194 | |
29 | 195 void jb_keepalive() |
196 { | |
113 | 197 if (jc && online) |
112 | 198 jab_send_raw(jc, " \t "); |
199 jb_reset_keepalive(); | |
200 } | |
201 | |
202 void jb_set_keepalive_delay(unsigned int delay) | |
203 { | |
204 KeepaliveDelay = delay; | |
29 | 205 } |
206 | |
207 void jb_main() | |
208 { | |
209 xmlnode x, z; | |
210 char *cid; | |
211 | |
406 | 212 if (!online) { |
419 | 213 safe_usleep(10000); |
406 | 214 return; |
215 } | |
164 | 216 |
29 | 217 if (jc && jc->state == JCONN_STATE_CONNECTING) { |
419 | 218 safe_usleep(75000); |
29 | 219 jab_start(jc); |
220 return; | |
221 } | |
222 | |
31 | 223 jab_poll(jc, 50); |
29 | 224 |
225 if (jstate == STATE_CONNECTING) { | |
226 if (jc) { | |
227 x = jutil_iqnew(JPACKET__GET, NS_AUTH); | |
228 cid = jab_getid(jc); | |
229 xmlnode_put_attrib(x, "id", cid); | |
230 // id = atoi(cid); | |
231 | |
232 z = xmlnode_insert_tag(xmlnode_get_tag(x, "query"), "username"); | |
233 xmlnode_insert_cdata(z, jc->user->user, (unsigned) -1); | |
234 jab_send(jc, x); | |
235 xmlnode_free(x); | |
236 | |
237 jstate = STATE_GETAUTH; | |
238 } | |
239 | |
240 if (!jc || jc->state == JCONN_STATE_OFF) { | |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
241 scr_LogPrint(LPRINT_LOGNORM, "Unable to connect to the server"); |
112 | 242 online = FALSE; |
29 | 243 } |
244 } | |
245 | |
246 if (!jc) { | |
247 statehandler(jc, JCONN_STATE_OFF); | |
248 } else if (jc->state == JCONN_STATE_OFF || jc->fd == -1) { | |
249 statehandler(jc, JCONN_STATE_OFF); | |
250 } | |
112 | 251 |
252 // Keepalive | |
253 if (KeepaliveDelay) { | |
254 time_t now; | |
255 time(&now); | |
256 if (now > LastPingTime + KeepaliveDelay) | |
257 jb_keepalive(); | |
258 } | |
29 | 259 } |
260 | |
116 | 261 inline enum imstatus jb_getstatus() |
262 { | |
263 return mystatus; | |
264 } | |
265 | |
519
5c338d31de56
Show current global status message in "/status"
Mikael Berthe <mikael@lilotux.net>
parents:
513
diff
changeset
|
266 inline const char *jb_getstatusmsg() |
5c338d31de56
Show current global status message in "/status"
Mikael Berthe <mikael@lilotux.net>
parents:
513
diff
changeset
|
267 { |
5c338d31de56
Show current global status message in "/status"
Mikael Berthe <mikael@lilotux.net>
parents:
513
diff
changeset
|
268 return mystatusmsg; |
5c338d31de56
Show current global status message in "/status"
Mikael Berthe <mikael@lilotux.net>
parents:
513
diff
changeset
|
269 } |
5c338d31de56
Show current global status message in "/status"
Mikael Berthe <mikael@lilotux.net>
parents:
513
diff
changeset
|
270 |
532
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
531
diff
changeset
|
271 static void roompresence(gpointer room, void *presencedata) |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
531
diff
changeset
|
272 { |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
531
diff
changeset
|
273 const char *jid; |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
531
diff
changeset
|
274 const char *nickname; |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
531
diff
changeset
|
275 char *to; |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
531
diff
changeset
|
276 struct T_presence *pres = presencedata; |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
531
diff
changeset
|
277 |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
531
diff
changeset
|
278 if (!buddy_getresources(room)) // FIXME: that's a memory leak |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
531
diff
changeset
|
279 return; |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
531
diff
changeset
|
280 |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
531
diff
changeset
|
281 jid = buddy_getjid(room); |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
531
diff
changeset
|
282 if (!jid) return; |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
531
diff
changeset
|
283 nickname = buddy_getnickname(room); |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
531
diff
changeset
|
284 if (!nickname) return; |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
531
diff
changeset
|
285 |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
531
diff
changeset
|
286 to = g_strdup_printf("%s/%s", jid, nickname); |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
531
diff
changeset
|
287 jb_setstatus(pres->st, to, pres->msg); |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
531
diff
changeset
|
288 g_free(to); |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
531
diff
changeset
|
289 } |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
531
diff
changeset
|
290 |
534 | 291 // presnew(status, recipient, message) |
292 // Create an xmlnode with default presence attributes | |
293 // Note: the caller must free the node after use | |
294 static xmlnode presnew(enum imstatus st, const char *recipient, | |
295 const char *msg) | |
29 | 296 { |
534 | 297 unsigned int prio; |
116 | 298 xmlnode x; |
299 | |
300 x = jutil_presnew(JPACKET__UNKNOWN, 0, 0); | |
29 | 301 |
444 | 302 if (recipient) |
303 xmlnode_put_attrib(x, "to", recipient); | |
304 | |
29 | 305 switch(st) { |
306 case away: | |
307 xmlnode_insert_cdata(xmlnode_insert_tag(x, "show"), "away", | |
308 (unsigned) -1); | |
309 break; | |
310 | |
311 case dontdisturb: | |
312 xmlnode_insert_cdata(xmlnode_insert_tag(x, "show"), "dnd", | |
313 (unsigned) -1); | |
314 break; | |
315 | |
316 case freeforchat: | |
317 xmlnode_insert_cdata(xmlnode_insert_tag(x, "show"), "chat", | |
318 (unsigned) -1); | |
319 break; | |
320 | |
321 case notavail: | |
322 xmlnode_insert_cdata(xmlnode_insert_tag(x, "show"), "xa", | |
323 (unsigned) -1); | |
324 break; | |
325 | |
326 case invisible: | |
327 xmlnode_put_attrib(x, "type", "invisible"); | |
328 break; | |
51 | 329 |
118 | 330 case offline: |
331 xmlnode_put_attrib(x, "type", "unavailable"); | |
332 break; | |
333 | |
51 | 334 default: |
335 break; | |
29 | 336 } |
337 | |
531
aee9a279a0f3
Allow changing priority on the fly
Mikael Berthe <mikael@lilotux.net>
parents:
527
diff
changeset
|
338 prio = settings_opt_get_int("priority"); |
272 | 339 if (prio) { |
340 char strprio[8]; | |
341 snprintf(strprio, 8, "%u", prio); | |
29 | 342 xmlnode_insert_cdata(xmlnode_insert_tag(x, "priority"), |
534 | 343 strprio, (unsigned) -1); |
344 } | |
345 | |
346 if (msg) { | |
347 gchar *utf8_msg = to_utf8(msg); | |
348 xmlnode_insert_cdata(xmlnode_insert_tag(x, "status"), utf8_msg, | |
349 (unsigned) -1); | |
350 g_free(utf8_msg); | |
272 | 351 } |
29 | 352 |
534 | 353 return x; |
354 } | |
355 | |
356 void jb_setstatus(enum imstatus st, const char *recipient, const char *msg) | |
357 { | |
358 xmlnode x; | |
359 struct T_presence room_presence; | |
360 | |
361 if (!online) return; | |
362 | |
521 | 363 if (msg) { |
364 // The status message has been specified. We'll use it, unless it is | |
365 // "-" which is a special case (option meaning "no status message"). | |
366 if (!strcmp(msg, "-")) | |
367 msg = ""; | |
368 } else { | |
369 // No status message specified; we'll use: | |
370 // a) the default status message (if provided by the user); | |
371 // b) the current status message; | |
372 // c) no status message (i.e. an empty one). | |
373 msg = settings_get_status_msg(st); | |
374 if (!msg) { | |
375 if (mystatusmsg) | |
376 msg = mystatusmsg; | |
377 else | |
378 msg = ""; | |
379 } | |
380 } | |
29 | 381 |
534 | 382 x = presnew(st, recipient, msg); |
29 | 383 jab_send(jc, x); |
384 xmlnode_free(x); | |
385 | |
444 | 386 // If we didn't change our _global_ status, we are done |
387 if (recipient) return; | |
388 | |
532
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
531
diff
changeset
|
389 // Send presence to chatrooms |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
531
diff
changeset
|
390 if (st != invisible) { |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
531
diff
changeset
|
391 room_presence.st = st; |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
531
diff
changeset
|
392 room_presence.msg = msg; |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
531
diff
changeset
|
393 foreach_buddy(ROSTER_TYPE_ROOM, &roompresence, &room_presence); |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
531
diff
changeset
|
394 } |
29 | 395 |
164 | 396 // We'll need to update the roster if we switch to/from offline because |
397 // we don't know the presences of buddies when offline... | |
398 if (mystatus == offline || st == offline) | |
399 update_roster = TRUE; | |
400 | |
318
45076d02eeef
The /status command can specify a status message
Mikael Berthe <mikael@lilotux.net>
parents:
311
diff
changeset
|
401 hk_mystatuschange(0, mystatus, st, msg); |
116 | 402 mystatus = st; |
521 | 403 if (msg != mystatusmsg) { |
404 if (mystatusmsg) | |
405 g_free(mystatusmsg); | |
406 if (*msg) | |
407 mystatusmsg = g_strdup(msg); | |
408 else | |
409 mystatusmsg = NULL; | |
410 } | |
29 | 411 } |
412 | |
475
fa49ac0bb8f3
Add "/room topic", and display topic changes
Mikael Berthe <mikael@lilotux.net>
parents:
474
diff
changeset
|
413 void jb_send_msg(const char *jid, const char *text, int type, |
fa49ac0bb8f3
Add "/room topic", and display topic changes
Mikael Berthe <mikael@lilotux.net>
parents:
474
diff
changeset
|
414 const char *subject) |
35 | 415 { |
475
fa49ac0bb8f3
Add "/room topic", and display topic changes
Mikael Berthe <mikael@lilotux.net>
parents:
474
diff
changeset
|
416 xmlnode x; |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
417 gchar *strtype; |
387
2bbeef7b4fdd
Do non UTF8-encode/decode null pointers
Mikael Berthe <mikael@lilotux.net>
parents:
384
diff
changeset
|
418 gchar *buffer = to_utf8(text); |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
419 |
472
75442262c082
Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents:
470
diff
changeset
|
420 if (!online) return; |
75442262c082
Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents:
470
diff
changeset
|
421 |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
422 if (type == ROSTER_TYPE_ROOM) |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
423 strtype = TMSG_GROUPCHAT; |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
424 else |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
425 strtype = TMSG_CHAT; |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
426 |
486 | 427 x = jutil_msgnew(strtype, (char*)jid, NULL, (char*)buffer); |
475
fa49ac0bb8f3
Add "/room topic", and display topic changes
Mikael Berthe <mikael@lilotux.net>
parents:
474
diff
changeset
|
428 if (subject) { |
fa49ac0bb8f3
Add "/room topic", and display topic changes
Mikael Berthe <mikael@lilotux.net>
parents:
474
diff
changeset
|
429 xmlnode y; |
fa49ac0bb8f3
Add "/room topic", and display topic changes
Mikael Berthe <mikael@lilotux.net>
parents:
474
diff
changeset
|
430 char *bs = to_utf8(subject); |
fa49ac0bb8f3
Add "/room topic", and display topic changes
Mikael Berthe <mikael@lilotux.net>
parents:
474
diff
changeset
|
431 y = xmlnode_insert_tag(x, "subject"); |
fa49ac0bb8f3
Add "/room topic", and display topic changes
Mikael Berthe <mikael@lilotux.net>
parents:
474
diff
changeset
|
432 xmlnode_insert_cdata(y, bs, (unsigned) -1); |
fa49ac0bb8f3
Add "/room topic", and display topic changes
Mikael Berthe <mikael@lilotux.net>
parents:
474
diff
changeset
|
433 if (bs) g_free(bs); |
fa49ac0bb8f3
Add "/room topic", and display topic changes
Mikael Berthe <mikael@lilotux.net>
parents:
474
diff
changeset
|
434 } |
35 | 435 jab_send(jc, x); |
436 xmlnode_free(x); | |
383
39c5da51b387
Remove utf8 files, use Glib
Mikael Berthe <mikael@lilotux.net>
parents:
374
diff
changeset
|
437 g_free(buffer); |
114 | 438 jb_reset_keepalive(); |
35 | 439 } |
440 | |
213 | 441 // Note: the caller should check the jid is correct |
244 | 442 void jb_addbuddy(const char *jid, const char *name, const char *group) |
124 | 443 { |
444 xmlnode x, y, z; | |
192 | 445 char *cleanjid; |
124 | 446 |
208 | 447 if (!online) return; |
124 | 448 |
449 // We don't check if the jabber user already exists in the roster, | |
450 // because it allows to re-ask for notification. | |
451 | |
452 //x = jutil_presnew(JPACKET__SUBSCRIBE, jid, NULL); | |
125 | 453 x = jutil_presnew(JPACKET__SUBSCRIBE, (char*)jid, "online"); |
124 | 454 jab_send(jc, x); |
455 xmlnode_free(x); | |
456 | |
457 x = jutil_iqnew(JPACKET__SET, NS_ROSTER); | |
458 y = xmlnode_get_tag(x, "query"); | |
459 z = xmlnode_insert_tag(y, "item"); | |
460 xmlnode_put_attrib(z, "jid", jid); | |
461 | |
244 | 462 if (name) { |
387
2bbeef7b4fdd
Do non UTF8-encode/decode null pointers
Mikael Berthe <mikael@lilotux.net>
parents:
384
diff
changeset
|
463 gchar *name_utf8 = to_utf8(name); |
244 | 464 z = xmlnode_insert_tag(z, "name"); |
465 xmlnode_insert_cdata(z, name_utf8, (unsigned) -1); | |
383
39c5da51b387
Remove utf8 files, use Glib
Mikael Berthe <mikael@lilotux.net>
parents:
374
diff
changeset
|
466 g_free(name_utf8); |
244 | 467 } |
468 | |
124 | 469 if (group) { |
387
2bbeef7b4fdd
Do non UTF8-encode/decode null pointers
Mikael Berthe <mikael@lilotux.net>
parents:
384
diff
changeset
|
470 char *group_utf8 = to_utf8(group); |
124 | 471 z = xmlnode_insert_tag(z, "group"); |
213 | 472 xmlnode_insert_cdata(z, group_utf8, (unsigned) -1); |
383
39c5da51b387
Remove utf8 files, use Glib
Mikael Berthe <mikael@lilotux.net>
parents:
374
diff
changeset
|
473 g_free(group_utf8); |
124 | 474 } |
475 | |
476 jab_send(jc, x); | |
477 xmlnode_free(x); | |
478 | |
192 | 479 cleanjid = jidtodisp(jid); |
244 | 480 roster_add_user(cleanjid, name, group, ROSTER_TYPE_USER); |
192 | 481 g_free(cleanjid); |
124 | 482 buddylist_build(); |
483 | |
244 | 484 update_roster = TRUE; |
124 | 485 } |
486 | |
205 | 487 void jb_delbuddy(const char *jid) |
488 { | |
489 xmlnode x, y, z; | |
490 char *cleanjid; | |
491 | |
492 if (!online) return; | |
493 | |
494 cleanjid = jidtodisp(jid); | |
495 | |
496 // If the current buddy is an agent, unsubscribe from it | |
497 if (roster_gettype(cleanjid) == ROSTER_TYPE_AGENT) { | |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
498 scr_LogPrint(LPRINT_LOGNORM, "Unregistering from the %s agent", cleanjid); |
205 | 499 |
500 x = jutil_iqnew(JPACKET__SET, NS_REGISTER); | |
501 xmlnode_put_attrib(x, "to", cleanjid); | |
502 y = xmlnode_get_tag(x, "query"); | |
503 xmlnode_insert_tag(y, "remove"); | |
504 jab_send(jc, x); | |
505 xmlnode_free(x); | |
506 } | |
507 | |
508 // Unsubscribe this buddy from our presence notification | |
509 x = jutil_presnew(JPACKET__UNSUBSCRIBE, cleanjid, 0); | |
510 jab_send(jc, x); | |
511 xmlnode_free(x); | |
512 | |
513 // Ask for removal from roster | |
514 x = jutil_iqnew(JPACKET__SET, NS_ROSTER); | |
515 y = xmlnode_get_tag(x, "query"); | |
516 z = xmlnode_insert_tag(y, "item"); | |
517 xmlnode_put_attrib(z, "jid", cleanjid); | |
518 xmlnode_put_attrib(z, "subscription", "remove"); | |
519 jab_send(jc, x); | |
520 xmlnode_free(x); | |
521 | |
522 roster_del_user(cleanjid); | |
523 g_free(cleanjid); | |
524 buddylist_build(); | |
525 | |
526 update_roster = TRUE; | |
527 } | |
528 | |
208 | 529 void jb_updatebuddy(const char *jid, const char *name, const char *group) |
530 { | |
531 xmlnode x, y; | |
532 char *cleanjid; | |
383
39c5da51b387
Remove utf8 files, use Glib
Mikael Berthe <mikael@lilotux.net>
parents:
374
diff
changeset
|
533 gchar *name_utf8; |
208 | 534 |
535 if (!online) return; | |
536 | |
537 // XXX We should check name's and group's correctness | |
538 | |
539 cleanjid = jidtodisp(jid); | |
387
2bbeef7b4fdd
Do non UTF8-encode/decode null pointers
Mikael Berthe <mikael@lilotux.net>
parents:
384
diff
changeset
|
540 name_utf8 = to_utf8(name); |
208 | 541 |
542 x = jutil_iqnew(JPACKET__SET, NS_ROSTER); | |
543 y = xmlnode_insert_tag(xmlnode_get_tag(x, "query"), "item"); | |
544 xmlnode_put_attrib(y, "jid", cleanjid); | |
213 | 545 xmlnode_put_attrib(y, "name", name_utf8); |
208 | 546 |
547 if (group) { | |
387
2bbeef7b4fdd
Do non UTF8-encode/decode null pointers
Mikael Berthe <mikael@lilotux.net>
parents:
384
diff
changeset
|
548 gchar *group_utf8 = to_utf8(group); |
208 | 549 y = xmlnode_insert_tag(y, "group"); |
213 | 550 xmlnode_insert_cdata(y, group_utf8, (unsigned) -1); |
383
39c5da51b387
Remove utf8 files, use Glib
Mikael Berthe <mikael@lilotux.net>
parents:
374
diff
changeset
|
551 g_free(group_utf8); |
208 | 552 } |
553 | |
554 jab_send(jc, x); | |
555 xmlnode_free(x); | |
383
39c5da51b387
Remove utf8 files, use Glib
Mikael Berthe <mikael@lilotux.net>
parents:
374
diff
changeset
|
556 g_free(name_utf8); |
208 | 557 g_free(cleanjid); |
558 } | |
559 | |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
560 // Join a MUC room |
469
a926523d2392
Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
468
diff
changeset
|
561 void jb_room_join(const char *room, const char *nickname) |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
562 { |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
563 xmlnode x, y; |
469
a926523d2392
Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
468
diff
changeset
|
564 gchar *roomid, *utf8_nickname; |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
565 |
472
75442262c082
Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents:
470
diff
changeset
|
566 if (!online || !room) return; |
75442262c082
Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents:
470
diff
changeset
|
567 if (!nickname) return; |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
568 |
469
a926523d2392
Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
468
diff
changeset
|
569 utf8_nickname = to_utf8(nickname); |
a926523d2392
Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
468
diff
changeset
|
570 roomid = g_strdup_printf("%s/%s", room, utf8_nickname); |
a926523d2392
Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
468
diff
changeset
|
571 g_free(utf8_nickname); |
a926523d2392
Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
468
diff
changeset
|
572 if (check_jid_syntax(roomid)) { |
a926523d2392
Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
468
diff
changeset
|
573 scr_LogPrint(LPRINT_NORMAL, "<%s/%s> is not a valid Jabber room", room, |
a926523d2392
Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
468
diff
changeset
|
574 nickname); |
a926523d2392
Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
468
diff
changeset
|
575 g_free(roomid); |
a926523d2392
Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
468
diff
changeset
|
576 return; |
a926523d2392
Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
468
diff
changeset
|
577 } |
a926523d2392
Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
468
diff
changeset
|
578 |
a926523d2392
Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
468
diff
changeset
|
579 // Send the XML request |
535
b407d19c39ab
Set status correctly when joining a room
Mikael Berthe <mikael@lilotux.net>
parents:
534
diff
changeset
|
580 x = presnew(mystatus, roomid, mystatusmsg); |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
581 y = xmlnode_insert_tag(x, "x"); |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
582 xmlnode_put_attrib(y, "xmlns", "http://jabber.org/protocol/muc"); |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
583 |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
584 jab_send(jc, x); |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
585 xmlnode_free(x); |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
586 jb_reset_keepalive(); |
469
a926523d2392
Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
468
diff
changeset
|
587 g_free(roomid); |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
588 } |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
589 |
449 | 590 // Unlock a MUC room |
591 // room syntax: "room@server" | |
592 void jb_room_unlock(const char *room) | |
593 { | |
594 xmlnode x, y, z; | |
595 | |
472
75442262c082
Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents:
470
diff
changeset
|
596 if (!online || !room) return; |
449 | 597 |
598 x = jutil_iqnew(JPACKET__SET, "http://jabber.org/protocol/muc#owner"); | |
599 xmlnode_put_attrib(x, "id", "unlock1"); // XXX | |
600 xmlnode_put_attrib(x, "to", room); | |
601 y = xmlnode_get_tag(x, "query"); | |
602 z = xmlnode_insert_tag(y, "x"); | |
603 xmlnode_put_attrib(z, "xmlns", "jabber:x:data"); | |
604 xmlnode_put_attrib(z, "type", "submit"); | |
605 | |
606 jab_send(jc, x); | |
607 xmlnode_free(x); | |
608 jb_reset_keepalive(); | |
609 } | |
610 | |
486 | 611 |
612 // Invite a user to a MUC room | |
613 // room syntax: "room@server" | |
614 // reason can be null. | |
615 void jb_room_invite(const char *room, const char *jid, const char *reason) | |
616 { | |
617 xmlnode x, y, z; | |
618 gchar *utf8_reason; | |
619 | |
620 if (!online || !room || !jid) return; | |
621 | |
622 if (!reason) reason = ""; | |
623 | |
624 x = jutil_msgnew(NULL, (char*)room, NULL, NULL); | |
625 | |
626 y = xmlnode_insert_tag(x, "x"); | |
627 xmlnode_put_attrib(y, "xmlns", "http://jabber.org/protocol/muc#user"); | |
628 | |
629 z = xmlnode_insert_tag(y, "invite"); | |
630 xmlnode_put_attrib(z, "to", jid); | |
631 | |
632 utf8_reason = to_utf8(reason); | |
633 y = xmlnode_insert_tag(z, "reason"); | |
634 xmlnode_insert_cdata(y, utf8_reason, (unsigned) -1); | |
635 g_free(utf8_reason); | |
636 | |
637 jab_send(jc, x); | |
638 xmlnode_free(x); | |
639 jb_reset_keepalive(); | |
640 } | |
641 | |
533
c478e8f7f074
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
532
diff
changeset
|
642 static void postlogin() |
31 | 643 { |
644 //int i; | |
645 | |
646 //flogged = TRUE; | |
647 //ourstatus = available; | |
648 | |
649 //setautostatus(jhook.manualstatus); | |
650 | |
444 | 651 jb_setstatus(available, NULL, NULL); |
81 | 652 buddylist_build(); |
31 | 653 /* |
654 for (i = 0; i < clist.count; i++) { | |
655 c = (icqcontact *) clist.at(i); | |
656 | |
657 if (c->getdesc().pname == proto) | |
658 if (ischannel(c)) | |
659 if (c->getbasicinfo().requiresauth) | |
660 c->setstatus(available); | |
661 } | |
662 */ | |
663 | |
664 /* | |
665 agents.insert(agents.begin(), agent("vcard", "Jabber VCard", "", agent::atStandard)); | |
666 agents.begin()->params[agent::ptRegister].enabled = TRUE; | |
667 | |
668 string buf; | |
669 ifstream f(conf.getconfigfname("jabber-infoset").c_str()); | |
670 | |
671 if (f.is_open()) { | |
672 icqcontact *c = clist.get(contactroot); | |
673 | |
674 c->clear(); | |
675 icqcontact::basicinfo bi = c->getbasicinfo(); | |
676 icqcontact::reginfo ri = c->getreginfo(); | |
677 | |
678 ri.service = agents.begin()->name; | |
679 getstring(f, buf); c->setnick(buf); | |
680 getstring(f, buf); bi.email = buf; | |
681 getstring(f, buf); bi.fname = buf; | |
682 getstring(f, buf); bi.lname = buf; | |
683 f.close(); | |
684 | |
685 c->setbasicinfo(bi); | |
686 c->setreginfo(ri); | |
687 | |
688 sendupdateuserinfo(*c); | |
689 unlink(conf.getconfigfname("jabber-infoset").c_str()); | |
690 } | |
691 */ | |
692 } | |
693 | |
533
c478e8f7f074
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
532
diff
changeset
|
694 static void gotloggedin(void) |
29 | 695 { |
696 xmlnode x; | |
697 | |
698 x = jutil_iqnew(JPACKET__GET, NS_AGENTS); | |
699 xmlnode_put_attrib(x, "id", "Agent List"); | |
700 jab_send(jc, x); | |
701 xmlnode_free(x); | |
702 | |
703 x = jutil_iqnew(JPACKET__GET, NS_ROSTER); | |
704 xmlnode_put_attrib(x, "id", "Roster"); | |
705 jab_send(jc, x); | |
706 xmlnode_free(x); | |
707 } | |
708 | |
533
c478e8f7f074
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
532
diff
changeset
|
709 static void gotroster(xmlnode x) |
29 | 710 { |
33 | 711 xmlnode y, z; |
29 | 712 |
713 for (y = xmlnode_get_tag(x, "item"); y; y = xmlnode_get_nextsibling(y)) { | |
714 const char *alias = xmlnode_get_attrib(y, "jid"); | |
51 | 715 //const char *sub = xmlnode_get_attrib(y, "subscription"); // TODO Not used |
29 | 716 const char *name = xmlnode_get_attrib(y, "name"); |
213 | 717 char *group = NULL; |
29 | 718 |
33 | 719 z = xmlnode_get_tag(y, "group"); |
720 if (z) group = xmlnode_get_data(z); | |
29 | 721 |
722 if (alias) { | |
35 | 723 char *buddyname; |
192 | 724 char *cleanalias = jidtodisp(alias); |
383
39c5da51b387
Remove utf8 files, use Glib
Mikael Berthe <mikael@lilotux.net>
parents:
374
diff
changeset
|
725 gchar *name_noutf8 = NULL; |
39c5da51b387
Remove utf8 files, use Glib
Mikael Berthe <mikael@lilotux.net>
parents:
374
diff
changeset
|
726 gchar *group_noutf8 = NULL; |
213 | 727 |
441
51b8f10cfeb8
Handle g_locale_from_utf8() failures
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
728 buddyname = cleanalias; |
213 | 729 if (name) { |
387
2bbeef7b4fdd
Do non UTF8-encode/decode null pointers
Mikael Berthe <mikael@lilotux.net>
parents:
384
diff
changeset
|
730 name_noutf8 = from_utf8(name); |
523
fc6bc26f891e
Write UTF-9 conversion failures to the tracelog file
Mikael Berthe <mikael@lilotux.net>
parents:
521
diff
changeset
|
731 if (name_noutf8) |
fc6bc26f891e
Write UTF-9 conversion failures to the tracelog file
Mikael Berthe <mikael@lilotux.net>
parents:
521
diff
changeset
|
732 buddyname = name_noutf8; |
fc6bc26f891e
Write UTF-9 conversion failures to the tracelog file
Mikael Berthe <mikael@lilotux.net>
parents:
521
diff
changeset
|
733 else |
fc6bc26f891e
Write UTF-9 conversion failures to the tracelog file
Mikael Berthe <mikael@lilotux.net>
parents:
521
diff
changeset
|
734 scr_LogPrint(LPRINT_LOG, "Decoding of buddy alias has failed: %s", |
fc6bc26f891e
Write UTF-9 conversion failures to the tracelog file
Mikael Berthe <mikael@lilotux.net>
parents:
521
diff
changeset
|
735 name); |
441
51b8f10cfeb8
Handle g_locale_from_utf8() failures
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
736 } |
35 | 737 |
523
fc6bc26f891e
Write UTF-9 conversion failures to the tracelog file
Mikael Berthe <mikael@lilotux.net>
parents:
521
diff
changeset
|
738 if (group) { |
387
2bbeef7b4fdd
Do non UTF8-encode/decode null pointers
Mikael Berthe <mikael@lilotux.net>
parents:
384
diff
changeset
|
739 group_noutf8 = from_utf8(group); |
523
fc6bc26f891e
Write UTF-9 conversion failures to the tracelog file
Mikael Berthe <mikael@lilotux.net>
parents:
521
diff
changeset
|
740 if (!group_noutf8) |
fc6bc26f891e
Write UTF-9 conversion failures to the tracelog file
Mikael Berthe <mikael@lilotux.net>
parents:
521
diff
changeset
|
741 scr_LogPrint(LPRINT_LOG, "Decoding of buddy group has failed: %s", |
fc6bc26f891e
Write UTF-9 conversion failures to the tracelog file
Mikael Berthe <mikael@lilotux.net>
parents:
521
diff
changeset
|
742 group); |
fc6bc26f891e
Write UTF-9 conversion failures to the tracelog file
Mikael Berthe <mikael@lilotux.net>
parents:
521
diff
changeset
|
743 } |
383
39c5da51b387
Remove utf8 files, use Glib
Mikael Berthe <mikael@lilotux.net>
parents:
374
diff
changeset
|
744 |
213 | 745 roster_add_user(cleanalias, buddyname, group_noutf8, ROSTER_TYPE_USER); |
383
39c5da51b387
Remove utf8 files, use Glib
Mikael Berthe <mikael@lilotux.net>
parents:
374
diff
changeset
|
746 if (name_noutf8) g_free(name_noutf8); |
39c5da51b387
Remove utf8 files, use Glib
Mikael Berthe <mikael@lilotux.net>
parents:
374
diff
changeset
|
747 if (group_noutf8) g_free(group_noutf8); |
192 | 748 g_free(cleanalias); |
29 | 749 } |
750 } | |
751 | |
752 postlogin(); | |
753 } | |
754 | |
533
c478e8f7f074
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
532
diff
changeset
|
755 static void gotmessage(char *type, const char *from, const char *body, |
c478e8f7f074
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
532
diff
changeset
|
756 const char *enc, time_t timestamp) |
29 | 757 { |
113 | 758 char *jid; |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
759 const char *rname; |
387
2bbeef7b4fdd
Do non UTF8-encode/decode null pointers
Mikael Berthe <mikael@lilotux.net>
parents:
384
diff
changeset
|
760 gchar *buffer = from_utf8(body); |
29 | 761 |
441
51b8f10cfeb8
Handle g_locale_from_utf8() failures
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
762 jid = jidtodisp(from); |
51b8f10cfeb8
Handle g_locale_from_utf8() failures
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
763 |
51b8f10cfeb8
Handle g_locale_from_utf8() failures
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
764 if (!buffer && body) { |
523
fc6bc26f891e
Write UTF-9 conversion failures to the tracelog file
Mikael Berthe <mikael@lilotux.net>
parents:
521
diff
changeset
|
765 scr_LogPrint(LPRINT_NORMAL, "Decoding of message from <%s> has failed", |
441
51b8f10cfeb8
Handle g_locale_from_utf8() failures
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
766 from); |
523
fc6bc26f891e
Write UTF-9 conversion failures to the tracelog file
Mikael Berthe <mikael@lilotux.net>
parents:
521
diff
changeset
|
767 scr_LogPrint(LPRINT_LOG, "Decoding of message from <%s> has failed: %s", |
fc6bc26f891e
Write UTF-9 conversion failures to the tracelog file
Mikael Berthe <mikael@lilotux.net>
parents:
521
diff
changeset
|
768 from, body); |
441
51b8f10cfeb8
Handle g_locale_from_utf8() failures
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
769 scr_WriteIncomingMessage(jid, "Cannot display message: " |
51b8f10cfeb8
Handle g_locale_from_utf8() failures
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
770 "UTF-8 conversion failure", |
51b8f10cfeb8
Handle g_locale_from_utf8() failures
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
771 0, HBB_PREFIX_ERR | HBB_PREFIX_IN); |
51b8f10cfeb8
Handle g_locale_from_utf8() failures
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
772 g_free(jid); |
51b8f10cfeb8
Handle g_locale_from_utf8() failures
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
773 return; |
51b8f10cfeb8
Handle g_locale_from_utf8() failures
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
774 } |
51b8f10cfeb8
Handle g_locale_from_utf8() failures
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
775 |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
776 rname = strchr(from, '/'); |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
777 if (rname) rname++; |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
778 hk_message_in(jid, rname, timestamp, buffer, type); |
192 | 779 g_free(jid); |
383
39c5da51b387
Remove utf8 files, use Glib
Mikael Berthe <mikael@lilotux.net>
parents:
374
diff
changeset
|
780 g_free(buffer); |
29 | 781 } |
782 | |
533
c478e8f7f074
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
532
diff
changeset
|
783 static const char *defaulterrormsg(int code) |
420
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
784 { |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
785 const char *desc; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
786 |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
787 switch(code) { |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
788 case 401: desc = "Unauthorized"; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
789 break; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
790 case 302: desc = "Redirect"; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
791 break; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
792 case 400: desc = "Bad request"; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
793 break; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
794 case 402: desc = "Payment Required"; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
795 break; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
796 case 403: desc = "Forbidden"; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
797 break; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
798 case 404: desc = "Not Found"; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
799 break; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
800 case 405: desc = "Not Allowed"; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
801 break; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
802 case 406: desc = "Not Acceptable"; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
803 break; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
804 case 407: desc = "Registration Required"; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
805 break; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
806 case 408: desc = "Request Timeout"; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
807 break; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
808 case 409: desc = "Conflict"; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
809 break; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
810 case 500: desc = "Internal Server Error"; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
811 break; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
812 case 501: desc = "Not Implemented"; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
813 break; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
814 case 502: desc = "Remote Server Error"; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
815 break; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
816 case 503: desc = "Service Unavailable"; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
817 break; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
818 case 504: desc = "Remote Server Timeout"; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
819 break; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
820 default: |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
821 desc = NULL; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
822 } |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
823 |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
824 return desc; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
825 } |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
826 |
430
d03663d2e7d9
Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents:
426
diff
changeset
|
827 // display_server_error(x) |
d03663d2e7d9
Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents:
426
diff
changeset
|
828 // Display the error to the user |
d03663d2e7d9
Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents:
426
diff
changeset
|
829 // x: error tag xmlnode pointer |
533
c478e8f7f074
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
532
diff
changeset
|
830 static void display_server_error(xmlnode x) |
426
2706ef3e25a7
Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents:
421
diff
changeset
|
831 { |
430
d03663d2e7d9
Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents:
426
diff
changeset
|
832 const char *desc = NULL; |
d03663d2e7d9
Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents:
426
diff
changeset
|
833 int code = 0; |
426
2706ef3e25a7
Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents:
421
diff
changeset
|
834 char *s; |
430
d03663d2e7d9
Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents:
426
diff
changeset
|
835 const char *p; |
426
2706ef3e25a7
Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents:
421
diff
changeset
|
836 |
430
d03663d2e7d9
Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents:
426
diff
changeset
|
837 /* RFC3920: |
d03663d2e7d9
Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents:
426
diff
changeset
|
838 * The <error/> element: |
d03663d2e7d9
Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents:
426
diff
changeset
|
839 * o MUST contain a child element corresponding to one of the defined |
d03663d2e7d9
Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents:
426
diff
changeset
|
840 * stanza error conditions specified below; this element MUST be |
d03663d2e7d9
Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents:
426
diff
changeset
|
841 * qualified by the 'urn:ietf:params:xml:ns:xmpp-stanzas' namespace. |
d03663d2e7d9
Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents:
426
diff
changeset
|
842 */ |
d03663d2e7d9
Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents:
426
diff
changeset
|
843 p = xmlnode_get_name(xmlnode_get_firstchild(x)); |
d03663d2e7d9
Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents:
426
diff
changeset
|
844 if (p) |
d03663d2e7d9
Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents:
426
diff
changeset
|
845 scr_LogPrint(LPRINT_LOGNORM, "Received error packet [%s]", p); |
d03663d2e7d9
Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents:
426
diff
changeset
|
846 |
d03663d2e7d9
Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents:
426
diff
changeset
|
847 // For backward compatibility |
426
2706ef3e25a7
Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents:
421
diff
changeset
|
848 if ((s = xmlnode_get_attrib(x, "code")) != NULL) { |
2706ef3e25a7
Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents:
421
diff
changeset
|
849 code = atoi(s); |
2706ef3e25a7
Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents:
421
diff
changeset
|
850 // Default message |
430
d03663d2e7d9
Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents:
426
diff
changeset
|
851 desc = defaulterrormsg(code); |
d03663d2e7d9
Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents:
426
diff
changeset
|
852 } |
426
2706ef3e25a7
Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents:
421
diff
changeset
|
853 |
430
d03663d2e7d9
Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents:
426
diff
changeset
|
854 // Error tag data is better, if available |
d03663d2e7d9
Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents:
426
diff
changeset
|
855 s = xmlnode_get_data(x); |
d03663d2e7d9
Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents:
426
diff
changeset
|
856 if (s && *s) desc = s; |
426
2706ef3e25a7
Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents:
421
diff
changeset
|
857 |
430
d03663d2e7d9
Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents:
426
diff
changeset
|
858 // And sometimes there is a text message |
d03663d2e7d9
Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents:
426
diff
changeset
|
859 s = xmlnode_get_tag_data(x, "text"); |
d03663d2e7d9
Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents:
426
diff
changeset
|
860 if (s && *s) desc = s; // FIXME utf8?? |
426
2706ef3e25a7
Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents:
421
diff
changeset
|
861 |
430
d03663d2e7d9
Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents:
426
diff
changeset
|
862 scr_LogPrint(LPRINT_LOGNORM, "Error code from server: %d %s", code, desc); |
426
2706ef3e25a7
Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents:
421
diff
changeset
|
863 } |
2706ef3e25a7
Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents:
421
diff
changeset
|
864 |
533
c478e8f7f074
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
532
diff
changeset
|
865 static void statehandler(jconn conn, int state) |
31 | 866 { |
867 static int previous_state = -1; | |
868 | |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
869 scr_LogPrint(LPRINT_DEBUG, "StateHandler called (state=%d).", state); |
31 | 870 |
871 switch(state) { | |
872 case JCONN_STATE_OFF: | |
192 | 873 if (previous_state != JCONN_STATE_OFF) |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
874 scr_LogPrint(LPRINT_LOGNORM, "[Jabber] Not connected to the server"); |
37 | 875 |
112 | 876 online = FALSE; |
159 | 877 mystatus = offline; |
519
5c338d31de56
Show current global status message in "/status"
Mikael Berthe <mikael@lilotux.net>
parents:
513
diff
changeset
|
878 if (mystatusmsg) { |
5c338d31de56
Show current global status message in "/status"
Mikael Berthe <mikael@lilotux.net>
parents:
513
diff
changeset
|
879 g_free(mystatusmsg); |
5c338d31de56
Show current global status message in "/status"
Mikael Berthe <mikael@lilotux.net>
parents:
513
diff
changeset
|
880 mystatusmsg = NULL; |
5c338d31de56
Show current global status message in "/status"
Mikael Berthe <mikael@lilotux.net>
parents:
513
diff
changeset
|
881 } |
164 | 882 roster_free(); |
883 update_roster = TRUE; | |
31 | 884 break; |
885 | |
886 case JCONN_STATE_CONNECTED: | |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
887 scr_LogPrint(LPRINT_LOGNORM, "[Jabber] Connected to the server"); |
31 | 888 break; |
889 | |
890 case JCONN_STATE_AUTH: | |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
891 scr_LogPrint(LPRINT_LOGNORM, "[Jabber] Authenticating to the server"); |
31 | 892 break; |
893 | |
894 case JCONN_STATE_ON: | |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
895 scr_LogPrint(LPRINT_LOGNORM, "[Jabber] Communication with the server " |
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
896 "established"); |
112 | 897 online = TRUE; |
31 | 898 break; |
899 | |
35 | 900 case JCONN_STATE_CONNECTING: |
357
e8adc3c96e68
Better messages for server connection states
Mikael Berthe <mikael@lilotux.net>
parents:
353
diff
changeset
|
901 if (previous_state != state) |
408
73433860665c
Tune previous usleep() change
Mikael Berthe <mikael@lilotux.net>
parents:
407
diff
changeset
|
902 scr_LogPrint(LPRINT_LOGNORM, "[Jabber] Connecting to the server"); |
35 | 903 break; |
904 | |
31 | 905 default: |
906 break; | |
907 } | |
908 previous_state = state; | |
909 } | |
910 | |
533
c478e8f7f074
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
532
diff
changeset
|
911 static void packethandler(jconn conn, jpacket packet) |
31 | 912 { |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
913 char *p, *r, *s; |
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
436
diff
changeset
|
914 const char *m, *rname; |
37 | 915 xmlnode x, y; |
31 | 916 char *from=NULL, *type=NULL, *body=NULL, *enc=NULL; |
917 char *ns=NULL; | |
918 char *id=NULL; | |
35 | 919 enum imstatus ust; |
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
436
diff
changeset
|
920 char bpprio; |
31 | 921 |
469
a926523d2392
Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
468
diff
changeset
|
922 jb_reset_keepalive(); // reset keepalive timeout |
31 | 923 jpacket_reset(packet); |
924 | |
925 p = xmlnode_get_attrib(packet->x, "type"); if (p) type = p; | |
469
a926523d2392
Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
468
diff
changeset
|
926 p = xmlnode_get_attrib(packet->x, "from"); |
a926523d2392
Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
468
diff
changeset
|
927 if (p) { // Convert from UTF8 |
a926523d2392
Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
468
diff
changeset
|
928 // We need to be careful because from_utf8() can fail on some chars |
a926523d2392
Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
468
diff
changeset
|
929 // Thus we only convert the resource part |
a926523d2392
Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
468
diff
changeset
|
930 from = g_new0(char, strlen(p)+1); |
a926523d2392
Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
468
diff
changeset
|
931 strcpy(from, p); |
a926523d2392
Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
468
diff
changeset
|
932 r = strchr(from, '/'); |
a926523d2392
Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
468
diff
changeset
|
933 m = strchr(p, '/'); |
a926523d2392
Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
468
diff
changeset
|
934 if (m++) { |
a926523d2392
Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
468
diff
changeset
|
935 s = from_utf8(m); |
a926523d2392
Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
468
diff
changeset
|
936 if (s) { |
a926523d2392
Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
468
diff
changeset
|
937 // The length should be enough because from_utf should only |
a926523d2392
Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
468
diff
changeset
|
938 // reduce the string length |
a926523d2392
Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
468
diff
changeset
|
939 strcpy(r+1, s); |
a926523d2392
Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
468
diff
changeset
|
940 g_free(s); |
a926523d2392
Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
468
diff
changeset
|
941 } else { |
a926523d2392
Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
468
diff
changeset
|
942 *(r+1) = 0; |
523
fc6bc26f891e
Write UTF-9 conversion failures to the tracelog file
Mikael Berthe <mikael@lilotux.net>
parents:
521
diff
changeset
|
943 scr_LogPrint(LPRINT_NORMAL, "Decoding of message sender has failed"); |
fc6bc26f891e
Write UTF-9 conversion failures to the tracelog file
Mikael Berthe <mikael@lilotux.net>
parents:
521
diff
changeset
|
944 scr_LogPrint(LPRINT_LOG, "Decoding of message sender has failed: %s", m); |
469
a926523d2392
Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
468
diff
changeset
|
945 } |
a926523d2392
Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
468
diff
changeset
|
946 } |
a926523d2392
Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
468
diff
changeset
|
947 } |
a926523d2392
Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
468
diff
changeset
|
948 |
a926523d2392
Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
468
diff
changeset
|
949 if (!from && packet->type != JPACKET_IQ) { |
a926523d2392
Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
468
diff
changeset
|
950 scr_LogPrint(LPRINT_LOGNORM, "Error in packet (could be UTF8-related)"); |
a926523d2392
Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
468
diff
changeset
|
951 return; |
a926523d2392
Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
468
diff
changeset
|
952 } |
31 | 953 |
954 switch (packet->type) { | |
955 case JPACKET_MESSAGE: | |
52 | 956 { |
957 char *tmp = NULL; | |
223 | 958 time_t timestamp = 0; |
959 | |
473
c024d1d5d350
Fix segfault when receiving a message stanza with no body tag
Mikael Berthe <mikael@lilotux.net>
parents:
472
diff
changeset
|
960 body = xmlnode_get_tag_data(packet->x, "body"); |
31 | 961 |
473
c024d1d5d350
Fix segfault when receiving a message stanza with no body tag
Mikael Berthe <mikael@lilotux.net>
parents:
472
diff
changeset
|
962 p = xmlnode_get_tag_data(packet->x, "subject"); |
c024d1d5d350
Fix segfault when receiving a message stanza with no body tag
Mikael Berthe <mikael@lilotux.net>
parents:
472
diff
changeset
|
963 if (p != NULL) { |
475
fa49ac0bb8f3
Add "/room topic", and display topic changes
Mikael Berthe <mikael@lilotux.net>
parents:
474
diff
changeset
|
964 if (type && !strcmp(type, TMSG_GROUPCHAT)) { // Room topic |
fa49ac0bb8f3
Add "/room topic", and display topic changes
Mikael Berthe <mikael@lilotux.net>
parents:
474
diff
changeset
|
965 gchar *mbuf; |
fa49ac0bb8f3
Add "/room topic", and display topic changes
Mikael Berthe <mikael@lilotux.net>
parents:
474
diff
changeset
|
966 gchar *subj_noutf8 = from_utf8(p); |
523
fc6bc26f891e
Write UTF-9 conversion failures to the tracelog file
Mikael Berthe <mikael@lilotux.net>
parents:
521
diff
changeset
|
967 if (!subj_noutf8) |
fc6bc26f891e
Write UTF-9 conversion failures to the tracelog file
Mikael Berthe <mikael@lilotux.net>
parents:
521
diff
changeset
|
968 scr_LogPrint(LPRINT_LOG, |
fc6bc26f891e
Write UTF-9 conversion failures to the tracelog file
Mikael Berthe <mikael@lilotux.net>
parents:
521
diff
changeset
|
969 "Decoding of room topic has failed: %s", p); |
475
fa49ac0bb8f3
Add "/room topic", and display topic changes
Mikael Berthe <mikael@lilotux.net>
parents:
474
diff
changeset
|
970 // Get the room (s) and the nickname (r) |
fa49ac0bb8f3
Add "/room topic", and display topic changes
Mikael Berthe <mikael@lilotux.net>
parents:
474
diff
changeset
|
971 s = g_strdup(from); |
fa49ac0bb8f3
Add "/room topic", and display topic changes
Mikael Berthe <mikael@lilotux.net>
parents:
474
diff
changeset
|
972 r = strchr(s, '/'); |
fa49ac0bb8f3
Add "/room topic", and display topic changes
Mikael Berthe <mikael@lilotux.net>
parents:
474
diff
changeset
|
973 if (r) *r++ = 0; |
fa49ac0bb8f3
Add "/room topic", and display topic changes
Mikael Berthe <mikael@lilotux.net>
parents:
474
diff
changeset
|
974 else r = s; |
fa49ac0bb8f3
Add "/room topic", and display topic changes
Mikael Berthe <mikael@lilotux.net>
parents:
474
diff
changeset
|
975 // Display inside the room window |
fa49ac0bb8f3
Add "/room topic", and display topic changes
Mikael Berthe <mikael@lilotux.net>
parents:
474
diff
changeset
|
976 mbuf = g_strdup_printf("%s has set the topic to: %s", r, |
489
21ab22a60bcb
Auto-convert a roster item to "room" type when receiving a groupchat message
Mikael Berthe <mikael@lilotux.net>
parents:
486
diff
changeset
|
977 (subj_noutf8 ? subj_noutf8 : "(?)")); |
513 | 978 scr_WriteIncomingMessage(s, mbuf, 0, |
979 HBB_PREFIX_INFO|HBB_PREFIX_NOFLAG); | |
478
47cfa3779549
MUC: log join/nick/leave/topic if log_muc_conf is set
Mikael Berthe <mikael@lilotux.net>
parents:
475
diff
changeset
|
980 if (settings_opt_get_int("log_muc_conf")) |
47cfa3779549
MUC: log join/nick/leave/topic if log_muc_conf is set
Mikael Berthe <mikael@lilotux.net>
parents:
475
diff
changeset
|
981 hlog_write_message(s, 0, FALSE, mbuf); |
475
fa49ac0bb8f3
Add "/room topic", and display topic changes
Mikael Berthe <mikael@lilotux.net>
parents:
474
diff
changeset
|
982 if (subj_noutf8) g_free(subj_noutf8); |
fa49ac0bb8f3
Add "/room topic", and display topic changes
Mikael Berthe <mikael@lilotux.net>
parents:
474
diff
changeset
|
983 g_free(s); |
fa49ac0bb8f3
Add "/room topic", and display topic changes
Mikael Berthe <mikael@lilotux.net>
parents:
474
diff
changeset
|
984 g_free(mbuf); |
fa49ac0bb8f3
Add "/room topic", and display topic changes
Mikael Berthe <mikael@lilotux.net>
parents:
474
diff
changeset
|
985 } else { // Chat message |
473
c024d1d5d350
Fix segfault when receiving a message stanza with no body tag
Mikael Berthe <mikael@lilotux.net>
parents:
472
diff
changeset
|
986 tmp = g_new(char, (body ? strlen(body) : 0) + strlen(p) + 4); |
52 | 987 *tmp = '['; |
988 strcpy(tmp+1, p); | |
989 strcat(tmp, "]\n"); | |
473
c024d1d5d350
Fix segfault when receiving a message stanza with no body tag
Mikael Berthe <mikael@lilotux.net>
parents:
472
diff
changeset
|
990 if (body) strcat(tmp, body); |
52 | 991 body = tmp; |
992 } | |
473
c024d1d5d350
Fix segfault when receiving a message stanza with no body tag
Mikael Berthe <mikael@lilotux.net>
parents:
472
diff
changeset
|
993 } |
52 | 994 |
995 /* there can be multiple <x> tags. we're looking for one with | |
996 xmlns = jabber:x:encrypted */ | |
997 | |
420
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
998 x = xmlnode_get_firstchild(packet->x); |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
999 for ( ; x; x = xmlnode_get_nextsibling(x)) { |
52 | 1000 if ((p = xmlnode_get_name(x)) && !strcmp(p, "x")) |
1001 if ((p = xmlnode_get_attrib(x, "xmlns")) && | |
1002 !strcasecmp(p, "jabber:x:encrypted")) | |
1003 if ((p = xmlnode_get_data(x)) != NULL) { | |
1004 enc = p; | |
1005 break; | |
1006 } | |
31 | 1007 } |
1008 | |
223 | 1009 // Timestamp? |
1010 if ((x = xmlnode_get_tag(packet->x, "x")) != NULL) { | |
241 | 1011 if ((p = xmlnode_get_attrib(x, "stamp")) != NULL) |
1012 timestamp = from_iso8601(p, 1); | |
223 | 1013 } |
1014 | |
474 | 1015 if (type && !strcmp(type, TMSG_ERROR)) { |
1016 if ((x = xmlnode_get_tag(packet->x, TMSG_ERROR)) != NULL) | |
426
2706ef3e25a7
Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents:
421
diff
changeset
|
1017 display_server_error(x); |
420
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
1018 } |
165 | 1019 if (from && body) |
223 | 1020 gotmessage(type, from, body, enc, timestamp); |
52 | 1021 if (tmp) |
159 | 1022 g_free(tmp); |
31 | 1023 } |
1024 break; | |
1025 | |
1026 case JPACKET_IQ: | |
1027 if (!strcmp(type, "result")) { | |
1028 | |
51 | 1029 if ((p = xmlnode_get_attrib(packet->x, "id")) != NULL) { |
31 | 1030 int iid = atoi(p); |
1031 | |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
1032 scr_LogPrint(LPRINT_DEBUG, "iid = %d", iid); |
31 | 1033 if (iid == s_id) { |
1034 if (!regmode) { | |
1035 if (jstate == STATE_GETAUTH) { | |
51 | 1036 if ((x = xmlnode_get_tag(packet->x, "query")) != NULL) |
31 | 1037 if (!xmlnode_get_tag(x, "digest")) { |
1038 jc->sid = 0; | |
1039 } | |
1040 | |
1041 s_id = atoi(jab_auth(jc)); | |
1042 jstate = STATE_SENDAUTH; | |
1043 } else { | |
1044 gotloggedin(); | |
1045 jstate = STATE_LOGGED; | |
1046 } | |
1047 } else { | |
1048 regdone = TRUE; | |
1049 } | |
1050 return; | |
1051 } | |
1052 | |
1053 if (!strcmp(p, "VCARDreq")) { | |
1054 x = xmlnode_get_firstchild(packet->x); | |
1055 if (!x) x = packet->x; | |
1056 | |
1057 //jhook.gotvcard(ic, x); TODO | |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
1058 scr_LogPrint(LPRINT_LOGNORM, "Got VCARD"); |
31 | 1059 return; |
1060 } else if (!strcmp(p, "versionreq")) { | |
1061 // jhook.gotversion(ic, packet->x); TODO | |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
1062 scr_LogPrint(LPRINT_LOGNORM, "Got version"); |
31 | 1063 return; |
1064 } | |
1065 } | |
1066 | |
51 | 1067 if ((x = xmlnode_get_tag(packet->x, "query")) != NULL) { |
31 | 1068 p = xmlnode_get_attrib(x, "xmlns"); if (p) ns = p; |
1069 | |
1070 if (!strcmp(ns, NS_ROSTER)) { | |
1071 gotroster(x); | |
1072 } else if (!strcmp(ns, NS_AGENTS)) { | |
1073 for (y = xmlnode_get_tag(x, "agent"); y; y = xmlnode_get_nextsibling(y)) { | |
1074 const char *alias = xmlnode_get_attrib(y, "jid"); | |
1075 | |
1076 if (alias) { | |
1077 const char *name = xmlnode_get_tag_data(y, "name"); | |
1078 const char *desc = xmlnode_get_tag_data(y, "description"); | |
474 | 1079 // TODO |
1080 // const char *service = xmlnode_get_tag_data(y, "service"); | |
37 | 1081 enum agtype atype = unknown; |
31 | 1082 |
474 | 1083 if (xmlnode_get_tag(y, TMSG_GROUPCHAT)) atype = groupchat; |
1084 else if (xmlnode_get_tag(y, "transport")) atype = transport; | |
1085 else if (xmlnode_get_tag(y, "search")) atype = search; | |
31 | 1086 |
192 | 1087 if (atype == transport) { |
1088 char *cleanjid = jidtodisp(alias); | |
194 | 1089 roster_add_user(cleanjid, NULL, JABBER_AGENT_GROUP, |
1090 ROSTER_TYPE_AGENT); | |
192 | 1091 g_free(cleanjid); |
1092 } | |
31 | 1093 if (alias && name && desc) { |
474 | 1094 scr_LogPrint(LPRINT_LOGNORM, |
1095 "Agent: %s / %s / %s / type=%d", | |
37 | 1096 alias, name, desc, atype); |
31 | 1097 |
37 | 1098 if (atype == search) { |
31 | 1099 x = jutil_iqnew (JPACKET__GET, NS_SEARCH); |
1100 xmlnode_put_attrib(x, "to", alias); | |
1101 xmlnode_put_attrib(x, "id", "Agent info"); | |
1102 jab_send(conn, x); | |
1103 xmlnode_free(x); | |
1104 } | |
1105 | |
1106 if (xmlnode_get_tag(y, "register")) { | |
1107 x = jutil_iqnew (JPACKET__GET, NS_REGISTER); | |
1108 xmlnode_put_attrib(x, "to", alias); | |
1109 xmlnode_put_attrib(x, "id", "Agent info"); | |
1110 jab_send(conn, x); | |
1111 xmlnode_free(x); | |
1112 } | |
1113 } | |
1114 } | |
1115 } | |
1116 | |
37 | 1117 /* |
31 | 1118 if (find(jhook.agents.begin(), jhook.agents.end(), DEFAULT_CONFSERV) == jhook.agents.end()) |
1119 jhook.agents.insert(jhook.agents.begin(), agent(DEFAULT_CONFSERV, DEFAULT_CONFSERV, | |
1120 _("Default Jabber conference server"), agent::atGroupchat)); | |
1121 | |
1122 */ | |
1123 } else if (!strcmp(ns, NS_SEARCH) || !strcmp(ns, NS_REGISTER)) { | |
1124 p = xmlnode_get_attrib(packet->x, "id"); id = p ? p : (char*)""; | |
1125 | |
1126 if (!strcmp(id, "Agent info")) { | |
1127 // jhook.gotagentinfo(packet->x); TODO | |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
1128 scr_LogPrint(LPRINT_LOGNORM, "Got agent info"); |
31 | 1129 } else if (!strcmp(id, "Lookup")) { |
1130 // jhook.gotsearchresults(packet->x); TODO | |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
1131 scr_LogPrint(LPRINT_LOGNORM, "Got search results"); |
31 | 1132 } else if (!strcmp(id, "Register")) { |
1133 x = jutil_iqnew(JPACKET__GET, NS_REGISTER); | |
1134 xmlnode_put_attrib(x, "to", from); | |
1135 xmlnode_put_attrib(x, "id", "Agent info"); | |
1136 jab_send(conn, x); | |
1137 xmlnode_free(x); | |
1138 } | |
1139 | |
1140 } | |
1141 } | |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
1142 } else if (!strcmp(type, "get")) { |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
1143 p = xmlnode_get_attrib(packet->x, "id"); |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
1144 if (p) { |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
1145 xmlnode z; |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
1146 |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
1147 id = p; |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
1148 x = xmlnode_new_tag("iq"); |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
1149 xmlnode_put_attrib(x, "type", "result"); |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
1150 xmlnode_put_attrib(x, "to", from); |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
1151 xmlnode_put_attrib(x, "id", id); |
474 | 1152 xmlnode_put_attrib(x, "type", TMSG_ERROR); |
1153 y = xmlnode_insert_tag(x, TMSG_ERROR); | |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
1154 xmlnode_put_attrib(y, "code", "503"); |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
1155 xmlnode_put_attrib(y, "type", "cancel"); |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
1156 z = xmlnode_insert_tag(y, "feature-not-implemented"); |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
1157 xmlnode_put_attrib(z, "xmlns", |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
1158 "urn:ietf:params:xml:ns:xmpp-stanzas"); |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
1159 jab_send(conn, x); |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
1160 xmlnode_free(x); |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
1161 } |
31 | 1162 } else if (!strcmp(type, "set")) { |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
1163 /* FIXME: send error */ |
474 | 1164 } else if (!strcmp(type, TMSG_ERROR)) { |
1165 if ((x = xmlnode_get_tag(packet->x, TMSG_ERROR)) != NULL) | |
426
2706ef3e25a7
Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents:
421
diff
changeset
|
1166 display_server_error(x); |
31 | 1167 } |
1168 break; | |
1169 | |
1170 case JPACKET_PRESENCE: | |
426
2706ef3e25a7
Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents:
421
diff
changeset
|
1171 r = jidtodisp(from); |
474 | 1172 if (type && !strcmp(type, TMSG_ERROR)) { |
426
2706ef3e25a7
Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents:
421
diff
changeset
|
1173 scr_LogPrint(LPRINT_LOGNORM, "Error presence packet from <%s>", r); |
474 | 1174 if ((x = xmlnode_get_tag(packet->x, TMSG_ERROR)) != NULL) |
426
2706ef3e25a7
Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents:
421
diff
changeset
|
1175 display_server_error(x); |
2706ef3e25a7
Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents:
421
diff
changeset
|
1176 g_free(r); |
2706ef3e25a7
Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents:
421
diff
changeset
|
1177 break; |
2706ef3e25a7
Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents:
421
diff
changeset
|
1178 } |
31 | 1179 |
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
436
diff
changeset
|
1180 p = xmlnode_get_tag_data(packet->x, "priority"); |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
436
diff
changeset
|
1181 if (p && *p) bpprio = (gchar)atoi(p); |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
436
diff
changeset
|
1182 else bpprio = 0; |
31 | 1183 |
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
436
diff
changeset
|
1184 ust = available; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
436
diff
changeset
|
1185 p = xmlnode_get_tag_data(packet->x, "show"); |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
436
diff
changeset
|
1186 if (p) { |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
436
diff
changeset
|
1187 if (!strcmp(p, "away")) ust = away; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
436
diff
changeset
|
1188 else if (!strcmp(p, "dnd")) ust = dontdisturb; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
436
diff
changeset
|
1189 else if (!strcmp(p, "xa")) ust = notavail; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
436
diff
changeset
|
1190 else if (!strcmp(p, "chat")) ust = freeforchat; |
31 | 1191 } |
1192 | |
321
59193965f2cb
Convert status messages to/from UTF-8
Mikael Berthe <mikael@lilotux.net>
parents:
319
diff
changeset
|
1193 if (type && !strcmp(type, "unavailable")) |
35 | 1194 ust = offline; |
31 | 1195 |
523
fc6bc26f891e
Write UTF-9 conversion failures to the tracelog file
Mikael Berthe <mikael@lilotux.net>
parents:
521
diff
changeset
|
1196 s = NULL; |
fc6bc26f891e
Write UTF-9 conversion failures to the tracelog file
Mikael Berthe <mikael@lilotux.net>
parents:
521
diff
changeset
|
1197 p = xmlnode_get_tag_data(packet->x, "status"); |
fc6bc26f891e
Write UTF-9 conversion failures to the tracelog file
Mikael Berthe <mikael@lilotux.net>
parents:
521
diff
changeset
|
1198 if (p) { |
fc6bc26f891e
Write UTF-9 conversion failures to the tracelog file
Mikael Berthe <mikael@lilotux.net>
parents:
521
diff
changeset
|
1199 s = from_utf8(p); |
fc6bc26f891e
Write UTF-9 conversion failures to the tracelog file
Mikael Berthe <mikael@lilotux.net>
parents:
521
diff
changeset
|
1200 if (!s) |
fc6bc26f891e
Write UTF-9 conversion failures to the tracelog file
Mikael Berthe <mikael@lilotux.net>
parents:
521
diff
changeset
|
1201 scr_LogPrint(LPRINT_LOG, |
fc6bc26f891e
Write UTF-9 conversion failures to the tracelog file
Mikael Berthe <mikael@lilotux.net>
parents:
521
diff
changeset
|
1202 "Decoding of status message of <%s> has failed: %s", |
fc6bc26f891e
Write UTF-9 conversion failures to the tracelog file
Mikael Berthe <mikael@lilotux.net>
parents:
521
diff
changeset
|
1203 from, p); |
fc6bc26f891e
Write UTF-9 conversion failures to the tracelog file
Mikael Berthe <mikael@lilotux.net>
parents:
521
diff
changeset
|
1204 } |
221 | 1205 |
318
45076d02eeef
The /status command can specify a status message
Mikael Berthe <mikael@lilotux.net>
parents:
311
diff
changeset
|
1206 // Call hk_statuschange() if status has changed or if the |
45076d02eeef
The /status command can specify a status message
Mikael Berthe <mikael@lilotux.net>
parents:
311
diff
changeset
|
1207 // status message is different |
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
436
diff
changeset
|
1208 rname = strchr(from, '/'); |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
436
diff
changeset
|
1209 if (rname) rname++; |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
1210 |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
1211 // Check for MUC presence packet |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
1212 // There can be multiple <x> tags!! |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
1213 x = xmlnode_get_firstchild(packet->x); |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
1214 for ( ; x; x = xmlnode_get_nextsibling(x)) { |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
1215 if ((p = xmlnode_get_name(x)) && !strcmp(p, "x")) |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
1216 if ((p = xmlnode_get_attrib(x, "xmlns")) && |
468
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
461
diff
changeset
|
1217 !strcasecmp(p, "http://jabber.org/protocol/muc#user")) |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
1218 break; |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
1219 } |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
1220 if (x) { // This is a MUC presence message |
468
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
461
diff
changeset
|
1221 enum imrole mbrole = role_none; |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
461
diff
changeset
|
1222 const char *mbrjid = NULL; |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
461
diff
changeset
|
1223 const char *mbnewnick = NULL; |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
461
diff
changeset
|
1224 GSList *room_elt; |
478
47cfa3779549
MUC: log join/nick/leave/topic if log_muc_conf is set
Mikael Berthe <mikael@lilotux.net>
parents:
475
diff
changeset
|
1225 int log_muc_conf = settings_opt_get_int("log_muc_conf"); |
468
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
461
diff
changeset
|
1226 |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
461
diff
changeset
|
1227 // Add room if it doesn't already exist |
489
21ab22a60bcb
Auto-convert a roster item to "room" type when receiving a groupchat message
Mikael Berthe <mikael@lilotux.net>
parents:
486
diff
changeset
|
1228 room_elt = roster_find(r, jidsearch, 0); |
21ab22a60bcb
Auto-convert a roster item to "room" type when receiving a groupchat message
Mikael Berthe <mikael@lilotux.net>
parents:
486
diff
changeset
|
1229 if (!room_elt) |
21ab22a60bcb
Auto-convert a roster item to "room" type when receiving a groupchat message
Mikael Berthe <mikael@lilotux.net>
parents:
486
diff
changeset
|
1230 room_elt = roster_add_user(r, NULL, NULL, ROSTER_TYPE_ROOM); |
21ab22a60bcb
Auto-convert a roster item to "room" type when receiving a groupchat message
Mikael Berthe <mikael@lilotux.net>
parents:
486
diff
changeset
|
1231 else // Make sure this is a room (it can be a conversion user->room) |
21ab22a60bcb
Auto-convert a roster item to "room" type when receiving a groupchat message
Mikael Berthe <mikael@lilotux.net>
parents:
486
diff
changeset
|
1232 buddy_settype(room_elt->data, ROSTER_TYPE_ROOM); |
468
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
461
diff
changeset
|
1233 |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
461
diff
changeset
|
1234 // Get room member's information |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
461
diff
changeset
|
1235 y = xmlnode_get_tag(x, "item"); |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
461
diff
changeset
|
1236 if (y) { |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
461
diff
changeset
|
1237 p = xmlnode_get_attrib(y, "role"); |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
461
diff
changeset
|
1238 if (p) { |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
461
diff
changeset
|
1239 if (!strcmp(p, "moderator")) mbrole = role_moderator; |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
461
diff
changeset
|
1240 else if (!strcmp(p, "participant")) mbrole = role_participant; |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
461
diff
changeset
|
1241 else if (!strcmp(p, "visitor")) mbrole = role_visitor; |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
461
diff
changeset
|
1242 else if (!strcmp(p, "none")) mbrole = role_none; |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
461
diff
changeset
|
1243 else scr_LogPrint(LPRINT_LOGNORM, "<%s>: Unknown role \"%s\"", |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
461
diff
changeset
|
1244 from, p); |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
461
diff
changeset
|
1245 } |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
461
diff
changeset
|
1246 p = xmlnode_get_attrib(y, "jid"); |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
461
diff
changeset
|
1247 if (p) mbrjid = p; |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
461
diff
changeset
|
1248 p = xmlnode_get_attrib(y, "nick"); |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
461
diff
changeset
|
1249 if (p) mbnewnick = p; |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
461
diff
changeset
|
1250 } |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
1251 |
468
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
461
diff
changeset
|
1252 // Check for nickname change |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
461
diff
changeset
|
1253 y = xmlnode_get_tag(x, "status"); |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
461
diff
changeset
|
1254 if (y && mbnewnick) { |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
461
diff
changeset
|
1255 p = xmlnode_get_attrib(y, "code"); |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
461
diff
changeset
|
1256 if (p && !strcmp(p, "303")) { |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
461
diff
changeset
|
1257 gchar *mbuf; |
469
a926523d2392
Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
468
diff
changeset
|
1258 gchar *newname_noutf8 = from_utf8(mbnewnick); |
523
fc6bc26f891e
Write UTF-9 conversion failures to the tracelog file
Mikael Berthe <mikael@lilotux.net>
parents:
521
diff
changeset
|
1259 if (!newname_noutf8) |
fc6bc26f891e
Write UTF-9 conversion failures to the tracelog file
Mikael Berthe <mikael@lilotux.net>
parents:
521
diff
changeset
|
1260 scr_LogPrint(LPRINT_LOG, |
fc6bc26f891e
Write UTF-9 conversion failures to the tracelog file
Mikael Berthe <mikael@lilotux.net>
parents:
521
diff
changeset
|
1261 "Decoding of new nickname has failed: %s", |
fc6bc26f891e
Write UTF-9 conversion failures to the tracelog file
Mikael Berthe <mikael@lilotux.net>
parents:
521
diff
changeset
|
1262 mbnewnick); |
469
a926523d2392
Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
468
diff
changeset
|
1263 mbuf = g_strdup_printf("%s is now known as %s", rname, |
527
d721b3502a77
Notice when we are ejected from a room
Mikael Berthe <mikael@lilotux.net>
parents:
523
diff
changeset
|
1264 (newname_noutf8 ? newname_noutf8 : "(?)")); |
513 | 1265 scr_WriteIncomingMessage(r, mbuf, 0, |
1266 HBB_PREFIX_INFO|HBB_PREFIX_NOFLAG); | |
478
47cfa3779549
MUC: log join/nick/leave/topic if log_muc_conf is set
Mikael Berthe <mikael@lilotux.net>
parents:
475
diff
changeset
|
1267 if (log_muc_conf) hlog_write_message(r, 0, FALSE, mbuf); |
468
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
461
diff
changeset
|
1268 g_free(mbuf); |
469
a926523d2392
Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
468
diff
changeset
|
1269 if (newname_noutf8) { |
a926523d2392
Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
468
diff
changeset
|
1270 buddy_resource_setname(room_elt->data, rname, newname_noutf8); |
470 | 1271 m = buddy_getnickname(room_elt->data); |
1272 if (m && !strcmp(rname, m)) | |
1273 buddy_setnickname(room_elt->data, newname_noutf8); | |
469
a926523d2392
Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
468
diff
changeset
|
1274 g_free(newname_noutf8); |
a926523d2392
Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
468
diff
changeset
|
1275 } |
468
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
461
diff
changeset
|
1276 } |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
461
diff
changeset
|
1277 } |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
461
diff
changeset
|
1278 |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
461
diff
changeset
|
1279 // Check for departure/arrival |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
461
diff
changeset
|
1280 if (!mbnewnick && mbrole == role_none) { |
507
16dd9b91702f
MUC: display buddy's departure message, if any
Mikael Berthe <mikael@lilotux.net>
parents:
493
diff
changeset
|
1281 gchar *mbuf; |
527
d721b3502a77
Notice when we are ejected from a room
Mikael Berthe <mikael@lilotux.net>
parents:
523
diff
changeset
|
1282 |
d721b3502a77
Notice when we are ejected from a room
Mikael Berthe <mikael@lilotux.net>
parents:
523
diff
changeset
|
1283 // If this is a leave, check if it is ourself |
d721b3502a77
Notice when we are ejected from a room
Mikael Berthe <mikael@lilotux.net>
parents:
523
diff
changeset
|
1284 m = buddy_getnickname(room_elt->data); |
d721b3502a77
Notice when we are ejected from a room
Mikael Berthe <mikael@lilotux.net>
parents:
523
diff
changeset
|
1285 if (m && !strcmp(rname, m)) { |
d721b3502a77
Notice when we are ejected from a room
Mikael Berthe <mikael@lilotux.net>
parents:
523
diff
changeset
|
1286 // _We_ have left! (kicked, banned, etc.) |
d721b3502a77
Notice when we are ejected from a room
Mikael Berthe <mikael@lilotux.net>
parents:
523
diff
changeset
|
1287 buddy_setnickname(room_elt->data, NULL); |
d721b3502a77
Notice when we are ejected from a room
Mikael Berthe <mikael@lilotux.net>
parents:
523
diff
changeset
|
1288 buddy_del_all_resources(room_elt->data); |
d721b3502a77
Notice when we are ejected from a room
Mikael Berthe <mikael@lilotux.net>
parents:
523
diff
changeset
|
1289 scr_LogPrint(LPRINT_LOGNORM, "You have left %s", r); |
d721b3502a77
Notice when we are ejected from a room
Mikael Berthe <mikael@lilotux.net>
parents:
523
diff
changeset
|
1290 scr_WriteIncomingMessage(r, "You have left", 0, |
d721b3502a77
Notice when we are ejected from a room
Mikael Berthe <mikael@lilotux.net>
parents:
523
diff
changeset
|
1291 HBB_PREFIX_INFO|HBB_PREFIX_NOFLAG); |
d721b3502a77
Notice when we are ejected from a room
Mikael Berthe <mikael@lilotux.net>
parents:
523
diff
changeset
|
1292 g_free(r); |
d721b3502a77
Notice when we are ejected from a room
Mikael Berthe <mikael@lilotux.net>
parents:
523
diff
changeset
|
1293 if (s) g_free(s); |
d721b3502a77
Notice when we are ejected from a room
Mikael Berthe <mikael@lilotux.net>
parents:
523
diff
changeset
|
1294 update_roster = TRUE; |
d721b3502a77
Notice when we are ejected from a room
Mikael Berthe <mikael@lilotux.net>
parents:
523
diff
changeset
|
1295 break; |
d721b3502a77
Notice when we are ejected from a room
Mikael Berthe <mikael@lilotux.net>
parents:
523
diff
changeset
|
1296 } |
d721b3502a77
Notice when we are ejected from a room
Mikael Berthe <mikael@lilotux.net>
parents:
523
diff
changeset
|
1297 |
507
16dd9b91702f
MUC: display buddy's departure message, if any
Mikael Berthe <mikael@lilotux.net>
parents:
493
diff
changeset
|
1298 if (s) mbuf = g_strdup_printf("%s has left: %s", rname, s); |
16dd9b91702f
MUC: display buddy's departure message, if any
Mikael Berthe <mikael@lilotux.net>
parents:
493
diff
changeset
|
1299 else mbuf = g_strdup_printf("%s has left", rname); |
513 | 1300 scr_WriteIncomingMessage(r, mbuf, 0, |
1301 HBB_PREFIX_INFO|HBB_PREFIX_NOFLAG); | |
478
47cfa3779549
MUC: log join/nick/leave/topic if log_muc_conf is set
Mikael Berthe <mikael@lilotux.net>
parents:
475
diff
changeset
|
1302 if (log_muc_conf) hlog_write_message(r, 0, FALSE, mbuf); |
468
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
461
diff
changeset
|
1303 g_free(mbuf); |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
461
diff
changeset
|
1304 } else if (buddy_getstatus(room_elt->data, rname) == offline && |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
461
diff
changeset
|
1305 ust != offline) { |
470 | 1306 gchar *mbuf; |
1307 if (buddy_getnickname(room_elt->data) == NULL) { | |
1308 buddy_setnickname(room_elt->data, rname); | |
1309 mbuf = g_strdup_printf("You have joined as \"%s\"", rname); | |
1310 } else { | |
1311 mbuf = g_strdup_printf("%s has joined", rname); | |
1312 } | |
513 | 1313 scr_WriteIncomingMessage(r, mbuf, 0, |
1314 HBB_PREFIX_INFO|HBB_PREFIX_NOFLAG); | |
478
47cfa3779549
MUC: log join/nick/leave/topic if log_muc_conf is set
Mikael Berthe <mikael@lilotux.net>
parents:
475
diff
changeset
|
1315 if (log_muc_conf) hlog_write_message(r, 0, FALSE, mbuf); |
468
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
461
diff
changeset
|
1316 g_free(mbuf); |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
461
diff
changeset
|
1317 } |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
461
diff
changeset
|
1318 |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
461
diff
changeset
|
1319 // Update room member status |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
1320 if (rname) |
493
dba5de0b89bc
Update message status for conference occupants
Mikael Berthe <mikael@lilotux.net>
parents:
489
diff
changeset
|
1321 roster_setstatus(r, rname, bpprio, ust, s, mbrole, mbrjid); |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
1322 else |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
1323 scr_LogPrint(LPRINT_LOGNORM, "MUC DBG: no rname!"); /* DBG */ |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
1324 |
468
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
461
diff
changeset
|
1325 g_free(r); |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
461
diff
changeset
|
1326 if (s) g_free(s); |
644b8bf9ca4d
Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents:
461
diff
changeset
|
1327 |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
1328 buddylist_build(); |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
1329 scr_DrawRoster(); |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
1330 break; |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
1331 } |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
1332 |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
1333 // Not a MUC message, so this is a regular buddy... |
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
436
diff
changeset
|
1334 m = roster_getstatusmsg(r, rname); |
537
6547fd48fb5e
Buddy status change was not always displayed
Mikael Berthe <mikael@lilotux.net>
parents:
535
diff
changeset
|
1335 if ((ust != roster_getstatus(r, rname)) || |
6547fd48fb5e
Buddy status change was not always displayed
Mikael Berthe <mikael@lilotux.net>
parents:
535
diff
changeset
|
1336 (!s && m && m[0]) || (s && (!m || strcmp(s, m)))) |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
1337 hk_statuschange(r, rname, bpprio, 0, ust, s); |
159 | 1338 g_free(r); |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
1339 if (s) g_free(s); |
31 | 1340 break; |
1341 | |
1342 case JPACKET_S10N: | |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
1343 scr_LogPrint(LPRINT_LOGNORM, "Received (un)subscription packet " |
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
1344 "(type=%s)", ((type) ? type : "")); |
31 | 1345 |
43 | 1346 if (!strcmp(type, "subscribe")) { |
91 | 1347 int isagent; |
1348 r = jidtodisp(from); | |
1349 isagent = (roster_gettype(r) & ROSTER_TYPE_AGENT) != 0; | |
159 | 1350 g_free(r); |
538 | 1351 //scr_LogPrint(LPRINT_LOGNORM, "isagent=%d", isagent); // XXX DBG |
91 | 1352 if (!isagent) { |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
1353 scr_LogPrint(LPRINT_LOGNORM, "<%s> wants to subscribe " |
43 | 1354 "to your network presence updates", from); |
125 | 1355 // FIXME we accept everybody... |
1356 x = jutil_presnew(JPACKET__SUBSCRIBED, from, 0); | |
1357 jab_send(jc, x); | |
1358 xmlnode_free(x); | |
91 | 1359 } else { |
1360 x = jutil_presnew(JPACKET__SUBSCRIBED, from, 0); | |
31 | 1361 jab_send(jc, x); |
1362 xmlnode_free(x); | |
91 | 1363 } |
43 | 1364 } else if (!strcmp(type, "unsubscribe")) { |
1365 x = jutil_presnew(JPACKET__UNSUBSCRIBED, from, 0); | |
31 | 1366 jab_send(jc, x); |
1367 xmlnode_free(x); | |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
1368 scr_LogPrint(LPRINT_LOGNORM, "<%s> has unsubscribed to " |
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
1369 "your presence updates", from); |
31 | 1370 } |
1371 break; | |
1372 | |
1373 default: | |
1374 break; | |
1375 } | |
469
a926523d2392
Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
468
diff
changeset
|
1376 g_free(from); |
31 | 1377 } |
1378 |