Libraries report their name, not config

This commit is contained in:
zv0n 2021-07-09 13:01:45 +02:00
parent 9413214fce
commit 0b84f16316
11 changed files with 27 additions and 10 deletions

View File

@ -18,6 +18,9 @@ add_executable(RenameServer
jwt.cpp jwt.cpp
) )
target_link_libraries(RenameServer restbed config++ jwt) target_link_libraries(RenameServer restbed config++ jwt)
if(UNIX AND NOT APPLE)
target_link_libraries(RenameServer dl)
endif()
add_library(thetvdb SHARED add_library(thetvdb SHARED
thetvdb/tv_rename.cpp thetvdb/tv_rename.cpp

View File

@ -22,7 +22,6 @@ bool Configuration::readConfiguration(const std::string &file) {
for(auto &library : cfg_libraries) { for(auto &library : cfg_libraries) {
libraries.emplace_back( libraries.emplace_back(
library.lookup("path"), library.lookup("path"),
library.lookup("name"),
library.lookup("config")); library.lookup("config"));
} }
@ -39,7 +38,7 @@ bool Configuration::readConfiguration(const std::string &file) {
const std::string &Configuration::getSourcePath() { const std::string &Configuration::getSourcePath() {
return source_path; return source_path;
} }
const std::vector<std::tuple<std::string, std::string, std::string>> &Configuration::getLibraries() { const std::vector<std::pair<std::string, std::string>> &Configuration::getLibraries() {
return libraries; return libraries;
} }
const std::vector<std::pair<std::string, std::string>> &Configuration::getTargetPaths() { const std::vector<std::pair<std::string, std::string>> &Configuration::getTargetPaths() {

View File

@ -8,11 +8,11 @@ class Configuration {
public: public:
bool readConfiguration(const std::string &file); bool readConfiguration(const std::string &file);
const std::string &getSourcePath(); const std::string &getSourcePath();
const std::vector<std::tuple<std::string, std::string, std::string>> &getLibraries(); const std::vector<std::pair<std::string, std::string>> &getLibraries();
const std::vector<std::pair<std::string,std::string>> &getTargetPaths(); const std::vector<std::pair<std::string,std::string>> &getTargetPaths();
const std::vector<std::pair<std::string,std::string>> &getUsers(); const std::vector<std::pair<std::string,std::string>> &getUsers();
private: private:
std::vector<std::tuple<std::string,std::string,std::string>> libraries; std::vector<std::pair<std::string,std::string>> libraries;
std::string source_path; std::string source_path;
std::vector<std::pair<std::string, std::string>> target_paths; std::vector<std::pair<std::string, std::string>> target_paths;
std::vector<std::pair<std::string, std::string>> users; std::vector<std::pair<std::string, std::string>> users;

View File

@ -1,13 +1,14 @@
#include <algorithm>
#include <dlfcn.h> #include <dlfcn.h>
#include <iostream> #include <iostream>
#include "functions.hpp" #include "functions.hpp"
#include "filesystem/filesystem.hpp" #include "filesystem/filesystem.hpp"
std::vector< RenameLibrary > getLibraries(const std::vector<std::tuple<std::string,std::string,std::string>> &libraries) { std::vector< RenameLibrary > getLibraries(const std::vector<std::pair<std::string,std::string>> &libraries) {
// TODO get from config file // TODO get from config file
std::vector< RenameLibrary > result{}; std::vector< RenameLibrary > result{};
for ( auto &library : libraries ) { 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 ) { if ( !libhndl ) {
std::cerr << "Could not load library " << std::get<0>(library) << std::endl; std::cerr << "Could not load library " << std::get<0>(library) << std::endl;
closeLibraries( result ); closeLibraries( result );
@ -39,8 +40,8 @@ std::vector< RenameLibrary > getLibraries(const std::vector<std::tuple<std::stri
result.push_back( rl ); result.push_back( rl );
goto dlsymerror; goto dlsymerror;
} }
rl.name = std::get<1>(library); rl.getName = ( const std::string(*)() ) dlsym( libhndl, "getName" );
rl.config = std::get<2>(library); rl.config = library.second;
result.push_back( rl ); result.push_back( rl );
} }
return result; return result;

View File

@ -4,7 +4,7 @@
#include <vector> #include <vector>
#include "rename_library.hpp" #include "rename_library.hpp"
std::vector< RenameLibrary > getLibraries(const std::vector<std::tuple<std::string,std::string,std::string>> &libraries); std::vector< RenameLibrary > getLibraries(const std::vector<std::pair<std::string,std::string>> &libraries);
void closeLibraries( std::vector< RenameLibrary > &libraries ); void closeLibraries( std::vector< RenameLibrary > &libraries );
std::vector< std::string > getFilesInSource( const std::string &source_dir ); std::vector< std::string > getFilesInSource( const std::string &source_dir );
std::vector< std::string > getTargetDirectories( const std::string &target_dir ); std::vector< std::string > getTargetDirectories( const std::string &target_dir );

View File

@ -20,6 +20,7 @@ bool init(const string &configuration);
std::vector< RenameObject > getOptions( const RenameObject &search ); std::vector< RenameObject > getOptions( const RenameObject &search );
bool renamePath( const string &path, const RenameObject &renamer ); bool renamePath( const string &path, const RenameObject &renamer );
std::vector< string > getCustomKeys(); std::vector< string > getCustomKeys();
const string getName();
} }
#endif // TV_RENAME_HPP #endif // TV_RENAME_HPP

View File

@ -60,7 +60,7 @@ bool verifyLogin( const std::shared_ptr< restbed::Session > &session, rapidjson:
std::vector<std::pair<std::string, size_t>> getTypes() { std::vector<std::pair<std::string, size_t>> getTypes() {
std::vector<std::pair<std::string, size_t>> result{}; std::vector<std::pair<std::string, size_t>> result{};
for(size_t i = 0; i < libraries.size(); i++) { 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; return result;
} }

View File

@ -9,6 +9,7 @@ struct RenameLibrary {
std::vector< RenameObject > ( *getOptions )( const RenameObject & ); std::vector< RenameObject > ( *getOptions )( const RenameObject & );
bool ( *renamePath )( const std::string &, const RenameObject & ); bool ( *renamePath )( const std::string &, const RenameObject & );
std::vector< std::string > ( *getCustomKeys )(); std::vector< std::string > ( *getCustomKeys )();
const std::string ( *getName )();
void *libhndl; void *libhndl;
std::string name; std::string name;
std::string config; std::string config;

View File

@ -49,3 +49,7 @@ bool renamePath( const string &path, const RenameObject &renamer ) {
std::vector< string > getCustomKeys() { std::vector< string > getCustomKeys() {
return { "new_name" }; return { "new_name" };
} }
const string getName() {
return "simple rename";
}

View File

@ -198,3 +198,7 @@ bool renamePath( const string &path, const RenameObject &renamer ) {
std::vector< string > getCustomKeys() { std::vector< string > getCustomKeys() {
return { "id", "language", "year", "original_title", "use_original" }; return { "id", "language", "year", "original_title", "use_original" };
} }
const string getName() {
return "themoviedb";
}

View File

@ -412,3 +412,7 @@ bool renamePath( const string &path, const RenameObject &renamer ) {
std::vector< string > getCustomKeys() { std::vector< string > getCustomKeys() {
return { "id", "language", "pattern", "order" }; return { "id", "language", "pattern", "order" };
} }
const string getName() {
return "thetvdb";
}