diff --git a/include/ulib/command.h b/include/ulib/command.h index b73b7a28..e560c152 100644 --- a/include/ulib/command.h +++ b/include/ulib/command.h @@ -152,11 +152,11 @@ public: { U_TRACE(0, "UCommand::getArgument(%d)", n) - char* result = (argv_exec ? argv_exec[n] : 0); + char* arg = (argv_exec ? argv_exec[n] : 0); - U_INTERNAL_ASSERT(result == 0 || u_isText((const unsigned char*)result, u__strlen(result, __PRETTY_FUNCTION__))) + U_INTERNAL_ASSERT(arg == 0 || u_isText((const unsigned char*)arg, u__strlen(arg, __PRETTY_FUNCTION__))) - U_RETURN(result); + U_RETURN(arg); } void setNumArgument(int32_t n = 1, bool bfree = false); @@ -217,9 +217,9 @@ public: U_INTERNAL_ASSERT(command) - bool result = (strncmp(command.data(), U_CONSTANT_TO_PARAM(U_PATH_SHELL)) == 0); + if (strncmp(command.data(), U_CONSTANT_TO_PARAM(U_PATH_SHELL)) == 0) U_RETURN(true); - U_RETURN(result); + U_RETURN(false); } char* getCommand() const __pure { return getArgument(isShellScript() ? 2 : 0); } @@ -252,9 +252,9 @@ public: U_INTERNAL_ASSERT_POINTER(argv_exec) - bool result = (U_SYSCALL(access, "%S,%d", argv_exec[0], mode) == 0); + if (U_SYSCALL(access, "%S,%d", argv_exec[0], mode) == 0) U_RETURN(true); - U_RETURN(result); + U_RETURN(false); } // MANAGE MESSAGE ERROR @@ -263,18 +263,18 @@ public: { U_TRACE_NO_PARAM(0, "UCommand::isStarted()") - bool result = (pid > 0); + if (pid > 0) U_RETURN(true); - U_RETURN(result); + U_RETURN(false); } static bool isTimeout() { U_TRACE_NO_PARAM(0, "UCommand::isTimeout()") - bool result = (exit_value == -EAGAIN); + if (exit_value == -EAGAIN) U_RETURN(true); - U_RETURN(result); + U_RETURN(false); } static void printMsgError() diff --git a/include/ulib/container/hash_map.h b/include/ulib/container/hash_map.h index a0cd1bb1..f2f9b1bf 100644 --- a/include/ulib/container/hash_map.h +++ b/include/ulib/container/hash_map.h @@ -851,6 +851,11 @@ public: UHashMap::insertAfterFind(_key, str.rep); } + // OPERATOR + + bool operator==(const UHashMap& v) __pure; + bool operator!=(const UHashMap& v) { return ! operator==(v); } + // OPERATOR [] UString operator[](const char* _key); diff --git a/include/ulib/dynamic/plugin.h b/include/ulib/dynamic/plugin.h index 98f3ee0a..1dc94b88 100644 --- a/include/ulib/dynamic/plugin.h +++ b/include/ulib/dynamic/plugin.h @@ -53,9 +53,9 @@ public: { U_TRACE_NO_PARAM(0, "UPlugIn::empty()") - bool result = (first == 0); + if (first == 0) U_RETURN(true); - U_RETURN(result); + U_RETURN(false); } static UPlugIn* getObjWrapper(void* obj) __pure; diff --git a/include/ulib/json/value.h b/include/ulib/json/value.h index d5d36a8f..8beef9a3 100644 --- a/include/ulib/json/value.h +++ b/include/ulib/json/value.h @@ -530,8 +530,10 @@ public: static int jread_error; static uint32_t jread_elements, jread_pos; - static bool jfind(const UString& json, const UString& query, UString& result); - static int jread(const UString& json, const UString& query, UString& result, uint32_t* queryParams = 0); + static int jread(const UString& json, const UString& query, UString& result, uint32_t* queryParams = 0); + static bool jfind(const UString& json, const char* query, uint32_t quey_len, UString& result); + + static bool jfind(const UString& json, const UString& query, UString& result) { return jfind(json, U_STRING_TO_PARAM(query), result); } // reads one value from an array diff --git a/include/ulib/mime/entity.h b/include/ulib/mime/entity.h index e9a9b1bf..0555e9ba 100644 --- a/include/ulib/mime/entity.h +++ b/include/ulib/mime/entity.h @@ -82,9 +82,9 @@ public: { U_TRACE_NO_PARAM(0, "UMimeEntity::isEmpty()") - bool result = content.empty(); + if (content.empty()) U_RETURN(true); - U_RETURN(result); + U_RETURN(false); } void clear() @@ -189,21 +189,27 @@ public: UString value = getContentDisposition(); - bool result = (value.empty() == false && - U_STRING_FIND(value, 0, "attachment") != U_NOT_FOUND); + if (value.empty() == false && + U_STRING_FIND(value, 0, "attachment") != U_NOT_FOUND) + { + U_RETURN(true); + } - U_RETURN(result); + U_RETURN(false); } bool isBodyMessage() const { U_TRACE_NO_PARAM(0, "UMimeEntity::isBodyMessage()") - bool result = (isText() && - UMimeHeader::getValueAttributeFromKeyValue(content_type, U_CONSTANT_TO_PARAM("name"), false).empty() && - isAttachment() == false); + if (isText() && + UMimeHeader::getValueAttributeFromKeyValue(content_type, U_CONSTANT_TO_PARAM("name"), false).empty() && + isAttachment() == false) + { + U_RETURN(true); + } - U_RETURN(result); + U_RETURN(false); } UString getFileName() const { return UMimeHeader::getFileName(getContentDisposition()); } @@ -312,9 +318,9 @@ public: // DEBUG -# ifdef DEBUG +# ifdef DEBUG const char* dump(bool reset) const; -# endif +# endif #endif protected: @@ -391,9 +397,9 @@ public: // DEBUG -# ifdef DEBUG +# ifdef DEBUG const char* dump(bool reset) const; -# endif +# endif #endif protected: @@ -414,9 +420,13 @@ protected: { U_TRACE_NO_PARAM(0, "UMimeMultipart::isEmpty()") - bool result = (UMimeEntity::isEmpty() && getNumBodyPart() == 0); + if (UMimeEntity::isEmpty() && + getNumBodyPart() == 0) + { + U_RETURN(true); + } - U_RETURN(result); + U_RETURN(false); } void setEmpty() diff --git a/include/ulib/mime/header.h b/include/ulib/mime/header.h index 7ade325c..33ca37da 100644 --- a/include/ulib/mime/header.h +++ b/include/ulib/mime/header.h @@ -189,9 +189,10 @@ public: U_ASSERT(empty() == false) - bool result = getHeader(U_CONSTANT_TO_PARAM("Connection")).equal(U_CONSTANT_TO_PARAM("close")); + if (getHeader(U_CONSTANT_TO_PARAM("Connection")).equal(U_CONSTANT_TO_PARAM("close"))) - U_RETURN(result); + U_RETURN(true); + U_RETURN(false); } // Transfer-Encoding: chunked @@ -202,9 +203,9 @@ public: U_ASSERT(empty() == false) - bool result = (getHeader(U_CONSTANT_TO_PARAM("Transfer-Encoding")) == *UString::str_chunked); + if (getHeader(U_CONSTANT_TO_PARAM("Transfer-Encoding")) == *UString::str_chunked) U_RETURN(true); - U_RETURN(result); + U_RETURN(false); } // Cookie @@ -228,9 +229,9 @@ public: U_ASSERT(empty() == false) - bool result = containsHeader(U_CONSTANT_TO_PARAM("Set-Cookie")); + if (containsHeader(U_CONSTANT_TO_PARAM("Set-Cookie"))) U_RETURN(true); - U_RETURN(result); + U_RETURN(false); } // Location @@ -276,10 +277,13 @@ public: { U_TRACE_NO_PARAM(0, "UMimeHeader::isMime()") - bool result = ((table.empty() == false) && - (getMimeVersion().empty() == false)); + if (table.empty() == false && + getMimeVersion().empty() == false) + { + U_RETURN(true); + } - U_RETURN(result); + U_RETURN(false); } /** @@ -311,10 +315,11 @@ public: if (content_type) { - bool result = (ignore_case ? u__strncasecmp(content_type.data(), type, len) - : strncmp(content_type.data(), type, len)) == 0; - - U_RETURN(result); + if ((ignore_case ? u__strncasecmp(content_type.data(), type, len) + : strncmp(content_type.data(), type, len)) == 0) + { + U_RETURN(true); + } } U_RETURN(false); diff --git a/include/ulib/net/client/client.h b/include/ulib/net/client/client.h index 17ab117d..ceaba705 100644 --- a/include/ulib/net/client/client.h +++ b/include/ulib/net/client/client.h @@ -129,9 +129,7 @@ public: { U_TRACE_NO_PARAM(0, "UClient_Base::reset()") -# ifdef DEBUG uri.clear(); // NB: to avoid DEAD OF SOURCE STRING WITH CHILD ALIVE... (uri can be a substr of url) -# endif url.clear(); } diff --git a/include/ulib/net/client/http.h b/include/ulib/net/client/http.h index c3f4f2ec..d32c32ba 100644 --- a/include/ulib/net/client/http.h +++ b/include/ulib/net/client/http.h @@ -101,9 +101,9 @@ public: { U_TRACE_NO_PARAM(0, "UHttpClient_Base::isPasswordAuthentication()") - bool result = (user && password); + if (user && password) U_RETURN(true); - U_RETURN(result); + U_RETURN(false); } void setRequestPasswordAuthentication(const UString& _user, const UString& _password) diff --git a/include/ulib/net/client/mongodb.h b/include/ulib/net/client/mongodb.h index efe59409..050d710c 100644 --- a/include/ulib/net/client/mongodb.h +++ b/include/ulib/net/client/mongodb.h @@ -82,7 +82,7 @@ public: BSON_APPEND_INT32(query, "_id", value); - bool result = find(query); + bool result = find(query, 0); U_SYSCALL_VOID(bson_destroy, "%p", query); @@ -102,7 +102,7 @@ public: bson_t* query = (bson_t*) U_SYSCALL_NO_PARAM(bson_new); - bool result = find(query); + bool result = find(query, 0); U_SYSCALL_VOID(bson_destroy, "%p", query); @@ -122,6 +122,8 @@ public: bool findOne(const char* json, uint32_t len); + bool find(bson_t* query, bson_t* projection); + bool update(bson_t* query, bson_t* update); bool findAndModify(bson_t* query, bson_t* update); @@ -143,8 +145,6 @@ protected: mongoc_client_t* client; mongoc_cursor_t* cursor; mongoc_collection_t* collection; - - bool find(bson_t* query); #endif private: diff --git a/include/ulib/net/ipaddress.h b/include/ulib/net/ipaddress.h index 39c1c6c5..58918f4a 100644 --- a/include/ulib/net/ipaddress.h +++ b/include/ulib/net/ipaddress.h @@ -125,9 +125,13 @@ public: { U_TRACE_NO_PARAM(0, "UIPAllow::isEmpty()") - bool result = (device.empty() || host.empty()); + if (device.empty() || + host.empty()) + { + U_RETURN(true); + } - U_RETURN(result); + U_RETURN(false); } static bool getNetworkInterface(UVector& vipallow); @@ -292,11 +296,14 @@ public: { U_TRACE(0, "UIPAddress::operator==(%p)", &cOtherAddr) - bool result = (iAddressType == cOtherAddr.iAddressType) && - (iAddressLength == cOtherAddr.iAddressLength) && - (memcmp(pcAddress.p, cOtherAddr.pcAddress.p, iAddressLength) == 0); + if (iAddressType == cOtherAddr.iAddressType && + iAddressLength == cOtherAddr.iAddressLength && + (memcmp(pcAddress.p, cOtherAddr.pcAddress.p, iAddressLength) == 0)) + { + U_RETURN(true); + } - U_RETURN(result); + U_RETURN(false); } bool operator!=(const UIPAddress& cOtherAddr) const { return !operator==(cOtherAddr); } diff --git a/include/ulib/timeval.h b/include/ulib/timeval.h index cd16f275..ca7b2b56 100644 --- a/include/ulib/timeval.h +++ b/include/ulib/timeval.h @@ -107,19 +107,26 @@ public: { U_TRACE_NO_PARAM(0, "UTimeVal::isZero()") - bool result = (tv_sec == 0L && - tv_usec <= 1L); + if (tv_sec == 0L && + tv_usec <= 1L) + { + U_RETURN(true); + } - U_RETURN(result); + U_RETURN(false); } bool isNegativ() const { U_TRACE_NO_PARAM(0,"UTimeVal::isNegativ()") - bool result = (tv_sec < 0L || tv_usec < 0L); + if (tv_sec < 0L || + tv_usec < 0L) + { + U_RETURN(true); + } - U_RETURN(result); + U_RETURN(false); } bool notZero() const { return (isZero() == false); } @@ -155,9 +162,9 @@ public: U_CHECK_MEMORY - long result = tv_sec + (tv_usec >= 500000L ? 1L : 0L); + long sec = tv_sec + (tv_usec >= 500000L ? 1L : 0L); - U_RETURN(result); + U_RETURN(sec); } long getMilliSecond() const @@ -204,9 +211,13 @@ public: U_CHECK_MEMORY - bool result = (tv_sec == t.tv_sec && tv_usec == t.tv_usec); + if (tv_sec == t.tv_sec && + tv_usec == t.tv_usec) + { + U_RETURN(true); + } - U_RETURN(result); + U_RETURN(false); } bool operator==(const UTimeVal& t) const @@ -215,9 +226,13 @@ public: U_CHECK_MEMORY - bool result = (tv_sec == t.tv_sec && tv_usec == t.tv_usec); + if (tv_sec == t.tv_sec && + tv_usec == t.tv_usec) + { + U_RETURN(true); + } - U_RETURN(result); + U_RETURN(false); } bool operator< (const UTimeVal& t) const __pure; @@ -343,10 +358,14 @@ public: U_INTERNAL_ASSERT_RANGE(0L, tv_usec, U_SECOND) - bool result = (tv_sec > t->tv_sec || - (tv_sec == t->tv_sec && ((tv_usec * 1000L) > t->tv_nsec))); + if ( tv_sec > t->tv_sec || + (tv_sec == t->tv_sec && + ((tv_usec * 1000L) > t->tv_nsec))) + { + U_RETURN(true); + } - U_RETURN(result); + U_RETURN(false); } // SERVICES diff --git a/include/ulib/tokenizer.h b/include/ulib/tokenizer.h index 33a89ac9..27fa9f1b 100644 --- a/include/ulib/tokenizer.h +++ b/include/ulib/tokenizer.h @@ -60,9 +60,9 @@ public: { U_TRACE_NO_PARAM(0, "UTokenizer::atEnd()") - bool result = (s >= end); + if (s >= end) U_RETURN(true); - U_RETURN(result); + U_RETURN(false); } void setDelimiter(const char* sep) diff --git a/include/ulib/url.h b/include/ulib/url.h index 32bbeb90..e90207e8 100644 --- a/include/ulib/url.h +++ b/include/ulib/url.h @@ -148,13 +148,13 @@ public: void set(const Url& u) { service_end = u.service_end; - user_begin = u.user_begin; - user_end = u.user_end; - host_begin = u.host_begin; - host_end = u.host_end; - path_begin = u.path_begin; - path_end = u.path_end; - query = u.query; + user_begin = u.user_begin; + user_end = u.user_end; + host_begin = u.host_begin; + host_end = u.host_end; + path_begin = u.path_begin; + path_end = u.path_end; + query = u.query; } Url(const Url& u) : url(u.url) @@ -198,7 +198,14 @@ public: url.clear(); - service_end = user_begin = user_end = host_begin = host_end = path_begin = path_end = query = -1; + service_end = + user_begin = + user_end = + host_begin = + host_end = + path_begin = + path_end = + query = -1; } /** @@ -216,36 +223,45 @@ public: { U_TRACE_NO_PARAM(0, "Url::isHTTP()") - bool result = (getService() == *UString::str_http); + if (service_end == 4 && + UString::str_http->equal(url.data(), (uint32_t)service_end)) + { + U_RETURN(true); + } - U_RETURN(result); + U_RETURN(false); } bool isHTTPS() const { U_TRACE_NO_PARAM(0, "Url::isHTTPS()") - bool result = getService().equal(U_CONSTANT_TO_PARAM("https")); + if (service_end == 5 && + url.c_char(4) == 's' && + UString::str_http->equal(url.data(), 4)) + { + U_RETURN(true); + } - U_RETURN(result); + U_RETURN(false); } bool isLDAP() const { U_TRACE_NO_PARAM(0, "Url::isLDAP()") - bool result = getService().equal(U_CONSTANT_TO_PARAM("ldap")); + if (getService().equal(U_CONSTANT_TO_PARAM("ldap"))) U_RETURN(true); - U_RETURN(result); + U_RETURN(false); } bool isLDAPS() const { U_TRACE_NO_PARAM(0, "Url::isLDAPS()") - bool result = getService().equal(U_CONSTANT_TO_PARAM("ldaps")); + if (getService().equal(U_CONSTANT_TO_PARAM("ldaps"))) U_RETURN(true); - U_RETURN(result); + U_RETURN(false); } /** @@ -304,9 +320,11 @@ public: { U_TRACE_NO_PARAM(0, "Url::isLocalFile()") - bool result = (host_begin < host_end ? true : false); // Is there a host ? + // Is there a host ? - U_RETURN(result); + if (host_begin < host_end) U_RETURN(true); + + U_RETURN(false); } /** @@ -364,9 +382,9 @@ public: { U_TRACE_NO_PARAM(0, "Url::isPath()") - bool result = (path_begin < path_end); + if (path_begin < path_end) U_RETURN(true); - U_RETURN(result); + U_RETURN(false); } /** @@ -412,9 +430,9 @@ public: { U_TRACE_NO_PARAM(0, "Url::isQuery()") - bool result = (path_end < (int)(url.size() - 1)); + if (path_end < (int)(url.size() - 1)) U_RETURN(true); - U_RETURN(result); + U_RETURN(false); } /** diff --git a/src/ulib/container/hash_map.cpp b/src/ulib/container/hash_map.cpp index 2976fe7d..bac7a0b5 100644 --- a/src/ulib/container/hash_map.cpp +++ b/src/ulib/container/hash_map.cpp @@ -542,6 +542,48 @@ UString UHashMap::erase(const UString& _key) return UString::getStringNull(); } +__pure bool UHashMap::operator==(const UHashMap& t) +{ + U_TRACE(0, "UHashMap::operator==(%p)", &t) + + U_CHECK_MEMORY + + if (_length == t._length) + { + U_INTERNAL_DUMP("_length = %u", _length) + + UHashMapNode* _node; + UHashMapNode* _next; + UHashMapNode** ptr; + UHashMapNode** end; + + for (end = (ptr = t.table) + t._capacity; ptr < end; ++ptr) + { + if (*ptr) + { + _node = *ptr; + + do { + _next = _node->next; + + UHashMap::lookup((UStringRep*)_node->key); + + if (node == 0 || + ((UStringRep*)_node->elem)->equal(elem()) == false) + { + U_RETURN(false); + } + } + while ((_node = _next)); + } + } + + U_RETURN(true); + } + + U_RETURN(false); +} + // OPERATOR [] UString UHashMap::at(const UStringRep* _key) diff --git a/src/ulib/json/value.cpp b/src/ulib/json/value.cpp index 84b4a2ae..b932bd26 100644 --- a/src/ulib/json/value.cpp +++ b/src/ulib/json/value.cpp @@ -2011,19 +2011,19 @@ end: U_RETURN(jTok); } -bool UValue::jfind(const UString& json, const UString& query, UString& result) +bool UValue::jfind(const UString& json, const char* query, uint32_t query_len, UString& result) { - U_TRACE(0, "UValue::jfind(%V,%V,%p)", json.rep, query.rep, &result) + U_TRACE(0, "UValue::jfind(%V,%.*S,%u,%p)", json.rep, query_len, query, query_len, &result) U_ASSERT(result.empty()) - uint32_t pos = json.find(query); + uint32_t pos = json.find(query, query_len); U_INTERNAL_DUMP("pos = %d", pos) if (pos != U_NOT_FOUND) { - pos += query.size(); + pos += query_len; if (u__isquote(json.c_char(pos))) ++pos; @@ -2046,7 +2046,17 @@ bool UValue::jfind(const UString& json, const UString& query, UString& result) if (jread_skip(tok) != -1) { - (void) result.assign(start, tok.getPointer()-start); + const char* end = tok.getPointer(); + + if (u__isquote(*start)) + { + ++start; + --end; + + U_INTERNAL_ASSERT(u__isquote(*end)) + } + + (void) result.assign(start, end-start); U_RETURN(true); } diff --git a/src/ulib/net/client/client.cpp b/src/ulib/net/client/client.cpp index ca73ed31..76cb6c74 100644 --- a/src/ulib/net/client/client.cpp +++ b/src/ulib/net/client/client.cpp @@ -357,43 +357,47 @@ bool UClient_Base::setUrl(const char* str, uint32_t len) U_INTERNAL_ASSERT_POINTER(str) U_INTERNAL_ASSERT_MAJOR(len, 0) - // check we've been passed a absolute URL + // we check we've been passed a absolute URL if (u_isUrlScheme(str, len) == 0) { - char* p; - char* ptr; - char* dest; - uint32_t sz; - char buf[U_PATH_MAX]; - - const char* src = uri.data(); - const char* _end = src + uri.size(); - U_INTERNAL_DUMP("uri = %V", uri.rep) - ptr = dest = buf; - - while (src < _end) + if (uri.empty()) (void) uri.replace(str, len); + else { - p = (char*) memchr(src, '/', _end - src); + char* p; + char* ptr; + char* dest; + uint32_t sz; + char buf[U_PATH_MAX]; - if (p == 0) break; + const char* src = uri.data(); + const char* _end = src + uri.size(); - sz = p - src + 1; + ptr = dest = buf; - U_INTERNAL_DUMP("segment = %.*S", sz, src) + while (src < _end) + { + p = (char*) memchr(src, '/', _end - src); - U_MEMCPY(dest, src, sz); + if (p == 0) break; - src = p + 1; - dest += sz; + sz = p - src + 1; + + U_INTERNAL_DUMP("segment = %.*S", sz, src) + + U_MEMCPY(dest, src, sz); + + src = p + 1; + dest += sz; + } + + U_MEMCPY(dest, str, len); + + (void) uri.replace(buf, dest - ptr + len); } - U_MEMCPY(dest, str, len); - - (void) uri.replace(buf, dest - ptr + len); - U_INTERNAL_DUMP("uri = %V", uri.rep) U_RETURN(false); diff --git a/src/ulib/net/client/http.cpp b/src/ulib/net/client/http.cpp index 4de7293c..ddb4da72 100644 --- a/src/ulib/net/client/http.cpp +++ b/src/ulib/net/client/http.cpp @@ -953,9 +953,16 @@ bool UHttpClient_Base::sendRequest(int method, const char* content_type, uint32_ // send post request to server and get response - if (sendRequest()) U_RETURN(true); + bool ok = sendRequest(); - U_RETURN(false); + // reset reference to request... + + UClient_Base::reset(); + + requestHeader->clear(); + responseHeader->clear(); + + U_RETURN(ok); } bool UHttpClient_Base::sendPost(const UString& _url, const UString& _body, const char* content_type, uint32_t content_type_len) diff --git a/src/ulib/net/client/mongodb.cpp b/src/ulib/net/client/mongodb.cpp index 42ee4e1f..d863b994 100644 --- a/src/ulib/net/client/mongodb.cpp +++ b/src/ulib/net/client/mongodb.cpp @@ -78,14 +78,27 @@ bool UMongoDBClient::insert(bson_t* doc) U_RETURN(false); } -bool UMongoDBClient::find(bson_t* query) +bool UMongoDBClient::find(bson_t* query, bson_t* projection) { - U_TRACE(0, "UMongoDBClient::find(%p)", query) + U_TRACE(0, "UMongoDBClient::find(%p,%p)", query, projection) U_INTERNAL_ASSERT_POINTER(client) U_INTERNAL_ASSERT_POINTER(collection) - cursor = (mongoc_cursor_t*) U_SYSCALL(mongoc_collection_find, "%p,%d,%u,%u,%u,%p,%p,%p", collection, MONGOC_QUERY_NONE, 0, 0, 0, query, 0, 0); + /** + * Parameters + * + * collection A mongoc_collection_t + * flags A mongoc_query_flags_t + * skip A uint32_t of number of documents to skip or 0 + * limit A uint32_t of max number of documents to return or 0 + * batch_size A uint32_t containing batch size of document result sets or 0 for default. Default is 100 + * query A bson_t containing the query and options to execute + * fields A bson_t containing fields to return or NULL + * read_prefs A mongoc_read_prefs_t or NULL for default read preferences + */ + + cursor = (mongoc_cursor_t*) U_SYSCALL(mongoc_collection_find, "%p,%d,%u,%u,%u,%p,%p,%p", collection, MONGOC_QUERY_NONE, 0, 0, 0, query, projection, 0); if (cursor) { @@ -143,7 +156,7 @@ bool UMongoDBClient::findOne(const char* json, uint32_t len) } else { - bool result = find(bson); + bool result = find(bson, 0); U_SYSCALL_VOID(bson_destroy, "%p", bson); diff --git a/src/ulib/net/server/plugin/usp/edb.usp b/src/ulib/net/server/plugin/usp/edb.usp index 16cc4f2b..41fdb04b 100644 --- a/src/ulib/net/server/plugin/usp/edb.usp +++ b/src/ulib/net/server/plugin/usp/edb.usp @@ -5,8 +5,6 @@ TechEmpower Web Framework Benchmarks @@ -62,18 +51,18 @@ static void usp_end_edb() Content-Type: application/json --> diff --git a/src/ulib/net/server/plugin/usp/equery.usp b/src/ulib/net/server/plugin/usp/equery.usp index 5a867838..dd40c729 100644 --- a/src/ulib/net/server/plugin/usp/equery.usp +++ b/src/ulib/net/server/plugin/usp/equery.usp @@ -5,9 +5,7 @@ TechEmpower Web Framework Benchmarks @@ -65,6 +57,7 @@ static void usp_end_equery() Content-Type: application/json --> @@ -65,7 +67,7 @@ static void usp_end_eupdate() Content-Type: application/json --> @@ -64,18 +53,18 @@ static void usp_end_mdb() Content-Type: application/json --> diff --git a/src/ulib/net/server/plugin/usp/mfortune.usp b/src/ulib/net/server/plugin/usp/mfortune.usp index aff1b2fa..bd73c3c8 100644 --- a/src/ulib/net/server/plugin/usp/mfortune.usp +++ b/src/ulib/net/server/plugin/usp/mfortune.usp @@ -5,7 +5,6 @@ TechEmpower Web Framework Benchmarks @@ -67,6 +59,7 @@ static void usp_end_mquery() Content-Type: application/json --> @@ -64,6 +59,7 @@ static void usp_end_mupdate() Content-Type: application/json --> @@ -57,18 +49,16 @@ static void usp_end_rdb() Content-Type: application/json --> diff --git a/src/ulib/net/server/plugin/usp/usp_translator.cpp b/src/ulib/net/server/plugin/usp/usp_translator.cpp index 436ec212..3ef67a07 100644 --- a/src/ulib/net/server/plugin/usp/usp_translator.cpp +++ b/src/ulib/net/server/plugin/usp/usp_translator.cpp @@ -527,7 +527,7 @@ public: UString tmp(encoded.size() + 200U); - tmp.snprintf("\n\t\tU_INTERNAL_ASSERT_EQUALS(UClientImage_Base::wbuffer->findEndHeader(),false);" + tmp.snprintf("\n\t\tU_INTERNAL_ASSERT_EQUALS(UClientImage_Base::wbuffer->findEndHeader(),false)" "\n\t\tU_http_info.endHeader = %u;" "\n\t\t(void) UClientImage_Base::wbuffer->insert(0, \n\tU_CONSTANT_TO_PARAM(%v));\n", n, encoded.rep); @@ -563,7 +563,8 @@ public: bsighup == false || bfork == false) { - ptr6 = "\n\t\tif (param >= U_DPAGE_FORK) return;\n"; + ptr6 = (bfork ? "\n\t\tif (param > U_DPAGE_FORK) return;\n" + : "\n\t\tif (param >= U_DPAGE_FORK) return;\n"); } if (bparallelization) ptr7 = "\t\n\t\tif (UServer_Base::startParallelization(UServer_Base::num_client_for_parallelization)) return;\n\t\n"; diff --git a/src/ulib/net/server/plugin/usp/world.h b/src/ulib/net/server/plugin/usp/world.h index 418bb2de..465fff3e 100644 --- a/src/ulib/net/server/plugin/usp/world.h +++ b/src/ulib/net/server/plugin/usp/world.h @@ -27,11 +27,9 @@ public: # endif } - World(const World& w) : id(w.id), randomNumber(w.randomNumber) + World(uint32_t _id, uint32_t _randomNumber) : id(_id), randomNumber(_randomNumber) { - U_TRACE_REGISTER_OBJECT(5, World, "%p", &w) - - U_MEMORY_TEST_COPY(w) + U_TRACE_REGISTER_OBJECT(5, World, "%u,%u", _id, _randomNumber) } ~World() diff --git a/src/ulib/url.cpp b/src/ulib/url.cpp index c7d961f4..9324e1f5 100644 --- a/src/ulib/url.cpp +++ b/src/ulib/url.cpp @@ -36,8 +36,9 @@ void Url::setService(const char* service, uint32_t n) if (service_end > 0) (void) url.replace(0, service_end, service, n); else { - (void) url.insert(0, U_CONSTANT_TO_PARAM("://")); - (void) url.insert(0, service, n); + char buffer[32]; + + (void) url.insert(0, buffer, u__snprintf(buffer, sizeof(buffer), "%.*s://", n, service)); } findpos(); @@ -49,10 +50,7 @@ UString Url::getUser() UString usr; - if (user_begin < user_end) - { - usr = url.substr(user_begin, user_end - user_begin); - } + if (user_begin < user_end) usr = url.substr(user_begin, user_end - user_begin); U_RETURN_STRING(usr); } @@ -67,14 +65,12 @@ bool Url::setUser(const char* user, uint32_t n) if (host_begin < host_end) { - if (user_begin < user_end) - { - (void) url.replace(user_begin, user_end - user_begin, user, n); - } + if (user_begin < user_end) (void) url.replace(user_begin, user_end - user_begin, user, n); else { - (void) url.insert(user_begin, 1, '@'); - (void) url.insert(user_begin, user, n); + char buffer[128]; + + (void) url.insert(user_begin, buffer, u__snprintf(buffer, sizeof(buffer), "%.*s@", n, user)); } findpos(); @@ -199,10 +195,7 @@ void Url::setPath(const char* path, uint32_t n) if (path_begin < path_end) { - if (*path != '/') - { - ++path_begin; - } + if (*path != '/') ++path_begin; (void) url.replace(path_begin, path_end - path_begin, path, n); } @@ -335,7 +328,14 @@ void Url::findpos() if (service_end < 0) { - service_end = user_begin = user_end = host_begin = host_end = path_begin = path_end = query = 0; + service_end = + user_begin = + user_end = + host_begin = + host_end = + path_begin = + path_end = + query = 0; return; } diff --git a/tests/examples/benchmark/FrameworkBenchmarks/ULib/install.sh b/tests/examples/benchmark/FrameworkBenchmarks/ULib/install.sh index c820f76e..ee831736 100755 --- a/tests/examples/benchmark/FrameworkBenchmarks/ULib/install.sh +++ b/tests/examples/benchmark/FrameworkBenchmarks/ULib/install.sh @@ -39,8 +39,7 @@ USP_FLAGS="-DAS_cpoll_cppsp_DO" \ --without-ssl --without-pcre --without-expat \ --without-libz --without-libuuid --without-magic --without-libares \ --enable-static-orm-driver='mysql pgsql sqlite' --enable-static-server-plugin=http \ - --with-mongodb --with-mongodb-includes="-I$IROOT/include/libbson-1.0 -I$IROOT/include/libmongoc-1.0" --with-mongodb-ldflags="-L$IROOT" -# --enable-debug --enable-HCRS --enable-HPRS --disable-CRPWS --disable-check-time --disable-HIS --disable-log --disable-GSDS --disable-alias --disable-HSTS \ + --with-mongodb --with-mongodb-includes="-I$IROOT/include/libbson-1.0 -I$IROOT/include/libmongoc-1.0" --with-mongodb-ldflags="-L$IROOT" #USP_LIBS="-ljson" \ cp config.cache .. @@ -53,10 +52,11 @@ make clean make install cd ../../src/ulib/net/server/plugin/usp -make json.la plaintext.la db.la query.la update.la fortune.la rdb.la rquery.la rupdate.la rfortune.la mdb.la mquery.la mupdate.la mfortune.la +make json.la plaintext.la db.la query.la update.la fortune.la rdb.la rquery.la rupdate.la rfortune.la mdb.la mquery.la mupdate.la mfortune.la edb.la equery.la eupdate.la mkdir -p $ULIB_DOCUMENT_ROOT cp .libs/json.so .libs/plaintext.so \ + .libs/edb.so .libs/equery.so .libs/eupdate.so \ .libs/db.so .libs/query.so .libs/update.so .libs/fortune.so \ .libs/rdb.so .libs/rquery.so .libs/rupdate.so .libs/rfortune.so \ .libs/mdb.so .libs/mquery.so .libs/mupdate.so .libs/mfortune.so $ULIB_DOCUMENT_ROOT diff --git a/tests/examples/benchmark/FrameworkBenchmarks/ULib/src/edb.usp b/tests/examples/benchmark/FrameworkBenchmarks/ULib/src/edb.usp index 16cc4f2b..f924976c 100644 --- a/tests/examples/benchmark/FrameworkBenchmarks/ULib/src/edb.usp +++ b/tests/examples/benchmark/FrameworkBenchmarks/ULib/src/edb.usp @@ -5,56 +5,45 @@ TechEmpower Web Framework Benchmarks @@ -62,18 +51,18 @@ static void usp_end_edb() Content-Type: application/json --> diff --git a/tests/examples/benchmark/FrameworkBenchmarks/ULib/src/equery.usp b/tests/examples/benchmark/FrameworkBenchmarks/ULib/src/equery.usp index 5a867838..dd40c729 100644 --- a/tests/examples/benchmark/FrameworkBenchmarks/ULib/src/equery.usp +++ b/tests/examples/benchmark/FrameworkBenchmarks/ULib/src/equery.usp @@ -5,9 +5,7 @@ TechEmpower Web Framework Benchmarks @@ -65,6 +57,7 @@ static void usp_end_equery() Content-Type: application/json --> @@ -65,7 +67,7 @@ static void usp_end_eupdate() Content-Type: application/json --> @@ -64,18 +53,18 @@ static void usp_end_mdb() Content-Type: application/json --> diff --git a/tests/examples/benchmark/FrameworkBenchmarks/ULib/src/mfortune.usp b/tests/examples/benchmark/FrameworkBenchmarks/ULib/src/mfortune.usp index aff1b2fa..4063cb40 100644 --- a/tests/examples/benchmark/FrameworkBenchmarks/ULib/src/mfortune.usp +++ b/tests/examples/benchmark/FrameworkBenchmarks/ULib/src/mfortune.usp @@ -5,7 +5,6 @@ TechEmpower Web Framework Benchmarks @@ -60,33 +57,37 @@ uint32_t i, n; UString result; U_NEW(Fortune, item, Fortune(*pfortune2add)); + pvfortune->push_back(item); (void) mc->findAll(); for (i = 0, n = mc->vitem.size(); i < n; ++i) - { - (void) UValue::jread(mc->vitem[i], *jquery, result); // { "_id" : 5.000000, "id" : 5.000000, "message" : "A computer program does what you tell it to do, not what you want it to do." } + { + result.clear(); + + (void) UValue::jfind(mc->vitem[i], U_CONSTANT_TO_PARAM("message"), result); U_NEW(Fortune, item, Fortune(i+1, result)); + pvfortune->push_back(item); - } + } pvfortune->sort(Fortune::cmp_obj); for (i = 0, ++n; i < n; ++i) - { - Fortune* elem = (*pvfortune)[i]; + { + Fortune* elem = (*pvfortune)[i]; - UXMLEscape::encode(elem->message, *pencoded); + UXMLEscape::encode(elem->message, *pencoded); - USP_PRINTF_ADD( - "" - "%u" - "%v" - "", - elem->id, pencoded->rep); - } + USP_PRINTF_ADD( + "" + "%u" + "%v" + "", + elem->id, pencoded->rep); + } pvfortune->clear(); --> diff --git a/tests/examples/benchmark/FrameworkBenchmarks/ULib/src/mquery.usp b/tests/examples/benchmark/FrameworkBenchmarks/ULib/src/mquery.usp index 3f27889e..5257c2d6 100644 --- a/tests/examples/benchmark/FrameworkBenchmarks/ULib/src/mquery.usp +++ b/tests/examples/benchmark/FrameworkBenchmarks/ULib/src/mquery.usp @@ -5,61 +5,53 @@ TechEmpower Web Framework Benchmarks @@ -67,6 +59,7 @@ static void usp_end_mquery() Content-Type: application/json --> @@ -64,6 +59,7 @@ static void usp_end_mupdate() Content-Type: application/json --> @@ -57,18 +49,16 @@ static void usp_end_rdb() Content-Type: application/json --> diff --git a/tests/examples/benchmark/FrameworkBenchmarks/ULib/src/world.h b/tests/examples/benchmark/FrameworkBenchmarks/ULib/src/world.h index 91b1d67f..1c08cac5 100644 --- a/tests/examples/benchmark/FrameworkBenchmarks/ULib/src/world.h +++ b/tests/examples/benchmark/FrameworkBenchmarks/ULib/src/world.h @@ -27,11 +27,9 @@ public: # endif } - World(const World& w) : id(w.id), randomNumber(w.randomNumber) + World(uint32_t _id, uint32_t _randomNumber) : id(_id), randomNumber(_randomNumber) { - U_TRACE_REGISTER_OBJECT(5, World, "%p", &w) - - U_MEMORY_TEST_COPY(w) + U_TRACE_REGISTER_OBJECT(5, World, "%u,%u", _id, _randomNumber) } ~World()