From 78c10b85ee1f8c853f216a8ba9b9e0c86b4e76d5 Mon Sep 17 00:00:00 2001 From: stefanocasazza Date: Wed, 4 Apr 2018 18:15:41 +0200 Subject: [PATCH] fix --- Makefile.am | 4 + Makefile.in | 4 + examples/WiAuth/v2/wi_auth_declaration2.h | 245 +++++++++++---------- include/ulib/file.h | 4 +- include/ulib/internal/macro.h | 2 +- include/ulib/net/client/redis.h | 117 ++++++---- include/ulib/net/server/plugin/mod_nodog.h | 5 +- include/ulib/serialize/flatbuffers.h | 11 +- src/ulib/base/base.c | 45 ++-- src/ulib/file.cpp | 33 +-- src/ulib/internal/common.cpp | 7 +- src/ulib/internal/memory_pool.cpp | 7 +- src/ulib/net/server/plugin/mod_nodog.cpp | 93 ++++++-- src/ulib/string.cpp | 2 + src/ulib/utility/interrupt.cpp | 4 + tests/examples/nodog.sh | 2 +- 16 files changed, 359 insertions(+), 226 deletions(-) diff --git a/Makefile.am b/Makefile.am index 239faffa..4db6db08 100644 --- a/Makefile.am +++ b/Makefile.am @@ -36,6 +36,10 @@ aclocal_DATA = ULib.m4 ##README.html: README.md ##@Markdown.pl README.md > README.html +configure: configure.ac + @echo "$< changed: you must re-run './autogen.sh'" + @false + test: @cd $(top_builddir)/tests; $(MAKE) $(AM_MAKEFLAGS) test diff --git a/Makefile.in b/Makefile.in index f696e8d9..460ac497 100644 --- a/Makefile.in +++ b/Makefile.in @@ -982,6 +982,10 @@ uninstall-am: uninstall-aclocalDATA .phony: doxy todo +configure: configure.ac + @echo "$< changed: you must re-run './autogen.sh'" + @false + test: @cd $(top_builddir)/tests; $(MAKE) $(AM_MAKEFLAGS) test diff --git a/examples/WiAuth/v2/wi_auth_declaration2.h b/examples/WiAuth/v2/wi_auth_declaration2.h index efa39a58..03d78375 100644 --- a/examples/WiAuth/v2/wi_auth_declaration2.h +++ b/examples/WiAuth/v2/wi_auth_declaration2.h @@ -18,11 +18,6 @@ static UString* allowed_web_hosts; static UFile* file_LOG; static UFile* file_WARNING; -/* -static UVector* vap; -*/ -static UVector* vcaptive; - static UREDISClient_Base* rc; static UHttpClient* client; @@ -38,8 +33,15 @@ static uint8_t policySessionNotify; static uint64_t counter, device_counter; static uint32_t addr, created, lastUpdate, lastReset; -#define U_MAX_TRAFFIC_DAILY (500ULL * 1024ULL * 1024ULL) // 500M -#define U_MAX_TIME_NO_TRAFFIC (30 * 60) // 30m +#define U_TEST +#define U_CLEAN_INTERVAL (60 * 60) // 1h +#define U_MAX_TIME_NO_TRAFFIC (15 * 60) // 15m + +#ifdef U_TEST +# define U_MAX_TRAFFIC_DAILY (50ULL * 1024ULL * 1024ULL) // 50M +#else +# define U_MAX_TRAFFIC_DAILY (500ULL * 1024ULL * 1024ULL) // 500M +#endif #define U_LOGGER(fmt,args...) ULog::log(file_WARNING->getFd(), U_CONSTANT_TO_PARAM("%v: " fmt), UClientImage_Base::request_uri->rep , ##args) @@ -55,7 +57,7 @@ enum UPolicy { class WiAuthClean : public UEventTime { public: - WiAuthClean() : UEventTime(30L * 60L, 0L) // 30m + WiAuthClean() : UEventTime(U_CLEAN_INTERVAL, 0L) { U_TRACE_REGISTER_OBJECT(0, WiAuthClean, "", U_NULLPTR) } @@ -80,6 +82,7 @@ public: uint8_t status; UString url(100U); + /* for (uint32_t i = 0, n = vcaptive->size(); i < n; ++i) { url.snprintf(U_CONSTANT_TO_PARAM("http://%v:5280/ping"), vcaptive->at(i).rep); @@ -111,6 +114,7 @@ public: client->reset(); } + */ if (pid == 0) UServer_Base::endNewChild(); @@ -218,9 +222,6 @@ static void usp_init_wi_auth2() U_ASSERT_EQUALS(client->isPasswordAuthentication(), false) -// U_NEW(UVector, vap, UVector); - U_NEW(UVector, vcaptive, UVector); - UVector vnetmask; UTokenizer tok(*db_anagrafica, ",\n"); UString lip, lnetmask, lbl, lnetmask1, lbl1; @@ -246,9 +247,6 @@ loop: U_INTERNAL_ASSERT(lbl) U_INTERNAL_ASSERT(lnetmask) -// vap->push_back(lbl); - vcaptive->push_back(lip); - U_ASSERT(vnetmask.empty()) vnetmask.push_back(lnetmask); @@ -259,13 +257,13 @@ loop: (void) UIPAddress::getBinaryForm(ip->c_str(), addr, true); - (void) rc->hmset(U_CONSTANT_TO_PARAM("CAPTIVE:id:%u name ???"), addr); + (void) rc->hmset(U_CONSTANT_TO_PARAM("CAPTIVE:id:%u ip %v"), addr, ip->rep); (void) rc->zadd(U_CONSTANT_TO_PARAM("CAPTIVE:byId 0 id:%u"), addr); (void) rc->hmset(U_CONSTANT_TO_PARAM("AP:id:%v captiveId %u network %v"), lbl.rep, addr, lnetmask.rep); - (void) rc->zadd(U_CONSTANT_TO_PARAM("AP:byCaptiveId %u \"id:%v;network:%v\""), addr, lbl.rep, lnetmask.rep); + (void) rc->zadd(U_CONSTANT_TO_PARAM("AP:byCaptiveId %u id:%v;network:%v"), addr, lbl.rep, lnetmask.rep); while (tok.next(lip, (bool*)U_NULLPTR)) { @@ -296,11 +294,9 @@ loop: continue; } -// vap->push_back(lbl1); - (void) rc->hmset(U_CONSTANT_TO_PARAM("AP:id:%v captiveId %u network %v"), lbl1.rep, addr, lnetmask1.rep); - (void) rc->zadd(U_CONSTANT_TO_PARAM("AP:byCaptiveId %u \"id:%v;network:%v\""), addr, lbl1.rep, lnetmask1.rep); + (void) rc->zadd(U_CONSTANT_TO_PARAM("AP:byCaptiveId %u id:%v;network:%v"), addr, lbl1.rep, lnetmask1.rep); vnetmask.clear(); @@ -308,8 +304,6 @@ loop: lnetmask = lnetmask1; } - vcaptive->sort(UStringExt::qscompver); - // CLEAN MONITORING U_NEW(UPing, sockp, UPing(5000, UClientImage_Base::bIPv6)); @@ -342,8 +336,6 @@ static void usp_end_wi_auth2() delete policySessionId; delete allowed_web_hosts; -// delete vap; - delete vcaptive; delete db_anagrafica; delete rc; @@ -614,7 +606,7 @@ static void writeSessionToLOG(const char* op, uint32_t op_len) UString opt(200U); - opt.snprintf(U_CONSTANT_TO_PARAM(", traffic: %llu, elapsed: %u"), counter/(1024*1024), (u_now->tv_sec-created)/60); + opt.snprintf(U_CONSTANT_TO_PARAM(", traffic: %llu, elapsed: %u"), counter/1024, (u_now->tv_sec-created)/60); writeToLOG(op, op_len, opt); } @@ -624,8 +616,8 @@ static void deleteSession() U_TRACE_NO_PARAM(5, "::deleteSession()") (void) rc->del(U_CONSTANT_TO_PARAM("SESSION:%v"), key_session->rep); - (void) rc->zrem(U_CONSTANT_TO_PARAM("SESSION:byCaptiveIdAndApId \"deviceId:%v;ip:%v\""), mac->rep, ip->rep); - (void) rc->zrem(U_CONSTANT_TO_PARAM("SESSION:byLastUpdate \"%v\""), key_session->rep); + (void) rc->zrem(U_CONSTANT_TO_PARAM("SESSION:byCaptiveIdAndApId deviceId:%v;ip:%v"), mac->rep, ip->rep); + (void) rc->zrem(U_CONSTANT_TO_PARAM("SESSION:byLastUpdate %v"), key_session->rep); } static void resetDeviceDailyCounter() @@ -868,9 +860,13 @@ static void GET_start_ap() } } - if (vcaptive->findSorted(*ap_address) == U_NOT_FOUND) + UString x(200U); + + x.snprintf(U_CONSTANT_TO_PARAM("CAPTIVE:id:%u"), addr); + + if (rc->exists(U_STRING_TO_PARAM(x)) == false) { - U_LOGGER("*** CAPTIVE:%v NOT FOUND ***", ap_address->rep); + U_LOGGER("*** %v NOT FOUND ***", x.rep); return; } @@ -884,41 +880,45 @@ static void GET_start_ap() (void) rc->hmset(U_CONSTANT_TO_PARAM("CAPTIVE:id:%u name %v status 1 uptime %v since %u lastUpdate %u"), addr, ap_hostname->rep, uptime.rep, u_now->tv_sec, u_now->tv_sec); - UString x(200U); + x.snprintf(U_CONSTANT_TO_PARAM("%u"), addr); - x.snprintf(U_CONSTANT_TO_PARAM("%u%06u"), addr, ap_label->strtoul()); - - (void) rc->zrangebyscore(U_CONSTANT_TO_PARAM("SESSION:byCaptiveIdAndApId %v %v"), x.rep, x.rep); + (void) rc->zrangebyscore(U_CONSTANT_TO_PARAM("SESSION:byCaptiveIdAndApId %v000000 %v999999 WITHSCORES"), x.rep, x.rep); uint32_t n = rc->vitem.size(); if (n) { + const char* ptr1; + const char* ptr2; UVector vec(n); vec.copy(rc->vitem); - x.snprintf(U_CONSTANT_TO_PARAM("captiveId:%u;apId:%v;"), addr, ap_label->rep); + key_session->setBuffer(200U); - for (uint32_t i = 0; i < n; ++i) + x.snprintf(U_CONSTANT_TO_PARAM("captiveId:%u;apId:"), addr); + + for (uint32_t i = 0; i < n; i += 2) { - *key_session = x + vec[i]; + ptr1 = + ptr2 = vec[i+1].pend()-6; // score (ex: 3232246838000064) + + while (*ptr2 == '0') { ++ptr2; } + + (void) ap_label->assign(ptr2, 6-(ptr2-ptr1)); + + key_session->snprintf(U_CONSTANT_TO_PARAM("%v%v;%v"), x.rep, ap_label->rep, vec[i].rep); if (getSession()) { - addr = rc->getULong(6); - *ap_label = rc->getString(7); - *mac = rc->getString(8); - *ip = rc->getString(9); + U_ASSERT_EQUALS(addr, rc->getULong(6)) + U_ASSERT_EQUALS(*ap_label, rc->getString(7)) + + *mac = rc->getString(8); + *ip = rc->getString(9); U_INTERNAL_ASSERT(u_isIPv4Addr(U_STRING_TO_PARAM(*ip))) - *ap_address = UIPAddress::toString(addr); - - (void) rc->hmget(U_CONSTANT_TO_PARAM("CAPTIVE:id:%u name"), addr); - - *ap_hostname = rc->getString(); - writeSessionToLOG(U_CONSTANT_TO_PARAM("DENY_LOST")); deleteSession(); @@ -968,48 +968,51 @@ static void POST_login() peer = U_NULLPTR; - UFlatBuffer fb; bool ko = (getDataFromPOST(true) == false); - char buffer[2] = { '1'-ko, '0'+policySessionNotify }; // deny|permit: ('0'|'1') policy: notify|no_notify|strict_notify ('0'|'1'|'2') - writeToLOG(U_CONSTANT_TO_PARAM("PERMIT"), UString::getStringNull()); - - (void) rc->hmset(U_CONSTANT_TO_PARAM("DEVICE:id:%v lastAccess %u"), mac->rep, u_now->tv_sec); - (void) rc->zadd(U_CONSTANT_TO_PARAM("DEVICE:bylastAccess %u id:%v"), u_now->tv_sec, mac->rep); - - if (ko) writeSessionToLOG(U_CONSTANT_TO_PARAM("DENY_POLICY")); - else + if (*ap_address) { - setSessionkey(); + UFlatBuffer fb; + char buffer[2] = { '1'-ko, '0'+policySessionNotify }; // deny|permit: ('0'|'1') policy: notify|no_notify|strict_notify ('0'|'1'|'2') - (void) rc->hmset(U_CONSTANT_TO_PARAM("SESSION:%v captiveId %u apId %v deviceId %v ip %v created %u pId %v notify %c consume %c counter 0 lastUpdate %u"), - key_session->rep, - addr, ap_label->rep, mac->rep, ip->rep, u_now->tv_sec, policySessionId->rep, buffer[1], '0'+ap_consume, u_now->tv_sec); + writeToLOG(U_CONSTANT_TO_PARAM("PERMIT"), UString::getStringNull()); - (void) rc->zadd(U_CONSTANT_TO_PARAM("SESSION:byCaptiveIdAndApId %u%06u \"deviceId:%v;ip:%v\""), addr, ap_label->strtoul(), mac->rep, ip->rep); - (void) rc->zadd(U_CONSTANT_TO_PARAM("SESSION:byLastUpdate %u \"%v\""), u_now->tv_sec, key_session->rep); - } + (void) rc->hmset(U_CONSTANT_TO_PARAM("DEVICE:id:%v lastAccess %u"), mac->rep, u_now->tv_sec); + (void) rc->zadd(U_CONSTANT_TO_PARAM("DEVICE:bylastAccess %u id:%v"), u_now->tv_sec, mac->rep); - // $1 -> peer - // $2 -> deny|permit: ('0'|'1') policy: notify|no_notify|strict_notify ('0'|'1'|'2') + if (ko) writeSessionToLOG(U_CONSTANT_TO_PARAM("DENY_POLICY")); + else + { + setSessionkey(); + + (void) rc->hmset(U_CONSTANT_TO_PARAM("SESSION:%v captiveId %u apId %v deviceId %v ip %v created %u pId %v notify %c consume %c counter 0 lastUpdate %u"), key_session->rep, + addr, ap_label->rep, mac->rep, ip->rep, u_now->tv_sec, policySessionId->rep, buffer[1], '0'+ap_consume, u_now->tv_sec); + + (void) rc->zadd(U_CONSTANT_TO_PARAM("SESSION:byCaptiveIdAndApId %u%06u deviceId:%v;ip:%v"), addr, ap_label->strtoul(), mac->rep, ip->rep); + (void) rc->zadd(U_CONSTANT_TO_PARAM("SESSION:byLastUpdate %u %v"), u_now->tv_sec, key_session->rep); + } + + // $1 -> peer + // $2 -> deny|permit: ('0'|'1') policy: notify|no_notify|strict_notify ('0'|'1'|'2') + +# ifdef HAVE_CXX11 + (void) fb.encodeVector([&]() { + fb.UInt(U_PTR2INT(peer)); + fb.String(buffer, sizeof(buffer)); + }); +# else + fb.StartBuild(); + (void) fb.StartVector(); -#ifdef HAVE_CXX11 - (void) fb.encodeVector([&]() { fb.UInt(U_PTR2INT(peer)); fb.String(buffer, sizeof(buffer)); - }); -#else - fb.StartBuild(); - (void) fb.StartVector(); - fb.UInt(U_PTR2INT(peer)); - fb.String(buffer, sizeof(buffer)); + fb.EndVector(0, false); + (void) fb.EndBuild(); +# endif - fb.EndVector(0, false); - (void) fb.EndBuild(); -#endif - - (void) sendRequestToNodog(U_CONSTANT_TO_PARAM("login_validate"), fb.getResult()); + (void) sendRequestToNodog(U_CONSTANT_TO_PARAM("login_validate"), fb.getResult()); + } } static void POST_notify() @@ -1036,11 +1039,17 @@ static void POST_strict_notify() if (getDataFromPOST(false)) { - (void) rc->hmget(U_CONSTANT_TO_PARAM("DEVICE:id:%v pNotify"), mac->rep); + UString x(200U); + + x.snprintf(U_CONSTANT_TO_PARAM("DEVICE:id:%v pNotify"), mac->rep); + + (void) rc->hmget(x); if (rc->getUInt8() == 2) // (strict notify) => (notify) { - (void) rc->hmset(U_CONSTANT_TO_PARAM("DEVICE:id:%v pNotify 0"), mac->rep); + (void) x.append(U_CONSTANT_TO_PARAM(" 0")); + + (void) rc->hmset(x); } writeToLOG(U_CONSTANT_TO_PARAM("STRICT_NOTIFIED"), UString::getStringNull()); @@ -1100,8 +1109,9 @@ static void POST_info() setAccessPoint()) { const char* op; + UString x(200U); UVector vec_logout; - uint32_t _ctime, ctraffic, time_no_traffic, op_len, midnigth = u_getLocalTime() / U_ONE_DAY_IN_SECOND; + uint32_t _ctime, ctraffic, time_no_traffic, ctime_no_traffic, op_len, midnigth = u_getLocalTime() / U_ONE_DAY_IN_SECOND; (void) rc->hmset(U_CONSTANT_TO_PARAM("CAPTIVE:id:%u status 1 lastUpdate %u"), addr, u_now->tv_sec); @@ -1133,67 +1143,64 @@ static void POST_info() U_INTERNAL_DUMP("ap_label = %V mac = %V ip = %V", rc->getString(7).rep, rc->getString(8).rep, rc->getString(9).rep) - U_ASSERT_EQUALS(*ap_label, rc->getString(7)) - U_ASSERT_EQUALS(*mac, rc->getString(8)) - U_ASSERT_EQUALS(*ip, rc->getString(9)) - U_INTERNAL_ASSERT_EQUALS(addr, rc->getULong(6)) + U_ASSERT_EQUALS(*ap_label, rc->getString(7)) + U_ASSERT_EQUALS(*mac, rc->getString(8)) + U_ASSERT_EQUALS(*ip, rc->getString(9)) - if (time_no_traffic >= U_MAX_TIME_NO_TRAFFIC) + if (ctraffic == 0) { - U_INTERNAL_ASSERT_EQUALS(ctraffic, 0) + ctime_no_traffic = (u_now->tv_sec - lastUpdate); - U_DEBUG("Peer IP %v MAC %v has made no traffic for %u secs", ip->rep, mac->rep, time_no_traffic); + U_DEBUG("Peer IP %v MAC %v has made no traffic for %u secs", ip->rep, mac->rep, ctime_no_traffic); - op = "DENY_NO_TRAFFIC"; - op_len = U_CONSTANT_SIZE("DENY_NO_TRAFFIC"); + if (ctime_no_traffic >= U_MAX_TIME_NO_TRAFFIC) // (time_no_traffic >= U_MAX_TIME_NO_TRAFFIC) + { + op = "DENY_NO_TRAFFIC"; + op_len = U_CONSTANT_SIZE("DENY_NO_TRAFFIC"); - created += time_no_traffic; + created += ctime_no_traffic; -del_sess: writeSessionToLOG(op, op_len); +del_sess: writeSessionToLOG(op, op_len); - deleteSession(); + deleteSession(); -del_login: vec_logout.push_back(*ip); - vec_logout.push_back(*mac); +del_login: vec_logout.push_back(*ip); + vec_logout.push_back(*mac); - continue; + continue; + } } if ((u_get_localtime(lastUpdate) / U_ONE_DAY_IN_SECOND) < midnigth) { - UString opt(200U); - - opt.snprintf(U_CONSTANT_TO_PARAM(", traffic: %llu"), counter/(1024*1024)); - - writeToLOG(U_CONSTANT_TO_PARAM("RST_SESSION"), opt); - if (policySessionId->equal(U_CONSTANT_TO_PARAM("DAILY"))) resetDeviceDailyCounter(); - counter = 0; + if (counter) + { + x.snprintf(U_CONSTANT_TO_PARAM(", traffic: %llu"), counter/1024); + + writeToLOG(U_CONSTANT_TO_PARAM("RST_SESSION"), x); + + counter = 0; + + (void) rc->hmset(U_CONSTANT_TO_PARAM("SESSION:%v counter 0"), key_session->rep); + } } if (ctraffic) { - if (ap_consume && - policySessionId->equal(U_CONSTANT_TO_PARAM("DAILY"))) - { - (void) rc->hmset(U_CONSTANT_TO_PARAM("DEVICE:id:%v pCounter %llu"), mac->rep, device_counter); - - device_counter += ctraffic; - - if (device_counter >= U_MAX_TRAFFIC_DAILY) - { - op = "DENY_POLICY"; - op_len = U_CONSTANT_SIZE("DENY_POLICY"); - - goto del_sess; - } - - (void) rc->hmset(U_CONSTANT_TO_PARAM("DEVICE:id:%v pCounter %llu"), mac->rep, device_counter); - } - (void) rc->hmset(U_CONSTANT_TO_PARAM("SESSION:%v counter %llu lastUpdate %u"), key_session->rep, counter+ctraffic, u_now->tv_sec); + + if (ap_consume && + policySessionId->equal(U_CONSTANT_TO_PARAM("DAILY")) && + rc->hincrby(U_CONSTANT_TO_PARAM("DEVICE:id:%v pCounter %llu"), mac->rep, ctraffic) >= U_MAX_TRAFFIC_DAILY) + { + op = "DENY_POLICY"; + op_len = U_CONSTANT_SIZE("DENY_POLICY"); + + goto del_sess; + } } } diff --git a/include/ulib/file.h b/include/ulib/file.h index 23c87f16..2b3c7cc5 100644 --- a/include/ulib/file.h +++ b/include/ulib/file.h @@ -1222,7 +1222,7 @@ protected: U_ASSERT(isMapped()) # ifdef HAVE_ARCH64 - U_INTERNAL_ASSERT_MINOR_MSG(map_size, (off_t)U_STRING_MAX_SIZE, "Sorry, I can't manage string size bigger than 4G...") // limit of UString + U_INTERNAL_ASSERT_MINOR_MSG((uint32_t)map_size, U_STRING_MAX_SIZE, "Sorry, I can't manage string size bigger than 4G...") // limit of UString # endif str.mmap(map, map_size); @@ -1239,7 +1239,7 @@ protected: U_INTERNAL_ASSERT_MAJOR(count, 0) U_INTERNAL_ASSERT_DIFFERS(map, MAP_FAILED) - if (count > (off_t)U_STRING_MAX_SIZE) + if ((uint64_t)count > U_STRING_MAX_SIZE) { U_WARNING("Sorry, I can't manage string size bigger than 4G...") // limit of UString diff --git a/include/ulib/internal/macro.h b/include/ulib/internal/macro.h index a0c61e13..5d9c8372 100644 --- a/include/ulib/internal/macro.h +++ b/include/ulib/internal/macro.h @@ -18,7 +18,7 @@ #define U_TIMEOUT_MS (30L * 1000L) // 30 second connection/read timeout #define U_SSL_TIMEOUT_MS (10L * 1000L) // 10 second handshake timeout -#define U_STRING_MAX_SIZE (((U_NOT_FOUND-sizeof(ustringrep))/sizeof(char))-4096) +#define U_STRING_MAX_SIZE (U_NOT_FOUND-sizeof(ustringrep)-4096U) #ifndef ENABLE_MEMPOOL # define U_CAPACITY 1024 diff --git a/include/ulib/net/client/redis.h b/include/ulib/net/client/redis.h index 4dddb560..a8672743 100644 --- a/include/ulib/net/client/redis.h +++ b/include/ulib/net/client/redis.h @@ -112,11 +112,11 @@ public: U_RETURN(0); } - void setUInt8(uint8_t& value, uint32_t i = 0, uint8_t _default = 0) + void setUInt8(uint8_t& value, uint32_t i = 0, uint8_t ldefault = 0) { - U_TRACE(0, "UREDISClient_Base::setUInt8(%p,%u,%u)", &value, i, _default) + U_TRACE(0, "UREDISClient_Base::setUInt8(%p,%u,%u)", &value, i, ldefault) - value = (getResult(i) ? x.first_char()-'0' : _default); + value = (getResult(i) ? x.first_char()-'0' : ldefault); } long getLong(uint32_t i = 0) @@ -197,7 +197,16 @@ public: return processRequest(U_RC_MULTIBULK, U_CONSTANT_TO_PARAM("MGET"), param, len); } - bool hmget(const char* format, uint32_t fmt_size, ...) // HMGET myhash field1 field2 nofield + // HMGET myhash field1 field2 nofield + + bool hmget(const UString& str) + { + U_TRACE(0, "UREDISClient_Base::hmget(%V)", str.rep) + + return processRequest(U_RC_MULTIBULK, U_CONSTANT_TO_PARAM("HMGET"), U_STRING_TO_PARAM(str)); + } + + bool hmget(const char* format, uint32_t fmt_size, ...) { U_TRACE(0, "UREDISClient_Base::hmget(%.*S,%u)", fmt_size, format, fmt_size) @@ -213,6 +222,31 @@ public: U_RETURN(ok); } + // HMSET myhash field1 "Hello" field2 "World" + + bool hmset(const UString& str) + { + U_TRACE(0, "UREDISClient_Base::hmset(%V)", str.rep) + + return processRequest(U_RC_INLINE, U_CONSTANT_TO_PARAM("HMSET"), U_STRING_TO_PARAM(str)); + } + + bool hmset(const char* format, uint32_t fmt_size, ...) + { + U_TRACE(0, "UREDISClient_Base::hmset(%.*S,%u)", fmt_size, format, fmt_size) + + bool ok; + + va_list argp; + va_start(argp, fmt_size); + + ok = processMethod(U_RC_INLINE, U_CONSTANT_TO_PARAM("HMSET"), format, fmt_size, argp); + + va_end(argp); + + U_RETURN(ok); + } + bool set(const char* key, uint32_t keylen, const char* value, uint32_t valuelen) // Set the string value of a key { U_TRACE(0, "UREDISClient_Base::set(%.*S,%u,%.*S,%u)", keylen, key, keylen, valuelen, value, valuelen) @@ -227,22 +261,6 @@ public: return processRequest(U_RC_INLINE, U_CONSTANT_TO_PARAM("MSET"), param, len); } - bool hmset(const char* format, uint32_t fmt_size, ...) // HMSET myhash field1 "Hello" field2 "World" - { - U_TRACE(0, "UREDISClient_Base::hmset(%.*S,%u)", fmt_size, format, fmt_size) - - bool ok; - - va_list argp; - va_start(argp, fmt_size); - - ok = processMethod(U_RC_INLINE, U_CONSTANT_TO_PARAM("HMSET"), format, fmt_size, argp); - - va_end(argp); - - U_RETURN(ok); - } - bool operator[](const UString& key) { return get(U_STRING_TO_PARAM(key)); } int operator+=(const char* key) // Increment the integer value of a key by one @@ -429,8 +447,6 @@ public: return processRequest(U_RC_BULK, U_CONSTANT_TO_PARAM("RANDOMKEY")); } - bool scan(const char* pattern, uint32_t len, vPFcs function); // Returns all keys matching pattern (scan 0 MATCH *11*) - bool del(const UString& keys) // Delete one or more key { U_TRACE(0, "UREDISClient_Base::del(%V)", keys.rep) @@ -438,8 +454,6 @@ public: return processRequest(U_RC_INT, U_CONSTANT_TO_PARAM("DEL"), U_STRING_TO_PARAM(keys)); } - bool deleteKeys(const char* pattern, uint32_t len); // Delete all keys matching pattern - bool del(const char* format, uint32_t fmt_size, ...) // Delete one or more key { U_TRACE(0, "UREDISClient_Base::del(%.*S,%u)", fmt_size, format, fmt_size) @@ -456,6 +470,10 @@ public: U_RETURN(ok); } + bool deleteKeys(const char* pattern, uint32_t len); // Delete all keys matching pattern + + bool scan(const char* pattern, uint32_t len, vPFcs function); // Returns all keys matching pattern (scan 0 MATCH *11*) + bool dump(const char* key, uint32_t keylen) // Return a serialized version of the value stored at the specified key { U_TRACE(0, "UREDISClient_Base::dump(%.*S,%u)", keylen, key, keylen) @@ -463,36 +481,57 @@ public: return processRequest(U_RC_BULK, U_CONSTANT_TO_PARAM("DUMP"), key, keylen); } - bool exists(const char* format, uint32_t fmt_size, ...) // EXISTS key1 + bool exists(const char* key, uint32_t keylen) // EXISTS key1 { - U_TRACE(0, "UREDISClient_Base::exists(%.*S,%u)", fmt_size, format, fmt_size) + U_TRACE(0, "UREDISClient_Base::exists(%.*S,%u)", keylen, key, keylen) - bool ok; + if (processRequest(U_RC_INT, U_CONSTANT_TO_PARAM("EXISTS"), key, keylen) && + getUInt8()) + { + U_RETURN(true); + } - va_list argp; - va_start(argp, fmt_size); - - ok = processMethod(U_RC_INT, U_CONSTANT_TO_PARAM("EXISTS"), format, fmt_size, argp); - - va_end(argp); - - U_RETURN(ok); + U_RETURN(false); } - bool hexists(const char* format, uint32_t fmt_size, ...) // HEXISTS myhash field1 + bool hexists(const char* key, uint32_t keylen, const char* field, uint32_t fieldlen) // HEXISTS myhash field1 { - U_TRACE(0, "UREDISClient_Base::hexists(%.*S,%u)", fmt_size, format, fmt_size) + U_TRACE(0, "UREDISClient_Base::hexists(%.*S,%u,%.*S,%u)", keylen, key, keylen, fieldlen, field, fieldlen) + + if (processRequest(U_RC_INT, U_CONSTANT_TO_PARAM("HEXISTS"), key, keylen, field, fieldlen) && + getUInt8()) + { + U_RETURN(true); + } + + U_RETURN(false); + } + + uint64_t hincrby(const char* key, uint32_t keylen, const char* field, uint32_t fieldlen) // HINCRBY myhash field1 + { + U_TRACE(0, "UREDISClient_Base::hincrby(%.*S,%u,%.*S,%u)", keylen, key, keylen, fieldlen, field, fieldlen) + + if (processRequest(U_RC_INT, U_CONSTANT_TO_PARAM("HINCRBY"), key, keylen, field, fieldlen)) return getUInt64(); + + U_RETURN(0ULL); + } + + uint64_t hincrby(const char* format, uint32_t fmt_size, ...) + { + U_TRACE(0, "UREDISClient_Base::hincrby(%.*S,%u)", fmt_size, format, fmt_size) bool ok; va_list argp; va_start(argp, fmt_size); - ok = processMethod(U_RC_INT, U_CONSTANT_TO_PARAM("HEXISTS"), format, fmt_size, argp); + ok = processMethod(U_RC_INT, U_CONSTANT_TO_PARAM("HINCRBY"), format, fmt_size, argp); va_end(argp); - U_RETURN(ok); + if (ok) return getUInt64(); + + U_RETURN(0ULL); } bool type(const char* key, uint32_t keylen) // Determine the type stored at key diff --git a/include/ulib/net/server/plugin/mod_nodog.h b/include/ulib/net/server/plugin/mod_nodog.h index 06a2553d..d04102a3 100644 --- a/include/ulib/net/server/plugin/mod_nodog.h +++ b/include/ulib/net/server/plugin/mod_nodog.h @@ -213,7 +213,6 @@ protected: static UVector* vLocalNetworkLabel; static UVector* vLocalNetworkMask; - static void sendLogin(); static void setNewPeer(); static void checkSystem(); static bool preallocatePeersFault(); @@ -297,11 +296,15 @@ private: U_DISALLOW_COPY_AND_ASSIGN(UNoDogPlugIn) static void setMAC() U_NO_EXPORT; + static void erasePeer() U_NO_EXPORT; + static void sendLogin() U_NO_EXPORT; static void getTraffic() U_NO_EXPORT; static void sendNotify() U_NO_EXPORT; static void eraseTimer() U_NO_EXPORT; static void setLabelAndMAC() U_NO_EXPORT; static void sendStrictNotify() U_NO_EXPORT; + + static void printPeers(const char* fmt, uint32_t len) U_NO_EXPORT; static void makeInfoData(UFlatBuffer* pfb, void* param) U_NO_EXPORT; static void makeLoginData(UFlatBuffer* pfb, void* param) U_NO_EXPORT; static void makeNotifyData(UFlatBuffer* pfb, void* param) U_NO_EXPORT; diff --git a/include/ulib/serialize/flatbuffers.h b/include/ulib/serialize/flatbuffers.h index a2003502..b969fa9e 100644 --- a/include/ulib/serialize/flatbuffers.h +++ b/include/ulib/serialize/flatbuffers.h @@ -2030,6 +2030,13 @@ private: template friend class UFlatBufferTypeHandler; }; +#ifndef U_FLAT_BUFFERS_SPACE_STACK +#define U_FLAT_BUFFERS_SPACE_STACK (8U * 1024U) +#endif +#ifndef U_FLAT_BUFFERS_SPACE_BUFFER +#define U_FLAT_BUFFERS_SPACE_BUFFER (64U * 1024U) +#endif + class U_EXPORT UFlatBufferSpace { public: @@ -2056,8 +2063,8 @@ protected: uint32_t prev_stack_size, prev_buffer_size; - uint8_t stack[ 8 * 1024], - buffer[64 * 1024]; + uint8_t stack[U_FLAT_BUFFERS_SPACE_STACK], + buffer[U_FLAT_BUFFERS_SPACE_BUFFER]; }; // Template specialization diff --git a/src/ulib/base/base.c b/src/ulib/base/base.c index b1db2d1e..0230b558 100644 --- a/src/ulib/base/base.c +++ b/src/ulib/base/base.c @@ -314,11 +314,18 @@ void u__memcpy(void* restrict dst, const void* restrict src, size_t n, const cha U_INTERNAL_ASSERT_POINTER(dst) U_INTERNAL_ASSERT_POINTER(called_by_function) - if (n == 0) U_WARNING("*** Zero copy in memcpy *** - %s", called_by_function); + if (n == 0) U_WARNING("*** Zero copy in memcpy(%p,%p,%u) *** - calleb by %s() dst = %#.*S src = %#.*S", dst, src, n, called_by_function, n, dst, n, src); + + if (dst == src) + { + U_WARNING("*** Source and Destination are EQUALS in memcpy(%p,%p,%u) *** - calleb by %s() src = %#.*S", dst, src, n, called_by_function, n, src); + + return; + } if (u_is_overlap((const char* restrict)dst, (const char* restrict)src, n)) { - U_WARNING("*** Source and Destination OVERLAP in memcpy *** - %s", called_by_function); + U_WARNING("*** Source and Destination OVERLAP in memcpy(%p,%p,%u) *** - calleb by %s() dst = %#.*S src = %#.*S", dst, src, n, called_by_function, n, dst, n, src); (void) apex_memmove(dst, src, n); } @@ -1643,17 +1650,17 @@ uint32_t u__vsnprintf(char* restrict buffer, uint32_t buffer_size, const char* r { U_INTERNAL_ASSERT_MAJOR(fmt_size, 0) - u__memcpy(bp, fmark, fmt_size, __PRETTY_FUNCTION__); - bp += fmt_size; + (void) memcpy(bp, fmark, fmt_size); + bp += fmt_size; break; } if ((n = (fp - fmark))) { - u__memcpy(bp, fmark, n, __PRETTY_FUNCTION__); - bp += n; - fmt_size -= n; + (void) memcpy(bp, fmark, n); + bp += n; + fmt_size -= n; } /* init var */ @@ -2191,7 +2198,7 @@ case_D: /* extension: print date and time in various format */ case_H: /* extension: print host name */ U_INTERNAL_ERROR(u_hostname_len, "HOSTNAME NULL at u__vsnprintf() - CHECK THE PARAMETERS - format = \"%.*s\"", format_size_save, format); - u__memcpy(bp, u_hostname, u_hostname_len, __PRETTY_FUNCTION__); + (void) memcpy(bp, u_hostname, u_hostname_len); bp += u_hostname_len; @@ -2230,14 +2237,14 @@ case_M: /* extension: print memory dump */ continue; case_N: /* extension: print program name */ - u__memcpy(bp, u_progname, u_progname_len, __PRETTY_FUNCTION__); + (void) memcpy(bp, u_progname, u_progname_len); bp += u_progname_len; continue; case_P: /* extension: print process pid */ - u__memcpy(bp, u_pid_str, u_pid_str_len, __PRETTY_FUNCTION__); + (void) memcpy(bp, u_pid_str, u_pid_str_len); bp += u_pid_str_len; @@ -2257,7 +2264,7 @@ case_R: /* extension: print msg - u_getSysError() */ { len = u__strlen((const char* restrict)cp, __PRETTY_FUNCTION__); - u__memcpy(bp, cp, len, __PRETTY_FUNCTION__); + (void) memcpy(bp, cp, len); bp += len; } @@ -2279,7 +2286,7 @@ case_R: /* extension: print msg - u_getSysError() */ cp = getSysError_w32((uint32_t*)&len); - u__memcpy(bp, cp, len, __PRETTY_FUNCTION__); + (void) memcpy(bp, cp, len); bp += len; @@ -2294,7 +2301,7 @@ case_R: /* extension: print msg - u_getSysError() */ u_getSysError((uint32_t*)&len); - u__memcpy(bp, u_err_buffer, len, __PRETTY_FUNCTION__); + (void) memcpy(bp, u_err_buffer, len); bp += len; @@ -2310,7 +2317,7 @@ case_T: /* extension: print time_t */ case_U: /* extension: print user name */ U_INTERNAL_ERROR(u_user_name_len, "USER NAME NULL at u__vsnprintf() - CHECK THE PARAMETERS - format = \"%.*s\"", format_size_save, format); - u__memcpy(bp, u_user_name, u_user_name_len, __PRETTY_FUNCTION__); + (void) memcpy(bp, u_user_name, u_user_name_len); bp += u_user_name_len; @@ -2336,7 +2343,7 @@ case_W: /* extension: print COLOR (ANSI ESCAPE STR) */ len = sizeof(U_RESET_STR) - (n == RESET); - u__memcpy(bp, tab_color[n], len, __PRETTY_FUNCTION__); + (void) memcpy(bp, tab_color[n], len); bp += len; } @@ -2444,7 +2451,7 @@ number: /* uint32_t conversions */ case_Y: /* extension: print u_getSysSignal(signo) */ u_getSysSignal(VA_ARG(int), (uint32_t*)&len); - u__memcpy(bp, u_err_buffer, len, __PRETTY_FUNCTION__); + (void) memcpy(bp, u_err_buffer, len); bp += len; @@ -2581,7 +2588,7 @@ case_q: /* field length modifier: quad. This is a synonym for ll */ case_r: /* extension: print u_getExitStatus(exit_value) */ u_getExitStatus(VA_ARG(int), (uint32_t*)&len); - u__memcpy(bp, u_err_buffer, len, __PRETTY_FUNCTION__); + (void) memcpy(bp, u_err_buffer, len); bp += len; @@ -2606,7 +2613,7 @@ case_v: /* extension: print ustring */ case_w: /* extension: print current working directory */ U_INTERNAL_ERROR(u_cwd_len, "CURRENT WORKING DIRECTORY NULL at u__vsnprintf() - CHECK THE PARAMETERS - format = \"%.*s\"", format_size_save, format); - u__memcpy(bp, u_cwd, u_cwd_len, __PRETTY_FUNCTION__); + (void) memcpy(bp, u_cwd, u_cwd_len); bp += u_cwd_len; @@ -2710,7 +2717,7 @@ next: U_INTERNAL_ERROR(ret <= buffer_size, "BUFFER OVERFLOW at u__vsnprintf() ret = %u buffer_size = %u format = \"%.*s\"", ret, buffer_size, format_size_save, format); - u__memcpy(bp, cp, size, __PRETTY_FUNCTION__); + (void) memcpy(bp, cp, size); bp += size; } diff --git a/src/ulib/file.cpp b/src/ulib/file.cpp index e368ec32..8bac733b 100644 --- a/src/ulib/file.cpp +++ b/src/ulib/file.cpp @@ -695,39 +695,28 @@ bool UFile::memmap(int prot, UString* str, off_t start, off_t count) map_size = 0; } - map = (char*) U_SYSCALL(mmap, "%p,%u,%d,%d,%d,%I", U_NULLPTR, count, prot, flags, fd, start); + map = (char*) U_SYSCALL(mmap, "%p,%I,%d,%d,%d,%I", U_NULLPTR, count, prot, flags, fd, start); if (map != (char*)MAP_FAILED) { map_size = count; - if (str) + if (str == U_NULLPTR) U_RETURN(true); + + count -= resto; + + U_INTERNAL_DUMP("count = %I U_STRING_MAX_SIZE = %u", count, U_STRING_MAX_SIZE) + + if ((uint64_t)count < U_STRING_MAX_SIZE) { - count -= resto; - - if (count > (off_t)U_STRING_MAX_SIZE) - { - U_WARNING("Sorry, I can't manage string size bigger than 4G...") // limit of UString - - U_RETURN(false); - } - str->mmap(map+resto, count); map = (char*)MAP_FAILED; // transfer the ownership to string + + U_RETURN(true); } - /* -# if defined(U_LINUX) && defined(MADV_SEQUENTIAL) - if (prot == PROT_READ && - length > (32 * PAGESIZE)) - { - (void) U_SYSCALL(madvise, "%p,%I,%d", (void*)map, map_size, MADV_SEQUENTIAL); - } -# endif - */ - - U_RETURN(true); + U_WARNING("Sorry, I can't manage string size bigger than 4G...") // limit of UString } U_RETURN(false); diff --git a/src/ulib/internal/common.cpp b/src/ulib/internal/common.cpp index 794cdc8b..5a772320 100644 --- a/src/ulib/internal/common.cpp +++ b/src/ulib/internal/common.cpp @@ -198,7 +198,7 @@ void ULib::init(char** argv, const char* mempool) if (ptr < u_buffer) u_buffer = (char*)ptr; - u_err_buffer = (char*) UMemoryPool::pop(U_SIZE_TO_STACK_INDEX(256)); + if (u_err_buffer == U_NULLPTR) u_err_buffer = (char*) UMemoryPool::pop(U_SIZE_TO_STACK_INDEX(256)); U_INTERNAL_DUMP("ptr = %p u_buffer = %p diff = %ld", ptr, u_buffer, ptr - u_buffer) @@ -206,8 +206,9 @@ void ULib::init(char** argv, const char* mempool) UMemoryError::pbuffer = (char*) UMemoryPool::pop(U_SIZE_TO_STACK_INDEX(U_MAX_SIZE_PREALLOCATE)); # endif #else - u_buffer = (char*) U_SYSCALL(malloc, "%u", U_BUFFER_SIZE); - u_err_buffer = (char*) U_SYSCALL(malloc, "%u", 256); + u_buffer = (char*) U_SYSCALL(malloc, "%u", U_BUFFER_SIZE); + + if (u_err_buffer == U_NULLPTR) u_err_buffer = (char*) U_SYSCALL(malloc, "%u", 256); # ifdef DEBUG UMemoryError::pbuffer = (char*) U_SYSCALL(malloc, "%u", U_MAX_SIZE_PREALLOCATE); diff --git a/src/ulib/internal/memory_pool.cpp b/src/ulib/internal/memory_pool.cpp index ff2b6bd9..e7986515 100644 --- a/src/ulib/internal/memory_pool.cpp +++ b/src/ulib/internal/memory_pool.cpp @@ -303,9 +303,12 @@ void UMemoryPool::allocateMemoryBlocks(const char* ptr) if (UFile::rlimit_memfree == U_2M) { # ifdef DEBUG - char buffer[256]; + if (u_err_buffer == U_NULLPTR) + { + static char buffer[256]; - if (u_err_buffer == U_NULLPTR) u_err_buffer = buffer; + u_err_buffer = buffer; + } # endif // cat /proc/meminfo | grep Huge diff --git a/src/ulib/net/server/plugin/mod_nodog.cpp b/src/ulib/net/server/plugin/mod_nodog.cpp index a9df6020..16ae432c 100644 --- a/src/ulib/net/server/plugin/mod_nodog.cpp +++ b/src/ulib/net/server/plugin/mod_nodog.cpp @@ -11,6 +11,13 @@ // // ============================================================================ +#include + +#ifndef HAVE_ARCH64 +# define U_FLAT_BUFFERS_SPACE_STACK 1024U +# define U_FLAT_BUFFERS_SPACE_BUFFER 1024U +#endif + #include #include #include @@ -198,7 +205,7 @@ U_NO_EXPORT void UNoDogPlugIn::getTraffic() ip.snprintf(U_CONSTANT_TO_PARAM("%u.%u.%u.%u"), bytep[0], bytep[1], bytep[2], bytep[3]); # endif - U_DEBUG("IP: %v SRC packets: %u bytes: %u DST packets: %u bytes: %u", ip.rep, entry->src_packets, entry->src_bytes, entry->dst_packets, entry->dst_bytes) + U_SRV_LOG("IP: %v SRC packets: %u bytes: %u DST packets: %u bytes: %u", ip.rep, entry->src_packets, entry->src_bytes, entry->dst_packets, entry->dst_bytes); peer = (*peers)[ip]; @@ -249,7 +256,7 @@ bool UNoDogPlugIn::getPeerInfo(UStringRep* key, void* value) { if (U_peer_permit == false) { - U_WARNING("Peer IP %v MAC %v has made traffic(%u bytes) but it has status DENY", peer->ip.rep, peer->mac.rep, peer->ctraffic); + U_SRV_LOG("WARNING: Peer IP %v MAC %v has made traffic(%u bytes) but it has status DENY", peer->ip.rep, peer->mac.rep, peer->ctraffic); } pfb->UInt(_ctime); @@ -292,8 +299,8 @@ U_NO_EXPORT void UNoDogPlugIn::makeNotifyData(UFlatBuffer* _pfb, void* param) U_INTERNAL_DUMP("peer->mac = %V peer->ip = %V peer->label = %V", peer->mac.rep, peer->ip.rep, peer->label.rep) - U_INTERNAL_ASSERT(u_isIPv4Addr(U_STRING_TO_PARAM(peer->ip))) U_INTERNAL_ASSERT(u_isMacAddr(U_STRING_TO_PARAM(peer->mac))) + U_INTERNAL_ASSERT(u_isIPv4Addr(U_STRING_TO_PARAM(peer->ip))) _pfb->String(getApInfo(peer->label)); _pfb->String(peer->getMAC()); @@ -362,6 +369,7 @@ U_NO_EXPORT void UNoDogPlugIn::setMAC() U_INTERNAL_DUMP("peer->mac = %V", peer->mac.rep) U_INTERNAL_ASSERT(peer->mac) + U_INTERNAL_ASSERT(u_isMacAddr(U_STRING_TO_PARAM(peer->mac))) U_ASSERT_EQUALS(peer->mac, USocketExt::getMacAddress(peer->ip)) } } @@ -497,6 +505,35 @@ void UNoDogPlugIn::setNewPeer() peers->insert(peer->ip, peer); } +U_NO_EXPORT void UNoDogPlugIn::printPeers(const char* msg, uint32_t len) +{ + U_TRACE(0, "UNoDogPlugIn::printPeers(%.*S,%u)", len, msg, len) + +#if defined(DEBUG) && !defined(U_LOG_DISABLE) + if (UServer_Base::isLog()) + { + typedef UHashMap uhashpeer; + + UServer_Base::log->log(U_CONSTANT_TO_PARAM("[nodog] %.*S peers = %.*S"), len, msg, UObjectIO::buffer_output_len, UObject2String(*peers)); + } +#endif +} + +U_NO_EXPORT void UNoDogPlugIn::erasePeer() +{ + U_TRACE_NO_PARAM(0, "UNoDogPlugIn::erasePeer()") + + U_INTERNAL_ASSERT_POINTER(peer) + + printPeers(U_CONSTANT_TO_PARAM("before erase")); + + delete peers->erase(peer->ip); + + printPeers(U_CONSTANT_TO_PARAM("after erase")); + + U_ASSERT_EQUALS(peers->at(peer->ip), U_NULLPTR) +} + U_NO_EXPORT void UNoDogPlugIn::eraseTimer() { U_TRACE_NO_PARAM(0, "UNoDogPlugIn::eraseTimer()") @@ -509,6 +546,15 @@ U_NO_EXPORT void UNoDogPlugIn::eraseTimer() } } +U_NO_EXPORT void UNoDogPlugIn::sendLogin() +{ + U_TRACE_NO_PARAM(0, "UNoDogPlugIn::sendLogin()") + + UFlatBufferSpace space; + + (void) client->sendPOSTRequestAsync(UFlatBuffer::toVector(makeLoginData), *auth_login, true); +} + U_NO_EXPORT void UNoDogPlugIn::sendNotify() { U_TRACE_NO_PARAM(0, "UNoDogPlugIn::sendNotify()") @@ -517,6 +563,8 @@ U_NO_EXPORT void UNoDogPlugIn::sendNotify() { U_peer_flag |= U_PEER_NOTIFY_DISABLE; + UFlatBufferSpace space; + (void) client->sendPOSTRequestAsync(UFlatBuffer::toVector(makeNotifyData), *auth_notify, true); } } @@ -529,6 +577,8 @@ U_NO_EXPORT void UNoDogPlugIn::sendStrictNotify() { U_peer_flag |= U_PEER_STRICT_NOTIFY_DISABLE; + UFlatBufferSpace space; + (void) client->sendPOSTRequestAsync(UFlatBuffer::toVector(makeNotifyData), *auth_strict_notify, true); } } @@ -979,6 +1029,7 @@ int UNoDogPlugIn::handlerRequest() U_INTERNAL_ASSERT(peer->mac) U_INTERNAL_ASSERT(peer->welcome) + U_INTERNAL_ASSERT(u_isMacAddr(U_STRING_TO_PARAM(peer->mac))) U_SRV_LOG("request to validate login for peer IP %v MAC %v: bdeny = %b policy = %C", peer->ip.rep, peer->mac.rep, bdeny, policy); @@ -988,7 +1039,7 @@ int UNoDogPlugIn::handlerRequest() if (U_peer_permit) deny(); - delete peers->erase(peer->ip); + erasePeer(); U_peer_flag |= U_PEER_ALLOW_DISABLE; @@ -1029,7 +1080,7 @@ int UNoDogPlugIn::handlerRequest() if (data.empty()) { - U_WARNING("AUTH request to logout users tampered"); + U_SRV_LOG("WARNING: AUTH request to logout users tampered"); goto bad; } @@ -1073,7 +1124,7 @@ next: if (U_peer_permit) deny(); U_SRV_LOG("AUTH request to logout user with status DENY: IP %v MAC %v", peer->ip.rep, peer->mac.rep); } - delete peers->erase(peer->ip); + erasePeer(); } } else if (U_HTTP_URI_STREQ("/ping")) @@ -1087,7 +1138,10 @@ bad: UHTTP::setBadRequest(); goto end; } - if ((peer = peers->at(U_CLIENT_ADDRESS_TO_PARAM))) + printPeers(U_CONSTANT_TO_PARAM("user request")); + + if (peers->empty() == false && + (peer = peers->at(U_CLIENT_ADDRESS_TO_PARAM))) { // ----------------- // request from user @@ -1096,12 +1150,12 @@ bad: UHTTP::setBadRequest(); U_INTERNAL_ASSERT(peer->mac) U_INTERNAL_ASSERT(peer->welcome) U_ASSERT(peer->ip.equal(U_CLIENT_ADDRESS_TO_PARAM)) + U_INTERNAL_ASSERT(u_isMacAddr(U_STRING_TO_PARAM(peer->mac))) if (U_peer_allow_disable == false && U_HTTP_URI_MEMEQ("/nodog_peer_allow.sh")) { - if (U_HTTP_QUERY_MEMEQ("url=") && - UHTTP::processForm() == 2*2) + if (U_HTTP_QUERY_MEMEQ("url=")) { /** * open firewall, respond with redirect to original request @@ -1110,10 +1164,19 @@ bad: UHTTP::setBadRequest(); * $2 -> forced ('0'|'1') */ - UHTTP::getFormValue(redirect, U_CONSTANT_TO_PARAM("url"), 0, 1, 4); - UHTTP::getFormValue(x, U_CONSTANT_TO_PARAM("forced"), 0, 3, 4); + bool forced = false; + uint32_t n = UHTTP::processForm(); - if (x.first_char() == '1') // forced + UHTTP::getFormValue(redirect, U_CONSTANT_TO_PARAM("url"), 0, 1, n); + + if (n == 2*2) + { + UHTTP::getFormValue(x, U_CONSTANT_TO_PARAM("forced"), 0, 3, 4); + + if (x.first_char() == '1') forced = true; + } + + if (forced) { sendStrictNotify(); @@ -1125,12 +1188,12 @@ bad: UHTTP::setBadRequest(); if (T2 < 3600 && U_peer_policy != '2') // (strict notify) { + sendNotify(); + next1: eraseTimer(); if (U_peer_permit == false) permit(); - sendNotify(); - UHTTP::setRedirectResponse(UHTTP::NO_BODY, U_STRING_TO_PARAM(redirect)); } } @@ -1190,7 +1253,7 @@ next1: eraseTimer(); setNewPeer(); - (void) client->sendPOSTRequestAsync(UFlatBuffer::toVector(makeLoginData), *auth_login, true); + sendLogin(); (void) redirect.reserve(8 + U_http_host_len + U_HTTP_URI_QUERY_LEN); diff --git a/src/ulib/string.cpp b/src/ulib/string.cpp index e125d0bb..d268afb2 100644 --- a/src/ulib/string.cpp +++ b/src/ulib/string.cpp @@ -705,6 +705,8 @@ UStringRep* UStringRep::create(uint32_t length, uint32_t need, const char* ptr) if (length && ptr) { + U_INTERNAL_ASSERT_DIFFERS(_ptr, ptr) + U_MEMCPY((void*)_ptr, ptr, length); _ptr[length] = '\0'; diff --git a/src/ulib/utility/interrupt.cpp b/src/ulib/utility/interrupt.cpp index c6e03c35..d2ac5f61 100644 --- a/src/ulib/utility/interrupt.cpp +++ b/src/ulib/utility/interrupt.cpp @@ -388,6 +388,10 @@ void UInterrupt::getSignalInfo(int signo, siginfo_t* info) CYAN, (double)rss / (1024.0 * 1024.0), YELLOW); } # endif + +#if defined(DEBUG) && defined(U_SERVER_CAPTIVE_PORTAL) && !defined(ENABLE_THREAD) + UError::stackDump(); +#endif } __noreturn RETSIGTYPE UInterrupt::handlerInterruptWithInfo(int signo, siginfo_t* info, void* context) diff --git a/tests/examples/nodog.sh b/tests/examples/nodog.sh index dfd75e5c..8a44b005 100755 --- a/tests/examples/nodog.sh +++ b/tests/examples/nodog.sh @@ -74,7 +74,7 @@ EOF DIR_CMD="../../examples/userver" #STRACE=$TRUSS -VALGRIND='valgrind --leak-check=yes --track-origins=yes' +#VALGRIND='valgrind --leak-check=yes --track-origins=yes' start_prg_background userver_tcp -c inp/webserver.cfg wait_server_ready localhost 5280