Mercurial > pidgin.yaz
annotate src/protocols/jabber/buddy.c @ 11509:fca94aa83486
[gaim-migrate @ 13754]
I thought I understood this type-punned pointer stuff, perhaps I'm wrong.
Why is a gchar ** considered incompatable with a guchar **?
committer: Tailor Script <tailor@pidgin.im>
author | Tim Ringenbach <marv@pidgin.im> |
---|---|
date | Sun, 11 Sep 2005 15:51:45 +0000 |
parents | ce2a2e793835 |
children | d41aabad3b7a |
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" | |
10684
72a5babfa8b4
[gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
10662
diff
changeset
|
22 #include "cipher.h" |
7014 | 23 #include "debug.h" |
7076 | 24 #include "imgstore.h" |
9713 | 25 #include "prpl.h" |
7014 | 26 #include "notify.h" |
27 #include "request.h" | |
28 #include "util.h" | |
7395 | 29 #include "xmlnode.h" |
7014 | 30 |
31 #include "buddy.h" | |
32 #include "chat.h" | |
33 #include "jabber.h" | |
34 #include "iq.h" | |
35 #include "presence.h" | |
36 | |
7116 | 37 void jabber_buddy_free(JabberBuddy *jb) |
38 { | |
39 g_return_if_fail(jb != NULL); | |
40 | |
41 if(jb->error_msg) | |
42 g_free(jb->error_msg); | |
43 while(jb->resources) | |
44 jabber_buddy_resource_free(jb->resources->data); | |
45 | |
46 g_free(jb); | |
47 } | |
48 | |
7014 | 49 JabberBuddy *jabber_buddy_find(JabberStream *js, const char *name, |
50 gboolean create) | |
51 { | |
52 JabberBuddy *jb; | |
7445 | 53 const char *realname; |
7014 | 54 |
7445 | 55 if(!(realname = jabber_normalize(js->gc->account, name))) |
7014 | 56 return NULL; |
57 | |
58 jb = g_hash_table_lookup(js->buddies, realname); | |
59 | |
60 if(!jb && create) { | |
61 jb = g_new0(JabberBuddy, 1); | |
62 g_hash_table_insert(js->buddies, g_strdup(realname), jb); | |
63 } | |
64 | |
65 return jb; | |
66 } | |
67 | |
68 | |
69 JabberBuddyResource *jabber_buddy_find_resource(JabberBuddy *jb, | |
70 const char *resource) | |
71 { | |
72 JabberBuddyResource *jbr = NULL; | |
73 GList *l; | |
74 | |
75 if(!jb) | |
76 return NULL; | |
77 | |
78 for(l = jb->resources; l; l = l->next) | |
79 { | |
80 if(!jbr && !resource) { | |
81 jbr = l->data; | |
82 } else if(!resource) { | |
83 if(((JabberBuddyResource *)l->data)->priority >= jbr->priority) | |
84 jbr = l->data; | |
85 } else if(((JabberBuddyResource *)l->data)->name) { | |
86 if(!strcmp(((JabberBuddyResource *)l->data)->name, resource)) { | |
87 jbr = l->data; | |
88 break; | |
89 } | |
90 } | |
91 } | |
92 | |
93 return jbr; | |
94 } | |
95 | |
9954 | 96 JabberBuddyResource *jabber_buddy_track_resource(JabberBuddy *jb, const char *resource, |
97 int priority, JabberBuddyState state, const char *status) | |
7014 | 98 { |
99 JabberBuddyResource *jbr = jabber_buddy_find_resource(jb, resource); | |
100 | |
101 if(!jbr) { | |
102 jbr = g_new0(JabberBuddyResource, 1); | |
7116 | 103 jbr->jb = jb; |
7014 | 104 jbr->name = g_strdup(resource); |
105 jbr->capabilities = JABBER_CAP_XHTML; | |
106 jb->resources = g_list_append(jb->resources, jbr); | |
107 } | |
108 jbr->priority = priority; | |
109 jbr->state = state; | |
110 if(jbr->status) | |
111 g_free(jbr->status); | |
112 jbr->status = g_strdup(status); | |
9954 | 113 |
114 return jbr; | |
7014 | 115 } |
116 | |
7116 | 117 void jabber_buddy_resource_free(JabberBuddyResource *jbr) |
118 { | |
119 g_return_if_fail(jbr != NULL); | |
120 | |
121 jbr->jb->resources = g_list_remove(jbr->jb->resources, jbr); | |
122 | |
123 g_free(jbr->name); | |
124 if(jbr->status) | |
125 g_free(jbr->status); | |
8400 | 126 if(jbr->thread_id) |
127 g_free(jbr->thread_id); | |
7116 | 128 g_free(jbr); |
129 } | |
130 | |
7014 | 131 void jabber_buddy_remove_resource(JabberBuddy *jb, const char *resource) |
132 { | |
133 JabberBuddyResource *jbr = jabber_buddy_find_resource(jb, resource); | |
134 | |
135 if(!jbr) | |
136 return; | |
137 | |
7116 | 138 jabber_buddy_resource_free(jbr); |
7014 | 139 } |
140 | |
141 const char *jabber_buddy_get_status_msg(JabberBuddy *jb) | |
142 { | |
143 JabberBuddyResource *jbr; | |
144 | |
145 if(!jb) | |
146 return NULL; | |
147 | |
148 jbr = jabber_buddy_find_resource(jb, NULL); | |
149 | |
150 if(!jbr) | |
151 return NULL; | |
152 | |
153 return jbr->status; | |
154 } | |
155 | |
156 /******* | |
157 * This is the old vCard stuff taken from the old prpl. vCards, by definition | |
158 * are a temporary thing until jabber can get its act together and come up | |
159 * with a format for user information, hence the namespace of 'vcard-temp' | |
160 * | |
161 * Since I don't feel like putting that much work into something that's | |
162 * _supposed_ to go away, i'm going to just copy the kludgy old code here, | |
163 * and make it purdy when jabber comes up with a standards-track JEP to | |
164 * replace vcard-temp | |
165 * --Nathan | |
166 *******/ | |
167 | |
168 /*---------------------------------------*/ | |
169 /* Jabber "set info" (vCard) support */ | |
170 /*---------------------------------------*/ | |
171 | |
172 /* | |
173 * V-Card format: | |
174 * | |
175 * <vCard prodid='' version='' xmlns=''> | |
176 * <FN></FN> | |
177 * <N> | |
178 * <FAMILY/> | |
179 * <GIVEN/> | |
180 * </N> | |
181 * <NICKNAME/> | |
182 * <URL/> | |
183 * <ADR> | |
184 * <STREET/> | |
185 * <EXTADD/> | |
186 * <LOCALITY/> | |
187 * <REGION/> | |
188 * <PCODE/> | |
189 * <COUNTRY/> | |
190 * </ADR> | |
191 * <TEL/> | |
192 * <EMAIL/> | |
193 * <ORG> | |
194 * <ORGNAME/> | |
195 * <ORGUNIT/> | |
196 * </ORG> | |
197 * <TITLE/> | |
198 * <ROLE/> | |
199 * <DESC/> | |
200 * <BDAY/> | |
201 * </vCard> | |
202 * | |
203 * See also: | |
204 * | |
205 * http://docs.jabber.org/proto/html/vcard-temp.html | |
206 * http://www.vcard-xml.org/dtd/vCard-XML-v2-20010520.dtd | |
207 */ | |
208 | |
209 /* | |
210 * Cross-reference user-friendly V-Card entry labels to vCard XML tags | |
211 * and attributes. | |
212 * | |
213 * Order is (or should be) unimportant. For example: we have no way of | |
214 * knowing in what order real data will arrive. | |
215 * | |
216 * Format: Label, Pre-set text, "visible" flag, "editable" flag, XML tag | |
217 * name, XML tag's parent tag "path" (relative to vCard node). | |
218 * | |
219 * List is terminated by a NULL label pointer. | |
220 * | |
221 * Entries with no label text, but with XML tag and parent tag | |
222 * entries, are used by V-Card XML construction routines to | |
223 * "automagically" construct the appropriate XML node tree. | |
224 * | |
225 * Thoughts on future direction/expansion | |
226 * | |
227 * This is a "simple" vCard. | |
228 * | |
229 * It is possible for nodes other than the "vCard" node to have | |
230 * attributes. Should that prove necessary/desirable, add an | |
231 * "attributes" pointer to the vcard_template struct, create the | |
232 * necessary tag_attr structs, and add 'em to the vcard_dflt_data | |
233 * array. | |
234 * | |
235 * The above changes will (obviously) require changes to the vCard | |
236 * construction routines. | |
237 */ | |
238 | |
239 struct vcard_template { | |
240 char *label; /* label text pointer */ | |
241 char *text; /* entry text pointer */ | |
242 int visible; /* should entry field be "visible?" */ | |
243 int editable; /* should entry field be editable? */ | |
244 char *tag; /* tag text */ | |
245 char *ptag; /* parent tag "path" text */ | |
246 char *url; /* vCard display format if URL */ | |
247 } vcard_template_data[] = { | |
248 {N_("Full Name"), NULL, TRUE, TRUE, "FN", NULL, NULL}, | |
249 {N_("Family Name"), NULL, TRUE, TRUE, "FAMILY", "N", NULL}, | |
250 {N_("Given Name"), NULL, TRUE, TRUE, "GIVEN", "N", NULL}, | |
251 {N_("Nickname"), NULL, TRUE, TRUE, "NICKNAME", NULL, NULL}, | |
252 {N_("URL"), NULL, TRUE, TRUE, "URL", NULL, "<A HREF=\"%s\">%s</A>"}, | |
253 {N_("Street Address"), NULL, TRUE, TRUE, "STREET", "ADR", NULL}, | |
254 {N_("Extended Address"), NULL, TRUE, TRUE, "EXTADD", "ADR", NULL}, | |
255 {N_("Locality"), NULL, TRUE, TRUE, "LOCALITY", "ADR", NULL}, | |
256 {N_("Region"), NULL, TRUE, TRUE, "REGION", "ADR", NULL}, | |
257 {N_("Postal Code"), NULL, TRUE, TRUE, "PCODE", "ADR", NULL}, | |
258 {N_("Country"), NULL, TRUE, TRUE, "COUNTRY", "ADR", NULL}, | |
11361 | 259 {N_("Telephone"), NULL, TRUE, TRUE, "NUMBER", "TEL", NULL}, |
260 {N_("Email"), NULL, TRUE, TRUE, "USERID", "EMAIL", "<A HREF=\"mailto:%s\">%s</A>"}, | |
7014 | 261 {N_("Organization Name"), NULL, TRUE, TRUE, "ORGNAME", "ORG", NULL}, |
262 {N_("Organization Unit"), NULL, TRUE, TRUE, "ORGUNIT", "ORG", NULL}, | |
263 {N_("Title"), NULL, TRUE, TRUE, "TITLE", NULL, NULL}, | |
264 {N_("Role"), NULL, TRUE, TRUE, "ROLE", NULL, NULL}, | |
265 {N_("Birthday"), NULL, TRUE, TRUE, "BDAY", NULL, NULL}, | |
266 {N_("Description"), NULL, TRUE, TRUE, "DESC", NULL, NULL}, | |
267 {"", NULL, TRUE, TRUE, "N", NULL, NULL}, | |
268 {"", NULL, TRUE, TRUE, "ADR", NULL, NULL}, | |
269 {"", NULL, TRUE, TRUE, "ORG", NULL, NULL}, | |
270 {NULL, NULL, 0, 0, NULL, NULL, NULL} | |
271 }; | |
272 | |
273 /* | |
8735
92cbf9713795
[gaim-migrate @ 9490]
Christian Hammond <chipx86@chipx86.com>
parents:
8401
diff
changeset
|
274 * The "vCard" tag's attribute list... |
7014 | 275 */ |
276 struct tag_attr { | |
277 char *attr; | |
278 char *value; | |
279 } vcard_tag_attr_list[] = { | |
280 {"prodid", "-//HandGen//NONSGML vGen v1.0//EN"}, | |
281 {"version", "2.0", }, | |
282 {"xmlns", "vcard-temp", }, | |
283 {NULL, NULL}, | |
284 }; | |
285 | |
286 | |
287 /* | |
288 * Insert a tag node into an xmlnode tree, recursively inserting parent tag | |
289 * nodes as necessary | |
290 * | |
291 * Returns pointer to inserted node | |
292 * | |
293 * Note to hackers: this code is designed to be re-entrant (it's recursive--it | |
294 * calls itself), so don't put any "static"s in here! | |
295 */ | |
296 static xmlnode *insert_tag_to_parent_tag(xmlnode *start, const char *parent_tag, const char *new_tag) | |
297 { | |
298 xmlnode *x = NULL; | |
299 | |
300 /* | |
301 * If the parent tag wasn't specified, see if we can get it | |
302 * from the vCard template struct. | |
303 */ | |
304 if(parent_tag == NULL) { | |
305 struct vcard_template *vc_tp = vcard_template_data; | |
306 | |
307 while(vc_tp->label != NULL) { | |
308 if(strcmp(vc_tp->tag, new_tag) == 0) { | |
309 parent_tag = vc_tp->ptag; | |
310 break; | |
311 } | |
312 ++vc_tp; | |
313 } | |
314 } | |
315 | |
316 /* | |
317 * If we have a parent tag... | |
318 */ | |
319 if(parent_tag != NULL ) { | |
320 /* | |
321 * Try to get the parent node for a tag | |
322 */ | |
323 if((x = xmlnode_get_child(start, parent_tag)) == NULL) { | |
324 /* | |
325 * Descend? | |
326 */ | |
327 char *grand_parent = g_strdup(parent_tag); | |
328 char *parent; | |
329 | |
330 if((parent = strrchr(grand_parent, '/')) != NULL) { | |
331 *(parent++) = '\0'; | |
332 x = insert_tag_to_parent_tag(start, grand_parent, parent); | |
333 } else { | |
334 x = xmlnode_new_child(start, grand_parent); | |
335 } | |
336 g_free(grand_parent); | |
337 } else { | |
338 /* | |
339 * We found *something* to be the parent node. | |
340 * Note: may be the "root" node! | |
341 */ | |
342 xmlnode *y; | |
343 if((y = xmlnode_get_child(x, new_tag)) != NULL) { | |
344 return(y); | |
345 } | |
346 } | |
347 } | |
348 | |
349 /* | |
350 * insert the new tag into its parent node | |
351 */ | |
352 return(xmlnode_new_child((x == NULL? start : x), new_tag)); | |
353 } | |
354 | |
355 /* | |
356 * Send vCard info to Jabber server | |
357 */ | |
358 void jabber_set_info(GaimConnection *gc, const char *info) | |
359 { | |
360 JabberIq *iq; | |
361 JabberStream *js = gc->proto_data; | |
362 xmlnode *vc_node; | |
11303
10066662176a
[gaim-migrate @ 13503]
Richard Laager <rlaager@wiktel.com>
parents:
11183
diff
changeset
|
363 char *avatar_file = NULL; |
7014 | 364 |
10189 | 365 if(js->avatar_hash) |
366 g_free(js->avatar_hash); | |
367 js->avatar_hash = NULL; | |
7014 | 368 |
369 /* | |
370 * Send only if there's actually any *information* to send | |
371 */ | |
11388 | 372 vc_node = info ? xmlnode_from_str(info, -1) : NULL; |
11318 | 373 avatar_file = gaim_buddy_icons_get_full_path(gaim_account_get_buddy_icon(gc->account)); |
10189 | 374 |
375 if(!vc_node && avatar_file) { | |
376 vc_node = xmlnode_new("vCard"); | |
377 } | |
7014 | 378 |
379 if(vc_node) { | |
380 if (vc_node->name && | |
10189 | 381 !g_ascii_strncasecmp(vc_node->name, "vCard", 5)) { |
382 GError *error = NULL; | |
11509 | 383 gchar *avatar_data_tmp; |
384 guchar *avatar_data; | |
10189 | 385 gsize avatar_len; |
386 | |
11509 | 387 if(avatar_file && g_file_get_contents(avatar_file, &avatar_data_tmp, &avatar_len, &error)) { |
10941 | 388 xmlnode *photo, *binval; |
11127 | 389 gchar *enc; |
11509 | 390 avatar_data = (guchar *) avatar_data_tmp; |
10189 | 391 int i; |
392 unsigned char hashval[20]; | |
393 char *p, hash[41]; | |
394 | |
395 photo = xmlnode_new_child(vc_node, "PHOTO"); | |
10941 | 396 binval = xmlnode_new_child(photo, "BINVAL"); |
10189 | 397 enc = gaim_base64_encode(avatar_data, avatar_len); |
10684
72a5babfa8b4
[gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
10662
diff
changeset
|
398 |
11183 | 399 gaim_cipher_digest_region("sha1", (guchar *)avatar_data, |
10687
b256ce6b85b8
[gaim-migrate @ 12235]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10684
diff
changeset
|
400 avatar_len, sizeof(hashval), |
b256ce6b85b8
[gaim-migrate @ 12235]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10684
diff
changeset
|
401 hashval, NULL); |
10684
72a5babfa8b4
[gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
10662
diff
changeset
|
402 |
10189 | 403 p = hash; |
404 for(i=0; i<20; i++, p+=2) | |
405 snprintf(p, 3, "%02x", hashval[i]); | |
406 js->avatar_hash = g_strdup(hash); | |
407 | |
10941 | 408 xmlnode_insert_data(binval, enc, -1); |
10189 | 409 g_free(enc); |
410 g_free(avatar_data); | |
10504 | 411 } else if (error != NULL) { |
10189 | 412 g_error_free(error); |
413 } | |
11303
10066662176a
[gaim-migrate @ 13503]
Richard Laager <rlaager@wiktel.com>
parents:
11183
diff
changeset
|
414 g_free(avatar_file); |
10189 | 415 |
7014 | 416 iq = jabber_iq_new(js, JABBER_IQ_SET); |
417 xmlnode_insert_child(iq->node, vc_node); | |
418 jabber_iq_send(iq); | |
419 } else { | |
420 xmlnode_free(vc_node); | |
421 } | |
422 } | |
423 } | |
424 | |
10189 | 425 void jabber_set_buddy_icon(GaimConnection *gc, const char *iconfile) |
426 { | |
427 GaimPresence *gpresence; | |
428 GaimStatus *status; | |
429 | |
430 jabber_set_info(gc, gaim_account_get_user_info(gc->account)); | |
431 | |
432 gpresence = gaim_account_get_presence(gc->account); | |
433 status = gaim_presence_get_active_status(gpresence); | |
10216 | 434 jabber_presence_send(gc->account, status); |
10189 | 435 } |
436 | |
7014 | 437 /* |
438 * This is the callback from the "ok clicked" for "set vCard" | |
439 * | |
440 * Formats GSList data into XML-encoded string and returns a pointer | |
441 * to said string. | |
442 * | |
443 * g_free()'ing the returned string space is the responsibility of | |
444 * the caller. | |
445 */ | |
446 static void | |
447 jabber_format_info(GaimConnection *gc, GaimRequestFields *fields) | |
448 { | |
449 GaimAccount *account; | |
450 xmlnode *vc_node; | |
451 GaimRequestField *field; | |
452 const char *text; | |
453 char *p; | |
454 const struct vcard_template *vc_tp; | |
455 struct tag_attr *tag_attr; | |
456 | |
457 vc_node = xmlnode_new("vCard"); | |
458 | |
459 for(tag_attr = vcard_tag_attr_list; tag_attr->attr != NULL; ++tag_attr) | |
460 xmlnode_set_attrib(vc_node, tag_attr->attr, tag_attr->value); | |
461 | |
462 for (vc_tp = vcard_template_data; vc_tp->label != NULL; vc_tp++) { | |
463 if (*vc_tp->label == '\0') | |
464 continue; | |
465 | |
466 field = gaim_request_fields_get_field(fields, vc_tp->tag); | |
467 text = gaim_request_field_string_get_value(field); | |
468 | |
469 | |
470 if (text != NULL && *text != '\0') { | |
471 xmlnode *xp; | |
472 | |
9339 | 473 gaim_debug(GAIM_DEBUG_INFO, "jabber", |
474 "Setting %s to '%s'\n", vc_tp->tag, text); | |
475 | |
7014 | 476 if ((xp = insert_tag_to_parent_tag(vc_node, |
477 NULL, vc_tp->tag)) != NULL) { | |
478 | |
479 xmlnode_insert_data(xp, text, -1); | |
480 } | |
481 } | |
482 } | |
483 | |
7642 | 484 p = xmlnode_to_str(vc_node, NULL); |
7014 | 485 xmlnode_free(vc_node); |
486 | |
487 account = gaim_connection_get_account(gc); | |
488 | |
489 if (account != NULL) { | |
490 gaim_account_set_user_info(account, p); | |
491 | |
492 if (gc != NULL) | |
493 serv_set_info(gc, p); | |
494 } | |
495 | |
496 g_free(p); | |
497 } | |
498 | |
499 /* | |
500 * This gets executed by the proto action | |
501 * | |
502 * Creates a new GaimRequestFields struct, gets the XML-formatted user_info | |
503 * string (if any) into GSLists for the (multi-entry) edit dialog and | |
504 * calls the set_vcard dialog. | |
505 */ | |
9015 | 506 void jabber_setup_set_info(GaimPluginAction *action) |
7014 | 507 { |
9015 | 508 GaimConnection *gc = (GaimConnection *) action->context; |
7014 | 509 GaimRequestFields *fields; |
510 GaimRequestFieldGroup *group; | |
511 GaimRequestField *field; | |
512 const struct vcard_template *vc_tp; | |
513 char *user_info; | |
514 char *cdata; | |
515 xmlnode *x_vc_data = NULL; | |
516 | |
517 fields = gaim_request_fields_new(); | |
518 group = gaim_request_field_group_new(NULL); | |
519 gaim_request_fields_add_group(fields, group); | |
520 | |
521 /* | |
522 * Get existing, XML-formatted, user info | |
523 */ | |
524 if((user_info = g_strdup(gaim_account_get_user_info(gc->account))) != NULL) | |
525 x_vc_data = xmlnode_from_str(user_info, -1); | |
526 else | |
527 user_info = g_strdup(""); | |
528 | |
529 /* | |
530 * Set up GSLists for edit with labels from "template," data from user info | |
531 */ | |
532 for(vc_tp = vcard_template_data; vc_tp->label != NULL; ++vc_tp) { | |
533 xmlnode *data_node; | |
534 if((vc_tp->label)[0] == '\0') | |
535 continue; | |
536 if(vc_tp->ptag == NULL) { | |
537 data_node = xmlnode_get_child(x_vc_data, vc_tp->tag); | |
538 } else { | |
539 gchar *tag = g_strdup_printf("%s/%s", vc_tp->ptag, vc_tp->tag); | |
540 data_node = xmlnode_get_child(x_vc_data, tag); | |
541 g_free(tag); | |
542 } | |
543 if(data_node) | |
544 cdata = xmlnode_get_data(data_node); | |
545 else | |
546 cdata = NULL; | |
547 | |
548 if(strcmp(vc_tp->tag, "DESC") == 0) { | |
549 field = gaim_request_field_string_new(vc_tp->tag, | |
550 _(vc_tp->label), cdata, | |
551 TRUE); | |
552 } else { | |
553 field = gaim_request_field_string_new(vc_tp->tag, | |
554 _(vc_tp->label), cdata, | |
555 FALSE); | |
556 } | |
557 | |
558 gaim_request_field_group_add_field(group, field); | |
559 } | |
560 | |
561 if(x_vc_data != NULL) | |
562 xmlnode_free(x_vc_data); | |
563 | |
564 g_free(user_info); | |
565 | |
566 gaim_request_fields(gc, _("Edit Jabber vCard"), | |
567 _("Edit Jabber vCard"), | |
568 _("All items below are optional. Enter only the " | |
569 "information with which you feel comfortable."), | |
570 fields, | |
571 _("Save"), G_CALLBACK(jabber_format_info), | |
572 _("Cancel"), NULL, | |
573 gc); | |
574 } | |
575 | |
576 /*---------------------------------------*/ | |
577 /* End Jabber "set info" (vCard) support */ | |
578 /*---------------------------------------*/ | |
579 | |
580 /****** | |
581 * end of that ancient crap that needs to die | |
582 ******/ | |
583 | |
584 | |
7395 | 585 static void jabber_vcard_parse(JabberStream *js, xmlnode *packet, gpointer data) |
7014 | 586 { |
587 GList *resources; | |
588 const char *from = xmlnode_get_attrib(packet, "from"); | |
589 JabberBuddy *jb; | |
590 JabberBuddyResource *jbr; | |
591 GString *info_text; | |
7306 | 592 char *resource_name; |
7955 | 593 char *bare_jid; |
7014 | 594 char *title; |
8213 | 595 char *text; |
7014 | 596 xmlnode *vcard; |
7955 | 597 GaimBuddy *b; |
10189 | 598 GSList *imgids = NULL; |
7014 | 599 |
600 if(!from) | |
601 return; | |
602 | |
11361 | 603 if(!(jb = jabber_buddy_find(js, from, TRUE))) |
604 return; | |
605 | |
10490 | 606 /* XXX: handle the error case */ |
607 | |
7014 | 608 resource_name = jabber_get_resource(from); |
7955 | 609 bare_jid = jabber_get_bare_jid(from); |
610 | |
611 b = gaim_find_buddy(js->gc->account, bare_jid); | |
7014 | 612 |
11361 | 613 |
7014 | 614 info_text = g_string_new(""); |
615 | |
8213 | 616 g_string_append_printf(info_text, "<b>%s:</b> %s<br/>", _("Jabber ID"), |
7014 | 617 from); |
618 | |
619 if(resource_name) { | |
620 jbr = jabber_buddy_find_resource(jb, resource_name); | |
621 if(jbr) { | |
7145 | 622 char *purdy = NULL; |
623 if(jbr->status) | |
624 purdy = gaim_strdup_withhtml(jbr->status); | |
8213 | 625 g_string_append_printf(info_text, "<b>%s:</b> %s%s%s<br/>", |
9954 | 626 _("Status"), jabber_buddy_state_get_name(jbr->state), |
7014 | 627 purdy ? ": " : "", |
628 purdy ? purdy : ""); | |
7145 | 629 if(purdy) |
630 g_free(purdy); | |
7014 | 631 } else { |
8213 | 632 g_string_append_printf(info_text, "<b>%s:</b> %s<br/>", |
7014 | 633 _("Status"), _("Unknown")); |
634 } | |
635 } else { | |
636 for(resources = jb->resources; resources; resources = resources->next) { | |
7145 | 637 char *purdy = NULL; |
7014 | 638 jbr = resources->data; |
7145 | 639 if(jbr->status) |
640 purdy = gaim_strdup_withhtml(jbr->status); | |
8213 | 641 g_string_append_printf(info_text, "<b>%s:</b> %s<br/>", |
7014 | 642 _("Resource"), jbr->name); |
8213 | 643 g_string_append_printf(info_text, "<b>%s:</b> %s%s%s<br/><br/>", |
9954 | 644 _("Status"), jabber_buddy_state_get_name(jbr->state), |
7014 | 645 purdy ? ": " : "", |
646 purdy ? purdy : ""); | |
7145 | 647 if(purdy) |
648 g_free(purdy); | |
7014 | 649 } |
650 } | |
651 | |
7306 | 652 g_free(resource_name); |
653 | |
10189 | 654 if((vcard = xmlnode_get_child(packet, "vCard")) || |
655 (vcard = xmlnode_get_child_with_namespace(packet, "query", "vcard-temp"))) { | |
7014 | 656 xmlnode *child; |
657 for(child = vcard->child; child; child = child->next) | |
658 { | |
659 xmlnode *child2; | |
660 | |
8135 | 661 if(child->type != XMLNODE_TYPE_TAG) |
7014 | 662 continue; |
663 | |
664 text = xmlnode_get_data(child); | |
665 if(text && !strcmp(child->name, "FN")) { | |
8213 | 666 g_string_append_printf(info_text, "<b>%s:</b> %s<br/>", |
7014 | 667 _("Full Name"), text); |
668 } else if(!strcmp(child->name, "N")) { | |
669 for(child2 = child->child; child2; child2 = child2->next) | |
670 { | |
671 char *text2; | |
672 | |
8135 | 673 if(child2->type != XMLNODE_TYPE_TAG) |
7014 | 674 continue; |
675 | |
676 text2 = xmlnode_get_data(child2); | |
677 if(text2 && !strcmp(child2->name, "FAMILY")) { | |
678 g_string_append_printf(info_text, | |
8213 | 679 "<b>%s:</b> %s<br/>", |
7014 | 680 _("Family Name"), text2); |
681 } else if(text2 && !strcmp(child2->name, "GIVEN")) { | |
682 g_string_append_printf(info_text, | |
8213 | 683 "<b>%s:</b> %s<br/>", |
7014 | 684 _("Given Name"), text2); |
685 } else if(text2 && !strcmp(child2->name, "MIDDLE")) { | |
686 g_string_append_printf(info_text, | |
8213 | 687 "<b>%s:</b> %s<br/>", |
7014 | 688 _("Middle Name"), text2); |
689 } | |
690 g_free(text2); | |
691 } | |
692 } else if(text && !strcmp(child->name, "NICKNAME")) { | |
693 serv_got_alias(js->gc, from, text); | |
7955 | 694 if(b) { |
695 gaim_blist_node_set_string((GaimBlistNode*)b, "servernick", text); | |
696 } | |
8213 | 697 g_string_append_printf(info_text, "<b>%s:</b> %s<br/>", |
7014 | 698 _("Nickname"), text); |
699 } else if(text && !strcmp(child->name, "BDAY")) { | |
8213 | 700 g_string_append_printf(info_text, "<b>%s:</b> %s<br/>", |
7014 | 701 _("Birthday"), text); |
702 } else if(!strcmp(child->name, "ADR")) { | |
703 /* show which address it is */ | |
704 if(child->child) | |
8213 | 705 g_string_append_printf(info_text, "<b>%s:</b><br/>", |
7014 | 706 _("Address")); |
707 for(child2 = child->child; child2; child2 = child2->next) | |
708 { | |
709 char *text2; | |
710 | |
8135 | 711 if(child2->type != XMLNODE_TYPE_TAG) |
7014 | 712 continue; |
713 | |
714 text2 = xmlnode_get_data(child2); | |
715 if(text2 && !strcmp(child2->name, "POBOX")) { | |
716 g_string_append_printf(info_text, | |
8213 | 717 " <b>%s:</b> %s<br/>", |
7014 | 718 _("P.O. Box"), text2); |
719 } else if(text2 && !strcmp(child2->name, "EXTADR")) { | |
720 g_string_append_printf(info_text, | |
8213 | 721 " <b>%s:</b> %s<br/>", |
7014 | 722 _("Extended Address"), text2); |
723 } else if(text2 && !strcmp(child2->name, "STREET")) { | |
724 g_string_append_printf(info_text, | |
8213 | 725 " <b>%s:</b> %s<br/>", |
7014 | 726 _("Street Address"), text2); |
727 } else if(text2 && !strcmp(child2->name, "LOCALITY")) { | |
728 g_string_append_printf(info_text, | |
8213 | 729 " <b>%s:</b> %s<br/>", |
7014 | 730 _("Locality"), text2); |
731 } else if(text2 && !strcmp(child2->name, "REGION")) { | |
732 g_string_append_printf(info_text, | |
8213 | 733 " <b>%s:</b> %s<br/>", |
7014 | 734 _("Region"), text2); |
735 } else if(text2 && !strcmp(child2->name, "PCODE")) { | |
736 g_string_append_printf(info_text, | |
8213 | 737 " <b>%s:</b> %s<br/>", |
7014 | 738 _("Postal Code"), text2); |
739 } else if(text2 && (!strcmp(child2->name, "CTRY") | |
740 || !strcmp(child2->name, "COUNTRY"))) { | |
741 g_string_append_printf(info_text, | |
8213 | 742 " <b>%s:</b> %s<br/>", |
7014 | 743 _("Country"), text2); |
744 } | |
745 g_free(text2); | |
746 } | |
747 } else if(!strcmp(child->name, "TEL")) { | |
748 char *number; | |
749 if((child2 = xmlnode_get_child(child, "NUMBER"))) { | |
750 /* show what kind of number it is */ | |
751 number = xmlnode_get_data(child2); | |
752 if(number) { | |
753 g_string_append_printf(info_text, | |
8213 | 754 "<b>%s:</b> %s<br/>", _("Telephone"), number); |
7014 | 755 g_free(number); |
756 } | |
757 } else if((number = xmlnode_get_data(child))) { | |
758 /* lots of clients (including gaim) do this, but it's | |
759 * out of spec */ | |
760 g_string_append_printf(info_text, | |
8213 | 761 "<b>%s:</b> %s<br/>", _("Telephone"), number); |
7014 | 762 g_free(number); |
763 } | |
764 } else if(!strcmp(child->name, "EMAIL")) { | |
765 char *userid; | |
766 if((child2 = xmlnode_get_child(child, "USERID"))) { | |
767 /* show what kind of email it is */ | |
768 userid = xmlnode_get_data(child2); | |
769 if(userid) { | |
770 g_string_append_printf(info_text, | |
8213 | 771 "<b>%s:</b> <a href='mailto:%s'>%s</a><br/>", |
7014 | 772 _("Email"), userid, userid); |
773 g_free(userid); | |
774 } | |
775 } else if((userid = xmlnode_get_data(child))) { | |
776 /* lots of clients (including gaim) do this, but it's | |
777 * out of spec */ | |
778 g_string_append_printf(info_text, | |
8213 | 779 "<b>%s:</b> <a href='mailto:%s'>%s</a><br/>", |
7014 | 780 _("Email"), userid, userid); |
781 g_free(userid); | |
782 } | |
783 } else if(!strcmp(child->name, "ORG")) { | |
784 for(child2 = child->child; child2; child2 = child2->next) | |
785 { | |
786 char *text2; | |
787 | |
8135 | 788 if(child2->type != XMLNODE_TYPE_TAG) |
7014 | 789 continue; |
790 | |
791 text2 = xmlnode_get_data(child2); | |
792 if(text2 && !strcmp(child2->name, "ORGNAME")) { | |
793 g_string_append_printf(info_text, | |
8213 | 794 "<b>%s:</b> %s<br/>", |
7014 | 795 _("Organization Name"), text2); |
796 } else if(text2 && !strcmp(child2->name, "ORGUNIT")) { | |
797 g_string_append_printf(info_text, | |
8213 | 798 "<b>%s:</b> %s<br/>", |
7014 | 799 _("Organization Unit"), text2); |
800 } | |
801 g_free(text2); | |
802 } | |
803 } else if(text && !strcmp(child->name, "TITLE")) { | |
8213 | 804 g_string_append_printf(info_text, "<b>%s:</b> %s<br/>", |
7014 | 805 _("Title"), text); |
806 } else if(text && !strcmp(child->name, "ROLE")) { | |
8213 | 807 g_string_append_printf(info_text, "<b>%s:</b> %s<br/>", |
7014 | 808 _("Role"), text); |
809 } else if(text && !strcmp(child->name, "DESC")) { | |
8213 | 810 g_string_append_printf(info_text, "<b>%s:</b> %s<br/>", |
811 _("Description"), text); | |
7076 | 812 } else if(!strcmp(child->name, "PHOTO") || |
813 !strcmp(child->name, "LOGO")) { | |
10941 | 814 char *bintext = NULL; |
815 xmlnode *binval; | |
11361 | 816 |
817 if( ((binval = xmlnode_get_child(child, "BINVAL")) && | |
818 (bintext = xmlnode_get_data(binval))) || | |
819 (bintext = xmlnode_get_data(child))) { | |
11127 | 820 gsize size; |
11137 | 821 guchar *data; |
11127 | 822 int i; |
10941 | 823 unsigned char hashval[20]; |
11127 | 824 char *p, hash[41]; |
10941 | 825 gboolean photo = (strcmp(child->name, "PHOTO") == 0); |
10189 | 826 |
11361 | 827 data = gaim_base64_decode(bintext, &size); |
7076 | 828 |
10941 | 829 imgids = g_slist_prepend(imgids, GINT_TO_POINTER(gaim_imgstore_add(data, size, "logo.png"))); |
830 g_string_append_printf(info_text, | |
831 "<b>%s:</b> <img id='%d'><br/>", | |
832 photo ? _("Photo") : _("Logo"), | |
833 GPOINTER_TO_INT(imgids->data)); | |
7076 | 834 |
10941 | 835 gaim_buddy_icons_set_for_user(js->gc->account, bare_jid, |
836 data, size); | |
10189 | 837 |
11183 | 838 gaim_cipher_digest_region("sha1", (guchar *)data, size, |
10941 | 839 sizeof(hashval), hashval, NULL); |
840 p = hash; | |
841 for(i=0; i<20; i++, p+=2) | |
842 snprintf(p, 3, "%02x", hashval[i]); | |
843 gaim_blist_node_set_string((GaimBlistNode*)b, "avatar_hash", hash); | |
10189 | 844 |
10941 | 845 g_free(data); |
846 g_free(bintext); | |
847 } | |
7014 | 848 } |
849 g_free(text); | |
850 } | |
851 } | |
852 | |
853 title = g_strdup_printf("User info for %s", from); | |
854 | |
8213 | 855 text = gaim_strdup_withhtml(info_text->str); |
856 | |
9797 | 857 gaim_notify_userinfo(js->gc, from, title, _("Jabber Profile"), |
8213 | 858 NULL, text, NULL, NULL); |
7014 | 859 |
10189 | 860 while(imgids) { |
861 gaim_imgstore_unref(GPOINTER_TO_INT(imgids->data)); | |
862 imgids = g_slist_delete_link(imgids, imgids); | |
863 } | |
7014 | 864 g_free(title); |
865 g_string_free(info_text, TRUE); | |
8213 | 866 g_free(text); |
10189 | 867 g_free(bare_jid); |
7014 | 868 } |
869 | |
10189 | 870 static void jabber_buddy_get_info_for_jid(JabberStream *js, const char *full_jid) |
7014 | 871 { |
872 JabberIq *iq; | |
873 xmlnode *vcard; | |
874 | |
875 iq = jabber_iq_new(js, JABBER_IQ_GET); | |
876 | |
10189 | 877 xmlnode_set_attrib(iq->node, "to", full_jid); |
7014 | 878 vcard = xmlnode_new_child(iq->node, "vCard"); |
879 xmlnode_set_attrib(vcard, "xmlns", "vcard-temp"); | |
880 | |
7395 | 881 jabber_iq_set_callback(iq, jabber_vcard_parse, NULL); |
7014 | 882 |
883 jabber_iq_send(iq); | |
884 } | |
885 | |
10189 | 886 void jabber_buddy_get_info(GaimConnection *gc, const char *who) |
887 { | |
888 JabberStream *js = gc->proto_data; | |
889 char *bare_jid = jabber_get_bare_jid(who); | |
890 | |
891 if(bare_jid) { | |
892 jabber_buddy_get_info_for_jid(js, bare_jid); | |
893 g_free(bare_jid); | |
894 } | |
895 } | |
896 | |
7014 | 897 void jabber_buddy_get_info_chat(GaimConnection *gc, int id, |
898 const char *resource) | |
899 { | |
900 JabberStream *js = gc->proto_data; | |
901 JabberChat *chat = jabber_chat_find_by_id(js, id); | |
902 char *full_jid; | |
903 | |
904 if(!chat) | |
905 return; | |
906 | |
907 full_jid = g_strdup_printf("%s@%s/%s", chat->room, chat->server, resource); | |
10189 | 908 jabber_buddy_get_info_for_jid(js, full_jid); |
7014 | 909 g_free(full_jid); |
910 } | |
911 | |
7395 | 912 |
7014 | 913 static void jabber_buddy_set_invisibility(JabberStream *js, const char *who, |
914 gboolean invisible) | |
915 { | |
9944 | 916 GaimPresence *gpresence; |
917 GaimAccount *account; | |
918 GaimStatus *status; | |
7014 | 919 JabberBuddy *jb = jabber_buddy_find(js, who, TRUE); |
920 xmlnode *presence; | |
9954 | 921 JabberBuddyState state; |
922 const char *msg; | |
923 int priority; | |
7014 | 924 |
9944 | 925 account = gaim_connection_get_account(js->gc); |
926 gpresence = gaim_account_get_presence(account); | |
927 status = gaim_presence_get_active_status(gpresence); | |
928 | |
9954 | 929 gaim_status_to_jabber(status, &state, &msg, &priority); |
930 presence = jabber_presence_create(state, msg, priority); | |
931 | |
7014 | 932 xmlnode_set_attrib(presence, "to", who); |
933 if(invisible) { | |
934 xmlnode_set_attrib(presence, "type", "invisible"); | |
935 jb->invisible |= JABBER_INVIS_BUDDY; | |
936 } else { | |
937 jb->invisible &= ~JABBER_INVIS_BUDDY; | |
938 } | |
939 | |
940 jabber_send(js, presence); | |
941 xmlnode_free(presence); | |
942 } | |
943 | |
9030 | 944 static void jabber_buddy_make_invisible(GaimBlistNode *node, gpointer data) |
7014 | 945 { |
9030 | 946 GaimBuddy *buddy; |
947 GaimConnection *gc; | |
948 JabberStream *js; | |
949 | |
950 g_return_if_fail(GAIM_BLIST_NODE_IS_BUDDY(node)); | |
951 | |
952 buddy = (GaimBuddy *) node; | |
953 gc = gaim_account_get_connection(buddy->account); | |
954 js = gc->proto_data; | |
955 | |
956 jabber_buddy_set_invisibility(js, buddy->name, TRUE); | |
7014 | 957 } |
958 | |
9030 | 959 static void jabber_buddy_make_visible(GaimBlistNode *node, gpointer data) |
7014 | 960 { |
9030 | 961 GaimBuddy *buddy; |
962 GaimConnection *gc; | |
963 JabberStream *js; | |
7014 | 964 |
9030 | 965 g_return_if_fail(GAIM_BLIST_NODE_IS_BUDDY(node)); |
7014 | 966 |
9030 | 967 buddy = (GaimBuddy *) node; |
968 gc = gaim_account_get_connection(buddy->account); | |
969 js = gc->proto_data; | |
970 | |
971 jabber_buddy_set_invisibility(js, buddy->name, FALSE); | |
7014 | 972 } |
973 | |
9030 | 974 static void jabber_buddy_cancel_presence_notification(GaimBlistNode *node, |
975 gpointer data) | |
7014 | 976 { |
9030 | 977 GaimBuddy *buddy; |
978 GaimConnection *gc; | |
979 JabberStream *js; | |
980 | |
981 g_return_if_fail(GAIM_BLIST_NODE_IS_BUDDY(node)); | |
7014 | 982 |
9030 | 983 buddy = (GaimBuddy *) node; |
984 gc = gaim_account_get_connection(buddy->account); | |
985 js = gc->proto_data; | |
986 | |
987 /* I wonder if we should prompt the user before doing this */ | |
988 jabber_presence_subscription_set(js, buddy->name, "unsubscribed"); | |
7014 | 989 } |
990 | |
9030 | 991 static void jabber_buddy_rerequest_auth(GaimBlistNode *node, gpointer data) |
7250 | 992 { |
9030 | 993 GaimBuddy *buddy; |
994 GaimConnection *gc; | |
995 JabberStream *js; | |
996 | |
997 g_return_if_fail(GAIM_BLIST_NODE_IS_BUDDY(node)); | |
7250 | 998 |
9030 | 999 buddy = (GaimBuddy *) node; |
1000 gc = gaim_account_get_connection(buddy->account); | |
1001 js = gc->proto_data; | |
1002 | |
1003 jabber_presence_subscription_set(js, buddy->name, "subscribe"); | |
7250 | 1004 } |
1005 | |
9030 | 1006 |
1007 static void jabber_buddy_unsubscribe(GaimBlistNode *node, gpointer data) | |
7014 | 1008 { |
9030 | 1009 GaimBuddy *buddy; |
1010 GaimConnection *gc; | |
1011 JabberStream *js; | |
1012 | |
1013 g_return_if_fail(GAIM_BLIST_NODE_IS_BUDDY(node)); | |
1014 | |
1015 buddy = (GaimBuddy *) node; | |
1016 gc = gaim_account_get_connection(buddy->account); | |
1017 js = gc->proto_data; | |
1018 | |
1019 jabber_presence_subscription_set(js, buddy->name, "unsubscribe"); | |
1020 } | |
1021 | |
1022 | |
1023 GList *jabber_buddy_menu(GaimBuddy *buddy) | |
1024 { | |
1025 GaimConnection *gc = gaim_account_get_connection(buddy->account); | |
1026 JabberStream *js = gc->proto_data; | |
1027 JabberBuddy *jb = jabber_buddy_find(js, buddy->name, TRUE); | |
1028 | |
7014 | 1029 GList *m = NULL; |
9030 | 1030 GaimBlistNodeAction *act; |
7395 | 1031 |
1032 if(!jb) | |
1033 return m; | |
1034 | |
8185 | 1035 /* XXX: fix the NOT ME below */ |
1036 | |
1037 if(js->protocol_version == JABBER_PROTO_0_9 /* && NOT ME */) { | |
8166 | 1038 if(jb->invisible & JABBER_INVIS_BUDDY) { |
9030 | 1039 act = gaim_blist_node_action_new(_("Un-hide From"), |
10662
54ac161a876e
[gaim-migrate @ 12199]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10504
diff
changeset
|
1040 jabber_buddy_make_visible, NULL, NULL); |
8166 | 1041 } else { |
9030 | 1042 act = gaim_blist_node_action_new(_("Temporarily Hide From"), |
10662
54ac161a876e
[gaim-migrate @ 12199]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10504
diff
changeset
|
1043 jabber_buddy_make_invisible, NULL, NULL); |
8166 | 1044 } |
9030 | 1045 m = g_list_append(m, act); |
7014 | 1046 } |
1047 | |
8185 | 1048 if(jb->subscription & JABBER_SUB_FROM /* && NOT ME */) { |
9030 | 1049 act = gaim_blist_node_action_new(_("Cancel Presence Notification"), |
10662
54ac161a876e
[gaim-migrate @ 12199]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10504
diff
changeset
|
1050 jabber_buddy_cancel_presence_notification, NULL, NULL); |
9030 | 1051 m = g_list_append(m, act); |
7014 | 1052 } |
1053 | |
1054 if(!(jb->subscription & JABBER_SUB_TO)) { | |
9030 | 1055 act = gaim_blist_node_action_new(_("(Re-)Request authorization"), |
10662
54ac161a876e
[gaim-migrate @ 12199]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10504
diff
changeset
|
1056 jabber_buddy_rerequest_auth, NULL, NULL); |
9030 | 1057 m = g_list_append(m, act); |
1058 | |
8185 | 1059 } else /* if(NOT ME) */{ |
9030 | 1060 |
1061 /* shouldn't this just happen automatically when the buddy is | |
1062 removed? */ | |
1063 act = gaim_blist_node_action_new(_("Unsubscribe"), | |
10662
54ac161a876e
[gaim-migrate @ 12199]
Etan Reisner <pidgin@unreliablesource.net>
parents:
10504
diff
changeset
|
1064 jabber_buddy_unsubscribe, NULL, NULL); |
9030 | 1065 m = g_list_append(m, act); |
7014 | 1066 } |
1067 | |
1068 return m; | |
1069 } | |
9030 | 1070 |
1071 GList * | |
1072 jabber_blist_node_menu(GaimBlistNode *node) | |
1073 { | |
1074 if(GAIM_BLIST_NODE_IS_BUDDY(node)) { | |
1075 return jabber_buddy_menu((GaimBuddy *) node); | |
1076 } else { | |
1077 return NULL; | |
1078 } | |
1079 } | |
1080 | |
1081 | |
9954 | 1082 const char * |
1083 jabber_buddy_state_get_name(JabberBuddyState state) | |
1084 { | |
1085 switch(state) { | |
1086 case JABBER_BUDDY_STATE_UNKNOWN: | |
1087 return _("Unknown"); | |
1088 case JABBER_BUDDY_STATE_ERROR: | |
1089 return _("Error"); | |
1090 case JABBER_BUDDY_STATE_UNAVAILABLE: | |
1091 return _("Offline"); | |
1092 case JABBER_BUDDY_STATE_ONLINE: | |
1093 return _("Online"); | |
1094 case JABBER_BUDDY_STATE_CHAT: | |
1095 return _("Chatty"); | |
1096 case JABBER_BUDDY_STATE_AWAY: | |
1097 return _("Away"); | |
1098 case JABBER_BUDDY_STATE_XA: | |
1099 return _("Extended Away"); | |
1100 case JABBER_BUDDY_STATE_DND: | |
1101 return _("Do Not Disturb"); | |
1102 } | |
1103 | |
1104 return _("Unknown"); | |
1105 } | |
1106 | |
1107 JabberBuddyState jabber_buddy_status_id_get_state(const char *id) { | |
1108 if(!id) | |
1109 return JABBER_BUDDY_STATE_UNKNOWN; | |
1110 if(!strcmp(id, "online")) | |
1111 return JABBER_BUDDY_STATE_ONLINE; | |
1112 if(!strcmp(id, "chat")) | |
1113 return JABBER_BUDDY_STATE_CHAT; | |
1114 if(!strcmp(id, "away")) | |
1115 return JABBER_BUDDY_STATE_AWAY; | |
1116 if(!strcmp(id, "xa")) | |
1117 return JABBER_BUDDY_STATE_XA; | |
1118 if(!strcmp(id, "dnd")) | |
1119 return JABBER_BUDDY_STATE_DND; | |
1120 if(!strcmp(id, "offline")) | |
1121 return JABBER_BUDDY_STATE_UNAVAILABLE; | |
1122 if(!strcmp(id, "error")) | |
1123 return JABBER_BUDDY_STATE_ERROR; | |
1124 | |
1125 return JABBER_BUDDY_STATE_UNKNOWN; | |
1126 } | |
1127 | |
1128 const char *jabber_buddy_state_get_status_id(JabberBuddyState state) { | |
1129 switch(state) { | |
1130 case JABBER_BUDDY_STATE_CHAT: | |
1131 return "chat"; | |
1132 case JABBER_BUDDY_STATE_AWAY: | |
1133 return "away"; | |
1134 case JABBER_BUDDY_STATE_XA: | |
1135 return "xa"; | |
1136 case JABBER_BUDDY_STATE_DND: | |
1137 return "dnd"; | |
1138 case JABBER_BUDDY_STATE_ONLINE: | |
1139 return "online"; | |
1140 case JABBER_BUDDY_STATE_UNKNOWN: | |
1141 case JABBER_BUDDY_STATE_ERROR: | |
1142 return NULL; | |
1143 case JABBER_BUDDY_STATE_UNAVAILABLE: | |
1144 return "offline"; | |
1145 } | |
1146 return NULL; | |
1147 } |