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