From 3539f934d44e0c266e9b1b102e729a534ade95e3 Mon Sep 17 00:00:00 2001 From: stefanocasazza Date: Sun, 7 May 2017 18:06:08 +0200 Subject: [PATCH] sync --- Makefile.am | 2 +- Makefile.in | 2 +- README.md | 7 +- configure | 2 +- configure.ac | 2 +- examples/form_completion/main.cpp | 2 +- include/ulib/orm/orm.h | 56 +-- src/ulib/net/server/plugin/usp/businesses.usp | 10 +- src/ulib/net/server/plugin/usp/db.usp | 2 +- src/ulib/net/server/plugin/usp/fortune.h | 43 +- src/ulib/net/server/plugin/usp/fortune.usp | 2 +- .../net/server/plugin/usp/jsonrequest.usp | 2 +- src/ulib/net/server/plugin/usp/mdb.usp | 2 +- src/ulib/net/server/plugin/usp/mfortune.usp | 2 +- src/ulib/net/server/plugin/usp/mquery.usp | 2 +- src/ulib/net/server/plugin/usp/mupdate.usp | 2 +- src/ulib/net/server/plugin/usp/query.usp | 2 +- src/ulib/net/server/plugin/usp/update.usp | 4 +- .../net/server/plugin/usp/usp_translator.cpp | 6 +- src/ulib/net/server/plugin/usp/world.h | 43 +- src/ulib/utility/http2.cpp | 12 +- .../ULib/db/hello_world.db | Bin 253952 -> 253952 bytes .../FrameworkBenchmarks/ULib/src/db.usp | 2 +- .../FrameworkBenchmarks/ULib/src/fortune.h | 43 +- .../FrameworkBenchmarks/ULib/src/fortune.usp | 2 +- .../FrameworkBenchmarks/ULib/src/mdb.usp | 2 +- .../FrameworkBenchmarks/ULib/src/mfortune.usp | 2 +- .../FrameworkBenchmarks/ULib/src/mquery.usp | 2 +- .../FrameworkBenchmarks/ULib/src/mupdate.usp | 2 +- .../FrameworkBenchmarks/ULib/src/query.usp | 2 +- .../FrameworkBenchmarks/ULib/src/update.usp | 4 +- .../FrameworkBenchmarks/ULib/src/world.h | 43 +- tests/examples/web_server.sh | 1 + tests/ulib/test_orm.cpp | 96 ++--- ulib.html | 402 ++++++++++++++++++ 35 files changed, 602 insertions(+), 208 deletions(-) create mode 100644 ulib.html diff --git a/Makefile.am b/Makefile.am index 2e0da444..9f26f169 100644 --- a/Makefile.am +++ b/Makefile.am @@ -3,7 +3,7 @@ AUTOMAKE_OPTIONS = no-dependencies ## dist-shar dist-zip ACLOCAL_AMFLAGS = -I m4 -EXTRA_DIST = cdb configure.help TODO LICENSE* README* *.spec* \ +EXTRA_DIST = cdb configure.help TODO LICENSE* README* *.spec* ulib.html \ ULib.m4 rpm.sh rpmpkgreq.lst rpmpkgreq.lst.suse openwrt \ doc/Doxyfile doc/readme.txt shtool *.awk .travis.yml autogen.sh nativejson-benchmark \ fuzz/http1-corpus fuzz/http2-corpus fuzz/build_libFuzzer.sh fuzz/Makefile.in fuzz/Makefile.am fuzz/uclient_fuzzer.cpp fuzz/uclient.cfg diff --git a/Makefile.in b/Makefile.in index f915c8c7..84988726 100644 --- a/Makefile.in +++ b/Makefile.in @@ -444,7 +444,7 @@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ AUTOMAKE_OPTIONS = no-dependencies ## dist-shar dist-zip ACLOCAL_AMFLAGS = -I m4 -EXTRA_DIST = cdb configure.help TODO LICENSE* README* *.spec* \ +EXTRA_DIST = cdb configure.help TODO LICENSE* README* *.spec* ulib.html \ ULib.m4 rpm.sh rpmpkgreq.lst rpmpkgreq.lst.suse openwrt \ doc/Doxyfile doc/readme.txt shtool *.awk .travis.yml autogen.sh nativejson-benchmark \ fuzz/http1-corpus fuzz/http2-corpus fuzz/build_libFuzzer.sh fuzz/Makefile.in fuzz/Makefile.am fuzz/uclient_fuzzer.cpp fuzz/uclient.cfg diff --git a/README.md b/README.md index 66544c35..120df351 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ It include as application example a powerful search engine with relative [web in The current version offers the following features : - * HTTP/1.0 and 1.1 protocols supported and experimental implementations of HTTP/2 ([h2spec compliant](https://github.com/summerwind/h2spec)). + * HTTP/1.0, 1.1 and HTTP/2 ([h2spec compliant](https://github.com/summerwind/h2spec)) protocols supported. * Persistent connections for HTTP/1.1 and Keep-Alive support for HTTP/1.0. * Browser cache management (headers: If-Modified-Since/Last-modified). * Chunk-encoding transfers support. @@ -42,6 +42,7 @@ The current version offers the following features : * [C Servlet Support](http://bellard.org/tcc/) with libtcc (if available) as a backend for dynamic code generation (experimental). * Support for running Ruby on Rails applications natively (experimental). * Support for running natively PHP applications whith a php (embedded) library (experimental). + * Support for load balance support between physical server via udp brodcast (experimental). * Preforking mode to improve concurrency with dedicated process for long-time request. * Support for Windows (without preforking). * Customizable builds (you can remove unneeded functionality). @@ -78,6 +79,10 @@ It is the main software component of [city of Florence wireless network](http:// userver application server is since 10th round in the [TechEmpower's web framework benchmarks](http://www.techempower.com/benchmarks). This independent work tests a large number of frameworks and platforms against a set of tests common to web applications, such as JSON serialization, database queries and templating. +## Getting Started With ULib (donated generously by jonathan kelly) + +* [ulib.html](https://github.com/stefanocasazza/ULib/blob/master/ulib.html) + ## Contributing 1. Fork it ( http://github.com//ULib/fork ) diff --git a/configure b/configure index 42d34c4d..f0521021 100755 --- a/configure +++ b/configure @@ -32158,7 +32158,7 @@ $as_echo "$ulib_cc_flag" >&6; } else ## _FORTIFY_SOURCE is enabled by default from g++ 4.7.2 MAYBE_FLAGS="$MAYBE_FLAGS -Wunsafe-loop-optimizations -Wno-unused-parameter -rdynamic -fdiagnostics-color=auto -Wmisleading-indentation" - CXX_MAYBE_FLAGS="$CXX_MAYBE_FLAGS -Wc++11-compat -Wzero-as-null-pointer-constant -Wimplicit-fallthrough=0" + CXX_MAYBE_FLAGS="$CXX_MAYBE_FLAGS -Wc++11-compat -Wzero-as-null-pointer-constant -Wno-implicit-fallthrough" fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking for gcc supported flags" >&5 diff --git a/configure.ac b/configure.ac index c9f07f70..e756d6a4 100644 --- a/configure.ac +++ b/configure.ac @@ -2342,7 +2342,7 @@ if test "$ac_cv_c_compiler_gnu" = "yes" -a "x$GCC_IS_CLANG" = xno -a "x$OPERATIN else ## _FORTIFY_SOURCE is enabled by default from g++ 4.7.2 MAYBE_FLAGS="$MAYBE_FLAGS -Wunsafe-loop-optimizations -Wno-unused-parameter -rdynamic -fdiagnostics-color=auto -Wmisleading-indentation" - CXX_MAYBE_FLAGS="$CXX_MAYBE_FLAGS -Wc++11-compat -Wzero-as-null-pointer-constant -Wimplicit-fallthrough=0" + CXX_MAYBE_FLAGS="$CXX_MAYBE_FLAGS -Wc++11-compat -Wzero-as-null-pointer-constant -Wno-implicit-fallthrough" fi AC_CACHE_CHECK([for gcc supported flags], ulib_cv_flags, [ diff --git a/examples/form_completion/main.cpp b/examples/form_completion/main.cpp index d1dda305..bfed5069 100644 --- a/examples/form_completion/main.cpp +++ b/examples/form_completion/main.cpp @@ -93,7 +93,7 @@ public: // search to LDAP char buffer[4096]; - const char* attr_name[] = { username.c_str(), password.c_str(), 0 }; + const char* attr_name[] = { username.c_str(), password.c_str(), U_NULLPTR }; (void) u__snprintf(buffer, sizeof(buffer), U_CONSTANT_TO_PARAM("%v=%s,%.*s"), subject_attr.rep, buf, U_STRING_TO_TRACE(LDAP_searchbase)); diff --git a/include/ulib/orm/orm.h b/include/ulib/orm/orm.h index 6716ad77..686ec151 100644 --- a/include/ulib/orm/orm.h +++ b/include/ulib/orm/orm.h @@ -125,11 +125,11 @@ private: U_DISALLOW_ASSIGN(UOrmTypeHandler_Base) }; -#define U_ORM_TYPE_HANDLER(class_name, name_object_member, type_object_member) \ - UOrmTypeHandler(((class_name*)pval)->name_object_member) +#define U_ORM_TYPE_HANDLER(name_object_member, type_object_member) UOrmTypeHandler(name_object_member) /** - * Converts Rows to a Type and the other way around. Provide template specializations to support your own complex types. + * Converts Rows to a Type and the other way around. + * Provide template specializations to support your own complex types. * * Take as example the following (simplified) class: * @@ -140,30 +140,25 @@ private: * UString firstName; * }; * - * The UOrmTypeHandler must provide a custom bindParam and bindResult method: + * add this methods to the (simplified) class: * - * template <> class UOrmTypeHandler : public UOrmTypeHandler_Base { - * public: - * explicit UOrmTypeHandler(Person& val) : UOrmTypeHandler_Base(&val) + * void bindParam(UOrmStatement* stmt) + * { + * // the table is defined as Person (LastName VARCHAR(30), FirstName VARCHAR, Age INTEGER(3)) * - * void bindParam(UOrmStatement* stmt) - * { - * // the table is defined as Person (LastName VARCHAR(30), FirstName VARCHAR, Age INTEGER(3)) - * - * stmt->bindParam(U_ORM_TYPE_HANDLER(Person, age, int)); - * stmt->bindParam(U_ORM_TYPE_HANDLER(Person, lastName, UString)); - * stmt->bindParam(U_ORM_TYPE_HANDLER(Person, firstName, UString)); - * } + * stmt->bindParam(U_ORM_TYPE_HANDLER(age, int)); + * stmt->bindParam(U_ORM_TYPE_HANDLER( lastName, UString)); + * stmt->bindParam(U_ORM_TYPE_HANDLER(firstName, UString)); + * } * - * void bindResult(UOrmStatement* stmt) - * { - * // the table is defined as Person (LastName VARCHAR(30), FirstName VARCHAR, Age INTEGER(3)) + * void bindResult(UOrmStatement* stmt) + * { + * // the table is defined as Person (LastName VARCHAR(30), FirstName VARCHAR, Age INTEGER(3)) * - * stmt->bindResult(U_ORM_TYPE_HANDLER(Person, age, int)); - * stmt->bindResult(U_ORM_TYPE_HANDLER(Person, lastName, UString)); - * stmt->bindResult(U_ORM_TYPE_HANDLER(Person, firstName, UString)); - * } - * }; + * stmt->bindResult(U_ORM_TYPE_HANDLER(age, int)); + * stmt->bindResult(U_ORM_TYPE_HANDLER( lastName, UString)); + * stmt->bindResult(U_ORM_TYPE_HANDLER(firstName, UString)); + * } */ template class U_EXPORT UOrmTypeHandler : public UOrmTypeHandler_Base { @@ -173,8 +168,19 @@ public: // SERVICES - void bindParam( UOrmStatement* stmt); - void bindResult(UOrmStatement* stmt); + void bindParam(UOrmStatement* stmt) + { + U_TRACE(0, "UOrmTypeHandler::bindParam(%p)", stmt) + + ((T*)pval)->bindParam(stmt); + } + + void bindResult(UOrmStatement* stmt) + { + U_TRACE(0, "UOrmTypeHandler::bindResult(%p)", stmt) + + ((T*)pval)->bindResult(stmt); + } private: U_DISALLOW_ASSIGN(UOrmTypeHandler) diff --git a/src/ulib/net/server/plugin/usp/businesses.usp b/src/ulib/net/server/plugin/usp/businesses.usp index b1f036d1..9ae469c1 100644 --- a/src/ulib/net/server/plugin/usp/businesses.usp +++ b/src/ulib/net/server/plugin/usp/businesses.usp @@ -75,7 +75,7 @@ public: return UObjectIO::buffer_output; } - return 0; + return U_NULLPTR; } #endif @@ -178,7 +178,7 @@ public: return UObjectIO::buffer_output; } - return 0; + return U_NULLPTR; } #endif @@ -313,7 +313,7 @@ public: HTTP2Push() : UEventTime(15L * 60L, 0L), message(U_STRING_FROM_CONSTANT("{aps:{content-available:1},check:health}")), token(U_CAPACITY) { - U_TRACE_REGISTER_OBJECT(0, HTTP2Push, "", 0) + U_TRACE_REGISTER_OBJECT(0, HTTP2Push, "", U_NULLPTR) # ifdef USE_LIBCURL UCURL::initHTTP2Push("https://api.development.push.apple.com", "/certificates/samplepush/development.pem", "GoGo.Hopscotch"); @@ -337,7 +337,7 @@ public: // child - token.snprintf(U_CONSTANT_TO_PARAM("dbdaeae86abcde56rtyww1859fb41d2c7b2cberrttyyy053ec48987847"), 0); + (void) token.assign(U_CONSTANT_TO_PARAM("dbdaeae86abcde56rtyww1859fb41d2c7b2cberrttyyy053ec48987847")); # ifdef USE_LIBCURL if (UCURL::sendHTTP2Push(token, message) == false) @@ -381,7 +381,7 @@ static void usp_fork_businesses() U_NEW(UMongoDBClient, mc, UMongoDBClient); - if (mc->connect(0,0) == false) + if (mc->connect(U_NULLPTR, 0) == false) { U_WARNING("usp_fork_businesses(): connection failed"); diff --git a/src/ulib/net/server/plugin/usp/db.usp b/src/ulib/net/server/plugin/usp/db.usp index f52be656..55409888 100644 --- a/src/ulib/net/server/plugin/usp/db.usp +++ b/src/ulib/net/server/plugin/usp/db.usp @@ -19,7 +19,7 @@ static void usp_fork_db() { U_NEW(UOrmStatement, pstmt_db, UOrmStatement(*psql_db, U_CONSTANT_TO_PARAM("SELECT randomNumber FROM World WHERE id = ?"))); - if (pstmt_db == 0) + if (pstmt_db == U_NULLPTR) { U_WARNING("usp_fork_db(): we cound't connect to db"); diff --git a/src/ulib/net/server/plugin/usp/fortune.h b/src/ulib/net/server/plugin/usp/fortune.h index 25bf6e08..c3e66545 100644 --- a/src/ulib/net/server/plugin/usp/fortune.h +++ b/src/ulib/net/server/plugin/usp/fortune.h @@ -87,6 +87,24 @@ public: json.fromJSON(U_JSON_METHOD_HANDLER(message, UString)); } + // ORM + + void bindParam(UOrmStatement* stmt) + { + U_TRACE(0, "Fortune::bindParam(%p)", stmt) + + stmt->bindParam(U_ORM_TYPE_HANDLER(id, unsigned int)); + stmt->bindParam(U_ORM_TYPE_HANDLER(message, UString)); + } + + void bindResult(UOrmStatement* stmt) + { + U_TRACE(0, "Fortune::bindResult(%p)", stmt) + + stmt->bindResult(U_ORM_TYPE_HANDLER(id, unsigned int)); + stmt->bindResult(U_ORM_TYPE_HANDLER(message, UString)); + } + #ifdef DEBUG const char* dump(bool breset) const { @@ -100,34 +118,11 @@ public: return UObjectIO::buffer_output; } - return 0; + return U_NULLPTR; } #endif private: U_DISALLOW_ASSIGN(Fortune) }; - -// ORM TEMPLATE SPECIALIZATIONS - -template <> class U_EXPORT UOrmTypeHandler : public UOrmTypeHandler_Base { -public: - explicit UOrmTypeHandler(Fortune& val) : UOrmTypeHandler_Base(&val) {} - - void bindParam(UOrmStatement* stmt) const - { - U_TRACE(0, "UOrmTypeHandler::bindParam(%p)", stmt) - - stmt->bindParam(U_ORM_TYPE_HANDLER(Fortune, id, unsigned int)); - stmt->bindParam(U_ORM_TYPE_HANDLER(Fortune, message, UString)); - } - - void bindResult(UOrmStatement* stmt) - { - U_TRACE(0, "UOrmTypeHandler::bindResult(%p)", stmt) - - stmt->bindResult(U_ORM_TYPE_HANDLER(Fortune, id, unsigned int)); - stmt->bindResult(U_ORM_TYPE_HANDLER(Fortune, message, UString)); - } -}; #endif diff --git a/src/ulib/net/server/plugin/usp/fortune.usp b/src/ulib/net/server/plugin/usp/fortune.usp index d9bf9c79..993caecf 100644 --- a/src/ulib/net/server/plugin/usp/fortune.usp +++ b/src/ulib/net/server/plugin/usp/fortune.usp @@ -24,7 +24,7 @@ static void usp_fork_fortune() { U_NEW(UOrmStatement, pstmt_fortune, UOrmStatement(*psql_fortune, U_CONSTANT_TO_PARAM("SELECT id, message FROM Fortune"))); - if (pstmt_fortune == 0) + if (pstmt_fortune == U_NULLPTR) { U_WARNING("usp_fork_fortune(): we cound't connect to db"); diff --git a/src/ulib/net/server/plugin/usp/jsonrequest.usp b/src/ulib/net/server/plugin/usp/jsonrequest.usp index 847e3c62..951fc590 100644 --- a/src/ulib/net/server/plugin/usp/jsonrequest.usp +++ b/src/ulib/net/server/plugin/usp/jsonrequest.usp @@ -97,7 +97,7 @@ public: return UObjectIO::buffer_output; } - return 0; + return U_NULLPTR; } #endif diff --git a/src/ulib/net/server/plugin/usp/mdb.usp b/src/ulib/net/server/plugin/usp/mdb.usp index 1e99b434..9ac4976f 100644 --- a/src/ulib/net/server/plugin/usp/mdb.usp +++ b/src/ulib/net/server/plugin/usp/mdb.usp @@ -13,7 +13,7 @@ static void usp_fork_mdb() U_NEW(UMongoDBClient, mc, UMongoDBClient); - if (mc->connect(0,0) == false) + if (mc->connect(U_NULLPTR, 0) == false) { U_WARNING("usp_fork_mdb(): connection failed"); diff --git a/src/ulib/net/server/plugin/usp/mfortune.usp b/src/ulib/net/server/plugin/usp/mfortune.usp index ad352a3d..43fabc02 100644 --- a/src/ulib/net/server/plugin/usp/mfortune.usp +++ b/src/ulib/net/server/plugin/usp/mfortune.usp @@ -16,7 +16,7 @@ static void usp_fork_mfortune() U_NEW(UMongoDBClient, mc, UMongoDBClient); - if (mc->connect(0,0) == false) + if (mc->connect(U_NULLPTR, 0) == false) { U_WARNING("usp_fork_mfortune(): connection failed"); diff --git a/src/ulib/net/server/plugin/usp/mquery.usp b/src/ulib/net/server/plugin/usp/mquery.usp index 7b70e943..761bd434 100644 --- a/src/ulib/net/server/plugin/usp/mquery.usp +++ b/src/ulib/net/server/plugin/usp/mquery.usp @@ -17,7 +17,7 @@ static void usp_fork_mquery() U_NEW(UMongoDBClient, mc, UMongoDBClient); - if (mc->connect(0,0) == false) + if (mc->connect(U_NULLPTR, 0) == false) { U_WARNING("usp_fork_mquery(): connection disabled or failed"); diff --git a/src/ulib/net/server/plugin/usp/mupdate.usp b/src/ulib/net/server/plugin/usp/mupdate.usp index a17655b0..aa78c481 100644 --- a/src/ulib/net/server/plugin/usp/mupdate.usp +++ b/src/ulib/net/server/plugin/usp/mupdate.usp @@ -17,7 +17,7 @@ static void usp_fork_mupdate() U_NEW(UMongoDBClient, mc, UMongoDBClient); - if (mc->connect(0,0) == false) + if (mc->connect(U_NULLPTR, 0) == false) { U_WARNING("usp_fork_mupdate(): connection disabled or failed"); diff --git a/src/ulib/net/server/plugin/usp/query.usp b/src/ulib/net/server/plugin/usp/query.usp index 3cbf3300..22a55063 100644 --- a/src/ulib/net/server/plugin/usp/query.usp +++ b/src/ulib/net/server/plugin/usp/query.usp @@ -23,7 +23,7 @@ static void usp_fork_query() { U_NEW(UOrmStatement, pstmt_query, UOrmStatement(*psql_query, U_CONSTANT_TO_PARAM("SELECT randomNumber FROM World WHERE id = ?"))); - if (pstmt_query == 0) + if (pstmt_query == U_NULLPTR) { U_WARNING("usp_fork_query(): we cound't connect to db"); diff --git a/src/ulib/net/server/plugin/usp/update.usp b/src/ulib/net/server/plugin/usp/update.usp index cd606794..11ae7489 100644 --- a/src/ulib/net/server/plugin/usp/update.usp +++ b/src/ulib/net/server/plugin/usp/update.usp @@ -25,8 +25,8 @@ static void usp_fork_update() U_NEW(UOrmStatement, pstmt1, UOrmStatement(*psql_update, U_CONSTANT_TO_PARAM("SELECT randomNumber FROM World WHERE id = ?"))); U_NEW(UOrmStatement, pstmt2, UOrmStatement(*psql_update, U_CONSTANT_TO_PARAM("UPDATE World SET randomNumber = ? WHERE id = ?"))); - if (pstmt1 == 0 || - pstmt2 == 0) + if (pstmt1 == U_NULLPTR || + pstmt2 == U_NULLPTR) { U_WARNING("usp_fork_update(): we cound't connect to db"); diff --git a/src/ulib/net/server/plugin/usp/usp_translator.cpp b/src/ulib/net/server/plugin/usp/usp_translator.cpp index ebd18ada..c5a2258b 100644 --- a/src/ulib/net/server/plugin/usp/usp_translator.cpp +++ b/src/ulib/net/server/plugin/usp/usp_translator.cpp @@ -36,7 +36,7 @@ "\t\n" \ "%s" \ "%s" \ -"\n\tif (UHTTP::db_session == 0) UHTTP::initSession();\n" \ +"\n\tif (UHTTP::db_session == U_NULLPTR) UHTTP::initSession();\n" \ "}" #define USP_TEMPLATE \ @@ -533,8 +533,8 @@ public: buffer.snprintf(U_CONSTANT_TO_PARAM(USP_SESSION_INIT), size, ptr, size, ptr, - (bsession ? "\n\tif (UHTTP::data_session == 0) U_NEW(UDataSession, UHTTP::data_session, UDataSession);\n\t" : ""), - (bstorage ? "\n\tif (UHTTP::data_storage == 0) { U_NEW(UDataSession, UHTTP::data_storage, UDataSession(*UString::str_storage_keyid)); }\n\t" : "")); + (bsession ? "\n\tif (UHTTP::data_session == U_NULLPTR) U_NEW(UDataSession, UHTTP::data_session, UDataSession);\n\t" : ""), + (bstorage ? "\n\tif (UHTTP::data_storage == U_NULLPTR) { U_NEW(UDataSession, UHTTP::data_storage, UDataSession(*UString::str_storage_keyid)); }\n\t" : "")); (void) declaration.append(buffer); } diff --git a/src/ulib/net/server/plugin/usp/world.h b/src/ulib/net/server/plugin/usp/world.h index 14a71bcb..ec55d8d6 100644 --- a/src/ulib/net/server/plugin/usp/world.h +++ b/src/ulib/net/server/plugin/usp/world.h @@ -55,6 +55,24 @@ public: json.fromJSON(U_JSON_METHOD_HANDLER(randomNumber, unsigned int)); } + // ORM + + void bindParam(UOrmStatement* stmt) + { + U_TRACE(0, "World::bindParam(%p)", stmt) + + stmt->bindParam(U_ORM_TYPE_HANDLER(id, unsigned int)); + stmt->bindParam(U_ORM_TYPE_HANDLER(randomNumber, unsigned int)); + } + + void bindResult(UOrmStatement* stmt) + { + U_TRACE(0, "World::bindResult(%p)", stmt) + + stmt->bindResult(U_ORM_TYPE_HANDLER(id, unsigned int)); + stmt->bindResult(U_ORM_TYPE_HANDLER(randomNumber, unsigned int)); + } + #ifdef DEBUG const char* dump(bool breset) const { @@ -68,34 +86,11 @@ public: return UObjectIO::buffer_output; } - return 0; + return U_NULLPTR; } #endif private: U_DISALLOW_ASSIGN(World) }; - -// ORM TEMPLATE SPECIALIZATIONS - -template <> class U_EXPORT UOrmTypeHandler : public UOrmTypeHandler_Base { -public: - explicit UOrmTypeHandler(World& val) : UOrmTypeHandler_Base(&val) {} - - void bindParam(UOrmStatement* stmt) const - { - U_TRACE(0, "UOrmTypeHandler::bindParam(%p)", stmt) - - stmt->bindParam(U_ORM_TYPE_HANDLER(World, id, unsigned int)); - stmt->bindParam(U_ORM_TYPE_HANDLER(World, randomNumber, unsigned int)); - } - - void bindResult(UOrmStatement* stmt) - { - U_TRACE(0, "UOrmTypeHandler::bindResult(%p)", stmt) - - stmt->bindResult(U_ORM_TYPE_HANDLER(World, id, unsigned int)); - stmt->bindResult(U_ORM_TYPE_HANDLER(World, randomNumber, unsigned int)); - } -}; #endif diff --git a/src/ulib/utility/http2.cpp b/src/ulib/utility/http2.cpp index 5049177b..31070f06 100644 --- a/src/ulib/utility/http2.cpp +++ b/src/ulib/utility/http2.cpp @@ -2406,6 +2406,10 @@ window_update: pConnection->inp_window = (HTTP2_MAX_WINDOW_SIZE + pConnection->inp_window); sendWindowUpdate(); + + U_INTERNAL_DUMP("nerror = %u", nerror) + + if (nerror != NO_ERROR) goto end; } goto loop; @@ -3478,9 +3482,15 @@ loop: U_DUMP("pStream->id = %u pStream->state = (%u, %s) pStream->headers(%u) = if (pConnection->inp_window < 8192) // Send Window Update if current window size is not sufficient { - pConnection->inp_window = HTTP2_MAX_WINDOW_SIZE; + pConnection->inp_window = HTTP2_MAX_WINDOW_SIZE - pConnection->inp_window; sendWindowUpdate(); + + U_INTERNAL_DUMP("nerror = %u", nerror) + + if (nerror != NO_ERROR) goto err; + + pConnection->inp_window = HTTP2_MAX_WINDOW_SIZE; } } diff --git a/tests/examples/benchmark/FrameworkBenchmarks/ULib/db/hello_world.db b/tests/examples/benchmark/FrameworkBenchmarks/ULib/db/hello_world.db index dd66f304629f4762c6fd935b851c75b1414f9f83..dbe3b2196e4ab93092bddf9860ce7946f064629e 100644 GIT binary patch delta 51 zcmZoTz~69ye}Xil%|sbzRvQLAPL0Nt))dCADNHQPOgt&=SbindParam(U_ORM_TYPE_HANDLER(id, unsigned int)); + stmt->bindParam(U_ORM_TYPE_HANDLER(message, UString)); + } + + void bindResult(UOrmStatement* stmt) + { + U_TRACE(0, "Fortune::bindResult(%p)", stmt) + + stmt->bindResult(U_ORM_TYPE_HANDLER(id, unsigned int)); + stmt->bindResult(U_ORM_TYPE_HANDLER(message, UString)); + } + #ifdef DEBUG const char* dump(bool breset) const { @@ -100,34 +118,11 @@ public: return UObjectIO::buffer_output; } - return 0; + return U_NULLPTR; } #endif private: U_DISALLOW_ASSIGN(Fortune) }; - -// ORM TEMPLATE SPECIALIZATIONS - -template <> class U_EXPORT UOrmTypeHandler : public UOrmTypeHandler_Base { -public: - explicit UOrmTypeHandler(Fortune& val) : UOrmTypeHandler_Base(&val) {} - - void bindParam(UOrmStatement* stmt) const - { - U_TRACE(0, "UOrmTypeHandler::bindParam(%p)", stmt) - - stmt->bindParam(U_ORM_TYPE_HANDLER(Fortune, id, unsigned int)); - stmt->bindParam(U_ORM_TYPE_HANDLER(Fortune, message, UString)); - } - - void bindResult(UOrmStatement* stmt) - { - U_TRACE(0, "UOrmTypeHandler::bindResult(%p)", stmt) - - stmt->bindResult(U_ORM_TYPE_HANDLER(Fortune, id, unsigned int)); - stmt->bindResult(U_ORM_TYPE_HANDLER(Fortune, message, UString)); - } -}; #endif diff --git a/tests/examples/benchmark/FrameworkBenchmarks/ULib/src/fortune.usp b/tests/examples/benchmark/FrameworkBenchmarks/ULib/src/fortune.usp index d9bf9c79..993caecf 100644 --- a/tests/examples/benchmark/FrameworkBenchmarks/ULib/src/fortune.usp +++ b/tests/examples/benchmark/FrameworkBenchmarks/ULib/src/fortune.usp @@ -24,7 +24,7 @@ static void usp_fork_fortune() { U_NEW(UOrmStatement, pstmt_fortune, UOrmStatement(*psql_fortune, U_CONSTANT_TO_PARAM("SELECT id, message FROM Fortune"))); - if (pstmt_fortune == 0) + if (pstmt_fortune == U_NULLPTR) { U_WARNING("usp_fork_fortune(): we cound't connect to db"); diff --git a/tests/examples/benchmark/FrameworkBenchmarks/ULib/src/mdb.usp b/tests/examples/benchmark/FrameworkBenchmarks/ULib/src/mdb.usp index 1e99b434..9ac4976f 100644 --- a/tests/examples/benchmark/FrameworkBenchmarks/ULib/src/mdb.usp +++ b/tests/examples/benchmark/FrameworkBenchmarks/ULib/src/mdb.usp @@ -13,7 +13,7 @@ static void usp_fork_mdb() U_NEW(UMongoDBClient, mc, UMongoDBClient); - if (mc->connect(0,0) == false) + if (mc->connect(U_NULLPTR, 0) == false) { U_WARNING("usp_fork_mdb(): connection failed"); diff --git a/tests/examples/benchmark/FrameworkBenchmarks/ULib/src/mfortune.usp b/tests/examples/benchmark/FrameworkBenchmarks/ULib/src/mfortune.usp index ad352a3d..43fabc02 100644 --- a/tests/examples/benchmark/FrameworkBenchmarks/ULib/src/mfortune.usp +++ b/tests/examples/benchmark/FrameworkBenchmarks/ULib/src/mfortune.usp @@ -16,7 +16,7 @@ static void usp_fork_mfortune() U_NEW(UMongoDBClient, mc, UMongoDBClient); - if (mc->connect(0,0) == false) + if (mc->connect(U_NULLPTR, 0) == false) { U_WARNING("usp_fork_mfortune(): connection failed"); diff --git a/tests/examples/benchmark/FrameworkBenchmarks/ULib/src/mquery.usp b/tests/examples/benchmark/FrameworkBenchmarks/ULib/src/mquery.usp index 7b70e943..761bd434 100644 --- a/tests/examples/benchmark/FrameworkBenchmarks/ULib/src/mquery.usp +++ b/tests/examples/benchmark/FrameworkBenchmarks/ULib/src/mquery.usp @@ -17,7 +17,7 @@ static void usp_fork_mquery() U_NEW(UMongoDBClient, mc, UMongoDBClient); - if (mc->connect(0,0) == false) + if (mc->connect(U_NULLPTR, 0) == false) { U_WARNING("usp_fork_mquery(): connection disabled or failed"); diff --git a/tests/examples/benchmark/FrameworkBenchmarks/ULib/src/mupdate.usp b/tests/examples/benchmark/FrameworkBenchmarks/ULib/src/mupdate.usp index a17655b0..aa78c481 100644 --- a/tests/examples/benchmark/FrameworkBenchmarks/ULib/src/mupdate.usp +++ b/tests/examples/benchmark/FrameworkBenchmarks/ULib/src/mupdate.usp @@ -17,7 +17,7 @@ static void usp_fork_mupdate() U_NEW(UMongoDBClient, mc, UMongoDBClient); - if (mc->connect(0,0) == false) + if (mc->connect(U_NULLPTR, 0) == false) { U_WARNING("usp_fork_mupdate(): connection disabled or failed"); diff --git a/tests/examples/benchmark/FrameworkBenchmarks/ULib/src/query.usp b/tests/examples/benchmark/FrameworkBenchmarks/ULib/src/query.usp index 3cbf3300..22a55063 100644 --- a/tests/examples/benchmark/FrameworkBenchmarks/ULib/src/query.usp +++ b/tests/examples/benchmark/FrameworkBenchmarks/ULib/src/query.usp @@ -23,7 +23,7 @@ static void usp_fork_query() { U_NEW(UOrmStatement, pstmt_query, UOrmStatement(*psql_query, U_CONSTANT_TO_PARAM("SELECT randomNumber FROM World WHERE id = ?"))); - if (pstmt_query == 0) + if (pstmt_query == U_NULLPTR) { U_WARNING("usp_fork_query(): we cound't connect to db"); diff --git a/tests/examples/benchmark/FrameworkBenchmarks/ULib/src/update.usp b/tests/examples/benchmark/FrameworkBenchmarks/ULib/src/update.usp index cd606794..11ae7489 100644 --- a/tests/examples/benchmark/FrameworkBenchmarks/ULib/src/update.usp +++ b/tests/examples/benchmark/FrameworkBenchmarks/ULib/src/update.usp @@ -25,8 +25,8 @@ static void usp_fork_update() U_NEW(UOrmStatement, pstmt1, UOrmStatement(*psql_update, U_CONSTANT_TO_PARAM("SELECT randomNumber FROM World WHERE id = ?"))); U_NEW(UOrmStatement, pstmt2, UOrmStatement(*psql_update, U_CONSTANT_TO_PARAM("UPDATE World SET randomNumber = ? WHERE id = ?"))); - if (pstmt1 == 0 || - pstmt2 == 0) + if (pstmt1 == U_NULLPTR || + pstmt2 == U_NULLPTR) { U_WARNING("usp_fork_update(): we cound't connect to db"); diff --git a/tests/examples/benchmark/FrameworkBenchmarks/ULib/src/world.h b/tests/examples/benchmark/FrameworkBenchmarks/ULib/src/world.h index b3a2a932..d7a746dc 100644 --- a/tests/examples/benchmark/FrameworkBenchmarks/ULib/src/world.h +++ b/tests/examples/benchmark/FrameworkBenchmarks/ULib/src/world.h @@ -55,6 +55,24 @@ public: json.fromJSON(U_JSON_METHOD_HANDLER(randomNumber, unsigned int)); } + // ORM + + void bindParam(UOrmStatement* stmt) + { + U_TRACE(0, "World::bindParam(%p)", stmt) + + stmt->bindParam(U_ORM_TYPE_HANDLER(id, unsigned int)); + stmt->bindParam(U_ORM_TYPE_HANDLER(randomNumber, unsigned int)); + } + + void bindResult(UOrmStatement* stmt) + { + U_TRACE(0, "World::bindResult(%p)", stmt) + + stmt->bindResult(U_ORM_TYPE_HANDLER(id, unsigned int)); + stmt->bindResult(U_ORM_TYPE_HANDLER(randomNumber, unsigned int)); + } + #ifdef DEBUG const char* dump(bool breset) const { @@ -68,34 +86,11 @@ public: return UObjectIO::buffer_output; } - return 0; + return U_NULLPTR; } #endif private: U_DISALLOW_ASSIGN(World) }; - -// ORM TEMPLATE SPECIALIZATIONS - -template <> class U_EXPORT UOrmTypeHandler : public UOrmTypeHandler_Base { -public: - explicit UOrmTypeHandler(World& val) : UOrmTypeHandler_Base(&val) {} - - void bindParam(UOrmStatement* stmt) const - { - U_TRACE(0, "UOrmTypeHandler::bindParam(%p)", stmt) - - stmt->bindParam(U_ORM_TYPE_HANDLER(World, id, unsigned int)); - stmt->bindParam(U_ORM_TYPE_HANDLER(World, randomNumber, unsigned int)); - } - - void bindResult(UOrmStatement* stmt) - { - U_TRACE(0, "UOrmTypeHandler::bindResult(%p)", stmt) - - stmt->bindResult(U_ORM_TYPE_HANDLER(World, id, unsigned int)); - stmt->bindResult(U_ORM_TYPE_HANDLER(World, randomNumber, unsigned int)); - } -}; #endif diff --git a/tests/examples/web_server.sh b/tests/examples/web_server.sh index f93577ed..f4d05e17 100755 --- a/tests/examples/web_server.sh +++ b/tests/examples/web_server.sh @@ -68,6 +68,7 @@ userver { #REQ_TIMEOUT 300 #PLUGIN "ssi http" #ORM_DRIVER "sqlite mysql" + ORM_DRIVER sqlite DOCUMENT_ROOT benchmark/docroot PLUGIN_DIR ../../../../src/ulib/net/server/plugin/.libs ORM_DRIVER_DIR ../../../../src/ulib/orm/driver/.libs diff --git a/tests/ulib/test_orm.cpp b/tests/ulib/test_orm.cpp index 07578d61..58020aa4 100644 --- a/tests/ulib/test_orm.cpp +++ b/tests/ulib/test_orm.cpp @@ -60,6 +60,30 @@ public: return (_address < p._address); } + void bindParam(UOrmStatement* stmt) + { + U_TRACE(0, "Person::bindParam(%p)", stmt) + + // the table is defined as Person (LastName VARCHAR(30), FirstName VARCHAR(30), Address VARCHAR(30), Age INTEGER) + + stmt->bindParam(U_ORM_TYPE_HANDLER(_lastName, UString)); + stmt->bindParam(U_ORM_TYPE_HANDLER(_firstName, UString)); + stmt->bindParam(U_ORM_TYPE_HANDLER(_address, UString)); + stmt->bindParam(U_ORM_TYPE_HANDLER(_age, int)); + } + + void bindResult(UOrmStatement* stmt) + { + U_TRACE(0, "Person::bindResult(%p)", stmt) + + // the table is defined as Person (LastName VARCHAR(30), FirstName VARCHAR(30), Address VARCHAR(30), Age INTEGER) + + stmt->bindResult(U_ORM_TYPE_HANDLER(_lastName, UString)); + stmt->bindResult(U_ORM_TYPE_HANDLER(_firstName, UString)); + stmt->bindResult(U_ORM_TYPE_HANDLER(_address, UString)); + stmt->bindResult(U_ORM_TYPE_HANDLER(_age, int)); + } + #ifdef DEBUG const char* dump(bool breset) const { @@ -75,7 +99,7 @@ public: return UObjectIO::buffer_output; } - return 0; + return U_NULLPTR; } #endif @@ -117,6 +141,22 @@ public: U_TRACE_UNREGISTER_OBJECT(5, Test1) } + void bindParam(UOrmStatement* stmt) + { + U_TRACE(0, "UOrmTypeHandler::bindParam(%p)", stmt) + + stmt->bindParam(U_ORM_TYPE_HANDLER(id, int)); + stmt->bindParam(U_ORM_TYPE_HANDLER(name, UString)); + } + + void bindResult(UOrmStatement* stmt) + { + U_TRACE(0, "UOrmTypeHandler::bindResult(%p)", stmt) + + stmt->bindResult(U_ORM_TYPE_HANDLER(id, int)); + stmt->bindResult(U_ORM_TYPE_HANDLER(name, UString)); + } + #ifdef DEBUG const char* dump(bool breset) const { @@ -130,7 +170,7 @@ public: return UObjectIO::buffer_output; } - return 0; + return U_NULLPTR; } #endif @@ -138,56 +178,6 @@ private: Test1& operator=(const Test1&) { return *this; } }; -// ORM TEMPLATE SPECIALIZATIONS - -template <> class UOrmTypeHandler : public UOrmTypeHandler_Base { -public: - explicit UOrmTypeHandler(Person& val) : UOrmTypeHandler_Base(&val) {} - - // the table is defined as Person (LastName VARCHAR(30), FirstName VARCHAR(30), Address VARCHAR(30), Age INTEGER) - - void bindParam(UOrmStatement* stmt) const - { - U_TRACE(0, "UOrmTypeHandler::bindParam(%p)", stmt) - - stmt->bindParam(U_ORM_TYPE_HANDLER(Person, _lastName, UString)); - stmt->bindParam(U_ORM_TYPE_HANDLER(Person, _firstName, UString)); - stmt->bindParam(U_ORM_TYPE_HANDLER(Person, _address, UString)); - stmt->bindParam(U_ORM_TYPE_HANDLER(Person, _age, int)); - } - - void bindResult(UOrmStatement* stmt) - { - U_TRACE(0, "UOrmTypeHandler::bindResult(%p)", stmt) - - stmt->bindResult(U_ORM_TYPE_HANDLER(Person, _lastName, UString)); - stmt->bindResult(U_ORM_TYPE_HANDLER(Person, _firstName, UString)); - stmt->bindResult(U_ORM_TYPE_HANDLER(Person, _address, UString)); - stmt->bindResult(U_ORM_TYPE_HANDLER(Person, _age, int)); - } -}; - -template <> class U_EXPORT UOrmTypeHandler : public UOrmTypeHandler_Base { -public: - explicit UOrmTypeHandler(Test1& val) : UOrmTypeHandler_Base(&val) {} - - void bindParam(UOrmStatement* stmt) const - { - U_TRACE(0, "UOrmTypeHandler::bindParam(%p)", stmt) - - stmt->bindParam(U_ORM_TYPE_HANDLER(Test1, id, int)); - stmt->bindParam(U_ORM_TYPE_HANDLER(Test1, name, UString)); - } - - void bindResult(UOrmStatement* stmt) - { - U_TRACE(0, "UOrmTypeHandler::bindResult(%p)", stmt) - - stmt->bindResult(U_ORM_TYPE_HANDLER(Test1, id, int)); - stmt->bindResult(U_ORM_TYPE_HANDLER(Test1, name, UString)); - } -}; - static void testBinding(UOrmSession* sql) { U_TRACE(5, "testBinding(%p)", sql) @@ -488,7 +478,7 @@ U_EXPORT main(int argc, char* argv[]) value1 = 10; str = "Hello 'World'"; float f = 3.1415926565; - time_t tt = time(NULL); + time_t tt = time(U_NULLPTR); struct tm t = *localtime(&tt); cout << asctime(&t); diff --git a/ulib.html b/ulib.html new file mode 100644 index 00000000..8fc61e3c --- /dev/null +++ b/ulib.html @@ -0,0 +1,402 @@ + + + + +ULib + + + + + + + + +
+

ULib

+ +
+

1 Getting Started With ULib

+
+

+To help those curious souls that want to see if userver is a good fit for their needs I have recorded my own experiences below. +Firstly a huge thankyou to Stefano Casazza not only for making ULib but for all his patience in answering all my questions. +

+
+ +
+

1.1 What is userver

+
+

+UServer is a extensible plugin based web server that is build on top of ULib. +

+ +

+ULib is installed as a set of shared object libraries and header files (like Boost). +

+
+
+ +
+

1.2 Get a copy of the ULib source code

+ +
+ +
+

1.3 configure your build

+
+

+For those of you like me who havn't had much experience playing with autotools read the config help or: +

+ +

+./configure -h +

+ +

+Having now decided on what features you need let ./configure do its magic. +

+ +

+For example: +./configure –enable-debug –with-sqlite3 +

+ +

+make +sudo make install +

+
+
+ +
+

1.4 configure userver

+
+

+Assuming you haven't changed the PREFIX make will install userver to /usr/local +

+ +

+At this point we need to configure /usr/local/etc/userver.cfg +The file is well annotated at a bare minimum setup the following values: +
+ DOCUMENT_ROOT /var/www
+ LOG_FILE userver.log
+ PLUGIN "http"
+ PLUGIN_DIR /usr/local/libexec
+ ORM_DRIVER_DIR /usr/local/libexec
+

+
+
+

+This environment variables are for ORM management: +
+ ORM_DRIVER "sqlite"
+ ORM_OPTION "host=localhost user=user password=pass character-set=utf8 dbname=/path_to_db/dbname.db" +

+
+
+ +
+

1.5 debug environment

+
+

+userver_tcp expects some environment variables for debug mode to save typing it is easiest to put these into a bash script like this: +

+ +

+#!/bin/sh +

+ +

+ UTRACE="0 20M 0"
+ UTRACE_SIGNAL="0 20M 0"
+#UOBJDUMP="0 10M 100"
+#USIMERR="error.sim"
+ export UTRACE UOBJDUMP USIMERR UTRACE_SIGNAL +

+ +

+userver_tcp +

+
+
+ + +
+

1.6 Running your server (static pages)

+
+

+Once you have configured your userver.cfg and placed the relevant html documents in your docroot just execute the bash script above. +

+ +

+Point your browser to localhost/filename you should now have a working server. +

+
+
+ +
+

1.7 USP ULib Servlet Page (dynamic pages)

+
+

+userver offers a wide variety of ways to generate dynamic content we will be looking at USP method. +

+ +

+A USP page is a multi-format document that permits c++ code to be embedded into html. +This document is then compiled into a shared object library that will be executed by userver. +

+ +

+The document consists of overloaded html comment tags that the USP compiler will extract. +

+
+
+ +
+

1.8 Tags

+
+

+Have a look at the examples in the ULib source directory ULib/src/ulib/net/server/plugin/usp for usage but in very simple terms. +

+
+ +
+

1.8.1 c++ header file .h

+
+

+<!–#declaration +–> +

+
+
+ +
+

1.8.2 c++ code file .cpp

+
+

+<!–#code +UString name = U_STRING_FROM_CONSTANT("Hello World"); +–> +

+
+
+ +
+

1.8.3 html template

+
+

+<h1>Hello <!–#xmlputs name –></h1> +

+
+
+
+ +
+

1.9 Compiling

+
+

+Once you have written your .usp file it needs to be compiled. +I found it easiest to navigate to the folder where the file.usp was saved and execute the compilation in the shell for example: +

+ +

+cd /srv/http/servlet +/usr/local/bin/usp_compile.sh test +

+ +

+Please note that usp_compile.sh wants the usp file without the extension. +The shell script will call the relevant programs to generate c++ code from the usp file and finally call gcc and libtool to create a shared library.Any compilation errors will be output to console and no .so file will be generated. +

+ +

+It would be trivial to execute usp_compile as a custom command from most IDEs. +

+
+
+ +
+

1.10 Test

+
+

+Now point your browser to localhost/nameofusp and userver will execute the USP file. +

+
+
+ +
+

1.11 SECURITY

+
+

+As with all web servers do not run them as the root user. +This introduction has been written to give you an idea of the ULib/UServer workflow. It is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. It is your responsibility to secure your web server and follow sound security conscious programming practices. +

+
+
+ + +
+

Author: nemsys

+

Created: 2017-05-07 Sun 13:21

+

Emacs 25.2.1 (Org mode 8.2.10)

+

Validate

+
+ +