comparison libpurple/protocols/msn/msg.c @ 30909:25e200cb3532

propagate from branch 'im.pidgin.pidgin' (head dca20e09164518b0f7a773edd7e9649f41d8873d) to branch 'im.pidgin.cpw.malu.xmpp.google_refactor' (head 7823c556f2d1bbca43f5ef9f0fea30cabc5d313f)
author Marcus Lundblad <ml@update.uu.se>
date Tue, 31 Aug 2010 18:28:10 +0000
parents 5044315e81e1
children 9623db527d1e 66e7fe9f7810
comparison
equal deleted inserted replaced
30908:c44ec533a48c 30909:25e200cb3532
937 const char *msg, const char *filename) 937 const char *msg, const char *filename)
938 { 938 {
939 char *username, *str; 939 char *username, *str;
940 PurpleAccount *account; 940 PurpleAccount *account;
941 PurpleBuddy *b; 941 PurpleBuddy *b;
942 PurpleConnection *pc;
943 gboolean chat;
942 944
943 account = swboard->session->account; 945 account = swboard->session->account;
946 pc = purple_account_get_connection(account);
944 947
945 if ((b = purple_find_buddy(account, who)) != NULL) 948 if ((b = purple_find_buddy(account, who)) != NULL)
946 username = g_markup_escape_text(purple_buddy_get_alias(b), -1); 949 username = g_markup_escape_text(purple_buddy_get_alias(b), -1);
947 else 950 else
948 username = g_markup_escape_text(who, -1); 951 username = g_markup_escape_text(who, -1);
949 str = g_strdup_printf(msg, username, filename); 952 str = g_strdup_printf(msg, username, filename);
950 g_free(username); 953 g_free(username);
951 954
955 swboard->flag |= MSN_SB_FLAG_IM;
956 if (swboard->current_users > 1)
957 chat = TRUE;
958 else
959 chat = FALSE;
960
952 if (swboard->conv == NULL) { 961 if (swboard->conv == NULL) {
953 if (swboard->current_users > 1) 962 if (chat)
954 swboard->conv = purple_find_chat(account->gc, swboard->chat_id); 963 swboard->conv = purple_find_chat(account->gc, swboard->chat_id);
955 else { 964 else {
956 swboard->conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, 965 swboard->conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM,
957 who, account); 966 who, account);
958 if (swboard->conv == NULL) 967 if (swboard->conv == NULL)
959 swboard->conv = purple_conversation_new(PURPLE_CONV_TYPE_IM, account, who); 968 swboard->conv = purple_conversation_new(PURPLE_CONV_TYPE_IM, account, who);
960 } 969 }
961 } 970 }
962 swboard->flag |= MSN_SB_FLAG_IM; 971
963 972 if (chat)
964 purple_conversation_write(swboard->conv, NULL, str, PURPLE_MESSAGE_SYSTEM, time(NULL)); 973 serv_got_chat_in(pc,
974 purple_conv_chat_get_id(PURPLE_CONV_CHAT(swboard->conv)),
975 who, PURPLE_MESSAGE_RECV|PURPLE_MESSAGE_SYSTEM, str,
976 time(NULL));
977 else
978 serv_got_im(pc, who, str, PURPLE_MESSAGE_RECV|PURPLE_MESSAGE_SYSTEM,
979 time(NULL));
965 g_free(str); 980 g_free(str);
966 981
967 } 982 }
968 983
969 /* TODO: Make these not be such duplicates of each other */ 984 /* TODO: Make these not be such duplicates of each other */
970 static void 985 static void
971 got_wink_cb(MsnSlpCall *slpcall, const guchar *data, gsize size) 986 got_wink_cb(MsnSlpCall *slpcall, const guchar *data, gsize size)
972 { 987 {
973 FILE *f; 988 FILE *f = NULL;
974 char *path = NULL; 989 char *path = NULL;
975 const char *who = slpcall->slplink->remote_user; 990 const char *who = slpcall->slplink->remote_user;
976 purple_debug_info("msn", "Received wink from %s\n", who); 991 purple_debug_info("msn", "Received wink from %s\n", who);
977 992
978 if ((f = purple_mkstemp(&path, TRUE))) { 993 if ((f = purple_mkstemp(&path, TRUE)) &&
979 fwrite(data, size, 1, f); 994 (fwrite(data, 1, size, f) == size)) {
980 fclose(f);
981 datacast_inform_user(slpcall->slplink->swboard, 995 datacast_inform_user(slpcall->slplink->swboard,
982 who, 996 who,
983 _("%s sent a wink. <a href='msn-wink://%s'>Click here to play it</a>"), 997 _("%s sent a wink. <a href='msn-wink://%s'>Click here to play it</a>"),
984 path); 998 path);
985 } else { 999 } else {
986 purple_debug_error("msn", "Couldn\'t create temp file to store wink\n"); 1000 purple_debug_error("msn", "Couldn\'t create temp file to store wink\n");
987 datacast_inform_user(slpcall->slplink->swboard, 1001 datacast_inform_user(slpcall->slplink->swboard,
988 who, 1002 who,
989 _("%s sent a wink, but it could not be saved"), 1003 _("%s sent a wink, but it could not be saved"),
990 NULL); 1004 NULL);
991 } 1005 }
1006 if (f)
1007 fclose(f);
992 g_free(path); 1008 g_free(path);
993 } 1009 }
994 1010
995 static void 1011 static void
996 got_voiceclip_cb(MsnSlpCall *slpcall, const guchar *data, gsize size) 1012 got_voiceclip_cb(MsnSlpCall *slpcall, const guchar *data, gsize size)
997 { 1013 {
998 FILE *f; 1014 FILE *f = NULL;
999 char *path = NULL; 1015 char *path = NULL;
1000 const char *who = slpcall->slplink->remote_user; 1016 const char *who = slpcall->slplink->remote_user;
1001 purple_debug_info("msn", "Received voice clip from %s\n", who); 1017 purple_debug_info("msn", "Received voice clip from %s\n", who);
1002 1018
1003 if ((f = purple_mkstemp(&path, TRUE))) { 1019 if ((f = purple_mkstemp(&path, TRUE)) &&
1004 fwrite(data, size, 1, f); 1020 (fwrite(data, 1, size, f) == size)) {
1005 fclose(f);
1006 datacast_inform_user(slpcall->slplink->swboard, 1021 datacast_inform_user(slpcall->slplink->swboard,
1007 who, 1022 who,
1008 _("%s sent a voice clip. <a href='audio://%s'>Click here to play it</a>"), 1023 _("%s sent a voice clip. <a href='audio://%s'>Click here to play it</a>"),
1009 path); 1024 path);
1010 } else { 1025 } else {
1011 purple_debug_error("msn", "Couldn\'t create temp file to store sound\n"); 1026 purple_debug_error("msn", "Couldn\'t create temp file to store sound\n");
1012 datacast_inform_user(slpcall->slplink->swboard, 1027 datacast_inform_user(slpcall->slplink->swboard,
1013 who, 1028 who,
1014 _("%s sent a voice clip, but it could not be saved"), 1029 _("%s sent a voice clip, but it could not be saved"),
1015 NULL); 1030 NULL);
1016 } 1031 }
1032 if (f)
1033 fclose(f);
1017 g_free(path); 1034 g_free(path);
1018 } 1035 }
1019 1036
1020 void 1037 void
1021 msn_datacast_msg(MsnCmdProc *cmdproc, MsnMessage *msg) 1038 msn_datacast_msg(MsnCmdProc *cmdproc, MsnMessage *msg)
1098 1115
1099 void 1116 void
1100 msn_invite_msg(MsnCmdProc *cmdproc, MsnMessage *msg) 1117 msn_invite_msg(MsnCmdProc *cmdproc, MsnMessage *msg)
1101 { 1118 {
1102 GHashTable *body; 1119 GHashTable *body;
1103 const gchar *guid; 1120 const gchar *command;
1121 const gchar *cookie;
1104 gboolean accepted = FALSE; 1122 gboolean accepted = FALSE;
1105 1123
1106 g_return_if_fail(cmdproc != NULL); 1124 g_return_if_fail(cmdproc != NULL);
1107 g_return_if_fail(msg != NULL); 1125 g_return_if_fail(msg != NULL);
1108 1126
1111 if (body == NULL) { 1129 if (body == NULL) {
1112 purple_debug_warning("msn", 1130 purple_debug_warning("msn",
1113 "Unable to parse invite msg body.\n"); 1131 "Unable to parse invite msg body.\n");
1114 return; 1132 return;
1115 } 1133 }
1116 1134
1117 guid = g_hash_table_lookup(body, "Application-GUID"); 1135 /*
1118 1136 * GUID is NOT always present but Invitation-Command and Invitation-Cookie
1119 if (guid == NULL) { 1137 * are mandatory.
1120 const gchar *cmd = g_hash_table_lookup( 1138 */
1121 body, "Invitation-Command"); 1139 command = g_hash_table_lookup(body, "Invitation-Command");
1122 1140 cookie = g_hash_table_lookup(body, "Invitation-Cookie");
1123 if (cmd && !strcmp(cmd, "CANCEL")) { 1141
1124 const gchar *code = g_hash_table_lookup( 1142 if (command == NULL || cookie == NULL) {
1125 body, "Cancel-Code"); 1143 purple_debug_warning("msn",
1126 purple_debug_info("msn", 1144 "Invalid invitation message: either Invitation-Command "
1127 "MSMSGS invitation cancelled: %s.\n", 1145 "or Invitation-Cookie is missing or invalid.\n"
1128 code ? code : "no reason given"); 1146 );
1129 } else 1147 return;
1130 purple_debug_warning("msn", "Invite msg missing " 1148
1131 "Application-GUID.\n"); 1149 } else if (!strcmp(command, "INVITE")) {
1132 1150 const gchar *guid = g_hash_table_lookup(body, "Application-GUID");
1133 accepted = TRUE; 1151
1134 1152 if (guid == NULL) {
1135 } else if (!strcmp(guid, "{02D3C01F-BF30-4825-A83A-DE7AF41648AA}")) { 1153 purple_debug_warning("msn",
1136 purple_debug_info("msn", "Computer call\n"); 1154 "Invite msg missing Application-GUID.\n");
1137 1155
1138 if (cmdproc->session) { 1156 accepted = TRUE;
1139 PurpleConversation *conv = NULL; 1157
1140 gchar *from = msg->remote_user; 1158 } else if (!strcmp(guid, MSN_FT_GUID)) {
1141 gchar *buf = NULL; 1159
1142 1160 } else if (!strcmp(guid, "{02D3C01F-BF30-4825-A83A-DE7AF41648AA}")) {
1143 if (from) 1161 purple_debug_info("msn", "Computer call\n");
1144 conv = purple_find_conversation_with_account( 1162
1145 PURPLE_CONV_TYPE_IM, from, 1163 if (cmdproc->session) {
1146 cmdproc->session->account); 1164 PurpleConversation *conv = NULL;
1147 if (conv) 1165 gchar *from = msg->remote_user;
1148 buf = g_strdup_printf( 1166 gchar *buf = NULL;
1149 _("%s sent you a voice chat " 1167
1150 "invite, which is not yet " 1168 if (from)
1151 "supported."), from); 1169 conv = purple_find_conversation_with_account(
1152 if (buf) { 1170 PURPLE_CONV_TYPE_IM, from,
1153 purple_conversation_write(conv, NULL, buf, 1171 cmdproc->session->account);
1154 PURPLE_MESSAGE_SYSTEM | 1172 if (conv)
1155 PURPLE_MESSAGE_NOTIFY, 1173 buf = g_strdup_printf(
1156 time(NULL)); 1174 _("%s sent you a voice chat "
1157 g_free(buf); 1175 "invite, which is not yet "
1176 "supported."), from);
1177 if (buf) {
1178 purple_conversation_write(conv, NULL, buf,
1179 PURPLE_MESSAGE_SYSTEM |
1180 PURPLE_MESSAGE_NOTIFY,
1181 time(NULL));
1182 g_free(buf);
1183 }
1158 } 1184 }
1159 } 1185 } else {
1160 } else { 1186 const gchar *application = g_hash_table_lookup(body, "Application-Name");
1161 const gchar *application = g_hash_table_lookup(body, "Application-Name"); 1187 purple_debug_warning("msn", "Unhandled invite msg with GUID %s: %s.\n",
1162 purple_debug_warning("msn", "Unhandled invite msg with GUID %s: %s.\n", 1188 guid, application ? application : "(null)");
1163 guid, application ? application : "(null)"); 1189 }
1164 } 1190
1165 1191 if (!accepted) {
1166 if (!accepted) {
1167 const gchar *cookie = g_hash_table_lookup(body, "Invitation-Cookie");
1168 if (cookie) {
1169 MsnSwitchBoard *swboard = cmdproc->data; 1192 MsnSwitchBoard *swboard = cmdproc->data;
1170 char *text; 1193 char *text;
1171 MsnMessage *cancel; 1194 MsnMessage *cancel;
1172 1195
1173 cancel = msn_message_new(MSN_MSG_TEXT); 1196 cancel = msn_message_new(MSN_MSG_TEXT);
1183 g_free(text); 1206 g_free(text);
1184 1207
1185 msn_switchboard_send_msg(swboard, cancel, TRUE); 1208 msn_switchboard_send_msg(swboard, cancel, TRUE);
1186 msn_message_destroy(cancel); 1209 msn_message_destroy(cancel);
1187 } 1210 }
1211
1212 } else if (!strcmp(command, "CANCEL")) {
1213 const gchar *code = g_hash_table_lookup(body, "Cancel-Code");
1214 purple_debug_info("msn", "MSMSGS invitation cancelled: %s.\n",
1215 code ? code : "no reason given");
1216
1217 } else {
1218 /*
1219 * Some other already established invitation session.
1220 * Can be retrieved by Invitation-Cookie.
1221 */
1188 } 1222 }
1189 1223
1190 g_hash_table_destroy(body); 1224 g_hash_table_destroy(body);
1191 } 1225 }
1192 1226