From aad73db128a851eb6a72435df79be0689870f09c Mon Sep 17 00:00:00 2001 From: Oreste Panaia Date: Mon, 22 Oct 2012 20:51:31 +0800 Subject: [PATCH] various changes for windows --- arangod/Actions/ActionDispatcherThread.h | 1 + arangod/Actions/RestActionHandler.cpp | 2 +- arangod/Ahuacatl/ahuacatl-ast-node.c | 2 +- arangod/Ahuacatl/ahuacatl-codegen.c | 5 +- arangod/Ahuacatl/ahuacatl-node.c | 8 +- arangod/Ahuacatl/ahuacatl-optimiser.c | 4 +- arangod/BitIndexes/bitarrayIndex.c | 4 +- arangod/PriorityQueue/pqueueindex.c | 1 + arangod/RestServer/ArangoServer.cpp | 13 +- arangod/RestServer/arango.cpp | 6 +- arangod/SkipLists/compare.h | 2 + arangod/V8Server/v8-actions.cpp | 1 + arangod/VocBase/compactor.c | 4 + arangod/VocBase/document-collection.c | 2 + arangod/VocBase/general-cursor.c | 4 +- arangosh/V8Client/arangoimp.cpp | 2 +- arangosh/V8Client/arangosh.cpp | 2 +- lib/ApplicationServer/ApplicationServer.cpp | 121 ++++++++++++-- .../{Initialise.cpp => InitialiseBasics.cpp} | 4 +- .../{Initialise.h => InitialiseBasics.h} | 4 +- .../{Random.cpp => RandomGenerator.cpp} | 93 ++++++++++- lib/Basics/{Random.h => RandomGenerator.h} | 11 +- lib/Basics/StringUtils.h | 2 +- lib/BasicsC/files.c | 28 ++-- lib/BasicsC/locks-win32.c | 4 +- lib/BasicsC/logging.c | 2 +- lib/BasicsC/operating-system.h | 20 ++- lib/BasicsC/random.c | 9 +- lib/BasicsC/threads-win32.c | 50 ++++++ lib/BasicsC/win-utils.c | 14 ++ lib/BasicsC/win-utils.h | 9 + lib/HttpServer/ApplicationEndpointServer.cpp | 4 +- lib/Makefile.files | 8 +- lib/ProgramOptions/program-options.c | 157 ++---------------- lib/ProgramOptions/program-options.h | 12 -- lib/Rest/AnyServer.cpp | 1 + lib/Rest/HttpRequest.cpp | 1 - lib/Rest/HttpRequest.h | 2 + .../{Initialise.cpp => InitialiseRest.cpp} | 4 +- lib/Rest/{Initialise.h => InitialiseRest.h} | 4 +- lib/Rest/SslInterface.cpp | 2 +- lib/Rest/SslInterface.h | 2 +- ...Initialise.cpp => InitialiseGenerator.cpp} | 4 +- .../{Initialise.h => InitialiseGenerator.h} | 4 +- lib/Scheduler/ApplicationScheduler.cpp | 5 +- lib/Scheduler/Task.cpp | 1 + 46 files changed, 409 insertions(+), 236 deletions(-) rename lib/Basics/{Initialise.cpp => InitialiseBasics.cpp} (96%) rename lib/Basics/{Initialise.h => InitialiseBasics.h} (96%) rename lib/Basics/{Random.cpp => RandomGenerator.cpp} (87%) rename lib/Basics/{Random.h => RandomGenerator.h} (95%) rename lib/Rest/{Initialise.cpp => InitialiseRest.cpp} (98%) rename lib/Rest/{Initialise.h => InitialiseRest.h} (96%) rename lib/ResultGenerator/{Initialise.cpp => InitialiseGenerator.cpp} (96%) rename lib/ResultGenerator/{Initialise.h => InitialiseGenerator.h} (97%) diff --git a/arangod/Actions/ActionDispatcherThread.h b/arangod/Actions/ActionDispatcherThread.h index 8f45abaeca..775492becf 100644 --- a/arangod/Actions/ActionDispatcherThread.h +++ b/arangod/Actions/ActionDispatcherThread.h @@ -30,6 +30,7 @@ #include "Dispatcher/DispatcherThread.h" + // ----------------------------------------------------------------------------- // --SECTION-- class ActionDispatcherThread // ----------------------------------------------------------------------------- diff --git a/arangod/Actions/RestActionHandler.cpp b/arangod/Actions/RestActionHandler.cpp index 99f326b8b2..df29881719 100644 --- a/arangod/Actions/RestActionHandler.cpp +++ b/arangod/Actions/RestActionHandler.cpp @@ -27,7 +27,7 @@ #include "RestActionHandler.h" -#include "Actions/ActionDispatcherThread.h" +// #include "Actions/ActionDispatcherThread.h" #include "Actions/actions.h" #include "Basics/StringUtils.h" #include "Rest/HttpRequest.h" diff --git a/arangod/Ahuacatl/ahuacatl-ast-node.c b/arangod/Ahuacatl/ahuacatl-ast-node.c index 0d745ffd10..ac6ab74328 100644 --- a/arangod/Ahuacatl/ahuacatl-ast-node.c +++ b/arangod/Ahuacatl/ahuacatl-ast-node.c @@ -998,7 +998,7 @@ bool TRI_PushArrayAql (TRI_aql_context_t* const context, /// @brief get the boolean value of a node //////////////////////////////////////////////////////////////////////////////// -inline bool TRI_GetBooleanNodeValueAql (const TRI_aql_node_t* const node) { +bool TRI_GetBooleanNodeValueAql (const TRI_aql_node_t* const node) { assert(node); assert(node->_type == TRI_AQL_NODE_VALUE); diff --git a/arangod/Ahuacatl/ahuacatl-codegen.c b/arangod/Ahuacatl/ahuacatl-codegen.c index b9b7a090f3..4c830c7b0e 100644 --- a/arangod/Ahuacatl/ahuacatl-codegen.c +++ b/arangod/Ahuacatl/ahuacatl-codegen.c @@ -32,6 +32,7 @@ #include "Ahuacatl/ahuacatl-collections.h" #include "Ahuacatl/ahuacatl-index.h" #include "Ahuacatl/ahuacatl-functions.h" +#include "Ahuacatl/ahuacatl-node.h" #include "Ahuacatl/ahuacatl-scope.h" // ----------------------------------------------------------------------------- @@ -423,7 +424,7 @@ static TRI_aql_scope_e NextScopeType (TRI_aql_codegen_js_t* const generator, static void StartScope (TRI_aql_codegen_js_t* const generator, TRI_string_buffer_t* const buffer, - const TRI_aql_scope_e const type, + const TRI_aql_scope_e type, const TRI_aql_codegen_register_t listRegister, const TRI_aql_codegen_register_t keyRegister, const TRI_aql_codegen_register_t ownRegister, @@ -2102,7 +2103,7 @@ static void ProcessFilter (TRI_aql_codegen_js_t* const generator, /// this is a dispatcher function only //////////////////////////////////////////////////////////////////////////////// -static void ProcessNode (TRI_aql_codegen_js_t* generator, const TRI_aql_node_t* const node) { +static void ProcessNode (TRI_aql_codegen_js_t* const generator, const TRI_aql_node_t* const node) { if (node == NULL) { return; } diff --git a/arangod/Ahuacatl/ahuacatl-node.c b/arangod/Ahuacatl/ahuacatl-node.c index 0d64d42634..7e5c3ac5cb 100644 --- a/arangod/Ahuacatl/ahuacatl-node.c +++ b/arangod/Ahuacatl/ahuacatl-node.c @@ -36,7 +36,7 @@ /// @{ //////////////////////////////////////////////////////////////////////////////// -inline bool TRI_IsTopLevelTypeAql (const TRI_aql_node_type_e type) { +bool TRI_IsTopLevelTypeAql (const TRI_aql_node_type_e type) { if (type == TRI_AQL_NODE_SCOPE_START || type == TRI_AQL_NODE_SCOPE_END || type == TRI_AQL_NODE_SUBQUERY || @@ -193,7 +193,7 @@ const char* TRI_NodeNameAql (const TRI_aql_node_type_e type) { /// @brief return true if a node is a list node //////////////////////////////////////////////////////////////////////////////// -inline bool TRI_IsListNodeAql (const TRI_aql_node_t* const node) { +bool TRI_IsListNodeAql (const TRI_aql_node_t* const node) { return (node->_type == TRI_AQL_NODE_LIST); } @@ -245,7 +245,7 @@ bool TRI_IsConstantValueNodeAql (const TRI_aql_node_t* const node) { /// @brief checks if a node value is numeric //////////////////////////////////////////////////////////////////////////////// -inline bool TRI_IsNumericValueNodeAql (const TRI_aql_node_t* const node) { +bool TRI_IsNumericValueNodeAql (const TRI_aql_node_t* const node) { assert(node); if (node->_type != TRI_AQL_NODE_VALUE) { @@ -260,7 +260,7 @@ inline bool TRI_IsNumericValueNodeAql (const TRI_aql_node_t* const node) { /// @brief checks if a node value is boolean //////////////////////////////////////////////////////////////////////////////// -inline bool TRI_IsBooleanValueNodeAql (const TRI_aql_node_t* const node) { +bool TRI_IsBooleanValueNodeAql (const TRI_aql_node_t* const node) { assert(node); return (node->_type == TRI_AQL_NODE_VALUE && node->_value._type == TRI_AQL_TYPE_BOOL); diff --git a/arangod/Ahuacatl/ahuacatl-optimiser.c b/arangod/Ahuacatl/ahuacatl-optimiser.c index aa52550d6f..c714224028 100644 --- a/arangod/Ahuacatl/ahuacatl-optimiser.c +++ b/arangod/Ahuacatl/ahuacatl-optimiser.c @@ -514,6 +514,7 @@ static TRI_aql_node_t* OptimiseUnaryArithmeticOperation (TRI_aql_context_t* cons TRI_SetErrorContextAql(context, TRI_ERROR_QUERY_INVALID_ARITHMETIC_VALUE, NULL); return node; } + if (node->_type == TRI_AQL_NODE_OPERATOR_UNARY_PLUS) { // + number => number @@ -725,7 +726,7 @@ static TRI_aql_node_t* OptimiseBinaryArithmeticOperation (TRI_aql_context_t* con isEligibleLhs = TRI_IsConstantValueNodeAql(lhs); isEligibleRhs = TRI_IsConstantValueNodeAql(rhs); - + if (isEligibleLhs && !TRI_IsNumericValueNodeAql(lhs)) { // node is not a numeric value => error TRI_SetErrorContextAql(context, TRI_ERROR_QUERY_INVALID_ARITHMETIC_VALUE, NULL); @@ -739,6 +740,7 @@ static TRI_aql_node_t* OptimiseBinaryArithmeticOperation (TRI_aql_context_t* con return node; } + if (!isEligibleLhs || !isEligibleRhs) { return node; } diff --git a/arangod/BitIndexes/bitarrayIndex.c b/arangod/BitIndexes/bitarrayIndex.c index f43241d31c..ee95a1af38 100755 --- a/arangod/BitIndexes/bitarrayIndex.c +++ b/arangod/BitIndexes/bitarrayIndex.c @@ -891,7 +891,9 @@ static bool isEqualJson(TRI_json_t* left, TRI_json_t* right) { default: { assert(false); } - } + } + + return false; // shut the vc++ up } diff --git a/arangod/PriorityQueue/pqueueindex.c b/arangod/PriorityQueue/pqueueindex.c index 681036d6bf..c87672aa5d 100755 --- a/arangod/PriorityQueue/pqueueindex.c +++ b/arangod/PriorityQueue/pqueueindex.c @@ -978,6 +978,7 @@ static int CompareShapeTypes (const TRI_shaped_json_t* left, const TRI_shaped_js } assert(false); + return 0; // shut the vc++ up } diff --git a/arangod/RestServer/ArangoServer.cpp b/arangod/RestServer/ArangoServer.cpp index 6550fcdb1f..d9c2d12c29 100644 --- a/arangod/RestServer/ArangoServer.cpp +++ b/arangod/RestServer/ArangoServer.cpp @@ -47,7 +47,7 @@ #include "Admin/RestHandlerCreator.h" #include "Basics/ProgramOptions.h" #include "Basics/ProgramOptionsDescription.h" -#include "Basics/Random.h" +#include "Basics/RandomGenerator.h" #include "Basics/Utf8Helper.h" #include "BasicsC/files.h" #include "BasicsC/init.h" @@ -59,7 +59,7 @@ #include "HttpServer/RedirectHandler.h" #include "Logger/Logger.h" -#include "Rest/Initialise.h" +#include "Rest/InitialiseRest.h" #include "Rest/OperationMode.h" #include "RestHandler/ConnectionStatisticsHandler.h" #include "RestHandler/RequestStatisticsHandler.h" @@ -68,7 +68,11 @@ #include "RestHandler/RestEdgeHandler.h" #include "RestHandler/RestImportHandler.h" #include "Scheduler/ApplicationScheduler.h" + +#ifndef _WIN32 #include "V8/V8LineEditor.h" +#endif + #include "V8/v8-conv.h" #include "V8/v8-utils.h" #include "V8Server/ApplicationV8.h" @@ -245,7 +249,7 @@ void ArangoServer::buildApplicationServer () { _applicationServer = new ApplicationServer("arangod", "[] ", TRIAGENS_VERSION); _applicationServer->setSystemConfigFile("arangod.conf"); - _applicationServer->setUserConfigFile(".arango/arangod.conf"); + _applicationServer->setUserConfigFile(string(".arango") + string(1,TRI_DIR_SEPARATOR_CHAR) + string("arangod.conf") ); // ............................................................................. // multi-threading scheduler and dispatcher @@ -792,6 +796,7 @@ int ArangoServer::executeConsole (OperationMode::server_operation_mode_e mode) { // ............................................................................. case OperationMode::MODE_CONSOLE: { +#ifndef _WIN32 context->_context->Global()->Set(v8::String::New("DATABASEPATH"), v8::String::New(_databasePath.c_str()), v8::ReadOnly); context->_context->Global()->Set(v8::String::New("VALGRIND"), _runningOnValgrind ? v8::True() : v8::False(), v8::ReadOnly); V8LineEditor* console = new V8LineEditor(context->_context, ".arango"); @@ -830,7 +835,7 @@ int ArangoServer::executeConsole (OperationMode::server_operation_mode_e mode) { console->close(); delete console; - +#endif break; } diff --git a/arangod/RestServer/arango.cpp b/arangod/RestServer/arango.cpp index dd2cdc3575..83566f3bcb 100644 --- a/arangod/RestServer/arango.cpp +++ b/arangod/RestServer/arango.cpp @@ -28,7 +28,7 @@ #include "Basics/Common.h" #include "RestServer/ArangoServer.h" -#include "ResultGenerator/Initialise.h" +#include "ResultGenerator/InitialiseGenerator.h" using namespace triagens; using namespace triagens::rest; @@ -48,6 +48,8 @@ using namespace triagens::arango; //////////////////////////////////////////////////////////////////////////////// int main (int argc, char* argv[]) { + int res = 0; + TRIAGENS_RESULT_GENERATOR_INITIALISE(argc, argv); TRI_InitialiseVocBase(); @@ -55,7 +57,7 @@ int main (int argc, char* argv[]) { ArangoServer server(argc, argv); - int res = server.start(); + res = server.start(); // shutdown diff --git a/arangod/SkipLists/compare.h b/arangod/SkipLists/compare.h index c2d44c3c03..6331042a54 100755 --- a/arangod/SkipLists/compare.h +++ b/arangod/SkipLists/compare.h @@ -692,6 +692,8 @@ static int CompareShapeTypes (const TRI_shaped_json_t* left, const TRI_shaped_js } // end of switch (leftType) assert(false); + + return 0; //shut the vc++ up } diff --git a/arangod/V8Server/v8-actions.cpp b/arangod/V8Server/v8-actions.cpp index 0b3d83cb96..4cc7411560 100644 --- a/arangod/V8Server/v8-actions.cpp +++ b/arangod/V8Server/v8-actions.cpp @@ -45,6 +45,7 @@ using namespace triagens::basics; using namespace triagens::rest; using namespace triagens::arango; + // ----------------------------------------------------------------------------- // --SECTION-- forward declarations // ----------------------------------------------------------------------------- diff --git a/arangod/VocBase/compactor.c b/arangod/VocBase/compactor.c index d4353cb59f..0a17fdfe8b 100644 --- a/arangod/VocBase/compactor.c +++ b/arangod/VocBase/compactor.c @@ -25,6 +25,10 @@ /// @author Copyright 2011, triagens GmbH, Cologne, Germany //////////////////////////////////////////////////////////////////////////////// +#ifdef _WIN32 +#include "BasicsC/win-utils.h" +#endif + #include "compactor.h" #include "BasicsC/conversions.h" diff --git a/arangod/VocBase/document-collection.c b/arangod/VocBase/document-collection.c index 096314cfb3..268e4b5ccc 100755 --- a/arangod/VocBase/document-collection.c +++ b/arangod/VocBase/document-collection.c @@ -3623,6 +3623,8 @@ static int GeoIndexFromJson (TRI_document_collection_t* sim, else { assert(false); } + + return 0; // shut the vc++ up } //////////////////////////////////////////////////////////////////////////////// diff --git a/arangod/VocBase/general-cursor.c b/arangod/VocBase/general-cursor.c index 27680ea823..80169dcaef 100644 --- a/arangod/VocBase/general-cursor.c +++ b/arangod/VocBase/general-cursor.c @@ -225,7 +225,7 @@ TRI_general_cursor_t* TRI_CreateGeneralCursor (TRI_general_cursor_result_t* resu /// @brief exclusively lock a general cursor //////////////////////////////////////////////////////////////////////////////// -inline void TRI_LockGeneralCursor (TRI_general_cursor_t* const cursor) { +void TRI_LockGeneralCursor (TRI_general_cursor_t* const cursor) { TRI_LockMutex(&cursor->_lock); } @@ -233,7 +233,7 @@ inline void TRI_LockGeneralCursor (TRI_general_cursor_t* const cursor) { /// @brief unlock a general cursor //////////////////////////////////////////////////////////////////////////////// -inline void TRI_UnlockGeneralCursor (TRI_general_cursor_t* const cursor) { +void TRI_UnlockGeneralCursor (TRI_general_cursor_t* const cursor) { assert(cursor); TRI_UnlockMutex(&cursor->_lock); diff --git a/arangosh/V8Client/arangoimp.cpp b/arangosh/V8Client/arangoimp.cpp index 75259cf948..1939960e41 100644 --- a/arangosh/V8Client/arangoimp.cpp +++ b/arangosh/V8Client/arangoimp.cpp @@ -43,7 +43,7 @@ #include "ImportHelper.h" #include "Logger/Logger.h" #include "Rest/Endpoint.h" -#include "Rest/Initialise.h" +#include "Rest/InitialiseRest.h" #include "SimpleHttpClient/SimpleHttpClient.h" #include "SimpleHttpClient/SimpleHttpResult.h" #include "V8Client/V8ClientConnection.h" diff --git a/arangosh/V8Client/arangosh.cpp b/arangosh/V8Client/arangosh.cpp index 1da0a86a22..948e8deaf7 100644 --- a/arangosh/V8Client/arangosh.cpp +++ b/arangosh/V8Client/arangosh.cpp @@ -44,7 +44,7 @@ #include "BasicsC/init.h" #include "BasicsC/strings.h" #include "Rest/Endpoint.h" -#include "Rest/Initialise.h" +#include "Rest/InitialiseRest.h" #include "SimpleHttpClient/SimpleHttpClient.h" #include "SimpleHttpClient/SimpleHttpResult.h" #include "V8/JSLoader.h" diff --git a/lib/ApplicationServer/ApplicationServer.cpp b/lib/ApplicationServer/ApplicationServer.cpp index 94527e16af..8bb8f76bfd 100644 --- a/lib/ApplicationServer/ApplicationServer.cpp +++ b/lib/ApplicationServer/ApplicationServer.cpp @@ -38,7 +38,7 @@ #include "ApplicationServer/ApplicationFeature.h" #include "Basics/FileUtils.h" -#include "Basics/Random.h" +#include "Basics/RandomGenerator.h" #include "Basics/StringUtils.h" #include "Basics/delete_object.h" #include "BasicsC/conversions.h" @@ -106,6 +106,43 @@ string const ApplicationServer::OPTIONS_SERVER = "Server Options"; /// @brief constructor //////////////////////////////////////////////////////////////////////////////// +#ifdef _WIN32 +ApplicationServer::ApplicationServer (string const& name, string const& title, string const& version) + : _options(), + _description(), + _descriptionFile(), + _arguments(), + _features(), + _exitOnParentDeath(false), + _watchParent(0), + _stopping(0), + _name(name), + _title(title), + _version(version), + _configFile(), + _userConfigFile(), + _systemConfigFile(), + _systemConfigPath(), + _uid(), + _realUid(0), + _effectiveUid(0), + _gid(), + _realGid(0), + _effectiveGid(0), + _logApplicationName("triagens"), + _logHostName("-"), + _logFacility("-"), + _logLevel("info"), + _logFormat(), + _logSeverity("human"), + _logFile("+"), + _logPrefix(), + _logSyslog(), + _logThreadId(false), + _logLineNumber(false), + _randomGenerator(5) { +} +#else ApplicationServer::ApplicationServer (string const& name, string const& title, string const& version) : _options(), _description(), @@ -141,6 +178,7 @@ ApplicationServer::ApplicationServer (string const& name, string const& title, s _logLineNumber(false), _randomGenerator(3) { } +#endif //////////////////////////////////////////////////////////////////////////////// /// @brief destructor @@ -385,11 +423,29 @@ bool ApplicationServer::parse (int argc, try { switch (_randomGenerator) { - case 1: Random::selectVersion(Random::RAND_MERSENNE); break; - case 2: Random::selectVersion(Random::RAND_RANDOM); break; - case 3: Random::selectVersion(Random::RAND_URANDOM); break; - case 4: Random::selectVersion(Random::RAND_COMBINED); break; - default: break; + case 1: { + Random::selectVersion(Random::RAND_MERSENNE); + break; + } + case 2: { + Random::selectVersion(Random::RAND_RANDOM); + break; + } + case 3: { + Random::selectVersion(Random::RAND_URANDOM); + break; + } + case 4: { + Random::selectVersion(Random::RAND_COMBINED); + break; + } + case 5: { + Random::selectVersion(Random::RAND_WIN32); + break; + } + default: { + break; + } } } catch (...) { @@ -398,6 +454,7 @@ bool ApplicationServer::parse (int argc, exit(EXIT_FAILURE); } + for (vector::iterator i = _features.begin(); i != _features.end(); ++i) { ok = (*i)->parsePhase2(_options); @@ -845,12 +902,56 @@ bool ApplicationServer::readConfigurationFile () { // nothing has been specified on the command line regarding configuration file if (! _userConfigFile.empty()) { + // ......................................................................... // first attempt to obtain a default configuration file from the users home directory - string homeDir = string(getenv("HOME")); + // ......................................................................... + + // ......................................................................... + // Under windows there is no 'HOME' directory as such so getenv("HOME") + // may return NULL -- which it does under windows + // A safer approach below + // ......................................................................... + + string homeDir; + string homeEnv; + const char* envResult; + +#ifdef _WIN32 + string homeDrive; + string homePath; + + homeEnv = string("%HOMEDRIVE% and/or %HOMEPATH%"); + + envResult = getenv("HOMEDRIVE"); + if (envResult != 0) { + homeDrive = string(envResult); + } + + envResult = getenv("HOMEPATH"); + if (envResult != 0) { + homePath = string(envResult); + } + + if (! homeDrive.empty() && ! homePath.empty()) { + homeDir = homeDrive + homePath; + } + else { + homeDir = string(""); + } +#else + homeEnv = string("$HOME"); + envResult = getenv("HOME"); + if (envResult != 0) { + homeDir = string(envResult); + } + else { + homeDir = string(""); + } +#endif if (! homeDir.empty()) { - if (homeDir[homeDir.size() - 1] != '/') { - homeDir += "/" + _userConfigFile; + if (homeDir[homeDir.size() - 1] != TRI_DIR_SEPARATOR_CHAR) { + homeDir += TRI_DIR_SEPARATOR_CHAR + _userConfigFile; } else { homeDir += _userConfigFile; @@ -876,7 +977,7 @@ bool ApplicationServer::readConfigurationFile () { } } else { - LOGGER_DEBUG << "no user init file, $HOME is empty"; + LOGGER_DEBUG << "no user init file, " << homeEnv << " is empty"; } } diff --git a/lib/Basics/Initialise.cpp b/lib/Basics/InitialiseBasics.cpp similarity index 96% rename from lib/Basics/Initialise.cpp rename to lib/Basics/InitialiseBasics.cpp index 1bf3dbb7c5..d77fa125b4 100644 --- a/lib/Basics/Initialise.cpp +++ b/lib/Basics/InitialiseBasics.cpp @@ -25,7 +25,7 @@ /// @author Copyright 2009-2012, triAGENS GmbH, Cologne, Germany //////////////////////////////////////////////////////////////////////////////// -#include "Basics/Initialise.h" +#include "Basics/InitialiseBasics.h" #include "BasicsC/init.h" #include "BasicsC/error.h" @@ -33,7 +33,7 @@ #include "BasicsC/random.h" #include "Logger/Logger.h" -#include "Basics/Random.h" +#include "Basics/RandomGenerator.h" #ifdef TRI_BROKEN_CXA_GUARD #include diff --git a/lib/Basics/Initialise.h b/lib/Basics/InitialiseBasics.h similarity index 96% rename from lib/Basics/Initialise.h rename to lib/Basics/InitialiseBasics.h index ce9e365475..2503c67fde 100644 --- a/lib/Basics/Initialise.h +++ b/lib/Basics/InitialiseBasics.h @@ -25,8 +25,8 @@ /// @author Copyright 2009-2012, triAGENS GmbH, Cologne, Germany //////////////////////////////////////////////////////////////////////////////// -#ifndef TRIAGENS_BASICS_INITIALISE_H -#define TRIAGENS_BASICS_INITIALISE_H 1 +#ifndef TRIAGENS_BASICS_INITIALISE_BASICS_H +#define TRIAGENS_BASICS_INITIALISE_BASICS_H 1 #include "Basics/Common.h" diff --git a/lib/Basics/Random.cpp b/lib/Basics/RandomGenerator.cpp similarity index 87% rename from lib/Basics/Random.cpp rename to lib/Basics/RandomGenerator.cpp index 8df09aa2c3..18bf8b384d 100644 --- a/lib/Basics/Random.cpp +++ b/lib/Basics/RandomGenerator.cpp @@ -26,7 +26,7 @@ /// @author Copyright 2009-2012, triAGENS GmbH, Cologne, Germany //////////////////////////////////////////////////////////////////////////////// -#include "Random.h" +#include "RandomGenerator.h" #include "BasicsC/mersenne.h" #include "BasicsC/socket-utils.h" @@ -235,11 +235,64 @@ namespace RandomHelper { uint32_t rseed; }; + template + class RandomDeviceWin32 : public RandomDevice { +#ifndef _WIN32 + public: + RandomDeviceWin32 () { assert(false); } + ~RandomDeviceWin32 () {} + uint32_t random () { return 0;} +#else + public: + RandomDeviceWin32 () : cryptoHandle(0), pos(0) { + CryptAcquireContext(&cryptoHandle, NULL, NULL, PROV_RSA_FULL, 0); + if (cryptoHandle == 0) { + THROW_INTERNAL_ERROR("cannot create cryptographic windows handle"); + } + fillBuffer(); + } + ~RandomDeviceWin32 () { + if (cryptoHandle != 0) { + CryptReleaseContext(cryptoHandle, 0); + } + } + + + uint32_t random () { + if (pos >= N) { + fillBuffer(); + } + + return buffer[pos++]; + } + + private: + void fillBuffer () { + size_t n = sizeof(buffer); + BYTE* ptr = reinterpret_cast(&buffer); + + // fill the buffer with random characters + int result = CryptGenRandom(cryptoHandle, n, ptr); + if (result == 0) { + LOGGER_FATAL << "read on random device failed: nothing read"; + THROW_INTERNAL_ERROR("read on random device failed"); + } + pos = 0; + } + + private: + HCRYPTPROV cryptoHandle; + uint32_t buffer[N]; + size_t pos; +#endif + }; + RandomDevice* randomDevice = 0; RandomDevice* urandomDevice = 0; RandomDevice* combinedDevice = 0; + RandomDevice* win32Device = 0; } // ----------------------------------------------------------------------------- @@ -391,6 +444,17 @@ namespace triagens { }; + // RANDOM DEVICE + struct UniformIntegerWin32 : public UniformIntegerImpl, private RandomHelper::UniformGenerator { + UniformIntegerWin32 (RandomHelper::RandomDevice* device) : RandomHelper::UniformGenerator(device) { + } + + int32_t random (int32_t left, int32_t right) { + return RandomHelper::UniformGenerator::random(left, right); + } + }; + + // current implementation (see version at the top of the file) UniformIntegerImpl * uniformInteger = new UniformIntegerMersenne; @@ -461,6 +525,7 @@ namespace triagens { // ----------------------------------------------------------------------------- random_e selectVersion (random_e newVersion) { + MUTEX_LOCKER(RandomLock); random_e oldVersion = version; @@ -471,12 +536,15 @@ namespace triagens { uniformInteger = 0; } + switch (version) { - case RAND_MERSENNE: + + case RAND_MERSENNE: { uniformInteger = new UniformIntegerMersenne; break; + } - case RAND_RANDOM: + case RAND_RANDOM: { if (RandomHelper::randomDevice == 0) { RandomHelper::randomDevice = new RandomHelper::RandomDeviceDirect<1024>("/dev/random"); } @@ -484,8 +552,9 @@ namespace triagens { uniformInteger = new UniformIntegerRandom(RandomHelper::randomDevice); break; + } - case RAND_URANDOM: + case RAND_URANDOM: { if (RandomHelper::urandomDevice == 0) { RandomHelper::urandomDevice = new RandomHelper::RandomDeviceDirect<1024>("/dev/urandom"); } @@ -493,8 +562,9 @@ namespace triagens { uniformInteger = new UniformIntegerRandom(RandomHelper::urandomDevice); break; + } - case RAND_COMBINED: + case RAND_COMBINED: { if (RandomHelper::combinedDevice == 0) { RandomHelper::combinedDevice = new RandomHelper::RandomDeviceCombined<600>("/dev/random"); } @@ -502,9 +572,20 @@ namespace triagens { uniformInteger = new UniformIntegerRandom(RandomHelper::combinedDevice); break; + } - default: + case RAND_WIN32: { + if (RandomHelper::win32Device == 0) { + RandomHelper::win32Device = new RandomHelper::RandomDeviceWin32<1024>(); + } + uniformInteger = new UniformIntegerWin32(RandomHelper::win32Device); + break; + } + + default: { THROW_INTERNAL_ERROR("unknown random generator"); + } + } return oldVersion; diff --git a/lib/Basics/Random.h b/lib/Basics/RandomGenerator.h similarity index 95% rename from lib/Basics/Random.h rename to lib/Basics/RandomGenerator.h index a46447f658..0af20bbf83 100644 --- a/lib/Basics/Random.h +++ b/lib/Basics/RandomGenerator.h @@ -26,11 +26,15 @@ /// @author Copyright 2009-2012, triAGENS GmbH, Cologne, Germany //////////////////////////////////////////////////////////////////////////////// -#ifndef TRIAGENS_BASICS_RANDOM_H -#define TRIAGENS_BASICS_RANDOM_H 1 +#ifndef TRIAGENS_BASICS_RANDOM_GENERATOR_H +#define TRIAGENS_BASICS_RANDOM_GENERATOR_H 1 #include "Basics/Common.h" +#ifdef _WIN32 +#include +#endif + namespace triagens { namespace basics { @@ -48,7 +52,8 @@ namespace triagens { RAND_MERSENNE = 1, RAND_RANDOM = 2, RAND_URANDOM = 3, - RAND_COMBINED = 4 + RAND_COMBINED = 4, + RAND_WIN32 = 5 // uses the built in cryptographic services offered and recommended by microsoft (e.g. CryptGenKey(...) ) }; diff --git a/lib/Basics/StringUtils.h b/lib/Basics/StringUtils.h index 75d48ffb50..e325b125a4 100644 --- a/lib/Basics/StringUtils.h +++ b/lib/Basics/StringUtils.h @@ -22,7 +22,7 @@ /// Copyright holder is triAGENS GmbH, Cologne, Germany /// /// @author Dr. Frank Celler -/// @author Dr. Oreste Costa-Panaia +/// @author Dr. O /// @author Copyright 2005-2012, triAGENS GmbH, Cologne, Germany //////////////////////////////////////////////////////////////////////////////// diff --git a/lib/BasicsC/files.c b/lib/BasicsC/files.c index cd7da8f099..e0b3ff1adc 100644 --- a/lib/BasicsC/files.c +++ b/lib/BasicsC/files.c @@ -323,7 +323,7 @@ char* TRI_Dirname (char const* path) { m = 0; if (1 < n) { - if (path[n - 1] == '/') { + if (path[n - 1] == TRI_DIR_SEPARATOR_CHAR) { m = 1; } } @@ -331,8 +331,8 @@ char* TRI_Dirname (char const* path) { if (n == 0) { return TRI_DuplicateString("."); } - else if (n == 1 && *path == '/') { - return TRI_DuplicateString("/"); + else if (n == 1 && *path == TRI_DIR_SEPARATOR_CHAR) { + return TRI_DuplicateString(TRI_DIR_SEPARATOR_STR); } else if (n - m == 1 && *path == '.') { return TRI_DuplicateString("."); @@ -342,14 +342,14 @@ char* TRI_Dirname (char const* path) { } for (p = path + (n - m - 1); path < p; --p) { - if (*p == '/') { + if (*p == TRI_DIR_SEPARATOR_CHAR) { break; } } if (path == p) { - if (*p == '/') { - return TRI_DuplicateString("/"); + if (*p == TRI_DIR_SEPARATOR_CHAR) { + return TRI_DuplicateString(TRI_DIR_SEPARATOR_STR); } else { return TRI_DuplicateString("."); @@ -374,7 +374,7 @@ char* TRI_Basename (char const* path) { m = 0; if (1 < n) { - if (path[n - 1] == '/') { + if (path[n - 1] == TRI_DIR_SEPARATOR_CHAR) { m = 1; } } @@ -382,7 +382,7 @@ char* TRI_Basename (char const* path) { if (n == 0) { return TRI_DuplicateString(""); } - else if (n == 1 && *path == '/') { + else if (n == 1 && *path == TRI_DIR_SEPARATOR_CHAR) { return TRI_DuplicateString(""); } else if (n - m == 1 && *path == '.') { @@ -393,13 +393,13 @@ char* TRI_Basename (char const* path) { } for (p = path + (n - m - 1); path < p; --p) { - if (*p == '/') { + if (*p == TRI_DIR_SEPARATOR_CHAR) { break; } } if (path == p) { - if (*p == '/') { + if (*p == TRI_DIR_SEPARATOR_CHAR) { return TRI_DuplicateString2(path + 1, n - m); } } @@ -414,7 +414,7 @@ char* TRI_Basename (char const* path) { //////////////////////////////////////////////////////////////////////////////// char* TRI_Concatenate2File (char const* path, char const* name) { - return TRI_Concatenate3String(path, "/", name); + return TRI_Concatenate3String(path, TRI_DIR_SEPARATOR_STR, name); } //////////////////////////////////////////////////////////////////////////////// @@ -422,7 +422,7 @@ char* TRI_Concatenate2File (char const* path, char const* name) { //////////////////////////////////////////////////////////////////////////////// char* TRI_Concatenate3File (char const* path1, char const* path2, char const* name) { - return TRI_Concatenate5String(path1, "/", path2, "/", name); + return TRI_Concatenate5String(path1, TRI_DIR_SEPARATOR_STR, path2, TRI_DIR_SEPARATOR_STR, name); } //////////////////////////////////////////////////////////////////////////////// @@ -1047,10 +1047,10 @@ char* TRI_LocateBinaryPath (char const* argv0) { char* binaryPath = NULL; size_t i; - // check if name contains a '/' + // check if name contains a '/' ( or '\' for windows) p = argv0; - for (; *p && *p != '/'; ++p) { + for (; *p && *p != TRI_DIR_SEPARATOR_CHAR; ++p) { } // contains a path diff --git a/lib/BasicsC/locks-win32.c b/lib/BasicsC/locks-win32.c index ced9fc312e..e604cca26a 100644 --- a/lib/BasicsC/locks-win32.c +++ b/lib/BasicsC/locks-win32.c @@ -300,6 +300,7 @@ void TRI_ReadLockReadWriteLock (TRI_read_write_lock_t* lock) { LeaveCriticalSection(&lock->_lockReaders); if (WaitForSingleObject(lock->_writerEvent, 0) != WAIT_OBJECT_0) { + exit(EXIT_FAILURE); EnterCriticalSection(&lock->_lockReaders); DecrementReaders(lock); LeaveCriticalSection(&lock->_lockReaders); @@ -335,7 +336,7 @@ void TRI_ReadUnlockReadWriteLock (TRI_read_write_lock_t* lock) { exit(EXIT_FAILURE); } - LeaveCriticalSection(&lock->_lockWriter); + LeaveCriticalSection(&lock->_lockReaders); } //////////////////////////////////////////////////////////////////////////////// @@ -359,6 +360,7 @@ void TRI_WriteLockReadWriteLock (TRI_read_write_lock_t* lock) { //////////////////////////////////////////////////////////////////////////////// void TRI_WriteUnlockReadWriteLock (TRI_read_write_lock_t* lock) { + //printf("%s:%s:%s:%d:%s:%d\n","oreste",__FILE__,__FUNCTION__,__LINE__,"!!!!!!!!!!!!!!!!!",(uint64_t)(lock)); EnterCriticalSection(&lock->_lockReaders); // a write lock eists diff --git a/lib/BasicsC/logging.c b/lib/BasicsC/logging.c index f64331462a..8c32a83dd1 100644 --- a/lib/BasicsC/logging.c +++ b/lib/BasicsC/logging.c @@ -29,7 +29,7 @@ #include "win-utils.h" #endif -#include "logging.h" +#include "BasicsC/logging.h" #ifdef TRI_ENABLE_SYSLOG #define SYSLOG_NAMES diff --git a/lib/BasicsC/operating-system.h b/lib/BasicsC/operating-system.h index b5c5412409..dc1c3cd40f 100644 --- a/lib/BasicsC/operating-system.h +++ b/lib/BasicsC/operating-system.h @@ -41,7 +41,6 @@ /// @{ //////////////////////////////////////////////////////////////////////////////// -#define TRI_DIR_SEPARATOR_CHAR '/' #define TRI_HAVE_GETGRGID 1 #define TRI_HAVE_GETPWNAM 1 #define TRI_HAVE_GETPWUID 1 @@ -67,6 +66,9 @@ #ifdef __APPLE__ +#define TRI_DIR_SEPARATOR_CHAR '/' +#define TRI_DIR_SEPARATOR_STR "/" + #define TRI_HAVE_POSIX 1 #define TRI_HAVE_DLFCN_H 1 @@ -163,6 +165,9 @@ #ifdef __CYGWIN__ +#define TRI_DIR_SEPARATOR_CHAR '/' +#define TRI_DIR_SEPARATOR_STR "/" + #define TRI_HAVE_POSIX 1 #define TRI_HAVE_DLFCN_H 1 @@ -238,6 +243,9 @@ #ifdef __linux__ +#define TRI_DIR_SEPARATOR_CHAR '/' +#define TRI_DIR_SEPARATOR_STR "/" + #define TRI_HAVE_POSIX 1 #define TRI_HAVE_DLFCN_H 1 @@ -347,6 +355,9 @@ #if defined(_WIN32) && defined(_MSC_VER) +#define TRI_DIR_SEPARATOR_CHAR '\\' +#define TRI_DIR_SEPARATOR_STR "\\" + #define _CRT_SECURE_NO_WARNINGS 1 #define _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES 1 @@ -450,6 +461,13 @@ typedef unsigned int bool; // ........................................................................... #define inline _inline +// ........................................................................... +// windows uses _alloca instead of alloca +// ........................................................................... +#define alloca _alloca + + + #endif //////////////////////////////////////////////////////////////////////////////// diff --git a/lib/BasicsC/random.c b/lib/BasicsC/random.c index bad67dbfae..8e0d720411 100644 --- a/lib/BasicsC/random.c +++ b/lib/BasicsC/random.c @@ -103,7 +103,7 @@ static unsigned long SeedRandom (void) { /// @brief generates a 16 bit random unsigned integer //////////////////////////////////////////////////////////////////////////////// -uint16_t TRI_UInt16Random () { +uint16_t TRI_UInt16Random (void) { #if RAND_MAX == 2147483647 return rand() & 0xFFFF; @@ -125,7 +125,7 @@ uint16_t TRI_UInt16Random () { /// @brief generates a 32 bit random unsigned integer //////////////////////////////////////////////////////////////////////////////// -uint32_t TRI_UInt32Random () { +uint32_t TRI_UInt32Random (void) { #if RAND_MAX == 2147483647 uint32_t l1; @@ -174,7 +174,7 @@ uint32_t TRI_UInt32Random () { /// @brief initialises the random components //////////////////////////////////////////////////////////////////////////////// -void TRI_InitialiseRandom () { +void TRI_InitialiseRandom (void) { if (Initialised) { return; } @@ -188,7 +188,7 @@ void TRI_InitialiseRandom () { /// @brief shut downs the logging components //////////////////////////////////////////////////////////////////////////////// -void TRI_ShutdownRandom () { +void TRI_ShutdownRandom (void) { if (! Initialised) { return; } @@ -196,6 +196,7 @@ void TRI_ShutdownRandom () { Initialised = false; } + //////////////////////////////////////////////////////////////////////////////// /// @} //////////////////////////////////////////////////////////////////////////////// diff --git a/lib/BasicsC/threads-win32.c b/lib/BasicsC/threads-win32.c index 5cf0178a78..a8ee1c566e 100644 --- a/lib/BasicsC/threads-win32.c +++ b/lib/BasicsC/threads-win32.c @@ -170,6 +170,25 @@ bool TRI_StartThread (TRI_thread_t* thread, const char* name, void (*starter)(v return true; } + +//////////////////////////////////////////////////////////////////////////////// +/// @brief attempts to stop/terminate a thread +//////////////////////////////////////////////////////////////////////////////// + +void TRI_StopThread(TRI_thread_t* thread) { + TerminateThread(thread,0); +} + + + +//////////////////////////////////////////////////////////////////////////////// +/// @brief waits for a thread to finish +//////////////////////////////////////////////////////////////////////////////// + +void TRI_DetachThread(TRI_thread_t* thread) { + // TODO: no native implementation +} + //////////////////////////////////////////////////////////////////////////////// /// @brief waits for a thread to finish //////////////////////////////////////////////////////////////////////////////// @@ -178,6 +197,37 @@ void TRI_JoinThread (TRI_thread_t* thread) { WaitForSingleObject(*thread, INFINITE); } + + +//////////////////////////////////////////////////////////////////////////////// +/// @brief sends a signal to a thread +//////////////////////////////////////////////////////////////////////////////// + +bool TRI_SignalThread (TRI_thread_t* thread, int signum) { + // TODO: NO NATIVE implementation of signals +} + + +//////////////////////////////////////////////////////////////////////////////// +/// @brief checks if this thread is the thread passed as a parameter +//////////////////////////////////////////////////////////////////////////////// + +bool TRI_IsSelfThread (TRI_thread_t* thread) { + return ( GetCurrentThreadId() == GetThreadId(thread) ); +} + + +//////////////////////////////////////////////////////////////////////////////// +/// @brief allow cancellation +//////////////////////////////////////////////////////////////////////////////// + +void TRI_AllowCancelation(void) { + // TODO: No native implementation of this +} + + + + //////////////////////////////////////////////////////////////////////////////// /// @} //////////////////////////////////////////////////////////////////////////////// diff --git a/lib/BasicsC/win-utils.c b/lib/BasicsC/win-utils.c index 26e2ffedbb..ab1018b5f3 100644 --- a/lib/BasicsC/win-utils.c +++ b/lib/BasicsC/win-utils.c @@ -26,13 +26,27 @@ //////////////////////////////////////////////////////////////////////////////// #include +#include #include "win-utils.h" +/* +#include +#include +#include +#include +#include +*/ + //////////////////////////////////////////////////////////////////////////////// /// @addtogroup Windows_Utilties /// @{ //////////////////////////////////////////////////////////////////////////////// +int ftruncate(int fd, long newSize) { + int result = _chsize(fd, newSize); + return result; +} + int getpagesize(void) { static int pageSize = 0; // only define it once diff --git a/lib/BasicsC/win-utils.h b/lib/BasicsC/win-utils.h index 4f24d039fa..d2919f31f3 100644 --- a/lib/BasicsC/win-utils.h +++ b/lib/BasicsC/win-utils.h @@ -55,6 +55,15 @@ extern "C" { /// @{ //////////////////////////////////////////////////////////////////////////////// + +// ............................................................................. +// windows equivalent of ftruncate (the truncation of an open file) is +// _chsize +// ............................................................................. + +int ftruncate (int, long); + + // ............................................................................. // windows does not have a function called getpagesize -- create one here // ............................................................................. diff --git a/lib/HttpServer/ApplicationEndpointServer.cpp b/lib/HttpServer/ApplicationEndpointServer.cpp index 39b41c4ef9..142208d022 100644 --- a/lib/HttpServer/ApplicationEndpointServer.cpp +++ b/lib/HttpServer/ApplicationEndpointServer.cpp @@ -31,7 +31,7 @@ #include "Basics/delete_object.h" #include "Basics/ssl-helper.h" -#include "Basics/Random.h" +#include "Basics/RandomGenerator.h" #include "Dispatcher/ApplicationDispatcher.h" #include "HttpServer/HttpHandlerFactory.h" #include "HttpServer/HttpServer.h" @@ -262,7 +262,7 @@ bool ApplicationEndpointServer::parsePhase2 (ProgramOptions& options) { } OperationMode::server_operation_mode_e mode = OperationMode::determineMode(options); - if (0 == _endpoints.size() && mode == OperationMode::MODE_SERVER) { + if (_endpoints.size() == 0 && mode == OperationMode::MODE_SERVER) { LOGGER_FATAL << "no endpoint has been specified, giving up"; cerr << "no endpoint has been specified, giving up\n"; LOGGER_INFO << "please use the '--server.endpoint' option"; diff --git a/lib/Makefile.files b/lib/Makefile.files index 4a0e0129a7..2c06fad738 100644 --- a/lib/Makefile.files +++ b/lib/Makefile.files @@ -13,13 +13,13 @@ lib_libarango_a_SOURCES = \ lib/Basics/ConditionVariable.cpp \ lib/Basics/Exceptions.cpp \ lib/Basics/FileUtils.cpp \ - lib/Basics/Initialise.cpp \ + lib/Basics/InitialiseBasics.cpp \ lib/Basics/LibraryLoader.cpp \ lib/Basics/Mutex.cpp \ lib/Basics/MutexLocker.cpp \ lib/Basics/ProgramOptions.cpp \ lib/Basics/ProgramOptionsDescription.cpp \ - lib/Basics/Random.cpp \ + lib/Basics/RandomGenerator.cpp \ lib/Basics/ReadLocker.cpp \ lib/Basics/ReadUnlocker.cpp \ lib/Basics/ReadWriteLock.cpp \ @@ -73,7 +73,7 @@ lib_libarango_a_SOURCES = \ lib/Rest/Handler.cpp \ lib/Rest/HttpRequest.cpp \ lib/Rest/HttpResponse.cpp \ - lib/Rest/Initialise.cpp \ + lib/Rest/InitialiseRest.cpp \ lib/Rest/JsonContainer.cpp \ lib/Rest/SslInterface.cpp \ lib/Rest/Url.cpp \ @@ -141,7 +141,7 @@ lib_libarango_fe_a_SOURCES = \ lib/HttpServer/RedirectHandler.cpp \ lib/HttpServer/ServiceUnavailableHandler.cpp \ lib/ResultGenerator/HtmlResultGenerator.cpp \ - lib/ResultGenerator/Initialise.cpp \ + lib/ResultGenerator/InitialiseGenerator.cpp \ lib/ResultGenerator/JsonResultGenerator.cpp \ lib/ResultGenerator/JsonXResultGenerator.cpp \ lib/ResultGenerator/OutputGenerator.cpp \ diff --git a/lib/ProgramOptions/program-options.c b/lib/ProgramOptions/program-options.c index a895dcd102..847f5a38da 100644 --- a/lib/ProgramOptions/program-options.c +++ b/lib/ProgramOptions/program-options.c @@ -156,23 +156,6 @@ typedef struct po_visit_functions_s { /// @{ //////////////////////////////////////////////////////////////////////////////// -#ifdef __TCHAR_DEFINED - -struct option * InitOptionStructure (struct option * option, - TCHAR const * name, - int hasArg, - int * flag, - int val) { - option->name = name; - option->has_arg = hasArg; - option->flag = flag; - option->val = 256 + val; - - return option; -} - -#else - struct option * InitOptionStructure (struct option * option, char const * name, int hasArg, @@ -186,8 +169,6 @@ struct option * InitOptionStructure (struct option * option, return option; } -#endif - //////////////////////////////////////////////////////////////////////////////// /// @brief frees a atomic option //////////////////////////////////////////////////////////////////////////////// @@ -229,13 +210,10 @@ static void CreateDoubleOption (po_double_t * desc, void const * input, void * o TRI_program_options_t * po; struct option doubleOpt; - po = output; + po = (TRI_program_options_t*) (output); -#ifdef __TCHAR_DEFINED InitOptionStructure(&doubleOpt, desc->base._name, 1, 0, po->_longopts._length); -#else - InitOptionStructure(&doubleOpt, desc->base._name, 1, 0, po->_longopts._length); -#endif + memset(&item, 0, sizeof(item)); item._desc = &desc->base; @@ -254,7 +232,7 @@ static void ParseFlagArg (char const * userarg, void * value) { assert(value != NULL); - flag = value; + flag = (po_flag_t*) (value); if (flag->_value != NULL) { if (userarg == NULL) { @@ -290,7 +268,7 @@ static void CreateFlagOption (po_flag_t * desc, void const * input, void * outpu TRI_program_options_t * po; struct option flagOpt; - po = output; + po = (TRI_program_options_t*) (output); if (desc->_value == 0) { InitOptionStructure(&flagOpt, desc->base._name, 0, 0, po->_longopts._length); @@ -318,7 +296,7 @@ static void ParseInt16Arg (char const * userarg, void * value) { assert(value != NULL); - desc = value; + desc = (po_int16_t*) (value); tmp = TRI_Int32String(userarg); if (TRI_errno() == TRI_ERROR_NO_ERROR) { @@ -340,7 +318,7 @@ void CreateInt16Option (po_int16_t * desc, void const * input, void * output) { TRI_program_options_t * po; struct option intOpt; - po = output; + po = (TRI_program_options_t*) (output); InitOptionStructure(&intOpt, desc->base._name, 1, 0, po->_longopts._length); @@ -363,7 +341,7 @@ static void ParseInt32Arg (char const * userarg, void * value) { assert(value != NULL); - desc = value; + desc = (po_int32_t*) (value); tmp = TRI_Int32String(userarg); if (TRI_errno() == TRI_ERROR_NO_ERROR) { @@ -380,7 +358,7 @@ void CreateInt32Option (po_int32_t * desc, void const * input, void * output) { TRI_program_options_t * po; struct option intOpt; - po = output; + po = (TRI_program_options_t*) (output); InitOptionStructure(&intOpt, desc->base._name, 1, 0, po->_longopts._length); @@ -403,7 +381,7 @@ static void ParseInt64Arg (char const * userarg, void * value) { assert(value != NULL); - desc = value; + desc = (po_int64_t*) (value); tmp = TRI_Int64String(userarg); if (TRI_errno() == TRI_ERROR_NO_ERROR) { @@ -420,7 +398,7 @@ static void CreateInt64Option (po_int64_t * desc, void const * input, void * out TRI_program_options_t * po; struct option intOpt; - po = output; + po = (TRI_program_options_t*) (output); InitOptionStructure(&intOpt, desc->base._name, 1, 0, po->_longopts._length); @@ -522,7 +500,7 @@ static void CreateUInt16Option (po_uint16_t * desc, void const * input, void * o TRI_program_options_t * po; struct option intOpt; - po = output; + po = (TRI_program_options_t*) (output); InitOptionStructure(&intOpt, desc->base._name, 1, 0, po->_longopts._length); @@ -562,7 +540,7 @@ static void CreateUInt32Option (po_uint32_t * desc, void const * input, void * o TRI_program_options_t * po; struct option intOpt; - po = output; + po = (TRI_program_options_t*) (output); InitOptionStructure(&intOpt, desc->base._name, 1, 0, po->_longopts._length); @@ -602,7 +580,7 @@ static void CreateUInt64Option (po_uint64_t * desc, void const * input, void * o TRI_program_options_t * po; struct option intOpt; - po = output; + po = (TRI_program_options_t*) (output); InitOptionStructure(&intOpt, desc->base._name, 1, 0, po->_longopts._length); @@ -639,7 +617,7 @@ static void CreateVectorStringOption (TRI_PO_vector_string_t * desc, void const TRI_program_options_t * po; struct option vectorOpt; - po = output; + po = (TRI_program_options_t*) (output); InitOptionStructure(&vectorOpt, desc->base._name, 1, 0, po->_longopts._length); @@ -995,7 +973,9 @@ TRI_program_options_t * TRI_CreateProgramOptions (TRI_PO_section_t * desc) { po_visit_functions_t optionBuilders; struct option nullOpt; - po = TRI_Allocate(TRI_CORE_MEM_ZONE, sizeof(TRI_program_options_t), false); + po = (TRI_program_options_t*) (TRI_Allocate(TRI_CORE_MEM_ZONE, sizeof(TRI_program_options_t), false)); + + // TODO: not safe since po could be 0 TRI_InitVector(&po->_longopts, TRI_CORE_MEM_ZONE, sizeof(struct option)); TRI_InitVector(&po->_items, TRI_CORE_MEM_ZONE, sizeof(TRI_PO_item_t)); @@ -1366,107 +1346,6 @@ char * TRI_UsagePODescription (TRI_PO_section_t * desc) { /// @brief parses a command line of arguments //////////////////////////////////////////////////////////////////////////////// -#ifdef __TCHAR_DEFINED - -bool TRI_ParseArgumentsProgramOptions (TRI_program_options_t * options, - int argc, - char ** argv) { - extern TCHAR *optarg; - extern int optind; - - TRI_string_buffer_t buffer; - TRI_PO_item_t * item; - char const* shortOptions; - size_t i; - int c; - int idx; - int maxIdx; - - TRI_set_errno(TRI_ERROR_NO_ERROR); - - TRI_InitStringBuffer(&buffer, TRI_CORE_MEM_ZONE); - - for (i = 0; i < options->_items._length; ++i) { - item = TRI_AtVector(&options->_items, i); - - if (item->_desc->_short != '\0') { - TRI_AppendCharStringBuffer(&buffer, item->_desc->_short); - - if (item->_desc->_type == TRI_PO_FLAG) { - po_flag_t* p; - - p = (po_flag_t*) item->_desc; - - if (p->_value != 0) { - TRI_AppendCharStringBuffer(&buffer, ':'); - } - } - else { - TRI_AppendCharStringBuffer(&buffer, ':'); - } - } - } - - if (TRI_LengthStringBuffer(&buffer) == 0) { - shortOptions = ""; - } - else { - shortOptions = TRI_BeginStringBuffer(&buffer); - } - - optind = 1; - maxIdx = options->_items._length; - - while (true) { - c = getopt_long(argc, argv, shortOptions, (const struct option*) options->_longopts._buffer, &idx); - - if (c == -1) { - for (i = optind; i < (size_t) argc; ++i) { - TRI_PushBackVectorString(&options->_arguments, TRI_DuplicateString(argv[i])); - } - - break; - } - - if (c < 256) { - for (i = 0; i < options->_items._length; ++i) { - item = TRI_AtVector(&options->_items, i); - - if (item->_desc->_short == c) { - break; - } - } - - if (i == options->_items._length) { - TRI_set_errno(TRI_ERROR_ILLEGAL_OPTION); - TRI_DestroyStringBuffer(&buffer); - return false; - } - } - else { - c -= 256; - - if (c >= maxIdx) { - TRI_set_errno(TRI_ERROR_ILLEGAL_OPTION); - TRI_DestroyStringBuffer(&buffer); - return false; - } - - item = TRI_AtVector(&options->_items, c); - } - - // the opt.. are external variables - item->_used = true; - item->parse(optarg, item->_desc); - } - - TRI_AnnihilateStringBuffer(&buffer); - - return true; -} - -#else - bool TRI_ParseArgumentsProgramOptions (TRI_program_options_t * options, int argc, char ** argv) { @@ -1564,8 +1443,6 @@ bool TRI_ParseArgumentsProgramOptions (TRI_program_options_t * options, return true; } -#endif - //////////////////////////////////////////////////////////////////////////////// /// @brief parses a text file containing the configuration variables //////////////////////////////////////////////////////////////////////////////// diff --git a/lib/ProgramOptions/program-options.h b/lib/ProgramOptions/program-options.h index 1aa36ba7b8..67f5be2985 100644 --- a/lib/ProgramOptions/program-options.h +++ b/lib/ProgramOptions/program-options.h @@ -68,17 +68,6 @@ typedef enum { /// @brief abstract base structure for descriptions //////////////////////////////////////////////////////////////////////////////// -#ifdef __TCHAR_DEFINED - -typedef struct TRI_PO_desc_s { - TRI_PO_description_types_e _type; - TCHAR * _name; - char _short; - char * _desc; -} TRI_PO_desc_t; - -#else - typedef struct TRI_PO_desc_s { TRI_PO_description_types_e _type; char * _name; @@ -86,7 +75,6 @@ typedef struct TRI_PO_desc_s { char * _desc; } TRI_PO_desc_t; -#endif //////////////////////////////////////////////////////////////////////////////// /// @brief description of attribute of type string diff --git a/lib/Rest/AnyServer.cpp b/lib/Rest/AnyServer.cpp index 1a8e10396b..f43e71671f 100644 --- a/lib/Rest/AnyServer.cpp +++ b/lib/Rest/AnyServer.cpp @@ -384,6 +384,7 @@ AnyServer::~AnyServer () { //////////////////////////////////////////////////////////////////////////////// int AnyServer::start () { + if (_applicationServer == 0) { buildApplicationServer(); } diff --git a/lib/Rest/HttpRequest.cpp b/lib/Rest/HttpRequest.cpp index 274e09c56a..1955da0964 100644 --- a/lib/Rest/HttpRequest.cpp +++ b/lib/Rest/HttpRequest.cpp @@ -36,7 +36,6 @@ using namespace triagens::basics; using namespace triagens::rest; -using namespace std; // ----------------------------------------------------------------------------- // --SECTION-- local constants diff --git a/lib/Rest/HttpRequest.h b/lib/Rest/HttpRequest.h index 92a8c9369d..1578da5a34 100644 --- a/lib/Rest/HttpRequest.h +++ b/lib/Rest/HttpRequest.h @@ -37,6 +37,8 @@ #include "Basics/StringBuffer.h" #include "Rest/ConnectionInfo.h" +using namespace std; + // ----------------------------------------------------------------------------- // --SECTION-- class HttpRequest // ----------------------------------------------------------------------------- diff --git a/lib/Rest/Initialise.cpp b/lib/Rest/InitialiseRest.cpp similarity index 98% rename from lib/Rest/Initialise.cpp rename to lib/Rest/InitialiseRest.cpp index 4ae4cf38cf..7d13b2f5b3 100644 --- a/lib/Rest/Initialise.cpp +++ b/lib/Rest/InitialiseRest.cpp @@ -25,7 +25,7 @@ /// @author Copyright 2009-2011, triAGENS GmbH, Cologne, Germany //////////////////////////////////////////////////////////////////////////////// -#include "Initialise.h" +#include "InitialiseRest.h" #include #include @@ -40,7 +40,7 @@ #include "build.h" -#include "Basics/Initialise.h" +#include "Basics/InitialiseBasics.h" #include "Logger/Logger.h" #include "Rest/HttpResponse.h" #include "Rest/Url.h" diff --git a/lib/Rest/Initialise.h b/lib/Rest/InitialiseRest.h similarity index 96% rename from lib/Rest/Initialise.h rename to lib/Rest/InitialiseRest.h index cb4e7c5503..3a02c39a59 100644 --- a/lib/Rest/Initialise.h +++ b/lib/Rest/InitialiseRest.h @@ -25,8 +25,8 @@ /// @author Copyright 2009-2011, triAGENS GmbH, Cologne, Germany //////////////////////////////////////////////////////////////////////////////// -#ifndef TRIAGENS_FYN_REST_INITIALISE_H -#define TRIAGENS_FYN_REST_INITIALISE_H 1 +#ifndef TRIAGENS_FYN_REST_INITIALISE_REST_H +#define TRIAGENS_FYN_REST_INITIALISE_REST_H 1 #include diff --git a/lib/Rest/SslInterface.cpp b/lib/Rest/SslInterface.cpp index bce9cd2e32..3021000d46 100644 --- a/lib/Rest/SslInterface.cpp +++ b/lib/Rest/SslInterface.cpp @@ -32,7 +32,7 @@ #include #include -#include +#include #include using namespace triagens::basics; diff --git a/lib/Rest/SslInterface.h b/lib/Rest/SslInterface.h index ea650e246e..a54417f645 100644 --- a/lib/Rest/SslInterface.h +++ b/lib/Rest/SslInterface.h @@ -21,7 +21,7 @@ /// /// Copyright holder is triAGENS GmbH, Cologne, Germany /// -/// @author Dr. Oreste Costa-Panaia +/// @author Dr. O /// @author Copyright 2011, triagens GmbH, Cologne, Germany //////////////////////////////////////////////////////////////////////////////// diff --git a/lib/ResultGenerator/Initialise.cpp b/lib/ResultGenerator/InitialiseGenerator.cpp similarity index 96% rename from lib/ResultGenerator/Initialise.cpp rename to lib/ResultGenerator/InitialiseGenerator.cpp index d14ff6b70f..0cc1c729e5 100644 --- a/lib/ResultGenerator/Initialise.cpp +++ b/lib/ResultGenerator/InitialiseGenerator.cpp @@ -25,9 +25,9 @@ /// @author Copyright 2009-2011, triAGENS GmbH, Cologne, Germany //////////////////////////////////////////////////////////////////////////////// -#include "Initialise.h" +#include "InitialiseGenerator.h" -#include +#include #include "ResultGenerator/HtmlResultGenerator.h" #include "ResultGenerator/JsonResultGenerator.h" diff --git a/lib/ResultGenerator/Initialise.h b/lib/ResultGenerator/InitialiseGenerator.h similarity index 97% rename from lib/ResultGenerator/Initialise.h rename to lib/ResultGenerator/InitialiseGenerator.h index 7bf7a24ac6..44b3fc8f13 100644 --- a/lib/ResultGenerator/Initialise.h +++ b/lib/ResultGenerator/InitialiseGenerator.h @@ -25,8 +25,8 @@ /// @author Copyright 2009-2011, triAGENS GmbH, Cologne, Germany //////////////////////////////////////////////////////////////////////////////// -#ifndef TRIAGENS_FYN_REST_INITIALISE2_H -#define TRIAGENS_FYN_REST_INITIALISE2_H 1 +#ifndef TRIAGENS_FYN_REST_INITIALISE_GENERATOR_H +#define TRIAGENS_FYN_REST_INITIALISE_GENERATOR_H 1 #include diff --git a/lib/Scheduler/ApplicationScheduler.cpp b/lib/Scheduler/ApplicationScheduler.cpp index 32716a5491..28238e3d47 100644 --- a/lib/Scheduler/ApplicationScheduler.cpp +++ b/lib/Scheduler/ApplicationScheduler.cpp @@ -63,8 +63,8 @@ namespace { #include #include - bool static CtrlHandler(DWORD eventType); - static SignalTask* localSignalTask; +bool static CtrlHandler(DWORD eventType); +static SignalTask* localSignalTask; #endif @@ -184,6 +184,7 @@ namespace { Scheduler* _scheduler; }; + #ifdef _WIN32 //////////////////////////////////////////////////////////////////////////////// diff --git a/lib/Scheduler/Task.cpp b/lib/Scheduler/Task.cpp index 8b27f10e96..034d953c72 100644 --- a/lib/Scheduler/Task.cpp +++ b/lib/Scheduler/Task.cpp @@ -31,6 +31,7 @@ #include "Scheduler/Scheduler.h" using namespace triagens::rest; +using namespace std; // ----------------------------------------------------------------------------- // constructors and destructors