From 8871e6c2e356f49cd478f06c328994ed2bccd798 Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Tue, 20 Dec 2016 00:19:38 +0100 Subject: [PATCH] first version of meson --- meson.build | 40 ++++ meson_options.txt | 2 + src/contentManager/contentManager.cpp | 294 -------------------------- src/launcher/kiwix-launcher.cpp | 285 ------------------------- src/man/kiwix.1 | 52 ----- src/meson.build | 8 + src/server/kiwix-serve.cpp | 10 +- src/server/meson.build | 3 + 8 files changed, 58 insertions(+), 636 deletions(-) create mode 100644 meson.build create mode 100644 meson_options.txt delete mode 100644 src/contentManager/contentManager.cpp delete mode 100644 src/launcher/kiwix-launcher.cpp delete mode 100644 src/man/kiwix.1 create mode 100644 src/meson.build create mode 100644 src/server/meson.build diff --git a/meson.build b/meson.build new file mode 100644 index 0000000..3ca19a3 --- /dev/null +++ b/meson.build @@ -0,0 +1,40 @@ +project('kiwix-tools', 'cpp') + +compiler = meson.get_compiler('cpp') + +thread_dep = dependency('threads') +kiwixlib_dep = dependency('kiwix') +microhttpd_dep = dependency('libmicrohttpd') + +# Idealy we should not have more dependency, however : +# We should declare we use ctpp2 in kiwixlib in the pkg-config file. +# But there is no pkg-config file for ctpp2. Once one exists, no need to +# declare the dependency here +ctpp2_prefix_install = get_option('ctpp2-install-prefix') +if get_option('default_library') == 'static' + libname = 'ctpp2-st' +else + libname = 'ctpp2' +endif +if ctpp2_prefix_install == '' + if not compiler.has_header('ctpp2/CTPP2Logger.hpp') + error('ctpp2/CTPP2Logger.hppnot found') + endif + ctpp2_lib = compiler.find_library(libname) + ctpp2_dep = declare_dependency(dependencies:[ctpp2_lib]) +else + ctpp2_include_path = ctpp2_prefix_install + '/include' + ctpp2_include_args = ['-I'+ctpp2_include_path] + if not compiler.has_header('ctpp2/CTPP2Logger.hpp', args:ctpp2_include_args) + error('ctpp2/CTPP2Logger.hpp not found') + endif + ctpp2_include_path = include_directories(ctpp2_include_path, is_system:true) + ctpp2_lib_path = ctpp2_prefix_install+'/lib' + ctpp2_lib = compiler.find_library(libname, dirs:ctpp2_lib_path) + ctpp2_dep = declare_dependency(include_directories:ctpp2_include_path, dependencies:[ctpp2_lib]) +endif + +all_deps = [thread_dep, kiwixlib_dep, microhttpd_dep, ctpp2_dep] + +#subdir('include') +subdir('src') diff --git a/meson_options.txt b/meson_options.txt new file mode 100644 index 0000000..886efcc --- /dev/null +++ b/meson_options.txt @@ -0,0 +1,2 @@ +option('ctpp2-install-prefix', type : 'string', value : '', + description : 'Prefix where ctpp libs has been installed') diff --git a/src/contentManager/contentManager.cpp b/src/contentManager/contentManager.cpp deleted file mode 100644 index 94fdf93..0000000 --- a/src/contentManager/contentManager.cpp +++ /dev/null @@ -1,294 +0,0 @@ -/* - * Copyright 2011 Emmanuel Engelhart - * Copyright 2011 Renaud Gaudin - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301, USA. - */ - -#include -#include -#include -#include -#include -#include -#include "contentManager.h" - -ContentManager::ContentManager(int x) : manager() {} - -bool ContentManager::OpenLibraryFromFile(string path, bool readOnly) { - try { - return this->manager.readFile(path, readOnly); - } catch (exception &e) { - cerr << e.what() << endl; - return false; - } - return true; -} - -bool ContentManager::OpenLibraryFromText(string &xml, bool readOnly) { - - bool returnValue = true; - const char *cXml; - cXml = xml.c_str(); - - try { - return this->manager.readXml(cXml, readOnly); - } catch (exception &e) { - cerr << e.what() << endl; - return false; - } - - return false; -} - -bool ContentManager::WriteLibrary() { - - try { - return this->manager.writeFile(this->manager.writableLibraryPath); - } catch (exception &e) { - cerr << e.what() << endl; - return false; - } - - return false; -} - -bool ContentManager::WriteLibraryToFile(string &path) { - - try { - return this->manager.writeFile(path.c_str()); - } catch (exception &e) { - cerr << e.what() << endl; - return false; - } - - return false; -} - -bool ContentManager::AddBookFromPath(string &path) { - - try { - return this->manager.addBookFromPath(path.c_str(), path); - } catch (exception &e) { - cerr << e.what() << endl; - return false; - } - - return false; -} - -bool ContentManager::RemoveBookById(string &id) { - - try { - return this->manager.removeBookById(id.c_str()); - } catch (exception &e) { - cerr << e.what() << endl; - return false; - } - return false; -} - -bool ContentManager::SetCurrentBookId(string &id) { - - try { - return this->manager.setCurrentBookId(id.c_str()); - } catch (exception &e) { - cerr << e.what() << endl; - return false; - } - - return false; - } - -string ContentManager::GetCurrentBookId() { - string none = ""; - try { - return this->manager.getCurrentBookId(); - } catch (exception &e) { - cerr << e.what() << endl; - return none; - } - - return none; -} - -bool ContentManager::GetBookById(string &id, - string &path, - string &title, - string &indexPath, - string &indexType, - string &description, - string &articleCount, - string &mediaCount, - string &size, - string &creator, - string &date, - string &language, - string &favicon, - string &url) { - - try { - kiwix::Book book; - - if (this->manager.getBookById(id.c_str(), book)) { - path = book.pathAbsolute.data(); - title = book.title.data(); - indexPath = book.indexPathAbsolute.data(); - articleCount = book.articleCount.data(); - mediaCount = book.mediaCount.data(); - size = book.size.data(); - creator = book.creator.data(); - date = book.date.data(); - language = book.language.data(); - url = book.url.data(); - - string faviconUrl = ""; - if (!book.faviconMimeType.empty()) { - faviconUrl = "url(data:" + book.faviconMimeType + ";base64," + book.favicon + ")"; - } - favicon = faviconUrl.data(); - - string indexTypeString = ""; - if (book.indexType == kiwix::XAPIAN) { - indexTypeString = "xapian"; - } - indexType = indexTypeString.data(); - - description = book.description.data(); - - return true; - } - } catch (exception &e) { - cerr << e.what() << endl; - return false; - } - return false; -} - -bool ContentManager::UpdateBookLastOpenDateById(string &id) { - try { - return this->manager.updateBookLastOpenDateById(id.c_str()); - } catch (exception &e) { - cerr << e.what() << endl; - return false; - } - - return false; -} - -unsigned int ContentManager::GetBookCount(const bool localBooks, const bool remoteBooks) { - int count = 0; - - try { - return this->manager.getBookCount(localBooks, remoteBooks); - } catch (exception &e) { - cerr << e.what() << endl; - return count; - } - - return count; -} - -bool ContentManager::ListBooks(string &mode, string &sortBy, unsigned int maxSize, - string &language, string &publisher, string &search) { - try { - - // Set the mode enum - kiwix::supportedListMode listMode; - if (mode == "lastOpen") { - listMode = kiwix::LASTOPEN; - } else if ( mode == "remote") { - listMode = kiwix::REMOTE; - } else { - listMode = kiwix::LOCAL; - } - - // Set the sortBy enum - kiwix::supportedListSortBy listSortBy; - if (sortBy == "publisher") { - listSortBy = kiwix::PUBLISHER; - } else if ( sortBy == "date") { - listSortBy = kiwix::DATE; - } else if ( sortBy == "size") { - listSortBy = kiwix::SIZE; - } else { - listSortBy = kiwix::TITLE; - } - - return this->manager.listBooks(listMode, listSortBy, maxSize, language.c_str(), publisher.c_str(), search.c_str()); - } catch (exception &e) { - cerr << e.what() << endl; - } - return false; -} - -const char* ContentManager::GetListNextBookId() { - - string id; - try { - if (!this->manager.bookIdList.empty()) { - id = *(this->manager.bookIdList.begin()); - this->manager.bookIdList.erase(this->manager.bookIdList.begin()); - } - } catch (exception &e) { - cerr << e.what() << endl; - } - return id.c_str(); -} - -bool ContentManager::SetBookIndex(string &id, string &path, string &indexType) { - try { - kiwix::supportedIndexType iType; - iType = kiwix::XAPIAN; - - return this->manager.setBookIndex(id.c_str(), path.c_str(), iType); - } catch (exception &e) { - cerr << e.what() << endl; - } - - return false; -} - -bool ContentManager::SetBookPath(string &id, string &path) { - try { - return this->manager.setBookPath(id.c_str(), path.c_str()); - } catch (exception &e) { - cerr << e.what() << endl; - } - return false; -} - -string ContentManager::GetBooksLanguages() { - string languagesStr = ""; - - vector booksLanguages = this->manager.getBooksLanguages(); - vector::iterator itr; - for ( itr = booksLanguages.begin(); itr != booksLanguages.end(); ++itr ) { - languagesStr += *itr + ";"; - } - return languagesStr; -} - -string ContentManager::GetBooksPublishers() { - string publishersStr = ""; - - vector booksPublishers = this->manager.getBooksPublishers(); - vector::iterator itr; - for ( itr = booksPublishers.begin(); itr != booksPublishers.end(); ++itr ) { - publishersStr += *itr + ";"; - } - return publishersStr; -} diff --git a/src/launcher/kiwix-launcher.cpp b/src/launcher/kiwix-launcher.cpp deleted file mode 100644 index 8567a6c..0000000 --- a/src/launcher/kiwix-launcher.cpp +++ /dev/null @@ -1,285 +0,0 @@ -/* - * Copyright 2012-2014 - * Renaud Gaudin - * Emmanuel Engelhart - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301, USA. - */ - -#ifdef _WIN32 -#pragma comment( linker, "/subsystem:\"windows\" /entry:\"mainCRTStartup\"" ) -#include -#include -#define EXEXT ".exe" -#define EXECL _execl -#define PUTENV _putenv -#else -#define EXEXT "" -#include -#include -#define EXECL execl -#define PUTENV putenv -#endif - -#include -#include "pathTools.h" - -using namespace std; - -/* Split string in a token array */ -std::vector split(const std::string & str, - const std::string & delims=" *-") -{ - std::string::size_type lastPos = str.find_first_not_of(delims, 0); - std::string::size_type pos = str.find_first_of(delims, lastPos); - std::vector tokens; - - while (std::string::npos != pos || std::string::npos != lastPos) - { - tokens.push_back(str.substr(lastPos, pos - lastPos)); - lastPos = str.find_first_not_of(delims, pos); - pos = str.find_first_of(delims, lastPos); - } - - return tokens; -} - -/* Quote string on Windows */ -char *prepareArgument(const char *argument) { - if (argument != NULL) { -#ifdef _WIN32 - string quotedArgument = "\"" + string(argument) + "\""; - return strdup(quotedArgument.c_str()); -#else - return strdup(argument); -#endif - } else { - return NULL; - } -} - -int main(int argc, char *argv[]) { - - /* Initialisation of a few paths */ - string executablePath = getExecutablePath(); - string executableDirectory = removeLastPathElement(executablePath); - - /* Possible xulrunner paths */ - std::vector xulrunnerPossibleDirectories; - std::vector::iterator directoriesIt; - - /* Possible xulrunner paths: local directories */ - xulrunnerPossibleDirectories.push_back(computeAbsolutePath(executableDirectory, "xulrunner")); - xulrunnerPossibleDirectories.push_back(computeAbsolutePath(executableDirectory, "kiwix/xulrunner")); - xulrunnerPossibleDirectories.push_back(computeAbsolutePath(executableDirectory, "kiwix-linux/xulrunner")); - xulrunnerPossibleDirectories.push_back(computeAbsolutePath(executableDirectory, "kiwix-win/xulrunner")); - xulrunnerPossibleDirectories.push_back(computeAbsolutePath(executableDirectory, "kiwix-windows/xulrunner")); - - /* Possible xulrunner paths: system directories */ - string binaryPath = getenv("PATH") == NULL ? "" : string(getenv("PATH")); - std::vector xulrunnerPossibleSystemDirectories = ::split(binaryPath, ":"); - for (directoriesIt = xulrunnerPossibleSystemDirectories.begin() ; - directoriesIt != xulrunnerPossibleSystemDirectories.end() ; - directoriesIt++) { - xulrunnerPossibleDirectories.push_back(*directoriesIt); - } - - /* Possible xulrunner binary names */ - std::vector xulrunnerPossibleNames; - xulrunnerPossibleNames.push_back(std::string("xulrunner") + std::string(EXEXT)); - xulrunnerPossibleNames.push_back(std::string("xulrunner-bin") + std::string(EXEXT)); - xulrunnerPossibleNames.push_back(std::string("xulrunner-") + std::string(GECKO_VERSION)); - xulrunnerPossibleNames.push_back(std::string("xulrunner-") + std::string(GECKO_VERSION) + - std::string(".0")); - xulrunnerPossibleNames.push_back(std::string("xulrunner-") + std::string(MAJOR_GECKO_VERSION)); - xulrunnerPossibleNames.push_back(std::string("xulrunner-") + std::string(MINOR_GECKO_VERSION)); - - /* Find xulrunner (binary) path */ - string xulrunnerPath; - std::vector::iterator filesIt; - directoriesIt = xulrunnerPossibleDirectories.begin(); - while (xulrunnerPath.empty() && directoriesIt != xulrunnerPossibleDirectories.end()) { - if (fileExists(*directoriesIt)) { - filesIt = xulrunnerPossibleNames.begin(); - while (xulrunnerPath.empty() && - filesIt != xulrunnerPossibleNames.end()) { - xulrunnerPath = computeAbsolutePath(*directoriesIt, *filesIt); - if (!fileExists(xulrunnerPath)) { - xulrunnerPath.clear(); - } - filesIt++; - }; - } - directoriesIt++; - } - if (!fileExists(xulrunnerPath)) { - perror("Error: unable to find the xulrunner binary."); - return EXIT_FAILURE; - } - - /* Compute xulrunner directory */ - string xulrunnerDirectory = removeLastPathElement(xulrunnerPath); - - /* Compute application.ini path */ - std::vector applicationIniPossiblePaths; - applicationIniPossiblePaths.push_back(computeAbsolutePath(executableDirectory, - "application.ini")); - applicationIniPossiblePaths.push_back(computeAbsolutePath(executableDirectory, - "kiwix/application.ini")); - applicationIniPossiblePaths.push_back(computeAbsolutePath(executableDirectory, - "kiwix-linux/application.ini")); - applicationIniPossiblePaths.push_back(computeAbsolutePath(executableDirectory, - "kiwix-win/application.ini")); - applicationIniPossiblePaths.push_back(computeAbsolutePath(executableDirectory, - "kiwix-windows/application.ini")); - - string applicationIniPath; - filesIt = applicationIniPossiblePaths.begin(); - while (applicationIniPath.empty() && - filesIt != applicationIniPossiblePaths.end()) { - if (fileExists(*filesIt)) { - applicationIniPath = *filesIt; - } - filesIt++; - }; - if (!fileExists(xulrunnerPath)) { - perror("Error: unable to find the application.ini file."); - return EXIT_FAILURE; - } - - /* Debug prints */ - /* - cout << "Executable directory (executableDirectory): " << executableDirectory << endl; - cout << "Executable path (executablePath): " << executablePath << endl; - cout << "Xulrunner directory (xulrunnerDirectory): " << xulrunnerDirectory << endl; - cout << "Xulrunner path (xulrunnerPath): " << xulrunnerPath << endl; - cout << "Application.ini path (applicationIniPath): " << applicationIniPath << endl; - */ - - /* Modify environnement variables */ -#ifdef _WIN32 - string sep = ";"; - string execlArg0 = "kiwix-launcher.exe"; -#else - string sep = ":"; - string execlArg0 = xulrunnerPath.c_str(); -#endif - - string ldLibraryPath = getenv("LD_LIBRARY_PATH") == NULL ? "" : string(getenv("LD_LIBRARY_PATH")); - string putenvStr = "LD_LIBRARY_PATH=" + xulrunnerDirectory + sep + ldLibraryPath; - PUTENV((char *)putenvStr.c_str()); - - /* Launch xulrunner */ - if (argc == 0) { - return EXECL(xulrunnerPath.c_str(), - execlArg0.c_str(), - prepareArgument(applicationIniPath.c_str()), - NULL); - } else if (argc == 1) { - return EXECL(xulrunnerPath.c_str(), - execlArg0.c_str(), - prepareArgument(applicationIniPath.c_str()), - prepareArgument(argv[1]), - NULL); - } else if (argc == 2) { - return EXECL(xulrunnerPath.c_str(), - execlArg0.c_str(), - prepareArgument(applicationIniPath.c_str()), - prepareArgument(argv[1]), - prepareArgument(argv[2]), - NULL); - } else if (argc == 3) { - return EXECL(xulrunnerPath.c_str(), - execlArg0.c_str(), - prepareArgument(applicationIniPath.c_str()), - prepareArgument(argv[1]), - prepareArgument(argv[2]), - prepareArgument(argv[3]), - NULL); - } else if (argc == 4) { - return EXECL(xulrunnerPath.c_str(), - execlArg0.c_str(), - prepareArgument(applicationIniPath.c_str()), - prepareArgument(argv[1]), - prepareArgument(argv[2]), - prepareArgument(argv[3]), - prepareArgument(argv[4]), - NULL); - } else if (argc == 5) { - return EXECL(xulrunnerPath.c_str(), - execlArg0.c_str(), - prepareArgument(applicationIniPath.c_str()), - prepareArgument(argv[1]), - prepareArgument(argv[2]), - prepareArgument(argv[3]), - prepareArgument(argv[4]), - prepareArgument(argv[5]), - NULL); - } else if (argc == 6) { - return EXECL(xulrunnerPath.c_str(), - execlArg0.c_str(), - prepareArgument(applicationIniPath.c_str()), - prepareArgument(argv[1]), - prepareArgument(argv[2]), - prepareArgument(argv[3]), - prepareArgument(argv[4]), - prepareArgument(argv[5]), - prepareArgument(argv[6]), - NULL); - } else if (argc == 7) { - return EXECL(xulrunnerPath.c_str(), - execlArg0.c_str(), - prepareArgument(applicationIniPath.c_str()), - prepareArgument(argv[1]), - prepareArgument(argv[2]), - prepareArgument(argv[3]), - prepareArgument(argv[4]), - prepareArgument(argv[5]), - prepareArgument(argv[6]), - prepareArgument(argv[7]), - NULL); - } else if (argc == 8) { - return EXECL(xulrunnerPath.c_str(), - execlArg0.c_str(), - prepareArgument(applicationIniPath.c_str()), - prepareArgument(argv[1]), - prepareArgument(argv[2]), - prepareArgument(argv[3]), - prepareArgument(argv[4]), - prepareArgument(argv[5]), - prepareArgument(argv[6]), - prepareArgument(argv[7]), - prepareArgument(argv[8]), - NULL); - } else if (argc >= 9) { - if (argc > 9) { - cerr << "Kiwix was not able to forward all your arguments to the xulrunner binary." << endl; - } - return EXECL(xulrunnerPath.c_str(), - execlArg0.c_str(), - prepareArgument(applicationIniPath.c_str()), - prepareArgument(argv[1]), - prepareArgument(argv[2]), - prepareArgument(argv[3]), - prepareArgument(argv[4]), - prepareArgument(argv[5]), - prepareArgument(argv[6]), - prepareArgument(argv[7]), - prepareArgument(argv[8]), - prepareArgument(argv[9]), - NULL); - } -} diff --git a/src/man/kiwix.1 b/src/man/kiwix.1 deleted file mode 100644 index 719ba7a..0000000 --- a/src/man/kiwix.1 +++ /dev/null @@ -1,52 +0,0 @@ -.TH KIWIX 1 "12 June 2012" -.SH NAME -Kiwix \- Offline ZIM file reader -.SH SYNOPSIS -.B kiwix [-jsconsole] [-articleByUrl] [-articleByTitle] [FILE] -.SH DESCRIPTION -.PP -Kiwix is an offline content reader for the ZIM format. -.br -ZIM files are compressed content (usually HTML) archives. -.br -Most popular ZIM includes Wikipedia and Wikileaks. - -.TP -\fB\-jsconsole\fR -Enable the Javascript Debug console (Xulrunner) -.TP -\fB\-articleByUrl url\fR -Open a specific article by url. FILE must be given. -.TP -\fB\-articleByTitle title\fR -Open a specific article by title. FILE must be given. - -.PP -Features: - * Pure ZIM file reader - * Full text search engine - * Bookmarks & Notes - * ZIM base HTTP server - * PDF/HTML export - * Localized in 80+ languages - * Search suggestions - * ZIM file indexing capacity - * Tabs navigation - * Content manager - -.SH SEE ALSO -kiwix-index(1) kiwix-install(1) kiwix-serve(1) -.br -kiwix-compact(1) kiwix-manage(1) - -.SH TROUBLESHOOTING -See http://reportabug.kiwix.org for more details on how to report bugs in Kiwix. - -.SH AUTHORS - Emmanuel Engelhart - Guillaume Duhamel - Fabien Coullon - Renaud Gaudin - Wilfredo Rodriguez -.br - Vasudev Kamath (Manual) diff --git a/src/meson.build b/src/meson.build new file mode 100644 index 0000000..79d90e0 --- /dev/null +++ b/src/meson.build @@ -0,0 +1,8 @@ + + +#subdir('indexer') +#subdir('installer') +#subdir('manager') +#subdir('reader') +#subdir('searcher') +subdir('server') diff --git a/src/server/kiwix-serve.cpp b/src/server/kiwix-serve.cpp index a91511f..760b617 100644 --- a/src/server/kiwix-serve.cpp +++ b/src/server/kiwix-serve.cpp @@ -62,11 +62,11 @@ extern "C" { #include #include #include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #ifndef _WIN32 #include diff --git a/src/server/meson.build b/src/server/meson.build new file mode 100644 index 0000000..61621f6 --- /dev/null +++ b/src/server/meson.build @@ -0,0 +1,3 @@ +executable('kiwix-serve', ['kiwix-serve.cpp'], + dependencies:all_deps, + install:true) \ No newline at end of file