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