comparison src/protocols/oscar/oscar.c @ 9975:c66345b33b88

[gaim-migrate @ 10886] Steps in the right direction for oscar committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Wed, 08 Sep 2004 03:33:37 +0000
parents 09ed9a574761
children f4ff7d2b9b2c
comparison
equal deleted inserted replaced
9974:37eb241b11ed 9975:c66345b33b88
44 #include "version.h" 44 #include "version.h"
45 45
46 #include "aim.h" 46 #include "aim.h"
47 #include "md5.h" 47 #include "md5.h"
48 48
49 #define UC_AOL 0x02 49 #define AIM_ICQ_STATUS_ID_ONLINE "online"
50 #define UC_ADMIN 0x04 50 #define AIM_ICQ_STATUS_ID_AWAY "away"
51 #define AIM_ICQ_STATUS_ID_DND "dnd"
52 #define AIM_ICQ_STATUS_ID_NA "na"
53 #define AIM_ICQ_STATUS_ID_OCCUPIED "occupied"
54 #define AIM_ICQ_STATUS_ID_FREE4CHAT "free4chat"
55 #define AIM_ICQ_STATUS_ID_INVISIBLE "invisible"
56 #define AIM_ICQ_STATUS_ID_CUSTOM "custom"
57
58 #define UC_UNAVAILABLE 0x01
59 #define UC_AOL 0x02
60 #define UC_ADMIN 0x04
51 #define UC_UNCONFIRMED 0x08 61 #define UC_UNCONFIRMED 0x08
52 #define UC_NORMAL 0x10 62 #define UC_NORMAL 0x10
53 #define UC_AB 0x20 63 #define UC_AB 0x20
54 #define UC_WIRELESS 0x40 64 #define UC_WIRELESS 0x40
55 65
56 #define AIMHASHDATA "http://gaim.sourceforge.net/aim_data.php3" 66 #define AIMHASHDATA "http://gaim.sourceforge.net/aim_data.php3"
57 67
58 #define OSCAR_CONNECT_STEPS 6 68 #define OSCAR_CONNECT_STEPS 6
59 #define OSCAR_DEFAULT_CUSTOM_ENCODING "ISO-8859-1" 69 #define OSCAR_DEFAULT_CUSTOM_ENCODING "ISO-8859-1"
284 static int oscar_sendfile_estblsh(aim_session_t *, aim_frame_t *, ...); 294 static int oscar_sendfile_estblsh(aim_session_t *, aim_frame_t *, ...);
285 static int oscar_sendfile_prompt (aim_session_t *, aim_frame_t *, ...); 295 static int oscar_sendfile_prompt (aim_session_t *, aim_frame_t *, ...);
286 static int oscar_sendfile_ack (aim_session_t *, aim_frame_t *, ...); 296 static int oscar_sendfile_ack (aim_session_t *, aim_frame_t *, ...);
287 static int oscar_sendfile_done (aim_session_t *, aim_frame_t *, ...); 297 static int oscar_sendfile_done (aim_session_t *, aim_frame_t *, ...);
288 298
289 /* for icons */
290 static gboolean gaim_icon_timerfunc(gpointer data); 299 static gboolean gaim_icon_timerfunc(gpointer data);
291
292 /* just because */
293 static void oscar_callback(gpointer data, gint source, GaimInputCondition condition); 300 static void oscar_callback(gpointer data, gint source, GaimInputCondition condition);
294 static void oscar_direct_im_initiate(GaimConnection *gc, const char *who, const char *cookie); 301 static void oscar_direct_im_initiate(GaimConnection *gc, const char *who, const char *cookie);
295
296 /* remove these at some point? */
297 /* Because I don't like forward declarations? I think that was why... */
298 static void oscar_set_info(GaimConnection *gc, const char *text); 302 static void oscar_set_info(GaimConnection *gc, const char *text);
299 static void oscar_set_status(GaimConnection *gc, const char *state, const char *message);
300
301 static void recent_buddies_cb(const char *name, GaimPrefType type, gpointer value, gpointer data); 303 static void recent_buddies_cb(const char *name, GaimPrefType type, gpointer value, gpointer data);
302 304
303 static void oscar_free_name_data(struct name_data *data) { 305 static void oscar_free_name_data(struct name_data *data) {
304 g_free(data->name); 306 g_free(data->name);
305 g_free(data->nick); 307 g_free(data->nick);
461 463
462 if (charset == AIM_CHARSET_UNICODE) { 464 if (charset == AIM_CHARSET_UNICODE) {
463 charsetstr1 = "UCS-2BE"; 465 charsetstr1 = "UCS-2BE";
464 charsetstr2 = "UTF-8"; 466 charsetstr2 = "UTF-8";
465 } else if (charset == AIM_CHARSET_CUSTOM) { 467 } else if (charset == AIM_CHARSET_CUSTOM) {
466 if ((sourcesn != NULL) && isdigit(sourcesn[0])) 468 if ((sourcesn != NULL) && aim_sn_is_icq(sourcesn))
467 charsetstr1 = gaim_account_get_string(account, "encoding", OSCAR_DEFAULT_CUSTOM_ENCODING); 469 charsetstr1 = gaim_account_get_string(account, "encoding", OSCAR_DEFAULT_CUSTOM_ENCODING);
468 else 470 else
469 charsetstr1 = "ISO-8859-1"; 471 charsetstr1 = "ISO-8859-1";
470 charsetstr2 = "UTF-8"; 472 charsetstr2 = "UTF-8";
471 } else if (charset == AIM_CHARSET_ASCII) { 473 } else if (charset == AIM_CHARSET_ASCII) {
512 514
513 /* 515 /*
514 * If we're sending to an ICQ user, and they are advertising the 516 * If we're sending to an ICQ user, and they are advertising the
515 * Unicode capability, then attempt to send as UCS-2BE. 517 * Unicode capability, then attempt to send as UCS-2BE.
516 */ 518 */
517 if ((destsn != NULL) && isdigit(destsn[0])) 519 if ((destsn != NULL) && aim_sn_is_icq(destsn))
518 userinfo = aim_locate_finduserinfo(od->sess, destsn); 520 userinfo = aim_locate_finduserinfo(od->sess, destsn);
519 521
520 if ((userinfo != NULL) && (userinfo->capabilities & AIM_CAPS_ICQUTF8)) { 522 if ((userinfo != NULL) && (userinfo->capabilities & AIM_CAPS_ICQUTF8)) {
521 *msg = g_convert(from, strlen(from), "UCS-2BE", "UTF-8", NULL, msglen, NULL); 523 *msg = g_convert(from, strlen(from), "UCS-2BE", "UTF-8", NULL, msglen, NULL);
522 if (*msg != NULL) { 524 if (*msg != NULL) {
529 /* 531 /*
530 * If this is AIM then attempt to send as ISO-8859-1. If this is 532 * If this is AIM then attempt to send as ISO-8859-1. If this is
531 * ICQ then attempt to send as the user specified character encoding. 533 * ICQ then attempt to send as the user specified character encoding.
532 */ 534 */
533 charsetstr = "ISO-8859-1"; 535 charsetstr = "ISO-8859-1";
534 if ((destsn != NULL) && isdigit(destsn[0])) 536 if ((destsn != NULL) && aim_sn_is_icq(destsn))
535 charsetstr = gaim_account_get_string(account, "encoding", OSCAR_DEFAULT_CUSTOM_ENCODING); 537 charsetstr = gaim_account_get_string(account, "encoding", OSCAR_DEFAULT_CUSTOM_ENCODING);
536 538
537 *msg = g_convert(from, strlen(from), charsetstr, "UTF-8", NULL, msglen, NULL); 539 *msg = g_convert(from, strlen(from), charsetstr, "UTF-8", NULL, msglen, NULL);
538 if (*msg != NULL) { 540 if (*msg != NULL) {
539 *charset = AIM_CHARSET_CUSTOM; 541 *charset = AIM_CHARSET_CUSTOM;
713 if (userinfo != NULL) 715 if (userinfo != NULL)
714 bi = g_hash_table_lookup(od->buddyinfo, gaim_normalize(account, userinfo->sn)); 716 bi = g_hash_table_lookup(od->buddyinfo, gaim_normalize(account, userinfo->sn));
715 717
716 if (b != NULL) { 718 if (b != NULL) {
717 if (GAIM_BUDDY_IS_ONLINE(b)) { 719 if (GAIM_BUDDY_IS_ONLINE(b)) {
718 if (isdigit(b->name[0])) { 720 if (aim_sn_is_icq(b->name)) {
719 tmp = oscar_icqstatus((b->uc & 0xffff0000) >> 16); 721 tmp = oscar_icqstatus((b->uc & 0xffff0000) >> 16);
720 oscar_string_append(str, newline, _("Status"), tmp); 722 oscar_string_append(str, newline, _("Status"), tmp);
721 g_free(tmp); 723 g_free(tmp);
722 } 724 }
723 } else { 725 } else {
1701 buf = g_strdup_printf(_("Unable to login: Could not sign on as %s because the screen name is invalid. Screen names must either start with a letter and contain only letters, numbers and spaces, or contain only numbers."), gaim_account_get_username(account)); 1703 buf = g_strdup_printf(_("Unable to login: Could not sign on as %s because the screen name is invalid. Screen names must either start with a letter and contain only letters, numbers and spaces, or contain only numbers."), gaim_account_get_username(account));
1702 gaim_connection_error(gc, buf); 1704 gaim_connection_error(gc, buf);
1703 g_free(buf); 1705 g_free(buf);
1704 } 1706 }
1705 1707
1706 if (isdigit(*(gaim_account_get_username(account)))) { 1708 if (aim_sn_is_icq((gaim_account_get_username(account)))) {
1707 od->icq = TRUE; 1709 od->icq = TRUE;
1708 } else { 1710 } else {
1709 gc->flags |= GAIM_CONNECTION_HTML; 1711 gc->flags |= GAIM_CONNECTION_HTML;
1710 gc->flags |= GAIM_CONNECTION_AUTO_RESP; 1712 gc->flags |= GAIM_CONNECTION_AUTO_RESP;
1711 } 1713 }
1803 gaim_timeout_remove(od->icontimer); 1805 gaim_timeout_remove(od->icontimer);
1804 if (od->getblisttimer > 0) 1806 if (od->getblisttimer > 0)
1805 gaim_timeout_remove(od->getblisttimer); 1807 gaim_timeout_remove(od->getblisttimer);
1806 if (od->getinfotimer > 0) 1808 if (od->getinfotimer > 0)
1807 gaim_timeout_remove(od->getinfotimer); 1809 gaim_timeout_remove(od->getinfotimer);
1808 gaim_prefs_disconnect_callback(od->recentbuddies->cbid); 1810 gaim_prefs_disconnect_callback(od->recentbuddies_cbid);
1809 1811
1810 aim_session_kill(od->sess); 1812 aim_session_kill(od->sess);
1811 g_free(od->sess); 1813 g_free(od->sess);
1812 od->sess = NULL; 1814 od->sess = NULL;
1813 g_free(gc->proto_data); 1815 g_free(gc->proto_data);
3276 * so any HTML we receive is intended to be displayed 3278 * so any HTML we receive is intended to be displayed
3277 * 3279 *
3278 * Note: There *may* be some clients which send messages as HTML formatted - 3280 * Note: There *may* be some clients which send messages as HTML formatted -
3279 * they need to be special-cased somehow. 3281 * they need to be special-cased somehow.
3280 */ 3282 */
3281 if (isdigit(gaim_account_get_username(account)[0]) && isdigit(userinfo->sn[0])) { 3283 if (aim_sn_is_icq(gaim_account_get_username(account) && aim_sn_is_icq(userinfo->sn)) {
3282 /* being recevied by ICQ from ICQ - escape HTML so it is displayed as sent */ 3284 /* being recevied by ICQ from ICQ - escape HTML so it is displayed as sent */
3283 gchar *tmp2 = gaim_escape_html(tmp); 3285 gchar *tmp2 = gaim_escape_html(tmp);
3284 g_free(tmp); 3286 g_free(tmp);
3285 tmp = tmp2; 3287 tmp = tmp2;
3286 } 3288 }
5411 5413
5412 /* 5414 /*
5413 * If we're IMing an ICQ user then send newlines as CR/LF and 5415 * If we're IMing an ICQ user then send newlines as CR/LF and
5414 * strip all HTML 5416 * strip all HTML
5415 */ 5417 */
5416 if (isdigit(name[0]) ) { 5418 if (aim_sn_is_icq(name) ) {
5417 /* being sent to an ICQ user */ 5419 /* being sent to an ICQ user */
5418 if (!isdigit(gaim_account_get_username(gc->account)[0])) { 5420 if (!aim_sn_is_icq(gaim_account_get_username(gc->account))) {
5419 /* from an AIM user - ICQ receiving from AIM *expects the messsage to be HTML formatted* */ 5421 /* from an AIM user - ICQ receiving from AIM *expects the messsage to be HTML formatted* */
5420 tmpmsg = gaim_str_add_cr(message); 5422 tmpmsg = gaim_str_add_cr(message);
5421 } else { 5423 } else {
5422 /* from an ICQ user - do nothing */ 5424 /* from an ICQ user - do nothing */
5423 tmpmsg = g_strdup(message); 5425 tmpmsg = g_strdup(message);
5424 } 5426 }
5425 } else { 5427 } else {
5426 /* being sent to an AIM user */ 5428 /* being sent to an AIM user */
5427 if (isdigit(gaim_account_get_username(gc->account)[0])) { 5429 if (aim_sn_is_icq(gaim_account_get_username(gc->account))) {
5428 /* from an ICQ user */ 5430 /* from an ICQ user */
5429 tmpmsg2 = gaim_strdup_withhtml(message); 5431 tmpmsg2 = gaim_strdup_withhtml(message);
5430 tmpmsg = gaim_escape_html(tmpmsg2); 5432 tmpmsg = gaim_escape_html(tmpmsg2);
5431 g_free(tmpmsg2); 5433 g_free(tmpmsg2);
5432 } else 5434 } else
5450 } 5452 }
5451 5453
5452 static void oscar_get_info(GaimConnection *gc, const char *name) { 5454 static void oscar_get_info(GaimConnection *gc, const char *name) {
5453 OscarData *od = (OscarData *)gc->proto_data; 5455 OscarData *od = (OscarData *)gc->proto_data;
5454 5456
5455 if (od->icq && isdigit(name[0])) 5457 if (od->icq && aim_sn_is_icq(name))
5456 aim_icq_getallinfo(od->sess, name); 5458 aim_icq_getallinfo(od->sess, name);
5457 else 5459 else
5458 aim_locate_getinfoshort(od->sess, name, 0x00000003); 5460 aim_locate_getinfoshort(od->sess, name, 0x00000003);
5459 } 5461 }
5460 5462
6490 return 0; 6492 return 0;
6491 } 6493 }
6492 6494
6493 static const char *oscar_list_icon(GaimAccount *a, GaimBuddy *b) { 6495 static const char *oscar_list_icon(GaimAccount *a, GaimBuddy *b) {
6494 if (!b || (b && b->name && b->name[0] == '+')) { 6496 if (!b || (b && b->name && b->name[0] == '+')) {
6495 if (a != NULL && isdigit(*gaim_account_get_username(a))) 6497 if (a != NULL && aim_sn_is_icq(gaim_account_get_username(a)))
6496 return "icq"; 6498 return "icq";
6497 else 6499 else
6498 return "aim"; 6500 return "aim";
6499 } 6501 }
6500 6502
6501 if (b != NULL && isdigit(b->name[0])) 6503 if (b != NULL && aim_sn_is_icq(b->name))
6502 return "icq"; 6504 return "icq";
6503 return "aim"; 6505 return "aim";
6504 } 6506 }
6505 6507
6506 static void oscar_list_emblems(GaimBuddy *b, const char **se, const char **sw, const char **nw, const char **ne) 6508 static void oscar_list_emblems(GaimBuddy *b, const char **se, const char **sw, const char **nw, const char **ne)
6530 } else { 6532 } else {
6531 emblems[i++] = "offline"; 6533 emblems[i++] = "offline";
6532 } 6534 }
6533 } 6535 }
6534 6536
6535 if (b->name && (b->uc & 0xffff0000) && isdigit(b->name[0])) { 6537 if (b->name && (b->uc & 0xffff0000) && aim_sn_is_icq(b->name)) {
6536 int uc = b->uc >> 16; 6538 int uc = b->uc >> 16;
6537 if (uc & AIM_ICQ_STATE_INVISIBLE) 6539 if (uc & AIM_ICQ_STATE_INVISIBLE)
6538 emblems[i++] = "invisible"; 6540 emblems[i++] = "invisible";
6539 else if (uc & AIM_ICQ_STATE_CHAT) 6541 else if (uc & AIM_ICQ_STATE_CHAT)
6540 emblems[i++] = "freeforchat"; 6542 emblems[i++] = "freeforchat";
6607 GaimConnection *gc = b->account->gc; 6609 GaimConnection *gc = b->account->gc;
6608 OscarData *od = gc->proto_data; 6610 OscarData *od = gc->proto_data;
6609 gchar *ret = NULL; 6611 gchar *ret = NULL;
6610 6612
6611 if ((b->uc & UC_UNAVAILABLE) || (((b->uc & 0xffff0000) >> 16) & AIM_ICQ_STATE_CHAT)) { 6613 if ((b->uc & UC_UNAVAILABLE) || (((b->uc & 0xffff0000) >> 16) & AIM_ICQ_STATE_CHAT)) {
6612 if (isdigit(b->name[0])) 6614 if (aim_sn_is_icq(b->name))
6613 ret = oscar_icqstatus((b->uc & 0xffff0000) >> 16); 6615 ret = oscar_icqstatus((b->uc & 0xffff0000) >> 16);
6614 else 6616 else
6615 ret = g_strdup(_("Away")); 6617 ret = g_strdup(_("Away"));
6616 } else if (GAIM_BUDDY_IS_ONLINE(b)) { 6618 } else if (GAIM_BUDDY_IS_ONLINE(b)) {
6617 struct buddyinfo *bi = g_hash_table_lookup(od->buddyinfo, gaim_normalize(b->account, b->name)); 6619 struct buddyinfo *bi = g_hash_table_lookup(od->buddyinfo, gaim_normalize(b->account, b->name));
6803 if (od->sess->ssi.received_data) 6805 if (od->sess->ssi.received_data)
6804 aim_ssi_deldeny(od->sess, who); 6806 aim_ssi_deldeny(od->sess, who);
6805 #endif 6807 #endif
6806 } 6808 }
6807 6809
6808 static GList *oscar_status_types(GaimAccount *account) 6810 static GList *
6811 oscar_status_types(GaimAccount *account)
6809 { 6812 {
6810 OscarData *od = gc->proto_data; 6813 GList *status_types = NULL;
6811 GList *m = NULL; 6814 GaimStatusType *type;
6815 gboolean is_icq;
6812 6816
6813 g_return_val_if_fail(account != NULL, NULL); 6817 g_return_val_if_fail(account != NULL, NULL);
6814 6818
6819 is_icq = aim_sn_is_icq(gaim_account_get_username(account));
6820
6821
6822
6823 return status_types;
6824
6825 #if 0 /* STATUS - old stuff that should be removed */
6815 if (od->icq) { 6826 if (od->icq) {
6816 m = g_list_append(m, _("Online")); 6827 m = g_list_append(m, _("Online"));
6817 m = g_list_append(m, _("Away")); 6828 m = g_list_append(m, _("Away"));
6818 m = g_list_append(m, _("Do Not Disturb")); 6829 m = g_list_append(m, _("Do Not Disturb"));
6819 m = g_list_append(m, _("Not Available")); 6830 m = g_list_append(m, _("Not Available"));
6826 m = g_list_append(m, _("Visible")); 6837 m = g_list_append(m, _("Visible"));
6827 m = g_list_append(m, _("Invisible")); 6838 m = g_list_append(m, _("Invisible"));
6828 } 6839 }
6829 6840
6830 return m; 6841 return m;
6842 #endif
6831 } 6843 }
6832 6844
6833 static void oscar_ssi_editcomment(struct name_data *data, const char *text) { 6845 static void oscar_ssi_editcomment(struct name_data *data, const char *text) {
6834 GaimConnection *gc = data->gc; 6846 GaimConnection *gc = data->gc;
6835 OscarData *od = gc->proto_data; 6847 OscarData *od = gc->proto_data;