Skip to content
Snippets Groups Projects
Commit cd556555 authored by Rider Linden's avatar Rider Linden
Browse files

Crash logger changes to LLCore::Http

parent 82b671da
No related branches found
No related tags found
No related merge requests found
......@@ -3,6 +3,7 @@
project(llcrashlogger)
include(00-Common)
include(LLCoreHttp)
include(LLCommon)
include(LLMath)
include(LLMessage)
......@@ -10,6 +11,7 @@ include(LLVFS)
include(LLXML)
include_directories(
${LLCOREHTTP_INCLUDE_DIRS}
${LLCOMMON_INCLUDE_DIRS}
${LLMATH_INCLUDE_DIRS}
${LLMESSAGE_INCLUDE_DIRS}
......
......@@ -40,38 +40,45 @@
#include "lldir.h"
#include "llfile.h"
#include "llsdserialize.h"
#include "lliopipe.h"
#include "llpumpio.h"
#include "llhttpclient.h"
#include "llsdserialize.h"
#include "llproxy.h"
LLPumpIO* gServicePump = NULL;
#include "llcorehttputil.h"
#include "llhttpsdhandler.h"
#include "httpcommon.h"
#include "httpresponse.h"
#include <curl/curl.h>
#include <openssl/crypto.h>
BOOL gBreak = false;
BOOL gSent = false;
class LLCrashLoggerResponder : public LLHTTPClient::Responder
int LLCrashLogger::ssl_mutex_count = 0;
LLCoreInt::HttpMutex ** LLCrashLogger::ssl_mutex_list = NULL;
class LLCrashLoggerHandler : public LLHttpSDHandler
{
LOG_CLASS(LLCrashLoggerResponder);
LOG_CLASS(LLCrashLoggerHandler);
public:
LLCrashLoggerResponder()
{
}
LLCrashLoggerHandler() {}
protected:
virtual void httpFailure()
{
LL_WARNS() << dumpResponse() << LL_ENDL;
gBreak = true;
}
virtual void onSuccess(LLCore::HttpResponse * response, const LLSD &content);
virtual void onFailure(LLCore::HttpResponse * response, LLCore::HttpStatus status);
virtual void httpSuccess()
{
gBreak = true;
gSent = true;
}
};
void LLCrashLoggerHandler::onSuccess(LLCore::HttpResponse * response, const LLSD &content)
{
gBreak = true;
gSent = true;
}
void LLCrashLoggerHandler::onFailure(LLCore::HttpResponse * response, LLCore::HttpStatus status)
{
gBreak = true;
}
LLCrashLogger::LLCrashLogger() :
mCrashBehavior(CRASH_BEHAVIOR_ALWAYS_SEND),
mCrashInPreviousExec(false),
......@@ -389,14 +396,20 @@ bool LLCrashLogger::saveCrashBehaviorSetting(S32 crash_behavior)
bool LLCrashLogger::runCrashLogPost(std::string host, LLSD data, std::string msg, int retries, int timeout)
{
LLCore::HttpRequest httpRequest;
gBreak = false;
for(int i = 0; i < retries; ++i)
{
updateApplication(llformat("%s, try %d...", msg.c_str(), i+1));
LLHTTPClient::post(host, data, new LLCrashLoggerResponder(), timeout);
while(!gBreak)
LLCoreHttpUtil::requestPostWithLLSD(&httpRequest, LLCore::HttpRequest::DEFAULT_POLICY_ID, 0,
host, data, NULL, NULL, new LLCrashLoggerHandler);
while(!gBreak)
{
updateApplication(); // No new message, just pump the IO
httpRequest.update(0L);
}
if(gSent)
{
......@@ -510,8 +523,6 @@ bool LLCrashLogger::sendCrashLogs()
void LLCrashLogger::updateApplication(const std::string& message)
{
gServicePump->pump();
gServicePump->callback();
if (!message.empty()) LL_INFOS() << message << LL_ENDL;
}
......@@ -576,16 +587,74 @@ bool LLCrashLogger::init()
return false;
}
gServicePump = new LLPumpIO(gAPRPoolp);
gServicePump->prime(gAPRPoolp);
LLHTTPClient::setPump(*gServicePump);
init_curl();
LLCore::HttpRequest::createService();
LLCore::HttpRequest::startThread();
return true;
}
// For cleanup code common to all platforms.
void LLCrashLogger::commonCleanup()
{
term_curl();
LLError::logToFile(""); //close crashreport.log
LLProxy::cleanupClass();
}
void LLCrashLogger::init_curl()
{
curl_global_init(CURL_GLOBAL_ALL);
ssl_mutex_count = CRYPTO_num_locks();
if (ssl_mutex_count > 0)
{
ssl_mutex_list = new LLCoreInt::HttpMutex *[ssl_mutex_count];
for (int i(0); i < ssl_mutex_count; ++i)
{
ssl_mutex_list[i] = new LLCoreInt::HttpMutex;
}
CRYPTO_set_locking_callback(ssl_locking_callback);
CRYPTO_set_id_callback(ssl_thread_id_callback);
}
}
void LLCrashLogger::term_curl()
{
CRYPTO_set_locking_callback(NULL);
for (int i(0); i < ssl_mutex_count; ++i)
{
delete ssl_mutex_list[i];
}
delete[] ssl_mutex_list;
}
unsigned long LLCrashLogger::ssl_thread_id_callback(void)
{
#if LL_WINDOWS
return (unsigned long)GetCurrentThread();
#else
return (unsigned long)pthread_self();
#endif
}
void LLCrashLogger::ssl_locking_callback(int mode, int type, const char * /* file */, int /* line */)
{
if (type >= 0 && type < ssl_mutex_count)
{
if (mode & CRYPTO_LOCK)
{
ssl_mutex_list[type]->lock();
}
else
{
ssl_mutex_list[type]->unlock();
}
}
}
......@@ -34,6 +34,7 @@
#include "llsd.h"
#include "llcontrol.h"
#include "llcrashlock.h"
#include "_mutex.h"
// Crash reporter behavior
const S32 CRASH_BEHAVIOR_ASK = 0;
......@@ -66,6 +67,11 @@ class LLCrashLogger : public LLApp
bool readMinidump(std::string minidump_path);
protected:
static void init_curl();
static void term_curl();
static unsigned long ssl_thread_id_callback(void);
static void ssl_locking_callback(int mode, int type, const char * file, int line);
S32 mCrashBehavior;
BOOL mCrashInPreviousExec;
std::map<std::string, std::string> mFileMap;
......@@ -78,6 +84,10 @@ class LLCrashLogger : public LLApp
LLSD mDebugLog;
bool mSentCrashLogs;
LLCrashLock mKeyMaster;
static int ssl_mutex_count;
static LLCoreInt::HttpMutex ** ssl_mutex_list;
};
#endif //LLCRASHLOGGER_H
......@@ -90,18 +90,7 @@ HttpHandle requestPostWithLLSD(HttpRequest * request,
return handle;
}
HttpHandle requestPostWithLLSD(HttpRequest::ptr_t & request,
HttpRequest::policy_t policy_id,
HttpRequest::priority_t priority,
const std::string & url,
const LLSD & body,
HttpOptions::ptr_t & options,
HttpHeaders::ptr_t & headers,
HttpHandler * handler)
{
return requestPostWithLLSD(request.get(), policy_id, priority,
url, body, options.get(), headers.get(), handler);
}
HttpHandle requestPutWithLLSD(HttpRequest * request,
HttpRequest::policy_t policy_id,
......@@ -129,19 +118,6 @@ HttpHandle requestPutWithLLSD(HttpRequest * request,
return handle;
}
HttpHandle requestPutWithLLSD(HttpRequest::ptr_t & request,
HttpRequest::policy_t policy_id,
HttpRequest::priority_t priority,
const std::string & url,
const LLSD & body,
HttpOptions::ptr_t & options,
HttpHeaders::ptr_t & headers,
HttpHandler * handler)
{
return requestPutWithLLSD(request.get(), policy_id, priority,
url, body, options.get(), headers.get(), handler);
}
HttpHandle requestPatchWithLLSD(HttpRequest * request,
HttpRequest::policy_t policy_id,
HttpRequest::priority_t priority,
......@@ -168,19 +144,6 @@ HttpHandle requestPatchWithLLSD(HttpRequest * request,
return handle;
}
HttpHandle requestPatchWithLLSD(HttpRequest::ptr_t & request,
HttpRequest::policy_t policy_id,
HttpRequest::priority_t priority,
const std::string & url,
const LLSD & body,
HttpOptions::ptr_t & options,
HttpHeaders::ptr_t & headers,
HttpHandler * handler)
{
return requestPatchWithLLSD(request.get(), policy_id, priority,
url, body, options.get(), headers.get(), handler);
}
std::string responseToString(LLCore::HttpResponse * response)
{
......
......@@ -112,14 +112,30 @@ LLCore::HttpHandle requestPostWithLLSD(LLCore::HttpRequest * request,
LLCore::HttpHeaders * headers,
LLCore::HttpHandler * handler);
LLCore::HttpHandle requestPostWithLLSD(LLCore::HttpRequest::ptr_t & request,
inline LLCore::HttpHandle requestPostWithLLSD(LLCore::HttpRequest::ptr_t & request,
LLCore::HttpRequest::policy_t policy_id,
LLCore::HttpRequest::priority_t priority,
const std::string & url,
const LLSD & body,
LLCore::HttpOptions::ptr_t & options,
LLCore::HttpHeaders::ptr_t & headers,
LLCore::HttpHandler * handler);
LLCore::HttpHandler * handler)
{
return requestPostWithLLSD(request.get(), policy_id, priority,
url, body, options.get(), headers.get(), handler);
}
inline LLCore::HttpHandle requestPostWithLLSD(LLCore::HttpRequest::ptr_t & request,
LLCore::HttpRequest::policy_t policy_id,
LLCore::HttpRequest::priority_t priority,
const std::string & url,
const LLSD & body,
LLCore::HttpHandler * handler)
{
return requestPostWithLLSD(request.get(), policy_id, priority,
url, body, NULL, NULL, handler);
}
/// Issue a standard HttpRequest::requestPut() call but using
/// and LLSD object as the request body. Conventions are the
......@@ -146,14 +162,29 @@ LLCore::HttpHandle requestPutWithLLSD(LLCore::HttpRequest * request,
LLCore::HttpHeaders * headers,
LLCore::HttpHandler * handler);
LLCore::HttpHandle requestPutWithLLSD(LLCore::HttpRequest::ptr_t & request,
inline LLCore::HttpHandle requestPutWithLLSD(LLCore::HttpRequest::ptr_t & request,
LLCore::HttpRequest::policy_t policy_id,
LLCore::HttpRequest::priority_t priority,
const std::string & url,
const LLSD & body,
LLCore::HttpOptions::ptr_t & options,
LLCore::HttpHeaders::ptr_t & headers,
LLCore::HttpHandler * handler);
LLCore::HttpHandler * handler)
{
return requestPutWithLLSD(request.get(), policy_id, priority,
url, body, options.get(), headers.get(), handler);
}
inline LLCore::HttpHandle requestPutWithLLSD(LLCore::HttpRequest::ptr_t & request,
LLCore::HttpRequest::policy_t policy_id,
LLCore::HttpRequest::priority_t priority,
const std::string & url,
const LLSD & body,
LLCore::HttpHandler * handler)
{
return requestPutWithLLSD(request.get(), policy_id, priority,
url, body, NULL, NULL, handler);
}
/// Issue a standard HttpRequest::requestPatch() call but using
/// and LLSD object as the request body. Conventions are the
......@@ -180,15 +211,29 @@ LLCore::HttpHandle requestPatchWithLLSD(LLCore::HttpRequest * request,
LLCore::HttpHeaders * headers,
LLCore::HttpHandler * handler);
LLCore::HttpHandle requestPatchWithLLSD(LLCore::HttpRequest::ptr_t & request,
inline LLCore::HttpHandle requestPatchWithLLSD(LLCore::HttpRequest::ptr_t & request,
LLCore::HttpRequest::policy_t policy_id,
LLCore::HttpRequest::priority_t priority,
const std::string & url,
const LLSD & body,
LLCore::HttpOptions::ptr_t & options,
LLCore::HttpHeaders::ptr_t & headers,
LLCore::HttpHandler * handler);
LLCore::HttpHandler * handler)
{
return requestPatchWithLLSD(request.get(), policy_id, priority,
url, body, options.get(), headers.get(), handler);
}
inline LLCore::HttpHandle requestPatchWithLLSD(LLCore::HttpRequest::ptr_t & request,
LLCore::HttpRequest::policy_t policy_id,
LLCore::HttpRequest::priority_t priority,
const std::string & url,
const LLSD & body,
LLCore::HttpHandler * handler)
{
return requestPatchWithLLSD(request.get(), policy_id, priority,
url, body, NULL, NULL, handler);
}
/// The HttpCoroHandler is a specialization of the LLCore::HttpHandler for
/// interacting with coroutines. When the request is completed the response
......
......@@ -4,6 +4,7 @@ project(mac_crash_logger)
include(00-Common)
include(LLCommon)
include(LLCoreHttp)
include(LLCrashLogger)
include(LLMath)
include(LLMessage)
......@@ -11,8 +12,10 @@ include(LLVFS)
include(LLXML)
include(Linking)
include(LLSharedLibs)
include(Boost)
include_directories(
${LLCOREHTTP_INCLUDE_DIRS}
${LLCOMMON_INCLUDE_DIRS}
${LLCRASHLOGGER_INCLUDE_DIRS}
${LLMATH_INCLUDE_DIRS}
......@@ -71,7 +74,10 @@ target_link_libraries(mac-crash-logger
${LLMESSAGE_LIBRARIES}
${LLVFS_LIBRARIES}
${LLMATH_LIBRARIES}
${LLCOREHTTP_LIBRARIES}
${LLCOMMON_LIBRARIES}
${BOOST_CONTEXT_LIBRARY}
${BOOST_COROUTINE_LIBRARY}
)
add_custom_command(
......
......@@ -4,6 +4,7 @@ project(win_crash_logger)
include(00-Common)
include(LLCommon)
include(LLCoreHttp)
include(LLCrashLogger)
include(LLMath)
include(LLMessage)
......@@ -13,8 +14,10 @@ include(LLXML)
include(Linking)
include(LLSharedLibs)
include(GoogleBreakpad)
include(Boost)
include_directories(
${LLCOREHTTP_INCLUDE_DIRS}
${LLCOMMON_INCLUDE_DIRS}
${LLCRASHLOGGER_INCLUDE_DIRS}
${LLMATH_INCLUDE_DIRS}
......@@ -77,7 +80,10 @@ target_link_libraries(windows-crash-logger
${LLXML_LIBRARIES}
${LLMESSAGE_LIBRARIES}
${LLMATH_LIBRARIES}
${LLCOREHTTP_LIBRARIES}
${LLCOMMON_LIBRARIES}
${BOOST_CONTEXT_LIBRARY}
${BOOST_COROUTINE_LIBRARY}
${WINDOWS_LIBRARIES}
${DXGUID_LIBRARY}
${GOOGLE_PERFTOOLS_LIBRARIES}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment