diff options
Diffstat (limited to 'libcommon')
| -rw-r--r-- | libcommon/Makefile | 123 | ||||
| -rw-r--r-- | libcommon/mime.cpp | 41 | ||||
| -rw-r--r-- | libcommon/mime.h | 5 | 
3 files changed, 169 insertions, 0 deletions
diff --git a/libcommon/Makefile b/libcommon/Makefile new file mode 100644 index 0000000..3314549 --- /dev/null +++ b/libcommon/Makefile @@ -0,0 +1,123 @@ +# Static library to be included both in main program an in plugins (.so) + +DISTROS=debian10 +VERSION=$(shell dpkg-parsechangelog --show-field Version) +PROJECTNAME=libcommon + +CXX=clang++-10 + +ifeq ($(shell which $(CXX)),) +CXX=clang++ +endif + +ifeq ($(shell which $(CXX)),) +CXX=g++-9 +endif + +ifeq ($(CXXFLAGS),) +#CXXFLAGS=-O2 -DNDEBUG +CXXFLAGS=-O0 -g -D_DEBUG +endif +# -fprofile-instr-generate -fcoverage-mapping +# gcc:--coverage + +CXXFLAGS+= -Wall -I. + +CXXFLAGS+= -pthread -fvisibility=hidden -fPIC +ifeq ($(CXX),clang++-10) +CXXFLAGS+=-std=c++20 #-stdlib=libc++ +else +CXXFLAGS+=-std=c++17 +endif + +CXXTESTFLAGS=-Igoogletest/include -Igooglemock/include/ -Igoogletest -Igooglemock + +LIBS=\ +-lboost_context \ +-lboost_coroutine \ +-lboost_program_options \ +-lboost_system \ +-lboost_thread \ +-lboost_filesystem \ +-lboost_regex \ +-lpthread \ +-lssl -lcrypto \ +-ldl + +ifeq ($(CXX),clang++-10) +LIBS+= \ +-fuse-ld=lld-10 \ +-lstdc++ +#-lc++ \ +#-lc++abi +#-lc++fs +#-lstdc++fs +else +LIBS+= \ +-lstdc++ \ +-lstdc++fs +endif + +PROGSRC=\ +    mime.cpp + +TESTSRC=\ +    test-webserver.cpp \ +    googlemock/src/gmock-all.cpp \ +    googletest/src/gtest-all.cpp \ +    $(PROGSRC) + +SRC=$(PROGSRC) + +all: $(PROJECTNAME).a + +# testsuite ---------------------------------------------- +test-$(PROJECTNAME): $(TESTSRC:.cpp=.o) +	$(CXX) $(CXXFLAGS) $^ $(LIBS) -o $@ + +$(PROJECTNAME).a: $(SRC:.cpp=.o) +	ar rcs $@ $^ + +dep: $(TESTSRC:.cpp=.d) + +%.d: %.cpp +	$(CXX) $(CXXFLAGS) $(CXXTESTFLAGS) -MM -MP -MF $@ -c $< + +%.o: %.cpp %.d +	$(CXX) $(CXXFLAGS) $(CXXTESTFLAGS) -c $< -o $@ + +googletest/src/%.o: googletest/src/%.cc +	$(CXX) $(CXXFLAGS) $(CXXTESTFLAGS) -c $< -o $@ + +# dependencies + +ADD_DEP=Makefile + + +# misc --------------------------------------------------- +deb: +	# build binary deb package +	dpkg-buildpackage -us -uc -rfakeroot + +deb-src: +	dpkg-source -b . + +$(DISTROS): deb-src +	sudo pbuilder build --basetgz /var/cache/pbuilder/$@.tgz --buildresult result/$@ ../webserver_$(VERSION).dsc ; \ + +debs: $(DISTROS) + +clean: +	-rm -f test-$(PROJECTNAME) $(PROJECTNAME) +	-find . -name '*.a' -o -name '*.o' -o -name '*.so' -o -name '*.d' -o -name '*.gcno' -o -name '*.gcda' | xargs rm -f + +zip: clean +	-rm -f ../$(PROJECTNAME).zip +	zip -r ../$(PROJECTNAME).zip * +	ls -l ../$(PROJECTNAME).zip + + + +.PHONY: clean all zip install deb deb-src debs all $(DISTROS) + +-include $(wildcard $(SRC:.cpp=.d)) diff --git a/libcommon/mime.cpp b/libcommon/mime.cpp new file mode 100644 index 0000000..f093596 --- /dev/null +++ b/libcommon/mime.cpp @@ -0,0 +1,41 @@ +#include "mime.h" + +#include <boost/beast/http.hpp> + +namespace beast = boost::beast;  + +// Return a reasonable mime type based on the extension of a file. +std::string mime_type(const std::string& path) +{ +    using beast::iequals; +    auto const ext = [&path] +    { +        auto const pos = path.rfind("."); +        if (pos == std::string::npos) +            return std::string{}; +        return path.substr(pos); +    }(); +    if(iequals(ext, ".htm"))  return "text/html"; +    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"; +} + diff --git a/libcommon/mime.h b/libcommon/mime.h new file mode 100644 index 0000000..c05eb45 --- /dev/null +++ b/libcommon/mime.h @@ -0,0 +1,5 @@ +#pragma once + +#include <string> + +std::string mime_type(const std::string& path);  | 
