# HG changeset patch # User Christian Hammond # Date 1055495484 0 # Node ID 97d1ad7a50ccb8cb5402b5a51bf92dafc6b620c3 # Parent 8331918af110a157fd64e4e8c800a35b5d15a475 [gaim-migrate @ 6280] Users can now set their Trepia buddy icon. committer: Tailor Script diff -r 8331918af110 -r 97d1ad7a50cc src/protocols/trepia/trepia.c --- a/src/protocols/trepia/trepia.c Fri Jun 13 08:54:02 2003 +0000 +++ b/src/protocols/trepia/trepia.c Fri Jun 13 09:11:24 2003 +0000 @@ -24,6 +24,7 @@ #include "accountopt.h" #include "md5.h" #include "profile.h" +#include #include #include #include @@ -84,6 +85,51 @@ #define TREPIA_PORT 8201 #define TREPIA_REG_PORT 8209 +static const char alphabet[] = + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" + "0123456789+/"; + +static char * +base64_enc(const char *data, int len) +{ + char *dest; + char *buf; + + buf = dest = g_malloc(4 * len / 3 + 4); + + /* Encode 3 bytes at a time */ + while (len >= 3) { + buf[0] = alphabet[(data[0] >> 2) & 0x3F]; + buf[1] = alphabet[((data[0] << 4) & 0x30) | ((data[1] >> 4) & 0x0F)]; + buf[2] = alphabet[((data[1] << 2) & 0x3C) | ((data[2] >> 6) & 0x03)]; + buf[3] = alphabet[data[2] & 0x3F]; + data += 3; + buf += 4; + len -= 3; + } + + if (len > 0) { + buf[0] = alphabet[(data[0] >> 2) & 0x3F]; + buf[1] = alphabet[(data[0] << 4) & 0x30]; + + if (len > 1) { + buf[1] += (data[1] >> 4) & 0x0F; + buf[2] = alphabet[(data[1] << 2) & 0x3C]; + } + + else + buf[2] = '='; + + buf[3] = '='; + buf += 4; + } + + *buf = '\0'; + + return dest; +} + + static int trepia_write(int fd, const char *data, size_t len) { @@ -1100,6 +1146,41 @@ } static void +trepia_set_buddy_icon(GaimConnection *gc, const char *filename) +{ + TrepiaSession *session = gc->proto_data; + struct stat sb; + + if (!stat(filename, &sb)) { + FILE *fp; + + if ((fp = fopen(filename, "rb")) != NULL) { + char *buf = g_malloc(sb.st_size + 1); + char *temp; + char *out_buf; + + fread(buf, 1, sb.st_size, fp); + + buf[sb.st_size] = '\0'; + + temp = base64_enc(buf, sb.st_size); + + out_buf = g_strdup_printf("%s", temp); + + g_free(temp); + g_free(buf); + + fclose(fp); + + if (trepia_write(session->fd, out_buf, strlen(out_buf)) < 0) { + gaim_connection_error(session->gc, _("Write error")); + return; + } + } + } +} + +static void trepia_register_user(GaimAccount *account) { #if 0 @@ -1164,7 +1245,8 @@ NULL, trepia_buddy_free, NULL, - NULL + NULL, + trepia_set_buddy_icon }; static GaimPluginInfo info =