diff --git a/SConscript b/SConscript index 0d89cb00d..46e225bd6 100644 --- a/SConscript +++ b/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']) diff --git a/src/client/Client.cpp b/src/client/Client.cpp index b6408eaf0..d0a806108 100644 --- a/src/client/Client.cpp +++ b/src/client/Client.cpp @@ -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; @@ -923,8 +925,10 @@ void Client::Shutdown() { alternateVersionCheckRequest->Cancel(); } - + +#ifndef NOHTTP http::RequestManager::Ref().Shutdown(); +#endif //Save config WritePrefs(); diff --git a/src/client/http/Request.cpp b/src/client/http/Request.cpp index ca328ab5a..ab0bf191a 100644 --- a/src/client/http/Request.cpp +++ b/src/client/http/Request.cpp @@ -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 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 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 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 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 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 g(rm_mutex); rm_canceled = true; } RequestManager::Ref().RemoveRequest(this); +#endif } ByteString Request::Simple(ByteString uri, int *status, std::map post_data) diff --git a/src/client/http/Request.h b/src/client/http/Request.h index 399085171..6f4181c51 100644 --- a/src/client/http/Request.h +++ b/src/client/http/Request.h @@ -2,11 +2,12 @@ #define REQUEST_H #include +#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 #include #include -#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); diff --git a/src/client/http/RequestManager.cpp b/src/client/http/RequestManager.cpp index 5ba90fd1c..126028f32 100644 --- a/src/client/http/RequestManager.cpp +++ b/src/client/http/RequestManager.cpp @@ -1,3 +1,4 @@ +#ifndef NOHTTP #include "RequestManager.h" #include @@ -254,3 +255,4 @@ namespace http rt_cv.notify_one(); } } +#endif diff --git a/src/client/http/RequestManager.h b/src/client/http/RequestManager.h index 3c2acb52f..9245df55a 100644 --- a/src/client/http/RequestManager.h +++ b/src/client/http/RequestManager.h @@ -1,3 +1,4 @@ +#ifndef NOHTTP #ifndef REQUESTMANAGER_H #define REQUESTMANAGER_H @@ -53,3 +54,4 @@ namespace http } #endif // REQUESTMANAGER_H +#endif diff --git a/src/gui/filebrowser/FileBrowserActivity.cpp b/src/gui/filebrowser/FileBrowserActivity.cpp index c0189c4bb..05fc4661d 100644 --- a/src/gui/filebrowser/FileBrowserActivity.cpp +++ b/src/gui/filebrowser/FileBrowserActivity.cpp @@ -1,5 +1,7 @@ #include "FileBrowserActivity.h" +#include + #include "gui/interface/Label.h" #include "gui/interface/Textbox.h" #include "gui/interface/ScrollPanel.h"