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