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