commit
be8f8f7238
1
.gitignore
vendored
1
.gitignore
vendored
@ -20,6 +20,7 @@ LICENSE.txt
|
||||
*Config.cmake
|
||||
*ConfigVersion.cmake
|
||||
include/freerdp/version.h
|
||||
include/freerdp/build-config.h
|
||||
|
||||
*.a.objlist.cmake
|
||||
*.a.objlist
|
||||
|
@ -68,9 +68,9 @@ if ($ENV{BUILD_NUMBER})
|
||||
set(BUILD_NUMBER $ENV{BUILD_NUMBER})
|
||||
endif()
|
||||
set(WITH_LIBRARY_VERSIONING "ON")
|
||||
set(FREERDP_VERSION_MAJOR "1")
|
||||
set(FREERDP_VERSION_MINOR "2")
|
||||
set(FREERDP_VERSION_REVISION "5")
|
||||
set(FREERDP_VERSION_MAJOR "2")
|
||||
set(FREERDP_VERSION_MINOR "0")
|
||||
set(FREERDP_VERSION_REVISION "0")
|
||||
set(FREERDP_VERSION_SUFFIX "dev")
|
||||
set(FREERDP_API_VERSION "${FREERDP_VERSION_MAJOR}.${FREERDP_VERSION_MINOR}")
|
||||
set(FREERDP_VERSION "${FREERDP_API_VERSION}.${FREERDP_VERSION_REVISION}")
|
||||
|
@ -31,6 +31,7 @@
|
||||
#include <winpr/collections.h>
|
||||
|
||||
#include <freerdp/addin.h>
|
||||
#include <freerdp/build-config.h>
|
||||
#include <freerdp/client/channels.h>
|
||||
|
||||
#include "tables.h"
|
||||
@ -181,22 +182,22 @@ FREERDP_ADDIN** freerdp_channels_list_dynamic_addins(LPSTR pszName, LPSTR pszSub
|
||||
|
||||
if (pszName && pszSubsystem && pszType)
|
||||
{
|
||||
sprintf_s(pszPattern, cchPattern, CMAKE_SHARED_LIBRARY_PREFIX"%s-client-%s-%s.%s",
|
||||
sprintf_s(pszPattern, cchPattern, FREERDP_SHARED_LIBRARY_PREFIX"%s-client-%s-%s.%s",
|
||||
pszName, pszSubsystem, pszType, pszExtension);
|
||||
}
|
||||
else if (pszName && pszType)
|
||||
{
|
||||
sprintf_s(pszPattern, cchPattern, CMAKE_SHARED_LIBRARY_PREFIX"%s-client-?-%s.%s",
|
||||
sprintf_s(pszPattern, cchPattern, FREERDP_SHARED_LIBRARY_PREFIX"%s-client-?-%s.%s",
|
||||
pszName, pszType, pszExtension);
|
||||
}
|
||||
else if (pszName)
|
||||
{
|
||||
sprintf_s(pszPattern, cchPattern, CMAKE_SHARED_LIBRARY_PREFIX"%s-client*.%s",
|
||||
sprintf_s(pszPattern, cchPattern, FREERDP_SHARED_LIBRARY_PREFIX"%s-client*.%s",
|
||||
pszName, pszExtension);
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf_s(pszPattern, cchPattern, CMAKE_SHARED_LIBRARY_PREFIX"?-client*.%s",
|
||||
sprintf_s(pszPattern, cchPattern, FREERDP_SHARED_LIBRARY_PREFIX"?-client*.%s",
|
||||
pszExtension);
|
||||
}
|
||||
|
||||
|
@ -633,7 +633,6 @@ static UINT cliprdr_server_receive_format_list(CliprdrServerContext* context, wS
|
||||
WCHAR* wszFormatName;
|
||||
CLIPRDR_FORMAT* formats = NULL;
|
||||
CLIPRDR_FORMAT_LIST formatList;
|
||||
CliprdrServerPrivate* cliprdr = (CliprdrServerPrivate*) context->handle;
|
||||
UINT error = CHANNEL_RC_OK;
|
||||
|
||||
dataLen = header->dataLen;
|
||||
@ -1094,7 +1093,6 @@ static UINT cliprdr_server_init(CliprdrServerContext* context)
|
||||
CLIPRDR_CAPABILITIES capabilities;
|
||||
CLIPRDR_MONITOR_READY monitorReady;
|
||||
CLIPRDR_GENERAL_CAPABILITY_SET generalCapabilitySet;
|
||||
CliprdrServerPrivate* cliprdr = (CliprdrServerPrivate*) context->handle;
|
||||
UINT error;
|
||||
|
||||
ZeroMemory(&capabilities, sizeof(capabilities));
|
||||
|
@ -239,7 +239,7 @@ BOOL xf_GetWindowProperty(xfContext* xfc, Window window, Atom property, int leng
|
||||
|
||||
if (actual_type == None)
|
||||
{
|
||||
WLog_ERR(TAG, "Property %lu does not exist", property);
|
||||
WLog_INFO(TAG, "Property %lu does not exist", property);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
16
config.h.in
16
config.h.in
@ -1,22 +1,6 @@
|
||||
#ifndef __CONFIG_H
|
||||
#define __CONFIG_H
|
||||
|
||||
#define FREERDP_DATA_PATH "${FREERDP_DATA_PATH}"
|
||||
#define FREERDP_KEYMAP_PATH "${FREERDP_KEYMAP_PATH}"
|
||||
#define FREERDP_PLUGIN_PATH "${FREERDP_PLUGIN_PATH}"
|
||||
|
||||
#define FREERDP_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}"
|
||||
|
||||
#define FREERDP_LIBRARY_PATH "${FREERDP_LIBRARY_PATH}"
|
||||
|
||||
#define FREERDP_ADDIN_PATH "${FREERDP_ADDIN_PATH}"
|
||||
|
||||
#define CMAKE_SHARED_LIBRARY_SUFFIX "${CMAKE_SHARED_LIBRARY_SUFFIX}"
|
||||
#define CMAKE_SHARED_LIBRARY_PREFIX "${CMAKE_SHARED_LIBRARY_PREFIX}"
|
||||
|
||||
#define FREERDP_VENDOR_STRING "${VENDOR}"
|
||||
#define FREERDP_PRODUCT_STRING "${PRODUCT}"
|
||||
|
||||
/* Include files */
|
||||
#cmakedefine HAVE_FCNTL_H
|
||||
#cmakedefine HAVE_UNISTD_H
|
||||
|
151
docs/wlog.md
Normal file
151
docs/wlog.md
Normal file
@ -0,0 +1,151 @@
|
||||
# Overview
|
||||
|
||||
WLog is a configurable and flexible logging system used throughout winpr and
|
||||
FreeRDP.
|
||||
|
||||
The primary concept is to have a hierarchy of loggers that can be be configured
|
||||
independently.
|
||||
|
||||
TODO add more details and configuration examples.
|
||||
|
||||
|
||||
|
||||
# Environment variables
|
||||
|
||||
* WLOG_APPENDER - the appender to use possible values below also see the Appender section.
|
||||
* CONSOLE
|
||||
* FILE
|
||||
* BINARY
|
||||
* SYSLOG
|
||||
* JOURNALD
|
||||
* UDP
|
||||
* WLOG_PREFIX - configure the prefix used for outputting the message (see
|
||||
Format for more details and examples)
|
||||
* WLOG_LEVEL - the level to output messages for
|
||||
* WLOG_FILTER - sets a filter for WLog messages. Only the filtered messages are
|
||||
printed
|
||||
* WLOG_FILEAPPENDER_OUTPUT_FILE_PATH - set the output file path for the file
|
||||
file appender
|
||||
* WLOG_FILEAPPENDER_OUTPUT_FILE_NAME - set the output file name for the output
|
||||
appender
|
||||
* WLOG_JOURNALD_ID - identifier used by the journal appender
|
||||
* WLOG_UDP_TARGET - target to use for the UDP appender in the format host:port
|
||||
|
||||
# Levels
|
||||
|
||||
The WLog are complementary the higher level always includes the lower ones.
|
||||
The level list below is top down. Top the highest level.
|
||||
|
||||
* WLOG_TRACE - print everything including package dumps
|
||||
* WLOG_DEBUG - debug messages
|
||||
* WLOG_INFO - general informations
|
||||
* WLOG_WARN - warnings
|
||||
* WLOG_ERROR - errors
|
||||
* WLOG_FATAL - fatal problems
|
||||
* WLOG_OFF - completely disable the wlog output
|
||||
|
||||
|
||||
# Format
|
||||
|
||||
The format a logger prints in has the following possible options:
|
||||
|
||||
* "lv" - log level
|
||||
* "mn" - module name
|
||||
* "fl" - file name
|
||||
* "fn" - function
|
||||
* "ln" - line number
|
||||
* "pid" - process id
|
||||
* "tid" - thread id
|
||||
* "yr" - year
|
||||
* "mo" - month
|
||||
* "dw" - day of week
|
||||
* "hr" - hour
|
||||
* "mi" - minute
|
||||
* "se" - second
|
||||
* "ml" - millisecond
|
||||
|
||||
A maximum of 16 options can be used per format string.
|
||||
|
||||
An example that generally sets the WLOG_PREFIX for xfreerdp would look like:
|
||||
```
|
||||
WLOG_PREFIX="pid=%pid:tid=%tid:fn=%fn -" xfreerdp /v:xxx
|
||||
```
|
||||
|
||||
# Appenders
|
||||
|
||||
WLog uses different appenders that define where the log output should be written
|
||||
to. If the application doesn't explicitly configure the appenders the above
|
||||
described variable WLOG_APPENDER can be used to choose one appender.
|
||||
|
||||
The following represents an overview about all appenders and their possible
|
||||
configuration values.
|
||||
|
||||
### Binary
|
||||
|
||||
Write the log data into a binary format file.
|
||||
|
||||
Options:
|
||||
* "outputfilename", value const char* - file to write the data to
|
||||
* "outputfilepath", value const char* - location of the output file
|
||||
|
||||
### Callback
|
||||
The callback appender can be used from an application to get all log messages
|
||||
back the application. For example if an application wants to handle the log
|
||||
output itself.
|
||||
|
||||
Options:
|
||||
|
||||
* "callbacks", value struct wLogCallbacks*, callbacks to use
|
||||
|
||||
### Console
|
||||
|
||||
The console appender writes to the console. Depending of the operating system
|
||||
the application runs on the output might be handled differently. For example
|
||||
on android log print would be used.
|
||||
|
||||
Options:
|
||||
|
||||
|
||||
* "outputstream", value const char * - output stream to write to
|
||||
* "stdout" - write everything to stdout
|
||||
* "stderr" - write everything to stderr
|
||||
* "default" - use the default settings - in this case errors and fatal would
|
||||
go to stderr everything else to stdout
|
||||
* debug - use the debug output. Only used on windows on all operating systems
|
||||
this behaves as as if default was set.
|
||||
|
||||
### File
|
||||
The file appender writes the textual output to a file.
|
||||
|
||||
Options:
|
||||
|
||||
* "outputfilename", value const char*, filename to use
|
||||
* "outputfilepath", value const char*, location of the file
|
||||
|
||||
### Udp
|
||||
|
||||
This appender sends the logging messages to a pre-defined remote host via UDP.
|
||||
|
||||
Options:
|
||||
|
||||
* "target", value const char*, target to send the data too in the format
|
||||
host:port
|
||||
|
||||
If no target is set the default one 127.0.0.1:20000 is used. To receive the
|
||||
log messages one can use netcat. To receive the default target the following
|
||||
command could be used.
|
||||
```
|
||||
nc -u 127.0.0.1 -p 20000 -l
|
||||
```
|
||||
|
||||
### Syslog (optional)
|
||||
|
||||
Use syslog for outputting the debug messages. No options available.
|
||||
|
||||
### Journald (optional)
|
||||
|
||||
For outputting the log messages to journald this appender can be used.
|
||||
The available options are:
|
||||
|
||||
* "identifier", value const char*, the identifier to use for journald (default
|
||||
is winpr)
|
@ -18,10 +18,12 @@
|
||||
# limitations under the License.
|
||||
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/freerdp/version.h.in ${CMAKE_CURRENT_BINARY_DIR}/freerdp/version.h)
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/freerdp/build-config.h.in ${CMAKE_CURRENT_BINARY_DIR}/freerdp/build-config.h)
|
||||
|
||||
file(GLOB FREERDP_HEADERS "freerdp/*.h")
|
||||
install(FILES ${FREERDP_HEADERS} DESTINATION include/freerdp COMPONENT headers)
|
||||
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/freerdp/version.h DESTINATION include/freerdp COMPONENT headers)
|
||||
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/freerdp/build-config.h DESTINATION include/freerdp COMPONENT headers)
|
||||
|
||||
install(DIRECTORY freerdp/cache DESTINATION include/freerdp COMPONENT headers FILES_MATCHING PATTERN "*.h")
|
||||
install(DIRECTORY freerdp/codec DESTINATION include/freerdp COMPONENT headers FILES_MATCHING PATTERN "*.h")
|
||||
|
20
include/freerdp/build-config.h.in
Normal file
20
include/freerdp/build-config.h.in
Normal file
@ -0,0 +1,20 @@
|
||||
#ifndef FREERDP_BUILD_CONFIG_H
|
||||
#define FREERDP_BUILD_CONFIG_H
|
||||
|
||||
#define FREERDP_DATA_PATH "${FREERDP_DATA_PATH}"
|
||||
#define FREERDP_KEYMAP_PATH "${FREERDP_KEYMAP_PATH}"
|
||||
#define FREERDP_PLUGIN_PATH "${FREERDP_PLUGIN_PATH}"
|
||||
|
||||
#define FREERDP_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}"
|
||||
|
||||
#define FREERDP_LIBRARY_PATH "${FREERDP_LIBRARY_PATH}"
|
||||
|
||||
#define FREERDP_ADDIN_PATH "${FREERDP_ADDIN_PATH}"
|
||||
|
||||
#define FREERDP_SHARED_LIBRARY_SUFFIX "${CMAKE_SHARED_LIBRARY_SUFFIX}"
|
||||
#define FREERDP_SHARED_LIBRARY_PREFIX "${CMAKE_SHARED_LIBRARY_PREFIX}"
|
||||
|
||||
#define FREERDP_VENDOR_STRING "${VENDOR}"
|
||||
#define FREERDP_PRODUCT_STRING "${PRODUCT}"
|
||||
|
||||
#endif /* FREERDP_BUILD_CONFIG_H */
|
@ -43,6 +43,7 @@
|
||||
#include <freerdp/constants.h>
|
||||
#include <freerdp/primitives.h>
|
||||
#include <freerdp/codec/region.h>
|
||||
#include <freerdp/build-config.h>
|
||||
|
||||
#include "rfx_constants.h"
|
||||
#include "rfx_types.h"
|
||||
|
@ -694,7 +694,6 @@ static int test_norbert2_case() {
|
||||
int retCode = -1;
|
||||
const RECTANGLE_16 *rects;
|
||||
int nbRects = 0;
|
||||
int i;
|
||||
RECTANGLE_16 rect1 = { 464, 696, 476, 709 };
|
||||
RECTANGLE_16 rect2 = { 0, 0, 1024, 32 };
|
||||
|
||||
|
@ -30,6 +30,7 @@
|
||||
#include <winpr/library.h>
|
||||
|
||||
#include <freerdp/addin.h>
|
||||
#include <freerdp/build-config.h>
|
||||
|
||||
|
||||
LPSTR freerdp_get_library_install_path()
|
||||
@ -143,7 +144,7 @@ void* freerdp_load_dynamic_addin(LPCSTR pszFileName, LPCSTR pszPath, LPCSTR pszE
|
||||
}
|
||||
else
|
||||
{
|
||||
cchAddinFile = cchFileName + cchExt + 2 + sizeof(CMAKE_SHARED_LIBRARY_PREFIX);
|
||||
cchAddinFile = cchFileName + cchExt + 2 + sizeof(FREERDP_SHARED_LIBRARY_PREFIX);
|
||||
pszAddinFile = (LPSTR) malloc(cchAddinFile + 1);
|
||||
if (!pszAddinFile)
|
||||
{
|
||||
@ -151,7 +152,7 @@ void* freerdp_load_dynamic_addin(LPCSTR pszFileName, LPCSTR pszPath, LPCSTR pszE
|
||||
free(pszFilePath);
|
||||
return NULL;
|
||||
}
|
||||
sprintf_s(pszAddinFile, cchAddinFile, CMAKE_SHARED_LIBRARY_PREFIX"%s%s", pszFileName, pszExt);
|
||||
sprintf_s(pszAddinFile, cchAddinFile, FREERDP_SHARED_LIBRARY_PREFIX"%s%s", pszFileName, pszExt);
|
||||
cchAddinFile = strlen(pszAddinFile);
|
||||
}
|
||||
|
||||
@ -182,9 +183,9 @@ void* freerdp_load_dynamic_channel_addin_entry(LPCSTR pszName, LPSTR pszSubsyste
|
||||
{
|
||||
void* entry;
|
||||
LPSTR pszFileName;
|
||||
size_t cchFileName = sizeof(CMAKE_SHARED_LIBRARY_PREFIX) + 32;
|
||||
size_t cchFileName = sizeof(FREERDP_SHARED_LIBRARY_PREFIX) + 32;
|
||||
LPCSTR pszExtension;
|
||||
LPCSTR pszPrefix = CMAKE_SHARED_LIBRARY_PREFIX;
|
||||
LPCSTR pszPrefix = FREERDP_SHARED_LIBRARY_PREFIX;
|
||||
|
||||
pszExtension = PathGetSharedLibraryExtensionA(0);
|
||||
|
||||
|
@ -31,6 +31,7 @@
|
||||
|
||||
#include <freerdp/log.h>
|
||||
#include <freerdp/crypto/tls.h>
|
||||
#include <freerdp/build-config.h>
|
||||
|
||||
#include <winpr/crt.h>
|
||||
#include <winpr/sam.h>
|
||||
|
@ -37,6 +37,7 @@
|
||||
#include <winpr/registry.h>
|
||||
|
||||
#include <freerdp/settings.h>
|
||||
#include <freerdp/build-config.h>
|
||||
#include <ctype.h>
|
||||
|
||||
|
||||
|
@ -23,6 +23,8 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <freerdp/build-config.h>
|
||||
|
||||
#include <winpr/tchar.h>
|
||||
#include <winpr/windows.h>
|
||||
|
||||
|
@ -31,6 +31,7 @@
|
||||
#include <freerdp/constants.h>
|
||||
#include <freerdp/channels/wtsvc.h>
|
||||
#include <freerdp/channels/channels.h>
|
||||
#include <freerdp/build-config.h>
|
||||
|
||||
#include "wf_peer.h"
|
||||
#include "wf_settings.h"
|
||||
|
@ -28,6 +28,7 @@
|
||||
|
||||
#include <freerdp/listener.h>
|
||||
#include <freerdp/codec/rfx.h>
|
||||
#include <freerdp/build-config.h>
|
||||
|
||||
#include "wf_info.h"
|
||||
#include "wf_input.h"
|
||||
|
@ -3,6 +3,9 @@
|
||||
* WinPR Logger
|
||||
*
|
||||
* Copyright 2013 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
||||
* Copyright 2015 Thincast Technologies GmbH
|
||||
* Copyright 2015 Bernhard Miklautz <bernhard.miklautz@thincast.com>
|
||||
*
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -24,42 +27,40 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#include <winpr/winpr.h>
|
||||
#include <winpr/wtypes.h>
|
||||
|
||||
#include <winpr/synch.h>
|
||||
#include <winpr/thread.h>
|
||||
#include <winpr/winsock.h>
|
||||
|
||||
typedef struct _wLog wLog;
|
||||
typedef struct _wLogMessage wLogMessage;
|
||||
typedef struct _wLogLayout wLogLayout;
|
||||
typedef struct _wLogAppender wLogAppender;
|
||||
|
||||
/**
|
||||
* Log Levels
|
||||
*/
|
||||
|
||||
#define WLOG_TRACE 0
|
||||
#define WLOG_DEBUG 1
|
||||
#define WLOG_INFO 2
|
||||
#define WLOG_WARN 3
|
||||
#define WLOG_ERROR 4
|
||||
#define WLOG_FATAL 5
|
||||
#define WLOG_OFF 6
|
||||
#define WLOG_TRACE 0
|
||||
#define WLOG_DEBUG 1
|
||||
#define WLOG_INFO 2
|
||||
#define WLOG_WARN 3
|
||||
#define WLOG_ERROR 4
|
||||
#define WLOG_FATAL 5
|
||||
#define WLOG_OFF 6
|
||||
#define WLOG_LEVEL_INHERIT 0xFFFF
|
||||
|
||||
/**
|
||||
* Log Message
|
||||
*/
|
||||
#define WLOG_MESSAGE_TEXT 0
|
||||
#define WLOG_MESSAGE_DATA 1
|
||||
#define WLOG_MESSAGE_IMAGE 2
|
||||
#define WLOG_MESSAGE_PACKET 3
|
||||
|
||||
#define WLOG_MESSAGE_TEXT 0
|
||||
#define WLOG_MESSAGE_DATA 1
|
||||
#define WLOG_MESSAGE_IMAGE 2
|
||||
#define WLOG_MESSAGE_PACKET 3
|
||||
/**
|
||||
* Log Appenders
|
||||
*/
|
||||
#define WLOG_APPENDER_CONSOLE 0
|
||||
#define WLOG_APPENDER_FILE 1
|
||||
#define WLOG_APPENDER_BINARY 2
|
||||
#define WLOG_APPENDER_CALLBACK 3
|
||||
#define WLOG_APPENDER_SYSLOG 4
|
||||
#define WLOG_APPENDER_JOURNALD 5
|
||||
#define WLOG_APPENDER_UDP 6
|
||||
|
||||
struct _wLogMessage
|
||||
{
|
||||
@ -94,169 +95,13 @@ struct _wLogMessage
|
||||
int PacketLength;
|
||||
DWORD PacketFlags;
|
||||
};
|
||||
typedef struct _wLogMessage wLogMessage;
|
||||
typedef struct _wLogLayout wLogLayout;
|
||||
typedef struct _wLogAppender wLogAppender;
|
||||
typedef struct _wLog wLog;
|
||||
|
||||
/**
|
||||
* Log Layout
|
||||
*/
|
||||
|
||||
struct _wLogLayout
|
||||
{
|
||||
DWORD Type;
|
||||
|
||||
LPSTR FormatString;
|
||||
};
|
||||
|
||||
/**
|
||||
* Log Appenders
|
||||
*/
|
||||
|
||||
#define WLOG_APPENDER_CONSOLE 0
|
||||
#define WLOG_APPENDER_FILE 1
|
||||
#define WLOG_APPENDER_BINARY 2
|
||||
#define WLOG_APPENDER_CALLBACK 3
|
||||
#define WLOG_APPENDER_SYSLOG 4
|
||||
#define WLOG_APPENDER_JOURNALD 5
|
||||
#define WLOG_APPENDER_UDP 6
|
||||
|
||||
#define WLOG_PACKET_INBOUND 1
|
||||
#define WLOG_PACKET_OUTBOUND 2
|
||||
|
||||
typedef BOOL (*WLOG_APPENDER_OPEN_FN)(wLog* log, wLogAppender* appender);
|
||||
typedef BOOL (*WLOG_APPENDER_CLOSE_FN)(wLog* log, wLogAppender* appender);
|
||||
typedef BOOL (*WLOG_APPENDER_WRITE_MESSAGE_FN)(wLog* log, wLogAppender* appender, wLogMessage* message);
|
||||
typedef BOOL (*WLOG_APPENDER_WRITE_DATA_MESSAGE_FN)(wLog* log, wLogAppender* appender, wLogMessage* message);
|
||||
typedef BOOL (*WLOG_APPENDER_WRITE_IMAGE_MESSAGE_FN)(wLog* log, wLogAppender* appender, wLogMessage* message);
|
||||
typedef BOOL (*WLOG_APPENDER_WRITE_PACKET_MESSAGE_FN)(wLog* log, wLogAppender* appender, wLogMessage* message);
|
||||
|
||||
#define WLOG_APPENDER_COMMON() \
|
||||
DWORD Type; \
|
||||
DWORD State; \
|
||||
wLogLayout* Layout; \
|
||||
CRITICAL_SECTION lock; \
|
||||
BOOL recursive; \
|
||||
void* TextMessageContext; \
|
||||
void* DataMessageContext; \
|
||||
void* ImageMessageContext; \
|
||||
void* PacketMessageContext; \
|
||||
WLOG_APPENDER_OPEN_FN Open; \
|
||||
WLOG_APPENDER_CLOSE_FN Close; \
|
||||
WLOG_APPENDER_WRITE_MESSAGE_FN WriteMessage; \
|
||||
WLOG_APPENDER_WRITE_DATA_MESSAGE_FN WriteDataMessage; \
|
||||
WLOG_APPENDER_WRITE_IMAGE_MESSAGE_FN WriteImageMessage; \
|
||||
WLOG_APPENDER_WRITE_PACKET_MESSAGE_FN WritePacketMessage
|
||||
|
||||
struct _wLogAppender
|
||||
{
|
||||
WLOG_APPENDER_COMMON();
|
||||
};
|
||||
|
||||
#define WLOG_CONSOLE_DEFAULT 0
|
||||
#define WLOG_CONSOLE_STDOUT 1
|
||||
#define WLOG_CONSOLE_STDERR 2
|
||||
#define WLOG_CONSOLE_DEBUG 4
|
||||
|
||||
struct _wLogConsoleAppender
|
||||
{
|
||||
WLOG_APPENDER_COMMON();
|
||||
|
||||
int outputStream;
|
||||
};
|
||||
typedef struct _wLogConsoleAppender wLogConsoleAppender;
|
||||
|
||||
struct _wLogFileAppender
|
||||
{
|
||||
WLOG_APPENDER_COMMON();
|
||||
|
||||
char* FileName;
|
||||
char* FilePath;
|
||||
char* FullFileName;
|
||||
FILE* FileDescriptor;
|
||||
};
|
||||
typedef struct _wLogFileAppender wLogFileAppender;
|
||||
|
||||
struct _wLogBinaryAppender
|
||||
{
|
||||
WLOG_APPENDER_COMMON();
|
||||
|
||||
char* FileName;
|
||||
char* FilePath;
|
||||
char* FullFileName;
|
||||
FILE* FileDescriptor;
|
||||
};
|
||||
typedef struct _wLogBinaryAppender wLogBinaryAppender;
|
||||
|
||||
typedef BOOL (*CallbackAppenderMessage_t)(const wLogMessage *msg);
|
||||
typedef BOOL (*CallbackAppenderData_t)(const wLogMessage *msg);
|
||||
typedef BOOL (*CallbackAppenderImage_t)(const wLogMessage *msg);
|
||||
typedef BOOL (*CallbackAppenderPackage_t)(const wLogMessage *msg);
|
||||
|
||||
struct _wLogCallbackAppender
|
||||
{
|
||||
WLOG_APPENDER_COMMON();
|
||||
|
||||
CallbackAppenderMessage_t message;
|
||||
CallbackAppenderData_t data;
|
||||
CallbackAppenderImage_t image;
|
||||
CallbackAppenderPackage_t package;
|
||||
};
|
||||
typedef struct _wLogCallbackAppender wLogCallbackAppender;
|
||||
|
||||
struct _wLogSyslogAppender
|
||||
{
|
||||
WLOG_APPENDER_COMMON();
|
||||
};
|
||||
typedef struct _wLogSyslogAppender wLogSyslogAppender;
|
||||
|
||||
struct _wLogJournaldAppender
|
||||
{
|
||||
WLOG_APPENDER_COMMON();
|
||||
char *identifier;
|
||||
FILE *stream;
|
||||
};
|
||||
typedef struct _wLogJournaldAppender wLogJournaldAppender;
|
||||
|
||||
struct _wLogUdpAppender
|
||||
{
|
||||
WLOG_APPENDER_COMMON();
|
||||
char *host;
|
||||
struct sockaddr targetAddr;
|
||||
int targetAddrLen;
|
||||
SOCKET sock;
|
||||
};
|
||||
typedef struct _wLogUdpAppender wLogUdpAppender;
|
||||
|
||||
|
||||
/**
|
||||
* Filter
|
||||
*/
|
||||
|
||||
struct _wLogFilter
|
||||
{
|
||||
DWORD Level;
|
||||
LPSTR* Names;
|
||||
DWORD NameCount;
|
||||
};
|
||||
typedef struct _wLogFilter wLogFilter;
|
||||
|
||||
/**
|
||||
* Logger
|
||||
*/
|
||||
|
||||
struct _wLog
|
||||
{
|
||||
LPSTR Name;
|
||||
DWORD Level;
|
||||
|
||||
BOOL IsRoot;
|
||||
LPSTR* Names;
|
||||
DWORD NameCount;
|
||||
wLogAppender* Appender;
|
||||
|
||||
wLog* Parent;
|
||||
wLog** Children;
|
||||
DWORD ChildrenCount;
|
||||
DWORD ChildrenSize;
|
||||
};
|
||||
#define WLOG_PACKET_INBOUND 1
|
||||
#define WLOG_PACKET_OUTBOUND 2
|
||||
|
||||
WINPR_API BOOL WLog_PrintMessage(wLog* log, wLogMessage* message, ...);
|
||||
WINPR_API BOOL WLog_PrintMessageVA(wLog* log, wLogMessage* message, va_list args);
|
||||
@ -345,20 +190,11 @@ WINPR_API BOOL WLog_PrintMessageVA(wLog* log, wLogMessage* message, va_list args
|
||||
WINPR_API DWORD WLog_GetLogLevel(wLog* log);
|
||||
WINPR_API BOOL WLog_SetLogLevel(wLog* log, DWORD logLevel);
|
||||
|
||||
WINPR_API wLogAppender* WLog_GetLogAppender(wLog* log);
|
||||
WINPR_API BOOL WLog_SetLogAppenderType(wLog* log, DWORD logAppenderType);
|
||||
|
||||
WINPR_API wLogAppender* WLog_GetLogAppender(wLog* log);
|
||||
WINPR_API BOOL WLog_OpenAppender(wLog* log);
|
||||
WINPR_API BOOL WLog_CloseAppender(wLog* log);
|
||||
|
||||
WINPR_API BOOL WLog_ConsoleAppender_SetOutputStream(wLog* log, wLogConsoleAppender* appender, int outputStream);
|
||||
|
||||
WINPR_API BOOL WLog_FileAppender_SetOutputFileName(wLog* log, wLogFileAppender* appender, const char* filename);
|
||||
WINPR_API BOOL WLog_FileAppender_SetOutputFilePath(wLog* log, wLogFileAppender* appender, const char* filepath);
|
||||
|
||||
WINPR_API BOOL WLog_CallbackAppender_SetCallbacks(wLog* log, wLogCallbackAppender* appender,
|
||||
CallbackAppenderMessage_t msg, CallbackAppenderImage_t img, CallbackAppenderPackage_t pkg,
|
||||
CallbackAppenderData_t data);
|
||||
WINPR_API BOOL WLog_ConfigureAppender(wLogAppender *appender, const char *setting, void *value);
|
||||
|
||||
WINPR_API wLogLayout* WLog_GetLogLayout(wLog* log);
|
||||
WINPR_API BOOL WLog_Layout_SetPrefixFormat(wLog* log, wLogLayout* layout, const char* format);
|
||||
@ -369,6 +205,19 @@ WINPR_API wLog* WLog_Get(LPCSTR name);
|
||||
WINPR_API BOOL WLog_Init(void);
|
||||
WINPR_API BOOL WLog_Uninit(void);
|
||||
|
||||
typedef BOOL (*wLogCallbackMessage_t)(const wLogMessage *msg);
|
||||
typedef BOOL (*wLogCallbackData_t)(const wLogMessage *msg);
|
||||
typedef BOOL (*wLogCallbackImage_t)(const wLogMessage *msg);
|
||||
typedef BOOL (*wLogCallbackPackage_t)(const wLogMessage *msg);
|
||||
|
||||
struct _wLogCallbacks {
|
||||
wLogCallbackData_t data;
|
||||
wLogCallbackImage_t image;
|
||||
wLogCallbackMessage_t message;
|
||||
wLogCallbackPackage_t package;
|
||||
};
|
||||
typedef struct _wLogCallbacks wLogCallbacks;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -20,6 +20,7 @@
|
||||
*/
|
||||
|
||||
#include <winpr/file.h>
|
||||
#include <winpr/handle.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
@ -44,4 +45,4 @@ int TestFileGetStdHandle(int argc, char* argv[])
|
||||
CloseHandle(stdout);
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@ -1269,7 +1269,7 @@ SCardApiFunctionTable Inspect_SCardApiFunctionTable =
|
||||
void Inspect_InitLog()
|
||||
{
|
||||
wLogLayout* layout;
|
||||
wLogFileAppender* appender;
|
||||
wLogAppender* appender;
|
||||
const char* filepath = SMARTCARD_INSPECT_FILEPATH;
|
||||
|
||||
if (g_Log)
|
||||
@ -1284,10 +1284,12 @@ void Inspect_InitLog()
|
||||
|
||||
WLog_SetLogLevel(g_Log, WLOG_DEBUG);
|
||||
WLog_SetLogAppenderType(g_Log, WLOG_APPENDER_FILE);
|
||||
appender = (wLogFileAppender*) WLog_GetLogAppender(g_Log);
|
||||
appender = WLog_GetLogAppender(g_Log);
|
||||
if (!appender)
|
||||
return;
|
||||
|
||||
WLog_FileAppender_SetOutputFileName(g_Log, appender, "WinSCard.txt");
|
||||
WLog_FileAppender_SetOutputFilePath(g_Log, appender, filepath);
|
||||
WLog_ConfigureAppender(appender, "outputfilename", "WinSCard.txt");
|
||||
WLog_ConfigureAppender(appender, "outputfilepath", (void *)filepath);
|
||||
|
||||
layout = WLog_GetLogLayout(g_Log);
|
||||
WLog_Layout_SetPrefixFormat(g_Log, layout, "[%mn] ");
|
||||
|
@ -27,6 +27,7 @@
|
||||
#include <winpr/tchar.h>
|
||||
#include <winpr/sysinfo.h>
|
||||
#include <winpr/registry.h>
|
||||
#include <freerdp/build-config.h>
|
||||
|
||||
#include "ntlm.h"
|
||||
#include "../sspi.h"
|
||||
|
@ -91,7 +91,6 @@
|
||||
LPSTR* CommandLineToArgvA(LPCSTR lpCmdLine, int* pNumArgs)
|
||||
{
|
||||
char* p;
|
||||
int index;
|
||||
int length;
|
||||
char* pBeg;
|
||||
char* pEnd;
|
||||
|
@ -77,7 +77,6 @@ set(${MODULE_PREFIX}_WLOG_SRCS
|
||||
wlog/Message.c
|
||||
wlog/Message.h
|
||||
wlog/TextMessage.c
|
||||
wlog/TextMessage.h
|
||||
wlog/DataMessage.c
|
||||
wlog/DataMessage.h
|
||||
wlog/ImageMessage.c
|
||||
|
@ -70,7 +70,7 @@ WINPR_SAM* SamOpen(BOOL read_only)
|
||||
sam->fp = fp;
|
||||
}
|
||||
else
|
||||
WLog_ERR(TAG, "Could not open SAM file!");
|
||||
WLog_DBG(TAG, "Could not open SAM file!");
|
||||
|
||||
return sam;
|
||||
}
|
||||
|
@ -19,7 +19,10 @@ int TestWLog(int argc, char* argv[])
|
||||
WLog_SetLogAppenderType(root, WLOG_APPENDER_BINARY);
|
||||
|
||||
appender = WLog_GetLogAppender(root);
|
||||
WLog_ConsoleAppender_SetOutputStream(root, (wLogConsoleAppender*) appender, WLOG_CONSOLE_STDERR);
|
||||
if(!WLog_ConfigureAppender(appender, "outputfilename", "test_w.log"))
|
||||
return 1;
|
||||
if(!WLog_ConfigureAppender(appender, "outputfilepath", "/tmp/"))
|
||||
return 1;
|
||||
|
||||
layout = WLog_GetLogLayout(root);
|
||||
WLog_Layout_SetPrefixFormat(root, layout, "[%lv:%mn] [%fl|%fn|%ln] - ");
|
||||
|
@ -90,6 +90,7 @@ int TestWLogCallback(int argc, char* argv[])
|
||||
wLog* logB;
|
||||
wLogLayout* layout;
|
||||
wLogAppender* appender;
|
||||
wLogCallbacks callbacks;
|
||||
|
||||
function = __FUNCTION__;
|
||||
WLog_Init();
|
||||
@ -100,9 +101,13 @@ int TestWLogCallback(int argc, char* argv[])
|
||||
|
||||
appender = WLog_GetLogAppender(root);
|
||||
|
||||
WLog_CallbackAppender_SetCallbacks(root, (wLogCallbackAppender*) appender,
|
||||
CallbackAppenderMessage, CallbackAppenderImage, CallbackAppenderPackage,
|
||||
CallbackAppenderData);
|
||||
callbacks.data = CallbackAppenderData;
|
||||
callbacks.image = CallbackAppenderImage;
|
||||
callbacks.message = CallbackAppenderMessage;
|
||||
callbacks.package = CallbackAppenderPackage;
|
||||
|
||||
if (!WLog_ConfigureAppender(appender, "callbacks", (void *)&callbacks))
|
||||
return -1;
|
||||
|
||||
layout = WLog_GetLogLayout(root);
|
||||
WLog_Layout_SetPrefixFormat(root, layout, "%mn");
|
||||
|
@ -21,11 +21,77 @@
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <winpr/wlog.h>
|
||||
#include "Appender.h"
|
||||
|
||||
#include "wlog/Layout.h"
|
||||
void WLog_Appender_Free(wLog* log, wLogAppender* appender)
|
||||
{
|
||||
if (!appender)
|
||||
return;
|
||||
|
||||
#include "wlog/Appender.h"
|
||||
if (appender->Layout)
|
||||
{
|
||||
WLog_Layout_Free(log, appender->Layout);
|
||||
appender->Layout = NULL;
|
||||
}
|
||||
|
||||
DeleteCriticalSection(&appender->lock);
|
||||
appender->Free(appender);
|
||||
}
|
||||
|
||||
wLogAppender* WLog_GetLogAppender(wLog* log)
|
||||
{
|
||||
if (!log)
|
||||
return NULL;
|
||||
|
||||
if (!log->Appender)
|
||||
return WLog_GetLogAppender(log->Parent);
|
||||
|
||||
return log->Appender;
|
||||
}
|
||||
|
||||
BOOL WLog_OpenAppender(wLog* log)
|
||||
{
|
||||
int status = 0;
|
||||
wLogAppender* appender;
|
||||
|
||||
appender = WLog_GetLogAppender(log);
|
||||
|
||||
if (!appender)
|
||||
return FALSE;
|
||||
|
||||
if (!appender->Open)
|
||||
return TRUE;
|
||||
|
||||
if (!appender->active)
|
||||
{
|
||||
status = appender->Open(log, appender);
|
||||
appender->active = TRUE;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
BOOL WLog_CloseAppender(wLog* log)
|
||||
{
|
||||
int status = 0;
|
||||
wLogAppender* appender;
|
||||
|
||||
appender = WLog_GetLogAppender(log);
|
||||
|
||||
if (!appender)
|
||||
return FALSE;
|
||||
|
||||
if (!appender->Close)
|
||||
return TRUE;
|
||||
|
||||
if (appender->active)
|
||||
{
|
||||
status = appender->Close(log, appender);
|
||||
appender->active = FALSE;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
wLogAppender* WLog_Appender_New(wLog* log, DWORD logAppenderType)
|
||||
{
|
||||
@ -37,25 +103,25 @@ wLogAppender* WLog_Appender_New(wLog* log, DWORD logAppenderType)
|
||||
switch (logAppenderType)
|
||||
{
|
||||
case WLOG_APPENDER_CONSOLE:
|
||||
appender = (wLogAppender*) WLog_ConsoleAppender_New(log);
|
||||
appender = WLog_ConsoleAppender_New(log);
|
||||
break;
|
||||
case WLOG_APPENDER_FILE:
|
||||
appender = (wLogAppender*) WLog_FileAppender_New(log);
|
||||
appender = WLog_FileAppender_New(log);
|
||||
break;
|
||||
case WLOG_APPENDER_BINARY:
|
||||
appender = (wLogAppender*) WLog_BinaryAppender_New(log);
|
||||
appender = WLog_BinaryAppender_New(log);
|
||||
break;
|
||||
case WLOG_APPENDER_CALLBACK:
|
||||
appender = (wLogAppender*) WLog_CallbackAppender_New(log);
|
||||
appender = WLog_CallbackAppender_New(log);
|
||||
break;
|
||||
#ifdef HAVE_SYSLOG_H
|
||||
case WLOG_APPENDER_SYSLOG:
|
||||
appender = (wLogAppender*) WLog_SyslogAppender_New(log);
|
||||
appender = WLog_SyslogAppender_New(log);
|
||||
break;
|
||||
#endif
|
||||
#ifdef HAVE_JOURNALD_H
|
||||
case WLOG_APPENDER_JOURNALD:
|
||||
appender = (wLogAppender*) WLog_JournaldAppender_New(log);
|
||||
appender = WLog_JournaldAppender_New(log);
|
||||
break;
|
||||
#endif
|
||||
case WLOG_APPENDER_UDP:
|
||||
@ -84,65 +150,11 @@ wLogAppender* WLog_Appender_New(wLog* log, DWORD logAppenderType)
|
||||
return appender;
|
||||
}
|
||||
|
||||
void WLog_Appender_Free(wLog* log, wLogAppender* appender)
|
||||
{
|
||||
if (!appender)
|
||||
return;
|
||||
|
||||
if (appender->Layout)
|
||||
{
|
||||
WLog_Layout_Free(log, appender->Layout);
|
||||
appender->Layout = NULL;
|
||||
}
|
||||
|
||||
DeleteCriticalSection(&appender->lock);
|
||||
|
||||
switch (appender->Type)
|
||||
{
|
||||
case WLOG_APPENDER_CONSOLE:
|
||||
WLog_ConsoleAppender_Free(log, (wLogConsoleAppender*) appender);
|
||||
break;
|
||||
case WLOG_APPENDER_FILE:
|
||||
WLog_FileAppender_Free(log, (wLogFileAppender*) appender);
|
||||
break;
|
||||
case WLOG_APPENDER_BINARY:
|
||||
WLog_BinaryAppender_Free(log, (wLogBinaryAppender*) appender);
|
||||
break;
|
||||
case WLOG_APPENDER_CALLBACK:
|
||||
WLog_CallbackAppender_Free(log, (wLogCallbackAppender*) appender);
|
||||
break;
|
||||
#ifdef HAVE_SYSLOG_H
|
||||
case WLOG_APPENDER_SYSLOG:
|
||||
WLog_SyslogAppender_Free(log, (wLogSyslogAppender *) appender);
|
||||
break;
|
||||
#endif
|
||||
#ifdef HAVE_JOURNALD_H
|
||||
case WLOG_APPENDER_JOURNALD:
|
||||
WLog_JournaldAppender_Free(log, (wLogJournaldAppender *) appender);
|
||||
break;
|
||||
#endif
|
||||
case WLOG_APPENDER_UDP:
|
||||
WLog_UdpAppender_Free(log, (wLogUdpAppender *) appender);
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "%s: don't know how to free appender type %d\n", __FUNCTION__, appender->Type);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
wLogAppender* WLog_GetLogAppender(wLog* log)
|
||||
{
|
||||
if (!log)
|
||||
return NULL;
|
||||
|
||||
if (!log->Appender)
|
||||
return WLog_GetLogAppender(log->Parent);
|
||||
|
||||
return log->Appender;
|
||||
}
|
||||
|
||||
BOOL WLog_SetLogAppenderType(wLog* log, DWORD logAppenderType)
|
||||
{
|
||||
if (!log)
|
||||
return FALSE;
|
||||
|
||||
if (log->Appender)
|
||||
{
|
||||
WLog_Appender_Free(log, log->Appender);
|
||||
@ -153,46 +165,14 @@ BOOL WLog_SetLogAppenderType(wLog* log, DWORD logAppenderType)
|
||||
return log->Appender != NULL;
|
||||
}
|
||||
|
||||
BOOL WLog_OpenAppender(wLog* log)
|
||||
BOOL WLog_ConfigureAppender(wLogAppender *appender, const char *setting, void *value)
|
||||
{
|
||||
int status = 0;
|
||||
wLogAppender* appender;
|
||||
|
||||
appender = WLog_GetLogAppender(log);
|
||||
|
||||
if (!appender)
|
||||
if (!appender || !setting || !strlen(setting))
|
||||
return FALSE;
|
||||
|
||||
if (!appender->Open)
|
||||
return TRUE;
|
||||
|
||||
if (!appender->State)
|
||||
{
|
||||
status = appender->Open(log, appender);
|
||||
appender->State = 1;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
BOOL WLog_CloseAppender(wLog* log)
|
||||
{
|
||||
int status = 0;
|
||||
wLogAppender* appender;
|
||||
|
||||
appender = WLog_GetLogAppender(log);
|
||||
|
||||
if (!appender)
|
||||
if (appender->Set)
|
||||
return appender->Set(appender, setting, value);
|
||||
else
|
||||
return FALSE;
|
||||
|
||||
if (!appender->Close)
|
||||
return TRUE;
|
||||
|
||||
if (appender->State)
|
||||
{
|
||||
status = appender->Close(log, appender);
|
||||
appender->State = 0;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
@ -20,25 +20,21 @@
|
||||
#ifndef WINPR_WLOG_APPENDER_PRIVATE_H
|
||||
#define WINPR_WLOG_APPENDER_PRIVATE_H
|
||||
|
||||
#include <winpr/wlog.h>
|
||||
|
||||
#include "wlog/FileAppender.h"
|
||||
#include "wlog/BinaryAppender.h"
|
||||
#include "wlog/ConsoleAppender.h"
|
||||
#include "wlog/CallbackAppender.h"
|
||||
#include "wlog/UdpAppender.h"
|
||||
|
||||
#ifdef HAVE_SYSLOG_H
|
||||
#include "wlog/SyslogAppender.h"
|
||||
#endif
|
||||
#include "wlog.h"
|
||||
|
||||
#include "FileAppender.h"
|
||||
#include "ConsoleAppender.h"
|
||||
#include "BinaryAppender.h"
|
||||
#include "CallbackAppender.h"
|
||||
#ifdef HAVE_JOURNALD_H
|
||||
#include "wlog/JournaldAppender.h"
|
||||
#include "JournaldAppender.h"
|
||||
#endif
|
||||
#ifdef HAVE_SYSLOG_H
|
||||
#include "SyslogAppender.h"
|
||||
#endif
|
||||
#include "UdpAppender.h"
|
||||
|
||||
void WLog_Appender_Free(wLog* log, wLogAppender* appender);
|
||||
|
||||
#include "wlog/wlog.h"
|
||||
|
||||
#endif /* WINPR_WLOG_APPENDER_PRIVATE_H */
|
||||
|
||||
|
@ -23,107 +23,87 @@
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#include "BinaryAppender.h"
|
||||
#include <winpr/crt.h>
|
||||
#include <winpr/file.h>
|
||||
#include <winpr/path.h>
|
||||
#include <winpr/thread.h>
|
||||
#include <winpr/stream.h>
|
||||
|
||||
#include <winpr/wlog.h>
|
||||
|
||||
#include "wlog/Message.h"
|
||||
|
||||
#include "wlog/BinaryAppender.h"
|
||||
|
||||
/**
|
||||
* Binary Appender
|
||||
*/
|
||||
|
||||
BOOL WLog_BinaryAppender_SetOutputFileName(wLog* log, wLogBinaryAppender* appender, const char* filename)
|
||||
struct _wLogBinaryAppender
|
||||
{
|
||||
if (!appender || !filename)
|
||||
return FALSE;
|
||||
WLOG_APPENDER_COMMON();
|
||||
|
||||
if (appender->Type != WLOG_APPENDER_BINARY)
|
||||
return FALSE;
|
||||
char* FileName;
|
||||
char* FilePath;
|
||||
char* FullFileName;
|
||||
FILE* FileDescriptor;
|
||||
};
|
||||
typedef struct _wLogBinaryAppender wLogBinaryAppender;
|
||||
|
||||
appender->FileName = _strdup(filename);
|
||||
if (!appender->FileName)
|
||||
return FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL WLog_BinaryAppender_SetOutputFilePath(wLog* log, wLogBinaryAppender* appender, const char* filepath)
|
||||
{
|
||||
if (!appender || !filepath)
|
||||
return FALSE;
|
||||
|
||||
if (appender->Type != WLOG_APPENDER_BINARY)
|
||||
return FALSE;
|
||||
|
||||
appender->FilePath = _strdup(filepath);
|
||||
if (!appender->FilePath)
|
||||
return FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL WLog_BinaryAppender_Open(wLog* log, wLogBinaryAppender* appender)
|
||||
static BOOL WLog_BinaryAppender_Open(wLog* log, wLogAppender* appender)
|
||||
{
|
||||
wLogBinaryAppender* binaryAppender;
|
||||
if (!log || !appender)
|
||||
return FALSE;
|
||||
|
||||
if (!appender->FileName)
|
||||
binaryAppender = (wLogBinaryAppender *)appender;
|
||||
if (!binaryAppender->FileName)
|
||||
{
|
||||
appender->FileName = (char*) malloc(MAX_PATH);
|
||||
if (!appender->FileName)
|
||||
binaryAppender->FileName = (char*) malloc(MAX_PATH);
|
||||
if (!binaryAppender->FileName)
|
||||
return FALSE;
|
||||
sprintf_s(appender->FileName, MAX_PATH, "%u.wlog", (unsigned int) GetCurrentProcessId());
|
||||
sprintf_s(binaryAppender->FileName, MAX_PATH, "%u.wlog", (unsigned int) GetCurrentProcessId());
|
||||
}
|
||||
|
||||
if (!appender->FilePath)
|
||||
if (!binaryAppender->FilePath)
|
||||
{
|
||||
appender->FilePath = GetKnownSubPath(KNOWN_PATH_TEMP, "wlog");
|
||||
if (!appender->FilePath)
|
||||
binaryAppender->FilePath = GetKnownSubPath(KNOWN_PATH_TEMP, "wlog");
|
||||
if (!binaryAppender->FilePath)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!appender->FullFileName)
|
||||
if (!binaryAppender->FullFileName)
|
||||
{
|
||||
appender->FullFileName = GetCombinedPath(appender->FilePath, appender->FileName);
|
||||
if (!appender->FullFileName)
|
||||
binaryAppender->FullFileName = GetCombinedPath(binaryAppender->FilePath, binaryAppender->FileName);
|
||||
if (!binaryAppender->FullFileName)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!PathFileExistsA(appender->FilePath))
|
||||
if (!PathFileExistsA(binaryAppender->FilePath))
|
||||
{
|
||||
if (!PathMakePathA(appender->FilePath, 0))
|
||||
if (!PathMakePathA(binaryAppender->FilePath, 0))
|
||||
return FALSE;
|
||||
UnixChangeFileMode(appender->FilePath, 0xFFFF);
|
||||
UnixChangeFileMode(binaryAppender->FilePath, 0xFFFF);
|
||||
}
|
||||
|
||||
appender->FileDescriptor = fopen(appender->FullFileName, "a+");
|
||||
binaryAppender->FileDescriptor = fopen(binaryAppender->FullFileName, "a+");
|
||||
|
||||
if (!appender->FileDescriptor)
|
||||
if (!binaryAppender->FileDescriptor)
|
||||
return FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL WLog_BinaryAppender_Close(wLog* log, wLogBinaryAppender* appender)
|
||||
static BOOL WLog_BinaryAppender_Close(wLog* log, wLogAppender* appender)
|
||||
{
|
||||
if (!appender->FileDescriptor)
|
||||
wLogBinaryAppender* binaryAppender;
|
||||
|
||||
if (!appender)
|
||||
return FALSE;
|
||||
|
||||
binaryAppender = (wLogBinaryAppender *)appender;
|
||||
if (!binaryAppender->FileDescriptor)
|
||||
return TRUE;
|
||||
|
||||
fclose(appender->FileDescriptor);
|
||||
fclose(binaryAppender->FileDescriptor);
|
||||
|
||||
appender->FileDescriptor = NULL;
|
||||
binaryAppender->FileDescriptor = NULL;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL WLog_BinaryAppender_WriteMessage(wLog* log, wLogBinaryAppender* appender, wLogMessage* message)
|
||||
static BOOL WLog_BinaryAppender_WriteMessage(wLog* log, wLogAppender* appender, wLogMessage* message)
|
||||
{
|
||||
FILE* fp;
|
||||
wStream* s;
|
||||
@ -132,11 +112,14 @@ BOOL WLog_BinaryAppender_WriteMessage(wLog* log, wLogBinaryAppender* appender, w
|
||||
int FunctionNameLength;
|
||||
int TextStringLength;
|
||||
BOOL ret = TRUE;
|
||||
wLogBinaryAppender* binaryAppender;
|
||||
|
||||
if (!log || !appender || !message)
|
||||
return FALSE;
|
||||
|
||||
fp = appender->FileDescriptor;
|
||||
binaryAppender = (wLogBinaryAppender *)appender;
|
||||
|
||||
fp = binaryAppender->FileDescriptor;
|
||||
|
||||
if (!fp)
|
||||
return FALSE;
|
||||
@ -180,17 +163,55 @@ BOOL WLog_BinaryAppender_WriteMessage(wLog* log, wLogBinaryAppender* appender, w
|
||||
return ret;
|
||||
}
|
||||
|
||||
BOOL WLog_BinaryAppender_WriteDataMessage(wLog* log, wLogBinaryAppender* appender, wLogMessage* message)
|
||||
static BOOL WLog_BinaryAppender_WriteDataMessage(wLog* log, wLogAppender* appender, wLogMessage* message)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL WLog_BinaryAppender_WriteImageMessage(wLog* log, wLogBinaryAppender* appender, wLogMessage* message)
|
||||
static BOOL WLog_BinaryAppender_WriteImageMessage(wLog* log, wLogAppender* appender, wLogMessage* message)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
wLogBinaryAppender* WLog_BinaryAppender_New(wLog* log)
|
||||
static BOOL WLog_BinaryAppender_Set(wLogAppender* appender, const char *setting, void *value)
|
||||
{
|
||||
wLogBinaryAppender *binaryAppender = (wLogBinaryAppender *) appender;
|
||||
|
||||
if (!value || !strlen(value))
|
||||
return FALSE;
|
||||
|
||||
if (!strcmp("outputfilename", setting))
|
||||
{
|
||||
binaryAppender->FileName = _strdup((const char *)value);
|
||||
if (!binaryAppender->FileName)
|
||||
return FALSE;
|
||||
}
|
||||
else if (!strcmp("outputfilepath", setting))
|
||||
{
|
||||
binaryAppender->FilePath = _strdup((const char *)value);
|
||||
if (!binaryAppender->FilePath)
|
||||
return FALSE;
|
||||
}
|
||||
else
|
||||
return FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void WLog_BinaryAppender_Free(wLogAppender* appender)
|
||||
{
|
||||
wLogBinaryAppender *binaryAppender;
|
||||
if (appender)
|
||||
{
|
||||
binaryAppender = (wLogBinaryAppender *)appender;
|
||||
free(binaryAppender->FileName);
|
||||
free(binaryAppender->FilePath);
|
||||
free(binaryAppender->FullFileName);
|
||||
free(binaryAppender);
|
||||
}
|
||||
}
|
||||
|
||||
wLogAppender* WLog_BinaryAppender_New(wLog* log)
|
||||
{
|
||||
wLogBinaryAppender* BinaryAppender;
|
||||
|
||||
@ -199,25 +220,13 @@ wLogBinaryAppender* WLog_BinaryAppender_New(wLog* log)
|
||||
return NULL;
|
||||
|
||||
BinaryAppender->Type = WLOG_APPENDER_BINARY;
|
||||
BinaryAppender->Open = (WLOG_APPENDER_OPEN_FN) WLog_BinaryAppender_Open;
|
||||
BinaryAppender->Close = (WLOG_APPENDER_OPEN_FN) WLog_BinaryAppender_Close;
|
||||
BinaryAppender->WriteMessage =
|
||||
(WLOG_APPENDER_WRITE_MESSAGE_FN) WLog_BinaryAppender_WriteMessage;
|
||||
BinaryAppender->WriteDataMessage =
|
||||
(WLOG_APPENDER_WRITE_DATA_MESSAGE_FN) WLog_BinaryAppender_WriteDataMessage;
|
||||
BinaryAppender->WriteImageMessage =
|
||||
(WLOG_APPENDER_WRITE_IMAGE_MESSAGE_FN) WLog_BinaryAppender_WriteImageMessage;
|
||||
BinaryAppender->Open = WLog_BinaryAppender_Open;
|
||||
BinaryAppender->Close = WLog_BinaryAppender_Close;
|
||||
BinaryAppender->WriteMessage = WLog_BinaryAppender_WriteMessage;
|
||||
BinaryAppender->WriteDataMessage = WLog_BinaryAppender_WriteDataMessage;
|
||||
BinaryAppender->WriteImageMessage = WLog_BinaryAppender_WriteImageMessage;
|
||||
BinaryAppender->Free = WLog_BinaryAppender_Free;
|
||||
BinaryAppender->Set = WLog_BinaryAppender_Set;
|
||||
|
||||
return BinaryAppender;
|
||||
}
|
||||
|
||||
void WLog_BinaryAppender_Free(wLog* log, wLogBinaryAppender* appender)
|
||||
{
|
||||
if (appender)
|
||||
{
|
||||
free(appender->FileName);
|
||||
free(appender->FilePath);
|
||||
free(appender->FullFileName);
|
||||
free(appender);
|
||||
}
|
||||
return (wLogAppender *)BinaryAppender;
|
||||
}
|
||||
|
@ -20,11 +20,8 @@
|
||||
#ifndef WINPR_WLOG_BINARY_APPENDER_PRIVATE_H
|
||||
#define WINPR_WLOG_BINARY_APPENDER_PRIVATE_H
|
||||
|
||||
#include <winpr/wlog.h>
|
||||
#include "wlog.h"
|
||||
|
||||
#include "wlog/wlog.h"
|
||||
|
||||
WINPR_API wLogBinaryAppender* WLog_BinaryAppender_New(wLog* log);
|
||||
WINPR_API void WLog_BinaryAppender_Free(wLog* log, wLogBinaryAppender* appender);
|
||||
WINPR_API wLogAppender* WLog_BinaryAppender_New(wLog* log);
|
||||
|
||||
#endif /* WINPR_WLOG_BINARY_APPENDER_PRIVATE_H */
|
||||
|
@ -21,100 +21,114 @@
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <winpr/crt.h>
|
||||
#include <winpr/path.h>
|
||||
#include "CallbackAppender.h"
|
||||
|
||||
#include <winpr/wlog.h>
|
||||
|
||||
#include "wlog/Message.h"
|
||||
|
||||
#include "wlog/CallbackAppender.h"
|
||||
|
||||
/**
|
||||
* Callback Appender
|
||||
*/
|
||||
|
||||
WINPR_API BOOL WLog_CallbackAppender_SetCallbacks(wLog* log, wLogCallbackAppender* appender,
|
||||
CallbackAppenderMessage_t msg, CallbackAppenderImage_t img, CallbackAppenderPackage_t pkg,
|
||||
CallbackAppenderData_t data)
|
||||
struct _wLogCallbackAppender
|
||||
{
|
||||
if (!appender)
|
||||
return FALSE;
|
||||
WLOG_APPENDER_COMMON();
|
||||
|
||||
if (appender->Type != WLOG_APPENDER_CALLBACK)
|
||||
return FALSE;
|
||||
wLogCallbacks *callbacks;
|
||||
};
|
||||
typedef struct _wLogCallbackAppender wLogCallbackAppender;
|
||||
|
||||
appender->message = msg;
|
||||
appender->image = img;
|
||||
appender->package = pkg;
|
||||
appender->data = data;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL WLog_CallbackAppender_Open(wLog* log, wLogCallbackAppender* appender)
|
||||
static BOOL WLog_CallbackAppender_Open(wLog* log, wLogAppender* appender)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL WLog_CallbackAppender_Close(wLog* log, wLogCallbackAppender* appender)
|
||||
static BOOL WLog_CallbackAppender_Close(wLog* log, wLogAppender* appender)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL WLog_CallbackAppender_WriteMessage(wLog* log, wLogCallbackAppender* appender, wLogMessage* message)
|
||||
static BOOL WLog_CallbackAppender_WriteMessage(wLog* log, wLogAppender* appender, wLogMessage* message)
|
||||
{
|
||||
char prefix[WLOG_MAX_PREFIX_SIZE];
|
||||
wLogCallbackAppender* callbackAppender;
|
||||
|
||||
if (!appender)
|
||||
return FALSE;
|
||||
message->PrefixString = prefix;
|
||||
WLog_Layout_GetMessagePrefix(log, appender->Layout, message);
|
||||
|
||||
if (appender->message)
|
||||
{
|
||||
return appender->message(message);
|
||||
}
|
||||
callbackAppender = (wLogCallbackAppender *)appender;
|
||||
|
||||
if (callbackAppender->callbacks && callbackAppender->callbacks->message)
|
||||
return callbackAppender->callbacks->message(message);
|
||||
else
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
BOOL WLog_CallbackAppender_WriteDataMessage(wLog* log, wLogCallbackAppender* appender, wLogMessage* message)
|
||||
static BOOL WLog_CallbackAppender_WriteDataMessage(wLog* log, wLogAppender* appender, wLogMessage* message)
|
||||
{
|
||||
if (appender->data)
|
||||
{
|
||||
return appender->data(message);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
wLogCallbackAppender* callbackAppender;
|
||||
if (!appender)
|
||||
return FALSE;
|
||||
|
||||
callbackAppender = (wLogCallbackAppender *)appender;
|
||||
if (callbackAppender->callbacks && callbackAppender->callbacks->data)
|
||||
return callbackAppender->callbacks->data(message);
|
||||
else
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
BOOL WLog_CallbackAppender_WriteImageMessage(wLog* log, wLogCallbackAppender* appender, wLogMessage* message)
|
||||
static BOOL WLog_CallbackAppender_WriteImageMessage(wLog* log, wLogAppender* appender, wLogMessage* message)
|
||||
{
|
||||
if (appender->image)
|
||||
{
|
||||
return appender->image(message);
|
||||
}
|
||||
else
|
||||
{
|
||||
wLogCallbackAppender* callbackAppender;
|
||||
if (!appender)
|
||||
return FALSE;
|
||||
|
||||
callbackAppender = (wLogCallbackAppender *)appender;
|
||||
if (callbackAppender->callbacks && callbackAppender->callbacks->image)
|
||||
return callbackAppender->callbacks->image(message);
|
||||
else
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
BOOL WLog_CallbackAppender_WritePacketMessage(wLog* log, wLogCallbackAppender* appender, wLogMessage* message)
|
||||
static BOOL WLog_CallbackAppender_WritePacketMessage(wLog* log, wLogAppender* appender, wLogMessage* message)
|
||||
{
|
||||
if (appender->package)
|
||||
{
|
||||
return appender->package(message);
|
||||
}
|
||||
else
|
||||
{
|
||||
wLogCallbackAppender* callbackAppender;
|
||||
if (!appender)
|
||||
return FALSE;
|
||||
|
||||
callbackAppender = (wLogCallbackAppender *)appender;
|
||||
if (callbackAppender->callbacks && callbackAppender->callbacks->package)
|
||||
return callbackAppender->callbacks->package(message);
|
||||
else
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
wLogCallbackAppender* WLog_CallbackAppender_New(wLog* log)
|
||||
static BOOL WLog_CallbackAppender_Set(wLogAppender* appender, const char *setting, void *value)
|
||||
{
|
||||
wLogCallbackAppender *callbackAppender = (wLogCallbackAppender *)appender;
|
||||
|
||||
if (!value || strcmp(setting, "callbacks"))
|
||||
return FALSE;
|
||||
|
||||
if (!(callbackAppender->callbacks = calloc(1, sizeof(wLogCallbacks)))) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
callbackAppender->callbacks = memcpy(callbackAppender->callbacks, value, sizeof(wLogCallbacks));
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void WLog_CallbackAppender_Free(wLogAppender* appender)
|
||||
{
|
||||
wLogCallbackAppender *callbackAppender;
|
||||
if (!appender) {
|
||||
return;
|
||||
}
|
||||
|
||||
callbackAppender = (wLogCallbackAppender *)appender;
|
||||
|
||||
free(callbackAppender->callbacks);
|
||||
free(appender);
|
||||
}
|
||||
|
||||
wLogAppender* WLog_CallbackAppender_New(wLog* log)
|
||||
{
|
||||
wLogCallbackAppender* CallbackAppender;
|
||||
|
||||
@ -124,21 +138,14 @@ wLogCallbackAppender* WLog_CallbackAppender_New(wLog* log)
|
||||
|
||||
CallbackAppender->Type = WLOG_APPENDER_CALLBACK;
|
||||
|
||||
CallbackAppender->Open = (WLOG_APPENDER_OPEN_FN) WLog_CallbackAppender_Open;
|
||||
CallbackAppender->Close = (WLOG_APPENDER_OPEN_FN) WLog_CallbackAppender_Close;
|
||||
CallbackAppender->WriteMessage =
|
||||
(WLOG_APPENDER_WRITE_MESSAGE_FN) WLog_CallbackAppender_WriteMessage;
|
||||
CallbackAppender->WriteDataMessage =
|
||||
(WLOG_APPENDER_WRITE_DATA_MESSAGE_FN) WLog_CallbackAppender_WriteDataMessage;
|
||||
CallbackAppender->WriteImageMessage =
|
||||
(WLOG_APPENDER_WRITE_IMAGE_MESSAGE_FN) WLog_CallbackAppender_WriteImageMessage;
|
||||
CallbackAppender->WritePacketMessage =
|
||||
(WLOG_APPENDER_WRITE_PACKET_MESSAGE_FN) WLog_CallbackAppender_WritePacketMessage;
|
||||
CallbackAppender->Open = WLog_CallbackAppender_Open;
|
||||
CallbackAppender->Close = WLog_CallbackAppender_Close;
|
||||
CallbackAppender->WriteMessage = WLog_CallbackAppender_WriteMessage;
|
||||
CallbackAppender->WriteDataMessage = WLog_CallbackAppender_WriteDataMessage;
|
||||
CallbackAppender->WriteImageMessage = WLog_CallbackAppender_WriteImageMessage;
|
||||
CallbackAppender->WritePacketMessage = WLog_CallbackAppender_WritePacketMessage;
|
||||
CallbackAppender->Free = WLog_CallbackAppender_Free;
|
||||
CallbackAppender->Set = WLog_CallbackAppender_Set;
|
||||
|
||||
return CallbackAppender;
|
||||
}
|
||||
|
||||
void WLog_CallbackAppender_Free(wLog* log, wLogCallbackAppender* appender)
|
||||
{
|
||||
free(appender);
|
||||
return (wLogAppender *)CallbackAppender;
|
||||
}
|
||||
|
@ -20,11 +20,8 @@
|
||||
#ifndef WINPR_WLOG_CALLBACK_APPENDER_PRIVATE_H
|
||||
#define WINPR_WLOG_CALLBACK_APPENDER_PRIVATE_H
|
||||
|
||||
#include <winpr/wlog.h>
|
||||
#include "wlog.h"
|
||||
|
||||
#include "wlog/wlog.h"
|
||||
|
||||
WINPR_API wLogCallbackAppender* WLog_CallbackAppender_New(wLog* log);
|
||||
WINPR_API void WLog_CallbackAppender_Free(wLog* log, wLogCallbackAppender* appender);
|
||||
wLogAppender* WLog_CallbackAppender_New(wLog* log);
|
||||
|
||||
#endif /* WINPR_WLOG_CALLBACK_APPENDER_PRIVATE_H */
|
||||
|
@ -21,63 +21,51 @@
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <winpr/crt.h>
|
||||
#include <winpr/path.h>
|
||||
|
||||
#include <winpr/wlog.h>
|
||||
|
||||
#include "wlog/Message.h"
|
||||
|
||||
#include "wlog/ConsoleAppender.h"
|
||||
#include "ConsoleAppender.h"
|
||||
#include "Message.h"
|
||||
|
||||
#ifdef ANDROID
|
||||
#include <android/log.h>
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Console Appender
|
||||
*/
|
||||
#define WLOG_CONSOLE_DEFAULT 0
|
||||
#define WLOG_CONSOLE_STDOUT 1
|
||||
#define WLOG_CONSOLE_STDERR 2
|
||||
#define WLOG_CONSOLE_DEBUG 4
|
||||
|
||||
BOOL WLog_ConsoleAppender_SetOutputStream(wLog* log, wLogConsoleAppender* appender, int outputStream)
|
||||
struct _wLogConsoleAppender
|
||||
{
|
||||
if (!appender)
|
||||
return FALSE;
|
||||
WLOG_APPENDER_COMMON();
|
||||
|
||||
if (appender->Type != WLOG_APPENDER_CONSOLE)
|
||||
return FALSE;
|
||||
int outputStream;
|
||||
};
|
||||
typedef struct _wLogConsoleAppender wLogConsoleAppender;
|
||||
|
||||
if (outputStream < 0)
|
||||
outputStream = WLOG_CONSOLE_DEFAULT;
|
||||
|
||||
if (outputStream == WLOG_CONSOLE_STDOUT)
|
||||
appender->outputStream = WLOG_CONSOLE_STDOUT;
|
||||
else if (outputStream == WLOG_CONSOLE_STDERR)
|
||||
appender->outputStream = WLOG_CONSOLE_STDERR;
|
||||
else
|
||||
appender->outputStream = WLOG_CONSOLE_DEFAULT;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL WLog_ConsoleAppender_Open(wLog* log, wLogConsoleAppender* appender)
|
||||
static BOOL WLog_ConsoleAppender_Open(wLog* log, wLogAppender* appender)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL WLog_ConsoleAppender_Close(wLog* log, wLogConsoleAppender* appender)
|
||||
static BOOL WLog_ConsoleAppender_Close(wLog* log, wLogAppender* appender)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL WLog_ConsoleAppender_WriteMessage(wLog* log, wLogConsoleAppender* appender, wLogMessage* message)
|
||||
static BOOL WLog_ConsoleAppender_WriteMessage(wLog* log, wLogAppender* appender, wLogMessage* message)
|
||||
{
|
||||
FILE* fp;
|
||||
char prefix[WLOG_MAX_PREFIX_SIZE];
|
||||
if (!appender)
|
||||
return FALSE;
|
||||
|
||||
wLogConsoleAppender *consoleAppender = (wLogConsoleAppender *)appender;
|
||||
|
||||
|
||||
message->PrefixString = prefix;
|
||||
WLog_Layout_GetMessagePrefix(log, appender->Layout, message);
|
||||
|
||||
#ifdef _WIN32
|
||||
if (appender->outputStream == WLOG_CONSOLE_DEBUG)
|
||||
if (consoleAppender->outputStream == WLOG_CONSOLE_DEBUG)
|
||||
{
|
||||
char MessageString[4096];
|
||||
|
||||
@ -124,7 +112,7 @@ BOOL WLog_ConsoleAppender_WriteMessage(wLog* log, wLogConsoleAppender* appender,
|
||||
__android_log_print(level, log->Name, "%s%s", message->PrefixString, message->TextString);
|
||||
|
||||
#else
|
||||
switch(appender->outputStream)
|
||||
switch(consoleAppender->outputStream)
|
||||
{
|
||||
case WLOG_CONSOLE_STDOUT:
|
||||
fp = stdout;
|
||||
@ -155,7 +143,7 @@ BOOL WLog_ConsoleAppender_WriteMessage(wLog* log, wLogConsoleAppender* appender,
|
||||
|
||||
static int g_DataId = 0;
|
||||
|
||||
BOOL WLog_ConsoleAppender_WriteDataMessage(wLog* log, wLogConsoleAppender* appender, wLogMessage* message)
|
||||
static BOOL WLog_ConsoleAppender_WriteDataMessage(wLog* log, wLogAppender* appender, wLogMessage* message)
|
||||
{
|
||||
int DataId;
|
||||
char* FullFileName;
|
||||
@ -172,7 +160,7 @@ BOOL WLog_ConsoleAppender_WriteDataMessage(wLog* log, wLogConsoleAppender* appen
|
||||
|
||||
static int g_ImageId = 0;
|
||||
|
||||
BOOL WLog_ConsoleAppender_WriteImageMessage(wLog* log, wLogConsoleAppender* appender, wLogMessage* message)
|
||||
static BOOL WLog_ConsoleAppender_WriteImageMessage(wLog* log, wLogAppender* appender, wLogMessage* message)
|
||||
{
|
||||
int ImageId;
|
||||
char* FullFileName;
|
||||
@ -190,7 +178,7 @@ BOOL WLog_ConsoleAppender_WriteImageMessage(wLog* log, wLogConsoleAppender* appe
|
||||
|
||||
static int g_PacketId = 0;
|
||||
|
||||
BOOL WLog_ConsoleAppender_WritePacketMessage(wLog* log, wLogConsoleAppender* appender, wLogMessage* message)
|
||||
static BOOL WLog_ConsoleAppender_WritePacketMessage(wLog* log, wLogAppender* appender, wLogMessage* message)
|
||||
{
|
||||
int PacketId;
|
||||
char* FullFileName;
|
||||
@ -210,41 +198,31 @@ BOOL WLog_ConsoleAppender_WritePacketMessage(wLog* log, wLogConsoleAppender* app
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
wLogConsoleAppender* WLog_ConsoleAppender_New(wLog* log)
|
||||
static BOOL WLog_ConsoleAppender_Set(wLogAppender* appender, const char *setting, void *value)
|
||||
{
|
||||
wLogConsoleAppender* ConsoleAppender;
|
||||
wLogConsoleAppender *consoleAppender = (wLogConsoleAppender *)appender;
|
||||
|
||||
ConsoleAppender = (wLogConsoleAppender*) calloc(1, sizeof(wLogConsoleAppender));
|
||||
if (!value || !strlen(value))
|
||||
return FALSE;
|
||||
|
||||
if (!ConsoleAppender)
|
||||
return NULL;
|
||||
if (strcmp("outputstream", setting))
|
||||
return FALSE;
|
||||
|
||||
ConsoleAppender->Type = WLOG_APPENDER_CONSOLE;
|
||||
if (!strcmp("stdout", value))
|
||||
consoleAppender->outputStream = WLOG_CONSOLE_STDOUT;
|
||||
else if (!strcmp("stderr", value))
|
||||
consoleAppender->outputStream = WLOG_CONSOLE_STDERR;
|
||||
else if (!strcmp("default", value))
|
||||
consoleAppender->outputStream = WLOG_CONSOLE_DEFAULT;
|
||||
else if (!strcmp("debug", value))
|
||||
consoleAppender->outputStream = WLOG_CONSOLE_DEBUG;
|
||||
else
|
||||
return FALSE;
|
||||
|
||||
ConsoleAppender->Open = (WLOG_APPENDER_OPEN_FN) WLog_ConsoleAppender_Open;
|
||||
ConsoleAppender->Close = (WLOG_APPENDER_OPEN_FN) WLog_ConsoleAppender_Close;
|
||||
|
||||
ConsoleAppender->WriteMessage =
|
||||
(WLOG_APPENDER_WRITE_MESSAGE_FN) WLog_ConsoleAppender_WriteMessage;
|
||||
ConsoleAppender->WriteDataMessage =
|
||||
(WLOG_APPENDER_WRITE_DATA_MESSAGE_FN) WLog_ConsoleAppender_WriteDataMessage;
|
||||
ConsoleAppender->WriteImageMessage =
|
||||
(WLOG_APPENDER_WRITE_IMAGE_MESSAGE_FN) WLog_ConsoleAppender_WriteImageMessage;
|
||||
ConsoleAppender->WritePacketMessage =
|
||||
(WLOG_APPENDER_WRITE_PACKET_MESSAGE_FN) WLog_ConsoleAppender_WritePacketMessage;
|
||||
|
||||
ConsoleAppender->outputStream = WLOG_CONSOLE_DEFAULT;
|
||||
|
||||
#ifdef _WIN32
|
||||
if (IsDebuggerPresent())
|
||||
ConsoleAppender->outputStream = WLOG_CONSOLE_DEBUG;
|
||||
#endif
|
||||
|
||||
return ConsoleAppender;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void WLog_ConsoleAppender_Free(wLog* log, wLogConsoleAppender* appender)
|
||||
static void WLog_ConsoleAppender_Free(wLogAppender* appender)
|
||||
{
|
||||
if (appender)
|
||||
{
|
||||
@ -256,3 +234,34 @@ void WLog_ConsoleAppender_Free(wLog* log, wLogConsoleAppender* appender)
|
||||
free(appender);
|
||||
}
|
||||
}
|
||||
|
||||
wLogAppender* WLog_ConsoleAppender_New(wLog* log)
|
||||
{
|
||||
wLogConsoleAppender* ConsoleAppender;
|
||||
|
||||
ConsoleAppender = (wLogConsoleAppender*) calloc(1, sizeof(wLogConsoleAppender));
|
||||
|
||||
if (!ConsoleAppender)
|
||||
return NULL;
|
||||
|
||||
ConsoleAppender->Type = WLOG_APPENDER_CONSOLE;
|
||||
|
||||
ConsoleAppender->Open = WLog_ConsoleAppender_Open;
|
||||
ConsoleAppender->Close = WLog_ConsoleAppender_Close;
|
||||
ConsoleAppender->WriteMessage = WLog_ConsoleAppender_WriteMessage;
|
||||
ConsoleAppender->WriteDataMessage = WLog_ConsoleAppender_WriteDataMessage;
|
||||
ConsoleAppender->WriteImageMessage = WLog_ConsoleAppender_WriteImageMessage;
|
||||
ConsoleAppender->WritePacketMessage = WLog_ConsoleAppender_WritePacketMessage;
|
||||
ConsoleAppender->Set = WLog_ConsoleAppender_Set;
|
||||
ConsoleAppender->Free = WLog_ConsoleAppender_Free;
|
||||
|
||||
ConsoleAppender->outputStream = WLOG_CONSOLE_DEFAULT;
|
||||
|
||||
#ifdef _WIN32
|
||||
if (IsDebuggerPresent())
|
||||
ConsoleAppender->outputStream = WLOG_CONSOLE_DEBUG;
|
||||
#endif
|
||||
|
||||
return (wLogAppender *)ConsoleAppender;
|
||||
}
|
||||
|
||||
|
@ -20,11 +20,8 @@
|
||||
#ifndef WINPR_WLOG_CONSOLE_APPENDER_PRIVATE_H
|
||||
#define WINPR_WLOG_CONSOLE_APPENDER_PRIVATE_H
|
||||
|
||||
#include <winpr/wlog.h>
|
||||
#include "wlog.h"
|
||||
|
||||
#include "wlog/wlog.h"
|
||||
|
||||
WINPR_API wLogConsoleAppender* WLog_ConsoleAppender_New(wLog* log);
|
||||
WINPR_API void WLog_ConsoleAppender_Free(wLog* log, wLogConsoleAppender* appender);
|
||||
wLogAppender* WLog_ConsoleAppender_New(wLog* log);
|
||||
|
||||
#endif /* WINPR_WLOG_CONSOLE_APPENDER_PRIVATE_H */
|
||||
|
@ -21,7 +21,7 @@
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <winpr/wlog.h>
|
||||
#include "wlog.h"
|
||||
|
||||
#include "wlog/DataMessage.h"
|
||||
|
||||
|
@ -20,10 +20,6 @@
|
||||
#ifndef WINPR_WLOG_DATA_MESSAGE_PRIVATE_H
|
||||
#define WINPR_WLOG_DATA_MESSAGE_PRIVATE_H
|
||||
|
||||
#include <winpr/wlog.h>
|
||||
|
||||
#include "wlog/wlog.h"
|
||||
|
||||
BOOL WLog_DataMessage_Write(char* filename, void* data, int length);
|
||||
|
||||
#endif /* WINPR_WLOG_DATA_MESSAGE_PRIVATE_H */
|
||||
|
@ -21,30 +21,28 @@
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "FileAppender.h"
|
||||
#include "Message.h"
|
||||
|
||||
#include <winpr/crt.h>
|
||||
#include <winpr/environment.h>
|
||||
#include <winpr/file.h>
|
||||
#include <winpr/path.h>
|
||||
#include <winpr/thread.h>
|
||||
|
||||
#include <winpr/wlog.h>
|
||||
|
||||
#include "wlog/Message.h"
|
||||
|
||||
#include "wlog/FileAppender.h"
|
||||
|
||||
/**
|
||||
* File Appender
|
||||
*/
|
||||
|
||||
BOOL WLog_FileAppender_SetOutputFileName(wLog* log, wLogFileAppender* appender, const char* filename)
|
||||
struct _wLogFileAppender
|
||||
{
|
||||
if (!appender || !filename)
|
||||
return FALSE;
|
||||
WLOG_APPENDER_COMMON();
|
||||
|
||||
if (appender->Type != WLOG_APPENDER_FILE)
|
||||
return FALSE;
|
||||
char* FileName;
|
||||
char* FilePath;
|
||||
char* FullFileName;
|
||||
FILE* FileDescriptor;
|
||||
};
|
||||
typedef struct _wLogFileAppender wLogFileAppender;
|
||||
|
||||
|
||||
static BOOL WLog_FileAppender_SetOutputFileName(wLogFileAppender* appender, const char* filename)
|
||||
{
|
||||
appender->FileName = _strdup(filename);
|
||||
if (!appender->FileName)
|
||||
return FALSE;
|
||||
@ -52,14 +50,8 @@ BOOL WLog_FileAppender_SetOutputFileName(wLog* log, wLogFileAppender* appender,
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL WLog_FileAppender_SetOutputFilePath(wLog* log, wLogFileAppender* appender, const char* filepath)
|
||||
static BOOL WLog_FileAppender_SetOutputFilePath(wLogFileAppender* appender, const char* filepath)
|
||||
{
|
||||
if (!appender || !filepath)
|
||||
return FALSE;
|
||||
|
||||
if (appender->Type != WLOG_APPENDER_FILE)
|
||||
return FALSE;
|
||||
|
||||
appender->FilePath = _strdup(filepath);
|
||||
if (!appender->FilePath)
|
||||
return FALSE;
|
||||
@ -67,73 +59,83 @@ BOOL WLog_FileAppender_SetOutputFilePath(wLog* log, wLogFileAppender* appender,
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL WLog_FileAppender_Open(wLog* log, wLogFileAppender* appender)
|
||||
static BOOL WLog_FileAppender_Open(wLog* log, wLogAppender* appender)
|
||||
{
|
||||
wLogFileAppender *fileAppender;
|
||||
|
||||
if (!log || !appender)
|
||||
return FALSE;
|
||||
|
||||
if (!appender->FilePath)
|
||||
fileAppender = (wLogFileAppender *)appender;
|
||||
|
||||
if (!fileAppender->FilePath)
|
||||
{
|
||||
appender->FilePath = GetKnownSubPath(KNOWN_PATH_TEMP, "wlog");
|
||||
if (!appender->FilePath)
|
||||
fileAppender->FilePath = GetKnownSubPath(KNOWN_PATH_TEMP, "wlog");
|
||||
if (!fileAppender->FilePath)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!appender->FileName)
|
||||
if (!fileAppender->FileName)
|
||||
{
|
||||
appender->FileName = (char*) malloc(MAX_PATH);
|
||||
if (!appender->FileName)
|
||||
fileAppender->FileName = (char*) malloc(MAX_PATH);
|
||||
if (!fileAppender->FileName)
|
||||
return FALSE;
|
||||
|
||||
sprintf_s(appender->FileName, MAX_PATH, "%u.log", (unsigned int) GetCurrentProcessId());
|
||||
sprintf_s(fileAppender->FileName, MAX_PATH, "%u.log", (unsigned int) GetCurrentProcessId());
|
||||
}
|
||||
|
||||
if (!appender->FullFileName)
|
||||
if (!fileAppender->FullFileName)
|
||||
{
|
||||
appender->FullFileName = GetCombinedPath(appender->FilePath, appender->FileName);
|
||||
if (!appender->FullFileName)
|
||||
fileAppender->FullFileName = GetCombinedPath(fileAppender->FilePath, fileAppender->FileName);
|
||||
if (!fileAppender->FullFileName)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!PathFileExistsA(appender->FilePath))
|
||||
if (!PathFileExistsA(fileAppender->FilePath))
|
||||
{
|
||||
if (!PathMakePathA(appender->FilePath, 0))
|
||||
if (!PathMakePathA(fileAppender->FilePath, 0))
|
||||
return FALSE;
|
||||
UnixChangeFileMode(appender->FilePath, 0xFFFF);
|
||||
UnixChangeFileMode(fileAppender->FilePath, 0xFFFF);
|
||||
}
|
||||
|
||||
appender->FileDescriptor = fopen(appender->FullFileName, "a+");
|
||||
fileAppender->FileDescriptor = fopen(fileAppender->FullFileName, "a+");
|
||||
|
||||
if (!appender->FileDescriptor)
|
||||
if (!fileAppender->FileDescriptor)
|
||||
return FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL WLog_FileAppender_Close(wLog* log, wLogFileAppender* appender)
|
||||
static BOOL WLog_FileAppender_Close(wLog* log, wLogAppender* appender)
|
||||
{
|
||||
wLogFileAppender *fileAppender;
|
||||
if (!log || !appender)
|
||||
return FALSE;
|
||||
|
||||
if (!appender->FileDescriptor)
|
||||
fileAppender = (wLogFileAppender *)appender;
|
||||
|
||||
if (!fileAppender->FileDescriptor)
|
||||
return TRUE;
|
||||
|
||||
fclose(appender->FileDescriptor);
|
||||
fclose(fileAppender->FileDescriptor);
|
||||
|
||||
appender->FileDescriptor = NULL;
|
||||
fileAppender->FileDescriptor = NULL;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL WLog_FileAppender_WriteMessage(wLog* log, wLogFileAppender* appender, wLogMessage* message)
|
||||
static BOOL WLog_FileAppender_WriteMessage(wLog* log, wLogAppender* appender, wLogMessage* message)
|
||||
{
|
||||
FILE* fp;
|
||||
char prefix[WLOG_MAX_PREFIX_SIZE];
|
||||
wLogFileAppender *fileAppender;
|
||||
|
||||
if (!log || !appender || !message)
|
||||
return FALSE;
|
||||
|
||||
fp = appender->FileDescriptor;
|
||||
fileAppender = (wLogFileAppender *)appender;
|
||||
|
||||
fp = fileAppender->FileDescriptor;
|
||||
|
||||
if (!fp)
|
||||
return FALSE;
|
||||
@ -150,7 +152,7 @@ BOOL WLog_FileAppender_WriteMessage(wLog* log, wLogFileAppender* appender, wLogM
|
||||
|
||||
static int g_DataId = 0;
|
||||
|
||||
BOOL WLog_FileAppender_WriteDataMessage(wLog* log, wLogFileAppender* appender, wLogMessage* message)
|
||||
static BOOL WLog_FileAppender_WriteDataMessage(wLog* log, wLogAppender* appender, wLogMessage* message)
|
||||
{
|
||||
int DataId;
|
||||
char* FullFileName;
|
||||
@ -170,7 +172,7 @@ BOOL WLog_FileAppender_WriteDataMessage(wLog* log, wLogFileAppender* appender, w
|
||||
|
||||
static int g_ImageId = 0;
|
||||
|
||||
int WLog_FileAppender_WriteImageMessage(wLog* log, wLogFileAppender* appender, wLogMessage* message)
|
||||
static int WLog_FileAppender_WriteImageMessage(wLog* log, wLogAppender* appender, wLogMessage* message)
|
||||
{
|
||||
int ImageId;
|
||||
char* FullFileName;
|
||||
@ -189,7 +191,38 @@ int WLog_FileAppender_WriteImageMessage(wLog* log, wLogFileAppender* appender, w
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
wLogFileAppender* WLog_FileAppender_New(wLog* log)
|
||||
static BOOL WLog_FileAppender_Set(wLogAppender* appender, const char *setting, void *value)
|
||||
{
|
||||
wLogFileAppender *fileAppender = (wLogFileAppender *) appender;
|
||||
|
||||
if (!value || !strlen(value))
|
||||
return FALSE;
|
||||
|
||||
if (!strcmp("outputfilename", setting))
|
||||
return WLog_FileAppender_SetOutputFileName(fileAppender, (const char *)value);
|
||||
else if (!strcmp("outputfilepath", setting))
|
||||
return WLog_FileAppender_SetOutputFilePath(fileAppender, (const char *)value);
|
||||
else
|
||||
return FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void WLog_FileAppender_Free(wLogAppender* appender)
|
||||
{
|
||||
wLogFileAppender* fileAppender = NULL;
|
||||
|
||||
if (appender)
|
||||
{
|
||||
fileAppender = (wLogFileAppender *)appender;
|
||||
free(fileAppender->FileName);
|
||||
free(fileAppender->FilePath);
|
||||
free(fileAppender->FullFileName);
|
||||
free(fileAppender);
|
||||
}
|
||||
}
|
||||
|
||||
wLogAppender* WLog_FileAppender_New(wLog* log)
|
||||
{
|
||||
LPSTR env;
|
||||
LPCSTR name;
|
||||
@ -203,14 +236,13 @@ wLogFileAppender* WLog_FileAppender_New(wLog* log)
|
||||
|
||||
FileAppender->Type = WLOG_APPENDER_FILE;
|
||||
|
||||
FileAppender->Open = (WLOG_APPENDER_OPEN_FN) WLog_FileAppender_Open;
|
||||
FileAppender->Close = (WLOG_APPENDER_OPEN_FN) WLog_FileAppender_Close;
|
||||
FileAppender->WriteMessage =
|
||||
(WLOG_APPENDER_WRITE_MESSAGE_FN) WLog_FileAppender_WriteMessage;
|
||||
FileAppender->WriteDataMessage =
|
||||
(WLOG_APPENDER_WRITE_DATA_MESSAGE_FN) WLog_FileAppender_WriteDataMessage;
|
||||
FileAppender->WriteImageMessage =
|
||||
(WLOG_APPENDER_WRITE_IMAGE_MESSAGE_FN) WLog_FileAppender_WriteImageMessage;
|
||||
FileAppender->Open = WLog_FileAppender_Open;
|
||||
FileAppender->Close = WLog_FileAppender_Close;
|
||||
FileAppender->WriteMessage = WLog_FileAppender_WriteMessage;
|
||||
FileAppender->WriteDataMessage = WLog_FileAppender_WriteDataMessage;
|
||||
FileAppender->WriteImageMessage = WLog_FileAppender_WriteImageMessage;
|
||||
FileAppender->Free = WLog_FileAppender_Free;
|
||||
FileAppender->Set = WLog_FileAppender_Set;
|
||||
|
||||
name = "WLOG_FILEAPPENDER_OUTPUT_FILE_PATH";
|
||||
nSize = GetEnvironmentVariableA(name, NULL, 0);
|
||||
@ -221,7 +253,7 @@ wLogFileAppender* WLog_FileAppender_New(wLog* log)
|
||||
goto error_free;
|
||||
|
||||
nSize = GetEnvironmentVariableA(name, env, nSize);
|
||||
status = WLog_FileAppender_SetOutputFilePath(log, FileAppender, env);
|
||||
status = WLog_FileAppender_SetOutputFilePath(FileAppender, env);
|
||||
free(env);
|
||||
|
||||
if (!status)
|
||||
@ -236,15 +268,15 @@ wLogFileAppender* WLog_FileAppender_New(wLog* log)
|
||||
if (!env)
|
||||
goto error_output_file_name;
|
||||
|
||||
nSize = GetEnvironmentVariableA(name, env, nSize);
|
||||
status = WLog_FileAppender_SetOutputFileName(log, FileAppender, env);
|
||||
GetEnvironmentVariableA(name, env, nSize);
|
||||
status = WLog_FileAppender_SetOutputFileName(FileAppender, env);
|
||||
free(env);
|
||||
|
||||
if (!status)
|
||||
goto error_output_file_name;
|
||||
}
|
||||
|
||||
return FileAppender;
|
||||
return (wLogAppender *)FileAppender;
|
||||
|
||||
error_output_file_name:
|
||||
free(FileAppender->FilePath);
|
||||
@ -252,14 +284,3 @@ error_free:
|
||||
free(FileAppender);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void WLog_FileAppender_Free(wLog* log, wLogFileAppender* appender)
|
||||
{
|
||||
if (appender)
|
||||
{
|
||||
free(appender->FileName);
|
||||
free(appender->FilePath);
|
||||
free(appender->FullFileName);
|
||||
free(appender);
|
||||
}
|
||||
}
|
||||
|
@ -20,11 +20,8 @@
|
||||
#ifndef WINPR_WLOG_FILE_APPENDER_PRIVATE_H
|
||||
#define WINPR_WLOG_FILE_APPENDER_PRIVATE_H
|
||||
|
||||
#include <winpr/wlog.h>
|
||||
#include "wlog.h"
|
||||
|
||||
#include "wlog/wlog.h"
|
||||
|
||||
WINPR_API wLogFileAppender* WLog_FileAppender_New(wLog* log);
|
||||
WINPR_API void WLog_FileAppender_Free(wLog* log, wLogFileAppender* appender);
|
||||
wLogAppender* WLog_FileAppender_New(wLog* log);
|
||||
|
||||
#endif /* WINPR_WLOG_FILE_APPENDER_PRIVATE_H */
|
||||
|
@ -21,7 +21,7 @@
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <winpr/wlog.h>
|
||||
#include "wlog.h"
|
||||
#include <winpr/image.h>
|
||||
|
||||
#include "wlog/ImageMessage.h"
|
||||
|
@ -20,10 +20,6 @@
|
||||
#ifndef WINPR_WLOG_IMAGE_MESSAGE_PRIVATE_H
|
||||
#define WINPR_WLOG_IMAGE_MESSAGE_PRIVATE_H
|
||||
|
||||
#include <winpr/wlog.h>
|
||||
|
||||
#include "wlog/wlog.h"
|
||||
|
||||
BOOL WLog_ImageMessage_Write(char* filename, void* data, int width, int height, int bpp);
|
||||
|
||||
#endif /* WINPR_WLOG_IMAGE_MESSAGE_PRIVATE_H */
|
||||
|
@ -22,59 +22,52 @@
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "JournaldAppender.h"
|
||||
|
||||
#include <unistd.h>
|
||||
#include <syslog.h>
|
||||
#include <systemd/sd-journal.h>
|
||||
|
||||
#include <winpr/crt.h>
|
||||
#include <winpr/environment.h>
|
||||
#include <winpr/thread.h>
|
||||
|
||||
#include <winpr/wlog.h>
|
||||
|
||||
#include "wlog/Message.h"
|
||||
#include "wlog/JournaldAppender.h"
|
||||
|
||||
BOOL Wlog_JournaldAppender_SetIdentifier(wLogJournaldAppender* appender, const char *id)
|
||||
struct _wLogJournaldAppender
|
||||
{
|
||||
if (appender->identifier)
|
||||
free(appender->identifier);
|
||||
WLOG_APPENDER_COMMON();
|
||||
char *identifier;
|
||||
FILE *stream;
|
||||
};
|
||||
typedef struct _wLogJournaldAppender wLogJournaldAppender;
|
||||
|
||||
if (appender->stream)
|
||||
{
|
||||
fclose(appender->stream);
|
||||
appender->stream = NULL;
|
||||
}
|
||||
|
||||
return ((appender->identifier = _strdup(id)) != NULL);
|
||||
}
|
||||
|
||||
static BOOL WLog_JournaldAppender_Open(wLog* log, wLogJournaldAppender* appender)
|
||||
static BOOL WLog_JournaldAppender_Open(wLog* log, wLogAppender* appender)
|
||||
{
|
||||
int fd;
|
||||
wLogJournaldAppender *journaldAppender;
|
||||
|
||||
if (!log || !appender)
|
||||
return FALSE;
|
||||
|
||||
if (appender->stream)
|
||||
journaldAppender = (wLogJournaldAppender*)appender;
|
||||
if (journaldAppender->stream)
|
||||
return TRUE;
|
||||
|
||||
fd = sd_journal_stream_fd(appender->identifier, LOG_INFO, 1);
|
||||
fd = sd_journal_stream_fd(journaldAppender->identifier, LOG_INFO, 1);
|
||||
if (fd < 0)
|
||||
return FALSE;
|
||||
|
||||
appender->stream = fdopen(fd, "w");
|
||||
if (!appender->stream)
|
||||
journaldAppender->stream = fdopen(fd, "w");
|
||||
if (!journaldAppender->stream)
|
||||
{
|
||||
close(fd);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
setbuffer(appender->stream, NULL, 0);
|
||||
setbuffer(journaldAppender->stream, NULL, 0);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static BOOL WLog_JournaldAppender_Close(wLog* log, wLogJournaldAppender* appender)
|
||||
static BOOL WLog_JournaldAppender_Close(wLog* log, wLogAppender* appender)
|
||||
{
|
||||
if (!log || !appender)
|
||||
return FALSE;
|
||||
@ -82,13 +75,16 @@ static BOOL WLog_JournaldAppender_Close(wLog* log, wLogJournaldAppender* appende
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static BOOL WLog_JournaldAppender_WriteMessage(wLog* log, wLogJournaldAppender* appender, wLogMessage* message)
|
||||
static BOOL WLog_JournaldAppender_WriteMessage(wLog* log, wLogAppender* appender, wLogMessage* message)
|
||||
{
|
||||
char *formatStr;
|
||||
wLogJournaldAppender* journaldAppender;
|
||||
|
||||
if (!log || !appender || !message)
|
||||
return FALSE;
|
||||
|
||||
journaldAppender = (wLogJournaldAppender *)appender;
|
||||
|
||||
switch (message->Level)
|
||||
{
|
||||
case WLOG_TRACE:
|
||||
@ -114,11 +110,11 @@ static BOOL WLog_JournaldAppender_WriteMessage(wLog* log, wLogJournaldAppender*
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
fprintf(appender->stream, formatStr, message->TextString);
|
||||
fprintf(journaldAppender->stream, formatStr, message->TextString);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static BOOL WLog_JournaldAppender_WriteDataMessage(wLog* log, wLogJournaldAppender* appender, wLogMessage* message)
|
||||
static BOOL WLog_JournaldAppender_WriteDataMessage(wLog* log, wLogAppender* appender, wLogMessage* message)
|
||||
{
|
||||
if (!log || !appender || !message)
|
||||
return FALSE;
|
||||
@ -126,7 +122,7 @@ static BOOL WLog_JournaldAppender_WriteDataMessage(wLog* log, wLogJournaldAppend
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static BOOL WLog_JournaldAppender_WriteImageMessage(wLog* log, wLogJournaldAppender* appender, wLogMessage* message)
|
||||
static BOOL WLog_JournaldAppender_WriteImageMessage(wLog* log, wLogAppender* appender, wLogMessage* message)
|
||||
{
|
||||
if (!log || !appender || !message)
|
||||
return FALSE;
|
||||
@ -135,7 +131,40 @@ static BOOL WLog_JournaldAppender_WriteImageMessage(wLog* log, wLogJournaldAppen
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
wLogJournaldAppender* WLog_JournaldAppender_New(wLog* log)
|
||||
static BOOL WLog_JournaldAppender_Set(wLogAppender* appender, const char *setting, void *value)
|
||||
{
|
||||
wLogJournaldAppender* journaldAppender = (wLogJournaldAppender *)appender;
|
||||
|
||||
if (!value || !strlen(value))
|
||||
return FALSE;
|
||||
|
||||
if (strcmp("identifier", setting))
|
||||
return FALSE;
|
||||
|
||||
/* If the stream is already open the identifier can't be changed */
|
||||
if (journaldAppender->stream)
|
||||
return FALSE;
|
||||
|
||||
if (journaldAppender->identifier)
|
||||
free(journaldAppender->identifier);
|
||||
|
||||
return ((journaldAppender->identifier = _strdup((const char *)value)) != NULL);
|
||||
}
|
||||
|
||||
static void WLog_JournaldAppender_Free(wLogAppender* appender)
|
||||
{
|
||||
wLogJournaldAppender *journaldAppender;
|
||||
if (appender)
|
||||
{
|
||||
journaldAppender = (wLogJournaldAppender*)appender;
|
||||
if (journaldAppender->stream)
|
||||
fclose(journaldAppender->stream);
|
||||
free(journaldAppender->identifier);
|
||||
free(journaldAppender);
|
||||
}
|
||||
}
|
||||
|
||||
wLogAppender* WLog_JournaldAppender_New(wLog* log)
|
||||
{
|
||||
wLogJournaldAppender* appender;
|
||||
DWORD nSize;
|
||||
@ -146,15 +175,13 @@ wLogJournaldAppender* WLog_JournaldAppender_New(wLog* log)
|
||||
return NULL;
|
||||
|
||||
appender->Type = WLOG_APPENDER_JOURNALD;
|
||||
|
||||
appender->Open = (WLOG_APPENDER_OPEN_FN) WLog_JournaldAppender_Open;
|
||||
appender->Close = (WLOG_APPENDER_OPEN_FN) WLog_JournaldAppender_Close;
|
||||
appender->WriteMessage =
|
||||
(WLOG_APPENDER_WRITE_MESSAGE_FN) WLog_JournaldAppender_WriteMessage;
|
||||
appender->WriteDataMessage =
|
||||
(WLOG_APPENDER_WRITE_DATA_MESSAGE_FN) WLog_JournaldAppender_WriteDataMessage;
|
||||
appender->WriteImageMessage =
|
||||
(WLOG_APPENDER_WRITE_IMAGE_MESSAGE_FN) WLog_JournaldAppender_WriteImageMessage;
|
||||
appender->Open = WLog_JournaldAppender_Open;
|
||||
appender->Close = WLog_JournaldAppender_Close;
|
||||
appender->WriteMessage = WLog_JournaldAppender_WriteMessage;
|
||||
appender->WriteDataMessage = WLog_JournaldAppender_WriteDataMessage;
|
||||
appender->WriteImageMessage = WLog_JournaldAppender_WriteImageMessage;
|
||||
appender->Set = WLog_JournaldAppender_Set;
|
||||
appender->Free = WLog_JournaldAppender_Free;
|
||||
|
||||
name = "WLOG_JOURNALD_ID";
|
||||
nSize = GetEnvironmentVariableA(name, NULL, 0);
|
||||
@ -166,17 +193,11 @@ wLogJournaldAppender* WLog_JournaldAppender_New(wLog* log)
|
||||
|
||||
GetEnvironmentVariableA(name, appender->identifier, nSize);
|
||||
|
||||
if (!WLog_JournaldAppender_Open(log, appender))
|
||||
if (!WLog_JournaldAppender_Open(log, (wLogAppender *)appender))
|
||||
goto error_open;
|
||||
}
|
||||
else
|
||||
{
|
||||
appender->identifier = _strdup("winpr");
|
||||
if (!appender->identifier)
|
||||
goto error_env_malloc;
|
||||
}
|
||||
|
||||
return appender;
|
||||
return (wLogAppender *)appender;
|
||||
|
||||
error_open:
|
||||
free(appender->identifier);
|
||||
@ -184,14 +205,3 @@ error_env_malloc:
|
||||
free(appender);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void WLog_JournaldAppender_Free(wLog* log, wLogJournaldAppender* appender)
|
||||
{
|
||||
if (appender)
|
||||
{
|
||||
if (appender->stream)
|
||||
fclose(appender->stream);
|
||||
free(appender->identifier);
|
||||
free(appender);
|
||||
}
|
||||
}
|
||||
|
@ -24,13 +24,8 @@
|
||||
#ifndef WINPR_LIBWINPR_UTILS_WLOG_JOURNALDAPPENDER_H_
|
||||
#define WINPR_LIBWINPR_UTILS_WLOG_JOURNALDAPPENDER_H_
|
||||
|
||||
#include <winpr/wlog.h>
|
||||
|
||||
#include "wlog/wlog.h"
|
||||
|
||||
WINPR_API wLogJournaldAppender* WLog_JournaldAppender_New(wLog* log);
|
||||
WINPR_API void WLog_JournaldAppender_Free(wLog* log, wLogJournaldAppender* appender);
|
||||
WINPR_API BOOL Wlog_JournaldAppender_SetIdentifier(wLogJournaldAppender* appender, const char *id);
|
||||
#include "wlog.h"
|
||||
|
||||
wLogAppender* WLog_JournaldAppender_New(wLog* log);
|
||||
|
||||
#endif /* WINPR_LIBWINPR_UTILS_WLOG_JOURNALDAPPENDER_H_ */
|
||||
|
@ -30,7 +30,7 @@
|
||||
#include <winpr/sysinfo.h>
|
||||
#include <winpr/environment.h>
|
||||
|
||||
#include <winpr/wlog.h>
|
||||
#include "wlog.h"
|
||||
|
||||
#include "wlog/Layout.h"
|
||||
|
||||
|
@ -20,7 +20,18 @@
|
||||
#ifndef WINPR_WLOG_LAYOUT_PRIVATE_H
|
||||
#define WINPR_WLOG_LAYOUT_PRIVATE_H
|
||||
|
||||
#include <winpr/wlog.h>
|
||||
#include "wlog.h"
|
||||
|
||||
/**
|
||||
* Log Layout
|
||||
*/
|
||||
|
||||
struct _wLogLayout
|
||||
{
|
||||
DWORD Type;
|
||||
|
||||
LPSTR FormatString;
|
||||
};
|
||||
|
||||
wLogLayout* WLog_Layout_New(wLog* log);
|
||||
void WLog_Layout_Free(wLog* log, wLogLayout* layout);
|
||||
|
@ -25,9 +25,9 @@
|
||||
#include <winpr/path.h>
|
||||
#include <winpr/file.h>
|
||||
|
||||
#include <winpr/wlog.h>
|
||||
#include "wlog.h"
|
||||
|
||||
#include "wlog/Message.h"
|
||||
#include "Message.h"
|
||||
|
||||
char* WLog_Message_GetOutputFileName(int id, const char* ext)
|
||||
{
|
||||
|
@ -20,14 +20,9 @@
|
||||
#ifndef WINPR_WLOG_MESSAGE_PRIVATE_H
|
||||
#define WINPR_WLOG_MESSAGE_PRIVATE_H
|
||||
|
||||
#include <winpr/wlog.h>
|
||||
|
||||
#include "wlog/wlog.h"
|
||||
|
||||
#include "wlog/TextMessage.h"
|
||||
#include "wlog/DataMessage.h"
|
||||
#include "wlog/ImageMessage.h"
|
||||
#include "wlog/PacketMessage.h"
|
||||
#include "DataMessage.h"
|
||||
#include "ImageMessage.h"
|
||||
#include "PacketMessage.h"
|
||||
|
||||
char* WLog_Message_GetOutputFileName(int id, const char* ext);
|
||||
|
||||
|
@ -23,7 +23,7 @@
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <winpr/wlog.h>
|
||||
#include "wlog.h"
|
||||
|
||||
#include "wlog/PacketMessage.h"
|
||||
|
||||
|
@ -20,9 +20,7 @@
|
||||
#ifndef WINPR_WLOG_PACKET_MESSAGE_PRIVATE_H
|
||||
#define WINPR_WLOG_PACKET_MESSAGE_PRIVATE_H
|
||||
|
||||
#include <winpr/wlog.h>
|
||||
|
||||
#include "wlog/wlog.h"
|
||||
#include "wlog.h"
|
||||
|
||||
#define PCAP_MAGIC_NUMBER 0xA1B2C3D4
|
||||
|
||||
|
@ -2,7 +2,8 @@
|
||||
* WinPR: Windows Portable Runtime
|
||||
* WinPR Logger
|
||||
*
|
||||
* Copyright 2013 David FORT <contact@hardening-consulting.com>
|
||||
* Copyright © 2015 Thincast Technologies GmbH
|
||||
* Copyright © 2015 David FORT <contact@hardening-consulting.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -21,16 +22,14 @@
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "SyslogAppender.h"
|
||||
#include <syslog.h>
|
||||
|
||||
#include <winpr/crt.h>
|
||||
#include <winpr/environment.h>
|
||||
#include <winpr/thread.h>
|
||||
|
||||
#include <winpr/wlog.h>
|
||||
|
||||
#include "wlog/Message.h"
|
||||
#include "wlog/SyslogAppender.h"
|
||||
struct _wLogSyslogAppender
|
||||
{
|
||||
WLOG_APPENDER_COMMON();
|
||||
};
|
||||
typedef struct _wLogSyslogAppender wLogSyslogAppender;
|
||||
|
||||
static int getSyslogLevel(DWORD level)
|
||||
{
|
||||
@ -53,7 +52,7 @@ static int getSyslogLevel(DWORD level)
|
||||
}
|
||||
}
|
||||
|
||||
static BOOL WLog_SyslogAppender_Open(wLog* log, wLogSyslogAppender* appender)
|
||||
static BOOL WLog_SyslogAppender_Open(wLog* log, wLogAppender* appender)
|
||||
{
|
||||
if (!log || !appender)
|
||||
return FALSE;
|
||||
@ -61,7 +60,7 @@ static BOOL WLog_SyslogAppender_Open(wLog* log, wLogSyslogAppender* appender)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static BOOL WLog_SyslogAppender_Close(wLog* log, wLogSyslogAppender* appender)
|
||||
static BOOL WLog_SyslogAppender_Close(wLog* log, wLogAppender* appender)
|
||||
{
|
||||
if (!log || !appender)
|
||||
return FALSE;
|
||||
@ -69,7 +68,7 @@ static BOOL WLog_SyslogAppender_Close(wLog* log, wLogSyslogAppender* appender)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static BOOL WLog_SyslogAppender_WriteMessage(wLog* log, wLogSyslogAppender* appender, wLogMessage* message)
|
||||
static BOOL WLog_SyslogAppender_WriteMessage(wLog* log, wLogAppender* appender, wLogMessage* message)
|
||||
{
|
||||
int syslogLevel;
|
||||
|
||||
@ -83,7 +82,7 @@ static BOOL WLog_SyslogAppender_WriteMessage(wLog* log, wLogSyslogAppender* appe
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static BOOL WLog_SyslogAppender_WriteDataMessage(wLog* log, wLogSyslogAppender* appender, wLogMessage* message)
|
||||
static BOOL WLog_SyslogAppender_WriteDataMessage(wLog* log, wLogAppender* appender, wLogMessage* message)
|
||||
{
|
||||
int syslogLevel;
|
||||
|
||||
@ -97,7 +96,7 @@ static BOOL WLog_SyslogAppender_WriteDataMessage(wLog* log, wLogSyslogAppender*
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static BOOL WLog_SyslogAppender_WriteImageMessage(wLog* log, wLogSyslogAppender* appender, wLogMessage* message)
|
||||
static BOOL WLog_SyslogAppender_WriteImageMessage(wLog* log, wLogAppender* appender, wLogMessage* message)
|
||||
{
|
||||
int syslogLevel;
|
||||
|
||||
@ -111,7 +110,12 @@ static BOOL WLog_SyslogAppender_WriteImageMessage(wLog* log, wLogSyslogAppender*
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
wLogSyslogAppender* WLog_SyslogAppender_New(wLog* log)
|
||||
void WLog_SyslogAppender_Free(wLogAppender* appender)
|
||||
{
|
||||
free(appender);
|
||||
}
|
||||
|
||||
wLogAppender* WLog_SyslogAppender_New(wLog* log)
|
||||
{
|
||||
wLogSyslogAppender* appender;
|
||||
|
||||
@ -121,20 +125,12 @@ wLogSyslogAppender* WLog_SyslogAppender_New(wLog* log)
|
||||
|
||||
appender->Type = WLOG_APPENDER_SYSLOG;
|
||||
|
||||
appender->Open = (WLOG_APPENDER_OPEN_FN) WLog_SyslogAppender_Open;
|
||||
appender->Close = (WLOG_APPENDER_OPEN_FN) WLog_SyslogAppender_Close;
|
||||
appender->WriteMessage =
|
||||
(WLOG_APPENDER_WRITE_MESSAGE_FN) WLog_SyslogAppender_WriteMessage;
|
||||
appender->WriteDataMessage =
|
||||
(WLOG_APPENDER_WRITE_DATA_MESSAGE_FN) WLog_SyslogAppender_WriteDataMessage;
|
||||
appender->WriteImageMessage =
|
||||
(WLOG_APPENDER_WRITE_IMAGE_MESSAGE_FN) WLog_SyslogAppender_WriteImageMessage;
|
||||
appender->Open = WLog_SyslogAppender_Open;
|
||||
appender->Close = WLog_SyslogAppender_Close;
|
||||
appender->WriteMessage = WLog_SyslogAppender_WriteMessage;
|
||||
appender->WriteDataMessage = WLog_SyslogAppender_WriteDataMessage;
|
||||
appender->WriteImageMessage = WLog_SyslogAppender_WriteImageMessage;
|
||||
appender->Free = WLog_SyslogAppender_Free;
|
||||
|
||||
return appender;
|
||||
}
|
||||
|
||||
void WLog_SyslogAppender_Free(wLog* log, wLogSyslogAppender* appender)
|
||||
{
|
||||
if (appender)
|
||||
free(appender);
|
||||
return (wLogAppender*)appender;
|
||||
}
|
||||
|
@ -24,12 +24,8 @@
|
||||
#ifndef WINPR_LIBWINPR_UTILS_WLOG_SYSLOGAPPENDER_H_
|
||||
#define WINPR_LIBWINPR_UTILS_WLOG_SYSLOGAPPENDER_H_
|
||||
|
||||
#include <winpr/wlog.h>
|
||||
|
||||
#include "wlog/wlog.h"
|
||||
|
||||
WINPR_API wLogSyslogAppender* WLog_SyslogAppender_New(wLog* log);
|
||||
WINPR_API void WLog_SyslogAppender_Free(wLog* log, wLogSyslogAppender* appender);
|
||||
#include "wlog.h"
|
||||
|
||||
wLogAppender* WLog_SyslogAppender_New(wLog* log);
|
||||
|
||||
#endif /* WINPR_LIBWINPR_UTILS_WLOG_SYSLOGAPPENDER_H_ */
|
||||
|
@ -21,10 +21,6 @@
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <winpr/wlog.h>
|
||||
|
||||
#include "wlog/TextMessage.h"
|
||||
|
||||
void wlog_TextMessage_dummy()
|
||||
{
|
||||
/* avoid no symbol ranlib warning */
|
||||
|
@ -1,30 +0,0 @@
|
||||
/**
|
||||
* WinPR: Windows Portable Runtime
|
||||
* WinPR Logger
|
||||
*
|
||||
* Copyright 2013 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef WINPR_WLOG_TEXT_MESSAGE_PRIVATE_H
|
||||
#define WINPR_WLOG_TEXT_MESSAGE_PRIVATE_H
|
||||
|
||||
#include <winpr/wlog.h>
|
||||
|
||||
#include "wlog/wlog.h"
|
||||
|
||||
|
||||
|
||||
#endif /* WINPR_WLOG_TEXT_MESSAGE_PRIVATE_H */
|
||||
|
@ -25,39 +25,43 @@
|
||||
|
||||
#include <winpr/crt.h>
|
||||
#include <winpr/environment.h>
|
||||
#include <winpr/thread.h>
|
||||
#include <winpr/winsock.h>
|
||||
|
||||
#include <winpr/wlog.h>
|
||||
#include "wlog.h"
|
||||
|
||||
#include "wlog/Message.h"
|
||||
#include "wlog/UdpAppender.h"
|
||||
|
||||
#ifndef _WIN32
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#endif
|
||||
|
||||
static BOOL WLog_UdpAppender_Open(wLog* log, wLogUdpAppender* appender)
|
||||
struct _wLogUdpAppender
|
||||
{
|
||||
WLOG_APPENDER_COMMON();
|
||||
char *host;
|
||||
struct sockaddr targetAddr;
|
||||
int targetAddrLen;
|
||||
SOCKET sock;
|
||||
};
|
||||
typedef struct _wLogUdpAppender wLogUdpAppender;
|
||||
|
||||
static BOOL WLog_UdpAppender_Open(wLog* log, wLogAppender* appender)
|
||||
{
|
||||
wLogUdpAppender *udpAppender;
|
||||
char addressString[256];
|
||||
struct addrinfo hints;
|
||||
struct addrinfo* result;
|
||||
int status, addrLen;
|
||||
char *colonPos;
|
||||
|
||||
|
||||
if (!appender)
|
||||
return FALSE;
|
||||
|
||||
if (appender->targetAddrLen) /* already opened */
|
||||
udpAppender = (wLogUdpAppender*)appender;
|
||||
|
||||
if (udpAppender->targetAddrLen) /* already opened */
|
||||
return TRUE;
|
||||
|
||||
colonPos = strchr(appender->host, ':');
|
||||
colonPos = strchr(udpAppender->host, ':');
|
||||
if (!colonPos)
|
||||
return FALSE;
|
||||
addrLen = colonPos - appender->host;
|
||||
memcpy(addressString, appender->host, addrLen);
|
||||
addrLen = colonPos - udpAppender->host;
|
||||
memcpy(addressString, udpAppender->host, addrLen);
|
||||
addressString[addrLen] = '\0';
|
||||
|
||||
ZeroMemory(&hints, sizeof(hints));
|
||||
@ -68,31 +72,19 @@ static BOOL WLog_UdpAppender_Open(wLog* log, wLogUdpAppender* appender)
|
||||
if (status != 0)
|
||||
return FALSE;
|
||||
|
||||
if (result->ai_addrlen > sizeof(appender->targetAddr))
|
||||
if (result->ai_addrlen > sizeof(udpAppender->targetAddr))
|
||||
{
|
||||
freeaddrinfo(result);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
memcpy(&appender->targetAddr, result->ai_addr, result->ai_addrlen);
|
||||
appender->targetAddrLen = result->ai_addrlen;
|
||||
|
||||
memcpy(&udpAppender->targetAddr, result->ai_addr, result->ai_addrlen);
|
||||
udpAppender->targetAddrLen = result->ai_addrlen;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL Wlog_UdpAppender_SetTarget(wLogUdpAppender* appender, const char *host)
|
||||
{
|
||||
|
||||
appender->targetAddrLen = 0;
|
||||
if (appender->host)
|
||||
free(appender->host);
|
||||
|
||||
appender->host = _strdup(host);
|
||||
return (appender->host != NULL) && WLog_UdpAppender_Open(NULL, appender);
|
||||
}
|
||||
|
||||
static BOOL WLog_UdpAppender_Close(wLog* log, wLogUdpAppender* appender)
|
||||
static BOOL WLog_UdpAppender_Close(wLog* log, wLogAppender* appender)
|
||||
{
|
||||
if (!log || !appender)
|
||||
return FALSE;
|
||||
@ -100,28 +92,32 @@ static BOOL WLog_UdpAppender_Close(wLog* log, wLogUdpAppender* appender)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static BOOL WLog_UdpAppender_WriteMessage(wLog* log, wLogUdpAppender* appender, wLogMessage* message)
|
||||
static BOOL WLog_UdpAppender_WriteMessage(wLog* log, wLogAppender* appender, wLogMessage* message)
|
||||
{
|
||||
char prefix[WLOG_MAX_PREFIX_SIZE];
|
||||
wLogUdpAppender *udpAppender;
|
||||
|
||||
|
||||
if (!log || !appender || !message)
|
||||
return FALSE;
|
||||
|
||||
udpAppender = (wLogUdpAppender *)appender;
|
||||
|
||||
message->PrefixString = prefix;
|
||||
WLog_Layout_GetMessagePrefix(log, appender->Layout, message);
|
||||
|
||||
_sendto(appender->sock, message->PrefixString, strlen(message->PrefixString),
|
||||
0, &appender->targetAddr, appender->targetAddrLen);
|
||||
_sendto(udpAppender->sock, message->PrefixString, strlen(message->PrefixString),
|
||||
0, &udpAppender->targetAddr, udpAppender->targetAddrLen);
|
||||
|
||||
_sendto(appender->sock, message->TextString, strlen(message->TextString),
|
||||
0, &appender->targetAddr, appender->targetAddrLen);
|
||||
_sendto(udpAppender->sock, message->TextString, strlen(message->TextString),
|
||||
0, &udpAppender->targetAddr, udpAppender->targetAddrLen);
|
||||
|
||||
_sendto(appender->sock, "\n", 1, 0, &appender->targetAddr, appender->targetAddrLen);
|
||||
_sendto(udpAppender->sock, "\n", 1, 0, &udpAppender->targetAddr, udpAppender->targetAddrLen);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static BOOL WLog_UdpAppender_WriteDataMessage(wLog* log, wLogUdpAppender* appender, wLogMessage* message)
|
||||
static BOOL WLog_UdpAppender_WriteDataMessage(wLog* log, wLogAppender* appender, wLogMessage* message)
|
||||
{
|
||||
if (!log || !appender || !message)
|
||||
return FALSE;
|
||||
@ -129,7 +125,7 @@ static BOOL WLog_UdpAppender_WriteDataMessage(wLog* log, wLogUdpAppender* append
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static BOOL WLog_UdpAppender_WriteImageMessage(wLog* log, wLogUdpAppender* appender, wLogMessage* message)
|
||||
static BOOL WLog_UdpAppender_WriteImageMessage(wLog* log, wLogAppender* appender, wLogMessage* message)
|
||||
{
|
||||
if (!log || !appender || !message)
|
||||
return FALSE;
|
||||
@ -138,7 +134,41 @@ static BOOL WLog_UdpAppender_WriteImageMessage(wLog* log, wLogUdpAppender* appen
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
wLogUdpAppender* WLog_UdpAppender_New(wLog* log)
|
||||
static BOOL WLog_UdpAppender_Set(wLogAppender* appender, const char *setting, void *value)
|
||||
{
|
||||
wLogUdpAppender *udpAppender = (wLogUdpAppender *)appender;
|
||||
|
||||
if (!value || !strlen(value))
|
||||
return FALSE;
|
||||
|
||||
if (strcmp("target", setting))
|
||||
return FALSE;
|
||||
|
||||
udpAppender->targetAddrLen = 0;
|
||||
if (udpAppender->host)
|
||||
free(udpAppender->host);
|
||||
|
||||
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;
|
||||
if (udpAppender->sock != INVALID_SOCKET)
|
||||
{
|
||||
closesocket(udpAppender->sock);
|
||||
udpAppender->sock = INVALID_SOCKET;
|
||||
}
|
||||
free(udpAppender->host);
|
||||
free(udpAppender);
|
||||
}
|
||||
}
|
||||
|
||||
wLogAppender* WLog_UdpAppender_New(wLog* log)
|
||||
{
|
||||
wLogUdpAppender* appender;
|
||||
DWORD nSize;
|
||||
@ -150,14 +180,13 @@ wLogUdpAppender* WLog_UdpAppender_New(wLog* log)
|
||||
|
||||
appender->Type = WLOG_APPENDER_UDP;
|
||||
|
||||
appender->Open = (WLOG_APPENDER_OPEN_FN) WLog_UdpAppender_Open;
|
||||
appender->Close = (WLOG_APPENDER_OPEN_FN) WLog_UdpAppender_Close;
|
||||
appender->WriteMessage =
|
||||
(WLOG_APPENDER_WRITE_MESSAGE_FN) WLog_UdpAppender_WriteMessage;
|
||||
appender->WriteDataMessage =
|
||||
(WLOG_APPENDER_WRITE_DATA_MESSAGE_FN) WLog_UdpAppender_WriteDataMessage;
|
||||
appender->WriteImageMessage =
|
||||
(WLOG_APPENDER_WRITE_IMAGE_MESSAGE_FN) WLog_UdpAppender_WriteImageMessage;
|
||||
appender->Open = WLog_UdpAppender_Open;
|
||||
appender->Close = WLog_UdpAppender_Close;
|
||||
appender->WriteMessage = WLog_UdpAppender_WriteMessage;
|
||||
appender->WriteDataMessage = WLog_UdpAppender_WriteDataMessage;
|
||||
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)
|
||||
@ -173,7 +202,7 @@ wLogUdpAppender* WLog_UdpAppender_New(wLog* log)
|
||||
|
||||
GetEnvironmentVariableA(name, appender->host, nSize);
|
||||
|
||||
if (!WLog_UdpAppender_Open(log, appender))
|
||||
if (!WLog_UdpAppender_Open(log, (wLogAppender *)appender))
|
||||
goto error_open;
|
||||
}
|
||||
else
|
||||
@ -183,7 +212,7 @@ wLogUdpAppender* WLog_UdpAppender_New(wLog* log)
|
||||
goto error_host_alloc;
|
||||
}
|
||||
|
||||
return appender;
|
||||
return (wLogAppender*)appender;
|
||||
|
||||
error_open:
|
||||
free(appender->host);
|
||||
@ -193,17 +222,3 @@ error_sock:
|
||||
free(appender);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void WLog_UdpAppender_Free(wLog* log, wLogUdpAppender* appender)
|
||||
{
|
||||
if (appender)
|
||||
{
|
||||
if (appender->sock != INVALID_SOCKET)
|
||||
{
|
||||
closesocket(appender->sock);
|
||||
appender->sock = INVALID_SOCKET;
|
||||
}
|
||||
free(appender->host);
|
||||
free(appender);
|
||||
}
|
||||
}
|
||||
|
@ -28,8 +28,6 @@
|
||||
|
||||
#include "wlog/wlog.h"
|
||||
|
||||
WINPR_API wLogUdpAppender* WLog_UdpAppender_New(wLog* log);
|
||||
WINPR_API void WLog_UdpAppender_Free(wLog* log, wLogUdpAppender* appender);
|
||||
WINPR_API BOOL Wlog_UdpAppender_SetTarget(wLogUdpAppender* appender, const char *host);
|
||||
wLogAppender* WLog_UdpAppender_New(wLog* log);
|
||||
|
||||
#endif /* WINPR_LIBWINPR_UTILS_WLOG_UDPAPPENDER_H_ */
|
||||
|
@ -31,13 +31,19 @@
|
||||
|
||||
#if defined(ANDROID)
|
||||
#include <android/log.h>
|
||||
#include "../log.h"
|
||||
#endif
|
||||
|
||||
#include <winpr/wlog.h>
|
||||
#include "wlog.h"
|
||||
|
||||
#include "wlog/wlog.h"
|
||||
|
||||
#include "../../log.h"
|
||||
struct _wLogFilter
|
||||
{
|
||||
DWORD Level;
|
||||
LPSTR* Names;
|
||||
DWORD NameCount;
|
||||
};
|
||||
typedef struct _wLogFilter wLogFilter;
|
||||
|
||||
/**
|
||||
* References for general logging concepts:
|
||||
@ -114,7 +120,7 @@ BOOL WLog_Write(wLog* log, wLogMessage* message)
|
||||
if (!appender)
|
||||
return FALSE;
|
||||
|
||||
if (!appender->State)
|
||||
if (!appender->active)
|
||||
if (!WLog_OpenAppender(log))
|
||||
return FALSE;
|
||||
|
||||
@ -145,7 +151,7 @@ BOOL WLog_WriteData(wLog* log, wLogMessage* message)
|
||||
if (!appender)
|
||||
return FALSE;
|
||||
|
||||
if (!appender->State)
|
||||
if (!appender->active)
|
||||
if (!WLog_OpenAppender(log))
|
||||
return FALSE;
|
||||
|
||||
@ -176,7 +182,7 @@ BOOL WLog_WriteImage(wLog* log, wLogMessage* message)
|
||||
if (!appender)
|
||||
return FALSE;
|
||||
|
||||
if (!appender->State)
|
||||
if (!appender->active)
|
||||
if (!WLog_OpenAppender(log))
|
||||
return FALSE;
|
||||
|
||||
@ -207,7 +213,7 @@ BOOL WLog_WritePacket(wLog* log, wLogMessage* message)
|
||||
if (!appender)
|
||||
return FALSE;
|
||||
|
||||
if (!appender->State)
|
||||
if (!appender->active)
|
||||
if (!WLog_OpenAppender(log))
|
||||
return FALSE;
|
||||
|
||||
|
@ -25,9 +25,62 @@
|
||||
#define WLOG_MAX_PREFIX_SIZE 512
|
||||
#define WLOG_MAX_STRING_SIZE 8192
|
||||
|
||||
|
||||
typedef BOOL (*WLOG_APPENDER_OPEN_FN)(wLog* log, wLogAppender* appender);
|
||||
typedef BOOL (*WLOG_APPENDER_CLOSE_FN)(wLog* log, wLogAppender* appender);
|
||||
typedef BOOL (*WLOG_APPENDER_WRITE_MESSAGE_FN)(wLog* log, wLogAppender* appender, wLogMessage* message);
|
||||
typedef BOOL (*WLOG_APPENDER_WRITE_DATA_MESSAGE_FN)(wLog* log, wLogAppender* appender, wLogMessage* message);
|
||||
typedef BOOL (*WLOG_APPENDER_WRITE_IMAGE_MESSAGE_FN)(wLog* log, wLogAppender* appender, wLogMessage* message);
|
||||
typedef BOOL (*WLOG_APPENDER_WRITE_PACKET_MESSAGE_FN)(wLog* log, wLogAppender* appender, wLogMessage* message);
|
||||
typedef BOOL (*WLOG_APPENDER_SET)(wLogAppender* appender, const char *setting, void *value);
|
||||
typedef void (*WLOG_APPENDER_FREE)(wLogAppender* appender);
|
||||
|
||||
#define WLOG_APPENDER_COMMON() \
|
||||
DWORD Type; \
|
||||
BOOL active; \
|
||||
wLogLayout* Layout; \
|
||||
CRITICAL_SECTION lock; \
|
||||
BOOL recursive; \
|
||||
void* TextMessageContext; \
|
||||
void* DataMessageContext; \
|
||||
void* ImageMessageContext; \
|
||||
void* PacketMessageContext; \
|
||||
WLOG_APPENDER_OPEN_FN Open; \
|
||||
WLOG_APPENDER_CLOSE_FN Close; \
|
||||
WLOG_APPENDER_WRITE_MESSAGE_FN WriteMessage; \
|
||||
WLOG_APPENDER_WRITE_DATA_MESSAGE_FN WriteDataMessage; \
|
||||
WLOG_APPENDER_WRITE_IMAGE_MESSAGE_FN WriteImageMessage; \
|
||||
WLOG_APPENDER_WRITE_PACKET_MESSAGE_FN WritePacketMessage; \
|
||||
WLOG_APPENDER_FREE Free; \
|
||||
WLOG_APPENDER_SET Set
|
||||
|
||||
|
||||
struct _wLogAppender
|
||||
{
|
||||
WLOG_APPENDER_COMMON();
|
||||
};
|
||||
|
||||
struct _wLog
|
||||
{
|
||||
LPSTR Name;
|
||||
DWORD Level;
|
||||
|
||||
BOOL IsRoot;
|
||||
LPSTR* Names;
|
||||
DWORD NameCount;
|
||||
wLogAppender* Appender;
|
||||
|
||||
wLog* Parent;
|
||||
wLog** Children;
|
||||
DWORD ChildrenCount;
|
||||
DWORD ChildrenSize;
|
||||
};
|
||||
|
||||
|
||||
BOOL WLog_Layout_GetMessagePrefix(wLog* log, wLogLayout* layout, wLogMessage* message);
|
||||
|
||||
#include "wlog/Layout.h"
|
||||
#include "wlog/Appender.h"
|
||||
|
||||
|
||||
#endif /* WINPR_WLOG_PRIVATE_H */
|
||||
|
Loading…
Reference in New Issue
Block a user