diff options
author | Rider Linden <rider@lindenlab.com> | 2015-09-15 17:01:26 -0700 |
---|---|---|
committer | Rider Linden <rider@lindenlab.com> | 2015-09-15 17:01:26 -0700 |
commit | 907efc9cc9bcf4a935ed0e1bd17b19da2bb99dce (patch) | |
tree | 8453041f5ba3e07fbe0e7d2a632ee1fbf08698e7 /indra/llmessage | |
parent | 5f7985f6a79a21256162785cd9f0b97baac0504a (diff) |
MAINT-5507: Remove llcurl, move constant values and untilities to llcorehttp lib
Diffstat (limited to 'indra/llmessage')
-rwxr-xr-x | indra/llmessage/CMakeLists.txt | 4 | ||||
-rwxr-xr-x | indra/llmessage/llcurl.cpp | 360 | ||||
-rwxr-xr-x | indra/llmessage/llcurl.h | 142 | ||||
-rwxr-xr-x | indra/llmessage/llhttpconstants.cpp | 226 | ||||
-rwxr-xr-x | indra/llmessage/llhttpconstants.h | 226 | ||||
-rwxr-xr-x | indra/llmessage/llproxy.cpp | 13 | ||||
-rwxr-xr-x | indra/llmessage/llproxy.h | 2 | ||||
-rwxr-xr-x | indra/llmessage/lltrustedmessageservice.cpp | 1 | ||||
-rwxr-xr-x | indra/llmessage/message.h | 1 |
9 files changed, 8 insertions, 967 deletions
diff --git a/indra/llmessage/CMakeLists.txt b/indra/llmessage/CMakeLists.txt index 9cbb76e794..3bcee13d28 100755 --- a/indra/llmessage/CMakeLists.txt +++ b/indra/llmessage/CMakeLists.txt @@ -42,13 +42,11 @@ set(llmessage_SOURCE_FILES llclassifiedflags.cpp llcoproceduremanager.cpp llcorehttputil.cpp - llcurl.cpp lldatapacker.cpp lldispatcher.cpp llexperiencecache.cpp llfiltersd2xmlrpc.cpp llhost.cpp - llhttpconstants.cpp llhttpnode.cpp llhttpsdhandler.cpp llinstantmessage.cpp @@ -126,7 +124,6 @@ set(llmessage_HEADER_FILES llclassifiedflags.h llcoproceduremanager.h llcorehttputil.h - llcurl.h lldatapacker.h lldbstrings.h lldispatcher.h @@ -136,7 +133,6 @@ set(llmessage_HEADER_FILES llfiltersd2xmlrpc.h llfollowcamparams.h llhost.h - llhttpconstants.h llhttpnode.h llhttpnodeadapter.h llhttpsdhandler.h diff --git a/indra/llmessage/llcurl.cpp b/indra/llmessage/llcurl.cpp deleted file mode 100755 index 0094c42a02..0000000000 --- a/indra/llmessage/llcurl.cpp +++ /dev/null @@ -1,360 +0,0 @@ -/** - * @file llcurl.cpp - * @author Zero / Donovan - * @date 2006-10-15 - * @brief Implementation of wrapper around libcurl. - * - * $LicenseInfo:firstyear=2006&license=viewerlgpl$ - * Second Life Viewer Source Code - * Copyright (C) 2010-2013, Linden Research, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; - * version 2.1 of the License only. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA - * $/LicenseInfo$ - */ - -#if LL_WINDOWS -#define SAFE_SSL 1 -#elif LL_DARWIN -#define SAFE_SSL 1 -#else -#define SAFE_SSL 1 -#endif - -#include "linden_common.h" - -#include "llcurl.h" - -#include <algorithm> -#include <iomanip> -#include <curl/curl.h> -#if SAFE_SSL -#include <openssl/crypto.h> -#endif - -#include "llbufferstream.h" -#include "llproxy.h" -#include "llsdserialize.h" -#include "llstl.h" -#include "llstring.h" -#include "llthread.h" -#include "lltimer.h" - -////////////////////////////////////////////////////////////////////////////// -/* - The trick to getting curl to do keep-alives is to reuse the - same easy handle for the requests. It appears that curl - keeps a pool of connections alive for each easy handle, but - doesn't share them between easy handles. Therefore it is - important to keep a pool of easy handles and reuse them, - rather than create and destroy them with each request. This - code does this. - - Furthermore, it would behoove us to keep track of which - hosts an easy handle was used for and pick an easy handle - that matches the next request. This code does not current - do this. - */ - -// *TODO: TSN remove the commented code from this file -////////////////////////////////////////////////////////////////////////////// - -//static const S32 MAX_ACTIVE_REQUEST_COUNT = 100; - -// DEBUG // -S32 gCurlEasyCount = 0; -S32 gCurlMultiCount = 0; - -////////////////////////////////////////////////////////////////////////////// - -//static -std::vector<LLMutex*> LLCurl::sSSLMutex; -std::string LLCurl::sCAPath; -std::string LLCurl::sCAFile; -//LLCurlThread* LLCurl::sCurlThread = NULL ; -LLMutex* LLCurl::sHandleMutexp = NULL ; -S32 LLCurl::sTotalHandles = 0 ; -bool LLCurl::sNotQuitting = true; -F32 LLCurl::sCurlRequestTimeOut = 120.f; //seonds -S32 LLCurl::sMaxHandles = 256; //max number of handles, (multi handles and easy handles combined). -CURL* LLCurl::sCurlTemplateStandardHandle = NULL; - -void check_curl_code(CURLcode code) -{ - if (code != CURLE_OK) - { - // linux appears to throw a curl error once per session for a bad initialization - // at a pretty random time (when enabling cookies). - LL_WARNS("curl") << "curl error detected: " << curl_easy_strerror(code) << LL_ENDL; - } -} - -void check_curl_multi_code(CURLMcode code) -{ - if (code != CURLM_OK) - { - // linux appears to throw a curl error once per session for a bad initialization - // at a pretty random time (when enabling cookies). - LL_WARNS("curl") << "curl multi error detected: " << curl_multi_strerror(code) << LL_ENDL; - } -} - -//static -void LLCurl::setCAPath(const std::string& path) -{ - sCAPath = path; -} - -//static -void LLCurl::setCAFile(const std::string& file) -{ - sCAFile = file; -} - -//static -std::string LLCurl::getVersionString() -{ - return std::string(curl_version()); -} - - -//static -std::string LLCurl::strerror(CURLcode errorcode) -{ - return std::string(curl_easy_strerror(errorcode)); -} - - -//////////////////////////////////////////////////////////////////////////// - -#if SAFE_SSL -//static -void LLCurl::ssl_locking_callback(int mode, int type, const char *file, int line) -{ - if (mode & CRYPTO_LOCK) - { - LLCurl::sSSLMutex[type]->lock(); - } - else - { - LLCurl::sSSLMutex[type]->unlock(); - } -} - -//static -unsigned long LLCurl::ssl_thread_id(void) -{ - return LLThread::currentID(); -} -#endif - -void LLCurl::initClass(F32 curl_reuest_timeout, S32 max_number_handles, bool multi_threaded) -{ - sCurlRequestTimeOut = curl_reuest_timeout ; //seconds - sMaxHandles = max_number_handles ; //max number of handles, (multi handles and easy handles combined). - - // Do not change this "unless you are familiar with and mean to control - // internal operations of libcurl" - // - http://curl.haxx.se/libcurl/c/curl_global_init.html - CURLcode code = curl_global_init(CURL_GLOBAL_ALL); - - check_curl_code(code); - -#if SAFE_SSL - S32 mutex_count = CRYPTO_num_locks(); - for (S32 i=0; i<mutex_count; i++) - { - sSSLMutex.push_back(new LLMutex(NULL)); - } - CRYPTO_set_id_callback(&LLCurl::ssl_thread_id); - CRYPTO_set_locking_callback(&LLCurl::ssl_locking_callback); -#endif - -// sCurlThread = new LLCurlThread(multi_threaded) ; - if(multi_threaded) - { - sHandleMutexp = new LLMutex(NULL) ; -// Easy::sHandleMutexp = new LLMutex(NULL) ; - } -} - -void LLCurl::cleanupClass() -{ - sNotQuitting = false; //set quitting - - //shut down curl thread -// while(1) -// { -// if(!sCurlThread->update(1)) //finish all tasks -// { -// break ; -// } -// } - LL_CHECK_MEMORY -// sCurlThread->shutdown() ; - LL_CHECK_MEMORY -// delete sCurlThread ; -// sCurlThread = NULL ; - LL_CHECK_MEMORY - -#if SAFE_SSL - CRYPTO_set_locking_callback(NULL); - for_each(sSSLMutex.begin(), sSSLMutex.end(), DeletePointer()); - sSSLMutex.clear(); -#endif - - LL_CHECK_MEMORY - - // Free the template easy handle - curl_easy_cleanup(sCurlTemplateStandardHandle); - sCurlTemplateStandardHandle = NULL; - LL_CHECK_MEMORY - - - delete sHandleMutexp ; - sHandleMutexp = NULL ; - - LL_CHECK_MEMORY - - // removed as per https://jira.secondlife.com/browse/SH-3115 - //llassert(Easy::sActiveHandles.empty()); -} - -//static -CURLM* LLCurl::newMultiHandle() -{ - llassert(sNotQuitting); - - LLMutexLock lock(sHandleMutexp) ; - - if(sTotalHandles + 1 > sMaxHandles) - { - LL_WARNS() << "no more handles available." << LL_ENDL ; - return NULL ; //failed - } - sTotalHandles++; - - CURLM* ret = curl_multi_init() ; - if(!ret) - { - LL_WARNS() << "curl_multi_init failed." << LL_ENDL ; - } - - return ret ; -} - -//static -CURLMcode LLCurl::deleteMultiHandle(CURLM* handle) -{ - if(handle) - { - LLMutexLock lock(sHandleMutexp) ; - sTotalHandles-- ; - return curl_multi_cleanup(handle) ; - } - return CURLM_OK ; -} - -//static -CURL* LLCurl::newEasyHandle() -{ - llassert(sNotQuitting); - LLMutexLock lock(sHandleMutexp) ; - - if(sTotalHandles + 1 > sMaxHandles) - { - LL_WARNS() << "no more handles available." << LL_ENDL ; - return NULL ; //failed - } - sTotalHandles++; - - CURL* ret = createStandardCurlHandle(); - if(!ret) - { - LL_WARNS() << "failed to create curl handle." << LL_ENDL ; - } - - return ret ; -} - -//static -void LLCurl::deleteEasyHandle(CURL* handle) -{ - if(handle) - { - LLMutexLock lock(sHandleMutexp) ; - LL_CHECK_MEMORY - curl_easy_cleanup(handle) ; - LL_CHECK_MEMORY - sTotalHandles-- ; - } -} - -const unsigned int LLCurl::MAX_REDIRECTS = 5; - -// Provide access to LLCurl free functions outside of llcurl.cpp without polluting the global namespace. -void LLCurlFF::check_easy_code(CURLcode code) -{ - check_curl_code(code); -} -// void LLCurlFF::check_multi_code(CURLMcode code) -// { -// check_curl_multi_code(code); -// } - - -// Static -CURL* LLCurl::createStandardCurlHandle() -{ - if (sCurlTemplateStandardHandle == NULL) - { // Late creation of the template curl handle - sCurlTemplateStandardHandle = curl_easy_init(); - if (sCurlTemplateStandardHandle == NULL) - { - LL_WARNS() << "curl error calling curl_easy_init()" << LL_ENDL; - } - else - { - CURLcode result = curl_easy_setopt(sCurlTemplateStandardHandle, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4); - check_curl_code(result); - result = curl_easy_setopt(sCurlTemplateStandardHandle, CURLOPT_NOSIGNAL, 1); - check_curl_code(result); - result = curl_easy_setopt(sCurlTemplateStandardHandle, CURLOPT_NOPROGRESS, 1); - check_curl_code(result); - result = curl_easy_setopt(sCurlTemplateStandardHandle, CURLOPT_ENCODING, ""); - check_curl_code(result); - result = curl_easy_setopt(sCurlTemplateStandardHandle, CURLOPT_AUTOREFERER, 1); - check_curl_code(result); - result = curl_easy_setopt(sCurlTemplateStandardHandle, CURLOPT_FOLLOWLOCATION, 1); - check_curl_code(result); - result = curl_easy_setopt(sCurlTemplateStandardHandle, CURLOPT_SSL_VERIFYPEER, 1); - check_curl_code(result); - result = curl_easy_setopt(sCurlTemplateStandardHandle, CURLOPT_SSL_VERIFYHOST, 0); - check_curl_code(result); - - // The Linksys WRT54G V5 router has an issue with frequent - // DNS lookups from LAN machines. If they happen too often, - // like for every HTTP request, the router gets annoyed after - // about 700 or so requests and starts issuing TCP RSTs to - // new connections. Reuse the DNS lookups for even a few - // seconds and no RSTs. - result = curl_easy_setopt(sCurlTemplateStandardHandle, CURLOPT_DNS_CACHE_TIMEOUT, 15); - check_curl_code(result); - } - } - - return curl_easy_duphandle(sCurlTemplateStandardHandle); -} diff --git a/indra/llmessage/llcurl.h b/indra/llmessage/llcurl.h deleted file mode 100755 index 289e4bfd22..0000000000 --- a/indra/llmessage/llcurl.h +++ /dev/null @@ -1,142 +0,0 @@ -/** - * @file llcurl.h - * @author Zero / Donovan - * @date 2006-10-15 - * @brief A wrapper around libcurl. - * - * $LicenseInfo:firstyear=2006&license=viewerlgpl$ - * Second Life Viewer Source Code - * Copyright (C) 2010, Linden Research, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; - * version 2.1 of the License only. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA - * $/LicenseInfo$ - */ - -#ifndef LL_LLCURL_H -#define LL_LLCURL_H - -#include "linden_common.h" - -#include <sstream> -#include <string> -#include <vector> - -#include <boost/intrusive_ptr.hpp> -#include <curl/curl.h> // TODO: remove dependency - -#include "llbuffer.h" -#include "llhttpconstants.h" -#include "lliopipe.h" -#include "llsd.h" -#include "llqueuedthread.h" -#include "llframetimer.h" -#include "llpointer.h" -#include "llsingleton.h" - -class LLMutex; -//class LLCurlThread; - -// For whatever reason, this is not typedef'd in curl.h -typedef size_t (*curl_header_callback)(void *ptr, size_t size, size_t nmemb, void *stream); - -class LLCurl -{ - LOG_CLASS(LLCurl); - -public: - - /** - * @ brief Set certificate authority file used to verify HTTPS certs. - */ - static void setCAFile(const std::string& file); - - /** - * @ brief Set certificate authority path used to verify HTTPS certs. - */ - static void setCAPath(const std::string& path); - - /** - * @ brief Return human-readable string describing libcurl version. - */ - static std::string getVersionString(); - - /** - * @ brief Get certificate authority file used to verify HTTPS certs. - */ - static const std::string& getCAFile() { return sCAFile; } - - /** - * @ brief Get certificate authority path used to verify HTTPS certs. - */ - static const std::string& getCAPath() { return sCAPath; } - - /** - * @ brief Initialize LLCurl class - */ - static void initClass(F32 curl_reuest_timeout = 120.f, S32 max_number_handles = 256, bool multi_threaded = false); - - /** - * @ brief Cleanup LLCurl class - */ - static void cleanupClass(); - - /** - * @ brief curl error code -> string - */ - static std::string strerror(CURLcode errorcode); - - // For OpenSSL callbacks - static std::vector<LLMutex*> sSSLMutex; - - // OpenSSL callbacks - static void ssl_locking_callback(int mode, int type, const char *file, int line); - static unsigned long ssl_thread_id(void); - -// static LLCurlThread* getCurlThread() { return sCurlThread ;} - - static CURLM* newMultiHandle() ; - static CURLMcode deleteMultiHandle(CURLM* handle) ; - static CURL* newEasyHandle() ; - static void deleteEasyHandle(CURL* handle) ; - - static CURL* createStandardCurlHandle(); - -private: - static std::string sCAPath; - static std::string sCAFile; - static const unsigned int MAX_REDIRECTS; - // static LLCurlThread* sCurlThread; -// static LLCurlThread* sCurlThread; - - static LLMutex* sHandleMutexp ; - static S32 sTotalHandles ; - static S32 sMaxHandles; - static CURL* sCurlTemplateStandardHandle; -public: - static bool sNotQuitting; - static F32 sCurlRequestTimeOut; -}; - - -// Provide access to LLCurl free functions outside of llcurl.cpp without polluting the global namespace. -namespace LLCurlFF -{ - void check_easy_code(CURLcode code); - //void check_multi_code(CURLMcode code); -} - -#endif // LL_LLCURL_H diff --git a/indra/llmessage/llhttpconstants.cpp b/indra/llmessage/llhttpconstants.cpp deleted file mode 100755 index 32f76f0d70..0000000000 --- a/indra/llmessage/llhttpconstants.cpp +++ /dev/null @@ -1,226 +0,0 @@ -/** - * @file llhttpconstants.cpp - * @brief Implementation of the HTTP request / response constant lookups - * - * $LicenseInfo:firstyear=2013&license=viewerlgpl$ - * Second Life Viewer Source Code - * Copyright (C) 2013-2014, Linden Research, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; - * version 2.1 of the License only. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA - * $/LicenseInfo$ - */ - -#include "linden_common.h" -#include "llhttpconstants.h" -#include "lltimer.h" - -// for curl_getdate() (apparently parsing RFC 1123 dates is hard) -#include <curl/curl.h> - -// Outgoing headers. Do *not* use these to check incoming headers. -// For incoming headers, use the lower-case headers, below. -const std::string HTTP_OUT_HEADER_ACCEPT("Accept"); -const std::string HTTP_OUT_HEADER_ACCEPT_CHARSET("Accept-Charset"); -const std::string HTTP_OUT_HEADER_ACCEPT_ENCODING("Accept-Encoding"); -const std::string HTTP_OUT_HEADER_ACCEPT_LANGUAGE("Accept-Language"); -const std::string HTTP_OUT_HEADER_ACCEPT_RANGES("Accept-Ranges"); -const std::string HTTP_OUT_HEADER_AGE("Age"); -const std::string HTTP_OUT_HEADER_ALLOW("Allow"); -const std::string HTTP_OUT_HEADER_AUTHORIZATION("Authorization"); -const std::string HTTP_OUT_HEADER_CACHE_CONTROL("Cache-Control"); -const std::string HTTP_OUT_HEADER_CONNECTION("Connection"); -const std::string HTTP_OUT_HEADER_CONTENT_DESCRIPTION("Content-Description"); -const std::string HTTP_OUT_HEADER_CONTENT_ENCODING("Content-Encoding"); -const std::string HTTP_OUT_HEADER_CONTENT_ID("Content-ID"); -const std::string HTTP_OUT_HEADER_CONTENT_LANGUAGE("Content-Language"); -const std::string HTTP_OUT_HEADER_CONTENT_LENGTH("Content-Length"); -const std::string HTTP_OUT_HEADER_CONTENT_LOCATION("Content-Location"); -const std::string HTTP_OUT_HEADER_CONTENT_MD5("Content-MD5"); -const std::string HTTP_OUT_HEADER_CONTENT_RANGE("Content-Range"); -const std::string HTTP_OUT_HEADER_CONTENT_TRANSFER_ENCODING("Content-Transfer-Encoding"); -const std::string HTTP_OUT_HEADER_CONTENT_TYPE("Content-Type"); -const std::string HTTP_OUT_HEADER_COOKIE("Cookie"); -const std::string HTTP_OUT_HEADER_DATE("Date"); -const std::string HTTP_OUT_HEADER_DESTINATION("Destination"); -const std::string HTTP_OUT_HEADER_ETAG("ETag"); -const std::string HTTP_OUT_HEADER_EXPECT("Expect"); -const std::string HTTP_OUT_HEADER_EXPIRES("Expires"); -const std::string HTTP_OUT_HEADER_FROM("From"); -const std::string HTTP_OUT_HEADER_HOST("Host"); -const std::string HTTP_OUT_HEADER_IF_MATCH("If-Match"); -const std::string HTTP_OUT_HEADER_IF_MODIFIED_SINCE("If-Modified-Since"); -const std::string HTTP_OUT_HEADER_IF_NONE_MATCH("If-None-Match"); -const std::string HTTP_OUT_HEADER_IF_RANGE("If-Range"); -const std::string HTTP_OUT_HEADER_IF_UNMODIFIED_SINCE("If-Unmodified-Since"); -const std::string HTTP_OUT_HEADER_KEEP_ALIVE("Keep-Alive"); -const std::string HTTP_OUT_HEADER_LAST_MODIFIED("Last-Modified"); -const std::string HTTP_OUT_HEADER_LOCATION("Location"); -const std::string HTTP_OUT_HEADER_MAX_FORWARDS("Max-Forwards"); -const std::string HTTP_OUT_HEADER_MIME_VERSION("MIME-Version"); -const std::string HTTP_OUT_HEADER_PRAGMA("Pragma"); -const std::string HTTP_OUT_HEADER_PROXY_AUTHENTICATE("Proxy-Authenticate"); -const std::string HTTP_OUT_HEADER_PROXY_AUTHORIZATION("Proxy-Authorization"); -const std::string HTTP_OUT_HEADER_RANGE("Range"); -const std::string HTTP_OUT_HEADER_REFERER("Referer"); -const std::string HTTP_OUT_HEADER_RETRY_AFTER("Retry-After"); -const std::string HTTP_OUT_HEADER_SERVER("Server"); -const std::string HTTP_OUT_HEADER_SET_COOKIE("Set-Cookie"); -const std::string HTTP_OUT_HEADER_TE("TE"); -const std::string HTTP_OUT_HEADER_TRAILER("Trailer"); -const std::string HTTP_OUT_HEADER_TRANSFER_ENCODING("Transfer-Encoding"); -const std::string HTTP_OUT_HEADER_UPGRADE("Upgrade"); -const std::string HTTP_OUT_HEADER_USER_AGENT("User-Agent"); -const std::string HTTP_OUT_HEADER_VARY("Vary"); -const std::string HTTP_OUT_HEADER_VIA("Via"); -const std::string HTTP_OUT_HEADER_WARNING("Warning"); -const std::string HTTP_OUT_HEADER_WWW_AUTHENTICATE("WWW-Authenticate"); - -// Incoming headers are normalized to lower-case. -const std::string HTTP_IN_HEADER_ACCEPT_LANGUAGE("accept-language"); -const std::string HTTP_IN_HEADER_CACHE_CONTROL("cache-control"); -const std::string HTTP_IN_HEADER_CONTENT_LENGTH("content-length"); -const std::string HTTP_IN_HEADER_CONTENT_LOCATION("content-location"); -const std::string HTTP_IN_HEADER_CONTENT_TYPE("content-type"); -const std::string HTTP_IN_HEADER_HOST("host"); -const std::string HTTP_IN_HEADER_LOCATION("location"); -const std::string HTTP_IN_HEADER_RETRY_AFTER("retry-after"); -const std::string HTTP_IN_HEADER_SET_COOKIE("set-cookie"); -const std::string HTTP_IN_HEADER_USER_AGENT("user-agent"); -const std::string HTTP_IN_HEADER_X_FORWARDED_FOR("x-forwarded-for"); - -const std::string HTTP_CONTENT_LLSD_XML("application/llsd+xml"); -const std::string HTTP_CONTENT_OCTET_STREAM("application/octet-stream"); -const std::string HTTP_CONTENT_VND_LL_MESH("application/vnd.ll.mesh"); -const std::string HTTP_CONTENT_XML("application/xml"); -const std::string HTTP_CONTENT_JSON("application/json"); -const std::string HTTP_CONTENT_TEXT_HTML("text/html"); -const std::string HTTP_CONTENT_TEXT_HTML_UTF8("text/html; charset=utf-8"); -const std::string HTTP_CONTENT_TEXT_PLAIN_UTF8("text/plain; charset=utf-8"); -const std::string HTTP_CONTENT_TEXT_LLSD("text/llsd"); -const std::string HTTP_CONTENT_TEXT_XML("text/xml"); -const std::string HTTP_CONTENT_TEXT_LSL("text/lsl"); -const std::string HTTP_CONTENT_TEXT_PLAIN("text/plain"); -const std::string HTTP_CONTENT_IMAGE_X_J2C("image/x-j2c"); -const std::string HTTP_CONTENT_IMAGE_J2C("image/j2c"); -const std::string HTTP_CONTENT_IMAGE_JPEG("image/jpeg"); -const std::string HTTP_CONTENT_IMAGE_PNG("image/png"); -const std::string HTTP_CONTENT_IMAGE_BMP("image/bmp"); - -const std::string HTTP_NO_CACHE("no-cache"); -const std::string HTTP_NO_CACHE_CONTROL("no-cache, max-age=0"); - -const std::string HTTP_VERB_INVALID("(invalid)"); -const std::string HTTP_VERB_HEAD("HEAD"); -const std::string HTTP_VERB_GET("GET"); -const std::string HTTP_VERB_PUT("PUT"); -const std::string HTTP_VERB_POST("POST"); -const std::string HTTP_VERB_DELETE("DELETE"); -const std::string HTTP_VERB_MOVE("MOVE"); -const std::string HTTP_VERB_OPTIONS("OPTIONS"); -const std::string HTTP_VERB_PATCH("PATCH"); -const std::string HTTP_VERB_COPY("COPY"); - -const std::string& httpMethodAsVerb(EHTTPMethod method) -{ - static const std::string VERBS[] = - { - HTTP_VERB_INVALID, - HTTP_VERB_HEAD, - HTTP_VERB_GET, - HTTP_VERB_PUT, - HTTP_VERB_POST, - HTTP_VERB_DELETE, - HTTP_VERB_MOVE, - HTTP_VERB_OPTIONS, - HTTP_VERB_PATCH, - HTTP_VERB_COPY - }; - if(((S32)method <=0) || ((S32)method >= HTTP_METHOD_COUNT)) - { - return VERBS[0]; - } - return VERBS[method]; -} - -bool isHttpInformationalStatus(S32 status) -{ - // Check for status 1xx. - return((100 <= status) && (status < 200)); -} - -bool isHttpGoodStatus(S32 status) -{ - // Check for status 2xx. - return((200 <= status) && (status < 300)); -} - -bool isHttpRedirectStatus(S32 status) -{ - // Check for status 3xx. - return((300 <= status) && (status < 400)); -} - -bool isHttpClientErrorStatus(S32 status) -{ - // Status 499 is sometimes used for re-interpreted status 2xx errors - // based on body content. Treat these as potentially retryable 'server' status errors, - // since we do not have enough context to know if this will always fail. - if (HTTP_INTERNAL_ERROR == status) return false; - - // Check for status 5xx. - return((400 <= status) && (status < 500)); -} - -bool isHttpServerErrorStatus(S32 status) -{ - // Status 499 is sometimes used for re-interpreted status 2xx errors. - // Allow retry of these, since we don't have enough information in this - // context to know if this will always fail. - if (HTTP_INTERNAL_ERROR == status) return true; - - // Check for status 5xx. - return((500 <= status) && (status < 600)); -} - -// Parses 'Retry-After' header contents and returns seconds until retry should occur. -bool getSecondsUntilRetryAfter(const std::string& retry_after, F32& seconds_to_wait) -{ - // *TODO: This needs testing! Not in use yet. - // Examples of Retry-After headers: - // Retry-After: Fri, 31 Dec 1999 23:59:59 GMT - // Retry-After: 120 - - // Check for number of seconds version, first: - char* end = 0; - // Parse as double - double seconds = std::strtod(retry_after.c_str(), &end); - if ( end != 0 && *end == 0 ) - { - // Successful parse - seconds_to_wait = (F32) seconds; - return true; - } - - // Parse rfc1123 date. - time_t date = curl_getdate(retry_after.c_str(), NULL ); - if (-1 == date) return false; - - seconds_to_wait = (F64)date - LLTimer::getTotalSeconds(); - - return true; -} - diff --git a/indra/llmessage/llhttpconstants.h b/indra/llmessage/llhttpconstants.h deleted file mode 100755 index d6bcbd3c19..0000000000 --- a/indra/llmessage/llhttpconstants.h +++ /dev/null @@ -1,226 +0,0 @@ -/** - * @file llhttpconstants.h - * @brief Constants for HTTP requests and responses - * - * $LicenseInfo:firstyear=2001&license=viewerlgpl$ - * Second Life Viewer Source Code - * Copyright (C) 2001-2014, Linden Research, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; - * version 2.1 of the License only. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA - * $/LicenseInfo$ - */ - -#ifndef LL_HTTP_CONSTANTS_H -#define LL_HTTP_CONSTANTS_H - -#include "stdtypes.h" - -/////// HTTP STATUS CODES /////// - -// Standard errors from HTTP spec: -// http://www.w3.org/Protocols/rfc2616/rfc2616-sec6.html#sec6.1 -const S32 HTTP_CONTINUE = 100; -const S32 HTTP_SWITCHING_PROTOCOLS = 101; - -// Success -const S32 HTTP_OK = 200; -const S32 HTTP_CREATED = 201; -const S32 HTTP_ACCEPTED = 202; -const S32 HTTP_NON_AUTHORITATIVE_INFORMATION = 203; -const S32 HTTP_NO_CONTENT = 204; -const S32 HTTP_RESET_CONTENT = 205; -const S32 HTTP_PARTIAL_CONTENT = 206; - -// Redirection -const S32 HTTP_MULTIPLE_CHOICES = 300; -const S32 HTTP_MOVED_PERMANENTLY = 301; -const S32 HTTP_FOUND = 302; -const S32 HTTP_SEE_OTHER = 303; -const S32 HTTP_NOT_MODIFIED = 304; -const S32 HTTP_USE_PROXY = 305; -const S32 HTTP_TEMPORARY_REDIRECT = 307; - -// Client Error -const S32 HTTP_BAD_REQUEST = 400; -const S32 HTTP_UNAUTHORIZED = 401; -const S32 HTTP_PAYMENT_REQUIRED = 402; -const S32 HTTP_FORBIDDEN = 403; -const S32 HTTP_NOT_FOUND = 404; -const S32 HTTP_METHOD_NOT_ALLOWED = 405; -const S32 HTTP_NOT_ACCEPTABLE = 406; -const S32 HTTP_PROXY_AUTHENTICATION_REQUIRED = 407; -const S32 HTTP_REQUEST_TIME_OUT = 408; -const S32 HTTP_CONFLICT = 409; -const S32 HTTP_GONE = 410; -const S32 HTTP_LENGTH_REQUIRED = 411; -const S32 HTTP_PRECONDITION_FAILED = 412; -const S32 HTTP_REQUEST_ENTITY_TOO_LARGE = 413; -const S32 HTTP_REQUEST_URI_TOO_LARGE = 414; -const S32 HTTP_UNSUPPORTED_MEDIA_TYPE = 415; -const S32 HTTP_REQUESTED_RANGE_NOT_SATISFIABLE = 416; -const S32 HTTP_EXPECTATION_FAILED = 417; - -// Server Error -const S32 HTTP_INTERNAL_SERVER_ERROR = 500; -const S32 HTTP_NOT_IMPLEMENTED = 501; -const S32 HTTP_BAD_GATEWAY = 502; -const S32 HTTP_SERVICE_UNAVAILABLE = 503; -const S32 HTTP_GATEWAY_TIME_OUT = 504; -const S32 HTTP_VERSION_NOT_SUPPORTED = 505; - -// We combine internal process errors with status codes -// These status codes should not be sent over the wire -// and indicate something went wrong internally. -// If you get these they are not normal. -const S32 HTTP_INTERNAL_CURL_ERROR = 498; -const S32 HTTP_INTERNAL_ERROR = 499; - - -////// HTTP Methods ////// - -extern const std::string HTTP_VERB_INVALID; -extern const std::string HTTP_VERB_HEAD; -extern const std::string HTTP_VERB_GET; -extern const std::string HTTP_VERB_PUT; -extern const std::string HTTP_VERB_POST; -extern const std::string HTTP_VERB_DELETE; -extern const std::string HTTP_VERB_MOVE; -extern const std::string HTTP_VERB_OPTIONS; - -enum EHTTPMethod -{ - HTTP_INVALID = 0, - HTTP_HEAD, - HTTP_GET, - HTTP_PUT, - HTTP_POST, - HTTP_DELETE, - HTTP_MOVE, // Caller will need to set 'Destination' header - HTTP_OPTIONS, - HTTP_PATCH, - HTTP_COPY, - HTTP_METHOD_COUNT -}; - -const std::string& httpMethodAsVerb(EHTTPMethod method); -bool isHttpInformationalStatus(S32 status); -bool isHttpGoodStatus(S32 status); -bool isHttpRedirectStatus(S32 status); -bool isHttpClientErrorStatus(S32 status); -bool isHttpServerErrorStatus(S32 status); - -// Parses 'Retry-After' header contents and returns seconds until retry should occur. -bool getSecondsUntilRetryAfter(const std::string& retry_after, F32& seconds_to_wait); - -//// HTTP Headers ///// - -// Outgoing headers. Do *not* use these to check incoming headers. -// For incoming headers, use the lower-case headers, below. -extern const std::string HTTP_OUT_HEADER_ACCEPT; -extern const std::string HTTP_OUT_HEADER_ACCEPT_CHARSET; -extern const std::string HTTP_OUT_HEADER_ACCEPT_ENCODING; -extern const std::string HTTP_OUT_HEADER_ACCEPT_LANGUAGE; -extern const std::string HTTP_OUT_HEADER_ACCEPT_RANGES; -extern const std::string HTTP_OUT_HEADER_AGE; -extern const std::string HTTP_OUT_HEADER_ALLOW; -extern const std::string HTTP_OUT_HEADER_AUTHORIZATION; -extern const std::string HTTP_OUT_HEADER_CACHE_CONTROL; -extern const std::string HTTP_OUT_HEADER_CONNECTION; -extern const std::string HTTP_OUT_HEADER_CONTENT_DESCRIPTION; -extern const std::string HTTP_OUT_HEADER_CONTENT_ENCODING; -extern const std::string HTTP_OUT_HEADER_CONTENT_ID; -extern const std::string HTTP_OUT_HEADER_CONTENT_LANGUAGE; -extern const std::string HTTP_OUT_HEADER_CONTENT_LENGTH; -extern const std::string HTTP_OUT_HEADER_CONTENT_LOCATION; -extern const std::string HTTP_OUT_HEADER_CONTENT_MD5; -extern const std::string HTTP_OUT_HEADER_CONTENT_RANGE; -extern const std::string HTTP_OUT_HEADER_CONTENT_TRANSFER_ENCODING; -extern const std::string HTTP_OUT_HEADER_CONTENT_TYPE; -extern const std::string HTTP_OUT_HEADER_COOKIE; -extern const std::string HTTP_OUT_HEADER_DATE; -extern const std::string HTTP_OUT_HEADER_DESTINATION; -extern const std::string HTTP_OUT_HEADER_ETAG; -extern const std::string HTTP_OUT_HEADER_EXPECT; -extern const std::string HTTP_OUT_HEADER_EXPIRES; -extern const std::string HTTP_OUT_HEADER_FROM; -extern const std::string HTTP_OUT_HEADER_HOST; -extern const std::string HTTP_OUT_HEADER_IF_MATCH; -extern const std::string HTTP_OUT_HEADER_IF_MODIFIED_SINCE; -extern const std::string HTTP_OUT_HEADER_IF_NONE_MATCH; -extern const std::string HTTP_OUT_HEADER_IF_RANGE; -extern const std::string HTTP_OUT_HEADER_IF_UNMODIFIED_SINCE; -extern const std::string HTTP_OUT_HEADER_KEEP_ALIVE; -extern const std::string HTTP_OUT_HEADER_LAST_MODIFIED; -extern const std::string HTTP_OUT_HEADER_LOCATION; -extern const std::string HTTP_OUT_HEADER_MAX_FORWARDS; -extern const std::string HTTP_OUT_HEADER_MIME_VERSION; -extern const std::string HTTP_OUT_HEADER_PRAGMA; -extern const std::string HTTP_OUT_HEADER_PROXY_AUTHENTICATE; -extern const std::string HTTP_OUT_HEADER_PROXY_AUTHORIZATION; -extern const std::string HTTP_OUT_HEADER_RANGE; -extern const std::string HTTP_OUT_HEADER_REFERER; -extern const std::string HTTP_OUT_HEADER_RETRY_AFTER; -extern const std::string HTTP_OUT_HEADER_SERVER; -extern const std::string HTTP_OUT_HEADER_SET_COOKIE; -extern const std::string HTTP_OUT_HEADER_TE; -extern const std::string HTTP_OUT_HEADER_TRAILER; -extern const std::string HTTP_OUT_HEADER_TRANSFER_ENCODING; -extern const std::string HTTP_OUT_HEADER_UPGRADE; -extern const std::string HTTP_OUT_HEADER_USER_AGENT; -extern const std::string HTTP_OUT_HEADER_VARY; -extern const std::string HTTP_OUT_HEADER_VIA; -extern const std::string HTTP_OUT_HEADER_WARNING; -extern const std::string HTTP_OUT_HEADER_WWW_AUTHENTICATE; - -// Incoming headers are normalized to lower-case. -extern const std::string HTTP_IN_HEADER_ACCEPT_LANGUAGE; -extern const std::string HTTP_IN_HEADER_CACHE_CONTROL; -extern const std::string HTTP_IN_HEADER_CONTENT_LENGTH; -extern const std::string HTTP_IN_HEADER_CONTENT_LOCATION; -extern const std::string HTTP_IN_HEADER_CONTENT_TYPE; -extern const std::string HTTP_IN_HEADER_HOST; -extern const std::string HTTP_IN_HEADER_LOCATION; -extern const std::string HTTP_IN_HEADER_RETRY_AFTER; -extern const std::string HTTP_IN_HEADER_SET_COOKIE; -extern const std::string HTTP_IN_HEADER_USER_AGENT; -extern const std::string HTTP_IN_HEADER_X_FORWARDED_FOR; - -//// HTTP Content Types //// - -extern const std::string HTTP_CONTENT_LLSD_XML; -extern const std::string HTTP_CONTENT_OCTET_STREAM; -extern const std::string HTTP_CONTENT_VND_LL_MESH; -extern const std::string HTTP_CONTENT_XML; -extern const std::string HTTP_CONTENT_JSON; -extern const std::string HTTP_CONTENT_TEXT_HTML; -extern const std::string HTTP_CONTENT_TEXT_HTML_UTF8; -extern const std::string HTTP_CONTENT_TEXT_PLAIN_UTF8; -extern const std::string HTTP_CONTENT_TEXT_LLSD; -extern const std::string HTTP_CONTENT_TEXT_XML; -extern const std::string HTTP_CONTENT_TEXT_LSL; -extern const std::string HTTP_CONTENT_TEXT_PLAIN; -extern const std::string HTTP_CONTENT_IMAGE_X_J2C; -extern const std::string HTTP_CONTENT_IMAGE_J2C; -extern const std::string HTTP_CONTENT_IMAGE_JPEG; -extern const std::string HTTP_CONTENT_IMAGE_PNG; -extern const std::string HTTP_CONTENT_IMAGE_BMP; - -//// HTTP Cache Settings //// -extern const std::string HTTP_NO_CACHE; -extern const std::string HTTP_NO_CACHE_CONTROL; - -#endif diff --git a/indra/llmessage/llproxy.cpp b/indra/llmessage/llproxy.cpp index c25f1ec5e5..537efa69d8 100755 --- a/indra/llmessage/llproxy.cpp +++ b/indra/llmessage/llproxy.cpp @@ -30,9 +30,8 @@ #include <string> #include <curl/curl.h> - +#include "httpcommon.h" #include "llapr.h" -#include "llcurl.h" #include "llhost.h" // Static class variable instances @@ -429,21 +428,21 @@ void LLProxy::applyProxySettings(CURL* handle) // Now test again to verify that the proxy wasn't disabled between the first check and the lock. if (mHTTPProxyEnabled) { - LLCurlFF::check_easy_code(curl_easy_setopt(handle, CURLOPT_PROXY, mHTTPProxy.getIPString().c_str())); - LLCurlFF::check_easy_code(curl_easy_setopt(handle, CURLOPT_PROXYPORT, mHTTPProxy.getPort())); + LLCore::LLHttp::check_curl_code(curl_easy_setopt(handle, CURLOPT_PROXY, mHTTPProxy.getIPString().c_str()), CURLOPT_PROXY); + LLCore::LLHttp::check_curl_code(curl_easy_setopt(handle, CURLOPT_PROXYPORT, mHTTPProxy.getPort()), CURLOPT_PROXYPORT); if (mProxyType == LLPROXY_SOCKS) { - LLCurlFF::check_easy_code(curl_easy_setopt(handle, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5)); + LLCore::LLHttp::check_curl_code(curl_easy_setopt(handle, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5), CURLOPT_PROXYTYPE); if (mAuthMethodSelected == METHOD_PASSWORD) { std::string auth_string = mSocksUsername + ":" + mSocksPassword; - LLCurlFF::check_easy_code(curl_easy_setopt(handle, CURLOPT_PROXYUSERPWD, auth_string.c_str())); + LLCore::LLHttp::check_curl_code(curl_easy_setopt(handle, CURLOPT_PROXYUSERPWD, auth_string.c_str()), CURLOPT_PROXYUSERPWD); } } else { - LLCurlFF::check_easy_code(curl_easy_setopt(handle, CURLOPT_PROXYTYPE, CURLPROXY_HTTP)); + LLCore::LLHttp::check_curl_code(curl_easy_setopt(handle, CURLOPT_PROXYTYPE, CURLPROXY_HTTP), CURLOPT_PROXYTYPE); } } } diff --git a/indra/llmessage/llproxy.h b/indra/llmessage/llproxy.h index da965219fa..bd23dd39de 100755 --- a/indra/llmessage/llproxy.h +++ b/indra/llmessage/llproxy.h @@ -27,12 +27,12 @@ #ifndef LL_PROXY_H #define LL_PROXY_H -#include "llcurl.h" #include "llhost.h" #include "lliosocket.h" #include "llmemory.h" #include "llsingleton.h" #include "llthread.h" +#include <curl/curl.h> #include <string> // SOCKS error codes returned from the StartProxy method diff --git a/indra/llmessage/lltrustedmessageservice.cpp b/indra/llmessage/lltrustedmessageservice.cpp index 5bd1112cfe..33944f7883 100755 --- a/indra/llmessage/lltrustedmessageservice.cpp +++ b/indra/llmessage/lltrustedmessageservice.cpp @@ -30,6 +30,7 @@ #include "llhost.h" #include "llmessageconfig.h" #include "message.h" +#include "llhttpconstants.h" bool LLTrustedMessageService::validate(const std::string& name, LLSD& context) diff --git a/indra/llmessage/message.h b/indra/llmessage/message.h index fc391da633..133db620e6 100755 --- a/indra/llmessage/message.h +++ b/indra/llmessage/message.h @@ -50,7 +50,6 @@ #include "lltimer.h" #include "llpacketring.h" #include "llhost.h" -#include "llcurl.h" #include "llhttpnode.h" //#include "llpacketack.h" #include "llsingleton.h" |