comparison src/protocols/msn/notification.c @ 10481:bcfea6c3d5c9

[gaim-migrate @ 11769] Patch 1093958 from Felipe Contreras. It fixes stuff. I also made some tweaks to make valgrind a bit happier. committer: Tailor Script <tailor@pidgin.im>
author Stu Tomlinson <stu@nosnilmot.com>
date Fri, 07 Jan 2005 02:48:33 +0000
parents 9bed28273ec7
children 1a97d5e88d12
comparison
equal deleted inserted replaced
10480:8e0a91d11362 10481:bcfea6c3d5c9
30 30
31 #include "userlist.h" 31 #include "userlist.h"
32 #include "sync.h" 32 #include "sync.h"
33 #include "slplink.h" 33 #include "slplink.h"
34 34
35 #define BUDDY_ALIAS_MAXLEN 388
36
37 static MsnTable *cbs_table; 35 static MsnTable *cbs_table;
38 36
39 /************************************************************************** 37 /**************************************************************************
40 * Main 38 * Main
41 **************************************************************************/ 39 **************************************************************************/
40
42 static void 41 static void
43 destroy_cb(MsnServConn *servconn) 42 destroy_cb(MsnServConn *servconn)
44 { 43 {
45 MsnNotification *notification; 44 MsnNotification *notification;
46 45
59 g_return_val_if_fail(session != NULL, NULL); 58 g_return_val_if_fail(session != NULL, NULL);
60 59
61 notification = g_new0(MsnNotification, 1); 60 notification = g_new0(MsnNotification, 1);
62 61
63 notification->session = session; 62 notification->session = session;
64 notification->servconn = servconn = msn_servconn_new(session, MSN_SERVER_NS); 63 notification->servconn = servconn = msn_servconn_new(session, MSN_SERVCONN_NS);
65 msn_servconn_set_destroy_cb(servconn, destroy_cb); 64 msn_servconn_set_destroy_cb(servconn, destroy_cb);
66 65
67 notification->cmdproc = servconn->cmdproc; 66 notification->cmdproc = servconn->cmdproc;
68 notification->cmdproc->data = notification; 67 notification->cmdproc->data = notification;
69 notification->cmdproc->cbs_table = cbs_table; 68 notification->cmdproc->cbs_table = cbs_table;
72 } 71 }
73 72
74 void 73 void
75 msn_notification_destroy(MsnNotification *notification) 74 msn_notification_destroy(MsnNotification *notification)
76 { 75 {
77 if (notification->destroying) 76 notification->cmdproc->data = NULL;
78 return; 77
79 78 msn_servconn_set_destroy_cb(notification->servconn, NULL);
80 notification->destroying = TRUE;
81 79
82 msn_servconn_destroy(notification->servconn); 80 msn_servconn_destroy(notification->servconn);
83 81
84 notification->session->notification = NULL;
85 g_free(notification); 82 g_free(notification);
86 } 83 }
87 84
88 /************************************************************************** 85 /**************************************************************************
89 * Connect 86 * Connect
90 **************************************************************************/ 87 **************************************************************************/
88
91 static void 89 static void
92 connect_cb(MsnServConn *servconn) 90 connect_cb(MsnServConn *servconn)
93 { 91 {
94 MsnCmdProc *cmdproc; 92 MsnCmdProc *cmdproc;
95 MsnSession *session; 93 MsnSession *session;
111 109
112 *c++ = g_strdup("CVR0"); 110 *c++ = g_strdup("CVR0");
113 111
114 vers = g_strjoinv(" ", a); 112 vers = g_strjoinv(" ", a);
115 113
114 msn_session_set_login_step(session, MSN_LOGIN_STEP_HANDSHAKE);
116 msn_cmdproc_send(cmdproc, "VER", "%s", vers); 115 msn_cmdproc_send(cmdproc, "VER", "%s", vers);
117 116
118 g_strfreev(a); 117 g_strfreev(a);
119 g_free(vers); 118 g_free(vers);
120
121 if (cmdproc->error)
122 return;
123
124 if (session->user == NULL)
125 session->user = msn_user_new(session->userlist,
126 gaim_account_get_username(account), NULL);
127 } 119 }
128 120
129 gboolean 121 gboolean
130 msn_notification_connect(MsnNotification *notification, const char *host, int port) 122 msn_notification_connect(MsnNotification *notification, const char *host, int port)
131 { 123 {
153 } 145 }
154 146
155 /************************************************************************** 147 /**************************************************************************
156 * Util 148 * Util
157 **************************************************************************/ 149 **************************************************************************/
150
158 static void 151 static void
159 group_error_helper(MsnSession *session, const char *msg, int group_id, int error) 152 group_error_helper(MsnSession *session, const char *msg, int group_id, int error)
160 { 153 {
161 GaimAccount *account; 154 GaimAccount *account;
162 GaimConnection *gc; 155 GaimConnection *gc;
196 } 189 }
197 190
198 /************************************************************************** 191 /**************************************************************************
199 * Login 192 * Login
200 **************************************************************************/ 193 **************************************************************************/
194
201 void 195 void
202 msn_got_login_params(MsnSession *session, const char *login_params) 196 msn_got_login_params(MsnSession *session, const char *login_params)
203 { 197 {
204 MsnCmdProc *cmdproc; 198 MsnCmdProc *cmdproc;
205 199
206 cmdproc = session->notification->cmdproc; 200 cmdproc = session->notification->cmdproc;
207 201
202 msn_session_set_login_step(session, MSN_LOGIN_STEP_AUTH_END);
203
208 msn_cmdproc_send(cmdproc, "USR", "TWN S %s", login_params); 204 msn_cmdproc_send(cmdproc, "USR", "TWN S %s", login_params);
209 } 205 }
210 206
211 static void 207 static void
212 cvr_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd) 208 cvr_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd)
218 msn_cmdproc_send(cmdproc, "USR", "TWN I %s", 214 msn_cmdproc_send(cmdproc, "USR", "TWN I %s",
219 gaim_account_get_username(account)); 215 gaim_account_get_username(account));
220 } 216 }
221 217
222 static void 218 static void
223 inf_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd) 219 usr_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd)
224 { 220 {
221 MsnSession *session;
225 GaimAccount *account; 222 GaimAccount *account;
226 GaimConnection *gc; 223 GaimConnection *gc;
227 224
228 account = cmdproc->session->account;
229 gc = gaim_account_get_connection(account);
230
231 if (strcmp(cmd->params[1], "MD5"))
232 {
233 msn_cmdproc_show_error(cmdproc, MSN_ERROR_MISC);
234 return;
235 }
236
237 msn_cmdproc_send(cmdproc, "USR", "MD5 I %s",
238 gaim_account_get_username(account));
239
240 if (cmdproc->error)
241 return;
242
243 gaim_connection_update_progress(gc, _("Requesting to send password"),
244 5, MSN_CONNECT_STEPS);
245 }
246
247 static void
248 usr_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd)
249 {
250 MsnSession *session;
251 GaimAccount *account;
252 GaimConnection *gc;
253
254 session = cmdproc->session; 225 session = cmdproc->session;
255 account = session->account; 226 account = session->account;
256 gc = gaim_account_get_connection(account); 227 gc = gaim_account_get_connection(account);
257 228
258 /*
259 * We're either getting the passport connect info (if we're on
260 * MSNP8 or higher), or a challenge request (MSNP7 and lower).
261 *
262 * Let's find out.
263 */
264 if (!g_ascii_strcasecmp(cmd->params[1], "OK")) 229 if (!g_ascii_strcasecmp(cmd->params[1], "OK"))
265 { 230 {
231 /* OK */
266 const char *friendly = gaim_url_decode(cmd->params[3]); 232 const char *friendly = gaim_url_decode(cmd->params[3]);
267 233
268 /* OK */
269
270 gaim_connection_set_display_name(gc, friendly); 234 gaim_connection_set_display_name(gc, friendly);
271 235
236 msn_session_set_login_step(session, MSN_LOGIN_STEP_SYN);
237
272 msn_cmdproc_send(cmdproc, "SYN", "%s", "0"); 238 msn_cmdproc_send(cmdproc, "SYN", "%s", "0");
273
274 if (cmdproc->error)
275 return;
276
277 gaim_connection_update_progress(gc, _("Retrieving buddy list"),
278 7, MSN_CONNECT_STEPS);
279 } 239 }
280 else if (!g_ascii_strcasecmp(cmd->params[1], "TWN")) 240 else if (!g_ascii_strcasecmp(cmd->params[1], "TWN"))
281 { 241 {
242 /* Passport authentication */
282 char **elems, **cur, **tokens; 243 char **elems, **cur, **tokens;
283 244
284 /* Passport authentication */
285 session->nexus = msn_nexus_new(session); 245 session->nexus = msn_nexus_new(session);
286 246
287 /* Parse the challenge data. */ 247 /* Parse the challenge data. */
288 248
289 elems = g_strsplit(cmd->params[3], ",", 0); 249 elems = g_strsplit(cmd->params[3], ",", 0);
296 g_free(tokens); 256 g_free(tokens);
297 } 257 }
298 258
299 g_strfreev(elems); 259 g_strfreev(elems);
300 260
261 msn_session_set_login_step(session, MSN_LOGIN_STEP_AUTH_START);
262
301 msn_nexus_connect(session->nexus); 263 msn_nexus_connect(session->nexus);
302
303 gaim_connection_update_progress(gc, _("Password sent"),
304 6, MSN_CONNECT_STEPS);
305 }
306 else if (!g_ascii_strcasecmp(cmd->params[1], "MD5"))
307 {
308 /* Challenge */
309 const char *challenge;
310 const char *password;
311 char buf[33];
312 md5_state_t st;
313 md5_byte_t di[16];
314 int i;
315
316 challenge = cmd->params[3];
317 password = gaim_account_get_password(account);
318
319 md5_init(&st);
320 md5_append(&st, (const md5_byte_t *)challenge, strlen(challenge));
321 md5_append(&st, (const md5_byte_t *)password, strlen(password));
322 md5_finish(&st, di);
323
324 for (i = 0; i < 16; i++)
325 g_snprintf(buf + (i*2), 3, "%02x", di[i]);
326
327 msn_cmdproc_send(cmdproc, "USR", "MD5 S %s", buf);
328
329 if (cmdproc->error)
330 return;
331
332 gaim_connection_update_progress(gc, _("Password sent"),
333 6, MSN_CONNECT_STEPS);
334 } 264 }
335 } 265 }
336 266
337 static void 267 static void
338 ver_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd) 268 ver_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd)
357 } 287 }
358 } 288 }
359 289
360 if (!protocol_supported) 290 if (!protocol_supported)
361 { 291 {
362 msn_cmdproc_show_error(cmdproc, MSN_ERROR_MISC); 292 msn_session_set_error(session, MSN_ERROR_UNSUPORTED_PROTOCOL,
293 NULL);
363 return; 294 return;
364 } 295 }
365 296
366 msn_cmdproc_send(cmdproc, "CVR", 297 msn_cmdproc_send(cmdproc, "CVR",
367 "0x0409 winnt 5.1 i386 MSNMSGR 6.0.0602 MSMSGS %s", 298 "0x0409 winnt 5.1 i386 MSNMSGR 6.0.0602 MSMSGS %s",
369 } 300 }
370 301
371 /************************************************************************** 302 /**************************************************************************
372 * Log out 303 * Log out
373 **************************************************************************/ 304 **************************************************************************/
305
374 static void 306 static void
375 out_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd) 307 out_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd)
376 { 308 {
377 if (!g_ascii_strcasecmp(cmd->params[0], "OTH")) 309 if (!g_ascii_strcasecmp(cmd->params[0], "OTH"))
378 msn_cmdproc_show_error(cmdproc, MSN_ERROR_SIGNOTHER); 310 msn_session_set_error(cmdproc->session, MSN_ERROR_SIGN_OTHER,
311 NULL);
379 else if (!g_ascii_strcasecmp(cmd->params[0], "SSD")) 312 else if (!g_ascii_strcasecmp(cmd->params[0], "SSD"))
380 msn_cmdproc_show_error(cmdproc, MSN_ERROR_SERVDOWN); 313 msn_session_set_error(cmdproc->session, MSN_ERROR_SERV_DOWN, NULL);
381 } 314 }
382 315
383 void 316 void
384 msn_notification_close(MsnNotification *notification) 317 msn_notification_close(MsnNotification *notification)
385 { 318 {
391 } 324 }
392 325
393 /************************************************************************** 326 /**************************************************************************
394 * Messages 327 * Messages
395 **************************************************************************/ 328 **************************************************************************/
329
396 static void 330 static void
397 msg_cmd_post(MsnCmdProc *cmdproc, MsnCommand *cmd, char *payload, 331 msg_cmd_post(MsnCmdProc *cmdproc, MsnCommand *cmd, char *payload,
398 size_t len) 332 size_t len)
399 { 333 {
400 MsnMessage *msg; 334 MsnMessage *msg;
429 } 363 }
430 364
431 /************************************************************************** 365 /**************************************************************************
432 * Challenges 366 * Challenges
433 **************************************************************************/ 367 **************************************************************************/
368
434 static void 369 static void
435 chl_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd) 370 chl_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd)
436 { 371 {
437 MsnTransaction *trans; 372 MsnTransaction *trans;
438 char buf[33]; 373 char buf[33];
462 } 397 }
463 398
464 /************************************************************************** 399 /**************************************************************************
465 * Buddy Lists 400 * Buddy Lists
466 **************************************************************************/ 401 **************************************************************************/
402
467 static void 403 static void
468 add_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd) 404 add_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd)
469 { 405 {
470 MsnSession *session; 406 MsnSession *session;
471 MsnUser *user; 407 MsnUser *user;
872 808
873 session = cmdproc->session; 809 session = cmdproc->session;
874 810
875 if (cmd->param_count == 2) 811 if (cmd->param_count == 2)
876 { 812 {
877 char *buf;
878 /* 813 /*
879 * This can happen if we sent a SYN with an up-to-date 814 * This can happen if we sent a SYN with an up-to-date
880 * buddy list revision, but we send 0 to get a full list. 815 * buddy list revision, but we send 0 to get a full list.
881 * So, error out. 816 * So, error out.
882 */ 817 */
883 buf = g_strdup_printf( 818
884 _("Your MSN buddy list for %s is temporarily unavailable. " 819 msn_session_set_error(cmdproc->session, MSN_ERROR_BAD_BLIST, NULL);
885 "Please wait and try again."),
886 gaim_account_get_username(session->account));
887
888 gaim_connection_error(gaim_account_get_connection(session->account),
889 buf);
890
891 g_free(buf);
892
893 return; 820 return;
894 } 821 }
895 822
896 total_users = atoi(cmd->params[2]); 823 total_users = atoi(cmd->params[2]);
897 824
914 } 841 }
915 842
916 /************************************************************************** 843 /**************************************************************************
917 * Misc commands 844 * Misc commands
918 **************************************************************************/ 845 **************************************************************************/
846
919 static void 847 static void
920 url_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd) 848 url_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd)
921 { 849 {
922 MsnSession *session; 850 MsnSession *session;
923 GaimAccount *account; 851 GaimAccount *account;
1016 } 944 }
1017 } 945 }
1018 /************************************************************************** 946 /**************************************************************************
1019 * Switchboards 947 * Switchboards
1020 **************************************************************************/ 948 **************************************************************************/
949
1021 static void 950 static void
1022 rng_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd) 951 rng_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd)
1023 { 952 {
1024 MsnSession *session; 953 MsnSession *session;
1025 MsnSwitchBoard *swboard; 954 MsnSwitchBoard *swboard;
1054 char *host; 983 char *host;
1055 int port; 984 int port;
1056 985
1057 if (strcmp(cmd->params[1], "SB") && strcmp(cmd->params[1], "NS")) 986 if (strcmp(cmd->params[1], "SB") && strcmp(cmd->params[1], "NS"))
1058 { 987 {
1059 msn_cmdproc_show_error(cmdproc, MSN_ERROR_MISC); 988 /* Maybe we can have a generic bad command error. */
989 gaim_debug_error("msn", "Bad XFR command (%s)\n", cmd->params[1]);
1060 return; 990 return;
1061 } 991 }
1062 992
1063 msn_parse_socket(cmd->params[2], &host, &port); 993 msn_parse_socket(cmd->params[2], &host, &port);
1064 994
1065 if (!strcmp(cmd->params[1], "SB")) 995 if (!strcmp(cmd->params[1], "SB"))
1066 { 996 {
1067 gaim_debug_error("msn", "This shouldn't be handled here.\n"); 997 gaim_debug_error("msn", "This shouldn't be handled here.\n");
1068 #if 0
1069 swboard = cmd->trans->data;
1070
1071 if (swboard != NULL)
1072 {
1073 msn_switchboard_set_auth_key(swboard, cmd->params[4]);
1074
1075 if (session->http_method)
1076 port = 80;
1077
1078 msn_switchboard_connect(swboard, host, port);
1079 }
1080 #endif
1081 } 998 }
1082 else if (!strcmp(cmd->params[1], "NS")) 999 else if (!strcmp(cmd->params[1], "NS"))
1083 { 1000 {
1084 MsnSession *session; 1001 MsnSession *session;
1085 1002
1086 session = cmdproc->session; 1003 session = cmdproc->session;
1004
1005 if (!session->logged_in)
1006 msn_session_set_login_step(session, MSN_LOGIN_STEP_TRANSFER);
1087 1007
1088 msn_notification_connect(session->notification, host, port); 1008 msn_notification_connect(session->notification, host, port);
1089 } 1009 }
1090 1010
1091 g_free(host); 1011 g_free(host);
1092 } 1012 }
1093 1013
1094 /************************************************************************** 1014 /**************************************************************************
1095 * Message Types 1015 * Message Types
1096 **************************************************************************/ 1016 **************************************************************************/
1017
1097 static void 1018 static void
1098 profile_msg(MsnCmdProc *cmdproc, MsnMessage *msg) 1019 profile_msg(MsnCmdProc *cmdproc, MsnMessage *msg)
1099 { 1020 {
1100 MsnSession *session; 1021 MsnSession *session;
1101 const char *value; 1022 const char *value;
1341 } 1262 }
1342 1263
1343 /************************************************************************** 1264 /**************************************************************************
1344 * Init 1265 * Init
1345 **************************************************************************/ 1266 **************************************************************************/
1267
1346 void 1268 void
1347 msn_notification_init(void) 1269 msn_notification_init(void)
1348 { 1270 {
1349 /* TODO: check prp, blp */ 1271 /* TODO: check prp, blp */
1350 1272
1358 msn_table_add_cmd(cbs_table, "REM", "REM", rem_cmd); 1280 msn_table_add_cmd(cbs_table, "REM", "REM", rem_cmd);
1359 msn_table_add_cmd(cbs_table, "USR", "USR", usr_cmd); 1281 msn_table_add_cmd(cbs_table, "USR", "USR", usr_cmd);
1360 msn_table_add_cmd(cbs_table, "USR", "XFR", xfr_cmd); 1282 msn_table_add_cmd(cbs_table, "USR", "XFR", xfr_cmd);
1361 msn_table_add_cmd(cbs_table, "SYN", "SYN", syn_cmd); 1283 msn_table_add_cmd(cbs_table, "SYN", "SYN", syn_cmd);
1362 msn_table_add_cmd(cbs_table, "CVR", "CVR", cvr_cmd); 1284 msn_table_add_cmd(cbs_table, "CVR", "CVR", cvr_cmd);
1363 msn_table_add_cmd(cbs_table, "INF", "INF", inf_cmd);
1364 msn_table_add_cmd(cbs_table, "VER", "VER", ver_cmd); 1285 msn_table_add_cmd(cbs_table, "VER", "VER", ver_cmd);
1365 msn_table_add_cmd(cbs_table, "REA", "REA", rea_cmd); 1286 msn_table_add_cmd(cbs_table, "REA", "REA", rea_cmd);
1366 /* msn_table_add_cmd(cbs_table, "PRP", "PRP", prp_cmd); */ 1287 /* msn_table_add_cmd(cbs_table, "PRP", "PRP", prp_cmd); */
1367 /* msn_table_add_cmd(cbs_table, "BLP", "BLP", blp_cmd); */ 1288 /* msn_table_add_cmd(cbs_table, "BLP", "BLP", blp_cmd); */
1368 msn_table_add_cmd(cbs_table, "BLP", "BLP", NULL); 1289 msn_table_add_cmd(cbs_table, "BLP", "BLP", NULL);