Mercurial > pidgin
annotate src/protocols/jabber/buddy.c @ 8622:ffed55cbdd67
[gaim-migrate @ 9373]
Any objections to this?
committer: Tailor Script <tailor@pidgin.im>
| author | Mark Doliner <mark@kingant.net> |
|---|---|
| date | Fri, 09 Apr 2004 02:49:30 +0000 |
| parents | c13a4913a071 |
| children | 92cbf9713795 |
| rev | line source |
|---|---|
| 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); | |
| 8400 | 125 if(jbr->thread_id) |
| 126 g_free(jbr->thread_id); | |
| 7116 | 127 g_free(jbr); |
| 128 } | |
| 129 | |
| 7014 | 130 void jabber_buddy_remove_resource(JabberBuddy *jb, const char *resource) |
| 131 { | |
| 132 JabberBuddyResource *jbr = jabber_buddy_find_resource(jb, resource); | |
| 133 | |
| 134 if(!jbr) | |
| 135 return; | |
| 136 | |
| 7116 | 137 jabber_buddy_resource_free(jbr); |
| 7014 | 138 } |
| 139 | |
| 140 const char *jabber_buddy_get_status_msg(JabberBuddy *jb) | |
| 141 { | |
| 142 JabberBuddyResource *jbr; | |
| 143 | |
| 144 if(!jb) | |
| 145 return NULL; | |
| 146 | |
| 147 jbr = jabber_buddy_find_resource(jb, NULL); | |
| 148 | |
| 149 if(!jbr) | |
| 150 return NULL; | |
| 151 | |
| 152 return jbr->status; | |
| 153 } | |
| 154 | |
| 155 /******* | |
| 156 * This is the old vCard stuff taken from the old prpl. vCards, by definition | |
| 157 * are a temporary thing until jabber can get its act together and come up | |
| 158 * with a format for user information, hence the namespace of 'vcard-temp' | |
| 159 * | |
| 160 * Since I don't feel like putting that much work into something that's | |
| 161 * _supposed_ to go away, i'm going to just copy the kludgy old code here, | |
| 162 * and make it purdy when jabber comes up with a standards-track JEP to | |
| 163 * replace vcard-temp | |
| 164 * --Nathan | |
| 165 *******/ | |
| 166 | |
| 167 /*---------------------------------------*/ | |
| 168 /* Jabber "set info" (vCard) support */ | |
| 169 /*---------------------------------------*/ | |
| 170 | |
| 171 /* | |
| 172 * V-Card format: | |
| 173 * | |
| 174 * <vCard prodid='' version='' xmlns=''> | |
| 175 * <FN></FN> | |
| 176 * <N> | |
| 177 * <FAMILY/> | |
| 178 * <GIVEN/> | |
| 179 * </N> | |
| 180 * <NICKNAME/> | |
| 181 * <URL/> | |
| 182 * <ADR> | |
| 183 * <STREET/> | |
| 184 * <EXTADD/> | |
| 185 * <LOCALITY/> | |
| 186 * <REGION/> | |
| 187 * <PCODE/> | |
| 188 * <COUNTRY/> | |
| 189 * </ADR> | |
| 190 * <TEL/> | |
| 191 * <EMAIL/> | |
| 192 * <ORG> | |
| 193 * <ORGNAME/> | |
| 194 * <ORGUNIT/> | |
| 195 * </ORG> | |
| 196 * <TITLE/> | |
| 197 * <ROLE/> | |
| 198 * <DESC/> | |
| 199 * <BDAY/> | |
| 200 * </vCard> | |
| 201 * | |
| 202 * See also: | |
| 203 * | |
| 204 * http://docs.jabber.org/proto/html/vcard-temp.html | |
| 205 * http://www.vcard-xml.org/dtd/vCard-XML-v2-20010520.dtd | |
| 206 */ | |
| 207 | |
| 208 /* | |
| 209 * Cross-reference user-friendly V-Card entry labels to vCard XML tags | |
| 210 * and attributes. | |
| 211 * | |
| 212 * Order is (or should be) unimportant. For example: we have no way of | |
| 213 * knowing in what order real data will arrive. | |
| 214 * | |
| 215 * Format: Label, Pre-set text, "visible" flag, "editable" flag, XML tag | |
| 216 * name, XML tag's parent tag "path" (relative to vCard node). | |
| 217 * | |
| 218 * List is terminated by a NULL label pointer. | |
| 219 * | |
| 220 * Entries with no label text, but with XML tag and parent tag | |
| 221 * entries, are used by V-Card XML construction routines to | |
| 222 * "automagically" construct the appropriate XML node tree. | |
| 223 * | |
| 224 * Thoughts on future direction/expansion | |
| 225 * | |
| 226 * This is a "simple" vCard. | |
| 227 * | |
| 228 * It is possible for nodes other than the "vCard" node to have | |
| 229 * attributes. Should that prove necessary/desirable, add an | |
| 230 * "attributes" pointer to the vcard_template struct, create the | |
| 231 * necessary tag_attr structs, and add 'em to the vcard_dflt_data | |
| 232 * array. | |
| 233 * | |
| 234 * The above changes will (obviously) require changes to the vCard | |
| 235 * construction routines. | |
| 236 */ | |
| 237 | |
| 238 struct vcard_template { | |
| 239 char *label; /* label text pointer */ | |
| 240 char *text; /* entry text pointer */ | |
| 241 int visible; /* should entry field be "visible?" */ | |
| 242 int editable; /* should entry field be editable? */ | |
| 243 char *tag; /* tag text */ | |
| 244 char *ptag; /* parent tag "path" text */ | |
| 245 char *url; /* vCard display format if URL */ | |
| 246 } vcard_template_data[] = { | |
| 247 {N_("Full Name"), NULL, TRUE, TRUE, "FN", NULL, NULL}, | |
| 248 {N_("Family Name"), NULL, TRUE, TRUE, "FAMILY", "N", NULL}, | |
| 249 {N_("Given Name"), NULL, TRUE, TRUE, "GIVEN", "N", NULL}, | |
| 250 {N_("Nickname"), NULL, TRUE, TRUE, "NICKNAME", NULL, NULL}, | |
| 251 {N_("URL"), NULL, TRUE, TRUE, "URL", NULL, "<A HREF=\"%s\">%s</A>"}, | |
| 252 {N_("Street Address"), NULL, TRUE, TRUE, "STREET", "ADR", NULL}, | |
| 253 {N_("Extended Address"), NULL, TRUE, TRUE, "EXTADD", "ADR", NULL}, | |
| 254 {N_("Locality"), NULL, TRUE, TRUE, "LOCALITY", "ADR", NULL}, | |
| 255 {N_("Region"), NULL, TRUE, TRUE, "REGION", "ADR", NULL}, | |
| 256 {N_("Postal Code"), NULL, TRUE, TRUE, "PCODE", "ADR", NULL}, | |
| 257 {N_("Country"), NULL, TRUE, TRUE, "COUNTRY", "ADR", NULL}, | |
| 258 {N_("Telephone"), NULL, TRUE, TRUE, "TELEPHONE", NULL, NULL}, | |
| 259 {N_("Email"), NULL, TRUE, TRUE, "EMAIL", NULL, "<A HREF=\"mailto:%s\">%s</A>"}, | |
| 260 {N_("Organization Name"), NULL, TRUE, TRUE, "ORGNAME", "ORG", NULL}, | |
| 261 {N_("Organization Unit"), NULL, TRUE, TRUE, "ORGUNIT", "ORG", NULL}, | |
| 262 {N_("Title"), NULL, TRUE, TRUE, "TITLE", NULL, NULL}, | |
| 263 {N_("Role"), NULL, TRUE, TRUE, "ROLE", NULL, NULL}, | |
| 264 {N_("Birthday"), NULL, TRUE, TRUE, "BDAY", NULL, NULL}, | |
| 265 {N_("Description"), NULL, TRUE, TRUE, "DESC", NULL, NULL}, | |
| 266 {"", NULL, TRUE, TRUE, "N", NULL, NULL}, | |
| 267 {"", NULL, TRUE, TRUE, "ADR", NULL, NULL}, | |
| 268 {"", NULL, TRUE, TRUE, "ORG", NULL, NULL}, | |
| 269 {NULL, NULL, 0, 0, NULL, NULL, NULL} | |
| 270 }; | |
| 271 | |
| 272 /* | |
| 273 * The "vCard" tag's attibute list... | |
| 274 */ | |
| 275 struct tag_attr { | |
| 276 char *attr; | |
| 277 char *value; | |
| 278 } vcard_tag_attr_list[] = { | |
| 279 {"prodid", "-//HandGen//NONSGML vGen v1.0//EN"}, | |
| 280 {"version", "2.0", }, | |
| 281 {"xmlns", "vcard-temp", }, | |
| 282 {NULL, NULL}, | |
| 283 }; | |
| 284 | |
| 285 | |
| 286 /* | |
| 287 * Insert a tag node into an xmlnode tree, recursively inserting parent tag | |
| 288 * nodes as necessary | |
| 289 * | |
| 290 * Returns pointer to inserted node | |
| 291 * | |
| 292 * Note to hackers: this code is designed to be re-entrant (it's recursive--it | |
| 293 * calls itself), so don't put any "static"s in here! | |
| 294 */ | |
| 295 static xmlnode *insert_tag_to_parent_tag(xmlnode *start, const char *parent_tag, const char *new_tag) | |
| 296 { | |
| 297 xmlnode *x = NULL; | |
| 298 | |
| 299 /* | |
| 300 * If the parent tag wasn't specified, see if we can get it | |
| 301 * from the vCard template struct. | |
| 302 */ | |
| 303 if(parent_tag == NULL) { | |
| 304 struct vcard_template *vc_tp = vcard_template_data; | |
| 305 | |
| 306 while(vc_tp->label != NULL) { | |
| 307 if(strcmp(vc_tp->tag, new_tag) == 0) { | |
| 308 parent_tag = vc_tp->ptag; | |
| 309 break; | |
| 310 } | |
| 311 ++vc_tp; | |
| 312 } | |
| 313 } | |
| 314 | |
| 315 /* | |
| 316 * If we have a parent tag... | |
| 317 */ | |
| 318 if(parent_tag != NULL ) { | |
| 319 /* | |
| 320 * Try to get the parent node for a tag | |
| 321 */ | |
| 322 if((x = xmlnode_get_child(start, parent_tag)) == NULL) { | |
| 323 /* | |
| 324 * Descend? | |
| 325 */ | |
| 326 char *grand_parent = g_strdup(parent_tag); | |
| 327 char *parent; | |
| 328 | |
| 329 if((parent = strrchr(grand_parent, '/')) != NULL) { | |
| 330 *(parent++) = '\0'; | |
| 331 x = insert_tag_to_parent_tag(start, grand_parent, parent); | |
| 332 } else { | |
| 333 x = xmlnode_new_child(start, grand_parent); | |
| 334 } | |
| 335 g_free(grand_parent); | |
| 336 } else { | |
| 337 /* | |
| 338 * We found *something* to be the parent node. | |
| 339 * Note: may be the "root" node! | |
| 340 */ | |
| 341 xmlnode *y; | |
| 342 if((y = xmlnode_get_child(x, new_tag)) != NULL) { | |
| 343 return(y); | |
| 344 } | |
| 345 } | |
| 346 } | |
| 347 | |
| 348 /* | |
| 349 * insert the new tag into its parent node | |
| 350 */ | |
| 351 return(xmlnode_new_child((x == NULL? start : x), new_tag)); | |
| 352 } | |
| 353 | |
| 354 /* | |
| 355 * Send vCard info to Jabber server | |
| 356 */ | |
| 357 void jabber_set_info(GaimConnection *gc, const char *info) | |
| 358 { | |
| 359 JabberIq *iq; | |
| 360 JabberStream *js = gc->proto_data; | |
| 361 xmlnode *vc_node; | |
| 362 | |
| 363 | |
| 364 /* | |
| 365 * Send only if there's actually any *information* to send | |
| 366 */ | |
| 367 vc_node = xmlnode_from_str(info, -1); | |
| 368 | |
| 369 if(vc_node) { | |
| 370 if (vc_node->name && | |
| 371 !g_ascii_strncasecmp(vc_node->name, "vcard", 5)) { | |
| 372 iq = jabber_iq_new(js, JABBER_IQ_SET); | |
| 373 xmlnode_insert_child(iq->node, vc_node); | |
| 374 jabber_iq_send(iq); | |
| 375 } else { | |
| 376 xmlnode_free(vc_node); | |
| 377 } | |
| 378 } | |
| 379 } | |
| 380 | |
| 381 /* | |
| 382 * This is the callback from the "ok clicked" for "set vCard" | |
| 383 * | |
| 384 * Formats GSList data into XML-encoded string and returns a pointer | |
| 385 * to said string. | |
| 386 * | |
| 387 * g_free()'ing the returned string space is the responsibility of | |
| 388 * the caller. | |
| 389 */ | |
| 390 static void | |
| 391 jabber_format_info(GaimConnection *gc, GaimRequestFields *fields) | |
| 392 { | |
| 393 GaimAccount *account; | |
| 394 xmlnode *vc_node; | |
| 395 GaimRequestField *field; | |
| 396 const char *text; | |
| 397 char *p; | |
| 398 const struct vcard_template *vc_tp; | |
| 399 struct tag_attr *tag_attr; | |
| 400 | |
| 401 vc_node = xmlnode_new("vCard"); | |
| 402 | |
| 403 for(tag_attr = vcard_tag_attr_list; tag_attr->attr != NULL; ++tag_attr) | |
| 404 xmlnode_set_attrib(vc_node, tag_attr->attr, tag_attr->value); | |
| 405 | |
| 406 for (vc_tp = vcard_template_data; vc_tp->label != NULL; vc_tp++) { | |
| 407 if (*vc_tp->label == '\0') | |
| 408 continue; | |
| 409 | |
| 410 field = gaim_request_fields_get_field(fields, vc_tp->tag); | |
| 411 text = gaim_request_field_string_get_value(field); | |
| 412 | |
| 413 gaim_debug(GAIM_DEBUG_INFO, "jabber", | |
| 414 "Setting %s to '%s'\n", vc_tp->tag, text); | |
| 415 | |
| 416 if (text != NULL && *text != '\0') { | |
| 417 xmlnode *xp; | |
| 418 | |
| 419 if ((xp = insert_tag_to_parent_tag(vc_node, | |
| 420 NULL, vc_tp->tag)) != NULL) { | |
| 421 | |
| 422 xmlnode_insert_data(xp, text, -1); | |
| 423 } | |
| 424 } | |
| 425 } | |
| 426 | |
| 7642 | 427 p = xmlnode_to_str(vc_node, NULL); |
| 7014 | 428 xmlnode_free(vc_node); |
| 429 | |
| 430 account = gaim_connection_get_account(gc); | |
| 431 | |
| 432 if (account != NULL) { | |
| 433 gaim_account_set_user_info(account, p); | |
| 434 | |
| 435 if (gc != NULL) | |
| 436 serv_set_info(gc, p); | |
| 437 } | |
| 438 | |
| 439 g_free(p); | |
| 440 } | |
| 441 | |
| 442 /* | |
| 443 * This gets executed by the proto action | |
| 444 * | |
| 445 * Creates a new GaimRequestFields struct, gets the XML-formatted user_info | |
| 446 * string (if any) into GSLists for the (multi-entry) edit dialog and | |
| 447 * calls the set_vcard dialog. | |
| 448 */ | |
| 449 void jabber_setup_set_info(GaimConnection *gc) | |
| 450 { | |
| 451 GaimRequestFields *fields; | |
| 452 GaimRequestFieldGroup *group; | |
| 453 GaimRequestField *field; | |
| 454 const struct vcard_template *vc_tp; | |
| 455 char *user_info; | |
| 456 char *cdata; | |
| 457 xmlnode *x_vc_data = NULL; | |
| 458 | |
| 459 fields = gaim_request_fields_new(); | |
| 460 group = gaim_request_field_group_new(NULL); | |
| 461 gaim_request_fields_add_group(fields, group); | |
| 462 | |
| 463 /* | |
| 464 * Get existing, XML-formatted, user info | |
| 465 */ | |
| 466 if((user_info = g_strdup(gaim_account_get_user_info(gc->account))) != NULL) | |
| 467 x_vc_data = xmlnode_from_str(user_info, -1); | |
| 468 else | |
| 469 user_info = g_strdup(""); | |
| 470 | |
| 471 /* | |
| 472 * Set up GSLists for edit with labels from "template," data from user info | |
| 473 */ | |
| 474 for(vc_tp = vcard_template_data; vc_tp->label != NULL; ++vc_tp) { | |
| 475 xmlnode *data_node; | |
| 476 if((vc_tp->label)[0] == '\0') | |
| 477 continue; | |
| 478 if(vc_tp->ptag == NULL) { | |
| 479 data_node = xmlnode_get_child(x_vc_data, vc_tp->tag); | |
| 480 } else { | |
| 481 gchar *tag = g_strdup_printf("%s/%s", vc_tp->ptag, vc_tp->tag); | |
| 482 data_node = xmlnode_get_child(x_vc_data, tag); | |
| 483 g_free(tag); | |
| 484 } | |
| 485 if(data_node) | |
| 486 cdata = xmlnode_get_data(data_node); | |
| 487 else | |
| 488 cdata = NULL; | |
| 489 | |
| 490 if(strcmp(vc_tp->tag, "DESC") == 0) { | |
| 491 field = gaim_request_field_string_new(vc_tp->tag, | |
| 492 _(vc_tp->label), cdata, | |
| 493 TRUE); | |
| 494 } else { | |
| 495 field = gaim_request_field_string_new(vc_tp->tag, | |
| 496 _(vc_tp->label), cdata, | |
| 497 FALSE); | |
| 498 } | |
| 499 | |
| 500 gaim_request_field_group_add_field(group, field); | |
| 501 } | |
| 502 | |
| 503 if(x_vc_data != NULL) | |
| 504 xmlnode_free(x_vc_data); | |
| 505 | |
| 506 g_free(user_info); | |
| 507 | |
| 508 gaim_request_fields(gc, _("Edit Jabber vCard"), | |
| 509 _("Edit Jabber vCard"), | |
| 510 _("All items below are optional. Enter only the " | |
| 511 "information with which you feel comfortable."), | |
| 512 fields, | |
| 513 _("Save"), G_CALLBACK(jabber_format_info), | |
| 514 _("Cancel"), NULL, | |
| 515 gc); | |
| 516 } | |
| 517 | |
| 518 /*---------------------------------------*/ | |
| 519 /* End Jabber "set info" (vCard) support */ | |
| 520 /*---------------------------------------*/ | |
| 521 | |
| 522 /****** | |
| 523 * end of that ancient crap that needs to die | |
| 524 ******/ | |
| 525 | |
| 526 | |
| 7395 | 527 static void jabber_vcard_parse(JabberStream *js, xmlnode *packet, gpointer data) |
| 7014 | 528 { |
| 529 GList *resources; | |
| 530 const char *from = xmlnode_get_attrib(packet, "from"); | |
| 531 JabberBuddy *jb; | |
| 532 JabberBuddyResource *jbr; | |
| 533 GString *info_text; | |
| 7306 | 534 char *resource_name; |
| 7955 | 535 char *bare_jid; |
| 7014 | 536 char *title; |
| 8213 | 537 char *text; |
| 7014 | 538 xmlnode *vcard; |
| 7955 | 539 GaimBuddy *b; |
| 7014 | 540 |
| 541 if(!from) | |
| 542 return; | |
| 543 | |
| 544 resource_name = jabber_get_resource(from); | |
| 7955 | 545 bare_jid = jabber_get_bare_jid(from); |
| 546 | |
| 547 b = gaim_find_buddy(js->gc->account, bare_jid); | |
| 7014 | 548 |
| 549 jb = jabber_buddy_find(js, from, TRUE); | |
| 550 info_text = g_string_new(""); | |
| 551 | |
| 8213 | 552 g_string_append_printf(info_text, "<b>%s:</b> %s<br/>", _("Jabber ID"), |
| 7014 | 553 from); |
| 554 | |
| 555 if(resource_name) { | |
| 556 jbr = jabber_buddy_find_resource(jb, resource_name); | |
| 557 if(jbr) { | |
| 7145 | 558 char *purdy = NULL; |
| 559 if(jbr->status) | |
| 560 purdy = gaim_strdup_withhtml(jbr->status); | |
| 8213 | 561 g_string_append_printf(info_text, "<b>%s:</b> %s%s%s<br/>", |
| 7014 | 562 _("Status"), jabber_get_state_string(jbr->state), |
| 563 purdy ? ": " : "", | |
| 564 purdy ? purdy : ""); | |
| 7145 | 565 if(purdy) |
| 566 g_free(purdy); | |
| 7014 | 567 } else { |
| 8213 | 568 g_string_append_printf(info_text, "<b>%s:</b> %s<br/>", |
| 7014 | 569 _("Status"), _("Unknown")); |
| 570 } | |
| 571 } else { | |
| 572 for(resources = jb->resources; resources; resources = resources->next) { | |
| 7145 | 573 char *purdy = NULL; |
| 7014 | 574 jbr = resources->data; |
| 7145 | 575 if(jbr->status) |
| 576 purdy = gaim_strdup_withhtml(jbr->status); | |
| 8213 | 577 g_string_append_printf(info_text, "<b>%s:</b> %s<br/>", |
| 7014 | 578 _("Resource"), jbr->name); |
| 8213 | 579 g_string_append_printf(info_text, "<b>%s:</b> %s%s%s<br/><br/>", |
| 7014 | 580 _("Status"), jabber_get_state_string(jbr->state), |
| 581 purdy ? ": " : "", | |
| 582 purdy ? purdy : ""); | |
| 7145 | 583 if(purdy) |
| 584 g_free(purdy); | |
| 7014 | 585 } |
| 586 } | |
| 587 | |
| 7306 | 588 g_free(resource_name); |
| 7955 | 589 g_free(bare_jid); |
| 7306 | 590 |
| 7014 | 591 if((vcard = xmlnode_get_child(packet, "vCard"))) { |
| 592 xmlnode *child; | |
| 593 for(child = vcard->child; child; child = child->next) | |
| 594 { | |
| 595 xmlnode *child2; | |
| 596 | |
| 8135 | 597 if(child->type != XMLNODE_TYPE_TAG) |
| 7014 | 598 continue; |
| 599 | |
| 600 text = xmlnode_get_data(child); | |
| 601 if(text && !strcmp(child->name, "FN")) { | |
| 8213 | 602 g_string_append_printf(info_text, "<b>%s:</b> %s<br/>", |
| 7014 | 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 | |
| 8135 | 609 if(child2->type != XMLNODE_TYPE_TAG) |
| 7014 | 610 continue; |
| 611 | |
| 612 text2 = xmlnode_get_data(child2); | |
| 613 if(text2 && !strcmp(child2->name, "FAMILY")) { | |
| 614 g_string_append_printf(info_text, | |
| 8213 | 615 "<b>%s:</b> %s<br/>", |
| 7014 | 616 _("Family Name"), text2); |
| 617 } else if(text2 && !strcmp(child2->name, "GIVEN")) { | |
| 618 g_string_append_printf(info_text, | |
| 8213 | 619 "<b>%s:</b> %s<br/>", |
| 7014 | 620 _("Given Name"), text2); |
| 621 } else if(text2 && !strcmp(child2->name, "MIDDLE")) { | |
| 622 g_string_append_printf(info_text, | |
| 8213 | 623 "<b>%s:</b> %s<br/>", |
| 7014 | 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 } | |
| 8213 | 634 g_string_append_printf(info_text, "<b>%s:</b> %s<br/>", |
| 7014 | 635 _("Nickname"), text); |
| 636 } else if(text && !strcmp(child->name, "BDAY")) { | |
| 8213 | 637 g_string_append_printf(info_text, "<b>%s:</b> %s<br/>", |
| 7014 | 638 _("Birthday"), text); |
| 639 } else if(!strcmp(child->name, "ADR")) { | |
| 640 /* show which address it is */ | |
| 641 if(child->child) | |
| 8213 | 642 g_string_append_printf(info_text, "<b>%s:</b><br/>", |
| 7014 | 643 _("Address")); |
| 644 for(child2 = child->child; child2; child2 = child2->next) | |
| 645 { | |
| 646 char *text2; | |
| 647 | |
| 8135 | 648 if(child2->type != XMLNODE_TYPE_TAG) |
| 7014 | 649 continue; |
| 650 | |
| 651 text2 = xmlnode_get_data(child2); | |
| 652 if(text2 && !strcmp(child2->name, "POBOX")) { | |
| 653 g_string_append_printf(info_text, | |
| 8213 | 654 " <b>%s:</b> %s<br/>", |
| 7014 | 655 _("P.O. Box"), text2); |
| 656 } else if(text2 && !strcmp(child2->name, "EXTADR")) { | |
| 657 g_string_append_printf(info_text, | |
| 8213 | 658 " <b>%s:</b> %s<br/>", |
| 7014 | 659 _("Extended Address"), text2); |
| 660 } else if(text2 && !strcmp(child2->name, "STREET")) { | |
| 661 g_string_append_printf(info_text, | |
| 8213 | 662 " <b>%s:</b> %s<br/>", |
| 7014 | 663 _("Street Address"), text2); |
| 664 } else if(text2 && !strcmp(child2->name, "LOCALITY")) { | |
| 665 g_string_append_printf(info_text, | |
| 8213 | 666 " <b>%s:</b> %s<br/>", |
| 7014 | 667 _("Locality"), text2); |
| 668 } else if(text2 && !strcmp(child2->name, "REGION")) { | |
| 669 g_string_append_printf(info_text, | |
| 8213 | 670 " <b>%s:</b> %s<br/>", |
| 7014 | 671 _("Region"), text2); |
| 672 } else if(text2 && !strcmp(child2->name, "PCODE")) { | |
| 673 g_string_append_printf(info_text, | |
| 8213 | 674 " <b>%s:</b> %s<br/>", |
| 7014 | 675 _("Postal Code"), text2); |
| 676 } else if(text2 && (!strcmp(child2->name, "CTRY") | |
| 677 || !strcmp(child2->name, "COUNTRY"))) { | |
| 678 g_string_append_printf(info_text, | |
| 8213 | 679 " <b>%s:</b> %s<br/>", |
| 7014 | 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, | |
| 8213 | 691 "<b>%s:</b> %s<br/>", _("Telephone"), number); |
| 7014 | 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, | |
| 8213 | 698 "<b>%s:</b> %s<br/>", _("Telephone"), number); |
| 7014 | 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, | |
| 8213 | 708 "<b>%s:</b> <a href='mailto:%s'>%s</a><br/>", |
| 7014 | 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, | |
| 8213 | 716 "<b>%s:</b> <a href='mailto:%s'>%s</a><br/>", |
| 7014 | 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 | |
| 8135 | 725 if(child2->type != XMLNODE_TYPE_TAG) |
| 7014 | 726 continue; |
| 727 | |
| 728 text2 = xmlnode_get_data(child2); | |
| 729 if(text2 && !strcmp(child2->name, "ORGNAME")) { | |
| 730 g_string_append_printf(info_text, | |
| 8213 | 731 "<b>%s:</b> %s<br/>", |
| 7014 | 732 _("Organization Name"), text2); |
| 733 } else if(text2 && !strcmp(child2->name, "ORGUNIT")) { | |
| 734 g_string_append_printf(info_text, | |
| 8213 | 735 "<b>%s:</b> %s<br/>", |
| 7014 | 736 _("Organization Unit"), text2); |
| 737 } | |
| 738 g_free(text2); | |
| 739 } | |
| 740 } else if(text && !strcmp(child->name, "TITLE")) { | |
| 8213 | 741 g_string_append_printf(info_text, "<b>%s:</b> %s<br/>", |
| 7014 | 742 _("Title"), text); |
| 743 } else if(text && !strcmp(child->name, "ROLE")) { | |
| 8213 | 744 g_string_append_printf(info_text, "<b>%s:</b> %s<br/>", |
| 7014 | 745 _("Role"), text); |
| 746 } else if(text && !strcmp(child->name, "DESC")) { | |
| 8213 | 747 g_string_append_printf(info_text, "<b>%s:</b> %s<br/>", |
| 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
db6bd3e794d8
[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 | |
| 8213 | 775 text = gaim_strdup_withhtml(info_text->str); |
| 776 | |
| 7014 | 777 gaim_notify_formatted(NULL, title, _("Jabber Profile"), |
| 8213 | 778 NULL, text, NULL, NULL); |
| 7014 | 779 |
| 780 g_free(title); | |
| 781 g_string_free(info_text, TRUE); | |
| 8213 | 782 g_free(text); |
| 7014 | 783 } |
| 784 | |
| 785 void jabber_buddy_get_info(GaimConnection *gc, const char *who) | |
| 786 { | |
| 787 JabberStream *js = gc->proto_data; | |
| 788 JabberIq *iq; | |
| 789 xmlnode *vcard; | |
| 790 | |
| 791 iq = jabber_iq_new(js, JABBER_IQ_GET); | |
| 792 | |
| 793 xmlnode_set_attrib(iq->node, "to", who); | |
| 794 vcard = xmlnode_new_child(iq->node, "vCard"); | |
| 795 xmlnode_set_attrib(vcard, "xmlns", "vcard-temp"); | |
| 796 | |
| 7395 | 797 jabber_iq_set_callback(iq, jabber_vcard_parse, NULL); |
| 7014 | 798 |
| 799 jabber_iq_send(iq); | |
| 800 } | |
| 801 | |
| 802 void jabber_buddy_get_info_chat(GaimConnection *gc, int id, | |
| 803 const char *resource) | |
| 804 { | |
| 805 JabberStream *js = gc->proto_data; | |
| 806 JabberChat *chat = jabber_chat_find_by_id(js, id); | |
| 807 char *full_jid; | |
| 808 | |
| 809 if(!chat) | |
| 810 return; | |
| 811 | |
| 812 full_jid = g_strdup_printf("%s@%s/%s", chat->room, chat->server, resource); | |
| 813 jabber_buddy_get_info(gc, full_jid); | |
| 814 g_free(full_jid); | |
| 815 } | |
| 816 | |
| 7395 | 817 |
| 7014 | 818 static void jabber_buddy_set_invisibility(JabberStream *js, const char *who, |
| 819 gboolean invisible) | |
| 820 { | |
| 821 JabberBuddy *jb = jabber_buddy_find(js, who, TRUE); | |
| 822 xmlnode *presence; | |
| 823 | |
| 824 presence = jabber_presence_create(js->gc->away_state, js->gc->away); | |
| 825 xmlnode_set_attrib(presence, "to", who); | |
| 826 if(invisible) { | |
| 827 xmlnode_set_attrib(presence, "type", "invisible"); | |
| 828 jb->invisible |= JABBER_INVIS_BUDDY; | |
| 829 } else { | |
| 830 jb->invisible &= ~JABBER_INVIS_BUDDY; | |
| 831 } | |
| 832 | |
| 833 jabber_send(js, presence); | |
| 834 xmlnode_free(presence); | |
| 835 } | |
| 836 | |
| 837 static void jabber_buddy_make_invisible(GaimConnection *gc, const char *name) | |
| 838 { | |
| 839 JabberStream *js = gc->proto_data; | |
| 840 jabber_buddy_set_invisibility(js, name, TRUE); | |
| 841 } | |
| 842 | |
| 843 static void jabber_buddy_make_visible(GaimConnection *gc, const char *name) | |
| 844 { | |
| 845 JabberStream *js = gc->proto_data; | |
| 846 jabber_buddy_set_invisibility(js, name, FALSE); | |
| 847 } | |
| 848 | |
| 849 static void jabber_buddy_cancel_presence_notification(GaimConnection *gc, | |
| 850 const char *name) | |
| 851 { | |
| 852 JabberStream *js = gc->proto_data; | |
| 853 | |
| 854 /* I wonder if we should prompt the user before doing this */ | |
| 855 jabber_presence_subscription_set(js, name, "unsubscribed"); | |
| 856 } | |
| 857 | |
| 858 static void jabber_buddy_rerequest_auth(GaimConnection *gc, const char *name) | |
| 859 { | |
| 860 JabberStream *js = gc->proto_data; | |
| 861 | |
| 862 jabber_presence_subscription_set(js, name, "subscribe"); | |
| 863 } | |
| 864 | |
| 7250 | 865 static void jabber_buddy_unsubscribe(GaimConnection *gc, const char *name) |
| 866 { | |
| 867 JabberStream *js = gc->proto_data; | |
| 868 | |
| 869 jabber_presence_subscription_set(js, name, "unsubscribe"); | |
| 870 } | |
| 871 | |
| 7014 | 872 GList *jabber_buddy_menu(GaimConnection *gc, const char *name) |
| 873 { | |
| 874 GList *m = NULL; | |
| 875 struct proto_buddy_menu *pbm; | |
| 876 JabberStream *js = gc->proto_data; | |
| 877 JabberBuddy *jb = jabber_buddy_find(js, name, TRUE); | |
| 7395 | 878 |
| 879 if(!jb) | |
| 880 return m; | |
| 881 | |
| 7425 | 882 pbm = g_new0(struct proto_buddy_menu, 1); |
| 883 pbm->label = _("Send File"); | |
| 8312 | 884 pbm->callback = jabber_si_xfer_ask_send; |
| 7425 | 885 pbm->gc = gc; |
| 886 m = g_list_append(m, pbm); | |
| 7395 | 887 |
| 8185 | 888 /* XXX: fix the NOT ME below */ |
| 889 | |
| 890 if(js->protocol_version == JABBER_PROTO_0_9 /* && NOT ME */) { | |
| 8166 | 891 pbm = g_new0(struct proto_buddy_menu, 1); |
| 892 if(jb->invisible & JABBER_INVIS_BUDDY) { | |
| 893 pbm->label = _("Un-hide From"); | |
| 894 pbm->callback = jabber_buddy_make_visible; | |
| 895 } else { | |
| 896 pbm->label = _("Temporarily Hide From"); | |
| 897 pbm->callback = jabber_buddy_make_invisible; | |
| 898 } | |
| 899 pbm->gc = gc; | |
| 900 m = g_list_append(m, pbm); | |
| 7014 | 901 } |
| 902 | |
| 8185 | 903 if(jb->subscription & JABBER_SUB_FROM /* && NOT ME */) { |
| 7014 | 904 pbm = g_new0(struct proto_buddy_menu, 1); |
| 905 pbm->label = _("Cancel Presence Notification"); | |
| 906 pbm->callback = jabber_buddy_cancel_presence_notification; | |
| 907 pbm->gc = gc; | |
| 908 m = g_list_append(m, pbm); | |
| 909 } | |
| 910 | |
| 911 if(!(jb->subscription & JABBER_SUB_TO)) { | |
| 912 pbm = g_new0(struct proto_buddy_menu, 1); | |
| 7250 | 913 pbm->label = _("(Re-)Request authorization"); |
| 7014 | 914 pbm->callback = jabber_buddy_rerequest_auth; |
| 915 pbm->gc = gc; | |
| 916 m = g_list_append(m, pbm); | |
| 8185 | 917 } else /* if(NOT ME) */{ |
| 7250 | 918 pbm = g_new0(struct proto_buddy_menu, 1); |
| 919 pbm->label = _("Unsubscribe"); | |
| 920 pbm->callback = jabber_buddy_unsubscribe; | |
| 921 pbm->gc = gc; | |
| 922 m = g_list_append(m, pbm); | |
| 7014 | 923 } |
| 924 | |
| 925 return m; | |
| 926 } |
