mirror of
https://github.com/stefanocasazza/ULib.git
synced 2025-09-28 19:05:55 +08:00
fix+sync
This commit is contained in:
parent
b66e456d46
commit
16be2e0658
|
@ -16,11 +16,15 @@
|
|||
|
||||
/* Manage the header files to include */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include <ulib/internal/config.h>
|
||||
# include <ulib/base/replace/replace.h>
|
||||
#else
|
||||
/* Minimal environment configuration */
|
||||
#include <ulib/internal/config.h>
|
||||
#include <ulib/base/replace/replace.h>
|
||||
|
||||
#ifndef U_LIBEXECDIR
|
||||
#define U_LIBEXECDIR "/usr/local/libexec/ulib"
|
||||
#endif
|
||||
|
||||
/*
|
||||
#ifndef HAVE_CONFIG_H
|
||||
# define HAVE_CXX11 1
|
||||
# define HAVE_CXX14 1
|
||||
# define ENABLE_LFS 1
|
||||
|
@ -39,21 +43,18 @@
|
|||
# define PACKAGE_NAME "ULib"
|
||||
# define HAVE_NETINET_IN_H 1
|
||||
# define ULIB_VERSION "1.4.2"
|
||||
# define USE_HARDWARE_CRC32 1
|
||||
# define HAVE_SYS_SENDFILE_H 1
|
||||
# define PACKAGE_VERSION "1.4.2"
|
||||
# define HAVE_NETPACKET_PACKET_H 1
|
||||
# define FNM_PATHNAME (1 << 0) /* No wildcard can ever match '/' */
|
||||
# define FNM_NOESCAPE (1 << 1) /* Backslashes don't quote special chars */
|
||||
# define FNM_PERIOD (1 << 2) /* Leading '.' is matched only explicitly */
|
||||
# define FNM_PATHNAME (1 << 0)
|
||||
# define FNM_NOESCAPE (1 << 1)
|
||||
# define FNM_PERIOD (1 << 2)
|
||||
# define U_CACHE_REQUEST_DISABLE 1
|
||||
# define U_PIPELINE_HOMOGENEOUS_DISABLE 1
|
||||
# define restrict
|
||||
# include <ulib/internal/platform.h>
|
||||
# ifndef U_LIBEXECDIR
|
||||
# define U_LIBEXECDIR "/usr/libexec/ulib"
|
||||
# endif
|
||||
#endif
|
||||
*/
|
||||
|
||||
#ifdef U_LINUX
|
||||
# ifdef HAVE__USR_SRC_LINUX_INCLUDE_GENERATED_UAPI_LINUX_VERSION_H
|
||||
|
@ -107,6 +108,9 @@ U_DO_PRAGMA(message ("Sorry I was compiled with http2 enabled so I cannot suppor
|
|||
# undef U_HTTP_INOTIFY_SUPPORT
|
||||
U_DO_PRAGMA(message ("Sorry I was compiled with server captive portal mode enabled so I cannot support http inotify"))
|
||||
#endif
|
||||
#if defined(USE_HARDWARE_CRC32) && defined(__GNUC__) && !defined(HAVE_CONFIG_H) /* The built-in functions __builtin_ia32_crc32 are available when -mcrc32 is used */
|
||||
U_DO_PRAGMA(message ("ULib is configured with support for crc32 intrinsics, so you must use the -mcrc32 g++ option for compilation"))
|
||||
#endif
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdarg.h>
|
||||
|
|
|
@ -809,6 +809,7 @@ unsigned zip_extract(const char* zipfile, const char** files, char*** filenames,
|
|||
|
||||
U_INTERNAL_TRACE("zip_extract(%s,%p,%p,%p)", zipfile, files, filenames, filenames_len)
|
||||
|
||||
#ifndef U_COVERITY_FALSE_POSITIVE
|
||||
if (zip_open(zipfile)) return 0; /* open the zipfile */
|
||||
|
||||
if (files) while (files[file_num] != 0) ++file_num;
|
||||
|
@ -901,8 +902,6 @@ unsigned zip_extract(const char* zipfile, const char** files, char*** filenames,
|
|||
return 0;
|
||||
}
|
||||
|
||||
# ifndef U_COVERITY_FALSE_POSITIVE
|
||||
/* coverity[toctou] */
|
||||
if (stat(tmp_buff, &sbuf) < 0)
|
||||
{
|
||||
if (errno != ENOENT)
|
||||
|
@ -929,7 +928,6 @@ unsigned zip_extract(const char* zipfile, const char** files, char*** filenames,
|
|||
|
||||
return 0;
|
||||
}
|
||||
# endif
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -992,18 +990,14 @@ unsigned zip_extract(const char* zipfile, const char** files, char*** filenames,
|
|||
{
|
||||
perror("read");
|
||||
|
||||
# ifndef U_COVERITY_FALSE_POSITIVE // NEGATIVE_RETURNS
|
||||
(void) close(f_fd);
|
||||
|
||||
return 0;
|
||||
# endif
|
||||
}
|
||||
|
||||
ze.crc = crc32(ze.crc, (Bytef*)rd_buff, rdamt);
|
||||
|
||||
# ifndef U_COVERITY_FALSE_POSITIVE // NEGATIVE_RETURNS
|
||||
(void) write(f_fd, rd_buff, rdamt);
|
||||
# endif
|
||||
|
||||
in_a -= rdamt;
|
||||
out_a += rdamt;
|
||||
|
@ -1014,9 +1008,7 @@ unsigned zip_extract(const char* zipfile, const char** files, char*** filenames,
|
|||
if (eflen) consume(eflen);
|
||||
}
|
||||
|
||||
# ifndef U_COVERITY_FALSE_POSITIVE // NEGATIVE_RETURNS
|
||||
(void) close(f_fd);
|
||||
# endif
|
||||
|
||||
/* if there is a data descriptor left, compare the CRC */
|
||||
|
||||
|
@ -1069,6 +1061,7 @@ unsigned zip_extract(const char* zipfile, const char** files, char*** filenames,
|
|||
*filenames = 0;
|
||||
*filenames_len = 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
return n;
|
||||
}
|
||||
|
|
|
@ -81,6 +81,14 @@ public:
|
|||
Application()
|
||||
{
|
||||
U_TRACE_NO_PARAM(5, "Application::Application()")
|
||||
|
||||
bvar =
|
||||
bsession =
|
||||
bstorage =
|
||||
bfirst_pass =
|
||||
is_html =
|
||||
test_if_html =
|
||||
bpreprocessing_failed = false;
|
||||
}
|
||||
|
||||
~Application()
|
||||
|
@ -201,7 +209,7 @@ public:
|
|||
|
||||
const char* directive = token.c_pointer(2); // "-#"...
|
||||
|
||||
U_INTERNAL_DUMP("directive(10) = %.*S", 10, directive)
|
||||
U_INTERNAL_DUMP("directive(10) = %.10S", directive)
|
||||
|
||||
if (bfirst_pass)
|
||||
{
|
||||
|
@ -213,50 +221,58 @@ public:
|
|||
if (bdefine ||
|
||||
binclude)
|
||||
{
|
||||
UString block(100U);
|
||||
UVector<UString> vec;
|
||||
uint32_t pos;
|
||||
const char* ptr;
|
||||
UString block(100U + token.size());
|
||||
|
||||
block.snprintf(U_CONSTANT_TO_PARAM("<!-%v-->"), token.rep);
|
||||
|
||||
for (const char* ptr = t.getPointer(); u__isspace(*ptr); ++ptr) block.push_back(*ptr);
|
||||
pos = t.getDistance() - block.size();
|
||||
|
||||
vec.push_back(block);
|
||||
U_INTERNAL_DUMP("usp(%u) = %.10S", pos, t.getPointer())
|
||||
|
||||
if (binclude)
|
||||
for (ptr = t.getPointer(); u__isspace(*ptr); ++ptr) block.push_back(*ptr);
|
||||
|
||||
if (bdefine)
|
||||
{
|
||||
vdefine.push_back(block);
|
||||
vdefine.push_back(UString::getStringNull());
|
||||
|
||||
setDirectiveItem(directive, U_CONSTANT_SIZE("define"));
|
||||
|
||||
ptr = token.data();
|
||||
|
||||
do { ++ptr; } while (u__isspace(*ptr) == false);
|
||||
|
||||
pos = token.distance(ptr);
|
||||
|
||||
UString id(token, 0, pos),
|
||||
value(token, pos);
|
||||
|
||||
vdefine.push_back(id);
|
||||
vdefine.push_back(value);
|
||||
}
|
||||
else
|
||||
{
|
||||
setDirectiveItem(directive, U_CONSTANT_SIZE("include"));
|
||||
|
||||
UString content = UFile::contentOf(token);
|
||||
|
||||
if (content) vec.push_back(vdefine.empty() ? content : UStringExt::substitute(content, vdefine));
|
||||
else
|
||||
if (content.empty())
|
||||
{
|
||||
vec.push_back(UString::getStringNull());
|
||||
|
||||
U_WARNING("load of include usp %V failed", token.rep);
|
||||
}
|
||||
else
|
||||
{
|
||||
# ifdef DEBUG
|
||||
token.clear(); // NB: to avoid DEAD OF SOURCE STRING WITH CHILD ALIVE...
|
||||
# endif
|
||||
|
||||
t.setData((usp = UStringExt::substitute(usp, block, content)));
|
||||
|
||||
t.setDistance(pos);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
U_INTERNAL_ASSERT(bdefine)
|
||||
|
||||
setDirectiveItem(directive, U_CONSTANT_SIZE("define"));
|
||||
|
||||
vec.push_back(UString::getStringNull());
|
||||
|
||||
(void) vec.split(U_STRING_TO_PARAM(token));
|
||||
|
||||
U_ASSERT_EQUALS(vec.size(), 4)
|
||||
|
||||
vdefine.push_back(vec[2]);
|
||||
vdefine.push_back(vec[3]);
|
||||
}
|
||||
|
||||
# ifdef DEBUG
|
||||
token.clear(); // NB: to avoid DEAD OF SOURCE STRING WITH CHILD ALIVE...
|
||||
# endif
|
||||
|
||||
t.setData((usp = UStringExt::substitute(usp, vec)));
|
||||
}
|
||||
|
||||
return;
|
||||
|
@ -476,10 +492,6 @@ public:
|
|||
const char* ptr;
|
||||
uint32_t distance, pos, size;
|
||||
|
||||
# ifdef DEBUG
|
||||
token.clear(); // NB: to avoid DEAD OF SOURCE STRING WITH CHILD ALIVE...
|
||||
# endif
|
||||
|
||||
t.setData(usp);
|
||||
|
||||
loop: distance = t.getDistance();
|
||||
|
@ -546,25 +558,10 @@ loop: distance = t.getDistance();
|
|||
}
|
||||
}
|
||||
|
||||
void firstPass()
|
||||
{
|
||||
U_TRACE_NO_PARAM(5, "Application::firstPass()")
|
||||
|
||||
// NB: we check for <!--#define ... --> and <!--#include ... -->
|
||||
|
||||
bfirst_pass = true;
|
||||
|
||||
processUSP();
|
||||
}
|
||||
|
||||
bool execPreProcessing()
|
||||
{
|
||||
U_TRACE_NO_PARAM(5, "Application::execPreProcessing()")
|
||||
|
||||
# ifndef DEBUG
|
||||
bpreprocessing_failed = false;
|
||||
# endif
|
||||
|
||||
if (U_STRING_FIND(usp, 0, "\n#ifdef DEBUG") != U_NOT_FOUND)
|
||||
{
|
||||
UFileConfig cfg(UStringExt::substitute(usp, U_CONSTANT_TO_PARAM("#include"), U_CONSTANT_TO_PARAM("//#include")), true);
|
||||
|
@ -572,9 +569,7 @@ loop: distance = t.getDistance();
|
|||
if (cfg.processData(false)) usp = UStringExt::substitute(cfg.getData(), U_CONSTANT_TO_PARAM("//#include"), U_CONSTANT_TO_PARAM("#include"));
|
||||
else
|
||||
{
|
||||
# ifndef DEBUG
|
||||
bpreprocessing_failed = true;
|
||||
# endif
|
||||
|
||||
U_RETURN(false);
|
||||
}
|
||||
|
@ -583,20 +578,6 @@ loop: distance = t.getDistance();
|
|||
U_RETURN(true);
|
||||
}
|
||||
|
||||
void secondPass()
|
||||
{
|
||||
U_TRACE_NO_PARAM(5, "Application::secondPass()")
|
||||
|
||||
bvar =
|
||||
bsession =
|
||||
bstorage =
|
||||
bfirst_pass =
|
||||
is_html =
|
||||
test_if_html = false;
|
||||
|
||||
processUSP();
|
||||
}
|
||||
|
||||
void run(int argc, char* argv[], char* env[])
|
||||
{
|
||||
U_TRACE(5, "Application::run(%d,%p,%p)", argc, argv, env)
|
||||
|
@ -613,13 +594,21 @@ loop: distance = t.getDistance();
|
|||
|
||||
t.setGroup(U_CONSTANT_TO_PARAM("<!--->"));
|
||||
|
||||
firstPass();
|
||||
bfirst_pass = true; // NB: we check for <!--#define ... --> and <!--#include ... -->
|
||||
|
||||
if (usp.empty()) U_ERROR("first pass for %V failed", filename.rep);
|
||||
processUSP();
|
||||
|
||||
# ifdef DEBUG
|
||||
token.clear(); // NB: to avoid DEAD OF SOURCE STRING WITH CHILD ALIVE...
|
||||
# endif
|
||||
|
||||
if (vdefine.empty() == false) usp = UStringExt::substitute(usp, vdefine);
|
||||
|
||||
if (execPreProcessing() == false) U_WARNING("preprocessing of %V failed", filename.rep);
|
||||
|
||||
secondPass();
|
||||
bfirst_pass = false;
|
||||
|
||||
processUSP();
|
||||
|
||||
U_INTERNAL_DUMP("declaration = %V", declaration.rep)
|
||||
|
||||
|
@ -634,9 +623,16 @@ loop: distance = t.getDistance();
|
|||
char ptr4[100] = { '\0' };
|
||||
char ptr5[100] = { '\0' };
|
||||
const char* ptr6 = "";
|
||||
const char* ptr7 = (u_get_unalignedp32(usp.data()) == U_MULTICHAR_CONSTANT32('<','!','-','-') && usp.c_char(4) == '#' && u__isspace(usp.c_char(5)) // <!--# --> (comment)
|
||||
? "\n\tUClientImage_Base::setRequestNoCache();\n\t\n"
|
||||
: "");
|
||||
const char* ptr7 = "";
|
||||
|
||||
# ifndef U_CACHE_REQUEST_DISABLE
|
||||
if (usp.c_char(4) == '#' &&
|
||||
u__isspace(usp.c_char(5)) &&
|
||||
u_get_unalignedp32(usp.data()) == U_MULTICHAR_CONSTANT32('<','!','-','-')) // <!--# --> (comment)
|
||||
{
|
||||
ptr7 = "\n\tUClientImage_Base::setRequestNoCache();\n\t\n";
|
||||
}
|
||||
# endif
|
||||
|
||||
UString basename = UStringExt::basename(filename);
|
||||
|
||||
|
@ -769,7 +765,7 @@ private:
|
|||
UTokenizer t;
|
||||
UVector<UString> vdefine;
|
||||
UString usp, token, output0, output1, declaration, vcode, http_header;
|
||||
bool test_if_html, is_html, bpreprocessing_failed, bfirst_pass, bvar, bsession, bstorage;
|
||||
bool bvar, bsession, bstorage, bfirst_pass, is_html, test_if_html, bpreprocessing_failed;
|
||||
|
||||
U_DISALLOW_COPY_AND_ASSIGN(Application)
|
||||
};
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
# include <ws2tcpip.h>
|
||||
#else
|
||||
# include <pwd.h>
|
||||
# include <sys/prctl.h>
|
||||
# include <ulib/net/unixsocket.h>
|
||||
# ifdef HAVE_SCHED_GETCPU
|
||||
# include <sched.h>
|
||||
|
@ -1815,14 +1816,16 @@ void UServer_Base::loadConfigParam()
|
|||
min_size_for_sendfile = cfg->readLong(U_CONSTANT_TO_PARAM("MIN_SIZE_FOR_SENDFILE"), 500 * 1024); // 500k: for major size we assume is better to use sendfile()
|
||||
num_client_threshold = cfg->readLong(U_CONSTANT_TO_PARAM("CLIENT_THRESHOLD"));
|
||||
UNotifier::max_connection = cfg->readLong(U_CONSTANT_TO_PARAM("MAX_KEEP_ALIVE"));
|
||||
u_printf_string_max_length = cfg->readLong(U_CONSTANT_TO_PARAM("LOG_MSG_SIZE"));
|
||||
num_client_for_parallelization = cfg->readLong(U_CONSTANT_TO_PARAM("CLIENT_FOR_PARALLELIZATION"));
|
||||
|
||||
#ifdef USERVER_UDP
|
||||
if (budp == false)
|
||||
if (budp &&
|
||||
u_printf_string_max_length == -1)
|
||||
{
|
||||
u_printf_string_max_length = 128;
|
||||
}
|
||||
#endif
|
||||
{
|
||||
u_printf_string_max_length = cfg->readLong(U_CONSTANT_TO_PARAM("LOG_MSG_SIZE"));
|
||||
}
|
||||
|
||||
x = cfg->at(U_CONSTANT_TO_PARAM("CRASH_EMAIL_NOTIFY"));
|
||||
|
||||
|
@ -4270,6 +4273,10 @@ void UServer_Base::run()
|
|||
|
||||
UInterrupt::setHandlerForSignal(SIGHUP, (sighandler_t)SIG_IGN); // NB: we can't use UInterrupt::erase() because it restore the old action (UInterrupt::init)...
|
||||
|
||||
# ifdef U_LINUX
|
||||
(void) U_SYSCALL(prctl, "%d,%lu", PR_SET_PDEATHSIG, SIGINT);
|
||||
# endif
|
||||
|
||||
runLoop(user);
|
||||
|
||||
return;
|
||||
|
|
6
tests/examples/inp/http/usp_include.req
Normal file
6
tests/examples/inp/http/usp_include.req
Normal file
|
@ -0,0 +1,6 @@
|
|||
GET /home HTTP/1.1
|
||||
Host: localhost:8080
|
||||
|
||||
GET /home HTTP/1.1
|
||||
Host: localhost:8080
|
||||
|
55
tests/examples/ok/usp_include.ok
Normal file
55
tests/examples/ok/usp_include.ok
Normal file
|
@ -0,0 +1,55 @@
|
|||
HTTP/1.1 200 OK
|
||||
Date: Thu, 12 Oct 2017 15:11:29 GMT
|
||||
Server: ULib
|
||||
Content-Type: text/html; charset=UTF-8
|
||||
Content-Length: 332
|
||||
|
||||
<html>
|
||||
<head></head>
|
||||
<body>
|
||||
|
||||
<nav>
|
||||
<a href="/staff/home">Home</a>
|
||||
<a href="/staff/logout">Logout</a> </nav>
|
||||
|
||||
<div class="wrapper">
|
||||
<div class="fullscreen-content">
|
||||
|
||||
|
||||
<h1>Hello </h1>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="footer"> <p style="text-align: center;"> "Copyright © Nemsys Enterprises" "2017"</p> </div>
|
||||
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>HTTP/1.1 200 OK
|
||||
Date: Thu, 12 Oct 2017 15:11:29 GMT
|
||||
Server: ULib
|
||||
Content-Type: text/html; charset=UTF-8
|
||||
Content-Length: 332
|
||||
|
||||
<html>
|
||||
<head></head>
|
||||
<body>
|
||||
|
||||
<nav>
|
||||
<a href="/staff/home">Home</a>
|
||||
<a href="/staff/logout">Logout</a> </nav>
|
||||
|
||||
<div class="wrapper">
|
||||
<div class="fullscreen-content">
|
||||
|
||||
|
||||
<h1>Hello </h1>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="footer"> <p style="text-align: center;"> "Copyright © Nemsys Enterprises" "2017"</p> </div>
|
||||
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
58
tests/examples/usp_include.test
Executable file
58
tests/examples/usp_include.test
Executable file
|
@ -0,0 +1,58 @@
|
|||
#!/bin/sh
|
||||
|
||||
. ../.function
|
||||
|
||||
## usp_include.test -- Test prototype for Jon
|
||||
|
||||
start_msg usp_include
|
||||
|
||||
UTRACE="0 15M 0"
|
||||
#UOBJDUMP="0 10M 10"
|
||||
#USIMERR="error.sim"
|
||||
export UTRACE UOBJDUMP USIMERR
|
||||
|
||||
DOC_ROOT=JONATHAN/docroot
|
||||
|
||||
rm -rf $DOC_ROOT/*log /tmp/request.* /tmp/response.* \
|
||||
out/userver_tcp.out err/userver_tcp.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]*
|
||||
|
||||
cat <<EOF >inp/webserver.cfg
|
||||
userver {
|
||||
PORT 8080
|
||||
LOG_FILE usp_include.log
|
||||
LOG_FILE_SZ 1M
|
||||
PID_FILE /var/run/userver_tcp.pid
|
||||
DOCUMENT_ROOT $DOC_ROOT
|
||||
PREFORK_CHILD 0
|
||||
PLUGIN_DIR ../../../../src/ulib/net/server/plugin/.libs
|
||||
#ORM_DRIVER mysql
|
||||
#ORM_DRIVER sqlite
|
||||
#ORM_DRIVER_DIR ../../../../src/ulib/orm/driver/.libs
|
||||
}
|
||||
EOF
|
||||
|
||||
check_for_netcat
|
||||
|
||||
DIR_CMD="../../examples/userver"
|
||||
|
||||
#export ORM_DRIVER="sqlite"
|
||||
#export ORM_OPTION="host=localhost dbname=../db/hello_world"
|
||||
|
||||
start_prg_background userver_tcp -c inp/webserver.cfg
|
||||
|
||||
wait_server_ready localhost 8080
|
||||
|
||||
#sync
|
||||
#echo "PID = `cat /var/run/userver_tcp.pid`"
|
||||
#exit 0
|
||||
|
||||
send_req $NCAT localhost 8080 inp/http/usp_include.req usp_include 2 kill
|
||||
|
||||
kill_server userver_tcp
|
||||
|
||||
mv err/userver_tcp.err err/one.err
|
||||
|
||||
# Test against expected output
|
||||
test_output_wc l usp_include
|
|
@ -7,8 +7,8 @@ Debian 7.11 was released Saturday, 4th June 2016.
|
|||
Debian 8.9, or jessie. Access this release through dists/oldstable
|
||||
Debian 8.9 was released Saturday, 22nd July 2017.
|
||||
|
||||
Debian 9.1, or stretch. Access this release through dists/stable
|
||||
Debian 9.1 was released Saturday, 22nd July 2017.
|
||||
Debian 9.2, or stretch. Access this release through dists/stable
|
||||
Debian 9.2 was released Saturday, 7th October 2017.
|
||||
|
||||
Testing, or buster. Access this release through dists/testing. The
|
||||
current tested development snapshot is named buster. Packages which
|
||||
|
|
Loading…
Reference in New Issue
Block a user