Project homepage Mailing List  Warmcat.com  API Docs  Github Mirror 
{"schema":"libjg2-1", "vpath":"/git/", "avatar":"/git/avatar/", "alang":"", "gen_ut":1750653498, "reponame":"libwebsockets", "desc":"libwebsockets lightweight C networking library", "owner": { "name": "Andy Green", "email": "andy@warmcat.com", "md5": "c50933ca2aa61e0fe2c43d46bb6b59cb" },"url":"https://libwebsockets.org/repo/libwebsockets", "f":3, "items": [ {"schema":"libjg2-1", "cid":"4ef65312dcedbfb50cad0b15dee5824f", "commit": {"type":"commit", "time": 1446948901, "time_ofs": 480, "oid_tree": { "oid": "8d098f2ede40deaeb24946ebb5a0c46dba9746ae", "alias": []}, "oid":{ "oid": "6e405565f52895bf5ec214a1236a8f6a430e3bdb", "alias": []}, "msg": "proxy auth", "sig_commit": { "git_time": { "time": 1446948901, "offset": 480 }, "name": "Andy Green", "email": "andy.green@linaro.org", "md5": "4863edaebb4491aa6049a4d2d9c98c2c" }, "sig_author": { "git_time": { "time": 1446948901, "offset": 480 }, "name": "Andy Green", "email": "andy.green@linaro.org", "md5": "4863edaebb4491aa6049a4d2d9c98c2c" }}, "body": "proxy auth\n\nSimplifies proxy code to use the existing libwebsocket_set_proxy.\n\nEnables libwebsocket_set_proxy() to parse username:password@ at front of\nservername in both http_proxy and info-\u003ehttp_proxy_address.\n\nIf given the base64 version of the credentials are sent in the CONNECT\nheader to the proxy.\n\nPort is now taken from info-\u003ehttp_proxy_address server:port syntax, but if\na port is given in the now deprecated info-\u003ehttp_proxy_port (ie, is nonzero)\nthen it is allowed to be missed out and the info port used instead for\nbackwards compatibility.\n\nSigned-off-by: Andy Green \u003candy.green@linaro.org\u003e" , "diff": "diff --git a/lib/client-handshake.c b/lib/client-handshake.c\nindex f8fd6de..cd93a0b 100644\n--- a/lib/client-handshake.c\n+++ b/lib/client-handshake.c\n@@ -27,11 +27,18 @@ struct libwebsocket *libwebsocket_client_connect_2(\n \tif (context-\u003ehttp_proxy_port) {\n \t\tplen \u003d sprintf((char *)context-\u003eservice_buffer,\n \t\t\t\u0022CONNECT %s:%u HTTP/1.0\u005cx0d\u005cx0a\u0022\n-\t\t\t\u0022User-agent: libwebsockets\u005cx0d\u005cx0a\u0022\n-/*Proxy-authorization: basic aGVsbG86d29ybGQ\u003d */\n-\t\t\t\u0022\u005cx0d\u005cx0a\u0022,\n+\t\t\t\u0022User-agent: libwebsockets\u005cx0d\u005cx0a\u0022,\n \t\t\tlws_hdr_simple_ptr(wsi, _WSI_TOKEN_CLIENT_PEER_ADDRESS),\n \t\t\twsi-\u003eu.hdr.ah-\u003ec_port);\n+\n+\t\tif (context-\u003eproxy_basic_auth_token)\n+\t\t\tplen +\u003d sprintf((char *)context-\u003eservice_buffer + plen,\n+\t\t\t\t\t\u0022Proxy-authorization: basic %s\u005cx0d\u005cx0a\u0022,\n+\t\t\t\t\tcontext-\u003eproxy_basic_auth_token);\n+\n+\t\tplen +\u003d sprintf((char *)context-\u003eservice_buffer + plen,\n+\t\t\t\t\u0022\u005cx0d\u005cx0a\u0022);\n+\n \t\tads \u003d context-\u003ehttp_proxy_address;\n \n #ifdef LWS_USE_IPV6\n@@ -54,7 +61,7 @@ struct libwebsocket *libwebsocket_client_connect_2(\n \t/*\n \t * prepare the actual connection (to the proxy, if any)\n \t */\n- lwsl_client(\u0022libwebsocket_client_connect_2: address %s\u005cn\u0022, ads);\n+ lwsl_client(\u0022%s: address %s\u005cn\u0022, __func__, ads);\n \n #ifdef LWS_USE_IPV6\n \tif (LWS_IPV6_ENABLED(context)) {\ndiff --git a/lib/context.c b/lib/context.c\nindex 385561d..98c9ea2 100644\n--- a/lib/context.c\n+++ b/lib/context.c\n@@ -176,39 +176,21 @@ libwebsocket_create_context(struct lws_context_creation_info *info)\n \n \tlws_server_get_canonical_hostname(context, info);\n \n-\t/* split the proxy ads:port if given */\n+\t/* either use proxy from info, or try get it from env var */\n \n \tif (info-\u003ehttp_proxy_address) {\n-\t\tstrncpy(context-\u003ehttp_proxy_address, info-\u003ehttp_proxy_address,\n-\t\t\t\t sizeof(context-\u003ehttp_proxy_address) - 1);\n-\t\tcontext-\u003ehttp_proxy_address[\n-\t\t\t\tsizeof(context-\u003ehttp_proxy_address) - 1] \u003d '\u005c0';\n-\t\tcontext-\u003ehttp_proxy_port \u003d info-\u003ehttp_proxy_port;\n+\t\t/* override for backwards compatibility */\n+\t\tif (info-\u003ehttp_proxy_port)\n+\t\t\tcontext-\u003ehttp_proxy_port \u003d info-\u003ehttp_proxy_port;\n+\t\tlibwebsocket_set_proxy(context, info-\u003ehttp_proxy_address);\n \t} else {\n #ifdef LWS_HAVE_GETENV\n \t\tp \u003d getenv(\u0022http_proxy\u0022);\n-\t\tif (p) {\n-\t\t\tstrncpy(context-\u003ehttp_proxy_address, p,\n-\t\t\t\t sizeof(context-\u003ehttp_proxy_address) - 1);\n-\t\t\tcontext-\u003ehttp_proxy_address[\n-\t\t\t\tsizeof(context-\u003ehttp_proxy_address) - 1] \u003d '\u005c0';\n-\n-\t\t\tp \u003d strchr(context-\u003ehttp_proxy_address, ':');\n-\t\t\tif (p \u003d\u003d NULL) {\n-\t\t\t\tlwsl_err(\u0022http_proxy needs to be ads:port\u005cn\u0022);\n-\t\t\t\tgoto bail;\n-\t\t\t}\n-\t\t\t*p \u003d '\u005c0';\n-\t\t\tcontext-\u003ehttp_proxy_port \u003d atoi(p + 1);\n-\t\t}\n+\t\tif (p)\n+\t\t\tlibwebsocket_set_proxy(context, p);\n #endif\n \t}\n \n-\tif (context-\u003ehttp_proxy_address[0])\n-\t\tlwsl_notice(\u0022 Proxy %s:%u\u005cn\u0022,\n-\t\t\t\tcontext-\u003ehttp_proxy_address,\n-\t\t\t\t\t\t context-\u003ehttp_proxy_port);\n-\n \tlwsl_notice(\n \t\t\u0022 per-conn mem: %u + %u headers + protocol rx buf\u005cn\u0022,\n \t\t\t\tsizeof(struct libwebsocket),\ndiff --git a/lib/libwebsockets.c b/lib/libwebsockets.c\nindex e680481..d1ab619 100644\n--- a/lib/libwebsockets.c\n+++ b/lib/libwebsockets.c\n@@ -672,28 +672,54 @@ LWS_VISIBLE int\n libwebsocket_set_proxy(struct libwebsocket_context *context, const char *proxy)\n {\n \tchar *p;\n+\tchar authstring[96];\n \t\n \tif (!proxy)\n \t\treturn -1;\n \n+\tp \u003d strchr(proxy, '@');\n+\tif (p) { /* auth is around */\n+\n+\t\tif ((p - proxy) \u003e sizeof(authstring) - 1)\n+\t\t\tgoto auth_too_long;\n+\n+\t\tstrncpy(authstring + 6, proxy, p - proxy);\n+\t\t// null termination not needed on input\n+\t\tif (lws_b64_encode_string(authstring, (p - proxy),\n+\t\t context-\u003eproxy_basic_auth_token,\n+\t\t sizeof context-\u003eproxy_basic_auth_token) \u003c 0)\n+\t\t\tgoto auth_too_long;\n+\n+\t\tlwsl_notice(\u0022 Proxy auth in use\u005cn\u0022);\n+\t\t\t\n+\t\tproxy \u003d p + 1;\n+\t} else\n+\t\tcontext-\u003eproxy_basic_auth_token[0] \u003d '\u005c0';\n+\n \tstrncpy(context-\u003ehttp_proxy_address, proxy,\n \t\t\t\tsizeof(context-\u003ehttp_proxy_address) - 1);\n \tcontext-\u003ehttp_proxy_address[\n \t\t\t\tsizeof(context-\u003ehttp_proxy_address) - 1] \u003d '\u005c0';\n-\t\n+\n \tp \u003d strchr(context-\u003ehttp_proxy_address, ':');\n-\tif (!p) {\n+\tif (!p \u0026\u0026 !context-\u003ehttp_proxy_port) {\n \t\tlwsl_err(\u0022http_proxy needs to be ads:port\u005cn\u0022);\n \n \t\treturn -1;\n+\t} else {\n+\t\t*p \u003d '\u005c0';\n+\t\tcontext-\u003ehttp_proxy_port \u003d atoi(p + 1);\n \t}\n-\t*p \u003d '\u005c0';\n-\tcontext-\u003ehttp_proxy_port \u003d atoi(p + 1);\n-\t\n+\n \tlwsl_notice(\u0022 Proxy %s:%u\u005cn\u0022, context-\u003ehttp_proxy_address,\n \t\t\t\t\t\tcontext-\u003ehttp_proxy_port);\n \n \treturn 0;\n+\n+auth_too_long:\n+\tlwsl_err(\u0022proxy auth too long\u005cn\u0022);\n+\n+\treturn -1;\n }\n \n /**\ndiff --git a/lib/libwebsockets.h b/lib/libwebsockets.h\nindex 859ee96..3d7b469 100644\n--- a/lib/libwebsockets.h\n+++ b/lib/libwebsockets.h\n@@ -1047,7 +1047,9 @@ struct libwebsocket_extension {\n * @ssl_cipher_list:\tList of valid ciphers to use (eg,\n * \t\t\t\u0022RC4-MD5:RC4-SHA:AES128-SHA:AES256-SHA:HIGH:!DSS:!aNULL\u0022\n * \t\t\tor you can leave it as NULL to get \u0022DEFAULT\u0022\n- * @http_proxy_address: If non-NULL, attempts to proxy via the given address\n+ * @http_proxy_address: If non-NULL, attempts to proxy via the given address.\n+ *\t\t\tIf proxy auth is required, use format\n+ *\t\t\t\u0022username:password@server:port\u0022\n * @http_proxy_port:\tIf http_proxy_address was non-NULL, uses this port at the address \n * @gid:\tgroup id to change to after setting listen socket, or -1.\n * @uid:\tuser id to change to after setting listen socket, or -1.\ndiff --git a/lib/private-libwebsockets.h b/lib/private-libwebsockets.h\nindex da6a2d9..a96e295 100644\n--- a/lib/private-libwebsockets.h\n+++ b/lib/private-libwebsockets.h\n@@ -452,6 +452,7 @@ struct libwebsocket_context {\n \tconst char *iface;\n \tchar http_proxy_address[128];\n \tchar canonical_hostname[128];\n+\tchar proxy_basic_auth_token[128];\n \tunsigned int http_proxy_port;\n \tunsigned int options;\n \ttime_t last_timeout_check_s;\n","s":{"c":1750653498,"u": 9331}} ],"g": 10904,"chitpc": 0,"ehitpc": 0,"indexed":0 , "ab": 0, "si": 0, "db":0, "di":0, "sat":0, "lfc": "0000"}