Mercurial > pidgin
changeset 12761:95a73ce6e285
[gaim-migrate @ 15108]
Patch from Pekka Riikonen to add Buddy Icon support to SILC. This requires
SILC Toolkit 1.0.2, but I modified it so you can build without buddy icon
support on older toolkit versions.
committer: Tailor Script <tailor@pidgin.im>
author | Stu Tomlinson <stu@nosnilmot.com> |
---|---|
date | Sun, 08 Jan 2006 16:17:22 +0000 |
parents | c5acba513363 |
children | 40584fbf8c6e |
files | ChangeLog src/protocols/silc/buddy.c src/protocols/silc/silc.c src/protocols/silc/silcgaim.h |
diffstat | 4 files changed, 127 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog Sun Jan 08 01:16:23 2006 +0000 +++ b/ChangeLog Sun Jan 08 16:17:22 2006 +0000 @@ -113,6 +113,7 @@ * Whiteboard support (Pekka Riikonen) * Sending/receiving images in IMs (Pekka Riikonen) * Cipher and HMAC selection support (Pekka Riikonen) + * Buddy Icon support (Pekka Riikonen) Other Protocol Changes: * Bonjour (Rendezvous) protocol support (Juanjo Molinero Horno, Google
--- a/src/protocols/silc/buddy.c Sun Jan 08 01:16:23 2006 +0000 +++ b/src/protocols/silc/buddy.c Sun Jan 08 16:17:22 2006 +0000 @@ -609,8 +609,7 @@ buddy = (GaimBuddy *) node; gc = gaim_account_get_connection(buddy->account); - silcgaim_buddy_privkey(gc, buddy->name); - + silcgaim_buddy_getkey(gc, buddy->name); } static void @@ -752,6 +751,9 @@ SilcAttribute attribute; SilcVCardStruct vcard; SilcAttributeObjMime message, extension; +#ifdef SILC_ATTRIBUTE_USER_ICON + SilcAttributeObjMime usericon; +#endif SilcAttributeObjPk serverpk, usersign, serversign; gboolean usign_success = TRUE, ssign_success = TRUE; char filename[512], filename2[512], *fingerprint = NULL, *tmp; @@ -795,6 +797,9 @@ memset(&vcard, 0, sizeof(vcard)); memset(&message, 0, sizeof(message)); memset(&extension, 0, sizeof(extension)); +#ifdef SILC_ATTRIBUTE_USER_ICON + memset(&usericon, 0, sizeof(usericon)); +#endif memset(&serverpk, 0, sizeof(serverpk)); memset(&usersign, 0, sizeof(usersign)); memset(&serversign, 0, sizeof(serversign)); @@ -827,6 +832,14 @@ continue; break; +#ifdef SILC_ATTRIBUTE_USER_ICON + case SILC_ATTRIBUTE_USER_ICON: + if (!silc_attribute_get_object(attr, (void *)&usericon, + sizeof(usericon))) + continue; + break; +#endif + case SILC_ATTRIBUTE_SERVER_PUBLIC_KEY: if (serverpk.type) continue; @@ -958,6 +971,28 @@ silc_file_writefile(filename2, (char *)extension.mime, extension.mime_len); } + +#ifdef SILC_ATTRIBUTE_USER_ICON + /* Save user icon */ + if (usericon.mime) { + SilcMime m = silc_mime_decode(usericon.mime, + usericon.mime_len); + if (m) { + const char *type = silc_mime_get_field(m, "Content-Type"); + if (!strcmp(type, "image/jpeg") || + !strcmp(type, "image/gif") || + !strcmp(type, "image/bmp") || + !strcmp(type, "image/png")) { + const unsigned char *data; + SilcUInt32 data_len; + data = silc_mime_get_data(m, &data_len); + if (data) + gaim_buddy_icons_set_for_user(gaim_buddy_get_account(r->b), gaim_buddy_get_name(r->b), (void *)data, data_len); + } + silc_mime_free(m); + } + } +#endif } /* Save the public key path to buddy properties, as it is used @@ -1319,6 +1354,9 @@ SILC_ATTRIBUTE_PREFERRED_CONTACT, SILC_ATTRIBUTE_TIMEZONE, SILC_ATTRIBUTE_GEOLOCATION, +#ifdef SILC_ATTRIBUTE_USER_ICON + SILC_ATTRIBUTE_USER_ICON, +#endif SILC_ATTRIBUTE_DEVICE_INFO, 0); userpk.type = "silc-rsa"; userpk.data = silc_pkcs_public_key_encode(public_key, &userpk.data_len); @@ -1634,3 +1672,66 @@ } return m; } + +#ifdef SILC_ATTRIBUTE_USER_ICON +void silcgaim_buddy_set_icon(GaimConnection *gc, const char *iconfile) +{ + SilcGaim sg = gc->proto_data; + SilcClient client = sg->client; + SilcClientConnection conn = sg->conn; + SilcMime mime; + GaimBuddyIcon ic; + char type[32]; + unsigned char *icon; + const char *t; + struct stat st; + FILE *fp; + SilcAttributeObjMime obj; + + /* Remove */ + if (!iconfile) { + silc_client_attribute_del(client, conn, + SILC_ATTRIBUTE_USER_ICON, NULL); + return; + } + + /* Add */ + if (g_stat(iconfile, &st) < 0) + return; + fp = g_fopen(iconfile, "rb"); + if (!fp) + return; + ic.data = g_malloc(st.st_size); + if (!ic.data) + return; + ic.len = fread(ic.data, 1, st.st_size, fp); + fclose(fp); + + mime = silc_mime_alloc(); + if (!mime) { + g_free(ic.data); + return; + } + + t = gaim_buddy_icon_get_type((const GaimBuddyIcon *)&ic); + if (!t) { + g_free(ic.data); + silc_mime_free(mime); + return; + } + if (!strcmp(t, "jpg")) + t = "jpeg"; + g_snprintf(type, sizeof(type), "image/%s", t); + silc_mime_add_field(mime, "Content-Type", type); + silc_mime_add_data(mime, ic.data, ic.len); + + obj.mime = icon = silc_mime_encode(mime, &obj.mime_len); + if (obj.mime) + silc_client_attribute_add(client, conn, + SILC_ATTRIBUTE_USER_ICON, &obj, sizeof(obj)); + + silc_free(icon); + g_free(ic.data); + silc_mime_free(mime); +} +#endif
--- a/src/protocols/silc/silc.c Sun Jan 08 01:16:23 2006 +0000 +++ b/src/protocols/silc/silc.c Sun Jan 08 16:17:22 2006 +0000 @@ -206,6 +206,9 @@ if (!gaim_account_get_bool(account, "reject-attrs", FALSE)) { SilcUInt32 mask; const char *tmp; +#ifdef SILC_ATTRIBUTE_USER_ICON + char *icon; +#endif #ifdef HAVE_SYS_UTSNAME_H struct utsname u; #endif @@ -240,6 +243,13 @@ silc_client_attribute_add(client, conn, SILC_ATTRIBUTE_TIMEZONE, (void *)tmp, strlen(tmp)); + +#ifdef SILC_ATTRIBUTE_USER_ICON + /* Set our buddy icon */ + icon = gaim_buddy_icons_get_full_path(gaim_account_get_buddy_icon(account)); + silcgaim_buddy_set_icon(gc, icon); + g_free(icon); +#endif } silc_free(params.detach_data); @@ -1724,7 +1734,11 @@ #endif NULL, /* user_splits */ NULL, /* protocol_options */ - NO_BUDDY_ICONS, /* icon_spec */ +#ifdef SILC_ATTRIBUTE_USER_ICON + {"jpeg,gif,png,bmp", 0, 0, 96, 96, GAIM_ICON_SCALE_DISPLAY}, /* icon_spec */ +#else + NO_BUDDY_ICONS, +#endif silcgaim_list_icon, /* list_icon */ silcgaim_list_emblems, /* list_emblems */ silcgaim_status_text, /* status_text */ @@ -1768,7 +1782,11 @@ NULL, /* buddy_free */ NULL, /* convo_closed */ NULL, /* normalize */ - NULL, /* set_buddy_icon */ +#ifdef SILC_ATTRIBUTE_USER_ICON + silcgaim_buddy_set_icon, /* set_buddy_icon */ +#else + NULL, +#endif NULL, /* remove_group */ NULL, /* get_cb_real_name */ silcgaim_chat_set_topic, /* set_chat_topic */
--- a/src/protocols/silc/silcgaim.h Sun Jan 08 01:16:23 2006 +0000 +++ b/src/protocols/silc/silcgaim.h Sun Jan 08 16:17:22 2006 +0000 @@ -144,6 +144,9 @@ void silcgaim_parse_attrs(SilcDList attrs, char **moodstr, char **statusstr, char **contactstr, char **langstr, char **devicestr, char **tzstr, char **geostr); +#ifdef SILC_ATTRIBUTE_USER_ICON +void silcgaim_buddy_set_icon(GaimConnection *gc, const char *iconfile); +#endif #ifdef HAVE_SILCMIME_H char *silcgaim_file2mime(const char *filename); SilcDList silcgaim_image_message(const char *msg, SilcUInt32 *mflags);