Mercurial > pidgin
annotate src/protocols/jabber/jabber.c @ 5135:102135caa225
[gaim-migrate @ 5499]
make use of KingAnt's uber-cool new notauthorized emblem, and let the prpls
stick text into the status line of the buddy to replace "Offline" if they
care to do so
committer: Tailor Script <tailor@pidgin.im>
author | Nathan Walp <nwalp@pidgin.im> |
---|---|
date | Tue, 15 Apr 2003 03:45:31 +0000 |
parents | 463b03cd8c90 |
children | 381da05cb5ed |
rev | line source |
---|---|
2086 | 1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ |
2 /* | |
3 * gaim | |
4 * | |
5 * Some code copyright (C) 1998-1999, Mark Spencer <markster@marko.net> | |
6 * libfaim code copyright 1998, 1999 Adam Fritzler <afritz@auk.cx> | |
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 | |
11 * (at your option) any later version. | |
12 * This program is distributed in the hope that it will be useful, | |
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 * GNU General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU General Public License | |
18 * along with this program; if not, write to the Free Software | |
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
20 * | |
21 */ | |
22 #ifdef HAVE_CONFIG_H | |
3630 | 23 #include <config.h> |
2086 | 24 #endif |
25 | |
3664 | 26 #include <sys/types.h> |
27 /*this must happen before sys/socket.h or freebsd won't compile*/ | |
28 | |
3630 | 29 #ifndef _WIN32 |
2086 | 30 #include <netdb.h> |
31 #include <netinet/in.h> | |
32 #include <arpa/inet.h> | |
3630 | 33 #include <sys/socket.h> |
34 #include <sys/utsname.h> | |
35 #include <unistd.h> | |
36 #else | |
37 #include "utsname.h" | |
38 #endif | |
39 | |
40 #include <errno.h> | |
2086 | 41 #include <string.h> |
42 #include <stdlib.h> | |
43 #include <stdio.h> | |
44 #include <time.h> | |
45 #include <sys/stat.h> | |
4608 | 46 #include "gaim.h" |
2086 | 47 #include "multi.h" |
48 #include "prpl.h" | |
2232
14e8978f86bb
[gaim-migrate @ 2242]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2231
diff
changeset
|
49 #ifdef MAX |
14e8978f86bb
[gaim-migrate @ 2242]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2231
diff
changeset
|
50 #undef MAX |
14e8978f86bb
[gaim-migrate @ 2242]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2231
diff
changeset
|
51 #endif |
14e8978f86bb
[gaim-migrate @ 2242]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2231
diff
changeset
|
52 #ifdef MIN |
14e8978f86bb
[gaim-migrate @ 2242]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2231
diff
changeset
|
53 #undef MIN |
14e8978f86bb
[gaim-migrate @ 2242]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2231
diff
changeset
|
54 #endif |
2086 | 55 #include "jabber.h" |
56 #include "proxy.h" | |
57 | |
3630 | 58 #ifdef _WIN32 |
59 #include "win32dep.h" | |
60 #endif | |
61 | |
4249 | 62 static struct prpl *my_protocol = NULL; |
63 | |
3630 | 64 /* for win32 compatability */ |
65 G_MODULE_IMPORT GSList *connections; | |
66 | |
2086 | 67 /* The priv member of gjconn's is a gaim_connection for now. */ |
68 #define GJ_GC(x) ((struct gaim_connection *)(x)->priv) | |
4249 | 69 /* Confused? That makes three of us. -Robot101 */ |
70 #define GC_GJ(x) ((gjconn)((struct jabber_data *)(x)->proto_data)->gjc) | |
2086 | 71 |
72 #define IQID_AUTH "__AUTH__" | |
73 | |
74 #define IQ_NONE -1 | |
75 #define IQ_AUTH 0 | |
76 #define IQ_ROSTER 1 | |
77 | |
3259 | 78 #define UC_AWAY (0x02 | UC_UNAVAILABLE) |
79 #define UC_CHAT 0x04 | |
80 #define UC_XA (0x08 | UC_UNAVAILABLE) | |
81 #define UC_DND (0x10 | UC_UNAVAILABLE) | |
82 #define UC_ERROR (0x20 | UC_UNAVAILABLE) | |
2086 | 83 |
4917 | 84 #define DEFAULT_SERVER "jabber.org" |
2086 | 85 #define DEFAULT_GROUPCHAT "conference.jabber.org" |
86 #define DEFAULT_PORT 5222 | |
87 | |
88 #define USEROPT_PORT 0 | |
4436 | 89 #define USEROPT_CONN_SERVER 1 |
2086 | 90 |
3311 | 91 #define JABBER_TYPING_NOTIFY_INT 15 /* Delay (in seconds) between sending typing notifications */ |
92 | |
4450 | 93 #define JABBER_KEEPALIVE_STRING " \t " |
94 | |
3074 | 95 /* |
96 * Note: "was_connected" may seem redundant, but it was needed and I | |
97 * didn't want to touch the Jabber state stuff not specific to Gaim. | |
98 */ | |
2086 | 99 typedef struct gjconn_struct { |
100 /* Core structure */ | |
101 pool p; /* Memory allocation pool */ | |
102 int state; /* Connection state flag */ | |
3074 | 103 int was_connected; /* We were once connected */ |
2086 | 104 int fd; /* Connection file descriptor */ |
105 jid user; /* User info */ | |
106 char *pass; /* User passwd */ | |
107 | |
108 /* Stream stuff */ | |
109 int id; /* id counter for jab_getid() function */ | |
110 char idbuf[9]; /* temporary storage for jab_getid() */ | |
111 char *sid; /* stream id from server, for digest auth */ | |
112 XML_Parser parser; /* Parser instance */ | |
113 xmlnode current; /* Current node in parsing instance.. */ | |
114 | |
115 /* Event callback ptrs */ | |
2956 | 116 void (*on_state)(struct gjconn_struct *gjc, int state); |
117 void (*on_packet)(struct gjconn_struct *gjc, jpacket p); | |
118 | |
119 GHashTable *queries; /* query tracker */ | |
2086 | 120 |
121 void *priv; | |
122 | |
123 } *gjconn, gjconn_struct; | |
124 | |
2956 | 125 typedef void (*gjconn_state_h)(gjconn gjc, int state); |
126 typedef void (*gjconn_packet_h)(gjconn gjc, jpacket p); | |
2086 | 127 |
128 static gjconn gjab_new(char *user, char *pass, void *priv); | |
2956 | 129 static void gjab_delete(gjconn gjc); |
130 static void gjab_state_handler(gjconn gjc, gjconn_state_h h); | |
131 static void gjab_packet_handler(gjconn gjc, gjconn_packet_h h); | |
132 static void gjab_start(gjconn gjc); | |
133 static void gjab_stop(gjconn gjc); | |
2086 | 134 /* |
2956 | 135 static int gjab_getfd(gjconn gjc); |
136 static jid gjab_getjid(gjconn gjc); | |
137 static char *gjab_getsid(gjconn gjc); | |
2086 | 138 */ |
2956 | 139 static char *gjab_getid(gjconn gjc); |
140 static void gjab_send(gjconn gjc, xmlnode x); | |
141 static void gjab_send_raw(gjconn gjc, const char *str); | |
142 static void gjab_recv(gjconn gjc); | |
143 static void gjab_auth(gjconn gjc); | |
144 | |
145 /* | |
146 * It is *this* to which we point the gaim_connection proto_data | |
147 */ | |
2086 | 148 struct jabber_data { |
2956 | 149 gjconn gjc; |
2086 | 150 gboolean did_import; |
2956 | 151 GSList *chats; |
2086 | 152 time_t idle; |
2800
0ad63a625eec
[gaim-migrate @ 2813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2791
diff
changeset
|
153 gboolean die; |
3311 | 154 GHashTable *buddies; |
3630 | 155 GSList *file_transfers; |
2086 | 156 }; |
157 | |
2956 | 158 /* |
3340 | 159 * Used in jabber_buddy_data.invisible, below |
160 */ | |
161 #define JABBER_NOT_INVIS 0x00 | |
162 #define JABBER_SERV_INVIS 0x01 /* Invisible set on server */ | |
163 #define JABBER_BUD_INVIS 0x02 /* Invisible set on buddy */ | |
164 | |
165 /* | |
4927 | 166 * Used in jabber_buddy_data.subscription, below |
167 */ | |
168 #define JABBER_SUB_NONE 0x0 | |
169 #define JABBER_SUB_PENDING 0x1 | |
170 #define JABBER_SUB_TO 0x2 | |
171 #define JABBER_SUB_FROM 0x4 | |
172 #define JABBER_SUB_BOTH (JABBER_SUB_TO | JABBER_SUB_FROM) | |
173 | |
174 | |
175 /* | |
3311 | 176 * It is *this* to which we point the buddy proto_data |
177 */ | |
178 struct jabber_buddy_data { | |
179 GSList *resources; | |
180 char *error_msg; | |
3340 | 181 unsigned invisible; /* We've set presence type invisible for this buddy */ |
4927 | 182 unsigned subscription; /* subscription type for this buddy */ |
3311 | 183 }; |
184 | |
185 /* | |
186 * per-resource info | |
187 */ | |
188 typedef struct jabber_resource_info { | |
3770 | 189 char *name; |
3311 | 190 int priority; |
191 int state; | |
192 char *away_msg; | |
193 char *thread_id; | |
194 gboolean has_composing; | |
5093 | 195 gboolean has_xhtml; |
3311 | 196 } *jab_res_info; |
197 | |
198 /* | |
199 * For our own jid handling | |
200 * | |
201 * We do our own so we can cleanly parse buddy names | |
202 * (user@server/resource) and rid ourselves of the | |
203 * struct when we're done with it. The Jabber lib | |
204 * structs last the life of the pool--we frequently | |
205 * don't want that. | |
206 * | |
207 * We use the real jid structs so we can make use of | |
208 * jid_safe(), jid_cmp() and some others. | |
209 * | |
210 * BE CAREFUL using the Jabber lib routines. | |
211 * Many of them assume pool use and are not | |
212 * amenable to use with our own! | |
213 * | |
214 * We give them special names so we know, throughout | |
215 * the code, that they're not alloc'd out of pool | |
216 * memory and we can, and must, dispose of them when | |
217 * we're done with 'em. | |
218 */ | |
219 #define gaim_jid_struct jid_struct | |
220 typedef struct gaim_jid_struct *gaim_jid; | |
221 | |
222 /* | |
2956 | 223 * Jabber "chat group" info. Pointers to these go in jabber_data |
224 * pending and existing chats lists. | |
225 */ | |
2086 | 226 struct jabber_chat { |
3311 | 227 gaim_jid gjid; |
2086 | 228 struct gaim_connection *gc; |
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4357
diff
changeset
|
229 struct gaim_conversation *b; |
2086 | 230 int id; |
2956 | 231 int state; |
2086 | 232 }; |
233 | |
2956 | 234 /* |
235 * Jabber chat states... | |
236 * | |
237 * Note: due to a bug in one version of the Jabber server, subscriptions | |
238 * to chat groups aren't (always?) properly removed at the server. The | |
239 * result is clients receive Jabber "presence" notifications for JIDs | |
240 * they no longer care about. The problem with such vestigial notifies is | |
241 * that we really have no way of telling if it's vestigial or if it's a | |
242 * valid "buddy" presence notification. So we keep jabber_chat structs | |
243 * around after leaving a chat group and simply mark them "closed." That | |
244 * way we can test for such errant presence notifications. I.e.: if we | |
245 * get a presence notfication from a JID that matches a chat group JID, | |
246 * we disregard it. | |
247 */ | |
248 #define JCS_PENDING 1 /* pending */ | |
249 #define JCS_ACTIVE 2 /* active */ | |
250 #define JCS_CLOSED 3 /* closed */ | |
251 | |
252 | |
253 #define STATE_EVT(arg) if(gjc->on_state) { (gjc->on_state)(gjc, (arg) ); } | |
254 | |
255 static void jabber_handlevcard(gjconn, xmlnode, char *); | |
2086 | 256 |
3630 | 257 static char *jabber_normalize(const char *s); |
258 | |
2086 | 259 static char *create_valid_jid(const char *given, char *server, char *resource) |
260 { | |
261 char *valid; | |
4927 | 262 char *tmp; |
263 | |
264 if (!(tmp = strchr(given, '@'))) | |
2086 | 265 valid = g_strdup_printf("%s@%s/%s", given, server, resource); |
4927 | 266 else if (!strchr(tmp, '/')) |
2086 | 267 valid = g_strdup_printf("%s/%s", given, resource); |
268 else | |
269 valid = g_strdup(given); | |
270 | |
271 return valid; | |
272 } | |
273 | |
4915 | 274 |
3311 | 275 /* |
276 * Dispose of a gaim_jid_struct | |
277 */ | |
278 static void gaim_jid_free(gaim_jid gjid) | |
279 { | |
280 if(gjid) { | |
281 if(gjid->resource) | |
282 free(gjid->resource); | |
283 if(gjid->user) | |
284 free(gjid->user); | |
285 if(gjid->server) | |
286 free(gjid->server); | |
287 if(gjid->full) | |
288 free(gjid->full); | |
289 free(gjid); | |
290 } | |
291 } | |
292 | |
293 /* | |
294 * Create a new gjid struct | |
295 * | |
296 * Unlike jid_new(), also creates "full." | |
297 * | |
298 * Shamelessly copied, in part, from jid.c: jid_new() | |
299 * | |
300 * Caller is responsible for freeing the space allocated by this via | |
301 * gaim_jid_free(). | |
302 * | |
303 * JFIXME: Has a local declaration for jid.c:jid_safe(). I've put in a | |
304 * request to have that added to libjabber's lib.h file. (JSeymour) | |
305 */ | |
306 static gaim_jid gaim_jid_new(char *name) | |
307 { | |
308 extern jid jid_safe(jid); /* *retch* */ | |
309 | |
310 gaim_jid gjid = NULL; | |
311 | |
312 if(name && strlen(name)) { | |
313 char *server, *resource, *type, *str; | |
314 int full_len = 0; | |
315 | |
316 /* user@server/resource */ | |
317 | |
318 str = strdup(name); /* we mangle a copy */ | |
319 | |
320 gjid = calloc(1, sizeof(struct gaim_jid_struct)); | |
321 | |
322 if((resource = strstr(str, "/")) != NULL) { | |
323 *resource = '\0'; | |
324 ++resource; | |
325 if((full_len = strlen(resource)) > 0) { | |
326 gjid->resource = strdup(resource); | |
327 ++full_len; /* for later "/" addition */ | |
328 } | |
329 } else { | |
330 resource = str + strlen(str); /* point to end */ | |
331 } | |
332 | |
333 type = strstr(str, ":"); | |
334 if(type != NULL && type < resource) { | |
335 *type = '\0'; | |
336 ++type; | |
337 str = type; /* ignore the type: prefix */ | |
338 } | |
339 | |
340 server = strstr(str, "@"); | |
341 | |
342 /* | |
343 * if there's no @, it's just the server address | |
344 */ | |
345 if(server == NULL || server > resource) { | |
346 gjid->server = strdup(str); | |
347 full_len += strlen(str); | |
348 } else { | |
349 *server = '\0'; | |
350 ++server; | |
351 gjid->server = strdup(server); | |
352 full_len += strlen(server) + 1; /* account for later "@" */ | |
353 if(strlen(str) > 0) { | |
354 gjid->user = strdup(str); | |
355 full_len += strlen(str); | |
356 } | |
357 } | |
358 | |
359 free(str); | |
360 | |
361 if(!jid_safe(gjid)) { | |
362 gaim_jid_free(gjid); | |
363 gjid = NULL; | |
364 } else { | |
365 if(full_len) { | |
366 char *s = gjid->full = malloc(++full_len); | |
367 | |
368 if(gjid->user) { | |
369 strcpy(s, gjid->user); | |
370 s += strlen(gjid->user); | |
371 } | |
372 if(gjid->server) { | |
373 if(s > gjid->full) | |
374 *(s++) = '@'; | |
375 strcpy(s, gjid->server); | |
376 s += strlen(gjid->server); | |
377 } | |
378 if(gjid->resource) { | |
379 *(s++) = '/'; | |
380 strcpy(s, gjid->resource); | |
381 } | |
382 } | |
383 } | |
384 } | |
385 | |
386 return gjid; | |
387 } | |
388 | |
389 /* | |
390 * Get a "username@server" from unadorned "username" | |
391 * | |
392 * If there's no "@server" part and "who" doesn't match the | |
393 * gjconn server (which would indicate that "who" *is* the | |
394 * server in case of server messages), the gjconn server is | |
395 * appended. | |
396 * | |
397 * If incl_resource is TRUE (non-0), the returned string | |
398 * includes the "/resource" part (if it exists), otherwise not. | |
399 * | |
400 * Allocates space for returned string. Caller is | |
401 * responsible for freeing it with g_free(). | |
402 * | |
403 * If "gjid" is non-null, sets that as well. Caller is | |
404 * reponsible for freeing that via gaim_jid_free() when done | |
405 * with it. | |
406 */ | |
3466 | 407 static gchar *get_realwho(gjconn gjc, const char *who, int incl_resource, gaim_jid *gjid) |
3311 | 408 { |
409 gaim_jid my_gjid; | |
410 gchar *my_who; | |
411 gchar *realwho = NULL; | |
412 | |
413 if(!(who && who[0])) { | |
414 return NULL; | |
415 } | |
416 | |
417 /* | |
418 * Bare username and "username" not the server itself? | |
419 */ | |
420 if(!strchr(who, '@') && strcasecmp(who, gjc->user->server)) { | |
421 my_who = g_strdup_printf("%s@%s", who, gjc->user->server); | |
422 } else { | |
423 my_who = g_strdup(who); | |
424 } | |
425 | |
426 if((my_gjid = gaim_jid_new(my_who)) != NULL) { | |
427 /* | |
428 * If there's no "user" part, "who" was just the server or perhaps a transport (?) | |
429 */ | |
430 if(my_gjid->user) { | |
431 /* | |
432 * Include "/resource" bit? | |
433 */ | |
434 if(incl_resource) { | |
435 realwho = g_strdup(my_gjid->full); | |
436 } else { | |
437 realwho = g_strdup_printf("%s@%s", my_gjid->user, my_gjid->server); | |
438 } | |
439 } else { | |
440 realwho = g_strdup(my_gjid->server); | |
441 } | |
442 } | |
443 | |
444 g_free(my_who); | |
445 | |
446 if(gjid) { | |
447 *gjid = my_gjid; | |
448 } else { | |
449 gaim_jid_free(my_gjid); | |
450 } | |
451 | |
452 return realwho; | |
453 } | |
454 | |
2086 | 455 static gjconn gjab_new(char *user, char *pass, void *priv) |
456 { | |
457 pool p; | |
2956 | 458 gjconn gjc; |
2086 | 459 |
460 if (!user) | |
461 return (NULL); | |
462 | |
463 p = pool_new(); | |
464 if (!p) | |
465 return (NULL); | |
2956 | 466 gjc = pmalloc_x(p, sizeof(gjconn_struct), 0); |
467 if (!gjc) { | |
468 pool_free(p); /* no need for this anymore! */ | |
2086 | 469 return (NULL); |
2956 | 470 } |
471 gjc->p = p; | |
472 | |
3236 | 473 if((gjc->user = jid_new(p, user)) == NULL) { |
474 pool_free(p); /* no need for this anymore! */ | |
475 return (NULL); | |
476 } | |
3257 | 477 |
478 gjc->pass = strdup(pass); | |
2956 | 479 |
480 gjc->state = JCONN_STATE_OFF; | |
3074 | 481 gjc->was_connected = 0; |
2956 | 482 gjc->id = 1; |
483 gjc->fd = -1; | |
484 | |
485 gjc->priv = priv; | |
486 | |
487 return gjc; | |
2086 | 488 } |
489 | |
2956 | 490 static void gjab_delete(gjconn gjc) |
2086 | 491 { |
2956 | 492 if (!gjc) |
2086 | 493 return; |
494 | |
2956 | 495 gjab_stop(gjc); |
3257 | 496 free(gjc->pass); |
2956 | 497 pool_free(gjc->p); |
2086 | 498 } |
499 | |
2956 | 500 static void gjab_state_handler(gjconn gjc, gjconn_state_h h) |
2086 | 501 { |
2956 | 502 if (!gjc) |
2086 | 503 return; |
504 | |
2956 | 505 gjc->on_state = h; |
2086 | 506 } |
507 | |
2956 | 508 static void gjab_packet_handler(gjconn gjc, gjconn_packet_h h) |
2086 | 509 { |
2956 | 510 if (!gjc) |
2086 | 511 return; |
512 | |
2956 | 513 gjc->on_packet = h; |
2086 | 514 } |
515 | |
2956 | 516 static void gjab_stop(gjconn gjc) |
2086 | 517 { |
2956 | 518 if (!gjc || gjc->state == JCONN_STATE_OFF) |
2086 | 519 return; |
520 | |
2956 | 521 gjab_send_raw(gjc, "</stream:stream>"); |
522 gjc->state = JCONN_STATE_OFF; | |
3074 | 523 gjc->was_connected = 0; |
2956 | 524 close(gjc->fd); |
525 gjc->fd = -1; | |
526 XML_ParserFree(gjc->parser); | |
527 gjc->parser = NULL; | |
2086 | 528 } |
529 | |
530 /* | |
2956 | 531 static int gjab_getfd(gjconn gjc) |
2086 | 532 { |
2956 | 533 if (gjc) |
534 return gjc->fd; | |
2086 | 535 else |
536 return -1; | |
537 } | |
538 | |
2956 | 539 static jid gjab_getjid(gjconn gjc) |
2086 | 540 { |
2956 | 541 if (gjc) |
542 return (gjc->user); | |
2086 | 543 else |
544 return NULL; | |
545 } | |
546 | |
2956 | 547 static char *gjab_getsid(gjconn gjc) |
2086 | 548 { |
2956 | 549 if (gjc) |
550 return (gjc->sid); | |
2086 | 551 else |
552 return NULL; | |
553 } | |
554 */ | |
555 | |
2956 | 556 static char *gjab_getid(gjconn gjc) |
2086 | 557 { |
2956 | 558 snprintf(gjc->idbuf, 8, "%d", gjc->id++); |
559 return &gjc->idbuf[0]; | |
2086 | 560 } |
561 | |
2956 | 562 static void gjab_send(gjconn gjc, xmlnode x) |
2086 | 563 { |
2956 | 564 if (gjc && gjc->state != JCONN_STATE_OFF) { |
2086 | 565 char *buf = xmlnode2str(x); |
566 if (buf) | |
3630 | 567 #ifndef _WIN32 |
2956 | 568 write(gjc->fd, buf, strlen(buf)); |
3630 | 569 #else |
570 send(gjc->fd, buf, strlen(buf), 0); | |
571 #endif | |
2086 | 572 debug_printf("gjab_send: %s\n", buf); |
573 } | |
574 } | |
575 | |
2956 | 576 static void gjab_send_raw(gjconn gjc, const char *str) |
2086 | 577 { |
2956 | 578 if (gjc && gjc->state != JCONN_STATE_OFF) { |
579 /* | |
580 * JFIXME: No error detection?!?! | |
581 */ | |
3630 | 582 #ifndef _WIN32 |
2956 | 583 if(write(gjc->fd, str, strlen(str)) < 0) { |
3630 | 584 #else |
585 if(send(gjc->fd, str, strlen(str), 0) < 0) { | |
586 #endif | |
2956 | 587 fprintf(stderr, "DBG: Problem sending. Error: %d\n", errno); |
588 fflush(stderr); | |
589 } | |
4450 | 590 /* printing keepalives to the debug window is really annoying */ |
591 if(strcmp(str, JABBER_KEEPALIVE_STRING)) | |
592 debug_printf("gjab_send_raw: %s\n", str); | |
2086 | 593 } |
594 } | |
595 | |
2956 | 596 static void gjab_reqroster(gjconn gjc) |
2086 | 597 { |
598 xmlnode x; | |
599 | |
600 x = jutil_iqnew(JPACKET__GET, NS_ROSTER); | |
2956 | 601 xmlnode_put_attrib(x, "id", gjab_getid(gjc)); |
602 | |
603 gjab_send(gjc, x); | |
2086 | 604 xmlnode_free(x); |
605 } | |
606 | |
2956 | 607 static void gjab_reqauth(gjconn gjc) |
2814
f4f9e5a01890
[gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2800
diff
changeset
|
608 { |
f4f9e5a01890
[gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2800
diff
changeset
|
609 xmlnode x, y, z; |
f4f9e5a01890
[gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2800
diff
changeset
|
610 char *user; |
f4f9e5a01890
[gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2800
diff
changeset
|
611 |
2956 | 612 if (!gjc) |
2814
f4f9e5a01890
[gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2800
diff
changeset
|
613 return; |
f4f9e5a01890
[gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2800
diff
changeset
|
614 |
f4f9e5a01890
[gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2800
diff
changeset
|
615 x = jutil_iqnew(JPACKET__GET, NS_AUTH); |
f4f9e5a01890
[gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2800
diff
changeset
|
616 xmlnode_put_attrib(x, "id", IQID_AUTH); |
f4f9e5a01890
[gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2800
diff
changeset
|
617 y = xmlnode_get_tag(x, "query"); |
f4f9e5a01890
[gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2800
diff
changeset
|
618 |
2956 | 619 user = gjc->user->user; |
2814
f4f9e5a01890
[gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2800
diff
changeset
|
620 |
f4f9e5a01890
[gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2800
diff
changeset
|
621 if (user) { |
f4f9e5a01890
[gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2800
diff
changeset
|
622 z = xmlnode_insert_tag(y, "username"); |
f4f9e5a01890
[gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2800
diff
changeset
|
623 xmlnode_insert_cdata(z, user, -1); |
f4f9e5a01890
[gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2800
diff
changeset
|
624 } |
f4f9e5a01890
[gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2800
diff
changeset
|
625 |
2956 | 626 gjab_send(gjc, x); |
2814
f4f9e5a01890
[gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2800
diff
changeset
|
627 xmlnode_free(x); |
f4f9e5a01890
[gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2800
diff
changeset
|
628 } |
f4f9e5a01890
[gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2800
diff
changeset
|
629 |
2956 | 630 static void gjab_auth(gjconn gjc) |
2086 | 631 { |
632 xmlnode x, y, z; | |
633 char *hash, *user; | |
634 | |
2956 | 635 if (!gjc) |
2086 | 636 return; |
637 | |
638 x = jutil_iqnew(JPACKET__SET, NS_AUTH); | |
639 xmlnode_put_attrib(x, "id", IQID_AUTH); | |
640 y = xmlnode_get_tag(x, "query"); | |
641 | |
2956 | 642 user = gjc->user->user; |
2086 | 643 |
644 if (user) { | |
645 z = xmlnode_insert_tag(y, "username"); | |
646 xmlnode_insert_cdata(z, user, -1); | |
647 } | |
648 | |
649 z = xmlnode_insert_tag(y, "resource"); | |
2956 | 650 xmlnode_insert_cdata(z, gjc->user->resource, -1); |
651 | |
652 if (gjc->sid) { | |
653 debug_printf("digest authentication (sid %s)\n", gjc->sid); | |
2086 | 654 z = xmlnode_insert_tag(y, "digest"); |
2956 | 655 hash = pmalloc(x->p, strlen(gjc->sid) + strlen(gjc->pass) + 1); |
656 strcpy(hash, gjc->sid); | |
657 strcat(hash, gjc->pass); | |
2086 | 658 hash = shahash(hash); |
659 xmlnode_insert_cdata(z, hash, 40); | |
660 } else { | |
661 z = xmlnode_insert_tag(y, "password"); | |
2956 | 662 xmlnode_insert_cdata(z, gjc->pass, -1); |
2086 | 663 } |
664 | |
2956 | 665 gjab_send(gjc, x); |
2086 | 666 xmlnode_free(x); |
667 | |
668 return; | |
669 } | |
670 | |
2956 | 671 static void gjab_recv(gjconn gjc) |
2086 | 672 { |
673 static char buf[4096]; | |
674 int len; | |
675 | |
2956 | 676 if (!gjc || gjc->state == JCONN_STATE_OFF) |
2086 | 677 return; |
3630 | 678 #ifndef _WIN32 |
3234 | 679 if ((len = read(gjc->fd, buf, sizeof(buf) - 1)) > 0) { |
3630 | 680 #else |
681 if ((len = recv(gjc->fd, buf, sizeof(buf) - 1, 0)) > 0) { | |
682 #endif | |
2956 | 683 struct jabber_data *jd = GJ_GC(gjc)->proto_data; |
2086 | 684 buf[len] = '\0'; |
685 debug_printf("input (len %d): %s\n", len, buf); | |
2956 | 686 XML_Parse(gjc->parser, buf, len, 0); |
2800
0ad63a625eec
[gaim-migrate @ 2813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2791
diff
changeset
|
687 if (jd->die) |
2956 | 688 signoff(GJ_GC(gjc)); |
3105 | 689 } else if (len < 0 || errno != EAGAIN) { |
2086 | 690 STATE_EVT(JCONN_STATE_OFF) |
691 } | |
692 } | |
693 | |
694 static void startElement(void *userdata, const char *name, const char **attribs) | |
695 { | |
696 xmlnode x; | |
2956 | 697 gjconn gjc = (gjconn) userdata; |
698 | |
699 if (gjc->current) { | |
2086 | 700 /* Append the node to the current one */ |
2956 | 701 x = xmlnode_insert_tag(gjc->current, name); |
2086 | 702 xmlnode_put_expat_attribs(x, attribs); |
703 | |
2956 | 704 gjc->current = x; |
2086 | 705 } else { |
706 x = xmlnode_new_tag(name); | |
707 xmlnode_put_expat_attribs(x, attribs); | |
708 if (strcmp(name, "stream:stream") == 0) { | |
709 /* special case: name == stream:stream */ | |
710 /* id attrib of stream is stored for digest auth */ | |
2956 | 711 gjc->sid = g_strdup(xmlnode_get_attrib(x, "id")); |
2086 | 712 /* STATE_EVT(JCONN_STATE_AUTH) */ |
2635
8c75e59e4bdf
[gaim-migrate @ 2648]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2607
diff
changeset
|
713 xmlnode_free(x); |
2086 | 714 } else { |
2956 | 715 gjc->current = x; |
2086 | 716 } |
717 } | |
718 } | |
719 | |
720 static void endElement(void *userdata, const char *name) | |
721 { | |
2956 | 722 gjconn gjc = (gjconn) userdata; |
2086 | 723 xmlnode x; |
724 jpacket p; | |
725 | |
2956 | 726 if (gjc->current == NULL) { |
2086 | 727 /* we got </stream:stream> */ |
728 STATE_EVT(JCONN_STATE_OFF) | |
729 return; | |
730 } | |
731 | |
2956 | 732 x = xmlnode_get_parent(gjc->current); |
2086 | 733 |
734 if (!x) { | |
735 /* it is time to fire the event */ | |
2956 | 736 p = jpacket_new(gjc->current); |
737 | |
738 if (gjc->on_packet) | |
739 (gjc->on_packet) (gjc, p); | |
2086 | 740 else |
2956 | 741 xmlnode_free(gjc->current); |
2086 | 742 } |
743 | |
2956 | 744 gjc->current = x; |
2086 | 745 } |
746 | |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
747 static void jabber_callback(gpointer data, gint source, GaimInputCondition condition) |
2086 | 748 { |
749 struct gaim_connection *gc = (struct gaim_connection *)data; | |
750 struct jabber_data *jd = (struct jabber_data *)gc->proto_data; | |
751 | |
2956 | 752 gjab_recv(jd->gjc); |
2086 | 753 } |
754 | |
755 static void charData(void *userdata, const char *s, int slen) | |
756 { | |
2956 | 757 gjconn gjc = (gjconn) userdata; |
758 | |
759 if (gjc->current) | |
760 xmlnode_insert_cdata(gjc->current, s, slen); | |
2086 | 761 } |
762 | |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
763 static void gjab_connected(gpointer data, gint source, GaimInputCondition cond) |
2086 | 764 { |
765 xmlnode x; | |
766 char *t, *t2; | |
767 struct gaim_connection *gc = data; | |
768 struct jabber_data *jd; | |
2956 | 769 gjconn gjc; |
2086 | 770 |
771 if (!g_slist_find(connections, gc)) { | |
772 close(source); | |
773 return; | |
774 } | |
775 | |
776 jd = gc->proto_data; | |
2956 | 777 gjc = jd->gjc; |
778 | |
4366 | 779 gjc->fd = source; |
2300
d2686f757d6e
[gaim-migrate @ 2310]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2289
diff
changeset
|
780 |
2086 | 781 if (source == -1) { |
782 STATE_EVT(JCONN_STATE_OFF) | |
783 return; | |
784 } | |
785 | |
2956 | 786 gjc->state = JCONN_STATE_CONNECTED; |
2086 | 787 STATE_EVT(JCONN_STATE_CONNECTED) |
788 | |
789 /* start stream */ | |
2956 | 790 x = jutil_header(NS_CLIENT, gjc->user->server); |
2086 | 791 t = xmlnode2str(x); |
792 /* this is ugly, we can create the string here instead of jutil_header */ | |
793 /* what do you think about it? -madcat */ | |
794 t2 = strstr(t, "/>"); | |
795 *t2++ = '>'; | |
796 *t2 = '\0'; | |
2956 | 797 gjab_send_raw(gjc, "<?xml version='1.0'?>"); |
798 gjab_send_raw(gjc, t); | |
2086 | 799 xmlnode_free(x); |
800 | |
2956 | 801 gjc->state = JCONN_STATE_ON; |
2086 | 802 STATE_EVT(JCONN_STATE_ON); |
803 | |
2956 | 804 gc = GJ_GC(gjc); |
805 gc->inpa = gaim_input_add(gjc->fd, GAIM_INPUT_READ, jabber_callback, gc); | |
2086 | 806 } |
807 | |
2956 | 808 static void gjab_start(gjconn gjc) |
2086 | 809 { |
4491 | 810 struct gaim_account *account; |
4366 | 811 int port, rc; |
4436 | 812 char *server; |
2086 | 813 |
2956 | 814 if (!gjc || gjc->state != JCONN_STATE_OFF) |
2086 | 815 return; |
816 | |
4491 | 817 account = GJ_GC(gjc)->account; |
818 port = account->proto_opt[USEROPT_PORT][0] ? atoi(account->proto_opt[USEROPT_PORT]) : DEFAULT_PORT; | |
819 server = account->proto_opt[USEROPT_CONN_SERVER][0] ? account->proto_opt[USEROPT_CONN_SERVER] : gjc->user->server; | |
4436 | 820 |
2086 | 821 |
2956 | 822 gjc->parser = XML_ParserCreate(NULL); |
823 XML_SetUserData(gjc->parser, (void *)gjc); | |
824 XML_SetElementHandler(gjc->parser, startElement, endElement); | |
825 XML_SetCharacterDataHandler(gjc->parser, charData); | |
826 | |
4634 | 827 rc = proxy_connect(account, server, port, gjab_connected, GJ_GC(gjc)); |
4491 | 828 if (!account->gc || (rc != 0)) { |
2086 | 829 STATE_EVT(JCONN_STATE_OFF) |
830 return; | |
831 } | |
832 } | |
833 | |
2956 | 834 /* |
835 * Find chat by chat group name | |
836 */ | |
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4357
diff
changeset
|
837 static struct gaim_conversation *find_chat(struct gaim_connection *gc, char *name) |
2086 | 838 { |
839 GSList *bcs = gc->buddy_chats; | |
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4357
diff
changeset
|
840 struct gaim_conversation *b = NULL; |
2086 | 841 char *chat = g_strdup(normalize(name)); |
842 | |
843 while (bcs) { | |
844 b = bcs->data; | |
845 if (!strcasecmp(normalize(b->name), chat)) | |
846 break; | |
847 b = NULL; | |
848 bcs = bcs->next; | |
849 } | |
850 | |
851 g_free(chat); | |
852 return b; | |
853 } | |
854 | |
2956 | 855 /* |
856 * Find chat by "chat id" | |
857 * | |
858 * Returns: 0 on success and jabber_chat pointer set | |
859 * or -EINVAL on error and jabber_chat pointer is | |
860 * undefined. | |
861 * | |
862 * TBD: Slogging through the buddy_chats list seems | |
863 * redundant since the chat i.d. is mirrored in the | |
864 * jabber_chat struct list. But that's the way it | |
865 * was, so that's the way I'm leaving it--for now. | |
866 */ | |
867 static int jabber_find_chat_by_convo_id(struct gaim_connection *gc, int id, struct jabber_chat **jc) | |
2086 | 868 { |
2956 | 869 GSList *bcs = gc->buddy_chats; |
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4357
diff
changeset
|
870 struct gaim_conversation *b = NULL; |
2956 | 871 struct jabber_data *jd = gc->proto_data; |
872 | |
873 *jc = NULL; | |
874 | |
875 while(bcs != NULL) { | |
876 b = bcs->data; | |
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4357
diff
changeset
|
877 if (id == gaim_chat_get_id(GAIM_CHAT(b))) |
2956 | 878 break; |
879 bcs = bcs->next; | |
880 } | |
881 | |
882 if (bcs != NULL) { | |
883 bcs = jd->chats; | |
884 while (bcs != NULL) { | |
885 *jc = bcs->data; | |
886 if ((*jc)->state == JCS_ACTIVE && (*jc)->b == b) | |
887 break; | |
888 bcs = bcs->next; | |
889 } | |
890 } | |
891 | |
892 return(bcs == NULL? -EINVAL : 0); | |
893 } | |
894 | |
895 /* | |
896 * Find any chat | |
897 */ | |
898 static struct jabber_chat *find_any_chat(struct gaim_connection *gc, jid chat) | |
899 { | |
900 GSList *jcs = ((struct jabber_data *)gc->proto_data)->chats; | |
2086 | 901 struct jabber_chat *jc = NULL; |
902 | |
2956 | 903 while (jcs) { |
904 jc = jcs->data; | |
3311 | 905 if (!jid_cmpx(chat, jc->gjid, JID_USER | JID_SERVER)) |
2086 | 906 break; |
907 jc = NULL; | |
2956 | 908 jcs = jcs->next; |
2086 | 909 } |
910 | |
911 return jc; | |
912 } | |
913 | |
2956 | 914 |
915 /* | |
916 * Find existing/active Jabber chat | |
917 */ | |
918 static struct jabber_chat *find_existing_chat(struct gaim_connection *gc, jid chat) | |
919 { | |
920 GSList *jcs = ((struct jabber_data *)gc->proto_data)->chats; | |
921 struct jabber_chat *jc = NULL; | |
922 | |
923 while (jcs) { | |
924 jc = jcs->data; | |
3311 | 925 if (jc->state == JCS_ACTIVE && !jid_cmpx(chat, jc->gjid, JID_USER | JID_SERVER)) |
2956 | 926 break; |
927 jc = NULL; | |
928 jcs = jcs->next; | |
929 } | |
930 | |
931 return jc; | |
932 } | |
933 | |
934 /* | |
935 * Find pending chat | |
936 */ | |
2086 | 937 static struct jabber_chat *find_pending_chat(struct gaim_connection *gc, jid chat) |
938 { | |
2956 | 939 GSList *jcs = ((struct jabber_data *)gc->proto_data)->chats; |
2086 | 940 struct jabber_chat *jc = NULL; |
941 | |
2956 | 942 while (jcs) { |
943 jc = jcs->data; | |
3311 | 944 if (jc->state == JCS_PENDING && !jid_cmpx(chat, jc->gjid, JID_USER | JID_SERVER)) |
2086 | 945 break; |
946 jc = NULL; | |
2956 | 947 jcs = jcs->next; |
2086 | 948 } |
949 | |
950 return jc; | |
951 } | |
952 | |
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4357
diff
changeset
|
953 static gboolean find_chat_buddy(struct gaim_conversation *b, char *name) |
2086 | 954 { |
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4357
diff
changeset
|
955 GList *m = gaim_chat_get_users(GAIM_CHAT(b)); |
2086 | 956 |
957 while (m) { | |
958 if (!strcmp(m->data, name)) | |
959 return TRUE; | |
960 m = m->next; | |
961 } | |
962 | |
963 return FALSE; | |
964 } | |
965 | |
2956 | 966 /* |
3236 | 967 * Remove a buddy from the (gaim) buddylist (if he's on it) |
968 */ | |
3466 | 969 static void jabber_remove_gaim_buddy(struct gaim_connection *gc, const char *buddyname) |
3236 | 970 { |
971 struct buddy *b; | |
972 | |
4687 | 973 if ((b = gaim_find_buddy(gc->account, buddyname)) != NULL) { |
4349 | 974 debug_printf("removing buddy [1]: %s\n", buddyname); |
4687 | 975 gaim_blist_remove_buddy(b); |
4349 | 976 gaim_blist_save(); |
3236 | 977 } |
978 } | |
979 | |
3466 | 980 static void jabber_change_passwd(struct gaim_connection *gc, const char *old, const char *new) |
3257 | 981 { |
982 gjconn gjc = ((struct jabber_data *)gc->proto_data)->gjc; | |
983 | |
984 if(strcmp(old, gjc->pass)) | |
985 { | |
3427 | 986 do_error_dialog(_("Unable to change password."), |
987 _("The current password you entered is incorrect. Your password has " | |
988 "not been changed."), GAIM_ERROR); | |
3257 | 989 } |
990 else if(!strcmp(old, new)) | |
991 { | |
3427 | 992 do_error_dialog(_("Unable to change password"), |
4059 | 993 _("The new password you entered is the same as your current password. " |
3427 | 994 "Your password remains the same."), GAIM_ERROR); |
3257 | 995 } |
996 else | |
997 { | |
998 xmlnode x, y, z; | |
999 char *id; | |
1000 | |
1001 x = jutil_iqnew(JPACKET__SET, NS_REGISTER); | |
1002 xmlnode_put_attrib(x, "to", gjc->user->server); | |
1003 y = xmlnode_get_tag(x, "query"); | |
1004 z = xmlnode_insert_tag(y, "username"); | |
1005 xmlnode_insert_cdata(z, gjc->user->user, -1); | |
1006 z = xmlnode_insert_tag(y, "password"); | |
1007 xmlnode_insert_cdata(z, new, -1); | |
1008 | |
1009 id = gjab_getid(gjc); | |
1010 xmlnode_put_attrib(x, "id", id); | |
1011 | |
1012 free(gjc->pass); | |
1013 gjc->pass = strdup(new); | |
1014 | |
1015 g_hash_table_insert(gjc->queries, g_strdup(id), g_strdup("change_password")); | |
1016 | |
1017 gjab_send(gjc, x); | |
1018 xmlnode_free(x); | |
1019 } | |
1020 } | |
3311 | 1021 |
3340 | 1022 /* |
1023 * Return pointer to jabber_buddy_data if buddy found. Create if necessary. | |
1024 */ | |
5135 | 1025 static struct jabber_buddy_data* jabber_find_buddy(struct gaim_connection *gc, char *buddy, gboolean create) |
3311 | 1026 { |
1027 struct jabber_data *jd = gc->proto_data; | |
1028 gpointer val; | |
1029 char *realwho; | |
1030 | |
1031 if((realwho = get_realwho(jd->gjc, buddy, FALSE, NULL)) == NULL) | |
1032 return NULL; | |
1033 | |
1034 val = g_hash_table_lookup(jd->buddies, realwho); | |
1035 if(val) { | |
1036 g_free(realwho); | |
1037 return (struct jabber_buddy_data *)val; | |
1038 | |
5135 | 1039 } else if (create) { |
3311 | 1040 struct jabber_buddy_data *jbd = g_new0(struct jabber_buddy_data, 1); |
3340 | 1041 jbd->invisible = JABBER_NOT_INVIS; |
3311 | 1042 g_hash_table_insert(jd->buddies, g_strdup(realwho), jbd); |
1043 g_free(realwho); | |
1044 return jbd; | |
5135 | 1045 } else { |
1046 return NULL; | |
3311 | 1047 } |
1048 } | |
3770 | 1049 |
3236 | 1050 /* |
3311 | 1051 * find a resource by name, or if no name given, return the "default" resource |
3770 | 1052 * default being the highest priority one. |
3311 | 1053 */ |
1054 | |
1055 static jab_res_info jabber_find_resource(struct gaim_connection *gc, char *who) | |
1056 { | |
1057 GSList *resources; | |
5135 | 1058 struct jabber_buddy_data *jbd = jabber_find_buddy(gc, who, FALSE); |
3311 | 1059 jab_res_info jri = NULL; |
1060 char *res = strstr(who, "/"); | |
1061 | |
1062 if(res) | |
1063 res++; | |
1064 | |
1065 if(jbd) | |
1066 { | |
1067 resources = jbd->resources; | |
1068 while(resources) | |
1069 { | |
1070 if(!jri && !res) { | |
1071 jri = (jab_res_info) resources->data; | |
1072 } else if(!res) { /* we're looking for the default priority, so... */ | |
1073 if(((jab_res_info) resources->data)->priority >= jri->priority) | |
1074 jri = (jab_res_info) resources->data; | |
3337 | 1075 } else if(((jab_res_info)resources->data)->name) { |
3311 | 1076 if(!strcasecmp(((jab_res_info) resources->data)->name, res)) { |
1077 jri = (jab_res_info) resources->data; | |
1078 break; | |
1079 } | |
1080 } | |
1081 resources = resources->next; | |
1082 } | |
1083 } | |
1084 | |
1085 return jri; | |
1086 } | |
1087 | |
1088 /* | |
1089 * if the resource doesn't exist, create it. otherwise, just update the priority | |
2956 | 1090 */ |
3311 | 1091 static void jabber_track_resource(struct gaim_connection *gc, |
1092 char *buddy, | |
1093 char *res, | |
1094 int priority, | |
1095 int state) | |
1096 { | |
5135 | 1097 struct jabber_buddy_data *jbd = jabber_find_buddy(gc, buddy, TRUE); |
3311 | 1098 |
3337 | 1099 if(jbd) { |
1100 char *who; | |
1101 jab_res_info jri; | |
1102 if(res) | |
1103 who = g_strdup_printf("%s/%s", buddy, res); | |
1104 else | |
1105 who = g_strdup(buddy); | |
1106 jri = jabber_find_resource(gc, who); | |
3311 | 1107 g_free(who); |
1108 if(!jri) { | |
1109 jri = g_new0(struct jabber_resource_info, 1); | |
1110 jri->name = g_strdup(res); | |
1111 jri->away_msg = NULL; | |
5093 | 1112 jri->has_xhtml = TRUE; |
3311 | 1113 jbd->resources = g_slist_append(jbd->resources, jri); |
1114 } | |
1115 jri->priority = priority; | |
1116 jri->state = state; | |
1117 } | |
1118 } | |
1119 | |
1120 /* | |
1121 * remove the resource, if it exists | |
1122 */ | |
1123 static void jabber_remove_resource(struct gaim_connection *gc, char *buddy, char *res) | |
2956 | 1124 { |
5135 | 1125 struct jabber_buddy_data *jbd = jabber_find_buddy(gc, buddy, FALSE); |
3337 | 1126 if(jbd) { |
1127 char *who; | |
1128 jab_res_info jri; | |
1129 if(res) | |
1130 who = g_strdup_printf("%s/%s", buddy, res); | |
1131 else | |
1132 who = g_strdup(buddy); | |
1133 jri = jabber_find_resource(gc, who); | |
3311 | 1134 g_free(who); |
1135 if(jri) { | |
3337 | 1136 if(jri->name) |
1137 g_free(jri->name); | |
3311 | 1138 if(jri->away_msg) |
1139 g_free(jri->away_msg); | |
1140 jbd->resources = g_slist_remove(jbd->resources, jri); | |
1141 g_free(jri); | |
1142 } | |
1143 } | |
1144 } | |
1145 | |
1146 /* | |
1147 * grab the away message for the default resource | |
1148 */ | |
1149 static char *jabber_lookup_away(gjconn gjc, char *name) | |
1150 { | |
1151 jab_res_info jri = jabber_find_resource(GJ_GC(gjc), name); | |
1152 | |
4745 | 1153 if(!jri) |
3311 | 1154 return _("Unknown"); |
1155 | |
1156 return jri->away_msg; | |
1157 } | |
4745 | 1158 static const char *jabber_get_state_string(int s) { |
1159 switch(s) { | |
1160 case UC_AWAY: | |
1161 return _("Away"); | |
1162 case UC_CHAT: | |
1163 return _("Chatty"); | |
1164 case UC_XA: | |
1165 return _("Extended Away"); | |
1166 case UC_DND: | |
1167 return _("Do Not Disturb"); | |
1168 default: | |
1169 return _("Available"); | |
1170 } | |
1171 } | |
3311 | 1172 |
1173 static void jabber_track_away(gjconn gjc, jpacket p, char *type) | |
1174 { | |
1175 jab_res_info jri = NULL; | |
1176 | |
3337 | 1177 if(!p || !p->from || !p->from->user) |
3311 | 1178 return; |
1179 | |
1180 jri = jabber_find_resource(GJ_GC(gjc), jid_full(p->from)); | |
1181 | |
1182 if(!jri) | |
1183 return; | |
3770 | 1184 |
3311 | 1185 if(jri->away_msg) |
1186 g_free(jri->away_msg); | |
1187 | |
4745 | 1188 jri->away_msg = g_strdup(xmlnode_get_tag_data(p->x, "status")); |
3311 | 1189 } |
1190 | |
1191 static void jabber_convo_closed(struct gaim_connection *gc, char *name) | |
1192 { | |
1193 jab_res_info jri = jabber_find_resource(gc, name); | |
1194 | |
1195 if(jri) { | |
1196 if(jri->thread_id) | |
1197 g_free(jri->thread_id); | |
1198 | |
1199 jri->thread_id = NULL; | |
2956 | 1200 } |
1201 } | |
1202 | |
3311 | 1203 static void jabber_track_convo_thread(gjconn gjc, char *name, char *thread_id) |
1204 { | |
1205 jab_res_info jri = jabber_find_resource(GJ_GC(gjc), name); | |
1206 | |
1207 if(jri) { | |
1208 if(jri->thread_id) | |
1209 g_free(jri->thread_id); | |
1210 | |
1211 jri->thread_id = g_strdup(thread_id); | |
1212 } | |
1213 } | |
1214 | |
1215 static char *jabber_get_convo_thread(gjconn gjc, char *name) | |
1216 { | |
1217 char *ct = NULL; | |
1218 jab_res_info jri = jabber_find_resource(GJ_GC(gjc), name); | |
1219 | |
1220 if(jri) { | |
1221 if(jri->thread_id) | |
1222 ct = g_strdup(jri->thread_id); | |
1223 } | |
5135 | 1224 |
3311 | 1225 return ct; |
1226 } | |
1227 | |
1228 | |
3159 | 1229 static time_t iso8601_to_time(char *timestamp) |
1230 { | |
3229 | 1231 struct tm t; |
1232 time_t retval = 0; | |
5112 | 1233 localtime_r(NULL, &t); |
3229 | 1234 |
3311 | 1235 if(sscanf(timestamp, "%04d%02d%02dT%02d:%02d:%02d", |
3229 | 1236 &t.tm_year, &t.tm_mon, &t.tm_mday, &t.tm_hour, &t.tm_min, &t.tm_sec)) |
1237 { | |
1238 t.tm_year -= 1900; | |
1239 t.tm_mon -= 1; | |
1240 retval = mktime(&t); | |
1241 # ifdef HAVE_TM_GMTOFF | |
1242 retval += t.tm_gmtoff; | |
1243 # else | |
1244 # ifdef HAVE_TIMEZONE | |
1245 tzset(); /* making sure */ | |
1246 retval -= timezone; | |
1247 # endif | |
1248 # endif | |
1249 } | |
1250 | |
1251 return retval; | |
3159 | 1252 } |
1253 | |
2956 | 1254 static void jabber_handlemessage(gjconn gjc, jpacket p) |
2086 | 1255 { |
3311 | 1256 xmlnode y, subj; |
3159 | 1257 time_t time_sent = time(NULL); |
3311 | 1258 gboolean typing = FALSE; |
5093 | 1259 gboolean has_xhtml = TRUE; |
2086 | 1260 |
1261 char *from = NULL, *msg = NULL, *type = NULL, *topic = NULL; | |
3311 | 1262 char *thread_id = NULL; |
1263 char *conference_room = NULL; | |
2086 | 1264 char m[BUF_LONG * 2]; |
1265 | |
1266 type = xmlnode_get_attrib(p->x, "type"); | |
3769 | 1267 |
3311 | 1268 if ((y = xmlnode_get_tag(p->x, "thread"))) |
1269 thread_id = xmlnode_get_data(y); | |
1270 | |
1271 y = xmlnode_get_firstchild(p->x); | |
1272 | |
1273 while(y) { | |
1274 if(NSCHECK(y, NS_DELAY)) { | |
1275 char *timestamp = xmlnode_get_attrib(y, "stamp"); | |
1276 time_sent = iso8601_to_time(timestamp); | |
1277 } else if(NSCHECK(y, "jabber:x:event")) { | |
1278 if(xmlnode_get_tag(y, "composing")) | |
1279 typing = TRUE; | |
1280 } else if(NSCHECK(y, "jabber:x:conference")) { | |
1281 conference_room = xmlnode_get_attrib(y, "jid"); | |
1282 } | |
1283 y = xmlnode_get_nextsibling(y); | |
3159 | 1284 } |
1285 | |
2086 | 1286 if (!type || !strcasecmp(type, "normal") || !strcasecmp(type, "chat")) { |
1287 | |
1288 from = jid_full(p->from); | |
1289 if ((y = xmlnode_get_tag(p->x, "html"))) { | |
5093 | 1290 msg = xmlnode2str(y); |
1291 } else if ((y = xmlnode_get_tag(p->x, "body"))) { | |
2086 | 1292 msg = xmlnode_get_data(y); |
5093 | 1293 has_xhtml = FALSE; |
2086 | 1294 } |
1295 | |
1296 if (!from) | |
1297 return; | |
1298 | |
3311 | 1299 if (conference_room) { |
2205
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1300 GList *m = NULL; |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1301 char **data; |
2086 | 1302 |
3311 | 1303 data = g_strsplit(conference_room, "@", 2); |
2205
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1304 m = g_list_append(m, g_strdup(data[0])); |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1305 m = g_list_append(m, g_strdup(data[1])); |
2956 | 1306 m = g_list_append(m, g_strdup(gjc->user->user)); |
2205
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1307 g_strfreev(data); |
2086 | 1308 |
3311 | 1309 serv_got_chat_invite(GJ_GC(gjc), conference_room, from, msg, m); |
2086 | 1310 } else if (msg) { /* whisper */ |
1311 struct jabber_chat *jc; | |
1312 g_snprintf(m, sizeof(m), "%s", msg); | |
2956 | 1313 if (((jc = find_existing_chat(GJ_GC(gjc), p->from)) != NULL) && jc->b) |
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4357
diff
changeset
|
1314 serv_got_chat_in(GJ_GC(gjc), |
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4357
diff
changeset
|
1315 gaim_chat_get_id(GAIM_CHAT(jc->b)), |
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4357
diff
changeset
|
1316 p->from->resource, 1, m, time_sent); |
2086 | 1317 else { |
2278
00a8b7bcef6c
[gaim-migrate @ 2288]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2232
diff
changeset
|
1318 int flags = 0; |
3769 | 1319 jab_res_info jri = jabber_find_resource(GJ_GC(gjc), from); |
5093 | 1320 if(jri) { |
1321 if(typing) | |
1322 jri->has_composing = TRUE; | |
1323 jri->has_xhtml = has_xhtml; | |
1324 } | |
2278
00a8b7bcef6c
[gaim-migrate @ 2288]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2232
diff
changeset
|
1325 if (xmlnode_get_tag(p->x, "gaim")) |
00a8b7bcef6c
[gaim-migrate @ 2288]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2232
diff
changeset
|
1326 flags = IM_FLAG_GAIMUSER; |
3769 | 1327 jabber_track_convo_thread(gjc, from, thread_id); |
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4357
diff
changeset
|
1328 if (gaim_find_conversation(from)) |
3769 | 1329 serv_got_im(GJ_GC(gjc), from, m, flags, |
3311 | 1330 time_sent, -1); |
2086 | 1331 else { |
2956 | 1332 if(p->from->user) { |
3311 | 1333 from = g_strdup_printf("%s@%s", p->from->user, |
1334 p->from->server); | |
2956 | 1335 } else { |
3311 | 1336 /* server message? */ |
1337 from = g_strdup(p->from->server); | |
2956 | 1338 } |
3159 | 1339 serv_got_im(GJ_GC(gjc), from, m, flags, time_sent, -1); |
2086 | 1340 g_free(from); |
1341 } | |
1342 } | |
3311 | 1343 } else { |
1344 /* a non-message message! */ | |
1345 from = g_strdup_printf("%s@%s", p->from->user, p->from->server); | |
1346 if(typing) | |
3768 | 1347 serv_got_typing(GJ_GC(gjc), from, 0, TYPING); |
3311 | 1348 else |
1349 serv_got_typing_stopped(GJ_GC(gjc), from); | |
1350 g_free(from); | |
2086 | 1351 } |
1352 | |
1353 } else if (!strcasecmp(type, "error")) { | |
1354 if ((y = xmlnode_get_tag(p->x, "error"))) { | |
1355 type = xmlnode_get_attrib(y, "code"); | |
1356 msg = xmlnode_get_data(y); | |
1357 } | |
1358 | |
1359 if (msg) { | |
3427 | 1360 from = g_strdup_printf(_("Jabber Error %s"), type ? type : ""); |
1361 do_error_dialog(from, msg, GAIM_ERROR); | |
2086 | 1362 g_free(from); |
1363 } | |
1364 } else if (!strcasecmp(type, "groupchat")) { | |
1365 struct jabber_chat *jc; | |
1366 static int i = 0; | |
1367 | |
1368 if ((y = xmlnode_get_tag(p->x, "html"))) { | |
5093 | 1369 msg = xmlnode2str(y); |
1370 } else if ((y = xmlnode_get_tag(p->x, "body"))) { | |
2086 | 1371 msg = xmlnode_get_data(y); |
1372 } | |
1373 | |
1374 if ((subj = xmlnode_get_tag(p->x, "subject"))) { | |
3770 | 1375 topic = xmlnode_get_data(subj); |
1376 } | |
2086 | 1377 |
2956 | 1378 jc = find_existing_chat(GJ_GC(gjc), p->from); |
2086 | 1379 if (!jc) { |
1380 /* we're not in this chat. are we supposed to be? */ | |
2956 | 1381 if ((jc = find_pending_chat(GJ_GC(gjc), p->from)) != NULL) { |
2086 | 1382 /* yes, we're supposed to be. so now we are. */ |
2956 | 1383 jc->b = serv_got_joined_chat(GJ_GC(gjc), i++, p->from->user); |
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4357
diff
changeset
|
1384 jc->id = gaim_chat_get_id(GAIM_CHAT(jc->b)); |
2956 | 1385 jc->state = JCS_ACTIVE; |
2086 | 1386 } else { |
1387 /* no, we're not supposed to be. */ | |
1388 g_free(msg); | |
1389 return; | |
1390 } | |
1391 } | |
1392 if (p->from->resource) { | |
1393 if (!y) { | |
2956 | 1394 if (!find_chat_buddy(jc->b, p->from->resource)) { |
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4357
diff
changeset
|
1395 gaim_chat_add_user(GAIM_CHAT(jc->b), |
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4357
diff
changeset
|
1396 p->from->resource, NULL); |
2956 | 1397 } else if ((y = xmlnode_get_tag(p->x, "status"))) { |
3311 | 1398 jabber_track_away(gjc, p, NULL); |
2086 | 1399 } |
1400 } else if (jc->b && msg) { | |
1401 char buf[8192]; | |
1402 | |
1403 if (topic) { | |
1404 char tbuf[8192]; | |
1405 g_snprintf(tbuf, sizeof(tbuf), "%s", topic); | |
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4357
diff
changeset
|
1406 gaim_chat_set_topic(GAIM_CHAT(jc->b), |
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4357
diff
changeset
|
1407 p->from->resource, tbuf); |
2086 | 1408 } |
1409 | |
1410 g_snprintf(buf, sizeof(buf), "%s", msg); | |
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4357
diff
changeset
|
1411 serv_got_chat_in(GJ_GC(gjc), |
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4357
diff
changeset
|
1412 gaim_chat_get_id(GAIM_CHAT(jc->b)), |
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4357
diff
changeset
|
1413 p->from->resource, 0, buf, time_sent); |
2086 | 1414 } |
1415 } else { /* message from the server */ | |
3770 | 1416 if(jc->b && topic) { |
1417 char tbuf[8192]; | |
2086 | 1418 g_snprintf(tbuf, sizeof(tbuf), "%s", topic); |
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4357
diff
changeset
|
1419 gaim_chat_set_topic(GAIM_CHAT(jc->b), "", tbuf); |
2086 | 1420 } |
1421 } | |
1422 | |
1423 } else { | |
1424 debug_printf("unhandled message %s\n", type); | |
1425 } | |
1426 } | |
3770 | 1427 |
2956 | 1428 static void jabber_handlepresence(gjconn gjc, jpacket p) |
2086 | 1429 { |
1430 char *to, *from, *type; | |
1431 struct buddy *b = NULL; | |
3311 | 1432 gaim_jid gjid; |
2086 | 1433 char *buddy; |
3194 | 1434 xmlnode y; |
2086 | 1435 char *show; |
2501
227cc42ffa6e
[gaim-migrate @ 2514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2382
diff
changeset
|
1436 int state = 0; |
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4357
diff
changeset
|
1437 struct gaim_conversation *cnv = NULL; |
2086 | 1438 struct jabber_chat *jc = NULL; |
3311 | 1439 int priority = 0; |
1440 struct jabber_buddy_data *jbd; | |
3770 | 1441 |
2086 | 1442 to = xmlnode_get_attrib(p->x, "to"); |
1443 from = xmlnode_get_attrib(p->x, "from"); | |
1444 type = xmlnode_get_attrib(p->x, "type"); | |
3770 | 1445 |
3311 | 1446 if((buddy = get_realwho(gjc, from, FALSE, &gjid)) == NULL) |
1447 return; | |
1448 | |
1449 if (gjid->user == NULL) { | |
1450 /* FIXME: transport */ | |
1451 g_free(buddy); | |
1452 gaim_jid_free(gjid); | |
1453 return; | |
1454 } | |
1455 | |
5135 | 1456 jbd = jabber_find_buddy(GJ_GC(gjc), buddy, TRUE); |
3311 | 1457 |
1458 if(jbd->error_msg) { | |
1459 g_free(jbd->error_msg); | |
1460 jbd->error_msg = NULL; | |
1461 } | |
1462 | |
3259 | 1463 if(type && !strcasecmp(type, "error")) { |
1464 state = UC_ERROR; | |
3311 | 1465 if((y = xmlnode_get_tag(p->x, "error")) != NULL) { |
1466 jbd->error_msg = g_strdup_printf(_("Error %s: %s"), | |
1467 xmlnode_get_attrib(y, "code"), xmlnode_get_data(y)); | |
1468 } else { | |
1469 jbd->error_msg = g_strdup(_("Unknown Error in presence")); | |
1470 } | |
3259 | 1471 } else { |
1472 if ((y = xmlnode_get_tag(p->x, "show"))) { | |
1473 show = xmlnode_get_data(y); | |
1474 if (!show) { | |
1475 state = 0; | |
1476 } else if (!strcasecmp(show, "away")) { | |
1477 state = UC_AWAY; | |
1478 } else if (!strcasecmp(show, "chat")) { | |
1479 state = UC_CHAT; | |
1480 } else if (!strcasecmp(show, "xa")) { | |
1481 state = UC_XA; | |
1482 } else if (!strcasecmp(show, "dnd")) { | |
1483 state = UC_DND; | |
1484 } | |
1485 } else { | |
2501
227cc42ffa6e
[gaim-migrate @ 2514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2382
diff
changeset
|
1486 state = 0; |
2086 | 1487 } |
1488 } | |
1489 | |
3311 | 1490 if ((y = xmlnode_get_tag(p->x, "priority"))) |
3770 | 1491 priority = atoi(xmlnode_get_data(y)); |
2086 | 1492 |
1493 /* um. we're going to check if it's a chat. if it isn't, and there are pending | |
2956 | 1494 * chats, create the chat. if there aren't pending chats and we don't have the |
1495 * buddy on our list, simply bail out. */ | |
3311 | 1496 if ((cnv = find_chat(GJ_GC(gjc), gjid->user)) == NULL) { |
2086 | 1497 static int i = 0x70; |
3311 | 1498 if ((jc = find_pending_chat(GJ_GC(gjc), gjid)) != NULL) { |
1499 jc->b = cnv = serv_got_joined_chat(GJ_GC(gjc), i++, gjid->user); | |
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4357
diff
changeset
|
1500 jc->id = gaim_chat_get_id(GAIM_CHAT(jc->b)); |
2956 | 1501 jc->state = JCS_ACTIVE; |
4687 | 1502 } else if ((b = gaim_find_buddy(GJ_GC(gjc)->account, buddy)) == NULL) { |
2956 | 1503 g_free(buddy); |
3311 | 1504 gaim_jid_free(gjid); |
2956 | 1505 return; |
2086 | 1506 } |
1507 } | |
1508 | |
4732 | 1509 if (state == UC_ERROR || (type && (strcasecmp(type, "unavailable") == 0))) |
3311 | 1510 jabber_remove_resource(GJ_GC(gjc), buddy, gjid->resource); |
1511 else { | |
1512 jabber_track_resource(GJ_GC(gjc), buddy, gjid->resource, priority, state); | |
1513 | |
1514 /* keep track of away msg somewhat the same as the yahoo plugin */ | |
1515 jabber_track_away(gjc, p, type); | |
1516 } | |
3770 | 1517 |
3311 | 1518 |
2086 | 1519 if (!cnv) { |
3311 | 1520 /* this is where we handle presence information for "regular" buddies */ |
1521 jab_res_info jri = jabber_find_resource(GJ_GC(gjc), buddy); | |
1522 if(jri) { | |
4732 | 1523 serv_got_update(GJ_GC(gjc), buddy, 1, 0, b->signon, b->idle, jri->state); |
3311 | 1524 } else |
4732 | 1525 serv_got_update(GJ_GC(gjc), buddy, 0, 0, 0, 0, 0); |
3311 | 1526 |
2086 | 1527 } else { |
3311 | 1528 if (gjid->resource) { |
3259 | 1529 if (type && (!strcasecmp(type, "unavailable"))) { |
2086 | 1530 struct jabber_data *jd; |
3311 | 1531 if (!jc && !(jc = find_existing_chat(GJ_GC(gjc), gjid))) { |
2086 | 1532 g_free(buddy); |
3311 | 1533 gaim_jid_free(gjid); |
2086 | 1534 return; |
1535 } | |
1536 jd = jc->gc->proto_data; | |
2956 | 1537 /* if it's not ourselves...*/ |
3311 | 1538 if (strcmp(gjid->resource, jc->gjid->resource) && jc->b) { |
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4357
diff
changeset
|
1539 gaim_chat_remove_user(GAIM_CHAT(jc->b), gjid->resource, |
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4357
diff
changeset
|
1540 NULL); |
2086 | 1541 g_free(buddy); |
3311 | 1542 gaim_jid_free(gjid); |
2086 | 1543 return; |
1544 } | |
2956 | 1545 |
1546 jc->state = JCS_CLOSED; | |
1547 serv_got_chat_left(GJ_GC(gjc), jc->id); | |
1548 /* | |
1549 * TBD: put back some day? | |
1550 jd->chats = g_slist_remove(jd->chats, jc); | |
1551 g_free(jc); | |
1552 */ | |
1553 } else { | |
3311 | 1554 if ((!jc && !(jc = find_existing_chat(GJ_GC(gjc), gjid))) || !jc->b) { |
2956 | 1555 g_free(buddy); |
3311 | 1556 gaim_jid_free(gjid); |
2956 | 1557 return; |
1558 } | |
3311 | 1559 if (!find_chat_buddy(jc->b, gjid->resource)) { |
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4357
diff
changeset
|
1560 gaim_chat_add_user(GAIM_CHAT(jc->b), gjid->resource, NULL); |
2086 | 1561 } |
1562 } | |
1563 } | |
1564 } | |
1565 | |
1566 g_free(buddy); | |
3311 | 1567 gaim_jid_free(gjid); |
2086 | 1568 |
1569 return; | |
1570 } | |
1571 | |
3229 | 1572 /* |
1573 * Used only by Jabber accept/deny add stuff just below | |
1574 */ | |
1575 struct jabber_add_permit { | |
4249 | 1576 struct gaim_connection *gc; |
3229 | 1577 gchar *user; |
1578 }; | |
1579 | |
1580 /* | |
1581 * Common part for Jabber accept/deny adds | |
1582 * | |
1583 * "type" says whether we'll permit/deny the subscribe request | |
1584 */ | |
1585 static void jabber_accept_deny_add(struct jabber_add_permit *jap, const char *type) | |
1586 { | |
1587 xmlnode g = xmlnode_new_tag("presence"); | |
1588 | |
1589 xmlnode_put_attrib(g, "to", jap->user); | |
1590 xmlnode_put_attrib(g, "type", type); | |
4249 | 1591 gjab_send(GC_GJ(jap->gc), g); |
3229 | 1592 |
1593 xmlnode_free(g); | |
1594 } | |
1595 | |
1596 /* | |
1597 * Callback from "accept" in do_ask_dialog() invoked by jabber_handles10n() | |
1598 */ | |
3730 | 1599 static void jabber_accept_add(struct jabber_add_permit *jap) |
3229 | 1600 { |
4249 | 1601 if(g_slist_find(connections, jap->gc)) { |
1602 jabber_accept_deny_add(jap, "subscribed"); | |
1603 /* | |
1604 * If we don't already have the buddy on *our* buddylist, | |
1605 * ask if we want him or her added. | |
1606 */ | |
4687 | 1607 if(gaim_find_buddy(jap->gc->account, jap->user) == NULL) { |
4249 | 1608 show_got_added(jap->gc, NULL, jap->user, NULL, NULL); |
1609 } | |
3229 | 1610 } |
4249 | 1611 |
3229 | 1612 g_free(jap->user); |
1613 g_free(jap); | |
1614 } | |
1615 | |
1616 /* | |
1617 * Callback from "deny/cancel" in do_ask_dialog() invoked by jabber_handles10n() | |
1618 */ | |
3730 | 1619 static void jabber_deny_add(struct jabber_add_permit *jap) |
3229 | 1620 { |
4249 | 1621 if(g_slist_find(connections, jap->gc)) { |
1622 jabber_accept_deny_add(jap, "unsubscribed"); | |
1623 } | |
1624 | |
3229 | 1625 g_free(jap->user); |
1626 g_free(jap); | |
1627 } | |
1628 | |
1629 /* | |
1630 * Handle subscription requests | |
1631 */ | |
2956 | 1632 static void jabber_handles10n(gjconn gjc, jpacket p) |
2086 | 1633 { |
1634 xmlnode g; | |
1635 char *Jid = xmlnode_get_attrib(p->x, "from"); | |
3136 | 1636 char *type = xmlnode_get_attrib(p->x, "type"); |
2086 | 1637 |
1638 g = xmlnode_new_tag("presence"); | |
1639 xmlnode_put_attrib(g, "to", Jid); | |
3229 | 1640 |
1641 if (!strcmp(type, "subscribe")) { | |
1642 /* | |
1643 * A "subscribe to us" request was received - put up the approval dialog | |
1644 */ | |
1645 struct jabber_add_permit *jap = g_new0(struct jabber_add_permit, 1); | |
1646 gchar *msg = g_strdup_printf(_("The user %s wants to add you to their buddy list."), | |
1647 Jid); | |
1648 | |
4249 | 1649 jap->gc = GJ_GC(gjc); |
3229 | 1650 jap->user = g_strdup(Jid); |
4249 | 1651 do_ask_dialog(msg, NULL, jap, _("Authorize"), jabber_accept_add, _("Deny"), jabber_deny_add, my_protocol->plug ? my_protocol->plug->handle : NULL, FALSE); |
3229 | 1652 |
1653 g_free(msg); | |
1654 xmlnode_free(g); /* Never needed it here anyway */ | |
1655 return; | |
1656 | |
1657 } else if (!strcmp(type, "unsubscribe")) { | |
1658 /* | |
1659 * An "unsubscribe to us" was received - simply "approve" it | |
1660 */ | |
2086 | 1661 xmlnode_put_attrib(g, "type", "unsubscribed"); |
3229 | 1662 } else { |
1663 /* | |
1664 * Did we attempt to subscribe to somebody and they do not exist? | |
1665 */ | |
3136 | 1666 if (!strcmp(type, "unsubscribed")) { |
1667 xmlnode y; | |
1668 char *status; | |
1669 if((y = xmlnode_get_tag(p->x, "status")) && (status = xmlnode_get_data(y)) && | |
1670 !strcmp(status, "Not Found")) { | |
3427 | 1671 char *msg = g_strdup_printf(_("The Jabber user %s does not exist and was therefore " |
1672 "not added to your roster."), | |
1673 xmlnode_get_attrib(p->x, "from")); | |
1674 do_error_dialog(_("No such user."), msg, GAIM_ERROR ); | |
3136 | 1675 g_free(msg); |
1676 } | |
1677 } | |
1678 | |
2956 | 1679 xmlnode_free(g); |
2086 | 1680 return; |
2956 | 1681 } |
1682 | |
1683 gjab_send(gjc, g); | |
1684 xmlnode_free(g); | |
2086 | 1685 } |
1686 | |
2956 | 1687 /* |
1688 * Pending subscription to a buddy? | |
1689 */ | |
1690 #define BUD_SUB_TO_PEND(sub, ask) ((!strcasecmp((sub), "none") || !strcasecmp((sub), "from")) && \ | |
3770 | 1691 (ask) != NULL && !strcasecmp((ask), "subscribe")) |
2956 | 1692 |
1693 /* | |
1694 * Subscribed to a buddy? | |
1695 */ | |
1696 #define BUD_SUBD_TO(sub, ask) ((!strcasecmp((sub), "to") || !strcasecmp((sub), "both")) && \ | |
1697 ((ask) == NULL || !strcasecmp((ask), "subscribe"))) | |
1698 | |
1699 /* | |
1700 * Pending unsubscription to a buddy? | |
1701 */ | |
1702 #define BUD_USUB_TO_PEND(sub, ask) ((!strcasecmp((sub), "to") || !strcasecmp((sub), "both")) && \ | |
1703 (ask) != NULL && !strcasecmp((ask), "unsubscribe")) | |
1704 | |
1705 /* | |
1706 * Unsubscribed to a buddy? | |
1707 */ | |
1708 #define BUD_USUBD_TO(sub, ask) ((!strcasecmp((sub), "none") || !strcasecmp((sub), "from")) && \ | |
1709 ((ask) == NULL || !strcasecmp((ask), "unsubscribe"))) | |
1710 | |
1711 /* | |
1712 * If a buddy is added or removed from the roster on another resource | |
1713 * jabber_handlebuddy is called | |
1714 * | |
1715 * Called with roster item node. | |
1716 */ | |
1717 static void jabber_handlebuddy(gjconn gjc, xmlnode x) | |
1718 { | |
1719 xmlnode g; | |
3311 | 1720 char *who, *name, *sub, *ask; |
1721 gaim_jid gjid; | |
2956 | 1722 struct buddy *b = NULL; |
4927 | 1723 struct jabber_buddy_data *jbd = NULL; |
3136 | 1724 char *buddyname, *groupname = NULL; |
2956 | 1725 |
3311 | 1726 who = xmlnode_get_attrib(x, "jid"); |
2956 | 1727 name = xmlnode_get_attrib(x, "name"); |
1728 sub = xmlnode_get_attrib(x, "subscription"); | |
1729 ask = xmlnode_get_attrib(x, "ask"); | |
3311 | 1730 |
1731 if((buddyname = get_realwho(gjc, who, FALSE, &gjid)) == NULL) | |
1732 return; | |
2956 | 1733 |
4705 | 1734 |
2956 | 1735 /* JFIXME: jabber_handleroster() had a "FIXME: transport" at this |
1736 * equivilent point. So... | |
1737 * | |
3311 | 1738 * We haven't done anything interesting to this point, so we'll |
1739 * violate Good Coding Structure here by simply bailing out. | |
2956 | 1740 */ |
3311 | 1741 if(!gjid->user) { |
1742 g_free(buddyname); | |
1743 gaim_jid_free(gjid); | |
2956 | 1744 return; |
1745 } | |
3311 | 1746 gaim_jid_free(gjid); |
2956 | 1747 |
3236 | 1748 if((g = xmlnode_get_tag(x, "group")) != NULL) { |
3136 | 1749 groupname = xmlnode_get_data(g); |
2956 | 1750 } |
1751 | |
3059 | 1752 /* |
3136 | 1753 * Add or remove a buddy? Change buddy's alias or group? |
3059 | 1754 */ |
2956 | 1755 if (BUD_SUB_TO_PEND(sub, ask) || BUD_SUBD_TO(sub, ask)) { |
4687 | 1756 if ((b = gaim_find_buddy(GJ_GC(gjc)->account, buddyname)) == NULL) { |
4932 | 1757 struct group *g; |
4927 | 1758 b = gaim_buddy_new(GJ_GC(gjc)->account, buddyname, name); |
4687 | 1759 if (groupname) { |
4775 | 1760 if (!(g = gaim_find_group(groupname))) { |
4687 | 1761 g = gaim_group_new(groupname); |
4775 | 1762 gaim_blist_add_group(g, NULL); |
1763 } | |
1764 } else { | |
4687 | 1765 g = gaim_group_new(_("Buddies")); |
4775 | 1766 gaim_blist_add_group(g, NULL); |
1767 } | |
2956 | 1768 debug_printf("adding buddy [4]: %s\n", buddyname); |
4687 | 1769 gaim_blist_add_buddy(b, g, NULL); |
4349 | 1770 gaim_blist_save(); |
3136 | 1771 } else { |
4687 | 1772 struct group *c_grp = gaim_find_buddys_group(b); |
3136 | 1773 |
3770 | 1774 /* |
3136 | 1775 * If the buddy's in a new group or his/her alias is changed... |
1776 */ | |
1777 if(groupname && c_grp && strcmp(c_grp->name, groupname)) { | |
1778 int present = b->present; /* save presence state */ | |
1779 int uc = b->uc; /* and away state (?) */ | |
3150 | 1780 int idle = b->idle; |
1781 int signon = b->signon; | |
3136 | 1782 |
1783 /* | |
5068 | 1784 * FIXME: this ugly hack is no longer needed |
3136 | 1785 * seems rude, but it seems to be the only way... |
1786 */ | |
4687 | 1787 gaim_blist_remove_buddy(b); |
4705 | 1788 b = gaim_buddy_new(GJ_GC(gjc)->account, buddyname, name); |
4687 | 1789 gaim_blist_add_buddy(b, gaim_find_group(groupname), NULL); |
4349 | 1790 gaim_blist_save(); |
5068 | 1791 if(present > 0) { |
3311 | 1792 serv_got_update(GJ_GC(gjc), buddyname, 1, 0, signon, idle, |
4732 | 1793 uc); |
3136 | 1794 } |
4227 | 1795 } else if(name != NULL && strcmp(b->alias, name)) { |
4705 | 1796 g_free(b->alias); |
1797 b->alias = g_strdup(name); | |
4687 | 1798 gaim_blist_rename_buddy(b, buddyname); |
4349 | 1799 gaim_blist_save(); |
3136 | 1800 } |
2956 | 1801 } |
1802 } else if (BUD_USUB_TO_PEND(sub, ask) || BUD_USUBD_TO(sub, ask) || !strcasecmp(sub, "remove")) { | |
3236 | 1803 jabber_remove_gaim_buddy(GJ_GC(gjc), buddyname); |
2956 | 1804 } |
5135 | 1805 if(b && (jbd = jabber_find_buddy(b->account->gc, buddyname, TRUE)) != NULL) { |
4927 | 1806 jbd->subscription = JABBER_SUB_NONE; |
1807 if(!strcasecmp(sub, "to")) | |
1808 jbd->subscription |= JABBER_SUB_TO; | |
1809 else if(!strcasecmp(sub, "from")) | |
1810 jbd->subscription |= JABBER_SUB_FROM; | |
1811 else if(!strcasecmp(sub, "both")) | |
1812 jbd->subscription |= JABBER_SUB_BOTH; | |
1813 | |
1814 if(ask && !strcasecmp(ask, "subscribe")) | |
1815 jbd->subscription |= JABBER_SUB_PENDING; | |
1816 } | |
3328 | 1817 |
2956 | 1818 g_free(buddyname); |
1819 | |
1820 } | |
1821 | |
1822 static void jabber_handleroster(gjconn gjc, xmlnode querynode) | |
2086 | 1823 { |
1824 xmlnode x; | |
1825 | |
1826 x = xmlnode_get_firstchild(querynode); | |
1827 while (x) { | |
2956 | 1828 jabber_handlebuddy(gjc, x); |
2086 | 1829 x = xmlnode_get_nextsibling(x); |
1830 } | |
1831 | |
1832 x = jutil_presnew(0, NULL, "Online"); | |
2956 | 1833 gjab_send(gjc, x); |
2086 | 1834 xmlnode_free(x); |
1835 } | |
1836 | |
2956 | 1837 static void jabber_handleauthresp(gjconn gjc, jpacket p) |
2086 | 1838 { |
1839 if (jpacket_subtype(p) == JPACKET__RESULT) { | |
2814
f4f9e5a01890
[gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2800
diff
changeset
|
1840 if (xmlnode_has_children(p->x)) { |
f4f9e5a01890
[gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2800
diff
changeset
|
1841 xmlnode query = xmlnode_get_tag(p->x, "query"); |
2975 | 1842 set_login_progress(GJ_GC(gjc), 4, _("Authenticating")); |
2814
f4f9e5a01890
[gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2800
diff
changeset
|
1843 if (!xmlnode_get_tag(query, "digest")) { |
2956 | 1844 g_free(gjc->sid); |
1845 gjc->sid = NULL; | |
2814
f4f9e5a01890
[gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2800
diff
changeset
|
1846 } |
2956 | 1847 gjab_auth(gjc); |
2814
f4f9e5a01890
[gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2800
diff
changeset
|
1848 } else { |
f4f9e5a01890
[gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2800
diff
changeset
|
1849 debug_printf("auth success\n"); |
2086 | 1850 |
2956 | 1851 account_online(GJ_GC(gjc)); |
1852 serv_finish_login(GJ_GC(gjc)); | |
1853 | |
1854 ((struct jabber_data *)GJ_GC(gjc)->proto_data)->did_import = TRUE; | |
1855 | |
1856 gjab_reqroster(gjc); | |
2814
f4f9e5a01890
[gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2800
diff
changeset
|
1857 } |
2086 | 1858 } else { |
1859 xmlnode xerr; | |
1860 char *errmsg = NULL; | |
1861 int errcode = 0; | |
2956 | 1862 struct jabber_data *jd = GJ_GC(gjc)->proto_data; |
2086 | 1863 |
1864 debug_printf("auth failed\n"); | |
1865 xerr = xmlnode_get_tag(p->x, "error"); | |
1866 if (xerr) { | |
1867 char msg[BUF_LONG]; | |
1868 errmsg = xmlnode_get_data(xerr); | |
1869 if (xmlnode_get_attrib(xerr, "code")) { | |
1870 errcode = atoi(xmlnode_get_attrib(xerr, "code")); | |
1871 g_snprintf(msg, sizeof(msg), "Error %d: %s", errcode, errmsg); | |
1872 } else | |
1873 g_snprintf(msg, sizeof(msg), "%s", errmsg); | |
2956 | 1874 hide_login_progress(GJ_GC(gjc), msg); |
2086 | 1875 } else { |
2975 | 1876 hide_login_progress(GJ_GC(gjc), _("Unknown login error")); |
2086 | 1877 } |
1878 | |
2800
0ad63a625eec
[gaim-migrate @ 2813]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2791
diff
changeset
|
1879 jd->die = TRUE; |
2086 | 1880 } |
1881 } | |
1882 | |
2956 | 1883 static void jabber_handleversion(gjconn gjc, xmlnode iqnode) { |
2086 | 1884 xmlnode querynode, x; |
1885 char *id, *from; | |
1886 char os[1024]; | |
1887 struct utsname osinfo; | |
1888 | |
1889 uname(&osinfo); | |
1890 g_snprintf(os, sizeof os, "%s %s %s", osinfo.sysname, osinfo.release, osinfo.machine); | |
1891 | |
1892 id = xmlnode_get_attrib(iqnode, "id"); | |
1893 from = xmlnode_get_attrib(iqnode, "from"); | |
1894 | |
1895 x = jutil_iqnew(JPACKET__RESULT, NS_VERSION); | |
1896 | |
1897 xmlnode_put_attrib(x, "to", from); | |
1898 xmlnode_put_attrib(x, "id", id); | |
1899 querynode = xmlnode_get_tag(x, "query"); | |
1900 xmlnode_insert_cdata(xmlnode_insert_tag(querynode, "name"), PACKAGE, -1); | |
1901 xmlnode_insert_cdata(xmlnode_insert_tag(querynode, "version"), VERSION, -1); | |
1902 xmlnode_insert_cdata(xmlnode_insert_tag(querynode, "os"), os, -1); | |
1903 | |
2956 | 1904 gjab_send(gjc, x); |
2086 | 1905 |
1906 xmlnode_free(x); | |
1907 } | |
1908 | |
2956 | 1909 static void jabber_handletime(gjconn gjc, xmlnode iqnode) { |
2086 | 1910 xmlnode querynode, x; |
1911 char *id, *from; | |
3770 | 1912 time_t now_t; |
2086 | 1913 struct tm *now; |
1914 char buf[1024]; | |
1915 | |
1916 time(&now_t); | |
1917 now = localtime(&now_t); | |
1918 | |
1919 id = xmlnode_get_attrib(iqnode, "id"); | |
1920 from = xmlnode_get_attrib(iqnode, "from"); | |
1921 | |
1922 x = jutil_iqnew(JPACKET__RESULT, NS_TIME); | |
1923 | |
1924 xmlnode_put_attrib(x, "to", from); | |
1925 xmlnode_put_attrib(x, "id", id); | |
1926 querynode = xmlnode_get_tag(x, "query"); | |
1927 | |
1928 strftime(buf, 1024, "%Y%m%dT%T", now); | |
1929 xmlnode_insert_cdata(xmlnode_insert_tag(querynode, "utc"), buf, -1); | |
1930 strftime(buf, 1024, "%Z", now); | |
1931 xmlnode_insert_cdata(xmlnode_insert_tag(querynode, "tz"), buf, -1); | |
1932 strftime(buf, 1024, "%d %b %Y %T", now); | |
1933 xmlnode_insert_cdata(xmlnode_insert_tag(querynode, "display"), buf, -1); | |
3770 | 1934 |
2956 | 1935 gjab_send(gjc, x); |
2086 | 1936 |
1937 xmlnode_free(x); | |
1938 } | |
1939 | |
4538 | 1940 struct jabber_xfer_data { |
3630 | 1941 struct g_url *url; |
1942 GString *headers; | |
1943 gboolean newline; | |
4538 | 1944 |
1945 char *iq_id; | |
1946 | |
1947 struct jabber_data *jd; | |
3630 | 1948 }; |
1949 | |
4538 | 1950 static void jabber_xfer_init(struct gaim_xfer *xfer) |
1951 { | |
1952 struct jabber_xfer_data *data = xfer->data; | |
1953 gaim_xfer_start(xfer, -1, data->url->address, data->url->port); | |
1954 } | |
1955 | |
1956 static void jabber_xfer_free(struct gaim_xfer *xfer) | |
1957 { | |
1958 struct jabber_xfer_data *data = xfer->data; | |
1959 data->jd->file_transfers = g_slist_remove(data->jd->file_transfers, xfer); | |
1960 | |
1961 g_string_free(data->headers, TRUE); | |
1962 g_free(data->url); | |
1963 g_free(data->iq_id); | |
1964 g_free(data); | |
1965 | |
1966 xfer->data = NULL; | |
3630 | 1967 } |
1968 | |
4538 | 1969 static void jabber_xfer_end(struct gaim_xfer *xfer) |
1970 { | |
1971 struct jabber_xfer_data *data = xfer->data; | |
1972 xmlnode x; | |
1973 | |
1974 x = xmlnode_new_tag("iq"); | |
1975 xmlnode_put_attrib(x, "type", "result"); | |
1976 xmlnode_put_attrib(x, "to", xfer->who); | |
1977 xmlnode_put_attrib(x, "id", data->iq_id); | |
1978 | |
1979 gjab_send(data->jd->gjc, x); | |
1980 | |
1981 xmlnode_free(x); | |
1982 | |
1983 jabber_xfer_free(xfer); | |
1984 } | |
1985 | |
1986 static void jabber_xfer_start(struct gaim_xfer *xfer) | |
1987 { | |
1988 struct jabber_xfer_data *data = xfer->data; | |
1989 char *buf = g_strdup_printf("GET /%s HTTP/1.1\r\nHost: %s\r\n\r\n", | |
1990 data->url->page, data->url->address); | |
1991 write(xfer->fd, buf, strlen(buf)); | |
1992 g_free(buf); | |
1993 } | |
1994 | |
1995 static size_t jabber_xfer_read(char **buffer, struct gaim_xfer *xfer) { | |
1996 struct jabber_xfer_data *data = xfer->data; | |
3630 | 1997 char test; |
4538 | 1998 size_t size; |
1999 | |
2000 if(read(xfer->fd, &test, sizeof(test)) > 0) { | |
2001 data->headers = g_string_append_c(data->headers, test); | |
2002 if(test == '\r') | |
2003 return 0; | |
2004 if(test == '\n') { | |
2005 if(data->newline) { | |
2006 gchar *lenstr = strstr(data->headers->str, "Content-Length: "); | |
2007 if(lenstr) { | |
2008 sscanf(lenstr, "Content-Length: %d", &size); | |
2009 gaim_xfer_set_size(xfer, size); | |
2010 } | |
2011 gaim_xfer_set_read_fnc(xfer, NULL); | |
2012 return 0; | |
2013 } else | |
2014 data->newline = TRUE; | |
2015 return 0; | |
3630 | 2016 } |
4538 | 2017 data->newline = FALSE; |
2018 return 0; | |
3630 | 2019 } |
4538 | 2020 return 0; |
3630 | 2021 } |
2022 | |
4675
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4634
diff
changeset
|
2023 static void jabber_xfer_cancel_send(struct gaim_xfer *xfer) { |
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4634
diff
changeset
|
2024 } |
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4634
diff
changeset
|
2025 |
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4634
diff
changeset
|
2026 static void jabber_xfer_cancel_recv(struct gaim_xfer *xfer) { |
4538 | 2027 struct jabber_xfer_data *data = xfer->data; |
3630 | 2028 xmlnode x,y; |
2029 | |
2030 x = xmlnode_new_tag("iq"); | |
2031 xmlnode_put_attrib(x, "type", "error"); | |
4538 | 2032 xmlnode_put_attrib(x, "to", xfer->who); |
2033 xmlnode_put_attrib(x, "id", data->iq_id); | |
3630 | 2034 y = xmlnode_insert_tag(x, "error"); |
2035 /* FIXME: need to handle other kinds of errors here */ | |
2036 xmlnode_put_attrib(y, "code", "406"); | |
2037 xmlnode_insert_cdata(y, "File Transfer Refused", -1); | |
2038 | |
4538 | 2039 gjab_send(data->jd->gjc, x); |
3630 | 2040 |
2041 xmlnode_free(x); | |
2042 | |
4538 | 2043 jabber_xfer_free(xfer); |
3630 | 2044 } |
2045 | |
2046 static void jabber_handleoob(gjconn gjc, xmlnode iqnode) { | |
4538 | 2047 struct jabber_xfer_data *xfer_data; |
3630 | 2048 struct jabber_data *jd = GJ_GC(gjc)->proto_data; |
4675
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4634
diff
changeset
|
2049 struct gaim_xfer *xfer; |
3630 | 2050 char *msg = NULL; |
4538 | 2051 char *filename; |
3630 | 2052 xmlnode querynode = xmlnode_get_tag(iqnode, "query"); |
2053 xmlnode urlnode,descnode; | |
2054 | |
2055 if(!querynode) | |
2056 return; | |
2057 urlnode = xmlnode_get_tag(querynode, "url"); | |
2058 if(!urlnode) | |
2059 return; | |
2060 descnode = xmlnode_get_tag(querynode, "desc"); | |
2061 if(descnode) | |
2062 msg = xmlnode_get_data(descnode); | |
2063 | |
4538 | 2064 xfer_data = g_new0(struct jabber_xfer_data, 1); |
2065 xfer_data->url = parse_url(xmlnode_get_data(urlnode)); | |
2066 xfer_data->jd = jd; | |
2067 xfer_data->headers = g_string_new(""); | |
2068 xfer_data->iq_id = g_strdup(xmlnode_get_attrib(iqnode, "id")); | |
2069 | |
2070 xfer = gaim_xfer_new(GJ_GC(gjc)->account, GAIM_XFER_RECEIVE, | |
2071 xmlnode_get_attrib(iqnode, "from")); | |
2072 xfer->data = xfer_data; | |
2073 | |
2074 filename = g_strdup(g_strrstr(xfer_data->url->page, "/")); | |
2075 if(!filename) | |
2076 filename = g_strdup(xfer_data->url->page); | |
2077 | |
2078 gaim_xfer_set_filename(xfer, filename); | |
2079 | |
2080 g_free(filename); | |
2081 | |
2082 gaim_xfer_set_init_fnc(xfer, jabber_xfer_init); | |
2083 gaim_xfer_set_end_fnc(xfer, jabber_xfer_end); | |
4675
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4634
diff
changeset
|
2084 gaim_xfer_set_cancel_send_fnc(xfer, jabber_xfer_cancel_send); |
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4634
diff
changeset
|
2085 gaim_xfer_set_cancel_recv_fnc(xfer, jabber_xfer_cancel_recv); |
4538 | 2086 gaim_xfer_set_read_fnc(xfer, jabber_xfer_read); |
2087 gaim_xfer_set_start_fnc(xfer, jabber_xfer_start); | |
2088 | |
2089 jd->file_transfers = g_slist_append(jd->file_transfers, xfer); | |
2090 | |
2091 gaim_xfer_request(xfer); | |
3630 | 2092 } |
2093 | |
2956 | 2094 static void jabber_handlelast(gjconn gjc, xmlnode iqnode) { |
3630 | 2095 xmlnode x, querytag; |
2086 | 2096 char *id, *from; |
2956 | 2097 struct jabber_data *jd = GJ_GC(gjc)->proto_data; |
2086 | 2098 char idle_time[32]; |
3630 | 2099 |
2086 | 2100 id = xmlnode_get_attrib(iqnode, "id"); |
2101 from = xmlnode_get_attrib(iqnode, "from"); | |
2102 | |
2103 x = jutil_iqnew(JPACKET__RESULT, "jabber:iq:last"); | |
2104 | |
2105 xmlnode_put_attrib(x, "to", from); | |
2106 xmlnode_put_attrib(x, "id", id); | |
2107 querytag = xmlnode_get_tag(x, "query"); | |
2108 g_snprintf(idle_time, sizeof idle_time, "%ld", jd->idle ? time(NULL) - jd->idle : 0); | |
2109 xmlnode_put_attrib(querytag, "seconds", idle_time); | |
2110 | |
2956 | 2111 gjab_send(gjc, x); |
2086 | 2112 xmlnode_free(x); |
2113 } | |
2114 | |
2956 | 2115 /* |
2116 * delete == TRUE: delete found entry | |
2117 * | |
2118 * returns pointer to (local) copy of value if found, NULL otherwise | |
2119 * | |
2120 * Note: non-reentrant! Local static storage re-used on subsequent calls. | |
2121 * If you're going to need to keep the returned value, make a copy! | |
2122 */ | |
2123 static gchar *jabber_track_queries(GHashTable *queries, gchar *key, gboolean delete) | |
2124 { | |
2125 gpointer my_key, my_val; | |
2126 static gchar *ret_val = NULL; | |
2127 | |
2128 if(ret_val != NULL) { | |
2129 g_free(ret_val); | |
2130 ret_val = NULL; | |
2131 } | |
2132 | |
2133 /* self-protection */ | |
2134 if(queries != NULL && key != NULL) { | |
2135 if(g_hash_table_lookup_extended(queries, key, &my_key, &my_val)) { | |
2136 ret_val = g_strdup((gchar *) my_val); | |
2137 if(delete) { | |
2138 g_hash_table_remove(queries, key); | |
2139 g_free(my_key); | |
2140 g_free(my_val); | |
2141 } | |
2142 } | |
2143 } | |
2144 | |
2145 return(ret_val); | |
2146 } | |
2147 | |
2148 static void jabber_handlepacket(gjconn gjc, jpacket p) | |
2086 | 2149 { |
2814
f4f9e5a01890
[gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2800
diff
changeset
|
2150 char *id; |
2086 | 2151 switch (p->type) { |
2152 case JPACKET_MESSAGE: | |
2956 | 2153 jabber_handlemessage(gjc, p); |
2086 | 2154 break; |
2155 case JPACKET_PRESENCE: | |
2956 | 2156 jabber_handlepresence(gjc, p); |
2086 | 2157 break; |
2158 case JPACKET_IQ: | |
2159 debug_printf("jpacket_subtype: %d\n", jpacket_subtype(p)); | |
2160 | |
2956 | 2161 id = xmlnode_get_attrib(p->x, "id"); |
2162 if (id != NULL && !strcmp(id, IQID_AUTH)) { | |
2163 jabber_handleauthresp(gjc, p); | |
2814
f4f9e5a01890
[gaim-migrate @ 2827]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2800
diff
changeset
|
2164 break; |
2086 | 2165 } |
2166 | |
2167 if (jpacket_subtype(p) == JPACKET__SET) { | |
2956 | 2168 xmlnode querynode; |
2169 querynode = xmlnode_get_tag(p->x, "query"); | |
2170 if (NSCHECK(querynode, "jabber:iq:roster")) { | |
2171 jabber_handlebuddy(gjc, xmlnode_get_firstchild(querynode)); | |
3630 | 2172 } else if(NSCHECK(querynode, "jabber:iq:oob")) { |
2173 jabber_handleoob(gjc, p->x); | |
2956 | 2174 } |
2086 | 2175 } else if (jpacket_subtype(p) == JPACKET__GET) { |
3770 | 2176 xmlnode querynode; |
2086 | 2177 querynode = xmlnode_get_tag(p->x, "query"); |
3770 | 2178 if (NSCHECK(querynode, NS_VERSION)) { |
2179 jabber_handleversion(gjc, p->x); | |
2086 | 2180 } else if (NSCHECK(querynode, NS_TIME)) { |
3770 | 2181 jabber_handletime(gjc, p->x); |
2086 | 2182 } else if (NSCHECK(querynode, "jabber:iq:last")) { |
3770 | 2183 jabber_handlelast(gjc, p->x); |
2086 | 2184 } |
2185 } else if (jpacket_subtype(p) == JPACKET__RESULT) { | |
2186 xmlnode querynode, vcard; | |
2187 char *xmlns, *from; | |
2188 | |
2956 | 2189 /* |
2190 * TBD: ISTM maybe this part could use a serious re-work? | |
2191 */ | |
2086 | 2192 from = xmlnode_get_attrib(p->x, "from"); |
2193 querynode = xmlnode_get_tag(p->x, "query"); | |
2194 vcard = xmlnode_get_tag(p->x, "vCard"); | |
2316
ebb5ecb2cd5b
[gaim-migrate @ 2326]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
2195 if (!vcard) |
ebb5ecb2cd5b
[gaim-migrate @ 2326]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
2196 vcard = xmlnode_get_tag(p->x, "VCARD"); |
2086 | 2197 |
2198 if (NSCHECK(querynode, NS_ROSTER)) { | |
2956 | 2199 jabber_handleroster(gjc, querynode); |
2086 | 2200 } else if (NSCHECK(querynode, NS_VCARD)) { |
2956 | 2201 jabber_track_queries(gjc->queries, id, TRUE); /* delete query track */ |
3770 | 2202 jabber_handlevcard(gjc, querynode, from); |
2316
ebb5ecb2cd5b
[gaim-migrate @ 2326]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
2203 } else if (vcard) { |
2956 | 2204 jabber_track_queries(gjc->queries, id, TRUE); /* delete query track */ |
2205 jabber_handlevcard(gjc, vcard, from); | |
2206 } else if((xmlns = xmlnode_get_attrib(querynode, "xmlns")) != NULL) { | |
2207 debug_printf("jabber:iq:query: %s\n", xmlns); | |
2086 | 2208 } else { |
2956 | 2209 char *val; |
2210 | |
2211 debug_printf("jabber:iq: %s\n", xmlnode2str(p->x)); | |
2212 | |
2213 /* handle "null" query results */ | |
2214 if((val = jabber_track_queries(gjc->queries, id, TRUE)) != NULL) { | |
2215 if(strcmp((char *) val, "vCard") == 0) { | |
2216 /* | |
2217 * No actual vCard, but there's other stuff. This | |
2218 * way the user always gets some kind of response. | |
2219 */ | |
2220 jabber_handlevcard(gjc, NULL, from); | |
3257 | 2221 } else if(!strcmp((char *) val, "change_password")) { |
2222 char buf[BUF_LONG]; | |
3311 | 2223 sprintf(buf, _("Password successfully changed.")); |
3257 | 2224 |
3427 | 2225 do_error_dialog(buf, NULL, GAIM_INFO); |
2956 | 2226 } |
2227 } | |
2086 | 2228 } |
2229 | |
2230 } else if (jpacket_subtype(p) == JPACKET__ERROR) { | |
2231 xmlnode xerr; | |
2232 char *from, *errmsg = NULL; | |
2233 int errcode = 0; | |
2234 | |
2235 from = xmlnode_get_attrib(p->x, "from"); | |
2236 xerr = xmlnode_get_tag(p->x, "error"); | |
2237 if (xerr) { | |
2238 errmsg = xmlnode_get_data(xerr); | |
2239 if (xmlnode_get_attrib(xerr, "code")) | |
2240 errcode = atoi(xmlnode_get_attrib(xerr, "code")); | |
2241 } | |
2242 | |
3427 | 2243 from = g_strdup_printf("Jabber Error %d (%s)", errcode, from); |
2244 do_error_dialog(from, errmsg, GAIM_ERROR); | |
2086 | 2245 g_free(from); |
2246 | |
2247 } | |
2248 | |
2249 break; | |
2250 case JPACKET_S10N: | |
2956 | 2251 jabber_handles10n(gjc, p); |
2086 | 2252 break; |
2253 default: | |
2254 debug_printf("jabber: packet type %d (%s)\n", p->type, xmlnode2str(p->x)); | |
2255 } | |
2256 | |
2257 xmlnode_free(p->x); | |
2258 | |
2259 return; | |
2260 } | |
2261 | |
2956 | 2262 static void jabber_handlestate(gjconn gjc, int state) |
2086 | 2263 { |
2264 switch (state) { | |
2265 case JCONN_STATE_OFF: | |
3074 | 2266 if(gjc->was_connected) { |
2267 hide_login_progress_error(GJ_GC(gjc), _("Connection lost")); | |
2268 } else { | |
2269 hide_login_progress(GJ_GC(gjc), _("Unable to connect")); | |
2270 } | |
2956 | 2271 signoff(GJ_GC(gjc)); |
2086 | 2272 break; |
2273 case JCONN_STATE_CONNECTED: | |
3074 | 2274 gjc->was_connected = 1; |
2975 | 2275 set_login_progress(GJ_GC(gjc), 2, _("Connected")); |
2086 | 2276 break; |
2277 case JCONN_STATE_ON: | |
2975 | 2278 set_login_progress(GJ_GC(gjc), 3, _("Requesting Authentication Method")); |
2956 | 2279 gjab_reqauth(gjc); |
2086 | 2280 break; |
2281 default: | |
2282 debug_printf("state change: %d\n", state); | |
2283 } | |
2284 return; | |
2285 } | |
2286 | |
4491 | 2287 static void jabber_login(struct gaim_account *account) |
2086 | 2288 { |
4491 | 2289 struct gaim_connection *gc = new_gaim_conn(account); |
2086 | 2290 struct jabber_data *jd = gc->proto_data = g_new0(struct jabber_data, 1); |
4917 | 2291 char *loginname = create_valid_jid(account->username, DEFAULT_SERVER, "Gaim"); |
2086 | 2292 |
3311 | 2293 jd->buddies = g_hash_table_new(g_str_hash, g_str_equal); |
2956 | 2294 jd->chats = NULL; /* we have no chats yet */ |
2086 | 2295 |
2975 | 2296 set_login_progress(gc, 1, _("Connecting")); |
2086 | 2297 |
4491 | 2298 if (!(jd->gjc = gjab_new(loginname, account->password, gc))) { |
2086 | 2299 g_free(loginname); |
2300 debug_printf("jabber: unable to connect (jab_new failed)\n"); | |
2975 | 2301 hide_login_progress(gc, _("Unable to connect")); |
2086 | 2302 signoff(gc); |
2303 return; | |
2304 } | |
2305 | |
2306 g_free(loginname); | |
2956 | 2307 gjab_state_handler(jd->gjc, jabber_handlestate); |
2308 gjab_packet_handler(jd->gjc, jabber_handlepacket); | |
2309 jd->gjc->queries = g_hash_table_new(g_str_hash, g_str_equal); | |
2310 gjab_start(jd->gjc); | |
2086 | 2311 } |
2312 | |
2313 static gboolean jabber_destroy_hash(gpointer key, gpointer val, gpointer data) { | |
3770 | 2314 g_free(key); |
2086 | 2315 g_free(val); |
2316 return TRUE; | |
2317 } | |
2318 | |
3311 | 2319 static gboolean jabber_destroy_buddy_hash(gpointer key, gpointer val, gpointer data) { |
2320 struct jabber_buddy_data *jbd = val; | |
2321 while (jbd->resources) { | |
2322 g_free(((jab_res_info) ((GSList *)jbd->resources)->data)->name); | |
2323 if(((jab_res_info) ((GSList *)jbd->resources)->data)->away_msg) | |
2324 g_free(((jab_res_info) ((GSList *)jbd->resources)->data)->away_msg); | |
2325 g_free(((GSList *)jbd->resources)->data); | |
2326 jbd->resources = g_slist_remove(jbd->resources, ((GSList *)jbd->resources)->data); | |
2327 | |
2328 } | |
2329 if(jbd->error_msg) | |
2330 g_free(jbd->error_msg); | |
2331 g_free(key); | |
2332 g_free(jbd); | |
2333 return TRUE; | |
2334 } | |
2335 | |
2336 | |
2086 | 2337 static gboolean jabber_free(gpointer data) |
2338 { | |
2956 | 2339 struct jabber_data *jd = data; |
2340 | |
3236 | 2341 if(jd->gjc != NULL) { |
3486 | 2342 g_free(jd->gjc->sid); |
3236 | 2343 gjab_delete(jd->gjc); |
2344 jd->gjc = NULL; | |
2345 } | |
2956 | 2346 g_free(jd); |
2347 | |
2086 | 2348 return FALSE; |
2349 } | |
2350 | |
2351 static void jabber_close(struct gaim_connection *gc) | |
2352 { | |
2353 struct jabber_data *jd = gc->proto_data; | |
2956 | 2354 |
2355 if(jd) { | |
2356 GSList *jcs = jd->chats; | |
2357 | |
2358 /* Free-up the jabber_chat struct allocs and the list */ | |
2359 while (jcs) { | |
3311 | 2360 gaim_jid_free(((struct jabber_chat *)jcs->data)->gjid); |
2956 | 2361 g_free(jcs->data); |
2362 jcs = jcs->next; | |
2363 } | |
2364 g_slist_free(jd->chats); | |
2365 | |
3311 | 2366 /* Free-up the buddy data hash */ |
2367 if(jd->buddies != NULL) | |
2368 { | |
2369 g_hash_table_foreach_remove(jd->buddies, jabber_destroy_buddy_hash, NULL); | |
2370 g_hash_table_destroy(jd->buddies); | |
2371 jd->buddies = NULL; | |
2956 | 2372 } |
2373 | |
2374 /* Free-up the pending queries memories and the list */ | |
3236 | 2375 if(jd->gjc != NULL && jd->gjc->queries != NULL) { |
2956 | 2376 g_hash_table_foreach_remove(jd->gjc->queries, jabber_destroy_hash, NULL); |
2377 g_hash_table_destroy(jd->gjc->queries); | |
2378 jd->gjc->queries = NULL; | |
2379 } | |
2380 } | |
2300
d2686f757d6e
[gaim-migrate @ 2310]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2289
diff
changeset
|
2381 if (gc->inpa) |
d2686f757d6e
[gaim-migrate @ 2310]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2289
diff
changeset
|
2382 gaim_input_remove(gc->inpa); |
2956 | 2383 |
2384 if(jd) { | |
3613 | 2385 g_timeout_add(0, jabber_free, jd); |
3236 | 2386 if(jd->gjc != NULL) |
2387 xmlnode_free(jd->gjc->current); | |
2956 | 2388 } |
2086 | 2389 gc->proto_data = NULL; |
2390 } | |
2391 | |
3311 | 2392 static int jabber_send_typing(struct gaim_connection *gc, char *who, int typing) |
2393 { | |
2394 xmlnode x, y; | |
2395 char *realwho; | |
2396 gjconn gjc = ((struct jabber_data *)gc->proto_data)->gjc; | |
2397 jab_res_info jri = jabber_find_resource(gc, who); | |
2398 | |
2399 if(!jri || !jri->has_composing) | |
2400 return 0; | |
2401 | |
2402 if((realwho = get_realwho(gjc, who, FALSE, NULL)) == NULL) | |
2403 return 0; | |
3596 | 2404 |
3311 | 2405 x = xmlnode_new_tag("message"); |
2406 xmlnode_put_attrib(x, "to", realwho); | |
2407 xmlnode_insert_tag(x, "gaim"); | |
2408 | |
2409 y = xmlnode_insert_tag(x, "x"); | |
2410 xmlnode_put_attrib(y, "xmlns", "jabber:x:event"); | |
2411 | |
3596 | 2412 if(typing == TYPING) |
3311 | 2413 xmlnode_insert_tag(y, "composing"); |
3596 | 2414 |
3311 | 2415 gjab_send(((struct jabber_data *)gc->proto_data)->gjc, x); |
2416 xmlnode_free(x); | |
2417 g_free(realwho); | |
2418 return JABBER_TYPING_NOTIFY_INT; | |
2419 } | |
2420 | |
5093 | 2421 static void insert_message(xmlnode x, const char *message, gboolean use_xhtml) { |
2422 xmlnode y; | |
5110 | 2423 char *buf = g_strdup_printf("<html xmlns='http://jabber.org/protocol/xhtml-im'><body>%s</body></html>", message); |
2424 char *xhtml, *plain; | |
2425 | |
2426 html_to_xhtml(buf, &xhtml, &plain); | |
2427 g_free(buf); | |
2428 | |
5093 | 2429 y = xmlnode_insert_tag(x, "body"); |
5110 | 2430 xmlnode_insert_cdata(y, plain, -1); |
2431 g_free(plain); | |
5093 | 2432 |
2433 if(use_xhtml) { | |
5110 | 2434 y = xmlnode_str(xhtml, strlen(xhtml)); |
5093 | 2435 if(y) { |
2436 xmlnode_insert_tag_node(x, y); | |
2437 xmlnode_free(y); | |
2438 } else { | |
2439 debug_printf("holy cow, html_to_xhtml didn't work right!\n"); | |
5110 | 2440 debug_printf("the invalid XML: %s\n", xhtml); |
5093 | 2441 } |
2442 } | |
5110 | 2443 g_free(xhtml); |
5093 | 2444 } |
2445 | |
3033 | 2446 static int jabber_send_im(struct gaim_connection *gc, char *who, char *message, int len, int flags) |
2086 | 2447 { |
2448 xmlnode x, y; | |
3311 | 2449 char *thread_id = NULL; |
2956 | 2450 gjconn gjc = ((struct jabber_data *)gc->proto_data)->gjc; |
5093 | 2451 jab_res_info jri = jabber_find_resource(gc, who); |
2086 | 2452 |
2453 if (!who || !message) | |
2123
56c4382f2909
[gaim-migrate @ 2133]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2112
diff
changeset
|
2454 return 0; |
2086 | 2455 |
2456 x = xmlnode_new_tag("message"); | |
4927 | 2457 xmlnode_put_attrib(x, "to", who); |
2458 | |
2459 thread_id = jabber_get_convo_thread(gjc, who); | |
3311 | 2460 if(thread_id) |
2461 { | |
3769 | 2462 if(strcmp(thread_id, "")) { |
2463 y = xmlnode_insert_tag(x, "thread"); | |
2464 xmlnode_insert_cdata(y, thread_id, -1); | |
2465 } | |
3311 | 2466 g_free(thread_id); |
2467 } | |
2468 | |
2278
00a8b7bcef6c
[gaim-migrate @ 2288]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2232
diff
changeset
|
2469 xmlnode_insert_tag(x, "gaim"); |
2086 | 2470 xmlnode_put_attrib(x, "type", "chat"); |
2471 | |
3311 | 2472 /* let other clients know we support typing notification */ |
2473 y = xmlnode_insert_tag(x, "x"); | |
2474 xmlnode_put_attrib(y, "xmlns", "jabber:x:event"); | |
2475 xmlnode_insert_tag(y, "composing"); | |
2476 | |
2086 | 2477 if (message && strlen(message)) { |
5093 | 2478 insert_message(x, message, jri ? jri->has_xhtml : TRUE); |
2086 | 2479 } |
2480 | |
2956 | 2481 gjab_send(((struct jabber_data *)gc->proto_data)->gjc, x); |
2086 | 2482 xmlnode_free(x); |
2303
f5bf315e6104
[gaim-migrate @ 2313]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2300
diff
changeset
|
2483 return 1; |
2086 | 2484 } |
2485 | |
3105 | 2486 /* |
2487 * Add/update buddy's roster entry on server | |
3349 | 2488 * |
2489 * If "alias" or "group" are NULL, gets them from Gaim's current buddylist values | |
2490 * for the buddy. | |
3105 | 2491 */ |
3867 | 2492 static void jabber_roster_update(struct gaim_connection *gc, const char *name, const char *alias, const char *group) |
3105 | 2493 { |
2494 xmlnode x, y; | |
2495 char *realwho; | |
2496 gjconn gjc; | |
2497 struct buddy *buddy = NULL; | |
2498 struct group *buddy_group = NULL; | |
3867 | 2499 const char *my_alias = NULL; |
2500 const char *my_group = NULL; | |
3770 | 2501 |
3105 | 2502 if(gc && gc->proto_data && ((struct jabber_data *)gc->proto_data)->gjc && name) { |
3311 | 2503 gaim_jid gjid; |
3105 | 2504 gjc = ((struct jabber_data *)gc->proto_data)->gjc; |
2505 | |
3311 | 2506 if((realwho = get_realwho(gjc, name, FALSE, &gjid)) == NULL) |
2507 return; | |
2508 | |
2509 /* FIXME: transport */ | |
2510 if(gjid->user == NULL) { | |
2511 g_free(realwho); | |
2512 gaim_jid_free(gjid); | |
2513 return; | |
3105 | 2514 } |
3311 | 2515 gaim_jid_free(gjid); |
3105 | 2516 |
2517 x = jutil_iqnew(JPACKET__SET, NS_ROSTER); | |
2518 y = xmlnode_insert_tag(xmlnode_get_tag(x, "query"), "item"); | |
2519 xmlnode_put_attrib(y, "jid", realwho); | |
2520 | |
4687 | 2521 buddy = gaim_find_buddy(gc->account, realwho); |
4349 | 2522 |
3349 | 2523 /* |
2524 * See if there's an explict (new?) alias for the buddy or we can pull | |
2525 * one out of current Gaim buddylist data for him. | |
2526 */ | |
2527 if(alias && alias[0] != '\0') { | |
2528 my_alias = alias; | |
4705 | 2529 } else if(buddy && buddy->alias) { |
4227 | 2530 my_alias = buddy->alias; |
3349 | 2531 } |
2532 | |
2533 /* If there's an alias for the buddy, it's not 0-length | |
3105 | 2534 * and it doesn't match his JID, add the "name" attribute. |
2535 */ | |
3349 | 2536 if(my_alias != NULL && my_alias[0] != '\0' && strcmp(realwho, my_alias)) |
3311 | 2537 { |
3642 | 2538 xmlnode_put_attrib(y, "name", my_alias); |
3105 | 2539 } |
2540 | |
2541 /* | |
3349 | 2542 * See if there's an explict (new?) group for the buddy or pull |
2543 * one out of current Gaim buddylist data for him. | |
3105 | 2544 */ |
3349 | 2545 if(group && group[0] != '\0') { |
2546 my_group = group; | |
4687 | 2547 } else if((buddy_group = gaim_find_buddys_group(buddy)) != NULL) { |
3349 | 2548 my_group = buddy_group->name; |
2549 } | |
2550 | |
2551 /* | |
2552 * Send what group the buddy's in along with the roster item. | |
2553 */ | |
2554 if(my_group != NULL && my_group[0] != '\0') { | |
2555 xmlnode z = xmlnode_insert_tag(y, "group"); | |
2556 xmlnode_insert_cdata(z, my_group, -1); | |
3105 | 2557 } |
2558 | |
2559 gjab_send(((struct jabber_data *)gc->proto_data)->gjc, x); | |
2560 | |
2561 xmlnode_free(x); | |
2562 g_free(realwho); | |
2563 } | |
2564 } | |
2565 | |
3136 | 2566 /* |
3349 | 2567 * Add/update buddy's alias on server |
2568 * | |
2569 * This is just a roster update using existing, local buddylist data | |
2570 */ | |
4269 | 2571 static void jabber_alias_buddy(struct gaim_connection *gc, const char *name, const char *alias) |
3349 | 2572 { |
4269 | 2573 jabber_roster_update(gc, name, alias, NULL); |
3349 | 2574 } |
2575 | |
2576 /* | |
3136 | 2577 * Change buddy's group on server roster |
2578 */ | |
3867 | 2579 static void jabber_group_change(struct gaim_connection *gc, const char *name, const char *old_group, const char *new_group) |
3136 | 2580 { |
3349 | 2581 if(old_group && new_group && strcmp(old_group, new_group)) |
2582 jabber_roster_update(gc, name, NULL, new_group); | |
2583 } | |
2584 | |
2585 /* | |
2586 * Group rename | |
2587 * | |
2588 * Jabber doesn't have "groups," per se. "Group" is simply a JID attribute. | |
2589 * So we iterate through the list of buddies that are in the group and change | |
2590 * the group attribute for each of them. | |
2591 */ | |
2592 static void jabber_rename_group(struct gaim_connection *gc, | |
3867 | 2593 const char *old_group, |
2594 const char *new_group, | |
3349 | 2595 GList *members) |
2596 { | |
2597 if(old_group && new_group && strcmp(old_group, new_group)) | |
2598 while(members) { | |
2599 jabber_group_change(gc, (char *)(members->data), old_group, new_group); | |
2600 members = members->next; | |
2601 } | |
3136 | 2602 } |
2603 | |
3466 | 2604 static void jabber_add_buddy(struct gaim_connection *gc, const char *name) |
2086 | 2605 { |
3136 | 2606 xmlnode x; |
2086 | 2607 char *realwho; |
2956 | 2608 gjconn gjc = ((struct jabber_data *)gc->proto_data)->gjc; |
3311 | 2609 gaim_jid gjid; |
2086 | 2610 |
2611 if (!((struct jabber_data *)gc->proto_data)->did_import) | |
2612 return; | |
2613 | |
3311 | 2614 /* |
2615 * If there's no name or the name is ourself | |
2616 */ | |
2617 if(!name || !strcmp(gc->username, name)) | |
2086 | 2618 return; |
2619 | |
3311 | 2620 if((realwho = get_realwho(gjc, name, FALSE, &gjid)) == NULL) { |
3427 | 2621 char *msg = g_strdup_printf(_("The user %s is an invalid Jabber I.D. and was " |
2622 "therefore not added."), name); | |
2623 do_error_dialog("Unable to add buddy.", _("Jabber Error"), GAIM_ERROR); | |
3311 | 2624 g_free(msg); |
2625 jabber_remove_gaim_buddy(gc, name); | |
2626 return; | |
2086 | 2627 } |
2628 | |
3311 | 2629 /* FIXME: transport */ |
2630 if(gjid->user == NULL) { | |
2631 g_free(realwho); | |
2632 gaim_jid_free(gjid); | |
2633 return; | |
2634 } | |
2635 gaim_jid_free(gjid); | |
2636 | |
2086 | 2637 x = xmlnode_new_tag("presence"); |
2638 xmlnode_put_attrib(x, "to", realwho); | |
2639 xmlnode_put_attrib(x, "type", "subscribe"); | |
2956 | 2640 gjab_send(((struct jabber_data *)gc->proto_data)->gjc, x); |
2641 xmlnode_free(x); | |
2086 | 2642 |
3349 | 2643 jabber_roster_update(gc, realwho, NULL, NULL); |
3105 | 2644 |
2086 | 2645 g_free(realwho); |
2646 } | |
2647 | |
2681
37d80035e77f
[gaim-migrate @ 2694]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2635
diff
changeset
|
2648 static void jabber_remove_buddy(struct gaim_connection *gc, char *name, char *group) |
2086 | 2649 { |
3048 | 2650 xmlnode x; |
2086 | 2651 char *realwho; |
2956 | 2652 gjconn gjc = ((struct jabber_data *)gc->proto_data)->gjc; |
2086 | 2653 |
3311 | 2654 if(!name || (realwho = get_realwho(gjc, name, FALSE, NULL)) == NULL) |
2086 | 2655 return; |
2656 | |
2956 | 2657 x = xmlnode_new_tag("presence"); |
2658 xmlnode_put_attrib(x, "to", realwho); | |
2659 xmlnode_put_attrib(x, "type", "unsubscribe"); | |
2660 gjab_send(((struct jabber_data *)gc->proto_data)->gjc, x); | |
2086 | 2661 g_free(realwho); |
2662 xmlnode_free(x); | |
2663 } | |
2664 | |
4916 | 2665 #if 0 /* Faceprint! Look here! */ |
3314 | 2666 /* |
2667 * Remove a buddy item from the roster entirely | |
2668 */ | |
2669 static void jabber_remove_buddy_roster_item(struct gaim_connection *gc, char *name) | |
2670 { | |
3340 | 2671 gjconn gjc = ((struct jabber_data *)gc->proto_data)->gjc; |
3314 | 2672 char *realwho; |
3340 | 2673 |
2674 if((realwho = get_realwho(gjc, name, FALSE, NULL)) != NULL) { | |
2675 xmlnode x = jutil_iqnew(JPACKET__SET, NS_ROSTER); | |
2676 xmlnode y = xmlnode_insert_tag(xmlnode_get_tag(x, "query"), "item"); | |
2677 xmlnode_put_attrib(y, "jid", realwho); | |
2678 xmlnode_put_attrib(y, "subscription", "remove"); | |
2679 gjab_send(((struct jabber_data *)gc->proto_data)->gjc, x); | |
2680 g_free(realwho); | |
2681 xmlnode_free(x); | |
2682 } | |
2683 } | |
4916 | 2684 #endif |
3340 | 2685 |
2686 /* | |
2687 * Unsubscribe a buddy from our presence | |
2688 */ | |
2689 static void jabber_unsubscribe_buddy_from_us(struct gaim_connection *gc, char *name) | |
2690 { | |
2691 gjconn gjc = ((struct jabber_data *)gc->proto_data)->gjc; | |
2692 char *realwho; | |
2693 | |
2694 if((realwho = get_realwho(gjc, name, FALSE, NULL)) != NULL) { | |
2695 xmlnode g = xmlnode_new_tag("presence"); | |
2696 xmlnode_put_attrib(g, "to", realwho); | |
2697 xmlnode_put_attrib(g, "type", "unsubscribed"); | |
2698 gjab_send(gjc, g); | |
2699 xmlnode_free(g); | |
2700 } | |
2701 } | |
2702 | |
2703 /* | |
2704 * Common code for setting ourselves invisible/visible to buddy | |
2705 */ | |
2706 static void jabber_invisible_to_buddy_common(struct gaim_connection *gc, char *name, gboolean invisible) | |
2707 { | |
3314 | 2708 gjconn gjc = ((struct jabber_data *)gc->proto_data)->gjc; |
3340 | 2709 char *realwho; |
2710 | |
2711 if((realwho = get_realwho(gjc, name, FALSE, NULL)) != NULL) { | |
5135 | 2712 struct jabber_buddy_data *jbd = jabber_find_buddy(gc, realwho, TRUE); |
3340 | 2713 xmlnode g = xmlnode_new_tag("presence"); |
2714 | |
2715 xmlnode_put_attrib(g, "to", realwho); | |
2716 | |
2717 if(invisible) | |
2718 xmlnode_put_attrib(g, "type", "invisible"); | |
2719 | |
2720 gjab_send(gjc, g); | |
2721 | |
2722 g_free(realwho); | |
2723 xmlnode_free(g); | |
2724 | |
2725 if(jbd) { | |
2726 if(invisible) { | |
2727 jbd->invisible |= JABBER_BUD_INVIS; | |
2728 } else { | |
2729 jbd->invisible &= ~JABBER_BUD_INVIS; | |
2730 } | |
2731 } | |
2732 } | |
2733 } | |
2734 | |
2735 /* | |
2736 * Make ourselves temporarily invisible to a buddy | |
2737 */ | |
2738 static void jabber_invisible_to_buddy(struct gaim_connection *gc, char *name) | |
2739 { | |
2740 jabber_invisible_to_buddy_common(gc, name, TRUE); | |
2741 } | |
2742 | |
2743 /* | |
2744 * Make ourselves visible to a buddy | |
2745 */ | |
2746 static void jabber_visible_to_buddy(struct gaim_connection *gc, char *name) | |
2747 { | |
2748 jabber_invisible_to_buddy_common(gc, name, FALSE); | |
2749 } | |
2750 | |
2751 /* | |
2752 * Function used by the g_hash_table_foreach() in invisible_to_all_buddies() to | |
2753 * actually set the status. | |
2754 * | |
2755 * key is unused | |
2756 * value is the pointer to the jabber_buddy_data struct | |
2757 * data is gboolean: TRUE (invisible) or FALSE (not invisible) | |
2758 */ | |
2759 static void set_invisible_to_buddy_status(gpointer key, gpointer val, gpointer data) { | |
2760 struct jabber_buddy_data *jbd = val; | |
2761 gboolean invisible = (gboolean) data; | |
2762 | |
2763 if(jbd) { | |
2764 if(invisible) { | |
2765 jbd->invisible = JABBER_SERV_INVIS | JABBER_BUD_INVIS; | |
2766 } else { | |
2767 /* | |
2768 * If we've asserted server-level invisibility, cancelling | |
2769 * it removes explicit buddy invisibility settings too. | |
2770 */ | |
2771 if(jbd->invisible & JABBER_SERV_INVIS) | |
2772 jbd->invisible = JABBER_NOT_INVIS; | |
2773 } | |
2774 } | |
2775 } | |
2776 | |
2777 /* | |
2778 * Show we've set ourselves invisible/visible to all buddies on the server | |
2779 * | |
2780 * Used when we set server-wide invisibility so that individual buddy menu | |
2781 * entries show the proper option. | |
2782 */ | |
2783 static void invisible_to_all_buddies(struct gaim_connection *gc, gboolean invisible) | |
2784 { | |
2785 struct jabber_data *jd = gc->proto_data; | |
2786 | |
2787 if(jd->buddies != NULL) | |
2788 g_hash_table_foreach(jd->buddies, set_invisible_to_buddy_status, (gpointer) invisible); | |
3314 | 2789 } |
2790 | |
4687 | 2791 static const char *jabber_list_icon(struct gaim_account *a, struct buddy *b) |
2086 | 2792 { |
4687 | 2793 return "jabber"; |
2794 } | |
4916 | 2795 |
2796 static void jabber_list_emblems(struct buddy *b, char **se, char **sw, char **nw, char **ne) | |
2797 { | |
5135 | 2798 struct jabber_buddy_data *jbd = jabber_find_buddy(b->account->gc, b->name, FALSE); |
2799 | |
2800 if(!GAIM_BUDDY_IS_ONLINE(b)) { | |
2801 if (jbd && jbd->error_msg) | |
4927 | 2802 *nw = "error"; |
5135 | 2803 |
2804 if(jbd && (jbd->subscription & JABBER_SUB_PENDING || | |
2805 !(jbd->subscription & JABBER_SUB_TO))) | |
2806 *se = "notauthorized"; | |
2807 else | |
2808 *se = "offline"; | |
2809 | |
4916 | 2810 } else { |
2811 switch (b->uc) { | |
2812 case UC_AWAY: | |
2813 *se = "away"; | |
2814 break; | |
2815 case UC_CHAT: | |
2816 *se = "chat"; | |
2817 break; | |
2818 case UC_XA: | |
2819 *se = "extendedaway"; | |
2820 break; | |
2821 case UC_DND: | |
2822 *se = "dnd"; | |
2823 break; | |
2824 case UC_ERROR: | |
2825 *se = "error"; | |
2826 break; | |
2827 } | |
2086 | 2828 } |
4916 | 2829 } |
2086 | 2830 |
2205
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
2831 static GList *jabber_chat_info(struct gaim_connection *gc) |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
2832 { |
2956 | 2833 gjconn gjc = ((struct jabber_data *)gc->proto_data)->gjc; |
2834 | |
2835 static char *confserv = NULL; /* this pointer must be persistent */ | |
2836 gchar *server; | |
2205
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
2837 |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
2838 GList *m = NULL; |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
2839 struct proto_chat_entry *pce; |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
2840 |
2956 | 2841 /* This is a scientific wild-ass guess... |
2842 * | |
2843 * If there are more than two "components" to the current server name, | |
2844 * lop-off the left-most component and replace with "conference." | |
2845 */ | |
2846 if(confserv != NULL) { | |
2847 g_free(confserv); /* dispose of the old value */ | |
2848 } | |
2849 | |
2850 if((server = g_strdup(gjc->user->server)) == NULL) { | |
2851 confserv = g_strdup(DEFAULT_GROUPCHAT); | |
2852 } else { | |
2853 gchar **splits, **index; | |
2854 gchar *tmp; | |
2855 int cnt = 0; | |
2856 | |
2857 | |
2858 index = splits = g_strsplit(server, ".", -1); /* split the connected server */ | |
2859 | |
2860 while(*(index++)) /* index to the end--counting the parts */ | |
2861 ++cnt; | |
2862 | |
2863 /* | |
2864 * If we've more than two parts, point to the second part. Else point | |
2865 * to the start. | |
2866 */ | |
2867 if(cnt > 2) { | |
2868 index -= cnt; | |
2869 } else { | |
2870 index = splits; | |
2871 } | |
2872 | |
2873 /* Put it together */ | |
2874 confserv = g_strjoin(".", "conference", (tmp = g_strjoinv(".", index)), NULL); | |
2875 | |
2876 g_free(server); /* we don't need this stuff no more */ | |
2877 g_free(tmp); | |
2878 g_strfreev(splits); | |
2879 } | |
2880 | |
2205
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
2881 pce = g_new0(struct proto_chat_entry, 1); |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
2882 pce->label = _("Room:"); |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
2883 m = g_list_append(m, pce); |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
2884 |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
2885 pce = g_new0(struct proto_chat_entry, 1); |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
2886 pce->label = _("Server:"); |
2956 | 2887 pce->def = confserv; |
2205
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
2888 m = g_list_append(m, pce); |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
2889 |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
2890 pce = g_new0(struct proto_chat_entry, 1); |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
2891 pce->label = _("Handle:"); |
2956 | 2892 pce->def = gjc->user->user; |
2205
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
2893 m = g_list_append(m, pce); |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
2894 |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
2895 return m; |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
2896 } |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
2897 |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
2898 static void jabber_join_chat(struct gaim_connection *gc, GList *data) |
2086 | 2899 { |
2900 xmlnode x; | |
2901 char *realwho; | |
2956 | 2902 gjconn gjc = ((struct jabber_data *)gc->proto_data)->gjc; |
2903 GSList *jcs = ((struct jabber_data *)gc->proto_data)->chats; | |
2086 | 2904 struct jabber_chat *jc; |
3311 | 2905 gaim_jid gjid; |
2086 | 2906 |
2205
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
2907 if (!data || !data->next || !data->next->next) |
2086 | 2908 return; |
2909 | |
3311 | 2910 realwho = create_valid_jid(data->data, data->next->data, data->next->next->data); |
2086 | 2911 debug_printf("%s\n", realwho); |
2912 | |
3311 | 2913 if((gjid = gaim_jid_new(realwho)) == NULL) { |
3427 | 2914 char *msg = g_strdup_printf("The Jabber I.D. %s is invalid.", realwho); |
2915 do_error_dialog(_("Unable to join chat"), msg, GAIM_ERROR); | |
3236 | 2916 g_free(msg); |
3311 | 2917 g_free(realwho); |
3236 | 2918 return; |
2919 } | |
2956 | 2920 |
3311 | 2921 if((jc = find_any_chat(gc, gjid)) != NULL) { |
2956 | 2922 switch(jc->state) { |
2923 case JCS_PENDING: | |
2924 debug_printf("attempt to re-join already pending Jabber chat! (ignoring)\n"); | |
2925 g_free(realwho); /* yuck! */ | |
3311 | 2926 gaim_jid_free(gjid); |
2956 | 2927 return; |
2928 case JCS_ACTIVE: | |
2929 debug_printf("attempt to re-join already active Jabber chat! (ignoring)\n"); | |
2930 g_free(realwho); /* yuck! */ | |
3311 | 2931 gaim_jid_free(gjid); |
2956 | 2932 return; |
2933 case JCS_CLOSED: | |
2934 debug_printf("rejoining previously closed Jabber chat\n"); | |
2935 break; | |
2936 default: | |
2937 debug_printf("found Jabber chat in unknown state! (ignoring)\n"); | |
2938 g_free(realwho); /* yuck! */ | |
3311 | 2939 gaim_jid_free(gjid); |
2956 | 2940 return; |
2941 } | |
2942 } else { | |
2943 debug_printf("joining completely new Jabber chat\n"); | |
2944 jc = g_new0(struct jabber_chat, 1); | |
3311 | 2945 jc->gjid = gjid; |
2956 | 2946 jc->gc = gc; |
2947 ((struct jabber_data *)gc->proto_data)->chats = g_slist_append(jcs, jc); | |
4687 | 2948 // add_buddy(gc->account, _("Chats"), realwho, realwho); |
2956 | 2949 } |
2950 | |
2951 jc->state = JCS_PENDING; | |
2952 | |
2086 | 2953 x = jutil_presnew(0, realwho, NULL); |
2956 | 2954 gjab_send(gjc, x); |
2086 | 2955 xmlnode_free(x); |
2956 g_free(realwho); | |
2957 } | |
2958 | |
3466 | 2959 static void jabber_chat_invite(struct gaim_connection *gc, int id, const char *message, const char *name) |
2086 | 2960 { |
2961 xmlnode x, y; | |
2962 struct jabber_data *jd = gc->proto_data; | |
2956 | 2963 gjconn gjc = jd->gjc; |
2205
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
2964 struct jabber_chat *jc = NULL; |
2086 | 2965 char *realwho, *subject; |
2966 | |
3311 | 2967 if(!name || (realwho = get_realwho(gjc, name, FALSE, NULL)) == NULL) |
2086 | 2968 return; |
2969 | |
2970 /* find which chat we're inviting to */ | |
2956 | 2971 if(jabber_find_chat_by_convo_id(gc, id, &jc) != 0) |
2086 | 2972 return; |
2973 | |
2974 x = xmlnode_new_tag("message"); | |
2975 xmlnode_put_attrib(x, "to", realwho); | |
3311 | 2976 |
2086 | 2977 g_free(realwho); |
2978 | |
2979 y = xmlnode_insert_tag(x, "x"); | |
2980 xmlnode_put_attrib(y, "xmlns", "jabber:x:conference"); | |
3311 | 2981 subject = g_strdup_printf("%s@%s", jc->gjid->user, jc->gjid->server); |
2086 | 2982 xmlnode_put_attrib(y, "jid", subject); |
2983 g_free(subject); | |
2984 | |
2985 if (message && strlen(message)) { | |
5093 | 2986 insert_message(x, message, FALSE); |
2086 | 2987 } |
2988 | |
2956 | 2989 gjab_send(((struct jabber_data *)gc->proto_data)->gjc, x); |
2086 | 2990 xmlnode_free(x); |
2991 } | |
2992 | |
2993 static void jabber_chat_leave(struct gaim_connection *gc, int id) | |
2994 { | |
2995 struct jabber_data *jd = gc->proto_data; | |
2956 | 2996 gjconn gjc = jd->gjc; |
2205
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
2997 struct jabber_chat *jc = NULL; |
3311 | 2998 char *chatname; |
2086 | 2999 xmlnode x; |
3000 | |
2956 | 3001 /* Find out which chat we're leaving */ |
3002 if(jabber_find_chat_by_convo_id(gc, id, &jc) != 0) | |
2086 | 3003 return; |
3004 | |
3311 | 3005 chatname = g_strdup_printf("%s@%s", jc->gjid->user, jc->gjid->server); |
3006 x = jutil_presnew(0, chatname, NULL); | |
3007 g_free(chatname); | |
2086 | 3008 xmlnode_put_attrib(x, "type", "unavailable"); |
2956 | 3009 gjab_send(gjc, x); |
2086 | 3010 xmlnode_free(x); |
3011 jc->b = NULL; | |
3012 } | |
3013 | |
2167
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2162
diff
changeset
|
3014 static int jabber_chat_send(struct gaim_connection *gc, int id, char *message) |
2086 | 3015 { |
3016 xmlnode x, y; | |
2205
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
3017 struct jabber_chat *jc = NULL; |
2086 | 3018 char *chatname; |
2956 | 3019 int retval = 0; |
3020 | |
3021 /* Find out which chat we're sending to */ | |
3022 if((retval = jabber_find_chat_by_convo_id(gc, id, &jc)) != 0) | |
3023 return(retval); | |
2086 | 3024 |
3025 x = xmlnode_new_tag("message"); | |
3311 | 3026 xmlnode_put_attrib(x, "from", jc->gjid->full); |
3027 chatname = g_strdup_printf("%s@%s", jc->gjid->user, jc->gjid->server); | |
2086 | 3028 xmlnode_put_attrib(x, "to", chatname); |
3029 g_free(chatname); | |
3030 xmlnode_put_attrib(x, "type", "groupchat"); | |
3031 | |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2278
diff
changeset
|
3032 if (message && strlen(message) > strlen("/topic ") && |
4793 | 3033 !g_ascii_strncasecmp(message, "/topic ", strlen("/topic "))) { |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2278
diff
changeset
|
3034 char buf[8192]; |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2278
diff
changeset
|
3035 y = xmlnode_insert_tag(x, "subject"); |
3642 | 3036 xmlnode_insert_cdata(y, message + strlen("/topic "), -1); |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2278
diff
changeset
|
3037 y = xmlnode_insert_tag(x, "body"); |
3642 | 3038 g_snprintf(buf, sizeof(buf), "/me has changed the subject to: %s", message + strlen("/topic")); |
2289
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2278
diff
changeset
|
3039 xmlnode_insert_cdata(y, buf, -1); |
38e156136896
[gaim-migrate @ 2299]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2278
diff
changeset
|
3040 } else if (message && strlen(message)) { |
5093 | 3041 insert_message(x, message, FALSE); |
2086 | 3042 } |
3043 | |
2956 | 3044 gjab_send(((struct jabber_data *)gc->proto_data)->gjc, x); |
2086 | 3045 xmlnode_free(x); |
2167
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2162
diff
changeset
|
3046 return 0; |
2086 | 3047 } |
3048 | |
3049 static void jabber_chat_whisper(struct gaim_connection *gc, int id, char *who, char *message) | |
3050 { | |
5093 | 3051 xmlnode x; |
2205
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
3052 struct jabber_chat *jc = NULL; |
2086 | 3053 char *chatname; |
3054 | |
2956 | 3055 /* Find out which chat we're whispering to */ |
3056 if(jabber_find_chat_by_convo_id(gc, id, &jc) != 0) | |
2086 | 3057 return; |
3058 | |
3059 x = xmlnode_new_tag("message"); | |
3311 | 3060 xmlnode_put_attrib(x, "from", jc->gjid->full); |
3061 chatname = g_strdup_printf("%s@%s/%s", jc->gjid->user, jc->gjid->server, who); | |
2086 | 3062 xmlnode_put_attrib(x, "to", chatname); |
3063 g_free(chatname); | |
3064 xmlnode_put_attrib(x, "type", "normal"); | |
3065 | |
3066 if (message && strlen(message)) { | |
5093 | 3067 insert_message(x, message, FALSE); |
2086 | 3068 } |
3069 | |
2956 | 3070 gjab_send(((struct jabber_data *)gc->proto_data)->gjc, x); |
2086 | 3071 xmlnode_free(x); |
3072 } | |
3073 | |
3074 static char *jabber_normalize(const char *s) | |
3075 { | |
3076 static char buf[BUF_LEN]; | |
3077 char *t, *u; | |
3078 int x = 0; | |
3079 | |
3080 g_return_val_if_fail((s != NULL), NULL); | |
3081 | |
2956 | 3082 /* Somebody called us with s == NULL once... */ |
3083 if(s == NULL) { | |
3084 return(NULL); | |
3085 } else { | |
4793 | 3086 u = t = g_utf8_strdown(s, -1); |
2956 | 3087 |
3088 while (*t && (x < BUF_LEN - 1)) { | |
3089 if (*t != ' ') | |
3090 buf[x++] = *t; | |
3091 t++; | |
3092 } | |
3093 buf[x] = '\0'; | |
3094 g_free(u); | |
3095 | |
3096 if (!strchr(buf, '@')) { | |
4927 | 3097 strcat(buf, "@" DEFAULT_SERVER); /* this isn't always right, but eh */ |
2956 | 3098 } else if ((u = strchr(strchr(buf, '@'), '/')) != NULL) { |
3099 *u = '\0'; | |
3100 } | |
3101 | |
3102 return buf; | |
2086 | 3103 } |
3104 } | |
3105 | |
3106 static void jabber_get_info(struct gaim_connection *gc, char *who) { | |
3107 xmlnode x; | |
3108 char *id; | |
2956 | 3109 char *realwho; |
2086 | 3110 struct jabber_data *jd = gc->proto_data; |
2956 | 3111 gjconn gjc = jd->gjc; |
2086 | 3112 |
3311 | 3113 if((realwho = get_realwho(gjc, who, TRUE, NULL)) == NULL) |
3114 return; | |
3115 | |
2086 | 3116 x = jutil_iqnew(JPACKET__GET, NS_VCARD); |
2956 | 3117 xmlnode_put_attrib(x, "to", realwho); |
3311 | 3118 |
2956 | 3119 g_free(realwho); |
3120 | |
3121 id = gjab_getid(gjc); | |
2086 | 3122 xmlnode_put_attrib(x, "id", id); |
3123 | |
2956 | 3124 g_hash_table_insert(jd->gjc->queries, g_strdup(id), g_strdup("vCard")); |
3125 | |
3126 gjab_send(gjc, x); | |
2086 | 3127 |
3128 xmlnode_free(x); | |
3311 | 3129 } |
3130 | |
3131 static void jabber_get_error_msg(struct gaim_connection *gc, char *who) { | |
3132 struct jabber_data *jd = gc->proto_data; | |
3133 gjconn gjc = jd->gjc; | |
3134 gchar **str_arr = (gchar **) g_new(gpointer, 3); | |
3135 gchar **ap = str_arr; | |
3136 gchar *realwho, *final; | |
3137 struct jabber_buddy_data *jbd; | |
3138 | |
3139 if((realwho = get_realwho(gjc, who, FALSE, NULL)) == NULL) { | |
3140 g_strfreev(str_arr); | |
3141 return; | |
3142 } | |
3143 | |
5135 | 3144 jbd = jabber_find_buddy(gc, realwho, TRUE); |
3311 | 3145 |
3146 *ap++ = g_strdup_printf("<B>Jabber ID:</B> %s<BR>\n", realwho); | |
3147 *ap++ = g_strdup_printf("<B>Error:</B> %s<BR>\n", jbd->error_msg); | |
3148 *ap = NULL; | |
3770 | 3149 |
3311 | 3150 final= g_strjoinv(NULL, str_arr); |
3770 | 3151 |
3311 | 3152 g_strfreev(str_arr); |
3153 | |
3154 g_show_info_text(gc, realwho, 2, final, NULL); | |
3155 g_free(realwho); | |
3156 g_free(final); | |
2086 | 3157 } |
3158 | |
2956 | 3159 static void jabber_get_away_msg(struct gaim_connection *gc, char *who) { |
3160 struct jabber_data *jd = gc->proto_data; | |
3161 gjconn gjc = jd->gjc; | |
3311 | 3162 int num_resources; |
3163 gaim_jid gjid; | |
3164 char *buddy = get_realwho(gjc, who, FALSE, &gjid); | |
5135 | 3165 struct jabber_buddy_data *jbd = jabber_find_buddy(gc, buddy, TRUE); |
3311 | 3166 gchar **str_arr; |
3167 gchar **ap; | |
3168 gchar *realwho, *final; | |
3169 GSList *resources; | |
3170 int i; | |
3171 | |
3172 if(!buddy) | |
3173 return; | |
3174 | |
3175 if(!gjid->resource) { | |
3176 num_resources = g_slist_length(jbd->resources); | |
3177 resources = jbd->resources; | |
3178 } else { | |
3179 num_resources = 1; | |
3180 resources = jbd->resources; | |
3181 while(strcasecmp(((jab_res_info)resources->data)->name, gjid->resource)) | |
3182 resources = resources->next; | |
3183 } | |
3184 | |
3185 gaim_jid_free(gjid); | |
2956 | 3186 |
3187 /* space for all elements: Jabber I.D. + "status" + NULL (list terminator) */ | |
3311 | 3188 str_arr = (gchar **) g_new(gpointer, num_resources*2 + 1); |
3189 ap = str_arr; | |
3190 | |
3191 for(i=0; i<num_resources; i++) | |
3192 { | |
3193 jab_res_info jri = resources->data; | |
4450 | 3194 char *status; |
3311 | 3195 realwho = g_strdup_printf("%s/%s", buddy, jri->name); |
4450 | 3196 status = strdup_withhtml(jabber_lookup_away(gjc, realwho)); |
3311 | 3197 *ap++ = g_strdup_printf("<B>Jabber ID:</B> %s<BR>\n", realwho); |
4745 | 3198 *ap++ = g_strdup_printf("<B>Status:</B> %s%s%s<BR>\n", jabber_get_state_string(jri->state), status ? ": " : "", status ? status : ""); |
4450 | 3199 g_free(status); |
3311 | 3200 g_free(realwho); |
3201 resources = resources->next; | |
2956 | 3202 } |
3203 | |
3204 *ap = NULL; | |
3770 | 3205 |
3311 | 3206 g_free(buddy); |
2956 | 3207 |
3208 final= g_strjoinv(NULL, str_arr); | |
3209 g_strfreev(str_arr); | |
3210 | |
3311 | 3211 g_show_info_text(gc, who, 2, final, NULL); |
2956 | 3212 g_free(final); |
3770 | 3213 |
2956 | 3214 } |
3215 | |
3216 static void jabber_get_cb_info(struct gaim_connection *gc, int cid, char *who) { | |
3217 struct jabber_chat *jc = NULL; | |
3218 char *realwho; | |
3219 | |
3220 /* Find out which chat */ | |
3221 if(jabber_find_chat_by_convo_id(gc, cid, &jc) != 0) | |
3222 return; | |
3223 | |
3311 | 3224 realwho = g_strdup_printf("%s@%s/%s", jc->gjid->user, jc->gjid->server, who); |
2956 | 3225 |
3226 jabber_get_info(gc, realwho); | |
3227 g_free(realwho); | |
3228 } | |
3229 | |
3230 static void jabber_get_cb_away_msg(struct gaim_connection *gc, int cid, char *who) { | |
3231 struct jabber_chat *jc = NULL; | |
3232 char *realwho; | |
3233 | |
3234 /* Find out which chat */ | |
3235 if(jabber_find_chat_by_convo_id(gc, cid, &jc) != 0) | |
3236 return; | |
3237 | |
3311 | 3238 realwho = g_strdup_printf("%s@%s/%s", jc->gjid->user, jc->gjid->server, who); |
2956 | 3239 |
3240 jabber_get_away_msg(gc, realwho); | |
3241 g_free(realwho); | |
3242 | |
3243 } | |
3244 | |
4744 | 3245 static char *jabber_tooltip_text(struct buddy *b) |
3246 { | |
5135 | 3247 struct jabber_buddy_data *jbd = jabber_find_buddy(b->account->gc, b->name, FALSE); |
4745 | 3248 jab_res_info jri = jabber_find_resource(b->account->gc, b->name); |
5135 | 3249 char *ret = NULL; |
4745 | 3250 if(jri) { |
4777 | 3251 char *stripped = strip_html(jabber_lookup_away(GC_GJ(b->account->gc), |
4745 | 3252 b->name)); |
4777 | 3253 char *text = NULL; |
3254 if(stripped) | |
3255 text = g_markup_escape_text(stripped, strlen(stripped)); | |
3256 ret = g_strdup_printf(_("<b>Status:</b> %s%s%s"), | |
4745 | 3257 jabber_get_state_string(jri->state), text ? ": " : "", |
3258 text ? text : ""); | |
3259 | |
4777 | 3260 if(stripped) { |
3261 g_free(stripped); | |
4745 | 3262 g_free(text); |
4777 | 3263 } |
5135 | 3264 } else if(jbd && (jbd->subscription & JABBER_SUB_PENDING || |
3265 !(jbd->subscription & JABBER_SUB_TO))) { | |
3266 ret = g_strdup(_("<b>Status:</b> Not Authorized")); | |
4745 | 3267 } |
5135 | 3268 return ret; |
4744 | 3269 } |
3270 | |
4732 | 3271 static char *jabber_status_text(struct buddy *b) |
3272 { | |
5135 | 3273 struct jabber_buddy_data *jbd = jabber_find_buddy(b->account->gc, b->name, FALSE); |
3274 char *ret = NULL; | |
4732 | 3275 if (b->uc & UC_UNAVAILABLE) { |
4777 | 3276 char *stripped = strip_html(jabber_lookup_away(GC_GJ(b->account->gc), |
4745 | 3277 b->name)); |
4777 | 3278 if(!stripped) { |
4745 | 3279 jab_res_info jri = jabber_find_resource(b->account->gc, b->name); |
3280 if(jri) | |
4777 | 3281 stripped = g_strdup(jabber_get_state_string(jri->state)); |
4745 | 3282 } |
4777 | 3283 ret = g_markup_escape_text(stripped, strlen(stripped)); |
3284 g_free(stripped); | |
5135 | 3285 } else if(jbd && (jbd->subscription & JABBER_SUB_PENDING || |
3286 !(jbd->subscription & JABBER_SUB_TO))) { | |
3287 ret = g_strdup(_("Not Authorized")); | |
4732 | 3288 } |
5135 | 3289 return ret; |
4732 | 3290 } |
3291 | |
2170
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
3292 static GList *jabber_buddy_menu(struct gaim_connection *gc, char *who) { |
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
3293 GList *m = NULL; |
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
3294 struct proto_buddy_menu *pbm; |
4687 | 3295 struct buddy *b = gaim_find_buddy(gc->account, who); |
3311 | 3296 |
3297 if(b->uc == UC_ERROR) | |
3298 { | |
3299 pbm = g_new0(struct proto_buddy_menu, 1); | |
3300 pbm->label = _("View Error Msg"); | |
3301 pbm->callback = jabber_get_error_msg; | |
3302 pbm->gc = gc; | |
3303 m = g_list_append(m, pbm); | |
3304 } else { | |
3340 | 3305 gjconn gjc = ((struct jabber_data *)gc->proto_data)->gjc; |
3306 char *realwho = get_realwho(gjc, who, FALSE, NULL); | |
5135 | 3307 struct jabber_buddy_data *jbd = jabber_find_buddy(gc, realwho, FALSE); |
3340 | 3308 |
3309 g_free(realwho); | |
3310 | |
3311 | 3311 pbm = g_new0(struct proto_buddy_menu, 1); |
3312 pbm->label = _("Get Away Msg"); | |
3313 pbm->callback = jabber_get_away_msg; | |
3314 pbm->gc = gc; | |
3315 m = g_list_append(m, pbm); | |
3340 | 3316 |
3317 pbm = g_new0(struct proto_buddy_menu, 1); | |
3318 if(jbd && (jbd->invisible & JABBER_BUD_INVIS)) { | |
3319 pbm->label = _("Un-hide From"); | |
3320 pbm->callback = jabber_visible_to_buddy; | |
3321 } else { | |
3322 pbm->label = _("Temporarily Hide From"); | |
3323 pbm->callback = jabber_invisible_to_buddy; | |
3324 } | |
4916 | 3325 |
3326 pbm->gc = gc; | |
3327 m = g_list_append(m, pbm); | |
3328 pbm = g_new0(struct proto_buddy_menu, 1); | |
3329 pbm->label = _("Cancel Presence Notification"); | |
3330 pbm->callback = jabber_unsubscribe_buddy_from_us; | |
3340 | 3331 pbm->gc = gc; |
3332 m = g_list_append(m, pbm); | |
3311 | 3333 } |
2170
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
3334 |
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
3335 return m; |
2086 | 3336 } |
3337 | |
2501
227cc42ffa6e
[gaim-migrate @ 2514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2382
diff
changeset
|
3338 static GList *jabber_away_states(struct gaim_connection *gc) { |
2086 | 3339 GList *m = NULL; |
3340 | |
4982 | 3341 m = g_list_append(m, _("Online")); |
3342 m = g_list_append(m, _("Chatty")); | |
3343 m = g_list_append(m, _("Away")); | |
3344 m = g_list_append(m, _("Extended Away")); | |
3345 m = g_list_append(m, _("Do Not Disturb")); | |
3346 m = g_list_append(m, _("Invisible")); | |
4110 | 3347 m = g_list_append(m, GAIM_AWAY_CUSTOM); |
2086 | 3348 |
3349 return m; | |
3350 } | |
3351 | |
3352 static void jabber_set_away(struct gaim_connection *gc, char *state, char *message) | |
3353 { | |
3354 xmlnode x, y; | |
3355 struct jabber_data *jd = gc->proto_data; | |
2956 | 3356 gjconn gjc = jd->gjc; |
3311 | 3357 GSList *jcs; |
3358 struct jabber_chat *jc; | |
3359 char *chatname; | |
3340 | 3360 gboolean invisible = FALSE; |
2086 | 3361 |
4111
ee884f1d7ae3
[gaim-migrate @ 4326]
Christian Hammond <chipx86@chipx86.com>
parents:
4110
diff
changeset
|
3362 if (gc->away) { |
ee884f1d7ae3
[gaim-migrate @ 4326]
Christian Hammond <chipx86@chipx86.com>
parents:
4110
diff
changeset
|
3363 g_free(gc->away); |
ee884f1d7ae3
[gaim-migrate @ 4326]
Christian Hammond <chipx86@chipx86.com>
parents:
4110
diff
changeset
|
3364 gc->away = NULL; |
ee884f1d7ae3
[gaim-migrate @ 4326]
Christian Hammond <chipx86@chipx86.com>
parents:
4110
diff
changeset
|
3365 } |
2086 | 3366 |
3367 x = xmlnode_new_tag("presence"); | |
3368 | |
3369 if (!strcmp(state, GAIM_AWAY_CUSTOM)) { | |
3370 /* oh goody. Gaim is telling us what to do. */ | |
3371 if (message) { | |
3372 /* Gaim wants us to be away */ | |
3373 y = xmlnode_insert_tag(x, "show"); | |
3374 xmlnode_insert_cdata(y, "away", -1); | |
3375 y = xmlnode_insert_tag(x, "status"); | |
3376 xmlnode_insert_cdata(y, message, -1); | |
4111
ee884f1d7ae3
[gaim-migrate @ 4326]
Christian Hammond <chipx86@chipx86.com>
parents:
4110
diff
changeset
|
3377 gc->away = g_strdup(message); |
2086 | 3378 } else { |
3379 /* Gaim wants us to not be away */ | |
3380 /* but for Jabber, we can just send presence with no other information. */ | |
3381 } | |
3382 } else { | |
3383 /* state is one of our own strings. it won't be NULL. */ | |
4982 | 3384 if (!strcmp(state, _("Online"))) { |
2086 | 3385 /* once again, we don't have to put anything here */ |
4982 | 3386 } else if (!strcmp(state, _("Chatty"))) { |
2086 | 3387 y = xmlnode_insert_tag(x, "show"); |
3388 xmlnode_insert_cdata(y, "chat", -1); | |
4111
ee884f1d7ae3
[gaim-migrate @ 4326]
Christian Hammond <chipx86@chipx86.com>
parents:
4110
diff
changeset
|
3389 gc->away = g_strdup(""); |
4982 | 3390 } else if (!strcmp(state, _("Away"))) { |
2086 | 3391 y = xmlnode_insert_tag(x, "show"); |
3392 xmlnode_insert_cdata(y, "away", -1); | |
4111
ee884f1d7ae3
[gaim-migrate @ 4326]
Christian Hammond <chipx86@chipx86.com>
parents:
4110
diff
changeset
|
3393 gc->away = g_strdup(""); |
4982 | 3394 } else if (!strcmp(state, _("Extended Away"))) { |
2086 | 3395 y = xmlnode_insert_tag(x, "show"); |
3396 xmlnode_insert_cdata(y, "xa", -1); | |
4111
ee884f1d7ae3
[gaim-migrate @ 4326]
Christian Hammond <chipx86@chipx86.com>
parents:
4110
diff
changeset
|
3397 gc->away = g_strdup(""); |
4982 | 3398 } else if (!strcmp(state, _("Do Not Disturb"))) { |
2086 | 3399 y = xmlnode_insert_tag(x, "show"); |
3400 xmlnode_insert_cdata(y, "dnd", -1); | |
4111
ee884f1d7ae3
[gaim-migrate @ 4326]
Christian Hammond <chipx86@chipx86.com>
parents:
4110
diff
changeset
|
3401 gc->away = g_strdup(""); |
4982 | 3402 } else if (!strcmp(state, _("Invisible"))) { |
3340 | 3403 xmlnode_put_attrib(x, "type", "invisible"); |
4111
ee884f1d7ae3
[gaim-migrate @ 4326]
Christian Hammond <chipx86@chipx86.com>
parents:
4110
diff
changeset
|
3404 gc->away = g_strdup(""); |
3340 | 3405 invisible = TRUE; |
2086 | 3406 } |
3407 } | |
3408 | |
3311 | 3409 gjab_send(gjc, x); /* Notify "individuals" */ |
3410 | |
3411 /* | |
3412 * As of jabberd-1.4.2: simply sending presence to the server doesn't result in | |
3413 * it being propagated to conference rooms. So we wade thru the list of chats, | |
3414 * sending our new presence status to each and every one. | |
3415 */ | |
3416 for(jcs = jd->chats; jcs; jcs = jcs->next) { | |
3417 jc = jcs->data; | |
3418 if(jc->state == JCS_ACTIVE) { | |
3419 xmlnode_put_attrib(x, "from", jc->gjid->full); | |
3420 chatname = g_strdup_printf("%s@%s", jc->gjid->user, jc->gjid->server); | |
3421 xmlnode_put_attrib(x, "to", chatname); | |
3422 gjab_send(gjc, x); | |
3423 g_free(chatname); | |
3424 } | |
3425 } | |
3426 | |
2086 | 3427 xmlnode_free(x); |
3340 | 3428 |
3429 invisible_to_all_buddies(gc, invisible); | |
2086 | 3430 } |
3431 | |
3432 static void jabber_set_idle(struct gaim_connection *gc, int idle) { | |
3433 struct jabber_data *jd = (struct jabber_data *)gc->proto_data; | |
3434 debug_printf("jabber_set_idle: setting idle %i\n", idle); | |
3770 | 3435 jd->idle = idle ? time(NULL) - idle : idle; |
2086 | 3436 } |
3437 | |
3438 static void jabber_keepalive(struct gaim_connection *gc) { | |
3439 struct jabber_data *jd = (struct jabber_data *)gc->proto_data; | |
4450 | 3440 gjab_send_raw(jd->gjc, JABBER_KEEPALIVE_STRING); |
2086 | 3441 } |
3442 | |
2956 | 3443 /*---------------------------------------*/ |
3444 /* Jabber "set info" (vCard) support */ | |
3445 /*---------------------------------------*/ | |
3446 | |
3447 /* | |
3448 * V-Card format: | |
3449 * | |
3450 * <vCard prodid='' version='' xmlns=''> | |
3451 * <FN></FN> | |
3452 * <N> | |
3453 * <FAMILY/> | |
3454 * <GIVEN/> | |
3455 * </N> | |
3456 * <NICKNAME/> | |
3457 * <URL/> | |
3458 * <ADR> | |
3459 * <STREET/> | |
3460 * <EXTADD/> | |
3461 * <LOCALITY/> | |
3462 * <REGION/> | |
3463 * <PCODE/> | |
3464 * <COUNTRY/> | |
3465 * </ADR> | |
3466 * <TEL/> | |
3467 * <EMAIL/> | |
3468 * <ORG> | |
3469 * <ORGNAME/> | |
3470 * <ORGUNIT/> | |
3471 * </ORG> | |
3472 * <TITLE/> | |
3473 * <ROLE/> | |
3474 * <DESC/> | |
3475 * <BDAY/> | |
3476 * </vCard> | |
3477 * | |
3478 * See also: | |
3479 * | |
3480 * http://docs.jabber.org/proto/html/vcard-temp.html | |
3481 * http://www.vcard-xml.org/dtd/vCard-XML-v2-20010520.dtd | |
3482 */ | |
3483 | |
3484 /* | |
3485 * Cross-reference user-friendly V-Card entry labels to vCard XML tags | |
3486 * and attributes. | |
3487 * | |
3488 * Order is (or should be) unimportant. For example: we have no way of | |
3489 * knowing in what order real data will arrive. | |
3490 * | |
3491 * Format: Label, Pre-set text, "visible" flag, "editable" flag, XML tag | |
3492 * name, XML tag's parent tag "path" (relative to vCard node). | |
3493 * | |
3494 * List is terminated by a NULL label pointer. | |
3495 * | |
3496 * Entries with no label text, but with XML tag and parent tag | |
3497 * entries, are used by V-Card XML construction routines to | |
3498 * "automagically" construct the appropriate XML node tree. | |
3499 * | |
3500 * Thoughts on future direction/expansion | |
3501 * | |
3502 * This is a "simple" vCard. | |
3503 * | |
3504 * It is possible for nodes other than the "vCard" node to have | |
3505 * attributes. Should that prove necessary/desirable, add an | |
3506 * "attributes" pointer to the vcard_template struct, create the | |
3507 * necessary tag_attr structs, and add 'em to the vcard_dflt_data | |
3508 * array. | |
3509 * | |
3510 * The above changes will (obviously) require changes to the vCard | |
3511 * construction routines. | |
3512 */ | |
3513 | |
3514 struct vcard_template { | |
3515 char *label; /* label text pointer */ | |
3516 char *text; /* entry text pointer */ | |
3517 int visible; /* should entry field be "visible?" */ | |
3518 int editable; /* should entry field be editable? */ | |
3519 char *tag; /* tag text */ | |
3520 char *ptag; /* parent tag "path" text */ | |
3521 char *url; /* vCard display format if URL */ | |
3522 } vcard_template_data[] = { | |
2975 | 3523 {N_("Full Name"), NULL, TRUE, TRUE, "FN", NULL, NULL}, |
3524 {N_("Family Name"), NULL, TRUE, TRUE, "FAMILY", "N", NULL}, | |
3525 {N_("Given Name"), NULL, TRUE, TRUE, "GIVEN", "N", NULL}, | |
3526 {N_("Nickname"), NULL, TRUE, TRUE, "NICKNAME", NULL, NULL}, | |
3527 {N_("URL"), NULL, TRUE, TRUE, "URL", NULL, "<A HREF=\"%s\">%s</A>"}, | |
3528 {N_("Street Address"), NULL, TRUE, TRUE, "STREET", "ADR", NULL}, | |
3529 {N_("Extended Address"), NULL, TRUE, TRUE, "EXTADD", "ADR", NULL}, | |
3530 {N_("Locality"), NULL, TRUE, TRUE, "LOCALITY", "ADR", NULL}, | |
3531 {N_("Region"), NULL, TRUE, TRUE, "REGION", "ADR", NULL}, | |
3532 {N_("Postal Code"), NULL, TRUE, TRUE, "PCODE", "ADR", NULL}, | |
3533 {N_("Country"), NULL, TRUE, TRUE, "COUNTRY", "ADR", NULL}, | |
3534 {N_("Telephone"), NULL, TRUE, TRUE, "TELEPHONE", NULL, NULL}, | |
3535 {N_("Email"), NULL, TRUE, TRUE, "EMAIL", NULL, "<A HREF=\"mailto:%s\">%s</A>"}, | |
3536 {N_("Organization Name"), NULL, TRUE, TRUE, "ORGNAME", "ORG", NULL}, | |
3537 {N_("Organization Unit"), NULL, TRUE, TRUE, "ORGUNIT", "ORG", NULL}, | |
3538 {N_("Title"), NULL, TRUE, TRUE, "TITLE", NULL, NULL}, | |
3539 {N_("Role"), NULL, TRUE, TRUE, "ROLE", NULL, NULL}, | |
3540 {N_("Birthday"), NULL, TRUE, TRUE, "BDAY", NULL, NULL}, | |
3541 {N_("Description"), NULL, TRUE, TRUE, "DESC", NULL, NULL}, | |
2956 | 3542 {"", NULL, TRUE, TRUE, "N", NULL, NULL}, |
3543 {"", NULL, TRUE, TRUE, "ADR", NULL, NULL}, | |
3544 {"", NULL, TRUE, TRUE, "ORG", NULL, NULL}, | |
3545 {NULL, NULL, 0, 0, NULL, NULL, NULL} | |
3546 }; | |
3547 | |
3548 /* | |
3549 * The "vCard" tag's attibute list... | |
3550 */ | |
3551 struct tag_attr { | |
3552 char *attr; | |
3553 char *value; | |
3554 } vcard_tag_attr_list[] = { | |
3555 {"prodid", "-//HandGen//NONSGML vGen v1.0//EN"}, | |
3556 {"version", "2.0", }, | |
3557 {"xmlns", "vcard-temp", }, | |
3558 {NULL, NULL}, | |
3559 }; | |
3560 | |
3561 | |
3562 /* | |
3563 * V-Card user instructions | |
3564 */ | |
3565 static char *multi_entry_instructions = | |
2975 | 3566 N_("All items below are optional. Enter only the information with which you feel comfortable"); |
3567 static char *entries_title = N_("User Identity"); | |
2956 | 3568 |
3569 /* | |
3570 * Used by routines to parse an XML-encoded string into an xmlnode tree | |
3571 */ | |
3572 typedef struct { | |
3573 XML_Parser parser; | |
3574 xmlnode current; | |
3575 } *xmlstr2xmlnode_parser, xmlstr2xmlnode_parser_struct; | |
3576 | |
3577 | |
3578 /* | |
3579 * Display a Jabber vCard | |
3580 */ | |
3581 static void jabber_handlevcard(gjconn gjc, xmlnode querynode, char *from) | |
3582 { | |
3583 struct gaim_connection *gc = GJ_GC(gjc); | |
3584 char *cdata, *status; | |
3585 struct vcard_template *vc_tp = vcard_template_data; | |
3586 | |
3587 /* space for all vCard elements + Jabber I.D. + "status" + NULL (list terminator) */ | |
3588 gchar **str_arr = (gchar **) g_new(gpointer, | |
3589 (sizeof(vcard_template_data)/sizeof(struct vcard_template)) + 3); | |
3590 gchar **ap = str_arr; | |
3591 gchar *buddy, *final; | |
3592 | |
4745 | 3593 jab_res_info jri; |
3594 | |
3311 | 3595 if((buddy = get_realwho(gjc, from, TRUE, NULL)) == NULL) { |
3596 g_strfreev(str_arr); | |
3597 return; | |
2956 | 3598 } |
3311 | 3599 |
4745 | 3600 jri = jabber_find_resource(GJ_GC(gjc), buddy); |
3601 | |
2956 | 3602 *ap++ = g_strdup_printf("<B>Jabber ID:</B> %s<BR>\n", buddy); |
3603 | |
3604 for(vc_tp = vcard_template_data; vc_tp->label != NULL; ++vc_tp) { | |
3605 if(strcmp(vc_tp->tag, "DESC") == 0) | |
3606 continue; /* special handling later */ | |
3607 if(vc_tp->ptag == NULL) { | |
3608 cdata = xmlnode_get_tag_data(querynode, vc_tp->tag); | |
3609 } else { | |
3610 gchar *tag = g_strdup_printf("%s/%s", vc_tp->ptag, vc_tp->tag); | |
3611 cdata = xmlnode_get_tag_data(querynode, tag); | |
3612 g_free(tag); | |
3613 } | |
3614 if(cdata != NULL) { | |
3615 if(vc_tp->url == NULL) { | |
3616 *ap++ = g_strdup_printf("<B>%s:</B> %s<BR>\n", vc_tp->label, cdata); | |
3617 } else { | |
3618 gchar *fmt = g_strdup_printf("<B>%%s:</B> %s<BR>\n", vc_tp->url); | |
3619 *ap++ = g_strdup_printf(fmt, vc_tp->label, cdata, cdata); | |
3620 g_free(fmt); | |
3621 } | |
3622 } | |
3623 } | |
3624 | |
4745 | 3625 |
4450 | 3626 status = strdup_withhtml(jabber_lookup_away(gjc, buddy)); |
4745 | 3627 *ap++ = g_strdup_printf("<B>Status:</B> %s%s%s<BR>\n", |
3628 jri ? jabber_get_state_string(jri->state) : "", | |
3629 jri && status ? ": " : "", status ? status : ""); | |
4450 | 3630 g_free(status); |
2956 | 3631 |
3632 /* | |
3633 * "Description" handled as a special case: get a copy of the | |
3634 * string and HTML-ize. | |
3635 */ | |
3636 if((cdata = xmlnode_get_tag_data(querynode, "DESC")) != NULL) { | |
3637 gchar *tmp = g_strdup_printf("<HR>%s<BR>", cdata); | |
3638 *ap++ = strdup_withhtml(tmp); | |
3639 g_free(tmp); | |
3640 } | |
3641 | |
3642 *ap = NULL; | |
3643 | |
3644 final= g_strjoinv(NULL, str_arr); | |
3645 g_strfreev(str_arr); | |
3646 | |
3647 g_show_info_text(gc, buddy, 2, final, NULL); | |
3648 g_free(buddy); | |
3649 g_free(final); | |
3650 } | |
3651 | |
3652 /* | |
3653 * Used by XML_Parse on parsing CDATA | |
3654 */ | |
3655 static void xmlstr2xmlnode_charData(void *userdata, const char *s, int slen) | |
3656 { | |
3657 xmlstr2xmlnode_parser xmlp = (xmlstr2xmlnode_parser) userdata; | |
3658 | |
3659 if (xmlp->current) | |
3660 xmlnode_insert_cdata(xmlp->current, s, slen); | |
3661 } | |
3662 | |
3663 /* | |
3664 * Used by XML_Parse to start or append to an xmlnode | |
3665 */ | |
3666 static void xmlstr2xmlnode_startElement(void *userdata, const char *name, const char **attribs) | |
3667 { | |
3668 xmlnode x; | |
3669 xmlstr2xmlnode_parser xmlp = (xmlstr2xmlnode_parser) userdata; | |
3670 | |
3671 if (xmlp->current) { | |
3672 /* Append the node to the current one */ | |
3673 x = xmlnode_insert_tag(xmlp->current, name); | |
3674 xmlnode_put_expat_attribs(x, attribs); | |
3675 | |
3676 xmlp->current = x; | |
3677 } else { | |
3678 x = xmlnode_new_tag(name); | |
3679 xmlnode_put_expat_attribs(x, attribs); | |
3680 xmlp->current = x; | |
3681 } | |
3682 } | |
3683 | |
3684 /* | |
3685 * Used by XML_Parse to end an xmlnode | |
3686 */ | |
3687 static void xmlstr2xmlnode_endElement(void *userdata, const char *name) | |
3688 { | |
3689 xmlstr2xmlnode_parser xmlp = (xmlstr2xmlnode_parser) userdata; | |
3690 xmlnode x; | |
3691 | |
3692 if (xmlp->current != NULL && (x = xmlnode_get_parent(xmlp->current)) != NULL) { | |
3693 xmlp->current = x; | |
3694 } | |
3695 } | |
3696 | |
3697 /* | |
3698 * Parse an XML-encoded string into an xmlnode tree | |
3699 * | |
3700 * Caller is responsible for freeing the returned xmlnode | |
3701 */ | |
3702 static xmlnode xmlstr2xmlnode(char *xmlstring) | |
3703 { | |
3704 xmlstr2xmlnode_parser my_parser = g_new(xmlstr2xmlnode_parser_struct, 1); | |
3705 xmlnode x = NULL; | |
3706 | |
3707 my_parser->parser = XML_ParserCreate(NULL); | |
3708 my_parser->current = NULL; | |
3709 | |
3710 XML_SetUserData(my_parser->parser, (void *)my_parser); | |
3711 XML_SetElementHandler(my_parser->parser, xmlstr2xmlnode_startElement, xmlstr2xmlnode_endElement); | |
3712 XML_SetCharacterDataHandler(my_parser->parser, xmlstr2xmlnode_charData); | |
3713 XML_Parse(my_parser->parser, xmlstring, strlen(xmlstring), 0); | |
3714 | |
3715 x = my_parser->current; | |
3716 | |
3717 XML_ParserFree(my_parser->parser); | |
3718 g_free(my_parser); | |
3719 | |
3720 return(x); | |
3721 } | |
3722 | |
3723 /* | |
3724 * Insert a tag node into an xmlnode tree, recursively inserting parent tag | |
3725 * nodes as necessary | |
3726 * | |
3727 * Returns pointer to inserted node | |
3728 * | |
3729 * Note to hackers: this code is designed to be re-entrant (it's recursive--it | |
3730 * calls itself), so don't put any "static"s in here! | |
3731 */ | |
3732 static xmlnode insert_tag_to_parent_tag(xmlnode start, const char *parent_tag, const char *new_tag) | |
3733 { | |
3734 xmlnode x = NULL; | |
3735 | |
3736 /* | |
3737 * If the parent tag wasn't specified, see if we can get it | |
3738 * from the vCard template struct. | |
3739 */ | |
3740 if(parent_tag == NULL) { | |
3741 struct vcard_template *vc_tp = vcard_template_data; | |
3742 | |
3743 while(vc_tp->label != NULL) { | |
3744 if(strcmp(vc_tp->tag, new_tag) == 0) { | |
3745 parent_tag = vc_tp->ptag; | |
3746 break; | |
3747 } | |
3748 ++vc_tp; | |
3749 } | |
3750 } | |
3751 | |
3752 /* | |
3753 * If we have a parent tag... | |
3754 */ | |
3755 if(parent_tag != NULL ) { | |
3756 /* | |
3757 * Try to get the parent node for a tag | |
3758 */ | |
3759 if((x = xmlnode_get_tag(start, parent_tag)) == NULL) { | |
3760 /* | |
3761 * Descend? | |
3762 */ | |
3763 char *grand_parent = strcpy(g_malloc(strlen(parent_tag) + 1), parent_tag); | |
3764 char *parent; | |
3765 | |
3766 if((parent = strrchr(grand_parent, '/')) != NULL) { | |
3767 *(parent++) = '\0'; | |
3768 x = insert_tag_to_parent_tag(start, grand_parent, parent); | |
3769 } else { | |
3770 x = xmlnode_insert_tag(start, grand_parent); | |
3771 } | |
3772 g_free(grand_parent); | |
3773 } else { | |
3774 /* | |
3775 * We found *something* to be the parent node. | |
3776 * Note: may be the "root" node! | |
3777 */ | |
3778 xmlnode y; | |
3779 if((y = xmlnode_get_tag(x, new_tag)) != NULL) { | |
3780 return(y); | |
3781 } | |
3782 } | |
3783 } | |
3784 | |
3785 /* | |
3786 * insert the new tag into its parent node | |
3787 */ | |
3788 return(xmlnode_insert_tag((x == NULL? start : x), new_tag)); | |
3789 } | |
3790 | |
3791 /* | |
3792 * Find the tag name for a label | |
3793 * | |
3794 * Returns NULL on not found | |
3795 */ | |
3796 static char *tag_for_label(const char *label) | |
3797 { | |
3798 struct vcard_template *vc_tp = vcard_template_data; | |
3799 char *p = NULL; | |
3800 | |
3801 for(vc_tp = vcard_template_data; vc_tp->label != NULL; ++vc_tp) { | |
3802 if(strcmp(label, vc_tp->label) == 0) { | |
3803 p = vc_tp->tag; | |
3804 break; | |
3805 } | |
3806 } | |
3807 | |
3808 return(p); | |
3809 } | |
3810 | |
3811 /* | |
3812 * Send vCard info to Jabber server | |
3813 */ | |
3814 static void jabber_set_info(struct gaim_connection *gc, char *info) | |
3815 { | |
3816 xmlnode x, vc_node; | |
3817 char *id; | |
3818 struct jabber_data *jd = gc->proto_data; | |
3819 gjconn gjc = jd->gjc; | |
3820 | |
3821 x = xmlnode_new_tag("iq"); | |
3311 | 3822 xmlnode_put_attrib(x, "type", "set"); |
2956 | 3823 |
3824 id = gjab_getid(gjc); | |
3770 | 3825 |
2956 | 3826 xmlnode_put_attrib(x, "id", id); |
3827 | |
3828 /* | |
3829 * Send only if there's actually any *information* to send | |
3830 */ | |
4874 | 3831 vc_node = xmlstr2xmlnode(info); |
3832 | |
3833 if(vc_node) { | |
3834 if (xmlnode_get_name(vc_node) && | |
3835 !g_ascii_strncasecmp(xmlnode_get_name(vc_node), "vcard", 5)) { | |
3836 xmlnode_insert_tag_node(x, vc_node); | |
3837 debug_printf("jabber: vCard packet: %s\n", xmlnode2str(x)); | |
3838 gjab_send(gjc, x); | |
3839 } | |
3840 xmlnode_free(vc_node); | |
2956 | 3841 } |
3842 | |
3843 xmlnode_free(x); | |
3844 } | |
3845 | |
3846 /* | |
3847 * This is the callback from the "ok clicked" for "set vCard" | |
3848 * | |
3849 * Formats GSList data into XML-encoded string and returns a pointer | |
3850 * to said string. | |
3851 * | |
3852 * g_free()'ing the returned string space is the responsibility of | |
3853 * the caller. | |
3854 */ | |
3855 static gchar *jabber_format_info(MultiEntryDlg *b) | |
3856 { | |
3857 xmlnode vc_node; | |
3858 GSList *list; | |
3859 MultiEntryData *med; | |
3860 MultiTextData *mtd; | |
3861 char *p; | |
3862 | |
3863 struct tag_attr *tag_attr; | |
3864 | |
3865 vc_node = xmlnode_new_tag("vCard"); | |
3866 | |
3867 for(tag_attr = vcard_tag_attr_list; tag_attr->attr != NULL; ++tag_attr) | |
3868 xmlnode_put_attrib(vc_node, tag_attr->attr, tag_attr->value); | |
3869 | |
3870 for(list = b->multi_entry_items; list != NULL; list = list->next) { | |
3871 med = (MultiEntryData *) list->data; | |
3872 if(med->label != NULL && med->text != NULL && (med->text)[0] != '\0') { | |
3873 if((p = tag_for_label(med->label)) != NULL) { | |
3874 xmlnode xp; | |
3875 if((xp = insert_tag_to_parent_tag(vc_node, NULL, p)) != NULL) { | |
3876 xmlnode_insert_cdata(xp, med->text, -1); | |
3877 } | |
3878 } | |
3879 } | |
3880 } | |
3881 | |
3882 for(list = b->multi_text_items; list != NULL; list = list->next) { | |
3883 mtd = (MultiTextData *) list->data; | |
3884 if(mtd->label != NULL && mtd->text != NULL && (mtd->text)[0] != '\0') { | |
3885 if((p = tag_for_label(mtd->label)) != NULL) { | |
3886 xmlnode xp; | |
3887 if((xp = insert_tag_to_parent_tag(vc_node, NULL, p)) != NULL) { | |
3888 xmlnode_insert_cdata(xp, mtd->text, -1); | |
3889 } | |
3890 } | |
3891 } | |
3892 } | |
3893 | |
3894 | |
3895 p = g_strdup(xmlnode2str(vc_node)); | |
3896 xmlnode_free(vc_node); | |
3897 | |
3898 return(p); | |
3899 } | |
3900 | |
3901 /* | |
3902 * This gets executed by the proto action | |
3903 * | |
3904 * Creates a new MultiEntryDlg struct, gets the XML-formatted user_info | |
3905 * string (if any) into GSLists for the (multi-entry) edit dialog and | |
3906 * calls the set_vcard dialog. | |
3907 */ | |
3908 static void jabber_setup_set_info(struct gaim_connection *gc) | |
3909 { | |
3910 MultiEntryData *data; | |
3911 const struct vcard_template *vc_tp; | |
3912 char *user_info; | |
3913 MultiEntryDlg *b = multi_entry_dialog_new(); | |
3914 char *cdata; | |
3915 xmlnode x_vc_data = NULL; | |
4491 | 3916 struct gaim_account *tmp = gc->account; |
3917 b->account = tmp; | |
2956 | 3918 |
3919 | |
3920 /* | |
3921 * Get existing, XML-formatted, user info | |
3922 */ | |
3923 if((user_info = g_malloc(strlen(tmp->user_info) + 1)) != NULL) { | |
3924 strcpy(user_info, tmp->user_info); | |
3925 x_vc_data = xmlstr2xmlnode(user_info); | |
3926 } | |
3927 | |
3928 /* | |
3929 * Set up GSLists for edit with labels from "template," data from user info | |
3930 */ | |
3931 for(vc_tp = vcard_template_data; vc_tp->label != NULL; ++vc_tp) { | |
3932 if((vc_tp->label)[0] == '\0') | |
3933 continue; | |
3934 if(vc_tp->ptag == NULL) { | |
3935 cdata = xmlnode_get_tag_data(x_vc_data, vc_tp->tag); | |
3936 } else { | |
3937 gchar *tag = g_strdup_printf("%s/%s", vc_tp->ptag, vc_tp->tag); | |
3938 cdata = xmlnode_get_tag_data(x_vc_data, tag); | |
3939 g_free(tag); | |
3940 } | |
3941 if(strcmp(vc_tp->tag, "DESC") == 0) { | |
3942 multi_text_list_update(&(b->multi_text_items), | |
3943 vc_tp->label, cdata, TRUE); | |
3944 } else { | |
3945 data = multi_entry_list_update(&(b->multi_entry_items), | |
3946 vc_tp->label, cdata, TRUE); | |
3947 data->visible = vc_tp->visible; | |
3948 data->editable = vc_tp->editable; | |
3949 } | |
3950 } | |
3951 | |
3952 | |
3953 if(x_vc_data != NULL) { | |
3954 xmlnode_free(x_vc_data); | |
3955 } else { | |
3956 /* | |
3957 * Early Beta versions had a different user_info storage format--let's | |
3958 * see if that works. | |
3959 * | |
3960 * This goes away RSN. | |
3961 */ | |
3962 const char *record_separator = "<BR>"; | |
3963 const char *field_separator = ": "; | |
3964 gchar **str_list, **str_list_ptr, **str_list2; | |
3965 | |
3966 if((str_list = g_strsplit(user_info, record_separator, 0)) != NULL) { | |
3967 for(str_list_ptr = str_list; *str_list_ptr != NULL; ++str_list_ptr) { | |
3968 str_list2 = g_strsplit(*str_list_ptr, field_separator, 2); | |
3969 if(str_list2[0] != NULL && str_list2[1] != NULL) { | |
3970 g_strstrip(str_list2[0]); | |
3971 g_strstrip(str_list2[1]); | |
3972 /* this is ugly--so far */ | |
3973 if(strcmp(str_list2[0], "Description") == 0) { | |
3974 multi_text_list_update(&(b->multi_text_items), | |
3975 str_list2[0], str_list2[1], FALSE); | |
3976 } else { | |
3977 multi_entry_list_update(&(b->multi_entry_items), | |
3978 str_list2[0], str_list2[1], FALSE); | |
3979 } | |
3980 } | |
3981 g_strfreev(str_list2); | |
3982 } | |
3983 g_strfreev(str_list); | |
3984 } | |
3985 } | |
3986 | |
3987 if(user_info != NULL) { | |
3988 g_free(user_info); | |
3989 } | |
3990 | |
2975 | 3991 b->title = _("Gaim - Edit Jabber vCard"); |
4074 | 3992 b->role = "set_info"; |
2956 | 3993 b->instructions->text = g_strdup(multi_entry_instructions); |
2975 | 3994 b->entries_title = g_strdup(entries_title); |
2956 | 3995 |
3996 b->custom = (void *) jabber_format_info; | |
3997 | |
3998 show_set_vcard(b); | |
3999 } | |
4000 | |
4001 /*---------------------------------------*/ | |
4002 /* End Jabber "set info" (vCard) support */ | |
4003 /*---------------------------------------*/ | |
4004 | |
4005 /*----------------------------------------*/ | |
4006 /* Jabber "user registration" support */ | |
4007 /*----------------------------------------*/ | |
4008 | |
4009 /* | |
4010 * Three of the following four functions duplicate much of what | |
4011 * exists elsewhere: | |
4012 * | |
4013 * jabber_handleregresp() | |
4014 * gjab_reqreg() | |
4015 * jabber_handle_registration_state() | |
4016 * | |
4017 * It may be that an additional flag could be added to one of | |
4018 * the "local" structs and the duplicated code modified to | |
4019 * account for it--thus eliminating the duplication. Then again: | |
4020 * doing it the way it is may be much cleaner. | |
4021 * | |
4022 * TBD: Code to support requesting additional information server | |
4023 * wants at registration--incl. dialog. | |
4024 */ | |
4025 | |
4026 /* | |
4027 * Like jabber_handlepacket(), only different | |
4028 */ | |
4029 static void jabber_handleregresp(gjconn gjc, jpacket p) | |
4030 { | |
4031 if (jpacket_subtype(p) == JPACKET__RESULT) { | |
4032 xmlnode querynode; | |
4033 | |
4034 if((querynode = xmlnode_get_tag(p->x, "query")) != NULL) { | |
4035 char *xmlns; | |
4036 | |
4037 /* we damn well *better* have this! */ | |
4038 if((xmlns = xmlnode_get_attrib(querynode, "xmlns")) != NULL && | |
4039 strcmp(xmlns, NS_REGISTER) == 0) { | |
4040 | |
4041 char *tag; | |
4042 xmlnode child = xmlnode_get_firstchild(querynode); | |
4043 | |
4044 debug_printf("got registration requirments response!\n"); | |
4045 | |
4046 while(child != NULL) { | |
4047 if((tag = xmlnode_get_name(child)) != NULL) { | |
4048 char *data; | |
4049 | |
4050 fprintf(stderr, "DBG: got node: \"%s\"\n", tag); | |
4051 fflush(stderr); | |
4052 | |
4053 if((data = xmlnode_get_data(child)) != NULL) { | |
4054 fprintf(stderr, "DBG: got data: \"%s\"\n", data); | |
4055 fflush(stderr); | |
4056 } | |
4057 } | |
4058 child = xmlnode_get_nextsibling(child); | |
4059 } | |
4060 } | |
4061 } else { | |
4062 debug_printf("registration successful!\n"); | |
4063 | |
2975 | 4064 hide_login_progress_notice(GJ_GC(gjc), _("Server Registration successful!")); |
2956 | 4065 /* |
4066 * TBD: is this the correct way to do away with a | |
4067 * gaim_connection and all its associated memory | |
4068 * allocs, etc.? | |
4069 */ | |
4070 signoff(GJ_GC(gjc)); | |
4071 } | |
4072 | |
4073 } else { | |
4074 xmlnode xerr; | |
4075 char *errmsg = NULL; | |
4076 int errcode = 0; | |
4077 struct jabber_data *jd = GJ_GC(gjc)->proto_data; | |
4078 | |
4079 debug_printf("registration failed\n"); | |
4080 xerr = xmlnode_get_tag(p->x, "error"); | |
4081 if (xerr) { | |
4082 char msg[BUF_LONG]; | |
4083 errmsg = xmlnode_get_data(xerr); | |
4084 if (xmlnode_get_attrib(xerr, "code")) { | |
4085 errcode = atoi(xmlnode_get_attrib(xerr, "code")); | |
4086 g_snprintf(msg, sizeof(msg), "Error %d: %s", errcode, errmsg); | |
4087 } else | |
4088 g_snprintf(msg, sizeof(msg), "%s", errmsg); | |
4089 hide_login_progress(GJ_GC(gjc), msg); | |
4090 } else { | |
2975 | 4091 hide_login_progress(GJ_GC(gjc), _("Unknown registration error")); |
2956 | 4092 } |
4093 | |
4094 jd->die = TRUE; | |
4095 } | |
4096 } | |
4097 | |
4098 /* | |
4099 * Like gjab_reqauth(), only different | |
4100 */ | |
4101 static void gjab_reqreg(gjconn gjc) | |
4102 { | |
4103 xmlnode x, y, z; | |
4104 char *user; | |
4105 | |
4106 if (!gjc) | |
4107 return; | |
4108 | |
4109 x = jutil_iqnew(JPACKET__SET, NS_REGISTER); | |
4110 y = xmlnode_get_tag(x, "query"); | |
4111 | |
4112 user = gjc->user->user; | |
4113 | |
4114 if (user) { | |
4115 z = xmlnode_insert_tag(y, "username"); | |
4116 xmlnode_insert_cdata(z, user, -1); | |
4117 } | |
4118 z = xmlnode_insert_tag(y, "password"); | |
4119 xmlnode_insert_cdata(z, gjc->pass, -1); | |
4120 | |
4121 debug_printf("jabber: registration packet: %s\n", xmlnode2str(x)); | |
4122 gjab_send(gjc, x); | |
4123 xmlnode_free(x); | |
4124 } | |
4125 | |
4126 /* | |
4127 * Like jabber_handlestate(), only different | |
4128 */ | |
4129 static void jabber_handle_registration_state(gjconn gjc, int state) | |
4130 { | |
4131 switch (state) { | |
4132 case JCONN_STATE_OFF: | |
3074 | 4133 if(gjc->was_connected) { |
4134 hide_login_progress_error(GJ_GC(gjc), _("Connection lost")); | |
4135 } else { | |
4136 hide_login_progress(GJ_GC(gjc), _("Unable to connect")); | |
4137 } | |
2956 | 4138 signoff(GJ_GC(gjc)); |
4139 break; | |
4140 case JCONN_STATE_CONNECTED: | |
3074 | 4141 gjc->was_connected = 1; |
2956 | 4142 /* |
4143 * TBD? | |
2975 | 4144 set_login_progress(GJ_GC(gjc), 2, _("Connected")); |
2956 | 4145 */ |
4146 break; | |
4147 case JCONN_STATE_ON: | |
4148 /* | |
4149 * TBD? | |
2975 | 4150 set_login_progress(GJ_GC(gjc), 3, _("Requesting Authentication Method")); |
2956 | 4151 */ |
4152 gjab_reqreg(gjc); | |
4153 /* | |
4154 * TBD: A work-in-progress | |
4155 gjab_reqregreqs(gjc); | |
4156 */ | |
4157 break; | |
4158 default: | |
4159 debug_printf("state change: %d\n", state); | |
4160 } | |
4161 return; | |
4162 } | |
4163 | |
4164 /* | |
4165 * Like jabber_login(), only different | |
4166 */ | |
4491 | 4167 void jabber_register_user(struct gaim_account *account) |
2956 | 4168 { |
4491 | 4169 struct gaim_connection *gc = new_gaim_conn(account); |
2956 | 4170 struct jabber_data *jd = gc->proto_data = g_new0(struct jabber_data, 1); |
4917 | 4171 char *loginname = create_valid_jid(account->username, DEFAULT_SERVER, "Gaim"); |
2956 | 4172 |
4173 /* | |
4174 * These do nothing during registration | |
4175 */ | |
3311 | 4176 jd->buddies = NULL; |
2956 | 4177 jd->chats = NULL; |
4178 | |
4491 | 4179 if ((jd->gjc = gjab_new(loginname, account->password, gc)) == NULL) { |
2956 | 4180 g_free(loginname); |
4181 debug_printf("jabber: unable to connect (jab_new failed)\n"); | |
2975 | 4182 hide_login_progress(gc, _("Unable to connect")); |
2956 | 4183 signoff(gc); |
4184 } else { | |
4185 gjab_state_handler(jd->gjc, jabber_handle_registration_state); | |
4186 gjab_packet_handler(jd->gjc, jabber_handleregresp); | |
4187 jd->gjc->queries = NULL; | |
4188 gjab_start(jd->gjc); | |
4189 } | |
4190 | |
4191 g_free(loginname); | |
4192 } | |
4193 | |
4194 /*----------------------------------------*/ | |
4195 /* End Jabber "user registration" support */ | |
4196 /*----------------------------------------*/ | |
4197 | |
4333 | 4198 static GList *jabber_actions(struct gaim_connection *gc) |
2956 | 4199 { |
4200 GList *m = NULL; | |
4333 | 4201 struct proto_actions_menu *pam; |
4202 | |
4203 pam = g_new0(struct proto_actions_menu, 1); | |
4204 pam->label = _("Set User Info"); | |
4205 pam->callback = jabber_setup_set_info; | |
4206 pam->gc = gc; | |
4207 m = g_list_append(m, pam); | |
4208 | |
2956 | 4209 /* |
4333 | 4210 pam = g_new0(struct proto_actions_menu, 1); |
4211 pam->label = _("Set Dir Info"); | |
4212 pam->callback = show_set_dir; | |
4213 pam->gc = gc; | |
4214 m = g_list_append(m, pam); | |
3257 | 4215 */ |
4333 | 4216 |
4217 pam = g_new0(struct proto_actions_menu, 1); | |
4218 pam->label = _("Change Password"); | |
4219 pam->callback = show_change_passwd; | |
4220 pam->gc = gc; | |
4221 m = g_list_append(m, pam); | |
2956 | 4222 |
4223 return m; | |
4224 } | |
4225 | |
3630 | 4226 G_MODULE_EXPORT void jabber_init(struct prpl *ret) |
2086 | 4227 { |
4228 /* the NULL's aren't required but they're nice to have */ | |
4966 | 4229 struct proto_user_split *pus; |
3572 | 4230 struct proto_user_opt *puo; |
2086 | 4231 ret->protocol = PROTO_JABBER; |
4232 ret->options = OPT_PROTO_UNIQUE_CHATNAME | OPT_PROTO_CHAT_TOPIC; | |
3572 | 4233 ret->name = g_strdup("Jabber"); |
2086 | 4234 ret->list_icon = jabber_list_icon; |
4916 | 4235 ret->list_emblems = jabber_list_emblems; |
4732 | 4236 ret->status_text = jabber_status_text; |
4744 | 4237 ret->tooltip_text = jabber_tooltip_text; |
2086 | 4238 ret->away_states = jabber_away_states; |
2956 | 4239 ret->actions = jabber_actions; |
2086 | 4240 ret->buddy_menu = jabber_buddy_menu; |
4241 ret->login = jabber_login; | |
4242 ret->close = jabber_close; | |
4243 ret->send_im = jabber_send_im; | |
2956 | 4244 ret->set_info = jabber_set_info; |
2086 | 4245 ret->get_info = jabber_get_info; |
2956 | 4246 ret->get_cb_info = jabber_get_cb_info; |
4247 ret->get_cb_away = jabber_get_cb_away_msg; | |
2086 | 4248 ret->set_away = jabber_set_away; |
4249 ret->set_dir = NULL; | |
4250 ret->get_dir = NULL; | |
4251 ret->dir_search = NULL; | |
4252 ret->set_idle = jabber_set_idle; | |
3257 | 4253 ret->change_passwd = jabber_change_passwd; |
2086 | 4254 ret->add_buddy = jabber_add_buddy; |
4255 ret->add_buddies = NULL; | |
4256 ret->remove_buddy = jabber_remove_buddy; | |
4257 ret->add_permit = NULL; | |
4258 ret->add_deny = NULL; | |
4259 ret->rem_permit = NULL; | |
4260 ret->rem_deny = NULL; | |
4261 ret->set_permit_deny = NULL; | |
4262 ret->warn = NULL; | |
2205
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
4263 ret->chat_info = jabber_chat_info; |
2086 | 4264 ret->join_chat = jabber_join_chat; |
4265 ret->chat_invite = jabber_chat_invite; | |
4266 ret->chat_leave = jabber_chat_leave; | |
4267 ret->chat_whisper = jabber_chat_whisper; | |
4268 ret->chat_send = jabber_chat_send; | |
4269 ret->keepalive = jabber_keepalive; | |
4270 ret->normalize = jabber_normalize; | |
2956 | 4271 ret->register_user = jabber_register_user; |
3349 | 4272 ret->alias_buddy = jabber_alias_buddy; |
3136 | 4273 ret->group_buddy = jabber_group_change; |
3311 | 4274 ret->send_typing = jabber_send_typing; |
4275 ret->convo_closed = jabber_convo_closed; | |
3349 | 4276 ret->rename_group = jabber_rename_group; |
4508
4c40fccbd7c9
[gaim-migrate @ 4784]
Christian Hammond <chipx86@chipx86.com>
parents:
4491
diff
changeset
|
4277 |
4966 | 4278 pus = g_new0(struct proto_user_split, 1); |
4279 pus->sep = '@'; | |
4280 pus->label = g_strdup(_("Server:")); | |
4281 pus->def = g_strdup("jabber.org"); | |
4282 ret->user_splits = g_list_append(ret->user_splits, pus); | |
4283 | |
4284 pus = g_new0(struct proto_user_split, 1); | |
4285 pus->sep = '/'; | |
4286 pus->label = g_strdup(_("Resource:")); | |
4287 pus->def = g_strdup("Gaim"); | |
4288 ret->user_splits = g_list_append(ret->user_splits, pus); | |
4289 | |
3572 | 4290 puo = g_new0(struct proto_user_opt, 1); |
4591 | 4291 puo->label = g_strdup(_("Port:")); |
4927 | 4292 puo->def = g_strdup_printf("%d", DEFAULT_PORT); |
4591 | 4293 puo->pos = USEROPT_PORT; |
4294 ret->user_opts = g_list_append(ret->user_opts, puo); | |
4295 | |
4296 puo = g_new0(struct proto_user_opt, 1); | |
4917 | 4297 puo->label = g_strdup(_("Connect Server:")); |
4589 | 4298 puo->def = g_strdup(""); |
4299 puo->pos = USEROPT_CONN_SERVER; | |
4300 ret->user_opts = g_list_append(ret->user_opts, puo); | |
4301 | |
2086 | 4302 my_protocol = ret; |
4303 } | |
4304 | |
4305 #ifndef STATIC | |
4306 | |
3630 | 4307 G_MODULE_EXPORT void gaim_prpl_init(struct prpl *prpl) |
2086 | 4308 { |
3572 | 4309 jabber_init(prpl); |
4310 prpl->plug->desc.api_version = PLUGIN_API_VERSION; | |
2086 | 4311 } |
4312 | |
4313 #endif | |
3311 | 4314 |
4315 /* | |
4316 * Local variables: | |
4317 * c-indentation-style: k&r | |
4318 * c-basic-offset: 8 | |
4319 * indent-tabs-mode: notnil | |
4320 * End: | |
4321 * | |
4322 * vim: shiftwidth=8: | |
4323 */ |