Mercurial > pidgin
comparison libpurple/protocols/simple/simple.c @ 20776:f3cfcbbac3d8
propagate from branch 'im.pidgin.pidgin' (head 294731552d0baf5f1f37a45e0c119b2188f34ba8)
to branch 'im.pidgin.cpw.resiak.disconnectreason' (head 548e06334e7772c9583776ecbd80e8d2a68fcd79)
author | Will Thompson <will.thompson@collabora.co.uk> |
---|---|
date | Fri, 05 Oct 2007 15:50:17 +0000 |
parents | 5723dbc6212d 885320299776 |
children | efa448405f3d |
comparison
equal
deleted
inserted
replaced
20775:d3443cb6a60f | 20776:f3cfcbbac3d8 |
---|---|
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(gc, _("Could not write")); | 416 purple_connection_error_reason(gc, PURPLE_REASON_NETWORK_ERROR, |
417 _("Could not write")); | |
417 return; | 418 return; |
418 } | 419 } |
419 | 420 |
420 purple_circ_buffer_mark_read(sip->txbuf, written); | 421 purple_circ_buffer_mark_read(sip->txbuf, written); |
421 } | 422 } |
433 close(source); | 434 close(source); |
434 return; | 435 return; |
435 } | 436 } |
436 | 437 |
437 if(source < 0) { | 438 if(source < 0) { |
438 purple_connection_error(gc, _("Could not connect")); | 439 purple_connection_error_reason(gc, PURPLE_REASON_NETWORK_ERROR, |
440 _("Could not connect")); | |
439 return; | 441 return; |
440 } | 442 } |
441 | 443 |
442 sip = gc->proto_data; | 444 sip = gc->proto_data; |
443 sip->fd = source; | 445 sip->fd = source; |
459 struct simple_account_data *sip = gc->proto_data; | 461 struct simple_account_data *sip = gc->proto_data; |
460 | 462 |
461 if(!sip->connecting) { | 463 if(!sip->connecting) { |
462 purple_debug_info("simple", "connecting to %s port %d\n", sip->realhostname ? sip->realhostname : "{NULL}", sip->realport); | 464 purple_debug_info("simple", "connecting to %s port %d\n", sip->realhostname ? sip->realhostname : "{NULL}", sip->realport); |
463 if (purple_proxy_connect(gc, sip->account, sip->realhostname, sip->realport, send_later_cb, gc) == NULL) { | 465 if (purple_proxy_connect(gc, sip->account, sip->realhostname, sip->realport, send_later_cb, gc) == NULL) { |
464 purple_connection_error(gc, _("Couldn't create socket")); | 466 purple_connection_error_reason(gc, PURPLE_REASON_NETWORK_ERROR, _("Couldn't create socket")); |
465 } | 467 } |
466 sip->connecting = TRUE; | 468 sip->connecting = TRUE; |
467 } | 469 } |
468 | 470 |
469 if(purple_circ_buffer_get_max_read(sip->txbuf) > 0) | 471 if(purple_circ_buffer_get_max_read(sip->txbuf) > 0) |
1042 if(sip->registrar.retries > SIMPLE_REGISTER_RETRY_MAX) { | 1044 if(sip->registrar.retries > SIMPLE_REGISTER_RETRY_MAX) { |
1043 purple_debug_info("simple", "Setting wants_to_die to true.\n"); | 1045 purple_debug_info("simple", "Setting wants_to_die to true.\n"); |
1044 sip->gc->wants_to_die = TRUE; | 1046 sip->gc->wants_to_die = TRUE; |
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(sip->gc, _("Incorrect password.")); | 1049 purple_connection_error_reason(sip->gc, |
1050 PURPLE_REASON_AUTHENTICATION_FAILED, | |
1051 _("Incorrect password.")); | |
1048 return TRUE; | 1052 return TRUE; |
1049 } | 1053 } |
1050 tmp = sipmsg_find_header(msg, "WWW-Authenticate"); | 1054 tmp = sipmsg_find_header(msg, "WWW-Authenticate"); |
1051 fill_auth(sip, tmp, &sip->registrar); | 1055 fill_auth(sip, tmp, &sip->registrar); |
1052 sip->registerstatus = SIMPLE_REGISTER_RETRY; | 1056 sip->registerstatus = SIMPLE_REGISTER_RETRY; |
1056 default: | 1060 default: |
1057 if (sip->registerstatus != SIMPLE_REGISTER_RETRY) { | 1061 if (sip->registerstatus != SIMPLE_REGISTER_RETRY) { |
1058 purple_debug_info("simple", "Unrecognized return code for REGISTER.\n"); | 1062 purple_debug_info("simple", "Unrecognized return code for REGISTER.\n"); |
1059 if (sip->registrar.retries > SIMPLE_REGISTER_RETRY_MAX) { | 1063 if (sip->registrar.retries > SIMPLE_REGISTER_RETRY_MAX) { |
1060 sip->gc->wants_to_die = TRUE; | 1064 sip->gc->wants_to_die = TRUE; |
1061 purple_connection_error(sip->gc, _("Unknown server response.")); | 1065 purple_connection_error_reason(sip->gc, PURPLE_REASON_OTHER_ERROR, |
1066 _("Unknown server response.")); | |
1062 return TRUE; | 1067 return TRUE; |
1063 } | 1068 } |
1064 sip->registerstatus = SIMPLE_REGISTER_RETRY; | 1069 sip->registerstatus = SIMPLE_REGISTER_RETRY; |
1065 do_register(sip); | 1070 do_register(sip); |
1066 } | 1071 } |
1526 close(source); | 1531 close(source); |
1527 return; | 1532 return; |
1528 } | 1533 } |
1529 | 1534 |
1530 if(source < 0) { | 1535 if(source < 0) { |
1531 purple_connection_error(gc, _("Could not connect")); | 1536 purple_connection_error_reason(gc, PURPLE_REASON_NETWORK_ERROR, |
1537 _("Could not connect")); | |
1532 return; | 1538 return; |
1533 } | 1539 } |
1534 | 1540 |
1535 sip = gc->proto_data; | 1541 sip = gc->proto_data; |
1536 sip->fd = source; | 1542 sip->fd = source; |
1560 struct simple_account_data *sip = (struct simple_account_data*) data; | 1566 struct simple_account_data *sip = (struct simple_account_data*) data; |
1561 | 1567 |
1562 sip->listen_data = NULL; | 1568 sip->listen_data = NULL; |
1563 | 1569 |
1564 if(listenfd == -1) { | 1570 if(listenfd == -1) { |
1565 purple_connection_error(sip->gc, _("Could not create listen socket")); | 1571 purple_connection_error_reason(sip->gc, PURPLE_REASON_NETWORK_ERROR, |
1572 _("Could not create listen socket")); | |
1566 return; | 1573 return; |
1567 } | 1574 } |
1568 | 1575 |
1569 sip->fd = listenfd; | 1576 sip->fd = listenfd; |
1570 | 1577 |
1583 int addr_size; | 1590 int addr_size; |
1584 | 1591 |
1585 sip->query_data = NULL; | 1592 sip->query_data = NULL; |
1586 | 1593 |
1587 if (!hosts || !hosts->data) { | 1594 if (!hosts || !hosts->data) { |
1588 purple_connection_error(sip->gc, _("Couldn't resolve host")); | 1595 purple_connection_error_reason(sip->gc, |
1596 PURPLE_REASON_NETWORK_ERROR, | |
1597 _("Couldn't resolve host")); | |
1589 return; | 1598 return; |
1590 } | 1599 } |
1591 | 1600 |
1592 addr_size = GPOINTER_TO_INT(hosts->data); | 1601 addr_size = GPOINTER_TO_INT(hosts->data); |
1593 hosts = g_slist_remove(hosts, hosts->data); | 1602 hosts = g_slist_remove(hosts, hosts->data); |
1602 | 1611 |
1603 /* create socket for incoming connections */ | 1612 /* create socket for incoming connections */ |
1604 sip->listen_data = purple_network_listen_range(5060, 5160, SOCK_DGRAM, | 1613 sip->listen_data = purple_network_listen_range(5060, 5160, SOCK_DGRAM, |
1605 simple_udp_host_resolved_listen_cb, sip); | 1614 simple_udp_host_resolved_listen_cb, sip); |
1606 if (sip->listen_data == NULL) { | 1615 if (sip->listen_data == NULL) { |
1607 purple_connection_error(sip->gc, _("Could not create listen socket")); | 1616 purple_connection_error_reason(sip->gc, |
1617 PURPLE_REASON_NETWORK_ERROR, | |
1618 _("Could not create listen socket")); | |
1608 return; | 1619 return; |
1609 } | 1620 } |
1610 } | 1621 } |
1611 | 1622 |
1612 static void | 1623 static void |
1615 | 1626 |
1616 sip->listen_data = NULL; | 1627 sip->listen_data = NULL; |
1617 | 1628 |
1618 sip->listenfd = listenfd; | 1629 sip->listenfd = listenfd; |
1619 if(sip->listenfd == -1) { | 1630 if(sip->listenfd == -1) { |
1620 purple_connection_error(sip->gc, _("Could not create listen socket")); | 1631 purple_connection_error_reason(sip->gc, |
1632 PURPLE_REASON_NETWORK_ERROR, | |
1633 _("Could not create listen socket")); | |
1621 return; | 1634 return; |
1622 } | 1635 } |
1623 | 1636 |
1624 purple_debug_info("simple", "listenfd: %d\n", sip->listenfd); | 1637 purple_debug_info("simple", "listenfd: %d\n", sip->listenfd); |
1625 sip->listenport = purple_network_get_port_from_fd(sip->listenfd); | 1638 sip->listenport = purple_network_get_port_from_fd(sip->listenfd); |
1628 purple_debug_info("simple", "connecting to %s port %d\n", | 1641 purple_debug_info("simple", "connecting to %s port %d\n", |
1629 sip->realhostname, sip->realport); | 1642 sip->realhostname, sip->realport); |
1630 /* open tcp connection to the server */ | 1643 /* open tcp connection to the server */ |
1631 if (purple_proxy_connect(sip->gc, sip->account, sip->realhostname, | 1644 if (purple_proxy_connect(sip->gc, sip->account, sip->realhostname, |
1632 sip->realport, login_cb, sip->gc) == NULL) { | 1645 sip->realport, login_cb, sip->gc) == NULL) { |
1633 purple_connection_error(sip->gc, _("Couldn't create socket")); | 1646 purple_connection_error_reason(sip->gc, |
1647 PURPLE_REASON_NETWORK_ERROR, | |
1648 _("Couldn't create socket")); | |
1634 } | 1649 } |
1635 } | 1650 } |
1636 | 1651 |
1637 static void srvresolved(PurpleSrvResponse *resp, int results, gpointer data) { | 1652 static void srvresolved(PurpleSrvResponse *resp, int results, gpointer data) { |
1638 struct simple_account_data *sip; | 1653 struct simple_account_data *sip; |
1666 if(!sip->udp) { | 1681 if(!sip->udp) { |
1667 /* create socket for incoming connections */ | 1682 /* create socket for incoming connections */ |
1668 sip->listen_data = purple_network_listen_range(5060, 5160, SOCK_STREAM, | 1683 sip->listen_data = purple_network_listen_range(5060, 5160, SOCK_STREAM, |
1669 simple_tcp_connect_listen_cb, sip); | 1684 simple_tcp_connect_listen_cb, sip); |
1670 if (sip->listen_data == NULL) { | 1685 if (sip->listen_data == NULL) { |
1671 purple_connection_error(sip->gc, _("Could not create listen socket")); | 1686 purple_connection_error_reason(sip->gc, PURPLE_REASON_NETWORK_ERROR, |
1687 _("Could not create listen socket")); | |
1672 return; | 1688 return; |
1673 } | 1689 } |
1674 } else { /* UDP */ | 1690 } else { /* UDP */ |
1675 purple_debug_info("simple", "using udp with server %s and port %d\n", hostname, port); | 1691 purple_debug_info("simple", "using udp with server %s and port %d\n", hostname, port); |
1676 | 1692 |
1677 sip->query_data = purple_dnsquery_a(hostname, port, simple_udp_host_resolved, sip); | 1693 sip->query_data = purple_dnsquery_a(hostname, port, simple_udp_host_resolved, sip); |
1678 if (sip->query_data == NULL) { | 1694 if (sip->query_data == NULL) { |
1679 purple_connection_error(sip->gc, _("Could not resolve hostname")); | 1695 purple_connection_error_reason(sip->gc, PURPLE_REASON_NETWORK_ERROR, |
1696 _("Could not resolve hostname")); | |
1680 } | 1697 } |
1681 } | 1698 } |
1682 } | 1699 } |
1683 | 1700 |
1684 static void simple_login(PurpleAccount *account) | 1701 static void simple_login(PurpleAccount *account) |
1691 const char *username = purple_account_get_username(account); | 1708 const char *username = purple_account_get_username(account); |
1692 gc = purple_account_get_connection(account); | 1709 gc = purple_account_get_connection(account); |
1693 | 1710 |
1694 if (strpbrk(username, " \t\v\r\n") != NULL) { | 1711 if (strpbrk(username, " \t\v\r\n") != NULL) { |
1695 gc->wants_to_die = TRUE; | 1712 gc->wants_to_die = TRUE; |
1696 purple_connection_error(gc, _("SIP screen names may not contain whitespaces or @ symbols")); | 1713 purple_connection_error_reason(gc, PURPLE_REASON_INVALID_SETTINGS, |
1714 _("SIP screen names may not contain whitespaces or @ symbols")); | |
1697 return; | 1715 return; |
1698 } | 1716 } |
1699 | 1717 |
1700 gc->proto_data = sip = g_new0(struct simple_account_data, 1); | 1718 gc->proto_data = sip = g_new0(struct simple_account_data, 1); |
1701 sip->gc = gc; | 1719 sip->gc = gc; |