14192
|
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 "cipher.h"
|
|
23 #include "debug.h"
|
|
24 #include "imgstore.h"
|
|
25 #include "prpl.h"
|
|
26 #include "notify.h"
|
|
27 #include "request.h"
|
|
28 #include "util.h"
|
|
29 #include "xmlnode.h"
|
|
30
|
|
31 #include "buddy.h"
|
|
32 #include "chat.h"
|
|
33 #include "jabber.h"
|
|
34 #include "iq.h"
|
|
35 #include "presence.h"
|
|
36 #include "xdata.h"
|
|
37
|
|
38 typedef struct {
|
|
39 long idle_seconds;
|
|
40 } JabberBuddyInfoResource;
|
|
41
|
|
42 typedef struct {
|
|
43 JabberStream *js;
|
|
44 JabberBuddy *jb;
|
|
45 char *jid;
|
|
46 GSList *ids;
|
|
47 GHashTable *resources;
|
|
48 int timeout_handle;
|
|
49 char *vcard_text;
|
|
50 GSList *vcard_imgids;
|
|
51 } JabberBuddyInfo;
|
|
52
|
|
53 void jabber_buddy_free(JabberBuddy *jb)
|
|
54 {
|
|
55 g_return_if_fail(jb != NULL);
|
|
56
|
|
57 if(jb->error_msg)
|
|
58 g_free(jb->error_msg);
|
|
59 while(jb->resources)
|
|
60 jabber_buddy_resource_free(jb->resources->data);
|
|
61
|
|
62 g_free(jb);
|
|
63 }
|
|
64
|
|
65 JabberBuddy *jabber_buddy_find(JabberStream *js, const char *name,
|
|
66 gboolean create)
|
|
67 {
|
|
68 JabberBuddy *jb;
|
|
69 const char *realname;
|
|
70
|
15082
|
71 if (js->buddies == NULL)
|
|
72 return NULL;
|
|
73
|
14192
|
74 if(!(realname = jabber_normalize(js->gc->account, name)))
|
|
75 return NULL;
|
|
76
|
|
77 jb = g_hash_table_lookup(js->buddies, realname);
|
|
78
|
|
79 if(!jb && create) {
|
|
80 jb = g_new0(JabberBuddy, 1);
|
|
81 g_hash_table_insert(js->buddies, g_strdup(realname), jb);
|
|
82 }
|
|
83
|
|
84 return jb;
|
|
85 }
|
|
86
|
|
87
|
|
88 JabberBuddyResource *jabber_buddy_find_resource(JabberBuddy *jb,
|
|
89 const char *resource)
|
|
90 {
|
|
91 JabberBuddyResource *jbr = NULL;
|
|
92 GList *l;
|
|
93
|
|
94 if(!jb)
|
|
95 return NULL;
|
|
96
|
|
97 for(l = jb->resources; l; l = l->next)
|
|
98 {
|
|
99 if(!jbr && !resource) {
|
|
100 jbr = l->data;
|
|
101 } else if(!resource) {
|
|
102 if(((JabberBuddyResource *)l->data)->priority >= jbr->priority)
|
|
103 jbr = l->data;
|
|
104 } else if(((JabberBuddyResource *)l->data)->name) {
|
|
105 if(!strcmp(((JabberBuddyResource *)l->data)->name, resource)) {
|
|
106 jbr = l->data;
|
|
107 break;
|
|
108 }
|
|
109 }
|
|
110 }
|
|
111
|
|
112 return jbr;
|
|
113 }
|
|
114
|
|
115 JabberBuddyResource *jabber_buddy_track_resource(JabberBuddy *jb, const char *resource,
|
|
116 int priority, JabberBuddyState state, const char *status)
|
|
117 {
|
|
118 JabberBuddyResource *jbr = jabber_buddy_find_resource(jb, resource);
|
|
119
|
|
120 if(!jbr) {
|
|
121 jbr = g_new0(JabberBuddyResource, 1);
|
|
122 jbr->jb = jb;
|
|
123 jbr->name = g_strdup(resource);
|
|
124 jbr->capabilities = JABBER_CAP_XHTML;
|
|
125 jb->resources = g_list_append(jb->resources, jbr);
|
|
126 }
|
|
127 jbr->priority = priority;
|
|
128 jbr->state = state;
|
|
129 if(jbr->status)
|
|
130 g_free(jbr->status);
|
|
131 if (status)
|
|
132 jbr->status = g_markup_escape_text(status, -1);
|
|
133 else
|
|
134 jbr->status = NULL;
|
|
135
|
|
136 return jbr;
|
|
137 }
|
|
138
|
|
139 void jabber_buddy_resource_free(JabberBuddyResource *jbr)
|
|
140 {
|
|
141 g_return_if_fail(jbr != NULL);
|
|
142
|
|
143 jbr->jb->resources = g_list_remove(jbr->jb->resources, jbr);
|
|
144
|
|
145 g_free(jbr->name);
|
|
146 g_free(jbr->status);
|
|
147 g_free(jbr->thread_id);
|
|
148 g_free(jbr->client.name);
|
|
149 g_free(jbr->client.version);
|
|
150 g_free(jbr->client.os);
|
|
151 g_free(jbr);
|
|
152 }
|
|
153
|
|
154 void jabber_buddy_remove_resource(JabberBuddy *jb, const char *resource)
|
|
155 {
|
|
156 JabberBuddyResource *jbr = jabber_buddy_find_resource(jb, resource);
|
|
157
|
|
158 if(!jbr)
|
|
159 return;
|
|
160
|
|
161 jabber_buddy_resource_free(jbr);
|
|
162 }
|
|
163
|
|
164 const char *jabber_buddy_get_status_msg(JabberBuddy *jb)
|
|
165 {
|
|
166 JabberBuddyResource *jbr;
|
|
167
|
|
168 if(!jb)
|
|
169 return NULL;
|
|
170
|
|
171 jbr = jabber_buddy_find_resource(jb, NULL);
|
|
172
|
|
173 if(!jbr)
|
|
174 return NULL;
|
|
175
|
|
176 return jbr->status;
|
|
177 }
|
|
178
|
|
179 /*******
|
|
180 * This is the old vCard stuff taken from the old prpl. vCards, by definition
|
|
181 * are a temporary thing until jabber can get its act together and come up
|
|
182 * with a format for user information, hence the namespace of 'vcard-temp'
|
|
183 *
|
|
184 * Since I don't feel like putting that much work into something that's
|
|
185 * _supposed_ to go away, i'm going to just copy the kludgy old code here,
|
|
186 * and make it purdy when jabber comes up with a standards-track JEP to
|
|
187 * replace vcard-temp
|
|
188 * --Nathan
|
|
189 *******/
|
|
190
|
|
191 /*---------------------------------------*/
|
|
192 /* Jabber "set info" (vCard) support */
|
|
193 /*---------------------------------------*/
|
|
194
|
|
195 /*
|
|
196 * V-Card format:
|
|
197 *
|
|
198 * <vCard prodid='' version='' xmlns=''>
|
|
199 * <FN></FN>
|
|
200 * <N>
|
|
201 * <FAMILY/>
|
|
202 * <GIVEN/>
|
|
203 * </N>
|
|
204 * <NICKNAME/>
|
|
205 * <URL/>
|
|
206 * <ADR>
|
|
207 * <STREET/>
|
|
208 * <EXTADD/>
|
|
209 * <LOCALITY/>
|
|
210 * <REGION/>
|
|
211 * <PCODE/>
|
|
212 * <COUNTRY/>
|
|
213 * </ADR>
|
|
214 * <TEL/>
|
|
215 * <EMAIL/>
|
|
216 * <ORG>
|
|
217 * <ORGNAME/>
|
|
218 * <ORGUNIT/>
|
|
219 * </ORG>
|
|
220 * <TITLE/>
|
|
221 * <ROLE/>
|
|
222 * <DESC/>
|
|
223 * <BDAY/>
|
|
224 * </vCard>
|
|
225 *
|
|
226 * See also:
|
|
227 *
|
|
228 * http://docs.jabber.org/proto/html/vcard-temp.html
|
|
229 * http://www.vcard-xml.org/dtd/vCard-XML-v2-20010520.dtd
|
|
230 */
|
|
231
|
|
232 /*
|
|
233 * Cross-reference user-friendly V-Card entry labels to vCard XML tags
|
|
234 * and attributes.
|
|
235 *
|
|
236 * Order is (or should be) unimportant. For example: we have no way of
|
|
237 * knowing in what order real data will arrive.
|
|
238 *
|
|
239 * Format: Label, Pre-set text, "visible" flag, "editable" flag, XML tag
|
|
240 * name, XML tag's parent tag "path" (relative to vCard node).
|
|
241 *
|
|
242 * List is terminated by a NULL label pointer.
|
|
243 *
|
|
244 * Entries with no label text, but with XML tag and parent tag
|
|
245 * entries, are used by V-Card XML construction routines to
|
|
246 * "automagically" construct the appropriate XML node tree.
|
|
247 *
|
|
248 * Thoughts on future direction/expansion
|
|
249 *
|
|
250 * This is a "simple" vCard.
|
|
251 *
|
|
252 * It is possible for nodes other than the "vCard" node to have
|
|
253 * attributes. Should that prove necessary/desirable, add an
|
|
254 * "attributes" pointer to the vcard_template struct, create the
|
|
255 * necessary tag_attr structs, and add 'em to the vcard_dflt_data
|
|
256 * array.
|
|
257 *
|
|
258 * The above changes will (obviously) require changes to the vCard
|
|
259 * construction routines.
|
|
260 */
|
|
261
|
|
262 struct vcard_template {
|
|
263 char *label; /* label text pointer */
|
|
264 char *text; /* entry text pointer */
|
|
265 int visible; /* should entry field be "visible?" */
|
|
266 int editable; /* should entry field be editable? */
|
|
267 char *tag; /* tag text */
|
|
268 char *ptag; /* parent tag "path" text */
|
|
269 char *url; /* vCard display format if URL */
|
|
270 } vcard_template_data[] = {
|
|
271 {N_("Full Name"), NULL, TRUE, TRUE, "FN", NULL, NULL},
|
|
272 {N_("Family Name"), NULL, TRUE, TRUE, "FAMILY", "N", NULL},
|
|
273 {N_("Given Name"), NULL, TRUE, TRUE, "GIVEN", "N", NULL},
|
|
274 {N_("Nickname"), NULL, TRUE, TRUE, "NICKNAME", NULL, NULL},
|
|
275 {N_("URL"), NULL, TRUE, TRUE, "URL", NULL, "<A HREF=\"%s\">%s</A>"},
|
|
276 {N_("Street Address"), NULL, TRUE, TRUE, "STREET", "ADR", NULL},
|
|
277 {N_("Extended Address"), NULL, TRUE, TRUE, "EXTADD", "ADR", NULL},
|
|
278 {N_("Locality"), NULL, TRUE, TRUE, "LOCALITY", "ADR", NULL},
|
|
279 {N_("Region"), NULL, TRUE, TRUE, "REGION", "ADR", NULL},
|
|
280 {N_("Postal Code"), NULL, TRUE, TRUE, "PCODE", "ADR", NULL},
|
|
281 {N_("Country"), NULL, TRUE, TRUE, "CTRY", "ADR", NULL},
|
|
282 {N_("Telephone"), NULL, TRUE, TRUE, "NUMBER", "TEL", NULL},
|
|
283 {N_("E-Mail"), NULL, TRUE, TRUE, "USERID", "EMAIL", "<A HREF=\"mailto:%s\">%s</A>"},
|
|
284 {N_("Organization Name"), NULL, TRUE, TRUE, "ORGNAME", "ORG", NULL},
|
|
285 {N_("Organization Unit"), NULL, TRUE, TRUE, "ORGUNIT", "ORG", NULL},
|
|
286 {N_("Title"), NULL, TRUE, TRUE, "TITLE", NULL, NULL},
|
|
287 {N_("Role"), NULL, TRUE, TRUE, "ROLE", NULL, NULL},
|
|
288 {N_("Birthday"), NULL, TRUE, TRUE, "BDAY", NULL, NULL},
|
|
289 {N_("Description"), NULL, TRUE, TRUE, "DESC", NULL, NULL},
|
|
290 {"", NULL, TRUE, TRUE, "N", NULL, NULL},
|
|
291 {"", NULL, TRUE, TRUE, "ADR", NULL, NULL},
|
|
292 {"", NULL, TRUE, TRUE, "ORG", NULL, NULL},
|
|
293 {NULL, NULL, 0, 0, NULL, NULL, NULL}
|
|
294 };
|
|
295
|
|
296 /*
|
|
297 * The "vCard" tag's attribute list...
|
|
298 */
|
|
299 struct tag_attr {
|
|
300 char *attr;
|
|
301 char *value;
|
|
302 } vcard_tag_attr_list[] = {
|
|
303 {"prodid", "-//HandGen//NONSGML vGen v1.0//EN"},
|
|
304 {"version", "2.0", },
|
|
305 {"xmlns", "vcard-temp", },
|
|
306 {NULL, NULL},
|
|
307 };
|
|
308
|
|
309
|
|
310 /*
|
|
311 * Insert a tag node into an xmlnode tree, recursively inserting parent tag
|
|
312 * nodes as necessary
|
|
313 *
|
|
314 * Returns pointer to inserted node
|
|
315 *
|
|
316 * Note to hackers: this code is designed to be re-entrant (it's recursive--it
|
|
317 * calls itself), so don't put any "static"s in here!
|
|
318 */
|
|
319 static xmlnode *insert_tag_to_parent_tag(xmlnode *start, const char *parent_tag, const char *new_tag)
|
|
320 {
|
|
321 xmlnode *x = NULL;
|
|
322
|
|
323 /*
|
|
324 * If the parent tag wasn't specified, see if we can get it
|
|
325 * from the vCard template struct.
|
|
326 */
|
|
327 if(parent_tag == NULL) {
|
|
328 struct vcard_template *vc_tp = vcard_template_data;
|
|
329
|
|
330 while(vc_tp->label != NULL) {
|
|
331 if(strcmp(vc_tp->tag, new_tag) == 0) {
|
|
332 parent_tag = vc_tp->ptag;
|
|
333 break;
|
|
334 }
|
|
335 ++vc_tp;
|
|
336 }
|
|
337 }
|
|
338
|
|
339 /*
|
|
340 * If we have a parent tag...
|
|
341 */
|
|
342 if(parent_tag != NULL ) {
|
|
343 /*
|
|
344 * Try to get the parent node for a tag
|
|
345 */
|
|
346 if((x = xmlnode_get_child(start, parent_tag)) == NULL) {
|
|
347 /*
|
|
348 * Descend?
|
|
349 */
|
|
350 char *grand_parent = g_strdup(parent_tag);
|
|
351 char *parent;
|
|
352
|
|
353 if((parent = strrchr(grand_parent, '/')) != NULL) {
|
|
354 *(parent++) = '\0';
|
|
355 x = insert_tag_to_parent_tag(start, grand_parent, parent);
|
|
356 } else {
|
|
357 x = xmlnode_new_child(start, grand_parent);
|
|
358 }
|
|
359 g_free(grand_parent);
|
|
360 } else {
|
|
361 /*
|
|
362 * We found *something* to be the parent node.
|
|
363 * Note: may be the "root" node!
|
|
364 */
|
|
365 xmlnode *y;
|
|
366 if((y = xmlnode_get_child(x, new_tag)) != NULL) {
|
|
367 return(y);
|
|
368 }
|
|
369 }
|
|
370 }
|
|
371
|
|
372 /*
|
|
373 * insert the new tag into its parent node
|
|
374 */
|
|
375 return(xmlnode_new_child((x == NULL? start : x), new_tag));
|
|
376 }
|
|
377
|
|
378 /*
|
|
379 * Send vCard info to Jabber server
|
|
380 */
|
|
381 void jabber_set_info(GaimConnection *gc, const char *info)
|
|
382 {
|
|
383 JabberIq *iq;
|
|
384 JabberStream *js = gc->proto_data;
|
|
385 xmlnode *vc_node;
|
|
386 char *avatar_file = NULL;
|
|
387 struct tag_attr *tag_attr;
|
|
388
|
|
389 if(js->avatar_hash)
|
|
390 g_free(js->avatar_hash);
|
|
391 js->avatar_hash = NULL;
|
|
392
|
|
393 /*
|
|
394 * Send only if there's actually any *information* to send
|
|
395 */
|
|
396 vc_node = info ? xmlnode_from_str(info, -1) : NULL;
|
|
397 avatar_file = gaim_buddy_icons_get_full_path(gaim_account_get_buddy_icon(gc->account));
|
|
398
|
|
399 if(!vc_node && avatar_file) {
|
|
400 vc_node = xmlnode_new("vCard");
|
|
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
|
|
405 if(vc_node) {
|
|
406 if (vc_node->name &&
|
|
407 !g_ascii_strncasecmp(vc_node->name, "vCard", 5)) {
|
|
408 GError *error = NULL;
|
|
409 gchar *avatar_data_tmp;
|
|
410 guchar *avatar_data;
|
|
411 gsize avatar_len;
|
|
412
|
|
413 if(avatar_file && g_file_get_contents(avatar_file, &avatar_data_tmp, &avatar_len, &error)) {
|
|
414 xmlnode *photo, *binval;
|
|
415 gchar *enc;
|
|
416 int i;
|
|
417 unsigned char hashval[20];
|
|
418 char *p, hash[41];
|
|
419
|
|
420 avatar_data = (guchar *) avatar_data_tmp;
|
|
421 photo = xmlnode_new_child(vc_node, "PHOTO");
|
|
422 binval = xmlnode_new_child(photo, "BINVAL");
|
|
423 enc = gaim_base64_encode(avatar_data, avatar_len);
|
|
424
|
|
425 gaim_cipher_digest_region("sha1", (guchar *)avatar_data,
|
|
426 avatar_len, sizeof(hashval),
|
|
427 hashval, NULL);
|
|
428
|
|
429 p = hash;
|
|
430 for(i=0; i<20; i++, p+=2)
|
|
431 snprintf(p, 3, "%02x", hashval[i]);
|
|
432 js->avatar_hash = g_strdup(hash);
|
|
433
|
|
434 xmlnode_insert_data(binval, enc, -1);
|
|
435 g_free(enc);
|
|
436 g_free(avatar_data);
|
|
437 } else if (error != NULL) {
|
|
438 g_error_free(error);
|
|
439 }
|
|
440 g_free(avatar_file);
|
|
441
|
|
442 iq = jabber_iq_new(js, JABBER_IQ_SET);
|
|
443 xmlnode_insert_child(iq->node, vc_node);
|
|
444 jabber_iq_send(iq);
|
|
445 } else {
|
|
446 xmlnode_free(vc_node);
|
|
447 }
|
|
448 }
|
|
449 }
|
|
450
|
|
451 void jabber_set_buddy_icon(GaimConnection *gc, const char *iconfile)
|
|
452 {
|
|
453 GaimPresence *gpresence;
|
|
454 GaimStatus *status;
|
|
455
|
|
456 jabber_set_info(gc, gaim_account_get_user_info(gc->account));
|
|
457
|
|
458 gpresence = gaim_account_get_presence(gc->account);
|
|
459 status = gaim_presence_get_active_status(gpresence);
|
|
460 jabber_presence_send(gc->account, status);
|
|
461 }
|
|
462
|
|
463 /*
|
|
464 * This is the callback from the "ok clicked" for "set vCard"
|
|
465 *
|
|
466 * Formats GSList data into XML-encoded string and returns a pointer
|
|
467 * to said string.
|
|
468 *
|
|
469 * g_free()'ing the returned string space is the responsibility of
|
|
470 * the caller.
|
|
471 */
|
|
472 static void
|
|
473 jabber_format_info(GaimConnection *gc, GaimRequestFields *fields)
|
|
474 {
|
|
475 xmlnode *vc_node;
|
|
476 GaimRequestField *field;
|
|
477 const char *text;
|
|
478 char *p;
|
|
479 const struct vcard_template *vc_tp;
|
|
480 struct tag_attr *tag_attr;
|
|
481
|
|
482 vc_node = xmlnode_new("vCard");
|
|
483
|
|
484 for(tag_attr = vcard_tag_attr_list; tag_attr->attr != NULL; ++tag_attr)
|
|
485 xmlnode_set_attrib(vc_node, tag_attr->attr, tag_attr->value);
|
|
486
|
|
487 for (vc_tp = vcard_template_data; vc_tp->label != NULL; vc_tp++) {
|
|
488 if (*vc_tp->label == '\0')
|
|
489 continue;
|
|
490
|
|
491 field = gaim_request_fields_get_field(fields, vc_tp->tag);
|
|
492 text = gaim_request_field_string_get_value(field);
|
|
493
|
|
494
|
|
495 if (text != NULL && *text != '\0') {
|
|
496 xmlnode *xp;
|
|
497
|
|
498 gaim_debug(GAIM_DEBUG_INFO, "jabber",
|
|
499 "Setting %s to '%s'\n", vc_tp->tag, text);
|
|
500
|
|
501 if ((xp = insert_tag_to_parent_tag(vc_node,
|
|
502 NULL, vc_tp->tag)) != NULL) {
|
|
503
|
|
504 xmlnode_insert_data(xp, text, -1);
|
|
505 }
|
|
506 }
|
|
507 }
|
|
508
|
|
509 p = xmlnode_to_str(vc_node, NULL);
|
|
510 xmlnode_free(vc_node);
|
|
511
|
14607
|
512 gaim_account_set_user_info(gaim_connection_get_account(gc), p);
|
|
513 serv_set_info(gc, p);
|
14192
|
514
|
|
515 g_free(p);
|
|
516 }
|
|
517
|
|
518 /*
|
|
519 * This gets executed by the proto action
|
|
520 *
|
|
521 * Creates a new GaimRequestFields struct, gets the XML-formatted user_info
|
|
522 * string (if any) into GSLists for the (multi-entry) edit dialog and
|
|
523 * calls the set_vcard dialog.
|
|
524 */
|
|
525 void jabber_setup_set_info(GaimPluginAction *action)
|
|
526 {
|
|
527 GaimConnection *gc = (GaimConnection *) action->context;
|
|
528 GaimRequestFields *fields;
|
|
529 GaimRequestFieldGroup *group;
|
|
530 GaimRequestField *field;
|
|
531 const struct vcard_template *vc_tp;
|
|
532 const char *user_info;
|
|
533 char *cdata = NULL;
|
|
534 xmlnode *x_vc_data = NULL;
|
|
535
|
|
536 fields = gaim_request_fields_new();
|
|
537 group = gaim_request_field_group_new(NULL);
|
|
538 gaim_request_fields_add_group(fields, group);
|
|
539
|
|
540 /*
|
|
541 * Get existing, XML-formatted, user info
|
|
542 */
|
|
543 if((user_info = gaim_account_get_user_info(gc->account)) != NULL)
|
|
544 x_vc_data = xmlnode_from_str(user_info, -1);
|
|
545
|
|
546 /*
|
|
547 * Set up GSLists for edit with labels from "template," data from user info
|
|
548 */
|
|
549 for(vc_tp = vcard_template_data; vc_tp->label != NULL; ++vc_tp) {
|
|
550 xmlnode *data_node;
|
|
551 if((vc_tp->label)[0] == '\0')
|
|
552 continue;
|
|
553
|
|
554 if (x_vc_data != NULL) {
|
|
555 if(vc_tp->ptag == NULL) {
|
|
556 data_node = xmlnode_get_child(x_vc_data, vc_tp->tag);
|
|
557 } else {
|
|
558 gchar *tag = g_strdup_printf("%s/%s", vc_tp->ptag, vc_tp->tag);
|
|
559 data_node = xmlnode_get_child(x_vc_data, tag);
|
|
560 g_free(tag);
|
|
561 }
|
|
562 if(data_node)
|
|
563 cdata = xmlnode_get_data(data_node);
|
|
564 }
|
|
565
|
|
566 if(strcmp(vc_tp->tag, "DESC") == 0) {
|
|
567 field = gaim_request_field_string_new(vc_tp->tag,
|
|
568 _(vc_tp->label), cdata,
|
|
569 TRUE);
|
|
570 } else {
|
|
571 field = gaim_request_field_string_new(vc_tp->tag,
|
|
572 _(vc_tp->label), cdata,
|
|
573 FALSE);
|
|
574 }
|
|
575
|
|
576 g_free(cdata);
|
|
577 cdata = NULL;
|
|
578
|
|
579 gaim_request_field_group_add_field(group, field);
|
|
580 }
|
|
581
|
|
582 if(x_vc_data != NULL)
|
|
583 xmlnode_free(x_vc_data);
|
|
584
|
|
585 gaim_request_fields(gc, _("Edit Jabber vCard"),
|
|
586 _("Edit Jabber vCard"),
|
|
587 _("All items below are optional. Enter only the "
|
|
588 "information with which you feel comfortable."),
|
|
589 fields,
|
|
590 _("Save"), G_CALLBACK(jabber_format_info),
|
|
591 _("Cancel"), NULL,
|
|
592 gc);
|
|
593 }
|
|
594
|
|
595 /*---------------------------------------*/
|
|
596 /* End Jabber "set info" (vCard) support */
|
|
597 /*---------------------------------------*/
|
|
598
|
|
599 /******
|
|
600 * end of that ancient crap that needs to die
|
|
601 ******/
|
|
602
|
|
603 static void jabber_buddy_info_show_if_ready(JabberBuddyInfo *jbi)
|
|
604 {
|
|
605 GString *info_text;
|
|
606 char *resource_name;
|
|
607 JabberBuddyResource *jbr;
|
15031
|
608 JabberBuddyInfoResource *jbir = NULL;
|
14192
|
609 GList *resources;
|
|
610
|
|
611 /* not yet */
|
|
612 if(jbi->ids)
|
|
613 return;
|
|
614
|
|
615 info_text = g_string_new("");
|
|
616 resource_name = jabber_get_resource(jbi->jid);
|
|
617
|
|
618 if(resource_name) {
|
|
619 jbr = jabber_buddy_find_resource(jbi->jb, resource_name);
|
|
620 jbir = g_hash_table_lookup(jbi->resources, resource_name);
|
|
621 if(jbr) {
|
|
622 char *purdy = NULL;
|
|
623 if(jbr->status)
|
|
624 purdy = gaim_strdup_withhtml(jbr->status);
|
|
625 g_string_append_printf(info_text, "<b>%s:</b> %s%s%s<br/>",
|
|
626 _("Status"), jabber_buddy_state_get_name(jbr->state),
|
|
627 purdy ? ": " : "",
|
|
628 purdy ? purdy : "");
|
|
629 if(purdy)
|
|
630 g_free(purdy);
|
|
631 } else {
|
|
632 g_string_append_printf(info_text, "<b>%s:</b> %s<br/>",
|
|
633 _("Status"), _("Unknown"));
|
|
634 }
|
|
635 if(jbir) {
|
|
636 if(jbir->idle_seconds > 0) {
|
|
637 g_string_append_printf(info_text, "<b>%s:</b> %s<br/>",
|
|
638 _("Idle"), gaim_str_seconds_to_string(jbir->idle_seconds));
|
|
639 }
|
|
640 }
|
|
641 if(jbr && jbr->client.name) {
|
|
642 g_string_append_printf(info_text, "<b>%s:</b> %s %s<br/>",
|
|
643 _("Client:"), jbr->client.name,
|
|
644 jbr->client.version ? jbr->client.version : "");
|
|
645 if(jbr->client.os) {
|
|
646 g_string_append_printf(info_text, "<b>%s:</b> %s<br/>",
|
|
647 _("Operating System"), jbr->client.os);
|
|
648 }
|
|
649 }
|
|
650 } else {
|
|
651 for(resources = jbi->jb->resources; resources; resources = resources->next) {
|
|
652 char *purdy = NULL;
|
|
653 jbr = resources->data;
|
|
654 if(jbr->status)
|
|
655 purdy = gaim_strdup_withhtml(jbr->status);
|
15031
|
656 if(jbr->name)
|
|
657 g_string_append_printf(info_text, "<b>%s:</b> %s<br/>",
|
|
658 _("Resource"), jbr->name);
|
14463
|
659 g_string_append_printf(info_text, "<b>%s:</b> %d<br/>",
|
|
660 _("Priority"), jbr->priority);
|
14192
|
661 g_string_append_printf(info_text, "<b>%s:</b> %s%s%s<br/>",
|
|
662 _("Status"), jabber_buddy_state_get_name(jbr->state),
|
|
663 purdy ? ": " : "",
|
|
664 purdy ? purdy : "");
|
|
665 if(purdy)
|
|
666 g_free(purdy);
|
|
667
|
15031
|
668 if(jbr->name)
|
|
669 jbir = g_hash_table_lookup(jbi->resources, jbr->name);
|
|
670
|
14192
|
671 if(jbir) {
|
|
672 if(jbir->idle_seconds > 0) {
|
|
673 g_string_append_printf(info_text, "<b>%s:</b> %s<br/>",
|
|
674 _("Idle"), gaim_str_seconds_to_string(jbir->idle_seconds));
|
|
675 }
|
|
676 }
|
|
677 if(jbr->client.name) {
|
|
678 g_string_append_printf(info_text, "<b>%s:</b> %s %s<br/>",
|
|
679 _("Client"), jbr->client.name,
|
|
680 jbr->client.version ? jbr->client.version : "");
|
|
681 if(jbr->client.os) {
|
|
682 g_string_append_printf(info_text, "<b>%s:</b> %s<br/>",
|
|
683 _("Operating System"), jbr->client.os);
|
|
684 }
|
|
685 }
|
|
686
|
|
687 g_string_append_printf(info_text, "<br/>");
|
|
688 }
|
|
689 }
|
|
690
|
|
691 g_free(resource_name);
|
|
692
|
|
693 if (jbi->vcard_text != NULL)
|
|
694 info_text = g_string_append(info_text, jbi->vcard_text);
|
|
695
|
|
696 gaim_notify_userinfo(jbi->js->gc, jbi->jid, info_text->str, NULL, NULL);
|
|
697
|
|
698 while(jbi->vcard_imgids) {
|
|
699 gaim_imgstore_unref(GPOINTER_TO_INT(jbi->vcard_imgids->data));
|
|
700 jbi->vcard_imgids = g_slist_delete_link(jbi->vcard_imgids, jbi->vcard_imgids);
|
|
701 }
|
|
702
|
|
703 g_string_free(info_text, TRUE);
|
|
704
|
|
705 if (jbi->timeout_handle > 0)
|
|
706 gaim_timeout_remove(jbi->timeout_handle);
|
|
707
|
|
708 g_free(jbi->jid);
|
|
709 g_hash_table_destroy(jbi->resources);
|
|
710 g_free(jbi->vcard_text);
|
|
711 g_free(jbi);
|
|
712 }
|
|
713
|
|
714 static void jabber_buddy_info_remove_id(JabberBuddyInfo *jbi, const char *id)
|
|
715 {
|
|
716 GSList *l = jbi->ids;
|
|
717
|
|
718 if(!id)
|
|
719 return;
|
|
720
|
|
721 while(l) {
|
|
722 if(!strcmp(id, l->data)) {
|
|
723 jbi->ids = g_slist_remove(jbi->ids, l->data);
|
|
724 return;
|
|
725 }
|
|
726 l = l->next;
|
|
727 }
|
|
728 }
|
|
729
|
|
730 static void jabber_vcard_parse(JabberStream *js, xmlnode *packet, gpointer data)
|
|
731 {
|
|
732 const char *id, *from;
|
|
733 GString *info_text;
|
|
734 char *bare_jid;
|
|
735 char *text;
|
|
736 xmlnode *vcard;
|
|
737 GaimBuddy *b;
|
|
738 JabberBuddyInfo *jbi = data;
|
|
739
|
|
740 from = xmlnode_get_attrib(packet, "from");
|
|
741 id = xmlnode_get_attrib(packet, "id");
|
|
742
|
|
743 if(!jbi)
|
|
744 return;
|
|
745
|
|
746 jabber_buddy_info_remove_id(jbi, id);
|
|
747
|
|
748 if(!from)
|
|
749 return;
|
|
750
|
|
751 if(!jabber_buddy_find(js, from, FALSE))
|
|
752 return;
|
|
753
|
|
754 /* XXX: handle the error case */
|
|
755
|
|
756 bare_jid = jabber_get_bare_jid(from);
|
|
757
|
|
758 b = gaim_find_buddy(js->gc->account, bare_jid);
|
|
759
|
|
760 info_text = g_string_new("");
|
|
761
|
|
762 if((vcard = xmlnode_get_child(packet, "vCard")) ||
|
|
763 (vcard = xmlnode_get_child_with_namespace(packet, "query", "vcard-temp"))) {
|
|
764 xmlnode *child;
|
|
765 for(child = vcard->child; child; child = child->next)
|
|
766 {
|
|
767 xmlnode *child2;
|
|
768
|
|
769 if(child->type != XMLNODE_TYPE_TAG)
|
|
770 continue;
|
|
771
|
|
772 text = xmlnode_get_data(child);
|
|
773 if(text && !strcmp(child->name, "FN")) {
|
|
774 g_string_append_printf(info_text, "<b>%s:</b> %s<br/>",
|
|
775 _("Full Name"), text);
|
|
776 } else if(!strcmp(child->name, "N")) {
|
|
777 for(child2 = child->child; child2; child2 = child2->next)
|
|
778 {
|
|
779 char *text2;
|
|
780
|
|
781 if(child2->type != XMLNODE_TYPE_TAG)
|
|
782 continue;
|
|
783
|
|
784 text2 = xmlnode_get_data(child2);
|
|
785 if(text2 && !strcmp(child2->name, "FAMILY")) {
|
|
786 g_string_append_printf(info_text,
|
|
787 "<b>%s:</b> %s<br/>",
|
|
788 _("Family Name"), text2);
|
|
789 } else if(text2 && !strcmp(child2->name, "GIVEN")) {
|
|
790 g_string_append_printf(info_text,
|
|
791 "<b>%s:</b> %s<br/>",
|
|
792 _("Given Name"), text2);
|
|
793 } else if(text2 && !strcmp(child2->name, "MIDDLE")) {
|
|
794 g_string_append_printf(info_text,
|
|
795 "<b>%s:</b> %s<br/>",
|
|
796 _("Middle Name"), text2);
|
|
797 }
|
|
798 g_free(text2);
|
|
799 }
|
|
800 } else if(text && !strcmp(child->name, "NICKNAME")) {
|
|
801 serv_got_alias(js->gc, from, text);
|
|
802 if(b) {
|
|
803 gaim_blist_node_set_string((GaimBlistNode*)b, "servernick", text);
|
|
804 }
|
|
805 g_string_append_printf(info_text, "<b>%s:</b> %s<br/>",
|
|
806 _("Nickname"), text);
|
|
807 } else if(text && !strcmp(child->name, "BDAY")) {
|
|
808 g_string_append_printf(info_text, "<b>%s:</b> %s<br/>",
|
|
809 _("Birthday"), text);
|
|
810 } else if(!strcmp(child->name, "ADR")) {
|
|
811 gboolean address_line_added = FALSE;
|
|
812
|
|
813 for(child2 = child->child; child2; child2 = child2->next)
|
|
814 {
|
|
815 char *text2;
|
|
816
|
|
817 if(child2->type != XMLNODE_TYPE_TAG)
|
|
818 continue;
|
|
819
|
|
820 text2 = xmlnode_get_data(child2);
|
|
821 if (text2 == NULL)
|
|
822 continue;
|
|
823
|
|
824 /* We do this here so that it's not added if all the child
|
|
825 * elements are empty. */
|
|
826 if (!address_line_added)
|
|
827 {
|
|
828 g_string_append_printf(info_text, "<b>%s:</b><br/>",
|
|
829 _("Address"));
|
|
830 address_line_added = TRUE;
|
|
831 }
|
|
832
|
|
833 if(!strcmp(child2->name, "POBOX")) {
|
|
834 g_string_append_printf(info_text,
|
|
835 " <b>%s:</b> %s<br/>",
|
|
836 _("P.O. Box"), text2);
|
|
837 } else if(!strcmp(child2->name, "EXTADR")) {
|
|
838 g_string_append_printf(info_text,
|
|
839 " <b>%s:</b> %s<br/>",
|
|
840 _("Extended Address"), text2);
|
|
841 } else if(!strcmp(child2->name, "STREET")) {
|
|
842 g_string_append_printf(info_text,
|
|
843 " <b>%s:</b> %s<br/>",
|
|
844 _("Street Address"), text2);
|
|
845 } else if(!strcmp(child2->name, "LOCALITY")) {
|
|
846 g_string_append_printf(info_text,
|
|
847 " <b>%s:</b> %s<br/>",
|
|
848 _("Locality"), text2);
|
|
849 } else if(!strcmp(child2->name, "REGION")) {
|
|
850 g_string_append_printf(info_text,
|
|
851 " <b>%s:</b> %s<br/>",
|
|
852 _("Region"), text2);
|
|
853 } else if(!strcmp(child2->name, "PCODE")) {
|
|
854 g_string_append_printf(info_text,
|
|
855 " <b>%s:</b> %s<br/>",
|
|
856 _("Postal Code"), text2);
|
|
857 } else if(!strcmp(child2->name, "CTRY")
|
|
858 || !strcmp(child2->name, "COUNTRY")) {
|
|
859 g_string_append_printf(info_text,
|
|
860 " <b>%s:</b> %s<br/>",
|
|
861 _("Country"), text2);
|
|
862 }
|
|
863 g_free(text2);
|
|
864 }
|
|
865 } else if(!strcmp(child->name, "TEL")) {
|
|
866 char *number;
|
|
867 if((child2 = xmlnode_get_child(child, "NUMBER"))) {
|
|
868 /* show what kind of number it is */
|
|
869 number = xmlnode_get_data(child2);
|
|
870 if(number) {
|
|
871 g_string_append_printf(info_text,
|
|
872 "<b>%s:</b> %s<br/>", _("Telephone"), number);
|
|
873 g_free(number);
|
|
874 }
|
|
875 } else if((number = xmlnode_get_data(child))) {
|
|
876 /* lots of clients (including gaim) do this, but it's
|
|
877 * out of spec */
|
|
878 g_string_append_printf(info_text,
|
|
879 "<b>%s:</b> %s<br/>", _("Telephone"), number);
|
|
880 g_free(number);
|
|
881 }
|
|
882 } else if(!strcmp(child->name, "EMAIL")) {
|
|
883 char *userid;
|
|
884 if((child2 = xmlnode_get_child(child, "USERID"))) {
|
|
885 /* show what kind of email it is */
|
|
886 userid = xmlnode_get_data(child2);
|
|
887 if(userid) {
|
|
888 g_string_append_printf(info_text,
|
|
889 "<b>%s:</b> <a href='mailto:%s'>%s</a><br/>",
|
|
890 _("E-Mail"), userid, userid);
|
|
891 g_free(userid);
|
|
892 }
|
|
893 } else if((userid = xmlnode_get_data(child))) {
|
|
894 /* lots of clients (including gaim) do this, but it's
|
|
895 * out of spec */
|
|
896 g_string_append_printf(info_text,
|
|
897 "<b>%s:</b> <a href='mailto:%s'>%s</a><br/>",
|
|
898 _("E-Mail"), userid, userid);
|
|
899 g_free(userid);
|
|
900 }
|
|
901 } else if(!strcmp(child->name, "ORG")) {
|
|
902 for(child2 = child->child; child2; child2 = child2->next)
|
|
903 {
|
|
904 char *text2;
|
|
905
|
|
906 if(child2->type != XMLNODE_TYPE_TAG)
|
|
907 continue;
|
|
908
|
|
909 text2 = xmlnode_get_data(child2);
|
|
910 if(text2 && !strcmp(child2->name, "ORGNAME")) {
|
|
911 g_string_append_printf(info_text,
|
|
912 "<b>%s:</b> %s<br/>",
|
|
913 _("Organization Name"), text2);
|
|
914 } else if(text2 && !strcmp(child2->name, "ORGUNIT")) {
|
|
915 g_string_append_printf(info_text,
|
|
916 "<b>%s:</b> %s<br/>",
|
|
917 _("Organization Unit"), text2);
|
|
918 }
|
|
919 g_free(text2);
|
|
920 }
|
|
921 } else if(text && !strcmp(child->name, "TITLE")) {
|
|
922 g_string_append_printf(info_text, "<b>%s:</b> %s<br/>",
|
|
923 _("Title"), text);
|
|
924 } else if(text && !strcmp(child->name, "ROLE")) {
|
|
925 g_string_append_printf(info_text, "<b>%s:</b> %s<br/>",
|
|
926 _("Role"), text);
|
|
927 } else if(text && !strcmp(child->name, "DESC")) {
|
|
928 g_string_append_printf(info_text, "<b>%s:</b> %s<br/>",
|
|
929 _("Description"), text);
|
|
930 } else if(!strcmp(child->name, "PHOTO") ||
|
|
931 !strcmp(child->name, "LOGO")) {
|
|
932 char *bintext = NULL;
|
|
933 xmlnode *binval;
|
|
934
|
|
935 if( ((binval = xmlnode_get_child(child, "BINVAL")) &&
|
|
936 (bintext = xmlnode_get_data(binval))) ||
|
|
937 (bintext = xmlnode_get_data(child))) {
|
|
938 gsize size;
|
|
939 guchar *data;
|
|
940 int i;
|
|
941 unsigned char hashval[20];
|
|
942 char *p, hash[41];
|
|
943 gboolean photo = (strcmp(child->name, "PHOTO") == 0);
|
|
944
|
|
945 data = gaim_base64_decode(bintext, &size);
|
|
946
|
|
947 jbi->vcard_imgids = g_slist_prepend(jbi->vcard_imgids, GINT_TO_POINTER(gaim_imgstore_add(data, size, "logo.png")));
|
|
948 g_string_append_printf(info_text,
|
|
949 "<b>%s:</b> <img id='%d'><br/>",
|
|
950 photo ? _("Photo") : _("Logo"),
|
|
951 GPOINTER_TO_INT(jbi->vcard_imgids->data));
|
|
952
|
|
953 gaim_buddy_icons_set_for_user(js->gc->account, bare_jid,
|
|
954 data, size);
|
|
955
|
|
956 gaim_cipher_digest_region("sha1", (guchar *)data, size,
|
|
957 sizeof(hashval), hashval, NULL);
|
|
958 p = hash;
|
|
959 for(i=0; i<20; i++, p+=2)
|
|
960 snprintf(p, 3, "%02x", hashval[i]);
|
|
961 gaim_blist_node_set_string((GaimBlistNode*)b, "avatar_hash", hash);
|
|
962
|
|
963 g_free(data);
|
|
964 g_free(bintext);
|
|
965 }
|
|
966 }
|
|
967 g_free(text);
|
|
968 }
|
|
969 }
|
|
970
|
|
971 jbi->vcard_text = gaim_strdup_withhtml(info_text->str);
|
|
972 g_string_free(info_text, TRUE);
|
|
973 g_free(bare_jid);
|
|
974
|
|
975 jabber_buddy_info_show_if_ready(jbi);
|
|
976 }
|
|
977
|
|
978
|
|
979 static void jabber_buddy_info_resource_free(gpointer data)
|
|
980 {
|
|
981 JabberBuddyInfoResource *jbri = data;
|
|
982 g_free(jbri);
|
|
983 }
|
|
984
|
|
985 static void jabber_version_parse(JabberStream *js, xmlnode *packet, gpointer data)
|
|
986 {
|
|
987 JabberBuddyInfo *jbi = data;
|
|
988 const char *type, *id, *from;
|
|
989 xmlnode *query;
|
|
990 char *resource_name;
|
|
991
|
|
992 g_return_if_fail(jbi != NULL);
|
|
993
|
|
994 type = xmlnode_get_attrib(packet, "type");
|
|
995 id = xmlnode_get_attrib(packet, "id");
|
|
996 from = xmlnode_get_attrib(packet, "from");
|
|
997
|
|
998 jabber_buddy_info_remove_id(jbi, id);
|
|
999
|
|
1000 if(!from)
|
|
1001 return;
|
|
1002
|
|
1003 resource_name = jabber_get_resource(from);
|
|
1004
|
|
1005 if(resource_name) {
|
|
1006 if(type && !strcmp(type, "result")) {
|
|
1007 if((query = xmlnode_get_child(packet, "query"))) {
|
|
1008 JabberBuddyResource *jbr = jabber_buddy_find_resource(jbi->jb, resource_name);
|
|
1009 if(jbr) {
|
|
1010 xmlnode *node;
|
|
1011 if((node = xmlnode_get_child(query, "name"))) {
|
|
1012 jbr->client.name = xmlnode_get_data(node);
|
|
1013 }
|
|
1014 if((node = xmlnode_get_child(query, "version"))) {
|
|
1015 jbr->client.version = xmlnode_get_data(node);
|
|
1016 }
|
|
1017 if((node = xmlnode_get_child(query, "os"))) {
|
|
1018 jbr->client.os = xmlnode_get_data(node);
|
|
1019 }
|
|
1020 }
|
|
1021 }
|
|
1022 }
|
|
1023 g_free(resource_name);
|
|
1024 }
|
|
1025
|
|
1026 jabber_buddy_info_show_if_ready(jbi);
|
|
1027 }
|
|
1028
|
|
1029 static void jabber_last_parse(JabberStream *js, xmlnode *packet, gpointer data)
|
|
1030 {
|
|
1031 JabberBuddyInfo *jbi = data;
|
|
1032 xmlnode *query;
|
|
1033 char *resource_name;
|
|
1034 const char *type, *id, *from, *seconds;
|
|
1035
|
|
1036 g_return_if_fail(jbi != NULL);
|
|
1037
|
|
1038 type = xmlnode_get_attrib(packet, "type");
|
|
1039 id = xmlnode_get_attrib(packet, "id");
|
|
1040 from = xmlnode_get_attrib(packet, "from");
|
|
1041
|
|
1042 jabber_buddy_info_remove_id(jbi, id);
|
|
1043
|
|
1044 if(!from)
|
|
1045 return;
|
|
1046
|
|
1047 resource_name = jabber_get_resource(from);
|
|
1048
|
|
1049 if(resource_name) {
|
|
1050 if(type && !strcmp(type, "result")) {
|
|
1051 if((query = xmlnode_get_child(packet, "query"))) {
|
|
1052 seconds = xmlnode_get_attrib(query, "seconds");
|
|
1053 if(seconds) {
|
|
1054 char *end = NULL;
|
|
1055 long sec = strtol(seconds, &end, 10);
|
|
1056 if(end != seconds) {
|
|
1057 JabberBuddyInfoResource *jbir = g_hash_table_lookup(jbi->resources, resource_name);
|
|
1058 if(jbir) {
|
|
1059 jbir->idle_seconds = sec;
|
|
1060 }
|
|
1061 }
|
|
1062 }
|
|
1063 }
|
|
1064 }
|
|
1065 g_free(resource_name);
|
|
1066 }
|
|
1067
|
|
1068 jabber_buddy_info_show_if_ready(jbi);
|
|
1069 }
|
|
1070
|
|
1071 static gboolean jabber_buddy_get_info_timeout(gpointer data)
|
|
1072 {
|
|
1073 JabberBuddyInfo *jbi = data;
|
|
1074
|
|
1075 /* remove the pending callbacks */
|
|
1076 while(jbi->ids) {
|
|
1077 char *id = jbi->ids->data;
|
|
1078 jabber_iq_remove_callback_by_id(jbi->js, id);
|
|
1079 g_free(id);
|
|
1080 jbi->ids = g_slist_remove(jbi->ids, id);
|
|
1081 }
|
|
1082
|
|
1083 jbi->timeout_handle = 0;
|
|
1084
|
|
1085 jabber_buddy_info_show_if_ready(jbi);
|
|
1086
|
|
1087 return FALSE;
|
|
1088 }
|
|
1089
|
|
1090 static void jabber_buddy_get_info_for_jid(JabberStream *js, const char *jid)
|
|
1091 {
|
|
1092 JabberIq *iq;
|
|
1093 xmlnode *vcard;
|
|
1094 GList *resources;
|
|
1095 JabberBuddy *jb;
|
|
1096 JabberBuddyInfo *jbi;
|
|
1097
|
|
1098 jb = jabber_buddy_find(js, jid, TRUE);
|
|
1099
|
|
1100 /* invalid JID */
|
|
1101 if(!jb)
|
|
1102 return;
|
|
1103
|
|
1104 jbi = g_new0(JabberBuddyInfo, 1);
|
|
1105 jbi->jid = g_strdup(jid);
|
|
1106 jbi->js = js;
|
|
1107 jbi->jb = jb;
|
|
1108 jbi->resources = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, jabber_buddy_info_resource_free);
|
|
1109
|
|
1110 iq = jabber_iq_new(js, JABBER_IQ_GET);
|
|
1111
|
|
1112 xmlnode_set_attrib(iq->node, "to", jid);
|
|
1113 vcard = xmlnode_new_child(iq->node, "vCard");
|
|
1114 xmlnode_set_namespace(vcard, "vcard-temp");
|
|
1115
|
|
1116 jabber_iq_set_callback(iq, jabber_vcard_parse, jbi);
|
|
1117 jbi->ids = g_slist_prepend(jbi->ids, g_strdup(iq->id));
|
|
1118
|
|
1119 jabber_iq_send(iq);
|
|
1120
|
|
1121 for(resources = jb->resources; resources; resources = resources->next)
|
|
1122 {
|
|
1123 JabberBuddyResource *jbr = resources->data;
|
|
1124 JabberBuddyInfoResource *jbir;
|
|
1125 char *full_jid;
|
|
1126
|
|
1127 if ((strchr(jid, '/') == NULL) && (jbr->name != NULL)) {
|
|
1128 full_jid = g_strdup_printf("%s/%s", jid, jbr->name);
|
|
1129 } else {
|
|
1130 full_jid = g_strdup(jid);
|
|
1131 }
|
|
1132
|
|
1133 if (jbr->name != NULL)
|
|
1134 {
|
|
1135 jbir = g_new0(JabberBuddyInfoResource, 1);
|
|
1136 g_hash_table_insert(jbi->resources, g_strdup(jbr->name), jbir);
|
|
1137 }
|
|
1138
|
|
1139 if(!jbr->client.name) {
|
|
1140 iq = jabber_iq_new_query(js, JABBER_IQ_GET, "jabber:iq:version");
|
|
1141 xmlnode_set_attrib(iq->node, "to", full_jid);
|
|
1142 jabber_iq_set_callback(iq, jabber_version_parse, jbi);
|
|
1143 jbi->ids = g_slist_prepend(jbi->ids, g_strdup(iq->id));
|
|
1144 jabber_iq_send(iq);
|
|
1145 }
|
|
1146
|
|
1147 iq = jabber_iq_new_query(js, JABBER_IQ_GET, "jabber:iq:last");
|
|
1148 xmlnode_set_attrib(iq->node, "to", full_jid);
|
|
1149 jabber_iq_set_callback(iq, jabber_last_parse, jbi);
|
|
1150 jbi->ids = g_slist_prepend(jbi->ids, g_strdup(iq->id));
|
|
1151 jabber_iq_send(iq);
|
|
1152
|
|
1153 g_free(full_jid);
|
|
1154 }
|
|
1155
|
|
1156 jbi->timeout_handle = gaim_timeout_add(30000, jabber_buddy_get_info_timeout, jbi);
|
|
1157 }
|
|
1158
|
|
1159 void jabber_buddy_get_info(GaimConnection *gc, const char *who)
|
|
1160 {
|
|
1161 JabberStream *js = gc->proto_data;
|
|
1162 char *bare_jid = jabber_get_bare_jid(who);
|
|
1163
|
|
1164 if(bare_jid) {
|
|
1165 jabber_buddy_get_info_for_jid(js, bare_jid);
|
|
1166 g_free(bare_jid);
|
|
1167 }
|
|
1168 }
|
|
1169
|
|
1170 void jabber_buddy_get_info_chat(GaimConnection *gc, int id,
|
|
1171 const char *resource)
|
|
1172 {
|
|
1173 JabberStream *js = gc->proto_data;
|
|
1174 JabberChat *chat = jabber_chat_find_by_id(js, id);
|
|
1175 char *full_jid;
|
|
1176
|
|
1177 if(!chat)
|
|
1178 return;
|
|
1179
|
|
1180 full_jid = g_strdup_printf("%s@%s/%s", chat->room, chat->server, resource);
|
|
1181 jabber_buddy_get_info_for_jid(js, full_jid);
|
|
1182 g_free(full_jid);
|
|
1183 }
|
|
1184
|
|
1185
|
|
1186 static void jabber_buddy_set_invisibility(JabberStream *js, const char *who,
|
|
1187 gboolean invisible)
|
|
1188 {
|
|
1189 GaimPresence *gpresence;
|
|
1190 GaimAccount *account;
|
|
1191 GaimStatus *status;
|
|
1192 JabberBuddy *jb = jabber_buddy_find(js, who, TRUE);
|
|
1193 xmlnode *presence;
|
|
1194 JabberBuddyState state;
|
14463
|
1195 char *msg;
|
14192
|
1196 int priority;
|
|
1197
|
|
1198 account = gaim_connection_get_account(js->gc);
|
|
1199 gpresence = gaim_account_get_presence(account);
|
|
1200 status = gaim_presence_get_active_status(gpresence);
|
|
1201
|
|
1202 gaim_status_to_jabber(status, &state, &msg, &priority);
|
|
1203 presence = jabber_presence_create(state, msg, priority);
|
|
1204
|
14463
|
1205 g_free(msg);
|
|
1206
|
14192
|
1207 xmlnode_set_attrib(presence, "to", who);
|
|
1208 if(invisible) {
|
|
1209 xmlnode_set_attrib(presence, "type", "invisible");
|
|
1210 jb->invisible |= JABBER_INVIS_BUDDY;
|
|
1211 } else {
|
|
1212 jb->invisible &= ~JABBER_INVIS_BUDDY;
|
|
1213 }
|
|
1214
|
|
1215 jabber_send(js, presence);
|
|
1216 xmlnode_free(presence);
|
|
1217 }
|
|
1218
|
|
1219 static void jabber_buddy_make_invisible(GaimBlistNode *node, gpointer data)
|
|
1220 {
|
|
1221 GaimBuddy *buddy;
|
|
1222 GaimConnection *gc;
|
|
1223 JabberStream *js;
|
|
1224
|
|
1225 g_return_if_fail(GAIM_BLIST_NODE_IS_BUDDY(node));
|
|
1226
|
|
1227 buddy = (GaimBuddy *) node;
|
|
1228 gc = gaim_account_get_connection(buddy->account);
|
|
1229 js = gc->proto_data;
|
|
1230
|
|
1231 jabber_buddy_set_invisibility(js, buddy->name, TRUE);
|
|
1232 }
|
|
1233
|
|
1234 static void jabber_buddy_make_visible(GaimBlistNode *node, gpointer data)
|
|
1235 {
|
|
1236 GaimBuddy *buddy;
|
|
1237 GaimConnection *gc;
|
|
1238 JabberStream *js;
|
|
1239
|
|
1240 g_return_if_fail(GAIM_BLIST_NODE_IS_BUDDY(node));
|
|
1241
|
|
1242 buddy = (GaimBuddy *) node;
|
|
1243 gc = gaim_account_get_connection(buddy->account);
|
|
1244 js = gc->proto_data;
|
|
1245
|
|
1246 jabber_buddy_set_invisibility(js, buddy->name, FALSE);
|
|
1247 }
|
|
1248
|
|
1249 static void jabber_buddy_cancel_presence_notification(GaimBlistNode *node,
|
|
1250 gpointer data)
|
|
1251 {
|
|
1252 GaimBuddy *buddy;
|
|
1253 GaimConnection *gc;
|
|
1254 JabberStream *js;
|
|
1255
|
|
1256 g_return_if_fail(GAIM_BLIST_NODE_IS_BUDDY(node));
|
|
1257
|
|
1258 buddy = (GaimBuddy *) node;
|
|
1259 gc = gaim_account_get_connection(buddy->account);
|
|
1260 js = gc->proto_data;
|
|
1261
|
|
1262 /* I wonder if we should prompt the user before doing this */
|
|
1263 jabber_presence_subscription_set(js, buddy->name, "unsubscribed");
|
|
1264 }
|
|
1265
|
|
1266 static void jabber_buddy_rerequest_auth(GaimBlistNode *node, gpointer data)
|
|
1267 {
|
|
1268 GaimBuddy *buddy;
|
|
1269 GaimConnection *gc;
|
|
1270 JabberStream *js;
|
|
1271
|
|
1272 g_return_if_fail(GAIM_BLIST_NODE_IS_BUDDY(node));
|
|
1273
|
|
1274 buddy = (GaimBuddy *) node;
|
|
1275 gc = gaim_account_get_connection(buddy->account);
|
|
1276 js = gc->proto_data;
|
|
1277
|
|
1278 jabber_presence_subscription_set(js, buddy->name, "subscribe");
|
|
1279 }
|
|
1280
|
|
1281
|
|
1282 static void jabber_buddy_unsubscribe(GaimBlistNode *node, gpointer data)
|
|
1283 {
|
|
1284 GaimBuddy *buddy;
|
|
1285 GaimConnection *gc;
|
|
1286 JabberStream *js;
|
|
1287
|
|
1288 g_return_if_fail(GAIM_BLIST_NODE_IS_BUDDY(node));
|
|
1289
|
|
1290 buddy = (GaimBuddy *) node;
|
|
1291 gc = gaim_account_get_connection(buddy->account);
|
|
1292 js = gc->proto_data;
|
|
1293
|
|
1294 jabber_presence_subscription_set(js, buddy->name, "unsubscribe");
|
|
1295 }
|
|
1296
|
|
1297
|
|
1298 static GList *jabber_buddy_menu(GaimBuddy *buddy)
|
|
1299 {
|
|
1300 GaimConnection *gc = gaim_account_get_connection(buddy->account);
|
|
1301 JabberStream *js = gc->proto_data;
|
|
1302 JabberBuddy *jb = jabber_buddy_find(js, buddy->name, TRUE);
|
|
1303
|
|
1304 GList *m = NULL;
|
|
1305 GaimMenuAction *act;
|
|
1306
|
|
1307 if(!jb)
|
|
1308 return m;
|
|
1309
|
|
1310 /* XXX: fix the NOT ME below */
|
|
1311
|
|
1312 if(js->protocol_version == JABBER_PROTO_0_9 /* && NOT ME */) {
|
|
1313 if(jb->invisible & JABBER_INVIS_BUDDY) {
|
|
1314 act = gaim_menu_action_new(_("Un-hide From"),
|
|
1315 GAIM_CALLBACK(jabber_buddy_make_visible),
|
|
1316 NULL, NULL);
|
|
1317 } else {
|
|
1318 act = gaim_menu_action_new(_("Temporarily Hide From"),
|
|
1319 GAIM_CALLBACK(jabber_buddy_make_invisible),
|
|
1320 NULL, NULL);
|
|
1321 }
|
|
1322 m = g_list_append(m, act);
|
|
1323 }
|
|
1324
|
|
1325 if(jb->subscription & JABBER_SUB_FROM /* && NOT ME */) {
|
|
1326 act = gaim_menu_action_new(_("Cancel Presence Notification"),
|
|
1327 GAIM_CALLBACK(jabber_buddy_cancel_presence_notification),
|
|
1328 NULL, NULL);
|
|
1329 m = g_list_append(m, act);
|
|
1330 }
|
|
1331
|
|
1332 if(!(jb->subscription & JABBER_SUB_TO)) {
|
|
1333 act = gaim_menu_action_new(_("(Re-)Request authorization"),
|
|
1334 GAIM_CALLBACK(jabber_buddy_rerequest_auth),
|
|
1335 NULL, NULL);
|
|
1336 m = g_list_append(m, act);
|
|
1337
|
|
1338 } else /* if(NOT ME) */{
|
|
1339
|
|
1340 /* shouldn't this just happen automatically when the buddy is
|
|
1341 removed? */
|
|
1342 act = gaim_menu_action_new(_("Unsubscribe"),
|
|
1343 GAIM_CALLBACK(jabber_buddy_unsubscribe),
|
|
1344 NULL, NULL);
|
|
1345 m = g_list_append(m, act);
|
|
1346 }
|
|
1347
|
|
1348 return m;
|
|
1349 }
|
|
1350
|
|
1351 GList *
|
|
1352 jabber_blist_node_menu(GaimBlistNode *node)
|
|
1353 {
|
|
1354 if(GAIM_BLIST_NODE_IS_BUDDY(node)) {
|
|
1355 return jabber_buddy_menu((GaimBuddy *) node);
|
|
1356 } else {
|
|
1357 return NULL;
|
|
1358 }
|
|
1359 }
|
|
1360
|
|
1361
|
|
1362 const char *
|
|
1363 jabber_buddy_state_get_name(JabberBuddyState state)
|
|
1364 {
|
|
1365 switch(state) {
|
|
1366 case JABBER_BUDDY_STATE_UNKNOWN:
|
|
1367 return _("Unknown");
|
|
1368 case JABBER_BUDDY_STATE_ERROR:
|
|
1369 return _("Error");
|
|
1370 case JABBER_BUDDY_STATE_UNAVAILABLE:
|
|
1371 return _("Offline");
|
|
1372 case JABBER_BUDDY_STATE_ONLINE:
|
|
1373 return _("Available");
|
|
1374 case JABBER_BUDDY_STATE_CHAT:
|
|
1375 return _("Chatty");
|
|
1376 case JABBER_BUDDY_STATE_AWAY:
|
|
1377 return _("Away");
|
|
1378 case JABBER_BUDDY_STATE_XA:
|
|
1379 return _("Extended Away");
|
|
1380 case JABBER_BUDDY_STATE_DND:
|
|
1381 return _("Do Not Disturb");
|
|
1382 }
|
|
1383
|
|
1384 return _("Unknown");
|
|
1385 }
|
|
1386
|
|
1387 JabberBuddyState jabber_buddy_status_id_get_state(const char *id) {
|
|
1388 if(!id)
|
|
1389 return JABBER_BUDDY_STATE_UNKNOWN;
|
|
1390 if(!strcmp(id, "available"))
|
|
1391 return JABBER_BUDDY_STATE_ONLINE;
|
|
1392 if(!strcmp(id, "freeforchat"))
|
|
1393 return JABBER_BUDDY_STATE_CHAT;
|
|
1394 if(!strcmp(id, "away"))
|
|
1395 return JABBER_BUDDY_STATE_AWAY;
|
|
1396 if(!strcmp(id, "extended_away"))
|
|
1397 return JABBER_BUDDY_STATE_XA;
|
|
1398 if(!strcmp(id, "dnd"))
|
|
1399 return JABBER_BUDDY_STATE_DND;
|
|
1400 if(!strcmp(id, "offline"))
|
|
1401 return JABBER_BUDDY_STATE_UNAVAILABLE;
|
|
1402 if(!strcmp(id, "error"))
|
|
1403 return JABBER_BUDDY_STATE_ERROR;
|
|
1404
|
|
1405 return JABBER_BUDDY_STATE_UNKNOWN;
|
|
1406 }
|
|
1407
|
|
1408 JabberBuddyState jabber_buddy_show_get_state(const char *id) {
|
|
1409 if(!id)
|
|
1410 return JABBER_BUDDY_STATE_UNKNOWN;
|
|
1411 if(!strcmp(id, "available"))
|
|
1412 return JABBER_BUDDY_STATE_ONLINE;
|
|
1413 if(!strcmp(id, "chat"))
|
|
1414 return JABBER_BUDDY_STATE_CHAT;
|
|
1415 if(!strcmp(id, "away"))
|
|
1416 return JABBER_BUDDY_STATE_AWAY;
|
|
1417 if(!strcmp(id, "xa"))
|
|
1418 return JABBER_BUDDY_STATE_XA;
|
|
1419 if(!strcmp(id, "dnd"))
|
|
1420 return JABBER_BUDDY_STATE_DND;
|
|
1421 if(!strcmp(id, "offline"))
|
|
1422 return JABBER_BUDDY_STATE_UNAVAILABLE;
|
|
1423 if(!strcmp(id, "error"))
|
|
1424 return JABBER_BUDDY_STATE_ERROR;
|
|
1425
|
|
1426 return JABBER_BUDDY_STATE_UNKNOWN;
|
|
1427 }
|
|
1428
|
|
1429 const char *jabber_buddy_state_get_show(JabberBuddyState state) {
|
|
1430 switch(state) {
|
|
1431 case JABBER_BUDDY_STATE_CHAT:
|
|
1432 return "chat";
|
|
1433 case JABBER_BUDDY_STATE_AWAY:
|
|
1434 return "away";
|
|
1435 case JABBER_BUDDY_STATE_XA:
|
|
1436 return "xa";
|
|
1437 case JABBER_BUDDY_STATE_DND:
|
|
1438 return "dnd";
|
|
1439 case JABBER_BUDDY_STATE_ONLINE:
|
|
1440 return "available";
|
|
1441 case JABBER_BUDDY_STATE_UNKNOWN:
|
|
1442 case JABBER_BUDDY_STATE_ERROR:
|
|
1443 return NULL;
|
|
1444 case JABBER_BUDDY_STATE_UNAVAILABLE:
|
|
1445 return "offline";
|
|
1446 }
|
|
1447 return NULL;
|
|
1448 }
|
|
1449
|
|
1450 const char *jabber_buddy_state_get_status_id(JabberBuddyState state) {
|
|
1451 switch(state) {
|
|
1452 case JABBER_BUDDY_STATE_CHAT:
|
|
1453 return "freeforchat";
|
|
1454 case JABBER_BUDDY_STATE_AWAY:
|
|
1455 return "away";
|
|
1456 case JABBER_BUDDY_STATE_XA:
|
|
1457 return "extended_away";
|
|
1458 case JABBER_BUDDY_STATE_DND:
|
|
1459 return "dnd";
|
|
1460 case JABBER_BUDDY_STATE_ONLINE:
|
|
1461 return "available";
|
|
1462 case JABBER_BUDDY_STATE_UNKNOWN:
|
|
1463 return "available";
|
|
1464 case JABBER_BUDDY_STATE_ERROR:
|
|
1465 return "error";
|
|
1466 case JABBER_BUDDY_STATE_UNAVAILABLE:
|
|
1467 return "offline";
|
|
1468 }
|
|
1469 return NULL;
|
|
1470 }
|
|
1471
|
|
1472 static void user_search_result_add_buddy_cb(GaimConnection *gc, GList *row, void *user_data)
|
|
1473 {
|
|
1474 /* XXX find out the jid */
|
|
1475 gaim_blist_request_add_buddy(gaim_connection_get_account(gc),
|
|
1476 g_list_nth_data(row, 0), NULL, NULL);
|
|
1477 }
|
|
1478
|
|
1479 static void user_search_result_cb(JabberStream *js, xmlnode *packet, gpointer data)
|
|
1480 {
|
|
1481 GaimNotifySearchResults *results;
|
|
1482 GaimNotifySearchColumn *column;
|
|
1483 xmlnode *x, *query, *item, *field;
|
|
1484
|
|
1485 /* XXX error checking? */
|
|
1486 if(!(query = xmlnode_get_child(packet, "query")))
|
|
1487 return;
|
|
1488
|
|
1489 results = gaim_notify_searchresults_new();
|
|
1490 if((x = xmlnode_get_child_with_namespace(query, "x", "jabber:x:data"))) {
|
|
1491 xmlnode *reported;
|
|
1492 gaim_debug_info("jabber", "new-skool\n");
|
|
1493 if((reported = xmlnode_get_child(x, "reported"))) {
|
|
1494 xmlnode *field = xmlnode_get_child(reported, "field");
|
|
1495 while(field) {
|
|
1496 /* XXX keep track of this order, use it below */
|
|
1497 const char *var = xmlnode_get_attrib(field, "var");
|
|
1498 const char *label = xmlnode_get_attrib(field, "label");
|
|
1499 if(var) {
|
|
1500 column = gaim_notify_searchresults_column_new(label ? label : var);
|
|
1501 gaim_notify_searchresults_column_add(results, column);
|
|
1502 }
|
|
1503 field = xmlnode_get_next_twin(field);
|
|
1504 }
|
|
1505 }
|
|
1506 item = xmlnode_get_child(x, "item");
|
|
1507 while(item) {
|
|
1508 GList *row = NULL;
|
|
1509 field = xmlnode_get_child(item, "field");
|
|
1510 while(field) {
|
|
1511 xmlnode *valuenode = xmlnode_get_child(field, "value");
|
|
1512 if(valuenode) {
|
|
1513 char *value = xmlnode_get_data(valuenode);
|
|
1514 row = g_list_append(row, value);
|
|
1515 }
|
|
1516 field = xmlnode_get_next_twin(field);
|
|
1517 }
|
|
1518 gaim_notify_searchresults_row_add(results, row);
|
|
1519
|
|
1520 item = xmlnode_get_next_twin(item);
|
|
1521 }
|
|
1522 } else {
|
|
1523 /* old skool */
|
|
1524 gaim_debug_info("jabber", "old-skool\n");
|
|
1525
|
|
1526 column = gaim_notify_searchresults_column_new(_("JID"));
|
|
1527 gaim_notify_searchresults_column_add(results, column);
|
|
1528 column = gaim_notify_searchresults_column_new(_("First Name"));
|
|
1529 gaim_notify_searchresults_column_add(results, column);
|
|
1530 column = gaim_notify_searchresults_column_new(_("Last Name"));
|
|
1531 gaim_notify_searchresults_column_add(results, column);
|
|
1532 column = gaim_notify_searchresults_column_new(_("Nickname"));
|
|
1533 gaim_notify_searchresults_column_add(results, column);
|
|
1534 column = gaim_notify_searchresults_column_new(_("E-Mail"));
|
|
1535 gaim_notify_searchresults_column_add(results, column);
|
|
1536
|
|
1537 for(item = xmlnode_get_child(query, "item"); item; item = xmlnode_get_next_twin(item)) {
|
|
1538 const char *jid;
|
|
1539 xmlnode *node;
|
|
1540 GList *row = NULL;
|
|
1541
|
|
1542 if(!(jid = xmlnode_get_attrib(item, "jid")))
|
|
1543 continue;
|
|
1544
|
|
1545 row = g_list_append(row, g_strdup(jid));
|
|
1546 node = xmlnode_get_child(item, "first");
|
|
1547 row = g_list_append(row, node ? xmlnode_get_data(node) : NULL);
|
|
1548 node = xmlnode_get_child(item, "last");
|
|
1549 row = g_list_append(row, node ? xmlnode_get_data(node) : NULL);
|
|
1550 node = xmlnode_get_child(item, "nick");
|
|
1551 row = g_list_append(row, node ? xmlnode_get_data(node) : NULL);
|
|
1552 node = xmlnode_get_child(item, "email");
|
|
1553 row = g_list_append(row, node ? xmlnode_get_data(node) : NULL);
|
|
1554 gaim_debug_info("jabber", "row=%d\n", row);
|
|
1555 gaim_notify_searchresults_row_add(results, row);
|
|
1556 }
|
|
1557 }
|
|
1558
|
|
1559 gaim_notify_searchresults_button_add(results, GAIM_NOTIFY_BUTTON_ADD,
|
|
1560 user_search_result_add_buddy_cb);
|
|
1561
|
|
1562 gaim_notify_searchresults(js->gc, NULL, NULL, _("The following are the results of your search"), results, NULL, NULL);
|
|
1563 }
|
|
1564
|
|
1565 static void user_search_x_data_cb(JabberStream *js, xmlnode *result, gpointer data)
|
|
1566 {
|
|
1567 xmlnode *query;
|
|
1568 JabberIq *iq;
|
|
1569 char *dir_server = data;
|
|
1570
|
|
1571 iq = jabber_iq_new_query(js, JABBER_IQ_SET, "jabber:iq:search");
|
|
1572 query = xmlnode_get_child(iq->node, "query");
|
|
1573
|
|
1574 xmlnode_insert_child(query, result);
|
|
1575
|
|
1576 jabber_iq_set_callback(iq, user_search_result_cb, NULL);
|
|
1577 xmlnode_set_attrib(iq->node, "to", dir_server);
|
|
1578 jabber_iq_send(iq);
|
|
1579 g_free(dir_server);
|
|
1580 }
|
|
1581
|
|
1582 struct user_search_info {
|
|
1583 JabberStream *js;
|
|
1584 char *directory_server;
|
|
1585 };
|
|
1586
|
|
1587 static void user_search_cancel_cb(struct user_search_info *usi, GaimRequestFields *fields)
|
|
1588 {
|
|
1589 g_free(usi->directory_server);
|
|
1590 g_free(usi);
|
|
1591 }
|
|
1592
|
|
1593 static void user_search_cb(struct user_search_info *usi, GaimRequestFields *fields)
|
|
1594 {
|
|
1595 JabberStream *js = usi->js;
|
|
1596 JabberIq *iq;
|
|
1597 xmlnode *query;
|
|
1598 GList *groups, *flds;
|
|
1599
|
|
1600 iq = jabber_iq_new_query(js, JABBER_IQ_SET, "jabber:iq:search");
|
|
1601 query = xmlnode_get_child(iq->node, "query");
|
|
1602
|
|
1603 for(groups = gaim_request_fields_get_groups(fields); groups; groups = groups->next) {
|
|
1604 for(flds = gaim_request_field_group_get_fields(groups->data);
|
|
1605 flds; flds = flds->next) {
|
|
1606 GaimRequestField *field = flds->data;
|
|
1607 const char *id = gaim_request_field_get_id(field);
|
|
1608 const char *value = gaim_request_field_string_get_value(field);
|
|
1609
|
|
1610 if(value && (!strcmp(id, "first") || !strcmp(id, "last") || !strcmp(id, "nick") || !strcmp(id, "email"))) {
|
|
1611 xmlnode *y = xmlnode_new_child(query, id);
|
|
1612 xmlnode_insert_data(y, value, -1);
|
|
1613 }
|
|
1614 }
|
|
1615 }
|
|
1616
|
|
1617 jabber_iq_set_callback(iq, user_search_result_cb, NULL);
|
|
1618 xmlnode_set_attrib(iq->node, "to", usi->directory_server);
|
|
1619 jabber_iq_send(iq);
|
|
1620
|
|
1621 g_free(usi->directory_server);
|
|
1622 g_free(usi);
|
|
1623 }
|
|
1624
|
|
1625 #if 0
|
|
1626 /* This is for gettext only -- it will see this even though there's an #if 0. */
|
|
1627
|
|
1628 /*
|
|
1629 * An incomplete list of server generated original language search
|
|
1630 * comments for Jabber User Directories
|
|
1631 *
|
|
1632 * See discussion thread "Search comment for Jabber is not translatable"
|
|
1633 * in gaim-i18n@lists.sourceforge.net (March 2006)
|
|
1634 */
|
|
1635 static const char * jabber_user_dir_comments [] = {
|
|
1636 /* current comment from Jabber User Directory users.jabber.org */
|
|
1637 N_("Find a contact by entering the search criteria in the given fields. "
|
|
1638 "Note: Each field supports wild card searches (%)"),
|
|
1639 NULL
|
|
1640 };
|
|
1641 #endif
|
|
1642
|
|
1643 static void user_search_fields_result_cb(JabberStream *js, xmlnode *packet, gpointer data)
|
|
1644 {
|
|
1645 xmlnode *query, *x;
|
|
1646 const char *from, *type;
|
|
1647
|
|
1648 if(!(from = xmlnode_get_attrib(packet, "from")))
|
|
1649 return;
|
|
1650
|
|
1651 if(!(type = xmlnode_get_attrib(packet, "type")) || !strcmp(type, "error")) {
|
|
1652 char *msg = jabber_parse_error(js, packet);
|
|
1653
|
|
1654 if(!msg)
|
|
1655 msg = g_strdup(_("Unknown error"));
|
|
1656
|
|
1657 gaim_notify_error(js->gc, _("Directory Query Failed"),
|
|
1658 _("Could not query the directory server."), msg);
|
|
1659 g_free(msg);
|
|
1660
|
|
1661 return;
|
|
1662 }
|
|
1663
|
|
1664
|
|
1665 if(!(query = xmlnode_get_child(packet, "query")))
|
|
1666 return;
|
|
1667
|
|
1668 if((x = xmlnode_get_child_with_namespace(query, "x", "jabber:x:data"))) {
|
|
1669 jabber_x_data_request(js, x, user_search_x_data_cb, g_strdup(from));
|
|
1670 return;
|
|
1671 } else {
|
|
1672 struct user_search_info *usi;
|
|
1673 xmlnode *instnode;
|
|
1674 char *instructions = NULL;
|
|
1675 GaimRequestFields *fields;
|
|
1676 GaimRequestFieldGroup *group;
|
|
1677 GaimRequestField *field;
|
|
1678
|
|
1679 /* old skool */
|
|
1680 fields = gaim_request_fields_new();
|
|
1681 group = gaim_request_field_group_new(NULL);
|
|
1682 gaim_request_fields_add_group(fields, group);
|
|
1683
|
|
1684 if((instnode = xmlnode_get_child(query, "instructions")))
|
|
1685 {
|
|
1686 char *tmp = xmlnode_get_data(instnode);
|
|
1687
|
|
1688 if(tmp)
|
|
1689 {
|
|
1690 /* Try to translate the message (see static message
|
|
1691 list in jabber_user_dir_comments[]) */
|
|
1692 instructions = g_strdup_printf(_("Server Instructions: %s"), _(tmp));
|
|
1693 g_free(tmp);
|
|
1694 }
|
|
1695 }
|
|
1696
|
|
1697 if(!instructions)
|
|
1698 {
|
|
1699 instructions = g_strdup(_("Fill in one or more fields to search "
|
|
1700 "for any matching Jabber users."));
|
|
1701 }
|
|
1702
|
|
1703 if(xmlnode_get_child(query, "first")) {
|
|
1704 field = gaim_request_field_string_new("first", _("First Name"),
|
|
1705 NULL, FALSE);
|
|
1706 gaim_request_field_group_add_field(group, field);
|
|
1707 }
|
|
1708 if(xmlnode_get_child(query, "last")) {
|
|
1709 field = gaim_request_field_string_new("last", _("Last Name"),
|
|
1710 NULL, FALSE);
|
|
1711 gaim_request_field_group_add_field(group, field);
|
|
1712 }
|
|
1713 if(xmlnode_get_child(query, "nick")) {
|
|
1714 field = gaim_request_field_string_new("nick", _("Nickname"),
|
|
1715 NULL, FALSE);
|
|
1716 gaim_request_field_group_add_field(group, field);
|
|
1717 }
|
|
1718 if(xmlnode_get_child(query, "email")) {
|
|
1719 field = gaim_request_field_string_new("email", _("E-Mail Address"),
|
|
1720 NULL, FALSE);
|
|
1721 gaim_request_field_group_add_field(group, field);
|
|
1722 }
|
|
1723
|
|
1724 usi = g_new0(struct user_search_info, 1);
|
|
1725 usi->js = js;
|
|
1726 usi->directory_server = g_strdup(from);
|
|
1727
|
|
1728 gaim_request_fields(js->gc, _("Search for Jabber users"),
|
|
1729 _("Search for Jabber users"), instructions, fields,
|
|
1730 _("Search"), G_CALLBACK(user_search_cb),
|
|
1731 _("Cancel"), G_CALLBACK(user_search_cancel_cb), usi);
|
|
1732
|
|
1733 g_free(instructions);
|
|
1734 }
|
|
1735 }
|
|
1736
|
|
1737 static void jabber_user_search_ok(JabberStream *js, const char *directory)
|
|
1738 {
|
|
1739 JabberIq *iq;
|
|
1740
|
|
1741 /* XXX: should probably better validate the directory we're given */
|
|
1742 if(!directory || !*directory) {
|
|
1743 gaim_notify_error(js->gc, _("Invalid Directory"), _("Invalid Directory"), NULL);
|
|
1744 return;
|
|
1745 }
|
|
1746
|
|
1747 iq = jabber_iq_new_query(js, JABBER_IQ_GET, "jabber:iq:search");
|
|
1748 xmlnode_set_attrib(iq->node, "to", directory);
|
|
1749
|
|
1750 jabber_iq_set_callback(iq, user_search_fields_result_cb, NULL);
|
|
1751
|
|
1752 jabber_iq_send(iq);
|
|
1753 }
|
|
1754
|
|
1755 void jabber_user_search_begin(GaimPluginAction *action)
|
|
1756 {
|
|
1757 GaimConnection *gc = (GaimConnection *) action->context;
|
|
1758 JabberStream *js = gc->proto_data;
|
|
1759
|
|
1760 gaim_request_input(gc, _("Enter a User Directory"), _("Enter a User Directory"),
|
|
1761 _("Select a user directory to search"),
|
|
1762 js->user_directories ? js->user_directories->data : "users.jabber.org",
|
|
1763 FALSE, FALSE, NULL,
|
|
1764 _("Search Directory"), GAIM_CALLBACK(jabber_user_search_ok),
|
|
1765 _("Cancel"), NULL, js);
|
|
1766 }
|
|
1767
|
|
1768
|
|
1769
|