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