From ab5afa50038e987da7d92794564df45382b3d1a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9gory=20Soutad=C3=A9?= Date: Thu, 5 Jan 2023 21:29:55 +0100 Subject: [PATCH] Add new default ADEPT directories : /home//.config/adept and $ADEPT_DIR environment variable --- README.md | 19 ++++++++++++------- include/libgourou.h | 11 ++++++----- src/libgourou.cpp | 25 +++++++++++++++++++++++-- utils/acsmdownloader.cpp | 2 ++ utils/adept_activate.cpp | 2 +- utils/adept_loan_mgt.cpp | 2 ++ utils/adept_remove.cpp | 2 ++ utils/utils_common.cpp | 16 +++++++++++++++- 8 files changed, 63 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index d09f731..7b14aa5 100644 --- a/README.md +++ b/README.md @@ -82,38 +82,43 @@ BUILD_SHARED build libgourou.so if 1, nothing if 0, can be combined with BUILD_S Utils ----- -You can import configuration from your eReader or create a new one with _utils/adept\_activate_ : +First, add libgourou.so to your LD_LIBRARY_PATH export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$PWD + +You can optionaly specify your .adept directory + + export ADEPT_DIR=/home/XXX + +Then, use utils as following : + +You can import configuration from your eReader or create a new one with _utils/adept\_activate_ : + ./utils/adept_activate -u -Then a _./.adept_ directory is created with all configuration file +Then a _/home//.config/adept_ directory is created with all configuration file To download an ePub/PDF : - export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$PWD ./utils/acsmdownloader -f To export your private key (for DeDRM software) : - export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$PWD ./utils/acsmdownloader --export-private-key [-o adobekey_1.der] To remove ADEPT DRM : - export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$PWD ./utils/adept_remove -f To list loaned books : - export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$PWD ./utils/adept_loan_mgt [-l] To return a loaned book : - export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$PWD ./utils/adept_loan_mgt -r + You can get utils full options description with -h or --help switch diff --git a/include/libgourou.h b/include/libgourou.h index 1f82dd8..706504a 100644 --- a/include/libgourou.h +++ b/include/libgourou.h @@ -32,10 +32,6 @@ #define HOBBES_DEFAULT_VERSION "10.0.4" #endif -#ifndef DEFAULT_ADEPT_DIR -#define DEFAULT_ADEPT_DIR "./.adept" -#endif - #ifndef ACS_SERVER #define ACS_SERVER "http://adeactivate.adobe.com/adept" #endif @@ -107,6 +103,11 @@ namespace gourou * @param operatorURL URL of operator that loans this book */ void returnLoan(const std::string& loanID, const std::string& operatorURL); + + /** + * @brief Return default ADEPT directory (ie /home//.config/adept) + */ + static std::string getDefaultAdeptDir(void); /** * @brief Create a new ADEPT environment (device.xml, devicesalt and activation.xml). @@ -118,7 +119,7 @@ namespace gourou * @param ACSServer Override main ACS server (default adeactivate.adobe.com) */ static DRMProcessor* createDRMProcessor(DRMProcessorClient* client, - bool randomSerial=false, const std::string& dirName=std::string(DEFAULT_ADEPT_DIR), + bool randomSerial=false, std::string dirName=std::string(""), const std::string& hobbes=std::string(HOBBES_DEFAULT_VERSION), const std::string& ACSServer=ACS_SERVER); diff --git a/src/libgourou.cpp b/src/libgourou.cpp index 9210460..ec199d4 100644 --- a/src/libgourou.cpp +++ b/src/libgourou.cpp @@ -28,6 +28,8 @@ #include #include +#define LOCAL_ADEPT_DIR "./.adept" + #define ASN_NONE 0x00 #define ASN_NS_TAG 0x01 #define ASN_CHILD 0x02 @@ -68,11 +70,14 @@ namespace gourou if (user) delete user; } - DRMProcessor* DRMProcessor::createDRMProcessor(DRMProcessorClient* client, bool randomSerial, const std::string& dirName, + DRMProcessor* DRMProcessor::createDRMProcessor(DRMProcessorClient* client, bool randomSerial, std::string dirName, const std::string& hobbes, const std::string& ACSServer) { DRMProcessor* processor = new DRMProcessor(client); + if (dirName == "") + dirName = getDefaultAdeptDir(); + Device* device = Device::createDevice(processor, dirName, hobbes, randomSerial); processor->device = device; @@ -844,7 +849,23 @@ namespace gourou addNonce(root); signNode(root); } - + + std::string DRMProcessor::getDefaultAdeptDir(void) + { +#ifndef DEFAULT_ADEPT_DIR + const char* user = getenv("USER"); + + if (user && user[0]) + { + return std::string("/home/") + user + std::string("/.config/adept/"); + } + else + return LOCAL_ADEPT_DIR; +#else + return DEFAULT_ADEPT_DIR "/"; +#endif + } + void DRMProcessor::returnLoan(const std::string& loanID, const std::string& operatorURL) { pugi::xml_document returnReq; diff --git a/utils/acsmdownloader.cpp b/utils/acsmdownloader.cpp index 1c66086..867205c 100644 --- a/utils/acsmdownloader.cpp +++ b/utils/acsmdownloader.cpp @@ -201,6 +201,8 @@ static void usage(const char* cmd) std::cout << std::endl; std::cout << "Device file, activation file and device key file are optionals. If not set, they are looked into :" << std::endl; + std::cout << " * $ADEPT_DIR environment variable" << std::endl; + std::cout << " * /home//.config/adept" << std::endl; std::cout << " * Current directory" << std::endl; std::cout << " * .adept" << std::endl; std::cout << " * adobe-digital-editions directory" << std::endl; diff --git a/utils/adept_activate.cpp b/utils/adept_activate.cpp index bee58d3..80c8068 100644 --- a/utils/adept_activate.cpp +++ b/utils/adept_activate.cpp @@ -230,7 +230,7 @@ int main(int argc, char** argv) if (!_outputDir || _outputDir[0] == 0) { - outputDir = strdup(abspath(DEFAULT_ADEPT_DIR)); + outputDir = strdup(abspath(gourou::DRMProcessor::getDefaultAdeptDir().c_str())); } else { diff --git a/utils/adept_loan_mgt.cpp b/utils/adept_loan_mgt.cpp index 190cf5f..30e9444 100644 --- a/utils/adept_loan_mgt.cpp +++ b/utils/adept_loan_mgt.cpp @@ -348,6 +348,8 @@ static void usage(const char* cmd) std::cout << std::endl; std::cout << "ADEPT directory is optional. If not set, it's looked into :" << std::endl; + std::cout << " * $ADEPT_DIR environment variable" << std::endl; + std::cout << " * /home//.config/adept" << std::endl; std::cout << " * Current directory" << std::endl; std::cout << " * .adept" << std::endl; std::cout << " * adobe-digital-editions directory" << std::endl; diff --git a/utils/adept_remove.cpp b/utils/adept_remove.cpp index 6baeb53..77cda8e 100644 --- a/utils/adept_remove.cpp +++ b/utils/adept_remove.cpp @@ -158,6 +158,8 @@ static void usage(const char* cmd) std::cout << std::endl; std::cout << "Device file, activation file and device key file are optionals. If not set, they are looked into :" << std::endl; + std::cout << " * $ADEPT_DIR environment variable" << std::endl; + std::cout << " * /home//.config/adept" << std::endl; std::cout << " * Current directory" << std::endl; std::cout << " * .adept" << std::endl; std::cout << " * adobe-digital-editions directory" << std::endl; diff --git a/utils/utils_common.cpp b/utils/utils_common.cpp index 08ca3a2..a686b40 100644 --- a/utils/utils_common.cpp +++ b/utils/utils_common.cpp @@ -61,6 +61,20 @@ bool fileExists(const char* filename) const char* findFile(const char* filename, bool inDefaultDirs) { + std::string path; + + const char* adeptDir = getenv("ADEPT_DIR"); + if (adeptDir && adeptDir[0]) + { + path = adeptDir + std::string("/") + filename; + if (fileExists(path.c_str())) + return strdup(path.c_str()); + } + + path = gourou::DRMProcessor::getDefaultAdeptDir() + filename; + if (fileExists(path.c_str())) + return strdup(path.c_str()); + if (fileExists(filename)) return strdup(filename); @@ -68,7 +82,7 @@ const char* findFile(const char* filename, bool inDefaultDirs) for (int i=0; i<(int)ARRAY_SIZE(defaultDirs); i++) { - std::string path = std::string(defaultDirs[i]) + filename; + path = std::string(defaultDirs[i]) + filename; if (fileExists(path.c_str())) return strdup(path.c_str()); }