comparison src/protocols/oscar/oscar.c @ 9991:cc4b2125d05d

[gaim-migrate @ 10904] Some oscar status fixes/changes from Dave West and I, and other odds n' ends. It's dinner and Jeopardy! time, then Smallville and some bar or something with someone cool. committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Wed, 08 Sep 2004 22:58:12 +0000
parents d770673338f4
children 7596ad640b56
comparison
equal deleted inserted replaced
9990:bd5517471d99 9991:cc4b2125d05d
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 OSCAR_STATUS_ID_AVAILABLE "available"
50 #define OSCAR_STATUS_ID_INVISIBLE "invisible" 49 #define OSCAR_STATUS_ID_INVISIBLE "invisible"
51 #define OSCAR_STATUS_ID_OFFLINE "offline" 50 #define OSCAR_STATUS_ID_OFFLINE "offline"
52 #define OSCAR_STATUS_ID_ONLINE "online" 51 #define OSCAR_STATUS_ID_ONLINE "online"
52 #define OSCAR_STATUS_ID_AVAILABLE "available"
53 #define OSCAR_STATUS_ID_AWAY "away" 53 #define OSCAR_STATUS_ID_AWAY "away"
54 #define OSCAR_STATUS_ID_DND "dnd" 54 #define OSCAR_STATUS_ID_DND "dnd"
55 #define OSCAR_STATUS_ID_NA "na" 55 #define OSCAR_STATUS_ID_NA "na"
56 #define OSCAR_STATUS_ID_OCCUPIED "occupied" 56 #define OSCAR_STATUS_ID_OCCUPIED "occupied"
57 #define OSCAR_STATUS_ID_FREE4CHAT "free4chat" 57 #define OSCAR_STATUS_ID_FREE4CHAT "free4chat"
5528 g_free(text_html); 5528 g_free(text_html);
5529 5529
5530 return; 5530 return;
5531 } 5531 }
5532 5532
5533 static void oscar_set_status_aim(GaimAccount *account, GaimStatus *status) 5533 static void
5534 oscar_set_status_aim(GaimAccount *account, GaimStatus *status)
5534 { 5535 {
5535 OscarData *od; 5536 GaimConnection *gc = gaim_account_get_connection(account);
5537 OscarData *od = (OscarData *)gc->proto_data;
5538 GaimStatusType *statusType;
5539 GaimStatusPrimitive primitive;
5540 GaimPresence *presence;
5541 const gchar *status_id;
5536 int charset = 0; 5542 int charset = 0;
5537 gchar *text_html = NULL; 5543 gchar *text_html = NULL;
5538 const gchar *state;
5539 char *msg = NULL; 5544 char *msg = NULL;
5540 gsize msglen = 0; 5545 gsize msglen = 0;
5541 5546
5542 od = (OscarData *)account->gc->proto_data; 5547 statusType = gaim_status_get_type(status);
5543 state = gaim_status_get_name(status); 5548 primitive = gaim_status_type_get_primitive(statusType);
5544 5549 status_id = gaim_status_get_id(status);
5545 if (!strcmp(state, _("Visible"))) { 5550 presence = gaim_account_get_presence(account);
5551
5552 if (primitive == GAIM_STATUS_HIDDEN)
5553 aim_setextstatus(od->sess, AIM_ICQ_STATE_INVISIBLE);
5554 else
5546 aim_setextstatus(od->sess, AIM_ICQ_STATE_NORMAL); 5555 aim_setextstatus(od->sess, AIM_ICQ_STATE_NORMAL);
5547 return; 5556
5548 } else if (!strcmp(state, _("Invisible"))) {
5549 aim_setextstatus(od->sess, AIM_ICQ_STATE_INVISIBLE);
5550 return;
5551 } /* else... */
5552
5553 if (!strcmp(state, _("Back"))) {
5554 /* If this is our only online account then globally set Gaim not-away */
5555 GList *gcs = gaim_connections_get_all();
5556 if (gcs->next == NULL)
5557 ; /* XXX do_im_back(NULL, NULL); */
5558 }
5559 5557
5560 aim_setextstatus(od->sess, AIM_ICQ_STATE_NORMAL); 5558 aim_setextstatus(od->sess, AIM_ICQ_STATE_NORMAL);
5561 5559
5562 if (od->rights.maxawaymsglen == 0) 5560 if (od->rights.maxawaymsglen == 0)
5563 gaim_notify_warning(account->gc, NULL, _("Unable to set AIM away message."), 5561 gaim_notify_warning(gc, NULL, _("Unable to set AIM away message."),
5564 _("You have probably requested to set your " 5562 _("You have probably requested to set your "
5565 "away message before the login procedure " 5563 "away message before the login procedure "
5566 "completed. You remain in a \"present\" " 5564 "completed. You remain in a \"present\" "
5567 "state; try setting it again when you are " 5565 "state; try setting it again when you are "
5568 "fully connected.")); 5566 "fully connected."));
5569 5567
5570 #if 0 /* this needs to be fixed when we have the custom away messages setup below */ 5568 status_id = gaim_status_get_name(status);
5571 if (!text) { 5569 if (status_id == NULL) {
5572 aim_locate_setprofile(od->sess, NULL, NULL, 0, NULL, "", 0); 5570 aim_locate_setprofile(od->sess, NULL, NULL, 0, NULL, "", 0);
5573 return; 5571 return;
5574 } 5572 }
5575 5573 text_html = gaim_strdup_withhtml(status_id);
5576 text_html = gaim_strdup_withhtml(text); 5574
5577 charset = oscar_charset_check(text_html); 5575 charset = oscar_charset_check(text_html);
5578 if (charset == AIM_CHARSET_UNICODE) { 5576 if (charset == AIM_CHARSET_UNICODE) {
5579 msg = g_convert(text_html, strlen(text_html), "UCS-2BE", "UTF-8", NULL, &msglen, NULL); 5577 msg = g_convert(text_html, strlen(text_html), "UCS-2BE", "UTF-8", NULL, &msglen, NULL);
5580 aim_locate_setprofile(od->sess, NULL, NULL, 0, "unicode-2-0", msg, 5578 aim_locate_setprofile(od->sess, NULL, NULL, 0, "unicode-2-0", msg,
5581 (msglen > od->rights.maxawaymsglen ? od->rights.maxawaymsglen : msglen)); 5579 (msglen > od->rights.maxawaymsglen ? od->rights.maxawaymsglen : msglen));
5582 g_free(msg); 5580 g_free(msg);
5583 gc->away = g_strndup(text, od->rights.maxawaymsglen/2);
5584 } else if (charset == AIM_CHARSET_CUSTOM) { 5581 } else if (charset == AIM_CHARSET_CUSTOM) {
5585 msg = g_convert(text_html, strlen(text_html), "ISO-8859-1", "UTF-8", NULL, &msglen, NULL); 5582 msg = g_convert(text_html, strlen(text_html), "ISO-8859-1", "UTF-8", NULL, &msglen, NULL);
5586 aim_locate_setprofile(od->sess, NULL, NULL, 0, "iso-8859-1", msg, 5583 aim_locate_setprofile(od->sess, NULL, NULL, 0, "iso-8859-1", msg,
5587 (msglen > od->rights.maxawaymsglen ? od->rights.maxawaymsglen : msglen)); 5584 (msglen > od->rights.maxawaymsglen ? od->rights.maxawaymsglen : msglen));
5588 g_free(msg); 5585 g_free(msg);
5589 gc->away = g_strndup(text_html, od->rights.maxawaymsglen);
5590 } else { 5586 } else {
5591 msglen = strlen(text_html); 5587 msglen = strlen(text_html);
5592 aim_locate_setprofile(od->sess, NULL, NULL, 0, "us-ascii", text_html, 5588 aim_locate_setprofile(od->sess, NULL, NULL, 0, "us-ascii", text_html,
5593 (msglen > od->rights.maxawaymsglen ? od->rights.maxawaymsglen : msglen)); 5589 (msglen > od->rights.maxawaymsglen ? od->rights.maxawaymsglen : msglen));
5594 gc->away = g_strndup(text_html, od->rights.maxawaymsglen);
5595 } 5590 }
5596 5591
5597 if (msglen > od->rights.maxawaymsglen) { 5592 if (msglen > od->rights.maxawaymsglen) {
5598 gchar *errstr; 5593 gchar *errstr;
5599 5594
5605 gaim_notify_warning(gc, NULL, _("Away message too long."), errstr); 5600 gaim_notify_warning(gc, NULL, _("Away message too long."), errstr);
5606 g_free(errstr); 5601 g_free(errstr);
5607 } 5602 }
5608 5603
5609 g_free(text_html); 5604 g_free(text_html);
5610 #endif
5611 5605
5612 return; 5606 return;
5613 } 5607 }
5614 5608
5615 static void oscar_set_status_icq(GaimAccount *account, GaimStatus *status) 5609 static void
5610 oscar_set_status_icq(GaimAccount *account, GaimStatus *status)
5616 { 5611 {
5617 OscarData *od = (OscarData *)account->gc->proto_data; 5612 GaimConnection *gc = gaim_account_get_connection(account);
5618 const gchar *state = gaim_status_get_name(status); 5613 OscarData *od = (OscarData *)gc->proto_data;
5619 5614 const gchar *status_id = gaim_status_get_id(status);
5620 if (strcmp(state, _("Invisible"))) 5615
5616 if (gaim_status_type_get_primitive(gaim_status_get_type(status)) == GAIM_STATUS_HIDDEN)
5621 account->perm_deny = 4; 5617 account->perm_deny = 4;
5622 else 5618 else
5623 account->perm_deny = 3; 5619 account->perm_deny = 3;
5620
5624 if ((od->sess->ssi.received_data) && (aim_ssi_getpermdeny(od->sess->ssi.local) != account->perm_deny)) 5621 if ((od->sess->ssi.received_data) && (aim_ssi_getpermdeny(od->sess->ssi.local) != account->perm_deny))
5625 aim_ssi_setpermdeny(od->sess, account->perm_deny, 0xffffffff); 5622 aim_ssi_setpermdeny(od->sess, account->perm_deny, 0xffffffff);
5626 5623
5627 if (!strcmp(state, _("Online"))) 5624 if (!strcmp(status_id, OSCAR_STATUS_ID_ONLINE))
5628 aim_setextstatus(od->sess, AIM_ICQ_STATE_NORMAL); 5625 aim_setextstatus(od->sess, AIM_ICQ_STATE_NORMAL);
5629 else if (!strcmp(state, _("Away"))) { 5626
5627 else if (!strcmp(status_id, OSCAR_STATUS_ID_AWAY))
5630 aim_setextstatus(od->sess, AIM_ICQ_STATE_AWAY); 5628 aim_setextstatus(od->sess, AIM_ICQ_STATE_AWAY);
5631 } else if (!strcmp(state, _("Do Not Disturb"))) { 5629
5630 else if (!strcmp(status_id, OSCAR_STATUS_ID_DND))
5632 aim_setextstatus(od->sess, AIM_ICQ_STATE_AWAY | AIM_ICQ_STATE_DND | AIM_ICQ_STATE_BUSY); 5631 aim_setextstatus(od->sess, AIM_ICQ_STATE_AWAY | AIM_ICQ_STATE_DND | AIM_ICQ_STATE_BUSY);
5633 } else if (!strcmp(state, _("Not Available"))) { 5632
5633 else if (!strcmp(status_id, OSCAR_STATUS_ID_NA))
5634 aim_setextstatus(od->sess, AIM_ICQ_STATE_OUT | AIM_ICQ_STATE_AWAY); 5634 aim_setextstatus(od->sess, AIM_ICQ_STATE_OUT | AIM_ICQ_STATE_AWAY);
5635 } else if (!strcmp(state, _("Occupied"))) { 5635
5636 else if (!strcmp(status_id, OSCAR_STATUS_ID_OCCUPIED))
5636 aim_setextstatus(od->sess, AIM_ICQ_STATE_AWAY | AIM_ICQ_STATE_BUSY); 5637 aim_setextstatus(od->sess, AIM_ICQ_STATE_AWAY | AIM_ICQ_STATE_BUSY);
5637 } else if (!strcmp(state, _("Free For Chat"))) { 5638
5639 else if (!strcmp(status_id, OSCAR_STATUS_ID_FREE4CHAT))
5638 aim_setextstatus(od->sess, AIM_ICQ_STATE_CHAT); 5640 aim_setextstatus(od->sess, AIM_ICQ_STATE_CHAT);
5639 } else if (!strcmp(state, _("Invisible"))) { 5641
5642 else if (!strcmp(status_id, OSCAR_STATUS_ID_INVISIBLE))
5640 aim_setextstatus(od->sess, AIM_ICQ_STATE_INVISIBLE); 5643 aim_setextstatus(od->sess, AIM_ICQ_STATE_INVISIBLE);
5641 #if 0 /* XXX fix me!! */ 5644
5642 } else if (!strcmp(state, GAIM_AWAY_CUSTOM)) { 5645 else if (!strcmp(status_id, OSCAR_STATUS_ID_CUSTOM))
5643 if (message) { 5646 aim_setextstatus(od->sess, AIM_ICQ_STATE_OUT | AIM_ICQ_STATE_AWAY);
5644 aim_setextstatus(od->sess, AIM_ICQ_STATE_OUT | AIM_ICQ_STATE_AWAY);
5645 } else {
5646 aim_setextstatus(od->sess, AIM_ICQ_STATE_NORMAL);
5647 }
5648 #endif
5649 }
5650 5647
5651 return; 5648 return;
5652 } 5649 }
5653 5650
5654 static void oscar_set_status(GaimAccount *account, GaimStatus *status) 5651 static void
5652 oscar_set_status(GaimAccount *account, GaimStatus *status)
5655 { 5653 {
5656 OscarData *od = (OscarData *)account->gc->proto_data; 5654 GaimConnection *gc = gaim_account_get_connection(account);
5655 OscarData *od = (OscarData *)gc->proto_data;
5657 5656
5658 if (od->icq) 5657 if (od->icq)
5659 oscar_set_status_icq(account, status); 5658 oscar_set_status_icq(account, status);
5660 else 5659 else
5661 oscar_set_status_aim(account, status); 5660 oscar_set_status_aim(account, status);
5662 5661
5663 return; 5662 return;
5664 } 5663 }
5665 5664
5666 static void oscar_warn(GaimConnection *gc, const char *name, gboolean anonymous) { 5665 static void
5666 oscar_warn(GaimConnection *gc, const char *name, gboolean anonymous) {
5667 OscarData *od = (OscarData *)gc->proto_data; 5667 OscarData *od = (OscarData *)gc->proto_data;
5668 aim_im_warn(od->sess, od->conn, name, anonymous ? AIM_WARN_ANON : 0); 5668 aim_im_warn(od->sess, od->conn, name, anonymous ? AIM_WARN_ANON : 0);
5669 } 5669 }
5670 5670
5671 static void oscar_add_buddy(GaimConnection *gc, GaimBuddy *buddy, GaimGroup *group) { 5671 static void oscar_add_buddy(GaimConnection *gc, GaimBuddy *buddy, GaimGroup *group) {
5851 } 5851 }
5852 5852
5853 static int gaim_ssi_parserights(aim_session_t *sess, aim_frame_t *fr, ...) { 5853 static int gaim_ssi_parserights(aim_session_t *sess, aim_frame_t *fr, ...) {
5854 GaimConnection *gc = sess->aux_data; 5854 GaimConnection *gc = sess->aux_data;
5855 OscarData *od = (OscarData *)gc->proto_data; 5855 OscarData *od = (OscarData *)gc->proto_data;
5856 GaimAccount *account = gaim_connection_get_account(gc);
5857 GaimStatus *status;
5858 int i; 5856 int i;
5859 va_list ap; 5857 va_list ap;
5860 int numtypes; 5858 int numtypes;
5861 fu16_t *maxitems; 5859 fu16_t *maxitems;
5862 5860
6077 if ((permdeny = aim_ssi_getpermdeny(sess->ssi.local)) && (permdeny != account->perm_deny)) { 6075 if ((permdeny = aim_ssi_getpermdeny(sess->ssi.local)) && (permdeny != account->perm_deny)) {
6078 gaim_debug_info("oscar", 6076 gaim_debug_info("oscar",
6079 "ssi: changing permdeny from %d to %hhu\n", account->perm_deny, permdeny); 6077 "ssi: changing permdeny from %d to %hhu\n", account->perm_deny, permdeny);
6080 account->perm_deny = permdeny; 6078 account->perm_deny = permdeny;
6081 if (od->icq && account->perm_deny == 0x03) { 6079 if (od->icq && account->perm_deny == 0x03) {
6082 gaim_presence_switch_status(account->presence, 6080 gaim_presence_switch_status(account->presence, OSCAR_STATUS_ID_INVISIBLE);
6083 OSCAR_STATUS_ID_INVISIBLE);
6084 } 6081 }
6085 } 6082 }
6086 } 6083 }
6087 } break; 6084 } break;
6088 6085
6090 /* We don't want to change Gaim's setting because it applies to all accounts */ 6087 /* We don't want to change Gaim's setting because it applies to all accounts */
6091 } break; 6088 } break;
6092 } /* End of switch on curitem->type */ 6089 } /* End of switch on curitem->type */
6093 } /* End of for loop */ 6090 } /* End of for loop */
6094 6091
6095 /* XXX - STATUS - Set our ICQ status */ 6092 /*
6093 * XXX - STATUS - Set our ICQ status. We probably don't want to do
6094 * this. We probably want the SSI status setting to override the local
6095 * setting.
6096 */
6096 status = gaim_presence_get_active_status(account->presence); 6097 status = gaim_presence_get_active_status(account->presence);
6097 if (gaim_status_is_available(status)) 6098 if (gaim_status_is_available(status))
6098 aim_setextstatus(sess, AIM_ICQ_STATE_NORMAL); 6099 aim_setextstatus(sess, AIM_ICQ_STATE_NORMAL);
6099 6100
6100 /* Activate SSI */ 6101 /* Activate SSI */
6820 6821
6821 g_return_val_if_fail(account != NULL, NULL); 6822 g_return_val_if_fail(account != NULL, NULL);
6822 6823
6823 is_icq = aim_sn_is_icq(gaim_account_get_username(account)); 6824 is_icq = aim_sn_is_icq(gaim_account_get_username(account));
6824 6825
6825 type = gaim_status_type_new_full(GAIM_STATUS_OFFLINE, OSCAR_STATUS_ID_OFFLINE, _("Offline"), FALSE, FALSE, FALSE); 6826 type = gaim_status_type_new_full(GAIM_STATUS_OFFLINE,
6827 OSCAR_STATUS_ID_OFFLINE,
6828 _("Offline"), FALSE, FALSE, FALSE);
6826 status_types = g_list_append(status_types, type); 6829 status_types = g_list_append(status_types, type);
6827 6830
6828 type = gaim_status_type_new_full(GAIM_STATUS_ONLINE, OSCAR_STATUS_ID_ONLINE, _("Online"), FALSE, FALSE, FALSE); 6831 type = gaim_status_type_new_full(GAIM_STATUS_ONLINE,
6832 OSCAR_STATUS_ID_ONLINE,
6833 _("Online"), FALSE, FALSE, FALSE);
6829 status_types = g_list_append(status_types, type); 6834 status_types = g_list_append(status_types, type);
6830 6835
6831 type = gaim_status_type_new_full(GAIM_STATUS_HIDDEN, OSCAR_STATUS_ID_INVISIBLE, _("Invisible"), TRUE, TRUE, TRUE); 6836 type = gaim_status_type_new_full(GAIM_STATUS_AVAILABLE,
6837 OSCAR_STATUS_ID_AVAILABLE,
6838 _("Available"), TRUE, TRUE, FALSE);
6832 status_types = g_list_append(status_types, type); 6839 status_types = g_list_append(status_types, type);
6833 6840
6834 type = gaim_status_type_new_full(GAIM_STATUS_AVAILABLE, OSCAR_STATUS_ID_AVAILABLE, _("Available"), TRUE, TRUE, FALSE); 6841 type = gaim_status_type_new_full(GAIM_STATUS_AVAILABLE,
6842 OSCAR_STATUS_ID_FREE4CHAT,
6843 _("Free For Chat"), TRUE, TRUE, FALSE);
6835 status_types = g_list_append(status_types, type); 6844 status_types = g_list_append(status_types, type);
6836 6845
6837 type = gaim_status_type_new_full(GAIM_STATUS_AVAILABLE, OSCAR_STATUS_ID_FREE4CHAT, _("Free For Chat"), TRUE, TRUE, FALSE); 6846 type = gaim_status_type_new_full(GAIM_STATUS_UNAVAILABLE,
6847 OSCAR_STATUS_ID_OCCUPIED,
6848 _("Occupied"), TRUE, TRUE, FALSE);
6838 status_types = g_list_append(status_types, type); 6849 status_types = g_list_append(status_types, type);
6839 6850
6840 type = gaim_status_type_new_full(GAIM_STATUS_AWAY, OSCAR_STATUS_ID_AWAY, _("Away"), TRUE, TRUE, FALSE); 6851 type = gaim_status_type_new_full(GAIM_STATUS_HIDDEN,
6852 OSCAR_STATUS_ID_INVISIBLE,
6853 _("Invisible"), TRUE, TRUE, TRUE);
6841 status_types = g_list_append(status_types, type); 6854 status_types = g_list_append(status_types, type);
6842 6855
6843 type = gaim_status_type_new_full(GAIM_STATUS_AWAY, OSCAR_STATUS_ID_OCCUPIED, _("Occupied"), TRUE, TRUE, FALSE); 6856 type = gaim_status_type_new_full(GAIM_STATUS_AWAY,
6857 OSCAR_STATUS_ID_AWAY,
6858 _("Away"), TRUE, TRUE, FALSE);
6844 status_types = g_list_append(status_types, type); 6859 status_types = g_list_append(status_types, type);
6845 6860
6846 type = gaim_status_type_new_full(GAIM_STATUS_EXTENDED_AWAY, OSCAR_STATUS_ID_DND, _("Do Not Disturb"), TRUE, TRUE, FALSE); 6861 type = gaim_status_type_new_full(GAIM_STATUS_EXTENDED_AWAY,
6862 OSCAR_STATUS_ID_DND,
6863 _("Do Not Disturb"), TRUE, TRUE, FALSE);
6847 status_types = g_list_append(status_types, type); 6864 status_types = g_list_append(status_types, type);
6848 6865
6849 type = gaim_status_type_new_full(GAIM_STATUS_EXTENDED_AWAY, OSCAR_STATUS_ID_NA, _("Not Available"), TRUE, TRUE, FALSE); 6866 type = gaim_status_type_new_full(GAIM_STATUS_EXTENDED_AWAY,
6867 OSCAR_STATUS_ID_NA,
6868 _("Not Available"), TRUE, TRUE, FALSE);
6850 status_types = g_list_append(status_types, type); 6869 status_types = g_list_append(status_types, type);
6851 6870
6852 return status_types; 6871 return status_types;
6853
6854 /*
6855 * Do something with:
6856 * #define OSCAR_STATUS_ID_CUSTOM "custom"
6857 */
6858
6859 #if 0 /* STATUS - old stuff that should be removed */
6860 if (od->icq) {
6861 m = g_list_append(m, _("Online"));
6862 m = g_list_append(m, _("Away"));
6863 m = g_list_append(m, _("Do Not Disturb"));
6864 m = g_list_append(m, _("Not Available"));
6865 m = g_list_append(m, _("Occupied"));
6866 m = g_list_append(m, _("Free For Chat"));
6867 m = g_list_append(m, _("Invisible"));
6868 } else {
6869 m = g_list_append(m, GAIM_AWAY_CUSTOM);
6870 m = g_list_append(m, _("Back"));
6871 m = g_list_append(m, _("Visible"));
6872 m = g_list_append(m, _("Invisible"));
6873 }
6874
6875 return m;
6876 #endif
6877 } 6872 }
6878 6873
6879 static void oscar_ssi_editcomment(struct name_data *data, const char *text) { 6874 static void oscar_ssi_editcomment(struct name_data *data, const char *text) {
6880 GaimConnection *gc = data->gc; 6875 GaimConnection *gc = data->gc;
6881 OscarData *od = gc->proto_data; 6876 OscarData *od = gc->proto_data;