mirror of
https://github.com/stefanocasazza/ULib.git
synced 2025-09-28 19:05:55 +08:00
some fix
This commit is contained in:
parent
36a4502ca7
commit
2302132f3e
|
@ -42,11 +42,31 @@ static void usp_end_ir_web()
|
|||
U_DELETE(footer)
|
||||
}
|
||||
|
||||
static bool usp_bSESSION;
|
||||
|
||||
#define USP_SESSION_VAR_GET(index,varname) \
|
||||
{ \
|
||||
UString varname##_value; \
|
||||
if (UHTTP::getDataSession(index, varname##_value) && \
|
||||
(usp_sz = varname##_value.size())) \
|
||||
{ \
|
||||
UString2Object(varname##_value.data(), usp_sz, varname); \
|
||||
} \
|
||||
U_INTERNAL_DUMP("%s(%u) = %.*S", #varname, usp_sz, usp_sz, varname##_value.data()) \
|
||||
}
|
||||
|
||||
#define USP_SESSION_VAR_PUT(index,varname) \
|
||||
{ \
|
||||
usp_sz = UObject2String(varname, usp_buffer, sizeof(usp_buffer)); \
|
||||
UHTTP::putDataSession(index, usp_buffer, usp_sz); \
|
||||
}
|
||||
|
||||
static void usp_body_ir_web()
|
||||
{
|
||||
U_TRACE(5, "::usp_body_ir_web()")
|
||||
|
||||
if (UHTTP::getDataSession() == false) UHTTP::setSessionCookie();
|
||||
usp_bSESSION = (UHTTP::getDataSession() ? true : (UHTTP::setSessionCookie(), false));
|
||||
usp_bSESSION = true;
|
||||
const char* ref = "?ext=help";
|
||||
uint32_t num_args = UHTTP::processForm() / 2;
|
||||
bool form_with_help = false;
|
||||
|
@ -199,7 +219,7 @@ extern U_EXPORT void runDynamicPage_ir_web();
|
|||
U_TRACE_NO_PARAM(0, "::runDynamicPage_ir_web()")
|
||||
|
||||
usp_body_ir_web();
|
||||
UHTTP::putDataSession();
|
||||
if (usp_bSESSION) UHTTP::putDataSession();
|
||||
UHTTP::mime_index = U_html;
|
||||
U_http_info.endHeader = 0;
|
||||
} }
|
|
@ -44,10 +44,7 @@ public:
|
|||
bmode = false;
|
||||
}
|
||||
|
||||
~UEventDB()
|
||||
{
|
||||
U_TRACE_DTOR(0, UEventDB)
|
||||
}
|
||||
~UEventDB();
|
||||
|
||||
// SERVICES
|
||||
|
||||
|
@ -67,8 +64,18 @@ private:
|
|||
void* conn;
|
||||
uint32_t start, end;
|
||||
query_info query[512];
|
||||
int fd_conn;
|
||||
bool bmode;
|
||||
|
||||
static bool basync;
|
||||
static uint32_t nquery;
|
||||
|
||||
#ifdef DEBUG
|
||||
static uint32_t max_num_handler;
|
||||
#endif
|
||||
|
||||
uint32_t getResult(void* vresult);
|
||||
|
||||
U_DISALLOW_COPY_AND_ASSIGN(UEventDB)
|
||||
};
|
||||
#endif
|
||||
|
|
|
@ -105,14 +105,14 @@ public:
|
|||
{
|
||||
U_TRACE_NO_PARAM(0, "UClientImage_Base::setNoHeaderForResponse()")
|
||||
|
||||
iov_vec[1].iov_len = 0;
|
||||
iov_vec[0].iov_len = 0;
|
||||
}
|
||||
|
||||
static bool isNoHeaderForResponse()
|
||||
{
|
||||
U_TRACE_NO_PARAM(0, "UClientImage_Base::isNoHeaderForResponse()")
|
||||
|
||||
if (UNLIKELY(iov_vec[1].iov_len == 0)) U_RETURN(true);
|
||||
if (UNLIKELY(iov_vec[0].iov_len == 0)) U_RETURN(true);
|
||||
|
||||
U_RETURN(false);
|
||||
}
|
||||
|
@ -368,6 +368,8 @@ public:
|
|||
iov_vec[2].iov_len = sz;
|
||||
iov_vec[2].iov_base = (caddr_t)wbuffer->data();
|
||||
|
||||
U_INTERNAL_DUMP("iov_vec[0].iov_len = %u iov_vec[1].iov_len = %u", iov_vec[0].iov_len, iov_vec[1].iov_len)
|
||||
|
||||
U_INTERNAL_ASSERT_EQUALS(iov_vec[0].iov_len, 17)
|
||||
U_INTERNAL_ASSERT_EQUALS(iov_vec[1].iov_len, 51)
|
||||
|
||||
|
|
|
@ -43,40 +43,4 @@
|
|||
#define USP_FORM_NAME(n) (UHTTP::getFormValue(*UClientImage_Base::_value,(0+(n*2))), *UClientImage_Base::_value)
|
||||
#define USP_FORM_VALUE(n) (UHTTP::getFormValue(*UClientImage_Base::_value,(1+(n*2))), *UClientImage_Base::_value)
|
||||
#define USP_FORM_VALUE_FROM_NAME(name) (UHTTP::getFormValue(*UClientImage_Base::_value,U_CONSTANT_TO_PARAM(name)),*UClientImage_Base::_value)
|
||||
|
||||
#define USP_STORAGE_VAR_GET(index,varname) \
|
||||
{ \
|
||||
UString varname##_value; \
|
||||
if (UHTTP::getDataStorage(index, varname##_value) && \
|
||||
(usp_sz = varname##_value.size())) \
|
||||
{ \
|
||||
UString2Object(varname##_value.data(), usp_sz, varname); \
|
||||
} \
|
||||
}
|
||||
|
||||
#define USP_SESSION_VAR_GET(index,varname) \
|
||||
{ \
|
||||
UString varname##_value; \
|
||||
if (UHTTP::getDataSession(index, varname##_value) == false) UHTTP::setSessionCookie(); \
|
||||
else if ((usp_sz = varname##_value.size())) \
|
||||
{ \
|
||||
UString2Object(varname##_value.data(), usp_sz, varname); \
|
||||
} \
|
||||
}
|
||||
|
||||
#define USP_STORAGE_VAR_PUT(index,varname) \
|
||||
{ \
|
||||
usp_sz = UObject2String(varname, usp_buffer, sizeof(usp_buffer)); \
|
||||
UHTTP::putDataStorage(index, usp_buffer, usp_sz); \
|
||||
}
|
||||
|
||||
#define USP_SESSION_VAR_PUT(index,varname) \
|
||||
{ \
|
||||
if (UHTTP::isDataSession() && \
|
||||
(usp_sz = UObject2String(varname, usp_buffer, sizeof(usp_buffer)))) \
|
||||
{ \
|
||||
UHTTP::putDataSession(index, usp_buffer, usp_sz); \
|
||||
} \
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -170,10 +170,6 @@ public:
|
|||
virtual ~UDataSession()
|
||||
{
|
||||
U_TRACE_DTOR(0, UDataSession)
|
||||
|
||||
U_INTERNAL_ASSERT_POINTER(vec_var)
|
||||
|
||||
U_DELETE(vec_var)
|
||||
}
|
||||
|
||||
// SERVICES
|
||||
|
@ -224,10 +220,8 @@ public:
|
|||
{
|
||||
U_TRACE(0, "UDataSession::getValueVar(%u,%p)", index, &value)
|
||||
|
||||
U_INTERNAL_ASSERT_POINTER(vec_var)
|
||||
|
||||
if (index < vec_var->size()) value = vec_var->at(index);
|
||||
else value.clear();
|
||||
if (index < vec_var.size()) value = vec_var.at(index);
|
||||
else value.clear();
|
||||
|
||||
U_INTERNAL_DUMP("value = %V", value.rep)
|
||||
}
|
||||
|
@ -236,14 +230,12 @@ public:
|
|||
{
|
||||
U_TRACE(0, "UDataSession::putValueVar(%u,%V)", index, value.rep)
|
||||
|
||||
U_INTERNAL_ASSERT_POINTER(vec_var)
|
||||
|
||||
if (index < vec_var->size()) vec_var->replace(index, value);
|
||||
if (index < vec_var.size()) vec_var.replace(index, value);
|
||||
else
|
||||
{
|
||||
U_INTERNAL_ASSERT_EQUALS(index, vec_var->size())
|
||||
U_INTERNAL_ASSERT_EQUALS(index, vec_var.size())
|
||||
|
||||
vec_var->push_back(value);
|
||||
vec_var.push_back(value);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -256,9 +248,7 @@ public:
|
|||
{
|
||||
U_TRACE_NO_PARAM(0, "UDataSession::clear()")
|
||||
|
||||
U_INTERNAL_ASSERT_POINTER(vec_var)
|
||||
|
||||
vec_var->clear();
|
||||
vec_var.clear();
|
||||
}
|
||||
|
||||
// STREAM
|
||||
|
@ -276,7 +266,7 @@ public:
|
|||
#endif
|
||||
|
||||
protected:
|
||||
UVector<UString>* vec_var;
|
||||
UVector<UString> vec_var;
|
||||
long creation, last_access;
|
||||
|
||||
void init()
|
||||
|
@ -285,8 +275,6 @@ protected:
|
|||
|
||||
creation =
|
||||
last_access = u_now->tv_sec;
|
||||
|
||||
U_NEW(UVector<UString>, vec_var, UVector<UString>);
|
||||
}
|
||||
|
||||
private:
|
||||
|
|
|
@ -43,6 +43,10 @@ typedef int (*verify_cb)(int,X509_STORE_CTX*); /* error callback */
|
|||
#define FNM_CASEFOLD FNM_IGNORECASE
|
||||
#endif
|
||||
|
||||
// HTTP Access Authentication
|
||||
#define U_HTTP_QOP "auth"
|
||||
#define U_HTTP_REALM "Protected Area"
|
||||
|
||||
struct U_EXPORT UServices {
|
||||
|
||||
static bool isSetuidRoot(); // UID handling: check if we are setuid-root
|
||||
|
@ -169,6 +173,8 @@ struct U_EXPORT UServices {
|
|||
static void generateDigest(int alg, uint32_t keylen, const UString& data, UString& output, int base64 = 0)
|
||||
{ generateDigest(alg, keylen, (unsigned char*)U_STRING_TO_PARAM(data), output, base64); }
|
||||
|
||||
static bool setDigestCalcResponse(const UString& ha1, const UString& nc, const UString& nonce, const UString& cnonce, const UString& _uri, const UString& user, UString& response);
|
||||
|
||||
static UString generateCode(uint32_t len = 6)
|
||||
{
|
||||
U_TRACE(0, "UServices::generateCode(%u)", len)
|
||||
|
|
|
@ -27,8 +27,6 @@
|
|||
# include <ulib/container/vector.h>
|
||||
#endif
|
||||
|
||||
#define U_HTTP_REALM "Protected Area" // HTTP Access Authentication
|
||||
|
||||
#define U_MAX_UPLOAD_PROGRESS 16
|
||||
#define U_MIN_SIZE_FOR_DEFLATE 150 // NB: google advice...
|
||||
|
||||
|
@ -539,7 +537,7 @@ public:
|
|||
setErrorResponse(*UString::str_ctype_html, HTTP_ENTITY_TOO_LARGE, U_CONSTANT_TO_PARAM("Sorry, the data you requested is too large"), false);
|
||||
}
|
||||
|
||||
static void setUnAuthorized();
|
||||
static void setUnAuthorized(bool bstale);
|
||||
|
||||
static void setInternalError()
|
||||
{
|
||||
|
@ -1512,7 +1510,6 @@ private:
|
|||
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 void putDataInCache(const UString& path, const UString& fmt, UString& content) U_NO_EXPORT;
|
||||
static uint32_t checkPasswd(UFileCacheData* ptr_file_data, UString& fpasswd, const UString& line) U_NO_EXPORT;
|
||||
static void addContentLengthToHeader(UString& header, char* ptr, uint32_t size, const char* pEndHeader = U_NULLPTR) U_NO_EXPORT;
|
||||
static void setDataInCache(const UString& fmt, const UString& content, const char* encoding, uint32_t encoding_len) 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;
|
||||
|
@ -1538,6 +1535,9 @@ private:
|
|||
static inline void setXForwardedFor(const char* ptr, uint32_t len) U_NO_EXPORT;
|
||||
static inline void setXHttpForwardedFor(const char* ptr, uint32_t len) U_NO_EXPORT;
|
||||
|
||||
static uint32_t getPosPasswd(UString& fpasswd, const UString& line) U_NO_EXPORT;
|
||||
static uint32_t checkPasswd(UFileCacheData* ptr_file_data, UString& fpasswd, const UString& line) U_NO_EXPORT;
|
||||
|
||||
U_DISALLOW_COPY_AND_ASSIGN(UHTTP)
|
||||
|
||||
friend class UHTTP2;
|
||||
|
|
|
@ -19,7 +19,7 @@ VS_VERSION_INFO VERSIONINFO
|
|||
VALUE "InternalName", "libulib-1.4-2"
|
||||
VALUE "LegalCopyright", "Copyright © 2014 Unirel"
|
||||
VALUE "OriginalFilename", "libulib-1.4-2.dll"
|
||||
VALUE "ProductName", "Ulib"
|
||||
VALUE "ProductName", "ULib"
|
||||
VALUE "ProductVersion", "1.4.2"
|
||||
END
|
||||
END
|
||||
|
|
|
@ -174,6 +174,8 @@ int u_dgst_finish(unsigned char* restrict hash, int base64) /* Finish and get ha
|
|||
|
||||
if (u_hmac_keylen)
|
||||
{
|
||||
u_hmac_keylen = 0;
|
||||
|
||||
# if OPENSSL_VERSION_NUMBER < 0x10100000L
|
||||
HMAC_Final(&u_hctx, u_mdValue, (unsigned int*)&u_mdLen);
|
||||
# else
|
||||
|
|
|
@ -18,6 +18,22 @@
|
|||
# include <ulib/orm/driver/orm_driver_pgsql.h>
|
||||
#endif
|
||||
|
||||
bool UEventDB::basync;
|
||||
uint32_t UEventDB::nquery;
|
||||
#ifdef DEBUG
|
||||
uint32_t UEventDB::max_num_handler;
|
||||
#endif
|
||||
|
||||
UEventDB::~UEventDB()
|
||||
{
|
||||
U_TRACE_DTOR(0, UEventDB)
|
||||
|
||||
#ifdef DEBUG
|
||||
(void) UFile::writeToTmp(u_buffer, u__snprintf(u_buffer, U_BUFFER_SIZE, U_CONSTANT_TO_PARAM("max_num_handler: %u"), max_num_handler),
|
||||
O_RDWR | O_TRUNC, U_CONSTANT_TO_PARAM("event_db.%P"), 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
void UEventDB::setConnection(void* connection)
|
||||
{
|
||||
U_TRACE(0, "UEventDB::setConnection(%p)", connection)
|
||||
|
@ -29,11 +45,13 @@ void UEventDB::setConnection(void* connection)
|
|||
start = end = 0;
|
||||
|
||||
bmode = false;
|
||||
|
||||
#ifdef U_STATIC_ORM_DRIVER_PGSQL
|
||||
UEventFd::fd = U_SYSCALL(PQsocket, "%p", (PGconn*)conn);
|
||||
|
||||
(void) U_SYSCALL(PQsetnonblocking, "%p,%u", (PGconn*)conn, 1);
|
||||
U_INTERNAL_DUMP("basync = %b", basync)
|
||||
|
||||
#ifdef U_STATIC_ORM_DRIVER_PGSQL
|
||||
fd_conn = U_SYSCALL(PQsocket, "%p", (PGconn*)conn);
|
||||
|
||||
if (basync) UEventFd::fd = fd_conn;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -48,7 +66,13 @@ void UEventDB::handlerQuery(uint32_t num_query)
|
|||
U_INTERNAL_ASSERT_MINOR(end, 512)
|
||||
U_INTERNAL_ASSERT_MINOR(start, 512)
|
||||
|
||||
U_INTERNAL_DUMP("bmode = %b", bmode)
|
||||
#if defined(U_SERVER_CAPTIVE_PORTAL) && defined(ENABLE_THREAD)
|
||||
UClientImage_Base::setRequestProcessed();
|
||||
#endif
|
||||
|
||||
U_INTERNAL_DUMP("basync = %b bmode = %b", basync, bmode)
|
||||
|
||||
nquery = num_query;
|
||||
|
||||
#ifdef U_STATIC_ORM_DRIVER_PGSQL
|
||||
if (bmode)
|
||||
|
@ -57,7 +81,8 @@ void UEventDB::handlerQuery(uint32_t num_query)
|
|||
{
|
||||
bmode = false;
|
||||
|
||||
(void) U_SYSCALL(PQexitQueueMode, "%p", (PGconn*)conn);
|
||||
(void) U_SYSCALL(PQexitQueueMode, "%p", (PGconn*)conn);
|
||||
(void) U_SYSCALL(PQsetnonblocking, "%p,%u", (PGconn*)conn, 0);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -66,70 +91,37 @@ void UEventDB::handlerQuery(uint32_t num_query)
|
|||
{
|
||||
bmode = true;
|
||||
|
||||
(void) U_SYSCALL(PQenterQueueMode, "%p", (PGconn*)conn);
|
||||
(void) U_SYSCALL(PQsetnonblocking, "%p,%u", (PGconn*)conn, 1);
|
||||
(void) U_SYSCALL(PQenterQueueMode, "%p", (PGconn*)conn);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(U_SERVER_CAPTIVE_PORTAL) && defined(ENABLE_THREAD)
|
||||
UClientImage_Base::setRequestProcessed();
|
||||
#endif
|
||||
if (basync)
|
||||
{
|
||||
query_info* pquery = query+end;
|
||||
|
||||
query_info* pquery = query+end;
|
||||
|
||||
pquery->pClientImage = UServer_Base::pClientImage;
|
||||
pquery->num_query = num_query;
|
||||
pquery->num_result = 0;
|
||||
pquery->timestamp = u_now->tv_sec;
|
||||
}
|
||||
|
||||
void UEventDB::handlerResult(vPFpvu handler)
|
||||
{
|
||||
U_TRACE(0, "UEventDB::handlerQuery(%p)", handler)
|
||||
|
||||
U_CHECK_MEMORY
|
||||
|
||||
U_INTERNAL_DUMP("start = %u end = %u", start, end)
|
||||
|
||||
U_INTERNAL_ASSERT_MINOR(end, 512)
|
||||
U_INTERNAL_ASSERT_MINOR(start, 512)
|
||||
|
||||
query_info* pquery = query+end;
|
||||
|
||||
pquery->handlerResult = handler;
|
||||
|
||||
end = (end+1) & 511;
|
||||
|
||||
U_INTERNAL_DUMP("start = %u end = %u", start, end)
|
||||
|
||||
U_INTERNAL_ASSERT_MINOR(end, 512)
|
||||
U_INTERNAL_ASSERT_DIFFERS(end, start)
|
||||
|
||||
#ifdef U_STATIC_ORM_DRIVER_PGSQL
|
||||
if (bmode) (void) U_SYSCALL(PQsendQueue, "%p", (PGconn*)conn);
|
||||
pquery->pClientImage = UServer_Base::pClientImage;
|
||||
pquery->num_query = num_query;
|
||||
pquery->num_result = 0;
|
||||
pquery->timestamp = u_now->tv_sec;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
int UEventDB::handlerRead()
|
||||
uint32_t UEventDB::getResult(void* vresult)
|
||||
{
|
||||
U_TRACE_NO_PARAM(0, "UEventDB::handlerRead()")
|
||||
U_TRACE(0, "UEventDB::getResult(%p)", vresult)
|
||||
|
||||
U_CHECK_MEMORY
|
||||
|
||||
uint32_t num_result = 0;
|
||||
|
||||
U_INTERNAL_DUMP("basync = %b bmode = %b", basync, bmode)
|
||||
|
||||
#ifdef U_STATIC_ORM_DRIVER_PGSQL
|
||||
if (U_SYSCALL(PQconsumeInput, "%p", (PGconn*)conn) == 1)
|
||||
{
|
||||
PGresult* result;
|
||||
query_info* pquery;
|
||||
PGresult* vresult[1024];
|
||||
bool bopen[1024], bcheck;
|
||||
uint32_t i, index = start, num_open = 0, num_result = 0, num_handler = (end >= start ? end-start : (end+512)-start);
|
||||
|
||||
U_INTERNAL_DUMP("start = %u end = %u num_handler = %u", start, end, num_handler)
|
||||
|
||||
U_INTERNAL_ASSERT_MINOR(end, 512)
|
||||
U_INTERNAL_ASSERT_MINOR(start, 512)
|
||||
U_INTERNAL_ASSERT_MINOR(num_handler, 512)
|
||||
|
||||
while (U_SYSCALL(PQisBusy, "%p", (PGconn*)conn) == 0)
|
||||
{
|
||||
|
@ -144,93 +136,172 @@ int UEventDB::handlerRead()
|
|||
|
||||
U_INTERNAL_ASSERT_EQUALS(PQresultStatus(result), PGRES_TUPLES_OK)
|
||||
|
||||
vresult[num_result++] = result;
|
||||
((PGresult**)vresult)[num_result++] = result;
|
||||
|
||||
U_INTERNAL_ASSERT_RANGE(1,num_result,1023)
|
||||
}
|
||||
|
||||
U_INTERNAL_DUMP("bmode = %b num_result = %u", bmode, num_result)
|
||||
|
||||
U_INTERNAL_ASSERT_RANGE(1,num_result,1023)
|
||||
U_INTERNAL_ASSERT(num_result <= num_handler)
|
||||
|
||||
for (i = 0; i < num_handler; ++i)
|
||||
{
|
||||
pquery = query+index;
|
||||
|
||||
if ((bopen[i] = pquery->pClientImage->isOpen())) ++num_open;
|
||||
|
||||
U_INTERNAL_DUMP("bopen[%u] = %b pquery->num_query = %u pquery->num_result = %u (now-timestamp) = %#2D",
|
||||
i, bopen[i], pquery->num_query, pquery->num_result, u_now->tv_sec - pquery->timestamp)
|
||||
|
||||
index = (index+1) & 511;
|
||||
|
||||
U_INTERNAL_ASSERT_MINOR(index, 512)
|
||||
}
|
||||
|
||||
U_INTERNAL_DUMP("num_open = %u", num_open)
|
||||
|
||||
if (num_open == 0)
|
||||
{
|
||||
start = end = 0;
|
||||
|
||||
goto end;
|
||||
}
|
||||
|
||||
U_INTERNAL_ASSERT_RANGE(1,num_open,1023)
|
||||
U_INTERNAL_ASSERT(num_open <= num_handler)
|
||||
|
||||
i = 0;
|
||||
bcheck = (num_open != num_result);
|
||||
|
||||
U_INTERNAL_DUMP("bcheck = %b", bcheck)
|
||||
|
||||
loop: if (bopen[i] == false) goto next;
|
||||
|
||||
pquery = query+start;
|
||||
|
||||
if (bcheck &&
|
||||
((u_now->tv_sec - pquery->timestamp) > 10)) // 10 second connection/read timeout
|
||||
{
|
||||
U_INTERNAL_DUMP("num_open = %u num_result = %u", num_open, num_result)
|
||||
|
||||
if (--num_open == num_result) bcheck = false;
|
||||
|
||||
pquery->pClientImage->abortive_close();
|
||||
|
||||
goto next;
|
||||
}
|
||||
|
||||
pquery->num_result++;
|
||||
|
||||
result = vresult[i++];
|
||||
|
||||
pquery->handlerResult(result, pquery->num_result);
|
||||
|
||||
if (pquery->num_query == pquery->num_result)
|
||||
{
|
||||
pquery->pClientImage->writeResponseCompact();
|
||||
|
||||
next: start = (start+1) & 511;
|
||||
|
||||
U_INTERNAL_ASSERT_MINOR(start, 512)
|
||||
|
||||
if (start == end)
|
||||
{
|
||||
U_INTERNAL_DUMP("i = %u num_result = %u", i, num_result)
|
||||
|
||||
U_INTERNAL_ASSERT_EQUALS(i, num_result)
|
||||
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
|
||||
U_INTERNAL_DUMP("i = %u num_result = %u", i, num_result)
|
||||
|
||||
if (i < num_result) goto loop;
|
||||
|
||||
end: for (i = 0; i < num_result; ++i) U_SYSCALL_VOID(PQclear, "%p", vresult[i]);
|
||||
}
|
||||
#endif
|
||||
|
||||
U_RETURN(num_result);
|
||||
}
|
||||
|
||||
void UEventDB::handlerResult(vPFpvu handler)
|
||||
{
|
||||
U_TRACE(0, "UEventDB::handlerQuery(%p)", handler)
|
||||
|
||||
U_CHECK_MEMORY
|
||||
|
||||
U_INTERNAL_DUMP("start = %u end = %u", start, end)
|
||||
|
||||
U_INTERNAL_ASSERT_MINOR(end, 512)
|
||||
U_INTERNAL_ASSERT_MINOR(start, 512)
|
||||
|
||||
U_INTERNAL_DUMP("basync = %b bmode = %b", basync, bmode)
|
||||
|
||||
#ifdef U_STATIC_ORM_DRIVER_PGSQL
|
||||
if (bmode) (void) U_SYSCALL(PQsendQueue, "%p", (PGconn*)conn);
|
||||
|
||||
if (basync)
|
||||
{
|
||||
query[end].handlerResult = handler;
|
||||
|
||||
end = (end+1) & 511;
|
||||
|
||||
U_INTERNAL_DUMP("start = %u end = %u", start, end)
|
||||
|
||||
U_INTERNAL_ASSERT_MINOR(end, 512)
|
||||
U_INTERNAL_ASSERT_DIFFERS(end, start)
|
||||
}
|
||||
else
|
||||
{
|
||||
if (UNotifier::waitForRead(fd_conn))
|
||||
{
|
||||
PGresult* result;
|
||||
PGresult* vresult[1024];
|
||||
|
||||
uint32_t num_result = getResult(vresult);
|
||||
|
||||
U_INTERNAL_ASSERT_EQUALS(nquery, num_result)
|
||||
|
||||
for (uint32_t i = 0; i < num_result; ++i)
|
||||
{
|
||||
handler(result = vresult[i], i+1);
|
||||
|
||||
U_SYSCALL_VOID(PQclear, "%p", result);
|
||||
}
|
||||
|
||||
UServer_Base::pClientImage->writeResponseCompact();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
int UEventDB::handlerRead()
|
||||
{
|
||||
U_TRACE_NO_PARAM(0, "UEventDB::handlerRead()")
|
||||
|
||||
U_CHECK_MEMORY
|
||||
|
||||
#ifdef U_STATIC_ORM_DRIVER_PGSQL
|
||||
PGresult* result;
|
||||
query_info* pquery;
|
||||
PGresult* vresult[1024];
|
||||
bool bopen[1024], bcheck;
|
||||
uint32_t i, index = start, num_open = 0, num_handler = (end >= start ? end-start : (end+512)-start);
|
||||
|
||||
U_INTERNAL_DUMP("start = %u end = %u num_handler = %u", start, end, num_handler)
|
||||
|
||||
U_INTERNAL_ASSERT_MINOR(end, 512)
|
||||
U_INTERNAL_ASSERT_MINOR(start, 512)
|
||||
U_INTERNAL_ASSERT_MINOR(num_handler, 512)
|
||||
|
||||
#ifdef DEBUG
|
||||
if (max_num_handler < num_handler) max_num_handler = num_handler;
|
||||
#endif
|
||||
|
||||
uint32_t num_result = getResult(vresult);
|
||||
|
||||
U_INTERNAL_ASSERT_RANGE(1,num_result,1023)
|
||||
U_INTERNAL_ASSERT(num_result <= num_handler)
|
||||
|
||||
for (i = 0; i < num_handler; ++i)
|
||||
{
|
||||
pquery = query+index;
|
||||
|
||||
if ((bopen[i] = pquery->pClientImage->isOpen())) ++num_open;
|
||||
|
||||
U_INTERNAL_DUMP("bopen[%u] = %b pquery->num_query = %u pquery->num_result = %u (now-timestamp) = %#2D",
|
||||
i, bopen[i], pquery->num_query, pquery->num_result, u_now->tv_sec - pquery->timestamp)
|
||||
|
||||
index = (index+1) & 511;
|
||||
|
||||
U_INTERNAL_ASSERT_MINOR(index, 512)
|
||||
}
|
||||
|
||||
U_INTERNAL_DUMP("num_open = %u", num_open)
|
||||
|
||||
if (num_open == 0)
|
||||
{
|
||||
start = end = 0;
|
||||
|
||||
for (i = 0; i < num_result; ++i) U_SYSCALL_VOID(PQclear, "%p", vresult[i]);
|
||||
|
||||
U_RETURN(U_NOTIFIER_OK);
|
||||
}
|
||||
|
||||
U_INTERNAL_ASSERT_RANGE(1,num_open,1023)
|
||||
U_INTERNAL_ASSERT(num_open <= num_handler)
|
||||
|
||||
i = 0;
|
||||
bcheck = (num_open != num_result);
|
||||
|
||||
U_INTERNAL_DUMP("bcheck = %b", bcheck)
|
||||
|
||||
loop:
|
||||
if (bopen[i] == false) goto next;
|
||||
|
||||
pquery = query+start;
|
||||
|
||||
if (bcheck &&
|
||||
((u_now->tv_sec - pquery->timestamp) > 10)) // 10 second connection/read timeout
|
||||
{
|
||||
U_INTERNAL_DUMP("num_open = %u num_result = %u", num_open, num_result)
|
||||
|
||||
if (--num_open == num_result) bcheck = false;
|
||||
|
||||
pquery->pClientImage->abortive_close();
|
||||
|
||||
goto next;
|
||||
}
|
||||
|
||||
pquery->handlerResult(result = vresult[i++], pquery->num_result += 1);
|
||||
|
||||
U_SYSCALL_VOID(PQclear, "%p", result);
|
||||
|
||||
if (pquery->num_query == pquery->num_result)
|
||||
{
|
||||
pquery->pClientImage->writeResponseCompact();
|
||||
|
||||
next: start = (start+1) & 511;
|
||||
|
||||
U_INTERNAL_ASSERT_MINOR(start, 512)
|
||||
|
||||
if (start == end)
|
||||
{
|
||||
U_INTERNAL_DUMP("i = %u num_result = %u", i, num_result)
|
||||
|
||||
U_INTERNAL_ASSERT_EQUALS(i, num_result)
|
||||
|
||||
U_RETURN(U_NOTIFIER_OK);
|
||||
}
|
||||
}
|
||||
|
||||
U_INTERNAL_DUMP("i = %u num_result = %u", i, num_result)
|
||||
|
||||
if (i < num_result) goto loop;
|
||||
#endif
|
||||
|
||||
U_RETURN(U_NOTIFIER_OK);
|
||||
}
|
||||
|
||||
|
@ -239,10 +310,11 @@ end: for (i = 0; i < num_result; ++i) U_SYSCALL_VOID(PQclear, "%p", vresult[i])
|
|||
#ifdef DEBUG
|
||||
const char* UEventDB::dump(bool _reset) const
|
||||
{
|
||||
*UObjectIO::os << "end " << end << '\n'
|
||||
<< "conn " << (void*)conn << '\n'
|
||||
<< "bmode " << bmode << '\n'
|
||||
<< "start " << start;
|
||||
*UObjectIO::os << "end " << end << '\n'
|
||||
<< "conn " << (void*)conn << '\n'
|
||||
<< "bmode " << bmode << '\n'
|
||||
<< "start " << start << '\n'
|
||||
<< "fd_conn " << fd_conn;
|
||||
|
||||
if (_reset)
|
||||
{
|
||||
|
|
198
src/ulib/log.cpp
198
src/ulib/log.cpp
|
@ -196,48 +196,38 @@ void ULog::updateDate1()
|
|||
* 012345678901234567890123456789
|
||||
*/
|
||||
|
||||
#if defined(U_LINUX) && defined(ENABLE_THREAD)
|
||||
# ifdef U_SERVER_CAPTIVE_PORTAL
|
||||
U_INTERNAL_ASSERT_POINTER(u_pthread_time)
|
||||
# else
|
||||
#if defined(U_LINUX) && !defined(U_SERVER_CAPTIVE_PORTAL) && defined(ENABLE_THREAD)
|
||||
if (u_pthread_time)
|
||||
# endif
|
||||
{
|
||||
# ifndef U_SERVER_CAPTIVE_PORTAL
|
||||
(void) U_SYSCALL(pthread_rwlock_rdlock, "%p", prwlock);
|
||||
# endif
|
||||
|
||||
if (tv_sec_old_1 != u_now->tv_sec)
|
||||
{
|
||||
long tv_sec = u_now->tv_sec;
|
||||
|
||||
U_INTERNAL_DUMP("tv_sec_old_1 = %lu u_now->tv_sec = %lu", tv_sec_old_1, tv_sec)
|
||||
|
||||
if ((tv_sec - tv_sec_old_1) != 1 ||
|
||||
(tv_sec % U_ONE_HOUR_IN_SECOND) == 0)
|
||||
if (tv_sec_old_1 != u_now->tv_sec)
|
||||
{
|
||||
tv_sec_old_1 = tv_sec;
|
||||
(void) U_SYSCALL(pthread_rwlock_rdlock, "%p", prwlock);
|
||||
|
||||
U_MEMCPY(date.date1, ptr_shared_date->date1, 17);
|
||||
long tv_sec = u_now->tv_sec;
|
||||
|
||||
U_INTERNAL_DUMP("tv_sec_old_1 = %lu u_now->tv_sec = %lu", tv_sec_old_1, tv_sec)
|
||||
|
||||
if ((tv_sec - tv_sec_old_1) != 1 ||
|
||||
(tv_sec % U_ONE_HOUR_IN_SECOND) == 0)
|
||||
{
|
||||
tv_sec_old_1 = tv_sec;
|
||||
|
||||
U_MEMCPY(date.date1, ptr_shared_date->date1, 17);
|
||||
}
|
||||
else
|
||||
{
|
||||
++tv_sec_old_1;
|
||||
|
||||
u_put_unalignedp16(date.date1+12, U_MULTICHAR_CONSTANT16(ptr_shared_date->date1[12],ptr_shared_date->date1[13]));
|
||||
u_put_unalignedp16(date.date1+12+3,U_MULTICHAR_CONSTANT16(ptr_shared_date->date1[15],ptr_shared_date->date1[16]));
|
||||
}
|
||||
|
||||
U_INTERNAL_ASSERT_EQUALS(tv_sec, tv_sec_old_1)
|
||||
|
||||
(void) U_SYSCALL(pthread_rwlock_unlock, "%p", prwlock);
|
||||
}
|
||||
else
|
||||
{
|
||||
++tv_sec_old_1;
|
||||
|
||||
u_put_unalignedp16(date.date1+12, U_MULTICHAR_CONSTANT16(ptr_shared_date->date1[12],ptr_shared_date->date1[13]));
|
||||
u_put_unalignedp16(date.date1+12+3,U_MULTICHAR_CONSTANT16(ptr_shared_date->date1[15],ptr_shared_date->date1[16]));
|
||||
}
|
||||
|
||||
U_INTERNAL_ASSERT_EQUALS(tv_sec, tv_sec_old_1)
|
||||
}
|
||||
|
||||
# ifndef U_SERVER_CAPTIVE_PORTAL
|
||||
(void) U_SYSCALL(pthread_rwlock_unlock, "%p", prwlock);
|
||||
# endif
|
||||
}
|
||||
# ifndef U_SERVER_CAPTIVE_PORTAL
|
||||
else
|
||||
# endif
|
||||
#endif
|
||||
{
|
||||
U_INTERNAL_ASSERT_EQUALS(u_pthread_time, U_NULLPTR)
|
||||
|
@ -278,39 +268,42 @@ void ULog::updateDate2()
|
|||
* 012345678901234567890123456789
|
||||
*/
|
||||
|
||||
#if defined(U_LINUX) && defined(ENABLE_THREAD)
|
||||
# ifndef U_SERVER_CAPTIVE_PORTAL
|
||||
(void) U_SYSCALL(pthread_rwlock_rdlock, "%p", prwlock);
|
||||
# endif
|
||||
|
||||
if (tv_sec_old_2 != u_now->tv_sec)
|
||||
#if defined(U_LINUX) && !defined(U_SERVER_CAPTIVE_PORTAL) && defined(ENABLE_THREAD)
|
||||
if (u_pthread_time)
|
||||
{
|
||||
long tv_sec = u_now->tv_sec;
|
||||
|
||||
U_INTERNAL_DUMP("tv_sec_old_2 = %lu u_now->tv_sec = %lu", tv_sec_old_2, tv_sec)
|
||||
|
||||
if ((tv_sec - tv_sec_old_2) != 1 ||
|
||||
(tv_sec % U_ONE_HOUR_IN_SECOND) == 0)
|
||||
if (tv_sec_old_2 != u_now->tv_sec)
|
||||
{
|
||||
tv_sec_old_2 = tv_sec;
|
||||
(void) U_SYSCALL(pthread_rwlock_rdlock, "%p", prwlock);
|
||||
|
||||
U_MEMCPY(date.date2, ptr_shared_date->date2, 26);
|
||||
long tv_sec = u_now->tv_sec;
|
||||
|
||||
U_INTERNAL_DUMP("tv_sec_old_2 = %lu u_now->tv_sec = %lu", tv_sec_old_2, tv_sec)
|
||||
|
||||
if ((tv_sec - tv_sec_old_2) != 1 ||
|
||||
(tv_sec % U_ONE_HOUR_IN_SECOND) == 0)
|
||||
{
|
||||
tv_sec_old_2 = tv_sec;
|
||||
|
||||
U_MEMCPY(date.date2, ptr_shared_date->date2, 26);
|
||||
}
|
||||
else
|
||||
{
|
||||
++tv_sec_old_2;
|
||||
|
||||
u_put_unalignedp16(date.date2+15, U_MULTICHAR_CONSTANT16(ptr_shared_date->date2[15],ptr_shared_date->date2[16]));
|
||||
u_put_unalignedp16(date.date2+15+3,U_MULTICHAR_CONSTANT16(ptr_shared_date->date2[18],ptr_shared_date->date2[19]));
|
||||
}
|
||||
|
||||
U_INTERNAL_ASSERT_EQUALS(tv_sec, tv_sec_old_2)
|
||||
|
||||
(void) U_SYSCALL(pthread_rwlock_unlock, "%p", prwlock);
|
||||
}
|
||||
else
|
||||
{
|
||||
++tv_sec_old_2;
|
||||
|
||||
u_put_unalignedp16(date.date2+15, U_MULTICHAR_CONSTANT16(ptr_shared_date->date2[15],ptr_shared_date->date2[16]));
|
||||
u_put_unalignedp16(date.date2+15+3,U_MULTICHAR_CONSTANT16(ptr_shared_date->date2[18],ptr_shared_date->date2[19]));
|
||||
}
|
||||
|
||||
U_INTERNAL_ASSERT_EQUALS(tv_sec, tv_sec_old_2)
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
U_INTERNAL_ASSERT_EQUALS(u_pthread_time, U_NULLPTR)
|
||||
|
||||
# ifndef U_SERVER_CAPTIVE_PORTAL
|
||||
(void) U_SYSCALL(pthread_rwlock_unlock, "%p", prwlock);
|
||||
# endif
|
||||
#else
|
||||
u_gettimenow();
|
||||
|
||||
if (tv_sec_old_2 != u_now->tv_sec)
|
||||
|
@ -333,7 +326,7 @@ void ULog::updateDate2()
|
|||
|
||||
U_INTERNAL_ASSERT_EQUALS(tv_sec, tv_sec_old_2)
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
U_INTERNAL_DUMP("date.date2 = %.26S", date.date2)
|
||||
}
|
||||
|
@ -348,51 +341,54 @@ void ULog::updateDate3(char* ptr_date)
|
|||
* 0123456789012345678901234567890123456789
|
||||
*/
|
||||
|
||||
#if defined(U_LINUX) && defined(ENABLE_THREAD)
|
||||
# ifndef U_SERVER_CAPTIVE_PORTAL
|
||||
(void) U_SYSCALL(pthread_rwlock_rdlock, "%p", prwlock);
|
||||
# endif
|
||||
|
||||
if (tv_sec_old_3 != u_now->tv_sec)
|
||||
#if defined(U_LINUX) && !defined(U_SERVER_CAPTIVE_PORTAL) && defined(ENABLE_THREAD)
|
||||
if (u_pthread_time)
|
||||
{
|
||||
long tv_sec = u_now->tv_sec;
|
||||
|
||||
U_INTERNAL_DUMP("tv_sec_old_3 = %lu u_now->tv_sec = %lu", tv_sec_old_3, tv_sec)
|
||||
|
||||
/*
|
||||
U_INTERNAL_ASSERT_DIFFERS(u_get_unalignedp64( date.date3+6+U_CONSTANT_SIZE("Wed, 20 Jun 2012 ")),
|
||||
u_get_unalignedp64(ptr_shared_date->date3+6+U_CONSTANT_SIZE("Wed, 20 Jun 2012 ")))
|
||||
*/
|
||||
|
||||
if ((tv_sec - tv_sec_old_3) != 1 ||
|
||||
(tv_sec % U_ONE_HOUR_IN_SECOND) == 0)
|
||||
if (tv_sec_old_3 != u_now->tv_sec)
|
||||
{
|
||||
tv_sec_old_3 = tv_sec;
|
||||
(void) U_SYSCALL(pthread_rwlock_rdlock, "%p", prwlock);
|
||||
|
||||
U_MEMCPY(date.date3+6, ptr_shared_date->date3+6, 29-4);
|
||||
if (ptr_date) U_MEMCPY( ptr_date+6, ptr_shared_date->date3+6, 29-4);
|
||||
}
|
||||
else
|
||||
{
|
||||
++tv_sec_old_3;
|
||||
long tv_sec = u_now->tv_sec;
|
||||
|
||||
u_put_unalignedp16(date.date3+26, U_MULTICHAR_CONSTANT16(ptr_shared_date->date3[26],ptr_shared_date->date3[27]));
|
||||
u_put_unalignedp16(date.date3+26+3,U_MULTICHAR_CONSTANT16(ptr_shared_date->date3[29],ptr_shared_date->date3[30]));
|
||||
U_INTERNAL_DUMP("tv_sec_old_3 = %lu u_now->tv_sec = %lu", tv_sec_old_3, tv_sec)
|
||||
|
||||
if (ptr_date)
|
||||
/*
|
||||
U_INTERNAL_ASSERT_DIFFERS(u_get_unalignedp64( date.date3+6+U_CONSTANT_SIZE("Wed, 20 Jun 2012 ")),
|
||||
u_get_unalignedp64(ptr_shared_date->date3+6+U_CONSTANT_SIZE("Wed, 20 Jun 2012 ")))
|
||||
*/
|
||||
|
||||
if ((tv_sec - tv_sec_old_3) != 1 ||
|
||||
(tv_sec % U_ONE_HOUR_IN_SECOND) == 0)
|
||||
{
|
||||
u_put_unalignedp16(ptr_date+26, U_MULTICHAR_CONSTANT16(ptr_shared_date->date3[26],ptr_shared_date->date3[27]));
|
||||
u_put_unalignedp16(ptr_date+26+3,U_MULTICHAR_CONSTANT16(ptr_shared_date->date3[29],ptr_shared_date->date3[30]));
|
||||
tv_sec_old_3 = tv_sec;
|
||||
|
||||
U_MEMCPY(date.date3+6, ptr_shared_date->date3+6, 29-4);
|
||||
if (ptr_date) U_MEMCPY( ptr_date+6, ptr_shared_date->date3+6, 29-4);
|
||||
}
|
||||
else
|
||||
{
|
||||
++tv_sec_old_3;
|
||||
|
||||
u_put_unalignedp16(date.date3+26, U_MULTICHAR_CONSTANT16(ptr_shared_date->date3[26],ptr_shared_date->date3[27]));
|
||||
u_put_unalignedp16(date.date3+26+3,U_MULTICHAR_CONSTANT16(ptr_shared_date->date3[29],ptr_shared_date->date3[30]));
|
||||
|
||||
if (ptr_date)
|
||||
{
|
||||
u_put_unalignedp16(ptr_date+26, U_MULTICHAR_CONSTANT16(ptr_shared_date->date3[26],ptr_shared_date->date3[27]));
|
||||
u_put_unalignedp16(ptr_date+26+3,U_MULTICHAR_CONSTANT16(ptr_shared_date->date3[29],ptr_shared_date->date3[30]));
|
||||
}
|
||||
}
|
||||
|
||||
U_INTERNAL_ASSERT_EQUALS(tv_sec, tv_sec_old_3)
|
||||
|
||||
(void) U_SYSCALL(pthread_rwlock_unlock, "%p", prwlock);
|
||||
}
|
||||
|
||||
U_INTERNAL_ASSERT_EQUALS(tv_sec, tv_sec_old_3)
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
U_INTERNAL_ASSERT_EQUALS(u_pthread_time, U_NULLPTR)
|
||||
|
||||
# ifndef U_SERVER_CAPTIVE_PORTAL
|
||||
(void) U_SYSCALL(pthread_rwlock_unlock, "%p", prwlock);
|
||||
# endif
|
||||
#else
|
||||
u_gettimenow();
|
||||
|
||||
if (tv_sec_old_3 != u_now->tv_sec)
|
||||
|
@ -418,11 +414,11 @@ void ULog::updateDate3(char* ptr_date)
|
|||
|
||||
U_INTERNAL_ASSERT_EQUALS(tv_sec, tv_sec_old_3)
|
||||
}
|
||||
#endif
|
||||
|
||||
U_INTERNAL_DUMP("date.date3+6 = %.29S", date.date3+6)
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
U_INTERNAL_DUMP("date.date3+6 = %.29S", date.date3+6)
|
||||
|
||||
if (ptr_date) U_INTERNAL_DUMP("ptr_date+6 = %.29S", ptr_date+6)
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -1198,6 +1198,8 @@ start:
|
|||
U_ASSERT(isOpen())
|
||||
|
||||
UServer_Base::nread++;
|
||||
|
||||
U_INTERNAL_DUMP("iov_vec[0].iov_len = %u iov_vec[1].iov_len = %u", iov_vec[0].iov_len, iov_vec[1].iov_len)
|
||||
#endif
|
||||
|
||||
loop:
|
||||
|
@ -1579,6 +1581,8 @@ error:
|
|||
{
|
||||
end: if (U_ClientImage_parallelization == U_PARALLELIZATION_CHILD) goto death;
|
||||
|
||||
setHeaderForResponse(6+29+2+12+2); // Date: Wed, 20 Jun 2012 11:43:17 GMT\r\nServer: ULib\r\n
|
||||
|
||||
U_RETURN(U_NOTIFIER_DELETE);
|
||||
}
|
||||
|
||||
|
@ -1673,7 +1677,7 @@ bool UClientImage_Base::writeResponse()
|
|||
if (U_ClientImage_close &&
|
||||
U_ClientImage_pipeline == false)
|
||||
{
|
||||
iov_vec[1].iov_len += 17+2; // Connection: close\r\n
|
||||
iov_vec[1].iov_len = 6+29+2+12+2+17+2; // Date: Wed, 20 Jun 2012 11:43:17 GMT\r\nServer: ULib\r\nConnection: close\r\n
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -531,7 +531,7 @@ int UHttpPlugIn::handlerRun() // NB: we use this method instead of handlerInit()
|
|||
UServer_Base::update_date =
|
||||
UServer_Base::update_date3 = true;
|
||||
|
||||
UClientImage_Base::iov_vec[1].iov_len = 6+29+2+12+2+17+2;
|
||||
UClientImage_Base::iov_vec[1].iov_len = 6+29+2+12+2; //+17+2;
|
||||
UClientImage_Base::iov_vec[1].iov_base = (caddr_t)ULog::date.date3; // Date: Wed, 20 Jun 2012 11:43:17 GMT\r\nServer: ULib\r\nConnection: close\r\n
|
||||
|
||||
#if defined(U_LINUX) && defined(ENABLE_THREAD)
|
||||
|
|
|
@ -17,7 +17,7 @@ if (delete_cookie) UHTTP::removeDataSession();
|
|||
-->
|
||||
<html>
|
||||
<head>
|
||||
<title>Hello World-application for Ulib</title>
|
||||
<title>Hello World-application for ULib</title>
|
||||
</head>
|
||||
|
||||
<body bgcolor="#FFFFFF">
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
<tr>
|
||||
<td bgcolor="white">
|
||||
<center>
|
||||
<h3>Welcome to Ulib (Ver. <!--#puts ULIB_VERSION -->)!</h3>
|
||||
<h3>Welcome to ULib (Ver. <!--#puts ULIB_VERSION -->)!</h3>
|
||||
</center>
|
||||
</td>
|
||||
</tr>
|
||||
|
@ -24,7 +24,7 @@
|
|||
</table>
|
||||
</blockquote>
|
||||
|
||||
<p>About Ulib:</p>
|
||||
<p>About ULib:</p>
|
||||
|
||||
<blockquote>
|
||||
<table width="750" cellpadding="5">
|
||||
|
|
|
@ -3,7 +3,7 @@ name("World");
|
|||
-->
|
||||
<html>
|
||||
<head>
|
||||
<title>Hello World-application for Ulib</title>
|
||||
<title>Hello World-application for ULib</title>
|
||||
</head>
|
||||
|
||||
<body bgcolor="#FFFFFF">
|
||||
|
|
|
@ -93,8 +93,8 @@ public:
|
|||
(void) output0.reserve(50U + size);
|
||||
(void) output1.reserve(50U + size);
|
||||
|
||||
output0.snprintf_add(U_CONSTANT_TO_PARAM("\n\tUSP_%s_VAR_GET(%u,%.*s);\n"), name, i, size, ptr);
|
||||
output1.snprintf_add(U_CONSTANT_TO_PARAM("\n\tUSP_%s_VAR_PUT(%u,%.*s);\n"), name, i, size, ptr);
|
||||
output0.snprintf_add(U_CONSTANT_TO_PARAM("\n\tif (usp_b%s) USP_%s_VAR_GET(%u,%.*s);\n"), name, name, i, size, ptr);
|
||||
output1.snprintf_add(U_CONSTANT_TO_PARAM("\n\tif (usp_b%s) USP_%s_VAR_PUT(%u,%.*s);\n"), name, name, i, size, ptr);
|
||||
|
||||
# ifdef DEBUG
|
||||
id.clear(); // NB: to avoid DEAD OF SOURCE STRING WITH CHILD ALIVE...
|
||||
|
@ -263,14 +263,17 @@ public:
|
|||
|
||||
bsession = true;
|
||||
|
||||
(void) output0.append(U_CONSTANT_TO_PARAM("\n\tusp_bSESSION = (UHTTP::getDataSession() ? true : (UHTTP::setSessionCookie(), false));\n"));
|
||||
|
||||
setDirectiveItem(directive, U_CONSTANT_SIZE("session"));
|
||||
|
||||
if (token) manageDirectiveSessionOrStorage("SESSION");
|
||||
else
|
||||
{
|
||||
(void) output0.append(U_CONSTANT_TO_PARAM("\n\tif (UHTTP::getDataSession() == false) UHTTP::setSessionCookie();\n"));
|
||||
(void) output1.append(U_CONSTANT_TO_PARAM("\n\tUHTTP::putDataSession();\n"));
|
||||
(void) output1.append(U_CONSTANT_TO_PARAM("\n\tif (usp_bSESSION) UHTTP::putDataSession();\n"));
|
||||
}
|
||||
|
||||
(void) output0.append(U_CONSTANT_TO_PARAM("\n\tusp_bSESSION = true;\n"));
|
||||
}
|
||||
else if (strncmp(directive, U_CONSTANT_TO_PARAM("storage")) == 0)
|
||||
{
|
||||
|
@ -279,14 +282,17 @@ public:
|
|||
|
||||
bstorage = true;
|
||||
|
||||
(void) output0.append(U_CONSTANT_TO_PARAM("\n\tusp_bSTORAGE = true;\n\t(void) UHTTP::getDataStorage();\n"));
|
||||
|
||||
setDirectiveItem(directive, U_CONSTANT_SIZE("storage"));
|
||||
|
||||
if (token) manageDirectiveSessionOrStorage("STORAGE");
|
||||
else
|
||||
{
|
||||
(void) output0.append(U_CONSTANT_TO_PARAM("\n\t(void) UHTTP::getDataStorage();\n"));
|
||||
(void) output1.append(U_CONSTANT_TO_PARAM("\n\tUHTTP::putDataStorage();\n"));
|
||||
(void) output1.append(U_CONSTANT_TO_PARAM("\n\ttif (usp_bSTORAGE) UHTTP::putDataStorage();\n"));
|
||||
}
|
||||
|
||||
(void) output0.append(U_CONSTANT_TO_PARAM("\n\tusp_bSTORAGE = true;\n"));
|
||||
}
|
||||
else if (strncmp(directive, U_CONSTANT_TO_PARAM("args")) == 0)
|
||||
{
|
||||
|
@ -627,25 +633,28 @@ loop: distance = t.getDistance();
|
|||
if (size)
|
||||
{
|
||||
token = usp.substr(distance, size);
|
||||
|
||||
// plain html block
|
||||
|
||||
if (test_if_html == false)
|
||||
|
||||
if (token.isWhiteSpace() == false)
|
||||
{
|
||||
test_if_html = true;
|
||||
// plain html block
|
||||
|
||||
if (u_isHTML(token.data())) is_html = true;
|
||||
if (test_if_html == false)
|
||||
{
|
||||
test_if_html = true;
|
||||
|
||||
if (u_isHTML(token.data())) is_html = true;
|
||||
}
|
||||
|
||||
UString tmp(token.size() * 4);
|
||||
|
||||
UEscape::encode(token, tmp);
|
||||
|
||||
U_ASSERT(tmp.isQuoted())
|
||||
|
||||
(void) output0.reserve(100U + tmp.size());
|
||||
|
||||
output0.snprintf_add(U_CONSTANT_TO_PARAM("\n\t(void) UClientImage_Base::wbuffer->append(\n\t\tU_CONSTANT_TO_PARAM(%v)\n\t);\n"), tmp.rep);
|
||||
}
|
||||
|
||||
UString tmp(token.size() * 4);
|
||||
|
||||
UEscape::encode(token, tmp);
|
||||
|
||||
U_ASSERT(tmp.isQuoted())
|
||||
|
||||
(void) output0.reserve(100U + tmp.size());
|
||||
|
||||
output0.snprintf_add(U_CONSTANT_TO_PARAM("\n\t(void) UClientImage_Base::wbuffer->append(\n\t\tU_CONSTANT_TO_PARAM(%v)\n\t);\n"), tmp.rep);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -816,28 +825,78 @@ loop: distance = t.getDistance();
|
|||
bclose = false;
|
||||
}
|
||||
|
||||
U_INTERNAL_DUMP("binit = %b breset = %b bend = %b bsighup = %b bfork = %b bopen = %b bclose = %b", binit, breset, bend, bsighup, bfork, bopen, bclose)
|
||||
bool bdatamod = (bsession || bstorage);
|
||||
|
||||
if (binit == false &&
|
||||
(bsession || bstorage))
|
||||
U_INTERNAL_DUMP("binit = %b breset = %b bend = %b bsighup = %b bfork = %b bopen = %b bclose = %b bdatamod = %b", binit, breset, bend, bsighup, bfork, bopen, bclose, bdatamod)
|
||||
|
||||
if (bdatamod)
|
||||
{
|
||||
binit = true;
|
||||
if (bsession)
|
||||
{
|
||||
(void) declaration.append(U_CONSTANT_TO_PARAM(
|
||||
"\n\t\nstatic bool usp_bSESSION;\n"
|
||||
"\n\t\n"
|
||||
"#define USP_SESSION_VAR_GET(index,varname) \\\n"
|
||||
" { \\\n"
|
||||
" UString varname##_value; \\\n"
|
||||
" if (UHTTP::getDataSession(index, varname##_value) && \\\n"
|
||||
" (usp_sz = varname##_value.size())) \\\n"
|
||||
" { \\\n"
|
||||
" UString2Object(varname##_value.data(), usp_sz, varname); \\\n"
|
||||
" } \\\n"
|
||||
" U_INTERNAL_DUMP(\"%s(%u) = %.*S\", #varname, usp_sz, usp_sz, varname##_value.data()) \\\n"
|
||||
" }"
|
||||
"\n\t\n"
|
||||
"#define USP_SESSION_VAR_PUT(index,varname) \\\n"
|
||||
" { \\\n"
|
||||
" usp_sz = UObject2String(varname, usp_buffer, sizeof(usp_buffer)); \\\n"
|
||||
" UHTTP::putDataSession(index, usp_buffer, usp_sz); \\\n"
|
||||
" }\n"));
|
||||
}
|
||||
|
||||
(void) declaration.reserve(500U);
|
||||
if (bstorage)
|
||||
{
|
||||
(void) declaration.append(U_CONSTANT_TO_PARAM(
|
||||
"\n\t\nstatic bool usp_bSTORAGE;\n"
|
||||
"\n\t\n"
|
||||
"#define USP_STORAGE_VAR_GET(index,varname) \\\n"
|
||||
" { \\\n"
|
||||
" UString varname##_value; \\\n"
|
||||
" if (UHTTP::getDataStorage(index, varname##_value) && \\\n"
|
||||
" (usp_sz = varname##_value.size())) \\\n"
|
||||
" { \\\n"
|
||||
" UString2Object(varname##_value.data(), usp_sz, varname); \\\n"
|
||||
" } \\\n"
|
||||
" U_INTERNAL_DUMP(\"%s(%u) = %.*S\", #varname, usp_sz, usp_sz, varname##_value.data()) \\\n"
|
||||
" }"
|
||||
"\n\t\n"
|
||||
"#define USP_STORAGE_VAR_PUT(index,varname) \\\n"
|
||||
" { \\\n"
|
||||
" usp_sz = UObject2String(varname, usp_buffer, sizeof(usp_buffer)); \\\n"
|
||||
" UHTTP::putDataStorage(index, usp_buffer, usp_sz); \\\n"
|
||||
" }\n"));
|
||||
}
|
||||
|
||||
declaration.snprintf_add(U_CONSTANT_TO_PARAM(
|
||||
"\n\t\nstatic void usp_init_%.*s()\n"
|
||||
"{\n"
|
||||
"\tU_TRACE(5, \"::usp_init_%.*s()\")\n"
|
||||
"\t\n"
|
||||
"%s"
|
||||
"%s"
|
||||
"\n\tif (UHTTP::db_session == U_NULLPTR) UHTTP::initSession();\n"
|
||||
"}"),
|
||||
basename_sz, basename_ptr,
|
||||
basename_sz, basename_ptr,
|
||||
(bsession ? "\n\tif (UHTTP::data_session == U_NULLPTR) U_NEW(UDataSession, UHTTP::data_session, UDataSession)\n" : ""),
|
||||
(bstorage ? "\n\tif (UHTTP::data_storage == U_NULLPTR) { U_NEW(UDataSession, UHTTP::data_storage, UDataSession(*UString::str_storage_keyid)) }\n" : ""));
|
||||
if (binit == false)
|
||||
{
|
||||
binit = true;
|
||||
|
||||
(void) declaration.reserve(500U);
|
||||
|
||||
declaration.snprintf_add(U_CONSTANT_TO_PARAM(
|
||||
"\n\t\nstatic void usp_init_%.*s()\n"
|
||||
"{\n"
|
||||
"\tU_TRACE(5, \"::usp_init_%.*s()\")\n"
|
||||
"\t\n"
|
||||
"%s"
|
||||
"%s"
|
||||
"\n\tif (UHTTP::db_session == U_NULLPTR) UHTTP::initSession();\n"
|
||||
"}"),
|
||||
basename_sz, basename_ptr,
|
||||
basename_sz, basename_ptr,
|
||||
(bsession ? "\n\tif (UHTTP::data_session == U_NULLPTR) U_NEW(UDataSession, UHTTP::data_session, UDataSession)\n" : ""),
|
||||
(bstorage ? "\n\tif (UHTTP::data_storage == U_NULLPTR) { U_NEW(UDataSession, UHTTP::data_storage, UDataSession(*UString::str_storage_keyid)) }\n" : ""));
|
||||
}
|
||||
}
|
||||
|
||||
if (binit) (void) u__snprintf(ptr1, 100, U_CONSTANT_TO_PARAM("\n\tif (param == U_DPAGE_INIT) { usp_init_%.*s(); return; }\n"), basename_sz, basename_ptr);
|
||||
|
|
|
@ -1111,7 +1111,7 @@ private:
|
|||
U_DISALLOW_COPY_AND_ASSIGN(UClientThread)
|
||||
};
|
||||
|
||||
# ifdef U_LINUX
|
||||
# if defined(U_LINUX) && !defined(U_SERVER_CAPTIVE_PORTAL)
|
||||
class UTimeThread : public UThread {
|
||||
public:
|
||||
|
||||
|
@ -1195,7 +1195,7 @@ public:
|
|||
continue;
|
||||
}
|
||||
|
||||
# if !defined(U_SERVER_CAPTIVE_PORTAL) && !defined(U_LOG_DISABLE) && defined(USE_LIBZ)
|
||||
# if !defined(U_LOG_DISABLE) && defined(USE_LIBZ)
|
||||
if (UServer_Base::log) UServer_Base::log->checkForLogRotateDataToWrite();
|
||||
if (UServer_Base::apache_like_log) UServer_Base::apache_like_log->checkForLogRotateDataToWrite();
|
||||
# endif
|
||||
|
@ -1260,19 +1260,15 @@ public:
|
|||
|
||||
sec = u_now->tv_sec;
|
||||
|
||||
# ifndef U_SERVER_CAPTIVE_PORTAL
|
||||
if (daylight &&
|
||||
(sec % U_ONE_HOUR_IN_SECOND) == 0)
|
||||
{
|
||||
(void) UTimeDate::checkForDaylightSavingTime(sec);
|
||||
}
|
||||
# endif
|
||||
|
||||
if (UServer_Base::update_date)
|
||||
{
|
||||
# ifndef U_SERVER_CAPTIVE_PORTAL
|
||||
(void) U_SYSCALL(pthread_rwlock_wrlock, "%p", ULog::prwlock);
|
||||
# endif
|
||||
|
||||
if ((sec % U_ONE_HOUR_IN_SECOND) != 0)
|
||||
{
|
||||
|
@ -1289,9 +1285,7 @@ public:
|
|||
if (UServer_Base::update_date3) (void) u_strftime2(ULog::ptr_shared_date->date3+6, 29-4, U_CONSTANT_TO_PARAM("%a, %d %b %Y %T"), sec);
|
||||
}
|
||||
|
||||
# ifndef U_SERVER_CAPTIVE_PORTAL
|
||||
(void) U_SYSCALL(pthread_rwlock_unlock, "%p", ULog::prwlock);
|
||||
# endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1803,13 +1797,15 @@ UServer_Base::~UServer_Base()
|
|||
}
|
||||
# endif
|
||||
|
||||
# ifdef U_LINUX
|
||||
# if defined(U_LINUX)
|
||||
# if !defined(U_SERVER_CAPTIVE_PORTAL)
|
||||
if (u_pthread_time)
|
||||
{
|
||||
U_DELETE((UTimeThread*)u_pthread_time)
|
||||
|
||||
(void) pthread_rwlock_destroy(ULog::prwlock);
|
||||
}
|
||||
# endif
|
||||
|
||||
# if defined(USE_LIBSSL) && !defined(OPENSSL_NO_OCSP) && defined(SSL_CTRL_SET_TLSEXT_STATUS_REQ_CB)
|
||||
if (bssl)
|
||||
|
@ -2216,7 +2212,7 @@ void UServer_Base::loadConfigParam()
|
|||
U_INTERNAL_DUMP("SOMAXCONN = %d FD_SETSIZE = %d", SOMAXCONN, FD_SETSIZE)
|
||||
|
||||
set_tcp_keep_alive = cfg->readBoolean(U_CONSTANT_TO_PARAM("TCP_KEEP_ALIVE"));
|
||||
set_realtime_priority = cfg->readBoolean(U_CONSTANT_TO_PARAM("SET_REALTIME_PRIORITY"), true);
|
||||
set_realtime_priority = cfg->readBoolean(U_CONSTANT_TO_PARAM("SET_REALTIME_PRIORITY"), false);
|
||||
|
||||
crash_count = cfg->readLong(U_CONSTANT_TO_PARAM("CRASH_COUNT"), 5);
|
||||
tcp_linger_set = cfg->readLong(U_CONSTANT_TO_PARAM("TCP_LINGER_SET"), -2);
|
||||
|
@ -3036,7 +3032,9 @@ void UServer_Base::suspendThread()
|
|||
U_TRACE_NO_PARAM(0, "UServer_Base::suspendThread()")
|
||||
|
||||
#if defined(U_LINUX) && defined(ENABLE_THREAD)
|
||||
# if !defined(U_SERVER_CAPTIVE_PORTAL)
|
||||
if (u_pthread_time) ((UTimeThread*)u_pthread_time)->suspend();
|
||||
# endif
|
||||
|
||||
# if defined(USE_LIBSSL) && !defined(OPENSSL_NO_OCSP) && defined(SSL_CTRL_SET_TLSEXT_STATUS_REQ_CB)
|
||||
if (pthread_ocsp) pthread_ocsp->suspend();
|
||||
|
@ -3354,15 +3352,19 @@ next:
|
|||
U_INTERNAL_ASSERT_EQUALS(u_pthread_time, U_NULLPTR)
|
||||
|
||||
# ifdef USERVER_UDP
|
||||
if (budp == false ||
|
||||
UServer_Base::update_date)
|
||||
if (budp == false)
|
||||
# endif
|
||||
{
|
||||
U_NEW_WITHOUT_CHECK_MEMORY(UTimeThread, u_pthread_time, UTimeThread);
|
||||
# if !defined(U_SERVER_CAPTIVE_PORTAL)
|
||||
if (UServer_Base::update_date)
|
||||
{
|
||||
U_NEW_WITHOUT_CHECK_MEMORY(UTimeThread, u_pthread_time, UTimeThread);
|
||||
|
||||
(void) UThread::initRwLock((ULog::prwlock = &(ptr_shared_data->rwlock)));
|
||||
(void) UThread::initRwLock((ULog::prwlock = &(ptr_shared_data->rwlock)));
|
||||
|
||||
((UTimeThread*)u_pthread_time)->start(50);
|
||||
((UTimeThread*)u_pthread_time)->start(50);
|
||||
}
|
||||
# endif
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -3626,7 +3628,9 @@ void UServer_Base::sendSignalToAllChildren(int signo, sighandler_t handler)
|
|||
#endif
|
||||
|
||||
#if defined(U_LINUX) && defined(ENABLE_THREAD)
|
||||
# if !defined(U_SERVER_CAPTIVE_PORTAL)
|
||||
if (u_pthread_time) ((UTimeThread*)u_pthread_time)->resume();
|
||||
# endif
|
||||
|
||||
# if defined(USE_LIBSSL) && !defined(OPENSSL_NO_OCSP) && defined(SSL_CTRL_SET_TLSEXT_STATUS_REQ_CB)
|
||||
if (pthread_ocsp) pthread_ocsp->resume();
|
||||
|
@ -4187,9 +4191,7 @@ retry: pid = UProcess::waitpid(-1, &status, WNOHANG); // NB: to avoid too much
|
|||
if (msg_welcome &&
|
||||
USocketExt::write(CSOCKET, *msg_welcome, timeoutMS) == false)
|
||||
{
|
||||
CSOCKET->abortive_close();
|
||||
|
||||
CLIENT_IMAGE->UClientImage_Base::handlerDelete();
|
||||
if (CSOCKET->isOpen()) CSOCKET->abortive_close();
|
||||
|
||||
goto next;
|
||||
}
|
||||
|
@ -4475,14 +4477,16 @@ void UServer_Base::runLoop(const char* user)
|
|||
if (budp == false)
|
||||
#endif
|
||||
{
|
||||
if (handler_db1)
|
||||
if (handler_db1 &&
|
||||
handler_db1->UEventFd::fd != -1)
|
||||
{
|
||||
UNotifier::min_connection++;
|
||||
|
||||
handler_db1->UEventFd::op_mask &= ~EPOLLRDHUP;
|
||||
}
|
||||
|
||||
if (handler_db2)
|
||||
if (handler_db2 &&
|
||||
handler_db2->UEventFd::fd != -1)
|
||||
{
|
||||
UNotifier::min_connection++;
|
||||
|
||||
|
@ -4510,10 +4514,20 @@ void UServer_Base::runLoop(const char* user)
|
|||
if (UNotifier::min_connection)
|
||||
{
|
||||
if (binsert) UNotifier::insert(pthis, EPOLLEXCLUSIVE | EPOLLROUNDROBIN); // NB: we ask to be notified for request of connection (=> accept)
|
||||
if (handler_db1) UNotifier::insert(handler_db1, EPOLLEXCLUSIVE | EPOLLROUNDROBIN); // NB: we ask to be notified for response from db
|
||||
if (handler_db2) UNotifier::insert(handler_db2, EPOLLEXCLUSIVE | EPOLLROUNDROBIN); // NB: we ask to be notified for response from db
|
||||
if (handler_inotify) UNotifier::insert(handler_inotify, EPOLLEXCLUSIVE | EPOLLROUNDROBIN); // NB: we ask to be notified for change of file system (=> inotify)
|
||||
|
||||
if (handler_db1 &&
|
||||
handler_db1->UEventFd::fd != -1)
|
||||
{
|
||||
UNotifier::insert(handler_db1, EPOLLEXCLUSIVE | EPOLLROUNDROBIN); // NB: we ask to be notified for response from db
|
||||
}
|
||||
|
||||
if (handler_db2 &&
|
||||
handler_db2->UEventFd::fd != -1)
|
||||
{
|
||||
UNotifier::insert(handler_db2, EPOLLEXCLUSIVE | EPOLLROUNDROBIN); // NB: we ask to be notified for response from db
|
||||
}
|
||||
|
||||
if (handler_other) // NB: we ask to be notified for request from generic system
|
||||
{
|
||||
for (uint32_t i = 0, n = handler_other->size(); i < n; ++i) UNotifier::insert(handler_other->at(i), EPOLLEXCLUSIVE | EPOLLROUNDROBIN);
|
||||
|
|
|
@ -80,13 +80,11 @@ void UDataSession::toStream(ostream& os)
|
|||
{
|
||||
U_TRACE(0, "UDataSession::toStream(%p)", &os)
|
||||
|
||||
U_INTERNAL_ASSERT_POINTER(vec_var)
|
||||
|
||||
os.put('{');
|
||||
os.put(' ');
|
||||
os << creation;
|
||||
os.put(' ');
|
||||
os << *vec_var;
|
||||
os << vec_var;
|
||||
os.put(' ');
|
||||
os.put('}');
|
||||
}
|
||||
|
@ -95,7 +93,6 @@ void UDataSession::fromStream(istream& is)
|
|||
{
|
||||
U_TRACE(0, "UDataSession::fromStream(%p)", &is)
|
||||
|
||||
U_INTERNAL_ASSERT_POINTER(vec_var)
|
||||
U_INTERNAL_ASSERT_EQUALS(is.peek(), '{')
|
||||
|
||||
is.get(); // skip '{'
|
||||
|
@ -106,7 +103,7 @@ void UDataSession::fromStream(istream& is)
|
|||
|
||||
U_INTERNAL_ASSERT(is.peek() == '(')
|
||||
|
||||
is >> *vec_var;
|
||||
is >> vec_var;
|
||||
|
||||
is.get(); // skip ' '
|
||||
is.get(); // skip '}'
|
||||
|
@ -134,9 +131,9 @@ const char* UDataSession::dump(bool reset) const
|
|||
UDataStorage::dump(false);
|
||||
|
||||
*UObjectIO::os << '\n'
|
||||
<< "creation " << creation << '\n'
|
||||
<< "last_access " << last_access << '\n'
|
||||
<< "vec_var (UVector<UString*> " << (void*)vec_var << ')';
|
||||
<< "creation " << creation << '\n'
|
||||
<< "last_access " << last_access << '\n'
|
||||
<< "vec_var (UVector<UString*> " << (void*)&vec_var << ')';
|
||||
|
||||
if (reset)
|
||||
{
|
||||
|
|
|
@ -722,6 +722,8 @@ void UServices::generateDigest(int alg, uint32_t keylen, unsigned char* data, ui
|
|||
#ifdef USE_LIBSSL
|
||||
u_dgst_init(alg, (const char*)key, keylen);
|
||||
|
||||
U_INTERNAL_DUMP("u_hmac_keylen = %u", u_hmac_keylen)
|
||||
|
||||
u_dgst_hash(data, size);
|
||||
|
||||
if (base64 == -2)
|
||||
|
@ -732,15 +734,63 @@ void UServices::generateDigest(int alg, uint32_t keylen, unsigned char* data, ui
|
|||
}
|
||||
else
|
||||
{
|
||||
uint32_t bytes_written = u_dgst_finish((unsigned char*)output.pend(), base64);
|
||||
uint32_t sz = output.size(), bytes_written = u_dgst_finish((unsigned char*)output.data()+sz, base64);
|
||||
|
||||
output.size_adjust(output.size() + bytes_written);
|
||||
output.size_adjust(sz + bytes_written);
|
||||
}
|
||||
|
||||
U_INTERNAL_DUMP("u_mdLen = %d output = %V", u_mdLen, output.rep)
|
||||
#endif
|
||||
}
|
||||
|
||||
bool UServices::setDigestCalcResponse(const UString& ha1, const UString& nc, const UString& nonce, const UString& cnonce, const UString& uri, const UString& user, UString& response)
|
||||
{
|
||||
U_TRACE(0, "UServices::setDigestCalcResponse(%V,%V,%V,%V,%V,%V,%p)", ha1.rep, nc.rep, nonce.rep, cnonce.rep, uri.rep, user.rep, &response)
|
||||
|
||||
U_INTERNAL_ASSERT(ha1)
|
||||
|
||||
if ( nc.empty() ||
|
||||
uri.empty() ||
|
||||
nonce.empty() ||
|
||||
cnonce.empty() ||
|
||||
user.empty())
|
||||
{
|
||||
U_WARNING("Invalid Authorization Digest header: nc = %V nonce = %V cnonce = %V uri = %V user = %V", nc.rep, nonce.rep, cnonce.rep, uri.rep, user.rep);
|
||||
|
||||
U_RETURN(false);
|
||||
}
|
||||
|
||||
// ha1 => MD5(user : realm : password)
|
||||
|
||||
#ifdef USE_LIBSSL
|
||||
UString a2(4+1+uri.size()), // method : uri
|
||||
ha2(33U), // MD5(method : uri)
|
||||
a3(200U);
|
||||
|
||||
// MD5(method : uri)
|
||||
|
||||
a2.snprintf(U_CONSTANT_TO_PARAM("%.*s:%v"), U_HTTP_METHOD_TO_TRACE, uri.rep);
|
||||
|
||||
generateDigest(U_HASH_MD5, 0, a2, ha2, false);
|
||||
|
||||
U_INTERNAL_DUMP("U_HTTP_METHOD_TO_TRACE = %.*s ha2 = %V", U_HTTP_METHOD_TO_TRACE, ha2.rep)
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
// MD5(HA1 : nonce : nc : cnonce : qop : HA2)
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
a3.snprintf(U_CONSTANT_TO_PARAM("%v:%v:%v:%v:" U_HTTP_QOP ":%v"), ha1.rep, nonce.rep, nc.rep, cnonce.rep, ha2.rep);
|
||||
|
||||
generateDigest(U_HASH_MD5, 0, a3, response, false);
|
||||
|
||||
U_INTERNAL_DUMP("response = %V", response.rep)
|
||||
|
||||
U_RETURN(true);
|
||||
#endif
|
||||
|
||||
U_RETURN(false);
|
||||
}
|
||||
|
||||
#define U_HMAC_SIZE 16U // MD5 output len
|
||||
#define U_TOKEN_SIZE (1U + 10U + 1U + U_HMAC_SIZE) // ... '&' time '&' hmac
|
||||
|
||||
|
|
|
@ -3599,7 +3599,7 @@ next:
|
|||
case HTTP_BAD_METHOD: setBadMethod(); break;
|
||||
case HTTP_BAD_REQUEST: setBadRequest(); break;
|
||||
case HTTP_UNAVAILABLE: setServiceUnavailable(); break;
|
||||
case HTTP_UNAUTHORIZED: setUnAuthorized(); break;
|
||||
case HTTP_UNAUTHORIZED: setUnAuthorized(false); break;
|
||||
default: setInternalError(); break;
|
||||
}
|
||||
|
||||
|
@ -6683,7 +6683,11 @@ void UHTTP::handlerResponse()
|
|||
else
|
||||
#endif
|
||||
{
|
||||
UClientImage_Base::setHeaderForResponse(6+29+2+12+2); // Date: Wed, 20 Jun 2012 11:43:17 GMT\r\nServer: ULib\r\n
|
||||
U_INTERNAL_DUMP("UClientImage_Base::iov_vec[0].iov_len = %u UClientImage_Base::iov_vec[1].iov_len = %u", UClientImage_Base::iov_vec[0].iov_len, UClientImage_Base::iov_vec[1].iov_len)
|
||||
|
||||
U_INTERNAL_ASSERT_EQUALS(UClientImage_Base::iov_vec[1].iov_len, 51)
|
||||
|
||||
// UClientImage_Base::setHeaderForResponse(6+29+2+12+2); // Date: Wed, 20 Jun 2012 11:43:17 GMT\r\nServer: ULib\r\n
|
||||
|
||||
setStatusDescription();
|
||||
|
||||
|
@ -6801,14 +6805,14 @@ void UHTTP::handlerResponse()
|
|||
|
||||
// A server implements an HSTS policy by supplying a header over an HTTPS connection (HSTS headers over HTTP are ignored)
|
||||
|
||||
# if defined(USE_LIBSSL) && defined(U_HTTP_STRICT_TRANSPORT_SECURITY)
|
||||
# if defined(USE_LIBSSL) && defined(U_HTTP_STRICT_TRANSPORT_SECURITY)
|
||||
if (UServer_Base::bssl &&
|
||||
uri_strict_transport_security_mask == (void*)1L)
|
||||
{
|
||||
ptr2 = "Strict-Transport-Security: max-age=31536000; includeSubDomains; preload\r\nContent-Length: 0\r\n\r\n";
|
||||
sz2 = U_CONSTANT_SIZE("Strict-Transport-Security: max-age=31536000; includeSubDomains; preload\r\nContent-Length: 0\r\n\r\n");
|
||||
}
|
||||
# endif
|
||||
# endif
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -7110,20 +7114,37 @@ void UHTTP::setErrorResponse(const UString& content_type, int code, const char*
|
|||
setResponse(content_type, &lbody);
|
||||
}
|
||||
|
||||
void UHTTP::setUnAuthorized()
|
||||
void UHTTP::setUnAuthorized(bool bstale)
|
||||
{
|
||||
U_TRACE_NO_PARAM(0, "UHTTP::setUnAuthorized()")
|
||||
U_TRACE(0, "UHTTP::setUnAuthorized(%b)", bstale)
|
||||
|
||||
UString tmp(100U);
|
||||
UString tmp(200U);
|
||||
char* ptr = tmp.data();
|
||||
|
||||
(void) tmp.assign(U_CONSTANT_TO_PARAM(U_CTYPE_HTML "\r\nWWW-Authenticate: "));
|
||||
U_MEMCPY(ptr, U_CTYPE_HTML "\r\nWWW-Authenticate: ", U_CONSTANT_SIZE(U_CTYPE_HTML "\r\nWWW-Authenticate: "));
|
||||
ptr += U_CONSTANT_SIZE(U_CTYPE_HTML "\r\nWWW-Authenticate: ");
|
||||
|
||||
U_INTERNAL_DUMP("digest_authentication = %b", digest_authentication)
|
||||
|
||||
if (digest_authentication) tmp.snprintf_add(U_CONSTANT_TO_PARAM("Digest qop=\"auth\", nonce=\"%ld\", algorithm=MD5,"), u_now->tv_sec);
|
||||
else (void) tmp.append(U_CONSTANT_TO_PARAM("Basic"));
|
||||
if (digest_authentication)
|
||||
{
|
||||
ptr += u__snprintf(ptr, tmp.remain(ptr), U_CONSTANT_TO_PARAM("Digest qop=" U_HTTP_QOP ", nonce=%lu, algorithm=MD5,"), u_now->tv_sec);
|
||||
}
|
||||
else
|
||||
{
|
||||
U_MEMCPY(ptr, "Basic", U_CONSTANT_SIZE("Basic"));
|
||||
ptr += U_CONSTANT_SIZE("Basic");
|
||||
}
|
||||
|
||||
(void) tmp.append(U_CONSTANT_TO_PARAM(" realm=\"" U_HTTP_REALM "\"\r\n"));
|
||||
if (bstale)
|
||||
{
|
||||
U_MEMCPY(ptr, " stale=TRUE,", U_CONSTANT_SIZE(" stale=TRUE,"));
|
||||
ptr += U_CONSTANT_SIZE(" stale=TRUE,");
|
||||
}
|
||||
|
||||
U_MEMCPY(ptr, " realm=\"" U_HTTP_REALM "\"\r\n", U_CONSTANT_SIZE(" realm=\"" U_HTTP_REALM "\"\r\n"));
|
||||
|
||||
tmp.size_adjust(ptr + U_CONSTANT_SIZE(" realm=\"" U_HTTP_REALM "\"\r\n"));
|
||||
|
||||
UClientImage_Base::setRequestForbidden();
|
||||
|
||||
|
@ -7499,6 +7520,21 @@ end:
|
|||
handlerResponse();
|
||||
}
|
||||
|
||||
U_NO_EXPORT uint32_t UHTTP::getPosPasswd(UString& fpasswd, const UString& line)
|
||||
{
|
||||
U_TRACE(0, "UHTTP::getPosPasswd(%V,%V)", fpasswd.rep, line.rep)
|
||||
|
||||
uint32_t pos = fpasswd.find(line);
|
||||
|
||||
if (pos == U_NOT_FOUND ||
|
||||
(pos > 0 && fpasswd[pos-1] != '\n'))
|
||||
{
|
||||
U_RETURN(U_NOT_FOUND);
|
||||
}
|
||||
|
||||
U_RETURN(pos);
|
||||
}
|
||||
|
||||
U_NO_EXPORT uint32_t UHTTP::checkPasswd(UHTTP::UFileCacheData* ptr_file_data, UString& fpasswd, const UString& line)
|
||||
{
|
||||
U_TRACE(0, "UHTTP::checkPasswd(%p,%V,%V)", ptr_file_data, fpasswd.rep, line.rep)
|
||||
|
@ -7506,10 +7542,9 @@ U_NO_EXPORT uint32_t UHTTP::checkPasswd(UHTTP::UFileCacheData* ptr_file_data, US
|
|||
// s.casazza:{SHA}Lkii1ZE7k.....\n
|
||||
// s.casazza:Protected Area:b9ee2af50be37...........\n
|
||||
|
||||
uint32_t pos = fpasswd.find(line);
|
||||
uint32_t pos = getPosPasswd(fpasswd, line);
|
||||
|
||||
if (pos == U_NOT_FOUND ||
|
||||
(pos > 0 && line[pos-1] != '\n'))
|
||||
if (pos == U_NOT_FOUND)
|
||||
{
|
||||
U_INTERNAL_DUMP("digest_authentication = %b htpasswd = %p", digest_authentication, htpasswd)
|
||||
|
||||
|
@ -7521,71 +7556,61 @@ U_NO_EXPORT uint32_t UHTTP::checkPasswd(UHTTP::UFileCacheData* ptr_file_data, US
|
|||
|
||||
UFile tmp(lpathname);
|
||||
|
||||
if (tmp.open() &&
|
||||
(tmp.st_mtime = ptr_file_data->mtime, tmp.isModified()))
|
||||
if (tmp.open())
|
||||
{
|
||||
ptr_file_data->array->erase(0);
|
||||
if ((tmp.st_mtime = ptr_file_data->mtime, tmp.isModified()) == false) tmp.close();
|
||||
else
|
||||
{
|
||||
ptr_file_data->array->erase(0);
|
||||
|
||||
fpasswd = tmp.getContent(true, false, true);
|
||||
fpasswd = tmp.getContent(true, false, true);
|
||||
|
||||
ptr_file_data->array->push_back(fpasswd);
|
||||
ptr_file_data->array->push_back(fpasswd);
|
||||
|
||||
U_SRV_LOG("File data users permission: %V reloaded - %u bytes", lpathname.rep, fpasswd.size());
|
||||
U_SRV_LOG("File data users permission: %V reloaded - %u bytes", lpathname.rep, fpasswd.size());
|
||||
|
||||
goto next;
|
||||
pos = getPosPasswd(fpasswd, line);
|
||||
}
|
||||
}
|
||||
|
||||
tmp.close();
|
||||
}
|
||||
else
|
||||
else if (digest_authentication)
|
||||
{
|
||||
if (digest_authentication)
|
||||
U_INTERNAL_ASSERT(htdigest)
|
||||
|
||||
UFile tmp(*UString::str_htdigest);
|
||||
|
||||
if (tmp.open())
|
||||
{
|
||||
U_INTERNAL_ASSERT(htdigest)
|
||||
|
||||
UFile tmp(*UString::str_htdigest);
|
||||
|
||||
if (tmp.open() &&
|
||||
(tmp.st_mtime = htdigest_mtime, tmp.isModified()))
|
||||
if ((tmp.st_mtime = htdigest_mtime, tmp.isModified()) == false) tmp.close();
|
||||
else
|
||||
{
|
||||
fpasswd = *htdigest = tmp.getContent(true, false, true);
|
||||
|
||||
U_SRV_LOG("File data users permission: ../.htdigest reloaded - %u bytes", fpasswd.size());
|
||||
|
||||
goto next;
|
||||
pos = getPosPasswd(fpasswd, line);
|
||||
}
|
||||
|
||||
tmp.close();
|
||||
}
|
||||
else
|
||||
}
|
||||
else
|
||||
{
|
||||
U_INTERNAL_ASSERT(htpasswd)
|
||||
|
||||
UFile tmp(*UString::str_htpasswd);
|
||||
|
||||
if (tmp.open())
|
||||
{
|
||||
U_INTERNAL_ASSERT(htpasswd)
|
||||
|
||||
UFile tmp(*UString::str_htpasswd);
|
||||
|
||||
if (tmp.open() &&
|
||||
(tmp.st_mtime = htpasswd_mtime, tmp.isModified()))
|
||||
if ((tmp.st_mtime = htpasswd_mtime, tmp.isModified()) == false) tmp.close();
|
||||
else
|
||||
{
|
||||
fpasswd = *htpasswd = tmp.getContent(true, false, true);
|
||||
|
||||
U_SRV_LOG("File data users permission: ../.htpasswd reloaded - %u bytes", fpasswd.size());
|
||||
|
||||
goto next;
|
||||
pos = getPosPasswd(fpasswd, line);
|
||||
}
|
||||
|
||||
tmp.close();
|
||||
}
|
||||
}
|
||||
|
||||
U_RETURN(U_NOT_FOUND);
|
||||
|
||||
next: pos = fpasswd.find(line);
|
||||
|
||||
if (pos == U_NOT_FOUND ||
|
||||
(pos > 0 && line[pos-1] != '\n'))
|
||||
{
|
||||
U_RETURN(U_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
|
||||
U_RETURN(pos);
|
||||
|
@ -7595,15 +7620,13 @@ U_NO_EXPORT bool UHTTP::processAuthorization(const char* request, uint32_t sz, c
|
|||
{
|
||||
U_TRACE(0, "UHTTP::processAuthorization(%.*S,%u,%.*S,%u)", sz, request, sz, len, pattern, len)
|
||||
|
||||
user_authentication->clear();
|
||||
|
||||
if (sz == 0) request = UClientImage_Base::getRequestUri(sz);
|
||||
|
||||
UTokenizer t;
|
||||
const char* ptr;
|
||||
uint32_t pos = 0;
|
||||
bool result = false, bpass = false;
|
||||
UString buffer(U_CAPACITY), fpasswd, content, tmp;
|
||||
bool result = false, bpass = false, bstale = false;
|
||||
|
||||
if (pattern)
|
||||
{
|
||||
|
@ -7700,7 +7723,7 @@ U_NO_EXPORT bool UHTTP::processAuthorization(const char* request, uint32_t sz, c
|
|||
*/
|
||||
|
||||
UVector<UString> name_value;
|
||||
UString name, value, realm, nonce, _uri, response, qop, nc, cnonce;
|
||||
UString name, value, nc, nonce, cnonce, uri, response, ha1, ha3(33U);
|
||||
|
||||
for (int32_t i = 0, n = UStringExt::getNameValueFromData(content, name_value, U_CONSTANT_TO_PARAM(", \t")); i < n; i += 2)
|
||||
{
|
||||
|
@ -7715,13 +7738,12 @@ U_NO_EXPORT bool UHTTP::processAuthorization(const char* request, uint32_t sz, c
|
|||
{
|
||||
if (name.equal(U_CONSTANT_TO_PARAM("username")))
|
||||
{
|
||||
U_ASSERT(user_authentication->empty())
|
||||
|
||||
*user_authentication = value;
|
||||
if (value == *user_authentication) bstale = true;
|
||||
else *user_authentication = value;
|
||||
}
|
||||
else if (name.equal(U_CONSTANT_TO_PARAM("uri")))
|
||||
{
|
||||
U_ASSERT(_uri.empty())
|
||||
U_ASSERT(uri.empty())
|
||||
|
||||
ptr = value.data();
|
||||
pos = value.size();
|
||||
|
@ -7741,7 +7763,7 @@ U_NO_EXPORT bool UHTTP::processAuthorization(const char* request, uint32_t sz, c
|
|||
}
|
||||
}
|
||||
|
||||
_uri = value;
|
||||
uri = value;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
@ -7750,9 +7772,7 @@ U_NO_EXPORT bool UHTTP::processAuthorization(const char* request, uint32_t sz, c
|
|||
{
|
||||
if (name.equal(U_CONSTANT_TO_PARAM("realm")))
|
||||
{
|
||||
U_ASSERT(realm.empty())
|
||||
|
||||
realm = value;
|
||||
if (value.equal(U_HTTP_REALM) == false) goto end;
|
||||
}
|
||||
else if (name.equal(U_CONSTANT_TO_PARAM("response")))
|
||||
{
|
||||
|
@ -7771,9 +7791,7 @@ U_NO_EXPORT bool UHTTP::processAuthorization(const char* request, uint32_t sz, c
|
|||
{
|
||||
U_ASSERT(nonce.empty())
|
||||
|
||||
// XXX: Due to a bug in MSIE (version=??), we do not check for authentication timeout...
|
||||
|
||||
if ((u_now->tv_sec - value.strtoul()) > 3600) goto end;
|
||||
// if ((u_now->tv_sec - value.strtoul()) > 3600) goto end; // Due to a bug in MSIE (version=??), we do not check for authentication timeout...
|
||||
|
||||
nonce = value;
|
||||
}
|
||||
|
@ -7790,9 +7808,7 @@ U_NO_EXPORT bool UHTTP::processAuthorization(const char* request, uint32_t sz, c
|
|||
{
|
||||
if (name.equal(U_CONSTANT_TO_PARAM("qop")))
|
||||
{
|
||||
U_ASSERT(qop.empty())
|
||||
|
||||
qop = value;
|
||||
if (value.equal(U_HTTP_QOP) == false) goto end;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
@ -7819,15 +7835,9 @@ U_NO_EXPORT bool UHTTP::processAuthorization(const char* request, uint32_t sz, c
|
|||
}
|
||||
}
|
||||
|
||||
UString a2(4 + 1 + _uri.size()), // method : uri
|
||||
ha2(33U), // MD5(method : uri)
|
||||
ha1, // MD5(user : realm : password)
|
||||
a3(200U),
|
||||
ha3(33U);
|
||||
// ha1 => MD5(user : realm : password)
|
||||
|
||||
// MD5(user : realm : password)
|
||||
|
||||
buffer.snprintf(U_CONSTANT_TO_PARAM("%v:%v:"), user_authentication->rep, realm.rep);
|
||||
buffer.snprintf(U_CONSTANT_TO_PARAM("%v:" U_HTTP_REALM ":"), user_authentication->rep);
|
||||
|
||||
// s.casazza:Protected Area:b9ee2af50be37...........\n
|
||||
|
||||
|
@ -7836,37 +7846,14 @@ U_NO_EXPORT bool UHTTP::processAuthorization(const char* request, uint32_t sz, c
|
|||
if (pos == U_NOT_FOUND) goto end;
|
||||
|
||||
pos += buffer.size();
|
||||
ha1 = fpasswd.substr(pos, 32);
|
||||
|
||||
U_INTERNAL_ASSERT_EQUALS(fpasswd.c_char(pos + 32), '\n')
|
||||
ha1 = fpasswd.substr(pos, 32);
|
||||
|
||||
U_INTERNAL_DUMP("ha1 = %V", ha1.rep)
|
||||
U_INTERNAL_ASSERT_EQUALS(fpasswd.c_char(pos+32), '\n')
|
||||
|
||||
// MD5(method : uri)
|
||||
if (UServices::setDigestCalcResponse(ha1, nc, nonce, cnonce, uri, *user_authentication, ha3)) result = (ha3 == response);
|
||||
|
||||
a2.snprintf(U_CONSTANT_TO_PARAM("%.*s:%v"), U_HTTP_METHOD_TO_TRACE, _uri.rep);
|
||||
|
||||
UServices::generateDigest(U_HASH_MD5, 0, a2, ha2, false);
|
||||
|
||||
U_INTERNAL_DUMP("ha2 = %V", ha2.rep)
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
// MD5(HA1 : nonce : nc : cnonce : qop : HA2)
|
||||
// --------------------------------------------------------------------------
|
||||
// NB: wget supports only Basic auth as the only auth type over HTTP proxy...
|
||||
// --------------------------------------------------------------------------
|
||||
// if (qop.empty()) (void) qop.assign(U_CONSTANT_TO_PARAM("auth"));
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
a3.snprintf(U_CONSTANT_TO_PARAM("%v:%v:%v:%v:%v:%v"), ha1.rep, nonce.rep, nc.rep, cnonce.rep, qop.rep, ha2.rep);
|
||||
|
||||
UServices::generateDigest(U_HASH_MD5, 0, a3, ha3, false);
|
||||
|
||||
U_INTERNAL_DUMP("ha3 = %V response = %V", ha3.rep, response.rep)
|
||||
|
||||
result = (ha3 == response);
|
||||
|
||||
U_INTERNAL_DUMP("result = %b", result)
|
||||
U_INTERNAL_DUMP("ha3 = %V response = %V result = %b bstale = %b", ha3.rep, response.rep, result, bstale)
|
||||
}
|
||||
else if (content.size() < 1000) // Authorization: Basic cy5jYXNhenphOnN0ZWZhbm8x==
|
||||
{
|
||||
|
@ -7895,7 +7882,7 @@ U_NO_EXPORT bool UHTTP::processAuthorization(const char* request, uint32_t sz, c
|
|||
}
|
||||
}
|
||||
|
||||
end: if (*user_authentication) user_authentication->duplicate();
|
||||
end: if (user_authentication->isConstant()) user_authentication->duplicate();
|
||||
|
||||
U_SRV_LOG("%srequest authorization for user %V %s", result ? "" : "WARNING: ", user_authentication->rep, result ? "success" : "failed");
|
||||
}
|
||||
|
@ -7904,8 +7891,8 @@ end: if (*user_authentication) user_authentication->duplicate();
|
|||
{
|
||||
// NB: we cannot authorize someone if it is not present above document root almost one auth file...
|
||||
|
||||
if (bpass || htdigest || htpasswd) setUnAuthorized();
|
||||
else setForbidden();
|
||||
if (bpass || htdigest || htpasswd) setUnAuthorized(bstale);
|
||||
else setForbidden();
|
||||
|
||||
U_RETURN(false);
|
||||
}
|
||||
|
@ -8869,9 +8856,9 @@ U_NO_EXPORT void UHTTP::manageDataForCache(const UString& basename, const UStrin
|
|||
}
|
||||
|
||||
if (bdigest &&
|
||||
U_STRING_FIND(content, 0, ":Protected Area:") == U_NOT_FOUND) // htdigest .htdigest 'Protected Area' admin
|
||||
U_STRING_FIND(content, 0, ":" U_HTTP_REALM ":") == U_NOT_FOUND) // htdigest .htdigest 'Protected Area' admin
|
||||
{
|
||||
U_WARNING("Find file data users permission (%V - %u bytes) that don't use the fixed realm name 'Protected Area', ignored", lpathname.rep, file_data->size);
|
||||
U_WARNING("Find file data users permission (%V - %u bytes) that don't use the fixed realm name '" U_HTTP_REALM "', ignored", lpathname.rep, file_data->size);
|
||||
|
||||
goto error;
|
||||
}
|
||||
|
@ -11846,6 +11833,10 @@ loop: while (u__isalpha(*++ptr1)) {}
|
|||
|
||||
setStatusDescription();
|
||||
|
||||
U_INTERNAL_ASSERT_EQUALS(UClientImage_Base::iov_vec[1].iov_base, ULog::date.date3)
|
||||
|
||||
ULog::updateDate3(U_NULLPTR);
|
||||
|
||||
next: if (*ptr1 == '?')
|
||||
{
|
||||
U_http_info.query = (const char*)(ptr1 += U_CONSTANT_SIZE("?queries"));
|
||||
|
|
|
@ -453,13 +453,22 @@ send_req() {
|
|||
|
||||
# function : wait_server_ready
|
||||
wait_server_ready() {
|
||||
$SLEEP
|
||||
for i in 1 2 3 4 5; do
|
||||
$1 -c $1 $2 </dev/null 2>/dev/null
|
||||
if [ $? -eq 0 ]; then
|
||||
break
|
||||
|
||||
if [ -z "$NCAT" ]; then
|
||||
check_for_netcat
|
||||
fi
|
||||
done
|
||||
|
||||
# FTMP=/tmp/get.req
|
||||
# echo -en 'GET / HTTP/1.0\r\n\r\n' >$FTMP
|
||||
|
||||
$SLEEP
|
||||
for i in 1 2 3 4 5; do
|
||||
# send_req $NCAT $1 $2 $FTMP web_server 3 || break
|
||||
$NCAT -z $1 $2
|
||||
if [ $? -eq 0 ]; then
|
||||
break
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
# function : post_processing
|
||||
|
|
|
@ -1 +1 @@
|
|||
0276
|
||||
02F0
|
||||
|
|
|
@ -9,7 +9,7 @@ userver {
|
|||
|
||||
ORM_DRIVER "sqlite mysql pgsql"
|
||||
|
||||
# LOG_FILE ../../benchmark.log
|
||||
LOG_FILE ../../benchmark.log
|
||||
# LOG_FILE_SZ 50M
|
||||
# LOG_MSG_SIZE -1
|
||||
|
||||
|
|
|
@ -4,10 +4,11 @@
|
|||
|
||||
(cd benchmark; rm -f db; creat_link FrameworkBenchmarks/ULib/db db)
|
||||
|
||||
DOC_ROOT=SESSION
|
||||
#DOC_ROOT=SESSION
|
||||
#DOC_ROOT=docroot
|
||||
#DOC_ROOT=sse_example
|
||||
#DOC_ROOT=ruby/blog
|
||||
DOC_ROOT=JONATHAN/docroot
|
||||
#DOC_ROOT=benchmark/docroot
|
||||
#DOC_ROOT=ShivShankarDayal/docroot
|
||||
|
||||
|
@ -17,7 +18,7 @@ rm -f tmp/usp_compile.sh.err /tmp/*.hpack.* \
|
|||
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 -1"
|
||||
UTRACE="0 50M 0"
|
||||
UTRACE_SIGNAL="0 50M -1"
|
||||
UTRACE_FOLDER=/tmp
|
||||
TMPDIR=/tmp
|
||||
|
@ -81,16 +82,19 @@ userver {
|
|||
#REQ_TIMEOUT 300
|
||||
#PLUGIN "ssi http"
|
||||
#ORM_DRIVER "sqlite mysql"
|
||||
#ORM_DRIVER sqlite
|
||||
#DOCUMENT_ROOT .
|
||||
ORM_DRIVER sqlite
|
||||
|
||||
#DOCUMENT_ROOT .
|
||||
#PLUGIN_DIR ../../src/ulib/net/server/plugin/.libs
|
||||
#ORM_DRIVER_DIR ../../src/ulib/orm/driver/.libs
|
||||
DOCUMENT_ROOT $DOC_ROOT
|
||||
PLUGIN_DIR ../../../src/ulib/net/server/plugin/.libs
|
||||
ORM_DRIVER_DIR ../../../src/ulib/orm/driver/.libs
|
||||
#DOCUMENT_ROOT benchmark/docroot
|
||||
#PLUGIN_DIR ../../../../src/ulib/net/server/plugin/.libs
|
||||
#ORM_DRIVER_DIR ../../../../src/ulib/orm/driver/.libs
|
||||
#DOCUMENT_ROOT docroot
|
||||
#PLUGIN_DIR ../../../src/ulib/net/server/plugin/.libs
|
||||
#ORM_DRIVER_DIR ../../../src/ulib/orm/driver/.libs
|
||||
#DOCUMENT_ROOT benchmark/docroot
|
||||
PLUGIN_DIR ../../../../src/ulib/net/server/plugin/.libs
|
||||
ORM_DRIVER_DIR ../../../../src/ulib/orm/driver/.libs
|
||||
|
||||
DOCUMENT_ROOT $DOC_ROOT
|
||||
}
|
||||
http {
|
||||
#ALIAS "[ / /100.html ]"
|
||||
|
@ -100,7 +104,8 @@ http {
|
|||
REQUEST_READ_TIMEOUT 30
|
||||
APACHE_LIKE_LOG /var/log/httpd/access_log
|
||||
LOG_FILE_SZ 10M
|
||||
DIGEST_AUTHENTICATION no
|
||||
DIGEST_AUTHENTICATION yes
|
||||
URI_PROTECTED_MASK /tutor/*|/learner/*|/HOD/*
|
||||
#CACHE_FILE_STORE nocat/webif.gz
|
||||
#CACHE_FILE_MASK inp/http/data/file1|*.flv|*.svgz
|
||||
#URI_REQUEST_STRICT_TRANSPORT_SECURITY_MASK *
|
||||
|
@ -111,7 +116,8 @@ export ORM_DRIVER="sqlite"
|
|||
export ELASTICSEARCH_HOST="localhost"
|
||||
export UMEMPOOL="750,0,123,251,305,53,-6,-26,52"
|
||||
#export ORM_OPTION="host=localhost dbname=../db/fortune"
|
||||
export ORM_OPTION="host=localhost dbname=../db/hello_world"
|
||||
#export ORM_OPTION="host=localhost dbname=../db/hello_world"
|
||||
export ORM_OPTION="host=localhost user=dbuser password=dbpass character-set=utf8 dbname=../db/concise-ile"
|
||||
|
||||
DIR_CMD="../../examples/userver"
|
||||
|
||||
|
|
|
@ -145,8 +145,8 @@ test_pcre_SOURCES = test_pcre.cpp
|
|||
endif
|
||||
|
||||
if SSL
|
||||
PRG += test_des3 test_digest test_certificate test_crl test_pkcs10 test_ssl_client test_ssl_server test_https test_pkcs7 test_url
|
||||
TST += des3.test digest.test certificate.test crl.test pkcs10.test ssl_client_server.test https.test pkcs7.test url.test
|
||||
PRG += test_des3 test_certificate test_crl test_pkcs10 test_ssl_client test_ssl_server test_https test_pkcs7 test_url test_digest
|
||||
TST += des3.test digest.test certificate.test crl.test pkcs10.test ssl_client_server.test https.test pkcs7.test url.test digest.test
|
||||
test_des3_SOURCES = test_des3.cpp
|
||||
test_digest_SOURCES = test_digest.cpp
|
||||
test_certificate_SOURCES = test_certificate.cpp
|
||||
|
|
|
@ -92,8 +92,8 @@ target_triplet = @target@
|
|||
@LIBTDB_TRUE@am__append_11 = tdb.test
|
||||
@PCRE_TRUE@am__append_12 = test_pcre
|
||||
@PCRE_TRUE@am__append_13 = pcre.test
|
||||
@SSL_TRUE@am__append_14 = test_des3 test_digest test_certificate test_crl test_pkcs10 test_ssl_client test_ssl_server test_https test_pkcs7 test_url
|
||||
@SSL_TRUE@am__append_15 = des3.test digest.test certificate.test crl.test pkcs10.test ssl_client_server.test https.test pkcs7.test url.test
|
||||
@SSL_TRUE@am__append_14 = test_des3 test_certificate test_crl test_pkcs10 test_ssl_client test_ssl_server test_https test_pkcs7 test_url test_digest
|
||||
@SSL_TRUE@am__append_15 = des3.test digest.test certificate.test crl.test pkcs10.test ssl_client_server.test https.test pkcs7.test url.test digest.test
|
||||
@SSL_TRUE@@SSL_TS_TRUE@am__append_16 = test_timestamp
|
||||
@SSL_TRUE@@SSL_TS_TRUE@am__append_17 = timestamp.test
|
||||
@SSH_TRUE@am__append_18 = test_ssh_client
|
||||
|
@ -183,11 +183,11 @@ product2_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) \
|
|||
@ZIP_TRUE@am__EXEEXT_6 = test_zip$(EXEEXT)
|
||||
@LIBTDB_TRUE@am__EXEEXT_7 = test_tdb$(EXEEXT)
|
||||
@PCRE_TRUE@am__EXEEXT_8 = test_pcre$(EXEEXT)
|
||||
@SSL_TRUE@am__EXEEXT_9 = test_des3$(EXEEXT) test_digest$(EXEEXT) \
|
||||
@SSL_TRUE@ test_certificate$(EXEEXT) test_crl$(EXEEXT) \
|
||||
@SSL_TRUE@ test_pkcs10$(EXEEXT) test_ssl_client$(EXEEXT) \
|
||||
@SSL_TRUE@ test_ssl_server$(EXEEXT) test_https$(EXEEXT) \
|
||||
@SSL_TRUE@ test_pkcs7$(EXEEXT) test_url$(EXEEXT)
|
||||
@SSL_TRUE@am__EXEEXT_9 = test_des3$(EXEEXT) test_certificate$(EXEEXT) \
|
||||
@SSL_TRUE@ test_crl$(EXEEXT) test_pkcs10$(EXEEXT) \
|
||||
@SSL_TRUE@ test_ssl_client$(EXEEXT) test_ssl_server$(EXEEXT) \
|
||||
@SSL_TRUE@ test_https$(EXEEXT) test_pkcs7$(EXEEXT) \
|
||||
@SSL_TRUE@ test_url$(EXEEXT) test_digest$(EXEEXT)
|
||||
@SSL_TRUE@@SSL_TS_TRUE@am__EXEEXT_10 = test_timestamp$(EXEEXT)
|
||||
@CURL_TRUE@am__EXEEXT_11 = test_curl$(EXEEXT)
|
||||
@MAGIC_TRUE@am__EXEEXT_12 = test_magic$(EXEEXT)
|
||||
|
|
|
@ -2,16 +2,23 @@
|
|||
|
||||
. ../.function
|
||||
|
||||
## digest.test -- Test vector feature
|
||||
## digest.test -- Test digest feature
|
||||
|
||||
start_msg digest
|
||||
|
||||
#UTRACE="0 1M 0"
|
||||
#UTRACE="0 5M 0"
|
||||
#UOBJDUMP="-1 100k 10"
|
||||
#USIMERR="error.sim"
|
||||
export UTRACE UOBJDUMP USIMERR
|
||||
|
||||
start_prg digest
|
||||
#STRACE=$TRUSS
|
||||
#VALGRIND='valgrind' # --leak-check=full
|
||||
|
||||
# ha1, nc, nonce, cnonce, uri, user
|
||||
start_prg digest "b9ee2af50be372e1784497693a3caa80" "00000002" "1533798660" "71afdcdea5197745" "/tutor/tutor_profile" "s.casazza" # 43bd362b65d2924c3f4bc47f8b4e94a0
|
||||
#start_prg digest "b9ee2af50be372e1784497693a3caa80" "00000003" "1533798660" "c1c6858eeaea3d54" "/tutor/tutor_home" "s.casazza" # 5000f6066f6ccf0277816292b18f5d0f
|
||||
#start_prg digest "b9ee2af50be372e1784497693a3caa80" "00000004" "1533798660" "5366e2067b7971fb" "/tutor/tutor_profile" "s.casazza" # f01b5eb77baf3511ce0f4d65b12d0093
|
||||
#start_prg digest "b9ee2af50be372e1784497693a3caa80" "00000003" "1533833952" "cf091939a67054ec" "/tutor/tutor_profile" "s.casazza" # 4f88e04ee241f80c9ff53d884805907b
|
||||
|
||||
# Test against expected output
|
||||
test_output_diff digest
|
||||
|
|
|
@ -1,7 +1 @@
|
|||
-> d41d8cd98f00b204e9800998ecf8427e
|
||||
a -> 0cc175b9c0f1b6a831c399e269772661
|
||||
abc -> 900150983cd24fb0d6963f7d28e17f72
|
||||
message digest -> f96b697d7cb7938d525a2f31aaf161d0
|
||||
abcdefghijklmnopqrstuvwxyz -> c3fcd3d76192e4007dfb496cca67e13b
|
||||
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 -> d174ab98d277d9f5a5611c2c9f419d9f
|
||||
12345678901234567890123456789012345678901234567890123456789012345678901234567890 -> 57edf4a22be3c955ac49da2e2107b67a
|
||||
43bd362b65d2924c3f4bc47f8b4e94a0
|
||||
|
|
|
@ -1,58 +1,31 @@
|
|||
// test_digest.cpp
|
||||
|
||||
#include <ulib/ssl/digest.h>
|
||||
#include <ulib/utility/services.h>
|
||||
|
||||
static const char* test[] = {
|
||||
"",
|
||||
"a",
|
||||
"abc",
|
||||
"message digest",
|
||||
"abcdefghijklmnopqrstuvwxyz",
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
|
||||
"12345678901234567890123456789012345678901234567890123456789012345678901234567890",
|
||||
0,
|
||||
};
|
||||
|
||||
static const char* ret[] = {
|
||||
"d41d8cd98f00b204e9800998ecf8427e",
|
||||
"0cc175b9c0f1b6a831c399e269772661",
|
||||
"900150983cd24fb0d6963f7d28e17f72",
|
||||
"f96b697d7cb7938d525a2f31aaf161d0",
|
||||
"c3fcd3d76192e4007dfb496cca67e13b",
|
||||
"d174ab98d277d9f5a5611c2c9f419d9f",
|
||||
"57edf4a22be3c955ac49da2e2107b67a",
|
||||
};
|
||||
#include <ulib/internal/chttp.h>
|
||||
|
||||
int
|
||||
U_EXPORT main (int argc, char* argv[])
|
||||
U_EXPORT main(int argc, char* argv[])
|
||||
{
|
||||
U_ULIB_INIT(argv);
|
||||
|
||||
U_TRACE(5,"main(%d)",argc)
|
||||
|
||||
int i;
|
||||
unsigned char* md;
|
||||
UString buffer(MD5_DIGEST_LENGTH * 2);
|
||||
U_INTERNAL_DUMP("argv[0] = %S argv[1] = %S argv[2] = %S argv[3] = %S argv[4] = %S argv[5] = %S argv[6] = %S", argv[0], argv[1], argv[2], argv[3], argv[4], argv[5], argv[6])
|
||||
|
||||
buffer.size_adjust(MD5_DIGEST_LENGTH * 2);
|
||||
UString ha1, nc, nonce, cnonce, uri, user, ha3(33U);
|
||||
|
||||
char* buf = buffer.data();
|
||||
const char** P = test;
|
||||
const char** R = ret;
|
||||
ha1.assign(argv[1]);
|
||||
nc.assign(argv[2]);
|
||||
nonce.assign(argv[3]);
|
||||
cnonce.assign(argv[4]);
|
||||
uri.assign(argv[5]);
|
||||
user.assign(argv[6]);
|
||||
|
||||
while (*P)
|
||||
{
|
||||
UString data(*P), output = UDigest::md5(data);
|
||||
u_init_http_method_list();
|
||||
|
||||
md = (unsigned char*)output.data();
|
||||
(void) UServices::setDigestCalcResponse(ha1, nc, nonce, cnonce, uri, user, ha3);
|
||||
|
||||
for (i = 0; i < MD5_DIGEST_LENGTH; ++i) (void)sprintf(&(buf[i*2]), "%02x", md[i]);
|
||||
|
||||
cout << *P << " -> " << buffer << endl;
|
||||
|
||||
U_ASSERT( buffer == *R )
|
||||
|
||||
++R;
|
||||
++P;
|
||||
}
|
||||
cout.write(U_STRING_TO_PARAM(ha3));
|
||||
cout.put('\n');
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user