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