comparison libpurple/protocols/msn/msn.c @ 23142:dea8b856466e

propagate from branch 'im.pidgin.pidgin.custom_smiley' (head c134ff23eba5faac09c13e731e792fa612c91a9a) to branch 'im.pidgin.pidgin.next.minor' (head 4d2d20241c7dac5915e142f0aa9811c9eab40111)
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Mon, 12 May 2008 23:17:48 +0000
parents 8c3444f04709 9aa105267f46
children caa533b62902
comparison
equal deleted inserted replaced
23114:d53f72735830 23142:dea8b856466e
30 #include "msg.h" 30 #include "msg.h"
31 #include "page.h" 31 #include "page.h"
32 #include "pluginpref.h" 32 #include "pluginpref.h"
33 #include "prefs.h" 33 #include "prefs.h"
34 #include "session.h" 34 #include "session.h"
35 #include "smiley.h"
35 #include "state.h" 36 #include "state.h"
36 #include "util.h" 37 #include "util.h"
37 #include "cmds.h" 38 #include "cmds.h"
38 #include "core.h" 39 #include "core.h"
39 #include "prpl.h" 40 #include "prpl.h"
80 char *msg; 81 char *msg;
81 PurpleMessageFlags flags; 82 PurpleMessageFlags flags;
82 time_t when; 83 time_t when;
83 } MsnIMData; 84 } MsnIMData;
84 85
86 typedef struct
87 {
88 char *smile;
89 MsnObject *obj;
90 } MsnEmoticon;
91
85 static const char * 92 static const char *
86 msn_normalize(const PurpleAccount *account, const char *str) 93 msn_normalize(const PurpleAccount *account, const char *str)
87 { 94 {
88 static char buf[BUF_LEN]; 95 static char buf[BUF_LEN];
89 char *tmp; 96 char *tmp;
113 120
114 if (swboard == NULL) 121 if (swboard == NULL)
115 return FALSE; 122 return FALSE;
116 123
117 msn_switchboard_send_msg(swboard, msg, TRUE); 124 msn_switchboard_send_msg(swboard, msg, TRUE);
125 msn_message_destroy(msg);
118 126
119 return TRUE; 127 return TRUE;
120 } 128 }
121 129
122 static GList * 130 static GList *
893 port = purple_account_get_int(account, "port", MSN_PORT); 901 port = purple_account_get_int(account, "port", MSN_PORT);
894 902
895 session = msn_session_new(account); 903 session = msn_session_new(account);
896 904
897 gc->proto_data = session; 905 gc->proto_data = session;
898 gc->flags |= PURPLE_CONNECTION_HTML | PURPLE_CONNECTION_FORMATTING_WBFO | PURPLE_CONNECTION_NO_BGCOLOR | PURPLE_CONNECTION_NO_FONTSIZE | PURPLE_CONNECTION_NO_URLDESC; 906 gc->flags |= PURPLE_CONNECTION_HTML | PURPLE_CONNECTION_FORMATTING_WBFO | PURPLE_CONNECTION_NO_BGCOLOR |
907 PURPLE_CONNECTION_NO_FONTSIZE | PURPLE_CONNECTION_NO_URLDESC | PURPLE_CONNECTION_ALLOW_CUSTOM_SMILEY;
899 908
900 msn_session_set_login_step(session, MSN_LOGIN_STEP_START); 909 msn_session_set_login_step(session, MSN_LOGIN_STEP_START);
901 910
902 /* Hmm, I don't like this. */ 911 /* Hmm, I don't like this. */
903 /* XXX shx: Me neither */ 912 /* XXX shx: Me neither */
934 g_free(imdata->msg); 943 g_free(imdata->msg);
935 g_free(imdata); 944 g_free(imdata);
936 return FALSE; 945 return FALSE;
937 } 946 }
938 947
948 static GString*
949 msn_msg_emoticon_add(GString *current, MsnEmoticon *emoticon)
950 {
951 MsnObject *obj;
952 char *strobj;
953
954 if (emoticon == NULL)
955 return current;
956
957 obj = emoticon->obj;
958
959 if (!obj)
960 return current;
961
962 strobj = msn_object_to_string(obj);
963
964 if (current)
965 g_string_append_printf(current, "\t%s\t%s",
966 emoticon->smile, strobj);
967 else {
968 current = g_string_new("");
969 g_string_printf(current,"%s\t%s",
970 emoticon->smile, strobj);
971 }
972
973 g_free(strobj);
974
975 return current;
976 }
977
978 static void
979 msn_send_emoticons(MsnSwitchBoard *swboard, GString *body)
980 {
981 MsnMessage *msg;
982
983 g_return_if_fail(body != NULL);
984
985 msg = msn_message_new(MSN_MSG_SLP);
986 msn_message_set_content_type(msg, "text/x-mms-emoticon");
987 msn_message_set_flag(msg, 'N');
988 msn_message_set_bin_data(msg, body->str, body->len);
989
990 msn_switchboard_send_msg(swboard, msg, TRUE);
991 msn_message_destroy(msg);
992 }
993
994 static void msn_emoticon_destroy(MsnEmoticon *emoticon)
995 {
996 if (emoticon->obj)
997 msn_object_destroy(emoticon->obj);
998 g_free(emoticon->smile);
999 g_free(emoticon);
1000 }
1001
1002 static GSList* msn_msg_grab_emoticons(const char *msg, const char *username)
1003 {
1004 GSList *list;
1005 GList *smileys;
1006 PurpleSmiley *smiley;
1007 PurpleStoredImage *img;
1008 char *ptr;
1009 MsnEmoticon *emoticon;
1010 int length;
1011
1012 list = NULL;
1013 smileys = purple_smileys_get_all();
1014 length = strlen(msg);
1015
1016 for (; smileys; smileys = g_list_delete_link(smileys, smileys)) {
1017 smiley = smileys->data;
1018
1019 ptr = g_strstr_len(msg, length, purple_smiley_get_shortcut(smiley));
1020
1021 if (!ptr)
1022 continue;
1023
1024 img = purple_smiley_get_stored_image(smiley);
1025
1026 emoticon = g_new0(MsnEmoticon, 1);
1027 emoticon->smile = g_strdup(purple_smiley_get_shortcut(smiley));
1028 emoticon->obj = msn_object_new_from_image(img,
1029 purple_imgstore_get_filename(img),
1030 username, MSN_OBJECT_EMOTICON);
1031
1032 purple_imgstore_unref(img);
1033 list = g_slist_prepend(list, emoticon);
1034 }
1035
1036 return list;
1037 }
1038
939 static int 1039 static int
940 msn_send_im(PurpleConnection *gc, const char *who, const char *message, 1040 msn_send_im(PurpleConnection *gc, const char *who, const char *message,
941 PurpleMessageFlags flags) 1041 PurpleMessageFlags flags)
942 { 1042 {
943 PurpleAccount *account; 1043 PurpleAccount *account;
944 PurpleBuddy *buddy = purple_find_buddy(gc->account, who); 1044 PurpleBuddy *buddy = purple_find_buddy(gc->account, who);
945 MsnMessage *msg; 1045 MsnMessage *msg;
946 char *msgformat; 1046 char *msgformat;
947 char *msgtext; 1047 char *msgtext;
1048 const char *username;
948 1049
949 purple_debug_info("MSNP14","send IM {%s} to %s\n",message,who); 1050 purple_debug_info("MSNP14","send IM {%s} to %s\n",message,who);
950 account = purple_connection_get_account(gc); 1051 account = purple_connection_get_account(gc);
1052 username = purple_account_get_username(account);
951 1053
952 if (buddy) { 1054 if (buddy) {
953 PurplePresence *p = purple_buddy_get_presence(buddy); 1055 PurplePresence *p = purple_buddy_get_presence(buddy);
954 if (purple_presence_is_status_primitive_active(p, PURPLE_STATUS_MOBILE)) { 1056 if (purple_presence_is_status_primitive_active(p, PURPLE_STATUS_MOBILE)) {
955 char *text = purple_markup_strip_html(message); 1057 char *text = purple_markup_strip_html(message);
978 1080
979 g_free(msgformat); 1081 g_free(msgformat);
980 g_free(msgtext); 1082 g_free(msgtext);
981 1083
982 purple_debug_info("MSNP14","prepare to send online Message\n"); 1084 purple_debug_info("MSNP14","prepare to send online Message\n");
983 if (g_ascii_strcasecmp(who, purple_account_get_username(account))) 1085 if (g_ascii_strcasecmp(who, username))
984 { 1086 {
985 MsnSession *session; 1087 MsnSession *session;
986 MsnSwitchBoard *swboard; 1088 MsnSwitchBoard *swboard;
1089 MsnEmoticon *smile;
1090 GSList *smileys;
1091 GString *emoticons = NULL;
987 1092
988 session = gc->proto_data; 1093 session = gc->proto_data;
989 if(msn_user_is_yahoo(account,who)){ 1094 if(msn_user_is_yahoo(account,who)){
990 /*we send the online and offline Message to Yahoo User via UBM*/ 1095 /*we send the online and offline Message to Yahoo User via UBM*/
991 purple_debug_info("MSNP14","send to Yahoo User\n"); 1096 purple_debug_info("MSNP14","send to Yahoo User\n");
992 uum_send_msg(session,msg); 1097 uum_send_msg(session,msg);
993 }else{ 1098 }else{
994 purple_debug_info("MSNP14","send via switchboard\n"); 1099 purple_debug_info("MSNP14","send via switchboard\n");
995 swboard = msn_session_get_swboard(session, who, MSN_SB_FLAG_IM); 1100 swboard = msn_session_get_swboard(session, who, MSN_SB_FLAG_IM);
1101 smileys = msn_msg_grab_emoticons(message, username);
1102 while (smileys) {
1103 smile = (MsnEmoticon*)smileys->data;
1104 emoticons = msn_msg_emoticon_add(emoticons, smile);
1105 msn_emoticon_destroy(smile);
1106 smileys = g_slist_delete_link(smileys, smileys);
1107 }
1108
1109 if (emoticons) {
1110 msn_send_emoticons(swboard, emoticons);
1111 g_string_free(emoticons, TRUE);
1112 }
1113
996 msn_switchboard_send_msg(swboard, msg, TRUE); 1114 msn_switchboard_send_msg(swboard, msg, TRUE);
997 } 1115 }
998 } 1116 }
999 else 1117 else
1000 { 1118 {