1
0
mirror of https://github.com/stefanocasazza/ULib.git synced 2025-09-28 19:05:55 +08:00

fix+userver_udp

This commit is contained in:
stefanocasazza 2017-10-04 18:26:27 +02:00
parent 3822047d72
commit 57371985d5
43 changed files with 6044 additions and 5410 deletions

96
configure vendored
View File

@ -805,6 +805,10 @@ ENABLE_SHARED_FALSE
ENABLE_SHARED_TRUE
ENABLE_EXAMPLES_FALSE
ENABLE_EXAMPLES_TRUE
USERVER_UDP_FALSE
USERVER_UDP_TRUE
USERVER_IPC_FALSE
USERVER_IPC_TRUE
POW_LIB
LIBOBJS
SEM_TIMEDWAIT_FALSE
@ -1039,6 +1043,8 @@ enable_thread
enable_pth
with_ipv6
enable_examples
with_userver_ipc
with_userver_udp
enable_plugins
enable_memory_pool
enable_LFS
@ -1836,6 +1842,8 @@ Optional Packages:
compiler's sysroot if not specified).
--with-libc=path specify path to alternate libc [[default=c]]
--with-ipv6 Enable ipv6, default is disabled
--with-userver-ipc Enable building of userver_ipc, default is disabled
--with-userver-udp Enable building of userver_udp, default is disabled
--with-parser use parser generator bison/yacc
--with-distcc using distcc we must avoid to use some gcc flags (-mtune=native,-flto,...)
--with-libz use system LIBZ library - [will check /usr /usr/local] [default=use if present]
@ -27818,6 +27826,23 @@ if test -z "$enable_examples" -a "$enable_shared" = "yes"; then
enable_examples="yes"
fi
if false; then
USERVER_IPC_TRUE=
USERVER_IPC_FALSE='#'
else
USERVER_IPC_TRUE='#'
USERVER_IPC_FALSE=
fi
if false; then
USERVER_UDP_TRUE=
USERVER_UDP_FALSE='#'
else
USERVER_UDP_TRUE='#'
USERVER_UDP_FALSE=
fi
if test "$enable_examples" = "yes"; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
$as_echo "yes" >&6; }
@ -27830,6 +27855,60 @@ else
ENABLE_EXAMPLES_FALSE=
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if you want to build userver_ipc" >&5
$as_echo_n "checking if you want to build userver_ipc... " >&6; }
# Check whether --with-userver-ipc was given.
if test "${with_userver_ipc+set}" = set; then :
withval=$with_userver_ipc; use_userver_ipc=$withval
else
use_userver_ipc=no
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $use_userver_ipc" >&5
$as_echo "$use_userver_ipc" >&6; }
if test "$use_userver_ipc" = "yes" ; then
if true; then
USERVER_IPC_TRUE=
USERVER_IPC_FALSE='#'
else
USERVER_IPC_TRUE='#'
USERVER_IPC_FALSE=
fi
$as_echo "#define USERVER_IPC 1" >>confdefs.h
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if you want to build userver_udp" >&5
$as_echo_n "checking if you want to build userver_udp... " >&6; }
# Check whether --with-userver-udp was given.
if test "${with_userver_udp+set}" = set; then :
withval=$with_userver_udp; use_userver_udp=$withval
else
use_userver_udp=no
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $use_userver_udp" >&5
$as_echo "$use_userver_udp" >&6; }
if test "$use_userver_udp" = "yes" ; then
if true; then
USERVER_UDP_TRUE=
USERVER_UDP_FALSE='#'
else
USERVER_UDP_TRUE='#'
USERVER_UDP_FALSE=
fi
$as_echo "#define USERVER_UDP 1" >>confdefs.h
fi
else
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
@ -28501,6 +28580,7 @@ fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $use_parser" >&5
$as_echo "$use_parser" >&6; }
if test "$use_parser" = "yes" ; then
for ac_prog in 'bison -y' byacc
do
@ -35873,10 +35953,26 @@ if test -z "${NANOSLEEP_TRUE}" && test -z "${NANOSLEEP_FALSE}"; then
as_fn_error $? "conditional \"NANOSLEEP\" was never defined.
Usually this means the macro was only invoked conditionally." "$LINENO" 5
fi
if test -z "${USERVER_IPC_TRUE}" && test -z "${USERVER_IPC_FALSE}"; then
as_fn_error $? "conditional \"USERVER_IPC\" was never defined.
Usually this means the macro was only invoked conditionally." "$LINENO" 5
fi
if test -z "${USERVER_UDP_TRUE}" && test -z "${USERVER_UDP_FALSE}"; then
as_fn_error $? "conditional \"USERVER_UDP\" was never defined.
Usually this means the macro was only invoked conditionally." "$LINENO" 5
fi
if test -z "${ENABLE_EXAMPLES_TRUE}" && test -z "${ENABLE_EXAMPLES_FALSE}"; then
as_fn_error $? "conditional \"ENABLE_EXAMPLES\" was never defined.
Usually this means the macro was only invoked conditionally." "$LINENO" 5
fi
if test -z "${USERVER_IPC_TRUE}" && test -z "${USERVER_IPC_FALSE}"; then
as_fn_error $? "conditional \"USERVER_IPC\" was never defined.
Usually this means the macro was only invoked conditionally." "$LINENO" 5
fi
if test -z "${USERVER_UDP_TRUE}" && test -z "${USERVER_UDP_FALSE}"; then
as_fn_error $? "conditional \"USERVER_UDP\" was never defined.
Usually this means the macro was only invoked conditionally." "$LINENO" 5
fi
if test -z "${ENABLE_EXAMPLES_TRUE}" && test -z "${ENABLE_EXAMPLES_FALSE}"; then
as_fn_error $? "conditional \"ENABLE_EXAMPLES\" was never defined.
Usually this means the macro was only invoked conditionally." "$LINENO" 5

View File

@ -1253,10 +1253,37 @@ if test -z "$enable_examples" -a "$enable_shared" = "yes"; then
enable_examples="yes"
fi
AM_CONDITIONAL(USERVER_IPC, false)
AM_CONDITIONAL(USERVER_UDP, false)
if test "$enable_examples" = "yes"; then
AC_MSG_RESULT(yes)
ulib_examples="enabled"
AM_CONDITIONAL(ENABLE_EXAMPLES, true)
AC_MSG_CHECKING(if you want to build userver_ipc)
AC_ARG_WITH(userver-ipc,
[ --with-userver-ipc Enable building of userver_ipc, default is disabled],
[use_userver_ipc=$withval],
[use_userver_ipc=no])
AC_MSG_RESULT($use_userver_ipc)
if test "$use_userver_ipc" = "yes" ; then
AM_CONDITIONAL(USERVER_IPC, true)
AC_DEFINE(USERVER_IPC, 1, [Define if use userver_ipc])
fi
AC_MSG_CHECKING(if you want to build userver_udp)
AC_ARG_WITH(userver-udp,
[ --with-userver-udp Enable building of userver_udp, default is disabled],
[use_userver_udp=$withval],
[use_userver_udp=no])
AC_MSG_RESULT($use_userver_udp)
if test "$use_userver_udp" = "yes" ; then
AM_CONDITIONAL(USERVER_UDP, true)
AC_DEFINE(USERVER_UDP, 1, [Define if use userver_udp])
fi
else
AC_MSG_RESULT(no)
AM_CONDITIONAL(ENABLE_EXAMPLES, false)
@ -1299,6 +1326,7 @@ AC_ARG_WITH(parser,
[use_parser=$withval],
[use_parser=no])
AC_MSG_RESULT($use_parser)
if test "$use_parser" = "yes" ; then
AC_PROG_YACC
AC_PROG_LEX

View File

@ -23,6 +23,15 @@ userver_ssl_CPPFLAGS = -DU_SSL_SOCKET $(CPPFLAGS)
bin_PROGRAMS += userver_ssl
endif
if USERVER_UDP
userver_udp_LDADD = $(ulib_la)
userver_udp_SOURCES = userver.cpp
userver_udp_LDFLAGS = $(PRG_LDFLAGS)
userver_udp_CPPFLAGS = -DU_UDP_SOCKET $(CPPFLAGS)
bin_PROGRAMS += userver_udp
endif
if USERVER_IPC
## MINGW don't have unix socket...
if !MINGW
userver_ipc_LDADD = $(ulib_la)
@ -31,6 +40,7 @@ userver_ipc_LDFLAGS = $(PRG_LDFLAGS)
userver_ipc_CPPFLAGS = -DU_UNIX_SOCKET $(CPPFLAGS)
bin_PROGRAMS += userver_ipc
endif
endif
install-exec-hook:
@if test -f "$(DESTDIR)$(DEFAULT_CONFIG_FILE)" ; then \

View File

@ -90,9 +90,11 @@ POST_UNINSTALL = :
build_triplet = @build@
host_triplet = @host@
target_triplet = @target@
bin_PROGRAMS = userver_tcp$(EXEEXT) $(am__EXEEXT_1) $(am__EXEEXT_2)
bin_PROGRAMS = userver_tcp$(EXEEXT) $(am__EXEEXT_1) $(am__EXEEXT_2) \
$(am__EXEEXT_3)
@SSL_TRUE@am__append_1 = userver_ssl
@MINGW_FALSE@am__append_2 = userver_ipc
@USERVER_UDP_TRUE@am__append_2 = userver_udp
@MINGW_FALSE@@USERVER_IPC_TRUE@am__append_3 = userver_ipc
subdir = examples/userver
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/m4/ac_check_package.m4 \
@ -123,14 +125,17 @@ CONFIG_CLEAN_FILES = web_server.spec wagsmserver.spec tsaserver.spec \
cspserver.spec rsignserver.spec
CONFIG_CLEAN_VPATH_FILES =
@SSL_TRUE@am__EXEEXT_1 = userver_ssl$(EXEEXT)
@MINGW_FALSE@am__EXEEXT_2 = userver_ipc$(EXEEXT)
@USERVER_UDP_TRUE@am__EXEEXT_2 = userver_udp$(EXEEXT)
@MINGW_FALSE@@USERVER_IPC_TRUE@am__EXEEXT_3 = userver_ipc$(EXEEXT)
am__installdirs = "$(DESTDIR)$(bindir)" "$(DESTDIR)$(sysconfdir)"
PROGRAMS = $(bin_PROGRAMS)
am__userver_ipc_SOURCES_DIST = userver.cpp
@MINGW_FALSE@am_userver_ipc_OBJECTS = userver_ipc-userver.$(OBJEXT)
@MINGW_FALSE@@USERVER_IPC_TRUE@am_userver_ipc_OBJECTS = \
@MINGW_FALSE@@USERVER_IPC_TRUE@ userver_ipc-userver.$(OBJEXT)
userver_ipc_OBJECTS = $(am_userver_ipc_OBJECTS)
am__DEPENDENCIES_1 = $(top_builddir)/src/ulib/lib@ULIB@.la
@MINGW_FALSE@userver_ipc_DEPENDENCIES = $(am__DEPENDENCIES_1)
@MINGW_FALSE@@USERVER_IPC_TRUE@userver_ipc_DEPENDENCIES = \
@MINGW_FALSE@@USERVER_IPC_TRUE@ $(am__DEPENDENCIES_1)
AM_V_lt = $(am__v_lt_@AM_V@)
am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@)
am__v_lt_0 = --silent
@ -151,6 +156,14 @@ userver_tcp_DEPENDENCIES = $(am__DEPENDENCIES_1)
userver_tcp_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) \
$(LIBTOOLFLAGS) --mode=link $(CXXLD) $(AM_CXXFLAGS) \
$(CXXFLAGS) $(userver_tcp_LDFLAGS) $(LDFLAGS) -o $@
am__userver_udp_SOURCES_DIST = userver.cpp
@USERVER_UDP_TRUE@am_userver_udp_OBJECTS = \
@USERVER_UDP_TRUE@ userver_udp-userver.$(OBJEXT)
userver_udp_OBJECTS = $(am_userver_udp_OBJECTS)
@USERVER_UDP_TRUE@userver_udp_DEPENDENCIES = $(am__DEPENDENCIES_1)
userver_udp_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) \
$(LIBTOOLFLAGS) --mode=link $(CXXLD) $(AM_CXXFLAGS) \
$(CXXFLAGS) $(userver_udp_LDFLAGS) $(LDFLAGS) -o $@
AM_V_P = $(am__v_P_@AM_V@)
am__v_P_ = $(am__v_P_@AM_DEFAULT_V@)
am__v_P_0 = false
@ -185,9 +198,10 @@ am__v_CXXLD_ = $(am__v_CXXLD_@AM_DEFAULT_V@)
am__v_CXXLD_0 = @echo " CXXLD " $@;
am__v_CXXLD_1 =
SOURCES = $(userver_ipc_SOURCES) $(userver_ssl_SOURCES) \
$(userver_tcp_SOURCES)
$(userver_tcp_SOURCES) $(userver_udp_SOURCES)
DIST_SOURCES = $(am__userver_ipc_SOURCES_DIST) \
$(am__userver_ssl_SOURCES_DIST) $(userver_tcp_SOURCES)
$(am__userver_ssl_SOURCES_DIST) $(userver_tcp_SOURCES) \
$(am__userver_udp_SOURCES_DIST)
am__can_run_installinfo = \
case $$AM_UPDATE_INFO_DIR in \
n|no|NO) false;; \
@ -451,10 +465,14 @@ userver_tcp_CPPFLAGS = -DU_TCP_SOCKET $(CPPFLAGS)
@SSL_TRUE@userver_ssl_SOURCES = userver.cpp
@SSL_TRUE@userver_ssl_LDFLAGS = $(PRG_LDFLAGS)
@SSL_TRUE@userver_ssl_CPPFLAGS = -DU_SSL_SOCKET $(CPPFLAGS)
@MINGW_FALSE@userver_ipc_LDADD = $(ulib_la)
@MINGW_FALSE@userver_ipc_SOURCES = userver.cpp
@MINGW_FALSE@userver_ipc_LDFLAGS = $(PRG_LDFLAGS)
@MINGW_FALSE@userver_ipc_CPPFLAGS = -DU_UNIX_SOCKET $(CPPFLAGS)
@USERVER_UDP_TRUE@userver_udp_LDADD = $(ulib_la)
@USERVER_UDP_TRUE@userver_udp_SOURCES = userver.cpp
@USERVER_UDP_TRUE@userver_udp_LDFLAGS = $(PRG_LDFLAGS)
@USERVER_UDP_TRUE@userver_udp_CPPFLAGS = -DU_UDP_SOCKET $(CPPFLAGS)
@MINGW_FALSE@@USERVER_IPC_TRUE@userver_ipc_LDADD = $(ulib_la)
@MINGW_FALSE@@USERVER_IPC_TRUE@userver_ipc_SOURCES = userver.cpp
@MINGW_FALSE@@USERVER_IPC_TRUE@userver_ipc_LDFLAGS = $(PRG_LDFLAGS)
@MINGW_FALSE@@USERVER_IPC_TRUE@userver_ipc_CPPFLAGS = -DU_UNIX_SOCKET $(CPPFLAGS)
all: all-am
.SUFFIXES:
@ -560,6 +578,10 @@ userver_tcp$(EXEEXT): $(userver_tcp_OBJECTS) $(userver_tcp_DEPENDENCIES) $(EXTRA
@rm -f userver_tcp$(EXEEXT)
$(AM_V_CXXLD)$(userver_tcp_LINK) $(userver_tcp_OBJECTS) $(userver_tcp_LDADD) $(LIBS)
userver_udp$(EXEEXT): $(userver_udp_OBJECTS) $(userver_udp_DEPENDENCIES) $(EXTRA_userver_udp_DEPENDENCIES)
@rm -f userver_udp$(EXEEXT)
$(AM_V_CXXLD)$(userver_udp_LINK) $(userver_udp_OBJECTS) $(userver_udp_LDADD) $(LIBS)
mostlyclean-compile:
-rm -f *.$(OBJEXT)
@ -569,6 +591,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/userver_ipc-userver.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/userver_ssl-userver.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/userver_tcp-userver.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/userver_udp-userver.Po@am__quote@
.cpp.o:
@am__fastdepCXX_TRUE@ $(AM_V_CXX)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.o$$||'`;\
@ -636,6 +659,20 @@ userver_tcp-userver.obj: userver.cpp
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(userver_tcp_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o userver_tcp-userver.obj `if test -f 'userver.cpp'; then $(CYGPATH_W) 'userver.cpp'; else $(CYGPATH_W) '$(srcdir)/userver.cpp'; fi`
userver_udp-userver.o: userver.cpp
@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(userver_udp_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT userver_udp-userver.o -MD -MP -MF $(DEPDIR)/userver_udp-userver.Tpo -c -o userver_udp-userver.o `test -f 'userver.cpp' || echo '$(srcdir)/'`userver.cpp
@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/userver_udp-userver.Tpo $(DEPDIR)/userver_udp-userver.Po
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='userver.cpp' object='userver_udp-userver.o' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(userver_udp_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o userver_udp-userver.o `test -f 'userver.cpp' || echo '$(srcdir)/'`userver.cpp
userver_udp-userver.obj: userver.cpp
@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(userver_udp_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT userver_udp-userver.obj -MD -MP -MF $(DEPDIR)/userver_udp-userver.Tpo -c -o userver_udp-userver.obj `if test -f 'userver.cpp'; then $(CYGPATH_W) 'userver.cpp'; else $(CYGPATH_W) '$(srcdir)/userver.cpp'; fi`
@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/userver_udp-userver.Tpo $(DEPDIR)/userver_udp-userver.Po
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='userver.cpp' object='userver_udp-userver.obj' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(userver_udp_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o userver_udp-userver.obj `if test -f 'userver.cpp'; then $(CYGPATH_W) 'userver.cpp'; else $(CYGPATH_W) '$(srcdir)/userver.cpp'; fi`
mostlyclean-libtool:
-rm -f *.lo

View File

@ -5,14 +5,17 @@
#ifdef U_SSL_SOCKET
# include <ulib/ssl/net/sslsocket.h>
# define Server UServer<USSLSocket>
#elif defined(U_TCP_SOCKET)
# include <ulib/net/tcpsocket.h>
# define Server UServer<UTCPSocket>
#elif defined(U_UDP_SOCKET)
# include <ulib/net/udpsocket.h>
# define Server UServer<UUDPSocket>
#elif defined(U_UNIX_SOCKET)
# include <ulib/net/unixsocket.h>
# define Server UServer<UUnixSocket>
#elif defined(U_TCP_SOCKET)
# include <ulib/net/tcpsocket.h>
# define Server UServer<UTCPSocket>
#else
# error "you must define the socket type (U_SSL_SOCKET | U_TCP_SOCKET | U_UNIX_SOCKET)"
# error "you must define the socket type (U_SSL_SOCKET | U_TCP_SOCKET | U_UNIX_SOCKET | U_UDP_SOCKET)"
#endif
#include <ulib/net/server/server.h>
@ -132,11 +135,14 @@ public:
// DOS_LOGFILE the file to write DOS event
// ---------------------------------------------------------------------------------------------------------------------------------------
# ifdef U_SSL_SOCKET
# if defined(U_SSL_SOCKET)
UServer_Base::bssl = true;
# elif defined(U_UDP_SOCKET)
UServer_Base::budp = true;
# elif defined(U_UNIX_SOCKET)
UServer_Base::bipc = true;
# endif
server = new Server(&cfg);
server->run();

View File

@ -26,7 +26,9 @@ extern "C" {
* #define GZIP_MAGIC "\037\213" Magic header for gzip files, 1F 8B
*/
U_EXPORT uint32_t u_gz_deflate(const char* restrict input, uint32_t len, char* restrict result, bool bheader);
extern U_EXPORT bool u_gz_deflate_header; /* deflate, gzip */
U_EXPORT uint32_t u_gz_deflate(const char* restrict input, uint32_t len, char* restrict result, int level);
U_EXPORT uint32_t u_gz_inflate(const char* restrict input, uint32_t len, char* restrict result);
#ifdef __cplusplus

View File

@ -143,15 +143,8 @@ public:
U_CHECK_MEMORY
U_INTERNAL_ASSERT_POINTER(handle)
# ifdef _MSWINDOWS_
::FreeLibrary(handle);
# else
(void) U_SYSCALL(dlclose, "%p", handle);
# endif
handle = U_NULLPTR;
dclose(handle);
handle = U_NULLPTR;
}
/**
@ -189,6 +182,7 @@ protected:
static UString* plugin_dir;
static void dclose(HINSTANCE handle);
static HINSTANCE dload(const char* pathname);
static void* lookup(HINSTANCE handle, const char* sym);
static HINSTANCE dload(const char* name, uint32_t name_len);

View File

@ -5667,7 +5667,7 @@ static void GET_get_config()
if (U_http_is_accept_gzip &&
_body.size() > U_MIN_SIZE_FOR_DEFLATE)
{
_body = UStringExt::deflate(_body, 1);
_body = UStringExt::deflate(_body, Z_DEFAULT_COMPRESSION);
}
# endif
}

View File

@ -696,6 +696,12 @@
/* ULib version */
#undef ULIB_VERSION
/* Define if use userver_ipc */
#undef USERVER_IPC
/* Define if use userver_udp */
#undef USERVER_UDP
/* Define if enable c-ares support */
#undef USE_C_ARES

View File

@ -235,7 +235,6 @@ protected:
static bool checkPeerInfo(UStringRep* key, void* value);
static bool checkPeerStatus(UStringRep* key, void* value);
static bool getPeerListInfo(UStringRep* key, void* value);
static void setHTTPResponse(const UString& content, int mime_index);
static void permit(UString& UserDownloadRate, UString& UserUploadRate);
static void sendMsgToPortal(uint32_t index_AUTH, const UString& msg, UString* poutput);
static void sendData(uint32_t index_AUTH, const UString& data, const char* service, uint32_t service_len);

View File

@ -19,6 +19,8 @@
#include <ulib/command.h>
#include <ulib/notifier.h>
#include <ulib/file_config.h>
#include <ulib/net/udpsocket.h>
#include <ulib/net/unixsocket.h>
#include <ulib/utility/interrupt.h>
#include <ulib/utility/socket_ext.h>
#include <ulib/net/server/client_image.h>
@ -209,7 +211,7 @@ public:
static void run(); // loop waiting for connection
static UFileConfig* cfg;
static bool bssl, bipc, flag_loop;
static bool bssl, bipc, budp, flag_loop;
static unsigned int port; // the port number to bind to
static int getReqTimeout() { return (ptime ? ptime->UTimeVal::tv_sec : 0); }
@ -610,8 +612,10 @@ public:
static int iAddressType, socket_flags, tcp_linger_set;
static uint32_t client_address_len, min_size_for_sendfile;
#define U_CLIENT_ADDRESS_TO_PARAM UServer_Base::client_address, UServer_Base::client_address_len
#define U_CLIENT_ADDRESS_TO_TRACE UServer_Base::client_address_len, UServer_Base::client_address
#define U_CLIENT_ADDRESS_TO_PARAM UServer_Base::client_address, UServer_Base::client_address_len
#define U_CLIENT_ADDRESS_TO_TRACE UServer_Base::client_address_len, UServer_Base::client_address
static void setClientAddress() { setClientAddress(csocket, client_address, client_address_len); }
static UString getIPAddress() { return *IP_address; }
static UString getNetworkDevice( const char* exclude) { return USocketExt::getNetworkDevice(exclude); }
@ -641,6 +645,7 @@ public:
static USocket* socket;
static USocket* csocket;
static UString* name_sock; // name file for the listening socket
protected:
static int timeoutMS, // the time-out value in milliseconds for client request
verify_mode; // mode of verification ssl connection
@ -653,7 +658,6 @@ protected:
static UString* password; // password for private key of server
static UString* ca_file; // locations of trusted CA certificates used in the verification
static UString* ca_path; // locations of trusted CA certificates used in the verification
static UString* name_sock; // name file for the listening socket
static UString* IP_address; // IP address of this server
static int rkids;
@ -681,6 +685,10 @@ protected:
static void runLoop(const char* user);
static bool handlerTimeoutConnection(void* cimg);
#ifndef U_LOG_DISABLE
static void logNewClient(USocket* psocket, UClientImage_Base* lClientImage);
#endif
#ifdef U_WELCOME_SUPPORT
static UString* msg_welcome;
#endif
@ -704,6 +712,28 @@ protected:
static UString getStats();
#endif
#ifdef USERVER_UDP
static vPFi runDynamicPage_udp;
static int handlerUDP()
{
U_TRACE_NO_PARAM(0, "UServer_Base::handlerUDP()")
U_INTERNAL_DUMP("runDynamicPage_udp = %p", runDynamicPage_udp)
if (runDynamicPage_udp) runDynamicPage_udp(0);
else
{
*UClientImage_Base::wbuffer = *UClientImage_Base::rbuffer; // echo server
}
UClientImage_Base::setRequestProcessed();
UClientImage_Base::setNoHeaderForResponse();
U_RETURN(U_PLUGIN_HANDLER_FINISHED);
}
#endif
#ifdef U_THROTTLING_SUPPORT
typedef struct uthrottling {
uint64_t bytes_since_avg;
@ -872,9 +902,9 @@ protected:
U_RETURN(false);
}
static RETSIGTYPE handlerForSigHUP( int signo);
static RETSIGTYPE handlerForSigTERM( int signo);
// static RETSIGTYPE handlerForSigCHLD( int signo);
static RETSIGTYPE handlerForSigHUP( int signo);
static RETSIGTYPE handlerForSigTERM(int signo);
// static RETSIGTYPE handlerForSigCHLD(int signo);
static void sendSignalToAllChildren(int signo, sighandler_t handler);
@ -901,6 +931,18 @@ private:
if (pluginsHandlerSigHUP() != U_PLUGIN_HANDLER_FINISHED) U_WARNING("Plugins stage SigHUP failed...");
}
static void setClientAddress(USocket* psocket, char*& pclient_address, uint32_t& pclient_address_len)
{
U_TRACE(0, "UServer_Base::setClientAddress(%p,%p,%u)", psocket, pclient_address, pclient_address_len)
U_INTERNAL_ASSERT(psocket->isConnected())
pclient_address = UIPAddress::resolveStrAddress(iAddressType, psocket->cRemoteAddress.pcAddress.p, psocket->cRemoteAddress.pcStrAddress);
pclient_address_len = u__strlen(pclient_address, __PRETTY_FUNCTION__);
U_INTERNAL_DUMP("client_address = %.*S", pclient_address_len, pclient_address)
}
static void logMemUsage(const char* signame)
{
U_TRACE(0, "UServer_Base::logMemUsage(%S)", signame)
@ -1036,6 +1078,8 @@ public:
# endif
U_NEW(USSLSocket, socket, USSLSocket(UClientImage_Base::bIPv6, U_NULLPTR, true));
if (pcfg) ((USSLSocket*)socket)->ciphersuite_model = pcfg->readLong(U_CONSTANT_TO_PARAM("CIPHER_SUITE"));
}
virtual ~UServer()
@ -1084,4 +1128,140 @@ private:
U_DISALLOW_COPY_AND_ASSIGN(UServer<USSLSocket>)
};
#endif
#ifdef USERVER_UDP
template <> class U_EXPORT UServer<UUDPSocket> : public UServer_Base {
public:
typedef UClientImage<UUDPSocket> client_type;
UServer(UFileConfig* pcfg) : UServer_Base(pcfg)
{
U_TRACE_REGISTER_OBJECT(0, UServer<UUDPSocket>, "%p", pcfg)
# ifdef DEBUG
if (pcfg &&
budp == false)
{
U_ERROR("You need to set budp var before loading the configuration");
}
# endif
U_NEW(UUDPSocket, socket, UUDPSocket(UClientImage_Base::bIPv6));
}
virtual ~UServer()
{
U_TRACE_UNREGISTER_OBJECT(0, UServer<UUDPSocket>)
}
// DEBUG
#if defined(DEBUG) && defined(U_STDCPP_ENABLE)
const char* dump(bool reset) const { return UServer_Base::dump(reset); }
#endif
protected:
// ---------------------------------------------------------------------------------------------------------------
// method VIRTUAL to redefine
// ---------------------------------------------------------------------------------------------------------------
// Create a new UClientImage object representing a client connection to the server.
// Derived classes that have overridden UClientImage object may call this function to implement the creation logic
// ---------------------------------------------------------------------------------------------------------------
virtual void preallocate() U_DECL_OVERRIDE
{
U_TRACE_NO_PARAM(0+256, "UServer<UUDPSocket>::preallocate()")
// NB: array are not pointers (virtual table can shift the address of this)...
vClientImage = new client_type[UNotifier::max_connection];
}
#ifdef DEBUG
virtual void deallocate() U_DECL_OVERRIDE
{
U_TRACE_NO_PARAM(0+256, "UServer<UUDPSocket>::deallocate()")
// NB: array are not pointers (virtual table can shift the address of this)...
delete[] (client_type*)vClientImage;
}
virtual bool check_memory() U_DECL_OVERRIDE { return u_check_memory_vector<client_type>((client_type*)vClientImage, UNotifier::max_connection); }
#endif
private:
U_DISALLOW_COPY_AND_ASSIGN(UServer<UUDPSocket>)
};
#endif
#ifdef USERVER_IPC
template <> class U_EXPORT UServer<UUnixSocket> : public UServer_Base {
public:
typedef UClientImage<UUnixSocket> client_type;
UServer(UFileConfig* pcfg) : UServer_Base(pcfg)
{
U_TRACE_REGISTER_OBJECT(0, UServer<UUnixSocket>, "%p", pcfg)
# ifdef DEBUG
if (pcfg &&
bipc == false)
{
U_ERROR("You need to set bipc var before loading the configuration");
}
# endif
U_NEW(UUnixSocket, socket, UUnixSocket(UClientImage_Base::bIPv6));
}
virtual ~UServer()
{
U_TRACE_UNREGISTER_OBJECT(0, UServer<UUnixSocket>)
}
// DEBUG
#if defined(DEBUG) && defined(U_STDCPP_ENABLE)
const char* dump(bool reset) const { return UServer_Base::dump(reset); }
#endif
protected:
// ---------------------------------------------------------------------------------------------------------------
// method VIRTUAL to redefine
// ---------------------------------------------------------------------------------------------------------------
// Create a new UClientImage object representing a client connection to the server.
// Derived classes that have overridden UClientImage object may call this function to implement the creation logic
// ---------------------------------------------------------------------------------------------------------------
virtual void preallocate() U_DECL_OVERRIDE
{
U_TRACE_NO_PARAM(0+256, "UServer<UUnixSocket>::preallocate()")
// NB: array are not pointers (virtual table can shift the address of this)...
vClientImage = new client_type[UNotifier::max_connection];
}
#ifdef DEBUG
virtual void deallocate() U_DECL_OVERRIDE
{
U_TRACE_NO_PARAM(0+256, "UServer<UUnixSocket>::deallocate()")
// NB: array are not pointers (virtual table can shift the address of this)...
delete[] (client_type*)vClientImage;
}
virtual bool check_memory() U_DECL_OVERRIDE { return u_check_memory_vector<client_type>((client_type*)vClientImage, UNotifier::max_connection); }
#endif
private:
U_DISALLOW_COPY_AND_ASSIGN(UServer<UUnixSocket>)
};
#endif
#endif

View File

@ -606,12 +606,16 @@ public:
int recvFrom(void* pBuffer, uint32_t iBufLength, uint32_t uiFlags, UIPAddress& cSourceIP, unsigned int& iSourcePortNumber);
int recvFrom(void* pBuffer, uint32_t iBufLength, uint32_t uiFlags = 0) { return recvFrom(pBuffer, iBufLength, uiFlags, cRemoteAddress, iRemotePort); }
/**
* The socket transmits the data to the remote socket
* The socket transmits the data to the remote socket. The number of bytes written is returned
*/
int sendTo(void* pPayload, uint32_t iPayloadLength, uint32_t uiFlags, UIPAddress& cDestinationIP, unsigned int iDestinationPortNumber);
int sendTo(void* pPayload, uint32_t iPayloadLength, uint32_t uiFlags = 0) { return sendTo(pPayload, iPayloadLength, uiFlags, cRemoteAddress, iRemotePort); }
/**
* This method is called to read a 16-bit binary value from the remote connection.
* We loop - calling recv() - until the required number of bytes are read, if recv()
@ -771,6 +775,9 @@ protected:
static bool breuseport, bincoming_cpu;
static int iBackLog, incoming_cpu, accept4_flags; // If flags is 0, then accept4() is the same as accept()
static void setLocalInfo( USocket* p, SocketAddress* cLocal);
static void setRemoteInfo(USocket* p, SocketAddress* cRemote);
/**
* The _socket() function is called to create the socket of the specified type.
* The parameters indicate whether the socket will use IPv6 or IPv4 and the type of socket

View File

@ -16,8 +16,9 @@
#include <ulib/net/socket.h>
#ifdef _WIN32
#ifdef _MSWINDOWS_
# include <io.h>
typedef struct sockaddr_un { char sun_path[108]; } sockaddr_un;
#else
# include <sys/un.h>
#endif
@ -57,8 +58,8 @@
*/
union uusockaddr_un {
struct sockaddr psaGeneric;
struct sockaddr_un psaUnixAddr;
struct sockaddr psaGeneric;
struct sockaddr_un psaUnixAddr;
};
class UServer_Base;

View File

@ -68,26 +68,31 @@ public:
static UString compress(const UString& s) { return compress(U_STRING_TO_PARAM(s)); }
static UString decompress(const UString& s) { return decompress(U_STRING_TO_PARAM(s)); }
#ifdef USE_LIBBROTLI
static uint32_t ratio, ratio_threshold;
static bool isGzip(const char* s) { return (u_get_unalignedp16(s) == U_MULTICHAR_CONSTANT16('\x1F','\x8B')); }
static bool isGzip(const UString& s) { return isGzip(s.data()); }
static UString gunzip(const char* s, uint32_t n, uint32_t sz_orig); // .gz uncompress
static UString gunzip(const UString& s, uint32_t sz_orig = 0) { return gunzip(U_STRING_TO_PARAM(s), sz_orig); }
#ifdef USE_LIBZ
static UString deflate(const char* s, uint32_t n, uint32_t quality = 0); // .gz compress (0 => zopfli)
static UString deflate(const UString& s, uint32_t quality = 0) { return deflate(U_STRING_TO_PARAM(s), quality); }
#endif
static bool isBrotli(const char* s) { return false; } // (u_get_unalignedp32(s) == U_MULTICHAR_CONSTANT32('\xCE','\xB2','\xCF','\x81'))
static bool isBrotli(const UString& s) { return isBrotli(s.data()); }
static UString unbrotli(const char* s, uint32_t n);
static UString unbrotli(const UString& s) { return unbrotli(U_STRING_TO_PARAM(s)); }
#ifdef USE_LIBBROTLI
static UString brotli(const char* s, uint32_t n, uint32_t quality = BROTLI_MAX_QUALITY, uint32_t mode = BROTLI_MODE_TEXT, uint32_t lgwin = BROTLI_DEFAULT_WINDOW);
static UString brotli(const UString& s, uint32_t quality = BROTLI_MAX_QUALITY, uint32_t mode = BROTLI_MODE_TEXT, uint32_t lgwin = BROTLI_DEFAULT_WINDOW)
{ return brotli(U_STRING_TO_PARAM(s), quality, mode, lgwin); }
#endif
// GZIP method
static bool isGzip(const char* s) { return (u_get_unalignedp16(s) == U_MULTICHAR_CONSTANT16('\x1F','\x8B')); }
static bool isGzip(const UString& s) { return isGzip(s.data()); }
static UString deflate(const char* s, uint32_t n, int type); // .gz compress
static UString gunzip(const char* s, uint32_t n, uint32_t sz_orig); // .gz uncompress
static UString deflate(const UString& s, int type) { return deflate(U_STRING_TO_PARAM(s), type); }
static UString gunzip(const UString& s, uint32_t sz_orig = 0) { return gunzip(U_STRING_TO_PARAM(s), sz_orig); }
// Convert numeric to string
static UString printSize(off_t n)

View File

@ -44,6 +44,7 @@ class UPageSpeed;
class USSIPlugIn;
class UHttpPlugIn;
class USSLSession;
class UProxyPlugIn;
class UMimeMultipart;
class UModProxyService;
class UClientImage_Base;
@ -184,7 +185,7 @@ public:
static char response_buffer[64];
static int mime_index, cgi_timeout; // the time-out value in seconds for output cgi process
static bool enable_caching_by_proxy_servers, skip_check_cookie_ip_address;
static uint32_t limit_request_body, request_read_timeout, range_start, range_size, brotli_level_for_dynamic_content;
static uint32_t limit_request_body, request_read_timeout, range_start, range_size, gzip_level_for_dynamic_content, brotli_level_for_dynamic_content;
static bool readRequest();
static bool handlerCache();
@ -419,10 +420,6 @@ public:
NETWORK_AUTHENTICATION_REQUIRED = 0x008
};
static void setDynamicResponse();
static void setResponse(bool btype, const UString& content_type, UString* pbody);
static void setRedirectResponse(int mode, const char* ptr_location, uint32_t len_location);
static void setErrorResponse(const UString& content_type, int code, const char* fmt, uint32_t fmt_size, bool bformat = true);
static void setResponse()
{
@ -435,6 +432,12 @@ public:
handlerResponse();
}
static void setDynamicResponse();
static void setResponseMimeIndex(const UString& content, int mime_index);
static void setResponse(const UString& content_type, UString* pbody = U_NULLPTR);
static void setRedirectResponse(int mode, const char* ptr_location, uint32_t len_location);
static void setErrorResponse(const UString& content_type, int code, const char* fmt, uint32_t fmt_size, bool bformat = true);
// set HTTP main error message
static void setNotFound()
@ -1282,6 +1285,7 @@ private:
static int handlerREAD();
static void processRequest();
static void handlerResponse();
static void setDynamicResponse(const UString& body, const UString& header = UString::getStringNull(), const UString& content_type = UString::getStringNull());
#ifndef U_LOG_DISABLE
static int handlerREADWithLog()
@ -1365,6 +1369,7 @@ private:
static void checkArrayCompressData(UFileCacheData* ptr) U_NO_EXPORT;
# endif
static inline bool compress(const UString& body) U_NO_EXPORT;
static inline void setAcceptEncoding(const char* ptr, uint32_t len) U_NO_EXPORT;
#endif
@ -1385,19 +1390,20 @@ private:
static bool checkGetRequestIfRange() U_NO_EXPORT;
static void setCGIShellScript(UString& command) U_NO_EXPORT;
static bool checkIfSourceHasChangedAndCompileUSP() U_NO_EXPORT;
static void setResponseCompressed(const UString& data) U_NO_EXPORT;
static bool compileUSP(const char* path, uint32_t len) U_NO_EXPORT;
static int checkGetRequestForRange(const UString& data) U_NO_EXPORT;
static int sortRange(const void* a, const void* b) __pure U_NO_EXPORT;
static bool addHTTPVariables(UStringRep* key, void* value) U_NO_EXPORT;
static void setContentResponse(const UString& content_type) U_NO_EXPORT;
static bool splitCGIOutput(const char*& ptr1, const char* ptr2) U_NO_EXPORT;
static void putDataInCache(const UString& fmt, UString& content) U_NO_EXPORT;
static void setHeaderForCache(UFileCacheData* ptr, const UString& data) U_NO_EXPORT;
static void setHeaderForCache(UFileCacheData* ptr, UString& data) U_NO_EXPORT;
static bool readDataChunked(USocket* sk, UString* pbuffer, UString& body) U_NO_EXPORT;
static void setResponseForRange(uint32_t start, uint32_t end, uint32_t header) U_NO_EXPORT;
static void manageDataForCache(const UString& basename, const UString& suffix) U_NO_EXPORT;
static bool checkDataSession(const UString& token, time_t expire, UString* data) U_NO_EXPORT;
static bool processAuthorization(const char* ptr = U_NULLPTR, uint32_t sz = 0, const char* pattern = U_NULLPTR, uint32_t len = 0) U_NO_EXPORT;
static void setDataInCache(const UString& fmt, const UString& content, const char* encoding = U_NULLPTR, uint32_t encoding_len = 0) U_NO_EXPORT;
static inline void resetFileCache() U_NO_EXPORT;
static inline void setUpgrade(const char* ptr) U_NO_EXPORT;
@ -1425,6 +1431,7 @@ private:
friend class UHTTP2;
friend class USSIPlugIn;
friend class UHttpPlugIn;
friend class UProxyPlugIn;
friend class UClientImage_Base;
#ifdef U_STDCPP_ENABLE

View File

@ -50,7 +50,8 @@ void UApplication::printMemUsage()
{
U_TRACE_NO_PARAM(0, "UApplication::printMemUsage()")
if (U_SYSCALL(getenv, "%S", "UMEMUSAGE"))
if (UServer_Base::budp == false &&
U_SYSCALL(getenv, "%S", "UMEMUSAGE"))
{
if (UServer_Base::preforked_num_kids) U_WARNING("UMEMUSAGE must be used with PREFORK_CHILD == 0");

View File

@ -17,6 +17,8 @@
#include <ulib/base/coder/gzio.h>
bool u_gz_deflate_header = true;
/**
* Synopsis: Compress and Decompresses the source buffer into the destination buffer
*
@ -38,13 +40,13 @@ static const char* get_error_string(int err)
switch (err)
{
case Z_ERRNO: p = "Error occured while reading file"; break;
case Z_STREAM_ERROR: p = "The stream state was inconsistent (e.g., next_in or next_out was NULL)"; break;
case Z_DATA_ERROR: p = "The deflate data was invalid or incomplete"; break;
case Z_MEM_ERROR: p = "Memory could not be allocated for processing"; break;
case Z_BUF_ERROR: p = "Ran out of output buffer for writing compressed bytes"; break;
case Z_VERSION_ERROR: p = "The version of zlib.h and the version of the library linked do not match"; break;
default: p = "Unknown error code."; break;
case Z_ERRNO: p = "Error occured while reading file"; break;
case Z_STREAM_ERROR: p = "The stream state was inconsistent (e.g., next_in or next_out was NULL)"; break;
case Z_DATA_ERROR: p = "The deflate data was invalid or incomplete"; break;
case Z_MEM_ERROR: p = "Memory could not be allocated for processing"; break;
case Z_BUF_ERROR: p = "Ran out of output buffer for writing compressed bytes"; break;
case Z_VERSION_ERROR: p = "The version of zlib.h and the version of the library linked do not match"; break;
default: p = "Unknown error code."; break;
}
return p;
@ -56,21 +58,21 @@ static int workspacesize = zlib_deflate_workspacesize();
static char workspace[workspacesize];
#endif
uint32_t u_gz_deflate(const char* restrict input, uint32_t len, char* restrict result, bool bheader)
uint32_t u_gz_deflate(const char* restrict input, uint32_t len, char* restrict result, int level)
{
int err;
z_stream stream;
/**
* stream.zalloc = // Set zalloc, zfree, and opaque to Z_NULL so
* stream.zfree = // that when we call deflateInit2 they will be
* stream.opaque = // updated to use default allocation functions.
* stream.total_out = // Total number of output bytes produced so far
* stream.next_in = // Pointer to input bytes
* stream.avail_in = // Number of input bytes left to process
* stream.zalloc // Set zalloc, zfree, and opaque to Z_NULL so
* stream.zfree // that when we call deflateInit2 they will be
* stream.opaque // updated to use default allocation functions.
* stream.total_out // Total number of output bytes produced so far
* stream.next_in // Pointer to input bytes
* stream.avail_in // Number of input bytes left to process
*/
U_INTERNAL_TRACE("u_gz_deflate(%p,%u,%p,%d)", input, len, result, bheader)
U_INTERNAL_TRACE("u_gz_deflate(%p,%u,%p,%d)", input, len, result, level)
U_INTERNAL_ASSERT_POINTER(input)
@ -103,7 +105,7 @@ uint32_t u_gz_deflate(const char* restrict input, uint32_t len, char* restrict r
* The parameters are as follows:
*
* z_streamp strm - Pointer to a zstream struct
* int level - Compression level. Must be Z_DEFAULT_COMPRESSION, or between 0 and 9:
* int level - Compression level. Must be Z_DEFAULT_COMPRESSION(-1), or between 0 and 9:
* 1 gives best speed, 9 gives best compression, 0 gives no compression.
*
* int method - Compression method. Only method supported is "Z_DEFLATED".
@ -127,7 +129,7 @@ uint32_t u_gz_deflate(const char* restrict input, uint32_t len, char* restrict r
* force Huffman encoding only (no string match)
*/
err = deflateInit2(&stream, Z_DEFAULT_COMPRESSION, Z_DEFLATED, (bheader ? MAX_WBITS+16 : -MAX_WBITS), MAX_MEM_LEVEL, Z_DEFAULT_STRATEGY);
err = deflateInit2(&stream, level, Z_DEFLATED, (u_gz_deflate_header ? MAX_WBITS+16 : -MAX_WBITS), MAX_MEM_LEVEL, Z_DEFAULT_STRATEGY);
if (err != Z_OK)
{
@ -199,7 +201,7 @@ uint32_t u_gz_deflate(const char* restrict input, uint32_t len, char* restrict r
U_INTERNAL_ASSERT_EQUALS(stream.total_in, len)
#ifdef DEBUG
if (bheader)
if (u_gz_deflate_header)
{
uint32_t size_original;
uint32_t* psize_original = (uint32_t*)(result + stream.total_out - 4);

View File

@ -70,6 +70,19 @@ HINSTANCE UDynamic::dload(const char* name, uint32_t name_len)
return dload(buffer);
}
void UDynamic::dclose(HINSTANCE handle)
{
U_TRACE(0, "UDynamic::dclose(%p)", handle)
U_INTERNAL_ASSERT_POINTER(handle)
#ifdef _MSWINDOWS_
::FreeLibrary(handle);
#else
(void) U_SYSCALL(dlclose, "%p", handle);
#endif
}
void* UDynamic::lookup(HINSTANCE handle, const char* sym)
{
U_TRACE(0, "UDynamic::lookup(%p,%S)", handle, sym)

View File

@ -483,7 +483,7 @@ void ULog::write(const struct iovec* iov, int n)
checkForLogRotateDataToWrite(); // check if there are previous data to write
# endif
ptr_log_data->gzip_len = u_gz_deflate(UFile::map, file_ptr, (char*)ptr_log_data+sizeof(log_data), true);
ptr_log_data->gzip_len = u_gz_deflate(UFile::map, file_ptr, (char*)ptr_log_data+sizeof(log_data), Z_DEFAULT_COMPRESSION);
U_INTERNAL_DUMP("u_gz_deflate(%u) = %u", file_ptr, ptr_log_data->gzip_len)
}
@ -491,7 +491,7 @@ void ULog::write(const struct iovec* iov, int n)
{
U_INTERNAL_ASSERT_EQUALS(ptr_log_data->gzip_len, 0)
UString data_to_write = UStringExt::deflate(UFile::map, file_ptr, 1);
UString data_to_write = UStringExt::deflate(UFile::map, file_ptr, 0);
char* ptr1 = buf_path_compress->c_pointer(index_path_compress);

View File

@ -656,6 +656,15 @@ const char* UClientImage_Base::getRequestUri(uint32_t& sz)
ptr = U_http_info.uri;
U_INTERNAL_DUMP("U_http_info.uri(%u) = %.*S", sz, sz, ptr)
#ifdef USERVER_UDP
if (sz == 0 &&
UServer_Base::budp)
{
sz = U_CONSTANT_SIZE("unknow");
ptr = "unknow";
}
#endif
}
return ptr;
@ -1070,10 +1079,6 @@ bool UClientImage_Base::genericRead()
U_INTERNAL_ASSERT_EQUALS(socket->iSockDesc, UEventFd::fd)
U_gettimeofday // NB: optimization if it is enough a time resolution of one second...
startRequest();
rstart = 0;
request->clear(); // reset buffer before read
@ -1094,6 +1099,25 @@ bool UClientImage_Base::genericRead()
socket->iState = USocket::CONNECT; // prepare socket before read
#ifdef USERVER_UDP
if (UServer_Base::budp)
{
uint32_t sz = rbuffer->size();
int iBytesTransferred = socket->recvFrom(rbuffer->data()+sz, rbuffer->capacity());
if (iBytesTransferred <= 0) U_RETURN(false);
rbuffer->size_adjust(sz+iBytesTransferred);
UServer_Base::setClientAddress();
# ifndef U_LOG_DISABLE
UServer_Base::logNewClient(socket, this);
# endif
}
else
#endif
{
if (USocketExt::read(socket, *rbuffer, U_SINGLE_READ, 0) == false) // NB: timeout == 0 means that we put the socket fd on epoll queue if EAGAIN...
{
U_ClientImage_state = (socket->isOpen() ? U_PLUGIN_HANDLER_AGAIN
@ -1101,6 +1125,7 @@ bool UClientImage_Base::genericRead()
U_RETURN(false);
}
}
if (data_pending)
{
@ -1119,6 +1144,10 @@ bool UClientImage_Base::genericRead()
data_pending = U_NULLPTR;
}
U_gettimeofday // NB: optimization if it is enough a time resolution of one second...
startRequest();
#ifdef U_SERVER_CHECK_TIME_BETWEEN_REQUEST
if (U_ClientImage_advise_for_parallelization)
{
@ -1146,6 +1175,9 @@ int UClientImage_Base::handlerRead() // Connection-wide hooks
int result;
uint32_t sz;
# ifdef USERVER_UDP
if (UServer_Base::budp == false)
# endif
prepareForRead();
start:
@ -1586,10 +1618,21 @@ bool UClientImage_Base::writeResponse()
{
U_INTERNAL_ASSERT_EQUALS(nrequest, 0)
U_SRV_LOG_WITH_ADDR("send response (%u bytes) %.*s%#.*S to", ncount, msg_len, "[pipeline] ", iov_vec[2].iov_len, iov_vec[2].iov_base);
# ifdef USERVER_UDP
if (UServer_Base::budp)
{
iBytesWrite = socket->sendTo(iov_vec[2].iov_base, iov_vec[2].iov_len);
if (iBytesWrite == (int)ncount) U_RETURN(true);
U_RETURN(false);
}
# endif
idx = 2;
iovcnt = 2;
U_SRV_LOG_WITH_ADDR("send response (%u bytes) %.*s%#.*S to", ncount, msg_len, "[pipeline] ", iov_vec[2].iov_len, iov_vec[2].iov_base);
}
else
{

View File

@ -440,7 +440,7 @@ void UNoCatPlugIn::setStatusContent(const UString& ap_label)
*status_content = buffer;
}
setHTTPResponse(*status_content, U_html);
UHTTP::setResponseMimeIndex(*status_content, U_html);
}
void UNoCatPlugIn::getTraffic()
@ -1809,7 +1809,7 @@ void UNoCatPlugIn::sendData(uint32_t index_AUTH, const UString& data, const char
UString body = data, url = getUrlForSendMsgToPortal(index_AUTH, service, service_len);
#ifdef USE_LIBZ
if (sz > U_MIN_SIZE_FOR_DEFLATE) body = UStringExt::deflate(data, 1);
if (sz > U_MIN_SIZE_FOR_DEFLATE) body = UStringExt::deflate(data, Z_DEFAULT_COMPRESSION);
#endif
#ifndef U_LOG_DISABLE
@ -1819,7 +1819,9 @@ void UNoCatPlugIn::sendData(uint32_t index_AUTH, const UString& data, const char
{
UString str = UStringExt::substitute(data.data(), U_min(sz,200), '%', U_CONSTANT_TO_PARAM("%%")); // NB: we need this because we have a message with url encoded char...
(void) u__snprintf(buffer, sizeof(buffer), U_CONSTANT_TO_PARAM("[nocat] Sent %.*s %%s (%u bytes) after %%d attempts to AUTH(%u): %V"), service_len, service, sz, index_AUTH, str.rep);
(void) u__snprintf(buffer, sizeof(buffer),
U_CONSTANT_TO_PARAM("[nocat] Sent %.*s %%s (%u bytes) after %%d attempts to AUTH(%u): %V"),
service_len, service, sz, index_AUTH, str.rep);
log_msg = buffer;
}
@ -1873,26 +1875,6 @@ void UNoCatPlugIn::notifyAuthOfUsersInfo(uint32_t index_AUTH)
UHTTP::setResponse();
}
void UNoCatPlugIn::setHTTPResponse(const UString& content, int mime_index)
{
U_TRACE(0, "UNoCatPlugIn::setHTTPResponse(%V%d)", content.rep, mime_index)
if (content.empty())
{
U_http_info.nResponseCode = HTTP_NO_CONTENT;
UHTTP::setResponse();
}
else
{
U_http_info.endHeader = 0;
U_http_info.nResponseCode = HTTP_OK;
*UClientImage_Base::wbuffer = content;
UHTTP::setDynamicResponse();
}
}
bool UNoCatPlugIn::getPeerFromMAC(const UString& mac)
{
U_TRACE(0, "UNoCatPlugIn::getPeerFromMAC(%V)", mac.rep)
@ -2472,7 +2454,7 @@ int UNoCatPlugIn::handlerRequest()
status_content->setFromNumber32(u_get_uptime());
setHTTPResponse(*status_content, U_unknow);
UHTTP::setResponseMimeIndex(*status_content, U_unknow);
}
else if (U_HTTP_URI_STREQ("/users"))
{
@ -2482,7 +2464,7 @@ int UNoCatPlugIn::handlerRequest()
peers->callForAllEntry(getPeerListInfo);
setHTTPResponse(*status_content, U_html);
UHTTP::setResponseMimeIndex(*status_content, U_html);
U_SRV_LOG("AUTH request to get list info on peers permitted");
}
@ -2637,7 +2619,7 @@ next: (void) getARPCache();
}
}
setHTTPResponse(*status_content, U_txt);
UHTTP::setResponseMimeIndex(*status_content, U_txt);
}
# endif
else
@ -2685,7 +2667,7 @@ next: (void) getARPCache();
/*
if (u_find(U_HTTP_USER_AGENT_TO_PARAM, U_CONSTANT_TO_PARAM("CaptiveNetworkSupport")) != 0)
{
setHTTPResponse(UString::str_IPHONE_SUCCESS, U_html);
UHTTP::setResponseMimeIndex(UString::str_IPHONE_SUCCESS, U_html);
goto end;
}
@ -2830,7 +2812,7 @@ set_redirect_to_AUTH:
(check_type & U_CHECK_MAC) != 0 && // not unifi (L2)
(peer->mac == *UString::str_without_mac || peer->mac.empty()))
{
mode = UHTTP::REFRESH | UHTTP::NO_BODY;
mode |= UHTTP::REFRESH;
(void) location->reserve(7 + U_http_host_len + U_http_info.uri_len + 1 + U_http_info.query_len);

View File

@ -205,51 +205,16 @@ int UProxyPlugIn::handlerRequest()
{
// NB: in this case we broke the transparency of the response to avoid a duplication of effort to read chunked data...
uint32_t sz, csz, ratio;
UString body = client_http->getContent();
UString body = client_http->getContent(),
content_type = client_http->getResponseHeader()->getContentType();
U_INTERNAL_ASSERT(body)
if (UHTTP::service->isReplaceResponse()) body = UHTTP::service->replaceResponse(body);
UString content_type = client_http->getResponseHeader()->getContentType();
content_type.rep->_length += 2; // NB: we add "\r\n"...
# if defined(USE_LIBZ) || defined(USE_LIBBROTLI)
if ((sz = body.size()) > U_MIN_SIZE_FOR_DEFLATE)
{
UString compressed;
U_INTERNAL_DUMP("U_http_is_accept_gzip = %b U_http_is_accept_brotli = %b", U_http_is_accept_gzip, U_http_is_accept_brotli)
# ifdef USE_LIBBROTLI
if (U_http_is_accept_brotli &&
(compressed = UStringExt::brotli(body, 6)))
{
goto next;
}
# endif
# ifdef USE_LIBZ
if (U_http_is_accept_gzip) compressed = UStringExt::deflate(body, 1);
# endif
next: csz = compressed.size(), ratio = (csz * 100U) / sz;
U_INTERNAL_DUMP("ratio = %u (%u%%)", ratio, 100-ratio)
// NB: we accept new data only if ratio compression is better than 15%...
if (ratio < 85)
{
body = compressed;
U_SRV_LOG("proxy response: %u bytes - (%u%%) compression ratio", csz, 100-ratio);
}
}
# endif
UHTTP::setResponse(true, content_type, &body);
UHTTP::setDynamicResponse(body, UString::getStringNull(), content_type);
}
}

View File

@ -98,7 +98,7 @@ int USoapPlugIn::handlerRequest()
U_http_info.nResponseCode = HTTP_OK;
UHTTP::setResponse(true, *UString::str_ctype_soap, &body);
UHTTP::setResponse(*UString::str_ctype_soap, &body);
}
U_RETURN(U_PLUGIN_HANDLER_PROCESSED);

View File

@ -91,7 +91,7 @@ void USSIPlugIn::setAlternativeRedirect(const char* fmt, ...)
UClientImage_Base::setCloseConnection();
UHTTP::setResponse(true, buffer, U_NULLPTR);
UHTTP::setResponse(buffer, U_NULLPTR);
}
void USSIPlugIn::setBadRequest()
@ -134,7 +134,7 @@ void USSIPlugIn::setAlternativeResponse(UString& _body)
{
U_http_info.nResponseCode = HTTP_OK;
UHTTP::setResponse(true, *(u_is_know(UHTTP::mime_index) ? UString::str_ctype_txt : UString::str_ctype_html), &_body);
UHTTP::setResponse(*(u_is_know(UHTTP::mime_index) ? UString::str_ctype_txt : UString::str_ctype_html), &_body);
}
}
@ -1057,7 +1057,9 @@ int USSIPlugIn::handlerRequest()
U_INTERNAL_DUMP("U_http_version = %C", U_http_version)
(void) header->append(UHTTP::getDataFromCache(UHTTP::file_data->array, 1)); // NB: after now 'file_data' can change...
// NB: after now 'file_data' can change...
(void) header->append(UHTTP::getDataFromCache(UHTTP::file_data->array, 1)); // NB: we must consider HTTP/2
*body = (UHTTP::isGETorHEAD() &&
*UClientImage_Base::body
@ -1073,37 +1075,8 @@ int USSIPlugIn::handlerRequest()
U_http_info.nResponseCode = HTTP_OK;
if (alternative_response == 0)
{
uint32_t size = output.size();
# if !defined(USE_LIBZ) && !defined(USE_LIBBROTLI)
bool bcompress = false;
# else
bool bcompress = UHTTP::checkForCompression(size);
# endif
if (bcompress == false) *UClientImage_Base::body = output;
else
{
UHTTP::setResponseCompressed(output);
size = UClientImage_Base::body->size();
}
(void) UHTTP::ext->append(*header);
if (bcache) (void) UHTTP::checkContentLength(size); // NB: adjusting the size of response...
else
{
UHTTP::mime_index = U_unknow;
(void) UHTTP::ext->append(UHTTP::getHeaderMimeType(U_NULLPTR, size, U_CTYPE_HTML));
}
UHTTP::handlerResponse();
}
else if (alternative_response > 1)
if (alternative_response == 0) UHTTP::setDynamicResponse(output, *header);
else if (alternative_response > 1)
{
// -----------------------------------------------------------------------------------------------------
// 1 => response already complete (nothing to do)

View File

@ -188,7 +188,7 @@ int UStreamPlugIn::handlerRequest()
U_http_info.nResponseCode = HTTP_OK;
UHTTP::setResponse(true, *content_type, U_NULLPTR);
UHTTP::setResponse(*content_type, U_NULLPTR);
UClientImage_Base::setCloseConnection();

View File

@ -97,7 +97,7 @@ int UTsaPlugIn::handlerRequest()
{
U_http_info.nResponseCode = HTTP_OK;
UHTTP::setResponse(true, *UString::str_ctype_tsa, &body);
UHTTP::setResponse(*UString::str_ctype_tsa, &body);
}
# ifndef U_LOG_DISABLE

View File

@ -0,0 +1,4 @@
<!--#
general manager for udp servder
-->
Hello, World!

File diff suppressed because it is too large Load Diff

View File

@ -52,11 +52,9 @@ void USocket::setAddress(void* address)
{
U_TRACE(0, "USocket::setAddress(%p)", address)
U_INTERNAL_ASSERT_POINTER(cLocal)
cLocalAddress.setAddress(address, (bool)U_socket_IPv6(this));
cLocal->setIPAddress(cLocalAddress);
if (cLocal) cLocal->setIPAddress(cLocalAddress);
U_socket_LocalSet(this) = true;
}
@ -184,20 +182,34 @@ bool USocket::checkTime(long time_limit, long& timeout)
U_RETURN(true);
}
void USocket::setLocalInfo(USocket* p, SocketAddress* cLocal)
{
U_TRACE(0, "USocket::setLocalInfo(%p,%p)", p, cLocal)
p->iLocalPort = cLocal->getPortNumber();
cLocal->getIPAddress(p->cLocalAddress);
}
void USocket::setRemoteInfo(USocket* p, SocketAddress* cRemote)
{
U_TRACE(0, "USocket::setRemoteInfo(%p,%p)", p, cRemote)
p->iRemotePort = cRemote->getPortNumber();
cRemote->getIPAddress(p->cRemoteAddress);
}
void USocket::setLocal()
{
U_TRACE_NO_PARAM(1, "USocket::setLocal()")
U_CHECK_MEMORY
SocketAddress tmp;
SocketAddress cLocal;
socklen_t slDummy = cLocal.sizeOf();
socklen_t slDummy = tmp.sizeOf();
if (U_SYSCALL(getsockname, "%d,%p,%p", getFd(), (sockaddr*)tmp, &slDummy) == 0)
if (U_SYSCALL(getsockname, "%d,%p,%p", getFd(), (sockaddr*)cLocal, &slDummy) == 0)
{
iLocalPort = tmp.getPortNumber();
tmp.getIPAddress(cLocalAddress);
setLocalInfo(this, &cLocal);
U_socket_LocalSet(this) = true;
}
@ -406,6 +418,8 @@ bool USocket::setServer(unsigned int port, void* localAddress)
if (isUDP())
{
U_INTERNAL_ASSERT_POINTER(localAddress)
((uusockaddr*)localAddress)->psaIP4Addr.sin_port = htons(port);
if (U_SYSCALL(bind, "%d,%p,%d", iSockDesc, &(((uusockaddr*)localAddress)->psaGeneric), sizeof(uusockaddr)) == 0)
@ -560,14 +574,9 @@ void USocket::setRemote()
U_INTERNAL_ASSERT(isOpen())
SocketAddress cRemote;
socklen_t slDummy = cRemote.sizeOf();
if (U_SYSCALL(getpeername, "%d,%p,%p", getFd(), (sockaddr*)cRemote, &slDummy) == 0)
{
iRemotePort = cRemote.getPortNumber();
cRemote.getIPAddress(cRemoteAddress);
}
if (U_SYSCALL(getpeername, "%d,%p,%p", getFd(), (sockaddr*)cRemote, &slDummy) == 0) setRemoteInfo(this, &cRemote);
}
bool USocket::connect()
@ -627,15 +636,13 @@ int USocket::recvFrom(void* pBuffer, uint32_t iBufLength, uint32_t uiFlags, UIPA
int iBytesRead;
SocketAddress cSource;
socklen_t slDummy = cSource.sizeOf();
loop:
iBytesRead = U_SYSCALL(recvfrom, "%d,%p,%u,%u,%p,%p", getFd(), CAST(pBuffer), iBufLength, uiFlags, (sockaddr*)cSource, &slDummy);
if (iBytesRead > 0)
{
U_INTERNAL_DUMP("BytesRead(%d) = %#.*S", iBytesRead, iBytesRead, CAST(pBuffer))
U_INTERNAL_DUMP("BytesRead(%u) = %#.*S", iBytesRead, iBytesRead, CAST(pBuffer))
iSourcePortNumber = cSource.getPortNumber();
cSource.getIPAddress(cSourceIP);
@ -643,12 +650,7 @@ loop:
U_RETURN(iBytesRead);
}
if (errno == EINTR)
{
UInterrupt::checkForEventSignalPending();
goto loop;
}
if (errno == EINTR) UInterrupt::checkForEventSignalPending(); // NB: we never restart recvfrom(), in general the socket server is NOT blocking...
U_RETURN(-1);
}
@ -672,7 +674,7 @@ loop:
if (iBytesWrite > 0)
{
U_INTERNAL_DUMP("BytesWrite(%d) = %#.*S", iBytesWrite, iBytesWrite, CAST(pPayload))
U_INTERNAL_DUMP("BytesWrite(%u) = %#.*S", iBytesWrite, iBytesWrite, CAST(pPayload))
U_RETURN(iBytesWrite);
}
@ -896,7 +898,6 @@ bool USocket::acceptClient(USocket* pcNewConnection)
U_INTERNAL_ASSERT_POINTER(pcNewConnection)
SocketAddress cRemote;
socklen_t slDummy = cRemote.sizeOf();
#ifdef HAVE_ACCEPT4
@ -917,8 +918,7 @@ bool USocket::acceptClient(USocket* pcNewConnection)
{
pcNewConnection->iState = CONNECT;
pcNewConnection->iRemotePort = cRemote.getPortNumber();
cRemote.getIPAddress( pcNewConnection->cRemoteAddress);
setRemoteInfo(pcNewConnection, &cRemote);
U_INTERNAL_DUMP("pcNewConnection->iSockDesc = %d pcNewConnection->flags = %d %B",
pcNewConnection->iSockDesc, pcNewConnection->flags, pcNewConnection->flags)

View File

@ -1212,11 +1212,7 @@ void UString::moveToBeginDataInBuffer(uint32_t n)
rep->_length -= n;
#ifdef U_APEX_ENABLE
(void) U_SYSCALL(apex_memmove, "%p,%p,%u", (void*)rep->str, rep->str + n, rep->_length);
#else
(void) U_SYSCALL( memmove, "%p,%p,%u", (void*)rep->str, rep->str + n, rep->_length);
#endif
(void) U_SYSCALL(memmove, "%p,%p,%u", (void*)rep->str, rep->str + n, rep->_length);
U_INTERNAL_ASSERT(invariant())
}

View File

@ -3813,8 +3813,6 @@ void UHTTP2::sendGoAway(USocket* psocket)
{
psocket->close();
UClientImage_Base::setRequestProcessed();
UClientImage_Base::resetPipelineAndSetCloseConnection();
}
}

View File

@ -1234,6 +1234,9 @@ UString UStringExt::decompress(const char* s, uint32_t n)
U_RETURN_STRING(out);
}
uint32_t UStringExt::ratio;
uint32_t UStringExt::ratio_threshold = 90; // NB: we accept compressed data only if ratio compression is better than 10%...
#ifdef USE_LIBBROTLI
UString UStringExt::brotli(const char* s, uint32_t len, uint32_t quality, uint32_t mode, uint32_t lgwin) // .br compress
{
@ -1248,9 +1251,17 @@ UString UStringExt::brotli(const char* s, uint32_t len, uint32_t quality, uint32
{
rc = U_SYSCALL(BrotliEncoderCompress, "%u,%u,%u,%u,%p,%p,%p", quality, lgwin, (BrotliEncoderMode)mode, (size_t)len, (uint8_t*)s, &sz, (uint8_t*)UFile::pfree);
U_INTERNAL_DUMP("BrotliEncoderCompress() = %d (%u => %u)", rc, len, sz)
ratio = (sz * 100U) / len;
if (rc == 0) return UString::getStringNull();
U_INTERNAL_DUMP("BrotliEncoderCompress() = %d ratio = %u (%u%%)", rc, ratio, 100-ratio)
if (rc == 0 ||
ratio > ratio_threshold)
{
return UString::getStringNull();
}
U_INTERNAL_DUMP("BrotliEncoderCompress() = %#.4S", UFile::pfree)
len = UFile::getSizeAligned(sz);
@ -1259,6 +1270,8 @@ UString UStringExt::brotli(const char* s, uint32_t len, uint32_t quality, uint32
UFile::pfree += len;
UFile::nfree -= len;
// U_INTERNAL_ASSERT(isBrotli(result)) // check magic byte
U_RETURN_STRING(result);
}
@ -1266,19 +1279,31 @@ UString UStringExt::brotli(const char* s, uint32_t len, uint32_t quality, uint32
rc = U_SYSCALL(BrotliEncoderCompress, "%u,%u,%u,%u,%p,%p,%p", quality, lgwin, (BrotliEncoderMode)mode, (size_t)len, (uint8_t*)s, &sz, (uint8_t*)r.data());
U_INTERNAL_DUMP("BrotliEncoderCompress() = %d (%u => %u)", rc, len, sz)
ratio = (sz * 100U) / len;
if (rc == 0) return UString::getStringNull();
U_INTERNAL_DUMP("BrotliEncoderCompress() = %d ratio = %u (%u%%)", rc, ratio, 100-ratio)
if (rc == 0 ||
ratio > ratio_threshold)
{
return UString::getStringNull();
}
U_INTERNAL_DUMP("BrotliEncoderCompress() = %#.4S", r.data())
r.rep->_length = sz;
// U_INTERNAL_ASSERT(isBrotli(r)) // check magic byte
U_RETURN_STRING(r);
}
#endif
UString UStringExt::unbrotli(const char* ptr, uint32_t sz) // .br uncompress
{
U_TRACE(0, "UStringExt::unbrotli(%.*S,%u)", sz, ptr, sz)
#ifdef USE_LIBBROTLI
UString r(sz);
const uint8_t* next_out;
BrotliDecoderResult result;
@ -1308,16 +1333,15 @@ UString UStringExt::unbrotli(const char* ptr, uint32_t sz) // .br uncompress
U_SYSCALL_VOID(BrotliDecoderDestroyInstance, "%p", state);
U_RETURN_STRING(r);
}
#endif
UString UStringExt::deflate(const char* s, uint32_t len, int type) // .gz compress
{
U_TRACE(1, "UStringExt::deflate(%.*S,%u,%d)", len, s, len, type)
#ifndef USE_LIBZ
#else
return UString::getStringNull();
#endif
}
#ifdef USE_LIBZ
UString UStringExt::deflate(const char* s, uint32_t len, uint32_t quality) // .gz compress
{
U_TRACE(1, "UStringExt::deflate(%.*S,%u,%u)", len, s, len, quality)
// The zlib documentation states that destination buffer size must be at least 0.1% larger than avail_in plus 12 bytes
@ -1326,17 +1350,7 @@ UString UStringExt::deflate(const char* s, uint32_t len, int type) // .gz compre
if (UFile::isAllocableFromPool(sz))
{
# ifdef USE_LIBZOPFLI
if (type <= 1)
# endif
{
# ifdef USE_LIBZ
len = u_gz_deflate(s, len, UFile::pfree, type);
# endif
U_INTERNAL_DUMP("u_gz_deflate() = %u", len)
}
# ifdef USE_LIBZOPFLI
else
if (quality == 0)
{
size_t outsize = 0;
ZopfliOptions options;
@ -1346,54 +1360,68 @@ UString UStringExt::deflate(const char* s, uint32_t len, int type) // .gz compre
U_SYSCALL_VOID(ZopfliCompress, "%p,%d,%p,%u,%p,%p", &options, ZOPFLI_FORMAT_GZIP, (unsigned char*)s, (size_t)len, &out, &outsize);
U_INTERNAL_DUMP("ZopfliCompress(%u) = %u", len, outsize)
ratio = (outsize * 100U) / len;
len = outsize;
U_INTERNAL_DUMP("ZopfliCompress(%u) = %u ratio = %u (%u%%)", len, outsize, ratio, 100-ratio)
U_MEMCPY(UFile::pfree, out, len);
if (ratio > ratio_threshold) return UString::getStringNull();
U_MEMCPY(UFile::pfree, out, sz = outsize);
U_SYSCALL_VOID(free, "%p", out);
}
else
# endif
{
sz = u_gz_deflate(s, len, UFile::pfree, (quality ? quality : Z_BEST_COMPRESSION));
sz = UFile::getSizeAligned(len);
ratio = (sz * 100U) / len;
UString result(len, sz, UFile::pfree);
U_INTERNAL_DUMP("u_gz_deflate(%u) = %u ratio = %u (%u%%)", len, sz, ratio, 100-ratio)
UFile::pfree += sz;
UFile::nfree -= sz;
if (ratio > ratio_threshold) return UString::getStringNull();
}
UString result(sz, len = UFile::getSizeAligned(sz), UFile::pfree);
UFile::pfree += len;
UFile::nfree -= len;
U_INTERNAL_ASSERT(isGzip(result)) // check magic byte
U_RETURN_STRING(result);
}
UString r(sz);
#ifdef USE_LIBZ
r.rep->_length = u_gz_deflate(s, len, r.rep->data(), (type ? true : false));
#endif
r.rep->_length = u_gz_deflate(s, len, r.rep->data(), (quality ? quality : Z_BEST_COMPRESSION));
U_INTERNAL_DUMP("u_gz_deflate(%u) = %u", len, r.size())
ratio = (r.rep->_length * 100U) / len;
U_INTERNAL_DUMP("u_gz_deflate(%u) = %u ratio = %u (%u%%)", len, r.rep->_length, ratio, 100-ratio)
if (ratio > ratio_threshold) return UString::getStringNull();
#ifdef DEBUG
if (type)
{
uint32_t* psize_original = (uint32_t*)r.c_pointer(r.size() - 4);
uint32_t* psize_original = (uint32_t*)r.c_pointer(r.size() - 4);
# if __BYTE_ORDER == __LITTLE_ENDIAN
U_INTERNAL_DUMP("size original = %u (LE)", *psize_original)
U_INTERNAL_DUMP("size original = %u (LE)", *psize_original)
# else
U_INTERNAL_DUMP("size original = %u (BE)", u_invert32(*psize_original))
U_INTERNAL_DUMP("size original = %u (BE)", u_invert32(*psize_original))
# endif
}
#endif
U_INTERNAL_ASSERT(isGzip(r)) // check magic byte
U_RETURN_STRING(r);
}
#endif
UString UStringExt::gunzip(const char* ptr, uint32_t sz, uint32_t space) // .gz uncompress
{
U_TRACE(0, "UStringExt::gunzip(%.*S,%u,%u)", sz, ptr, sz, space)
#ifdef USE_LIBZ
if (space == 0)
{
if (isGzip(ptr)) // check magic byte
@ -1412,7 +1440,6 @@ UString UStringExt::gunzip(const char* ptr, uint32_t sz, uint32_t space) // .gz
if (space == 0) space = sz * 4;
}
#ifdef USE_LIBZ // decompress with zlib
UString result(space);
result.rep->_length = u_gz_inflate(ptr, sz, result.rep->data());

View File

@ -111,6 +111,7 @@ uint32_t UHTTP::limit_request_body = U_STRING_MAX_SIZE;
uint32_t UHTTP::request_read_timeout;
// https://www.google.com/url?q=https%3A%2F%2Fblogs.akamai.com%2F2016%2F02%2Funderstanding-brotlis-potential.html&sa=D&sntz=1&usg=AFQjCNGP4Nu9yPm65RKkAThsWxJ8qy49Sw
uint32_t UHTTP::gzip_level_for_dynamic_content = 3;
uint32_t UHTTP::brotli_level_for_dynamic_content = 2;
UCommand* UHTTP::pcmd;
@ -1554,9 +1555,7 @@ __pure bool UHTTP::isMobile()
}
/**
* HTTP message
* ---------------------------------------------------------------------------------------------------------------------------
* There are four parts to an HTTP request:
* HTTP message: there are four parts to an HTTP request:
* ---------------------------------------------------------------------------------------------------------------------------
* 1) the request line [REQUIRED]: the method, the URL, the version of the protocol
* 2) the request headers [OPTIONAL]: a series of lines (one per) in the format of name, colon(:), and the value of the header
@ -2101,7 +2100,7 @@ bool UHTTP::checkContentLength(const UString& response)
U_INTERNAL_DUMP("U_http_info.clength = %u U_http_data_chunked = %b", U_http_info.clength, U_http_data_chunked)
// check for double content-length
// check for duolicate content-length header
pos = response.distance(s);
@ -4809,43 +4808,90 @@ U_NO_EXPORT inline void UHTTP::resetFileCache()
file_data->fd = -1;
}
U_NO_EXPORT void UHTTP::setResponseCompressed(const UString& data)
#if defined(USE_LIBZ) || defined(USE_LIBBROTLI)
U_NO_EXPORT inline bool UHTTP::compress(const UString& body)
{
U_TRACE(0, "UHTTP::setResponseCompressed(%V)", data.rep)
U_TRACE(0, "UHTTP::compress(%V)", body.rep)
ext->setBuffer(U_CAPACITY);
U_INTERNAL_DUMP("U_http_is_accept_gzip = %b U_http_is_accept_brotli = %b", U_http_is_accept_gzip, U_http_is_accept_brotli)
char* ptr = ext->data();
#ifdef USE_LIBBROTLI
if (U_http_is_accept_brotli &&
(*UClientImage_Base::body = UStringExt::brotli(data, brotli_level_for_dynamic_content)))
(*UClientImage_Base::body = UStringExt::brotli(body, (U_PARALLELIZATION_CHILD ? BROTLI_MAX_QUALITY : brotli_level_for_dynamic_content))))
{
# ifndef U_CACHE_REQUEST_DISABLE
is_response_compressed = 2; // brotli
# endif
(void) ext->append(U_CONSTANT_TO_PARAM("Content-Encoding: br\r\n"));
u_put_unalignedp64(ptr, U_MULTICHAR_CONSTANT64('C','o','n','t','e','n','t','-'));
u_put_unalignedp64(ptr+8, U_MULTICHAR_CONSTANT64('E','n','c','o','d','i','n','g'));
u_put_unalignedp32(ptr+16, U_MULTICHAR_CONSTANT32(':',' ','b','r'));
u_put_unalignedp16(ptr+20, U_MULTICHAR_CONSTANT16('\r','\n'));
return;
ext->rep->_length = U_CONSTANT_SIZE("Content-Encoding: br\r\n");
U_SRV_LOG("dynamic response: %u bytes - (%u%%) brotli compression ratio", UClientImage_Base::body->size(), 100-UStringExt::ratio);
U_RETURN(true);
}
#endif
#ifdef USE_LIBZ
if (U_http_is_accept_gzip &&
(*UClientImage_Base::body = UStringExt::deflate(data, 1)))
(*UClientImage_Base::body = UStringExt::deflate(body, (U_PARALLELIZATION_CHILD ? 0 : gzip_level_for_dynamic_content))))
{
# ifndef U_CACHE_REQUEST_DISABLE
is_response_compressed = 1; // gzip
# endif
(void) ext->append(U_CONSTANT_TO_PARAM("Content-Encoding: gzip\r\n"));
u_put_unalignedp64(ptr, U_MULTICHAR_CONSTANT64('C','o','n','t','e','n','t','-'));
u_put_unalignedp64(ptr+8, U_MULTICHAR_CONSTANT64('E','n','c','o','d','i','n','g'));
u_put_unalignedp64(ptr+16, U_MULTICHAR_CONSTANT64(':',' ','g','z','i','p','\r','\n'));
return;
ext->rep->_length = U_CONSTANT_SIZE("Content-Encoding: gzip\r\n");
U_SRV_LOG("dynamic response: %u bytes - (%u%%) gzip compression ratio", UClientImage_Base::body->size(), 100-UStringExt::ratio);
U_RETURN(true);
}
# endif
#endif
*UClientImage_Base::body = data;
U_RETURN(false);
}
#endif
void UHTTP::setDynamicResponse(const UString& body, const UString& header, const UString& content_type)
{
U_TRACE(0, "UHTTP::setDynamicResponse(%V,%V,%V)", body.rep, header.rep, content_type.rep)
ext->setBuffer(U_CAPACITY);
#if defined(USE_LIBZ) || defined(USE_LIBBROTLI)
if (checkForCompression(body.size()) == false ||
compress(body) == false)
#endif
{
*UClientImage_Base::body = body;
}
if (header)
{
(void) ext->append(header);
(void) checkContentLength(UClientImage_Base::body->size()); // NB: adjusting the size of response...
}
else
{
if (content_type) setContentResponse(content_type);
else
{
mime_index = U_unknow;
(void) ext->append(getHeaderMimeType(U_NULLPTR, UClientImage_Base::body->size(), U_CTYPE_HTML));
}
}
handlerResponse();
}
void UHTTP::processRequest()
@ -5065,13 +5111,9 @@ void UHTTP::processRequest()
{
// check if it's OK to do directory listing via authentication (digest|basic)
if (processAuthorization() == false) return;
if (processAuthorization()) setDynamicResponse(getHTMLDirectoryList());
setResponseCompressed(getHTMLDirectoryList());
mime_index = U_unknow;
(void) ext->append(getHeaderMimeType(U_NULLPTR, UClientImage_Base::body->size(), U_CTYPE_HTML));
return;
}
goto end;
@ -6685,79 +6727,122 @@ void UHTTP::handlerResponse()
U_INTERNAL_DUMP("UClientImage_Base::body(%u) = %V", UClientImage_Base::body->size(), UClientImage_Base::body->rep)
}
void UHTTP::setResponse(bool btype, const UString& content_type, UString* pbody)
void UHTTP::setResponseMimeIndex(const UString& content, int mime_idx)
{
U_TRACE(0, "UHTTP::setResponse(%b,%V,%p)", btype, content_type.rep, pbody)
U_TRACE(0, "UHTTP::setResponseMimeIndex(%V,%d)", content.rep, mime_idx)
U_INTERNAL_ASSERT_POINTER(UClientImage_Base::body)
U_INTERNAL_ASSERT_MAJOR(U_http_info.nResponseCode, 0)
if (content.empty())
{
U_http_info.nResponseCode = HTTP_NO_CONTENT;
setResponse();
return;
}
U_INTERNAL_ASSERT_EQUALS(U_http_info.nResponseCode, HTTP_OK)
U_http_info.endHeader = 0;
*UClientImage_Base::wbuffer = content;
setDynamicResponse();
}
U_NO_EXPORT void UHTTP::setContentResponse(const UString& content_type)
{
U_TRACE(0, "UHTTP::setContentResponse(%V)", content_type.rep)
U_INTERNAL_ASSERT(u_endsWith(U_STRING_TO_PARAM(content_type), U_CONSTANT_TO_PARAM(U_CRLF)))
ext->setBuffer(U_CAPACITY);
char* ptr = ext->pend();
u_put_unalignedp64(ptr, U_MULTICHAR_CONSTANT64('C','o','n','t','e','n','t','-'));
u_put_unalignedp32(ptr+8, U_MULTICHAR_CONSTANT32('T','y','p','e'));
u_put_unalignedp16(ptr+12, U_MULTICHAR_CONSTANT16(':',' '));
ptr += U_CONSTANT_SIZE("Content-Type: ");
char* start = ext->data();
char* ptr = start;
uint32_t sz = content_type.size();
U_INTERNAL_ASSERT_RANGE(1,sz,U_CAPACITY)
if (btype)
{
u_put_unalignedp64(ptr, U_MULTICHAR_CONSTANT64('C','o','n','t','e','n','t','-'));
u_put_unalignedp32(ptr+8, U_MULTICHAR_CONSTANT32('T','y','p','e'));
u_put_unalignedp16(ptr+12, U_MULTICHAR_CONSTANT16(':',' '));
ptr += U_CONSTANT_SIZE("Content-Type: ");
}
U_MEMCPY(ptr, content_type.data(), sz);
ptr += sz;
ptr += sz;
u_put_unalignedp64(ptr, U_MULTICHAR_CONSTANT64('C','o','n','t','e','n','t','-'));
u_put_unalignedp64(ptr+8, U_MULTICHAR_CONSTANT64('L','e','n','g','t','h',':',' '));
ptr += U_CONSTANT_SIZE("Content-Length: ");
ptr = u_num2str32(UClientImage_Base::body->size(), ptr + U_CONSTANT_SIZE("Content-Length: "));
u_put_unalignedp32(ptr, U_MULTICHAR_CONSTANT32('\r','\n','\r','\n'));
ext->size_adjust(ptr + U_CONSTANT_SIZE(U_CRLF2));
}
void UHTTP::setResponse(const UString& content_type, UString* pbody)
{
U_TRACE(0, "UHTTP::setResponse(%V,%p)", content_type.rep, pbody)
U_INTERNAL_ASSERT_MAJOR(U_http_info.nResponseCode, 0)
ext->setBuffer(U_CAPACITY);
if (pbody == U_NULLPTR)
{
*ptr++ = '0';
UClientImage_Base::body->clear(); // clean body to avoid writev() in response...
goto end;
}
#ifdef USE_LIBZ
if (UStringExt::isGzip(*pbody))
{
if (U_http_is_accept_gzip == false) *pbody = UStringExt::gunzip(*pbody);
ptr = u_num2str32(pbody->size(), ptr);
if (U_http_is_accept_gzip)
{
u_put_unalignedp64(ptr, U_MULTICHAR_CONSTANT64('\r','\n','C','o','n','t','e','n'));
u_put_unalignedp64(ptr+8, U_MULTICHAR_CONSTANT64('t', '-','E','n','c','o','d','i'));
u_put_unalignedp64(ptr+16, U_MULTICHAR_CONSTANT64('n', 'g',':',' ','g','z','i','p'));
ptr += U_CONSTANT_SIZE("\r\nContent-Encoding: gzip");
}
pbody = UClientImage_Base::body;
}
else
{
# ifdef USE_LIBBROTLI
if (UStringExt::isBrotli(*pbody))
{
if (U_http_is_accept_brotli == false) *UClientImage_Base::body = UStringExt::unbrotli(*pbody);
else
{
char* ptr = ext->data();
u_put_unalignedp64(ptr, U_MULTICHAR_CONSTANT64('C','o','n','t','e','n','t','-'));
u_put_unalignedp64(ptr+8, U_MULTICHAR_CONSTANT64('E','n','c','o','d','i','n','g'));
u_put_unalignedp32(ptr+16, U_MULTICHAR_CONSTANT32(':',' ','b','r'));
u_put_unalignedp16(ptr+20, U_MULTICHAR_CONSTANT16('\r','\n'));
ext->rep->_length = U_CONSTANT_SIZE("Content-Encoding: br\r\n");
*UClientImage_Base::body = *pbody;
}
goto next;
}
# endif
# ifdef USE_LIBZ
if (UStringExt::isGzip(*pbody))
{
if (U_http_is_accept_gzip == false) *UClientImage_Base::body = UStringExt::gunzip(*pbody);
else
{
char* ptr = ext->data();
u_put_unalignedp64(ptr, U_MULTICHAR_CONSTANT64('C','o','n','t','e','n','t','-'));
u_put_unalignedp64(ptr+8, U_MULTICHAR_CONSTANT64('E','n','c','o','d','i','n','g'));
u_put_unalignedp64(ptr+16, U_MULTICHAR_CONSTANT64(':',' ','g','z','i','p','\r','\n'));
ext->rep->_length = U_CONSTANT_SIZE("Content-Encoding: gzip\r\n");
*UClientImage_Base::body = *pbody;
}
goto next;
}
# endif
*UClientImage_Base::body = *pbody;
}
#if defined(USE_LIBBROTLI) || defined(USE_LIBZ)
next:
#endif
{
ptr = u_num2str32(pbody->size(), ptr);
}
*UClientImage_Base::body = *pbody;
end:
u_put_unalignedp32(ptr, U_MULTICHAR_CONSTANT32('\r','\n','\r','\n'));
ptr += U_CONSTANT_SIZE(U_CRLF2);
ext->size_adjust(ptr - start);
setContentResponse(content_type);
handlerResponse();
}
@ -6838,35 +6923,54 @@ void UHTTP::setRedirectResponse(int mode, const char* ptr_location, uint32_t len
# endif
}
if ((mode & NO_BODY) != 0) setResponse(false, tmp, U_NULLPTR);
if ((mode & NO_BODY) != 0)
{
ext->setBuffer(U_CAPACITY);
UClientImage_Base::body->clear(); // clean body to avoid writev() in response...
char* ptr = ext->data();
uint32_t sz = tmp.size();
U_MEMCPY(ptr, tmp.data(), sz);
ptr += sz;
u_put_unalignedp64(ptr, U_MULTICHAR_CONSTANT64('C','o','n','t','e','n','t','-'));
u_put_unalignedp64(ptr+8, U_MULTICHAR_CONSTANT64('L','e','n','g','t','h',':',' '));
u_put_unalignedp64(ptr+16, U_MULTICHAR_CONSTANT64('0','\r','\n','\r','\n','\0','\0','\0'));
ext->size_adjust(ptr + U_CONSTANT_SIZE("Content-Length: 0\r\n\r\n"));
handlerResponse();
return;
}
char msg[4096];
uint32_t sz, len;
if ((mode & NETWORK_AUTHENTICATION_REQUIRED) != 0)
{
len = u__snprintf(msg, sizeof(msg), U_CONSTANT_TO_PARAM("You need to <a href=\"%.*s\">authenticate with the local network</a> in order to get access"),
len_location, ptr_location);
}
else
{
char msg[4096];
uint32_t sz, len;
if ((mode & NETWORK_AUTHENTICATION_REQUIRED) != 0)
{
len = u__snprintf(msg, sizeof(msg), U_CONSTANT_TO_PARAM("You need to <a href=\"%.*s\">authenticate with the local network</a> in order to get access"),
len_location, ptr_location);
}
else
{
len = u__snprintf(msg, sizeof(msg), U_CONSTANT_TO_PARAM("The document has moved <a href=\"%.*s\">here</a>"), len_location, ptr_location);
}
const char* status = getStatusDescription(&sz);
UString body(500U + len_location), content_type(U_CAPACITY);
body.snprintf(U_CONSTANT_TO_PARAM(U_STR_FMR_BODY),
U_http_info.nResponseCode, sz, status,
sz, status,
len, msg);
(void) content_type.assign(U_CONSTANT_TO_PARAM(U_CTYPE_HTML "\r\n"));
(void) content_type.append(tmp);
setResponse(true, content_type, &body);
len = u__snprintf(msg, sizeof(msg), U_CONSTANT_TO_PARAM("The document has moved <a href=\"%.*s\">here</a>"), len_location, ptr_location);
}
const char* status = getStatusDescription(&sz);
UString body(500U + len_location), content_type(U_CAPACITY);
body.snprintf(U_CONSTANT_TO_PARAM(U_STR_FMR_BODY),
U_http_info.nResponseCode, sz, status,
sz, status,
len, msg);
(void) content_type.assign(U_CONSTANT_TO_PARAM(U_CTYPE_HTML "\r\n"));
(void) content_type.append(tmp);
setResponse(content_type, &body);
}
void UHTTP::setErrorResponse(const UString& content_type, int code, const char* fmt, uint32_t fmt_size, bool bformat)
@ -6928,7 +7032,7 @@ void UHTTP::setErrorResponse(const UString& content_type, int code, const char*
}
}
setResponse(true, content_type, &body);
setResponse(content_type, &body);
}
void UHTTP::setUnAuthorized()
@ -6966,10 +7070,9 @@ void UHTTP::setDynamicResponse()
U_INTERNAL_ASSERT_MAJOR(U_http_info.nResponseCode, 0)
char* ptr1;
UString compressed;
char* ptr;
const char* pEndHeader;
uint32_t sz = 0, csz, ratio, clength = UClientImage_Base::wbuffer->size();
uint32_t clength = UClientImage_Base::wbuffer->size();
#if !defined(USE_LIBZ) && !defined(USE_LIBBROTLI)
bool bcompress = false;
@ -6979,111 +7082,21 @@ void UHTTP::setDynamicResponse()
ext->setBuffer(U_CAPACITY);
char* ptr = ext->data();
if (U_http_info.endHeader)
{
U_INTERNAL_ASSERT(clength >= U_http_info.endHeader)
clength -= U_http_info.endHeader;
if (clength == 0) // no response
{
UClientImage_Base::body->clear(); // clean body to avoid writev() in response...
UClientImage_Base::wbuffer->clear();
goto no_response;
}
if (clength == 0) goto no_response;
pEndHeader = UClientImage_Base::wbuffer->data();
if (bcompress == false) goto no_compress;
}
else
{
pEndHeader = U_NULLPTR;
if (bcompress == false)
{
*UClientImage_Base::body = *UClientImage_Base::wbuffer;
if (clength == 0) goto no_response;
goto end;
}
}
#ifdef USE_LIBBROTLI
if (U_http_is_accept_brotli &&
(compressed = UStringExt::brotli(UClientImage_Base::wbuffer->c_pointer(U_http_info.endHeader), clength, brotli_level_for_dynamic_content)))
{
bcompress = false;
goto next;
}
#endif
#ifdef USE_LIBZ
if (U_http_is_accept_gzip) compressed = UStringExt::deflate(UClientImage_Base::wbuffer->c_pointer(U_http_info.endHeader), clength, 1);
#endif
#ifdef USE_LIBBROTLI
next:
#endif
csz = compressed.size(), ratio = (csz * 100U) / clength;
U_INTERNAL_DUMP("ratio = %u (%u%%)", ratio, 100-ratio)
// NB: we accept new data only if ratio compression is better than 15%...
if (ratio < 85)
{
clength = csz;
*UClientImage_Base::body = compressed;
U_SRV_LOG("cgi response: %u bytes - (%u%%) compression ratio", csz, 100-ratio);
# ifdef USE_LIBBROTLI
if (bcompress == false)
{
U_INTERNAL_ASSERT(U_http_is_accept_brotli)
sz = U_CONSTANT_SIZE("Content-Encoding: br\r\n");
u_put_unalignedp64(ptr, U_MULTICHAR_CONSTANT64('C','o','n','t','e','n','t','-'));
u_put_unalignedp64(ptr+8, U_MULTICHAR_CONSTANT64('E','n','c','o','d','i','n','g'));
u_put_unalignedp32(ptr+16, U_MULTICHAR_CONSTANT32(':',' ','b','r'));
u_put_unalignedp16(ptr+20, U_MULTICHAR_CONSTANT16('\r','\n'));
goto end;
}
# endif
# ifdef USE_LIBZ
U_INTERNAL_ASSERT(U_http_is_accept_gzip)
sz = U_CONSTANT_SIZE("Content-Encoding: gzip\r\n");
u_put_unalignedp64(ptr, U_MULTICHAR_CONSTANT64('C','o','n','t','e','n','t','-'));
u_put_unalignedp64(ptr+8, U_MULTICHAR_CONSTANT64('E','n','c','o','d','i','n','g'));
u_put_unalignedp64(ptr+16, U_MULTICHAR_CONSTANT64(':',' ','g','z','i','p','\r','\n'));
# endif
}
else
{
no_compress:
(void) UClientImage_Base::body->replace(pEndHeader + U_http_info.endHeader, clength);
}
end:
if (U_http_content_type_len != 1)
{
// NB: we assume that we don't have a HTTP content-type header...
# if defined(DEBUG) && defined(USE_LIBMAGIC)
if (clength > 4)
if (clength > 4 &&
U_http_content_type_len != 1) // NB: we assume that we don't have a HTTP content-type header...
{
const char* p = UClientImage_Base::wbuffer->c_pointer(U_http_info.endHeader);
const char* p = pEndHeader + U_http_info.endHeader;
if (u_isText((const unsigned char*)p, clength))
{
@ -7094,67 +7107,111 @@ end:
}
# endif
ptr1 = ptr+sz;
if (bcompress == false)
{
(void) UClientImage_Base::body->replace(pEndHeader + U_http_info.endHeader, clength);
u_put_unalignedp64(ptr1, U_MULTICHAR_CONSTANT64('C','o','n','t','e','n','t','-'));
u_put_unalignedp64(ptr1+8, U_MULTICHAR_CONSTANT64('T','y','p','e',':',' ','t','e'));
u_put_unalignedp16(ptr1+16, U_MULTICHAR_CONSTANT16('x','t'));
goto next;
}
}
else
{
if (clength == 0)
{
no_response:
UClientImage_Base::body->clear(); // clean body to avoid writev() in response...
ptr1 += U_CONSTANT_SIZE("Content-Type: text");
handlerResponse();
return;
}
pEndHeader = U_NULLPTR;
if (bcompress == false)
{
*UClientImage_Base::body = *UClientImage_Base::wbuffer;
goto next;
}
}
U_INTERNAL_ASSERT(bcompress)
#if defined(USE_LIBZ) || defined(USE_LIBBROTLI)
if (compress(UClientImage_Base::wbuffer->substr(U_http_info.endHeader, clength))) clength = UClientImage_Base::body->size();
else
{
U_INTERNAL_ASSERT_MAJOR(clength, 0)
U_INTERNAL_ASSERT_POINTER(pEndHeader)
(void) UClientImage_Base::body->replace(pEndHeader + U_http_info.endHeader, clength);
}
#endif
next:
ptr = ext->pend();
if (U_http_content_type_len != 1)
{
// NB: we assume that we don't have a HTTP content-type header...
u_put_unalignedp64(ptr, U_MULTICHAR_CONSTANT64('C','o','n','t','e','n','t','-'));
u_put_unalignedp64(ptr+8, U_MULTICHAR_CONSTANT64('T','y','p','e',':',' ','t','e'));
u_put_unalignedp16(ptr+16, U_MULTICHAR_CONSTANT16('x','t'));
ptr += U_CONSTANT_SIZE("Content-Type: text");
if (u_is_html(mime_index))
{
u_put_unalignedp64(ptr1, U_MULTICHAR_CONSTANT64('/','h','t','m','l',';',' ','c'));
u_put_unalignedp64(ptr1+8, U_MULTICHAR_CONSTANT64('h','a','r','s','e','t','=','U'));
u_put_unalignedp32(ptr1+16, U_MULTICHAR_CONSTANT32('T','F','-','8'));
u_put_unalignedp16(ptr1+20, U_MULTICHAR_CONSTANT16('\r','\n'));
u_put_unalignedp64(ptr, U_MULTICHAR_CONSTANT64('/','h','t','m','l',';',' ','c'));
u_put_unalignedp64(ptr+8, U_MULTICHAR_CONSTANT64('h','a','r','s','e','t','=','U'));
u_put_unalignedp32(ptr+16, U_MULTICHAR_CONSTANT32('T','F','-','8'));
u_put_unalignedp16(ptr+20, U_MULTICHAR_CONSTANT16('\r','\n'));
sz += U_CONSTANT_SIZE("Content-Type: " U_CTYPE_HTML "\r\n");
ptr += U_CONSTANT_SIZE("/html; charset=UTF-8\r\n");
}
else
{
# ifdef U_SERVER_CAPTIVE_PORTAL
u_put_unalignedp64(ptr1, U_MULTICHAR_CONSTANT64('/','p','l','a','i','n','\r','\n'));
u_put_unalignedp64(ptr, U_MULTICHAR_CONSTANT64('/','p','l','a','i','n','\r','\n'));
sz += U_CONSTANT_SIZE("Content-Type: text/plain\r\n");
ptr += U_CONSTANT_SIZE("/plain\r\n");
# else
u_put_unalignedp64(ptr1, U_MULTICHAR_CONSTANT64('/','p','l','a','i','n',';',' '));
u_put_unalignedp64(ptr1+8, U_MULTICHAR_CONSTANT64('c','h','a','r','s','e','t','='));
u_put_unalignedp32(ptr1+16, U_MULTICHAR_CONSTANT32('U','T','F','-'));
ptr1[20] = '8';
u_put_unalignedp16(ptr1+21, U_MULTICHAR_CONSTANT16('\r','\n'));
u_put_unalignedp64(ptr, U_MULTICHAR_CONSTANT64('/','p','l','a','i','n',';',' '));
u_put_unalignedp64(ptr+8, U_MULTICHAR_CONSTANT64('c','h','a','r','s','e','t','='));
u_put_unalignedp32(ptr+16, U_MULTICHAR_CONSTANT32('U','T','F','-'));
ptr[20] = '8';
u_put_unalignedp16(ptr+21, U_MULTICHAR_CONSTANT16('\r','\n'));
sz += U_CONSTANT_SIZE("Content-Type: " U_CTYPE_TEXT_WITH_CHARSET "\r\n");
ptr += U_CONSTANT_SIZE("/plain; charset=UTF-8\r\n");
# endif
}
}
ptr1 = ptr+sz;
u_put_unalignedp64(ptr, U_MULTICHAR_CONSTANT64('C','o','n','t','e','n','t','-'));
u_put_unalignedp64(ptr+8, U_MULTICHAR_CONSTANT64('L','e','n','g','t','h',':',' '));
u_put_unalignedp64(ptr1, U_MULTICHAR_CONSTANT64('C','o','n','t','e','n','t','-'));
u_put_unalignedp64(ptr1+8, U_MULTICHAR_CONSTANT64('L','e','n','g','t','h',':',' '));
ptr1 = u_num2str32(clength, ptr1 + U_CONSTANT_SIZE("Content-Length: "));
ptr = u_num2str32(clength, ptr + U_CONSTANT_SIZE("Content-Length: "));
if (pEndHeader == U_NULLPTR)
{
u_put_unalignedp32(ptr1, U_MULTICHAR_CONSTANT32('\r','\n','\r','\n'));
ptr1 += 4;
u_put_unalignedp32(ptr, U_MULTICHAR_CONSTANT32('\r','\n','\r','\n'));
ptr += U_CONSTANT_SIZE(U_CRLF2);
}
else
{
u_put_unalignedp16(ptr1, U_MULTICHAR_CONSTANT16('\r','\n'));
ptr1 += 2;
u_put_unalignedp16(ptr, U_MULTICHAR_CONSTANT16('\r','\n'));
ptr += U_CONSTANT_SIZE(U_CRLF);
U_INTERNAL_ASSERT(u_endsWith(pEndHeader, U_http_info.endHeader, U_CONSTANT_TO_PARAM(U_CRLF2)))
U_MEMCPY(ptr1, pEndHeader, U_http_info.endHeader);
ptr1 += U_http_info.endHeader;
U_MEMCPY(ptr, pEndHeader, U_http_info.endHeader);
ptr += U_http_info.endHeader;
}
ext->size_adjust(ptr1);
ext->size_adjust(ptr);
no_response:
handlerResponse();
}
@ -7968,12 +8025,14 @@ next:
U_RETURN_STRING(header);
}
U_NO_EXPORT void UHTTP::setHeaderForCache(UHTTP::UFileCacheData* ptr, const UString& data)
U_NO_EXPORT void UHTTP::setHeaderForCache(UHTTP::UFileCacheData* ptr, UString& data)
{
U_TRACE(0, "UHTTP::setHeaderForCache(%p,%V)", ptr, data.rep)
U_INTERNAL_ASSERT_POINTER(ptr)
(void) data.shrink();
ptr->array->push_back(data);
#ifndef U_HTTP2_DISABLE
@ -7988,6 +8047,29 @@ U_NO_EXPORT void UHTTP::setHeaderForCache(UHTTP::UFileCacheData* ptr, const UStr
#endif
}
U_NO_EXPORT void UHTTP::setDataInCache(const UString& fmt, const UString& content, const char* encoding, uint32_t encoding_len)
{
U_TRACE(0, "UHTTP::setDataInCache(%V,%V,%.*S,%u)", fmt.rep, content.rep, encoding_len, encoding, encoding_len)
uint32_t size = content.size();
file_data->array->push_back(content);
UString header(U_CAPACITY);
if (encoding_len == 0) header.snprintf(U_STRING_TO_PARAM(fmt), size);
else
{
U_INTERNAL_ASSERT_POINTER(encoding)
(void) header.append(encoding, encoding_len);
header.snprintf_add(U_STRING_TO_PARAM(fmt), size);
}
setHeaderForCache(file_data, header);
}
#ifdef USE_LIBBROTLI
U_NO_EXPORT void UHTTP::checkArrayCompressData(UFileCacheData* ptr)
{
@ -8015,29 +8097,24 @@ U_NO_EXPORT void UHTTP::putDataInCache(const UString& fmt, UString& content)
U_INTERNAL_ASSERT_MAJOR(file_data->size, 0)
U_INTERNAL_ASSERT_EQUALS(file_data->mime_index, mime_index)
UString header(U_CAPACITY);
uint32_t size = file_data->size, ratio1 = 100, ratio2 = 100;
U_NEW(UVector<UString>, file_data->array, UVector<UString>(6U));
#ifndef U_HTTP2_DISABLE
U_NEW(UVector<UString>, file_data->http2, UVector<UString>(3U));
#endif
file_data->array->push_back(content);
header.snprintf(U_STRING_TO_PARAM(fmt), size);
(void) header.shrink();
setHeaderForCache(file_data, header);
setDataInCache(fmt, content);
if (content.empty())
{
U_SRV_LOG("File cached (sendfile): %V - %u bytes", pathname->rep, size);
U_SRV_LOG("File cached (sendfile): %V - %u bytes", pathname->rep, file_data->size);
return;
}
U_INTERNAL_ASSERT_EQUALS(file_data->size, content.size())
uint32_t ratio1 = 100, ratio2 = 100;
if (u_is_img(mime_index))
{
U_INTERNAL_ASSERT(u_endsWith(U_FILE_TO_PARAM(*file), U_CONSTANT_TO_PARAM(".gif")) ||
@ -8051,10 +8128,10 @@ U_NO_EXPORT void UHTTP::putDataInCache(const UString& fmt, UString& content)
else if (u_is_png(mime_index)) page_speed->optimize_png(content);
else page_speed->optimize_jpg(content);
if (content.size() < size) U_SRV_LOG("WARNING: found image not optimized: %V", pathname->rep);
if (content.size() < file_data->size) U_SRV_LOG("WARNING: found image not optimized: %V", pathname->rep);
# endif
U_SRV_LOG("File cached (image): %V - %u bytes", pathname->rep, size);
U_SRV_LOG("File cached (image): %V - %u bytes", pathname->rep, file_data->size);
return;
}
@ -8102,8 +8179,8 @@ U_NO_EXPORT void UHTTP::putDataInCache(const UString& fmt, UString& content)
next:
#if defined(USE_LIBZ) || defined(USE_LIBBROTLI)
if (size > U_MIN_SIZE_FOR_DEFLATE &&
u_is_compressable(mime_index))
if (u_is_compressable(mime_index) &&
file_data->size > U_MIN_SIZE_FOR_DEFLATE)
{
# ifdef USE_LIBZ
/**
@ -8133,60 +8210,26 @@ next:
* Sending raw DEFLATE data is just not a good idea. As Mark says "[it's] simply more reliable to only use GZIP"
*/
UString content1 = UStringExt::deflate(content, 2); // 2 => zopfli...
UString content1 = UStringExt::deflate(content); // zopfli...
// NB: we accept compress data only if ratio compression is better than 15%...
if ((size = content1.size()) < file_data->size)
if (content1)
{
if (size) ratio1 = (size * 100U) / file_data->size;
ratio1 = UStringExt::ratio;
U_INTERNAL_DUMP("ratio1 = %u (%u%%)", ratio1, 100-ratio1)
if (ratio1 < 85)
{
file_data->array->push_back(content1); // gzip content...
header.setBuffer(U_CAPACITY);
(void) header.replace(U_CONSTANT_TO_PARAM("Content-Encoding: gzip\r\n"));
header.snprintf_add(U_STRING_TO_PARAM(fmt), size);
(void) header.shrink();
setHeaderForCache(file_data, header);
}
setDataInCache(fmt, content1, U_CONSTANT_TO_PARAM("Content-Encoding: gzip\r\n"));
}
# endif
# ifdef USE_LIBBROTLI
UString content2 = UStringExt::brotli(content);
// NB: we accept compress data only if ratio compression is better than 15%...
if ((size = content2.size()) < file_data->size)
if (content2)
{
ratio2 = UStringExt::ratio;
checkArrayCompressData(file_data);
if (size) ratio2 = (size * 100U) / file_data->size;
U_INTERNAL_DUMP("ratio2 = %u (%u%%)", ratio2, 100-ratio2)
if (ratio2 < 85)
{
file_data->array->push_back(content2); // brotli content...
header.setBuffer(U_CAPACITY);
(void) header.replace(U_CONSTANT_TO_PARAM("Content-Encoding: br\r\n"));
header.snprintf_add(U_STRING_TO_PARAM(fmt), size);
(void) header.shrink();
setHeaderForCache(file_data, header);
}
setDataInCache(fmt, content2, U_CONSTANT_TO_PARAM("Content-Encoding: br\r\n"));
}
# endif
}
@ -10405,7 +10448,7 @@ void UHTTP::checkContentLength(uint32_t length)
if (pos != U_NOT_FOUND)
{
const char* ptr = ext->c_pointer(pos += U_CONSTANT_SIZE("Content-Length") + 1);
const char* ptr = ext->c_pointer((pos += sizeof("Content-Length")));
if (u__isblank(*ptr)) // NB: weighttp fail if we don't put at least one space...
{
@ -11600,7 +11643,7 @@ U_EXPORT istream& operator>>(istream& is, UHTTP::UFileCacheData& d)
# ifdef USE_LIBZ
else if (u_is_img(d.mime_index) == false)
{
d.array->push_back(UStringExt::deflate(content, 2)); // 2 gzip(content)
d.array->push_back(UStringExt::deflate(content)); // 2 gzip(content)
decoded = U_STRING_FROM_CONSTANT("Content-Encoding: gzip\r\n") + header;

View File

@ -43,7 +43,7 @@ static void do_cipher(int fd, int operation)
}
}
if (operation == U_ENCODE) ebuflen = u_gz_deflate(buf, readlen, ebuf, true);
if (operation == U_ENCODE) ebuflen = u_gz_deflate(buf, readlen, ebuf, Z_DEFAULT_COMPRESSION);
else ebuflen = u_gz_inflate(buf, readlen, ebuf);
write(STDOUT_FILENO, ebuf, ebuflen);

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -6,7 +6,7 @@
start_msg tsa_http
UTRACE="0 75M 0"
#UTRACE="0 75M 0"
#UOBJDUMP="0 10M 10"
#USIMERR="error.sim"
export UTRACE UOBJDUMP USIMERR
@ -79,6 +79,8 @@ kill_server userver_tcp
mv err/userver_tcp.err err/tsa_http.err
#exit
if [ -s out/TSA_response.out ]; then
tail -c +155 out/TSA_response.out > TSA/response/response.tsr

View File

@ -6,7 +6,7 @@ start_msg uclient
DOC_ROOT=docroot
rm -f uclient.log $DOC_ROOT//webserver_uclient.log \
rm -f uclient.log $DOC_ROOT/webserver_uclient.log \
out/uclient.out err/uclient.err out/userver_tcp.out err/userver_tcp.err \
trace.*uclient*.[0-9]* object.*uclient*.[0-9]* stack.*uclient*.[0-9]* mempool.*uclient*.[0-9]* \
trace.*userver_*.[0-9]* object.*userver_*.[0-9]* stack.*userver_*.[0-9]* mempool.*userver_*.[0-9]* \

45
tests/examples/udp_server.sh Executable file
View File

@ -0,0 +1,45 @@
#!/bin/sh
. ../.function
DOC_ROOT=benchmark/docroot
rm -f tmp/usp_compile.sh.err /tmp/*.hpack.* \
/tmp/*userver_udp* \
out/userver_*.out err/userver_*.err \
trace.*userver_*.[0-9]* object.*userver_*.[0-9]* stack.*userver_*.[0-9]* mempool.*userver_*.[0-9]* \
$DOC_ROOT/trace.*userver_*.[0-9]* $DOC_ROOT/object.*userver_*.[0-9]* $DOC_ROOT/stack.*userver_*.[0-9]* $DOC_ROOT/mempool.*userver_*.[0-9]*
UTRACE="0 50M 0"
UTRACE_SIGNAL="0 50M 0"
UTRACE_FOLDER=/tmp
#UOBJDUMP="0 10M 100"
#USIMERR="error.sim"
UMEMUSAGE=yes
export UTRACE UOBJDUMP USIMERR UTRACE_SIGNAL UMEMUSAGE UTRACE_FOLDER
cat <<EOF >inp/webserver.cfg
userver {
PORT 8080
RUN_AS_USER nobody
LOG_FILE /tmp/userver_udp.log
LOG_FILE_SZ 10M
PID_FILE /var/run/userver_udp.pid
PREFORK_CHILD 0
}
EOF
DIR_CMD="../../examples/userver"
#STRACE=$TRUSS
start_prg_background userver_udp -c inp/webserver.cfg
$SLEEP
sync
echo "PID = `cat /var/run/userver_udp.pid`"
#$SLEEP
#$SLEEP
#killall userver_udp
#nc -u -w 5 192.168.42.12 8080 < /tmp/audacious-temp-*

View File

@ -7,7 +7,7 @@ public:
Product1() {}
virtual ~Product1() { (void) write(1, U_CONSTANT_TO_PARAM("distruttore Product1\n")); }
virtual void print(ostream& os) const { os << "I am Product1" << endl; }
virtual void print(ostream& os) const { os.write(U_CONSTANT_TO_PARAM("I am Product1\n")); }
};
U_CREAT_FUNC(product1, Product1)

View File

@ -7,7 +7,7 @@ public:
Product2() {}
virtual ~Product2() { (void) write(1, U_CONSTANT_TO_PARAM("distruttore Product2\n")); }
virtual void print(ostream& os) const { os << "I am Product2" << endl; }
virtual void print(ostream& os) const { os.write(U_CONSTANT_TO_PARAM("I am Product2\n")); }
};
U_CREAT_FUNC(product2, Product2)

View File

@ -2068,47 +2068,17 @@ U_EXPORT main(int argc, char* argv[])
*/
#ifdef USE_LIBZ
#define TEXT3 \
"Apr 12 10:03:22 www sm-mta[2031]: l3C834YF002031: from=<tddiaz@thai.com>, size=2426, class=0, nrcpts=1, msgid=<c69d01c77cd8$9471501e$6aa9eea9@thai.com>, proto=SMTP, daemon=MTA, relay=adsl-d36.87-197-150.t-com.sk [87.197.150.36]\n" \
"Apr 12 10:03:22 www sm-mta[2034]: l3C834YF002031: to=<marcodd@unirel.it>, delay=00:00:13, xdelay=00:00:00, mailer=cyrusv2, pri=122426, relay=localhost, dsn=5.1.1, stat=User unknown\n" \
"Apr 12 10:03:22 www sm-mta[2034]: l3C834YF002031: l3C83MYF002034: DSN: User unknown" \
"Apr 12 10:03:22 www sm-mta[2031]: l3C834YF002031: from=<tddiaz@thai.com>, size=2426, class=0, nrcpts=1, msgid=<c69d01c77cd8$9471501e$6aa9eea9@thai.com>, proto=SMTP, daemon=MTA, relay=adsl-d36.87-197-150.t-com.sk [87.197.150.36]\n" \
"Apr 12 10:03:22 www sm-mta[2034]: l3C834YF002031: to=<marcodd@unirel.it>, delay=00:00:13, xdelay=00:00:00, mailer=cyrusv2, pri=122426, relay=localhost, dsn=5.1.1, stat=User unknown\n" \
"Apr 12 10:03:22 www sm-mta[2034]: l3C834YF002031: l3C83MYF002034: DSN: User unknown" \
"Apr 12 10:03:22 www sm-mta[2031]: l3C834YF002031: from=<tddiaz@thai.com>, size=2426, class=0, nrcpts=1, msgid=<c69d01c77cd8$9471501e$6aa9eea9@thai.com>, proto=SMTP, daemon=MTA, relay=adsl-d36.87-197-150.t-com.sk [87.197.150.36]\n" \
"Apr 12 10:03:22 www sm-mta[2034]: l3C834YF002031: to=<marcodd@unirel.it>, delay=00:00:13, xdelay=00:00:00, mailer=cyrusv2, pri=122426, relay=localhost, dsn=5.1.1, stat=User unknown\n" \
"Apr 12 10:03:22 www sm-mta[2034]: l3C834YF002031: l3C83MYF002034: DSN: User unknown" \
"Apr 12 10:03:22 www sm-mta[2031]: l3C834YF002031: from=<tddiaz@thai.com>, size=2426, class=0, nrcpts=1, msgid=<c69d01c77cd8$9471501e$6aa9eea9@thai.com>, proto=SMTP, daemon=MTA, relay=adsl-d36.87-197-150.t-com.sk [87.197.150.36]\n" \
"Apr 12 10:03:22 www sm-mta[2034]: l3C834YF002031: to=<marcodd@unirel.it>, delay=00:00:13, xdelay=00:00:00, mailer=cyrusv2, pri=122426, relay=localhost, dsn=5.1.1, stat=User unknown\n" \
"Apr 12 10:03:22 www sm-mta[2034]: l3C834YF002031: l3C83MYF002034: DSN: User unknown" \
"Apr 12 10:03:22 www sm-mta[2031]: l3C834YF002031: from=<tddiaz@thai.com>, size=2426, class=0, nrcpts=1, msgid=<c69d01c77cd8$9471501e$6aa9eea9@thai.com>, proto=SMTP, daemon=MTA, relay=adsl-d36.87-197-150.t-com.sk [87.197.150.36]\n" \
"Apr 12 10:03:22 www sm-mta[2034]: l3C834YF002031: to=<marcodd@unirel.it>, delay=00:00:13, xdelay=00:00:00, mailer=cyrusv2, pri=122426, relay=localhost, dsn=5.1.1, stat=User unknown\n" \
"Apr 12 10:03:22 www sm-mta[2034]: l3C834YF002031: l3C83MYF002034: DSN: User unknown" \
"Apr 12 10:03:22 www sm-mta[2031]: l3C834YF002031: from=<tddiaz@thai.com>, size=2426, class=0, nrcpts=1, msgid=<c69d01c77cd8$9471501e$6aa9eea9@thai.com>, proto=SMTP, daemon=MTA, relay=adsl-d36.87-197-150.t-com.sk [87.197.150.36]\n" \
"Apr 12 10:03:22 www sm-mta[2034]: l3C834YF002031: to=<marcodd@unirel.it>, delay=00:00:13, xdelay=00:00:00, mailer=cyrusv2, pri=122426, relay=localhost, dsn=5.1.1, stat=User unknown\n" \
"Apr 12 10:03:22 www sm-mta[2034]: l3C834YF002031: l3C83MYF002034: DSN: User unknown" \
"Apr 12 10:03:22 www sm-mta[2031]: l3C834YF002031: from=<tddiaz@thai.com>, size=2426, class=0, nrcpts=1, msgid=<c69d01c77cd8$9471501e$6aa9eea9@thai.com>, proto=SMTP, daemon=MTA, relay=adsl-d36.87-197-150.t-com.sk [87.197.150.36]\n" \
"Apr 12 10:03:22 www sm-mta[2034]: l3C834YF002031: to=<marcodd@unirel.it>, delay=00:00:13, xdelay=00:00:00, mailer=cyrusv2, pri=122426, relay=localhost, dsn=5.1.1, stat=User unknown\n" \
"Apr 12 10:03:22 www sm-mta[2034]: l3C834YF002031: l3C83MYF002034: DSN: User unknown" \
"Apr 12 10:03:22 www sm-mta[2031]: l3C834YF002031: from=<tddiaz@thai.com>, size=2426, class=0, nrcpts=1, msgid=<c69d01c77cd8$9471501e$6aa9eea9@thai.com>, proto=SMTP, daemon=MTA, relay=adsl-d36.87-197-150.t-com.sk [87.197.150.36]\n" \
"Apr 12 10:03:22 www sm-mta[2034]: l3C834YF002031: to=<marcodd@unirel.it>, delay=00:00:13, xdelay=00:00:00, mailer=cyrusv2, pri=122426, relay=localhost, dsn=5.1.1, stat=User unknown\n" \
"Apr 12 10:03:22 www sm-mta[2034]: l3C834YF002031: l3C83MYF002034: DSN: User unknown" \
"Apr 12 10:03:22 www sm-mta[2034]: l3C834YF002031: l3C83MYF002034: DSN: User unknown" \
"Apr 12 10:03:22 www sm-mta[2031]: l3C834YF002031: from=<tddiaz@thai.com>, size=2426, class=0, nrcpts=1, msgid=<c69d01c77cd8$9471501e$6aa9eea9@thai.com>, proto=SMTP, daemon=MTA, relay=adsl-d36.87-197-150.t-com.sk [87.197.150.36]\n" \
"Apr 12 10:03:22 www sm-mta[2034]: l3C834YF002031: to=<marcodd@unirel.it>, delay=00:00:13, xdelay=00:00:00, mailer=cyrusv2, pri=122426, relay=localhost, dsn=5.1.1, stat=User unknown\n" \
"Apr 12 10:03:22 www sm-mta[2034]: l3C834YF002031: l3C83MYF002034: DSN: User unknown" \
"Apr 12 10:03:22 www sm-mta[2031]: l3C834YF002031: from=<tddiaz@thai.com>, size=2426, class=0, nrcpts=1, msgid=<c69d01c77cd8$9471501e$6aa9eea9@thai.com>, proto=SMTP, daemon=MTA, relay=adsl-d36.87-197-150.t-com.sk [87.197.150.36]\n" \
"Apr 12 10:03:22 www sm-mta[2034]: l3C834YF002031: to=<marcodd@unirel.it>, delay=00:00:13, xdelay=00:00:00, mailer=cyrusv2, pri=122426, relay=localhost, dsn=5.1.1, stat=User unknown\n"
z = U_STRING_FROM_CONSTANT("########################################################################################################################"
"########################################################################################################################"
"########################################################################################################################");
z = U_STRING_FROM_CONSTANT(TEXT3);
x = UStringExt::deflate(z, 1);
x = UStringExt::deflate(z);
y = UStringExt::gunzip(x);
U_ASSERT( z == y )
x = UStringExt::deflate(z, 2);
x = UStringExt::deflate(z, Z_BEST_COMPRESSION);
y = UStringExt::gunzip(x);

View File

@ -54,12 +54,15 @@ U_EXPORT main (int argc, char* argv[], char* env[])
U_TRACE(5,"main(%d)",argc)
UFileConfig fcg;
UUnixServer s(0);
UUnixSocket::setPath(argv[1]);
UUnixServer s(U_NULLPTR);
UString plugin_dir(argv[2]), plugin_list(argv[3]);
UServer_Base::bipc = true;
(void) s.name_sock->assign(argv[1]);
UUnixSocket::setPath(s.name_sock->data());
if (argv[4])
{
UString x(argv[4]);