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