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