diff --git a/src/server/kiwix-serve.cpp b/src/server/kiwix-serve.cpp index cfaf5f9..373c66d 100644 --- a/src/server/kiwix-serve.cpp +++ b/src/server/kiwix-serve.cpp @@ -14,118 +14,131 @@ #include #include #include -#include +#include using namespace std; static const string HTMLScripts = " \ - \ - \ - \ + \n \ +\n \ + \n \ "; static const string HTMLDiv = " \ -
\ - \ -Your content here. \ -
\ +
\n \ + \n \ +Your content here. \n \ +
\n \ "; static zim::File* zimFileHandler; static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER; +static void appendToFirstOccurence(string &content, const string regex, const string &replacement) { + regmatch_t matchs[1]; + regex_t regexp; + + regcomp(®exp, regex.data(), REG_ICASE); + regexec(®exp, content.data(), 1, matchs, 0); + + if (matchs[0].rm_so > 0) + content.replace(matchs[0].rm_eo, 0, replacement); + + regfree(®exp); +} + static int accessHandlerCallback(void *cls, struct MHD_Connection * connection, const char * url, @@ -213,6 +226,12 @@ static int accessHandlerCallback(void *cls, mimeType = article.getMimeType(); cout << "mimeType: " << mimeType << endl; + /* Rewrite the content */ + if (mimeType == "text/html") { + appendToFirstOccurence(content, "", HTMLScripts); + appendToFirstOccurence(content, "]*>", HTMLDiv); + } + } else { /* The found article is not the good one */ content="";