Mercurial > hg
annotate mcabber/src/jabglue.c @ 449:e08b0c2d0e54
Add "/room unlock"
author | Mikael Berthe <mikael@lilotux.net> |
---|---|
date | Sun, 25 Sep 2005 23:45:34 +0200 |
parents | 03bb57383cea |
children | 1d8f5b3a5f2b |
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 |
449 | 492 // Unlock a MUC room |
493 // room syntax: "room@server" | |
494 void jb_room_unlock(const char *room) | |
495 { | |
496 xmlnode x, y, z; | |
497 | |
498 if (!online) return; | |
499 if (!room) return; | |
500 | |
501 x = jutil_iqnew(JPACKET__SET, "http://jabber.org/protocol/muc#owner"); | |
502 xmlnode_put_attrib(x, "id", "unlock1"); // XXX | |
503 xmlnode_put_attrib(x, "to", room); | |
504 y = xmlnode_get_tag(x, "query"); | |
505 z = xmlnode_insert_tag(y, "x"); | |
506 xmlnode_put_attrib(z, "xmlns", "jabber:x:data"); | |
507 xmlnode_put_attrib(z, "type", "submit"); | |
508 | |
509 jab_send(jc, x); | |
510 xmlnode_free(x); | |
511 jb_reset_keepalive(); | |
512 } | |
513 | |
31 | 514 void postlogin() |
515 { | |
516 //int i; | |
517 | |
518 //flogged = TRUE; | |
519 //ourstatus = available; | |
520 | |
521 //setautostatus(jhook.manualstatus); | |
522 | |
444 | 523 jb_setstatus(available, NULL, NULL); |
81 | 524 buddylist_build(); |
31 | 525 /* |
526 for (i = 0; i < clist.count; i++) { | |
527 c = (icqcontact *) clist.at(i); | |
528 | |
529 if (c->getdesc().pname == proto) | |
530 if (ischannel(c)) | |
531 if (c->getbasicinfo().requiresauth) | |
532 c->setstatus(available); | |
533 } | |
534 */ | |
535 | |
536 /* | |
537 agents.insert(agents.begin(), agent("vcard", "Jabber VCard", "", agent::atStandard)); | |
538 agents.begin()->params[agent::ptRegister].enabled = TRUE; | |
539 | |
540 string buf; | |
541 ifstream f(conf.getconfigfname("jabber-infoset").c_str()); | |
542 | |
543 if (f.is_open()) { | |
544 icqcontact *c = clist.get(contactroot); | |
545 | |
546 c->clear(); | |
547 icqcontact::basicinfo bi = c->getbasicinfo(); | |
548 icqcontact::reginfo ri = c->getreginfo(); | |
549 | |
550 ri.service = agents.begin()->name; | |
551 getstring(f, buf); c->setnick(buf); | |
552 getstring(f, buf); bi.email = buf; | |
553 getstring(f, buf); bi.fname = buf; | |
554 getstring(f, buf); bi.lname = buf; | |
555 f.close(); | |
556 | |
557 c->setbasicinfo(bi); | |
558 c->setreginfo(ri); | |
559 | |
560 sendupdateuserinfo(*c); | |
561 unlink(conf.getconfigfname("jabber-infoset").c_str()); | |
562 } | |
563 */ | |
564 } | |
565 | |
29 | 566 void gotloggedin(void) |
567 { | |
568 xmlnode x; | |
569 | |
570 x = jutil_iqnew(JPACKET__GET, NS_AGENTS); | |
571 xmlnode_put_attrib(x, "id", "Agent List"); | |
572 jab_send(jc, x); | |
573 xmlnode_free(x); | |
574 | |
575 x = jutil_iqnew(JPACKET__GET, NS_ROSTER); | |
576 xmlnode_put_attrib(x, "id", "Roster"); | |
577 jab_send(jc, x); | |
578 xmlnode_free(x); | |
579 } | |
580 | |
581 void gotroster(xmlnode x) | |
582 { | |
33 | 583 xmlnode y, z; |
29 | 584 |
585 for (y = xmlnode_get_tag(x, "item"); y; y = xmlnode_get_nextsibling(y)) { | |
586 const char *alias = xmlnode_get_attrib(y, "jid"); | |
51 | 587 //const char *sub = xmlnode_get_attrib(y, "subscription"); // TODO Not used |
29 | 588 const char *name = xmlnode_get_attrib(y, "name"); |
213 | 589 char *group = NULL; |
29 | 590 |
33 | 591 z = xmlnode_get_tag(y, "group"); |
592 if (z) group = xmlnode_get_data(z); | |
29 | 593 |
594 if (alias) { | |
35 | 595 char *buddyname; |
192 | 596 char *cleanalias = jidtodisp(alias); |
383
39c5da51b387
Remove utf8 files, use Glib
Mikael Berthe <mikael@lilotux.net>
parents:
374
diff
changeset
|
597 gchar *name_noutf8 = NULL; |
39c5da51b387
Remove utf8 files, use Glib
Mikael Berthe <mikael@lilotux.net>
parents:
374
diff
changeset
|
598 gchar *group_noutf8 = NULL; |
213 | 599 |
441
51b8f10cfeb8
Handle g_locale_from_utf8() failures
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
600 buddyname = cleanalias; |
213 | 601 if (name) { |
387
2bbeef7b4fdd
Do non UTF8-encode/decode null pointers
Mikael Berthe <mikael@lilotux.net>
parents:
384
diff
changeset
|
602 name_noutf8 = from_utf8(name); |
441
51b8f10cfeb8
Handle g_locale_from_utf8() failures
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
603 if (name_noutf8) buddyname = name_noutf8; |
51b8f10cfeb8
Handle g_locale_from_utf8() failures
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
604 } |
35 | 605 |
383
39c5da51b387
Remove utf8 files, use Glib
Mikael Berthe <mikael@lilotux.net>
parents:
374
diff
changeset
|
606 if (group) |
387
2bbeef7b4fdd
Do non UTF8-encode/decode null pointers
Mikael Berthe <mikael@lilotux.net>
parents:
384
diff
changeset
|
607 group_noutf8 = from_utf8(group); |
383
39c5da51b387
Remove utf8 files, use Glib
Mikael Berthe <mikael@lilotux.net>
parents:
374
diff
changeset
|
608 |
213 | 609 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
|
610 if (name_noutf8) g_free(name_noutf8); |
39c5da51b387
Remove utf8 files, use Glib
Mikael Berthe <mikael@lilotux.net>
parents:
374
diff
changeset
|
611 if (group_noutf8) g_free(group_noutf8); |
192 | 612 g_free(cleanalias); |
29 | 613 } |
614 } | |
615 | |
616 postlogin(); | |
617 } | |
618 | |
619 void gotmessage(char *type, const char *from, const char *body, | |
223 | 620 const char *enc, time_t timestamp) |
29 | 621 { |
113 | 622 char *jid; |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
623 const char *rname; |
387
2bbeef7b4fdd
Do non UTF8-encode/decode null pointers
Mikael Berthe <mikael@lilotux.net>
parents:
384
diff
changeset
|
624 gchar *buffer = from_utf8(body); |
29 | 625 |
441
51b8f10cfeb8
Handle g_locale_from_utf8() failures
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
626 jid = jidtodisp(from); |
51b8f10cfeb8
Handle g_locale_from_utf8() failures
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
627 |
51b8f10cfeb8
Handle g_locale_from_utf8() failures
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
628 if (!buffer && body) { |
51b8f10cfeb8
Handle g_locale_from_utf8() failures
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
629 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
|
630 from); |
51b8f10cfeb8
Handle g_locale_from_utf8() failures
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
631 scr_WriteIncomingMessage(jid, "Cannot display message: " |
51b8f10cfeb8
Handle g_locale_from_utf8() failures
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
632 "UTF-8 conversion failure", |
51b8f10cfeb8
Handle g_locale_from_utf8() failures
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
633 0, HBB_PREFIX_ERR | HBB_PREFIX_IN); |
51b8f10cfeb8
Handle g_locale_from_utf8() failures
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
634 g_free(jid); |
51b8f10cfeb8
Handle g_locale_from_utf8() failures
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
635 return; |
51b8f10cfeb8
Handle g_locale_from_utf8() failures
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
636 } |
51b8f10cfeb8
Handle g_locale_from_utf8() failures
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
637 |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
638 rname = strchr(from, '/'); |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
639 if (rname) rname++; |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
640 hk_message_in(jid, rname, timestamp, buffer, type); |
192 | 641 g_free(jid); |
383
39c5da51b387
Remove utf8 files, use Glib
Mikael Berthe <mikael@lilotux.net>
parents:
374
diff
changeset
|
642 g_free(buffer); |
29 | 643 } |
644 | |
426
2706ef3e25a7
Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents:
421
diff
changeset
|
645 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
|
646 { |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
647 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
|
648 |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
649 switch(code) { |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
650 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
|
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 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
|
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 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
|
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 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
|
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 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
|
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 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
|
661 break; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
662 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
|
663 break; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
664 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
|
665 break; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
666 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
|
667 break; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
668 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
|
669 break; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
670 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
|
671 break; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
672 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
|
673 break; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
674 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
|
675 break; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
676 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
|
677 break; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
678 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
|
679 break; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
680 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
|
681 break; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
682 default: |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
683 desc = NULL; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
684 } |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
685 |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
686 return desc; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
687 } |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
688 |
430
d03663d2e7d9
Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents:
426
diff
changeset
|
689 // display_server_error(x) |
d03663d2e7d9
Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents:
426
diff
changeset
|
690 // 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
|
691 // x: error tag xmlnode pointer |
426
2706ef3e25a7
Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents:
421
diff
changeset
|
692 void display_server_error(xmlnode x) |
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 const char *desc = NULL; |
d03663d2e7d9
Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents:
426
diff
changeset
|
695 int code = 0; |
426
2706ef3e25a7
Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents:
421
diff
changeset
|
696 char *s; |
430
d03663d2e7d9
Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents:
426
diff
changeset
|
697 const char *p; |
426
2706ef3e25a7
Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents:
421
diff
changeset
|
698 |
430
d03663d2e7d9
Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents:
426
diff
changeset
|
699 /* RFC3920: |
d03663d2e7d9
Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents:
426
diff
changeset
|
700 * The <error/> element: |
d03663d2e7d9
Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents:
426
diff
changeset
|
701 * 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
|
702 * 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
|
703 * 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
|
704 */ |
d03663d2e7d9
Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents:
426
diff
changeset
|
705 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
|
706 if (p) |
d03663d2e7d9
Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents:
426
diff
changeset
|
707 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
|
708 |
d03663d2e7d9
Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents:
426
diff
changeset
|
709 // For backward compatibility |
426
2706ef3e25a7
Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents:
421
diff
changeset
|
710 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
|
711 code = atoi(s); |
2706ef3e25a7
Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents:
421
diff
changeset
|
712 // Default message |
430
d03663d2e7d9
Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents:
426
diff
changeset
|
713 desc = defaulterrormsg(code); |
d03663d2e7d9
Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents:
426
diff
changeset
|
714 } |
426
2706ef3e25a7
Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents:
421
diff
changeset
|
715 |
430
d03663d2e7d9
Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents:
426
diff
changeset
|
716 // 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
|
717 s = xmlnode_get_data(x); |
d03663d2e7d9
Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents:
426
diff
changeset
|
718 if (s && *s) desc = s; |
426
2706ef3e25a7
Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents:
421
diff
changeset
|
719 |
430
d03663d2e7d9
Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents:
426
diff
changeset
|
720 // 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
|
721 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
|
722 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
|
723 |
430
d03663d2e7d9
Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents:
426
diff
changeset
|
724 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
|
725 } |
2706ef3e25a7
Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents:
421
diff
changeset
|
726 |
31 | 727 void statehandler(jconn conn, int state) |
728 { | |
729 static int previous_state = -1; | |
730 | |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
731 scr_LogPrint(LPRINT_DEBUG, "StateHandler called (state=%d).", state); |
31 | 732 |
733 switch(state) { | |
734 case JCONN_STATE_OFF: | |
192 | 735 if (previous_state != JCONN_STATE_OFF) |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
736 scr_LogPrint(LPRINT_LOGNORM, "[Jabber] Not connected to the server"); |
37 | 737 |
112 | 738 online = FALSE; |
159 | 739 mystatus = offline; |
164 | 740 roster_free(); |
741 update_roster = TRUE; | |
31 | 742 break; |
743 | |
744 case JCONN_STATE_CONNECTED: | |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
745 scr_LogPrint(LPRINT_LOGNORM, "[Jabber] Connected to the server"); |
31 | 746 break; |
747 | |
748 case JCONN_STATE_AUTH: | |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
749 scr_LogPrint(LPRINT_LOGNORM, "[Jabber] Authenticating to the server"); |
31 | 750 break; |
751 | |
752 case JCONN_STATE_ON: | |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
753 scr_LogPrint(LPRINT_LOGNORM, "[Jabber] Communication with the server " |
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
754 "established"); |
112 | 755 online = TRUE; |
31 | 756 break; |
757 | |
35 | 758 case JCONN_STATE_CONNECTING: |
357
e8adc3c96e68
Better messages for server connection states
Mikael Berthe <mikael@lilotux.net>
parents:
353
diff
changeset
|
759 if (previous_state != state) |
408
73433860665c
Tune previous usleep() change
Mikael Berthe <mikael@lilotux.net>
parents:
407
diff
changeset
|
760 scr_LogPrint(LPRINT_LOGNORM, "[Jabber] Connecting to the server"); |
35 | 761 break; |
762 | |
31 | 763 default: |
764 break; | |
765 } | |
766 previous_state = state; | |
767 } | |
768 | |
769 void packethandler(jconn conn, jpacket packet) | |
770 { | |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
771 char *p, *r, *s; |
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
436
diff
changeset
|
772 const char *m, *rname; |
37 | 773 xmlnode x, y; |
31 | 774 char *from=NULL, *type=NULL, *body=NULL, *enc=NULL; |
775 char *ns=NULL; | |
776 char *id=NULL; | |
35 | 777 enum imstatus ust; |
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
436
diff
changeset
|
778 char bpprio; |
31 | 779 |
112 | 780 jb_reset_keepalive(); // reset keepalive delay |
31 | 781 jpacket_reset(packet); |
782 | |
783 p = xmlnode_get_attrib(packet->x, "from"); if (p) from = p; | |
784 p = xmlnode_get_attrib(packet->x, "type"); if (p) type = p; | |
785 | |
786 switch (packet->type) { | |
787 case JPACKET_MESSAGE: | |
52 | 788 { |
789 char *tmp = NULL; | |
223 | 790 time_t timestamp = 0; |
791 | |
52 | 792 x = xmlnode_get_tag(packet->x, "body"); |
793 p = xmlnode_get_data(x); if (p) body = p; | |
31 | 794 |
52 | 795 if ((x = xmlnode_get_tag(packet->x, "subject")) != NULL) |
796 if ((p = xmlnode_get_data(x)) != NULL) { | |
165 | 797 tmp = g_new(char, strlen(body)+strlen(p)+4); |
52 | 798 *tmp = '['; |
799 strcpy(tmp+1, p); | |
800 strcat(tmp, "]\n"); | |
801 strcat(tmp, body); | |
802 body = tmp; | |
803 } | |
804 | |
805 /* there can be multiple <x> tags. we're looking for one with | |
806 xmlns = jabber:x:encrypted */ | |
807 | |
420
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
808 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
|
809 for ( ; x; x = xmlnode_get_nextsibling(x)) { |
52 | 810 if ((p = xmlnode_get_name(x)) && !strcmp(p, "x")) |
811 if ((p = xmlnode_get_attrib(x, "xmlns")) && | |
812 !strcasecmp(p, "jabber:x:encrypted")) | |
813 if ((p = xmlnode_get_data(x)) != NULL) { | |
814 enc = p; | |
815 break; | |
816 } | |
31 | 817 } |
818 | |
223 | 819 // Timestamp? |
820 if ((x = xmlnode_get_tag(packet->x, "x")) != NULL) { | |
241 | 821 if ((p = xmlnode_get_attrib(x, "stamp")) != NULL) |
822 timestamp = from_iso8601(p, 1); | |
223 | 823 } |
824 | |
420
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
825 if (type && !strcmp(type, "error")) { |
426
2706ef3e25a7
Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents:
421
diff
changeset
|
826 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
|
827 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
|
828 } |
165 | 829 if (from && body) |
223 | 830 gotmessage(type, from, body, enc, timestamp); |
52 | 831 if (tmp) |
159 | 832 g_free(tmp); |
31 | 833 } |
834 break; | |
835 | |
836 case JPACKET_IQ: | |
837 if (!strcmp(type, "result")) { | |
838 | |
51 | 839 if ((p = xmlnode_get_attrib(packet->x, "id")) != NULL) { |
31 | 840 int iid = atoi(p); |
841 | |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
842 scr_LogPrint(LPRINT_DEBUG, "iid = %d", iid); |
31 | 843 if (iid == s_id) { |
844 if (!regmode) { | |
845 if (jstate == STATE_GETAUTH) { | |
51 | 846 if ((x = xmlnode_get_tag(packet->x, "query")) != NULL) |
31 | 847 if (!xmlnode_get_tag(x, "digest")) { |
848 jc->sid = 0; | |
849 } | |
850 | |
851 s_id = atoi(jab_auth(jc)); | |
852 jstate = STATE_SENDAUTH; | |
853 } else { | |
854 gotloggedin(); | |
855 jstate = STATE_LOGGED; | |
856 } | |
857 } else { | |
858 regdone = TRUE; | |
859 } | |
860 return; | |
861 } | |
862 | |
863 if (!strcmp(p, "VCARDreq")) { | |
864 x = xmlnode_get_firstchild(packet->x); | |
865 if (!x) x = packet->x; | |
866 | |
867 //jhook.gotvcard(ic, x); TODO | |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
868 scr_LogPrint(LPRINT_LOGNORM, "Got VCARD"); |
31 | 869 return; |
870 } else if (!strcmp(p, "versionreq")) { | |
871 // jhook.gotversion(ic, packet->x); TODO | |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
872 scr_LogPrint(LPRINT_LOGNORM, "Got version"); |
31 | 873 return; |
874 } | |
875 } | |
876 | |
51 | 877 if ((x = xmlnode_get_tag(packet->x, "query")) != NULL) { |
31 | 878 p = xmlnode_get_attrib(x, "xmlns"); if (p) ns = p; |
879 | |
880 if (!strcmp(ns, NS_ROSTER)) { | |
881 gotroster(x); | |
882 } else if (!strcmp(ns, NS_AGENTS)) { | |
883 for (y = xmlnode_get_tag(x, "agent"); y; y = xmlnode_get_nextsibling(y)) { | |
884 const char *alias = xmlnode_get_attrib(y, "jid"); | |
885 | |
886 if (alias) { | |
887 const char *name = xmlnode_get_tag_data(y, "name"); | |
888 const char *desc = xmlnode_get_tag_data(y, "description"); | |
51 | 889 // const char *service = xmlnode_get_tag_data(y, "service"); TODO |
37 | 890 enum agtype atype = unknown; |
31 | 891 |
37 | 892 if (xmlnode_get_tag(y, "groupchat")) atype = groupchat; else |
893 if (xmlnode_get_tag(y, "transport")) atype = transport; else | |
894 if (xmlnode_get_tag(y, "search")) atype = search; | |
31 | 895 |
192 | 896 if (atype == transport) { |
897 char *cleanjid = jidtodisp(alias); | |
194 | 898 roster_add_user(cleanjid, NULL, JABBER_AGENT_GROUP, |
899 ROSTER_TYPE_AGENT); | |
192 | 900 g_free(cleanjid); |
901 } | |
31 | 902 if (alias && name && desc) { |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
903 scr_LogPrint(LPRINT_LOGNORM, "Agent: %s / %s / %s / type=%d", |
37 | 904 alias, name, desc, atype); |
31 | 905 |
37 | 906 if (atype == search) { |
31 | 907 x = jutil_iqnew (JPACKET__GET, NS_SEARCH); |
908 xmlnode_put_attrib(x, "to", alias); | |
909 xmlnode_put_attrib(x, "id", "Agent info"); | |
910 jab_send(conn, x); | |
911 xmlnode_free(x); | |
912 } | |
913 | |
914 if (xmlnode_get_tag(y, "register")) { | |
915 x = jutil_iqnew (JPACKET__GET, NS_REGISTER); | |
916 xmlnode_put_attrib(x, "to", alias); | |
917 xmlnode_put_attrib(x, "id", "Agent info"); | |
918 jab_send(conn, x); | |
919 xmlnode_free(x); | |
920 } | |
921 } | |
922 } | |
923 } | |
924 | |
37 | 925 /* |
31 | 926 if (find(jhook.agents.begin(), jhook.agents.end(), DEFAULT_CONFSERV) == jhook.agents.end()) |
927 jhook.agents.insert(jhook.agents.begin(), agent(DEFAULT_CONFSERV, DEFAULT_CONFSERV, | |
928 _("Default Jabber conference server"), agent::atGroupchat)); | |
929 | |
930 */ | |
931 } else if (!strcmp(ns, NS_SEARCH) || !strcmp(ns, NS_REGISTER)) { | |
932 p = xmlnode_get_attrib(packet->x, "id"); id = p ? p : (char*)""; | |
933 | |
934 if (!strcmp(id, "Agent info")) { | |
935 // jhook.gotagentinfo(packet->x); TODO | |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
936 scr_LogPrint(LPRINT_LOGNORM, "Got agent info"); |
31 | 937 } else if (!strcmp(id, "Lookup")) { |
938 // jhook.gotsearchresults(packet->x); TODO | |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
939 scr_LogPrint(LPRINT_LOGNORM, "Got search results"); |
31 | 940 } else if (!strcmp(id, "Register")) { |
941 x = jutil_iqnew(JPACKET__GET, NS_REGISTER); | |
942 xmlnode_put_attrib(x, "to", from); | |
943 xmlnode_put_attrib(x, "id", "Agent info"); | |
944 jab_send(conn, x); | |
945 xmlnode_free(x); | |
946 } | |
947 | |
948 } | |
949 } | |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
950 } else if (!strcmp(type, "get")) { |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
951 p = xmlnode_get_attrib(packet->x, "id"); |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
952 if (p) { |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
953 xmlnode z; |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
954 |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
955 id = p; |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
956 x = xmlnode_new_tag("iq"); |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
957 xmlnode_put_attrib(x, "type", "result"); |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
958 xmlnode_put_attrib(x, "to", from); |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
959 xmlnode_put_attrib(x, "id", id); |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
960 xmlnode_put_attrib(x, "type", "error"); |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
961 y = xmlnode_insert_tag(x, "error"); |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
962 xmlnode_put_attrib(y, "code", "503"); |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
963 xmlnode_put_attrib(y, "type", "cancel"); |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
964 z = xmlnode_insert_tag(y, "feature-not-implemented"); |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
965 xmlnode_put_attrib(z, "xmlns", |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
966 "urn:ietf:params:xml:ns:xmpp-stanzas"); |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
967 jab_send(conn, x); |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
968 xmlnode_free(x); |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
969 } |
31 | 970 } else if (!strcmp(type, "set")) { |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
971 /* FIXME: send error */ |
31 | 972 } else if (!strcmp(type, "error")) { |
426
2706ef3e25a7
Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents:
421
diff
changeset
|
973 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
|
974 display_server_error(x); |
31 | 975 } |
976 break; | |
977 | |
978 case JPACKET_PRESENCE: | |
426
2706ef3e25a7
Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents:
421
diff
changeset
|
979 r = jidtodisp(from); |
2706ef3e25a7
Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents:
421
diff
changeset
|
980 if (type && !strcmp(type, "error")) { |
2706ef3e25a7
Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents:
421
diff
changeset
|
981 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
|
982 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
|
983 display_server_error(x); |
2706ef3e25a7
Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents:
421
diff
changeset
|
984 g_free(r); |
2706ef3e25a7
Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents:
421
diff
changeset
|
985 break; |
2706ef3e25a7
Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents:
421
diff
changeset
|
986 } |
31 | 987 |
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
436
diff
changeset
|
988 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
|
989 if (p && *p) bpprio = (gchar)atoi(p); |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
436
diff
changeset
|
990 else bpprio = 0; |
31 | 991 |
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
436
diff
changeset
|
992 ust = available; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
436
diff
changeset
|
993 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
|
994 if (p) { |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
436
diff
changeset
|
995 if (!strcmp(p, "away")) ust = away; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
436
diff
changeset
|
996 else if (!strcmp(p, "dnd")) ust = dontdisturb; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
436
diff
changeset
|
997 else if (!strcmp(p, "xa")) ust = notavail; |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
436
diff
changeset
|
998 else if (!strcmp(p, "chat")) ust = freeforchat; |
31 | 999 } |
1000 | |
321
59193965f2cb
Convert status messages to/from UTF-8
Mikael Berthe <mikael@lilotux.net>
parents:
319
diff
changeset
|
1001 if (type && !strcmp(type, "unavailable")) |
35 | 1002 ust = offline; |
31 | 1003 |
221 | 1004 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
|
1005 s = from_utf8(xmlnode_get_data(x)); |
221 | 1006 else |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
1007 s = NULL; |
221 | 1008 |
318
45076d02eeef
The /status command can specify a status message
Mikael Berthe <mikael@lilotux.net>
parents:
311
diff
changeset
|
1009 // 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
|
1010 // status message is different |
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
436
diff
changeset
|
1011 rname = strchr(from, '/'); |
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
436
diff
changeset
|
1012 if (rname) rname++; |
447
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 // Check for MUC presence packet |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
1015 // There can be multiple <x> tags!! |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
1016 x = xmlnode_get_firstchild(packet->x); |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
1017 for ( ; x; x = xmlnode_get_nextsibling(x)) { |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
1018 if ((p = xmlnode_get_name(x)) && !strcmp(p, "x")) |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
1019 if ((p = xmlnode_get_attrib(x, "xmlns")) && |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
1020 !strncasecmp(p, "http://jabber.org/protocol/muc", 30)) |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
1021 break; |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
1022 } |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
1023 if (x) { // This is a MUC presence message |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
1024 roster_add_user(r, NULL, NULL, ROSTER_TYPE_ROOM); |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
1025 |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
1026 if (rname) |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
1027 roster_setstatus(r, rname, bpprio, ust, NULL); |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
1028 else |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
1029 scr_LogPrint(LPRINT_LOGNORM, "MUC DBG: no rname!"); /* DBG */ |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
1030 |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
1031 buddylist_build(); |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
1032 scr_DrawRoster(); |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
1033 break; |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
1034 } |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
1035 |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
1036 // 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
|
1037 m = roster_getstatusmsg(r, rname); |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
1038 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
|
1039 hk_statuschange(r, rname, bpprio, 0, ust, s); |
159 | 1040 g_free(r); |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
1041 if (s) g_free(s); |
31 | 1042 break; |
1043 | |
1044 case JPACKET_S10N: | |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
1045 scr_LogPrint(LPRINT_LOGNORM, "Received (un)subscription packet " |
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
1046 "(type=%s)", ((type) ? type : "")); |
31 | 1047 |
43 | 1048 if (!strcmp(type, "subscribe")) { |
91 | 1049 int isagent; |
1050 r = jidtodisp(from); | |
1051 isagent = (roster_gettype(r) & ROSTER_TYPE_AGENT) != 0; | |
159 | 1052 g_free(r); |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
1053 scr_LogPrint(LPRINT_LOGNORM, "isagent=%d", isagent); // XXX DBG |
91 | 1054 if (!isagent) { |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
1055 scr_LogPrint(LPRINT_LOGNORM, "<%s> wants to subscribe " |
43 | 1056 "to your network presence updates", from); |
125 | 1057 // FIXME we accept everybody... |
1058 x = jutil_presnew(JPACKET__SUBSCRIBED, from, 0); | |
1059 jab_send(jc, x); | |
1060 xmlnode_free(x); | |
91 | 1061 } else { |
1062 x = jutil_presnew(JPACKET__SUBSCRIBED, from, 0); | |
31 | 1063 jab_send(jc, x); |
1064 xmlnode_free(x); | |
91 | 1065 } |
43 | 1066 } else if (!strcmp(type, "unsubscribe")) { |
1067 x = jutil_presnew(JPACKET__UNSUBSCRIBED, from, 0); | |
31 | 1068 jab_send(jc, x); |
1069 xmlnode_free(x); | |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
1070 scr_LogPrint(LPRINT_LOGNORM, "<%s> has unsubscribed to " |
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
1071 "your presence updates", from); |
31 | 1072 } |
1073 break; | |
1074 | |
1075 default: | |
1076 break; | |
1077 } | |
1078 } | |
1079 |