mirror of
https://github.com/stefanocasazza/ULib.git
synced 2025-09-28 19:05:55 +08:00
sync
This commit is contained in:
parent
0acb747538
commit
8e882aa257
|
@ -35,16 +35,11 @@ extern U_EXPORT void runDynamicPage_index();
|
|||
UHTTP::getPostLoginUserPasswd())
|
||||
{
|
||||
UHTTP::usp->runDynamicPageParam(U_DPAGE_AUTH);
|
||||
if (*UClientImage_Base::wbuffer) return;
|
||||
}
|
||||
if (UHTTP::loginCookie->empty())
|
||||
{
|
||||
UHTTP::UServletPage* usp_save = UHTTP::usp;
|
||||
if (UHTTP::getUSP(U_CONSTANT_TO_PARAM("login_form")))
|
||||
{
|
||||
UHTTP::usp->runDynamicPageParam(U_DPAGE_AUTH);
|
||||
UHTTP::usp = usp_save;
|
||||
return;
|
||||
}
|
||||
if (UHTTP::runUSP(U_CONSTANT_TO_PARAM("login_form"))) return;
|
||||
UHTTP::UFileCacheData* login_form_html = UHTTP::getFileCachePointer(U_CONSTANT_TO_PARAM("login_form.html"));
|
||||
if (login_form_html)
|
||||
{
|
||||
|
@ -55,8 +50,8 @@ extern U_EXPORT void runDynamicPage_index();
|
|||
(void) UClientImage_Base::wbuffer->append(U_CONSTANT_TO_PARAM(
|
||||
"<form method=\"post\">\n"
|
||||
" <p>Login</p>\n"
|
||||
" <p>username <input name=\"user\" type=\"text\" class=\"inputbox\" title=\"Enter your username\"></p>\n"
|
||||
" <p>password <input name=\"pass\" type=\"text\" class=\"inputbox\" title=\"Enter your password\"></p>\n"
|
||||
" <p>username <input name=\"username\" type=\"text\" class=\"inputbox\" title=\"Enter your username\"></p>\n"
|
||||
" <p>password <input name=\"password\" type=\"text\" class=\"inputbox\" title=\"Enter your password\"></p>\n"
|
||||
" <p><input type=\"submit\" value=\"login\"></p>\n"
|
||||
"</form>"));
|
||||
return;
|
||||
|
@ -73,5 +68,4 @@ extern U_EXPORT void runDynamicPage_index();
|
|||
|
||||
UHTTP::manageRequest(GET_table, U_NUM_ELEMENTS(GET_table), POST_table, U_NUM_ELEMENTS(POST_table));
|
||||
|
||||
U_http_info.endHeader = 0;
|
||||
} }
|
|
@ -240,7 +240,9 @@ public:
|
|||
}
|
||||
|
||||
UString setKeyIdDataSession(uint32_t counter);
|
||||
UString setKeyIdDataSession(uint32_t counter, const UString& data);
|
||||
UString setKeyIdDataSession(uint32_t counter, const UString& data) { return (keyid = getKeyIdDataSession(counter, data)); }
|
||||
|
||||
static UString getKeyIdDataSession(uint32_t counter, const UString& data);
|
||||
|
||||
// define method VIRTUAL of class UDataStorage
|
||||
|
||||
|
|
|
@ -751,9 +751,7 @@ public:
|
|||
{
|
||||
U_TRACE(0, "UHTTP::getKeyIdDataSession(%V)", data.rep)
|
||||
|
||||
U_INTERNAL_ASSERT_POINTER(data_session)
|
||||
|
||||
UString keyid = data_session->setKeyIdDataSession(++sid_counter_gen, data);
|
||||
UString keyid = UDataSession::getKeyIdDataSession(++sid_counter_gen, data);
|
||||
|
||||
U_RETURN_STRING(keyid);
|
||||
}
|
||||
|
@ -988,6 +986,8 @@ private:
|
|||
|
||||
static bool checkForUSP();
|
||||
static bool getUSP(const char* key, uint32_t key_len);
|
||||
static bool runUSP(const char* key, uint32_t key_len);
|
||||
static bool runUSP(const char* key, uint32_t key_len, int param);
|
||||
|
||||
// CSP (C Servlet Page)
|
||||
|
||||
|
|
|
@ -313,6 +313,9 @@ public:
|
|||
{
|
||||
U_ASSERT(vcode.empty())
|
||||
U_INTERNAL_ASSERT_EQUALS(bfirst_pass, false)
|
||||
U_INTERNAL_ASSERT_EQUALS(bhttp_header_empty, false)
|
||||
|
||||
bhttp_header_empty = true;
|
||||
|
||||
(void) output0.append(U_CONSTANT_TO_PARAM(
|
||||
"\n\tU_http_info.endHeader = 0;"
|
||||
|
@ -320,16 +323,11 @@ public:
|
|||
"\n\t UHTTP::getPostLoginUserPasswd())"
|
||||
"\n\t\t{"
|
||||
"\n\t\tUHTTP::usp->runDynamicPageParam(U_DPAGE_AUTH);"
|
||||
"\n\t\tif (*UClientImage_Base::wbuffer) return;"
|
||||
"\n\t\t}"
|
||||
"\n\tif (UHTTP::loginCookie->empty())"
|
||||
"\n\t\t{"
|
||||
"\n\t\tUHTTP::UServletPage* usp_save = UHTTP::usp;"
|
||||
"\n\t\tif (UHTTP::getUSP(U_CONSTANT_TO_PARAM(\"login_form\")))"
|
||||
"\n\t\t\t{"
|
||||
"\n\t\t\tUHTTP::usp->runDynamicPageParam(U_DPAGE_AUTH);"
|
||||
"\n\t\t\tUHTTP::usp = usp_save;"
|
||||
"\n\t\t\treturn;"
|
||||
"\n\t\t\t}"
|
||||
"\n\t\tif (UHTTP::runUSP(U_CONSTANT_TO_PARAM(\"login_form\"))) return;"
|
||||
"\n\t\tUHTTP::UFileCacheData* login_form_html = UHTTP::getFileCachePointer(U_CONSTANT_TO_PARAM(\"login_form.html\"));"
|
||||
"\n\t\tif (login_form_html)"
|
||||
"\n\t\t\t{"
|
||||
|
@ -340,8 +338,8 @@ public:
|
|||
"\n\t\t(void) UClientImage_Base::wbuffer->append(U_CONSTANT_TO_PARAM("
|
||||
"\n\"<form method=\\\"post\\\">\\n\""
|
||||
"\n\" <p>Login</p>\\n\""
|
||||
"\n\" <p>username <input name=\\\"user\\\" type=\\\"text\\\" class=\\\"inputbox\\\" title=\\\"Enter your username\\\"></p>\\n\""
|
||||
"\n\" <p>password <input name=\\\"pass\\\" type=\\\"text\\\" class=\\\"inputbox\\\" title=\\\"Enter your password\\\"></p>\\n\""
|
||||
"\n\" <p>username <input name=\\\"username\\\" type=\\\"text\\\" class=\\\"inputbox\\\" title=\\\"Enter your username\\\"></p>\\n\""
|
||||
"\n\" <p>password <input name=\\\"password\\\" type=\\\"text\\\" class=\\\"inputbox\\\" title=\\\"Enter your password\\\"></p>\\n\""
|
||||
"\n\" <p><input type=\\\"submit\\\" value=\\\"login\\\"></p>\\n\""
|
||||
"\n\"</form>\"));"
|
||||
"\n\t\treturn;"
|
||||
|
@ -870,7 +868,7 @@ loop: distance = t.getDistance();
|
|||
# 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)
|
||||
u_get_unalignedp32(usp.data()) == U_MULTICHAR_CONSTANT32('<','!','-','-')) // <!-- --> (comment)
|
||||
{
|
||||
(void) output1.append(U_CONSTANT_TO_PARAM("\n\tUClientImage_Base::setRequestNoCache();\n\t\n"));
|
||||
}
|
||||
|
|
|
@ -64,15 +64,15 @@ UString UDataSession::setKeyIdDataSession(uint32_t counter)
|
|||
U_RETURN_STRING(keyid);
|
||||
}
|
||||
|
||||
UString UDataSession::setKeyIdDataSession(uint32_t counter, const UString& data)
|
||||
UString UDataSession::getKeyIdDataSession(uint32_t counter, const UString& data)
|
||||
{
|
||||
U_TRACE(0, "UDataSession::setKeyIdDataSession(%u,%V)", counter, data.rep)
|
||||
|
||||
keyid.setBuffer(100U + data.size());
|
||||
UString _keyid(100U + data.size());
|
||||
|
||||
keyid.snprintf(U_CONSTANT_TO_PARAM("%.*s_%u_%P_%u:%v"), U_CLIENT_ADDRESS_TO_TRACE, UHTTP::getUserAgent(), counter, data.rep);
|
||||
_keyid.snprintf(U_CONSTANT_TO_PARAM("%.*s_%u_%P_%u:%v"), U_CLIENT_ADDRESS_TO_TRACE, UHTTP::getUserAgent(), counter, data.rep);
|
||||
|
||||
U_RETURN_STRING(keyid);
|
||||
U_RETURN_STRING(_keyid);
|
||||
}
|
||||
|
||||
#ifdef U_STDCPP_ENABLE
|
||||
|
|
|
@ -6101,7 +6101,11 @@ remove: removeCookieSession();
|
|||
continue;
|
||||
}
|
||||
|
||||
if (checkDataSession(token, expire, data)) result = true;
|
||||
if (data_session == U_NULLPTR ||
|
||||
checkDataSession(token, expire, data))
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
else if (cookie)
|
||||
{
|
||||
|
@ -6141,20 +6145,20 @@ bool UHTTP::getPostLoginUserPasswd()
|
|||
U_INTERNAL_ASSERT(loginCookieUser)
|
||||
U_INTERNAL_ASSERT(loginCookiePasswd)
|
||||
|
||||
loginCookieUser->clear();
|
||||
loginCookiePasswd->clear();
|
||||
|
||||
// $1 -> user
|
||||
// $2 -> pass
|
||||
// $1 -> username
|
||||
// $2 -> password
|
||||
|
||||
if (isPostLogin() &&
|
||||
processForm() >= 2*2)
|
||||
{
|
||||
UHTTP::getFormValue(*loginCookieUser, U_CONSTANT_TO_PARAM("user"), 0, 1, 4);
|
||||
loginCookieUser->clear();
|
||||
loginCookiePasswd->clear();
|
||||
|
||||
UHTTP::getFormValue(*loginCookieUser, U_CONSTANT_TO_PARAM("username"), 0, 1, 4);
|
||||
|
||||
if (*loginCookieUser)
|
||||
{
|
||||
UHTTP::getFormValue(*loginCookiePasswd, U_CONSTANT_TO_PARAM("pass"), 0, 3, 4);
|
||||
UHTTP::getFormValue(*loginCookiePasswd, U_CONSTANT_TO_PARAM("password"), 0, 3, 4);
|
||||
|
||||
if (*loginCookiePasswd) U_RETURN(true);
|
||||
}
|
||||
|
@ -6168,7 +6172,6 @@ U_NO_EXPORT bool UHTTP::checkDataSession(const UString& token, time_t expire, US
|
|||
U_TRACE(0, "UHTTP::checkDataSession(%V,%ld,%p)", token.rep, expire, data)
|
||||
|
||||
U_INTERNAL_ASSERT(token)
|
||||
U_INTERNAL_ASSERT_POINTER(db_session)
|
||||
U_INTERNAL_ASSERT_POINTER(data_session)
|
||||
|
||||
// NB: check for previous valid cookie...
|
||||
|
@ -6178,6 +6181,8 @@ U_NO_EXPORT bool UHTTP::checkDataSession(const UString& token, time_t expire, US
|
|||
if (data == U_NULLPTR ||
|
||||
data->empty())
|
||||
{
|
||||
U_INTERNAL_ASSERT_POINTER(db_session)
|
||||
|
||||
data_session->keyid = token;
|
||||
|
||||
db_session->setPointerToDataStorage(data_session);
|
||||
|
@ -7891,9 +7896,7 @@ UHTTP::UFileCacheData* UHTTP::getPasswdDB(const char* name, uint32_t len)
|
|||
{
|
||||
U_INTERNAL_ASSERT_EQUALS(name[0], '/')
|
||||
|
||||
UHTTP::UServletPage* usp_save = usp;
|
||||
|
||||
if (getUSP(name+1, len-1))
|
||||
if (runUSP(name+1, len-1, U_DPAGE_AUTH))
|
||||
{
|
||||
/**
|
||||
* Must set UHTTP::fpasswd as something like:
|
||||
|
@ -7909,12 +7912,8 @@ UHTTP::UFileCacheData* UHTTP::getPasswdDB(const char* name, uint32_t len)
|
|||
* NB: if UHTTP::buri_overload_authentication is set we authorize the request...
|
||||
*/
|
||||
|
||||
usp->runDynamicPageParam(U_DPAGE_AUTH);
|
||||
|
||||
U_INTERNAL_DUMP("fpasswd = %V buri_overload_authentication = %b", fpasswd->rep, buri_overload_authentication)
|
||||
|
||||
usp = usp_save;
|
||||
|
||||
U_RETURN_POINTER(U_NULLPTR, UHTTP::UFileCacheData);
|
||||
}
|
||||
}
|
||||
|
@ -8658,8 +8657,9 @@ void UHTTP::manageRequest(service_info* GET_table, uint32_t n1,
|
|||
|
||||
const char* ptr;
|
||||
service_info* key;
|
||||
uint32_t target_len;
|
||||
const char* suffix;
|
||||
int32_t cmp, probe, low;
|
||||
uint32_t len = 0, target_len;
|
||||
const char* target = UClientImage_Base::getRequestUri(target_len);
|
||||
|
||||
U_INTERNAL_ASSERT_EQUALS(target[0], '/')
|
||||
|
@ -8681,23 +8681,29 @@ void UHTTP::manageRequest(service_info* GET_table, uint32_t n1,
|
|||
return;
|
||||
}
|
||||
|
||||
ptr = (const char*) memchr(++target, PATH_SEPARATOR, target_len);
|
||||
ptr = (const char*) memchr(++target, PATH_SEPARATOR, target_len-1);
|
||||
|
||||
if (ptr) target_len = ptr - target;
|
||||
|
||||
U_INTERNAL_DUMP("target(%u) = %.*S", target_len, target_len, target)
|
||||
|
||||
ptr = u_getsuffix(target, target_len);
|
||||
|
||||
if (ptr != U_NULLPTR)
|
||||
if (ptr)
|
||||
{
|
||||
if (memcmp(ptr+1, U_CONSTANT_TO_PARAM("shtml"))) return; // NB: if we have a suffix different from '.shtml' (Ex: process.sh) we go to the next phase of request processing...
|
||||
cmp = ptr - target;
|
||||
|
||||
if (ptr) target_len = ptr - target;
|
||||
len = target_len-cmp-1;
|
||||
|
||||
U_INTERNAL_DUMP("target(%u) = %.*S", target_len, target_len, target)
|
||||
target_len = cmp;
|
||||
}
|
||||
|
||||
suffix = u_getsuffix(target, target_len);
|
||||
|
||||
if (suffix != U_NULLPTR)
|
||||
{
|
||||
if (memcmp(suffix+1, U_CONSTANT_TO_PARAM("shtml"))) return; // NB: if we have a suffix different from '.shtml' (Ex: process.sh) we go to the next phase of request processing...
|
||||
|
||||
if (suffix) target_len = suffix - target;
|
||||
}
|
||||
|
||||
retry:
|
||||
U_INTERNAL_DUMP("target(%u) = %.*S", target_len, target_len, target)
|
||||
|
||||
cmp =
|
||||
low = -1;
|
||||
|
||||
|
@ -8723,6 +8729,18 @@ void UHTTP::manageRequest(service_info* GET_table, uint32_t n1,
|
|||
if (low == -1 ||
|
||||
(key = table + low, key->len != target_len || memcmp(key->name, target, target_len)))
|
||||
{
|
||||
if (ptr)
|
||||
{
|
||||
target = ptr+1;
|
||||
ptr = U_NULLPTR;
|
||||
|
||||
target_len = len;
|
||||
|
||||
high = (isGETorHEAD() ? n1 : n2);
|
||||
|
||||
goto retry;
|
||||
}
|
||||
|
||||
U_http_info.nResponseCode = HTTP_BAD_REQUEST;
|
||||
|
||||
return;
|
||||
|
@ -12336,6 +12354,42 @@ found:
|
|||
U_RETURN(true);
|
||||
}
|
||||
|
||||
bool UHTTP::runUSP(const char* key, uint32_t key_len, int param)
|
||||
{
|
||||
U_TRACE(0, "UHTTP::runUSP(%.*S,%u,%d)", key_len, key, key_len, param)
|
||||
|
||||
UHTTP::UServletPage* usp_save = usp;
|
||||
|
||||
if (getUSP(key, key_len))
|
||||
{
|
||||
usp->runDynamicPageParam(param);
|
||||
|
||||
usp = usp_save;
|
||||
|
||||
U_RETURN(true);
|
||||
}
|
||||
|
||||
U_RETURN(false);
|
||||
}
|
||||
|
||||
bool UHTTP::runUSP(const char* key, uint32_t key_len)
|
||||
{
|
||||
U_TRACE(0, "UHTTP::runUSP(%.*S,%u)", key_len, key, key_len)
|
||||
|
||||
UHTTP::UServletPage* usp_save = usp;
|
||||
|
||||
if (getUSP(key, key_len))
|
||||
{
|
||||
usp->runDynamicPage();
|
||||
|
||||
usp = usp_save;
|
||||
|
||||
U_RETURN(true);
|
||||
}
|
||||
|
||||
U_RETURN(false);
|
||||
}
|
||||
|
||||
bool UHTTP::checkForUSP()
|
||||
{
|
||||
U_TRACE_NO_PARAM(0, "UHTTP::checkForUSP()")
|
||||
|
|
|
@ -1 +1 @@
|
|||
05AB
|
||||
05B8
|
||||
|
|
29
tests/examples/jon.sh
Executable file
29
tests/examples/jon.sh
Executable file
|
@ -0,0 +1,29 @@
|
|||
#!/bin/sh
|
||||
|
||||
. ../.function
|
||||
|
||||
rm -f JONATHAN/log/* /tmp/trace.*userver_tcp*.[0-9]* /tmp/object.*userver_tcp*.[0-9]* /tmp/stack.*userver_tcp*.[0-9]*
|
||||
|
||||
#UTRACE="0 50M 0"
|
||||
UTRACE_SIGNAL="0 5M -1"
|
||||
#UOBJDUMP="0 1M 300"
|
||||
UTRACE_FOLDER="/tmp"
|
||||
#USIMERR="error.sim"
|
||||
export UTRACE UTRACE_SIGNAL UOBJDUMP USIMERR UTRACE_FOLDER
|
||||
|
||||
export ORM_DRIVER="sqlite"
|
||||
export ORM_OPTION="host=localhost user=dbuser password=dbpass character-set=utf8 dbname=../db/concise-ile"
|
||||
|
||||
DIR_CMD="../../examples/userver"
|
||||
|
||||
compile_usp
|
||||
|
||||
#STRACE=$TRUSS
|
||||
start_prg_background userver_tcp -c JONATHAN/etc/userver.cfg
|
||||
|
||||
wait_server_ready localhost 8080
|
||||
|
||||
sync
|
||||
echo "PID = `cat JONATHAN/log/userver.pid`"
|
||||
|
||||
mv err/userver_tcp.err err/jon.err
|
Loading…
Reference in New Issue
Block a user