Mercurial > pidgin.yaz
comparison libpurple/protocols/msnp9/msn.c @ 27842:acef4202e147
propagate from branch 'im.pidgin.pidgin' (head 217103c3e954ff2d295a6590ad3477d357894f9c)
to branch 'im.pidgin.pidgin.yaz' (head 0a5a324e3974fba2b40dcd1bb82fb1cc8b8fcabf)
author | Yoshiki Yazawa <yaz@honeyplanet.jp> |
---|---|
date | Sun, 25 May 2008 04:30:41 +0000 |
parents | f8b47fd39f53 caa533b62902 |
children | 30eaeb7cc076 |
comparison
equal
deleted
inserted
replaced
27841:5fc417883a5d | 27842:acef4202e147 |
---|---|
31 #include "msg.h" | 31 #include "msg.h" |
32 #include "page.h" | 32 #include "page.h" |
33 #include "pluginpref.h" | 33 #include "pluginpref.h" |
34 #include "prefs.h" | 34 #include "prefs.h" |
35 #include "session.h" | 35 #include "session.h" |
36 #include "smiley.h" | |
36 #include "state.h" | 37 #include "state.h" |
37 #include "util.h" | 38 #include "util.h" |
38 #include "cmds.h" | 39 #include "cmds.h" |
39 #include "core.h" | 40 #include "core.h" |
40 #include "prpl.h" | 41 #include "prpl.h" |
81 char *msg; | 82 char *msg; |
82 PurpleMessageFlags flags; | 83 PurpleMessageFlags flags; |
83 time_t when; | 84 time_t when; |
84 } MsnIMData; | 85 } MsnIMData; |
85 | 86 |
87 typedef struct | |
88 { | |
89 char *smile; | |
90 MsnObject *obj; | |
91 } MsnEmoticon; | |
92 | |
86 static const char * | 93 static const char * |
87 msn_normalize(const PurpleAccount *account, const char *str) | 94 msn_normalize(const PurpleAccount *account, const char *str) |
88 { | 95 { |
89 static char buf[BUF_LEN]; | 96 static char buf[BUF_LEN]; |
90 char *tmp; | 97 char *tmp; |
114 | 121 |
115 if (swboard == NULL) | 122 if (swboard == NULL) |
116 return FALSE; | 123 return FALSE; |
117 | 124 |
118 msn_switchboard_send_msg(swboard, msg, TRUE); | 125 msn_switchboard_send_msg(swboard, msg, TRUE); |
126 msn_message_destroy(msg); | |
119 | 127 |
120 return TRUE; | 128 return TRUE; |
121 } | 129 } |
122 | 130 |
123 static GList * | 131 static GList * |
131 } | 139 } |
132 | 140 |
133 return list; | 141 return list; |
134 } | 142 } |
135 | 143 |
144 static GHashTable * | |
145 msn_get_account_text_table(PurpleAccount *unused) | |
146 { | |
147 GHashTable *table; | |
148 | |
149 table = g_hash_table_new(g_str_hash, g_str_equal); | |
150 | |
151 g_hash_table_insert(table, "login_label", (gpointer)_("E-mail Address...")); | |
152 | |
153 return table; | |
154 } | |
136 | 155 |
137 static PurpleCmdRet | 156 static PurpleCmdRet |
138 msn_cmd_nudge(PurpleConversation *conv, const gchar *cmd, gchar **args, gchar **error, void *data) | 157 msn_cmd_nudge(PurpleConversation *conv, const gchar *cmd, gchar **args, gchar **error, void *data) |
139 { | 158 { |
140 PurpleAccount *account = purple_conversation_get_account(conv); | 159 PurpleAccount *account = purple_conversation_get_account(conv); |
758 port = purple_account_get_int(account, "port", MSN_PORT); | 777 port = purple_account_get_int(account, "port", MSN_PORT); |
759 | 778 |
760 session = msn_session_new(account); | 779 session = msn_session_new(account); |
761 | 780 |
762 gc->proto_data = session; | 781 gc->proto_data = session; |
763 gc->flags |= PURPLE_CONNECTION_HTML | PURPLE_CONNECTION_FORMATTING_WBFO | PURPLE_CONNECTION_NO_BGCOLOR | PURPLE_CONNECTION_NO_FONTSIZE | PURPLE_CONNECTION_NO_URLDESC; | 782 gc->flags |= PURPLE_CONNECTION_HTML | PURPLE_CONNECTION_FORMATTING_WBFO | PURPLE_CONNECTION_NO_BGCOLOR | |
783 PURPLE_CONNECTION_NO_FONTSIZE | PURPLE_CONNECTION_NO_URLDESC | PURPLE_CONNECTION_ALLOW_CUSTOM_SMILEY; | |
764 | 784 |
765 msn_session_set_login_step(session, MSN_LOGIN_STEP_START); | 785 msn_session_set_login_step(session, MSN_LOGIN_STEP_START); |
766 | 786 |
767 /* Hmm, I don't like this. */ | 787 /* Hmm, I don't like this. */ |
768 /* XXX shx: Me neither */ | 788 /* XXX shx: Me neither */ |
799 g_free(imdata->msg); | 819 g_free(imdata->msg); |
800 g_free(imdata); | 820 g_free(imdata); |
801 return FALSE; | 821 return FALSE; |
802 } | 822 } |
803 | 823 |
824 static GString* | |
825 msn_msg_emoticon_add(GString *current, MsnEmoticon *emoticon) | |
826 { | |
827 MsnObject *obj; | |
828 char *strobj; | |
829 | |
830 if (emoticon == NULL) | |
831 return current; | |
832 | |
833 obj = emoticon->obj; | |
834 | |
835 if (!obj) | |
836 return current; | |
837 | |
838 strobj = msn_object_to_string(obj); | |
839 | |
840 if (current) | |
841 g_string_append_printf(current, "\t%s\t%s", | |
842 emoticon->smile, strobj); | |
843 else { | |
844 current = g_string_new(""); | |
845 g_string_printf(current,"%s\t%s", | |
846 emoticon->smile, strobj); | |
847 } | |
848 | |
849 g_free(strobj); | |
850 | |
851 return current; | |
852 } | |
853 | |
854 static void | |
855 msn_send_emoticons(MsnSwitchBoard *swboard, GString *body) | |
856 { | |
857 MsnMessage *msg; | |
858 | |
859 g_return_if_fail(body != NULL); | |
860 | |
861 msg = msn_message_new(MSN_MSG_SLP); | |
862 msn_message_set_content_type(msg, "text/x-mms-emoticon"); | |
863 msn_message_set_flag(msg, 'N'); | |
864 msn_message_set_bin_data(msg, body->str, body->len); | |
865 | |
866 msn_switchboard_send_msg(swboard, msg, TRUE); | |
867 msn_message_destroy(msg); | |
868 } | |
869 | |
870 static void msn_emoticon_destroy(MsnEmoticon *emoticon) | |
871 { | |
872 if (emoticon->obj) | |
873 msn_object_destroy(emoticon->obj); | |
874 g_free(emoticon->smile); | |
875 g_free(emoticon); | |
876 } | |
877 | |
878 static GSList* msn_msg_grab_emoticons(const char *msg, const char *username) | |
879 { | |
880 GSList *list; | |
881 GList *smileys; | |
882 PurpleSmiley *smiley; | |
883 PurpleStoredImage *img; | |
884 char *ptr; | |
885 MsnEmoticon *emoticon; | |
886 int length; | |
887 | |
888 list = NULL; | |
889 smileys = purple_smileys_get_all(); | |
890 length = strlen(msg); | |
891 | |
892 for (; smileys; smileys = g_list_delete_link(smileys, smileys)) { | |
893 smiley = (PurpleSmiley*)smileys->data; | |
894 | |
895 ptr = g_strstr_len(msg, length, purple_smiley_get_shortcut(smiley)); | |
896 | |
897 if (!ptr) | |
898 continue; | |
899 | |
900 img = purple_smiley_get_stored_image(smiley); | |
901 | |
902 emoticon = g_new0(MsnEmoticon, 1); | |
903 emoticon->smile = g_strdup(purple_smiley_get_shortcut(smiley)); | |
904 emoticon->obj = msn_object_new_from_image(img, | |
905 purple_imgstore_get_filename(img), | |
906 username, MSN_OBJECT_EMOTICON); | |
907 | |
908 purple_imgstore_unref(img); | |
909 list = g_slist_prepend(list, emoticon); | |
910 } | |
911 | |
912 return list; | |
913 } | |
914 | |
804 static int | 915 static int |
805 msn_send_im(PurpleConnection *gc, const char *who, const char *message, | 916 msn_send_im(PurpleConnection *gc, const char *who, const char *message, |
806 PurpleMessageFlags flags) | 917 PurpleMessageFlags flags) |
807 { | 918 { |
808 PurpleAccount *account; | 919 PurpleAccount *account; |
809 PurpleBuddy *buddy = purple_find_buddy(gc->account, who); | 920 PurpleBuddy *buddy = purple_find_buddy(gc->account, who); |
810 MsnMessage *msg; | 921 MsnMessage *msg; |
811 char *msgformat; | 922 char *msgformat; |
812 char *msgtext; | 923 char *msgtext; |
924 const char *username; | |
813 | 925 |
814 account = purple_connection_get_account(gc); | 926 account = purple_connection_get_account(gc); |
927 username = purple_account_get_username(account); | |
815 | 928 |
816 if (buddy) { | 929 if (buddy) { |
817 PurplePresence *p = purple_buddy_get_presence(buddy); | 930 PurplePresence *p = purple_buddy_get_presence(buddy); |
818 if (purple_presence_is_status_primitive_active(p, PURPLE_STATUS_MOBILE)) { | 931 if (purple_presence_is_status_primitive_active(p, PURPLE_STATUS_MOBILE)) { |
819 char *text = purple_markup_strip_html(message); | 932 char *text = purple_markup_strip_html(message); |
837 msn_message_set_attr(msg, "X-MMS-IM-Format", msgformat); | 950 msn_message_set_attr(msg, "X-MMS-IM-Format", msgformat); |
838 | 951 |
839 g_free(msgformat); | 952 g_free(msgformat); |
840 g_free(msgtext); | 953 g_free(msgtext); |
841 | 954 |
842 if (g_ascii_strcasecmp(who, purple_account_get_username(account))) | 955 if (g_ascii_strcasecmp(who, username)) |
843 { | 956 { |
844 MsnSession *session; | 957 MsnSession *session; |
845 MsnSwitchBoard *swboard; | 958 MsnSwitchBoard *swboard; |
959 MsnEmoticon *smile; | |
960 GSList *smileys; | |
961 GString *emoticons = NULL; | |
846 | 962 |
847 session = gc->proto_data; | 963 session = gc->proto_data; |
848 swboard = msn_session_get_swboard(session, who, MSN_SB_FLAG_IM); | 964 swboard = msn_session_get_swboard(session, who, MSN_SB_FLAG_IM); |
965 smileys = msn_msg_grab_emoticons(message, username); | |
966 | |
967 while (smileys) { | |
968 smile = (MsnEmoticon*)smileys->data; | |
969 emoticons = msn_msg_emoticon_add(emoticons,smile); | |
970 msn_emoticon_destroy(smile); | |
971 smileys = g_slist_delete_link(smileys, smileys); | |
972 } | |
973 | |
974 if (emoticons) { | |
975 msn_send_emoticons(swboard, emoticons); | |
976 g_string_free(emoticons, TRUE); | |
977 } | |
849 | 978 |
850 msn_switchboard_send_msg(swboard, msg, TRUE); | 979 msn_switchboard_send_msg(swboard, msg, TRUE); |
851 } | 980 } |
852 else | 981 else |
853 { | 982 { |
1266 msn_message_destroy(msg); | 1395 msn_message_destroy(msg); |
1267 | 1396 |
1268 g_free(msgformat); | 1397 g_free(msgformat); |
1269 g_free(msgtext); | 1398 g_free(msgtext); |
1270 | 1399 |
1271 serv_got_chat_in(gc, id, purple_account_get_username(account), 0, | 1400 serv_got_chat_in(gc, id, purple_account_get_username(account), flags, |
1272 message, time(NULL)); | 1401 message, time(NULL)); |
1273 | 1402 |
1274 return 0; | 1403 return 0; |
1275 } | 1404 } |
1276 | 1405 |
2151 NULL, /* roomlist_room_serialize */ | 2280 NULL, /* roomlist_room_serialize */ |
2152 NULL, /* unregister_user */ | 2281 NULL, /* unregister_user */ |
2153 msn_send_attention, /* send_attention */ | 2282 msn_send_attention, /* send_attention */ |
2154 msn_attention_types, /* attention_types */ | 2283 msn_attention_types, /* attention_types */ |
2155 | 2284 |
2156 /* padding */ | 2285 sizeof(PurplePluginProtocolInfo), /* struct_size */ |
2157 NULL | 2286 msn_get_account_text_table, /* get_account_text_table */ |
2158 }; | 2287 }; |
2159 | 2288 |
2160 static PurplePluginInfo info = | 2289 static PurplePluginInfo info = |
2161 { | 2290 { |
2162 PURPLE_PLUGIN_MAGIC, | 2291 PURPLE_PLUGIN_MAGIC, |