Mon, 29 Dec 2003 08:59:22 +0000
[gaim-migrate @ 8630]
fun jabber stuff, which isn't done yet. mostly harmless, and committing this now makes the next
commit that much easier for a lazy person such as myself to type.
| 7014 | 1 | /* |
| 2 | * gaim - Jabber Protocol Plugin | |
| 3 | * | |
| 4 | * Copyright (C) 2003, Nathan Walp <faceprint@faceprint.com> | |
| 5 | * | |
| 6 | * This program is free software; you can redistribute it and/or modify | |
| 7 | * it under the terms of the GNU General Public License as published by | |
| 8 | * the Free Software Foundation; either version 2 of the License, or | |
| 9 | * (at your option) any later version. | |
| 10 | * | |
| 11 | * This program is distributed in the hope that it will be useful, | |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 14 | * GNU General Public License for more details. | |
| 15 | * | |
| 16 | * You should have received a copy of the GNU General Public License | |
| 17 | * along with this program; if not, write to the Free Software | |
| 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 19 | * | |
| 20 | */ | |
| 21 | #include "internal.h" | |
| 22 | #include "debug.h" | |
| 7076 | 23 | #include "imgstore.h" |
| 7014 | 24 | #include "multi.h" |
| 25 | #include "notify.h" | |
| 26 | #include "request.h" | |
| 27 | #include "util.h" | |
| 7395 | 28 | #include "xmlnode.h" |
| 7014 | 29 | |
| 30 | #include "buddy.h" | |
| 31 | #include "chat.h" | |
| 32 | #include "jabber.h" | |
| 33 | #include "iq.h" | |
| 34 | #include "presence.h" | |
| 7395 | 35 | #include "si.h" |
| 7014 | 36 | |
| 37 | ||
| 7116 | 38 | void jabber_buddy_free(JabberBuddy *jb) |
| 39 | { | |
| 40 | g_return_if_fail(jb != NULL); | |
| 41 | ||
| 42 | if(jb->error_msg) | |
| 43 | g_free(jb->error_msg); | |
| 44 | while(jb->resources) | |
| 45 | jabber_buddy_resource_free(jb->resources->data); | |
| 46 | ||
| 47 | g_free(jb); | |
| 48 | } | |
| 49 | ||
| 7014 | 50 | JabberBuddy *jabber_buddy_find(JabberStream *js, const char *name, |
| 51 | gboolean create) | |
| 52 | { | |
| 53 | JabberBuddy *jb; | |
| 7445 | 54 | const char *realname; |
| 7014 | 55 | |
| 7445 | 56 | if(!(realname = jabber_normalize(js->gc->account, name))) |
| 7014 | 57 | return NULL; |
| 58 | ||
| 59 | jb = g_hash_table_lookup(js->buddies, realname); | |
| 60 | ||
| 61 | if(!jb && create) { | |
| 62 | jb = g_new0(JabberBuddy, 1); | |
| 63 | g_hash_table_insert(js->buddies, g_strdup(realname), jb); | |
| 64 | } | |
| 65 | ||
| 66 | return jb; | |
| 67 | } | |
| 68 | ||
| 69 | ||
| 70 | JabberBuddyResource *jabber_buddy_find_resource(JabberBuddy *jb, | |
| 71 | const char *resource) | |
| 72 | { | |
| 73 | JabberBuddyResource *jbr = NULL; | |
| 74 | GList *l; | |
| 75 | ||
| 76 | if(!jb) | |
| 77 | return NULL; | |
| 78 | ||
| 79 | for(l = jb->resources; l; l = l->next) | |
| 80 | { | |
| 81 | if(!jbr && !resource) { | |
| 82 | jbr = l->data; | |
| 83 | } else if(!resource) { | |
| 84 | if(((JabberBuddyResource *)l->data)->priority >= jbr->priority) | |
| 85 | jbr = l->data; | |
| 86 | } else if(((JabberBuddyResource *)l->data)->name) { | |
| 87 | if(!strcmp(((JabberBuddyResource *)l->data)->name, resource)) { | |
| 88 | jbr = l->data; | |
| 89 | break; | |
| 90 | } | |
| 91 | } | |
| 92 | } | |
| 93 | ||
| 94 | return jbr; | |
| 95 | } | |
| 96 | ||
| 97 | void jabber_buddy_track_resource(JabberBuddy *jb, const char *resource, | |
| 98 | int priority, int state, const char *status) | |
| 99 | { | |
| 100 | JabberBuddyResource *jbr = jabber_buddy_find_resource(jb, resource); | |
| 101 | ||
| 102 | if(!jbr) { | |
| 103 | jbr = g_new0(JabberBuddyResource, 1); | |
| 7116 | 104 | jbr->jb = jb; |
| 7014 | 105 | jbr->name = g_strdup(resource); |
| 106 | jbr->capabilities = JABBER_CAP_XHTML; | |
| 107 | jb->resources = g_list_append(jb->resources, jbr); | |
| 108 | } | |
| 109 | jbr->priority = priority; | |
| 110 | jbr->state = state; | |
| 111 | if(jbr->status) | |
| 112 | g_free(jbr->status); | |
| 113 | jbr->status = g_strdup(status); | |
| 114 | } | |
| 115 | ||
| 7116 | 116 | void jabber_buddy_resource_free(JabberBuddyResource *jbr) |
| 117 | { | |
| 118 | g_return_if_fail(jbr != NULL); | |
| 119 | ||
| 120 | jbr->jb->resources = g_list_remove(jbr->jb->resources, jbr); | |
| 121 | ||
| 122 | g_free(jbr->name); | |
| 123 | if(jbr->status) | |
| 124 | g_free(jbr->status); | |
| 125 | g_free(jbr); | |
| 126 | } | |
| 127 | ||
| 7014 | 128 | void jabber_buddy_remove_resource(JabberBuddy *jb, const char *resource) |
| 129 | { | |
| 130 | JabberBuddyResource *jbr = jabber_buddy_find_resource(jb, resource); | |
| 131 | ||
| 132 | if(!jbr) | |
| 133 | return; | |
| 134 | ||
| 7116 | 135 | jabber_buddy_resource_free(jbr); |
| 7014 | 136 | } |
| 137 | ||
| 138 | const char *jabber_buddy_get_status_msg(JabberBuddy *jb) | |
| 139 | { | |
| 140 | JabberBuddyResource *jbr; | |
| 141 | ||
| 142 | if(!jb) | |
| 143 | return NULL; | |
| 144 | ||
| 145 | jbr = jabber_buddy_find_resource(jb, NULL); | |
| 146 | ||
| 147 | if(!jbr) | |
| 148 | return NULL; | |
| 149 | ||
| 150 | return jbr->status; | |
| 151 | } | |
| 152 | ||
| 153 | /******* | |
| 154 | * This is the old vCard stuff taken from the old prpl. vCards, by definition | |
| 155 | * are a temporary thing until jabber can get its act together and come up | |
| 156 | * with a format for user information, hence the namespace of 'vcard-temp' | |
| 157 | * | |
| 158 | * Since I don't feel like putting that much work into something that's | |
| 159 | * _supposed_ to go away, i'm going to just copy the kludgy old code here, | |
| 160 | * and make it purdy when jabber comes up with a standards-track JEP to | |
| 161 | * replace vcard-temp | |
| 162 | * --Nathan | |
| 163 | *******/ | |
| 164 | ||
| 165 | /*---------------------------------------*/ | |
| 166 | /* Jabber "set info" (vCard) support */ | |
| 167 | /*---------------------------------------*/ | |
| 168 | ||
| 169 | /* | |
| 170 | * V-Card format: | |
| 171 | * | |
| 172 | * <vCard prodid='' version='' xmlns=''> | |
| 173 | * <FN></FN> | |
| 174 | * <N> | |
| 175 | * <FAMILY/> | |
| 176 | * <GIVEN/> | |
| 177 | * </N> | |
| 178 | * <NICKNAME/> | |
| 179 | * <URL/> | |
| 180 | * <ADR> | |
| 181 | * <STREET/> | |
| 182 | * <EXTADD/> | |
| 183 | * <LOCALITY/> | |
| 184 | * <REGION/> | |
| 185 | * <PCODE/> | |
| 186 | * <COUNTRY/> | |
| 187 | * </ADR> | |
| 188 | * <TEL/> | |
| 189 | * <EMAIL/> | |
| 190 | * <ORG> | |
| 191 | * <ORGNAME/> | |
| 192 | * <ORGUNIT/> | |
| 193 | * </ORG> | |
| 194 | * <TITLE/> | |
| 195 | * <ROLE/> | |
| 196 | * <DESC/> | |
| 197 | * <BDAY/> | |
| 198 | * </vCard> | |
| 199 | * | |
| 200 | * See also: | |
| 201 | * | |
| 202 | * http://docs.jabber.org/proto/html/vcard-temp.html | |
| 203 | * http://www.vcard-xml.org/dtd/vCard-XML-v2-20010520.dtd | |
| 204 | */ | |
| 205 | ||
| 206 | /* | |
| 207 | * Cross-reference user-friendly V-Card entry labels to vCard XML tags | |
| 208 | * and attributes. | |
| 209 | * | |
| 210 | * Order is (or should be) unimportant. For example: we have no way of | |
| 211 | * knowing in what order real data will arrive. | |
| 212 | * | |
| 213 | * Format: Label, Pre-set text, "visible" flag, "editable" flag, XML tag | |
| 214 | * name, XML tag's parent tag "path" (relative to vCard node). | |
| 215 | * | |
| 216 | * List is terminated by a NULL label pointer. | |
| 217 | * | |
| 218 | * Entries with no label text, but with XML tag and parent tag | |
| 219 | * entries, are used by V-Card XML construction routines to | |
| 220 | * "automagically" construct the appropriate XML node tree. | |
| 221 | * | |
| 222 | * Thoughts on future direction/expansion | |
| 223 | * | |
| 224 | * This is a "simple" vCard. | |
| 225 | * | |
| 226 | * It is possible for nodes other than the "vCard" node to have | |
| 227 | * attributes. Should that prove necessary/desirable, add an | |
| 228 | * "attributes" pointer to the vcard_template struct, create the | |
| 229 | * necessary tag_attr structs, and add 'em to the vcard_dflt_data | |
| 230 | * array. | |
| 231 | * | |
| 232 | * The above changes will (obviously) require changes to the vCard | |
| 233 | * construction routines. | |
| 234 | */ | |
| 235 | ||
| 236 | struct vcard_template { | |
| 237 | char *label; /* label text pointer */ | |
| 238 | char *text; /* entry text pointer */ | |
| 239 | int visible; /* should entry field be "visible?" */ | |
| 240 | int editable; /* should entry field be editable? */ | |
| 241 | char *tag; /* tag text */ | |
| 242 | char *ptag; /* parent tag "path" text */ | |
| 243 | char *url; /* vCard display format if URL */ | |
| 244 | } vcard_template_data[] = { | |
| 245 | {N_("Full Name"), NULL, TRUE, TRUE, "FN", NULL, NULL}, | |
| 246 | {N_("Family Name"), NULL, TRUE, TRUE, "FAMILY", "N", NULL}, | |
| 247 | {N_("Given Name"), NULL, TRUE, TRUE, "GIVEN", "N", NULL}, | |
| 248 | {N_("Nickname"), NULL, TRUE, TRUE, "NICKNAME", NULL, NULL}, | |
| 249 | {N_("URL"), NULL, TRUE, TRUE, "URL", NULL, "<A HREF=\"%s\">%s</A>"}, | |
| 250 | {N_("Street Address"), NULL, TRUE, TRUE, "STREET", "ADR", NULL}, | |
| 251 | {N_("Extended Address"), NULL, TRUE, TRUE, "EXTADD", "ADR", NULL}, | |
| 252 | {N_("Locality"), NULL, TRUE, TRUE, "LOCALITY", "ADR", NULL}, | |
| 253 | {N_("Region"), NULL, TRUE, TRUE, "REGION", "ADR", NULL}, | |
| 254 | {N_("Postal Code"), NULL, TRUE, TRUE, "PCODE", "ADR", NULL}, | |
| 255 | {N_("Country"), NULL, TRUE, TRUE, "COUNTRY", "ADR", NULL}, | |
| 256 | {N_("Telephone"), NULL, TRUE, TRUE, "TELEPHONE", NULL, NULL}, | |
| 257 | {N_("Email"), NULL, TRUE, TRUE, "EMAIL", NULL, "<A HREF=\"mailto:%s\">%s</A>"}, | |
| 258 | {N_("Organization Name"), NULL, TRUE, TRUE, "ORGNAME", "ORG", NULL}, | |
| 259 | {N_("Organization Unit"), NULL, TRUE, TRUE, "ORGUNIT", "ORG", NULL}, | |
| 260 | {N_("Title"), NULL, TRUE, TRUE, "TITLE", NULL, NULL}, | |
| 261 | {N_("Role"), NULL, TRUE, TRUE, "ROLE", NULL, NULL}, | |
| 262 | {N_("Birthday"), NULL, TRUE, TRUE, "BDAY", NULL, NULL}, | |
| 263 | {N_("Description"), NULL, TRUE, TRUE, "DESC", NULL, NULL}, | |
| 264 | {"", NULL, TRUE, TRUE, "N", NULL, NULL}, | |
| 265 | {"", NULL, TRUE, TRUE, "ADR", NULL, NULL}, | |
| 266 | {"", NULL, TRUE, TRUE, "ORG", NULL, NULL}, | |
| 267 | {NULL, NULL, 0, 0, NULL, NULL, NULL} | |
| 268 | }; | |
| 269 | ||
| 270 | /* | |
| 271 | * The "vCard" tag's attibute list... | |
| 272 | */ | |
| 273 | struct tag_attr { | |
| 274 | char *attr; | |
| 275 | char *value; | |
| 276 | } vcard_tag_attr_list[] = { | |
| 277 | {"prodid", "-//HandGen//NONSGML vGen v1.0//EN"}, | |
| 278 | {"version", "2.0", }, | |
| 279 | {"xmlns", "vcard-temp", }, | |
| 280 | {NULL, NULL}, | |
| 281 | }; | |
| 282 | ||
| 283 | ||
| 284 | /* | |
| 285 | * Insert a tag node into an xmlnode tree, recursively inserting parent tag | |
| 286 | * nodes as necessary | |
| 287 | * | |
| 288 | * Returns pointer to inserted node | |
| 289 | * | |
| 290 | * Note to hackers: this code is designed to be re-entrant (it's recursive--it | |
| 291 | * calls itself), so don't put any "static"s in here! | |
| 292 | */ | |
| 293 | static xmlnode *insert_tag_to_parent_tag(xmlnode *start, const char *parent_tag, const char *new_tag) | |
| 294 | { | |
| 295 | xmlnode *x = NULL; | |
| 296 | ||
| 297 | /* | |
| 298 | * If the parent tag wasn't specified, see if we can get it | |
| 299 | * from the vCard template struct. | |
| 300 | */ | |
| 301 | if(parent_tag == NULL) { | |
| 302 | struct vcard_template *vc_tp = vcard_template_data; | |
| 303 | ||
| 304 | while(vc_tp->label != NULL) { | |
| 305 | if(strcmp(vc_tp->tag, new_tag) == 0) { | |
| 306 | parent_tag = vc_tp->ptag; | |
| 307 | break; | |
| 308 | } | |
| 309 | ++vc_tp; | |
| 310 | } | |
| 311 | } | |
| 312 | ||
| 313 | /* | |
| 314 | * If we have a parent tag... | |
| 315 | */ | |
| 316 | if(parent_tag != NULL ) { | |
| 317 | /* | |
| 318 | * Try to get the parent node for a tag | |
| 319 | */ | |
| 320 | if((x = xmlnode_get_child(start, parent_tag)) == NULL) { | |
| 321 | /* | |
| 322 | * Descend? | |
| 323 | */ | |
| 324 | char *grand_parent = g_strdup(parent_tag); | |
| 325 | char *parent; | |
| 326 | ||
| 327 | if((parent = strrchr(grand_parent, '/')) != NULL) { | |
| 328 | *(parent++) = '\0'; | |
| 329 | x = insert_tag_to_parent_tag(start, grand_parent, parent); | |
| 330 | } else { | |
| 331 | x = xmlnode_new_child(start, grand_parent); | |
| 332 | } | |
| 333 | g_free(grand_parent); | |
| 334 | } else { | |
| 335 | /* | |
| 336 | * We found *something* to be the parent node. | |
| 337 | * Note: may be the "root" node! | |
| 338 | */ | |
| 339 | xmlnode *y; | |
| 340 | if((y = xmlnode_get_child(x, new_tag)) != NULL) { | |
| 341 | return(y); | |
| 342 | } | |
| 343 | } | |
| 344 | } | |
| 345 | ||
| 346 | /* | |
| 347 | * insert the new tag into its parent node | |
| 348 | */ | |
| 349 | return(xmlnode_new_child((x == NULL? start : x), new_tag)); | |
| 350 | } | |
| 351 | ||
| 352 | /* | |
| 353 | * Send vCard info to Jabber server | |
| 354 | */ | |
| 355 | void jabber_set_info(GaimConnection *gc, const char *info) | |
| 356 | { | |
| 357 | JabberIq *iq; | |
| 358 | JabberStream *js = gc->proto_data; | |
| 359 | xmlnode *vc_node; | |
| 360 | ||
| 361 | ||
| 362 | /* | |
| 363 | * Send only if there's actually any *information* to send | |
| 364 | */ | |
| 365 | vc_node = xmlnode_from_str(info, -1); | |
| 366 | ||
| 367 | if(vc_node) { | |
| 368 | if (vc_node->name && | |
| 369 | !g_ascii_strncasecmp(vc_node->name, "vcard", 5)) { | |
| 370 | iq = jabber_iq_new(js, JABBER_IQ_SET); | |
| 371 | xmlnode_insert_child(iq->node, vc_node); | |
| 372 | jabber_iq_send(iq); | |
| 373 | } else { | |
| 374 | xmlnode_free(vc_node); | |
| 375 | } | |
| 376 | } | |
| 377 | } | |
| 378 | ||
| 379 | /* | |
| 380 | * This is the callback from the "ok clicked" for "set vCard" | |
| 381 | * | |
| 382 | * Formats GSList data into XML-encoded string and returns a pointer | |
| 383 | * to said string. | |
| 384 | * | |
| 385 | * g_free()'ing the returned string space is the responsibility of | |
| 386 | * the caller. | |
| 387 | */ | |
| 388 | static void | |
| 389 | jabber_format_info(GaimConnection *gc, GaimRequestFields *fields) | |
| 390 | { | |
| 391 | GaimAccount *account; | |
| 392 | xmlnode *vc_node; | |
| 393 | GaimRequestField *field; | |
| 394 | const char *text; | |
| 395 | char *p; | |
| 396 | const struct vcard_template *vc_tp; | |
| 397 | struct tag_attr *tag_attr; | |
| 398 | ||
| 399 | vc_node = xmlnode_new("vCard"); | |
| 400 | ||
| 401 | for(tag_attr = vcard_tag_attr_list; tag_attr->attr != NULL; ++tag_attr) | |
| 402 | xmlnode_set_attrib(vc_node, tag_attr->attr, tag_attr->value); | |
| 403 | ||
| 404 | for (vc_tp = vcard_template_data; vc_tp->label != NULL; vc_tp++) { | |
| 405 | if (*vc_tp->label == '\0') | |
| 406 | continue; | |
| 407 | ||
| 408 | field = gaim_request_fields_get_field(fields, vc_tp->tag); | |
| 409 | text = gaim_request_field_string_get_value(field); | |
| 410 | ||
| 411 | gaim_debug(GAIM_DEBUG_INFO, "jabber", | |
| 412 | "Setting %s to '%s'\n", vc_tp->tag, text); | |
| 413 | ||
| 414 | if (text != NULL && *text != '\0') { | |
| 415 | xmlnode *xp; | |
| 416 | ||
| 417 | if ((xp = insert_tag_to_parent_tag(vc_node, | |
| 418 | NULL, vc_tp->tag)) != NULL) { | |
| 419 | ||
| 420 | xmlnode_insert_data(xp, text, -1); | |
| 421 | } | |
| 422 | } | |
| 423 | } | |
| 424 | ||
| 7642 | 425 | p = xmlnode_to_str(vc_node, NULL); |
| 7014 | 426 | xmlnode_free(vc_node); |
| 427 | ||
| 428 | account = gaim_connection_get_account(gc); | |
| 429 | ||
| 430 | if (account != NULL) { | |
| 431 | gaim_account_set_user_info(account, p); | |
| 432 | ||
| 433 | if (gc != NULL) | |
| 434 | serv_set_info(gc, p); | |
| 435 | } | |
| 436 | ||
| 437 | g_free(p); | |
| 438 | } | |
| 439 | ||
| 440 | /* | |
| 441 | * This gets executed by the proto action | |
| 442 | * | |
| 443 | * Creates a new GaimRequestFields struct, gets the XML-formatted user_info | |
| 444 | * string (if any) into GSLists for the (multi-entry) edit dialog and | |
| 445 | * calls the set_vcard dialog. | |
| 446 | */ | |
| 447 | void jabber_setup_set_info(GaimConnection *gc) | |
| 448 | { | |
| 449 | GaimRequestFields *fields; | |
| 450 | GaimRequestFieldGroup *group; | |
| 451 | GaimRequestField *field; | |
| 452 | const struct vcard_template *vc_tp; | |
| 453 | char *user_info; | |
| 454 | char *cdata; | |
| 455 | xmlnode *x_vc_data = NULL; | |
| 456 | ||
| 457 | fields = gaim_request_fields_new(); | |
| 458 | group = gaim_request_field_group_new(NULL); | |
| 459 | gaim_request_fields_add_group(fields, group); | |
| 460 | ||
| 461 | /* | |
| 462 | * Get existing, XML-formatted, user info | |
| 463 | */ | |
| 464 | if((user_info = g_strdup(gaim_account_get_user_info(gc->account))) != NULL) | |
| 465 | x_vc_data = xmlnode_from_str(user_info, -1); | |
| 466 | else | |
| 467 | user_info = g_strdup(""); | |
| 468 | ||
| 469 | /* | |
| 470 | * Set up GSLists for edit with labels from "template," data from user info | |
| 471 | */ | |
| 472 | for(vc_tp = vcard_template_data; vc_tp->label != NULL; ++vc_tp) { | |
| 473 | xmlnode *data_node; | |
| 474 | if((vc_tp->label)[0] == '\0') | |
| 475 | continue; | |
| 476 | if(vc_tp->ptag == NULL) { | |
| 477 | data_node = xmlnode_get_child(x_vc_data, vc_tp->tag); | |
| 478 | } else { | |
| 479 | gchar *tag = g_strdup_printf("%s/%s", vc_tp->ptag, vc_tp->tag); | |
| 480 | data_node = xmlnode_get_child(x_vc_data, tag); | |
| 481 | g_free(tag); | |
| 482 | } | |
| 483 | if(data_node) | |
| 484 | cdata = xmlnode_get_data(data_node); | |
| 485 | else | |
| 486 | cdata = NULL; | |
| 487 | ||
| 488 | if(strcmp(vc_tp->tag, "DESC") == 0) { | |
| 489 | field = gaim_request_field_string_new(vc_tp->tag, | |
| 490 | _(vc_tp->label), cdata, | |
| 491 | TRUE); | |
| 492 | } else { | |
| 493 | field = gaim_request_field_string_new(vc_tp->tag, | |
| 494 | _(vc_tp->label), cdata, | |
| 495 | FALSE); | |
| 496 | } | |
| 497 | ||
| 498 | gaim_request_field_group_add_field(group, field); | |
| 499 | } | |
| 500 | ||
| 501 | if(x_vc_data != NULL) | |
| 502 | xmlnode_free(x_vc_data); | |
| 503 | ||
| 504 | g_free(user_info); | |
| 505 | ||
| 506 | gaim_request_fields(gc, _("Edit Jabber vCard"), | |
| 507 | _("Edit Jabber vCard"), | |
| 508 | _("All items below are optional. Enter only the " | |
| 509 | "information with which you feel comfortable."), | |
| 510 | fields, | |
| 511 | _("Save"), G_CALLBACK(jabber_format_info), | |
| 512 | _("Cancel"), NULL, | |
| 513 | gc); | |
| 514 | } | |
| 515 | ||
| 516 | /*---------------------------------------*/ | |
| 517 | /* End Jabber "set info" (vCard) support */ | |
| 518 | /*---------------------------------------*/ | |
| 519 | ||
| 520 | /****** | |
| 521 | * end of that ancient crap that needs to die | |
| 522 | ******/ | |
| 523 | ||
| 524 | ||
| 7395 | 525 | static void jabber_vcard_parse(JabberStream *js, xmlnode *packet, gpointer data) |
| 7014 | 526 | { |
| 527 | GList *resources; | |
| 528 | const char *from = xmlnode_get_attrib(packet, "from"); | |
| 529 | JabberBuddy *jb; | |
| 530 | JabberBuddyResource *jbr; | |
| 531 | GString *info_text; | |
| 7306 | 532 | char *resource_name; |
| 7955 | 533 | char *bare_jid; |
| 7014 | 534 | char *title; |
| 535 | xmlnode *vcard; | |
| 7955 | 536 | GaimBuddy *b; |
| 7014 | 537 | |
| 538 | if(!from) | |
| 539 | return; | |
| 540 | ||
| 7116 | 541 | /* XXX: make this handle handle errors */ |
| 542 | ||
| 7014 | 543 | resource_name = jabber_get_resource(from); |
| 7955 | 544 | bare_jid = jabber_get_bare_jid(from); |
| 545 | ||
| 546 | b = gaim_find_buddy(js->gc->account, bare_jid); | |
| 7014 | 547 | |
| 548 | jb = jabber_buddy_find(js, from, TRUE); | |
| 549 | info_text = g_string_new(""); | |
| 550 | ||
| 551 | g_string_append_printf(info_text, "<b>%s:</b> %s<br/>\n", _("Jabber ID"), | |
| 552 | from); | |
| 553 | ||
| 554 | if(resource_name) { | |
| 555 | jbr = jabber_buddy_find_resource(jb, resource_name); | |
| 556 | if(jbr) { | |
| 7145 | 557 | char *purdy = NULL; |
| 558 | if(jbr->status) | |
| 559 | purdy = gaim_strdup_withhtml(jbr->status); | |
| 7014 | 560 | g_string_append_printf(info_text, "<b>%s:</b> %s%s%s<br/>\n", |
| 561 | _("Status"), jabber_get_state_string(jbr->state), | |
| 562 | purdy ? ": " : "", | |
| 563 | purdy ? purdy : ""); | |
| 7145 | 564 | if(purdy) |
| 565 | g_free(purdy); | |
| 7014 | 566 | } else { |
| 567 | g_string_append_printf(info_text, "<b>%s:</b> %s<br/>\n", | |
| 568 | _("Status"), _("Unknown")); | |
| 569 | } | |
| 570 | } else { | |
| 571 | for(resources = jb->resources; resources; resources = resources->next) { | |
| 7145 | 572 | char *purdy = NULL; |
| 7014 | 573 | jbr = resources->data; |
| 7145 | 574 | if(jbr->status) |
| 575 | purdy = gaim_strdup_withhtml(jbr->status); | |
| 7014 | 576 | g_string_append_printf(info_text, "<b>%s:</b> %s<br/>\n", |
| 577 | _("Resource"), jbr->name); | |
| 578 | g_string_append_printf(info_text, "<b>%s:</b> %s%s%s<br/><br/>\n", | |
| 579 | _("Status"), jabber_get_state_string(jbr->state), | |
| 580 | purdy ? ": " : "", | |
| 581 | purdy ? purdy : ""); | |
| 7145 | 582 | if(purdy) |
| 583 | g_free(purdy); | |
| 7014 | 584 | } |
| 585 | } | |
| 586 | ||
| 7306 | 587 | g_free(resource_name); |
| 7955 | 588 | g_free(bare_jid); |
| 7306 | 589 | |
| 7014 | 590 | if((vcard = xmlnode_get_child(packet, "vCard"))) { |
| 591 | xmlnode *child; | |
| 592 | for(child = vcard->child; child; child = child->next) | |
| 593 | { | |
| 594 | xmlnode *child2; | |
| 595 | char *text; | |
| 596 | ||
| 597 | if(child->type != NODE_TYPE_TAG) | |
| 598 | continue; | |
| 599 | ||
| 600 | text = xmlnode_get_data(child); | |
| 601 | if(text && !strcmp(child->name, "FN")) { | |
| 602 | g_string_append_printf(info_text, "<b>%s:</b> %s<br/>\n", | |
| 603 | _("Full Name"), text); | |
| 604 | } else if(!strcmp(child->name, "N")) { | |
| 605 | for(child2 = child->child; child2; child2 = child2->next) | |
| 606 | { | |
| 607 | char *text2; | |
| 608 | ||
| 609 | if(child2->type != NODE_TYPE_TAG) | |
| 610 | continue; | |
| 611 | ||
| 612 | text2 = xmlnode_get_data(child2); | |
| 613 | if(text2 && !strcmp(child2->name, "FAMILY")) { | |
| 614 | g_string_append_printf(info_text, | |
| 615 | "<b>%s:</b> %s<br/>\n", | |
| 616 | _("Family Name"), text2); | |
| 617 | } else if(text2 && !strcmp(child2->name, "GIVEN")) { | |
| 618 | g_string_append_printf(info_text, | |
| 619 | "<b>%s:</b> %s<br/>\n", | |
| 620 | _("Given Name"), text2); | |
| 621 | } else if(text2 && !strcmp(child2->name, "MIDDLE")) { | |
| 622 | g_string_append_printf(info_text, | |
| 623 | "<b>%s:</b> %s<br/>\n", | |
| 624 | _("Middle Name"), text2); | |
| 625 | } | |
| 626 | g_free(text2); | |
| 627 | } | |
| 628 | } else if(text && !strcmp(child->name, "NICKNAME")) { | |
| 629 | serv_got_alias(js->gc, from, text); | |
| 7955 | 630 | if(b) { |
| 631 | gaim_blist_node_set_string((GaimBlistNode*)b, "servernick", text); | |
| 632 | gaim_blist_save(); | |
| 633 | } | |
| 7014 | 634 | g_string_append_printf(info_text, "<b>%s:</b> %s<br/>\n", |
| 635 | _("Nickname"), text); | |
| 636 | } else if(text && !strcmp(child->name, "BDAY")) { | |
| 637 | g_string_append_printf(info_text, "<b>%s:</b> %s<br/>\n", | |
| 638 | _("Birthday"), text); | |
| 639 | } else if(!strcmp(child->name, "ADR")) { | |
| 640 | /* show which address it is */ | |
| 641 | if(child->child) | |
| 642 | g_string_append_printf(info_text, "<b>%s:</b><br/>\n", | |
| 643 | _("Address")); | |
| 644 | for(child2 = child->child; child2; child2 = child2->next) | |
| 645 | { | |
| 646 | char *text2; | |
| 647 | ||
| 648 | if(child2->type != NODE_TYPE_TAG) | |
| 649 | continue; | |
| 650 | ||
| 651 | text2 = xmlnode_get_data(child2); | |
| 652 | if(text2 && !strcmp(child2->name, "POBOX")) { | |
| 653 | g_string_append_printf(info_text, | |
| 654 | " <b>%s:</b> %s<br/>\n", | |
| 655 | _("P.O. Box"), text2); | |
| 656 | } else if(text2 && !strcmp(child2->name, "EXTADR")) { | |
| 657 | g_string_append_printf(info_text, | |
| 658 | " <b>%s:</b> %s<br/>\n", | |
| 659 | _("Extended Address"), text2); | |
| 660 | } else if(text2 && !strcmp(child2->name, "STREET")) { | |
| 661 | g_string_append_printf(info_text, | |
| 662 | " <b>%s:</b> %s<br/>\n", | |
| 663 | _("Street Address"), text2); | |
| 664 | } else if(text2 && !strcmp(child2->name, "LOCALITY")) { | |
| 665 | g_string_append_printf(info_text, | |
| 666 | " <b>%s:</b> %s<br/>\n", | |
| 667 | _("Locality"), text2); | |
| 668 | } else if(text2 && !strcmp(child2->name, "REGION")) { | |
| 669 | g_string_append_printf(info_text, | |
| 670 | " <b>%s:</b> %s<br/>\n", | |
| 671 | _("Region"), text2); | |
| 672 | } else if(text2 && !strcmp(child2->name, "PCODE")) { | |
| 673 | g_string_append_printf(info_text, | |
| 674 | " <b>%s:</b> %s<br/>\n", | |
| 675 | _("Postal Code"), text2); | |
| 676 | } else if(text2 && (!strcmp(child2->name, "CTRY") | |
| 677 | || !strcmp(child2->name, "COUNTRY"))) { | |
| 678 | g_string_append_printf(info_text, | |
| 679 | " <b>%s:</b> %s<br/>\n", | |
| 680 | _("Country"), text2); | |
| 681 | } | |
| 682 | g_free(text2); | |
| 683 | } | |
| 684 | } else if(!strcmp(child->name, "TEL")) { | |
| 685 | char *number; | |
| 686 | if((child2 = xmlnode_get_child(child, "NUMBER"))) { | |
| 687 | /* show what kind of number it is */ | |
| 688 | number = xmlnode_get_data(child2); | |
| 689 | if(number) { | |
| 690 | g_string_append_printf(info_text, | |
| 691 | "<b>%s:</b> %s<br/>\n", _("Telephone"), number); | |
| 692 | g_free(number); | |
| 693 | } | |
| 694 | } else if((number = xmlnode_get_data(child))) { | |
| 695 | /* lots of clients (including gaim) do this, but it's | |
| 696 | * out of spec */ | |
| 697 | g_string_append_printf(info_text, | |
| 698 | "<b>%s:</b> %s<br/>\n", _("Telephone"), number); | |
| 699 | g_free(number); | |
| 700 | } | |
| 701 | } else if(!strcmp(child->name, "EMAIL")) { | |
| 702 | char *userid; | |
| 703 | if((child2 = xmlnode_get_child(child, "USERID"))) { | |
| 704 | /* show what kind of email it is */ | |
| 705 | userid = xmlnode_get_data(child2); | |
| 706 | if(userid) { | |
| 707 | g_string_append_printf(info_text, | |
| 708 | "<b>%s:</b> <a href='mailto:%s'>%s</a><br/>\n", | |
| 709 | _("Email"), userid, userid); | |
| 710 | g_free(userid); | |
| 711 | } | |
| 712 | } else if((userid = xmlnode_get_data(child))) { | |
| 713 | /* lots of clients (including gaim) do this, but it's | |
| 714 | * out of spec */ | |
| 715 | g_string_append_printf(info_text, | |
| 716 | "<b>%s:</b> <a href='mailto:%s'>%s</a><br/>\n", | |
| 717 | _("Email"), userid, userid); | |
| 718 | g_free(userid); | |
| 719 | } | |
| 720 | } else if(!strcmp(child->name, "ORG")) { | |
| 721 | for(child2 = child->child; child2; child2 = child2->next) | |
| 722 | { | |
| 723 | char *text2; | |
| 724 | ||
| 725 | if(child2->type != NODE_TYPE_TAG) | |
| 726 | continue; | |
| 727 | ||
| 728 | text2 = xmlnode_get_data(child2); | |
| 729 | if(text2 && !strcmp(child2->name, "ORGNAME")) { | |
| 730 | g_string_append_printf(info_text, | |
| 731 | "<b>%s:</b> %s<br/>\n", | |
| 732 | _("Organization Name"), text2); | |
| 733 | } else if(text2 && !strcmp(child2->name, "ORGUNIT")) { | |
| 734 | g_string_append_printf(info_text, | |
| 735 | "<b>%s:</b> %s<br/>\n", | |
| 736 | _("Organization Unit"), text2); | |
| 737 | } | |
| 738 | g_free(text2); | |
| 739 | } | |
| 740 | } else if(text && !strcmp(child->name, "TITLE")) { | |
| 741 | g_string_append_printf(info_text, "<b>%s:</b> %s<br/>\n", | |
| 742 | _("Title"), text); | |
| 743 | } else if(text && !strcmp(child->name, "ROLE")) { | |
| 744 | g_string_append_printf(info_text, "<b>%s:</b> %s<br/>\n", | |
| 745 | _("Role"), text); | |
| 746 | } else if(text && !strcmp(child->name, "DESC")) { | |
| 747 | g_string_append_printf(info_text, "<b>%s:</b> %s<br/>\n", | |
| 748 | _("Description"), text); | |
| 7076 | 749 | } else if(!strcmp(child->name, "PHOTO") || |
| 750 | !strcmp(child->name, "LOGO")) { | |
| 751 | if((child2 = xmlnode_get_child(child, "BINVAL"))) { | |
| 752 | char *data, *text2; | |
| 753 | int size, imgid; | |
| 754 | if((text2 = xmlnode_get_data(child2))) { | |
|
7106
eaeff5775818
[gaim-migrate @ 7671]
Christian Hammond <chipx86@chipx86.com>
parents:
7076
diff
changeset
|
755 | gaim_base64_decode(text2, &data, &size); |
| 7076 | 756 | |
| 757 | imgid = gaim_imgstore_add(data, size, "logo.png"); | |
| 758 | g_string_append_printf(info_text, | |
| 7116 | 759 | "<b>%s:</b> <img id='%d'><br/>", |
| 7076 | 760 | strcmp(child->name, "PHOTO") == 0 ? |
| 761 | _("Photo") : _("Logo"), | |
| 762 | imgid); | |
| 763 | ||
| 764 | g_free(data); | |
| 765 | g_free(text2); | |
| 766 | } | |
| 767 | } | |
| 7014 | 768 | } |
| 769 | g_free(text); | |
| 770 | } | |
| 771 | } | |
| 772 | ||
| 773 | title = g_strdup_printf("User info for %s", from); | |
| 774 | ||
| 775 | gaim_notify_formatted(NULL, title, _("Jabber Profile"), | |
| 776 | NULL, info_text->str, NULL, NULL); | |
| 777 | ||
| 778 | g_free(title); | |
| 779 | g_string_free(info_text, TRUE); | |
| 780 | } | |
| 781 | ||
| 782 | void jabber_buddy_get_info(GaimConnection *gc, const char *who) | |
| 783 | { | |
| 784 | JabberStream *js = gc->proto_data; | |
| 785 | JabberIq *iq; | |
| 786 | xmlnode *vcard; | |
| 787 | ||
| 788 | iq = jabber_iq_new(js, JABBER_IQ_GET); | |
| 789 | ||
| 790 | xmlnode_set_attrib(iq->node, "to", who); | |
| 791 | vcard = xmlnode_new_child(iq->node, "vCard"); | |
| 792 | xmlnode_set_attrib(vcard, "xmlns", "vcard-temp"); | |
| 793 | ||
| 7395 | 794 | jabber_iq_set_callback(iq, jabber_vcard_parse, NULL); |
| 7014 | 795 | |
| 796 | jabber_iq_send(iq); | |
| 797 | } | |
| 798 | ||
| 799 | void jabber_buddy_get_info_chat(GaimConnection *gc, int id, | |
| 800 | const char *resource) | |
| 801 | { | |
| 802 | JabberStream *js = gc->proto_data; | |
| 803 | JabberChat *chat = jabber_chat_find_by_id(js, id); | |
| 804 | char *full_jid; | |
| 805 | ||
| 806 | if(!chat) | |
| 807 | return; | |
| 808 | ||
| 809 | full_jid = g_strdup_printf("%s@%s/%s", chat->room, chat->server, resource); | |
| 810 | jabber_buddy_get_info(gc, full_jid); | |
| 811 | g_free(full_jid); | |
| 812 | } | |
| 813 | ||
| 7395 | 814 | |
|
7757
e00649fedd6e
[gaim-migrate @ 8402]
Mark Doliner <markdoliner@pidgin.im>
parents:
7642
diff
changeset
|
815 | #if 0 |
| 7395 | 816 | static void jabber_buddy_ask_send_file(GaimConnection *gc, const char *name) |
| 817 | { | |
| 818 | JabberStream *js = gc->proto_data; | |
| 819 | GaimXfer *xfer; | |
| 820 | JabberSIXfer *jsx; | |
| 821 | ||
| 822 | xfer = gaim_xfer_new(gaim_connection_get_account(gc), GAIM_XFER_SEND, name); | |
| 823 | ||
| 824 | xfer->data = jsx = g_new0(JabberSIXfer, 1); | |
| 825 | jsx->js = js; | |
| 826 | ||
| 827 | gaim_xfer_set_init_fnc(xfer, jabber_si_xfer_init); | |
| 828 | gaim_xfer_set_start_fnc(xfer, jabber_si_xfer_start); | |
| 829 | gaim_xfer_set_end_fnc(xfer, jabber_si_xfer_end); | |
| 830 | gaim_xfer_set_cancel_send_fnc(xfer, jabber_si_xfer_cancel_send); | |
| 831 | gaim_xfer_set_cancel_recv_fnc(xfer, jabber_si_xfer_cancel_recv); | |
| 832 | gaim_xfer_set_ack_fnc(xfer, jabber_si_xfer_ack); | |
| 833 | ||
| 834 | js->file_transfers = g_list_append(js->file_transfers, xfer); | |
| 835 | ||
| 836 | gaim_xfer_request(xfer); | |
| 837 | } | |
|
7757
e00649fedd6e
[gaim-migrate @ 8402]
Mark Doliner <markdoliner@pidgin.im>
parents:
7642
diff
changeset
|
838 | #endif |
| 7395 | 839 | |
| 7014 | 840 | static void jabber_buddy_set_invisibility(JabberStream *js, const char *who, |
| 841 | gboolean invisible) | |
| 842 | { | |
| 843 | JabberBuddy *jb = jabber_buddy_find(js, who, TRUE); | |
| 844 | xmlnode *presence; | |
| 845 | ||
| 846 | presence = jabber_presence_create(js->gc->away_state, js->gc->away); | |
| 847 | xmlnode_set_attrib(presence, "to", who); | |
| 848 | if(invisible) { | |
| 849 | xmlnode_set_attrib(presence, "type", "invisible"); | |
| 850 | jb->invisible |= JABBER_INVIS_BUDDY; | |
| 851 | } else { | |
| 852 | jb->invisible &= ~JABBER_INVIS_BUDDY; | |
| 853 | } | |
| 854 | ||
| 855 | jabber_send(js, presence); | |
| 856 | xmlnode_free(presence); | |
| 857 | } | |
| 858 | ||
| 859 | static void jabber_buddy_make_invisible(GaimConnection *gc, const char *name) | |
| 860 | { | |
| 861 | JabberStream *js = gc->proto_data; | |
| 862 | jabber_buddy_set_invisibility(js, name, TRUE); | |
| 863 | } | |
| 864 | ||
| 865 | static void jabber_buddy_make_visible(GaimConnection *gc, const char *name) | |
| 866 | { | |
| 867 | JabberStream *js = gc->proto_data; | |
| 868 | jabber_buddy_set_invisibility(js, name, FALSE); | |
| 869 | } | |
| 870 | ||
| 871 | static void jabber_buddy_cancel_presence_notification(GaimConnection *gc, | |
| 872 | const char *name) | |
| 873 | { | |
| 874 | JabberStream *js = gc->proto_data; | |
| 875 | ||
| 876 | /* I wonder if we should prompt the user before doing this */ | |
| 877 | jabber_presence_subscription_set(js, name, "unsubscribed"); | |
| 878 | } | |
| 879 | ||
| 880 | static void jabber_buddy_rerequest_auth(GaimConnection *gc, const char *name) | |
| 881 | { | |
| 882 | JabberStream *js = gc->proto_data; | |
| 883 | ||
| 884 | jabber_presence_subscription_set(js, name, "subscribe"); | |
| 885 | } | |
| 886 | ||
| 7250 | 887 | static void jabber_buddy_unsubscribe(GaimConnection *gc, const char *name) |
| 888 | { | |
| 889 | JabberStream *js = gc->proto_data; | |
| 890 | ||
| 891 | jabber_presence_subscription_set(js, name, "unsubscribe"); | |
| 892 | } | |
| 893 | ||
| 7014 | 894 | GList *jabber_buddy_menu(GaimConnection *gc, const char *name) |
| 895 | { | |
| 896 | GList *m = NULL; | |
| 897 | struct proto_buddy_menu *pbm; | |
| 898 | JabberStream *js = gc->proto_data; | |
| 899 | JabberBuddy *jb = jabber_buddy_find(js, name, TRUE); | |
| 7395 | 900 | |
| 901 | if(!jb) | |
| 902 | return m; | |
| 903 | ||
| 7425 | 904 | /* XXX: should check capability once we know we want to send |
| 905 | pbm = g_new0(struct proto_buddy_menu, 1); | |
| 906 | pbm->label = _("Send File"); | |
| 907 | pbm->callback = jabber_buddy_ask_send_file; | |
| 908 | pbm->gc = gc; | |
| 909 | m = g_list_append(m, pbm); | |
| 7395 | 910 | |
| 7425 | 911 | */ |
| 7014 | 912 | |
| 913 | pbm = g_new0(struct proto_buddy_menu, 1); | |
| 914 | if(jb->invisible & JABBER_INVIS_BUDDY) { | |
| 915 | pbm->label = _("Un-hide From"); | |
| 916 | pbm->callback = jabber_buddy_make_visible; | |
| 917 | } else { | |
| 918 | pbm->label = _("Temporarily Hide From"); | |
| 919 | pbm->callback = jabber_buddy_make_invisible; | |
| 920 | } | |
| 921 | pbm->gc = gc; | |
| 922 | m = g_list_append(m, pbm); | |
| 923 | ||
| 924 | if(jb->subscription & JABBER_SUB_FROM) { | |
| 925 | pbm = g_new0(struct proto_buddy_menu, 1); | |
| 926 | pbm->label = _("Cancel Presence Notification"); | |
| 927 | pbm->callback = jabber_buddy_cancel_presence_notification; | |
| 928 | pbm->gc = gc; | |
| 929 | m = g_list_append(m, pbm); | |
| 930 | } | |
| 931 | ||
| 932 | if(!(jb->subscription & JABBER_SUB_TO)) { | |
| 933 | pbm = g_new0(struct proto_buddy_menu, 1); | |
| 7250 | 934 | pbm->label = _("(Re-)Request authorization"); |
| 7014 | 935 | pbm->callback = jabber_buddy_rerequest_auth; |
| 936 | pbm->gc = gc; | |
| 937 | m = g_list_append(m, pbm); | |
| 7250 | 938 | } else { |
| 939 | pbm = g_new0(struct proto_buddy_menu, 1); | |
| 940 | pbm->label = _("Unsubscribe"); | |
| 941 | pbm->callback = jabber_buddy_unsubscribe; | |
| 942 | pbm->gc = gc; | |
| 943 | m = g_list_append(m, pbm); | |
| 7014 | 944 | } |
| 945 | ||
| 946 | return m; | |
| 947 | } |