Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

various enhancement + fix very insidious bug

  • Loading branch information...
commit b6989654f097cf3b32d13a5a2c6ced3623e73c00 1 parent 4b9da43
@stefanocasazza authored
Showing with 4,400 additions and 2,627 deletions.
  1. +2 −0  README.html
  2. +2 −0  README.md
  3. +4 −23 configure
  4. +4 −6 configure.in
  5. +6 −0 examples/IR/ir_web.cpp
  6. +6 −0 examples/IR/ir_web.usp
  7. +1 −1  examples/IR/posting.cpp
  8. +18 −20 examples/PEC_log/PEC_report_anomalie.cpp
  9. +3 −3 examples/PEC_log/PEC_report_anomalie1.cpp
  10. +136 −59 examples/WiAuth/wi_auth.cpp
  11. +136 −59 examples/WiAuth/wi_auth.usp
  12. +1 −3 examples/XAdES/feed.cpp
  13. +10 −12 examples/download_accelerator/main.cpp
  14. +4 −6 examples/uclient/uclient.cpp
  15. +1 −0  include/ulib/all.h
  16. +2 −0  include/ulib/base/macro.h
  17. +1 −1  include/ulib/base/utility.h
  18. +4 −0 include/ulib/base/win32/system.h
  19. +3 −3 include/ulib/container/gen_hash_map.h
  20. +63 −42 include/ulib/container/hash_map.h
  21. +2 −2 include/ulib/container/tree.h
  22. +28 −11 include/ulib/container/vector.h
  23. +1 −1  include/ulib/debug/error_memory.h
  24. +32 −17 include/ulib/debug/macro.h
  25. +5 −1 include/ulib/debug/objectDB.h
  26. +2 −0  include/ulib/event/event_fd.h
  27. +53 −26 include/ulib/file.h
  28. +48 −52 include/ulib/internal/chttp.h
  29. +8 −29 include/ulib/internal/common.h
  30. +0 −3  include/ulib/internal/config.h.in
  31. +4 −11 include/ulib/internal/macro.h
  32. +56 −85 include/ulib/internal/memory_pool.h
  33. +16 −8 include/ulib/log.h
  34. +23 −17 include/ulib/net/client/client.h
  35. +0 −4 include/ulib/net/client/client_rdb.h
  36. +5 −9 include/ulib/net/client/http.h
  37. +1 −1  include/ulib/net/ipaddress.h
  38. +1 −1  include/ulib/net/ping.h
  39. +3 −3 include/ulib/net/rpc/rpc_client.h
  40. +10 −14 include/ulib/net/server/client_image.h
  41. +11 −9 include/ulib/net/server/plugin/mod_nocat.h
  42. +64 −17 include/ulib/net/server/server.h
  43. +7 −42 include/ulib/net/server/server_rdb.h
  44. +2 −2 include/ulib/net/socket.h
  45. +2 −2 include/ulib/notifier.h
  46. +0 −1  include/ulib/ssl/net/ssl_session.h
  47. +2 −9 include/ulib/ssl/net/sslsocket.h
  48. +169 −86 include/ulib/string.h
  49. +1 −1  include/ulib/thread.h
  50. +2 −2 include/ulib/tokenizer.h
  51. +154 −0 include/ulib/utility/dir_walk.h
  52. +2 −2 include/ulib/utility/ring_buffer.h
  53. +2 −1  include/ulib/utility/semaphore.h
  54. +7 −3 include/ulib/utility/string_ext.h
  55. +13 −97 include/ulib/utility/uhttp.h
  56. +6 −7 include/ulib/xml/soap/soap_client.h
  57. +0 −8 m4/ac_compilation_options.m4
  58. +4 −2 openwrt/package/nodog/Makefile
  59. +1 −1  src/ulib/Makefile.am
  60. +41 −32 src/ulib/Makefile.in
  61. +1 −0  src/ulib/all_cpp.cpp
  62. +10 −0 src/ulib/application.cpp
  63. +38 −7 src/ulib/base/utility.c
  64. +2 −1  src/ulib/cache.cpp
  65. +19 −14 src/ulib/command.cpp
  66. +56 −3 src/ulib/container/hash_map.cpp
  67. +2 −0  src/ulib/container/tree.cpp
  68. +31 −9 src/ulib/container/vector.cpp
  69. +2 −0  src/ulib/curl/curl.cpp
  70. +2 −1  src/ulib/date.cpp
  71. +12 −11 src/ulib/db/cdb.cpp
  72. +5 −8 src/ulib/db/rdb.cpp
  73. +8 −0 src/ulib/dbi/dbi.cpp
  74. +3 −3 src/ulib/debug/debug_common.cpp
  75. +45 −14 src/ulib/debug/objectDB.cpp
  76. +1 −1  src/ulib/debug/trace.cpp
  77. +2 −0  src/ulib/dynamic/dynamic.cpp
  78. +2 −0  src/ulib/dynamic/plugin.cpp
  79. +2 −0  src/ulib/dynamic/ruby.cpp
  80. +2 −0  src/ulib/event/event_time.cpp
  81. +90 −21 src/ulib/file.cpp
  82. +2 −1  src/ulib/file_config.cpp
  83. +2 −0  src/ulib/flex/bison.cpp
  84. +2 −0  src/ulib/flex/flexer.cpp
  85. +17 −4 src/ulib/internal/common.cpp
  86. +351 −279 src/ulib/internal/memory_pool.cpp
  87. +1 −1  src/ulib/internal/objectIO.cpp
  88. +31 −16 src/ulib/json/value.cpp
  89. +11 −15 src/ulib/ldap/ldap.cpp
  90. +2 −0  src/ulib/libevent/event.cpp
  91. +139 −74 src/ulib/log.cpp
  92. +2 −0  src/ulib/magic/magic.cpp
  93. +7 −1 src/ulib/mime/entity.cpp
  94. +2 −2 src/ulib/mime/header.cpp
  95. +2 −0  src/ulib/mime/multipart.cpp
  96. +6 −0 src/ulib/mysql/mysql.cpp
  97. +43 −42 src/ulib/net/client/client.cpp
  98. +7 −5 src/ulib/net/client/client_rdb.cpp
  99. +2 −0  src/ulib/net/client/ftp.cpp
  100. +225 −152 src/ulib/net/client/http.cpp
  101. +2 −0  src/ulib/net/client/imap.cpp
  102. +2 −0  src/ulib/net/client/pop3.cpp
  103. +2 −0  src/ulib/net/client/smtp.cpp
  104. +4 −1 src/ulib/net/ipaddress.cpp
  105. +3 −2 src/ulib/net/ipt_ACCOUNT.cpp
  106. +15 −13 src/ulib/net/ping.cpp
  107. +2 −0  src/ulib/net/rpc/rpc_encoder.cpp
  108. +2 −0  src/ulib/net/rpc/rpc_envelope.cpp
  109. +2 −0  src/ulib/net/rpc/rpc_fault.cpp
  110. +2 −0  src/ulib/net/rpc/rpc_gen_method.cpp
  111. +2 −0  src/ulib/net/rpc/rpc_method.cpp
  112. +2 −0  src/ulib/net/rpc/rpc_object.cpp
  113. +2 −0  src/ulib/net/rpc/rpc_parser.cpp
  114. +143 −62 src/ulib/net/server/client_image.cpp
  115. +8 −2 src/ulib/net/server/client_image_rdb.cpp
  116. +3 −0  src/ulib/net/server/plugin/mod_echo.cpp
  117. +8 −37 src/ulib/net/server/plugin/mod_http.cpp
  118. +123 −98 src/ulib/net/server/plugin/mod_nocat.cpp
  119. +1 −4 src/ulib/net/server/plugin/mod_proxy.cpp
  120. +2 −0  src/ulib/net/server/plugin/mod_proxy_service.cpp
  121. +2 −2 src/ulib/net/server/plugin/mod_shib/mod_shib.cpp
  122. +17 −14 src/ulib/net/server/plugin/mod_ssi.cpp
  123. +7 −7 src/ulib/net/server/plugin/usp/usp_translator.cpp
  124. +169 −116 src/ulib/net/server/server.cpp
  125. +60 −1 src/ulib/net/server/server_rdb.cpp
  126. +3 −2 src/ulib/net/socket.cpp
  127. +1 −1  src/ulib/net/tcpsocket.cpp
  128. +2 −1  src/ulib/net/unixsocket.cpp
  129. +18 −18 src/ulib/notifier.cpp
  130. +18 −15 src/ulib/options.cpp
  131. +6 −5 src/ulib/pcre/pcre.cpp
  132. +2 −1  src/ulib/process.cpp
  133. +8 −5 src/ulib/query/query_parser.cpp
  134. +2 −1  src/ulib/ssh/net/sshsocket.cpp
  135. +2 −1  src/ulib/ssl/certificate.cpp
  136. +2 −1  src/ulib/ssl/crl.cpp
  137. +2 −1  src/ulib/ssl/mime/mime_pkcs7.cpp
  138. +12 −15 src/ulib/ssl/net/ssl_session.cpp
  139. +35 −1 src/ulib/ssl/net/sslsocket.cpp
  140. +2 −1  src/ulib/ssl/pkcs10.cpp
  141. +2 −1  src/ulib/ssl/pkcs7.cpp
  142. +2 −1  src/ulib/ssl/timestamp.cpp
  143. +363 −228 src/ulib/string.cpp
  144. +5 −2 src/ulib/thread.cpp
  145. +2 −1  src/ulib/timer.cpp
  146. +2 −1  src/ulib/timeval.cpp
  147. +2 −0  src/ulib/tokenizer.cpp
  148. +2 −1  src/ulib/ui/dialog.cpp
  149. +2 −1  src/ulib/url.cpp
  150. +2 −1  src/ulib/utility/data_session.cpp
  151. +316 −0 src/ulib/utility/dir_walk.cpp
  152. +2 −1  src/ulib/utility/lock.cpp
  153. +10 −9 src/ulib/utility/ring_buffer.cpp
  154. +8 −7 src/ulib/utility/semaphore.cpp
  155. +4 −3 src/ulib/utility/services.cpp
  156. +12 −10 src/ulib/utility/socket_ext.cpp
  157. +43 −54 src/ulib/utility/string_ext.cpp
  158. +245 −172 src/ulib/utility/uhttp.cpp
  159. +2 −1  src/ulib/xml/expat/attribute.cpp
  160. +2 −1  src/ulib/xml/expat/element.cpp
  161. +2 −1  src/ulib/xml/expat/xml2txt.cpp
  162. +2 −1  src/ulib/xml/expat/xml_parser.cpp
  163. +2 −1  src/ulib/xml/libxml2/document.cpp
  164. +2 −1  src/ulib/xml/libxml2/node.cpp
  165. +2 −1  src/ulib/xml/libxml2/schema.cpp
  166. +2 −0  src/ulib/xml/soap/soap_parser.cpp
  167. +2 −1  src/ulib/zip/zip.cpp
  168. +3 −2 tests/examples/Makefile.am
  169. +3 −2 tests/examples/Makefile.in
  170. +1 −1  tests/examples/TSA/CA/tsaserial
  171. +5 −8 tests/examples/benchmarking.sh
  172. +1 −1  tests/examples/client_server.test
  173. +9 −19 tests/examples/inp/http/all4.inp
  174. BIN  tests/examples/inp/http/all5.inp
  175. +36 −46 tests/examples/nocat.cfg
  176. +8 −6 tests/examples/nocat.sh
  177. +19 −0 tests/examples/nocat/cgi-bin/allow.sh
  178. +13 −0 tests/examples/nocat/cgi-bin/peer.sh
  179. +4 −0 tests/examples/nocat/etc/nodog.env
  180. +1 −1  tests/examples/nocat/firewall/nodog.fw
  181. +97 −0 tests/examples/nocat/nodog.shtml
  182. +2 −2 tests/examples/tsa_http.test
  183. +2 −2 tests/examples/uclient.test
  184. +2 −2 tests/examples/web_server.test
  185. +3 −2 tests/examples/web_server_multiclient.test
  186. +1 −1  tests/examples/web_server_ssl.test
  187. +1 −0  tests/examples/wi-auth/www/10.30.1.111/cgi-bin/main.bash
  188. +2 −1  tests/ulib/Makefile.am
  189. +2 −1  tests/ulib/application.test
  190. +1 −1  tests/ulib/file_config.test
  191. +1 −1  tests/ulib/header.test
  192. BIN  tests/ulib/inp/test.db
  193. +1 −1  tests/ulib/log.test
  194. +33 −33 tests/ulib/ok/file_config.ok
  195. +8 −8 tests/ulib/ok/header.ok
  196. 0  tests/ulib/private/id_rsa.pub
  197. +1 −1  tests/ulib/query_parser.test
  198. +1 −1  tests/ulib/rdb_client_server.test
  199. +1 −1  tests/ulib/server.test
  200. +2 −5 tests/ulib/test_arping.cpp
  201. +1 −1  tests/ulib/test_http.cpp
  202. +2 −2 tests/ulib/test_https.cpp
  203. +1 −0  tests/ulib/test_rdb_server.cpp
  204. +2 −2 tests/ulib/test_string.cpp
  205. +2 −0  tests/ulib/test_vector.cpp
  206. +2 −2 tests/ulib/vector.test
View
2  README.html
@@ -64,7 +64,9 @@
<li>Support for running JavaScript code with wrapping <a href="http://code.google.com/apis/v8/intro.html">google V8 JavaScript Engine</a>.</li>
<li><a href="http://www.phpmotionwiz.com/what-is-pseudo-streaming">HTTP pseudo-streaming</a> for FLV video managed transparently.</li>
<li><a href="http://bellard.org/tcc/">C Servlet Support</a> with libtcc (if available) as a backend for dynamic code generation (experimental).</li>
+<li>Preforking mode to improve concurrency.</li>
<li>Support for Windows (without preforking).</li>
+<li>Customizable builds (you can remove unneeded functionality).</li>
<li>Requests cut in phases for modular architecture (apache-like).</li>
<li>Configuration file with dedicated section.</li>
<li>Built-in modules :
View
2  README.md
@@ -66,7 +66,9 @@ The current version offers the following features :
* Support for running JavaScript code with wrapping [google V8 JavaScript Engine](http://code.google.com/apis/v8/intro.html).
* [HTTP pseudo-streaming](http://www.phpmotionwiz.com/what-is-pseudo-streaming) for FLV video managed transparently.
* [C Servlet Support](http://bellard.org/tcc/) with libtcc (if available) as a backend for dynamic code generation (experimental).
+ * Preforking mode to improve concurrency.
* Support for Windows (without preforking).
+ * Customizable builds (you can remove unneeded functionality).
* Requests cut in phases for modular architecture (apache-like).
* Configuration file with dedicated section.
* Built-in modules :
View
27 configure
@@ -951,7 +951,6 @@ enable_gcc_optimized
enable_mudflap
enable_final
enable_new_ldflags
-enable_overload_new_delete
with_parser
with_distcc
with_libz
@@ -1637,7 +1636,6 @@ Optional Features:
--enable-mudflap build binaries with mudflap instrumentation [default=no]
--enable-final build size optimized apps (needs more amounts of memory) [default=yes]
--enable-new-ldflags enable the new linker flags (enable-new-dtags,as-needed,...) [default=yes]
- --enable-overload-new-delete enable use of our versions of the C++ memory operators [default=no]
--enable-zip enable build of ZIP support - require libz [default: use if present libz]
--enable-thread enable build of thread support - require libpthread [default: use if present libpthread]
--enable-static-module=MODULES - mod_rpc mod_shib mod_stream mod_socket mod_scgi mod_fcgi mod_geoip mod_proxy mod_soap mod_ssi mod_tsa mod_nocat mod_http mod_echo
@@ -21071,19 +21069,6 @@ fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: ${enable_new_ldflags}" >&5
$as_echo "${enable_new_ldflags}" >&6; }
- { $as_echo "$as_me:${as_lineno-$LINENO}: checking for use of our versions of the C++ memory operators" >&5
-$as_echo_n "checking for use of our versions of the C++ memory operators... " >&6; }
- # Check whether --enable-overload-new-delete was given.
-if test "${enable_overload_new_delete+set}" = set; then :
- enableval=$enable_overload_new_delete;
-fi
-
- if test -z "$enable_overload_new_delete" ; then
- enable_overload_new_delete="no"
- fi
- { $as_echo "$as_me:${as_lineno-$LINENO}: result: ${enable_overload_new_delete}" >&5
-$as_echo "${enable_overload_new_delete}" >&6; }
-
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ${CXX} supports -fvisibility-inlines-hidden" >&5
$as_echo_n "checking whether ${CXX} supports -fvisibility-inlines-hidden... " >&6; }
@@ -27337,11 +27322,6 @@ else
MEMORY_POOL_FALSE=
fi
- if test "$enable_overload_new_delete" = "yes"; then
-
-$as_echo "#define U_OVERLOAD_NEW_DELETE 1" >>confdefs.h
-
- fi
else
if false; then
MEMORY_POOL_TRUE=
@@ -27499,6 +27479,7 @@ $as_echo "$ulib_cc_flag" >&6; }
case "${gcc_version}" in
2*)
+ CPPFLAGS="${CPPFLAGS} -O0"
;;
3*)
;;
@@ -27516,7 +27497,7 @@ $as_echo "$ulib_cc_flag" >&6; }
MAYBE_FLAGS="$MAYBE_FLAGS -Wno-unused-result -Wshadow -Wsuggest-attribute=pure -Wsuggest-attribute=noreturn" # -Wsuggest-attribute=const
if test "${enable_gcc_optimized}" = "yes"; then
- MAYBE_FLAGS="$MAYBE_FLAGS -Ofast -flto" ## -ffunction-sections -fdata-sections
+ MAYBE_FLAGS="$MAYBE_FLAGS -Ofast -flto -ftree-partial-pre" ## -ffunction-sections -fdata-sections
fi
;;
esac
@@ -27532,7 +27513,7 @@ $as_echo "$ulib_cc_flag" >&6; }
# -------------------------------------------------------------------------------------
if test "$enable_debug" = "yes"; then
- MAYBE_FLAGS="$MAYBE_FLAGS -Wunsafe-loop-optimizations" ## _FORTIFY_SOURCE enabled by default g++ 4.7.2
+ MAYBE_FLAGS="$MAYBE_FLAGS -Wunsafe-loop-optimizations -fsanitize=address -fsanitize=thread" ## _FORTIFY_SOURCE enabled by default g++ 4.7.2
if test "$USE_LIBSSL" = "yes"; then
MAYBE_FLAGS="$MAYBE_FLAGS -Wno-unused-parameter"
fi
@@ -27551,7 +27532,7 @@ $as_echo "$ulib_cc_flag" >&6; }
# -Wcast-qual
CC_MAYBE_FLAGS="-Werror-implicit-function-declaration -Wstrict-prototypes -Wc++-compat \
- -Wmissing-prototypes -Wnested-externs -Wdeclaration-after-statement -Wold-style-definition"
+ -Wmissing-prototypes -Wnested-externs -Wdeclaration-after-statement -Wold-style-definition -Wsizeof-pointer-memaccess"
CXX_MAYBE_FLAGS="-fno-check-new -fno-exceptions -fno-rtti -Wno-deprecated -Wdelete-non-virtual-dtor"
View
10 configure.in
@@ -881,9 +881,6 @@ AC_SUBST(ULIB)
if test "$enable_memory_pool" = "yes"; then
ulib_memp_msg="enabled"
AM_CONDITIONAL(MEMORY_POOL, true)
- if test "$enable_overload_new_delete" = "yes"; then
- AC_DEFINE(U_OVERLOAD_NEW_DELETE, 1, [enable use of our versions of the memory operators])
- fi
else
AM_CONDITIONAL(MEMORY_POOL, false)
fi
@@ -943,6 +940,7 @@ if test "${ac_cv_c_compiler_gnu}" = "yes"; then
case "${gcc_version}" in
2*)
+ CPPFLAGS="${CPPFLAGS} -O0"
;;
3*)
;;
@@ -960,7 +958,7 @@ if test "${ac_cv_c_compiler_gnu}" = "yes"; then
MAYBE_FLAGS="$MAYBE_FLAGS -Wno-unused-result -Wshadow -Wsuggest-attribute=pure -Wsuggest-attribute=noreturn" # -Wsuggest-attribute=const
if test "${enable_gcc_optimized}" = "yes"; then
- MAYBE_FLAGS="$MAYBE_FLAGS -Ofast -flto" ## -ffunction-sections -fdata-sections
+ MAYBE_FLAGS="$MAYBE_FLAGS -Ofast -flto -ftree-partial-pre" ## -ffunction-sections -fdata-sections
fi
;;
esac
@@ -976,7 +974,7 @@ if test "${ac_cv_c_compiler_gnu}" = "yes"; then
# -------------------------------------------------------------------------------------
if test "$enable_debug" = "yes"; then
- MAYBE_FLAGS="$MAYBE_FLAGS -Wunsafe-loop-optimizations" ## _FORTIFY_SOURCE enabled by default g++ 4.7.2
+ MAYBE_FLAGS="$MAYBE_FLAGS -Wunsafe-loop-optimizations -fsanitize=address -fsanitize=thread" ## _FORTIFY_SOURCE enabled by default g++ 4.7.2
if test "$USE_LIBSSL" = "yes"; then
MAYBE_FLAGS="$MAYBE_FLAGS -Wno-unused-parameter"
fi
@@ -995,7 +993,7 @@ if test "${ac_cv_c_compiler_gnu}" = "yes"; then
# -Wcast-qual
CC_MAYBE_FLAGS="-Werror-implicit-function-declaration -Wstrict-prototypes -Wc++-compat \
- -Wmissing-prototypes -Wnested-externs -Wdeclaration-after-statement -Wold-style-definition"
+ -Wmissing-prototypes -Wnested-externs -Wdeclaration-after-statement -Wold-style-definition -Wsizeof-pointer-memaccess"
CXX_MAYBE_FLAGS="-fno-check-new -fno-exceptions -fno-rtti -Wno-deprecated -Wdelete-non-virtual-dtor"
View
6 examples/IR/ir_web.cpp
@@ -50,6 +50,12 @@
delete query;
delete crono;
delete footer;
+
+ if (UHTTP::data_session)
+ {
+ delete UHTTP::data_session;
+ UHTTP::data_session = 0;
+ }
#endif
}
View
6 examples/IR/ir_web.usp
@@ -48,6 +48,12 @@ delete ir;
delete query;
delete crono;
delete footer;
+
+if (UHTTP::data_session)
+ {
+ delete UHTTP::data_session;
+ UHTTP::data_session = 0;
+ }
#endif
}
-->
View
2  examples/IR/posting.cpp
@@ -231,7 +231,7 @@ U_NO_EXPORT void UPosting::readPosting(UStringRep* word_rep, bool flag)
{
// check if add operation...
- if (word_rep == 0) posting->duplicate(32); // NB: need duplicate string because we need space on string constant..
+ if (word_rep == 0) posting->duplicate(); // NB: need duplicate string because we need space on string constant..
}
U_INTERNAL_ASSERT_EQUALS(UStringExt::isCompress(posting->data()),false)
View
38 examples/PEC_log/PEC_report_anomalie.cpp
@@ -40,13 +40,13 @@ inline void Messaggio::allocDestinatari(int n)
U_CHECK_MEMORY
- vdestinatari_domini = U_MALLOC_N(n+1, char);
- vdestinatari_certificati = U_MALLOC_N(n+1, char);
- vdestinatari_presa_in_carico = U_MALLOC_N(n+1, char);
- vdestinatari_mancata_consegna = U_MALLOC_N(n+1, char);
- vdestinatari_avvenuta_consegna = U_MALLOC_N(n+1, char);
- vdestinatari_rilevazione_virus = U_MALLOC_N(n+1, char);
- vdestinatari_mancata_consegna_virus = U_MALLOC_N(n+1, char);
+ vdestinatari_domini = (char*) malloc(n+1);
+ vdestinatari_certificati = (char*) malloc(n+1);
+ vdestinatari_presa_in_carico = (char*) malloc(n+1);
+ vdestinatari_mancata_consegna = (char*) malloc(n+1);
+ vdestinatari_avvenuta_consegna = (char*) malloc(n+1);
+ vdestinatari_rilevazione_virus = (char*) malloc(n+1);
+ vdestinatari_mancata_consegna_virus = (char*) malloc(n+1);
(void) memset(vdestinatari_presa_in_carico, '0', n);
(void) memset(vdestinatari_mancata_consegna, '0', n);
@@ -90,8 +90,8 @@ Messaggio::Messaggio() : id(*PEC_report::id), mittente(*PEC_report::mittente), i
UString elem;
uint32_t n = vec.size();
- char* vdestcert = U_MALLOC_N(n+1, char);
- char* vdestdomini = U_MALLOC_N(n+1, char);
+ char* vdestcert = (char*) malloc(n+1);
+ char* vdestdomini = (char*) malloc(n+1);
(void) memset(vdestcert, '0', n);
(void) memset(vdestdomini, '0', n);
@@ -121,8 +121,8 @@ Messaggio::Messaggio() : id(*PEC_report::id), mittente(*PEC_report::mittente), i
n = vec.size() + 1;
- U_FREE_N(vdestcert, n, char);
- U_FREE_N(vdestdomini, n, char);
+ free(vdestcert);
+ free(vdestdomini);
U_INTERNAL_DUMP("vdestinatari_certificati = %S", vdestinatari_certificati)
U_INTERNAL_DUMP("vdestinatari_domini = %S", vdestinatari_domini)
@@ -132,15 +132,13 @@ Messaggio::~Messaggio()
{
U_TRACE_UNREGISTER_OBJECT(5, Messaggio)
- int num_destinatari = vdestinatari.size();
-
- U_FREE_N(vdestinatari_domini, num_destinatari+1, char);
- U_FREE_N(vdestinatari_certificati, num_destinatari+1, char);
- U_FREE_N(vdestinatari_presa_in_carico, num_destinatari+1, char);
- U_FREE_N(vdestinatari_mancata_consegna, num_destinatari+1, char);
- U_FREE_N(vdestinatari_avvenuta_consegna, num_destinatari+1, char);
- U_FREE_N(vdestinatari_rilevazione_virus, num_destinatari+1, char);
- U_FREE_N(vdestinatari_mancata_consegna_virus, num_destinatari+1, char);
+ free(vdestinatari_domini);
+ free(vdestinatari_certificati);
+ free(vdestinatari_presa_in_carico);
+ free(vdestinatari_mancata_consegna);
+ free(vdestinatari_avvenuta_consegna);
+ free(vdestinatari_rilevazione_virus);
+ free(vdestinatari_mancata_consegna_virus);
}
bool Messaggio::setRicezione(const UString& elem)
View
6 examples/PEC_log/PEC_report_anomalie1.cpp
@@ -81,7 +81,7 @@ class Application : public PEC_report_anomalie {
{
if (msg->isAnomalia()) PEC_report_anomalie::reportAnomalie(0, msg);
- UStringRep* rep = UStringRep::create((const char*)&(msg->start), sizeof(time_t), 0U);
+ UStringRep* rep = U_NEW(UStringRep((const char*)&(msg->start), sizeof(time_t)));
delete msg;
@@ -233,7 +233,7 @@ class Application : public PEC_report_anomalie {
pvPFpmpb func = Application::MessageToString;
- if (rdb->writeTo(table, (pvPFpvpb)func) == false) U_ERROR("failed to write table on database, exit...");
+ if (rdb->UCDB::writeTo(table, (pvPFpvpb)func) == false) U_ERROR("failed to write table on database, exit...");
rdbname->setEmpty();
# else
@@ -253,7 +253,7 @@ class Application : public PEC_report_anomalie {
pvPFpmpb func = Application::FirstCheckForOldMessage;
- if (rdb->writeTo(table, (pvPFpvpb)func) == false)
+ if (rdb->UCDB::writeTo(table, (pvPFpvpb)func) == false)
{
U_ERROR("write to database file %.*S failed...", U_STRING_TO_TRACE(*rdbname));
}
View
195 examples/WiAuth/wi_auth.cpp
@@ -48,6 +48,7 @@
static UString* historical_log_dir;
static UString* wiauth_card_basedn;
static UString* wiauth_user_basedn;
+ static UString* max_time_no_traffic;
static UString* content_policy_flat;
static UString* content_policy_daily;
static UString* message_page_template;
@@ -138,6 +139,8 @@
{
U_TRACE(5, "WiAuthAccessPoint::clear()")
+ U_CHECK_MEMORY
+
value.clear();
_label.clear();
mac_mask.clear();
@@ -148,6 +151,8 @@
{
U_TRACE(5, "WiAuthAccessPoint::toString()")
+ U_CHECK_MEMORY
+
U_INTERNAL_ASSERT(_label)
value.snprintf(" %u %.*s \"%.*s\" \"%.*s\"",
@@ -163,6 +168,8 @@
{
U_TRACE(5, "WiAuthAccessPoint::fromVector(%p,%u)", &_vec, _index)
+ U_CHECK_MEMORY
+
U_ASSERT_EQUALS(_vec.empty(), false)
noconsume = (_vec[_index].strtol() == 1);
@@ -288,6 +295,8 @@
{
U_TRACE(5, "WiAuthNodog::clear()")
+ U_CHECK_MEMORY
+
value.clear();
_hostname.clear();
access_point.clear();
@@ -297,6 +306,8 @@
{
U_TRACE(5, "WiAuthNodog::callForAllAccessPoint(%p)", func)
+ U_CHECK_MEMORY
+
U_ASSERT(access_point.size())
lindex = U_NOT_FOUND;
@@ -329,6 +340,8 @@
{
U_TRACE(5, "WiAuthNodog::findLabel()")
+ U_CHECK_MEMORY
+
U_INTERNAL_DUMP("label = %.*S", U_STRING_TO_TRACE(*label))
U_INTERNAL_ASSERT(*label)
@@ -360,6 +373,8 @@
{
U_TRACE(5, "WiAuthNodog::findMAC()")
+ U_CHECK_MEMORY
+
U_INTERNAL_DUMP("mac = %.*S", U_STRING_TO_TRACE(*mac))
U_INTERNAL_ASSERT(*mac)
@@ -387,6 +402,8 @@
{
U_TRACE(5, "WiAuthNodog::toString()")
+ U_CHECK_MEMORY
+
buffer->setBuffer(U_CAPACITY);
buffer->snprintf("%u %10ld %10ld %u %.*s [",
@@ -407,6 +424,8 @@
{
U_TRACE(5, "WiAuthNodog::fromString()")
+ U_CHECK_MEMORY
+
U_INTERNAL_ASSERT(value)
istrstream is(value.data(), value.size());
@@ -435,10 +454,14 @@
{
U_TRACE(5, "WiAuthNodog::setDown(%b)", bdown)
+ U_CHECK_MEMORY
+
char* _ptr = value.c_pointer(0);
U_INTERNAL_DUMP("_ptr = %.40s", _ptr)
+ if (u__isspace(_ptr[1]) == false) U_ERROR("DB record nodog not valid: %.40s", _ptr);
+
U_INTERNAL_ASSERT(u__isspace(_ptr[1]))
bool old = (_ptr[0] == '1');
@@ -468,6 +491,8 @@
{
U_TRACE(5, "WiAuthNodog::setValue(%.*S)", U_STRING_TO_TRACE(_address))
+ U_CHECK_MEMORY
+
U_INTERNAL_ASSERT(_address)
value = (*db_ap)[_address];
@@ -488,6 +513,8 @@
{
U_TRACE(5, "WiAuthNodog::setRecord(%p,%d,%b,%b,%b,%p)", pindex, _port, bdown, bnoconsume, bgroup_account, mac_mask)
+ U_CHECK_MEMORY
+
int op = RDB_REPLACE;
bool add_ap = false;
@@ -623,8 +650,16 @@
if (content.empty()) user = U_STRING_FROM_CONSTANT("anonymous");
else
{
- if (vec->split(content) > 2) user = (*vec)[0] + ' ' + (*vec)[1];
- vec->clear();
+ if (vec->split(content) > 2)
+ {
+ user = (*vec)[0];
+
+ user.push_back(' ');
+
+ (void) user.append((*vec)[1]);
+ }
+
+ vec->clear();
}
U_RETURN_STRING(user);
@@ -669,6 +704,8 @@
{
U_TRACE(5, "WiAuthUser::clear()")
+ U_CHECK_MEMORY
+
_ip.clear();
_mac.clear();
_user.clear();
@@ -682,6 +719,8 @@
{
U_TRACE(5, "WiAuthUser::toString()")
+ U_CHECK_MEMORY
+
U_INTERNAL_ASSERT(nodog)
UString x(U_CAPACITY);
@@ -710,6 +749,8 @@
{
U_TRACE(5, "WiAuthUser::setConnected(%b)", bconnected)
+ U_CHECK_MEMORY
+
char c = (bconnected ? '1' : '0');
char* _ptr = value.c_pointer(_ip.size());
@@ -760,6 +801,8 @@
{
U_TRACE(5, "WiAuthUser::resetCounter()")
+ U_CHECK_MEMORY
+
// ip c modified login time_consume traff_consume time_done time_avail traff_done traff_avail x m agent Dr Ur domain
// 172.16.1.172 0 1355492583 0 2572 4378722 0 0 4378722 314572800 0 1 2161242255 0 0 PASS_AUTH
@@ -808,6 +851,8 @@
{
U_TRACE(5, "WiAuthUser::updateCounter(%ld,%ld,%llu)", _logout, _connected, _traffic)
+ U_CHECK_MEMORY
+
U_INTERNAL_ASSERT(connected)
U_INTERNAL_ASSERT(user_exist)
U_INTERNAL_ASSERT_MAJOR(last_modified, 0)
@@ -872,7 +917,7 @@
time_t time_diff = time_done - time_available;
- U_LOGGER("*** updateCounter() UID(%.*s) IP(%.*s) MAC(%.*s) AP(%.*s@%.*s) EXCEED TIME AVAILABLE (%ld sec) ***",
+ U_LOGGER("*** updateCounter() UID(%.*s) IP(%.*s) MAC(%.*s) AP(%.*s@%.*s) EXCEED TIME_AVAILABLE (%ld sec) ***",
U_STRING_TO_TRACE(*uid), U_STRING_TO_TRACE(_ip), U_STRING_TO_TRACE(_mac),
U_STRING_TO_TRACE(*label), U_STRING_TO_TRACE(*address), time_diff);
}
@@ -898,7 +943,7 @@
uint64_t traffic_diff = traffic_done - traffic_available;
- U_LOGGER("*** updateCounter() UID(%.*s) IP(%.*s) MAC(%.*s) AP(%.*s@%.*s) EXCEED TRAFFIC AVAILABLE (%llu bytes) ***",
+ U_LOGGER("*** updateCounter() UID(%.*s) IP(%.*s) MAC(%.*s) AP(%.*s@%.*s) EXCEED TRAFFIC_AVAILABLE (%llu bytes) ***",
U_STRING_TO_TRACE(*uid), U_STRING_TO_TRACE(_ip), U_STRING_TO_TRACE(_mac),
U_STRING_TO_TRACE(*label), U_STRING_TO_TRACE(*address), traffic_diff);
}
@@ -920,14 +965,15 @@
{
if (_traffic == 0)
{
- U_LOGGER("*** INFO PARAM: UID(%.*s) IP(%.*s) MAC(%.*s) AP(%.*s@%.*s) NO TRAFFIC (%ld secs) ***",
- U_STRING_TO_TRACE(*uid), U_STRING_TO_TRACE(_ip), U_STRING_TO_TRACE(_mac),
- U_STRING_TO_TRACE(*label), U_STRING_TO_TRACE(*address), _connected);
+ loadPolicy(_policy);
- if (_connected >= 360 &&
- _policy != *policy_flat)
+ if (_connected > (max_time_no_traffic->strtol() * 60))
{
ask_logout = true;
+
+ U_LOGGER("*** updateCounter() UID(%.*s) IP(%.*s) MAC(%.*s) AP(%.*s@%.*s) EXCEED MAX_TIME_NO_TRAFFIC (%ld secs) ***",
+ U_STRING_TO_TRACE(*uid), U_STRING_TO_TRACE(_ip), U_STRING_TO_TRACE(_mac),
+ U_STRING_TO_TRACE(*label), U_STRING_TO_TRACE(*address), _connected);
}
}
}
@@ -948,6 +994,8 @@
{
U_TRACE(5, "WiAuthUser::fromString()")
+ U_CHECK_MEMORY
+
U_INTERNAL_ASSERT(value)
istrstream is(value.data(), value.size());
@@ -991,6 +1039,8 @@
{
U_TRACE(5, "WiAuthUser::setValue()")
+ U_CHECK_MEMORY
+
U_INTERNAL_ASSERT(*uid)
value = (*db_user)[*uid];
@@ -1008,6 +1058,8 @@
{
U_TRACE(5, "WiAuthUser::getLabelAP()")
+ U_CHECK_MEMORY
+
UString x = nodog_rec->access_point[index_access_point + 1];
U_RETURN_STRING(x);
@@ -1017,6 +1069,8 @@
{
U_TRACE(5, "WiAuthUser::getAP()")
+ U_CHECK_MEMORY
+
UString x(100U), _label = getLabelAP();
x.snprintf("%.*s@%.*s:%u/%.*s", U_STRING_TO_TRACE(_label), U_STRING_TO_TRACE(nodog), nodog_rec->port, U_STRING_TO_TRACE(nodog_rec->_hostname));
@@ -1028,14 +1082,28 @@
{
U_TRACE(5, "WiAuthUser::setChunkValue()")
- _time_chunk->snprintf("%ld", time_available - time_done);
- _traffic_chunk->snprintf("%llu", traffic_available - traffic_done);
+ U_CHECK_MEMORY
+
+ loadPolicy(_policy);
+
+ if (consume)
+ {
+ _time_chunk->snprintf("%ld", time_available - time_done);
+ _traffic_chunk->snprintf("%llu", traffic_available - traffic_done);
+ }
+ else
+ {
+ _time_chunk->snprintf("%.*s", U_STRING_TO_TRACE(*_time_available));
+ _traffic_chunk->snprintf("%.*s", U_STRING_TO_TRACE(*_traffic_available));
+ }
}
void getCounter()
{
U_TRACE(5, "WiAuthUser::getCounter()")
+ U_CHECK_MEMORY
+
_time_chunk->snprintf("%ld", ( time_available - time_done) / 60L);
_traffic_chunk->snprintf("%llu", (traffic_available - traffic_done) / (1024ULL * 1024ULL));
}
@@ -1044,6 +1112,8 @@
{
U_TRACE(5, "WiAuthUser::getConsumed()")
+ U_CHECK_MEMORY
+
_time_consumed->snprintf("%ld", time_consumed / 60L);
_traffic_consumed->snprintf("%llu", traffic_consumed / (1024ULL * 1024ULL));
}
@@ -1052,6 +1122,8 @@
{
U_TRACE(5, "WiAuthUser::setNodogReference()")
+ U_CHECK_MEMORY
+
U_INTERNAL_ASSERT(*uid)
U_INTERNAL_ASSERT(nodog)
@@ -1085,6 +1157,8 @@
{
U_TRACE(5, "WiAuthUser::setRecord()")
+ U_CHECK_MEMORY
+
U_INTERNAL_ASSERT(*uid)
if (nodog_rec->setRecord(&index_access_point) == false ||
@@ -1273,11 +1347,6 @@
num_user = _num_user;
}
- #define VIRTUAL_HOST "auth.t-unwired.com"
- /*
- #define VIRTUAL_HOST "wifi-aaa.comune.fi.it"
- */
-
static void usp_init()
{
U_TRACE(5, "::usp_init()")
@@ -1365,6 +1434,9 @@
client_address = U_NEW(UString);
allowed_web_hosts = U_NEW(UString);
+ user_UploadRate = U_NEW(UString);
+ user_DownloadRate = U_NEW(UString);
+
_time_chunk = U_NEW(UString(20U));
_time_consumed = U_NEW(UString(20U));
_time_available = U_NEW(UString);
@@ -1372,15 +1444,17 @@
_traffic_consumed = U_NEW(UString(20U));
_traffic_available = U_NEW(UString);
- user_UploadRate = U_NEW(UString);
- user_DownloadRate = U_NEW(UString);
+ environment = U_NEW(UString(*USSIPlugIn::environment));
+ virtual_name = U_NEW(UString(UStringExt::getEnvironmentVar(U_CONSTANT_TO_PARAM("VIRTUAL_NAME"), environment)));
- environment = U_NEW(UString(*USSIPlugIn::environment + "VIRTUAL_HOST=" + VIRTUAL_HOST));
+ // NB: we can assume that we not serve the admin user (wich is served by bash script)...
+
+ (void) environment->append(U_CONSTANT_TO_PARAM("VIRTUAL_HOST="));
+ (void) environment->append(*virtual_name);
dir_reg = U_NEW(UString(UStringExt::getEnvironmentVar(U_CONSTANT_TO_PARAM("DIR_REG"), environment)));
dir_root = U_NEW(UString(UStringExt::getEnvironmentVar(U_CONSTANT_TO_PARAM("DIR_ROOT"), environment)));
dir_policy = U_NEW(UString(UStringExt::getEnvironmentVar(U_CONSTANT_TO_PARAM("DIR_POLICY"), environment)));
- virtual_name = U_NEW(UString(UStringExt::getEnvironmentVar(U_CONSTANT_TO_PARAM("VIRTUAL_NAME"), environment)));
title_default = U_NEW(UString(UStringExt::getEnvironmentVar(U_CONSTANT_TO_PARAM("TITLE_DEFAULT"), environment)));
historical_log_dir = U_NEW(UString(UStringExt::getEnvironmentVar(U_CONSTANT_TO_PARAM("HISTORICAL_LOG_DIR"), environment)));
@@ -1407,16 +1481,21 @@
vec->clear();
}
- cache = U_NEW(UCache);
- content = U_STRING_FROM_CONSTANT("$DIR_ROOT/etc/" VIRTUAL_HOST "/cache.tmpl");
+ cache = U_NEW(UCache);
+
+ UString x(U_CAPACITY);
- (void) cache->open(content, U_STRING_FROM_CONSTANT("$DIR_TEMPLATE"), environment);
+ x.snprintf("$DIR_ROOT/etc/%s/cache.tmpl", virtual_name->data());
+
+ (void) cache->open(x, U_STRING_FROM_CONSTANT("$DIR_TEMPLATE"), environment);
message_page_template = U_NEW(UString(cache->getContent(U_CONSTANT_TO_PARAM("message_page.tmpl"))));
status_nodog_template = U_NEW(UString(cache->getContent(U_CONSTANT_TO_PARAM("status_nodog_body.tmpl"))));
status_network_template = U_NEW(UString(cache->getContent(U_CONSTANT_TO_PARAM("status_network_body.tmpl"))));
- content = UFile::contentOf("$DIR_ROOT/etc/" VIRTUAL_HOST "/script.conf", O_RDONLY, false, environment);
+ x.snprintf("$DIR_ROOT/etc/%s/script.conf", virtual_name->data());
+
+ content = UFile::contentOf(x.data(), O_RDONLY, false, environment);
table = U_NEW(UHashMap<UString>);
@@ -1436,13 +1515,11 @@
wallet_url = U_NEW(UString(UStringExt::expandEnvironmentVar((*table)["WALLET_URL"], environment)));
registrazione_url = U_NEW(UString(UStringExt::expandEnvironmentVar((*table)["REGISTRAZIONE_URL"], environment)));
- UString x(U_CAPACITY);
-
- x.snprintf("$DIR_WEB/" VIRTUAL_HOST "%s/default", url_banner_ap->data());
+ x.snprintf("$DIR_WEB/%s/%s/default", virtual_name->data(), url_banner_ap->data());
url_banner_ap_default = U_NEW(UFile(x, environment));
- x.snprintf("$DIR_WEB/" VIRTUAL_HOST "%s/default", url_banner_comune->data());
+ x.snprintf("$DIR_WEB/%s/%s/default", virtual_name->data(), url_banner_comune->data());
url_banner_comune_default = U_NEW(UFile(x, environment));
@@ -1465,8 +1542,6 @@
client = U_NEW(UHttpClient<UTCPSocket>(0));
- client->setSaveHttpInfo(true);
-
if (UServer_Base::isLog() &&
client->UClient_Base::isLogSharedWithServer() == false)
{
@@ -1487,6 +1562,8 @@
policy_flat = U_NEW(U_STRING_FROM_CONSTANT("FLAT"));
policy_daily = U_NEW(U_STRING_FROM_CONSTANT("DAILY"));
+ max_time_no_traffic = U_NEW(UString);
+
UString pathname(U_CAPACITY);
pathname.snprintf("%.*s/FLAT", U_STRING_TO_TRACE(*dir_policy));
@@ -1545,6 +1622,7 @@
delete wiauth_card_basedn;
delete wiauth_user_basedn;
delete historical_log_dir;
+ delete max_time_no_traffic;
delete content_policy_flat;
delete content_policy_daily;
delete message_page_template;
@@ -1907,7 +1985,7 @@
U_STRING_TO_TRACE(user_rec->_policy),
ptr1, ptr2,
ptr3, ptr4,
- VIRTUAL_HOST,
+ virtual_name->data(),
U_STRING_TO_TRACE(_label), U_STRING_TO_TRACE(nodog_rec->_hostname),
U_STRING_TO_TRACE(user_rec->nodog), nodog_rec->port, U_STRING_TO_TRACE(x));
@@ -1938,7 +2016,7 @@
riga.snprintf(status_nodog_template->data(),
size, ptr,
- VIRTUAL_HOST, size, ptr, U_STRING_TO_TRACE(nodog_rec->_hostname), U_STRING_TO_TRACE(*address), nodog_rec->port,
+ virtual_name->data(), size, ptr, U_STRING_TO_TRACE(nodog_rec->_hostname), U_STRING_TO_TRACE(*address), nodog_rec->port,
U_STRING_TO_TRACE(*address),
U_STRING_TO_TRACE(nodog_rec->_hostname),
ptr1, ptr2,
@@ -1947,7 +2025,7 @@
ptr3, ptr4,
U_STRING_TO_TRACE(ap_rec->mac_mask),
U_STRING_TO_TRACE(ap_rec->group_account),
- VIRTUAL_HOST, size, ptr, U_STRING_TO_TRACE(nodog_rec->_hostname), U_STRING_TO_TRACE(*address), nodog_rec->port);
+ virtual_name->data(), size, ptr, U_STRING_TO_TRACE(nodog_rec->_hostname), U_STRING_TO_TRACE(*address), nodog_rec->port);
(void) output->append(riga);
@@ -1985,7 +2063,7 @@
UString result;
if (client->connectServer(url) &&
- client->sendRequest(result))
+ client->sendRequest(0,0))
{
result = client->getContent();
@@ -2091,7 +2169,7 @@
{
U_ASSERT(url_banner_ap_default->dir())
- x.snprintf("$DIR_WEB/" VIRTUAL_HOST "%s/%s", url_banner_ap->data(), ap_ref->data());
+ x.snprintf("$DIR_WEB/%s/%s/%s", virtual_name->data(), url_banner_ap->data(), ap_ref->data());
banner = UStringExt::expandPath(x, environment);
_ptr = banner.data();
@@ -2111,7 +2189,7 @@
{
U_ASSERT(url_banner_comune_default->dir())
- x.snprintf("$DIR_WEB/" VIRTUAL_HOST "%s/%s", url_banner_comune->data(), ap_ref->data());
+ x.snprintf("$DIR_WEB/%s/%s/%s", virtual_name->data(), url_banner_comune->data(), ap_ref->data());
banner = UStringExt::expandPath(x, environment);
_ptr = banner.data();
@@ -2484,8 +2562,9 @@
U_INTERNAL_ASSERT(name)
- const char* key_time = 0;
- const char* key_traffic = 0;
+ const char* key_time = 0;
+ const char* key_traffic = 0;
+ const char* key_time_no_traffic = 0;
if (table->empty() == false)
{
@@ -2507,18 +2586,20 @@
content = UFile::contentOf(pathname);
}
- if (UFileConfig::loadProperties(*table, content.data(), content.end()))
+ if (content.empty() == false &&
+ UFileConfig::loadProperties(*table, content.data(), content.end()))
{
- key_time = "MAX_TIME";
- key_traffic = "MAX_TRAFFIC";
+ key_time = "MAX_TIME";
+ key_traffic = "MAX_TRAFFIC";
+ key_time_no_traffic = "MAX_TIME_NO_TRAFFIC";
}
}
- if (key_time &&
- key_traffic)
+ if (key_time)
{
- *_time_available = (*table)[key_time];
- *_traffic_available = (*table)[key_traffic];
+ *_time_available = (*table)[key_time];
+ *_traffic_available = (*table)[key_traffic];
+ if (key_time_no_traffic) *max_time_no_traffic = (*table)[key_time_no_traffic];
}
table->clear();
@@ -3026,35 +3107,31 @@
// redirect back to the gateway appending a signed ticket that will signal NoDog to unlock the firewall...
- if (user_rec->consume) user_rec->setChunkValue();
- else
- {
- loadPolicy(*policy_flat);
-
- _time_chunk->snprintf("%.*s", U_STRING_TO_TRACE(*_time_available));
- _traffic_chunk->snprintf("%.*s", U_STRING_TO_TRACE(*_traffic_available));
- }
+ user_rec->setChunkValue();
UString signed_data = UDES3::signData("\n"
// "Action Permit\n"
// "Mode Login\n"
- "Redirect http://" VIRTUAL_HOST "/postlogin?%.*s\n"
"Mac %.*s\n"
"Timeout %.*s\n"
"Traffic %.*s\n"
"Token %.*s\n"
"User %.*s\n"
"Policy %.*s\n"
+ "NoTraffic %.*s\n"
+ "UserUploadRate %.*s\n"
"UserDownloadRate %.*s\n"
- "UserUploadRate %.*s\n",
- U_HTTP_QUERY_TO_TRACE,
+ "Redirect http://%s/postlogin?%.*s\n",
U_STRING_TO_TRACE(*mac),
U_STRING_TO_TRACE(*_time_chunk),
U_STRING_TO_TRACE(*_traffic_chunk),
U_STRING_TO_TRACE(*token),
U_STRING_TO_TRACE(*uid),
U_STRING_TO_TRACE(user_rec->_policy),
- U_STRING_TO_TRACE(*user_DownloadRate), U_STRING_TO_TRACE(*user_UploadRate));
+ U_STRING_TO_TRACE(*max_time_no_traffic),
+ U_STRING_TO_TRACE(*user_DownloadRate),
+ U_STRING_TO_TRACE(*user_UploadRate),
+ virtual_name->data(), U_HTTP_QUERY_TO_TRACE);
USSIPlugIn::setAlternativeRedirect("http://%.*s/ticket?ticket=%.*s", U_STRING_TO_TRACE(*gateway), U_STRING_TO_TRACE(signed_data));
#endif
@@ -3380,7 +3457,7 @@
callForAllAPSorted(setStatusNodog, 0);
- _buffer.snprintf(_template.data(), num_ap, VIRTUAL_HOST);
+ _buffer.snprintf(_template.data(), num_ap, virtual_name->data());
(void) output->insert(0, _buffer);
@@ -3547,7 +3624,7 @@
(void) UFile::writeTo(dest, *address);
- USSIPlugIn::setAlternativeRedirect("http://" VIRTUAL_HOST "/cgi-bin/webif/status-basic.sh?cat=Status", 0);
+ USSIPlugIn::setAlternativeRedirect("http://%s/cgi-bin/webif/status-basic.sh?cat=Status", virtual_name->data());
}
else
{
View
195 examples/WiAuth/wi_auth.usp
@@ -45,6 +45,7 @@ static UString* allowed_web_hosts;
static UString* historical_log_dir;
static UString* wiauth_card_basedn;
static UString* wiauth_user_basedn;
+static UString* max_time_no_traffic;
static UString* content_policy_flat;
static UString* content_policy_daily;
static UString* message_page_template;
@@ -135,6 +136,8 @@ public:
{
U_TRACE(5, "WiAuthAccessPoint::clear()")
+ U_CHECK_MEMORY
+
value.clear();
_label.clear();
mac_mask.clear();
@@ -145,6 +148,8 @@ public:
{
U_TRACE(5, "WiAuthAccessPoint::toString()")
+ U_CHECK_MEMORY
+
U_INTERNAL_ASSERT(_label)
value.snprintf(" %u %.*s \"%.*s\" \"%.*s\"",
@@ -160,6 +165,8 @@ public:
{
U_TRACE(5, "WiAuthAccessPoint::fromVector(%p,%u)", &_vec, _index)
+ U_CHECK_MEMORY
+
U_ASSERT_EQUALS(_vec.empty(), false)
noconsume = (_vec[_index].strtol() == 1);
@@ -285,6 +292,8 @@ speed attribute must be a non-negative real number.
{
U_TRACE(5, "WiAuthNodog::clear()")
+ U_CHECK_MEMORY
+
value.clear();
_hostname.clear();
access_point.clear();
@@ -294,6 +303,8 @@ speed attribute must be a non-negative real number.
{
U_TRACE(5, "WiAuthNodog::callForAllAccessPoint(%p)", func)
+ U_CHECK_MEMORY
+
U_ASSERT(access_point.size())
lindex = U_NOT_FOUND;
@@ -326,6 +337,8 @@ speed attribute must be a non-negative real number.
{
U_TRACE(5, "WiAuthNodog::findLabel()")
+ U_CHECK_MEMORY
+
U_INTERNAL_DUMP("label = %.*S", U_STRING_TO_TRACE(*label))
U_INTERNAL_ASSERT(*label)
@@ -357,6 +370,8 @@ speed attribute must be a non-negative real number.
{
U_TRACE(5, "WiAuthNodog::findMAC()")
+ U_CHECK_MEMORY
+
U_INTERNAL_DUMP("mac = %.*S", U_STRING_TO_TRACE(*mac))
U_INTERNAL_ASSERT(*mac)
@@ -384,6 +399,8 @@ speed attribute must be a non-negative real number.
{
U_TRACE(5, "WiAuthNodog::toString()")
+ U_CHECK_MEMORY
+
buffer->setBuffer(U_CAPACITY);
buffer->snprintf("%u %10ld %10ld %u %.*s [",
@@ -404,6 +421,8 @@ speed attribute must be a non-negative real number.
{
U_TRACE(5, "WiAuthNodog::fromString()")
+ U_CHECK_MEMORY
+
U_INTERNAL_ASSERT(value)
istrstream is(value.data(), value.size());
@@ -432,10 +451,14 @@ speed attribute must be a non-negative real number.
{
U_TRACE(5, "WiAuthNodog::setDown(%b)", bdown)
+ U_CHECK_MEMORY
+
char* _ptr = value.c_pointer(0);
U_INTERNAL_DUMP("_ptr = %.40s", _ptr)
+ if (u__isspace(_ptr[1]) == false) U_ERROR("DB record nodog not valid: %.40s", _ptr);
+
U_INTERNAL_ASSERT(u__isspace(_ptr[1]))
bool old = (_ptr[0] == '1');
@@ -465,6 +488,8 @@ speed attribute must be a non-negative real number.
{
U_TRACE(5, "WiAuthNodog::setValue(%.*S)", U_STRING_TO_TRACE(_address))
+ U_CHECK_MEMORY
+
U_INTERNAL_ASSERT(_address)
value = (*db_ap)[_address];
@@ -485,6 +510,8 @@ speed attribute must be a non-negative real number.
{
U_TRACE(5, "WiAuthNodog::setRecord(%p,%d,%b,%b,%b,%p)", pindex, _port, bdown, bnoconsume, bgroup_account, mac_mask)
+ U_CHECK_MEMORY
+
int op = RDB_REPLACE;
bool add_ap = false;
@@ -620,8 +647,16 @@ static UString get_UserName()
if (content.empty()) user = U_STRING_FROM_CONSTANT("anonymous");
else
{
- if (vec->split(content) > 2) user = (*vec)[0] + ' ' + (*vec)[1];
- vec->clear();
+ if (vec->split(content) > 2)
+ {
+ user = (*vec)[0];
+
+ user.push_back(' ');
+
+ (void) user.append((*vec)[1]);
+ }
+
+ vec->clear();
}
U_RETURN_STRING(user);
@@ -666,6 +701,8 @@ public:
{
U_TRACE(5, "WiAuthUser::clear()")
+ U_CHECK_MEMORY
+
_ip.clear();
_mac.clear();
_user.clear();
@@ -679,6 +716,8 @@ public:
{
U_TRACE(5, "WiAuthUser::toString()")
+ U_CHECK_MEMORY
+
U_INTERNAL_ASSERT(nodog)
UString x(U_CAPACITY);
@@ -707,6 +746,8 @@ public:
{
U_TRACE(5, "WiAuthUser::setConnected(%b)", bconnected)
+ U_CHECK_MEMORY
+
char c = (bconnected ? '1' : '0');
char* _ptr = value.c_pointer(_ip.size());
@@ -757,6 +798,8 @@ public:
{
U_TRACE(5, "WiAuthUser::resetCounter()")
+ U_CHECK_MEMORY
+
// ip c modified login time_consume traff_consume time_done time_avail traff_done traff_avail x m agent Dr Ur domain
// 172.16.1.172 0 1355492583 0 2572 4378722 0 0 4378722 314572800 0 1 2161242255 0 0 PASS_AUTH
@@ -805,6 +848,8 @@ public:
{
U_TRACE(5, "WiAuthUser::updateCounter(%ld,%ld,%llu)", _logout, _connected, _traffic)
+ U_CHECK_MEMORY
+
U_INTERNAL_ASSERT(connected)
U_INTERNAL_ASSERT(user_exist)
U_INTERNAL_ASSERT_MAJOR(last_modified, 0)
@@ -869,7 +914,7 @@ public:
time_t time_diff = time_done - time_available;
- U_LOGGER("*** updateCounter() UID(%.*s) IP(%.*s) MAC(%.*s) AP(%.*s@%.*s) EXCEED TIME AVAILABLE (%ld sec) ***",
+ U_LOGGER("*** updateCounter() UID(%.*s) IP(%.*s) MAC(%.*s) AP(%.*s@%.*s) EXCEED TIME_AVAILABLE (%ld sec) ***",
U_STRING_TO_TRACE(*uid), U_STRING_TO_TRACE(_ip), U_STRING_TO_TRACE(_mac),
U_STRING_TO_TRACE(*label), U_STRING_TO_TRACE(*address), time_diff);
}
@@ -895,7 +940,7 @@ public:
uint64_t traffic_diff = traffic_done - traffic_available;
- U_LOGGER("*** updateCounter() UID(%.*s) IP(%.*s) MAC(%.*s) AP(%.*s@%.*s) EXCEED TRAFFIC AVAILABLE (%llu bytes) ***",
+ U_LOGGER("*** updateCounter() UID(%.*s) IP(%.*s) MAC(%.*s) AP(%.*s@%.*s) EXCEED TRAFFIC_AVAILABLE (%llu bytes) ***",
U_STRING_TO_TRACE(*uid), U_STRING_TO_TRACE(_ip), U_STRING_TO_TRACE(_mac),
U_STRING_TO_TRACE(*label), U_STRING_TO_TRACE(*address), traffic_diff);
}
@@ -917,14 +962,15 @@ public:
{
if (_traffic == 0)
{
- U_LOGGER("*** INFO PARAM: UID(%.*s) IP(%.*s) MAC(%.*s) AP(%.*s@%.*s) NO TRAFFIC (%ld secs) ***",
- U_STRING_TO_TRACE(*uid), U_STRING_TO_TRACE(_ip), U_STRING_TO_TRACE(_mac),
- U_STRING_TO_TRACE(*label), U_STRING_TO_TRACE(*address), _connected);
+ loadPolicy(_policy);
- if (_connected >= 360 &&
- _policy != *policy_flat)
+ if (_connected > (max_time_no_traffic->strtol() * 60))
{
ask_logout = true;
+
+ U_LOGGER("*** updateCounter() UID(%.*s) IP(%.*s) MAC(%.*s) AP(%.*s@%.*s) EXCEED MAX_TIME_NO_TRAFFIC (%ld secs) ***",
+ U_STRING_TO_TRACE(*uid), U_STRING_TO_TRACE(_ip), U_STRING_TO_TRACE(_mac),
+ U_STRING_TO_TRACE(*label), U_STRING_TO_TRACE(*address), _connected);
}
}
}
@@ -945,6 +991,8 @@ public:
{
U_TRACE(5, "WiAuthUser::fromString()")
+ U_CHECK_MEMORY
+
U_INTERNAL_ASSERT(value)
istrstream is(value.data(), value.size());
@@ -988,6 +1036,8 @@ public:
{
U_TRACE(5, "WiAuthUser::setValue()")
+ U_CHECK_MEMORY
+
U_INTERNAL_ASSERT(*uid)
value = (*db_user)[*uid];
@@ -1005,6 +1055,8 @@ public:
{
U_TRACE(5, "WiAuthUser::getLabelAP()")
+ U_CHECK_MEMORY
+
UString x = nodog_rec->access_point[index_access_point + 1];
U_RETURN_STRING(x);
@@ -1014,6 +1066,8 @@ public:
{
U_TRACE(5, "WiAuthUser::getAP()")
+ U_CHECK_MEMORY
+
UString x(100U), _label = getLabelAP();
x.snprintf("%.*s@%.*s:%u/%.*s", U_STRING_TO_TRACE(_label), U_STRING_TO_TRACE(nodog), nodog_rec->port, U_STRING_TO_TRACE(nodog_rec->_hostname));
@@ -1025,14 +1079,28 @@ public:
{
U_TRACE(5, "WiAuthUser::setChunkValue()")
- _time_chunk->snprintf("%ld", time_available - time_done);
- _traffic_chunk->snprintf("%llu", traffic_available - traffic_done);
+ U_CHECK_MEMORY
+
+ loadPolicy(_policy);
+
+ if (consume)
+ {
+ _time_chunk->snprintf("%ld", time_available - time_done);
+ _traffic_chunk->snprintf("%llu", traffic_available - traffic_done);
+ }
+ else
+ {
+ _time_chunk->snprintf("%.*s", U_STRING_TO_TRACE(*_time_available));
+ _traffic_chunk->snprintf("%.*s", U_STRING_TO_TRACE(*_traffic_available));
+ }
}
void getCounter()
{
U_TRACE(5, "WiAuthUser::getCounter()")
+ U_CHECK_MEMORY
+
_time_chunk->snprintf("%ld", ( time_available - time_done) / 60L);
_traffic_chunk->snprintf("%llu", (traffic_available - traffic_done) / (1024ULL * 1024ULL));
}
@@ -1041,6 +1109,8 @@ public:
{
U_TRACE(5, "WiAuthUser::getConsumed()")
+ U_CHECK_MEMORY
+
_time_consumed->snprintf("%ld", time_consumed / 60L);
_traffic_consumed->snprintf("%llu", traffic_consumed / (1024ULL * 1024ULL));
}
@@ -1049,6 +1119,8 @@ public:
{
U_TRACE(5, "WiAuthUser::setNodogReference()")
+ U_CHECK_MEMORY
+
U_INTERNAL_ASSERT(*uid)
U_INTERNAL_ASSERT(nodog)
@@ -1082,6 +1154,8 @@ public:
{
U_TRACE(5, "WiAuthUser::setRecord()")
+ U_CHECK_MEMORY
+
U_INTERNAL_ASSERT(*uid)
if (nodog_rec->setRecord(&index_access_point) == false ||
@@ -1270,11 +1344,6 @@ static void callForAllUsers(vPFprpr function)
num_user = _num_user;
}
-#define VIRTUAL_HOST "auth.t-unwired.com"
-/*
-#define VIRTUAL_HOST "wifi-aaa.comune.fi.it"
-*/
-
static void usp_init()
{
U_TRACE(5, "::usp_init()")
@@ -1362,6 +1431,9 @@ static void usp_init()
client_address = U_NEW(UString);
allowed_web_hosts = U_NEW(UString);
+ user_UploadRate = U_NEW(UString);
+ user_DownloadRate = U_NEW(UString);
+
_time_chunk = U_NEW(UString(20U));
_time_consumed = U_NEW(UString(20U));
_time_available = U_NEW(UString);
@@ -1369,15 +1441,17 @@ static void usp_init()
_traffic_consumed = U_NEW(UString(20U));
_traffic_available = U_NEW(UString);
- user_UploadRate = U_NEW(UString);
- user_DownloadRate = U_NEW(UString);
+ environment = U_NEW(UString(*USSIPlugIn::environment));
+ virtual_name = U_NEW(UString(UStringExt::getEnvironmentVar(U_CONSTANT_TO_PARAM("VIRTUAL_NAME"), environment)));
- environment = U_NEW(UString(*USSIPlugIn::environment + "VIRTUAL_HOST=" + VIRTUAL_HOST));
+ // NB: we can assume that we not serve the admin user (wich is served by bash script)...
+
+ (void) environment->append(U_CONSTANT_TO_PARAM("VIRTUAL_HOST="));
+ (void) environment->append(*virtual_name);
dir_reg = U_NEW(UString(UStringExt::getEnvironmentVar(U_CONSTANT_TO_PARAM("DIR_REG"), environment)));
dir_root = U_NEW(UString(UStringExt::getEnvironmentVar(U_CONSTANT_TO_PARAM("DIR_ROOT"), environment)));
dir_policy = U_NEW(UString(UStringExt::getEnvironmentVar(U_CONSTANT_TO_PARAM("DIR_POLICY"), environment)));
- virtual_name = U_NEW(UString(UStringExt::getEnvironmentVar(U_CONSTANT_TO_PARAM("VIRTUAL_NAME"), environment)));
title_default = U_NEW(UString(UStringExt::getEnvironmentVar(U_CONSTANT_TO_PARAM("TITLE_DEFAULT"), environment)));
historical_log_dir = U_NEW(UString(UStringExt::getEnvironmentVar(U_CONSTANT_TO_PARAM("HISTORICAL_LOG_DIR"), environment)));
@@ -1404,16 +1478,21 @@ static void usp_init()
vec->clear();
}
- cache = U_NEW(UCache);
- content = U_STRING_FROM_CONSTANT("$DIR_ROOT/etc/" VIRTUAL_HOST "/cache.tmpl");
+ cache = U_NEW(UCache);
+
+ UString x(U_CAPACITY);
- (void) cache->open(content, U_STRING_FROM_CONSTANT("$DIR_TEMPLATE"), environment);
+ x.snprintf("$DIR_ROOT/etc/%s/cache.tmpl", virtual_name->data());
+
+ (void) cache->open(x, U_STRING_FROM_CONSTANT("$DIR_TEMPLATE"), environment);
message_page_template = U_NEW(UString(cache->getContent(U_CONSTANT_TO_PARAM("message_page.tmpl"))));
status_nodog_template = U_NEW(UString(cache->getContent(U_CONSTANT_TO_PARAM("status_nodog_body.tmpl"))));
status_network_template = U_NEW(UString(cache->getContent(U_CONSTANT_TO_PARAM("status_network_body.tmpl"))));
- content = UFile::contentOf("$DIR_ROOT/etc/" VIRTUAL_HOST "/script.conf", O_RDONLY, false, environment);
+ x.snprintf("$DIR_ROOT/etc/%s/script.conf", virtual_name->data());
+
+ content = UFile::contentOf(x.data(), O_RDONLY, false, environment);
table = U_NEW(UHashMap<UString>);
@@ -1433,13 +1512,11 @@ static void usp_init()
wallet_url = U_NEW(UString(UStringExt::expandEnvironmentVar((*table)["WALLET_URL"], environment)));
registrazione_url = U_NEW(UString(UStringExt::expandEnvironmentVar((*table)["REGISTRAZIONE_URL"], environment)));
- UString x(U_CAPACITY);
-
- x.snprintf("$DIR_WEB/" VIRTUAL_HOST "%s/default", url_banner_ap->data());
+ x.snprintf("$DIR_WEB/%s/%s/default", virtual_name->data(), url_banner_ap->data());
url_banner_ap_default = U_NEW(UFile(x, environment));
- x.snprintf("$DIR_WEB/" VIRTUAL_HOST "%s/default", url_banner_comune->data());
+ x.snprintf("$DIR_WEB/%s/%s/default", virtual_name->data(), url_banner_comune->data());
url_banner_comune_default = U_NEW(UFile(x, environment));
@@ -1462,8 +1539,6 @@ static void usp_init()
client = U_NEW(UHttpClient<UTCPSocket>(0));
- client->setSaveHttpInfo(true);
-
if (UServer_Base::isLog() &&
client->UClient_Base::isLogSharedWithServer() == false)
{
@@ -1484,6 +1559,8 @@ static void usp_init()
policy_flat = U_NEW(U_STRING_FROM_CONSTANT("FLAT"));
policy_daily = U_NEW(U_STRING_FROM_CONSTANT("DAILY"));
+ max_time_no_traffic = U_NEW(UString);
+
UString pathname(U_CAPACITY);
pathname.snprintf("%.*s/FLAT", U_STRING_TO_TRACE(*dir_policy));
@@ -1542,6 +1619,7 @@ static void usp_end()
delete wiauth_card_basedn;
delete wiauth_user_basedn;
delete historical_log_dir;
+ delete max_time_no_traffic;
delete content_policy_flat;
delete content_policy_daily;
delete message_page_template;
@@ -1904,7 +1982,7 @@ static void setStatusUser(UStringRep* key, UStringRep* data)
U_STRING_TO_TRACE(user_rec->_policy),
ptr1, ptr2,
ptr3, ptr4,
- VIRTUAL_HOST,
+ virtual_name->data(),
U_STRING_TO_TRACE(_label), U_STRING_TO_TRACE(nodog_rec->_hostname),
U_STRING_TO_TRACE(user_rec->nodog), nodog_rec->port, U_STRING_TO_TRACE(x));
@@ -1935,7 +2013,7 @@ static bool writeStatusAccessPoint()
riga.snprintf(status_nodog_template->data(),
size, ptr,
- VIRTUAL_HOST, size, ptr, U_STRING_TO_TRACE(nodog_rec->_hostname), U_STRING_TO_TRACE(*address), nodog_rec->port,
+ virtual_name->data(), size, ptr, U_STRING_TO_TRACE(nodog_rec->_hostname), U_STRING_TO_TRACE(*address), nodog_rec->port,
U_STRING_TO_TRACE(*address),
U_STRING_TO_TRACE(nodog_rec->_hostname),
ptr1, ptr2,
@@ -1944,7 +2022,7 @@ static bool writeStatusAccessPoint()
ptr3, ptr4,
U_STRING_TO_TRACE(ap_rec->mac_mask),
U_STRING_TO_TRACE(ap_rec->group_account),
- VIRTUAL_HOST, size, ptr, U_STRING_TO_TRACE(nodog_rec->_hostname), U_STRING_TO_TRACE(*address), nodog_rec->port);
+ virtual_name->data(), size, ptr, U_STRING_TO_TRACE(nodog_rec->_hostname), U_STRING_TO_TRACE(*address), nodog_rec->port);
(void) output->append(riga);
@@ -1982,7 +2060,7 @@ static UString sendRequestToNodog(const UString& url)
UString result;
if (client->connectServer(url) &&
- client->sendRequest(result))
+ client->sendRequest(0,0))
{
result = client->getContent();
@@ -2088,7 +2166,7 @@ static void setAccessPointReference()
{
U_ASSERT(url_banner_ap_default->dir())
- x.snprintf("$DIR_WEB/" VIRTUAL_HOST "%s/%s", url_banner_ap->data(), ap_ref->data());
+ x.snprintf("$DIR_WEB/%s/%s/%s", virtual_name->data(), url_banner_ap->data(), ap_ref->data());
banner = UStringExt::expandPath(x, environment);
_ptr = banner.data();
@@ -2108,7 +2186,7 @@ static void setAccessPointReference()
{
U_ASSERT(url_banner_comune_default->dir())
- x.snprintf("$DIR_WEB/" VIRTUAL_HOST "%s/%s", url_banner_comune->data(), ap_ref->data());
+ x.snprintf("$DIR_WEB/%s/%s/%s", virtual_name->data(), url_banner_comune->data(), ap_ref->data());
banner = UStringExt::expandPath(x, environment);
_ptr = banner.data();
@@ -2481,8 +2559,9 @@ static void loadPolicy(const UString& name)
U_INTERNAL_ASSERT(name)
- const char* key_time = 0;
- const char* key_traffic = 0;
+ const char* key_time = 0;
+ const char* key_traffic = 0;
+ const char* key_time_no_traffic = 0;
if (table->empty() == false)
{
@@ -2504,18 +2583,20 @@ static void loadPolicy(const UString& name)
content = UFile::contentOf(pathname);
}
- if (UFileConfig::loadProperties(*table, content.data(), content.end()))
+ if (content.empty() == false &&
+ UFileConfig::loadProperties(*table, content.data(), content.end()))
{
- key_time = "MAX_TIME";
- key_traffic = "MAX_TRAFFIC";
+ key_time = "MAX_TIME";
+ key_traffic = "MAX_TRAFFIC";
+ key_time_no_traffic = "MAX_TIME_NO_TRAFFIC";
}
}
- if (key_time &&
- key_traffic)
+ if (key_time)
{
- *_time_available = (*table)[key_time];
- *_traffic_available = (*table)[key_traffic];
+ *_time_available = (*table)[key_time];
+ *_traffic_available = (*table)[key_traffic];
+ if (key_time_no_traffic) *max_time_no_traffic = (*table)[key_time_no_traffic];
}
table->clear();
@@ -3023,35 +3104,31 @@ error:
// redirect back to the gateway appending a signed ticket that will signal NoDog to unlock the firewall...
- if (user_rec->consume) user_rec->setChunkValue();
- else
- {
- loadPolicy(*policy_flat);
-
- _time_chunk->snprintf("%.*s", U_STRING_TO_TRACE(*_time_available));
- _traffic_chunk->snprintf("%.*s", U_STRING_TO_TRACE(*_traffic_available));
- }
+ user_rec->setChunkValue();
UString signed_data = UDES3::signData("\n"
// "Action Permit\n"
// "Mode Login\n"
- "Redirect http://" VIRTUAL_HOST "/postlogin?%.*s\n"
"Mac %.*s\n"
"Timeout %.*s\n"
"Traffic %.*s\n"
"Token %.*s\n"
"User %.*s\n"
"Policy %.*s\n"
+ "NoTraffic %.*s\n"
+ "UserUploadRate %.*s\n"
"UserDownloadRate %.*s\n"
- "UserUploadRate %.*s\n",
- U_HTTP_QUERY_TO_TRACE,
+ "Redirect http://%s/postlogin?%.*s\n",
U_STRING_TO_TRACE(*mac),
U_STRING_TO_TRACE(*_time_chunk),
U_STRING_TO_TRACE(*_traffic_chunk),
U_STRING_TO_TRACE(*token),
U_STRING_TO_TRACE(*uid),
U_STRING_TO_TRACE(user_rec->_policy),
- U_STRING_TO_TRACE(*user_DownloadRate), U_STRING_TO_TRACE(*user_UploadRate));
+ U_STRING_TO_TRACE(*max_time_no_traffic),
+ U_STRING_TO_TRACE(*user_DownloadRate),
+ U_STRING_TO_TRACE(*user_UploadRate),
+ virtual_name->data(), U_HTTP_QUERY_TO_TRACE);
USSIPlugIn::setAlternativeRedirect("http://%.*s/ticket?ticket=%.*s", U_STRING_TO_TRACE(*gateway), U_STRING_TO_TRACE(signed_data));
#endif
@@ -3377,7 +3454,7 @@ static void GET_status_nodog()
callForAllAPSorted(setStatusNodog, 0);
- _buffer.snprintf(_template.data(), num_ap, VIRTUAL_HOST);
+ _buffer.snprintf(_template.data(), num_ap, virtual_name->data());
(void) output->insert(0, _buffer);
@@ -3544,7 +3621,7 @@ static void GET_webif_ap()
(void) UFile::writeTo(dest, *address);
- USSIPlugIn::setAlternativeRedirect("http://" VIRTUAL_HOST "/cgi-bin/webif/status-basic.sh?cat=Status", 0);
+ USSIPlugIn::setAlternativeRedirect("http://%s/cgi-bin/webif/status-basic.sh?cat=Status", virtual_name->data());
}
else
{
View
4 examples/XAdES/feed.cpp
@@ -62,10 +62,8 @@ class Application : public UApplication {
if (u_startsWith(U_STRING_TO_PARAM(uri), U_CONSTANT_TO_PARAM("http")))
{
- UString request;
-
if (client.connectServer(uri) &&
- client.sendRequest(request))
+ client.sendRequest(0,0))
{
output = client.getContent();
}
View
22 examples/download_accelerator/main.cpp
@@ -115,8 +115,6 @@ class ProgressBar : public UEventTime {
U_INTERNAL_DUMP("screen_width = %d", screen_width)
- buffer = U_MALLOC_N(screen_width + 2, char);
-
count = 0;
howmuch = 0;
dl_total_time = 0;
@@ -313,8 +311,6 @@ class ProgressBar : public UEventTime {
display();
(void) UFile::write(STDOUT_FILENO, U_CONSTANT_TO_PARAM("\n"));
-
- U_FREE_N(buffer, screen_width + 2,char);
}
virtual int handlerTime()
@@ -368,7 +364,7 @@ class ProgressBar : public UEventTime {
private:
size_t count; /* total bytes downloaded so far */
- char* buffer; /* buffer where the bar "image" is stored */
+ char* buffer[1024]; /* buffer where the bar "image" is stored */
long dl_total_time; /* time measured since the beginning of download */
size_t total_length; /* expected total byte count when the download finishes */
off_t initial_length; /* how many bytes have been downloaded previously */
@@ -900,9 +896,9 @@ class Application : public UApplication {
U_INTERNAL_DUMP("num = %u", num)
- size = num * sizeof(HostData);
+ map_size1 = num * sizeof(HostData);
- place = (HostData*) UFile::mmap(size);
+ place = (HostData*) UFile::mmap(&map_size1);
U_INTERNAL_ASSERT(place->bytes_read == 0)
@@ -911,7 +907,9 @@ class Application : public UApplication {
U_INTERNAL_ASSERT(host == place)
U_INTERNAL_ASSERT(host[num-1].server.invariant())
- from = U_MALLOC_VECTOR(num, HostData);
+ map_size2 = num * sizeof(HostData*);
+
+ from = (HostData**) UFile::mmap(&map_size2);
}
void download()
@@ -1223,9 +1221,8 @@ class Application : public UApplication {
file.close();
- U_FREE_VECTOR(from, num, HostData);
-
- UFile::munmap(place, size);
+ UFile::munmap(place, map_size1);
+ UFile::munmap(from, map_size2);
# endif
}
@@ -1235,7 +1232,8 @@ class Application : public UApplication {
HostData** from;
ProgressBar* pinfo;
time_t delta_time;
- unsigned i, num, numhosts, num_score, numproc, size;
+ uint32_t map_size1, map_size2;
+ unsigned i, num, numhosts, num_score, numproc;
int max_ttl;
UFile file;
UProcess proc;
View
10 examples/uclient/uclient.cpp
@@ -26,8 +26,6 @@ class Application : public UApplication {
{
U_TRACE(5, "Application::~Application()")
- result.clear(); // NB: to avoid DEAD OF SOURCE STRING WITH CHILD ALIVE...
-
delete client;
}
@@ -104,13 +102,13 @@ class Application : public UApplication {
if (client->upload(url, file)) UApplication::exit_value = 0;
}
else if (client->connectServer(url) &&
- client->sendRequest(result))
+ client->sendRequest(0,0))
{
UApplication::exit_value = 0;
}
- result = (include ? client->getResponse()
- : client->getContent());
+ UString result = (include ? client->getResponse()
+ : client->getContent());
if (result.empty() == false) std::cout.write(U_STRING_TO_PARAM(result));
}
@@ -118,7 +116,7 @@ class Application : public UApplication {
private:
UHttpClient<USSLSocket>* client;
UFileConfig cfg;
- UString cfg_str, upload, user, password, result;
+ UString cfg_str, upload, user, password;
bool follow_redirects;
};
View
1  include/ulib/all.h
@@ -33,6 +33,7 @@
#include <ulib/utility/lock.h>
#include <ulib/utility/base64.h>
#include <ulib/utility/hexdump.h>
+#include <ulib/utility/dir_walk.h>
#include <ulib/utility/compress.h>
#include <ulib/utility/interrupt.h>
#include <ulib/utility/websocket.h>
View
2  include/ulib/base/macro.h
@@ -183,6 +183,8 @@
# define PAGESIZE 4096U
#endif
+#define U_PAGEMASK (PAGESIZE-1)
+
#ifndef O_CLOEXEC
# define O_CLOEXEC 0
#endif
View
2  include/ulib/base/utility.h
@@ -267,7 +267,7 @@ U_EXPORT int u_strnatcmp(char const* restrict a, char const* restrict b) __pure;
/* Get address space and rss (resident set size) usage */
-U_EXPORT void u_get_memusage(uint32_t* vsz, uint32_t* rss);
+U_EXPORT void u_get_memusage(unsigned long* vsz, unsigned long* rss);
/* Get the number of the processors including offline CPUs */
View
4 include/ulib/base/win32/system.h
@@ -218,6 +218,10 @@ __declspec(dllexport) int fsync(int fd);
#define MAP_ANONYMOUS 0x20 /* Don't use a file. */
#define MAP_ANON MAP_ANONYMOUS
#define MAP_FAILED ((void*)-1)
+/* These are Linux-specific. */
+#define MAP_LOCKED 0x02000 /* Lock the mapping. */
+#define MAP_NORESERVE 0x04000 /* Don't check for reservations. */
+#define MAP_POPULATE 0x08000 /* Populate (prefault) pagetables. */
#define ENOTSUP 48 /* This is the value in Solaris */
#define EBADRQC 54 /* "Invalid request code" */
View
6 include/ulib/container/gen_hash_map.h
@@ -120,8 +120,8 @@ template <typename K, typename I,
U_CHECK_MEMORY
+ table = (UGenericHashMapNode**) UMemoryPool::_malloc(&n, sizeof(UGenericHashMapNode*), true);
_capacity = n;
- table = U_CALLOC_VECTOR(n, UGenericHashMapNode);
}
void deallocate()
@@ -132,7 +132,7 @@ template <typename K, typename I,
U_INTERNAL_ASSERT_MAJOR(_capacity,0)
- U_FREE_VECTOR(table, _capacity, UGenericHashMapNode);
+ UMemoryPool::_free(table, _capacity, sizeof(UGenericHashMapNode*));
_capacity = 0;
}
@@ -339,7 +339,7 @@ template <typename K, typename I,
}
}
- U_FREE_VECTOR(old_table, old_capacity, UGenericHashMapNode);
+ UMemoryPool::_free(old_table, old_capacity, sizeof(UGenericHashMapNode*));
}
// Cancellazione tabella
View
105 include/ulib/container/hash_map.h
@@ -24,6 +24,7 @@ typedef bool (*bPFprpv)(UStringRep* key, void* elem);
class UHTTP;
class UValue;
template <class T> class UVector;
+ class USSLSession;
class UDataSession;
class U_NO_EXPORT UHashMapNode {
@@ -88,9 +89,9 @@ template <> class U_EXPORT UHashMap<void*> {
{
U_TRACE_REGISTER_OBJECT(0, UHashMap<void*>, "%b", _ignore_case)
- ignore_case = _ignore_case;
-
_length = _capacity = _space = 0;
+
+ ignore_case = _ignore_case;
}
~UHashMap()
@@ -106,8 +107,8 @@ template <> class U_EXPORT UHashMap<void*> {
U_CHECK_MEMORY
+ table = (UHashMapNode**) UMemoryPool::_malloc(&n, sizeof(UHashMapNode*), true);
_capacity = n;
- table = U_CALLOC_VECTOR(n, UHashMapNode);
}
void deallocate()
@@ -116,9 +117,9 @@ template <> class U_EXPORT UHashMap<void*> {
U_CHECK_MEMORY
- U_INTERNAL_ASSERT_MAJOR(_capacity,0)
+ U_INTERNAL_ASSERT_MAJOR(_capacity, 0)
- U_FREE_VECTOR(table, _capacity, UHashMapNode);
+ UMemoryPool::_free(table, _capacity, sizeof(UHashMapNode*));
_capacity = 0;
}
@@ -169,7 +170,7 @@ template <> class U_EXPORT UHashMap<void*> {
ignore_case = flag;
}
- bool ignoreCase() const { return ignore_case; }
+ bool ignoreCase() const { return ignore_case; }
// Ricerche
@@ -184,9 +185,9 @@ template <> class U_EXPORT UHashMap<void*> {
// Set/get methods
- void* operator[](const char* _key) { UStringRep keyr(_key); return at(&keyr); }
- void* operator[](UStringRep* _key) { return at(_key); }
- void* operator[](const UString& _key) { return at(_key.rep); }
+ void* operator[](const char* _key);
+ void* operator[](UStringRep* _key) { return at(_key); }
+ void* operator[](const UString& _key) { return at(_key.rep); }
void* elem() const { return node->elem; }
UStringRep* key() const { return node->key; }
@@ -224,9 +225,9 @@ template <> class U_EXPORT UHashMap<void*> {
void replaceKey(const UString& key);
- void* erase(const char* _key) { UStringRep keyr(_key); return erase(&keyr); }
+ void* erase(const char* _key);
void* erase(UStringRep* _key);
- void* erase(const UString& _key) { return erase(_key.rep); }
+ void* erase(const UString& _key) { return erase(_key.rep); }
// Make room for a total of n element
@@ -268,6 +269,7 @@ template <> class U_EXPORT UHashMap<void*> {
uint32_t _length, _capacity, _space, index, hash;
bool ignore_case;
+ static UStringRep* pkey;
static bool stop_call_for_all_entry;
// Find a elem in the array with <key>
@@ -284,7 +286,11 @@ template <> class U_EXPORT UHashMap<void*> {
UHashMap<void*>& operator=(const UHashMap<void*>&) { return *this; }
friend class UCDB;
+ friend class UHTTP;
friend class UValue;
+ friend class USSLSession;
+
+ friend void ULib_init();
};
template <class T> class U_EXPORT UHashMap<T*> : public UHashMap<void*> {
@@ -368,20 +374,18 @@ template <class T> class U_EXPORT UHashMap<T*> : public UHashMap<void*> {
insertAfterFind(_key, _elem);
}
- // Cancellazione tabella
-
- void clear()
+#ifdef DEBUG
+ bool check_memory() // check all element
{
- U_TRACE(0, "UHashMap<T*>::clear()")
+ U_TRACE(0, "UHashMap<T*>::check_memory()")
- U_INTERNAL_DUMP("_length = %u", _length)
+ U_CHECK_MEMORY
-# ifdef DEBUG
- int sum = 0, max = 0, min = 1024, width;
-# endif
+ U_INTERNAL_DUMP("_length = %u", _length)
T* _elem;
UHashMapNode* _next;
+ int sum = 0, max = 0, min = 1024, width;
for (index = 0; index < _capacity; ++index)
{
@@ -389,36 +393,61 @@ template <class T> class U_EXPORT UHashMap<T*> : public UHashMap<void*> {
{
node = table[index];
-# ifdef DEBUG
++sum;
width = -1;
-# endif
do {
-# ifdef DEBUG
++width;
-# endif
_next = node->next;
_elem = (T*) node->elem;
- u_destroy<T>(_elem);
-
- delete node;
+ U_CHECK_MEMORY_CLASS(*(const UMemoryError*)_elem);
}
while ((node = _next));
-# ifdef DEBUG
if (max < width) max = width;
if (min > width) min = width;
-# endif
-
- table[index] = 0;
}
}
U_INTERNAL_DUMP("collision(min,max) = (%d,%d) - distribution = %f", min, max, (double)_length / (double)sum)
+ U_RETURN(true);
+ }
+#endif
+
+ // Cancellazione tabella
+
+ void clear()
+ {
+ U_TRACE(0, "UHashMap<T*>::clear()")
+
+ U_ASSERT(check_memory())
+
+ T* _elem;
+ UHashMapNode* _next;
+
+ for (index = 0; index < _capacity; ++index)
+ {