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