Mercurial > pidgin
annotate src/protocols/jabber/buddy.c @ 10261:d4e9ff2edc4e
[gaim-migrate @ 11405]
This should fix segfault bug 1072604. Oops.
committer: Tailor Script <tailor@pidgin.im>
| author | Tim Ringenbach <marv@pidgin.im> |
|---|---|
| date | Thu, 25 Nov 2004 18:35:26 +0000 |
| parents | 09876d57c520 |
| children | e0a4b8586cbe |
| 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" |
| 9713 | 24 #include "prpl.h" |
| 7014 | 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" | |
| 10189 | 35 #include "sha.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 | |
| 9954 | 97 JabberBuddyResource *jabber_buddy_track_resource(JabberBuddy *jb, const char *resource, |
| 98 int priority, JabberBuddyState state, const char *status) | |
| 7014 | 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); | |
| 9954 | 114 |
| 115 return jbr; | |
| 7014 | 116 } |
| 117 | |
| 7116 | 118 void jabber_buddy_resource_free(JabberBuddyResource *jbr) |
| 119 { | |
| 120 g_return_if_fail(jbr != NULL); | |
| 121 | |
| 122 jbr->jb->resources = g_list_remove(jbr->jb->resources, jbr); | |
| 123 | |
| 124 g_free(jbr->name); | |
| 125 if(jbr->status) | |
| 126 g_free(jbr->status); | |
| 8400 | 127 if(jbr->thread_id) |
| 128 g_free(jbr->thread_id); | |
| 7116 | 129 g_free(jbr); |
| 130 } | |
| 131 | |
| 7014 | 132 void jabber_buddy_remove_resource(JabberBuddy *jb, const char *resource) |
| 133 { | |
| 134 JabberBuddyResource *jbr = jabber_buddy_find_resource(jb, resource); | |
| 135 | |
| 136 if(!jbr) | |
| 137 return; | |
| 138 | |
| 7116 | 139 jabber_buddy_resource_free(jbr); |
| 7014 | 140 } |
| 141 | |
| 142 const char *jabber_buddy_get_status_msg(JabberBuddy *jb) | |
| 143 { | |
| 144 JabberBuddyResource *jbr; | |
| 145 | |
| 146 if(!jb) | |
| 147 return NULL; | |
| 148 | |
| 149 jbr = jabber_buddy_find_resource(jb, NULL); | |
| 150 | |
| 151 if(!jbr) | |
| 152 return NULL; | |
| 153 | |
| 154 return jbr->status; | |
| 155 } | |
| 156 | |
| 157 /******* | |
| 158 * This is the old vCard stuff taken from the old prpl. vCards, by definition | |
| 159 * are a temporary thing until jabber can get its act together and come up | |
| 160 * with a format for user information, hence the namespace of 'vcard-temp' | |
| 161 * | |
| 162 * Since I don't feel like putting that much work into something that's | |
| 163 * _supposed_ to go away, i'm going to just copy the kludgy old code here, | |
| 164 * and make it purdy when jabber comes up with a standards-track JEP to | |
| 165 * replace vcard-temp | |
| 166 * --Nathan | |
| 167 *******/ | |
| 168 | |
| 169 /*---------------------------------------*/ | |
| 170 /* Jabber "set info" (vCard) support */ | |
| 171 /*---------------------------------------*/ | |
| 172 | |
| 173 /* | |
| 174 * V-Card format: | |
| 175 * | |
| 176 * <vCard prodid='' version='' xmlns=''> | |
| 177 * <FN></FN> | |
| 178 * <N> | |
| 179 * <FAMILY/> | |
| 180 * <GIVEN/> | |
| 181 * </N> | |
| 182 * <NICKNAME/> | |
| 183 * <URL/> | |
| 184 * <ADR> | |
| 185 * <STREET/> | |
| 186 * <EXTADD/> | |
| 187 * <LOCALITY/> | |
| 188 * <REGION/> | |
| 189 * <PCODE/> | |
| 190 * <COUNTRY/> | |
| 191 * </ADR> | |
| 192 * <TEL/> | |
| 193 * <EMAIL/> | |
| 194 * <ORG> | |
| 195 * <ORGNAME/> | |
| 196 * <ORGUNIT/> | |
| 197 * </ORG> | |
| 198 * <TITLE/> | |
| 199 * <ROLE/> | |
| 200 * <DESC/> | |
| 201 * <BDAY/> | |
| 202 * </vCard> | |
| 203 * | |
| 204 * See also: | |
| 205 * | |
| 206 * http://docs.jabber.org/proto/html/vcard-temp.html | |
| 207 * http://www.vcard-xml.org/dtd/vCard-XML-v2-20010520.dtd | |
| 208 */ | |
| 209 | |
| 210 /* | |
| 211 * Cross-reference user-friendly V-Card entry labels to vCard XML tags | |
| 212 * and attributes. | |
| 213 * | |
| 214 * Order is (or should be) unimportant. For example: we have no way of | |
| 215 * knowing in what order real data will arrive. | |
| 216 * | |
| 217 * Format: Label, Pre-set text, "visible" flag, "editable" flag, XML tag | |
| 218 * name, XML tag's parent tag "path" (relative to vCard node). | |
| 219 * | |
| 220 * List is terminated by a NULL label pointer. | |
| 221 * | |
| 222 * Entries with no label text, but with XML tag and parent tag | |
| 223 * entries, are used by V-Card XML construction routines to | |
| 224 * "automagically" construct the appropriate XML node tree. | |
| 225 * | |
| 226 * Thoughts on future direction/expansion | |
| 227 * | |
| 228 * This is a "simple" vCard. | |
| 229 * | |
| 230 * It is possible for nodes other than the "vCard" node to have | |
| 231 * attributes. Should that prove necessary/desirable, add an | |
| 232 * "attributes" pointer to the vcard_template struct, create the | |
| 233 * necessary tag_attr structs, and add 'em to the vcard_dflt_data | |
| 234 * array. | |
| 235 * | |
| 236 * The above changes will (obviously) require changes to the vCard | |
| 237 * construction routines. | |
| 238 */ | |
| 239 | |
| 240 struct vcard_template { | |
| 241 char *label; /* label text pointer */ | |
| 242 char *text; /* entry text pointer */ | |
| 243 int visible; /* should entry field be "visible?" */ | |
| 244 int editable; /* should entry field be editable? */ | |
| 245 char *tag; /* tag text */ | |
| 246 char *ptag; /* parent tag "path" text */ | |
| 247 char *url; /* vCard display format if URL */ | |
| 248 } vcard_template_data[] = { | |
| 249 {N_("Full Name"), NULL, TRUE, TRUE, "FN", NULL, NULL}, | |
| 250 {N_("Family Name"), NULL, TRUE, TRUE, "FAMILY", "N", NULL}, | |
| 251 {N_("Given Name"), NULL, TRUE, TRUE, "GIVEN", "N", NULL}, | |
| 252 {N_("Nickname"), NULL, TRUE, TRUE, "NICKNAME", NULL, NULL}, | |
| 253 {N_("URL"), NULL, TRUE, TRUE, "URL", NULL, "<A HREF=\"%s\">%s</A>"}, | |
| 254 {N_("Street Address"), NULL, TRUE, TRUE, "STREET", "ADR", NULL}, | |
| 255 {N_("Extended Address"), NULL, TRUE, TRUE, "EXTADD", "ADR", NULL}, | |
| 256 {N_("Locality"), NULL, TRUE, TRUE, "LOCALITY", "ADR", NULL}, | |
| 257 {N_("Region"), NULL, TRUE, TRUE, "REGION", "ADR", NULL}, | |
| 258 {N_("Postal Code"), NULL, TRUE, TRUE, "PCODE", "ADR", NULL}, | |
| 259 {N_("Country"), NULL, TRUE, TRUE, "COUNTRY", "ADR", NULL}, | |
| 10215 | 260 {N_("Telephone"), NULL, TRUE, TRUE, "TEL", NULL, NULL}, |
| 7014 | 261 {N_("Email"), NULL, TRUE, TRUE, "EMAIL", NULL, "<A HREF=\"mailto:%s\">%s</A>"}, |
| 262 {N_("Organization Name"), NULL, TRUE, TRUE, "ORGNAME", "ORG", NULL}, | |
| 263 {N_("Organization Unit"), NULL, TRUE, TRUE, "ORGUNIT", "ORG", NULL}, | |
| 264 {N_("Title"), NULL, TRUE, TRUE, "TITLE", NULL, NULL}, | |
| 265 {N_("Role"), NULL, TRUE, TRUE, "ROLE", NULL, NULL}, | |
| 266 {N_("Birthday"), NULL, TRUE, TRUE, "BDAY", NULL, NULL}, | |
| 267 {N_("Description"), NULL, TRUE, TRUE, "DESC", NULL, NULL}, | |
| 268 {"", NULL, TRUE, TRUE, "N", NULL, NULL}, | |
| 269 {"", NULL, TRUE, TRUE, "ADR", NULL, NULL}, | |
| 270 {"", NULL, TRUE, TRUE, "ORG", NULL, NULL}, | |
| 271 {NULL, NULL, 0, 0, NULL, NULL, NULL} | |
| 272 }; | |
| 273 | |
| 274 /* | |
|
8735
92cbf9713795
[gaim-migrate @ 9490]
Christian Hammond <chipx86@chipx86.com>
parents:
8401
diff
changeset
|
275 * The "vCard" tag's attribute list... |
| 7014 | 276 */ |
| 277 struct tag_attr { | |
| 278 char *attr; | |
| 279 char *value; | |
| 280 } vcard_tag_attr_list[] = { | |
| 281 {"prodid", "-//HandGen//NONSGML vGen v1.0//EN"}, | |
| 282 {"version", "2.0", }, | |
| 283 {"xmlns", "vcard-temp", }, | |
| 284 {NULL, NULL}, | |
| 285 }; | |
| 286 | |
| 287 | |
| 288 /* | |
| 289 * Insert a tag node into an xmlnode tree, recursively inserting parent tag | |
| 290 * nodes as necessary | |
| 291 * | |
| 292 * Returns pointer to inserted node | |
| 293 * | |
| 294 * Note to hackers: this code is designed to be re-entrant (it's recursive--it | |
| 295 * calls itself), so don't put any "static"s in here! | |
| 296 */ | |
| 297 static xmlnode *insert_tag_to_parent_tag(xmlnode *start, const char *parent_tag, const char *new_tag) | |
| 298 { | |
| 299 xmlnode *x = NULL; | |
| 300 | |
| 301 /* | |
| 302 * If the parent tag wasn't specified, see if we can get it | |
| 303 * from the vCard template struct. | |
| 304 */ | |
| 305 if(parent_tag == NULL) { | |
| 306 struct vcard_template *vc_tp = vcard_template_data; | |
| 307 | |
| 308 while(vc_tp->label != NULL) { | |
| 309 if(strcmp(vc_tp->tag, new_tag) == 0) { | |
| 310 parent_tag = vc_tp->ptag; | |
| 311 break; | |
| 312 } | |
| 313 ++vc_tp; | |
| 314 } | |
| 315 } | |
| 316 | |
| 317 /* | |
| 318 * If we have a parent tag... | |
| 319 */ | |
| 320 if(parent_tag != NULL ) { | |
| 321 /* | |
| 322 * Try to get the parent node for a tag | |
| 323 */ | |
| 324 if((x = xmlnode_get_child(start, parent_tag)) == NULL) { | |
| 325 /* | |
| 326 * Descend? | |
| 327 */ | |
| 328 char *grand_parent = g_strdup(parent_tag); | |
| 329 char *parent; | |
| 330 | |
| 331 if((parent = strrchr(grand_parent, '/')) != NULL) { | |
| 332 *(parent++) = '\0'; | |
| 333 x = insert_tag_to_parent_tag(start, grand_parent, parent); | |
| 334 } else { | |
| 335 x = xmlnode_new_child(start, grand_parent); | |
| 336 } | |
| 337 g_free(grand_parent); | |
| 338 } else { | |
| 339 /* | |
| 340 * We found *something* to be the parent node. | |
| 341 * Note: may be the "root" node! | |
| 342 */ | |
| 343 xmlnode *y; | |
| 344 if((y = xmlnode_get_child(x, new_tag)) != NULL) { | |
| 345 return(y); | |
| 346 } | |
| 347 } | |
| 348 } | |
| 349 | |
| 350 /* | |
| 351 * insert the new tag into its parent node | |
| 352 */ | |
| 353 return(xmlnode_new_child((x == NULL? start : x), new_tag)); | |
| 354 } | |
| 355 | |
| 356 /* | |
| 357 * Send vCard info to Jabber server | |
| 358 */ | |
| 359 void jabber_set_info(GaimConnection *gc, const char *info) | |
| 360 { | |
| 361 JabberIq *iq; | |
| 362 JabberStream *js = gc->proto_data; | |
| 363 xmlnode *vc_node; | |
| 10189 | 364 const char *avatar_file = NULL; |
| 7014 | 365 |
| 10189 | 366 if(js->avatar_hash) |
| 367 g_free(js->avatar_hash); | |
| 368 js->avatar_hash = NULL; | |
| 7014 | 369 |
| 370 /* | |
| 371 * Send only if there's actually any *information* to send | |
| 372 */ | |
| 373 vc_node = xmlnode_from_str(info, -1); | |
| 10189 | 374 avatar_file = gaim_account_get_buddy_icon(gc->account); |
| 375 | |
| 376 if(!vc_node && avatar_file) { | |
| 377 vc_node = xmlnode_new("vCard"); | |
| 378 } | |
| 7014 | 379 |
| 380 if(vc_node) { | |
| 381 if (vc_node->name && | |
| 10189 | 382 !g_ascii_strncasecmp(vc_node->name, "vCard", 5)) { |
| 383 GError *error = NULL; | |
| 384 char *avatar_data; | |
| 385 gsize avatar_len; | |
| 386 | |
| 387 if(avatar_file && g_file_get_contents(avatar_file, &avatar_data, &avatar_len, &error)) { | |
| 388 xmlnode *photo; | |
| 389 char *enc; | |
| 390 int i; | |
| 391 unsigned char hashval[20]; | |
| 392 char *p, hash[41]; | |
| 393 | |
| 394 photo = xmlnode_new_child(vc_node, "PHOTO"); | |
| 395 enc = gaim_base64_encode(avatar_data, avatar_len); | |
| 396 shaBlock((unsigned char *)avatar_data, avatar_len, hashval); | |
| 397 p = hash; | |
| 398 for(i=0; i<20; i++, p+=2) | |
| 399 snprintf(p, 3, "%02x", hashval[i]); | |
| 400 js->avatar_hash = g_strdup(hash); | |
| 401 | |
| 402 xmlnode_insert_data(photo, enc, -1); | |
| 403 g_free(enc); | |
| 404 g_free(avatar_data); | |
| 405 } else { | |
| 406 g_error_free(error); | |
| 407 } | |
| 408 | |
| 7014 | 409 iq = jabber_iq_new(js, JABBER_IQ_SET); |
| 410 xmlnode_insert_child(iq->node, vc_node); | |
| 411 jabber_iq_send(iq); | |
| 412 } else { | |
| 413 xmlnode_free(vc_node); | |
| 414 } | |
| 415 } | |
| 416 } | |
| 417 | |
| 10189 | 418 void jabber_set_buddy_icon(GaimConnection *gc, const char *iconfile) |
| 419 { | |
| 420 GaimPresence *gpresence; | |
| 421 GaimStatus *status; | |
| 422 | |
| 423 jabber_set_info(gc, gaim_account_get_user_info(gc->account)); | |
| 424 | |
| 425 gpresence = gaim_account_get_presence(gc->account); | |
| 426 status = gaim_presence_get_active_status(gpresence); | |
| 10216 | 427 jabber_presence_send(gc->account, status); |
| 10189 | 428 } |
| 429 | |
| 7014 | 430 /* |
| 431 * This is the callback from the "ok clicked" for "set vCard" | |
| 432 * | |
| 433 * Formats GSList data into XML-encoded string and returns a pointer | |
| 434 * to said string. | |
| 435 * | |
| 436 * g_free()'ing the returned string space is the responsibility of | |
| 437 * the caller. | |
| 438 */ | |
| 439 static void | |
| 440 jabber_format_info(GaimConnection *gc, GaimRequestFields *fields) | |
| 441 { | |
| 442 GaimAccount *account; | |
| 443 xmlnode *vc_node; | |
| 444 GaimRequestField *field; | |
| 445 const char *text; | |
| 446 char *p; | |
| 447 const struct vcard_template *vc_tp; | |
| 448 struct tag_attr *tag_attr; | |
| 449 | |
| 450 vc_node = xmlnode_new("vCard"); | |
| 451 | |
| 452 for(tag_attr = vcard_tag_attr_list; tag_attr->attr != NULL; ++tag_attr) | |
| 453 xmlnode_set_attrib(vc_node, tag_attr->attr, tag_attr->value); | |
| 454 | |
| 455 for (vc_tp = vcard_template_data; vc_tp->label != NULL; vc_tp++) { | |
| 456 if (*vc_tp->label == '\0') | |
| 457 continue; | |
| 458 | |
| 459 field = gaim_request_fields_get_field(fields, vc_tp->tag); | |
| 460 text = gaim_request_field_string_get_value(field); | |
| 461 | |
| 462 | |
| 463 if (text != NULL && *text != '\0') { | |
| 464 xmlnode *xp; | |
| 465 | |
| 9339 | 466 gaim_debug(GAIM_DEBUG_INFO, "jabber", |
| 467 "Setting %s to '%s'\n", vc_tp->tag, text); | |
| 468 | |
| 7014 | 469 if ((xp = insert_tag_to_parent_tag(vc_node, |
| 470 NULL, vc_tp->tag)) != NULL) { | |
| 471 | |
| 472 xmlnode_insert_data(xp, text, -1); | |
| 473 } | |
| 474 } | |
| 475 } | |
| 476 | |
| 7642 | 477 p = xmlnode_to_str(vc_node, NULL); |
| 7014 | 478 xmlnode_free(vc_node); |
| 479 | |
| 480 account = gaim_connection_get_account(gc); | |
| 481 | |
| 482 if (account != NULL) { | |
| 483 gaim_account_set_user_info(account, p); | |
| 484 | |
| 485 if (gc != NULL) | |
| 486 serv_set_info(gc, p); | |
| 487 } | |
| 488 | |
| 489 g_free(p); | |
| 490 } | |
| 491 | |
| 492 /* | |
| 493 * This gets executed by the proto action | |
| 494 * | |
| 495 * Creates a new GaimRequestFields struct, gets the XML-formatted user_info | |
| 496 * string (if any) into GSLists for the (multi-entry) edit dialog and | |
| 497 * calls the set_vcard dialog. | |
| 498 */ | |
| 9015 | 499 void jabber_setup_set_info(GaimPluginAction *action) |
| 7014 | 500 { |
| 9015 | 501 GaimConnection *gc = (GaimConnection *) action->context; |
| 7014 | 502 GaimRequestFields *fields; |
| 503 GaimRequestFieldGroup *group; | |
| 504 GaimRequestField *field; | |
| 505 const struct vcard_template *vc_tp; | |
| 506 char *user_info; | |
| 507 char *cdata; | |
| 508 xmlnode *x_vc_data = NULL; | |
| 509 | |
| 510 fields = gaim_request_fields_new(); | |
| 511 group = gaim_request_field_group_new(NULL); | |
| 512 gaim_request_fields_add_group(fields, group); | |
| 513 | |
| 514 /* | |
| 515 * Get existing, XML-formatted, user info | |
| 516 */ | |
| 517 if((user_info = g_strdup(gaim_account_get_user_info(gc->account))) != NULL) | |
| 518 x_vc_data = xmlnode_from_str(user_info, -1); | |
| 519 else | |
| 520 user_info = g_strdup(""); | |
| 521 | |
| 522 /* | |
| 523 * Set up GSLists for edit with labels from "template," data from user info | |
| 524 */ | |
| 525 for(vc_tp = vcard_template_data; vc_tp->label != NULL; ++vc_tp) { | |
| 526 xmlnode *data_node; | |
| 527 if((vc_tp->label)[0] == '\0') | |
| 528 continue; | |
| 529 if(vc_tp->ptag == NULL) { | |
| 530 data_node = xmlnode_get_child(x_vc_data, vc_tp->tag); | |
| 531 } else { | |
| 532 gchar *tag = g_strdup_printf("%s/%s", vc_tp->ptag, vc_tp->tag); | |
| 533 data_node = xmlnode_get_child(x_vc_data, tag); | |
| 534 g_free(tag); | |
| 535 } | |
| 536 if(data_node) | |
| 537 cdata = xmlnode_get_data(data_node); | |
| 538 else | |
| 539 cdata = NULL; | |
| 540 | |
| 541 if(strcmp(vc_tp->tag, "DESC") == 0) { | |
| 542 field = gaim_request_field_string_new(vc_tp->tag, | |
| 543 _(vc_tp->label), cdata, | |
| 544 TRUE); | |
| 545 } else { | |
| 546 field = gaim_request_field_string_new(vc_tp->tag, | |
| 547 _(vc_tp->label), cdata, | |
| 548 FALSE); | |
| 549 } | |
| 550 | |
| 551 gaim_request_field_group_add_field(group, field); | |
| 552 } | |
| 553 | |
| 554 if(x_vc_data != NULL) | |
| 555 xmlnode_free(x_vc_data); | |
| 556 | |
| 557 g_free(user_info); | |
| 558 | |
| 559 gaim_request_fields(gc, _("Edit Jabber vCard"), | |
| 560 _("Edit Jabber vCard"), | |
| 561 _("All items below are optional. Enter only the " | |
| 562 "information with which you feel comfortable."), | |
| 563 fields, | |
| 564 _("Save"), G_CALLBACK(jabber_format_info), | |
| 565 _("Cancel"), NULL, | |
| 566 gc); | |
| 567 } | |
| 568 | |
| 569 /*---------------------------------------*/ | |
| 570 /* End Jabber "set info" (vCard) support */ | |
| 571 /*---------------------------------------*/ | |
| 572 | |
| 573 /****** | |
| 574 * end of that ancient crap that needs to die | |
| 575 ******/ | |
| 576 | |
| 577 | |
| 7395 | 578 static void jabber_vcard_parse(JabberStream *js, xmlnode *packet, gpointer data) |
| 7014 | 579 { |
| 580 GList *resources; | |
| 581 const char *from = xmlnode_get_attrib(packet, "from"); | |
| 582 JabberBuddy *jb; | |
| 583 JabberBuddyResource *jbr; | |
| 584 GString *info_text; | |
| 7306 | 585 char *resource_name; |
| 7955 | 586 char *bare_jid; |
| 7014 | 587 char *title; |
| 8213 | 588 char *text; |
| 7014 | 589 xmlnode *vcard; |
| 7955 | 590 GaimBuddy *b; |
| 10189 | 591 GSList *imgids = NULL; |
| 7014 | 592 |
| 593 if(!from) | |
| 594 return; | |
| 595 | |
| 596 resource_name = jabber_get_resource(from); | |
| 7955 | 597 bare_jid = jabber_get_bare_jid(from); |
| 598 | |
| 599 b = gaim_find_buddy(js->gc->account, bare_jid); | |
| 7014 | 600 |
| 601 jb = jabber_buddy_find(js, from, TRUE); | |
| 602 info_text = g_string_new(""); | |
| 603 | |
| 8213 | 604 g_string_append_printf(info_text, "<b>%s:</b> %s<br/>", _("Jabber ID"), |
| 7014 | 605 from); |
| 606 | |
| 607 if(resource_name) { | |
| 608 jbr = jabber_buddy_find_resource(jb, resource_name); | |
| 609 if(jbr) { | |
| 7145 | 610 char *purdy = NULL; |
| 611 if(jbr->status) | |
| 612 purdy = gaim_strdup_withhtml(jbr->status); | |
| 8213 | 613 g_string_append_printf(info_text, "<b>%s:</b> %s%s%s<br/>", |
| 9954 | 614 _("Status"), jabber_buddy_state_get_name(jbr->state), |
| 7014 | 615 purdy ? ": " : "", |
| 616 purdy ? purdy : ""); | |
| 7145 | 617 if(purdy) |
| 618 g_free(purdy); | |
| 7014 | 619 } else { |
| 8213 | 620 g_string_append_printf(info_text, "<b>%s:</b> %s<br/>", |
| 7014 | 621 _("Status"), _("Unknown")); |
| 622 } | |
| 623 } else { | |
| 624 for(resources = jb->resources; resources; resources = resources->next) { | |
| 7145 | 625 char *purdy = NULL; |
| 7014 | 626 jbr = resources->data; |
| 7145 | 627 if(jbr->status) |
| 628 purdy = gaim_strdup_withhtml(jbr->status); | |
| 8213 | 629 g_string_append_printf(info_text, "<b>%s:</b> %s<br/>", |
| 7014 | 630 _("Resource"), jbr->name); |
| 8213 | 631 g_string_append_printf(info_text, "<b>%s:</b> %s%s%s<br/><br/>", |
| 9954 | 632 _("Status"), jabber_buddy_state_get_name(jbr->state), |
| 7014 | 633 purdy ? ": " : "", |
| 634 purdy ? purdy : ""); | |
| 7145 | 635 if(purdy) |
| 636 g_free(purdy); | |
| 7014 | 637 } |
| 638 } | |
| 639 | |
| 7306 | 640 g_free(resource_name); |
| 641 | |
| 10189 | 642 if((vcard = xmlnode_get_child(packet, "vCard")) || |
| 643 (vcard = xmlnode_get_child_with_namespace(packet, "query", "vcard-temp"))) { | |
| 7014 | 644 xmlnode *child; |
| 645 for(child = vcard->child; child; child = child->next) | |
| 646 { | |
| 647 xmlnode *child2; | |
| 648 | |
| 8135 | 649 if(child->type != XMLNODE_TYPE_TAG) |
| 7014 | 650 continue; |
| 651 | |
| 652 text = xmlnode_get_data(child); | |
| 653 if(text && !strcmp(child->name, "FN")) { | |
| 8213 | 654 g_string_append_printf(info_text, "<b>%s:</b> %s<br/>", |
| 7014 | 655 _("Full Name"), text); |
| 656 } else if(!strcmp(child->name, "N")) { | |
| 657 for(child2 = child->child; child2; child2 = child2->next) | |
| 658 { | |
| 659 char *text2; | |
| 660 | |
| 8135 | 661 if(child2->type != XMLNODE_TYPE_TAG) |
| 7014 | 662 continue; |
| 663 | |
| 664 text2 = xmlnode_get_data(child2); | |
| 665 if(text2 && !strcmp(child2->name, "FAMILY")) { | |
| 666 g_string_append_printf(info_text, | |
| 8213 | 667 "<b>%s:</b> %s<br/>", |
| 7014 | 668 _("Family Name"), text2); |
| 669 } else if(text2 && !strcmp(child2->name, "GIVEN")) { | |
| 670 g_string_append_printf(info_text, | |
| 8213 | 671 "<b>%s:</b> %s<br/>", |
| 7014 | 672 _("Given Name"), text2); |
| 673 } else if(text2 && !strcmp(child2->name, "MIDDLE")) { | |
| 674 g_string_append_printf(info_text, | |
| 8213 | 675 "<b>%s:</b> %s<br/>", |
| 7014 | 676 _("Middle Name"), text2); |
| 677 } | |
| 678 g_free(text2); | |
| 679 } | |
| 680 } else if(text && !strcmp(child->name, "NICKNAME")) { | |
| 681 serv_got_alias(js->gc, from, text); | |
| 7955 | 682 if(b) { |
| 683 gaim_blist_node_set_string((GaimBlistNode*)b, "servernick", text); | |
| 684 } | |
| 8213 | 685 g_string_append_printf(info_text, "<b>%s:</b> %s<br/>", |
| 7014 | 686 _("Nickname"), text); |
| 687 } else if(text && !strcmp(child->name, "BDAY")) { | |
| 8213 | 688 g_string_append_printf(info_text, "<b>%s:</b> %s<br/>", |
| 7014 | 689 _("Birthday"), text); |
| 690 } else if(!strcmp(child->name, "ADR")) { | |
| 691 /* show which address it is */ | |
| 692 if(child->child) | |
| 8213 | 693 g_string_append_printf(info_text, "<b>%s:</b><br/>", |
| 7014 | 694 _("Address")); |
| 695 for(child2 = child->child; child2; child2 = child2->next) | |
| 696 { | |
| 697 char *text2; | |
| 698 | |
| 8135 | 699 if(child2->type != XMLNODE_TYPE_TAG) |
| 7014 | 700 continue; |
| 701 | |
| 702 text2 = xmlnode_get_data(child2); | |
| 703 if(text2 && !strcmp(child2->name, "POBOX")) { | |
| 704 g_string_append_printf(info_text, | |
| 8213 | 705 " <b>%s:</b> %s<br/>", |
| 7014 | 706 _("P.O. Box"), text2); |
| 707 } else if(text2 && !strcmp(child2->name, "EXTADR")) { | |
| 708 g_string_append_printf(info_text, | |
| 8213 | 709 " <b>%s:</b> %s<br/>", |
| 7014 | 710 _("Extended Address"), text2); |
| 711 } else if(text2 && !strcmp(child2->name, "STREET")) { | |
| 712 g_string_append_printf(info_text, | |
| 8213 | 713 " <b>%s:</b> %s<br/>", |
| 7014 | 714 _("Street Address"), text2); |
| 715 } else if(text2 && !strcmp(child2->name, "LOCALITY")) { | |
| 716 g_string_append_printf(info_text, | |
| 8213 | 717 " <b>%s:</b> %s<br/>", |
| 7014 | 718 _("Locality"), text2); |
| 719 } else if(text2 && !strcmp(child2->name, "REGION")) { | |
| 720 g_string_append_printf(info_text, | |
| 8213 | 721 " <b>%s:</b> %s<br/>", |
| 7014 | 722 _("Region"), text2); |
| 723 } else if(text2 && !strcmp(child2->name, "PCODE")) { | |
| 724 g_string_append_printf(info_text, | |
| 8213 | 725 " <b>%s:</b> %s<br/>", |
| 7014 | 726 _("Postal Code"), text2); |
| 727 } else if(text2 && (!strcmp(child2->name, "CTRY") | |
| 728 || !strcmp(child2->name, "COUNTRY"))) { | |
| 729 g_string_append_printf(info_text, | |
| 8213 | 730 " <b>%s:</b> %s<br/>", |
| 7014 | 731 _("Country"), text2); |
| 732 } | |
| 733 g_free(text2); | |
| 734 } | |
| 735 } else if(!strcmp(child->name, "TEL")) { | |
| 736 char *number; | |
| 737 if((child2 = xmlnode_get_child(child, "NUMBER"))) { | |
| 738 /* show what kind of number it is */ | |
| 739 number = xmlnode_get_data(child2); | |
| 740 if(number) { | |
| 741 g_string_append_printf(info_text, | |
| 8213 | 742 "<b>%s:</b> %s<br/>", _("Telephone"), number); |
| 7014 | 743 g_free(number); |
| 744 } | |
| 745 } else if((number = xmlnode_get_data(child))) { | |
| 746 /* lots of clients (including gaim) do this, but it's | |
| 747 * out of spec */ | |
| 748 g_string_append_printf(info_text, | |
| 8213 | 749 "<b>%s:</b> %s<br/>", _("Telephone"), number); |
| 7014 | 750 g_free(number); |
| 751 } | |
| 752 } else if(!strcmp(child->name, "EMAIL")) { | |
| 753 char *userid; | |
| 754 if((child2 = xmlnode_get_child(child, "USERID"))) { | |
| 755 /* show what kind of email it is */ | |
| 756 userid = xmlnode_get_data(child2); | |
| 757 if(userid) { | |
| 758 g_string_append_printf(info_text, | |
| 8213 | 759 "<b>%s:</b> <a href='mailto:%s'>%s</a><br/>", |
| 7014 | 760 _("Email"), userid, userid); |
| 761 g_free(userid); | |
| 762 } | |
| 763 } else if((userid = xmlnode_get_data(child))) { | |
| 764 /* lots of clients (including gaim) do this, but it's | |
| 765 * out of spec */ | |
| 766 g_string_append_printf(info_text, | |
| 8213 | 767 "<b>%s:</b> <a href='mailto:%s'>%s</a><br/>", |
| 7014 | 768 _("Email"), userid, userid); |
| 769 g_free(userid); | |
| 770 } | |
| 771 } else if(!strcmp(child->name, "ORG")) { | |
| 772 for(child2 = child->child; child2; child2 = child2->next) | |
| 773 { | |
| 774 char *text2; | |
| 775 | |
| 8135 | 776 if(child2->type != XMLNODE_TYPE_TAG) |
| 7014 | 777 continue; |
| 778 | |
| 779 text2 = xmlnode_get_data(child2); | |
| 780 if(text2 && !strcmp(child2->name, "ORGNAME")) { | |
| 781 g_string_append_printf(info_text, | |
| 8213 | 782 "<b>%s:</b> %s<br/>", |
| 7014 | 783 _("Organization Name"), text2); |
| 784 } else if(text2 && !strcmp(child2->name, "ORGUNIT")) { | |
| 785 g_string_append_printf(info_text, | |
| 8213 | 786 "<b>%s:</b> %s<br/>", |
| 7014 | 787 _("Organization Unit"), text2); |
| 788 } | |
| 789 g_free(text2); | |
| 790 } | |
| 791 } else if(text && !strcmp(child->name, "TITLE")) { | |
| 8213 | 792 g_string_append_printf(info_text, "<b>%s:</b> %s<br/>", |
| 7014 | 793 _("Title"), text); |
| 794 } else if(text && !strcmp(child->name, "ROLE")) { | |
| 8213 | 795 g_string_append_printf(info_text, "<b>%s:</b> %s<br/>", |
| 7014 | 796 _("Role"), text); |
| 797 } else if(text && !strcmp(child->name, "DESC")) { | |
| 8213 | 798 g_string_append_printf(info_text, "<b>%s:</b> %s<br/>", |
| 799 _("Description"), text); | |
| 7076 | 800 } else if(!strcmp(child->name, "PHOTO") || |
| 801 !strcmp(child->name, "LOGO")) { | |
| 10189 | 802 int size, i; |
| 803 unsigned char hashval[20]; | |
| 804 char *data, *p, hash[41]; | |
| 805 gboolean photo = (strcmp(child->name, "PHOTO") == 0); | |
| 806 | |
| 807 gaim_base64_decode(text, &data, &size); | |
| 7076 | 808 |
| 10189 | 809 imgids = g_slist_prepend(imgids, GINT_TO_POINTER(gaim_imgstore_add(data, size, "logo.png"))); |
| 810 g_string_append_printf(info_text, | |
| 811 "<b>%s:</b> <img id='%d'><br/>", | |
| 812 photo ? _("Photo") : _("Logo"), | |
| 813 GPOINTER_TO_INT(imgids->data)); | |
| 7076 | 814 |
| 10189 | 815 gaim_buddy_icons_set_for_user(js->gc->account, bare_jid, |
| 816 data, size); | |
| 817 | |
| 818 shaBlock((unsigned char *)data, size, hashval); | |
| 819 p = hash; | |
| 820 for(i=0; i<20; i++, p+=2) | |
| 821 snprintf(p, 3, "%02x", hashval[i]); | |
| 822 gaim_blist_node_set_string((GaimBlistNode*)b, "avatar_hash", hash); | |
| 823 | |
| 824 g_free(data); | |
| 7014 | 825 } |
| 826 g_free(text); | |
| 827 } | |
| 828 } | |
| 829 | |
| 830 title = g_strdup_printf("User info for %s", from); | |
| 831 | |
| 8213 | 832 text = gaim_strdup_withhtml(info_text->str); |
| 833 | |
| 9797 | 834 gaim_notify_userinfo(js->gc, from, title, _("Jabber Profile"), |
| 8213 | 835 NULL, text, NULL, NULL); |
| 7014 | 836 |
| 10189 | 837 while(imgids) { |
| 838 gaim_imgstore_unref(GPOINTER_TO_INT(imgids->data)); | |
| 839 imgids = g_slist_delete_link(imgids, imgids); | |
| 840 } | |
| 7014 | 841 g_free(title); |
| 842 g_string_free(info_text, TRUE); | |
| 8213 | 843 g_free(text); |
| 10189 | 844 g_free(bare_jid); |
| 7014 | 845 } |
| 846 | |
| 10189 | 847 static void jabber_buddy_get_info_for_jid(JabberStream *js, const char *full_jid) |
| 7014 | 848 { |
| 849 JabberIq *iq; | |
| 850 xmlnode *vcard; | |
| 851 | |
| 852 iq = jabber_iq_new(js, JABBER_IQ_GET); | |
| 853 | |
| 10189 | 854 xmlnode_set_attrib(iq->node, "to", full_jid); |
| 7014 | 855 vcard = xmlnode_new_child(iq->node, "vCard"); |
| 856 xmlnode_set_attrib(vcard, "xmlns", "vcard-temp"); | |
| 857 | |
| 7395 | 858 jabber_iq_set_callback(iq, jabber_vcard_parse, NULL); |
| 7014 | 859 |
| 860 jabber_iq_send(iq); | |
| 861 } | |
| 862 | |
| 10189 | 863 void jabber_buddy_get_info(GaimConnection *gc, const char *who) |
| 864 { | |
| 865 JabberStream *js = gc->proto_data; | |
| 866 char *bare_jid = jabber_get_bare_jid(who); | |
| 867 | |
| 868 if(bare_jid) { | |
| 869 jabber_buddy_get_info_for_jid(js, bare_jid); | |
| 870 g_free(bare_jid); | |
| 871 } | |
| 872 } | |
| 873 | |
| 7014 | 874 void jabber_buddy_get_info_chat(GaimConnection *gc, int id, |
| 875 const char *resource) | |
| 876 { | |
| 877 JabberStream *js = gc->proto_data; | |
| 878 JabberChat *chat = jabber_chat_find_by_id(js, id); | |
| 879 char *full_jid; | |
| 880 | |
| 881 if(!chat) | |
| 882 return; | |
| 883 | |
| 884 full_jid = g_strdup_printf("%s@%s/%s", chat->room, chat->server, resource); | |
| 10189 | 885 jabber_buddy_get_info_for_jid(js, full_jid); |
| 7014 | 886 g_free(full_jid); |
| 887 } | |
| 888 | |
| 7395 | 889 |
| 7014 | 890 static void jabber_buddy_set_invisibility(JabberStream *js, const char *who, |
| 891 gboolean invisible) | |
| 892 { | |
| 9944 | 893 GaimPresence *gpresence; |
| 894 GaimAccount *account; | |
| 895 GaimStatus *status; | |
| 7014 | 896 JabberBuddy *jb = jabber_buddy_find(js, who, TRUE); |
| 897 xmlnode *presence; | |
| 9954 | 898 JabberBuddyState state; |
| 899 const char *msg; | |
| 900 int priority; | |
| 7014 | 901 |
| 9944 | 902 account = gaim_connection_get_account(js->gc); |
| 903 gpresence = gaim_account_get_presence(account); | |
| 904 status = gaim_presence_get_active_status(gpresence); | |
| 905 | |
| 9954 | 906 gaim_status_to_jabber(status, &state, &msg, &priority); |
| 907 presence = jabber_presence_create(state, msg, priority); | |
| 908 | |
| 7014 | 909 xmlnode_set_attrib(presence, "to", who); |
| 910 if(invisible) { | |
| 911 xmlnode_set_attrib(presence, "type", "invisible"); | |
| 912 jb->invisible |= JABBER_INVIS_BUDDY; | |
| 913 } else { | |
| 914 jb->invisible &= ~JABBER_INVIS_BUDDY; | |
| 915 } | |
| 916 | |
| 917 jabber_send(js, presence); | |
| 918 xmlnode_free(presence); | |
| 919 } | |
| 920 | |
| 9030 | 921 static void jabber_buddy_make_invisible(GaimBlistNode *node, gpointer data) |
| 7014 | 922 { |
| 9030 | 923 GaimBuddy *buddy; |
| 924 GaimConnection *gc; | |
| 925 JabberStream *js; | |
| 926 | |
| 927 g_return_if_fail(GAIM_BLIST_NODE_IS_BUDDY(node)); | |
| 928 | |
| 929 buddy = (GaimBuddy *) node; | |
| 930 gc = gaim_account_get_connection(buddy->account); | |
| 931 js = gc->proto_data; | |
| 932 | |
| 933 jabber_buddy_set_invisibility(js, buddy->name, TRUE); | |
| 7014 | 934 } |
| 935 | |
| 9030 | 936 static void jabber_buddy_make_visible(GaimBlistNode *node, gpointer data) |
| 7014 | 937 { |
| 9030 | 938 GaimBuddy *buddy; |
| 939 GaimConnection *gc; | |
| 940 JabberStream *js; | |
| 7014 | 941 |
| 9030 | 942 g_return_if_fail(GAIM_BLIST_NODE_IS_BUDDY(node)); |
| 7014 | 943 |
| 9030 | 944 buddy = (GaimBuddy *) node; |
| 945 gc = gaim_account_get_connection(buddy->account); | |
| 946 js = gc->proto_data; | |
| 947 | |
| 948 jabber_buddy_set_invisibility(js, buddy->name, FALSE); | |
| 7014 | 949 } |
| 950 | |
| 9030 | 951 static void jabber_buddy_cancel_presence_notification(GaimBlistNode *node, |
| 952 gpointer data) | |
| 7014 | 953 { |
| 9030 | 954 GaimBuddy *buddy; |
| 955 GaimConnection *gc; | |
| 956 JabberStream *js; | |
| 957 | |
| 958 g_return_if_fail(GAIM_BLIST_NODE_IS_BUDDY(node)); | |
| 7014 | 959 |
| 9030 | 960 buddy = (GaimBuddy *) node; |
| 961 gc = gaim_account_get_connection(buddy->account); | |
| 962 js = gc->proto_data; | |
| 963 | |
| 964 /* I wonder if we should prompt the user before doing this */ | |
| 965 jabber_presence_subscription_set(js, buddy->name, "unsubscribed"); | |
| 7014 | 966 } |
| 967 | |
| 9030 | 968 static void jabber_buddy_rerequest_auth(GaimBlistNode *node, gpointer data) |
| 7250 | 969 { |
| 9030 | 970 GaimBuddy *buddy; |
| 971 GaimConnection *gc; | |
| 972 JabberStream *js; | |
| 973 | |
| 974 g_return_if_fail(GAIM_BLIST_NODE_IS_BUDDY(node)); | |
| 7250 | 975 |
| 9030 | 976 buddy = (GaimBuddy *) node; |
| 977 gc = gaim_account_get_connection(buddy->account); | |
| 978 js = gc->proto_data; | |
| 979 | |
| 980 jabber_presence_subscription_set(js, buddy->name, "subscribe"); | |
| 7250 | 981 } |
| 982 | |
| 9030 | 983 |
| 984 static void jabber_buddy_unsubscribe(GaimBlistNode *node, gpointer data) | |
| 7014 | 985 { |
| 9030 | 986 GaimBuddy *buddy; |
| 987 GaimConnection *gc; | |
| 988 JabberStream *js; | |
| 989 | |
| 990 g_return_if_fail(GAIM_BLIST_NODE_IS_BUDDY(node)); | |
| 991 | |
| 992 buddy = (GaimBuddy *) node; | |
| 993 gc = gaim_account_get_connection(buddy->account); | |
| 994 js = gc->proto_data; | |
| 995 | |
| 996 jabber_presence_subscription_set(js, buddy->name, "unsubscribe"); | |
| 997 } | |
| 998 | |
| 999 | |
| 1000 GList *jabber_buddy_menu(GaimBuddy *buddy) | |
| 1001 { | |
| 1002 GaimConnection *gc = gaim_account_get_connection(buddy->account); | |
| 1003 JabberStream *js = gc->proto_data; | |
| 1004 JabberBuddy *jb = jabber_buddy_find(js, buddy->name, TRUE); | |
| 1005 | |
| 7014 | 1006 GList *m = NULL; |
| 9030 | 1007 GaimBlistNodeAction *act; |
| 7395 | 1008 |
| 1009 if(!jb) | |
| 1010 return m; | |
| 1011 | |
| 8185 | 1012 /* XXX: fix the NOT ME below */ |
| 1013 | |
| 1014 if(js->protocol_version == JABBER_PROTO_0_9 /* && NOT ME */) { | |
| 8166 | 1015 if(jb->invisible & JABBER_INVIS_BUDDY) { |
| 9030 | 1016 act = gaim_blist_node_action_new(_("Un-hide From"), |
| 1017 jabber_buddy_make_visible, NULL); | |
| 8166 | 1018 } else { |
| 9030 | 1019 act = gaim_blist_node_action_new(_("Temporarily Hide From"), |
| 1020 jabber_buddy_make_invisible, NULL); | |
| 8166 | 1021 } |
| 9030 | 1022 m = g_list_append(m, act); |
| 7014 | 1023 } |
| 1024 | |
| 8185 | 1025 if(jb->subscription & JABBER_SUB_FROM /* && NOT ME */) { |
| 9030 | 1026 act = gaim_blist_node_action_new(_("Cancel Presence Notification"), |
| 1027 jabber_buddy_cancel_presence_notification, NULL); | |
| 1028 m = g_list_append(m, act); | |
| 7014 | 1029 } |
| 1030 | |
| 1031 if(!(jb->subscription & JABBER_SUB_TO)) { | |
| 9030 | 1032 act = gaim_blist_node_action_new(_("(Re-)Request authorization"), |
| 1033 jabber_buddy_rerequest_auth, NULL); | |
| 1034 m = g_list_append(m, act); | |
| 1035 | |
| 8185 | 1036 } else /* if(NOT ME) */{ |
| 9030 | 1037 |
| 1038 /* shouldn't this just happen automatically when the buddy is | |
| 1039 removed? */ | |
| 1040 act = gaim_blist_node_action_new(_("Unsubscribe"), | |
| 1041 jabber_buddy_unsubscribe, NULL); | |
| 1042 m = g_list_append(m, act); | |
| 7014 | 1043 } |
| 1044 | |
| 1045 return m; | |
| 1046 } | |
| 9030 | 1047 |
| 1048 GList * | |
| 1049 jabber_blist_node_menu(GaimBlistNode *node) | |
| 1050 { | |
| 1051 if(GAIM_BLIST_NODE_IS_BUDDY(node)) { | |
| 1052 return jabber_buddy_menu((GaimBuddy *) node); | |
| 1053 } else { | |
| 1054 return NULL; | |
| 1055 } | |
| 1056 } | |
| 1057 | |
| 1058 | |
| 9954 | 1059 const char * |
| 1060 jabber_buddy_state_get_name(JabberBuddyState state) | |
| 1061 { | |
| 1062 switch(state) { | |
| 1063 case JABBER_BUDDY_STATE_UNKNOWN: | |
| 1064 return _("Unknown"); | |
| 1065 case JABBER_BUDDY_STATE_ERROR: | |
| 1066 return _("Error"); | |
| 1067 case JABBER_BUDDY_STATE_UNAVAILABLE: | |
| 1068 return _("Offline"); | |
| 1069 case JABBER_BUDDY_STATE_ONLINE: | |
| 1070 return _("Online"); | |
| 1071 case JABBER_BUDDY_STATE_CHAT: | |
| 1072 return _("Chatty"); | |
| 1073 case JABBER_BUDDY_STATE_AWAY: | |
| 1074 return _("Away"); | |
| 1075 case JABBER_BUDDY_STATE_XA: | |
| 1076 return _("Extended Away"); | |
| 1077 case JABBER_BUDDY_STATE_DND: | |
| 1078 return _("Do Not Disturb"); | |
| 1079 } | |
| 1080 | |
| 1081 return _("Unknown"); | |
| 1082 } | |
| 1083 | |
| 1084 JabberBuddyState jabber_buddy_status_id_get_state(const char *id) { | |
| 1085 if(!id) | |
| 1086 return JABBER_BUDDY_STATE_UNKNOWN; | |
| 1087 if(!strcmp(id, "online")) | |
| 1088 return JABBER_BUDDY_STATE_ONLINE; | |
| 1089 if(!strcmp(id, "chat")) | |
| 1090 return JABBER_BUDDY_STATE_CHAT; | |
| 1091 if(!strcmp(id, "away")) | |
| 1092 return JABBER_BUDDY_STATE_AWAY; | |
| 1093 if(!strcmp(id, "xa")) | |
| 1094 return JABBER_BUDDY_STATE_XA; | |
| 1095 if(!strcmp(id, "dnd")) | |
| 1096 return JABBER_BUDDY_STATE_DND; | |
| 1097 if(!strcmp(id, "offline")) | |
| 1098 return JABBER_BUDDY_STATE_UNAVAILABLE; | |
| 1099 if(!strcmp(id, "error")) | |
| 1100 return JABBER_BUDDY_STATE_ERROR; | |
| 1101 | |
| 1102 return JABBER_BUDDY_STATE_UNKNOWN; | |
| 1103 } | |
| 1104 | |
| 1105 const char *jabber_buddy_state_get_status_id(JabberBuddyState state) { | |
| 1106 switch(state) { | |
| 1107 case JABBER_BUDDY_STATE_CHAT: | |
| 1108 return "chat"; | |
| 1109 case JABBER_BUDDY_STATE_AWAY: | |
| 1110 return "away"; | |
| 1111 case JABBER_BUDDY_STATE_XA: | |
| 1112 return "xa"; | |
| 1113 case JABBER_BUDDY_STATE_DND: | |
| 1114 return "dnd"; | |
| 1115 case JABBER_BUDDY_STATE_ONLINE: | |
| 1116 return "online"; | |
| 1117 case JABBER_BUDDY_STATE_UNKNOWN: | |
| 1118 case JABBER_BUDDY_STATE_ERROR: | |
| 1119 return NULL; | |
| 1120 case JABBER_BUDDY_STATE_UNAVAILABLE: | |
| 1121 return "offline"; | |
| 1122 } | |
| 1123 return NULL; | |
| 1124 } |
