comparison src/protocols/oscar/oscar.c @ 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 a48c338dff6c
children db5aa27cb345
comparison
equal deleted inserted replaced
5841:eeb72d03e189 5842:dbed8c87f750
49 #include "multi.h" 49 #include "multi.h"
50 #include "prpl.h" 50 #include "prpl.h"
51 #include "core.h" 51 #include "core.h"
52 #include "proxy.h" 52 #include "proxy.h"
53 #include "aim.h" 53 #include "aim.h"
54 #include "md5.h"
54 55
55 #ifdef _WIN32 56 #ifdef _WIN32
56 #include "win32dep.h" 57 #include "win32dep.h"
57 #endif 58 #endif
58 59
82 guint paspa; 83 guint paspa;
83 guint emlpa; 84 guint emlpa;
84 guint icopa; 85 guint icopa;
85 86
86 gboolean iconconnecting; 87 gboolean iconconnecting;
88 gboolean set_icon;
87 89
88 GSList *create_rooms; 90 GSList *create_rooms;
89 91
90 gboolean conf; 92 gboolean conf;
91 gboolean reqemail; 93 gboolean reqemail;
94 gboolean setnick; 96 gboolean setnick;
95 char *newsn; 97 char *newsn;
96 gboolean chpass; 98 gboolean chpass;
97 char *oldp; 99 char *oldp;
98 char *newp; 100 char *newp;
99 101
100 GSList *oscar_chats; 102 GSList *oscar_chats;
101 GSList *direct_ims; 103 GSList *direct_ims;
102 GSList *file_transfers; 104 GSList *file_transfers;
103 GHashTable *buddyinfo; 105 GHashTable *buddyinfo;
104 GSList *requesticon; 106 GSList *requesticon;
278 /* for file transfer */ 280 /* for file transfer */
279 static int oscar_sendfile_estblsh(aim_session_t *, aim_frame_t *, ...); 281 static int oscar_sendfile_estblsh(aim_session_t *, aim_frame_t *, ...);
280 static int oscar_sendfile_prompt (aim_session_t *, aim_frame_t *, ...); 282 static int oscar_sendfile_prompt (aim_session_t *, aim_frame_t *, ...);
281 static int oscar_sendfile_ack (aim_session_t *, aim_frame_t *, ...); 283 static int oscar_sendfile_ack (aim_session_t *, aim_frame_t *, ...);
282 static int oscar_sendfile_done (aim_session_t *, aim_frame_t *, ...); 284 static int oscar_sendfile_done (aim_session_t *, aim_frame_t *, ...);
285
286 static int gaim_buddyiconreq (aim_session_t *, aim_frame_t *, ...);
283 287
284 /* for icons */ 288 /* for icons */
285 static gboolean gaim_icon_timerfunc(gpointer data); 289 static gboolean gaim_icon_timerfunc(gpointer data);
286 290
287 /* prpl actions - remove this at some point */ 291 /* prpl actions - remove this at some point */
1141 aim_conn_addhandler(sess, bosconn, 0x0001, 0x0001, gaim_parse_genericerr, 0); 1145 aim_conn_addhandler(sess, bosconn, 0x0001, 0x0001, gaim_parse_genericerr, 0);
1142 aim_conn_addhandler(sess, bosconn, 0x0003, 0x0001, gaim_parse_genericerr, 0); 1146 aim_conn_addhandler(sess, bosconn, 0x0003, 0x0001, gaim_parse_genericerr, 0);
1143 aim_conn_addhandler(sess, bosconn, 0x0009, 0x0001, gaim_parse_genericerr, 0); 1147 aim_conn_addhandler(sess, bosconn, 0x0009, 0x0001, gaim_parse_genericerr, 0);
1144 aim_conn_addhandler(sess, bosconn, 0x0001, 0x001f, gaim_memrequest, 0); 1148 aim_conn_addhandler(sess, bosconn, 0x0001, 0x001f, gaim_memrequest, 0);
1145 aim_conn_addhandler(sess, bosconn, 0x0001, 0x000f, gaim_selfinfo, 0); 1149 aim_conn_addhandler(sess, bosconn, 0x0001, 0x000f, gaim_selfinfo, 0);
1150 aim_conn_addhandler(sess, bosconn, 0x0001, 0x0021, gaim_buddyiconreq,0);
1146 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_ICQ, AIM_CB_ICQ_OFFLINEMSG, gaim_offlinemsg, 0); 1151 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_ICQ, AIM_CB_ICQ_OFFLINEMSG, gaim_offlinemsg, 0);
1147 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_ICQ, AIM_CB_ICQ_OFFLINEMSGCOMPLETE, gaim_offlinemsgdone, 0); 1152 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_ICQ, AIM_CB_ICQ_OFFLINEMSGCOMPLETE, gaim_offlinemsgdone, 0);
1148 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_POP, 0x0002, gaim_popup, 0); 1153 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_POP, 0x0002, gaim_popup, 0);
1149 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_ICQ, AIM_CB_ICQ_ALIAS, gaim_icqalias, 0); 1154 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_ICQ, AIM_CB_ICQ_ALIAS, gaim_icqalias, 0);
1150 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_ICQ, AIM_CB_ICQ_INFO, gaim_icqinfo, 0); 1155 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_ICQ, AIM_CB_ICQ_INFO, gaim_icqinfo, 0);
3530 GaimConnection *gc = data; 3535 GaimConnection *gc = data;
3531 struct oscar_data *od = gc->proto_data; 3536 struct oscar_data *od = gc->proto_data;
3532 struct buddyinfo *bi; 3537 struct buddyinfo *bi;
3533 aim_conn_t *conn; 3538 aim_conn_t *conn;
3534 3539
3535 if (!od->requesticon) {
3536 gaim_debug(GAIM_DEBUG_MISC, "oscar",
3537 "no more icons to request\n");
3538 return FALSE;
3539 }
3540
3541 conn = aim_getconn_type(od->sess, AIM_CONN_TYPE_ICON); 3540 conn = aim_getconn_type(od->sess, AIM_CONN_TYPE_ICON);
3542 if (!conn && !od->iconconnecting) { 3541 if (!conn && !od->iconconnecting) {
3543 aim_reqservice(od->sess, od->conn, AIM_CONN_TYPE_ICON); 3542 aim_reqservice(od->sess, od->conn, AIM_CONN_TYPE_ICON);
3544 od->iconconnecting = TRUE; 3543 od->iconconnecting = TRUE;
3544 return FALSE;
3545 }
3546
3547 if (od->set_icon) {
3548 const char *iconfile;
3549 if ((iconfile = gaim_account_get_buddy_icon(gaim_connection_get_account(gc)))) {
3550 FILE *file;
3551 struct stat st;
3552 gaim_debug(GAIM_DEBUG_INFO, "Uploading icon: %s\n", iconfile);
3553 if (!stat(iconfile, &st)) {
3554 char *buf = g_malloc(st.st_size);
3555 file = fopen(iconfile, "rb");
3556 if (file) {
3557 int len = fread(buf, 1, st.st_size, file);
3558 gaim_debug(GAIM_DEBUG_INFO, "oscar",
3559 "Uploading icon to icon server\n");
3560 aim_icon_upload(od->sess, aim_getconn_type(od->sess, AIM_CONN_TYPE_ICON), buf, st.st_size);
3561 fclose(file);
3562 } else
3563 gaim_debug(GAIM_DEBUG_ERROR, "oscar",
3564 "Can't open buddy icon file!\n");
3565 g_free(buf);
3566 } else
3567 gaim_debug(GAIM_DEBUG_ERROR, "oscar",
3568 "Can't stat buddy icon file!\n");
3569 }
3570 od->set_icon = FALSE;
3571 }
3572
3573 if (!od->requesticon) {
3574 gaim_debug(GAIM_DEBUG_MISC, "oscar",
3575 "no more icons to request\n");
3545 return FALSE; 3576 return FALSE;
3546 } 3577 }
3547 3578
3548 bi = g_hash_table_lookup(od->buddyinfo, (char *)od->requesticon->data); 3579 bi = g_hash_table_lookup(od->buddyinfo, (char *)od->requesticon->data);
3549 if (bi && (bi->iconcsumlen > 0)) { 3580 if (bi && (bi->iconcsumlen > 0)) {
5422 } 5453 }
5423 5454
5424 return ret; 5455 return ret;
5425 } 5456 }
5426 5457
5458
5459 static int gaim_buddyiconreq (aim_session_t *sess, aim_frame_t *fr, ...) {
5460 GaimConnection *gc = sess->aux_data;
5461 struct oscar_data *od = gc->proto_data;
5462
5463 char *md5 = NULL;
5464 fu16_t type;
5465 fu8_t length, cached;
5466 va_list ap;
5467 va_start(ap, fr);
5468 type = va_arg(ap, int);
5469 switch (type) {
5470 case 0x0001:
5471 case 0x0000:
5472 cached = va_arg(ap, int);
5473 length = va_arg(ap, int);
5474 md5 = va_arg(ap, char*);
5475 break;
5476 }
5477 va_end(ap);
5478 if (cached == 0x41) {
5479 if (!aim_getconn_type(od->sess, AIM_CONN_TYPE_ICON) && !od->iconconnecting) {
5480 od->iconconnecting = TRUE;
5481 od->set_icon = TRUE;
5482 aim_reqservice(od->sess, od->conn, AIM_CONN_TYPE_ICON);
5483 } else {
5484 const char *iconfile;
5485 if ((iconfile = gaim_account_get_buddy_icon(gaim_connection_get_account(gc)))) {
5486 FILE *file;
5487 struct stat st;
5488
5489 if (!stat(iconfile, &st)) {
5490 char *buf = g_malloc(st.st_size);
5491 file = fopen(iconfile, "rb");
5492 if (file) {
5493 int len = fread(buf, 1, st.st_size, file);
5494 gaim_debug(GAIM_DEBUG_INFO, "oscar",
5495 "Uploading icon to icon server\n");
5496 aim_icon_upload(od->sess, aim_getconn_type(od->sess, AIM_CONN_TYPE_ICON), buf, st.st_size);
5497 fclose(file);
5498 } else
5499 gaim_debug(GAIM_DEBUG_ERROR, "oscar",
5500 "Can't open buddy icon file!\n");
5501 g_free(buf);
5502 } else
5503 gaim_debug(GAIM_DEBUG_ERROR, "oscar",
5504 "Can't stat buddy icon file!\n");
5505 }
5506 }
5507 } else if (cached == 0x81)
5508 aim_ssi_seticon(od->sess, md5, length);
5509 }
5510
5511
5427 /* 5512 /*
5428 * We have just established a socket with the other dude, so set up some handlers. 5513 * We have just established a socket with the other dude, so set up some handlers.
5429 */ 5514 */
5430 static int gaim_odc_initiate(aim_session_t *sess, aim_frame_t *fr, ...) { 5515 static int gaim_odc_initiate(aim_session_t *sess, aim_frame_t *fr, ...) {
5431 GaimConnection *gc = sess->aux_data; 5516 GaimConnection *gc = sess->aux_data;
5927 gchar *substituted = gaim_strreplace(od->sess->authinfo->chpassurl, "%s", gaim_account_get_username(gaim_connection_get_account(gc))); 6012 gchar *substituted = gaim_strreplace(od->sess->authinfo->chpassurl, "%s", gaim_account_get_username(gaim_connection_get_account(gc)));
5928 open_url(NULL, substituted); 6013 open_url(NULL, substituted);
5929 g_free(substituted); 6014 g_free(substituted);
5930 } 6015 }
5931 6016
6017 static void oscar_set_icon(GaimConnection *gc, const char *iconfile)
6018 {
6019 struct oscar_data *od;
6020 aim_session_t *sess;
6021 od = gc->proto_data;
6022 FILE *file;
6023 struct stat st;
6024 sess = od->sess;
6025 if (!stat(iconfile, &st)) {
6026 char *buf = g_malloc(st.st_size);
6027 file = fopen(iconfile, "rb");
6028 if (file) {
6029 int len = fread(buf, 1, st.st_size, file);
6030 char md5[16];
6031 md5_state_t *state = g_malloc(sizeof(md5_state_t));
6032 md5_init(state);
6033 md5_append(state, buf, len);
6034 md5_finish(state, md5);
6035 fclose(file);
6036 g_free(state);
6037 aim_ssi_seticon(sess, md5, 16);
6038 } else
6039 gaim_debug(GAIM_DEBUG_ERROR, "oscar",
6040 "Can't open buddy icon file!\n");
6041 g_free(buf);
6042 } else
6043 gaim_debug(GAIM_DEBUG_ERROR, "oscar",
6044 "Can't stat buddy icon file!\n");
6045 }
6046
6047
5932 static GList *oscar_actions(GaimConnection *gc) 6048 static GList *oscar_actions(GaimConnection *gc)
5933 { 6049 {
5934 struct oscar_data *od = gc->proto_data; 6050 struct oscar_data *od = gc->proto_data;
5935 struct proto_actions_menu *pam; 6051 struct proto_actions_menu *pam;
5936 GList *m = NULL; 6052 GList *m = NULL;
5957 6073
5958 if (!od->icq) { 6074 if (!od->icq) {
5959 /* AIM actions */ 6075 /* AIM actions */
5960 m = g_list_append(m, NULL); 6076 m = g_list_append(m, NULL);
5961 6077
5962 pam = g_new0(struct proto_actions_menu, 1); 6078 pam = g_new0(struct proto_actions_menu, 1);
5963 pam->label = _("Format Screenname"); 6079 pam->label = _("Format Screenname");
5964 pam->callback = oscar_show_format_screenname; 6080 pam->callback = oscar_format_screenname;
5965 pam->gc = gc; 6081 pam->gc = gc;
5966 m = g_list_append(m, pam); 6082 m = g_list_append(m, pam);
5967 6083
5968 pam = g_new0(struct proto_actions_menu, 1); 6084 pam = g_new0(struct proto_actions_menu, 1);
5969 pam->label = _("Confirm Account"); 6085 pam->label = _("Confirm Account");
6097 NULL, 6213 NULL,
6098 NULL, 6214 NULL,
6099 #endif 6215 #endif
6100 NULL, 6216 NULL,
6101 oscar_convo_closed, 6217 oscar_convo_closed,
6102 NULL 6218 NULL,
6219 oscar_set_icon
6103 }; 6220 };
6104 6221
6105 static GaimPluginInfo info = 6222 static GaimPluginInfo info =
6106 { 6223 {
6107 2, /**< api_version */ 6224 2, /**< api_version */