Mercurial > pidgin
annotate src/protocols/jabber/buddy.c @ 12264:2be62353f708
[gaim-migrate @ 14566]
this was TRUE in oldstatus
committer: Tailor Script <tailor@pidgin.im>
| author | Nathan Walp <nwalp@pidgin.im> |
|---|---|
| date | Tue, 29 Nov 2005 23:50:39 +0000 |
| parents | 828802f2251b |
| children | ecd471d1eeec |
| 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" | |
|
10684
72a5babfa8b4
[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 | 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" | |
| 11675 | 36 #include "xdata.h" |
| 7014 | 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}, | |
| 11361 | 260 {N_("Telephone"), NULL, TRUE, TRUE, "NUMBER", "TEL", NULL}, |
| 261 {N_("Email"), NULL, TRUE, TRUE, "USERID", "EMAIL", "<A HREF=\"mailto:%s\">%s</A>"}, | |
| 7014 | 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; | |
|
11303
10066662176a
[gaim-migrate @ 13503]
Richard Laager <rlaager@wiktel.com>
parents:
11183
diff
changeset
|
364 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 */ | |
| 11388 | 373 vc_node = info ? xmlnode_from_str(info, -1) : NULL; |
| 11318 | 374 avatar_file = gaim_buddy_icons_get_full_path(gaim_account_get_buddy_icon(gc->account)); |
| 10189 | 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; | |
| 11509 | 384 gchar *avatar_data_tmp; |
| 385 guchar *avatar_data; | |
| 10189 | 386 gsize avatar_len; |
| 387 | |
| 11509 | 388 if(avatar_file && g_file_get_contents(avatar_file, &avatar_data_tmp, &avatar_len, &error)) { |
| 10941 | 389 xmlnode *photo, *binval; |
| 11127 | 390 gchar *enc; |
| 10189 | 391 int i; |
| 392 unsigned char hashval[20]; | |
| 393 char *p, hash[41]; | |
| 394 | |
| 11521 | 395 avatar_data = (guchar *) avatar_data_tmp; |
| 10189 | 396 photo = xmlnode_new_child(vc_node, "PHOTO"); |
| 10941 | 397 binval = xmlnode_new_child(photo, "BINVAL"); |
| 10189 | 398 enc = gaim_base64_encode(avatar_data, avatar_len); |
|
10684
72a5babfa8b4
[gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
10662
diff
changeset
|
399 |
| 11183 | 400 gaim_cipher_digest_region("sha1", (guchar *)avatar_data, |
|
10687
b256ce6b85b8
[gaim-migrate @ 12235]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10684
diff
changeset
|
401 avatar_len, sizeof(hashval), |
|
b256ce6b85b8
[gaim-migrate @ 12235]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10684
diff
changeset
|
402 hashval, NULL); |
|
10684
72a5babfa8b4
[gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
10662
diff
changeset
|
403 |
| 10189 | 404 p = hash; |
| 405 for(i=0; i<20; i++, p+=2) | |
| 406 snprintf(p, 3, "%02x", hashval[i]); | |
| 407 js->avatar_hash = g_strdup(hash); | |
| 408 | |
| 10941 | 409 xmlnode_insert_data(binval, enc, -1); |
| 10189 | 410 g_free(enc); |
| 411 g_free(avatar_data); | |
| 10504 | 412 } else if (error != NULL) { |
| 10189 | 413 g_error_free(error); |
| 414 } | |
|
11303
10066662176a
[gaim-migrate @ 13503]
Richard Laager <rlaager@wiktel.com>
parents:
11183
diff
changeset
|
415 g_free(avatar_file); |
| 10189 | 416 |
| 7014 | 417 iq = jabber_iq_new(js, JABBER_IQ_SET); |
| 418 xmlnode_insert_child(iq->node, vc_node); | |
| 419 jabber_iq_send(iq); | |
| 420 } else { | |
| 421 xmlnode_free(vc_node); | |
| 422 } | |
| 423 } | |
| 424 } | |
| 425 | |
| 10189 | 426 void jabber_set_buddy_icon(GaimConnection *gc, const char *iconfile) |
| 427 { | |
| 428 GaimPresence *gpresence; | |
| 429 GaimStatus *status; | |
| 430 | |
| 431 jabber_set_info(gc, gaim_account_get_user_info(gc->account)); | |
| 432 | |
| 433 gpresence = gaim_account_get_presence(gc->account); | |
| 434 status = gaim_presence_get_active_status(gpresence); | |
| 10216 | 435 jabber_presence_send(gc->account, status); |
| 10189 | 436 } |
| 437 | |
| 7014 | 438 /* |
| 439 * This is the callback from the "ok clicked" for "set vCard" | |
| 440 * | |
| 441 * Formats GSList data into XML-encoded string and returns a pointer | |
| 442 * to said string. | |
| 443 * | |
| 444 * g_free()'ing the returned string space is the responsibility of | |
| 445 * the caller. | |
| 446 */ | |
| 447 static void | |
| 448 jabber_format_info(GaimConnection *gc, GaimRequestFields *fields) | |
| 449 { | |
| 450 GaimAccount *account; | |
| 451 xmlnode *vc_node; | |
| 452 GaimRequestField *field; | |
| 453 const char *text; | |
| 454 char *p; | |
| 455 const struct vcard_template *vc_tp; | |
| 456 struct tag_attr *tag_attr; | |
| 457 | |
| 458 vc_node = xmlnode_new("vCard"); | |
| 459 | |
| 460 for(tag_attr = vcard_tag_attr_list; tag_attr->attr != NULL; ++tag_attr) | |
| 461 xmlnode_set_attrib(vc_node, tag_attr->attr, tag_attr->value); | |
| 462 | |
| 463 for (vc_tp = vcard_template_data; vc_tp->label != NULL; vc_tp++) { | |
| 464 if (*vc_tp->label == '\0') | |
| 465 continue; | |
| 466 | |
| 467 field = gaim_request_fields_get_field(fields, vc_tp->tag); | |
| 468 text = gaim_request_field_string_get_value(field); | |
| 469 | |
| 470 | |
| 471 if (text != NULL && *text != '\0') { | |
| 472 xmlnode *xp; | |
| 473 | |
| 9339 | 474 gaim_debug(GAIM_DEBUG_INFO, "jabber", |
| 475 "Setting %s to '%s'\n", vc_tp->tag, text); | |
| 476 | |
| 7014 | 477 if ((xp = insert_tag_to_parent_tag(vc_node, |
| 478 NULL, vc_tp->tag)) != NULL) { | |
| 479 | |
| 480 xmlnode_insert_data(xp, text, -1); | |
| 481 } | |
| 482 } | |
| 483 } | |
| 484 | |
| 7642 | 485 p = xmlnode_to_str(vc_node, NULL); |
| 7014 | 486 xmlnode_free(vc_node); |
| 487 | |
| 488 account = gaim_connection_get_account(gc); | |
| 489 | |
| 490 if (account != NULL) { | |
| 491 gaim_account_set_user_info(account, p); | |
| 492 | |
| 493 if (gc != NULL) | |
| 494 serv_set_info(gc, p); | |
| 495 } | |
| 496 | |
| 497 g_free(p); | |
| 498 } | |
| 499 | |
| 500 /* | |
| 501 * This gets executed by the proto action | |
| 502 * | |
| 503 * Creates a new GaimRequestFields struct, gets the XML-formatted user_info | |
| 504 * string (if any) into GSLists for the (multi-entry) edit dialog and | |
| 505 * calls the set_vcard dialog. | |
| 506 */ | |
| 9015 | 507 void jabber_setup_set_info(GaimPluginAction *action) |
| 7014 | 508 { |
| 9015 | 509 GaimConnection *gc = (GaimConnection *) action->context; |
| 7014 | 510 GaimRequestFields *fields; |
| 511 GaimRequestFieldGroup *group; | |
| 512 GaimRequestField *field; | |
| 513 const struct vcard_template *vc_tp; | |
| 514 char *user_info; | |
| 515 char *cdata; | |
| 516 xmlnode *x_vc_data = NULL; | |
| 517 | |
| 518 fields = gaim_request_fields_new(); | |
| 519 group = gaim_request_field_group_new(NULL); | |
| 520 gaim_request_fields_add_group(fields, group); | |
| 521 | |
| 522 /* | |
| 523 * Get existing, XML-formatted, user info | |
| 524 */ | |
| 525 if((user_info = g_strdup(gaim_account_get_user_info(gc->account))) != NULL) | |
| 526 x_vc_data = xmlnode_from_str(user_info, -1); | |
| 527 else | |
| 528 user_info = g_strdup(""); | |
| 529 | |
| 530 /* | |
| 531 * Set up GSLists for edit with labels from "template," data from user info | |
| 532 */ | |
| 533 for(vc_tp = vcard_template_data; vc_tp->label != NULL; ++vc_tp) { | |
| 534 xmlnode *data_node; | |
| 535 if((vc_tp->label)[0] == '\0') | |
| 536 continue; | |
| 537 if(vc_tp->ptag == NULL) { | |
| 538 data_node = xmlnode_get_child(x_vc_data, vc_tp->tag); | |
| 539 } else { | |
| 540 gchar *tag = g_strdup_printf("%s/%s", vc_tp->ptag, vc_tp->tag); | |
| 541 data_node = xmlnode_get_child(x_vc_data, tag); | |
| 542 g_free(tag); | |
| 543 } | |
| 544 if(data_node) | |
| 545 cdata = xmlnode_get_data(data_node); | |
| 546 else | |
| 547 cdata = NULL; | |
| 548 | |
| 549 if(strcmp(vc_tp->tag, "DESC") == 0) { | |
| 550 field = gaim_request_field_string_new(vc_tp->tag, | |
| 551 _(vc_tp->label), cdata, | |
| 552 TRUE); | |
| 553 } else { | |
| 554 field = gaim_request_field_string_new(vc_tp->tag, | |
| 555 _(vc_tp->label), cdata, | |
| 556 FALSE); | |
| 557 } | |
| 558 | |
| 559 gaim_request_field_group_add_field(group, field); | |
| 560 } | |
| 561 | |
| 562 if(x_vc_data != NULL) | |
| 563 xmlnode_free(x_vc_data); | |
| 564 | |
| 565 g_free(user_info); | |
| 566 | |
| 567 gaim_request_fields(gc, _("Edit Jabber vCard"), | |
| 568 _("Edit Jabber vCard"), | |
| 569 _("All items below are optional. Enter only the " | |
| 570 "information with which you feel comfortable."), | |
| 571 fields, | |
| 572 _("Save"), G_CALLBACK(jabber_format_info), | |
| 573 _("Cancel"), NULL, | |
| 574 gc); | |
| 575 } | |
| 576 | |
| 577 /*---------------------------------------*/ | |
| 578 /* End Jabber "set info" (vCard) support */ | |
| 579 /*---------------------------------------*/ | |
| 580 | |
| 581 /****** | |
| 582 * end of that ancient crap that needs to die | |
| 583 ******/ | |
| 584 | |
| 585 | |
| 7395 | 586 static void jabber_vcard_parse(JabberStream *js, xmlnode *packet, gpointer data) |
| 7014 | 587 { |
| 588 GList *resources; | |
| 589 const char *from = xmlnode_get_attrib(packet, "from"); | |
| 590 JabberBuddy *jb; | |
| 591 JabberBuddyResource *jbr; | |
| 592 GString *info_text; | |
| 7306 | 593 char *resource_name; |
| 7955 | 594 char *bare_jid; |
| 8213 | 595 char *text; |
| 7014 | 596 xmlnode *vcard; |
| 7955 | 597 GaimBuddy *b; |
| 10189 | 598 GSList *imgids = NULL; |
| 7014 | 599 |
| 600 if(!from) | |
| 601 return; | |
| 602 | |
| 11361 | 603 if(!(jb = jabber_buddy_find(js, from, TRUE))) |
| 604 return; | |
| 605 | |
| 10490 | 606 /* XXX: handle the error case */ |
| 607 | |
| 7014 | 608 resource_name = jabber_get_resource(from); |
| 7955 | 609 bare_jid = jabber_get_bare_jid(from); |
| 610 | |
| 611 b = gaim_find_buddy(js->gc->account, bare_jid); | |
| 7014 | 612 |
| 11361 | 613 |
| 7014 | 614 info_text = g_string_new(""); |
| 615 | |
| 8213 | 616 g_string_append_printf(info_text, "<b>%s:</b> %s<br/>", _("Jabber ID"), |
| 7014 | 617 from); |
| 618 | |
| 619 if(resource_name) { | |
| 620 jbr = jabber_buddy_find_resource(jb, resource_name); | |
| 621 if(jbr) { | |
| 7145 | 622 char *purdy = NULL; |
| 623 if(jbr->status) | |
| 624 purdy = gaim_strdup_withhtml(jbr->status); | |
| 8213 | 625 g_string_append_printf(info_text, "<b>%s:</b> %s%s%s<br/>", |
| 9954 | 626 _("Status"), jabber_buddy_state_get_name(jbr->state), |
| 7014 | 627 purdy ? ": " : "", |
| 628 purdy ? purdy : ""); | |
| 7145 | 629 if(purdy) |
| 630 g_free(purdy); | |
| 7014 | 631 } else { |
| 8213 | 632 g_string_append_printf(info_text, "<b>%s:</b> %s<br/>", |
| 7014 | 633 _("Status"), _("Unknown")); |
| 634 } | |
| 635 } else { | |
| 636 for(resources = jb->resources; resources; resources = resources->next) { | |
| 7145 | 637 char *purdy = NULL; |
| 7014 | 638 jbr = resources->data; |
| 7145 | 639 if(jbr->status) |
| 640 purdy = gaim_strdup_withhtml(jbr->status); | |
| 8213 | 641 g_string_append_printf(info_text, "<b>%s:</b> %s<br/>", |
| 7014 | 642 _("Resource"), jbr->name); |
| 8213 | 643 g_string_append_printf(info_text, "<b>%s:</b> %s%s%s<br/><br/>", |
| 9954 | 644 _("Status"), jabber_buddy_state_get_name(jbr->state), |
| 7014 | 645 purdy ? ": " : "", |
| 646 purdy ? purdy : ""); | |
| 7145 | 647 if(purdy) |
| 648 g_free(purdy); | |
| 7014 | 649 } |
| 650 } | |
| 651 | |
| 7306 | 652 g_free(resource_name); |
| 653 | |
| 10189 | 654 if((vcard = xmlnode_get_child(packet, "vCard")) || |
| 655 (vcard = xmlnode_get_child_with_namespace(packet, "query", "vcard-temp"))) { | |
| 7014 | 656 xmlnode *child; |
| 657 for(child = vcard->child; child; child = child->next) | |
| 658 { | |
| 659 xmlnode *child2; | |
| 660 | |
| 8135 | 661 if(child->type != XMLNODE_TYPE_TAG) |
| 7014 | 662 continue; |
| 663 | |
| 664 text = xmlnode_get_data(child); | |
| 665 if(text && !strcmp(child->name, "FN")) { | |
| 8213 | 666 g_string_append_printf(info_text, "<b>%s:</b> %s<br/>", |
| 7014 | 667 _("Full Name"), text); |
| 668 } else if(!strcmp(child->name, "N")) { | |
| 669 for(child2 = child->child; child2; child2 = child2->next) | |
| 670 { | |
| 671 char *text2; | |
| 672 | |
| 8135 | 673 if(child2->type != XMLNODE_TYPE_TAG) |
| 7014 | 674 continue; |
| 675 | |
| 676 text2 = xmlnode_get_data(child2); | |
| 677 if(text2 && !strcmp(child2->name, "FAMILY")) { | |
| 678 g_string_append_printf(info_text, | |
| 8213 | 679 "<b>%s:</b> %s<br/>", |
| 7014 | 680 _("Family Name"), text2); |
| 681 } else if(text2 && !strcmp(child2->name, "GIVEN")) { | |
| 682 g_string_append_printf(info_text, | |
| 8213 | 683 "<b>%s:</b> %s<br/>", |
| 7014 | 684 _("Given Name"), text2); |
| 685 } else if(text2 && !strcmp(child2->name, "MIDDLE")) { | |
| 686 g_string_append_printf(info_text, | |
| 8213 | 687 "<b>%s:</b> %s<br/>", |
| 7014 | 688 _("Middle Name"), text2); |
| 689 } | |
| 690 g_free(text2); | |
| 691 } | |
| 692 } else if(text && !strcmp(child->name, "NICKNAME")) { | |
| 693 serv_got_alias(js->gc, from, text); | |
| 7955 | 694 if(b) { |
| 695 gaim_blist_node_set_string((GaimBlistNode*)b, "servernick", text); | |
| 696 } | |
| 8213 | 697 g_string_append_printf(info_text, "<b>%s:</b> %s<br/>", |
| 7014 | 698 _("Nickname"), text); |
| 699 } else if(text && !strcmp(child->name, "BDAY")) { | |
| 8213 | 700 g_string_append_printf(info_text, "<b>%s:</b> %s<br/>", |
| 7014 | 701 _("Birthday"), text); |
| 702 } else if(!strcmp(child->name, "ADR")) { | |
| 703 /* show which address it is */ | |
| 704 if(child->child) | |
| 8213 | 705 g_string_append_printf(info_text, "<b>%s:</b><br/>", |
| 7014 | 706 _("Address")); |
| 707 for(child2 = child->child; child2; child2 = child2->next) | |
| 708 { | |
| 709 char *text2; | |
| 710 | |
| 8135 | 711 if(child2->type != XMLNODE_TYPE_TAG) |
| 7014 | 712 continue; |
| 713 | |
| 714 text2 = xmlnode_get_data(child2); | |
| 715 if(text2 && !strcmp(child2->name, "POBOX")) { | |
| 716 g_string_append_printf(info_text, | |
| 8213 | 717 " <b>%s:</b> %s<br/>", |
| 7014 | 718 _("P.O. Box"), text2); |
| 719 } else if(text2 && !strcmp(child2->name, "EXTADR")) { | |
| 720 g_string_append_printf(info_text, | |
| 8213 | 721 " <b>%s:</b> %s<br/>", |
| 7014 | 722 _("Extended Address"), text2); |
| 723 } else if(text2 && !strcmp(child2->name, "STREET")) { | |
| 724 g_string_append_printf(info_text, | |
| 8213 | 725 " <b>%s:</b> %s<br/>", |
| 7014 | 726 _("Street Address"), text2); |
| 727 } else if(text2 && !strcmp(child2->name, "LOCALITY")) { | |
| 728 g_string_append_printf(info_text, | |
| 8213 | 729 " <b>%s:</b> %s<br/>", |
| 7014 | 730 _("Locality"), text2); |
| 731 } else if(text2 && !strcmp(child2->name, "REGION")) { | |
| 732 g_string_append_printf(info_text, | |
| 8213 | 733 " <b>%s:</b> %s<br/>", |
| 7014 | 734 _("Region"), text2); |
| 735 } else if(text2 && !strcmp(child2->name, "PCODE")) { | |
| 736 g_string_append_printf(info_text, | |
| 8213 | 737 " <b>%s:</b> %s<br/>", |
| 7014 | 738 _("Postal Code"), text2); |
| 739 } else if(text2 && (!strcmp(child2->name, "CTRY") | |
| 740 || !strcmp(child2->name, "COUNTRY"))) { | |
| 741 g_string_append_printf(info_text, | |
| 8213 | 742 " <b>%s:</b> %s<br/>", |
| 7014 | 743 _("Country"), text2); |
| 744 } | |
| 745 g_free(text2); | |
| 746 } | |
| 747 } else if(!strcmp(child->name, "TEL")) { | |
| 748 char *number; | |
| 749 if((child2 = xmlnode_get_child(child, "NUMBER"))) { | |
| 750 /* show what kind of number it is */ | |
| 751 number = xmlnode_get_data(child2); | |
| 752 if(number) { | |
| 753 g_string_append_printf(info_text, | |
| 8213 | 754 "<b>%s:</b> %s<br/>", _("Telephone"), number); |
| 7014 | 755 g_free(number); |
| 756 } | |
| 757 } else if((number = xmlnode_get_data(child))) { | |
| 758 /* lots of clients (including gaim) do this, but it's | |
| 759 * out of spec */ | |
| 760 g_string_append_printf(info_text, | |
| 8213 | 761 "<b>%s:</b> %s<br/>", _("Telephone"), number); |
| 7014 | 762 g_free(number); |
| 763 } | |
| 764 } else if(!strcmp(child->name, "EMAIL")) { | |
| 765 char *userid; | |
| 766 if((child2 = xmlnode_get_child(child, "USERID"))) { | |
| 767 /* show what kind of email it is */ | |
| 768 userid = xmlnode_get_data(child2); | |
| 769 if(userid) { | |
| 770 g_string_append_printf(info_text, | |
| 8213 | 771 "<b>%s:</b> <a href='mailto:%s'>%s</a><br/>", |
| 7014 | 772 _("Email"), userid, userid); |
| 773 g_free(userid); | |
| 774 } | |
| 775 } else if((userid = xmlnode_get_data(child))) { | |
| 776 /* lots of clients (including gaim) do this, but it's | |
| 777 * out of spec */ | |
| 778 g_string_append_printf(info_text, | |
| 8213 | 779 "<b>%s:</b> <a href='mailto:%s'>%s</a><br/>", |
| 7014 | 780 _("Email"), userid, userid); |
| 781 g_free(userid); | |
| 782 } | |
| 783 } else if(!strcmp(child->name, "ORG")) { | |
| 784 for(child2 = child->child; child2; child2 = child2->next) | |
| 785 { | |
| 786 char *text2; | |
| 787 | |
| 8135 | 788 if(child2->type != XMLNODE_TYPE_TAG) |
| 7014 | 789 continue; |
| 790 | |
| 791 text2 = xmlnode_get_data(child2); | |
| 792 if(text2 && !strcmp(child2->name, "ORGNAME")) { | |
| 793 g_string_append_printf(info_text, | |
| 8213 | 794 "<b>%s:</b> %s<br/>", |
| 7014 | 795 _("Organization Name"), text2); |
| 796 } else if(text2 && !strcmp(child2->name, "ORGUNIT")) { | |
| 797 g_string_append_printf(info_text, | |
| 8213 | 798 "<b>%s:</b> %s<br/>", |
| 7014 | 799 _("Organization Unit"), text2); |
| 800 } | |
| 801 g_free(text2); | |
| 802 } | |
| 803 } else if(text && !strcmp(child->name, "TITLE")) { | |
| 8213 | 804 g_string_append_printf(info_text, "<b>%s:</b> %s<br/>", |
| 7014 | 805 _("Title"), text); |
| 806 } else if(text && !strcmp(child->name, "ROLE")) { | |
| 8213 | 807 g_string_append_printf(info_text, "<b>%s:</b> %s<br/>", |
| 7014 | 808 _("Role"), text); |
| 809 } else if(text && !strcmp(child->name, "DESC")) { | |
| 8213 | 810 g_string_append_printf(info_text, "<b>%s:</b> %s<br/>", |
| 811 _("Description"), text); | |
| 7076 | 812 } else if(!strcmp(child->name, "PHOTO") || |
| 813 !strcmp(child->name, "LOGO")) { | |
| 10941 | 814 char *bintext = NULL; |
| 815 xmlnode *binval; | |
| 11361 | 816 |
| 817 if( ((binval = xmlnode_get_child(child, "BINVAL")) && | |
| 818 (bintext = xmlnode_get_data(binval))) || | |
| 819 (bintext = xmlnode_get_data(child))) { | |
| 11127 | 820 gsize size; |
| 11137 | 821 guchar *data; |
| 11127 | 822 int i; |
| 10941 | 823 unsigned char hashval[20]; |
| 11127 | 824 char *p, hash[41]; |
| 10941 | 825 gboolean photo = (strcmp(child->name, "PHOTO") == 0); |
| 10189 | 826 |
| 11361 | 827 data = gaim_base64_decode(bintext, &size); |
| 7076 | 828 |
| 10941 | 829 imgids = g_slist_prepend(imgids, GINT_TO_POINTER(gaim_imgstore_add(data, size, "logo.png"))); |
| 830 g_string_append_printf(info_text, | |
| 831 "<b>%s:</b> <img id='%d'><br/>", | |
| 832 photo ? _("Photo") : _("Logo"), | |
| 833 GPOINTER_TO_INT(imgids->data)); | |
| 7076 | 834 |
| 10941 | 835 gaim_buddy_icons_set_for_user(js->gc->account, bare_jid, |
| 836 data, size); | |
| 10189 | 837 |
| 11183 | 838 gaim_cipher_digest_region("sha1", (guchar *)data, size, |
| 10941 | 839 sizeof(hashval), hashval, NULL); |
| 840 p = hash; | |
| 841 for(i=0; i<20; i++, p+=2) | |
| 842 snprintf(p, 3, "%02x", hashval[i]); | |
| 843 gaim_blist_node_set_string((GaimBlistNode*)b, "avatar_hash", hash); | |
| 10189 | 844 |
| 10941 | 845 g_free(data); |
| 846 g_free(bintext); | |
| 847 } | |
| 7014 | 848 } |
| 849 g_free(text); | |
| 850 } | |
| 851 } | |
| 852 | |
| 8213 | 853 text = gaim_strdup_withhtml(info_text->str); |
| 854 | |
|
11533
c9b815aeddc1
[gaim-migrate @ 13782]
Richard Laager <rlaager@wiktel.com>
parents:
11532
diff
changeset
|
855 gaim_notify_userinfo(js->gc, from, text, NULL, NULL); |
| 7014 | 856 |
| 10189 | 857 while(imgids) { |
| 858 gaim_imgstore_unref(GPOINTER_TO_INT(imgids->data)); | |
| 859 imgids = g_slist_delete_link(imgids, imgids); | |
| 860 } | |
| 7014 | 861 g_string_free(info_text, TRUE); |
| 8213 | 862 g_free(text); |
| 10189 | 863 g_free(bare_jid); |
| 7014 | 864 } |
| 865 | |
| 10189 | 866 static void jabber_buddy_get_info_for_jid(JabberStream *js, const char *full_jid) |
| 7014 | 867 { |
| 868 JabberIq *iq; | |
| 869 xmlnode *vcard; | |
| 870 | |
| 871 iq = jabber_iq_new(js, JABBER_IQ_GET); | |
| 872 | |
| 10189 | 873 xmlnode_set_attrib(iq->node, "to", full_jid); |
| 7014 | 874 vcard = xmlnode_new_child(iq->node, "vCard"); |
| 875 xmlnode_set_attrib(vcard, "xmlns", "vcard-temp"); | |
| 876 | |
| 7395 | 877 jabber_iq_set_callback(iq, jabber_vcard_parse, NULL); |
| 7014 | 878 |
| 879 jabber_iq_send(iq); | |
| 880 } | |
| 881 | |
| 10189 | 882 void jabber_buddy_get_info(GaimConnection *gc, const char *who) |
| 883 { | |
| 884 JabberStream *js = gc->proto_data; | |
| 885 char *bare_jid = jabber_get_bare_jid(who); | |
| 886 | |
| 887 if(bare_jid) { | |
| 888 jabber_buddy_get_info_for_jid(js, bare_jid); | |
| 889 g_free(bare_jid); | |
| 890 } | |
| 891 } | |
| 892 | |
| 7014 | 893 void jabber_buddy_get_info_chat(GaimConnection *gc, int id, |
| 894 const char *resource) | |
| 895 { | |
| 896 JabberStream *js = gc->proto_data; | |
| 897 JabberChat *chat = jabber_chat_find_by_id(js, id); | |
| 898 char *full_jid; | |
| 899 | |
| 900 if(!chat) | |
| 901 return; | |
| 902 | |
| 903 full_jid = g_strdup_printf("%s@%s/%s", chat->room, chat->server, resource); | |
| 10189 | 904 jabber_buddy_get_info_for_jid(js, full_jid); |
| 7014 | 905 g_free(full_jid); |
| 906 } | |
| 907 | |
| 7395 | 908 |
| 7014 | 909 static void jabber_buddy_set_invisibility(JabberStream *js, const char *who, |
| 910 gboolean invisible) | |
| 911 { | |
| 9944 | 912 GaimPresence *gpresence; |
| 913 GaimAccount *account; | |
| 914 GaimStatus *status; | |
| 7014 | 915 JabberBuddy *jb = jabber_buddy_find(js, who, TRUE); |
| 916 xmlnode *presence; | |
| 9954 | 917 JabberBuddyState state; |
| 918 const char *msg; | |
| 919 int priority; | |
| 7014 | 920 |
| 9944 | 921 account = gaim_connection_get_account(js->gc); |
| 922 gpresence = gaim_account_get_presence(account); | |
| 923 status = gaim_presence_get_active_status(gpresence); | |
| 924 | |
| 9954 | 925 gaim_status_to_jabber(status, &state, &msg, &priority); |
| 926 presence = jabber_presence_create(state, msg, priority); | |
| 927 | |
| 7014 | 928 xmlnode_set_attrib(presence, "to", who); |
| 929 if(invisible) { | |
| 930 xmlnode_set_attrib(presence, "type", "invisible"); | |
| 931 jb->invisible |= JABBER_INVIS_BUDDY; | |
| 932 } else { | |
| 933 jb->invisible &= ~JABBER_INVIS_BUDDY; | |
| 934 } | |
| 935 | |
| 936 jabber_send(js, presence); | |
| 937 xmlnode_free(presence); | |
| 938 } | |
| 939 | |
| 9030 | 940 static void jabber_buddy_make_invisible(GaimBlistNode *node, gpointer data) |
| 7014 | 941 { |
| 9030 | 942 GaimBuddy *buddy; |
| 943 GaimConnection *gc; | |
| 944 JabberStream *js; | |
| 945 | |
| 946 g_return_if_fail(GAIM_BLIST_NODE_IS_BUDDY(node)); | |
| 947 | |
| 948 buddy = (GaimBuddy *) node; | |
| 949 gc = gaim_account_get_connection(buddy->account); | |
| 950 js = gc->proto_data; | |
| 951 | |
| 952 jabber_buddy_set_invisibility(js, buddy->name, TRUE); | |
| 7014 | 953 } |
| 954 | |
| 9030 | 955 static void jabber_buddy_make_visible(GaimBlistNode *node, gpointer data) |
| 7014 | 956 { |
| 9030 | 957 GaimBuddy *buddy; |
| 958 GaimConnection *gc; | |
| 959 JabberStream *js; | |
| 7014 | 960 |
| 9030 | 961 g_return_if_fail(GAIM_BLIST_NODE_IS_BUDDY(node)); |
| 7014 | 962 |
| 9030 | 963 buddy = (GaimBuddy *) node; |
| 964 gc = gaim_account_get_connection(buddy->account); | |
| 965 js = gc->proto_data; | |
| 966 | |
| 967 jabber_buddy_set_invisibility(js, buddy->name, FALSE); | |
| 7014 | 968 } |
| 969 | |
| 9030 | 970 static void jabber_buddy_cancel_presence_notification(GaimBlistNode *node, |
| 971 gpointer data) | |
| 7014 | 972 { |
| 9030 | 973 GaimBuddy *buddy; |
| 974 GaimConnection *gc; | |
| 975 JabberStream *js; | |
| 976 | |
| 977 g_return_if_fail(GAIM_BLIST_NODE_IS_BUDDY(node)); | |
| 7014 | 978 |
| 9030 | 979 buddy = (GaimBuddy *) node; |
| 980 gc = gaim_account_get_connection(buddy->account); | |
| 981 js = gc->proto_data; | |
| 982 | |
| 983 /* I wonder if we should prompt the user before doing this */ | |
| 984 jabber_presence_subscription_set(js, buddy->name, "unsubscribed"); | |
| 7014 | 985 } |
| 986 | |
| 9030 | 987 static void jabber_buddy_rerequest_auth(GaimBlistNode *node, gpointer data) |
| 7250 | 988 { |
| 9030 | 989 GaimBuddy *buddy; |
| 990 GaimConnection *gc; | |
| 991 JabberStream *js; | |
| 992 | |
| 993 g_return_if_fail(GAIM_BLIST_NODE_IS_BUDDY(node)); | |
| 7250 | 994 |
| 9030 | 995 buddy = (GaimBuddy *) node; |
| 996 gc = gaim_account_get_connection(buddy->account); | |
| 997 js = gc->proto_data; | |
| 998 | |
| 999 jabber_presence_subscription_set(js, buddy->name, "subscribe"); | |
| 7250 | 1000 } |
| 1001 | |
| 9030 | 1002 |
| 1003 static void jabber_buddy_unsubscribe(GaimBlistNode *node, gpointer data) | |
| 7014 | 1004 { |
| 9030 | 1005 GaimBuddy *buddy; |
| 1006 GaimConnection *gc; | |
| 1007 JabberStream *js; | |
| 1008 | |
| 1009 g_return_if_fail(GAIM_BLIST_NODE_IS_BUDDY(node)); | |
| 1010 | |
| 1011 buddy = (GaimBuddy *) node; | |
| 1012 gc = gaim_account_get_connection(buddy->account); | |
| 1013 js = gc->proto_data; | |
| 1014 | |
| 1015 jabber_presence_subscription_set(js, buddy->name, "unsubscribe"); | |
| 1016 } | |
| 1017 | |
| 1018 | |
| 1019 GList *jabber_buddy_menu(GaimBuddy *buddy) | |
| 1020 { | |
| 1021 GaimConnection *gc = gaim_account_get_connection(buddy->account); | |
| 1022 JabberStream *js = gc->proto_data; | |
| 1023 JabberBuddy *jb = jabber_buddy_find(js, buddy->name, TRUE); | |
| 1024 | |
| 7014 | 1025 GList *m = NULL; |
| 9030 | 1026 GaimBlistNodeAction *act; |
| 7395 | 1027 |
| 1028 if(!jb) | |
| 1029 return m; | |
| 1030 | |
| 8185 | 1031 /* XXX: fix the NOT ME below */ |
| 1032 | |
| 1033 if(js->protocol_version == JABBER_PROTO_0_9 /* && NOT ME */) { | |
| 8166 | 1034 if(jb->invisible & JABBER_INVIS_BUDDY) { |
| 9030 | 1035 act = gaim_blist_node_action_new(_("Un-hide From"), |
|
10662
54ac161a876e
[gaim-migrate @ 12199]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10504
diff
changeset
|
1036 jabber_buddy_make_visible, NULL, NULL); |
| 8166 | 1037 } else { |
| 9030 | 1038 act = gaim_blist_node_action_new(_("Temporarily Hide From"), |
|
10662
54ac161a876e
[gaim-migrate @ 12199]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10504
diff
changeset
|
1039 jabber_buddy_make_invisible, NULL, NULL); |
| 8166 | 1040 } |
| 9030 | 1041 m = g_list_append(m, act); |
| 7014 | 1042 } |
| 1043 | |
| 8185 | 1044 if(jb->subscription & JABBER_SUB_FROM /* && NOT ME */) { |
| 9030 | 1045 act = gaim_blist_node_action_new(_("Cancel Presence Notification"), |
|
10662
54ac161a876e
[gaim-migrate @ 12199]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10504
diff
changeset
|
1046 jabber_buddy_cancel_presence_notification, NULL, NULL); |
| 9030 | 1047 m = g_list_append(m, act); |
| 7014 | 1048 } |
| 1049 | |
| 1050 if(!(jb->subscription & JABBER_SUB_TO)) { | |
| 9030 | 1051 act = gaim_blist_node_action_new(_("(Re-)Request authorization"), |
|
10662
54ac161a876e
[gaim-migrate @ 12199]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10504
diff
changeset
|
1052 jabber_buddy_rerequest_auth, NULL, NULL); |
| 9030 | 1053 m = g_list_append(m, act); |
| 1054 | |
| 8185 | 1055 } else /* if(NOT ME) */{ |
| 9030 | 1056 |
| 1057 /* shouldn't this just happen automatically when the buddy is | |
| 1058 removed? */ | |
| 1059 act = gaim_blist_node_action_new(_("Unsubscribe"), | |
|
10662
54ac161a876e
[gaim-migrate @ 12199]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10504
diff
changeset
|
1060 jabber_buddy_unsubscribe, NULL, NULL); |
| 9030 | 1061 m = g_list_append(m, act); |
| 7014 | 1062 } |
| 1063 | |
| 1064 return m; | |
| 1065 } | |
| 9030 | 1066 |
| 1067 GList * | |
| 1068 jabber_blist_node_menu(GaimBlistNode *node) | |
| 1069 { | |
| 1070 if(GAIM_BLIST_NODE_IS_BUDDY(node)) { | |
| 1071 return jabber_buddy_menu((GaimBuddy *) node); | |
| 1072 } else { | |
| 1073 return NULL; | |
| 1074 } | |
| 1075 } | |
| 1076 | |
| 1077 | |
| 9954 | 1078 const char * |
| 1079 jabber_buddy_state_get_name(JabberBuddyState state) | |
| 1080 { | |
| 1081 switch(state) { | |
| 1082 case JABBER_BUDDY_STATE_UNKNOWN: | |
| 1083 return _("Unknown"); | |
| 1084 case JABBER_BUDDY_STATE_ERROR: | |
| 1085 return _("Error"); | |
| 1086 case JABBER_BUDDY_STATE_UNAVAILABLE: | |
| 1087 return _("Offline"); | |
| 1088 case JABBER_BUDDY_STATE_ONLINE: | |
| 1089 return _("Online"); | |
| 1090 case JABBER_BUDDY_STATE_CHAT: | |
| 1091 return _("Chatty"); | |
| 1092 case JABBER_BUDDY_STATE_AWAY: | |
| 1093 return _("Away"); | |
| 1094 case JABBER_BUDDY_STATE_XA: | |
| 1095 return _("Extended Away"); | |
| 1096 case JABBER_BUDDY_STATE_DND: | |
| 1097 return _("Do Not Disturb"); | |
| 1098 } | |
| 1099 | |
| 1100 return _("Unknown"); | |
| 1101 } | |
| 1102 | |
| 1103 JabberBuddyState jabber_buddy_status_id_get_state(const char *id) { | |
| 1104 if(!id) | |
| 1105 return JABBER_BUDDY_STATE_UNKNOWN; | |
| 11540 | 1106 if(!strcmp(id, "available")) |
| 9954 | 1107 return JABBER_BUDDY_STATE_ONLINE; |
| 1108 if(!strcmp(id, "chat")) | |
| 1109 return JABBER_BUDDY_STATE_CHAT; | |
| 1110 if(!strcmp(id, "away")) | |
| 1111 return JABBER_BUDDY_STATE_AWAY; | |
| 1112 if(!strcmp(id, "xa")) | |
| 1113 return JABBER_BUDDY_STATE_XA; | |
| 1114 if(!strcmp(id, "dnd")) | |
| 1115 return JABBER_BUDDY_STATE_DND; | |
| 1116 if(!strcmp(id, "offline")) | |
| 1117 return JABBER_BUDDY_STATE_UNAVAILABLE; | |
| 1118 if(!strcmp(id, "error")) | |
| 1119 return JABBER_BUDDY_STATE_ERROR; | |
| 1120 | |
| 1121 return JABBER_BUDDY_STATE_UNKNOWN; | |
| 1122 } | |
| 1123 | |
| 1124 const char *jabber_buddy_state_get_status_id(JabberBuddyState state) { | |
| 1125 switch(state) { | |
| 1126 case JABBER_BUDDY_STATE_CHAT: | |
| 1127 return "chat"; | |
| 1128 case JABBER_BUDDY_STATE_AWAY: | |
| 1129 return "away"; | |
| 1130 case JABBER_BUDDY_STATE_XA: | |
| 1131 return "xa"; | |
| 1132 case JABBER_BUDDY_STATE_DND: | |
| 1133 return "dnd"; | |
| 1134 case JABBER_BUDDY_STATE_ONLINE: | |
| 11540 | 1135 return "available"; |
| 9954 | 1136 case JABBER_BUDDY_STATE_UNKNOWN: |
| 1137 case JABBER_BUDDY_STATE_ERROR: | |
| 1138 return NULL; | |
| 1139 case JABBER_BUDDY_STATE_UNAVAILABLE: | |
| 1140 return "offline"; | |
| 1141 } | |
| 1142 return NULL; | |
| 1143 } | |
| 11675 | 1144 |
| 1145 static void user_search_result_add_buddy_cb(GaimConnection *gc, GList *row) | |
| 1146 { | |
| 1147 /* XXX find out the jid */ | |
| 1148 gaim_blist_request_add_buddy(gaim_connection_get_account(gc), | |
| 1149 g_list_nth_data(row, 0), NULL, NULL); | |
| 1150 } | |
| 1151 | |
| 1152 static void user_search_result_cb(JabberStream *js, xmlnode *packet, gpointer data) | |
| 1153 { | |
| 1154 GaimNotifySearchResults *results; | |
| 1155 GaimNotifySearchColumn *column; | |
| 1156 xmlnode *x, *query, *item, *field; | |
| 1157 | |
| 1158 /* XXX error checking? */ | |
| 1159 if(!(query = xmlnode_get_child(packet, "query"))) | |
| 1160 return; | |
| 1161 | |
| 1162 results = gaim_notify_searchresults_new(); | |
| 1163 if((x = xmlnode_get_child_with_namespace(query, "x", "jabber:x:data"))) { | |
| 1164 xmlnode *reported; | |
| 1165 gaim_debug_info("jabber", "new-skool\n"); | |
| 1166 if((reported = xmlnode_get_child(x, "reported"))) { | |
| 1167 xmlnode *field = xmlnode_get_child(reported, "field"); | |
| 1168 while(field) { | |
| 1169 /* XXX keep track of this order, use it below */ | |
| 1170 const char *var = xmlnode_get_attrib(field, "var"); | |
| 1171 const char *label = xmlnode_get_attrib(field, "label"); | |
| 1172 if(var) { | |
| 1173 column = gaim_notify_searchresults_column_new(label ? label : var); | |
| 1174 gaim_notify_searchresults_column_add(results, column); | |
| 1175 } | |
| 1176 field = xmlnode_get_next_twin(field); | |
| 1177 } | |
| 1178 } | |
| 1179 item = xmlnode_get_child(x, "item"); | |
| 1180 while(item) { | |
| 1181 GList *row = NULL; | |
| 1182 field = xmlnode_get_child(item, "field"); | |
| 1183 while(field) { | |
| 1184 xmlnode *valuenode = xmlnode_get_child(item, "value"); | |
| 1185 if(valuenode) { | |
| 1186 char *value = xmlnode_get_data(valuenode); | |
| 1187 row = g_list_append(row, value); | |
| 1188 } | |
| 1189 field = xmlnode_get_next_twin(field); | |
| 1190 } | |
| 1191 gaim_notify_searchresults_row_add(results, row); | |
| 1192 | |
| 1193 item = xmlnode_get_next_twin(item); | |
| 1194 } | |
| 1195 } else { | |
| 1196 /* old skool */ | |
| 1197 gaim_debug_info("jabber", "old-skool\n"); | |
| 1198 | |
| 1199 column = gaim_notify_searchresults_column_new("JID"); | |
| 1200 gaim_notify_searchresults_column_add(results, column); | |
| 1201 column = gaim_notify_searchresults_column_new("First"); | |
| 1202 gaim_notify_searchresults_column_add(results, column); | |
| 1203 column = gaim_notify_searchresults_column_new("Last"); | |
| 1204 gaim_notify_searchresults_column_add(results, column); | |
| 1205 column = gaim_notify_searchresults_column_new("Nickname"); | |
| 1206 gaim_notify_searchresults_column_add(results, column); | |
| 1207 column = gaim_notify_searchresults_column_new("E-Mail"); | |
| 1208 gaim_notify_searchresults_column_add(results, column); | |
| 1209 | |
| 1210 for(item = xmlnode_get_child(query, "item"); item; item = xmlnode_get_next_twin(item)) { | |
| 1211 const char *jid; | |
| 1212 xmlnode *node; | |
| 1213 GList *row = NULL; | |
| 1214 | |
| 1215 if(!(jid = xmlnode_get_attrib(item, "jid"))) | |
| 1216 continue; | |
| 1217 | |
| 1218 row = g_list_append(row, g_strdup(jid)); | |
| 1219 node = xmlnode_get_child(item, "first"); | |
| 1220 row = g_list_append(row, node ? xmlnode_get_data(node) : NULL); | |
| 1221 node = xmlnode_get_child(item, "last"); | |
| 1222 row = g_list_append(row, node ? xmlnode_get_data(node) : NULL); | |
| 1223 node = xmlnode_get_child(item, "nick"); | |
| 1224 row = g_list_append(row, node ? xmlnode_get_data(node) : NULL); | |
| 1225 node = xmlnode_get_child(item, "email"); | |
| 1226 row = g_list_append(row, node ? xmlnode_get_data(node) : NULL); | |
| 1227 gaim_debug_info("jabber", "row=%d\n", row); | |
| 1228 gaim_notify_searchresults_row_add(results, row); | |
| 1229 } | |
| 1230 } | |
| 1231 | |
| 1232 gaim_notify_searchresults_button_add(results, GAIM_NOTIFY_BUTTON_ADD_BUDDY, | |
| 1233 user_search_result_add_buddy_cb); | |
| 1234 | |
| 1235 gaim_notify_searchresults(js->gc, NULL, NULL, _("The following are the results of your search"), results, NULL, NULL); | |
| 1236 } | |
| 1237 | |
| 1238 static void user_search_x_data_cb(JabberStream *js, xmlnode *result, gpointer data) | |
| 1239 { | |
| 1240 xmlnode *query; | |
| 1241 JabberIq *iq; | |
| 1242 | |
| 1243 iq = jabber_iq_new_query(js, JABBER_IQ_SET, "jabber:iq:search"); | |
| 1244 query = xmlnode_get_child(iq->node, "query"); | |
| 1245 | |
| 1246 xmlnode_insert_child(query, result); | |
| 1247 | |
| 1248 jabber_iq_set_callback(iq, user_search_result_cb, NULL); | |
| 1249 jabber_iq_send(iq); | |
| 1250 } | |
| 1251 | |
| 1252 struct user_search_info { | |
| 1253 JabberStream *js; | |
| 1254 char *directory_server; | |
| 1255 }; | |
| 1256 | |
| 1257 static void user_search_cancel_cb(struct user_search_info *usi, GaimRequestFields *fields) | |
| 1258 { | |
| 1259 g_free(usi->directory_server); | |
| 1260 g_free(usi); | |
| 1261 } | |
| 1262 | |
| 1263 static void user_search_cb(struct user_search_info *usi, GaimRequestFields *fields) | |
| 1264 { | |
| 1265 JabberStream *js = usi->js; | |
| 1266 JabberIq *iq; | |
| 1267 xmlnode *query; | |
| 1268 GList *groups, *flds; | |
| 1269 | |
| 1270 iq = jabber_iq_new_query(js, JABBER_IQ_SET, "jabber:iq:search"); | |
| 1271 query = xmlnode_get_child(iq->node, "query"); | |
| 1272 | |
| 1273 for(groups = gaim_request_fields_get_groups(fields); groups; groups = groups->next) { | |
| 1274 for(flds = gaim_request_field_group_get_fields(groups->data); | |
| 1275 flds; flds = flds->next) { | |
| 1276 GaimRequestField *field = flds->data; | |
| 1277 const char *id = gaim_request_field_get_id(field); | |
| 1278 const char *value = gaim_request_field_string_get_value(field); | |
| 1279 | |
| 1280 if(value && (!strcmp(id, "first") || !strcmp(id, "last") || !strcmp(id, "nick") || !strcmp(id, "email"))) { | |
| 1281 xmlnode *y = xmlnode_new_child(query, id); | |
| 1282 xmlnode_insert_data(y, value, -1); | |
| 1283 } | |
| 1284 } | |
| 1285 } | |
| 1286 | |
| 1287 jabber_iq_set_callback(iq, user_search_result_cb, NULL); | |
| 1288 xmlnode_set_attrib(iq->node, "to", usi->directory_server); | |
| 1289 jabber_iq_send(iq); | |
| 1290 | |
| 1291 g_free(usi->directory_server); | |
| 1292 g_free(usi); | |
| 1293 } | |
| 1294 | |
| 1295 static void user_search_fields_result_cb(JabberStream *js, xmlnode *packet, gpointer data) | |
| 1296 { | |
| 1297 xmlnode *query, *x; | |
| 1298 const char *from; | |
| 1299 | |
| 1300 /* i forget, do i have to check for error? XXX */ | |
| 1301 if(!(from= xmlnode_get_attrib(packet, "from"))) | |
| 1302 return; | |
| 1303 | |
| 1304 | |
| 1305 if(!(query = xmlnode_get_child(packet, "query"))) | |
| 1306 return; | |
| 1307 | |
| 1308 if((x = xmlnode_get_child_with_namespace(packet, "x", "jabber:x:data"))) { | |
| 1309 jabber_x_data_request(js, x, user_search_x_data_cb, NULL); | |
| 1310 return; | |
| 1311 } else { | |
| 1312 struct user_search_info *usi; | |
| 1313 xmlnode *instnode; | |
| 1314 char *instructions; | |
| 1315 GaimRequestFields *fields; | |
| 1316 GaimRequestFieldGroup *group; | |
| 1317 GaimRequestField *field; | |
| 1318 | |
| 1319 /* old skool */ | |
| 1320 fields = gaim_request_fields_new(); | |
| 1321 group = gaim_request_field_group_new(NULL); | |
| 1322 gaim_request_fields_add_group(fields, group); | |
| 1323 | |
| 1324 if((instnode = xmlnode_get_child(query, "instructions"))) | |
| 1325 instructions = xmlnode_get_data(instnode); | |
| 1326 else | |
| 1327 instructions = g_strdup(_("Fill in one or more fields to search " | |
| 1328 "for any matching Jabber users.")); | |
| 1329 | |
| 1330 if(xmlnode_get_child(query, "first")) { | |
| 1331 field = gaim_request_field_string_new("first", _("First Name"), | |
| 1332 NULL, FALSE); | |
| 1333 gaim_request_field_group_add_field(group, field); | |
| 1334 } | |
| 1335 if(xmlnode_get_child(query, "last")) { | |
| 1336 field = gaim_request_field_string_new("last", _("Last Name"), | |
| 1337 NULL, FALSE); | |
| 1338 gaim_request_field_group_add_field(group, field); | |
| 1339 } | |
| 1340 if(xmlnode_get_child(query, "nick")) { | |
| 1341 field = gaim_request_field_string_new("nick", _("Nickname"), | |
| 1342 NULL, FALSE); | |
| 1343 gaim_request_field_group_add_field(group, field); | |
| 1344 } | |
| 1345 if(xmlnode_get_child(query, "email")) { | |
| 1346 field = gaim_request_field_string_new("email", _("E-Mail Address"), | |
| 1347 NULL, FALSE); | |
| 1348 gaim_request_field_group_add_field(group, field); | |
| 1349 } | |
| 1350 | |
| 1351 usi = g_new0(struct user_search_info, 1); | |
| 1352 usi->js = js; | |
| 1353 usi->directory_server = g_strdup(from); | |
| 1354 | |
| 1355 gaim_request_fields(js->gc, _("Search for Jabber users"), | |
| 1356 _("Search for Jabber users"), instructions, fields, | |
| 1357 _("Search"), G_CALLBACK(user_search_cb), | |
| 1358 _("Cancel"), G_CALLBACK(user_search_cancel_cb), usi); | |
| 1359 | |
| 1360 g_free(instructions); | |
| 1361 } | |
| 1362 } | |
| 1363 | |
| 1364 static void jabber_user_search_ok(JabberStream *js, const char *directory) | |
| 1365 { | |
| 1366 JabberIq *iq; | |
| 1367 | |
| 1368 /* XXX: should probably better validate the directory we're given */ | |
| 1369 if(!directory || !*directory) { | |
| 1370 gaim_notify_error(js->gc, _("Invalid Directory"), _("Invalid Directory"), NULL); | |
| 1371 return; | |
| 1372 } | |
| 1373 | |
| 1374 iq = jabber_iq_new_query(js, JABBER_IQ_GET, "jabber:iq:search"); | |
| 1375 xmlnode_set_attrib(iq->node, "to", directory); | |
| 1376 | |
| 1377 jabber_iq_set_callback(iq, user_search_fields_result_cb, NULL); | |
| 1378 | |
| 1379 jabber_iq_send(iq); | |
| 1380 } | |
| 1381 | |
| 1382 void jabber_user_search_begin(GaimPluginAction *action) | |
| 1383 { | |
| 1384 GaimConnection *gc = (GaimConnection *) action->context; | |
| 1385 JabberStream *js = gc->proto_data; | |
| 1386 | |
| 1387 gaim_request_input(gc, _("Enter a User Directory"), _("Enter a User Directory"), | |
| 1388 _("Select a user directory to search"), | |
| 1389 js->user_directories ? js->user_directories->data : "users.jabber.org", | |
| 1390 FALSE, FALSE, NULL, | |
| 1391 _("Search Directory"), GAIM_CALLBACK(jabber_user_search_ok), | |
| 1392 _("Cancel"), NULL, js); | |
| 1393 } |
