| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 0cf71bf commit a3fb0ec
10 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -53,6 +53,21 @@ if test x"$samedirectory" = x"no"; then | |||
| 53 | 53 | fi | |
| 54 | 54 | fi | |
| 55 | 55 | ||
| 56 | + case "$host" in | ||
| 57 | + *-mingw*) | ||
| 58 | + NETWORK_HEADER="winsock2.h" | ||
| 59 | + REGEX_LIBS="-lregex -no-undefined" | ||
| 60 | + ;; | ||
| 61 | + *-cygwin*) | ||
| 62 | + NETWORK_HEADER="winsock2.h" | ||
| 63 | + REGEX_LIBS="-lregex -no-undefined" | ||
| 64 | + ;; | ||
| 65 | + *) | ||
| 66 | + NETWORK_HEADER="arpa/inet.h" | ||
| 67 | + REGEX_LIBS="" | ||
| 68 | + ;; | ||
| 69 | + esac | ||
| 70 | + | ||
| 56 | 71 | # Checks for header files. | |
| 57 | 72 | AC_HEADER_STDC | |
| 58 | 73 | AC_CHECK_HEADER([string],[],[AC_MSG_ERROR("C++ strings not found")]) | |
@@ -73,7 +88,7 @@ AC_CHECK_HEADER([ctype.h],[],[AC_MSG_ERROR("cctype not found")]) | |||
| 73 | 88 | AC_CHECK_HEADER([regex.h],[],[AC_MSG_ERROR("regex.h not found")]) | |
| 74 | 89 | AC_CHECK_HEADER([sys/stat.h],[],[AC_MSG_ERROR("sys/stat.h not found")]) | |
| 75 | 90 | AC_CHECK_HEADER([sys/types.h],[],[AC_MSG_ERROR("sys/types.h not found")]) | |
| 76 | - AC_CHECK_HEADER([arpa/inet.h],[],[AC_MSG_ERROR("arpa/inet.h not found")]) | ||
| 91 | + AC_CHECK_HEADER([$NETWORK_HEADER],[],[AC_MSG_ERROR("$NETWORK_HEADER not found")]) | ||
| 77 | 92 | AC_CHECK_HEADER([signal.h],[],[AC_MSG_ERROR("signal.h not found")]) | |
| 78 | 93 | ||
| 79 | 94 | AC_CHECK_HEADER([gnutls/gnutls.h],[have_gnutls="yes"],[AC_MSG_WARN("gnutls/gnutls.h not found. TLS will be disabled"); have_gnutls="no"]) | |
@@ -84,7 +99,7 @@ PKG_CHECK_MODULES([LIBMICROHTTPD],[libmicrohttpd >= 0.9.7],[],[AC_MSG_ERROR("lib | |||
| 84 | 99 | #AC_CHECK_LIB([microhttpd],[MHD_start_daemon],[],[AC_MSG_ERROR("Microhttpd header files not found. Please use a version >= 0.9.9.")]) | |
| 85 | 100 | ||
| 86 | 101 | CXXFLAGS="-DHTTPSERVER_COMPILATION -D_REENTRANT $LIBMICROHTTPD_CFLAGS $CXXFLAGS" | |
| 87 | - LDFLAGS="$LIBMICROHTTPD_LIBS $LD_FLAGS" | ||
| 102 | + LDFLAGS="$LIBMICROHTTPD_LIBS $REGEX_LIBS $LD_FLAGS" | ||
| 88 | 103 | ||
| 89 | 104 | m4_pattern_allow([AC_TYPE_SIZE_T]) | |
| 90 | 105 | m4_pattern_allow([AC_TYPE_UINT16_T]) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -26,7 +26,7 @@ AM_CXXFLAGS += -fPIC -Wall | |||
| 26 | 26 | libhttpserver_la_LIBADD = -lmicrohttpd | |
| 27 | 27 | libhttpserver_la_LDFLAGS = | |
| 28 | 28 | ||
| 29 | - install-exec-hook: | ||
| 29 | + install-data-hook: | ||
| 30 | 30 | (mkdir -p $(DESTDIR)$(includedir) && cd $(DESTDIR)$(includedir) && $(LN_S) -f httpserver.hpp httpserverpp) | |
| 31 | 31 | ||
| 32 | 32 | uninstall-hook: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -21,6 +21,7 @@ | |||
| 21 | 21 | #include <errno.h> | |
| 22 | 22 | #include <iostream> | |
| 23 | 23 | #include "details/comet_manager.hpp" | |
| 24 | + #include <sys/time.h> | ||
| 24 | 25 | ||
| 25 | 26 | using namespace std; | |
| 26 | 27 | ||
@@ -140,7 +141,7 @@ size_t comet_manager::get_topic_consumers( | |||
| 140 | 141 | { | |
| 141 | 142 | consumers.insert((*it)); | |
| 142 | 143 | } | |
| 143 | - int size = consumers.size(); | ||
| 144 | + std::set<httpserver::http::httpserver_ska>::size_type size = consumers.size(); | ||
| 144 | 145 | pthread_rwlock_unlock(&comet_guard); | |
| 145 | 146 | return size; | |
| 146 | 147 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -99,8 +99,8 @@ http_endpoint::http_endpoint | |||
| 99 | 99 | (parts[i][parts[i].size() - 1] == '}') | |
| 100 | 100 | ) | |
| 101 | 101 | { | |
| 102 | - int bar = parts[i].find_first_of('|'); | ||
| 103 | - if(bar != (int)string::npos) | ||
| 102 | + std::string::size_type bar = parts[i].find_first_of('|'); | ||
| 103 | + if(bar != string::npos) | ||
| 104 | 104 | { | |
| 105 | 105 | this->url_pars.push_back(parts[i].substr(1, bar - 1)); | |
| 106 | 106 | if(first) | |
@@ -201,7 +201,7 @@ http_endpoint& http_endpoint::operator =(const http_endpoint& h) | |||
| 201 | 201 | ||
| 202 | 202 | bool http_endpoint::operator <(const http_endpoint& b) const | |
| 203 | 203 | { | |
| 204 | - COMPARATOR(this->url_modded, b.url_modded, toupper); | ||
| 204 | + COMPARATOR(this->url_modded, b.url_modded, std::toupper); | ||
| 205 | 205 | } | |
| 206 | 206 | ||
| 207 | 207 | bool http_endpoint::match(const http_endpoint& url) const | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -207,7 +207,7 @@ namespace details | |||
| 207 | 207 | ||
| 208 | 208 | ssize_t cb(void* cls, uint64_t pos, char* buf, size_t max) | |
| 209 | 209 | { | |
| 210 | - int val = static_cast<http_response*>(cls)->cycle_callback(buf); | ||
| 210 | + ssize_t val = static_cast<http_response*>(cls)->cycle_callback(buf); | ||
| 211 | 211 | if(val == -1) | |
| 212 | 212 | static_cast<http_response*>(cls)->completed = true; | |
| 213 | 213 | return val; | |
@@ -272,7 +272,7 @@ ssize_t http_response::data_generator( | |||
| 272 | 272 | if(_this->ws->pop_signaled(_this->connection_id)) | |
| 273 | 273 | { | |
| 274 | 274 | string message; | |
| 275 | - int size = _this->ws->read_message(_this->connection_id, message); | ||
| 275 | + size_t size = _this->ws->read_message(_this->connection_id, message); | ||
| 276 | 276 | memcpy(buf, message.c_str(), size); | |
| 277 | 277 | return size; | |
| 278 | 278 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -21,7 +21,15 @@ | |||
| 21 | 21 | #include <stdio.h> | |
| 22 | 22 | #include <stdlib.h> | |
| 23 | 23 | #include <string.h> | |
| 24 | + #if defined(__MINGW32__) || defined(__CYGWIN32__) | ||
| 25 | + #define _WINDOWS | ||
| 26 | + #undef _WIN32_WINNT | ||
| 27 | + #define _WIN32_WINNT 0x600 | ||
| 28 | + #include <winsock2.h> | ||
| 29 | + #include <ws2tcpip.h> | ||
| 30 | + #else | ||
| 24 | 31 | #include <arpa/inet.h> | |
| 32 | + #endif | ||
| 25 | 33 | #include <sstream> | |
| 26 | 34 | #include <iomanip> | |
| 27 | 35 | #include <fstream> | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -85,7 +85,7 @@ class create_webserver | |||
| 85 | 85 | { | |
| 86 | 86 | } | |
| 87 | 87 | ||
| 88 | - explicit create_webserver(int port): | ||
| 88 | + explicit create_webserver(uint16_t port): | ||
| 89 | 89 | _port(port), | |
| 90 | 90 | _start_method(http::http_utils::INTERNAL_SELECT), | |
| 91 | 91 | _max_threads(0), | |
@@ -125,7 +125,7 @@ class create_webserver | |||
| 125 | 125 | { | |
| 126 | 126 | } | |
| 127 | 127 | ||
| 128 | - create_webserver& port(int port) { _port = port; return *this; } | ||
| 128 | + create_webserver& port(uint16_t port) { _port = port; return *this; } | ||
| 129 | 129 | create_webserver& start_method( | |
| 130 | 130 | const http::http_utils::start_method_T& start_method | |
| 131 | 131 | ) | |
@@ -317,7 +317,7 @@ class create_webserver | |||
| 317 | 317 | } | |
| 318 | 318 | ||
| 319 | 319 | private: | |
| 320 | - int _port; | ||
| 320 | + uint16_t _port; | ||
| 321 | 321 | http::http_utils::start_method_T _start_method; | |
| 322 | 322 | int _max_threads; | |
| 323 | 323 | int _max_connections; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -27,7 +27,7 @@ | |||
| 27 | 27 | ||
| 28 | 28 | #include <microhttpd.h> | |
| 29 | 29 | #include <string> | |
| 30 | - #include <ctype.h> | ||
| 30 | + #include <cctype> | ||
| 31 | 31 | #include <vector> | |
| 32 | 32 | #include <algorithm> | |
| 33 | 33 | #include <exception> | |
@@ -238,8 +238,8 @@ class http_utils | |||
| 238 | 238 | \ | |
| 239 | 239 | for (size_t n = 0; n < l1; n++)\ | |
| 240 | 240 | {\ | |
| 241 | - char xc = op((x)[n]);\ | ||
| 242 | - char yc = op((y)[n]);\ | ||
| 241 | + int xc = op((x)[n]);\ | ||
| 242 | + int yc = op((y)[n]);\ | ||
| 243 | 243 | if (xc < yc) return true;\ | |
| 244 | 244 | if (xc > yc) return false;\ | |
| 245 | 245 | }\ | |
@@ -255,7 +255,7 @@ class header_comparator { | |||
| 255 | 255 | **/ | |
| 256 | 256 | bool operator()(const std::string& x,const std::string& y) const | |
| 257 | 257 | { | |
| 258 | - COMPARATOR(x, y, toupper); | ||
| 258 | + COMPARATOR(x, y, std::toupper); | ||
| 259 | 259 | } | |
| 260 | 260 | }; | |
| 261 | 261 | ||
@@ -274,7 +274,7 @@ class arg_comparator { | |||
| 274 | 274 | bool operator()(const std::string& x,const std::string& y) const | |
| 275 | 275 | { | |
| 276 | 276 | #ifdef CASE_INSENSITIVE | |
| 277 | - COMPARATOR(x, y, toupper); | ||
| 277 | + COMPARATOR(x, y, std::toupper); | ||
| 278 | 278 | #else | |
| 279 | 279 | COMPARATOR(x, y, ); | |
| 280 | 280 | #endif | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -188,7 +188,7 @@ class webserver | |||
| 188 | 188 | webserver& operator=(const webserver& other); | |
| 189 | 189 | ||
| 190 | 190 | private: | |
| 191 | - const int port; | ||
| 191 | + const uint16_t port; | ||
| 192 | 192 | http::http_utils::start_method_T start_method; | |
| 193 | 193 | const int max_threads; | |
| 194 | 194 | const int max_connections; | |
@@ -200,7 +200,9 @@ class webserver | |||
| 200 | 200 | validator_ptr validator; | |
| 201 | 201 | unescaper_ptr unescaper; | |
| 202 | 202 | const struct sockaddr* bind_address; | |
| 203 | - int bind_socket; | ||
| 203 | + /* Changed type to MHD_socket because this type will always reflect the | ||
| 204 | + platform's actual socket type (e.g. SOCKET on windows, int on unixes)*/ | ||
| 205 | + MHD_socket bind_socket; | ||
| 204 | 206 | const int max_thread_stack_size; | |
| 205 | 207 | const bool use_ssl; | |
| 206 | 208 | const bool use_ipv6; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -27,7 +27,15 @@ | |||
| 27 | 27 | #include <unistd.h> | |
| 28 | 28 | #include <sys/stat.h> | |
| 29 | 29 | #include <sys/types.h> | |
| 30 | + #include <sys/time.h> | ||
| 31 | + | ||
| 32 | + #if defined(__MINGW32__) || defined(__CYGWIN32__) | ||
| 33 | + #include <winsock2.h> | ||
| 34 | + #define _WINDOWS | ||
| 35 | + #else | ||
| 30 | 36 | #include <netinet/ip.h> | |
| 37 | + #endif | ||
| 38 | + | ||
| 31 | 39 | #include <signal.h> | |
| 32 | 40 | #include <fcntl.h> | |
| 33 | 41 | #include <algorithm> | |
@@ -115,12 +123,16 @@ struct compare_value | |||
| 115 | 123 | } | |
| 116 | 124 | }; | |
| 117 | 125 | ||
| 126 | + #ifndef __MINGW32__ | ||
| 118 | 127 | static void catcher (int sig) | |
| 119 | 128 | { | |
| 120 | 129 | } | |
| 130 | + #endif | ||
| 121 | 131 | ||
| 122 | 132 | static void ignore_sigpipe () | |
| 123 | 133 | { | |
| 134 | + //Mingw doesn't implement SIGPIPE | ||
| 135 | + #ifndef __MINGW32__ | ||
| 124 | 136 | struct sigaction oldsig; | |
| 125 | 137 | struct sigaction sig; | |
| 126 | 138 | ||
@@ -136,6 +148,7 @@ static void ignore_sigpipe () | |||
| 136 | 148 | gettext("Failed to install SIGPIPE handler: %s\n"), | |
| 137 | 149 | strerror (errno) | |
| 138 | 150 | ); | |
| 151 | + #endif | ||
| 139 | 152 | } | |
| 140 | 153 | ||
| 141 | 154 | //WEBSERVER | |
@@ -259,7 +272,7 @@ void* webserver::select(void* self) | |||
| 259 | 272 | fd_set es; | |
| 260 | 273 | struct timeval timeout_value; | |
| 261 | 274 | details::daemon_item* di = static_cast<details::daemon_item*>(self); | |
| 262 | - int max; | ||
| 275 | + MHD_socket max; | ||
| 263 | 276 | while (di->ws->is_running()) | |
| 264 | 277 | { | |
| 265 | 278 | max = 0; | |
@@ -298,7 +311,7 @@ void* webserver::select(void* self) | |||
| 298 | 311 | int local_max; | |
| 299 | 312 | (*it).second.supply_events(&rs, &ws, &es, &local_max); | |
| 300 | 313 | ||
| 301 | - if(local_max > max) | ||
| 314 | + if((MHD_socket) local_max > max) | ||
| 302 | 315 | max = local_max; | |
| 303 | 316 | ||
| 304 | 317 | struct timeval t = (*it).second.get_timeout(); | |
@@ -321,7 +334,9 @@ void* webserver::select(void* self) | |||
| 321 | 334 | timeout_value.tv_sec = timeout_secs; | |
| 322 | 335 | timeout_value.tv_usec = timeout_microsecs; | |
| 323 | 336 | ||
| 324 | - ::select (max + 1, &rs, &ws, &es, &timeout_value); | ||
| 337 | + /*On unix, MHD_socket will be an int anyway. | ||
| 338 | + On windows, the cast is safe because winsock ignores first argument to select*/ | ||
| 339 | + ::select ((int) max + 1, &rs, &ws, &es, &timeout_value); | ||
| 325 | 340 | MHD_run (di->daemon); | |
| 326 | 341 | ||
| 327 | 342 | //EVENT SUPPLIERS DISPATCHING | |
@@ -338,24 +353,25 @@ void* webserver::select(void* self) | |||
| 338 | 353 | return 0x0; | |
| 339 | 354 | } | |
| 340 | 355 | ||
| 341 | - int create_socket (int domain, int type, int protocol) | ||
| 356 | + MHD_socket create_socket (int domain, int type, int protocol) | ||
| 342 | 357 | { | |
| 343 | 358 | int sock_cloexec = SOCK_CLOEXEC; | |
| 344 | 359 | int ctype = SOCK_STREAM | sock_cloexec; | |
| 345 | - int fd; | ||
| 346 | - | ||
| 347 | - /* use SOCK_STREAM rather than ai_socktype: some getaddrinfo | ||
| 360 | + | ||
| 361 | + /* use SOCK_STREAM rather than ai_socktype: some getaddrinfo | ||
| 348 | 362 | * implementations do not set ai_socktype, e.g. RHL6.2. */ | |
| 349 | - fd = socket(domain, ctype, protocol); | ||
| 363 | + MHD_socket fd = socket(domain, ctype, protocol); | ||
| 364 | + | ||
| 365 | + #ifdef _WINDOWS | ||
| 366 | + if (fd == INVALID_SOCKET) | ||
| 367 | + #else | ||
| 350 | 368 | if ((fd == -1) && | |
| 351 | 369 | (errno == EINVAL || errno == EPROTONOSUPPORT) && (sock_cloexec != 0) | |
| 352 | 370 | ) | |
| 371 | + #endif | ||
| 353 | 372 | { | |
| 354 | - sock_cloexec = 0; | ||
| 355 | 373 | fd = socket(domain, type, protocol); | |
| 356 | 374 | } | |
| 357 | - if (-1 == fd) | ||
| 358 | - return -1; | ||
| 359 | 375 | return fd; | |
| 360 | 376 | } | |
| 361 | 377 | ||
@@ -488,24 +504,29 @@ bool webserver::start(bool blocking) | |||
| 488 | 504 | setsockopt (bind_socket, | |
| 489 | 505 | SOL_SOCKET, | |
| 490 | 506 | SO_REUSEADDR, | |
| 491 | - &on, sizeof (on)); | ||
| 507 | + (const char*) &on, sizeof (on)); | ||
| 492 | 508 | ||
| 493 | 509 | if(use_ipv6) | |
| 494 | 510 | { | |
| 495 | 511 | #ifdef IPPROTO_IPV6 | |
| 496 | 512 | #ifdef IPV6_V6ONLY | |
| 497 | 513 | setsockopt (bind_socket, | |
| 498 | 514 | IPPROTO_IPV6, IPV6_V6ONLY, | |
| 499 | - &on, sizeof (on) | ||
| 515 | + (const char*) &on, sizeof (on) | ||
| 500 | 516 | ); | |
| 501 | 517 | #endif | |
| 502 | 518 | #endif | |
| 503 | 519 | } | |
| 504 | 520 | bind(bind_socket, servaddr, addrlen); | |
| 505 | 521 | } | |
| 522 | + #ifdef _WINDOWS | ||
| 523 | + unsigned long ioarg = 1; | ||
| 524 | + ioctlsocket(bind_socket, FIONBIO, &ioarg); | ||
| 525 | + #else | ||
| 506 | 526 | int flags = fcntl (bind_socket, F_GETFL); | |
| 507 | 527 | flags |= O_NONBLOCK; | |
| 508 | 528 | fcntl (bind_socket, F_SETFL, flags); | |
| 529 | + #endif | ||
| 509 | 530 | if(!bind_settled) | |
| 510 | 531 | listen(bind_socket, 1); | |
| 511 | 532 | iov.push_back(gen(MHD_OPTION_LISTEN_SOCKET, bind_socket)); | |
@@ -730,7 +751,7 @@ int webserver::build_request_args ( | |||
| 730 | 751 | mr->dhr->querystring += string(buf); | |
| 731 | 752 | } | |
| 732 | 753 | } | |
| 733 | - int size = internal_unescaper((void*) mr->ws, value); | ||
| 754 | + size_t size = internal_unescaper((void*) mr->ws, value); | ||
| 734 | 755 | mr->dhr->set_arg(key, string(value, size)); | |
| 735 | 756 | return MHD_YES; | |
| 736 | 757 | } | |
@@ -1046,18 +1067,17 @@ int webserver::finalize_answer( | |||
| 1046 | 1067 | details::http_resource_mirror | |
| 1047 | 1068 | >::iterator it; | |
| 1048 | 1069 | ||
| 1049 | - int len = -1; | ||
| 1050 | - int tot_len = -1; | ||
| 1070 | + size_t len = 0; | ||
| 1071 | + size_t tot_len = 0; | ||
| 1051 | 1072 | for( | |
| 1052 | 1073 | it=registered_resources.begin(); | |
| 1053 | 1074 | it!=registered_resources.end(); | |
| 1054 | 1075 | ++it | |
| 1055 | 1076 | ) | |
| 1056 | 1077 | { | |
| 1057 | - int endpoint_pieces_len = (*it).first.get_url_pieces_num(); | ||
| 1058 | - int endpoint_tot_len = (*it).first.get_url_complete_size(); | ||
| 1059 | - if(tot_len == -1 || | ||
| 1060 | - len == -1 || | ||
| 1078 | + size_t endpoint_pieces_len = (*it).first.get_url_pieces_num(); | ||
| 1079 | + size_t endpoint_tot_len = (*it).first.get_url_complete_size(); | ||
| 1080 | + if(!found || | ||
| 1061 | 1081 | endpoint_pieces_len > len || | |
| 1062 | 1082 | ( | |
| 1063 | 1083 | endpoint_pieces_len == len && | |
@@ -1078,7 +1098,7 @@ int webserver::finalize_answer( | |||
| 1078 | 1098 | { | |
| 1079 | 1099 | vector<string> url_pars; | |
| 1080 | 1100 | ||
| 1081 | - unsigned int pars_size = | ||
| 1101 | + size_t pars_size = | ||
| 1082 | 1102 | found_endpoint->first.get_url_pars(url_pars); | |
| 1083 | 1103 | ||
| 1084 | 1104 | vector<string> url_pieces; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments