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