comparison libpurple/protocols/myspace/myspace.c @ 20121:e4bcdd9622c2

purple_connection_error_reason-ify myspace
author Will Thompson <will.thompson@collabora.co.uk>
date Thu, 20 Sep 2007 17:30:59 +0000
parents 27754fc4d72e
children f3cfcbbac3d8
comparison
equal deleted inserted replaced
20120:557c4c67bd29 20121:e4bcdd9622c2
289 (int)strlen(acct->password)); 289 (int)strlen(acct->password));
290 290
291 /* Notify an error message also, because this is important! */ 291 /* Notify an error message also, because this is important! */
292 purple_notify_error(acct, g_strdup(_("MySpaceIM Error")), str, NULL); 292 purple_notify_error(acct, g_strdup(_("MySpaceIM Error")), str, NULL);
293 293
294 purple_connection_error(gc, str); 294 purple_connection_error_reason (gc,
295 PURPLE_REASON_AUTHENTICATION_FAILED, str);
295 296
296 g_free(str); 297 g_free(str);
297 } 298 }
298 #endif 299 #endif
299 300
312 313
313 /* Calls msim_connect_cb when connected. */ 314 /* Calls msim_connect_cb when connected. */
314 if (!purple_proxy_connect(gc, acct, host, port, msim_connect_cb, gc)) { 315 if (!purple_proxy_connect(gc, acct, host, port, msim_connect_cb, gc)) {
315 /* TODO: try other ports if in auto mode, then save 316 /* TODO: try other ports if in auto mode, then save
316 * working port and try that first next time. */ 317 * working port and try that first next time. */
317 purple_connection_error(gc, _("Couldn't create socket")); 318 purple_connection_error_reason (gc, PURPLE_REASON_NETWORK_ERROR,
319 _("Couldn't create socket"));
318 return; 320 return;
319 } 321 }
320 } 322 }
321 323
322 /** 324 /**
349 351
350 purple_debug_info("msim", "nc is %d bytes, decoded\n", nc_len); 352 purple_debug_info("msim", "nc is %d bytes, decoded\n", nc_len);
351 353
352 if (nc_len != MSIM_AUTH_CHALLENGE_LENGTH) { 354 if (nc_len != MSIM_AUTH_CHALLENGE_LENGTH) {
353 purple_debug_info("msim", "bad nc length: %x != 0x%x\n", nc_len, MSIM_AUTH_CHALLENGE_LENGTH); 355 purple_debug_info("msim", "bad nc length: %x != 0x%x\n", nc_len, MSIM_AUTH_CHALLENGE_LENGTH);
354 purple_connection_error(session->gc, _("Unexpected challenge length from server")); 356 purple_connection_error_reason (session->gc, PURPLE_REASON_NETWORK_ERROR,
357 _("Unexpected challenge length from server"));
355 return FALSE; 358 return FALSE;
356 } 359 }
357 360
358 purple_connection_update_progress(session->gc, _("Logging in"), 2, 4); 361 purple_connection_update_progress(session->gc, _("Logging in"), 2, 4);
359 362
1275 if (delta >= MSIM_KEEPALIVE_INTERVAL) { 1278 if (delta >= MSIM_KEEPALIVE_INTERVAL) {
1276 errmsg = g_strdup_printf(_("Connection to server lost (no data received within %d seconds)"), (int)delta); 1279 errmsg = g_strdup_printf(_("Connection to server lost (no data received within %d seconds)"), (int)delta);
1277 1280
1278 purple_debug_info("msim", "msim_check_alive: %s > interval of %d, presumed dead\n", 1281 purple_debug_info("msim", "msim_check_alive: %s > interval of %d, presumed dead\n",
1279 errmsg, MSIM_KEEPALIVE_INTERVAL); 1282 errmsg, MSIM_KEEPALIVE_INTERVAL);
1280 purple_connection_error(session->gc, errmsg); 1283 purple_connection_error_reason (session->gc,
1284 PURPLE_REASON_NETWORK_ERROR, errmsg);
1281 1285
1282 purple_notify_error(session->gc, NULL, errmsg, NULL); 1286 purple_notify_error(session->gc, NULL, errmsg, NULL);
1283 1287
1284 g_free(errmsg); 1288 g_free(errmsg);
1285 1289
1544 purple_debug_info("msim_we_are_logged_on", "TODO: pick username\n"); 1548 purple_debug_info("msim_we_are_logged_on", "TODO: pick username\n");
1545 /* No username is set. */ 1549 /* No username is set. */
1546 purple_notify_error(session->account, 1550 purple_notify_error(session->account,
1547 _("No username set"), 1551 _("No username set"),
1548 _("Please go to http://editprofile.myspace.com/index.cfm?fuseaction=profile.username and choose a username and try to login again."), NULL); 1552 _("Please go to http://editprofile.myspace.com/index.cfm?fuseaction=profile.username and choose a username and try to login again."), NULL);
1549 purple_connection_error(session->gc, _("No username set")); 1553 session->gc->wants_to_die = TRUE;
1554 purple_connection_error_reason (session->gc, PURPLE_REASON_AUTHENTICATION_FAILED, _("No username set"));
1550 return FALSE; 1555 return FALSE;
1551 } 1556 }
1552 1557
1553 body = msim_msg_new( 1558 body = msim_msg_new(
1554 "UserID", MSIM_TYPE_INTEGER, session->userid, 1559 "UserID", MSIM_TYPE_INTEGER, session->userid,
1780 purple_debug_info("msim", "msim_error (sesskey=%d): %s\n", 1785 purple_debug_info("msim", "msim_error (sesskey=%d): %s\n",
1781 session->sesskey, full_errmsg); 1786 session->sesskey, full_errmsg);
1782 1787
1783 /* Destroy session if fatal. */ 1788 /* Destroy session if fatal. */
1784 if (msim_msg_get(msg, "fatal")) { 1789 if (msim_msg_get(msg, "fatal")) {
1790 PurpleDisconnectReason reason = PURPLE_REASON_NETWORK_ERROR;
1785 purple_debug_info("msim", "fatal error, closing\n"); 1791 purple_debug_info("msim", "fatal error, closing\n");
1786 if (err == 260) { 1792 if (err == 260) {
1787 /* Incorrect password */ 1793 /* Incorrect password */
1788 session->gc->wants_to_die = TRUE; 1794 session->gc->wants_to_die = TRUE;
1795 reason = PURPLE_REASON_AUTHENTICATION_FAILED;
1789 if (!purple_account_get_remember_password(session->account)) 1796 if (!purple_account_get_remember_password(session->account))
1790 purple_account_set_password(session->account, NULL); 1797 purple_account_set_password(session->account, NULL);
1791 } 1798 }
1792 purple_connection_error(session->gc, full_errmsg); 1799 purple_connection_error_reason (session->gc, reason, full_errmsg);
1793 } else { 1800 } else {
1794 purple_notify_error(session->account, g_strdup(_("MySpaceIM Error")), 1801 purple_notify_error(session->account, g_strdup(_("MySpaceIM Error")),
1795 full_errmsg, NULL); 1802 full_errmsg, NULL);
1796 } 1803 }
1797 1804
2303 session = gc->proto_data; 2310 session = gc->proto_data;
2304 2311
2305 /* libpurple/eventloop.h only defines these two */ 2312 /* libpurple/eventloop.h only defines these two */
2306 if (cond != PURPLE_INPUT_READ && cond != PURPLE_INPUT_WRITE) { 2313 if (cond != PURPLE_INPUT_READ && cond != PURPLE_INPUT_WRITE) {
2307 purple_debug_info("msim_input_cb", "unknown condition=%d\n", cond); 2314 purple_debug_info("msim_input_cb", "unknown condition=%d\n", cond);
2308 purple_connection_error(gc, _("Invalid input condition")); 2315 purple_connection_error_reason (gc, PURPLE_REASON_NETWORK_ERROR,
2316 _("Invalid input condition"));
2309 return; 2317 return;
2310 } 2318 }
2311 2319
2312 g_return_if_fail(cond == PURPLE_INPUT_READ); 2320 g_return_if_fail(cond == PURPLE_INPUT_READ);
2313 g_return_if_fail(MSIM_SESSION_VALID(session)); 2321 g_return_if_fail(MSIM_SESSION_VALID(session));
2321 */ 2329 */
2322 if (session->rxoff >= MSIM_READ_BUF_SIZE) { 2330 if (session->rxoff >= MSIM_READ_BUF_SIZE) {
2323 purple_debug_error("msim", 2331 purple_debug_error("msim",
2324 "msim_input_cb: %d-byte read buffer full! rxoff=%d\n", 2332 "msim_input_cb: %d-byte read buffer full! rxoff=%d\n",
2325 MSIM_READ_BUF_SIZE, session->rxoff); 2333 MSIM_READ_BUF_SIZE, session->rxoff);
2326 purple_connection_error(gc, _("Read buffer full")); 2334 purple_connection_error_reason (gc, PURPLE_REASON_NETWORK_ERROR,
2335 _("Read buffer full"));
2327 return; 2336 return;
2328 } 2337 }
2329 2338
2330 purple_debug_info("msim", "buffer at %d (max %d), reading up to %d\n", 2339 purple_debug_info("msim", "buffer at %d (max %d), reading up to %d\n",
2331 session->rxoff, MSIM_READ_BUF_SIZE, 2340 session->rxoff, MSIM_READ_BUF_SIZE,
2340 return; 2349 return;
2341 } else if (n < 0) { 2350 } else if (n < 0) {
2342 purple_debug_error("msim", "msim_input_cb: read error, ret=%d, " 2351 purple_debug_error("msim", "msim_input_cb: read error, ret=%d, "
2343 "error=%s, source=%d, fd=%d (%X))\n", 2352 "error=%s, source=%d, fd=%d (%X))\n",
2344 n, strerror(errno), source, session->fd, session->fd); 2353 n, strerror(errno), source, session->fd, session->fd);
2345 purple_connection_error(gc, _("Read error")); 2354 purple_connection_error_reason (gc, PURPLE_REASON_NETWORK_ERROR,
2355 _("Read error"));
2346 return; 2356 return;
2347 } else if (n == 0) { 2357 } else if (n == 0) {
2348 purple_debug_info("msim", "msim_input_cb: server disconnected\n"); 2358 purple_debug_info("msim", "msim_input_cb: server disconnected\n");
2349 purple_connection_error(gc, _("Server has disconnected")); 2359 purple_connection_error_reason (gc, PURPLE_REASON_NETWORK_ERROR,
2360 _("Server has disconnected"));
2350 return; 2361 return;
2351 } 2362 }
2352 2363
2353 if (n + session->rxoff >= MSIM_READ_BUF_SIZE) { 2364 if (n + session->rxoff >= MSIM_READ_BUF_SIZE) {
2354 purple_debug_info("msim_input_cb", "received %d bytes, pushing rxoff to %d, over buffer size of %d\n", 2365 purple_debug_info("msim_input_cb", "received %d bytes, pushing rxoff to %d, over buffer size of %d\n",
2355 n, n + session->rxoff, MSIM_READ_BUF_SIZE); 2366 n, n + session->rxoff, MSIM_READ_BUF_SIZE);
2356 /* TODO: g_realloc like msn, yahoo, irc, jabber? */ 2367 /* TODO: g_realloc like msn, yahoo, irc, jabber? */
2357 purple_connection_error(gc, _("Read buffer full")); 2368 purple_connection_error_reason (gc, PURPLE_REASON_NETWORK_ERROR,
2369 _("Read buffer full"));
2358 } 2370 }
2359 2371
2360 /* Null terminate */ 2372 /* Null terminate */
2361 purple_debug_info("msim", "msim_input_cb: going to null terminate " 2373 purple_debug_info("msim", "msim_input_cb: going to null terminate "
2362 "at n=%d\n", n); 2374 "at n=%d\n", n);
2367 if (strlen(session->rxbuf + session->rxoff) != n) { 2379 if (strlen(session->rxbuf + session->rxoff) != n) {
2368 /* Occurs after login, but it is not a null byte. */ 2380 /* Occurs after login, but it is not a null byte. */
2369 purple_debug_info("msim", "msim_input_cb: strlen=%d, but read %d bytes" 2381 purple_debug_info("msim", "msim_input_cb: strlen=%d, but read %d bytes"
2370 "--null byte encountered?\n", 2382 "--null byte encountered?\n",
2371 strlen(session->rxbuf + session->rxoff), n); 2383 strlen(session->rxbuf + session->rxoff), n);
2372 //purple_connection_error(gc, "Invalid message - null byte on input"); 2384 /*purple_connection_error_reason (gc, PURPLE_REASON_NETWORK_ERROR,
2385 "Invalid message - null byte on input"); */
2373 return; 2386 return;
2374 } 2387 }
2375 #endif 2388 #endif
2376 2389
2377 session->rxoff += n; 2390 session->rxoff += n;
2390 #endif 2403 #endif
2391 *end = 0; 2404 *end = 0;
2392 msg = msim_parse(g_strdup(session->rxbuf)); 2405 msg = msim_parse(g_strdup(session->rxbuf));
2393 if (!msg) { 2406 if (!msg) {
2394 purple_debug_info("msim", "msim_input_cb: couldn't parse rxbuf\n"); 2407 purple_debug_info("msim", "msim_input_cb: couldn't parse rxbuf\n");
2395 purple_connection_error(gc, _("Unparseable message")); 2408 purple_connection_error_reason (gc, PURPLE_REASON_NETWORK_ERROR,
2409 _("Unparseable message"));
2396 } else { 2410 } else {
2397 /* Process message and then free it (processing function should 2411 /* Process message and then free it (processing function should
2398 * clone message if it wants to keep it afterwards.) */ 2412 * clone message if it wants to keep it afterwards.) */
2399 if (!msim_preprocess_incoming(session, msg)) { 2413 if (!msim_preprocess_incoming(session, msg)) {
2400 msim_msg_dump("msim_input_cb: preprocessing message failed on msg: %s\n", msg); 2414 msim_msg_dump("msim_input_cb: preprocessing message failed on msg: %s\n", msg);
2457 2471
2458 gc = (PurpleConnection *)data; 2472 gc = (PurpleConnection *)data;
2459 session = (MsimSession *)gc->proto_data; 2473 session = (MsimSession *)gc->proto_data;
2460 2474
2461 if (source < 0) { 2475 if (source < 0) {
2462 purple_connection_error(gc, _("Couldn't connect to host")); 2476 purple_connection_error_reason (gc, PURPLE_REASON_NETWORK_ERROR,
2463 purple_connection_error(gc, g_strdup_printf( 2477 g_strdup_printf(_("Couldn't connect to host: %s (%d)"),
2464 _("Couldn't connect to host: %s (%d)"),
2465 error_message ? error_message : "no message given", 2478 error_message ? error_message : "no message given",
2466 source)); 2479 source));
2467 return; 2480 return;
2468 } 2481 }
2469 2482