|
|
|
|
@ -79,6 +79,7 @@ using namespace std;
|
|
|
|
|
static bool nosearchbarFlag = false;
|
|
|
|
|
static string welcomeHTML;
|
|
|
|
|
static bool verboseFlag = false;
|
|
|
|
|
static std::map<std::string, std::string> extMimeTypes;
|
|
|
|
|
static std::map<std::string, kiwix::Reader*> readers;
|
|
|
|
|
static std::map<std::string, kiwix::Searcher*> searchers;
|
|
|
|
|
static pthread_mutex_t readerLock = PTHREAD_MUTEX_INITIALIZER;
|
|
|
|
|
@ -88,58 +89,25 @@ static pthread_mutex_t searcherLock = PTHREAD_MUTEX_INITIALIZER;
|
|
|
|
|
static pthread_mutex_t compressorLock = PTHREAD_MUTEX_INITIALIZER;
|
|
|
|
|
static pthread_mutex_t resourceLock = PTHREAD_MUTEX_INITIALIZER;
|
|
|
|
|
static pthread_mutex_t verboseFlagLock = PTHREAD_MUTEX_INITIALIZER;
|
|
|
|
|
static pthread_mutex_t mimeTypeLock = PTHREAD_MUTEX_INITIALIZER;
|
|
|
|
|
|
|
|
|
|
/* Try to get the mimeType from the file extension */
|
|
|
|
|
static std::string getMimeTypeForFile(const std::string& filename) {
|
|
|
|
|
|
|
|
|
|
std::map<std::string, std::string> extMimeTypes;
|
|
|
|
|
extMimeTypes["HTML"] = "text/html";
|
|
|
|
|
extMimeTypes["html"] = "text/html";
|
|
|
|
|
extMimeTypes["HTM"] = "text/html";
|
|
|
|
|
extMimeTypes["htm"] = "text/html";
|
|
|
|
|
extMimeTypes["PNG"] = "image/png";
|
|
|
|
|
extMimeTypes["png"] = "image/png";
|
|
|
|
|
extMimeTypes["TIFF"] = "image/tiff";
|
|
|
|
|
extMimeTypes["tiff"] = "image/tiff";
|
|
|
|
|
extMimeTypes["TIF"] = "image/tiff";
|
|
|
|
|
extMimeTypes["tif"] = "image/tiff";
|
|
|
|
|
extMimeTypes["JPEG"] = "image/jpeg";
|
|
|
|
|
extMimeTypes["jpeg"] = "image/jpeg";
|
|
|
|
|
extMimeTypes["JPG"] = "image/jpeg";
|
|
|
|
|
extMimeTypes["jpg"] = "image/jpeg";
|
|
|
|
|
extMimeTypes["GIF"] = "image/gif";
|
|
|
|
|
extMimeTypes["gif"] = "image/gif";
|
|
|
|
|
extMimeTypes["SVG"] = "image/svg+xml";
|
|
|
|
|
extMimeTypes["svg"] = "image/svg+xml";
|
|
|
|
|
extMimeTypes["TXT"] = "text/plain";
|
|
|
|
|
extMimeTypes["txt"] = "text/plain";
|
|
|
|
|
extMimeTypes["XML"] = "text/xml";
|
|
|
|
|
extMimeTypes["xml"] = "text/xml";
|
|
|
|
|
extMimeTypes["PDF"] = "application/pdf";
|
|
|
|
|
extMimeTypes["pdf"] = "application/pdf";
|
|
|
|
|
extMimeTypes["OGG"] = "application/ogg";
|
|
|
|
|
extMimeTypes["ogg"] = "application/ogg";
|
|
|
|
|
extMimeTypes["JS"] = "application/javascript";
|
|
|
|
|
extMimeTypes["js"] = "application/javascript";
|
|
|
|
|
extMimeTypes["CSS"] = "text/css";
|
|
|
|
|
extMimeTypes["css"] = "text/css";
|
|
|
|
|
extMimeTypes["otf"] = "application/vnd.ms-opentype";
|
|
|
|
|
extMimeTypes["OTF"] = "application/vnd.ms-opentype";
|
|
|
|
|
extMimeTypes["ttf"] = "application/font-ttf";
|
|
|
|
|
extMimeTypes["TTF"] = "application/font-ttf";
|
|
|
|
|
extMimeTypes["woff"] = "application/font-woff";
|
|
|
|
|
extMimeTypes["WOFF"] = "application/font-woff";
|
|
|
|
|
extMimeTypes["vtt"] = "text/vtt";
|
|
|
|
|
extMimeTypes["VTT"] = "text/vtt";
|
|
|
|
|
std::string mimeType = "text/plain";
|
|
|
|
|
|
|
|
|
|
if (filename.find_last_of(".") != std::string::npos) {
|
|
|
|
|
std::string mimeType = filename.substr(filename.find_last_of(".")+1);
|
|
|
|
|
if (extMimeTypes.find(mimeType) != extMimeTypes.end()) {
|
|
|
|
|
return extMimeTypes[mimeType];
|
|
|
|
|
|
|
|
|
|
pthread_mutex_lock(&mimeTypeLock);
|
|
|
|
|
if (extMimeTypes.find(mimeType) != extMimeTypes.end() ||
|
|
|
|
|
extMimeTypes.find(kiwix::ucAll(mimeType)) != extMimeTypes.end()
|
|
|
|
|
) {
|
|
|
|
|
mimeType = extMimeTypes[mimeType];
|
|
|
|
|
}
|
|
|
|
|
pthread_mutex_unlock(&mimeTypeLock);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return "text/plain";
|
|
|
|
|
return mimeType;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void introduceTaskbar(string &content, const string &humanReadableBookId) {
|
|
|
|
|
@ -693,7 +661,29 @@ int main(int argc, char **argv) {
|
|
|
|
|
pthread_mutex_init(&compressorLock, NULL);
|
|
|
|
|
pthread_mutex_init(&resourceLock, NULL);
|
|
|
|
|
pthread_mutex_init(&verboseFlagLock, NULL);
|
|
|
|
|
|
|
|
|
|
pthread_mutex_init(&mimeTypeLock, NULL);
|
|
|
|
|
|
|
|
|
|
/* Hard coded mimetypes */
|
|
|
|
|
extMimeTypes["html"] = "text/html";
|
|
|
|
|
extMimeTypes["htm"] = "text/html";
|
|
|
|
|
extMimeTypes["png"] = "image/png";
|
|
|
|
|
extMimeTypes["tiff"] = "image/tiff";
|
|
|
|
|
extMimeTypes["tif"] = "image/tiff";
|
|
|
|
|
extMimeTypes["jpeg"] = "image/jpeg";
|
|
|
|
|
extMimeTypes["jpg"] = "image/jpeg";
|
|
|
|
|
extMimeTypes["gif"] = "image/gif";
|
|
|
|
|
extMimeTypes["svg"] = "image/svg+xml";
|
|
|
|
|
extMimeTypes["txt"] = "text/plain";
|
|
|
|
|
extMimeTypes["xml"] = "text/xml";
|
|
|
|
|
extMimeTypes["pdf"] = "application/pdf";
|
|
|
|
|
extMimeTypes["ogg"] = "application/ogg";
|
|
|
|
|
extMimeTypes["js"] = "application/javascript";
|
|
|
|
|
extMimeTypes["css"] = "text/css";
|
|
|
|
|
extMimeTypes["otf"] = "application/vnd.ms-opentype";
|
|
|
|
|
extMimeTypes["ttf"] = "application/font-ttf";
|
|
|
|
|
extMimeTypes["woff"] = "application/font-woff";
|
|
|
|
|
extMimeTypes["vtt"] = "text/vtt";
|
|
|
|
|
|
|
|
|
|
/* Start the HTTP daemon */
|
|
|
|
|
void *page = NULL;
|
|
|
|
|
daemon = MHD_start_daemon(MHD_USE_SELECT_INTERNALLY,
|
|
|
|
|
@ -753,5 +743,6 @@ int main(int argc, char **argv) {
|
|
|
|
|
pthread_mutex_destroy(&mapLock);
|
|
|
|
|
pthread_mutex_destroy(&welcomeLock);
|
|
|
|
|
pthread_mutex_destroy(&verboseFlagLock);
|
|
|
|
|
pthread_mutex_destroy(&mimeTypeLock);
|
|
|
|
|
exit(0);
|
|
|
|
|
}
|
|
|
|
|
|