Add somewhat ugly --nohttp option
used for the renderer to not include libcurl, because it isn't installed on the tpt server
This commit is contained in:
parent
6279bbeed3
commit
5dd4897fa4
11
SConscript
11
SConscript
@ -72,9 +72,10 @@ AddSconsOption('font', False, False, "Build the font editor.")
|
||||
AddSconsOption('wall', False, False, "Error on all warnings.")
|
||||
AddSconsOption('no-warnings', False, False, "Disable all compiler warnings.")
|
||||
AddSconsOption('nolua', False, False, "Disable Lua.")
|
||||
AddSconsOption('luajit', False, False, "Enable LuaJIT")
|
||||
AddSconsOption('lua52', False, False, "Compile using lua 5.2")
|
||||
AddSconsOption('luajit', False, False, "Enable LuaJIT.")
|
||||
AddSconsOption('lua52', False, False, "Compile using lua 5.2.")
|
||||
AddSconsOption('nofft', False, False, "Disable FFT.")
|
||||
AddSconsOption('nohttp', False, False, "Disable http requests and libcurl.")
|
||||
AddSconsOption("output", False, True, "Executable output name.")
|
||||
|
||||
|
||||
@ -327,7 +328,7 @@ def findLibs(env, conf):
|
||||
FatalError("libz not found or not installed")
|
||||
|
||||
#Look for libcurl
|
||||
if not conf.CheckLib(['curl', 'libcurl']):
|
||||
if not GetOption('nohttp') and not conf.CheckLib(['curl', 'libcurl']):
|
||||
FatalError("libcurl not found or not installed")
|
||||
|
||||
if platform == "Linux" or compilePlatform == "Linux" or platform == "FreeBSD":
|
||||
@ -496,10 +497,12 @@ if GetOption('static'):
|
||||
|
||||
|
||||
#Add other flags and defines
|
||||
if not GetOption('nofft'):
|
||||
if not GetOption('nofft') or GetOption('renderer'):
|
||||
env.Append(CPPDEFINES=['GRAVFFT'])
|
||||
if not GetOption('nolua') and not GetOption('renderer') and not GetOption('font'):
|
||||
env.Append(CPPDEFINES=['LUACONSOLE'])
|
||||
if GetOption('nohttp') or GetOption('renderer'):
|
||||
env.Append(CPPDEFINES=['NOHTTP'])
|
||||
|
||||
if GetOption('opengl') or GetOption('opengl-renderer'):
|
||||
env.Append(CPPDEFINES=['OGLI', 'PIX32OGL'])
|
||||
|
@ -110,8 +110,10 @@ void Client::Initialise(ByteString proxyString, bool disableNetwork)
|
||||
update_finish();
|
||||
}
|
||||
|
||||
#ifndef NOHTTP
|
||||
if (!disableNetwork)
|
||||
http::RequestManager::Ref().Initialise(proxyString);
|
||||
#endif
|
||||
|
||||
//Read stamps library
|
||||
std::ifstream stampsLib;
|
||||
@ -924,7 +926,9 @@ void Client::Shutdown()
|
||||
alternateVersionCheckRequest->Cancel();
|
||||
}
|
||||
|
||||
#ifndef NOHTTP
|
||||
http::RequestManager::Ref().Shutdown();
|
||||
#endif
|
||||
|
||||
//Save config
|
||||
WritePrefs();
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
namespace http
|
||||
{
|
||||
#ifndef NOHTTP
|
||||
Request::Request(ByteString uri_):
|
||||
uri(uri_),
|
||||
rm_total(0),
|
||||
@ -28,9 +29,13 @@ namespace http
|
||||
rm_finished = true;
|
||||
}
|
||||
}
|
||||
#else
|
||||
Request::Request(ByteString uri_) {}
|
||||
#endif
|
||||
|
||||
Request::~Request()
|
||||
{
|
||||
#ifndef NOHTTP
|
||||
curl_easy_cleanup(easy);
|
||||
#ifdef REQUEST_USE_CURL_MIMEPOST
|
||||
curl_mime_free(post_fields);
|
||||
@ -38,16 +43,20 @@ namespace http
|
||||
curl_formfree(post_fields_first);
|
||||
#endif
|
||||
curl_slist_free_all(headers);
|
||||
#endif
|
||||
}
|
||||
|
||||
void Request::AddHeader(ByteString name, ByteString value)
|
||||
{
|
||||
#ifndef NOHTTP
|
||||
headers = curl_slist_append(headers, (name + ": " + value).c_str());
|
||||
#endif
|
||||
}
|
||||
|
||||
// add post data to a request
|
||||
void Request::AddPostData(std::map<ByteString, ByteString> data)
|
||||
{
|
||||
#ifndef NOHTTP
|
||||
if (!data.size())
|
||||
{
|
||||
return;
|
||||
@ -79,6 +88,7 @@ namespace http
|
||||
post_fields_map.insert(data.begin(), data.end());
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// add userID and sessionID headers to the request
|
||||
@ -98,6 +108,7 @@ namespace http
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef NOHTTP
|
||||
size_t Request::WriteDataHandler(char *ptr, size_t size, size_t count, void *userdata)
|
||||
{
|
||||
Request *req = (Request *)userdata;
|
||||
@ -105,10 +116,12 @@ namespace http
|
||||
req->response_body.append(ptr, actual_size);
|
||||
return actual_size;
|
||||
}
|
||||
#endif
|
||||
|
||||
// start the request thread
|
||||
void Request::Start()
|
||||
{
|
||||
#ifndef NOHTTP
|
||||
if (CheckStarted() || CheckDone())
|
||||
{
|
||||
return;
|
||||
@ -210,12 +223,14 @@ namespace http
|
||||
rm_started = true;
|
||||
}
|
||||
RequestManager::Ref().StartRequest(this);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
// finish the request (if called before the request is done, this will block)
|
||||
ByteString Request::Finish(int *status_out)
|
||||
{
|
||||
#ifndef NOHTTP
|
||||
if (CheckCanceled())
|
||||
{
|
||||
return ""; // shouldn't happen but just in case
|
||||
@ -236,10 +251,16 @@ namespace http
|
||||
|
||||
RequestManager::Ref().RemoveRequest(this);
|
||||
return response_out;
|
||||
#else
|
||||
if (status_out)
|
||||
*status_out = 604;
|
||||
return "";
|
||||
#endif
|
||||
}
|
||||
|
||||
void Request::CheckProgress(int *total, int *done)
|
||||
{
|
||||
#ifndef NOHTTP
|
||||
std::lock_guard<std::mutex> g(rm_mutex);
|
||||
if (total)
|
||||
{
|
||||
@ -249,38 +270,53 @@ namespace http
|
||||
{
|
||||
*done = rm_done;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// returns true if the request has finished
|
||||
bool Request::CheckDone()
|
||||
{
|
||||
#ifndef NOHTTP
|
||||
std::lock_guard<std::mutex> g(rm_mutex);
|
||||
return rm_finished;
|
||||
#else
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
|
||||
// returns true if the request was canceled
|
||||
bool Request::CheckCanceled()
|
||||
{
|
||||
#ifndef NOHTTP
|
||||
std::lock_guard<std::mutex> g(rm_mutex);
|
||||
return rm_canceled;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
// returns true if the request is running
|
||||
bool Request::CheckStarted()
|
||||
{
|
||||
#ifndef NOHTTP
|
||||
std::lock_guard<std::mutex> g(rm_mutex);
|
||||
return rm_started;
|
||||
#else
|
||||
return true;
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
// cancels the request, the request thread will delete the Request* when it finishes (do not use Request in any way after canceling)
|
||||
void Request::Cancel()
|
||||
{
|
||||
#ifndef NOHTTP
|
||||
{
|
||||
std::lock_guard<std::mutex> g(rm_mutex);
|
||||
rm_canceled = true;
|
||||
}
|
||||
RequestManager::Ref().RemoveRequest(this);
|
||||
#endif
|
||||
}
|
||||
|
||||
ByteString Request::Simple(ByteString uri, int *status, std::map<ByteString, ByteString> post_data)
|
||||
|
@ -2,11 +2,12 @@
|
||||
#define REQUEST_H
|
||||
|
||||
#include <map>
|
||||
#include "common/String.h"
|
||||
#ifndef NOHTTP
|
||||
#include "common/tpt-minmax.h" // for MSVC, ensures windows.h doesn't cause compile errors by defining min/max
|
||||
#include <mutex>
|
||||
#include <condition_variable>
|
||||
#include <curl/curl.h>
|
||||
#include "common/String.h"
|
||||
|
||||
#if defined(CURL_AT_LEAST_VERSION) && CURL_AT_LEAST_VERSION(7, 55, 0)
|
||||
# define REQUEST_USE_CURL_OFFSET_T
|
||||
@ -19,12 +20,14 @@
|
||||
#if defined(CURL_AT_LEAST_VERSION) && CURL_AT_LEAST_VERSION(7, 61, 0)
|
||||
# define REQUEST_USE_CURL_TLSV13CL
|
||||
#endif
|
||||
#endif
|
||||
|
||||
namespace http
|
||||
{
|
||||
class RequestManager;
|
||||
class Request
|
||||
{
|
||||
#ifndef NOHTTP
|
||||
ByteString uri;
|
||||
ByteString response_body;
|
||||
|
||||
@ -53,6 +56,7 @@ namespace http
|
||||
std::condition_variable done_cv;
|
||||
|
||||
static size_t WriteDataHandler(char * ptr, size_t size, size_t count, void * userdata);
|
||||
#endif
|
||||
|
||||
public:
|
||||
Request(ByteString uri);
|
||||
|
@ -1,3 +1,4 @@
|
||||
#ifndef NOHTTP
|
||||
#include "RequestManager.h"
|
||||
|
||||
#include <iostream>
|
||||
@ -254,3 +255,4 @@ namespace http
|
||||
rt_cv.notify_one();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
@ -1,3 +1,4 @@
|
||||
#ifndef NOHTTP
|
||||
#ifndef REQUESTMANAGER_H
|
||||
#define REQUESTMANAGER_H
|
||||
|
||||
@ -53,3 +54,4 @@ namespace http
|
||||
}
|
||||
|
||||
#endif // REQUESTMANAGER_H
|
||||
#endif
|
||||
|
@ -1,5 +1,7 @@
|
||||
#include "FileBrowserActivity.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include "gui/interface/Label.h"
|
||||
#include "gui/interface/Textbox.h"
|
||||
#include "gui/interface/ScrollPanel.h"
|
||||
|
Loading…
Reference in New Issue
Block a user