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