diff options
| author | Roland Reichwein <mail@reichwein.it> | 2020-05-10 18:18:37 +0200 | 
|---|---|---|
| committer | Roland Reichwein <mail@reichwein.it> | 2020-05-10 18:18:37 +0200 | 
| commit | 6c1cc0b2c854dd56dcb6238816a6ce2cb493c71c (patch) | |
| tree | de041dfb3bc12a04fa4defdbd286d098f34adddc /plugins/weblog | |
| parent | 5b32a4415c9776dd6cae859c8d718b5e68f01d81 (diff) | |
Separated out lib
Diffstat (limited to 'plugins/weblog')
| -rw-r--r-- | plugins/weblog/Makefile | 11 | ||||
| -rw-r--r-- | plugins/weblog/weblog.cpp | 41 | 
2 files changed, 11 insertions, 41 deletions
diff --git a/plugins/weblog/Makefile b/plugins/weblog/Makefile index 58d1801..b9f278a 100644 --- a/plugins/weblog/Makefile +++ b/plugins/weblog/Makefile @@ -19,7 +19,7 @@ endif  # -fprofile-instr-generate -fcoverage-mapping  # gcc:--coverage -CXXFLAGS+= -Wall -I. +CXXFLAGS+= -Wall -I. -I../..  CXXFLAGS+= -pthread -fvisibility=hidden -fPIC  ifeq ($(CXX),clang++-10) @@ -40,7 +40,8 @@ LIBS=\  -lboost_regex \  -lpthread \  -lssl -lcrypto \ --ldl +-ldl \ +-lcommon  ifeq ($(CXX),clang++-10)  LIBS+= \ @@ -56,6 +57,8 @@ LIBS+= \  -lstdc++fs  endif +LDFLAGS=-L../../libcommon +  PROGSRC=\      stringutil.cpp \      weblog.cpp @@ -74,8 +77,8 @@ all: $(PROJECTNAME).so  test-$(PROJECTNAME): $(TESTSRC:.cpp=.o)  	$(CXX) $(CXXFLAGS) $^ $(LIBS) -o $@ -$(PROJECTNAME).so: $(SRC:.cpp=.o) -	$(CXX) -shared $(CXXFLAGS) $^ $(LIBS) -o $@ +$(PROJECTNAME).so: ../../libcommon/libcommon.a $(SRC:.cpp=.o) +	$(CXX) -shared $(LDFLAGS) $^ $(LDLIBS) $(LIBS) -o $@  dep: $(TESTSRC:.cpp=.d) diff --git a/plugins/weblog/weblog.cpp b/plugins/weblog/weblog.cpp index 4ed468e..4a14799 100644 --- a/plugins/weblog/weblog.cpp +++ b/plugins/weblog/weblog.cpp @@ -2,6 +2,8 @@  #include "stringutil.h" +#include "libcommon/mime.h" +  #include <boost/algorithm/string/predicate.hpp>  #include <boost/algorithm/string/replace.hpp>  #include <boost/property_tree/ptree.hpp> @@ -23,41 +25,6 @@ namespace {   const size_t number_of_articles_on_front_page {10};   const std::string article_filename{"article.data"}; - // Return a reasonable mime type based on the extension of a file. - std::string mime_type(fs::path path) - { -  using boost::algorithm::iequals; -  auto const ext = [&path] -  { -   size_t pos = path.string().rfind("."); -   if (pos == std::string::npos) -    return std::string{}; -   return path.string().substr(pos); -  }(); -  if(iequals(ext, ".htm"))  return "text/html"; // TODO: unordered_map -  if(iequals(ext, ".html")) return "text/html"; -  if(iequals(ext, ".php"))  return "text/html"; -  if(iequals(ext, ".css"))  return "text/css"; -  if(iequals(ext, ".txt"))  return "text/plain"; -  if(iequals(ext, ".js"))   return "application/javascript"; -  if(iequals(ext, ".json")) return "application/json"; -  if(iequals(ext, ".xml"))  return "application/xml"; -  if(iequals(ext, ".swf"))  return "application/x-shockwave-flash"; -  if(iequals(ext, ".flv"))  return "video/x-flv"; -  if(iequals(ext, ".png"))  return "image/png"; -  if(iequals(ext, ".jpe"))  return "image/jpeg"; -  if(iequals(ext, ".jpeg")) return "image/jpeg"; -  if(iequals(ext, ".jpg"))  return "image/jpeg"; -  if(iequals(ext, ".gif"))  return "image/gif"; -  if(iequals(ext, ".bmp"))  return "image/bmp"; -  if(iequals(ext, ".ico"))  return "image/vnd.microsoft.icon"; -  if(iequals(ext, ".tiff")) return "image/tiff"; -  if(iequals(ext, ".tif"))  return "image/tiff"; -  if(iequals(ext, ".svg"))  return "image/svg+xml"; -  if(iequals(ext, ".svgz")) return "image/svg+xml"; -  return "application/text"; - } -   // Used to return errors by generating response page and HTTP status code   std::string HttpStatus(std::string status, std::string message, std::function<plugin_interface_setter_type>& SetResponseHeader)   { @@ -92,7 +59,7 @@ namespace {   bool is_index_file(std::string& rel_target, fs::path& path)   {    // must be top-level file, recognized as mime_type() -  return rel_target.find("/") == rel_target.npos && mime_type(path) != "application/text"; +  return rel_target.find("/") == rel_target.npos && mime_type(path.string()) != "application/text";   }   bool is_article_page(std::string& rel_target, fs::path& path) @@ -344,7 +311,7 @@ namespace {   std::string generateStaticFile(fs::path& path, std::function<plugin_interface_setter_type>& SetResponseHeader)   {    try { -   SetResponseHeader("content_type", mime_type(path)); +   SetResponseHeader("content_type", mime_type(path.string()));     return getFile(path);    } catch (const std::exception& ex) {     return HttpStatus("500", "Reading Article file: "s + ex.what(), SetResponseHeader);  | 
