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