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