mirror of
https://github.com/stefanocasazza/ULib.git
synced 2025-09-28 19:05:55 +08:00
completion management dedicated server process
This commit is contained in:
parent
c03d8716bb
commit
424c0fc222
|
@ -101,6 +101,7 @@ extern U_EXPORT int runDynamicPage_wi_auth(UClientImage_Base* client_image);
|
||||||
POST_ENTRY(admin_execute_recovery),
|
POST_ENTRY(admin_execute_recovery),
|
||||||
POST_ENTRY(admin_recovery),
|
POST_ENTRY(admin_recovery),
|
||||||
POST_ENTRY(admin_view_user),
|
POST_ENTRY(admin_view_user),
|
||||||
|
POST_ENTRY(info),
|
||||||
POST_ENTRY(login_request),
|
POST_ENTRY(login_request),
|
||||||
POST_ENTRY(login_request_IdP),
|
POST_ENTRY(login_request_IdP),
|
||||||
POST_ENTRY(password),
|
POST_ENTRY(password),
|
||||||
|
|
|
@ -68,6 +68,7 @@ static UHTTP::service_info POST_table[] = { // NB: the table must be ordered alp
|
||||||
POST_ENTRY(admin_execute_recovery),
|
POST_ENTRY(admin_execute_recovery),
|
||||||
POST_ENTRY(admin_recovery),
|
POST_ENTRY(admin_recovery),
|
||||||
POST_ENTRY(admin_view_user),
|
POST_ENTRY(admin_view_user),
|
||||||
|
POST_ENTRY(info),
|
||||||
POST_ENTRY(login_request),
|
POST_ENTRY(login_request),
|
||||||
POST_ENTRY(login_request_IdP),
|
POST_ENTRY(login_request_IdP),
|
||||||
POST_ENTRY(password),
|
POST_ENTRY(password),
|
||||||
|
|
|
@ -126,8 +126,12 @@ loop:
|
||||||
|
|
||||||
if (result)
|
if (result)
|
||||||
{
|
{
|
||||||
if (outpath.empty()) (void) write(1, U_STRING_TO_PARAM(result));
|
# ifdef USE_LIBZ
|
||||||
else UFile::writeTo(outpath, result);
|
if (UStringExt::isGzip(result)) result = UStringExt::gunzip(result);
|
||||||
|
# endif
|
||||||
|
|
||||||
|
if (outpath) UFile::writeTo(outpath, result);
|
||||||
|
else (void) write(1, U_STRING_TO_PARAM(result));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (queue_time)
|
if (queue_time)
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
class UHTTP;
|
class UHTTP;
|
||||||
class UHttpPlugIn;
|
class UHttpPlugIn;
|
||||||
class UFileConfig;
|
class UFileConfig;
|
||||||
|
class UNoCatPlugIn;
|
||||||
|
|
||||||
template <class T> class UVector;
|
template <class T> class UVector;
|
||||||
template <class T> class UOrmTypeHandler;
|
template <class T> class UOrmTypeHandler;
|
||||||
|
@ -415,7 +416,7 @@ public:
|
||||||
|
|
||||||
void clear() // erase all element
|
void clear() // erase all element
|
||||||
{
|
{
|
||||||
U_TRACE(0, "UVector<T*>::clear()")
|
U_TRACE(0+256, "UVector<T*>::clear()")
|
||||||
|
|
||||||
U_CHECK_MEMORY
|
U_CHECK_MEMORY
|
||||||
|
|
||||||
|
@ -1202,6 +1203,8 @@ public:
|
||||||
protected:
|
protected:
|
||||||
uint32_t loadFromData(const char* start, uint32_t size);
|
uint32_t loadFromData(const char* start, uint32_t size);
|
||||||
|
|
||||||
|
UStringRep* getStringRep(uint32_t pos) { return UVector<UStringRep*>::at(pos); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static void mksort(UStringRep** a, int n, int depth);
|
static void mksort(UStringRep** a, int n, int depth);
|
||||||
bool _isEqual(UVector<UString>& vec, bool ignore_case);
|
bool _isEqual(UVector<UString>& vec, bool ignore_case);
|
||||||
|
@ -1217,6 +1220,7 @@ private:
|
||||||
friend class UHTTP;
|
friend class UHTTP;
|
||||||
friend class UHttpPlugIn;
|
friend class UHttpPlugIn;
|
||||||
friend class UFileConfig;
|
friend class UFileConfig;
|
||||||
|
friend class UNoCatPlugIn;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -973,6 +973,10 @@ public:
|
||||||
if (result &&
|
if (result &&
|
||||||
U_IS_HTTP_ERROR(u_http_info.nResponseCode) == false)
|
U_IS_HTTP_ERROR(u_http_info.nResponseCode) == false)
|
||||||
{
|
{
|
||||||
|
# ifdef USE_LIBZ
|
||||||
|
if (UStringExt::isGzip(result)) result = UStringExt::gunzip(result);
|
||||||
|
# endif
|
||||||
|
|
||||||
UVector<UString> vec(result);
|
UVector<UString> vec(result);
|
||||||
|
|
||||||
for (uint32_t i = 0, n = vec.size(); i < n; i += 5)
|
for (uint32_t i = 0, n = vec.size(); i < n; i += 5)
|
||||||
|
@ -2735,6 +2739,10 @@ static bool askNodogToLogoutUser(const UString& _ip, const UString& _mac, bool b
|
||||||
|
|
||||||
U_INTERNAL_ASSERT(U_IS_HTTP_SUCCESS(u_http_info.nResponseCode))
|
U_INTERNAL_ASSERT(U_IS_HTTP_SUCCESS(u_http_info.nResponseCode))
|
||||||
|
|
||||||
|
# ifdef USE_LIBZ
|
||||||
|
if (UStringExt::isGzip(result)) result = UStringExt::gunzip(result);
|
||||||
|
# endif
|
||||||
|
|
||||||
if (U_STRING_FIND(result, 0, "DENY") == U_NOT_FOUND)
|
if (U_STRING_FIND(result, 0, "DENY") == U_NOT_FOUND)
|
||||||
{
|
{
|
||||||
U_LOGGER("*** USER STATUS NOT DENY: UID(%.*s) IP(%.*s) MAC(%.*s) AP(%.*s) ***",
|
U_LOGGER("*** USER STATUS NOT DENY: UID(%.*s) IP(%.*s) MAC(%.*s) AP(%.*s) ***",
|
||||||
|
@ -2757,7 +2765,7 @@ static bool askNodogToLogoutUser(const UString& _ip, const UString& _mac, bool b
|
||||||
U_STRING_TO_TRACE(*UClientImage_Base::request_uri),
|
U_STRING_TO_TRACE(*UClientImage_Base::request_uri),
|
||||||
U_STRING_TO_TRACE(*uid), U_STRING_TO_TRACE(_ip), U_STRING_TO_TRACE(_mac), U_STRING_TO_TRACE(*ap_address));
|
U_STRING_TO_TRACE(*uid), U_STRING_TO_TRACE(_ip), U_STRING_TO_TRACE(_mac), U_STRING_TO_TRACE(*ap_address));
|
||||||
|
|
||||||
(void) client->sendRequestAsync(*url_nodog, false, log_msg, file_WARNING->getFd());
|
(void) client->sendGETRequestAsync(*url_nodog, false, log_msg, file_WARNING->getFd());
|
||||||
|
|
||||||
U_RETURN(false);
|
U_RETURN(false);
|
||||||
}
|
}
|
||||||
|
@ -3491,7 +3499,12 @@ static void GET_admin_export_view_using_historical_as_csv()
|
||||||
U_TRACE(5, "::GET_admin_export_view_using_historical_as_csv()")
|
U_TRACE(5, "::GET_admin_export_view_using_historical_as_csv()")
|
||||||
|
|
||||||
if (UServer_Base::bssl == false) USSIPlugIn::setBadRequest();
|
if (UServer_Base::bssl == false) USSIPlugIn::setBadRequest();
|
||||||
else USSIPlugIn::setAlternativeResponse(file_UTILIZZO->_getContent());
|
else
|
||||||
|
{
|
||||||
|
UString body = file_UTILIZZO->_getContent();
|
||||||
|
|
||||||
|
USSIPlugIn::setAlternativeResponse(body);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void GET_admin_historical_statistics_login()
|
static void GET_admin_historical_statistics_login()
|
||||||
|
@ -3784,6 +3797,10 @@ static void GET_error_ap()
|
||||||
U_ASSERT( vuid->empty())
|
U_ASSERT( vuid->empty())
|
||||||
U_ASSERT(vallow_IP_user->empty())
|
U_ASSERT(vallow_IP_user->empty())
|
||||||
|
|
||||||
|
# ifdef USE_LIBZ
|
||||||
|
if (UStringExt::isGzip(result)) result = UStringExt::gunzip(result);
|
||||||
|
# endif
|
||||||
|
|
||||||
UIPAllow* elem;
|
UIPAllow* elem;
|
||||||
UVector<UString> vec(result);
|
UVector<UString> vec(result);
|
||||||
|
|
||||||
|
@ -4029,9 +4046,20 @@ static void GET_get_config()
|
||||||
|
|
||||||
UFileConfig cfg(_body, true);
|
UFileConfig cfg(_body, true);
|
||||||
|
|
||||||
if (cfg.processData()) _body = cfg.getData();
|
|
||||||
|
|
||||||
UHTTP::mime_index = U_know;
|
UHTTP::mime_index = U_know;
|
||||||
|
|
||||||
|
if (cfg.processData())
|
||||||
|
{
|
||||||
|
_body = cfg.getData();
|
||||||
|
|
||||||
|
# ifdef USE_LIBZ
|
||||||
|
if (U_http_is_accept_gzip &&
|
||||||
|
_body.size() > U_MIN_SIZE_FOR_DEFLATE)
|
||||||
|
{
|
||||||
|
_body = UStringExt::deflate(_body, 1);
|
||||||
|
}
|
||||||
|
# endif
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4253,6 +4281,17 @@ next:
|
||||||
if (vec.empty() == false) askNodogToLogoutUser(vec, false);
|
if (vec.empty() == false) askNodogToLogoutUser(vec, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void POST_info()
|
||||||
|
{
|
||||||
|
U_TRACE(5, "::POST_info()")
|
||||||
|
|
||||||
|
#ifdef USE_LIBZ
|
||||||
|
if (UStringExt::isGzip(*UClientImage_Base::body)) *UClientImage_Base::body = UStringExt::gunzip(*UClientImage_Base::body);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
GET_info();
|
||||||
|
}
|
||||||
|
|
||||||
static void GET_logged()
|
static void GET_logged()
|
||||||
{
|
{
|
||||||
U_TRACE(5, "::GET_logged()")
|
U_TRACE(5, "::GET_logged()")
|
||||||
|
@ -4651,6 +4690,10 @@ static void GET_login_validate()
|
||||||
if (result &&
|
if (result &&
|
||||||
U_IS_HTTP_ERROR(u_http_info.nResponseCode) == false)
|
U_IS_HTTP_ERROR(u_http_info.nResponseCode) == false)
|
||||||
{
|
{
|
||||||
|
# ifdef USE_LIBZ
|
||||||
|
if (UStringExt::isGzip(result)) result = UStringExt::gunzip(result);
|
||||||
|
# endif
|
||||||
|
|
||||||
UVector<UString> vec1(result);
|
UVector<UString> vec1(result);
|
||||||
|
|
||||||
for (uint32_t i = 0, n = vec1.size(); i < n; i += 5)
|
for (uint32_t i = 0, n = vec1.size(); i < n; i += 5)
|
||||||
|
|
|
@ -14,20 +14,21 @@
|
||||||
#ifndef ULIB_CHTTP_H
|
#ifndef ULIB_CHTTP_H
|
||||||
#define ULIB_CHTTP_H 1
|
#define ULIB_CHTTP_H 1
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------------------------------------
|
/**
|
||||||
_ _ _
|
* -------------------------------------------------------------------------------------------------------
|
||||||
| |__ | |_| |_ _ __
|
* _ _ _
|
||||||
| '_ \| __| __| '_ \
|
* | |__ | |_| |_ _ __
|
||||||
| | | | |_| |_| |_) |
|
* | '_ \| __| __| '_ \
|
||||||
|_| |_|\__|\__| .__/
|
* | | | | |_| |_| |_) |
|
||||||
|_|
|
* |_| |_|\__|\__| .__/
|
||||||
|
* |_|
|
||||||
---------------------------------------------------------------------------------------------------------
|
*
|
||||||
HTTP message handler
|
* ---------------------------------------------------------------------------------------------------------
|
||||||
|
* HTTP message handler
|
||||||
The status code is a three-digit integer, and the first digit identifies the general category of response
|
*
|
||||||
---------------------------------------------------------------------------------------------------------
|
* The status code is a three-digit integer, and the first digit identifies the general category of response
|
||||||
*/
|
* ---------------------------------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
/* 1xx indicates an informational message only */
|
/* 1xx indicates an informational message only */
|
||||||
#define HTTP_CONTINUE 100
|
#define HTTP_CONTINUE 100
|
||||||
|
@ -43,7 +44,7 @@
|
||||||
#define HTTP_RESET 205
|
#define HTTP_RESET 205
|
||||||
#define HTTP_PARTIAL 206
|
#define HTTP_PARTIAL 206
|
||||||
#define HTTP_STATUS_207 207 /* "Multi-Status" */
|
#define HTTP_STATUS_207 207 /* "Multi-Status" */
|
||||||
#define HTTP_OPTIONS_RESPONSE 222 /* internal use, not standard */
|
#define HTTP_OPTIONS_RESPONSE 222 /* only internal use, not standard */
|
||||||
|
|
||||||
/* 3xx redirects the client to another URL */
|
/* 3xx redirects the client to another URL */
|
||||||
#define HTTP_MULT_CHOICE 300
|
#define HTTP_MULT_CHOICE 300
|
||||||
|
@ -159,7 +160,7 @@ typedef struct uhttpinfo {
|
||||||
#define U_http_ip_client_len u_http_info.flag[ 8]
|
#define U_http_ip_client_len u_http_info.flag[ 8]
|
||||||
#define U_http_websocket_len u_http_info.flag[ 9]
|
#define U_http_websocket_len u_http_info.flag[ 9]
|
||||||
#define U_http2_settings_len u_http_info.flag[10]
|
#define U_http2_settings_len u_http_info.flag[10]
|
||||||
#define U_http_is_accept_gzip u_http_info.flag[11] /* NB: this pos is locked by mod_proxy (UHttpClient_Base::u_http_info_save)... */
|
#define U_http_is_accept_gzip u_http_info.flag[11] /* NB: this position(11) is locked by mod_proxy (UHttpClient_Base::u_http_info_save)... */
|
||||||
#define U_http_content_type_len u_http_info.flag[12]
|
#define U_http_content_type_len u_http_info.flag[12]
|
||||||
#define U_http_is_request_nostat u_http_info.flag[13]
|
#define U_http_is_request_nostat u_http_info.flag[13]
|
||||||
#define U_http_accept_language_len u_http_info.flag[14]
|
#define U_http_accept_language_len u_http_info.flag[14]
|
||||||
|
@ -205,9 +206,6 @@ typedef struct uhttpmethodtype {
|
||||||
uint32_t len;
|
uint32_t len;
|
||||||
} uhttpmethodtype;
|
} uhttpmethodtype;
|
||||||
|
|
||||||
#define U_HTTP_METHOD_TO_PARAM u_http_method_list[U_http_method_num].name, u_http_method_list[U_http_method_num].len
|
|
||||||
#define U_HTTP_METHOD_TO_TRACE u_http_method_list[U_http_method_num].len, u_http_method_list[U_http_method_num].name
|
|
||||||
|
|
||||||
#define U_HTTP_URI_TO_PARAM u_http_info.uri, u_http_info.uri_len
|
#define U_HTTP_URI_TO_PARAM u_http_info.uri, u_http_info.uri_len
|
||||||
#define U_HTTP_URI_TO_TRACE u_http_info.uri_len, u_http_info.uri
|
#define U_HTTP_URI_TO_TRACE u_http_info.uri_len, u_http_info.uri
|
||||||
|
|
||||||
|
@ -249,6 +247,12 @@ typedef struct uhttpmethodtype {
|
||||||
#define U_HTTP_ACCEPT_LANGUAGE_TO_PARAM u_http_info.accept_language, U_http_accept_language_len
|
#define U_HTTP_ACCEPT_LANGUAGE_TO_PARAM u_http_info.accept_language, U_http_accept_language_len
|
||||||
#define U_HTTP_ACCEPT_LANGUAGE_TO_TRACE U_http_accept_language_len, u_http_info.accept_language
|
#define U_HTTP_ACCEPT_LANGUAGE_TO_TRACE U_http_accept_language_len, u_http_info.accept_language
|
||||||
|
|
||||||
|
#define U_HTTP_METHOD_TO_PARAM U_HTTP_METHOD_NUM_TO_PARAM(U_http_method_num)
|
||||||
|
#define U_HTTP_METHOD_TO_TRACE U_HTTP_METHOD_NUM_TO_TRACE(U_http_method_num)
|
||||||
|
|
||||||
|
#define U_HTTP_METHOD_NUM_TO_PARAM(num) u_http_method_list[num].name, u_http_method_list[num].len
|
||||||
|
#define U_HTTP_METHOD_NUM_TO_TRACE(num) u_http_method_list[num].len, u_http_method_list[num].name
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The hostname of your server from header's request.
|
* The hostname of your server from header's request.
|
||||||
* The difference between U_HTTP_HOST_.. and U_HTTP_VHOST_.. is that
|
* The difference between U_HTTP_HOST_.. and U_HTTP_VHOST_.. is that
|
||||||
|
|
|
@ -24,6 +24,7 @@ class UProxyPlugIn;
|
||||||
class UNoCatPlugIn;
|
class UNoCatPlugIn;
|
||||||
class UServer_Base;
|
class UServer_Base;
|
||||||
class UClient_Base;
|
class UClient_Base;
|
||||||
|
class UHttpClient_Base;
|
||||||
class UClientImage_Base;
|
class UClientImage_Base;
|
||||||
|
|
||||||
// Logging is the process of recording application actions and state to a secondary interface
|
// Logging is the process of recording application actions and state to a secondary interface
|
||||||
|
@ -157,8 +158,8 @@ protected:
|
||||||
static void startup();
|
static void startup();
|
||||||
static void initStaticDate();
|
static void initStaticDate();
|
||||||
static void _updateStaticDate(char* ptr, int which);
|
static void _updateStaticDate(char* ptr, int which);
|
||||||
static void logResponse(const UString& data, const char* name, const char* format, ...);
|
static void logResponse(const UString& data, const char* name, const char* format, ...);
|
||||||
static void log(const struct iovec* iov, const char* name, const char* type, int ncount, const char* pipeline, const char* format, ...);
|
static void log(const struct iovec* iov, const char* name, const char* type, int ncount, const char* msg, uint32_t msg_len, const char* format, ...);
|
||||||
|
|
||||||
static void updateStaticDate(char* ptr, int which)
|
static void updateStaticDate(char* ptr, int which)
|
||||||
{
|
{
|
||||||
|
@ -194,6 +195,7 @@ private:
|
||||||
friend class UNoCatPlugIn;
|
friend class UNoCatPlugIn;
|
||||||
friend class UServer_Base;
|
friend class UServer_Base;
|
||||||
friend class UClient_Base;
|
friend class UClient_Base;
|
||||||
|
friend class UHttpClient_Base;
|
||||||
friend class UClientImage_Base;
|
friend class UClientImage_Base;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -155,7 +155,6 @@ public:
|
||||||
|
|
||||||
bool connect();
|
bool connect();
|
||||||
void clearData();
|
void clearData();
|
||||||
bool readHTTPResponse();
|
|
||||||
bool readResponse(uint32_t count = U_SINGLE_READ);
|
bool readResponse(uint32_t count = U_SINGLE_READ);
|
||||||
bool sendRequest(const UString& req, bool bread_response);
|
bool sendRequest(const UString& req, bool bread_response);
|
||||||
|
|
||||||
|
@ -178,11 +177,9 @@ public:
|
||||||
// Very simple RPC-like layer
|
// Very simple RPC-like layer
|
||||||
//
|
//
|
||||||
// Requests and responses are build of little packets each containing a 4-byte ascii token, an 8-byte hex value or length,
|
// Requests and responses are build of little packets each containing a 4-byte ascii token, an 8-byte hex value or length,
|
||||||
// and optionally data corresponding to the length.
|
// and optionally data corresponding to the length
|
||||||
// -----------------------------------------------------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
bool readRPCResponse();
|
|
||||||
|
|
||||||
// Transmit token name (4 characters) and value (32-bit int, as 8 hex characters)
|
// Transmit token name (4 characters) and value (32-bit int, as 8 hex characters)
|
||||||
|
|
||||||
bool sendTokenInt(const char* token, uint32_t value)
|
bool sendTokenInt(const char* token, uint32_t value)
|
||||||
|
@ -230,7 +227,9 @@ protected:
|
||||||
static bool log_shared_with_server, bIPv6;
|
static bool log_shared_with_server, bIPv6;
|
||||||
|
|
||||||
bool connectServer();
|
bool connectServer();
|
||||||
|
bool readHTTPResponse();
|
||||||
bool setUrl(const UString& url); // NB: return if it has modified host or port...
|
bool setUrl(const UString& url); // NB: return if it has modified host or port...
|
||||||
|
|
||||||
bool sendRequest(bool bread_response);
|
bool sendRequest(bool bread_response);
|
||||||
|
|
||||||
#ifdef USE_LIBSSL
|
#ifdef USE_LIBSSL
|
||||||
|
|
|
@ -125,7 +125,11 @@ public:
|
||||||
|
|
||||||
// ASYNC MODE (it creates a copy of itself, return pid child if parent)
|
// ASYNC MODE (it creates a copy of itself, return pid child if parent)
|
||||||
|
|
||||||
int sendRequestAsync(const UString& url, bool bqueue = true, const char* log_msg = 0, int log_fd = -1);
|
int sendGETRequestAsync(const UString& _url, bool bqueue, const char* log_msg, int log_fd = -1)
|
||||||
|
{ method_num = 0; return sendRequestAsync(_url, bqueue, log_msg, log_fd); }
|
||||||
|
|
||||||
|
int sendPOSTRequestAsync(const UString& _body, const UString& _url, bool bqueue, const char* log_msg, int log_fd = -1)
|
||||||
|
{ body = _body; method_num = 2; return sendRequestAsync(_url, bqueue, log_msg, log_fd); }
|
||||||
|
|
||||||
// QUEUE MODE
|
// QUEUE MODE
|
||||||
|
|
||||||
|
@ -153,9 +157,10 @@ protected:
|
||||||
|
|
||||||
static struct uhttpinfo u_http_info_save;
|
static struct uhttpinfo u_http_info_save;
|
||||||
|
|
||||||
void parseRequest();
|
|
||||||
void composeRequest();
|
|
||||||
bool sendRequestEngine();
|
bool sendRequestEngine();
|
||||||
|
void parseRequest(uint32_t n = 3);
|
||||||
|
void composeRequest(const char* content_type = 0);
|
||||||
|
int sendRequestAsync(const UString& url, bool bqueue, const char* log_msg, int log_fd);
|
||||||
|
|
||||||
// Add the MIME-type headers to the request for HTTP server
|
// Add the MIME-type headers to the request for HTTP server
|
||||||
|
|
||||||
|
@ -163,7 +168,7 @@ protected:
|
||||||
const char* uri, uint32_t uri_len, const char* extension, const char* content_type = 0);
|
const char* uri, uint32_t uri_len, const char* extension, const char* content_type = 0);
|
||||||
|
|
||||||
// In response to a HTTP_UNAUTHORISED response from the HTTP server, this function will attempt
|
// In response to a HTTP_UNAUTHORISED response from the HTTP server, this function will attempt
|
||||||
// to generate an Authentication header to satisfy the server.
|
// to generate an Authentication header to satisfy the server
|
||||||
|
|
||||||
bool createAuthorizationHeader();
|
bool createAuthorizationHeader();
|
||||||
int checkResponse(int& redirectCount);
|
int checkResponse(int& redirectCount);
|
||||||
|
|
|
@ -17,6 +17,8 @@
|
||||||
#include <ulib/net/client/client.h>
|
#include <ulib/net/client/client.h>
|
||||||
#include <ulib/net/rpc/rpc_encoder.h>
|
#include <ulib/net/rpc/rpc_encoder.h>
|
||||||
|
|
||||||
|
class URDBClient_Base;
|
||||||
|
|
||||||
class U_EXPORT URPCClient_Base : public UClient_Base {
|
class U_EXPORT URPCClient_Base : public UClient_Base {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
@ -30,9 +32,9 @@ public:
|
||||||
|
|
||||||
UString request = URPCMethod::encoder->encodeMethodCall(method, UString::getStringNull());
|
UString request = URPCMethod::encoder->encodeMethodCall(method, UString::getStringNull());
|
||||||
|
|
||||||
if (UClient_Base::sendRequest(request, false) &&
|
if (sendRequest(request, false) &&
|
||||||
UClient_Base::readRPCResponse() &&
|
readResponse(socket, buffer, response) &&
|
||||||
UClient_Base::buffer.equal(U_CONSTANT_TO_PARAM("DONE")))
|
buffer.equal(U_CONSTANT_TO_PARAM("DONE")))
|
||||||
{
|
{
|
||||||
U_RETURN(true);
|
U_RETURN(true);
|
||||||
}
|
}
|
||||||
|
@ -64,6 +66,31 @@ protected:
|
||||||
delete URPCMethod::encoder;
|
delete URPCMethod::encoder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool readResponse(USocket* sk, UString& buffer, UString& response)
|
||||||
|
{
|
||||||
|
U_TRACE(0, "URPCClient_Base::readResponse(%p,%.*S,%.*S)", sk, U_STRING_TO_TRACE(buffer), U_STRING_TO_TRACE(response))
|
||||||
|
|
||||||
|
uint32_t rstart = 0;
|
||||||
|
|
||||||
|
// NB: we force for U_SUBSTR_INC_REF case (string can be referenced more)...
|
||||||
|
|
||||||
|
buffer.setEmptyForce();
|
||||||
|
response.setEmptyForce();
|
||||||
|
|
||||||
|
if (URPC::readTokenString(sk, 0, buffer, rstart, response))
|
||||||
|
{
|
||||||
|
// NB: we force for U_SUBSTR_INC_REF case (string can be referenced more)...
|
||||||
|
|
||||||
|
buffer.size_adjust_force(U_TOKEN_NM);
|
||||||
|
}
|
||||||
|
|
||||||
|
U_INTERNAL_DUMP("buffer = %.*S response = %.*S)", U_STRING_TO_TRACE(buffer), U_STRING_TO_TRACE(response))
|
||||||
|
|
||||||
|
if (buffer) U_RETURN(true);
|
||||||
|
|
||||||
|
U_RETURN(false);
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
#ifdef U_COMPILER_DELETE_MEMBERS
|
#ifdef U_COMPILER_DELETE_MEMBERS
|
||||||
URPCClient_Base(const URPCClient_Base&) = delete;
|
URPCClient_Base(const URPCClient_Base&) = delete;
|
||||||
|
@ -72,6 +99,8 @@ private:
|
||||||
URPCClient_Base(const URPCClient_Base&) : UClient_Base(0) {}
|
URPCClient_Base(const URPCClient_Base&) : UClient_Base(0) {}
|
||||||
URPCClient_Base& operator=(const URPCClient_Base&) { return *this; }
|
URPCClient_Base& operator=(const URPCClient_Base&) { return *this; }
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
friend class URDBClient_Base;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class Socket> class U_EXPORT URPCClient : public URPCClient_Base {
|
template <class Socket> class U_EXPORT URPCClient : public URPCClient_Base {
|
||||||
|
|
|
@ -181,11 +181,11 @@ protected:
|
||||||
static UString* peer_present_in_arp_cache;
|
static UString* peer_present_in_arp_cache;
|
||||||
|
|
||||||
static UVector<Url*>* vauth_url;
|
static UVector<Url*>* vauth_url;
|
||||||
static UVector<Url*>* vinfo_url;
|
|
||||||
static UVector<UString>* vauth;
|
static UVector<UString>* vauth;
|
||||||
static UVector<UString>* vauth_ip;
|
static UVector<UString>* vauth_ip;
|
||||||
static UVector<UString>* openlist;
|
static UVector<UString>* openlist;
|
||||||
static UVector<UString>* varp_cache;
|
static UVector<UString>* varp_cache;
|
||||||
|
static UVector<UString>* vinfo_data;
|
||||||
static UVector<UIPAddress*>** vaddr;
|
static UVector<UIPAddress*>** vaddr;
|
||||||
static UHttpClient<UTCPSocket>* client;
|
static UHttpClient<UTCPSocket>* client;
|
||||||
static UHashMap<UModNoCatPeer*>* peers;
|
static UHashMap<UModNoCatPeer*>* peers;
|
||||||
|
@ -210,26 +210,41 @@ protected:
|
||||||
|
|
||||||
// VARIE
|
// VARIE
|
||||||
|
|
||||||
|
static void getTraffic();
|
||||||
static void setNewPeer();
|
static void setNewPeer();
|
||||||
|
static void checkSystem();
|
||||||
static void checkOldPeer();
|
static void checkOldPeer();
|
||||||
static void creatNewPeer();
|
static void creatNewPeer();
|
||||||
static bool creatNewPeer(uint32_t index_AUTH);
|
static bool checkFirewall();
|
||||||
|
|
||||||
static void preallocatePeers() { U_NEW_VECTOR_ULIB_OBJECT(peers_preallocate, num_peers_preallocate, UModNoCatPeer, 0); }
|
|
||||||
static bool preallocatePeersFault();
|
static bool preallocatePeersFault();
|
||||||
|
static void deny(bool disconnected);
|
||||||
static bool checkFirewall();
|
static void executeCommand(int type);
|
||||||
static uint32_t checkFirewall(UString& output);
|
|
||||||
static uint32_t getIndexAUTH(const char* ip_address) __pure;
|
|
||||||
|
|
||||||
static void checkSystem();
|
|
||||||
static void addPeerInfo(time_t logout);
|
static void addPeerInfo(time_t logout);
|
||||||
static bool getPeer(uint32_t i) __pure;
|
static bool getPeer(uint32_t i) __pure;
|
||||||
static void uploadFileToPortal(UFile& file);
|
static void uploadFileToPortal(UFile& file);
|
||||||
|
static bool creatNewPeer(uint32_t index_AUTH);
|
||||||
|
static void sendInfoData(uint32_t index_AUTH);
|
||||||
static bool getPeerFromMAC(const UString& mac);
|
static bool getPeerFromMAC(const UString& mac);
|
||||||
static bool checkAuthMessage(const UString& msg);
|
static bool checkAuthMessage(const UString& msg);
|
||||||
static void setStatusContent(const UString& label);
|
static void setStatusContent(const UString& label);
|
||||||
|
static void setHTTPResponse(const UString& content);
|
||||||
|
static void notifyAuthOfUsersInfo(uint32_t index_AUTH);
|
||||||
|
static bool getPeerStatus(UStringRep* key, void* value);
|
||||||
|
static bool checkPeerInfo(UStringRep* key, void* value);
|
||||||
|
static bool checkPeerStatus(UStringRep* key, void* value);
|
||||||
|
static bool getPeerListInfo(UStringRep* key, void* value);
|
||||||
static void setRedirectLocation(const UString& redirect, const Url& auth);
|
static void setRedirectLocation(const UString& redirect, const Url& auth);
|
||||||
|
static void permit(const UString& UserDownloadRate, const UString& UserUploadRate);
|
||||||
|
static void sendMsgToPortal(uint32_t index_AUTH, const UString& msg, UString* poutput);
|
||||||
|
static void setFireWallCommand(UCommand& cmd, const UString& script, const UString& mac, const UString& ip);
|
||||||
|
|
||||||
|
static uint32_t checkFirewall(UString& output);
|
||||||
|
static uint32_t getIndexAUTH(const char* ip_address) __pure;
|
||||||
|
static UString getIPAddress(const char* ptr, uint32_t len);
|
||||||
|
static UString getSignedData(const char* ptr, uint32_t len);
|
||||||
|
static UString getUrlForSendMsgToPortal(uint32_t index_AUTH, const char* msg, uint32_t msg_len);
|
||||||
|
|
||||||
|
static void preallocatePeers() { U_NEW_VECTOR_ULIB_OBJECT(peers_preallocate, num_peers_preallocate, UModNoCatPeer, 0); }
|
||||||
|
|
||||||
static void getARPCache()
|
static void getARPCache()
|
||||||
{
|
{
|
||||||
|
@ -238,32 +253,13 @@ protected:
|
||||||
(void) USocketExt::getARPCache(*arp_cache, *varp_cache);
|
(void) USocketExt::getARPCache(*arp_cache, *varp_cache);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void sendMsgToPortal(const UString& msg)
|
static void sendMsgToAllPortal(const UString& msg)
|
||||||
{
|
{
|
||||||
U_TRACE(0, "UNoCatPlugIn::sendMsgToPortal(%.*S)", U_STRING_TO_TRACE(msg))
|
U_TRACE(0, "UNoCatPlugIn::sendMsgToAllPortal(%.*S)", U_STRING_TO_TRACE(msg))
|
||||||
|
|
||||||
for (uint32_t i = 0, n = vinfo_url->size(); i < n; ++i) sendMsgToPortal(i, msg, 0, false);
|
for (uint32_t i = 0, n = vauth_url->size(); i < n; ++i) sendMsgToPortal(i, msg, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void sendMsgToPortal(uint32_t index_AUTH, const UString& msg, UString* poutput, bool basync);
|
|
||||||
|
|
||||||
static UString getIPAddress(const char* ptr, uint32_t len);
|
|
||||||
static UString getSignedData(const char* ptr, uint32_t len);
|
|
||||||
static UString getUrlForSendMsgToPortal(uint32_t index_AUTH, const char* msg, uint32_t msg_len);
|
|
||||||
|
|
||||||
static void deny(bool disconnected);
|
|
||||||
static void permit(const UString& UserDownloadRate, const UString& UserUploadRate);
|
|
||||||
|
|
||||||
static void getTraffic();
|
|
||||||
static void executeCommand(int type);
|
|
||||||
static void setHTTPResponse(const UString& content);
|
|
||||||
static void notifyAuthOfUsersInfo(uint32_t index_AUTH);
|
|
||||||
static bool getPeerStatus(UStringRep* key, void* value);
|
|
||||||
static bool checkPeerInfo(UStringRep* key, void* value);
|
|
||||||
static bool checkPeerStatus(UStringRep* key, void* value);
|
|
||||||
static bool getPeerListInfo(UStringRep* key, void* value);
|
|
||||||
static void setFireWallCommand(UCommand& cmd, const UString& script, const UString& mac, const UString& ip);
|
|
||||||
|
|
||||||
static bool isPingAsyncPending()
|
static bool isPingAsyncPending()
|
||||||
{
|
{
|
||||||
U_TRACE(0, "UNoCatPlugIn::isPingAsyncPending()")
|
U_TRACE(0, "UNoCatPlugIn::isPingAsyncPending()")
|
||||||
|
|
|
@ -57,7 +57,7 @@ public:
|
||||||
|
|
||||||
static void setBadRequest();
|
static void setBadRequest();
|
||||||
static void setAlternativeResponse();
|
static void setAlternativeResponse();
|
||||||
static void setAlternativeResponse(const UString& body);
|
static void setAlternativeResponse(UString& body);
|
||||||
static void setAlternativeRedirect(const char* fmt, ...);
|
static void setAlternativeRedirect(const char* fmt, ...);
|
||||||
static void setAlternativeInclude(const UString& tmpl, uint32_t estimated_size, bool bprocess,
|
static void setAlternativeInclude(const UString& tmpl, uint32_t estimated_size, bool bprocess,
|
||||||
const char* title_txt, const char* ssi_head, const char* body_style, ...);
|
const char* title_txt, const char* ssi_head, const char* body_style, ...);
|
||||||
|
|
|
@ -66,6 +66,9 @@ public:
|
||||||
|
|
||||||
// GZIP method
|
// GZIP method
|
||||||
|
|
||||||
|
static bool isGzip(const char* s) { return (*(int16_t*)s == U_MULTICHAR_CONSTANT16('\x1F','\x8B')); }
|
||||||
|
static bool isGzip(const UString& s) { return isGzip(s.data()); }
|
||||||
|
|
||||||
static UString deflate(const char* s, uint32_t n, int type); // .gz compress
|
static UString deflate(const char* s, uint32_t n, int type); // .gz compress
|
||||||
static UString gunzip(const char* s, uint32_t n, uint32_t sz_orig); // .gz uncompress
|
static UString gunzip(const char* s, uint32_t n, uint32_t sz_orig); // .gz uncompress
|
||||||
|
|
||||||
|
|
|
@ -271,7 +271,7 @@ public:
|
||||||
NETWORK_AUTHENTICATION_REQUIRED = 0x008
|
NETWORK_AUTHENTICATION_REQUIRED = 0x008
|
||||||
};
|
};
|
||||||
|
|
||||||
static void setResponse(const UString* content_type, const UString* body);
|
static void setResponse(const UString* content_type, UString* pbody);
|
||||||
static void setRedirectResponse(int mode, const UString& ext, const char* ptr_location, uint32_t len_location);
|
static void setRedirectResponse(int mode, const UString& ext, const char* ptr_location, uint32_t len_location);
|
||||||
|
|
||||||
// get HTTP response message
|
// get HTTP response message
|
||||||
|
|
|
@ -1016,14 +1016,16 @@ uint32_t u_strftime2(char* restrict s, uint32_t maxsize, const char* restrict fo
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
{
|
{
|
||||||
char dbg[4096];
|
|
||||||
uint32_t result = u_strftime1(s, maxsize, format);
|
uint32_t result = u_strftime1(s, maxsize, format);
|
||||||
|
|
||||||
|
/*
|
||||||
|
char dbg[4096];
|
||||||
if (strftime(dbg, maxsize, format, &u_strftime_tm) &&
|
if (strftime(dbg, maxsize, format, &u_strftime_tm) &&
|
||||||
strcmp(s,dbg))
|
strcmp(s,dbg))
|
||||||
{
|
{
|
||||||
U_WARNING("DIFFERENT: u_strftime2() = \"%s\" strftime() = \"%s\" format = \"%s\"", s, dbg, format);
|
U_WARNING("DIFFERENT: u_strftime2() = \"%s\" strftime() = \"%s\" format = \"%s\"", s, dbg, format);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -228,7 +228,7 @@ __pure uint32_t UVector<UString>::find(const char* s, uint32_t n)
|
||||||
|
|
||||||
__pure uint32_t UVector<UString>::findRange(const char* s, uint32_t n, uint32_t start, uint32_t _end)
|
__pure uint32_t UVector<UString>::findRange(const char* s, uint32_t n, uint32_t start, uint32_t _end)
|
||||||
{
|
{
|
||||||
U_TRACE(0, "UVector<UString>::findRange(%.*S,%u,%u,%u)", n, s, n, start, _end)
|
U_TRACE(0+256, "UVector<UString>::findRange(%.*S,%u,%u,%u)", n, s, n, start, _end)
|
||||||
|
|
||||||
U_CHECK_MEMORY
|
U_CHECK_MEMORY
|
||||||
|
|
||||||
|
|
|
@ -188,7 +188,7 @@ void UError::stackDump()
|
||||||
|
|
||||||
FILE* f = fdopen(fd, "w");
|
FILE* f = fdopen(fd, "w");
|
||||||
|
|
||||||
(void) fwrite(U_CONSTANT_TO_PARAM("=== STACK TRACE ===\n"), 1, f);
|
(void) fwrite(buffer, u__snprintf(buffer, sizeof(buffer), "%9D: %N (pid %P) === STACK TRACE ===\n", 0), 1, f);
|
||||||
|
|
||||||
# ifdef HAVE_DLFCN_H
|
# ifdef HAVE_DLFCN_H
|
||||||
Dl_info dlinf;
|
Dl_info dlinf;
|
||||||
|
|
|
@ -610,9 +610,9 @@ void ULog::log(int _fd, const char* fmt, ...)
|
||||||
(void) U_SYSCALL(writev, "%d,%p,%d", _fd, iov_vec, 5);
|
(void) U_SYSCALL(writev, "%d,%p,%d", _fd, iov_vec, 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ULog::log(const struct iovec* iov, const char* name, const char* type, int ncount, const char* pipeline, const char* format, ...)
|
void ULog::log(const struct iovec* iov, const char* name, const char* type, int ncount, const char* msg, uint32_t msg_len, const char* format, ...)
|
||||||
{
|
{
|
||||||
U_TRACE(0, "ULog::log(%p,%S,%S,%d,%S,%S)", iov, name, type, ncount, pipeline, format)
|
U_TRACE(0, "ULog::log(%p,%S,%S,%d,%.*S,%u,%S)", iov, name, type, ncount, msg_len, msg, msg_len, format)
|
||||||
|
|
||||||
U_INTERNAL_ASSERT_MAJOR(ncount, 0)
|
U_INTERNAL_ASSERT_MAJOR(ncount, 0)
|
||||||
|
|
||||||
|
@ -674,7 +674,7 @@ void ULog::log(const struct iovec* iov, const char* name, const char* type, int
|
||||||
ptr = buffer1;
|
ptr = buffer1;
|
||||||
}
|
}
|
||||||
|
|
||||||
len = u__snprintf(buffer2, sizeof(buffer2), "%ssend %s (%u bytes) %s%.*S", name, type, ncount, pipeline, sz, ptr);
|
len = u__snprintf(buffer2, sizeof(buffer2), "%ssend %s (%u bytes) %.*s%.*S", name, type, ncount, msg_len, msg, sz, ptr);
|
||||||
|
|
||||||
va_list argp;
|
va_list argp;
|
||||||
va_start(argp, format);
|
va_start(argp, format);
|
||||||
|
|
|
@ -511,8 +511,8 @@ resend:
|
||||||
|
|
||||||
if (log)
|
if (log)
|
||||||
{
|
{
|
||||||
ULog::log(iov, name, "request", ncount, "", " to %.*s", U_STRING_TO_TRACE(host_port));
|
ULog::log(iov, name, "request", ncount, "", 0, " to %.*s", U_STRING_TO_TRACE(host_port));
|
||||||
ULog::log("%serror on reading data from %.*S%R", name, U_STRING_TO_TRACE(host_port), 0); // 0 is necessary...
|
ULog::log("%serror on reading data from %.*S%R", name, U_STRING_TO_TRACE(host_port), 0); // 0 is necessary
|
||||||
}
|
}
|
||||||
|
|
||||||
U_RETURN(false);
|
U_RETURN(false);
|
||||||
|
@ -520,8 +520,8 @@ resend:
|
||||||
|
|
||||||
if (log)
|
if (log)
|
||||||
{
|
{
|
||||||
ULog::log(iov, name, "request", ncount, "", " to %.*s", U_STRING_TO_TRACE(host_port));
|
ULog::log(iov, name, "request", ncount, "", 0, " to %.*s", U_STRING_TO_TRACE(host_port));
|
||||||
if (response) ULog::logResponse(response, name, " from %.*s", U_STRING_TO_TRACE(host_port));
|
if (response) ULog::logResponse(response, name, " from %.*s", U_STRING_TO_TRACE(host_port));
|
||||||
}
|
}
|
||||||
|
|
||||||
reset();
|
reset();
|
||||||
|
@ -552,6 +552,7 @@ bool UClient_Base::readResponse(uint32_t count)
|
||||||
U_RETURN(false);
|
U_RETURN(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool UClient_Base::readHTTPResponse()
|
bool UClient_Base::readHTTPResponse()
|
||||||
{
|
{
|
||||||
U_TRACE(0, "UClient_Base::readHTTPResponse()")
|
U_TRACE(0, "UClient_Base::readHTTPResponse()")
|
||||||
|
@ -587,31 +588,6 @@ bool UClient_Base::readHTTPResponse()
|
||||||
U_RETURN(false);
|
U_RETURN(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool UClient_Base::readRPCResponse()
|
|
||||||
{
|
|
||||||
U_TRACE(0, "UClient_Base::readRPCResponse()")
|
|
||||||
|
|
||||||
// NB: we force for U_SUBSTR_INC_REF case (string can be referenced more)...
|
|
||||||
|
|
||||||
buffer.setEmptyForce();
|
|
||||||
response.setEmptyForce();
|
|
||||||
|
|
||||||
uint32_t rstart = 0;
|
|
||||||
|
|
||||||
if (URPC::readTokenString(socket, 0, buffer, rstart, response))
|
|
||||||
{
|
|
||||||
// NB: we force for U_SUBSTR_INC_REF case (string can be referenced more)...
|
|
||||||
|
|
||||||
buffer.size_adjust_force(U_TOKEN_NM);
|
|
||||||
}
|
|
||||||
|
|
||||||
U_INTERNAL_DUMP("buffer = %.*S response = %.*S)", U_STRING_TO_TRACE(buffer), U_STRING_TO_TRACE(response))
|
|
||||||
|
|
||||||
if (buffer) U_RETURN(true);
|
|
||||||
|
|
||||||
U_RETURN(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
// DEBUG
|
// DEBUG
|
||||||
|
|
||||||
#if defined(U_STDCPP_ENABLE) && defined(DEBUG)
|
#if defined(U_STDCPP_ENABLE) && defined(DEBUG)
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
//
|
//
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
|
||||||
|
#include <ulib/net/rpc/rpc_client.h>
|
||||||
#include <ulib/utility/socket_ext.h>
|
#include <ulib/utility/socket_ext.h>
|
||||||
#include <ulib/net/client/client_rdb.h>
|
#include <ulib/net/client/client_rdb.h>
|
||||||
|
|
||||||
|
@ -47,7 +48,7 @@ bool URDBClient_Base::readResponse()
|
||||||
|
|
||||||
response.setBuffer(U_CAPACITY);
|
response.setBuffer(U_CAPACITY);
|
||||||
|
|
||||||
if (this->UClient_Base::readRPCResponse())
|
if (URPCClient_Base::readResponse(socket, buffer, response))
|
||||||
{
|
{
|
||||||
nResponseCode = strtol(buffer.data(), 0, 10);
|
nResponseCode = strtol(buffer.data(), 0, 10);
|
||||||
|
|
||||||
|
@ -77,10 +78,13 @@ bool URDBClient_Base::processRequest(const char* token)
|
||||||
|
|
||||||
UStringExt::buildTokenVector(token, *URPC::rpc_info, request);
|
UStringExt::buildTokenVector(token, *URPC::rpc_info, request);
|
||||||
|
|
||||||
bool result = this->UClient_Base::sendRequest(request, false) &&
|
if (sendRequest(request, false) &&
|
||||||
this->readResponse();
|
readResponse())
|
||||||
|
{
|
||||||
|
U_RETURN(true);
|
||||||
|
}
|
||||||
|
|
||||||
U_RETURN(result);
|
U_RETURN(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool URDBClient_Base::closeReorganize()
|
bool URDBClient_Base::closeReorganize()
|
||||||
|
|
|
@ -394,7 +394,7 @@ bool UHttpClient_Base::createAuthorizationHeader()
|
||||||
|
|
||||||
// MD5(method : uri)
|
// MD5(method : uri)
|
||||||
|
|
||||||
a2.snprintf("%.*s:%.*s", u_http_method_list[method_num].len, u_http_method_list[method_num].name, U_STRING_TO_TRACE(UClient_Base::uri));
|
a2.snprintf("%.*s:%.*s", U_HTTP_METHOD_NUM_TO_TRACE(method_num), U_STRING_TO_TRACE(UClient_Base::uri));
|
||||||
|
|
||||||
UServices::generateDigest(U_HASH_MD5, 0, a2, ha2, false);
|
UServices::generateDigest(U_HASH_MD5, 0, a2, ha2, false);
|
||||||
|
|
||||||
|
@ -619,9 +619,7 @@ int UHttpClient_Base::sendRequestAsync(const UString& _url, bool bqueue, const c
|
||||||
{
|
{
|
||||||
// we need to compose the request to the HTTP server...
|
// we need to compose the request to the HTTP server...
|
||||||
|
|
||||||
method_num = 0; // GET
|
composeRequest("application/x-www-form-urlencoded");
|
||||||
|
|
||||||
composeRequest();
|
|
||||||
|
|
||||||
UClient_Base::adjustTimeOut();
|
UClient_Base::adjustTimeOut();
|
||||||
|
|
||||||
|
@ -689,9 +687,9 @@ next:
|
||||||
// We do not process Location headers when accompanying a 200 OK response.
|
// We do not process Location headers when accompanying a 200 OK response.
|
||||||
//=============================================================================
|
//=============================================================================
|
||||||
|
|
||||||
void UHttpClient_Base::parseRequest()
|
void UHttpClient_Base::parseRequest(uint32_t n)
|
||||||
{
|
{
|
||||||
U_TRACE(0, "UHttpClient_Base::parseRequest()")
|
U_TRACE(0, "UHttpClient_Base::parseRequest(%u)", n)
|
||||||
|
|
||||||
U_INTERNAL_DUMP("last_request = %.*S", U_STRING_TO_TRACE(last_request))
|
U_INTERNAL_DUMP("last_request = %.*S", U_STRING_TO_TRACE(last_request))
|
||||||
|
|
||||||
|
@ -703,7 +701,7 @@ void UHttpClient_Base::parseRequest()
|
||||||
|
|
||||||
const char* ptr = last_request.data();
|
const char* ptr = last_request.data();
|
||||||
|
|
||||||
UClient_Base::iovcnt = 3;
|
UClient_Base::iovcnt = n;
|
||||||
|
|
||||||
UClient_Base::iov[0].iov_base = (caddr_t)ptr;
|
UClient_Base::iov[0].iov_base = (caddr_t)ptr;
|
||||||
UClient_Base::iov[0].iov_len = startHeader;
|
UClient_Base::iov[0].iov_len = startHeader;
|
||||||
|
@ -728,10 +726,12 @@ UString UHttpClient_Base::wrapRequest(UString* req, const UString& host_port, ui
|
||||||
|
|
||||||
tmp.snprintf("%.*s %.*s HTTP/1.1\r\n"
|
tmp.snprintf("%.*s %.*s HTTP/1.1\r\n"
|
||||||
"Host: %.*s\r\n"
|
"Host: %.*s\r\n"
|
||||||
|
# ifdef USE_LIBZ
|
||||||
|
"Accept-Encoding: gzip\r\n"
|
||||||
|
# endif
|
||||||
"User-Agent: " PACKAGE_NAME "/" PACKAGE_VERSION "\r\n"
|
"User-Agent: " PACKAGE_NAME "/" PACKAGE_VERSION "\r\n"
|
||||||
"%s",
|
"%s",
|
||||||
u_http_method_list[method_num].len, u_http_method_list[method_num].name,
|
U_HTTP_METHOD_NUM_TO_TRACE(method_num), uri_len, _uri,
|
||||||
uri_len, _uri,
|
|
||||||
U_STRING_TO_TRACE(host_port),
|
U_STRING_TO_TRACE(host_port),
|
||||||
extension);
|
extension);
|
||||||
|
|
||||||
|
@ -752,15 +752,46 @@ UString UHttpClient_Base::wrapRequest(UString* req, const UString& host_port, ui
|
||||||
U_RETURN_STRING(tmp);
|
U_RETURN_STRING(tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
void UHttpClient_Base::composeRequest()
|
void UHttpClient_Base::composeRequest(const char* content_type)
|
||||||
{
|
{
|
||||||
U_TRACE(0, "UHttpClient_Base::composeRequest()")
|
U_TRACE(0, "UHttpClient_Base::composeRequest(%S)", content_type)
|
||||||
|
|
||||||
U_INTERNAL_ASSERT(UClient_Base::uri)
|
U_INTERNAL_ASSERT(UClient_Base::uri)
|
||||||
|
|
||||||
last_request = wrapRequest(0, UClient_Base::host_port, method_num, U_STRING_TO_PARAM(UClient_Base::uri), "\r\n");
|
U_INTERNAL_DUMP("method_num = %u", method_num)
|
||||||
|
|
||||||
parseRequest();
|
if (method_num == 0) // GET
|
||||||
|
{
|
||||||
|
last_request = wrapRequest(0, UClient_Base::host_port, method_num, U_STRING_TO_PARAM(UClient_Base::uri), "\r\n");
|
||||||
|
|
||||||
|
parseRequest(3);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
U_INTERNAL_ASSERT_EQUALS(method_num, 2) // POST
|
||||||
|
|
||||||
|
uint32_t sz = body.size();
|
||||||
|
|
||||||
|
U_INTERNAL_ASSERT_MAJOR(sz, 0)
|
||||||
|
|
||||||
|
UClient_Base::iov[3].iov_base = (caddr_t)body.data();
|
||||||
|
UClient_Base::iov[3].iov_len = sz;
|
||||||
|
|
||||||
|
(void) last_request.reserve(UClient_Base::uri.size() + UClient_Base::server.size() + 300U);
|
||||||
|
|
||||||
|
last_request.snprintf("POST %.*s HTTP/1.1\r\n"
|
||||||
|
"Host: %.*s:%u\r\n"
|
||||||
|
"User-Agent: ULib/1.0\r\n"
|
||||||
|
"Content-Length: %d\r\n"
|
||||||
|
"Content-Type: %s\r\n"
|
||||||
|
"\r\n",
|
||||||
|
U_STRING_TO_TRACE(UClient_Base::uri),
|
||||||
|
U_STRING_TO_TRACE(UClient_Base::server), UClient_Base::port,
|
||||||
|
sz,
|
||||||
|
content_type);
|
||||||
|
|
||||||
|
parseRequest(4);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool UHttpClient_Base::sendRequestEngine()
|
bool UHttpClient_Base::sendRequestEngine()
|
||||||
|
@ -906,34 +937,13 @@ bool UHttpClient_Base::sendPost(const UString& _url, const UString& _body, const
|
||||||
U_RETURN(false);
|
U_RETURN(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t sz = _body.size();
|
body = _body;
|
||||||
|
method_num = 2; // POST
|
||||||
|
|
||||||
UClient_Base::iov[3].iov_base = (caddr_t)_body.data();
|
composeRequest(content_type);
|
||||||
UClient_Base::iov[3].iov_len = sz;
|
|
||||||
|
|
||||||
U_INTERNAL_ASSERT(UClient_Base::uri)
|
|
||||||
|
|
||||||
(void) last_request.reserve(UClient_Base::uri.size() + UClient_Base::server.size() + 300U);
|
|
||||||
|
|
||||||
last_request.snprintf("POST %.*s HTTP/1.1\r\n"
|
|
||||||
"Host: %.*s:%u\r\n"
|
|
||||||
"User-Agent: ULib/1.0\r\n"
|
|
||||||
"Content-Length: %d\r\n"
|
|
||||||
"Content-Type: %s\r\n"
|
|
||||||
"\r\n",
|
|
||||||
U_STRING_TO_TRACE(UClient_Base::uri),
|
|
||||||
U_STRING_TO_TRACE(UClient_Base::server), UClient_Base::port,
|
|
||||||
sz,
|
|
||||||
content_type);
|
|
||||||
|
|
||||||
parseRequest();
|
|
||||||
|
|
||||||
UClient_Base::iovcnt = 4;
|
|
||||||
|
|
||||||
// send post request to server and get response
|
// send post request to server and get response
|
||||||
|
|
||||||
method_num = 2; // POST
|
|
||||||
|
|
||||||
if (sendRequest()) U_RETURN(true);
|
if (sendRequest()) U_RETURN(true);
|
||||||
|
|
||||||
U_RETURN(false);
|
U_RETURN(false);
|
||||||
|
@ -950,6 +960,8 @@ bool UHttpClient_Base::upload(const UString& _url, UFile& file, const char* file
|
||||||
U_RETURN(false);
|
U_RETURN(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
method_num = 2; // POST
|
||||||
|
|
||||||
UString content = file.getContent();
|
UString content = file.getContent();
|
||||||
|
|
||||||
if (content.empty()) U_RETURN(false);
|
if (content.empty()) U_RETURN(false);
|
||||||
|
@ -998,14 +1010,10 @@ bool UHttpClient_Base::upload(const UString& _url, UFile& file, const char* file
|
||||||
U_STRING_TO_TRACE(UClient_Base::server), UClient_Base::port,
|
U_STRING_TO_TRACE(UClient_Base::server), UClient_Base::port,
|
||||||
_body.size() + sz + UClient_Base::iov[5].iov_len);
|
_body.size() + sz + UClient_Base::iov[5].iov_len);
|
||||||
|
|
||||||
parseRequest();
|
parseRequest(6);
|
||||||
|
|
||||||
UClient_Base::iovcnt = 6;
|
|
||||||
|
|
||||||
// send upload request to server and get response
|
// send upload request to server and get response
|
||||||
|
|
||||||
method_num = 2; // POST
|
|
||||||
|
|
||||||
if (sendRequest()) U_RETURN(true);
|
if (sendRequest()) U_RETURN(true);
|
||||||
|
|
||||||
U_RETURN(false);
|
U_RETURN(false);
|
||||||
|
|
|
@ -11,8 +11,7 @@
|
||||||
//
|
//
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
|
||||||
#include <ulib/net/rpc/rpc.h>
|
#include <ulib/net/rpc/rpc_client.h>
|
||||||
#include <ulib/net/server/client_image.h>
|
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------------------------------------------------
|
||||||
// Very simple RPC-like layer
|
// Very simple RPC-like layer
|
||||||
|
|
|
@ -953,6 +953,8 @@ start:
|
||||||
if (U_ClientImage_state == U_PLUGIN_HANDLER_AGAIN &&
|
if (U_ClientImage_state == U_PLUGIN_HANDLER_AGAIN &&
|
||||||
U_ClientImage_parallelization != 1) // 1 => child of parallelization
|
U_ClientImage_parallelization != 1) // 1 => child of parallelization
|
||||||
{
|
{
|
||||||
|
U_INTERNAL_ASSERT(socket->isOpen())
|
||||||
|
|
||||||
U_RETURN(U_NOTIFIER_OK); // NOT BLOCKING...
|
U_RETURN(U_NOTIFIER_OK); // NOT BLOCKING...
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1011,6 +1013,9 @@ dmiss:
|
||||||
// TODO
|
// TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
|
U_INTERNAL_ASSERT(socket->isOpen())
|
||||||
|
U_INTERNAL_ASSERT_DIFFERS(U_ClientImage_parallelization, 1) // 1 => child of parallelization
|
||||||
|
|
||||||
U_RETURN(U_NOTIFIER_OK);
|
U_RETURN(U_NOTIFIER_OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1076,7 +1081,21 @@ dmiss:
|
||||||
|
|
||||||
U_INTERNAL_ASSERT(socket->isOpen())
|
U_INTERNAL_ASSERT(socket->isOpen())
|
||||||
|
|
||||||
if (U_ClientImage_data_missing) goto dmiss;
|
if (U_ClientImage_data_missing)
|
||||||
|
{
|
||||||
|
if (U_ClientImage_parallelization == 1)
|
||||||
|
{
|
||||||
|
if (UNotifier::waitForRead(socket->iSockDesc, U_TIMEOUT_MS) != 1 ||
|
||||||
|
USocketExt::read(socket, *rbuffer, U_SINGLE_READ, 0) == false)
|
||||||
|
{
|
||||||
|
goto death;
|
||||||
|
}
|
||||||
|
|
||||||
|
goto loop;
|
||||||
|
}
|
||||||
|
|
||||||
|
goto dmiss;
|
||||||
|
}
|
||||||
|
|
||||||
if (LIKELY(size_request))
|
if (LIKELY(size_request))
|
||||||
{
|
{
|
||||||
|
@ -1293,22 +1312,27 @@ error:
|
||||||
|
|
||||||
if (U_ClientImage_close)
|
if (U_ClientImage_close)
|
||||||
{
|
{
|
||||||
end: if (U_ClientImage_parallelization == 1) UServer_Base::endNewChild(); // 1 => child of parallelization
|
end: if (U_ClientImage_parallelization == 1) goto death; // 1 => child of parallelization
|
||||||
|
|
||||||
U_RETURN(U_NOTIFIER_DELETE);
|
U_RETURN(U_NOTIFIER_DELETE);
|
||||||
}
|
}
|
||||||
|
|
||||||
// NB: maybe we have some more request to services on the same connection...
|
// NB: maybe we have some more request to services on the same connection...
|
||||||
|
|
||||||
if (U_ClientImage_parallelization == 1 &&
|
if (U_ClientImage_parallelization == 1)
|
||||||
UNotifier::waitForRead(socket->iSockDesc, U_TIMEOUT_MS) == 1)
|
|
||||||
{
|
{
|
||||||
goto start;
|
U_INTERNAL_ASSERT_EQUALS(count, 0) // NB: we must not have pending write...
|
||||||
|
U_INTERNAL_ASSERT_DIFFERS(socket->iSockDesc, -1)
|
||||||
|
|
||||||
|
if (UNotifier::waitForRead(socket->iSockDesc, U_TIMEOUT_MS) == 1) goto start;
|
||||||
|
death:
|
||||||
|
UServer_Base::endNewChild(); // no return;
|
||||||
}
|
}
|
||||||
|
|
||||||
last_event = u_now->tv_sec;
|
last_event = u_now->tv_sec;
|
||||||
|
|
||||||
U_INTERNAL_ASSERT(socket->isOpen())
|
U_INTERNAL_ASSERT(socket->isOpen())
|
||||||
|
U_INTERNAL_ASSERT_DIFFERS(U_ClientImage_parallelization, 1) // 1 => child of parallelization
|
||||||
|
|
||||||
U_RETURN(U_NOTIFIER_OK);
|
U_RETURN(U_NOTIFIER_OK);
|
||||||
}
|
}
|
||||||
|
@ -1317,13 +1341,16 @@ bool UClientImage_Base::writeResponse()
|
||||||
{
|
{
|
||||||
U_TRACE(0, "UClientImage_Base::writeResponse()")
|
U_TRACE(0, "UClientImage_Base::writeResponse()")
|
||||||
|
|
||||||
|
U_INTERNAL_DUMP("U_ClientImage_pipeline = %b U_ClientImage_close = %b nrequest = %u", U_ClientImage_pipeline, U_ClientImage_close, nrequest)
|
||||||
|
|
||||||
U_INTERNAL_ASSERT(*wbuffer)
|
U_INTERNAL_ASSERT(*wbuffer)
|
||||||
U_INTERNAL_ASSERT(socket->isOpen())
|
U_INTERNAL_ASSERT(socket->isOpen())
|
||||||
U_INTERNAL_ASSERT_DIFFERS(U_ClientImage_parallelization, 2) // 2 => parent of parallelization
|
U_INTERNAL_ASSERT_DIFFERS(U_ClientImage_parallelization, 2) // 2 => parent of parallelization
|
||||||
|
|
||||||
int iBytesWrite;
|
int iBytesWrite;
|
||||||
uint32_t sz1 = wbuffer->size(),
|
uint32_t sz1 = wbuffer->size(),
|
||||||
sz2 = (U_http_method_type == HTTP_HEAD ? 0 : body->size());
|
sz2 = (U_http_method_type == HTTP_HEAD ? 0 : body->size()),
|
||||||
|
msg_len = (U_ClientImage_pipeline ? U_CONSTANT_SIZE("[pipeline] ") : 0);
|
||||||
|
|
||||||
iov_vec[2].iov_len = sz1;
|
iov_vec[2].iov_len = sz1;
|
||||||
iov_vec[2].iov_base = (caddr_t) wbuffer->data();
|
iov_vec[2].iov_base = (caddr_t) wbuffer->data();
|
||||||
|
@ -1332,8 +1359,6 @@ bool UClientImage_Base::writeResponse()
|
||||||
|
|
||||||
ncount = sz1 + sz2;
|
ncount = sz1 + sz2;
|
||||||
|
|
||||||
U_INTERNAL_DUMP("U_ClientImage_pipeline = %b U_ClientImage_close = %b nrequest = %u", U_ClientImage_pipeline, U_ClientImage_close, nrequest)
|
|
||||||
|
|
||||||
if (LIKELY(response_len)) // HTTP/1.1 200 OK\r\n
|
if (LIKELY(response_len)) // HTTP/1.1 200 OK\r\n
|
||||||
{
|
{
|
||||||
ncount += (iov_vec[0].iov_len = response_len) +
|
ncount += (iov_vec[0].iov_len = response_len) +
|
||||||
|
@ -1361,22 +1386,44 @@ bool UClientImage_Base::writeResponse()
|
||||||
if (LIKELY(iBytesWrite == (int)ncount))
|
if (LIKELY(iBytesWrite == (int)ncount))
|
||||||
{
|
{
|
||||||
# ifdef U_LOG_ENABLE
|
# ifdef U_LOG_ENABLE
|
||||||
if (logbuf)
|
if (logbuf) ULog::log(iov_vec, UServer_Base::mod_name[0], "response", ncount, "[pipeline] ", msg_len, " to %.*s", U_STRING_TO_TRACE(*logbuf));
|
||||||
{
|
|
||||||
ULog::log(iov_vec, UServer_Base::mod_name[0], "response", ncount,
|
|
||||||
(U_ClientImage_pipeline ? "[pipeline] " : ""), " to %.*s", U_STRING_TO_TRACE(*logbuf));
|
|
||||||
}
|
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
U_RETURN(true);
|
U_RETURN(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
loop:
|
||||||
if (iBytesWrite > 0)
|
if (iBytesWrite > 0)
|
||||||
{
|
{
|
||||||
U_SRV_LOG_WITH_ADDR("sent partial response (%u bytes of %u: sock_fd %d)%.*s to",
|
U_SRV_LOG_WITH_ADDR("sent partial response (%u bytes of %u: sock_fd %d)%.*s to", iBytesWrite, ncount, socket->iSockDesc, msg_len, " [pipeline]");
|
||||||
iBytesWrite, ncount, socket->iSockDesc, (U_ClientImage_pipeline ? U_CONSTANT_SIZE(" [pipeline]") : 0), " [pipeline]");
|
|
||||||
|
|
||||||
ncount -= iBytesWrite;
|
ncount -= iBytesWrite;
|
||||||
|
|
||||||
|
if (U_ClientImage_parallelization != 1 && // 1 => child of parallelization
|
||||||
|
UServer_Base::startParallelization())
|
||||||
|
{
|
||||||
|
// parent
|
||||||
|
|
||||||
|
U_ClientImage_state = U_PLUGIN_HANDLER_ERROR;
|
||||||
|
|
||||||
|
U_RETURN(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (U_ClientImage_parallelization == 1) // 1 => child of parallelization
|
||||||
|
{
|
||||||
|
if (UNotifier::waitForWrite(socket->iSockDesc, U_TIMEOUT_MS) != 1) U_RETURN(false);
|
||||||
|
|
||||||
|
iBytesWrite = USocketExt::writev(socket, iov_vec, 4, ncount, UServer_Base::timeoutMS);
|
||||||
|
|
||||||
|
if (LIKELY(iBytesWrite == (int)ncount))
|
||||||
|
{
|
||||||
|
U_SRV_LOG_WITH_ADDR("sending partial response completed (%u bytes of %u: sock_fd %d)%.*s to", iBytesWrite, ncount, socket->iSockDesc, msg_len, " [pipeline]");
|
||||||
|
|
||||||
|
U_RETURN(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
goto loop;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
U_RETURN(false);
|
U_RETURN(false);
|
||||||
|
@ -1388,7 +1435,8 @@ int UClientImage_Base::handlerResponse()
|
||||||
|
|
||||||
if (writeResponse()) U_RETURN(U_NOTIFIER_OK);
|
if (writeResponse()) U_RETURN(U_NOTIFIER_OK);
|
||||||
|
|
||||||
if (socket->isOpen())
|
if (socket->isOpen() &&
|
||||||
|
U_ClientImage_parallelization == 0) // 1/2 => child/parent of parallelization
|
||||||
{
|
{
|
||||||
# ifndef U_CLIENT_RESPONSE_PARTIAL_WRITE_SUPPORT
|
# ifndef U_CLIENT_RESPONSE_PARTIAL_WRITE_SUPPORT
|
||||||
resetPipelineAndClose();
|
resetPipelineAndClose();
|
||||||
|
|
|
@ -471,7 +471,7 @@ int UFCGIPlugIn::handlerRequest()
|
||||||
U_INTERNAL_DUMP("pos = %u response.size() = %u", pos, connection->response.size())
|
U_INTERNAL_DUMP("pos = %u response.size() = %u", pos, connection->response.size())
|
||||||
|
|
||||||
if ((connection->response.size() - pos) < FCGI_HEADER_LEN &&
|
if ((connection->response.size() - pos) < FCGI_HEADER_LEN &&
|
||||||
connection->readResponse() == false)
|
connection->readResponse(U_SINGLE_READ) == false)
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,11 +70,11 @@ UIptAccount* UNoCatPlugIn::ipt;
|
||||||
UModNoCatPeer* UNoCatPlugIn::peer;
|
UModNoCatPeer* UNoCatPlugIn::peer;
|
||||||
UModNoCatPeer* UNoCatPlugIn::peers_preallocate;
|
UModNoCatPeer* UNoCatPlugIn::peers_preallocate;
|
||||||
UVector<Url*>* UNoCatPlugIn::vauth_url;
|
UVector<Url*>* UNoCatPlugIn::vauth_url;
|
||||||
UVector<Url*>* UNoCatPlugIn::vinfo_url;
|
|
||||||
UVector<UString>* UNoCatPlugIn::openlist;
|
|
||||||
UVector<UString>* UNoCatPlugIn::vauth;
|
UVector<UString>* UNoCatPlugIn::vauth;
|
||||||
UVector<UString>* UNoCatPlugIn::vauth_ip;
|
UVector<UString>* UNoCatPlugIn::vauth_ip;
|
||||||
|
UVector<UString>* UNoCatPlugIn::openlist;
|
||||||
UVector<UString>* UNoCatPlugIn::varp_cache;
|
UVector<UString>* UNoCatPlugIn::varp_cache;
|
||||||
|
UVector<UString>* UNoCatPlugIn::vinfo_data;
|
||||||
UVector<UString>* UNoCatPlugIn::vLoginValidate;
|
UVector<UString>* UNoCatPlugIn::vLoginValidate;
|
||||||
UVector<UString>* UNoCatPlugIn::vInternalDevice;
|
UVector<UString>* UNoCatPlugIn::vInternalDevice;
|
||||||
UVector<UString>* UNoCatPlugIn::vLocalNetworkLabel;
|
UVector<UString>* UNoCatPlugIn::vLocalNetworkLabel;
|
||||||
|
@ -88,51 +88,51 @@ const UString* UNoCatPlugIn::str_allowed_members_default;
|
||||||
//const UString* UNoCatPlugIn::str_IPHONE_SUCCESS;
|
//const UString* UNoCatPlugIn::str_IPHONE_SUCCESS;
|
||||||
|
|
||||||
#define U_NOCAT_STATUS \
|
#define U_NOCAT_STATUS \
|
||||||
"<html>\n" \
|
"<html>\n" \
|
||||||
"<head>\n" \
|
"<head>\n" \
|
||||||
"<meta http-equiv=\"Cache Control\" content=\"max-age=0\">\n" \
|
"<meta http-equiv=\"Cache Control\" content=\"max-age=0\">\n" \
|
||||||
"<title>Access Point: %s</title>" \
|
"<title>Access Point: %s</title>" \
|
||||||
"</head>\n" \
|
"</head>\n" \
|
||||||
"<body bgcolor=\"#FFFFFF\" text=\"#000000\">\n" \
|
"<body bgcolor=\"#FFFFFF\" text=\"#000000\">\n" \
|
||||||
"<h1>Access Point: %s</h1>\n" \
|
"<h1>Access Point: %s</h1>\n" \
|
||||||
"<hr noshade=\"1\"/>\n" \
|
|
||||||
"<table border=\"0\" cellpadding=\"5\" cellspacing=\"0\">\n" \
|
|
||||||
"<tr><td>Current Time</td><td>%5D</td></tr>\n" \
|
|
||||||
"<tr><td>Gateway Up Since</td><td>%#5D</td></tr>\n" \
|
|
||||||
"<tr><td>GatewayVersion</td><td>" ULIB_VERSION "</td></tr>\n" \
|
|
||||||
"<tr><td>ExternalDevice</td><td>%.*s</td></tr>\n" \
|
|
||||||
"<tr><td>InternalDevice</td><td>%.*s</td></tr>\n" \
|
|
||||||
"<tr><td>LocalNetwork</td><td>%.*s</td></tr>\n" \
|
|
||||||
"<tr><td>GatewayPort</td><td>%u</td></tr>\n" \
|
|
||||||
"<tr><td>AuthServiceAddr</td><td>%.*s</td></tr>\n" \
|
|
||||||
"%s" \
|
|
||||||
"</table>\n" \
|
|
||||||
"<hr noshade=\"1\"/>\n" \
|
"<hr noshade=\"1\"/>\n" \
|
||||||
"<table border=\"0\" cellpadding=\"5\" cellspacing=\"0\">\n" \
|
"<table border=\"0\" cellpadding=\"5\" cellspacing=\"0\">\n" \
|
||||||
"<tr><td>Users</td><td>%u</td></tr>\n" \
|
"<tr><td>Current Time</td><td>%5D</td></tr>\n" \
|
||||||
"<tr><td>Users Connected</td><td>%u</td></tr>\n" \
|
"<tr><td>Gateway Up Since</td><td>%#5D</td></tr>\n" \
|
||||||
"<tr><td></td><td></td></tr>\n" \
|
"<tr><td>GatewayVersion</td><td>" ULIB_VERSION "</td></tr>\n" \
|
||||||
"<tr><td align=\"center\"><h2>Current Users</h2></td>\n" \
|
"<tr><td>ExternalDevice</td><td>%.*s</td></tr>\n" \
|
||||||
"<table border=\"1\" cellpadding=\"5\">\n" \
|
"<tr><td>InternalDevice</td><td>%.*s</td></tr>\n" \
|
||||||
"<tr><th>User UID</th>\n" \
|
"<tr><td>LocalNetwork</td><td>%.*s</td></tr>\n" \
|
||||||
"<th>IP address</th>\n" \
|
"<tr><td>GatewayPort</td><td>%u</td></tr>\n" \
|
||||||
"<th>Connection time</th>\n" \
|
"<tr><td>AuthServiceAddr</td><td>%.*s</td></tr>\n" \
|
||||||
"<th>Elapsed connection time</th>\n" \
|
"%s" \
|
||||||
"<th>Left connection time</th>\n" \
|
"</table>\n" \
|
||||||
"<th>Consumed traffic</th>\n" \
|
"<hr noshade=\"1\"/>\n" \
|
||||||
"<th>Left traffic</th>\n" \
|
"<table border=\"0\" cellpadding=\"5\" cellspacing=\"0\">\n" \
|
||||||
"<th>MAC address</th>\n" \
|
"<tr><td>Users</td><td>%u</td></tr>\n" \
|
||||||
"<th>Status</th></tr>\n" \
|
"<tr><td>Users Connected</td><td>%u</td></tr>\n" \
|
||||||
"%.*s" \
|
"<tr><td></td><td></td></tr>\n" \
|
||||||
"</table></td></tr>\n" \
|
"<tr><td align=\"center\"><h2>Current Users</h2></td>\n" \
|
||||||
"</table>\n" \
|
"<table border=\"1\" cellpadding=\"5\">\n" \
|
||||||
"<hr noshade=\"1\"/>\n" \
|
"<tr><th>User UID</th>\n" \
|
||||||
"<img src=%s width=\"112\" height=\"35\">\n" \
|
"<th>IP address</th>\n" \
|
||||||
"<p style=\"text-align:right\">Powered by ULib</p>\n" \
|
"<th>Connection time</th>\n" \
|
||||||
"</body>\n" \
|
"<th>Elapsed connection time</th>\n" \
|
||||||
"</html>"
|
"<th>Left connection time</th>\n" \
|
||||||
|
"<th>Consumed traffic</th>\n" \
|
||||||
|
"<th>Left traffic</th>\n" \
|
||||||
|
"<th>MAC address</th>\n" \
|
||||||
|
"<th>Status</th></tr>\n" \
|
||||||
|
"%.*s" \
|
||||||
|
"</table></td></tr>\n" \
|
||||||
|
"</table>\n" \
|
||||||
|
"<hr noshade=\"1\"/>\n" \
|
||||||
|
"<img src=%s width=\"112\" height=\"35\">\n" \
|
||||||
|
"<p style=\"text-align:right\">Powered by ULib</p>\n" \
|
||||||
|
"</body>\n" \
|
||||||
|
"</html>"
|
||||||
|
|
||||||
// define method VIRTUAL of class UEventTime
|
// define method VIRTUAL of class UEventTime
|
||||||
|
|
||||||
int UModNoCatPeer::handlerTime()
|
int UModNoCatPeer::handlerTime()
|
||||||
{
|
{
|
||||||
|
@ -213,8 +213,8 @@ UNoCatPlugIn::UNoCatPlugIn()
|
||||||
vauth = U_NEW(UVector<UString>(4U));
|
vauth = U_NEW(UVector<UString>(4U));
|
||||||
vauth_ip = U_NEW(UVector<UString>(4U));
|
vauth_ip = U_NEW(UVector<UString>(4U));
|
||||||
vauth_url = U_NEW(UVector<Url*>(4U));
|
vauth_url = U_NEW(UVector<Url*>(4U));
|
||||||
vinfo_url = U_NEW(UVector<Url*>(4U));
|
|
||||||
varp_cache = U_NEW(UVector<UString>);
|
varp_cache = U_NEW(UVector<UString>);
|
||||||
|
vinfo_data = U_NEW(UVector<UString>(4U));
|
||||||
vLoginValidate = U_NEW(UVector<UString>);
|
vLoginValidate = U_NEW(UVector<UString>);
|
||||||
vInternalDevice = U_NEW(UVector<UString>(64U));
|
vInternalDevice = U_NEW(UVector<UString>(64U));
|
||||||
vLocalNetworkMask = U_NEW(UVector<UIPAllow*>);
|
vLocalNetworkMask = U_NEW(UVector<UIPAllow*>);
|
||||||
|
@ -260,7 +260,7 @@ UNoCatPlugIn::~UNoCatPlugIn()
|
||||||
delete vauth;
|
delete vauth;
|
||||||
delete vauth_ip;
|
delete vauth_ip;
|
||||||
delete vauth_url;
|
delete vauth_url;
|
||||||
delete vinfo_url;
|
delete vinfo_data;
|
||||||
delete vLoginValidate;
|
delete vLoginValidate;
|
||||||
delete vInternalDevice;
|
delete vInternalDevice;
|
||||||
delete vLocalNetworkMask;
|
delete vLocalNetworkMask;
|
||||||
|
@ -524,7 +524,7 @@ UString UNoCatPlugIn::getUrlForSendMsgToPortal(uint32_t index_AUTH, const char*
|
||||||
{
|
{
|
||||||
U_TRACE(0, "UNoCatPlugIn::getUrlForSendMsgToPortal(%u,%.*S,%u)", index_AUTH, msg_len, msg, msg_len)
|
U_TRACE(0, "UNoCatPlugIn::getUrlForSendMsgToPortal(%u,%.*S,%u)", index_AUTH, msg_len, msg, msg_len)
|
||||||
|
|
||||||
Url* auth = (*vinfo_url)[index_AUTH];
|
Url* auth = (*vauth_url)[index_AUTH];
|
||||||
UString auth_host = auth->getHost(),
|
UString auth_host = auth->getHost(),
|
||||||
auth_service = auth->getService(),
|
auth_service = auth->getService(),
|
||||||
url(200U + auth_host.size() + auth_service.size() + msg_len);
|
url(200U + auth_host.size() + auth_service.size() + msg_len);
|
||||||
|
@ -565,45 +565,17 @@ void UNoCatPlugIn::uploadFileToPortal(UFile& file)
|
||||||
if (result) (void) file._unlink();
|
if (result) (void) file._unlink();
|
||||||
}
|
}
|
||||||
|
|
||||||
void UNoCatPlugIn::sendMsgToPortal(uint32_t index_AUTH, const UString& msg, UString* poutput, bool basync)
|
void UNoCatPlugIn::sendMsgToPortal(uint32_t index_AUTH, const UString& msg, UString* poutput)
|
||||||
{
|
{
|
||||||
U_TRACE(0, "UNoCatPlugIn::sendMsgToPortal(%u,%.*S,%p,%b)", index_AUTH, U_STRING_TO_TRACE(msg), poutput, basync)
|
U_TRACE(0, "UNoCatPlugIn::sendMsgToPortal(%u,%.*S,%p)", index_AUTH, U_STRING_TO_TRACE(msg), poutput)
|
||||||
|
|
||||||
UString url = getUrlForSendMsgToPortal(index_AUTH, U_STRING_TO_PARAM(msg));
|
|
||||||
|
|
||||||
if (basync)
|
|
||||||
{
|
|
||||||
U_INTERNAL_ASSERT_EQUALS(poutput, 0)
|
|
||||||
U_INTERNAL_ASSERT_EQUALS(UClient_Base::queue_dir, 0)
|
|
||||||
|
|
||||||
# ifdef U_LOG_ENABLE
|
|
||||||
if (UServer_Base::isLog())
|
|
||||||
{
|
|
||||||
char log_msg[4096];
|
|
||||||
uint32_t sz = msg.size();
|
|
||||||
|
|
||||||
// NB: we need this because we have a message with many url encoded char...
|
|
||||||
|
|
||||||
UString str = UStringExt::substitute(msg.data(), U_min(sz,200), '%', U_CONSTANT_TO_PARAM("%%"));
|
|
||||||
|
|
||||||
(void) u__snprintf(log_msg, sizeof(log_msg),
|
|
||||||
"[nocat] Sent info %%s (%u bytes) after %%d attempts to AUTH(%u): %.*S",
|
|
||||||
sz, index_AUTH, U_STRING_TO_TRACE(str));
|
|
||||||
|
|
||||||
(void) client->sendRequestAsync(url, false, log_msg);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
# endif
|
|
||||||
(void) client->sendRequestAsync(url);
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef U_LOG_ENABLE
|
#ifdef U_LOG_ENABLE
|
||||||
const char* result = "FAILED";
|
const char* result = "FAILED";
|
||||||
#endif
|
#endif
|
||||||
bool bqueue = false, we_need_response = (poutput != 0);
|
bool bqueue = false, we_need_response = (poutput != 0);
|
||||||
|
|
||||||
|
UString url = getUrlForSendMsgToPortal(index_AUTH, U_STRING_TO_PARAM(msg));
|
||||||
|
|
||||||
loop:
|
loop:
|
||||||
if (we_need_response == false) UClient_Base::queue_dir = UString::str_CLIENT_QUEUE_DIR;
|
if (we_need_response == false) UClient_Base::queue_dir = UString::str_CLIENT_QUEUE_DIR;
|
||||||
|
|
||||||
|
@ -884,7 +856,7 @@ bool UNoCatPlugIn::checkFirewall()
|
||||||
msg.snprintf("/error_ap?ap=%.*s@%.*s&public=%.*s:%u",
|
msg.snprintf("/error_ap?ap=%.*s@%.*s&public=%.*s:%u",
|
||||||
U_STRING_TO_TRACE(*label), U_STRING_TO_TRACE(*hostname), U_STRING_TO_TRACE(*UServer_Base::IP_address), UServer_Base::port);
|
U_STRING_TO_TRACE(*label), U_STRING_TO_TRACE(*hostname), U_STRING_TO_TRACE(*UServer_Base::IP_address), UServer_Base::port);
|
||||||
|
|
||||||
sendMsgToPortal(msg);
|
sendMsgToAllPortal(msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -899,8 +871,6 @@ void UNoCatPlugIn::checkSystem()
|
||||||
{
|
{
|
||||||
U_TRACE(1, "UNoCatPlugIn::checkSystem()")
|
U_TRACE(1, "UNoCatPlugIn::checkSystem()")
|
||||||
|
|
||||||
UString info;
|
|
||||||
Url* info_url;
|
|
||||||
uint32_t i, n;
|
uint32_t i, n;
|
||||||
long check_interval;
|
long check_interval;
|
||||||
|
|
||||||
|
@ -1003,28 +973,7 @@ result:
|
||||||
paddrmask = 0;
|
paddrmask = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0, n = vinfo_url->size(); i < n; ++i)
|
for (i = 0, n = vauth_url->size(); i < n; ++i) sendInfoData(i);
|
||||||
{
|
|
||||||
info_url = (*vinfo_url)[i];
|
|
||||||
|
|
||||||
if (info_url->isQuery())
|
|
||||||
{
|
|
||||||
info = info_url->getPathAndQuery();
|
|
||||||
|
|
||||||
U_INTERNAL_ASSERT(info)
|
|
||||||
|
|
||||||
// NB: we can't try to send immediately the info data on users to portal because the worst we have a hole
|
|
||||||
// of 10 seconds and the portal can have need to ask us something (to logout some user, the list of peer permitted, ...)
|
|
||||||
|
|
||||||
sendMsgToPortal(i, info, 0, true);
|
|
||||||
|
|
||||||
# ifdef DEBUG
|
|
||||||
info.clear(); // NB: to avoid DEAD OF SOURCE STRING WITH CHILD ALIVE...
|
|
||||||
# endif
|
|
||||||
|
|
||||||
*info_url = *((*vauth_url)[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// check if there are some log file to upload
|
// check if there are some log file to upload
|
||||||
|
|
||||||
|
@ -1269,12 +1218,14 @@ bool UNoCatPlugIn::checkAuthMessage(const UString& msg)
|
||||||
{
|
{
|
||||||
U_SRV_LOG("WARNING: tampered token from peer: IP %.*s MAC %.*s", U_STRING_TO_TRACE(peer->ip), U_STRING_TO_TRACE(peer->mac));
|
U_SRV_LOG("WARNING: tampered token from peer: IP %.*s MAC %.*s", U_STRING_TO_TRACE(peer->ip), U_STRING_TO_TRACE(peer->mac));
|
||||||
|
|
||||||
/* ---------------------------------------------------------------------------------------------------------------------
|
/**
|
||||||
// NB: tutto il traffico viene rediretto sulla 80 (CAPTIVE PORTAL) e quindi windows update, antivrus, etc...
|
* --------------------------------------------------------------------------------------------------------------------
|
||||||
// questo introduce la possibilita' che durante la fase di autorizzazione il token generato per il ticket autorizzativo
|
* NB: tutto il traffico viene rediretto sulla 80 (CAPTIVE PORTAL) e quindi windows update, antivrus, etc...
|
||||||
// non corrisponda piu' a quello inviato dal portale per l'autorizzazione...
|
* questo introduce la possibilita' che durante la fase di autorizzazione il token generato per il ticket autorizzativo
|
||||||
// ---------------------------------------------------------------------------------------------------------------------
|
* non corrisponda piu' a quello inviato dal portale per l'autorizzazione...
|
||||||
*/
|
* ---------------------------------------------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
peer->token.snprintf("%u", u_random(u_now->tv_usec));
|
peer->token.snprintf("%u", u_random(u_now->tv_usec));
|
||||||
|
|
||||||
goto end;
|
goto end;
|
||||||
|
@ -1561,12 +1512,14 @@ void UNoCatPlugIn::setNewPeer()
|
||||||
|
|
||||||
setFireWallCommand(peer->fw, *fw_cmd, peer->mac, peer->ip);
|
setFireWallCommand(peer->fw, *fw_cmd, peer->mac, peer->ip);
|
||||||
|
|
||||||
/* ---------------------------------------------------------------------------------------------------------------------
|
/**
|
||||||
// NB: tutto il traffico viene rediretto sulla 80 (CAPTIVE PORTAL) e quindi windows update, antivrus, etc...
|
* --------------------------------------------------------------------------------------------------------------------
|
||||||
// questo introduce la possibilita' che durante la fase di autorizzazione il token generato per il ticket autorizzativo
|
* NB: tutto il traffico viene rediretto sulla 80 (CAPTIVE PORTAL) e quindi windows update, antivrus, etc...
|
||||||
// non corrisponda piu' a quello inviato dal portale per l'autorizzazione...
|
* questo introduce la possibilita' che durante la fase di autorizzazione il token generato per il ticket autorizzativo
|
||||||
// ---------------------------------------------------------------------------------------------------------------------
|
* non corrisponda piu' a quello inviato dal portale per l'autorizzazione...
|
||||||
*/
|
* ---------------------------------------------------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
peer->token.snprintf("%u", u_random(u_now->tv_usec));
|
peer->token.snprintf("%u", u_random(u_now->tv_usec));
|
||||||
|
|
||||||
peers->insert(peer->ip, peer);
|
peers->insert(peer->ip, peer);
|
||||||
|
@ -1628,62 +1581,74 @@ void UNoCatPlugIn::addPeerInfo(time_t logout)
|
||||||
U_TRACE(0, "UNoCatPlugIn::addPeerInfo(%T)", logout)
|
U_TRACE(0, "UNoCatPlugIn::addPeerInfo(%T)", logout)
|
||||||
|
|
||||||
U_INTERNAL_ASSERT_POINTER(peer)
|
U_INTERNAL_ASSERT_POINTER(peer)
|
||||||
|
U_INTERNAL_ASSERT(peer->user)
|
||||||
|
U_INTERNAL_ASSERT(u_now->tv_sec >= peer->ctime)
|
||||||
|
|
||||||
|
char* ptr;
|
||||||
|
char buffer[64];
|
||||||
|
UString info = (*vinfo_data)[U_peer_index_AUTH];
|
||||||
|
uint32_t sz = info.size();
|
||||||
|
|
||||||
|
U_INTERNAL_DUMP("U_peer_index_AUTH = %u info = %.*S", U_peer_index_AUTH, U_STRING_TO_TRACE(info))
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------------------------------------------------------------------
|
||||||
// $1 -> mac
|
// $1 -> mac
|
||||||
// $2 -> ip
|
// $2 -> ip
|
||||||
// $3 -> gateway
|
// $3 -> gateway
|
||||||
// $4 -> ap
|
// $4 -> ap (with localization => '@')
|
||||||
// $5 -> uid
|
// $5 -> => UID <=
|
||||||
// $6 -> logout
|
// $6 -> logout
|
||||||
// $7 -> connected
|
// $7 -> connected
|
||||||
// $8 -> traffic
|
// $8 -> traffic
|
||||||
|
// -----------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
// /info?Mac=98%3A0c%3A82%3A76%3A3b%3A39&ip=172.16.1.8&gateway=172.16.1.254%3A5280&ap=ap%4010.8.0.1&User=1212&logout=1&connected=3&traffic=0
|
||||||
|
// -----------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
Url* info_url = (*vinfo_url)[U_peer_index_AUTH];
|
info.reserve(sz + 200);
|
||||||
|
|
||||||
info_url->setPath(U_CONSTANT_TO_PARAM("/info"));
|
info.snprintf_add("%sMac=%.*s&ip=%.*s&", (sz ? "&" : ""),
|
||||||
|
u_url_encode((const unsigned char*)U_STRING_TO_PARAM(peer->mac), (unsigned char*)buffer), buffer, U_STRING_TO_TRACE(peer->ip));
|
||||||
|
|
||||||
U_INTERNAL_DUMP("U_peer_index_AUTH = %u info_url = %p", U_peer_index_AUTH, info_url)
|
info.snprintf_add("gateway=%.*s&ap=%.*s%%40%.*s&User=",
|
||||||
|
u_url_encode((const unsigned char*)U_STRING_TO_PARAM(peer->gateway), (unsigned char*)buffer), buffer,
|
||||||
|
U_STRING_TO_TRACE(peer->label), U_STRING_TO_TRACE(*UServer_Base::IP_address));
|
||||||
|
|
||||||
U_INTERNAL_ASSERT(peer->user)
|
info.snprintf_add("%.*s&logout=", u_url_encode((const unsigned char*)U_STRING_TO_PARAM(peer->user), (unsigned char*)buffer), buffer);
|
||||||
|
|
||||||
UString buffer(U_CAPACITY);
|
ptr = (char*) info.end();
|
||||||
|
|
||||||
buffer.snprintf("%.*s@%.*s", U_STRING_TO_TRACE(peer->label), U_STRING_TO_TRACE(*UServer_Base::IP_address));
|
|
||||||
|
|
||||||
info_url->addQuery(U_CONSTANT_TO_PARAM("Mac"), U_STRING_TO_PARAM(peer->mac));
|
|
||||||
info_url->addQuery(U_CONSTANT_TO_PARAM("ip"), U_STRING_TO_PARAM(peer->ip));
|
|
||||||
info_url->addQuery(U_CONSTANT_TO_PARAM("gateway"), U_STRING_TO_PARAM(peer->gateway));
|
|
||||||
info_url->addQuery(U_CONSTANT_TO_PARAM("ap"), U_STRING_TO_PARAM(buffer));
|
|
||||||
info_url->addQuery(U_CONSTANT_TO_PARAM("User"), U_STRING_TO_PARAM(peer->user));
|
|
||||||
|
|
||||||
// NB: 0 => mean NOT logout (only info)
|
// NB: 0 => mean NOT logout (only info)
|
||||||
// -1 => disconnected (logout implicito)
|
// -1 => disconnected (logout implicito)
|
||||||
|
|
||||||
bool logout_implicito = (logout == -1);
|
if (logout == -1)
|
||||||
|
|
||||||
if (logout_implicito) logout = u_now->tv_sec;
|
|
||||||
|
|
||||||
buffer.setFromNumber32(logout);
|
|
||||||
|
|
||||||
if (logout_implicito) (void) buffer.insert(0, '-');
|
|
||||||
|
|
||||||
info_url->addQuery(U_CONSTANT_TO_PARAM("logout"), U_STRING_TO_PARAM(buffer));
|
|
||||||
|
|
||||||
U_INTERNAL_ASSERT(u_now->tv_sec >= peer->ctime)
|
|
||||||
|
|
||||||
buffer.setFromNumber32(u_now->tv_sec - peer->ctime);
|
|
||||||
peer->ctime = u_now->tv_sec;
|
|
||||||
|
|
||||||
info_url->addQuery(U_CONSTANT_TO_PARAM("connected"), U_STRING_TO_PARAM(buffer));
|
|
||||||
|
|
||||||
if (peer->ctraffic == 0) info_url->addQuery(U_CONSTANT_TO_PARAM("traffic"), U_CONSTANT_TO_PARAM("0"));
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
buffer.snprintf("%u", peer->ctraffic);
|
*ptr++ = '-';
|
||||||
peer->ctraffic = peer->time_no_traffic = 0;
|
logout = u_now->tv_sec;
|
||||||
|
|
||||||
info_url->addQuery(U_CONSTANT_TO_PARAM("traffic"), U_STRING_TO_PARAM(buffer));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ptr += u_num2str32(ptr, logout);
|
||||||
|
|
||||||
|
u__memcpy(ptr, "&connected=",
|
||||||
|
U_CONSTANT_SIZE("&connected="), __PRETTY_FUNCTION__);
|
||||||
|
ptr += U_CONSTANT_SIZE("&connected=");
|
||||||
|
|
||||||
|
ptr += u_num2str32(ptr, u_now->tv_sec - peer->ctime);
|
||||||
|
|
||||||
|
u__memcpy(ptr, "&traffic=",
|
||||||
|
U_CONSTANT_SIZE("&traffic="), __PRETTY_FUNCTION__);
|
||||||
|
ptr += U_CONSTANT_SIZE("&traffic=");
|
||||||
|
|
||||||
|
ptr += u_num2str32(ptr, peer->ctraffic);
|
||||||
|
|
||||||
|
info.size_adjust(ptr);
|
||||||
|
|
||||||
|
U_INTERNAL_DUMP("info(%u) = %.*S", info.size(), U_STRING_TO_TRACE(info))
|
||||||
|
|
||||||
|
vinfo_data->replace(U_peer_index_AUTH, info);
|
||||||
|
|
||||||
|
peer->ctime = u_now->tv_sec;
|
||||||
|
|
||||||
|
if (peer->ctraffic) peer->ctraffic = peer->time_no_traffic = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool UModNoCatPeer::checkPeerInfo(bool btraffic)
|
bool UModNoCatPeer::checkPeerInfo(bool btraffic)
|
||||||
|
@ -1856,36 +1821,60 @@ __pure bool UNoCatPlugIn::getPeer(uint32_t n)
|
||||||
U_RETURN(false);
|
U_RETURN(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UNoCatPlugIn::sendInfoData(uint32_t index_AUTH)
|
||||||
|
{
|
||||||
|
U_TRACE(0, "UNoCatPlugIn::sendInfoData(%u)", index_AUTH)
|
||||||
|
|
||||||
|
UString info = (*vinfo_data)[index_AUTH];
|
||||||
|
|
||||||
|
if (info)
|
||||||
|
{
|
||||||
|
U_INTERNAL_ASSERT_EQUALS(UClient_Base::queue_dir, 0)
|
||||||
|
|
||||||
|
// NB: we can't try to send immediately the info data on users to portal because the worst we have a hole
|
||||||
|
// of 10 seconds and the portal can have need to ask us something (to logout some user, the list of peer permitted, ...)
|
||||||
|
|
||||||
|
char buffer[4096];
|
||||||
|
const char* log_msg = 0;
|
||||||
|
uint32_t sz = info.size();
|
||||||
|
UString body = info, url = getUrlForSendMsgToPortal(index_AUTH, U_CONSTANT_TO_PARAM("/info"));
|
||||||
|
|
||||||
|
# ifdef USE_LIBZ
|
||||||
|
if (sz > U_MIN_SIZE_FOR_DEFLATE) body = UStringExt::deflate(info, 1);
|
||||||
|
# endif
|
||||||
|
|
||||||
|
# ifdef U_LOG_ENABLE
|
||||||
|
if (UServer_Base::isLog())
|
||||||
|
{
|
||||||
|
UString str = UStringExt::substitute(info.data(), U_min(sz,200), '%', U_CONSTANT_TO_PARAM("%%")); // NB: we need this because we have a message with url encoded char...
|
||||||
|
|
||||||
|
(void) u__snprintf(buffer, sizeof(buffer),
|
||||||
|
"[nocat] Sent info %%s (%u bytes) after %%d attempts to AUTH(%u): %.*S",
|
||||||
|
sz, index_AUTH, U_STRING_TO_TRACE(str));
|
||||||
|
|
||||||
|
log_msg = buffer;
|
||||||
|
}
|
||||||
|
# endif
|
||||||
|
|
||||||
|
(void) client->sendPOSTRequestAsync(body, url, true, log_msg);
|
||||||
|
|
||||||
|
vinfo_data->getStringRep(index_AUTH)->size_adjust(0U);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void UNoCatPlugIn::notifyAuthOfUsersInfo(uint32_t index_AUTH)
|
void UNoCatPlugIn::notifyAuthOfUsersInfo(uint32_t index_AUTH)
|
||||||
{
|
{
|
||||||
U_TRACE(0, "UNoCatPlugIn::notifyAuthOfUsersInfo(%u)", index_AUTH)
|
U_TRACE(0, "UNoCatPlugIn::notifyAuthOfUsersInfo(%u)", index_AUTH)
|
||||||
|
|
||||||
Url* info_url = (*vinfo_url)[index_AUTH];
|
sendInfoData(index_AUTH);
|
||||||
|
|
||||||
U_INTERNAL_DUMP("index_AUTH = %u info_url = %p", index_AUTH, info_url)
|
// NB: if there is arping pending AUTH must recall us after ~15sec for completion...
|
||||||
|
|
||||||
// NB: if there are some data to transmit we need redirect...
|
u_http_info.nResponseCode = (isPingAsyncPending() ? HTTP_NO_CONTENT : HTTP_NOT_MODIFIED);
|
||||||
|
|
||||||
if (info_url->isQuery())
|
UClientImage_Base::setCloseConnection();
|
||||||
{
|
|
||||||
// NB: we need to send a body for portal discrimination...
|
|
||||||
|
|
||||||
UHTTP::setRedirectResponse(0, UString::getStringNull(), U_URL_TO_PARAM(*info_url));
|
UHTTP::setResponse(0, 0);
|
||||||
|
|
||||||
// NB: we assume that the redirect always have success...
|
|
||||||
|
|
||||||
*info_url = *((*vauth_url)[index_AUTH]);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// NB: if there is arping pending AUTH must recall us after ~15sec for completion...
|
|
||||||
|
|
||||||
u_http_info.nResponseCode = (isPingAsyncPending() ? HTTP_NO_CONTENT : HTTP_NOT_MODIFIED);
|
|
||||||
|
|
||||||
UClientImage_Base::setCloseConnection();
|
|
||||||
|
|
||||||
UHTTP::setResponse(0, 0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void UNoCatPlugIn::setHTTPResponse(const UString& content)
|
void UNoCatPlugIn::setHTTPResponse(const UString& content)
|
||||||
|
@ -2152,13 +2141,13 @@ int UNoCatPlugIn::handlerInit()
|
||||||
|
|
||||||
Url* url;
|
Url* url;
|
||||||
UIPAddress addr;
|
UIPAddress addr;
|
||||||
UString auth_ip, ip;
|
UString auth_ip, ip, info(U_CAPACITY);
|
||||||
|
|
||||||
// NB: get IP address of AUTH hosts...
|
// NB: get IP address of AUTH hosts...
|
||||||
|
|
||||||
for (uint32_t i = 0, n = vauth->size(); i < n; ++i)
|
for (uint32_t i = 0, n = vauth->size(); i < n; ++i)
|
||||||
{
|
{
|
||||||
ip = (*vauth)[i];
|
ip = (*vauth)[i];
|
||||||
url = U_NEW(Url(ip));
|
url = U_NEW(Url(ip));
|
||||||
|
|
||||||
vauth_url->push(url);
|
vauth_url->push(url);
|
||||||
|
@ -2178,12 +2167,11 @@ int UNoCatPlugIn::handlerInit()
|
||||||
vauth_ip->push(auth_ip);
|
vauth_ip->push(auth_ip);
|
||||||
}
|
}
|
||||||
|
|
||||||
url = U_NEW(Url(ip));
|
vinfo_data->push(info);
|
||||||
|
|
||||||
vinfo_url->push(url);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
U_ASSERT_EQUALS(vauth->size(), vauth_ip->size())
|
U_ASSERT_EQUALS(vauth->size(), vauth_ip->size())
|
||||||
|
U_ASSERT_EQUALS(vauth->size(), vinfo_data->size())
|
||||||
|
|
||||||
*hostname = USocketExt::getNodeName();
|
*hostname = USocketExt::getNodeName();
|
||||||
|
|
||||||
|
@ -2278,7 +2266,7 @@ bool UNoCatPlugIn::preallocatePeersFault()
|
||||||
U_STRING_TO_TRACE(*label), U_STRING_TO_TRACE(*hostname),
|
U_STRING_TO_TRACE(*label), U_STRING_TO_TRACE(*hostname),
|
||||||
U_STRING_TO_TRACE(*UServer_Base::IP_address), UServer_Base::port, _vsz, _rss);
|
U_STRING_TO_TRACE(*UServer_Base::IP_address), UServer_Base::port, _vsz, _rss);
|
||||||
|
|
||||||
sendMsgToPortal(0, msg, 0, false);
|
sendMsgToPortal(0, msg, 0);
|
||||||
|
|
||||||
U_INTERNAL_ASSERT_EQUALS(peers_preallocate, 0)
|
U_INTERNAL_ASSERT_EQUALS(peers_preallocate, 0)
|
||||||
|
|
||||||
|
@ -2357,9 +2345,9 @@ int UNoCatPlugIn::handlerFork()
|
||||||
U_STRING_TO_TRACE(*label), U_STRING_TO_TRACE(*hostname),
|
U_STRING_TO_TRACE(*label), U_STRING_TO_TRACE(*hostname),
|
||||||
U_STRING_TO_TRACE(*UServer_Base::IP_address), UServer_Base::port, UServer_Base::pid);
|
U_STRING_TO_TRACE(*UServer_Base::IP_address), UServer_Base::port, UServer_Base::pid);
|
||||||
|
|
||||||
for (i = 0, n = (*vinfo_url).size(); i < n; ++i)
|
for (i = 0, n = vauth_url->size(); i < n; ++i)
|
||||||
{
|
{
|
||||||
sendMsgToPortal(i, msg, &output, false);
|
sendMsgToPortal(i, msg, &output);
|
||||||
|
|
||||||
(void) allowed_web_hosts.append(output);
|
(void) allowed_web_hosts.append(output);
|
||||||
}
|
}
|
||||||
|
@ -2606,10 +2594,7 @@ int UNoCatPlugIn::handlerRequest()
|
||||||
{
|
{
|
||||||
next: getARPCache();
|
next: getARPCache();
|
||||||
|
|
||||||
if (U_peer_status != UModNoCatPeer::PEER_PERMIT)
|
if (U_peer_status != UModNoCatPeer::PEER_PERMIT) setStatusContent(UString::getStringNull()); // NB: peer == 0 -> request from AUTH to get status access point...
|
||||||
{
|
|
||||||
setStatusContent(UString::getStringNull()); // NB: peer == 0 -> request from AUTH to get status access point...
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
(void) peer->checkPeerInfo(true);
|
(void) peer->checkPeerInfo(true);
|
||||||
|
@ -2931,7 +2916,6 @@ const char* UNoCatPlugIn::dump(bool _reset) const
|
||||||
<< "fw (UCommand " << (void*)fw << ")\n"
|
<< "fw (UCommand " << (void*)fw << ")\n"
|
||||||
<< "ipt (UIptAccount " << (void*)ipt << ")\n"
|
<< "ipt (UIptAccount " << (void*)ipt << ")\n"
|
||||||
<< "vauth_url (UVector<Url*> " << (void*)vauth_url << ")\n"
|
<< "vauth_url (UVector<Url*> " << (void*)vauth_url << ")\n"
|
||||||
<< "vinfo_url (UVector<Url*> " << (void*)vinfo_url << ")\n"
|
|
||||||
<< "vauth (UVector<UString> " << (void*)vauth << ")\n"
|
<< "vauth (UVector<UString> " << (void*)vauth << ")\n"
|
||||||
<< "vauth_ip (UVector<UString> " << (void*)vauth_ip << ")\n"
|
<< "vauth_ip (UVector<UString> " << (void*)vauth_ip << ")\n"
|
||||||
<< "vInternalDevice (UVector<UString> " << (void*)vInternalDevice << ")\n"
|
<< "vInternalDevice (UVector<UString> " << (void*)vInternalDevice << ")\n"
|
||||||
|
|
|
@ -145,10 +145,10 @@ int UProxyPlugIn::handlerRequest()
|
||||||
|
|
||||||
// --------------------------------------------------------------------------------------------------------------------
|
// --------------------------------------------------------------------------------------------------------------------
|
||||||
// A WebSocket is a long-lived connection, lasting hours or days. If each WebSocket proxy holds the original thread,
|
// A WebSocket is a long-lived connection, lasting hours or days. If each WebSocket proxy holds the original thread,
|
||||||
// won't that consume all of the workers very quickly ? It looks as if my server, with 16 workers, will be unable to
|
// won't that consume all of the workers very quickly? It looks as if my server, with 16 workers, will be unable to
|
||||||
// handle either the 17th WebSocket proxy or any other HTTP request. That's not really practical in a production system.
|
// handle either the 17th WebSocket proxy or any other HTTP request. That's not really practical in a production system.
|
||||||
// A WebSocket server could potentially handle hundreds or even thousands of simultaneous connections, which would mean
|
// A WebSocket server could potentially handle hundreds or even thousands of simultaneous connections, which would mean
|
||||||
// the same number of proxies in server
|
// the same number of proxies in server...
|
||||||
// --------------------------------------------------------------------------------------------------------------------
|
// --------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
if (UHTTP::service->isWebSocket())
|
if (UHTTP::service->isWebSocket())
|
||||||
|
@ -212,18 +212,6 @@ int UProxyPlugIn::handlerRequest()
|
||||||
if (body.size() > U_MIN_SIZE_FOR_DEFLATE &&
|
if (body.size() > U_MIN_SIZE_FOR_DEFLATE &&
|
||||||
UHttpClient_Base::u_http_info_save.flag[11]) // U_http_is_accept_gzip
|
UHttpClient_Base::u_http_info_save.flag[11]) // U_http_is_accept_gzip
|
||||||
{
|
{
|
||||||
UString header(U_CAPACITY);
|
|
||||||
|
|
||||||
char* ptr1 = header.data();
|
|
||||||
uint32_t sz1 = U_CONSTANT_SIZE("Content-Encoding: gzip\r\n");
|
|
||||||
|
|
||||||
u__memcpy(ptr1, content_type.data(), sz, __PRETTY_FUNCTION__);
|
|
||||||
u__memcpy(ptr1+sz, "Content-Encoding: gzip\r\n", sz1, __PRETTY_FUNCTION__);
|
|
||||||
|
|
||||||
header.size_adjust(sz + sz1);
|
|
||||||
|
|
||||||
content_type = header;
|
|
||||||
|
|
||||||
body = UStringExt::deflate(body, 1);
|
body = UStringExt::deflate(body, 1);
|
||||||
}
|
}
|
||||||
# endif
|
# endif
|
||||||
|
|
|
@ -136,7 +136,7 @@ void USSIPlugIn::setAlternativeResponse()
|
||||||
UHTTP::setResponse(0, 0);
|
UHTTP::setResponse(0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void USSIPlugIn::setAlternativeResponse(const UString& _body)
|
void USSIPlugIn::setAlternativeResponse(UString& _body)
|
||||||
{
|
{
|
||||||
U_TRACE(0, "USSIPlugIn::setAlternativeResponse(%.*S)", U_STRING_TO_TRACE(_body))
|
U_TRACE(0, "USSIPlugIn::setAlternativeResponse(%.*S)", U_STRING_TO_TRACE(_body))
|
||||||
|
|
||||||
|
|
|
@ -1881,6 +1881,7 @@ int UServer_Base::handlerRead() // This method is called to accept a new connect
|
||||||
|
|
||||||
loop:
|
loop:
|
||||||
U_INTERNAL_ASSERT_MINOR(pClientIndex, eClientImage)
|
U_INTERNAL_ASSERT_MINOR(pClientIndex, eClientImage)
|
||||||
|
U_INTERNAL_ASSERT_DIFFERS(U_ClientImage_parallelization, 1) // 1 => child of parallelization
|
||||||
|
|
||||||
U_INTERNAL_DUMP("----------------------------------------", 0)
|
U_INTERNAL_DUMP("----------------------------------------", 0)
|
||||||
U_INTERNAL_DUMP("vClientImage[%d].last_event = %#3D", (pClientIndex - vClientImage),
|
U_INTERNAL_DUMP("vClientImage[%d].last_event = %#3D", (pClientIndex - vClientImage),
|
||||||
|
@ -1930,6 +1931,7 @@ try_next:
|
||||||
|
|
||||||
try_accept:
|
try_accept:
|
||||||
U_INTERNAL_ASSERT(csocket->isClosed())
|
U_INTERNAL_ASSERT(csocket->isClosed())
|
||||||
|
U_INTERNAL_ASSERT_DIFFERS(U_ClientImage_parallelization, 1) // 1 => child of parallelization
|
||||||
|
|
||||||
if (socket->acceptClient(csocket) == false)
|
if (socket->acceptClient(csocket) == false)
|
||||||
{
|
{
|
||||||
|
@ -2196,6 +2198,9 @@ retry:
|
||||||
if (UServer_Base::max_depth < UNotifier::num_connection) UServer_Base::max_depth = UNotifier::num_connection;
|
if (UServer_Base::max_depth < UNotifier::num_connection) UServer_Base::max_depth = UNotifier::num_connection;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
U_INTERNAL_ASSERT(csocket->isOpen())
|
||||||
|
U_INTERNAL_ASSERT_DIFFERS(U_ClientImage_parallelization, 1) // 1 => child of parallelization
|
||||||
|
|
||||||
UNotifier::insert((UEventFd*)pClientIndex);
|
UNotifier::insert((UEventFd*)pClientIndex);
|
||||||
|
|
||||||
if (UNLIKELY(++pClientIndex >= eClientImage))
|
if (UNLIKELY(++pClientIndex >= eClientImage))
|
||||||
|
@ -2832,6 +2837,10 @@ bool UServer_Base::startParallelization()
|
||||||
U_INTERNAL_DUMP("U_ClientImage_pipeline = %b U_ClientImage_parallelization = %d U_CNT_PARALLELIZATION = %d max_num_process_parallelization = %d",
|
U_INTERNAL_DUMP("U_ClientImage_pipeline = %b U_ClientImage_parallelization = %d U_CNT_PARALLELIZATION = %d max_num_process_parallelization = %d",
|
||||||
U_ClientImage_pipeline, U_ClientImage_parallelization, U_CNT_PARALLELIZATION, max_num_process_parallelization)
|
U_ClientImage_pipeline, U_ClientImage_parallelization, U_CNT_PARALLELIZATION, max_num_process_parallelization)
|
||||||
|
|
||||||
|
#ifdef USE_LIBSSL
|
||||||
|
// if (bssl == false)
|
||||||
|
#endif
|
||||||
|
{
|
||||||
if (U_ClientImage_pipeline == false &&
|
if (U_ClientImage_pipeline == false &&
|
||||||
U_ClientImage_parallelization == false &&
|
U_ClientImage_parallelization == false &&
|
||||||
U_CNT_PARALLELIZATION < max_num_process_parallelization) // NB: thread approach => (max_num_process_parallelization == 0)
|
U_CNT_PARALLELIZATION < max_num_process_parallelization) // NB: thread approach => (max_num_process_parallelization == 0)
|
||||||
|
@ -2857,6 +2866,7 @@ bool UServer_Base::startParallelization()
|
||||||
|
|
||||||
U_ASSERT(isParallelizationChild())
|
U_ASSERT(isParallelizationChild())
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
U_INTERNAL_DUMP("U_ClientImage_close = %b", U_ClientImage_close)
|
U_INTERNAL_DUMP("U_ClientImage_close = %b", U_ClientImage_close)
|
||||||
|
|
||||||
|
|
|
@ -51,17 +51,17 @@ void ULock::lock(time_t timeout)
|
||||||
{
|
{
|
||||||
if (spinlock)
|
if (spinlock)
|
||||||
{
|
{
|
||||||
uint32_t cnt = 100;
|
// uint32_t cnt = 100;
|
||||||
|
|
||||||
do {
|
// do {
|
||||||
if (spinLockAcquire(spinlock))
|
if (spinLockAcquire(spinlock))
|
||||||
{
|
{
|
||||||
locked = -1;
|
locked = -1;
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
// }
|
||||||
while (cnt--);
|
// while (cnt--);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sem &&
|
if (sem &&
|
||||||
|
|
|
@ -1425,9 +1425,7 @@ UString UStringExt::gunzip(const char* ptr, uint32_t sz, uint32_t space) // .gz
|
||||||
|
|
||||||
if (space == 0)
|
if (space == 0)
|
||||||
{
|
{
|
||||||
// check magic byte
|
if (isGzip(ptr)) // check magic byte
|
||||||
|
|
||||||
if (*(int16_t*)ptr == U_MULTICHAR_CONSTANT16('\x1F','\x8B'))
|
|
||||||
{
|
{
|
||||||
uint32_t* psize_original = (uint32_t*)(ptr + sz - 4); // read original size
|
uint32_t* psize_original = (uint32_t*)(ptr + sz - 4); // read original size
|
||||||
|
|
||||||
|
@ -1770,7 +1768,7 @@ static inline bool isExtendableOnLeft(char c)
|
||||||
|
|
||||||
UString UStringExt::minifyCssJs(const char* s, uint32_t n)
|
UString UStringExt::minifyCssJs(const char* s, uint32_t n)
|
||||||
{
|
{
|
||||||
U_TRACE(0, "UStringExt::minifyCssJs(%.*S,%u)", n, s, n)
|
U_TRACE(0+256, "UStringExt::minifyCssJs(%.*S,%u)", n, s, n)
|
||||||
|
|
||||||
U_INTERNAL_ASSERT_MAJOR_MSG(n, 0, "elaborazione su stringa vuota: inserire if empty()...")
|
U_INTERNAL_ASSERT_MAJOR_MSG(n, 0, "elaborazione su stringa vuota: inserire if empty()...")
|
||||||
|
|
||||||
|
|
|
@ -2185,7 +2185,7 @@ bool UHTTP::readBody(USocket* sk, UString* pbuffer, UString& body)
|
||||||
* be much larger than the examples here. The size-line parameters are rarely used, but you should at
|
* be much larger than the examples here. The size-line parameters are rarely used, but you should at
|
||||||
* least ignore them correctly. Footers are also rare, but might be appropriate for things like checksums
|
* least ignore them correctly. Footers are also rare, but might be appropriate for things like checksums
|
||||||
* or digital signatures
|
* or digital signatures
|
||||||
*/
|
*/
|
||||||
|
|
||||||
count = pbuffer->find(U_CRLF2, u_http_info.endHeader, U_CONSTANT_SIZE(U_CRLF2));
|
count = pbuffer->find(U_CRLF2, u_http_info.endHeader, U_CONSTANT_SIZE(U_CRLF2));
|
||||||
|
|
||||||
|
@ -2224,7 +2224,7 @@ bool UHTTP::readBody(USocket* sk, UString* pbuffer, UString& body)
|
||||||
|
|
||||||
chunkSize = strtol(inp, 0, 16);
|
chunkSize = strtol(inp, 0, 16);
|
||||||
|
|
||||||
// U_INTERNAL_DUMP("chunkSize = %u inp[0] = %C", chunkSize, inp[0])
|
// U_INTERNAL_DUMP("chunkSize = %u inp[0] = %C", chunkSize, inp[0])
|
||||||
|
|
||||||
// The last chunk is followed by zero or more trailers, followed by a blank line
|
// The last chunk is followed by zero or more trailers, followed by a blank line
|
||||||
|
|
||||||
|
@ -5313,7 +5313,7 @@ UString UHTTP::getHeaderForResponse(const UString& ext)
|
||||||
U_RETURN_STRING(result);
|
U_RETURN_STRING(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
void UHTTP::setResponse(const UString* content_type, const UString* pbody)
|
void UHTTP::setResponse(const UString* content_type, UString* pbody)
|
||||||
{
|
{
|
||||||
U_TRACE(0, "UHTTP::setResponse(%p,%p)", content_type, pbody)
|
U_TRACE(0, "UHTTP::setResponse(%p,%p)", content_type, pbody)
|
||||||
|
|
||||||
|
@ -5348,7 +5348,35 @@ void UHTTP::setResponse(const UString* content_type, const UString* pbody)
|
||||||
ptr += U_CONSTANT_SIZE("Content-Length: ");
|
ptr += U_CONSTANT_SIZE("Content-Length: ");
|
||||||
|
|
||||||
if (pbody == 0) *ptr++ = '0';
|
if (pbody == 0) *ptr++ = '0';
|
||||||
else ptr += u_num2str32(ptr, pbody->size());
|
else
|
||||||
|
{
|
||||||
|
sz = pbody->size();
|
||||||
|
|
||||||
|
# ifdef USE_LIBZ
|
||||||
|
if (UStringExt::isGzip(*pbody))
|
||||||
|
{
|
||||||
|
if (U_http_is_accept_gzip == false)
|
||||||
|
{
|
||||||
|
*pbody = UStringExt::gunzip(*pbody);
|
||||||
|
|
||||||
|
sz = pbody->size();
|
||||||
|
}
|
||||||
|
|
||||||
|
ptr += u_num2str32(ptr, sz);
|
||||||
|
|
||||||
|
if (U_http_is_accept_gzip)
|
||||||
|
{
|
||||||
|
*(int64_t*) ptr = U_MULTICHAR_CONSTANT64('\r','\n','C','o','n','t','e','n');
|
||||||
|
*(int64_t*)(ptr+8) = U_MULTICHAR_CONSTANT64( 't', '-','E','n','c','o','d','i');
|
||||||
|
*(int64_t*)(ptr+16) = U_MULTICHAR_CONSTANT64( 'n', 'g',':',' ','g','z','i','p');
|
||||||
|
|
||||||
|
ptr += U_CONSTANT_SIZE("\r\nContent-Encoding: gzip");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
# endif
|
||||||
|
ptr += u_num2str32(ptr, sz);
|
||||||
|
}
|
||||||
|
|
||||||
*(int32_t*)ptr = U_MULTICHAR_CONSTANT32('\r','\n','\r','\n');
|
*(int32_t*)ptr = U_MULTICHAR_CONSTANT32('\r','\n','\r','\n');
|
||||||
ptr += U_CONSTANT_SIZE(U_CRLF2);
|
ptr += U_CONSTANT_SIZE(U_CRLF2);
|
||||||
|
|
|
@ -482,4 +482,4 @@ TIMEOUT() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# grep -v 'Not a GIF file' err/* | grep --colour -i -E -e 'ERROR|ABORT|ASSERT|SIGSEGV|OVERLAP|genericRead|handler|epoll_ctl'
|
# grep -v 'Not a GIF file' err/* | grep --colour -i -E -e 'ERROR|ABORT|ASSERT|SIGSEGV|OVERLAP|genericRead|handler|epoll_ctl' | grep -v SQLITE_ABORT
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
AFF6
|
B0BC
|
||||||
|
|
|
@ -16,9 +16,9 @@
|
||||||
# . $FWROOT/ULib/install.sh (cwd=$FWROOT//installs)
|
# . $FWROOT/ULib/install.sh (cwd=$FWROOT//installs)
|
||||||
# --------------------------------------------------------------------------------------------------------
|
# --------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
export ULIB_VERSION=1.4.2
|
ULIB_VERSION=1.4.2
|
||||||
export ULIB_ROOT=$IROOT/ULib
|
ULIB_ROOT=$IROOT/ULib
|
||||||
export ULIB_DOCUMENT_ROOT=${ULIB_ROOT}/ULIB_DOCUMENT_ROOT
|
ULIB_DOCUMENT_ROOT=${ULIB_ROOT}/ULIB_DOCUMENT_ROOT
|
||||||
|
|
||||||
# Check if ULib is already installed
|
# Check if ULib is already installed
|
||||||
ULIB_INSTALLED_FILE="${IROOT}/ULib-${ULIB_VERSION}.installed"
|
ULIB_INSTALLED_FILE="${IROOT}/ULib-${ULIB_VERSION}.installed"
|
||||||
|
|
|
@ -5,7 +5,7 @@ export ORM_DRIVER="mysql"
|
||||||
export ORM_OPTION="host=${DBHOST} user=benchmarkdbuser password=benchmarkdbpass character-set=utf8 dbname=hello_world"
|
export ORM_OPTION="host=${DBHOST} user=benchmarkdbuser password=benchmarkdbpass character-set=utf8 dbname=hello_world"
|
||||||
|
|
||||||
# 1. Change ULib Server configuration
|
# 1. Change ULib Server configuration
|
||||||
sed -i "s|PREFORK_CHILD .*|PREFORK_CHILD ${MAX_THREADS}|g" $ULIB_ROOT/benchmark.cfg
|
sed -i "s|PREFORK_CHILD .*|PREFORK_CHILD ${MAX_THREADS}|g" $IROOT/ULib/benchmark.cfg
|
||||||
|
|
||||||
# 2. Start ULib Server (userver_tcp)
|
# 2. Start ULib Server (userver_tcp)
|
||||||
$ULIB_ROOT/bin/userver_tcp -c $ULIB_ROOT/benchmark.cfg &
|
$IROOT/ULib/bin/userver_tcp -c $IROOT/ULib/benchmark.cfg &
|
||||||
|
|
|
@ -5,7 +5,7 @@ export ORM_DRIVER="pgsql"
|
||||||
export ORM_OPTION="host=${DBHOST} user=benchmarkdbuser password=benchmarkdbpass dbname=hello_world client_encoding=UTF8"
|
export ORM_OPTION="host=${DBHOST} user=benchmarkdbuser password=benchmarkdbpass dbname=hello_world client_encoding=UTF8"
|
||||||
|
|
||||||
# 1. Change ULib Server configuration
|
# 1. Change ULib Server configuration
|
||||||
sed -i "s|PREFORK_CHILD .*|PREFORK_CHILD ${MAX_THREADS}|g" $ULIB_ROOT/benchmark.cfg
|
sed -i "s|PREFORK_CHILD .*|PREFORK_CHILD ${MAX_THREADS}|g" $IROOT/ULib/benchmark.cfg
|
||||||
|
|
||||||
# 2. Start ULib Server (userver_tcp)
|
# 2. Start ULib Server (userver_tcp)
|
||||||
$ULIB_ROOT/bin/userver_tcp -c $ULIB_ROOT/benchmark.cfg &
|
$IROOT/ULib/bin/userver_tcp -c $IROOT/ULib/benchmark.cfg &
|
||||||
|
|
|
@ -5,7 +5,7 @@ export ORM_DRIVER="sqlite"
|
||||||
export ORM_OPTION="host=${DBHOST} user=benchmarkdbuser password=benchmarkdbpass character-set=utf8 dbname=${ULIB_ROOT}/db/%.*s"
|
export ORM_OPTION="host=${DBHOST} user=benchmarkdbuser password=benchmarkdbpass character-set=utf8 dbname=${ULIB_ROOT}/db/%.*s"
|
||||||
|
|
||||||
# 1. Change ULib Server configuration
|
# 1. Change ULib Server configuration
|
||||||
sed -i "s|PREFORK_CHILD .*|PREFORK_CHILD ${MAX_THREADS}|g" $ULIB_ROOT/benchmark.cfg
|
sed -i "s|PREFORK_CHILD .*|PREFORK_CHILD ${MAX_THREADS}|g" ${IROOT}/ULib/benchmark.cfg
|
||||||
|
|
||||||
# 2. Start ULib Server (userver_tcp)
|
# 2. Start ULib Server (userver_tcp)
|
||||||
$ULIB_ROOT/bin/userver_tcp -c $ULIB_ROOT/benchmark.cfg &
|
${IROOT}/ULib/bin/userver_tcp -c ${IROOT}/ULib/benchmark.cfg &
|
||||||
|
|
|
@ -43,5 +43,4 @@ const char* hello_str = json_object_to_json_string(hello);
|
||||||
USP_PUTS_STRING(hello_str);
|
USP_PUTS_STRING(hello_str);
|
||||||
json_object_put(hello);
|
json_object_put(hello);
|
||||||
#endif
|
#endif
|
||||||
U_ClientImage_request_nocache = true;
|
|
||||||
-->
|
-->
|
||||||
|
|
|
@ -24,8 +24,6 @@ int main(int argc, char* argv[])
|
||||||
captcha(im, l);
|
captcha(im, l);
|
||||||
makegif(im, gif);
|
makegif(im, gif);
|
||||||
|
|
||||||
U_ClientImage_request_nocache = true;
|
|
||||||
|
|
||||||
set_reply_capacity(1024 + GIF_SIZE * 3);
|
set_reply_capacity(1024 + GIF_SIZE * 3);
|
||||||
|
|
||||||
(void) u__snprintf(get_reply(), get_reply_capacity(), "<img src=\"data:img/gif;base64,%.*s\">", u_base64_encode(gif, GIF_SIZE, encoded), encoded);
|
(void) u__snprintf(get_reply(), get_reply_capacity(), "<img src=\"data:img/gif;base64,%.*s\">", u_base64_encode(gif, GIF_SIZE, encoded), encoded);
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
GET /test HTTP/1.1
|
GET /test HTTP/1.1
|
||||||
User-Agent: curl/7.18.0 (i486-pc-linux-gnu) libcurl/7.18.0 OpenSSL/0.9.8g zlib/1.2.3.3 libidn/1.1
|
User-Agent: curl/7.18.0 (i486-pc-linux-gnu) libcurl/7.18.0 OpenSSL/0.9.8g zlib/1.2.3.3 libidn/1.1
|
||||||
Host: 0.0.0.0=5000
|
Host: 0.0.0.0:5000
|
||||||
Accept: */*
|
Accept: */*
|
||||||
|
|
||||||
GET /favicon.ico HTTP/1.1
|
GET /favicon.ico HTTP/1.1
|
||||||
|
@ -16,9 +16,6 @@ Connection: keep-alive
|
||||||
GET /dumbfuck HTTP/1.0
|
GET /dumbfuck HTTP/1.0
|
||||||
aaaaaaaaaaaaa:++++++++++
|
aaaaaaaaaaaaa:++++++++++
|
||||||
|
|
||||||
GET /forums/1/topics/2375?page=1#posts-17408 HTTP/1.1
|
|
||||||
Host: 0.0.0.0=5000
|
|
||||||
|
|
||||||
GET /get_no_headers_no_body/world HTTP/1.0
|
GET /get_no_headers_no_body/world HTTP/1.0
|
||||||
|
|
||||||
GET /get_one_header_no_body HTTP/1.0
|
GET /get_one_header_no_body HTTP/1.0
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -38,6 +38,7 @@ userver {
|
||||||
DOCUMENT_ROOT benchmark/docroot
|
DOCUMENT_ROOT benchmark/docroot
|
||||||
PLUGIN_DIR ../../../../src/ulib/net/server/plugin/.libs
|
PLUGIN_DIR ../../../../src/ulib/net/server/plugin/.libs
|
||||||
ORM_DRIVER_DIR ../../../../src/ulib/orm/driver/.libs
|
ORM_DRIVER_DIR ../../../../src/ulib/orm/driver/.libs
|
||||||
|
PREFORK_CHILD 2
|
||||||
}
|
}
|
||||||
http {
|
http {
|
||||||
ALIAS [ / /index.php ]
|
ALIAS [ / /index.php ]
|
||||||
|
|
|
@ -201,6 +201,8 @@ c
|
||||||
c
|
c
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
|
killall userver_ssl 2>/dev/null
|
||||||
|
|
||||||
# webserver_ssl0
|
# webserver_ssl0
|
||||||
creat_config 0
|
creat_config 0
|
||||||
start_test
|
start_test
|
||||||
|
|
Binary file not shown.
|
@ -1,13 +1,15 @@
|
||||||
POST /soap HTTP/1.1
|
POST /soap HTTP/1.1
|
||||||
Host: localhost
|
Host: localhost
|
||||||
|
Accept-Encoding: gzip
|
||||||
User-Agent: ULib/1.4.2
|
User-Agent: ULib/1.4.2
|
||||||
Content-Type: application/soap+xml; charset="utf-8"
|
Content-Type: application/soap+xml; charset="utf-8"
|
||||||
Content-Length: 350
|
Content-Length: 350
|
||||||
|
|
||||||
<?xml version='1.0' ?><env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><env:Header></env:Header><env:Body><ns:add env:encodingStyle="http://www.w3.org/2003/05/soap-encoding" xmlns:ns="ns"><a xsi:type="xsd:int">10</a><b xsi:type="xsd:int">20</b></ns:add></env:Body></env:Envelope>POST /soap HTTP/1.1
|
<?xml version='1.0' ?><env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><env:Header></env:Header><env:Body><ns:add env:encodingStyle="http://www.w3.org/2003/05/soap-encoding" xmlns:ns="ns"><a xsi:type="xsd:int">10</a><b xsi:type="xsd:int">20</b></ns:add></env:Body></env:Envelope>POST /soap HTTP/1.1
|
||||||
Host: localhost
|
Host: localhost
|
||||||
|
Accept-Encoding: gzip
|
||||||
User-Agent: ULib/1.4.2
|
User-Agent: ULib/1.4.2
|
||||||
Content-Type: application/soap+xml; charset="utf-8"
|
Content-Type: application/soap+xml; charset="utf-8"
|
||||||
Content-Length: 345
|
Content-Length: 345
|
||||||
|
|
||||||
<?xml version='1.0' ?><env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><env:Header></env:Header><env:Body><ns:reverse env:encodingStyle="http://www.w3.org/2003/05/soap-encoding" xmlns:ns="ns"><str xsi:type="xsd:string">0123456789</str></ns:reverse></env:Body></env:Envelope>
|
<?xml version='1.0' ?><env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><env:Header></env:Header><env:Body><ns:reverse env:encodingStyle="http://www.w3.org/2003/05/soap-encoding" xmlns:ns="ns"><str xsi:type="xsd:string">0123456789</str></ns:reverse></env:Body></env:Envelope>
|
Loading…
Reference in New Issue
Block a user