comparison libpurple/protocols/simple/simple.c @ 21358:ba41f2a60253

Rename: * PurpleDisconnectReason to PurpleConnectionError; * elements of that enum from PURPLE_REASON_* to PURPLE_CONNECTION_ERROR_*; * purple_connection_reason_is_fatal to purple_connection_error_is_fatal.
author Will Thompson <will.thompson@collabora.co.uk>
date Sun, 14 Oct 2007 21:08:42 +0000
parents efa448405f3d
children e747ac0c42d6
comparison
equal deleted inserted replaced
21357:5a3242b676ad 21358:ba41f2a60253
411 411
412 if(written < 0 && errno == EAGAIN) 412 if(written < 0 && errno == EAGAIN)
413 written = 0; 413 written = 0;
414 else if(written <= 0) { 414 else if(written <= 0) {
415 /*TODO: do we really want to disconnect on a failure to write?*/ 415 /*TODO: do we really want to disconnect on a failure to write?*/
416 purple_connection_error_reason(gc, PURPLE_REASON_NETWORK_ERROR, 416 purple_connection_error_reason(gc,
417 PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
417 _("Could not write")); 418 _("Could not write"));
418 return; 419 return;
419 } 420 }
420 421
421 purple_circ_buffer_mark_read(sip->txbuf, written); 422 purple_circ_buffer_mark_read(sip->txbuf, written);
434 close(source); 435 close(source);
435 return; 436 return;
436 } 437 }
437 438
438 if(source < 0) { 439 if(source < 0) {
439 purple_connection_error_reason(gc, PURPLE_REASON_NETWORK_ERROR, 440 purple_connection_error_reason(gc,
441 PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
440 _("Could not connect")); 442 _("Could not connect"));
441 return; 443 return;
442 } 444 }
443 445
444 sip = gc->proto_data; 446 sip = gc->proto_data;
461 struct simple_account_data *sip = gc->proto_data; 463 struct simple_account_data *sip = gc->proto_data;
462 464
463 if(!sip->connecting) { 465 if(!sip->connecting) {
464 purple_debug_info("simple", "connecting to %s port %d\n", sip->realhostname ? sip->realhostname : "{NULL}", sip->realport); 466 purple_debug_info("simple", "connecting to %s port %d\n", sip->realhostname ? sip->realhostname : "{NULL}", sip->realport);
465 if (purple_proxy_connect(gc, sip->account, sip->realhostname, sip->realport, send_later_cb, gc) == NULL) { 467 if (purple_proxy_connect(gc, sip->account, sip->realhostname, sip->realport, send_later_cb, gc) == NULL) {
466 purple_connection_error_reason(gc, PURPLE_REASON_NETWORK_ERROR, _("Couldn't create socket")); 468 purple_connection_error_reason(gc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR, _("Couldn't create socket"));
467 } 469 }
468 sip->connecting = TRUE; 470 sip->connecting = TRUE;
469 } 471 }
470 472
471 if(purple_circ_buffer_get_max_read(sip->txbuf) > 0) 473 if(purple_circ_buffer_get_max_read(sip->txbuf) > 0)
1043 purple_debug_info("simple", "REGISTER retries %d\n", sip->registrar.retries); 1045 purple_debug_info("simple", "REGISTER retries %d\n", sip->registrar.retries);
1044 if(sip->registrar.retries > SIMPLE_REGISTER_RETRY_MAX) { 1046 if(sip->registrar.retries > SIMPLE_REGISTER_RETRY_MAX) {
1045 if (!purple_account_get_remember_password(sip->gc->account)) 1047 if (!purple_account_get_remember_password(sip->gc->account))
1046 purple_account_set_password(sip->gc->account, NULL); 1048 purple_account_set_password(sip->gc->account, NULL);
1047 purple_connection_error_reason(sip->gc, 1049 purple_connection_error_reason(sip->gc,
1048 PURPLE_REASON_AUTHENTICATION_FAILED, 1050 PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED,
1049 _("Incorrect password.")); 1051 _("Incorrect password."));
1050 return TRUE; 1052 return TRUE;
1051 } 1053 }
1052 tmp = sipmsg_find_header(msg, "WWW-Authenticate"); 1054 tmp = sipmsg_find_header(msg, "WWW-Authenticate");
1053 fill_auth(sip, tmp, &sip->registrar); 1055 fill_auth(sip, tmp, &sip->registrar);
1057 break; 1059 break;
1058 default: 1060 default:
1059 if (sip->registerstatus != SIMPLE_REGISTER_RETRY) { 1061 if (sip->registerstatus != SIMPLE_REGISTER_RETRY) {
1060 purple_debug_info("simple", "Unrecognized return code for REGISTER.\n"); 1062 purple_debug_info("simple", "Unrecognized return code for REGISTER.\n");
1061 if (sip->registrar.retries > SIMPLE_REGISTER_RETRY_MAX) { 1063 if (sip->registrar.retries > SIMPLE_REGISTER_RETRY_MAX) {
1062 purple_connection_error_reason(sip->gc, PURPLE_REASON_OTHER_ERROR, 1064 purple_connection_error_reason(sip->gc,
1065 PURPLE_CONNECTION_ERROR_OTHER_ERROR,
1063 _("Unknown server response.")); 1066 _("Unknown server response."));
1064 return TRUE; 1067 return TRUE;
1065 } 1068 }
1066 sip->registerstatus = SIMPLE_REGISTER_RETRY; 1069 sip->registerstatus = SIMPLE_REGISTER_RETRY;
1067 do_register(sip); 1070 do_register(sip);
1528 close(source); 1531 close(source);
1529 return; 1532 return;
1530 } 1533 }
1531 1534
1532 if(source < 0) { 1535 if(source < 0) {
1533 purple_connection_error_reason(gc, PURPLE_REASON_NETWORK_ERROR, 1536 purple_connection_error_reason(gc,
1537 PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
1534 _("Could not connect")); 1538 _("Could not connect"));
1535 return; 1539 return;
1536 } 1540 }
1537 1541
1538 sip = gc->proto_data; 1542 sip = gc->proto_data;
1563 struct simple_account_data *sip = (struct simple_account_data*) data; 1567 struct simple_account_data *sip = (struct simple_account_data*) data;
1564 1568
1565 sip->listen_data = NULL; 1569 sip->listen_data = NULL;
1566 1570
1567 if(listenfd == -1) { 1571 if(listenfd == -1) {
1568 purple_connection_error_reason(sip->gc, PURPLE_REASON_NETWORK_ERROR, 1572 purple_connection_error_reason(sip->gc,
1573 PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
1569 _("Could not create listen socket")); 1574 _("Could not create listen socket"));
1570 return; 1575 return;
1571 } 1576 }
1572 1577
1573 sip->fd = listenfd; 1578 sip->fd = listenfd;
1588 1593
1589 sip->query_data = NULL; 1594 sip->query_data = NULL;
1590 1595
1591 if (!hosts || !hosts->data) { 1596 if (!hosts || !hosts->data) {
1592 purple_connection_error_reason(sip->gc, 1597 purple_connection_error_reason(sip->gc,
1593 PURPLE_REASON_NETWORK_ERROR, 1598 PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
1594 _("Couldn't resolve host")); 1599 _("Couldn't resolve host"));
1595 return; 1600 return;
1596 } 1601 }
1597 1602
1598 addr_size = GPOINTER_TO_INT(hosts->data); 1603 addr_size = GPOINTER_TO_INT(hosts->data);
1609 /* create socket for incoming connections */ 1614 /* create socket for incoming connections */
1610 sip->listen_data = purple_network_listen_range(5060, 5160, SOCK_DGRAM, 1615 sip->listen_data = purple_network_listen_range(5060, 5160, SOCK_DGRAM,
1611 simple_udp_host_resolved_listen_cb, sip); 1616 simple_udp_host_resolved_listen_cb, sip);
1612 if (sip->listen_data == NULL) { 1617 if (sip->listen_data == NULL) {
1613 purple_connection_error_reason(sip->gc, 1618 purple_connection_error_reason(sip->gc,
1614 PURPLE_REASON_NETWORK_ERROR, 1619 PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
1615 _("Could not create listen socket")); 1620 _("Could not create listen socket"));
1616 return; 1621 return;
1617 } 1622 }
1618 } 1623 }
1619 1624
1624 sip->listen_data = NULL; 1629 sip->listen_data = NULL;
1625 1630
1626 sip->listenfd = listenfd; 1631 sip->listenfd = listenfd;
1627 if(sip->listenfd == -1) { 1632 if(sip->listenfd == -1) {
1628 purple_connection_error_reason(sip->gc, 1633 purple_connection_error_reason(sip->gc,
1629 PURPLE_REASON_NETWORK_ERROR, 1634 PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
1630 _("Could not create listen socket")); 1635 _("Could not create listen socket"));
1631 return; 1636 return;
1632 } 1637 }
1633 1638
1634 purple_debug_info("simple", "listenfd: %d\n", sip->listenfd); 1639 purple_debug_info("simple", "listenfd: %d\n", sip->listenfd);
1639 sip->realhostname, sip->realport); 1644 sip->realhostname, sip->realport);
1640 /* open tcp connection to the server */ 1645 /* open tcp connection to the server */
1641 if (purple_proxy_connect(sip->gc, sip->account, sip->realhostname, 1646 if (purple_proxy_connect(sip->gc, sip->account, sip->realhostname,
1642 sip->realport, login_cb, sip->gc) == NULL) { 1647 sip->realport, login_cb, sip->gc) == NULL) {
1643 purple_connection_error_reason(sip->gc, 1648 purple_connection_error_reason(sip->gc,
1644 PURPLE_REASON_NETWORK_ERROR, 1649 PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
1645 _("Couldn't create socket")); 1650 _("Couldn't create socket"));
1646 } 1651 }
1647 } 1652 }
1648 1653
1649 static void srvresolved(PurpleSrvResponse *resp, int results, gpointer data) { 1654 static void srvresolved(PurpleSrvResponse *resp, int results, gpointer data) {
1678 if(!sip->udp) { 1683 if(!sip->udp) {
1679 /* create socket for incoming connections */ 1684 /* create socket for incoming connections */
1680 sip->listen_data = purple_network_listen_range(5060, 5160, SOCK_STREAM, 1685 sip->listen_data = purple_network_listen_range(5060, 5160, SOCK_STREAM,
1681 simple_tcp_connect_listen_cb, sip); 1686 simple_tcp_connect_listen_cb, sip);
1682 if (sip->listen_data == NULL) { 1687 if (sip->listen_data == NULL) {
1683 purple_connection_error_reason(sip->gc, PURPLE_REASON_NETWORK_ERROR, 1688 purple_connection_error_reason(sip->gc,
1689 PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
1684 _("Could not create listen socket")); 1690 _("Could not create listen socket"));
1685 return; 1691 return;
1686 } 1692 }
1687 } else { /* UDP */ 1693 } else { /* UDP */
1688 purple_debug_info("simple", "using udp with server %s and port %d\n", hostname, port); 1694 purple_debug_info("simple", "using udp with server %s and port %d\n", hostname, port);
1689 1695
1690 sip->query_data = purple_dnsquery_a(hostname, port, simple_udp_host_resolved, sip); 1696 sip->query_data = purple_dnsquery_a(hostname, port, simple_udp_host_resolved, sip);
1691 if (sip->query_data == NULL) { 1697 if (sip->query_data == NULL) {
1692 purple_connection_error_reason(sip->gc, PURPLE_REASON_NETWORK_ERROR, 1698 purple_connection_error_reason(sip->gc,
1699 PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
1693 _("Could not resolve hostname")); 1700 _("Could not resolve hostname"));
1694 } 1701 }
1695 } 1702 }
1696 } 1703 }
1697 1704
1704 1711
1705 const char *username = purple_account_get_username(account); 1712 const char *username = purple_account_get_username(account);
1706 gc = purple_account_get_connection(account); 1713 gc = purple_account_get_connection(account);
1707 1714
1708 if (strpbrk(username, " \t\v\r\n") != NULL) { 1715 if (strpbrk(username, " \t\v\r\n") != NULL) {
1709 purple_connection_error_reason(gc, PURPLE_REASON_INVALID_SETTINGS, 1716 purple_connection_error_reason(gc,
1717 PURPLE_CONNECTION_ERROR_INVALID_SETTINGS,
1710 _("SIP screen names may not contain whitespaces or @ symbols")); 1718 _("SIP screen names may not contain whitespaces or @ symbols"));
1711 return; 1719 return;
1712 } 1720 }
1713 1721
1714 gc->proto_data = sip = g_new0(struct simple_account_data, 1); 1722 gc->proto_data = sip = g_new0(struct simple_account_data, 1);