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