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