|
|
|
@ -24,16 +24,12 @@
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
#ifdef _WIN32
|
|
|
|
#if (_MSC_VER < 1600)
|
|
|
|
|
|
|
|
#include "stdint4win.h"
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <winsock2.h>
|
|
|
|
|
|
|
|
#include <WS2tcpip.h> // otherwise socklen_t is not a recognized type
|
|
|
|
#include <WS2tcpip.h> // otherwise socklen_t is not a recognized type
|
|
|
|
//#include <Windows.h> // otherwise int is not a recognized type
|
|
|
|
#include <stdint4win.h>
|
|
|
|
typedef int off_t;
|
|
|
|
#include <winsock2.h>
|
|
|
|
|
|
|
|
#include <Windows.h> // otherwise int is not a recognized type
|
|
|
|
typedef SSIZE_T ssize_t;
|
|
|
|
typedef SSIZE_T ssize_t;
|
|
|
|
typedef UINT64 uint64_t;
|
|
|
|
typedef int off_t;
|
|
|
|
typedef UINT16 uint16_t;
|
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
extern "C" {
|
|
|
|
#include <microhttpd.h>
|
|
|
|
#include <microhttpd.h>
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -157,6 +153,11 @@ static int accessHandlerCallback(void *cls,
|
|
|
|
size_t * upload_data_size,
|
|
|
|
size_t * upload_data_size,
|
|
|
|
void ** ptr) {
|
|
|
|
void ** ptr) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Debug */
|
|
|
|
|
|
|
|
if (isVerbose()) {
|
|
|
|
|
|
|
|
std::cout << "Requesting " << url << std::endl;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Unexpected method */
|
|
|
|
/* Unexpected method */
|
|
|
|
if (0 != strcmp(method, "GET"))
|
|
|
|
if (0 != strcmp(method, "GET"))
|
|
|
|
return MHD_NO;
|
|
|
|
return MHD_NO;
|
|
|
|
@ -168,11 +169,6 @@ static int accessHandlerCallback(void *cls,
|
|
|
|
return MHD_YES;
|
|
|
|
return MHD_YES;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Debug */
|
|
|
|
|
|
|
|
if (isVerbose()) {
|
|
|
|
|
|
|
|
std::cout << "Requesting (" << method << ") " << url << std::endl;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Check if the response can be compressed */
|
|
|
|
/* Check if the response can be compressed */
|
|
|
|
const string acceptEncodingHeaderValue = MHD_lookup_connection_value(connection, MHD_HEADER_KIND, MHD_HTTP_HEADER_ACCEPT_ENCODING) ?
|
|
|
|
const string acceptEncodingHeaderValue = MHD_lookup_connection_value(connection, MHD_HEADER_KIND, MHD_HTTP_HEADER_ACCEPT_ENCODING) ?
|
|
|
|
MHD_lookup_connection_value(connection, MHD_HEADER_KIND, MHD_HTTP_HEADER_ACCEPT_ENCODING) : "";
|
|
|
|
MHD_lookup_connection_value(connection, MHD_HEADER_KIND, MHD_HTTP_HEADER_ACCEPT_ENCODING) : "";
|
|
|
|
@ -355,6 +351,13 @@ static int accessHandlerCallback(void *cls,
|
|
|
|
|
|
|
|
|
|
|
|
compress(compr, &comprLen, (const Bytef*)(content.data()), contentLength);
|
|
|
|
compress(compr, &comprLen, (const Bytef*)(content.data()), contentLength);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* /!\ Internet Explorer has a bug with deflate compression.
|
|
|
|
|
|
|
|
It can not handle the first two bytes (compression headers)
|
|
|
|
|
|
|
|
We need to chunk them off (move the content 2bytes)
|
|
|
|
|
|
|
|
It has no incidence on other browsers */
|
|
|
|
|
|
|
|
compr++;
|
|
|
|
|
|
|
|
compr++;
|
|
|
|
|
|
|
|
|
|
|
|
content = string((char *)compr, comprLen);
|
|
|
|
content = string((char *)compr, comprLen);
|
|
|
|
contentLength = comprLen;
|
|
|
|
contentLength = comprLen;
|
|
|
|
|
|
|
|
|
|
|
|
@ -474,21 +477,19 @@ int main(int argc, char **argv) {
|
|
|
|
|
|
|
|
|
|
|
|
/* Setup the library manager and get the list of books */
|
|
|
|
/* Setup the library manager and get the list of books */
|
|
|
|
if (libraryFlag) {
|
|
|
|
if (libraryFlag) {
|
|
|
|
vector<string> libraryPaths = kiwix::split(libraryPath, ";");
|
|
|
|
vector<string> libraryPaths = kiwix::split(libraryPath, ":");
|
|
|
|
vector<string>::iterator itr;
|
|
|
|
vector<string>::iterator itr;
|
|
|
|
for ( itr = libraryPaths.begin(); itr != libraryPaths.end(); ++itr ) {
|
|
|
|
for ( itr = libraryPaths.begin(); itr != libraryPaths.end(); ++itr ) {
|
|
|
|
if (!(*itr).empty()) {
|
|
|
|
bool retVal = false;
|
|
|
|
bool retVal = false;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
retVal = libraryManager.readFile(*itr, true);
|
|
|
|
retVal = libraryManager.readFile(*itr, true);
|
|
|
|
} catch (...) {
|
|
|
|
} catch (...) {
|
|
|
|
retVal = false;
|
|
|
|
retVal = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!retVal) {
|
|
|
|
if (!retVal) {
|
|
|
|
cerr << "Unable to open the XML library file '" << *itr << "'." << endl;
|
|
|
|
cerr << "Unable to open the XML library file '" << *itr << "'." << endl;
|
|
|
|
exit(1);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|