#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 */
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 */
#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 */
#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
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 */
#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);
#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
UINT32 Channels;
UINT32 BitsPerSample;
UINT32 BlockAlign;
- const BYTE *ExtraData;
+ const BYTE* ExtraData;
UINT32 ExtraDataSize;
} TS_AM_MEDIA_TYPE;
#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
};
#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 */
#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 */
#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);
#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 */
{
UINT32 maxRetries;
UINT32 numRetries = 0;
- xfContext* xfc = (xfContext*) instance->context;
rdpSettings* settings = instance->settings;
maxRetries = settings->AutoReconnectMaxRetries;
};
#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)
#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"
#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;
PTP_POOL ThreadPool;
TP_CALLBACK_ENVIRON ThreadPoolEnv;
-
+
wBufferPool* BufferPool;
/* profilers */
#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 */
#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 */
#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);
#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 */
#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
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)
{
}
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)
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;
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;
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
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)
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.");
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;
}
}
{
ret = wts_queue_receive_data(channel, Stream_Pointer(s), length);
}
+
return ret;
}
int cbChId;
UINT32 ChannelId;
rdpPeerChannel* dvc;
-
length = Stream_GetPosition(channel->receiveData);
if (length < 1)
Stream_SetPosition(channel->receiveData, 0);
Stream_Read_UINT8(channel->receiveData, value);
-
length--;
Cmd = (value & 0xf0) >> 4;
Sp = (value & 0x0c) >> 2;
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);
{
WLog_ERR(TAG, "received Cmd %d but channel is not ready.", Cmd);
}
+
return TRUE;
}
{
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;
if (!Stream_EnsureRemainingCapacity(channel->receiveData, size))
return FALSE;
+
Stream_Write(channel->receiveData, data, size);
if (flags & CHANNEL_FLAG_LAST)
{
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;
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)
}
#if 0
+
if (vcm->drdynvc_channel)
{
fd = GetEventWaitObject(vcm->drdynvc_channel->receiveEvent);
(*fds_count)++;
}
}
+
#endif
}
{
/* 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;
}
}
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;
}
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;
{
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];
}
}
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;
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)
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)
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;
}
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;
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;
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;
return TRUE;
}
-void* WTSChannelGetHandleByName(freerdp_peer* client, const char *channel_name)
+void* WTSChannelGetHandleByName(freerdp_peer* client, const char* channel_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;
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;
}
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;
}
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);
}
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:
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)
}
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)
if (WTSInfoClass == WTSSessionId)
{
ULONG* pBuffer;
-
BytesReturned = sizeof(ULONG);
pBuffer = (ULONG*) malloc(sizeof(BytesReturned));
+
if (!pBuffer)
{
SetLastError(E_OUTOFMEMORY);
}
*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;
}
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;
rdpPeerChannel* channel;
WTSVirtualChannelManager* vcm;
HANDLE hChannelHandle = NULL;
-
vcm = (WTSVirtualChannelManager*) hServer;
+
if (!vcm)
{
SetLastError(ERROR_INVALID_DATA);
client = vcm->client;
mcs = client->context->rdp->mcs;
-
length = strlen(pVirtualName);
+
if (length > 8)
{
SetLastError(ERROR_NOT_FOUND);
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;
}
channel = (rdpPeerChannel*) mcs->channels[index].handle;
+
if (!channel)
{
channel = (rdpPeerChannel*) calloc(1, sizeof(rdpPeerChannel));
+
if (!channel)
goto error_channel_alloc;
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;
hChannelHandle = (HANDLE) channel;
return hChannelHandle;
-
error_queue:
Stream_Free(channel->receiveData, TRUE);
error_receiveData:
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;
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;
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;
}
channel = (rdpPeerChannel*) calloc(1, sizeof(rdpPeerChannel));
+
if (!channel)
{
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
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)
{
}
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:
if (channel->dvc_open_state == DVC_OPEN_STATE_SUCCEEDED)
{
ULONG written;
-
s = Stream_New(NULL, 8);
+
if (!s)
{
WLog_ERR(TAG, "Stream_New failed!");
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);
}
-
}
}
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;
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)
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;
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;
while (Length > 0)
{
s = Stream_New(NULL, channel->client->settings->VirtualChannelChunkSize);
+
if (!s)
{
WLog_ERR(TAG, "Stream_New failed!");
}
buffer = Stream_Buffer(s);
-
Stream_Seek_UINT8(s);
cbChId = wts_write_variable_uint(s, channel->channelId);
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);
}
}
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;
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)
}
*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:
}
*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;
}
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;
}
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;
}
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;
}
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;
}
#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 */
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;
}
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);
#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 */
#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 */
#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
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;
{
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);
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)
}
}
-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;
}
}
-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);
move += 16;
/* Pipes */
MsPipes = MsInterface->MsPipes;
- for(pnum = 0; pnum < MsInterface->NumberOfPipes; pnum++)
+
+ for (pnum = 0; pnum < MsInterface->NumberOfPipes; pnum++)
{
MsPipe = MsPipes[pnum];
/* MaximumPacketSize */
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;
}
}
}
-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;
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);
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);
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];
WLog_INFO(TAG, " InitCompleted: %d", MsPipe->InitCompleted);
}
}
+
WLog_INFO(TAG, "==================================================");
}
#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;
}
void ringbuffer_destroy(RingBuffer* rb)
{
DEBUG_RINGBUFFER("ringbuffer_destroy(%p)", rb);
-
free(rb->buffer);
rb->buffer = NULL;
}
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)
* beginning of the buffer
*/
newData = (BYTE*) realloc(rb->buffer, targetSize);
-
+
if (!newData)
return FALSE;
-
+
rb->readPtr = rb->writePtr = 0;
rb->buffer = newData;
}
* [............|XXXXXXXXXXXXXX|..........]
*/
newData = (BYTE*) realloc(rb->buffer, targetSize);
-
+
if (!newData)
return FALSE;
* and the write head is set accordingly
*/
newData = (BYTE*) malloc(targetSize);
-
+
if (!newData)
return FALSE;
-
+
if (rb->readPtr < rb->writePtr)
{
/* readPtr writePtr
* [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);
rb->freeSize += (targetSize - rb->size);
rb->size = targetSize;
-
return TRUE;
}
{
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;
*/
toWrite = sz;
remaining = sz;
-
+
if (rb->size - rb->writePtr < sz)
toWrite = rb->size - rb->writePtr;
memcpy(rb->buffer, ptr, remaining);
rb->writePtr = (rb->writePtr + sz) % rb->size;
-
rb->freeSize -= sz;
return TRUE;
}
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;
}
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;
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);
}
#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);
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 wLogMessage* msg);
+typedef BOOL (*wLogCallbackData_t)(const wLogMessage* msg);
+typedef BOOL (*wLogCallbackImage_t)(const wLogMessage* msg);
+typedef BOOL (*wLogCallbackPackage_t)(const wLogMessage* msg);
-struct _wLogCallbacks {
+struct _wLogCallbacks
+{
wLogCallbackData_t data;
wLogCallbackImage_t image;
wLogCallbackMessage_t message;
#include "comm.h"
-static wLog *_Log = NULL;
+static wLog* _Log = NULL;
struct 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;
static int CommGetFd(HANDLE handle)
{
- WINPR_COMM *comm = (WINPR_COMM *)handle;
+ WINPR_COMM* comm = (WINPR_COMM*)handle;
if (!CommIsHandled(handle))
return -1;
return comm->fd;
}
-HANDLE_CREATOR *GetCommHandleCreator(void)
+HANDLE_CREATOR* GetCommHandleCreator(void)
{
_CommHandleCreator.IsHandled = IsCommDevice;
_CommHandleCreator.CreateFileA = CommCreateFileA;
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;
}
-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);
}
return FALSE;
/* TODO: not implemented */
-
CommLog_Print(WLOG_ERROR, "%s: Not implemented", __FUNCTION__);
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
return FALSE;
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;
return FALSE;
/* TODO: not implemented */
-
CommLog_Print(WLOG_ERROR, "%s: Not implemented", __FUNCTION__);
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
return FALSE;
return FALSE;
/* TODO: not implemented */
-
CommLog_Print(WLOG_ERROR, "%s: Not implemented", __FUNCTION__);
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
return FALSE;
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;
*/
BOOL GetCommState(HANDLE hFile, LPDCB lpDCB)
{
- DCB *lpLocalDcb;
+ DCB* lpLocalDcb;
struct termios currentState;
WINPR_COMM* pComm = (WINPR_COMM*) hFile;
DWORD bytesReturned;
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;
}
lpLocalDcb = (DCB*)calloc(1, lpDCB->DCBlength);
+
if (lpLocalDcb == NULL)
{
SetLastError(ERROR_OUTOFMEMORY);
}
/* 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)
{
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)
}
// 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;
}
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;
/* 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;
}
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));
handflow.ControlHandShake |= SERIAL_CTS_HANDSHAKE;
}
-
if (lpDCB->fOutxDsrFlow)
{
handflow.ControlHandShake |= SERIAL_DSR_HANDSHAKE;
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;
}
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;
}
}
/* 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;
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)
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
return FALSE;
}
-
return TRUE;
}
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;
/* 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;
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;
/* 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;
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;
return FALSE;
/* TODO: not implemented */
-
CommLog_Print(WLOG_ERROR, "%s: Not implemented", __FUNCTION__);
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
return FALSE;
return FALSE;
/* TODO: not implemented */
-
CommLog_Print(WLOG_ERROR, "%s: Not implemented", __FUNCTION__);
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
return FALSE;
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;
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;
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;
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;
}
/* 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;
}
/* FIXME: what about PRN ? */
-
return FALSE;
}
* 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;
}
storedDeviceName = _tcsdup(lpDeviceName);
+
if (storedDeviceName == NULL)
{
SetLastError(ERROR_OUTOFMEMORY);
}
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)
{
free(_CommDevices[i]->path);
_CommDevices[i]->name = storedDeviceName;
_CommDevices[i]->path = storedTargetPath;
-
break;
}
}
{
/* new emplacement */
_CommDevices[i] = (COMM_DEVICE*)calloc(1, sizeof(COMM_DEVICE));
+
if (_CommDevices[i] == NULL)
{
SetLastError(ERROR_OUTOFMEMORY);
LeaveCriticalSection(&_CommDevicesLock);
return TRUE;
-
-
error_handle:
free(storedDeviceName);
free(storedTargetPath);
-
LeaveCriticalSection(&_CommDevicesLock);
return FALSE;
}
{
int i;
LPTSTR storedTargetPath;
-
SetLastError(ERROR_SUCCESS);
if (!CommInitialized())
}
EnterCriticalSection(&_CommDevicesLock);
-
storedTargetPath = NULL;
- for (i=0; i<COMM_DEVICE_MAX; i++)
+
+ for (i = 0; i < COMM_DEVICE_MAX; i++)
{
if (_CommDevices[i] != NULL)
{
_tcscpy(lpTargetPath, storedTargetPath);
lpTargetPath[_tcslen(storedTargetPath) + 1] = '\0'; /* 2nd final '\0' */
-
return _tcslen(lpTargetPath) + 2;
}
pComm->serverSerialDriverId = driverId;
}
-static HANDLE_OPS ops = {
- CommIsHandled,
- CommCloseHandle,
- CommGetFd,
- NULL /* CleanupHandle */
+static HANDLE_OPS ops =
+{
+ CommIsHandled,
+ CommCloseHandle,
+ CommGetFd,
+ NULL /* CleanupHandle */
};
*
* @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;
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)
}
/* 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)
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)
}
pComm = (WINPR_COMM*) calloc(1, sizeof(WINPR_COMM));
+
if (pComm == NULL)
{
SetLastError(ERROR_OUTOFMEMORY);
}
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);
}
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);
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);
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;
}
return (HANDLE)pComm;
+error_handle:
-
- error_handle:
if (pComm != NULL)
{
CloseHandle(pComm);
}
-
return INVALID_HANDLE_VALUE;
}
BOOL CommIsHandled(HANDLE handle)
{
- WINPR_COMM *pComm;
+ WINPR_COMM* pComm;
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;
BOOL CommCloseHandle(HANDLE handle)
{
- WINPR_COMM *pComm;
+ WINPR_COMM* pComm;
if (!CommInitialized())
return FALSE;
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!");
}
close(pComm->fd_read_event);
free(pComm);
-
return TRUE;
}
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;
#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);
if (hDevice == INVALID_HANDLE_VALUE)
{
SetLastError(ERROR_INVALID_HANDLE);
- return FALSE;
- }
+ return FALSE;
+ }
if (!pComm || pComm->Type != HANDLE_TYPE_COMM)
{
else if (Ti > 25500)
return 255; /* 0xFF */
else
- return Ti/100;
+ return Ti / 100;
}
* 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;
+ COMMTIMEOUTS* pTimeouts;
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)
{
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;
}
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;
}
*
* 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;
}
{
/* 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;
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, ¤tTermios) < 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;
}
if (nbFds == 0)
{
/* timeout */
-
SetLastError(ERROR_TIMEOUT);
goto return_false;
}
-
/* read_set */
if (FD_ISSET(pComm->fd_read_event, &read_set))
}
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 ? */
}
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)
{
assert(FALSE);
*lpNumberOfBytesRead = 0;
-
- return_false:
+return_false:
LeaveCriticalSection(&pComm->ReadLock);
return FALSE;
-
- return_true:
+return_true:
LeaveCriticalSection(&pComm->ReadLock);
return TRUE;
}
* 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)
{
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;
}
* 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)
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;
}
if (nbFds == 0)
{
/* timeout */
-
SetLastError(ERROR_TIMEOUT);
goto return_false;
}
-
/* event_set */
if (FD_ISSET(pComm->fd_write_event, &event_set))
}
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 ? */
}
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)
{
*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
* 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;
}
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;
}
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;
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;
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;
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;
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;
}
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;
return FALSE;
g_Filters = tmp;
-
cp = (LPSTR)_strdup(filter);
+
if (!cp)
return FALSE;
do
{
p = strchr(p, ',');
+
if (p)
*p = '\0';
{
if (!WLog_ParseFilter(&g_Filters[pos++], filterStr))
{
- free (cp);
+ free(cp);
return FALSE;
}
}
while (p != NULL);
g_FilterCount = size;
- free (cp);
-
+ free(cp);
return TRUE;
}
int iLevel;
count = 1;
- if(!name)
+ if (!name)
return FALSE;
p = (char*) 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;
{
if (count < (int) filter->NameCount)
filter->Names[count++] = p + 1;
+
*p = '\0';
p++;
}
BOOL res;
char* env;
DWORD nSize;
-
g_Filters = NULL;
g_FilterCount = 0;
-
nSize = GetEnvironmentVariableA("WLOG_FILTER", NULL, 0);
if (nSize < 1)
return FALSE;
res = WLog_AddStringLogFilters(env);
-
free(env);
-
return res;
}
}
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;
{
if (count < (int) log->NameCount)
log->Names[count++] = p + 1;
+
*p = '\0';
p++;
}
char* env = NULL;
DWORD nSize;
int iLevel;
-
log = (wLog*) calloc(1, sizeof(wLog));
+
if (!log)
return NULL;
if (nSize)
{
env = (LPSTR) malloc(nSize);
+
if (!env)
goto out_fail;
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;
}
if (nSize)
{
env = (LPSTR) malloc(nSize);
+
if (!env)
goto fail;
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;
}
return g_RootLog;
-
fail:
free(g_RootLog);
g_RootLog = NULL;
{
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;
}
}
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;