Mercurial > pidgin
annotate src/protocols/jabber/buddy.c @ 8185:3a229ad2fab0
[gaim-migrate @ 8906]
take 1 of UberUglyHack
committer: Tailor Script <tailor@pidgin.im>
author | Nathan Walp <nwalp@pidgin.im> |
---|---|
date | Fri, 30 Jan 2004 21:56:31 +0000 |
parents | ac7bf273bd66 |
children | 8d41a4250bb7 |
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; |
7955 | 533 char *bare_jid; |
7014 | 534 char *title; |
535 xmlnode *vcard; | |
7955 | 536 GaimBuddy *b; |
7014 | 537 |
538 if(!from) | |
539 return; | |
540 | |
7116 | 541 /* XXX: make this handle handle errors */ |
542 | |
7014 | 543 resource_name = jabber_get_resource(from); |
7955 | 544 bare_jid = jabber_get_bare_jid(from); |
545 | |
546 b = gaim_find_buddy(js->gc->account, bare_jid); | |
7014 | 547 |
548 jb = jabber_buddy_find(js, from, TRUE); | |
549 info_text = g_string_new(""); | |
550 | |
551 g_string_append_printf(info_text, "<b>%s:</b> %s<br/>\n", _("Jabber ID"), | |
552 from); | |
553 | |
554 if(resource_name) { | |
555 jbr = jabber_buddy_find_resource(jb, resource_name); | |
556 if(jbr) { | |
7145 | 557 char *purdy = NULL; |
558 if(jbr->status) | |
559 purdy = gaim_strdup_withhtml(jbr->status); | |
7014 | 560 g_string_append_printf(info_text, "<b>%s:</b> %s%s%s<br/>\n", |
561 _("Status"), jabber_get_state_string(jbr->state), | |
562 purdy ? ": " : "", | |
563 purdy ? purdy : ""); | |
7145 | 564 if(purdy) |
565 g_free(purdy); | |
7014 | 566 } else { |
567 g_string_append_printf(info_text, "<b>%s:</b> %s<br/>\n", | |
568 _("Status"), _("Unknown")); | |
569 } | |
570 } else { | |
571 for(resources = jb->resources; resources; resources = resources->next) { | |
7145 | 572 char *purdy = NULL; |
7014 | 573 jbr = resources->data; |
7145 | 574 if(jbr->status) |
575 purdy = gaim_strdup_withhtml(jbr->status); | |
7014 | 576 g_string_append_printf(info_text, "<b>%s:</b> %s<br/>\n", |
577 _("Resource"), jbr->name); | |
578 g_string_append_printf(info_text, "<b>%s:</b> %s%s%s<br/><br/>\n", | |
579 _("Status"), jabber_get_state_string(jbr->state), | |
580 purdy ? ": " : "", | |
581 purdy ? purdy : ""); | |
7145 | 582 if(purdy) |
583 g_free(purdy); | |
7014 | 584 } |
585 } | |
586 | |
7306 | 587 g_free(resource_name); |
7955 | 588 g_free(bare_jid); |
7306 | 589 |
7014 | 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 | |
8135 | 597 if(child->type != XMLNODE_TYPE_TAG) |
7014 | 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 | |
8135 | 609 if(child2->type != XMLNODE_TYPE_TAG) |
7014 | 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); | |
7955 | 630 if(b) { |
631 gaim_blist_node_set_string((GaimBlistNode*)b, "servernick", text); | |
632 gaim_blist_save(); | |
633 } | |
7014 | 634 g_string_append_printf(info_text, "<b>%s:</b> %s<br/>\n", |
635 _("Nickname"), text); | |
636 } else if(text && !strcmp(child->name, "BDAY")) { | |
637 g_string_append_printf(info_text, "<b>%s:</b> %s<br/>\n", | |
638 _("Birthday"), text); | |
639 } else if(!strcmp(child->name, "ADR")) { | |
640 /* show which address it is */ | |
641 if(child->child) | |
642 g_string_append_printf(info_text, "<b>%s:</b><br/>\n", | |
643 _("Address")); | |
644 for(child2 = child->child; child2; child2 = child2->next) | |
645 { | |
646 char *text2; | |
647 | |
8135 | 648 if(child2->type != XMLNODE_TYPE_TAG) |
7014 | 649 continue; |
650 | |
651 text2 = xmlnode_get_data(child2); | |
652 if(text2 && !strcmp(child2->name, "POBOX")) { | |
653 g_string_append_printf(info_text, | |
654 " <b>%s:</b> %s<br/>\n", | |
655 _("P.O. Box"), text2); | |
656 } else if(text2 && !strcmp(child2->name, "EXTADR")) { | |
657 g_string_append_printf(info_text, | |
658 " <b>%s:</b> %s<br/>\n", | |
659 _("Extended Address"), text2); | |
660 } else if(text2 && !strcmp(child2->name, "STREET")) { | |
661 g_string_append_printf(info_text, | |
662 " <b>%s:</b> %s<br/>\n", | |
663 _("Street Address"), text2); | |
664 } else if(text2 && !strcmp(child2->name, "LOCALITY")) { | |
665 g_string_append_printf(info_text, | |
666 " <b>%s:</b> %s<br/>\n", | |
667 _("Locality"), text2); | |
668 } else if(text2 && !strcmp(child2->name, "REGION")) { | |
669 g_string_append_printf(info_text, | |
670 " <b>%s:</b> %s<br/>\n", | |
671 _("Region"), text2); | |
672 } else if(text2 && !strcmp(child2->name, "PCODE")) { | |
673 g_string_append_printf(info_text, | |
674 " <b>%s:</b> %s<br/>\n", | |
675 _("Postal Code"), text2); | |
676 } else if(text2 && (!strcmp(child2->name, "CTRY") | |
677 || !strcmp(child2->name, "COUNTRY"))) { | |
678 g_string_append_printf(info_text, | |
679 " <b>%s:</b> %s<br/>\n", | |
680 _("Country"), text2); | |
681 } | |
682 g_free(text2); | |
683 } | |
684 } else if(!strcmp(child->name, "TEL")) { | |
685 char *number; | |
686 if((child2 = xmlnode_get_child(child, "NUMBER"))) { | |
687 /* show what kind of number it is */ | |
688 number = xmlnode_get_data(child2); | |
689 if(number) { | |
690 g_string_append_printf(info_text, | |
691 "<b>%s:</b> %s<br/>\n", _("Telephone"), number); | |
692 g_free(number); | |
693 } | |
694 } else if((number = xmlnode_get_data(child))) { | |
695 /* lots of clients (including gaim) do this, but it's | |
696 * out of spec */ | |
697 g_string_append_printf(info_text, | |
698 "<b>%s:</b> %s<br/>\n", _("Telephone"), number); | |
699 g_free(number); | |
700 } | |
701 } else if(!strcmp(child->name, "EMAIL")) { | |
702 char *userid; | |
703 if((child2 = xmlnode_get_child(child, "USERID"))) { | |
704 /* show what kind of email it is */ | |
705 userid = xmlnode_get_data(child2); | |
706 if(userid) { | |
707 g_string_append_printf(info_text, | |
708 "<b>%s:</b> <a href='mailto:%s'>%s</a><br/>\n", | |
709 _("Email"), userid, userid); | |
710 g_free(userid); | |
711 } | |
712 } else if((userid = xmlnode_get_data(child))) { | |
713 /* lots of clients (including gaim) do this, but it's | |
714 * out of spec */ | |
715 g_string_append_printf(info_text, | |
716 "<b>%s:</b> <a href='mailto:%s'>%s</a><br/>\n", | |
717 _("Email"), userid, userid); | |
718 g_free(userid); | |
719 } | |
720 } else if(!strcmp(child->name, "ORG")) { | |
721 for(child2 = child->child; child2; child2 = child2->next) | |
722 { | |
723 char *text2; | |
724 | |
8135 | 725 if(child2->type != XMLNODE_TYPE_TAG) |
7014 | 726 continue; |
727 | |
728 text2 = xmlnode_get_data(child2); | |
729 if(text2 && !strcmp(child2->name, "ORGNAME")) { | |
730 g_string_append_printf(info_text, | |
731 "<b>%s:</b> %s<br/>\n", | |
732 _("Organization Name"), text2); | |
733 } else if(text2 && !strcmp(child2->name, "ORGUNIT")) { | |
734 g_string_append_printf(info_text, | |
735 "<b>%s:</b> %s<br/>\n", | |
736 _("Organization Unit"), text2); | |
737 } | |
738 g_free(text2); | |
739 } | |
740 } else if(text && !strcmp(child->name, "TITLE")) { | |
741 g_string_append_printf(info_text, "<b>%s:</b> %s<br/>\n", | |
742 _("Title"), text); | |
743 } else if(text && !strcmp(child->name, "ROLE")) { | |
744 g_string_append_printf(info_text, "<b>%s:</b> %s<br/>\n", | |
745 _("Role"), text); | |
746 } else if(text && !strcmp(child->name, "DESC")) { | |
8166 | 747 char *text2 = gaim_strdup_withhtml(text); |
7014 | 748 g_string_append_printf(info_text, "<b>%s:</b> %s<br/>\n", |
8166 | 749 _("Description"), text2); |
750 g_free(text2); | |
7076 | 751 } else if(!strcmp(child->name, "PHOTO") || |
752 !strcmp(child->name, "LOGO")) { | |
753 if((child2 = xmlnode_get_child(child, "BINVAL"))) { | |
754 char *data, *text2; | |
755 int size, imgid; | |
756 if((text2 = xmlnode_get_data(child2))) { | |
7106
db6bd3e794d8
[gaim-migrate @ 7671]
Christian Hammond <chipx86@chipx86.com>
parents:
7076
diff
changeset
|
757 gaim_base64_decode(text2, &data, &size); |
7076 | 758 |
759 imgid = gaim_imgstore_add(data, size, "logo.png"); | |
760 g_string_append_printf(info_text, | |
7116 | 761 "<b>%s:</b> <img id='%d'><br/>", |
7076 | 762 strcmp(child->name, "PHOTO") == 0 ? |
763 _("Photo") : _("Logo"), | |
764 imgid); | |
765 | |
766 g_free(data); | |
767 g_free(text2); | |
768 } | |
769 } | |
7014 | 770 } |
771 g_free(text); | |
772 } | |
773 } | |
774 | |
775 title = g_strdup_printf("User info for %s", from); | |
776 | |
777 gaim_notify_formatted(NULL, title, _("Jabber Profile"), | |
778 NULL, info_text->str, NULL, NULL); | |
779 | |
780 g_free(title); | |
781 g_string_free(info_text, TRUE); | |
782 } | |
783 | |
784 void jabber_buddy_get_info(GaimConnection *gc, const char *who) | |
785 { | |
786 JabberStream *js = gc->proto_data; | |
787 JabberIq *iq; | |
788 xmlnode *vcard; | |
789 | |
790 iq = jabber_iq_new(js, JABBER_IQ_GET); | |
791 | |
792 xmlnode_set_attrib(iq->node, "to", who); | |
793 vcard = xmlnode_new_child(iq->node, "vCard"); | |
794 xmlnode_set_attrib(vcard, "xmlns", "vcard-temp"); | |
795 | |
7395 | 796 jabber_iq_set_callback(iq, jabber_vcard_parse, NULL); |
7014 | 797 |
798 jabber_iq_send(iq); | |
799 } | |
800 | |
801 void jabber_buddy_get_info_chat(GaimConnection *gc, int id, | |
802 const char *resource) | |
803 { | |
804 JabberStream *js = gc->proto_data; | |
805 JabberChat *chat = jabber_chat_find_by_id(js, id); | |
806 char *full_jid; | |
807 | |
808 if(!chat) | |
809 return; | |
810 | |
811 full_jid = g_strdup_printf("%s@%s/%s", chat->room, chat->server, resource); | |
812 jabber_buddy_get_info(gc, full_jid); | |
813 g_free(full_jid); | |
814 } | |
815 | |
7395 | 816 |
7757 | 817 #if 0 |
7395 | 818 static void jabber_buddy_ask_send_file(GaimConnection *gc, const char *name) |
819 { | |
820 JabberStream *js = gc->proto_data; | |
821 GaimXfer *xfer; | |
822 JabberSIXfer *jsx; | |
823 | |
824 xfer = gaim_xfer_new(gaim_connection_get_account(gc), GAIM_XFER_SEND, name); | |
825 | |
826 xfer->data = jsx = g_new0(JabberSIXfer, 1); | |
827 jsx->js = js; | |
828 | |
829 gaim_xfer_set_init_fnc(xfer, jabber_si_xfer_init); | |
830 gaim_xfer_set_start_fnc(xfer, jabber_si_xfer_start); | |
831 gaim_xfer_set_end_fnc(xfer, jabber_si_xfer_end); | |
832 gaim_xfer_set_cancel_send_fnc(xfer, jabber_si_xfer_cancel_send); | |
833 gaim_xfer_set_cancel_recv_fnc(xfer, jabber_si_xfer_cancel_recv); | |
834 gaim_xfer_set_ack_fnc(xfer, jabber_si_xfer_ack); | |
835 | |
836 js->file_transfers = g_list_append(js->file_transfers, xfer); | |
837 | |
838 gaim_xfer_request(xfer); | |
839 } | |
7757 | 840 #endif |
7395 | 841 |
7014 | 842 static void jabber_buddy_set_invisibility(JabberStream *js, const char *who, |
843 gboolean invisible) | |
844 { | |
845 JabberBuddy *jb = jabber_buddy_find(js, who, TRUE); | |
846 xmlnode *presence; | |
847 | |
848 presence = jabber_presence_create(js->gc->away_state, js->gc->away); | |
849 xmlnode_set_attrib(presence, "to", who); | |
850 if(invisible) { | |
851 xmlnode_set_attrib(presence, "type", "invisible"); | |
852 jb->invisible |= JABBER_INVIS_BUDDY; | |
853 } else { | |
854 jb->invisible &= ~JABBER_INVIS_BUDDY; | |
855 } | |
856 | |
857 jabber_send(js, presence); | |
858 xmlnode_free(presence); | |
859 } | |
860 | |
861 static void jabber_buddy_make_invisible(GaimConnection *gc, const char *name) | |
862 { | |
863 JabberStream *js = gc->proto_data; | |
864 jabber_buddy_set_invisibility(js, name, TRUE); | |
865 } | |
866 | |
867 static void jabber_buddy_make_visible(GaimConnection *gc, const char *name) | |
868 { | |
869 JabberStream *js = gc->proto_data; | |
870 jabber_buddy_set_invisibility(js, name, FALSE); | |
871 } | |
872 | |
873 static void jabber_buddy_cancel_presence_notification(GaimConnection *gc, | |
874 const char *name) | |
875 { | |
876 JabberStream *js = gc->proto_data; | |
877 | |
878 /* I wonder if we should prompt the user before doing this */ | |
879 jabber_presence_subscription_set(js, name, "unsubscribed"); | |
880 } | |
881 | |
882 static void jabber_buddy_rerequest_auth(GaimConnection *gc, const char *name) | |
883 { | |
884 JabberStream *js = gc->proto_data; | |
885 | |
886 jabber_presence_subscription_set(js, name, "subscribe"); | |
887 } | |
888 | |
7250 | 889 static void jabber_buddy_unsubscribe(GaimConnection *gc, const char *name) |
890 { | |
891 JabberStream *js = gc->proto_data; | |
892 | |
893 jabber_presence_subscription_set(js, name, "unsubscribe"); | |
894 } | |
895 | |
7014 | 896 GList *jabber_buddy_menu(GaimConnection *gc, const char *name) |
897 { | |
898 GList *m = NULL; | |
899 struct proto_buddy_menu *pbm; | |
900 JabberStream *js = gc->proto_data; | |
901 JabberBuddy *jb = jabber_buddy_find(js, name, TRUE); | |
7395 | 902 |
903 if(!jb) | |
904 return m; | |
905 | |
7425 | 906 /* XXX: should check capability once we know we want to send |
907 pbm = g_new0(struct proto_buddy_menu, 1); | |
908 pbm->label = _("Send File"); | |
909 pbm->callback = jabber_buddy_ask_send_file; | |
910 pbm->gc = gc; | |
911 m = g_list_append(m, pbm); | |
7395 | 912 |
7425 | 913 */ |
7014 | 914 |
8185 | 915 /* XXX: fix the NOT ME below */ |
916 | |
917 if(js->protocol_version == JABBER_PROTO_0_9 /* && NOT ME */) { | |
8166 | 918 pbm = g_new0(struct proto_buddy_menu, 1); |
919 if(jb->invisible & JABBER_INVIS_BUDDY) { | |
920 pbm->label = _("Un-hide From"); | |
921 pbm->callback = jabber_buddy_make_visible; | |
922 } else { | |
923 pbm->label = _("Temporarily Hide From"); | |
924 pbm->callback = jabber_buddy_make_invisible; | |
925 } | |
926 pbm->gc = gc; | |
927 m = g_list_append(m, pbm); | |
7014 | 928 } |
929 | |
8185 | 930 if(jb->subscription & JABBER_SUB_FROM /* && NOT ME */) { |
7014 | 931 pbm = g_new0(struct proto_buddy_menu, 1); |
932 pbm->label = _("Cancel Presence Notification"); | |
933 pbm->callback = jabber_buddy_cancel_presence_notification; | |
934 pbm->gc = gc; | |
935 m = g_list_append(m, pbm); | |
936 } | |
937 | |
938 if(!(jb->subscription & JABBER_SUB_TO)) { | |
939 pbm = g_new0(struct proto_buddy_menu, 1); | |
7250 | 940 pbm->label = _("(Re-)Request authorization"); |
7014 | 941 pbm->callback = jabber_buddy_rerequest_auth; |
942 pbm->gc = gc; | |
943 m = g_list_append(m, pbm); | |
8185 | 944 } else /* if(NOT ME) */{ |
7250 | 945 pbm = g_new0(struct proto_buddy_menu, 1); |
946 pbm->label = _("Unsubscribe"); | |
947 pbm->callback = jabber_buddy_unsubscribe; | |
948 pbm->gc = gc; | |
949 m = g_list_append(m, pbm); | |
7014 | 950 } |
951 | |
952 return m; | |
953 } |