Mercurial > pidgin
annotate src/protocols/jabber/buddy.c @ 7262:85fcaff1505d
[gaim-migrate @ 7839]
put normalizing back in the realm of sanity (what was I thinking?) and fix
jabber chat case sensitivity (as well as a few other things)
committer: Tailor Script <tailor@pidgin.im>
author | Nathan Walp <nwalp@pidgin.im> |
---|---|
date | Tue, 14 Oct 2003 16:44:36 +0000 |
parents | dee9f6aebbf3 |
children | 7c12dab8e513 |
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; | |
540 const char *resource_name; | |
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 | |
590 if((vcard = xmlnode_get_child(packet, "vCard"))) { | |
591 xmlnode *child; | |
592 for(child = vcard->child; child; child = child->next) | |
593 { | |
594 xmlnode *child2; | |
595 char *text; | |
596 | |
597 if(child->type != NODE_TYPE_TAG) | |
598 continue; | |
599 | |
600 text = xmlnode_get_data(child); | |
601 if(text && !strcmp(child->name, "FN")) { | |
602 g_string_append_printf(info_text, "<b>%s:</b> %s<br/>\n", | |
603 _("Full Name"), text); | |
604 } else if(!strcmp(child->name, "N")) { | |
605 for(child2 = child->child; child2; child2 = child2->next) | |
606 { | |
607 char *text2; | |
608 | |
609 if(child2->type != NODE_TYPE_TAG) | |
610 continue; | |
611 | |
612 text2 = xmlnode_get_data(child2); | |
613 if(text2 && !strcmp(child2->name, "FAMILY")) { | |
614 g_string_append_printf(info_text, | |
615 "<b>%s:</b> %s<br/>\n", | |
616 _("Family Name"), text2); | |
617 } else if(text2 && !strcmp(child2->name, "GIVEN")) { | |
618 g_string_append_printf(info_text, | |
619 "<b>%s:</b> %s<br/>\n", | |
620 _("Given Name"), text2); | |
621 } else if(text2 && !strcmp(child2->name, "MIDDLE")) { | |
622 g_string_append_printf(info_text, | |
623 "<b>%s:</b> %s<br/>\n", | |
624 _("Middle Name"), text2); | |
625 } | |
626 g_free(text2); | |
627 } | |
628 } else if(text && !strcmp(child->name, "NICKNAME")) { | |
629 serv_got_alias(js->gc, from, text); | |
630 g_string_append_printf(info_text, "<b>%s:</b> %s<br/>\n", | |
631 _("Nickname"), text); | |
632 } else if(text && !strcmp(child->name, "BDAY")) { | |
633 g_string_append_printf(info_text, "<b>%s:</b> %s<br/>\n", | |
634 _("Birthday"), text); | |
635 } else if(!strcmp(child->name, "ADR")) { | |
636 /* show which address it is */ | |
637 if(child->child) | |
638 g_string_append_printf(info_text, "<b>%s:</b><br/>\n", | |
639 _("Address")); | |
640 for(child2 = child->child; child2; child2 = child2->next) | |
641 { | |
642 char *text2; | |
643 | |
644 if(child2->type != NODE_TYPE_TAG) | |
645 continue; | |
646 | |
647 text2 = xmlnode_get_data(child2); | |
648 if(text2 && !strcmp(child2->name, "POBOX")) { | |
649 g_string_append_printf(info_text, | |
650 " <b>%s:</b> %s<br/>\n", | |
651 _("P.O. Box"), text2); | |
652 } else if(text2 && !strcmp(child2->name, "EXTADR")) { | |
653 g_string_append_printf(info_text, | |
654 " <b>%s:</b> %s<br/>\n", | |
655 _("Extended Address"), text2); | |
656 } else if(text2 && !strcmp(child2->name, "STREET")) { | |
657 g_string_append_printf(info_text, | |
658 " <b>%s:</b> %s<br/>\n", | |
659 _("Street Address"), text2); | |
660 } else if(text2 && !strcmp(child2->name, "LOCALITY")) { | |
661 g_string_append_printf(info_text, | |
662 " <b>%s:</b> %s<br/>\n", | |
663 _("Locality"), text2); | |
664 } else if(text2 && !strcmp(child2->name, "REGION")) { | |
665 g_string_append_printf(info_text, | |
666 " <b>%s:</b> %s<br/>\n", | |
667 _("Region"), text2); | |
668 } else if(text2 && !strcmp(child2->name, "PCODE")) { | |
669 g_string_append_printf(info_text, | |
670 " <b>%s:</b> %s<br/>\n", | |
671 _("Postal Code"), text2); | |
672 } else if(text2 && (!strcmp(child2->name, "CTRY") | |
673 || !strcmp(child2->name, "COUNTRY"))) { | |
674 g_string_append_printf(info_text, | |
675 " <b>%s:</b> %s<br/>\n", | |
676 _("Country"), text2); | |
677 } | |
678 g_free(text2); | |
679 } | |
680 } else if(!strcmp(child->name, "TEL")) { | |
681 char *number; | |
682 if((child2 = xmlnode_get_child(child, "NUMBER"))) { | |
683 /* show what kind of number it is */ | |
684 number = xmlnode_get_data(child2); | |
685 if(number) { | |
686 g_string_append_printf(info_text, | |
687 "<b>%s:</b> %s<br/>\n", _("Telephone"), number); | |
688 g_free(number); | |
689 } | |
690 } else if((number = xmlnode_get_data(child))) { | |
691 /* lots of clients (including gaim) do this, but it's | |
692 * out of spec */ | |
693 g_string_append_printf(info_text, | |
694 "<b>%s:</b> %s<br/>\n", _("Telephone"), number); | |
695 g_free(number); | |
696 } | |
697 } else if(!strcmp(child->name, "EMAIL")) { | |
698 char *userid; | |
699 if((child2 = xmlnode_get_child(child, "USERID"))) { | |
700 /* show what kind of email it is */ | |
701 userid = xmlnode_get_data(child2); | |
702 if(userid) { | |
703 g_string_append_printf(info_text, | |
704 "<b>%s:</b> <a href='mailto:%s'>%s</a><br/>\n", | |
705 _("Email"), userid, userid); | |
706 g_free(userid); | |
707 } | |
708 } else if((userid = xmlnode_get_data(child))) { | |
709 /* lots of clients (including gaim) do this, but it's | |
710 * out of spec */ | |
711 g_string_append_printf(info_text, | |
712 "<b>%s:</b> <a href='mailto:%s'>%s</a><br/>\n", | |
713 _("Email"), userid, userid); | |
714 g_free(userid); | |
715 } | |
716 } else if(!strcmp(child->name, "ORG")) { | |
717 for(child2 = child->child; child2; child2 = child2->next) | |
718 { | |
719 char *text2; | |
720 | |
721 if(child2->type != NODE_TYPE_TAG) | |
722 continue; | |
723 | |
724 text2 = xmlnode_get_data(child2); | |
725 if(text2 && !strcmp(child2->name, "ORGNAME")) { | |
726 g_string_append_printf(info_text, | |
727 "<b>%s:</b> %s<br/>\n", | |
728 _("Organization Name"), text2); | |
729 } else if(text2 && !strcmp(child2->name, "ORGUNIT")) { | |
730 g_string_append_printf(info_text, | |
731 "<b>%s:</b> %s<br/>\n", | |
732 _("Organization Unit"), text2); | |
733 } | |
734 g_free(text2); | |
735 } | |
736 } else if(text && !strcmp(child->name, "TITLE")) { | |
737 g_string_append_printf(info_text, "<b>%s:</b> %s<br/>\n", | |
738 _("Title"), text); | |
739 } else if(text && !strcmp(child->name, "ROLE")) { | |
740 g_string_append_printf(info_text, "<b>%s:</b> %s<br/>\n", | |
741 _("Role"), text); | |
742 } else if(text && !strcmp(child->name, "DESC")) { | |
743 g_string_append_printf(info_text, "<b>%s:</b> %s<br/>\n", | |
744 _("Description"), text); | |
7076 | 745 } else if(!strcmp(child->name, "PHOTO") || |
746 !strcmp(child->name, "LOGO")) { | |
747 if((child2 = xmlnode_get_child(child, "BINVAL"))) { | |
748 char *data, *text2; | |
749 int size, imgid; | |
750 if((text2 = xmlnode_get_data(child2))) { | |
7106
db6bd3e794d8
[gaim-migrate @ 7671]
Christian Hammond <chipx86@chipx86.com>
parents:
7076
diff
changeset
|
751 gaim_base64_decode(text2, &data, &size); |
7076 | 752 |
753 imgid = gaim_imgstore_add(data, size, "logo.png"); | |
754 g_string_append_printf(info_text, | |
7116 | 755 "<b>%s:</b> <img id='%d'><br/>", |
7076 | 756 strcmp(child->name, "PHOTO") == 0 ? |
757 _("Photo") : _("Logo"), | |
758 imgid); | |
759 | |
760 g_free(data); | |
761 g_free(text2); | |
762 } | |
763 } | |
7014 | 764 } |
765 g_free(text); | |
766 } | |
767 } | |
768 | |
769 title = g_strdup_printf("User info for %s", from); | |
770 | |
771 gaim_notify_formatted(NULL, title, _("Jabber Profile"), | |
772 NULL, info_text->str, NULL, NULL); | |
773 | |
774 g_free(title); | |
775 g_string_free(info_text, TRUE); | |
776 } | |
777 | |
778 void jabber_buddy_get_info(GaimConnection *gc, const char *who) | |
779 { | |
780 JabberStream *js = gc->proto_data; | |
781 JabberIq *iq; | |
782 xmlnode *vcard; | |
783 | |
784 iq = jabber_iq_new(js, JABBER_IQ_GET); | |
785 | |
786 xmlnode_set_attrib(iq->node, "to", who); | |
787 vcard = xmlnode_new_child(iq->node, "vCard"); | |
788 xmlnode_set_attrib(vcard, "xmlns", "vcard-temp"); | |
789 | |
790 jabber_iq_set_callback(iq, jabber_vcard_parse); | |
791 | |
792 jabber_iq_send(iq); | |
793 } | |
794 | |
795 void jabber_buddy_get_info_chat(GaimConnection *gc, int id, | |
796 const char *resource) | |
797 { | |
798 JabberStream *js = gc->proto_data; | |
799 JabberChat *chat = jabber_chat_find_by_id(js, id); | |
800 char *full_jid; | |
801 | |
802 if(!chat) | |
803 return; | |
804 | |
805 full_jid = g_strdup_printf("%s@%s/%s", chat->room, chat->server, resource); | |
806 jabber_buddy_get_info(gc, full_jid); | |
807 g_free(full_jid); | |
808 } | |
809 | |
810 static void jabber_buddy_set_invisibility(JabberStream *js, const char *who, | |
811 gboolean invisible) | |
812 { | |
813 JabberBuddy *jb = jabber_buddy_find(js, who, TRUE); | |
814 xmlnode *presence; | |
815 | |
816 presence = jabber_presence_create(js->gc->away_state, js->gc->away); | |
817 xmlnode_set_attrib(presence, "to", who); | |
818 if(invisible) { | |
819 xmlnode_set_attrib(presence, "type", "invisible"); | |
820 jb->invisible |= JABBER_INVIS_BUDDY; | |
821 } else { | |
822 jb->invisible &= ~JABBER_INVIS_BUDDY; | |
823 } | |
824 | |
825 jabber_send(js, presence); | |
826 xmlnode_free(presence); | |
827 } | |
828 | |
829 static void jabber_buddy_make_invisible(GaimConnection *gc, const char *name) | |
830 { | |
831 JabberStream *js = gc->proto_data; | |
832 jabber_buddy_set_invisibility(js, name, TRUE); | |
833 } | |
834 | |
835 static void jabber_buddy_make_visible(GaimConnection *gc, const char *name) | |
836 { | |
837 JabberStream *js = gc->proto_data; | |
838 jabber_buddy_set_invisibility(js, name, FALSE); | |
839 } | |
840 | |
841 static void jabber_buddy_cancel_presence_notification(GaimConnection *gc, | |
842 const char *name) | |
843 { | |
844 JabberStream *js = gc->proto_data; | |
845 | |
846 /* I wonder if we should prompt the user before doing this */ | |
847 jabber_presence_subscription_set(js, name, "unsubscribed"); | |
848 } | |
849 | |
850 static void jabber_buddy_rerequest_auth(GaimConnection *gc, const char *name) | |
851 { | |
852 JabberStream *js = gc->proto_data; | |
853 | |
854 jabber_presence_subscription_set(js, name, "subscribe"); | |
855 } | |
856 | |
7250 | 857 static void jabber_buddy_unsubscribe(GaimConnection *gc, const char *name) |
858 { | |
859 JabberStream *js = gc->proto_data; | |
860 | |
861 jabber_presence_subscription_set(js, name, "unsubscribe"); | |
862 } | |
863 | |
7014 | 864 GList *jabber_buddy_menu(GaimConnection *gc, const char *name) |
865 { | |
866 GList *m = NULL; | |
867 struct proto_buddy_menu *pbm; | |
868 JabberStream *js = gc->proto_data; | |
869 JabberBuddy *jb = jabber_buddy_find(js, name, TRUE); | |
870 | |
871 pbm = g_new0(struct proto_buddy_menu, 1); | |
872 if(jb->invisible & JABBER_INVIS_BUDDY) { | |
873 pbm->label = _("Un-hide From"); | |
874 pbm->callback = jabber_buddy_make_visible; | |
875 } else { | |
876 pbm->label = _("Temporarily Hide From"); | |
877 pbm->callback = jabber_buddy_make_invisible; | |
878 } | |
879 pbm->gc = gc; | |
880 m = g_list_append(m, pbm); | |
881 | |
882 if(jb->subscription & JABBER_SUB_FROM) { | |
883 pbm = g_new0(struct proto_buddy_menu, 1); | |
884 pbm->label = _("Cancel Presence Notification"); | |
885 pbm->callback = jabber_buddy_cancel_presence_notification; | |
886 pbm->gc = gc; | |
887 m = g_list_append(m, pbm); | |
888 } | |
889 | |
890 if(!(jb->subscription & JABBER_SUB_TO)) { | |
891 pbm = g_new0(struct proto_buddy_menu, 1); | |
7250 | 892 pbm->label = _("(Re-)Request authorization"); |
7014 | 893 pbm->callback = jabber_buddy_rerequest_auth; |
894 pbm->gc = gc; | |
895 m = g_list_append(m, pbm); | |
7250 | 896 } else { |
897 pbm = g_new0(struct proto_buddy_menu, 1); | |
898 pbm->label = _("Unsubscribe"); | |
899 pbm->callback = jabber_buddy_unsubscribe; | |
900 pbm->gc = gc; | |
901 m = g_list_append(m, pbm); | |
7014 | 902 } |
903 | |
904 return m; | |
905 } |