diff options
author | shys <shyswork@zoho.com> | 2013-10-24 22:12:03 +0800 |
---|---|---|
committer | Andy Green <andy.green@linaro.org> | 2013-10-24 22:12:03 +0800 |
commit | b4e800e333f66bec56ad22f6e3cf1455618d4305 (patch) | |
tree | b172aff41023306d5b2003d9b4de2fbe9bb2379b /lib | |
parent | e0b3d13fbf4bd74385d96bc3aedb552780954443 (diff) | |
download | libwebsockets-b4e800e333f66bec56ad22f6e3cf1455618d4305.tar.gz |
manual proxy forcing api
add function to manually setup proxy. Useful on iOS where
getenv doesn't return proxy settings
Simplified by AG
Signed-off-by: shys <shyswork@zoho.com>
Signed-off-by: Andy Green <andy@warmcat.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libwebsockets.c | 46 | ||||
-rw-r--r-- | lib/libwebsockets.h | 3 |
2 files changed, 49 insertions, 0 deletions
diff --git a/lib/libwebsockets.c b/lib/libwebsockets.c index b0f25fe6..8e1e4fa2 100644 --- a/lib/libwebsockets.c +++ b/lib/libwebsockets.c @@ -2269,6 +2269,52 @@ bail: } /** + * libwebsocket_set_proxy() - Setups proxy to libwebsocket_context. + * @context: pointer to struct libwebsocket_context you want set proxy to + * @proxy: pointer to c string containing proxy in format address:port + * + * Returns 0 if proxy string was parsed and proxy was setup. + * Returns -1 if @proxy is NULL or has incorrect format. + * + * This is only required if your OS does not provide the http_proxy + * enviroment variable (eg, OSX) + * + * IMPORTANT! You should call this function right after creation of the + * libwebsocket_context and before call to connect. If you call this + * function after connect behavior is undefined. + * This function will override proxy settings made on libwebsocket_context + * creation with genenv() call. + */ + +LWS_VISIBLE int +libwebsocket_set_proxy(struct libwebsocket_context *context, const char *proxy) +{ + char *p; + + if (!proxy) + return -1; + + strncpy(context->http_proxy_address, proxy, + sizeof(context->http_proxy_address) - 1); + context->http_proxy_address[ + sizeof(context->http_proxy_address) - 1] = '\0'; + + p = strchr(context->http_proxy_address, ':'); + if (!p) { + lwsl_err("http_proxy needs to be ads:port\n"); + + return -1; + } + *p = '\0'; + context->http_proxy_port = atoi(p + 1); + + lwsl_notice(" Proxy %s:%u\n", context->http_proxy_address, + context->http_proxy_port); + + return 0; +} + +/** * libwebsockets_get_protocol() - Returns a protocol pointer from a websocket * connection. * @wsi: pointer to struct websocket you want to know the protocol of diff --git a/lib/libwebsockets.h b/lib/libwebsockets.h index d8e4a273..72a3769b 100644 --- a/lib/libwebsockets.h +++ b/lib/libwebsockets.h @@ -830,6 +830,9 @@ lwsl_emit_syslog(int level, const char *line); LWS_VISIBLE LWS_EXTERN struct libwebsocket_context * libwebsocket_create_context(struct lws_context_creation_info *info); + +LWS_VISIBLE LWS_EXTERN int +libwebsocket_set_proxy(struct libwebsocket_context *context, const char *proxy); LWS_VISIBLE LWS_EXTERN void libwebsocket_context_destroy(struct libwebsocket_context *context); |