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
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.
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.
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.
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).
`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.
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.
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.
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.
`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.
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.
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.
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.
We do not need the test "contentLength < COMPRESSOR_BUFFER_SIZE" to know
if we compress the content or not.
This is a non sens, we WANT to compress the content if it is big.
The compr pointer points to the allocated memory. We must not modify
it value.
If we advance the pointer by two bytes each time we compress an answer
we will end to write in some random memory and segfault.
Now, we use a std::vector to correctly handle allocation
(and deallocation!) of the memory.
For ie browser, we need to remove the two first bytes.
If we make our buffer start two bytes after, we also need to reduce the
size of the buffer by two bytes. Else we will read and send two extra
junk bytes.
Fix#15
'max' is a size_t and 'blob()->size()-pos' is a uint64_t.
Depending of the compiler (version, options, ...) this is a error as
we don't know which template specialization we have to use.
- On unix, filenames are case sensitive and all include files are lowercase
- When crosscompiling to Windows, we use mingw32 and not msc.
So we should not try to include "stdint4win.h"
- Windows includes #define interface to struct.
As we use interface as variable name, we need to undef interface
Binary content do not need to be modified, so we don't need to copy it.
We can directly serve it from the internal zim (cluster) buffer.
The handle_content function now getArticleObjectByDecodedUrl instead of
getContentByDecodedUrl.
This is to get the mimetype of the article and copy the content only when
needed (getContentByDecodedUrl always copy the content).
Thus, handle_content is a bit more complex as it need to do some
manipulation previously made in getContentByDecodedUrl.
The main change is that if the content is binary, we serve the content
with a callback response who will get the content chunks directly from
the blob buffer.
Instead of having a big callback function doing almost everything to
handle a request, we split the code into several functions.
There are two new helper functions :
- build_response that create a response object with correct headers set.
- compress_content who compress the content if necessary.
All the different cases are handle by different functions :
- handle_suggest
- handle_skin
- handle_search
- handle_random
- handle_content
- handle_default
accesHandlerCallback now handle common stuff, delegate to the handle_*
functions everything else.
There is no special optimization made here. Only splitting code.
- kiwix-search will try the embedded ft-index if no indexPath is specified
in the library.xml or command argument.
- kiwix-search also uses xapianSearcher and xapianSearcher needs zimlib,
so add zimlib in compilation flag for searcher.
- kiwix-serve already depends on zimlib.