mirror of https://github.com/kiwix/libkiwix.git
commit
db6717e199
|
@ -21,7 +21,9 @@
|
||||||
#define KIWIX_DOWNLOADER_H
|
#define KIWIX_DOWNLOADER_H
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <aria2/aria2.h>
|
#ifdef ENABLE_LIBARIA2
|
||||||
|
# include <aria2/aria2.h>
|
||||||
|
#endif
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
|
|
||||||
namespace kiwix
|
namespace kiwix
|
||||||
|
@ -56,14 +58,15 @@ class Downloader
|
||||||
private:
|
private:
|
||||||
static pthread_mutex_t globalLock;
|
static pthread_mutex_t globalLock;
|
||||||
|
|
||||||
aria2::Session* session;
|
|
||||||
DownloadedFile* fileHandle;
|
|
||||||
std::string tmpDir;
|
std::string tmpDir;
|
||||||
|
#ifdef ENABLE_LIBARIA2
|
||||||
|
DownloadedFile* fileHandle;
|
||||||
|
aria2::Session* session;
|
||||||
static int downloadEventCallback(aria2::Session* session,
|
static int downloadEventCallback(aria2::Session* session,
|
||||||
aria2::DownloadEvent event,
|
aria2::DownloadEvent event,
|
||||||
aria2::A2Gid gid,
|
aria2::A2Gid gid,
|
||||||
void* userData);
|
void* userData);
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
14
meson.build
14
meson.build
|
@ -17,7 +17,7 @@ thread_dep = dependency('threads')
|
||||||
libicu_dep = dependency('icu-i18n', static:static_deps)
|
libicu_dep = dependency('icu-i18n', static:static_deps)
|
||||||
libzim_dep = dependency('libzim', version : '>=4.0.0', static:static_deps)
|
libzim_dep = dependency('libzim', version : '>=4.0.0', static:static_deps)
|
||||||
pugixml_dep = dependency('pugixml', static:static_deps)
|
pugixml_dep = dependency('pugixml', static:static_deps)
|
||||||
libaria2_dep = dependency('libaria2', static:static_deps)
|
libaria2_dep = dependency('libaria2', static:static_deps, required:false)
|
||||||
|
|
||||||
ctpp2_include_path = ''
|
ctpp2_include_path = ''
|
||||||
has_ctpp2_dep = false
|
has_ctpp2_dep = false
|
||||||
|
@ -88,6 +88,13 @@ inc = include_directories('include')
|
||||||
conf = configuration_data()
|
conf = configuration_data()
|
||||||
conf.set('VERSION', '"@0@"'.format(meson.project_version()))
|
conf.set('VERSION', '"@0@"'.format(meson.project_version()))
|
||||||
conf.set('ENABLE_CTPP2', has_ctpp2_dep)
|
conf.set('ENABLE_CTPP2', has_ctpp2_dep)
|
||||||
|
conf.set('ENABLE_LIBARIA2', libaria2_dep.found())
|
||||||
|
|
||||||
|
if build_machine.system() == 'windows'
|
||||||
|
extra_link_args = ['-lshlwapi', '-lwinmm']
|
||||||
|
else
|
||||||
|
extra_link_args = []
|
||||||
|
endif
|
||||||
|
|
||||||
subdir('include')
|
subdir('include')
|
||||||
subdir('scripts')
|
subdir('scripts')
|
||||||
|
@ -95,7 +102,10 @@ subdir('static')
|
||||||
subdir('src')
|
subdir('src')
|
||||||
subdir('test')
|
subdir('test')
|
||||||
|
|
||||||
pkg_requires = ['libzim', 'icu-i18n', 'pugixml', 'libaria2']
|
pkg_requires = ['libzim', 'icu-i18n', 'pugixml']
|
||||||
|
if libaria2_dep.found()
|
||||||
|
pkg_requires += ['libaria2']
|
||||||
|
endif
|
||||||
if xapian_dep.found()
|
if xapian_dep.found()
|
||||||
pkg_requires += ['xapian-core']
|
pkg_requires += ['xapian-core']
|
||||||
endif
|
endif
|
||||||
|
|
|
@ -2,3 +2,5 @@
|
||||||
#mesondefine VERSION
|
#mesondefine VERSION
|
||||||
|
|
||||||
#mesondefine ENABLE_CTPP2
|
#mesondefine ENABLE_CTPP2
|
||||||
|
|
||||||
|
#mesondefine ENABLE_LIBARIA2
|
||||||
|
|
|
@ -20,7 +20,9 @@
|
||||||
#include "downloader.h"
|
#include "downloader.h"
|
||||||
#include "common/pathTools.h"
|
#include "common/pathTools.h"
|
||||||
|
|
||||||
#include <unistd.h>
|
#ifndef _WIN32
|
||||||
|
# include <unistd.h>
|
||||||
|
#endif
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
namespace kiwix
|
namespace kiwix
|
||||||
|
@ -32,6 +34,7 @@ pthread_mutex_t Downloader::globalLock = PTHREAD_MUTEX_INITIALIZER;
|
||||||
/* Constructor */
|
/* Constructor */
|
||||||
Downloader::Downloader()
|
Downloader::Downloader()
|
||||||
{
|
{
|
||||||
|
#ifdef ENABLE_LIBARIA2
|
||||||
aria2::SessionConfig config;
|
aria2::SessionConfig config;
|
||||||
config.downloadEventCallback = Downloader::downloadEventCallback;
|
config.downloadEventCallback = Downloader::downloadEventCallback;
|
||||||
config.userData = this;
|
config.userData = this;
|
||||||
|
@ -39,17 +42,20 @@ Downloader::Downloader()
|
||||||
aria2::KeyVals options;
|
aria2::KeyVals options;
|
||||||
options.push_back(std::pair<std::string, std::string>("dir", tmpDir));
|
options.push_back(std::pair<std::string, std::string>("dir", tmpDir));
|
||||||
session = aria2::sessionNew(options, config);
|
session = aria2::sessionNew(options, config);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Destructor */
|
/* Destructor */
|
||||||
Downloader::~Downloader()
|
Downloader::~Downloader()
|
||||||
{
|
{
|
||||||
|
#ifdef ENABLE_LIBARIA2
|
||||||
aria2::sessionFinal(session);
|
aria2::sessionFinal(session);
|
||||||
|
#endif
|
||||||
rmdir(tmpDir.c_str());
|
rmdir(tmpDir.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef ENABLE_LIBARIA2
|
||||||
int Downloader::downloadEventCallback(aria2::Session* session,
|
int Downloader::downloadEventCallback(aria2::Session* session,
|
||||||
aria2::DownloadEvent event,
|
aria2::DownloadEvent event,
|
||||||
aria2::A2Gid gid,
|
aria2::A2Gid gid,
|
||||||
|
@ -85,10 +91,12 @@ int Downloader::downloadEventCallback(aria2::Session* session,
|
||||||
aria2::deleteDownloadHandle(dh);
|
aria2::deleteDownloadHandle(dh);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
DownloadedFile Downloader::download(const std::string& url) {
|
DownloadedFile Downloader::download(const std::string& url) {
|
||||||
pthread_mutex_lock(&globalLock);
|
pthread_mutex_lock(&globalLock);
|
||||||
DownloadedFile fileHandle;
|
DownloadedFile fileHandle;
|
||||||
|
#ifdef ENABLE_LIBARIA2
|
||||||
try {
|
try {
|
||||||
std::vector<std::string> uris = {url};
|
std::vector<std::string> uris = {url};
|
||||||
aria2::KeyVals options;
|
aria2::KeyVals options;
|
||||||
|
@ -106,6 +114,7 @@ DownloadedFile Downloader::download(const std::string& url) {
|
||||||
} catch (...) {};
|
} catch (...) {};
|
||||||
this->fileHandle = nullptr;
|
this->fileHandle = nullptr;
|
||||||
pthread_mutex_unlock(&globalLock);
|
pthread_mutex_unlock(&globalLock);
|
||||||
|
#endif
|
||||||
return fileHandle;
|
return fileHandle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,9 @@
|
||||||
#include "xapianSearcher.h"
|
#include "xapianSearcher.h"
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <unicode/locid.h>
|
#include <unicode/locid.h>
|
||||||
#include <unistd.h>
|
#ifndef _WIN32
|
||||||
|
# include <unistd.h>
|
||||||
|
#endif
|
||||||
#include <zim/article.h>
|
#include <zim/article.h>
|
||||||
#include <zim/error.h>
|
#include <zim/error.h>
|
||||||
#include <zim/file.h>
|
#include <zim/file.h>
|
||||||
|
|
|
@ -10,6 +10,7 @@ gtest_dep = dependency('gtest', fallback: ['gtest', 'gtest_dep'])
|
||||||
foreach test_name : tests
|
foreach test_name : tests
|
||||||
test_exe = executable(test_name, [test_name+'.cpp'],
|
test_exe = executable(test_name, [test_name+'.cpp'],
|
||||||
link_with : kiwixlib,
|
link_with : kiwixlib,
|
||||||
|
link_args: extra_link_args,
|
||||||
dependencies : all_deps + [gtest_dep],
|
dependencies : all_deps + [gtest_dep],
|
||||||
build_rpath : '$ORIGIN')
|
build_rpath : '$ORIGIN')
|
||||||
test(test_name, test_exe)
|
test(test_name, test_exe)
|
||||||
|
|
Loading…
Reference in New Issue