diff options
author | Roland Reichwein <mail@reichwein.it> | 2020-06-06 13:58:22 +0200 |
---|---|---|
committer | Roland Reichwein <mail@reichwein.it> | 2020-06-06 13:58:22 +0200 |
commit | d0db131a73933d0a6c65bab59d1e0e4f6a185338 (patch) | |
tree | 06edad4d845c8ba4102843fc3b306d7b5cc485d6 | |
parent | 343922258d57261021daca42eb488c1205ae491c (diff) |
Code cleanup, use gcc 8 on debian 10
-rw-r--r-- | Makefile | 62 | ||||
-rw-r--r-- | archive.h | 29 | ||||
-rw-r--r-- | common.mk | 53 | ||||
-rw-r--r-- | http.cpp | 18 | ||||
-rw-r--r-- | https.cpp | 12 | ||||
-rw-r--r-- | libcommon/Makefile | 79 | ||||
-rw-r--r-- | libcommon/tempfile.cpp | 11 | ||||
-rw-r--r-- | plugins/cgi/Makefile | 73 | ||||
-rw-r--r-- | plugins/fcgi/Makefile | 68 | ||||
-rw-r--r-- | plugins/redirect/Makefile | 72 | ||||
-rw-r--r-- | plugins/static-files/Makefile | 73 | ||||
-rw-r--r-- | plugins/statistics/Makefile | 74 | ||||
-rw-r--r-- | plugins/webbox/Makefile | 80 | ||||
-rw-r--r-- | plugins/weblog/Makefile | 76 | ||||
-rw-r--r-- | statistics.cpp | 2 | ||||
-rw-r--r-- | tests/Makefile | 57 |
16 files changed, 208 insertions, 631 deletions
@@ -1,5 +1,8 @@ -DISTROS=debian10 ubuntu1910 ubuntu2004 +include common.mk + VERSION=$(shell dpkg-parsechangelog --show-field Version) + +DISTROS=debian10 ubuntu1910 ubuntu2004 PROJECTNAME=webserver PLUGINS= \ cgi \ @@ -10,37 +13,9 @@ PLUGINS= \ webbox \ weblog -CXX=clang++-10 - -ifeq ($(shell which $(CXX)),) -CXX=clang++ -endif - -ifeq ($(shell which $(CXX)),) -CXX=g++-9 -endif +CXXFLAGS+=-fPIE -DVERSION=\"$(VERSION)\" -ifeq ($(shell which $(CXX)),) -CXX=g++ -endif - -ifeq ($(CXXFLAGS),) -#CXXFLAGS=-O2 -DNDEBUG -CXXFLAGS=-O0 -g -D_DEBUG -endif -# -fprofile-instr-generate -fcoverage-mapping -# gcc:--coverage - -CXXFLAGS+=-Wall -I. -DVERSION=\"$(VERSION)\" -fPIE - -CXXFLAGS+=-pthread -ifeq ($(CXX),clang++-10) -CXXFLAGS+=-std=c++20 #-stdlib=libc++ -else -CXXFLAGS+=-std=c++17 -endif - -LIBS=\ +LDLIBS+=\ -lcommon \ -lboost_context \ -lboost_filesystem \ @@ -56,20 +31,6 @@ LIBS=\ #-lboost_thread \ #-lboost_regex \ -ifeq ($(CXX),clang++-10) -LIBS+= \ --fuse-ld=lld-10 \ --lstdc++ -#-lc++ \ -#-lc++abi -#-lc++fs -#-lstdc++fs -else -LIBS+= \ --lstdc++ \ --lstdc++fs -endif - LDFLAGS+=-pie -Llibcommon PROGSRC=\ @@ -87,8 +48,7 @@ PROGSRC=\ SRC=$(PROGSRC) webserver.cpp -build: $(PROJECTNAME) - +set -e ; for i in $(PLUGINS) ; do make -C plugins/$$i ; done +build: $(PROJECTNAME) $(PLUGINS) all: build ./webserver -c webserver.conf @@ -99,6 +59,9 @@ $(PROJECTNAME): libcommon/libcommon.a $(SRC:.cpp=.o) libcommon/libcommon.a: $(MAKE) -C libcommon +$(PLUGINS): + cd plugins/$@ && $(MAKE) + %.d: %.cpp $(CXX) $(CXXFLAGS) -MM -MP -MF $@ -c $< @@ -146,7 +109,7 @@ debs: $(DISTROS) clean: -rm -f $(PROJECTNAME) -rm -f plugins/*.so - -find . -name '*.o' -o -name '*.d' -o -name '*.gcno' -o -name '*.gcda' | xargs rm -f + -find . -name '*.o' -o -name '*.d' -o -name '*.gcno' -o -name '*.gcda' -o -name '*.so' | xargs rm -f #for i in $(PLUGINS) ; do $(MAKE) -C plugins/$$i clean ; done for i in libcommon tests ; do $(MAKE) -C $$i clean ; done @@ -182,6 +145,7 @@ DISTFILES= \ README.txt \ LICENSE.txt \ Makefile \ + common.mk \ googletest \ googlemock \ debian/changelog \ @@ -253,6 +217,6 @@ dist: clean rm -rf $(PROJECTNAME)-$(VERSION) ls -l ../$(PROJECTNAME)-$(VERSION).tar.xz -.PHONY: clean all zip test install deb deb-src debs all $(DISTROS) +.PHONY: clean all zip test install deb deb-src debs all $(DISTROS) $(PLUGINS) -include $(wildcard $(SRC:.cpp=.d)) @@ -5,6 +5,7 @@ #include <cstdint> #include <ostream> +#include <iostream> #include <istream> #include <sstream> #include <string> @@ -103,8 +104,18 @@ public: { // in coroutine case, wait for input, if necessary if (mCoro && mStringStream) { - while (mStringStream->tellp() - mStringStream->tellg() < sizeof(v)) { - (*mCoro)(); + while (true) { + auto pindex {mStringStream->tellp()}; + auto gindex {mStringStream->tellg()}; + if (pindex != std::stringstream::pos_type(-1) && gindex != std::stringstream::pos_type(-1) && pindex > gindex) { + if (static_cast<size_t>(pindex - gindex) < sizeof(v)) + (*mCoro)(); + else + break; + } else { + std::cerr << "Error: read_fundamental: Bad stringstream indices: " << pindex << ", " << gindex << std::endl; + break; + } } } @@ -153,8 +164,18 @@ public: // in coroutine case, wait for input, if necessary if (mCoro && mStringStream) { - while (mStringStream->tellp() - mStringStream->tellg() < size) { - (*mCoro)(); + while (true) { + auto pindex {mStringStream->tellp()}; + auto gindex {mStringStream->tellg()}; + if (pindex != std::stringstream::pos_type(-1) && gindex != std::stringstream::pos_type(-1) && pindex > gindex) { + if (static_cast<uint32_t>(pindex - gindex) < size) + (*mCoro)(); + else + break; + } else { + std::cerr << "Error: read_bytes_vector: Bad stringstream indices: " << pindex << ", " << gindex << std::endl; + break; + } } } diff --git a/common.mk b/common.mk new file mode 100644 index 0000000..0ce4df8 --- /dev/null +++ b/common.mk @@ -0,0 +1,53 @@ +CXX=g++-10 +#CXX=clang++-10 + +ifeq ($(shell which $(CXX)),) +CXX=g++-8 +endif + +ifeq ($(shell which $(CXX)),) +CXX=clang++ +endif + +ifeq ($(shell which $(CXX)),) +CXX=g++-10 +endif + +ifeq ($(shell which $(CXX)),) +CXX=g++-9 +endif + +ifeq ($(shell which $(CXX)),) +CXX=g++ +endif + +#ifeq ($(CXXFLAGS),) +#CXXFLAGS=-O2 -DNDEBUG +CXXFLAGS=-O0 -g -D_DEBUG +#endif +# -fprofile-instr-generate -fcoverage-mapping +# gcc:--coverage + +CXXFLAGS+=-Wall -I. + +CXXFLAGS+=-pthread +ifeq ($(CXX),clang++-10) +CXXFLAGS+=-std=c++20 #-stdlib=libc++ +else +CXXFLAGS+=-std=c++17 +endif + +ifeq ($(CXX),clang++-10) +LIBS+= \ +-fuse-ld=lld-10 \ +-lstdc++ +#-lc++ \ +#-lc++abi +#-lc++fs +#-lstdc++fs +else +LIBS+= \ +-lstdc++ \ +-lstdc++fs +endif + @@ -40,8 +40,7 @@ namespace { //------------------------------------------------------------------------------ // Report a failure -void -fail(beast::error_code ec, char const* what) +void fail(beast::error_code ec, char const* what) { std::cerr << what << ": " << ec.message() << "\n"; } @@ -59,7 +58,7 @@ class session : public std::enable_shared_from_this<session> Server& m_server; std::optional<http::request_parser<http::string_body>> parser_; request_type req_; - std::shared_ptr<response_type> res_; + std::shared_ptr<response_type> res_; // std::shared_ptr<void> ? void handle_request(::Server& server, request_type&& req) { @@ -116,8 +115,7 @@ public: } // Start the asynchronous operation - void - run() + void run() { // We need to be executing within a strand to perform async operations // on the I/O objects in this session. @@ -131,8 +129,7 @@ public: #endif } - void - do_read() + void do_read() { // Make the request empty before reading, // otherwise the operation behavior is undefined. @@ -179,10 +176,13 @@ public: boost::ignore_unused(bytes_transferred); // This means they closed the connection - if(ec == http::error::end_of_stream) + if (ec == http::error::end_of_stream) return do_close(); - if(ec) + if (ec == http::error::partial_message) + return; // ignore + + if (ec) return fail(ec, "read"); req_ = parser_->get(); @@ -46,8 +46,7 @@ namespace { //------------------------------------------------------------------------------ // Report a failure -void -fail( +void fail( #ifdef BOOST_LATEST beast::error_code ec, #else @@ -94,7 +93,7 @@ class session : public std::enable_shared_from_this<session> Server& m_server; std::optional<http::request_parser<http::string_body>> parser_; // need to reset parser every time, no other mechanism currently http::request<http::string_body> req_; - std::shared_ptr<response_type> res_; + std::shared_ptr<response_type> res_; // std::shared_ptr<void> void handle_request(::Server& server, request_type&& req) { @@ -253,10 +252,13 @@ public: boost::ignore_unused(bytes_transferred); // This means they closed the connection - if(ec == http::error::end_of_stream) + if (ec == http::error::end_of_stream) return do_close(); - if(ec) + if (ec == http::error::partial_message) + return; // ignore + + if (ec) return fail(ec, "https read"); req_ = parser_->get(); diff --git a/libcommon/Makefile b/libcommon/Makefile index ab76ed1..d3d781d 100644 --- a/libcommon/Makefile +++ b/libcommon/Makefile @@ -1,60 +1,10 @@ # 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 +include ../common.mk -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 - -LIBS=\ --lboost_context \ --lboost_coroutine \ --lboost_program_options \ --lboost_system \ --lboost_thread \ --lboost_filesystem \ --lboost_regex \ --lpthread \ --lssl -lcrypto \ --ldl +PROJECTNAME=libcommon -ifeq ($(CXX),clang++-10) -LIBS+= \ --fuse-ld=lld-10 \ --lstdc++ -#-lc++ \ -#-lc++abi -#-lc++fs -#-lstdc++fs -else -LIBS+= \ --lstdc++ \ --lstdc++fs -endif +CXXFLAGS+= -fvisibility=hidden -fPIC PROGSRC=\ file.cpp \ @@ -79,29 +29,10 @@ $(PROJECTNAME).a: $(SRC:.cpp=.o) 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 *.o *.a *.d -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) +.PHONY: clean all install -include $(wildcard $(SRC:.cpp=.d)) diff --git a/libcommon/tempfile.cpp b/libcommon/tempfile.cpp index 5d3a086..c30bb57 100644 --- a/libcommon/tempfile.cpp +++ b/libcommon/tempfile.cpp @@ -1,5 +1,9 @@ #include "tempfile.h" +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + #include <iostream> namespace fs = std::filesystem; @@ -12,7 +16,12 @@ fs::path Tempfile::GetPath() const Tempfile::Tempfile() { try { - m_path = std::string{tmpnam(NULL)} + ".zip"s; + char name[] = "/tmp/tempfileXXXXXX.zip"; + int fd = mkstemps(name, 4); + if (fd == -1) + std::runtime_error("mkstemps: "s + strerror(errno)); + close(fd); + m_path = std::string{name}; } catch (const std::exception& ex) { throw std::runtime_error("Tempfile error: "s + ex.what()); } diff --git a/plugins/cgi/Makefile b/plugins/cgi/Makefile index 2d86c50..df51e89 100644 --- a/plugins/cgi/Makefile +++ b/plugins/cgi/Makefile @@ -1,34 +1,12 @@ -DISTROS=debian10 -VERSION=$(shell dpkg-parsechangelog --show-field Version) -PROJECTNAME=cgi - -CXX=clang++-10 - -ifeq ($(shell which $(CXX)),) -CXX=clang++ -endif - -ifeq ($(shell which $(CXX)),) -CXX=g++-9 -endif +include ../../common.mk -ifeq ($(CXXFLAGS),) -#CXXFLAGS=-O2 -DNDEBUG -CXXFLAGS=-O0 -g -D_DEBUG -endif -# -fprofile-instr-generate -fcoverage-mapping -# gcc:--coverage +PROJECTNAME=cgi -CXXFLAGS+= -Wall -I. -I ../.. +CXXFLAGS+= -fvisibility=hidden -fPIC -CXXFLAGS+= -pthread -fvisibility=hidden -fPIC -ifeq ($(CXX),clang++-10) -CXXFLAGS+=-std=c++20 #-stdlib=libc++ -else -CXXFLAGS+=-std=c++17 -endif +CXXFLAGS+= -I../.. -LIBS=\ +LDLIBS=\ -lcommon \ -lboost_context \ -lboost_coroutine \ @@ -41,21 +19,7 @@ LIBS=\ -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 - -LDFLAGS=-L../../libcommon +LDFLAGS+=-L../../libcommon PROGSRC=\ cgi.cpp @@ -67,6 +31,9 @@ all: $(PROJECTNAME).so $(PROJECTNAME).so: ../../libcommon/libcommon.a $(SRC:.cpp=.o) $(CXX) $(LDFLAGS) $^ -shared $(LDLIBS) $(LIBS) -o $@ +../../libcommon/libcommon.a: + cd ../.. && $(MAKE) libcommon/libcommon.a + %.d: %.cpp $(CXX) $(CXXFLAGS) -MM -MP -MF $@ -c $< @@ -82,27 +49,9 @@ install: cp $(PROJECTNAME).so $(DESTDIR)/usr/lib/webserver/plugins # 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 *.o *.so *.d -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) +.PHONY: clean install all -include $(wildcard $(SRC:.cpp=.d)) diff --git a/plugins/fcgi/Makefile b/plugins/fcgi/Makefile index 8937689..d3b8ed1 100644 --- a/plugins/fcgi/Makefile +++ b/plugins/fcgi/Makefile @@ -1,34 +1,12 @@ -DISTROS=debian10 -VERSION=$(shell dpkg-parsechangelog --show-field Version) -PROJECTNAME=fcgi - -CXX=clang++-10 - -ifeq ($(shell which $(CXX)),) -CXX=clang++ -endif +include ../../common.mk -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 +PROJECTNAME=fcgi -CXXFLAGS+= -Wall -I. +CXXFLAGS+= -fvisibility=hidden -fPIC -CXXFLAGS+= -pthread -fvisibility=hidden -fPIC -ifeq ($(CXX),clang++-10) -CXXFLAGS+=-std=c++20 #-stdlib=libc++ -else -CXXFLAGS+=-std=c++17 -endif +CXXFLAGS+= -I../.. -LIBS=\ +LDLIBS=\ -lboost_context \ -lboost_coroutine \ -lboost_program_options \ @@ -40,19 +18,7 @@ LIBS=\ -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 +LDFLAGS+=-L../../libcommon PROGSRC=\ fcgi.cpp \ @@ -66,6 +32,9 @@ all: $(PROJECTNAME).so $(PROJECTNAME).so: $(SRC:.cpp=.o) $(CXX) $(CXXFLAGS) $^ -shared $(LIBS) -o $@ +../../libcommon/libcommon.a: + cd ../.. && $(MAKE) libcommon/libcommon.a + %.d: %.cpp $(CXX) $(CXXFLAGS) -MM -MP -MF $@ -c $< @@ -81,27 +50,12 @@ install: cp $(PROJECTNAME).so $(DESTDIR)/usr/lib/webserver/plugins # 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 *.o *.so *.d -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) +.PHONY: clean install all -include $(wildcard $(SRC:.cpp=.d)) diff --git a/plugins/redirect/Makefile b/plugins/redirect/Makefile index 77b496b..344aa91 100644 --- a/plugins/redirect/Makefile +++ b/plugins/redirect/Makefile @@ -1,34 +1,12 @@ -DISTROS=debian10 -VERSION=$(shell dpkg-parsechangelog --show-field Version) -PROJECTNAME=redirect - -CXX=clang++-10 - -ifeq ($(shell which $(CXX)),) -CXX=clang++ -endif +include ../../common.mk -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 +PROJECTNAME=redirect -CXXFLAGS+= -Wall -I. +CXXFLAGS+= -fvisibility=hidden -fPIC -CXXFLAGS+= -pthread -fvisibility=hidden -fPIC -ifeq ($(CXX),clang++-10) -CXXFLAGS+=-std=c++20 #-stdlib=libc++ -else -CXXFLAGS+=-std=c++17 -endif +CXXFLAGS+= -I../.. -LIBS=\ +LDLIBS=\ -lboost_context \ -lboost_coroutine \ -lboost_program_options \ @@ -40,19 +18,7 @@ LIBS=\ -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 +LDFLAGS+=-L../../libcommon PROGSRC=\ redirect.cpp @@ -64,6 +30,9 @@ all: $(PROJECTNAME).so $(PROJECTNAME).so: $(SRC:.cpp=.o) $(CXX) $(CXXFLAGS) $^ -shared $(LIBS) -o $@ +../../libcommon/libcommon.a: + cd ../.. && $(MAKE) libcommon/libcommon.a + %.d: %.cpp $(CXX) $(CXXFLAGS) -MM -MP -MF $@ -c $< @@ -75,29 +44,10 @@ install: cp $(PROJECTNAME).so $(DESTDIR)/usr/lib/webserver/plugins # 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 $(PROJECTNAME) - -find . -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 - - + -rm -f *.o *.so *.d -.PHONY: clean all zip install deb deb-src debs all $(DISTROS) +.PHONY: clean install all -include $(wildcard $(SRC:.cpp=.d)) diff --git a/plugins/static-files/Makefile b/plugins/static-files/Makefile index 9834e96..f4cfb31 100644 --- a/plugins/static-files/Makefile +++ b/plugins/static-files/Makefile @@ -1,34 +1,12 @@ -DISTROS=debian10 -VERSION=$(shell dpkg-parsechangelog --show-field Version) -PROJECTNAME=static-files - -CXX=clang++-10 - -ifeq ($(shell which $(CXX)),) -CXX=clang++ -endif - -ifeq ($(shell which $(CXX)),) -CXX=g++-9 -endif +include ../../common.mk -ifeq ($(CXXFLAGS),) -#CXXFLAGS=-O2 -DNDEBUG -CXXFLAGS=-O0 -g -D_DEBUG -endif -# -fprofile-instr-generate -fcoverage-mapping -# gcc:--coverage +PROJECTNAME=static-files -CXXFLAGS+= -Wall -I. -I../.. +CXXFLAGS+= -fvisibility=hidden -fPIC -CXXFLAGS+= -pthread -fvisibility=hidden -fPIC -ifeq ($(CXX),clang++-10) -CXXFLAGS+=-std=c++20 #-stdlib=libc++ -else -CXXFLAGS+=-std=c++17 -endif +CXXFLAGS+= -I../.. -LIBS=\ +LDLIBS=\ -lcommon \ -lboost_context \ -lboost_coroutine \ @@ -41,20 +19,6 @@ LIBS=\ -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 - LDFLAGS=-L../../libcommon PROGSRC=\ @@ -67,6 +31,9 @@ all: $(PROJECTNAME).so $(PROJECTNAME).so: ../../libcommon/libcommon.a $(SRC:.cpp=.o) $(CXX) $(LDFLAGS) $^ -shared $(LDLIBS) $(LIBS) -o $@ +../../libcommon/libcommon.a: + cd ../.. && $(MAKE) libcommon/libcommon.a + %.d: %.cpp $(CXX) $(CXXFLAGS) -MM -MP -MF $@ -c $< @@ -82,29 +49,9 @@ install: cp $(PROJECTNAME).so $(DESTDIR)/usr/lib/webserver/plugins # 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 $(PROJECTNAME) - -find . -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 - - + -rm -f *.o *.so *.d -.PHONY: clean all zip install deb deb-src debs all $(DISTROS) +.PHONY: clean all install -include $(wildcard $(SRC:.cpp=.d)) diff --git a/plugins/statistics/Makefile b/plugins/statistics/Makefile index 2a0d246..8e8a6f7 100644 --- a/plugins/statistics/Makefile +++ b/plugins/statistics/Makefile @@ -1,34 +1,13 @@ -DISTROS=debian10 -VERSION=$(shell dpkg-parsechangelog --show-field Version) -PROJECTNAME=statistics - -CXX=clang++-10 - -ifeq ($(shell which $(CXX)),) -CXX=clang++ -endif - -ifeq ($(shell which $(CXX)),) -CXX=g++-9 -endif +include ../../common.mk -ifeq ($(CXXFLAGS),) -#CXXFLAGS=-O2 -DNDEBUG -CXXFLAGS=-O0 -g -D_DEBUG -endif -# -fprofile-instr-generate -fcoverage-mapping -# gcc:--coverage +PROJECTNAME=statistics -CXXFLAGS+= -Wall -I. +CXXFLAGS+= -fvisibility=hidden -fPIC -CXXFLAGS+= -pthread -fvisibility=hidden -fPIC -ifeq ($(CXX),clang++-10) -CXXFLAGS+=-std=c++20 #-stdlib=libc++ -else -CXXFLAGS+=-std=c++17 -endif +CXXFLAGS+= -I../.. -LIBS=\ +LDLIBS=\ +-lcommon \ -lboost_context \ -lboost_coroutine \ -lboost_program_options \ @@ -40,19 +19,7 @@ LIBS=\ -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 +LDFLAGS=-L../../libcommon PROGSRC=\ statistics.cpp @@ -64,6 +31,9 @@ all: $(PROJECTNAME).so $(PROJECTNAME).so: $(SRC:.cpp=.o) $(CXX) $(CXXFLAGS) $^ -shared $(LIBS) -o $@ +../../libcommon/libcommon.a: + cd ../.. && $(MAKE) libcommon/libcommon.a + %.d: %.cpp $(CXX) $(CXXFLAGS) -MM -MP -MF $@ -c $< @@ -75,29 +45,9 @@ install: cp $(PROJECTNAME).so $(DESTDIR)/usr/lib/webserver/plugins # 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 $(PROJECTNAME) - -find . -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 - - + -rm -f *.o *.so *.d -.PHONY: clean all zip install deb deb-src debs all $(DISTROS) +.PHONY: clean all install -include $(wildcard $(SRC:.cpp=.d)) diff --git a/plugins/webbox/Makefile b/plugins/webbox/Makefile index 861b5d4..39a2c8c 100644 --- a/plugins/webbox/Makefile +++ b/plugins/webbox/Makefile @@ -1,34 +1,12 @@ -DISTROS=debian10 -VERSION=$(shell dpkg-parsechangelog --show-field Version) -PROJECTNAME=webbox - -CXX=clang++-10 - -ifeq ($(shell which $(CXX)),) -CXX=clang++ -endif - -ifeq ($(shell which $(CXX)),) -CXX=g++-9 -endif +include ../../common.mk -ifeq ($(CXXFLAGS),) -#CXXFLAGS=-O2 -DNDEBUG -CXXFLAGS=-O0 -g -D_DEBUG -endif -# -fprofile-instr-generate -fcoverage-mapping -# gcc:--coverage +PROJECTNAME=webbox -CXXFLAGS+= -Wall -I. -I../.. +CXXFLAGS+= -fvisibility=hidden -fPIC -CXXFLAGS+= -pthread -fvisibility=hidden -fPIC -ifeq ($(CXX),clang++-10) -CXXFLAGS+=-std=c++20 #-stdlib=libc++ -else -CXXFLAGS+=-std=c++17 -endif +CXXFLAGS+= -I../.. -LIBS=\ +LDLIBS=\ -lcommon \ -lboost_context \ -lboost_coroutine \ @@ -41,21 +19,7 @@ LIBS=\ -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 - -LDFLAGS+=-L../../libcommon +LDFLAGS=-L../../libcommon PROGSRC=\ webbox.cpp @@ -67,12 +31,19 @@ all: $(PROJECTNAME).so $(PROJECTNAME).so: ../../libcommon/libcommon.a $(SRC:.cpp=.o) $(CXX) $(LDFLAGS) $^ -shared $(LDLIBS) $(LIBS) -o $@ +../../libcommon/libcommon.a: + cd ../.. && $(MAKE) libcommon/libcommon.a + %.d: %.cpp $(CXX) $(CXXFLAGS) -MM -MP -MF $@ -c $< %.o: %.cpp %.d $(CXX) $(CXXFLAGS) -c $< -o $@ +# dependencies + +ADD_DEP=Makefile + install: mkdir -p $(DESTDIR)/usr/lib/webserver/plugins cp $(PROJECTNAME).so $(DESTDIR)/usr/lib/webserver/plugins @@ -84,31 +55,10 @@ install: htmlmin html/index.html $(DESTDIR)/usr/lib/webbox/html/index.html cleancss -o $(DESTDIR)/usr/lib/webbox/html/webbox.css html/webbox.css - # 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 $(PROJECTNAME) - -find . -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 - - + -rm -f *.o *.so *.d -.PHONY: clean all zip install deb deb-src debs all $(DISTROS) +.PHONY: clean all install -include $(wildcard $(SRC:.cpp=.d)) diff --git a/plugins/weblog/Makefile b/plugins/weblog/Makefile index a21b464..ca62ce8 100644 --- a/plugins/weblog/Makefile +++ b/plugins/weblog/Makefile @@ -1,34 +1,12 @@ -DISTROS=debian10 -VERSION=$(shell dpkg-parsechangelog --show-field Version) -PROJECTNAME=weblog - -CXX=clang++-10 - -ifeq ($(shell which $(CXX)),) -CXX=clang++ -endif - -ifeq ($(shell which $(CXX)),) -CXX=g++-9 -endif +include ../../common.mk -ifeq ($(CXXFLAGS),) -#CXXFLAGS=-O2 -DNDEBUG -CXXFLAGS=-O0 -g -D_DEBUG -endif -# -fprofile-instr-generate -fcoverage-mapping -# gcc:--coverage +PROJECTNAME=weblog -CXXFLAGS+= -Wall -I. -I../.. +CXXFLAGS+= -fvisibility=hidden -fPIC -CXXFLAGS+= -pthread -fvisibility=hidden -fPIC -ifeq ($(CXX),clang++-10) -CXXFLAGS+=-std=c++20 #-stdlib=libc++ -else -CXXFLAGS+=-std=c++17 -endif +CXXFLAGS+= -I../.. -LIBS=\ +LDLIBS=\ -lcommon \ -lboost_context \ -lboost_coroutine \ @@ -41,20 +19,6 @@ LIBS=\ -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 - LDFLAGS=-L../../libcommon PROGSRC=\ @@ -67,15 +31,15 @@ all: $(PROJECTNAME).so $(PROJECTNAME).so: ../../libcommon/libcommon.a $(SRC:.cpp=.o) $(CXX) $(LDFLAGS) $^ -shared $(LDLIBS) $(LIBS) -o $@ +../../libcommon/libcommon.a: + cd ../.. && $(MAKE) libcommon/libcommon.a + %.d: %.cpp $(CXX) $(CXXFLAGS) -MM -MP -MF $@ -c $< %.o: %.cpp %.d $(CXX) $(CXXFLAGS) -c $< -o $@ -googletest/src/%.o: googletest/src/%.cc - $(CXX) $(CXXFLAGS) -c $< -o $@ - # dependencies ADD_DEP=Makefile @@ -85,29 +49,9 @@ install: cp $(PROJECTNAME).so $(DESTDIR)/usr/lib/webserver/plugins # 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 '*.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 - - + -rm -f *.o *.so *.d -.PHONY: clean all zip install deb deb-src debs all $(DISTROS) +.PHONY: clean install all -include $(wildcard $(SRC:.cpp=.d)) diff --git a/statistics.cpp b/statistics.cpp index 3fb99a3..6138cca 100644 --- a/statistics.cpp +++ b/statistics.cpp @@ -57,7 +57,7 @@ Statistics::~Statistics() bool Statistics::Bin::expired() const { - auto now {time(nullptr)}; + uint64_t now {static_cast<uint64_t>(time(nullptr))}; if (now < start_time) std::runtime_error("Statistics time is in the future"); diff --git a/tests/Makefile b/tests/Makefile index 2bccae4..2f0e809 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -1,35 +1,8 @@ -DISTROS=debian10 ubuntu1910 ubuntu2004 -PROJECTNAME=test-webserver - -CXX=clang++-10 - -ifeq ($(shell which $(CXX)),) -CXX=clang++ -endif - -ifeq ($(shell which $(CXX)),) -CXX=g++-9 -endif +include ../common.mk -ifeq ($(shell which $(CXX)),) -CXX=g++ -endif - -ifeq ($(CXXFLAGS),) -#CXXFLAGS=-O2 -DNDEBUG -CXXFLAGS=-O0 -g -D_DEBUG -endif -# -fprofile-instr-generate -fcoverage-mapping -# gcc:--coverage - -CXXFLAGS+= -Wall -I. -fPIE +PROJECTNAME=test-webserver -CXXFLAGS+= -pthread -ifeq ($(CXX),clang++-10) -CXXFLAGS+=-std=c++20 #-stdlib=libc++ -else -CXXFLAGS+=-std=c++17 -endif +CXXFLAGS+= -I. -fPIE CXXTESTFLAGS=-I../googletest/include -I../googlemock/include/ -I../googletest -I../googlemock @@ -44,25 +17,6 @@ LIBS=\ -lssl -lcrypto \ -ldl -#-lboost_coroutine \ -#-lboost_program_options \ -#-lboost_thread \ -#-lboost_regex \ - -ifeq ($(CXX),clang++-10) -LIBS+= \ --fuse-ld=lld-10 \ --lstdc++ -#-lc++ \ -#-lc++abi -#-lc++fs -#-lstdc++fs -else -LIBS+= \ --lstdc++ \ --lstdc++fs -endif - LDFLAGS+=-pie -L../libcommon TESTSRC=\ @@ -104,9 +58,8 @@ install: # misc --------------------------------------------------- clean: - -rm -f $(PROJECTNAME) - -find . -name '*.o' -o -name '*.d' -o -name '*.gcno' -o -name '*.gcda' | xargs rm -f + -rm -f *.o *.a *.d $(PROJECTNAME) -.PHONY: clean all install all $(DISTROS) +.PHONY: clean all install -include $(wildcard $(TESTSRC:.cpp=.d)) |