From 67d101074faeb1312aabfd61bb5040b42efc34e4 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Fri, 16 Sep 2022 23:34:48 +0200 Subject: [PATCH] draft basics --- .gitignore | 4 ++- app/server/CMakeLists.txt | 5 +++ app/server/Models/Db.h | 26 ++++++++++++++ app/server/Models/File.h | 0 app/server/build/install.sh | 7 ++++ app/server/cOMS | 2 +- app/server/config.json | 0 app/server/main.cpp | 68 +++++++++++++++++++++++++++++++++++-- app/web/Install/db.json | 5 +++ 9 files changed, 113 insertions(+), 4 deletions(-) create mode 100644 app/server/Models/Db.h create mode 100644 app/server/Models/File.h create mode 100644 app/server/build/install.sh create mode 100644 app/server/config.json diff --git a/.gitignore b/.gitignore index 7a82fcb..67ffd12 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,6 @@ obj/ *.cache .directory bin/Debug -x64/Debug \ No newline at end of file +x64/Debug +app/server/Libraries +.vscode \ No newline at end of file diff --git a/app/server/CMakeLists.txt b/app/server/CMakeLists.txt index 6f91b2d..f150823 100644 --- a/app/server/CMakeLists.txt +++ b/app/server/CMakeLists.txt @@ -2,5 +2,10 @@ cmake_minimum_required(VERSION 2.8) project( OnlineResourceWatcherServerApp ) add_executable( OnlineResourceWatcherServerApp main.cpp ) +# SQLite3 +include_directories( /usr/include ) +link_directories( /usr/lib ) +target_link_libraries( OnlineResourceWatcherServerApp sqlite3 ) + # cmake -DCMAKE_BUILD_TYPE=Debug -DOMS_DEBUG=true # cmake -DCMAKE_BUILD_TYPE=Release -DOMS_DEMO=true \ No newline at end of file diff --git a/app/server/Models/Db.h b/app/server/Models/Db.h new file mode 100644 index 0000000..77ca6b1 --- /dev/null +++ b/app/server/Models/Db.h @@ -0,0 +1,26 @@ +/** + * Karaka + * + * @package Models + * @copyright Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link https://karaka.app + */ +#ifndef MODELS_DB_H +#define MODELS_DB_H + +namespace Models { + class Db { + private: + + public: + static inline + int setup_connection (char *cfg) + { + return 0; + } + }; +} + +#endif \ No newline at end of file diff --git a/app/server/Models/File.h b/app/server/Models/File.h new file mode 100644 index 0000000..e69de29 diff --git a/app/server/build/install.sh b/app/server/build/install.sh new file mode 100644 index 0000000..23e037a --- /dev/null +++ b/app/server/build/install.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +sudo apt-get install sqlite3 libsqlite3-dev +sudo apt install default-libmysqlclient-dev +sudo apt-get install libxml2-dev + +# install maria db https://mariadb.com/docs/connect/programming-languages/cpp/install/ diff --git a/app/server/cOMS b/app/server/cOMS index cd71fb7..6f9f0c0 160000 --- a/app/server/cOMS +++ b/app/server/cOMS @@ -1 +1 @@ -Subproject commit cd71fb74b146e1fffefafe6f8f053ec4ef4a1096 +Subproject commit 6f9f0c03aa5edab86b7c9eec9efa69367997b0d9 diff --git a/app/server/config.json b/app/server/config.json new file mode 100644 index 0000000..e69de29 diff --git a/app/server/main.cpp b/app/server/main.cpp index d9cfaf7..438da98 100644 --- a/app/server/main.cpp +++ b/app/server/main.cpp @@ -9,8 +9,17 @@ */ #include +#include + +#include +#include #include "cOMS/Utils/ArrayUtils.h" +#include "cOMS/Utils/FileUtils.h" +#include "cOMS/Hash/MeowHash.h" +#include "cOMS/Utils/Parser/Json.h" + +#include "Models/Db.h" #ifndef OMS_DEMO #define OMS_DEMO false @@ -33,19 +42,74 @@ void printVersion() printf("Version: 1.0.0\n"); } +void parseConfigFile() +{ + FILE *fp = fopen("config.json"); + + nlohmann::json config = nlohmann::json::parse(fp); +} + +bool isResourceModified(char *filename, time_t last_change) +{ + return oms_abs(Utils::FileUtils::last_modification(filename) - last_change) > 1; +} + +bool hasResourceContentChanged(char *filename1, char *filename2) +{ + Utils::FileUtils::file_body f1 = Utils::FileUtils::read_file(filename1); + Utils::FileUtils::file_body f2 = Utils::FileUtils::read_file(filename2); + + Hash::Meow::meow_u128 h1 = Hash::Meow::MeowHash(Hash::Meow::MeowDefaultSeed, f1.size, f1.content); + Hash::Meow::meow_u128 h2 = Hash::Meow::MeowHash(Hash::Meow::MeowDefaultSeed, f2.size, f2.content); + + bool areHashesEqual = Hash::Meow::MeowHashesAreEqual(h1, h2); + + free(f1.content); + free(f2.content); + + return areHashesEqual; +} + +void saveResourceChange() +{ + +} + +MYSQL *con = null; + int main(int argc, char **argv) { - bool hasHelpCmd = Utils::ArrayUtils::has_arg("-h", argv, argc); + bool hasHelpCmd = Utils::ArrayUtils::has_arg("-h", argv, argc); if (hasHelpCmd) { printHelp(); return 0; } - bool hasVersionCmd = Utils::ArrayUtils::has_arg("-v", argv, argc); + bool hasVersionCmd = Utils::ArrayUtils::has_arg("-v", argv, argc); if (hasVersionCmd) { printVersion(); return 0; } + + if (!Utils::FileUtils::file_exists("config.json")) { + printf("No config file available."); + + return -1; + } + + unsigned long resourceId = (unsigned long) Utils::ArrayUtils::get_arg("-r", argv, argc); + + + // read config file + // create database connection (either mariadb or sqlite) + // @todo create wrapper for sqlite, mysql and postgresql + + con = mysql_init(NULL); + if (mysql_real_connect(con, "localhost", "root", "root_passwd", NULL, 0, NULL, 0) == NULL) { + fprintf(stderr, "%s\n", mysql_error(con)); + mysql_close(con); + exit(1); + } } diff --git a/app/web/Install/db.json b/app/web/Install/db.json index 0a372ed..1b6edba 100644 --- a/app/web/Install/db.json +++ b/app/web/Install/db.json @@ -303,6 +303,11 @@ "type": "VARCHAR(255)", "null": false }, + "resource_xpath": { + "name": "resource_xpath", + "type": "VARCHAR(255)", + "null": false + }, "resource_hash": { "name": "resource_hash", "type": "BLOB(64)",