summaryrefslogtreecommitdiffhomepage
path: root/src/upstream.c
diff options
context:
space:
mode:
authorGonzalo Tornaria <tornaria@math.utexas.edu>2016-12-20 21:30:43 +0000
committerrofl0r <rofl0r@users.noreply.github.com>2018-02-06 16:11:39 +0000
commit8906b0734e5c61016d9d4090507f010b2006292d (patch)
tree73eea974f5a292516e1ffd85ed44ddeae1b34764 /src/upstream.c
parent116e59e93346ddbe08f56f8c7e8bd648690c0242 (diff)
add SOCKS upstream proxy support (socks4/socks5)
original patch submitted in 2006 to debian mailing list: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=392848%29#12 this version was rebased to git and updated by Russ Dill <russ.dill@gmail.com> in 2015 (the original patch used a different config file format). as discussed in #40. commit message by @rofl0r.
Diffstat (limited to 'src/upstream.c')
-rw-r--r--src/upstream.c31
1 files changed, 22 insertions, 9 deletions
diff --git a/src/upstream.c b/src/upstream.c
index 6b25f9b..91bf457 100644
--- a/src/upstream.c
+++ b/src/upstream.c
@@ -29,10 +29,22 @@
#include "log.h"
#ifdef UPSTREAM_SUPPORT
+const char *
+proxy_type_name(proxy_type type)
+{
+ switch(type) {
+ case HTTP_TYPE: return "http";
+ case SOCKS4_TYPE: return "socks4";
+ case SOCKS5_TYPE: return "socks5";
+ default: return "unknown";
+ }
+}
+
/**
* Construct an upstream struct from input data.
*/
-static struct upstream *upstream_build (const char *host, int port, const char *domain)
+static struct upstream *upstream_build (const char *host, int port, const char *domain,
+ proxy_type type)
{
char *ptr;
struct upstream *up;
@@ -44,6 +56,7 @@ static struct upstream *upstream_build (const char *host, int port, const char *
return NULL;
}
+ up->type = type;
up->host = up->domain = NULL;
up->ip = up->mask = 0;
@@ -57,8 +70,8 @@ static struct upstream *upstream_build (const char *host, int port, const char *
up->host = safestrdup (host);
up->port = port;
- log_message (LOG_INFO, "Added upstream %s:%d for [default]",
- host, port);
+ log_message (LOG_INFO, "Added upstream %s %s:%d for [default]",
+ proxy_type_name(type), host, port);
} else if (host == NULL) {
if (!domain || domain[0] == '\0') {
log_message (LOG_WARNING,
@@ -101,8 +114,8 @@ static struct upstream *upstream_build (const char *host, int port, const char *
up->port = port;
up->domain = safestrdup (domain);
- log_message (LOG_INFO, "Added upstream %s:%d for %s",
- host, port, domain);
+ log_message (LOG_INFO, "Added upstream %s %s:%d for %s",
+ proxy_type_name(type), host, port, domain);
}
return up;
@@ -119,11 +132,11 @@ fail:
* Add an entry to the upstream list
*/
void upstream_add (const char *host, int port, const char *domain,
- struct upstream **upstream_list)
+ proxy_type type, struct upstream **upstream_list)
{
struct upstream *up;
- up = upstream_build (host, port, domain);
+ up = upstream_build (host, port, domain, type);
if (up == NULL) {
return;
}
@@ -202,8 +215,8 @@ struct upstream *upstream_get (char *host, struct upstream *up)
up = NULL;
if (up)
- log_message (LOG_INFO, "Found upstream proxy %s:%d for %s",
- up->host, up->port, host);
+ log_message (LOG_INFO, "Found upstream proxy %s %s:%d for %s",
+ proxy_type_name(up->type), up->host, up->port, host);
else
log_message (LOG_INFO, "No upstream proxy for %s", host);