From b9995692e8939de3e0ffc5d5576f948b6be33742 Mon Sep 17 00:00:00 2001 From: Joel Goguen Date: Tue, 19 Aug 2014 17:40:59 -0700 Subject: [PATCH] Add explicit proxy support when using libcurl. The appropriate *_proxy environment variables aren't always detected properly by libcurl. This allows manually setting the proxy when this happens, and disabling SSL certificate verification if the proxy requires it. --- README.md | 2 +- push.cpp | 23 ++++++++++++++++++++--- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 58084e8..4c4634f 100755 --- a/README.md +++ b/README.md @@ -112,7 +112,7 @@ and looking in your profile or settings: /msg *push set username foo /msg *push set secret ... -If you're using Boxcar, you need to use the following command to send a subscription request +If you're using Boxcar or Airgram, you need to use the following command to send a subscription request to your account, before ZNC Push can start working: /msg *push subscribe diff --git a/push.cpp b/push.cpp index 8c41acc..0b2ba1f 100755 --- a/push.cpp +++ b/push.cpp @@ -147,6 +147,10 @@ class CPushMod : public CModule defaults["nick_blacklist"] = ""; defaults["replied"] = "yes"; + // Proxy, for libcurl + defaults["proxy"] = ""; + defaults["proxy_ssl_verify"] = "yes"; + // Advanced defaults["channel_conditions"] = "all"; defaults["query_conditions"] = "all"; @@ -570,13 +574,15 @@ class CPushMod : public CModule #ifdef USE_CURL PutDebug("using libcurl"); - make_curl_request(service_host, service_url, service_auth, params, use_port, use_ssl, use_post, options["debug"] == "on"); + params["proxy"] = options["proxy"]; + params["proxy_ssl_verify"] = options["proxy_ssl_verify"]; + make_curl_request(service_host, service_url, service_auth, params, use_port, use_ssl, use_post, options["debug"] == "on"); #else PutDebug("NOT using libcurl"); // Create the socket connection, write to it, and add it to the queue CPushSocket *sock = new CPushSocket(this); sock->Connect(service_host, use_port, use_ssl); - sock->Request(use_post, service_host, service_url, params, service_auth); + sock->Request(use_post, service_host, service_url, params, service_auth, options["proxy"].c_str()); AddSocket(sock); #endif } @@ -1531,13 +1537,16 @@ class CPushMod : public CModule return; } + params["proxy"] = options["proxy"]; + params["proxy_ssl_verify"] = options["proxy_ssl_verify"]; + #ifdef USE_CURL make_curl_request(service_host, service_url, service_auth, params, use_port, use_ssl, use_post, options["debug"] == "on"); #else // Create the socket connection, write to it, and add it to the queue CPushSocket *sock = new CPushSocket(this); sock->Connect(service_host, use_port, use_ssl); - sock->Request(use_post, service_host, service_url, params, service_auth); + sock->Request(use_post, service_host, service_url, params, service_auth, options["proxy"].c_str()); AddSocket(sock); #endif @@ -1657,6 +1666,14 @@ CURLcode make_curl_request(const CString& service_host, const CString& service_u curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, query.length()); } + if (params["proxy"] != "") { + curl_easy_setopt(curl, CURLOPT_PROXY, params["proxy"].c_str()); + + if (params["proxy_ssl_verify"] == "no") { + curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L); + } + } + result = curl_easy_perform(curl); curl_easy_cleanup(curl);