From 792667ff8ef13e16823d96b490ea9a4f498425ea Mon Sep 17 00:00:00 2001 From: Logan Dethrow Date: Tue, 19 Jul 2011 14:20:21 -0400 Subject: STORM-1112 Added LLProxy::applyProxySettings() to apply proxy settings to curl handles. Added call to that function everywhere curl handles are created in the viewer. --- indra/llmessage/llcurl.h | 103 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) (limited to 'indra/llmessage/llcurl.h') diff --git a/indra/llmessage/llcurl.h b/indra/llmessage/llcurl.h index 4ce3fa1078..5dd894d9b8 100644 --- a/indra/llmessage/llcurl.h +++ b/indra/llmessage/llcurl.h @@ -184,6 +184,106 @@ private: static const unsigned int MAX_REDIRECTS; }; +class LLCurl::Easy +{ + LOG_CLASS(Easy); + +private: + Easy(); + +public: + static Easy* getEasy(); + ~Easy(); + + CURL* getCurlHandle() const { return mCurlEasyHandle; } + + void setErrorBuffer(); + void setCA(); + + void setopt(CURLoption option, S32 value); + // These assume the setter does not free value! + void setopt(CURLoption option, void* value); + void setopt(CURLoption option, char* value); + // Copies the string so that it is guaranteed to stick around + void setoptString(CURLoption option, const std::string& value); + + void slist_append(const char* str); + void setHeaders(); + + U32 report(CURLcode); + void getTransferInfo(LLCurl::TransferInfo* info); + + void prepRequest(const std::string& url, const std::vector& headers, ResponderPtr, bool post = false); + + const char* getErrorBuffer(); + + std::stringstream& getInput() { return mInput; } + std::stringstream& getHeaderOutput() { return mHeaderOutput; } + LLIOPipe::buffer_ptr_t& getOutput() { return mOutput; } + const LLChannelDescriptors& getChannels() { return mChannels; } + + void resetState(); + + static CURL* allocEasyHandle(); + static void releaseEasyHandle(CURL* handle); + +private: + friend class LLCurl; + + CURL* mCurlEasyHandle; + struct curl_slist* mHeaders; + + std::stringstream mRequest; + LLChannelDescriptors mChannels; + LLIOPipe::buffer_ptr_t mOutput; + std::stringstream mInput; + std::stringstream mHeaderOutput; + char mErrorBuffer[CURL_ERROR_SIZE]; + + // Note: char*'s not strings since we pass pointers to curl + std::vector mStrings; + + ResponderPtr mResponder; + + static std::set sFreeHandles; + static std::set sActiveHandles; + static LLMutex* sHandleMutex; +}; + +class LLCurl::Multi +{ + LOG_CLASS(Multi); +public: + + Multi(); + ~Multi(); + + Easy* allocEasy(); + bool addEasy(Easy* easy); + + void removeEasy(Easy* easy); + + S32 process(); + S32 perform(); + + CURLMsg* info_read(S32* msgs_in_queue); + + S32 mQueued; + S32 mErrorCount; + +private: + void easyFree(Easy*); + + CURLM* mCurlMultiHandle; + + typedef std::set easy_active_list_t; + easy_active_list_t mEasyActiveList; + typedef std::map easy_active_map_t; + easy_active_map_t mEasyActiveMap; + typedef std::set easy_free_list_t; + easy_free_list_t mEasyFreeList; +}; + namespace boost { void intrusive_ptr_add_ref(LLCurl::Responder* p); @@ -250,4 +350,7 @@ private: bool mResultReturned; }; +void check_curl_code(CURLcode code); +void check_curl_multi_code(CURLMcode code); + #endif // LL_LLCURL_H -- cgit v1.3 From f15d28a636da7b6d2784d9301e7a030b5bd38a8c Mon Sep 17 00:00:00 2001 From: Logan Dethrow Date: Thu, 28 Jul 2011 13:47:20 -0400 Subject: Proxy cleanup in llstartup.cpp and llproxy.cpp. --- indra/llmessage/llcurl.h | 2 + indra/llmessage/llproxy.cpp | 45 ++---------- indra/newview/llstartup.cpp | 79 ++++++++++++---------- .../newview/skins/default/xui/en/notifications.xml | 11 +++ 4 files changed, 62 insertions(+), 75 deletions(-) (limited to 'indra/llmessage/llcurl.h') diff --git a/indra/llmessage/llcurl.h b/indra/llmessage/llcurl.h index 79f5eeb927..d60d3b6f40 100644 --- a/indra/llmessage/llcurl.h +++ b/indra/llmessage/llcurl.h @@ -355,6 +355,8 @@ public: bool getResult(CURLcode* result, LLCurl::TransferInfo* info = NULL); std::string getErrorString(); + LLCurl::Easy* getEasy() const { return mEasy; } + private: CURLMsg* info_read(S32* queue, LLCurl::TransferInfo* info); diff --git a/indra/llmessage/llproxy.cpp b/indra/llmessage/llproxy.cpp index d34ad1a811..e1970f1368 100644 --- a/indra/llmessage/llproxy.cpp +++ b/indra/llmessage/llproxy.cpp @@ -278,50 +278,15 @@ void LLProxy::cleanupClass() } // Apply proxy settings to CuRL request if either type of HTTP proxy is enabled. -void LLProxy::applyProxySettings(LLCurl::Easy* handle) +void LLProxy::applyProxySettings(LLCurlEasyRequest* handle) { - if (sHTTPProxyEnabled) - { - std::string address = mHTTPProxy.getIPString(); - U16 port = mHTTPProxy.getPort(); - handle->setoptString(CURLOPT_PROXY, address.c_str()); - handle->setopt(CURLOPT_PROXYPORT, port); - if (mProxyType == LLPROXY_SOCKS) - { - handle->setopt(CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5); - if (mAuthMethodSelected == METHOD_PASSWORD) - { - handle->setoptString(CURLOPT_PROXYUSERPWD, getProxyUserPwdCURL()); - } - } - else - { - handle->setopt(CURLOPT_PROXYTYPE, CURLPROXY_HTTP); - } - } + applyProxySettings(handle->getEasy()); } -void LLProxy::applyProxySettings(LLCurlEasyRequest* handle) + +void LLProxy::applyProxySettings(LLCurl::Easy* handle) { - if (sHTTPProxyEnabled) - { - std::string address = mHTTPProxy.getIPString(); - U16 port = mHTTPProxy.getPort(); - handle->setoptString(CURLOPT_PROXY, address.c_str()); - handle->setopt(CURLOPT_PROXYPORT, port); - if (mProxyType == LLPROXY_SOCKS) - { - handle->setopt(CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5); - if (mAuthMethodSelected == METHOD_PASSWORD) - { - handle->setoptString(CURLOPT_PROXYUSERPWD, getProxyUserPwdCURL()); - } - } - else - { - handle->setopt(CURLOPT_PROXYTYPE, CURLPROXY_HTTP); - } - } + applyProxySettings(handle->getCurlHandle()); } void LLProxy::applyProxySettings(CURL* handle) diff --git a/indra/newview/llstartup.cpp b/indra/newview/llstartup.cpp index 1fe241a8ce..eca3e5439e 100644 --- a/indra/newview/llstartup.cpp +++ b/indra/newview/llstartup.cpp @@ -2793,8 +2793,8 @@ bool LLStartUp::handleSocksProxy() LLProxy::getInstance()->disableHTTPProxy(); } - bool use_socks_proxy = gSavedSettings.getBOOL("Socks5ProxyEnabled"); - if (use_socks_proxy) + // Set up SOCKS proxy (if needed) + if (gSavedSettings.getBOOL("Socks5ProxyEnabled")) { // Determine and update LLProxy with the saved authentication system @@ -2826,45 +2826,54 @@ bool LLStartUp::handleSocksProxy() // Start the proxy and check for errors // If status != SOCKS_OK, stopProxy() will already have been called when startProxy() returns. int status = LLProxy::getInstance()->startProxy(gSavedSettings.getString("Socks5ProxyHost"), gSavedSettings.getU32("Socks5ProxyPort")); - LLSD subs; - subs["HOST"] = gSavedSettings.getString("Socks5ProxyHost"); - subs["PORT"] = (S32)gSavedSettings.getU32("Socks5ProxyPort"); - std::string error_string; - - switch(status) + if (status == SOCKS_OK) { - case SOCKS_OK: - return true; - break; - - case SOCKS_CONNECT_ERROR: // TCP Fail - error_string = "SOCKS_CONNECT_ERROR"; - break; - - case SOCKS_NOT_PERMITTED: // SOCKS 5 server rule set refused connection - error_string = "SOCKS_NOT_PERMITTED"; - break; - - case SOCKS_NOT_ACCEPTABLE: // Selected authentication is not acceptable to server - error_string = "SOCKS_NOT_ACCEPTABLE"; - break; + return true; + } + else + { + LLSD subs; + subs["HOST"] = gSavedSettings.getString("Socks5ProxyHost"); + subs["PORT"] = (S32)gSavedSettings.getU32("Socks5ProxyPort"); - case SOCKS_AUTH_FAIL: // Authentication failed - error_string = "SOCKS_AUTH_FAIL"; - break; + std::string error_string; - case SOCKS_UDP_FWD_NOT_GRANTED: // UDP forward request failed - error_string = "SOCKS_UDP_FWD_NOT_GRANTED"; - break; + switch(status) + { + case SOCKS_CONNECT_ERROR: // TCP Fail + error_string = "SOCKS_CONNECT_ERROR"; + break; + + case SOCKS_NOT_PERMITTED: // SOCKS 5 server rule set refused connection + error_string = "SOCKS_NOT_PERMITTED"; + break; + + case SOCKS_NOT_ACCEPTABLE: // Selected authentication is not acceptable to server + error_string = "SOCKS_NOT_ACCEPTABLE"; + break; + + case SOCKS_AUTH_FAIL: // Authentication failed + error_string = "SOCKS_AUTH_FAIL"; + break; + + case SOCKS_UDP_FWD_NOT_GRANTED: // UDP forward request failed + error_string = "SOCKS_UDP_FWD_NOT_GRANTED"; + break; + + case SOCKS_HOST_CONNECT_FAILED: // Failed to open a TCP channel to the socks server + error_string = "SOCKS_HOST_CONNECT_FAILED"; + break; + + default: + error_string = "SOCKS_UNKNOWN_STATUS"; // Something strange happened, + LL_WARNS("Proxy") << "Unknown return from LLProxy::startProxy(): " << status << LL_ENDL; + break; + } - case SOCKS_HOST_CONNECT_FAILED: // Failed to open a TCP channel to the socks server - error_string = "SOCKS_HOST_CONNECT_FAILED"; - break; + LLNotificationsUtil::add(error_string, subs); + return false; } - - LLNotificationsUtil::add(error_string, subs); - return false; } else { diff --git a/indra/newview/skins/default/xui/en/notifications.xml b/indra/newview/skins/default/xui/en/notifications.xml index 78685dbd79..8b7e6d8c4e 100644 --- a/indra/newview/skins/default/xui/en/notifications.xml +++ b/indra/newview/skins/default/xui/en/notifications.xml @@ -7207,6 +7207,17 @@ Click and drag anywhere on the world to rotate your view name="okbutton" yestext="OK"/> + + + Unknown SOCKS error with server "[HOST]:[PORT]" + fail + +