diff --git a/server/Controller/ApiController.h b/server/Controller/ApiController.h index 37f2649..f7f16c2 100755 --- a/server/Controller/ApiController.h +++ b/server/Controller/ApiController.h @@ -19,12 +19,17 @@ #include "../cOMS/Hash/MeowHash.h" #include "../cOMS/Utils/MathUtils.h" #include "../cOMS/Threads/Thread.h" +#include "../cOMS/DataStorage/Database/Mapper/DataMapperFactory.h" #include "../Models/Resource.h" +#include "../Models/ResourceMapper.h" #include "../Models/ResourceType.h" +#include "../Models/ResourceStatus.h" namespace Controller { namespace ApiController { + static Application::ApplicationAbstract *app = NULL; + void printHelp(int argc, char **argv) { printf(" The Online Resource Watcher app developed by jingga checks online or local resources\n"); @@ -80,35 +85,36 @@ namespace Controller { meow_u128 tempHash; for (i = 0; i < data->count; ++i) { - cachedSource = Utils::FileUtils::read_file(data->resources[i]->lastVersion); + // cachedSource = Utils::FileUtils::read_file(data->resources[i]->last_version_path); tempHash = Hash::Meow::MeowHash(Hash::Meow::MeowDefaultSeed, multi[i].size, multi[i].content); - if (hasChanged = (strcmp(Hash::Meow::MeowStringify(tempHash), data->resources[i]->lastHash) == 0)) { + if (hasChanged = (strcmp((char *) Hash::Meow::MeowStringify(tempHash), data->resources[i]->hash) == 0)) { // @todo: do stuff because of change!!! // create website image with pdf? // inform users } - if (hasChanged || data->resources[i]->lastCheckedAt == NULL) { + if (hasChanged || data->resources[i]->checked_at == 0) { // @todo: download references + css references (= second level) // @todo: probably ignore javascript references, they are not useful for static offline comparisons!? - data->resources[i].lastHash = Hash::Meow::MeowStringify(tempHash); - data->resources[i].lastChangedAt = time(); + data->resources[i]->hash = (char *) Hash::Meow::MeowStringify(tempHash); + data->resources[i]->last_version_date = time(0); // @todo: store new version // @todo: check if older version can/needs to be removed - data->resources[i].lastVersion = "PATH_TO_NEWEST_VERSION"; - data->resources[i].lastVersionHash = "Hash_of_new_version"; + data->resources[i]->last_version_path = (char *) "PATH_TO_NEWEST_VERSION\0"; + data->resources[i]->hash = (char *) "Hash_of_new_version\0"; } - data->resources[i].lastCheckedAt = time(); + data->resources[i]->checked_at = time(0); - Models::ResourceMapper::update() - ->execute($data->resources[i]); + // @todo: update data + //DataStorage::Database::DataMapperFactory::update(&Models::ResourceMapper) + // ->execute(data->resources[i]); - Models::Resource::free_Resource(data->resources[i]); + Models::free_Resource(data->resources[i]); } free(data->resources); @@ -139,14 +145,14 @@ namespace Controller { free(resourceIdStrings); } else { // find and load all relevant ids from the database - resources = ResourceMapper::get() - ->where('status', ResourceStatus::ACTIVE) + resources = (Models::Resource *) DataStorage::Database::DataMapperFactory::get(&Models::ResourceMapper) + ->where((char *) "status", (void *) Models::ResourceStatus::RESOURCE_ACTIVE) ->execute(); } // How many resources are handled in one thread // This must be multiplied with the thread count for the over all concurrent max downloads - int THREAD_SIZE = app.config["app"]["resources"]["online"]["downloads"].get(); + int THREAD_SIZE = app->config["app"]["resources"]["online"]["downloads"].get(); Models::Resource **onlineResources = (Models::Resource **) malloc(oms_min(idLength, THREAD_SIZE) * sizeof(Models::Resource *)); Models::Resource **offlineResources = (Models::Resource **) malloc(oms_min(idLength, THREAD_SIZE) * sizeof(Models::Resource *)); @@ -156,7 +162,7 @@ namespace Controller { int k = 0; for (i = 0; i < idLength; ++i) { - if (resources[i].type == Models::ResourceType::ONLINE) { + if (resources[i].type == Models::ResourceType::RESOURCE_ONLINE) { onlineResources[j] = &resources[i]; ++j; @@ -173,7 +179,7 @@ namespace Controller { data->count = j; data->simultaneous = THREAD_SIZE; - Threads::pool_add_work(app.pool, onlineResourceThreaded, data); + Threads::pool_add_work(app->pool, onlineResourceThreaded, data); if (i + 1 < idLength) { onlineResources = (Models::Resource **) malloc((oms_min(idLength - i, THREAD_SIZE)) * sizeof(Models::Resource *)); @@ -188,7 +194,7 @@ namespace Controller { data->count = k; data->simultaneous = THREAD_SIZE; - Threads::pool_add_work(app.pool, offlineResourceThreaded, data); + Threads::pool_add_work(app->pool, offlineResourceThreaded, data); if (i + 1 < idLength) { offlineResources = (Models::Resource **) malloc((oms_min(idLength - i, THREAD_SIZE)) * sizeof(Models::Resource *)); @@ -197,7 +203,7 @@ namespace Controller { } } - Threads::pool_wait(); + Threads::pool_wait(app->pool); free(resources); } diff --git a/server/Models/Account.h b/server/Models/Account.h index 1016fb4..c4c458c 100755 --- a/server/Models/Account.h +++ b/server/Models/Account.h @@ -20,7 +20,7 @@ namespace Models { typedef struct { int id = 0; - AccountStatus status = AccountStatus::ACTIVE; + AccountStatus status = AccountStatus::ACCOUNT_ACTIVE; char *email = NULL; diff --git a/server/Models/AccountStatus.h b/server/Models/AccountStatus.h index 0ce2b7f..235754e 100755 --- a/server/Models/AccountStatus.h +++ b/server/Models/AccountStatus.h @@ -12,8 +12,8 @@ namespace Models { typedef enum { - ACTIVE = 1, - INACTIVE = 2 + ACCOUNT_ACTIVE = 1, + ACCOUNT_INACTIVE = 2 } AccountStatus; } diff --git a/server/Models/Organization.h b/server/Models/Organization.h index ba81838..16914bd 100755 --- a/server/Models/Organization.h +++ b/server/Models/Organization.h @@ -13,8 +13,6 @@ #include #include -#include "ReosurceStatus.h" - namespace Models { typedef struct { int id = 0; diff --git a/server/Models/Resource.h b/server/Models/Resource.h index 8fb97e4..06b1acf 100755 --- a/server/Models/Resource.h +++ b/server/Models/Resource.h @@ -13,7 +13,7 @@ #include #include -#include "ReosurceStatus.h" +#include "ResourceStatus.h" #include "Organization.h" #include "ResourceInfo.h" @@ -21,7 +21,7 @@ namespace Models { typedef struct { unsigned long long id = 0; - ResourceStatus status = ResourceStatus::INACTIVE; + ResourceStatus status = ResourceStatus::RESOURCE_INACTIVE; char *uri = NULL; diff --git a/server/Models/ResourceMapper.h b/server/Models/ResourceMapper.h new file mode 100644 index 0000000..301ad19 --- /dev/null +++ b/server/Models/ResourceMapper.h @@ -0,0 +1,34 @@ +/** + * Karaka + * + * @package Models + * @copyright Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link https://jingga.app + */ +#ifndef MODELS_RESOURCE_MAPPER_H +#define MODELS_RESOURCE_MAPPER_H + +#include +#include + +#include "../cOMS/DataStorage/Database/Mapper/DataMapperTypes.h" +#include "../cOMS/DataStorage/Database/Mapper/MapperAbstract.h" + +namespace Models { + static const DataStorage::Database::MapperData ResourceMapper = { + .MEMBER_COUNT = 1, + .MODEL_STRUCTURE = new DataStorage::Database::ModelStructure[1] { + {.name = "id", .size = sizeof(int)} + }, + + .COLUMN_COUNT = 2, + .COLUMNS = new DataStorage::Database::DataMapperColumn[2] { + {.name = "orw_resource_id", .type = DataStorage::Database::FieldType::FIELD_TYPE_INT, .internal = "title"}, + {.name = "orw_resource_status", .type = DataStorage::Database::FieldType::FIELD_TYPE_INT, .internal = "status"} + } + }; +} + +#endif diff --git a/server/Models/ReosurceStatus.h b/server/Models/ResourceStatus.h similarity index 81% rename from server/Models/ReosurceStatus.h rename to server/Models/ResourceStatus.h index e8db4ab..6603706 100755 --- a/server/Models/ReosurceStatus.h +++ b/server/Models/ResourceStatus.h @@ -12,8 +12,8 @@ namespace Models { typedef enum { - ACTIVE = 1, - INACTIVE = 2 + RESOURCE_ACTIVE = 1, + RESOURCE_INACTIVE = 2 } ResourceStatus; } diff --git a/server/Models/ResourceType.h b/server/Models/ResourceType.h index 581d1f0..ff88397 100755 --- a/server/Models/ResourceType.h +++ b/server/Models/ResourceType.h @@ -12,8 +12,8 @@ namespace Models { typedef enum { - ONLINE = 1, - OFFLINE = 2 + RESOURCE_ONLINE = 1, + RESOURCE_OFFLINE = 2 } ResourceType; } diff --git a/server/Routes.h b/server/Routes.h index ac1c68e..ebecaaa 100755 --- a/server/Routes.h +++ b/server/Routes.h @@ -16,9 +16,12 @@ #include "Controller/ApiController.h" #include "Controller/InstallController.h" #include "cOMS/Router/Router.h" +#include "cOMS/Application/ApplicationAbstract.h" -Router::Router generate_routes() +Router::Router generate_routes(Application::ApplicationAbstract *app) { + Controller::ApiController::app = app; + Router::Router router = Router::create_router(4); Router::set(&router, "^.*?\\-h *.*$", (void *) &Controller::ApiController::printHelp); diff --git a/server/bin/CMakeCache.txt b/server/bin/CMakeCache.txt old mode 100755 new mode 100644 index bc92948..4646a60 --- a/server/bin/CMakeCache.txt +++ b/server/bin/CMakeCache.txt @@ -53,6 +53,32 @@ CMAKE_CXX_FLAGS_RELEASE:STRING=-O3 -DNDEBUG //Flags used by the CXX compiler during RELWITHDEBINFO builds. CMAKE_CXX_FLAGS_RELWITHDEBINFO:STRING=-O2 -g -DNDEBUG +//C compiler +CMAKE_C_COMPILER:FILEPATH=/usr/bin/cc + +//A wrapper around 'ar' adding the appropriate '--plugin' option +// for the GCC compiler +CMAKE_C_COMPILER_AR:FILEPATH=/usr/bin/gcc-ar-11 + +//A wrapper around 'ranlib' adding the appropriate '--plugin' option +// for the GCC compiler +CMAKE_C_COMPILER_RANLIB:FILEPATH=/usr/bin/gcc-ranlib-11 + +//Flags used by the C compiler during all build types. +CMAKE_C_FLAGS:STRING= + +//Flags used by the C compiler during DEBUG builds. +CMAKE_C_FLAGS_DEBUG:STRING=-g + +//Flags used by the C compiler during MINSIZEREL builds. +CMAKE_C_FLAGS_MINSIZEREL:STRING=-Os -DNDEBUG + +//Flags used by the C compiler during RELEASE builds. +CMAKE_C_FLAGS_RELEASE:STRING=-O3 -DNDEBUG + +//Flags used by the C compiler during RELWITHDEBINFO builds. +CMAKE_C_FLAGS_RELWITHDEBINFO:STRING=-O2 -g -DNDEBUG + //Path to a program. CMAKE_DLLTOOL:FILEPATH=CMAKE_DLLTOOL-NOTFOUND @@ -267,6 +293,22 @@ CMAKE_CXX_FLAGS_MINSIZEREL-ADVANCED:INTERNAL=1 CMAKE_CXX_FLAGS_RELEASE-ADVANCED:INTERNAL=1 //ADVANCED property for variable: CMAKE_CXX_FLAGS_RELWITHDEBINFO CMAKE_CXX_FLAGS_RELWITHDEBINFO-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_C_COMPILER +CMAKE_C_COMPILER-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_C_COMPILER_AR +CMAKE_C_COMPILER_AR-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_C_COMPILER_RANLIB +CMAKE_C_COMPILER_RANLIB-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_C_FLAGS +CMAKE_C_FLAGS-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_C_FLAGS_DEBUG +CMAKE_C_FLAGS_DEBUG-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_C_FLAGS_MINSIZEREL +CMAKE_C_FLAGS_MINSIZEREL-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_C_FLAGS_RELEASE +CMAKE_C_FLAGS_RELEASE-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_C_FLAGS_RELWITHDEBINFO +CMAKE_C_FLAGS_RELWITHDEBINFO-ADVANCED:INTERNAL=1 //ADVANCED property for variable: CMAKE_DLLTOOL CMAKE_DLLTOOL-ADVANCED:INTERNAL=1 //Path to cache edit program executable. diff --git a/server/bin/OnlineResourceWatcherServerApp b/server/bin/OnlineResourceWatcherServerApp index 0b85e30..86fb14f 100755 Binary files a/server/bin/OnlineResourceWatcherServerApp and b/server/bin/OnlineResourceWatcherServerApp differ diff --git a/server/cOMS b/server/cOMS index 593fbc9..bc465ff 160000 --- a/server/cOMS +++ b/server/cOMS @@ -1 +1 @@ -Subproject commit 593fbc9f892206b7b5edd89aa68ead793272ba4d +Subproject commit bc465ff0a8ea45ccb42b06fb7edb050bfa523791 diff --git a/server/main.cpp b/server/main.cpp index a3b3439..f6bac2e 100755 --- a/server/main.cpp +++ b/server/main.cpp @@ -17,6 +17,7 @@ #include "cOMS/Utils/OSWrapper.h" #include "cOMS/Router/Router.h" #include "cOMS/Threads/Thread.h" +#include "cOMS/Application/ApplicationAbstract.h" #include "Routes.h" @@ -24,13 +25,7 @@ #define OMS_DEMO false #endif -typedef struct { - DataStorage::Database::ConnectionAbstract *db; - nlohmann::json config; - Threads::ThreadPool *pool; -} App; - -App app = {0}; +Application::ApplicationAbstract app = {0}; int main(int argc, char **argv) { @@ -91,7 +86,7 @@ int main(int argc, char **argv) /* --------------- Handle request --------------- */ // Handle routes - Router::Router router = generate_routes(); + Router::Router router = generate_routes(&app); Router::RouterFunc ptr = Router::match_route(&router, arg); // No endpoint found