winpr/utils/wlog: Format code by astyle
Run ./scripts/format_code.sh before the following changes.
This commit is contained in:
parent
4813a70897
commit
d3c2ceb0f6
@ -33,7 +33,7 @@
|
||||
struct _wLogUdpAppender
|
||||
{
|
||||
WLOG_APPENDER_COMMON();
|
||||
char *host;
|
||||
char* host;
|
||||
struct sockaddr targetAddr;
|
||||
int targetAddrLen;
|
||||
SOCKET sock;
|
||||
@ -42,12 +42,12 @@ typedef struct _wLogUdpAppender wLogUdpAppender;
|
||||
|
||||
static BOOL WLog_UdpAppender_Open(wLog* log, wLogAppender* appender)
|
||||
{
|
||||
wLogUdpAppender *udpAppender;
|
||||
wLogUdpAppender* udpAppender;
|
||||
char addressString[256];
|
||||
struct addrinfo hints;
|
||||
struct addrinfo* result;
|
||||
int status, addrLen;
|
||||
char *colonPos;
|
||||
char* colonPos;
|
||||
|
||||
if (!appender)
|
||||
return FALSE;
|
||||
@ -58,17 +58,18 @@ static BOOL WLog_UdpAppender_Open(wLog* log, wLogAppender* appender)
|
||||
return TRUE;
|
||||
|
||||
colonPos = strchr(udpAppender->host, ':');
|
||||
|
||||
if (!colonPos)
|
||||
return FALSE;
|
||||
addrLen = (int) (colonPos - udpAppender->host);
|
||||
|
||||
addrLen = (int)(colonPos - udpAppender->host);
|
||||
memcpy(addressString, udpAppender->host, addrLen);
|
||||
addressString[addrLen] = '\0';
|
||||
|
||||
ZeroMemory(&hints, sizeof(hints));
|
||||
hints.ai_family = AF_INET;
|
||||
hints.ai_socktype = SOCK_DGRAM;
|
||||
status = getaddrinfo(addressString, colonPos + 1, &hints, &result);
|
||||
|
||||
status = getaddrinfo(addressString, colonPos+1, &hints, &result);
|
||||
if (status != 0)
|
||||
return FALSE;
|
||||
|
||||
@ -80,7 +81,6 @@ static BOOL WLog_UdpAppender_Open(wLog* log, wLogAppender* appender)
|
||||
|
||||
memcpy(&udpAppender->targetAddr, result->ai_addr, result->ai_addrlen);
|
||||
udpAppender->targetAddrLen = (int) result->ai_addrlen;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@ -95,29 +95,24 @@ static BOOL WLog_UdpAppender_Close(wLog* log, wLogAppender* appender)
|
||||
static BOOL WLog_UdpAppender_WriteMessage(wLog* log, wLogAppender* appender, wLogMessage* message)
|
||||
{
|
||||
char prefix[WLOG_MAX_PREFIX_SIZE];
|
||||
wLogUdpAppender *udpAppender;
|
||||
|
||||
wLogUdpAppender* udpAppender;
|
||||
|
||||
if (!log || !appender || !message)
|
||||
return FALSE;
|
||||
|
||||
udpAppender = (wLogUdpAppender *)appender;
|
||||
|
||||
udpAppender = (wLogUdpAppender*)appender;
|
||||
message->PrefixString = prefix;
|
||||
WLog_Layout_GetMessagePrefix(log, appender->Layout, message);
|
||||
|
||||
_sendto(udpAppender->sock, message->PrefixString, strlen(message->PrefixString),
|
||||
0, &udpAppender->targetAddr, udpAppender->targetAddrLen);
|
||||
|
||||
0, &udpAppender->targetAddr, udpAppender->targetAddrLen);
|
||||
_sendto(udpAppender->sock, message->TextString, strlen(message->TextString),
|
||||
0, &udpAppender->targetAddr, udpAppender->targetAddrLen);
|
||||
|
||||
0, &udpAppender->targetAddr, udpAppender->targetAddrLen);
|
||||
_sendto(udpAppender->sock, "\n", 1, 0, &udpAppender->targetAddr, udpAppender->targetAddrLen);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static BOOL WLog_UdpAppender_WriteDataMessage(wLog* log, wLogAppender* appender, wLogMessage* message)
|
||||
static BOOL WLog_UdpAppender_WriteDataMessage(wLog* log, wLogAppender* appender,
|
||||
wLogMessage* message)
|
||||
{
|
||||
if (!log || !appender || !message)
|
||||
return FALSE;
|
||||
@ -125,18 +120,18 @@ static BOOL WLog_UdpAppender_WriteDataMessage(wLog* log, wLogAppender* appender,
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static BOOL WLog_UdpAppender_WriteImageMessage(wLog* log, wLogAppender* appender, wLogMessage* message)
|
||||
static BOOL WLog_UdpAppender_WriteImageMessage(wLog* log, wLogAppender* appender,
|
||||
wLogMessage* message)
|
||||
{
|
||||
if (!log || !appender || !message)
|
||||
return FALSE;
|
||||
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static BOOL WLog_UdpAppender_Set(wLogAppender* appender, const char *setting, void *value)
|
||||
static BOOL WLog_UdpAppender_Set(wLogAppender* appender, const char* setting, void* value)
|
||||
{
|
||||
wLogUdpAppender *udpAppender = (wLogUdpAppender *)appender;
|
||||
wLogUdpAppender* udpAppender = (wLogUdpAppender*)appender;
|
||||
|
||||
if (!value || !strlen(value))
|
||||
return FALSE;
|
||||
@ -145,24 +140,28 @@ static BOOL WLog_UdpAppender_Set(wLogAppender* appender, const char *setting, vo
|
||||
return FALSE;
|
||||
|
||||
udpAppender->targetAddrLen = 0;
|
||||
|
||||
if (udpAppender->host)
|
||||
free(udpAppender->host);
|
||||
|
||||
udpAppender->host = _strdup((const char *)value);
|
||||
udpAppender->host = _strdup((const char*)value);
|
||||
return (udpAppender->host != NULL) && WLog_UdpAppender_Open(NULL, appender);
|
||||
}
|
||||
|
||||
static void WLog_UdpAppender_Free(wLogAppender* appender)
|
||||
{
|
||||
wLogUdpAppender* udpAppender;
|
||||
|
||||
if (appender)
|
||||
{
|
||||
udpAppender = (wLogUdpAppender *)appender;
|
||||
udpAppender = (wLogUdpAppender*)appender;
|
||||
|
||||
if (udpAppender->sock != INVALID_SOCKET)
|
||||
{
|
||||
closesocket(udpAppender->sock);
|
||||
udpAppender->sock = INVALID_SOCKET;
|
||||
}
|
||||
|
||||
free(udpAppender->host);
|
||||
free(udpAppender);
|
||||
}
|
||||
@ -173,13 +172,12 @@ wLogAppender* WLog_UdpAppender_New(wLog* log)
|
||||
wLogUdpAppender* appender;
|
||||
DWORD nSize;
|
||||
LPCSTR name;
|
||||
|
||||
appender = (wLogUdpAppender*) calloc(1, sizeof(wLogUdpAppender));
|
||||
|
||||
if (!appender)
|
||||
return NULL;
|
||||
|
||||
appender->Type = WLOG_APPENDER_UDP;
|
||||
|
||||
appender->Open = WLog_UdpAppender_Open;
|
||||
appender->Close = WLog_UdpAppender_Close;
|
||||
appender->WriteMessage = WLog_UdpAppender_WriteMessage;
|
||||
@ -187,34 +185,36 @@ wLogAppender* WLog_UdpAppender_New(wLog* log)
|
||||
appender->WriteImageMessage = WLog_UdpAppender_WriteImageMessage;
|
||||
appender->Free = WLog_UdpAppender_Free;
|
||||
appender->Set = WLog_UdpAppender_Set;
|
||||
|
||||
appender->sock = _socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
||||
|
||||
if (appender->sock == INVALID_SOCKET)
|
||||
goto error_sock;
|
||||
|
||||
name = "WLOG_UDP_TARGET";
|
||||
nSize = GetEnvironmentVariableA(name, NULL, 0);
|
||||
|
||||
if (nSize)
|
||||
{
|
||||
appender->host = (LPSTR) malloc(nSize);
|
||||
|
||||
if (!appender->host)
|
||||
goto error_open;
|
||||
|
||||
if (GetEnvironmentVariableA(name, appender->host, nSize) != nSize - 1)
|
||||
goto error_open;
|
||||
|
||||
if (!WLog_UdpAppender_Open(log, (wLogAppender *)appender))
|
||||
if (!WLog_UdpAppender_Open(log, (wLogAppender*)appender))
|
||||
goto error_open;
|
||||
}
|
||||
else
|
||||
{
|
||||
appender->host = _strdup("127.0.0.1:20000");
|
||||
|
||||
if (!appender->host)
|
||||
goto error_open;
|
||||
}
|
||||
|
||||
return (wLogAppender*)appender;
|
||||
|
||||
error_open:
|
||||
free(appender->host);
|
||||
closesocket(appender->sock);
|
||||
|
Loading…
Reference in New Issue
Block a user