Mercurial > pidgin
comparison src/proxy.c @ 6621:42fdf16f1dad
[gaim-migrate @ 7145]
Individual accounts remember the "No Proxy" setting instead of reverting
back to "Use Global Proxy Settings"
Proxy settings for individual accounts do not revert to "No Proxy" if
you open an account, don't change the proxy drop down, then save the
account.
Those two sound like the same thing, but they're different. I think.
Added the "use environmental variables" setting in a way that isn't
horrible.
We're not using that thing that splits the proxy variable into
host:port yet. I'll do that later. I would have done that
earlier, but I had to go buy a bike.
Also, I'd like to show what the environmental variables are set to
somewhere. That'll come later.
Also a patch from Robot101:
(22:10:25) Bzubhipheron: I have a patch that replaces #define WFLAG_* with
GaimMessageFlags GAIM_MESSAGE_*
(22:10:30) Bzubhipheron: (an enum in disguise)
(22:14:18) Bzubhipheron: GaimMessageFlags protrays much better typing
information than "int". most of the other #defines are gone, and glib
standardises on enums for its flags too.
(22:14:27) Bzubhipheron: (gone or going)
(22:14:45) Bzubhipheron: and it makes the prototype of my message queueing stuff prettier.
committer: Tailor Script <tailor@pidgin.im>
| author | Mark Doliner <mark@kingant.net> |
|---|---|
| date | Mon, 25 Aug 2003 02:49:42 +0000 |
| parents | ef9065e52582 |
| children | a14200b24371 |
comparison
equal
deleted
inserted
replaced
| 6620:7230e5920911 | 6621:42fdf16f1dad |
|---|---|
| 27 /* it is intended to : 1st handle http proxy, using the CONNECT command | 27 /* it is intended to : 1st handle http proxy, using the CONNECT command |
| 28 , 2nd provide an easy way to add socks support */ | 28 , 2nd provide an easy way to add socks support */ |
| 29 | 29 |
| 30 #include "internal.h" | 30 #include "internal.h" |
| 31 #include "debug.h" | 31 #include "debug.h" |
| 32 #include "notify.h" | |
| 32 #include "prefs.h" | 33 #include "prefs.h" |
| 33 #include "proxy.h" | 34 #include "proxy.h" |
| 34 #include "util.h" | 35 #include "util.h" |
| 35 | 36 |
| 36 #define GAIM_READ_COND (G_IO_IN | G_IO_HUP | G_IO_ERR) | 37 #define GAIM_READ_COND (G_IO_IN | G_IO_HUP | G_IO_ERR) |
| 37 #define GAIM_WRITE_COND (G_IO_OUT | G_IO_HUP | G_IO_ERR | G_IO_NVAL) | 38 #define GAIM_WRITE_COND (G_IO_OUT | G_IO_HUP | G_IO_ERR | G_IO_NVAL) |
| 38 | 39 |
| 39 static GaimProxyInfo *global_proxy_info = NULL; | 40 static GaimProxyInfo *global_proxy_info = NULL; |
| 40 static gboolean global_proxy_info_from_prefs = FALSE; | |
| 41 | 41 |
| 42 static int opt_debug = 0; | 42 static int opt_debug = 0; |
| 43 | 43 |
| 44 struct PHB { | 44 struct PHB { |
| 45 GaimInputFunction func; | 45 GaimInputFunction func; |
| 169 } | 169 } |
| 170 | 170 |
| 171 /************************************************************************** | 171 /************************************************************************** |
| 172 * Global Proxy API | 172 * Global Proxy API |
| 173 **************************************************************************/ | 173 **************************************************************************/ |
| 174 void | |
| 175 gaim_global_proxy_set_from_prefs(gboolean from_prefs) | |
| 176 { | |
| 177 global_proxy_info_from_prefs = from_prefs; | |
| 178 } | |
| 179 | |
| 180 GaimProxyInfo * | 174 GaimProxyInfo * |
| 181 gaim_global_proxy_get_info(void) | 175 gaim_global_proxy_get_info(void) |
| 182 { | 176 { |
| 183 return global_proxy_info; | 177 return global_proxy_info; |
| 184 } | 178 } |
| 185 | 179 |
| 186 gboolean | |
| 187 gaim_global_proxy_is_from_prefs(void) | |
| 188 { | |
| 189 return global_proxy_info_from_prefs; | |
| 190 } | |
| 191 | |
| 192 /************************************************************************** | 180 /************************************************************************** |
| 193 * Proxy API | 181 * Proxy API |
| 194 **************************************************************************/ | 182 **************************************************************************/ |
| 195 static void gaim_io_destroy(gpointer data) | 183 static void gaim_io_destroy(gpointer data) |
| 196 { | 184 { |
| 842 } | 830 } |
| 843 | 831 |
| 844 #define HTTP_GOODSTRING "HTTP/1.0 200" | 832 #define HTTP_GOODSTRING "HTTP/1.0 200" |
| 845 #define HTTP_GOODSTRING2 "HTTP/1.1 200" | 833 #define HTTP_GOODSTRING2 "HTTP/1.1 200" |
| 846 | 834 |
| 835 #if 0 | |
| 836 /* QQQ */ | |
| 837 static void | |
| 838 http_uri_get_host(const char *uri) | |
| 839 { | |
| 840 GaimProxyInfo *info; | |
| 841 | |
| 842 char *c, *d; | |
| 843 char buffer[2048]; | |
| 844 | |
| 845 char host[128]; | |
| 846 char user[128]; | |
| 847 char pass[128]; | |
| 848 int port = 0; | |
| 849 int len = 0; | |
| 850 | |
| 851 host[0] = '\0'; | |
| 852 user[0] = '\0'; | |
| 853 pass[0] = '\0'; | |
| 854 | |
| 855 gaim_debug(GAIM_DEBUG_MISC, "gaimrc", | |
| 856 "gaimrc_parse_proxy_uri(%s)\n", proxy); | |
| 857 | |
| 858 if ((c = strchr(proxy, ':')) == NULL) | |
| 859 { | |
| 860 gaim_debug(GAIM_DEBUG_ERROR, "gaimrc", | |
| 861 "No URI detected.\n"); | |
| 862 /* No URI detected. */ | |
| 863 return FALSE; | |
| 864 } | |
| 865 | |
| 866 len = c - proxy; | |
| 867 | |
| 868 if (strncmp(proxy, "http://", len + 3)) | |
| 869 return FALSE; | |
| 870 | |
| 871 gaim_debug(GAIM_DEBUG_MISC, "gaimrc", "Found HTTP proxy.\n"); | |
| 872 /* Get past "://" */ | |
| 873 c += 3; | |
| 874 | |
| 875 gaim_debug(GAIM_DEBUG_MISC, "gaimrc", "Looking at %s\n", c); | |
| 876 | |
| 877 for (;;) | |
| 878 { | |
| 879 *buffer = '\0'; | |
| 880 d = buffer; | |
| 881 | |
| 882 while (*c != '\0' && *c != '@' && *c != ':' && *c != '/') | |
| 883 *d++ = *c++; | |
| 884 | |
| 885 *d = '\0'; | |
| 886 | |
| 887 if (*c == ':') | |
| 888 { | |
| 889 /* | |
| 890 * If there is a '@' in there somewhere, we are in the auth part. | |
| 891 * If not, host. | |
| 892 */ | |
| 893 if (strchr(c, '@') != NULL) | |
| 894 strcpy(user, buffer); | |
| 895 else | |
| 896 strcpy(host, buffer); | |
| 897 } | |
| 898 else if (*c == '@') | |
| 899 { | |
| 900 if (user[0] == '\0') | |
| 901 strcpy(user, buffer); | |
| 902 else | |
| 903 strcpy(pass, buffer); | |
| 904 } | |
| 905 else if (*c == '/' || *c == '\0') | |
| 906 { | |
| 907 if (host[0] == '\0') | |
| 908 strcpy(host, buffer); | |
| 909 else | |
| 910 port = atoi(buffer); | |
| 911 | |
| 912 /* Done. */ | |
| 913 break; | |
| 914 } | |
| 915 | |
| 916 c++; | |
| 917 } | |
| 918 | |
| 919 /* NOTE: HTTP_PROXY takes precendence. */ | |
| 920 info = gaim_global_proxy_get_info(); | |
| 921 | |
| 922 if (*host) gaim_proxy_info_set_host(info, host); | |
| 923 if (*user) gaim_proxy_info_set_username(info, user); | |
| 924 if (*pass) gaim_proxy_info_set_password(info, pass); | |
| 925 | |
| 926 gaim_proxy_info_set_port(info, port); | |
| 927 | |
| 928 gaim_debug(GAIM_DEBUG_MISC, "gaimrc", | |
| 929 "Host: '%s', User: '%s', Password: '%s', Port: %d\n", | |
| 930 gaim_proxy_info_get_host(info), | |
| 931 gaim_proxy_info_get_username(info), | |
| 932 gaim_proxy_info_get_password(info), | |
| 933 gaim_proxy_info_get_port(info)); | |
| 934 | |
| 935 return TRUE; | |
| 936 } | |
| 937 #endif | |
| 938 | |
| 847 static void | 939 static void |
| 848 http_canread(gpointer data, gint source, GaimInputCondition cond) | 940 http_canread(gpointer data, gint source, GaimInputCondition cond) |
| 849 { | 941 { |
| 850 int nlc = 0; | 942 int nlc = 0; |
| 851 int pos = 0; | 943 int pos = 0; |
| 1503 | 1595 |
| 1504 case GAIM_PROXY_SOCKS5: | 1596 case GAIM_PROXY_SOCKS5: |
| 1505 ret = proxy_connect_socks5(phb, addr, addrlen); | 1597 ret = proxy_connect_socks5(phb, addr, addrlen); |
| 1506 break; | 1598 break; |
| 1507 | 1599 |
| 1600 case GAIM_PROXY_USE_ENVVAR: | |
| 1601 ret = proxy_connect_http(phb, addr, addrlen); | |
| 1602 break; | |
| 1603 | |
| 1508 default: | 1604 default: |
| 1509 break; | 1605 break; |
| 1510 } | 1606 } |
| 1511 | 1607 |
| 1512 if (ret > 0) | 1608 if (ret > 0) |
| 1530 GaimInputFunction func, gpointer data) | 1626 GaimInputFunction func, gpointer data) |
| 1531 { | 1627 { |
| 1532 const char *connecthost = host; | 1628 const char *connecthost = host; |
| 1533 int connectport = port; | 1629 int connectport = port; |
| 1534 struct PHB *phb; | 1630 struct PHB *phb; |
| 1631 const gchar *tmp; | |
| 1535 | 1632 |
| 1536 g_return_val_if_fail(host != NULL, -1); | 1633 g_return_val_if_fail(host != NULL, -1); |
| 1537 g_return_val_if_fail(port != 0 && port != -1, -1); | 1634 g_return_val_if_fail(port != 0 && port != -1, -1); |
| 1538 g_return_val_if_fail(func != NULL, -1); | 1635 g_return_val_if_fail(func != NULL, -1); |
| 1539 | 1636 |
| 1548 phb->data = data; | 1645 phb->data = data; |
| 1549 phb->host = g_strdup(host); | 1646 phb->host = g_strdup(host); |
| 1550 phb->port = port; | 1647 phb->port = port; |
| 1551 phb->account = account; | 1648 phb->account = account; |
| 1552 | 1649 |
| 1650 if (gaim_proxy_info_get_type(phb->gpi) == GAIM_PROXY_USE_ENVVAR) { | |
| 1651 if ((tmp = g_getenv("HTTP_PROXY")) != NULL || | |
| 1652 (tmp = g_getenv("http_proxy")) != NULL || | |
| 1653 (tmp= g_getenv("HTTPPROXY")) != NULL) { | |
| 1654 connecthost = tmp; | |
| 1655 gaim_proxy_info_set_host(phb->gpi, connecthost); | |
| 1656 } | |
| 1657 | |
| 1658 if ((tmp = g_getenv("HTTP_PROXY_PORT")) != NULL || | |
| 1659 (tmp = g_getenv("http_proxy_port")) != NULL || | |
| 1660 (tmp = g_getenv("HTTPPROXYPORT")) != NULL) { | |
| 1661 connectport = atoi(tmp); | |
| 1662 gaim_proxy_info_set_port(phb->gpi, connectport); | |
| 1663 } | |
| 1664 | |
| 1665 if ((tmp = g_getenv("HTTP_PROXY_USER")) != NULL || | |
| 1666 (tmp = g_getenv("http_proxy_user")) != NULL || | |
| 1667 (tmp = g_getenv("HTTPPROXYUSER")) != NULL) | |
| 1668 gaim_proxy_info_set_username(phb->gpi, tmp); | |
| 1669 | |
| 1670 if ((tmp = g_getenv("HTTP_PROXY_PASS")) != NULL || | |
| 1671 (tmp = g_getenv("http_proxy_pass")) != NULL || | |
| 1672 (tmp = g_getenv("HTTPPROXYPASS")) != NULL) | |
| 1673 gaim_proxy_info_set_password(phb->gpi, tmp); | |
| 1674 } | |
| 1675 | |
| 1553 if ((gaim_proxy_info_get_type(phb->gpi) != GAIM_PROXY_NONE) && | 1676 if ((gaim_proxy_info_get_type(phb->gpi) != GAIM_PROXY_NONE) && |
| 1554 (gaim_proxy_info_get_host(phb->gpi) == NULL || | 1677 (gaim_proxy_info_get_host(phb->gpi) == NULL || |
| 1555 gaim_proxy_info_get_port(phb->gpi) == 0 || | 1678 gaim_proxy_info_get_port(phb->gpi) <= 0)) { |
| 1556 gaim_proxy_info_get_port(phb->gpi) == -1)) { | 1679 |
| 1557 | 1680 gaim_notify_error(NULL, NULL, _("Invalid proxy settings"), _("Either the host name or port number specified for your given proxy type is invalid.")); |
| 1558 gaim_proxy_info_set_type(phb->gpi, GAIM_PROXY_NONE); | 1681 g_free(phb->host); |
| 1682 g_free(phb); | |
| 1683 return -1; | |
| 1559 } | 1684 } |
| 1560 | 1685 |
| 1561 switch (gaim_proxy_info_get_type(phb->gpi)) | 1686 switch (gaim_proxy_info_get_type(phb->gpi)) |
| 1562 { | 1687 { |
| 1563 case GAIM_PROXY_NONE: | 1688 case GAIM_PROXY_NONE: |
| 1564 break; | 1689 break; |
| 1565 | 1690 |
| 1566 case GAIM_PROXY_HTTP: | 1691 case GAIM_PROXY_HTTP: |
| 1567 case GAIM_PROXY_SOCKS4: | 1692 case GAIM_PROXY_SOCKS4: |
| 1568 case GAIM_PROXY_SOCKS5: | 1693 case GAIM_PROXY_SOCKS5: |
| 1694 case GAIM_PROXY_USE_ENVVAR: | |
| 1569 connecthost = gaim_proxy_info_get_host(phb->gpi); | 1695 connecthost = gaim_proxy_info_get_host(phb->gpi); |
| 1570 connectport = gaim_proxy_info_get_port(phb->gpi); | 1696 connectport = gaim_proxy_info_get_port(phb->gpi); |
| 1571 break; | 1697 break; |
| 1572 | 1698 |
| 1573 default: | 1699 default: |
| 1597 proxytype = GAIM_PROXY_HTTP; | 1723 proxytype = GAIM_PROXY_HTTP; |
| 1598 else if (!strcmp(type, "socks4")) | 1724 else if (!strcmp(type, "socks4")) |
| 1599 proxytype = GAIM_PROXY_SOCKS4; | 1725 proxytype = GAIM_PROXY_SOCKS4; |
| 1600 else if (!strcmp(type, "socks5")) | 1726 else if (!strcmp(type, "socks5")) |
| 1601 proxytype = GAIM_PROXY_SOCKS5; | 1727 proxytype = GAIM_PROXY_SOCKS5; |
| 1728 else if (!strcmp(type, "envvar")) | |
| 1729 proxytype = GAIM_PROXY_USE_ENVVAR; | |
| 1602 else | 1730 else |
| 1603 proxytype = -1; | 1731 proxytype = -1; |
| 1604 | 1732 |
| 1605 gaim_proxy_info_set_type(info, proxytype); | 1733 gaim_proxy_info_set_type(info, proxytype); |
| 1606 } else if (!strcmp(name, "/core/proxy/host")) | 1734 } else if (!strcmp(name, "/core/proxy/host")) |
