From 65517dc8b7786d161352ebef0ddcbc9caa62a914 Mon Sep 17 00:00:00 2001 From: stefanocasazza Date: Wed, 2 Jan 2019 19:37:08 +0100 Subject: [PATCH] sync --- examples/WiAuth/v2/wi_auth_declaration2.h | 29 ++++++++--------------- examples/userver/userver.cfg.default | 29 +++++++++++++++++++++++ include/ulib/base/base.h | 6 +++++ include/ulib/event/event_db.h | 6 ++++- src/ulib/event/event_db.cpp | 4 +++- src/ulib/net/server/plugin/mod_http.cpp | 10 ++++---- src/ulib/net/server/server.cpp | 24 +++++++++++-------- src/ulib/utility/uhttp.cpp | 21 ++++++++++++---- src/ulib/utility/websocket.cpp | 4 +++- tests/examples/TSA/tsaserial | 2 +- 10 files changed, 94 insertions(+), 41 deletions(-) diff --git a/examples/WiAuth/v2/wi_auth_declaration2.h b/examples/WiAuth/v2/wi_auth_declaration2.h index 6f6d16962..816fa6bbb 100644 --- a/examples/WiAuth/v2/wi_auth_declaration2.h +++ b/examples/WiAuth/v2/wi_auth_declaration2.h @@ -972,33 +972,24 @@ static void GET_acceptTermsOfConditions() { U_TRACE_NO_PARAM(5, "::GET_acceptTermsOfConditions()") - // $1 -> ap (with localization => '@') - // $2 -> mac + // $1 -> mac - if (UHTTP::processForm() == 2*2) + if (UHTTP::processForm() == 2) { - ap->clear(); - mac->clear(); + UHTTP::getFormValue(*mac, U_CONSTANT_TO_PARAM("mac"), 0, 1, 2); - UHTTP::getFormValue(*ap, U_CONSTANT_TO_PARAM("ap"), 0, 1, 4); - - if (setAccessPoint()) + if (mac->isMacAddr()) { - UHTTP::getFormValue(*mac, U_CONSTANT_TO_PARAM("mac"), 0, 3, 4); - - if (mac->isMacAddr()) - { - char buffer[16]; + char buffer[16]; - u_getXMAC(mac->data(), buffer); + u_getXMAC(mac->data(), buffer); - (void) mac->replace(buffer, 12); - } + (void) mac->replace(buffer, 12); + } - U_ASSERT(mac->isXMacAddr()) + U_ASSERT(mac->isXMacAddr()) - (void) rc->hmset(U_CONSTANT_TO_PARAM("DEVICE:id:%v ExpirePrivacy %u"), mac->rep, u_now->tv_sec + duration_privacy_policy); - } + (void) rc->hmset(U_CONSTANT_TO_PARAM("DEVICE:id:%v ExpirePrivacy %u"), mac->rep, u_now->tv_sec + duration_privacy_policy); } } diff --git a/examples/userver/userver.cfg.default b/examples/userver/userver.cfg.default index 8ffbe775b..bf3d52543 100644 --- a/examples/userver/userver.cfg.default +++ b/examples/userver/userver.cfg.default @@ -257,6 +257,7 @@ http { # CGI_TIMEOUT 60 # VIRTUAL_HOST yes +# WEBSOCKET_TIMEOUT -1 # DIGEST_AUTHENTICATION yes # URI_PROTECTED_MASK /RA/admin/cgi-bin/* @@ -686,6 +687,34 @@ http { # CHECK_EXPIRE_INTERVAL 360 # } +# ----------------------------------------------------------------------------------------------------------------------------------- +# nodog - plugin parameters +# ----------------------------------------------------------------------------------------------------------------------------------- +# FW_CMD shell script to manage the firewall +# FW_ENV environment for shell script to execute +# DECRYPT_KEY DES3 password stuff +# ALLOWED_MEMBERS file with list of allowed MAC/IP pairs or NETWORKS (default: /etc/nodog.allowed) +# LOCAL_NETWORK_LABEL access point localization tag to be used from portal +# CHECK_EXPIRE_INTERVAL Number of seconds to send client info to portal +# ----------------------------------------------------------------------------------------------------------------------------------- + +# nodog { + +# shell script to manage the firewall +# FW_CMD firewall/nodog.fw +# FW_ENV "FW_CONF=/etc/nodog_fw.conf \ +# AuthServiceAddr=http://www.auth-firenze.com/login" + +# DES3 password stuff +# DECRYPT_KEY PASSWORD + +# access point localization tag to be used from portal +# LOCAL_NETWORK_LABEL "radio1 radio2" + +# Number of seconds to check if some client has terminate their connection +# CHECK_EXPIRE_INTERVAL 360 +# } + # ---------------------------------------------------------------------------------------------------------------------------------------------------- # U S P P A G E S P A R A M E T E R S # ---------------------------------------------------------------------------------------------------------------------------------------------------- diff --git a/include/ulib/base/base.h b/include/ulib/base/base.h index 31916d8b6..b2a468741 100644 --- a/include/ulib/base/base.h +++ b/include/ulib/base/base.h @@ -19,9 +19,15 @@ #include #include +#ifndef U_PREFIXDIR +#define U_PREFIXDIR "/usr/local" +#endif #ifndef U_LIBEXECDIR #define U_LIBEXECDIR "/usr/local/libexec/ulib" #endif +#ifndef U_SYSCONFDIR +#define U_SYSCONFDIR "/usr/local/etc" +#endif /* #ifndef HAVE_CONFIG_H diff --git a/include/ulib/event/event_db.h b/include/ulib/event/event_db.h index c77b49ffc..1ca2ec1cc 100644 --- a/include/ulib/event/event_db.h +++ b/include/ulib/event/event_db.h @@ -16,7 +16,7 @@ #include -#define U_QUERY_INFO_SZ 1024 +#define U_QUERY_INFO_SZ 168 class UServer_Base; class UClientImage_Base; @@ -27,6 +27,10 @@ class U_EXPORT UEventDB : public UEventFd { // Check for memory error U_MEMORY_TEST + // Allocator e Deallocator + U_MEMORY_ALLOCATOR + U_MEMORY_DEALLOCATOR + UEventDB(); ~UEventDB(); diff --git a/src/ulib/event/event_db.cpp b/src/ulib/event/event_db.cpp index b9b70666f..7785def6b 100644 --- a/src/ulib/event/event_db.cpp +++ b/src/ulib/event/event_db.cpp @@ -41,7 +41,7 @@ UEventDB::UEventDB() pthis = (void*)U_CHECK_MEMORY_SENTINEL; #endif -// U_WARNING("UEventDB::UEventDB(): sizeof(UEventDB) = %u sizeof(query_info) = %u", sizeof(UEventDB), sizeof(query_info)); // sizeof(UEventDB) = 4072|4088 sizeof(query_info) = 24 + U_DEBUG("UEventDB::UEventDB(): sizeof(UEventDB) = %u sizeof(query_info) = %u", sizeof(UEventDB), sizeof(query_info)); // sizeof(UEventDB) = 4072|4088 sizeof(query_info) = 24 } UEventDB::~UEventDB() @@ -151,9 +151,11 @@ void UEventDB::handlerQuery(vPFpvu handler, uint32_t num_query) U_INTERNAL_ASSERT_MINOR(num_result, 4096) +#ifndef U_SERVER_CAPTIVE_PORTAL if (num_query > 20 || (num_result >= 2048 || num_handler == U_QUERY_INFO_SZ)) +#endif { U_DEBUG("UEventDB::handlerQuery(%u): num_result(%u), num_handler(%u)", num_query, num_result, num_handler); diff --git a/src/ulib/net/server/plugin/mod_http.cpp b/src/ulib/net/server/plugin/mod_http.cpp index 1867647f4..9776ae9ea 100644 --- a/src/ulib/net/server/plugin/mod_http.cpp +++ b/src/ulib/net/server/plugin/mod_http.cpp @@ -475,6 +475,9 @@ int UHttpPlugIn::handlerInit() { U_TRACE_NO_PARAM(0, "UHttpPlugIn::handlerInit()") + UServer_Base::update_date = + UServer_Base::update_date3 = true; + U_MEMCPY(ULog::date.header1, "HTTP/1.1 200 OK\r\n", U_CONSTANT_SIZE("HTTP/1.1 200 OK\r\n")); // 17 @@ -549,13 +552,12 @@ int UHttpPlugIn::handlerRun() // NB: we use this method instead of handlerInit() #endif if (UServer_Base::handler_inotify) UHTTP::initDbNotFound(); - UServer_Base::update_date = - UServer_Base::update_date3 = true; - -#if defined(U_LINUX) && defined(ENABLE_THREAD) && !defined(U_SERVER_CAPTIVE_PORTAL) +#if defined(U_LINUX) && defined(ENABLE_THREAD) U_INTERNAL_ASSERT_POINTER(UServer_Base::ptr_shared_data) +# if !defined(U_SERVER_CAPTIVE_PORTAL) UClientImage_Base::callerHandlerCache = UHTTP::handlerCache; +# endif UClientImage_Base::iov_vec[1].iov_base = (caddr_t)UServer_Base::ptr_shared_data->log_date_shared.header1; #endif diff --git a/src/ulib/net/server/server.cpp b/src/ulib/net/server/server.cpp index 174f5532a..659b22855 100644 --- a/src/ulib/net/server/server.cpp +++ b/src/ulib/net/server/server.cpp @@ -1112,7 +1112,7 @@ class UClientThread : public UThread { U_DISALLOW_COPY_AND_ASSIGN(UClientThread) }; -# if defined(U_LINUX) && !defined(U_SERVER_CAPTIVE_PORTAL) +# ifdef U_LINUX class UTimeThread : public UThread { public: @@ -1261,15 +1261,19 @@ class UTimeThread : public UThread { sec = u_now->tv_sec; +# ifndef U_SERVER_CAPTIVE_PORTAL if (daylight && (sec % U_ONE_HOUR_IN_SECOND) == 0) { (void) UTimeDate::checkForDaylightSavingTime(sec); } +# endif if (UServer_Base::update_date) { +# ifndef U_SERVER_CAPTIVE_PORTAL (void) U_SYSCALL(pthread_rwlock_wrlock, "%p", ULog::prwlock); +# endif if ((sec % U_ONE_HOUR_IN_SECOND) != 0) { @@ -1286,7 +1290,9 @@ class UTimeThread : public UThread { if (UServer_Base::update_date3) (void) u_strftime2(ULog::ptr_shared_date->date3+6, 29-4, U_CONSTANT_TO_PARAM("%a, %d %b %Y %T"), sec); } +# ifndef U_SERVER_CAPTIVE_PORTAL (void) U_SYSCALL(pthread_rwlock_unlock, "%p", ULog::prwlock); +# endif } } } @@ -1797,14 +1803,12 @@ UServer_Base::~UServer_Base() # endif # if defined(U_LINUX) -# if !defined(U_SERVER_CAPTIVE_PORTAL) if (u_pthread_time) { U_DELETE((UTimeThread*)u_pthread_time) (void) pthread_rwlock_destroy(ULog::prwlock); } -# endif # if defined(USE_LIBSSL) && !defined(OPENSSL_NO_OCSP) && defined(SSL_CTRL_SET_TLSEXT_STATUS_REQ_CB) if (bssl) @@ -2208,7 +2212,7 @@ void UServer_Base::loadConfigParam() port = _port; } - U_INTERNAL_DUMP("SOMAXCONN = %d FD_SETSIZE = %d", SOMAXCONN, FD_SETSIZE) + U_INTERNAL_DUMP("SOMAXCONN = %d FD_SETSIZE = %d timeoutMS = %d", SOMAXCONN, FD_SETSIZE, timeoutMS) set_tcp_keep_alive = pcfg->readBoolean(U_CONSTANT_TO_PARAM("TCP_KEEP_ALIVE")); set_realtime_priority = pcfg->readBoolean(U_CONSTANT_TO_PARAM("SET_REALTIME_PRIORITY"), false); @@ -3036,9 +3040,7 @@ void UServer_Base::suspendThread() U_TRACE_NO_PARAM(0, "UServer_Base::suspendThread()") #if defined(U_LINUX) && defined(ENABLE_THREAD) -# if !defined(U_SERVER_CAPTIVE_PORTAL) if (u_pthread_time) ((UTimeThread*)u_pthread_time)->suspend(); -# endif # if defined(USE_LIBSSL) && !defined(OPENSSL_NO_OCSP) && defined(SSL_CTRL_SET_TLSEXT_STATUS_REQ_CB) if (pthread_ocsp) pthread_ocsp->suspend(); @@ -3359,7 +3361,6 @@ void UServer_Base::init() if (budp == false) # endif { -# if !defined(U_SERVER_CAPTIVE_PORTAL) if (UServer_Base::update_date) { U_NEW_WITHOUT_CHECK_MEMORY(UTimeThread, u_pthread_time, UTimeThread); @@ -3368,7 +3369,6 @@ void UServer_Base::init() ((UTimeThread*)u_pthread_time)->start(50); } -# endif } #endif @@ -3632,9 +3632,7 @@ void UServer_Base::sendSignalToAllChildren(int signo, sighandler_t handler) #endif #if defined(U_LINUX) && defined(ENABLE_THREAD) -# if !defined(U_SERVER_CAPTIVE_PORTAL) if (u_pthread_time) ((UTimeThread*)u_pthread_time)->resume(); -# endif # if defined(USE_LIBSSL) && !defined(OPENSSL_NO_OCSP) && defined(SSL_CTRL_SET_TLSEXT_STATUS_REQ_CB) if (pthread_ocsp) pthread_ocsp->resume(); @@ -4483,6 +4481,7 @@ void UServer_Base::runLoop(const char* user) if (budp == false) #endif { +# ifndef U_SERVER_CAPTIVE_PORTAL if (handler_db1) { UNotifier::min_connection++; @@ -4498,6 +4497,7 @@ void UServer_Base::runLoop(const char* user) handler_db2->UEventFd::op_mask |= EPOLLET; handler_db2->UEventFd::op_mask &= ~EPOLLRDHUP; } +# endif if (handler_other) { @@ -4532,7 +4532,9 @@ void UServer_Base::runLoop(const char* user) handler_db1->pbusy = U_SRV_DB1_BUSY+rkids; # endif +# ifndef U_SERVER_CAPTIVE_PORTAL UNotifier::insert(handler_db1, EPOLLEXCLUSIVE | EPOLLROUNDROBIN); // NB: we ask to be notified for response from db +# endif } if (handler_db2) @@ -4543,7 +4545,9 @@ void UServer_Base::runLoop(const char* user) handler_db2->pbusy = U_SRV_DB2_BUSY+rkids; # endif +# ifndef U_SERVER_CAPTIVE_PORTAL UNotifier::insert(handler_db2, EPOLLEXCLUSIVE | EPOLLROUNDROBIN); // NB: we ask to be notified for response from db +# endif } if (handler_other) // NB: we ask to be notified for request from generic system diff --git a/src/ulib/utility/uhttp.cpp b/src/ulib/utility/uhttp.cpp index 9e9aaa5f5..125c2611f 100644 --- a/src/ulib/utility/uhttp.cpp +++ b/src/ulib/utility/uhttp.cpp @@ -11743,12 +11743,27 @@ U_NO_EXPORT bool UHTTP::compileUSP(const char* path, uint32_t len) U_TRACE(0, "UHTTP::compileUSP(%.*S,%u)", len, path, len) static int fd_stderr; + static UString* usp_compile_path; - UString command(200U); + if (usp_compile_path == U_NULLPTR) + { + struct stat st; + + if (U_SYSCALL(stat, "%S,%p", U_PREFIXDIR "/bin/usp_compile.sh", &st) == 0) + { + U_NEW_ULIB_STRING(usp_compile_path, U_STRING_FROM_CONSTANT(U_PREFIXDIR "/bin/usp_compile.sh")); + } + else + { + U_NEW_ULIB_STRING(usp_compile_path, U_STRING_FROM_CONSTANT("usp_compile.sh")); + } + } + + UString command(usp_compile_path->size()); // Ex: usp_compile.sh -i /home/user/project/include -o /home/user/project/build so - command.snprintf(U_CONSTANT_TO_PARAM("usp_compile.sh %.*s %s"), len, path, U_LIB_SUFFIX); + command.snprintf(U_CONSTANT_TO_PARAM("%v %.*s %s"), usp_compile_path->rep, len, path, U_LIB_SUFFIX); UCommand cmd(command); @@ -12019,8 +12034,6 @@ loop: while (u__isalpha(*++ptr1)) {} { old_sz = sz; - ULog::updateDate3(U_NULLPTR); - U_http_info.nResponseCode = HTTP_OK; UClientImage_Base::body->clear(); diff --git a/src/ulib/utility/websocket.cpp b/src/ulib/utility/websocket.cpp index 849035988..533b2d138 100644 --- a/src/ulib/utility/websocket.cpp +++ b/src/ulib/utility/websocket.cpp @@ -171,8 +171,10 @@ int UWebSocket::handleDataFraming(USocket* socket) int framing_state = U_WS_DATA_FRAMING_START, payload_length_bytes_remaining = 0, mask_index = 0, masking = 0; loop: + U_INTERNAL_DUMP("timeoutMS = %d", timeoutMS) + if (rbuffer->empty() && - USocketExt::read(socket, *rbuffer, U_SINGLE_READ, UWebSocket::timeoutMS) == false) + USocketExt::read(socket, *rbuffer, U_SINGLE_READ, timeoutMS) == false) { status_code = U_WS_STATUS_CODE_INTERNAL_ERROR; diff --git a/tests/examples/TSA/tsaserial b/tests/examples/TSA/tsaserial index 393ed918e..c7aa18a20 100644 --- a/tests/examples/TSA/tsaserial +++ b/tests/examples/TSA/tsaserial @@ -1 +1 @@ -0454 +0469