| 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
| 21 * |
21 * |
| 22 */ |
22 */ |
| 23 |
23 |
| 24 #include "internal.h" |
24 #include "internal.h" |
| 25 #include "obsolete.h" |
25 |
| 26 |
26 #include "http.h" |
| 27 #include "useravatar.h" |
27 #include "useravatar.h" |
| 28 #include "pep.h" |
28 #include "pep.h" |
| 29 #include "debug.h" |
29 #include "debug.h" |
| 30 |
30 |
| 31 #define MAX_HTTP_BUDDYICON_BYTES (200 * 1024) |
31 #define MAX_HTTP_BUDDYICON_BYTES (200 * 1024) |
| 258 char *from; |
258 char *from; |
| 259 char *id; |
259 char *id; |
| 260 } JabberBuddyAvatarUpdateURLInfo; |
260 } JabberBuddyAvatarUpdateURLInfo; |
| 261 |
261 |
| 262 static void |
262 static void |
| 263 do_buddy_avatar_update_fromurl(PurpleUtilFetchUrlData *url_data, |
263 do_buddy_avatar_update_fromurl(PurpleHttpConnection *http_conn, |
| 264 gpointer user_data, const gchar *url_text, |
264 PurpleHttpResponse *response, gpointer _info) |
| 265 gsize len, const gchar *error_message) |
265 { |
| 266 { |
266 JabberBuddyAvatarUpdateURLInfo *info = _info; |
| 267 JabberBuddyAvatarUpdateURLInfo *info = user_data; |
|
| 268 gpointer icon_data; |
267 gpointer icon_data; |
| 269 |
268 const gchar *got_data; |
| 270 if(!url_text) { |
269 size_t got_len; |
| 271 purple_debug_error("jabber", |
270 |
| 272 "do_buddy_avatar_update_fromurl got error \"%s\"", |
271 if (!purple_http_response_is_successfull(response)) { |
| 273 error_message); |
272 purple_debug_error("jabber", "do_buddy_avatar_update_fromurl " |
| |
273 "got error \"%s\"", |
| |
274 purple_http_response_get_error(response)); |
| 274 goto out; |
275 goto out; |
| 275 } |
276 } |
| 276 |
277 |
| 277 icon_data = g_memdup(url_text, len); |
278 got_data = purple_http_response_get_data(response, &got_len); |
| 278 purple_buddy_icons_set_for_user(purple_connection_get_account(info->js->gc), info->from, icon_data, len, info->id); |
279 icon_data = g_memdup(got_data, got_len); |
| |
280 purple_buddy_icons_set_for_user(purple_connection_get_account(info->js->gc), info->from, icon_data, got_len, info->id); |
| 279 |
281 |
| 280 out: |
282 out: |
| 281 g_free(info->from); |
283 g_free(info->from); |
| 282 g_free(info->id); |
284 g_free(info->id); |
| 283 g_free(info); |
285 g_free(info); |
| 376 /* the avatar might either be stored in a pep node, or on a HTTP(S) URL */ |
378 /* the avatar might either be stored in a pep node, or on a HTTP(S) URL */ |
| 377 if(!url) { |
379 if(!url) { |
| 378 jabber_pep_request_item(js, from, NS_AVATAR_1_1_DATA, id, |
380 jabber_pep_request_item(js, from, NS_AVATAR_1_1_DATA, id, |
| 379 do_buddy_avatar_update_data); |
381 do_buddy_avatar_update_data); |
| 380 } else { |
382 } else { |
| 381 PurpleUtilFetchUrlData *url_data; |
383 PurpleHttpRequest *req; |
| |
384 PurpleHttpConnection *http_conn; |
| 382 JabberBuddyAvatarUpdateURLInfo *info = g_new0(JabberBuddyAvatarUpdateURLInfo, 1); |
385 JabberBuddyAvatarUpdateURLInfo *info = g_new0(JabberBuddyAvatarUpdateURLInfo, 1); |
| 383 info->js = js; |
386 info->js = js; |
| 384 |
387 |
| 385 url_data = purple_util_fetch_url(url, TRUE, NULL, TRUE, |
388 req = purple_http_request_new(url); |
| 386 MAX_HTTP_BUDDYICON_BYTES, |
389 purple_http_request_set_max_len(req, MAX_HTTP_BUDDYICON_BYTES); |
| 387 do_buddy_avatar_update_fromurl, info); |
390 http_conn = purple_http_request(js->gc, req, do_buddy_avatar_update_fromurl, info); |
| 388 if (url_data) { |
391 purple_http_request_unref(req); |
| 389 info->from = g_strdup(from); |
392 |
| 390 info->id = g_strdup(id); |
393 info->from = g_strdup(from); |
| 391 js->url_datas = g_slist_prepend(js->url_datas, url_data); |
394 info->id = g_strdup(id); |
| 392 } else |
395 js->http_conns = g_slist_prepend(js->http_conns, http_conn); |
| 393 g_free(info); |
|
| 394 |
|
| 395 } |
396 } |
| 396 } |
397 } |
| 397 } |
398 } |
| 398 } |
399 } |