diff --git a/CMakeLists.txt b/CMakeLists.txt index e83ad73..93ce50a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,6 +18,9 @@ add_executable(RenameServer jwt.cpp ) target_link_libraries(RenameServer restbed config++ jwt) +if(UNIX AND NOT APPLE) + target_link_libraries(RenameServer dl) +endif() add_library(thetvdb SHARED thetvdb/tv_rename.cpp diff --git a/config/config.cpp b/config/config.cpp index 7ac7e44..fa5efb1 100644 --- a/config/config.cpp +++ b/config/config.cpp @@ -22,7 +22,6 @@ bool Configuration::readConfiguration(const std::string &file) { for(auto &library : cfg_libraries) { libraries.emplace_back( library.lookup("path"), - library.lookup("name"), library.lookup("config")); } @@ -39,7 +38,7 @@ bool Configuration::readConfiguration(const std::string &file) { const std::string &Configuration::getSourcePath() { return source_path; } -const std::vector> &Configuration::getLibraries() { +const std::vector> &Configuration::getLibraries() { return libraries; } const std::vector> &Configuration::getTargetPaths() { diff --git a/config/config.hpp b/config/config.hpp index f3b8b17..e3dd40f 100644 --- a/config/config.hpp +++ b/config/config.hpp @@ -8,11 +8,11 @@ class Configuration { public: bool readConfiguration(const std::string &file); const std::string &getSourcePath(); - const std::vector> &getLibraries(); + const std::vector> &getLibraries(); const std::vector> &getTargetPaths(); const std::vector> &getUsers(); private: - std::vector> libraries; + std::vector> libraries; std::string source_path; std::vector> target_paths; std::vector> users; diff --git a/functions.cpp b/functions.cpp index a90dfc0..a66e1c4 100644 --- a/functions.cpp +++ b/functions.cpp @@ -1,13 +1,14 @@ +#include #include #include #include "functions.hpp" #include "filesystem/filesystem.hpp" -std::vector< RenameLibrary > getLibraries(const std::vector> &libraries) { +std::vector< RenameLibrary > getLibraries(const std::vector> &libraries) { // TODO get from config file std::vector< RenameLibrary > result{}; for ( auto &library : libraries ) { - void *libhndl = dlopen( std::get<0>(library).c_str(), RTLD_NOW ); + void *libhndl = dlopen( library.first.c_str(), RTLD_NOW ); if ( !libhndl ) { std::cerr << "Could not load library " << std::get<0>(library) << std::endl; closeLibraries( result ); @@ -39,8 +40,8 @@ std::vector< RenameLibrary > getLibraries(const std::vector(library); - rl.config = std::get<2>(library); + rl.getName = ( const std::string(*)() ) dlsym( libhndl, "getName" ); + rl.config = library.second; result.push_back( rl ); } return result; diff --git a/functions.hpp b/functions.hpp index d669a87..2370562 100644 --- a/functions.hpp +++ b/functions.hpp @@ -4,7 +4,7 @@ #include #include "rename_library.hpp" -std::vector< RenameLibrary > getLibraries(const std::vector> &libraries); +std::vector< RenameLibrary > getLibraries(const std::vector> &libraries); void closeLibraries( std::vector< RenameLibrary > &libraries ); std::vector< std::string > getFilesInSource( const std::string &source_dir ); std::vector< std::string > getTargetDirectories( const std::string &target_dir ); diff --git a/library.hpp b/library.hpp index 32933b7..5c5c0e2 100644 --- a/library.hpp +++ b/library.hpp @@ -20,6 +20,7 @@ bool init(const string &configuration); std::vector< RenameObject > getOptions( const RenameObject &search ); bool renamePath( const string &path, const RenameObject &renamer ); std::vector< string > getCustomKeys(); +const string getName(); } #endif // TV_RENAME_HPP diff --git a/main.cpp b/main.cpp index 99de751..5075b6a 100644 --- a/main.cpp +++ b/main.cpp @@ -60,7 +60,7 @@ bool verifyLogin( const std::shared_ptr< restbed::Session > &session, rapidjson: std::vector> getTypes() { std::vector> result{}; for(size_t i = 0; i < libraries.size(); i++) { - result.emplace_back(libraries[i].name, i); + result.emplace_back(libraries[i].getName(), i); } return result; } diff --git a/rename_library.hpp b/rename_library.hpp index a5ad042..2bf0337 100644 --- a/rename_library.hpp +++ b/rename_library.hpp @@ -9,6 +9,7 @@ struct RenameLibrary { std::vector< RenameObject > ( *getOptions )( const RenameObject & ); bool ( *renamePath )( const std::string &, const RenameObject & ); std::vector< std::string > ( *getCustomKeys )(); + const std::string ( *getName )(); void *libhndl; std::string name; std::string config; diff --git a/simple_rename/simple.cpp b/simple_rename/simple.cpp index fbe8c97..9202a38 100644 --- a/simple_rename/simple.cpp +++ b/simple_rename/simple.cpp @@ -49,3 +49,7 @@ bool renamePath( const string &path, const RenameObject &renamer ) { std::vector< string > getCustomKeys() { return { "new_name" }; } + +const string getName() { + return "simple rename"; +} diff --git a/themoviedb/moviedb.cpp b/themoviedb/moviedb.cpp index ca3de8d..f7f5cf7 100644 --- a/themoviedb/moviedb.cpp +++ b/themoviedb/moviedb.cpp @@ -198,3 +198,7 @@ bool renamePath( const string &path, const RenameObject &renamer ) { std::vector< string > getCustomKeys() { return { "id", "language", "year", "original_title", "use_original" }; } + +const string getName() { + return "themoviedb"; +} diff --git a/thetvdb/tv_rename.cpp b/thetvdb/tv_rename.cpp index 3da0509..356cdab 100644 --- a/thetvdb/tv_rename.cpp +++ b/thetvdb/tv_rename.cpp @@ -412,3 +412,7 @@ bool renamePath( const string &path, const RenameObject &renamer ) { std::vector< string > getCustomKeys() { return { "id", "language", "pattern", "order" }; } + +const string getName() { + return "thetvdb"; +}