Mercurial > pidgin
comparison libpurple/proxy.c @ 27590:a08e84032814
merge of '2348ff22f0ff3453774b8b25b36238465580c609'
and 'e76f11543c2a4aa05bdf584f087cbe3439029661'
author | Paul Aurich <paul@darkrain42.org> |
---|---|
date | Sun, 12 Jul 2009 05:43:38 +0000 |
parents | f541583e31bd |
children | 3712ef8bf231 |
comparison
equal
deleted
inserted
replaced
27104:048bcf41deef | 27590:a08e84032814 |
---|---|
401 if (!loaded) { | 401 if (!loaded) { |
402 loaded = TRUE; | 402 loaded = TRUE; |
403 MyWinHttpGetIEProxyConfig = (LPFNWINHTTPGETIEPROXYCONFIG) | 403 MyWinHttpGetIEProxyConfig = (LPFNWINHTTPGETIEPROXYCONFIG) |
404 wpurple_find_and_loadproc("winhttp.dll", "WinHttpGetIEProxyConfigForCurrentUser"); | 404 wpurple_find_and_loadproc("winhttp.dll", "WinHttpGetIEProxyConfigForCurrentUser"); |
405 if (!MyWinHttpGetIEProxyConfig) | 405 if (!MyWinHttpGetIEProxyConfig) |
406 purple_debug_info("proxy", "Unable to read Windows Proxy Settings.\n"); | 406 purple_debug_warning("proxy", "Unable to read Windows Proxy Settings.\n"); |
407 } | 407 } |
408 | 408 |
409 if (!MyWinHttpGetIEProxyConfig) | 409 if (!MyWinHttpGetIEProxyConfig) |
410 return NULL; | 410 return NULL; |
411 | 411 |
570 g_free(connect_data->read_buffer); | 570 g_free(connect_data->read_buffer); |
571 connect_data->read_buffer = NULL; | 571 connect_data->read_buffer = NULL; |
572 | 572 |
573 if (error_message != NULL) | 573 if (error_message != NULL) |
574 { | 574 { |
575 purple_debug_info("proxy", "Connection attempt failed: %s\n", | 575 purple_debug_error("proxy", "Connection attempt failed: %s\n", |
576 error_message); | 576 error_message); |
577 if (connect_data->hosts != NULL) | 577 if (connect_data->hosts != NULL) |
578 try_connect(connect_data); | 578 try_connect(connect_data); |
579 else | 579 else |
580 { | 580 { |
656 } | 656 } |
657 | 657 |
658 if (ret != 0 || error != 0) { | 658 if (ret != 0 || error != 0) { |
659 if (ret != 0) | 659 if (ret != 0) |
660 error = errno; | 660 error = errno; |
661 purple_debug_info("proxy", "Error connecting to %s:%d (%s).\n", | 661 purple_debug_error("proxy", "Error connecting to %s:%d (%s).\n", |
662 connect_data->host, connect_data->port, g_strerror(error)); | 662 connect_data->host, connect_data->port, g_strerror(error)); |
663 | 663 |
664 purple_proxy_connect_data_disconnect(connect_data, g_strerror(error)); | 664 purple_proxy_connect_data_disconnect(connect_data, g_strerror(error)); |
665 return; | 665 return; |
666 } | 666 } |
686 | 686 |
687 connect_data->fd = socket(addr->sa_family, SOCK_DGRAM, 0); | 687 connect_data->fd = socket(addr->sa_family, SOCK_DGRAM, 0); |
688 if (connect_data->fd < 0) | 688 if (connect_data->fd < 0) |
689 { | 689 { |
690 purple_proxy_connect_data_disconnect_formatted(connect_data, | 690 purple_proxy_connect_data_disconnect_formatted(connect_data, |
691 _("Unable to create socket:\n%s"), g_strerror(errno)); | 691 _("Unable to create socket: %s"), g_strerror(errno)); |
692 return; | 692 return; |
693 } | 693 } |
694 | 694 |
695 flags = fcntl(connect_data->fd, F_GETFL); | 695 flags = fcntl(connect_data->fd, F_GETFL); |
696 fcntl(connect_data->fd, F_SETFL, flags | O_NONBLOCK); | 696 fcntl(connect_data->fd, F_SETFL, flags | O_NONBLOCK); |
748 | 748 |
749 connect_data->fd = socket(addr->sa_family, SOCK_STREAM, 0); | 749 connect_data->fd = socket(addr->sa_family, SOCK_STREAM, 0); |
750 if (connect_data->fd < 0) | 750 if (connect_data->fd < 0) |
751 { | 751 { |
752 purple_proxy_connect_data_disconnect_formatted(connect_data, | 752 purple_proxy_connect_data_disconnect_formatted(connect_data, |
753 _("Unable to create socket:\n%s"), g_strerror(errno)); | 753 _("Unable to create socket: %s"), g_strerror(errno)); |
754 return; | 754 return; |
755 } | 755 } |
756 | 756 |
757 flags = fcntl(connect_data->fd, F_GETFL); | 757 flags = fcntl(connect_data->fd, F_GETFL); |
758 fcntl(connect_data->fd, F_SETFL, flags | O_NONBLOCK); | 758 fcntl(connect_data->fd, F_SETFL, flags | O_NONBLOCK); |
869 | 869 |
870 len = read(connect_data->fd, p, max_read); | 870 len = read(connect_data->fd, p, max_read); |
871 | 871 |
872 if (len == 0) { | 872 if (len == 0) { |
873 purple_proxy_connect_data_disconnect(connect_data, | 873 purple_proxy_connect_data_disconnect(connect_data, |
874 _("Server closed the connection.")); | 874 _("Server closed the connection")); |
875 return; | 875 return; |
876 } | 876 } |
877 | 877 |
878 if (len < 0) { | 878 if (len < 0) { |
879 if (errno == EAGAIN) | 879 if (errno == EAGAIN) |
880 /* No worries */ | 880 /* No worries */ |
881 return; | 881 return; |
882 | 882 |
883 /* Error! */ | 883 /* Error! */ |
884 purple_proxy_connect_data_disconnect_formatted(connect_data, | 884 purple_proxy_connect_data_disconnect_formatted(connect_data, |
885 _("Lost connection with server:\n%s"), g_strerror(errno)); | 885 _("Lost connection with server: %s"), g_strerror(errno)); |
886 return; | 886 return; |
887 } | 887 } |
888 | 888 |
889 connect_data->read_len += len; | 889 connect_data->read_len += len; |
890 p[len] = '\0'; | 890 p[len] = '\0'; |
943 } | 943 } |
944 } | 944 } |
945 | 945 |
946 if (error) { | 946 if (error) { |
947 purple_proxy_connect_data_disconnect_formatted(connect_data, | 947 purple_proxy_connect_data_disconnect_formatted(connect_data, |
948 _("Unable to parse response from HTTP proxy: %s\n"), | 948 _("Unable to parse response from HTTP proxy: %s"), |
949 connect_data->read_buffer); | 949 connect_data->read_buffer); |
950 return; | 950 return; |
951 } | 951 } |
952 else if (status != 200) { | 952 else if (status != 200) { |
953 purple_debug_error("proxy", | 953 purple_debug_error("proxy", |
1063 } | 1063 } |
1064 | 1064 |
1065 if (status == 403) { | 1065 if (status == 403) { |
1066 /* Forbidden */ | 1066 /* Forbidden */ |
1067 purple_proxy_connect_data_disconnect_formatted(connect_data, | 1067 purple_proxy_connect_data_disconnect_formatted(connect_data, |
1068 _("Access denied: HTTP proxy server forbids port %d tunneling."), | 1068 _("Access denied: HTTP proxy server forbids port %d tunneling"), |
1069 connect_data->port); | 1069 connect_data->port); |
1070 } else { | 1070 } else { |
1071 purple_proxy_connect_data_disconnect_formatted(connect_data, | 1071 purple_proxy_connect_data_disconnect_formatted(connect_data, |
1072 _("HTTP proxy connection error %d"), status); | 1072 _("HTTP proxy connection error %d"), status); |
1073 } | 1073 } |
1189 | 1189 |
1190 connect_data->fd = socket(addr->sa_family, SOCK_STREAM, 0); | 1190 connect_data->fd = socket(addr->sa_family, SOCK_STREAM, 0); |
1191 if (connect_data->fd < 0) | 1191 if (connect_data->fd < 0) |
1192 { | 1192 { |
1193 purple_proxy_connect_data_disconnect_formatted(connect_data, | 1193 purple_proxy_connect_data_disconnect_formatted(connect_data, |
1194 _("Unable to create socket:\n%s"), g_strerror(errno)); | 1194 _("Unable to create socket: %s"), g_strerror(errno)); |
1195 return; | 1195 return; |
1196 } | 1196 } |
1197 | 1197 |
1198 flags = fcntl(connect_data->fd, F_GETFL); | 1198 flags = fcntl(connect_data->fd, F_GETFL); |
1199 fcntl(connect_data->fd, F_SETFL, flags | O_NONBLOCK); | 1199 fcntl(connect_data->fd, F_SETFL, flags | O_NONBLOCK); |
1382 | 1382 |
1383 connect_data->fd = socket(addr->sa_family, SOCK_STREAM, 0); | 1383 connect_data->fd = socket(addr->sa_family, SOCK_STREAM, 0); |
1384 if (connect_data->fd < 0) | 1384 if (connect_data->fd < 0) |
1385 { | 1385 { |
1386 purple_proxy_connect_data_disconnect_formatted(connect_data, | 1386 purple_proxy_connect_data_disconnect_formatted(connect_data, |
1387 _("Unable to create socket:\n%s"), g_strerror(errno)); | 1387 _("Unable to create socket: %s"), g_strerror(errno)); |
1388 return; | 1388 return; |
1389 } | 1389 } |
1390 | 1390 |
1391 flags = fcntl(connect_data->fd, F_GETFL); | 1391 flags = fcntl(connect_data->fd, F_GETFL); |
1392 fcntl(connect_data->fd, F_SETFL, flags | O_NONBLOCK); | 1392 fcntl(connect_data->fd, F_SETFL, flags | O_NONBLOCK); |
1451 len = read(connect_data->fd, dest, (connect_data->read_buf_len - connect_data->read_len)); | 1451 len = read(connect_data->fd, dest, (connect_data->read_buf_len - connect_data->read_len)); |
1452 | 1452 |
1453 if (len == 0) | 1453 if (len == 0) |
1454 { | 1454 { |
1455 purple_proxy_connect_data_disconnect(connect_data, | 1455 purple_proxy_connect_data_disconnect(connect_data, |
1456 _("Server closed the connection.")); | 1456 _("Server closed the connection")); |
1457 return; | 1457 return; |
1458 } | 1458 } |
1459 | 1459 |
1460 if (len < 0) | 1460 if (len < 0) |
1461 { | 1461 { |
1463 /* No worries */ | 1463 /* No worries */ |
1464 return; | 1464 return; |
1465 | 1465 |
1466 /* Error! */ | 1466 /* Error! */ |
1467 purple_proxy_connect_data_disconnect_formatted(connect_data, | 1467 purple_proxy_connect_data_disconnect_formatted(connect_data, |
1468 _("Lost connection with server:\n%s"), g_strerror(errno)); | 1468 _("Lost connection with server: %s"), g_strerror(errno)); |
1469 return; | 1469 return; |
1470 } | 1470 } |
1471 | 1471 |
1472 connect_data->read_len += len; | 1472 connect_data->read_len += len; |
1473 | 1473 |
1480 purple_proxy_connect_data_disconnect(connect_data, | 1480 purple_proxy_connect_data_disconnect(connect_data, |
1481 socks5errors[buf[1]]); | 1481 socks5errors[buf[1]]); |
1482 } else { | 1482 } else { |
1483 purple_debug_error("socks5 proxy", "Bad data.\n"); | 1483 purple_debug_error("socks5 proxy", "Bad data.\n"); |
1484 purple_proxy_connect_data_disconnect(connect_data, | 1484 purple_proxy_connect_data_disconnect(connect_data, |
1485 _("Received invalid data on connection with server.")); | 1485 _("Received invalid data on connection with server")); |
1486 } | 1486 } |
1487 return; | 1487 return; |
1488 } | 1488 } |
1489 | 1489 |
1490 /* Skip past BND.ADDR */ | 1490 /* Skip past BND.ADDR */ |
1510 buf += 4 + 16; | 1510 buf += 4 + 16; |
1511 break; | 1511 break; |
1512 default: | 1512 default: |
1513 purple_debug_error("socks5 proxy", "Invalid ATYP received (0x%X)\n", buf[3]); | 1513 purple_debug_error("socks5 proxy", "Invalid ATYP received (0x%X)\n", buf[3]); |
1514 purple_proxy_connect_data_disconnect(connect_data, | 1514 purple_proxy_connect_data_disconnect(connect_data, |
1515 _("Received invalid data on connection with server.")); | 1515 _("Received invalid data on connection with server")); |
1516 return; | 1516 return; |
1517 } | 1517 } |
1518 | 1518 |
1519 /* Skip past BND.PORT */ | 1519 /* Skip past BND.PORT */ |
1520 if(!s5_ensure_buffer_length(connect_data, (buf - connect_data->read_buffer) + 2)) | 1520 if(!s5_ensure_buffer_length(connect_data, (buf - connect_data->read_buffer) + 2)) |
1565 connect_data->read_buf_len - connect_data->read_len); | 1565 connect_data->read_buf_len - connect_data->read_len); |
1566 | 1566 |
1567 if (len == 0) | 1567 if (len == 0) |
1568 { | 1568 { |
1569 purple_proxy_connect_data_disconnect(connect_data, | 1569 purple_proxy_connect_data_disconnect(connect_data, |
1570 _("Server closed the connection.")); | 1570 _("Server closed the connection")); |
1571 return; | 1571 return; |
1572 } | 1572 } |
1573 | 1573 |
1574 if (len < 0) | 1574 if (len < 0) |
1575 { | 1575 { |
1577 /* No worries */ | 1577 /* No worries */ |
1578 return; | 1578 return; |
1579 | 1579 |
1580 /* Error! */ | 1580 /* Error! */ |
1581 purple_proxy_connect_data_disconnect_formatted(connect_data, | 1581 purple_proxy_connect_data_disconnect_formatted(connect_data, |
1582 _("Lost connection with server:\n%s"), g_strerror(errno)); | 1582 _("Lost connection with server: %s"), g_strerror(errno)); |
1583 return; | 1583 return; |
1584 } | 1584 } |
1585 | 1585 |
1586 connect_data->read_len += len; | 1586 connect_data->read_len += len; |
1587 if (connect_data->read_len < 2) | 1587 if (connect_data->read_len < 2) |
1590 purple_input_remove(connect_data->inpa); | 1590 purple_input_remove(connect_data->inpa); |
1591 connect_data->inpa = 0; | 1591 connect_data->inpa = 0; |
1592 | 1592 |
1593 if ((connect_data->read_buffer[0] != 0x01) || (connect_data->read_buffer[1] != 0x00)) { | 1593 if ((connect_data->read_buffer[0] != 0x01) || (connect_data->read_buffer[1] != 0x00)) { |
1594 purple_proxy_connect_data_disconnect(connect_data, | 1594 purple_proxy_connect_data_disconnect(connect_data, |
1595 _("Received invalid data on connection with server.")); | 1595 _("Received invalid data on connection with server")); |
1596 return; | 1596 return; |
1597 } | 1597 } |
1598 | 1598 |
1599 g_free(connect_data->read_buffer); | 1599 g_free(connect_data->read_buffer); |
1600 connect_data->read_buffer = NULL; | 1600 connect_data->read_buffer = NULL; |
1661 | 1661 |
1662 purple_debug_misc("socks5 proxy", "Reading CHAP message: %x\n", *cmdbuf); | 1662 purple_debug_misc("socks5 proxy", "Reading CHAP message: %x\n", *cmdbuf); |
1663 | 1663 |
1664 if (*cmdbuf != 0x01) { | 1664 if (*cmdbuf != 0x01) { |
1665 purple_proxy_connect_data_disconnect(connect_data, | 1665 purple_proxy_connect_data_disconnect(connect_data, |
1666 _("Received invalid data on connection with server.")); | 1666 _("Received invalid data on connection with server")); |
1667 return -1; | 1667 return -1; |
1668 } | 1668 } |
1669 cmdbuf++; | 1669 cmdbuf++; |
1670 | 1670 |
1671 navas = *cmdbuf; | 1671 navas = *cmdbuf; |
1762 "algorithm that we did not advertise " | 1762 "algorithm that we did not advertise " |
1763 "as supporting. This is a violation " | 1763 "as supporting. This is a violation " |
1764 "of the socks5 CHAP specification. " | 1764 "of the socks5 CHAP specification. " |
1765 "Disconnecting..."); | 1765 "Disconnecting..."); |
1766 purple_proxy_connect_data_disconnect(connect_data, | 1766 purple_proxy_connect_data_disconnect(connect_data, |
1767 _("Received invalid data on connection with server.")); | 1767 _("Received invalid data on connection with server")); |
1768 return -1; | 1768 return -1; |
1769 } | 1769 } |
1770 break; | 1770 break; |
1771 default: | 1771 default: |
1772 purple_debug_info("socks5 proxy", "Received unused command %x, length=%d\n", cmdbuf[0], cmdbuf[1]); | 1772 purple_debug_info("socks5 proxy", "Received unused command %x, length=%d\n", cmdbuf[0], cmdbuf[1]); |
1801 len = read(connect_data->fd, connect_data->read_buffer + connect_data->read_len, | 1801 len = read(connect_data->fd, connect_data->read_buffer + connect_data->read_len, |
1802 connect_data->read_buf_len - connect_data->read_len); | 1802 connect_data->read_buf_len - connect_data->read_len); |
1803 | 1803 |
1804 if (len == 0) { | 1804 if (len == 0) { |
1805 purple_proxy_connect_data_disconnect(connect_data, | 1805 purple_proxy_connect_data_disconnect(connect_data, |
1806 _("Server closed the connection.")); | 1806 _("Server closed the connection")); |
1807 return; | 1807 return; |
1808 } | 1808 } |
1809 | 1809 |
1810 if (len < 0) { | 1810 if (len < 0) { |
1811 if (errno == EAGAIN) | 1811 if (errno == EAGAIN) |
1812 /* No worries */ | 1812 /* No worries */ |
1813 return; | 1813 return; |
1814 | 1814 |
1815 /* Error! */ | 1815 /* Error! */ |
1816 purple_proxy_connect_data_disconnect_formatted(connect_data, | 1816 purple_proxy_connect_data_disconnect_formatted(connect_data, |
1817 _("Lost connection with server:\n%s"), g_strerror(errno)); | 1817 _("Lost connection with server: %s"), g_strerror(errno)); |
1818 return; | 1818 return; |
1819 } | 1819 } |
1820 | 1820 |
1821 connect_data->read_len += len; | 1821 connect_data->read_len += len; |
1822 | 1822 |
1876 connect_data->read_buf_len - connect_data->read_len); | 1876 connect_data->read_buf_len - connect_data->read_len); |
1877 | 1877 |
1878 if (len == 0) | 1878 if (len == 0) |
1879 { | 1879 { |
1880 purple_proxy_connect_data_disconnect(connect_data, | 1880 purple_proxy_connect_data_disconnect(connect_data, |
1881 _("Server closed the connection.")); | 1881 _("Server closed the connection")); |
1882 return; | 1882 return; |
1883 } | 1883 } |
1884 | 1884 |
1885 if (len < 0) | 1885 if (len < 0) |
1886 { | 1886 { |
1888 /* No worries */ | 1888 /* No worries */ |
1889 return; | 1889 return; |
1890 | 1890 |
1891 /* Error! */ | 1891 /* Error! */ |
1892 purple_proxy_connect_data_disconnect_formatted(connect_data, | 1892 purple_proxy_connect_data_disconnect_formatted(connect_data, |
1893 _("Lost connection with server:\n%s"), g_strerror(errno)); | 1893 _("Lost connection with server: %s"), g_strerror(errno)); |
1894 return; | 1894 return; |
1895 } | 1895 } |
1896 | 1896 |
1897 connect_data->read_len += len; | 1897 connect_data->read_len += len; |
1898 if (connect_data->read_len < 2) | 1898 if (connect_data->read_len < 2) |
1901 purple_input_remove(connect_data->inpa); | 1901 purple_input_remove(connect_data->inpa); |
1902 connect_data->inpa = 0; | 1902 connect_data->inpa = 0; |
1903 | 1903 |
1904 if ((connect_data->read_buffer[0] != 0x05) || (connect_data->read_buffer[1] == 0xff)) { | 1904 if ((connect_data->read_buffer[0] != 0x05) || (connect_data->read_buffer[1] == 0xff)) { |
1905 purple_proxy_connect_data_disconnect(connect_data, | 1905 purple_proxy_connect_data_disconnect(connect_data, |
1906 _("Received invalid data on connection with server.")); | 1906 _("Received invalid data on connection with server")); |
1907 return; | 1907 return; |
1908 } | 1908 } |
1909 | 1909 |
1910 if (connect_data->read_buffer[1] == 0x02) { | 1910 if (connect_data->read_buffer[1] == 0x02) { |
1911 size_t i, j; | 1911 size_t i, j; |
2042 | 2042 |
2043 connect_data->fd = socket(addr->sa_family, SOCK_STREAM, 0); | 2043 connect_data->fd = socket(addr->sa_family, SOCK_STREAM, 0); |
2044 if (connect_data->fd < 0) | 2044 if (connect_data->fd < 0) |
2045 { | 2045 { |
2046 purple_proxy_connect_data_disconnect_formatted(connect_data, | 2046 purple_proxy_connect_data_disconnect_formatted(connect_data, |
2047 _("Unable to create socket:\n%s"), g_strerror(errno)); | 2047 _("Unable to create socket: %s"), g_strerror(errno)); |
2048 return; | 2048 return; |
2049 } | 2049 } |
2050 | 2050 |
2051 flags = fcntl(connect_data->fd, F_GETFL); | 2051 flags = fcntl(connect_data->fd, F_GETFL); |
2052 fcntl(connect_data->fd, F_SETFL, flags | O_NONBLOCK); | 2052 fcntl(connect_data->fd, F_SETFL, flags | O_NONBLOCK); |
2154 return; | 2154 return; |
2155 } | 2155 } |
2156 | 2156 |
2157 if (hosts == NULL) | 2157 if (hosts == NULL) |
2158 { | 2158 { |
2159 purple_proxy_connect_data_disconnect(connect_data, _("Could not resolve host name")); | 2159 purple_proxy_connect_data_disconnect(connect_data, _("Unable to resolve hostname")); |
2160 return; | 2160 return; |
2161 } | 2161 } |
2162 | 2162 |
2163 connect_data->hosts = hosts; | 2163 connect_data->hosts = hosts; |
2164 | 2164 |