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