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
)
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

View File

@ -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<std::tuple<std::string, std::string, std::string>> &Configuration::getLibraries() {
const std::vector<std::pair<std::string, std::string>> &Configuration::getLibraries() {
return libraries;
}
const std::vector<std::pair<std::string, std::string>> &Configuration::getTargetPaths() {

View File

@ -8,11 +8,11 @@ class Configuration {
public:
bool readConfiguration(const std::string &file);
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>> &getUsers();
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::vector<std::pair<std::string, std::string>> target_paths;
std::vector<std::pair<std::string, std::string>> users;

View File

@ -1,13 +1,14 @@
#include <algorithm>
#include <dlfcn.h>
#include <iostream>
#include "functions.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
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<std::tuple<std::stri
result.push_back( rl );
goto dlsymerror;
}
rl.name = std::get<1>(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;

View File

@ -4,7 +4,7 @@
#include <vector>
#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 );
std::vector< std::string > getFilesInSource( const std::string &source_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 );
bool renamePath( const string &path, const RenameObject &renamer );
std::vector< string > getCustomKeys();
const string getName();
}
#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>> 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;
}

View File

@ -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;

View File

@ -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";
}

View File

@ -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";
}

View File

@ -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";
}