77 Commits
0.2 ... 0.4.0

Author SHA1 Message Date
Matthieu Gautier
c6ace1eafc Merge pull request #171 from kiwix/new_version
New version 0.4.0
2018-03-27 12:03:21 +02:00
Matthieu Gautier
8552985cd4 New version 0.4.0 2018-03-27 11:20:21 +02:00
Matthieu Gautier
9997a6ec18 Merge pull request #169 from kiwix/infinit_redirect
Correctly pre-increment the loopCounter.
2018-03-26 10:04:28 +02:00
Matthieu Gautier
8b6abc0e35 Correctly pre-increment the loopCounter.
In case of infinit redirection, if we post-increment the loop counter,
we will exit the loop when loopCounter will be 42 and increment it.
So loop counter will be 43.

Let's pre-increment the counter to still compare with 42 (more consistancy)

Fix #168
2018-03-25 17:07:38 +02:00
Kelson
426796dc37 Merge pull request #135 from kiwix/search_suggestions
Update usage() with --suggestion
2017-12-20 19:54:22 +01:00
kelson42
712cdf5e7b Update usage() with --suggestion 2017-12-20 19:07:38 +01:00
Matthieu Gautier
74cc1d0708 Merge pull request #133 from kiwix/better_search_tool
Better search tool
2017-12-19 15:24:29 +01:00
Matthieu Gautier
3ce668af66 Add a suggestion option to search in suggestion.
There are two kinds of search system :
- Suggestion (search in title only)
- "Classical" search (search in whole content)

The option `--suggestion` allow `kiwix-search` to search for suggestion.
Without the option, a "classical" search is made.

Fix #132.
2017-12-19 14:17:15 +01:00
Matthieu Gautier
2b69cc8ffc Pass verboseFlag to underlying kiwix::Searcher. 2017-12-19 14:13:36 +01:00
Matthieu Gautier
71ffaaa05a Merge pull request #127 from kiwix/compilation_fixes
Compilation fixes
2017-12-13 16:26:57 +00:00
Matthieu Gautier
f3fb5d61cc Use correct option to compile a static binary in travis.
We must use custom option `static-linkage` instead of meson's
`default-library`.
2017-12-13 17:17:28 +01:00
Matthieu Gautier
05c63536de Force usage of meson 0.43.0.
Static compilation is broken with meson 0.44.0.
2017-12-13 16:43:42 +01:00
Matthieu Gautier
16e12ad463 Stop workaround xapian-core.pc
`xapian-core.pc` is now correct stop workaround it adding extra
link args.
The workaround is broken with meson 0.44.0 and static compilation.

However, libmicrohttpd is using `librt` if present but doesn't declare
it in its `libmicrohttpd.pc` file so we must add it manually if we found
it.
2017-12-13 16:43:08 +01:00
Matthieu Gautier
c91285fc29 Merge pull request #123 from kiwix/fix_crash
Fix crash
2017-12-04 16:04:08 +00:00
Matthieu Gautier
5c11ff1a30 Correctly cast to int in debug message.
A `class enum` is not implicitly cast to an `int`.
It is better to explicitly cast it to avoid future error with different
versions of compiler.
2017-12-04 15:12:27 +00:00
Matthieu Gautier
9eaf512bf9 Correctly handle NULL string for request arguments.
When iterating over arguments of a request, the value can be a null pointer
if the argument is provided without a `=`.
https://www.gnu.org/software/libmicrohttpd/manual/html_node/microhttpd_002drequests.html

We have to handle this correctly.

Should fix #116.
2017-12-04 15:10:45 +00:00
Matthieu Gautier
9a29874f9f Better verbose message.
The parsing of the request in the `RequestContext` constructor may be
buggy and make kiwix-serve crash.

If we print debug information only after the request is parsed, we will
never print the debug information if the parsing crash.

It is better to, at least, write that we've got a new request to avoid
us to try to debug previous request where everything were ok.
2017-12-04 15:08:18 +00:00
Matthieu Gautier
aa9647e88c Merge pull request #122 from kiwix/gcc5
Compile using gcc-5 on native ubuntu.
2017-12-04 12:29:59 +00:00
Matthieu Gautier
da0c697963 Compile using gcc-5 on native ubuntu.
As dependencies prepared by kiwix-build are build using gcc-5
(kiwix/kiwix-build@7fc557d), we need to also compile libzim using gcc-5.
2017-12-04 11:15:50 +00:00
Matthieu Gautier
77d25686cb Merge pull request #115 from kiwix/better_search_handling
Better search handling
2017-11-29 16:21:45 +00:00
Matthieu Gautier
3df2fa708b Set the global humanReadableId.
This is needed by kiwix-lib to generate correct "next page" links.
2017-11-27 12:45:41 +00:00
Matthieu Gautier
9021f87715 Handle search with no content and empty query string.
We need to handle :

 - No content because it is how we do multisearch.
 - No query string because it is how we can do geosearch.
2017-11-27 12:44:25 +00:00
Matthieu Gautier
04b05b7902 Merge pull request #111 from kiwix/better_request_parsing
Better request parsing
2017-11-27 11:39:10 +00:00
Matthieu Gautier
a8e73aab98 Move the request context out of kiwix-serve.cpp.
RequestContext is now a "complex" class that handle a lot of thing for
the handlers :
- The rootLocation is correctly handle and remove from the url.
  So a handler doesn't have to care about it (when parsing the url)
- Request arguments and header are stored in a map and there are access
  methods to get it.
- Request arguments can be automatically convert to other type than string.
- Better parsing of the `byte` header. Related to #91.
2017-11-27 11:20:02 +00:00
Matthieu Gautier
234a9d9719 Let the different handlers look for the reader/searcher.
It is to the handlers to get the right reader/searcher they want and
create correct error/default page if the name doesn't correspond to a
zim file.

The `handle_default` function has also be renamed to `build_homepage`
because it is what is done. (And it doesn't handle a request).
2017-11-22 16:16:54 +00:00
Matthieu Gautier
c93617473d Move some variable out of the request's context.
`humanReadableBookId`, `reader` and `searcher` are not so global that
it seems.

Let's move it out of the request object as handler may or not use them.
2017-11-22 15:53:34 +00:00
Matthieu Gautier
09e2039aff Rename variable request_context to request. 2017-11-22 15:47:23 +00:00
Matthieu Gautier
5c6a1870b9 Merge pull request #107 from kiwix/geo_loc
Add a small (private) support for geo query.
2017-11-22 12:46:47 +01:00
Matthieu Gautier
4fffaf41b6 Add a small (private) support for geo query.
This use the small API of kiwix-lib and so, cannot search a text query
and filter around a geo position in the same time.

There is no way to do a search but than write directly the search url
by hand.

If the request is wrongly formatted, the search is simply not done without
error message.
2017-11-14 17:42:01 +01:00
Matthieu Gautier
05c734fc31 Merge pull request #104 from kiwix/library_relative_path
Relative paths are relative to current directory not executable.
2017-11-13 15:14:42 +01:00
Matthieu Gautier
fa9b027a39 Relative paths are relative to current directory not executable.
Almost nothing should be relative to the executable directory.
Content coming from the user should be relative to where the user
is (its working directory).

Fixes #70.
2017-11-13 14:42:52 +01:00
Matthieu Gautier
1fcc1ad9d4 Merge pull request #98 from kiwix/http_byte_range_fix
Fix HTTP request byte range handling #91
2017-11-13 14:42:16 +01:00
kelson42
5fd8dd3c36 Fix HTTP request byte range handling #91 2017-11-13 12:01:45 +01:00
Matthieu Gautier
f03ed85972 Merge pull request #87 from swiftugandan/master
do not cache results for searches from the welcome page
2017-11-09 15:48:15 +01:00
Philip Munaawa
52308b764d do not cache results for searches from the welcome page 2017-11-09 14:24:03 +00:00
Kelson
03bac00019 Merge pull request #99 from kiwix/dattaz-patch_issue_19_good
Dattaz patch issue 19 good
2017-11-08 20:19:57 +01:00
kelson42
905b83b3b1 Small beautification of the code 2017-11-08 20:11:55 +01:00
dattaz
894ed12f37 escape the & character of humanReadableBookId to not be interpreted in urls as a new argument 2017-11-08 19:50:23 +01:00
Kelson
573b826861 Merge pull request #62 from kiwix/julianharty-patch-1
Update kiwix-serve.cpp
2017-11-07 20:01:28 +01:00
Julian Harty
8051773124 Fixed a typo in an error message 2017-11-07 19:10:23 +01:00
Matthieu Gautier
69dd6cd869 Merge pull request #94 from kiwix/man_cleaning
Remove kiwix-index and kiiwx-compact man pages
2017-11-06 15:45:11 +01:00
kelson42
8d32bfd16e Remove kiwix-index and kiiwx-compact man pages 2017-11-06 15:31:06 +01:00
Matthieu Gautier
b1d2a1378b Merge pull request #90 from kiwix/new_release
Release of kiwix-tools 0.3.0.
2017-10-24 11:29:34 +02:00
Matthieu Gautier
df7d44128c Release of kiwix-tools 0.3.0. 2017-10-23 11:40:00 +02:00
Matthieu Gautier
ee5333bb91 Merge pull request #86 from kiwix/swiftugandan_root
Swiftugandan root
2017-10-17 16:21:04 +02:00
Philip Munaawa
871d8f4a51 disable caching for the welcome page 2017-10-17 15:46:55 +02:00
Philip Munaawa
9280d519f5 Adding support for relative url location 2017-10-17 15:46:11 +02:00
Matthieu Gautier
540fcd3be9 Merge pull request #84 from kiwix/byte_range
Byte range
2017-10-11 17:14:01 +02:00
Matthieu Gautier
ad7238b0c9 Stop refusing the first connection.
I don't know why we are refusing the first connection.

It seems to work without this.
Moreover, this is not thread safe and it would be pretty complex to
make it thread safe.
2017-10-11 17:00:55 +02:00
Matthieu Gautier
b5c91417ff Better debug information of each request. 2017-10-11 17:00:55 +02:00
Matthieu Gautier
b638df81fa Implement response to bytes range request.
Handle bytes range request http header.
Do not read the full buffer but try to stream it as far as possible.
2017-10-11 17:00:55 +02:00
Matthieu Gautier
58f0a716a6 Correctly return 404 if asked skin is not existing.
Fix #83
2017-10-10 17:02:15 +02:00
Matthieu Gautier
a2324b5e8b Use a structure RequestContext to pass all the context of a request.
This simplifies the code and avoid to pass a lot of arguments to
each function.
2017-10-10 16:59:45 +02:00
Matthieu Gautier
c2ac40d4f5 Merge pull request #82 from kiwix/multi_thread
Make kiwix-server multi-threaded.
2017-10-10 14:43:50 +02:00
Matthieu Gautier
4534b51f5e Use printf instead of cout.
`std::cout` stream is not thread safe at all.
Printing from different threads can lead to corrupted stream (and no
output working).

Using `printf` may still lead to interleaved output but nothing will broke.
2017-10-10 14:39:42 +02:00
Matthieu Gautier
0364951f75 Make kiwix-server multi-threaded. 2017-10-03 16:35:03 +02:00
Matthieu Gautier
a2627e81c4 Merge pull request #78 from kiwix/patch-1
Look for renamed kiwix-compile-resources script as well
2017-09-27 19:15:57 +02:00
Kunal Mehta
cd72a2d73c Look for renamed kiwix-compile-resources script as well
See https://github.com/kiwix/kiwix-lib/pull/76
2017-09-27 19:10:57 +02:00
Matthieu Gautier
fa3f33d3c7 Use sudo to install pip dependencies in travis 2017-09-27 19:03:11 +02:00
Matthieu Gautier
a210cb3a4b Merge pull request #68 from kiwix/css_taskbar
Css taskbar
2017-08-15 15:51:09 -04:00
Matthieu Gautier
63cb47247b Serve the taskbar css as separated file.
For firefox, the file encoding must be specified in the first 1024 bytes.
If it is not, firefox will reload the page when it founds it.

By inserting the taskbar's css directly in the html, we are "moving" down
the encoding of the page, and the encoding is not inside the first 1024
bytes.

This also improve a bit the performance as the browser can cache the css
file and it's avoid us to send the css in earch html file.
2017-08-15 15:15:26 -04:00
Matthieu Gautier
3220ee1276 Move <link> tag in <head> tag.
In html, the link tag should be in head tag, not in the body tag.
2017-08-15 15:08:56 -04:00
Matthieu Gautier
4a1b9cbfa9 Merge pull request #67 from kiwix/no_globalsearch_on_zim
Do not do globalSearch if the zim file has no full text index.
2017-08-15 14:54:35 -04:00
Matthieu Gautier
f2b5904221 Do not do globalSearch if the zim file has no full text index.
Global search is made only on the global task bar.
Task bar display in the article should provide full text search only
if the zim file has associated full text index.

This is done by having a `NULL` searcher. However, commit `558a0375`
return the globalSearcher if no searcher is associated to a zim.

This commit associate a `NULL` searcher to the zim, so we will not use
the globalSearcher.
2017-08-13 11:35:57 -04:00
Matthieu Gautier
f44722fbbc Merge pull request #64 from kiwix/fix_protocol
Correctly set ProtocolPrefix and SearchProtocolPrefix for searcher.
2017-08-11 00:44:28 -04:00
Matthieu Gautier
0cfcc59437 Update to new kiwix-lib API about Searcher instantiation.
`kiwix-lib` remove `setContentHumanReadableId` method in favour of
specifying directly it in the constructor.
2017-08-10 09:45:08 -04:00
Matthieu Gautier
7776eafbfc Correctly set ProtocolPrefix and SearchProtocolPrefix for searcher.
Default `protocolPrefix` for the kiwix-lib searcher is `zim:://`.
We have to change it to `/` for all searcher we create else the search's
results will have a `zim://...` url, which will obviously won't work.
2017-08-09 20:20:56 -04:00
Matthieu Gautier
5989146931 Merge pull request #49 from kiwix/globalSearch
Global search
2017-07-19 09:54:31 +02:00
Matthieu Gautier
ea088b21a4 Introduce a global taskbar on the welcomeHTML page to allow global search.
Global search is a search on all zims.
2017-07-17 18:24:27 +02:00
Matthieu Gautier
558a0375b0 Use a globalSearcher to do multi search on all zims. 2017-07-17 18:23:12 +02:00
Matthieu Gautier
5f0a05e8d8 Add a global_taskbar.html.part file to be use as taskbar in library home.
This is a simplified version of taskbar.html.part without the buttons
(specific to the current read zim)
2017-07-17 18:20:55 +02:00
Matthieu Gautier
4b9dc39c49 Use only one lock to acces zim library.
Search can now use reader. So there is no need to have to different locks.
2017-07-17 18:17:33 +02:00
Matthieu Gautier
08f2373360 Merge pull request #48 from kiwix/no_use_of_tree_h
Remove use of tree.h
2017-07-12 14:45:38 +02:00
Matthieu Gautier
82fb6bc4d0 Remove use of tree.h
All code using tree.h where commented.
As tree.h where install by kiwix-lib and we removed it there, let's remove
its use here.
2017-07-12 10:28:40 +02:00
Matthieu Gautier
17eceeff5b Merge pull request #46 from kiwix/format_code
Format code
2017-07-12 10:06:46 +02:00
Matthieu Gautier
aef20d6c96 Move to C++11.
Code and kiwix-lib are C++11. So compile using C++11.
2017-07-12 10:01:25 +02:00
Matthieu Gautier
4e3ff03059 Format all the code using clang-format.
Add a script `format_code.sh` to easily format the code.
2017-07-05 15:52:32 +02:00
34 changed files with 1405 additions and 958 deletions

12
.clang-format Normal file
View File

@@ -0,0 +1,12 @@
BasedOnStyle: Google
BinPackArguments: false
BinPackParameters: false
BreakBeforeBinaryOperators: All
BreakBeforeBraces: Linux
DerivePointerAlignment: false
SpacesInContainerLiterals: false
Standard: Cpp11
AllowShortFunctionsOnASingleLine: Inline
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false

View File

@@ -2,10 +2,22 @@ language: cpp
dist: trusty
sudo: required
cache: ccache
before_install:
- eval "${MATRIX_EVAL}"
- ${CXX} --version
install: travis/install_deps.sh
script: travis/compile.sh
env:
- PLATFORM="native_static"
- PLATFORM="native_dyn"
- PLATFORM="win32_static"
- PLATFORM="win32_dyn"
global:
- MATRIX_EVAL="CC=gcc-5 && CXX=g++-5"
matrix:
- PLATFORM="native_static"
- PLATFORM="native_dyn"
- PLATFORM="win32_static"
- PLATFORM="win32_dyn"
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- g++-5

View File

@@ -1,10 +1,57 @@
kiwix-tools 0.4.0
=================
* Use gcc-5 on travis.
kiwix-serve
-----------
* Accept zim file with `&` in the name
* Do not cache (on client side) global search (as it can depends on the zim
files handled)
* Fix HTTP byte range handling. (#91)
* Fix opening of relative path (#70)
* Add a small (and hidden) API to do geo search.
* Better request parsing. (#91)
* Better handling of invalid request (#116)
* Various bug fixes (#146, #150, #153, #165, #168, #165)
kiwix-search
------------
* Add an option `--suggestion` to do suggestion search with
kiwix-search.(#132)
kiwix-tools 0.3.0
=================
* Move to C++11
kiwix-serve
-----------
* Add a global taskbar in the welcome page to search in all zims (#49)
* Serve the taskbar as css file instead of including it in the html (#68):
* Better client caching
* The html encoding is now in the first 1024 bytes and firefox correctly
detect the encoding
* Make kiwix-server multi-threaded (#82)
* Correctly return 404 instead of crashing when request inexistant skin file
(#83)
* Correctly respond to bytes-range requests.(#84)
* Directly respond to first request for a url instead of refusing the first
connexion
* Add support to relative url location. (#86)
* Remove caching (on client side) for the welcome page. (#86)
kiwix-tools 0.2.0
=================
* Remove indexer tools
kiwix-serve
----------
-----------
* Correctly fix the deflate data we send over http. (#15)
* Update in the taskbar (or topbar):

15
format_code.sh Executable file
View File

@@ -0,0 +1,15 @@
#!/usr/bin/bash
files=(
"src/installer/kiwix-install.cpp"
"src/searcher/kiwix-search.cpp"
"src/reader/kiwix-read.cpp"
"src/manager/kiwix-manage.cpp"
"src/server/kiwix-serve.cpp"
)
for i in "${files[@]}"
do
echo $i
clang-format -i -style=file $i
done

View File

@@ -1,6 +1,7 @@
project('kiwix-tools', 'cpp',
version : '0.2.0',
license : 'GPL')
version : '0.4.0',
license : 'GPL',
default_options: ['c_std=c11', 'cpp_std=c++11'])
compiler = meson.get_compiler('cpp')
@@ -10,26 +11,18 @@ if static_linkage
endif
thread_dep = dependency('threads')
kiwixlib_dep = dependency('kiwix', static:static_linkage)
kiwixlib_dep = dependency('kiwix', version:'>=1.0.0', static:static_linkage)
microhttpd_dep = dependency('libmicrohttpd', static:static_linkage)
z_dep = dependency('zlib', static:static_linkage)
# This is a temporary workaround until xapian fix it's xapian-core.pc
# For a correct dependency checking we should test if uuid is really installed
# but for a workaround, we assume that in xapian is installed, uuid also.
if meson.is_cross_build() and host_machine.system() == 'windows'
# xapian doesn't use uuid on windows.
uuid_dep = declare_dependency()
else
xapian_dep = dependency('xapian-core', required : false)
if xapian_dep.found()
uuid_dep = declare_dependency(link_args:['-luuid', '-lrt'])
else
uuid_dep = declare_dependency()
endif
endif
all_deps = [thread_dep, kiwixlib_dep, microhttpd_dep, z_dep]
all_deps = [thread_dep, kiwixlib_dep, microhttpd_dep, z_dep, uuid_dep]
if static_linkage
librt = compiler.find_library('rt', required:false)
if librt.found()
all_deps += librt
endif
endif
#subdir('include')
subdir('static')

View File

@@ -19,21 +19,23 @@
#include <getopt.h>
#include <kiwix/common/pathTools.h>
#include <kiwix/reader.h>
#include <kiwix/manager.h>
#include <kiwix/reader.h>
enum supportedAction { NONE, ADDCONTENT };
void usage() {
cout << "Usage: kiwix-install [--verbose] addcontent ZIM_PATH KIWIX_PATH" << endl;
exit(1);
void usage()
{
cout << "Usage: kiwix-install [--verbose] addcontent ZIM_PATH KIWIX_PATH"
<< endl;
exit(1);
}
int main(int argc, char **argv) {
int main(int argc, char** argv)
{
/* Init the variables */
const char *contentPath = NULL;
const char *kiwixPath = NULL;
const char* contentPath = NULL;
const char* kiwixPath = NULL;
supportedAction action = NONE;
bool verboseFlag = false;
int option_index = 0;
@@ -41,36 +43,33 @@ int main(int argc, char **argv) {
/* Argument parsing */
while (42) {
static struct option long_options[] = {
{"verbose", no_argument, 0, 'v'},
{0, 0, 0, 0}
};
static struct option long_options[]
= {{"verbose", no_argument, 0, 'v'}, {0, 0, 0, 0}};
if (c != -1) {
c = getopt_long(argc, argv, "vi", long_options, &option_index);
switch (c) {
case 'v':
verboseFlag = true;
break;
case 'v':
verboseFlag = true;
break;
}
} else {
if (optind < argc) {
if (action == NONE) {
string actionString = argv[optind++];
if (actionString == "addcontent" || actionString == "ADDCONTENT") {
action = ADDCONTENT;
}
} else if (contentPath == NULL) {
contentPath = argv[optind++];
} else if (kiwixPath == NULL) {
kiwixPath = argv[optind++];
} else {
usage();
}
if (action == NONE) {
string actionString = argv[optind++];
if (actionString == "addcontent" || actionString == "ADDCONTENT") {
action = ADDCONTENT;
}
} else if (contentPath == NULL) {
contentPath = argv[optind++];
} else if (kiwixPath == NULL) {
kiwixPath = argv[optind++];
} else {
usage();
}
} else {
break;
break;
}
}
}
@@ -82,38 +81,48 @@ int main(int argc, char **argv) {
/* Make the action */
if (action == ADDCONTENT) {
/* Check if the content path exists and is readable */
if (verboseFlag) { std::cout << "Check if the ZIM file exists..." << std::endl; }
if (verboseFlag) {
std::cout << "Check if the ZIM file exists..." << std::endl;
}
if (!fileExists(contentPath)) {
cerr << "The content path '" << contentPath << "' does not exist or is not readable." << endl;
cerr << "The content path '" << contentPath
<< "' does not exist or is not readable." << endl;
exit(1);
}
/* Check if this is a ZIM file */
try {
if (verboseFlag) { std::cout << "Check if the ZIM file is valid..." << std::endl; }
kiwix::Reader *reader = new kiwix::Reader(contentPath);
if (verboseFlag) {
std::cout << "Check if the ZIM file is valid..." << std::endl;
}
kiwix::Reader* reader = new kiwix::Reader(contentPath);
delete reader;
} catch (exception &e) {
cerr << "The content available at '" << contentPath << "' is not a ZIM file." << endl;
} catch (exception& e) {
cerr << "The content available at '" << contentPath
<< "' is not a ZIM file." << endl;
exit(1);
}
string contentFilename = getLastPathElement(contentPath);
/* Check if kiwixPath/kiwix/kiwix.exe exists */
if (verboseFlag) { std::cout << "Check if the Kiwix path is valid..." << std::endl; }
if (verboseFlag) {
std::cout << "Check if the Kiwix path is valid..." << std::endl;
}
string kiwixBinaryPath = computeAbsolutePath(kiwixPath, "kiwix/kiwix.exe");
if (!fileExists(kiwixBinaryPath)) {
kiwixBinaryPath = computeAbsolutePath(kiwixPath, "kiwix/kiwix");
if (!fileExists(kiwixBinaryPath)) {
cerr << "Unable to find the Kiwix binary at '" << kiwixBinaryPath << "[.exe]'." << endl;
exit(1);
cerr << "Unable to find the Kiwix binary at '" << kiwixBinaryPath
<< "[.exe]'." << endl;
exit(1);
}
}
/* Check if the directory "data" structure exists */
if (verboseFlag) { std::cout << "Check the target data directory structure..." << std::endl; }
if (verboseFlag) {
std::cout << "Check the target data directory structure..." << std::endl;
}
string dataPath = computeAbsolutePath(kiwixPath, "data/");
if (!fileExists(dataPath)) {
makeDirectory(dataPath);
@@ -132,22 +141,31 @@ int main(int argc, char **argv) {
}
/* Copy the file to the data/content directory */
if (verboseFlag) { std::cout << "Copy ZIM file to the target directory..." << std::endl; }
string newContentPath = computeAbsolutePath(dataContentPath, contentFilename);
if (!fileExists(newContentPath) || getFileSize(contentPath) != getFileSize(newContentPath)) {
if (verboseFlag) {
std::cout << "Copy ZIM file to the target directory..." << std::endl;
}
string newContentPath
= computeAbsolutePath(dataContentPath, contentFilename);
if (!fileExists(newContentPath)
|| getFileSize(contentPath) != getFileSize(newContentPath)) {
copyFile(contentPath, newContentPath);
}
/* Add the file to the library.xml */
if (verboseFlag) { std::cout << "Create the library XML file..." << std::endl; }
if (verboseFlag) {
std::cout << "Create the library XML file..." << std::endl;
}
kiwix::Manager libraryManager;
string libraryPath = computeAbsolutePath(dataLibraryPath, contentFilename + ".xml");
string bookId = libraryManager.addBookFromPathAndGetId(newContentPath, "../content/" + contentFilename, "", false);
string libraryPath
= computeAbsolutePath(dataLibraryPath, contentFilename + ".xml");
string bookId = libraryManager.addBookFromPathAndGetId(
newContentPath, "../content/" + contentFilename, "", false);
if (!bookId.empty()) {
libraryManager.setCurrentBookId(bookId);
libraryManager.writeFile(libraryPath);
} else {
cerr << "Unable to build or save library file '" << libraryPath << "'" << endl;
cerr << "Unable to build or save library file '" << libraryPath << "'"
<< endl;
}
}

View File

@@ -1,23 +0,0 @@
.TH KIWIX 1 "21 May 2012"
.SH NAME
kiwix-compact \- Compacteur d'index pour fichier ZIM
.SH SYNOPSIS
.IX Header SYNOPSIS
kiwix-compact INDEX_PATH
.SH DESCRIPTION
.PP
Compacte les fichiers d'index des ZIM à l'aide de xapian-compact.
.TP
\fBINDEX_PATH\fR
Chemin de l'index plein texte à compacter.
.SH SEE ALSO
kiwix(1) kiwix-index(1) kiwix-manage(1) xapian-compact(1)
.br
kiwix-install(1) kiwix-serve(1)
.SH AUTHOR
Emmanuel Engelhart <kelson@kiwix.org>
.br
Vasudev Kamath <kamathvasudev@gmail.com> (Manual)

View File

@@ -1,31 +0,0 @@
.TH KIWIX 1 "21 May 2012"
.SH NAME
kiwix\-index \- Indexeur de fichiers ZIM
.SH SYNOPSIS
.IX Header SYNOPSIS
kiwix\-index [\-\-backend|\-b=xapian|clucene] ZIM_PATH INDEX_PATH
.SH DESCRIPTION
.PP
Génère un index plein texte xapian ou cLucene pour un fichier ZIM.
.TP
\fB\-\-backend=xapian|clucene\fR
Séléctionne un moteur d'indexation.
.TP
\fBZIM_PATH\fR
Chemin du fichier ZIM à indexer.
.TP
\fBINDEX_PATH\fR
Chemin où enregistrer l'index plein texte.
.SH SEE ALSO
kiwix\-compact(1) kiwix\-manage(1) kiwix\-serve(1)
.br
kiwix(1) kiwix\-install(1)
.SH AUTHOR
Emmanuel Engelhart <kelson@kiwix.org>
.br
Vasudev Kamath <kamathvasudev@gmail.com> (Manual)

View File

@@ -33,8 +33,8 @@ Chemin d'accès dossier kiwix/.
Le chemin doit contenit le binaire statique de Kiwix.
.SH SEE ALSO
kiwix(1) kiwix\-index(1) kiwix\-serve(1) kiwix\-compact(1) kiwix\-manage(1)
kiwix(1) kiwix\-serve(1) kiwix\-manage(1)
.SH AUTHOR
Emmanuel Engelhart <kelson@kiwix.org>
.br
Vasudev Kamath <kamathvasudev@gmail.com> (Manual)
Vasudev Kamath <kamathvasudev@gmail.com> (Manual)

View File

@@ -57,8 +57,8 @@ Chemin vers l'index plein texte correspondant au fichier ZIM.
Définit l'adresse URL corresponsant au fichier ZIM pour pouvoir être téléchargé depuis Kiwix.
.SH SEE ALSO
kiwix(1) kiwix\-index(1) kiwix\-install(1) kiwix\-serve(1) kiwix\-compact(1)
kiwix(1) kiwix\-install(1) kiwix\-serve(1)
.SH AUTHOR
Emmanuel Engelhart <kelson@kiwix.org>
.br
Vasudev Kamath <kamathvasudev@gmail.com> (Manual)
Vasudev Kamath <kamathvasudev@gmail.com> (Manual)

View File

@@ -52,10 +52,10 @@ Chemin vers le fichier bibliothèque de Kiwix.
Le fichier bibliothèque est un fichier XML créé avec \fBkiwix-manage\fB.
.SH SEE ALSO
kiwix(1) kiwix\-index(1) kiwix\-manage(1)
kiwix(1) kiwix\-manage(1)
.br
kiwix\-install(1) kiwix\-compact(1)
kiwix\-install(1)
.SH AUTHOR
Emmanuel Engelhart <kelson@kiwix.org>
.br
Vasudev Kamath <kamathvasudev@gmail.com> (Manual)
Vasudev Kamath <kamathvasudev@gmail.com> (Manual)

View File

@@ -34,9 +34,9 @@ Fonctionnalités:
* Bibliothèque de contenus intégrée
.SH SEE ALSO
kiwix-index(1) kiwix-install(1) kiwix-serve(1)
kiwix\-install(1) kiwix\-serve(1)
.br
kiwix-compact(1) kiwix-manage(1)
kiwix\-manage(1)
.SH TROUBLESHOOTING

View File

@@ -1,5 +1,4 @@
install_man('kiwix-index.1',
'kiwix-install.1',
install_man('kiwix-install.1',
'kiwix-manage.1',
'kiwix-serve.1',
install_dir:get_option('mandir')+'/fr/man1')

View File

@@ -1,23 +0,0 @@
.TH KIWIX 1 "21 May 2012"
.SH NAME
kiwix-compact \- ZIM index compacter
.SH SYNOPSIS
.IX Header SYNOPSIS
kiwix-compact INDEX_PATH
.SH DESCRIPTION
.PP
Compacts ZIM index files used by Kiwix using xapian-compact
.TP
\fBINDEX_PATH\fR
Full-text index path to compact.
.SH SEE ALSO
kiwix(1) kiwix-index(1) kiwix-manage(1) xapian-compact(1)
.br
kiwix-install(1) kiwix-serve(1)
.SH AUTHOR
Emmanuel Engelhart <kelson@kiwix.org>
.br
Vasudev Kamath <kamathvasudev@gmail.com> (Manual)

View File

@@ -1,31 +0,0 @@
.TH KIWIX 1 "21 May 2012"
.SH NAME
kiwix\-index \- Kiwix ZIM Indexer
.SH SYNOPSIS
.IX Header SYNOPSIS
kiwix\-index [\-\-backend|\-b=xapian|clucene] ZIM_PATH INDEX_PATH
.SH DESCRIPTION
.PP
Generates a xapian or clucene full-text index for a ZIM file.
.TP
\fB\-\-backend=xapian|clucene\fR
Select an indexing backend.
.TP
\fBZIM_PATH\fR
ZIM file path to index.
.TP
\fBINDEX_PATH\fR
Path to save the full\-text index to.
.SH SEE ALSO
kiwix\-compact(1) kiwix\-manage(1) kiwix\-serve(1)
.br
kiwix(1) kiwix\-install(1)
.SH AUTHOR
Emmanuel Engelhart <kelson@kiwix.org>
.br
Vasudev Kamath <kamathvasudev@gmail.com> (Manual)

View File

@@ -33,8 +33,8 @@ Path to the kiwix/ folder.
The path must contain the kiwix standalone binary.
.SH SEE ALSO
kiwix(1) kiwix\-index(1) kiwix\-serve(1) kiwix\-compact(1) kiwix\-manage(1)
kiwix(1) kiwix\-serve(1) kiwix\-manage(1)
.SH AUTHOR
Emmanuel Engelhart <kelson@kiwix.org>
.br
Vasudev Kamath <kamathvasudev@gmail.com> (Manual)
Vasudev Kamath <kamathvasudev@gmail.com> (Manual)

View File

@@ -55,8 +55,8 @@ Path to full-text index for that ZIM file.
Set the content location of the ZIM file over the network for in\-kiwix download.
.SH SEE ALSO
kiwix(1) kiwix\-index(1) kiwix\-install(1) kiwix\-serve(1) kiwix\-compact(1)
kiwix(1) kiwix\-install(1) kiwix\-serve(1)
.SH AUTHOR
Emmanuel Engelhart <kelson@kiwix.org>
.br
Vasudev Kamath <kamathvasudev@gmail.com> (Manual)
Vasudev Kamath <kamathvasudev@gmail.com> (Manual)

View File

@@ -13,7 +13,7 @@ Stand\-alone HTTP server for serving ZIM content over the network.
.TP
\fB\-\-index=INDEX_PATH\fR
Path to index folder created using \fBkiwix-index\fB.
Path to index folder created using \fBkiwix-install\fB.
.TP
\fB\-\-port=PORT\fR
@@ -52,10 +52,10 @@ Kiwix library file path.
Library is XML file created using \fBkiwix-manage\fB.
.SH SEE ALSO
kiwix(1) kiwix\-index(1) kiwix\-manage(1)
kiwix(1) kiwix\-manage(1)
.br
kiwix\-install(1) kiwix\-compact(1)
kiwix\-install(1)
.SH AUTHOR
Emmanuel Engelhart <kelson@kiwix.org>
.br
Vasudev Kamath <kamathvasudev@gmail.com> (Manual)
Vasudev Kamath <kamathvasudev@gmail.com> (Manual)

View File

@@ -1,5 +1,4 @@
install_man('kiwix-index.1',
'kiwix-install.1',
install_man('kiwix-install.1',
'kiwix-manage.1',
'kiwix-serve.1')
subdir('fr')

View File

@@ -21,47 +21,54 @@
#include <unistd.h>
#endif
#include <getopt.h>
#include <iostream>
#include <cstdlib>
#include <kiwix/common/pathTools.h>
#include <kiwix/manager.h>
#include <cstdlib>
#include <iostream>
using namespace std;
enum supportedAction { NONE, ADD, SHOW, REMOVE };
void show(kiwix::Library library) {
std::vector<kiwix::Book>::iterator itr;
unsigned int inc = 1;
for ( itr = library.books.begin(); itr != library.books.end(); ++itr ) {
std::cout << "#" << inc++
<< std::endl << "id:\t\t" << itr->id
<< std::endl << "path:\t\t" << itr->path
<< std::endl << "indexpath:\t" << itr->indexPath
<< std::endl << "url:\t\t" << itr->url
<< std::endl << "title:\t\t" << itr->title
<< std::endl << "name:\t\t" << itr->name
<< std::endl << "tags:\t\t" << itr->tags
<< std::endl << "description:\t" << itr->description
<< std::endl << "creator:\t" << itr->creator
<< std::endl << "date:\t\t" << itr->date
<< std::endl << "articleCount:\t" << itr->articleCount
<< std::endl << "mediaCount:\t" << itr->mediaCount
<< std::endl << "size:\t\t" << itr->size << " KB"
<< std::endl << std::endl;
}
void show(kiwix::Library library)
{
std::vector<kiwix::Book>::iterator itr;
unsigned int inc = 1;
for (itr = library.books.begin(); itr != library.books.end(); ++itr) {
std::cout << "#" << inc++ << std::endl
<< "id:\t\t" << itr->id << std::endl
<< "path:\t\t" << itr->path << std::endl
<< "indexpath:\t" << itr->indexPath << std::endl
<< "url:\t\t" << itr->url << std::endl
<< "title:\t\t" << itr->title << std::endl
<< "name:\t\t" << itr->name << std::endl
<< "tags:\t\t" << itr->tags << std::endl
<< "description:\t" << itr->description << std::endl
<< "creator:\t" << itr->creator << std::endl
<< "date:\t\t" << itr->date << std::endl
<< "articleCount:\t" << itr->articleCount << std::endl
<< "mediaCount:\t" << itr->mediaCount << std::endl
<< "size:\t\t" << itr->size << " KB" << std::endl
<< std::endl;
}
}
void usage() {
cerr << "Usage:" << endl;
cerr << "\tkiwix-manage LIBRARY_PATH add ZIM_PATH [--zimPathToSave=../content/foobar.zim] [--current] [--indexBackend=xapian] [--indexPath=FULLTEXT_IDX_PATH] [--url=http://...metalink]" << endl;
cerr << "\tkiwix-manage LIBRARY_PATH show [CONTENTID1] [CONTENTID2] ... (show everything if no param.)" << endl;
cerr << "\tkiwix-manage LIBRARY_PATH remove CONTENTID1 [CONTENTID2]" << endl;
void usage()
{
cerr << "Usage:" << endl;
cerr << "\tkiwix-manage LIBRARY_PATH add ZIM_PATH "
"[--zimPathToSave=../content/foobar.zim] [--current] "
"[--indexBackend=xapian] [--indexPath=FULLTEXT_IDX_PATH] "
"[--url=http://...metalink]"
<< endl;
cerr << "\tkiwix-manage LIBRARY_PATH show [CONTENTID1] [CONTENTID2] ... "
"(show everything if no param.)"
<< endl;
cerr << "\tkiwix-manage LIBRARY_PATH remove CONTENTID1 [CONTENTID2]" << endl;
}
int main(int argc, char **argv) {
int main(int argc, char** argv)
{
string libraryPath = "";
supportedAction action = NONE;
string zimPath = "";
@@ -89,9 +96,9 @@ int main(int argc, char **argv) {
}
/* Try to read the file */
libraryPath = isRelativePath(libraryPath) ?
computeAbsolutePath(getCurrentDirectory(), libraryPath) :
libraryPath;
libraryPath = isRelativePath(libraryPath)
? computeAbsolutePath(getCurrentDirectory(), libraryPath)
: libraryPath;
libraryManager.readFile(libraryPath, false);
/* SHOW */
@@ -103,81 +110,78 @@ int main(int argc, char **argv) {
string indexPath;
kiwix::supportedIndexType indexBackend = kiwix::XAPIAN;
string url;
string origID="";
string origID = "";
bool setCurrent = false;
if (argc>3) {
if (argc > 3) {
zimPath = argv[3];
}
/* Options parsing */
optind = 2;
while (42) {
static struct option long_options[]
= {{"url", required_argument, 0, 'u'},
{"origId", required_argument, 0, 'o'},
{"indexPath", required_argument, 0, 'i'},
{"indexBackend", required_argument, 0, 'b'},
{"zimPathToSave", required_argument, 0, 'z'},
{"current", no_argument, 0, 'c'},
{0, 0, 0, 0}};
static struct option long_options[] = {
{"url", required_argument, 0, 'u'},
{"origId", required_argument, 0, 'o'},
{"indexPath", required_argument, 0, 'i'},
{"indexBackend", required_argument, 0, 'b'},
{"zimPathToSave", required_argument, 0, 'z'},
{"current", no_argument, 0, 'c'},
{0, 0, 0, 0}
};
c = getopt_long(argc, argv, "cz:u:i:b:", long_options, &option_index);
if (c != -1) {
switch (c) {
case 'u':
url = optarg;
break;
switch (c) {
case 'u':
url = optarg;
break;
case 'o':
origID = optarg;
break;
case 'o':
origID = optarg;
break;
case 'c':
setCurrent = true;
break;
case 'c':
setCurrent = true;
break;
case 'i':
indexPath = optarg;
break;
case 'i':
indexPath = optarg;
break;
case 'b':
if (!strcmp(optarg, "xapian")) {
indexBackend = kiwix::XAPIAN;
} else {
usage();
}
break;
case 'b':
if (!strcmp(optarg, "xapian")) {
indexBackend = kiwix::XAPIAN;
} else {
usage();
}
break;
case 'z':
zimPathToSave = optarg;
break;
}
case 'z':
zimPathToSave = optarg;
break;
}
} else {
break;
break;
}
}
if (!zimPath.empty()) {
zimPathToSave = zimPathToSave == "." ? zimPath : zimPathToSave;
string bookId = libraryManager.addBookFromPathAndGetId(zimPath, zimPathToSave, url, false);
string bookId = libraryManager.addBookFromPathAndGetId(
zimPath, zimPathToSave, url, false);
if (!bookId.empty()) {
if (setCurrent)
libraryManager.setCurrentBookId(bookId);
if (setCurrent)
libraryManager.setCurrentBookId(bookId);
/* Save the index infos if necessary */
if (!indexPath.empty())
libraryManager.setBookIndex(bookId, indexPath, indexBackend);
/* Save the index infos if necessary */
if (!indexPath.empty())
libraryManager.setBookIndex(bookId, indexPath, indexBackend);
} else {
cerr << "Unable to build or save library file '" << libraryPath << "'" << endl;
cerr << "Unable to build or save library file '" << libraryPath << "'"
<< endl;
}
} else {
std::cerr << "Invalid zim file path" << std::endl;
@@ -187,7 +191,7 @@ int main(int argc, char **argv) {
unsigned int bookIndex = 0;
const unsigned int totalBookCount = libraryManager.getBookCount(true, true);
if (argc>3) {
if (argc > 3) {
bookIndex = atoi(argv[3]);
}
@@ -195,9 +199,13 @@ int main(int argc, char **argv) {
libraryManager.removeBookByIndex(bookIndex - 1);
} else {
if (totalBookCount > 0) {
std::cerr << "Invalid book index number. Please give a number between 1 and " << totalBookCount << std::endl;
std::cerr
<< "Invalid book index number. Please give a number between 1 and "
<< totalBookCount << std::endl;
} else {
std::cerr << "Invalid book index number. Library is empty, no book to delete." << std::endl;
std::cerr
<< "Invalid book index number. Library is empty, no book to delete."
<< std::endl;
}
}
}

View File

@@ -18,59 +18,53 @@
*/
#include <getopt.h>
#include <unistd.h>
#include <string>
#include <map>
#include <kiwix/common/tree.h>
#include <kiwix/reader.h>
#include <unistd.h>
#include <map>
#include <string>
void usage() {
cout << "Usage: kiwix-read --suggest=<PATTERN> ZIM_FILE_PATH" << endl;
exit(1);
void usage()
{
cout << "Usage: kiwix-read --suggest=<PATTERN> ZIM_FILE_PATH" << endl;
exit(1);
}
void updateSuggestionTree(tree< pair<string, unsigned> > &suggestionTree, string suggestion) {
return;
}
int main(int argc, char **argv) {
int main(int argc, char** argv)
{
/* Init the variables */
const char *filePath = NULL;
const char *pattern = NULL;
const char* filePath = NULL;
const char* pattern = NULL;
int option_index = 0;
int c = 0;
kiwix::Reader *reader = NULL;
kiwix::Reader* reader = NULL;
/* Argument parsing */
while (42) {
static struct option long_options[]
= {{"verbose", no_argument, 0, 'v'},
{"suggest", required_argument, 0, 's'},
{0, 0, 0, 0}};
static struct option long_options[] = {
{"verbose", no_argument, 0, 'v'},
{"suggest", required_argument, 0, 's'},
{0, 0, 0, 0}
};
if (c != -1) {
c = getopt_long(argc, argv, "vs:", long_options, &option_index);
switch (c) {
case 'v':
break;
case 's':
pattern = optarg;
break;
case 'v':
break;
case 's':
pattern = optarg;
break;
}
} else {
if (optind < argc) {
if (filePath == NULL) {
filePath = argv[optind++];
} else {
usage();
}
if (filePath == NULL) {
filePath = argv[optind++];
} else {
usage();
}
} else {
break;
break;
}
}
}
@@ -90,25 +84,23 @@ int main(int argc, char **argv) {
string contentType;
unsigned int contentLength = 0;
string suggestion;
if (pattern != NULL) {
std::cout << "Searching suggestions for: " << pattern << std::endl;
reader->searchSuggestionsSmart(pattern, 10);
while (reader->getNextSuggestion(suggestion)) {
std::cout << suggestion << std::endl;
std::cout << suggestion << std::endl;
}
}
/*
if (reader->getContentByUrl(mainPageUrl, content, contentLength, contentType)) {
if (reader->getContentByUrl(mainPageUrl, content, contentLength,
contentType)) {
cout << content << endl;
}
*/
// tree< pair<string, unsigned> > tree;
//updateSuggestionTree(tree, string(suggestion));
delete reader;
} else {
cerr << "Unable instanciate the Kiwix reader." << endl;

View File

@@ -18,57 +18,69 @@
*/
#include <getopt.h>
#include <unistd.h>
#include <kiwix/reader.h>
#include <kiwix/searcher.h>
#include <unistd.h>
void usage() {
cout << "Usage: kiwix-search [--verbose|-v] ZIM_PATH SEARCH" << endl;
exit(1);
void usage()
{
cout << "Usage: kiwix-search [OPTIONS] ZIM PATTERN" << endl << endl
<< " kiwix-search allows to find articles based on the a fulltext search pattern." << endl << endl
<< " ZIM is the full path of the ZIM file. This can also be a disctinct fulltext" << endl
<< " index directory (usually distributed with the *.idx extension)." << endl
<< " PATTERN is/are word(s) - or part of - to search in the ZIM." << endl << endl
<< " -s, --suggestion\tSuggest article titles based on the few letters of the PATTERN instead of making a fulltext search. Work a bit like a completion solution." << endl
<< " -v, --verbose\t\tGive details about the search process" << endl;
exit(1);
}
int main(int argc, char **argv) {
int main(int argc, char** argv)
{
/* Init the variables */
//const char *indexPath = "/home/itamar/.www.kiwix.org/kiwix/43k0i1j4.default/6d2e587b-d586-dc6a-dc6a-e4ef035a1495d15c.index";
//const char *indexPath = "/home/itamar/testindex";
const char *zimPath = NULL;
const char *search = NULL;
// const char *indexPath =
// "/home/itamar/.www.kiwix.org/kiwix/43k0i1j4.default/6d2e587b-d586-dc6a-dc6a-e4ef035a1495d15c.index";
// const char *indexPath = "/home/itamar/testindex";
const char* zimPath = NULL;
const char* search = NULL;
bool verboseFlag = false;
bool suggestionFlag = false;
int option_index = 0;
int c = 0;
kiwix::Searcher *searcher = NULL;
kiwix::Reader *reader = NULL;
kiwix::Searcher* searcher = NULL;
kiwix::Reader* reader = NULL;
/* Argument parsing */
while (42) {
static struct option long_options[] = {
{"verbose", no_argument, 0, 'v'},
{0, 0, 0, 0}
};
static struct option long_options[]
= {{"verbose", no_argument, 0, 'v'},
{"suggestion", no_argument, 0, 's'},
{0, 0, 0, 0}};
if (c != -1) {
c = getopt_long(argc, argv, "vb:", long_options, &option_index);
c = getopt_long(argc, argv, "vsb:", long_options, &option_index);
switch (c) {
case 'v':
verboseFlag = true;
break;
case 'v':
verboseFlag = true;
break;
case 's':
suggestionFlag = true;
break;
}
} else {
if (optind < argc) {
if (zimPath == NULL) {
zimPath = argv[optind++];
} else if (search == NULL) {
search = argv[optind++];
} else {
cout << zimPath << endl;
usage();
}
if (zimPath == NULL) {
zimPath = argv[optind++];
} else if (search == NULL) {
search = argv[optind++];
} else {
cout << zimPath << endl;
usage();
}
} else {
break;
break;
}
}
}
@@ -80,28 +92,34 @@ int main(int argc, char **argv) {
/* Try to prepare the indexing */
try {
reader = new kiwix::Reader(zimPath);
reader = new kiwix::Reader(zimPath);
} catch (...) {
/* Cannot open the zimPath, maybe it is a plain old xapian database directory */
/* Cannot open the zimPath, maybe it is a plain old xapian database
* directory */
}
if ( reader ) {
searcher = new kiwix::Searcher("", reader);
if (reader) {
searcher = new kiwix::Searcher();
searcher->add_reader(reader, "");
} else {
try {
searcher = new kiwix::Searcher(zimPath, NULL);
} catch (...) {
cerr << "Unable to search through zim '" << zimPath << "'." << endl;
exit(1);
}
try {
searcher = new kiwix::Searcher(zimPath, NULL, "");
} catch (...) {
cerr << "Unable to search through zim '" << zimPath << "'." << endl;
exit(1);
}
}
/* Start the indexing */
if (searcher != NULL) {
string searchString(search);
searcher->search(searchString, 0, 10);
if (suggestionFlag) {
searcher->suggestions(searchString, verboseFlag);
} else {
searcher->search(searchString, 0, 10, verboseFlag);
}
kiwix::Result* p_result;
while ( (p_result = searcher->getNextResult()) ) {
while ((p_result = searcher->getNextResult())) {
cout << p_result->get_title() << endl;
delete p_result;
}

View File

File diff suppressed because it is too large Load Diff

View File

@@ -1,5 +1,5 @@
sources = ['kiwix-serve.cpp']
sources = ['kiwix-serve.cpp', 'request_context.cpp']
sources += server_resources
executable('kiwix-serve', sources,

View File

@@ -0,0 +1,211 @@
/*
* Copyright 2009-2016 Emmanuel Engelhart <kelson@kiwix.org>
* Copyright 2017 Matthieu Gautier<mgautier@kymeria.fr>
*
* 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 "request_context.h"
#include <string.h>
#include <stdexcept>
#include <sstream>
RequestContext::RequestContext(struct MHD_Connection* connection,
std::string rootLocation,
const std::string& _url,
const std::string& method,
const std::string& version) :
connection(connection),
full_url(_url),
url(_url),
valid_url(true),
version(version),
acceptEncodingDeflate(false),
accept_range(false),
range_pair(0, -1)
{
if (method == "GET") {
this->method = RequestMethod::GET;
} else if (method == "HEAD") {
this->method = RequestMethod::HEAD;
} else if (method == "POST") {
this->method = RequestMethod::POST;
} else if (method == "PUT") {
this->method = RequestMethod::PUT;
} else if (method == "DELETE") {
this->method = RequestMethod::DELETE_;
} else if (method == "CONNECT") {
this->method = RequestMethod::CONNECT;
} else if (method == "OPTIONS") {
this->method = RequestMethod::OPTIONS;
} else if (method == "TRACE") {
this->method = RequestMethod::TRACE;
} else if (method == "PATCH") {
this->method = RequestMethod::PATCH;
} else {
this->method = RequestMethod::OTHER;
}
MHD_get_connection_values(connection, MHD_HEADER_KIND, &RequestContext::fill_header, this);
MHD_get_connection_values(connection, MHD_GET_ARGUMENT_KIND, &RequestContext::fill_argument, this);
valid_url = true;
if (rootLocation.empty()) {
// nothing special to handle.
url = full_url;
} else {
if (full_url.size() > rootLocation.size() &&
full_url.substr(0, rootLocation.size()+1) == rootLocation + "/") {
url = full_url.substr(rootLocation.size());
} else {
valid_url = false;
}
}
try {
acceptEncodingDeflate =
(get_header(MHD_HTTP_HEADER_ACCEPT_ENCODING).find("deflate") != std::string::npos);
} catch (const std::out_of_range&) {}
/*Check if range is requested. */
try {
auto range = get_header(MHD_HTTP_HEADER_RANGE);
int start = 0;
int end = -1;
std::istringstream iss(range);
char c;
iss >> start >> c;
if (iss.good() && c=='-') {
iss >> end;
if (iss.fail()) {
// Something went wrong will extracting.
end = -1;
}
if (iss.eof()) {
accept_range = true;
range_pair = std::pair<int, int>(start, end);
}
}
} catch (const std::out_of_range&) {}
}
RequestContext::~RequestContext()
{}
int RequestContext::fill_header(void *__this, enum MHD_ValueKind kind,
const char *key, const char *value)
{
RequestContext *_this = static_cast<RequestContext*>(__this);
_this->headers[key] = value;
return MHD_YES;
}
int RequestContext::fill_argument(void *__this, enum MHD_ValueKind kind,
const char *key, const char* value)
{
RequestContext *_this = static_cast<RequestContext*>(__this);
_this->arguments[key] = value == nullptr ? "" : value;
return MHD_YES;
}
void RequestContext::print_debug_info() {
printf("method : %s (%d)\n", method==RequestMethod::GET ? "GET" :
method==RequestMethod::POST ? "POST" :
"OTHER", (int)method);
printf("version : %s\n", version.c_str());
printf("headers :\n");
for (auto it=headers.begin(); it!=headers.end(); it++) {
printf(" - %s : '%s'\n", it->first.c_str(), it->second.c_str());
}
printf("arguments :\n");
for (auto it=arguments.begin(); it!=arguments.end(); it++) {
printf(" - %s : '%s'\n", it->first.c_str(), it->second.c_str());
}
printf("Parsed : \n");
printf("url : %s\n", url.c_str());
printf("acceptEncodingDeflate : %d\n", acceptEncodingDeflate);
printf("has_range : %d\n", accept_range);
printf(".............\n");
}
RequestMethod RequestContext::get_method() {
return method;
}
std::string RequestContext::get_url() {
return url;
}
std::string RequestContext::get_url_part(int number) {
size_t start = 1;
while(true) {
auto found = url.find('/', start);
if (number == 0) {
if (found == std::string::npos) {
return url.substr(start);
} else {
return url.substr(start, found-start);
}
} else {
if (found == std::string::npos) {
throw std::out_of_range("No parts");
}
start = found + 1;
number -= 1;
}
}
}
std::string RequestContext::get_full_url() {
return full_url;
}
bool RequestContext::is_valid_url() {
return valid_url;
}
bool RequestContext::has_range() {
return accept_range;
}
std::pair<int, int> RequestContext::get_range() {
return range_pair;
}
template<>
std::string RequestContext::get_argument(const std::string& name) {
return arguments.at(name);
}
template<>
unsigned int RequestContext::get_argument(const std::string& name) {
return std::stoi(arguments.at(name).c_str());
}
template<>
float RequestContext::get_argument(const std::string& name) {
return std::stof(arguments.at(name).c_str());
}
std::string RequestContext::get_header(const std::string& name) {
return headers.at(name);
}

View File

@@ -0,0 +1,100 @@
/*
* Copyright 2009-2016 Emmanuel Engelhart <kelson@kiwix.org>
* Copyright 2017 Matthieu Gautier<mgautier@kymeria.fr>
*
* 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.
*/
#ifndef REQUEST_CONTEXT_H
#define REQUEST_CONTEXT_H
#include <string>
#include <map>
#include <stdexcept>
extern "C" {
#include <microhttpd.h>
}
enum class RequestMethod {
GET,
HEAD,
POST,
PUT,
DELETE_,
CONNECT,
OPTIONS,
TRACE,
PATCH,
OTHER
};
class KeyError : public std::runtime_error {};
class IndexError: public std::runtime_error {};
class RequestContext {
public:
RequestContext(struct MHD_Connection* connection,
std::string rootLocation,
const std::string& url,
const std::string& method,
const std::string& version);
~RequestContext();
void print_debug_info();
bool is_valid_url();
std::string get_header(const std::string& name);
template<typename T=std::string>
T get_argument(const std::string& name);
RequestMethod get_method();
std::string get_url();
std::string get_url_part(int part);
std::string get_full_url();
bool has_range();
std::pair<int, int> get_range();
bool can_compress() { return acceptEncodingDeflate; }
// [TODO] Move this to the response builder
int httpResponseCode;
private:
struct MHD_Connection* connection;
std::string full_url;
std::string url;
bool valid_url;
RequestMethod method;
std::string version;
bool acceptEncodingDeflate;
bool accept_range;
std::pair<int, int> range_pair;
std::map<std::string, std::string> headers;
std::map<std::string, std::string> arguments;
static int fill_header(void *, enum MHD_ValueKind, const char*, const char*);
static int fill_argument(void *, enum MHD_ValueKind, const char*, const char*);
};
#endif //REQUEST_CONTEXT_H

View File

@@ -1,4 +1,4 @@
res_compiler = find_program('compile_resources.py')
res_compiler = find_program('kiwix-compile-resources', 'compile_resources.py')
subdir('server')

View File

@@ -0,0 +1,13 @@
<span class="kiwix">
<span id="kiwixtoolbar" class="ui-widget-header">
<div class="kiwix_centered">
<div class="kiwix_searchform">
<form class="kiwixsearch" method="GET" action="__ROOT_LOCATION__/search" id="kiwixsearchform">
<input autocomplete="off" class="ui-autocomplete-input" id="kiwixsearchbox" name="pattern" type="text">
<input type="submit" value="Search">
</form>
</div>
</div>
</span>
</span>
<div style="display: block; height: 5em;"></div>

View File

@@ -3,10 +3,10 @@
<head>
<meta charset="UTF-8" />
<title>Welcome to Kiwix Server</title>
<script type="text/javascript" src="/skin/jquery-ui/external/jquery/jquery.js"></script>
<script type="text/javascript" src="/skin/jquery-ui/jquery-ui.min.js"></script>
<link type="text/css" href="/skin/jquery-ui/jquery-ui.min.css" rel="Stylesheet" />
<link type="text/css" href="/skin/jquery-ui/jquery-ui.theme.min.css" rel="Stylesheet" />
<script type="text/javascript" src="__ROOT_LOCATION__/skin/jquery-ui/external/jquery/jquery.js"></script>
<script type="text/javascript" src="__ROOT_LOCATION__/skin/jquery-ui/jquery-ui.min.js"></script>
<link type="text/css" href="__ROOT_LOCATION__/skin/jquery-ui/jquery-ui.min.css" rel="Stylesheet" />
<link type="text/css" href="__ROOT_LOCATION__/skin/jquery-ui/jquery-ui.theme.min.css" rel="Stylesheet" />
<style>
body {
background:

View File

@@ -1,11 +1,14 @@
<script type="text/javascript" src="/skin/jquery-ui/external/jquery/jquery.js"></script>
<script type="text/javascript" src="/skin/jquery-ui/jquery-ui.min.js"></script>
<link type="text/css" href="__ROOT_LOCATION__/skin/jquery-ui/jquery-ui.min.css" rel="Stylesheet" />
<link type="text/css" href="__ROOT_LOCATION__/skin/jquery-ui/jquery-ui.theme.min.css" rel="Stylesheet" />
<link type="text/css" href="__ROOT_LOCATION__/skin/taskbar.css" rel="Stylesheet" />
<script type="text/javascript" src="__ROOT_LOCATION__/skin/jquery-ui/external/jquery/jquery.js"></script>
<script type="text/javascript" src="__ROOT_LOCATION__/skin/jquery-ui/jquery-ui.min.js"></script>
<script>
var jk = jQuery.noConflict();
jk(function() {
jk( "#kiwixsearchbox" ).autocomplete({
source: "/suggest?content=__CONTENT__",
source: "__ROOT_LOCATION__/suggest?content=__CONTENT_ESCAPED__",
dataType: "json",
cache: false,

View File

@@ -21,3 +21,4 @@ home.html.tmpl
include.html.part
taskbar.css
taskbar.html.part
global_taskbar.html.part

View File

@@ -1,15 +1,13 @@
<link type="text/css" href="/skin/jquery-ui/jquery-ui.min.css" rel="Stylesheet" />
<link type="text/css" href="/skin/jquery-ui/jquery-ui.theme.min.css" rel="Stylesheet" />
<span class="kiwix">
<span id="kiwixtoolbar" class="ui-widget-header">
<div class="kiwix_centered">
<div class="kiwix_button_wrapper">
<a id="kiwix_serve_taskbar_library_button" href="/"><button>Library</button></a>
<a id="kiwix_serve_taskbar_home_button" href="/__CONTENT__/"><button>Home</button></a>
<a id="kiwix_serve_taskbar_random_button" href="/random?content=__CONTENT__"><button>Random</button></a>
<a id="kiwix_serve_taskbar_library_button" href="__ROOT_LOCATION__/"><button>Library</button></a>
<a id="kiwix_serve_taskbar_home_button" href="__ROOT_LOCATION__/__CONTENT__/"><button>Home</button></a>
<a id="kiwix_serve_taskbar_random_button" href="__ROOT_LOCATION__/random?content=__CONTENT_ESCAPED__"><button>Random</button></a>
</div>
<div class="kiwix_searchform">
<form class="kiwixsearch" method="GET" action="/search" id="kiwixsearchform">
<form class="kiwixsearch" method="GET" action="__ROOT_LOCATION__/search" id="kiwixsearchform">
<input type="hidden" name="content" value="__CONTENT__" />
<input autocomplete="off" class="ui-autocomplete-input" id="kiwixsearchbox" name="pattern" type="text">
<input type="submit" value="Search">

View File

@@ -8,24 +8,17 @@ INSTALL_DIR=${BUILD_DIR}/INSTALL
case ${PLATFORM} in
"native_static")
MESON_OPTION="--default-library=static"
MESON_OPTION="-Dstatic-linkage=true"
;;
"native_dyn")
MESON_OPTION="--default-library=shared"
MESON_OPTION=""
;;
"win32_static")
MESON_OPTION="--default-library=static --cross-file ${BUILD_DIR}/meson_cross_file.txt"
MESON_OPTION="-Dstatic-linkage=true --cross-file ${BUILD_DIR}/meson_cross_file.txt"
;;
"win32_dyn")
MESON_OPTION="--default-library=shared --cross-file ${BUILD_DIR}/meson_cross_file.txt"
MESON_OPTION="--cross-file ${BUILD_DIR}/meson_cross_file.txt"
;;
"android_arm")
MESON_OPTION="-Dandroid=true --default-library=shared --cross-file ${BUILD_DIR}/meson_cross_file.txt"
;;
"android_arm64")
MESON_OPTION="-Dandroid=true --default-library=shared --cross-file ${BUILD_DIR}/meson_cross_file.txt"
;;
esac
cd ${TRAVIS_BUILD_DIR}

View File

@@ -29,7 +29,7 @@ esac
sudo apt-get update -qq
sudo apt-get install -qq python3-pip ${PACKAGES}
pip3 install meson
sudo pip3 install meson==0.43.0
# Ninja
cd $HOME