WLog using C99 compatible variadic macros.
authorArmin Novak <armin.novak@thincast.com>
Fri, 7 Oct 2016 12:04:40 +0000 (14:04 +0200)
committerArmin Novak <armin.novak@thincast.com>
Fri, 7 Oct 2016 12:05:27 +0000 (14:05 +0200)
30 files changed:
channels/audin/client/audin_main.h
channels/cliprdr/client/cliprdr_main.h
channels/echo/client/echo_main.h
channels/printer/client/printer_win.h
channels/rdpei/client/rdpei_main.h
channels/rdpsnd/client/rdpsnd_main.h
channels/tsmf/client/tsmf_types.h
channels/urbdrc/client/urbdrc_types.h
client/Windows/wf_cliprdr.c
client/Windows/wf_event.h
client/X11/xf_client.c
client/X11/xf_event.c
client/X11/xf_window.c
libfreerdp/codec/rfx_types.h
libfreerdp/core/certificate.h
libfreerdp/core/license.h
libfreerdp/core/rdp.h
libfreerdp/core/redirection.h
libfreerdp/core/server.c
libfreerdp/core/timezone.h
libfreerdp/core/transport.c
libfreerdp/core/window.h
libfreerdp/locale/liblocale.h
libfreerdp/utils/msusb.c
libfreerdp/utils/ringbuffer.c
winpr/include/winpr/wlog.h
winpr/libwinpr/comm/comm.c
winpr/libwinpr/comm/comm.h
winpr/libwinpr/comm/comm_io.c
winpr/libwinpr/utils/wlog/wlog.c

index 05dd637..50a0b6c 100644 (file)
@@ -33,9 +33,9 @@
 #define TAG CHANNELS_TAG("audin.client")
 
 #ifdef WITH_DEBUG_DVC
-#define DEBUG_DVC(fmt, ...) WLog_DBG(TAG, fmt, ## __VA_ARGS__)
+#define DEBUG_DVC(...) WLog_DBG(TAG, __VA_ARGS__)
 #else
-#define DEBUG_DVC(fmt, ...) do { } while (0)
+#define DEBUG_DVC(...) do { } while (0)
 #endif
 
 #endif /* FREERDP_AUDIN_CLIENT_MAIN_H */
index 34d9cf8..ac0d752 100644 (file)
@@ -55,9 +55,9 @@ typedef struct cliprdr_plugin cliprdrPlugin;
 CliprdrClientContext* cliprdr_get_client_interface(cliprdrPlugin* cliprdr);
 
 #ifdef WITH_DEBUG_CLIPRDR
-#define DEBUG_CLIPRDR(fmt, ...) WLog_DBG(TAG, fmt, ## __VA_ARGS__)
+#define DEBUG_CLIPRDR(...) WLog_DBG(TAG, __VA_ARGS__)
 #else
-#define DEBUG_CLIPRDR(fmt, ...) do { } while (0)
+#define DEBUG_CLIPRDR(...) do { } while (0)
 #endif
 
 #endif /* __CLIPRDR_MAIN_H */
index 1ce6a1f..565142f 100644 (file)
@@ -31,9 +31,9 @@
 
 #define DVC_TAG CHANNELS_TAG("echo.client")
 #ifdef WITH_DEBUG_DVC
-#define DEBUG_DVC(fmt, ...) WLog_DBG(DVC_TAG, fmt, ## __VA_ARGS__)
+#define DEBUG_DVC(...) WLog_DBG(DVC_TAG, __VA_ARGS__)
 #else
-#define DEBUG_DVC(fmt, ...) do { } while (0)
+#define DEBUG_DVC(...) do { } while (0)
 #endif
 
 #endif /* __ECHO_MAIN_H */
index fbd1dbc..c0a0420 100644 (file)
@@ -26,9 +26,9 @@ rdpPrinterDriver* printer_win_get_driver(void);
 
 #define PRINTER_TAG CHANNELS_TAG("printer.client")
 #ifdef WITH_DEBUG_WINPR
-#define DEBUG_WINPR(fmt, ...) WLog_DBG(PRINTER_TAG, fmt, ## __VA_ARGS__)
+#define DEBUG_WINPR(...) WLog_DBG(PRINTER_TAG, __VA_ARGS__)
 #else
-#define DEBUG_WINPR(fmt, ...) do { } while (0)
+#define DEBUG_WINPR(...) do { } while (0)
 #endif
 
 #endif
index bc7c63d..4dc4998 100644 (file)
@@ -82,9 +82,9 @@ struct _RDPINPUT_CONTACT_POINT
 typedef struct _RDPINPUT_CONTACT_POINT RDPINPUT_CONTACT_POINT;
 
 #ifdef WITH_DEBUG_DVC
-#define DEBUG_DVC(fmt, ...) WLog_DBG(TAG, fmt, ## __VA_ARGS__)
+#define DEBUG_DVC(...) WLog_DBG(TAG, __VA_ARGS__)
 #else
-#define DEBUG_DVC(fmt, ...) do { } while (0)
+#define DEBUG_DVC(...) do { } while (0)
 #endif
 
 #endif /* FREERDP_CHANNEL_RDPEI_CLIENT_MAIN_H */
index cd6a152..dcd976f 100644 (file)
@@ -30,9 +30,9 @@
 #define TAG CHANNELS_TAG("rdpsnd.client")
 
 #if defined(WITH_DEBUG_SND)
-#define DEBUG_SND(fmt, ...) WLog_DBG(TAG, fmt, ## __VA_ARGS__)
+#define DEBUG_SND(...) WLog_DBG(TAG, __VA_ARGS__)
 #else
-#define DEBUG_SND(fmt, ...) do { } while (0)
+#define DEBUG_SND(...) do { } while (0)
 #endif
 
 UINT rdpsnd_virtual_channel_write(rdpsndPlugin* rdpsnd, wStream* s);
index 07cd999..cdda337 100644 (file)
@@ -31,9 +31,9 @@
 #define TAG CHANNELS_TAG("tsmf.client")
 
 #ifdef WITH_DEBUG_TSMF
-#define DEBUG_TSMF(fmt, ...) WLog_DBG(TAG, fmt, ## __VA_ARGS__)
+#define DEBUG_TSMF(...) WLog_DBG(TAG, __VA_ARGS__)
 #else
-#define DEBUG_TSMF(fmt, ...) do { } while (0)
+#define DEBUG_TSMF(...) do { } while (0)
 #endif
 
 typedef struct _TS_AM_MEDIA_TYPE
@@ -53,7 +53,7 @@ typedef struct _TS_AM_MEDIA_TYPE
        UINT32 Channels;
        UINT32 BitsPerSample;
        UINT32 BlockAlign;
-       const BYTE *ExtraData;
+       const BYTEExtraData;
        UINT32 ExtraDataSize;
 } TS_AM_MEDIA_TYPE;
 
index d506667..78c550e 100644 (file)
@@ -38,9 +38,9 @@
 
 #define TAG CHANNELS_TAG("urbdrc.client")
 #ifdef WITH_DEBUG_DVC
-#define DEBUG_DVC(fmt, ...) WLog_DBG(TAG, fmt, ## __VA_ARGS__)
+#define DEBUG_DVC(...) WLog_DBG(TAG, __VA_ARGS__)
 #else
-#define DEBUG_DVC(fmt, ...) do { } while (0)
+#define DEBUG_DVC(...) do { } while (0)
 #endif
 
 #define CAPABILITIES_NEGOTIATOR                                0x00000000
 
 enum device_text_type
 {
-       DeviceTextDescription = 0, 
+       DeviceTextDescription = 0,
        DeviceTextLocationInformation = 1,
 };
 
 enum device_descriptor_table
 {
-       B_LENGTH = 0, 
-       B_DESCRIPTOR_TYPE = 1, 
-       BCD_USB = 2, 
+       B_LENGTH = 0,
+       B_DESCRIPTOR_TYPE = 1,
+       BCD_USB = 2,
        B_DEVICE_CLASS = 4,
-       B_DEVICE_SUBCLASS = 5, 
+       B_DEVICE_SUBCLASS = 5,
        B_DEVICE_PROTOCOL = 6,
-       B_MAX_PACKET_SIZE0 = 7, 
-       ID_VENDOR = 8, 
+       B_MAX_PACKET_SIZE0 = 7,
+       ID_VENDOR = 8,
        ID_PRODUCT = 10,
-       BCD_DEVICE = 12, 
+       BCD_DEVICE = 12,
        I_MANUFACTURER = 14,
-       I_PRODUCT = 15, 
-       I_SERIAL_NUMBER = 16, 
+       I_PRODUCT = 15,
+       I_SERIAL_NUMBER = 16,
        B_NUM_CONFIGURATIONS = 17
 };
 
@@ -259,11 +259,11 @@ enum device_descriptor_table
 #define USBD_TRANSFER_DIRECTION_IN                             1
 
 #define VALID_TRANSFER_FLAGS_MASK                              USBD_SHORT_TRANSFER_OK | \
-                                                               USBD_TRANSFER_DIRECTION | \
-                                                               USBD_START_ISO_TRANSFER_ASAP | \
-                                                               USBD_DEFAULT_PIPE_TRANSFER)
-#define ENDPOINT_HALT                                          0x00  
+       USBD_TRANSFER_DIRECTION | \
+       USBD_START_ISO_TRANSFER_ASAP | \
+       USBD_DEFAULT_PIPE_TRANSFER)
+
+#define ENDPOINT_HALT                                          0x00
 #define DEVICE_REMOTE_WAKEUP                                   0x01
 
 /* transfer type */
@@ -318,16 +318,16 @@ enum device_descriptor_table
 
 #define LOG_LEVEL 1
 
-#define dummy_wait_obj(void) do{ sleep(5); } while(0)  
-#define dummy_wait_s_obj(_s) do{ sleep(_s); } while(0)  
+#define dummy_wait_obj(void) do{ sleep(5); } while(0)
+#define dummy_wait_s_obj(_s) do{ sleep(_s); } while(0)
 
 #define ISOCH_FIFO                                             1
 #define WAIT_COMPLETE_SLEEP                                    10000  /* for cpu high loading */
 
 #define urbdrc_get_mstime(_t) do { \
-       struct timeval _tp; \
-       gettimeofday(&_tp, 0); \
-       _t = (_tp.tv_sec * 1000) + (_tp.tv_usec / 1000); \
-} while (0)
+               struct timeval _tp; \
+               gettimeofday(&_tp, 0); \
+               _t = (_tp.tv_sec * 1000) + (_tp.tv_usec / 1000); \
+       } while (0)
 
 #endif /* __URBDRC_TYPES_H */
index 69b272d..07487e7 100644 (file)
@@ -48,9 +48,9 @@
 #define TAG CLIENT_TAG("windows")
 
 #ifdef WITH_DEBUG_CLIPRDR
-#define DEBUG_CLIPRDR(fmt, ...) WLog_DBG(TAG, fmt, ## __VA_ARGS__)
+#define DEBUG_CLIPRDR(...) WLog_DBG(TAG, __VA_ARGS__)
 #else
-#define DEBUG_CLIPRDR(fmt, ...) do { } while (0)
+#define DEBUG_CLIPRDR(...) do { } while (0)
 #endif
 
 typedef BOOL (WINAPI* fnAddClipboardFormatListener)(HWND hwnd);
index 741d7e8..d7e4a55 100644 (file)
@@ -33,9 +33,9 @@ void wf_event_focus_in(wfContext* wfc);
 
 #define KBD_TAG CLIENT_TAG("windows")
 #ifdef WITH_DEBUG_KBD
-#define DEBUG_KBD(fmt, ...) WLog_DBG(KBD_TAG, fmt, ## __VA_ARGS__)
+#define DEBUG_KBD(...) WLog_DBG(KBD_TAG, __VA_ARGS__)
 #else
-#define DEBUG_KBD(fmt, ...) do { } while (0)
+#define DEBUG_KBD(...) do { } while (0)
 #endif
 
 #endif /* __WF_EVENT_H */
index d7a04a9..fb9548a 100644 (file)
@@ -1383,7 +1383,6 @@ static BOOL xf_auto_reconnect(freerdp* instance)
 {
        UINT32 maxRetries;
        UINT32 numRetries = 0;
-       xfContext* xfc = (xfContext*) instance->context;
        rdpSettings* settings = instance->settings;
        maxRetries = settings->AutoReconnectMaxRetries;
 
index 9e55f3e..02c7690 100644 (file)
@@ -80,9 +80,9 @@ const char* const X11_EVENT_STRINGS[] =
 };
 
 #ifdef WITH_DEBUG_X11
-#define DEBUG_X11(fmt, ...) WLog_DBG(TAG, fmt, ## __VA_ARGS__)
+#define DEBUG_X11(...) WLog_DBG(TAG, __VA_ARGS__)
 #else
-#define DEBUG_X11(fmt, ...) do { } while (0)
+#define DEBUG_X11(...) do { } while (0)
 #endif
 
 BOOL xf_event_action_script_init(xfContext* xfc)
index db0ae31..2a73244 100644 (file)
@@ -58,9 +58,9 @@
 #define TAG CLIENT_TAG("x11")
 
 #ifdef WITH_DEBUG_X11
-#define DEBUG_X11(fmt, ...) WLog_DBG(TAG, fmt, ## __VA_ARGS__)
+#define DEBUG_X11(...) WLog_DBG(TAG, __VA_ARGS__)
 #else
-#define DEBUG_X11(fmt, ...) do { } while (0)
+#define DEBUG_X11(...) do { } while (0)
 #endif
 
 #include "FreeRDP_Icon_256px.h"
index 3b93d83..d852655 100644 (file)
@@ -34,9 +34,9 @@
 
 #define RFX_TAG FREERDP_TAG("codec.rfx")
 #ifdef WITH_DEBUG_RFX
-#define DEBUG_RFX(fmt, ...) WLog_DBG(RFX_TAG, fmt, ## __VA_ARGS__)
+#define DEBUG_RFX(...) WLog_DBG(RFX_TAG, __VA_ARGS__)
 #else
-#define DEBUG_RFX(fmt, ...) do { } while (0)
+#define DEBUG_RFX(...) do { } while (0)
 #endif
 
 typedef struct _RFX_TILE_COMPOSE_WORK_PARAM RFX_TILE_COMPOSE_WORK_PARAM;
@@ -55,7 +55,7 @@ struct _RFX_CONTEXT_PRIV
 
        PTP_POOL ThreadPool;
        TP_CALLBACK_ENVIRON ThreadPoolEnv;
+
        wBufferPool* BufferPool;
 
        /* profilers */
index 05e0528..1dd31eb 100644 (file)
@@ -72,9 +72,9 @@ FREERDP_LOCAL void key_free(rdpRsaKey* key);
 
 #define CERTIFICATE_TAG FREERDP_TAG("core.certificate")
 #ifdef WITH_DEBUG_CERTIFICATE
-#define DEBUG_CERTIFICATE(fmt, ...) WLog_DBG(CERTIFICATE_TAG, fmt, ## __VA_ARGS__)
+#define DEBUG_CERTIFICATE(...) WLog_DBG(CERTIFICATE_TAG, __VA_ARGS__)
 #else
-#define DEBUG_CERTIFICATE(fmt, ...) do { } while (0)
+#define DEBUG_CERTIFICATE(...) do { } while (0)
 #endif
 
 #endif /* __CERTIFICATE_H */
index 9067a4d..27369cf 100644 (file)
@@ -252,9 +252,9 @@ FREERDP_LOCAL void license_free(rdpLicense* license);
 
 #define LICENSE_TAG FREERDP_TAG("core.license")
 #ifdef WITH_DEBUG_LICENSE
-#define DEBUG_LICENSE(fmt, ...) WLog_DBG(LICENSE_TAG, fmt, ## __VA_ARGS__)
+#define DEBUG_LICENSE(...) WLog_DBG(LICENSE_TAG, __VA_ARGS__)
 #else
-#define DEBUG_LICENSE(fmt, ...) do { } while (0)
+#define DEBUG_LICENSE(...) do { } while (0)
 #endif
 
 #endif /* __LICENSE_H */
index c5d4879..687b133 100644 (file)
@@ -241,9 +241,9 @@ FREERDP_LOCAL void rdp_free(rdpRdp* rdp);
 
 #define RDP_TAG FREERDP_TAG("core.rdp")
 #ifdef WITH_DEBUG_RDP
-#define DEBUG_RDP(fmt, ...) WLog_DBG(RDP_TAG, fmt, ## __VA_ARGS__)
+#define DEBUG_RDP(...) WLog_DBG(RDP_TAG, __VA_ARGS__)
 #else
-#define DEBUG_RDP(fmt, ...) do { } while (0)
+#define DEBUG_RDP(...) do { } while (0)
 #endif
 
 BOOL rdp_decrypt(rdpRdp* rdp, wStream* s, int length, UINT16 securityFlags);
index 46c622c..cf6bca7 100644 (file)
@@ -60,9 +60,9 @@ FREERDP_LOCAL void redirection_free(rdpRedirection* redirection);
 
 #define REDIR_TAG FREERDP_TAG("core.redirection")
 #ifdef WITH_DEBUG_REDIR
-#define DEBUG_REDIR(fmt, ...) WLog_DBG(REDIR_TAG, fmt, ## __VA_ARGS__)
+#define DEBUG_REDIR(...) WLog_DBG(REDIR_TAG, __VA_ARGS__)
 #else
-#define DEBUG_REDIR(fmt, ...) do { } while (0)
+#define DEBUG_REDIR(...) do { } while (0)
 #endif
 
 #endif /* __REDIRECTION_H */
index fb1a740..6f9ee7f 100644 (file)
@@ -41,9 +41,9 @@
 
 #define TAG FREERDP_TAG("core.server")
 #ifdef WITH_DEBUG_DVC
-#define DEBUG_DVC(fmt, ...) WLog_DBG(TAG, fmt, ## __VA_ARGS__)
+#define DEBUG_DVC(...) WLog_DBG(TAG, __VA_ARGS__)
 #else
-#define DEBUG_DVC(fmt, ...) do { } while (0)
+#define DEBUG_DVC(...) do { } while (0)
 #endif
 
 struct _wtsChannelMessage
@@ -58,20 +58,20 @@ typedef struct _wtsChannelMessage wtsChannelMessage;
 static DWORD g_SessionId = 1;
 static wHashTable* g_ServerHandles = NULL;
 
-static rdpPeerChannel* wts_get_dvc_channel_by_id(WTSVirtualChannelManager* vcm, UINT32 ChannelId)
+static rdpPeerChannel* wts_get_dvc_channel_by_id(WTSVirtualChannelManager* vcm,
+        UINT32 ChannelId)
 {
        int index;
        int count;
        BOOL found = FALSE;
        rdpPeerChannel* channel = NULL;
-
        ArrayList_Lock(vcm->dynamicVirtualChannels);
-
        count = ArrayList_Count(vcm->dynamicVirtualChannels);
 
        for (index = 0; index < count; index++)
        {
-               channel = (rdpPeerChannel*) ArrayList_GetItem(vcm->dynamicVirtualChannels, index);
+               channel = (rdpPeerChannel*) ArrayList_GetItem(vcm->dynamicVirtualChannels,
+                         index);
 
                if (channel->channelId == ChannelId)
                {
@@ -81,38 +81,38 @@ static rdpPeerChannel* wts_get_dvc_channel_by_id(WTSVirtualChannelManager* vcm,
        }
 
        ArrayList_Unlock(vcm->dynamicVirtualChannels);
-
        return found ? channel : NULL;
 }
 
-static BOOL wts_queue_receive_data(rdpPeerChannel* channel, const BYTE* Buffer, UINT32 Length)
+static BOOL wts_queue_receive_data(rdpPeerChannel* channel, const BYTE* Buffer,
+                                   UINT32 Length)
 {
        BYTE* buffer;
        wtsChannelMessage* messageCtx;
-
        messageCtx = (wtsChannelMessage*) malloc(sizeof(wtsChannelMessage) + Length);
+
        if (!messageCtx)
                return FALSE;
+
        messageCtx->channelId = channel->channelId;
        messageCtx->length = Length;
        messageCtx->offset = 0;
-       buffer = (BYTE*) (messageCtx + 1);
+       buffer = (BYTE*)(messageCtx + 1);
        CopyMemory(buffer, Buffer, Length);
-
        return MessageQueue_Post(channel->queue, messageCtx, 0, NULL, NULL);
 }
 
-static BOOL wts_queue_send_item(rdpPeerChannel* channel, BYTE* Buffer, UINT32 Length)
+static BOOL wts_queue_send_item(rdpPeerChannel* channel, BYTE* Buffer,
+                                UINT32 Length)
 {
        BYTE* buffer;
        UINT32 length;
        UINT16 channelId;
-
        buffer = Buffer;
        length = Length;
        channelId = channel->channelId;
-
-       return MessageQueue_Post(channel->vcm->queue, (void*) (UINT_PTR) channelId, 0, (void*) buffer, (void*) (UINT_PTR) length);
+       return MessageQueue_Post(channel->vcm->queue, (void*)(UINT_PTR) channelId, 0,
+                                (void*) buffer, (void*)(UINT_PTR) length);
 }
 
 static int wts_read_variable_uint(wStream* s, int cbLen, UINT32* val)
@@ -122,24 +122,28 @@ static int wts_read_variable_uint(wStream* s, int cbLen, UINT32* val)
                case 0:
                        if (Stream_GetRemainingLength(s) < 1)
                                return 0;
+
                        Stream_Read_UINT8(s, *val);
                        return 1;
 
                case 1:
                        if (Stream_GetRemainingLength(s) < 2)
                                return 0;
+
                        Stream_Read_UINT16(s, *val);
                        return 2;
 
                default:
                        if (Stream_GetRemainingLength(s) < 4)
                                return 0;
+
                        Stream_Read_UINT32(s, *val);
                        return 4;
        }
 }
 
-static BOOL wts_read_drdynvc_capabilities_response(rdpPeerChannel* channel, UINT32 length)
+static BOOL wts_read_drdynvc_capabilities_response(rdpPeerChannel* channel,
+        UINT32 length)
 {
        UINT16 Version;
 
@@ -148,14 +152,13 @@ static BOOL wts_read_drdynvc_capabilities_response(rdpPeerChannel* channel, UINT
 
        Stream_Seek_UINT8(channel->receiveData); /* Pad (1 byte) */
        Stream_Read_UINT16(channel->receiveData, Version);
-
        DEBUG_DVC("Version: %d", Version);
-
        channel->vcm->drdynvc_state = DRDYNVC_STATE_READY;
        return TRUE;
 }
 
-static BOOL wts_read_drdynvc_create_response(rdpPeerChannel* channel, wStream* s, UINT32 length)
+static BOOL wts_read_drdynvc_create_response(rdpPeerChannel* channel,
+        wStream* s, UINT32 length)
 {
        UINT32 CreationStatus;
 
@@ -166,7 +169,8 @@ static BOOL wts_read_drdynvc_create_response(rdpPeerChannel* channel, wStream* s
 
        if ((INT32) CreationStatus < 0)
        {
-               DEBUG_DVC("ChannelId %d creation failed (%d)", channel->channelId, (INT32) CreationStatus);
+               DEBUG_DVC("ChannelId %d creation failed (%d)", channel->channelId,
+                         (INT32) CreationStatus);
                channel->dvc_open_state = DVC_OPEN_STATE_FAILED;
        }
        else
@@ -174,13 +178,14 @@ static BOOL wts_read_drdynvc_create_response(rdpPeerChannel* channel, wStream* s
                DEBUG_DVC("ChannelId %d creation succeeded", channel->channelId);
                channel->dvc_open_state = DVC_OPEN_STATE_SUCCEEDED;
        }
+
        return TRUE;
 }
 
-static BOOL wts_read_drdynvc_data_first(rdpPeerChannel* channel, wStream* s, int cbLen, UINT32 length)
+static BOOL wts_read_drdynvc_data_first(rdpPeerChannel* channel, wStream* s,
+                                        int cbLen, UINT32 length)
 {
        int value;
-
        value = wts_read_variable_uint(s, cbLen, &channel->dvc_total_length);
 
        if (value == 0)
@@ -192,18 +197,24 @@ static BOOL wts_read_drdynvc_data_first(rdpPeerChannel* channel, wStream* s, int
                return FALSE;
 
        Stream_SetPosition(channel->receiveData, 0);
-       if (!Stream_EnsureRemainingCapacity(channel->receiveData, (int) channel->dvc_total_length))
+
+       if (!Stream_EnsureRemainingCapacity(channel->receiveData,
+                                           (int) channel->dvc_total_length))
                return FALSE;
+
        Stream_Write(channel->receiveData, Stream_Pointer(s), length);
        return TRUE;
 }
 
-static BOOL wts_read_drdynvc_data(rdpPeerChannel* channel, wStream* s, UINT32 length)
+static BOOL wts_read_drdynvc_data(rdpPeerChannel* channel, wStream* s,
+                                  UINT32 length)
 {
        BOOL ret = FALSE;
+
        if (channel->dvc_total_length > 0)
        {
-               if (Stream_GetPosition(channel->receiveData) + length > channel->dvc_total_length)
+               if (Stream_GetPosition(channel->receiveData) + length >
+                   channel->dvc_total_length)
                {
                        channel->dvc_total_length = 0;
                        WLog_ERR(TAG, "incorrect fragment data, discarded.");
@@ -214,7 +225,8 @@ static BOOL wts_read_drdynvc_data(rdpPeerChannel* channel, wStream* s, UINT32 le
 
                if (Stream_GetPosition(channel->receiveData) >= (int) channel->dvc_total_length)
                {
-                       ret = wts_queue_receive_data(channel, Stream_Buffer(channel->receiveData), channel->dvc_total_length);
+                       ret = wts_queue_receive_data(channel, Stream_Buffer(channel->receiveData),
+                                                    channel->dvc_total_length);
                        channel->dvc_total_length = 0;
                }
        }
@@ -222,6 +234,7 @@ static BOOL wts_read_drdynvc_data(rdpPeerChannel* channel, wStream* s, UINT32 le
        {
                ret = wts_queue_receive_data(channel, Stream_Pointer(s), length);
        }
+
        return ret;
 }
 
@@ -240,7 +253,6 @@ static BOOL wts_read_drdynvc_pdu(rdpPeerChannel* channel)
        int cbChId;
        UINT32 ChannelId;
        rdpPeerChannel* dvc;
-
        length = Stream_GetPosition(channel->receiveData);
 
        if (length < 1)
@@ -248,7 +260,6 @@ static BOOL wts_read_drdynvc_pdu(rdpPeerChannel* channel)
 
        Stream_SetPosition(channel->receiveData, 0);
        Stream_Read_UINT8(channel->receiveData, value);
-
        length--;
        Cmd = (value & 0xf0) >> 4;
        Sp = (value & 0x0c) >> 2;
@@ -266,7 +277,6 @@ static BOOL wts_read_drdynvc_pdu(rdpPeerChannel* channel)
                        return FALSE;
 
                length -= value;
-
                DEBUG_DVC("Cmd %d ChannelId %d length %d", Cmd, ChannelId, length);
                dvc = wts_get_dvc_channel_by_id(channel->vcm, ChannelId);
 
@@ -301,6 +311,7 @@ static BOOL wts_read_drdynvc_pdu(rdpPeerChannel* channel)
        {
                WLog_ERR(TAG,  "received Cmd %d but channel is not ready.", Cmd);
        }
+
        return TRUE;
 }
 
@@ -331,26 +342,28 @@ static void wts_write_drdynvc_header(wStream* s, BYTE Cmd, UINT32 ChannelId)
 {
        BYTE* bm;
        int cbChId;
-
        Stream_GetPointer(s, bm);
        Stream_Seek_UINT8(s);
        cbChId = wts_write_variable_uint(s, ChannelId);
        *bm = ((Cmd & 0x0F) << 4) | cbChId;
 }
 
-static BOOL wts_write_drdynvc_create_request(wStream *s, UINT32 ChannelId, const char *ChannelName)
+static BOOL wts_write_drdynvc_create_request(wStream* s, UINT32 ChannelId,
+        const char* ChannelName)
 {
        UINT32 len;
-
        wts_write_drdynvc_header(s, CREATE_REQUEST_PDU, ChannelId);
        len = strlen(ChannelName) + 1;
+
        if (!Stream_EnsureRemainingCapacity(s, (int) len))
                return FALSE;
+
        Stream_Write(s, ChannelName, len);
        return TRUE;
 }
 
-static BOOL WTSProcessChannelData(rdpPeerChannel* channel, UINT16 channelId, BYTE* data, int size, int flags, int totalSize)
+static BOOL WTSProcessChannelData(rdpPeerChannel* channel, UINT16 channelId,
+                                  BYTE* data, int size, int flags, int totalSize)
 {
        BOOL ret = TRUE;
 
@@ -361,6 +374,7 @@ static BOOL WTSProcessChannelData(rdpPeerChannel* channel, UINT16 channelId, BYT
 
        if (!Stream_EnsureRemainingCapacity(channel->receiveData, size))
                return FALSE;
+
        Stream_Write(channel->receiveData, data, size);
 
        if (flags & CHANNEL_FLAG_LAST)
@@ -369,21 +383,25 @@ static BOOL WTSProcessChannelData(rdpPeerChannel* channel, UINT16 channelId, BYT
                {
                        WLog_ERR(TAG, "read error");
                }
+
                if (channel == channel->vcm->drdynvc_channel)
                {
                        ret = wts_read_drdynvc_pdu(channel);
                }
                else
                {
-                       ret = wts_queue_receive_data(channel, Stream_Buffer(channel->receiveData), Stream_GetPosition(channel->receiveData));
+                       ret = wts_queue_receive_data(channel, Stream_Buffer(channel->receiveData),
+                                                    Stream_GetPosition(channel->receiveData));
                }
+
                Stream_SetPosition(channel->receiveData, 0);
        }
 
        return ret;
 }
 
-static int WTSReceiveChannelData(freerdp_peer* client, UINT16 channelId, BYTE* data, int size, int flags, int totalSize)
+static int WTSReceiveChannelData(freerdp_peer* client, UINT16 channelId,
+                                 BYTE* data, int size, int flags, int totalSize)
 {
        UINT32 i;
        BOOL status = FALSE;
@@ -410,11 +428,11 @@ static int WTSReceiveChannelData(freerdp_peer* client, UINT16 channelId, BYTE* d
        return status;
 }
 
-void WTSVirtualChannelManagerGetFileDescriptor(HANDLE hServer, void** fds, int* fds_count)
+void WTSVirtualChannelManagerGetFileDescriptor(HANDLE hServer, void** fds,
+        int* fds_count)
 {
        void* fd;
        WTSVirtualChannelManager* vcm = (WTSVirtualChannelManager*) hServer;
-
        fd = GetEventWaitObject(MessageQueue_Event(vcm->queue));
 
        if (fd)
@@ -424,6 +442,7 @@ void WTSVirtualChannelManagerGetFileDescriptor(HANDLE hServer, void** fds, int*
        }
 
 #if 0
+
        if (vcm->drdynvc_channel)
        {
                fd = GetEventWaitObject(vcm->drdynvc_channel->receiveEvent);
@@ -434,6 +453,7 @@ void WTSVirtualChannelManagerGetFileDescriptor(HANDLE hServer, void** fds, int*
                        (*fds_count)++;
                }
        }
+
 #endif
 }
 
@@ -449,16 +469,17 @@ BOOL WTSVirtualChannelManagerCheckFileDescriptor(HANDLE hServer)
        {
                /* Initialize drdynvc channel once and only once. */
                vcm->drdynvc_state = DRDYNVC_STATE_INITIALIZED;
-
-               channel = (rdpPeerChannel*) WTSVirtualChannelOpen((HANDLE) vcm, WTS_CURRENT_SESSION, "drdynvc");
+               channel = (rdpPeerChannel*) WTSVirtualChannelOpen((HANDLE) vcm,
+                         WTS_CURRENT_SESSION, "drdynvc");
 
                if (channel)
                {
                        ULONG written;
-
                        vcm->drdynvc_channel = channel;
                        dynvc_caps = 0x00010050; /* DYNVC_CAPS_VERSION1 (4 bytes) */
-                       if (!WTSVirtualChannelWrite(channel, (PCHAR) &dynvc_caps, sizeof(dynvc_caps), &written))
+
+                       if (!WTSVirtualChannelWrite(channel, (PCHAR) &dynvc_caps, sizeof(dynvc_caps),
+                                                   &written))
                                return FALSE;
                }
        }
@@ -468,12 +489,12 @@ BOOL WTSVirtualChannelManagerCheckFileDescriptor(HANDLE hServer)
                BYTE* buffer;
                UINT32 length;
                UINT16 channelId;
-
-               channelId = (UINT16) (UINT_PTR) message.context;
+               channelId = (UINT16)(UINT_PTR) message.context;
                buffer = (BYTE*) message.wParam;
-               length = (UINT32) (UINT_PTR) message.lParam;
+               length = (UINT32)(UINT_PTR) message.lParam;
 
-               if (vcm->client->SendChannelData(vcm->client, channelId, buffer, length) == FALSE)
+               if (vcm->client->SendChannelData(vcm->client, channelId, buffer,
+                                                length) == FALSE)
                {
                        status = FALSE;
                }
@@ -493,7 +514,8 @@ HANDLE WTSVirtualChannelManagerGetEventHandle(HANDLE hServer)
        return MessageQueue_Event(vcm->queue);
 }
 
-static rdpMcsChannel* wts_get_joined_channel_by_name(rdpMcs* mcs, const char* channel_name)
+static rdpMcsChannel* wts_get_joined_channel_by_name(rdpMcs* mcs,
+        const char* channel_name)
 {
        UINT32 index;
 
@@ -504,7 +526,8 @@ static rdpMcsChannel* wts_get_joined_channel_by_name(rdpMcs* mcs, const char* ch
        {
                if (mcs->channels[index].joined)
                {
-                       if (_strnicmp(mcs->channels[index].Name, channel_name, strlen(channel_name)) == 0)
+                       if (_strnicmp(mcs->channels[index].Name, channel_name,
+                                     strlen(channel_name)) == 0)
                                return &mcs->channels[index];
                }
        }
@@ -512,7 +535,8 @@ static rdpMcsChannel* wts_get_joined_channel_by_name(rdpMcs* mcs, const char* ch
        return NULL;
 }
 
-static rdpMcsChannel* wts_get_joined_channel_by_id(rdpMcs* mcs, const UINT16 channel_id)
+static rdpMcsChannel* wts_get_joined_channel_by_id(rdpMcs* mcs,
+        const UINT16 channel_id)
 {
        UINT32 index;
 
@@ -536,7 +560,8 @@ BOOL WTSIsChannelJoinedByName(freerdp_peer* client, const char* channel_name)
        if (!client || !client->context || !client->context->rdp)
                return FALSE;
 
-       return wts_get_joined_channel_by_name(client->context->rdp->mcs, channel_name) == NULL ? FALSE : TRUE;
+       return wts_get_joined_channel_by_name(client->context->rdp->mcs,
+                                             channel_name) == NULL ? FALSE : TRUE;
 }
 
 BOOL WTSIsChannelJoinedById(freerdp_peer* client, const UINT16 channel_id)
@@ -544,7 +569,8 @@ BOOL WTSIsChannelJoinedById(freerdp_peer* client, const UINT16 channel_id)
        if (!client || !client->context || !client->context->rdp)
                return FALSE;
 
-       return wts_get_joined_channel_by_id(client->context->rdp->mcs, channel_id) == NULL ? FALSE : TRUE;
+       return wts_get_joined_channel_by_id(client->context->rdp->mcs,
+                                           channel_id) == NULL ? FALSE : TRUE;
 }
 
 BOOL WTSVirtualChannelManagerIsChannelJoined(HANDLE hServer, const char* name)
@@ -554,13 +580,13 @@ BOOL WTSVirtualChannelManagerIsChannelJoined(HANDLE hServer, const char* name)
        if (!vcm || !vcm->rdp)
                return FALSE;
 
-       return wts_get_joined_channel_by_name(vcm->rdp->mcs, name) == NULL ? FALSE : TRUE;
+       return wts_get_joined_channel_by_name(vcm->rdp->mcs,
+                                             name) == NULL ? FALSE : TRUE;
 }
 
 BYTE WTSVirtualChannelManagerGetDrdynvcState(HANDLE hServer)
 {
        WTSVirtualChannelManager* vcm = (WTSVirtualChannelManager*) hServer;
-
        return vcm->drdynvc_state;
 }
 
@@ -571,7 +597,8 @@ UINT16 WTSChannelGetId(freerdp_peer* client, const char* channel_name)
        if (!client || !client->context || !client->context->rdp)
                return 0;
 
-       channel = wts_get_joined_channel_by_name(client->context->rdp->mcs, channel_name);
+       channel = wts_get_joined_channel_by_name(client->context->rdp->mcs,
+                 channel_name);
 
        if (!channel)
                return 0;
@@ -579,14 +606,16 @@ UINT16 WTSChannelGetId(freerdp_peer* client, const char* channel_name)
        return channel->ChannelId;
 }
 
-BOOL WTSChannelSetHandleByName(freerdp_peer* client, const char* channel_name, void* handle)
+BOOL WTSChannelSetHandleByName(freerdp_peer* client, const char* channel_name,
+                               void* handle)
 {
        rdpMcsChannel* channel;
 
        if (!client || !client->context || !client->context->rdp)
                return FALSE;
 
-       channel = wts_get_joined_channel_by_name(client->context->rdp->mcs, channel_name);
+       channel = wts_get_joined_channel_by_name(client->context->rdp->mcs,
+                 channel_name);
 
        if (!channel)
                return FALSE;
@@ -595,7 +624,8 @@ BOOL WTSChannelSetHandleByName(freerdp_peer* client, const char* channel_name, v
        return TRUE;
 }
 
-BOOL WTSChannelSetHandleById(freerdp_peer* client, const UINT16 channel_id, void* handle)
+BOOL WTSChannelSetHandleById(freerdp_peer* client, const UINT16 channel_id,
+                             void* handle)
 {
        rdpMcsChannel* channel;
 
@@ -611,14 +641,15 @@ BOOL WTSChannelSetHandleById(freerdp_peer* client, const UINT16 channel_id, void
        return TRUE;
 }
 
-void* WTSChannelGetHandleByName(freerdp_peer* client, const char *channel_name)
+void* WTSChannelGetHandleByName(freerdp_peer* client, const charchannel_name)
 {
        rdpMcsChannel* channel;
 
        if (!client || !client->context || !client->context->rdp)
                return NULL;
 
-       channel = wts_get_joined_channel_by_name(client->context->rdp->mcs, channel_name);
+       channel = wts_get_joined_channel_by_name(client->context->rdp->mcs,
+                 channel_name);
 
        if (!channel)
                return NULL;
@@ -641,22 +672,26 @@ void* WTSChannelGetHandleById(freerdp_peer* client, const UINT16 channel_id)
        return channel->handle;
 }
 
-BOOL WINAPI FreeRDP_WTSStartRemoteControlSessionW(LPWSTR pTargetServerName, ULONG TargetLogonId, BYTE HotkeyVk, USHORT HotkeyModifiers)
+BOOL WINAPI FreeRDP_WTSStartRemoteControlSessionW(LPWSTR pTargetServerName,
+        ULONG TargetLogonId, BYTE HotkeyVk, USHORT HotkeyModifiers)
 {
        return FALSE;
 }
 
-BOOL WINAPI FreeRDP_WTSStartRemoteControlSessionA(LPSTR pTargetServerName, ULONG TargetLogonId, BYTE HotkeyVk, USHORT HotkeyModifiers)
+BOOL WINAPI FreeRDP_WTSStartRemoteControlSessionA(LPSTR pTargetServerName,
+        ULONG TargetLogonId, BYTE HotkeyVk, USHORT HotkeyModifiers)
 {
        return FALSE;
 }
 
-BOOL WINAPI FreeRDP_WTSStartRemoteControlSessionExW(LPWSTR pTargetServerName, ULONG TargetLogonId, BYTE HotkeyVk, USHORT HotkeyModifiers, DWORD flags)
+BOOL WINAPI FreeRDP_WTSStartRemoteControlSessionExW(LPWSTR pTargetServerName,
+        ULONG TargetLogonId, BYTE HotkeyVk, USHORT HotkeyModifiers, DWORD flags)
 {
        return FALSE;
 }
 
-BOOL WINAPI FreeRDP_WTSStartRemoteControlSessionExA(LPSTR pTargetServerName, ULONG TargetLogonId, BYTE HotkeyVk, USHORT HotkeyModifiers, DWORD flags)
+BOOL WINAPI FreeRDP_WTSStartRemoteControlSessionExA(LPSTR pTargetServerName,
+        ULONG TargetLogonId, BYTE HotkeyVk, USHORT HotkeyModifiers, DWORD flags)
 {
        return FALSE;
 }
@@ -666,22 +701,26 @@ BOOL WINAPI FreeRDP_WTSStopRemoteControlSession(ULONG LogonId)
        return FALSE;
 }
 
-BOOL WINAPI FreeRDP_WTSConnectSessionW(ULONG LogonId, ULONG TargetLogonId, PWSTR pPassword, BOOL bWait)
+BOOL WINAPI FreeRDP_WTSConnectSessionW(ULONG LogonId, ULONG TargetLogonId,
+                                       PWSTR pPassword, BOOL bWait)
 {
        return FALSE;
 }
 
-BOOL WINAPI FreeRDP_WTSConnectSessionA(ULONG LogonId, ULONG TargetLogonId, PSTR pPassword, BOOL bWait)
+BOOL WINAPI FreeRDP_WTSConnectSessionA(ULONG LogonId, ULONG TargetLogonId,
+                                       PSTR pPassword, BOOL bWait)
 {
        return FALSE;
 }
 
-BOOL WINAPI FreeRDP_WTSEnumerateServersW(LPWSTR pDomainName, DWORD Reserved, DWORD Version, PWTS_SERVER_INFOW* ppServerInfo, DWORD* pCount)
+BOOL WINAPI FreeRDP_WTSEnumerateServersW(LPWSTR pDomainName, DWORD Reserved,
+        DWORD Version, PWTS_SERVER_INFOW* ppServerInfo, DWORD* pCount)
 {
        return FALSE;
 }
 
-BOOL WINAPI FreeRDP_WTSEnumerateServersA(LPSTR pDomainName, DWORD Reserved, DWORD Version, PWTS_SERVER_INFOA* ppServerInfo, DWORD* pCount)
+BOOL WINAPI FreeRDP_WTSEnumerateServersA(LPSTR pDomainName, DWORD Reserved,
+        DWORD Version, PWTS_SERVER_INFOA* ppServerInfo, DWORD* pCount)
 {
        return FALSE;
 }
@@ -697,13 +736,13 @@ HANDLE WINAPI FreeRDP_WTSOpenServerA(LPSTR pServerName)
        freerdp_peer* client;
        WTSVirtualChannelManager* vcm;
        HANDLE hServer = INVALID_HANDLE_VALUE;
-
        context = (rdpContext*) pServerName;
 
        if (!context)
                return INVALID_HANDLE_VALUE;
 
        client = context->peer;
+
        if (!client)
        {
                SetLastError(ERROR_INVALID_DATA);
@@ -711,42 +750,44 @@ HANDLE WINAPI FreeRDP_WTSOpenServerA(LPSTR pServerName)
        }
 
        vcm = (WTSVirtualChannelManager*) calloc(1, sizeof(WTSVirtualChannelManager));
+
        if (!vcm)
                goto error_vcm_alloc;
 
        vcm->client = client;
        vcm->rdp = context->rdp;
-
        vcm->SessionId = g_SessionId++;
 
        if (!g_ServerHandles)
        {
                g_ServerHandles = HashTable_New(TRUE);
+
                if (!g_ServerHandles)
                        goto error_free;
        }
 
-       if (HashTable_Add(g_ServerHandles, (void*) (UINT_PTR) vcm->SessionId, (void*) vcm) < 0)
+       if (HashTable_Add(g_ServerHandles, (void*)(UINT_PTR) vcm->SessionId,
+                         (void*) vcm) < 0)
                goto error_free;
 
        vcm->queue = MessageQueue_New(NULL);
+
        if (!vcm->queue)
                goto error_queue;
 
        vcm->dvc_channel_id_seq = 0;
        vcm->dynamicVirtualChannels = ArrayList_New(TRUE);
+
        if (!vcm->dynamicVirtualChannels)
                goto error_dynamicVirtualChannels;
 
        client->ReceiveChannelData = WTSReceiveChannelData;
-
        hServer = (HANDLE) vcm;
        return hServer;
-
 error_dynamicVirtualChannels:
        MessageQueue_Free(vcm->queue);
 error_queue:
-       HashTable_Remove(g_ServerHandles, (void*) (UINT_PTR) vcm->SessionId);
+       HashTable_Remove(g_ServerHandles, (void*)(UINT_PTR) vcm->SessionId);
 error_free:
        free(vcm);
 error_vcm_alloc:
@@ -770,25 +811,22 @@ VOID WINAPI FreeRDP_WTSCloseServer(HANDLE hServer)
        int count;
        rdpPeerChannel* channel;
        WTSVirtualChannelManager* vcm;
-
        vcm = (WTSVirtualChannelManager*) hServer;
 
        if (vcm)
        {
-               HashTable_Remove(g_ServerHandles, (void*) (UINT_PTR) vcm->SessionId);
-
+               HashTable_Remove(g_ServerHandles, (void*)(UINT_PTR) vcm->SessionId);
                ArrayList_Lock(vcm->dynamicVirtualChannels);
-
                count = ArrayList_Count(vcm->dynamicVirtualChannels);
 
                for (index = 0; index < count; index++)
                {
-                       channel = (rdpPeerChannel*) ArrayList_GetItem(vcm->dynamicVirtualChannels, index);
+                       channel = (rdpPeerChannel*) ArrayList_GetItem(vcm->dynamicVirtualChannels,
+                                 index);
                        WTSVirtualChannelClose(channel);
                }
 
                ArrayList_Unlock(vcm->dynamicVirtualChannels);
-
                ArrayList_Free(vcm->dynamicVirtualChannels);
 
                if (vcm->drdynvc_channel)
@@ -798,56 +836,63 @@ VOID WINAPI FreeRDP_WTSCloseServer(HANDLE hServer)
                }
 
                MessageQueue_Free(vcm->queue);
-
                free(vcm);
        }
 }
 
-BOOL WINAPI FreeRDP_WTSEnumerateSessionsW(HANDLE hServer, DWORD Reserved, DWORD Version, PWTS_SESSION_INFOW* ppSessionInfo, DWORD* pCount)
+BOOL WINAPI FreeRDP_WTSEnumerateSessionsW(HANDLE hServer, DWORD Reserved,
+        DWORD Version, PWTS_SESSION_INFOW* ppSessionInfo, DWORD* pCount)
 {
        return FALSE;
 }
 
-BOOL WINAPI FreeRDP_WTSEnumerateSessionsA(HANDLE hServer, DWORD Reserved, DWORD Version, PWTS_SESSION_INFOA* ppSessionInfo, DWORD* pCount)
+BOOL WINAPI FreeRDP_WTSEnumerateSessionsA(HANDLE hServer, DWORD Reserved,
+        DWORD Version, PWTS_SESSION_INFOA* ppSessionInfo, DWORD* pCount)
 {
        return FALSE;
 }
 
-BOOL WINAPI FreeRDP_WTSEnumerateSessionsExW(HANDLE hServer, DWORD* pLevel, DWORD Filter, PWTS_SESSION_INFO_1W* ppSessionInfo, DWORD* pCount)
+BOOL WINAPI FreeRDP_WTSEnumerateSessionsExW(HANDLE hServer, DWORD* pLevel,
+        DWORD Filter, PWTS_SESSION_INFO_1W* ppSessionInfo, DWORD* pCount)
 {
        return FALSE;
 }
 
-BOOL WINAPI FreeRDP_WTSEnumerateSessionsExA(HANDLE hServer, DWORD* pLevel, DWORD Filter, PWTS_SESSION_INFO_1A* ppSessionInfo, DWORD* pCount)
+BOOL WINAPI FreeRDP_WTSEnumerateSessionsExA(HANDLE hServer, DWORD* pLevel,
+        DWORD Filter, PWTS_SESSION_INFO_1A* ppSessionInfo, DWORD* pCount)
 {
        return FALSE;
 }
 
-BOOL WINAPI FreeRDP_WTSEnumerateProcessesW(HANDLE hServer, DWORD Reserved, DWORD Version, PWTS_PROCESS_INFOW* ppProcessInfo, DWORD* pCount)
+BOOL WINAPI FreeRDP_WTSEnumerateProcessesW(HANDLE hServer, DWORD Reserved,
+        DWORD Version, PWTS_PROCESS_INFOW* ppProcessInfo, DWORD* pCount)
 {
        return FALSE;
 }
 
-BOOL WINAPI FreeRDP_WTSEnumerateProcessesA(HANDLE hServer, DWORD Reserved, DWORD Version, PWTS_PROCESS_INFOA* ppProcessInfo, DWORD* pCount)
+BOOL WINAPI FreeRDP_WTSEnumerateProcessesA(HANDLE hServer, DWORD Reserved,
+        DWORD Version, PWTS_PROCESS_INFOA* ppProcessInfo, DWORD* pCount)
 {
        return FALSE;
 }
 
-BOOL WINAPI FreeRDP_WTSTerminateProcess(HANDLE hServer, DWORD ProcessId, DWORD ExitCode)
+BOOL WINAPI FreeRDP_WTSTerminateProcess(HANDLE hServer, DWORD ProcessId,
+                                        DWORD ExitCode)
 {
        return FALSE;
 }
 
-BOOL WINAPI FreeRDP_WTSQuerySessionInformationW(HANDLE hServer, DWORD SessionId, WTS_INFO_CLASS WTSInfoClass, LPWSTR* ppBuffer, DWORD* pBytesReturned)
+BOOL WINAPI FreeRDP_WTSQuerySessionInformationW(HANDLE hServer, DWORD SessionId,
+        WTS_INFO_CLASS WTSInfoClass, LPWSTR* ppBuffer, DWORD* pBytesReturned)
 {
        return FALSE;
 }
 
-BOOL WINAPI FreeRDP_WTSQuerySessionInformationA(HANDLE hServer, DWORD SessionId, WTS_INFO_CLASS WTSInfoClass, LPSTR* ppBuffer, DWORD* pBytesReturned)
+BOOL WINAPI FreeRDP_WTSQuerySessionInformationA(HANDLE hServer, DWORD SessionId,
+        WTS_INFO_CLASS WTSInfoClass, LPSTR* ppBuffer, DWORD* pBytesReturned)
 {
        DWORD BytesReturned;
        WTSVirtualChannelManager* vcm;
-
        vcm = (WTSVirtualChannelManager*) hServer;
 
        if (!vcm)
@@ -856,9 +901,9 @@ BOOL WINAPI FreeRDP_WTSQuerySessionInformationA(HANDLE hServer, DWORD SessionId,
        if (WTSInfoClass == WTSSessionId)
        {
                ULONG* pBuffer;
-
                BytesReturned = sizeof(ULONG);
                pBuffer = (ULONG*) malloc(sizeof(BytesReturned));
+
                if (!pBuffer)
                {
                        SetLastError(E_OUTOFMEMORY);
@@ -866,54 +911,62 @@ BOOL WINAPI FreeRDP_WTSQuerySessionInformationA(HANDLE hServer, DWORD SessionId,
                }
 
                *pBuffer = vcm->SessionId;
-
                *ppBuffer = (LPSTR) pBuffer;
                *pBytesReturned = BytesReturned;
-
                return TRUE;
        }
 
        return FALSE;
 }
 
-BOOL WINAPI FreeRDP_WTSQueryUserConfigW(LPWSTR pServerName, LPWSTR pUserName, WTS_CONFIG_CLASS WTSConfigClass, LPWSTR* ppBuffer, DWORD* pBytesReturned)
+BOOL WINAPI FreeRDP_WTSQueryUserConfigW(LPWSTR pServerName, LPWSTR pUserName,
+                                        WTS_CONFIG_CLASS WTSConfigClass, LPWSTR* ppBuffer, DWORD* pBytesReturned)
 {
        return FALSE;
 }
 
-BOOL WINAPI FreeRDP_WTSQueryUserConfigA(LPSTR pServerName, LPSTR pUserName, WTS_CONFIG_CLASS WTSConfigClass, LPSTR* ppBuffer, DWORD* pBytesReturned)
+BOOL WINAPI FreeRDP_WTSQueryUserConfigA(LPSTR pServerName, LPSTR pUserName,
+                                        WTS_CONFIG_CLASS WTSConfigClass, LPSTR* ppBuffer, DWORD* pBytesReturned)
 {
        return FALSE;
 }
 
-BOOL WINAPI FreeRDP_WTSSetUserConfigW(LPWSTR pServerName, LPWSTR pUserName, WTS_CONFIG_CLASS WTSConfigClass, LPWSTR pBuffer, DWORD DataLength)
+BOOL WINAPI FreeRDP_WTSSetUserConfigW(LPWSTR pServerName, LPWSTR pUserName,
+                                      WTS_CONFIG_CLASS WTSConfigClass, LPWSTR pBuffer, DWORD DataLength)
 {
        return FALSE;
 }
 
-BOOL WINAPI FreeRDP_WTSSetUserConfigA(LPSTR pServerName, LPSTR pUserName, WTS_CONFIG_CLASS WTSConfigClass, LPSTR pBuffer, DWORD DataLength)
+BOOL WINAPI FreeRDP_WTSSetUserConfigA(LPSTR pServerName, LPSTR pUserName,
+                                      WTS_CONFIG_CLASS WTSConfigClass, LPSTR pBuffer, DWORD DataLength)
 {
        return FALSE;
 }
 
-BOOL WINAPI FreeRDP_WTSSendMessageW(HANDLE hServer, DWORD SessionId, LPWSTR pTitle, DWORD TitleLength,
-               LPWSTR pMessage, DWORD MessageLength, DWORD Style, DWORD Timeout, DWORD* pResponse, BOOL bWait)
+BOOL WINAPI FreeRDP_WTSSendMessageW(HANDLE hServer, DWORD SessionId,
+                                    LPWSTR pTitle, DWORD TitleLength,
+                                    LPWSTR pMessage, DWORD MessageLength, DWORD Style, DWORD Timeout,
+                                    DWORD* pResponse, BOOL bWait)
 {
        return FALSE;
 }
 
-BOOL WINAPI FreeRDP_WTSSendMessageA(HANDLE hServer, DWORD SessionId, LPSTR pTitle, DWORD TitleLength,
-               LPSTR pMessage, DWORD MessageLength, DWORD Style, DWORD Timeout, DWORD* pResponse, BOOL bWait)
+BOOL WINAPI FreeRDP_WTSSendMessageA(HANDLE hServer, DWORD SessionId,
+                                    LPSTR pTitle, DWORD TitleLength,
+                                    LPSTR pMessage, DWORD MessageLength, DWORD Style, DWORD Timeout,
+                                    DWORD* pResponse, BOOL bWait)
 {
        return FALSE;
 }
 
-BOOL WINAPI FreeRDP_WTSDisconnectSession(HANDLE hServer, DWORD SessionId, BOOL bWait)
+BOOL WINAPI FreeRDP_WTSDisconnectSession(HANDLE hServer, DWORD SessionId,
+        BOOL bWait)
 {
        return FALSE;
 }
 
-BOOL WINAPI FreeRDP_WTSLogoffSession(HANDLE hServer, DWORD SessionId, BOOL bWait)
+BOOL WINAPI FreeRDP_WTSLogoffSession(HANDLE hServer, DWORD SessionId,
+                                     BOOL bWait)
 {
        return FALSE;
 }
@@ -923,12 +976,14 @@ BOOL WINAPI FreeRDP_WTSShutdownSystem(HANDLE hServer, DWORD ShutdownFlag)
        return FALSE;
 }
 
-BOOL WINAPI FreeRDP_WTSWaitSystemEvent(HANDLE hServer, DWORD EventMask, DWORD* pEventFlags)
+BOOL WINAPI FreeRDP_WTSWaitSystemEvent(HANDLE hServer, DWORD EventMask,
+                                       DWORD* pEventFlags)
 {
        return FALSE;
 }
 
-HANDLE WINAPI FreeRDP_WTSVirtualChannelOpen(HANDLE hServer, DWORD SessionId, LPSTR pVirtualName)
+HANDLE WINAPI FreeRDP_WTSVirtualChannelOpen(HANDLE hServer, DWORD SessionId,
+        LPSTR pVirtualName)
 {
        int length;
        UINT32 index;
@@ -938,8 +993,8 @@ HANDLE WINAPI FreeRDP_WTSVirtualChannelOpen(HANDLE hServer, DWORD SessionId, LPS
        rdpPeerChannel* channel;
        WTSVirtualChannelManager* vcm;
        HANDLE hChannelHandle = NULL;
-
        vcm = (WTSVirtualChannelManager*) hServer;
+
        if (!vcm)
        {
                SetLastError(ERROR_INVALID_DATA);
@@ -948,8 +1003,8 @@ HANDLE WINAPI FreeRDP_WTSVirtualChannelOpen(HANDLE hServer, DWORD SessionId, LPS
 
        client = vcm->client;
        mcs = client->context->rdp->mcs;
-
        length = strlen(pVirtualName);
+
        if (length > 8)
        {
                SetLastError(ERROR_NOT_FOUND);
@@ -958,7 +1013,8 @@ HANDLE WINAPI FreeRDP_WTSVirtualChannelOpen(HANDLE hServer, DWORD SessionId, LPS
 
        for (index = 0; index < mcs->channelCount; index++)
        {
-               if (mcs->channels[index].joined && (strncmp(mcs->channels[index].Name, pVirtualName, length) == 0))
+               if (mcs->channels[index].joined
+                   && (strncmp(mcs->channels[index].Name, pVirtualName, length) == 0))
                {
                        joined = TRUE;
                        break;
@@ -972,9 +1028,11 @@ HANDLE WINAPI FreeRDP_WTSVirtualChannelOpen(HANDLE hServer, DWORD SessionId, LPS
        }
 
        channel = (rdpPeerChannel*) mcs->channels[index].handle;
+
        if (!channel)
        {
                channel = (rdpPeerChannel*) calloc(1, sizeof(rdpPeerChannel));
+
                if (!channel)
                        goto error_channel_alloc;
 
@@ -983,13 +1041,17 @@ HANDLE WINAPI FreeRDP_WTSVirtualChannelOpen(HANDLE hServer, DWORD SessionId, LPS
                channel->channelId = mcs->channels[index].ChannelId;
                channel->index = index;
                channel->channelType = RDP_PEER_CHANNEL_TYPE_SVC;
-               channel->receiveData = Stream_New(NULL, client->settings->VirtualChannelChunkSize);
+               channel->receiveData = Stream_New(NULL,
+                                                 client->settings->VirtualChannelChunkSize);
+
                if (!channel->receiveData)
                {
                        WLog_ERR(TAG, "Stream_New failed!");
                        goto error_receiveData;
                }
+
                channel->queue = MessageQueue_New(NULL);
+
                if (!channel->queue)
                        goto error_queue;
 
@@ -998,7 +1060,6 @@ HANDLE WINAPI FreeRDP_WTSVirtualChannelOpen(HANDLE hServer, DWORD SessionId, LPS
 
        hChannelHandle = (HANDLE) channel;
        return hChannelHandle;
-
 error_queue:
        Stream_Free(channel->receiveData, TRUE);
 error_receiveData:
@@ -1008,7 +1069,8 @@ error_channel_alloc:
        return NULL;
 }
 
-HANDLE WINAPI FreeRDP_WTSVirtualChannelOpenEx(DWORD SessionId, LPSTR pVirtualName, DWORD flags)
+HANDLE WINAPI FreeRDP_WTSVirtualChannelOpenEx(DWORD SessionId,
+        LPSTR pVirtualName, DWORD flags)
 {
        UINT32 index;
        wStream* s;
@@ -1022,7 +1084,8 @@ HANDLE WINAPI FreeRDP_WTSVirtualChannelOpenEx(DWORD SessionId, LPSTR pVirtualNam
        if (SessionId == WTS_CURRENT_SESSION)
                return NULL;
 
-       vcm = (WTSVirtualChannelManager*) HashTable_GetItemValue(g_ServerHandles, (void*) (UINT_PTR) SessionId);
+       vcm = (WTSVirtualChannelManager*) HashTable_GetItemValue(g_ServerHandles,
+               (void*)(UINT_PTR) SessionId);
 
        if (!vcm)
                return NULL;
@@ -1037,7 +1100,8 @@ HANDLE WINAPI FreeRDP_WTSVirtualChannelOpenEx(DWORD SessionId, LPSTR pVirtualNam
 
        for (index = 0; index < mcs->channelCount; index++)
        {
-               if (mcs->channels[index].joined && (strncmp(mcs->channels[index].Name, "drdynvc", 7) == 0))
+               if (mcs->channels[index].joined
+                   && (strncmp(mcs->channels[index].Name, "drdynvc", 7) == 0))
                {
                        joined = TRUE;
                        break;
@@ -1057,6 +1121,7 @@ HANDLE WINAPI FreeRDP_WTSVirtualChannelOpenEx(DWORD SessionId, LPSTR pVirtualNam
        }
 
        channel = (rdpPeerChannel*) calloc(1, sizeof(rdpPeerChannel));
+
        if (!channel)
        {
                SetLastError(ERROR_NOT_ENOUGH_MEMORY);
@@ -1066,7 +1131,8 @@ HANDLE WINAPI FreeRDP_WTSVirtualChannelOpenEx(DWORD SessionId, LPSTR pVirtualNam
        channel->vcm = vcm;
        channel->client = client;
        channel->channelType = RDP_PEER_CHANNEL_TYPE_DVC;
-       channel->receiveData = Stream_New(NULL, client->settings->VirtualChannelChunkSize);
+       channel->receiveData = Stream_New(NULL,
+                                         client->settings->VirtualChannelChunkSize);
 
        if (!channel->receiveData)
        {
@@ -1075,24 +1141,29 @@ HANDLE WINAPI FreeRDP_WTSVirtualChannelOpenEx(DWORD SessionId, LPSTR pVirtualNam
        }
 
        channel->queue = MessageQueue_New(NULL);
+
        if (!channel->queue)
                goto error_queue;
 
        channel->channelId = InterlockedIncrement(&vcm->dvc_channel_id_seq);
+
        if (ArrayList_Add(vcm->dynamicVirtualChannels, channel) < 0)
                goto error_add;
 
        s = Stream_New(NULL, 64);
+
        if (!s)
                goto error_s;
+
        if (!wts_write_drdynvc_create_request(s, channel->channelId, pVirtualName))
                goto error_create;
-       if (!WTSVirtualChannelWrite(vcm->drdynvc_channel, (PCHAR) Stream_Buffer(s), Stream_GetPosition(s), &written))
+
+       if (!WTSVirtualChannelWrite(vcm->drdynvc_channel, (PCHAR) Stream_Buffer(s),
+                                   Stream_GetPosition(s), &written))
                goto error_create;
-       Stream_Free(s, TRUE);
 
+       Stream_Free(s, TRUE);
        return channel;
-
 error_create:
        Stream_Free(s, TRUE);
 error_s:
@@ -1132,8 +1203,8 @@ BOOL WINAPI FreeRDP_WTSVirtualChannelClose(HANDLE hChannelHandle)
                        if (channel->dvc_open_state == DVC_OPEN_STATE_SUCCEEDED)
                        {
                                ULONG written;
-
                                s = Stream_New(NULL, 8);
+
                                if (!s)
                                {
                                        WLog_ERR(TAG, "Stream_New failed!");
@@ -1142,10 +1213,10 @@ BOOL WINAPI FreeRDP_WTSVirtualChannelClose(HANDLE hChannelHandle)
                                else
                                {
                                        wts_write_drdynvc_header(s, CLOSE_REQUEST_PDU, channel->channelId);
-                                       ret = WTSVirtualChannelWrite(vcm->drdynvc_channel, (PCHAR) Stream_Buffer(s), Stream_GetPosition(s), &written);
+                                       ret = WTSVirtualChannelWrite(vcm->drdynvc_channel, (PCHAR) Stream_Buffer(s),
+                                                                    Stream_GetPosition(s), &written);
                                        Stream_Free(s, TRUE);
                                }
-
                        }
                }
 
@@ -1164,7 +1235,8 @@ BOOL WINAPI FreeRDP_WTSVirtualChannelClose(HANDLE hChannelHandle)
        return ret;
 }
 
-BOOL WINAPI FreeRDP_WTSVirtualChannelRead(HANDLE hChannelHandle, ULONG TimeOut, PCHAR Buffer, ULONG BufferSize, PULONG pBytesRead)
+BOOL WINAPI FreeRDP_WTSVirtualChannelRead(HANDLE hChannelHandle, ULONG TimeOut,
+        PCHAR Buffer, ULONG BufferSize, PULONG pBytesRead)
 {
        BYTE* buffer;
        wMessage message;
@@ -1178,9 +1250,8 @@ BOOL WINAPI FreeRDP_WTSVirtualChannelRead(HANDLE hChannelHandle, ULONG TimeOut,
                return FALSE;
        }
 
-       messageCtx = (wtsChannelMessage*) (UINT_PTR) message.context;
-       buffer = (BYTE*) (messageCtx + 1);
-
+       messageCtx = (wtsChannelMessage*)(UINT_PTR) message.context;
+       buffer = (BYTE*)(messageCtx + 1);
        *pBytesRead = messageCtx->length - messageCtx->offset;
 
        if (Buffer == NULL || BufferSize == 0)
@@ -1203,7 +1274,8 @@ BOOL WINAPI FreeRDP_WTSVirtualChannelRead(HANDLE hChannelHandle, ULONG TimeOut,
        return TRUE;
 }
 
-BOOL WINAPI FreeRDP_WTSVirtualChannelWrite(HANDLE hChannelHandle, PCHAR Buffer, ULONG Length, PULONG pBytesWritten)
+BOOL WINAPI FreeRDP_WTSVirtualChannelWrite(HANDLE hChannelHandle, PCHAR Buffer,
+        ULONG Length, PULONG pBytesWritten)
 {
        wStream* s;
        int cbLen;
@@ -1222,19 +1294,20 @@ BOOL WINAPI FreeRDP_WTSVirtualChannelWrite(HANDLE hChannelHandle, PCHAR Buffer,
        if (channel->channelType == RDP_PEER_CHANNEL_TYPE_SVC)
        {
                length = Length;
-               buffer = (BYTE *)malloc(length);
+               buffer = (BYTE*)malloc(length);
+
                if (!buffer)
                {
                        SetLastError(E_OUTOFMEMORY);
                        return FALSE;
                }
-               CopyMemory(buffer, Buffer, length);
 
+               CopyMemory(buffer, Buffer, length);
                totalWritten = Length;
-
                ret = wts_queue_send_item(channel, buffer, length);
        }
-       else if (!channel->vcm->drdynvc_channel || (channel->vcm->drdynvc_state != DRDYNVC_STATE_READY))
+       else if (!channel->vcm->drdynvc_channel
+                || (channel->vcm->drdynvc_state != DRDYNVC_STATE_READY))
        {
                DEBUG_DVC("drdynvc not ready");
                return FALSE;
@@ -1246,6 +1319,7 @@ BOOL WINAPI FreeRDP_WTSVirtualChannelWrite(HANDLE hChannelHandle, PCHAR Buffer,
                while (Length > 0)
                {
                        s = Stream_New(NULL, channel->client->settings->VirtualChannelChunkSize);
+
                        if (!s)
                        {
                                WLog_ERR(TAG, "Stream_New failed!");
@@ -1254,7 +1328,6 @@ BOOL WINAPI FreeRDP_WTSVirtualChannelWrite(HANDLE hChannelHandle, PCHAR Buffer,
                        }
 
                        buffer = Stream_Buffer(s);
-
                        Stream_Seek_UINT8(s);
                        cbChId = wts_write_variable_uint(s, channel->channelId);
 
@@ -1277,11 +1350,9 @@ BOOL WINAPI FreeRDP_WTSVirtualChannelWrite(HANDLE hChannelHandle, PCHAR Buffer,
                        Stream_Write(s, Buffer, written);
                        length = Stream_GetPosition(s);
                        Stream_Free(s, FALSE);
-
                        Length -= written;
                        Buffer += written;
                        totalWritten += written;
-
                        ret = wts_queue_send_item(channel->vcm->drdynvc_channel, buffer, length);
                }
        }
@@ -1302,7 +1373,8 @@ BOOL WINAPI FreeRDP_WTSVirtualChannelPurgeOutput(HANDLE hChannelHandle)
        return TRUE;
 }
 
-BOOL WINAPI FreeRDP_WTSVirtualChannelQuery(HANDLE hChannelHandle, WTS_VIRTUAL_CLASS WtsVirtualClass, PVOID* ppBuffer, DWORD* pBytesReturned)
+BOOL WINAPI FreeRDP_WTSVirtualChannelQuery(HANDLE hChannelHandle,
+        WTS_VIRTUAL_CLASS WtsVirtualClass, PVOID* ppBuffer, DWORD* pBytesReturned)
 {
        void* pfd;
        BOOL bval;
@@ -1312,13 +1384,11 @@ BOOL WINAPI FreeRDP_WTSVirtualChannelQuery(HANDLE hChannelHandle, WTS_VIRTUAL_CL
        BOOL status = FALSE;
        rdpPeerChannel* channel = (rdpPeerChannel*) hChannelHandle;
        ZeroMemory(fds, sizeof(fds));
-
        hEvent = MessageQueue_Event(channel->queue);
 
        switch ((UINT32) WtsVirtualClass)
        {
                case WTSVirtualFileHandle:
-
                        pfd = GetEventWaitObject(hEvent);
 
                        if (pfd)
@@ -1328,26 +1398,34 @@ BOOL WINAPI FreeRDP_WTSVirtualChannelQuery(HANDLE hChannelHandle, WTS_VIRTUAL_CL
                        }
 
                        *ppBuffer = malloc(sizeof(void*));
+
                        if (!*ppBuffer)
                        {
                                SetLastError(E_OUTOFMEMORY);
-                       } else {
+                       }
+                       else
+                       {
                                CopyMemory(*ppBuffer, &fds[0], sizeof(void*));
                                *pBytesReturned = sizeof(void*);
                                status = TRUE;
                        }
+
                        break;
 
                case WTSVirtualEventHandle:
                        *ppBuffer = malloc(sizeof(HANDLE));
+
                        if (!*ppBuffer)
                        {
                                SetLastError(E_OUTOFMEMORY);
-                       } else {
+                       }
+                       else
+                       {
                                CopyMemory(*ppBuffer, &(hEvent), sizeof(HANDLE));
                                *pBytesReturned = sizeof(void*);
                                status = TRUE;
                        }
+
                        break;
 
                case WTSVirtualChannelReady:
@@ -1378,19 +1456,24 @@ BOOL WINAPI FreeRDP_WTSVirtualChannelQuery(HANDLE hChannelHandle, WTS_VIRTUAL_CL
                        }
 
                        *ppBuffer = malloc(sizeof(BOOL));
+
                        if (!*ppBuffer)
                        {
                                SetLastError(E_OUTOFMEMORY);
                                status = FALSE;
-                       } else {
+                       }
+                       else
+                       {
                                CopyMemory(*ppBuffer, &bval, sizeof(BOOL));
                                *pBytesReturned = sizeof(BOOL);
                        }
+
                        break;
 
                default:
                        break;
        }
+
        return status;
 }
 
@@ -1399,12 +1482,14 @@ VOID WINAPI FreeRDP_WTSFreeMemory(PVOID pMemory)
        free(pMemory);
 }
 
-BOOL WINAPI FreeRDP_WTSFreeMemoryExW(WTS_TYPE_CLASS WTSTypeClass, PVOID pMemory, ULONG NumberOfEntries)
+BOOL WINAPI FreeRDP_WTSFreeMemoryExW(WTS_TYPE_CLASS WTSTypeClass, PVOID pMemory,
+                                     ULONG NumberOfEntries)
 {
        return FALSE;
 }
 
-BOOL WINAPI FreeRDP_WTSFreeMemoryExA(WTS_TYPE_CLASS WTSTypeClass, PVOID pMemory, ULONG NumberOfEntries)
+BOOL WINAPI FreeRDP_WTSFreeMemoryExA(WTS_TYPE_CLASS WTSTypeClass, PVOID pMemory,
+                                     ULONG NumberOfEntries)
 {
        return FALSE;
 }
@@ -1419,12 +1504,14 @@ BOOL WINAPI FreeRDP_WTSUnRegisterSessionNotification(HWND hWnd)
        return FALSE;
 }
 
-BOOL WINAPI FreeRDP_WTSRegisterSessionNotificationEx(HANDLE hServer, HWND hWnd, DWORD dwFlags)
+BOOL WINAPI FreeRDP_WTSRegisterSessionNotificationEx(HANDLE hServer, HWND hWnd,
+        DWORD dwFlags)
 {
        return FALSE;
 }
 
-BOOL WINAPI FreeRDP_WTSUnRegisterSessionNotificationEx(HANDLE hServer, HWND hWnd)
+BOOL WINAPI FreeRDP_WTSUnRegisterSessionNotificationEx(HANDLE hServer,
+        HWND hWnd)
 {
        return FALSE;
 }
@@ -1434,72 +1521,86 @@ BOOL WINAPI FreeRDP_WTSQueryUserToken(ULONG SessionId, PHANDLE phToken)
        return FALSE;
 }
 
-BOOL WINAPI FreeRDP_WTSEnumerateProcessesExW(HANDLE hServer, DWORD* pLevel, DWORD SessionId, LPWSTR* ppProcessInfo, DWORD* pCount)
+BOOL WINAPI FreeRDP_WTSEnumerateProcessesExW(HANDLE hServer, DWORD* pLevel,
+        DWORD SessionId, LPWSTR* ppProcessInfo, DWORD* pCount)
 {
        return FALSE;
 }
 
-BOOL WINAPI FreeRDP_WTSEnumerateProcessesExA(HANDLE hServer, DWORD* pLevel, DWORD SessionId, LPSTR* ppProcessInfo, DWORD* pCount)
+BOOL WINAPI FreeRDP_WTSEnumerateProcessesExA(HANDLE hServer, DWORD* pLevel,
+        DWORD SessionId, LPSTR* ppProcessInfo, DWORD* pCount)
 {
        return FALSE;
 }
 
-BOOL WINAPI FreeRDP_WTSEnumerateListenersW(HANDLE hServer, PVOID pReserved, DWORD Reserved, PWTSLISTENERNAMEW pListeners, DWORD* pCount)
+BOOL WINAPI FreeRDP_WTSEnumerateListenersW(HANDLE hServer, PVOID pReserved,
+        DWORD Reserved, PWTSLISTENERNAMEW pListeners, DWORD* pCount)
 {
        return FALSE;
 }
 
-BOOL WINAPI FreeRDP_WTSEnumerateListenersA(HANDLE hServer, PVOID pReserved, DWORD Reserved, PWTSLISTENERNAMEA pListeners, DWORD* pCount)
+BOOL WINAPI FreeRDP_WTSEnumerateListenersA(HANDLE hServer, PVOID pReserved,
+        DWORD Reserved, PWTSLISTENERNAMEA pListeners, DWORD* pCount)
 {
        return FALSE;
 }
 
-BOOL WINAPI FreeRDP_WTSQueryListenerConfigW(HANDLE hServer, PVOID pReserved, DWORD Reserved, LPWSTR pListenerName, PWTSLISTENERCONFIGW pBuffer)
+BOOL WINAPI FreeRDP_WTSQueryListenerConfigW(HANDLE hServer, PVOID pReserved,
+        DWORD Reserved, LPWSTR pListenerName, PWTSLISTENERCONFIGW pBuffer)
 {
        return FALSE;
 }
 
-BOOL WINAPI FreeRDP_WTSQueryListenerConfigA(HANDLE hServer, PVOID pReserved, DWORD Reserved, LPSTR pListenerName, PWTSLISTENERCONFIGA pBuffer)
+BOOL WINAPI FreeRDP_WTSQueryListenerConfigA(HANDLE hServer, PVOID pReserved,
+        DWORD Reserved, LPSTR pListenerName, PWTSLISTENERCONFIGA pBuffer)
 {
        return FALSE;
 }
 
-BOOL WINAPI FreeRDP_WTSCreateListenerW(HANDLE hServer, PVOID pReserved, DWORD Reserved,
-               LPWSTR pListenerName, PWTSLISTENERCONFIGW pBuffer, DWORD flag)
+BOOL WINAPI FreeRDP_WTSCreateListenerW(HANDLE hServer, PVOID pReserved,
+                                       DWORD Reserved,
+                                       LPWSTR pListenerName, PWTSLISTENERCONFIGW pBuffer, DWORD flag)
 {
        return FALSE;
 }
 
-BOOL WINAPI FreeRDP_WTSCreateListenerA(HANDLE hServer, PVOID pReserved, DWORD Reserved,
-               LPSTR pListenerName, PWTSLISTENERCONFIGA pBuffer, DWORD flag)
+BOOL WINAPI FreeRDP_WTSCreateListenerA(HANDLE hServer, PVOID pReserved,
+                                       DWORD Reserved,
+                                       LPSTR pListenerName, PWTSLISTENERCONFIGA pBuffer, DWORD flag)
 {
        return FALSE;
 }
 
-BOOL WINAPI FreeRDP_WTSSetListenerSecurityW(HANDLE hServer, PVOID pReserved, DWORD Reserved,
-               LPWSTR pListenerName, SECURITY_INFORMATION SecurityInformation,
-               PSECURITY_DESCRIPTOR pSecurityDescriptor)
+BOOL WINAPI FreeRDP_WTSSetListenerSecurityW(HANDLE hServer, PVOID pReserved,
+        DWORD Reserved,
+        LPWSTR pListenerName, SECURITY_INFORMATION SecurityInformation,
+        PSECURITY_DESCRIPTOR pSecurityDescriptor)
 {
        return FALSE;
 }
 
-BOOL WINAPI FreeRDP_WTSSetListenerSecurityA(HANDLE hServer, PVOID pReserved, DWORD Reserved,
-               LPSTR pListenerName, SECURITY_INFORMATION SecurityInformation,
-               PSECURITY_DESCRIPTOR pSecurityDescriptor)
+BOOL WINAPI FreeRDP_WTSSetListenerSecurityA(HANDLE hServer, PVOID pReserved,
+        DWORD Reserved,
+        LPSTR pListenerName, SECURITY_INFORMATION SecurityInformation,
+        PSECURITY_DESCRIPTOR pSecurityDescriptor)
 {
        return FALSE;
 }
 
-BOOL WINAPI FreeRDP_WTSGetListenerSecurityW(HANDLE hServer, PVOID pReserved, DWORD Reserved,
-               LPWSTR pListenerName, SECURITY_INFORMATION SecurityInformation,
-               PSECURITY_DESCRIPTOR pSecurityDescriptor, DWORD nLength, LPDWORD lpnLengthNeeded)
+BOOL WINAPI FreeRDP_WTSGetListenerSecurityW(HANDLE hServer, PVOID pReserved,
+        DWORD Reserved,
+        LPWSTR pListenerName, SECURITY_INFORMATION SecurityInformation,
+        PSECURITY_DESCRIPTOR pSecurityDescriptor, DWORD nLength,
+        LPDWORD lpnLengthNeeded)
 {
        return FALSE;
 }
 
-BOOL WINAPI FreeRDP_WTSGetListenerSecurityA(HANDLE hServer, PVOID pReserved, DWORD Reserved,
-               LPSTR pListenerName, SECURITY_INFORMATION SecurityInformation,
-               PSECURITY_DESCRIPTOR pSecurityDescriptor, DWORD nLength, LPDWORD lpnLengthNeeded)
+BOOL WINAPI FreeRDP_WTSGetListenerSecurityA(HANDLE hServer, PVOID pReserved,
+        DWORD Reserved,
+        LPSTR pListenerName, SECURITY_INFORMATION SecurityInformation,
+        PSECURITY_DESCRIPTOR pSecurityDescriptor, DWORD nLength,
+        LPDWORD lpnLengthNeeded)
 {
        return FALSE;
 }
@@ -1528,7 +1629,8 @@ BOOL WINAPI FreeRDP_WTSLogoffUser(HANDLE hServer)
        return FALSE;
 }
 
-BOOL WINAPI FreeRDP_WTSLogonUser(HANDLE hServer, LPCSTR username, LPCSTR password, LPCSTR domain)
+BOOL WINAPI FreeRDP_WTSLogonUser(HANDLE hServer, LPCSTR username,
+                                 LPCSTR password, LPCSTR domain)
 {
        return FALSE;
 }
index 3fa5b7c..ba9a2e2 100644 (file)
@@ -38,9 +38,9 @@ FREERDP_LOCAL BOOL rdp_write_client_time_zone(wStream* s,
 
 #define TIMEZONE_TAG FREERDP_TAG("core.timezone")
 #ifdef WITH_DEBUG_TIMEZONE
-#define DEBUG_TIMEZONE(fmt, ...) WLog_DBG(TIMEZONE_TAG, fmt, ## __VA_ARGS__)
+#define DEBUG_TIMEZONE(...) WLog_DBG(TIMEZONE_TAG, __VA_ARGS__)
 #else
-#define DEBUG_TIMEZONE(fmt, ...) do { } while (0)
+#define DEBUG_TIMEZONE(...) do { } while (0)
 #endif
 
 #endif /* __TIMEZONE_H */
index 09cd381..a6ba4b8 100644 (file)
@@ -382,26 +382,23 @@ static void transport_bio_error_log(LPCSTR tag, LPCSTR biofunc, BIO* bio,
        wLog* log;
        wLogMessage log_message;
        int saveerrno;
+       DWORD level;
        saveerrno = errno;
        log = WLog_Get(tag);
 
        if (!log)
                return;
 
-       log_message.Level = WLOG_ERROR;
+       level = WLOG_ERROR;
 
-       if (log_message.Level < WLog_GetLogLevel(log))
+       if (level < WLog_GetLogLevel(log))
                return;
 
-       log_message.Type = WLOG_MESSAGE_TEXT;
-       log_message.LineNumber = line;
-       log_message.FileName = file;
-       log_message.FunctionName = func;
-
        if (ERR_peek_error() == 0)
        {
-               log_message.FormatString = "%s returned a system error %d: %s";
-               WLog_PrintMessage(log, &log_message, biofunc, saveerrno, strerror(saveerrno));
+               const char* fmt = "%s returned a system error %d: %s";
+               WLog_PrintMessage(log, WLOG_MESSAGE_TEXT, level, line, file, func, fmt, biofunc,
+                                 saveerrno, strerror(saveerrno));
                return;
        }
 
@@ -409,11 +406,13 @@ static void transport_bio_error_log(LPCSTR tag, LPCSTR biofunc, BIO* bio,
 
        if (buf)
        {
+               const char* fmt = "%s returned an error: %s";
+
                while ((sslerr = ERR_get_error()))
                {
                        ERR_error_string_n(sslerr, buf, 120);
-                       log_message.FormatString = "%s returned an error: %s";
-                       WLog_PrintMessage(log, &log_message, biofunc, buf);
+                       WLog_PrintMessage(log, WLOG_MESSAGE_TEXT, level, line, file, func, fmt, biofunc,
+                                         buf);
                }
 
                free(buf);
index 9892a90..4fdf4ba 100644 (file)
@@ -32,9 +32,9 @@ FREERDP_LOCAL BOOL update_recv_altsec_window_order(rdpUpdate* update,
 
 #define WND_TAG FREERDP_TAG("core.wnd")
 #ifdef WITH_DEBUG_WND
-#define DEBUG_WND(fmt, ...) WLog_DBG(WND_TAG, fmt, ## __VA_ARGS__)
+#define DEBUG_WND(...) WLog_DBG(WND_TAG, __VA_ARGS__)
 #else
-#define DEBUG_WND(fmt, ...) do { } while (0)
+#define DEBUG_WND(...) do { } while (0)
 #endif
 
 #endif /* __WINDOW_H */
index f883576..34fa8c2 100644 (file)
 
 #define KBD_TAG FREERDP_TAG("locale")
 #ifdef WITH_DEBUG_KBD
-#define DEBUG_KBD(fmt, ...) WLog_DBG(KBD_TAG, fmt, ## __VA_ARGS__)
+#define DEBUG_KBD(...) WLog_DBG(KBD_TAG, __VA_ARGS__)
 #else
-#define DEBUG_KBD(fmt, ...) do { } while (0)
+#define DEBUG_KBD(...) do { } while (0)
 #endif
 
 #define TIMEZONE_TAG FREERDP_TAG("timezone")
 #ifdef WITH_DEBUG_TIMEZONE
-#define DEBUG_TIMEZONE(fmt, ...) WLog_DBG(TIMEZONE_TAG, fmt, ## __VA_ARGS__)
+#define DEBUG_TIMEZONE(...) WLog_DBG(TIMEZONE_TAG, __VA_ARGS__)
 #else
-#define DEBUG_TIMEZONE(fmt, ...) do { } while (0)
+#define DEBUG_TIMEZONE(...) do { } while (0)
 #endif
 
 #endif /* __LIBLOCALE_H */
index 870c2e2..c11ec5b 100644 (file)
@@ -28,9 +28,9 @@
 #define TAG FREERDP_TAG("utils")
 
 #ifdef WITH_DEBUG_MSUSB
-#define DEBUG_MSUSB(fmt, ...) WLog_DBG(TAG, fmt, ## __VA_ARGS__)
+#define DEBUG_MSUSB(...) WLog_DBG(TAG, __VA_ARGS__)
 #else
-#define DEBUG_MSUSB(fmt, ...) do { } while (0)
+#define DEBUG_MSUSB(...) do { } while (0)
 #endif
 
 
@@ -39,7 +39,8 @@ static MSUSB_PIPE_DESCRIPTOR* msusb_mspipe_new()
        return (MSUSB_PIPE_DESCRIPTOR*) calloc(1, sizeof(MSUSB_PIPE_DESCRIPTOR));
 }
 
-static void msusb_mspipes_free(MSUSB_PIPE_DESCRIPTOR** MsPipes, UINT32 NumberOfPipes)
+static void msusb_mspipes_free(MSUSB_PIPE_DESCRIPTOR** MsPipes,
+                               UINT32 NumberOfPipes)
 {
        int pnum = 0;
 
@@ -47,13 +48,15 @@ static void msusb_mspipes_free(MSUSB_PIPE_DESCRIPTOR** MsPipes, UINT32 NumberOfP
        {
                for (pnum = 0; pnum < NumberOfPipes && MsPipes[pnum]; pnum++)
                {
-                               zfree(MsPipes[pnum]);
+                       zfree(MsPipes[pnum]);
                }
+
                zfree(MsPipes);
        }
 }
 
-void msusb_mspipes_replace(MSUSB_INTERFACE_DESCRIPTOR* MsInterface, MSUSB_PIPE_DESCRIPTOR** NewMsPipes, UINT32 NewNumberOfPipes)
+void msusb_mspipes_replace(MSUSB_INTERFACE_DESCRIPTOR* MsInterface,
+                           MSUSB_PIPE_DESCRIPTOR** NewMsPipes, UINT32 NewNumberOfPipes)
 {
        /* free orignal MsPipes */
        msusb_mspipes_free(MsInterface->MsPipes, MsInterface->NumberOfPipes);
@@ -62,51 +65,55 @@ void msusb_mspipes_replace(MSUSB_INTERFACE_DESCRIPTOR* MsInterface, MSUSB_PIPE_D
        MsInterface->NumberOfPipes = NewNumberOfPipes;
 }
 
-static MSUSB_PIPE_DESCRIPTOR** msusb_mspipes_read(BYTE* data, UINT32 data_size, UINT32 NumberOfPipes, int* offset)
+static MSUSB_PIPE_DESCRIPTOR** msusb_mspipes_read(BYTE* data, UINT32 data_size,
+        UINT32 NumberOfPipes, int* offset)
 {
        int pnum, move = 0;
        MSUSB_PIPE_DESCRIPTOR** MsPipes;
-               
-       MsPipes = (MSUSB_PIPE_DESCRIPTOR**) calloc(NumberOfPipes, sizeof(MSUSB_PIPE_DESCRIPTOR*));
+       MsPipes = (MSUSB_PIPE_DESCRIPTOR**) calloc(NumberOfPipes,
+                 sizeof(MSUSB_PIPE_DESCRIPTOR*));
+
        if (!MsPipes)
                return NULL;
-       
+
        for (pnum = 0; pnum < NumberOfPipes; pnum++)
        {
-               MSUSB_PIPE_DESCRIPTOR *MsPipe = msusb_mspipe_new();
+               MSUSB_PIPE_DESCRIPTOR* MsPipe = msusb_mspipe_new();
+
                if (!MsPipe)
                        goto out_error;
-               
+
                data_read_UINT16(data + move, MsPipe->MaximumPacketSize);
                data_read_UINT32(data + move + 4, MsPipe->MaximumTransferSize);
                data_read_UINT32(data + move + 8, MsPipe->PipeFlags);
                move += 12;
-/* Already set to zero by memset
-               MsPipe->PipeHandle         = 0;
-               MsPipe->bEndpointAddress = 0;
-               MsPipe->bInterval               = 0;
-               MsPipe->PipeType                 = 0;
-               MsPipe->InitCompleted   = 0;
-*/
-               
+               /* Already set to zero by memset
+                               MsPipe->PipeHandle         = 0;
+                               MsPipe->bEndpointAddress = 0;
+                               MsPipe->bInterval               = 0;
+                               MsPipe->PipeType                 = 0;
+                               MsPipe->InitCompleted   = 0;
+               */
                MsPipes[pnum] = MsPipe;
-       } 
+       }
+
        *offset += move;
-       
        return MsPipes;
-
 out_error:
+
        for (pnum = 0; pnum < NumberOfPipes; pnum++)
        {
                free(MsPipes[pnum]);
        }
+
        free(MsPipes);
        return NULL;
 }
 
 static MSUSB_INTERFACE_DESCRIPTOR* msusb_msinterface_new()
 {
-       return (MSUSB_INTERFACE_DESCRIPTOR*) calloc(1, sizeof(MSUSB_INTERFACE_DESCRIPTOR));
+       return (MSUSB_INTERFACE_DESCRIPTOR*) calloc(1,
+               sizeof(MSUSB_INTERFACE_DESCRIPTOR));
 }
 
 static void msusb_msinterface_free(MSUSB_INTERFACE_DESCRIPTOR* MsInterface)
@@ -119,7 +126,8 @@ static void msusb_msinterface_free(MSUSB_INTERFACE_DESCRIPTOR* MsInterface)
        }
 }
 
-static void msusb_msinterface_free_list(MSUSB_INTERFACE_DESCRIPTOR** MsInterfaces, UINT32 NumInterfaces)
+static void msusb_msinterface_free_list(MSUSB_INTERFACE_DESCRIPTOR**
+                                        MsInterfaces, UINT32 NumInterfaces)
 {
        int inum = 0;
 
@@ -134,68 +142,70 @@ static void msusb_msinterface_free_list(MSUSB_INTERFACE_DESCRIPTOR** MsInterface
        }
 }
 
-void msusb_msinterface_replace(MSUSB_CONFIG_DESCRIPTOR* MsConfig, BYTE InterfaceNumber, MSUSB_INTERFACE_DESCRIPTOR* NewMsInterface)
+void msusb_msinterface_replace(MSUSB_CONFIG_DESCRIPTOR* MsConfig,
+                               BYTE InterfaceNumber, MSUSB_INTERFACE_DESCRIPTOR* NewMsInterface)
 {
        msusb_msinterface_free(MsConfig->MsInterfaces[InterfaceNumber]);
-       MsConfig->MsInterfaces[InterfaceNumber] = NewMsInterface;       
+       MsConfig->MsInterfaces[InterfaceNumber] = NewMsInterface;
 }
 
-MSUSB_INTERFACE_DESCRIPTOR* msusb_msinterface_read(BYTE* data, UINT32 data_size, int* offset)
+MSUSB_INTERFACE_DESCRIPTOR* msusb_msinterface_read(BYTE* data, UINT32 data_size,
+        int* offset)
 {
        MSUSB_INTERFACE_DESCRIPTOR* MsInterface;
-       
        MsInterface = msusb_msinterface_new();
+
        if (!MsInterface)
                return NULL;
-       
+
        data_read_UINT16(data, MsInterface->Length);
        data_read_UINT16(data + 2, MsInterface->NumberOfPipesExpected);
        data_read_BYTE(data + 4, MsInterface->InterfaceNumber);
        data_read_BYTE(data + 5, MsInterface->AlternateSetting);
        data_read_UINT32(data + 8, MsInterface->NumberOfPipes);
        *offset += 12;
-
        MsInterface->InterfaceHandle = 0;
        MsInterface->bInterfaceClass = 0;
        MsInterface->bInterfaceSubClass = 0;
        MsInterface->bInterfaceProtocol = 0;
        MsInterface->InitCompleted = 0;
        MsInterface->MsPipes = NULL;
-       
+
        if (MsInterface->NumberOfPipes > 0)
        {
-               MsInterface->MsPipes = 
-                       msusb_mspipes_read(data+(*offset), data_size-(*offset), MsInterface->NumberOfPipes, offset);
+               MsInterface->MsPipes =
+                   msusb_mspipes_read(data + (*offset), data_size - (*offset),
+                                      MsInterface->NumberOfPipes, offset);
+
                if (!MsInterface->MsPipes)
                        goto out_error;
        }
-       
-       return MsInterface;
 
+       return MsInterface;
 out_error:
        msusb_msinterface_free(MsInterface);
        return NULL;
 }
 
-int msusb_msinterface_write(MSUSB_INTERFACE_DESCRIPTOR* MsInterface, BYTE* data, int* offset)
+int msusb_msinterface_write(MSUSB_INTERFACE_DESCRIPTOR* MsInterface, BYTE* data,
+                            int* offset)
 {
-       MSUSB_PIPE_DESCRIPTOR ** MsPipes;
-       MSUSB_PIPE_DESCRIPTOR * MsPipe;
+       MSUSB_PIPE_DESCRIPTOR** MsPipes;
+       MSUSB_PIPE_DESCRIPTOR* MsPipe;
        int pnum = 0, move = 0;
-       
        /* Length */
-       data_write_UINT16(data, MsInterface->Length); 
+       data_write_UINT16(data, MsInterface->Length);
        /* InterfaceNumber */
-       data_write_BYTE(data + 2, MsInterface->InterfaceNumber); 
+       data_write_BYTE(data + 2, MsInterface->InterfaceNumber);
        /* AlternateSetting */
-       data_write_BYTE(data + 3, MsInterface->AlternateSetting); 
+       data_write_BYTE(data + 3, MsInterface->AlternateSetting);
        /* bInterfaceClass */
-       data_write_BYTE(data + 4, MsInterface->bInterfaceClass); 
+       data_write_BYTE(data + 4, MsInterface->bInterfaceClass);
        /* bInterfaceSubClass */
-       data_write_BYTE(data + 5, MsInterface->bInterfaceSubClass); 
+       data_write_BYTE(data + 5, MsInterface->bInterfaceSubClass);
        /* bInterfaceProtocol */
        data_write_BYTE(data + 6, MsInterface->bInterfaceProtocol);
-       /* Padding */ 
+       /* Padding */
        data_write_BYTE(data + 7, 0);
        /* InterfaceHandle */
        data_write_UINT32(data + 8, MsInterface->InterfaceHandle);
@@ -204,7 +214,8 @@ int msusb_msinterface_write(MSUSB_INTERFACE_DESCRIPTOR* MsInterface, BYTE* data,
        move += 16;
        /* Pipes */
        MsPipes = MsInterface->MsPipes;
-       for(pnum = 0; pnum < MsInterface->NumberOfPipes; pnum++)
+
+       for (pnum = 0; pnum < MsInterface->NumberOfPipes; pnum++)
        {
                MsPipe = MsPipes[pnum];
                /* MaximumPacketSize */
@@ -221,55 +232,53 @@ int msusb_msinterface_write(MSUSB_INTERFACE_DESCRIPTOR* MsInterface, BYTE* data,
                data_write_UINT32(data + move + 12, MsPipe->MaximumTransferSize);
                /* PipeFlags */
                data_write_UINT32(data + move + 16, MsPipe->PipeFlags);
-               
                move += 20;
        }
-       
+
        *offset += move;
-       
        return 0;
 }
 
-static MSUSB_INTERFACE_DESCRIPTOR** msusb_msinterface_read_list(BYTE * data, UINT32 data_size, UINT32 NumInterfaces)
+static MSUSB_INTERFACE_DESCRIPTOR** msusb_msinterface_read_list(BYTE* data,
+        UINT32 data_size, UINT32 NumInterfaces)
 {
        int inum, offset = 0;
        MSUSB_INTERFACE_DESCRIPTOR** MsInterfaces;
-       
-       MsInterfaces = (MSUSB_INTERFACE_DESCRIPTOR**) calloc(NumInterfaces, sizeof(MSUSB_INTERFACE_DESCRIPTOR*));
+       MsInterfaces = (MSUSB_INTERFACE_DESCRIPTOR**) calloc(NumInterfaces,
+                      sizeof(MSUSB_INTERFACE_DESCRIPTOR*));
+
        if (!MsInterfaces)
                return NULL;
-       
+
        for (inum = 0; inum < NumInterfaces; inum++)
        {
-               MsInterfaces[inum] = msusb_msinterface_read(data + offset, data_size - offset, &offset);
-       }   
-       
+               MsInterfaces[inum] = msusb_msinterface_read(data + offset, data_size - offset,
+                                    &offset);
+       }
+
        return MsInterfaces;
 }
 
-int msusb_msconfig_write(MSUSB_CONFIG_DESCRIPTOR* MsConfg, BYTE* data, int* offset)
+int msusb_msconfig_write(MSUSB_CONFIG_DESCRIPTOR* MsConfg, BYTE* data,
+                         int* offset)
 {
        int inum = 0;
        MSUSB_INTERFACE_DESCRIPTOR** MsInterfaces;
        MSUSB_INTERFACE_DESCRIPTOR* MsInterface;
-       
        /* ConfigurationHandle*/
        data_write_UINT32(data + *offset, MsConfg->ConfigurationHandle);
-
        /* NumInterfaces*/
-       data_write_UINT32(data + *offset + 4, MsConfg->NumInterfaces); 
+       data_write_UINT32(data + *offset + 4, MsConfg->NumInterfaces);
        *offset += 8;
-
        /* Interfaces */
-
        MsInterfaces = MsConfg->MsInterfaces;
 
-       for(inum = 0; inum < MsConfg->NumInterfaces; inum++)
+       for (inum = 0; inum < MsConfg->NumInterfaces; inum++)
        {
                MsInterface = MsInterfaces[inum];
                msusb_msinterface_write(MsInterface, data + (*offset), offset);
        }
-       
+
        return 0;
 }
 
@@ -288,16 +297,16 @@ void msusb_msconfig_free(MSUSB_CONFIG_DESCRIPTOR* MsConfig)
        }
 }
 
-MSUSB_CONFIG_DESCRIPTOR* msusb_msconfig_read(BYTE* data, UINT32 data_size, UINT32 NumInterfaces)
+MSUSB_CONFIG_DESCRIPTOR* msusb_msconfig_read(BYTE* data, UINT32 data_size,
+        UINT32 NumInterfaces)
 {
        int i, offset = 0;
        UINT16 lenInterface;
        MSUSB_CONFIG_DESCRIPTOR* MsConfig;
        BYTE lenConfiguration, typeConfiguration;
-       
        MsConfig = msusb_msconfig_new();
-       
-       for(i = 0; i < NumInterfaces; i++)
+
+       for (i = 0; i < NumInterfaces; i++)
        {
                data_read_UINT16(data + offset, lenInterface);
                offset += lenInterface;
@@ -309,33 +318,33 @@ MSUSB_CONFIG_DESCRIPTOR* msusb_msconfig_read(BYTE* data, UINT32 data_size, UINT3
        if (lenConfiguration != 0x9 || typeConfiguration != 0x2)
        {
                DEBUG_MSUSB("%s: len and type must be 0x9 and 0x2 , but it is 0x%x and 0x%x",
-                       lenConfiguration, typeConfiguration);
+                           lenConfiguration, typeConfiguration);
        }
 
        data_read_UINT16(data + offset + 2, MsConfig->wTotalLength);
        data_read_BYTE(data + offset + 5, MsConfig->bConfigurationValue);
-
        MsConfig->NumInterfaces = NumInterfaces;
        MsConfig->ConfigurationHandle = 0;
        MsConfig->InitCompleted = 0;
        MsConfig->MsOutSize = 0;
        MsConfig->MsInterfaces = NULL;
        offset = 0;
-       
+
        if (NumInterfaces > 0)
        {
-               MsConfig->MsInterfaces = msusb_msinterface_read_list(data, data_size, NumInterfaces);
+               MsConfig->MsInterfaces = msusb_msinterface_read_list(data, data_size,
+                                        NumInterfaces);
        }
-               
+
        return MsConfig;
 }
 
 void msusb_msconfig_dump(MSUSB_CONFIG_DESCRIPTOR* MsConfig)
 {
-       MSUSB_INTERFACE_DESCRIPTOR ** MsInterfaces;
-       MSUSB_INTERFACE_DESCRIPTOR * MsInterface;
-       MSUSB_PIPE_DESCRIPTOR ** MsPipes;
-       MSUSB_PIPE_DESCRIPTOR * MsPipe;
+       MSUSB_INTERFACE_DESCRIPTOR** MsInterfaces;
+       MSUSB_INTERFACE_DESCRIPTOR* MsInterface;
+       MSUSB_PIPE_DESCRIPTOR** MsPipes;
+       MSUSB_PIPE_DESCRIPTOR* MsPipe;
        int inum = 0, pnum = 0;
        WLog_INFO(TAG,  "=================MsConfig:========================");
        WLog_INFO(TAG,  "wTotalLength:%d", MsConfig->wTotalLength);
@@ -345,12 +354,14 @@ void msusb_msconfig_dump(MSUSB_CONFIG_DESCRIPTOR* MsConfig)
        WLog_INFO(TAG,  "MsOutSize:%d", MsConfig->MsOutSize);
        WLog_INFO(TAG,  "NumInterfaces:%d", MsConfig->NumInterfaces);
        MsInterfaces = MsConfig->MsInterfaces;
-       for(inum = 0; inum < MsConfig->NumInterfaces; inum++)
+
+       for (inum = 0; inum < MsConfig->NumInterfaces; inum++)
        {
                MsInterface = MsInterfaces[inum];
                WLog_INFO(TAG,  "       Interfase: %d", MsInterface->InterfaceNumber);
                WLog_INFO(TAG,  "       Length: %d", MsInterface->Length);
-               WLog_INFO(TAG,  "       NumberOfPipesExpected: %d", MsInterface->NumberOfPipesExpected);
+               WLog_INFO(TAG,  "       NumberOfPipesExpected: %d",
+                         MsInterface->NumberOfPipesExpected);
                WLog_INFO(TAG,  "       AlternateSetting: %d", MsInterface->AlternateSetting);
                WLog_INFO(TAG,  "       NumberOfPipes: %d", MsInterface->NumberOfPipes);
                WLog_INFO(TAG,  "       InterfaceHandle: 0x%x", MsInterface->InterfaceHandle);
@@ -359,6 +370,7 @@ void msusb_msconfig_dump(MSUSB_CONFIG_DESCRIPTOR* MsConfig)
                WLog_INFO(TAG,  "       bInterfaceProtocol: 0x%x", MsInterface->bInterfaceProtocol);
                WLog_INFO(TAG,  "       InitCompleted: %d", MsInterface->InitCompleted);
                MsPipes = MsInterface->MsPipes;
+
                for (pnum = 0; pnum < MsInterface->NumberOfPipes; pnum++)
                {
                        MsPipe = MsPipes[pnum];
@@ -373,5 +385,6 @@ void msusb_msconfig_dump(MSUSB_CONFIG_DESCRIPTOR* MsConfig)
                        WLog_INFO(TAG,  "               InitCompleted: %d", MsPipe->InitCompleted);
                }
        }
+
        WLog_INFO(TAG,  "==================================================");
 }
index 0f2eb6a..adec61d 100644 (file)
 #define TAG FREERDP_TAG("utils.ringbuffer")
 
 #ifdef WITH_DEBUG_RINGBUFFER
-#define DEBUG_RINGBUFFER(fmt, ...) WLog_DBG(TAG, fmt, ## __VA_ARGS__)
+#define DEBUG_RINGBUFFER(...) WLog_DBG(TAG, __VA_ARGS__)
 #else
-#define DEBUG_RINGBUFFER(fmt, ...) do { } while (0)
+#define DEBUG_RINGBUFFER(...) do { } while (0)
 #endif
 
 BOOL ringbuffer_init(RingBuffer* rb, size_t initialSize)
 {
        rb->buffer = malloc(initialSize);
-       
+
        if (!rb->buffer)
                return FALSE;
 
        rb->readPtr = rb->writePtr = 0;
        rb->initialSize = rb->size = rb->freeSize = initialSize;
-
        DEBUG_RINGBUFFER("ringbuffer_init(%p)", rb);
-
        return TRUE;
 }
 
@@ -66,7 +64,6 @@ size_t ringbuffer_capacity(const RingBuffer* rb)
 void ringbuffer_destroy(RingBuffer* rb)
 {
        DEBUG_RINGBUFFER("ringbuffer_destroy(%p)", rb);
-       
        free(rb->buffer);
        rb->buffer = NULL;
 }
@@ -74,7 +71,6 @@ void ringbuffer_destroy(RingBuffer* rb)
 static BOOL ringbuffer_realloc(RingBuffer* rb, size_t targetSize)
 {
        BYTE* newData;
-       
        DEBUG_RINGBUFFER("ringbuffer_realloc(%p): targetSize: %d", rb, targetSize);
 
        if (rb->writePtr == rb->readPtr)
@@ -83,10 +79,10 @@ static BOOL ringbuffer_realloc(RingBuffer* rb, size_t targetSize)
                 * beginning of the buffer
                 */
                newData = (BYTE*) realloc(rb->buffer, targetSize);
-               
+
                if (!newData)
                        return FALSE;
-               
+
                rb->readPtr = rb->writePtr = 0;
                rb->buffer = newData;
        }
@@ -101,7 +97,7 @@ static BOOL ringbuffer_realloc(RingBuffer* rb, size_t targetSize)
                 * [............|XXXXXXXXXXXXXX|..........]
                 */
                newData = (BYTE*) realloc(rb->buffer, targetSize);
-               
+
                if (!newData)
                        return FALSE;
 
@@ -113,10 +109,10 @@ static BOOL ringbuffer_realloc(RingBuffer* rb, size_t targetSize)
                 * and the write head is set accordingly
                 */
                newData = (BYTE*) malloc(targetSize);
-               
+
                if (!newData)
                        return FALSE;
-               
+
                if (rb->readPtr < rb->writePtr)
                {
                        /*        readPtr              writePtr
@@ -134,14 +130,13 @@ static BOOL ringbuffer_realloc(RingBuffer* rb, size_t targetSize)
                         * [XXXXXXXXXXXX|..............|XXXXXXXXXX]
                         */
                        BYTE* dst = newData;
-                       
                        memcpy(dst, rb->buffer + rb->readPtr, rb->size - rb->readPtr);
                        dst += (rb->size - rb->readPtr);
-                       
+
                        if (rb->writePtr)
                                memcpy(dst, rb->buffer, rb->writePtr);
                }
-               
+
                rb->writePtr = rb->size - rb->freeSize;
                rb->readPtr = 0;
                free(rb->buffer);
@@ -150,7 +145,6 @@ static BOOL ringbuffer_realloc(RingBuffer* rb, size_t targetSize)
 
        rb->freeSize += (targetSize - rb->size);
        rb->size = targetSize;
-       
        return TRUE;
 }
 
@@ -165,9 +159,8 @@ BOOL ringbuffer_write(RingBuffer* rb, const BYTE* ptr, size_t sz)
 {
        size_t toWrite;
        size_t remaining;
-
        DEBUG_RINGBUFFER("ringbuffer_write(%p): sz: %d", rb, sz);
-       
+
        if ((rb->freeSize <= sz) && !ringbuffer_realloc(rb, rb->size + sz))
                return FALSE;
 
@@ -179,7 +172,7 @@ BOOL ringbuffer_write(RingBuffer* rb, const BYTE* ptr, size_t sz)
         */
        toWrite = sz;
        remaining = sz;
-       
+
        if (rb->size - rb->writePtr < sz)
                toWrite = rb->size - rb->writePtr;
 
@@ -194,7 +187,6 @@ BOOL ringbuffer_write(RingBuffer* rb, const BYTE* ptr, size_t sz)
                memcpy(rb->buffer, ptr, remaining);
 
        rb->writePtr = (rb->writePtr + sz) % rb->size;
-
        rb->freeSize -= sz;
        return TRUE;
 }
@@ -233,16 +225,15 @@ BYTE* ringbuffer_ensure_linear_write(RingBuffer* rb, size_t sz)
 BOOL ringbuffer_commit_written_bytes(RingBuffer* rb, size_t sz)
 {
        DEBUG_RINGBUFFER("ringbuffer_commit_written_bytes(%p): sz: %d", rb, sz);
-       
+
        if (sz < 1)
                return TRUE;
-       
+
        if (rb->writePtr + sz > rb->size)
                return FALSE;
-       
+
        rb->writePtr = (rb->writePtr + sz) % rb->size;
        rb->freeSize -= sz;
-       
        return TRUE;
 }
 
@@ -252,12 +243,11 @@ int ringbuffer_peek(const RingBuffer* rb, DataChunk chunks[2], size_t sz)
        size_t toRead;
        int chunkIndex = 0;
        int status = 0;
-       
        DEBUG_RINGBUFFER("ringbuffer_peek(%p): sz: %d", rb, sz);
 
        if (sz < 1)
                return 0;
-       
+
        if ((rb->size - rb->freeSize) < sz)
                remaining = rb->size - rb->freeSize;
 
@@ -281,23 +271,23 @@ int ringbuffer_peek(const RingBuffer* rb, DataChunk chunks[2], size_t sz)
                chunks[chunkIndex].size = remaining;
                status++;
        }
-       
+
        return status;
 }
 
 void ringbuffer_commit_read_bytes(RingBuffer* rb, size_t sz)
 {
        DEBUG_RINGBUFFER("ringbuffer_commit_read_bytes(%p): sz: %d", rb, sz);
-       
+
        if (sz < 1)
                return;
-       
-       assert(rb->size - rb->freeSize >= sz);
 
+       assert(rb->size - rb->freeSize >= sz);
        rb->readPtr = (rb->readPtr + sz) % rb->size;
        rb->freeSize += sz;
 
        /* when we reach a reasonable free size, we can go back to the original size */
-       if ((rb->size != rb->initialSize) && (ringbuffer_used(rb) < rb->initialSize / 2))
+       if ((rb->size != rb->initialSize)
+           && (ringbuffer_used(rb) < rb->initialSize / 2))
                ringbuffer_realloc(rb, rb->initialSize);
 }
index f8e1480..c8ad36e 100644 (file)
@@ -104,109 +104,80 @@ typedef struct _wLog wLog;
 #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);
+WINPR_API BOOL WLog_PrintMessage(wLog* log, DWORD type, DWORD level, DWORD line,
+                                 const char* file, const char* function, ...);
+WINPR_API BOOL WLog_PrintMessageVA(wLog* log, DWORD type, DWORD level,
+                                   DWORD line,
+                                   const char* file, const char* function, va_list args);
 
-#define WLog_Print(_log, _log_level, _fmt, ...) \
+#define WLog_Print(_log, _log_level, ...) \
        do { \
                if (_log && _log_level >= WLog_GetLogLevel(_log)) { \
-                       wLogMessage _log_message; \
-                       memset(&_log_message, 0, sizeof(_log_message)); \
-                       _log_message.Type = WLOG_MESSAGE_TEXT; \
-                       _log_message.Level = _log_level; \
-                       _log_message.FormatString = _fmt; \
-                       _log_message.LineNumber = __LINE__; \
-                       _log_message.FileName = __FILE__; \
-                       _log_message.FunctionName = __FUNCTION__; \
-                       WLog_PrintMessage(_log, &(_log_message), ## __VA_ARGS__ ); \
+                       WLog_PrintMessage(_log, WLOG_MESSAGE_TEXT, _log_level, \
+                                         __LINE__, __FILE__, __FUNCTION__, __VA_ARGS__ ); \
                } \
        } while (0)
 
-#define WLog_PrintVA(_log, _log_level, _fmt, _args) \
+#define WLog_PrintVA(_log, _log_level, _args) \
        do { \
                if (_log && _log_level >= WLog_GetLogLevel(_log)) { \
-                       wLogMessage _log_message; \
-                       memset(&_log_message, 0, sizeof(_log_message)); \
-                       _log_message.Type = WLOG_MESSAGE_TEXT; \
-                       _log_message.Level = _log_level; \
-                       _log_message.FormatString = _fmt; \
-                       _log_message.LineNumber = __LINE__; \
-                       _log_message.FileName = __FILE__; \
-                       _log_message.FunctionName = __FUNCTION__; \
-                       WLog_PrintMessageVA(_log, &(_log_message), _args); \
+                       WLog_PrintMessageVA(_log, WLOG_MESSAGE_TEXT, _log_level, \
+                                           __LINE__, __FILE__, __FUNCTION__, _args ); \
                } \
        } while (0)
 
 #define WLog_Data(_log, _log_level, ...) \
        do { \
                if (_log && _log_level >= WLog_GetLogLevel(_log)) { \
-                       wLogMessage _log_message; \
-                       memset(&_log_message, 0, sizeof(_log_message)); \
-                       _log_message.Type = WLOG_MESSAGE_DATA; \
-                       _log_message.Level = _log_level; \
-                       _log_message.FormatString = NULL; \
-                       _log_message.LineNumber = __LINE__; \
-                       _log_message.FileName = __FILE__; \
-                       _log_message.FunctionName = __FUNCTION__; \
-                       WLog_PrintMessage(_log, &(_log_message), ## __VA_ARGS__ ); \
+                       WLog_PrintMessage(_log, WLOG_MESSAGE_DATA, _log_level, \
+                                         __LINE__, __FILE__, __FUNCTION__, __VA_ARGS__ ); \
                } \
        } while (0)
 
 #define WLog_Image(_log, _log_level, ...) \
        do { \
                if (_log && _log_level >= WLog_GetLogLevel(_log)) { \
-                       wLogMessage _log_message; \
-                       memset(&_log_message, 0, sizeof(_log_message)); \
-                       _log_message.Type = WLOG_MESSAGE_IMAGE; \
-                       _log_message.Level = _log_level; \
-                       _log_message.FormatString = NULL; \
-                       _log_message.LineNumber = __LINE__; \
-                       _log_message.FileName = __FILE__; \
-                       _log_message.FunctionName = __FUNCTION__; \
-                       WLog_PrintMessage(_log, &(_log_message), ## __VA_ARGS__ ); \
+                       WLog_PrintMessage(_log, WLOG_MESSAGE_DATA, _log_level, \
+                                         __LINE__, __FILE__, __FUNCTION__, __VA_ARGS__ ); \
                } \
        } while (0)
 
 #define WLog_Packet(_log, _log_level, ...) \
        do { \
                if (_log && _log_level >= WLog_GetLogLevel(_log)) { \
-                       wLogMessage _log_message; \
-                       memset(&_log_message, 0, sizeof(_log_message)); \
-                       _log_message.Type = WLOG_MESSAGE_PACKET; \
-                       _log_message.Level = _log_level; \
-                       _log_message.FormatString = NULL; \
-                       _log_message.LineNumber = __LINE__; \
-                       _log_message.FileName = __FILE__; \
-                       _log_message.FunctionName = __FUNCTION__; \
-                       WLog_PrintMessage(_log, &(_log_message), ## __VA_ARGS__ ); \
+                       WLog_PrintMessage(_log, WLOG_MESSAGE_PACKET, _log_level, \
+                                         __LINE__, __FILE__, __FUNCTION__, __VA_ARGS__ ); \
                } \
        } while (0)
 
-#define WLog_IsLevelActive(_log, _log_level) \
-       (_log ? _log_level >= WLog_GetLogLevel(_log) : FALSE)
-
-#define WLog_LVL(tag, lvl, fmt, ...) WLog_Print(WLog_Get(tag), lvl, fmt, ## __VA_ARGS__)
-#define WLog_VRB(tag, fmt, ...) WLog_Print(WLog_Get(tag), WLOG_TRACE, fmt, ## __VA_ARGS__)
-#define WLog_DBG(tag, fmt, ...) WLog_Print(WLog_Get(tag), WLOG_DEBUG, fmt, ## __VA_ARGS__)
-#define WLog_INFO(tag, fmt, ...) WLog_Print(WLog_Get(tag), WLOG_INFO, fmt, ## __VA_ARGS__)
-#define WLog_WARN(tag, fmt, ...) WLog_Print(WLog_Get(tag), WLOG_WARN, fmt, ## __VA_ARGS__)
-#define WLog_ERR(tag, fmt, ...) WLog_Print(WLog_Get(tag), WLOG_ERROR, fmt, ## __VA_ARGS__)
-#define WLog_FATAL(tag, fmt, ...) WLog_Print(WLog_Get(tag), WLOG_FATAL, fmt, ## __VA_ARGS__)
+#define WLog_LVL(tag, lvl, ...) WLog_Print(WLog_Get(tag), lvl, __VA_ARGS__)
+#define WLog_VRB(tag, ...) WLog_Print(WLog_Get(tag), WLOG_TRACE, __VA_ARGS__)
+#define WLog_DBG(tag, ...) WLog_Print(WLog_Get(tag), WLOG_DEBUG, __VA_ARGS__)
+#define WLog_INFO(tag, ...) WLog_Print(WLog_Get(tag), WLOG_INFO, __VA_ARGS__)
+#define WLog_WARN(tag, ...) WLog_Print(WLog_Get(tag), WLOG_WARN, __VA_ARGS__)
+#define WLog_ERR(tag, ...) WLog_Print(WLog_Get(tag), WLOG_ERROR, __VA_ARGS__)
+#define WLog_FATAL(tag, ...) WLog_Print(WLog_Get(tag), WLOG_FATAL, __VA_ARGS__)
 
 WINPR_API DWORD WLog_GetLogLevel(wLog* log);
 WINPR_API BOOL WLog_SetLogLevel(wLog* log, DWORD logLevel);
 WINPR_API BOOL WLog_SetStringLogLevel(wLog* log, LPCSTR level);
 WINPR_API BOOL WLog_AddStringLogFilters(LPCSTR filter);
 
+static INLINE BOOL WLog_IsLevelActive(wLog* _log, DWORD _log_level)
+{
+       return _log ? _log_level >= WLog_GetLogLevel(_log) : FALSE;
+}
 
 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_ConfigureAppender(wLogAppender *appender, const char *setting, void *value);
+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);
+WINPR_API BOOL WLog_Layout_SetPrefixFormat(wLog* log, wLogLayout* layout,
+        const char* format);
 
 WINPR_API wLog* WLog_GetRoot(void);
 WINPR_API wLog* WLog_Get(LPCSTR name);
@@ -214,12 +185,13 @@ 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);
+typedef BOOL (*wLogCallbackMessage_t)(const wLogMessagemsg);
+typedef BOOL (*wLogCallbackData_t)(const wLogMessagemsg);
+typedef BOOL (*wLogCallbackImage_t)(const wLogMessagemsg);
+typedef BOOL (*wLogCallbackPackage_t)(const wLogMessagemsg);
 
-struct _wLogCallbacks {
+struct _wLogCallbacks
+{
        wLogCallbackData_t data;
        wLogCallbackImage_t  image;
        wLogCallbackMessage_t message;
index b107b31..8a469a5 100644 (file)
@@ -54,7 +54,7 @@
 #include "comm.h"
 
 
-static wLog *_Log = NULL;
+static wLog_Log = NULL;
 
 struct comm_device
 {
@@ -68,7 +68,7 @@ typedef struct comm_device COMM_DEVICE;
 /* FIXME: get a clever data structure, see also io.h functions */
 /* _CommDevices is a NULL-terminated array with a maximun of COMM_DEVICE_MAX COMM_DEVICE */
 #define COMM_DEVICE_MAX        128
-static COMM_DEVICE **_CommDevices = NULL;
+static COMM_DEVICE** _CommDevices = NULL;
 static CRITICAL_SECTION _CommDevicesLock;
 
 static HANDLE_CREATOR _CommHandleCreator;
@@ -77,7 +77,7 @@ static pthread_once_t _CommInitialized = PTHREAD_ONCE_INIT;
 
 static int CommGetFd(HANDLE handle)
 {
-       WINPR_COMM *comm = (WINPR_COMM *)handle;
+       WINPR_COMM* comm = (WINPR_COMM*)handle;
 
        if (!CommIsHandled(handle))
                return -1;
@@ -85,7 +85,7 @@ static int CommGetFd(HANDLE handle)
        return comm->fd;
 }
 
-HANDLE_CREATOR *GetCommHandleCreator(void)
+HANDLE_CREATORGetCommHandleCreator(void)
 {
        _CommHandleCreator.IsHandled = IsCommDevice;
        _CommHandleCreator.CreateFileA = CommCreateFileA;
@@ -95,11 +95,10 @@ HANDLE_CREATOR *GetCommHandleCreator(void)
 static void _CommInit(void)
 {
        /* NB: error management to be done outside of this function */
-
        assert(_Log == NULL);
        assert(_CommDevices == NULL);
+       _CommDevices = (COMM_DEVICE**)calloc(COMM_DEVICE_MAX + 1, sizeof(COMM_DEVICE*));
 
-       _CommDevices = (COMM_DEVICE**)calloc(COMM_DEVICE_MAX+1, sizeof(COMM_DEVICE*));
        if (!_CommDevices)
                return;
 
@@ -130,14 +129,14 @@ static BOOL CommInitialized()
 }
 
 
-void CommLog_Print(int level, char *fmt, ...)
+void CommLog_Print(int level, ...)
 {
        if (!CommInitialized())
                return;
 
        va_list ap;
-       va_start(ap, fmt);
-       WLog_PrintVA(_Log, level, fmt, ap);
+       va_start(ap, level);
+       WLog_PrintVA(_Log, level, ap);
        va_end(ap);
 }
 
@@ -148,7 +147,6 @@ BOOL BuildCommDCBA(LPCSTR lpDef, LPDCB lpDCB)
                return FALSE;
 
        /* TODO: not implemented */
-
        CommLog_Print(WLOG_ERROR, "%s: Not implemented", __FUNCTION__);
        SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
        return FALSE;
@@ -160,31 +158,30 @@ BOOL BuildCommDCBW(LPCWSTR lpDef, LPDCB lpDCB)
                return FALSE;
 
        /* TODO: not implemented */
-
        CommLog_Print(WLOG_ERROR, "%s: Not implemented", __FUNCTION__);
        SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
        return FALSE;
 }
 
-BOOL BuildCommDCBAndTimeoutsA(LPCSTR lpDef, LPDCB lpDCB, LPCOMMTIMEOUTS lpCommTimeouts)
+BOOL BuildCommDCBAndTimeoutsA(LPCSTR lpDef, LPDCB lpDCB,
+                              LPCOMMTIMEOUTS lpCommTimeouts)
 {
        if (!CommInitialized())
                return FALSE;
 
        /* TODO: not implemented */
-
        CommLog_Print(WLOG_ERROR, "%s: Not implemented", __FUNCTION__);
        SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
        return FALSE;
 }
 
-BOOL BuildCommDCBAndTimeoutsW(LPCWSTR lpDef, LPDCB lpDCB, LPCOMMTIMEOUTS lpCommTimeouts)
+BOOL BuildCommDCBAndTimeoutsW(LPCWSTR lpDef, LPDCB lpDCB,
+                              LPCOMMTIMEOUTS lpCommTimeouts)
 {
        if (!CommInitialized())
                return FALSE;
 
        /* TODO: not implemented */
-
        CommLog_Print(WLOG_ERROR, "%s: Not implemented", __FUNCTION__);
        SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
        return FALSE;
@@ -196,7 +193,6 @@ BOOL CommConfigDialogA(LPCSTR lpszName, HWND hWnd, LPCOMMCONFIG lpCC)
                return FALSE;
 
        /* TODO: not implemented */
-
        CommLog_Print(WLOG_ERROR, "%s: Not implemented", __FUNCTION__);
        SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
        return FALSE;
@@ -208,7 +204,6 @@ BOOL CommConfigDialogW(LPCWSTR lpszName, HWND hWnd, LPCOMMCONFIG lpCC)
                return FALSE;
 
        /* TODO: not implemented */
-
        CommLog_Print(WLOG_ERROR, "%s: Not implemented", __FUNCTION__);
        SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
        return FALSE;
@@ -312,13 +307,14 @@ BOOL GetCommProperties(HANDLE hFile, LPCOMMPROP lpCommProp)
        if (!CommInitialized())
                return FALSE;
 
-       if (!pComm || pComm->Type != HANDLE_TYPE_COMM || !pComm->fd )
+       if (!pComm || pComm->Type != HANDLE_TYPE_COMM || !pComm->fd)
        {
                SetLastError(ERROR_INVALID_HANDLE);
                return FALSE;
        }
 
-       if (!CommDeviceIoControl(pComm, IOCTL_SERIAL_GET_PROPERTIES, NULL, 0, lpCommProp, sizeof(COMMPROP), &bytesReturned, NULL))
+       if (!CommDeviceIoControl(pComm, IOCTL_SERIAL_GET_PROPERTIES, NULL, 0,
+                                lpCommProp, sizeof(COMMPROP), &bytesReturned, NULL))
        {
                CommLog_Print(WLOG_WARN, "GetCommProperties failure.");
                return FALSE;
@@ -340,7 +336,7 @@ BOOL GetCommProperties(HANDLE hFile, LPCOMMPROP lpCommProp)
  */
 BOOL GetCommState(HANDLE hFile, LPDCB lpDCB)
 {
-       DCB *lpLocalDcb;
+       DCBlpLocalDcb;
        struct termios currentState;
        WINPR_COMM* pComm = (WINPR_COMM*) hFile;
        DWORD bytesReturned;
@@ -348,7 +344,7 @@ BOOL GetCommState(HANDLE hFile, LPDCB lpDCB)
        if (!CommInitialized())
                return FALSE;
 
-       if (!pComm || pComm->Type != HANDLE_TYPE_COMM || !pComm->fd )
+       if (!pComm || pComm->Type != HANDLE_TYPE_COMM || !pComm->fd)
        {
                SetLastError(ERROR_INVALID_HANDLE);
                return FALSE;
@@ -373,6 +369,7 @@ BOOL GetCommState(HANDLE hFile, LPDCB lpDCB)
        }
 
        lpLocalDcb = (DCB*)calloc(1, lpDCB->DCBlength);
+
        if (lpLocalDcb == NULL)
        {
                SetLastError(ERROR_OUTOFMEMORY);
@@ -380,35 +377,40 @@ BOOL GetCommState(HANDLE hFile, LPDCB lpDCB)
        }
 
        /* error_handle */
-
        lpLocalDcb->DCBlength = lpDCB->DCBlength;
-
        SERIAL_BAUD_RATE baudRate;
-       if (!CommDeviceIoControl(pComm, IOCTL_SERIAL_GET_BAUD_RATE, NULL, 0, &baudRate, sizeof(SERIAL_BAUD_RATE), &bytesReturned, NULL))
+
+       if (!CommDeviceIoControl(pComm, IOCTL_SERIAL_GET_BAUD_RATE, NULL, 0, &baudRate,
+                                sizeof(SERIAL_BAUD_RATE), &bytesReturned, NULL))
        {
                CommLog_Print(WLOG_WARN, "GetCommState failure: could not get the baud rate.");
                goto error_handle;
        }
-       lpLocalDcb->BaudRate = baudRate.BaudRate;
 
+       lpLocalDcb->BaudRate = baudRate.BaudRate;
        lpLocalDcb->fBinary = (currentState.c_cflag & ICANON) == 0;
+
        if (!lpLocalDcb->fBinary)
        {
-               CommLog_Print(WLOG_WARN, "Unexpected nonbinary mode, consider to unset the ICANON flag.");
+               CommLog_Print(WLOG_WARN,
+                             "Unexpected nonbinary mode, consider to unset the ICANON flag.");
        }
 
-       lpLocalDcb->fParity =  (currentState.c_iflag & INPCK) != 0;
-
+       lpLocalDcb->fParity = (currentState.c_iflag & INPCK) != 0;
        SERIAL_HANDFLOW handflow;
-       if (!CommDeviceIoControl(pComm, IOCTL_SERIAL_GET_HANDFLOW, NULL, 0, &handflow, sizeof(SERIAL_HANDFLOW), &bytesReturned, NULL))
+
+       if (!CommDeviceIoControl(pComm, IOCTL_SERIAL_GET_HANDFLOW, NULL, 0, &handflow,
+                                sizeof(SERIAL_HANDFLOW), &bytesReturned, NULL))
        {
-               CommLog_Print(WLOG_WARN, "GetCommState failure: could not get the handflow settings.");
+               CommLog_Print(WLOG_WARN,
+                             "GetCommState failure: could not get the handflow settings.");
                goto error_handle;
        }
 
-       lpLocalDcb->fOutxCtsFlow = (handflow.ControlHandShake & SERIAL_CTS_HANDSHAKE) != 0;
-
-       lpLocalDcb->fOutxDsrFlow = (handflow.ControlHandShake & SERIAL_DSR_HANDSHAKE) != 0;
+       lpLocalDcb->fOutxCtsFlow = (handflow.ControlHandShake & SERIAL_CTS_HANDSHAKE) !=
+                                  0;
+       lpLocalDcb->fOutxDsrFlow = (handflow.ControlHandShake & SERIAL_DSR_HANDSHAKE) !=
+                                  0;
 
        if (handflow.ControlHandShake & SERIAL_DTR_HANDSHAKE)
        {
@@ -423,16 +425,13 @@ BOOL GetCommState(HANDLE hFile, LPDCB lpDCB)
                lpLocalDcb->fDtrControl = DTR_CONTROL_DISABLE;
        }
 
-       lpLocalDcb->fDsrSensitivity = (handflow.ControlHandShake & SERIAL_DSR_SENSITIVITY) != 0;
-
-       lpLocalDcb->fTXContinueOnXoff = (handflow.FlowReplace & SERIAL_XOFF_CONTINUE) != 0;
-
+       lpLocalDcb->fDsrSensitivity = (handflow.ControlHandShake &
+                                      SERIAL_DSR_SENSITIVITY) != 0;
+       lpLocalDcb->fTXContinueOnXoff = (handflow.FlowReplace & SERIAL_XOFF_CONTINUE) !=
+                                       0;
        lpLocalDcb->fOutX = (handflow.FlowReplace & SERIAL_AUTO_TRANSMIT) != 0;
-
        lpLocalDcb->fInX = (handflow.FlowReplace & SERIAL_AUTO_RECEIVE) != 0;
-
        lpLocalDcb->fErrorChar = (handflow.FlowReplace & SERIAL_ERROR_CHAR) != 0;
-
        lpLocalDcb->fNull = (handflow.FlowReplace & SERIAL_NULL_STRIPPING) != 0;
 
        if (handflow.FlowReplace & SERIAL_RTS_HANDSHAKE)
@@ -449,57 +448,45 @@ BOOL GetCommState(HANDLE hFile, LPDCB lpDCB)
        }
 
        // FIXME: how to get the RTS_CONTROL_TOGGLE state? Does it match the UART 16750's Autoflow Control Enabled bit in its Modem Control Register (MCR)
-
-
-       lpLocalDcb->fAbortOnError = (handflow.ControlHandShake & SERIAL_ERROR_ABORT) != 0;
-
+       lpLocalDcb->fAbortOnError = (handflow.ControlHandShake & SERIAL_ERROR_ABORT) !=
+                                   0;
        /* lpLocalDcb->fDummy2 not used */
-
        lpLocalDcb->wReserved = 0; /* must be zero */
-
        lpLocalDcb->XonLim = handflow.XonLimit;
-
        lpLocalDcb->XoffLim = handflow.XoffLimit;
-
        SERIAL_LINE_CONTROL lineControl;
-       if (!CommDeviceIoControl(pComm, IOCTL_SERIAL_GET_LINE_CONTROL, NULL, 0, &lineControl, sizeof(SERIAL_LINE_CONTROL), &bytesReturned, NULL))
+
+       if (!CommDeviceIoControl(pComm, IOCTL_SERIAL_GET_LINE_CONTROL, NULL, 0,
+                                &lineControl, sizeof(SERIAL_LINE_CONTROL), &bytesReturned, NULL))
        {
-               CommLog_Print(WLOG_WARN, "GetCommState failure: could not get the control settings.");
+               CommLog_Print(WLOG_WARN,
+                             "GetCommState failure: could not get the control settings.");
                goto error_handle;
        }
 
        lpLocalDcb->ByteSize = lineControl.WordLength;
-
        lpLocalDcb->Parity = lineControl.Parity;
-
        lpLocalDcb->StopBits = lineControl.StopBits;
-
-
        SERIAL_CHARS serialChars;
-       if (!CommDeviceIoControl(pComm, IOCTL_SERIAL_GET_CHARS, NULL, 0, &serialChars, sizeof(SERIAL_CHARS), &bytesReturned, NULL))
+
+       if (!CommDeviceIoControl(pComm, IOCTL_SERIAL_GET_CHARS, NULL, 0, &serialChars,
+                                sizeof(SERIAL_CHARS), &bytesReturned, NULL))
        {
-               CommLog_Print(WLOG_WARN, "GetCommState failure: could not get the serial chars.");
+               CommLog_Print(WLOG_WARN,
+                             "GetCommState failure: could not get the serial chars.");
                goto error_handle;
        }
 
        lpLocalDcb->XonChar = serialChars.XonChar;
-
        lpLocalDcb->XoffChar = serialChars.XoffChar;
-
        lpLocalDcb->ErrorChar = serialChars.ErrorChar;
-
        lpLocalDcb->EofChar = serialChars.EofChar;
-
        lpLocalDcb->EvtChar = serialChars.EventChar;
-
-
        memcpy(lpDCB, lpLocalDcb, lpDCB->DCBlength);
        free(lpLocalDcb);
        return TRUE;
-
 error_handle:
        free(lpLocalDcb);
-
        return FALSE;
 }
 
@@ -526,7 +513,7 @@ BOOL SetCommState(HANDLE hFile, LPDCB lpDCB)
        if (!CommInitialized())
                return FALSE;
 
-       if (!pComm || pComm->Type != HANDLE_TYPE_COMM || !pComm->fd )
+       if (!pComm || pComm->Type != HANDLE_TYPE_COMM || !pComm->fd)
        {
                SetLastError(ERROR_INVALID_HANDLE);
                return FALSE;
@@ -540,31 +527,39 @@ BOOL SetCommState(HANDLE hFile, LPDCB lpDCB)
 
        /* NB: did the choice to call ioctls first when available and
           then to setup upcomingTermios. Don't mix both stages. */
-
        /** ioctl calls stage **/
-
        SERIAL_BAUD_RATE baudRate;
        baudRate.BaudRate = lpDCB->BaudRate;
-       if (!CommDeviceIoControl(pComm, IOCTL_SERIAL_SET_BAUD_RATE, &baudRate, sizeof(SERIAL_BAUD_RATE), NULL, 0, &bytesReturned, NULL))
+
+       if (!CommDeviceIoControl(pComm, IOCTL_SERIAL_SET_BAUD_RATE, &baudRate,
+                                sizeof(SERIAL_BAUD_RATE), NULL, 0, &bytesReturned, NULL))
        {
                CommLog_Print(WLOG_WARN, "SetCommState failure: could not set the baud rate.");
                return FALSE;
        }
 
        SERIAL_CHARS serialChars;
-       if (!CommDeviceIoControl(pComm, IOCTL_SERIAL_GET_CHARS, NULL, 0, &serialChars, sizeof(SERIAL_CHARS), &bytesReturned, NULL)) /* as of today, required for BreakChar */
+
+       if (!CommDeviceIoControl(pComm, IOCTL_SERIAL_GET_CHARS, NULL, 0, &serialChars,
+                                sizeof(SERIAL_CHARS), &bytesReturned,
+                                NULL)) /* as of today, required for BreakChar */
        {
-               CommLog_Print(WLOG_WARN, "SetCommState failure: could not get the initial serial chars.");
+               CommLog_Print(WLOG_WARN,
+                             "SetCommState failure: could not get the initial serial chars.");
                return FALSE;
        }
+
        serialChars.XonChar = lpDCB->XonChar;
        serialChars.XoffChar = lpDCB->XoffChar;
        serialChars.ErrorChar = lpDCB->ErrorChar;
        serialChars.EofChar = lpDCB->EofChar;
        serialChars.EventChar = lpDCB->EvtChar;
-       if (!CommDeviceIoControl(pComm, IOCTL_SERIAL_SET_CHARS, &serialChars, sizeof(SERIAL_CHARS), NULL, 0, &bytesReturned, NULL))
+
+       if (!CommDeviceIoControl(pComm, IOCTL_SERIAL_SET_CHARS, &serialChars,
+                                sizeof(SERIAL_CHARS), NULL, 0, &bytesReturned, NULL))
        {
-               CommLog_Print(WLOG_WARN, "SetCommState failure: could not set the serial chars.");
+               CommLog_Print(WLOG_WARN,
+                             "SetCommState failure: could not set the serial chars.");
                return FALSE;
        }
 
@@ -572,13 +567,15 @@ BOOL SetCommState(HANDLE hFile, LPDCB lpDCB)
        lineControl.StopBits = lpDCB->StopBits;
        lineControl.Parity = lpDCB->Parity;
        lineControl.WordLength = lpDCB->ByteSize;
-       if (!CommDeviceIoControl(pComm, IOCTL_SERIAL_SET_LINE_CONTROL, &lineControl, sizeof(SERIAL_LINE_CONTROL), NULL, 0, &bytesReturned, NULL))
+
+       if (!CommDeviceIoControl(pComm, IOCTL_SERIAL_SET_LINE_CONTROL, &lineControl,
+                                sizeof(SERIAL_LINE_CONTROL), NULL, 0, &bytesReturned, NULL))
        {
-               CommLog_Print(WLOG_WARN, "SetCommState failure: could not set the control settings.");
+               CommLog_Print(WLOG_WARN,
+                             "SetCommState failure: could not set the control settings.");
                return FALSE;
        }
 
-
        SERIAL_HANDFLOW handflow;
        ZeroMemory(&handflow, sizeof(SERIAL_HANDFLOW));
 
@@ -587,7 +584,6 @@ BOOL SetCommState(HANDLE hFile, LPDCB lpDCB)
                handflow.ControlHandShake |= SERIAL_CTS_HANDSHAKE;
        }
 
-
        if (lpDCB->fOutxDsrFlow)
        {
                handflow.ControlHandShake |= SERIAL_DSR_HANDSHAKE;
@@ -608,7 +604,8 @@ BOOL SetCommState(HANDLE hFile, LPDCB lpDCB)
                        break;
 
                default:
-                       CommLog_Print(WLOG_WARN, "Unexpected fDtrControl value: %d\n", lpDCB->fDtrControl);
+                       CommLog_Print(WLOG_WARN, "Unexpected fDtrControl value: %d\n",
+                                     lpDCB->fDtrControl);
                        return FALSE;
        }
 
@@ -662,7 +659,8 @@ BOOL SetCommState(HANDLE hFile, LPDCB lpDCB)
                        break;
 
                default:
-                       CommLog_Print(WLOG_WARN, "Unexpected fRtsControl value: %d\n", lpDCB->fRtsControl);
+                       CommLog_Print(WLOG_WARN, "Unexpected fRtsControl value: %d\n",
+                                     lpDCB->fRtsControl);
                        return FALSE;
        }
 
@@ -672,25 +670,24 @@ BOOL SetCommState(HANDLE hFile, LPDCB lpDCB)
        }
 
        /* lpDCB->fDummy2 not used */
-
        /* lpLocalDcb->wReserved  ignored */
-
        handflow.XonLimit = lpDCB->XonLim;
-
        handflow.XoffLimit = lpDCB->XoffLim;
 
-       if (!CommDeviceIoControl(pComm, IOCTL_SERIAL_SET_HANDFLOW, &handflow, sizeof(SERIAL_HANDFLOW), NULL, 0, &bytesReturned, NULL))
+       if (!CommDeviceIoControl(pComm, IOCTL_SERIAL_SET_HANDFLOW, &handflow,
+                                sizeof(SERIAL_HANDFLOW), NULL, 0, &bytesReturned, NULL))
        {
-               CommLog_Print(WLOG_WARN, "SetCommState failure: could not set the handflow settings.");
+               CommLog_Print(WLOG_WARN,
+                             "SetCommState failure: could not set the handflow settings.");
                return FALSE;
        }
 
-
        /** upcomingTermios stage **/
-
-
        ZeroMemory(&upcomingTermios, sizeof(struct termios));
-       if (tcgetattr(pComm->fd, &upcomingTermios) < 0) /* NB: preserves current settings not directly handled by the Communication Functions */
+
+       if (tcgetattr(pComm->fd,
+                     &upcomingTermios) <
+           0) /* NB: preserves current settings not directly handled by the Communication Functions */
        {
                SetLastError(ERROR_IO_DEVICE);
                return FALSE;
@@ -703,7 +700,8 @@ BOOL SetCommState(HANDLE hFile, LPDCB lpDCB)
        else
        {
                upcomingTermios.c_lflag |= ICANON;
-               CommLog_Print(WLOG_WARN, "Unexpected nonbinary mode, consider to unset the ICANON flag.");
+               CommLog_Print(WLOG_WARN,
+                             "Unexpected nonbinary mode, consider to unset the ICANON flag.");
        }
 
        if (lpDCB->fParity)
@@ -715,7 +713,6 @@ BOOL SetCommState(HANDLE hFile, LPDCB lpDCB)
                upcomingTermios.c_iflag &= ~INPCK;
        }
 
-
        /* http://msdn.microsoft.com/en-us/library/windows/desktop/aa363423%28v=vs.85%29.aspx
         *
         * The SetCommState function reconfigures the communications
@@ -733,7 +730,6 @@ BOOL SetCommState(HANDLE hFile, LPDCB lpDCB)
                return FALSE;
        }
 
-
        return TRUE;
 }
 
@@ -749,7 +745,7 @@ BOOL GetCommTimeouts(HANDLE hFile, LPCOMMTIMEOUTS lpCommTimeouts)
        if (!CommInitialized())
                return FALSE;
 
-       if (!pComm || pComm->Type != HANDLE_TYPE_COMM || !pComm->fd )
+       if (!pComm || pComm->Type != HANDLE_TYPE_COMM || !pComm->fd)
        {
                SetLastError(ERROR_INVALID_HANDLE);
                return FALSE;
@@ -757,7 +753,8 @@ BOOL GetCommTimeouts(HANDLE hFile, LPCOMMTIMEOUTS lpCommTimeouts)
 
        /* as of today, SERIAL_TIMEOUTS and COMMTIMEOUTS structures are identical */
 
-       if (!CommDeviceIoControl(pComm, IOCTL_SERIAL_GET_TIMEOUTS, NULL, 0, lpCommTimeouts, sizeof(COMMTIMEOUTS), &bytesReturned, NULL))
+       if (!CommDeviceIoControl(pComm, IOCTL_SERIAL_GET_TIMEOUTS, NULL, 0,
+                                lpCommTimeouts, sizeof(COMMTIMEOUTS), &bytesReturned, NULL))
        {
                CommLog_Print(WLOG_WARN, "GetCommTimeouts failure.");
                return FALSE;
@@ -779,7 +776,7 @@ BOOL SetCommTimeouts(HANDLE hFile, LPCOMMTIMEOUTS lpCommTimeouts)
        if (!CommInitialized())
                return FALSE;
 
-       if (!pComm || pComm->Type != HANDLE_TYPE_COMM || !pComm->fd )
+       if (!pComm || pComm->Type != HANDLE_TYPE_COMM || !pComm->fd)
        {
                SetLastError(ERROR_INVALID_HANDLE);
                return FALSE;
@@ -787,7 +784,8 @@ BOOL SetCommTimeouts(HANDLE hFile, LPCOMMTIMEOUTS lpCommTimeouts)
 
        /* as of today, SERIAL_TIMEOUTS and COMMTIMEOUTS structures are identical */
 
-       if (!CommDeviceIoControl(pComm, IOCTL_SERIAL_SET_TIMEOUTS, lpCommTimeouts, sizeof(COMMTIMEOUTS), NULL, 0, &bytesReturned, NULL))
+       if (!CommDeviceIoControl(pComm, IOCTL_SERIAL_SET_TIMEOUTS, lpCommTimeouts,
+                                sizeof(COMMTIMEOUTS), NULL, 0, &bytesReturned, NULL))
        {
                CommLog_Print(WLOG_WARN, "SetCommTimeouts failure.");
                return FALSE;
@@ -802,19 +800,18 @@ BOOL GetDefaultCommConfigA(LPCSTR lpszName, LPCOMMCONFIG lpCC, LPDWORD lpdwSize)
                return FALSE;
 
        /* TODO: not implemented */
-
        CommLog_Print(WLOG_ERROR, "%s: Not implemented", __FUNCTION__);
        SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
        return FALSE;
 }
 
-BOOL GetDefaultCommConfigW(LPCWSTR lpszName, LPCOMMCONFIG lpCC, LPDWORD lpdwSize)
+BOOL GetDefaultCommConfigW(LPCWSTR lpszName, LPCOMMCONFIG lpCC,
+                           LPDWORD lpdwSize)
 {
        if (!CommInitialized())
                return FALSE;
 
        /* TODO: not implemented */
-
        CommLog_Print(WLOG_ERROR, "%s: Not implemented", __FUNCTION__);
        SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
        return FALSE;
@@ -826,7 +823,6 @@ BOOL SetDefaultCommConfigA(LPCSTR lpszName, LPCOMMCONFIG lpCC, DWORD dwSize)
                return FALSE;
 
        /* TODO: not implemented */
-
        CommLog_Print(WLOG_ERROR, "%s: Not implemented", __FUNCTION__);
        SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
        return FALSE;
@@ -838,7 +834,6 @@ BOOL SetDefaultCommConfigW(LPCWSTR lpszName, LPCOMMCONFIG lpCC, DWORD dwSize)
                return FALSE;
 
        /* TODO: not implemented */
-
        CommLog_Print(WLOG_ERROR, "%s: Not implemented", __FUNCTION__);
        SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
        return FALSE;
@@ -904,13 +899,14 @@ BOOL PurgeComm(HANDLE hFile, DWORD dwFlags)
        if (!CommInitialized())
                return FALSE;
 
-       if (!pComm || pComm->Type != HANDLE_TYPE_COMM || !pComm->fd )
+       if (!pComm || pComm->Type != HANDLE_TYPE_COMM || !pComm->fd)
        {
                SetLastError(ERROR_INVALID_HANDLE);
                return FALSE;
        }
 
-       if (!CommDeviceIoControl(pComm, IOCTL_SERIAL_PURGE, &dwFlags, sizeof(DWORD), NULL, 0, &bytesReturned, NULL))
+       if (!CommDeviceIoControl(pComm, IOCTL_SERIAL_PURGE, &dwFlags, sizeof(DWORD),
+                                NULL, 0, &bytesReturned, NULL))
        {
                CommLog_Print(WLOG_WARN, "PurgeComm failure.");
                return FALSE;
@@ -929,7 +925,7 @@ BOOL SetupComm(HANDLE hFile, DWORD dwInQueue, DWORD dwOutQueue)
        if (!CommInitialized())
                return FALSE;
 
-       if (!pComm || pComm->Type != HANDLE_TYPE_COMM || !pComm->fd )
+       if (!pComm || pComm->Type != HANDLE_TYPE_COMM || !pComm->fd)
        {
                SetLastError(ERROR_INVALID_HANDLE);
                return FALSE;
@@ -938,7 +934,8 @@ BOOL SetupComm(HANDLE hFile, DWORD dwInQueue, DWORD dwOutQueue)
        queueSize.InSize = dwInQueue;
        queueSize.OutSize = dwOutQueue;
 
-       if (!CommDeviceIoControl(pComm, IOCTL_SERIAL_SET_QUEUE_SIZE, &queueSize, sizeof(SERIAL_QUEUE_SIZE), NULL, 0, &bytesReturned, NULL))
+       if (!CommDeviceIoControl(pComm, IOCTL_SERIAL_SET_QUEUE_SIZE, &queueSize,
+                                sizeof(SERIAL_QUEUE_SIZE), NULL, 0, &bytesReturned, NULL))
        {
                CommLog_Print(WLOG_WARN, "SetCommTimeouts failure.");
                return FALSE;
@@ -1009,9 +1006,10 @@ static BOOL _IsReservedCommDeviceName(LPCTSTR lpName)
                return FALSE;
 
        /* Serial ports, COM1-9 */
-       for (i=1; i<10; i++)
+       for (i = 1; i < 10; i++)
        {
                TCHAR genericName[5];
+
                if (_stprintf_s(genericName, 5, _T("COM%d"), i) < 0)
                {
                        return FALSE;
@@ -1022,9 +1020,10 @@ static BOOL _IsReservedCommDeviceName(LPCTSTR lpName)
        }
 
        /* Parallel ports, LPT1-9 */
-       for (i=1; i<10; i++)
+       for (i = 1; i < 10; i++)
        {
                TCHAR genericName[5];
+
                if (_stprintf_s(genericName, 5, _T("LPT%d"), i) < 0)
                {
                        return FALSE;
@@ -1035,7 +1034,6 @@ static BOOL _IsReservedCommDeviceName(LPCTSTR lpName)
        }
 
        /* FIXME: what about PRN ? */
-
        return FALSE;
 }
 
@@ -1049,7 +1047,8 @@ static BOOL _IsReservedCommDeviceName(LPCTSTR lpName)
  *   ERROR_OUTOFMEMORY was not possible to get mappings.
  *   ERROR_INVALID_DATA was not possible to add the device.
  */
-BOOL DefineCommDevice(/* DWORD dwFlags,*/ LPCTSTR lpDeviceName, LPCTSTR lpTargetPath)
+BOOL DefineCommDevice(/* DWORD dwFlags,*/ LPCTSTR lpDeviceName,
+        LPCTSTR lpTargetPath)
 {
        int i = 0;
        LPTSTR storedDeviceName = NULL;
@@ -1076,6 +1075,7 @@ BOOL DefineCommDevice(/* DWORD dwFlags,*/ LPCTSTR lpDeviceName, LPCTSTR lpTarget
        }
 
        storedDeviceName = _tcsdup(lpDeviceName);
+
        if (storedDeviceName == NULL)
        {
                SetLastError(ERROR_OUTOFMEMORY);
@@ -1083,13 +1083,14 @@ BOOL DefineCommDevice(/* DWORD dwFlags,*/ LPCTSTR lpDeviceName, LPCTSTR lpTarget
        }
 
        storedTargetPath = _tcsdup(lpTargetPath);
+
        if (storedTargetPath == NULL)
        {
                SetLastError(ERROR_OUTOFMEMORY);
                goto error_handle;
        }
 
-       for (i=0; i<COMM_DEVICE_MAX; i++)
+       for (i = 0; i < COMM_DEVICE_MAX; i++)
        {
                if (_CommDevices[i] != NULL)
                {
@@ -1100,7 +1101,6 @@ BOOL DefineCommDevice(/* DWORD dwFlags,*/ LPCTSTR lpDeviceName, LPCTSTR lpTarget
                                free(_CommDevices[i]->path);
                                _CommDevices[i]->name = storedDeviceName;
                                _CommDevices[i]->path = storedTargetPath;
-
                                break;
                        }
                }
@@ -1108,6 +1108,7 @@ BOOL DefineCommDevice(/* DWORD dwFlags,*/ LPCTSTR lpDeviceName, LPCTSTR lpTarget
                {
                        /* new emplacement */
                        _CommDevices[i] = (COMM_DEVICE*)calloc(1, sizeof(COMM_DEVICE));
+
                        if (_CommDevices[i] == NULL)
                        {
                                SetLastError(ERROR_OUTOFMEMORY);
@@ -1128,12 +1129,9 @@ BOOL DefineCommDevice(/* DWORD dwFlags,*/ LPCTSTR lpDeviceName, LPCTSTR lpTarget
 
        LeaveCriticalSection(&_CommDevicesLock);
        return TRUE;
-
-
 error_handle:
        free(storedDeviceName);
        free(storedTargetPath);
-
        LeaveCriticalSection(&_CommDevicesLock);
        return FALSE;
 }
@@ -1159,7 +1157,6 @@ DWORD QueryCommDevice(LPCTSTR lpDeviceName, LPTSTR lpTargetPath, DWORD ucchMax)
 {
        int i;
        LPTSTR storedTargetPath;
-
        SetLastError(ERROR_SUCCESS);
 
        if (!CommInitialized())
@@ -1178,9 +1175,9 @@ DWORD QueryCommDevice(LPCTSTR lpDeviceName, LPTSTR lpTargetPath, DWORD ucchMax)
        }
 
        EnterCriticalSection(&_CommDevicesLock);
-
        storedTargetPath = NULL;
-       for (i=0; i<COMM_DEVICE_MAX; i++)
+
+       for (i = 0; i < COMM_DEVICE_MAX; i++)
        {
                if (_CommDevices[i] != NULL)
                {
@@ -1212,7 +1209,6 @@ DWORD QueryCommDevice(LPCTSTR lpDeviceName, LPTSTR lpTargetPath, DWORD ucchMax)
 
        _tcscpy(lpTargetPath, storedTargetPath);
        lpTargetPath[_tcslen(storedTargetPath) + 1] = '\0'; /* 2nd final '\0' */
-
        return _tcslen(lpTargetPath) + 2;
 }
 
@@ -1257,11 +1253,12 @@ void _comm_setServerSerialDriver(HANDLE hComm, SERIAL_DRIVER_ID driverId)
        pComm->serverSerialDriverId = driverId;
 }
 
-static HANDLE_OPS ops = {
-               CommIsHandled,
-               CommCloseHandle,
-               CommGetFd,
-               NULL /* CleanupHandle */
+static HANDLE_OPS ops =
+{
+       CommIsHandled,
+       CommCloseHandle,
+       CommGetFd,
+       NULL /* CleanupHandle */
 };
 
 
@@ -1290,8 +1287,9 @@ static HANDLE_OPS ops = {
  *
  * @return INVALID_HANDLE_VALUE on error.
  */
-HANDLE CommCreateFileA(LPCSTR lpDeviceName, DWORD dwDesiredAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes,
-               DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile)
+HANDLE CommCreateFileA(LPCSTR lpDeviceName, DWORD dwDesiredAccess,
+                       DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes,
+                       DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile)
 {
        CHAR devicePath[MAX_PATH];
        struct stat deviceStat;
@@ -1300,10 +1298,11 @@ HANDLE CommCreateFileA(LPCSTR lpDeviceName, DWORD dwDesiredAccess, DWORD dwShare
 
        if (!CommInitialized())
                return INVALID_HANDLE_VALUE;
-       
+
        if (dwDesiredAccess != (GENERIC_READ | GENERIC_WRITE))
        {
-               CommLog_Print(WLOG_WARN, "unexpected access to the device: 0x%lX", dwDesiredAccess);
+               CommLog_Print(WLOG_WARN, "unexpected access to the device: 0x%lX",
+                             dwDesiredAccess);
        }
 
        if (dwShareMode != 0)
@@ -1313,11 +1312,12 @@ HANDLE CommCreateFileA(LPCSTR lpDeviceName, DWORD dwDesiredAccess, DWORD dwShare
        }
 
        /* TODO: Prevents other processes from opening a file or
-         * device if they request delete, read, or write access. */
+        * device if they request delete, read, or write access. */
 
        if (lpSecurityAttributes != NULL)
        {
-               CommLog_Print(WLOG_WARN, "unexpected security attributes, nLength=%lu", lpSecurityAttributes->nLength);
+               CommLog_Print(WLOG_WARN, "unexpected security attributes, nLength=%lu",
+                             lpSecurityAttributes->nLength);
        }
 
        if (dwCreationDisposition != OPEN_EXISTING)
@@ -1348,7 +1348,8 @@ HANDLE CommCreateFileA(LPCSTR lpDeviceName, DWORD dwDesiredAccess, DWORD dwShare
 
        if (dwFlagsAndAttributes != 0)
        {
-               CommLog_Print(WLOG_WARN, "unexpected flags and attributes: 0x%lX", dwFlagsAndAttributes);
+               CommLog_Print(WLOG_WARN, "unexpected flags and attributes: 0x%lX",
+                             dwFlagsAndAttributes);
        }
 
        if (hTemplateFile != NULL)
@@ -1358,6 +1359,7 @@ HANDLE CommCreateFileA(LPCSTR lpDeviceName, DWORD dwDesiredAccess, DWORD dwShare
        }
 
        pComm = (WINPR_COMM*) calloc(1, sizeof(WINPR_COMM));
+
        if (pComm == NULL)
        {
                SetLastError(ERROR_OUTOFMEMORY);
@@ -1365,12 +1367,10 @@ HANDLE CommCreateFileA(LPCSTR lpDeviceName, DWORD dwDesiredAccess, DWORD dwShare
        }
 
        WINPR_HANDLE_SET_TYPE_AND_MODE(pComm, HANDLE_TYPE_COMM, WINPR_FD_READ);
-
        pComm->ops = &ops;
-
        /* error_handle */
-
        pComm->fd = open(devicePath, O_RDWR | O_NOCTTY | O_NONBLOCK);
+
        if (pComm->fd < 0)
        {
                CommLog_Print(WLOG_WARN, "failed to open device %s", devicePath);
@@ -1379,6 +1379,7 @@ HANDLE CommCreateFileA(LPCSTR lpDeviceName, DWORD dwDesiredAccess, DWORD dwShare
        }
 
        pComm->fd_read = open(devicePath, O_RDONLY | O_NOCTTY | O_NONBLOCK);
+
        if (pComm->fd_read < 0)
        {
                CommLog_Print(WLOG_WARN, "failed to open fd_read, device: %s", devicePath);
@@ -1386,17 +1387,20 @@ HANDLE CommCreateFileA(LPCSTR lpDeviceName, DWORD dwDesiredAccess, DWORD dwShare
                goto error_handle;
        }
 
-       pComm->fd_read_event = eventfd(0, EFD_NONBLOCK); /* EFD_NONBLOCK required because a read() is not always expected */
+       pComm->fd_read_event = eventfd(0,
+                                      EFD_NONBLOCK); /* EFD_NONBLOCK required because a read() is not always expected */
+
        if (pComm->fd_read_event < 0)
        {
-               CommLog_Print(WLOG_WARN, "failed to open fd_read_event, device: %s", devicePath);
+               CommLog_Print(WLOG_WARN, "failed to open fd_read_event, device: %s",
+                             devicePath);
                SetLastError(ERROR_BAD_DEVICE);
                goto error_handle;
        }
 
        InitializeCriticalSection(&pComm->ReadLock);
-
        pComm->fd_write = open(devicePath, O_WRONLY | O_NOCTTY | O_NONBLOCK);
+
        if (pComm->fd_write < 0)
        {
                CommLog_Print(WLOG_WARN, "failed to open fd_write, device: %s", devicePath);
@@ -1404,60 +1408,59 @@ HANDLE CommCreateFileA(LPCSTR lpDeviceName, DWORD dwDesiredAccess, DWORD dwShare
                goto error_handle;
        }
 
-       pComm->fd_write_event = eventfd(0, EFD_NONBLOCK); /* EFD_NONBLOCK required because a read() is not always expected */
+       pComm->fd_write_event = eventfd(0,
+                                       EFD_NONBLOCK); /* EFD_NONBLOCK required because a read() is not always expected */
+
        if (pComm->fd_write_event < 0)
        {
-               CommLog_Print(WLOG_WARN, "failed to open fd_write_event, device: %s", devicePath);
+               CommLog_Print(WLOG_WARN, "failed to open fd_write_event, device: %s",
+                             devicePath);
                SetLastError(ERROR_BAD_DEVICE);
                goto error_handle;
        }
 
        InitializeCriticalSection(&pComm->WriteLock);
-
        /* can also be setup later on with _comm_setServerSerialDriver() */
        pComm->serverSerialDriverId = SerialDriverUnknown;
-
        InitializeCriticalSection(&pComm->EventsLock);
 
        if (ioctl(pComm->fd, TIOCGICOUNT, &(pComm->counters)) < 0)
        {
-               CommLog_Print(WLOG_WARN, "TIOCGICOUNT ioctl failed, errno=[%d] %s.", errno, strerror(errno));
+               CommLog_Print(WLOG_WARN, "TIOCGICOUNT ioctl failed, errno=[%d] %s.", errno,
+                             strerror(errno));
                CommLog_Print(WLOG_WARN, "could not read counters.");
-
-               /* could not initialize counters but keep on. 
+               /* could not initialize counters but keep on.
                 *
                 * Not all drivers, especially for USB to serial
                 * adapters (e.g. those based on pl2303), does support
                 * this call.
                 */
-
                ZeroMemory(&(pComm->counters), sizeof(struct serial_icounter_struct));
        }
 
-
        /* The binary/raw mode is required for the redirection but
         * only flags that are not handle somewhere-else, except
         * ICANON, are forced here. */
-
        ZeroMemory(&upcomingTermios, sizeof(struct termios));
+
        if (tcgetattr(pComm->fd, &upcomingTermios) < 0)
        {
                SetLastError(ERROR_IO_DEVICE);
                goto error_handle;
        }
 
-       upcomingTermios.c_iflag &= ~(/*IGNBRK |*/ BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL /*| IXON*/);
+       upcomingTermios.c_iflag &= ~(/*IGNBRK |*/ BRKINT | PARMRK | ISTRIP | INLCR |
+                                  IGNCR | ICRNL /*| IXON*/);
        upcomingTermios.c_oflag = 0; /* <=> &= ~OPOST */
-       upcomingTermios.c_lflag = 0; /* <=> &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN); */
+       upcomingTermios.c_lflag =
+           0; /* <=> &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN); */
        /* upcomingTermios.c_cflag &= ~(CSIZE | PARENB); */
        /* upcomingTermios.c_cflag |= CS8; */
-
        /* About missing flags recommended by termios(3):
         *
         *   IGNBRK and IXON, see: IOCTL_SERIAL_SET_HANDFLOW
         *   CSIZE, PARENB and CS8, see: IOCTL_SERIAL_SET_LINE_CONTROL
         */
-
        /* a few more settings required for the redirection */
        upcomingTermios.c_cflag |= CLOCAL | CREAD;
 
@@ -1468,29 +1471,28 @@ HANDLE CommCreateFileA(LPCSTR lpDeviceName, DWORD dwDesiredAccess, DWORD dwShare
        }
 
        return (HANDLE)pComm;
+error_handle:
 
-
-  error_handle:
        if (pComm != NULL)
        {
                CloseHandle(pComm);
        }
 
-
        return INVALID_HANDLE_VALUE;
 }
 
 
 BOOL CommIsHandled(HANDLE handle)
 {
-       WINPR_COMM *pComm;
+       WINPR_COMMpComm;
 
        if (!CommInitialized())
                return FALSE;
 
        pComm = (WINPR_COMM*)handle;
 
-       if (!pComm || (pComm->Type != HANDLE_TYPE_COMM) || (pComm == INVALID_HANDLE_VALUE))
+       if (!pComm || (pComm->Type != HANDLE_TYPE_COMM)
+           || (pComm == INVALID_HANDLE_VALUE))
        {
                SetLastError(ERROR_INVALID_HANDLE);
                return FALSE;
@@ -1501,7 +1503,7 @@ BOOL CommIsHandled(HANDLE handle)
 
 BOOL CommCloseHandle(HANDLE handle)
 {
-       WINPR_COMM *pComm;
+       WINPR_COMMpComm;
 
        if (!CommInitialized())
                return FALSE;
@@ -1520,7 +1522,8 @@ BOOL CommCloseHandle(HANDLE handle)
                DWORD BytesReturned = 0;
 
                /* ensures to gracefully stop the WAIT_ON_MASK's loop */
-               if (!CommDeviceIoControl(handle, IOCTL_SERIAL_SET_WAIT_MASK, &WaitMask, sizeof(ULONG), NULL, 0, &BytesReturned, NULL))
+               if (!CommDeviceIoControl(handle, IOCTL_SERIAL_SET_WAIT_MASK, &WaitMask,
+                                        sizeof(ULONG), NULL, 0, &BytesReturned, NULL))
                {
                        CommLog_Print(WLOG_WARN, "failure to WAIT_ON_MASK's loop!");
                }
@@ -1546,7 +1549,6 @@ BOOL CommCloseHandle(HANDLE handle)
                close(pComm->fd_read_event);
 
        free(pComm);
-
        return TRUE;
 }
 
index 02b3343..8bc5fdd 100644 (file)
@@ -63,7 +63,8 @@ struct winpr_comm
 
        COMMTIMEOUTS timeouts;
 
-       CRITICAL_SECTION EventsLock; /* protects counters, WaitEventMask and PendingEvents */
+       CRITICAL_SECTION
+       EventsLock; /* protects counters, WaitEventMask and PendingEvents */
        struct serial_icounter_struct counters;
        ULONG WaitEventMask;
        ULONG PendingEvents;
@@ -93,7 +94,7 @@ typedef struct winpr_comm WINPR_COMM;
 #define FREERDP_PURGE_RXABORT          0x00000002 /* abort pending reception */
 
 
-void CommLog_Print(int wlog_level, char *fmt, ...);
+void CommLog_Print(int wlog_level, ...);
 
 BOOL CommIsHandled(HANDLE handle);
 BOOL CommCloseHandle(HANDLE handle);
index de819a7..0a5ca46 100644 (file)
@@ -41,8 +41,8 @@ BOOL _comm_set_permissive(HANDLE hDevice, BOOL permissive)
        if (hDevice == INVALID_HANDLE_VALUE)
        {
                SetLastError(ERROR_INVALID_HANDLE);
-                return FALSE;
-        }
+               return FALSE;
+       }
 
        if (!pComm || pComm->Type != HANDLE_TYPE_COMM)
        {
@@ -67,7 +67,7 @@ static UCHAR _vtime(ULONG Ti)
        else if (Ti > 25500)
                return 255; /* 0xFF */
        else
-               return Ti/100;
+               return Ti / 100;
 }
 
 
@@ -81,26 +81,25 @@ static UCHAR _vtime(ULONG Ti)
  *   ERROR_BAD_DEVICE
  */
 BOOL CommReadFile(HANDLE hDevice, LPVOID lpBuffer, DWORD nNumberOfBytesToRead,
-               LPDWORD lpNumberOfBytesRead, LPOVERLAPPED lpOverlapped)
+                  LPDWORD lpNumberOfBytesRead, LPOVERLAPPED lpOverlapped)
 {
        WINPR_COMM* pComm = (WINPR_COMM*) hDevice;
        int biggestFd = -1;
        fd_set read_set;
        int nbFds;
-       COMMTIMEOUTS *pTimeouts;
+       COMMTIMEOUTSpTimeouts;
        UCHAR vmin = 0;
        UCHAR vtime = 0;
        ULONGLONG Tmax = 0;
        struct timeval tmaxTimeout, *pTmaxTimeout;
        struct termios currentTermios;
-
        EnterCriticalSection(&pComm->ReadLock); /* KISSer by the function's beginning */
 
        if (hDevice == INVALID_HANDLE_VALUE)
        {
                SetLastError(ERROR_INVALID_HANDLE);
-                goto return_false;
-        }
+               goto return_false;
+       }
 
        if (!pComm || pComm->Type != HANDLE_TYPE_COMM)
        {
@@ -116,7 +115,8 @@ BOOL CommReadFile(HANDLE hDevice, LPVOID lpBuffer, DWORD nNumberOfBytesToRead,
 
        if (lpNumberOfBytesRead == NULL)
        {
-               SetLastError(ERROR_INVALID_PARAMETER); /* since we doesn't suppport lpOverlapped != NULL */
+               SetLastError(
+                   ERROR_INVALID_PARAMETER); /* since we doesn't suppport lpOverlapped != NULL */
                goto return_false;
        }
 
@@ -135,7 +135,8 @@ BOOL CommReadFile(HANDLE hDevice, LPVOID lpBuffer, DWORD nNumberOfBytesToRead,
 
        if (currentTermios.c_lflag & ICANON)
        {
-               CommLog_Print(WLOG_WARN, "Canonical mode not supported"); /* the timeout could not be set */
+               CommLog_Print(WLOG_WARN,
+                             "Canonical mode not supported"); /* the timeout could not be set */
                SetLastError(ERROR_NOT_SUPPORTED);
                goto return_false;
        }
@@ -145,30 +146,31 @@ BOOL CommReadFile(HANDLE hDevice, LPVOID lpBuffer, DWORD nNumberOfBytesToRead,
         *
         * ReadIntervalTimeout  | ReadTotalTimeoutMultiplier | ReadTotalTimeoutConstant | VMIN | VTIME | TMAX  |
         *         0            |            0               |           0              |   N  |   0   | INDEF | Blocks for N bytes available.
-         *   0< Ti <MAXULONG    |            0               |           0              |   N  |   Ti  | INDEF | Blocks on first byte, then use Ti between bytes.
+            *   0< Ti <MAXULONG    |            0               |           0              |   N  |   Ti  | INDEF | Blocks on first byte, then use Ti between bytes.
         *       MAXULONG       |            0               |           0              |   0  |   0   |   0   | Returns immediately with bytes available (don't block)
         *       MAXULONG       |         MAXULONG           |      0< Tc <MAXULONG     |   N  |   0   |   Tc  | Blocks on first byte during Tc or returns immediately whith bytes available
         *       MAXULONG       |            m               |        MAXULONG          |                      | Invalid
         *         0            |            m               |      0< Tc <MAXULONG     |   N  |   0   |  Tmax | Blocks on first byte during Tmax or returns immediately whith bytes available
         *   0< Ti <MAXULONG    |            m               |      0< Tc <MAXULONG     |   N  |   Ti  |  Tmax | Blocks on first byte, then use Ti between bytes. Tmax is used for the whole system call.
         */
-
        /* NB: timeouts are in milliseconds, VTIME are in deciseconds and is an unsigned char */
-
        /* FIXME: double check whether open(pComm->fd_read_event, O_NONBLOCK) doesn't conflict with above use cases */
-
        pTimeouts = &(pComm->timeouts);
 
-       if ((pTimeouts->ReadIntervalTimeout == MAXULONG) && (pTimeouts->ReadTotalTimeoutConstant == MAXULONG))
+       if ((pTimeouts->ReadIntervalTimeout == MAXULONG)
+           && (pTimeouts->ReadTotalTimeoutConstant == MAXULONG))
        {
-               CommLog_Print(WLOG_WARN, "ReadIntervalTimeout and ReadTotalTimeoutConstant cannot be both set to MAXULONG");
+               CommLog_Print(WLOG_WARN,
+                             "ReadIntervalTimeout and ReadTotalTimeoutConstant cannot be both set to MAXULONG");
                SetLastError(ERROR_INVALID_PARAMETER);
                goto return_false;
        }
 
        /* VMIN */
 
-       if ((pTimeouts->ReadIntervalTimeout == MAXULONG) && (pTimeouts->ReadTotalTimeoutMultiplier == 0) && (pTimeouts->ReadTotalTimeoutConstant == 0))
+       if ((pTimeouts->ReadIntervalTimeout == MAXULONG)
+           && (pTimeouts->ReadTotalTimeoutMultiplier == 0)
+           && (pTimeouts->ReadTotalTimeoutConstant == 0))
        {
                vmin = 0;
        }
@@ -176,28 +178,26 @@ BOOL CommReadFile(HANDLE hDevice, LPVOID lpBuffer, DWORD nNumberOfBytesToRead,
        {
                /* N */
                /* vmin = nNumberOfBytesToRead < 256 ? nNumberOfBytesToRead : 255;*/ /* 0xFF */
-
                /* NB: we might wait endlessly with vmin=N, prefer to
                 * force vmin=1 and return with bytes
                 * available. FIXME: is a feature disarded here? */
                vmin = 1;
        }
 
-
        /* VTIME */
 
-       if ((pTimeouts->ReadIntervalTimeout > 0) && (pTimeouts->ReadIntervalTimeout < MAXULONG))
+       if ((pTimeouts->ReadIntervalTimeout > 0)
+           && (pTimeouts->ReadIntervalTimeout < MAXULONG))
        {
                /* Ti */
                vtime = _vtime(pTimeouts->ReadIntervalTimeout);
        }
 
-
        /* TMAX */
+       pTmaxTimeout = &tmaxTimeout;
 
-        pTmaxTimeout = &tmaxTimeout;
-
-       if ((pTimeouts->ReadIntervalTimeout == MAXULONG) && (pTimeouts->ReadTotalTimeoutMultiplier == MAXULONG))
+       if ((pTimeouts->ReadIntervalTimeout == MAXULONG)
+           && (pTimeouts->ReadTotalTimeoutMultiplier == MAXULONG))
        {
                /* Tc */
                Tmax = pTimeouts->ReadTotalTimeoutConstant;
@@ -205,60 +205,64 @@ BOOL CommReadFile(HANDLE hDevice, LPVOID lpBuffer, DWORD nNumberOfBytesToRead,
        else
        {
                /* Tmax */
-               Tmax = nNumberOfBytesToRead * pTimeouts->ReadTotalTimeoutMultiplier + pTimeouts->ReadTotalTimeoutConstant;
+               Tmax = nNumberOfBytesToRead * pTimeouts->ReadTotalTimeoutMultiplier +
+                      pTimeouts->ReadTotalTimeoutConstant;
 
                /* INDEFinitely */
-               if((Tmax == 0) && (pTimeouts->ReadIntervalTimeout < MAXULONG) && (pTimeouts->ReadTotalTimeoutMultiplier == 0))
+               if ((Tmax == 0) && (pTimeouts->ReadIntervalTimeout < MAXULONG)
+                   && (pTimeouts->ReadTotalTimeoutMultiplier == 0))
                        pTmaxTimeout = NULL;
        }
 
-       if ((currentTermios.c_cc[VMIN] != vmin) || (currentTermios.c_cc[VTIME] != vtime))
+       if ((currentTermios.c_cc[VMIN] != vmin)
+           || (currentTermios.c_cc[VTIME] != vtime))
        {
                currentTermios.c_cc[VMIN]  = vmin;
                currentTermios.c_cc[VTIME] = vtime;
 
                if (tcsetattr(pComm->fd, TCSANOW, &currentTermios) < 0)
                {
-                       CommLog_Print(WLOG_WARN, "CommReadFile failure, could not apply new timeout values: VMIN=%u, VTIME=%u", vmin, vtime);
+                       CommLog_Print(WLOG_WARN,
+                                     "CommReadFile failure, could not apply new timeout values: VMIN=%u, VTIME=%u",
+                                     vmin, vtime);
                        SetLastError(ERROR_IO_DEVICE);
                        goto return_false;
                }
        }
 
-        /* wait indefinitely if pTmaxTimeout is NULL */
+       /* wait indefinitely if pTmaxTimeout is NULL */
 
-       if(pTmaxTimeout != NULL) 
+       if (pTmaxTimeout != NULL)
        {
-           ZeroMemory(pTmaxTimeout, sizeof(struct timeval));
-           if (Tmax > 0) /* return immdiately if Tmax == 0 */
-           {
-               pTmaxTimeout->tv_sec = Tmax / 1000; /* s */
-               pTmaxTimeout->tv_usec = (Tmax % 1000) * 1000; /* us */
-           }
-       }
+               ZeroMemory(pTmaxTimeout, sizeof(struct timeval));
 
+               if (Tmax > 0) /* return immdiately if Tmax == 0 */
+               {
+                       pTmaxTimeout->tv_sec = Tmax / 1000; /* s */
+                       pTmaxTimeout->tv_usec = (Tmax % 1000) * 1000; /* us */
+               }
+       }
 
        /* FIXME: had expected eventfd_write() to return EAGAIN when
         * there is no eventfd_read() but this not the case. */
        /* discard a possible and no more relevant event */
        eventfd_read(pComm->fd_read_event, NULL);
-
        biggestFd = pComm->fd_read;
+
        if (pComm->fd_read_event > biggestFd)
                biggestFd = pComm->fd_read_event;
 
        FD_ZERO(&read_set);
-
        assert(pComm->fd_read_event < FD_SETSIZE);
        assert(pComm->fd_read < FD_SETSIZE);
-
        FD_SET(pComm->fd_read_event, &read_set);
        FD_SET(pComm->fd_read, &read_set);
+       nbFds = select(biggestFd + 1, &read_set, NULL, NULL, pTmaxTimeout);
 
-       nbFds = select(biggestFd+1, &read_set, NULL, NULL, pTmaxTimeout);
        if (nbFds < 0)
        {
-               CommLog_Print(WLOG_WARN, "select() failure, errno=[%d] %s\n", errno, strerror(errno));
+               CommLog_Print(WLOG_WARN, "select() failure, errno=[%d] %s\n", errno,
+                             strerror(errno));
                SetLastError(ERROR_IO_DEVICE);
                goto return_false;
        }
@@ -266,12 +270,10 @@ BOOL CommReadFile(HANDLE hDevice, LPVOID lpBuffer, DWORD nNumberOfBytesToRead,
        if (nbFds == 0)
        {
                /* timeout */
-
                SetLastError(ERROR_TIMEOUT);
                goto return_false;
        }
 
-
        /* read_set */
 
        if (FD_ISSET(pComm->fd_read_event, &read_set))
@@ -287,7 +289,9 @@ BOOL CommReadFile(HANDLE hDevice, LPVOID lpBuffer, DWORD nNumberOfBytesToRead,
                        }
                        else
                        {
-                               CommLog_Print(WLOG_WARN, "unexpected error on reading fd_read_event, errno=[%d] %s\n", errno, strerror(errno));
+                               CommLog_Print(WLOG_WARN,
+                                             "unexpected error on reading fd_read_event, errno=[%d] %s\n", errno,
+                                             strerror(errno));
                                /* FIXME: goto return_false ? */
                        }
 
@@ -303,18 +307,21 @@ BOOL CommReadFile(HANDLE hDevice, LPVOID lpBuffer, DWORD nNumberOfBytesToRead,
                assert(event == FREERDP_PURGE_RXABORT); /* no other expected event so far */
        }
 
-
        if (FD_ISSET(pComm->fd_read, &read_set))
        {
                ssize_t nbRead = 0;
-
                nbRead = read(pComm->fd_read, lpBuffer, nNumberOfBytesToRead);
+
                if (nbRead < 0)
                {
-                       CommLog_Print(WLOG_WARN, "CommReadFile failed, ReadIntervalTimeout=%lu, ReadTotalTimeoutMultiplier=%lu, ReadTotalTimeoutConstant=%lu VMIN=%u, VTIME=%u",
-                               pTimeouts->ReadIntervalTimeout, pTimeouts->ReadTotalTimeoutMultiplier, pTimeouts->ReadTotalTimeoutConstant,
-                               currentTermios.c_cc[VMIN], currentTermios.c_cc[VTIME]);
-                       CommLog_Print(WLOG_WARN, "CommReadFile failed, nNumberOfBytesToRead=%lu, errno=[%d] %s", nNumberOfBytesToRead, errno, strerror(errno));
+                       CommLog_Print(WLOG_WARN,
+                                     "CommReadFile failed, ReadIntervalTimeout=%lu, ReadTotalTimeoutMultiplier=%lu, ReadTotalTimeoutConstant=%lu VMIN=%u, VTIME=%u",
+                                     pTimeouts->ReadIntervalTimeout, pTimeouts->ReadTotalTimeoutMultiplier,
+                                     pTimeouts->ReadTotalTimeoutConstant,
+                                     currentTermios.c_cc[VMIN], currentTermios.c_cc[VTIME]);
+                       CommLog_Print(WLOG_WARN,
+                                     "CommReadFile failed, nNumberOfBytesToRead=%lu, errno=[%d] %s",
+                                     nNumberOfBytesToRead, errno, strerror(errno));
 
                        if (errno == EAGAIN)
                        {
@@ -347,12 +354,10 @@ BOOL CommReadFile(HANDLE hDevice, LPVOID lpBuffer, DWORD nNumberOfBytesToRead,
 
        assert(FALSE);
        *lpNumberOfBytesRead = 0;
-
-  return_false:
+return_false:
        LeaveCriticalSection(&pComm->ReadLock);
        return FALSE;
-
-  return_true:
+return_true:
        LeaveCriticalSection(&pComm->ReadLock);
        return TRUE;
 }
@@ -365,19 +370,20 @@ BOOL CommReadFile(HANDLE hDevice, LPVOID lpBuffer, DWORD nNumberOfBytesToRead,
  *   ERROR_INVALID_PARAMETER
  *   ERROR_BAD_DEVICE
  */
-BOOL CommWriteFile(HANDLE hDevice, LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite,
-               LPDWORD lpNumberOfBytesWritten, LPOVERLAPPED lpOverlapped)
+BOOL CommWriteFile(HANDLE hDevice, LPCVOID lpBuffer,
+                   DWORD nNumberOfBytesToWrite,
+                   LPDWORD lpNumberOfBytesWritten, LPOVERLAPPED lpOverlapped)
 {
        WINPR_COMM* pComm = (WINPR_COMM*) hDevice;
        struct timeval tmaxTimeout, *pTmaxTimeout;
-
-       EnterCriticalSection(&pComm->WriteLock); /* KISSer by the function's beginning */
+       EnterCriticalSection(
+           &pComm->WriteLock); /* KISSer by the function's beginning */
 
        if (hDevice == INVALID_HANDLE_VALUE)
        {
                SetLastError(ERROR_INVALID_HANDLE);
-                goto return_false;
-        }
+               goto return_false;
+       }
 
        if (!pComm || pComm->Type != HANDLE_TYPE_COMM)
        {
@@ -393,7 +399,8 @@ BOOL CommWriteFile(HANDLE hDevice, LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite
 
        if (lpNumberOfBytesWritten == NULL)
        {
-               SetLastError(ERROR_INVALID_PARAMETER); /* since we doesn't suppport lpOverlapped != NULL */
+               SetLastError(
+                   ERROR_INVALID_PARAMETER); /* since we doesn't suppport lpOverlapped != NULL */
                goto return_false;
        }
 
@@ -408,26 +415,27 @@ BOOL CommWriteFile(HANDLE hDevice, LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite
         * there is no eventfd_read() but this not the case. */
        /* discard a possible and no more relevant event */
        eventfd_read(pComm->fd_write_event, NULL);
-
-
        /* ms */
-       ULONGLONG Tmax = nNumberOfBytesToWrite * pComm->timeouts.WriteTotalTimeoutMultiplier + pComm->timeouts.WriteTotalTimeoutConstant;
-
+       ULONGLONG Tmax = nNumberOfBytesToWrite *
+                        pComm->timeouts.WriteTotalTimeoutMultiplier +
+                        pComm->timeouts.WriteTotalTimeoutConstant;
        /* NB: select() may update the timeout argument to indicate
         * how much time was left. Keep the timeout variable out of
         * the while() */
-
-       pTmaxTimeout = &tmaxTimeout; 
+       pTmaxTimeout = &tmaxTimeout;
        ZeroMemory(pTmaxTimeout, sizeof(struct timeval));
-       if (Tmax > 0) 
+
+       if (Tmax > 0)
        {
                pTmaxTimeout->tv_sec = Tmax / 1000; /* s */
                pTmaxTimeout->tv_usec = (Tmax % 1000) * 1000; /* us */
        }
-       else if ((pComm->timeouts.WriteTotalTimeoutMultiplier == 0) && (pComm->timeouts.WriteTotalTimeoutConstant == 0))
+       else if ((pComm->timeouts.WriteTotalTimeoutMultiplier == 0)
+                && (pComm->timeouts.WriteTotalTimeoutConstant == 0))
        {
                pTmaxTimeout = NULL;
        }
+
        /* else return immdiately */
 
        while (*lpNumberOfBytesWritten < nNumberOfBytesToWrite)
@@ -435,24 +443,23 @@ BOOL CommWriteFile(HANDLE hDevice, LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite
                int biggestFd = -1;
                fd_set event_set, write_set;
                int nbFds;
-
                biggestFd = pComm->fd_write;
+
                if (pComm->fd_write_event > biggestFd)
                        biggestFd = pComm->fd_write_event;
 
                FD_ZERO(&event_set);
                FD_ZERO(&write_set);
-
                assert(pComm->fd_write_event < FD_SETSIZE);
                assert(pComm->fd_write < FD_SETSIZE);
-
                FD_SET(pComm->fd_write_event, &event_set);
                FD_SET(pComm->fd_write, &write_set);
+               nbFds = select(biggestFd + 1, &event_set, &write_set, NULL, pTmaxTimeout);
 
-               nbFds = select(biggestFd+1, &event_set, &write_set, NULL, pTmaxTimeout);
                if (nbFds < 0)
                {
-                       CommLog_Print(WLOG_WARN, "select() failure, errno=[%d] %s\n", errno, strerror(errno));
+                       CommLog_Print(WLOG_WARN, "select() failure, errno=[%d] %s\n", errno,
+                                     strerror(errno));
                        SetLastError(ERROR_IO_DEVICE);
                        goto return_false;
                }
@@ -460,12 +467,10 @@ BOOL CommWriteFile(HANDLE hDevice, LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite
                if (nbFds == 0)
                {
                        /* timeout */
-
                        SetLastError(ERROR_TIMEOUT);
                        goto return_false;
                }
 
-
                /* event_set */
 
                if (FD_ISSET(pComm->fd_write_event, &event_set))
@@ -481,7 +486,9 @@ BOOL CommWriteFile(HANDLE hDevice, LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite
                                }
                                else
                                {
-                                       CommLog_Print(WLOG_WARN, "unexpected error on reading fd_write_event, errno=[%d] %s\n", errno, strerror(errno));
+                                       CommLog_Print(WLOG_WARN,
+                                                     "unexpected error on reading fd_write_event, errno=[%d] %s\n", errno,
+                                                     strerror(errno));
                                        /* FIXME: goto return_false ? */
                                }
 
@@ -497,20 +504,20 @@ BOOL CommWriteFile(HANDLE hDevice, LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite
                        assert(event == FREERDP_PURGE_TXABORT); /* no other expected event so far */
                }
 
-
                /* write_set */
 
                if (FD_ISSET(pComm->fd_write, &write_set))
                {
                        ssize_t nbWritten;
-
                        nbWritten = write(pComm->fd_write,
-                                       lpBuffer + (*lpNumberOfBytesWritten),
-                                       nNumberOfBytesToWrite - (*lpNumberOfBytesWritten));
+                                         ((BYTE*)lpBuffer) + (*lpNumberOfBytesWritten),
+                                         nNumberOfBytesToWrite - (*lpNumberOfBytesWritten));
 
                        if (nbWritten < 0)
                        {
-                               CommLog_Print(WLOG_WARN, "CommWriteFile failed after %lu bytes written, errno=[%d] %s\n", *lpNumberOfBytesWritten, errno, strerror(errno));
+                               CommLog_Print(WLOG_WARN,
+                                             "CommWriteFile failed after %lu bytes written, errno=[%d] %s\n",
+                                             *lpNumberOfBytesWritten, errno, strerror(errno));
 
                                if (errno == EAGAIN)
                                {
@@ -532,10 +539,8 @@ BOOL CommWriteFile(HANDLE hDevice, LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite
 
                        *lpNumberOfBytesWritten += nbWritten;
                }
-
        } /* while */
 
-
        /* FIXME: this call to tcdrain() doesn't look correct and
         * might hide a bug but was required while testing a serial
         * printer. Its driver was expecting the modem line status
@@ -545,13 +550,10 @@ BOOL CommWriteFile(HANDLE hDevice, LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite
         * DesiredAccess=0x0012019F. The printer worked fine with
         * mstsc. */
        tcdrain(pComm->fd_write);
-
-
-  return_true:
+return_true:
        LeaveCriticalSection(&pComm->WriteLock);
        return TRUE;
-
-  return_false:
+return_false:
        LeaveCriticalSection(&pComm->WriteLock);
        return FALSE;
 }
index 5653da0..1892153 100644 (file)
@@ -84,33 +84,39 @@ static BOOL log_recursion(LPCSTR file, LPCSTR fkt, int line)
 
        if (!bt)
                return FALSE;
+
        msg = winpr_backtrace_symbols(bt, &used);
+
        if (!msg)
                return FALSE;
+
 #if defined(ANDROID)
+
        if (__android_log_print(ANDROID_LOG_FATAL, tag, "Recursion detected!!!") < 0)
                return FALSE;
-       if (__android_log_print(ANDROID_LOG_FATAL, tag, "Check %s [%s:%d]", fkt, file, line) < 0)
+
+       if (__android_log_print(ANDROID_LOG_FATAL, tag, "Check %s [%s:%d]", fkt, file,
+                               line) < 0)
                return FALSE;
 
-       for (i=0; i<used; i++)
+       for (i = 0; i < used; i++)
                if (__android_log_print(ANDROID_LOG_FATAL, tag, "%d: %s", i, msg[i]) < 0)
                        return FALSE;
 
 #else
+
        if (fprintf(stderr, "[%s]: Recursion detected!\n", fkt) < 0)
                return FALSE;
+
        if (fprintf(stderr, "[%s]: Check %s:%d\n", fkt, file, line) < 0)
                return FALSE;
 
-       for (i=0; i<used; i++)
+       for (i = 0; i < used; i++)
                if (fprintf(stderr, "%s: %lu: %s\n", fkt, (unsigned long)i, msg[i]) < 0)
                        return FALSE;
 
 #endif
-
        free(msg);
-
        winpr_backtrace_free(bt);
        return TRUE;
 }
@@ -134,7 +140,8 @@ BOOL WLog_Write(wLog* log, wLogMessage* message)
        EnterCriticalSection(&appender->lock);
 
        if (appender->recursive)
-               status = log_recursion(message->FileName, message->FunctionName, message->LineNumber);
+               status = log_recursion(message->FileName, message->FunctionName,
+                                      message->LineNumber);
        else
        {
                appender->recursive = TRUE;
@@ -165,7 +172,8 @@ BOOL WLog_WriteData(wLog* log, wLogMessage* message)
        EnterCriticalSection(&appender->lock);
 
        if (appender->recursive)
-               status = log_recursion(message->FileName, message->FunctionName, message->LineNumber);
+               status = log_recursion(message->FileName, message->FunctionName,
+                                      message->LineNumber);
        else
        {
                appender->recursive = TRUE;
@@ -196,7 +204,8 @@ BOOL WLog_WriteImage(wLog* log, wLogMessage* message)
        EnterCriticalSection(&appender->lock);
 
        if (appender->recursive)
-               status = log_recursion(message->FileName, message->FunctionName, message->LineNumber);
+               status = log_recursion(message->FileName, message->FunctionName,
+                                      message->LineNumber);
        else
        {
                appender->recursive = TRUE;
@@ -227,7 +236,8 @@ BOOL WLog_WritePacket(wLog* log, wLogMessage* message)
        EnterCriticalSection(&appender->lock);
 
        if (appender->recursive)
-               status = log_recursion(message->FileName, message->FunctionName, message->LineNumber);
+               status = log_recursion(message->FileName, message->FunctionName,
+                                      message->LineNumber);
        else
        {
                appender->recursive = TRUE;
@@ -239,57 +249,75 @@ BOOL WLog_WritePacket(wLog* log, wLogMessage* message)
        return status;
 }
 
-BOOL WLog_PrintMessageVA(wLog* log, wLogMessage* message, va_list args)
+BOOL WLog_PrintMessageVA(wLog* log, DWORD type, DWORD level, DWORD line,
+                         const char* file, const char* function, va_list args)
 {
        BOOL status = FALSE;
+       wLogMessage message = { 0 };
+       message.Level = level;
+       message.LineNumber = line;
+       message.FileName = file;
+       message.FunctionName = function;
 
-       if (message->Type == WLOG_MESSAGE_TEXT)
-       {
-               if (!strchr(message->FormatString, '%'))
-               {
-                       message->TextString = (LPSTR) message->FormatString;
-                       status = WLog_Write(log, message);
-               }
-               else
-               {
-                       char formattedLogMessage[WLOG_MAX_STRING_SIZE];
-                       if (wvsnprintfx(formattedLogMessage, WLOG_MAX_STRING_SIZE - 1, message->FormatString, args) < 0)
-                               return FALSE;
-                       message->TextString = formattedLogMessage;
-                       status = WLog_Write(log, message);
-               }
-       }
-       else if (message->Type == WLOG_MESSAGE_DATA)
+       switch (type)
        {
-               message->Data = va_arg(args, void*);
-               message->Length = va_arg(args, int);
-               status = WLog_WriteData(log, message);
-       }
-       else if (message->Type == WLOG_MESSAGE_IMAGE)
-       {
-               message->ImageData = va_arg(args, void*);
-               message->ImageWidth = va_arg(args, int);
-               message->ImageHeight = va_arg(args, int);
-               message->ImageBpp = va_arg(args, int);
-               status = WLog_WriteImage(log, message);
-       }
-       else if (message->Type == WLOG_MESSAGE_PACKET)
-       {
-               message->PacketData = va_arg(args, void*);
-               message->PacketLength = va_arg(args, int);
-               message->PacketFlags = va_arg(args, int);
-               status = WLog_WritePacket(log, message);
+               case WLOG_MESSAGE_TEXT:
+                       message.FormatString = va_arg(args, const char*);
+
+                       if (!strchr(message.FormatString, '%'))
+                       {
+                               message.TextString = (LPSTR) message.FormatString;
+                               status = WLog_Write(log, &message);
+                       }
+                       else
+                       {
+                               char formattedLogMessage[WLOG_MAX_STRING_SIZE];
+
+                               if (wvsnprintfx(formattedLogMessage, WLOG_MAX_STRING_SIZE - 1,
+                                               message.FormatString, args) < 0)
+                                       return FALSE;
+
+                               message.TextString = formattedLogMessage;
+                               status = WLog_Write(log, &message);
+                       }
+
+                       break;
+
+               case WLOG_MESSAGE_DATA:
+                       message.Data = va_arg(args, void*);
+                       message.Length = va_arg(args, int);
+                       status = WLog_WriteData(log, &message);
+                       break;
+
+               case WLOG_MESSAGE_IMAGE:
+                       message.ImageData = va_arg(args, void*);
+                       message.ImageWidth = va_arg(args, int);
+                       message.ImageHeight = va_arg(args, int);
+                       message.ImageBpp = va_arg(args, int);
+                       status = WLog_WriteImage(log, &message);
+                       break;
+
+               case WLOG_MESSAGE_PACKET:
+                       message.PacketData = va_arg(args, void*);
+                       message.PacketLength = va_arg(args, int);
+                       message.PacketFlags = va_arg(args, int);
+                       status = WLog_WritePacket(log, &message);
+                       break;
+
+               default:
+                       break;
        }
 
        return status;
 }
 
-BOOL WLog_PrintMessage(wLog* log, wLogMessage* message, ...)
+BOOL WLog_PrintMessage(wLog* log, DWORD type, DWORD level, DWORD line,
+                       const char* file, const char* function, ...)
 {
        BOOL status;
        va_list args;
-       va_start(args, message);
-       status = WLog_PrintMessageVA(log, message, args);
+       va_start(args, function);
+       status = WLog_PrintMessageVA(log, type, level, line, file, function, args);
        va_end(args);
        return status;
 }
@@ -303,16 +331,19 @@ DWORD WLog_GetLogLevel(wLog* log)
                return log->FilterLevel;
        else if (log->Level == WLOG_LEVEL_INHERIT)
                log->Level = WLog_GetLogLevel(log->Parent);
+
        return log->Level;
 }
 
 BOOL WLog_SetStringLogLevel(wLog* log, LPCSTR level)
 {
        int lvl;
+
        if (!log || !level)
                return FALSE;
 
        lvl = WLog_ParseLogLevel(level);
+
        if (lvl < 0)
                return FALSE;
 
@@ -349,8 +380,8 @@ BOOL WLog_AddStringLogFilters(LPCSTR filter)
                return FALSE;
 
        g_Filters = tmp;
-
        cp = (LPSTR)_strdup(filter);
+
        if (!cp)
                return FALSE;
 
@@ -360,6 +391,7 @@ BOOL WLog_AddStringLogFilters(LPCSTR filter)
        do
        {
                p = strchr(p, ',');
+
                if (p)
                        *p = '\0';
 
@@ -367,7 +399,7 @@ BOOL WLog_AddStringLogFilters(LPCSTR filter)
                {
                        if (!WLog_ParseFilter(&g_Filters[pos++], filterStr))
                        {
-                               free (cp);
+                               free(cp);
                                return FALSE;
                        }
                }
@@ -383,8 +415,7 @@ BOOL WLog_AddStringLogFilters(LPCSTR filter)
        while (p != NULL);
 
        g_FilterCount = size;
-       free (cp);
-
+       free(cp);
        return TRUE;
 }
 
@@ -434,7 +465,7 @@ BOOL WLog_ParseFilter(wLogFilter* filter, LPCSTR name)
        int iLevel;
        count = 1;
 
-       if(!name)
+       if (!name)
                return FALSE;
 
        p = (char*) name;
@@ -449,16 +480,20 @@ BOOL WLog_ParseFilter(wLogFilter* filter, LPCSTR name)
        }
 
        names = _strdup(name);
+
        if (!names)
                return FALSE;
+
        filter->NameCount = count;
        filter->Names = (LPSTR*) calloc((count + 1UL), sizeof(LPSTR));
-       if(!filter->Names)
+
+       if (!filter->Names)
        {
                free(names);
                filter->NameCount = 0;
                return FALSE;
        }
+
        filter->Names[count] = NULL;
        count = 0;
        p = (char*) names;
@@ -493,6 +528,7 @@ BOOL WLog_ParseFilter(wLogFilter* filter, LPCSTR name)
        {
                if (count < (int) filter->NameCount)
                        filter->Names[count++] = p + 1;
+
                *p = '\0';
                p++;
        }
@@ -505,10 +541,8 @@ BOOL WLog_ParseFilters(void)
        BOOL res;
        char* env;
        DWORD nSize;
-
        g_Filters = NULL;
        g_FilterCount = 0;
-
        nSize = GetEnvironmentVariableA("WLOG_FILTER", NULL, 0);
 
        if (nSize < 1)
@@ -523,9 +557,7 @@ BOOL WLog_ParseFilters(void)
                return FALSE;
 
        res = WLog_AddStringLogFilters(env);
-
        free(env);
-
        return res;
 }
 
@@ -587,15 +619,19 @@ BOOL WLog_ParseName(wLog* log, LPCSTR name)
        }
 
        names = _strdup(name);
+
        if (!names)
                return FALSE;
+
        log->NameCount = count;
        log->Names = (LPSTR*) calloc((count + 1UL), sizeof(LPSTR));
-       if(!log->Names)
+
+       if (!log->Names)
        {
                free(names);
                return FALSE;
        }
+
        log->Names[count] = NULL;
        count = 0;
        p = (char*) names;
@@ -605,6 +641,7 @@ BOOL WLog_ParseName(wLog* log, LPCSTR name)
        {
                if (count < (int) log->NameCount)
                        log->Names[count++] = p + 1;
+
                *p = '\0';
                p++;
        }
@@ -618,8 +655,8 @@ wLog* WLog_New(LPCSTR name, wLog* rootLogger)
        char* env = NULL;
        DWORD nSize;
        int iLevel;
-
        log = (wLog*) calloc(1, sizeof(wLog));
+
        if (!log)
                return NULL;
 
@@ -653,6 +690,7 @@ wLog* WLog_New(LPCSTR name, wLog* rootLogger)
                if (nSize)
                {
                        env = (LPSTR) malloc(nSize);
+
                        if (!env)
                                goto out_fail;
 
@@ -677,11 +715,10 @@ wLog* WLog_New(LPCSTR name, wLog* rootLogger)
                log->Level = (DWORD) iLevel;
 
        return log;
-
 out_fail:
-       free (log->Children);
-       free (log->Name);
-       free (log);
+       free(log->Children);
+       free(log->Name);
+       free(log);
        return NULL;
 }
 
@@ -724,6 +761,7 @@ wLog* WLog_GetRoot(void)
                if (nSize)
                {
                        env = (LPSTR) malloc(nSize);
+
                        if (!env)
                                goto fail;
 
@@ -740,13 +778,16 @@ wLog* WLog_GetRoot(void)
                                logAppenderType = WLOG_APPENDER_FILE;
                        else if (_stricmp(env, "BINARY") == 0)
                                logAppenderType = WLOG_APPENDER_BINARY;
+
 #ifdef HAVE_SYSLOG_H
                        else if (_stricmp(env, "SYSLOG") == 0)
                                logAppenderType = WLOG_APPENDER_SYSLOG;
+
 #endif /* HAVE_SYSLOG_H */
 #ifdef HAVE_JOURNALD_H
                        else if (_stricmp(env, "JOURNALD") == 0)
                                logAppenderType = WLOG_APPENDER_JOURNALD;
+
 #endif
                        else if (_stricmp(env, "UDP") == 0)
                                logAppenderType = WLOG_APPENDER_UDP;
@@ -759,7 +800,6 @@ wLog* WLog_GetRoot(void)
        }
 
        return g_RootLog;
-
 fail:
        free(g_RootLog);
        g_RootLog = NULL;
@@ -770,24 +810,29 @@ BOOL WLog_AddChild(wLog* parent, wLog* child)
 {
        if (parent->ChildrenCount >= parent->ChildrenSize)
        {
-               wLog **tmp;
+               wLog** tmp;
                parent->ChildrenSize *= 2;
+
                if (!parent->ChildrenSize)
                {
                        if (parent->Children)
-                               free (parent->Children);
+                               free(parent->Children);
+
                        parent->Children = NULL;
                }
                else
                {
                        tmp = (wLog**) realloc(parent->Children, sizeof(wLog*) * parent->ChildrenSize);
+
                        if (!tmp)
                        {
                                if (parent->Children)
-                                       free (parent->Children);
+                                       free(parent->Children);
+
                                parent->Children = NULL;
                                return FALSE;
                        }
+
                        parent->Children = tmp;
                }
        }
@@ -828,28 +873,33 @@ wLog* WLog_FindChild(LPCSTR name)
 wLog* WLog_Get(LPCSTR name)
 {
        wLog* log;
+
        if (!(log = WLog_FindChild(name)))
        {
                wLog* root = WLog_GetRoot();
+
                if (!root)
                        return NULL;
+
                if (!(log = WLog_New(name, root)))
                        return NULL;
+
                if (!WLog_AddChild(root, log))
                {
                        WLog_Free(log);
                        return NULL;
                }
        }
+
        return log;
 }
 
-BOOL WLog_Init()
+BOOL WLog_Init(void)
 {
        return WLog_GetRoot() != NULL;
 }
 
-BOOL WLog_Uninit()
+BOOL WLog_Uninit(void)
 {
        DWORD index;
        wLog* child = NULL;