Mercurial > pidgin.yaz
changeset 5842:dbed8c87f750
[gaim-migrate @ 6273]
Another reason not to use CVS.
This saves your buddy icons to the OSCAR servers (I hope). It's not fully
tested and it may screw things up, but I wanted to get it in CVS so other people
can try to break this, and KingAnt can review my work (that libfaim wizard that
he is.) Don't use CVS.
I'd like to thank Christian Hammond, for his work on the account and prpl APIs
that made it so easy to add the hook into buddy icon changing. I'd like to thank
Mark Doliner for laying most of the groundwork and for his kind words of encouragement.
I'd like to thank myself for making the buddy icon selector real sexy-like. I'd like
to thank the Lord almighty for giving me the strength to do this.
I promised myself I wouldn't cry. I never imagined I'd be committing this.
committer: Tailor Script <tailor@pidgin.im>
author | Sean Egan <seanegan@gmail.com> |
---|---|
date | Thu, 12 Jun 2003 22:19:07 +0000 |
parents | eeb72d03e189 |
children | ec963ca8c9ee |
files | src/account.c src/gaim.h src/gtkaccount.c src/protocols/oscar/aim.h src/protocols/oscar/icon.c src/protocols/oscar/oscar.c src/protocols/oscar/service.c src/protocols/oscar/ssi.c src/prpl.h src/server.c |
diffstat | 10 files changed, 185 insertions(+), 39 deletions(-) [+] |
line wrap: on
line diff
--- a/src/account.c Thu Jun 12 18:17:31 2003 +0000 +++ b/src/account.c Thu Jun 12 22:19:07 2003 +0000 @@ -249,7 +249,9 @@ g_free(account->buddy_icon); account->buddy_icon = (icon == NULL ? NULL : g_strdup(icon)); - + if (account->gc) + serv_set_buddyicon(account->gc, icon); + schedule_accounts_save(); }
--- a/src/gaim.h Thu Jun 12 18:17:31 2003 +0000 +++ b/src/gaim.h Thu Jun 12 22:19:07 2003 +0000 @@ -261,6 +261,7 @@ extern void serv_alias_buddy(struct buddy *); extern void serv_move_buddy(struct buddy *, struct group *, struct group *); extern void serv_rename_group(GaimConnection *, struct group *, const char *); +extern void serv_set_buddyicon(GaimConnection *, const char *); /* Functions in log.h */ extern FILE *open_log_file (const char *, int);
--- a/src/gtkaccount.c Thu Jun 12 18:17:31 2003 +0000 +++ b/src/gtkaccount.c Thu Jun 12 22:19:07 2003 +0000 @@ -210,7 +210,6 @@ static void buddy_icon_filesel_delete_cb (GtkWidget *w, AccountPrefsDialog *dialog) { - gtk_widget_destroy(dialog->buddy_icon_filesel); dialog->buddy_icon_filesel = NULL; } @@ -284,7 +283,7 @@ g_signal_connect(G_OBJECT(dialog->buddy_icon_filesel), "delete-event", G_CALLBACK(buddy_icon_filesel_delete_cb), dialog); g_signal_connect(G_OBJECT(GTK_FILE_SELECTION(dialog->buddy_icon_filesel)->cancel_button), "clicked", - G_CALLBACK(buddy_icon_filesel_delete_cb), dialog); + G_CALLBACK(gtk_widget_destroy), NULL); g_signal_connect(G_OBJECT(GTK_FILE_SELECTION(dialog->buddy_icon_filesel)->ok_button), "clicked", G_CALLBACK(buddy_icon_filesel_choose), dialog);
--- a/src/protocols/oscar/aim.h Thu Jun 12 18:17:31 2003 +0000 +++ b/src/protocols/oscar/aim.h Thu Jun 12 22:19:07 2003 +0000 @@ -1107,7 +1107,7 @@ /* 0x0010 - icon.c */ -faim_export int aim_icon_upload(aim_session_t *sess, int num, const fu8_t *icon, fu16_t iconlen); +faim_export int aim_icon_upload(aim_session_t *sess, aim_conn_t *conn, const fu8_t *icon, fu16_t iconlen); faim_export int aim_icon_request(aim_session_t *sess, const char *sn, const fu8_t *iconstr, fu16_t iconstrlen);
--- a/src/protocols/oscar/icon.c Thu Jun 12 18:17:31 2003 +0000 +++ b/src/protocols/oscar/icon.c Thu Jun 12 22:19:07 2003 +0000 @@ -14,18 +14,17 @@ * * @param sess The oscar session. * @param conn The icon connection for this session. - * @param num The reference number of the icon you are uploading. * @param icon The raw data of the icon image file. * @param iconlen Length of the raw data of the icon image file. * @return Return 0 if no errors, otherwise return the error number. */ -faim_export int aim_icon_upload(aim_session_t *sess, int num, const fu8_t *icon, fu16_t iconlen) +faim_export int aim_icon_upload(aim_session_t *sess, aim_conn_t *conn, const fu8_t *icon, fu16_t iconlen) { aim_conn_t *conn; aim_frame_t *fr; aim_snacid_t snacid; - if (!sess || !(conn = aim_conn_findbygroup(sess, 0x0010)) || !num || !icon || !iconlen) + if (!sess || !(conn = aim_conn_findbygroup(sess, 0x0010)) || !icon || !iconlen) return -EINVAL; if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10 + 2 + 2+iconlen))) @@ -34,7 +33,7 @@ aim_putsnac(&fr->data, 0x0010, 0x0002, 0x0000, snacid); /* The reference number for the icon */ - aimbs_put16(&fr->data, num); + aimbs_put16(&fr->data, 1); /* The icon */ aimbs_put16(&fr->data, iconlen);
--- a/src/protocols/oscar/oscar.c Thu Jun 12 18:17:31 2003 +0000 +++ b/src/protocols/oscar/oscar.c Thu Jun 12 22:19:07 2003 +0000 @@ -51,6 +51,7 @@ #include "core.h" #include "proxy.h" #include "aim.h" +#include "md5.h" #ifdef _WIN32 #include "win32dep.h" @@ -84,6 +85,7 @@ guint icopa; gboolean iconconnecting; + gboolean set_icon; GSList *create_rooms; @@ -96,7 +98,7 @@ gboolean chpass; char *oldp; char *newp; - + GSList *oscar_chats; GSList *direct_ims; GSList *file_transfers; @@ -281,6 +283,8 @@ static int oscar_sendfile_ack (aim_session_t *, aim_frame_t *, ...); static int oscar_sendfile_done (aim_session_t *, aim_frame_t *, ...); +static int gaim_buddyiconreq (aim_session_t *, aim_frame_t *, ...); + /* for icons */ static gboolean gaim_icon_timerfunc(gpointer data); @@ -1143,6 +1147,7 @@ aim_conn_addhandler(sess, bosconn, 0x0009, 0x0001, gaim_parse_genericerr, 0); aim_conn_addhandler(sess, bosconn, 0x0001, 0x001f, gaim_memrequest, 0); aim_conn_addhandler(sess, bosconn, 0x0001, 0x000f, gaim_selfinfo, 0); + aim_conn_addhandler(sess, bosconn, 0x0001, 0x0021, gaim_buddyiconreq,0); aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_ICQ, AIM_CB_ICQ_OFFLINEMSG, gaim_offlinemsg, 0); aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_ICQ, AIM_CB_ICQ_OFFLINEMSGCOMPLETE, gaim_offlinemsgdone, 0); aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_POP, 0x0002, gaim_popup, 0); @@ -3532,12 +3537,6 @@ struct buddyinfo *bi; aim_conn_t *conn; - if (!od->requesticon) { - gaim_debug(GAIM_DEBUG_MISC, "oscar", - "no more icons to request\n"); - return FALSE; - } - conn = aim_getconn_type(od->sess, AIM_CONN_TYPE_ICON); if (!conn && !od->iconconnecting) { aim_reqservice(od->sess, od->conn, AIM_CONN_TYPE_ICON); @@ -3545,6 +3544,38 @@ return FALSE; } + if (od->set_icon) { + const char *iconfile; + if ((iconfile = gaim_account_get_buddy_icon(gaim_connection_get_account(gc)))) { + FILE *file; + struct stat st; + gaim_debug(GAIM_DEBUG_INFO, "Uploading icon: %s\n", iconfile); + if (!stat(iconfile, &st)) { + char *buf = g_malloc(st.st_size); + file = fopen(iconfile, "rb"); + if (file) { + int len = fread(buf, 1, st.st_size, file); + gaim_debug(GAIM_DEBUG_INFO, "oscar", + "Uploading icon to icon server\n"); + aim_icon_upload(od->sess, aim_getconn_type(od->sess, AIM_CONN_TYPE_ICON), buf, st.st_size); + fclose(file); + } else + gaim_debug(GAIM_DEBUG_ERROR, "oscar", + "Can't open buddy icon file!\n"); + g_free(buf); + } else + gaim_debug(GAIM_DEBUG_ERROR, "oscar", + "Can't stat buddy icon file!\n"); + } + od->set_icon = FALSE; + } + + if (!od->requesticon) { + gaim_debug(GAIM_DEBUG_MISC, "oscar", + "no more icons to request\n"); + return FALSE; + } + bi = g_hash_table_lookup(od->buddyinfo, (char *)od->requesticon->data); if (bi && (bi->iconcsumlen > 0)) { aim_icon_request(od->sess, od->requesticon->data, bi->iconcsum, bi->iconcsumlen); @@ -5424,6 +5455,60 @@ return ret; } + +static int gaim_buddyiconreq (aim_session_t *sess, aim_frame_t *fr, ...) { + GaimConnection *gc = sess->aux_data; + struct oscar_data *od = gc->proto_data; + + char *md5 = NULL; + fu16_t type; + fu8_t length, cached; + va_list ap; + va_start(ap, fr); + type = va_arg(ap, int); + switch (type) { + case 0x0001: + case 0x0000: + cached = va_arg(ap, int); + length = va_arg(ap, int); + md5 = va_arg(ap, char*); + break; + } + va_end(ap); + if (cached == 0x41) { + if (!aim_getconn_type(od->sess, AIM_CONN_TYPE_ICON) && !od->iconconnecting) { + od->iconconnecting = TRUE; + od->set_icon = TRUE; + aim_reqservice(od->sess, od->conn, AIM_CONN_TYPE_ICON); + } else { + const char *iconfile; + if ((iconfile = gaim_account_get_buddy_icon(gaim_connection_get_account(gc)))) { + FILE *file; + struct stat st; + + if (!stat(iconfile, &st)) { + char *buf = g_malloc(st.st_size); + file = fopen(iconfile, "rb"); + if (file) { + int len = fread(buf, 1, st.st_size, file); + gaim_debug(GAIM_DEBUG_INFO, "oscar", + "Uploading icon to icon server\n"); + aim_icon_upload(od->sess, aim_getconn_type(od->sess, AIM_CONN_TYPE_ICON), buf, st.st_size); + fclose(file); + } else + gaim_debug(GAIM_DEBUG_ERROR, "oscar", + "Can't open buddy icon file!\n"); + g_free(buf); + } else + gaim_debug(GAIM_DEBUG_ERROR, "oscar", + "Can't stat buddy icon file!\n"); + } + } + } else if (cached == 0x81) + aim_ssi_seticon(od->sess, md5, length); +} + + /* * We have just established a socket with the other dude, so set up some handlers. */ @@ -5929,6 +6014,37 @@ g_free(substituted); } +static void oscar_set_icon(GaimConnection *gc, const char *iconfile) +{ + struct oscar_data *od; + aim_session_t *sess; + od = gc->proto_data; + FILE *file; + struct stat st; + sess = od->sess; + if (!stat(iconfile, &st)) { + char *buf = g_malloc(st.st_size); + file = fopen(iconfile, "rb"); + if (file) { + int len = fread(buf, 1, st.st_size, file); + char md5[16]; + md5_state_t *state = g_malloc(sizeof(md5_state_t)); + md5_init(state); + md5_append(state, buf, len); + md5_finish(state, md5); + fclose(file); + g_free(state); + aim_ssi_seticon(sess, md5, 16); + } else + gaim_debug(GAIM_DEBUG_ERROR, "oscar", + "Can't open buddy icon file!\n"); + g_free(buf); + } else + gaim_debug(GAIM_DEBUG_ERROR, "oscar", + "Can't stat buddy icon file!\n"); +} + + static GList *oscar_actions(GaimConnection *gc) { struct oscar_data *od = gc->proto_data; @@ -5959,9 +6075,9 @@ /* AIM actions */ m = g_list_append(m, NULL); - pam = g_new0(struct proto_actions_menu, 1); + pam = g_new0(struct proto_actions_menu, 1); pam->label = _("Format Screenname"); - pam->callback = oscar_show_format_screenname; + pam->callback = oscar_format_screenname; pam->gc = gc; m = g_list_append(m, pam); @@ -6099,7 +6215,8 @@ #endif NULL, oscar_convo_closed, - NULL + NULL, + oscar_set_icon }; static GaimPluginInfo info =
--- a/src/protocols/oscar/service.c Thu Jun 12 18:17:31 2003 +0000 +++ b/src/protocols/oscar/service.c Thu Jun 12 22:19:07 2003 +0000 @@ -946,26 +946,38 @@ * Subtype 0x0021 - Receive our extended status * * This is used for MAC non-away "away" messages, and maybe ICQ extended status messages? + * It's also used to tell the client whether or not it needs to upload an SSI buddy icon... who engineers this stuff, anyway? */ static int aim_parse_extstatus(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs) { - int ret = 0; + int ret = 0, i; aim_rxcallback_t userfunc; - char *msg = NULL; + char *msg = NULL, *md5 = NULL; fu16_t type; - fu8_t number, length; + fu8_t number, length, cached; - type = aimbs_get16(bs); /* 0x0002 */ - number = aimbs_get8(bs); /* 0x04 */ - length = aimbs_get8(bs); /* the first length */ - msg = aimbs_getstr(bs, aimbs_get16(bs)); /* the second length is just for the message */ - - if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) - ret = userfunc(sess, rx, msg); - - free(msg); - - return ret; + type = aimbs_get16(bs); + printf("blah: %d\n", type); + if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) { + switch (type) { + case 0x0001: + case 0x0000: /* not sure what the difference between 1 and 0 is */ + cached = aimbs_get8(bs); + length = aimbs_get8(bs); + md5 = aimbs_getraw(bs, length); + ret = userfunc(sess, rx, type, cached, length, md5); + free(md5); + break; + case 0x0002: + number = aimbs_get8(bs); /* 0x04 */ + length = aimbs_get8(bs); /* the first length */ + msg = aimbs_getstr(bs, aimbs_get16(bs)); /* the second length is just for the message */ + ret = userfunc(sess, rx, msg); + free(msg); + break; + } + return ret; + } } static int snachandler(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
--- a/src/protocols/oscar/ssi.c Thu Jun 12 18:17:31 2003 +0000 +++ b/src/protocols/oscar/ssi.c Thu Jun 12 22:19:07 2003 +0000 @@ -1023,7 +1023,7 @@ * * @param sess The oscar session. * @param iconcsum The MD5 checksum of the icon you are using. - * @param iconcsumlen Length of the MD5 checksum given above. Should be 10 bytes. + * @param iconcsumlen Length of the MD5 checksum given above. Should be 0x10 bytes. * @return Return 0 if no errors, otherwise return the error number. */ faim_export int aim_ssi_seticon(aim_session_t *sess, fu8_t *iconsum, fu16_t iconsumlen) @@ -1035,30 +1035,31 @@ if (!sess || !iconsum || !iconsumlen) return -EINVAL; - /* Create the data for the TLV containing the icon checksum */ if (!(csumdata = (fu8_t *)malloc((iconsumlen+2)*sizeof(fu8_t)))) return -ENOMEM; csumdata[0] = 0x00; csumdata[1] = 0x10; memcpy(&csumdata[2], iconsum, iconsumlen); + + + /* Need to add the x00d5 TLV to the TLV chain */ + aim_addtlvtochain_raw(&data, 0x00d5, (iconsumlen+2) * sizeof(fu8_t), csumdata); - /* Need to add the x0131 TLV to the TLV chain */ + /* This TLV is added to cache the icon. */ aim_addtlvtochain_noval(&data, 0x0131); - /* Need to add the x00d5 TLV to the TLV chain */ - aim_addtlvtochain_raw(&data, 0x00d5, 0x0012, csumdata); if ((tmp = aim_ssi_itemlist_finditem(sess->ssi.local, NULL, "0", AIM_SSI_TYPE_ICONINFO))) { aim_freetlvchain(&tmp->data); tmp->data = data; } else { - tmp = aim_ssi_itemlist_add(&sess->ssi.local, "0", 0x0000, 0xFFFF, AIM_SSI_TYPE_ICONINFO, data); + tmp = aim_ssi_itemlist_add(&sess->ssi.local, "1", 0x0000, 0x51F4, AIM_SSI_TYPE_ICONINFO, data); aim_freetlvchain(&data); } /* Sync our local list with the server list */ aim_ssi_sync(sess); - + free(csumdata); return 0; }
--- a/src/prpl.h Thu Jun 12 18:17:31 2003 +0000 +++ b/src/prpl.h Thu Jun 12 22:19:07 2003 +0000 @@ -293,6 +293,8 @@ void (*convo_closed)(GaimConnection *, char *who); char *(*normalize)(const char *); + + void (*set_buddy_icon)(GaimConnection *, const char *filename); }; #define GAIM_IS_PROTOCOL_PLUGIN(plugin) \
--- a/src/server.c Thu Jun 12 18:17:31 2003 +0000 +++ b/src/server.c Thu Jun 12 22:19:07 2003 +0000 @@ -691,6 +691,18 @@ return val; } +void serv_set_buddyicon(GaimConnection *gc, const char *filename) +{ + GaimPluginProtocolInfo *prpl_info = NULL; + + if (gc->prpl != NULL) + prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl); + + if (prpl_info && prpl_info->set_buddy_icon) + prpl_info->set_buddy_icon(gc, filename); + +} + int find_queue_row_by_name(char *name) { gchar *temp; @@ -1484,3 +1496,4 @@ gtk_imhtml_append_text(GTK_IMHTML(text), msg, -1, GTK_IMHTML_NO_NEWLINE); } +