| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent b2d69d9 commit 6b1e195
14 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -64,17 +64,17 @@ NETWORK_LIBS="" | |||
| 64 | 64 | case "$host" in | |
| 65 | 65 | *-mingw*) | |
| 66 | 66 | NETWORK_HEADER="winsock2.h" | |
| 67 | - REGEX_LIBS="-lregex -lpthread -no-undefined" | ||
| 67 | + ADDITIONAL_LIBS="-lpthread -no-undefined" | ||
| 68 | 68 | NETWORK_LIBS="-lws2_32" | |
| 69 | 69 | native_srcdir=$(cd $srcdir; pwd -W) | |
| 70 | 70 | ;; | |
| 71 | 71 | *-cygwin*) | |
| 72 | - NETWORK_HEADER="winsock2.h" | ||
| 73 | - REGEX_LIBS="-lregex -lpthread -no-undefined" | ||
| 72 | + NETWORK_HEADER="arpa/inet.h" | ||
| 73 | + ADDITIONAL_LIBS="-lpthread -no-undefined" | ||
| 74 | 74 | ;; | |
| 75 | 75 | *) | |
| 76 | 76 | NETWORK_HEADER="arpa/inet.h" | |
| 77 | - REGEX_LIBS="" | ||
| 77 | + ADDITIONAL_LIBS="" | ||
| 78 | 78 | is_windows=no | |
| 79 | 79 | ;; | |
| 80 | 80 | esac | |
@@ -86,7 +86,6 @@ AC_CHECK_HEADER([inttypes.h],[],[AC_MSG_ERROR("inttypes.h not found")]) | |||
| 86 | 86 | AC_CHECK_HEADER([errno.h],[],[AC_MSG_ERROR("errno.h not found")]) | |
| 87 | 87 | AC_CHECK_HEADER([unistd.h],[],[AC_MSG_ERROR("unistd.h not found")]) | |
| 88 | 88 | AC_CHECK_HEADER([ctype.h],[],[AC_MSG_ERROR("cctype not found")]) | |
| 89 | - AC_CHECK_HEADER([regex.h],[],[AC_MSG_ERROR("regex.h not found")]) | ||
| 90 | 89 | AC_CHECK_HEADER([sys/stat.h],[],[AC_MSG_ERROR("sys/stat.h not found")]) | |
| 91 | 90 | AC_CHECK_HEADER([sys/types.h],[],[AC_MSG_ERROR("sys/types.h not found")]) | |
| 92 | 91 | AC_CHECK_HEADER([$NETWORK_HEADER],[],[AC_MSG_ERROR("$NETWORK_HEADER not found")]) | |
@@ -117,7 +116,7 @@ if test x"$host" = x"$build"; then | |||
| 117 | 116 | ) | |
| 118 | 117 | ||
| 119 | 118 | CXXFLAGS="-std=c++11 -DHTTPSERVER_COMPILATION -D_REENTRANT $LIBMICROHTTPD_CFLAGS $CXXFLAGS" | |
| 120 | - LDFLAGS="$LIBMICROHTTPD_LIBS $NETWORK_LIBS $REGEX_LIBS $LDFLAGS" | ||
| 119 | + LDFLAGS="$LIBMICROHTTPD_LIBS $NETWORK_LIBS $ADDITIONAL_LIBS $LDFLAGS" | ||
| 121 | 120 | ||
| 122 | 121 | cond_cross_compile="no" | |
| 123 | 122 | else | |
@@ -130,7 +129,7 @@ else | |||
| 130 | 129 | ) | |
| 131 | 130 | ||
| 132 | 131 | CXXFLAGS="-std=c++11 -DHTTPSERVER_COMPILATION -D_REENTRANT $CXXFLAGS" | |
| 133 | - LDFLAGS="$NETWORK_LIBS $REGEX_LIBS $LDFLAGS" | ||
| 132 | + LDFLAGS="$NETWORK_LIBS $ADDITIONAL_LIBS $LDFLAGS" | ||
| 134 | 133 | ||
| 135 | 134 | cond_cross_compile="yes" | |
| 136 | 135 | fi | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -35,10 +35,6 @@ using namespace http; | |||
| 35 | 35 | ||
| 36 | 36 | http_endpoint::~http_endpoint() | |
| 37 | 37 | { | |
| 38 | - if(reg_compiled) | ||
| 39 | - { | ||
| 40 | - regfree(&re_url_normalized); | ||
| 41 | - } | ||
| 42 | 38 | } | |
| 43 | 39 | ||
| 44 | 40 | http_endpoint::http_endpoint | |
@@ -119,9 +115,7 @@ http_endpoint::http_endpoint | |||
| 119 | 115 | if(use_regex) | |
| 120 | 116 | { | |
| 121 | 117 | url_normalized += "$"; | |
| 122 | - regcomp(&re_url_normalized, url_normalized.c_str(), | ||
| 123 | - REG_EXTENDED|REG_ICASE|REG_NOSUB | ||
| 124 | - ); | ||
| 118 | + re_url_normalized = std::regex(url_normalized, std::regex::extended | std::regex::icase | std::regex::nosubs); | ||
| 125 | 119 | reg_compiled = true; | |
| 126 | 120 | } | |
| 127 | 121 | } | |
@@ -133,12 +127,9 @@ http_endpoint::http_endpoint(const http_endpoint& h): | |||
| 133 | 127 | url_pieces(h.url_pieces), | |
| 134 | 128 | chunk_positions(h.chunk_positions), | |
| 135 | 129 | family_url(h.family_url), | |
| 136 | - reg_compiled(h.reg_compiled) | ||
| 130 | + reg_compiled(h.reg_compiled), | ||
| 131 | + re_url_normalized(h.re_url_normalized) | ||
| 137 | 132 | { | |
| 138 | - if(reg_compiled) | ||
| 139 | - regcomp(&re_url_normalized, url_normalized.c_str(), | ||
| 140 | - REG_EXTENDED|REG_ICASE|REG_NOSUB | ||
| 141 | - ); | ||
| 142 | 133 | } | |
| 143 | 134 | ||
| 144 | 135 | http_endpoint& http_endpoint::operator =(const http_endpoint& h) | |
@@ -147,14 +138,7 @@ http_endpoint& http_endpoint::operator =(const http_endpoint& h) | |||
| 147 | 138 | url_normalized = h.url_normalized; | |
| 148 | 139 | family_url = h.family_url; | |
| 149 | 140 | reg_compiled = h.reg_compiled; | |
| 150 | - if(reg_compiled) | ||
| 151 | - { | ||
| 152 | - regfree(&re_url_normalized); | ||
| 153 | - | ||
| 154 | - regcomp(&re_url_normalized, url_normalized.c_str(), | ||
| 155 | - REG_EXTENDED|REG_ICASE|REG_NOSUB | ||
| 156 | - ); | ||
| 157 | - } | ||
| 141 | + re_url_normalized = h.re_url_normalized; | ||
| 158 | 142 | url_pars = h.url_pars; | |
| 159 | 143 | url_pieces = h.url_pieces; | |
| 160 | 144 | chunk_positions = h.chunk_positions; | |
@@ -171,7 +155,9 @@ bool http_endpoint::match(const http_endpoint& url) const | |||
| 171 | 155 | if (!reg_compiled) throw std::invalid_argument("Cannot run match. Regex suppressed."); | |
| 172 | 156 | ||
| 173 | 157 | if(!family_url || url.url_pieces.size() < url_pieces.size()) | |
| 174 | - return regexec(&re_url_normalized, url.url_complete.c_str(), 0, NULL, 0) == 0; | ||
| 158 | + { | ||
| 159 | + return regex_match(url.url_complete, re_url_normalized); | ||
| 160 | + } | ||
| 175 | 161 | ||
| 176 | 162 | string nn = "/"; | |
| 177 | 163 | bool first = true; | |
@@ -180,7 +166,7 @@ bool http_endpoint::match(const http_endpoint& url) const | |||
| 180 | 166 | nn += (first ? "" : "/") + url.url_pieces[i]; | |
| 181 | 167 | first = false; | |
| 182 | 168 | } | |
| 183 | - return regexec(&re_url_normalized, nn.c_str(), 0, NULL, 0) == 0; | ||
| 169 | + return regex_match(nn, re_url_normalized); | ||
| 184 | 170 | } | |
| 185 | 171 | ||
| 186 | 172 | }; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -20,17 +20,19 @@ | |||
| 20 | 20 | ||
| 21 | 21 | #include "httpserver/http_utils.hpp" | |
| 22 | 22 | ||
| 23 | - #if defined(__MINGW32__) || defined(__CYGWIN32__) | ||
| 23 | + #if defined(_WIN32) && ! defined(__CYGWIN__) | ||
| 24 | 24 | #include <winsock2.h> | |
| 25 | 25 | #include <ws2tcpip.h> | |
| 26 | - #else | ||
| 26 | + #else // WIN32 check | ||
| 27 | 27 | #if defined(__FreeBSD__) | |
| 28 | 28 | #include <netinet/in.h> | |
| 29 | - #endif | ||
| 30 | - #include <sys/socket.h> | ||
| 31 | - #include <netdb.h> | ||
| 29 | + #endif // FreeBSD | ||
| 32 | 30 | #include <arpa/inet.h> | |
| 33 | - #endif | ||
| 31 | + #include <netdb.h> | ||
| 32 | + #include <netinet/in.h> | ||
| 33 | + #include <sys/socket.h> | ||
| 34 | + #include <sys/types.h> | ||
| 35 | + #endif // WIN32 check | ||
| 34 | 36 | ||
| 35 | 37 | #include <stdio.h> | |
| 36 | 38 | #include <stdlib.h> | |
@@ -40,6 +42,7 @@ | |||
| 40 | 42 | #include <iostream> | |
| 41 | 43 | #include <sstream> | |
| 42 | 44 | #include <stdexcept> | |
| 45 | + #include <utility> | ||
| 43 | 46 | ||
| 44 | 47 | #include "httpserver/string_utilities.hpp" | |
| 45 | 48 | ||
@@ -48,6 +51,19 @@ | |||
| 48 | 51 | #define SET_BIT(var,pos) ((var) |= 1 << (pos)) | |
| 49 | 52 | #define CLEAR_BIT(var,pos) ((var) &= ~(1<<(pos))) | |
| 50 | 53 | ||
| 54 | + #if defined (__CYGWIN__) | ||
| 55 | + | ||
| 56 | + #if ! defined (NI_MAXHOST) | ||
| 57 | + #define NI_MAXHOST 1025 | ||
| 58 | + #endif // NI_MAXHOST | ||
| 59 | + | ||
| 60 | + #ifndef __u_char_defined | ||
| 61 | + typedef unsigned char u_char; | ||
| 62 | + #define __u_char_defined | ||
| 63 | + #endif // __u_char_defined | ||
| 64 | + | ||
| 65 | + #endif // CYGWIN | ||
| 66 | + | ||
| 51 | 67 | using namespace std; | |
| 52 | 68 | ||
| 53 | 69 | namespace httpserver { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -25,7 +25,7 @@ | |||
| 25 | 25 | #ifndef _HTTP_ENDPOINT_HPP_ | |
| 26 | 26 | #define _HTTP_ENDPOINT_HPP_ | |
| 27 | 27 | ||
| 28 | - #include <regex.h> | ||
| 28 | + #include <regex> | ||
| 29 | 29 | #include <stdexcept> | |
| 30 | 30 | #include <string> | |
| 31 | 31 | #include <utility> | |
@@ -136,6 +136,7 @@ class http_endpoint | |||
| 136 | 136 | http_endpoint(): | |
| 137 | 137 | url_complete("/"), | |
| 138 | 138 | url_normalized("/"), | |
| 139 | + re_url_normalized(std::regex("")), // initialize empty | ||
| 139 | 140 | family_url(false), | |
| 140 | 141 | reg_compiled(false) | |
| 141 | 142 | { | |
@@ -186,7 +187,7 @@ class http_endpoint | |||
| 186 | 187 | /** | |
| 187 | 188 | * Regex used in comparisons | |
| 188 | 189 | **/ | |
| 189 | - regex_t re_url_normalized; | ||
| 190 | + std::regex re_url_normalized; | ||
| 190 | 191 | ||
| 191 | 192 | /** | |
| 192 | 193 | * Boolean indicating wheter the endpoint represents a family | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -37,6 +37,11 @@ | |||
| 37 | 37 | #define _WIN32_WINNT 0x600 | |
| 38 | 38 | #endif | |
| 39 | 39 | ||
| 40 | + // needed to have the fd_set definition ahead of microhttpd.h import | ||
| 41 | + #if defined(__CYGWIN__) | ||
| 42 | + #include <sys/select.h> | ||
| 43 | + #endif | ||
| 44 | + | ||
| 40 | 45 | #include <microhttpd.h> | |
| 41 | 46 | #include <algorithm> | |
| 42 | 47 | #include <cctype> | |
@@ -72,7 +77,7 @@ class http_utils | |||
| 72 | 77 | ||
| 73 | 78 | enum start_method_T | |
| 74 | 79 | { | |
| 75 | - #if defined(__MINGW32__) || defined(__CYGWIN32__) | ||
| 80 | + #if defined(__MINGW32__) || defined(__CYGWIN__) | ||
| 76 | 81 | #ifdef ENABLE_POLL | |
| 77 | 82 | INTERNAL_SELECT = MHD_USE_SELECT_INTERNALLY | MHD_USE_POLL, | |
| 78 | 83 | #else | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -44,9 +44,6 @@ const std::string to_lower_copy(const std::string& str); | |||
| 44 | 44 | const std::vector<std::string> string_split(const std::string& s, | |
| 45 | 45 | char sep = ' ', bool collapse = true | |
| 46 | 46 | ); | |
| 47 | - const std::string regex_replace(const std::string& str, const std::string& pattern, | ||
| 48 | - const std::string& replace_str | ||
| 49 | - ); | ||
| 50 | 47 | void to_upper(std::string& str); | |
| 51 | 48 | }; | |
| 52 | 49 | }; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -174,7 +174,6 @@ class webserver | |||
| 174 | 174 | bool single_resource; | |
| 175 | 175 | bool tcp_nodelay; | |
| 176 | 176 | pthread_mutex_t mutexwait; | |
| 177 | - pthread_rwlock_t runguard; | ||
| 178 | 177 | pthread_cond_t mutexcond; | |
| 179 | 178 | render_ptr not_found_resource; | |
| 180 | 179 | render_ptr method_not_allowed_resource; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -20,7 +20,6 @@ | |||
| 20 | 20 | ||
| 21 | 21 | #include "httpserver/string_utilities.hpp" | |
| 22 | 22 | ||
| 23 | - #include <regex.h> | ||
| 24 | 23 | #include <algorithm> | |
| 25 | 24 | #include <cctype> | |
| 26 | 25 | #include <cstdlib> | |
@@ -85,43 +84,5 @@ const std::vector<std::string> string_split( | |||
| 85 | 84 | return result; | |
| 86 | 85 | } | |
| 87 | 86 | ||
| 88 | - const std::string regex_replace(const std::string& str, | ||
| 89 | - const std::string& pattern, | ||
| 90 | - const std::string& replace_str | ||
| 91 | - ) | ||
| 92 | - { | ||
| 93 | - regex_t preg; | ||
| 94 | - regmatch_t substmatch[1]; | ||
| 95 | - regcomp(&preg, pattern.c_str(), REG_EXTENDED|REG_ICASE); | ||
| 96 | - std::string result; | ||
| 97 | - if ( regexec(&preg, str.c_str(), 1, substmatch, 0) == 0 ) | ||
| 98 | - { | ||
| 99 | - char ns[substmatch[0].rm_so + 1 + | ||
| 100 | - replace_str.size() + (str.size() - substmatch[0].rm_eo) + 2 | ||
| 101 | - ]; | ||
| 102 | - | ||
| 103 | - memcpy(ns, str.c_str(), substmatch[0].rm_so+1); | ||
| 104 | - | ||
| 105 | - memcpy(&ns[substmatch[0].rm_so], | ||
| 106 | - replace_str.c_str(), | ||
| 107 | - replace_str.size() | ||
| 108 | - ); | ||
| 109 | - | ||
| 110 | - memcpy(&ns[substmatch[0].rm_so+replace_str.size()], | ||
| 111 | - &str[substmatch[0].rm_eo], str.substr(substmatch[0].rm_eo).size() | ||
| 112 | - ); | ||
| 113 | - | ||
| 114 | - ns[substmatch[0].rm_so + | ||
| 115 | - replace_str.size() + | ||
| 116 | - str.substr(substmatch[0].rm_eo).size() | ||
| 117 | - ] = 0; | ||
| 118 | - | ||
| 119 | - result = std::string((char*)ns); | ||
| 120 | - } | ||
| 121 | - regfree(&preg); | ||
| 122 | - | ||
| 123 | - return result; | ||
| 124 | - } | ||
| 125 | - | ||
| 126 | 87 | }; | |
| 127 | 88 | }; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -20,14 +20,17 @@ | |||
| 20 | 20 | ||
| 21 | 21 | #include "httpserver/webserver.hpp" | |
| 22 | 22 | ||
| 23 | - #if defined(__MINGW32__) || defined(__CYGWIN32__) | ||
| 23 | + #if defined(_WIN32) && ! defined(__CYGWIN__) | ||
| 24 | 24 | #include <winsock2.h> | |
| 25 | 25 | #include <ws2tcpip.h> | |
| 26 | 26 | #define _WINDOWS | |
| 27 | 27 | #else | |
| 28 | 28 | #if defined(__FreeBSD__) | |
| 29 | 29 | #include <netinet/in.h> | |
| 30 | 30 | #endif | |
| 31 | + #if defined(__CYGWIN__) | ||
| 32 | + #include <sys/select.h> | ||
| 33 | + #endif | ||
| 31 | 34 | #include <netinet/ip.h> | |
| 32 | 35 | #include <netinet/tcp.h> | |
| 33 | 36 | #endif | |
@@ -47,6 +50,13 @@ | |||
| 47 | 50 | #include <unistd.h> | |
| 48 | 51 | #include <algorithm> | |
| 49 | 52 | #include <iostream> | |
| 53 | + #include <strings.h> | ||
| 54 | + #include <cstring> | ||
| 55 | + #include <exception> | ||
| 56 | + #include <memory> | ||
| 57 | + #include <stdexcept> | ||
| 58 | + #include <utility> | ||
| 59 | + #include <vector> | ||
| 50 | 60 | ||
| 51 | 61 | #include "gettext.h" | |
| 52 | 62 | #include "httpserver/create_webserver.hpp" | |
@@ -88,7 +98,7 @@ struct compare_value | |||
| 88 | 98 | } | |
| 89 | 99 | }; | |
| 90 | 100 | ||
| 91 | - #ifndef __MINGW32__ | ||
| 101 | + #if !defined(_WIN32) && !defined(__MINGW32__) && !defined(__CYGWIN__) | ||
| 92 | 102 | static void catcher (int sig) | |
| 93 | 103 | { | |
| 94 | 104 | } | |
@@ -97,7 +107,7 @@ static void catcher (int sig) | |||
| 97 | 107 | static void ignore_sigpipe () | |
| 98 | 108 | { | |
| 99 | 109 | //Mingw doesn't implement SIGPIPE | |
| 100 | - #ifndef __MINGW32__ | ||
| 110 | + #if !defined(_WIN32) && !defined(__MINGW32__) && !defined(__CYGWIN__) | ||
| 101 | 111 | struct sigaction oldsig; | |
| 102 | 112 | struct sigaction sig; | |
| 103 | 113 | ||
@@ -160,15 +170,13 @@ webserver::webserver(const create_webserver& params): | |||
| 160 | 170 | { | |
| 161 | 171 | ignore_sigpipe(); | |
| 162 | 172 | pthread_mutex_init(&mutexwait, NULL); | |
| 163 | - pthread_rwlock_init(&runguard, NULL); | ||
| 164 | 173 | pthread_cond_init(&mutexcond, NULL); | |
| 165 | 174 | } | |
| 166 | 175 | ||
| 167 | 176 | webserver::~webserver() | |
| 168 | 177 | { | |
| 169 | 178 | stop(); | |
| 170 | 179 | pthread_mutex_destroy(&mutexwait); | |
| 171 | - pthread_rwlock_destroy(&runguard); | ||
| 172 | 180 | pthread_cond_destroy(&mutexcond); | |
| 173 | 181 | } | |
| 174 | 182 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -18,7 +18,7 @@ | |||
| 18 | 18 | USA | |
| 19 | 19 | */ | |
| 20 | 20 | ||
| 21 | - #if defined(__MINGW32__) || defined(__CYGWIN32__) | ||
| 21 | + #if defined(_WIN32) && ! defined(__CYGWIN__) | ||
| 22 | 22 | #define _WINDOWS | |
| 23 | 23 | #undef _WIN32_WINNT | |
| 24 | 24 | #define _WIN32_WINNT 0x600 | |
| Back | FazBrowse Home | New Git URL |
0 commit comments