WLog using C99 compatible variadic macros.
This commit is contained in:
parent
267dea928c
commit
943e295714
@ -33,9 +33,9 @@
|
||||
#define TAG CHANNELS_TAG("audin.client")
|
||||
|
||||
#ifdef WITH_DEBUG_DVC
|
||||
#define DEBUG_DVC(fmt, ...) WLog_DBG(TAG, fmt, ## __VA_ARGS__)
|
||||
#define DEBUG_DVC(...) WLog_DBG(TAG, __VA_ARGS__)
|
||||
#else
|
||||
#define DEBUG_DVC(fmt, ...) do { } while (0)
|
||||
#define DEBUG_DVC(...) do { } while (0)
|
||||
#endif
|
||||
|
||||
#endif /* FREERDP_AUDIN_CLIENT_MAIN_H */
|
||||
|
@ -55,9 +55,9 @@ typedef struct cliprdr_plugin cliprdrPlugin;
|
||||
CliprdrClientContext* cliprdr_get_client_interface(cliprdrPlugin* cliprdr);
|
||||
|
||||
#ifdef WITH_DEBUG_CLIPRDR
|
||||
#define DEBUG_CLIPRDR(fmt, ...) WLog_DBG(TAG, fmt, ## __VA_ARGS__)
|
||||
#define DEBUG_CLIPRDR(...) WLog_DBG(TAG, __VA_ARGS__)
|
||||
#else
|
||||
#define DEBUG_CLIPRDR(fmt, ...) do { } while (0)
|
||||
#define DEBUG_CLIPRDR(...) do { } while (0)
|
||||
#endif
|
||||
|
||||
#endif /* __CLIPRDR_MAIN_H */
|
||||
|
@ -31,9 +31,9 @@
|
||||
|
||||
#define DVC_TAG CHANNELS_TAG("echo.client")
|
||||
#ifdef WITH_DEBUG_DVC
|
||||
#define DEBUG_DVC(fmt, ...) WLog_DBG(DVC_TAG, fmt, ## __VA_ARGS__)
|
||||
#define DEBUG_DVC(...) WLog_DBG(DVC_TAG, __VA_ARGS__)
|
||||
#else
|
||||
#define DEBUG_DVC(fmt, ...) do { } while (0)
|
||||
#define DEBUG_DVC(...) do { } while (0)
|
||||
#endif
|
||||
|
||||
#endif /* __ECHO_MAIN_H */
|
||||
|
@ -26,9 +26,9 @@ rdpPrinterDriver* printer_win_get_driver(void);
|
||||
|
||||
#define PRINTER_TAG CHANNELS_TAG("printer.client")
|
||||
#ifdef WITH_DEBUG_WINPR
|
||||
#define DEBUG_WINPR(fmt, ...) WLog_DBG(PRINTER_TAG, fmt, ## __VA_ARGS__)
|
||||
#define DEBUG_WINPR(...) WLog_DBG(PRINTER_TAG, __VA_ARGS__)
|
||||
#else
|
||||
#define DEBUG_WINPR(fmt, ...) do { } while (0)
|
||||
#define DEBUG_WINPR(...) do { } while (0)
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
@ -82,9 +82,9 @@ struct _RDPINPUT_CONTACT_POINT
|
||||
typedef struct _RDPINPUT_CONTACT_POINT RDPINPUT_CONTACT_POINT;
|
||||
|
||||
#ifdef WITH_DEBUG_DVC
|
||||
#define DEBUG_DVC(fmt, ...) WLog_DBG(TAG, fmt, ## __VA_ARGS__)
|
||||
#define DEBUG_DVC(...) WLog_DBG(TAG, __VA_ARGS__)
|
||||
#else
|
||||
#define DEBUG_DVC(fmt, ...) do { } while (0)
|
||||
#define DEBUG_DVC(...) do { } while (0)
|
||||
#endif
|
||||
|
||||
#endif /* FREERDP_CHANNEL_RDPEI_CLIENT_MAIN_H */
|
||||
|
@ -30,9 +30,9 @@
|
||||
#define TAG CHANNELS_TAG("rdpsnd.client")
|
||||
|
||||
#if defined(WITH_DEBUG_SND)
|
||||
#define DEBUG_SND(fmt, ...) WLog_DBG(TAG, fmt, ## __VA_ARGS__)
|
||||
#define DEBUG_SND(...) WLog_DBG(TAG, __VA_ARGS__)
|
||||
#else
|
||||
#define DEBUG_SND(fmt, ...) do { } while (0)
|
||||
#define DEBUG_SND(...) do { } while (0)
|
||||
#endif
|
||||
|
||||
UINT rdpsnd_virtual_channel_write(rdpsndPlugin* rdpsnd, wStream* s);
|
||||
|
@ -31,9 +31,9 @@
|
||||
#define TAG CHANNELS_TAG("tsmf.client")
|
||||
|
||||
#ifdef WITH_DEBUG_TSMF
|
||||
#define DEBUG_TSMF(fmt, ...) WLog_DBG(TAG, fmt, ## __VA_ARGS__)
|
||||
#define DEBUG_TSMF(...) WLog_DBG(TAG, __VA_ARGS__)
|
||||
#else
|
||||
#define DEBUG_TSMF(fmt, ...) do { } while (0)
|
||||
#define DEBUG_TSMF(...) do { } while (0)
|
||||
#endif
|
||||
|
||||
typedef struct _TS_AM_MEDIA_TYPE
|
||||
@ -53,7 +53,7 @@ typedef struct _TS_AM_MEDIA_TYPE
|
||||
UINT32 Channels;
|
||||
UINT32 BitsPerSample;
|
||||
UINT32 BlockAlign;
|
||||
const BYTE *ExtraData;
|
||||
const BYTE* ExtraData;
|
||||
UINT32 ExtraDataSize;
|
||||
} TS_AM_MEDIA_TYPE;
|
||||
|
||||
|
@ -38,9 +38,9 @@
|
||||
|
||||
#define TAG CHANNELS_TAG("urbdrc.client")
|
||||
#ifdef WITH_DEBUG_DVC
|
||||
#define DEBUG_DVC(fmt, ...) WLog_DBG(TAG, fmt, ## __VA_ARGS__)
|
||||
#define DEBUG_DVC(...) WLog_DBG(TAG, __VA_ARGS__)
|
||||
#else
|
||||
#define DEBUG_DVC(fmt, ...) do { } while (0)
|
||||
#define DEBUG_DVC(...) do { } while (0)
|
||||
#endif
|
||||
|
||||
#define CAPABILITIES_NEGOTIATOR 0x00000000
|
||||
@ -109,25 +109,25 @@
|
||||
|
||||
enum device_text_type
|
||||
{
|
||||
DeviceTextDescription = 0,
|
||||
DeviceTextDescription = 0,
|
||||
DeviceTextLocationInformation = 1,
|
||||
};
|
||||
|
||||
enum device_descriptor_table
|
||||
{
|
||||
B_LENGTH = 0,
|
||||
B_DESCRIPTOR_TYPE = 1,
|
||||
BCD_USB = 2,
|
||||
B_LENGTH = 0,
|
||||
B_DESCRIPTOR_TYPE = 1,
|
||||
BCD_USB = 2,
|
||||
B_DEVICE_CLASS = 4,
|
||||
B_DEVICE_SUBCLASS = 5,
|
||||
B_DEVICE_SUBCLASS = 5,
|
||||
B_DEVICE_PROTOCOL = 6,
|
||||
B_MAX_PACKET_SIZE0 = 7,
|
||||
ID_VENDOR = 8,
|
||||
B_MAX_PACKET_SIZE0 = 7,
|
||||
ID_VENDOR = 8,
|
||||
ID_PRODUCT = 10,
|
||||
BCD_DEVICE = 12,
|
||||
BCD_DEVICE = 12,
|
||||
I_MANUFACTURER = 14,
|
||||
I_PRODUCT = 15,
|
||||
I_SERIAL_NUMBER = 16,
|
||||
I_PRODUCT = 15,
|
||||
I_SERIAL_NUMBER = 16,
|
||||
B_NUM_CONFIGURATIONS = 17
|
||||
};
|
||||
|
||||
@ -259,11 +259,11 @@ enum device_descriptor_table
|
||||
#define USBD_TRANSFER_DIRECTION_IN 1
|
||||
|
||||
#define VALID_TRANSFER_FLAGS_MASK USBD_SHORT_TRANSFER_OK | \
|
||||
USBD_TRANSFER_DIRECTION | \
|
||||
USBD_START_ISO_TRANSFER_ASAP | \
|
||||
USBD_DEFAULT_PIPE_TRANSFER)
|
||||
|
||||
#define ENDPOINT_HALT 0x00
|
||||
USBD_TRANSFER_DIRECTION | \
|
||||
USBD_START_ISO_TRANSFER_ASAP | \
|
||||
USBD_DEFAULT_PIPE_TRANSFER)
|
||||
|
||||
#define ENDPOINT_HALT 0x00
|
||||
#define DEVICE_REMOTE_WAKEUP 0x01
|
||||
|
||||
/* transfer type */
|
||||
@ -318,16 +318,16 @@ enum device_descriptor_table
|
||||
|
||||
#define LOG_LEVEL 1
|
||||
|
||||
#define dummy_wait_obj(void) do{ sleep(5); } while(0)
|
||||
#define dummy_wait_s_obj(_s) do{ sleep(_s); } while(0)
|
||||
#define dummy_wait_obj(void) do{ sleep(5); } while(0)
|
||||
#define dummy_wait_s_obj(_s) do{ sleep(_s); } while(0)
|
||||
|
||||
#define ISOCH_FIFO 1
|
||||
#define WAIT_COMPLETE_SLEEP 10000 /* for cpu high loading */
|
||||
|
||||
#define urbdrc_get_mstime(_t) do { \
|
||||
struct timeval _tp; \
|
||||
gettimeofday(&_tp, 0); \
|
||||
_t = (_tp.tv_sec * 1000) + (_tp.tv_usec / 1000); \
|
||||
} while (0)
|
||||
struct timeval _tp; \
|
||||
gettimeofday(&_tp, 0); \
|
||||
_t = (_tp.tv_sec * 1000) + (_tp.tv_usec / 1000); \
|
||||
} while (0)
|
||||
|
||||
#endif /* __URBDRC_TYPES_H */
|
||||
|
@ -48,9 +48,9 @@
|
||||
#define TAG CLIENT_TAG("windows")
|
||||
|
||||
#ifdef WITH_DEBUG_CLIPRDR
|
||||
#define DEBUG_CLIPRDR(fmt, ...) WLog_DBG(TAG, fmt, ## __VA_ARGS__)
|
||||
#define DEBUG_CLIPRDR(...) WLog_DBG(TAG, __VA_ARGS__)
|
||||
#else
|
||||
#define DEBUG_CLIPRDR(fmt, ...) do { } while (0)
|
||||
#define DEBUG_CLIPRDR(...) do { } while (0)
|
||||
#endif
|
||||
|
||||
typedef BOOL (WINAPI* fnAddClipboardFormatListener)(HWND hwnd);
|
||||
|
@ -33,9 +33,9 @@ void wf_event_focus_in(wfContext* wfc);
|
||||
|
||||
#define KBD_TAG CLIENT_TAG("windows")
|
||||
#ifdef WITH_DEBUG_KBD
|
||||
#define DEBUG_KBD(fmt, ...) WLog_DBG(KBD_TAG, fmt, ## __VA_ARGS__)
|
||||
#define DEBUG_KBD(...) WLog_DBG(KBD_TAG, __VA_ARGS__)
|
||||
#else
|
||||
#define DEBUG_KBD(fmt, ...) do { } while (0)
|
||||
#define DEBUG_KBD(...) do { } while (0)
|
||||
#endif
|
||||
|
||||
#endif /* __WF_EVENT_H */
|
||||
|
@ -1383,7 +1383,6 @@ static BOOL xf_auto_reconnect(freerdp* instance)
|
||||
{
|
||||
UINT32 maxRetries;
|
||||
UINT32 numRetries = 0;
|
||||
xfContext* xfc = (xfContext*) instance->context;
|
||||
rdpSettings* settings = instance->settings;
|
||||
maxRetries = settings->AutoReconnectMaxRetries;
|
||||
|
||||
|
@ -80,9 +80,9 @@ const char* const X11_EVENT_STRINGS[] =
|
||||
};
|
||||
|
||||
#ifdef WITH_DEBUG_X11
|
||||
#define DEBUG_X11(fmt, ...) WLog_DBG(TAG, fmt, ## __VA_ARGS__)
|
||||
#define DEBUG_X11(...) WLog_DBG(TAG, __VA_ARGS__)
|
||||
#else
|
||||
#define DEBUG_X11(fmt, ...) do { } while (0)
|
||||
#define DEBUG_X11(...) do { } while (0)
|
||||
#endif
|
||||
|
||||
BOOL xf_event_action_script_init(xfContext* xfc)
|
||||
|
@ -58,9 +58,9 @@
|
||||
#define TAG CLIENT_TAG("x11")
|
||||
|
||||
#ifdef WITH_DEBUG_X11
|
||||
#define DEBUG_X11(fmt, ...) WLog_DBG(TAG, fmt, ## __VA_ARGS__)
|
||||
#define DEBUG_X11(...) WLog_DBG(TAG, __VA_ARGS__)
|
||||
#else
|
||||
#define DEBUG_X11(fmt, ...) do { } while (0)
|
||||
#define DEBUG_X11(...) do { } while (0)
|
||||
#endif
|
||||
|
||||
#include "FreeRDP_Icon_256px.h"
|
||||
|
@ -34,9 +34,9 @@
|
||||
|
||||
#define RFX_TAG FREERDP_TAG("codec.rfx")
|
||||
#ifdef WITH_DEBUG_RFX
|
||||
#define DEBUG_RFX(fmt, ...) WLog_DBG(RFX_TAG, fmt, ## __VA_ARGS__)
|
||||
#define DEBUG_RFX(...) WLog_DBG(RFX_TAG, __VA_ARGS__)
|
||||
#else
|
||||
#define DEBUG_RFX(fmt, ...) do { } while (0)
|
||||
#define DEBUG_RFX(...) do { } while (0)
|
||||
#endif
|
||||
|
||||
typedef struct _RFX_TILE_COMPOSE_WORK_PARAM RFX_TILE_COMPOSE_WORK_PARAM;
|
||||
@ -55,7 +55,7 @@ struct _RFX_CONTEXT_PRIV
|
||||
|
||||
PTP_POOL ThreadPool;
|
||||
TP_CALLBACK_ENVIRON ThreadPoolEnv;
|
||||
|
||||
|
||||
wBufferPool* BufferPool;
|
||||
|
||||
/* profilers */
|
||||
|
@ -72,9 +72,9 @@ FREERDP_LOCAL void key_free(rdpRsaKey* key);
|
||||
|
||||
#define CERTIFICATE_TAG FREERDP_TAG("core.certificate")
|
||||
#ifdef WITH_DEBUG_CERTIFICATE
|
||||
#define DEBUG_CERTIFICATE(fmt, ...) WLog_DBG(CERTIFICATE_TAG, fmt, ## __VA_ARGS__)
|
||||
#define DEBUG_CERTIFICATE(...) WLog_DBG(CERTIFICATE_TAG, __VA_ARGS__)
|
||||
#else
|
||||
#define DEBUG_CERTIFICATE(fmt, ...) do { } while (0)
|
||||
#define DEBUG_CERTIFICATE(...) do { } while (0)
|
||||
#endif
|
||||
|
||||
#endif /* __CERTIFICATE_H */
|
||||
|
@ -252,9 +252,9 @@ FREERDP_LOCAL void license_free(rdpLicense* license);
|
||||
|
||||
#define LICENSE_TAG FREERDP_TAG("core.license")
|
||||
#ifdef WITH_DEBUG_LICENSE
|
||||
#define DEBUG_LICENSE(fmt, ...) WLog_DBG(LICENSE_TAG, fmt, ## __VA_ARGS__)
|
||||
#define DEBUG_LICENSE(...) WLog_DBG(LICENSE_TAG, __VA_ARGS__)
|
||||
#else
|
||||
#define DEBUG_LICENSE(fmt, ...) do { } while (0)
|
||||
#define DEBUG_LICENSE(...) do { } while (0)
|
||||
#endif
|
||||
|
||||
#endif /* __LICENSE_H */
|
||||
|
@ -241,9 +241,9 @@ FREERDP_LOCAL void rdp_free(rdpRdp* rdp);
|
||||
|
||||
#define RDP_TAG FREERDP_TAG("core.rdp")
|
||||
#ifdef WITH_DEBUG_RDP
|
||||
#define DEBUG_RDP(fmt, ...) WLog_DBG(RDP_TAG, fmt, ## __VA_ARGS__)
|
||||
#define DEBUG_RDP(...) WLog_DBG(RDP_TAG, __VA_ARGS__)
|
||||
#else
|
||||
#define DEBUG_RDP(fmt, ...) do { } while (0)
|
||||
#define DEBUG_RDP(...) do { } while (0)
|
||||
#endif
|
||||
|
||||
BOOL rdp_decrypt(rdpRdp* rdp, wStream* s, int length, UINT16 securityFlags);
|
||||
|
@ -60,9 +60,9 @@ FREERDP_LOCAL void redirection_free(rdpRedirection* redirection);
|
||||
|
||||
#define REDIR_TAG FREERDP_TAG("core.redirection")
|
||||
#ifdef WITH_DEBUG_REDIR
|
||||
#define DEBUG_REDIR(fmt, ...) WLog_DBG(REDIR_TAG, fmt, ## __VA_ARGS__)
|
||||
#define DEBUG_REDIR(...) WLog_DBG(REDIR_TAG, __VA_ARGS__)
|
||||
#else
|
||||
#define DEBUG_REDIR(fmt, ...) do { } while (0)
|
||||
#define DEBUG_REDIR(...) do { } while (0)
|
||||
#endif
|
||||
|
||||
#endif /* __REDIRECTION_H */
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -38,9 +38,9 @@ FREERDP_LOCAL BOOL rdp_write_client_time_zone(wStream* s,
|
||||
|
||||
#define TIMEZONE_TAG FREERDP_TAG("core.timezone")
|
||||
#ifdef WITH_DEBUG_TIMEZONE
|
||||
#define DEBUG_TIMEZONE(fmt, ...) WLog_DBG(TIMEZONE_TAG, fmt, ## __VA_ARGS__)
|
||||
#define DEBUG_TIMEZONE(...) WLog_DBG(TIMEZONE_TAG, __VA_ARGS__)
|
||||
#else
|
||||
#define DEBUG_TIMEZONE(fmt, ...) do { } while (0)
|
||||
#define DEBUG_TIMEZONE(...) do { } while (0)
|
||||
#endif
|
||||
|
||||
#endif /* __TIMEZONE_H */
|
||||
|
@ -382,26 +382,23 @@ static void transport_bio_error_log(LPCSTR tag, LPCSTR biofunc, BIO* bio,
|
||||
wLog* log;
|
||||
wLogMessage log_message;
|
||||
int saveerrno;
|
||||
DWORD level;
|
||||
saveerrno = errno;
|
||||
log = WLog_Get(tag);
|
||||
|
||||
if (!log)
|
||||
return;
|
||||
|
||||
log_message.Level = WLOG_ERROR;
|
||||
level = WLOG_ERROR;
|
||||
|
||||
if (log_message.Level < WLog_GetLogLevel(log))
|
||||
if (level < WLog_GetLogLevel(log))
|
||||
return;
|
||||
|
||||
log_message.Type = WLOG_MESSAGE_TEXT;
|
||||
log_message.LineNumber = line;
|
||||
log_message.FileName = file;
|
||||
log_message.FunctionName = func;
|
||||
|
||||
if (ERR_peek_error() == 0)
|
||||
{
|
||||
log_message.FormatString = "%s returned a system error %d: %s";
|
||||
WLog_PrintMessage(log, &log_message, biofunc, saveerrno, strerror(saveerrno));
|
||||
const char* fmt = "%s returned a system error %d: %s";
|
||||
WLog_PrintMessage(log, WLOG_MESSAGE_TEXT, level, line, file, func, fmt, biofunc,
|
||||
saveerrno, strerror(saveerrno));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -409,11 +406,13 @@ static void transport_bio_error_log(LPCSTR tag, LPCSTR biofunc, BIO* bio,
|
||||
|
||||
if (buf)
|
||||
{
|
||||
const char* fmt = "%s returned an error: %s";
|
||||
|
||||
while ((sslerr = ERR_get_error()))
|
||||
{
|
||||
ERR_error_string_n(sslerr, buf, 120);
|
||||
log_message.FormatString = "%s returned an error: %s";
|
||||
WLog_PrintMessage(log, &log_message, biofunc, buf);
|
||||
WLog_PrintMessage(log, WLOG_MESSAGE_TEXT, level, line, file, func, fmt, biofunc,
|
||||
buf);
|
||||
}
|
||||
|
||||
free(buf);
|
||||
|
@ -32,9 +32,9 @@ FREERDP_LOCAL BOOL update_recv_altsec_window_order(rdpUpdate* update,
|
||||
|
||||
#define WND_TAG FREERDP_TAG("core.wnd")
|
||||
#ifdef WITH_DEBUG_WND
|
||||
#define DEBUG_WND(fmt, ...) WLog_DBG(WND_TAG, fmt, ## __VA_ARGS__)
|
||||
#define DEBUG_WND(...) WLog_DBG(WND_TAG, __VA_ARGS__)
|
||||
#else
|
||||
#define DEBUG_WND(fmt, ...) do { } while (0)
|
||||
#define DEBUG_WND(...) do { } while (0)
|
||||
#endif
|
||||
|
||||
#endif /* __WINDOW_H */
|
||||
|
@ -28,16 +28,16 @@
|
||||
|
||||
#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 */
|
||||
|
@ -28,9 +28,9 @@
|
||||
#define TAG FREERDP_TAG("utils")
|
||||
|
||||
#ifdef WITH_DEBUG_MSUSB
|
||||
#define DEBUG_MSUSB(fmt, ...) WLog_DBG(TAG, fmt, ## __VA_ARGS__)
|
||||
#define DEBUG_MSUSB(...) WLog_DBG(TAG, __VA_ARGS__)
|
||||
#else
|
||||
#define DEBUG_MSUSB(fmt, ...) do { } while (0)
|
||||
#define DEBUG_MSUSB(...) do { } while (0)
|
||||
#endif
|
||||
|
||||
|
||||
@ -39,7 +39,8 @@ static MSUSB_PIPE_DESCRIPTOR* msusb_mspipe_new()
|
||||
return (MSUSB_PIPE_DESCRIPTOR*) calloc(1, sizeof(MSUSB_PIPE_DESCRIPTOR));
|
||||
}
|
||||
|
||||
static void msusb_mspipes_free(MSUSB_PIPE_DESCRIPTOR** MsPipes, UINT32 NumberOfPipes)
|
||||
static void msusb_mspipes_free(MSUSB_PIPE_DESCRIPTOR** MsPipes,
|
||||
UINT32 NumberOfPipes)
|
||||
{
|
||||
int pnum = 0;
|
||||
|
||||
@ -47,13 +48,15 @@ static void msusb_mspipes_free(MSUSB_PIPE_DESCRIPTOR** MsPipes, UINT32 NumberOfP
|
||||
{
|
||||
for (pnum = 0; pnum < NumberOfPipes && MsPipes[pnum]; pnum++)
|
||||
{
|
||||
zfree(MsPipes[pnum]);
|
||||
zfree(MsPipes[pnum]);
|
||||
}
|
||||
|
||||
zfree(MsPipes);
|
||||
}
|
||||
}
|
||||
|
||||
void msusb_mspipes_replace(MSUSB_INTERFACE_DESCRIPTOR* MsInterface, MSUSB_PIPE_DESCRIPTOR** NewMsPipes, UINT32 NewNumberOfPipes)
|
||||
void msusb_mspipes_replace(MSUSB_INTERFACE_DESCRIPTOR* MsInterface,
|
||||
MSUSB_PIPE_DESCRIPTOR** NewMsPipes, UINT32 NewNumberOfPipes)
|
||||
{
|
||||
/* free orignal MsPipes */
|
||||
msusb_mspipes_free(MsInterface->MsPipes, MsInterface->NumberOfPipes);
|
||||
@ -62,51 +65,55 @@ void msusb_mspipes_replace(MSUSB_INTERFACE_DESCRIPTOR* MsInterface, MSUSB_PIPE_D
|
||||
MsInterface->NumberOfPipes = NewNumberOfPipes;
|
||||
}
|
||||
|
||||
static MSUSB_PIPE_DESCRIPTOR** msusb_mspipes_read(BYTE* data, UINT32 data_size, UINT32 NumberOfPipes, int* offset)
|
||||
static MSUSB_PIPE_DESCRIPTOR** msusb_mspipes_read(BYTE* data, UINT32 data_size,
|
||||
UINT32 NumberOfPipes, int* offset)
|
||||
{
|
||||
int pnum, move = 0;
|
||||
MSUSB_PIPE_DESCRIPTOR** MsPipes;
|
||||
|
||||
MsPipes = (MSUSB_PIPE_DESCRIPTOR**) calloc(NumberOfPipes, sizeof(MSUSB_PIPE_DESCRIPTOR*));
|
||||
MsPipes = (MSUSB_PIPE_DESCRIPTOR**) calloc(NumberOfPipes,
|
||||
sizeof(MSUSB_PIPE_DESCRIPTOR*));
|
||||
|
||||
if (!MsPipes)
|
||||
return NULL;
|
||||
|
||||
|
||||
for (pnum = 0; pnum < NumberOfPipes; pnum++)
|
||||
{
|
||||
MSUSB_PIPE_DESCRIPTOR *MsPipe = msusb_mspipe_new();
|
||||
MSUSB_PIPE_DESCRIPTOR* MsPipe = msusb_mspipe_new();
|
||||
|
||||
if (!MsPipe)
|
||||
goto out_error;
|
||||
|
||||
|
||||
data_read_UINT16(data + move, MsPipe->MaximumPacketSize);
|
||||
data_read_UINT32(data + move + 4, MsPipe->MaximumTransferSize);
|
||||
data_read_UINT32(data + move + 8, MsPipe->PipeFlags);
|
||||
move += 12;
|
||||
/* Already set to zero by memset
|
||||
MsPipe->PipeHandle = 0;
|
||||
MsPipe->bEndpointAddress = 0;
|
||||
MsPipe->bInterval = 0;
|
||||
MsPipe->PipeType = 0;
|
||||
MsPipe->InitCompleted = 0;
|
||||
*/
|
||||
|
||||
/* Already set to zero by memset
|
||||
MsPipe->PipeHandle = 0;
|
||||
MsPipe->bEndpointAddress = 0;
|
||||
MsPipe->bInterval = 0;
|
||||
MsPipe->PipeType = 0;
|
||||
MsPipe->InitCompleted = 0;
|
||||
*/
|
||||
MsPipes[pnum] = MsPipe;
|
||||
}
|
||||
*offset += move;
|
||||
|
||||
return MsPipes;
|
||||
}
|
||||
|
||||
*offset += move;
|
||||
return MsPipes;
|
||||
out_error:
|
||||
|
||||
for (pnum = 0; pnum < NumberOfPipes; pnum++)
|
||||
{
|
||||
free(MsPipes[pnum]);
|
||||
}
|
||||
|
||||
free(MsPipes);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static MSUSB_INTERFACE_DESCRIPTOR* msusb_msinterface_new()
|
||||
{
|
||||
return (MSUSB_INTERFACE_DESCRIPTOR*) calloc(1, sizeof(MSUSB_INTERFACE_DESCRIPTOR));
|
||||
return (MSUSB_INTERFACE_DESCRIPTOR*) calloc(1,
|
||||
sizeof(MSUSB_INTERFACE_DESCRIPTOR));
|
||||
}
|
||||
|
||||
static void msusb_msinterface_free(MSUSB_INTERFACE_DESCRIPTOR* MsInterface)
|
||||
@ -119,7 +126,8 @@ static void msusb_msinterface_free(MSUSB_INTERFACE_DESCRIPTOR* MsInterface)
|
||||
}
|
||||
}
|
||||
|
||||
static void msusb_msinterface_free_list(MSUSB_INTERFACE_DESCRIPTOR** MsInterfaces, UINT32 NumInterfaces)
|
||||
static void msusb_msinterface_free_list(MSUSB_INTERFACE_DESCRIPTOR**
|
||||
MsInterfaces, UINT32 NumInterfaces)
|
||||
{
|
||||
int inum = 0;
|
||||
|
||||
@ -134,68 +142,70 @@ static void msusb_msinterface_free_list(MSUSB_INTERFACE_DESCRIPTOR** MsInterface
|
||||
}
|
||||
}
|
||||
|
||||
void msusb_msinterface_replace(MSUSB_CONFIG_DESCRIPTOR* MsConfig, BYTE InterfaceNumber, MSUSB_INTERFACE_DESCRIPTOR* NewMsInterface)
|
||||
void msusb_msinterface_replace(MSUSB_CONFIG_DESCRIPTOR* MsConfig,
|
||||
BYTE InterfaceNumber, MSUSB_INTERFACE_DESCRIPTOR* NewMsInterface)
|
||||
{
|
||||
msusb_msinterface_free(MsConfig->MsInterfaces[InterfaceNumber]);
|
||||
MsConfig->MsInterfaces[InterfaceNumber] = NewMsInterface;
|
||||
MsConfig->MsInterfaces[InterfaceNumber] = NewMsInterface;
|
||||
}
|
||||
|
||||
MSUSB_INTERFACE_DESCRIPTOR* msusb_msinterface_read(BYTE* data, UINT32 data_size, int* offset)
|
||||
MSUSB_INTERFACE_DESCRIPTOR* msusb_msinterface_read(BYTE* data, UINT32 data_size,
|
||||
int* offset)
|
||||
{
|
||||
MSUSB_INTERFACE_DESCRIPTOR* MsInterface;
|
||||
|
||||
MsInterface = msusb_msinterface_new();
|
||||
|
||||
if (!MsInterface)
|
||||
return NULL;
|
||||
|
||||
|
||||
data_read_UINT16(data, MsInterface->Length);
|
||||
data_read_UINT16(data + 2, MsInterface->NumberOfPipesExpected);
|
||||
data_read_BYTE(data + 4, MsInterface->InterfaceNumber);
|
||||
data_read_BYTE(data + 5, MsInterface->AlternateSetting);
|
||||
data_read_UINT32(data + 8, MsInterface->NumberOfPipes);
|
||||
*offset += 12;
|
||||
|
||||
MsInterface->InterfaceHandle = 0;
|
||||
MsInterface->bInterfaceClass = 0;
|
||||
MsInterface->bInterfaceSubClass = 0;
|
||||
MsInterface->bInterfaceProtocol = 0;
|
||||
MsInterface->InitCompleted = 0;
|
||||
MsInterface->MsPipes = NULL;
|
||||
|
||||
|
||||
if (MsInterface->NumberOfPipes > 0)
|
||||
{
|
||||
MsInterface->MsPipes =
|
||||
msusb_mspipes_read(data+(*offset), data_size-(*offset), MsInterface->NumberOfPipes, offset);
|
||||
MsInterface->MsPipes =
|
||||
msusb_mspipes_read(data + (*offset), data_size - (*offset),
|
||||
MsInterface->NumberOfPipes, offset);
|
||||
|
||||
if (!MsInterface->MsPipes)
|
||||
goto out_error;
|
||||
}
|
||||
|
||||
return MsInterface;
|
||||
|
||||
return MsInterface;
|
||||
out_error:
|
||||
msusb_msinterface_free(MsInterface);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int msusb_msinterface_write(MSUSB_INTERFACE_DESCRIPTOR* MsInterface, BYTE* data, int* offset)
|
||||
int msusb_msinterface_write(MSUSB_INTERFACE_DESCRIPTOR* MsInterface, BYTE* data,
|
||||
int* offset)
|
||||
{
|
||||
MSUSB_PIPE_DESCRIPTOR ** MsPipes;
|
||||
MSUSB_PIPE_DESCRIPTOR * MsPipe;
|
||||
MSUSB_PIPE_DESCRIPTOR** MsPipes;
|
||||
MSUSB_PIPE_DESCRIPTOR* MsPipe;
|
||||
int pnum = 0, move = 0;
|
||||
|
||||
/* Length */
|
||||
data_write_UINT16(data, MsInterface->Length);
|
||||
data_write_UINT16(data, MsInterface->Length);
|
||||
/* InterfaceNumber */
|
||||
data_write_BYTE(data + 2, MsInterface->InterfaceNumber);
|
||||
data_write_BYTE(data + 2, MsInterface->InterfaceNumber);
|
||||
/* AlternateSetting */
|
||||
data_write_BYTE(data + 3, MsInterface->AlternateSetting);
|
||||
data_write_BYTE(data + 3, MsInterface->AlternateSetting);
|
||||
/* bInterfaceClass */
|
||||
data_write_BYTE(data + 4, MsInterface->bInterfaceClass);
|
||||
data_write_BYTE(data + 4, MsInterface->bInterfaceClass);
|
||||
/* bInterfaceSubClass */
|
||||
data_write_BYTE(data + 5, MsInterface->bInterfaceSubClass);
|
||||
data_write_BYTE(data + 5, MsInterface->bInterfaceSubClass);
|
||||
/* bInterfaceProtocol */
|
||||
data_write_BYTE(data + 6, MsInterface->bInterfaceProtocol);
|
||||
/* Padding */
|
||||
/* Padding */
|
||||
data_write_BYTE(data + 7, 0);
|
||||
/* InterfaceHandle */
|
||||
data_write_UINT32(data + 8, MsInterface->InterfaceHandle);
|
||||
@ -204,7 +214,8 @@ int msusb_msinterface_write(MSUSB_INTERFACE_DESCRIPTOR* MsInterface, BYTE* data,
|
||||
move += 16;
|
||||
/* Pipes */
|
||||
MsPipes = MsInterface->MsPipes;
|
||||
for(pnum = 0; pnum < MsInterface->NumberOfPipes; pnum++)
|
||||
|
||||
for (pnum = 0; pnum < MsInterface->NumberOfPipes; pnum++)
|
||||
{
|
||||
MsPipe = MsPipes[pnum];
|
||||
/* MaximumPacketSize */
|
||||
@ -221,55 +232,53 @@ int msusb_msinterface_write(MSUSB_INTERFACE_DESCRIPTOR* MsInterface, BYTE* data,
|
||||
data_write_UINT32(data + move + 12, MsPipe->MaximumTransferSize);
|
||||
/* PipeFlags */
|
||||
data_write_UINT32(data + move + 16, MsPipe->PipeFlags);
|
||||
|
||||
move += 20;
|
||||
}
|
||||
|
||||
|
||||
*offset += move;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static MSUSB_INTERFACE_DESCRIPTOR** msusb_msinterface_read_list(BYTE * data, UINT32 data_size, UINT32 NumInterfaces)
|
||||
static MSUSB_INTERFACE_DESCRIPTOR** msusb_msinterface_read_list(BYTE* data,
|
||||
UINT32 data_size, UINT32 NumInterfaces)
|
||||
{
|
||||
int inum, offset = 0;
|
||||
MSUSB_INTERFACE_DESCRIPTOR** MsInterfaces;
|
||||
|
||||
MsInterfaces = (MSUSB_INTERFACE_DESCRIPTOR**) calloc(NumInterfaces, sizeof(MSUSB_INTERFACE_DESCRIPTOR*));
|
||||
MsInterfaces = (MSUSB_INTERFACE_DESCRIPTOR**) calloc(NumInterfaces,
|
||||
sizeof(MSUSB_INTERFACE_DESCRIPTOR*));
|
||||
|
||||
if (!MsInterfaces)
|
||||
return NULL;
|
||||
|
||||
|
||||
for (inum = 0; inum < NumInterfaces; inum++)
|
||||
{
|
||||
MsInterfaces[inum] = msusb_msinterface_read(data + offset, data_size - offset, &offset);
|
||||
}
|
||||
|
||||
MsInterfaces[inum] = msusb_msinterface_read(data + offset, data_size - offset,
|
||||
&offset);
|
||||
}
|
||||
|
||||
return MsInterfaces;
|
||||
}
|
||||
|
||||
int msusb_msconfig_write(MSUSB_CONFIG_DESCRIPTOR* MsConfg, BYTE* data, int* offset)
|
||||
int msusb_msconfig_write(MSUSB_CONFIG_DESCRIPTOR* MsConfg, BYTE* data,
|
||||
int* offset)
|
||||
{
|
||||
int inum = 0;
|
||||
MSUSB_INTERFACE_DESCRIPTOR** MsInterfaces;
|
||||
MSUSB_INTERFACE_DESCRIPTOR* MsInterface;
|
||||
|
||||
/* ConfigurationHandle*/
|
||||
data_write_UINT32(data + *offset, MsConfg->ConfigurationHandle);
|
||||
|
||||
/* NumInterfaces*/
|
||||
data_write_UINT32(data + *offset + 4, MsConfg->NumInterfaces);
|
||||
data_write_UINT32(data + *offset + 4, MsConfg->NumInterfaces);
|
||||
*offset += 8;
|
||||
|
||||
/* Interfaces */
|
||||
|
||||
MsInterfaces = MsConfg->MsInterfaces;
|
||||
|
||||
for(inum = 0; inum < MsConfg->NumInterfaces; inum++)
|
||||
for (inum = 0; inum < MsConfg->NumInterfaces; inum++)
|
||||
{
|
||||
MsInterface = MsInterfaces[inum];
|
||||
msusb_msinterface_write(MsInterface, data + (*offset), offset);
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -288,16 +297,16 @@ void msusb_msconfig_free(MSUSB_CONFIG_DESCRIPTOR* MsConfig)
|
||||
}
|
||||
}
|
||||
|
||||
MSUSB_CONFIG_DESCRIPTOR* msusb_msconfig_read(BYTE* data, UINT32 data_size, UINT32 NumInterfaces)
|
||||
MSUSB_CONFIG_DESCRIPTOR* msusb_msconfig_read(BYTE* data, UINT32 data_size,
|
||||
UINT32 NumInterfaces)
|
||||
{
|
||||
int i, offset = 0;
|
||||
UINT16 lenInterface;
|
||||
MSUSB_CONFIG_DESCRIPTOR* MsConfig;
|
||||
BYTE lenConfiguration, typeConfiguration;
|
||||
|
||||
MsConfig = msusb_msconfig_new();
|
||||
|
||||
for(i = 0; i < NumInterfaces; i++)
|
||||
|
||||
for (i = 0; i < NumInterfaces; i++)
|
||||
{
|
||||
data_read_UINT16(data + offset, lenInterface);
|
||||
offset += lenInterface;
|
||||
@ -309,33 +318,33 @@ MSUSB_CONFIG_DESCRIPTOR* msusb_msconfig_read(BYTE* data, UINT32 data_size, UINT3
|
||||
if (lenConfiguration != 0x9 || typeConfiguration != 0x2)
|
||||
{
|
||||
DEBUG_MSUSB("%s: len and type must be 0x9 and 0x2 , but it is 0x%x and 0x%x",
|
||||
lenConfiguration, typeConfiguration);
|
||||
lenConfiguration, typeConfiguration);
|
||||
}
|
||||
|
||||
data_read_UINT16(data + offset + 2, MsConfig->wTotalLength);
|
||||
data_read_BYTE(data + offset + 5, MsConfig->bConfigurationValue);
|
||||
|
||||
MsConfig->NumInterfaces = NumInterfaces;
|
||||
MsConfig->ConfigurationHandle = 0;
|
||||
MsConfig->InitCompleted = 0;
|
||||
MsConfig->MsOutSize = 0;
|
||||
MsConfig->MsInterfaces = NULL;
|
||||
offset = 0;
|
||||
|
||||
|
||||
if (NumInterfaces > 0)
|
||||
{
|
||||
MsConfig->MsInterfaces = msusb_msinterface_read_list(data, data_size, NumInterfaces);
|
||||
MsConfig->MsInterfaces = msusb_msinterface_read_list(data, data_size,
|
||||
NumInterfaces);
|
||||
}
|
||||
|
||||
|
||||
return MsConfig;
|
||||
}
|
||||
|
||||
void msusb_msconfig_dump(MSUSB_CONFIG_DESCRIPTOR* MsConfig)
|
||||
{
|
||||
MSUSB_INTERFACE_DESCRIPTOR ** MsInterfaces;
|
||||
MSUSB_INTERFACE_DESCRIPTOR * MsInterface;
|
||||
MSUSB_PIPE_DESCRIPTOR ** MsPipes;
|
||||
MSUSB_PIPE_DESCRIPTOR * MsPipe;
|
||||
MSUSB_INTERFACE_DESCRIPTOR** MsInterfaces;
|
||||
MSUSB_INTERFACE_DESCRIPTOR* MsInterface;
|
||||
MSUSB_PIPE_DESCRIPTOR** MsPipes;
|
||||
MSUSB_PIPE_DESCRIPTOR* MsPipe;
|
||||
int inum = 0, pnum = 0;
|
||||
WLog_INFO(TAG, "=================MsConfig:========================");
|
||||
WLog_INFO(TAG, "wTotalLength:%d", MsConfig->wTotalLength);
|
||||
@ -345,12 +354,14 @@ void msusb_msconfig_dump(MSUSB_CONFIG_DESCRIPTOR* MsConfig)
|
||||
WLog_INFO(TAG, "MsOutSize:%d", MsConfig->MsOutSize);
|
||||
WLog_INFO(TAG, "NumInterfaces:%d", MsConfig->NumInterfaces);
|
||||
MsInterfaces = MsConfig->MsInterfaces;
|
||||
for(inum = 0; inum < MsConfig->NumInterfaces; inum++)
|
||||
|
||||
for (inum = 0; inum < MsConfig->NumInterfaces; inum++)
|
||||
{
|
||||
MsInterface = MsInterfaces[inum];
|
||||
WLog_INFO(TAG, " Interfase: %d", MsInterface->InterfaceNumber);
|
||||
WLog_INFO(TAG, " Length: %d", MsInterface->Length);
|
||||
WLog_INFO(TAG, " NumberOfPipesExpected: %d", MsInterface->NumberOfPipesExpected);
|
||||
WLog_INFO(TAG, " NumberOfPipesExpected: %d",
|
||||
MsInterface->NumberOfPipesExpected);
|
||||
WLog_INFO(TAG, " AlternateSetting: %d", MsInterface->AlternateSetting);
|
||||
WLog_INFO(TAG, " NumberOfPipes: %d", MsInterface->NumberOfPipes);
|
||||
WLog_INFO(TAG, " InterfaceHandle: 0x%x", MsInterface->InterfaceHandle);
|
||||
@ -359,6 +370,7 @@ void msusb_msconfig_dump(MSUSB_CONFIG_DESCRIPTOR* MsConfig)
|
||||
WLog_INFO(TAG, " bInterfaceProtocol: 0x%x", MsInterface->bInterfaceProtocol);
|
||||
WLog_INFO(TAG, " InitCompleted: %d", MsInterface->InitCompleted);
|
||||
MsPipes = MsInterface->MsPipes;
|
||||
|
||||
for (pnum = 0; pnum < MsInterface->NumberOfPipes; pnum++)
|
||||
{
|
||||
MsPipe = MsPipes[pnum];
|
||||
@ -373,5 +385,6 @@ void msusb_msconfig_dump(MSUSB_CONFIG_DESCRIPTOR* MsConfig)
|
||||
WLog_INFO(TAG, " InitCompleted: %d", MsPipe->InitCompleted);
|
||||
}
|
||||
}
|
||||
|
||||
WLog_INFO(TAG, "==================================================");
|
||||
}
|
||||
|
@ -33,23 +33,21 @@
|
||||
#define TAG FREERDP_TAG("utils.ringbuffer")
|
||||
|
||||
#ifdef WITH_DEBUG_RINGBUFFER
|
||||
#define DEBUG_RINGBUFFER(fmt, ...) WLog_DBG(TAG, fmt, ## __VA_ARGS__)
|
||||
#define DEBUG_RINGBUFFER(...) WLog_DBG(TAG, __VA_ARGS__)
|
||||
#else
|
||||
#define DEBUG_RINGBUFFER(fmt, ...) do { } while (0)
|
||||
#define DEBUG_RINGBUFFER(...) do { } while (0)
|
||||
#endif
|
||||
|
||||
BOOL ringbuffer_init(RingBuffer* rb, size_t initialSize)
|
||||
{
|
||||
rb->buffer = malloc(initialSize);
|
||||
|
||||
|
||||
if (!rb->buffer)
|
||||
return FALSE;
|
||||
|
||||
rb->readPtr = rb->writePtr = 0;
|
||||
rb->initialSize = rb->size = rb->freeSize = initialSize;
|
||||
|
||||
DEBUG_RINGBUFFER("ringbuffer_init(%p)", rb);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@ -66,7 +64,6 @@ size_t ringbuffer_capacity(const RingBuffer* rb)
|
||||
void ringbuffer_destroy(RingBuffer* rb)
|
||||
{
|
||||
DEBUG_RINGBUFFER("ringbuffer_destroy(%p)", rb);
|
||||
|
||||
free(rb->buffer);
|
||||
rb->buffer = NULL;
|
||||
}
|
||||
@ -74,7 +71,6 @@ void ringbuffer_destroy(RingBuffer* rb)
|
||||
static BOOL ringbuffer_realloc(RingBuffer* rb, size_t targetSize)
|
||||
{
|
||||
BYTE* newData;
|
||||
|
||||
DEBUG_RINGBUFFER("ringbuffer_realloc(%p): targetSize: %d", rb, targetSize);
|
||||
|
||||
if (rb->writePtr == rb->readPtr)
|
||||
@ -83,10 +79,10 @@ static BOOL ringbuffer_realloc(RingBuffer* rb, size_t targetSize)
|
||||
* beginning of the buffer
|
||||
*/
|
||||
newData = (BYTE*) realloc(rb->buffer, targetSize);
|
||||
|
||||
|
||||
if (!newData)
|
||||
return FALSE;
|
||||
|
||||
|
||||
rb->readPtr = rb->writePtr = 0;
|
||||
rb->buffer = newData;
|
||||
}
|
||||
@ -101,7 +97,7 @@ static BOOL ringbuffer_realloc(RingBuffer* rb, size_t targetSize)
|
||||
* [............|XXXXXXXXXXXXXX|..........]
|
||||
*/
|
||||
newData = (BYTE*) realloc(rb->buffer, targetSize);
|
||||
|
||||
|
||||
if (!newData)
|
||||
return FALSE;
|
||||
|
||||
@ -113,10 +109,10 @@ static BOOL ringbuffer_realloc(RingBuffer* rb, size_t targetSize)
|
||||
* and the write head is set accordingly
|
||||
*/
|
||||
newData = (BYTE*) malloc(targetSize);
|
||||
|
||||
|
||||
if (!newData)
|
||||
return FALSE;
|
||||
|
||||
|
||||
if (rb->readPtr < rb->writePtr)
|
||||
{
|
||||
/* readPtr writePtr
|
||||
@ -134,14 +130,13 @@ static BOOL ringbuffer_realloc(RingBuffer* rb, size_t targetSize)
|
||||
* [XXXXXXXXXXXX|..............|XXXXXXXXXX]
|
||||
*/
|
||||
BYTE* dst = newData;
|
||||
|
||||
memcpy(dst, rb->buffer + rb->readPtr, rb->size - rb->readPtr);
|
||||
dst += (rb->size - rb->readPtr);
|
||||
|
||||
|
||||
if (rb->writePtr)
|
||||
memcpy(dst, rb->buffer, rb->writePtr);
|
||||
}
|
||||
|
||||
|
||||
rb->writePtr = rb->size - rb->freeSize;
|
||||
rb->readPtr = 0;
|
||||
free(rb->buffer);
|
||||
@ -150,7 +145,6 @@ static BOOL ringbuffer_realloc(RingBuffer* rb, size_t targetSize)
|
||||
|
||||
rb->freeSize += (targetSize - rb->size);
|
||||
rb->size = targetSize;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@ -165,9 +159,8 @@ BOOL ringbuffer_write(RingBuffer* rb, const BYTE* ptr, size_t sz)
|
||||
{
|
||||
size_t toWrite;
|
||||
size_t remaining;
|
||||
|
||||
DEBUG_RINGBUFFER("ringbuffer_write(%p): sz: %d", rb, sz);
|
||||
|
||||
|
||||
if ((rb->freeSize <= sz) && !ringbuffer_realloc(rb, rb->size + sz))
|
||||
return FALSE;
|
||||
|
||||
@ -179,7 +172,7 @@ BOOL ringbuffer_write(RingBuffer* rb, const BYTE* ptr, size_t sz)
|
||||
*/
|
||||
toWrite = sz;
|
||||
remaining = sz;
|
||||
|
||||
|
||||
if (rb->size - rb->writePtr < sz)
|
||||
toWrite = rb->size - rb->writePtr;
|
||||
|
||||
@ -194,7 +187,6 @@ BOOL ringbuffer_write(RingBuffer* rb, const BYTE* ptr, size_t sz)
|
||||
memcpy(rb->buffer, ptr, remaining);
|
||||
|
||||
rb->writePtr = (rb->writePtr + sz) % rb->size;
|
||||
|
||||
rb->freeSize -= sz;
|
||||
return TRUE;
|
||||
}
|
||||
@ -233,16 +225,15 @@ BYTE* ringbuffer_ensure_linear_write(RingBuffer* rb, size_t sz)
|
||||
BOOL ringbuffer_commit_written_bytes(RingBuffer* rb, size_t sz)
|
||||
{
|
||||
DEBUG_RINGBUFFER("ringbuffer_commit_written_bytes(%p): sz: %d", rb, sz);
|
||||
|
||||
|
||||
if (sz < 1)
|
||||
return TRUE;
|
||||
|
||||
|
||||
if (rb->writePtr + sz > rb->size)
|
||||
return FALSE;
|
||||
|
||||
|
||||
rb->writePtr = (rb->writePtr + sz) % rb->size;
|
||||
rb->freeSize -= sz;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@ -252,12 +243,11 @@ int ringbuffer_peek(const RingBuffer* rb, DataChunk chunks[2], size_t sz)
|
||||
size_t toRead;
|
||||
int chunkIndex = 0;
|
||||
int status = 0;
|
||||
|
||||
DEBUG_RINGBUFFER("ringbuffer_peek(%p): sz: %d", rb, sz);
|
||||
|
||||
if (sz < 1)
|
||||
return 0;
|
||||
|
||||
|
||||
if ((rb->size - rb->freeSize) < sz)
|
||||
remaining = rb->size - rb->freeSize;
|
||||
|
||||
@ -281,23 +271,23 @@ int ringbuffer_peek(const RingBuffer* rb, DataChunk chunks[2], size_t sz)
|
||||
chunks[chunkIndex].size = remaining;
|
||||
status++;
|
||||
}
|
||||
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
void ringbuffer_commit_read_bytes(RingBuffer* rb, size_t sz)
|
||||
{
|
||||
DEBUG_RINGBUFFER("ringbuffer_commit_read_bytes(%p): sz: %d", rb, sz);
|
||||
|
||||
|
||||
if (sz < 1)
|
||||
return;
|
||||
|
||||
assert(rb->size - rb->freeSize >= sz);
|
||||
|
||||
assert(rb->size - rb->freeSize >= sz);
|
||||
rb->readPtr = (rb->readPtr + sz) % rb->size;
|
||||
rb->freeSize += sz;
|
||||
|
||||
/* when we reach a reasonable free size, we can go back to the original size */
|
||||
if ((rb->size != rb->initialSize) && (ringbuffer_used(rb) < rb->initialSize / 2))
|
||||
if ((rb->size != rb->initialSize)
|
||||
&& (ringbuffer_used(rb) < rb->initialSize / 2))
|
||||
ringbuffer_realloc(rb, rb->initialSize);
|
||||
}
|
||||
|
@ -104,109 +104,80 @@ typedef struct _wLog wLog;
|
||||
#define WLOG_PACKET_INBOUND 1
|
||||
#define WLOG_PACKET_OUTBOUND 2
|
||||
|
||||
WINPR_API BOOL WLog_PrintMessage(wLog* log, wLogMessage* message, ...);
|
||||
WINPR_API BOOL WLog_PrintMessageVA(wLog* log, wLogMessage* message, va_list args);
|
||||
WINPR_API BOOL WLog_PrintMessage(wLog* log, DWORD type, DWORD level, DWORD line,
|
||||
const char* file, const char* function, ...);
|
||||
WINPR_API BOOL WLog_PrintMessageVA(wLog* log, DWORD type, DWORD level,
|
||||
DWORD line,
|
||||
const char* file, const char* function, va_list args);
|
||||
|
||||
#define WLog_Print(_log, _log_level, _fmt, ...) \
|
||||
#define WLog_Print(_log, _log_level, ...) \
|
||||
do { \
|
||||
if (_log && _log_level >= WLog_GetLogLevel(_log)) { \
|
||||
wLogMessage _log_message; \
|
||||
memset(&_log_message, 0, sizeof(_log_message)); \
|
||||
_log_message.Type = WLOG_MESSAGE_TEXT; \
|
||||
_log_message.Level = _log_level; \
|
||||
_log_message.FormatString = _fmt; \
|
||||
_log_message.LineNumber = __LINE__; \
|
||||
_log_message.FileName = __FILE__; \
|
||||
_log_message.FunctionName = __FUNCTION__; \
|
||||
WLog_PrintMessage(_log, &(_log_message), ## __VA_ARGS__ ); \
|
||||
WLog_PrintMessage(_log, WLOG_MESSAGE_TEXT, _log_level, \
|
||||
__LINE__, __FILE__, __FUNCTION__, __VA_ARGS__ ); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define WLog_PrintVA(_log, _log_level, _fmt, _args) \
|
||||
#define WLog_PrintVA(_log, _log_level, _args) \
|
||||
do { \
|
||||
if (_log && _log_level >= WLog_GetLogLevel(_log)) { \
|
||||
wLogMessage _log_message; \
|
||||
memset(&_log_message, 0, sizeof(_log_message)); \
|
||||
_log_message.Type = WLOG_MESSAGE_TEXT; \
|
||||
_log_message.Level = _log_level; \
|
||||
_log_message.FormatString = _fmt; \
|
||||
_log_message.LineNumber = __LINE__; \
|
||||
_log_message.FileName = __FILE__; \
|
||||
_log_message.FunctionName = __FUNCTION__; \
|
||||
WLog_PrintMessageVA(_log, &(_log_message), _args); \
|
||||
WLog_PrintMessageVA(_log, WLOG_MESSAGE_TEXT, _log_level, \
|
||||
__LINE__, __FILE__, __FUNCTION__, _args ); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define WLog_Data(_log, _log_level, ...) \
|
||||
do { \
|
||||
if (_log && _log_level >= WLog_GetLogLevel(_log)) { \
|
||||
wLogMessage _log_message; \
|
||||
memset(&_log_message, 0, sizeof(_log_message)); \
|
||||
_log_message.Type = WLOG_MESSAGE_DATA; \
|
||||
_log_message.Level = _log_level; \
|
||||
_log_message.FormatString = NULL; \
|
||||
_log_message.LineNumber = __LINE__; \
|
||||
_log_message.FileName = __FILE__; \
|
||||
_log_message.FunctionName = __FUNCTION__; \
|
||||
WLog_PrintMessage(_log, &(_log_message), ## __VA_ARGS__ ); \
|
||||
WLog_PrintMessage(_log, WLOG_MESSAGE_DATA, _log_level, \
|
||||
__LINE__, __FILE__, __FUNCTION__, __VA_ARGS__ ); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define WLog_Image(_log, _log_level, ...) \
|
||||
do { \
|
||||
if (_log && _log_level >= WLog_GetLogLevel(_log)) { \
|
||||
wLogMessage _log_message; \
|
||||
memset(&_log_message, 0, sizeof(_log_message)); \
|
||||
_log_message.Type = WLOG_MESSAGE_IMAGE; \
|
||||
_log_message.Level = _log_level; \
|
||||
_log_message.FormatString = NULL; \
|
||||
_log_message.LineNumber = __LINE__; \
|
||||
_log_message.FileName = __FILE__; \
|
||||
_log_message.FunctionName = __FUNCTION__; \
|
||||
WLog_PrintMessage(_log, &(_log_message), ## __VA_ARGS__ ); \
|
||||
WLog_PrintMessage(_log, WLOG_MESSAGE_DATA, _log_level, \
|
||||
__LINE__, __FILE__, __FUNCTION__, __VA_ARGS__ ); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define WLog_Packet(_log, _log_level, ...) \
|
||||
do { \
|
||||
if (_log && _log_level >= WLog_GetLogLevel(_log)) { \
|
||||
wLogMessage _log_message; \
|
||||
memset(&_log_message, 0, sizeof(_log_message)); \
|
||||
_log_message.Type = WLOG_MESSAGE_PACKET; \
|
||||
_log_message.Level = _log_level; \
|
||||
_log_message.FormatString = NULL; \
|
||||
_log_message.LineNumber = __LINE__; \
|
||||
_log_message.FileName = __FILE__; \
|
||||
_log_message.FunctionName = __FUNCTION__; \
|
||||
WLog_PrintMessage(_log, &(_log_message), ## __VA_ARGS__ ); \
|
||||
WLog_PrintMessage(_log, WLOG_MESSAGE_PACKET, _log_level, \
|
||||
__LINE__, __FILE__, __FUNCTION__, __VA_ARGS__ ); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define WLog_IsLevelActive(_log, _log_level) \
|
||||
(_log ? _log_level >= WLog_GetLogLevel(_log) : FALSE)
|
||||
|
||||
#define WLog_LVL(tag, lvl, fmt, ...) WLog_Print(WLog_Get(tag), lvl, fmt, ## __VA_ARGS__)
|
||||
#define WLog_VRB(tag, fmt, ...) WLog_Print(WLog_Get(tag), WLOG_TRACE, fmt, ## __VA_ARGS__)
|
||||
#define WLog_DBG(tag, fmt, ...) WLog_Print(WLog_Get(tag), WLOG_DEBUG, fmt, ## __VA_ARGS__)
|
||||
#define WLog_INFO(tag, fmt, ...) WLog_Print(WLog_Get(tag), WLOG_INFO, fmt, ## __VA_ARGS__)
|
||||
#define WLog_WARN(tag, fmt, ...) WLog_Print(WLog_Get(tag), WLOG_WARN, fmt, ## __VA_ARGS__)
|
||||
#define WLog_ERR(tag, fmt, ...) WLog_Print(WLog_Get(tag), WLOG_ERROR, fmt, ## __VA_ARGS__)
|
||||
#define WLog_FATAL(tag, fmt, ...) WLog_Print(WLog_Get(tag), WLOG_FATAL, fmt, ## __VA_ARGS__)
|
||||
#define WLog_LVL(tag, lvl, ...) WLog_Print(WLog_Get(tag), lvl, __VA_ARGS__)
|
||||
#define WLog_VRB(tag, ...) WLog_Print(WLog_Get(tag), WLOG_TRACE, __VA_ARGS__)
|
||||
#define WLog_DBG(tag, ...) WLog_Print(WLog_Get(tag), WLOG_DEBUG, __VA_ARGS__)
|
||||
#define WLog_INFO(tag, ...) WLog_Print(WLog_Get(tag), WLOG_INFO, __VA_ARGS__)
|
||||
#define WLog_WARN(tag, ...) WLog_Print(WLog_Get(tag), WLOG_WARN, __VA_ARGS__)
|
||||
#define WLog_ERR(tag, ...) WLog_Print(WLog_Get(tag), WLOG_ERROR, __VA_ARGS__)
|
||||
#define WLog_FATAL(tag, ...) WLog_Print(WLog_Get(tag), WLOG_FATAL, __VA_ARGS__)
|
||||
|
||||
WINPR_API DWORD WLog_GetLogLevel(wLog* log);
|
||||
WINPR_API BOOL WLog_SetLogLevel(wLog* log, DWORD logLevel);
|
||||
WINPR_API BOOL WLog_SetStringLogLevel(wLog* log, LPCSTR level);
|
||||
WINPR_API BOOL WLog_AddStringLogFilters(LPCSTR filter);
|
||||
|
||||
static INLINE BOOL WLog_IsLevelActive(wLog* _log, DWORD _log_level)
|
||||
{
|
||||
return _log ? _log_level >= WLog_GetLogLevel(_log) : FALSE;
|
||||
}
|
||||
|
||||
WINPR_API BOOL WLog_SetLogAppenderType(wLog* log, DWORD logAppenderType);
|
||||
WINPR_API wLogAppender* WLog_GetLogAppender(wLog* log);
|
||||
WINPR_API BOOL WLog_OpenAppender(wLog* log);
|
||||
WINPR_API BOOL WLog_CloseAppender(wLog* log);
|
||||
WINPR_API BOOL WLog_ConfigureAppender(wLogAppender *appender, const char *setting, void *value);
|
||||
WINPR_API BOOL WLog_ConfigureAppender(wLogAppender* appender,
|
||||
const char* setting, void* value);
|
||||
|
||||
WINPR_API wLogLayout* WLog_GetLogLayout(wLog* log);
|
||||
WINPR_API BOOL WLog_Layout_SetPrefixFormat(wLog* log, wLogLayout* layout, const char* format);
|
||||
WINPR_API BOOL WLog_Layout_SetPrefixFormat(wLog* log, wLogLayout* layout,
|
||||
const char* format);
|
||||
|
||||
WINPR_API wLog* WLog_GetRoot(void);
|
||||
WINPR_API wLog* WLog_Get(LPCSTR name);
|
||||
@ -214,12 +185,13 @@ WINPR_API wLog* WLog_Get(LPCSTR name);
|
||||
WINPR_API BOOL WLog_Init(void);
|
||||
WINPR_API BOOL WLog_Uninit(void);
|
||||
|
||||
typedef BOOL (*wLogCallbackMessage_t)(const wLogMessage *msg);
|
||||
typedef BOOL (*wLogCallbackData_t)(const wLogMessage *msg);
|
||||
typedef BOOL (*wLogCallbackImage_t)(const wLogMessage *msg);
|
||||
typedef BOOL (*wLogCallbackPackage_t)(const wLogMessage *msg);
|
||||
typedef BOOL (*wLogCallbackMessage_t)(const 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;
|
||||
|
@ -54,7 +54,7 @@
|
||||
#include "comm.h"
|
||||
|
||||
|
||||
static wLog *_Log = NULL;
|
||||
static wLog* _Log = NULL;
|
||||
|
||||
struct comm_device
|
||||
{
|
||||
@ -68,7 +68,7 @@ typedef struct comm_device COMM_DEVICE;
|
||||
/* FIXME: get a clever data structure, see also io.h functions */
|
||||
/* _CommDevices is a NULL-terminated array with a maximun of COMM_DEVICE_MAX COMM_DEVICE */
|
||||
#define COMM_DEVICE_MAX 128
|
||||
static COMM_DEVICE **_CommDevices = NULL;
|
||||
static COMM_DEVICE** _CommDevices = NULL;
|
||||
static CRITICAL_SECTION _CommDevicesLock;
|
||||
|
||||
static HANDLE_CREATOR _CommHandleCreator;
|
||||
@ -77,7 +77,7 @@ static pthread_once_t _CommInitialized = PTHREAD_ONCE_INIT;
|
||||
|
||||
static int CommGetFd(HANDLE handle)
|
||||
{
|
||||
WINPR_COMM *comm = (WINPR_COMM *)handle;
|
||||
WINPR_COMM* comm = (WINPR_COMM*)handle;
|
||||
|
||||
if (!CommIsHandled(handle))
|
||||
return -1;
|
||||
@ -85,7 +85,7 @@ static int CommGetFd(HANDLE handle)
|
||||
return comm->fd;
|
||||
}
|
||||
|
||||
HANDLE_CREATOR *GetCommHandleCreator(void)
|
||||
HANDLE_CREATOR* GetCommHandleCreator(void)
|
||||
{
|
||||
_CommHandleCreator.IsHandled = IsCommDevice;
|
||||
_CommHandleCreator.CreateFileA = CommCreateFileA;
|
||||
@ -95,11 +95,10 @@ HANDLE_CREATOR *GetCommHandleCreator(void)
|
||||
static void _CommInit(void)
|
||||
{
|
||||
/* NB: error management to be done outside of this function */
|
||||
|
||||
assert(_Log == NULL);
|
||||
assert(_CommDevices == NULL);
|
||||
_CommDevices = (COMM_DEVICE**)calloc(COMM_DEVICE_MAX + 1, sizeof(COMM_DEVICE*));
|
||||
|
||||
_CommDevices = (COMM_DEVICE**)calloc(COMM_DEVICE_MAX+1, sizeof(COMM_DEVICE*));
|
||||
if (!_CommDevices)
|
||||
return;
|
||||
|
||||
@ -130,14 +129,14 @@ static BOOL CommInitialized()
|
||||
}
|
||||
|
||||
|
||||
void CommLog_Print(int level, char *fmt, ...)
|
||||
void CommLog_Print(int level, ...)
|
||||
{
|
||||
if (!CommInitialized())
|
||||
return;
|
||||
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
WLog_PrintVA(_Log, level, fmt, ap);
|
||||
va_start(ap, level);
|
||||
WLog_PrintVA(_Log, level, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
@ -148,7 +147,6 @@ BOOL BuildCommDCBA(LPCSTR lpDef, LPDCB lpDCB)
|
||||
return FALSE;
|
||||
|
||||
/* TODO: not implemented */
|
||||
|
||||
CommLog_Print(WLOG_ERROR, "%s: Not implemented", __FUNCTION__);
|
||||
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
||||
return FALSE;
|
||||
@ -160,31 +158,30 @@ BOOL BuildCommDCBW(LPCWSTR lpDef, LPDCB lpDCB)
|
||||
return FALSE;
|
||||
|
||||
/* TODO: not implemented */
|
||||
|
||||
CommLog_Print(WLOG_ERROR, "%s: Not implemented", __FUNCTION__);
|
||||
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
BOOL BuildCommDCBAndTimeoutsA(LPCSTR lpDef, LPDCB lpDCB, LPCOMMTIMEOUTS lpCommTimeouts)
|
||||
BOOL BuildCommDCBAndTimeoutsA(LPCSTR lpDef, LPDCB lpDCB,
|
||||
LPCOMMTIMEOUTS lpCommTimeouts)
|
||||
{
|
||||
if (!CommInitialized())
|
||||
return FALSE;
|
||||
|
||||
/* TODO: not implemented */
|
||||
|
||||
CommLog_Print(WLOG_ERROR, "%s: Not implemented", __FUNCTION__);
|
||||
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
BOOL BuildCommDCBAndTimeoutsW(LPCWSTR lpDef, LPDCB lpDCB, LPCOMMTIMEOUTS lpCommTimeouts)
|
||||
BOOL BuildCommDCBAndTimeoutsW(LPCWSTR lpDef, LPDCB lpDCB,
|
||||
LPCOMMTIMEOUTS lpCommTimeouts)
|
||||
{
|
||||
if (!CommInitialized())
|
||||
return FALSE;
|
||||
|
||||
/* TODO: not implemented */
|
||||
|
||||
CommLog_Print(WLOG_ERROR, "%s: Not implemented", __FUNCTION__);
|
||||
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
||||
return FALSE;
|
||||
@ -196,7 +193,6 @@ BOOL CommConfigDialogA(LPCSTR lpszName, HWND hWnd, LPCOMMCONFIG lpCC)
|
||||
return FALSE;
|
||||
|
||||
/* TODO: not implemented */
|
||||
|
||||
CommLog_Print(WLOG_ERROR, "%s: Not implemented", __FUNCTION__);
|
||||
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
||||
return FALSE;
|
||||
@ -208,7 +204,6 @@ BOOL CommConfigDialogW(LPCWSTR lpszName, HWND hWnd, LPCOMMCONFIG lpCC)
|
||||
return FALSE;
|
||||
|
||||
/* TODO: not implemented */
|
||||
|
||||
CommLog_Print(WLOG_ERROR, "%s: Not implemented", __FUNCTION__);
|
||||
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
||||
return FALSE;
|
||||
@ -312,13 +307,14 @@ BOOL GetCommProperties(HANDLE hFile, LPCOMMPROP lpCommProp)
|
||||
if (!CommInitialized())
|
||||
return FALSE;
|
||||
|
||||
if (!pComm || pComm->Type != HANDLE_TYPE_COMM || !pComm->fd )
|
||||
if (!pComm || pComm->Type != HANDLE_TYPE_COMM || !pComm->fd)
|
||||
{
|
||||
SetLastError(ERROR_INVALID_HANDLE);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!CommDeviceIoControl(pComm, IOCTL_SERIAL_GET_PROPERTIES, NULL, 0, lpCommProp, sizeof(COMMPROP), &bytesReturned, NULL))
|
||||
if (!CommDeviceIoControl(pComm, IOCTL_SERIAL_GET_PROPERTIES, NULL, 0,
|
||||
lpCommProp, sizeof(COMMPROP), &bytesReturned, NULL))
|
||||
{
|
||||
CommLog_Print(WLOG_WARN, "GetCommProperties failure.");
|
||||
return FALSE;
|
||||
@ -340,7 +336,7 @@ BOOL GetCommProperties(HANDLE hFile, LPCOMMPROP lpCommProp)
|
||||
*/
|
||||
BOOL GetCommState(HANDLE hFile, LPDCB lpDCB)
|
||||
{
|
||||
DCB *lpLocalDcb;
|
||||
DCB* lpLocalDcb;
|
||||
struct termios currentState;
|
||||
WINPR_COMM* pComm = (WINPR_COMM*) hFile;
|
||||
DWORD bytesReturned;
|
||||
@ -348,7 +344,7 @@ BOOL GetCommState(HANDLE hFile, LPDCB lpDCB)
|
||||
if (!CommInitialized())
|
||||
return FALSE;
|
||||
|
||||
if (!pComm || pComm->Type != HANDLE_TYPE_COMM || !pComm->fd )
|
||||
if (!pComm || pComm->Type != HANDLE_TYPE_COMM || !pComm->fd)
|
||||
{
|
||||
SetLastError(ERROR_INVALID_HANDLE);
|
||||
return FALSE;
|
||||
@ -373,6 +369,7 @@ BOOL GetCommState(HANDLE hFile, LPDCB lpDCB)
|
||||
}
|
||||
|
||||
lpLocalDcb = (DCB*)calloc(1, lpDCB->DCBlength);
|
||||
|
||||
if (lpLocalDcb == NULL)
|
||||
{
|
||||
SetLastError(ERROR_OUTOFMEMORY);
|
||||
@ -380,35 +377,40 @@ BOOL GetCommState(HANDLE hFile, LPDCB lpDCB)
|
||||
}
|
||||
|
||||
/* error_handle */
|
||||
|
||||
lpLocalDcb->DCBlength = lpDCB->DCBlength;
|
||||
|
||||
SERIAL_BAUD_RATE baudRate;
|
||||
if (!CommDeviceIoControl(pComm, IOCTL_SERIAL_GET_BAUD_RATE, NULL, 0, &baudRate, sizeof(SERIAL_BAUD_RATE), &bytesReturned, NULL))
|
||||
|
||||
if (!CommDeviceIoControl(pComm, IOCTL_SERIAL_GET_BAUD_RATE, NULL, 0, &baudRate,
|
||||
sizeof(SERIAL_BAUD_RATE), &bytesReturned, NULL))
|
||||
{
|
||||
CommLog_Print(WLOG_WARN, "GetCommState failure: could not get the baud rate.");
|
||||
goto error_handle;
|
||||
}
|
||||
lpLocalDcb->BaudRate = baudRate.BaudRate;
|
||||
|
||||
lpLocalDcb->BaudRate = baudRate.BaudRate;
|
||||
lpLocalDcb->fBinary = (currentState.c_cflag & ICANON) == 0;
|
||||
|
||||
if (!lpLocalDcb->fBinary)
|
||||
{
|
||||
CommLog_Print(WLOG_WARN, "Unexpected nonbinary mode, consider to unset the ICANON flag.");
|
||||
CommLog_Print(WLOG_WARN,
|
||||
"Unexpected nonbinary mode, consider to unset the ICANON flag.");
|
||||
}
|
||||
|
||||
lpLocalDcb->fParity = (currentState.c_iflag & INPCK) != 0;
|
||||
|
||||
lpLocalDcb->fParity = (currentState.c_iflag & INPCK) != 0;
|
||||
SERIAL_HANDFLOW handflow;
|
||||
if (!CommDeviceIoControl(pComm, IOCTL_SERIAL_GET_HANDFLOW, NULL, 0, &handflow, sizeof(SERIAL_HANDFLOW), &bytesReturned, NULL))
|
||||
|
||||
if (!CommDeviceIoControl(pComm, IOCTL_SERIAL_GET_HANDFLOW, NULL, 0, &handflow,
|
||||
sizeof(SERIAL_HANDFLOW), &bytesReturned, NULL))
|
||||
{
|
||||
CommLog_Print(WLOG_WARN, "GetCommState failure: could not get the handflow settings.");
|
||||
CommLog_Print(WLOG_WARN,
|
||||
"GetCommState failure: could not get the handflow settings.");
|
||||
goto error_handle;
|
||||
}
|
||||
|
||||
lpLocalDcb->fOutxCtsFlow = (handflow.ControlHandShake & SERIAL_CTS_HANDSHAKE) != 0;
|
||||
|
||||
lpLocalDcb->fOutxDsrFlow = (handflow.ControlHandShake & SERIAL_DSR_HANDSHAKE) != 0;
|
||||
lpLocalDcb->fOutxCtsFlow = (handflow.ControlHandShake & SERIAL_CTS_HANDSHAKE) !=
|
||||
0;
|
||||
lpLocalDcb->fOutxDsrFlow = (handflow.ControlHandShake & SERIAL_DSR_HANDSHAKE) !=
|
||||
0;
|
||||
|
||||
if (handflow.ControlHandShake & SERIAL_DTR_HANDSHAKE)
|
||||
{
|
||||
@ -423,16 +425,13 @@ BOOL GetCommState(HANDLE hFile, LPDCB lpDCB)
|
||||
lpLocalDcb->fDtrControl = DTR_CONTROL_DISABLE;
|
||||
}
|
||||
|
||||
lpLocalDcb->fDsrSensitivity = (handflow.ControlHandShake & SERIAL_DSR_SENSITIVITY) != 0;
|
||||
|
||||
lpLocalDcb->fTXContinueOnXoff = (handflow.FlowReplace & SERIAL_XOFF_CONTINUE) != 0;
|
||||
|
||||
lpLocalDcb->fDsrSensitivity = (handflow.ControlHandShake &
|
||||
SERIAL_DSR_SENSITIVITY) != 0;
|
||||
lpLocalDcb->fTXContinueOnXoff = (handflow.FlowReplace & SERIAL_XOFF_CONTINUE) !=
|
||||
0;
|
||||
lpLocalDcb->fOutX = (handflow.FlowReplace & SERIAL_AUTO_TRANSMIT) != 0;
|
||||
|
||||
lpLocalDcb->fInX = (handflow.FlowReplace & SERIAL_AUTO_RECEIVE) != 0;
|
||||
|
||||
lpLocalDcb->fErrorChar = (handflow.FlowReplace & SERIAL_ERROR_CHAR) != 0;
|
||||
|
||||
lpLocalDcb->fNull = (handflow.FlowReplace & SERIAL_NULL_STRIPPING) != 0;
|
||||
|
||||
if (handflow.FlowReplace & SERIAL_RTS_HANDSHAKE)
|
||||
@ -449,57 +448,45 @@ BOOL GetCommState(HANDLE hFile, LPDCB lpDCB)
|
||||
}
|
||||
|
||||
// FIXME: how to get the RTS_CONTROL_TOGGLE state? Does it match the UART 16750's Autoflow Control Enabled bit in its Modem Control Register (MCR)
|
||||
|
||||
|
||||
lpLocalDcb->fAbortOnError = (handflow.ControlHandShake & SERIAL_ERROR_ABORT) != 0;
|
||||
|
||||
lpLocalDcb->fAbortOnError = (handflow.ControlHandShake & SERIAL_ERROR_ABORT) !=
|
||||
0;
|
||||
/* lpLocalDcb->fDummy2 not used */
|
||||
|
||||
lpLocalDcb->wReserved = 0; /* must be zero */
|
||||
|
||||
lpLocalDcb->XonLim = handflow.XonLimit;
|
||||
|
||||
lpLocalDcb->XoffLim = handflow.XoffLimit;
|
||||
|
||||
SERIAL_LINE_CONTROL lineControl;
|
||||
if (!CommDeviceIoControl(pComm, IOCTL_SERIAL_GET_LINE_CONTROL, NULL, 0, &lineControl, sizeof(SERIAL_LINE_CONTROL), &bytesReturned, NULL))
|
||||
|
||||
if (!CommDeviceIoControl(pComm, IOCTL_SERIAL_GET_LINE_CONTROL, NULL, 0,
|
||||
&lineControl, sizeof(SERIAL_LINE_CONTROL), &bytesReturned, NULL))
|
||||
{
|
||||
CommLog_Print(WLOG_WARN, "GetCommState failure: could not get the control settings.");
|
||||
CommLog_Print(WLOG_WARN,
|
||||
"GetCommState failure: could not get the control settings.");
|
||||
goto error_handle;
|
||||
}
|
||||
|
||||
lpLocalDcb->ByteSize = lineControl.WordLength;
|
||||
|
||||
lpLocalDcb->Parity = lineControl.Parity;
|
||||
|
||||
lpLocalDcb->StopBits = lineControl.StopBits;
|
||||
|
||||
|
||||
SERIAL_CHARS serialChars;
|
||||
if (!CommDeviceIoControl(pComm, IOCTL_SERIAL_GET_CHARS, NULL, 0, &serialChars, sizeof(SERIAL_CHARS), &bytesReturned, NULL))
|
||||
|
||||
if (!CommDeviceIoControl(pComm, IOCTL_SERIAL_GET_CHARS, NULL, 0, &serialChars,
|
||||
sizeof(SERIAL_CHARS), &bytesReturned, NULL))
|
||||
{
|
||||
CommLog_Print(WLOG_WARN, "GetCommState failure: could not get the serial chars.");
|
||||
CommLog_Print(WLOG_WARN,
|
||||
"GetCommState failure: could not get the serial chars.");
|
||||
goto error_handle;
|
||||
}
|
||||
|
||||
lpLocalDcb->XonChar = serialChars.XonChar;
|
||||
|
||||
lpLocalDcb->XoffChar = serialChars.XoffChar;
|
||||
|
||||
lpLocalDcb->ErrorChar = serialChars.ErrorChar;
|
||||
|
||||
lpLocalDcb->EofChar = serialChars.EofChar;
|
||||
|
||||
lpLocalDcb->EvtChar = serialChars.EventChar;
|
||||
|
||||
|
||||
memcpy(lpDCB, lpLocalDcb, lpDCB->DCBlength);
|
||||
free(lpLocalDcb);
|
||||
return TRUE;
|
||||
|
||||
error_handle:
|
||||
free(lpLocalDcb);
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
@ -526,7 +513,7 @@ BOOL SetCommState(HANDLE hFile, LPDCB lpDCB)
|
||||
if (!CommInitialized())
|
||||
return FALSE;
|
||||
|
||||
if (!pComm || pComm->Type != HANDLE_TYPE_COMM || !pComm->fd )
|
||||
if (!pComm || pComm->Type != HANDLE_TYPE_COMM || !pComm->fd)
|
||||
{
|
||||
SetLastError(ERROR_INVALID_HANDLE);
|
||||
return FALSE;
|
||||
@ -540,31 +527,39 @@ BOOL SetCommState(HANDLE hFile, LPDCB lpDCB)
|
||||
|
||||
/* NB: did the choice to call ioctls first when available and
|
||||
then to setup upcomingTermios. Don't mix both stages. */
|
||||
|
||||
/** ioctl calls stage **/
|
||||
|
||||
SERIAL_BAUD_RATE baudRate;
|
||||
baudRate.BaudRate = lpDCB->BaudRate;
|
||||
if (!CommDeviceIoControl(pComm, IOCTL_SERIAL_SET_BAUD_RATE, &baudRate, sizeof(SERIAL_BAUD_RATE), NULL, 0, &bytesReturned, NULL))
|
||||
|
||||
if (!CommDeviceIoControl(pComm, IOCTL_SERIAL_SET_BAUD_RATE, &baudRate,
|
||||
sizeof(SERIAL_BAUD_RATE), NULL, 0, &bytesReturned, NULL))
|
||||
{
|
||||
CommLog_Print(WLOG_WARN, "SetCommState failure: could not set the baud rate.");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
SERIAL_CHARS serialChars;
|
||||
if (!CommDeviceIoControl(pComm, IOCTL_SERIAL_GET_CHARS, NULL, 0, &serialChars, sizeof(SERIAL_CHARS), &bytesReturned, NULL)) /* as of today, required for BreakChar */
|
||||
|
||||
if (!CommDeviceIoControl(pComm, IOCTL_SERIAL_GET_CHARS, NULL, 0, &serialChars,
|
||||
sizeof(SERIAL_CHARS), &bytesReturned,
|
||||
NULL)) /* as of today, required for BreakChar */
|
||||
{
|
||||
CommLog_Print(WLOG_WARN, "SetCommState failure: could not get the initial serial chars.");
|
||||
CommLog_Print(WLOG_WARN,
|
||||
"SetCommState failure: could not get the initial serial chars.");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
serialChars.XonChar = lpDCB->XonChar;
|
||||
serialChars.XoffChar = lpDCB->XoffChar;
|
||||
serialChars.ErrorChar = lpDCB->ErrorChar;
|
||||
serialChars.EofChar = lpDCB->EofChar;
|
||||
serialChars.EventChar = lpDCB->EvtChar;
|
||||
if (!CommDeviceIoControl(pComm, IOCTL_SERIAL_SET_CHARS, &serialChars, sizeof(SERIAL_CHARS), NULL, 0, &bytesReturned, NULL))
|
||||
|
||||
if (!CommDeviceIoControl(pComm, IOCTL_SERIAL_SET_CHARS, &serialChars,
|
||||
sizeof(SERIAL_CHARS), NULL, 0, &bytesReturned, NULL))
|
||||
{
|
||||
CommLog_Print(WLOG_WARN, "SetCommState failure: could not set the serial chars.");
|
||||
CommLog_Print(WLOG_WARN,
|
||||
"SetCommState failure: could not set the serial chars.");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
@ -572,13 +567,15 @@ BOOL SetCommState(HANDLE hFile, LPDCB lpDCB)
|
||||
lineControl.StopBits = lpDCB->StopBits;
|
||||
lineControl.Parity = lpDCB->Parity;
|
||||
lineControl.WordLength = lpDCB->ByteSize;
|
||||
if (!CommDeviceIoControl(pComm, IOCTL_SERIAL_SET_LINE_CONTROL, &lineControl, sizeof(SERIAL_LINE_CONTROL), NULL, 0, &bytesReturned, NULL))
|
||||
|
||||
if (!CommDeviceIoControl(pComm, IOCTL_SERIAL_SET_LINE_CONTROL, &lineControl,
|
||||
sizeof(SERIAL_LINE_CONTROL), NULL, 0, &bytesReturned, NULL))
|
||||
{
|
||||
CommLog_Print(WLOG_WARN, "SetCommState failure: could not set the control settings.");
|
||||
CommLog_Print(WLOG_WARN,
|
||||
"SetCommState failure: could not set the control settings.");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
SERIAL_HANDFLOW handflow;
|
||||
ZeroMemory(&handflow, sizeof(SERIAL_HANDFLOW));
|
||||
|
||||
@ -587,7 +584,6 @@ BOOL SetCommState(HANDLE hFile, LPDCB lpDCB)
|
||||
handflow.ControlHandShake |= SERIAL_CTS_HANDSHAKE;
|
||||
}
|
||||
|
||||
|
||||
if (lpDCB->fOutxDsrFlow)
|
||||
{
|
||||
handflow.ControlHandShake |= SERIAL_DSR_HANDSHAKE;
|
||||
@ -608,7 +604,8 @@ BOOL SetCommState(HANDLE hFile, LPDCB lpDCB)
|
||||
break;
|
||||
|
||||
default:
|
||||
CommLog_Print(WLOG_WARN, "Unexpected fDtrControl value: %d\n", lpDCB->fDtrControl);
|
||||
CommLog_Print(WLOG_WARN, "Unexpected fDtrControl value: %d\n",
|
||||
lpDCB->fDtrControl);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
@ -662,7 +659,8 @@ BOOL SetCommState(HANDLE hFile, LPDCB lpDCB)
|
||||
break;
|
||||
|
||||
default:
|
||||
CommLog_Print(WLOG_WARN, "Unexpected fRtsControl value: %d\n", lpDCB->fRtsControl);
|
||||
CommLog_Print(WLOG_WARN, "Unexpected fRtsControl value: %d\n",
|
||||
lpDCB->fRtsControl);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
@ -672,25 +670,24 @@ BOOL SetCommState(HANDLE hFile, LPDCB lpDCB)
|
||||
}
|
||||
|
||||
/* lpDCB->fDummy2 not used */
|
||||
|
||||
/* lpLocalDcb->wReserved ignored */
|
||||
|
||||
handflow.XonLimit = lpDCB->XonLim;
|
||||
|
||||
handflow.XoffLimit = lpDCB->XoffLim;
|
||||
|
||||
if (!CommDeviceIoControl(pComm, IOCTL_SERIAL_SET_HANDFLOW, &handflow, sizeof(SERIAL_HANDFLOW), NULL, 0, &bytesReturned, NULL))
|
||||
if (!CommDeviceIoControl(pComm, IOCTL_SERIAL_SET_HANDFLOW, &handflow,
|
||||
sizeof(SERIAL_HANDFLOW), NULL, 0, &bytesReturned, NULL))
|
||||
{
|
||||
CommLog_Print(WLOG_WARN, "SetCommState failure: could not set the handflow settings.");
|
||||
CommLog_Print(WLOG_WARN,
|
||||
"SetCommState failure: could not set the handflow settings.");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
/** upcomingTermios stage **/
|
||||
|
||||
|
||||
ZeroMemory(&upcomingTermios, sizeof(struct termios));
|
||||
if (tcgetattr(pComm->fd, &upcomingTermios) < 0) /* NB: preserves current settings not directly handled by the Communication Functions */
|
||||
|
||||
if (tcgetattr(pComm->fd,
|
||||
&upcomingTermios) <
|
||||
0) /* NB: preserves current settings not directly handled by the Communication Functions */
|
||||
{
|
||||
SetLastError(ERROR_IO_DEVICE);
|
||||
return FALSE;
|
||||
@ -703,7 +700,8 @@ BOOL SetCommState(HANDLE hFile, LPDCB lpDCB)
|
||||
else
|
||||
{
|
||||
upcomingTermios.c_lflag |= ICANON;
|
||||
CommLog_Print(WLOG_WARN, "Unexpected nonbinary mode, consider to unset the ICANON flag.");
|
||||
CommLog_Print(WLOG_WARN,
|
||||
"Unexpected nonbinary mode, consider to unset the ICANON flag.");
|
||||
}
|
||||
|
||||
if (lpDCB->fParity)
|
||||
@ -715,7 +713,6 @@ BOOL SetCommState(HANDLE hFile, LPDCB lpDCB)
|
||||
upcomingTermios.c_iflag &= ~INPCK;
|
||||
}
|
||||
|
||||
|
||||
/* http://msdn.microsoft.com/en-us/library/windows/desktop/aa363423%28v=vs.85%29.aspx
|
||||
*
|
||||
* The SetCommState function reconfigures the communications
|
||||
@ -733,7 +730,6 @@ BOOL SetCommState(HANDLE hFile, LPDCB lpDCB)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@ -749,7 +745,7 @@ BOOL GetCommTimeouts(HANDLE hFile, LPCOMMTIMEOUTS lpCommTimeouts)
|
||||
if (!CommInitialized())
|
||||
return FALSE;
|
||||
|
||||
if (!pComm || pComm->Type != HANDLE_TYPE_COMM || !pComm->fd )
|
||||
if (!pComm || pComm->Type != HANDLE_TYPE_COMM || !pComm->fd)
|
||||
{
|
||||
SetLastError(ERROR_INVALID_HANDLE);
|
||||
return FALSE;
|
||||
@ -757,7 +753,8 @@ BOOL GetCommTimeouts(HANDLE hFile, LPCOMMTIMEOUTS lpCommTimeouts)
|
||||
|
||||
/* as of today, SERIAL_TIMEOUTS and COMMTIMEOUTS structures are identical */
|
||||
|
||||
if (!CommDeviceIoControl(pComm, IOCTL_SERIAL_GET_TIMEOUTS, NULL, 0, lpCommTimeouts, sizeof(COMMTIMEOUTS), &bytesReturned, NULL))
|
||||
if (!CommDeviceIoControl(pComm, IOCTL_SERIAL_GET_TIMEOUTS, NULL, 0,
|
||||
lpCommTimeouts, sizeof(COMMTIMEOUTS), &bytesReturned, NULL))
|
||||
{
|
||||
CommLog_Print(WLOG_WARN, "GetCommTimeouts failure.");
|
||||
return FALSE;
|
||||
@ -779,7 +776,7 @@ BOOL SetCommTimeouts(HANDLE hFile, LPCOMMTIMEOUTS lpCommTimeouts)
|
||||
if (!CommInitialized())
|
||||
return FALSE;
|
||||
|
||||
if (!pComm || pComm->Type != HANDLE_TYPE_COMM || !pComm->fd )
|
||||
if (!pComm || pComm->Type != HANDLE_TYPE_COMM || !pComm->fd)
|
||||
{
|
||||
SetLastError(ERROR_INVALID_HANDLE);
|
||||
return FALSE;
|
||||
@ -787,7 +784,8 @@ BOOL SetCommTimeouts(HANDLE hFile, LPCOMMTIMEOUTS lpCommTimeouts)
|
||||
|
||||
/* as of today, SERIAL_TIMEOUTS and COMMTIMEOUTS structures are identical */
|
||||
|
||||
if (!CommDeviceIoControl(pComm, IOCTL_SERIAL_SET_TIMEOUTS, lpCommTimeouts, sizeof(COMMTIMEOUTS), NULL, 0, &bytesReturned, NULL))
|
||||
if (!CommDeviceIoControl(pComm, IOCTL_SERIAL_SET_TIMEOUTS, lpCommTimeouts,
|
||||
sizeof(COMMTIMEOUTS), NULL, 0, &bytesReturned, NULL))
|
||||
{
|
||||
CommLog_Print(WLOG_WARN, "SetCommTimeouts failure.");
|
||||
return FALSE;
|
||||
@ -802,19 +800,18 @@ BOOL GetDefaultCommConfigA(LPCSTR lpszName, LPCOMMCONFIG lpCC, LPDWORD lpdwSize)
|
||||
return FALSE;
|
||||
|
||||
/* TODO: not implemented */
|
||||
|
||||
CommLog_Print(WLOG_ERROR, "%s: Not implemented", __FUNCTION__);
|
||||
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
BOOL GetDefaultCommConfigW(LPCWSTR lpszName, LPCOMMCONFIG lpCC, LPDWORD lpdwSize)
|
||||
BOOL GetDefaultCommConfigW(LPCWSTR lpszName, LPCOMMCONFIG lpCC,
|
||||
LPDWORD lpdwSize)
|
||||
{
|
||||
if (!CommInitialized())
|
||||
return FALSE;
|
||||
|
||||
/* TODO: not implemented */
|
||||
|
||||
CommLog_Print(WLOG_ERROR, "%s: Not implemented", __FUNCTION__);
|
||||
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
||||
return FALSE;
|
||||
@ -826,7 +823,6 @@ BOOL SetDefaultCommConfigA(LPCSTR lpszName, LPCOMMCONFIG lpCC, DWORD dwSize)
|
||||
return FALSE;
|
||||
|
||||
/* TODO: not implemented */
|
||||
|
||||
CommLog_Print(WLOG_ERROR, "%s: Not implemented", __FUNCTION__);
|
||||
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
||||
return FALSE;
|
||||
@ -838,7 +834,6 @@ BOOL SetDefaultCommConfigW(LPCWSTR lpszName, LPCOMMCONFIG lpCC, DWORD dwSize)
|
||||
return FALSE;
|
||||
|
||||
/* TODO: not implemented */
|
||||
|
||||
CommLog_Print(WLOG_ERROR, "%s: Not implemented", __FUNCTION__);
|
||||
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
||||
return FALSE;
|
||||
@ -904,13 +899,14 @@ BOOL PurgeComm(HANDLE hFile, DWORD dwFlags)
|
||||
if (!CommInitialized())
|
||||
return FALSE;
|
||||
|
||||
if (!pComm || pComm->Type != HANDLE_TYPE_COMM || !pComm->fd )
|
||||
if (!pComm || pComm->Type != HANDLE_TYPE_COMM || !pComm->fd)
|
||||
{
|
||||
SetLastError(ERROR_INVALID_HANDLE);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!CommDeviceIoControl(pComm, IOCTL_SERIAL_PURGE, &dwFlags, sizeof(DWORD), NULL, 0, &bytesReturned, NULL))
|
||||
if (!CommDeviceIoControl(pComm, IOCTL_SERIAL_PURGE, &dwFlags, sizeof(DWORD),
|
||||
NULL, 0, &bytesReturned, NULL))
|
||||
{
|
||||
CommLog_Print(WLOG_WARN, "PurgeComm failure.");
|
||||
return FALSE;
|
||||
@ -929,7 +925,7 @@ BOOL SetupComm(HANDLE hFile, DWORD dwInQueue, DWORD dwOutQueue)
|
||||
if (!CommInitialized())
|
||||
return FALSE;
|
||||
|
||||
if (!pComm || pComm->Type != HANDLE_TYPE_COMM || !pComm->fd )
|
||||
if (!pComm || pComm->Type != HANDLE_TYPE_COMM || !pComm->fd)
|
||||
{
|
||||
SetLastError(ERROR_INVALID_HANDLE);
|
||||
return FALSE;
|
||||
@ -938,7 +934,8 @@ BOOL SetupComm(HANDLE hFile, DWORD dwInQueue, DWORD dwOutQueue)
|
||||
queueSize.InSize = dwInQueue;
|
||||
queueSize.OutSize = dwOutQueue;
|
||||
|
||||
if (!CommDeviceIoControl(pComm, IOCTL_SERIAL_SET_QUEUE_SIZE, &queueSize, sizeof(SERIAL_QUEUE_SIZE), NULL, 0, &bytesReturned, NULL))
|
||||
if (!CommDeviceIoControl(pComm, IOCTL_SERIAL_SET_QUEUE_SIZE, &queueSize,
|
||||
sizeof(SERIAL_QUEUE_SIZE), NULL, 0, &bytesReturned, NULL))
|
||||
{
|
||||
CommLog_Print(WLOG_WARN, "SetCommTimeouts failure.");
|
||||
return FALSE;
|
||||
@ -1009,9 +1006,10 @@ static BOOL _IsReservedCommDeviceName(LPCTSTR lpName)
|
||||
return FALSE;
|
||||
|
||||
/* Serial ports, COM1-9 */
|
||||
for (i=1; i<10; i++)
|
||||
for (i = 1; i < 10; i++)
|
||||
{
|
||||
TCHAR genericName[5];
|
||||
|
||||
if (_stprintf_s(genericName, 5, _T("COM%d"), i) < 0)
|
||||
{
|
||||
return FALSE;
|
||||
@ -1022,9 +1020,10 @@ static BOOL _IsReservedCommDeviceName(LPCTSTR lpName)
|
||||
}
|
||||
|
||||
/* Parallel ports, LPT1-9 */
|
||||
for (i=1; i<10; i++)
|
||||
for (i = 1; i < 10; i++)
|
||||
{
|
||||
TCHAR genericName[5];
|
||||
|
||||
if (_stprintf_s(genericName, 5, _T("LPT%d"), i) < 0)
|
||||
{
|
||||
return FALSE;
|
||||
@ -1035,7 +1034,6 @@ static BOOL _IsReservedCommDeviceName(LPCTSTR lpName)
|
||||
}
|
||||
|
||||
/* FIXME: what about PRN ? */
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
@ -1049,7 +1047,8 @@ static BOOL _IsReservedCommDeviceName(LPCTSTR lpName)
|
||||
* ERROR_OUTOFMEMORY was not possible to get mappings.
|
||||
* ERROR_INVALID_DATA was not possible to add the device.
|
||||
*/
|
||||
BOOL DefineCommDevice(/* DWORD dwFlags,*/ LPCTSTR lpDeviceName, LPCTSTR lpTargetPath)
|
||||
BOOL DefineCommDevice(/* DWORD dwFlags,*/ LPCTSTR lpDeviceName,
|
||||
LPCTSTR lpTargetPath)
|
||||
{
|
||||
int i = 0;
|
||||
LPTSTR storedDeviceName = NULL;
|
||||
@ -1076,6 +1075,7 @@ BOOL DefineCommDevice(/* DWORD dwFlags,*/ LPCTSTR lpDeviceName, LPCTSTR lpTarget
|
||||
}
|
||||
|
||||
storedDeviceName = _tcsdup(lpDeviceName);
|
||||
|
||||
if (storedDeviceName == NULL)
|
||||
{
|
||||
SetLastError(ERROR_OUTOFMEMORY);
|
||||
@ -1083,13 +1083,14 @@ BOOL DefineCommDevice(/* DWORD dwFlags,*/ LPCTSTR lpDeviceName, LPCTSTR lpTarget
|
||||
}
|
||||
|
||||
storedTargetPath = _tcsdup(lpTargetPath);
|
||||
|
||||
if (storedTargetPath == NULL)
|
||||
{
|
||||
SetLastError(ERROR_OUTOFMEMORY);
|
||||
goto error_handle;
|
||||
}
|
||||
|
||||
for (i=0; i<COMM_DEVICE_MAX; i++)
|
||||
for (i = 0; i < COMM_DEVICE_MAX; i++)
|
||||
{
|
||||
if (_CommDevices[i] != NULL)
|
||||
{
|
||||
@ -1100,7 +1101,6 @@ BOOL DefineCommDevice(/* DWORD dwFlags,*/ LPCTSTR lpDeviceName, LPCTSTR lpTarget
|
||||
free(_CommDevices[i]->path);
|
||||
_CommDevices[i]->name = storedDeviceName;
|
||||
_CommDevices[i]->path = storedTargetPath;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -1108,6 +1108,7 @@ BOOL DefineCommDevice(/* DWORD dwFlags,*/ LPCTSTR lpDeviceName, LPCTSTR lpTarget
|
||||
{
|
||||
/* new emplacement */
|
||||
_CommDevices[i] = (COMM_DEVICE*)calloc(1, sizeof(COMM_DEVICE));
|
||||
|
||||
if (_CommDevices[i] == NULL)
|
||||
{
|
||||
SetLastError(ERROR_OUTOFMEMORY);
|
||||
@ -1128,12 +1129,9 @@ BOOL DefineCommDevice(/* DWORD dwFlags,*/ LPCTSTR lpDeviceName, LPCTSTR lpTarget
|
||||
|
||||
LeaveCriticalSection(&_CommDevicesLock);
|
||||
return TRUE;
|
||||
|
||||
|
||||
error_handle:
|
||||
free(storedDeviceName);
|
||||
free(storedTargetPath);
|
||||
|
||||
LeaveCriticalSection(&_CommDevicesLock);
|
||||
return FALSE;
|
||||
}
|
||||
@ -1159,7 +1157,6 @@ DWORD QueryCommDevice(LPCTSTR lpDeviceName, LPTSTR lpTargetPath, DWORD ucchMax)
|
||||
{
|
||||
int i;
|
||||
LPTSTR storedTargetPath;
|
||||
|
||||
SetLastError(ERROR_SUCCESS);
|
||||
|
||||
if (!CommInitialized())
|
||||
@ -1178,9 +1175,9 @@ DWORD QueryCommDevice(LPCTSTR lpDeviceName, LPTSTR lpTargetPath, DWORD ucchMax)
|
||||
}
|
||||
|
||||
EnterCriticalSection(&_CommDevicesLock);
|
||||
|
||||
storedTargetPath = NULL;
|
||||
for (i=0; i<COMM_DEVICE_MAX; i++)
|
||||
|
||||
for (i = 0; i < COMM_DEVICE_MAX; i++)
|
||||
{
|
||||
if (_CommDevices[i] != NULL)
|
||||
{
|
||||
@ -1212,7 +1209,6 @@ DWORD QueryCommDevice(LPCTSTR lpDeviceName, LPTSTR lpTargetPath, DWORD ucchMax)
|
||||
|
||||
_tcscpy(lpTargetPath, storedTargetPath);
|
||||
lpTargetPath[_tcslen(storedTargetPath) + 1] = '\0'; /* 2nd final '\0' */
|
||||
|
||||
return _tcslen(lpTargetPath) + 2;
|
||||
}
|
||||
|
||||
@ -1257,11 +1253,12 @@ void _comm_setServerSerialDriver(HANDLE hComm, SERIAL_DRIVER_ID driverId)
|
||||
pComm->serverSerialDriverId = driverId;
|
||||
}
|
||||
|
||||
static HANDLE_OPS ops = {
|
||||
CommIsHandled,
|
||||
CommCloseHandle,
|
||||
CommGetFd,
|
||||
NULL /* CleanupHandle */
|
||||
static HANDLE_OPS ops =
|
||||
{
|
||||
CommIsHandled,
|
||||
CommCloseHandle,
|
||||
CommGetFd,
|
||||
NULL /* CleanupHandle */
|
||||
};
|
||||
|
||||
|
||||
@ -1290,8 +1287,9 @@ static HANDLE_OPS ops = {
|
||||
*
|
||||
* @return INVALID_HANDLE_VALUE on error.
|
||||
*/
|
||||
HANDLE CommCreateFileA(LPCSTR lpDeviceName, DWORD dwDesiredAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes,
|
||||
DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile)
|
||||
HANDLE CommCreateFileA(LPCSTR lpDeviceName, DWORD dwDesiredAccess,
|
||||
DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes,
|
||||
DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile)
|
||||
{
|
||||
CHAR devicePath[MAX_PATH];
|
||||
struct stat deviceStat;
|
||||
@ -1300,10 +1298,11 @@ HANDLE CommCreateFileA(LPCSTR lpDeviceName, DWORD dwDesiredAccess, DWORD dwShare
|
||||
|
||||
if (!CommInitialized())
|
||||
return INVALID_HANDLE_VALUE;
|
||||
|
||||
|
||||
if (dwDesiredAccess != (GENERIC_READ | GENERIC_WRITE))
|
||||
{
|
||||
CommLog_Print(WLOG_WARN, "unexpected access to the device: 0x%lX", dwDesiredAccess);
|
||||
CommLog_Print(WLOG_WARN, "unexpected access to the device: 0x%lX",
|
||||
dwDesiredAccess);
|
||||
}
|
||||
|
||||
if (dwShareMode != 0)
|
||||
@ -1313,11 +1312,12 @@ HANDLE CommCreateFileA(LPCSTR lpDeviceName, DWORD dwDesiredAccess, DWORD dwShare
|
||||
}
|
||||
|
||||
/* TODO: Prevents other processes from opening a file or
|
||||
* device if they request delete, read, or write access. */
|
||||
* device if they request delete, read, or write access. */
|
||||
|
||||
if (lpSecurityAttributes != NULL)
|
||||
{
|
||||
CommLog_Print(WLOG_WARN, "unexpected security attributes, nLength=%lu", lpSecurityAttributes->nLength);
|
||||
CommLog_Print(WLOG_WARN, "unexpected security attributes, nLength=%lu",
|
||||
lpSecurityAttributes->nLength);
|
||||
}
|
||||
|
||||
if (dwCreationDisposition != OPEN_EXISTING)
|
||||
@ -1348,7 +1348,8 @@ HANDLE CommCreateFileA(LPCSTR lpDeviceName, DWORD dwDesiredAccess, DWORD dwShare
|
||||
|
||||
if (dwFlagsAndAttributes != 0)
|
||||
{
|
||||
CommLog_Print(WLOG_WARN, "unexpected flags and attributes: 0x%lX", dwFlagsAndAttributes);
|
||||
CommLog_Print(WLOG_WARN, "unexpected flags and attributes: 0x%lX",
|
||||
dwFlagsAndAttributes);
|
||||
}
|
||||
|
||||
if (hTemplateFile != NULL)
|
||||
@ -1358,6 +1359,7 @@ HANDLE CommCreateFileA(LPCSTR lpDeviceName, DWORD dwDesiredAccess, DWORD dwShare
|
||||
}
|
||||
|
||||
pComm = (WINPR_COMM*) calloc(1, sizeof(WINPR_COMM));
|
||||
|
||||
if (pComm == NULL)
|
||||
{
|
||||
SetLastError(ERROR_OUTOFMEMORY);
|
||||
@ -1365,12 +1367,10 @@ HANDLE CommCreateFileA(LPCSTR lpDeviceName, DWORD dwDesiredAccess, DWORD dwShare
|
||||
}
|
||||
|
||||
WINPR_HANDLE_SET_TYPE_AND_MODE(pComm, HANDLE_TYPE_COMM, WINPR_FD_READ);
|
||||
|
||||
pComm->ops = &ops;
|
||||
|
||||
/* error_handle */
|
||||
|
||||
pComm->fd = open(devicePath, O_RDWR | O_NOCTTY | O_NONBLOCK);
|
||||
|
||||
if (pComm->fd < 0)
|
||||
{
|
||||
CommLog_Print(WLOG_WARN, "failed to open device %s", devicePath);
|
||||
@ -1379,6 +1379,7 @@ HANDLE CommCreateFileA(LPCSTR lpDeviceName, DWORD dwDesiredAccess, DWORD dwShare
|
||||
}
|
||||
|
||||
pComm->fd_read = open(devicePath, O_RDONLY | O_NOCTTY | O_NONBLOCK);
|
||||
|
||||
if (pComm->fd_read < 0)
|
||||
{
|
||||
CommLog_Print(WLOG_WARN, "failed to open fd_read, device: %s", devicePath);
|
||||
@ -1386,17 +1387,20 @@ HANDLE CommCreateFileA(LPCSTR lpDeviceName, DWORD dwDesiredAccess, DWORD dwShare
|
||||
goto error_handle;
|
||||
}
|
||||
|
||||
pComm->fd_read_event = eventfd(0, EFD_NONBLOCK); /* EFD_NONBLOCK required because a read() is not always expected */
|
||||
pComm->fd_read_event = eventfd(0,
|
||||
EFD_NONBLOCK); /* EFD_NONBLOCK required because a read() is not always expected */
|
||||
|
||||
if (pComm->fd_read_event < 0)
|
||||
{
|
||||
CommLog_Print(WLOG_WARN, "failed to open fd_read_event, device: %s", devicePath);
|
||||
CommLog_Print(WLOG_WARN, "failed to open fd_read_event, device: %s",
|
||||
devicePath);
|
||||
SetLastError(ERROR_BAD_DEVICE);
|
||||
goto error_handle;
|
||||
}
|
||||
|
||||
InitializeCriticalSection(&pComm->ReadLock);
|
||||
|
||||
pComm->fd_write = open(devicePath, O_WRONLY | O_NOCTTY | O_NONBLOCK);
|
||||
|
||||
if (pComm->fd_write < 0)
|
||||
{
|
||||
CommLog_Print(WLOG_WARN, "failed to open fd_write, device: %s", devicePath);
|
||||
@ -1404,60 +1408,59 @@ HANDLE CommCreateFileA(LPCSTR lpDeviceName, DWORD dwDesiredAccess, DWORD dwShare
|
||||
goto error_handle;
|
||||
}
|
||||
|
||||
pComm->fd_write_event = eventfd(0, EFD_NONBLOCK); /* EFD_NONBLOCK required because a read() is not always expected */
|
||||
pComm->fd_write_event = eventfd(0,
|
||||
EFD_NONBLOCK); /* EFD_NONBLOCK required because a read() is not always expected */
|
||||
|
||||
if (pComm->fd_write_event < 0)
|
||||
{
|
||||
CommLog_Print(WLOG_WARN, "failed to open fd_write_event, device: %s", devicePath);
|
||||
CommLog_Print(WLOG_WARN, "failed to open fd_write_event, device: %s",
|
||||
devicePath);
|
||||
SetLastError(ERROR_BAD_DEVICE);
|
||||
goto error_handle;
|
||||
}
|
||||
|
||||
InitializeCriticalSection(&pComm->WriteLock);
|
||||
|
||||
/* can also be setup later on with _comm_setServerSerialDriver() */
|
||||
pComm->serverSerialDriverId = SerialDriverUnknown;
|
||||
|
||||
InitializeCriticalSection(&pComm->EventsLock);
|
||||
|
||||
if (ioctl(pComm->fd, TIOCGICOUNT, &(pComm->counters)) < 0)
|
||||
{
|
||||
CommLog_Print(WLOG_WARN, "TIOCGICOUNT ioctl failed, errno=[%d] %s.", errno, strerror(errno));
|
||||
CommLog_Print(WLOG_WARN, "TIOCGICOUNT ioctl failed, errno=[%d] %s.", errno,
|
||||
strerror(errno));
|
||||
CommLog_Print(WLOG_WARN, "could not read counters.");
|
||||
|
||||
/* could not initialize counters but keep on.
|
||||
/* could not initialize counters but keep on.
|
||||
*
|
||||
* Not all drivers, especially for USB to serial
|
||||
* adapters (e.g. those based on pl2303), does support
|
||||
* this call.
|
||||
*/
|
||||
|
||||
ZeroMemory(&(pComm->counters), sizeof(struct serial_icounter_struct));
|
||||
}
|
||||
|
||||
|
||||
/* The binary/raw mode is required for the redirection but
|
||||
* only flags that are not handle somewhere-else, except
|
||||
* ICANON, are forced here. */
|
||||
|
||||
ZeroMemory(&upcomingTermios, sizeof(struct termios));
|
||||
|
||||
if (tcgetattr(pComm->fd, &upcomingTermios) < 0)
|
||||
{
|
||||
SetLastError(ERROR_IO_DEVICE);
|
||||
goto error_handle;
|
||||
}
|
||||
|
||||
upcomingTermios.c_iflag &= ~(/*IGNBRK |*/ BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL /*| IXON*/);
|
||||
upcomingTermios.c_iflag &= ~(/*IGNBRK |*/ BRKINT | PARMRK | ISTRIP | INLCR |
|
||||
IGNCR | ICRNL /*| IXON*/);
|
||||
upcomingTermios.c_oflag = 0; /* <=> &= ~OPOST */
|
||||
upcomingTermios.c_lflag = 0; /* <=> &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN); */
|
||||
upcomingTermios.c_lflag =
|
||||
0; /* <=> &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN); */
|
||||
/* upcomingTermios.c_cflag &= ~(CSIZE | PARENB); */
|
||||
/* upcomingTermios.c_cflag |= CS8; */
|
||||
|
||||
/* About missing flags recommended by termios(3):
|
||||
*
|
||||
* IGNBRK and IXON, see: IOCTL_SERIAL_SET_HANDFLOW
|
||||
* CSIZE, PARENB and CS8, see: IOCTL_SERIAL_SET_LINE_CONTROL
|
||||
*/
|
||||
|
||||
/* a few more settings required for the redirection */
|
||||
upcomingTermios.c_cflag |= CLOCAL | CREAD;
|
||||
|
||||
@ -1468,29 +1471,28 @@ HANDLE CommCreateFileA(LPCSTR lpDeviceName, DWORD dwDesiredAccess, DWORD dwShare
|
||||
}
|
||||
|
||||
return (HANDLE)pComm;
|
||||
error_handle:
|
||||
|
||||
|
||||
error_handle:
|
||||
if (pComm != NULL)
|
||||
{
|
||||
CloseHandle(pComm);
|
||||
}
|
||||
|
||||
|
||||
return INVALID_HANDLE_VALUE;
|
||||
}
|
||||
|
||||
|
||||
BOOL CommIsHandled(HANDLE handle)
|
||||
{
|
||||
WINPR_COMM *pComm;
|
||||
WINPR_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;
|
||||
@ -1501,7 +1503,7 @@ BOOL CommIsHandled(HANDLE handle)
|
||||
|
||||
BOOL CommCloseHandle(HANDLE handle)
|
||||
{
|
||||
WINPR_COMM *pComm;
|
||||
WINPR_COMM* pComm;
|
||||
|
||||
if (!CommInitialized())
|
||||
return FALSE;
|
||||
@ -1520,7 +1522,8 @@ BOOL CommCloseHandle(HANDLE handle)
|
||||
DWORD BytesReturned = 0;
|
||||
|
||||
/* ensures to gracefully stop the WAIT_ON_MASK's loop */
|
||||
if (!CommDeviceIoControl(handle, IOCTL_SERIAL_SET_WAIT_MASK, &WaitMask, sizeof(ULONG), NULL, 0, &BytesReturned, NULL))
|
||||
if (!CommDeviceIoControl(handle, IOCTL_SERIAL_SET_WAIT_MASK, &WaitMask,
|
||||
sizeof(ULONG), NULL, 0, &BytesReturned, NULL))
|
||||
{
|
||||
CommLog_Print(WLOG_WARN, "failure to WAIT_ON_MASK's loop!");
|
||||
}
|
||||
@ -1546,7 +1549,6 @@ BOOL CommCloseHandle(HANDLE handle)
|
||||
close(pComm->fd_read_event);
|
||||
|
||||
free(pComm);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
@ -63,7 +63,8 @@ struct winpr_comm
|
||||
|
||||
COMMTIMEOUTS timeouts;
|
||||
|
||||
CRITICAL_SECTION EventsLock; /* protects counters, WaitEventMask and PendingEvents */
|
||||
CRITICAL_SECTION
|
||||
EventsLock; /* protects counters, WaitEventMask and PendingEvents */
|
||||
struct serial_icounter_struct counters;
|
||||
ULONG WaitEventMask;
|
||||
ULONG PendingEvents;
|
||||
@ -93,7 +94,7 @@ typedef struct winpr_comm WINPR_COMM;
|
||||
#define FREERDP_PURGE_RXABORT 0x00000002 /* abort pending reception */
|
||||
|
||||
|
||||
void CommLog_Print(int wlog_level, char *fmt, ...);
|
||||
void CommLog_Print(int wlog_level, ...);
|
||||
|
||||
BOOL CommIsHandled(HANDLE handle);
|
||||
BOOL CommCloseHandle(HANDLE handle);
|
||||
|
@ -41,8 +41,8 @@ BOOL _comm_set_permissive(HANDLE hDevice, BOOL permissive)
|
||||
if (hDevice == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
SetLastError(ERROR_INVALID_HANDLE);
|
||||
return FALSE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!pComm || pComm->Type != HANDLE_TYPE_COMM)
|
||||
{
|
||||
@ -67,7 +67,7 @@ static UCHAR _vtime(ULONG Ti)
|
||||
else if (Ti > 25500)
|
||||
return 255; /* 0xFF */
|
||||
else
|
||||
return Ti/100;
|
||||
return Ti / 100;
|
||||
}
|
||||
|
||||
|
||||
@ -81,26 +81,25 @@ static UCHAR _vtime(ULONG Ti)
|
||||
* ERROR_BAD_DEVICE
|
||||
*/
|
||||
BOOL CommReadFile(HANDLE hDevice, LPVOID lpBuffer, DWORD nNumberOfBytesToRead,
|
||||
LPDWORD lpNumberOfBytesRead, LPOVERLAPPED lpOverlapped)
|
||||
LPDWORD lpNumberOfBytesRead, LPOVERLAPPED lpOverlapped)
|
||||
{
|
||||
WINPR_COMM* pComm = (WINPR_COMM*) hDevice;
|
||||
int biggestFd = -1;
|
||||
fd_set read_set;
|
||||
int nbFds;
|
||||
COMMTIMEOUTS *pTimeouts;
|
||||
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)
|
||||
{
|
||||
@ -116,7 +115,8 @@ BOOL CommReadFile(HANDLE hDevice, LPVOID lpBuffer, DWORD nNumberOfBytesToRead,
|
||||
|
||||
if (lpNumberOfBytesRead == NULL)
|
||||
{
|
||||
SetLastError(ERROR_INVALID_PARAMETER); /* since we doesn't suppport lpOverlapped != NULL */
|
||||
SetLastError(
|
||||
ERROR_INVALID_PARAMETER); /* since we doesn't suppport lpOverlapped != NULL */
|
||||
goto return_false;
|
||||
}
|
||||
|
||||
@ -135,7 +135,8 @@ BOOL CommReadFile(HANDLE hDevice, LPVOID lpBuffer, DWORD nNumberOfBytesToRead,
|
||||
|
||||
if (currentTermios.c_lflag & ICANON)
|
||||
{
|
||||
CommLog_Print(WLOG_WARN, "Canonical mode not supported"); /* the timeout could not be set */
|
||||
CommLog_Print(WLOG_WARN,
|
||||
"Canonical mode not supported"); /* the timeout could not be set */
|
||||
SetLastError(ERROR_NOT_SUPPORTED);
|
||||
goto return_false;
|
||||
}
|
||||
@ -145,30 +146,31 @@ BOOL CommReadFile(HANDLE hDevice, LPVOID lpBuffer, DWORD nNumberOfBytesToRead,
|
||||
*
|
||||
* ReadIntervalTimeout | ReadTotalTimeoutMultiplier | ReadTotalTimeoutConstant | VMIN | VTIME | TMAX |
|
||||
* 0 | 0 | 0 | N | 0 | INDEF | Blocks for N bytes available.
|
||||
* 0< Ti <MAXULONG | 0 | 0 | N | Ti | INDEF | Blocks on first byte, then use Ti between bytes.
|
||||
* 0< Ti <MAXULONG | 0 | 0 | N | Ti | INDEF | Blocks on first byte, then use Ti between bytes.
|
||||
* MAXULONG | 0 | 0 | 0 | 0 | 0 | Returns immediately with bytes available (don't block)
|
||||
* MAXULONG | MAXULONG | 0< Tc <MAXULONG | N | 0 | Tc | Blocks on first byte during Tc or returns immediately whith bytes available
|
||||
* MAXULONG | m | MAXULONG | | Invalid
|
||||
* 0 | m | 0< Tc <MAXULONG | N | 0 | Tmax | Blocks on first byte during Tmax or returns immediately whith bytes available
|
||||
* 0< Ti <MAXULONG | m | 0< Tc <MAXULONG | N | Ti | Tmax | Blocks on first byte, then use Ti between bytes. Tmax is used for the whole system call.
|
||||
*/
|
||||
|
||||
/* NB: timeouts are in milliseconds, VTIME are in deciseconds and is an unsigned char */
|
||||
|
||||
/* FIXME: double check whether open(pComm->fd_read_event, O_NONBLOCK) doesn't conflict with above use cases */
|
||||
|
||||
pTimeouts = &(pComm->timeouts);
|
||||
|
||||
if ((pTimeouts->ReadIntervalTimeout == MAXULONG) && (pTimeouts->ReadTotalTimeoutConstant == MAXULONG))
|
||||
if ((pTimeouts->ReadIntervalTimeout == MAXULONG)
|
||||
&& (pTimeouts->ReadTotalTimeoutConstant == MAXULONG))
|
||||
{
|
||||
CommLog_Print(WLOG_WARN, "ReadIntervalTimeout and ReadTotalTimeoutConstant cannot be both set to MAXULONG");
|
||||
CommLog_Print(WLOG_WARN,
|
||||
"ReadIntervalTimeout and ReadTotalTimeoutConstant cannot be both set to MAXULONG");
|
||||
SetLastError(ERROR_INVALID_PARAMETER);
|
||||
goto return_false;
|
||||
}
|
||||
|
||||
/* VMIN */
|
||||
|
||||
if ((pTimeouts->ReadIntervalTimeout == MAXULONG) && (pTimeouts->ReadTotalTimeoutMultiplier == 0) && (pTimeouts->ReadTotalTimeoutConstant == 0))
|
||||
if ((pTimeouts->ReadIntervalTimeout == MAXULONG)
|
||||
&& (pTimeouts->ReadTotalTimeoutMultiplier == 0)
|
||||
&& (pTimeouts->ReadTotalTimeoutConstant == 0))
|
||||
{
|
||||
vmin = 0;
|
||||
}
|
||||
@ -176,28 +178,26 @@ BOOL CommReadFile(HANDLE hDevice, LPVOID lpBuffer, DWORD nNumberOfBytesToRead,
|
||||
{
|
||||
/* N */
|
||||
/* vmin = nNumberOfBytesToRead < 256 ? nNumberOfBytesToRead : 255;*/ /* 0xFF */
|
||||
|
||||
/* NB: we might wait endlessly with vmin=N, prefer to
|
||||
* force vmin=1 and return with bytes
|
||||
* available. FIXME: is a feature disarded here? */
|
||||
vmin = 1;
|
||||
}
|
||||
|
||||
|
||||
/* VTIME */
|
||||
|
||||
if ((pTimeouts->ReadIntervalTimeout > 0) && (pTimeouts->ReadIntervalTimeout < MAXULONG))
|
||||
if ((pTimeouts->ReadIntervalTimeout > 0)
|
||||
&& (pTimeouts->ReadIntervalTimeout < MAXULONG))
|
||||
{
|
||||
/* Ti */
|
||||
vtime = _vtime(pTimeouts->ReadIntervalTimeout);
|
||||
}
|
||||
|
||||
|
||||
/* TMAX */
|
||||
pTmaxTimeout = &tmaxTimeout;
|
||||
|
||||
pTmaxTimeout = &tmaxTimeout;
|
||||
|
||||
if ((pTimeouts->ReadIntervalTimeout == MAXULONG) && (pTimeouts->ReadTotalTimeoutMultiplier == MAXULONG))
|
||||
if ((pTimeouts->ReadIntervalTimeout == MAXULONG)
|
||||
&& (pTimeouts->ReadTotalTimeoutMultiplier == MAXULONG))
|
||||
{
|
||||
/* Tc */
|
||||
Tmax = pTimeouts->ReadTotalTimeoutConstant;
|
||||
@ -205,60 +205,64 @@ BOOL CommReadFile(HANDLE hDevice, LPVOID lpBuffer, DWORD nNumberOfBytesToRead,
|
||||
else
|
||||
{
|
||||
/* Tmax */
|
||||
Tmax = nNumberOfBytesToRead * pTimeouts->ReadTotalTimeoutMultiplier + pTimeouts->ReadTotalTimeoutConstant;
|
||||
Tmax = nNumberOfBytesToRead * pTimeouts->ReadTotalTimeoutMultiplier +
|
||||
pTimeouts->ReadTotalTimeoutConstant;
|
||||
|
||||
/* INDEFinitely */
|
||||
if((Tmax == 0) && (pTimeouts->ReadIntervalTimeout < MAXULONG) && (pTimeouts->ReadTotalTimeoutMultiplier == 0))
|
||||
if ((Tmax == 0) && (pTimeouts->ReadIntervalTimeout < MAXULONG)
|
||||
&& (pTimeouts->ReadTotalTimeoutMultiplier == 0))
|
||||
pTmaxTimeout = NULL;
|
||||
}
|
||||
|
||||
if ((currentTermios.c_cc[VMIN] != vmin) || (currentTermios.c_cc[VTIME] != vtime))
|
||||
if ((currentTermios.c_cc[VMIN] != vmin)
|
||||
|| (currentTermios.c_cc[VTIME] != vtime))
|
||||
{
|
||||
currentTermios.c_cc[VMIN] = vmin;
|
||||
currentTermios.c_cc[VTIME] = vtime;
|
||||
|
||||
if (tcsetattr(pComm->fd, TCSANOW, ¤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;
|
||||
}
|
||||
@ -266,12 +270,10 @@ BOOL CommReadFile(HANDLE hDevice, LPVOID lpBuffer, DWORD nNumberOfBytesToRead,
|
||||
if (nbFds == 0)
|
||||
{
|
||||
/* timeout */
|
||||
|
||||
SetLastError(ERROR_TIMEOUT);
|
||||
goto return_false;
|
||||
}
|
||||
|
||||
|
||||
/* read_set */
|
||||
|
||||
if (FD_ISSET(pComm->fd_read_event, &read_set))
|
||||
@ -287,7 +289,9 @@ BOOL CommReadFile(HANDLE hDevice, LPVOID lpBuffer, DWORD nNumberOfBytesToRead,
|
||||
}
|
||||
else
|
||||
{
|
||||
CommLog_Print(WLOG_WARN, "unexpected error on reading fd_read_event, errno=[%d] %s\n", errno, strerror(errno));
|
||||
CommLog_Print(WLOG_WARN,
|
||||
"unexpected error on reading fd_read_event, errno=[%d] %s\n", errno,
|
||||
strerror(errno));
|
||||
/* FIXME: goto return_false ? */
|
||||
}
|
||||
|
||||
@ -303,18 +307,21 @@ BOOL CommReadFile(HANDLE hDevice, LPVOID lpBuffer, DWORD nNumberOfBytesToRead,
|
||||
assert(event == FREERDP_PURGE_RXABORT); /* no other expected event so far */
|
||||
}
|
||||
|
||||
|
||||
if (FD_ISSET(pComm->fd_read, &read_set))
|
||||
{
|
||||
ssize_t nbRead = 0;
|
||||
|
||||
nbRead = read(pComm->fd_read, lpBuffer, nNumberOfBytesToRead);
|
||||
|
||||
if (nbRead < 0)
|
||||
{
|
||||
CommLog_Print(WLOG_WARN, "CommReadFile failed, ReadIntervalTimeout=%lu, ReadTotalTimeoutMultiplier=%lu, ReadTotalTimeoutConstant=%lu VMIN=%u, VTIME=%u",
|
||||
pTimeouts->ReadIntervalTimeout, pTimeouts->ReadTotalTimeoutMultiplier, pTimeouts->ReadTotalTimeoutConstant,
|
||||
currentTermios.c_cc[VMIN], currentTermios.c_cc[VTIME]);
|
||||
CommLog_Print(WLOG_WARN, "CommReadFile failed, nNumberOfBytesToRead=%lu, errno=[%d] %s", nNumberOfBytesToRead, errno, strerror(errno));
|
||||
CommLog_Print(WLOG_WARN,
|
||||
"CommReadFile failed, ReadIntervalTimeout=%lu, ReadTotalTimeoutMultiplier=%lu, ReadTotalTimeoutConstant=%lu VMIN=%u, VTIME=%u",
|
||||
pTimeouts->ReadIntervalTimeout, pTimeouts->ReadTotalTimeoutMultiplier,
|
||||
pTimeouts->ReadTotalTimeoutConstant,
|
||||
currentTermios.c_cc[VMIN], currentTermios.c_cc[VTIME]);
|
||||
CommLog_Print(WLOG_WARN,
|
||||
"CommReadFile failed, nNumberOfBytesToRead=%lu, errno=[%d] %s",
|
||||
nNumberOfBytesToRead, errno, strerror(errno));
|
||||
|
||||
if (errno == EAGAIN)
|
||||
{
|
||||
@ -347,12 +354,10 @@ BOOL CommReadFile(HANDLE hDevice, LPVOID lpBuffer, DWORD nNumberOfBytesToRead,
|
||||
|
||||
assert(FALSE);
|
||||
*lpNumberOfBytesRead = 0;
|
||||
|
||||
return_false:
|
||||
return_false:
|
||||
LeaveCriticalSection(&pComm->ReadLock);
|
||||
return FALSE;
|
||||
|
||||
return_true:
|
||||
return_true:
|
||||
LeaveCriticalSection(&pComm->ReadLock);
|
||||
return TRUE;
|
||||
}
|
||||
@ -365,19 +370,20 @@ BOOL CommReadFile(HANDLE hDevice, LPVOID lpBuffer, DWORD nNumberOfBytesToRead,
|
||||
* ERROR_INVALID_PARAMETER
|
||||
* ERROR_BAD_DEVICE
|
||||
*/
|
||||
BOOL CommWriteFile(HANDLE hDevice, LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite,
|
||||
LPDWORD lpNumberOfBytesWritten, LPOVERLAPPED lpOverlapped)
|
||||
BOOL CommWriteFile(HANDLE hDevice, LPCVOID lpBuffer,
|
||||
DWORD nNumberOfBytesToWrite,
|
||||
LPDWORD lpNumberOfBytesWritten, LPOVERLAPPED lpOverlapped)
|
||||
{
|
||||
WINPR_COMM* pComm = (WINPR_COMM*) hDevice;
|
||||
struct timeval tmaxTimeout, *pTmaxTimeout;
|
||||
|
||||
EnterCriticalSection(&pComm->WriteLock); /* KISSer by the function's beginning */
|
||||
EnterCriticalSection(
|
||||
&pComm->WriteLock); /* KISSer by the function's beginning */
|
||||
|
||||
if (hDevice == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
SetLastError(ERROR_INVALID_HANDLE);
|
||||
goto return_false;
|
||||
}
|
||||
goto return_false;
|
||||
}
|
||||
|
||||
if (!pComm || pComm->Type != HANDLE_TYPE_COMM)
|
||||
{
|
||||
@ -393,7 +399,8 @@ BOOL CommWriteFile(HANDLE hDevice, LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite
|
||||
|
||||
if (lpNumberOfBytesWritten == NULL)
|
||||
{
|
||||
SetLastError(ERROR_INVALID_PARAMETER); /* since we doesn't suppport lpOverlapped != NULL */
|
||||
SetLastError(
|
||||
ERROR_INVALID_PARAMETER); /* since we doesn't suppport lpOverlapped != NULL */
|
||||
goto return_false;
|
||||
}
|
||||
|
||||
@ -408,26 +415,27 @@ BOOL CommWriteFile(HANDLE hDevice, LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite
|
||||
* there is no eventfd_read() but this not the case. */
|
||||
/* discard a possible and no more relevant event */
|
||||
eventfd_read(pComm->fd_write_event, NULL);
|
||||
|
||||
|
||||
/* ms */
|
||||
ULONGLONG Tmax = nNumberOfBytesToWrite * pComm->timeouts.WriteTotalTimeoutMultiplier + pComm->timeouts.WriteTotalTimeoutConstant;
|
||||
|
||||
ULONGLONG Tmax = nNumberOfBytesToWrite *
|
||||
pComm->timeouts.WriteTotalTimeoutMultiplier +
|
||||
pComm->timeouts.WriteTotalTimeoutConstant;
|
||||
/* NB: select() may update the timeout argument to indicate
|
||||
* how much time was left. Keep the timeout variable out of
|
||||
* the while() */
|
||||
|
||||
pTmaxTimeout = &tmaxTimeout;
|
||||
pTmaxTimeout = &tmaxTimeout;
|
||||
ZeroMemory(pTmaxTimeout, sizeof(struct timeval));
|
||||
if (Tmax > 0)
|
||||
|
||||
if (Tmax > 0)
|
||||
{
|
||||
pTmaxTimeout->tv_sec = Tmax / 1000; /* s */
|
||||
pTmaxTimeout->tv_usec = (Tmax % 1000) * 1000; /* us */
|
||||
}
|
||||
else if ((pComm->timeouts.WriteTotalTimeoutMultiplier == 0) && (pComm->timeouts.WriteTotalTimeoutConstant == 0))
|
||||
else if ((pComm->timeouts.WriteTotalTimeoutMultiplier == 0)
|
||||
&& (pComm->timeouts.WriteTotalTimeoutConstant == 0))
|
||||
{
|
||||
pTmaxTimeout = NULL;
|
||||
}
|
||||
|
||||
/* else return immdiately */
|
||||
|
||||
while (*lpNumberOfBytesWritten < nNumberOfBytesToWrite)
|
||||
@ -435,24 +443,23 @@ BOOL CommWriteFile(HANDLE hDevice, LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite
|
||||
int biggestFd = -1;
|
||||
fd_set event_set, write_set;
|
||||
int nbFds;
|
||||
|
||||
biggestFd = pComm->fd_write;
|
||||
|
||||
if (pComm->fd_write_event > biggestFd)
|
||||
biggestFd = pComm->fd_write_event;
|
||||
|
||||
FD_ZERO(&event_set);
|
||||
FD_ZERO(&write_set);
|
||||
|
||||
assert(pComm->fd_write_event < FD_SETSIZE);
|
||||
assert(pComm->fd_write < FD_SETSIZE);
|
||||
|
||||
FD_SET(pComm->fd_write_event, &event_set);
|
||||
FD_SET(pComm->fd_write, &write_set);
|
||||
nbFds = select(biggestFd + 1, &event_set, &write_set, NULL, pTmaxTimeout);
|
||||
|
||||
nbFds = select(biggestFd+1, &event_set, &write_set, NULL, pTmaxTimeout);
|
||||
if (nbFds < 0)
|
||||
{
|
||||
CommLog_Print(WLOG_WARN, "select() failure, errno=[%d] %s\n", errno, strerror(errno));
|
||||
CommLog_Print(WLOG_WARN, "select() failure, errno=[%d] %s\n", errno,
|
||||
strerror(errno));
|
||||
SetLastError(ERROR_IO_DEVICE);
|
||||
goto return_false;
|
||||
}
|
||||
@ -460,12 +467,10 @@ BOOL CommWriteFile(HANDLE hDevice, LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite
|
||||
if (nbFds == 0)
|
||||
{
|
||||
/* timeout */
|
||||
|
||||
SetLastError(ERROR_TIMEOUT);
|
||||
goto return_false;
|
||||
}
|
||||
|
||||
|
||||
/* event_set */
|
||||
|
||||
if (FD_ISSET(pComm->fd_write_event, &event_set))
|
||||
@ -481,7 +486,9 @@ BOOL CommWriteFile(HANDLE hDevice, LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite
|
||||
}
|
||||
else
|
||||
{
|
||||
CommLog_Print(WLOG_WARN, "unexpected error on reading fd_write_event, errno=[%d] %s\n", errno, strerror(errno));
|
||||
CommLog_Print(WLOG_WARN,
|
||||
"unexpected error on reading fd_write_event, errno=[%d] %s\n", errno,
|
||||
strerror(errno));
|
||||
/* FIXME: goto return_false ? */
|
||||
}
|
||||
|
||||
@ -497,20 +504,20 @@ BOOL CommWriteFile(HANDLE hDevice, LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite
|
||||
assert(event == FREERDP_PURGE_TXABORT); /* no other expected event so far */
|
||||
}
|
||||
|
||||
|
||||
/* write_set */
|
||||
|
||||
if (FD_ISSET(pComm->fd_write, &write_set))
|
||||
{
|
||||
ssize_t nbWritten;
|
||||
|
||||
nbWritten = write(pComm->fd_write,
|
||||
lpBuffer + (*lpNumberOfBytesWritten),
|
||||
nNumberOfBytesToWrite - (*lpNumberOfBytesWritten));
|
||||
((BYTE*)lpBuffer) + (*lpNumberOfBytesWritten),
|
||||
nNumberOfBytesToWrite - (*lpNumberOfBytesWritten));
|
||||
|
||||
if (nbWritten < 0)
|
||||
{
|
||||
CommLog_Print(WLOG_WARN, "CommWriteFile failed after %lu bytes written, errno=[%d] %s\n", *lpNumberOfBytesWritten, errno, strerror(errno));
|
||||
CommLog_Print(WLOG_WARN,
|
||||
"CommWriteFile failed after %lu bytes written, errno=[%d] %s\n",
|
||||
*lpNumberOfBytesWritten, errno, strerror(errno));
|
||||
|
||||
if (errno == EAGAIN)
|
||||
{
|
||||
@ -532,10 +539,8 @@ BOOL CommWriteFile(HANDLE hDevice, LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite
|
||||
|
||||
*lpNumberOfBytesWritten += nbWritten;
|
||||
}
|
||||
|
||||
} /* while */
|
||||
|
||||
|
||||
/* FIXME: this call to tcdrain() doesn't look correct and
|
||||
* might hide a bug but was required while testing a serial
|
||||
* printer. Its driver was expecting the modem line status
|
||||
@ -545,13 +550,10 @@ BOOL CommWriteFile(HANDLE hDevice, LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite
|
||||
* DesiredAccess=0x0012019F. The printer worked fine with
|
||||
* mstsc. */
|
||||
tcdrain(pComm->fd_write);
|
||||
|
||||
|
||||
return_true:
|
||||
return_true:
|
||||
LeaveCriticalSection(&pComm->WriteLock);
|
||||
return TRUE;
|
||||
|
||||
return_false:
|
||||
return_false:
|
||||
LeaveCriticalSection(&pComm->WriteLock);
|
||||
return FALSE;
|
||||
}
|
||||
|
@ -84,33 +84,39 @@ static BOOL log_recursion(LPCSTR file, LPCSTR fkt, int line)
|
||||
|
||||
if (!bt)
|
||||
return FALSE;
|
||||
|
||||
msg = winpr_backtrace_symbols(bt, &used);
|
||||
|
||||
if (!msg)
|
||||
return FALSE;
|
||||
|
||||
#if defined(ANDROID)
|
||||
|
||||
if (__android_log_print(ANDROID_LOG_FATAL, tag, "Recursion detected!!!") < 0)
|
||||
return FALSE;
|
||||
if (__android_log_print(ANDROID_LOG_FATAL, tag, "Check %s [%s:%d]", fkt, file, line) < 0)
|
||||
|
||||
if (__android_log_print(ANDROID_LOG_FATAL, tag, "Check %s [%s:%d]", fkt, file,
|
||||
line) < 0)
|
||||
return FALSE;
|
||||
|
||||
for (i=0; i<used; i++)
|
||||
for (i = 0; i < used; i++)
|
||||
if (__android_log_print(ANDROID_LOG_FATAL, tag, "%d: %s", i, msg[i]) < 0)
|
||||
return FALSE;
|
||||
|
||||
#else
|
||||
|
||||
if (fprintf(stderr, "[%s]: Recursion detected!\n", fkt) < 0)
|
||||
return FALSE;
|
||||
|
||||
if (fprintf(stderr, "[%s]: Check %s:%d\n", fkt, file, line) < 0)
|
||||
return FALSE;
|
||||
|
||||
for (i=0; i<used; i++)
|
||||
for (i = 0; i < used; i++)
|
||||
if (fprintf(stderr, "%s: %lu: %s\n", fkt, (unsigned long)i, msg[i]) < 0)
|
||||
return FALSE;
|
||||
|
||||
#endif
|
||||
|
||||
free(msg);
|
||||
|
||||
winpr_backtrace_free(bt);
|
||||
return TRUE;
|
||||
}
|
||||
@ -134,7 +140,8 @@ BOOL WLog_Write(wLog* log, wLogMessage* message)
|
||||
EnterCriticalSection(&appender->lock);
|
||||
|
||||
if (appender->recursive)
|
||||
status = log_recursion(message->FileName, message->FunctionName, message->LineNumber);
|
||||
status = log_recursion(message->FileName, message->FunctionName,
|
||||
message->LineNumber);
|
||||
else
|
||||
{
|
||||
appender->recursive = TRUE;
|
||||
@ -165,7 +172,8 @@ BOOL WLog_WriteData(wLog* log, wLogMessage* message)
|
||||
EnterCriticalSection(&appender->lock);
|
||||
|
||||
if (appender->recursive)
|
||||
status = log_recursion(message->FileName, message->FunctionName, message->LineNumber);
|
||||
status = log_recursion(message->FileName, message->FunctionName,
|
||||
message->LineNumber);
|
||||
else
|
||||
{
|
||||
appender->recursive = TRUE;
|
||||
@ -196,7 +204,8 @@ BOOL WLog_WriteImage(wLog* log, wLogMessage* message)
|
||||
EnterCriticalSection(&appender->lock);
|
||||
|
||||
if (appender->recursive)
|
||||
status = log_recursion(message->FileName, message->FunctionName, message->LineNumber);
|
||||
status = log_recursion(message->FileName, message->FunctionName,
|
||||
message->LineNumber);
|
||||
else
|
||||
{
|
||||
appender->recursive = TRUE;
|
||||
@ -227,7 +236,8 @@ BOOL WLog_WritePacket(wLog* log, wLogMessage* message)
|
||||
EnterCriticalSection(&appender->lock);
|
||||
|
||||
if (appender->recursive)
|
||||
status = log_recursion(message->FileName, message->FunctionName, message->LineNumber);
|
||||
status = log_recursion(message->FileName, message->FunctionName,
|
||||
message->LineNumber);
|
||||
else
|
||||
{
|
||||
appender->recursive = TRUE;
|
||||
@ -239,57 +249,75 @@ BOOL WLog_WritePacket(wLog* log, wLogMessage* message)
|
||||
return status;
|
||||
}
|
||||
|
||||
BOOL WLog_PrintMessageVA(wLog* log, wLogMessage* message, va_list args)
|
||||
BOOL WLog_PrintMessageVA(wLog* log, DWORD type, DWORD level, DWORD line,
|
||||
const char* file, const char* function, va_list args)
|
||||
{
|
||||
BOOL status = FALSE;
|
||||
wLogMessage message = { 0 };
|
||||
message.Level = level;
|
||||
message.LineNumber = line;
|
||||
message.FileName = file;
|
||||
message.FunctionName = function;
|
||||
|
||||
if (message->Type == WLOG_MESSAGE_TEXT)
|
||||
switch (type)
|
||||
{
|
||||
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)
|
||||
{
|
||||
message->Data = va_arg(args, void*);
|
||||
message->Length = va_arg(args, int);
|
||||
status = WLog_WriteData(log, message);
|
||||
}
|
||||
else if (message->Type == WLOG_MESSAGE_IMAGE)
|
||||
{
|
||||
message->ImageData = va_arg(args, void*);
|
||||
message->ImageWidth = va_arg(args, int);
|
||||
message->ImageHeight = va_arg(args, int);
|
||||
message->ImageBpp = va_arg(args, int);
|
||||
status = WLog_WriteImage(log, message);
|
||||
}
|
||||
else if (message->Type == WLOG_MESSAGE_PACKET)
|
||||
{
|
||||
message->PacketData = va_arg(args, void*);
|
||||
message->PacketLength = va_arg(args, int);
|
||||
message->PacketFlags = va_arg(args, int);
|
||||
status = WLog_WritePacket(log, message);
|
||||
case WLOG_MESSAGE_TEXT:
|
||||
message.FormatString = va_arg(args, const char*);
|
||||
|
||||
if (!strchr(message.FormatString, '%'))
|
||||
{
|
||||
message.TextString = (LPSTR) message.FormatString;
|
||||
status = WLog_Write(log, &message);
|
||||
}
|
||||
else
|
||||
{
|
||||
char formattedLogMessage[WLOG_MAX_STRING_SIZE];
|
||||
|
||||
if (wvsnprintfx(formattedLogMessage, WLOG_MAX_STRING_SIZE - 1,
|
||||
message.FormatString, args) < 0)
|
||||
return FALSE;
|
||||
|
||||
message.TextString = formattedLogMessage;
|
||||
status = WLog_Write(log, &message);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case WLOG_MESSAGE_DATA:
|
||||
message.Data = va_arg(args, void*);
|
||||
message.Length = va_arg(args, int);
|
||||
status = WLog_WriteData(log, &message);
|
||||
break;
|
||||
|
||||
case WLOG_MESSAGE_IMAGE:
|
||||
message.ImageData = va_arg(args, void*);
|
||||
message.ImageWidth = va_arg(args, int);
|
||||
message.ImageHeight = va_arg(args, int);
|
||||
message.ImageBpp = va_arg(args, int);
|
||||
status = WLog_WriteImage(log, &message);
|
||||
break;
|
||||
|
||||
case WLOG_MESSAGE_PACKET:
|
||||
message.PacketData = va_arg(args, void*);
|
||||
message.PacketLength = va_arg(args, int);
|
||||
message.PacketFlags = va_arg(args, int);
|
||||
status = WLog_WritePacket(log, &message);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
BOOL WLog_PrintMessage(wLog* log, wLogMessage* message, ...)
|
||||
BOOL WLog_PrintMessage(wLog* log, DWORD type, DWORD level, DWORD line,
|
||||
const char* file, const char* function, ...)
|
||||
{
|
||||
BOOL status;
|
||||
va_list args;
|
||||
va_start(args, message);
|
||||
status = WLog_PrintMessageVA(log, message, args);
|
||||
va_start(args, function);
|
||||
status = WLog_PrintMessageVA(log, type, level, line, file, function, args);
|
||||
va_end(args);
|
||||
return status;
|
||||
}
|
||||
@ -303,16 +331,19 @@ DWORD WLog_GetLogLevel(wLog* log)
|
||||
return log->FilterLevel;
|
||||
else if (log->Level == WLOG_LEVEL_INHERIT)
|
||||
log->Level = WLog_GetLogLevel(log->Parent);
|
||||
|
||||
return log->Level;
|
||||
}
|
||||
|
||||
BOOL WLog_SetStringLogLevel(wLog* log, LPCSTR level)
|
||||
{
|
||||
int lvl;
|
||||
|
||||
if (!log || !level)
|
||||
return FALSE;
|
||||
|
||||
lvl = WLog_ParseLogLevel(level);
|
||||
|
||||
if (lvl < 0)
|
||||
return FALSE;
|
||||
|
||||
@ -349,8 +380,8 @@ BOOL WLog_AddStringLogFilters(LPCSTR filter)
|
||||
return FALSE;
|
||||
|
||||
g_Filters = tmp;
|
||||
|
||||
cp = (LPSTR)_strdup(filter);
|
||||
|
||||
if (!cp)
|
||||
return FALSE;
|
||||
|
||||
@ -360,6 +391,7 @@ BOOL WLog_AddStringLogFilters(LPCSTR filter)
|
||||
do
|
||||
{
|
||||
p = strchr(p, ',');
|
||||
|
||||
if (p)
|
||||
*p = '\0';
|
||||
|
||||
@ -367,7 +399,7 @@ BOOL WLog_AddStringLogFilters(LPCSTR filter)
|
||||
{
|
||||
if (!WLog_ParseFilter(&g_Filters[pos++], filterStr))
|
||||
{
|
||||
free (cp);
|
||||
free(cp);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
@ -383,8 +415,7 @@ BOOL WLog_AddStringLogFilters(LPCSTR filter)
|
||||
while (p != NULL);
|
||||
|
||||
g_FilterCount = size;
|
||||
free (cp);
|
||||
|
||||
free(cp);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@ -434,7 +465,7 @@ BOOL WLog_ParseFilter(wLogFilter* filter, LPCSTR name)
|
||||
int iLevel;
|
||||
count = 1;
|
||||
|
||||
if(!name)
|
||||
if (!name)
|
||||
return FALSE;
|
||||
|
||||
p = (char*) name;
|
||||
@ -449,16 +480,20 @@ BOOL WLog_ParseFilter(wLogFilter* filter, LPCSTR name)
|
||||
}
|
||||
|
||||
names = _strdup(name);
|
||||
|
||||
if (!names)
|
||||
return FALSE;
|
||||
|
||||
filter->NameCount = count;
|
||||
filter->Names = (LPSTR*) calloc((count + 1UL), sizeof(LPSTR));
|
||||
if(!filter->Names)
|
||||
|
||||
if (!filter->Names)
|
||||
{
|
||||
free(names);
|
||||
filter->NameCount = 0;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
filter->Names[count] = NULL;
|
||||
count = 0;
|
||||
p = (char*) names;
|
||||
@ -493,6 +528,7 @@ BOOL WLog_ParseFilter(wLogFilter* filter, LPCSTR name)
|
||||
{
|
||||
if (count < (int) filter->NameCount)
|
||||
filter->Names[count++] = p + 1;
|
||||
|
||||
*p = '\0';
|
||||
p++;
|
||||
}
|
||||
@ -505,10 +541,8 @@ BOOL WLog_ParseFilters(void)
|
||||
BOOL res;
|
||||
char* env;
|
||||
DWORD nSize;
|
||||
|
||||
g_Filters = NULL;
|
||||
g_FilterCount = 0;
|
||||
|
||||
nSize = GetEnvironmentVariableA("WLOG_FILTER", NULL, 0);
|
||||
|
||||
if (nSize < 1)
|
||||
@ -523,9 +557,7 @@ BOOL WLog_ParseFilters(void)
|
||||
return FALSE;
|
||||
|
||||
res = WLog_AddStringLogFilters(env);
|
||||
|
||||
free(env);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
@ -587,15 +619,19 @@ BOOL WLog_ParseName(wLog* log, LPCSTR name)
|
||||
}
|
||||
|
||||
names = _strdup(name);
|
||||
|
||||
if (!names)
|
||||
return FALSE;
|
||||
|
||||
log->NameCount = count;
|
||||
log->Names = (LPSTR*) calloc((count + 1UL), sizeof(LPSTR));
|
||||
if(!log->Names)
|
||||
|
||||
if (!log->Names)
|
||||
{
|
||||
free(names);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
log->Names[count] = NULL;
|
||||
count = 0;
|
||||
p = (char*) names;
|
||||
@ -605,6 +641,7 @@ BOOL WLog_ParseName(wLog* log, LPCSTR name)
|
||||
{
|
||||
if (count < (int) log->NameCount)
|
||||
log->Names[count++] = p + 1;
|
||||
|
||||
*p = '\0';
|
||||
p++;
|
||||
}
|
||||
@ -618,8 +655,8 @@ wLog* WLog_New(LPCSTR name, wLog* rootLogger)
|
||||
char* env = NULL;
|
||||
DWORD nSize;
|
||||
int iLevel;
|
||||
|
||||
log = (wLog*) calloc(1, sizeof(wLog));
|
||||
|
||||
if (!log)
|
||||
return NULL;
|
||||
|
||||
@ -653,6 +690,7 @@ wLog* WLog_New(LPCSTR name, wLog* rootLogger)
|
||||
if (nSize)
|
||||
{
|
||||
env = (LPSTR) malloc(nSize);
|
||||
|
||||
if (!env)
|
||||
goto out_fail;
|
||||
|
||||
@ -677,11 +715,10 @@ wLog* WLog_New(LPCSTR name, wLog* rootLogger)
|
||||
log->Level = (DWORD) iLevel;
|
||||
|
||||
return log;
|
||||
|
||||
out_fail:
|
||||
free (log->Children);
|
||||
free (log->Name);
|
||||
free (log);
|
||||
free(log->Children);
|
||||
free(log->Name);
|
||||
free(log);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -724,6 +761,7 @@ wLog* WLog_GetRoot(void)
|
||||
if (nSize)
|
||||
{
|
||||
env = (LPSTR) malloc(nSize);
|
||||
|
||||
if (!env)
|
||||
goto fail;
|
||||
|
||||
@ -740,13 +778,16 @@ wLog* WLog_GetRoot(void)
|
||||
logAppenderType = WLOG_APPENDER_FILE;
|
||||
else if (_stricmp(env, "BINARY") == 0)
|
||||
logAppenderType = WLOG_APPENDER_BINARY;
|
||||
|
||||
#ifdef HAVE_SYSLOG_H
|
||||
else if (_stricmp(env, "SYSLOG") == 0)
|
||||
logAppenderType = WLOG_APPENDER_SYSLOG;
|
||||
|
||||
#endif /* HAVE_SYSLOG_H */
|
||||
#ifdef HAVE_JOURNALD_H
|
||||
else if (_stricmp(env, "JOURNALD") == 0)
|
||||
logAppenderType = WLOG_APPENDER_JOURNALD;
|
||||
|
||||
#endif
|
||||
else if (_stricmp(env, "UDP") == 0)
|
||||
logAppenderType = WLOG_APPENDER_UDP;
|
||||
@ -759,7 +800,6 @@ wLog* WLog_GetRoot(void)
|
||||
}
|
||||
|
||||
return g_RootLog;
|
||||
|
||||
fail:
|
||||
free(g_RootLog);
|
||||
g_RootLog = NULL;
|
||||
@ -770,24 +810,29 @@ BOOL WLog_AddChild(wLog* parent, wLog* child)
|
||||
{
|
||||
if (parent->ChildrenCount >= parent->ChildrenSize)
|
||||
{
|
||||
wLog **tmp;
|
||||
wLog** tmp;
|
||||
parent->ChildrenSize *= 2;
|
||||
|
||||
if (!parent->ChildrenSize)
|
||||
{
|
||||
if (parent->Children)
|
||||
free (parent->Children);
|
||||
free(parent->Children);
|
||||
|
||||
parent->Children = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
tmp = (wLog**) realloc(parent->Children, sizeof(wLog*) * parent->ChildrenSize);
|
||||
|
||||
if (!tmp)
|
||||
{
|
||||
if (parent->Children)
|
||||
free (parent->Children);
|
||||
free(parent->Children);
|
||||
|
||||
parent->Children = NULL;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
parent->Children = tmp;
|
||||
}
|
||||
}
|
||||
@ -828,28 +873,33 @@ wLog* WLog_FindChild(LPCSTR name)
|
||||
wLog* WLog_Get(LPCSTR name)
|
||||
{
|
||||
wLog* log;
|
||||
|
||||
if (!(log = WLog_FindChild(name)))
|
||||
{
|
||||
wLog* root = WLog_GetRoot();
|
||||
|
||||
if (!root)
|
||||
return NULL;
|
||||
|
||||
if (!(log = WLog_New(name, root)))
|
||||
return NULL;
|
||||
|
||||
if (!WLog_AddChild(root, log))
|
||||
{
|
||||
WLog_Free(log);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
return log;
|
||||
}
|
||||
|
||||
BOOL WLog_Init()
|
||||
BOOL WLog_Init(void)
|
||||
{
|
||||
return WLog_GetRoot() != NULL;
|
||||
}
|
||||
|
||||
BOOL WLog_Uninit()
|
||||
BOOL WLog_Uninit(void)
|
||||
{
|
||||
DWORD index;
|
||||
wLog* child = NULL;
|
||||
|
Loading…
Reference in New Issue
Block a user