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