Sun, 17 Jun 2007 04:05:28 +0000
Turns out the example in XEP-0084 is wrong. Fixed my implementation to not try to work around an issue that isn't one.
| 7014 | 1 | /* |
| 15884 | 2 | * purple - Jabber Protocol Plugin |
| 7014 | 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
0325b164a7eb
[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
bb37562302a1
[gaim-migrate @ 10574]
Mark Doliner <markdoliner@pidgin.im>
parents:
9466
diff
changeset
|
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" | |
| 11675 | 36 | #include "xdata.h" |
|
17787
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
37 | #include "pep.h" |
| 7014 | 38 | |
| 13794 | 39 | typedef struct { |
| 40 | long idle_seconds; | |
| 41 | } JabberBuddyInfoResource; | |
| 42 | ||
| 43 | typedef struct { | |
| 44 | JabberStream *js; | |
| 45 | JabberBuddy *jb; | |
| 46 | char *jid; | |
| 47 | GSList *ids; | |
| 48 | GHashTable *resources; | |
| 49 | int timeout_handle; | |
| 50 | char *vcard_text; | |
| 51 | GSList *vcard_imgids; | |
| 52 | } JabberBuddyInfo; | |
| 53 | ||
| 7116 | 54 | void jabber_buddy_free(JabberBuddy *jb) |
| 55 | { | |
| 56 | g_return_if_fail(jb != NULL); | |
| 57 | ||
| 58 | if(jb->error_msg) | |
| 59 | g_free(jb->error_msg); | |
| 60 | while(jb->resources) | |
| 61 | jabber_buddy_resource_free(jb->resources->data); | |
| 62 | ||
| 63 | g_free(jb); | |
| 64 | } | |
| 65 | ||
| 7014 | 66 | JabberBuddy *jabber_buddy_find(JabberStream *js, const char *name, |
| 67 | gboolean create) | |
| 68 | { | |
| 69 | JabberBuddy *jb; | |
| 7445 | 70 | const char *realname; |
| 7014 | 71 | |
|
15143
37451143f5c4
[gaim-migrate @ 17867]
Mark Doliner <markdoliner@pidgin.im>
parents:
15092
diff
changeset
|
72 | if (js->buddies == NULL) |
|
37451143f5c4
[gaim-migrate @ 17867]
Mark Doliner <markdoliner@pidgin.im>
parents:
15092
diff
changeset
|
73 | return NULL; |
|
37451143f5c4
[gaim-migrate @ 17867]
Mark Doliner <markdoliner@pidgin.im>
parents:
15092
diff
changeset
|
74 | |
| 7445 | 75 | if(!(realname = jabber_normalize(js->gc->account, name))) |
| 7014 | 76 | return NULL; |
| 77 | ||
| 78 | jb = g_hash_table_lookup(js->buddies, realname); | |
| 79 | ||
| 80 | if(!jb && create) { | |
| 81 | jb = g_new0(JabberBuddy, 1); | |
| 82 | g_hash_table_insert(js->buddies, g_strdup(realname), jb); | |
| 83 | } | |
| 84 | ||
| 85 | return jb; | |
| 86 | } | |
| 87 | ||
| 88 | ||
| 89 | JabberBuddyResource *jabber_buddy_find_resource(JabberBuddy *jb, | |
| 90 | const char *resource) | |
| 91 | { | |
| 92 | JabberBuddyResource *jbr = NULL; | |
| 93 | GList *l; | |
| 94 | ||
| 95 | if(!jb) | |
| 96 | return NULL; | |
| 97 | ||
| 98 | for(l = jb->resources; l; l = l->next) | |
| 99 | { | |
| 100 | if(!jbr && !resource) { | |
| 101 | jbr = l->data; | |
| 102 | } else if(!resource) { | |
| 103 | if(((JabberBuddyResource *)l->data)->priority >= jbr->priority) | |
| 104 | jbr = l->data; | |
| 105 | } else if(((JabberBuddyResource *)l->data)->name) { | |
| 106 | if(!strcmp(((JabberBuddyResource *)l->data)->name, resource)) { | |
| 107 | jbr = l->data; | |
| 108 | break; | |
| 109 | } | |
| 110 | } | |
| 111 | } | |
| 112 | ||
| 113 | return jbr; | |
| 114 | } | |
| 115 | ||
| 9954 | 116 | JabberBuddyResource *jabber_buddy_track_resource(JabberBuddy *jb, const char *resource, |
| 117 | int priority, JabberBuddyState state, const char *status) | |
| 7014 | 118 | { |
| 119 | JabberBuddyResource *jbr = jabber_buddy_find_resource(jb, resource); | |
| 120 | ||
| 121 | if(!jbr) { | |
| 122 | jbr = g_new0(JabberBuddyResource, 1); | |
| 7116 | 123 | jbr->jb = jb; |
| 7014 | 124 | jbr->name = g_strdup(resource); |
| 125 | jbr->capabilities = JABBER_CAP_XHTML; | |
| 126 | jb->resources = g_list_append(jb->resources, jbr); | |
| 127 | } | |
| 128 | jbr->priority = priority; | |
| 129 | jbr->state = state; | |
| 130 | if(jbr->status) | |
| 131 | g_free(jbr->status); | |
| 13787 | 132 | if (status) |
| 133 | jbr->status = g_markup_escape_text(status, -1); | |
| 134 | else | |
| 135 | jbr->status = NULL; | |
| 9954 | 136 | |
| 137 | return jbr; | |
| 7014 | 138 | } |
| 139 | ||
| 7116 | 140 | void jabber_buddy_resource_free(JabberBuddyResource *jbr) |
| 141 | { | |
| 142 | g_return_if_fail(jbr != NULL); | |
| 143 | ||
| 144 | jbr->jb->resources = g_list_remove(jbr->jb->resources, jbr); | |
| 145 | ||
| 146 | g_free(jbr->name); | |
| 13794 | 147 | g_free(jbr->status); |
| 148 | g_free(jbr->thread_id); | |
| 149 | g_free(jbr->client.name); | |
| 150 | g_free(jbr->client.version); | |
| 151 | g_free(jbr->client.os); | |
| 7116 | 152 | g_free(jbr); |
| 153 | } | |
| 154 | ||
| 7014 | 155 | void jabber_buddy_remove_resource(JabberBuddy *jb, const char *resource) |
| 156 | { | |
| 157 | JabberBuddyResource *jbr = jabber_buddy_find_resource(jb, resource); | |
| 158 | ||
| 159 | if(!jbr) | |
| 160 | return; | |
| 161 | ||
| 7116 | 162 | jabber_buddy_resource_free(jbr); |
| 7014 | 163 | } |
| 164 | ||
| 165 | const char *jabber_buddy_get_status_msg(JabberBuddy *jb) | |
| 166 | { | |
| 167 | JabberBuddyResource *jbr; | |
| 168 | ||
| 169 | if(!jb) | |
| 170 | return NULL; | |
| 171 | ||
| 172 | jbr = jabber_buddy_find_resource(jb, NULL); | |
| 173 | ||
| 174 | if(!jbr) | |
| 175 | return NULL; | |
| 176 | ||
| 177 | return jbr->status; | |
| 178 | } | |
| 179 | ||
| 180 | /******* | |
| 181 | * This is the old vCard stuff taken from the old prpl. vCards, by definition | |
| 182 | * are a temporary thing until jabber can get its act together and come up | |
| 183 | * with a format for user information, hence the namespace of 'vcard-temp' | |
| 184 | * | |
| 185 | * Since I don't feel like putting that much work into something that's | |
| 186 | * _supposed_ to go away, i'm going to just copy the kludgy old code here, | |
| 187 | * and make it purdy when jabber comes up with a standards-track JEP to | |
| 188 | * replace vcard-temp | |
| 189 | * --Nathan | |
| 190 | *******/ | |
| 191 | ||
| 192 | /*---------------------------------------*/ | |
| 193 | /* Jabber "set info" (vCard) support */ | |
| 194 | /*---------------------------------------*/ | |
| 195 | ||
| 196 | /* | |
| 197 | * V-Card format: | |
| 198 | * | |
| 199 | * <vCard prodid='' version='' xmlns=''> | |
| 200 | * <FN></FN> | |
| 201 | * <N> | |
| 202 | * <FAMILY/> | |
| 203 | * <GIVEN/> | |
| 204 | * </N> | |
| 205 | * <NICKNAME/> | |
| 206 | * <URL/> | |
| 207 | * <ADR> | |
| 208 | * <STREET/> | |
| 209 | * <EXTADD/> | |
| 210 | * <LOCALITY/> | |
| 211 | * <REGION/> | |
| 212 | * <PCODE/> | |
| 213 | * <COUNTRY/> | |
| 214 | * </ADR> | |
| 215 | * <TEL/> | |
| 216 | * <EMAIL/> | |
| 217 | * <ORG> | |
| 218 | * <ORGNAME/> | |
| 219 | * <ORGUNIT/> | |
| 220 | * </ORG> | |
| 221 | * <TITLE/> | |
| 222 | * <ROLE/> | |
| 223 | * <DESC/> | |
| 224 | * <BDAY/> | |
| 225 | * </vCard> | |
| 226 | * | |
| 227 | * See also: | |
| 228 | * | |
| 229 | * http://docs.jabber.org/proto/html/vcard-temp.html | |
| 230 | * http://www.vcard-xml.org/dtd/vCard-XML-v2-20010520.dtd | |
| 231 | */ | |
| 232 | ||
| 233 | /* | |
| 234 | * Cross-reference user-friendly V-Card entry labels to vCard XML tags | |
| 235 | * and attributes. | |
| 236 | * | |
| 237 | * Order is (or should be) unimportant. For example: we have no way of | |
| 238 | * knowing in what order real data will arrive. | |
| 239 | * | |
| 240 | * Format: Label, Pre-set text, "visible" flag, "editable" flag, XML tag | |
| 241 | * name, XML tag's parent tag "path" (relative to vCard node). | |
| 242 | * | |
| 243 | * List is terminated by a NULL label pointer. | |
| 244 | * | |
| 245 | * Entries with no label text, but with XML tag and parent tag | |
| 246 | * entries, are used by V-Card XML construction routines to | |
| 247 | * "automagically" construct the appropriate XML node tree. | |
| 248 | * | |
| 249 | * Thoughts on future direction/expansion | |
| 250 | * | |
| 251 | * This is a "simple" vCard. | |
| 252 | * | |
| 253 | * It is possible for nodes other than the "vCard" node to have | |
| 254 | * attributes. Should that prove necessary/desirable, add an | |
| 255 | * "attributes" pointer to the vcard_template struct, create the | |
| 256 | * necessary tag_attr structs, and add 'em to the vcard_dflt_data | |
| 257 | * array. | |
| 258 | * | |
| 259 | * The above changes will (obviously) require changes to the vCard | |
| 260 | * construction routines. | |
| 261 | */ | |
| 262 | ||
| 263 | struct vcard_template { | |
| 264 | char *label; /* label text pointer */ | |
| 265 | char *text; /* entry text pointer */ | |
| 266 | int visible; /* should entry field be "visible?" */ | |
| 267 | int editable; /* should entry field be editable? */ | |
| 268 | char *tag; /* tag text */ | |
| 269 | char *ptag; /* parent tag "path" text */ | |
| 270 | char *url; /* vCard display format if URL */ | |
| 271 | } vcard_template_data[] = { | |
| 272 | {N_("Full Name"), NULL, TRUE, TRUE, "FN", NULL, NULL}, | |
| 273 | {N_("Family Name"), NULL, TRUE, TRUE, "FAMILY", "N", NULL}, | |
| 274 | {N_("Given Name"), NULL, TRUE, TRUE, "GIVEN", "N", NULL}, | |
| 275 | {N_("Nickname"), NULL, TRUE, TRUE, "NICKNAME", NULL, NULL}, | |
| 276 | {N_("URL"), NULL, TRUE, TRUE, "URL", NULL, "<A HREF=\"%s\">%s</A>"}, | |
| 277 | {N_("Street Address"), NULL, TRUE, TRUE, "STREET", "ADR", NULL}, | |
| 278 | {N_("Extended Address"), NULL, TRUE, TRUE, "EXTADD", "ADR", NULL}, | |
| 279 | {N_("Locality"), NULL, TRUE, TRUE, "LOCALITY", "ADR", NULL}, | |
| 280 | {N_("Region"), NULL, TRUE, TRUE, "REGION", "ADR", NULL}, | |
| 281 | {N_("Postal Code"), NULL, TRUE, TRUE, "PCODE", "ADR", NULL}, | |
| 13332 | 282 | {N_("Country"), NULL, TRUE, TRUE, "CTRY", "ADR", NULL}, |
| 11361 | 283 | {N_("Telephone"), NULL, TRUE, TRUE, "NUMBER", "TEL", NULL}, |
|
13546
0700f0c29e14
[gaim-migrate @ 15922]
Richard Laager <rlaager@pidgin.im>
parents:
13345
diff
changeset
|
284 | {N_("E-Mail"), NULL, TRUE, TRUE, "USERID", "EMAIL", "<A HREF=\"mailto:%s\">%s</A>"}, |
| 7014 | 285 | {N_("Organization Name"), NULL, TRUE, TRUE, "ORGNAME", "ORG", NULL}, |
| 286 | {N_("Organization Unit"), NULL, TRUE, TRUE, "ORGUNIT", "ORG", NULL}, | |
| 287 | {N_("Title"), NULL, TRUE, TRUE, "TITLE", NULL, NULL}, | |
| 288 | {N_("Role"), NULL, TRUE, TRUE, "ROLE", NULL, NULL}, | |
| 289 | {N_("Birthday"), NULL, TRUE, TRUE, "BDAY", NULL, NULL}, | |
| 290 | {N_("Description"), NULL, TRUE, TRUE, "DESC", NULL, NULL}, | |
| 291 | {"", NULL, TRUE, TRUE, "N", NULL, NULL}, | |
| 292 | {"", NULL, TRUE, TRUE, "ADR", NULL, NULL}, | |
| 293 | {"", NULL, TRUE, TRUE, "ORG", NULL, NULL}, | |
| 294 | {NULL, NULL, 0, 0, NULL, NULL, NULL} | |
| 295 | }; | |
| 296 | ||
| 297 | /* | |
|
8735
01248ea222d3
[gaim-migrate @ 9490]
Jonathan Champ <royanee@users.sourceforge.net>
parents:
8401
diff
changeset
|
298 | * The "vCard" tag's attribute list... |
| 7014 | 299 | */ |
| 300 | struct tag_attr { | |
| 301 | char *attr; | |
| 302 | char *value; | |
| 303 | } vcard_tag_attr_list[] = { | |
| 304 | {"prodid", "-//HandGen//NONSGML vGen v1.0//EN"}, | |
| 305 | {"version", "2.0", }, | |
| 306 | {"xmlns", "vcard-temp", }, | |
| 307 | {NULL, NULL}, | |
| 308 | }; | |
| 309 | ||
| 310 | ||
| 311 | /* | |
| 312 | * Insert a tag node into an xmlnode tree, recursively inserting parent tag | |
| 313 | * nodes as necessary | |
| 314 | * | |
| 315 | * Returns pointer to inserted node | |
| 316 | * | |
| 317 | * Note to hackers: this code is designed to be re-entrant (it's recursive--it | |
| 318 | * calls itself), so don't put any "static"s in here! | |
| 319 | */ | |
| 320 | static xmlnode *insert_tag_to_parent_tag(xmlnode *start, const char *parent_tag, const char *new_tag) | |
| 321 | { | |
| 322 | xmlnode *x = NULL; | |
| 323 | ||
| 324 | /* | |
| 325 | * If the parent tag wasn't specified, see if we can get it | |
| 326 | * from the vCard template struct. | |
| 327 | */ | |
| 328 | if(parent_tag == NULL) { | |
| 329 | struct vcard_template *vc_tp = vcard_template_data; | |
| 330 | ||
| 331 | while(vc_tp->label != NULL) { | |
| 332 | if(strcmp(vc_tp->tag, new_tag) == 0) { | |
| 333 | parent_tag = vc_tp->ptag; | |
| 334 | break; | |
| 335 | } | |
| 336 | ++vc_tp; | |
| 337 | } | |
| 338 | } | |
| 339 | ||
| 340 | /* | |
| 341 | * If we have a parent tag... | |
| 342 | */ | |
| 343 | if(parent_tag != NULL ) { | |
| 344 | /* | |
| 345 | * Try to get the parent node for a tag | |
| 346 | */ | |
| 347 | if((x = xmlnode_get_child(start, parent_tag)) == NULL) { | |
| 348 | /* | |
| 349 | * Descend? | |
| 350 | */ | |
| 351 | char *grand_parent = g_strdup(parent_tag); | |
| 352 | char *parent; | |
| 353 | ||
| 354 | if((parent = strrchr(grand_parent, '/')) != NULL) { | |
| 355 | *(parent++) = '\0'; | |
| 356 | x = insert_tag_to_parent_tag(start, grand_parent, parent); | |
| 357 | } else { | |
| 358 | x = xmlnode_new_child(start, grand_parent); | |
| 359 | } | |
| 360 | g_free(grand_parent); | |
| 361 | } else { | |
| 362 | /* | |
| 363 | * We found *something* to be the parent node. | |
| 364 | * Note: may be the "root" node! | |
| 365 | */ | |
| 366 | xmlnode *y; | |
| 367 | if((y = xmlnode_get_child(x, new_tag)) != NULL) { | |
| 368 | return(y); | |
| 369 | } | |
| 370 | } | |
| 371 | } | |
| 372 | ||
| 373 | /* | |
| 374 | * insert the new tag into its parent node | |
| 375 | */ | |
| 376 | return(xmlnode_new_child((x == NULL? start : x), new_tag)); | |
| 377 | } | |
| 378 | ||
| 379 | /* | |
| 380 | * Send vCard info to Jabber server | |
| 381 | */ | |
| 15884 | 382 | void jabber_set_info(PurpleConnection *gc, const char *info) |
| 7014 | 383 | { |
| 384 | JabberIq *iq; | |
| 385 | JabberStream *js = gc->proto_data; | |
| 386 | xmlnode *vc_node; | |
|
13693
a20847c5c46d
[gaim-migrate @ 16094]
Chris <cbanal@users.sourceforge.net>
parents:
13641
diff
changeset
|
387 | struct tag_attr *tag_attr; |
| 7014 | 388 | |
|
15273
a7838f939207
[gaim-migrate @ 18001]
Mark Doliner <markdoliner@pidgin.im>
parents:
15205
diff
changeset
|
389 | g_free(js->avatar_hash); |
| 10189 | 390 | js->avatar_hash = NULL; |
| 7014 | 391 | |
| 392 | /* | |
| 393 | * Send only if there's actually any *information* to send | |
| 394 | */ | |
| 11388 | 395 | vc_node = info ? xmlnode_from_str(info, -1) : NULL; |
| 10189 | 396 | |
|
15273
a7838f939207
[gaim-migrate @ 18001]
Mark Doliner <markdoliner@pidgin.im>
parents:
15205
diff
changeset
|
397 | if(!vc_node) { |
| 10189 | 398 | vc_node = xmlnode_new("vCard"); |
|
13693
a20847c5c46d
[gaim-migrate @ 16094]
Chris <cbanal@users.sourceforge.net>
parents:
13641
diff
changeset
|
399 | for(tag_attr = vcard_tag_attr_list; tag_attr->attr != NULL; ++tag_attr) |
|
a20847c5c46d
[gaim-migrate @ 16094]
Chris <cbanal@users.sourceforge.net>
parents:
13641
diff
changeset
|
400 | xmlnode_set_attrib(vc_node, tag_attr->attr, tag_attr->value); |
| 10189 | 401 | } |
| 7014 | 402 | |
|
15273
a7838f939207
[gaim-migrate @ 18001]
Mark Doliner <markdoliner@pidgin.im>
parents:
15205
diff
changeset
|
403 | if (vc_node->name && |
|
a7838f939207
[gaim-migrate @ 18001]
Mark Doliner <markdoliner@pidgin.im>
parents:
15205
diff
changeset
|
404 | !g_ascii_strncasecmp(vc_node->name, "vCard", 5)) { |
|
16538
c7e61e2917c9
Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents:
16534
diff
changeset
|
405 | PurpleStoredImage *img; |
| 10189 | 406 | |
|
16538
c7e61e2917c9
Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents:
16534
diff
changeset
|
407 | if ((img = purple_buddy_icons_find_account_icon(gc->account))) { |
|
c7e61e2917c9
Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents:
16534
diff
changeset
|
408 | gconstpointer avatar_data; |
|
c7e61e2917c9
Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents:
16534
diff
changeset
|
409 | gsize avatar_len; |
|
17787
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
410 | xmlnode *photo, *binval, *type; |
|
15273
a7838f939207
[gaim-migrate @ 18001]
Mark Doliner <markdoliner@pidgin.im>
parents:
15205
diff
changeset
|
411 | gchar *enc; |
|
a7838f939207
[gaim-migrate @ 18001]
Mark Doliner <markdoliner@pidgin.im>
parents:
15205
diff
changeset
|
412 | int i; |
|
a7838f939207
[gaim-migrate @ 18001]
Mark Doliner <markdoliner@pidgin.im>
parents:
15205
diff
changeset
|
413 | unsigned char hashval[20]; |
|
a7838f939207
[gaim-migrate @ 18001]
Mark Doliner <markdoliner@pidgin.im>
parents:
15205
diff
changeset
|
414 | char *p, hash[41]; |
| 10189 | 415 | |
|
16538
c7e61e2917c9
Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents:
16534
diff
changeset
|
416 | avatar_data = purple_imgstore_get_data(img); |
|
c7e61e2917c9
Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents:
16534
diff
changeset
|
417 | avatar_len = purple_imgstore_get_size(img); |
|
15273
a7838f939207
[gaim-migrate @ 18001]
Mark Doliner <markdoliner@pidgin.im>
parents:
15205
diff
changeset
|
418 | photo = xmlnode_new_child(vc_node, "PHOTO"); |
|
17787
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
419 | type = xmlnode_new_child(photo, "TYPE"); |
|
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
420 | xmlnode_insert_data(type, "image/png", -1); |
|
15273
a7838f939207
[gaim-migrate @ 18001]
Mark Doliner <markdoliner@pidgin.im>
parents:
15205
diff
changeset
|
421 | binval = xmlnode_new_child(photo, "BINVAL"); |
| 15884 | 422 | enc = purple_base64_encode(avatar_data, avatar_len); |
|
10684
0325b164a7eb
[gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
10662
diff
changeset
|
423 | |
|
16538
c7e61e2917c9
Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents:
16534
diff
changeset
|
424 | purple_cipher_digest_region("sha1", avatar_data, |
|
15273
a7838f939207
[gaim-migrate @ 18001]
Mark Doliner <markdoliner@pidgin.im>
parents:
15205
diff
changeset
|
425 | avatar_len, sizeof(hashval), |
|
a7838f939207
[gaim-migrate @ 18001]
Mark Doliner <markdoliner@pidgin.im>
parents:
15205
diff
changeset
|
426 | hashval, NULL); |
|
10684
0325b164a7eb
[gaim-migrate @ 12231]
Luke Schierer <lschiere@pidgin.im>
parents:
10662
diff
changeset
|
427 | |
|
16538
c7e61e2917c9
Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents:
16534
diff
changeset
|
428 | purple_imgstore_unref(img); |
|
c7e61e2917c9
Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents:
16534
diff
changeset
|
429 | |
|
15273
a7838f939207
[gaim-migrate @ 18001]
Mark Doliner <markdoliner@pidgin.im>
parents:
15205
diff
changeset
|
430 | p = hash; |
|
a7838f939207
[gaim-migrate @ 18001]
Mark Doliner <markdoliner@pidgin.im>
parents:
15205
diff
changeset
|
431 | for(i=0; i<20; i++, p+=2) |
|
a7838f939207
[gaim-migrate @ 18001]
Mark Doliner <markdoliner@pidgin.im>
parents:
15205
diff
changeset
|
432 | snprintf(p, 3, "%02x", hashval[i]); |
|
a7838f939207
[gaim-migrate @ 18001]
Mark Doliner <markdoliner@pidgin.im>
parents:
15205
diff
changeset
|
433 | js->avatar_hash = g_strdup(hash); |
| 10189 | 434 | |
|
15273
a7838f939207
[gaim-migrate @ 18001]
Mark Doliner <markdoliner@pidgin.im>
parents:
15205
diff
changeset
|
435 | xmlnode_insert_data(binval, enc, -1); |
|
a7838f939207
[gaim-migrate @ 18001]
Mark Doliner <markdoliner@pidgin.im>
parents:
15205
diff
changeset
|
436 | g_free(enc); |
|
a7838f939207
[gaim-migrate @ 18001]
Mark Doliner <markdoliner@pidgin.im>
parents:
15205
diff
changeset
|
437 | } |
| 10189 | 438 | |
|
15273
a7838f939207
[gaim-migrate @ 18001]
Mark Doliner <markdoliner@pidgin.im>
parents:
15205
diff
changeset
|
439 | iq = jabber_iq_new(js, JABBER_IQ_SET); |
|
a7838f939207
[gaim-migrate @ 18001]
Mark Doliner <markdoliner@pidgin.im>
parents:
15205
diff
changeset
|
440 | xmlnode_insert_child(iq->node, vc_node); |
|
a7838f939207
[gaim-migrate @ 18001]
Mark Doliner <markdoliner@pidgin.im>
parents:
15205
diff
changeset
|
441 | jabber_iq_send(iq); |
|
a7838f939207
[gaim-migrate @ 18001]
Mark Doliner <markdoliner@pidgin.im>
parents:
15205
diff
changeset
|
442 | } else { |
|
a7838f939207
[gaim-migrate @ 18001]
Mark Doliner <markdoliner@pidgin.im>
parents:
15205
diff
changeset
|
443 | xmlnode_free(vc_node); |
| 7014 | 444 | } |
| 445 | } | |
| 446 | ||
|
16538
c7e61e2917c9
Updates for the account buddy icon stuff. This doesn't yet work fully (and maybe not even partly), but it compiles.
Richard Laager <rlaager@pidgin.im>
parents:
16534
diff
changeset
|
447 | void jabber_set_buddy_icon(PurpleConnection *gc, PurpleStoredImage *img) |
| 10189 | 448 | { |
| 15884 | 449 | PurplePresence *gpresence; |
| 450 | PurpleStatus *status; | |
|
17787
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
451 | |
|
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
452 | if(((JabberStream*)gc->proto_data)->pep) { |
|
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
453 | /* XEP-0084: User Avatars */ |
|
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
454 | if(img) { |
|
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
455 | /* A PNG header, including the IHDR, but nothing else */ |
|
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
456 | const struct { |
|
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
457 | guchar signature[8]; /* must be hex 89 50 4E 47 0D 0A 1A 0A */ |
|
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
458 | struct { |
|
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
459 | guint32 length; /* must be 0x0d */ |
|
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
460 | guchar type[4]; /* must be 'I' 'H' 'D' 'R' */ |
|
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
461 | guint32 width; |
|
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
462 | guint32 height; |
|
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
463 | guchar bitdepth; |
|
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
464 | guchar colortype; |
|
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
465 | guchar compression; |
|
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
466 | guchar filter; |
|
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
467 | guchar interlace; |
|
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
468 | } ihdr; |
|
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
469 | } *png = purple_imgstore_get_data(img); /* ATTN: this is in network byte order! */ |
| 10189 | 470 | |
|
17787
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
471 | /* check if the data is a valid png file (well, at least to some extend) */ |
|
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
472 | if(png->signature[0] == 0x89 && |
|
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
473 | png->signature[1] == 0x50 && |
|
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
474 | png->signature[2] == 0x4e && |
|
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
475 | png->signature[3] == 0x47 && |
|
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
476 | png->signature[4] == 0x0d && |
|
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
477 | png->signature[5] == 0x0a && |
|
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
478 | png->signature[6] == 0x1a && |
|
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
479 | png->signature[7] == 0x0a && |
|
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
480 | ntohl(png->ihdr.length) == 0x0d && |
|
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
481 | png->ihdr.type[0] == 'I' && |
|
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
482 | png->ihdr.type[1] == 'H' && |
|
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
483 | png->ihdr.type[2] == 'D' && |
|
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
484 | png->ihdr.type[3] == 'R') { |
|
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
485 | /* parse PNG header to get the size of the image (yes, this is required) */ |
|
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
486 | guint32 width = ntohl(png->ihdr.width); |
|
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
487 | guint32 height = ntohl(png->ihdr.height); |
|
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
488 | xmlnode *publish, *item, *data, *metadata, *info; |
|
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
489 | char *lengthstring, *widthstring, *heightstring; |
|
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
490 | |
|
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
491 | /* compute the sha1 hash */ |
|
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
492 | PurpleCipherContext *ctx; |
|
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
493 | unsigned char digest[20]; |
|
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
494 | char *hash; |
|
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
495 | char *base64avatar; |
|
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
496 | |
|
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
497 | ctx = purple_cipher_context_new_by_name("sha1", NULL); |
|
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
498 | purple_cipher_context_append(ctx, purple_imgstore_get_data(img), purple_imgstore_get_size(img)); |
|
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
499 | purple_cipher_context_digest(ctx, sizeof(digest), digest, NULL); |
|
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
500 | |
|
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
501 | /* convert digest to a string */ |
|
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
502 | hash = g_strdup_printf("%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x",digest[0],digest[1],digest[2],digest[3],digest[4],digest[5],digest[6],digest[7],digest[8],digest[9],digest[10],digest[11],digest[12],digest[13],digest[14],digest[15],digest[16],digest[17],digest[18],digest[19]); |
|
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
503 | |
|
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
504 | publish = xmlnode_new("publish"); |
|
17788
e6e381b0c7d6
Implemented receiving other people's avatars via XEP-0084. Note that this code now includes a workaround for a non-spec incompatibility for the current ejabberd PEP implementation, and doesn't use the correct namespace due to Psi using the wrong one (outdated?). Works fine though, and the vcard-based approach is retained.
Andreas Monitzer <am@adiumx.com>
parents:
17787
diff
changeset
|
505 | xmlnode_set_attrib(publish,"node",AVATARNAMESPACEDATA); |
|
17787
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
506 | |
|
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
507 | item = xmlnode_new_child(publish, "item"); |
|
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
508 | xmlnode_set_attrib(item, "id", hash); |
|
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
509 | |
|
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
510 | data = xmlnode_new_child(item, "data"); |
|
17788
e6e381b0c7d6
Implemented receiving other people's avatars via XEP-0084. Note that this code now includes a workaround for a non-spec incompatibility for the current ejabberd PEP implementation, and doesn't use the correct namespace due to Psi using the wrong one (outdated?). Works fine though, and the vcard-based approach is retained.
Andreas Monitzer <am@adiumx.com>
parents:
17787
diff
changeset
|
511 | xmlnode_set_namespace(data,AVATARNAMESPACEDATA); |
|
17787
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
512 | |
|
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
513 | base64avatar = purple_base64_encode(purple_imgstore_get_data(img), purple_imgstore_get_size(img)); |
|
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
514 | xmlnode_insert_data(data,base64avatar,-1); |
|
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
515 | g_free(base64avatar); |
|
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
516 | |
|
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
517 | /* publish the avatar itself */ |
|
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
518 | jabber_pep_publish((JabberStream*)gc->proto_data, publish); |
|
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
519 | |
|
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
520 | /* next step: publish the metadata */ |
|
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
521 | publish = xmlnode_new("publish"); |
|
17788
e6e381b0c7d6
Implemented receiving other people's avatars via XEP-0084. Note that this code now includes a workaround for a non-spec incompatibility for the current ejabberd PEP implementation, and doesn't use the correct namespace due to Psi using the wrong one (outdated?). Works fine though, and the vcard-based approach is retained.
Andreas Monitzer <am@adiumx.com>
parents:
17787
diff
changeset
|
522 | xmlnode_set_attrib(publish,"node",AVATARNAMESPACEMETA); |
|
17787
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
523 | |
|
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
524 | item = xmlnode_new_child(publish, "item"); |
|
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
525 | xmlnode_set_attrib(item, "id", hash); |
|
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
526 | |
|
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
527 | metadata = xmlnode_new_child(item, "metadata"); |
|
17788
e6e381b0c7d6
Implemented receiving other people's avatars via XEP-0084. Note that this code now includes a workaround for a non-spec incompatibility for the current ejabberd PEP implementation, and doesn't use the correct namespace due to Psi using the wrong one (outdated?). Works fine though, and the vcard-based approach is retained.
Andreas Monitzer <am@adiumx.com>
parents:
17787
diff
changeset
|
528 | xmlnode_set_namespace(metadata,AVATARNAMESPACEMETA); |
|
17787
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
529 | |
|
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
530 | info = xmlnode_new_child(metadata, "info"); |
|
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
531 | xmlnode_set_attrib(info, "id", hash); |
|
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
532 | xmlnode_set_attrib(info, "type", "image/png"); |
|
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
533 | lengthstring = g_strdup_printf("%u", (unsigned)purple_imgstore_get_size(img)); |
|
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
534 | xmlnode_set_attrib(info, "bytes", lengthstring); |
|
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
535 | g_free(lengthstring); |
|
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
536 | widthstring = g_strdup_printf("%u", width); |
|
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
537 | xmlnode_set_attrib(info, "width", widthstring); |
|
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
538 | g_free(widthstring); |
|
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
539 | heightstring = g_strdup_printf("%u", height); |
|
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
540 | xmlnode_set_attrib(info, "height", heightstring); |
|
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
541 | g_free(lengthstring); |
|
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
542 | |
|
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
543 | /* publish the metadata */ |
|
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
544 | jabber_pep_publish((JabberStream*)gc->proto_data, publish); |
|
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
545 | |
|
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
546 | g_free(hash); |
|
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
547 | } else { /* if(img) */ |
|
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
548 | /* remove the metadata */ |
|
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
549 | xmlnode *metadata, *item; |
|
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
550 | xmlnode *publish = xmlnode_new("publish"); |
|
17788
e6e381b0c7d6
Implemented receiving other people's avatars via XEP-0084. Note that this code now includes a workaround for a non-spec incompatibility for the current ejabberd PEP implementation, and doesn't use the correct namespace due to Psi using the wrong one (outdated?). Works fine though, and the vcard-based approach is retained.
Andreas Monitzer <am@adiumx.com>
parents:
17787
diff
changeset
|
551 | xmlnode_set_attrib(publish,"node",AVATARNAMESPACEMETA); |
|
17787
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
552 | |
|
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
553 | item = xmlnode_new_child(publish, "item"); |
|
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
554 | |
|
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
555 | metadata = xmlnode_new_child(item, "metadata"); |
|
17788
e6e381b0c7d6
Implemented receiving other people's avatars via XEP-0084. Note that this code now includes a workaround for a non-spec incompatibility for the current ejabberd PEP implementation, and doesn't use the correct namespace due to Psi using the wrong one (outdated?). Works fine though, and the vcard-based approach is retained.
Andreas Monitzer <am@adiumx.com>
parents:
17787
diff
changeset
|
556 | xmlnode_set_namespace(metadata,AVATARNAMESPACEMETA); |
|
17787
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
557 | |
|
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
558 | xmlnode_new_child(metadata, "stop"); |
|
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
559 | |
|
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
560 | /* publish the metadata */ |
|
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
561 | jabber_pep_publish((JabberStream*)gc->proto_data, publish); |
|
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
562 | } |
|
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
563 | } else { |
|
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
564 | purple_debug(PURPLE_DEBUG_ERROR, "jabber", |
|
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
565 | "jabber_set_buddy_icon received non-png data"); |
|
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
566 | } |
|
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
567 | } |
|
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
568 | |
|
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
569 | /* even when the image is not png, we can still publish the vCard, since this |
|
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
570 | one doesn't require a specific image type */ |
|
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
571 | |
|
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
572 | /* publish vCard for those poor older clients */ |
| 15884 | 573 | jabber_set_info(gc, purple_account_get_user_info(gc->account)); |
| 10189 | 574 | |
| 15884 | 575 | gpresence = purple_account_get_presence(gc->account); |
| 576 | status = purple_presence_get_active_status(gpresence); | |
| 10216 | 577 | jabber_presence_send(gc->account, status); |
| 10189 | 578 | } |
| 579 | ||
| 7014 | 580 | /* |
| 581 | * This is the callback from the "ok clicked" for "set vCard" | |
| 582 | * | |
| 583 | * Formats GSList data into XML-encoded string and returns a pointer | |
| 584 | * to said string. | |
| 585 | * | |
| 586 | * g_free()'ing the returned string space is the responsibility of | |
| 587 | * the caller. | |
| 588 | */ | |
| 589 | static void | |
| 15884 | 590 | jabber_format_info(PurpleConnection *gc, PurpleRequestFields *fields) |
| 7014 | 591 | { |
| 592 | xmlnode *vc_node; | |
| 15884 | 593 | PurpleRequestField *field; |
| 7014 | 594 | const char *text; |
| 595 | char *p; | |
| 596 | const struct vcard_template *vc_tp; | |
| 597 | struct tag_attr *tag_attr; | |
| 598 | ||
| 599 | vc_node = xmlnode_new("vCard"); | |
| 600 | ||
| 601 | for(tag_attr = vcard_tag_attr_list; tag_attr->attr != NULL; ++tag_attr) | |
| 602 | xmlnode_set_attrib(vc_node, tag_attr->attr, tag_attr->value); | |
| 603 | ||
| 604 | for (vc_tp = vcard_template_data; vc_tp->label != NULL; vc_tp++) { | |
| 605 | if (*vc_tp->label == '\0') | |
| 606 | continue; | |
| 607 | ||
| 15884 | 608 | field = purple_request_fields_get_field(fields, vc_tp->tag); |
| 609 | text = purple_request_field_string_get_value(field); | |
| 7014 | 610 | |
| 611 | ||
| 612 | if (text != NULL && *text != '\0') { | |
| 613 | xmlnode *xp; | |
| 614 | ||
| 15884 | 615 | purple_debug(PURPLE_DEBUG_INFO, "jabber", |
| 9339 | 616 | "Setting %s to '%s'\n", vc_tp->tag, text); |
| 617 | ||
| 7014 | 618 | if ((xp = insert_tag_to_parent_tag(vc_node, |
| 619 | NULL, vc_tp->tag)) != NULL) { | |
| 620 | ||
| 621 | xmlnode_insert_data(xp, text, -1); | |
| 622 | } | |
| 623 | } | |
| 624 | } | |
| 625 | ||
| 7642 | 626 | p = xmlnode_to_str(vc_node, NULL); |
| 7014 | 627 | xmlnode_free(vc_node); |
| 628 | ||
| 15884 | 629 | purple_account_set_user_info(purple_connection_get_account(gc), p); |
|
14669
df3f48ab4aff
[gaim-migrate @ 17335]
Mark Doliner <markdoliner@pidgin.im>
parents:
14525
diff
changeset
|
630 | serv_set_info(gc, p); |
| 7014 | 631 | |
| 632 | g_free(p); | |
| 633 | } | |
| 634 | ||
| 635 | /* | |
| 636 | * This gets executed by the proto action | |
| 637 | * | |
| 15884 | 638 | * Creates a new PurpleRequestFields struct, gets the XML-formatted user_info |
| 7014 | 639 | * string (if any) into GSLists for the (multi-entry) edit dialog and |
| 640 | * calls the set_vcard dialog. | |
| 641 | */ | |
| 15884 | 642 | void jabber_setup_set_info(PurplePluginAction *action) |
| 7014 | 643 | { |
| 15884 | 644 | PurpleConnection *gc = (PurpleConnection *) action->context; |
| 645 | PurpleRequestFields *fields; | |
| 646 | PurpleRequestFieldGroup *group; | |
| 647 | PurpleRequestField *field; | |
| 7014 | 648 | const struct vcard_template *vc_tp; |
|
14129
70db31dfeeb1
[gaim-migrate @ 16688]
Daniel Atallah <datallah@pidgin.im>
parents:
13808
diff
changeset
|
649 | const char *user_info; |
|
14130
02a5f8dad9cf
[gaim-migrate @ 16689]
Daniel Atallah <datallah@pidgin.im>
parents:
14129
diff
changeset
|
650 | char *cdata = NULL; |
| 7014 | 651 | xmlnode *x_vc_data = NULL; |
| 652 | ||
| 15884 | 653 | fields = purple_request_fields_new(); |
| 654 | group = purple_request_field_group_new(NULL); | |
| 655 | purple_request_fields_add_group(fields, group); | |
| 7014 | 656 | |
| 657 | /* | |
| 658 | * Get existing, XML-formatted, user info | |
| 659 | */ | |
| 15884 | 660 | if((user_info = purple_account_get_user_info(gc->account)) != NULL) |
| 7014 | 661 | x_vc_data = xmlnode_from_str(user_info, -1); |
| 662 | ||
| 663 | /* | |
| 664 | * Set up GSLists for edit with labels from "template," data from user info | |
| 665 | */ | |
| 666 | for(vc_tp = vcard_template_data; vc_tp->label != NULL; ++vc_tp) { | |
| 667 | xmlnode *data_node; | |
| 668 | if((vc_tp->label)[0] == '\0') | |
| 669 | continue; | |
|
14129
70db31dfeeb1
[gaim-migrate @ 16688]
Daniel Atallah <datallah@pidgin.im>
parents:
13808
diff
changeset
|
670 | |
|
70db31dfeeb1
[gaim-migrate @ 16688]
Daniel Atallah <datallah@pidgin.im>
parents:
13808
diff
changeset
|
671 | if (x_vc_data != NULL) { |
|
70db31dfeeb1
[gaim-migrate @ 16688]
Daniel Atallah <datallah@pidgin.im>
parents:
13808
diff
changeset
|
672 | if(vc_tp->ptag == NULL) { |
|
70db31dfeeb1
[gaim-migrate @ 16688]
Daniel Atallah <datallah@pidgin.im>
parents:
13808
diff
changeset
|
673 | data_node = xmlnode_get_child(x_vc_data, vc_tp->tag); |
|
70db31dfeeb1
[gaim-migrate @ 16688]
Daniel Atallah <datallah@pidgin.im>
parents:
13808
diff
changeset
|
674 | } else { |
|
70db31dfeeb1
[gaim-migrate @ 16688]
Daniel Atallah <datallah@pidgin.im>
parents:
13808
diff
changeset
|
675 | gchar *tag = g_strdup_printf("%s/%s", vc_tp->ptag, vc_tp->tag); |
|
70db31dfeeb1
[gaim-migrate @ 16688]
Daniel Atallah <datallah@pidgin.im>
parents:
13808
diff
changeset
|
676 | data_node = xmlnode_get_child(x_vc_data, tag); |
|
70db31dfeeb1
[gaim-migrate @ 16688]
Daniel Atallah <datallah@pidgin.im>
parents:
13808
diff
changeset
|
677 | g_free(tag); |
|
70db31dfeeb1
[gaim-migrate @ 16688]
Daniel Atallah <datallah@pidgin.im>
parents:
13808
diff
changeset
|
678 | } |
|
70db31dfeeb1
[gaim-migrate @ 16688]
Daniel Atallah <datallah@pidgin.im>
parents:
13808
diff
changeset
|
679 | if(data_node) |
|
70db31dfeeb1
[gaim-migrate @ 16688]
Daniel Atallah <datallah@pidgin.im>
parents:
13808
diff
changeset
|
680 | cdata = xmlnode_get_data(data_node); |
|
14130
02a5f8dad9cf
[gaim-migrate @ 16689]
Daniel Atallah <datallah@pidgin.im>
parents:
14129
diff
changeset
|
681 | } |
| 7014 | 682 | |
| 683 | if(strcmp(vc_tp->tag, "DESC") == 0) { | |
| 15884 | 684 | field = purple_request_field_string_new(vc_tp->tag, |
| 7014 | 685 | _(vc_tp->label), cdata, |
| 686 | TRUE); | |
| 687 | } else { | |
| 15884 | 688 | field = purple_request_field_string_new(vc_tp->tag, |
| 7014 | 689 | _(vc_tp->label), cdata, |
| 690 | FALSE); | |
| 691 | } | |
| 692 | ||
|
14130
02a5f8dad9cf
[gaim-migrate @ 16689]
Daniel Atallah <datallah@pidgin.im>
parents:
14129
diff
changeset
|
693 | g_free(cdata); |
|
02a5f8dad9cf
[gaim-migrate @ 16689]
Daniel Atallah <datallah@pidgin.im>
parents:
14129
diff
changeset
|
694 | cdata = NULL; |
|
02a5f8dad9cf
[gaim-migrate @ 16689]
Daniel Atallah <datallah@pidgin.im>
parents:
14129
diff
changeset
|
695 | |
| 15884 | 696 | purple_request_field_group_add_field(group, field); |
| 7014 | 697 | } |
| 698 | ||
| 699 | if(x_vc_data != NULL) | |
| 700 | xmlnode_free(x_vc_data); | |
| 701 | ||
|
16961
b6955f946f8f
s/Jabber/XMPP in user-visible places.
Richard Laager <rlaager@pidgin.im>
parents:
16799
diff
changeset
|
702 | purple_request_fields(gc, _("Edit XMPP vCard"), |
|
b6955f946f8f
s/Jabber/XMPP in user-visible places.
Richard Laager <rlaager@pidgin.im>
parents:
16799
diff
changeset
|
703 | _("Edit XMPP vCard"), |
| 7014 | 704 | _("All items below are optional. Enter only the " |
| 705 | "information with which you feel comfortable."), | |
| 706 | fields, | |
| 707 | _("Save"), G_CALLBACK(jabber_format_info), | |
| 708 | _("Cancel"), NULL, | |
|
16490
68c22924d66b
Added account, who, and conversation parameters to the request API calls, and updated all code to match. I can't compile the Perl module, so I'd appreciate it if someone who knows it would verify that this doesn't break Perl.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
709 | purple_connection_get_account(gc), NULL, NULL, |
| 7014 | 710 | gc); |
| 711 | } | |
| 712 | ||
| 713 | /*---------------------------------------*/ | |
| 714 | /* End Jabber "set info" (vCard) support */ | |
| 715 | /*---------------------------------------*/ | |
| 716 | ||
| 717 | /****** | |
| 718 | * end of that ancient crap that needs to die | |
| 719 | ******/ | |
| 720 | ||
|
15363
f6b9d1e3d0cb
[gaim-migrate @ 18092]
Evan Schoenberg <evands@pidgin.im>
parents:
15273
diff
changeset
|
721 | static void jabber_buddy_info_destroy(JabberBuddyInfo *jbi) |
|
f6b9d1e3d0cb
[gaim-migrate @ 18092]
Evan Schoenberg <evands@pidgin.im>
parents:
15273
diff
changeset
|
722 | { |
|
f6b9d1e3d0cb
[gaim-migrate @ 18092]
Evan Schoenberg <evands@pidgin.im>
parents:
15273
diff
changeset
|
723 | /* Remove the timeout, which would otherwise trigger jabber_buddy_get_info_timeout() */ |
|
f6b9d1e3d0cb
[gaim-migrate @ 18092]
Evan Schoenberg <evands@pidgin.im>
parents:
15273
diff
changeset
|
724 | if (jbi->timeout_handle > 0) |
| 15884 | 725 | purple_timeout_remove(jbi->timeout_handle); |
|
15727
0754583ceeae
Don't access the list element after it has been freed.
Daniel Atallah <datallah@pidgin.im>
parents:
15688
diff
changeset
|
726 | |
|
15363
f6b9d1e3d0cb
[gaim-migrate @ 18092]
Evan Schoenberg <evands@pidgin.im>
parents:
15273
diff
changeset
|
727 | g_free(jbi->jid); |
|
f6b9d1e3d0cb
[gaim-migrate @ 18092]
Evan Schoenberg <evands@pidgin.im>
parents:
15273
diff
changeset
|
728 | g_hash_table_destroy(jbi->resources); |
|
f6b9d1e3d0cb
[gaim-migrate @ 18092]
Evan Schoenberg <evands@pidgin.im>
parents:
15273
diff
changeset
|
729 | g_free(jbi->vcard_text); |
|
15727
0754583ceeae
Don't access the list element after it has been freed.
Daniel Atallah <datallah@pidgin.im>
parents:
15688
diff
changeset
|
730 | g_free(jbi); |
|
15363
f6b9d1e3d0cb
[gaim-migrate @ 18092]
Evan Schoenberg <evands@pidgin.im>
parents:
15273
diff
changeset
|
731 | } |
|
f6b9d1e3d0cb
[gaim-migrate @ 18092]
Evan Schoenberg <evands@pidgin.im>
parents:
15273
diff
changeset
|
732 | |
| 13794 | 733 | static void jabber_buddy_info_show_if_ready(JabberBuddyInfo *jbi) |
| 7014 | 734 | { |
|
15205
f642029b2f97
[gaim-migrate @ 17929]
Evan Schoenberg <evands@pidgin.im>
parents:
15143
diff
changeset
|
735 | char *resource_name, *tmp; |
| 13794 | 736 | JabberBuddyResource *jbr; |
|
15092
e7c5edee202e
[gaim-migrate @ 17813]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
14669
diff
changeset
|
737 | JabberBuddyInfoResource *jbir = NULL; |
| 13794 | 738 | GList *resources; |
| 15884 | 739 | PurpleNotifyUserInfo *user_info; |
| 7014 | 740 | |
| 13794 | 741 | /* not yet */ |
| 742 | if(jbi->ids) | |
| 11361 | 743 | return; |
| 744 | ||
| 15884 | 745 | user_info = purple_notify_user_info_new(); |
| 13794 | 746 | resource_name = jabber_get_resource(jbi->jid); |
| 7014 | 747 | |
| 748 | if(resource_name) { | |
| 13794 | 749 | jbr = jabber_buddy_find_resource(jbi->jb, resource_name); |
| 750 | jbir = g_hash_table_lookup(jbi->resources, resource_name); | |
| 7014 | 751 | if(jbr) { |
| 7145 | 752 | char *purdy = NULL; |
| 753 | if(jbr->status) | |
| 15884 | 754 | purdy = purple_strdup_withhtml(jbr->status); |
|
15205
f642029b2f97
[gaim-migrate @ 17929]
Evan Schoenberg <evands@pidgin.im>
parents:
15143
diff
changeset
|
755 | tmp = g_strdup_printf("%s%s%s", jabber_buddy_state_get_name(jbr->state), |
|
f642029b2f97
[gaim-migrate @ 17929]
Evan Schoenberg <evands@pidgin.im>
parents:
15143
diff
changeset
|
756 | (purdy ? ": " : ""), |
|
f642029b2f97
[gaim-migrate @ 17929]
Evan Schoenberg <evands@pidgin.im>
parents:
15143
diff
changeset
|
757 | (purdy ? purdy : "")); |
| 15884 | 758 | purple_notify_user_info_add_pair(user_info, _("Status"), tmp); |
|
15205
f642029b2f97
[gaim-migrate @ 17929]
Evan Schoenberg <evands@pidgin.im>
parents:
15143
diff
changeset
|
759 | g_free(tmp); |
|
f642029b2f97
[gaim-migrate @ 17929]
Evan Schoenberg <evands@pidgin.im>
parents:
15143
diff
changeset
|
760 | g_free(purdy); |
| 7014 | 761 | } else { |
| 15884 | 762 | purple_notify_user_info_add_pair(user_info, _("Status"), _("Unknown")); |
| 7014 | 763 | } |
| 13794 | 764 | if(jbir) { |
| 765 | if(jbir->idle_seconds > 0) { | |
| 15884 | 766 | char *idle = purple_str_seconds_to_string(jbir->idle_seconds); |
| 767 | purple_notify_user_info_add_pair(user_info, _("Idle"), idle); | |
|
15688
048953c6b084
Fixed 3 Jabber memory leaks: in jabber_roster_parse(), there's no need to g_strdup() this normalized jid since it's only used immediately, and there was no correspoding g_free(). When removing an id from jbi->ids, its data should always be freed. Finally, gaim_str_seconds_to_string() returns retained memory -- we must free the returned pointer when we're done using it.
Evan Schoenberg <evands@pidgin.im>
parents:
15435
diff
changeset
|
768 | g_free(idle); |
| 13794 | 769 | } |
| 770 | } | |
| 771 | if(jbr && jbr->client.name) { | |
|
15205
f642029b2f97
[gaim-migrate @ 17929]
Evan Schoenberg <evands@pidgin.im>
parents:
15143
diff
changeset
|
772 | tmp = g_strdup_printf("%s%s%s", jbr->client.name, |
|
f642029b2f97
[gaim-migrate @ 17929]
Evan Schoenberg <evands@pidgin.im>
parents:
15143
diff
changeset
|
773 | (jbr->client.version ? " " : ""), |
|
f642029b2f97
[gaim-migrate @ 17929]
Evan Schoenberg <evands@pidgin.im>
parents:
15143
diff
changeset
|
774 | (jbr->client.version ? jbr->client.version : "")); |
| 15884 | 775 | purple_notify_user_info_add_pair(user_info, _("Client"), tmp); |
|
15205
f642029b2f97
[gaim-migrate @ 17929]
Evan Schoenberg <evands@pidgin.im>
parents:
15143
diff
changeset
|
776 | g_free(tmp); |
|
f642029b2f97
[gaim-migrate @ 17929]
Evan Schoenberg <evands@pidgin.im>
parents:
15143
diff
changeset
|
777 | |
| 13794 | 778 | if(jbr->client.os) { |
| 15884 | 779 | purple_notify_user_info_add_pair(user_info, _("Operating System"), jbr->client.os); |
| 13794 | 780 | } |
| 781 | } | |
| 7014 | 782 | } else { |
| 13794 | 783 | for(resources = jbi->jb->resources; resources; resources = resources->next) { |
| 7145 | 784 | char *purdy = NULL; |
| 7014 | 785 | jbr = resources->data; |
| 7145 | 786 | if(jbr->status) |
| 15884 | 787 | purdy = purple_strdup_withhtml(jbr->status); |
|
15092
e7c5edee202e
[gaim-migrate @ 17813]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
14669
diff
changeset
|
788 | if(jbr->name) |
| 15884 | 789 | purple_notify_user_info_add_pair(user_info, _("Resource"), jbr->name); |
|
15205
f642029b2f97
[gaim-migrate @ 17929]
Evan Schoenberg <evands@pidgin.im>
parents:
15143
diff
changeset
|
790 | tmp = g_strdup_printf("%d", jbr->priority); |
| 15884 | 791 | purple_notify_user_info_add_pair(user_info, _("Priority"), tmp); |
|
15205
f642029b2f97
[gaim-migrate @ 17929]
Evan Schoenberg <evands@pidgin.im>
parents:
15143
diff
changeset
|
792 | g_free(tmp); |
|
f642029b2f97
[gaim-migrate @ 17929]
Evan Schoenberg <evands@pidgin.im>
parents:
15143
diff
changeset
|
793 | |
|
f642029b2f97
[gaim-migrate @ 17929]
Evan Schoenberg <evands@pidgin.im>
parents:
15143
diff
changeset
|
794 | tmp = g_strdup_printf("%s%s%s", jabber_buddy_state_get_name(jbr->state), |
|
f642029b2f97
[gaim-migrate @ 17929]
Evan Schoenberg <evands@pidgin.im>
parents:
15143
diff
changeset
|
795 | (purdy ? ": " : ""), |
|
f642029b2f97
[gaim-migrate @ 17929]
Evan Schoenberg <evands@pidgin.im>
parents:
15143
diff
changeset
|
796 | (purdy ? purdy : "")); |
| 15884 | 797 | purple_notify_user_info_add_pair(user_info, _("Status"), tmp); |
|
15205
f642029b2f97
[gaim-migrate @ 17929]
Evan Schoenberg <evands@pidgin.im>
parents:
15143
diff
changeset
|
798 | g_free(tmp); |
|
f642029b2f97
[gaim-migrate @ 17929]
Evan Schoenberg <evands@pidgin.im>
parents:
15143
diff
changeset
|
799 | g_free(purdy); |
| 13794 | 800 | |
|
15092
e7c5edee202e
[gaim-migrate @ 17813]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
14669
diff
changeset
|
801 | if(jbr->name) |
|
e7c5edee202e
[gaim-migrate @ 17813]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
14669
diff
changeset
|
802 | jbir = g_hash_table_lookup(jbi->resources, jbr->name); |
|
e7c5edee202e
[gaim-migrate @ 17813]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
14669
diff
changeset
|
803 | |
| 13794 | 804 | if(jbir) { |
| 805 | if(jbir->idle_seconds > 0) { | |
| 15884 | 806 | char *idle = purple_str_seconds_to_string(jbir->idle_seconds); |
| 807 | purple_notify_user_info_add_pair(user_info, _("Idle"), idle); | |
|
15688
048953c6b084
Fixed 3 Jabber memory leaks: in jabber_roster_parse(), there's no need to g_strdup() this normalized jid since it's only used immediately, and there was no correspoding g_free(). When removing an id from jbi->ids, its data should always be freed. Finally, gaim_str_seconds_to_string() returns retained memory -- we must free the returned pointer when we're done using it.
Evan Schoenberg <evands@pidgin.im>
parents:
15435
diff
changeset
|
808 | g_free(idle); |
| 13794 | 809 | } |
| 810 | } | |
|
15205
f642029b2f97
[gaim-migrate @ 17929]
Evan Schoenberg <evands@pidgin.im>
parents:
15143
diff
changeset
|
811 | if(jbr && jbr->client.name) { |
|
f642029b2f97
[gaim-migrate @ 17929]
Evan Schoenberg <evands@pidgin.im>
parents:
15143
diff
changeset
|
812 | tmp = g_strdup_printf("%s%s%s", jbr->client.name, |
|
f642029b2f97
[gaim-migrate @ 17929]
Evan Schoenberg <evands@pidgin.im>
parents:
15143
diff
changeset
|
813 | (jbr->client.version ? " " : ""), |
|
f642029b2f97
[gaim-migrate @ 17929]
Evan Schoenberg <evands@pidgin.im>
parents:
15143
diff
changeset
|
814 | (jbr->client.version ? jbr->client.version : "")); |
| 15884 | 815 | purple_notify_user_info_add_pair(user_info, |
|
15205
f642029b2f97
[gaim-migrate @ 17929]
Evan Schoenberg <evands@pidgin.im>
parents:
15143
diff
changeset
|
816 | _("Client"), tmp); |
|
f642029b2f97
[gaim-migrate @ 17929]
Evan Schoenberg <evands@pidgin.im>
parents:
15143
diff
changeset
|
817 | g_free(tmp); |
|
15727
0754583ceeae
Don't access the list element after it has been freed.
Daniel Atallah <datallah@pidgin.im>
parents:
15688
diff
changeset
|
818 | |
| 13794 | 819 | if(jbr->client.os) { |
| 15884 | 820 | purple_notify_user_info_add_pair(user_info, _("Operating System"), jbr->client.os); |
| 13794 | 821 | } |
| 822 | } | |
| 7014 | 823 | } |
| 824 | } | |
| 825 | ||
| 7306 | 826 | g_free(resource_name); |
| 827 | ||
|
15205
f642029b2f97
[gaim-migrate @ 17929]
Evan Schoenberg <evands@pidgin.im>
parents:
15143
diff
changeset
|
828 | if (jbi->vcard_text != NULL) { |
| 15884 | 829 | purple_notify_user_info_add_section_break(user_info); |
|
15205
f642029b2f97
[gaim-migrate @ 17929]
Evan Schoenberg <evands@pidgin.im>
parents:
15143
diff
changeset
|
830 | /* Should this have some sort of label? */ |
| 15884 | 831 | purple_notify_user_info_add_pair(user_info, NULL, jbi->vcard_text); |
|
15205
f642029b2f97
[gaim-migrate @ 17929]
Evan Schoenberg <evands@pidgin.im>
parents:
15143
diff
changeset
|
832 | } |
| 13794 | 833 | |
| 15884 | 834 | purple_notify_userinfo(jbi->js->gc, jbi->jid, user_info, NULL, NULL); |
| 835 | purple_notify_user_info_destroy(user_info); | |
| 13794 | 836 | |
| 837 | while(jbi->vcard_imgids) { | |
|
16437
7ff7c3405ea2
Rework the buddy icon subsystem to use the imgstore subsystem, and modify the
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
838 | purple_imgstore_unref_by_id(GPOINTER_TO_INT(jbi->vcard_imgids->data)); |
| 13794 | 839 | jbi->vcard_imgids = g_slist_delete_link(jbi->vcard_imgids, jbi->vcard_imgids); |
| 840 | } | |
| 841 | ||
|
15363
f6b9d1e3d0cb
[gaim-migrate @ 18092]
Evan Schoenberg <evands@pidgin.im>
parents:
15273
diff
changeset
|
842 | jbi->js->pending_buddy_info_requests = g_slist_remove(jbi->js->pending_buddy_info_requests, jbi); |
|
14155
c754f6e5be1f
[gaim-migrate @ 16719]
Mark Doliner <markdoliner@pidgin.im>
parents:
14130
diff
changeset
|
843 | |
|
15363
f6b9d1e3d0cb
[gaim-migrate @ 18092]
Evan Schoenberg <evands@pidgin.im>
parents:
15273
diff
changeset
|
844 | jabber_buddy_info_destroy(jbi); |
| 13794 | 845 | } |
| 846 | ||
| 847 | static void jabber_buddy_info_remove_id(JabberBuddyInfo *jbi, const char *id) | |
| 848 | { | |
| 849 | GSList *l = jbi->ids; | |
|
15727
0754583ceeae
Don't access the list element after it has been freed.
Daniel Atallah <datallah@pidgin.im>
parents:
15688
diff
changeset
|
850 | char *comp_id; |
| 13794 | 851 | |
| 852 | if(!id) | |
| 853 | return; | |
| 854 | ||
| 855 | while(l) { | |
|
15727
0754583ceeae
Don't access the list element after it has been freed.
Daniel Atallah <datallah@pidgin.im>
parents:
15688
diff
changeset
|
856 | comp_id = l->data; |
|
0754583ceeae
Don't access the list element after it has been freed.
Daniel Atallah <datallah@pidgin.im>
parents:
15688
diff
changeset
|
857 | if(!strcmp(id, comp_id)) { |
|
0754583ceeae
Don't access the list element after it has been freed.
Daniel Atallah <datallah@pidgin.im>
parents:
15688
diff
changeset
|
858 | jbi->ids = g_slist_remove(jbi->ids, comp_id); |
|
0754583ceeae
Don't access the list element after it has been freed.
Daniel Atallah <datallah@pidgin.im>
parents:
15688
diff
changeset
|
859 | g_free(comp_id); |
| 13794 | 860 | return; |
| 861 | } | |
| 862 | l = l->next; | |
| 863 | } | |
| 864 | } | |
| 865 | ||
| 866 | static void jabber_vcard_parse(JabberStream *js, xmlnode *packet, gpointer data) | |
| 867 | { | |
|
14129
70db31dfeeb1
[gaim-migrate @ 16688]
Daniel Atallah <datallah@pidgin.im>
parents:
13808
diff
changeset
|
868 | const char *id, *from; |
| 13794 | 869 | GString *info_text; |
| 870 | char *bare_jid; | |
| 871 | char *text; | |
| 872 | xmlnode *vcard; | |
| 15884 | 873 | PurpleBuddy *b; |
| 13794 | 874 | JabberBuddyInfo *jbi = data; |
| 875 | ||
| 876 | from = xmlnode_get_attrib(packet, "from"); | |
| 877 | id = xmlnode_get_attrib(packet, "id"); | |
| 878 | ||
| 879 | if(!jbi) | |
| 880 | return; | |
| 881 | ||
|
14129
70db31dfeeb1
[gaim-migrate @ 16688]
Daniel Atallah <datallah@pidgin.im>
parents:
13808
diff
changeset
|
882 | jabber_buddy_info_remove_id(jbi, id); |
|
70db31dfeeb1
[gaim-migrate @ 16688]
Daniel Atallah <datallah@pidgin.im>
parents:
13808
diff
changeset
|
883 | |
| 13794 | 884 | if(!from) |
| 885 | return; | |
| 886 | ||
|
14129
70db31dfeeb1
[gaim-migrate @ 16688]
Daniel Atallah <datallah@pidgin.im>
parents:
13808
diff
changeset
|
887 | if(!jabber_buddy_find(js, from, FALSE)) |
| 13794 | 888 | return; |
| 889 | ||
| 890 | /* XXX: handle the error case */ | |
| 891 | ||
| 892 | bare_jid = jabber_get_bare_jid(from); | |
| 893 | ||
| 15884 | 894 | b = purple_find_buddy(js->gc->account, bare_jid); |
| 13794 | 895 | |
| 896 | info_text = g_string_new(""); | |
| 897 | ||
| 10189 | 898 | if((vcard = xmlnode_get_child(packet, "vCard")) || |
| 899 | (vcard = xmlnode_get_child_with_namespace(packet, "query", "vcard-temp"))) { | |
| 7014 | 900 | xmlnode *child; |
| 901 | for(child = vcard->child; child; child = child->next) | |
| 902 | { | |
| 903 | xmlnode *child2; | |
| 904 | ||
| 8135 | 905 | if(child->type != XMLNODE_TYPE_TAG) |
| 7014 | 906 | continue; |
| 907 | ||
| 908 | text = xmlnode_get_data(child); | |
| 909 | if(text && !strcmp(child->name, "FN")) { | |
| 8213 | 910 | g_string_append_printf(info_text, "<b>%s:</b> %s<br/>", |
| 7014 | 911 | _("Full Name"), text); |
| 912 | } else if(!strcmp(child->name, "N")) { | |
| 913 | for(child2 = child->child; child2; child2 = child2->next) | |
| 914 | { | |
| 915 | char *text2; | |
| 916 | ||
| 8135 | 917 | if(child2->type != XMLNODE_TYPE_TAG) |
| 7014 | 918 | continue; |
| 919 | ||
| 920 | text2 = xmlnode_get_data(child2); | |
| 921 | if(text2 && !strcmp(child2->name, "FAMILY")) { | |
| 922 | g_string_append_printf(info_text, | |
| 8213 | 923 | "<b>%s:</b> %s<br/>", |
| 7014 | 924 | _("Family Name"), text2); |
| 925 | } else if(text2 && !strcmp(child2->name, "GIVEN")) { | |
| 926 | g_string_append_printf(info_text, | |
| 8213 | 927 | "<b>%s:</b> %s<br/>", |
| 7014 | 928 | _("Given Name"), text2); |
| 929 | } else if(text2 && !strcmp(child2->name, "MIDDLE")) { | |
| 930 | g_string_append_printf(info_text, | |
| 8213 | 931 | "<b>%s:</b> %s<br/>", |
| 7014 | 932 | _("Middle Name"), text2); |
| 933 | } | |
| 934 | g_free(text2); | |
| 935 | } | |
| 936 | } else if(text && !strcmp(child->name, "NICKNAME")) { | |
| 937 | serv_got_alias(js->gc, from, text); | |
| 7955 | 938 | if(b) { |
| 15884 | 939 | purple_blist_node_set_string((PurpleBlistNode*)b, "servernick", text); |
| 7955 | 940 | } |
| 8213 | 941 | g_string_append_printf(info_text, "<b>%s:</b> %s<br/>", |
| 7014 | 942 | _("Nickname"), text); |
| 943 | } else if(text && !strcmp(child->name, "BDAY")) { | |
| 8213 | 944 | g_string_append_printf(info_text, "<b>%s:</b> %s<br/>", |
| 7014 | 945 | _("Birthday"), text); |
| 946 | } else if(!strcmp(child->name, "ADR")) { | |
|
12933
885970470a9b
[gaim-migrate @ 15286]
Richard Laager <rlaager@pidgin.im>
parents:
12919
diff
changeset
|
947 | gboolean address_line_added = FALSE; |
|
885970470a9b
[gaim-migrate @ 15286]
Richard Laager <rlaager@pidgin.im>
parents:
12919
diff
changeset
|
948 | |
| 7014 | 949 | for(child2 = child->child; child2; child2 = child2->next) |
| 950 | { | |
| 951 | char *text2; | |
| 952 | ||
| 8135 | 953 | if(child2->type != XMLNODE_TYPE_TAG) |
| 7014 | 954 | continue; |
| 955 | ||
| 956 | text2 = xmlnode_get_data(child2); | |
|
12933
885970470a9b
[gaim-migrate @ 15286]
Richard Laager <rlaager@pidgin.im>
parents:
12919
diff
changeset
|
957 | if (text2 == NULL) |
|
885970470a9b
[gaim-migrate @ 15286]
Richard Laager <rlaager@pidgin.im>
parents:
12919
diff
changeset
|
958 | continue; |
|
885970470a9b
[gaim-migrate @ 15286]
Richard Laager <rlaager@pidgin.im>
parents:
12919
diff
changeset
|
959 | |
|
885970470a9b
[gaim-migrate @ 15286]
Richard Laager <rlaager@pidgin.im>
parents:
12919
diff
changeset
|
960 | /* We do this here so that it's not added if all the child |
|
885970470a9b
[gaim-migrate @ 15286]
Richard Laager <rlaager@pidgin.im>
parents:
12919
diff
changeset
|
961 | * elements are empty. */ |
|
885970470a9b
[gaim-migrate @ 15286]
Richard Laager <rlaager@pidgin.im>
parents:
12919
diff
changeset
|
962 | if (!address_line_added) |
|
885970470a9b
[gaim-migrate @ 15286]
Richard Laager <rlaager@pidgin.im>
parents:
12919
diff
changeset
|
963 | { |
|
885970470a9b
[gaim-migrate @ 15286]
Richard Laager <rlaager@pidgin.im>
parents:
12919
diff
changeset
|
964 | g_string_append_printf(info_text, "<b>%s:</b><br/>", |
|
885970470a9b
[gaim-migrate @ 15286]
Richard Laager <rlaager@pidgin.im>
parents:
12919
diff
changeset
|
965 | _("Address")); |
|
885970470a9b
[gaim-migrate @ 15286]
Richard Laager <rlaager@pidgin.im>
parents:
12919
diff
changeset
|
966 | address_line_added = TRUE; |
|
885970470a9b
[gaim-migrate @ 15286]
Richard Laager <rlaager@pidgin.im>
parents:
12919
diff
changeset
|
967 | } |
|
885970470a9b
[gaim-migrate @ 15286]
Richard Laager <rlaager@pidgin.im>
parents:
12919
diff
changeset
|
968 | |
|
885970470a9b
[gaim-migrate @ 15286]
Richard Laager <rlaager@pidgin.im>
parents:
12919
diff
changeset
|
969 | if(!strcmp(child2->name, "POBOX")) { |
| 7014 | 970 | g_string_append_printf(info_text, |
| 8213 | 971 | " <b>%s:</b> %s<br/>", |
| 7014 | 972 | _("P.O. Box"), text2); |
|
12933
885970470a9b
[gaim-migrate @ 15286]
Richard Laager <rlaager@pidgin.im>
parents:
12919
diff
changeset
|
973 | } else if(!strcmp(child2->name, "EXTADR")) { |
| 7014 | 974 | g_string_append_printf(info_text, |
| 8213 | 975 | " <b>%s:</b> %s<br/>", |
| 7014 | 976 | _("Extended Address"), text2); |
|
12933
885970470a9b
[gaim-migrate @ 15286]
Richard Laager <rlaager@pidgin.im>
parents:
12919
diff
changeset
|
977 | } else if(!strcmp(child2->name, "STREET")) { |
| 7014 | 978 | g_string_append_printf(info_text, |
| 8213 | 979 | " <b>%s:</b> %s<br/>", |
| 7014 | 980 | _("Street Address"), text2); |
|
12933
885970470a9b
[gaim-migrate @ 15286]
Richard Laager <rlaager@pidgin.im>
parents:
12919
diff
changeset
|
981 | } else if(!strcmp(child2->name, "LOCALITY")) { |
| 7014 | 982 | g_string_append_printf(info_text, |
| 8213 | 983 | " <b>%s:</b> %s<br/>", |
| 7014 | 984 | _("Locality"), text2); |
|
12933
885970470a9b
[gaim-migrate @ 15286]
Richard Laager <rlaager@pidgin.im>
parents:
12919
diff
changeset
|
985 | } else if(!strcmp(child2->name, "REGION")) { |
| 7014 | 986 | g_string_append_printf(info_text, |
| 8213 | 987 | " <b>%s:</b> %s<br/>", |
| 7014 | 988 | _("Region"), text2); |
|
12933
885970470a9b
[gaim-migrate @ 15286]
Richard Laager <rlaager@pidgin.im>
parents:
12919
diff
changeset
|
989 | } else if(!strcmp(child2->name, "PCODE")) { |
| 7014 | 990 | g_string_append_printf(info_text, |
| 8213 | 991 | " <b>%s:</b> %s<br/>", |
| 7014 | 992 | _("Postal Code"), text2); |
|
12933
885970470a9b
[gaim-migrate @ 15286]
Richard Laager <rlaager@pidgin.im>
parents:
12919
diff
changeset
|
993 | } else if(!strcmp(child2->name, "CTRY") |
|
885970470a9b
[gaim-migrate @ 15286]
Richard Laager <rlaager@pidgin.im>
parents:
12919
diff
changeset
|
994 | || !strcmp(child2->name, "COUNTRY")) { |
| 7014 | 995 | g_string_append_printf(info_text, |
| 8213 | 996 | " <b>%s:</b> %s<br/>", |
| 7014 | 997 | _("Country"), text2); |
| 998 | } | |
| 999 | g_free(text2); | |
| 1000 | } | |
| 1001 | } else if(!strcmp(child->name, "TEL")) { | |
| 1002 | char *number; | |
| 1003 | if((child2 = xmlnode_get_child(child, "NUMBER"))) { | |
| 1004 | /* show what kind of number it is */ | |
| 1005 | number = xmlnode_get_data(child2); | |
| 1006 | if(number) { | |
| 1007 | g_string_append_printf(info_text, | |
| 8213 | 1008 | "<b>%s:</b> %s<br/>", _("Telephone"), number); |
| 7014 | 1009 | g_free(number); |
| 1010 | } | |
| 1011 | } else if((number = xmlnode_get_data(child))) { | |
| 15884 | 1012 | /* lots of clients (including purple) do this, but it's |
| 7014 | 1013 | * out of spec */ |
| 1014 | g_string_append_printf(info_text, | |
| 8213 | 1015 | "<b>%s:</b> %s<br/>", _("Telephone"), number); |
| 7014 | 1016 | g_free(number); |
| 1017 | } | |
| 1018 | } else if(!strcmp(child->name, "EMAIL")) { | |
| 1019 | char *userid; | |
| 1020 | if((child2 = xmlnode_get_child(child, "USERID"))) { | |
| 1021 | /* show what kind of email it is */ | |
| 1022 | userid = xmlnode_get_data(child2); | |
| 1023 | if(userid) { | |
| 1024 | g_string_append_printf(info_text, | |
| 8213 | 1025 | "<b>%s:</b> <a href='mailto:%s'>%s</a><br/>", |
|
13546
0700f0c29e14
[gaim-migrate @ 15922]
Richard Laager <rlaager@pidgin.im>
parents:
13345
diff
changeset
|
1026 | _("E-Mail"), userid, userid); |
| 7014 | 1027 | g_free(userid); |
| 1028 | } | |
| 1029 | } else if((userid = xmlnode_get_data(child))) { | |
| 15884 | 1030 | /* lots of clients (including purple) do this, but it's |
| 7014 | 1031 | * out of spec */ |
| 1032 | g_string_append_printf(info_text, | |
| 8213 | 1033 | "<b>%s:</b> <a href='mailto:%s'>%s</a><br/>", |
|
13546
0700f0c29e14
[gaim-migrate @ 15922]
Richard Laager <rlaager@pidgin.im>
parents:
13345
diff
changeset
|
1034 | _("E-Mail"), userid, userid); |
| 7014 | 1035 | g_free(userid); |
| 1036 | } | |
| 1037 | } else if(!strcmp(child->name, "ORG")) { | |
| 1038 | for(child2 = child->child; child2; child2 = child2->next) | |
| 1039 | { | |
| 1040 | char *text2; | |
| 1041 | ||
| 8135 | 1042 | if(child2->type != XMLNODE_TYPE_TAG) |
| 7014 | 1043 | continue; |
| 1044 | ||
| 1045 | text2 = xmlnode_get_data(child2); | |
| 1046 | if(text2 && !strcmp(child2->name, "ORGNAME")) { | |
| 1047 | g_string_append_printf(info_text, | |
| 8213 | 1048 | "<b>%s:</b> %s<br/>", |
| 7014 | 1049 | _("Organization Name"), text2); |
| 1050 | } else if(text2 && !strcmp(child2->name, "ORGUNIT")) { | |
| 1051 | g_string_append_printf(info_text, | |
| 8213 | 1052 | "<b>%s:</b> %s<br/>", |
| 7014 | 1053 | _("Organization Unit"), text2); |
| 1054 | } | |
| 1055 | g_free(text2); | |
| 1056 | } | |
| 1057 | } else if(text && !strcmp(child->name, "TITLE")) { | |
| 8213 | 1058 | g_string_append_printf(info_text, "<b>%s:</b> %s<br/>", |
| 7014 | 1059 | _("Title"), text); |
| 1060 | } else if(text && !strcmp(child->name, "ROLE")) { | |
| 8213 | 1061 | g_string_append_printf(info_text, "<b>%s:</b> %s<br/>", |
| 7014 | 1062 | _("Role"), text); |
| 1063 | } else if(text && !strcmp(child->name, "DESC")) { | |
| 8213 | 1064 | g_string_append_printf(info_text, "<b>%s:</b> %s<br/>", |
| 1065 | _("Description"), text); | |
| 7076 | 1066 | } else if(!strcmp(child->name, "PHOTO") || |
| 1067 | !strcmp(child->name, "LOGO")) { | |
| 10941 | 1068 | char *bintext = NULL; |
| 1069 | xmlnode *binval; | |
| 11361 | 1070 | |
| 1071 | if( ((binval = xmlnode_get_child(child, "BINVAL")) && | |
| 1072 | (bintext = xmlnode_get_data(binval))) || | |
| 1073 | (bintext = xmlnode_get_data(child))) { | |
|
11127
5e539d9d26a4
[gaim-migrate @ 13183]
Mark Doliner <markdoliner@pidgin.im>
parents:
10941
diff
changeset
|
1074 | gsize size; |
|
11137
cf40226ddff7
[gaim-migrate @ 13201]
Mark Doliner <markdoliner@pidgin.im>
parents:
11127
diff
changeset
|
1075 | guchar *data; |
|
11127
5e539d9d26a4
[gaim-migrate @ 13183]
Mark Doliner <markdoliner@pidgin.im>
parents:
10941
diff
changeset
|
1076 | int i; |
| 10941 | 1077 | unsigned char hashval[20]; |
|
11127
5e539d9d26a4
[gaim-migrate @ 13183]
Mark Doliner <markdoliner@pidgin.im>
parents:
10941
diff
changeset
|
1078 | char *p, hash[41]; |
| 10941 | 1079 | gboolean photo = (strcmp(child->name, "PHOTO") == 0); |
| 10189 | 1080 | |
| 15884 | 1081 | data = purple_base64_decode(bintext, &size); |
|
16587
50de12a4b81b
disapproval of revision 'f95b376c0d2f066996620c5bb595dc71b5ee22d9'
Richard Laager <rlaager@pidgin.im>
parents:
16585
diff
changeset
|
1082 | if (data) { |
|
50de12a4b81b
disapproval of revision 'f95b376c0d2f066996620c5bb595dc71b5ee22d9'
Richard Laager <rlaager@pidgin.im>
parents:
16585
diff
changeset
|
1083 | jbi->vcard_imgids = g_slist_prepend(jbi->vcard_imgids, GINT_TO_POINTER(purple_imgstore_add_with_id(g_memdup(data, size), size, "logo.png"))); |
|
50de12a4b81b
disapproval of revision 'f95b376c0d2f066996620c5bb595dc71b5ee22d9'
Richard Laager <rlaager@pidgin.im>
parents:
16585
diff
changeset
|
1084 | g_string_append_printf(info_text, |
|
50de12a4b81b
disapproval of revision 'f95b376c0d2f066996620c5bb595dc71b5ee22d9'
Richard Laager <rlaager@pidgin.im>
parents:
16585
diff
changeset
|
1085 | "<b>%s:</b> <img id='%d'><br/>", |
|
50de12a4b81b
disapproval of revision 'f95b376c0d2f066996620c5bb595dc71b5ee22d9'
Richard Laager <rlaager@pidgin.im>
parents:
16585
diff
changeset
|
1086 | photo ? _("Photo") : _("Logo"), |
|
50de12a4b81b
disapproval of revision 'f95b376c0d2f066996620c5bb595dc71b5ee22d9'
Richard Laager <rlaager@pidgin.im>
parents:
16585
diff
changeset
|
1087 | GPOINTER_TO_INT(jbi->vcard_imgids->data)); |
|
50de12a4b81b
disapproval of revision 'f95b376c0d2f066996620c5bb595dc71b5ee22d9'
Richard Laager <rlaager@pidgin.im>
parents:
16585
diff
changeset
|
1088 | |
|
50de12a4b81b
disapproval of revision 'f95b376c0d2f066996620c5bb595dc71b5ee22d9'
Richard Laager <rlaager@pidgin.im>
parents:
16585
diff
changeset
|
1089 | purple_cipher_digest_region("sha1", (guchar *)data, size, |
|
50de12a4b81b
disapproval of revision 'f95b376c0d2f066996620c5bb595dc71b5ee22d9'
Richard Laager <rlaager@pidgin.im>
parents:
16585
diff
changeset
|
1090 | sizeof(hashval), hashval, NULL); |
|
50de12a4b81b
disapproval of revision 'f95b376c0d2f066996620c5bb595dc71b5ee22d9'
Richard Laager <rlaager@pidgin.im>
parents:
16585
diff
changeset
|
1091 | p = hash; |
|
50de12a4b81b
disapproval of revision 'f95b376c0d2f066996620c5bb595dc71b5ee22d9'
Richard Laager <rlaager@pidgin.im>
parents:
16585
diff
changeset
|
1092 | for(i=0; i<20; i++, p+=2) |
|
50de12a4b81b
disapproval of revision 'f95b376c0d2f066996620c5bb595dc71b5ee22d9'
Richard Laager <rlaager@pidgin.im>
parents:
16585
diff
changeset
|
1093 | snprintf(p, 3, "%02x", hashval[i]); |
| 7076 | 1094 | |
|
16587
50de12a4b81b
disapproval of revision 'f95b376c0d2f066996620c5bb595dc71b5ee22d9'
Richard Laager <rlaager@pidgin.im>
parents:
16585
diff
changeset
|
1095 | purple_buddy_icons_set_for_user(js->gc->account, bare_jid, |
|
50de12a4b81b
disapproval of revision 'f95b376c0d2f066996620c5bb595dc71b5ee22d9'
Richard Laager <rlaager@pidgin.im>
parents:
16585
diff
changeset
|
1096 | data, size, hash); |
|
50de12a4b81b
disapproval of revision 'f95b376c0d2f066996620c5bb595dc71b5ee22d9'
Richard Laager <rlaager@pidgin.im>
parents:
16585
diff
changeset
|
1097 | g_free(bintext); |
|
50de12a4b81b
disapproval of revision 'f95b376c0d2f066996620c5bb595dc71b5ee22d9'
Richard Laager <rlaager@pidgin.im>
parents:
16585
diff
changeset
|
1098 | } |
| 10941 | 1099 | } |
| 7014 | 1100 | } |
| 1101 | g_free(text); | |
| 1102 | } | |
| 1103 | } | |
| 1104 | ||
| 15884 | 1105 | jbi->vcard_text = purple_strdup_withhtml(info_text->str); |
| 13794 | 1106 | g_string_free(info_text, TRUE); |
| 1107 | g_free(bare_jid); | |
| 1108 | ||
| 1109 | jabber_buddy_info_show_if_ready(jbi); | |
| 1110 | } | |
| 1111 | ||
|
17788
e6e381b0c7d6
Implemented receiving other people's avatars via XEP-0084. Note that this code now includes a workaround for a non-spec incompatibility for the current ejabberd PEP implementation, and doesn't use the correct namespace due to Psi using the wrong one (outdated?). Works fine though, and the vcard-based approach is retained.
Andreas Monitzer <am@adiumx.com>
parents:
17787
diff
changeset
|
1112 | typedef struct _JabberBuddyAvatarUpdateURLInfo { |
|
e6e381b0c7d6
Implemented receiving other people's avatars via XEP-0084. Note that this code now includes a workaround for a non-spec incompatibility for the current ejabberd PEP implementation, and doesn't use the correct namespace due to Psi using the wrong one (outdated?). Works fine though, and the vcard-based approach is retained.
Andreas Monitzer <am@adiumx.com>
parents:
17787
diff
changeset
|
1113 | JabberStream *js; |
|
e6e381b0c7d6
Implemented receiving other people's avatars via XEP-0084. Note that this code now includes a workaround for a non-spec incompatibility for the current ejabberd PEP implementation, and doesn't use the correct namespace due to Psi using the wrong one (outdated?). Works fine though, and the vcard-based approach is retained.
Andreas Monitzer <am@adiumx.com>
parents:
17787
diff
changeset
|
1114 | char *from; |
|
e6e381b0c7d6
Implemented receiving other people's avatars via XEP-0084. Note that this code now includes a workaround for a non-spec incompatibility for the current ejabberd PEP implementation, and doesn't use the correct namespace due to Psi using the wrong one (outdated?). Works fine though, and the vcard-based approach is retained.
Andreas Monitzer <am@adiumx.com>
parents:
17787
diff
changeset
|
1115 | char *id; |
|
e6e381b0c7d6
Implemented receiving other people's avatars via XEP-0084. Note that this code now includes a workaround for a non-spec incompatibility for the current ejabberd PEP implementation, and doesn't use the correct namespace due to Psi using the wrong one (outdated?). Works fine though, and the vcard-based approach is retained.
Andreas Monitzer <am@adiumx.com>
parents:
17787
diff
changeset
|
1116 | } JabberBuddyAvatarUpdateURLInfo; |
|
e6e381b0c7d6
Implemented receiving other people's avatars via XEP-0084. Note that this code now includes a workaround for a non-spec incompatibility for the current ejabberd PEP implementation, and doesn't use the correct namespace due to Psi using the wrong one (outdated?). Works fine though, and the vcard-based approach is retained.
Andreas Monitzer <am@adiumx.com>
parents:
17787
diff
changeset
|
1117 | |
|
e6e381b0c7d6
Implemented receiving other people's avatars via XEP-0084. Note that this code now includes a workaround for a non-spec incompatibility for the current ejabberd PEP implementation, and doesn't use the correct namespace due to Psi using the wrong one (outdated?). Works fine though, and the vcard-based approach is retained.
Andreas Monitzer <am@adiumx.com>
parents:
17787
diff
changeset
|
1118 | static void do_buddy_avatar_update_fromurl(PurpleUtilFetchUrlData *url_data, gpointer user_data, const gchar *url_text, gsize len, const gchar *error_message) { |
|
e6e381b0c7d6
Implemented receiving other people's avatars via XEP-0084. Note that this code now includes a workaround for a non-spec incompatibility for the current ejabberd PEP implementation, and doesn't use the correct namespace due to Psi using the wrong one (outdated?). Works fine though, and the vcard-based approach is retained.
Andreas Monitzer <am@adiumx.com>
parents:
17787
diff
changeset
|
1119 | JabberBuddyAvatarUpdateURLInfo *info = user_data; |
|
e6e381b0c7d6
Implemented receiving other people's avatars via XEP-0084. Note that this code now includes a workaround for a non-spec incompatibility for the current ejabberd PEP implementation, and doesn't use the correct namespace due to Psi using the wrong one (outdated?). Works fine though, and the vcard-based approach is retained.
Andreas Monitzer <am@adiumx.com>
parents:
17787
diff
changeset
|
1120 | if(!url_text) { |
|
e6e381b0c7d6
Implemented receiving other people's avatars via XEP-0084. Note that this code now includes a workaround for a non-spec incompatibility for the current ejabberd PEP implementation, and doesn't use the correct namespace due to Psi using the wrong one (outdated?). Works fine though, and the vcard-based approach is retained.
Andreas Monitzer <am@adiumx.com>
parents:
17787
diff
changeset
|
1121 | purple_debug(PURPLE_DEBUG_ERROR, "jabber", |
|
e6e381b0c7d6
Implemented receiving other people's avatars via XEP-0084. Note that this code now includes a workaround for a non-spec incompatibility for the current ejabberd PEP implementation, and doesn't use the correct namespace due to Psi using the wrong one (outdated?). Works fine though, and the vcard-based approach is retained.
Andreas Monitzer <am@adiumx.com>
parents:
17787
diff
changeset
|
1122 | "do_buddy_avatar_update_fromurl got error \"%s\"", error_message); |
|
e6e381b0c7d6
Implemented receiving other people's avatars via XEP-0084. Note that this code now includes a workaround for a non-spec incompatibility for the current ejabberd PEP implementation, and doesn't use the correct namespace due to Psi using the wrong one (outdated?). Works fine though, and the vcard-based approach is retained.
Andreas Monitzer <am@adiumx.com>
parents:
17787
diff
changeset
|
1123 | return; |
|
e6e381b0c7d6
Implemented receiving other people's avatars via XEP-0084. Note that this code now includes a workaround for a non-spec incompatibility for the current ejabberd PEP implementation, and doesn't use the correct namespace due to Psi using the wrong one (outdated?). Works fine though, and the vcard-based approach is retained.
Andreas Monitzer <am@adiumx.com>
parents:
17787
diff
changeset
|
1124 | } |
|
e6e381b0c7d6
Implemented receiving other people's avatars via XEP-0084. Note that this code now includes a workaround for a non-spec incompatibility for the current ejabberd PEP implementation, and doesn't use the correct namespace due to Psi using the wrong one (outdated?). Works fine though, and the vcard-based approach is retained.
Andreas Monitzer <am@adiumx.com>
parents:
17787
diff
changeset
|
1125 | |
|
e6e381b0c7d6
Implemented receiving other people's avatars via XEP-0084. Note that this code now includes a workaround for a non-spec incompatibility for the current ejabberd PEP implementation, and doesn't use the correct namespace due to Psi using the wrong one (outdated?). Works fine though, and the vcard-based approach is retained.
Andreas Monitzer <am@adiumx.com>
parents:
17787
diff
changeset
|
1126 | purple_buddy_icons_set_for_user(purple_connection_get_account(info->js->gc), info->from, (void*)url_text, len, info->id); |
|
e6e381b0c7d6
Implemented receiving other people's avatars via XEP-0084. Note that this code now includes a workaround for a non-spec incompatibility for the current ejabberd PEP implementation, and doesn't use the correct namespace due to Psi using the wrong one (outdated?). Works fine though, and the vcard-based approach is retained.
Andreas Monitzer <am@adiumx.com>
parents:
17787
diff
changeset
|
1127 | g_free(info->from); |
|
e6e381b0c7d6
Implemented receiving other people's avatars via XEP-0084. Note that this code now includes a workaround for a non-spec incompatibility for the current ejabberd PEP implementation, and doesn't use the correct namespace due to Psi using the wrong one (outdated?). Works fine though, and the vcard-based approach is retained.
Andreas Monitzer <am@adiumx.com>
parents:
17787
diff
changeset
|
1128 | g_free(info->id); |
|
e6e381b0c7d6
Implemented receiving other people's avatars via XEP-0084. Note that this code now includes a workaround for a non-spec incompatibility for the current ejabberd PEP implementation, and doesn't use the correct namespace due to Psi using the wrong one (outdated?). Works fine though, and the vcard-based approach is retained.
Andreas Monitzer <am@adiumx.com>
parents:
17787
diff
changeset
|
1129 | g_free(info); |
|
e6e381b0c7d6
Implemented receiving other people's avatars via XEP-0084. Note that this code now includes a workaround for a non-spec incompatibility for the current ejabberd PEP implementation, and doesn't use the correct namespace due to Psi using the wrong one (outdated?). Works fine though, and the vcard-based approach is retained.
Andreas Monitzer <am@adiumx.com>
parents:
17787
diff
changeset
|
1130 | } |
|
e6e381b0c7d6
Implemented receiving other people's avatars via XEP-0084. Note that this code now includes a workaround for a non-spec incompatibility for the current ejabberd PEP implementation, and doesn't use the correct namespace due to Psi using the wrong one (outdated?). Works fine though, and the vcard-based approach is retained.
Andreas Monitzer <am@adiumx.com>
parents:
17787
diff
changeset
|
1131 | |
|
17789
f75d542850e3
Turns out the example in XEP-0084 is wrong. Fixed my implementation to not try to work around an issue that isn't one.
Andreas Monitzer <am@adiumx.com>
parents:
17788
diff
changeset
|
1132 | static void do_buddy_avatar_update_data(JabberStream *js, const char *from, xmlnode *items) { |
|
f75d542850e3
Turns out the example in XEP-0084 is wrong. Fixed my implementation to not try to work around an issue that isn't one.
Andreas Monitzer <am@adiumx.com>
parents:
17788
diff
changeset
|
1133 | xmlnode *item, *data; |
|
17788
e6e381b0c7d6
Implemented receiving other people's avatars via XEP-0084. Note that this code now includes a workaround for a non-spec incompatibility for the current ejabberd PEP implementation, and doesn't use the correct namespace due to Psi using the wrong one (outdated?). Works fine though, and the vcard-based approach is retained.
Andreas Monitzer <am@adiumx.com>
parents:
17787
diff
changeset
|
1134 | const char *checksum; |
|
e6e381b0c7d6
Implemented receiving other people's avatars via XEP-0084. Note that this code now includes a workaround for a non-spec incompatibility for the current ejabberd PEP implementation, and doesn't use the correct namespace due to Psi using the wrong one (outdated?). Works fine though, and the vcard-based approach is retained.
Andreas Monitzer <am@adiumx.com>
parents:
17787
diff
changeset
|
1135 | char *b64data; |
|
e6e381b0c7d6
Implemented receiving other people's avatars via XEP-0084. Note that this code now includes a workaround for a non-spec incompatibility for the current ejabberd PEP implementation, and doesn't use the correct namespace due to Psi using the wrong one (outdated?). Works fine though, and the vcard-based approach is retained.
Andreas Monitzer <am@adiumx.com>
parents:
17787
diff
changeset
|
1136 | void *img; |
|
e6e381b0c7d6
Implemented receiving other people's avatars via XEP-0084. Note that this code now includes a workaround for a non-spec incompatibility for the current ejabberd PEP implementation, and doesn't use the correct namespace due to Psi using the wrong one (outdated?). Works fine though, and the vcard-based approach is retained.
Andreas Monitzer <am@adiumx.com>
parents:
17787
diff
changeset
|
1137 | size_t size; |
|
17789
f75d542850e3
Turns out the example in XEP-0084 is wrong. Fixed my implementation to not try to work around an issue that isn't one.
Andreas Monitzer <am@adiumx.com>
parents:
17788
diff
changeset
|
1138 | if(!items) |
|
f75d542850e3
Turns out the example in XEP-0084 is wrong. Fixed my implementation to not try to work around an issue that isn't one.
Andreas Monitzer <am@adiumx.com>
parents:
17788
diff
changeset
|
1139 | return; |
|
f75d542850e3
Turns out the example in XEP-0084 is wrong. Fixed my implementation to not try to work around an issue that isn't one.
Andreas Monitzer <am@adiumx.com>
parents:
17788
diff
changeset
|
1140 | |
|
f75d542850e3
Turns out the example in XEP-0084 is wrong. Fixed my implementation to not try to work around an issue that isn't one.
Andreas Monitzer <am@adiumx.com>
parents:
17788
diff
changeset
|
1141 | item = xmlnode_get_child(items, "item"); |
|
17788
e6e381b0c7d6
Implemented receiving other people's avatars via XEP-0084. Note that this code now includes a workaround for a non-spec incompatibility for the current ejabberd PEP implementation, and doesn't use the correct namespace due to Psi using the wrong one (outdated?). Works fine though, and the vcard-based approach is retained.
Andreas Monitzer <am@adiumx.com>
parents:
17787
diff
changeset
|
1142 | if(!item) |
|
e6e381b0c7d6
Implemented receiving other people's avatars via XEP-0084. Note that this code now includes a workaround for a non-spec incompatibility for the current ejabberd PEP implementation, and doesn't use the correct namespace due to Psi using the wrong one (outdated?). Works fine though, and the vcard-based approach is retained.
Andreas Monitzer <am@adiumx.com>
parents:
17787
diff
changeset
|
1143 | return; |
|
e6e381b0c7d6
Implemented receiving other people's avatars via XEP-0084. Note that this code now includes a workaround for a non-spec incompatibility for the current ejabberd PEP implementation, and doesn't use the correct namespace due to Psi using the wrong one (outdated?). Works fine though, and the vcard-based approach is retained.
Andreas Monitzer <am@adiumx.com>
parents:
17787
diff
changeset
|
1144 | |
|
e6e381b0c7d6
Implemented receiving other people's avatars via XEP-0084. Note that this code now includes a workaround for a non-spec incompatibility for the current ejabberd PEP implementation, and doesn't use the correct namespace due to Psi using the wrong one (outdated?). Works fine though, and the vcard-based approach is retained.
Andreas Monitzer <am@adiumx.com>
parents:
17787
diff
changeset
|
1145 | data = xmlnode_get_child_with_namespace(item,"data",AVATARNAMESPACEDATA); |
|
e6e381b0c7d6
Implemented receiving other people's avatars via XEP-0084. Note that this code now includes a workaround for a non-spec incompatibility for the current ejabberd PEP implementation, and doesn't use the correct namespace due to Psi using the wrong one (outdated?). Works fine though, and the vcard-based approach is retained.
Andreas Monitzer <am@adiumx.com>
parents:
17787
diff
changeset
|
1146 | if(!data) |
|
e6e381b0c7d6
Implemented receiving other people's avatars via XEP-0084. Note that this code now includes a workaround for a non-spec incompatibility for the current ejabberd PEP implementation, and doesn't use the correct namespace due to Psi using the wrong one (outdated?). Works fine though, and the vcard-based approach is retained.
Andreas Monitzer <am@adiumx.com>
parents:
17787
diff
changeset
|
1147 | return; |
|
e6e381b0c7d6
Implemented receiving other people's avatars via XEP-0084. Note that this code now includes a workaround for a non-spec incompatibility for the current ejabberd PEP implementation, and doesn't use the correct namespace due to Psi using the wrong one (outdated?). Works fine though, and the vcard-based approach is retained.
Andreas Monitzer <am@adiumx.com>
parents:
17787
diff
changeset
|
1148 | |
|
e6e381b0c7d6
Implemented receiving other people's avatars via XEP-0084. Note that this code now includes a workaround for a non-spec incompatibility for the current ejabberd PEP implementation, and doesn't use the correct namespace due to Psi using the wrong one (outdated?). Works fine though, and the vcard-based approach is retained.
Andreas Monitzer <am@adiumx.com>
parents:
17787
diff
changeset
|
1149 | checksum = xmlnode_get_attrib(item,"id"); |
|
e6e381b0c7d6
Implemented receiving other people's avatars via XEP-0084. Note that this code now includes a workaround for a non-spec incompatibility for the current ejabberd PEP implementation, and doesn't use the correct namespace due to Psi using the wrong one (outdated?). Works fine though, and the vcard-based approach is retained.
Andreas Monitzer <am@adiumx.com>
parents:
17787
diff
changeset
|
1150 | if(!checksum) |
|
e6e381b0c7d6
Implemented receiving other people's avatars via XEP-0084. Note that this code now includes a workaround for a non-spec incompatibility for the current ejabberd PEP implementation, and doesn't use the correct namespace due to Psi using the wrong one (outdated?). Works fine though, and the vcard-based approach is retained.
Andreas Monitzer <am@adiumx.com>
parents:
17787
diff
changeset
|
1151 | return; |
|
e6e381b0c7d6
Implemented receiving other people's avatars via XEP-0084. Note that this code now includes a workaround for a non-spec incompatibility for the current ejabberd PEP implementation, and doesn't use the correct namespace due to Psi using the wrong one (outdated?). Works fine though, and the vcard-based approach is retained.
Andreas Monitzer <am@adiumx.com>
parents:
17787
diff
changeset
|
1152 | |
|
e6e381b0c7d6
Implemented receiving other people's avatars via XEP-0084. Note that this code now includes a workaround for a non-spec incompatibility for the current ejabberd PEP implementation, and doesn't use the correct namespace due to Psi using the wrong one (outdated?). Works fine though, and the vcard-based approach is retained.
Andreas Monitzer <am@adiumx.com>
parents:
17787
diff
changeset
|
1153 | b64data = xmlnode_get_data(data); |
|
e6e381b0c7d6
Implemented receiving other people's avatars via XEP-0084. Note that this code now includes a workaround for a non-spec incompatibility for the current ejabberd PEP implementation, and doesn't use the correct namespace due to Psi using the wrong one (outdated?). Works fine though, and the vcard-based approach is retained.
Andreas Monitzer <am@adiumx.com>
parents:
17787
diff
changeset
|
1154 | if(!b64data) |
|
e6e381b0c7d6
Implemented receiving other people's avatars via XEP-0084. Note that this code now includes a workaround for a non-spec incompatibility for the current ejabberd PEP implementation, and doesn't use the correct namespace due to Psi using the wrong one (outdated?). Works fine though, and the vcard-based approach is retained.
Andreas Monitzer <am@adiumx.com>
parents:
17787
diff
changeset
|
1155 | return; |
|
e6e381b0c7d6
Implemented receiving other people's avatars via XEP-0084. Note that this code now includes a workaround for a non-spec incompatibility for the current ejabberd PEP implementation, and doesn't use the correct namespace due to Psi using the wrong one (outdated?). Works fine though, and the vcard-based approach is retained.
Andreas Monitzer <am@adiumx.com>
parents:
17787
diff
changeset
|
1156 | |
|
e6e381b0c7d6
Implemented receiving other people's avatars via XEP-0084. Note that this code now includes a workaround for a non-spec incompatibility for the current ejabberd PEP implementation, and doesn't use the correct namespace due to Psi using the wrong one (outdated?). Works fine though, and the vcard-based approach is retained.
Andreas Monitzer <am@adiumx.com>
parents:
17787
diff
changeset
|
1157 | img = purple_base64_decode(b64data, &size); |
|
e6e381b0c7d6
Implemented receiving other people's avatars via XEP-0084. Note that this code now includes a workaround for a non-spec incompatibility for the current ejabberd PEP implementation, and doesn't use the correct namespace due to Psi using the wrong one (outdated?). Works fine though, and the vcard-based approach is retained.
Andreas Monitzer <am@adiumx.com>
parents:
17787
diff
changeset
|
1158 | if(!img) |
|
e6e381b0c7d6
Implemented receiving other people's avatars via XEP-0084. Note that this code now includes a workaround for a non-spec incompatibility for the current ejabberd PEP implementation, and doesn't use the correct namespace due to Psi using the wrong one (outdated?). Works fine though, and the vcard-based approach is retained.
Andreas Monitzer <am@adiumx.com>
parents:
17787
diff
changeset
|
1159 | return; |
|
e6e381b0c7d6
Implemented receiving other people's avatars via XEP-0084. Note that this code now includes a workaround for a non-spec incompatibility for the current ejabberd PEP implementation, and doesn't use the correct namespace due to Psi using the wrong one (outdated?). Works fine though, and the vcard-based approach is retained.
Andreas Monitzer <am@adiumx.com>
parents:
17787
diff
changeset
|
1160 | |
|
e6e381b0c7d6
Implemented receiving other people's avatars via XEP-0084. Note that this code now includes a workaround for a non-spec incompatibility for the current ejabberd PEP implementation, and doesn't use the correct namespace due to Psi using the wrong one (outdated?). Works fine though, and the vcard-based approach is retained.
Andreas Monitzer <am@adiumx.com>
parents:
17787
diff
changeset
|
1161 | purple_buddy_icons_set_for_user(purple_connection_get_account(js->gc), from, img, size, checksum); |
|
e6e381b0c7d6
Implemented receiving other people's avatars via XEP-0084. Note that this code now includes a workaround for a non-spec incompatibility for the current ejabberd PEP implementation, and doesn't use the correct namespace due to Psi using the wrong one (outdated?). Works fine though, and the vcard-based approach is retained.
Andreas Monitzer <am@adiumx.com>
parents:
17787
diff
changeset
|
1162 | } |
|
e6e381b0c7d6
Implemented receiving other people's avatars via XEP-0084. Note that this code now includes a workaround for a non-spec incompatibility for the current ejabberd PEP implementation, and doesn't use the correct namespace due to Psi using the wrong one (outdated?). Works fine though, and the vcard-based approach is retained.
Andreas Monitzer <am@adiumx.com>
parents:
17787
diff
changeset
|
1163 | |
|
17787
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
1164 | void jabber_buddy_avatar_update_metadata(JabberStream *js, const char *from, xmlnode *items) { |
|
17788
e6e381b0c7d6
Implemented receiving other people's avatars via XEP-0084. Note that this code now includes a workaround for a non-spec incompatibility for the current ejabberd PEP implementation, and doesn't use the correct namespace due to Psi using the wrong one (outdated?). Works fine though, and the vcard-based approach is retained.
Andreas Monitzer <am@adiumx.com>
parents:
17787
diff
changeset
|
1165 | PurpleBuddy *buddy = purple_find_buddy(purple_connection_get_account(js->gc), from); |
|
e6e381b0c7d6
Implemented receiving other people's avatars via XEP-0084. Note that this code now includes a workaround for a non-spec incompatibility for the current ejabberd PEP implementation, and doesn't use the correct namespace due to Psi using the wrong one (outdated?). Works fine though, and the vcard-based approach is retained.
Andreas Monitzer <am@adiumx.com>
parents:
17787
diff
changeset
|
1166 | const char *checksum; |
|
e6e381b0c7d6
Implemented receiving other people's avatars via XEP-0084. Note that this code now includes a workaround for a non-spec incompatibility for the current ejabberd PEP implementation, and doesn't use the correct namespace due to Psi using the wrong one (outdated?). Works fine though, and the vcard-based approach is retained.
Andreas Monitzer <am@adiumx.com>
parents:
17787
diff
changeset
|
1167 | xmlnode *item, *metadata; |
|
e6e381b0c7d6
Implemented receiving other people's avatars via XEP-0084. Note that this code now includes a workaround for a non-spec incompatibility for the current ejabberd PEP implementation, and doesn't use the correct namespace due to Psi using the wrong one (outdated?). Works fine though, and the vcard-based approach is retained.
Andreas Monitzer <am@adiumx.com>
parents:
17787
diff
changeset
|
1168 | if(!buddy) |
|
e6e381b0c7d6
Implemented receiving other people's avatars via XEP-0084. Note that this code now includes a workaround for a non-spec incompatibility for the current ejabberd PEP implementation, and doesn't use the correct namespace due to Psi using the wrong one (outdated?). Works fine though, and the vcard-based approach is retained.
Andreas Monitzer <am@adiumx.com>
parents:
17787
diff
changeset
|
1169 | return; |
|
17787
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
1170 | |
|
17788
e6e381b0c7d6
Implemented receiving other people's avatars via XEP-0084. Note that this code now includes a workaround for a non-spec incompatibility for the current ejabberd PEP implementation, and doesn't use the correct namespace due to Psi using the wrong one (outdated?). Works fine though, and the vcard-based approach is retained.
Andreas Monitzer <am@adiumx.com>
parents:
17787
diff
changeset
|
1171 | checksum = purple_buddy_icons_get_checksum_for_user(buddy); |
|
e6e381b0c7d6
Implemented receiving other people's avatars via XEP-0084. Note that this code now includes a workaround for a non-spec incompatibility for the current ejabberd PEP implementation, and doesn't use the correct namespace due to Psi using the wrong one (outdated?). Works fine though, and the vcard-based approach is retained.
Andreas Monitzer <am@adiumx.com>
parents:
17787
diff
changeset
|
1172 | item = xmlnode_get_child(items,"item"); |
|
e6e381b0c7d6
Implemented receiving other people's avatars via XEP-0084. Note that this code now includes a workaround for a non-spec incompatibility for the current ejabberd PEP implementation, and doesn't use the correct namespace due to Psi using the wrong one (outdated?). Works fine though, and the vcard-based approach is retained.
Andreas Monitzer <am@adiumx.com>
parents:
17787
diff
changeset
|
1173 | metadata = xmlnode_get_child_with_namespace(item, "metadata", AVATARNAMESPACEMETA); |
|
e6e381b0c7d6
Implemented receiving other people's avatars via XEP-0084. Note that this code now includes a workaround for a non-spec incompatibility for the current ejabberd PEP implementation, and doesn't use the correct namespace due to Psi using the wrong one (outdated?). Works fine though, and the vcard-based approach is retained.
Andreas Monitzer <am@adiumx.com>
parents:
17787
diff
changeset
|
1174 | if(!metadata) |
|
e6e381b0c7d6
Implemented receiving other people's avatars via XEP-0084. Note that this code now includes a workaround for a non-spec incompatibility for the current ejabberd PEP implementation, and doesn't use the correct namespace due to Psi using the wrong one (outdated?). Works fine though, and the vcard-based approach is retained.
Andreas Monitzer <am@adiumx.com>
parents:
17787
diff
changeset
|
1175 | return; |
|
e6e381b0c7d6
Implemented receiving other people's avatars via XEP-0084. Note that this code now includes a workaround for a non-spec incompatibility for the current ejabberd PEP implementation, and doesn't use the correct namespace due to Psi using the wrong one (outdated?). Works fine though, and the vcard-based approach is retained.
Andreas Monitzer <am@adiumx.com>
parents:
17787
diff
changeset
|
1176 | /* check if we have received a stop */ |
|
e6e381b0c7d6
Implemented receiving other people's avatars via XEP-0084. Note that this code now includes a workaround for a non-spec incompatibility for the current ejabberd PEP implementation, and doesn't use the correct namespace due to Psi using the wrong one (outdated?). Works fine though, and the vcard-based approach is retained.
Andreas Monitzer <am@adiumx.com>
parents:
17787
diff
changeset
|
1177 | if(xmlnode_get_child(metadata, "stop")) { |
|
e6e381b0c7d6
Implemented receiving other people's avatars via XEP-0084. Note that this code now includes a workaround for a non-spec incompatibility for the current ejabberd PEP implementation, and doesn't use the correct namespace due to Psi using the wrong one (outdated?). Works fine though, and the vcard-based approach is retained.
Andreas Monitzer <am@adiumx.com>
parents:
17787
diff
changeset
|
1178 | purple_buddy_icons_set_for_user(purple_connection_get_account(js->gc), from, NULL, 0, NULL); |
|
e6e381b0c7d6
Implemented receiving other people's avatars via XEP-0084. Note that this code now includes a workaround for a non-spec incompatibility for the current ejabberd PEP implementation, and doesn't use the correct namespace due to Psi using the wrong one (outdated?). Works fine though, and the vcard-based approach is retained.
Andreas Monitzer <am@adiumx.com>
parents:
17787
diff
changeset
|
1179 | } else { |
|
e6e381b0c7d6
Implemented receiving other people's avatars via XEP-0084. Note that this code now includes a workaround for a non-spec incompatibility for the current ejabberd PEP implementation, and doesn't use the correct namespace due to Psi using the wrong one (outdated?). Works fine though, and the vcard-based approach is retained.
Andreas Monitzer <am@adiumx.com>
parents:
17787
diff
changeset
|
1180 | xmlnode *info, *goodinfo = NULL; |
|
e6e381b0c7d6
Implemented receiving other people's avatars via XEP-0084. Note that this code now includes a workaround for a non-spec incompatibility for the current ejabberd PEP implementation, and doesn't use the correct namespace due to Psi using the wrong one (outdated?). Works fine though, and the vcard-based approach is retained.
Andreas Monitzer <am@adiumx.com>
parents:
17787
diff
changeset
|
1181 | |
|
e6e381b0c7d6
Implemented receiving other people's avatars via XEP-0084. Note that this code now includes a workaround for a non-spec incompatibility for the current ejabberd PEP implementation, and doesn't use the correct namespace due to Psi using the wrong one (outdated?). Works fine though, and the vcard-based approach is retained.
Andreas Monitzer <am@adiumx.com>
parents:
17787
diff
changeset
|
1182 | /* iterate over all info nodes to get one we can use */ |
|
e6e381b0c7d6
Implemented receiving other people's avatars via XEP-0084. Note that this code now includes a workaround for a non-spec incompatibility for the current ejabberd PEP implementation, and doesn't use the correct namespace due to Psi using the wrong one (outdated?). Works fine though, and the vcard-based approach is retained.
Andreas Monitzer <am@adiumx.com>
parents:
17787
diff
changeset
|
1183 | for(info = metadata->child; info; info = info->next) { |
|
e6e381b0c7d6
Implemented receiving other people's avatars via XEP-0084. Note that this code now includes a workaround for a non-spec incompatibility for the current ejabberd PEP implementation, and doesn't use the correct namespace due to Psi using the wrong one (outdated?). Works fine though, and the vcard-based approach is retained.
Andreas Monitzer <am@adiumx.com>
parents:
17787
diff
changeset
|
1184 | if(info->type == XMLNODE_TYPE_TAG && !strcmp(info->name,"info")) { |
|
e6e381b0c7d6
Implemented receiving other people's avatars via XEP-0084. Note that this code now includes a workaround for a non-spec incompatibility for the current ejabberd PEP implementation, and doesn't use the correct namespace due to Psi using the wrong one (outdated?). Works fine though, and the vcard-based approach is retained.
Andreas Monitzer <am@adiumx.com>
parents:
17787
diff
changeset
|
1185 | const char *type = xmlnode_get_attrib(info,"type"); |
|
e6e381b0c7d6
Implemented receiving other people's avatars via XEP-0084. Note that this code now includes a workaround for a non-spec incompatibility for the current ejabberd PEP implementation, and doesn't use the correct namespace due to Psi using the wrong one (outdated?). Works fine though, and the vcard-based approach is retained.
Andreas Monitzer <am@adiumx.com>
parents:
17787
diff
changeset
|
1186 | const char *id = xmlnode_get_attrib(info,"id"); |
|
e6e381b0c7d6
Implemented receiving other people's avatars via XEP-0084. Note that this code now includes a workaround for a non-spec incompatibility for the current ejabberd PEP implementation, and doesn't use the correct namespace due to Psi using the wrong one (outdated?). Works fine though, and the vcard-based approach is retained.
Andreas Monitzer <am@adiumx.com>
parents:
17787
diff
changeset
|
1187 | |
|
e6e381b0c7d6
Implemented receiving other people's avatars via XEP-0084. Note that this code now includes a workaround for a non-spec incompatibility for the current ejabberd PEP implementation, and doesn't use the correct namespace due to Psi using the wrong one (outdated?). Works fine though, and the vcard-based approach is retained.
Andreas Monitzer <am@adiumx.com>
parents:
17787
diff
changeset
|
1188 | if(checksum && id && !strcmp(id, checksum)) { |
|
e6e381b0c7d6
Implemented receiving other people's avatars via XEP-0084. Note that this code now includes a workaround for a non-spec incompatibility for the current ejabberd PEP implementation, and doesn't use the correct namespace due to Psi using the wrong one (outdated?). Works fine though, and the vcard-based approach is retained.
Andreas Monitzer <am@adiumx.com>
parents:
17787
diff
changeset
|
1189 | /* we already have that avatar, so we don't have to do anything */ |
|
e6e381b0c7d6
Implemented receiving other people's avatars via XEP-0084. Note that this code now includes a workaround for a non-spec incompatibility for the current ejabberd PEP implementation, and doesn't use the correct namespace due to Psi using the wrong one (outdated?). Works fine though, and the vcard-based approach is retained.
Andreas Monitzer <am@adiumx.com>
parents:
17787
diff
changeset
|
1190 | goodinfo = NULL; |
|
e6e381b0c7d6
Implemented receiving other people's avatars via XEP-0084. Note that this code now includes a workaround for a non-spec incompatibility for the current ejabberd PEP implementation, and doesn't use the correct namespace due to Psi using the wrong one (outdated?). Works fine though, and the vcard-based approach is retained.
Andreas Monitzer <am@adiumx.com>
parents:
17787
diff
changeset
|
1191 | break; |
|
e6e381b0c7d6
Implemented receiving other people's avatars via XEP-0084. Note that this code now includes a workaround for a non-spec incompatibility for the current ejabberd PEP implementation, and doesn't use the correct namespace due to Psi using the wrong one (outdated?). Works fine though, and the vcard-based approach is retained.
Andreas Monitzer <am@adiumx.com>
parents:
17787
diff
changeset
|
1192 | } |
|
e6e381b0c7d6
Implemented receiving other people's avatars via XEP-0084. Note that this code now includes a workaround for a non-spec incompatibility for the current ejabberd PEP implementation, and doesn't use the correct namespace due to Psi using the wrong one (outdated?). Works fine though, and the vcard-based approach is retained.
Andreas Monitzer <am@adiumx.com>
parents:
17787
diff
changeset
|
1193 | /* We'll only pick the png one for now. It's a very nice image format anyways. */ |
|
e6e381b0c7d6
Implemented receiving other people's avatars via XEP-0084. Note that this code now includes a workaround for a non-spec incompatibility for the current ejabberd PEP implementation, and doesn't use the correct namespace due to Psi using the wrong one (outdated?). Works fine though, and the vcard-based approach is retained.
Andreas Monitzer <am@adiumx.com>
parents:
17787
diff
changeset
|
1194 | if(type && id && !goodinfo && !strcmp(type, "image/png")) |
|
e6e381b0c7d6
Implemented receiving other people's avatars via XEP-0084. Note that this code now includes a workaround for a non-spec incompatibility for the current ejabberd PEP implementation, and doesn't use the correct namespace due to Psi using the wrong one (outdated?). Works fine though, and the vcard-based approach is retained.
Andreas Monitzer <am@adiumx.com>
parents:
17787
diff
changeset
|
1195 | goodinfo = info; |
|
e6e381b0c7d6
Implemented receiving other people's avatars via XEP-0084. Note that this code now includes a workaround for a non-spec incompatibility for the current ejabberd PEP implementation, and doesn't use the correct namespace due to Psi using the wrong one (outdated?). Works fine though, and the vcard-based approach is retained.
Andreas Monitzer <am@adiumx.com>
parents:
17787
diff
changeset
|
1196 | } |
|
e6e381b0c7d6
Implemented receiving other people's avatars via XEP-0084. Note that this code now includes a workaround for a non-spec incompatibility for the current ejabberd PEP implementation, and doesn't use the correct namespace due to Psi using the wrong one (outdated?). Works fine though, and the vcard-based approach is retained.
Andreas Monitzer <am@adiumx.com>
parents:
17787
diff
changeset
|
1197 | } |
|
e6e381b0c7d6
Implemented receiving other people's avatars via XEP-0084. Note that this code now includes a workaround for a non-spec incompatibility for the current ejabberd PEP implementation, and doesn't use the correct namespace due to Psi using the wrong one (outdated?). Works fine though, and the vcard-based approach is retained.
Andreas Monitzer <am@adiumx.com>
parents:
17787
diff
changeset
|
1198 | if(goodinfo) { |
|
e6e381b0c7d6
Implemented receiving other people's avatars via XEP-0084. Note that this code now includes a workaround for a non-spec incompatibility for the current ejabberd PEP implementation, and doesn't use the correct namespace due to Psi using the wrong one (outdated?). Works fine though, and the vcard-based approach is retained.
Andreas Monitzer <am@adiumx.com>
parents:
17787
diff
changeset
|
1199 | const char *url = xmlnode_get_attrib(goodinfo,"url"); |
|
e6e381b0c7d6
Implemented receiving other people's avatars via XEP-0084. Note that this code now includes a workaround for a non-spec incompatibility for the current ejabberd PEP implementation, and doesn't use the correct namespace due to Psi using the wrong one (outdated?). Works fine though, and the vcard-based approach is retained.
Andreas Monitzer <am@adiumx.com>
parents:
17787
diff
changeset
|
1200 | const char *id = xmlnode_get_attrib(goodinfo,"id"); |
|
e6e381b0c7d6
Implemented receiving other people's avatars via XEP-0084. Note that this code now includes a workaround for a non-spec incompatibility for the current ejabberd PEP implementation, and doesn't use the correct namespace due to Psi using the wrong one (outdated?). Works fine though, and the vcard-based approach is retained.
Andreas Monitzer <am@adiumx.com>
parents:
17787
diff
changeset
|
1201 | |
|
e6e381b0c7d6
Implemented receiving other people's avatars via XEP-0084. Note that this code now includes a workaround for a non-spec incompatibility for the current ejabberd PEP implementation, and doesn't use the correct namespace due to Psi using the wrong one (outdated?). Works fine though, and the vcard-based approach is retained.
Andreas Monitzer <am@adiumx.com>
parents:
17787
diff
changeset
|
1202 | /* the avatar might either be stored in a pep node, or on a HTTP/HTTPS URL */ |
|
e6e381b0c7d6
Implemented receiving other people's avatars via XEP-0084. Note that this code now includes a workaround for a non-spec incompatibility for the current ejabberd PEP implementation, and doesn't use the correct namespace due to Psi using the wrong one (outdated?). Works fine though, and the vcard-based approach is retained.
Andreas Monitzer <am@adiumx.com>
parents:
17787
diff
changeset
|
1203 | if(!url) |
|
e6e381b0c7d6
Implemented receiving other people's avatars via XEP-0084. Note that this code now includes a workaround for a non-spec incompatibility for the current ejabberd PEP implementation, and doesn't use the correct namespace due to Psi using the wrong one (outdated?). Works fine though, and the vcard-based approach is retained.
Andreas Monitzer <am@adiumx.com>
parents:
17787
diff
changeset
|
1204 | jabber_pep_request_item(js, from, AVATARNAMESPACEDATA, id, do_buddy_avatar_update_data); |
|
e6e381b0c7d6
Implemented receiving other people's avatars via XEP-0084. Note that this code now includes a workaround for a non-spec incompatibility for the current ejabberd PEP implementation, and doesn't use the correct namespace due to Psi using the wrong one (outdated?). Works fine though, and the vcard-based approach is retained.
Andreas Monitzer <am@adiumx.com>
parents:
17787
diff
changeset
|
1205 | else { |
|
e6e381b0c7d6
Implemented receiving other people's avatars via XEP-0084. Note that this code now includes a workaround for a non-spec incompatibility for the current ejabberd PEP implementation, and doesn't use the correct namespace due to Psi using the wrong one (outdated?). Works fine though, and the vcard-based approach is retained.
Andreas Monitzer <am@adiumx.com>
parents:
17787
diff
changeset
|
1206 | JabberBuddyAvatarUpdateURLInfo *info = g_new0(JabberBuddyAvatarUpdateURLInfo, 1); |
|
e6e381b0c7d6
Implemented receiving other people's avatars via XEP-0084. Note that this code now includes a workaround for a non-spec incompatibility for the current ejabberd PEP implementation, and doesn't use the correct namespace due to Psi using the wrong one (outdated?). Works fine though, and the vcard-based approach is retained.
Andreas Monitzer <am@adiumx.com>
parents:
17787
diff
changeset
|
1207 | info->js = js; |
|
e6e381b0c7d6
Implemented receiving other people's avatars via XEP-0084. Note that this code now includes a workaround for a non-spec incompatibility for the current ejabberd PEP implementation, and doesn't use the correct namespace due to Psi using the wrong one (outdated?). Works fine though, and the vcard-based approach is retained.
Andreas Monitzer <am@adiumx.com>
parents:
17787
diff
changeset
|
1208 | info->from = g_strdup(from); |
|
e6e381b0c7d6
Implemented receiving other people's avatars via XEP-0084. Note that this code now includes a workaround for a non-spec incompatibility for the current ejabberd PEP implementation, and doesn't use the correct namespace due to Psi using the wrong one (outdated?). Works fine though, and the vcard-based approach is retained.
Andreas Monitzer <am@adiumx.com>
parents:
17787
diff
changeset
|
1209 | info->id = g_strdup(id); |
|
e6e381b0c7d6
Implemented receiving other people's avatars via XEP-0084. Note that this code now includes a workaround for a non-spec incompatibility for the current ejabberd PEP implementation, and doesn't use the correct namespace due to Psi using the wrong one (outdated?). Works fine though, and the vcard-based approach is retained.
Andreas Monitzer <am@adiumx.com>
parents:
17787
diff
changeset
|
1210 | purple_util_fetch_url(url, TRUE, NULL, TRUE, do_buddy_avatar_update_fromurl, info); |
|
e6e381b0c7d6
Implemented receiving other people's avatars via XEP-0084. Note that this code now includes a workaround for a non-spec incompatibility for the current ejabberd PEP implementation, and doesn't use the correct namespace due to Psi using the wrong one (outdated?). Works fine though, and the vcard-based approach is retained.
Andreas Monitzer <am@adiumx.com>
parents:
17787
diff
changeset
|
1211 | } |
|
e6e381b0c7d6
Implemented receiving other people's avatars via XEP-0084. Note that this code now includes a workaround for a non-spec incompatibility for the current ejabberd PEP implementation, and doesn't use the correct namespace due to Psi using the wrong one (outdated?). Works fine though, and the vcard-based approach is retained.
Andreas Monitzer <am@adiumx.com>
parents:
17787
diff
changeset
|
1212 | } |
|
e6e381b0c7d6
Implemented receiving other people's avatars via XEP-0084. Note that this code now includes a workaround for a non-spec incompatibility for the current ejabberd PEP implementation, and doesn't use the correct namespace due to Psi using the wrong one (outdated?). Works fine though, and the vcard-based approach is retained.
Andreas Monitzer <am@adiumx.com>
parents:
17787
diff
changeset
|
1213 | } |
|
17787
439329d20337
Added support for setting the avatar via XEP-0084. Receiving other people's avatar is up next.
Andreas Monitzer <am@adiumx.com>
parents:
17770
diff
changeset
|
1214 | } |
| 8213 | 1215 | |
| 13794 | 1216 | static void jabber_buddy_info_resource_free(gpointer data) |
| 1217 | { | |
| 1218 | JabberBuddyInfoResource *jbri = data; | |
| 1219 | g_free(jbri); | |
| 1220 | } | |
| 1221 | ||
| 1222 | static void jabber_version_parse(JabberStream *js, xmlnode *packet, gpointer data) | |
| 1223 | { | |
| 1224 | JabberBuddyInfo *jbi = data; | |
| 1225 | const char *type, *id, *from; | |
| 1226 | xmlnode *query; | |
| 1227 | char *resource_name; | |
| 1228 | ||
| 1229 | g_return_if_fail(jbi != NULL); | |
| 1230 | ||
| 1231 | type = xmlnode_get_attrib(packet, "type"); | |
| 1232 | id = xmlnode_get_attrib(packet, "id"); | |
| 1233 | from = xmlnode_get_attrib(packet, "from"); | |
| 7014 | 1234 | |
| 13794 | 1235 | jabber_buddy_info_remove_id(jbi, id); |
| 1236 | ||
| 1237 | if(!from) | |
| 1238 | return; | |
| 1239 | ||
| 1240 | resource_name = jabber_get_resource(from); | |
| 1241 | ||
| 1242 | if(resource_name) { | |
| 1243 | if(type && !strcmp(type, "result")) { | |
| 1244 | if((query = xmlnode_get_child(packet, "query"))) { | |
| 1245 | JabberBuddyResource *jbr = jabber_buddy_find_resource(jbi->jb, resource_name); | |
| 1246 | if(jbr) { | |
| 1247 | xmlnode *node; | |
| 1248 | if((node = xmlnode_get_child(query, "name"))) { | |
| 1249 | jbr->client.name = xmlnode_get_data(node); | |
| 1250 | } | |
| 1251 | if((node = xmlnode_get_child(query, "version"))) { | |
| 1252 | jbr->client.version = xmlnode_get_data(node); | |
| 1253 | } | |
| 1254 | if((node = xmlnode_get_child(query, "os"))) { | |
| 1255 | jbr->client.os = xmlnode_get_data(node); | |
| 1256 | } | |
| 1257 | } | |
| 1258 | } | |
| 1259 | } | |
| 1260 | g_free(resource_name); | |
| 10189 | 1261 | } |
| 13794 | 1262 | |
| 1263 | jabber_buddy_info_show_if_ready(jbi); | |
| 7014 | 1264 | } |
| 1265 | ||
| 13794 | 1266 | static void jabber_last_parse(JabberStream *js, xmlnode *packet, gpointer data) |
| 1267 | { | |
| 1268 | JabberBuddyInfo *jbi = data; | |
| 1269 | xmlnode *query; | |
| 1270 | char *resource_name; | |
| 1271 | const char *type, *id, *from, *seconds; | |
| 1272 | ||
| 1273 | g_return_if_fail(jbi != NULL); | |
| 1274 | ||
| 1275 | type = xmlnode_get_attrib(packet, "type"); | |
| 1276 | id = xmlnode_get_attrib(packet, "id"); | |
| 1277 | from = xmlnode_get_attrib(packet, "from"); | |
| 1278 | ||
| 1279 | jabber_buddy_info_remove_id(jbi, id); | |
| 1280 | ||
| 1281 | if(!from) | |
| 1282 | return; | |
| 1283 | ||
| 1284 | resource_name = jabber_get_resource(from); | |
| 1285 | ||
| 1286 | if(resource_name) { | |
| 1287 | if(type && !strcmp(type, "result")) { | |
| 1288 | if((query = xmlnode_get_child(packet, "query"))) { | |
| 1289 | seconds = xmlnode_get_attrib(query, "seconds"); | |
| 1290 | if(seconds) { | |
| 1291 | char *end = NULL; | |
| 1292 | long sec = strtol(seconds, &end, 10); | |
| 1293 | if(end != seconds) { | |
| 1294 | JabberBuddyInfoResource *jbir = g_hash_table_lookup(jbi->resources, resource_name); | |
| 1295 | if(jbir) { | |
| 1296 | jbir->idle_seconds = sec; | |
| 1297 | } | |
| 1298 | } | |
| 1299 | } | |
| 1300 | } | |
| 1301 | } | |
| 1302 | g_free(resource_name); | |
| 1303 | } | |
| 1304 | ||
| 1305 | jabber_buddy_info_show_if_ready(jbi); | |
| 1306 | } | |
| 1307 | ||
|
15363
f6b9d1e3d0cb
[gaim-migrate @ 18092]
Evan Schoenberg <evands@pidgin.im>
parents:
15273
diff
changeset
|
1308 | void jabber_buddy_remove_all_pending_buddy_info_requests(JabberStream *js) |
|
f6b9d1e3d0cb
[gaim-migrate @ 18092]
Evan Schoenberg <evands@pidgin.im>
parents:
15273
diff
changeset
|
1309 | { |
|
f6b9d1e3d0cb
[gaim-migrate @ 18092]
Evan Schoenberg <evands@pidgin.im>
parents:
15273
diff
changeset
|
1310 | if (js->pending_buddy_info_requests) |
|
f6b9d1e3d0cb
[gaim-migrate @ 18092]
Evan Schoenberg <evands@pidgin.im>
parents:
15273
diff
changeset
|
1311 | { |
|
f6b9d1e3d0cb
[gaim-migrate @ 18092]
Evan Schoenberg <evands@pidgin.im>
parents:
15273
diff
changeset
|
1312 | JabberBuddyInfo *jbi; |
|
f6b9d1e3d0cb
[gaim-migrate @ 18092]
Evan Schoenberg <evands@pidgin.im>
parents:
15273
diff
changeset
|
1313 | GSList *l = js->pending_buddy_info_requests; |
|
f6b9d1e3d0cb
[gaim-migrate @ 18092]
Evan Schoenberg <evands@pidgin.im>
parents:
15273
diff
changeset
|
1314 | while (l) { |
|
f6b9d1e3d0cb
[gaim-migrate @ 18092]
Evan Schoenberg <evands@pidgin.im>
parents:
15273
diff
changeset
|
1315 | jbi = l->data; |
|
f6b9d1e3d0cb
[gaim-migrate @ 18092]
Evan Schoenberg <evands@pidgin.im>
parents:
15273
diff
changeset
|
1316 | |
|
f6b9d1e3d0cb
[gaim-migrate @ 18092]
Evan Schoenberg <evands@pidgin.im>
parents:
15273
diff
changeset
|
1317 | g_slist_free(jbi->ids); |
|
f6b9d1e3d0cb
[gaim-migrate @ 18092]
Evan Schoenberg <evands@pidgin.im>
parents:
15273
diff
changeset
|
1318 | jabber_buddy_info_destroy(jbi); |
|
f6b9d1e3d0cb
[gaim-migrate @ 18092]
Evan Schoenberg <evands@pidgin.im>
parents:
15273
diff
changeset
|
1319 | |
|
15727
0754583ceeae
Don't access the list element after it has been freed.
Daniel Atallah <datallah@pidgin.im>
parents:
15688
diff
changeset
|
1320 | l = l->next; |
|
15363
f6b9d1e3d0cb
[gaim-migrate @ 18092]
Evan Schoenberg <evands@pidgin.im>
parents:
15273
diff
changeset
|
1321 | } |
|
f6b9d1e3d0cb
[gaim-migrate @ 18092]
Evan Schoenberg <evands@pidgin.im>
parents:
15273
diff
changeset
|
1322 | |
|
f6b9d1e3d0cb
[gaim-migrate @ 18092]
Evan Schoenberg <evands@pidgin.im>
parents:
15273
diff
changeset
|
1323 | g_slist_free(js->pending_buddy_info_requests); |
|
f6b9d1e3d0cb
[gaim-migrate @ 18092]
Evan Schoenberg <evands@pidgin.im>
parents:
15273
diff
changeset
|
1324 | js->pending_buddy_info_requests = NULL; |
|
f6b9d1e3d0cb
[gaim-migrate @ 18092]
Evan Schoenberg <evands@pidgin.im>
parents:
15273
diff
changeset
|
1325 | } |
|
f6b9d1e3d0cb
[gaim-migrate @ 18092]
Evan Schoenberg <evands@pidgin.im>
parents:
15273
diff
changeset
|
1326 | } |
|
f6b9d1e3d0cb
[gaim-migrate @ 18092]
Evan Schoenberg <evands@pidgin.im>
parents:
15273
diff
changeset
|
1327 | |
| 13794 | 1328 | static gboolean jabber_buddy_get_info_timeout(gpointer data) |
| 1329 | { | |
| 1330 | JabberBuddyInfo *jbi = data; | |
| 1331 | ||
| 1332 | /* remove the pending callbacks */ | |
| 1333 | while(jbi->ids) { | |
| 1334 | char *id = jbi->ids->data; | |
| 1335 | jabber_iq_remove_callback_by_id(jbi->js, id); | |
|
15363
f6b9d1e3d0cb
[gaim-migrate @ 18092]
Evan Schoenberg <evands@pidgin.im>
parents:
15273
diff
changeset
|
1336 | jbi->ids = g_slist_remove(jbi->ids, id); |
| 13794 | 1337 | g_free(id); |
| 1338 | } | |
| 1339 | ||
|
15363
f6b9d1e3d0cb
[gaim-migrate @ 18092]
Evan Schoenberg <evands@pidgin.im>
parents:
15273
diff
changeset
|
1340 | jbi->js->pending_buddy_info_requests = g_slist_remove(jbi->js->pending_buddy_info_requests, jbi); |
| 13794 | 1341 | jbi->timeout_handle = 0; |
| 1342 | ||
| 1343 | jabber_buddy_info_show_if_ready(jbi); | |
| 1344 | ||
| 1345 | return FALSE; | |
| 1346 | } | |
| 1347 | ||
|
17029
dea59a003028
gross hack that will save me time in 30 second chunks
Nathan Walp <nwalp@pidgin.im>
parents:
17007
diff
changeset
|
1348 | static gboolean _client_is_blacklisted(JabberBuddyResource *jbr, const char *ns) |
|
dea59a003028
gross hack that will save me time in 30 second chunks
Nathan Walp <nwalp@pidgin.im>
parents:
17007
diff
changeset
|
1349 | { |
|
dea59a003028
gross hack that will save me time in 30 second chunks
Nathan Walp <nwalp@pidgin.im>
parents:
17007
diff
changeset
|
1350 | /* can't be blacklisted if we don't know what you're running yet */ |
|
dea59a003028
gross hack that will save me time in 30 second chunks
Nathan Walp <nwalp@pidgin.im>
parents:
17007
diff
changeset
|
1351 | if(!jbr->client.name) |
|
dea59a003028
gross hack that will save me time in 30 second chunks
Nathan Walp <nwalp@pidgin.im>
parents:
17007
diff
changeset
|
1352 | return FALSE; |
|
dea59a003028
gross hack that will save me time in 30 second chunks
Nathan Walp <nwalp@pidgin.im>
parents:
17007
diff
changeset
|
1353 | |
|
dea59a003028
gross hack that will save me time in 30 second chunks
Nathan Walp <nwalp@pidgin.im>
parents:
17007
diff
changeset
|
1354 | if(!strcmp(ns, "jabber:iq:last")) { |
|
dea59a003028
gross hack that will save me time in 30 second chunks
Nathan Walp <nwalp@pidgin.im>
parents:
17007
diff
changeset
|
1355 | if(!strcmp(jbr->client.name, "Trillian")) { |
|
dea59a003028
gross hack that will save me time in 30 second chunks
Nathan Walp <nwalp@pidgin.im>
parents:
17007
diff
changeset
|
1356 | if(!strcmp(jbr->client.version, "3.1.0.121")) { |
|
dea59a003028
gross hack that will save me time in 30 second chunks
Nathan Walp <nwalp@pidgin.im>
parents:
17007
diff
changeset
|
1357 | /* verified by nwalp 2007/05/09 */ |
|
dea59a003028
gross hack that will save me time in 30 second chunks
Nathan Walp <nwalp@pidgin.im>
parents:
17007
diff
changeset
|
1358 | return TRUE; |
|
dea59a003028
gross hack that will save me time in 30 second chunks
Nathan Walp <nwalp@pidgin.im>
parents:
17007
diff
changeset
|
1359 | } |
|
dea59a003028
gross hack that will save me time in 30 second chunks
Nathan Walp <nwalp@pidgin.im>
parents:
17007
diff
changeset
|
1360 | } |
|
dea59a003028
gross hack that will save me time in 30 second chunks
Nathan Walp <nwalp@pidgin.im>
parents:
17007
diff
changeset
|
1361 | } |
|
dea59a003028
gross hack that will save me time in 30 second chunks
Nathan Walp <nwalp@pidgin.im>
parents:
17007
diff
changeset
|
1362 | |
|
dea59a003028
gross hack that will save me time in 30 second chunks
Nathan Walp <nwalp@pidgin.im>
parents:
17007
diff
changeset
|
1363 | return FALSE; |
|
dea59a003028
gross hack that will save me time in 30 second chunks
Nathan Walp <nwalp@pidgin.im>
parents:
17007
diff
changeset
|
1364 | } |
|
dea59a003028
gross hack that will save me time in 30 second chunks
Nathan Walp <nwalp@pidgin.im>
parents:
17007
diff
changeset
|
1365 | |
| 13794 | 1366 | static void jabber_buddy_get_info_for_jid(JabberStream *js, const char *jid) |
| 7014 | 1367 | { |
| 1368 | JabberIq *iq; | |
| 1369 | xmlnode *vcard; | |
| 13794 | 1370 | GList *resources; |
| 1371 | JabberBuddy *jb; | |
| 1372 | JabberBuddyInfo *jbi; | |
| 1373 | ||
| 1374 | jb = jabber_buddy_find(js, jid, TRUE); | |
| 1375 | ||
| 1376 | /* invalid JID */ | |
| 1377 | if(!jb) | |
| 1378 | return; | |
| 1379 | ||
| 1380 | jbi = g_new0(JabberBuddyInfo, 1); | |
| 1381 | jbi->jid = g_strdup(jid); | |
| 1382 | jbi->js = js; | |
| 1383 | jbi->jb = jb; | |
| 1384 | jbi->resources = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, jabber_buddy_info_resource_free); | |
| 7014 | 1385 | |
| 1386 | iq = jabber_iq_new(js, JABBER_IQ_GET); | |
| 1387 | ||
| 13794 | 1388 | xmlnode_set_attrib(iq->node, "to", jid); |
| 7014 | 1389 | vcard = xmlnode_new_child(iq->node, "vCard"); |
| 13808 | 1390 | xmlnode_set_namespace(vcard, "vcard-temp"); |
| 7014 | 1391 | |
| 13794 | 1392 | jabber_iq_set_callback(iq, jabber_vcard_parse, jbi); |
| 1393 | jbi->ids = g_slist_prepend(jbi->ids, g_strdup(iq->id)); | |
| 7014 | 1394 | |
| 1395 | jabber_iq_send(iq); | |
| 13794 | 1396 | |
| 1397 | for(resources = jb->resources; resources; resources = resources->next) | |
| 1398 | { | |
| 1399 | JabberBuddyResource *jbr = resources->data; | |
|
14164
d85f44e1fec1
[gaim-migrate @ 16732]
Mark Doliner <markdoliner@pidgin.im>
parents:
14155
diff
changeset
|
1400 | JabberBuddyInfoResource *jbir; |
| 13794 | 1401 | char *full_jid; |
|
14164
d85f44e1fec1
[gaim-migrate @ 16732]
Mark Doliner <markdoliner@pidgin.im>
parents:
14155
diff
changeset
|
1402 | |
|
d85f44e1fec1
[gaim-migrate @ 16732]
Mark Doliner <markdoliner@pidgin.im>
parents:
14155
diff
changeset
|
1403 | if ((strchr(jid, '/') == NULL) && (jbr->name != NULL)) { |
|
d85f44e1fec1
[gaim-migrate @ 16732]
Mark Doliner <markdoliner@pidgin.im>
parents:
14155
diff
changeset
|
1404 | full_jid = g_strdup_printf("%s/%s", jid, jbr->name); |
|
d85f44e1fec1
[gaim-migrate @ 16732]
Mark Doliner <markdoliner@pidgin.im>
parents:
14155
diff
changeset
|
1405 | } else { |
| 13794 | 1406 | full_jid = g_strdup(jid); |
| 1407 | } | |
| 1408 | ||
|
14164
d85f44e1fec1
[gaim-migrate @ 16732]
Mark Doliner <markdoliner@pidgin.im>
parents:
14155
diff
changeset
|
1409 | if (jbr->name != NULL) |
|
d85f44e1fec1
[gaim-migrate @ 16732]
Mark Doliner <markdoliner@pidgin.im>
parents:
14155
diff
changeset
|
1410 | { |
|
d85f44e1fec1
[gaim-migrate @ 16732]
Mark Doliner <markdoliner@pidgin.im>
parents:
14155
diff
changeset
|
1411 | jbir = g_new0(JabberBuddyInfoResource, 1); |
|
d85f44e1fec1
[gaim-migrate @ 16732]
Mark Doliner <markdoliner@pidgin.im>
parents:
14155
diff
changeset
|
1412 | g_hash_table_insert(jbi->resources, g_strdup(jbr->name), jbir); |
|
d85f44e1fec1
[gaim-migrate @ 16732]
Mark Doliner <markdoliner@pidgin.im>
parents:
14155
diff
changeset
|
1413 | } |
| 13794 | 1414 | |
| 1415 | if(!jbr->client.name) { | |
| 1416 | iq = jabber_iq_new_query(js, JABBER_IQ_GET, "jabber:iq:version"); | |
| 1417 | xmlnode_set_attrib(iq->node, "to", full_jid); | |
| 1418 | jabber_iq_set_callback(iq, jabber_version_parse, jbi); | |
| 1419 | jbi->ids = g_slist_prepend(jbi->ids, g_strdup(iq->id)); | |
| 1420 | jabber_iq_send(iq); | |
| 1421 | } | |
| 1422 | ||
|
17029
dea59a003028
gross hack that will save me time in 30 second chunks
Nathan Walp <nwalp@pidgin.im>
parents:
17007
diff
changeset
|
1423 | /* this is to fix the feeling of irritation I get when trying |
|
dea59a003028
gross hack that will save me time in 30 second chunks
Nathan Walp <nwalp@pidgin.im>
parents:
17007
diff
changeset
|
1424 | * to get info on a friend running Trillian, which doesn't |
| 17051 | 1425 | * respond (with an error or otherwise) to jabber:iq:last |
|
17029
dea59a003028
gross hack that will save me time in 30 second chunks
Nathan Walp <nwalp@pidgin.im>
parents:
17007
diff
changeset
|
1426 | * requests. There are a number of Trillian users in my |
|
dea59a003028
gross hack that will save me time in 30 second chunks
Nathan Walp <nwalp@pidgin.im>
parents:
17007
diff
changeset
|
1427 | * office. */ |
|
dea59a003028
gross hack that will save me time in 30 second chunks
Nathan Walp <nwalp@pidgin.im>
parents:
17007
diff
changeset
|
1428 | if(!_client_is_blacklisted(jbr, "jabber:iq:last")) { |
|
dea59a003028
gross hack that will save me time in 30 second chunks
Nathan Walp <nwalp@pidgin.im>
parents:
17007
diff
changeset
|
1429 | iq = jabber_iq_new_query(js, JABBER_IQ_GET, "jabber:iq:last"); |
|
dea59a003028
gross hack that will save me time in 30 second chunks
Nathan Walp <nwalp@pidgin.im>
parents:
17007
diff
changeset
|
1430 | xmlnode_set_attrib(iq->node, "to", full_jid); |
|
dea59a003028
gross hack that will save me time in 30 second chunks
Nathan Walp <nwalp@pidgin.im>
parents:
17007
diff
changeset
|
1431 | jabber_iq_set_callback(iq, jabber_last_parse, jbi); |
|
dea59a003028
gross hack that will save me time in 30 second chunks
Nathan Walp <nwalp@pidgin.im>
parents:
17007
diff
changeset
|
1432 | jbi->ids = g_slist_prepend(jbi->ids, g_strdup(iq->id)); |
|
dea59a003028
gross hack that will save me time in 30 second chunks
Nathan Walp <nwalp@pidgin.im>
parents:
17007
diff
changeset
|
1433 | jabber_iq_send(iq); |
|
dea59a003028
gross hack that will save me time in 30 second chunks
Nathan Walp <nwalp@pidgin.im>
parents:
17007
diff
changeset
|
1434 | } |
| 13794 | 1435 | |
| 1436 | g_free(full_jid); | |
| 1437 | } | |
| 1438 | ||
|
15363
f6b9d1e3d0cb
[gaim-migrate @ 18092]
Evan Schoenberg <evands@pidgin.im>
parents:
15273
diff
changeset
|
1439 | js->pending_buddy_info_requests = g_slist_prepend(js->pending_buddy_info_requests, jbi); |
| 15884 | 1440 | jbi->timeout_handle = purple_timeout_add(30000, jabber_buddy_get_info_timeout, jbi); |
| 7014 | 1441 | } |
| 1442 | ||
| 15884 | 1443 | void jabber_buddy_get_info(PurpleConnection *gc, const char *who) |
| 10189 | 1444 | { |
| 1445 | JabberStream *js = gc->proto_data; | |
| 1446 | char *bare_jid = jabber_get_bare_jid(who); | |
| 1447 | ||
| 1448 | if(bare_jid) { | |
| 1449 | jabber_buddy_get_info_for_jid(js, bare_jid); | |
| 1450 | g_free(bare_jid); | |
| 1451 | } | |
| 1452 | } | |
| 1453 | ||
| 15884 | 1454 | void jabber_buddy_get_info_chat(PurpleConnection *gc, int id, |
| 7014 | 1455 | const char *resource) |
| 1456 | { | |
| 1457 | JabberStream *js = gc->proto_data; | |
| 1458 | JabberChat *chat = jabber_chat_find_by_id(js, id); | |
| 1459 | char *full_jid; | |
| 1460 | ||
| 1461 | if(!chat) | |
| 1462 | return; | |
| 1463 | ||
| 1464 | full_jid = g_strdup_printf("%s@%s/%s", chat->room, chat->server, resource); | |
| 10189 | 1465 | jabber_buddy_get_info_for_jid(js, full_jid); |
| 7014 | 1466 | g_free(full_jid); |
| 1467 | } | |
| 1468 | ||
| 7395 | 1469 | |
| 7014 | 1470 | static void jabber_buddy_set_invisibility(JabberStream *js, const char *who, |
| 1471 | gboolean invisible) | |
| 1472 | { | |
| 15884 | 1473 | PurplePresence *gpresence; |
| 1474 | PurpleAccount *account; | |
| 1475 | PurpleStatus *status; | |
| 7014 | 1476 | JabberBuddy *jb = jabber_buddy_find(js, who, TRUE); |
| 1477 | xmlnode *presence; | |
| 9954 | 1478 | JabberBuddyState state; |
| 14525 | 1479 | char *msg; |
| 9954 | 1480 | int priority; |
| 7014 | 1481 | |
| 15884 | 1482 | account = purple_connection_get_account(js->gc); |
| 1483 | gpresence = purple_account_get_presence(account); | |
| 1484 | status = purple_presence_get_active_status(gpresence); | |
|
9944
71ef020ec4b0
[gaim-migrate @ 10838]
Christian Hammond <chipx86@chipx86.com>
parents:
9797
diff
changeset
|
1485 | |
| 15884 | 1486 | purple_status_to_jabber(status, &state, &msg, &priority); |
|
17770
e67998927a3c
Added the ability to define extensions to caps
Andreas Monitzer <am@adiumx.com>
parents:
17051
diff
changeset
|
1487 | presence = jabber_presence_create_js(js, state, msg, priority); |
| 9954 | 1488 | |
| 14525 | 1489 | g_free(msg); |
| 1490 | ||
| 7014 | 1491 | xmlnode_set_attrib(presence, "to", who); |
| 1492 | if(invisible) { | |
| 1493 | xmlnode_set_attrib(presence, "type", "invisible"); | |
| 1494 | jb->invisible |= JABBER_INVIS_BUDDY; | |
| 1495 | } else { | |
| 1496 | jb->invisible &= ~JABBER_INVIS_BUDDY; | |
| 1497 | } | |
| 1498 | ||
| 1499 | jabber_send(js, presence); | |
| 1500 | xmlnode_free(presence); | |
| 1501 | } | |
| 1502 | ||
| 15884 | 1503 | static void jabber_buddy_make_invisible(PurpleBlistNode *node, gpointer data) |
| 7014 | 1504 | { |
| 15884 | 1505 | PurpleBuddy *buddy; |
| 1506 | PurpleConnection *gc; | |
|
9030
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
9015
diff
changeset
|
1507 | JabberStream *js; |
|
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
9015
diff
changeset
|
1508 | |
| 15884 | 1509 | g_return_if_fail(PURPLE_BLIST_NODE_IS_BUDDY(node)); |
|
9030
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
9015
diff
changeset
|
1510 | |
| 15884 | 1511 | buddy = (PurpleBuddy *) node; |
| 1512 | gc = purple_account_get_connection(buddy->account); | |
|
9030
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
9015
diff
changeset
|
1513 | js = gc->proto_data; |
|
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
9015
diff
changeset
|
1514 | |
|
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
9015
diff
changeset
|
1515 | jabber_buddy_set_invisibility(js, buddy->name, TRUE); |
| 7014 | 1516 | } |
| 1517 | ||
| 15884 | 1518 | static void jabber_buddy_make_visible(PurpleBlistNode *node, gpointer data) |
| 7014 | 1519 | { |
| 15884 | 1520 | PurpleBuddy *buddy; |
| 1521 | PurpleConnection *gc; | |
|
9030
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
9015
diff
changeset
|
1522 | JabberStream *js; |
| 7014 | 1523 | |
| 15884 | 1524 | g_return_if_fail(PURPLE_BLIST_NODE_IS_BUDDY(node)); |
| 7014 | 1525 | |
| 15884 | 1526 | buddy = (PurpleBuddy *) node; |
| 1527 | gc = purple_account_get_connection(buddy->account); | |
|
9030
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
9015
diff
changeset
|
1528 | js = gc->proto_data; |
|
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
9015
diff
changeset
|
1529 | |
|
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
9015
diff
changeset
|
1530 | jabber_buddy_set_invisibility(js, buddy->name, FALSE); |
| 7014 | 1531 | } |
| 1532 | ||
| 15884 | 1533 | static void jabber_buddy_cancel_presence_notification(PurpleBlistNode *node, |
|
9030
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
9015
diff
changeset
|
1534 | gpointer data) |
| 7014 | 1535 | { |
| 15884 | 1536 | PurpleBuddy *buddy; |
| 1537 | PurpleConnection *gc; | |
|
9030
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
9015
diff
changeset
|
1538 | JabberStream *js; |
|
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
9015
diff
changeset
|
1539 | |
| 15884 | 1540 | g_return_if_fail(PURPLE_BLIST_NODE_IS_BUDDY(node)); |
| 7014 | 1541 | |
| 15884 | 1542 | buddy = (PurpleBuddy *) node; |
| 1543 | gc = purple_account_get_connection(buddy->account); | |
|
9030
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
9015
diff
changeset
|
1544 | js = gc->proto_data; |
|
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
9015
diff
changeset
|
1545 | |
|
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
9015
diff
changeset
|
1546 | /* I wonder if we should prompt the user before doing this */ |
|
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
9015
diff
changeset
|
1547 | jabber_presence_subscription_set(js, buddy->name, "unsubscribed"); |
| 7014 | 1548 | } |
| 1549 | ||
| 15884 | 1550 | static void jabber_buddy_rerequest_auth(PurpleBlistNode *node, gpointer data) |
| 7250 | 1551 | { |
| 15884 | 1552 | PurpleBuddy *buddy; |
| 1553 | PurpleConnection *gc; | |
|
9030
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
9015
diff
changeset
|
1554 | JabberStream *js; |
|
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
9015
diff
changeset
|
1555 | |
| 15884 | 1556 | g_return_if_fail(PURPLE_BLIST_NODE_IS_BUDDY(node)); |
| 7250 | 1557 | |
| 15884 | 1558 | buddy = (PurpleBuddy *) node; |
| 1559 | gc = purple_account_get_connection(buddy->account); | |
|
9030
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
9015
diff
changeset
|
1560 | js = gc->proto_data; |
|
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
9015
diff
changeset
|
1561 | |
|
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
9015
diff
changeset
|
1562 | jabber_presence_subscription_set(js, buddy->name, "subscribe"); |
| 7250 | 1563 | } |
| 1564 | ||
|
9030
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
9015
diff
changeset
|
1565 | |
| 15884 | 1566 | static void jabber_buddy_unsubscribe(PurpleBlistNode *node, gpointer data) |
| 7014 | 1567 | { |
| 15884 | 1568 | PurpleBuddy *buddy; |
| 1569 | PurpleConnection *gc; | |
|
9030
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
9015
diff
changeset
|
1570 | JabberStream *js; |
|
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
9015
diff
changeset
|
1571 | |
| 15884 | 1572 | g_return_if_fail(PURPLE_BLIST_NODE_IS_BUDDY(node)); |
|
9030
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
9015
diff
changeset
|
1573 | |
| 15884 | 1574 | buddy = (PurpleBuddy *) node; |
| 1575 | gc = purple_account_get_connection(buddy->account); | |
|
9030
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
9015
diff
changeset
|
1576 | js = gc->proto_data; |
|
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
9015
diff
changeset
|
1577 | |
|
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
9015
diff
changeset
|
1578 | jabber_presence_subscription_set(js, buddy->name, "unsubscribe"); |
|
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
9015
diff
changeset
|
1579 | } |
|
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
9015
diff
changeset
|
1580 | |
|
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
9015
diff
changeset
|
1581 | |
| 15884 | 1582 | static GList *jabber_buddy_menu(PurpleBuddy *buddy) |
|
9030
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
9015
diff
changeset
|
1583 | { |
| 15884 | 1584 | PurpleConnection *gc = purple_account_get_connection(buddy->account); |
|
9030
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
9015
diff
changeset
|
1585 | JabberStream *js = gc->proto_data; |
|
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
9015
diff
changeset
|
1586 | JabberBuddy *jb = jabber_buddy_find(js, buddy->name, TRUE); |
|
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
9015
diff
changeset
|
1587 | |
| 7014 | 1588 | GList *m = NULL; |
| 15884 | 1589 | PurpleMenuAction *act; |
| 7395 | 1590 | |
| 1591 | if(!jb) | |
| 1592 | return m; | |
| 1593 | ||
| 8185 | 1594 | /* XXX: fix the NOT ME below */ |
| 1595 | ||
| 1596 | if(js->protocol_version == JABBER_PROTO_0_9 /* && NOT ME */) { | |
| 8166 | 1597 | if(jb->invisible & JABBER_INVIS_BUDDY) { |
| 15884 | 1598 | act = purple_menu_action_new(_("Un-hide From"), |
| 1599 | PURPLE_CALLBACK(jabber_buddy_make_visible), | |
| 12919 | 1600 | NULL, NULL); |
| 8166 | 1601 | } else { |
| 15884 | 1602 | act = purple_menu_action_new(_("Temporarily Hide From"), |
| 1603 | PURPLE_CALLBACK(jabber_buddy_make_invisible), | |
| 13019 | 1604 | NULL, NULL); |
| 8166 | 1605 | } |
|
9030
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
9015
diff
changeset
|
1606 | m = g_list_append(m, act); |
| 7014 | 1607 | } |
| 1608 | ||
| 8185 | 1609 | if(jb->subscription & JABBER_SUB_FROM /* && NOT ME */) { |
| 15884 | 1610 | act = purple_menu_action_new(_("Cancel Presence Notification"), |
| 1611 | PURPLE_CALLBACK(jabber_buddy_cancel_presence_notification), | |
| 12919 | 1612 | NULL, NULL); |
|
9030
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
9015
diff
changeset
|
1613 | m = g_list_append(m, act); |
| 7014 | 1614 | } |
| 1615 | ||
| 1616 | if(!(jb->subscription & JABBER_SUB_TO)) { | |
| 15884 | 1617 | act = purple_menu_action_new(_("(Re-)Request authorization"), |
| 1618 | PURPLE_CALLBACK(jabber_buddy_rerequest_auth), | |
| 12919 | 1619 | NULL, NULL); |
|
9030
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
9015
diff
changeset
|
1620 | m = g_list_append(m, act); |
|
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
9015
diff
changeset
|
1621 | |
| 8185 | 1622 | } else /* if(NOT ME) */{ |
|
9030
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
9015
diff
changeset
|
1623 | |
|
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
9015
diff
changeset
|
1624 | /* shouldn't this just happen automatically when the buddy is |
|
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
9015
diff
changeset
|
1625 | removed? */ |
| 15884 | 1626 | act = purple_menu_action_new(_("Unsubscribe"), |
| 1627 | PURPLE_CALLBACK(jabber_buddy_unsubscribe), | |
| 12919 | 1628 | NULL, NULL); |
|
9030
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
9015
diff
changeset
|
1629 | m = g_list_append(m, act); |
| 7014 | 1630 | } |
| 1631 | ||
| 1632 | return m; | |
| 1633 | } | |
|
9030
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
9015
diff
changeset
|
1634 | |
|
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
9015
diff
changeset
|
1635 | GList * |
| 15884 | 1636 | jabber_blist_node_menu(PurpleBlistNode *node) |
|
9030
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
9015
diff
changeset
|
1637 | { |
| 15884 | 1638 | if(PURPLE_BLIST_NODE_IS_BUDDY(node)) { |
| 1639 | return jabber_buddy_menu((PurpleBuddy *) node); | |
|
9030
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
9015
diff
changeset
|
1640 | } else { |
|
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
9015
diff
changeset
|
1641 | return NULL; |
|
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
9015
diff
changeset
|
1642 | } |
|
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
9015
diff
changeset
|
1643 | } |
|
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
9015
diff
changeset
|
1644 | |
|
7b574a641391
[gaim-migrate @ 9806]
Mark Doliner <markdoliner@pidgin.im>
parents:
9015
diff
changeset
|
1645 | |
| 9954 | 1646 | const char * |
| 1647 | jabber_buddy_state_get_name(JabberBuddyState state) | |
| 1648 | { | |
| 1649 | switch(state) { | |
| 1650 | case JABBER_BUDDY_STATE_UNKNOWN: | |
| 1651 | return _("Unknown"); | |
| 1652 | case JABBER_BUDDY_STATE_ERROR: | |
| 1653 | return _("Error"); | |
| 1654 | case JABBER_BUDDY_STATE_UNAVAILABLE: | |
| 1655 | return _("Offline"); | |
| 1656 | case JABBER_BUDDY_STATE_ONLINE: | |
|
12467
94948d1eb8cf
[gaim-migrate @ 14777]
Richard Laager <rlaager@pidgin.im>
parents:
12323
diff
changeset
|
1657 | return _("Available"); |
| 9954 | 1658 | case JABBER_BUDDY_STATE_CHAT: |
| 1659 | return _("Chatty"); | |
| 1660 | case JABBER_BUDDY_STATE_AWAY: | |
| 1661 | return _("Away"); | |
| 1662 | case JABBER_BUDDY_STATE_XA: | |
| 1663 | return _("Extended Away"); | |
| 1664 | case JABBER_BUDDY_STATE_DND: | |
| 1665 | return _("Do Not Disturb"); | |
| 1666 | } | |
| 1667 | ||
| 1668 | return _("Unknown"); | |
| 1669 | } | |
| 1670 | ||
| 1671 | JabberBuddyState jabber_buddy_status_id_get_state(const char *id) { | |
| 1672 | if(!id) | |
| 1673 | return JABBER_BUDDY_STATE_UNKNOWN; | |
|
11540
ad0321374664
[gaim-migrate @ 13795]
Mark Doliner <markdoliner@pidgin.im>
parents:
11533
diff
changeset
|
1674 | if(!strcmp(id, "available")) |
| 9954 | 1675 | return JABBER_BUDDY_STATE_ONLINE; |
| 12683 | 1676 | if(!strcmp(id, "freeforchat")) |
| 1677 | return JABBER_BUDDY_STATE_CHAT; | |
| 1678 | if(!strcmp(id, "away")) | |
| 1679 | return JABBER_BUDDY_STATE_AWAY; | |
| 1680 | if(!strcmp(id, "extended_away")) | |
| 1681 | return JABBER_BUDDY_STATE_XA; | |
| 1682 | if(!strcmp(id, "dnd")) | |
| 1683 | return JABBER_BUDDY_STATE_DND; | |
| 1684 | if(!strcmp(id, "offline")) | |
| 1685 | return JABBER_BUDDY_STATE_UNAVAILABLE; | |
| 1686 | if(!strcmp(id, "error")) | |
| 1687 | return JABBER_BUDDY_STATE_ERROR; | |
| 1688 | ||
| 1689 | return JABBER_BUDDY_STATE_UNKNOWN; | |
| 1690 | } | |
| 1691 | ||
| 1692 | JabberBuddyState jabber_buddy_show_get_state(const char *id) { | |
| 1693 | if(!id) | |
| 1694 | return JABBER_BUDDY_STATE_UNKNOWN; | |
| 1695 | if(!strcmp(id, "available")) | |
| 1696 | return JABBER_BUDDY_STATE_ONLINE; | |
| 9954 | 1697 | if(!strcmp(id, "chat")) |
| 1698 | return JABBER_BUDDY_STATE_CHAT; | |
| 1699 | if(!strcmp(id, "away")) | |
| 1700 | return JABBER_BUDDY_STATE_AWAY; | |
| 1701 | if(!strcmp(id, "xa")) | |
| 1702 | return JABBER_BUDDY_STATE_XA; | |
| 1703 | if(!strcmp(id, "dnd")) | |
| 1704 | return JABBER_BUDDY_STATE_DND; | |
| 1705 | if(!strcmp(id, "offline")) | |
| 1706 | return JABBER_BUDDY_STATE_UNAVAILABLE; | |
| 1707 | if(!strcmp(id, "error")) | |
| 1708 | return JABBER_BUDDY_STATE_ERROR; | |
| 1709 | ||
| 1710 | return JABBER_BUDDY_STATE_UNKNOWN; | |
| 1711 | } | |
| 1712 | ||
| 12683 | 1713 | const char *jabber_buddy_state_get_show(JabberBuddyState state) { |
| 9954 | 1714 | switch(state) { |
| 1715 | case JABBER_BUDDY_STATE_CHAT: | |
| 1716 | return "chat"; | |
| 1717 | case JABBER_BUDDY_STATE_AWAY: | |
| 1718 | return "away"; | |
| 1719 | case JABBER_BUDDY_STATE_XA: | |
| 1720 | return "xa"; | |
| 1721 | case JABBER_BUDDY_STATE_DND: | |
| 1722 | return "dnd"; | |
| 1723 | case JABBER_BUDDY_STATE_ONLINE: | |
|
11540
ad0321374664
[gaim-migrate @ 13795]
Mark Doliner <markdoliner@pidgin.im>
parents:
11533
diff
changeset
|
1724 | return "available"; |
| 9954 | 1725 | case JABBER_BUDDY_STATE_UNKNOWN: |
| 1726 | case JABBER_BUDDY_STATE_ERROR: | |
| 1727 | return NULL; | |
| 1728 | case JABBER_BUDDY_STATE_UNAVAILABLE: | |
| 1729 | return "offline"; | |
| 1730 | } | |
| 1731 | return NULL; | |
| 1732 | } | |
| 11675 | 1733 | |
| 12683 | 1734 | const char *jabber_buddy_state_get_status_id(JabberBuddyState state) { |
| 1735 | switch(state) { | |
| 1736 | case JABBER_BUDDY_STATE_CHAT: | |
| 1737 | return "freeforchat"; | |
| 1738 | case JABBER_BUDDY_STATE_AWAY: | |
| 1739 | return "away"; | |
| 1740 | case JABBER_BUDDY_STATE_XA: | |
| 1741 | return "extended_away"; | |
| 1742 | case JABBER_BUDDY_STATE_DND: | |
| 1743 | return "dnd"; | |
| 1744 | case JABBER_BUDDY_STATE_ONLINE: | |
| 1745 | return "available"; | |
| 1746 | case JABBER_BUDDY_STATE_UNKNOWN: | |
| 13758 | 1747 | return "available"; |
| 12683 | 1748 | case JABBER_BUDDY_STATE_ERROR: |
| 13758 | 1749 | return "error"; |
| 12683 | 1750 | case JABBER_BUDDY_STATE_UNAVAILABLE: |
| 1751 | return "offline"; | |
| 1752 | } | |
| 1753 | return NULL; | |
| 1754 | } | |
| 1755 | ||
| 15884 | 1756 | static void user_search_result_add_buddy_cb(PurpleConnection *gc, GList *row, void *user_data) |
| 11675 | 1757 | { |
| 1758 | /* XXX find out the jid */ | |
| 15884 | 1759 | purple_blist_request_add_buddy(purple_connection_get_account(gc), |
| 11675 | 1760 | g_list_nth_data(row, 0), NULL, NULL); |
| 1761 | } | |
| 1762 | ||
| 1763 | static void user_search_result_cb(JabberStream *js, xmlnode *packet, gpointer data) | |
| 1764 | { | |
| 15884 | 1765 | PurpleNotifySearchResults *results; |
| 1766 | PurpleNotifySearchColumn *column; | |
| 11675 | 1767 | xmlnode *x, *query, *item, *field; |
| 1768 | ||
| 1769 | /* XXX error checking? */ | |
| 1770 | if(!(query = xmlnode_get_child(packet, "query"))) | |
| 1771 | return; | |
| 1772 | ||
| 15884 | 1773 | results = purple_notify_searchresults_new(); |
| 11675 | 1774 | if((x = xmlnode_get_child_with_namespace(query, "x", "jabber:x:data"))) { |
| 1775 | xmlnode *reported; | |
| 15884 | 1776 | purple_debug_info("jabber", "new-skool\n"); |
| 11675 | 1777 | if((reported = xmlnode_get_child(x, "reported"))) { |
| 1778 | xmlnode *field = xmlnode_get_child(reported, "field"); | |
| 1779 | while(field) { | |
| 1780 | /* XXX keep track of this order, use it below */ | |
| 1781 | const char *var = xmlnode_get_attrib(field, "var"); | |
| 1782 | const char *label = xmlnode_get_attrib(field, "label"); | |
| 1783 | if(var) { | |
| 15884 | 1784 | column = purple_notify_searchresults_column_new(label ? label : var); |
| 1785 | purple_notify_searchresults_column_add(results, column); | |
| 11675 | 1786 | } |
| 1787 | field = xmlnode_get_next_twin(field); | |
| 1788 | } | |
| 1789 | } | |
| 1790 | item = xmlnode_get_child(x, "item"); | |
| 1791 | while(item) { | |
| 1792 | GList *row = NULL; | |
| 1793 | field = xmlnode_get_child(item, "field"); | |
| 1794 | while(field) { | |
| 13345 | 1795 | xmlnode *valuenode = xmlnode_get_child(field, "value"); |
| 11675 | 1796 | if(valuenode) { |
| 1797 | char *value = xmlnode_get_data(valuenode); | |
| 1798 | row = g_list_append(row, value); | |
| 1799 | } | |
| 1800 | field = xmlnode_get_next_twin(field); | |
| 1801 | } | |
| 15884 | 1802 | purple_notify_searchresults_row_add(results, row); |
| 11675 | 1803 | |
| 1804 | item = xmlnode_get_next_twin(item); | |
| 1805 | } | |
| 1806 | } else { | |
| 1807 | /* old skool */ | |
| 15884 | 1808 | purple_debug_info("jabber", "old-skool\n"); |
| 11675 | 1809 | |
| 15884 | 1810 | column = purple_notify_searchresults_column_new(_("JID")); |
| 1811 | purple_notify_searchresults_column_add(results, column); | |
| 1812 | column = purple_notify_searchresults_column_new(_("First Name")); | |
| 1813 | purple_notify_searchresults_column_add(results, column); | |
| 1814 | column = purple_notify_searchresults_column_new(_("Last Name")); | |
| 1815 | purple_notify_searchresults_column_add(results, column); | |
| 1816 | column = purple_notify_searchresults_column_new(_("Nickname")); | |
| 1817 | purple_notify_searchresults_column_add(results, column); | |
| 1818 | column = purple_notify_searchresults_column_new(_("E-Mail")); | |
| 1819 | purple_notify_searchresults_column_add(results, column); | |
| 11675 | 1820 | |
| 1821 | for(item = xmlnode_get_child(query, "item"); item; item = xmlnode_get_next_twin(item)) { | |
| 1822 | const char *jid; | |
| 1823 | xmlnode *node; | |
| 1824 | GList *row = NULL; | |
| 1825 | ||
| 1826 | if(!(jid = xmlnode_get_attrib(item, "jid"))) | |
| 1827 | continue; | |
| 1828 | ||
| 1829 | row = g_list_append(row, g_strdup(jid)); | |
| 1830 | node = xmlnode_get_child(item, "first"); | |
| 1831 | row = g_list_append(row, node ? xmlnode_get_data(node) : NULL); | |
| 1832 | node = xmlnode_get_child(item, "last"); | |
| 1833 | row = g_list_append(row, node ? xmlnode_get_data(node) : NULL); | |
| 1834 | node = xmlnode_get_child(item, "nick"); | |
| 1835 | row = g_list_append(row, node ? xmlnode_get_data(node) : NULL); | |
| 1836 | node = xmlnode_get_child(item, "email"); | |
| 1837 | row = g_list_append(row, node ? xmlnode_get_data(node) : NULL); | |
| 15884 | 1838 | purple_debug_info("jabber", "row=%d\n", row); |
| 1839 | purple_notify_searchresults_row_add(results, row); | |
| 11675 | 1840 | } |
| 1841 | } | |
| 1842 | ||
| 15884 | 1843 | purple_notify_searchresults_button_add(results, PURPLE_NOTIFY_BUTTON_ADD, |
| 11675 | 1844 | user_search_result_add_buddy_cb); |
| 1845 | ||
| 15884 | 1846 | purple_notify_searchresults(js->gc, NULL, NULL, _("The following are the results of your search"), results, NULL, NULL); |
| 11675 | 1847 | } |
| 1848 | ||
| 1849 | static void user_search_x_data_cb(JabberStream *js, xmlnode *result, gpointer data) | |
| 1850 | { | |
| 1851 | xmlnode *query; | |
| 1852 | JabberIq *iq; | |
| 13345 | 1853 | char *dir_server = data; |
| 11675 | 1854 | |
| 1855 | iq = jabber_iq_new_query(js, JABBER_IQ_SET, "jabber:iq:search"); | |
| 1856 | query = xmlnode_get_child(iq->node, "query"); | |
| 1857 | ||
| 1858 | xmlnode_insert_child(query, result); | |
| 1859 | ||
| 1860 | jabber_iq_set_callback(iq, user_search_result_cb, NULL); | |
| 13345 | 1861 | xmlnode_set_attrib(iq->node, "to", dir_server); |
| 11675 | 1862 | jabber_iq_send(iq); |
| 13345 | 1863 | g_free(dir_server); |
| 11675 | 1864 | } |
| 1865 | ||
| 1866 | struct user_search_info { | |
| 1867 | JabberStream *js; | |
| 1868 | char *directory_server; | |
| 1869 | }; | |
| 1870 | ||
| 15884 | 1871 | static void user_search_cancel_cb(struct user_search_info *usi, PurpleRequestFields *fields) |
| 11675 | 1872 | { |
| 1873 | g_free(usi->directory_server); | |
| 1874 | g_free(usi); | |
| 1875 | } | |
| 1876 | ||
| 15884 | 1877 | static void user_search_cb(struct user_search_info *usi, PurpleRequestFields *fields) |
| 11675 | 1878 | { |
| 1879 | JabberStream *js = usi->js; | |
| 1880 | JabberIq *iq; | |
| 1881 | xmlnode *query; | |
| 1882 | GList *groups, *flds; | |
| 1883 | ||
| 1884 | iq = jabber_iq_new_query(js, JABBER_IQ_SET, "jabber:iq:search"); | |
| 1885 | query = xmlnode_get_child(iq->node, "query"); | |
| 1886 | ||
| 15884 | 1887 | for(groups = purple_request_fields_get_groups(fields); groups; groups = groups->next) { |
| 1888 | for(flds = purple_request_field_group_get_fields(groups->data); | |
| 11675 | 1889 | flds; flds = flds->next) { |
| 15884 | 1890 | PurpleRequestField *field = flds->data; |
| 1891 | const char *id = purple_request_field_get_id(field); | |
| 1892 | const char *value = purple_request_field_string_get_value(field); | |
| 11675 | 1893 | |
| 1894 | if(value && (!strcmp(id, "first") || !strcmp(id, "last") || !strcmp(id, "nick") || !strcmp(id, "email"))) { | |
| 1895 | xmlnode *y = xmlnode_new_child(query, id); | |
| 1896 | xmlnode_insert_data(y, value, -1); | |
| 1897 | } | |
| 1898 | } | |
| 1899 | } | |
| 1900 | ||
| 1901 | jabber_iq_set_callback(iq, user_search_result_cb, NULL); | |
| 1902 | xmlnode_set_attrib(iq->node, "to", usi->directory_server); | |
| 1903 | jabber_iq_send(iq); | |
| 1904 | ||
| 1905 | g_free(usi->directory_server); | |
| 1906 | g_free(usi); | |
| 1907 | } | |
| 1908 | ||
|
13617
983b0c58fcae
[gaim-migrate @ 16002]
Björn Voigt <bjoern@cs.tu-berlin.de>
parents:
13574
diff
changeset
|
1909 | #if 0 |
|
983b0c58fcae
[gaim-migrate @ 16002]
Björn Voigt <bjoern@cs.tu-berlin.de>
parents:
13574
diff
changeset
|
1910 | /* This is for gettext only -- it will see this even though there's an #if 0. */ |
|
983b0c58fcae
[gaim-migrate @ 16002]
Björn Voigt <bjoern@cs.tu-berlin.de>
parents:
13574
diff
changeset
|
1911 | |
|
983b0c58fcae
[gaim-migrate @ 16002]
Björn Voigt <bjoern@cs.tu-berlin.de>
parents:
13574
diff
changeset
|
1912 | /* |
|
983b0c58fcae
[gaim-migrate @ 16002]
Björn Voigt <bjoern@cs.tu-berlin.de>
parents:
13574
diff
changeset
|
1913 | * An incomplete list of server generated original language search |
|
983b0c58fcae
[gaim-migrate @ 16002]
Björn Voigt <bjoern@cs.tu-berlin.de>
parents:
13574
diff
changeset
|
1914 | * comments for Jabber User Directories |
|
983b0c58fcae
[gaim-migrate @ 16002]
Björn Voigt <bjoern@cs.tu-berlin.de>
parents:
13574
diff
changeset
|
1915 | * |
|
983b0c58fcae
[gaim-migrate @ 16002]
Björn Voigt <bjoern@cs.tu-berlin.de>
parents:
13574
diff
changeset
|
1916 | * See discussion thread "Search comment for Jabber is not translatable" |
| 15884 | 1917 | * in purple-i18n@lists.sourceforge.net (March 2006) |
|
13617
983b0c58fcae
[gaim-migrate @ 16002]
Björn Voigt <bjoern@cs.tu-berlin.de>
parents:
13574
diff
changeset
|
1918 | */ |
|
983b0c58fcae
[gaim-migrate @ 16002]
Björn Voigt <bjoern@cs.tu-berlin.de>
parents:
13574
diff
changeset
|
1919 | static const char * jabber_user_dir_comments [] = { |
|
983b0c58fcae
[gaim-migrate @ 16002]
Björn Voigt <bjoern@cs.tu-berlin.de>
parents:
13574
diff
changeset
|
1920 | /* current comment from Jabber User Directory users.jabber.org */ |
|
983b0c58fcae
[gaim-migrate @ 16002]
Björn Voigt <bjoern@cs.tu-berlin.de>
parents:
13574
diff
changeset
|
1921 | N_("Find a contact by entering the search criteria in the given fields. " |
|
983b0c58fcae
[gaim-migrate @ 16002]
Björn Voigt <bjoern@cs.tu-berlin.de>
parents:
13574
diff
changeset
|
1922 | "Note: Each field supports wild card searches (%)"), |
|
983b0c58fcae
[gaim-migrate @ 16002]
Björn Voigt <bjoern@cs.tu-berlin.de>
parents:
13574
diff
changeset
|
1923 | NULL |
|
983b0c58fcae
[gaim-migrate @ 16002]
Björn Voigt <bjoern@cs.tu-berlin.de>
parents:
13574
diff
changeset
|
1924 | }; |
|
983b0c58fcae
[gaim-migrate @ 16002]
Björn Voigt <bjoern@cs.tu-berlin.de>
parents:
13574
diff
changeset
|
1925 | #endif |
|
983b0c58fcae
[gaim-migrate @ 16002]
Björn Voigt <bjoern@cs.tu-berlin.de>
parents:
13574
diff
changeset
|
1926 | |
| 11675 | 1927 | static void user_search_fields_result_cb(JabberStream *js, xmlnode *packet, gpointer data) |
| 1928 | { | |
| 1929 | xmlnode *query, *x; | |
| 13345 | 1930 | const char *from, *type; |
| 11675 | 1931 | |
| 12284 | 1932 | if(!(from = xmlnode_get_attrib(packet, "from"))) |
| 11675 | 1933 | return; |
| 1934 | ||
| 13345 | 1935 | if(!(type = xmlnode_get_attrib(packet, "type")) || !strcmp(type, "error")) { |
|
13634
e9f9cef982d7
[gaim-migrate @ 16031]
Björn Voigt <bjoern@cs.tu-berlin.de>
parents:
13619
diff
changeset
|
1936 | char *msg = jabber_parse_error(js, packet); |
| 13794 | 1937 | |
|
13634
e9f9cef982d7
[gaim-migrate @ 16031]
Björn Voigt <bjoern@cs.tu-berlin.de>
parents:
13619
diff
changeset
|
1938 | if(!msg) |
|
e9f9cef982d7
[gaim-migrate @ 16031]
Björn Voigt <bjoern@cs.tu-berlin.de>
parents:
13619
diff
changeset
|
1939 | msg = g_strdup(_("Unknown error")); |
|
e9f9cef982d7
[gaim-migrate @ 16031]
Björn Voigt <bjoern@cs.tu-berlin.de>
parents:
13619
diff
changeset
|
1940 | |
| 15884 | 1941 | purple_notify_error(js->gc, _("Directory Query Failed"), |
|
13634
e9f9cef982d7
[gaim-migrate @ 16031]
Björn Voigt <bjoern@cs.tu-berlin.de>
parents:
13619
diff
changeset
|
1942 | _("Could not query the directory server."), msg); |
|
e9f9cef982d7
[gaim-migrate @ 16031]
Björn Voigt <bjoern@cs.tu-berlin.de>
parents:
13619
diff
changeset
|
1943 | g_free(msg); |
|
e9f9cef982d7
[gaim-migrate @ 16031]
Björn Voigt <bjoern@cs.tu-berlin.de>
parents:
13619
diff
changeset
|
1944 | |
| 13345 | 1945 | return; |
| 1946 | } | |
| 1947 | ||
| 11675 | 1948 | |
| 1949 | if(!(query = xmlnode_get_child(packet, "query"))) | |
| 1950 | return; | |
| 1951 | ||
| 13330 | 1952 | if((x = xmlnode_get_child_with_namespace(query, "x", "jabber:x:data"))) { |
| 13345 | 1953 | jabber_x_data_request(js, x, user_search_x_data_cb, g_strdup(from)); |
| 11675 | 1954 | return; |
| 1955 | } else { | |
| 1956 | struct user_search_info *usi; | |
| 1957 | xmlnode *instnode; | |
|
13617
983b0c58fcae
[gaim-migrate @ 16002]
Björn Voigt <bjoern@cs.tu-berlin.de>
parents:
13574
diff
changeset
|
1958 | char *instructions = NULL; |
| 15884 | 1959 | PurpleRequestFields *fields; |
| 1960 | PurpleRequestFieldGroup *group; | |
| 1961 | PurpleRequestField *field; | |
| 11675 | 1962 | |
| 1963 | /* old skool */ | |
| 15884 | 1964 | fields = purple_request_fields_new(); |
| 1965 | group = purple_request_field_group_new(NULL); | |
| 1966 | purple_request_fields_add_group(fields, group); | |
| 11675 | 1967 | |
| 1968 | if((instnode = xmlnode_get_child(query, "instructions"))) | |
|
13574
433001d94e3e
[gaim-migrate @ 15952]
Richard Laager <rlaager@pidgin.im>
parents:
13572
diff
changeset
|
1969 | { |
|
433001d94e3e
[gaim-migrate @ 15952]
Richard Laager <rlaager@pidgin.im>
parents:
13572
diff
changeset
|
1970 | char *tmp = xmlnode_get_data(instnode); |
| 13794 | 1971 | |
|
13617
983b0c58fcae
[gaim-migrate @ 16002]
Björn Voigt <bjoern@cs.tu-berlin.de>
parents:
13574
diff
changeset
|
1972 | if(tmp) |
|
983b0c58fcae
[gaim-migrate @ 16002]
Björn Voigt <bjoern@cs.tu-berlin.de>
parents:
13574
diff
changeset
|
1973 | { |
| 13794 | 1974 | /* Try to translate the message (see static message |
|
13617
983b0c58fcae
[gaim-migrate @ 16002]
Björn Voigt <bjoern@cs.tu-berlin.de>
parents:
13574
diff
changeset
|
1975 | list in jabber_user_dir_comments[]) */ |
|
983b0c58fcae
[gaim-migrate @ 16002]
Björn Voigt <bjoern@cs.tu-berlin.de>
parents:
13574
diff
changeset
|
1976 | instructions = g_strdup_printf(_("Server Instructions: %s"), _(tmp)); |
|
983b0c58fcae
[gaim-migrate @ 16002]
Björn Voigt <bjoern@cs.tu-berlin.de>
parents:
13574
diff
changeset
|
1977 | g_free(tmp); |
|
983b0c58fcae
[gaim-migrate @ 16002]
Björn Voigt <bjoern@cs.tu-berlin.de>
parents:
13574
diff
changeset
|
1978 | } |
|
13574
433001d94e3e
[gaim-migrate @ 15952]
Richard Laager <rlaager@pidgin.im>
parents:
13572
diff
changeset
|
1979 | } |
| 13794 | 1980 | |
|
13617
983b0c58fcae
[gaim-migrate @ 16002]
Björn Voigt <bjoern@cs.tu-berlin.de>
parents:
13574
diff
changeset
|
1981 | if(!instructions) |
|
983b0c58fcae
[gaim-migrate @ 16002]
Björn Voigt <bjoern@cs.tu-berlin.de>
parents:
13574
diff
changeset
|
1982 | { |
| 11675 | 1983 | instructions = g_strdup(_("Fill in one or more fields to search " |
|
16961
b6955f946f8f
s/Jabber/XMPP in user-visible places.
Richard Laager <rlaager@pidgin.im>
parents:
16799
diff
changeset
|
1984 | "for any matching XMPP users.")); |
|
13617
983b0c58fcae
[gaim-migrate @ 16002]
Björn Voigt <bjoern@cs.tu-berlin.de>
parents:
13574
diff
changeset
|
1985 | } |
| 11675 | 1986 | |
| 1987 | if(xmlnode_get_child(query, "first")) { | |
| 15884 | 1988 | field = purple_request_field_string_new("first", _("First Name"), |
| 11675 | 1989 | NULL, FALSE); |
| 15884 | 1990 | purple_request_field_group_add_field(group, field); |
| 11675 | 1991 | } |
| 1992 | if(xmlnode_get_child(query, "last")) { | |
| 15884 | 1993 | field = purple_request_field_string_new("last", _("Last Name"), |
| 11675 | 1994 | NULL, FALSE); |
| 15884 | 1995 | purple_request_field_group_add_field(group, field); |
| 11675 | 1996 | } |
| 1997 | if(xmlnode_get_child(query, "nick")) { | |
| 15884 | 1998 | field = purple_request_field_string_new("nick", _("Nickname"), |
| 11675 | 1999 | NULL, FALSE); |
| 15884 | 2000 | purple_request_field_group_add_field(group, field); |
| 11675 | 2001 | } |
| 2002 | if(xmlnode_get_child(query, "email")) { | |
| 15884 | 2003 | field = purple_request_field_string_new("email", _("E-Mail Address"), |
| 11675 | 2004 | NULL, FALSE); |
| 15884 | 2005 | purple_request_field_group_add_field(group, field); |
| 11675 | 2006 | } |
| 2007 | ||
| 2008 | usi = g_new0(struct user_search_info, 1); | |
| 2009 | usi->js = js; | |
| 2010 | usi->directory_server = g_strdup(from); | |
| 2011 | ||
|
16961
b6955f946f8f
s/Jabber/XMPP in user-visible places.
Richard Laager <rlaager@pidgin.im>
parents:
16799
diff
changeset
|
2012 | purple_request_fields(js->gc, _("Search for XMPP users"), |
|
b6955f946f8f
s/Jabber/XMPP in user-visible places.
Richard Laager <rlaager@pidgin.im>
parents:
16799
diff
changeset
|
2013 | _("Search for XMPP users"), instructions, fields, |
| 11675 | 2014 | _("Search"), G_CALLBACK(user_search_cb), |
|
16490
68c22924d66b
Added account, who, and conversation parameters to the request API calls, and updated all code to match. I can't compile the Perl module, so I'd appreciate it if someone who knows it would verify that this doesn't break Perl.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
2015 | _("Cancel"), G_CALLBACK(user_search_cancel_cb), |
|
68c22924d66b
Added account, who, and conversation parameters to the request API calls, and updated all code to match. I can't compile the Perl module, so I'd appreciate it if someone who knows it would verify that this doesn't break Perl.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
2016 | NULL, NULL, NULL, |
|
68c22924d66b
Added account, who, and conversation parameters to the request API calls, and updated all code to match. I can't compile the Perl module, so I'd appreciate it if someone who knows it would verify that this doesn't break Perl.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
2017 | usi); |
| 11675 | 2018 | |
| 2019 | g_free(instructions); | |
| 2020 | } | |
| 2021 | } | |
| 2022 | ||
| 2023 | static void jabber_user_search_ok(JabberStream *js, const char *directory) | |
| 2024 | { | |
| 2025 | JabberIq *iq; | |
| 2026 | ||
| 2027 | /* XXX: should probably better validate the directory we're given */ | |
| 2028 | if(!directory || !*directory) { | |
| 15884 | 2029 | purple_notify_error(js->gc, _("Invalid Directory"), _("Invalid Directory"), NULL); |
| 11675 | 2030 | return; |
| 2031 | } | |
| 2032 | ||
| 2033 | iq = jabber_iq_new_query(js, JABBER_IQ_GET, "jabber:iq:search"); | |
| 2034 | xmlnode_set_attrib(iq->node, "to", directory); | |
| 2035 | ||
| 2036 | jabber_iq_set_callback(iq, user_search_fields_result_cb, NULL); | |
| 2037 | ||
| 2038 | jabber_iq_send(iq); | |
| 2039 | } | |
| 2040 | ||
| 15884 | 2041 | void jabber_user_search_begin(PurplePluginAction *action) |
| 11675 | 2042 | { |
| 15884 | 2043 | PurpleConnection *gc = (PurpleConnection *) action->context; |
| 11675 | 2044 | JabberStream *js = gc->proto_data; |
| 2045 | ||
| 15884 | 2046 | purple_request_input(gc, _("Enter a User Directory"), _("Enter a User Directory"), |
| 11675 | 2047 | _("Select a user directory to search"), |
|
17007
66c0fa6e5e2a
Removes 'jabber.org' defaults from XMPP. I think we had agreed this was a good idea.
Sean Egan <seanegan@pidgin.im>
parents:
16961
diff
changeset
|
2048 | js->user_directories ? js->user_directories->data : NULL, |
| 11675 | 2049 | FALSE, FALSE, NULL, |
| 15884 | 2050 | _("Search Directory"), PURPLE_CALLBACK(jabber_user_search_ok), |
|
16490
68c22924d66b
Added account, who, and conversation parameters to the request API calls, and updated all code to match. I can't compile the Perl module, so I'd appreciate it if someone who knows it would verify that this doesn't break Perl.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
2051 | _("Cancel"), NULL, |
|
68c22924d66b
Added account, who, and conversation parameters to the request API calls, and updated all code to match. I can't compile the Perl module, so I'd appreciate it if someone who knows it would verify that this doesn't break Perl.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
2052 | NULL, NULL, NULL, |
|
68c22924d66b
Added account, who, and conversation parameters to the request API calls, and updated all code to match. I can't compile the Perl module, so I'd appreciate it if someone who knows it would verify that this doesn't break Perl.
Evan Schoenberg <evands@pidgin.im>
parents:
15884
diff
changeset
|
2053 | js); |
| 11675 | 2054 | } |
| 13794 | 2055 | |
| 2056 | ||
| 2057 |