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