Skip to content

Commit

Permalink
sync
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanocasazza committed May 11, 2018
1 parent 7177337 commit d4dfd5d
Show file tree
Hide file tree
Showing 43 changed files with 2,721 additions and 380 deletions.
2 changes: 1 addition & 1 deletion examples/IR/ir_web.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ extern U_EXPORT void runDynamicPage_ir_web(int param);
{
if (param == U_DPAGE_INIT) { usp_init_ir_web(); return; }
if (param == U_DPAGE_DESTROY) { usp_end_ir_web(); return; }
if (param >= U_DPAGE_FORK) return;
return;
}

UHTTP::mime_index = U_html;
Expand Down
2 changes: 1 addition & 1 deletion examples/WiAuth/v2/wi_auth2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ extern U_EXPORT void runDynamicPage_wi_auth2(int param);
if (param == U_DPAGE_INIT) { usp_init_wi_auth2(); return; }
if (param == U_DPAGE_DESTROY) { usp_end_wi_auth2(); return; }
if (param == U_DPAGE_FORK) { usp_fork_wi_auth2(); return; }
if (param > U_DPAGE_FORK) return;
return;
}

U_http_info.endHeader = 0;
Expand Down
10 changes: 5 additions & 5 deletions examples/WiAuth/v2/wi_auth_declaration2.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,10 @@ static void loadAnagrafica()
U_INTERNAL_ASSERT(lnetmask)
U_ASSERT(vnetmask.empty())

U_INTERNAL_DUMP("tok.current() = %C", tok.current())
U_INTERNAL_DUMP("tok.previous() = %C tok.current() = %C", tok.previous(), tok.current())

if (u__isdigit(tok.current())) name.clear();
else (void) tok.next(name, (bool*)U_NULLPTR);
if (tok.previous() != ',') name.clear();
else (void) tok.next(name, (bool*)U_NULLPTR);

vnetmask.push_back(lnetmask);

Expand Down Expand Up @@ -613,7 +613,7 @@ static void deleteSession()
(void) rc->zrem(U_CONSTANT_TO_PARAM("SESSION:byCaptiveIdAndApId deviceId:%v;ip:%v"), mac->rep, ip->rep);
(void) rc->zrem(U_CONSTANT_TO_PARAM("SESSION:byLastUpdate %v"), key_session->rep);

U_LOGGER("*** SESSION(%V) deleted at deleteSession() ***", key_session->rep);
// U_LOGGER("*** SESSION(%V) deleted at deleteSession() ***", key_session->rep);
}

static void resetDeviceDailyCounter()
Expand Down Expand Up @@ -1111,7 +1111,7 @@ static void POST_login()
(void) rc->hmset(U_CONSTANT_TO_PARAM("SESSION:%v captiveId %u apId %v deviceId %v ip %v created %u pId %v notify %c consume %c counter 0 lastUpdate %u"), key_session->rep,
addr, ap_label->rep, mac->rep, ip->rep, u_now->tv_sec, policySessionId->rep, buffer[1], '0'+ap_consume, u_now->tv_sec);

U_LOGGER("*** SESSION(%V) created at POST_login() ***", key_session->rep);
// U_LOGGER("*** SESSION(%V) created at POST_login() ***", key_session->rep);

(void) rc->zadd(U_CONSTANT_TO_PARAM("SESSION:byCaptiveIdAndApId %u%06u deviceId:%v;ip:%v"), addr, ap_label->strtoul(), mac->rep, ip->rep);
(void) rc->zadd(U_CONSTANT_TO_PARAM("SESSION:byLastUpdate %u %v"), u_now->tv_sec, key_session->rep);
Expand Down
2 changes: 1 addition & 1 deletion examples/WiAuth/wi_auth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ extern U_EXPORT void runDynamicPage_wi_auth(int param);
if (param == U_DPAGE_INIT) { usp_init_wi_auth(); return; }
if (param == U_DPAGE_DESTROY) { usp_end_wi_auth(); return; }
if (param == U_DPAGE_SIGHUP) { usp_sighup_wi_auth(); return; }
if (param >= U_DPAGE_FORK) return;
return;
}

U_http_info.endHeader = 0;
Expand Down
4 changes: 2 additions & 2 deletions examples/userver/userver.cfg.default
Original file line number Diff line number Diff line change
Expand Up @@ -416,8 +416,8 @@ http {
# ------------------------------------------------------------------------------------------------------------------------------------------------
# socket - plugin parameters
# ------------------------------------------------------------------------------------------------------------------------------------------------
# COMMAND command (alternative to USP websocket) to execute
# ENVIRONMENT environment for command (alternative to USP websocket) to execute
# COMMAND command (alternative to USP modsocket) to execute
# ENVIRONMENT environment for command (alternative to USP modsocket) to execute
#
# MAX_MESSAGE_SIZE Maximum size (in bytes) of a message to accept; default is approximately 4GB
# ------------------------------------------------------------------------------------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions include/ulib/all.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
# include <ulib/ssl/digest.h>
# include <ulib/ssl/certificate.h>
# include <ulib/net/client/twilio.h>
# include <ulib/net/client/websocket.h>
# include <ulib/ssl/mime/mime_pkcs7.h>
# include <ulib/ssl/net/ssl_session.h>
# ifdef HAVE_SSL_TS
Expand Down
4 changes: 3 additions & 1 deletion include/ulib/dynamic/dynamic.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ enum DynamicPageType {
U_DPAGE_RESET = -2,
U_DPAGE_DESTROY = -3,
U_DPAGE_SIGHUP = -4,
U_DPAGE_FORK = -5
U_DPAGE_FORK = -5,
U_DPAGE_OPEN = -6,
U_DPAGE_CLOSE = -7
};

/**
Expand Down
2 changes: 2 additions & 0 deletions include/ulib/examples/wi_auth_declaration.h
Original file line number Diff line number Diff line change
Expand Up @@ -4163,7 +4163,9 @@ static bool runAuthCmd(const char* password, const char* prealm)

*output = UCommand::outputCommand(cmd, U_NULLPTR, -1, fd_stderr);

#ifdef U_LOG_DISABLE
UServer_Base::logCommandMsgError(cmd.data(), true);
#endif

if (UCommand::exit_value ||
output->empty())
Expand Down
3 changes: 1 addition & 2 deletions include/ulib/mime/header.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,8 @@ class U_EXPORT UMimeHeader {

U_ASSERT(empty() == false)

if (getHeader(U_CONSTANT_TO_PARAM("Connection")).equal(U_CONSTANT_TO_PARAM("close")))
if (getHeader(U_CONSTANT_TO_PARAM("Connection")).equal(U_CONSTANT_TO_PARAM("close"))) U_RETURN(true);

U_RETURN(true);
U_RETURN(false);
}

Expand Down
5 changes: 5 additions & 0 deletions include/ulib/net/client/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#include <ulib/url.h>
#include <ulib/net/rpc/rpc.h>
#include <ulib/mime/header.h>
#include <ulib/utility/uhttp.h>

#ifdef USE_LIBSSL
Expand All @@ -39,6 +40,7 @@ class USCGIPlugIn;
class UProxyPlugIn;
class UNoCatPlugIn;
class UServer_Base;
class UWebSocketClient;
class UHttpClient_Base;
class UClientImage_Base;
class UREDISClient_Base;
Expand Down Expand Up @@ -297,6 +299,8 @@ class U_EXPORT UClient_Base {

bool sendRequestAndReadResponse() { return sendRequest(true); }

bool processHeader(UMimeHeader* responseHeader) { return responseHeader->readHeader(socket, response); }

#ifdef USE_LIBSSL
void setSSLContext();

Expand Down Expand Up @@ -329,6 +333,7 @@ class U_EXPORT UClient_Base {
friend class UProxyPlugIn;
friend class UNoCatPlugIn;
friend class UServer_Base;
friend class UWebSocketClient;
friend class UHttpClient_Base;
friend class UClientImage_Base;
friend class UREDISClient_Base;
Expand Down
1 change: 0 additions & 1 deletion include/ulib/net/client/http.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
*/

class UHTTP;
class UMimeHeader;
class Application;
class WiAuthNodog;
class UServer_Base;
Expand Down
104 changes: 104 additions & 0 deletions include/ulib/net/client/websocket.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
// ============================================================================
//
// = LIBRARY
// ULib - c++ library
//
// = FILENAME
// websocket.h - simple websocket client
//
// = AUTHOR
// Stefano Casazza
//
// ============================================================================

#ifndef ULIB_WEBSOCKET_CLIENT_H
#define ULIB_WEBSOCKET_CLIENT_H 1

#include <ulib/net/client/client.h>
#include <ulib/ssl/net/sslsocket.h>
#include <ulib/utility/websocket.h>

/**
* @class UWebSocketClient
*/

class U_EXPORT UWebSocketClient {
public:

// Check for memory error
U_MEMORY_TEST

// Allocator e Deallocator
U_MEMORY_ALLOCATOR
U_MEMORY_DEALLOCATOR

/**
* Constructor
*/

UWebSocketClient()
{
U_TRACE_CTOR(0, UWebSocketClient, "", 0)

U_NEW(UClient<USSLSocket>, client, UClient<USSLSocket>(U_NULLPTR));
}

~UWebSocketClient()
{
U_TRACE_DTOR(0, UWebSocketClient)

U_INTERNAL_ASSERT_POINTER(client)

U_DELETE(client)
}

// SERVICES

bool readMessage()
{
U_TRACE_NO_PARAM(0, "UWebSocketClient::readMessage()")

U_INTERNAL_ASSERT_POINTER(client)

UWebSocket::rbuffer->setEmpty();

if (UWebSocket::handleDataFraming(client->UClient_Base::socket) == U_WS_STATUS_CODE_OK) U_RETURN(true);

U_RETURN(false);
}

bool sendMessage(const UString& msg, int type = U_WS_MESSAGE_TYPE_TEXT)
{
U_TRACE(0, "UWebSocketClient::sendMessage(%V,%d)", msg.rep, type)

U_INTERNAL_ASSERT_POINTER(client)

return UWebSocket::sendData(client->UClient_Base::socket, type, msg);
}

void close()
{
U_TRACE_NO_PARAM(0, "UWebSocketClient::close()")

U_INTERNAL_ASSERT_POINTER(client)

(void) UWebSocket::sendClose(client->UClient_Base::socket);

client->UClient_Base::close();
}

bool connectServer(const UString& url);

UClient<USSLSocket>* getClient() const { return client; }

#if defined(U_STDCPP_ENABLE) && defined(DEBUG)
const char* dump(bool reset) const;
#endif

protected:
UClient<USSLSocket>* client;

private:
U_DISALLOW_COPY_AND_ASSIGN(UWebSocketClient)
};
#endif
4 changes: 1 addition & 3 deletions include/ulib/net/server/plugin/mod_nocat.h
Original file line number Diff line number Diff line change
Expand Up @@ -300,9 +300,7 @@ class U_EXPORT UNoCatPlugIn : public UServerPlugIn, UEventTime {

(void) peer->fw.executeAndWait(U_NULLPTR, -1, fd_stderr);

# ifndef U_LOG_DISABLE
UServer_Base::logCommandMsgError(peer->fw.getCommand(), false);
# endif
U_SRV_LOG_CMD_MSG_ERR(peer->fw, false);

U_peer_status = type;
}
Expand Down
2 changes: 1 addition & 1 deletion include/ulib/net/server/plugin/mod_nodog.h
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ class U_EXPORT UNoDogPlugIn : public UServerPlugIn, UEventTime {
{
U_TRACE(0, "UNoDogPlugIn::setRedirect(%p,%u)", buffer, bufsize)

return u__snprintf(buffer, bufsize, U_CONSTANT_TO_PARAM("http://%.*s/%.*s"), U_HTTP_HOST_TO_TRACE, U_HTTP_URI_QUERY_TO_TRACE);
return u__snprintf(buffer, bufsize, U_CONSTANT_TO_PARAM("http://%.*s%.*s"), U_HTTP_HOST_TO_TRACE, U_HTTP_URI_QUERY_TO_TRACE);
}

static uint32_t getApInfo(char* buffer, uint32_t bufsize, const UString& lbl)
Expand Down
2 changes: 2 additions & 0 deletions include/ulib/net/server/plugin/mod_socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@ class U_EXPORT UWebSocketPlugIn : public UServerPlugIn {
#endif

protected:
static int fd_stderr;
static vPFi on_message;
static UCommand* command;
static UString* penvironment;

static RETSIGTYPE handlerForSigTERM(int signo);

Expand Down
16 changes: 10 additions & 6 deletions include/ulib/net/server/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,19 @@ vClientImage = new client_type[UNotifier::max_connection]; } }

# define U_SRV_LOG( fmt,args...) {}
# define U_SRV_LOG_WITH_ADDR(fmt,args...) {}

# define U_SRV_LOG_CMD_MSG_ERR(cmd,balways) {}
#else
# define U_SRV_LOG_CMD_MSG_ERR(cmd,balways) { if (UServer_Base::isLog()) UServer_Base::logCommandMsgError((cmd).getCommand(),balways); }

# define U_RESET_MODULE_NAME { if (UServer_Base::isLog()) (void) strcpy(UServer_Base::mod_name[0], UServer_Base::mod_name[1]); }
# define U_SET_MODULE_NAME(name) { if (UServer_Base::isLog()) { (void) strcpy(UServer_Base::mod_name[1], UServer_Base::mod_name[0]); \
(void) strcpy(UServer_Base::mod_name[0], "["#name"] "); } }

# define U_SRV_LOG( fmt,args...) { if (UServer_Base::isLog()) UServer_Base::log->log(U_CONSTANT_TO_PARAM("%s" fmt), UServer_Base::mod_name[0] , ##args); }
# define U_SRV_LOG_WITH_ADDR(fmt,args...) { if (UServer_Base::isLog()) UServer_Base::log->log(U_CONSTANT_TO_PARAM("%s" fmt " %v"), UServer_Base::mod_name[0] , ##args, \
UServer_Base::pClientImage->logbuf->rep); }

#endif

class UHTTP;
Expand Down Expand Up @@ -617,13 +622,12 @@ class U_EXPORT UServer_Base : public UEventFd {
U_TRACE(0, "UServer_Base::logCommandMsgError(%S,%b)", cmd, balways)

# ifndef U_LOG_DISABLE
if (isLog())
{
if (UCommand::setMsgError(cmd, !balways) || balways) log->log(U_CONSTANT_TO_PARAM("%s%.*s"), mod_name[0], u_buffer_len, u_buffer);
U_INTERNAL_ASSERT_POINTER(log)

errno = 0;
u_buffer_len = 0;
}
if (UCommand::setMsgError(cmd, !balways) || balways) log->log(U_CONSTANT_TO_PARAM("%s%.*s"), mod_name[0], u_buffer_len, u_buffer);

errno = 0;
u_buffer_len = 0;
# endif
}

Expand Down
11 changes: 11 additions & 0 deletions include/ulib/tokenizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,17 @@ class U_EXPORT UTokenizer {
--s;
}

// get previous char

char previous()
{
U_TRACE_NO_PARAM(0, "UTokenizer::previous()")

U_INTERNAL_ASSERT(s <= end)

U_RETURN(*(s-1));
}

// get current char

char current()
Expand Down
Loading

0 comments on commit d4dfd5d

Please sign in to comment.