From e40716d53414eacf2a82222efa2cf776b2f1b5df Mon Sep 17 00:00:00 2001 From: waTeim Date: Thu, 13 Feb 2014 15:39:17 -0500 Subject: [PATCH 1/4] Fixes/changes for OS/X compilation Added various include directives in http_response.cpp and http_resource.cpp and modified http_endpoint copy constructor to make it public to satifify clang. Fixed typo/bug in http_request::set_requestor_port. Modified various forwards to match actual declarations. Modified configure to allow build in same directory. --- configure.ac | 4 ---- src/http_resource.cpp | 4 ++++ src/http_response.cpp | 3 +++ src/httpserver/details/http_endpoint.hpp | 5 +++-- src/httpserver/http_request.hpp | 2 +- src/httpserver/webserver.hpp | 6 +++--- 6 files changed, 14 insertions(+), 10 deletions(-) diff --git a/configure.ac b/configure.ac index d4f2ae9c..dbd4b287 100644 --- a/configure.ac +++ b/configure.ac @@ -39,10 +39,6 @@ CXXFLAGS=$OLD_CXXFLAGS AC_LANG([C++]) AC_SYS_LARGEFILE -if test "`cd $srcdir; /bin/pwd`" = "`/bin/pwd`"; then - AC_MSG_ERROR("you must configure in a separate build directory") -fi - # Checks for header files. AC_HEADER_STDC AC_CHECK_HEADER([string],[],[AC_MSG_ERROR("C++ strings not found")]) diff --git a/src/http_resource.cpp b/src/http_resource.cpp index 19a59a0f..03437315 100644 --- a/src/http_resource.cpp +++ b/src/http_resource.cpp @@ -17,10 +17,14 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ + +#include + #include "http_resource.hpp" #include "http_utils.hpp" #include "http_request.hpp" #include "http_response.hpp" +#include "details/event_tuple.hpp" #include "webserver.hpp" #include "string_utilities.hpp" diff --git a/src/http_response.cpp b/src/http_response.cpp index 11e5e2ae..87a7e911 100644 --- a/src/http_response.cpp +++ b/src/http_response.cpp @@ -25,9 +25,12 @@ #include #include #include "http_utils.hpp" +#include "details/http_resource_mirror.hpp" +#include "details/event_tuple.hpp" #include "webserver.hpp" #include "http_response.hpp" + using namespace std; namespace httpserver diff --git a/src/httpserver/details/http_endpoint.hpp b/src/httpserver/details/http_endpoint.hpp index 120c6749..4094b2ba 100644 --- a/src/httpserver/details/http_endpoint.hpp +++ b/src/httpserver/details/http_endpoint.hpp @@ -38,7 +38,7 @@ class webserver; namespace details { -struct http_resource_mirror; +class http_resource_mirror; /** * Exception class throwed when a bad formatted http url is used @@ -60,7 +60,7 @@ class bad_http_endpoint : public std::exception **/ class http_endpoint { - private: + public: /** * Copy constructor. It is useful expecially to copy regex_t structure that contains dinamically allocated data. * @param h The http_endpoint to copy @@ -75,6 +75,7 @@ class http_endpoint * @param b The http_endpoint to compare to * @return boolean indicating if this is less than b. **/ + private: bool operator <(const http_endpoint& b) const; /** * Operator overload for "assignment operator". It is used to copy endpoints to existing objects. diff --git a/src/httpserver/http_request.hpp b/src/httpserver/http_request.hpp index 8b39118c..d702f35f 100644 --- a/src/httpserver/http_request.hpp +++ b/src/httpserver/http_request.hpp @@ -509,7 +509,7 @@ class http_request * Method used to set the requestor port * @param requestor The requestor port to set **/ - void set_requestor_port(short requestor) + void set_requestor_port(short requestor_port) { this->requestor_port = requestor_port; } diff --git a/src/httpserver/webserver.hpp b/src/httpserver/webserver.hpp index 22471e91..6b7ed075 100644 --- a/src/httpserver/webserver.hpp +++ b/src/httpserver/webserver.hpp @@ -60,11 +60,11 @@ struct httpserver_ska; }; namespace details { + class http_endpoint; class http_resource_mirror; class event_tuple; - class http_endpoint; - class daemon_item; - class modded_request; + struct daemon_item; + struct modded_request; struct cache_entry; } From 7ad50093eb7dcd9f3b68ecf982c5f7b41e9a2ef9 Mon Sep 17 00:00:00 2001 From: waTeim Date: Thu, 13 Feb 2014 15:56:02 -0500 Subject: [PATCH 2/4] Modified .gitignore to include files generated by build --- .gitignore | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/.gitignore b/.gitignore index bc2d7218..84d7079a 100644 --- a/.gitignore +++ b/.gitignore @@ -32,3 +32,40 @@ test/Test test/core test/err test/test.txt +Makefile +compile +config.h +config.log +config.status +debian/changelog +debian/control +debian/copyright +debian/libhttpserver-dev.install +debian/libhttpserver.install +debian/rules +libhttpserver.pc +libtool +redhat/libhttpserver.SPEC +src/.deps/ +src/.libs/ +src/Makefile +src/http_endpoint.lo +src/http_endpoint.o +src/http_request.lo +src/http_request.o +src/http_resource.lo +src/http_resource.o +src/http_response.lo +src/http_response.o +src/http_utils.lo +src/http_utils.o +src/libhttpserver.la +src/string_utilities.lo +src/string_utilities.o +src/webserver.lo +src/webserver.o +stamp-h1 +test-driver +test/.deps/ +test/Makefile + From da21676f627896b26bcb9e5e518d4a96bcb0b59d Mon Sep 17 00:00:00 2001 From: waTeim Date: Mon, 17 Feb 2014 14:48:00 -0500 Subject: [PATCH 3/4] Change getter to const --- src/http_response.cpp | 2 +- src/httpserver/http_response.hpp | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/http_response.cpp b/src/http_response.cpp index 87a7e911..c8179253 100644 --- a/src/http_response.cpp +++ b/src/http_response.cpp @@ -42,7 +42,7 @@ http_response::~http_response() webserver::unlock_cache_entry(ce); } -size_t http_response::get_headers(std::map& result) +size_t http_response::get_headers(std::map& result) const { result = this->headers; return result.size(); diff --git a/src/httpserver/http_response.hpp b/src/httpserver/http_response.hpp index 05790b39..2f4114e1 100644 --- a/src/httpserver/http_response.hpp +++ b/src/httpserver/http_response.hpp @@ -322,9 +322,7 @@ class http_response * Method used to get all headers passed with the request. * @return a map containing all headers. **/ - size_t get_headers( - std::map& result - ); + size_t get_headers(std::map& result) const; /** * Method used to get all footers passed with the request. * @return a map containing all footers. From 4d20b56236208b837e59b1f589ad30d4f22068d3 Mon Sep 17 00:00:00 2001 From: waTeim Date: Mon, 17 Feb 2014 19:30:33 -0500 Subject: [PATCH 4/4] Fixed problem on OS/X; SOCK_CLOEXEC raises EPROTONOSUPPORT instead of EINVAL. --- src/webserver.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/webserver.cpp b/src/webserver.cpp index 2e5f7fcc..8f8edd6c 100644 --- a/src/webserver.cpp +++ b/src/webserver.cpp @@ -376,7 +376,7 @@ int create_socket (int domain, int type, int protocol) /* use SOCK_STREAM rather than ai_socktype: some getaddrinfo * implementations do not set ai_socktype, e.g. RHL6.2. */ fd = socket(domain, ctype, protocol); - if ( (-1 == fd) && (EINVAL == errno) && (0 != sock_cloexec) ) + if ( (fd == -1) && (errno == EINVAL || errno == EPROTONOSUPPORT) && (sock_cloexec != 0) ) { sock_cloexec = 0; fd = socket(domain, type, protocol); @@ -512,6 +512,12 @@ bool webserver::start(bool blocking) else bind_socket = create_socket (PF_INET, SOCK_STREAM, 0); + if(bind_socket == -1) + { + perror("Unable to create socket"); + abort(); + } + setsockopt (bind_socket, SOL_SOCKET, SO_REUSEADDR, @@ -528,7 +534,11 @@ bool webserver::start(bool blocking) #endif #endif } - bind(bind_socket, servaddr, addrlen); + if(bind(bind_socket, servaddr, addrlen) == -1) + { + perror("Unable to bind specified server address"); + abort(); + } } int flags = fcntl (bind_socket, F_GETFL); flags |= O_NONBLOCK;