diff options
author | Erik Kundiman <erik@megapahit.org> | 2024-05-16 13:52:40 +0800 |
---|---|---|
committer | Erik Kundiman <erik@megapahit.org> | 2024-05-16 13:52:40 +0800 |
commit | 6d51e91895a7f2435c46a876410ccc6c63fe8c82 (patch) | |
tree | f2b48ebd99cb414227bf365f47665b8d4baa752b /indra/llcorehttp/httpcommon.cpp | |
parent | d1b5917bb9c92e4e47eba19b43781e4d1328b1ca (diff) | |
parent | 094dcc07f8c1d90ae723dbe60eddacb90a09eae8 (diff) |
Merge tag '7.1.7-release'
source for viewer 7.1.7.8974243247
Diffstat (limited to 'indra/llcorehttp/httpcommon.cpp')
-rw-r--r-- | indra/llcorehttp/httpcommon.cpp | 392 |
1 files changed, 196 insertions, 196 deletions
diff --git a/indra/llcorehttp/httpcommon.cpp b/indra/llcorehttp/httpcommon.cpp index 856602e50b..196559d6c2 100644 --- a/indra/llcorehttp/httpcommon.cpp +++ b/indra/llcorehttp/httpcommon.cpp @@ -1,6 +1,6 @@ /** * @file httpcommon.cpp - * @brief + * @brief * * $LicenseInfo:firstyear=2012&license=viewerlgpl$ * Second Life Viewer Source Code @@ -24,7 +24,7 @@ * $/LicenseInfo$ */ -#include "linden_common.h" // Modifies curl/curl.h interfaces +#include "linden_common.h" // Modifies curl/curl.h interfaces #include "httpcommon.h" #include "llmutex.h" #include "llthread.h" @@ -42,184 +42,184 @@ HttpStatus::type_enum_t LLCORE; HttpStatus::operator U32() const { - // Effectively, concatenate mType (high) with mStatus (low). - static const int shift(sizeof(mDetails->mStatus) * 8); + // Effectively, concatenate mType (high) with mStatus (low). + static const int shift(sizeof(mDetails->mStatus) * 8); - U32 result(U32(mDetails->mType) << shift | U32((int)mDetails->mStatus)); - return result; + U32 result(U32(mDetails->mType) << shift | U32((int)mDetails->mStatus)); + return result; } std::string HttpStatus::toHex() const { - std::ostringstream result; - result.width(8); - result.fill('0'); - result << std::hex << operator U32(); - return result.str(); + std::ostringstream result; + result.width(8); + result.fill('0'); + result << std::hex << operator U32(); + return result.str(); } std::string HttpStatus::toString() const { - static const char * llcore_errors[] = - { - "", - "HTTP error reply status", - "Services shutting down", - "Operation canceled", - "Invalid Content-Range header encountered", - "Request handle not found", - "Invalid datatype for argument or option", - "Option has not been explicitly set", - "Option is not dynamic and must be set early", - "Invalid HTTP status code received from server", - "Could not allocate required resource" - }; - static const int llcore_errors_count(sizeof(llcore_errors) / sizeof(llcore_errors[0])); - - static const struct - { - type_enum_t mCode; - const char * mText; - } - http_errors[] = - { - // Keep sorted by mCode, we binary search this list. - { 100, "Continue" }, - { 101, "Switching Protocols" }, - { 200, "OK" }, - { 201, "Created" }, - { 202, "Accepted" }, - { 203, "Non-Authoritative Information" }, - { 204, "No Content" }, - { 205, "Reset Content" }, - { 206, "Partial Content" }, - { 300, "Multiple Choices" }, - { 301, "Moved Permanently" }, - { 302, "Found" }, - { 303, "See Other" }, - { 304, "Not Modified" }, - { 305, "Use Proxy" }, - { 307, "Temporary Redirect" }, - { 400, "Bad Request" }, - { 401, "Unauthorized" }, - { 402, "Payment Required" }, - { 403, "Forbidden" }, - { 404, "Not Found" }, - { 405, "Method Not Allowed" }, - { 406, "Not Acceptable" }, - { 407, "Proxy Authentication Required" }, - { 408, "Request Time-out" }, - { 409, "Conflict" }, - { 410, "Gone" }, - { 411, "Length Required" }, - { 412, "Precondition Failed" }, - { 413, "Request Entity Too Large" }, - { 414, "Request-URI Too Large" }, - { 415, "Unsupported Media Type" }, - { 416, "Requested range not satisfiable" }, - { 417, "Expectation Failed" }, - { 499, "Linden Catch-All" }, - { 500, "Internal Server Error" }, - { 501, "Not Implemented" }, - { 502, "Bad Gateway" }, - { 503, "Service Unavailable" }, - { 504, "Gateway Time-out" }, - { 505, "HTTP Version not supported" } - }; - static const int http_errors_count(sizeof(http_errors) / sizeof(http_errors[0])); - - if (*this) - { - return std::string(""); - } - switch (getType()) - { - case EXT_CURL_EASY: - return std::string(curl_easy_strerror(CURLcode(getStatus()))); - - case EXT_CURL_MULTI: - return std::string(curl_multi_strerror(CURLMcode(getStatus()))); - - case LLCORE: - if (getStatus() >= 0 && getStatus() < llcore_errors_count) - { - return std::string(llcore_errors[getStatus()]); - } - break; - - default: - if (isHttpStatus()) - { - // special handling for status 499 "Linden Catchall" - if ((getType() == 499) && (!getMessage().empty())) - return getMessage(); - - // Binary search for the error code and string - int bottom(0), top(http_errors_count); - while (true) - { - int at((bottom + top) / 2); - if (getType() == http_errors[at].mCode) - { - return std::string(http_errors[at].mText); - } - if (at == bottom) - { - break; - } - else if (getType() < http_errors[at].mCode) - { - top = at; - } - else - { - bottom = at; - } - } - } - break; - } - return std::string("Unknown error"); + static const char * llcore_errors[] = + { + "", + "HTTP error reply status", + "Services shutting down", + "Operation canceled", + "Invalid Content-Range header encountered", + "Request handle not found", + "Invalid datatype for argument or option", + "Option has not been explicitly set", + "Option is not dynamic and must be set early", + "Invalid HTTP status code received from server", + "Could not allocate required resource" + }; + static const int llcore_errors_count(sizeof(llcore_errors) / sizeof(llcore_errors[0])); + + static const struct + { + type_enum_t mCode; + const char * mText; + } + http_errors[] = + { + // Keep sorted by mCode, we binary search this list. + { 100, "Continue" }, + { 101, "Switching Protocols" }, + { 200, "OK" }, + { 201, "Created" }, + { 202, "Accepted" }, + { 203, "Non-Authoritative Information" }, + { 204, "No Content" }, + { 205, "Reset Content" }, + { 206, "Partial Content" }, + { 300, "Multiple Choices" }, + { 301, "Moved Permanently" }, + { 302, "Found" }, + { 303, "See Other" }, + { 304, "Not Modified" }, + { 305, "Use Proxy" }, + { 307, "Temporary Redirect" }, + { 400, "Bad Request" }, + { 401, "Unauthorized" }, + { 402, "Payment Required" }, + { 403, "Forbidden" }, + { 404, "Not Found" }, + { 405, "Method Not Allowed" }, + { 406, "Not Acceptable" }, + { 407, "Proxy Authentication Required" }, + { 408, "Request Time-out" }, + { 409, "Conflict" }, + { 410, "Gone" }, + { 411, "Length Required" }, + { 412, "Precondition Failed" }, + { 413, "Request Entity Too Large" }, + { 414, "Request-URI Too Large" }, + { 415, "Unsupported Media Type" }, + { 416, "Requested range not satisfiable" }, + { 417, "Expectation Failed" }, + { 499, "Linden Catch-All" }, + { 500, "Internal Server Error" }, + { 501, "Not Implemented" }, + { 502, "Bad Gateway" }, + { 503, "Service Unavailable" }, + { 504, "Gateway Time-out" }, + { 505, "HTTP Version not supported" } + }; + static const int http_errors_count(sizeof(http_errors) / sizeof(http_errors[0])); + + if (*this) + { + return std::string(""); + } + switch (getType()) + { + case EXT_CURL_EASY: + return std::string(curl_easy_strerror(CURLcode(getStatus()))); + + case EXT_CURL_MULTI: + return std::string(curl_multi_strerror(CURLMcode(getStatus()))); + + case LLCORE: + if (getStatus() >= 0 && getStatus() < llcore_errors_count) + { + return std::string(llcore_errors[getStatus()]); + } + break; + + default: + if (isHttpStatus()) + { + // special handling for status 499 "Linden Catchall" + if ((getType() == 499) && (!getMessage().empty())) + return getMessage(); + + // Binary search for the error code and string + int bottom(0), top(http_errors_count); + while (true) + { + int at((bottom + top) / 2); + if (getType() == http_errors[at].mCode) + { + return std::string(http_errors[at].mText); + } + if (at == bottom) + { + break; + } + else if (getType() < http_errors[at].mCode) + { + top = at; + } + else + { + bottom = at; + } + } + } + break; + } + return std::string("Unknown error"); } std::string HttpStatus::toTerseString() const { - std::ostringstream result; - - unsigned int error_value((unsigned short)getStatus()); - - switch (getType()) - { - case EXT_CURL_EASY: - result << "Easy_"; - break; - - case EXT_CURL_MULTI: - result << "Multi_"; - break; - - case LLCORE: - result << "Core_"; - break; - - default: - if (isHttpStatus()) - { - result << "Http_"; - error_value = getType(); - } - else - { - result << "Unknown_"; - } - break; - } - - result << error_value; - return result.str(); + std::ostringstream result; + + unsigned int error_value((unsigned short)getStatus()); + + switch (getType()) + { + case EXT_CURL_EASY: + result << "Easy_"; + break; + + case EXT_CURL_MULTI: + result << "Multi_"; + break; + + case LLCORE: + result << "Core_"; + break; + + default: + if (isHttpStatus()) + { + result << "Http_"; + error_value = getType(); + } + else + { + result << "Unknown_"; + } + break; + } + + result << error_value; + return result.str(); } @@ -235,35 +235,35 @@ std::string HttpStatus::toTerseString() const // for details. bool HttpStatus::isRetryable() const { - static const HttpStatus cant_connect(HttpStatus::EXT_CURL_EASY, CURLE_COULDNT_CONNECT); - static const HttpStatus cant_res_proxy(HttpStatus::EXT_CURL_EASY, CURLE_COULDNT_RESOLVE_PROXY); - static const HttpStatus cant_res_host(HttpStatus::EXT_CURL_EASY, CURLE_COULDNT_RESOLVE_HOST); - static const HttpStatus send_error(HttpStatus::EXT_CURL_EASY, CURLE_SEND_ERROR); - static const HttpStatus recv_error(HttpStatus::EXT_CURL_EASY, CURLE_RECV_ERROR); - static const HttpStatus upload_failed(HttpStatus::EXT_CURL_EASY, CURLE_UPLOAD_FAILED); - static const HttpStatus op_timedout(HttpStatus::EXT_CURL_EASY, CURLE_OPERATION_TIMEDOUT); - static const HttpStatus post_error(HttpStatus::EXT_CURL_EASY, CURLE_HTTP_POST_ERROR); - static const HttpStatus partial_file(HttpStatus::EXT_CURL_EASY, CURLE_PARTIAL_FILE); - static const HttpStatus inv_cont_range(HttpStatus::LLCORE, HE_INV_CONTENT_RANGE_HDR); - static const HttpStatus inv_status(HttpStatus::LLCORE, HE_INVALID_HTTP_STATUS); - - // *DEBUG: For "[curl:bugs] #1420" tests. - // Disable the '*this == inv_status' test and look for 'Core_9' - // failures in log files. - - return ((isHttpStatus() && getType() >= 499 && getType() <= 599) || // Include special 499 in retryables - *this == cant_connect || // Connection reset/endpoint problems - *this == cant_res_proxy || // DNS problems - *this == cant_res_host || // DNS problems - *this == send_error || // General socket problems - *this == recv_error || // General socket problems - *this == upload_failed || // Transport problem - *this == op_timedout || // Timer expired - *this == post_error || // Transport problem - *this == partial_file || // Data inconsistency in response - // *DEBUG: Comment out 'inv_status' test for [curl:bugs] #1420 testing. - *this == inv_status || // Inv status can reflect internal state problem in libcurl - *this == inv_cont_range); // Short data read disagrees with content-range + static const HttpStatus cant_connect(HttpStatus::EXT_CURL_EASY, CURLE_COULDNT_CONNECT); + static const HttpStatus cant_res_proxy(HttpStatus::EXT_CURL_EASY, CURLE_COULDNT_RESOLVE_PROXY); + static const HttpStatus cant_res_host(HttpStatus::EXT_CURL_EASY, CURLE_COULDNT_RESOLVE_HOST); + static const HttpStatus send_error(HttpStatus::EXT_CURL_EASY, CURLE_SEND_ERROR); + static const HttpStatus recv_error(HttpStatus::EXT_CURL_EASY, CURLE_RECV_ERROR); + static const HttpStatus upload_failed(HttpStatus::EXT_CURL_EASY, CURLE_UPLOAD_FAILED); + static const HttpStatus op_timedout(HttpStatus::EXT_CURL_EASY, CURLE_OPERATION_TIMEDOUT); + static const HttpStatus post_error(HttpStatus::EXT_CURL_EASY, CURLE_HTTP_POST_ERROR); + static const HttpStatus partial_file(HttpStatus::EXT_CURL_EASY, CURLE_PARTIAL_FILE); + static const HttpStatus inv_cont_range(HttpStatus::LLCORE, HE_INV_CONTENT_RANGE_HDR); + static const HttpStatus inv_status(HttpStatus::LLCORE, HE_INVALID_HTTP_STATUS); + + // *DEBUG: For "[curl:bugs] #1420" tests. + // Disable the '*this == inv_status' test and look for 'Core_9' + // failures in log files. + + return ((isHttpStatus() && getType() >= 499 && getType() <= 599) || // Include special 499 in retryables + *this == cant_connect || // Connection reset/endpoint problems + *this == cant_res_proxy || // DNS problems + *this == cant_res_host || // DNS problems + *this == send_error || // General socket problems + *this == recv_error || // General socket problems + *this == upload_failed || // Transport problem + *this == op_timedout || // Timer expired + *this == post_error || // Transport problem + *this == partial_file || // Data inconsistency in response + // *DEBUG: Comment out 'inv_status' test for [curl:bugs] #1420 testing. + *this == inv_status || // Inv status can reflect internal state problem in libcurl + *this == inv_cont_range); // Short data read disagrees with content-range } namespace LLHttp @@ -275,7 +275,7 @@ CURL *getCurlTemplateHandle() static CURL *curlpTemplateHandle = NULL; if (curlpTemplateHandle == NULL) - { // Late creation of the template curl handle + { // Late creation of the template curl handle curlpTemplateHandle = curl_easy_init(); if (curlpTemplateHandle == NULL) { @@ -315,7 +315,7 @@ CURL *getCurlTemplateHandle() return curlpTemplateHandle; } - + LLMutex *getCurlMutex() { static LLMutex* sHandleMutexp = NULL; @@ -340,7 +340,7 @@ void deallocateEasyCurl(CURL *curlp) void initialize() { - // Do not change this "unless you are familiar with and mean to control + // 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); |