diff --git a/.travis.yml b/.travis.yml index fdf6cbd5..58122066 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,33 +1,33 @@ dist: trusty language: cpp -matrix: - include: - - compiler: gcc - addons: - apt: - sources: - - llvm-toolchain-precise-3.7 - - ubuntu-toolchain-r-test - packages: - - g++-5-multilib - - gcc-5-multilib - - - compiler: clang - addons: - apt: - sources: - - llvm-toolchain-precise-3.7 - - ubuntu-toolchain-r-test - packages: - - clang-3.7 +#matrix: +# include: +# - compiler: gcc +# addons: +# apt: +# sources: +# - llvm-toolchain-precise +# - ubuntu-toolchain-r-test +# packages: +# - g++-multilib +# - gcc-multilib +# +# - compiler: clang +# addons: +# apt: +# sources: +# - llvm-toolchain-precise +# - ubuntu-toolchain-r-test +# packages: +# - clang #before_install: # - sudo pip install cpp-coveralls -install: - - if [ "$CXX" = "g++" ]; then export CXX="g++-5" CC="gcc-5"; fi - - if [ "$CXX" = "clang++" ]; then export CXX="clang++-3.7" CC="clang-3.7"; fi +#install: +# - if [ "$CXX" = "g++" ]; then export CXX="g++" CC="gcc"; fi +# - if [ "$CXX" = "clang++" ]; then export CXX="clang++" CC="clang"; fi # - cd ${TRAVIS_BUILD_DIR} # - wget http://ftp.de.debian.org/debian/pool/main/l/lcov/lcov_1.11.orig.tar.gz # - tar xf lcov_1.11.orig.tar.gz diff --git a/examples/WiAuth/rdbgen.cpp b/examples/WiAuth/rdbgen.cpp index cdfa626f..0107cbe7 100644 --- a/examples/WiAuth/rdbgen.cpp +++ b/examples/WiAuth/rdbgen.cpp @@ -148,7 +148,7 @@ public: case 4: // size, capacity { - char buffer[64]; + char buffer[128]; uint32_t sz = x.getCapacity(), jsz = x.getJournalSize(), n = u__snprintf(buffer, sizeof(buffer), U_CONSTANT_TO_PARAM("journal.size() = %.2fM (%u bytes) - %u record(s) - capacity: %.2fM (%u bytes)\n"), diff --git a/examples/simple_client_server/server.cpp b/examples/simple_client_server/server.cpp index ed5b1cc4..3c59fb1b 100644 --- a/examples/simple_client_server/server.cpp +++ b/examples/simple_client_server/server.cpp @@ -46,7 +46,7 @@ protected: if (UClientImage_Base::manageRead() == U_NOTIFIER_DELETE) U_RETURN(U_NOTIFIER_DELETE); - if (U_ClientImage_state == U_PLUGIN_HANDLER_GO_ON) + if (U_ClientImage_state == U_PLUGIN_HANDLER_OK) { # ifndef U_LOG_DISABLE if (UClientImage_Base::logbuf) diff --git a/include/ulib/base/utility.h b/include/ulib/base/utility.h index 73128bfc..8c172dbf 100644 --- a/include/ulib/base/utility.h +++ b/include/ulib/base/utility.h @@ -397,16 +397,18 @@ U_EXPORT bool u_dosmatch_ext(const char* restrict s, uint32_t n1, const char* re /* multiple patterns separated by '|' */ -U_EXPORT bool u_match_with_OR(bPFpcupcud pfn_match, const char* restrict s, uint32_t n1, const char* restrict pattern, uint32_t n2, int flags) __pure; +extern U_EXPORT const char* restrict u_pOR; -static inline bool u_dosmatch_with_OR(const char* restrict s, uint32_t n1, const char* restrict pattern, uint32_t n2, int flags) +U_EXPORT uint32_t u_match_with_OR(bPFpcupcud pfn_match, const char* restrict s, uint32_t n1, const char* restrict pattern, uint32_t n2, int flags) __pure; + +static inline uint32_t u_dosmatch_with_OR(const char* restrict s, uint32_t n1, const char* restrict pattern, uint32_t n2, int flags) { U_INTERNAL_TRACE("u_dosmatch_with_OR(%.*s,%u,%.*s,%u,%d)", U_min(n1,128), s, n1, n2, pattern, n2, flags) return u_match_with_OR(u_dosmatch, s, n1, pattern, n2, flags); } -static inline bool u_dosmatch_ext_with_OR(const char* restrict s, uint32_t n1, const char* restrict pattern, uint32_t n2, int flags) +static inline uint32_t u_dosmatch_ext_with_OR(const char* restrict s, uint32_t n1, const char* restrict pattern, uint32_t n2, int flags) { U_INTERNAL_TRACE("u_dosmatch_ext_with_OR(%.*s,%u,%.*s,%u,%d)", U_min(n1,128), s, n1, n2, pattern, n2, flags) diff --git a/include/ulib/cache.h b/include/ulib/cache.h index 771500d3..6bf471c6 100644 --- a/include/ulib/cache.h +++ b/include/ulib/cache.h @@ -85,9 +85,7 @@ public: // sizeof(uint32_t) <= hsize <= size / sizeof(cache_hash_table_entry) (hsize is a power of 2) - uint32_t hsize = sizeof(uint32_t); - - while (hsize <= (size / sizeof(UCache::cache_hash_table_entry))) hsize <<= 1U; + uint32_t hsize = u_nextPowerOfTwo(size / sizeof(UCache::cache_hash_table_entry)); U_RETURN(hsize); } @@ -194,6 +192,12 @@ protected: { U_TRACE(0, "UCache::hash(%.*S,%u)", keylen, key, keylen) + U_INTERNAL_ASSERT_POINTER(info) + + U_INTERNAL_DUMP("info->hsize = %u", info->hsize) + + U_INTERNAL_ASSERT_MAJOR(info->hsize, 0) + uint32_t keyhash = u_cdb_hash((unsigned char*)key, keylen, -1) * sizeof(uint32_t) % info->hsize; U_RETURN(keyhash); @@ -216,7 +220,7 @@ protected: { U_TRACE(0, "UCache::setHead(%u,%u)", pos, value) - U_INTERNAL_ASSERT_MINOR(pos,info->hsize) + U_INTERNAL_ASSERT_MINOR(pos, info->hsize) U_INTERNAL_ASSERT(value <= (info->size - sizeof(uint32_t))) char* ptr = x + pos; diff --git a/include/ulib/file.h b/include/ulib/file.h index b65a6e90..aaaf9b6c 100644 --- a/include/ulib/file.h +++ b/include/ulib/file.h @@ -145,7 +145,7 @@ public: { U_TRACE_NO_PARAM(0, "UFile::isRoot()") - U_INTERNAL_DUMP("u_cwd = %S", u_cwd) + U_INTERNAL_DUMP("u_cwd = %S", u_cwd) U_INTERNAL_DUMP("path_relativ(%u) = %.*S", path_relativ_len, path_relativ_len, path_relativ) if (path_relativ_len == 1 && diff --git a/include/ulib/internal/chttp.h b/include/ulib/internal/chttp.h index 52472344..26cd337f 100644 --- a/include/ulib/internal/chttp.h +++ b/include/ulib/internal/chttp.h @@ -219,8 +219,7 @@ extern U_EXPORT uclientimage_info u_clientimage_info; #define U_http_method_list u_clientimage_info.http_method_list #define U_http_method_type u_clientimage_info.http_info.method_type -#define U_line_terminator_len u_clientimage_info.flag.c[0] - +#define U_line_terminator_len u_clientimage_info.flag.c[0] #define U_ClientImage_state u_clientimage_info.flag.c[1] #define U_ClientImage_close u_clientimage_info.flag.c[2] #define U_ClientImage_request u_clientimage_info.flag.c[3] @@ -229,18 +228,18 @@ extern U_EXPORT uclientimage_info u_clientimage_info; #define U_ClientImage_parallelization u_clientimage_info.flag.c[6] #define U_ClientImage_advise_for_parallelization u_clientimage_info.flag.c[7] -#define U_http_version u_clientimage_info.http_info.flag[ 0] -#define U_http_method_num u_clientimage_info.http_info.flag[ 1] -#define U_http_host_len u_clientimage_info.http_info.flag[ 2] -#define U_http_host_vlen u_clientimage_info.http_info.flag[ 3] -#define U_http_range_len u_clientimage_info.http_info.flag[ 4] -#define U_http_accept_len u_clientimage_info.http_info.flag[ 5] -#define U_http_uri_offset u_clientimage_info.http_info.flag[ 6] -#define U_http_websocket_len u_clientimage_info.http_info.flag[ 7] -#define U_http2_settings_len u_clientimage_info.http_info.flag[ 8] -#define U_http_ip_client_len u_clientimage_info.http_info.flag[ 9] -#define U_http_content_type_len u_clientimage_info.http_info.flag[10] -#define U_http_accept_language_len u_clientimage_info.http_info.flag[11] +#define U_http_version u_clientimage_info.http_info.flag[ 0] +#define U_http_method_num u_clientimage_info.http_info.flag[ 1] +#define U_http_host_len u_clientimage_info.http_info.flag[ 2] +#define U_http_host_vlen u_clientimage_info.http_info.flag[ 3] +#define U_http_range_len u_clientimage_info.http_info.flag[ 4] +#define U_http_accept_len u_clientimage_info.http_info.flag[ 5] +#define U_http_uri_offset u_clientimage_info.http_info.flag[ 6] +#define U_http_websocket_len u_clientimage_info.http_info.flag[ 7] +#define U_http2_settings_len u_clientimage_info.http_info.flag[ 8] +#define U_http_ip_client_len u_clientimage_info.http_info.flag[ 9] +#define U_http_content_type_len u_clientimage_info.http_info.flag[10] +#define U_http_accept_language_len u_clientimage_info.http_info.flag[11] #define U_http_flag u_clientimage_info.http_info.flag[12] #define U_http_flag_save UHttpClient_Base::u_http_info_save.flag[12] @@ -250,17 +249,15 @@ extern U_EXPORT uclientimage_info u_clientimage_info; #define U_http_len_user3 u_clientimage_info.http_info.flag[15] enum HttpRequestType { - HTTP_IS_SENDFILE = 0x0001, - HTTP_IS_KEEP_ALIVE = 0x0002, - HTTP_IS_DATA_CHUNKED = 0x0004, - HTTP_IS_ACCEPT_GZIP = 0x0008, - HTTP_IS_NOCACHE_FILE = 0x0010, - HTTP_IS_RESPONSE_GZIP = 0x0020, - HTTP_IS_REQUEST_NOSTAT = 0x0040, - HTTP_METHOD_NOT_IMPLEMENTED = 0x0080 + HTTP_IS_KEEP_ALIVE = 0x0001, + HTTP_IS_DATA_CHUNKED = 0x0002, + HTTP_IS_ACCEPT_GZIP = 0x0004, + HTTP_IS_NOCACHE_FILE = 0x0008, + HTTP_IS_RESPONSE_GZIP = 0x0010, + HTTP_IS_REQUEST_NOSTAT = 0x0020, + HTTP_METHOD_NOT_IMPLEMENTED = 0x0040 }; -#define U_http_sendfile ((U_http_flag & HTTP_IS_SENDFILE) != 0) #define U_http_keep_alive ((U_http_flag & HTTP_IS_KEEP_ALIVE) != 0) #define U_http_data_chunked ((U_http_flag & HTTP_IS_DATA_CHUNKED) != 0) #define U_http_is_nocache_file ((U_http_flag & HTTP_IS_NOCACHE_FILE) != 0) diff --git a/include/ulib/net/server/client_image.h b/include/ulib/net/server/client_image.h index aef2bc40..2ab5a4b4 100644 --- a/include/ulib/net/server/client_image.h +++ b/include/ulib/net/server/client_image.h @@ -44,12 +44,13 @@ class UBandWidthThrottling; template class UServer; -#define U_ClientImage_http(obj) (obj)->UClientImage_Base::flag.c[0] -#define U_ClientImage_idle(obj) (obj)->UClientImage_Base::flag.c[1] -#define U_ClientImage_pclose(obj) (obj)->UClientImage_Base::flag.c[2] - #define U_ClientImage_request_is_cached UClientImage_Base::cbuffer[0] +#define U_ClientImage_http(obj) (obj)->UClientImage_Base::flag.c[0] +#define U_ClientImage_idle(obj) (obj)->UClientImage_Base::flag.c[1] +#define U_ClientImage_pclose(obj) (obj)->UClientImage_Base::flag.c[2] +#define U_ClientImage_request_is_from_userver(obj) (obj)->UClientImage_Base::flag.c[3] + class U_EXPORT UClientImage_Base : public UEventFd { public: @@ -69,6 +70,8 @@ public: { U_TRACE_NO_PARAM(0, "UClientImage_Base::isPendingSendfile()") + U_INTERNAL_DUMP("sfd = %d count = %u", sfd, count) + if (count > 0) U_RETURN(true); U_RETURN(false); @@ -146,7 +149,8 @@ public: NO_CACHE = 0x0002, IN_FILE_CACHE = 0x0004, ALREADY_PROCESSED = 0x0008, - FILE_CACHE_PROCESSED = 0x0010 + FILE_CACHE_PROCESSED = 0x0010, + REQUEST_FROM_USERVER = 0x0020 }; static bool isRequestNotFound() @@ -344,7 +348,8 @@ public: static bPF callerHandlerCache; static bPFpc callerIsValidMethod; - static iPF callerHandlerRead, callerHandlerRequest; + static iPF callerHandlerRead; + static vPF callerHandlerRequest; static bPFpcu callerIsValidRequest, callerIsValidRequestExt; // NB: these are for ULib Servlet Page (USP) - USP_PRINTF... @@ -417,6 +422,8 @@ protected: { U_TRACE_NO_PARAM(0, "UClientImage::setPendingSendfile()") + U_INTERNAL_ASSERT_DIFFERS(U_ClientImage_parallelization, U_PARALLELIZATION_CHILD) + count = ncount; prepareForSendfile(); @@ -446,8 +453,8 @@ protected: bool logCertificate(); // append on log the peer certicate of client ("issuer","serial") bool askForClientCertificate(); + static int idx, iovcnt; static struct iovec* piov; - static int csfd, idx, iovcnt; static UTimeVal* chronometer; static uint32_t ncount, nrequest, resto; static long time_between_request, time_run; @@ -459,7 +466,30 @@ protected: static void resetWriteBuffer(); static void saveRequestResponse(); static void manageReadBufferResize(uint32_t n); - static void setSendfile(int _sfd, uint32_t _start, uint32_t _count); + static void setSendfile(int fd, uint32_t start, uint32_t count); + + bool isRequestFromUServer() + { + U_TRACE_NO_PARAM(0, "UClientImage_Base::isRequestFromUServer()") + + if (U_ClientImage_request_is_from_userver(this) != false) U_RETURN(true); + + U_RETURN(false); + } + + void setRequestFromUServer() + { + U_TRACE_NO_PARAM(0, "UClientImage_Base::setRequestFromUServer()") + + U_ClientImage_request_is_from_userver(this) = true; + } + + void resetRequestFromUServer() + { + U_TRACE_NO_PARAM(0, "UClientImage_Base::resetRequestFromUServer()") + + U_ClientImage_request_is_from_userver(this) = true; + } #ifndef U_CACHE_REQUEST_DISABLE static bool isRequestCacheable() __pure; diff --git a/include/ulib/net/server/plugin/mod_skeleton.h b/include/ulib/net/server/plugin/mod_skeleton.h index 7f6e6a4c..a9e3b3ad 100644 --- a/include/ulib/net/server/plugin/mod_skeleton.h +++ b/include/ulib/net/server/plugin/mod_skeleton.h @@ -17,12 +17,13 @@ #include /** - * The plugin interface is an integral part of UServer which provides a flexible way to add specific functionality to UServer. - * Plugins allow you to enhance the functionality of UServer without changing the core of the server. They can be loaded at - * startup time and can change virtually some aspect of the behaviour of the server. + * The plugin interface is an integral part of UServer which provides a flexible way to add specific + * functionality to UServer. Plugins allow you to enhance the functionality of UServer without changing + * the core of the server. They can be loaded at startup time and can change virtually some aspect of + * the behaviour of the server * * UServer has 7 hooks which are used in different states of the execution of the request: - * -------------------------------------------------------------------------------------------- + * ---------------------------------------------------------------------------------------------------- * * Server-wide hooks: * ```````````````````` * 1) handlerConfig: called when the server finished to process its configuration @@ -31,19 +32,18 @@ * 4) handlerFork: called when the server have forked a child * 5) handlerStop: called when the server shut down * - * * Connection-wide hooks: + * * Connection-wide hooks: called in `UClientImage_Base::handlerRead()` * ```````````````````````` * 6) handlerREAD: * 7) handlerRequest: - * called in `UClientImage_Base::handlerRead()` - * -------------------------------------------------------------------------------------------- + * ---------------------------------------------------------------------------------------------------- * * RETURNS: - * U_PLUGIN_HANDLER_GO_ON ok + * U_PLUGIN_HANDLER_OK ok * U_PLUGIN_HANDLER_ERROR error * U_PLUGIN_HANDLER_AGAIN the request is not ready (NONBLOCKING) - * U_PLUGIN_HANDLER_FINISHED the request processing is complete * U_PLUGIN_HANDLER_PROCESSED the request has been processed + * U_PLUGIN_HANDLER_FINISHED the request processing is complete */ class U_EXPORT USkeletonPlugIn : public UServerPlugIn { diff --git a/include/ulib/net/server/server.h b/include/ulib/net/server/server.h index a95d502f..2035aa31 100644 --- a/include/ulib/net/server/server.h +++ b/include/ulib/net/server/server.h @@ -260,8 +260,8 @@ public: // --------------------------------- // Connection-wide hooks // --------------------------------- - static int pluginsHandlerREAD(); - static int pluginsHandlerRequest(); + static int pluginsHandlerREAD(); + static void pluginsHandlerRequest(); // --------------------------------- // SIGHUP hook // --------------------------------- diff --git a/include/ulib/net/server/server_plugin.h b/include/ulib/net/server/server_plugin.h index 1f504bac..dd4e15fb 100644 --- a/include/ulib/net/server/server_plugin.h +++ b/include/ulib/net/server/server_plugin.h @@ -17,41 +17,41 @@ #include /** - * The plugin interface is an integral part of UServer which provides a flexible way to add specific functionality to UServer. - * Plugins allow you to enhance the functionality of UServer without changing the core of the server. They can be loaded at - * startup time and can change virtually some aspect of the behaviour of the server. + * The plugin interface is an integral part of UServer which provides a flexible way to add specific + * functionality to UServer. Plugins allow you to enhance the functionality of UServer without changing + * the core of the server. They can be loaded at startup time and can change virtually some aspect of + * the behaviour of the server * * UServer has 7 hooks which are used in different states of the execution of the request: - * -------------------------------------------------------------------------------------------- - * Server-wide hooks (5): + * ---------------------------------------------------------------------------------------------------- + * * Server-wide hooks: + * ```````````````````` + * 1) handlerConfig: called when the server finished to process its configuration + * 2) handlerInit: called when the server start to process its init + * 3) handlerRun: called when the server finished to process its init, and before start to run + * 4) handlerFork: called when the server have forked a child + * 5) handlerStop: called when the server shut down * - * 1) handlerConfig: called when the server finished to process its configuration - * 2) handlerInit: called when the server start to process its init - * 3) handlerRun: called when the server finished to process its init, and before start to run - * 4) handlerFork: called when the server have forked a child - * 5) handlerStop: called when the server shut down + * * Connection-wide hooks: called in `UClientImage_Base::handlerRead()` + * ```````````````````````` + * 6) handlerREAD: + * 7) handlerRequest: + * ---------------------------------------------------------------------------------------------------- * - * Connection-wide hooks (2): - * - * 6) handlerREAD: called in UClientImage_Base::handlerRead() - * 7) handlerRequest: called in UClientImage_Base::handlerRead() - * -------------------------------------------------------------------------------------------- - * - * RETURNS VALUE: - * - * U_PLUGIN_HANDLER_GO_ON ok - * U_PLUGIN_HANDLER_ERROR error - * U_PLUGIN_HANDLER_AGAIN the request is not ready (NONBLOCKING) - * U_PLUGIN_HANDLER_FINISHED the request processing is complete - * U_PLUGIN_HANDLER_PROCESSED the request has been processed + * RETURNS: + * U_PLUGIN_HANDLER_OK ok + * U_PLUGIN_HANDLER_ERROR error + * U_PLUGIN_HANDLER_AGAIN the request is not ready (NONBLOCKING) + * U_PLUGIN_HANDLER_PROCESSED the request has been processed + * U_PLUGIN_HANDLER_FINISHED the request processing is complete */ enum PluginHandlerReturn { - U_PLUGIN_HANDLER_GO_ON = 0x001, - U_PLUGIN_HANDLER_ERROR = 0x002, - U_PLUGIN_HANDLER_AGAIN = 0x004, - U_PLUGIN_HANDLER_FINISHED = 0x008, - U_PLUGIN_HANDLER_PROCESSED = 0x010 + U_PLUGIN_HANDLER_OK = 0x000, + U_PLUGIN_HANDLER_ERROR = 0x001, + U_PLUGIN_HANDLER_AGAIN = 0x002, + U_PLUGIN_HANDLER_PROCESSED = 0x004, + U_PLUGIN_HANDLER_FINISHED = 0x008 }; class UFileConfig; @@ -72,35 +72,35 @@ public: { U_TRACE(0, "UServerPlugIn::handlerConfig(%p)", &cfg) - U_RETURN(U_PLUGIN_HANDLER_GO_ON); + U_RETURN(U_PLUGIN_HANDLER_OK); } virtual int handlerInit() { U_TRACE_NO_PARAM(0, "UServerPlugIn::handlerInit()") - U_RETURN(U_PLUGIN_HANDLER_GO_ON); + U_RETURN(U_PLUGIN_HANDLER_OK); } virtual int handlerRun() { U_TRACE_NO_PARAM(0, "UServerPlugIn::handlerRun()") - U_RETURN(U_PLUGIN_HANDLER_GO_ON); + U_RETURN(U_PLUGIN_HANDLER_OK); } virtual int handlerFork() { U_TRACE_NO_PARAM(0, "UServerPlugIn::handlerFork()") - U_RETURN(U_PLUGIN_HANDLER_GO_ON); + U_RETURN(U_PLUGIN_HANDLER_OK); } virtual int handlerStop() { U_TRACE_NO_PARAM(0, "UServerPlugIn::handlerStop()") - U_RETURN(U_PLUGIN_HANDLER_GO_ON); + U_RETURN(U_PLUGIN_HANDLER_OK); } // Connection-wide hooks @@ -109,14 +109,14 @@ public: { U_TRACE_NO_PARAM(0, "UServerPlugIn::handlerREAD()") - U_RETURN(U_PLUGIN_HANDLER_GO_ON); + U_RETURN(U_PLUGIN_HANDLER_OK); } virtual int handlerRequest() { U_TRACE_NO_PARAM(0, "UServerPlugIn::handlerRequest()") - U_RETURN(U_PLUGIN_HANDLER_GO_ON); + U_RETURN(U_PLUGIN_HANDLER_OK); } // SigHUP hook @@ -125,7 +125,7 @@ public: { U_TRACE_NO_PARAM(0, "UServerPlugIn::handlerSigHUP()") - U_RETURN(U_PLUGIN_HANDLER_GO_ON); + U_RETURN(U_PLUGIN_HANDLER_OK); } private: diff --git a/include/ulib/notifier.h b/include/ulib/notifier.h index b50e919f..3be23d19 100644 --- a/include/ulib/notifier.h +++ b/include/ulib/notifier.h @@ -99,7 +99,7 @@ public: } static void clear(); - static void modify(UEventFd* handler_event); + static bool modify(UEventFd* handler_event); static void callForAllEntryDynamic(bPFpv function); static void insert(UEventFd* handler_event, int op = 0); diff --git a/include/ulib/utility/dir_walk.h b/include/ulib/utility/dir_walk.h index ed8a4637..e047ec42 100644 --- a/include/ulib/utility/dir_walk.h +++ b/include/ulib/utility/dir_walk.h @@ -158,9 +158,11 @@ public: static void setFilter(const UString& _filter, int _filter_flags = 0) { setFilter(U_STRING_TO_PARAM(_filter), _filter_flags); } - static bool setDirectory(const UString& dir, const char* f = U_NULLPTR, uint32_t flen = 0, int _filter_flags = 0); + static bool setDirectory(const char* dir, uint32_t dlen, const char* f = U_NULLPTR, uint32_t flen = 0, int _filter_flags = 0); - static void setDirectory(const UString& dir, const UString& _filter, int _filter_flags = 0) { setDirectory(dir, U_STRING_TO_PARAM(_filter), _filter_flags); } + static bool setDirectory(const UString& dir, const char* f = U_NULLPTR, uint32_t flen = 0, int _filter_flags = 0) { return setDirectory(U_STRING_TO_PARAM(dir), f, flen, _filter_flags); } + static bool setDirectory(const UString& dir, const UString& _filter, int _filter_flags = 0) + { return setDirectory(U_STRING_TO_PARAM(dir), U_STRING_TO_PARAM(_filter), _filter_flags); } // DEBUG diff --git a/include/ulib/utility/uhttp.h b/include/ulib/utility/uhttp.h index 02f98e3a..51be4269 100644 --- a/include/ulib/utility/uhttp.h +++ b/include/ulib/utility/uhttp.h @@ -547,7 +547,6 @@ public: static UString* uri_request_cert_mask; static bool checkUriProtected(); - static bool isUriRequestProtected() __pure; #endif #if defined(U_HTTP_STRICT_TRANSPORT_SECURITY) || defined(USE_LIBSSL) @@ -1325,7 +1324,7 @@ private: } static int handlerREAD(); - static int processRequest(); + static void processRequest(); static void handlerResponse(); #ifndef U_LOG_DISABLE @@ -1344,7 +1343,7 @@ private: U_RETURN(U_ClientImage_state); } - static int processRequestWithLog() + static void processRequestWithLog() { U_TRACE_NO_PARAM(0, "UHTTP::processRequestWithLog()") @@ -1352,11 +1351,9 @@ private: (void) strcpy(UServer_Base::mod_name[0], "[http] "); - U_ClientImage_state = processRequest(); + processRequest(); UServer_Base::mod_name[0][0] = '\0'; - - U_RETURN(U_ClientImage_state); } #endif @@ -1398,7 +1395,6 @@ private: static bool processFileCache() U_NO_EXPORT; static bool readHeaderRequest() U_NO_EXPORT; static bool processGetRequest() U_NO_EXPORT; - static bool processAuthorization() U_NO_EXPORT; static bool checkRequestForHeader() U_NO_EXPORT; static bool checkGetRequestIfRange() U_NO_EXPORT; static bool checkGetRequestIfModified() U_NO_EXPORT; @@ -1408,12 +1404,14 @@ private: static int checkGetRequestForRange(const UString& data) U_NO_EXPORT; static int sortRange(const void* a, const void* b) __pure U_NO_EXPORT; static bool addHTTPVariables(UStringRep* key, void* value) U_NO_EXPORT; + static void setSendfile(int fd, uint32_t start, uint32_t count) U_NO_EXPORT; static bool splitCGIOutput(const char*& ptr1, const char* ptr2) U_NO_EXPORT; static void putDataInCache(const UString& fmt, UString& content) U_NO_EXPORT; static bool readDataChunked(USocket* sk, UString* pbuffer, UString& body) U_NO_EXPORT; static void setResponseForRange(uint32_t start, uint32_t end, uint32_t header) U_NO_EXPORT; static void manageDataForCache(const UString& basename, const UString& suffix) U_NO_EXPORT; static bool checkDataSession(const UString& token, time_t expire, UString* data) U_NO_EXPORT; + static bool processAuthorization(const char* ptr = U_NULLPTR, uint32_t sz = 0, const char* pattern = U_NULLPTR, uint32_t len = 0) U_NO_EXPORT; static inline void resetFileCache() U_NO_EXPORT; static inline void setUpgrade(const char* ptr) U_NO_EXPORT; diff --git a/src/ulib/base/utility.c b/src/ulib/base/utility.c index 349e0bbf..1bf37e47 100644 --- a/src/ulib/base/utility.c +++ b/src/ulib/base/utility.c @@ -1974,9 +1974,11 @@ __pure bool u_dosmatch_ext(const char* restrict s, uint32_t n1, const char* rest return ((flags & FNM_INVERT) != 0); } -__pure bool u_match_with_OR(bPFpcupcud pfn_match, const char* restrict s, uint32_t n1, const char* restrict pattern, uint32_t n2, int flags) +const char* restrict u_pOR; + +__pure uint32_t u_match_with_OR(bPFpcupcud pfn_match, const char* restrict s, uint32_t n1, const char* restrict pattern, uint32_t n2, int flags) { - const char* restrict p_or; + uint32_t n0; const char* restrict end = pattern + n2; U_INTERNAL_TRACE("u_match_with_OR(%p,%.*s,%u,%.*s,%u,%d)", pfn_match, U_min(n1,128), s, n1, n2, pattern, n2, flags) @@ -1988,13 +1990,25 @@ __pure bool u_match_with_OR(bPFpcupcud pfn_match, const char* restrict s, uint32 while (true) { - p_or = (const char* restrict) memchr(pattern, '|', n2); + u_pOR = (const char* restrict) memchr(pattern, '|', n2); - if (p_or == 0) return pfn_match(s, n1, pattern, n2, flags); + if (u_pOR == U_NULLPTR) return pfn_match(s, n1, pattern, n2, flags); - if (pfn_match(s, n1, pattern, (p_or - pattern), (flags & ~FNM_INVERT))) return ((flags & FNM_INVERT) == 0); + n0 = (u_pOR - pattern); - pattern = p_or + 1; + if (pfn_match(s, n1, pattern, n0, (flags & ~FNM_INVERT))) + { + if ((flags & FNM_INVERT) == 0) + { + u_pOR = pattern; + + return n0; + } + + return 0; + } + + pattern = u_pOR + 1; n2 = end - pattern; } } diff --git a/src/ulib/file.cpp b/src/ulib/file.cpp index a8346ee1..7318719b 100644 --- a/src/ulib/file.cpp +++ b/src/ulib/file.cpp @@ -200,9 +200,11 @@ bool UFile::stat() st_ino = 0; - bool result = (U_SYSCALL(stat, "%S,%p", U_PATH_CONV(path_relativ), (struct stat*)this) == 0); + if (U_SYSCALL(stat, "%S,%p", U_PATH_CONV(path_relativ), (struct stat*)this) == 0) U_RETURN(true); - U_RETURN(result); + st_mode = 0; + + U_RETURN(false); } bool UFile::chdir(const char* path, bool flag_save) diff --git a/src/ulib/net/server/client_image.cpp b/src/ulib/net/server/client_image.cpp index cb79b560..b64a3e80 100644 --- a/src/ulib/net/server/client_image.cpp +++ b/src/ulib/net/server/client_image.cpp @@ -26,7 +26,6 @@ #endif int UClientImage_Base::idx; -int UClientImage_Base::csfd; int UClientImage_Base::iovcnt; bool UClientImage_Base::bIPv6; bool UClientImage_Base::bsendGzipBomb; @@ -50,7 +49,7 @@ struct iovec UClientImage_Base::iov_sav[4]; struct iovec* UClientImage_Base::piov; iPF UClientImage_Base::callerHandlerRead = UServer_Base::pluginsHandlerREAD; -iPF UClientImage_Base::callerHandlerRequest = UServer_Base::pluginsHandlerRequest; +vPF UClientImage_Base::callerHandlerRequest = UServer_Base::pluginsHandlerRequest; bPF UClientImage_Base::callerHandlerCache = handlerCache; bPFpc UClientImage_Base::callerIsValidMethod = isValidMethod; bPFpcu UClientImage_Base::callerIsValidRequest = isValidRequest; @@ -109,7 +108,7 @@ void UClientImage_Base::logRequest() U_INTERNAL_ASSERT_MAJOR(u_printf_string_max_length, 0) } - U_INTERNAL_DUMP("u_printf_string_max_length = %d U_ClientImage_pipeline = %b request = %V", u_printf_string_max_length, U_ClientImage_pipeline, request->rep) + U_INTERNAL_DUMP("u_printf_string_max_length = %d U_ClientImage_pipeline = %b", u_printf_string_max_length, U_ClientImage_pipeline) UServer_Base::log->log(U_CONSTANT_TO_PARAM("received request (%u bytes) %.*s%.*s%#.*S from %v"), sz, (U_ClientImage_pipeline ? U_CONSTANT_SIZE("[pipeline] ") : 0), "[pipeline] ", @@ -396,10 +395,13 @@ void UClientImage_Base::setSendfile(int fd, uint32_t lstart, uint32_t lcount) U_INTERNAL_DUMP("U_http_version = %C", U_http_version) + U_ASSERT(body->empty()) U_INTERNAL_ASSERT_DIFFERS(fd, -1) U_INTERNAL_ASSERT_MAJOR(lcount, 0) U_INTERNAL_ASSERT_DIFFERS(U_http_version, '2') + setRequestNoCache(); + UServer_Base::pClientImage->start = lstart; UServer_Base::pClientImage->count = lcount; UServer_Base::pClientImage->sfd = fd; @@ -473,6 +475,8 @@ void UClientImage_Base::handlerDelete() } #endif + U_INTERNAL_ASSERT_DIFFERS(U_ClientImage_parallelization, U_PARALLELIZATION_CHILD) + #ifndef U_LOG_DISABLE if (UServer_Base::isLog()) { @@ -546,7 +550,7 @@ void UClientImage_Base::handlerDelete() if ((U_ClientImage_pclose(this) & U_CLOSE) != 0) { # ifdef DEBUG - if (UNLIKELY(sfd == -1)) + if (UNLIKELY(sfd <= 0)) { U_ERROR("handlerDelete(): " "UEventFd::fd = %d socket->iSockDesc = %d " @@ -674,8 +678,8 @@ void UClientImage_Base::startRequest() #ifdef U_SERVER_CHECK_TIME_BETWEEN_REQUEST long time_elapsed = chronometer->restart(); - U_INTERNAL_DUMP("U_ClientImage_pipeline = %b time_elapsed = %ld time_run = %ld U_ClientImage_request_is_cached = %b csfd = %d", - U_ClientImage_pipeline, time_elapsed, time_run, U_ClientImage_request_is_cached, csfd) + U_INTERNAL_DUMP("U_ClientImage_pipeline = %b time_elapsed = %ld time_run = %ld U_ClientImage_request_is_cached = %b", + U_ClientImage_pipeline, time_elapsed, time_run, U_ClientImage_request_is_cached) if (U_ClientImage_pipeline == false && U_ClientImage_parallelization == 0) @@ -1001,6 +1005,8 @@ void UClientImage_Base::prepareForRead() return; } # endif + + // resetRequestFromUServer(); } else { @@ -1014,6 +1020,8 @@ void UClientImage_Base::prepareForRead() U_INTERNAL_ASSERT_MAJOR(UServer_Base::client_address_len, 0) UEventFd::fd = socket->iSockDesc; + + // setRequestFromUServer(); } #ifdef U_EVASIVE_SUPPORT @@ -1126,7 +1134,7 @@ bool UClientImage_Base::genericRead() } #endif - U_ClientImage_state = U_PLUGIN_HANDLER_GO_ON; + U_ClientImage_state = 0; U_RETURN(true); } @@ -1255,7 +1263,6 @@ data_missing: goto next2; } - csfd = -1; U_ClientImage_request_is_cached = false; } #endif @@ -1266,29 +1273,25 @@ data_missing: if (UHTTP::checkForUSP()) U_RETURN(U_NOTIFIER_OK); #endif - size_request = - U_ClientImage_request = 0; + size_request = 0; U_ClientImage_state = callerHandlerRead(); U_INTERNAL_DUMP("socket->isClosed() = %b U_http_info.nResponseCode = %u U_ClientImage_close = %b U_ClientImage_state = %d %B", socket->isClosed(), U_http_info.nResponseCode, U_ClientImage_close, U_ClientImage_state, U_ClientImage_state) - if (U_ClientImage_parallelization == U_PARALLELIZATION_PARENT) + if (UNLIKELY(socket->isClosed())) { - U_ASSERT(wbuffer->empty()) - U_ASSERT(socket->isClosed()) - U_ASSERT_EQUALS(isRequestNeedProcessing(), false) - U_INTERNAL_ASSERT_EQUALS(U_ClientImage_data_missing, false) +cls: if (U_ClientImage_parallelization == U_PARALLELIZATION_PARENT) + { + U_ASSERT(wbuffer->empty()) + U_ASSERT_EQUALS(isRequestNeedProcessing(), false) + U_INTERNAL_ASSERT_EQUALS(U_ClientImage_data_missing, false) - endRequest(); + endRequest(); - U_RETURN(U_NOTIFIER_DELETE); - } - - if ((U_ClientImage_state & U_PLUGIN_HANDLER_ERROR) != 0) - { - U_ASSERT(socket->isClosed()) + U_RETURN(U_NOTIFIER_DELETE); + } goto error; } @@ -1297,6 +1300,7 @@ data_missing: U_ClientImage_pipeline, U_ClientImage_parallelization, U_ClientImage_data_missing) U_INTERNAL_ASSERT(socket->isOpen()) + U_INTERNAL_ASSERT_EQUALS(U_ClientImage_state & U_PLUGIN_HANDLER_ERROR, 0) if (U_ClientImage_data_missing) goto data_missing; @@ -1412,9 +1416,9 @@ check: U_INTERNAL_DUMP("nrequest = %u resto = %u", nrequest, resto) U_INTERNAL_ASSERT_DIFFERS(U_ClientImage_parallelization, U_PARALLELIZATION_PARENT) U_INTERNAL_ASSERT_EQUALS(U_ClientImage_state & (U_PLUGIN_HANDLER_AGAIN | U_PLUGIN_HANDLER_ERROR), 0) - U_ClientImage_state = callerHandlerRequest(); + callerHandlerRequest(); - if (UNLIKELY(socket->isClosed())) goto error; + if (UNLIKELY(socket->isClosed())) goto cls; } U_INTERNAL_DUMP("socket->isClosed() = %b U_http_info.nResponseCode = %u U_ClientImage_close = %b U_ClientImage_state = %d %B", @@ -1472,9 +1476,6 @@ write: { // NB: we are managing a sendfile() request... - U_INTERNAL_DUMP("U_http_sendfile = %b", U_http_sendfile) - - U_INTERNAL_ASSERT(U_http_sendfile) U_INTERNAL_ASSERT_EQUALS(nrequest, 0) U_INTERNAL_ASSERT_DIFFERS(U_http_version, '2') U_INTERNAL_ASSERT_EQUALS(UEventFd::op_mask, EPOLLIN | EPOLLRDHUP | EPOLLET) @@ -1482,6 +1483,8 @@ write: if (writeResponse() == false || UClientImage_Base::handlerWrite() == U_NOTIFIER_DELETE) { + U_INTERNAL_DUMP("count = %u", count) + goto error; } } @@ -1496,6 +1499,8 @@ write: endRequest(); startRequest(); + U_ClientImage_request = 0; + goto pipeline; } } @@ -1529,7 +1534,12 @@ end: if (U_ClientImage_parallelization == U_PARALLELIZATION_CHILD) goto death; { U_INTERNAL_ASSERT_DIFFERS(socket->iSockDesc, -1) - if (UNotifier::waitForRead(socket->iSockDesc, U_TIMEOUT_MS) == 1) goto start; + if (UNotifier::waitForRead(socket->iSockDesc, U_TIMEOUT_MS) == 1) + { + U_ClientImage_request = 0; + + goto start; + } death: UServer_Base::endNewChild(); // no return; @@ -1539,6 +1549,7 @@ death: U_INTERNAL_ASSERT(socket->isOpen()) U_INTERNAL_ASSERT_DIFFERS(U_ClientImage_parallelization, U_PARALLELIZATION_CHILD) + U_INTERNAL_ASSERT_DIFFERS(U_ClientImage_parallelization, U_PARALLELIZATION_PARENT) U_INTERNAL_DUMP("request(%u) = %V", request->size(), request->rep); @@ -1815,9 +1826,10 @@ void UClientImage_Base::prepareForSendfile() { U_TRACE_NO_PARAM(0, "UClientImage_Base::prepareForSendfile()") + U_INTERNAL_ASSERT_MAJOR(sfd, 0) U_INTERNAL_ASSERT_MAJOR(count, 0) - U_INTERNAL_ASSERT_DIFFERS(sfd, -1) U_INTERNAL_ASSERT_DIFFERS(U_http_version, '2') + U_INTERNAL_ASSERT_DIFFERS(U_ClientImage_parallelization, U_PARALLELIZATION_CHILD) if (U_ClientImage_close) { @@ -1829,7 +1841,7 @@ void UClientImage_Base::prepareForSendfile() UEventFd::op_mask = EPOLLOUT; - if (UNotifier::isHandler(UEventFd::fd)) UNotifier::modify(this); + if (UNotifier::isHandler(UEventFd::fd)) (void) UNotifier::modify(this); U_INTERNAL_DUMP("start = %u count = %u", start, count) } @@ -1909,8 +1921,8 @@ int UClientImage_Base::handlerWrite() } #endif + U_INTERNAL_ASSERT_MAJOR(sfd, 0) U_INTERNAL_ASSERT_MAJOR(count, 0) - U_INTERNAL_ASSERT_DIFFERS(sfd, -1) U_INTERNAL_ASSERT(socket->isOpen()) bool bwrite = (UEventFd::op_mask == EPOLLOUT); @@ -1943,7 +1955,7 @@ write: { UEventFd::op_mask = EPOLLIN | EPOLLRDHUP | EPOLLET; - UNotifier::modify(this); + (void) UNotifier::modify(this); } # ifdef DEBUG else @@ -1953,12 +1965,12 @@ write: } # endif - if ((U_ClientImage_pclose(this) & U_CLOSE) != 0) UFile::close(sfd); - start = count = 0; sfd = -1; + if ((U_ClientImage_pclose(this) & U_CLOSE) != 0) UFile::close(sfd); + if ((U_ClientImage_pclose(this) & U_YES) != 0) U_RETURN(U_NOTIFIER_DELETE); U_RETURN(U_NOTIFIER_OK); @@ -1977,11 +1989,13 @@ write: if (U_ClientImage_parallelization == U_PARALLELIZATION_CHILD) { -wait: if (socket->isOpen() == false) goto end; +wait: if (socket->isOpen() && + UNotifier::waitForWrite(socket->iSockDesc, U_TIMEOUT_MS) == 1) + { + goto write; + } - if (UNotifier::waitForWrite(socket->iSockDesc, U_TIMEOUT_MS) == 1) goto write; - - U_RETURN(U_NOTIFIER_DELETE); + goto end; } if (UServer_Base::startParallelization()) U_RETURN(U_NOTIFIER_DELETE); // parent @@ -1996,13 +2010,16 @@ wait: if (socket->isOpen() == false) goto end; end: U_SRV_LOG("sendfile failed - sock_fd %d sfd %d count %u U_ClientImage_pclose(this) %d %B", socket->iSockDesc, sfd, count, U_ClientImage_pclose(this), U_ClientImage_pclose(this)); - if ((U_ClientImage_pclose(this) & U_CLOSE) != 0) UFile::close(sfd); + if (U_ClientImage_parallelization != U_PARALLELIZATION_CHILD) + { + if ((U_ClientImage_pclose(this) & U_CLOSE) != 0) UFile::close(sfd); - start = - count = 0; - sfd = -1; + start = + count = 0; + sfd = -1; - U_ClientImage_pclose(this) = 0; + U_ClientImage_pclose(this) = 0; + } U_RETURN(U_NOTIFIER_DELETE); } diff --git a/src/ulib/net/server/client_image_rdb.cpp b/src/ulib/net/server/client_image_rdb.cpp index a898ca09..9fb2985c 100644 --- a/src/ulib/net/server/client_image_rdb.cpp +++ b/src/ulib/net/server/client_image_rdb.cpp @@ -35,7 +35,7 @@ int URDBClientImage::handlerRead() if (UClientImage_Base::manageRead() == U_NOTIFIER_DELETE) U_RETURN(U_NOTIFIER_DELETE); - if (U_ClientImage_state == U_PLUGIN_HANDLER_GO_ON) + if (U_ClientImage_state == U_PLUGIN_HANDLER_OK) { # ifndef U_LOG_DISABLE if (UClientImage_Base::logbuf) diff --git a/src/ulib/net/server/plugin/mod_echo.cpp b/src/ulib/net/server/plugin/mod_echo.cpp index e919301a..0ec92701 100644 --- a/src/ulib/net/server/plugin/mod_echo.cpp +++ b/src/ulib/net/server/plugin/mod_echo.cpp @@ -50,5 +50,5 @@ int UEchoPlugIn::handlerRequest() (void) UClientImage_Base::wbuffer->assign(U_CONSTANT_TO_PARAM(U_ECHO_RESPONSE_FOR_TEST)); #endif - U_RETURN(U_PLUGIN_HANDLER_PROCESSED | U_PLUGIN_HANDLER_FINISHED); + U_RETURN(U_PLUGIN_HANDLER_PROCESSED); } diff --git a/src/ulib/net/server/plugin/mod_fcgi.cpp b/src/ulib/net/server/plugin/mod_fcgi.cpp index 5a80bfca..1e73f11d 100644 --- a/src/ulib/net/server/plugin/mod_fcgi.cpp +++ b/src/ulib/net/server/plugin/mod_fcgi.cpp @@ -197,10 +197,10 @@ int UFCGIPlugIn::handlerConfig(UFileConfig& cfg) fcgi_keep_conn = cfg.readBoolean(U_CONSTANT_TO_PARAM("CGI_KEEP_CONN")); - U_RETURN(U_PLUGIN_HANDLER_PROCESSED | U_PLUGIN_HANDLER_GO_ON); + U_RETURN(U_PLUGIN_HANDLER_PROCESSED); } - U_RETURN(U_PLUGIN_HANDLER_GO_ON); + U_RETURN(U_PLUGIN_HANDLER_OK); } int UFCGIPlugIn::handlerInit() @@ -236,8 +236,6 @@ int UFCGIPlugIn::handlerInit() UHTTP::valias->push_back(*UString::str_nostat); environment_type = (UHTTP::fcgi_uri_mask->equal(U_CONSTANT_TO_PARAM("*.php")) ? U_PHP : U_CGI); - - U_RETURN(U_PLUGIN_HANDLER_PROCESSED | U_PLUGIN_HANDLER_GO_ON); # endif } @@ -245,7 +243,7 @@ int UFCGIPlugIn::handlerInit() connection = U_NULLPTR; } - U_RETURN(U_PLUGIN_HANDLER_ERROR); + U_RETURN(U_PLUGIN_HANDLER_OK); } // Connection-wide hooks @@ -369,7 +367,7 @@ int UFCGIPlugIn::handlerRequest() { UHTTP::setInternalError(); - U_RETURN(U_PLUGIN_HANDLER_PROCESSED | U_PLUGIN_HANDLER_GO_ON); + U_RETURN(U_PLUGIN_HANDLER_PROCESSED); } if (fcgi_keep_conn == false) @@ -448,8 +446,7 @@ int UFCGIPlugIn::handlerRequest() { U_INTERNAL_ASSERT_EQUALS(pos + clength, connection->response.size()) - if (UHTTP::processCGIOutput(false, false)) UClientImage_Base::setRequestProcessed(); - else UHTTP::setInternalError(); + if (UHTTP::processCGIOutput(false, false) == false) UHTTP::setInternalError(); goto end; } @@ -487,10 +484,10 @@ end: connection->clearData(); connection->close(); } - U_RETURN(U_PLUGIN_HANDLER_GO_ON | U_PLUGIN_HANDLER_PROCESSED); + U_RETURN(U_PLUGIN_HANDLER_PROCESSED); } - U_RETURN(U_PLUGIN_HANDLER_GO_ON); + U_RETURN(U_PLUGIN_HANDLER_OK); } // DEBUG diff --git a/src/ulib/net/server/plugin/mod_geoip/mod_geoip.cpp b/src/ulib/net/server/plugin/mod_geoip/mod_geoip.cpp index 8f6b3df9..2e201c9f 100644 --- a/src/ulib/net/server/plugin/mod_geoip/mod_geoip.cpp +++ b/src/ulib/net/server/plugin/mod_geoip/mod_geoip.cpp @@ -164,11 +164,11 @@ int UGeoIPPlugIn::handlerConfig(UFileConfig& cfg) { U_NEW(UString, country_forbidden_mask, UString(x)); - U_RETURN(U_PLUGIN_HANDLER_PROCESSED | U_PLUGIN_HANDLER_GO_ON); + U_RETURN(U_PLUGIN_HANDLER_PROCESSED); } } - U_RETURN(U_PLUGIN_HANDLER_GO_ON); + U_RETURN(U_PLUGIN_HANDLER_OK); } int UGeoIPPlugIn::handlerInit() @@ -202,7 +202,7 @@ int UGeoIPPlugIn::handlerInit() } } - U_RETURN(U_PLUGIN_HANDLER_PROCESSED | U_PLUGIN_HANDLER_GO_ON); + U_RETURN(U_PLUGIN_HANDLER_OK); } // Connection-wide hooks @@ -220,7 +220,7 @@ int UGeoIPPlugIn::handlerREAD() U_RETURN(U_PLUGIN_HANDLER_ERROR); } - U_RETURN(U_PLUGIN_HANDLER_PROCESSED | U_PLUGIN_HANDLER_GO_ON); + U_RETURN(U_PLUGIN_HANDLER_OK); } int UGeoIPPlugIn::handlerRequest() @@ -268,7 +268,7 @@ int UGeoIPPlugIn::handlerRequest() gir->postal_code); } - U_RETURN(U_PLUGIN_HANDLER_PROCESSED | U_PLUGIN_HANDLER_GO_ON); + U_RETURN(U_PLUGIN_HANDLER_OK); } // DEBUG diff --git a/src/ulib/net/server/plugin/mod_http.cpp b/src/ulib/net/server/plugin/mod_http.cpp index 4e83f90f..03d509af 100644 --- a/src/ulib/net/server/plugin/mod_http.cpp +++ b/src/ulib/net/server/plugin/mod_http.cpp @@ -134,7 +134,7 @@ int UHttpPlugIn::handlerConfig(UFileConfig& cfg) U_NEW(UString, UHTTP::maintenance_mode_page, UString(x)); - U_RETURN(U_PLUGIN_HANDLER_PROCESSED | U_PLUGIN_HANDLER_GO_ON); + U_RETURN(U_PLUGIN_HANDLER_PROCESSED); } UHTTP::virtual_host = bvirtual_host; @@ -452,10 +452,10 @@ int UHttpPlugIn::handlerConfig(UFileConfig& cfg) } # endif - U_RETURN(U_PLUGIN_HANDLER_PROCESSED | U_PLUGIN_HANDLER_GO_ON); + U_RETURN(U_PLUGIN_HANDLER_PROCESSED); } - U_RETURN(U_PLUGIN_HANDLER_GO_ON); + U_RETURN(U_PLUGIN_HANDLER_OK); } int UHttpPlugIn::handlerInit() @@ -510,7 +510,7 @@ int UHttpPlugIn::handlerInit() UHTTP::init(); - U_RETURN(U_PLUGIN_HANDLER_PROCESSED | U_PLUGIN_HANDLER_GO_ON); + U_RETURN(U_PLUGIN_HANDLER_OK); } int UHttpPlugIn::handlerRun() // NB: we use this method instead of handlerInit() because now we have the shared data allocated by UServer... @@ -601,7 +601,7 @@ int UHttpPlugIn::handlerRun() // NB: we use this method instead of handlerInit() U_RESET_MODULE_NAME; - U_RETURN(U_PLUGIN_HANDLER_PROCESSED | U_PLUGIN_HANDLER_GO_ON); + U_RETURN(U_PLUGIN_HANDLER_OK); } int UHttpPlugIn::handlerFork() @@ -614,7 +614,7 @@ int UHttpPlugIn::handlerFork() if (UHTTP::bcallInitForAllUSP) UHTTP::callAfterForkForAllUSP(); - U_RETURN(U_PLUGIN_HANDLER_PROCESSED | U_PLUGIN_HANDLER_GO_ON); + U_RETURN(U_PLUGIN_HANDLER_OK); } int UHttpPlugIn::handlerStop() @@ -641,7 +641,7 @@ int UHttpPlugIn::handlerStop() U_RESET_MODULE_NAME; - U_RETURN(U_PLUGIN_HANDLER_PROCESSED | U_PLUGIN_HANDLER_GO_ON); + U_RETURN(U_PLUGIN_HANDLER_OK); } // Connection-wide hooks @@ -661,9 +661,14 @@ int UHttpPlugIn::handlerRequest() U_INTERNAL_DUMP("method_type = %C uri = %.*S UServer_Base::mod_name[0] = %S", U_http_method_type, U_HTTP_URI_TO_TRACE, UServer_Base::mod_name[0]) - if (UClientImage_Base::isRequestNeedProcessing()) return UHTTP::processRequest(); + if (UClientImage_Base::isRequestNeedProcessing()) + { + UHTTP::processRequest(); - U_RETURN(U_PLUGIN_HANDLER_FINISHED); + U_RETURN(U_PLUGIN_HANDLER_PROCESSED); + } + + U_RETURN(U_PLUGIN_HANDLER_OK); } // SigHUP hook @@ -684,5 +689,5 @@ int UHttpPlugIn::handlerSigHUP() if (UHTTP::bcallInitForAllUSP) UHTTP::callSigHUPForAllUSP(); - U_RETURN(U_PLUGIN_HANDLER_PROCESSED | U_PLUGIN_HANDLER_GO_ON); + U_RETURN(U_PLUGIN_HANDLER_OK); } diff --git a/src/ulib/net/server/plugin/mod_nocat.cpp b/src/ulib/net/server/plugin/mod_nocat.cpp index aebf5b21..ecaf2fee 100644 --- a/src/ulib/net/server/plugin/mod_nocat.cpp +++ b/src/ulib/net/server/plugin/mod_nocat.cpp @@ -2118,7 +2118,7 @@ int UNoCatPlugIn::handlerConfig(UFileConfig& cfg) U_INTERNAL_DUMP("label = %V", label->rep) - U_RETURN(U_PLUGIN_HANDLER_PROCESSED | U_PLUGIN_HANDLER_GO_ON); + U_RETURN(U_PLUGIN_HANDLER_PROCESSED); } int UNoCatPlugIn::handlerInit() @@ -2247,7 +2247,7 @@ int UNoCatPlugIn::handlerInit() U_INTERNAL_DUMP("num_peers_preallocate = %u peers_preallocate = %p", num_peers_preallocate, peers_preallocate) - U_RETURN(U_PLUGIN_HANDLER_PROCESSED | U_PLUGIN_HANDLER_GO_ON); + U_RETURN(U_PLUGIN_HANDLER_OK); } bool UNoCatPlugIn::preallocatePeersFault() @@ -2418,7 +2418,7 @@ int UNoCatPlugIn::handlerFork() } #endif - U_RETURN(U_PLUGIN_HANDLER_PROCESSED | U_PLUGIN_HANDLER_GO_ON); + U_RETURN(U_PLUGIN_HANDLER_OK); } // Connection-wide hooks @@ -2887,10 +2887,10 @@ redirect: end: UClientImage_Base::setCloseConnection(); - U_RETURN(U_PLUGIN_HANDLER_PROCESSED | U_PLUGIN_HANDLER_GO_ON); + U_RETURN(U_PLUGIN_HANDLER_PROCESSED); } - U_RETURN(U_PLUGIN_HANDLER_GO_ON); + U_RETURN(U_PLUGIN_HANDLER_OK); } // DEBUG diff --git a/src/ulib/net/server/plugin/mod_proxy.cpp b/src/ulib/net/server/plugin/mod_proxy.cpp index cf83ef48..74168ccf 100644 --- a/src/ulib/net/server/plugin/mod_proxy.cpp +++ b/src/ulib/net/server/plugin/mod_proxy.cpp @@ -48,9 +48,9 @@ int UProxyPlugIn::handlerConfig(UFileConfig& cfg) { U_TRACE(0, "UProxyPlugIn::handlerConfig(%p)", &cfg) - if (UModProxyService::loadConfig(cfg)) U_RETURN(U_PLUGIN_HANDLER_PROCESSED | U_PLUGIN_HANDLER_GO_ON); + if (UModProxyService::loadConfig(cfg)) U_RETURN(U_PLUGIN_HANDLER_PROCESSED); - U_RETURN(U_PLUGIN_HANDLER_GO_ON); + U_RETURN(U_PLUGIN_HANDLER_OK); } int UProxyPlugIn::handlerInit() @@ -70,7 +70,7 @@ int UProxyPlugIn::handlerInit() U_NEW(UHttpClient, client_http, UHttpClient((UFileConfig*)U_NULLPTR)); - U_RETURN(U_PLUGIN_HANDLER_PROCESSED | U_PLUGIN_HANDLER_GO_ON); + U_RETURN(U_PLUGIN_HANDLER_OK); } // Connection-wide hooks @@ -111,7 +111,7 @@ int UProxyPlugIn::handlerRequest() UHTTP::setInternalError(); } - U_RETURN(U_PLUGIN_HANDLER_PROCESSED | U_PLUGIN_HANDLER_GO_ON); + U_RETURN(U_PLUGIN_HANDLER_PROCESSED); } } @@ -125,7 +125,7 @@ int UProxyPlugIn::handlerRequest() { UModProxyService::setMsgError(UModProxyService::INTERNAL_ERROR); - U_RETURN(U_PLUGIN_HANDLER_PROCESSED | U_PLUGIN_HANDLER_GO_ON); + U_RETURN(U_PLUGIN_HANDLER_PROCESSED); } U_INTERNAL_DUMP("uri = %.*S", U_HTTP_URI_TO_TRACE) @@ -226,12 +226,10 @@ int UProxyPlugIn::handlerRequest() client_http->reset(); // reset reference to request... } - UClientImage_Base::setRequestProcessed(); - - U_RETURN(U_PLUGIN_HANDLER_PROCESSED | U_PLUGIN_HANDLER_GO_ON); + U_RETURN(U_PLUGIN_HANDLER_PROCESSED); } - U_RETURN(U_PLUGIN_HANDLER_GO_ON); + U_RETURN(U_PLUGIN_HANDLER_OK); } // DEBUG diff --git a/src/ulib/net/server/plugin/mod_rpc.cpp b/src/ulib/net/server/plugin/mod_rpc.cpp index 10d7c52c..ffa44fb7 100644 --- a/src/ulib/net/server/plugin/mod_rpc.cpp +++ b/src/ulib/net/server/plugin/mod_rpc.cpp @@ -46,14 +46,14 @@ int URpcPlugIn::handlerConfig(UFileConfig& cfg) URPCObject::loadGenericMethod(&cfg); - U_RETURN(U_PLUGIN_HANDLER_PROCESSED | U_PLUGIN_HANDLER_GO_ON); + U_RETURN(U_PLUGIN_HANDLER_PROCESSED); } __pure int URpcPlugIn::handlerInit() { U_TRACE_NO_PARAM(0, "URpcPlugIn::handlerInit()") - if (rpc_parser) U_RETURN(U_PLUGIN_HANDLER_PROCESSED | U_PLUGIN_HANDLER_GO_ON); + if (rpc_parser) U_RETURN(U_PLUGIN_HANDLER_OK); U_RETURN(U_PLUGIN_HANDLER_ERROR); } @@ -67,11 +67,9 @@ int URpcPlugIn::handlerREAD() if (rpc_parser) { is_rpc_msg = URPC::readRequest(UServer_Base::csocket); // NB: URPC::resetInfo() it is already called by clearData()... - - if (is_rpc_msg) U_RETURN(U_PLUGIN_HANDLER_PROCESSED | U_PLUGIN_HANDLER_FINISHED); } - U_RETURN(U_PLUGIN_HANDLER_GO_ON); + U_RETURN(U_PLUGIN_HANDLER_OK); } int URpcPlugIn::handlerRequest() @@ -96,10 +94,10 @@ int URpcPlugIn::handlerRequest() if (UServer_Base::isLog()) (void) UClientImage_Base::request_uri->assign(method); # endif - U_RETURN(U_PLUGIN_HANDLER_PROCESSED | U_PLUGIN_HANDLER_FINISHED); + U_RETURN(U_PLUGIN_HANDLER_PROCESSED); } - U_RETURN(U_PLUGIN_HANDLER_GO_ON); + U_RETURN(U_PLUGIN_HANDLER_OK); } // DEBUG diff --git a/src/ulib/net/server/plugin/mod_scgi.cpp b/src/ulib/net/server/plugin/mod_scgi.cpp index f64ce83a..a74d01b4 100644 --- a/src/ulib/net/server/plugin/mod_scgi.cpp +++ b/src/ulib/net/server/plugin/mod_scgi.cpp @@ -75,10 +75,10 @@ int USCGIPlugIn::handlerConfig(UFileConfig& cfg) scgi_keep_conn = cfg.readBoolean(U_CONSTANT_TO_PARAM("SCGI_KEEP_CONN")); - U_RETURN(U_PLUGIN_HANDLER_PROCESSED | U_PLUGIN_HANDLER_GO_ON); + U_RETURN(U_PLUGIN_HANDLER_PROCESSED); } - U_RETURN(U_PLUGIN_HANDLER_GO_ON); + U_RETURN(U_PLUGIN_HANDLER_OK); } int USCGIPlugIn::handlerInit() @@ -111,7 +111,7 @@ int USCGIPlugIn::handlerInit() UHTTP::valias->push_back(*UHTTP::scgi_uri_mask); UHTTP::valias->push_back(*UString::str_nostat); - U_RETURN(U_PLUGIN_HANDLER_PROCESSED | U_PLUGIN_HANDLER_GO_ON); + U_RETURN(U_PLUGIN_HANDLER_OK); # endif } @@ -203,8 +203,7 @@ int USCGIPlugIn::handlerRequest() *UClientImage_Base::wbuffer = connection->getResponse(); - if (UHTTP::processCGIOutput(false, false)) UClientImage_Base::setRequestProcessed(); - else UHTTP::setInternalError(); + if (UHTTP::processCGIOutput(false, false) == false) UHTTP::setInternalError(); end: connection->clearData(); @@ -214,10 +213,10 @@ end: connection->clearData(); connection->close(); } - U_RETURN(U_PLUGIN_HANDLER_PROCESSED | U_PLUGIN_HANDLER_GO_ON); + U_RETURN(U_PLUGIN_HANDLER_PROCESSED); } - U_RETURN(U_PLUGIN_HANDLER_GO_ON); + U_RETURN(U_PLUGIN_HANDLER_OK); } // DEBUG diff --git a/src/ulib/net/server/plugin/mod_shib/mod_shib.cpp b/src/ulib/net/server/plugin/mod_shib/mod_shib.cpp index fca9f1a2..dc3b9fa0 100644 --- a/src/ulib/net/server/plugin/mod_shib/mod_shib.cpp +++ b/src/ulib/net/server/plugin/mod_shib/mod_shib.cpp @@ -538,9 +538,9 @@ int UShibPlugIn::handlerConfig(UFileConfig& cfg) { U_TRACE(0, "UShibPlugIn::handlerConfig(%p)", &cfg) - if (UModProxyService::loadConfig(cfg)) U_RETURN(U_PLUGIN_HANDLER_PROCESSED | U_PLUGIN_HANDLER_GO_ON); + if (UModProxyService::loadConfig(cfg)) U_RETURN(U_PLUGIN_HANDLER_PROCESSED); - U_RETURN(U_PLUGIN_HANDLER_GO_ON); + U_RETURN(U_PLUGIN_HANDLER_OK); } /* @@ -587,7 +587,7 @@ int UShibPlugIn::handlerInit() m_plugMgr->regFactory(shibtarget::XML::NativeRequestMapType, &URequestMapFactory); m_plugMgr->regFactory(shibtarget::XML::LegacyRequestMapType, &URequestMapFactory); - if (conf->load(SHIB_CONFIG)) U_RETURN(U_PLUGIN_HANDLER_PROCESSED | U_PLUGIN_HANDLER_GO_ON); + if (conf->load(SHIB_CONFIG)) U_RETURN(U_PLUGIN_HANDLER_OK); } } @@ -702,8 +702,8 @@ int UShibPlugIn::handlerRequest() U_SYSCALL_VOID(free, "%p", (void*)UShibTarget::hostname); U_SYSCALL_VOID(free, "%p", (void*)UShibTarget::remote_addr); - U_RETURN(U_PLUGIN_HANDLER_PROCESSED | U_PLUGIN_HANDLER_GO_ON); + U_RETURN(U_PLUGIN_HANDLER_PROCESSED); } - U_RETURN(U_PLUGIN_HANDLER_GO_ON); + U_RETURN(U_PLUGIN_HANDLER_OK); } diff --git a/src/ulib/net/server/plugin/mod_skeleton.cpp b/src/ulib/net/server/plugin/mod_skeleton.cpp index 79e8640a..7517d4c0 100644 --- a/src/ulib/net/server/plugin/mod_skeleton.cpp +++ b/src/ulib/net/server/plugin/mod_skeleton.cpp @@ -23,7 +23,7 @@ int USkeletonPlugIn::handlerConfig(UFileConfig& cfg) { U_TRACE(0, "USkeletonPlugIn::handlerConfig(%p)", &cfg) - int result = U_PLUGIN_HANDLER_GO_ON; + int result = U_PLUGIN_HANDLER_OK; U_RETURN(result); } @@ -32,7 +32,7 @@ int USkeletonPlugIn::handlerInit() { U_TRACE_NO_PARAM(0, "USkeletonPlugIn::handlerInit()") - int result = U_PLUGIN_HANDLER_GO_ON; + int result = U_PLUGIN_HANDLER_OK; U_RETURN(result); } @@ -41,7 +41,7 @@ int USkeletonPlugIn::handlerRun() { U_TRACE_NO_PARAM(0, "USkeletonPlugIn::handlerRun()") - int result = U_PLUGIN_HANDLER_GO_ON; + int result = U_PLUGIN_HANDLER_OK; U_RETURN(result); } @@ -50,7 +50,7 @@ int USkeletonPlugIn::handlerFork() { U_TRACE_NO_PARAM(0, "USkeletonPlugIn::handlerFork()") - int result = U_PLUGIN_HANDLER_GO_ON; + int result = U_PLUGIN_HANDLER_OK; U_RETURN(result); } @@ -59,7 +59,7 @@ int USkeletonPlugIn::handlerStop() { U_TRACE_NO_PARAM(0, "USkeletonPlugIn::handlerStop()") - int result = U_PLUGIN_HANDLER_GO_ON; + int result = U_PLUGIN_HANDLER_OK; U_RETURN(result); } @@ -70,7 +70,7 @@ int USkeletonPlugIn::handlerREAD() { U_TRACE_NO_PARAM(0, "USkeletonPlugIn::handlerREAD()") - int result = U_PLUGIN_HANDLER_GO_ON; + int result = U_PLUGIN_HANDLER_OK; U_RETURN(result); } @@ -79,7 +79,7 @@ int USkeletonPlugIn::handlerRequest() { U_TRACE_NO_PARAM(0, "USkeletonPlugIn::handlerRequest()") - int result = U_PLUGIN_HANDLER_GO_ON; + int result = U_PLUGIN_HANDLER_OK; U_RETURN(result); } diff --git a/src/ulib/net/server/plugin/mod_soap.cpp b/src/ulib/net/server/plugin/mod_soap.cpp index bcb53464..b5a5a451 100644 --- a/src/ulib/net/server/plugin/mod_soap.cpp +++ b/src/ulib/net/server/plugin/mod_soap.cpp @@ -46,7 +46,7 @@ int USoapPlugIn::handlerConfig(UFileConfig& cfg) USOAPObject::loadGenericMethod(&cfg); - U_RETURN(U_PLUGIN_HANDLER_PROCESSED | U_PLUGIN_HANDLER_GO_ON); + U_RETURN(U_PLUGIN_HANDLER_PROCESSED); } int USoapPlugIn::handlerInit() @@ -65,7 +65,7 @@ int USoapPlugIn::handlerInit() UHTTP::valias->push_back(*UString::str_soap); UHTTP::valias->push_back(*UString::str_nostat); - U_RETURN(U_PLUGIN_HANDLER_PROCESSED | U_PLUGIN_HANDLER_GO_ON); + U_RETURN(U_PLUGIN_HANDLER_OK); # endif } @@ -101,10 +101,10 @@ int USoapPlugIn::handlerRequest() UHTTP::setResponse(true, *UString::str_ctype_soap, &body); } - U_RETURN(U_PLUGIN_HANDLER_PROCESSED | U_PLUGIN_HANDLER_GO_ON); + U_RETURN(U_PLUGIN_HANDLER_PROCESSED); } - U_RETURN(U_PLUGIN_HANDLER_GO_ON); + U_RETURN(U_PLUGIN_HANDLER_OK); } // DEBUG diff --git a/src/ulib/net/server/plugin/mod_socket.cpp b/src/ulib/net/server/plugin/mod_socket.cpp index 076bb7c6..bd16dc24 100644 --- a/src/ulib/net/server/plugin/mod_socket.cpp +++ b/src/ulib/net/server/plugin/mod_socket.cpp @@ -64,10 +64,10 @@ int UWebSocketPlugIn::handlerConfig(UFileConfig& cfg) UWebSocket::max_message_size = cfg.readLong(U_CONSTANT_TO_PARAM("MAX_MESSAGE_SIZE"), U_STRING_MAX_SIZE); - U_RETURN(U_PLUGIN_HANDLER_PROCESSED | U_PLUGIN_HANDLER_GO_ON); + U_RETURN(U_PLUGIN_HANDLER_PROCESSED); } - U_RETURN(U_PLUGIN_HANDLER_GO_ON); + U_RETURN(U_PLUGIN_HANDLER_OK); } int UWebSocketPlugIn::handlerRun() @@ -93,7 +93,7 @@ int UWebSocketPlugIn::handlerRun() if (command == U_NULLPTR) U_RETURN(U_PLUGIN_HANDLER_ERROR); } - U_RETURN(U_PLUGIN_HANDLER_PROCESSED | U_PLUGIN_HANDLER_GO_ON); + U_RETURN(U_PLUGIN_HANDLER_OK); } // Connection-wide hooks @@ -184,10 +184,10 @@ handle_data: UClientImage_Base::close(); } - U_RETURN(U_PLUGIN_HANDLER_PROCESSED | U_PLUGIN_HANDLER_GO_ON); + U_RETURN(U_PLUGIN_HANDLER_PROCESSED); } - U_RETURN(U_PLUGIN_HANDLER_GO_ON); + U_RETURN(U_PLUGIN_HANDLER_OK); } // DEBUG diff --git a/src/ulib/net/server/plugin/mod_ssi.cpp b/src/ulib/net/server/plugin/mod_ssi.cpp index 4dc1a726..193139ad 100644 --- a/src/ulib/net/server/plugin/mod_ssi.cpp +++ b/src/ulib/net/server/plugin/mod_ssi.cpp @@ -211,11 +211,11 @@ U_NO_EXPORT UString USSIPlugIn::getPathname(const UString& name, const UString& U_TRACE(0, "USSIPlugIn::getPathname(%V,%V,%V)", name.rep, value.rep, directory.rep) /** - * "include file" looks in the current directory (the name must not start with /, ., or ..) and "include virtual" starts - * in the root directory of your kiosk (so the name must start with "/".) You might want to make a "/includes" directory - * in your Kiosk and then you can say "include virtual=/includes/file.txt" from any page. The "virtual" and "file" - * parameters are also used with "fsize" and "flastmod". With either method, you can only reference files that are within - * your Kiosk directory (apart if "direct"...) + * 'include file' looks in the current directory (the name must not start with /, ., or ..) and 'include virtual' starts + * in the root directory of your kiosk (so the name must start with "/".) You might want to make a '/includes' directory + * in your Kiosk and then you can say 'include virtual=/includes/file.txt' from any page. The 'virtual' and 'file' + * parameters are also used with 'fsize' and 'flastmod'. With either method, you can only reference files that are within + * your Kiosk directory (apart if 'direct'...) */ UString pathname; @@ -938,12 +938,11 @@ int USSIPlugIn::handlerConfig(UFileConfig& cfg) { U_TRACE(0, "USSIPlugIn::handlerConfig(%p)", &cfg) - // -------------------------------------------------------------------------------------------------------------- + // ------------------------------------------------------------------------------------------------------------------------- // ENVIRONMENT path of file configuration environment for SSI // - // SSI_AUTOMATIC_ALIASING special SSI HTML file that is recognized automatically as alias of all uri request - // without suffix (generally cause navigation directory not working) - // -------------------------------------------------------------------------------------------------------------- + // SSI_AUTOMATIC_ALIASING special SSI HTML file that is recognized automatically as alias of all uri request without suffix + // ------------------------------------------------------------------------------------------------------------------------- if (cfg.loadTable()) { @@ -966,10 +965,10 @@ int USSIPlugIn::handlerConfig(UFileConfig& cfg) if (x) UHTTP::setGlobalAlias(x); // NB: automatic alias of all uri request without suffix... # endif - U_RETURN(U_PLUGIN_HANDLER_PROCESSED | U_PLUGIN_HANDLER_GO_ON); + U_RETURN(U_PLUGIN_HANDLER_PROCESSED); } - U_RETURN(U_PLUGIN_HANDLER_GO_ON); + U_RETURN(U_PLUGIN_HANDLER_OK); } int USSIPlugIn::handlerInit() @@ -984,7 +983,7 @@ int USSIPlugIn::handlerInit() U_NEW(UString, header, UString); U_NEW(UString, alternative_include, UString); - U_RETURN(U_PLUGIN_HANDLER_PROCESSED | U_PLUGIN_HANDLER_GO_ON); + U_RETURN(U_PLUGIN_HANDLER_OK); } // Connection-wide hooks @@ -993,11 +992,14 @@ int USSIPlugIn::handlerRequest() { U_TRACE_NO_PARAM(0, "USSIPlugIn::handlerRequest()") - U_INTERNAL_DUMP("uri = %.*S", U_HTTP_URI_TO_TRACE) + U_INTERNAL_DUMP("uri(%u) = %.*S query = %.*S", u_clientimage_info.http_info.uri_len, U_HTTP_URI_TO_TRACE, U_HTTP_QUERY_TO_TRACE) if (UClientImage_Base::isRequestNotFound() == false && UClientImage_Base::isRequestForbidden() == false) { + U_INTERNAL_ASSERT_MAJOR(U_http_info.uri_len, 1) + U_INTERNAL_ASSERT_EQUALS(U_HTTP_QUERY_STREQ("_nav_"), false) + bool bcache = UHTTP::file_data && u_is_ssi(UHTTP::file_data->mime_index); @@ -1042,7 +1044,7 @@ int USSIPlugIn::handlerRequest() UHTTP::setInternalError(); - U_RETURN(U_PLUGIN_HANDLER_GO_ON); + U_RETURN(U_PLUGIN_HANDLER_OK); } } else @@ -1131,10 +1133,10 @@ int USSIPlugIn::handlerRequest() UClientImage_Base::environment->setEmpty(); } - // U_RETURN(U_PLUGIN_HANDLER_PROCESSED | U_PLUGIN_HANDLER_GO_ON); + // U_RETURN(U_PLUGIN_HANDLER_PROCESSED); } - U_RETURN(U_PLUGIN_HANDLER_GO_ON); + U_RETURN(U_PLUGIN_HANDLER_OK); } // DEBUG diff --git a/src/ulib/net/server/plugin/mod_stream.cpp b/src/ulib/net/server/plugin/mod_stream.cpp index c753621f..2ad7d11c 100644 --- a/src/ulib/net/server/plugin/mod_stream.cpp +++ b/src/ulib/net/server/plugin/mod_stream.cpp @@ -93,10 +93,10 @@ int UStreamPlugIn::handlerConfig(UFileConfig& cfg) command = UServer_Base::loadConfigCommand(); - U_RETURN(U_PLUGIN_HANDLER_PROCESSED | U_PLUGIN_HANDLER_GO_ON); + U_RETURN(U_PLUGIN_HANDLER_PROCESSED); } - U_RETURN(U_PLUGIN_HANDLER_GO_ON); + U_RETURN(U_PLUGIN_HANDLER_OK); } int UStreamPlugIn::handlerInit() @@ -127,7 +127,7 @@ int UStreamPlugIn::handlerInit() (void) content_type->append(U_CONSTANT_TO_PARAM(U_CRLF)); - U_RETURN(U_PLUGIN_HANDLER_PROCESSED | U_PLUGIN_HANDLER_GO_ON); + U_RETURN(U_PLUGIN_HANDLER_OK); } int UStreamPlugIn::handlerRun() @@ -153,7 +153,7 @@ int UStreamPlugIn::handlerRun() UProcess::setProcessGroup(pid, pgid); */ - U_RETURN(U_PLUGIN_HANDLER_PROCESSED | U_PLUGIN_HANDLER_GO_ON); + U_RETURN(U_PLUGIN_HANDLER_OK); } if (proc.child()) @@ -175,7 +175,7 @@ int UStreamPlugIn::handlerRun() handlerForSigTERM(SIGTERM); } - U_RETURN(U_PLUGIN_HANDLER_PROCESSED | U_PLUGIN_HANDLER_GO_ON); + U_RETURN(U_PLUGIN_HANDLER_OK); } // Connection-wide hooks @@ -184,7 +184,7 @@ int UStreamPlugIn::handlerRequest() { U_TRACE_NO_PARAM(0, "UStreamPlugIn::handlerRequest()") - if (U_HTTP_URI_EQUAL(*uri_path) == false) U_RETURN(U_PLUGIN_HANDLER_GO_ON); + if (U_HTTP_URI_EQUAL(*uri_path) == false) U_RETURN(U_PLUGIN_HANDLER_OK); U_http_info.nResponseCode = HTTP_OK; @@ -205,7 +205,7 @@ int UStreamPlugIn::handlerRequest() rbuf->close(readd); - U_RETURN(U_PLUGIN_HANDLER_FINISHED); + U_RETURN(U_PLUGIN_HANDLER_OK); } UTimeVal to_sleep(0L, 10 * 1000L); @@ -224,7 +224,7 @@ int UStreamPlugIn::handlerRequest() } } - U_RETURN(U_PLUGIN_HANDLER_PROCESSED | U_PLUGIN_HANDLER_GO_ON); + U_RETURN(U_PLUGIN_HANDLER_PROCESSED); } // DEBUG diff --git a/src/ulib/net/server/plugin/mod_tsa.cpp b/src/ulib/net/server/plugin/mod_tsa.cpp index 02c7efc4..c715c478 100644 --- a/src/ulib/net/server/plugin/mod_tsa.cpp +++ b/src/ulib/net/server/plugin/mod_tsa.cpp @@ -49,10 +49,10 @@ int UTsaPlugIn::handlerConfig(UFileConfig& cfg) { command = UServer_Base::loadConfigCommand(); - U_RETURN(U_PLUGIN_HANDLER_PROCESSED | U_PLUGIN_HANDLER_GO_ON); + U_RETURN(U_PLUGIN_HANDLER_PROCESSED); } - U_RETURN(U_PLUGIN_HANDLER_GO_ON); + U_RETURN(U_PLUGIN_HANDLER_OK); } int UTsaPlugIn::handlerInit() @@ -71,7 +71,7 @@ int UTsaPlugIn::handlerInit() UHTTP::valias->push_back(*UString::str_tsa); UHTTP::valias->push_back(*UString::str_nostat); - U_RETURN(U_PLUGIN_HANDLER_PROCESSED | U_PLUGIN_HANDLER_GO_ON); + U_RETURN(U_PLUGIN_HANDLER_OK); # endif } @@ -105,10 +105,10 @@ int UTsaPlugIn::handlerRequest() UServer_Base::logCommandMsgError(command->getCommand(), true); # endif - U_RETURN(U_PLUGIN_HANDLER_PROCESSED | U_PLUGIN_HANDLER_GO_ON); + U_RETURN(U_PLUGIN_HANDLER_PROCESSED); } - U_RETURN(U_PLUGIN_HANDLER_GO_ON); + U_RETURN(U_PLUGIN_HANDLER_OK); } // DEBUG diff --git a/src/ulib/net/server/server.cpp b/src/ulib/net/server/server.cpp index f42badee..7c92b59b 100644 --- a/src/ulib/net/server/server.cpp +++ b/src/ulib/net/server/server.cpp @@ -2142,7 +2142,7 @@ void UServer_Base::loadConfigParam() UString plugin_dir = cfg->at(U_CONSTANT_TO_PARAM("PLUGIN_DIR")), plugin_list = cfg->at(U_CONSTANT_TO_PARAM("PLUGIN")); - if (loadPlugins(plugin_dir, plugin_list) == U_PLUGIN_HANDLER_ERROR) U_ERROR("Plugins stage load failed"); + if (loadPlugins(plugin_dir, plugin_list) != U_PLUGIN_HANDLER_FINISHED) U_ERROR("Plugins stage load failed"); } U_NO_EXPORT void UServer_Base::loadStaticLinkedModules(const char* name) @@ -2252,10 +2252,10 @@ int UServer_Base::loadPlugins(UString& plugin_dir, const UString& plugin_list) U_NEW(UVector, vplugin, UVector(10U)); U_NEW(UVector, vplugin_static, UVector(10U)); - uint32_t i, pos = 0; + int result; + uint32_t i, pos; UString item, _name; UServerPlugIn* _plugin; - int result = U_PLUGIN_HANDLER_ERROR; if (plugin_list) vplugin_size = vplugin_name->split(U_STRING_TO_PARAM(plugin_list)); // NB: we don't use split with substr() cause of dependency from config var PLUGIN... else @@ -2288,25 +2288,26 @@ int UServer_Base::loadPlugins(UString& plugin_dir, const UString& plugin_list) _plugin = vplugin_static->remove(pos); vplugin->push(_plugin); - - continue; } - - _name.setBuffer(32U); - - _name.snprintf(U_CONSTANT_TO_PARAM("server_plugin_%v"), item.rep); - - _plugin = UPlugIn::create(U_STRING_TO_PARAM(_name)); - -# ifndef U_LOG_DISABLE - if (isLog()) + else { - if (_plugin) log->log(U_CONSTANT_TO_PARAM( "Load phase of plugin %V success"), item.rep); - else log->log(U_CONSTANT_TO_PARAM("WARNING: Load phase of plugin %V failed"), item.rep); - } -# endif + _name.setBuffer(32U); - if (_plugin) vplugin->push(_plugin); + _name.snprintf(U_CONSTANT_TO_PARAM("server_plugin_%v"), item.rep); + + _plugin = UPlugIn::create(U_STRING_TO_PARAM(_name)); + + if (_plugin) + { + vplugin->push(_plugin); + + U_SRV_LOG("Load phase of plugin %V success", item.rep); + } + else + { + U_SRV_LOG("WARNING: Load phase of plugin %V failed", item.rep); + } + } } U_INTERNAL_ASSERT_MAJOR(vplugin_size, 0) @@ -2328,127 +2329,123 @@ int UServer_Base::loadPlugins(UString& plugin_dir, const UString& plugin_list) { cfg->table.clear(); - _plugin = vplugin->at(i); - - result = _plugin->handlerConfig(*cfg); - -# ifndef U_LOG_DISABLE - if (isLog()) - { - if ((result & (U_PLUGIN_HANDLER_ERROR | U_PLUGIN_HANDLER_PROCESSED)) != 0) - { - if ((result & U_PLUGIN_HANDLER_ERROR) == 0) log->log(U_CONSTANT_TO_PARAM( "Configuration phase of plugin %V success"), item.rep); - else log->log(U_CONSTANT_TO_PARAM("WARNING: Configuration phase of plugin %V failed"), item.rep); - } - } -# endif + result = vplugin->at(i)->handlerConfig(*cfg); cfg->reset(); - if ((result & U_PLUGIN_HANDLER_GO_ON) == 0) U_RETURN(result); - } + if (result) + { + if (result == U_PLUGIN_HANDLER_ERROR) + { + U_SRV_LOG("WARNING: Configuration phase of plugin %V failed", item.rep); - if (i == 0) U_RETURN(U_PLUGIN_HANDLER_FINISHED); + U_RETURN(U_PLUGIN_HANDLER_ERROR); + } + + U_SRV_LOG("Configuration phase of plugin %V success", item.rep); + } + } } - while (true); + while (i > 0); } U_RETURN(U_PLUGIN_HANDLER_FINISHED); } -// manage plugin handler hooks... - #ifdef U_LOG_DISABLE -# define U_PLUGIN_HANDLER(xxx) \ -int UServer_Base::pluginsHandler##xxx() \ -{ \ - U_TRACE_NO_PARAM(0, "UServer_Base::pluginsHandler"#xxx"()") \ - \ - U_INTERNAL_ASSERT_POINTER(vplugin) \ - U_INTERNAL_ASSERT_MAJOR(vplugin_size, 0) \ - \ - int result; \ - uint32_t i = 0; \ - \ - do { \ - result = vplugin->at(i)->handler##xxx(); \ - \ - if ((result & U_PLUGIN_HANDLER_GO_ON) == 0) U_RETURN(result); \ - } \ - while (++i < vplugin_size); \ - \ - U_RETURN(U_PLUGIN_HANDLER_FINISHED); \ +void UServer_Base::pluginsHandlerRequest() +{ + U_TRACE_NO_PARAM(0, "UServer_Base::pluginsHandlerRequest()") + + U_INTERNAL_ASSERT_POINTER(vplugin) + U_INTERNAL_ASSERT_MAJOR(vplugin_size, 0) + + int result; + + for (uint32_t i = 0; i < vplugin_size; ++i) + { + if ((result = vplugin->at(i)->handlerRequest())) + { + if (result == U_PLUGIN_HANDLER_ERROR) + { + U_ClientImage_state = U_PLUGIN_HANDLER_ERROR; + + return; + } + + U_INTERNAL_ASSERT_EQUALS(result, U_PLUGIN_HANDLER_PROCESSED) + + UClientImage_Base::setRequestProcessed(); + } + } } #else -# define U_PLUGIN_HANDLER(xxx) \ -int UServer_Base::pluginsHandler##xxx() \ -{ \ - U_TRACE_NO_PARAM(0, "UServer_Base::pluginsHandler"#xxx"()") \ - \ - U_INTERNAL_ASSERT_POINTER(vplugin) \ - U_INTERNAL_ASSERT_MAJOR(vplugin_size, 0) \ - \ - uint32_t i = 0; \ - int result, ilog; \ - UServerPlugIn* _plugin; \ - \ - do { \ - _plugin = vplugin->at(i); \ - \ - if (isLog() == false) result = _plugin->handler##xxx(); \ - else \ - { \ - UString name = vplugin_name->at(i); \ - \ - (void) u__snprintf(mod_name[0], sizeof(mod_name[0]), U_CONSTANT_TO_PARAM("[%v] "), name.rep); \ - \ - result = _plugin->handler##xxx(); \ - \ - if ((result & (U_PLUGIN_HANDLER_ERROR | \ - U_PLUGIN_HANDLER_PROCESSED)) != 0) \ - { \ - ilog = 0; \ - \ - if ((result & U_PLUGIN_HANDLER_ERROR) != 0) \ - { \ - if ((result & U_PLUGIN_HANDLER_FINISHED) == 0) ilog = 2; \ - } \ - else \ - { \ - if ((result & U_PLUGIN_HANDLER_PROCESSED) != 0 && \ - U_ClientImage_parallelization != U_PARALLELIZATION_PARENT) \ - { \ - ilog = 1; \ - } \ - } \ - \ - if (ilog) \ - { \ - if (ilog == 1) \ - { \ - log->log(U_CONSTANT_TO_PARAM(#xxx" phase of plugin %V success"), name.rep); \ - } \ - else \ - { \ - log->log(U_CONSTANT_TO_PARAM("WARNING: "#xxx" phase of plugin %V failed"), name.rep); \ - } \ - } \ - } \ - \ - mod_name[0][0] = '\0'; \ - } \ - \ - if ((result & U_PLUGIN_HANDLER_GO_ON) == 0) U_RETURN(result); \ - } \ - while (++i < vplugin_size); \ - \ - U_RETURN(U_PLUGIN_HANDLER_FINISHED); \ +void UServer_Base::pluginsHandlerRequest() +{ + U_TRACE_NO_PARAM(0, "UServer_Base::pluginsHandlerRequest()") + + U_INTERNAL_ASSERT_POINTER(vplugin) + U_INTERNAL_ASSERT_MAJOR(vplugin_size, 0) + + int result; + UString name; + UServerPlugIn* _plugin; + + for (uint32_t i = 0; i < vplugin_size; ++i) + { + _plugin = vplugin->at(i); + + if (isLog() == false) + { + if ((result = _plugin->handlerRequest())) + { + if (result == U_PLUGIN_HANDLER_ERROR) + { + U_ClientImage_state = U_PLUGIN_HANDLER_ERROR; + + return; + } + + U_INTERNAL_ASSERT_EQUALS(result, U_PLUGIN_HANDLER_PROCESSED) + + UClientImage_Base::setRequestProcessed(); + } + + continue; + } + + name = vplugin_name->at(i); + + (void) u__snprintf(mod_name[0], sizeof(mod_name[0]), U_CONSTANT_TO_PARAM("[%v] "), name.rep); + + result = _plugin->handlerRequest(); + + mod_name[0][0] = '\0'; + + if (result) + { + if (result == U_PLUGIN_HANDLER_ERROR) + { + U_ClientImage_state = U_PLUGIN_HANDLER_ERROR; + + log->log(U_CONSTANT_TO_PARAM("WARNING: Request phase of plugin %V failed"), name.rep); + + return; + } + + U_INTERNAL_ASSERT_EQUALS(result, U_PLUGIN_HANDLER_PROCESSED) + + if (U_ClientImage_parallelization != U_PARALLELIZATION_PARENT) + { + UClientImage_Base::setRequestProcessed(); + + log->log(U_CONSTANT_TO_PARAM("Request phase of plugin %V success"), name.rep); + } + } + } } #endif -// Connection-wide hooks -U_PLUGIN_HANDLER(Request) - // NB: we call the various handlerXXX() in reverse order respect to the content of config var PLUGIN... #ifdef U_LOG_DISABLE @@ -2460,17 +2457,17 @@ int UServer_Base::pluginsHandler##xxx() U_INTERNAL_ASSERT_POINTER(vplugin) \ U_INTERNAL_ASSERT_MAJOR(vplugin_size, 0) \ \ - int result; \ uint32_t i = vplugin_size; \ \ do { \ - result = vplugin->at(--i)->handler##xxx(); \ - \ - if ((result & U_PLUGIN_HANDLER_GO_ON) == 0) U_RETURN(result); \ - \ - if (i == 0) U_RETURN(U_PLUGIN_HANDLER_FINISHED); \ + if (vplugin->at(--i)->handler##xxx() == U_PLUGIN_HANDLER_ERROR) \ + { \ + U_RETURN(U_PLUGIN_HANDLER_ERROR); \ + } \ } \ - while (true); \ + while (i > 0); \ + \ + U_RETURN(U_PLUGIN_HANDLER_FINISHED); \ } #else # define U_PLUGIN_HANDLER_REVERSE(xxx) \ @@ -2481,61 +2478,57 @@ int UServer_Base::pluginsHandler##xxx() U_INTERNAL_ASSERT_POINTER(vplugin) \ U_INTERNAL_ASSERT_MAJOR(vplugin_size, 0) \ \ - int result, ilog; \ + int result; \ + UString name; \ UServerPlugIn* _plugin; \ uint32_t i = vplugin_size; \ \ do { \ _plugin = vplugin->at(--i); \ \ - if (isLog() == false) result = _plugin->handler##xxx(); \ - else \ + if (isLog() == false) \ { \ - UString name = vplugin_name->at(i); \ - \ - (void) u__snprintf(mod_name[0], sizeof(mod_name[0]), U_CONSTANT_TO_PARAM("[%v] "), name.rep); \ - \ - result = _plugin->handler##xxx(); \ - \ - if ((result & (U_PLUGIN_HANDLER_ERROR | \ - U_PLUGIN_HANDLER_PROCESSED)) != 0) \ + if ((result = _plugin->handler##xxx())) \ { \ - ilog = 0; \ + if (result == U_PLUGIN_HANDLER_ERROR) U_RETURN(U_PLUGIN_HANDLER_ERROR);\ \ - if ((result & U_PLUGIN_HANDLER_ERROR) != 0) \ - { \ - if ((result & U_PLUGIN_HANDLER_FINISHED) != 0) ilog = 2; \ - } \ - else \ - { \ - if ((result & U_PLUGIN_HANDLER_PROCESSED) != 0 && \ - U_ClientImage_parallelization != U_PARALLELIZATION_PARENT) \ - { \ - ilog = 1; \ - } \ - } \ - \ - if (ilog) \ - { \ - if (ilog == 1) \ - { \ - log->log(U_CONSTANT_TO_PARAM(#xxx" phase of plugin %V success"), name.rep); \ - } \ - else \ - { \ - log->log(U_CONSTANT_TO_PARAM("WARNING: "#xxx" phase of plugin %V failed"), name.rep); \ - } \ - } \ + U_INTERNAL_ASSERT_EQUALS(result, U_PLUGIN_HANDLER_PROCESSED) \ } \ \ - mod_name[0][0] = '\0'; \ + continue; \ } \ \ - if ((result & U_PLUGIN_HANDLER_GO_ON) == 0) U_RETURN(result); \ + name = vplugin_name->at(i); \ \ - if (i == 0) U_RETURN(U_PLUGIN_HANDLER_FINISHED); \ + (void) u__snprintf(mod_name[0], sizeof(mod_name[0]), \ + U_CONSTANT_TO_PARAM("[%v] "), name.rep); \ + \ + result = _plugin->handler##xxx(); \ + \ + mod_name[0][0] = '\0'; \ + \ + if (result) \ + { \ + if (result == U_PLUGIN_HANDLER_ERROR) \ + { \ + log->log(U_CONSTANT_TO_PARAM("WARNING: "#xxx" phase of plugin " \ + "%V failed"), name.rep); \ + \ + U_RETURN(U_PLUGIN_HANDLER_ERROR); \ + } \ + \ + U_INTERNAL_ASSERT_EQUALS(result, U_PLUGIN_HANDLER_PROCESSED) \ + \ + if (U_ClientImage_parallelization != U_PARALLELIZATION_PARENT) \ + { \ + log->log(U_CONSTANT_TO_PARAM(#xxx" phase of plugin %V success"), \ + name.rep); \ + } \ + } \ } \ - while (true); \ + while (i > 0); \ + \ + U_RETURN(U_PLUGIN_HANDLER_FINISHED); \ } #endif @@ -2668,7 +2661,7 @@ void UServer_Base::init() socket->cLocalAddress.setLocalHost(UClientImage_Base::bIPv6); - U_WARNING("IP_ADDRESS from system interface fail, we try using localhost"); + U_WARNING("getting IP_ADDRESS from system interface fail, we try using localhost"); } else { diff --git a/src/ulib/notifier.cpp b/src/ulib/notifier.cpp index 2d857973..b4f334ec 100644 --- a/src/ulib/notifier.cpp +++ b/src/ulib/notifier.cpp @@ -373,6 +373,8 @@ int UNotifier::waitForEvent(int fd_max, fd_set* read_set, fd_set* write_set, UEv { U_TRACE(1, "UNotifier::waitForEvent(%d,%p,%p,%p)", fd_max, read_set, write_set, ptimeout) + U_INTERNAL_ASSERT_DIFFERS(U_ClientImage_parallelization, U_PARALLELIZATION_CHILD) + int result; #ifdef HAVE_EPOLL_WAIT @@ -508,6 +510,7 @@ loop0: } # else int i = 0; + bool bdelete; pevents = events; # ifdef U_EPOLLET_POSTPONE_STRATEGY bool bloop1 = false; @@ -545,9 +548,13 @@ loop0: * EPOLLIN EPOLLRDHUP */ - if (UNLIKELY((pevents->events & (EPOLLERR | EPOLLHUP)) != 0) || - (LIKELY((pevents->events & (EPOLLIN | EPOLLRDHUP)) != 0) ? handler_event->handlerRead() - : handler_event->handlerWrite()) == U_NOTIFIER_DELETE) + bdelete = UNLIKELY((pevents->events & (EPOLLERR | EPOLLHUP)) != 0) || + LIKELY((pevents->events & (EPOLLIN | EPOLLRDHUP)) != 0 ? handler_event->handlerRead() + : handler_event->handlerWrite() == U_NOTIFIER_DELETE); + + U_INTERNAL_DUMP("bdelete = %b", bdelete) + + if (bdelete) { handlerDelete(handler_event); @@ -555,7 +562,7 @@ loop0: if (bepollet) pevents->events = 0; # endif } -# if defined(U_EPOLLET_POSTPONE_STRATEGY) +# if defined(U_EPOLLET_POSTPONE_STRATEGY) else if (bepollet) { if (U_ClientImage_state != U_PLUGIN_HANDLER_AGAIN && @@ -568,7 +575,7 @@ loop0: pevents->events = 0; } } -# endif +# endif } if (++i < nfd_ready) @@ -858,11 +865,12 @@ void UNotifier::insert(UEventFd* item, int op) #endif } -void UNotifier::modify(UEventFd* item) +bool UNotifier::modify(UEventFd* item) { U_TRACE(0, "UNotifier::modify(%p)", item) U_INTERNAL_ASSERT_POINTER(item) + U_INTERNAL_ASSERT_DIFFERS(U_ClientImage_parallelization, U_PARALLELIZATION_CHILD) int fd = item->fd; @@ -886,7 +894,7 @@ void UNotifier::modify(UEventFd* item) struct epoll_event _events = { item->op_mask, { item } }; - (void) U_SYSCALL(epoll_ctl, "%d,%d,%d,%p", epollfd, EPOLL_CTL_MOD, fd, &_events); + if (U_SYSCALL(epoll_ctl, "%d,%d,%d,%p", epollfd, EPOLL_CTL_MOD, fd, &_events)) U_RETURN(false); #elif defined(HAVE_KQUEUE) U_INTERNAL_ASSERT_MAJOR(kq, 0) U_INTERNAL_ASSERT_MINOR(nkqevents, max_connection) @@ -950,6 +958,8 @@ void UNotifier::modify(UEventFd* item) U_INTERNAL_ASSERT(fd_read_cnt >= 0) U_INTERNAL_ASSERT(fd_write_cnt >= 0) #endif + + U_RETURN(true); } void UNotifier::handlerDelete(int fd, int mask) @@ -957,6 +967,7 @@ void UNotifier::handlerDelete(int fd, int mask) U_TRACE(0, "UNotifier::handlerDelete(%d,%B)", fd, mask) U_INTERNAL_ASSERT_MAJOR(fd, 0) + U_INTERNAL_ASSERT_DIFFERS(U_ClientImage_parallelization, U_PARALLELIZATION_CHILD) if (fd < (int32_t)lo_map_fd_len) lo_map_fd[fd] = U_NULLPTR; else diff --git a/src/ulib/utility/dir_walk.cpp b/src/ulib/utility/dir_walk.cpp index 26d180a3..5a2446e7 100644 --- a/src/ulib/utility/dir_walk.cpp +++ b/src/ulib/utility/dir_walk.cpp @@ -91,13 +91,13 @@ void UDirWalk::ctor(const UString* dir, const char* _filter, uint32_t _filter_le } } -bool UDirWalk::setDirectory(const UString& dir, const char* _filter, uint32_t _filter_len, int _filter_flags) +bool UDirWalk::setDirectory(const char* dir, uint32_t dlen, const char* _filter, uint32_t _filter_len, int _filter_flags) { - U_TRACE(0, "UDirWalk::setDirectory(%V,%.*S,%u,%d)", dir.rep, _filter_len, _filter, _filter_len, _filter_flags) + U_TRACE(0, "UDirWalk::setDirectory(%.*S,%u,%.*S,%u,%d)", dlen, dir, dlen, _filter_len, _filter, _filter_len, _filter_flags) - pthis->pathlen = dir.size(); + pthis->pathlen = dlen; - const char* pdir = u_getPathRelativ(dir.data(), &(pthis->pathlen)); + const char* pdir = u_getPathRelativ(dir, &(pthis->pathlen)); U_INTERNAL_ASSERT_MAJOR(pthis->pathlen, 0) diff --git a/src/ulib/utility/uhttp.cpp b/src/ulib/utility/uhttp.cpp index 856ea7c2..9445ba72 100644 --- a/src/ulib/utility/uhttp.cpp +++ b/src/ulib/utility/uhttp.cpp @@ -574,9 +574,9 @@ void UHTTP::in_READ() inotify_dir = U_NULLPTR; inotify_file_data = U_NULLPTR; } - + if (*inotify_name != '.' || - u_isSuffixSwap(inotify_name + len - U_CONSTANT_SIZE(".swp")) == false) // NB: vi tmp... + (name = inotify_name + len - sizeof(".swp"), name[0] != '.' || u_isSuffixSwap(name) == false)) // NB: vi tmp... { if (binotify_path == false) cache_file->callForAllEntry(getInotifyPathDirectory); @@ -1116,8 +1116,8 @@ void UHTTP::init() } else { - if (cache_avoid_mask == U_NULLPTR) UDirWalk::setDirectory(*UString::str_point); - else UDirWalk::setDirectory(*UString::str_point, *cache_avoid_mask, FNM_INVERT); + if (cache_avoid_mask == U_NULLPTR) (void) UDirWalk::setDirectory(*UString::str_point); + else (void) UDirWalk::setDirectory(*UString::str_point, *cache_avoid_mask, FNM_INVERT); UDirWalk::setFollowLinks(true); UDirWalk::setRecurseSubDirs(true, true); @@ -3797,15 +3797,6 @@ next2: if (U_ClientImage_advise_for_parallelization == 2) U_RETURN(true); # endif - if (UClientImage_Base::csfd > 0) - { - U_INTERNAL_DUMP("U_http_sendfile = %b", U_http_sendfile) - - U_INTERNAL_ASSERT(U_http_sendfile) - - UClientImage_Base::setSendfile(UClientImage_Base::csfd, range_start, range_size); - } - UClientImage_Base::setHeaderForResponse(6+29+2+12+2); // Date: Wed, 20 Jun 2012 11:43:17 GMT\r\nServer: ULib\r\n #ifndef U_LOG_DISABLE @@ -3884,17 +3875,29 @@ bool UHTTP::isValidation() U_RETURN(false); } - if (isUriRequestProtected() && // check if the uri requested is protected - checkUriProtected() == false) - { - U_RETURN(false); - } + if (checkUriProtected() == false) U_RETURN(false); // check if the uri requested is protected #endif U_RETURN(true); } #endif +U_NO_EXPORT void UHTTP::setSendfile(int fd, uint32_t start, uint32_t count) +{ + U_TRACE(0, "UHTTP::setSendfile(%d,%u,%u)", fd, start, count) + + UClientImage_Base::setSendfile(fd, start, count); + + if ((count - start) > (6 * U_1M)) + { + if (UServer_Base::startParallelization()) return; // parent + + UClientImage_Base::setCloseConnection(); + + handlerResponse(); + } +} + int UHTTP::handlerREAD() { U_TRACE_NO_PARAM(0, "UHTTP::handlerREAD()") @@ -3937,7 +3940,7 @@ int UHTTP::handlerREAD() } # endif - if (U_ClientImage_data_missing) U_RETURN(U_PLUGIN_HANDLER_FINISHED); + if (U_ClientImage_data_missing) U_RETURN(U_PLUGIN_HANDLER_OK); if (UNLIKELY(UServer_Base::csocket->isClosed())) U_RETURN(U_PLUGIN_HANDLER_ERROR); @@ -3970,14 +3973,14 @@ int UHTTP::handlerREAD() { setBadRequest(); - U_RETURN(U_PLUGIN_HANDLER_FINISHED); + U_RETURN(U_PLUGIN_HANDLER_OK); } setResponse(); UClientImage_Base::resetPipelineAndSetCloseConnection(); - U_RETURN(U_PLUGIN_HANDLER_FINISHED); + U_RETURN(U_PLUGIN_HANDLER_OK); } U_INTERNAL_ASSERT_DIFFERS(U_http_method_type, 0) @@ -3997,7 +4000,7 @@ int UHTTP::handlerREAD() } # endif - if (U_ClientImage_data_missing) U_RETURN(U_PLUGIN_HANDLER_FINISHED); + if (U_ClientImage_data_missing) U_RETURN(U_PLUGIN_HANDLER_OK); } U_INTERNAL_DUMP("U_HTTP_HOST(%u) = %.*S", U_http_host_len, U_HTTP_HOST_TO_TRACE) @@ -4008,7 +4011,7 @@ int UHTTP::handlerREAD() { setBadRequest(); - U_RETURN(U_PLUGIN_HANDLER_FINISHED); + U_RETURN(U_PLUGIN_HANDLER_OK); } } #ifndef U_SERVER_CAPTIVE_PORTAL @@ -4020,7 +4023,7 @@ int UHTTP::handlerREAD() U_SRV_LOG("WARNING: unrecognized header in request: %.*S", U_HTTP_VHOST_TO_TRACE); - U_RETURN(U_PLUGIN_HANDLER_FINISHED); + U_RETURN(U_PLUGIN_HANDLER_OK); } #endif @@ -4047,7 +4050,7 @@ int UHTTP::handlerREAD() "NOTIFY, MSEARCH, SUBSCRIBE, UNSUBSCRIBE" // upnp "\r\nContent-Length: 0\r\n\r\n")); - U_RETURN(U_PLUGIN_HANDLER_FINISHED); + U_RETURN(U_PLUGIN_HANDLER_OK); } UClientImage_Base::size_request = (U_http_info.endHeader ? U_http_info.endHeader @@ -4088,7 +4091,7 @@ int UHTTP::handlerREAD() if (UClientImage_Base::wbuffer->empty()) setBadRequest(); - U_RETURN(U_PLUGIN_HANDLER_FINISHED); + U_RETURN(U_PLUGIN_HANDLER_OK); } UClientImage_Base::size_request += U_http_info.clength; @@ -4112,24 +4115,17 @@ int UHTTP::handlerREAD() U_SRV_LOG("we strike back sending gzip bomb...", 0); - if (UServer_Base::startParallelization()) U_RETURN(U_PLUGIN_HANDLER_FINISHED); // parent - UClientImage_Base::body->clear(); - UClientImage_Base::setCloseConnection(); - - U_http_flag |= HTTP_IS_RESPONSE_GZIP | HTTP_IS_SENDFILE; - U_ClientImage_request |= UClientImage_Base::ALREADY_PROCESSED | UClientImage_Base::NO_CACHE; - - UClientImage_Base::setSendfile(file_gzip_bomb->fd, 0, file_gzip_bomb->size); - U_http_info.nResponseCode = HTTP_OK; + U_http_flag |= HTTP_IS_RESPONSE_GZIP; + *ext = file_gzip_bomb->array->operator[](0); - handlerResponse(); + setSendfile(file_gzip_bomb->fd, 0, file_gzip_bomb->size); - U_RETURN(U_PLUGIN_HANDLER_FINISHED); + U_RETURN(U_PLUGIN_HANDLER_OK); } UClientImage_Base::abortive_close(); @@ -4230,11 +4226,15 @@ int UHTTP::manageRequest() // manage global alias - U_INTERNAL_DUMP("global_alias = %p UClientImage_Base::request_uri(%u) = %V", - global_alias, UClientImage_Base::request_uri->size(), UClientImage_Base::request_uri->rep) + U_INTERNAL_DUMP("global_alias = %p UClientImage_Base::request_uri(%u) = %V uri(%u) = %.*S query = %.*S", + global_alias, UClientImage_Base::request_uri->size(), UClientImage_Base::request_uri->rep, + u_clientimage_info.http_info.uri_len, U_HTTP_URI_TO_TRACE, U_HTTP_QUERY_TO_TRACE) - if (global_alias && - UClientImage_Base::request_uri->empty() && + if (global_alias && + UClientImage_Base::request_uri->empty() && // NB: this is exclusive with alias... + u_clientimage_info.http_info.uri_len > 1 && + u_clientimage_info.http_info.uri[u_clientimage_info.http_info.uri_len-1] != '/' && // directory request + U_HTTP_QUERY_STREQ("_nav_") == false && u_getsuffix(U_HTTP_URI_TO_PARAM) == U_NULLPTR) { (void) UClientImage_Base::request_uri->assign(U_HTTP_URI_TO_PARAM); @@ -4278,7 +4278,7 @@ set_uri: U_http_info.uri = alias->data(); { setServiceUnavailable(); - U_RETURN(U_PLUGIN_HANDLER_FINISHED); + U_RETURN(U_PLUGIN_HANDLER_OK); } #endif @@ -4316,7 +4316,7 @@ set_uri: U_http_info.uri = alias->data(); UClientImage_Base::setRequestNeedProcessing(); - U_RETURN(U_PLUGIN_HANDLER_FINISHED); + U_RETURN(U_PLUGIN_HANDLER_OK); } } @@ -4428,7 +4428,7 @@ file_in_cache: # endif # if defined(U_HTTP_STRICT_TRANSPORT_SECURITY) || defined(USE_LIBSSL) - if (isValidation() == false) U_RETURN(U_PLUGIN_HANDLER_FINISHED); + if (isValidation() == false) U_RETURN(U_PLUGIN_HANDLER_OK); # endif mime_index = file_data->mime_index; @@ -4479,13 +4479,13 @@ file_in_cache: U_RESET_MODULE_NAME; - U_RETURN(U_PLUGIN_HANDLER_FINISHED); + U_RETURN(U_PLUGIN_HANDLER_OK); } # ifndef U_COVERITY_FALSE_POSITIVE // UNREACHABLE if (U_ClientImage_state != U_PLUGIN_HANDLER_ERROR) goto from_cache; - U_RETURN(U_PLUGIN_HANDLER_FINISHED); + U_RETURN(U_PLUGIN_HANDLER_OK); # endif } @@ -4501,7 +4501,7 @@ file_in_cache: UClientImage_Base::environment->setEmpty(); - U_RETURN(U_PLUGIN_HANDLER_FINISHED); + U_RETURN(U_PLUGIN_HANDLER_OK); } U_INTERNAL_DUMP("U_http_is_request_nostat = %b query(%u) = %.*S", U_http_is_request_nostat, U_http_info.query_len, U_HTTP_QUERY_TO_TRACE) @@ -4511,7 +4511,7 @@ file_in_cache: U_HTTP_QUERY_STREQ("_nav_") == false && (checkForPathName(), runDynamicPage())) { - U_RETURN(U_PLUGIN_HANDLER_FINISHED); + U_RETURN(U_PLUGIN_HANDLER_OK); } # endif } @@ -4563,7 +4563,7 @@ file_exist_and_need_to_be_processed: // NB: if we can't service the content of f (UClientImage_Base::isRequestAlreadyProcessed() || // => 4) isValidation() == false)) { - U_RETURN(U_PLUGIN_HANDLER_FINISHED); + U_RETURN(U_PLUGIN_HANDLER_OK); } #endif @@ -4576,7 +4576,7 @@ file_exist_and_need_to_be_processed: // NB: if we can't service the content of f { setBadRequest(); - U_RETURN(U_PLUGIN_HANDLER_FINISHED); + U_RETURN(U_PLUGIN_HANDLER_OK); } UClientImage_Base::setRequestNoCache(); @@ -4609,7 +4609,7 @@ end: if (UClientImage_Base::isRequestNeedProcessing()) { - U_ClientImage_state = UClientImage_Base::callerHandlerRequest(); + UClientImage_Base::callerHandlerRequest(); if (UServer_Base::csocket->isClosed()) U_RETURN(U_PLUGIN_HANDLER_ERROR); } @@ -4619,7 +4619,7 @@ end: } #endif - U_RETURN(U_PLUGIN_HANDLER_FINISHED); + U_RETURN(U_PLUGIN_HANDLER_OK); } //#define TEST_LOAD_BALANCE_ON_LOCALHOST @@ -4770,7 +4770,7 @@ U_NO_EXPORT inline void UHTTP::resetFileCache() file_data->fd = -1; } -int UHTTP::processRequest() +void UHTTP::processRequest() { U_TRACE_NO_PARAM(1, "UHTTP::processRequest()") @@ -4783,7 +4783,7 @@ int UHTTP::processRequest() if (UClientImage_Base::isRequestNotFound()) setNotFound(); else setBadRequest(); - U_RETURN(U_PLUGIN_HANDLER_FINISHED); + return; } if (isPUT()) @@ -4862,7 +4862,7 @@ int UHTTP::processRequest() U_INTERNAL_DUMP("U_http_method_not_implemented = %b", U_http_method_not_implemented) - if (UServer_Base::vplugin_name->last() != *UString::str_http) U_RETURN(U_PLUGIN_HANDLER_GO_ON); // NB: there are other plugin after this (http)... + if (UServer_Base::vplugin_name->last() != *UString::str_http) return; // NB: there are other plugin after this (http)... setMethodNotImplemented(); @@ -4912,7 +4912,7 @@ int UHTTP::processRequest() { setForbidden(); // set forbidden error response... - U_RETURN(U_PLUGIN_HANDLER_FINISHED); + return; } # endif @@ -4947,7 +4947,7 @@ int UHTTP::processRequest() goto end; # endif - U_RETURN(U_PLUGIN_HANDLER_FINISHED); + return; } file->setPath(*pathname); @@ -4976,7 +4976,7 @@ int UHTTP::processRequest() UClientImage_Base::setRequestNoCache(); - U_RETURN(U_PLUGIN_HANDLER_FINISHED); + return; } # endif @@ -4988,7 +4988,7 @@ int UHTTP::processRequest() // check if it's OK to do directory listing via authentication (digest|basic) - if (processAuthorization() == false) U_RETURN(U_PLUGIN_HANDLER_FINISHED); + if (processAuthorization() == false) return; *UClientImage_Base::body = getHTMLDirectoryList(); @@ -5056,7 +5056,7 @@ check_file: // now we check the file... else if (errno == EPERM) setForbidden(); else setServiceUnavailable(); - U_RETURN(U_PLUGIN_HANDLER_FINISHED); + return; next: U_INTERNAL_DUMP("file_data->fd = %d file_data->size = %u file_data->mode = %d file_data->mtime = %ld", @@ -5096,7 +5096,7 @@ next: { if (U_http_is_nocache_file) resetFileCache(); - U_RETURN(U_PLUGIN_HANDLER_FINISHED); + return; } if (U_http_is_nocache_file == false) goto end; @@ -5107,8 +5107,6 @@ err: resetFileCache(); end: handlerResponse(); - - U_RETURN(U_PLUGIN_HANDLER_FINISHED); } void UHTTP::setEndRequestProcessing() @@ -5224,14 +5222,6 @@ void UHTTP::setEndRequestProcessing() U_IS_HTTP_SUCCESS(U_http_info.nResponseCode)) { UClientImage_Base::setRequestToCache(); - - U_INTERNAL_DUMP("file_data = %p U_http_sendfile = %b", file_data, U_http_sendfile) - - if (file_data && - U_http_sendfile) - { - UClientImage_Base::csfd = file_data->fd; - } } #endif } @@ -6009,15 +5999,14 @@ U_NO_EXPORT UString UHTTP::getHTMLDirectoryList() bool is_dir; UDirWalk dirwalk; - uint32_t i, pos, n; UVector vec(2048); UString buffer(4000U), item, size, basename, entry(4000U), value_encoded(U_CAPACITY), readme_txt; - int32_t len = file->getPathRelativLen(); + uint32_t len = file->getPathRelativLen(); const char* ptr = file->getPathRelativ(); - bool broot = (len == 1 && ptr[0] == '/'); - if (broot) + if (len == 1 && + ptr[0] == '/') { (void) buffer.assign(U_CONSTANT_TO_PARAM( "Index of /" @@ -6033,7 +6022,7 @@ U_NO_EXPORT UString UHTTP::getHTMLDirectoryList() "Index of %.*s" "

Index of directory: %.*s


" "" - "" + "" // '/../?_nav_' don't work "" "" ""), len, ptr, len, ptr, len, ptr); @@ -6041,11 +6030,7 @@ U_NO_EXPORT UString UHTTP::getHTMLDirectoryList() if (dirwalk.setDirectory(U_FILE_TO_STRING(*file)) == false) goto end; } - n = dirwalk.walk(vec, U_ALPHABETIC_SORT); - - pos = buffer.size(); - - for (i = 0; i < n; ++i) + for (uint32_t i = 0, n = dirwalk.walk(vec, U_ALPHABETIC_SORT), pos = buffer.size(); i < n; ++i) { item = vec[i]; file_data = (*cache_file)[item]; @@ -6096,7 +6081,6 @@ U_NO_EXPORT UString UHTTP::getHTMLDirectoryList() } } -end: (void) buffer.append(U_CONSTANT_TO_PARAM("
Up one level Up one level

")); if (readme_txt) @@ -6106,6 +6090,7 @@ end: (void) buffer.append(U_CONSTANT_TO_PARAM("
")); } +end: (void) buffer.append(U_CONSTANT_TO_PARAM("
ULib Server
")); U_INTERNAL_DUMP("buffer(%u) = %V", buffer.size(), buffer.rep) @@ -7060,23 +7045,37 @@ no_response: handlerResponse(); } -U_NO_EXPORT bool UHTTP::processAuthorization() +U_NO_EXPORT bool UHTTP::processAuthorization(const char* request, uint32_t sz, const char* pattern, uint32_t len) { - U_TRACE_NO_PARAM(0, "UHTTP::processAuthorization()") + U_TRACE(0, "UHTTP::processAuthorization(%.*S,%u,%.*S,%u)", sz, request, sz, len, pattern, len) + + if (sz == 0) request = UClientImage_Base::getRequestUri(sz); UTokenizer t; const char* ptr; - uint32_t sz, pos = 0; + uint32_t pos = 0; bool result = false, bpass = false; UString buffer(100U), fpasswd, content, tmp, user(100U); - const char* request = UClientImage_Base::getRequestUri(sz); - const char* uri_suffix = u_getsuffix(request, sz); - if (uri_suffix) + if (pattern) { - U_INTERNAL_ASSERT_EQUALS(uri_suffix[0], '.') + sz = len-1; + request = pattern; - pos = (request + sz) - uri_suffix; + U_INTERNAL_ASSERT_EQUALS(pattern[sz], '*') + + if (pattern[sz-1] == '/') pos = 1; + } + else + { + const char* uri_suffix = u_getsuffix(request, sz); + + if (uri_suffix) + { + U_INTERNAL_ASSERT_EQUALS(uri_suffix[0], '.') + + pos = (request + sz) - uri_suffix; + } } U_INTERNAL_DUMP("digest_authentication = %b", digest_authentication) @@ -7166,12 +7165,22 @@ U_NO_EXPORT bool UHTTP::processAuthorization() { U_ASSERT(_uri.empty()) - U_INTERNAL_DUMP("request = %.*S", sz, request) + ptr = value.data(); + pos = value.size(); - if (sz > value.size() || - memcmp(request, value.data(), sz)) + U_INTERNAL_DUMP("ptr(%u) = %.*S request(%u) = %.*S", pos, pos, ptr, sz, sz, request) + + if (pattern) { - goto end; + if (UServices::dosMatchWithOR(ptr, pos, pattern, len, 0) == false) goto end; + } + else + { + if (sz > pos || + memcmp(request, ptr, sz)) + { + goto end; + } } _uri = value; @@ -7477,54 +7486,47 @@ bool UHTTP::isProxyRequest() } #ifdef USE_LIBSSL -__pure bool UHTTP::isUriRequestProtected() +bool UHTTP::checkUriProtected() { - U_TRACE_NO_PARAM(0, "UHTTP::isUriRequestProtected()") + U_TRACE_NO_PARAM(0, "UHTTP::checkUriProtected()") // check if the uri is protected if (uri_protected_mask) { - uint32_t sz; + const char* pattern = uri_protected_mask->data(); + uint32_t sz, pattern_len = uri_protected_mask->size(); const char* ptr = UClientImage_Base::getRequestUri(sz); - if (UServices::dosMatchWithOR(ptr, sz, U_STRING_TO_PARAM(*uri_protected_mask), 0)) U_RETURN(true); - } - - U_RETURN(false); -} - -bool UHTTP::checkUriProtected() -{ - U_TRACE_NO_PARAM(0, "UHTTP::checkUriProtected()") - - U_INTERNAL_ASSERT_POINTER(uri_protected_mask) - - if (vallow_IP) - { - bool ok = UClientImage_Base::isAllowed(*vallow_IP); - - if (ok && - U_http_ip_client_len) + if ((pattern_len = u_dosmatch_with_OR(ptr, sz, pattern, pattern_len, 0))) { - ok = UIPAllow::isAllowed(UServer_Base::client_address, *vallow_IP); - } + if (vallow_IP) + { + bool ok = UClientImage_Base::isAllowed(*vallow_IP); - if (ok == false) - { - setForbidden(); + if (ok && + U_http_ip_client_len) + { + ok = UIPAllow::isAllowed(UServer_Base::client_address, *vallow_IP); + } - U_SRV_LOG("URI_PROTECTED: request %.*S denied by access list", U_HTTP_URI_TO_TRACE); + if (ok == false) + { + setForbidden(); - U_RETURN(false); + U_SRV_LOG("URI_PROTECTED: request %.*S denied by access list", U_HTTP_URI_TO_TRACE); + + U_RETURN(false); + } + } + + // check if it's OK via authentication (digest|basic) + + if (processAuthorization(ptr, sz, (u_pOR != U_NULLPTR ? u_pOR : pattern), pattern_len) == false) U_RETURN(false); } } - // check if it's OK via authentication (digest|basic) - - if (processAuthorization()) U_RETURN(true); - - U_RETURN(false); + U_RETURN(true); } #endif @@ -7610,7 +7612,16 @@ not_found: U_INTERNAL_DUMP("target(%u) = %.*S", target_len, target_len, target) - if (u_getsuffix(target, target_len) != U_NULLPTR) goto end; // NB: if we have a suffix (Ex: something.sh) we go to the next phase of request processing... + ptr = u_getsuffix(target, target_len); + + if (ptr != U_NULLPTR) + { + if (memcmp(ptr+1, U_CONSTANT_TO_PARAM("shtml"))) goto end; // NB: if we have a suffix different from '.shtml' (Ex: process.sh) we go to the next phase of request processing... + + if (ptr) target_len = ptr - target; + + U_INTERNAL_DUMP("target(%u) = %.*S", target_len, target_len, target) + } U_http_info.nResponseCode = 0; // NB: it is used by server_plugin_ssi to continue processing with a shell script... @@ -8293,7 +8304,7 @@ U_NO_EXPORT void UHTTP::manageDataForCache(const UString& basename, const UStrin // manage gzip bomb... if (suffix_len == 2 && - UServer_Base::bssl != false && // NB: we can't use sendfile with SSL... + UServer_Base::bssl == false && // NB: we can't use sendfile with SSL... u_get_unalignedp16( suffix_ptr) == U_MULTICHAR_CONSTANT16('g','z') && u_get_unalignedp64(basename_ptr) == U_MULTICHAR_CONSTANT64('_','_','B','o','m','B','_','_')) { @@ -8616,12 +8627,10 @@ U_NO_EXPORT bool UHTTP::processFileCache() U_http_info.nResponseCode = HTTP_PARTIAL; } - if (isSizeForSendfile(sz) == false) *UClientImage_Base::body = getBodyFromCache().substr(range_start, range_size); + if (isSizeForSendfile(sz)) setSendfile(file_data->fd, range_start, range_size); else { - U_http_flag |= HTTP_IS_SENDFILE; - - UClientImage_Base::setSendfile(file_data->fd, range_start, range_size); + *UClientImage_Base::body = getBodyFromCache().substr(range_start, range_size); } end: @@ -10554,23 +10563,12 @@ U_NO_EXPORT bool UHTTP::processGetRequest() U_INTERNAL_ASSERT_DIFFERS(file_data->fd, -1) U_INTERNAL_ASSERT_EQUALS(file->fd, file_data->fd) U_INTERNAL_ASSERT_EQUALS(file->st_size, file_data->size) + U_INTERNAL_ASSERT_MINOR(range_size, UServer_Base::min_size_for_sendfile) UString mmap; time_t expire; const char* ctype; - // NB: we check if we need to send the body with sendfile()... - - U_INTERNAL_DUMP("U_http_sendfile = %b", U_http_sendfile) - - if (U_http_sendfile) - { - U_INTERNAL_ASSERT_DIFFERS(U_http_version, '2') - U_INTERNAL_ASSERT(range_size >= UServer_Base::min_size_for_sendfile) - - goto sendfile; - } - if (file->memmap(PROT_READ, &mmap) == false) goto error; if (file_data == file_not_in_cache_data) @@ -10648,15 +10646,9 @@ U_NO_EXPORT bool UHTTP::processGetRequest() U_INTERNAL_DUMP("range_start = %u range_size = %u", range_start, range_size) - U_ASSERT(UClientImage_Base::body->empty()) + // NB: we check if we can send the body with sendfile()... - if (isSizeForSendfile(range_size)) // NB: we check if we can send the body with sendfile()... - { - U_http_flag |= HTTP_IS_SENDFILE; - -sendfile: - UClientImage_Base::setSendfile(file->fd, range_start, range_size); - } + if (isSizeForSendfile(range_size)) setSendfile(file->fd, range_start, range_size); else { if (U_http_info.nResponseCode == HTTP_PARTIAL && diff --git a/tests/examples/benchmark/FrameworkBenchmarks/ULib/benchmark_config.json b/tests/examples/benchmark/FrameworkBenchmarks/ULib/benchmark_config.json index 7064f5c7..a0774516 100644 --- a/tests/examples/benchmark/FrameworkBenchmarks/ULib/benchmark_config.json +++ b/tests/examples/benchmark/FrameworkBenchmarks/ULib/benchmark_config.json @@ -79,7 +79,7 @@ "query_url": "/query?queries=", "fortune_url": "/fortune", "update_url": "/update?queries=", - "cached_query_url": "/cached_worlds?queries=", + "cached_query_url": "/cached_worlds?queries=", "port": 8080, "approach": "Realistic", "classification": "Platform", @@ -101,7 +101,7 @@ "query_url": "/query?queries=", "fortune_url": "/fortune", "update_url": "/update?queries=", - "cached_query_url": "/cached_worlds?queries=", + "cached_query_url": "/cached_worlds?queries=", "port": 8080, "approach": "Realistic", "classification": "Platform", @@ -117,6 +117,27 @@ "notes": "", "versus": "" }, + "postgres_fit": { + "setup_file": "setup_postgres_fit", + "db_url": "/db", + "query_url": "/query?queries=", + "fortune_url": "/fortune", + "update_url": "/update?queries=", + "port": 8080, + "approach": "Realistic", + "classification": "Platform", + "database": "Postgres", + "framework": "ULib", + "language": "C++", + "orm": "Micro", + "platform": "None", + "webserver": "ULib", + "os": "Linux", + "database_os": "Linux", + "display_name": "ULib-fit", + "notes": "", + "versus": "" + }, "mongodb": { "setup_file": "setup_mongodb", "db_url": "/mdb", diff --git a/tests/examples/benchmark/FrameworkBenchmarks/ULib/setup_postgres_fit.sh b/tests/examples/benchmark/FrameworkBenchmarks/ULib/setup_postgres_fit.sh new file mode 100755 index 00000000..e37a6247 --- /dev/null +++ b/tests/examples/benchmark/FrameworkBenchmarks/ULib/setup_postgres_fit.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +fw_depends postgresql ulib + +# Travis is broken +if [ "$TRAVIS" != "true" ]; then +MAX_THREADS=$CPU_COUNT +else +MAX_THREADS=$(( 2 * $CPU_COUNT )) +fi + +# 1. Change ULib Server (userver_tcp) configuration +sed -i "s|TCP_LINGER_SET .*|TCP_LINGER_SET -2|g" $IROOT/ULib/benchmark.cfg +sed -i "s|LISTEN_BACKLOG .*|LISTEN_BACKLOG 256|g" $IROOT/ULib/benchmark.cfg +sed -i "s|PREFORK_CHILD .*|PREFORK_CHILD ${MAX_THREADS}|g" $IROOT/ULib/benchmark.cfg +sed -i "s|CLIENT_FOR_PARALLELIZATION .*|CLIENT_FOR_PARALLELIZATION 100|g" $IROOT/ULib/benchmark.cfg + +# 2. Start ULib Server (userver_tcp) +export ORM_DRIVER="pgsql" +export UMEMPOOL="581,0,0,59,16409,-7,-20,-23,31" +export ORM_OPTION="host=${DBHOST} user=benchmarkdbuser password=benchmarkdbpass dbname=hello_world client_encoding=UTF8" + +# Never use setcap inside of TRAVIS +[ "$TRAVIS" != "true" ] || { \ +if [ `ulimit -r` -eq 99 ]; then + sudo setcap cap_sys_nice,cap_sys_resource,cap_net_bind_service,cap_net_raw+eip $IROOT/ULib/bin/userver_tcp +fi +} + +$IROOT/ULib/bin/userver_tcp -c $IROOT/ULib/benchmark.cfg & diff --git a/tests/examples/benchmark/FrameworkBenchmarks/ULib/ulib.sh b/tests/examples/benchmark/FrameworkBenchmarks/ULib/ulib.sh index 058d6313..b4116e04 100755 --- a/tests/examples/benchmark/FrameworkBenchmarks/ULib/ulib.sh +++ b/tests/examples/benchmark/FrameworkBenchmarks/ULib/ulib.sh @@ -14,10 +14,10 @@ ULIB_DOCUMENT_ROOT=$ULIB_ROOT/ULIB_DOCUMENT_ROOT mkdir -p $ULIB_ROOT mkdir -p $ULIB_DOCUMENT_ROOT -if [ "$TRAVIS" = "true" ]; then +#if [ "$TRAVIS" = "true" ]; then # AVOID "fatal error: postgres_fe.h: No such file or directory" sudo apt-get install -y postgresql-server-dev-all -fi +#fi # make use of FIFO scheduling policy possible (we must avoid use of test because bash signal trapping) #type setcap >/dev/null 2>/dev/null diff --git a/tests/examples/web_server.sh b/tests/examples/web_server.sh index ef857854..b15a2f58 100755 --- a/tests/examples/web_server.sh +++ b/tests/examples/web_server.sh @@ -76,6 +76,9 @@ userver { #PLUGIN "ssi http" #ORM_DRIVER "sqlite mysql" ORM_DRIVER sqlite +#DOCUMENT_ROOT docroot +#PLUGIN_DIR ../../../src/ulib/net/server/plugin/.libs +#ORM_DRIVER_DIR ../../../src/ulib/orm/driver/.libs DOCUMENT_ROOT JONATHAN/docroot #DOCUMENT_ROOT benchmark/docroot PLUGIN_DIR ../../../../src/ulib/net/server/plugin/.libs @@ -91,7 +94,7 @@ userver { #ORM_DRIVER_DIR ../../../../../src/ulib/orm/driver/.libs } http { -ALIAS "[ / /100.html ]" +#ALIAS "[ / /100.html ]" #VIRTUAL_HOST yes ENABLE_INOTIFY yes LIMIT_REQUEST_BODY 3M diff --git a/tests/examples/web_socket_sh.cfg b/tests/examples/web_socket_sh.cfg index 8ba3af1f..84a738fc 100644 --- a/tests/examples/web_socket_sh.cfg +++ b/tests/examples/web_socket_sh.cfg @@ -1,20 +1,17 @@ userver { - - PORT 8787 - - RUN_AS_USER apache - - LOG_FILE web_socket.log - LOG_FILE_SZ 1M - LOG_MSG_SIZE -1 - - PLUGIN "socket http" - PLUGIN_DIR ../../src/ulib/net/server/plugin/.libs - -# ORM_DRIVER "sqlite" - ORM_DRIVER_DIR ../../src/ulib/orm/driver/.libs - - MAX_KEEP_ALIVE 6 - - PREFORK_CHILD 1 + PORT 8787 + MAX_KEEP_ALIVE 6 + RUN_AS_USER apache + PID_FILE docroot/web_socket_sh.pid + LOG_FILE web_socket.log + LOG_FILE_SZ 1M + LOG_MSG_SIZE -1 + PLUGIN "socket http" + DOCUMENT_ROOT docroot + PLUGIN_DIR ../../../src/ulib/net/server/plugin/.libs + ORM_DRIVER_DIR ../../../src/ulib/orm/driver/.libs + PREFORK_CHILD 1 +} +socket { + COMMAND ../my_websocket.sh } diff --git a/tests/ulib/test_ssl_server.cpp b/tests/ulib/test_ssl_server.cpp index e8a902c3..a0b8a0c2 100644 --- a/tests/ulib/test_ssl_server.cpp +++ b/tests/ulib/test_ssl_server.cpp @@ -34,7 +34,7 @@ protected: if (UClientImage_Base::manageRead() == U_NOTIFIER_DELETE) U_RETURN(U_NOTIFIER_DELETE); - if (U_ClientImage_state == U_PLUGIN_HANDLER_GO_ON) + if (U_ClientImage_state == U_PLUGIN_HANDLER_OK) { static bool binit; diff --git a/tests/ulib/test_string.cpp b/tests/ulib/test_string.cpp index c3700513..c781040d 100644 --- a/tests/ulib/test_string.cpp +++ b/tests/ulib/test_string.cpp @@ -1494,6 +1494,12 @@ U_EXPORT main(int argc, char* argv[]) U_TRACE(5, "main(%d)", argc) + const char* ptr = ".banner.swpx" + U_CONSTANT_SIZE(".banner.swpx") - sizeof(".swp"); + + U_INTERNAL_DUMP("u_isSuffixSwap(%S)", ptr) + + U_INTERNAL_ASSERT(u_isSuffixSwap(ptr)) + /* double val1 = U_STRING_FROM_CONSTANT("0").strtod(); u__printf(1, U_CONSTANT_TO_PARAM("0 = %lf %g"), val1, val1); @@ -1976,7 +1982,7 @@ U_EXPORT main(int argc, char* argv[]) U_ASSERT( UStringExt::dirname(z) == U_STRING_FROM_CONSTANT("/dir") ) U_ASSERT( UStringExt::basename(z) == U_STRING_FROM_CONSTANT("base.suffix") ) - const char* ptr = u_getsuffix(U_CONSTANT_TO_PARAM("/dir/base.suffix/www")); + ptr = u_getsuffix(U_CONSTANT_TO_PARAM("/dir/base.suffix/www")); U_INTERNAL_ASSERT_EQUALS( ptr, U_NULLPTR ) diff --git a/tests/ulib/test_unixsocket_server.cpp b/tests/ulib/test_unixsocket_server.cpp index e153f66f..42fc40f0 100644 --- a/tests/ulib/test_unixsocket_server.cpp +++ b/tests/ulib/test_unixsocket_server.cpp @@ -33,7 +33,7 @@ protected: if (UClientImage_Base::manageRead() == U_NOTIFIER_DELETE) U_RETURN(U_NOTIFIER_DELETE); - if (U_ClientImage_state == U_PLUGIN_HANDLER_GO_ON) + if (U_ClientImage_state == U_PLUGIN_HANDLER_OK) { *UClientImage_Base::wbuffer = *UClientImage_Base::rbuffer;