1
0
mirror of https://github.com/stefanocasazza/ULib.git synced 2025-09-28 19:05:55 +08:00
This commit is contained in:
stefanocasazza 2019-07-01 19:09:18 +02:00
parent 0acb747538
commit 8e882aa257
8 changed files with 134 additions and 57 deletions

View File

@ -35,16 +35,11 @@ extern U_EXPORT void runDynamicPage_index();
UHTTP::getPostLoginUserPasswd()) UHTTP::getPostLoginUserPasswd())
{ {
UHTTP::usp->runDynamicPageParam(U_DPAGE_AUTH); UHTTP::usp->runDynamicPageParam(U_DPAGE_AUTH);
if (*UClientImage_Base::wbuffer) return;
} }
if (UHTTP::loginCookie->empty()) if (UHTTP::loginCookie->empty())
{ {
UHTTP::UServletPage* usp_save = UHTTP::usp; if (UHTTP::runUSP(U_CONSTANT_TO_PARAM("login_form"))) return;
if (UHTTP::getUSP(U_CONSTANT_TO_PARAM("login_form")))
{
UHTTP::usp->runDynamicPageParam(U_DPAGE_AUTH);
UHTTP::usp = usp_save;
return;
}
UHTTP::UFileCacheData* login_form_html = UHTTP::getFileCachePointer(U_CONSTANT_TO_PARAM("login_form.html")); UHTTP::UFileCacheData* login_form_html = UHTTP::getFileCachePointer(U_CONSTANT_TO_PARAM("login_form.html"));
if (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( (void) UClientImage_Base::wbuffer->append(U_CONSTANT_TO_PARAM(
"<form method=\"post\">\n" "<form method=\"post\">\n"
" <p>Login</p>\n" " <p>Login</p>\n"
" <p>username <input name=\"user\" type=\"text\" class=\"inputbox\" title=\"Enter your username\"></p>\n" " <p>username <input name=\"username\" 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>password <input name=\"password\" type=\"text\" class=\"inputbox\" title=\"Enter your password\"></p>\n"
" <p><input type=\"submit\" value=\"login\"></p>\n" " <p><input type=\"submit\" value=\"login\"></p>\n"
"</form>")); "</form>"));
return; 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)); UHTTP::manageRequest(GET_table, U_NUM_ELEMENTS(GET_table), POST_table, U_NUM_ELEMENTS(POST_table));
U_http_info.endHeader = 0;
} } } }

View File

@ -240,7 +240,9 @@ public:
} }
UString setKeyIdDataSession(uint32_t counter); 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 // define method VIRTUAL of class UDataStorage

View File

@ -751,9 +751,7 @@ public:
{ {
U_TRACE(0, "UHTTP::getKeyIdDataSession(%V)", data.rep) U_TRACE(0, "UHTTP::getKeyIdDataSession(%V)", data.rep)
U_INTERNAL_ASSERT_POINTER(data_session) UString keyid = UDataSession::getKeyIdDataSession(++sid_counter_gen, data);
UString keyid = data_session->setKeyIdDataSession(++sid_counter_gen, data);
U_RETURN_STRING(keyid); U_RETURN_STRING(keyid);
} }
@ -988,6 +986,8 @@ private:
static bool checkForUSP(); static bool checkForUSP();
static bool getUSP(const char* key, uint32_t key_len); 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) // CSP (C Servlet Page)

View File

@ -313,6 +313,9 @@ public:
{ {
U_ASSERT(vcode.empty()) U_ASSERT(vcode.empty())
U_INTERNAL_ASSERT_EQUALS(bfirst_pass, false) 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( (void) output0.append(U_CONSTANT_TO_PARAM(
"\n\tU_http_info.endHeader = 0;" "\n\tU_http_info.endHeader = 0;"
@ -320,16 +323,11 @@ public:
"\n\t UHTTP::getPostLoginUserPasswd())" "\n\t UHTTP::getPostLoginUserPasswd())"
"\n\t\t{" "\n\t\t{"
"\n\t\tUHTTP::usp->runDynamicPageParam(U_DPAGE_AUTH);" "\n\t\tUHTTP::usp->runDynamicPageParam(U_DPAGE_AUTH);"
"\n\t\tif (*UClientImage_Base::wbuffer) return;"
"\n\t\t}" "\n\t\t}"
"\n\tif (UHTTP::loginCookie->empty())" "\n\tif (UHTTP::loginCookie->empty())"
"\n\t\t{" "\n\t\t{"
"\n\t\tUHTTP::UServletPage* usp_save = UHTTP::usp;" "\n\t\tif (UHTTP::runUSP(U_CONSTANT_TO_PARAM(\"login_form\"))) return;"
"\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\tUHTTP::UFileCacheData* login_form_html = UHTTP::getFileCachePointer(U_CONSTANT_TO_PARAM(\"login_form.html\"));" "\n\t\tUHTTP::UFileCacheData* login_form_html = UHTTP::getFileCachePointer(U_CONSTANT_TO_PARAM(\"login_form.html\"));"
"\n\t\tif (login_form_html)" "\n\t\tif (login_form_html)"
"\n\t\t\t{" "\n\t\t\t{"
@ -340,8 +338,8 @@ public:
"\n\t\t(void) UClientImage_Base::wbuffer->append(U_CONSTANT_TO_PARAM(" "\n\t\t(void) UClientImage_Base::wbuffer->append(U_CONSTANT_TO_PARAM("
"\n\"<form method=\\\"post\\\">\\n\"" "\n\"<form method=\\\"post\\\">\\n\""
"\n\" <p>Login</p>\\n\"" "\n\" <p>Login</p>\\n\""
"\n\" <p>username <input name=\\\"user\\\" type=\\\"text\\\" class=\\\"inputbox\\\" title=\\\"Enter your username\\\"></p>\\n\"" "\n\" <p>username <input name=\\\"username\\\" 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>password <input name=\\\"password\\\" type=\\\"text\\\" class=\\\"inputbox\\\" title=\\\"Enter your password\\\"></p>\\n\""
"\n\" <p><input type=\\\"submit\\\" value=\\\"login\\\"></p>\\n\"" "\n\" <p><input type=\\\"submit\\\" value=\\\"login\\\"></p>\\n\""
"\n\"</form>\"));" "\n\"</form>\"));"
"\n\t\treturn;" "\n\t\treturn;"
@ -870,7 +868,7 @@ loop: distance = t.getDistance();
# ifndef U_CACHE_REQUEST_DISABLE # ifndef U_CACHE_REQUEST_DISABLE
if (usp.c_char(4) == '#' && if (usp.c_char(4) == '#' &&
u__isspace(usp.c_char(5)) && 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")); (void) output1.append(U_CONSTANT_TO_PARAM("\n\tUClientImage_Base::setRequestNoCache();\n\t\n"));
} }

View File

@ -64,15 +64,15 @@ UString UDataSession::setKeyIdDataSession(uint32_t counter)
U_RETURN_STRING(keyid); 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) 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 #ifdef U_STDCPP_ENABLE

View File

@ -6101,7 +6101,11 @@ remove: removeCookieSession();
continue; continue;
} }
if (checkDataSession(token, expire, data)) result = true; if (data_session == U_NULLPTR ||
checkDataSession(token, expire, data))
{
result = true;
}
} }
else if (cookie) else if (cookie)
{ {
@ -6141,20 +6145,20 @@ bool UHTTP::getPostLoginUserPasswd()
U_INTERNAL_ASSERT(loginCookieUser) U_INTERNAL_ASSERT(loginCookieUser)
U_INTERNAL_ASSERT(loginCookiePasswd) U_INTERNAL_ASSERT(loginCookiePasswd)
loginCookieUser->clear(); // $1 -> username
loginCookiePasswd->clear(); // $2 -> password
// $1 -> user
// $2 -> pass
if (isPostLogin() && if (isPostLogin() &&
processForm() >= 2*2) 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) 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); 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_TRACE(0, "UHTTP::checkDataSession(%V,%ld,%p)", token.rep, expire, data)
U_INTERNAL_ASSERT(token) U_INTERNAL_ASSERT(token)
U_INTERNAL_ASSERT_POINTER(db_session)
U_INTERNAL_ASSERT_POINTER(data_session) U_INTERNAL_ASSERT_POINTER(data_session)
// NB: check for previous valid cookie... // 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 || if (data == U_NULLPTR ||
data->empty()) data->empty())
{ {
U_INTERNAL_ASSERT_POINTER(db_session)
data_session->keyid = token; data_session->keyid = token;
db_session->setPointerToDataStorage(data_session); 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], '/') U_INTERNAL_ASSERT_EQUALS(name[0], '/')
UHTTP::UServletPage* usp_save = usp; if (runUSP(name+1, len-1, U_DPAGE_AUTH))
if (getUSP(name+1, len-1))
{ {
/** /**
* Must set UHTTP::fpasswd as something like: * 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... * 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) U_INTERNAL_DUMP("fpasswd = %V buri_overload_authentication = %b", fpasswd->rep, buri_overload_authentication)
usp = usp_save;
U_RETURN_POINTER(U_NULLPTR, UHTTP::UFileCacheData); U_RETURN_POINTER(U_NULLPTR, UHTTP::UFileCacheData);
} }
} }
@ -8658,8 +8657,9 @@ void UHTTP::manageRequest(service_info* GET_table, uint32_t n1,
const char* ptr; const char* ptr;
service_info* key; service_info* key;
uint32_t target_len; const char* suffix;
int32_t cmp, probe, low; int32_t cmp, probe, low;
uint32_t len = 0, target_len;
const char* target = UClientImage_Base::getRequestUri(target_len); const char* target = UClientImage_Base::getRequestUri(target_len);
U_INTERNAL_ASSERT_EQUALS(target[0], '/') U_INTERNAL_ASSERT_EQUALS(target[0], '/')
@ -8681,23 +8681,29 @@ void UHTTP::manageRequest(service_info* GET_table, uint32_t n1,
return; 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; if (ptr)
U_INTERNAL_DUMP("target(%u) = %.*S", target_len, target_len, target)
ptr = u_getsuffix(target, target_len);
if (ptr != U_NULLPTR)
{ {
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 = cmp =
low = -1; low = -1;
@ -8723,6 +8729,18 @@ void UHTTP::manageRequest(service_info* GET_table, uint32_t n1,
if (low == -1 || if (low == -1 ||
(key = table + low, key->len != target_len || memcmp(key->name, target, target_len))) (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; U_http_info.nResponseCode = HTTP_BAD_REQUEST;
return; return;
@ -12336,6 +12354,42 @@ found:
U_RETURN(true); 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() bool UHTTP::checkForUSP()
{ {
U_TRACE_NO_PARAM(0, "UHTTP::checkForUSP()") U_TRACE_NO_PARAM(0, "UHTTP::checkForUSP()")

View File

@ -1 +1 @@
05AB 05B8

29
tests/examples/jon.sh Executable file
View 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