diff --git a/.gitignore b/.gitignore index e82f26244..fef711ec2 100644 --- a/.gitignore +++ b/.gitignore @@ -43,6 +43,11 @@ client/X11/xfreerdp.1 *.xcodeproj/ DerivedData/ +# iOS +FreeRDP.build +Debug-* +Release-* + # Windows *.vcxproj *.vcxproj.* @@ -80,7 +85,11 @@ xcode Release Win32 build/ +*.orig default.log *Amplifier XE* *Inspector XE* + +*.cbp +*.txt.user diff --git a/CMakeLists.txt b/CMakeLists.txt index a7ddf8396..22c361b1a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -111,6 +111,10 @@ if(MSVC) message(STATUS "Random freeing errors are a common sign of runtime issues") endif() configure_msvc_runtime() + + if(NOT DEFINED CMAKE_SUPPRESS_REGENERATION) + set(CMAKE_SUPPRESS_REGENERATION ON) + endif() endif() # Compiler-specific flags @@ -166,22 +170,26 @@ if(MSVC) else() set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_X86_") endif() - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_UNICODE") - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_WIN32_WINNT=0x0501") - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_CRT_SECURE_NO_WARNINGS") - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DWIN32_LEAN_AND_MEAN") SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}) SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}) endif() +if(WIN32) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DUNICODE -D_UNICODE") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_WIN32_WINNT=0x0501") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_CRT_SECURE_NO_WARNINGS") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DWIN32_LEAN_AND_MEAN") +endif() + if(IOS) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -isysroot ${CMAKE_IOS_SDK_ROOT}") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -isysroot ${CMAKE_IOS_SDK_ROOT} -g") endif() set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DWINPR_EXPORTS") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DFREERDP_EXPORTS") # Include files +if(NOT IOS) check_include_files(fcntl.h HAVE_FCNTL_H) check_include_files(unistd.h HAVE_UNISTD_H) check_include_files(stdint.h HAVE_STDINT_H) @@ -189,8 +197,19 @@ check_include_files(inttypes.h HAVE_INTTYPES_H) check_include_files(sys/modem.h HAVE_SYS_MODEM_H) check_include_files(sys/filio.h HAVE_SYS_FILIO_H) check_include_files(sys/strtio.h HAVE_SYS_STRTIO_H) +else() +set(HAVE_FCNTL_H 1) +set(HAVE_UNISTD_H 1) +set(HAVE_STDINT_H 1) +set(HAVE_INTTYPES_H 1) +set(HAVE_SYS_FILIO_H 1) +endif() +if(NOT IOS) check_struct_has_member("struct tm" tm_gmtoff time.h HAVE_TM_GMTOFF) +else() +set(HAVE_TM_GMTOFF 1) +endif() # Mac OS X if(APPLE) @@ -199,7 +218,8 @@ if(APPLE) message(STATUS "FREERDP_IOS_EXTERNAL_SSL_PATH not set! Required if openssl is not found in the iOS SDK (which usually isn't") endif() set(CMAKE_FIND_ROOT_PATH ${CMAKE_FIND_ROOT_PATH} ${FREERDP_IOS_EXTERNAL_SSL_PATH}) - else() + set_property(GLOBAL PROPERTY XCODE_ATTRIBUTE_SKIP_INSTALL YES) + else() if(IS_DIRECTORY /opt/local/include) include_directories(/opt/local/include) link_directories(/opt/local/lib) @@ -214,7 +234,11 @@ endif() # Android if(ANDROID) if (NOT FREERDP_ANDROID_EXTERNAL_SSL_PATH) - message(STATUS "FREERDP_ANDROID_EXTERNAL_SSL_PATH not set! - Needs to be set if openssl is not found in the android NDK (which usually isn't)") + if(IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/external/openssl") + set(FREERDP_ANDROID_EXTERNAL_SSL_PATH "${CMAKE_CURRENT_SOURCE_DIR}/external/openssl") + else() + message(STATUS "FREERDP_ANDROID_EXTERNAL_SSL_PATH not set! - Needs to be set if openssl is not found in the android NDK (which usually isn't)") + endif() endif() set(CMAKE_FIND_ROOT_PATH ${CMAKE_FIND_ROOT_PATH} ${FREERDP_ANDROID_EXTERNAL_SSL_PATH}) set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/client/Android/FreeRDPCore/libs/${ANDROID_ABI}) @@ -222,7 +246,7 @@ if(ANDROID) endif() set(CMAKE_THREAD_PREFER_PTHREAD TRUE) -if(NOT ANDROID) +if(NOT IOS AND NOT ANDROID) find_package(Threads REQUIRED) endif() @@ -291,6 +315,7 @@ endif() if(APPLE) set(DIRECTFB_FEATURE_TYPE "DISABLED") set(FFMPEG_FEATURE_TYPE "OPTIONAL") + set(GSTREAMER_FEATURE_TYPE "OPTIONAL") if(IOS) set(X11_FEATURE_TYPE "DISABLED") set(ALSA_FEATURE_TYPE "DISABLED") @@ -403,6 +428,13 @@ endif() # Sub-directories +if(WITH_THIRD_PARTY) + add_subdirectory(third-party) + if (NOT "${THIRD_PARTY_INCLUDES}" STREQUAL "") + include_directories(${THIRD_PARTY_INCLUDES}) + endif() +endif() + add_subdirectory(include) add_subdirectory(libfreerdp) @@ -411,6 +443,10 @@ if(WITH_CHANNELS) add_subdirectory(channels) endif() +if (IOS) +set(CMAKE_OSX_DEPLOYMENT_TARGET "") +set(CMAKE_OSX_SYSROOT "iphoneos") +endif() if(WITH_CLIENT) add_subdirectory(client) endif() @@ -419,10 +455,6 @@ if(WITH_SERVER) add_subdirectory(server) endif() -if(WITH_THIRD_PARTY) - add_subdirectory(third-party) -endif() - # Packaging SET(CPACK_BINARY_ZIP "ON") @@ -529,4 +561,6 @@ if (ANDROID AND CMAKE_EXTRA_GENERATOR STREQUAL "Eclipse CDT4") message(STATUS "Disabled CXX system defines for eclipse (workaround).") endif() + + include(CPack) diff --git a/channels/audin/client/alsa/audin_alsa.c b/channels/audin/client/alsa/audin_alsa.c index 11f31e420..0fd034514 100644 --- a/channels/audin/client/alsa/audin_alsa.c +++ b/channels/audin/client/alsa/audin_alsa.c @@ -26,13 +26,14 @@ #include #include +#include +#include #include #include #include #include -#include #include #include "audin_main.h" @@ -54,7 +55,8 @@ typedef struct _AudinALSADevice FREERDP_DSP_CONTEXT* dsp_context; - freerdp_thread* thread; + HANDLE thread; + HANDLE stopEvent; BYTE* buffer; int buffer_frames; @@ -128,7 +130,7 @@ static BOOL audin_alsa_thread_receive(AudinALSADevice* alsa, BYTE* src, int size while (frames > 0) { - if (freerdp_thread_is_stopped(alsa->thread)) + if (WaitForSingleObject(alsa->stopEvent, 0) == WAIT_OBJECT_0) break; cframes = alsa->frames_per_packet - alsa->buffer_frames; @@ -160,7 +162,7 @@ static BOOL audin_alsa_thread_receive(AudinALSADevice* alsa, BYTE* src, int size encoded_size = alsa->buffer_frames * tbytes_per_frame; } - if (freerdp_thread_is_stopped(alsa->thread)) + if (WaitForSingleObject(alsa->stopEvent, 0) == WAIT_OBJECT_0) { ret = 0; frames = 0; @@ -210,14 +212,16 @@ static void* audin_alsa_thread_func(void* arg) DEBUG_WARN("snd_pcm_open (%s)", snd_strerror(error)); break; } + if (!audin_alsa_set_params(alsa, capture_handle)) { break; } - while (!freerdp_thread_is_stopped(alsa->thread)) + while (!(WaitForSingleObject(alsa->stopEvent, 0) == WAIT_OBJECT_0)) { error = snd_pcm_readi(capture_handle, buffer, alsa->frames_per_packet); + if (error == -EPIPE) { snd_pcm_recover(capture_handle, error, 0); @@ -228,10 +232,12 @@ static void* audin_alsa_thread_func(void* arg) DEBUG_WARN("snd_pcm_readi (%s)", snd_strerror(error)); break; } + if (!audin_alsa_thread_receive(alsa, buffer, error * rbytes_per_frame)) break; } - } while (0); + } + while (0); free(buffer); @@ -241,7 +247,7 @@ static void* audin_alsa_thread_func(void* arg) if (capture_handle) snd_pcm_close(capture_handle); - freerdp_thread_quit(alsa->thread); + SetEvent(alsa->stopEvent); DEBUG_DVC("out"); @@ -252,7 +258,8 @@ static void audin_alsa_free(IAudinDevice* device) { AudinALSADevice* alsa = (AudinALSADevice*) device; - freerdp_thread_free(alsa->thread); + SetEvent(alsa->stopEvent); + freerdp_dsp_context_free(alsa->dsp_context); free(alsa->device_name); @@ -337,7 +344,8 @@ static void audin_alsa_open(IAudinDevice* device, AudinReceive receive, void* us alsa->receive = receive; alsa->user_data = user_data; - freerdp_thread_start(alsa->thread, audin_alsa_thread_func, alsa); + alsa->stopEvent = CreateEvent(NULL, TRUE, FALSE, NULL); + alsa->thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) audin_alsa_thread_func, alsa, 0, NULL); } static void audin_alsa_close(IAudinDevice* device) @@ -346,7 +354,7 @@ static void audin_alsa_close(IAudinDevice* device) DEBUG_DVC(""); - freerdp_thread_stop(alsa->thread); + SetEvent(alsa->stopEvent); alsa->receive = NULL; alsa->user_data = NULL; @@ -420,7 +428,6 @@ int freerdp_audin_client_subsystem_entry(PFREERDP_AUDIN_DEVICE_ENTRY_POINTS pEnt alsa->target_channels = 2; alsa->actual_channels = 2; alsa->bytes_per_channel = 2; - alsa->thread = freerdp_thread_new(); alsa->dsp_context = freerdp_dsp_context_new(); diff --git a/channels/audin/client/audin_main.c b/channels/audin/client/audin_main.c index 0ad1e6129..428684519 100644 --- a/channels/audin/client/audin_main.c +++ b/channels/audin/client/audin_main.c @@ -30,7 +30,7 @@ #include -#include +#include #include "audin_main.h" @@ -87,10 +87,10 @@ struct _AUDIN_PLUGIN IAudinDevice* device; }; -static int audin_process_version(IWTSVirtualChannelCallback* pChannelCallback, STREAM* s) +static int audin_process_version(IWTSVirtualChannelCallback* pChannelCallback, wStream* s) { int error; - STREAM* out; + wStream* out; UINT32 Version; AUDIN_CHANNEL_CALLBACK* callback = (AUDIN_CHANNEL_CALLBACK*) pChannelCallback; @@ -116,14 +116,14 @@ static int audin_send_incoming_data_pdu(IWTSVirtualChannelCallback* pChannelCall return callback->channel->Write(callback->channel, 1, out_data, NULL); } -static int audin_process_formats(IWTSVirtualChannelCallback* pChannelCallback, STREAM* s) +static int audin_process_formats(IWTSVirtualChannelCallback* pChannelCallback, wStream* s) { AUDIN_CHANNEL_CALLBACK* callback = (AUDIN_CHANNEL_CALLBACK*) pChannelCallback; AUDIN_PLUGIN* audin = (AUDIN_PLUGIN*) callback->plugin; UINT32 i; BYTE* fm; int error; - STREAM* out; + wStream* out; UINT32 NumFormats; audinFormat format; UINT32 cbSizeFormatsPacket; @@ -198,7 +198,7 @@ static int audin_process_formats(IWTSVirtualChannelCallback* pChannelCallback, S static int audin_send_format_change_pdu(IWTSVirtualChannelCallback* pChannelCallback, UINT32 NewFormat) { int error; - STREAM* out; + wStream* out; AUDIN_CHANNEL_CALLBACK* callback = (AUDIN_CHANNEL_CALLBACK*) pChannelCallback; out = stream_new(5); @@ -213,7 +213,7 @@ static int audin_send_format_change_pdu(IWTSVirtualChannelCallback* pChannelCall static int audin_send_open_reply_pdu(IWTSVirtualChannelCallback* pChannelCallback, UINT32 Result) { int error; - STREAM* out; + wStream* out; AUDIN_CHANNEL_CALLBACK* callback = (AUDIN_CHANNEL_CALLBACK*) pChannelCallback; out = stream_new(5); @@ -228,7 +228,7 @@ static int audin_send_open_reply_pdu(IWTSVirtualChannelCallback* pChannelCallbac static BOOL audin_receive_wave_data(BYTE* data, int size, void* user_data) { int error; - STREAM* out; + wStream* out; AUDIN_CHANNEL_CALLBACK* callback = (AUDIN_CHANNEL_CALLBACK*) user_data; error = audin_send_incoming_data_pdu((IWTSVirtualChannelCallback*) callback); @@ -245,7 +245,7 @@ static BOOL audin_receive_wave_data(BYTE* data, int size, void* user_data) return (error == 0 ? TRUE : FALSE); } -static int audin_process_open(IWTSVirtualChannelCallback* pChannelCallback, STREAM* s) +static int audin_process_open(IWTSVirtualChannelCallback* pChannelCallback, wStream* s) { AUDIN_CHANNEL_CALLBACK* callback = (AUDIN_CHANNEL_CALLBACK*) pChannelCallback; AUDIN_PLUGIN* audin = (AUDIN_PLUGIN*) callback->plugin; @@ -279,7 +279,7 @@ static int audin_process_open(IWTSVirtualChannelCallback* pChannelCallback, STRE return 0; } -static int audin_process_format_change(IWTSVirtualChannelCallback* pChannelCallback, STREAM* s) +static int audin_process_format_change(IWTSVirtualChannelCallback* pChannelCallback, wStream* s) { AUDIN_CHANNEL_CALLBACK* callback = (AUDIN_CHANNEL_CALLBACK*) pChannelCallback; AUDIN_PLUGIN * audin = (AUDIN_PLUGIN*) callback->plugin; @@ -314,7 +314,7 @@ static int audin_process_format_change(IWTSVirtualChannelCallback* pChannelCallb static int audin_on_data_received(IWTSVirtualChannelCallback* pChannelCallback, UINT32 cbSize, BYTE* pBuffer) { int error; - STREAM* s; + wStream* s; BYTE MessageId; s = stream_new(0); diff --git a/channels/audin/server/audin.c b/channels/audin/server/audin.c index b93476a74..75a143fda 100644 --- a/channels/audin/server/audin.c +++ b/channels/audin/server/audin.c @@ -26,31 +26,37 @@ #include #include +#include +#include +#include #include -#include -#include +#include #include #include -#define MSG_SNDIN_VERSION 0x01 -#define MSG_SNDIN_FORMATS 0x02 -#define MSG_SNDIN_OPEN 0x03 -#define MSG_SNDIN_OPEN_REPLY 0x04 -#define MSG_SNDIN_DATA_INCOMING 0x05 -#define MSG_SNDIN_DATA 0x06 -#define MSG_SNDIN_FORMATCHANGE 0x07 +#define MSG_SNDIN_VERSION 0x01 +#define MSG_SNDIN_FORMATS 0x02 +#define MSG_SNDIN_OPEN 0x03 +#define MSG_SNDIN_OPEN_REPLY 0x04 +#define MSG_SNDIN_DATA_INCOMING 0x05 +#define MSG_SNDIN_DATA 0x06 +#define MSG_SNDIN_FORMATCHANGE 0x07 typedef struct _audin_server { audin_server_context context; + BOOL opened; + + HANDLE event; + HANDLE stopEvent; + + HANDLE thread; void* audin_channel; - freerdp_thread* audin_channel_thread; FREERDP_DSP_CONTEXT* dsp_context; - BOOL opened; } audin_server; static void audin_server_select_format(audin_server_context* context, int client_format_index) @@ -59,34 +65,38 @@ static void audin_server_select_format(audin_server_context* context, int client if (client_format_index >= context->num_client_formats) return; + context->selected_client_format = client_format_index; + if (audin->opened) { /* TODO: send MSG_SNDIN_FORMATCHANGE */ } } -static void audin_server_send_version(audin_server* audin, STREAM* s) +static void audin_server_send_version(audin_server* audin, wStream* s) { stream_write_BYTE(s, MSG_SNDIN_VERSION); stream_write_UINT32(s, 1); /* Version (4 bytes) */ WTSVirtualChannelWrite(audin->audin_channel, stream_get_head(s), stream_get_length(s), NULL); } -static BOOL audin_server_recv_version(audin_server* audin, STREAM* s, UINT32 length) +static BOOL audin_server_recv_version(audin_server* audin, wStream* s, UINT32 length) { UINT32 Version; if (length < 4) return FALSE; + stream_read_UINT32(s, Version); + if (Version < 1) return FALSE; return TRUE; } -static void audin_server_send_formats(audin_server* audin, STREAM* s) +static void audin_server_send_formats(audin_server* audin, wStream* s) { int i; UINT32 nAvgBytesPerSec; @@ -120,7 +130,7 @@ static void audin_server_send_formats(audin_server* audin, STREAM* s) WTSVirtualChannelWrite(audin->audin_channel, stream_get_head(s), stream_get_length(s), NULL); } -static BOOL audin_server_recv_formats(audin_server* audin, STREAM* s, UINT32 length) +static BOOL audin_server_recv_formats(audin_server* audin, wStream* s, UINT32 length) { int i; @@ -164,7 +174,7 @@ static BOOL audin_server_recv_formats(audin_server* audin, STREAM* s, UINT32 len return TRUE; } -static void audin_server_send_open(audin_server* audin, STREAM* s) +static void audin_server_send_open(audin_server* audin, wStream* s) { if (audin->context.selected_client_format < 0) return; @@ -191,12 +201,13 @@ static void audin_server_send_open(audin_server* audin, STREAM* s) WTSVirtualChannelWrite(audin->audin_channel, stream_get_head(s), stream_get_length(s), NULL); } -static BOOL audin_server_recv_open_reply(audin_server* audin, STREAM* s, UINT32 length) +static BOOL audin_server_recv_open_reply(audin_server* audin, wStream* s, UINT32 length) { UINT32 Result; if (length < 4) return FALSE; + stream_read_UINT32(s, Result); IFCALL(audin->context.OpenResult, &audin->context, Result); @@ -204,7 +215,7 @@ static BOOL audin_server_recv_open_reply(audin_server* audin, STREAM* s, UINT32 return TRUE; } -static BOOL audin_server_recv_data(audin_server* audin, STREAM* s, UINT32 length) +static BOOL audin_server_recv_data(audin_server* audin, wStream* s, UINT32 length) { AUDIO_FORMAT* format; int sbytes_per_sample; @@ -218,7 +229,7 @@ static BOOL audin_server_recv_data(audin_server* audin, STREAM* s, UINT32 length format = &audin->context.client_formats[audin->context.selected_client_format]; - if (format->wFormatTag == 2) + if (format->wFormatTag == WAVE_FORMAT_ADPCM) { audin->dsp_context->decode_ms_adpcm(audin->dsp_context, stream_get_tail(s), length, format->nChannels, format->nBlockAlign); @@ -227,7 +238,7 @@ static BOOL audin_server_recv_data(audin_server* audin, STREAM* s, UINT32 length sbytes_per_sample = 2; sbytes_per_frame = format->nChannels * 2; } - else if (format->wFormatTag == 0x11) + else if (format->wFormatTag == WAVE_FORMAT_DVI_ADPCM) { audin->dsp_context->decode_ima_adpcm(audin->dsp_context, stream_get_tail(s), length, format->nChannels, format->nBlockAlign); @@ -265,29 +276,28 @@ static BOOL audin_server_recv_data(audin_server* audin, STREAM* s, UINT32 length static void* audin_server_thread_func(void* arg) { void* fd; - STREAM* s; + wStream* s; void* buffer; BYTE MessageId; BOOL ready = FALSE; UINT32 bytes_returned = 0; audin_server* audin = (audin_server*) arg; - freerdp_thread* thread = audin->audin_channel_thread; if (WTSVirtualChannelQuery(audin->audin_channel, WTSVirtualFileHandle, &buffer, &bytes_returned) == TRUE) { fd = *((void**) buffer); WTSFreeMemory(buffer); - thread->signals[thread->num_signals++] = CreateWaitObjectEvent(NULL, TRUE, FALSE, fd); + audin->event = CreateWaitObjectEvent(NULL, TRUE, FALSE, fd); } /* Wait for the client to confirm that the Audio Input dynamic channel is ready */ + while (1) { - if (freerdp_thread_wait(thread) < 0) - break; + WaitForSingleObject(audin->event, INFINITE); - if (freerdp_thread_is_stopped(thread)) + if (WaitForSingleObject(audin->stopEvent, 0) == WAIT_OBJECT_0) break; if (WTSVirtualChannelQuery(audin->audin_channel, WTSVirtualChannelReady, &buffer, &bytes_returned) == FALSE) @@ -310,10 +320,9 @@ static void* audin_server_thread_func(void* arg) while (ready) { - if (freerdp_thread_wait(thread) < 0) - break; - - if (freerdp_thread_is_stopped(thread)) + WaitForSingleObject(audin->event, INFINITE); + + if (WaitForSingleObject(audin->stopEvent, 0) == WAIT_OBJECT_0) break; stream_set_pos(s, 0); @@ -330,11 +339,13 @@ static void* audin_server_thread_func(void* arg) stream_get_size(s), &bytes_returned) == FALSE) break; } + if (bytes_returned < 1) continue; stream_read_BYTE(s, MessageId); bytes_returned--; + switch (MessageId) { case MSG_SNDIN_VERSION: @@ -362,7 +373,7 @@ static void* audin_server_thread_func(void* arg) break; default: - printf("audin_server_thread_func: unknown MessageId %d\n", MessageId); + fprintf(stderr, "audin_server_thread_func: unknown MessageId %d\n", MessageId); break; } } @@ -370,7 +381,6 @@ static void* audin_server_thread_func(void* arg) stream_free(s); WTSVirtualChannelClose(audin->audin_channel); audin->audin_channel = NULL; - freerdp_thread_quit(thread); return NULL; } @@ -379,15 +389,17 @@ static BOOL audin_server_open(audin_server_context* context) { audin_server* audin = (audin_server*) context; - if (audin->audin_channel_thread == NULL) + if (!audin->thread) { audin->audin_channel = WTSVirtualChannelOpenEx(context->vcm, "AUDIO_INPUT", WTS_CHANNEL_OPTION_DYNAMIC); - if (audin->audin_channel == NULL) + if (!audin->audin_channel) return FALSE; - audin->audin_channel_thread = freerdp_thread_new(); - freerdp_thread_start(audin->audin_channel_thread, audin_server_thread_func, audin); + audin->stopEvent = CreateEvent(NULL, TRUE, FALSE, NULL); + + audin->thread = CreateThread(NULL, 0, + (LPTHREAD_START_ROUTINE) audin_server_thread_func, (void*) audin, 0, NULL); return TRUE; } @@ -399,17 +411,20 @@ static BOOL audin_server_close(audin_server_context* context) { audin_server* audin = (audin_server*) context; - if (audin->audin_channel_thread) + if (audin->thread) { - freerdp_thread_stop(audin->audin_channel_thread); - freerdp_thread_free(audin->audin_channel_thread); - audin->audin_channel_thread = NULL; + SetEvent(audin->stopEvent); + WaitForSingleObject(audin->thread, INFINITE); + CloseHandle(audin->thread); + audin->thread = NULL; } + if (audin->audin_channel) { WTSVirtualChannelClose(audin->audin_channel); audin->audin_channel = NULL; } + audin->context.selected_client_format = -1; return TRUE; diff --git a/channels/client/CMakeLists.txt b/channels/client/CMakeLists.txt index 96714f701..d1726657d 100644 --- a/channels/client/CMakeLists.txt +++ b/channels/client/CMakeLists.txt @@ -21,6 +21,8 @@ set(MODULE_PREFIX "FREERDP_CHANNELS_CLIENT") set(${MODULE_PREFIX}_SRCS tables.c tables.h + addin.c + addin.h channels.c) list(REMOVE_DUPLICATES CHANNEL_STATIC_CLIENT_ENTRIES) diff --git a/channels/client/addin.c b/channels/client/addin.c new file mode 100644 index 000000000..f85314258 --- /dev/null +++ b/channels/client/addin.c @@ -0,0 +1,335 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Channel Addins + * + * Copyright 2012 Marc-Andre Moreau + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "tables.h" + +#include "addin.h" + +extern const STATIC_ENTRY_TABLE CLIENT_STATIC_ENTRY_TABLES[]; + +void* freerdp_channels_find_static_entry_in_table(const STATIC_ENTRY_TABLE* table, const char* identifier) +{ + int index = 0; + STATIC_ENTRY* pEntry; + + pEntry = (STATIC_ENTRY*) &table->table[index++]; + + while (pEntry->entry != NULL) + { + if (strcmp(pEntry->name, identifier) == 0) + { + return (void*) pEntry->entry; + } + + pEntry = (STATIC_ENTRY*) &table->table[index++]; + } + + return NULL; +} + +void* freerdp_channels_client_find_static_entry(const char* name, const char* identifier) +{ + int index = 0; + STATIC_ENTRY_TABLE* pEntry; + + pEntry = (STATIC_ENTRY_TABLE*) &CLIENT_STATIC_ENTRY_TABLES[index++]; + + while (pEntry->table != NULL) + { + if (strcmp(pEntry->name, name) == 0) + { + return freerdp_channels_find_static_entry_in_table(pEntry, identifier); + } + + pEntry = (STATIC_ENTRY_TABLE*) &CLIENT_STATIC_ENTRY_TABLES[index++]; + } + + return NULL; +} + +extern const STATIC_ADDIN_TABLE CLIENT_STATIC_ADDIN_TABLE[]; + +FREERDP_ADDIN** freerdp_channels_list_client_static_addins(LPSTR pszName, LPSTR pszSubsystem, LPSTR pszType, DWORD dwFlags) +{ + int i, j; + DWORD nAddins; + FREERDP_ADDIN* pAddin; + FREERDP_ADDIN** ppAddins = NULL; + STATIC_SUBSYSTEM_ENTRY* subsystems; + + nAddins = 0; + ppAddins = (FREERDP_ADDIN**) malloc(sizeof(FREERDP_ADDIN*) * 128); + ppAddins[nAddins] = NULL; + + for (i = 0; CLIENT_STATIC_ADDIN_TABLE[i].name != NULL; i++) + { + pAddin = (FREERDP_ADDIN*) malloc(sizeof(FREERDP_ADDIN)); + ZeroMemory(pAddin, sizeof(FREERDP_ADDIN)); + + strcpy(pAddin->cName, CLIENT_STATIC_ADDIN_TABLE[i].name); + + pAddin->dwFlags = FREERDP_ADDIN_CLIENT; + pAddin->dwFlags |= FREERDP_ADDIN_STATIC; + pAddin->dwFlags |= FREERDP_ADDIN_NAME; + + ppAddins[nAddins++] = pAddin; + + subsystems = (STATIC_SUBSYSTEM_ENTRY*) CLIENT_STATIC_ADDIN_TABLE[i].table; + + for (j = 0; subsystems[j].name != NULL; j++) + { + pAddin = (FREERDP_ADDIN*) malloc(sizeof(FREERDP_ADDIN)); + ZeroMemory(pAddin, sizeof(FREERDP_ADDIN)); + + strcpy(pAddin->cName, CLIENT_STATIC_ADDIN_TABLE[i].name); + strcpy(pAddin->cSubsystem, subsystems[j].name); + + pAddin->dwFlags = FREERDP_ADDIN_CLIENT; + pAddin->dwFlags |= FREERDP_ADDIN_STATIC; + pAddin->dwFlags |= FREERDP_ADDIN_NAME; + pAddin->dwFlags |= FREERDP_ADDIN_SUBSYSTEM; + + ppAddins[nAddins++] = pAddin; + } + } + + ppAddins[nAddins] = NULL; + + return ppAddins; +} + +FREERDP_ADDIN** freerdp_channels_list_dynamic_addins(LPSTR pszName, LPSTR pszSubsystem, LPSTR pszType, DWORD dwFlags) +{ + int index; + int nDashes; + HANDLE hFind; + DWORD nAddins; + LPSTR pszPattern; + size_t cchPattern; + LPCSTR pszAddinPath = FREERDP_ADDIN_PATH; + LPCSTR pszInstallPrefix = FREERDP_INSTALL_PREFIX; + LPCSTR pszExtension; + LPSTR pszSearchPath; + size_t cchSearchPath; + size_t cchAddinPath; + size_t cchInstallPrefix; + FREERDP_ADDIN** ppAddins; + WIN32_FIND_DATAA FindData; + + cchAddinPath = strlen(pszAddinPath); + cchInstallPrefix = strlen(pszInstallPrefix); + + pszExtension = PathGetSharedLibraryExtensionA(0); + + cchPattern = 128 + strlen(pszExtension) + 2; + pszPattern = (LPSTR) malloc(cchPattern + 1); + + if (pszName && pszSubsystem && pszType) + { + sprintf_s(pszPattern, cchPattern, "%s-client-%s-%s.%s", pszName, pszSubsystem, pszType, pszExtension); + } + else if (pszName && pszType) + { + sprintf_s(pszPattern, cchPattern, "%s-client-?-%s.%s", pszName, pszType, pszExtension); + } + else if (pszName) + { + sprintf_s(pszPattern, cchPattern, "%s-client*.%s", pszName, pszExtension); + } + else + { + sprintf_s(pszPattern, cchPattern, "?-client*.%s", pszExtension); + } + + cchPattern = strlen(pszPattern); + + cchSearchPath = cchInstallPrefix + cchAddinPath + cchPattern + 3; + pszSearchPath = (LPSTR) malloc(cchSearchPath + 1); + + CopyMemory(pszSearchPath, pszInstallPrefix, cchInstallPrefix); + pszSearchPath[cchInstallPrefix] = '\0'; + + NativePathCchAppendA(pszSearchPath, cchSearchPath + 1, pszAddinPath); + NativePathCchAppendA(pszSearchPath, cchSearchPath + 1, pszPattern); + + cchSearchPath = strlen(pszSearchPath); + + hFind = FindFirstFileA(pszSearchPath, &FindData); + + nAddins = 0; + ppAddins = (FREERDP_ADDIN**) malloc(sizeof(FREERDP_ADDIN*) * 128); + ppAddins[nAddins] = NULL; + + if (hFind == INVALID_HANDLE_VALUE) + return ppAddins; + + do + { + char* p[5]; + FREERDP_ADDIN* pAddin; + + nDashes = 0; + pAddin = (FREERDP_ADDIN*) malloc(sizeof(FREERDP_ADDIN)); + ZeroMemory(pAddin, sizeof(FREERDP_ADDIN)); + + for (index = 0; FindData.cFileName[index]; index++) + nDashes += (FindData.cFileName[index] == '-') ? 1 : 0; + + if (nDashes == 1) + { + /* -client. */ + + p[0] = FindData.cFileName; + p[1] = strchr(p[0], '-') + 1; + + strncpy(pAddin->cName, p[0], (p[1] - p[0]) - 1); + + pAddin->dwFlags = FREERDP_ADDIN_CLIENT; + pAddin->dwFlags |= FREERDP_ADDIN_DYNAMIC; + pAddin->dwFlags |= FREERDP_ADDIN_NAME; + + ppAddins[nAddins++] = pAddin; + } + else if (nDashes == 2) + { + /* -client-. */ + + p[0] = FindData.cFileName; + p[1] = strchr(p[0], '-') + 1; + p[2] = strchr(p[1], '-') + 1; + p[3] = strchr(p[2], '.') + 1; + + strncpy(pAddin->cName, p[0], (p[1] - p[0]) - 1); + strncpy(pAddin->cSubsystem, p[2], (p[3] - p[2]) - 1); + + pAddin->dwFlags = FREERDP_ADDIN_CLIENT; + pAddin->dwFlags |= FREERDP_ADDIN_DYNAMIC; + pAddin->dwFlags |= FREERDP_ADDIN_NAME; + pAddin->dwFlags |= FREERDP_ADDIN_SUBSYSTEM; + + ppAddins[nAddins++] = pAddin; + } + else if (nDashes == 3) + { + /* -client--. */ + + p[0] = FindData.cFileName; + p[1] = strchr(p[0], '-') + 1; + p[2] = strchr(p[1], '-') + 1; + p[3] = strchr(p[2], '-') + 1; + p[4] = strchr(p[3], '.') + 1; + + strncpy(pAddin->cName, p[0], (p[1] - p[0]) - 1); + strncpy(pAddin->cSubsystem, p[2], (p[3] - p[2]) - 1); + strncpy(pAddin->cType, p[3], (p[4] - p[3]) - 1); + + pAddin->dwFlags = FREERDP_ADDIN_CLIENT; + pAddin->dwFlags |= FREERDP_ADDIN_DYNAMIC; + pAddin->dwFlags |= FREERDP_ADDIN_NAME; + pAddin->dwFlags |= FREERDP_ADDIN_SUBSYSTEM; + pAddin->dwFlags |= FREERDP_ADDIN_TYPE; + + ppAddins[nAddins++] = pAddin; + } + else + { + free(pAddin); + } + } + while (FindNextFileA(hFind, &FindData)); + + FindClose(hFind); + + ppAddins[nAddins] = NULL; + + return ppAddins; +} + +FREERDP_ADDIN** freerdp_channels_list_addins(LPSTR pszName, LPSTR pszSubsystem, LPSTR pszType, DWORD dwFlags) +{ + if (dwFlags & FREERDP_ADDIN_STATIC) + return freerdp_channels_list_client_static_addins(pszName, pszSubsystem, pszType, dwFlags); + else if (dwFlags & FREERDP_ADDIN_DYNAMIC) + return freerdp_channels_list_dynamic_addins(pszName, pszSubsystem, pszType, dwFlags); + + return NULL; +} + +void freerdp_channels_addin_list_free(FREERDP_ADDIN** ppAddins) +{ + int index; + + for (index = 0; ppAddins[index] != NULL; index++) + free(ppAddins[index]); + + free(ppAddins); +} + +void* freerdp_channels_load_static_addin_entry(LPCSTR pszName, LPSTR pszSubsystem, LPSTR pszType, DWORD dwFlags) +{ + int i, j; + STATIC_SUBSYSTEM_ENTRY* subsystems; + + for (i = 0; CLIENT_STATIC_ADDIN_TABLE[i].name != NULL; i++) + { + if (strcmp(CLIENT_STATIC_ADDIN_TABLE[i].name, pszName) == 0) + { + if (pszSubsystem != NULL) + { + subsystems = (STATIC_SUBSYSTEM_ENTRY*) CLIENT_STATIC_ADDIN_TABLE[i].table; + + for (j = 0; subsystems[j].name != NULL; j++) + { + if (strcmp(subsystems[j].name, pszSubsystem) == 0) + { + if (pszType) + { + if (strcmp(subsystems[j].type, pszType) == 0) + return (void*) subsystems[j].entry; + } + else + { + return (void*) subsystems[j].entry; + } + } + } + } + else + { + return (void*) CLIENT_STATIC_ADDIN_TABLE[i].entry; + } + } + } + + return NULL; +} diff --git a/channels/client/addin.h b/channels/client/addin.h new file mode 100644 index 000000000..f3ad9702a --- /dev/null +++ b/channels/client/addin.h @@ -0,0 +1,20 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Channel Addins + * + * Copyright 2012 Marc-Andre Moreau + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + diff --git a/channels/client/channels.c b/channels/client/channels.c index c7d617a0c..82ee13e1c 100644 --- a/channels/client/channels.c +++ b/channels/client/channels.c @@ -23,8 +23,6 @@ #include "config.h" #endif -#include "tables.h" - #include #include #include @@ -35,7 +33,6 @@ #include #include #include -#include #include #include @@ -46,6 +43,8 @@ #include #include +#include "addin.h" + #ifdef WITH_DEBUG_CHANNELS #define DEBUG_CHANNELS(fmt, ...) DEBUG_CLASS(CHANNELS, fmt, ## __VA_ARGS__) #else @@ -68,313 +67,15 @@ * from the main thread. */ -extern const STATIC_ENTRY_TABLE CLIENT_STATIC_ENTRY_TABLES[]; - -void* freerdp_channels_find_static_entry_in_table(const STATIC_ENTRY_TABLE* table, const char* identifier) -{ - int index = 0; - STATIC_ENTRY* pEntry; - - pEntry = (STATIC_ENTRY*) &table->table[index++]; - - while (pEntry->entry != NULL) - { - if (strcmp(pEntry->name, identifier) == 0) - { - return (void*) pEntry->entry; - } - - pEntry = (STATIC_ENTRY*) &table->table[index++]; - } - - return NULL; -} - -void* freerdp_channels_client_find_static_entry(const char* name, const char* identifier) -{ - int index = 0; - STATIC_ENTRY_TABLE* pEntry; - - pEntry = (STATIC_ENTRY_TABLE*) &CLIENT_STATIC_ENTRY_TABLES[index++]; - - while (pEntry->table != NULL) - { - if (strcmp(pEntry->name, name) == 0) - { - return freerdp_channels_find_static_entry_in_table(pEntry, identifier); - } - - pEntry = (STATIC_ENTRY_TABLE*) &CLIENT_STATIC_ENTRY_TABLES[index++]; - } - - return NULL; -} - -extern const STATIC_ADDIN_TABLE CLIENT_STATIC_ADDIN_TABLE[]; - -FREERDP_ADDIN** freerdp_channels_list_client_static_addins(LPSTR pszName, LPSTR pszSubsystem, LPSTR pszType, DWORD dwFlags) -{ - int i, j; - DWORD nAddins; - FREERDP_ADDIN* pAddin; - FREERDP_ADDIN** ppAddins = NULL; - STATIC_SUBSYSTEM_ENTRY* subsystems; - - nAddins = 0; - ppAddins = (FREERDP_ADDIN**) malloc(sizeof(FREERDP_ADDIN*) * 128); - ppAddins[nAddins] = NULL; - - for (i = 0; CLIENT_STATIC_ADDIN_TABLE[i].name != NULL; i++) - { - pAddin = (FREERDP_ADDIN*) malloc(sizeof(FREERDP_ADDIN)); - ZeroMemory(pAddin, sizeof(FREERDP_ADDIN)); - - strcpy(pAddin->cName, CLIENT_STATIC_ADDIN_TABLE[i].name); - - pAddin->dwFlags = FREERDP_ADDIN_CLIENT; - pAddin->dwFlags |= FREERDP_ADDIN_STATIC; - pAddin->dwFlags |= FREERDP_ADDIN_NAME; - - ppAddins[nAddins++] = pAddin; - - subsystems = (STATIC_SUBSYSTEM_ENTRY*) CLIENT_STATIC_ADDIN_TABLE[i].table; - - for (j = 0; subsystems[j].name != NULL; j++) - { - pAddin = (FREERDP_ADDIN*) malloc(sizeof(FREERDP_ADDIN)); - ZeroMemory(pAddin, sizeof(FREERDP_ADDIN)); - - strcpy(pAddin->cName, CLIENT_STATIC_ADDIN_TABLE[i].name); - strcpy(pAddin->cSubsystem, subsystems[j].name); - - pAddin->dwFlags = FREERDP_ADDIN_CLIENT; - pAddin->dwFlags |= FREERDP_ADDIN_STATIC; - pAddin->dwFlags |= FREERDP_ADDIN_NAME; - pAddin->dwFlags |= FREERDP_ADDIN_SUBSYSTEM; - - ppAddins[nAddins++] = pAddin; - } - } - - ppAddins[nAddins] = NULL; - - return ppAddins; -} - -FREERDP_ADDIN** freerdp_channels_list_dynamic_addins(LPSTR pszName, LPSTR pszSubsystem, LPSTR pszType, DWORD dwFlags) -{ - int index; - int nDashes; - HANDLE hFind; - DWORD nAddins; - LPSTR pszPattern; - size_t cchPattern; - LPCSTR pszAddinPath = FREERDP_ADDIN_PATH; - LPCSTR pszInstallPrefix = FREERDP_INSTALL_PREFIX; - LPCSTR pszExtension; - LPSTR pszSearchPath; - size_t cchSearchPath; - size_t cchAddinPath; - size_t cchInstallPrefix; - FREERDP_ADDIN** ppAddins; - WIN32_FIND_DATAA FindData; - - cchAddinPath = strlen(pszAddinPath); - cchInstallPrefix = strlen(pszInstallPrefix); - - pszExtension = PathGetSharedLibraryExtensionA(0); - - cchPattern = 128 + strlen(pszExtension) + 2; - pszPattern = (LPSTR) malloc(cchPattern + 1); - - if (pszName && pszSubsystem && pszType) - { - sprintf_s(pszPattern, cchPattern, "%s-client-%s-%s.%s", pszName, pszSubsystem, pszType, pszExtension); - } - else if (pszName && pszType) - { - sprintf_s(pszPattern, cchPattern, "%s-client-?-%s.%s", pszName, pszType, pszExtension); - } - else if (pszName) - { - sprintf_s(pszPattern, cchPattern, "%s-client*.%s", pszName, pszExtension); - } - else - { - sprintf_s(pszPattern, cchPattern, "?-client*.%s", pszExtension); - } - - cchPattern = strlen(pszPattern); - - cchSearchPath = cchInstallPrefix + cchAddinPath + cchPattern + 3; - pszSearchPath = (LPSTR) malloc(cchSearchPath + 1); - - CopyMemory(pszSearchPath, pszInstallPrefix, cchInstallPrefix); - pszSearchPath[cchInstallPrefix] = '\0'; - - NativePathCchAppendA(pszSearchPath, cchSearchPath + 1, pszAddinPath); - NativePathCchAppendA(pszSearchPath, cchSearchPath + 1, pszPattern); - - cchSearchPath = strlen(pszSearchPath); - - hFind = FindFirstFileA(pszSearchPath, &FindData); - - nAddins = 0; - ppAddins = (FREERDP_ADDIN**) malloc(sizeof(FREERDP_ADDIN*) * 128); - ppAddins[nAddins] = NULL; - - if (hFind == INVALID_HANDLE_VALUE) - return ppAddins; - - do - { - char* p[5]; - FREERDP_ADDIN* pAddin; - - nDashes = 0; - pAddin = (FREERDP_ADDIN*) malloc(sizeof(FREERDP_ADDIN)); - ZeroMemory(pAddin, sizeof(FREERDP_ADDIN)); - - for (index = 0; FindData.cFileName[index]; index++) - nDashes += (FindData.cFileName[index] == '-') ? 1 : 0; - - if (nDashes == 1) - { - /* -client. */ - - p[0] = FindData.cFileName; - p[1] = strchr(p[0], '-') + 1; - - strncpy(pAddin->cName, p[0], (p[1] - p[0]) - 1); - - pAddin->dwFlags = FREERDP_ADDIN_CLIENT; - pAddin->dwFlags |= FREERDP_ADDIN_DYNAMIC; - pAddin->dwFlags |= FREERDP_ADDIN_NAME; - - ppAddins[nAddins++] = pAddin; - } - else if (nDashes == 2) - { - /* -client-. */ - - p[0] = FindData.cFileName; - p[1] = strchr(p[0], '-') + 1; - p[2] = strchr(p[1], '-') + 1; - p[3] = strchr(p[2], '.') + 1; - - strncpy(pAddin->cName, p[0], (p[1] - p[0]) - 1); - strncpy(pAddin->cSubsystem, p[2], (p[3] - p[2]) - 1); - - pAddin->dwFlags = FREERDP_ADDIN_CLIENT; - pAddin->dwFlags |= FREERDP_ADDIN_DYNAMIC; - pAddin->dwFlags |= FREERDP_ADDIN_NAME; - pAddin->dwFlags |= FREERDP_ADDIN_SUBSYSTEM; - - ppAddins[nAddins++] = pAddin; - } - else if (nDashes == 3) - { - /* -client--. */ - - p[0] = FindData.cFileName; - p[1] = strchr(p[0], '-') + 1; - p[2] = strchr(p[1], '-') + 1; - p[3] = strchr(p[2], '-') + 1; - p[4] = strchr(p[3], '.') + 1; - - strncpy(pAddin->cName, p[0], (p[1] - p[0]) - 1); - strncpy(pAddin->cSubsystem, p[2], (p[3] - p[2]) - 1); - strncpy(pAddin->cType, p[3], (p[4] - p[3]) - 1); - - pAddin->dwFlags = FREERDP_ADDIN_CLIENT; - pAddin->dwFlags |= FREERDP_ADDIN_DYNAMIC; - pAddin->dwFlags |= FREERDP_ADDIN_NAME; - pAddin->dwFlags |= FREERDP_ADDIN_SUBSYSTEM; - pAddin->dwFlags |= FREERDP_ADDIN_TYPE; - - ppAddins[nAddins++] = pAddin; - } - else - { - free(pAddin); - } - } - while (FindNextFileA(hFind, &FindData)); - - FindClose(hFind); - - ppAddins[nAddins] = NULL; - - return ppAddins; -} - -FREERDP_ADDIN** freerdp_channels_list_addins(LPSTR pszName, LPSTR pszSubsystem, LPSTR pszType, DWORD dwFlags) -{ - if (dwFlags & FREERDP_ADDIN_STATIC) - return freerdp_channels_list_client_static_addins(pszName, pszSubsystem, pszType, dwFlags); - else if (dwFlags & FREERDP_ADDIN_DYNAMIC) - return freerdp_channels_list_dynamic_addins(pszName, pszSubsystem, pszType, dwFlags); - - return NULL; -} - -void freerdp_channels_addin_list_free(FREERDP_ADDIN** ppAddins) -{ - int index; - - for (index = 0; ppAddins[index] != NULL; index++) - free(ppAddins[index]); - - free(ppAddins); -} - -void* freerdp_channels_load_static_addin_entry(LPCSTR pszName, LPSTR pszSubsystem, LPSTR pszType, DWORD dwFlags) -{ - int i, j; - STATIC_SUBSYSTEM_ENTRY* subsystems; - - for (i = 0; CLIENT_STATIC_ADDIN_TABLE[i].name != NULL; i++) - { - if (strcmp(CLIENT_STATIC_ADDIN_TABLE[i].name, pszName) == 0) - { - if (pszSubsystem != NULL) - { - subsystems = (STATIC_SUBSYSTEM_ENTRY*) CLIENT_STATIC_ADDIN_TABLE[i].table; - - for (j = 0; subsystems[j].name != NULL; j++) - { - if (strcmp(subsystems[j].name, pszSubsystem) == 0) - { - if (pszType) - { - if (strcmp(subsystems[j].type, pszType) == 0) - return (void*) subsystems[j].entry; - } - else - { - return (void*) subsystems[j].entry; - } - } - } - } - else - { - return (void*) CLIENT_STATIC_ADDIN_TABLE[i].entry; - } - } - } - - return NULL; -} - -struct lib_data +struct rdp_library_data { PVIRTUALCHANNELENTRY entry; /* the one and only exported function */ PCHANNEL_INIT_EVENT_FN init_event_proc; void* init_handle; }; +typedef struct rdp_library_data rdpLibraryData; -struct channel_data +struct rdp_channel_data { char name[CHANNEL_NAME_LEN + 1]; int open_handle; @@ -382,6 +83,7 @@ struct channel_data int flags; /* 0 nothing 1 init 2 open */ PCHANNEL_OPEN_EVENT_FN open_event_proc; }; +typedef struct rdp_channel_data rdpChannelData; struct _CHANNEL_OPEN_EVENT { @@ -410,20 +112,20 @@ struct rdp_channels * ie, no two threads can access index 0, ... */ - struct lib_data libs_data[CHANNEL_MAX_COUNT]; - int num_libs_data; + int libraryDataCount; + rdpLibraryData libraryDataList[CHANNEL_MAX_COUNT]; - struct channel_data channels_data[CHANNEL_MAX_COUNT]; - int num_channels_data; + int channelDataCount; + rdpChannelData channelDataList[CHANNEL_MAX_COUNT]; - rdpInitHandle init_handles[CHANNEL_MAX_COUNT]; - int num_init_handles; + int initHandleCount; + rdpInitHandle initHandleList[CHANNEL_MAX_COUNT]; /* control for entry into MyVirtualChannelInit */ int can_call_init; rdpSettings* settings; - /* true once freerdp_chanman_post_connect is called */ + /* true once freerdp_channels_post_connect is called */ int is_connected; /* used for locating the channels for a given instance */ @@ -438,91 +140,89 @@ struct rdp_channels */ static rdpChannels* g_init_channels; -/* The list of all channel managers. */ -typedef struct rdp_channels_list rdpChannelsList; - -struct rdp_channels_list -{ - rdpChannels* channels; - rdpChannelsList* next; -}; - -static rdpChannelsList* g_channels_list; +static wArrayList* g_ChannelsList = NULL; /* To generate unique sequence for all open handles */ static int g_open_handle_sequence; /* For locking the global resources */ static HANDLE g_mutex_init; -static HANDLE g_mutex_list; -/* returns the channels for the open handle passed in */ static rdpChannels* freerdp_channels_find_by_open_handle(int open_handle, int* pindex) { - int lindex; - rdpChannels* channels; - rdpChannelsList* channels_list; + int i, j; + BOOL found = FALSE; + rdpChannels* channels = NULL; - WaitForSingleObject(g_mutex_list, INFINITE); + ArrayList_Lock(g_ChannelsList); - for (channels_list = g_channels_list; channels_list; channels_list = channels_list->next) + i = j = 0; + channels = (rdpChannels*) ArrayList_GetItem(g_ChannelsList, i++); + + while (channels) { - channels = channels_list->channels; - - for (lindex = 0; lindex < channels->num_channels_data; lindex++) + for (j = 0; j < channels->channelDataCount; j++) { - if (channels->channels_data[lindex].open_handle == open_handle) + if (channels->channelDataList[j].open_handle == open_handle) { - ReleaseMutex(g_mutex_list); - *pindex = lindex; - return channels; + *pindex = j; + found = TRUE; + break; } } + + if (found) + break; + + channels = (rdpChannels*) ArrayList_GetItem(g_ChannelsList, i++); } - ReleaseMutex(g_mutex_list); + ArrayList_Unlock(g_ChannelsList); - return NULL; + return (found) ? channels : NULL; } -/* returns the channels for the rdp instance passed in */ static rdpChannels* freerdp_channels_find_by_instance(freerdp* instance) { - rdpChannels* channels; - rdpChannelsList* channels_list; + int index; + BOOL found = FALSE; + rdpChannels* channels = NULL; - WaitForSingleObject(g_mutex_list, INFINITE); + ArrayList_Lock(g_ChannelsList); - for (channels_list = g_channels_list; channels_list; channels_list = channels_list->next) + index = 0; + channels = (rdpChannels*) ArrayList_GetItem(g_ChannelsList, index++); + + while (channels) { - channels = channels_list->channels; - if (channels->instance == instance) { - ReleaseMutex(g_mutex_list); - return channels; + found = TRUE; + break; } + + channels = (rdpChannels*) ArrayList_GetItem(g_ChannelsList, index++); } - ReleaseMutex(g_mutex_list); + ArrayList_Unlock(g_ChannelsList); - return NULL; + return (found) ? channels : NULL; } -/* returns struct channel_data for the channel name passed in */ -static struct channel_data* freerdp_channels_find_channel_data_by_name(rdpChannels* channels, const char* channel_name, int* pindex) +/* returns rdpChannelData for the channel name passed in */ +static rdpChannelData* freerdp_channels_find_channel_data_by_name(rdpChannels* channels, const char* channel_name, int* pindex) { - int lindex; - struct channel_data* lchannel_data; + int index; + rdpChannelData* lchannel_data; - for (lindex = 0; lindex < channels->num_channels_data; lindex++) + for (index = 0; index < channels->channelDataCount; index++) { - lchannel_data = channels->channels_data + lindex; + lchannel_data = &channels->channelDataList[index]; if (strcmp(channel_name, lchannel_data->name) == 0) { if (pindex != 0) - *pindex = lindex; + *pindex = index; return lchannel_data; } @@ -534,22 +234,22 @@ static struct channel_data* freerdp_channels_find_channel_data_by_name(rdpChanne /* returns rdpChannel for the channel id passed in */ static rdpChannel* freerdp_channels_find_channel_by_id(rdpChannels* channels, rdpSettings* settings, int channel_id, int* pindex) { - int lindex; - int lcount; - rdpChannel* lrdp_channel; + int index; + int count; + rdpChannel* channel; - lcount = settings->ChannelCount; + count = settings->ChannelCount; - for (lindex = 0; lindex < lcount; lindex++) + for (index = 0; index < count; index++) { - lrdp_channel = settings->ChannelDefArray + lindex; + channel = &settings->ChannelDefArray[index]; - if (lrdp_channel->ChannelId == channel_id) + if (channel->ChannelId == channel_id) { if (pindex != 0) - *pindex = lindex; + *pindex = index; - return lrdp_channel; + return channel; } } @@ -560,22 +260,22 @@ static rdpChannel* freerdp_channels_find_channel_by_id(rdpChannels* channels, rd static rdpChannel* freerdp_channels_find_channel_by_name(rdpChannels* channels, rdpSettings* settings, const char* channel_name, int* pindex) { - int lindex; - int lcount; - rdpChannel* lrdp_channel; + int index; + int count; + rdpChannel* channel; - lcount = settings->ChannelCount; + count = settings->ChannelCount; - for (lindex = 0; lindex < lcount; lindex++) + for (index = 0; index < count; index++) { - lrdp_channel = settings->ChannelDefArray + lindex; + channel = &settings->ChannelDefArray[index]; - if (strcmp(channel_name, lrdp_channel->Name) == 0) + if (strcmp(channel_name, channel->Name) == 0) { if (pindex != 0) - *pindex = lindex; + *pindex = index; - return lrdp_channel; + return channel; } } @@ -591,11 +291,11 @@ static UINT32 FREERDP_CC MyVirtualChannelInit(void** ppInitHandle, PCHANNEL_DEF int channelCount, UINT32 versionRequested, PCHANNEL_INIT_EVENT_FN pChannelInitEventProc) { int index; + rdpChannel* channel; rdpChannels* channels; - struct lib_data* llib; - rdpChannel* lrdp_channel; + rdpLibraryData* llib; PCHANNEL_DEF lchannel_def; - struct channel_data* lchannel_data; + rdpChannelData* lchannel_data; if (!ppInitHandle) { @@ -604,9 +304,11 @@ static UINT32 FREERDP_CC MyVirtualChannelInit(void** ppInitHandle, PCHANNEL_DEF } channels = g_init_channels; - channels->init_handles[channels->num_init_handles].channels = channels; - *ppInitHandle = &channels->init_handles[channels->num_init_handles]; - channels->num_init_handles++; + + channels->initHandleList[channels->initHandleCount].channels = channels; + *ppInitHandle = &channels->initHandleList[channels->initHandleCount]; + + channels->initHandleCount++; DEBUG_CHANNELS("enter"); @@ -616,7 +318,7 @@ static UINT32 FREERDP_CC MyVirtualChannelInit(void** ppInitHandle, PCHANNEL_DEF return CHANNEL_RC_NOT_IN_VIRTUALCHANNELENTRY; } - if (channels->num_channels_data + channelCount >= CHANNEL_MAX_COUNT) + if (channels->channelDataCount + channelCount >= CHANNEL_MAX_COUNT) { DEBUG_CHANNELS("error too many channels"); return CHANNEL_RC_TOO_MANY_CHANNELS; @@ -641,7 +343,7 @@ static UINT32 FREERDP_CC MyVirtualChannelInit(void** ppInitHandle, PCHANNEL_DEF for (index = 0; index < channelCount; index++) { - lchannel_def = pChannel + index; + lchannel_def = &pChannel[index]; if (freerdp_channels_find_channel_data_by_name(channels, lchannel_def->name, 0) != 0) { @@ -650,19 +352,17 @@ static UINT32 FREERDP_CC MyVirtualChannelInit(void** ppInitHandle, PCHANNEL_DEF } } - llib = channels->libs_data + channels->num_libs_data; + llib = &channels->libraryDataList[channels->libraryDataCount]; llib->init_event_proc = pChannelInitEventProc; llib->init_handle = *ppInitHandle; - channels->num_libs_data++; + channels->libraryDataCount++; for (index = 0; index < channelCount; index++) { - lchannel_def = pChannel + index; - lchannel_data = channels->channels_data + channels->num_channels_data; + lchannel_def = &pChannel[index]; + lchannel_data = &channels->channelDataList[channels->channelDataCount]; - WaitForSingleObject(g_mutex_list, INFINITE); lchannel_data->open_handle = g_open_handle_sequence++; - ReleaseMutex(g_mutex_list); lchannel_data->flags = 1; /* init */ strncpy(lchannel_data->name, lchannel_def->name, CHANNEL_NAME_LEN); @@ -670,9 +370,9 @@ static UINT32 FREERDP_CC MyVirtualChannelInit(void** ppInitHandle, PCHANNEL_DEF if (channels->settings->ChannelCount < 16) { - lrdp_channel = channels->settings->ChannelDefArray + channels->settings->ChannelCount; - strncpy(lrdp_channel->Name, lchannel_def->name, 7); - lrdp_channel->options = lchannel_def->options; + channel = channels->settings->ChannelDefArray + channels->settings->ChannelCount; + strncpy(channel->Name, lchannel_def->name, 7); + channel->options = lchannel_def->options; channels->settings->ChannelCount++; } else @@ -680,7 +380,7 @@ static UINT32 FREERDP_CC MyVirtualChannelInit(void** ppInitHandle, PCHANNEL_DEF DEBUG_CHANNELS("warning more than 16 channels"); } - channels->num_channels_data++; + channels->channelDataCount++; } return CHANNEL_RC_OK; @@ -695,7 +395,7 @@ static UINT32 FREERDP_CC MyVirtualChannelOpen(void* pInitHandle, UINT32* pOpenHa { int index; rdpChannels* channels; - struct channel_data* lchannel_data; + rdpChannelData* lchannel_data; DEBUG_CHANNELS("enter"); @@ -748,7 +448,7 @@ static UINT32 FREERDP_CC MyVirtualChannelClose(UINT32 openHandle) { int index; rdpChannels* channels; - struct channel_data* lchannel_data; + rdpChannelData* lchannel_data; DEBUG_CHANNELS("enter"); @@ -760,7 +460,7 @@ static UINT32 FREERDP_CC MyVirtualChannelClose(UINT32 openHandle) return CHANNEL_RC_BAD_CHANNEL_HANDLE; } - lchannel_data = channels->channels_data + index; + lchannel_data = &channels->channelDataList[index]; if (lchannel_data->flags != 2) { @@ -779,7 +479,7 @@ static UINT32 FREERDP_CC MyVirtualChannelWrite(UINT32 openHandle, void* pData, U int index; CHANNEL_OPEN_EVENT* item; rdpChannels* channels; - struct channel_data* lchannel_data; + rdpChannelData* lchannel_data; channels = freerdp_channels_find_by_open_handle(openHandle, &index); @@ -807,7 +507,7 @@ static UINT32 FREERDP_CC MyVirtualChannelWrite(UINT32 openHandle, void* pData, U return CHANNEL_RC_ZERO_LENGTH; } - lchannel_data = channels->channels_data + index; + lchannel_data = &channels->channelDataList[index]; if (lchannel_data->flags != 2) { @@ -832,11 +532,11 @@ static UINT32 FREERDP_CC MyVirtualChannelWrite(UINT32 openHandle, void* pData, U return CHANNEL_RC_OK; } -static UINT32 FREERDP_CC MyVirtualChannelEventPush(UINT32 openHandle, RDP_EVENT* event) +static UINT32 FREERDP_CC MyVirtualChannelEventPush(UINT32 openHandle, wMessage* event) { int index; rdpChannels* channels; - struct channel_data* lchannel_data; + rdpChannelData* lchannel_data; channels = freerdp_channels_find_by_open_handle(openHandle, &index); @@ -858,7 +558,7 @@ static UINT32 FREERDP_CC MyVirtualChannelEventPush(UINT32 openHandle, RDP_EVENT* return CHANNEL_RC_NULL_DATA; } - lchannel_data = channels->channels_data + index; + lchannel_data = &channels->channelDataList[index]; if (lchannel_data->flags != 2) { @@ -892,21 +592,20 @@ static UINT32 FREERDP_CC MyVirtualChannelEventPush(UINT32 openHandle, RDP_EVENT* int freerdp_channels_global_init(void) { g_init_channels = NULL; - g_channels_list = NULL; g_open_handle_sequence = 1; g_mutex_init = CreateMutex(NULL, FALSE, NULL); - g_mutex_list = CreateMutex(NULL, FALSE, NULL); + + if (!g_ChannelsList) + g_ChannelsList = ArrayList_New(TRUE); return 0; } int freerdp_channels_global_uninit(void) { - while (g_channels_list) - freerdp_channels_free(g_channels_list->channels); + /* TODO: free channels list */ CloseHandle(g_mutex_init); - CloseHandle(g_mutex_list); return 0; } @@ -914,53 +613,22 @@ int freerdp_channels_global_uninit(void) rdpChannels* freerdp_channels_new(void) { rdpChannels* channels; - rdpChannelsList* channels_list; channels = (rdpChannels*) malloc(sizeof(rdpChannels)); ZeroMemory(channels, sizeof(rdpChannels)); channels->MsgPipe = MessagePipe_New(); - /* Add it to the global list */ - channels_list = (rdpChannelsList*) malloc(sizeof(rdpChannelsList)); - ZeroMemory(channels_list, sizeof(rdpChannelsList)); - channels_list->channels = channels; - - WaitForSingleObject(g_mutex_list, INFINITE); - channels_list->next = g_channels_list; - g_channels_list = channels_list; - ReleaseMutex(g_mutex_list); + ArrayList_Add(g_ChannelsList, (void*) channels); return channels; } void freerdp_channels_free(rdpChannels* channels) { - rdpChannelsList* list; - rdpChannelsList* prev; - MessagePipe_Free(channels->MsgPipe); - /* Remove from global list */ - - WaitForSingleObject(g_mutex_list, INFINITE); - - for (prev = NULL, list = g_channels_list; list; prev = list, list = list->next) - { - if (list->channels == channels) - break; - } - - if (list) - { - if (prev) - prev->next = list->next; - else - g_channels_list = list->next; - free(list); - } - - ReleaseMutex(g_mutex_list); + /* TODO: remove from channels list */ free(channels); } @@ -968,16 +636,16 @@ void freerdp_channels_free(rdpChannels* channels) int freerdp_channels_client_load(rdpChannels* channels, rdpSettings* settings, void* entry, void* data) { int status; - struct lib_data* lib; + rdpLibraryData* lib; CHANNEL_ENTRY_POINTS_EX ep; - if (channels->num_libs_data + 1 >= CHANNEL_MAX_COUNT) + if (channels->libraryDataCount + 1 >= CHANNEL_MAX_COUNT) { - printf("error: too many channels\n"); + fprintf(stderr, "error: too many channels\n"); return 1; } - lib = channels->libs_data + channels->num_libs_data; + lib = &channels->libraryDataList[channels->libraryDataCount]; lib->entry = (PVIRTUALCHANNELENTRY) entry; ep.cbSize = sizeof(ep); @@ -986,6 +654,7 @@ int freerdp_channels_client_load(rdpChannels* channels, rdpSettings* settings, v ep.pVirtualChannelOpen = MyVirtualChannelOpen; ep.pVirtualChannelClose = MyVirtualChannelClose; ep.pVirtualChannelWrite = MyVirtualChannelWrite; + ep.pExtendedData = data; ep.pVirtualChannelEventPush = MyVirtualChannelEventPush; @@ -1007,7 +676,7 @@ int freerdp_channels_client_load(rdpChannels* channels, rdpSettings* settings, v if (!status) { - printf("error: channel export function call failed\n"); + fprintf(stderr, "error: channel export function call failed\n"); return 1; } @@ -1026,7 +695,7 @@ int freerdp_channels_load_plugin(rdpChannels* channels, rdpSettings* settings, c entry = (PVIRTUALCHANNELENTRY) freerdp_load_channel_addin_entry(name, NULL, NULL, FREERDP_ADDIN_CHANNEL_STATIC); - if (entry == NULL) + if (!entry) { DEBUG_CHANNELS("failed to find export function"); return 1; @@ -1042,40 +711,14 @@ int freerdp_channels_load_plugin(rdpChannels* channels, rdpSettings* settings, c int freerdp_channels_pre_connect(rdpChannels* channels, freerdp* instance) { int index; - void* dummy; - struct lib_data* llib; - CHANNEL_DEF lchannel_def; + rdpLibraryData* llib; DEBUG_CHANNELS("enter"); channels->instance = instance; - /** - * If rdpsnd is registered but not rdpdr, it's necessary to register a fake - * rdpdr channel to make sound work. This is a workaround for Window 7 and - * Windows 2008 - */ - if (freerdp_channels_find_channel_data_by_name(channels, "rdpsnd", 0) != 0 && - freerdp_channels_find_channel_data_by_name(channels, "rdpdr", 0) == 0) + for (index = 0; index < channels->libraryDataCount; index++) { - lchannel_def.options = CHANNEL_OPTION_INITIALIZED | - CHANNEL_OPTION_ENCRYPT_RDP; - strcpy(lchannel_def.name, "rdpdr"); - channels->can_call_init = 1; - channels->settings = instance->settings; - WaitForSingleObject(g_mutex_init, INFINITE); - g_init_channels = channels; - MyVirtualChannelInit(&dummy, &lchannel_def, 1, - VIRTUAL_CHANNEL_VERSION_WIN2000, 0); - g_init_channels = NULL; - ReleaseMutex(g_mutex_init); - channels->can_call_init = 0; - channels->settings = 0; - DEBUG_CHANNELS("registered fake rdpdr for rdpsnd."); - } - - for (index = 0; index < channels->num_libs_data; index++) - { - llib = channels->libs_data + index; + llib = &channels->libraryDataList[index]; if (llib->init_event_proc != 0) llib->init_event_proc(llib->init_handle, CHANNEL_EVENT_INITIALIZED, 0, 0); @@ -1094,17 +737,17 @@ int freerdp_channels_post_connect(rdpChannels* channels, freerdp* instance) int index; char* hostname; int hostname_len; - struct lib_data* llib; + rdpLibraryData* llib; channels->is_connected = 1; hostname = instance->settings->ServerHostname; hostname_len = strlen(hostname); - DEBUG_CHANNELS("hostname [%s] channels->num_libs [%d]", hostname, channels->num_libs_data); + DEBUG_CHANNELS("hostname [%s] channels->num_libs [%d]", hostname, channels->libraryDataCount); - for (index = 0; index < channels->num_libs_data; index++) + for (index = 0; index < channels->libraryDataCount; index++) { - llib = channels->libs_data + index; + llib = &channels->libraryDataList[index]; if (llib->init_event_proc != 0) llib->init_event_proc(llib->init_handle, CHANNEL_EVENT_CONNECTED, hostname, hostname_len); @@ -1120,9 +763,9 @@ int freerdp_channels_post_connect(rdpChannels* channels, freerdp* instance) int freerdp_channels_data(freerdp* instance, int channel_id, void* data, int data_size, int flags, int total_size) { int index; + rdpChannel* channel; rdpChannels* channels; - rdpChannel* lrdp_channel; - struct channel_data* lchannel_data; + rdpChannelData* lchannel_data; channels = freerdp_channels_find_by_instance(instance); @@ -1132,15 +775,15 @@ int freerdp_channels_data(freerdp* instance, int channel_id, void* data, int dat return 1; } - lrdp_channel = freerdp_channels_find_channel_by_id(channels, instance->settings, channel_id, &index); + channel = freerdp_channels_find_channel_by_id(channels, instance->settings, channel_id, &index); - if (!lrdp_channel) + if (!channel) { DEBUG_CHANNELS("could not find channel id"); return 1; } - lchannel_data = freerdp_channels_find_channel_data_by_name(channels, lrdp_channel->Name, &index); + lchannel_data = freerdp_channels_find_channel_data_by_name(channels, channel->Name, &index); if (!lchannel_data) { @@ -1157,28 +800,36 @@ int freerdp_channels_data(freerdp* instance, int channel_id, void* data, int dat return 0; } -static const char* event_class_to_name_table[] = -{ - "rdpdbg", /* RDP_EVENT_CLASS_DEBUG */ - "cliprdr", /* RDP_EVENT_CLASS_CLIPRDR */ - "tsmf", /* RDP_EVENT_CLASS_TSMF */ - "rail", /* RDP_EVENT_CLASS_RAIL */ - NULL -}; - /** * Send a plugin-defined event to the plugin. * called only from main thread * @param channels the channel manager instance * @param event an event object created by freerdp_event_new() */ -FREERDP_API int freerdp_channels_send_event(rdpChannels* channels, RDP_EVENT* event) +FREERDP_API int freerdp_channels_send_event(rdpChannels* channels, wMessage* event) { int index; - const char* name; - struct channel_data* lchannel_data; + const char* name = NULL; + rdpChannelData* lchannel_data; - name = event_class_to_name_table[event->event_class]; + switch (GetMessageClass(event->id)) + { + case DebugChannel_Class: + name = "rdpdbg"; + break; + + case CliprdrChannel_Class: + name = "cliprdr"; + break; + + case TsmfChannel_Class: + name = "tsmf"; + break; + + case RailChannel_Class: + name = "rail"; + break; + } if (!name) { @@ -1199,7 +850,7 @@ FREERDP_API int freerdp_channels_send_event(rdpChannels* channels, RDP_EVENT* ev if (lchannel_data->open_event_proc) { lchannel_data->open_event_proc(lchannel_data->open_handle, CHANNEL_EVENT_USER, - event, sizeof(RDP_EVENT), sizeof(RDP_EVENT), 0); + event, sizeof(wMessage), sizeof(wMessage), 0); } return 0; @@ -1211,10 +862,10 @@ FREERDP_API int freerdp_channels_send_event(rdpChannels* channels, RDP_EVENT* ev static void freerdp_channels_process_sync(rdpChannels* channels, freerdp* instance) { wMessage message; - RDP_EVENT* event; + wMessage* event; + rdpChannel* channel; CHANNEL_OPEN_EVENT* item; - rdpChannel* lrdp_channel; - struct channel_data* lchannel_data; + rdpChannelData* lchannel_data; while (MessageQueue_Peek(channels->MsgPipe->Out, &message, TRUE)) { @@ -1228,13 +879,13 @@ static void freerdp_channels_process_sync(rdpChannels* channels, freerdp* instan if (!item) break; - lchannel_data = channels->channels_data + item->Index; + lchannel_data = &channels->channelDataList[item->Index]; - lrdp_channel = freerdp_channels_find_channel_by_name(channels, instance->settings, + channel = freerdp_channels_find_channel_by_name(channels, instance->settings, lchannel_data->name, &item->Index); - if (lrdp_channel) - instance->SendChannelData(instance, lrdp_channel->ChannelId, item->Data, item->DataLength); + if (channel) + instance->SendChannelData(instance, channel->ChannelId, item->Data, item->DataLength); if (lchannel_data->open_event_proc) { @@ -1246,7 +897,7 @@ static void freerdp_channels_process_sync(rdpChannels* channels, freerdp* instan } else if (message.id == 1) { - event = (RDP_EVENT*) message.wParam; + event = (wMessage*) message.wParam; /** * Ignore for now, the same event is being pushed on the In queue, @@ -1313,16 +964,16 @@ BOOL freerdp_channels_check_fds(rdpChannels* channels, freerdp* instance) return TRUE; } -RDP_EVENT* freerdp_channels_pop_event(rdpChannels* channels) +wMessage* freerdp_channels_pop_event(rdpChannels* channels) { wMessage message; - RDP_EVENT* event = NULL; + wMessage* event = NULL; if (MessageQueue_Peek(channels->MsgPipe->In, &message, TRUE)) { if (message.id == 1) { - event = (RDP_EVENT*) message.wParam; + event = (wMessage*) message.wParam; } } @@ -1332,16 +983,16 @@ RDP_EVENT* freerdp_channels_pop_event(rdpChannels* channels) void freerdp_channels_close(rdpChannels* channels, freerdp* instance) { int index; - struct lib_data* llib; + rdpLibraryData* llib; DEBUG_CHANNELS("closing"); channels->is_connected = 0; freerdp_channels_check_fds(channels, instance); /* tell all libraries we are shutting down */ - for (index = 0; index < channels->num_libs_data; index++) + for (index = 0; index < channels->libraryDataCount; index++) { - llib = channels->libs_data + index; + llib = &channels->libraryDataList[index]; if (llib->init_event_proc != 0) llib->init_event_proc(llib->init_handle, CHANNEL_EVENT_TERMINATED, 0, 0); diff --git a/channels/cliprdr/client/cliprdr_format.c b/channels/cliprdr/client/cliprdr_format.c index 2c6db2308..aa4dfa03b 100644 --- a/channels/cliprdr/client/cliprdr_format.c +++ b/channels/cliprdr/client/cliprdr_format.c @@ -46,7 +46,7 @@ void cliprdr_process_format_list_event(cliprdrPlugin* cliprdr, RDP_CB_FORMAT_LIST_EVENT* cb_event) { int i; - STREAM* s; + wStream* s; DEBUG_CLIPRDR("Sending Clipboard Format List"); @@ -57,7 +57,7 @@ void cliprdr_process_format_list_event(cliprdrPlugin* cliprdr, RDP_CB_FORMAT_LIS } else { - STREAM* body = stream_new(0); + wStream* body = stream_new(0); for (i = 0; i < cb_event->num_formats; i++) { @@ -79,7 +79,9 @@ void cliprdr_process_format_list_event(cliprdrPlugin* cliprdr, RDP_CB_FORMAT_LIS name = CFSTR_GIF; name_length = sizeof(CFSTR_GIF); break; default: - name = "\0\0"; name_length = 2; + name = "\0\0"; + name_length = 2; + break; } if (!cliprdr->use_long_format_names) @@ -101,13 +103,13 @@ void cliprdr_process_format_list_event(cliprdrPlugin* cliprdr, RDP_CB_FORMAT_LIS static void cliprdr_send_format_list_response(cliprdrPlugin* cliprdr) { - STREAM* s; + wStream* s; DEBUG_CLIPRDR("Sending Clipboard Format List Response"); s = cliprdr_packet_new(CB_FORMAT_LIST_RESPONSE, CB_RESPONSE_OK, 0); cliprdr_packet_send(cliprdr, s); } -void cliprdr_process_short_format_names(cliprdrPlugin* cliprdr, STREAM* s, UINT32 length, UINT16 flags) +void cliprdr_process_short_format_names(cliprdrPlugin* cliprdr, wStream* s, UINT32 length, UINT16 flags) { int i; BOOL ascii; @@ -139,20 +141,20 @@ void cliprdr_process_short_format_names(cliprdrPlugin* cliprdr, STREAM* s, UINT3 if (ascii) { - format_name->name = _strdup((char*) s->p); + format_name->name = _strdup((char*) s->pointer); format_name->length = strlen(format_name->name); } else { format_name->name = NULL; - format_name->length = ConvertFromUnicode(CP_UTF8, 0, (WCHAR*) s->p, 32 / 2, &format_name->name, 0, NULL, NULL); + format_name->length = ConvertFromUnicode(CP_UTF8, 0, (WCHAR*) s->pointer, 32 / 2, &format_name->name, 0, NULL, NULL); } stream_seek(s, 32); } } -void cliprdr_process_long_format_names(cliprdrPlugin* cliprdr, STREAM* s, UINT32 length, UINT16 flags) +void cliprdr_process_long_format_names(cliprdrPlugin* cliprdr, wStream* s, UINT32 length, UINT16 flags) { int allocated_formats = 8; BYTE* end_mark; @@ -194,7 +196,7 @@ void cliprdr_process_long_format_names(cliprdrPlugin* cliprdr, STREAM* s, UINT32 } } -void cliprdr_process_format_list(cliprdrPlugin* cliprdr, STREAM* s, UINT32 dataLen, UINT16 msgFlags) +void cliprdr_process_format_list(cliprdrPlugin* cliprdr, wStream* s, UINT32 dataLen, UINT16 msgFlags) { int i; UINT32 format; @@ -202,8 +204,8 @@ void cliprdr_process_format_list(cliprdrPlugin* cliprdr, STREAM* s, UINT32 dataL CLIPRDR_FORMAT_NAME* format_name; RDP_CB_FORMAT_LIST_EVENT* cb_event; - cb_event = (RDP_CB_FORMAT_LIST_EVENT*) freerdp_event_new(RDP_EVENT_CLASS_CLIPRDR, - RDP_EVENT_TYPE_CB_FORMAT_LIST, NULL, NULL); + cb_event = (RDP_CB_FORMAT_LIST_EVENT*) freerdp_event_new(CliprdrChannel_Class, + CliprdrChannel_FormatList, NULL, NULL); if (dataLen > 0) { @@ -282,15 +284,15 @@ void cliprdr_process_format_list(cliprdrPlugin* cliprdr, STREAM* s, UINT32 dataL cliprdr->num_format_names = 0; - svc_plugin_send_event((rdpSvcPlugin*) cliprdr, (RDP_EVENT*) cb_event); + svc_plugin_send_event((rdpSvcPlugin*) cliprdr, (wMessage*) cb_event); cliprdr_send_format_list_response(cliprdr); } -void cliprdr_process_format_list_response(cliprdrPlugin* cliprdr, STREAM* s, UINT32 dataLen, UINT16 msgFlags) +void cliprdr_process_format_list_response(cliprdrPlugin* cliprdr, wStream* s, UINT32 dataLen, UINT16 msgFlags) { /* where is this documented? */ #if 0 - RDP_EVENT* event; + wMessage* event; if ((msgFlags & CB_RESPONSE_FAIL) != 0) { @@ -300,20 +302,20 @@ void cliprdr_process_format_list_response(cliprdrPlugin* cliprdr, STREAM* s, UIN #endif } -void cliprdr_process_format_data_request(cliprdrPlugin* cliprdr, STREAM* s, UINT32 dataLen, UINT16 msgFlags) +void cliprdr_process_format_data_request(cliprdrPlugin* cliprdr, wStream* s, UINT32 dataLen, UINT16 msgFlags) { RDP_CB_DATA_REQUEST_EVENT* cb_event; - cb_event = (RDP_CB_DATA_REQUEST_EVENT*) freerdp_event_new(RDP_EVENT_CLASS_CLIPRDR, - RDP_EVENT_TYPE_CB_DATA_REQUEST, NULL, NULL); + cb_event = (RDP_CB_DATA_REQUEST_EVENT*) freerdp_event_new(CliprdrChannel_Class, + CliprdrChannel_DataRequest, NULL, NULL); stream_read_UINT32(s, cb_event->format); - svc_plugin_send_event((rdpSvcPlugin*) cliprdr, (RDP_EVENT*) cb_event); + svc_plugin_send_event((rdpSvcPlugin*) cliprdr, (wMessage*) cb_event); } void cliprdr_process_format_data_response_event(cliprdrPlugin* cliprdr, RDP_CB_DATA_RESPONSE_EVENT* cb_event) { - STREAM* s; + wStream* s; DEBUG_CLIPRDR("Sending Format Data Response"); @@ -332,7 +334,7 @@ void cliprdr_process_format_data_response_event(cliprdrPlugin* cliprdr, RDP_CB_D void cliprdr_process_format_data_request_event(cliprdrPlugin* cliprdr, RDP_CB_DATA_REQUEST_EVENT* cb_event) { - STREAM* s; + wStream* s; DEBUG_CLIPRDR("Sending Format Data Request"); @@ -341,19 +343,19 @@ void cliprdr_process_format_data_request_event(cliprdrPlugin* cliprdr, RDP_CB_DA cliprdr_packet_send(cliprdr, s); } -void cliprdr_process_format_data_response(cliprdrPlugin* cliprdr, STREAM* s, UINT32 dataLen, UINT16 msgFlags) +void cliprdr_process_format_data_response(cliprdrPlugin* cliprdr, wStream* s, UINT32 dataLen, UINT16 msgFlags) { RDP_CB_DATA_RESPONSE_EVENT* cb_event; - cb_event = (RDP_CB_DATA_RESPONSE_EVENT*) freerdp_event_new(RDP_EVENT_CLASS_CLIPRDR, - RDP_EVENT_TYPE_CB_DATA_RESPONSE, NULL, NULL); + cb_event = (RDP_CB_DATA_RESPONSE_EVENT*) freerdp_event_new(CliprdrChannel_Class, + CliprdrChannel_DataResponse, NULL, NULL); if (dataLen > 0) { cb_event->size = dataLen; cb_event->data = (BYTE*) malloc(dataLen); - memcpy(cb_event->data, stream_get_tail(s), dataLen); + CopyMemory(cb_event->data, stream_get_tail(s), dataLen); } - svc_plugin_send_event((rdpSvcPlugin*) cliprdr, (RDP_EVENT*) cb_event); + svc_plugin_send_event((rdpSvcPlugin*) cliprdr, (wMessage*) cb_event); } diff --git a/channels/cliprdr/client/cliprdr_format.h b/channels/cliprdr/client/cliprdr_format.h index ec6bb343d..5454e028b 100644 --- a/channels/cliprdr/client/cliprdr_format.h +++ b/channels/cliprdr/client/cliprdr_format.h @@ -22,13 +22,13 @@ #define __CLIPRDR_FORMAT_H void cliprdr_process_format_list_event(cliprdrPlugin* cliprdr, RDP_CB_FORMAT_LIST_EVENT* cb_event); -void cliprdr_process_format_list(cliprdrPlugin* cliprdr, STREAM* s, UINT32 dataLen, UINT16 msgFlags); -void cliprdr_process_format_list_response(cliprdrPlugin* cliprdr, STREAM* s, UINT32 dataLen, UINT16 msgFlags); +void cliprdr_process_format_list(cliprdrPlugin* cliprdr, wStream* s, UINT32 dataLen, UINT16 msgFlags); +void cliprdr_process_format_list_response(cliprdrPlugin* cliprdr, wStream* s, UINT32 dataLen, UINT16 msgFlags); -void cliprdr_process_format_data_request(cliprdrPlugin* cliprdr, STREAM* s, UINT32 dataLen, UINT16 msgFlags); +void cliprdr_process_format_data_request(cliprdrPlugin* cliprdr, wStream* s, UINT32 dataLen, UINT16 msgFlags); void cliprdr_process_format_data_response_event(cliprdrPlugin* cliprdr, RDP_CB_DATA_RESPONSE_EVENT* cb_event); void cliprdr_process_format_data_request_event(cliprdrPlugin* cliprdr, RDP_CB_DATA_REQUEST_EVENT* cb_event); -void cliprdr_process_format_data_response(cliprdrPlugin* cliprdr, STREAM* s, UINT32 dataLen, UINT16 msgFlags); +void cliprdr_process_format_data_response(cliprdrPlugin* cliprdr, wStream* s, UINT32 dataLen, UINT16 msgFlags); #endif /* __CLIPRDR_FORMAT_H */ diff --git a/channels/cliprdr/client/cliprdr_main.c b/channels/cliprdr/client/cliprdr_main.c index ddcc64099..c19479e85 100644 --- a/channels/cliprdr/client/cliprdr_main.c +++ b/channels/cliprdr/client/cliprdr_main.c @@ -53,9 +53,9 @@ static const char* const CB_MSG_TYPE_STRINGS[] = "CB_UNLOCK_CLIPDATA" }; -STREAM* cliprdr_packet_new(UINT16 msgType, UINT16 msgFlags, UINT32 dataLen) +wStream* cliprdr_packet_new(UINT16 msgType, UINT16 msgFlags, UINT32 dataLen) { - STREAM* s; + wStream* s; s = stream_new(dataLen + 8); stream_write_UINT16(s, msgType); @@ -66,7 +66,7 @@ STREAM* cliprdr_packet_new(UINT16 msgType, UINT16 msgFlags, UINT32 dataLen) return s; } -void cliprdr_packet_send(cliprdrPlugin* cliprdr, STREAM* s) +void cliprdr_packet_send(cliprdrPlugin* cliprdr, wStream* s) { int pos; UINT32 dataLen; @@ -87,21 +87,21 @@ static void cliprdr_process_connect(rdpSvcPlugin* plugin) void cliprdr_print_general_capability_flags(UINT32 flags) { - printf("generalFlags (0x%08X) {\n", flags); + fprintf(stderr, "generalFlags (0x%08X) {\n", flags); if (flags & CB_USE_LONG_FORMAT_NAMES) - printf("\tCB_USE_LONG_FORMAT_NAMES\n"); + fprintf(stderr, "\tCB_USE_LONG_FORMAT_NAMES\n"); if (flags & CB_STREAM_FILECLIP_ENABLED) - printf("\tCB_STREAM_FILECLIP_ENABLED\n"); + fprintf(stderr, "\tCB_STREAM_FILECLIP_ENABLED\n"); if (flags & CB_FILECLIP_NO_FILE_PATHS) - printf("\tCB_FILECLIP_NO_FILE_PATHS\n"); + fprintf(stderr, "\tCB_FILECLIP_NO_FILE_PATHS\n"); if (flags & CB_CAN_LOCK_CLIPDATA) - printf("\tCB_CAN_LOCK_CLIPDATA\n"); + fprintf(stderr, "\tCB_CAN_LOCK_CLIPDATA\n"); - printf("}\n"); + fprintf(stderr, "}\n"); } -static void cliprdr_process_general_capability(cliprdrPlugin* cliprdr, STREAM* s) +static void cliprdr_process_general_capability(cliprdrPlugin* cliprdr, wStream* s) { UINT32 version; UINT32 generalFlags; @@ -130,7 +130,7 @@ static void cliprdr_process_general_capability(cliprdrPlugin* cliprdr, STREAM* s cliprdr->received_caps = TRUE; } -static void cliprdr_process_clip_caps(cliprdrPlugin* cliprdr, STREAM* s, UINT16 length, UINT16 flags) +static void cliprdr_process_clip_caps(cliprdrPlugin* cliprdr, wStream* s, UINT16 length, UINT16 flags) { int i; UINT16 lengthCapability; @@ -162,7 +162,7 @@ static void cliprdr_process_clip_caps(cliprdrPlugin* cliprdr, STREAM* s, UINT16 static void cliprdr_send_clip_caps(cliprdrPlugin* cliprdr) { - STREAM* s; + wStream* s; UINT32 flags; s = cliprdr_packet_new(CB_CLIP_CAPS, 0, 4 + CB_CAPSTYPE_GENERAL_LEN); @@ -181,18 +181,19 @@ static void cliprdr_send_clip_caps(cliprdrPlugin* cliprdr) cliprdr_packet_send(cliprdr, s); } -static void cliprdr_process_monitor_ready(cliprdrPlugin* cliprdr, STREAM* s, UINT16 length, UINT16 flags) +static void cliprdr_process_monitor_ready(cliprdrPlugin* cliprdr, wStream* s, UINT16 length, UINT16 flags) { - RDP_EVENT* event; + wMessage* event; if (cliprdr->received_caps) cliprdr_send_clip_caps(cliprdr); - event = freerdp_event_new(RDP_EVENT_CLASS_CLIPRDR, RDP_EVENT_TYPE_CB_MONITOR_READY, NULL, NULL); + event = freerdp_event_new(CliprdrChannel_Class, CliprdrChannel_MonitorReady, NULL, NULL); + svc_plugin_send_event((rdpSvcPlugin*) cliprdr, event); } -static void cliprdr_process_receive(rdpSvcPlugin* plugin, STREAM* s) +static void cliprdr_process_receive(rdpSvcPlugin* plugin, wStream* s) { UINT16 msgType; UINT16 msgFlags; @@ -240,24 +241,24 @@ static void cliprdr_process_receive(rdpSvcPlugin* plugin, STREAM* s) stream_free(s); } -static void cliprdr_process_event(rdpSvcPlugin* plugin, RDP_EVENT* event) +static void cliprdr_process_event(rdpSvcPlugin* plugin, wMessage* event) { - switch (event->event_type) + switch (GetMessageType(event->id)) { - case RDP_EVENT_TYPE_CB_FORMAT_LIST: + case CliprdrChannel_FormatList: cliprdr_process_format_list_event((cliprdrPlugin*) plugin, (RDP_CB_FORMAT_LIST_EVENT*) event); break; - case RDP_EVENT_TYPE_CB_DATA_REQUEST: + case CliprdrChannel_DataRequest: cliprdr_process_format_data_request_event((cliprdrPlugin*) plugin, (RDP_CB_DATA_REQUEST_EVENT*) event); break; - case RDP_EVENT_TYPE_CB_DATA_RESPONSE: + case CliprdrChannel_DataResponse: cliprdr_process_format_data_response_event((cliprdrPlugin*) plugin, (RDP_CB_DATA_RESPONSE_EVENT*) event); break; default: - DEBUG_WARN("unknown event type %d", event->event_type); + DEBUG_WARN("unknown event type %d", GetMessageType(event->id)); break; } @@ -269,12 +270,37 @@ static void cliprdr_process_terminate(rdpSvcPlugin* plugin) free(plugin); } +/** + * Callback Interface + */ + +int cliprdr_monitor_ready(CliprdrClientContext* context) +{ + return 0; +} + +int cliprdr_format_list(CliprdrClientContext* context) +{ + return 0; +} + +int cliprdr_data_request(CliprdrClientContext* context) +{ + return 0; +} + +int cliprdr_data_response(CliprdrClientContext* context) +{ + return 0; +} + /* cliprdr is always built-in */ #define VirtualChannelEntry cliprdr_VirtualChannelEntry int VirtualChannelEntry(PCHANNEL_ENTRY_POINTS pEntryPoints) { cliprdrPlugin* _p; + CliprdrClientContext* context; _p = (cliprdrPlugin*) malloc(sizeof(cliprdrPlugin)); ZeroMemory(_p, sizeof(cliprdrPlugin)); @@ -292,6 +318,15 @@ int VirtualChannelEntry(PCHANNEL_ENTRY_POINTS pEntryPoints) _p->plugin.event_callback = cliprdr_process_event; _p->plugin.terminate_callback = cliprdr_process_terminate; + context = (CliprdrClientContext*) malloc(sizeof(CliprdrClientContext)); + + context->MonitorReady = cliprdr_monitor_ready; + context->FormatList = cliprdr_format_list; + context->DataRequest = cliprdr_data_request; + context->DataResponse = cliprdr_data_response; + + _p->plugin.channel_entry_points.pInterface = (void*) context; + svc_plugin_init((rdpSvcPlugin*) _p, pEntryPoints); return 1; diff --git a/channels/cliprdr/client/cliprdr_main.h b/channels/cliprdr/client/cliprdr_main.h index f48a4a742..b2b984d31 100644 --- a/channels/cliprdr/client/cliprdr_main.h +++ b/channels/cliprdr/client/cliprdr_main.h @@ -21,8 +21,9 @@ #ifndef __CLIPRDR_MAIN_H #define __CLIPRDR_MAIN_H +#include + #include -#include struct _CLIPRDR_FORMAT_NAME { @@ -45,8 +46,8 @@ struct cliprdr_plugin }; typedef struct cliprdr_plugin cliprdrPlugin; -STREAM* cliprdr_packet_new(UINT16 msgType, UINT16 msgFlags, UINT32 dataLen); -void cliprdr_packet_send(cliprdrPlugin* cliprdr, STREAM* data_out); +wStream* cliprdr_packet_new(UINT16 msgType, UINT16 msgFlags, UINT32 dataLen); +void cliprdr_packet_send(cliprdrPlugin* cliprdr, wStream* data_out); #ifdef WITH_DEBUG_CLIPRDR #define DEBUG_CLIPRDR(fmt, ...) DEBUG_CLASS(CLIPRDR, fmt, ## __VA_ARGS__) diff --git a/channels/drdynvc/client/drdynvc_main.c b/channels/drdynvc/client/drdynvc_main.c index e575e62df..a6b062692 100644 --- a/channels/drdynvc/client/drdynvc_main.c +++ b/channels/drdynvc/client/drdynvc_main.c @@ -28,7 +28,7 @@ #include #include -#include +#include #include #include "dvcman.h" @@ -55,7 +55,7 @@ struct drdynvc_plugin IWTSVirtualChannelManager* channel_mgr; }; -static int drdynvc_write_variable_uint(STREAM* stream, UINT32 val) +static int drdynvc_write_variable_uint(wStream* stream, UINT32 val) { int cb; @@ -80,7 +80,7 @@ static int drdynvc_write_variable_uint(STREAM* stream, UINT32 val) int drdynvc_write_data(drdynvcPlugin* drdynvc, UINT32 ChannelId, BYTE* data, UINT32 data_size) { - STREAM* data_out; + wStream* data_out; UINT32 pos = 0; UINT32 cbChId; UINT32 cbLen; @@ -158,7 +158,7 @@ int drdynvc_write_data(drdynvcPlugin* drdynvc, UINT32 ChannelId, BYTE* data, UIN return 0; } -int drdynvc_push_event(drdynvcPlugin* drdynvc, RDP_EVENT* event) +int drdynvc_push_event(drdynvcPlugin* drdynvc, wMessage* event) { int error; @@ -173,9 +173,9 @@ int drdynvc_push_event(drdynvcPlugin* drdynvc, RDP_EVENT* event) return 0; } -static int drdynvc_process_capability_request(drdynvcPlugin* drdynvc, int Sp, int cbChId, STREAM* s) +static int drdynvc_process_capability_request(drdynvcPlugin* drdynvc, int Sp, int cbChId, wStream* s) { - STREAM* data_out; + wStream* data_out; int error; DEBUG_DVC("Sp=%d cbChId=%d", Sp, cbChId); @@ -206,7 +206,7 @@ static int drdynvc_process_capability_request(drdynvcPlugin* drdynvc, int Sp, in return 0; } -static UINT32 drdynvc_read_variable_uint(STREAM* stream, int cbLen) +static UINT32 drdynvc_read_variable_uint(wStream* stream, int cbLen) { UINT32 val; @@ -228,12 +228,12 @@ static UINT32 drdynvc_read_variable_uint(STREAM* stream, int cbLen) return val; } -static int drdynvc_process_create_request(drdynvcPlugin* drdynvc, int Sp, int cbChId, STREAM* s) +static int drdynvc_process_create_request(drdynvcPlugin* drdynvc, int Sp, int cbChId, wStream* s) { int pos; int error; UINT32 ChannelId; - STREAM* data_out; + wStream* data_out; ChannelId = drdynvc_read_variable_uint(s, cbChId); pos = stream_get_pos(s); @@ -268,7 +268,7 @@ static int drdynvc_process_create_request(drdynvcPlugin* drdynvc, int Sp, int cb return 0; } -static int drdynvc_process_data_first(drdynvcPlugin* drdynvc, int Sp, int cbChId, STREAM* s) +static int drdynvc_process_data_first(drdynvcPlugin* drdynvc, int Sp, int cbChId, wStream* s) { int error; UINT32 Length; @@ -287,7 +287,7 @@ static int drdynvc_process_data_first(drdynvcPlugin* drdynvc, int Sp, int cbChId stream_get_tail(s), stream_get_left(s)); } -static int drdynvc_process_data(drdynvcPlugin* drdynvc, int Sp, int cbChId, STREAM* s) +static int drdynvc_process_data(drdynvcPlugin* drdynvc, int Sp, int cbChId, wStream* s) { UINT32 ChannelId; @@ -298,7 +298,7 @@ static int drdynvc_process_data(drdynvcPlugin* drdynvc, int Sp, int cbChId, STRE stream_get_tail(s), stream_get_left(s)); } -static int drdynvc_process_close_request(drdynvcPlugin* drdynvc, int Sp, int cbChId, STREAM* s) +static int drdynvc_process_close_request(drdynvcPlugin* drdynvc, int Sp, int cbChId, wStream* s) { UINT32 ChannelId; @@ -309,7 +309,7 @@ static int drdynvc_process_close_request(drdynvcPlugin* drdynvc, int Sp, int cbC return 0; } -static void drdynvc_process_receive(rdpSvcPlugin* plugin, STREAM* s) +static void drdynvc_process_receive(rdpSvcPlugin* plugin, wStream* s) { int value; int Cmd; @@ -372,7 +372,7 @@ static void drdynvc_process_connect(rdpSvcPlugin* plugin) dvcman_init(drdynvc->channel_mgr); } -static void drdynvc_process_event(rdpSvcPlugin* plugin, RDP_EVENT* event) +static void drdynvc_process_event(rdpSvcPlugin* plugin, wMessage* event) { freerdp_event_free(event); } diff --git a/channels/drdynvc/client/drdynvc_main.h b/channels/drdynvc/client/drdynvc_main.h index 3cfdcd6d3..4cc9a6695 100644 --- a/channels/drdynvc/client/drdynvc_main.h +++ b/channels/drdynvc/client/drdynvc_main.h @@ -25,6 +25,6 @@ typedef struct drdynvc_plugin drdynvcPlugin; int drdynvc_write_data(drdynvcPlugin* plugin, UINT32 ChannelId, BYTE* data, UINT32 data_size); -int drdynvc_push_event(drdynvcPlugin* plugin, RDP_EVENT* event); +int drdynvc_push_event(drdynvcPlugin* plugin, wMessage* event); #endif diff --git a/channels/drdynvc/client/dvcman.c b/channels/drdynvc/client/dvcman.c index 27ec7a57f..831205a3a 100644 --- a/channels/drdynvc/client/dvcman.c +++ b/channels/drdynvc/client/dvcman.c @@ -30,7 +30,7 @@ #include -#include +#include #include #include "drdynvc_types.h" @@ -86,7 +86,7 @@ struct _DVCMAN_CHANNEL UINT32 channel_id; IWTSVirtualChannelCallback* channel_callback; - STREAM* dvc_data; + wStream* dvc_data; HANDLE dvc_chan_mutex; }; @@ -131,7 +131,7 @@ static int dvcman_create_listener(IWTSVirtualChannelManager* pChannelMgr, } } -static int dvcman_push_event(IWTSVirtualChannelManager* pChannelMgr, RDP_EVENT* pEvent) +static int dvcman_push_event(IWTSVirtualChannelManager* pChannelMgr, wMessage* pEvent) { int status; DVCMAN* dvcman = (DVCMAN*) pChannelMgr; @@ -140,11 +140,11 @@ static int dvcman_push_event(IWTSVirtualChannelManager* pChannelMgr, RDP_EVENT* if (status == 0) { - DEBUG_DVC("event_type %d pushed.", pEvent->event_type); + DEBUG_DVC("event_type %d pushed.", GetMessageType(pEvent->id)); } else { - DEBUG_WARN("event_type %d push failed.", pEvent->event_type); + DEBUG_WARN("event_type %d push failed.", GetMessageType(pEvent->id)); } return status; @@ -233,7 +233,7 @@ int dvcman_load_addin(IWTSVirtualChannelManager* pChannelMgr, ADDIN_ARGV* args) DVCMAN_ENTRY_POINTS entryPoints; PDVC_PLUGIN_ENTRY pDVCPluginEntry = NULL; - printf("Loading Dynamic Virtual Channel %s\n", args->argv[0]); + fprintf(stderr, "Loading Dynamic Virtual Channel %s\n", args->argv[0]); pDVCPluginEntry = (PDVC_PLUGIN_ENTRY) freerdp_load_channel_addin_entry(args->argv[0], NULL, NULL, FREERDP_ADDIN_CHANNEL_DYNAMIC); diff --git a/channels/drive/client/drive_file.c b/channels/drive/client/drive_file.c index 4d4e6e8dd..aa5a3d5f2 100644 --- a/channels/drive/client/drive_file.c +++ b/channels/drive/client/drive_file.c @@ -41,7 +41,7 @@ #include #include -#include +#include #include #include @@ -376,7 +376,7 @@ BOOL drive_file_write(DRIVE_FILE* file, BYTE* buffer, UINT32 Length) return TRUE; } -BOOL drive_file_query_information(DRIVE_FILE* file, UINT32 FsInformationClass, STREAM* output) +BOOL drive_file_query_information(DRIVE_FILE* file, UINT32 FsInformationClass, wStream* output) { struct STAT st; @@ -428,7 +428,7 @@ BOOL drive_file_query_information(DRIVE_FILE* file, UINT32 FsInformationClass, S return TRUE; } -BOOL drive_file_set_information(DRIVE_FILE* file, UINT32 FsInformationClass, UINT32 Length, STREAM* input) +BOOL drive_file_set_information(DRIVE_FILE* file, UINT32 FsInformationClass, UINT32 Length, wStream* input) { char* s = NULL; mode_t m; @@ -534,7 +534,7 @@ BOOL drive_file_set_information(DRIVE_FILE* file, UINT32 FsInformationClass, UIN } BOOL drive_file_query_directory(DRIVE_FILE* file, UINT32 FsInformationClass, BYTE InitialQuery, - const char* path, STREAM* output) + const char* path, wStream* output) { int length; BOOL ret; diff --git a/channels/drive/client/drive_file.h b/channels/drive/client/drive_file.h index ca7683eff..60c8cb477 100644 --- a/channels/drive/client/drive_file.h +++ b/channels/drive/client/drive_file.h @@ -107,9 +107,9 @@ void drive_file_free(DRIVE_FILE* file); BOOL drive_file_seek(DRIVE_FILE* file, UINT64 Offset); BOOL drive_file_read(DRIVE_FILE* file, BYTE* buffer, UINT32* Length); BOOL drive_file_write(DRIVE_FILE* file, BYTE* buffer, UINT32 Length); -BOOL drive_file_query_information(DRIVE_FILE* file, UINT32 FsInformationClass, STREAM* output); -BOOL drive_file_set_information(DRIVE_FILE* file, UINT32 FsInformationClass, UINT32 Length, STREAM* input); +BOOL drive_file_query_information(DRIVE_FILE* file, UINT32 FsInformationClass, wStream* output); +BOOL drive_file_set_information(DRIVE_FILE* file, UINT32 FsInformationClass, UINT32 Length, wStream* input); BOOL drive_file_query_directory(DRIVE_FILE* file, UINT32 FsInformationClass, BYTE InitialQuery, - const char* path, STREAM* output); + const char* path, wStream* output); #endif /* FREERDP_CHANNEL_DRIVE_FILE_H */ diff --git a/channels/drive/client/drive_main.c b/channels/drive/client/drive_main.c index 35fd94f6c..8e7d1c8a1 100644 --- a/channels/drive/client/drive_main.c +++ b/channels/drive/client/drive_main.c @@ -41,7 +41,7 @@ #include #include -#include +#include #include #include @@ -386,7 +386,7 @@ static void drive_process_irp_set_information(DRIVE_DEVICE* disk, IRP* irp) static void drive_process_irp_query_volume_information(DRIVE_DEVICE* disk, IRP* irp) { UINT32 FsInformationClass; - STREAM* output = irp->output; + wStream* output = irp->output; struct STATVFS svfst; struct STAT st; char* volumeLabel = {"FREERDP"}; @@ -474,7 +474,7 @@ static void drive_process_irp_query_volume_information(DRIVE_DEVICE* disk, IRP* static void drive_process_irp_silent_ignore(DRIVE_DEVICE* disk, IRP* irp) { UINT32 FsInformationClass; - STREAM* output = irp->output; + wStream* output = irp->output; stream_read_UINT32(irp->input, FsInformationClass); diff --git a/channels/echo/client/echo_main.c b/channels/echo/client/echo_main.c index 63b4fde68..595844918 100644 --- a/channels/echo/client/echo_main.c +++ b/channels/echo/client/echo_main.c @@ -30,7 +30,7 @@ #include -#include +#include #include "echo_main.h" diff --git a/channels/parallel/client/parallel_main.c b/channels/parallel/client/parallel_main.c index 5b3d1d7c2..4b210b1c5 100644 --- a/channels/parallel/client/parallel_main.c +++ b/channels/parallel/client/parallel_main.c @@ -47,13 +47,12 @@ #include #include #include +#include #include #include #include -#include -#include -#include +#include #include #include @@ -65,8 +64,8 @@ struct _PARALLEL_DEVICE char* path; UINT32 id; - PSLIST_HEADER pIrpList; - freerdp_thread* thread; + HANDLE thread; + wMessageQueue* queue; }; typedef struct _PARALLEL_DEVICE PARALLEL_DEVICE; @@ -138,7 +137,7 @@ static void parallel_process_irp_read(PARALLEL_DEVICE* parallel, IRP* irp) buffer = (BYTE*) malloc(Length); - status = read(parallel->file, irp->output->p, Length); + status = read(parallel->file, irp->output->pointer, Length); if (status < 0) { @@ -155,11 +154,13 @@ static void parallel_process_irp_read(PARALLEL_DEVICE* parallel, IRP* irp) } stream_write_UINT32(irp->output, Length); + if (Length > 0) { stream_check_size(irp->output, Length); stream_write(irp->output, buffer, Length); } + free(buffer); irp->Complete(irp); @@ -167,10 +168,10 @@ static void parallel_process_irp_read(PARALLEL_DEVICE* parallel, IRP* irp) static void parallel_process_irp_write(PARALLEL_DEVICE* parallel, IRP* irp) { + UINT32 len; UINT32 Length; UINT64 Offset; ssize_t status; - UINT32 len; stream_read_UINT32(irp->input, Length); stream_read_UINT64(irp->input, Offset); @@ -244,43 +245,28 @@ static void parallel_process_irp(PARALLEL_DEVICE* parallel, IRP* irp) } } -static void parallel_process_irp_list(PARALLEL_DEVICE* parallel) -{ - IRP* irp; - - while (1) - { - if (freerdp_thread_is_stopped(parallel->thread)) - break; - - irp = (IRP*) InterlockedPopEntrySList(parallel->pIrpList); - - if (irp == NULL) - break; - - parallel_process_irp(parallel, irp); - } -} - static void* parallel_thread_func(void* arg) { + IRP* irp; + wMessage message; PARALLEL_DEVICE* parallel = (PARALLEL_DEVICE*) arg; while (1) { - if (freerdp_thread_wait(parallel->thread) < 0) + if (!MessageQueue_Wait(parallel->queue)) break; - if (freerdp_thread_is_stopped(parallel->thread)) + if (!MessageQueue_Peek(parallel->queue, &message, TRUE)) break; - freerdp_thread_reset(parallel->thread); + if (message.id == WMQ_QUIT) + break; - parallel_process_irp_list(parallel); + irp = (IRP*) message.wParam; + + parallel_process_irp(parallel, irp); } - freerdp_thread_quit(parallel->thread); - return NULL; } @@ -288,25 +274,20 @@ static void parallel_irp_request(DEVICE* device, IRP* irp) { PARALLEL_DEVICE* parallel = (PARALLEL_DEVICE*) device; - InterlockedPushEntrySList(parallel->pIrpList, &(irp->ItemEntry)); - - freerdp_thread_signal(parallel->thread); + MessageQueue_Post(parallel->queue, NULL, 0, (void*) irp, NULL); } static void parallel_free(DEVICE* device) { - IRP* irp; PARALLEL_DEVICE* parallel = (PARALLEL_DEVICE*) device; DEBUG_SVC("freeing device"); - freerdp_thread_stop(parallel->thread); - freerdp_thread_free(parallel->thread); + MessageQueue_PostQuit(parallel->queue, 0); + WaitForSingleObject(parallel->thread, INFINITE); - while ((irp = (IRP*) InterlockedPopEntrySList(parallel->pIrpList)) != NULL) - irp->Discard(irp); - - _aligned_free(parallel->pIrpList); + MessageQueue_Free(parallel->queue); + CloseHandle(parallel->thread); free(parallel); } @@ -345,14 +326,11 @@ int DeviceServiceEntry(PDEVICE_SERVICE_ENTRY_POINTS pEntryPoints) parallel->path = path; - parallel->pIrpList = (PSLIST_HEADER) _aligned_malloc(sizeof(SLIST_HEADER), MEMORY_ALLOCATION_ALIGNMENT); - InitializeSListHead(parallel->pIrpList); - - parallel->thread = freerdp_thread_new(); + parallel->queue = MessageQueue_New(); pEntryPoints->RegisterDevice(pEntryPoints->devman, (DEVICE*) parallel); - freerdp_thread_start(parallel->thread, parallel_thread_func, parallel); + parallel->thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) parallel_thread_func, (void*) parallel, 0, NULL); } return 0; diff --git a/channels/printer/client/printer_main.c b/channels/printer/client/printer_main.c index 322c7f322..57518219f 100644 --- a/channels/printer/client/printer_main.c +++ b/channels/printer/client/printer_main.c @@ -30,10 +30,9 @@ #include #include -#include -#include -#include +#include #include +#include #ifdef WITH_CUPS #include "printer_cups.h" @@ -53,17 +52,21 @@ struct _PRINTER_DEVICE rdpPrinter* printer; PSLIST_HEADER pIrpList; - freerdp_thread* thread; + + HANDLE event; + HANDLE stopEvent; + + HANDLE thread; }; static void printer_process_irp_create(PRINTER_DEVICE* printer_dev, IRP* irp) { rdpPrintJob* printjob = NULL; - if (printer_dev->printer != NULL) + if (printer_dev->printer) printjob = printer_dev->printer->CreatePrintJob(printer_dev->printer, irp->devman->id_sequence++); - if (printjob != NULL) + if (printjob) { stream_write_UINT32(irp->output, printjob->id); /* FileId */ @@ -87,7 +90,7 @@ static void printer_process_irp_close(PRINTER_DEVICE* printer_dev, IRP* irp) if (printer_dev->printer != NULL) printjob = printer_dev->printer->FindPrintJob(printer_dev->printer, irp->FileId); - if (printjob == NULL) + if (!printjob) { irp->IoStatus = STATUS_UNSUCCESSFUL; @@ -115,10 +118,10 @@ static void printer_process_irp_write(PRINTER_DEVICE* printer_dev, IRP* irp) stream_read_UINT64(irp->input, Offset); stream_seek(irp->input, 20); /* Padding */ - if (printer_dev->printer != NULL) + if (printer_dev->printer) printjob = printer_dev->printer->FindPrintJob(printer_dev->printer, irp->FileId); - if (printjob == NULL) + if (!printjob) { irp->IoStatus = STATUS_UNSUCCESSFUL; Length = 0; @@ -162,15 +165,20 @@ static void printer_process_irp(PRINTER_DEVICE* printer_dev, IRP* irp) } } -static void printer_process_irp_list(PRINTER_DEVICE* printer_dev) +static void* printer_thread_func(void* arg) { IRP* irp; + PRINTER_DEVICE* printer_dev = (PRINTER_DEVICE*) arg; while (1) { - if (freerdp_thread_is_stopped(printer_dev->thread)) + WaitForSingleObject(printer_dev->event, INFINITE); + + if (WaitForSingleObject(printer_dev->stopEvent, 0) == WAIT_OBJECT_0) break; + ResetEvent(printer_dev->event); + irp = (IRP*) InterlockedPopEntrySList(printer_dev->pIrpList); if (irp == NULL) @@ -178,24 +186,6 @@ static void printer_process_irp_list(PRINTER_DEVICE* printer_dev) printer_process_irp(printer_dev, irp); } -} - -static void* printer_thread_func(void* arg) -{ - PRINTER_DEVICE* printer_dev = (PRINTER_DEVICE*)arg; - - while (1) - { - freerdp_thread_wait(printer_dev->thread); - - if (freerdp_thread_is_stopped(printer_dev->thread)) - break; - - freerdp_thread_reset(printer_dev->thread); - printer_process_irp_list(printer_dev); - } - - freerdp_thread_quit(printer_dev->thread); return NULL; } @@ -206,7 +196,7 @@ static void printer_irp_request(DEVICE* device, IRP* irp) InterlockedPushEntrySList(printer_dev->pIrpList, &(irp->ItemEntry)); - freerdp_thread_signal(printer_dev->thread); + SetEvent(printer_dev->event); } static void printer_free(DEVICE* device) @@ -214,8 +204,9 @@ static void printer_free(DEVICE* device) IRP* irp; PRINTER_DEVICE* printer_dev = (PRINTER_DEVICE*) device; - freerdp_thread_stop(printer_dev->thread); - freerdp_thread_free(printer_dev->thread); + SetEvent(printer_dev->stopEvent); + WaitForSingleObject(printer_dev->thread, INFINITE); + CloseHandle(printer_dev->thread); while ((irp = (IRP*) InterlockedPopEntrySList(printer_dev->pIrpList)) != NULL) irp->Discard(irp); @@ -292,11 +283,13 @@ void printer_register(PDEVICE_SERVICE_ENTRY_POINTS pEntryPoints, rdpPrinter* pri printer_dev->pIrpList = (PSLIST_HEADER) _aligned_malloc(sizeof(SLIST_HEADER), MEMORY_ALLOCATION_ALIGNMENT); InitializeSListHead(printer_dev->pIrpList); - printer_dev->thread = freerdp_thread_new(); + printer_dev->event = CreateEvent(NULL, TRUE, FALSE, NULL); + printer_dev->stopEvent = CreateEvent(NULL, TRUE, FALSE, NULL); pEntryPoints->RegisterDevice(pEntryPoints->devman, (DEVICE*) printer_dev); - freerdp_thread_start(printer_dev->thread, printer_thread_func, printer_dev); + printer_dev->thread = CreateThread(NULL, 0, + (LPTHREAD_START_ROUTINE) printer_thread_func, (void*) printer_dev, 0, NULL); } #ifdef STATIC_CHANNELS @@ -316,6 +309,7 @@ int DeviceServiceEntry(PDEVICE_SERVICE_ENTRY_POINTS pEntryPoints) #ifdef WITH_CUPS driver = printer_cups_get_driver(); #endif + #ifdef WIN32 driver = printer_win_get_driver(); #endif @@ -334,7 +328,7 @@ int DeviceServiceEntry(PDEVICE_SERVICE_ENTRY_POINTS pEntryPoints) { printer = driver->GetPrinter(driver, name); - if (printer == NULL) + if (!printer) { DEBUG_WARN("printer %s not found.", name); return 1; diff --git a/channels/rail/client/rail_main.c b/channels/rail/client/rail_main.c index b984eff8d..f3477cfac 100644 --- a/channels/rail/client/rail_main.c +++ b/channels/rail/client/rail_main.c @@ -40,7 +40,7 @@ void rail_send_channel_data(void* rail_object, void* data, size_t length) { - STREAM* s = NULL; + wStream* s = NULL; railPlugin* plugin = (railPlugin*) rail_object; s = stream_new(length); @@ -49,25 +49,22 @@ void rail_send_channel_data(void* rail_object, void* data, size_t length) svc_plugin_send((rdpSvcPlugin*) plugin, s); } -static void on_free_rail_channel_event(RDP_EVENT* event) +static void on_free_rail_channel_event(wMessage* event) { - if (event->event_class == RDP_EVENT_CLASS_RAIL) - { - rail_free_cloned_order(event->event_type, event->user_data); - } + rail_free_cloned_order(GetMessageType(event->id), event->wParam); } void rail_send_channel_event(void* rail_object, UINT16 event_type, void* param) { void * payload = NULL; - RDP_EVENT* out_event = NULL; + wMessage* out_event = NULL; railPlugin* plugin = (railPlugin*) rail_object; payload = rail_clone_order(event_type, param); if (payload != NULL) { - out_event = freerdp_event_new(RDP_EVENT_CLASS_RAIL, event_type, + out_event = freerdp_event_new(RailChannel_Class, event_type, on_free_rail_channel_event, payload); svc_plugin_send_event((rdpSvcPlugin*) plugin, out_event); @@ -88,7 +85,7 @@ static void rail_process_terminate(rdpSvcPlugin* plugin) } -static void rail_process_receive(rdpSvcPlugin* plugin, STREAM* s) +static void rail_process_receive(rdpSvcPlugin* plugin, wStream* s) { railPlugin* rail = (railPlugin*) plugin; rail_order_recv(rail->rail_order, s); @@ -114,13 +111,13 @@ static void rail_process_addin_args(rdpRailOrder* rail_order, rdpSettings* setti rail_send_client_exec_order(rail_order); } -static void rail_recv_set_sysparams_event(rdpRailOrder* rail_order, RDP_EVENT* event) +static void rail_recv_set_sysparams_event(rdpRailOrder* rail_order, wMessage* event) { RAIL_SYSPARAM_ORDER* sysparam; /* Send System Parameters */ - sysparam = (RAIL_SYSPARAM_ORDER*) event->user_data; + sysparam = (RAIL_SYSPARAM_ORDER*) event->wParam; memmove(&rail_order->sysparam, sysparam, sizeof(RAIL_SYSPARAM_ORDER)); rail_send_client_sysparams_order(rail_order); @@ -132,7 +129,7 @@ static void rail_recv_set_sysparams_event(rdpRailOrder* rail_order, RDP_EVENT* e rail_process_addin_args(rail_order, rail_order->settings); } -static void rail_recv_exec_remote_app_event(rdpRailOrder* rail_order, RDP_EVENT* event) +static void rail_recv_exec_remote_app_event(rdpRailOrder* rail_order, wMessage* event) { /** * TODO: replace event system by an API to allow the execution @@ -143,102 +140,102 @@ static void rail_recv_exec_remote_app_event(rdpRailOrder* rail_order, RDP_EVENT* //rail_process_addin_args(rail_order, data); } -static void rail_recv_activate_event(rdpRailOrder* rail_order, RDP_EVENT* event) +static void rail_recv_activate_event(rdpRailOrder* rail_order, wMessage* event) { - RAIL_ACTIVATE_ORDER* activate = (RAIL_ACTIVATE_ORDER*) event->user_data; + RAIL_ACTIVATE_ORDER* activate = (RAIL_ACTIVATE_ORDER*) event->wParam; - memcpy(&rail_order->activate, activate, sizeof(RAIL_ACTIVATE_ORDER)); + CopyMemory(&rail_order->activate, activate, sizeof(RAIL_ACTIVATE_ORDER)); rail_send_client_activate_order(rail_order); } -static void rail_recv_sysmenu_event(rdpRailOrder* rail_order, RDP_EVENT* event) +static void rail_recv_sysmenu_event(rdpRailOrder* rail_order, wMessage* event) { - RAIL_SYSMENU_ORDER* sysmenu = (RAIL_SYSMENU_ORDER*) event->user_data; + RAIL_SYSMENU_ORDER* sysmenu = (RAIL_SYSMENU_ORDER*) event->wParam; - memcpy(&rail_order->sysmenu, sysmenu, sizeof(RAIL_SYSMENU_ORDER)); + CopyMemory(&rail_order->sysmenu, sysmenu, sizeof(RAIL_SYSMENU_ORDER)); rail_send_client_sysmenu_order(rail_order); } -static void rail_recv_syscommand_event(rdpRailOrder* rail_order, RDP_EVENT* event) +static void rail_recv_syscommand_event(rdpRailOrder* rail_order, wMessage* event) { - RAIL_SYSCOMMAND_ORDER* syscommand = (RAIL_SYSCOMMAND_ORDER*) event->user_data; + RAIL_SYSCOMMAND_ORDER* syscommand = (RAIL_SYSCOMMAND_ORDER*) event->wParam; - memcpy(&rail_order->syscommand, syscommand, sizeof(RAIL_SYSCOMMAND_ORDER)); + CopyMemory(&rail_order->syscommand, syscommand, sizeof(RAIL_SYSCOMMAND_ORDER)); rail_send_client_syscommand_order(rail_order); } -static void rail_recv_notify_event(rdpRailOrder* rail_order, RDP_EVENT* event) +static void rail_recv_notify_event(rdpRailOrder* rail_order, wMessage* event) { - RAIL_NOTIFY_EVENT_ORDER* notify = (RAIL_NOTIFY_EVENT_ORDER*) event->user_data; + RAIL_NOTIFY_EVENT_ORDER* notify = (RAIL_NOTIFY_EVENT_ORDER*) event->wParam; - memcpy(&rail_order->notify_event, notify, sizeof(RAIL_NOTIFY_EVENT_ORDER)); + CopyMemory(&rail_order->notify_event, notify, sizeof(RAIL_NOTIFY_EVENT_ORDER)); rail_send_client_notify_event_order(rail_order); } -static void rail_recv_window_move_event(rdpRailOrder* rail_order, RDP_EVENT* event) +static void rail_recv_window_move_event(rdpRailOrder* rail_order, wMessage* event) { - RAIL_WINDOW_MOVE_ORDER* window_move = (RAIL_WINDOW_MOVE_ORDER*) event->user_data; + RAIL_WINDOW_MOVE_ORDER* window_move = (RAIL_WINDOW_MOVE_ORDER*) event->wParam; - memcpy(&rail_order->window_move, window_move, sizeof(RAIL_WINDOW_MOVE_ORDER)); + CopyMemory(&rail_order->window_move, window_move, sizeof(RAIL_WINDOW_MOVE_ORDER)); rail_send_client_window_move_order(rail_order); } -static void rail_recv_app_req_event(rdpRailOrder* rail_order, RDP_EVENT* event) +static void rail_recv_app_req_event(rdpRailOrder* rail_order, wMessage* event) { - RAIL_GET_APPID_REQ_ORDER* get_appid_req = (RAIL_GET_APPID_REQ_ORDER*) event->user_data; + RAIL_GET_APPID_REQ_ORDER* get_appid_req = (RAIL_GET_APPID_REQ_ORDER*) event->wParam; - memcpy(&rail_order->get_appid_req, get_appid_req, sizeof(RAIL_GET_APPID_REQ_ORDER)); + CopyMemory(&rail_order->get_appid_req, get_appid_req, sizeof(RAIL_GET_APPID_REQ_ORDER)); rail_send_client_get_appid_req_order(rail_order); } -static void rail_recv_langbarinfo_event(rdpRailOrder* rail_order, RDP_EVENT* event) +static void rail_recv_langbarinfo_event(rdpRailOrder* rail_order, wMessage* event) { - RAIL_LANGBAR_INFO_ORDER* langbar_info = (RAIL_LANGBAR_INFO_ORDER*) event->user_data; + RAIL_LANGBAR_INFO_ORDER* langbar_info = (RAIL_LANGBAR_INFO_ORDER*) event->wParam; - memcpy(&rail_order->langbar_info, langbar_info, sizeof(RAIL_LANGBAR_INFO_ORDER)); + CopyMemory(&rail_order->langbar_info, langbar_info, sizeof(RAIL_LANGBAR_INFO_ORDER)); rail_send_client_langbar_info_order(rail_order); } -static void rail_process_event(rdpSvcPlugin* plugin, RDP_EVENT* event) +static void rail_process_event(rdpSvcPlugin* plugin, wMessage* event) { railPlugin* rail = NULL; rail = (railPlugin*) plugin; - switch (event->event_type) + switch (GetMessageType(event->id)) { - case RDP_EVENT_TYPE_RAIL_CLIENT_SET_SYSPARAMS: + case RailChannel_ClientSystemParam: rail_recv_set_sysparams_event(rail->rail_order, event); break; - case RDP_EVENT_TYPE_RAIL_CLIENT_EXEC_REMOTE_APP: + case RailChannel_ClientExecute: rail_recv_exec_remote_app_event(rail->rail_order, event); break; - case RDP_EVENT_TYPE_RAIL_CLIENT_ACTIVATE: + case RailChannel_ClientActivate: rail_recv_activate_event(rail->rail_order, event); break; - case RDP_EVENT_TYPE_RAIL_CLIENT_SYSMENU: + case RailChannel_ClientSystemMenu: rail_recv_sysmenu_event(rail->rail_order, event); break; - case RDP_EVENT_TYPE_RAIL_CLIENT_SYSCOMMAND: + case RailChannel_ClientSystemCommand: rail_recv_syscommand_event(rail->rail_order, event); break; - case RDP_EVENT_TYPE_RAIL_CLIENT_NOTIFY_EVENT: + case RailChannel_ClientNotifyEvent: rail_recv_notify_event(rail->rail_order, event); break; - case RDP_EVENT_TYPE_RAIL_CLIENT_WINDOW_MOVE: + case RailChannel_ClientWindowMove: rail_recv_window_move_event(rail->rail_order, event); break; - case RDP_EVENT_TYPE_RAIL_CLIENT_APPID_REQ: + case RailChannel_ClientGetAppIdRequest: rail_recv_app_req_event(rail->rail_order, event); break; - case RDP_EVENT_TYPE_RAIL_CLIENT_LANGBARINFO: + case RailChannel_ClientLanguageBarInfo: rail_recv_langbarinfo_event(rail->rail_order, event); break; diff --git a/channels/rail/client/rail_main.h b/channels/rail/client/rail_main.h index 802189934..6e0abb179 100644 --- a/channels/rail/client/rail_main.h +++ b/channels/rail/client/rail_main.h @@ -25,9 +25,10 @@ #include #include #include -#include #include +#include + struct rdp_rail_order { rdpSettings* settings; diff --git a/channels/rail/client/rail_orders.c b/channels/rail/client/rail_orders.c index eef9f13af..2533df326 100644 --- a/channels/rail/client/rail_orders.c +++ b/channels/rail/client/rail_orders.c @@ -88,30 +88,30 @@ void rail_string_to_unicode_string(rdpRailOrder* rail_order, char* string, RAIL_ unicode_string->length = (UINT16) length; } -BOOL rail_read_pdu_header(STREAM* s, UINT16* orderType, UINT16* orderLength) +BOOL rail_read_pdu_header(wStream* s, UINT16* orderType, UINT16* orderLength) { - if(stream_get_left(s) < 4) + if (stream_get_left(s) < 4) return FALSE; stream_read_UINT16(s, *orderType); /* orderType (2 bytes) */ stream_read_UINT16(s, *orderLength); /* orderLength (2 bytes) */ return TRUE; } -void rail_write_pdu_header(STREAM* s, UINT16 orderType, UINT16 orderLength) +void rail_write_pdu_header(wStream* s, UINT16 orderType, UINT16 orderLength) { stream_write_UINT16(s, orderType); /* orderType (2 bytes) */ stream_write_UINT16(s, orderLength); /* orderLength (2 bytes) */ } -STREAM* rail_pdu_init(int length) +wStream* rail_pdu_init(int length) { - STREAM* s; + wStream* s; s = stream_new(length + RAIL_PDU_HEADER_LENGTH); stream_seek(s, RAIL_PDU_HEADER_LENGTH); return s; } -void rail_send_pdu(rdpRailOrder* rail_order, STREAM* s, UINT16 orderType) +void rail_send_pdu(rdpRailOrder* rail_order, wStream* s, UINT16 orderType) { UINT16 orderLength; @@ -125,10 +125,10 @@ void rail_send_pdu(rdpRailOrder* rail_order, STREAM* s, UINT16 orderType) DEBUG_RAIL("Sending %s PDU, length:%d", RAIL_ORDER_TYPE_STRINGS[((orderType & 0xF0) >> 3) + (orderType & 0x0F)], orderLength); - rail_send_channel_data(rail_order->plugin, s->data, orderLength); + rail_send_channel_data(rail_order->plugin, s->buffer, orderLength); } -void rail_write_high_contrast(STREAM* s, HIGH_CONTRAST* high_contrast) +void rail_write_high_contrast(wStream* s, HIGH_CONTRAST* high_contrast) { high_contrast->colorSchemeLength = high_contrast->colorScheme.length + 2; stream_write_UINT32(s, high_contrast->flags); /* flags (4 bytes) */ @@ -136,17 +136,17 @@ void rail_write_high_contrast(STREAM* s, HIGH_CONTRAST* high_contrast) rail_write_unicode_string(s, &high_contrast->colorScheme); /* colorScheme */ } -BOOL rail_read_handshake_order(STREAM* s, RAIL_HANDSHAKE_ORDER* handshake) +BOOL rail_read_handshake_order(wStream* s, RAIL_HANDSHAKE_ORDER* handshake) { - if(stream_get_left(s) < 4) + if (stream_get_left(s) < 4) return FALSE; stream_read_UINT32(s, handshake->buildNumber); /* buildNumber (4 bytes) */ return TRUE; } -BOOL rail_read_server_exec_result_order(STREAM* s, RAIL_EXEC_RESULT_ORDER* exec_result) +BOOL rail_read_server_exec_result_order(wStream* s, RAIL_EXEC_RESULT_ORDER* exec_result) { - if(stream_get_left(s) < 8) + if (stream_get_left(s) < 8) return FALSE; stream_read_UINT16(s, exec_result->flags); /* flags (2 bytes) */ stream_read_UINT16(s, exec_result->execResult); /* execResult (2 bytes) */ @@ -155,11 +155,11 @@ BOOL rail_read_server_exec_result_order(STREAM* s, RAIL_EXEC_RESULT_ORDER* exec_ return rail_read_unicode_string(s, &exec_result->exeOrFile); /* exeOrFile */ } -BOOL rail_read_server_sysparam_order(STREAM* s, RAIL_SYSPARAM_ORDER* sysparam) +BOOL rail_read_server_sysparam_order(wStream* s, RAIL_SYSPARAM_ORDER* sysparam) { BYTE body; - if(stream_get_left(s) < 5) + if (stream_get_left(s) < 5) return FALSE; stream_read_UINT32(s, sysparam->param); /* systemParam (4 bytes) */ stream_read_BYTE(s, body); /* body (1 byte) */ @@ -180,9 +180,9 @@ BOOL rail_read_server_sysparam_order(STREAM* s, RAIL_SYSPARAM_ORDER* sysparam) return TRUE; } -BOOL rail_read_server_minmaxinfo_order(STREAM* s, RAIL_MINMAXINFO_ORDER* minmaxinfo) +BOOL rail_read_server_minmaxinfo_order(wStream* s, RAIL_MINMAXINFO_ORDER* minmaxinfo) { - if(stream_get_left(s) < 20) + if (stream_get_left(s) < 20) return FALSE; stream_read_UINT32(s, minmaxinfo->windowId); /* windowId (4 bytes) */ stream_read_UINT16(s, minmaxinfo->maxWidth); /* maxWidth (2 bytes) */ @@ -196,10 +196,10 @@ BOOL rail_read_server_minmaxinfo_order(STREAM* s, RAIL_MINMAXINFO_ORDER* minmaxi return TRUE; } -BOOL rail_read_server_localmovesize_order(STREAM* s, RAIL_LOCALMOVESIZE_ORDER* localmovesize) +BOOL rail_read_server_localmovesize_order(wStream* s, RAIL_LOCALMOVESIZE_ORDER* localmovesize) { UINT16 isMoveSizeStart; - if(stream_get_left(s) < 12) + if (stream_get_left(s) < 12) return FALSE; stream_read_UINT32(s, localmovesize->windowId); /* windowId (4 bytes) */ @@ -212,9 +212,9 @@ BOOL rail_read_server_localmovesize_order(STREAM* s, RAIL_LOCALMOVESIZE_ORDER* l return TRUE; } -BOOL rail_read_server_get_appid_resp_order(STREAM* s, RAIL_GET_APPID_RESP_ORDER* get_appid_resp) +BOOL rail_read_server_get_appid_resp_order(wStream* s, RAIL_GET_APPID_RESP_ORDER* get_appid_resp) { - if(stream_get_left(s) < 516) + if (stream_get_left(s) < 516) return FALSE; stream_read_UINT32(s, get_appid_resp->windowId); /* windowId (4 bytes) */ stream_read(s, &get_appid_resp->applicationIdBuffer[0], 512); /* applicationId (256 UNICODE chars) */ @@ -224,25 +224,25 @@ BOOL rail_read_server_get_appid_resp_order(STREAM* s, RAIL_GET_APPID_RESP_ORDER* return TRUE; } -BOOL rail_read_langbar_info_order(STREAM* s, RAIL_LANGBAR_INFO_ORDER* langbar_info) +BOOL rail_read_langbar_info_order(wStream* s, RAIL_LANGBAR_INFO_ORDER* langbar_info) { - if(stream_get_left(s) < 4) + if (stream_get_left(s) < 4) return FALSE; stream_read_UINT32(s, langbar_info->languageBarStatus); /* languageBarStatus (4 bytes) */ return TRUE; } -void rail_write_handshake_order(STREAM* s, RAIL_HANDSHAKE_ORDER* handshake) +void rail_write_handshake_order(wStream* s, RAIL_HANDSHAKE_ORDER* handshake) { stream_write_UINT32(s, handshake->buildNumber); /* buildNumber (4 bytes) */ } -void rail_write_client_status_order(STREAM* s, RAIL_CLIENT_STATUS_ORDER* client_status) +void rail_write_client_status_order(wStream* s, RAIL_CLIENT_STATUS_ORDER* client_status) { stream_write_UINT32(s, client_status->flags); /* flags (4 bytes) */ } -void rail_write_client_exec_order(STREAM* s, RAIL_EXEC_ORDER* exec) +void rail_write_client_exec_order(wStream* s, RAIL_EXEC_ORDER* exec) { stream_write_UINT16(s, exec->flags); /* flags (2 bytes) */ stream_write_UINT16(s, exec->exeOrFile.length); /* exeOrFileLength (2 bytes) */ @@ -253,7 +253,7 @@ void rail_write_client_exec_order(STREAM* s, RAIL_EXEC_ORDER* exec) rail_write_unicode_string_value(s, &exec->arguments); /* arguments */ } -void rail_write_client_sysparam_order(STREAM* s, RAIL_SYSPARAM_ORDER* sysparam) +void rail_write_client_sysparam_order(wStream* s, RAIL_SYSPARAM_ORDER* sysparam) { BYTE body; stream_write_UINT32(s, sysparam->param); /* systemParam (4 bytes) */ @@ -307,7 +307,7 @@ void rail_write_client_sysparam_order(STREAM* s, RAIL_SYSPARAM_ORDER* sysparam) } } -void rail_write_client_activate_order(STREAM* s, RAIL_ACTIVATE_ORDER* activate) +void rail_write_client_activate_order(wStream* s, RAIL_ACTIVATE_ORDER* activate) { BYTE enabled; @@ -317,27 +317,27 @@ void rail_write_client_activate_order(STREAM* s, RAIL_ACTIVATE_ORDER* activate) stream_write_BYTE(s, enabled); /* enabled (1 byte) */ } -void rail_write_client_sysmenu_order(STREAM* s, RAIL_SYSMENU_ORDER* sysmenu) +void rail_write_client_sysmenu_order(wStream* s, RAIL_SYSMENU_ORDER* sysmenu) { stream_write_UINT32(s, sysmenu->windowId); /* windowId (4 bytes) */ stream_write_UINT16(s, sysmenu->left); /* left (2 bytes) */ stream_write_UINT16(s, sysmenu->top); /* top (2 bytes) */ } -void rail_write_client_syscommand_order(STREAM* s, RAIL_SYSCOMMAND_ORDER* syscommand) +void rail_write_client_syscommand_order(wStream* s, RAIL_SYSCOMMAND_ORDER* syscommand) { stream_write_UINT32(s, syscommand->windowId); /* windowId (4 bytes) */ stream_write_UINT16(s, syscommand->command); /* command (2 bytes) */ } -void rail_write_client_notify_event_order(STREAM* s, RAIL_NOTIFY_EVENT_ORDER* notify_event) +void rail_write_client_notify_event_order(wStream* s, RAIL_NOTIFY_EVENT_ORDER* notify_event) { stream_write_UINT32(s, notify_event->windowId); /* windowId (4 bytes) */ stream_write_UINT32(s, notify_event->notifyIconId); /* notifyIconId (4 bytes) */ stream_write_UINT32(s, notify_event->message); /* notifyIconId (4 bytes) */ } -void rail_write_client_window_move_order(STREAM* s, RAIL_WINDOW_MOVE_ORDER* window_move) +void rail_write_client_window_move_order(wStream* s, RAIL_WINDOW_MOVE_ORDER* window_move) { stream_write_UINT32(s, window_move->windowId); /* windowId (4 bytes) */ stream_write_UINT16(s, window_move->left); /* left (2 bytes) */ @@ -346,19 +346,19 @@ void rail_write_client_window_move_order(STREAM* s, RAIL_WINDOW_MOVE_ORDER* wind stream_write_UINT16(s, window_move->bottom); /* bottom (2 bytes) */ } -void rail_write_client_get_appid_req_order(STREAM* s, RAIL_GET_APPID_REQ_ORDER* get_appid_req) +void rail_write_client_get_appid_req_order(wStream* s, RAIL_GET_APPID_REQ_ORDER* get_appid_req) { stream_write_UINT32(s, get_appid_req->windowId); /* windowId (4 bytes) */ } -void rail_write_langbar_info_order(STREAM* s, RAIL_LANGBAR_INFO_ORDER* langbar_info) +void rail_write_langbar_info_order(wStream* s, RAIL_LANGBAR_INFO_ORDER* langbar_info) { stream_write_UINT32(s, langbar_info->languageBarStatus); /* languageBarStatus (4 bytes) */ } -BOOL rail_recv_handshake_order(rdpRailOrder* rail_order, STREAM* s) +BOOL rail_recv_handshake_order(rdpRailOrder* rail_order, wStream* s) { - if(!rail_read_handshake_order(s, &rail_order->handshake)) + if (!rail_read_handshake_order(s, &rail_order->handshake)) return FALSE; rail_order->handshake.buildNumber = 0x00001DB0; @@ -395,70 +395,83 @@ BOOL rail_recv_handshake_order(rdpRailOrder* rail_order, STREAM* s) rail_order->sysparam.workArea.bottom = 768; rail_send_channel_event(rail_order->plugin, - RDP_EVENT_TYPE_RAIL_CHANNEL_GET_SYSPARAMS, &rail_order->sysparam); + RailChannel_GetSystemParam, &rail_order->sysparam); + return TRUE; } -BOOL rail_recv_exec_result_order(rdpRailOrder* rail_order, STREAM* s) +BOOL rail_recv_exec_result_order(rdpRailOrder* rail_order, wStream* s) { - if(!rail_read_server_exec_result_order(s, &rail_order->exec_result)) + if (!rail_read_server_exec_result_order(s, &rail_order->exec_result)) return FALSE; + rail_send_channel_event(rail_order->plugin, - RDP_EVENT_TYPE_RAIL_CHANNEL_EXEC_RESULTS, &rail_order->exec_result); + RailChannel_ServerExecuteResult, &rail_order->exec_result); + return TRUE; } -BOOL rail_recv_server_sysparam_order(rdpRailOrder* rail_order, STREAM* s) +BOOL rail_recv_server_sysparam_order(rdpRailOrder* rail_order, wStream* s) { - if(!rail_read_server_sysparam_order(s, &rail_order->sysparam)) + if (!rail_read_server_sysparam_order(s, &rail_order->sysparam)) return FALSE; + rail_send_channel_event(rail_order->plugin, - RDP_EVENT_TYPE_RAIL_CHANNEL_SERVER_SYSPARAM, &rail_order->sysparam); + RailChannel_ServerSystemParam, &rail_order->sysparam); + return TRUE; } -BOOL rail_recv_server_minmaxinfo_order(rdpRailOrder* rail_order, STREAM* s) +BOOL rail_recv_server_minmaxinfo_order(rdpRailOrder* rail_order, wStream* s) { - if(!rail_read_server_minmaxinfo_order(s, &rail_order->minmaxinfo)) + if (!rail_read_server_minmaxinfo_order(s, &rail_order->minmaxinfo)) return FALSE; + rail_send_channel_event(rail_order->plugin, - RDP_EVENT_TYPE_RAIL_CHANNEL_SERVER_MINMAXINFO, &rail_order->minmaxinfo); + RailChannel_ServerMinMaxInfo, &rail_order->minmaxinfo); + return TRUE; } -BOOL rail_recv_server_localmovesize_order(rdpRailOrder* rail_order, STREAM* s) +BOOL rail_recv_server_localmovesize_order(rdpRailOrder* rail_order, wStream* s) { - if(!rail_read_server_localmovesize_order(s, &rail_order->localmovesize)) + if (!rail_read_server_localmovesize_order(s, &rail_order->localmovesize)) return FALSE; + rail_send_channel_event(rail_order->plugin, - RDP_EVENT_TYPE_RAIL_CHANNEL_SERVER_LOCALMOVESIZE, &rail_order->localmovesize); + RailChannel_ServerLocalMoveSize, &rail_order->localmovesize); + return TRUE; } -BOOL rail_recv_server_get_appid_resp_order(rdpRailOrder* rail_order, STREAM* s) +BOOL rail_recv_server_get_appid_resp_order(rdpRailOrder* rail_order, wStream* s) { - if(!rail_read_server_get_appid_resp_order(s, &rail_order->get_appid_resp)) + if (!rail_read_server_get_appid_resp_order(s, &rail_order->get_appid_resp)) return FALSE; + rail_send_channel_event(rail_order->plugin, - RDP_EVENT_TYPE_RAIL_CHANNEL_APPID_RESP, &rail_order->get_appid_resp); + RailChannel_ServerGetAppIdResponse, &rail_order->get_appid_resp); + return TRUE; } -BOOL rail_recv_langbar_info_order(rdpRailOrder* rail_order, STREAM* s) +BOOL rail_recv_langbar_info_order(rdpRailOrder* rail_order, wStream* s) { - if(!rail_read_langbar_info_order(s, &rail_order->langbar_info)) + if (!rail_read_langbar_info_order(s, &rail_order->langbar_info)) return FALSE; + rail_send_channel_event(rail_order->plugin, - RDP_EVENT_TYPE_RAIL_CHANNEL_LANGBARINFO, &rail_order->langbar_info); + RailChannel_ServerLanguageBarInfo, &rail_order->langbar_info); + return TRUE; } -BOOL rail_order_recv(rdpRailOrder* rail_order, STREAM* s) +BOOL rail_order_recv(rdpRailOrder* rail_order, wStream* s) { UINT16 orderType; UINT16 orderLength; - if(!rail_read_pdu_header(s, &orderType, &orderLength)) + if (!rail_read_pdu_header(s, &orderType, &orderLength)) return FALSE; DEBUG_RAIL("Received %s PDU, length:%d", @@ -488,7 +501,7 @@ BOOL rail_order_recv(rdpRailOrder* rail_order, STREAM* s) return rail_recv_langbar_info_order(rail_order, s); default: - printf("Unknown RAIL PDU order reveived."); + fprintf(stderr, "Unknown RAIL PDU order reveived."); break; } return TRUE; @@ -496,7 +509,7 @@ BOOL rail_order_recv(rdpRailOrder* rail_order, STREAM* s) void rail_send_handshake_order(rdpRailOrder* rail_order) { - STREAM* s; + wStream* s; s = rail_pdu_init(RAIL_HANDSHAKE_ORDER_LENGTH); rail_write_handshake_order(s, &rail_order->handshake); rail_send_pdu(rail_order, s, RAIL_ORDER_TYPE_HANDSHAKE); @@ -505,7 +518,7 @@ void rail_send_handshake_order(rdpRailOrder* rail_order) void rail_send_client_status_order(rdpRailOrder* rail_order) { - STREAM* s; + wStream* s; s = rail_pdu_init(RAIL_CLIENT_STATUS_ORDER_LENGTH); rail_write_client_status_order(s, &rail_order->client_status); rail_send_pdu(rail_order, s, RAIL_ORDER_TYPE_CLIENT_STATUS); @@ -514,7 +527,7 @@ void rail_send_client_status_order(rdpRailOrder* rail_order) void rail_send_client_exec_order(rdpRailOrder* rail_order) { - STREAM* s; + wStream* s; int length; length = RAIL_EXEC_ORDER_LENGTH + @@ -530,7 +543,7 @@ void rail_send_client_exec_order(rdpRailOrder* rail_order) void rail_send_client_sysparam_order(rdpRailOrder* rail_order) { - STREAM* s; + wStream* s; int length; length = RAIL_SYSPARAM_ORDER_LENGTH; @@ -608,7 +621,7 @@ void rail_send_client_sysparams_order(rdpRailOrder* rail_order) void rail_send_client_activate_order(rdpRailOrder* rail_order) { - STREAM* s; + wStream* s; s = rail_pdu_init(RAIL_ACTIVATE_ORDER_LENGTH); rail_write_client_activate_order(s, &rail_order->activate); rail_send_pdu(rail_order, s, RAIL_ORDER_TYPE_ACTIVATE); @@ -617,7 +630,7 @@ void rail_send_client_activate_order(rdpRailOrder* rail_order) void rail_send_client_sysmenu_order(rdpRailOrder* rail_order) { - STREAM* s; + wStream* s; s = rail_pdu_init(RAIL_SYSMENU_ORDER_LENGTH); rail_write_client_sysmenu_order(s, &rail_order->sysmenu); rail_send_pdu(rail_order, s, RAIL_ORDER_TYPE_SYSMENU); @@ -626,7 +639,7 @@ void rail_send_client_sysmenu_order(rdpRailOrder* rail_order) void rail_send_client_syscommand_order(rdpRailOrder* rail_order) { - STREAM* s; + wStream* s; s = rail_pdu_init(RAIL_SYSCOMMAND_ORDER_LENGTH); rail_write_client_syscommand_order(s, &rail_order->syscommand); rail_send_pdu(rail_order, s, RAIL_ORDER_TYPE_SYSCOMMAND); @@ -635,7 +648,7 @@ void rail_send_client_syscommand_order(rdpRailOrder* rail_order) void rail_send_client_notify_event_order(rdpRailOrder* rail_order) { - STREAM* s; + wStream* s; s = rail_pdu_init(RAIL_NOTIFY_EVENT_ORDER_LENGTH); rail_write_client_notify_event_order(s, &rail_order->notify_event); rail_send_pdu(rail_order, s, RAIL_ORDER_TYPE_NOTIFY_EVENT); @@ -644,7 +657,7 @@ void rail_send_client_notify_event_order(rdpRailOrder* rail_order) void rail_send_client_window_move_order(rdpRailOrder* rail_order) { - STREAM* s; + wStream* s; s = rail_pdu_init(RAIL_WINDOW_MOVE_ORDER_LENGTH); rail_write_client_window_move_order(s, &rail_order->window_move); rail_send_pdu(rail_order, s, RAIL_ORDER_TYPE_WINDOW_MOVE); @@ -653,7 +666,7 @@ void rail_send_client_window_move_order(rdpRailOrder* rail_order) void rail_send_client_get_appid_req_order(rdpRailOrder* rail_order) { - STREAM* s; + wStream* s; s = rail_pdu_init(RAIL_GET_APPID_REQ_ORDER_LENGTH); rail_write_client_get_appid_req_order(s, &rail_order->get_appid_req); rail_send_pdu(rail_order, s, RAIL_ORDER_TYPE_GET_APPID_REQ); @@ -662,7 +675,7 @@ void rail_send_client_get_appid_req_order(rdpRailOrder* rail_order) void rail_send_client_langbar_info_order(rdpRailOrder* rail_order) { - STREAM* s; + wStream* s; s = rail_pdu_init(RAIL_LANGBAR_INFO_ORDER_LENGTH); rail_write_langbar_info_order(s, &rail_order->langbar_info); rail_send_pdu(rail_order, s, RAIL_ORDER_TYPE_LANGBAR_INFO); diff --git a/channels/rail/client/rail_orders.h b/channels/rail/client/rail_orders.h index 27f2a6e34..9c7f52a3d 100644 --- a/channels/rail/client/rail_orders.h +++ b/channels/rail/client/rail_orders.h @@ -56,27 +56,27 @@ void rail_string_to_unicode_string(rdpRailOrder* rail_order, char* string, RAIL_UNICODE_STRING* unicode_string); -BOOL rail_read_handshake_order(STREAM* s, RAIL_HANDSHAKE_ORDER* handshake); -BOOL rail_read_server_exec_result_order(STREAM* s, RAIL_EXEC_RESULT_ORDER* exec_result); -BOOL rail_read_server_sysparam_order(STREAM* s, RAIL_SYSPARAM_ORDER* sysparam); -BOOL rail_read_server_minmaxinfo_order(STREAM* s, RAIL_MINMAXINFO_ORDER* minmaxinfo); -BOOL rail_read_server_localmovesize_order(STREAM* s, RAIL_LOCALMOVESIZE_ORDER* localmovesize); -BOOL rail_read_server_get_appid_resp_order(STREAM* s, RAIL_GET_APPID_RESP_ORDER* get_appid_resp); -BOOL rail_read_langbar_info_order(STREAM* s, RAIL_LANGBAR_INFO_ORDER* langbar_info); +BOOL rail_read_handshake_order(wStream* s, RAIL_HANDSHAKE_ORDER* handshake); +BOOL rail_read_server_exec_result_order(wStream* s, RAIL_EXEC_RESULT_ORDER* exec_result); +BOOL rail_read_server_sysparam_order(wStream* s, RAIL_SYSPARAM_ORDER* sysparam); +BOOL rail_read_server_minmaxinfo_order(wStream* s, RAIL_MINMAXINFO_ORDER* minmaxinfo); +BOOL rail_read_server_localmovesize_order(wStream* s, RAIL_LOCALMOVESIZE_ORDER* localmovesize); +BOOL rail_read_server_get_appid_resp_order(wStream* s, RAIL_GET_APPID_RESP_ORDER* get_appid_resp); +BOOL rail_read_langbar_info_order(wStream* s, RAIL_LANGBAR_INFO_ORDER* langbar_info); -void rail_write_handshake_order(STREAM* s, RAIL_HANDSHAKE_ORDER* handshake); -void rail_write_client_status_order(STREAM* s, RAIL_CLIENT_STATUS_ORDER* client_status); -void rail_write_client_exec_order(STREAM* s, RAIL_EXEC_ORDER* exec); -void rail_write_client_sysparam_order(STREAM* s, RAIL_SYSPARAM_ORDER* sysparam); -void rail_write_client_activate_order(STREAM* s, RAIL_ACTIVATE_ORDER* activate); -void rail_write_client_sysmenu_order(STREAM* s, RAIL_SYSMENU_ORDER* sysmenu); -void rail_write_client_syscommand_order(STREAM* s, RAIL_SYSCOMMAND_ORDER* syscommand); -void rail_write_client_notify_event_order(STREAM* s, RAIL_NOTIFY_EVENT_ORDER* notify_event); -void rail_write_client_window_move_order(STREAM* s, RAIL_WINDOW_MOVE_ORDER* window_move); -void rail_write_client_get_appid_req_order(STREAM* s, RAIL_GET_APPID_REQ_ORDER* get_appid_req); -void rail_write_langbar_info_order(STREAM* s, RAIL_LANGBAR_INFO_ORDER* langbar_info); +void rail_write_handshake_order(wStream* s, RAIL_HANDSHAKE_ORDER* handshake); +void rail_write_client_status_order(wStream* s, RAIL_CLIENT_STATUS_ORDER* client_status); +void rail_write_client_exec_order(wStream* s, RAIL_EXEC_ORDER* exec); +void rail_write_client_sysparam_order(wStream* s, RAIL_SYSPARAM_ORDER* sysparam); +void rail_write_client_activate_order(wStream* s, RAIL_ACTIVATE_ORDER* activate); +void rail_write_client_sysmenu_order(wStream* s, RAIL_SYSMENU_ORDER* sysmenu); +void rail_write_client_syscommand_order(wStream* s, RAIL_SYSCOMMAND_ORDER* syscommand); +void rail_write_client_notify_event_order(wStream* s, RAIL_NOTIFY_EVENT_ORDER* notify_event); +void rail_write_client_window_move_order(wStream* s, RAIL_WINDOW_MOVE_ORDER* window_move); +void rail_write_client_get_appid_req_order(wStream* s, RAIL_GET_APPID_REQ_ORDER* get_appid_req); +void rail_write_langbar_info_order(wStream* s, RAIL_LANGBAR_INFO_ORDER* langbar_info); -BOOL rail_order_recv(rdpRailOrder* rail_order, STREAM* s); +BOOL rail_order_recv(rdpRailOrder* rail_order, wStream* s); void rail_send_handshake_order(rdpRailOrder* rail_order); void rail_send_client_status_order(rdpRailOrder* rail_order); diff --git a/channels/rdpdr/client/devman.c b/channels/rdpdr/client/devman.c index ff2f6e4d2..fcd36d1a1 100644 --- a/channels/rdpdr/client/devman.c +++ b/channels/rdpdr/client/devman.c @@ -30,7 +30,7 @@ #include #include -#include +#include #include #include #include @@ -99,7 +99,7 @@ BOOL devman_load_device_service(DEVMAN* devman, RDPDR_DEVICE* device) if (!ServiceName) return FALSE; - printf("Loading device service %s (static)\n", ServiceName); + fprintf(stderr, "Loading device service %s (static)\n", ServiceName); entry = (PDEVICE_SERVICE_ENTRY) freerdp_load_channel_addin_entry(ServiceName, NULL, "DeviceServiceEntry", 0); if (entry == NULL) diff --git a/channels/rdpdr/client/irp.c b/channels/rdpdr/client/irp.c index 68ad41655..19e83879e 100644 --- a/channels/rdpdr/client/irp.c +++ b/channels/rdpdr/client/irp.c @@ -28,7 +28,7 @@ #include -#include +#include #include #include "rdpdr_main.h" @@ -62,7 +62,7 @@ static void irp_complete(IRP* irp) irp_free(irp); } -IRP* irp_new(DEVMAN* devman, STREAM* data_in) +IRP* irp_new(DEVMAN* devman, wStream* data_in) { IRP* irp; UINT32 DeviceId; diff --git a/channels/rdpdr/client/irp.h b/channels/rdpdr/client/irp.h index fcdeba109..0d144efe5 100644 --- a/channels/rdpdr/client/irp.h +++ b/channels/rdpdr/client/irp.h @@ -23,6 +23,6 @@ #include "rdpdr_main.h" -IRP* irp_new(DEVMAN* devman, STREAM* data_in); +IRP* irp_new(DEVMAN* devman, wStream* data_in); #endif /* FREERDP_CHANNEL_RDPDR_CLIENT_IRP_H */ diff --git a/channels/rdpdr/client/rdpdr_capabilities.c b/channels/rdpdr/client/rdpdr_capabilities.c index de983d8ea..081f035cd 100644 --- a/channels/rdpdr/client/rdpdr_capabilities.c +++ b/channels/rdpdr/client/rdpdr_capabilities.c @@ -26,14 +26,14 @@ #include #include -#include +#include #include #include "rdpdr_main.h" #include "rdpdr_capabilities.h" /* Output device redirection capability set header */ -static void rdpdr_write_capset_header(STREAM* data_out, UINT16 capabilityType, UINT16 capabilityLength, UINT32 version) +static void rdpdr_write_capset_header(wStream* data_out, UINT16 capabilityType, UINT16 capabilityLength, UINT32 version) { stream_write_UINT16(data_out, capabilityType); stream_write_UINT16(data_out, capabilityLength); @@ -41,7 +41,7 @@ static void rdpdr_write_capset_header(STREAM* data_out, UINT16 capabilityType, U } /* Output device direction general capability set */ -static void rdpdr_write_general_capset(rdpdrPlugin* rdpdr, STREAM* data_out) +static void rdpdr_write_general_capset(rdpdrPlugin* rdpdr, wStream* data_out) { rdpdr_write_capset_header(data_out, CAP_GENERAL_TYPE, 44, GENERAL_CAPABILITY_VERSION_02); @@ -58,7 +58,7 @@ static void rdpdr_write_general_capset(rdpdrPlugin* rdpdr, STREAM* data_out) } /* Process device direction general capability set */ -static void rdpdr_process_general_capset(rdpdrPlugin* rdpdr, STREAM* data_in) +static void rdpdr_process_general_capset(rdpdrPlugin* rdpdr, wStream* data_in) { UINT16 capabilityLength; @@ -67,13 +67,13 @@ static void rdpdr_process_general_capset(rdpdrPlugin* rdpdr, STREAM* data_in) } /* Output printer direction capability set */ -static void rdpdr_write_printer_capset(rdpdrPlugin* rdpdr, STREAM* data_out) +static void rdpdr_write_printer_capset(rdpdrPlugin* rdpdr, wStream* data_out) { rdpdr_write_capset_header(data_out, CAP_PRINTER_TYPE, 8, PRINT_CAPABILITY_VERSION_01); } /* Process printer direction capability set */ -static void rdpdr_process_printer_capset(rdpdrPlugin* rdpdr, STREAM* data_in) +static void rdpdr_process_printer_capset(rdpdrPlugin* rdpdr, wStream* data_in) { UINT16 capabilityLength; @@ -82,13 +82,13 @@ static void rdpdr_process_printer_capset(rdpdrPlugin* rdpdr, STREAM* data_in) } /* Output port redirection capability set */ -static void rdpdr_write_port_capset(rdpdrPlugin* rdpdr, STREAM* data_out) +static void rdpdr_write_port_capset(rdpdrPlugin* rdpdr, wStream* data_out) { rdpdr_write_capset_header(data_out, CAP_PORT_TYPE, 8, PORT_CAPABILITY_VERSION_01); } /* Process port redirection capability set */ -static void rdpdr_process_port_capset(rdpdrPlugin* rdpdr, STREAM* data_in) +static void rdpdr_process_port_capset(rdpdrPlugin* rdpdr, wStream* data_in) { UINT16 capabilityLength; @@ -97,13 +97,13 @@ static void rdpdr_process_port_capset(rdpdrPlugin* rdpdr, STREAM* data_in) } /* Output drive redirection capability set */ -static void rdpdr_write_drive_capset(rdpdrPlugin* rdpdr, STREAM* data_out) +static void rdpdr_write_drive_capset(rdpdrPlugin* rdpdr, wStream* data_out) { rdpdr_write_capset_header(data_out, CAP_DRIVE_TYPE, 8, DRIVE_CAPABILITY_VERSION_02); } /* Process drive redirection capability set */ -static void rdpdr_process_drive_capset(rdpdrPlugin* rdpdr, STREAM* data_in) +static void rdpdr_process_drive_capset(rdpdrPlugin* rdpdr, wStream* data_in) { UINT16 capabilityLength; @@ -112,13 +112,13 @@ static void rdpdr_process_drive_capset(rdpdrPlugin* rdpdr, STREAM* data_in) } /* Output smart card redirection capability set */ -static void rdpdr_write_smartcard_capset(rdpdrPlugin* rdpdr, STREAM* data_out) +static void rdpdr_write_smartcard_capset(rdpdrPlugin* rdpdr, wStream* data_out) { rdpdr_write_capset_header(data_out, CAP_SMARTCARD_TYPE, 8, SMARTCARD_CAPABILITY_VERSION_01); } /* Process smartcard redirection capability set */ -static void rdpdr_process_smartcard_capset(rdpdrPlugin* rdpdr, STREAM* data_in) +static void rdpdr_process_smartcard_capset(rdpdrPlugin* rdpdr, wStream* data_in) { UINT16 capabilityLength; @@ -126,7 +126,7 @@ static void rdpdr_process_smartcard_capset(rdpdrPlugin* rdpdr, STREAM* data_in) stream_seek(data_in, capabilityLength - 4); } -void rdpdr_process_capability_request(rdpdrPlugin* rdpdr, STREAM* data_in) +void rdpdr_process_capability_request(rdpdrPlugin* rdpdr, wStream* data_in) { UINT16 i; UINT16 numCapabilities; @@ -170,7 +170,7 @@ void rdpdr_process_capability_request(rdpdrPlugin* rdpdr, STREAM* data_in) void rdpdr_send_capability_response(rdpdrPlugin* rdpdr) { - STREAM* data_out; + wStream* data_out; data_out = stream_new(256); diff --git a/channels/rdpdr/client/rdpdr_capabilities.h b/channels/rdpdr/client/rdpdr_capabilities.h index 16f0b1db9..b3acd774e 100644 --- a/channels/rdpdr/client/rdpdr_capabilities.h +++ b/channels/rdpdr/client/rdpdr_capabilities.h @@ -23,7 +23,7 @@ #include "rdpdr_main.h" -void rdpdr_process_capability_request(rdpdrPlugin* rdpdr, STREAM* data_in); +void rdpdr_process_capability_request(rdpdrPlugin* rdpdr, wStream* data_in); void rdpdr_send_capability_response(rdpdrPlugin* rdpdr); #endif /* FREERDP_CHANNEL_RDPDR_CLIENT_CAPABILITIES_H */ diff --git a/channels/rdpdr/client/rdpdr_main.c b/channels/rdpdr/client/rdpdr_main.c index 520b52ab3..110701103 100644 --- a/channels/rdpdr/client/rdpdr_main.c +++ b/channels/rdpdr/client/rdpdr_main.c @@ -30,7 +30,7 @@ #include #include -#include +#include #include #include @@ -64,7 +64,7 @@ static void rdpdr_process_connect(rdpSvcPlugin* plugin) } } -static void rdpdr_process_server_announce_request(rdpdrPlugin* rdpdr, STREAM* data_in) +static void rdpdr_process_server_announce_request(rdpdrPlugin* rdpdr, wStream* data_in) { stream_read_UINT16(data_in, rdpdr->versionMajor); stream_read_UINT16(data_in, rdpdr->versionMinor); @@ -75,7 +75,7 @@ static void rdpdr_process_server_announce_request(rdpdrPlugin* rdpdr, STREAM* da static void rdpdr_send_client_announce_reply(rdpdrPlugin* rdpdr) { - STREAM* data_out; + wStream* data_out; data_out = stream_new(12); @@ -91,7 +91,7 @@ static void rdpdr_send_client_announce_reply(rdpdrPlugin* rdpdr) static void rdpdr_send_client_name_request(rdpdrPlugin* rdpdr) { - STREAM* data_out; + wStream* data_out; WCHAR* computerNameW = NULL; size_t computerNameLenW; @@ -116,7 +116,7 @@ static void rdpdr_send_client_name_request(rdpdrPlugin* rdpdr) svc_plugin_send((rdpSvcPlugin*) rdpdr, data_out); } -static void rdpdr_process_server_clientid_confirm(rdpdrPlugin* rdpdr, STREAM* data_in) +static void rdpdr_process_server_clientid_confirm(rdpdrPlugin* rdpdr, wStream* data_in) { UINT16 versionMajor; UINT16 versionMinor; @@ -148,7 +148,7 @@ static void rdpdr_send_device_list_announce_request(rdpdrPlugin* rdpdr, BOOL use UINT32 count; int data_len; int count_pos; - STREAM* data_out; + wStream* data_out; DEVICE* device; LIST_ITEM* item; @@ -199,7 +199,7 @@ static void rdpdr_send_device_list_announce_request(rdpdrPlugin* rdpdr, BOOL use count++; - printf("registered device #%d: %s (type=%d id=%d)\n", + fprintf(stderr, "registered device #%d: %s (type=%d id=%d)\n", count, device->name, device->type, device->id); } } @@ -213,7 +213,7 @@ static void rdpdr_send_device_list_announce_request(rdpdrPlugin* rdpdr, BOOL use svc_plugin_send((rdpSvcPlugin*) rdpdr, data_out); } -static BOOL rdpdr_process_irp(rdpdrPlugin* rdpdr, STREAM* data_in) +static BOOL rdpdr_process_irp(rdpdrPlugin* rdpdr, wStream* data_in) { IRP* irp; @@ -227,7 +227,7 @@ static BOOL rdpdr_process_irp(rdpdrPlugin* rdpdr, STREAM* data_in) return TRUE; } -static void rdpdr_process_receive(rdpSvcPlugin* plugin, STREAM* data_in) +static void rdpdr_process_receive(rdpSvcPlugin* plugin, wStream* data_in) { UINT16 component; UINT16 packetID; @@ -297,7 +297,7 @@ static void rdpdr_process_receive(rdpSvcPlugin* plugin, STREAM* data_in) stream_free(data_in); } -static void rdpdr_process_event(rdpSvcPlugin* plugin, RDP_EVENT* event) +static void rdpdr_process_event(rdpSvcPlugin* plugin, wMessage* event) { freerdp_event_free(event); } diff --git a/channels/rdpei/CMakeLists.txt b/channels/rdpei/CMakeLists.txt new file mode 100644 index 000000000..e5ffe6afc --- /dev/null +++ b/channels/rdpei/CMakeLists.txt @@ -0,0 +1,23 @@ +# FreeRDP: A Remote Desktop Protocol Implementation +# FreeRDP cmake build script +# +# Copyright 2012 Marc-Andre Moreau +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +define_channel("rdpei") + +if(WITH_CLIENT_CHANNELS) + add_channel_client(${MODULE_PREFIX} ${CHANNEL_NAME}) +endif() + diff --git a/channels/rdpei/ChannelOptions.cmake b/channels/rdpei/ChannelOptions.cmake new file mode 100644 index 000000000..d3f874355 --- /dev/null +++ b/channels/rdpei/ChannelOptions.cmake @@ -0,0 +1,13 @@ + +set(OPTION_DEFAULT OFF) +set(OPTION_CLIENT_DEFAULT ON) +set(OPTION_SERVER_DEFAULT OFF) + +define_channel_options(NAME "rdpei" TYPE "dynamic" + DESCRIPTION "Input Virtual Channel Extension" + SPECIFICATIONS "[MS-RDPEI]" + DEFAULT ${OPTION_DEFAULT}) + +define_channel_client_options(${OPTION_CLIENT_DEFAULT}) +define_channel_server_options(${OPTION_SERVER_DEFAULT}) + diff --git a/channels/rdpei/client/CMakeLists.txt b/channels/rdpei/client/CMakeLists.txt new file mode 100644 index 000000000..8ad191ccc --- /dev/null +++ b/channels/rdpei/client/CMakeLists.txt @@ -0,0 +1,42 @@ +# FreeRDP: A Remote Desktop Protocol Implementation +# FreeRDP cmake build script +# +# Copyright 2012 Marc-Andre Moreau +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +define_channel_client("rdpei") + +set(${MODULE_PREFIX}_SRCS + rdpei_main.c + rdpei_main.h) + +include_directories(..) + +add_channel_client_library(${MODULE_PREFIX} ${MODULE_NAME} ${CHANNEL_NAME} TRUE "DVCPluginEntry") + +set_target_properties(${MODULE_NAME} PROPERTIES PREFIX "") + +set_complex_link_libraries(VARIABLE ${MODULE_PREFIX}_LIBS + MONOLITHIC ${MONOLITHIC_BUILD} + MODULE freerdp + MODULES freerdp-common freerdp-utils) + +target_link_libraries(${MODULE_NAME} ${${MODULE_PREFIX}_LIBS}) + +if(NOT STATIC_CHANNELS) + install(TARGETS ${MODULE_NAME} DESTINATION ${FREERDP_PLUGIN_PATH}) +endif() + +set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "Channels/${CHANNEL_NAME}/Client") + diff --git a/channels/rdpei/client/rdpei_main.c b/channels/rdpei/client/rdpei_main.c new file mode 100644 index 000000000..2f866d7ab --- /dev/null +++ b/channels/rdpei/client/rdpei_main.c @@ -0,0 +1,159 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Input Virtual Channel Extension + * + * Copyright 2013 Marc-Andre Moreau + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include + +#include +#include + +#include + +#include + +#include "rdpei_main.h" + +typedef struct _RDPEI_LISTENER_CALLBACK RDPEI_LISTENER_CALLBACK; +struct _RDPEI_LISTENER_CALLBACK +{ + IWTSListenerCallback iface; + + IWTSPlugin* plugin; + IWTSVirtualChannelManager* channel_mgr; +}; + +typedef struct _RDPEI_CHANNEL_CALLBACK RDPEI_CHANNEL_CALLBACK; +struct _RDPEI_CHANNEL_CALLBACK +{ + IWTSVirtualChannelCallback iface; + + IWTSPlugin* plugin; + IWTSVirtualChannelManager* channel_mgr; + IWTSVirtualChannel* channel; +}; + +typedef struct _RDPEI_PLUGIN RDPEI_PLUGIN; +struct _RDPEI_PLUGIN +{ + IWTSPlugin iface; + + RDPEI_LISTENER_CALLBACK* listener_callback; +}; + +static int rdpei_on_data_received(IWTSVirtualChannelCallback* pChannelCallback, UINT32 cbSize, BYTE* pBuffer) +{ + int status = 0; + //RDPEI_CHANNEL_CALLBACK* callback = (RDPEI_CHANNEL_CALLBACK*) pChannelCallback; + + return status; +} + +static int rdpei_on_close(IWTSVirtualChannelCallback* pChannelCallback) +{ + RDPEI_CHANNEL_CALLBACK* callback = (RDPEI_CHANNEL_CALLBACK*) pChannelCallback; + + DEBUG_DVC(""); + + free(callback); + + return 0; +} + +static int rdpei_on_new_channel_connection(IWTSListenerCallback* pListenerCallback, + IWTSVirtualChannel* pChannel, BYTE* Data, int* pbAccept, + IWTSVirtualChannelCallback** ppCallback) +{ + RDPEI_CHANNEL_CALLBACK* callback; + RDPEI_LISTENER_CALLBACK* listener_callback = (RDPEI_LISTENER_CALLBACK*) pListenerCallback; + + DEBUG_DVC(""); + + callback = (RDPEI_CHANNEL_CALLBACK*) malloc(sizeof(RDPEI_CHANNEL_CALLBACK)); + ZeroMemory(callback, sizeof(RDPEI_CHANNEL_CALLBACK)); + + callback->iface.OnDataReceived = rdpei_on_data_received; + callback->iface.OnClose = rdpei_on_close; + callback->plugin = listener_callback->plugin; + callback->channel_mgr = listener_callback->channel_mgr; + callback->channel = pChannel; + + *ppCallback = (IWTSVirtualChannelCallback*) callback; + + return 0; +} + +static int rdpei_plugin_initialize(IWTSPlugin* pPlugin, IWTSVirtualChannelManager* pChannelMgr) +{ + RDPEI_PLUGIN* echo = (RDPEI_PLUGIN*) pPlugin; + + DEBUG_DVC(""); + + echo->listener_callback = (RDPEI_LISTENER_CALLBACK*) malloc(sizeof(RDPEI_LISTENER_CALLBACK)); + ZeroMemory(echo->listener_callback, sizeof(RDPEI_LISTENER_CALLBACK)); + + echo->listener_callback->iface.OnNewChannelConnection = rdpei_on_new_channel_connection; + echo->listener_callback->plugin = pPlugin; + echo->listener_callback->channel_mgr = pChannelMgr; + + return pChannelMgr->CreateListener(pChannelMgr, "Microsoft::Windows::RDS::Input", 0, + (IWTSListenerCallback*) echo->listener_callback, NULL); +} + +static int rdpei_plugin_terminated(IWTSPlugin* pPlugin) +{ + RDPEI_PLUGIN* echo = (RDPEI_PLUGIN*) pPlugin; + + DEBUG_DVC(""); + + free(echo); + + return 0; +} + +#ifdef STATIC_CHANNELS +#define DVCPluginEntry rdpei_DVCPluginEntry +#endif + +int DVCPluginEntry(IDRDYNVC_ENTRY_POINTS* pEntryPoints) +{ + int error = 0; + RDPEI_PLUGIN* rdpei; + + rdpei = (RDPEI_PLUGIN*) pEntryPoints->GetPlugin(pEntryPoints, "rdpei"); + + if (rdpei == NULL) + { + rdpei = (RDPEI_PLUGIN*) malloc(sizeof(RDPEI_PLUGIN)); + ZeroMemory(rdpei, sizeof(RDPEI_PLUGIN)); + + rdpei->iface.Initialize = rdpei_plugin_initialize; + rdpei->iface.Connected = NULL; + rdpei->iface.Disconnected = NULL; + rdpei->iface.Terminated = rdpei_plugin_terminated; + + error = pEntryPoints->RegisterPlugin(pEntryPoints, "rdpei", (IWTSPlugin*) rdpei); + } + + return error; +} diff --git a/channels/rdpei/client/rdpei_main.h b/channels/rdpei/client/rdpei_main.h new file mode 100644 index 000000000..ca233b3a8 --- /dev/null +++ b/channels/rdpei/client/rdpei_main.h @@ -0,0 +1,39 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Input Virtual Channel Extension + * + * Copyright 2013 Marc-Andre Moreau + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CHANNEL_RDPEI_CLIENT_MAIN_H +#define FREERDP_CHANNEL_RDPEI_CLIENT_MAIN_H + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include +#include + +#ifdef WITH_DEBUG_DVC +#define DEBUG_DVC(fmt, ...) DEBUG_CLASS(DVC, fmt, ## __VA_ARGS__) +#else +#define DEBUG_DVC(fmt, ...) DEBUG_NULL(fmt, ## __VA_ARGS__) +#endif + +#endif /* FREERDP_CHANNEL_RDPEI_CLIENT_MAIN_H */ + diff --git a/channels/rdpsnd/client/alsa/rdpsnd_alsa.c b/channels/rdpsnd/client/alsa/rdpsnd_alsa.c index 6784e518a..07a779a02 100644 --- a/channels/rdpsnd/client/alsa/rdpsnd_alsa.c +++ b/channels/rdpsnd/client/alsa/rdpsnd_alsa.c @@ -68,7 +68,7 @@ struct rdpsnd_alsa_plugin #define SND_PCM_CHECK(_func, _status) \ if (_status < 0) \ { \ - printf("%s: %d\n", _func, _status); \ + fprintf(stderr, "%s: %d\n", _func, _status); \ return -1; \ } @@ -106,7 +106,7 @@ int rdpsnd_alsa_set_hw_params(rdpsndAlsaPlugin* alsa) if (alsa->buffer_size > buffer_size_max) { - printf("Warning: requested sound buffer size %d, got %d instead\n", + fprintf(stderr, "Warning: requested sound buffer size %d, got %d instead\n", (int) alsa->buffer_size, (int) buffer_size_max); alsa->buffer_size = buffer_size_max; } @@ -596,7 +596,7 @@ static void rdpsnd_alsa_wave_play(rdpsndDevicePlugin* device, RDPSND_WAVE* wave) } else if (status < 0) { - printf("status: %d\n", status); + fprintf(stderr, "status: %d\n", status); snd_pcm_close(alsa->pcm_handle); alsa->pcm_handle = NULL; rdpsnd_alsa_open((rdpsndDevicePlugin*) alsa, NULL, alsa->latency); @@ -617,7 +617,7 @@ static void rdpsnd_alsa_wave_play(rdpsndDevicePlugin* device, RDPSND_WAVE* wave) wave->wLatency = (UINT16) (wave->wLocalTimeB - wave->wLocalTimeA); wave->wTimeStampB = wave->wTimeStampA + wave->wLatency; - //printf("wTimeStampA: %d wTimeStampB: %d wLatency: %d\n", wave->wTimeStampA, wave->wTimeStampB, wave->wLatency); + //fprintf(stderr, "wTimeStampA: %d wTimeStampB: %d wLatency: %d\n", wave->wTimeStampA, wave->wTimeStampB, wave->wLatency); device->WaveConfirm(device, wave); } diff --git a/channels/rdpsnd/client/mac/rdpsnd_mac.c b/channels/rdpsnd/client/mac/rdpsnd_mac.c index 90a3ace0e..c8e3bed84 100644 --- a/channels/rdpsnd/client/mac/rdpsnd_mac.c +++ b/channels/rdpsnd/client/mac/rdpsnd_mac.c @@ -110,7 +110,7 @@ static void rdpsnd_audio_open(rdpsndDevicePlugin* device, AUDIO_FORMAT* format, &aq_plugin_p->aq_ref ); if (rv != 0) { - printf("rdpsnd_audio_open: AudioQueueNewOutput() failed with error %d\n", rv); + fprintf(stderr, "rdpsnd_audio_open: AudioQueueNewOutput() failed with error %d\n", rv); aq_plugin_p->is_open = 1; return; } @@ -205,7 +205,7 @@ static void aq_playback_cb(void* user_data, AudioQueueRef aq_ref, AudioQueueBuff int freerdp_rdpsnd_client_subsystem_entry(PFREERDP_RDPSND_DEVICE_ENTRY_POINTS pEntryPoints) { - printf("freerdp_rdpsnd_client_subsystem_entry()\n\n"); + fprintf(stderr, "freerdp_rdpsnd_client_subsystem_entry()\n\n"); ADDIN_ARGV* args; rdpsndAudioQPlugin* aqPlugin; diff --git a/channels/rdpsnd/client/rdpsnd_main.c b/channels/rdpsnd/client/rdpsnd_main.c index 2daac35e8..8e54f15e2 100644 --- a/channels/rdpsnd/client/rdpsnd_main.c +++ b/channels/rdpsnd/client/rdpsnd_main.c @@ -41,7 +41,7 @@ #include #include #include -#include +#include #include #include @@ -124,7 +124,7 @@ static void* rdpsnd_schedule_thread(void* arg) void rdpsnd_send_quality_mode_pdu(rdpsndPlugin* rdpsnd) { - STREAM* pdu; + wStream* pdu; pdu = stream_new(8); stream_write_BYTE(pdu, SNDC_QUALITYMODE); /* msgType */ @@ -178,20 +178,20 @@ void rdpsnd_select_supported_audio_formats(rdpsndPlugin* rdpsnd) } #if 0 - printf("Server "); + fprintf(stderr, "Server "); rdpsnd_print_audio_formats(rdpsnd->ServerFormats, rdpsnd->NumberOfServerFormats); - printf("\n"); + fprintf(stderr, "\n"); - printf("Client "); + fprintf(stderr, "Client "); rdpsnd_print_audio_formats(rdpsnd->ClientFormats, rdpsnd->NumberOfClientFormats); - printf("\n"); + fprintf(stderr, "\n"); #endif } void rdpsnd_send_client_audio_formats(rdpsndPlugin* rdpsnd) { int index; - STREAM* pdu; + wStream* pdu; UINT16 length; UINT32 dwVolume; UINT16 dwVolumeLeft; @@ -251,7 +251,7 @@ void rdpsnd_send_client_audio_formats(rdpsndPlugin* rdpsnd) svc_plugin_send((rdpSvcPlugin*) rdpsnd, pdu); } -void rdpsnd_recv_server_audio_formats_pdu(rdpsndPlugin* rdpsnd, STREAM* s) +void rdpsnd_recv_server_audio_formats_pdu(rdpsndPlugin* rdpsnd, wStream* s) { int index; UINT16 wVersion; @@ -300,7 +300,7 @@ void rdpsnd_recv_server_audio_formats_pdu(rdpsndPlugin* rdpsnd, STREAM* s) void rdpsnd_send_training_confirm_pdu(rdpsndPlugin* rdpsnd, UINT16 wTimeStamp, UINT16 wPackSize) { - STREAM* pdu; + wStream* pdu; pdu = stream_new(8); stream_write_BYTE(pdu, SNDC_TRAINING); /* msgType */ @@ -312,7 +312,7 @@ void rdpsnd_send_training_confirm_pdu(rdpsndPlugin* rdpsnd, UINT16 wTimeStamp, U svc_plugin_send((rdpSvcPlugin*) rdpsnd, pdu); } -static void rdpsnd_recv_training_pdu(rdpsndPlugin* rdpsnd, STREAM* s) +static void rdpsnd_recv_training_pdu(rdpsndPlugin* rdpsnd, wStream* s) { UINT16 wTimeStamp; UINT16 wPackSize; @@ -323,7 +323,7 @@ static void rdpsnd_recv_training_pdu(rdpsndPlugin* rdpsnd, STREAM* s) rdpsnd_send_training_confirm_pdu(rdpsnd, wTimeStamp, wPackSize); } -static void rdpsnd_recv_wave_info_pdu(rdpsndPlugin* rdpsnd, STREAM* s, UINT16 BodySize) +static void rdpsnd_recv_wave_info_pdu(rdpsndPlugin* rdpsnd, wStream* s, UINT16 BodySize) { UINT16 wFormatNo; AUDIO_FORMAT* format; @@ -365,7 +365,7 @@ static void rdpsnd_recv_wave_info_pdu(rdpsndPlugin* rdpsnd, STREAM* s, UINT16 Bo void rdpsnd_send_wave_confirm_pdu(rdpsndPlugin* rdpsnd, UINT16 wTimeStamp, BYTE cConfirmedBlockNo) { - STREAM* pdu; + wStream* pdu; pdu = stream_new(8); stream_write_BYTE(pdu, SNDC_WAVECONFIRM); @@ -383,7 +383,7 @@ void rdpsnd_device_send_wave_confirm_pdu(rdpsndDevicePlugin* device, RDPSND_WAVE MessageQueue_Post(device->rdpsnd->queue, NULL, 0, (void*) wave, NULL); } -static void rdpsnd_recv_wave_pdu(rdpsndPlugin* rdpsnd, STREAM* s) +static void rdpsnd_recv_wave_pdu(rdpsndPlugin* rdpsnd, wStream* s) { int size; BYTE* data; @@ -454,7 +454,7 @@ static void rdpsnd_recv_close_pdu(rdpsndPlugin* rdpsnd) rdpsnd->isOpen = FALSE; } -static void rdpsnd_recv_volume_pdu(rdpsndPlugin* rdpsnd, STREAM* s) +static void rdpsnd_recv_volume_pdu(rdpsndPlugin* rdpsnd, wStream* s) { UINT32 dwVolume; @@ -467,7 +467,7 @@ static void rdpsnd_recv_volume_pdu(rdpsndPlugin* rdpsnd, STREAM* s) } } -static void rdpsnd_recv_pdu(rdpSvcPlugin* plugin, STREAM* s) +static void rdpsnd_recv_pdu(rdpSvcPlugin* plugin, wStream* s) { BYTE msgType; UINT16 BodySize; @@ -484,7 +484,7 @@ static void rdpsnd_recv_pdu(rdpSvcPlugin* plugin, STREAM* s) stream_seek_BYTE(s); /* bPad */ stream_read_UINT16(s, BodySize); - //printf("msgType %d BodySize %d\n", msgType, BodySize); + //fprintf(stderr, "msgType %d BodySize %d\n", msgType, BodySize); switch (msgType) { @@ -693,7 +693,7 @@ static void rdpsnd_process_connect(rdpSvcPlugin* plugin) } } -static void rdpsnd_process_event(rdpSvcPlugin* plugin, RDP_EVENT* event) +static void rdpsnd_process_event(rdpSvcPlugin* plugin, wMessage* event) { freerdp_event_free(event); } diff --git a/channels/rdpsnd/server/rdpsnd.c b/channels/rdpsnd/server/rdpsnd.c index b80080554..75e4af02a 100644 --- a/channels/rdpsnd/server/rdpsnd.c +++ b/channels/rdpsnd/server/rdpsnd.c @@ -29,9 +29,9 @@ #include #include #include +#include #include -#include #include #include @@ -42,7 +42,7 @@ typedef struct _rdpsnd_server HANDLE thread; HANDLE StopEvent; void* rdpsnd_channel; - STREAM* rdpsnd_pdu; + wStream* rdpsnd_pdu; FREERDP_DSP_CONTEXT* dsp_context; BYTE* out_buffer; @@ -55,7 +55,7 @@ typedef struct _rdpsnd_server } rdpsnd_server; -static BOOL rdpsnd_server_send_formats(rdpsnd_server* rdpsnd, STREAM* s) +static BOOL rdpsnd_server_send_formats(rdpsnd_server* rdpsnd, wStream* s) { int pos; UINT16 i; @@ -104,7 +104,7 @@ static BOOL rdpsnd_server_send_formats(rdpsnd_server* rdpsnd, STREAM* s) return status; } -static void rdpsnd_server_recv_waveconfirm(rdpsnd_server* rdpsnd, STREAM* s) +static void rdpsnd_server_recv_waveconfirm(rdpsnd_server* rdpsnd, wStream* s) { //unhandled for now @@ -115,7 +115,7 @@ static void rdpsnd_server_recv_waveconfirm(rdpsnd_server* rdpsnd, STREAM* s) stream_seek_BYTE(s); // padding } -static void rdpsnd_server_recv_quality_mode(rdpsnd_server* rdpsnd, STREAM* s) +static void rdpsnd_server_recv_quality_mode(rdpsnd_server* rdpsnd, wStream* s) { //unhandled for now UINT16 quality; @@ -123,10 +123,10 @@ static void rdpsnd_server_recv_quality_mode(rdpsnd_server* rdpsnd, STREAM* s) stream_read_UINT16(s, quality); stream_seek_UINT16(s); // reserved - printf("Client requested sound quality: %#0X\n", quality); + fprintf(stderr, "Client requested sound quality: %#0X\n", quality); } -static BOOL rdpsnd_server_recv_formats(rdpsnd_server* rdpsnd, STREAM* s) +static BOOL rdpsnd_server_recv_formats(rdpsnd_server* rdpsnd, wStream* s) { int i, num_known_format = 0; UINT32 flags, vol, pitch; @@ -174,7 +174,7 @@ static BOOL rdpsnd_server_recv_formats(rdpsnd_server* rdpsnd, STREAM* s) if (num_known_format == 0) { - printf("Client doesnt support any known formats!\n"); + fprintf(stderr, "Client doesnt support any known formats!\n"); return FALSE; } @@ -184,7 +184,7 @@ static BOOL rdpsnd_server_recv_formats(rdpsnd_server* rdpsnd, STREAM* s) static void* rdpsnd_server_thread_func(void* arg) { void* fd; - STREAM* s; + wStream* s; void* buffer; DWORD status; BYTE msgType; @@ -251,7 +251,7 @@ static void* rdpsnd_server_thread_func(void* arg) } break; default: - printf("UNKOWN MESSAGE TYPE!! (%#0X)\n\n", msgType); + fprintf(stderr, "UNKOWN MESSAGE TYPE!! (%#0X)\n\n", msgType); break; } } @@ -293,7 +293,7 @@ static void rdpsnd_server_select_format(rdpsnd_server_context* context, int clie if (client_format_index < 0 || client_format_index >= context->num_client_formats) { - printf("rdpsnd_server_select_format: index %d is not correct.\n", client_format_index); + fprintf(stderr, "rdpsnd_server_select_format: index %d is not correct.\n", client_format_index); return; } @@ -305,7 +305,7 @@ static void rdpsnd_server_select_format(rdpsnd_server_context* context, int clie if (format->nSamplesPerSec == 0) { - printf("Invalid Client Sound Format!!\n\n"); + fprintf(stderr, "Invalid Client Sound Format!!\n\n"); return; } @@ -350,7 +350,7 @@ static BOOL rdpsnd_server_send_audio_pdu(rdpsnd_server* rdpsnd) BOOL status; AUDIO_FORMAT* format; int tbytes_per_frame; - STREAM* s = rdpsnd->rdpsnd_pdu; + wStream* s = rdpsnd->rdpsnd_pdu; format = &rdpsnd->context.client_formats[rdpsnd->context.selected_client_format]; tbytes_per_frame = format->nChannels * rdpsnd->src_bytes_per_sample; @@ -463,7 +463,7 @@ static BOOL rdpsnd_server_set_volume(rdpsnd_server_context* context, int left, i int pos; BOOL status; rdpsnd_server* rdpsnd = (rdpsnd_server*) context; - STREAM* s = rdpsnd->rdpsnd_pdu; + wStream* s = rdpsnd->rdpsnd_pdu; stream_write_BYTE(s, SNDC_SETVOLUME); stream_write_BYTE(s, 0); @@ -487,7 +487,7 @@ static BOOL rdpsnd_server_close(rdpsnd_server_context* context) int pos; BOOL status; rdpsnd_server* rdpsnd = (rdpsnd_server*) context; - STREAM* s = rdpsnd->rdpsnd_pdu; + wStream* s = rdpsnd->rdpsnd_pdu; if (rdpsnd->context.selected_client_format < 0) return FALSE; diff --git a/channels/sample/client/sample_main.c b/channels/sample/client/sample_main.c index 0c8d3571d..b36a07f8b 100644 --- a/channels/sample/client/sample_main.c +++ b/channels/sample/client/sample_main.c @@ -34,7 +34,7 @@ #include #include -#include +#include #include #include @@ -47,17 +47,17 @@ struct sample_plugin /* put your private data here */ }; -static void sample_process_receive(rdpSvcPlugin* plugin, STREAM* data_in) +static void sample_process_receive(rdpSvcPlugin* plugin, wStream* data_in) { int bytes; - STREAM* data_out; + wStream* data_out; samplePlugin* sample = (samplePlugin*) plugin; - printf("sample_process_receive:\n"); + fprintf(stderr, "sample_process_receive:\n"); if (!sample) { - printf("sample_process_receive: sample is nil\n"); + fprintf(stderr, "sample_process_receive: sample is nil\n"); return; } @@ -65,7 +65,7 @@ static void sample_process_receive(rdpSvcPlugin* plugin, STREAM* data_in) /* here we just send the same data back */ bytes = stream_get_size(data_in); - printf("sample_process_receive: got bytes %d\n", bytes); + fprintf(stderr, "sample_process_receive: got bytes %d\n", bytes); if (bytes > 0) { @@ -75,7 +75,7 @@ static void sample_process_receive(rdpSvcPlugin* plugin, STREAM* data_in) we do not free it */ bytes = stream_get_length(data_in); - printf("sample_process_receive: sending bytes %d\n", bytes); + fprintf(stderr, "sample_process_receive: sending bytes %d\n", bytes); svc_plugin_send(plugin, data_out); } @@ -88,15 +88,15 @@ static void sample_process_connect(rdpSvcPlugin* plugin) samplePlugin* sample = (samplePlugin*) plugin; DEBUG_SVC("connecting"); - printf("sample_process_connect:\n"); + fprintf(stderr, "sample_process_connect:\n"); if (!sample) return; } -static void sample_process_event(rdpSvcPlugin* plugin, RDP_EVENT* event) +static void sample_process_event(rdpSvcPlugin* plugin, wMessage* event) { - printf("sample_process_event:\n"); + fprintf(stderr, "sample_process_event:\n"); /* events coming from main freerdp window to plugin */ /* send them back with svc_plugin_send_event */ @@ -108,7 +108,7 @@ static void sample_process_terminate(rdpSvcPlugin* plugin) { samplePlugin* sample = (samplePlugin*) plugin; - printf("sample_process_terminate:\n"); + fprintf(stderr, "sample_process_terminate:\n"); if (!sample) return; diff --git a/channels/sample/client/server_chan_test.cpp b/channels/sample/client/server_chan_test.cpp index 8de5f3fde..577d7b1d1 100644 --- a/channels/sample/client/server_chan_test.cpp +++ b/channels/sample/client/server_chan_test.cpp @@ -26,7 +26,7 @@ int main() if (!ret) { long err = GetLastError(); - printf("error 0x%8.8x\n", err); + fprintf(stderr, "error 0x%8.8x\n", err); return 1; } @@ -34,12 +34,12 @@ int main() if (!ret) { long err = GetLastError(); - printf("error 0x%8.8x\n", err); + fprintf(stderr, "error 0x%8.8x\n", err); return 1; } if (written != DSIZE) { - printf("error read %d\n", written); + fprintf(stderr, "error read %d\n", written); return 1; } @@ -49,11 +49,11 @@ int main() } else { - printf("error data no match\n"); + fprintf(stderr, "error data no match\n"); return 1; } - printf("Success!\n"); + fprintf(stderr, "Success!\n"); Sleep(2000); return 0; diff --git a/channels/serial/client/serial_main.c b/channels/serial/client/serial_main.c index bbcdbeba7..f505c2c00 100644 --- a/channels/serial/client/serial_main.c +++ b/channels/serial/client/serial_main.c @@ -44,10 +44,13 @@ #include "serial_constants.h" #include +#include +#include +#include #include -#include -#include +#include +#include #include typedef struct _SERIAL_DEVICE SERIAL_DEVICE; @@ -59,9 +62,11 @@ struct _SERIAL_DEVICE char* path; SERIAL_TTY* tty; - LIST* irp_list; + HANDLE thread; + HANDLE stopEvent; + + wQueue* queue; LIST* pending_irps; - freerdp_thread* thread; HANDLE in_event; fd_set read_fds; @@ -253,7 +258,7 @@ static void serial_process_irp_device_control(SERIAL_DEVICE* serial, IRP* irp) tty = serial->tty; - if (tty == NULL) + if (!tty) { irp->IoStatus = STATUS_UNSUCCESSFUL; OutputBufferLength = 0; @@ -314,34 +319,18 @@ static void serial_process_irp(SERIAL_DEVICE* serial, IRP* irp) serial_check_for_events(serial); } -static void serial_process_irp_list(SERIAL_DEVICE* serial) -{ - IRP* irp; - - while (1) - { - if (freerdp_thread_is_stopped(serial->thread)) - break; - - freerdp_thread_lock(serial->thread); - irp = (IRP*) list_dequeue(serial->irp_list); - freerdp_thread_unlock(serial->thread); - - if (irp == NULL) - break; - - serial_process_irp(serial, irp); - } -} - static void* serial_thread_func(void* arg) { + IRP* irp; DWORD status; SERIAL_DEVICE* serial = (SERIAL_DEVICE*)arg; while (1) { - if (freerdp_thread_wait_timeout(serial->thread, 500) < 0) + if (WaitForSingleObject(serial->stopEvent, 0) == WAIT_OBJECT_0) + break; + + if (WaitForSingleObject(Queue_Event(serial->queue), 10) == WAIT_OBJECT_0) break; serial->nfds = 1; @@ -352,23 +341,20 @@ static void* serial_thread_func(void* arg) serial->tv.tv_usec = 0; serial->select_timeout = 0; - if (freerdp_thread_is_stopped(serial->thread)) - break; + irp = (IRP*) Queue_Dequeue(serial->queue); - freerdp_thread_reset(serial->thread); - serial_process_irp_list(serial); + if (irp) + serial_process_irp(serial, irp); status = WaitForSingleObject(serial->in_event, 0); if ((status == WAIT_OBJECT_0) || (status == WAIT_TIMEOUT)) { - if (serial_check_fds(serial)) - ResetEvent(serial->in_event); + if (serial_check_fds(serial)) + ResetEvent(serial->in_event); } } - freerdp_thread_quit(serial->thread); - return NULL; } @@ -376,40 +362,26 @@ static void serial_irp_request(DEVICE* device, IRP* irp) { SERIAL_DEVICE* serial = (SERIAL_DEVICE*) device; - freerdp_thread_lock(serial->thread); - list_enqueue(serial->irp_list, irp); - freerdp_thread_unlock(serial->thread); - - freerdp_thread_signal(serial->thread); + Queue_Enqueue(serial->queue, irp); } static void serial_free(DEVICE* device) { - IRP* irp; SERIAL_DEVICE* serial = (SERIAL_DEVICE*) device; DEBUG_SVC("freeing device"); - freerdp_thread_stop(serial->thread); - freerdp_thread_free(serial->thread); + SetEvent(serial->stopEvent); - while ((irp = (IRP*) list_dequeue(serial->irp_list)) != NULL) - irp->Discard(irp); - - list_free(serial->irp_list); - - while ((irp = (IRP*) list_dequeue(serial->pending_irps)) != NULL) - irp->Discard(irp); - - list_free(serial->pending_irps); + /* TODO: free lists */ free(serial); } static void serial_abort_single_io(SERIAL_DEVICE* serial, UINT32 file_id, UINT32 abort_io, UINT32 io_status) { - IRP* irp = NULL; UINT32 major; + IRP* irp = NULL; SERIAL_TTY* tty; DEBUG_SVC("[in] pending size %d", list_size(serial->pending_irps)); @@ -626,7 +598,7 @@ static void __serial_check_fds(SERIAL_DEVICE* serial) prev = irp; irp = (IRP*) list_next(serial->pending_irps, irp); - if (irp_completed || prev->IoStatus == STATUS_SUCCESS) + if (irp_completed || (prev->IoStatus == STATUS_SUCCESS)) { list_remove(serial->pending_irps, prev); SetEvent(serial->in_event); @@ -737,14 +709,15 @@ int DeviceServiceEntry(PDEVICE_SERVICE_ENTRY_POINTS pEntryPoints) stream_write_BYTE(serial->device.data, name[i] < 0 ? '_' : name[i]); serial->path = path; - serial->irp_list = list_new(); + serial->queue = Queue_New(TRUE, -1, -1); serial->pending_irps = list_new(); - serial->thread = freerdp_thread_new(); serial->in_event = CreateEvent(NULL, TRUE, FALSE, NULL); + serial->stopEvent = CreateEvent(NULL, TRUE, FALSE, NULL); + pEntryPoints->RegisterDevice(pEntryPoints->devman, (DEVICE*) serial); - freerdp_thread_start(serial->thread, serial_thread_func, serial); + serial->thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) serial_thread_func, (void*) serial, 0, NULL); } return 0; diff --git a/channels/serial/client/serial_tty.c b/channels/serial/client/serial_tty.c index 0ba907b09..74b2d09ef 100644 --- a/channels/serial/client/serial_tty.c +++ b/channels/serial/client/serial_tty.c @@ -29,9 +29,8 @@ #include #include -#include +#include #include -#include #include #include @@ -79,7 +78,7 @@ static void tty_set_termios(SERIAL_TTY* tty); static BOOL tty_get_termios(SERIAL_TTY* tty); static int tty_get_error_status(); -UINT32 serial_tty_control(SERIAL_TTY* tty, UINT32 IoControlCode, STREAM* input, STREAM* output, UINT32* abort_io) +UINT32 serial_tty_control(SERIAL_TTY* tty, UINT32 IoControlCode, wStream* input, wStream* output, UINT32* abort_io) { int purge_mask; UINT32 result; @@ -372,9 +371,9 @@ UINT32 serial_tty_control(SERIAL_TTY* tty, UINT32 IoControlCode, STREAM* input, BOOL serial_tty_read(SERIAL_TTY* tty, BYTE* buffer, UINT32* Length) { - ssize_t r; + ssize_t status; long timeout = 90; - struct termios *ptermios; + struct termios* ptermios; DEBUG_SVC("in"); ptermios = tty->ptermios; @@ -410,13 +409,13 @@ BOOL serial_tty_read(SERIAL_TTY* tty, BYTE* buffer, UINT32* Length) ZeroMemory(buffer, *Length); - r = read(tty->fd, buffer, *Length); + status = read(tty->fd, buffer, *Length); - if (r < 0) + if (status < 0) return FALSE; - tty->event_txempty = r; - *Length = r; + tty->event_txempty = status; + *Length = status; return TRUE; } @@ -550,7 +549,7 @@ SERIAL_TTY* serial_tty_new(const char* path, UINT32 id) BOOL serial_tty_get_event(SERIAL_TTY* tty, UINT32* result) { int bytes; - BOOL ret = FALSE; + BOOL status = FALSE; DEBUG_SVC("in"); @@ -579,7 +578,7 @@ BOOL serial_tty_get_event(SERIAL_TTY* tty, UINT32* result) { DEBUG_SVC("SERIAL_EV_RLSD"); *result |= SERIAL_EV_RLSD; - ret = TRUE; + status = TRUE; } } @@ -588,14 +587,14 @@ BOOL serial_tty_get_event(SERIAL_TTY* tty, UINT32* result) { DEBUG_SVC("SERIAL_EV_RXFLAG bytes %d", bytes); *result |= SERIAL_EV_RXFLAG; - ret = TRUE; + status = TRUE; } if ((tty->wait_mask & SERIAL_EV_RXCHAR)) { DEBUG_SVC("SERIAL_EV_RXCHAR bytes %d", bytes); *result |= SERIAL_EV_RXCHAR; - ret = TRUE; + status = TRUE; } } @@ -611,7 +610,7 @@ BOOL serial_tty_get_event(SERIAL_TTY* tty, UINT32* result) { DEBUG_SVC("SERIAL_EV_TXEMPTY"); *result |= SERIAL_EV_TXEMPTY; - ret = TRUE; + status = TRUE; } tty->event_txempty = bytes; #endif @@ -624,7 +623,7 @@ BOOL serial_tty_get_event(SERIAL_TTY* tty, UINT32* result) { DEBUG_SVC("SERIAL_EV_DSR %s", (bytes & TIOCM_DSR) ? "ON" : "OFF"); *result |= SERIAL_EV_DSR; - ret = TRUE; + status = TRUE; } } @@ -635,14 +634,14 @@ BOOL serial_tty_get_event(SERIAL_TTY* tty, UINT32* result) { DEBUG_SVC("SERIAL_EV_CTS %s", (bytes & TIOCM_CTS) ? "ON" : "OFF"); *result |= SERIAL_EV_CTS; - ret = TRUE; + status = TRUE; } } - if (ret) + if (status) tty->event_pending = 0; - return ret; + return status; } static BOOL tty_get_termios(SERIAL_TTY* tty) diff --git a/channels/serial/client/serial_tty.h b/channels/serial/client/serial_tty.h index bace6e709..f75a3988d 100644 --- a/channels/serial/client/serial_tty.h +++ b/channels/serial/client/serial_tty.h @@ -29,7 +29,8 @@ #endif #include -#include + +#include typedef struct _SERIAL_TTY SERIAL_TTY; @@ -71,7 +72,7 @@ void serial_tty_free(SERIAL_TTY* tty); BOOL serial_tty_read(SERIAL_TTY* tty, BYTE* buffer, UINT32* Length); BOOL serial_tty_write(SERIAL_TTY* tty, BYTE* buffer, UINT32 Length); -UINT32 serial_tty_control(SERIAL_TTY* tty, UINT32 IoControlCode, STREAM* input, STREAM* output, UINT32* abort_io); +UINT32 serial_tty_control(SERIAL_TTY* tty, UINT32 IoControlCode, wStream* input, wStream* output, UINT32* abort_io); BOOL serial_tty_get_event(SERIAL_TTY* tty, UINT32* result); diff --git a/channels/server/channels.c b/channels/server/channels.c index 231826866..d7fc26c13 100644 --- a/channels/server/channels.c +++ b/channels/server/channels.c @@ -128,7 +128,7 @@ static void wts_queue_send_item(rdpPeerChannel* channel, wts_data_item* item) SetEvent(vcm->send_event); } -static int wts_read_variable_uint(STREAM* s, int cbLen, UINT32* val) +static int wts_read_variable_uint(wStream* s, int cbLen, UINT32* val) { switch (cbLen) { @@ -167,7 +167,7 @@ static void wts_read_drdynvc_capabilities_response(rdpPeerChannel* channel, UINT channel->vcm->drdynvc_state = DRDYNVC_STATE_READY; } -static void wts_read_drdynvc_create_response(rdpPeerChannel* channel, STREAM* s, UINT32 length) +static void wts_read_drdynvc_create_response(rdpPeerChannel* channel, wStream* s, UINT32 length) { UINT32 CreationStatus; @@ -190,7 +190,7 @@ static void wts_read_drdynvc_create_response(rdpPeerChannel* channel, STREAM* s, SetEvent(channel->receive_event); } -static void wts_read_drdynvc_data_first(rdpPeerChannel* channel, STREAM* s, int cbLen, UINT32 length) +static void wts_read_drdynvc_data_first(rdpPeerChannel* channel, wStream* s, int cbLen, UINT32 length) { int value; @@ -209,14 +209,14 @@ static void wts_read_drdynvc_data_first(rdpPeerChannel* channel, STREAM* s, int stream_write(channel->receive_data, stream_get_tail(s), length); } -static void wts_read_drdynvc_data(rdpPeerChannel* channel, STREAM* s, UINT32 length) +static void wts_read_drdynvc_data(rdpPeerChannel* channel, wStream* s, UINT32 length) { if (channel->dvc_total_length > 0) { if (stream_get_length(channel->receive_data) + length > channel->dvc_total_length) { channel->dvc_total_length = 0; - printf("wts_read_drdynvc_data: incorrect fragment data, discarded.\n"); + fprintf(stderr, "wts_read_drdynvc_data: incorrect fragment data, discarded.\n"); return; } @@ -300,7 +300,7 @@ static void wts_read_drdynvc_pdu(rdpPeerChannel* channel) break; default: - printf("wts_read_drdynvc_pdu: Cmd %d not recognized.\n", Cmd); + fprintf(stderr, "wts_read_drdynvc_pdu: Cmd %d not recognized.\n", Cmd); break; } } @@ -311,11 +311,11 @@ static void wts_read_drdynvc_pdu(rdpPeerChannel* channel) } else { - printf("wts_read_drdynvc_pdu: received Cmd %d but channel is not ready.\n", Cmd); + fprintf(stderr, "wts_read_drdynvc_pdu: received Cmd %d but channel is not ready.\n", Cmd); } } -static int wts_write_variable_uint(STREAM* stream, UINT32 val) +static int wts_write_variable_uint(wStream* stream, UINT32 val) { int cb; @@ -338,7 +338,7 @@ static int wts_write_variable_uint(STREAM* stream, UINT32 val) return cb; } -static void wts_write_drdynvc_header(STREAM *s, BYTE Cmd, UINT32 ChannelId) +static void wts_write_drdynvc_header(wStream *s, BYTE Cmd, UINT32 ChannelId) { BYTE* bm; int cbChId; @@ -349,7 +349,7 @@ static void wts_write_drdynvc_header(STREAM *s, BYTE Cmd, UINT32 ChannelId) *bm = ((Cmd & 0x0F) << 4) | cbChId; } -static void wts_write_drdynvc_create_request(STREAM *s, UINT32 ChannelId, const char *ChannelName) +static void wts_write_drdynvc_create_request(wStream *s, UINT32 ChannelId, const char *ChannelName) { UINT32 len; @@ -373,7 +373,7 @@ static void WTSProcessChannelData(rdpPeerChannel* channel, int channelId, BYTE* { if (stream_get_length(channel->receive_data) != total_size) { - printf("WTSProcessChannelData: read error\n"); + fprintf(stderr, "WTSProcessChannelData: read error\n"); } if (channel == channel->vcm->drdynvc_channel) { @@ -545,7 +545,7 @@ void* WTSVirtualChannelOpenEx( { int i; int len; - STREAM* s; + wStream* s; rdpPeerChannel* channel; freerdp_peer* client = vcm->client; @@ -745,7 +745,7 @@ BOOL WTSVirtualChannelWrite( { rdpPeerChannel* channel = (rdpPeerChannel*) hChannelHandle; wts_data_item* item; - STREAM* s; + wStream* s; int cbLen; int cbChId; int first; @@ -822,7 +822,7 @@ BOOL WTSVirtualChannelWrite( BOOL WTSVirtualChannelClose( /* __in */ void* hChannelHandle) { - STREAM* s; + wStream* s; wts_data_item* item; WTSVirtualChannelManager* vcm; rdpPeerChannel* channel = (rdpPeerChannel*) hChannelHandle; diff --git a/channels/server/channels.h b/channels/server/channels.h index e0960c205..d6fa95278 100644 --- a/channels/server/channels.h +++ b/channels/server/channels.h @@ -22,12 +22,12 @@ #define __WTSVC_H #include -#include #include #include #include #include +#include #ifdef WITH_DEBUG_DVC #define DEBUG_DVC(fmt, ...) DEBUG_CLASS(DVC, fmt, ## __VA_ARGS__) @@ -66,7 +66,7 @@ struct rdp_peer_channel UINT16 channel_type; UINT16 index; - STREAM* receive_data; + wStream* receive_data; HANDLE receive_event; LIST* receive_queue; HANDLE mutex; diff --git a/channels/smartcard/client/smartcard_main.c b/channels/smartcard/client/smartcard_main.c index 339cb8fcc..d241e4a0e 100644 --- a/channels/smartcard/client/smartcard_main.c +++ b/channels/smartcard/client/smartcard_main.c @@ -73,7 +73,7 @@ static void smartcard_process_irp(SMARTCARD_DEVICE* smartcard, IRP* irp) break; default: - printf("MajorFunction 0x%X unexpected for smartcards.", irp->MajorFunction); + fprintf(stderr, "MajorFunction 0x%X unexpected for smartcards.", irp->MajorFunction); DEBUG_WARN("Smartcard MajorFunction 0x%X not supported.", irp->MajorFunction); irp->IoStatus = STATUS_NOT_SUPPORTED; irp->Complete(irp); diff --git a/channels/smartcard/client/smartcard_operations.c b/channels/smartcard/client/smartcard_operations.c index 817c49139..2c4b595b9 100644 --- a/channels/smartcard/client/smartcard_operations.c +++ b/channels/smartcard/client/smartcard_operations.c @@ -38,13 +38,12 @@ #undef BOOL #include +#include +#include #include -#include -#include -#include -#include #include +#include #include "smartcard_main.h" @@ -750,10 +749,10 @@ static UINT32 handle_State(IRP* irp) (unsigned) hCard, (int) atrLen, (unsigned) state, (unsigned) protocol); #ifdef WITH_DEBUG_SCARD - printf(" ATR: "); + fprintf(stderr, " ATR: "); for (i = 0; i < atrLen; i++) - printf("%02x%c", pbAtr[i], (i == atrLen - 1) ? ' ' : ':'); - printf("\n"); + fprintf(stderr, "%02x%c", pbAtr[i], (i == atrLen - 1) ? ' ' : ':'); + fprintf(stderr, "\n"); #endif state = smartcard_map_state(state); @@ -823,10 +822,10 @@ static DWORD handle_Status(IRP *irp, BOOL wide) DEBUG_SCARD(" Reader: \"%s\"", readerName ? readerName : "NULL"); #ifdef WITH_DEBUG_SCARD - printf(" ATR: "); + fprintf(stderr, " ATR: "); for (i = 0; i < atrLen; i++) - printf("%02x%c", pbAtr[i], (i == atrLen - 1) ? ' ' : ':'); - printf("\n"); + fprintf(stderr, "%02x%c", pbAtr[i], (i == atrLen - 1) ? ' ' : ':'); + fprintf(stderr, "\n"); #endif state = smartcard_map_state(state); @@ -1181,7 +1180,7 @@ static UINT32 handle_AccessStartedEvent(IRP* irp) void scard_error(SMARTCARD_DEVICE* scard, IRP* irp, UINT32 ntstatus) { /* [MS-RDPESC] 3.1.4.4 */ - printf("scard processing error %x\n", ntstatus); + fprintf(stderr, "scard processing error %x\n", ntstatus); stream_set_pos(irp->output, 0); /* CHECKME */ irp->IoStatus = ntstatus; @@ -1516,7 +1515,7 @@ void smartcard_device_control(SMARTCARD_DEVICE* scard, IRP* irp) default: result = 0xc0000001; - printf("scard unknown ioctl 0x%x\n", ioctl_code); + fprintf(stderr, "scard unknown ioctl 0x%x\n", ioctl_code); break; } diff --git a/channels/tsmf/client/CMakeLists.txt b/channels/tsmf/client/CMakeLists.txt index e4560ab5c..6624ec24a 100644 --- a/channels/tsmf/client/CMakeLists.txt +++ b/channels/tsmf/client/CMakeLists.txt @@ -57,9 +57,15 @@ if(WITH_FFMPEG) add_channel_client_subsystem(${MODULE_PREFIX} ${CHANNEL_NAME} "ffmpeg" "decoder") endif() -if(WITH_XRANDR) - if(GSTREAMER_FOUND) +if(WITH_GSTREAMER) + set(XRANDR_FEATURE_TYPE "REQUIRED") + set(XRANDR_FEATURE_PURPOSE "X11 randr") + set(XRANDR_FEATURE_DESCRIPTION "X11 randr extension") + find_feature(XRandR ${XRANDR_FEATURE_TYPE} ${XRANDR_FEATURE_PURPOSE} ${XRANDR_FEATURE_DESCRIPTION}) + if (WITH_XRANDR) add_channel_client_subsystem(${MODULE_PREFIX} ${CHANNEL_NAME} "gstreamer" "decoder") + else() + message(WARNING "Disabling tsmf gstreamer because XRandR wasn't found") endif() endif() diff --git a/channels/tsmf/client/ffmpeg/tsmf_ffmpeg.c b/channels/tsmf/client/ffmpeg/tsmf_ffmpeg.c index 6effab9da..adf8e04f1 100644 --- a/channels/tsmf/client/ffmpeg/tsmf_ffmpeg.c +++ b/channels/tsmf/client/ffmpeg/tsmf_ffmpeg.c @@ -29,8 +29,11 @@ #include #include + #include +#include + #include "tsmf_constants.h" #include "tsmf_decoder.h" @@ -533,7 +536,7 @@ ITSMFDecoder* freerdp_tsmf_client_decoder_subsystem_entry(void) initialized = TRUE; } - printf("TSMFDecoderEntry FFMPEG\n"); + fprintf(stderr, "TSMFDecoderEntry FFMPEG\n"); decoder = (TSMFFFmpegDecoder*) malloc(sizeof(TSMFFFmpegDecoder)); ZeroMemory(decoder, sizeof(TSMFFFmpegDecoder)); diff --git a/channels/tsmf/client/tsmf_codec.c b/channels/tsmf/client/tsmf_codec.c index 0dc2414ac..9cf19e92a 100644 --- a/channels/tsmf/client/tsmf_codec.c +++ b/channels/tsmf/client/tsmf_codec.c @@ -26,7 +26,7 @@ #include #include -#include +#include #include #include "tsmf_constants.h" @@ -265,26 +265,26 @@ static void tsmf_print_guid(const BYTE* guid) int i; for (i = 3; i >= 0; i--) - printf("%02X", guid[i]); - printf("-"); + fprintf(stderr, "%02X", guid[i]); + fprintf(stderr, "-"); for (i = 5; i >= 4; i--) - printf("%02X", guid[i]); - printf("-"); + fprintf(stderr, "%02X", guid[i]); + fprintf(stderr, "-"); for (i = 7; i >= 6; i--) - printf("%02X", guid[i]); - printf("-"); + fprintf(stderr, "%02X", guid[i]); + fprintf(stderr, "-"); for (i = 8; i < 16; i++) { - printf("%02X", guid[i]); + fprintf(stderr, "%02X", guid[i]); if (i == 9) - printf("-"); + fprintf(stderr, "-"); } - printf("\n"); + fprintf(stderr, "\n"); #endif } /* http://msdn.microsoft.com/en-us/library/dd318229.aspx */ -static UINT32 tsmf_codec_parse_BITMAPINFOHEADER(TS_AM_MEDIA_TYPE* mediatype, STREAM* s, BOOL bypass) +static UINT32 tsmf_codec_parse_BITMAPINFOHEADER(TS_AM_MEDIA_TYPE* mediatype, wStream* s, BOOL bypass) { UINT32 biSize; UINT32 biWidth; @@ -308,7 +308,7 @@ static UINT32 tsmf_codec_parse_BITMAPINFOHEADER(TS_AM_MEDIA_TYPE* mediatype, STR } /* http://msdn.microsoft.com/en-us/library/dd407326.aspx */ -static UINT32 tsmf_codec_parse_VIDEOINFOHEADER2(TS_AM_MEDIA_TYPE* mediatype, STREAM* s) +static UINT32 tsmf_codec_parse_VIDEOINFOHEADER2(TS_AM_MEDIA_TYPE* mediatype, wStream* s) { UINT64 AvgTimePerFrame; @@ -334,7 +334,7 @@ static UINT32 tsmf_codec_parse_VIDEOINFOHEADER2(TS_AM_MEDIA_TYPE* mediatype, STR } /* http://msdn.microsoft.com/en-us/library/dd390700.aspx */ -static UINT32 tsmf_codec_parse_VIDEOINFOHEADER(TS_AM_MEDIA_TYPE* mediatype, STREAM* s) +static UINT32 tsmf_codec_parse_VIDEOINFOHEADER(TS_AM_MEDIA_TYPE* mediatype, wStream* s) { /* typedef struct tagVIDEOINFOHEADER { @@ -367,7 +367,7 @@ typedef struct tagVIDEOINFOHEADER { return 48; } -BOOL tsmf_codec_parse_media_type(TS_AM_MEDIA_TYPE* mediatype, STREAM* s) +BOOL tsmf_codec_parse_media_type(TS_AM_MEDIA_TYPE* mediatype, wStream* s) { int i; UINT32 cbFormat; @@ -514,7 +514,7 @@ BOOL tsmf_codec_parse_media_type(TS_AM_MEDIA_TYPE* mediatype, STREAM* s) return ret; } -BOOL tsmf_codec_check_media_type(STREAM* s) +BOOL tsmf_codec_check_media_type(wStream* s) { BYTE* m; BOOL ret; diff --git a/channels/tsmf/client/tsmf_codec.h b/channels/tsmf/client/tsmf_codec.h index b00c0895f..5fc3a0a13 100644 --- a/channels/tsmf/client/tsmf_codec.h +++ b/channels/tsmf/client/tsmf_codec.h @@ -22,8 +22,8 @@ #include "tsmf_types.h" -BOOL tsmf_codec_parse_media_type(TS_AM_MEDIA_TYPE* mediatype, STREAM* s); -BOOL tsmf_codec_check_media_type(STREAM* s); +BOOL tsmf_codec_parse_media_type(TS_AM_MEDIA_TYPE* mediatype, wStream* s); +BOOL tsmf_codec_check_media_type(wStream* s); #endif diff --git a/channels/tsmf/client/tsmf_ifman.c b/channels/tsmf/client/tsmf_ifman.c index dd92246bf..b3bd1e97b 100644 --- a/channels/tsmf/client/tsmf_ifman.c +++ b/channels/tsmf/client/tsmf_ifman.c @@ -28,7 +28,7 @@ #include -#include +#include #include "tsmf_types.h" #include "tsmf_constants.h" diff --git a/channels/tsmf/client/tsmf_ifman.h b/channels/tsmf/client/tsmf_ifman.h index 90719f85f..8d3fbc2a5 100644 --- a/channels/tsmf/client/tsmf_ifman.h +++ b/channels/tsmf/client/tsmf_ifman.h @@ -31,9 +31,9 @@ struct _TSMF_IFMAN UINT32 stream_id; UINT32 message_id; - STREAM* input; + wStream* input; UINT32 input_size; - STREAM* output; + wStream* output; BOOL output_pending; UINT32 output_interface_id; }; diff --git a/channels/tsmf/client/tsmf_main.c b/channels/tsmf/client/tsmf_main.c index 24c8ad8f3..591b59659 100644 --- a/channels/tsmf/client/tsmf_main.c +++ b/channels/tsmf/client/tsmf_main.c @@ -28,7 +28,7 @@ #include #include -#include +#include #include "tsmf_types.h" #include "tsmf_constants.h" @@ -77,7 +77,7 @@ struct _TSMF_PLUGIN void tsmf_playback_ack(IWTSVirtualChannelCallback* pChannelCallback, UINT32 message_id, UINT64 duration, UINT32 data_size) { - STREAM* s; + wStream* s; int status; TSMF_CHANNEL_CALLBACK* callback = (TSMF_CHANNEL_CALLBACK*) pChannelCallback; @@ -100,7 +100,7 @@ void tsmf_playback_ack(IWTSVirtualChannelCallback* pChannelCallback, stream_free(s); } -BOOL tsmf_push_event(IWTSVirtualChannelCallback* pChannelCallback, RDP_EVENT* event) +BOOL tsmf_push_event(IWTSVirtualChannelCallback* pChannelCallback, wMessage* event) { int status; TSMF_CHANNEL_CALLBACK* callback = (TSMF_CHANNEL_CALLBACK*) pChannelCallback; @@ -121,8 +121,8 @@ static int tsmf_on_data_received(IWTSVirtualChannelCallback* pChannelCallback, BYTE* pBuffer) { int length; - STREAM* input; - STREAM* output; + wStream* input; + wStream* output; int status = -1; TSMF_IFMAN ifman; UINT32 MessageId; diff --git a/channels/tsmf/client/tsmf_main.h b/channels/tsmf/client/tsmf_main.h index b7b9589a8..d5de07f09 100644 --- a/channels/tsmf/client/tsmf_main.h +++ b/channels/tsmf/client/tsmf_main.h @@ -23,7 +23,7 @@ void tsmf_playback_ack(IWTSVirtualChannelCallback* pChannelCallback, UINT32 message_id, UINT64 duration, UINT32 data_size); BOOL tsmf_push_event(IWTSVirtualChannelCallback* pChannelCallback, - RDP_EVENT* event); + wMessage* event); #endif diff --git a/channels/tsmf/client/tsmf_media.c b/channels/tsmf/client/tsmf_media.c index ce3a5ce97..d1449237e 100644 --- a/channels/tsmf/client/tsmf_media.c +++ b/channels/tsmf/client/tsmf_media.c @@ -36,16 +36,15 @@ #endif #include +#include +#include +#include -#include +#include #include -#include #include #include -#include -#include - #include "tsmf_constants.h" #include "tsmf_types.h" #include "tsmf_decoder.h" @@ -54,6 +53,8 @@ #include "tsmf_codec.h" #include "tsmf_media.h" +#include + #define AUDIO_TOLERANCE 10000000LL struct _TSMF_PRESENTATION @@ -83,8 +84,8 @@ struct _TSMF_PRESENTATION UINT64 audio_start_time; UINT64 audio_end_time; - /* The stream list could be accessed by different threads and need to be protected. */ HANDLE mutex; + HANDLE thread; LIST* stream_list; }; @@ -112,12 +113,13 @@ struct _TSMF_STREAM /* Next sample should not start before this system time. */ UINT64 next_start_time; - freerdp_thread* thread; + BOOL started; - LIST* sample_list; + HANDLE thread; + HANDLE stopEvent; - /* The sample ack response queue will be accessed only by the stream thread. */ - LIST* sample_ack_list; + wQueue* sample_list; + wQueue* sample_ack_list; }; struct _TSMF_SAMPLE @@ -158,7 +160,7 @@ static TSMF_SAMPLE* tsmf_stream_pop_sample(TSMF_STREAM* stream, int sync) BOOL pending = FALSE; TSMF_PRESENTATION* presentation = stream->presentation; - if (list_size(stream->sample_list) == 0) + if (Queue_Count(stream->sample_list) < 1) return NULL; if (sync) @@ -204,11 +206,9 @@ static TSMF_SAMPLE* tsmf_stream_pop_sample(TSMF_STREAM* stream, int sync) if (pending) return NULL; - freerdp_thread_lock(stream->thread); - sample = (TSMF_SAMPLE*) list_dequeue(stream->sample_list); - freerdp_thread_unlock(stream->thread); + sample = (TSMF_SAMPLE*) Queue_Dequeue(stream->sample_list); - if (sample && sample->end_time > stream->last_end_time) + if (sample && (sample->end_time > stream->last_end_time)) stream->last_end_time = sample->end_time; return sample; @@ -218,6 +218,7 @@ static void tsmf_sample_free(TSMF_SAMPLE* sample) { if (sample->data) free(sample->data); + free(sample); } @@ -230,7 +231,7 @@ static void tsmf_sample_queue_ack(TSMF_SAMPLE* sample) { TSMF_STREAM* stream = sample->stream; - list_enqueue(stream->sample_ack_list, sample); + Queue_Enqueue(stream->sample_ack_list, sample); } static void tsmf_stream_process_ack(TSMF_STREAM* stream) @@ -239,13 +240,16 @@ static void tsmf_stream_process_ack(TSMF_STREAM* stream) UINT64 ack_time; ack_time = get_current_time(); - while (list_size(stream->sample_ack_list) > 0 && !freerdp_thread_is_stopped(stream->thread)) + + while ((Queue_Count(stream->sample_ack_list) > 0) && !(WaitForSingleObject(stream->stopEvent, 0) == WAIT_OBJECT_0)) { - sample = (TSMF_SAMPLE*) list_peek(stream->sample_ack_list); - if (!sample || sample->ack_time > ack_time) + sample = (TSMF_SAMPLE*) Queue_Peek(stream->sample_ack_list); + + if (!sample || (sample->ack_time > ack_time)) break; - sample = list_dequeue(stream->sample_ack_list); + sample = Queue_Dequeue(stream->sample_ack_list); + tsmf_sample_ack(sample); tsmf_sample_free(sample); } @@ -306,16 +310,19 @@ static void tsmf_presentation_restore_last_video_frame(TSMF_PRESENTATION* presen if (presentation->last_width && presentation->last_height) { - revent = (RDP_REDRAW_EVENT*) freerdp_event_new(RDP_EVENT_CLASS_TSMF, RDP_EVENT_TYPE_TSMF_REDRAW, + revent = (RDP_REDRAW_EVENT*) freerdp_event_new(TsmfChannel_Class, TsmfChannel_Redraw, NULL, NULL); + revent->x = presentation->last_x; revent->y = presentation->last_y; revent->width = presentation->last_width; revent->height = presentation->last_height; - if (!tsmf_push_event(presentation->channel_callback, (RDP_EVENT*) revent)) + + if (!tsmf_push_event(presentation->channel_callback, (wMessage*) revent)) { - freerdp_event_free((RDP_EVENT*) revent); + freerdp_event_free((wMessage*) revent); } + presentation->last_x = 0; presentation->last_y = 0; presentation->last_width = 0; @@ -379,8 +386,9 @@ static void tsmf_sample_playback_video(TSMF_SAMPLE* sample) } } - vevent = (RDP_VIDEO_FRAME_EVENT*) freerdp_event_new(RDP_EVENT_CLASS_TSMF, RDP_EVENT_TYPE_TSMF_VIDEO_FRAME, + vevent = (RDP_VIDEO_FRAME_EVENT*) freerdp_event_new(TsmfChannel_Class, TsmfChannel_VideoFrame, NULL, NULL); + vevent->frame_data = sample->data; vevent->frame_size = sample->decoded_size; vevent->frame_pixfmt = sample->pixfmt; @@ -406,9 +414,9 @@ static void tsmf_sample_playback_video(TSMF_SAMPLE* sample) sample->data = NULL; sample->decoded_size = 0; - if (!tsmf_push_event(sample->channel_callback, (RDP_EVENT*) vevent)) + if (!tsmf_push_event(sample->channel_callback, (wMessage*) vevent)) { - freerdp_event_free((RDP_EVENT*) vevent); + freerdp_event_free((wMessage*) vevent); } #if 0 @@ -670,7 +678,8 @@ static void* tsmf_stream_playback_func(void* arg) } } } - while (!freerdp_thread_is_stopped(stream->thread)) + + while (!(WaitForSingleObject(stream->stopEvent, 0) == WAIT_OBJECT_0)) { tsmf_stream_process_ack(stream); sample = tsmf_stream_pop_sample(stream, 1); @@ -680,18 +689,20 @@ static void* tsmf_stream_playback_func(void* arg) else USleep(5000); } + if (stream->eos || presentation->eos) { while ((sample = tsmf_stream_pop_sample(stream, 1)) != NULL) tsmf_sample_playback(sample); } + if (stream->audio) { stream->audio->Free(stream->audio); stream->audio = NULL; } - freerdp_thread_quit(stream->thread); + SetEvent(stream->stopEvent); DEBUG_DVC("out %d", stream->stream_id); @@ -700,9 +711,10 @@ static void* tsmf_stream_playback_func(void* arg) static void tsmf_stream_start(TSMF_STREAM* stream) { - if (!freerdp_thread_is_running(stream->thread)) + if (!stream->started) { - freerdp_thread_start(stream->thread, tsmf_stream_playback_func, stream); + ResumeThread(stream->thread); + stream->started = TRUE; } } @@ -714,10 +726,12 @@ static void tsmf_stream_stop(TSMF_STREAM* stream) if (!stream->decoder) return; - if (freerdp_thread_is_running(stream->thread)) + if (stream->started) { - freerdp_thread_stop(stream->thread); + SetEvent(stream->stopEvent); + stream->started = FALSE; } + if (stream->decoder->Control) { stream->decoder->Control(stream->decoder, Control_Flush, NULL); @@ -830,30 +844,35 @@ void tsmf_presentation_stop(TSMF_PRESENTATION* presentation) } tsmf_presentation_restore_last_video_frame(presentation); + if (presentation->last_rects) { free(presentation->last_rects); presentation->last_rects = NULL; } + presentation->last_num_rects = 0; + if (presentation->output_rects) { free(presentation->output_rects); presentation->output_rects = NULL; } + presentation->output_num_rects = 0; } void tsmf_presentation_set_geometry_info(TSMF_PRESENTATION* presentation, - UINT32 x, UINT32 y, UINT32 width, UINT32 height, - int num_rects, RDP_RECT* rects) + UINT32 x, UINT32 y, UINT32 width, UINT32 height, int num_rects, RDP_RECT* rects) { presentation->output_x = x; presentation->output_y = y; presentation->output_width = width; presentation->output_height = height; + if (presentation->output_rects) free(presentation->output_rects); + presentation->output_rects = rects; presentation->output_num_rects = num_rects; } @@ -866,13 +885,9 @@ void tsmf_presentation_set_audio_device(TSMF_PRESENTATION* presentation, const c static void tsmf_stream_flush(TSMF_STREAM* stream) { - TSMF_SAMPLE* sample; + //TSMF_SAMPLE* sample; - while ((sample = tsmf_stream_pop_sample(stream, 0)) != NULL) - tsmf_sample_free(sample); - - while ((sample = list_dequeue(stream->sample_ack_list)) != NULL) - tsmf_sample_free(sample); + /* TODO: free lists */ if (stream->audio) stream->audio->Flush(stream->audio); @@ -880,6 +895,7 @@ static void tsmf_stream_flush(TSMF_STREAM* stream) stream->eos = 0; stream->last_end_time = 0; stream->next_start_time = 0; + if (stream->major_type == TSMF_MAJOR_TYPE_AUDIO) { stream->presentation->audio_start_time = 0; @@ -929,6 +945,7 @@ TSMF_STREAM* tsmf_stream_new(TSMF_PRESENTATION* presentation, UINT32 stream_id) TSMF_STREAM* stream; stream = tsmf_stream_find_by_id(presentation, stream_id); + if (stream) { DEBUG_WARN("duplicated stream id %d!", stream_id); @@ -940,9 +957,14 @@ TSMF_STREAM* tsmf_stream_new(TSMF_PRESENTATION* presentation, UINT32 stream_id) stream->stream_id = stream_id; stream->presentation = presentation; - stream->thread = freerdp_thread_new(); - stream->sample_list = list_new(); - stream->sample_ack_list = list_new(); + + stream->started = FALSE; + + stream->stopEvent = CreateEvent(NULL, TRUE, FALSE, NULL); + stream->thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) tsmf_stream_playback_func, stream, CREATE_SUSPENDED, NULL); + + stream->sample_list = Queue_New(TRUE, -1, -1); + stream->sample_ack_list = Queue_New(TRUE, -1, -1); WaitForSingleObject(presentation->mutex, INFINITE); list_enqueue(presentation->stream_list, stream); @@ -959,13 +981,15 @@ TSMF_STREAM* tsmf_stream_find_by_id(TSMF_PRESENTATION* presentation, UINT32 stre for (item = presentation->stream_list->head; item; item = item->next) { stream = (TSMF_STREAM*) item->data; + if (stream->stream_id == stream_id) return stream; } + return NULL; } -void tsmf_stream_set_format(TSMF_STREAM* stream, const char* name, STREAM* s) +void tsmf_stream_set_format(TSMF_STREAM* stream, const char* name, wStream* s) { TS_AM_MEDIA_TYPE mediatype; @@ -981,7 +1005,7 @@ void tsmf_stream_set_format(TSMF_STREAM* stream, const char* name, STREAM* s) { DEBUG_DVC("video width %d height %d bit_rate %d frame_rate %f codec_data %d", mediatype.Width, mediatype.Height, mediatype.BitRate, - (double)mediatype.SamplesPerSecond.Numerator / (double)mediatype.SamplesPerSecond.Denominator, + (double) mediatype.SamplesPerSecond.Numerator / (double) mediatype.SamplesPerSecond.Denominator, mediatype.ExtraDataSize); } else if (mediatype.MajorType == TSMF_MAJOR_TYPE_AUDIO) @@ -989,9 +1013,11 @@ void tsmf_stream_set_format(TSMF_STREAM* stream, const char* name, STREAM* s) DEBUG_DVC("audio channel %d sample_rate %d bits_per_sample %d codec_data %d", mediatype.Channels, mediatype.SamplesPerSecond.Numerator, mediatype.BitsPerSample, mediatype.ExtraDataSize); + stream->sample_rate = mediatype.SamplesPerSecond.Numerator; stream->channels = mediatype.Channels; stream->bits_per_sample = mediatype.BitsPerSample; + if (stream->bits_per_sample == 0) stream->bits_per_sample = 16; } @@ -1019,8 +1045,8 @@ void tsmf_stream_free(TSMF_STREAM* stream) list_remove(presentation->stream_list, stream); ReleaseMutex(presentation->mutex); - list_free(stream->sample_list); - list_free(stream->sample_ack_list); + Queue_Free(stream->sample_list); + Queue_Free(stream->sample_ack_list); if (stream->decoder) { @@ -1028,7 +1054,7 @@ void tsmf_stream_free(TSMF_STREAM* stream) stream->decoder = 0; } - freerdp_thread_free(stream->thread); + SetEvent(stream->thread); free(stream); stream = 0; @@ -1063,11 +1089,9 @@ void tsmf_stream_push_sample(TSMF_STREAM* stream, IWTSVirtualChannelCallback* pC sample->data_size = data_size; sample->data = malloc(data_size + TSMF_BUFFER_PADDING_SIZE); ZeroMemory(sample->data, data_size + TSMF_BUFFER_PADDING_SIZE); - memcpy(sample->data, data, data_size); + CopyMemory(sample->data, data, data_size); - freerdp_thread_lock(stream->thread); - list_enqueue(stream->sample_list, sample); - freerdp_thread_unlock(stream->thread); + Queue_Enqueue(stream->sample_list, sample); } #ifndef _WIN32 diff --git a/channels/tsmf/client/tsmf_media.h b/channels/tsmf/client/tsmf_media.h index 9ba358820..fe52ccd79 100644 --- a/channels/tsmf/client/tsmf_media.h +++ b/channels/tsmf/client/tsmf_media.h @@ -49,7 +49,7 @@ void tsmf_presentation_free(TSMF_PRESENTATION* presentation); TSMF_STREAM* tsmf_stream_new(TSMF_PRESENTATION* presentation, UINT32 stream_id); TSMF_STREAM* tsmf_stream_find_by_id(TSMF_PRESENTATION* presentation, UINT32 stream_id); -void tsmf_stream_set_format(TSMF_STREAM* stream, const char* name, STREAM* s); +void tsmf_stream_set_format(TSMF_STREAM* stream, const char* name, wStream* s); void tsmf_stream_end(TSMF_STREAM* stream); void tsmf_stream_free(TSMF_STREAM* stream); diff --git a/channels/urbdrc/client/data_transfer.c b/channels/urbdrc/client/data_transfer.c index 1a39bc745..99d714513 100644 --- a/channels/urbdrc/client/data_transfer.c +++ b/channels/urbdrc/client/data_transfer.c @@ -237,7 +237,7 @@ static int urbdrc_process_io_control(URBDRC_CHANNEL_CALLBACK* callback, BYTE* da { case IOCTL_INTERNAL_USB_SUBMIT_URB: /** 0x00220003 */ LLOGLN(urbdrc_debug, ("ioctl: IOCTL_INTERNAL_USB_SUBMIT_URB")); - printf(" Function IOCTL_INTERNAL_USB_SUBMIT_URB: Unchecked\n"); + fprintf(stderr, " Function IOCTL_INTERNAL_USB_SUBMIT_URB: Unchecked\n"); break; case IOCTL_INTERNAL_USB_RESET_PORT: /** 0x00220007 */ @@ -269,12 +269,12 @@ static int urbdrc_process_io_control(URBDRC_CHANNEL_CALLBACK* callback, BYTE* da case IOCTL_INTERNAL_USB_CYCLE_PORT: /** 0x0022001F */ LLOGLN(urbdrc_debug, ("ioctl: IOCTL_INTERNAL_USB_CYCLE_PORT")); - printf(" Function IOCTL_INTERNAL_USB_CYCLE_PORT: Unchecked\n"); + fprintf(stderr, " Function IOCTL_INTERNAL_USB_CYCLE_PORT: Unchecked\n"); break; case IOCTL_INTERNAL_USB_SUBMIT_IDLE_NOTIFICATION: /** 0x00220027 */ LLOGLN(urbdrc_debug, ("ioctl: IOCTL_INTERNAL_USB_SUBMIT_IDLE_NOTIFICATION")); - printf(" Function IOCTL_INTERNAL_USB_SUBMIT_IDLE_NOTIFICATION: Unchecked\n"); + fprintf(stderr, " Function IOCTL_INTERNAL_USB_SUBMIT_IDLE_NOTIFICATION: Unchecked\n"); break; default: @@ -447,7 +447,7 @@ static int urb_select_configuration(URBDRC_CHANNEL_CALLBACK* callback, BYTE* dat if (transferDir == 0) { - printf("urb_select_configuration: not support transfer out\n"); + fprintf(stderr, "urb_select_configuration: not support transfer out\n"); return -1; } @@ -539,7 +539,7 @@ static int urb_select_interface(URBDRC_CHANNEL_CALLBACK* callback, BYTE* data, U if (transferDir == 0) { - printf("urb_select_interface: not support transfer out\n"); + fprintf(stderr, "urb_select_interface: not support transfer out\n"); return -1; } @@ -1296,7 +1296,7 @@ static int urb_os_feature_descriptor_request(URBDRC_CHANNEL_CALLBACK * callback, switch (transferDir) { case USBD_TRANSFER_DIRECTION_OUT: - printf("Function urb_os_feature_descriptor_request: OUT Unchecked\n"); + fprintf(stderr, "Function urb_os_feature_descriptor_request: OUT Unchecked\n"); memcpy(buffer, data + offset, OutputBufferSize); break; case USBD_TRANSFER_DIRECTION_IN: @@ -1699,7 +1699,7 @@ static int urb_control_feature_request(URBDRC_CHANNEL_CALLBACK * callback, BYTE switch (transferDir) { case USBD_TRANSFER_DIRECTION_OUT: - printf("Function urb_control_feature_request: OUT Unchecked\n"); + fprintf(stderr, "Function urb_control_feature_request: OUT Unchecked\n"); memcpy(buffer, data + offset, OutputBufferSize); bmRequestType |= 0x00; break; @@ -1717,7 +1717,7 @@ static int urb_control_feature_request(URBDRC_CHANNEL_CALLBACK * callback, BYTE bmRequest = 0x01; /* REQUEST_CLEAR_FEATURE */ break; default: - printf("urb_control_feature_request: Error Command %x\n", command); + fprintf(stderr, "urb_control_feature_request: Error Command %x\n", command); return -1; } diff --git a/channels/urbdrc/client/libusb/libusb_udevice.c b/channels/urbdrc/client/libusb/libusb_udevice.c index f325c994d..a2f417527 100644 --- a/channels/urbdrc/client/libusb/libusb_udevice.c +++ b/channels/urbdrc/client/libusb/libusb_udevice.c @@ -201,7 +201,7 @@ static void func_iso_callback(struct libusb_transfer *transfer) } else { - //printf("actual length %d \n", act_len); + //fprintf(stderr, "actual length %d \n", act_len); //exit(EXIT_FAILURE); } } @@ -362,7 +362,7 @@ static int func_config_release_all_interface(LIBUSB_DEVICE_HANDLE* libusb_handle if (ret < 0) { - printf("config_release_all_interface: error num %d\n", ret); + fprintf(stderr, "config_release_all_interface: error num %d\n", ret); return -1; } } @@ -380,7 +380,7 @@ static int func_claim_all_interface(LIBUSB_DEVICE_HANDLE* libusb_handle, int Num if (ret < 0) { - printf("claim_all_interface: error num %d\n", ret); + fprintf(stderr, "claim_all_interface: error num %d\n", ret); return -1; } } @@ -394,28 +394,28 @@ static void* print_transfer_status(enum libusb_transfer_status status) switch (status) { case LIBUSB_TRANSFER_COMPLETED: - //printf("Transfer Status: LIBUSB_TRANSFER_COMPLETED\n"); + //fprintf(stderr, "Transfer Status: LIBUSB_TRANSFER_COMPLETED\n"); break; case LIBUSB_TRANSFER_ERROR: - printf("Transfer Status: LIBUSB_TRANSFER_ERROR\n"); + fprintf(stderr, "Transfer Status: LIBUSB_TRANSFER_ERROR\n"); break; case LIBUSB_TRANSFER_TIMED_OUT: - printf("Transfer Status: LIBUSB_TRANSFER_TIMED_OUT\n"); + fprintf(stderr, "Transfer Status: LIBUSB_TRANSFER_TIMED_OUT\n"); break; case LIBUSB_TRANSFER_CANCELLED: - printf("Transfer Status: LIBUSB_TRANSFER_CANCELLED\n"); + fprintf(stderr, "Transfer Status: LIBUSB_TRANSFER_CANCELLED\n"); break; case LIBUSB_TRANSFER_STALL: - printf("Transfer Status: LIBUSB_TRANSFER_STALL\n"); + fprintf(stderr, "Transfer Status: LIBUSB_TRANSFER_STALL\n"); break; case LIBUSB_TRANSFER_NO_DEVICE: - printf("Transfer Status: LIBUSB_TRANSFER_NO_DEVICE\n"); + fprintf(stderr, "Transfer Status: LIBUSB_TRANSFER_NO_DEVICE\n"); break; case LIBUSB_TRANSFER_OVERFLOW: - printf("Transfer Status: LIBUSB_TRANSFER_OVERFLOW\n"); + fprintf(stderr, "Transfer Status: LIBUSB_TRANSFER_OVERFLOW\n"); break; default: - printf("Transfer Status: Get unknow error num %d (0x%x)\n", + fprintf(stderr, "Transfer Status: Get unknow error num %d (0x%x)\n", status, status); } return 0; @@ -426,28 +426,28 @@ static void print_status(enum libusb_transfer_status status) switch (status) { case LIBUSB_TRANSFER_COMPLETED: - printf("Transfer status: LIBUSB_TRANSFER_COMPLETED\n"); + fprintf(stderr, "Transfer status: LIBUSB_TRANSFER_COMPLETED\n"); break; case LIBUSB_TRANSFER_ERROR: - printf("Transfer status: LIBUSB_TRANSFER_ERROR\n"); + fprintf(stderr, "Transfer status: LIBUSB_TRANSFER_ERROR\n"); break; case LIBUSB_TRANSFER_TIMED_OUT: - printf("Transfer status: LIBUSB_TRANSFER_TIMED_OUT\n"); + fprintf(stderr, "Transfer status: LIBUSB_TRANSFER_TIMED_OUT\n"); break; case LIBUSB_TRANSFER_CANCELLED: - printf("Transfer status: LIBUSB_TRANSFER_CANCELLED\n"); + fprintf(stderr, "Transfer status: LIBUSB_TRANSFER_CANCELLED\n"); break; case LIBUSB_TRANSFER_STALL: - printf("Transfer status: LIBUSB_TRANSFER_STALL\n"); + fprintf(stderr, "Transfer status: LIBUSB_TRANSFER_STALL\n"); break; case LIBUSB_TRANSFER_NO_DEVICE: - printf("Transfer status: LIBUSB_TRANSFER_NO_DEVICE\n"); + fprintf(stderr, "Transfer status: LIBUSB_TRANSFER_NO_DEVICE\n"); break; case LIBUSB_TRANSFER_OVERFLOW: - printf("Transfer status: LIBUSB_TRANSFER_OVERFLOW\n"); + fprintf(stderr, "Transfer status: LIBUSB_TRANSFER_OVERFLOW\n"); break; default: - printf("Transfer status: unknow status %d(0x%x)\n", status, status); + fprintf(stderr, "Transfer status: unknow status %d(0x%x)\n", status, status); break; } } @@ -484,7 +484,7 @@ static LIBUSB_DEVICE_DESCRIPTOR* udev_new_descript(LIBUSB_DEVICE* libusb_dev) if (ret < 0) { - printf("libusb_get_device_descriptor: ERROR!!\n"); + fprintf(stderr, "libusb_get_device_descriptor: ERROR!!\n"); return NULL; } @@ -653,7 +653,7 @@ static int libusb_udev_select_interface(IUDEVICE* idev, BYTE InterfaceNumber, BY if (error < 0) { - printf("%s: Set interface altsetting get error num %d\n", + fprintf(stderr, "%s: Set interface altsetting get error num %d\n", __func__, error); } } @@ -680,7 +680,7 @@ static MSUSB_CONFIG_DESCRIPTOR* libusb_udev_complete_msconfig_setup(IUDEVICE* id LibusbConfig = pdev->LibusbConfig; if (LibusbConfig->bNumInterfaces != MsConfig->NumInterfaces) { - printf("Select Configuration: Libusb NumberInterfaces(%d) is different " + fprintf(stderr, "Select Configuration: Libusb NumberInterfaces(%d) is different " "with MsConfig NumberInterfaces(%d)\n", LibusbConfig->bNumInterfaces, MsConfig->NumInterfaces); } @@ -826,7 +826,7 @@ static int libusb_udev_select_configuration(IUDEVICE* idev, UINT32 bConfiguratio ret = libusb_set_configuration(libusb_handle, bConfigurationValue); if (ret < 0){ - printf("libusb_set_configuration: ERROR number %d!!\n", ret); + fprintf(stderr, "libusb_set_configuration: ERROR number %d!!\n", ret); func_claim_all_interface(libusb_handle, (*LibusbConfig)->bNumInterfaces); return -1; } @@ -834,7 +834,7 @@ static int libusb_udev_select_configuration(IUDEVICE* idev, UINT32 bConfiguratio { ret = libusb_get_active_config_descriptor (libusb_dev, LibusbConfig); if (ret < 0){ - printf("libusb_get_config_descriptor_by_value: ERROR number %d!!\n", ret); + fprintf(stderr, "libusb_get_config_descriptor_by_value: ERROR number %d!!\n", ret); func_claim_all_interface(libusb_handle, (*LibusbConfig)->bNumInterfaces); return -1; } @@ -884,7 +884,7 @@ static int libusb_udev_control_pipe_request(IUDEVICE* idev, UINT32 RequestId, *UsbdStatus = 0; /* if(pdev->request_queue->unregister_request(pdev->request_queue, RequestId)) - printf("request_queue_unregister_request: not fount request 0x%x\n", RequestId); + fprintf(stderr, "request_queue_unregister_request: not fount request 0x%x\n", RequestId); */ return error; } @@ -979,12 +979,12 @@ static int libusb_udev_os_feature_descriptor_request(IUDEVICE* idev, UINT32 Requ ms_string_desc, 0x12, Timeout); - //printf("Get ms string: result number %d", error); + //fprintf(stderr, "Get ms string: result number %d", error); if (error > 0) { BYTE bMS_Vendorcode; data_read_BYTE(ms_string_desc + 16, bMS_Vendorcode); - //printf("bMS_Vendorcode:0x%x", bMS_Vendorcode); + //fprintf(stderr, "bMS_Vendorcode:0x%x", bMS_Vendorcode); /** get os descriptor */ error = libusb_control_transfer(pdev->libusb_handle, LIBUSB_ENDPOINT_IN |LIBUSB_REQUEST_TYPE_VENDOR | Recipient, @@ -1003,7 +1003,7 @@ static int libusb_udev_os_feature_descriptor_request(IUDEVICE* idev, UINT32 Requ *UsbdStatus = USBD_STATUS_SUCCESS; /* if(pdev->request_queue->unregister_request(pdev->request_queue, RequestId)) - printf("request_queue_unregister_request: not fount request 0x%x\n", RequestId); + fprintf(stderr, "request_queue_unregister_request: not fount request 0x%x\n", RequestId); */ return error; } @@ -1262,7 +1262,7 @@ static int libusb_udev_isoch_transfer(IUDEVICE* idev, UINT32 RequestId, UINT32 E if (iso_transfer == NULL) { - printf("Error: libusb_alloc_transfer.\n"); + fprintf(stderr, "Error: libusb_alloc_transfer.\n"); status = -1; } @@ -1367,7 +1367,7 @@ static int libusb_udev_bulk_or_interrupt_transfer(IUDEVICE* idev, UINT32 Request if (!ep_desc) { - printf("func_get_ep_desc: endpoint 0x%x is not found!!\n", EndpointAddress); + fprintf(stderr, "func_get_ep_desc: endpoint 0x%x is not found!!\n", EndpointAddress); return -1; } transfer_type = (ep_desc->bmAttributes) & 0x3; @@ -1493,7 +1493,7 @@ static int libusb_udev_bulk_or_interrupt_transfer(IUDEVICE* idev, UINT32 Request if (request) { if(pdev->request_queue->unregister_request(pdev->request_queue, RequestId)) - printf("request_queue_unregister_request: not fount request 0x%x\n", RequestId); + fprintf(stderr, "request_queue_unregister_request: not fount request 0x%x\n", RequestId); } libusb_free_transfer(transfer); @@ -1698,7 +1698,7 @@ static IUDEVICE* udev_init(UDEVICE* pdev, UINT16 bus_number, UINT16 dev_number) if (status < 0) { - printf("USB init: Error to get HUB handle!!\n"); + fprintf(stderr, "USB init: Error to get HUB handle!!\n"); pdev->hub_handle = NULL; } @@ -1706,7 +1706,7 @@ static IUDEVICE* udev_init(UDEVICE* pdev, UINT16 bus_number, UINT16 dev_number) if (!pdev->devDescriptor) { - printf("USB init: Error to get device descriptor!!\n"); + fprintf(stderr, "USB init: Error to get device descriptor!!\n"); zfree(pdev); return NULL; } @@ -1717,7 +1717,7 @@ static IUDEVICE* udev_init(UDEVICE* pdev, UINT16 bus_number, UINT16 dev_number) if (status < 0) { - printf("libusb_get_descriptor: ERROR!!ret:%d\n", status); + fprintf(stderr, "libusb_get_descriptor: ERROR!!ret:%d\n", status); zfree(pdev); return NULL; } @@ -1746,7 +1746,7 @@ static IUDEVICE* udev_init(UDEVICE* pdev, UINT16 bus_number, UINT16 dev_number) case CLASS_CONTENT_SECURITY: //case CLASS_WIRELESS_CONTROLLER: //case CLASS_ELSE_DEVICE: - printf(" Device is not supported!!\n"); + fprintf(stderr, " Device is not supported!!\n"); zfree(pdev); return NULL; default: @@ -1812,7 +1812,7 @@ int udev_new_by_id(UINT16 idVendor, UINT16 idProduct, IUDEVICE*** devArray) ssize_t total_device; int i, status, num = 0; - printf("VID: 0x%04X PID: 0x%04X\n", idVendor, idProduct); + fprintf(stderr, "VID: 0x%04X PID: 0x%04X\n", idVendor, idProduct); array = (UDEVICE**) malloc(16 * sizeof(UDEVICE*)); @@ -1833,7 +1833,7 @@ int udev_new_by_id(UINT16 idVendor, UINT16 idProduct, IUDEVICE*** devArray) if (status < 0) { - printf("libusb_open: (by id) error: 0x%08X (%d)\n", status, status); + fprintf(stderr, "libusb_open: (by id) error: 0x%08X (%d)\n", status, status); zfree(descriptor); zfree(array[num]); continue; @@ -1870,7 +1870,7 @@ IUDEVICE* udev_new_by_addr(int bus_number, int dev_number) if (pDev->libusb_dev == NULL) { - printf("libusb_device_new: ERROR!!\n"); + fprintf(stderr, "libusb_device_new: ERROR!!\n"); zfree(pDev); return NULL; } @@ -1879,7 +1879,7 @@ IUDEVICE* udev_new_by_addr(int bus_number, int dev_number) if (status < 0) { - printf("libusb_open: (by addr) ERROR!!\n"); + fprintf(stderr, "libusb_open: (by addr) ERROR!!\n"); zfree(pDev); return NULL; } diff --git a/channels/urbdrc/client/libusb/libusb_udevman.c b/channels/urbdrc/client/libusb/libusb_udevman.c index 0e0e14a3d..ebf5e4b5a 100644 --- a/channels/urbdrc/client/libusb/libusb_udevman.c +++ b/channels/urbdrc/client/libusb/libusb_udevman.c @@ -206,7 +206,7 @@ static int udevman_register_udevice(IUDEVMAN* idevman, int bus_number, int dev_n } else { - printf("udevman_register_udevice: function error!!"); + fprintf(stderr, "udevman_register_udevice: function error!!"); return 0; } diff --git a/channels/urbdrc/client/libusb/request_queue.c b/channels/urbdrc/client/libusb/request_queue.c index 893d4f236..e5ebfef71 100644 --- a/channels/urbdrc/client/libusb/request_queue.c +++ b/channels/urbdrc/client/libusb/request_queue.c @@ -100,7 +100,7 @@ TRANSFER_REQUEST* request_queue_get_request_by_endpoint(REQUEST_QUEUE* queue, BY } } pthread_mutex_unlock(&queue->request_loading); - printf("request_queue_get_request_by_id: ERROR!!\n"); + fprintf(stderr, "request_queue_get_request_by_id: ERROR!!\n"); return NULL; } diff --git a/channels/urbdrc/client/searchman.c b/channels/urbdrc/client/searchman.c index fd13ab0cb..18fc5b73e 100644 --- a/channels/urbdrc/client/searchman.c +++ b/channels/urbdrc/client/searchman.c @@ -156,16 +156,16 @@ static void searchman_list_show(USB_SEARCHMAN* self) int num = 0; USB_SEARCHDEV* usb; - printf("=========== Usb Search List ========= \n"); + fprintf(stderr, "=========== Usb Search List ========= \n"); self->rewind(self); while (self->has_next(self)) { usb = self->get_next(self); - printf(" USB %d: \n", num++); - printf(" idVendor: 0x%04X \n", usb->idVendor); - printf(" idProduct: 0x%04X \n", usb->idProduct); + fprintf(stderr, " USB %d: \n", num++); + fprintf(stderr, " idVendor: 0x%04X \n", usb->idVendor); + fprintf(stderr, " idProduct: 0x%04X \n", usb->idProduct); } - printf("================= END =============== \n"); + fprintf(stderr, "================= END =============== \n"); } void searchman_free(USB_SEARCHMAN* self) @@ -202,7 +202,7 @@ USB_SEARCHMAN* searchman_new(void * urbdrc, UINT32 UsbDevice) if (ret != 0) { - printf("searchman mutex initialization: searchman->mutex failed"); + fprintf(stderr, "searchman mutex initialization: searchman->mutex failed"); exit(EXIT_FAILURE); } diff --git a/channels/urbdrc/client/urbdrc_main.c b/channels/urbdrc/client/urbdrc_main.c index 32e493c74..d7628f343 100644 --- a/channels/urbdrc/client/urbdrc_main.c +++ b/channels/urbdrc/client/urbdrc_main.c @@ -464,7 +464,7 @@ static void* urbdrc_search_usb_device(void* arg) if (!udev) { - printf("Can't create udev\n"); + fprintf(stderr, "Can't create udev\n"); return 0; } @@ -648,7 +648,7 @@ static void* urbdrc_search_usb_device(void* arg) } else { - printf("No Device from receive_device(). An error occured.\n"); + fprintf(stderr, "No Device from receive_device(). An error occured.\n"); } } } @@ -830,7 +830,7 @@ static int urbdrc_on_data_received(IWTSVirtualChannelCallback* pChannelCallback, transfer_data = (TRANSFER_DATA*) malloc(sizeof(TRANSFER_DATA)); if (transfer_data == NULL) - printf("transfer_data is NULL!!"); + fprintf(stderr, "transfer_data is NULL!!"); transfer_data->callback = callback; transfer_data->urbdrc = urbdrc; diff --git a/channels/urbdrc/client/urbdrc_types.h b/channels/urbdrc/client/urbdrc_types.h index 485595004..3b83cee02 100644 --- a/channels/urbdrc/client/urbdrc_types.h +++ b/channels/urbdrc/client/urbdrc_types.h @@ -28,13 +28,14 @@ #include #include #include -#include #include #include #include #include +#include + #ifdef WITH_DEBUG_DVC #define DEBUG_DVC(fmt, ...) DEBUG_CLASS(DVC, fmt, ## __VA_ARGS__) #else diff --git a/client/.gitignore b/client/.gitignore index e69de29bb..3b702c283 100644 --- a/client/.gitignore +++ b/client/.gitignore @@ -0,0 +1,2 @@ +WaykClient + diff --git a/client/Android/.classpath b/client/Android/.classpath deleted file mode 100644 index a4763d1ee..000000000 --- a/client/Android/.classpath +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - diff --git a/client/Android/.project b/client/Android/.project deleted file mode 100644 index 335291e03..000000000 --- a/client/Android/.project +++ /dev/null @@ -1,33 +0,0 @@ - - - aFreeRDP - - - - - - com.android.ide.eclipse.adt.ResourceManagerBuilder - - - - - com.android.ide.eclipse.adt.PreCompilerBuilder - - - - - org.eclipse.jdt.core.javabuilder - - - - - com.android.ide.eclipse.adt.ApkBuilder - - - - - - com.android.ide.eclipse.adt.AndroidNature - org.eclipse.jdt.core.javanature - - diff --git a/client/Android/FreeRDPCore/AndroidManifest.xml.cmake b/client/Android/FreeRDPCore/AndroidManifest.xml.cmake index 03344d43f..639d5ac80 100644 --- a/client/Android/FreeRDPCore/AndroidManifest.xml.cmake +++ b/client/Android/FreeRDPCore/AndroidManifest.xml.cmake @@ -9,41 +9,41 @@ - + - - - - - - + + + + + + - - - - - - - + android:targetActivity="com.freerdp.freerdpcore.presentation.ShortcutsActivity" + android:label="@string/title_create_shortcut"> + + + + + + + - - - - - + + + + + - - - + + + + diff --git a/client/Android/FreeRDPCore/jni/android_freerdp.c b/client/Android/FreeRDPCore/jni/android_freerdp.c index 8a4165a06..e93c6b217 100644 --- a/client/Android/FreeRDPCore/jni/android_freerdp.c +++ b/client/Android/FreeRDPCore/jni/android_freerdp.c @@ -24,7 +24,6 @@ #include #include #include -#include #include #include @@ -309,7 +308,7 @@ int android_receive_channel_data(freerdp* instance, int channelId, UINT8* data, void android_process_channel_event(rdpChannels* channels, freerdp* instance) { - RDP_EVENT* event; + wMessage* event; event = freerdp_channels_pop_event(channels); @@ -317,7 +316,7 @@ void android_process_channel_event(rdpChannels* channels, freerdp* instance) { /* switch (event->event_class) { - case RDP_EVENT_CLASS_RAIL: + case RailChannel_Class: xf_process_rail_event(ai, chanman, event); break; @@ -533,11 +532,17 @@ JNIEXPORT void JNICALL jni_freerdp_set_data_directory(JNIEnv *env, jclass cls, j rdpSettings * settings = inst->settings; const jbyte *directory = (*env)->GetStringUTFChars(env, jdirectory, NULL); + free(settings->HomePath); free(settings->ConfigPath); + + int config_dir_len = strlen(directory) + 10; /* +9 chars for /.freerdp and +1 for \0 */ + char* config_dir_buf = (char*)malloc(config_dir_len); + strcpy(config_dir_buf, directory); + strcat(config_dir_buf, "/.freerdp"); settings->HomePath = strdup(directory); - settings->ConfigPath = NULL; - freerdp_detect_paths(settings); + settings->ConfigPath = config_dir_buf; /* will be freed by freerdp library */ + (*env)->ReleaseStringUTFChars(env, jdirectory, directory); } @@ -596,6 +601,7 @@ JNIEXPORT void JNICALL jni_freerdp_set_connection_info(JNIEnv *env, jclass cls, /* enable NSCodec */ settings->NSCodec = TRUE; + settings->BitmapCacheV3Enabled = TRUE; switch ((int) security) { diff --git a/client/Android/FreeRDPCore/res/values-es/strings.xml b/client/Android/FreeRDPCore/res/values-es/strings.xml new file mode 100644 index 000000000..2f9d36d8e --- /dev/null +++ b/client/Android/FreeRDPCore/res/values-es/strings.xml @@ -0,0 +1,175 @@ + + + + Si + No + Cancelar + Continuar + Ingresar + Salir + + Salida + Sobre + Ayuda + Nueva conexión + Configuracion + + Conexión + Conectar + Editar + Borrar + + Teclado + Funcion teclado + Puntero Tactil + Inicio + desconectart + + Conexión Manual + Sesiones Activas + + Connectarse a iWinCloud + + Login + No hay escritorios virtuales + Conectando ... + Desconectando ... + Conexión perdida + Contraseña equivocada + Usuario Invalido + Agregar escritorio virtual de iWinCloud + + Host + Su nombre + IP + Puerto + Credenciales de iWinCloud + Credenciales + Usuario + Contraseña + Dominio + Configuracion + Pantalla + Configuracion Pantalla + Colores + + Calidad Normal (16 Bit) + Calidad Optima (24 Bit) + Calidad maxima (32 Bit) + + + 16 + 24 + 32 + + Resolucion + Automatico + Manual + + Automatico + Manual + 640x480 + 720x480 + 800x600 + 1024x768 + 1280x1024 + 1440x900 + 1920x1080 + 1920x1200 + + + automatico + manual + 640x480 + 720x480 + 800x600 + 1024x768 + 1280x1024 + 1440x900 + 1920x1080 + 1920x1200 + + Ancho + Altura + Rendimiento + Configuracion Rendimiento + RemoteFX + Fondo escritorio + Fuente suave + Composicion escritorio + Contenidos de la ventana mientras se arrastra + Animacion del menu + Estilo visual + Avanzado + Configuracion Avanzada + Configuracion 3G + Pantalla 3G + Rendimiento 3G + Seguridad + + Automatico + RDP + TLS + NLA + + + 0 + 1 + 2 + 3 + + Programa Remoto + Directorio de trabajo + Modo Consola + + ******* + no configurado + Interfaze Usuario + Ocultar barra de estado + Ocultar controles de zoom + Intercambiar botones del mouse + invertir desplazamiento + Puntero táctil de desplazamiento automático + Mostrar cuadro de diálogo en la salida + Ahorro de energía + Cerrar las conexiones inactivas + Seguridad + Aceptar todos los certificados + Borrar el Cache de los certificados + Despues %1$d Minutos + Desabilitado + + Configuración de la conexión + Configuración + iWinCloud - iWinCloud para Android + Conexiones RDP + Ayuda + Sobre + + Cancelar sin guardar? + Pulse el botón "Cancelar" para abortar! \ NPulse "Continuar" para especificar los campos obligatorios! + No se pudo establecer una conexión con iWinCloud! + + Los ajustes de pantalla se han cambiado porque el escritorio virtual no es compatible con la configuración especificada! + Eliminado el cache del certificado! + No se pudo borrar el caché del certificado! + + verificar el certificado + La identidad de su escritorio de iWinCloud debe ser verificada. ¿Desea conectarse de todos modos? + Por favor, introduzca sus credenciales + Crear acceso directo + Nombre corto: + Conectando ... + Ingresando a ... + Sobre iWinCloud + Version: %1$s\n\u00A9 2012 iWinCloud LLc + Guardar configuración de conexión? + La configuración de conexión no se han guardado! ¿Quieres guardarlos? + Guardar Conexión + ¿Desea guardar los cambios realizados en la configuración de conexión? + No volver a preguntar + Salir del programa? + Esta seguro que desea salir del programa? + Borrar Certificados? + Esta seguro que desea borrar todos los certificados? + diff --git a/client/Android/FreeRDPCore/res/values-fr/strings.xml b/client/Android/FreeRDPCore/res/values-fr/strings.xml new file mode 100644 index 000000000..95f3d6490 --- /dev/null +++ b/client/Android/FreeRDPCore/res/values-fr/strings.xml @@ -0,0 +1,174 @@ + + + "Oui" + "Non" + "Annuler" + "Continuer" + "Se connecter" + "Déconnexion" + + "Quitter" + "À propos" + "Aide" + "Nouvelle connexion" + "Paramètres" + + "Connexion" + "Connexion" + "Éditer" + "Supprimer" + + "Clavier" + "Touches de fonction" + "Pointeur tactile" + "Accueil" + "Se déconnecter" + + "Connexions manuelles" + "Sessions actives" + + "Connexion à l'ordinateur" + + "Se connecter" + "Pas de connexion" + "Connexion..." + "Déconnexion…" + "Perte de la connexion" + "Mot de passe incorrect" + "Nom d'utilisateur invalide" + "Ajouter une connexion" + + "Hôte" + "Étiquette" + "Hôte" + "Port" + "Authentifiant" + "Authentifiant" + "Nom d'utilisateur" + "Mot de passe" + "Nom de domaine" + "Paramètres" + "Écran" + "Paramètres d'écran" + "Couleurs" + + "Hautes couleurs (16 bits)" + "Couleurs vraies (24 bits)" + "Haute qualité (32 bits)" + + + "16" + "24" + "32" + + "Résolution" + "Automatique" + "Personalisé" + + "Automatique" + "Personalisé" + "640x480" + "720x480" + "800x600" + "1024x768" + "1280x1024" + "1440x900" + "1920x1080" + "1920x1200" + + + "Automatique" + "Personalisé" + "640x480" + "720x480" + "800x600" + "1024x768" + "1280x1024" + "1440x900" + "1920x1080" + "1920x1200" + + "Largeur" + "Hauteur" + "Performance" + "Paramètres de performance" + "RemoteFX" + "Fond d'écran" + "Lissage des polices" + "Effets visuels Aero" + "Afficher le contenu des fenêtres en mouvement" + "Animations de menu" + "Styles visuels" + "Avancé" + "Paramètres avancés" + "Paramètres 3G" + "Écran 3G" + "Performance 3G" + "Securité" + + "Automatique" + "RDP" + "TLS" + "NLA" + + + "0" + "1" + "2" + "3" + + "Lancement de programme" + "Répertoire de travail" + "Mode console" + + "*******" + "Valeur non définie" + "Interface utilisateur" + "Masquer la barre d'état" + "Masquer les contrôles zoom" + "Inverser les boutons de la souris" + "Inverser le défilement de la souris" + "Défilement automatique du pointeur tactile" + "Confirmer au moment de quitter" + "Economie d'énergie" + "Fermer les connexions inactives" + "Securité" + "Accepter tous les certificats" + "Vider la cache de certificats" + "Après %1$d minutes" + "Désactivé" + + "Paramètres de connexion" + "Paramètres" + "aFreeRDP - FreeRDP pour Android" + "Connexions RDP" + "Aide" + "À propos" + + "Annuler sans enregistrer?" + "Appuyez sur \"Annuler\" pour annuler, ou cliquez sur «Continuer» pour spécifier les champs obligatoires." + "Impossible d'établir une connexion au serveur!" + + "Les paramètres de l'écran ont changé parce que le serveur ne prend pas en charge les paramètres que vous avez spécifiés!" + "La cache de certificats a été supprimée!" + "Impossible de supprimer la cache de certificat!" + + "Validation de certificat" + "L'identité de l'ordinateur distant ne peut pas être vérifiée. Voulez-vous poursuivre la connexion?" + "Veuillez entrer votre nom d'usager et mot de passe" + "Créer un raccourci" + "Nom du raccourci:" + "Connexion..." + "Connexion..." + "À propos de aFreeRDP" + "Version: %1$s \ n \ u00A9 2012 Technologies GmbH Thinstuff" + "Enregistrer les paramètres de connexion?" + "Vos paramètres de connexion n'ont pas été sauvegardés! Voulez-vous les enregistrer?" + "Enregistrer la connexion?" + "Voulez-vous enregistrer les modifications que vous avez apportées aux paramètres de connexion?" + "Ne plus demander" + "Quittez l'application?" + "Êtes-vous sûr de vouloir quitter l'application?" + "Êtes-vous sûrs de vouloir supprimer les certificats?" + "Êtes-vous sûr de vouloir supprimer tous les certificats mis en cache?" + diff --git a/client/Android/FreeRDPCore/res/xml/application_settings.xml b/client/Android/FreeRDPCore/res/xml/application_settings.xml index 9d7cc0a67..0df4ea126 100644 --- a/client/Android/FreeRDPCore/res/xml/application_settings.xml +++ b/client/Android/FreeRDPCore/res/xml/application_settings.xml @@ -29,5 +29,4 @@ - diff --git a/client/Android/FreeRDPCore/res/xml/bookmark_settings.xml b/client/Android/FreeRDPCore/res/xml/bookmark_settings.xml index c49d4272a..0564537d7 100644 --- a/client/Android/FreeRDPCore/res/xml/bookmark_settings.xml +++ b/client/Android/FreeRDPCore/res/xml/bookmark_settings.xml @@ -12,7 +12,7 @@ - + diff --git a/client/Android/FreeRDPCore/res/xml/credentials_settings.xml b/client/Android/FreeRDPCore/res/xml/credentials_settings.xml index 0247b66cd..a27be58c1 100644 --- a/client/Android/FreeRDPCore/res/xml/credentials_settings.xml +++ b/client/Android/FreeRDPCore/res/xml/credentials_settings.xml @@ -11,8 +11,8 @@ --> - - - + + + diff --git a/client/Android/FreeRDPCore/src/com/freerdp/freerdpcore/application/GlobalApp.java b/client/Android/FreeRDPCore/src/com/freerdp/freerdpcore/application/GlobalApp.java index c37f8df5a..aca737a4b 100644 --- a/client/Android/FreeRDPCore/src/com/freerdp/freerdpcore/application/GlobalApp.java +++ b/client/Android/FreeRDPCore/src/com/freerdp/freerdpcore/application/GlobalApp.java @@ -194,8 +194,7 @@ public class GlobalApp extends Application implements LibFreeRDP.EventListener { Log.v("LibFreeRDP", "OnConnectionFailure"); - // free session - GlobalApp.freeSession(instance); + // send notification to session activity sendRDPNotification(FREERDP_EVENT_CONNECTION_FAILURE, instance); } @@ -210,8 +209,5 @@ public class GlobalApp extends Application implements LibFreeRDP.EventListener public void OnDisconnected(int instance) { Log.v("LibFreeRDP", "OnDisconnected"); - - // free session - GlobalApp.freeSession(instance); } } diff --git a/client/Android/FreeRDPCore/src/com/freerdp/freerdpcore/presentation/SessionActivity.java b/client/Android/FreeRDPCore/src/com/freerdp/freerdpcore/presentation/SessionActivity.java index 657678bc7..3d1c5adc1 100644 --- a/client/Android/FreeRDPCore/src/com/freerdp/freerdpcore/presentation/SessionActivity.java +++ b/client/Android/FreeRDPCore/src/com/freerdp/freerdpcore/presentation/SessionActivity.java @@ -256,7 +256,6 @@ public class SessionActivity extends Activity if (!connectCancelledByUser) uiHandler.sendMessage(Message.obtain(null, UIHandler.DISPLAY_TOAST, getResources().getText(R.string.error_connection_failure))); - session = null; closeSessionActivity(RESULT_CANCELED); } @@ -271,7 +270,6 @@ public class SessionActivity extends Activity } session.setUIEventListener(null); - session = null; closeSessionActivity(RESULT_OK); } } @@ -518,9 +516,13 @@ public class SessionActivity extends Activity protected void onDestroy() { super.onDestroy(); Log.v(TAG, "Session.onDestroy"); - + // unregister freerdp events broadcast receiver unregisterReceiver(libFreeRDPBroadcastReceiver); + + // free session + GlobalApp.freeSession(session.getInstance()); + session = null; } @Override diff --git a/client/Android/aFreeRDP/AndroidManifest.xml.cmake b/client/Android/aFreeRDP/AndroidManifest.xml.cmake index 696e03646..7e6e0e86c 100644 --- a/client/Android/aFreeRDP/AndroidManifest.xml.cmake +++ b/client/Android/aFreeRDP/AndroidManifest.xml.cmake @@ -7,7 +7,7 @@ android:versionName="@FREERDP_VERSION_FULL@" > - + - - - + + + @@ -42,7 +42,7 @@ android:excludeFromRecents="true"> - + + diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index 25b639caf..ee294378b 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -51,3 +51,7 @@ if(ANDROID) add_subdirectory(Android) endif() +if(WITH_WAYK) + add_subdirectory(WaykClient) +endif() + diff --git a/client/DirectFB/dfreerdp.c b/client/DirectFB/dfreerdp.c index 1812cd3a1..e2b88a786 100644 --- a/client/DirectFB/dfreerdp.c +++ b/client/DirectFB/dfreerdp.c @@ -265,12 +265,12 @@ static int df_receive_channel_data(freerdp* instance, int channelId, BYTE* data, static void df_process_cb_monitor_ready_event(rdpChannels* channels, freerdp* instance) { - RDP_EVENT* event; + wMessage* event; RDP_CB_FORMAT_LIST_EVENT* format_list_event; - event = freerdp_event_new(RDP_EVENT_CLASS_CLIPRDR, RDP_EVENT_TYPE_CB_FORMAT_LIST, NULL, NULL); + event = freerdp_event_new(CliprdrChannel_Class, CliprdrChannel_FormatList, NULL, NULL); - format_list_event = (RDP_CB_FORMAT_LIST_EVENT*)event; + format_list_event = (RDP_CB_FORMAT_LIST_EVENT*) event; format_list_event->num_formats = 0; freerdp_channels_send_event(channels, event); @@ -278,19 +278,20 @@ static void df_process_cb_monitor_ready_event(rdpChannels* channels, freerdp* in static void df_process_channel_event(rdpChannels* channels, freerdp* instance) { - RDP_EVENT* event; + wMessage* event; event = freerdp_channels_pop_event(channels); if (event) { - switch (event->event_type) + switch (GetMessageType(event->id)) { - case RDP_EVENT_TYPE_CB_MONITOR_READY: + case CliprdrChannel_MonitorReady: df_process_cb_monitor_ready_event(channels, instance); break; + default: - printf("df_process_channel_event: unknown event type %d\n", event->event_type); + fprintf(stderr, "df_process_channel_event: unknown event type %d\n", GetMessageType(event->id)); break; } @@ -319,8 +320,8 @@ int dfreerdp_run(freerdp* instance) dfContext* context; rdpChannels* channels; - memset(rfds, 0, sizeof(rfds)); - memset(wfds, 0, sizeof(wfds)); + ZeroMemory(rfds, sizeof(rfds)); + ZeroMemory(wfds, sizeof(wfds)); if (!freerdp_connect(instance)) return 0; @@ -337,17 +338,17 @@ int dfreerdp_run(freerdp* instance) if (freerdp_get_fds(instance, rfds, &rcount, wfds, &wcount) != TRUE) { - printf("Failed to get FreeRDP file descriptor\n"); + fprintf(stderr, "Failed to get FreeRDP file descriptor\n"); break; } if (freerdp_channels_get_fds(channels, instance, rfds, &rcount, wfds, &wcount) != TRUE) { - printf("Failed to get channel manager file descriptor\n"); + fprintf(stderr, "Failed to get channel manager file descriptor\n"); break; } if (df_get_fds(instance, rfds, &rcount, wfds, &wcount) != TRUE) { - printf("Failed to get dfreerdp file descriptor\n"); + fprintf(stderr, "Failed to get dfreerdp file descriptor\n"); break; } @@ -376,24 +377,24 @@ int dfreerdp_run(freerdp* instance) (errno == EINPROGRESS) || (errno == EINTR))) /* signal occurred */ { - printf("dfreerdp_run: select failed\n"); + fprintf(stderr, "dfreerdp_run: select failed\n"); break; } } if (freerdp_check_fds(instance) != TRUE) { - printf("Failed to check FreeRDP file descriptor\n"); + fprintf(stderr, "Failed to check FreeRDP file descriptor\n"); break; } if (df_check_fds(instance, &rfds_set) != TRUE) { - printf("Failed to check dfreerdp file descriptor\n"); + fprintf(stderr, "Failed to check dfreerdp file descriptor\n"); break; } if (freerdp_channels_check_fds(channels, instance) != TRUE) { - printf("Failed to check channel manager file descriptor\n"); + fprintf(stderr, "Failed to check channel manager file descriptor\n"); break; } df_process_channel_event(channels, instance); diff --git a/client/Mac/CMakeLists.txt b/client/Mac/CMakeLists.txt index 2183eb9d2..80b03ca62 100644 --- a/client/Mac/CMakeLists.txt +++ b/client/Mac/CMakeLists.txt @@ -6,12 +6,10 @@ set(MODULE_PREFIX "FREERDP_CLIENT_MAC") set(FRAMEWORK_HEADERS_PATH /System/Library/Frameworks/Cocoa.framework/Versions/A/Headers/) include_directories(${FRAMEWORK_HEADERS_PATH} /System/Library/Frameworks) - -# set(CMAKE_OSX_SYSROOT MacOSX10.7.sdk) + set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -mmacosx-version-min=10.4") set(GUI_TYPE MACOSX_BUNDLE) -# Import libraries find_library(FOUNDATION_LIBRARY Foundation) find_library(COCOA_LIBRARY Cocoa) find_library(APPKIT_LIBRARY AppKit) @@ -33,16 +31,32 @@ mark_as_advanced(COCOA_LIBRARY FOUNDATION_LIBRARY APPKIT_LIBRARY) set(EXTRA_LIBS ${COCOA_LIBRARY} ${FOUNDATION_LIBRARY} ${APPKIT_LIBRARY}) set(APP_TYPE MACOSX_BUNDLE) -# OS X Interface Builder files -file(GLOB ${MODULE_NAME}_XIBS *.xib) +set(${MODULE_NAME}_XIBS + MainMenu.xib + PasswordDialog.xib) -set(${MODULE_NAME}_RESOURCES ${${MODULE_NAME}_XIBS} ${MACOSX_BUNDLE_ICON_FILE}) +set(${MODULE_NAME}_RESOURCES + ${${MODULE_NAME}_XIBS} + ${MACOSX_BUNDLE_ICON_FILE}) -# Headers -file(GLOB ${MODULE_NAME}_HEADERS *.h) +set(${MODULE_NAME}_HEADERS + AppDelegate.h + MRDPCursor.h + MRDPRailView.h + MRDPRailWindow.h + MRDPView.h + MRDPWindow.h + PasswordDialog.h) -# Source -file(GLOB ${MODULE_NAME}_SOURCES *.m) +set(${MODULE_NAME}_SOURCES + main.m + AppDelegate.m + MRDPCursor.m + MRDPRailView.m + MRDPRailWindow.m + MRDPView.m + MRDPWindow.m + PasswordDialog.m) add_executable(${MODULE_NAME} ${APP_TYPE} @@ -63,13 +77,6 @@ set_target_properties(${MODULE_NAME} PROPERTIES RESOURCE "${${MODULE_NAME}_RESOU # Support for automatic reference counting requires non-fragile abi. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fobjc-nonfragile-abi") -# XCode project architecture to native architecture of build machine -# ----------------------------------------------------------------------------------------------------- -# Issue: Had some issues with FreeRDP project building only 64 bit and -# MacFreeRDP attempting to link to both 32 and 64 for dual target. -# In the future the FreeRDP Xcode project should be pulled in for a couple of reasons: -# 1) better step-into debugging 2) automatic dependency compilation and multi-arch compilation + linkage -# If you know the solutions for 1 and 2, please add below. set_target_properties(${MODULE_NAME} PROPERTIES XCODE_ATTRIBUTE_ARCHS "$(NATIVE_ARCH_ACTUAL)") # Set the info plist to the custom instance diff --git a/client/Mac/MRDPRailView.m b/client/Mac/MRDPRailView.m index d5ed2e66d..b23c9c3e4 100644 --- a/client/Mac/MRDPRailView.m +++ b/client/Mac/MRDPRailView.m @@ -778,7 +778,7 @@ MRDPRailView* g_mrdpRailView; apple_to_windowMove(&r, &windowMove); windowMove.windowId = self->savedWindowId; - mac_send_rail_client_event(self->context->channels, RDP_EVENT_TYPE_RAIL_CLIENT_WINDOW_MOVE, &windowMove); + mac_send_rail_client_event(self->context->channels, RailChannel_ClientWindowMove, &windowMove); } /** @@ -800,7 +800,7 @@ MRDPRailView* g_mrdpRailView; apple_to_windowMove(&r, &windowMove); windowMove.windowId = self->savedWindowId; - mac_send_rail_client_event(self->context->channels, RDP_EVENT_TYPE_RAIL_CLIENT_WINDOW_MOVE, &windowMove); + mac_send_rail_client_event(self->context->channels, RailChannel_ClientWindowMove, &windowMove); } /** @@ -923,7 +923,7 @@ void mac_rail_send_activate(int window_id) activate.windowId = window_id; activate.enabled = 1; - mac_send_rail_client_event(g_mrdpRailView->context->channels, RDP_EVENT_TYPE_RAIL_CLIENT_ACTIVATE, &activate); + mac_send_rail_client_event(g_mrdpRailView->context->channels, RailChannel_ClientActivate, &activate); } @end diff --git a/client/Mac/MRDPView.h b/client/Mac/MRDPView.h index 5ac9fe298..c894cb939 100644 --- a/client/Mac/MRDPView.h +++ b/client/Mac/MRDPView.h @@ -111,7 +111,7 @@ void mf_Pointer_SetNull(rdpContext* context); void mf_Pointer_SetDefault(rdpContext* context); int rdp_connect(void); BOOL mac_pre_connect(freerdp* instance); -BOOL mac_post_connect(freerdp* instance); +BOOL mac_post_connect(freerdp* instance); BOOL mac_authenticate(freerdp* instance, char** username, char** password, char** domain); void mac_context_new(freerdp* instance, rdpContext* context); void mac_context_free(freerdp* instance, rdpContext* context); @@ -126,7 +126,7 @@ int register_fds(int* fds, int count, void* instance); int invoke_draw_rect(rdpContext* context); int process_plugin_args(rdpSettings* settings, const char* name, RDP_PLUGIN_DATA* plugin_data, void* user_data); int receive_channel_data(freerdp* instance, int chan_id, BYTE* data, int size, int flags, int total_size); -void process_cliprdr_event(freerdp* instance, RDP_EVENT* event); +void process_cliprdr_event(freerdp* instance, wMessage* event); void cliprdr_process_cb_format_list_event(freerdp* instance, RDP_CB_FORMAT_LIST_EVENT* event); void cliprdr_send_data_request(freerdp* instance, UINT32 format); void cliprdr_process_cb_monitor_ready_event(freerdp* inst); @@ -135,7 +135,7 @@ void cliprdr_process_text(freerdp* instance, BYTE* data, int len); void cliprdr_send_supported_format_list(freerdp* instance); int register_channel_fds(int* fds, int count, void* instance); -void mac_process_rail_event(freerdp* instance, RDP_EVENT* event); +void mac_process_rail_event(freerdp* instance, wMessage* event); void mac_rail_register_callbacks(freerdp* instance, rdpRail* rail); void mac_rail_CreateWindow(rdpRail* rail, rdpWindow* window); void mac_rail_MoveWindow(rdpRail* rail, rdpWindow* window); @@ -145,14 +145,14 @@ void mac_rail_SetWindowIcon(rdpRail* rail, rdpWindow* window, rdpIcon* icon); void mac_rail_SetWindowRects(rdpRail* rail, rdpWindow* window); void mac_rail_SetWindowVisibilityRects(rdpRail* rail, rdpWindow* window); void mac_rail_DestroyWindow(rdpRail* rail, rdpWindow* window); -void mac_process_rail_get_sysparams_event(rdpChannels* channels, RDP_EVENT* event); +void mac_process_rail_get_sysparams_event(rdpChannels* channels, wMessage* event); void mac_send_rail_client_event(rdpChannels* channels, UINT16 event_type, void* param); -void mac_on_free_rail_client_event(RDP_EVENT* event); -void mac_process_rail_server_sysparam_event(rdpChannels* channels, RDP_EVENT* event); -void mac_process_rail_exec_result_event(rdpChannels* channels, RDP_EVENT* event); +void mac_on_free_rail_client_event(wMessage* event); +void mac_process_rail_server_sysparam_event(rdpChannels* channels, wMessage* event); +void mac_process_rail_exec_result_event(rdpChannels* channels, wMessage* event); void mac_rail_enable_remoteapp_mode(void); -void mac_process_rail_server_minmaxinfo_event(rdpChannels* channels, RDP_EVENT* event); -void mac_process_rail_server_localmovesize_event(freerdp* instance, RDP_EVENT* event); +void mac_process_rail_server_minmaxinfo_event(rdpChannels* channels, wMessage* event); +void mac_process_rail_server_localmovesize_event(freerdp* instance, wMessage* event); void apple_center_window(NSRect* r); void apple_to_windowMove(NSRect* r, RAIL_WINDOW_MOVE_ORDER * windowMove); diff --git a/client/Mac/MRDPView.m b/client/Mac/MRDPView.m index e3cc554bb..db30f5830 100644 --- a/client/Mac/MRDPView.m +++ b/client/Mac/MRDPView.m @@ -1323,7 +1323,7 @@ void skt_activity_cb(CFSocketRef s, CFSocketCallBackType callbackType, void channel_activity_cb(CFSocketRef s, CFSocketCallBackType callbackType, CFDataRef address, const void* data, void* info) { - RDP_EVENT* event; + wMessage* event; freerdp* instance = (freerdp*) info; freerdp_channels_check_fds(instance->context->channels, instance); @@ -1331,13 +1331,13 @@ void channel_activity_cb(CFSocketRef s, CFSocketCallBackType callbackType, if (event) { - switch (event->event_class) + switch (GetMessageClass(event->id)) { - case RDP_EVENT_CLASS_RAIL: + case RailChannel_Class: mac_process_rail_event(instance, event); break; - case RDP_EVENT_CLASS_CLIPRDR: + case CliprdrChannel_Class: process_cliprdr_event(instance, event); break; } @@ -1432,7 +1432,7 @@ void cliprdr_process_cb_data_request_event(freerdp* instance) NSArray* types; RDP_CB_DATA_RESPONSE_EVENT* event; - event = (RDP_CB_DATA_RESPONSE_EVENT*) freerdp_event_new(RDP_EVENT_CLASS_CLIPRDR, RDP_EVENT_TYPE_CB_DATA_RESPONSE, NULL, NULL); + event = (RDP_CB_DATA_RESPONSE_EVENT*) freerdp_event_new(CliprdrChannel_Class, CliprdrChannel_DataResponse, NULL, NULL); types = [NSArray arrayWithObject:NSStringPboardType]; NSString* str = [g_mrdpview->pasteboard_rd availableTypeFromArray:types]; @@ -1451,17 +1451,17 @@ void cliprdr_process_cb_data_request_event(freerdp* instance) event->size = len; } - freerdp_channels_send_event(instance->context->channels, (RDP_EVENT*) event); + freerdp_channels_send_event(instance->context->channels, (wMessage*) event); } void cliprdr_send_data_request(freerdp* instance, UINT32 format) { RDP_CB_DATA_REQUEST_EVENT* event; - event = (RDP_CB_DATA_REQUEST_EVENT*) freerdp_event_new(RDP_EVENT_CLASS_CLIPRDR, RDP_EVENT_TYPE_CB_DATA_REQUEST, NULL, NULL); + event = (RDP_CB_DATA_REQUEST_EVENT*) freerdp_event_new(CliprdrChannel_Class, CliprdrChannel_DataRequest, NULL, NULL); event->format = format; - freerdp_channels_send_event(instance->context->channels, (RDP_EVENT*) event); + freerdp_channels_send_event(instance->context->channels, (wMessage*) event); } /** @@ -1489,10 +1489,10 @@ void cliprdr_process_cb_data_response_event(freerdp* instance, RDP_CB_DATA_RESPO void cliprdr_process_cb_monitor_ready_event(freerdp* instance) { - RDP_EVENT* event; + wMessage* event; RDP_CB_FORMAT_LIST_EVENT* format_list_event; - event = freerdp_event_new(RDP_EVENT_CLASS_CLIPRDR, RDP_EVENT_TYPE_CB_FORMAT_LIST, NULL, NULL); + event = freerdp_event_new(CliprdrChannel_Class, CliprdrChannel_FormatList, NULL, NULL); format_list_event = (RDP_CB_FORMAT_LIST_EVENT*) event; format_list_event->num_formats = 0; @@ -1551,18 +1551,18 @@ void cliprdr_process_cb_format_list_event(freerdp* instance, RDP_CB_FORMAT_LIST_ } } -void process_cliprdr_event(freerdp* instance, RDP_EVENT* event) +void process_cliprdr_event(freerdp* instance, wMessage* event) { if (event) { - switch (event->event_type) + switch (GetMessageType(event->id)) { /* * Monitor Ready PDU is sent by server to indicate that it has been * initialized and is ready. This PDU is transmitted by the server after it has sent * Clipboard Capabilities PDU */ - case RDP_EVENT_TYPE_CB_MONITOR_READY: + case CliprdrChannel_MonitorReady: cliprdr_process_cb_monitor_ready_event(instance); break; @@ -1572,7 +1572,7 @@ void process_cliprdr_event(freerdp* instance, RDP_EVENT* event) * contains the Clipboard Format ID and name pairs of the new Clipboard * Formats on the clipboard */ - case RDP_EVENT_TYPE_CB_FORMAT_LIST: + case CliprdrChannel_FormatList: cliprdr_process_cb_format_list_event(instance, (RDP_CB_FORMAT_LIST_EVENT*) event); break; @@ -1581,7 +1581,7 @@ void process_cliprdr_event(freerdp* instance, RDP_EVENT* event) * It is used to request the data for one of the formats that was listed in the * Format List PDU */ - case RDP_EVENT_TYPE_CB_DATA_REQUEST: + case CliprdrChannel_DataRequest: cliprdr_process_cb_data_request_event(instance); break; @@ -1591,12 +1591,12 @@ void process_cliprdr_event(freerdp* instance, RDP_EVENT* event) * was successful. If the processing was successful, the Format Data Response PDU * includes the contents of the requested clipboard data */ - case RDP_EVENT_TYPE_CB_DATA_RESPONSE: + case CliprdrChannel_DataResponse: cliprdr_process_cb_data_response_event(instance, (RDP_CB_DATA_RESPONSE_EVENT*) event); break; default: - printf("process_cliprdr_event: unknown event type %d\n", event->event_type); + printf("process_cliprdr_event: unknown event type %d\n", GetMessageType(event->id)); break; } @@ -1608,13 +1608,13 @@ void cliprdr_send_supported_format_list(freerdp* instance) { RDP_CB_FORMAT_LIST_EVENT* event; - event = (RDP_CB_FORMAT_LIST_EVENT*) freerdp_event_new(RDP_EVENT_CLASS_CLIPRDR, RDP_EVENT_TYPE_CB_FORMAT_LIST, NULL, NULL); + event = (RDP_CB_FORMAT_LIST_EVENT*) freerdp_event_new(CliprdrChannel_Class, CliprdrChannel_FormatList, NULL, NULL); event->formats = (UINT32*) malloc(sizeof(UINT32) * 1); event->num_formats = 1; event->formats[0] = CB_FORMAT_UNICODETEXT; - freerdp_channels_send_event(instance->context->channels, (RDP_EVENT*) event); + freerdp_channels_send_event(instance->context->channels, (wMessage*) event); } /**************************************************************************************** @@ -1625,35 +1625,35 @@ void cliprdr_send_supported_format_list(freerdp* instance) * * ****************************************************************************************/ -void mac_process_rail_event(freerdp* instance, RDP_EVENT* event) +void mac_process_rail_event(freerdp* instance, wMessage* event) { - switch (event->event_type) + switch (GetMessageType(event->id)) { - case RDP_EVENT_TYPE_RAIL_CHANNEL_GET_SYSPARAMS: + case RailChannel_GetSystemParam: mac_process_rail_get_sysparams_event(instance->context->channels, event); break; - case RDP_EVENT_TYPE_RAIL_CHANNEL_EXEC_RESULTS: + case RailChannel_ServerExecuteResult: mac_process_rail_exec_result_event(instance->context->channels, event); break; - case RDP_EVENT_TYPE_RAIL_CHANNEL_SERVER_SYSPARAM: + case RailChannel_ServerSystemParam: mac_process_rail_server_sysparam_event(instance->context->channels, event); break; - case RDP_EVENT_TYPE_RAIL_CHANNEL_SERVER_MINMAXINFO: + case RailChannel_ServerMinMaxInfo: mac_process_rail_server_minmaxinfo_event(instance->context->channels, event); break; - case RDP_EVENT_TYPE_RAIL_CHANNEL_SERVER_LOCALMOVESIZE: + case RailChannel_ServerLocalMoveSize: mac_process_rail_server_localmovesize_event(instance, event); break; - case RDP_EVENT_TYPE_RAIL_CHANNEL_APPID_RESP: + case RailChannel_ServerGetAppIdResponse: //xf_process_rail_appid_resp_event(xfi, channels, event); break; - case RDP_EVENT_TYPE_RAIL_CHANNEL_LANGBARINFO: + case RailChannel_ServerLanguageBarInfo: //xf_process_rail_langbarinfo_event(xfi, channels, event); break; } @@ -1715,7 +1715,7 @@ void mac_rail_CreateWindow(rdpRail* rail, rdpWindow* window) RAIL_WINDOW_MOVE_ORDER windowMove; apple_to_windowMove(&winFrame, &windowMove); windowMove.windowId = window->windowId; - mac_send_rail_client_event(g_mrdpview->rdp_instance->context->channels, RDP_EVENT_TYPE_RAIL_CLIENT_WINDOW_MOVE, &windowMove); + mac_send_rail_client_event(g_mrdpview->rdp_instance->context->channels, RailChannel_ClientWindowMove, &windowMove); } /* create MRDPRailView and add to above window */ @@ -1850,10 +1850,11 @@ void mac_rail_register_callbacks(freerdp* instance, rdpRail* rail) * by the system taskbar or by application desktop toolbars ************************************************************************/ -void mac_process_rail_get_sysparams_event(rdpChannels* channels, RDP_EVENT* event) +void mac_process_rail_get_sysparams_event(rdpChannels* channels, wMessage* event) { - RAIL_SYSPARAM_ORDER * sysparam; - sysparam = (RAIL_SYSPARAM_ORDER*) event->user_data; + RAIL_SYSPARAM_ORDER* sysparam; + + sysparam = (RAIL_SYSPARAM_ORDER*) event->wParam; sysparam->workArea.left = 0; sysparam->workArea.top = 22; @@ -1867,12 +1868,12 @@ void mac_process_rail_get_sysparams_event(rdpChannels* channels, RDP_EVENT* even sysparam->dragFullWindows = FALSE; - mac_send_rail_client_event(channels, RDP_EVENT_TYPE_RAIL_CLIENT_SET_SYSPARAMS, sysparam); + mac_send_rail_client_event(channels, RailChannel_ClientSystemParam, sysparam); } -void mac_process_rail_server_sysparam_event(rdpChannels* channels, RDP_EVENT* event) +void mac_process_rail_server_sysparam_event(rdpChannels* channels, wMessage* event) { - RAIL_SYSPARAM_ORDER* sysparam = (RAIL_SYSPARAM_ORDER*) event->user_data; + RAIL_SYSPARAM_ORDER* sysparam = (RAIL_SYSPARAM_ORDER*) event->wParam; switch (sysparam->param) { @@ -1888,11 +1889,11 @@ void mac_process_rail_server_sysparam_event(rdpChannels* channels, RDP_EVENT* ev * server returned result of exec'ing remote app on server ************************************************************************/ -void mac_process_rail_exec_result_event(rdpChannels* channels, RDP_EVENT* event) +void mac_process_rail_exec_result_event(rdpChannels* channels, wMessage* event) { RAIL_EXEC_RESULT_ORDER* exec_result; - exec_result = (RAIL_EXEC_RESULT_ORDER*) event->user_data; + exec_result = (RAIL_EXEC_RESULT_ORDER*) event->wParam; if (exec_result->execResult != RAIL_EXEC_S_OK) { @@ -1913,10 +1914,10 @@ void mac_process_rail_exec_result_event(rdpChannels* channels, RDP_EVENT* event) * to which the window can be moved or sized ************************************************************************/ -void mac_process_rail_server_minmaxinfo_event(rdpChannels* channels, RDP_EVENT* event) +void mac_process_rail_server_minmaxinfo_event(rdpChannels* channels, wMessage* event) { #if 0 - RAIL_MINMAXINFO_ORDER * minmax = (RAIL_MINMAXINFO_ORDER*) event->user_data; + RAIL_MINMAXINFO_ORDER * minmax = (RAIL_MINMAXINFO_ORDER*) event->wParam; printf("minmax_info: maxPosX=%d maxPosY=%d maxWidth=%d maxHeight=%d minTrackWidth=%d minTrackHeight=%d maxTrackWidth=%d maxTrackHeight=%d\n", minmax->maxPosX, minmax->maxPosY, minmax->maxWidth, minmax->maxHeight, minmax->minTrackWidth, minmax->minTrackHeight, minmax->maxTrackWidth, minmax->maxTrackHeight); @@ -1929,9 +1930,9 @@ void mac_process_rail_server_minmaxinfo_event(rdpChannels* channels, RDP_EVENT* * corresponding local window ************************************************************************/ -void mac_process_rail_server_localmovesize_event(freerdp* instance, RDP_EVENT *event) +void mac_process_rail_server_localmovesize_event(freerdp* instance, wMessage *event) { - RAIL_LOCALMOVESIZE_ORDER* moveSize = (RAIL_LOCALMOVESIZE_ORDER*) event->user_data; + RAIL_LOCALMOVESIZE_ORDER* moveSize = (RAIL_LOCALMOVESIZE_ORDER*) event->wParam; RAIL_WINDOW_MOVE_ORDER windowMove; switch (moveSize->moveSizeType) @@ -1983,7 +1984,7 @@ void mac_process_rail_server_localmovesize_event(freerdp* instance, RDP_EVENT *e [g_mrdpview->currentWindow view]->saveInitialDragLoc = NO; /* let RDP server know where this window is located */ - mac_send_rail_client_event(instance->context->channels, RDP_EVENT_TYPE_RAIL_CLIENT_WINDOW_MOVE, &windowMove); + mac_send_rail_client_event(instance->context->channels, RailChannel_ClientWindowMove, &windowMove); /* the event we just sent will cause an extra MoveWindow() to be invoked which we need to ignore */ [g_mrdpview->currentWindow view]->skipMoveWindowOnce = YES; @@ -2008,23 +2009,20 @@ void mac_process_rail_server_localmovesize_event(freerdp* instance, RDP_EVENT *e void mac_send_rail_client_event(rdpChannels* channels, UINT16 event_type, void* param) { void* payload = NULL; - RDP_EVENT* out_event = NULL; + wMessage* out_event = NULL; payload = rail_clone_order(event_type, param); if (payload) { - out_event = freerdp_event_new(RDP_EVENT_CLASS_RAIL, event_type, mac_on_free_rail_client_event, payload); + out_event = freerdp_event_new(RailChannel_Class, event_type, mac_on_free_rail_client_event, payload); freerdp_channels_send_event(channels, out_event); } } -void mac_on_free_rail_client_event(RDP_EVENT* event) +void mac_on_free_rail_client_event(wMessage* event) { - if (event->event_class == RDP_EVENT_CLASS_RAIL) - { - rail_free_cloned_order(event->event_type, event->user_data); - } + rail_free_cloned_order(GetMessageType(event->id), event->wParam); } void mac_rail_enable_remoteapp_mode() diff --git a/client/Sample/freerdp.c b/client/Sample/freerdp.c index 11155c2ea..1ad9cc673 100644 --- a/client/Sample/freerdp.c +++ b/client/Sample/freerdp.c @@ -100,10 +100,10 @@ int tf_receive_channel_data(freerdp* instance, int channelId, BYTE* data, int si void tf_process_cb_monitor_ready_event(rdpChannels* channels, freerdp* instance) { - RDP_EVENT* event; + wMessage* event; RDP_CB_FORMAT_LIST_EVENT* format_list_event; - event = freerdp_event_new(RDP_EVENT_CLASS_CLIPRDR, RDP_EVENT_TYPE_CB_FORMAT_LIST, NULL, NULL); + event = freerdp_event_new(CliprdrChannel_Class, CliprdrChannel_FormatList, NULL, NULL); format_list_event = (RDP_CB_FORMAT_LIST_EVENT*) event; format_list_event->num_formats = 0; @@ -113,19 +113,20 @@ void tf_process_cb_monitor_ready_event(rdpChannels* channels, freerdp* instance) void tf_process_channel_event(rdpChannels* channels, freerdp* instance) { - RDP_EVENT* event; + wMessage* event; event = freerdp_channels_pop_event(channels); if (event) { - switch (event->event_type) + switch (GetMessageType(event->id)) { - case RDP_EVENT_TYPE_CB_MONITOR_READY: + case CliprdrChannel_MonitorReady: tf_process_cb_monitor_ready_event(channels, instance); break; + default: - printf("tf_process_channel_event: unknown event type %d\n", event->event_type); + printf("tf_process_channel_event: unknown event type %d\n", GetMessageType(event->id)); break; } @@ -204,8 +205,8 @@ int tfreerdp_run(freerdp* instance) fd_set wfds_set; rdpChannels* channels; - memset(rfds, 0, sizeof(rfds)); - memset(wfds, 0, sizeof(wfds)); + ZeroMemory(rfds, sizeof(rfds)); + ZeroMemory(wfds, sizeof(wfds)); channels = instance->context->channels; diff --git a/client/Windows/CMakeLists.txt b/client/Windows/CMakeLists.txt index c006d1b00..0f2b26d65 100644 --- a/client/Windows/CMakeLists.txt +++ b/client/Windows/CMakeLists.txt @@ -37,14 +37,17 @@ set(${MODULE_PREFIX}_SRCS resource.h) if(WITH_CLIENT_INTERFACE) - add_library(${MODULE_NAME} ${${MODULE_PREFIX}_SRCS}) + if(CLIENT_INTERFACE_SHARED) + add_library(${MODULE_NAME} SHARED ${${MODULE_PREFIX}_SRCS}) + else() + add_library(${MODULE_NAME} ${${MODULE_PREFIX}_SRCS}) + endif() set_target_properties(${MODULE_NAME} PROPERTIES VERSION ${FREERDP_VERSION} SOVERSION ${FREERDP_API_VERSION} PREFIX "lib") else() set(${MODULE_PREFIX}_SRCS ${${MODULE_PREFIX}_SRCS} cli/wfreerdp.c cli/wfreerdp.h) add_executable(${MODULE_NAME} WIN32 ${${MODULE_PREFIX}_SRCS}) endif() - set(${MODULE_PREFIX}_LIBS ${${MODULE_PREFIX}_LIBS} freerdp-client) set_complex_link_libraries(VARIABLE ${MODULE_PREFIX}_LIBS diff --git a/client/Windows/cli/wfreerdp.c b/client/Windows/cli/wfreerdp.c index 00920d926..87601279f 100644 --- a/client/Windows/cli/wfreerdp.c +++ b/client/Windows/cli/wfreerdp.c @@ -47,11 +47,11 @@ INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine int status; wfInfo* wfi; - wf_global_init(); + freerdp_client_global_init(); - wfi = wf_new(hInstance, NULL, __argc, __argv); + wfi = freerdp_client_new(__argc, __argv); - status = wf_start(wfi); + status = freerdp_client_start(wfi); if (status < 0) { @@ -64,7 +64,7 @@ INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine WaitForSingleObject(wfi->thread, INFINITE); } - wf_free(wfi); + freerdp_client_free(wfi); return 0; } diff --git a/client/Windows/wf_cliprdr.c b/client/Windows/wf_cliprdr.c index 6b1213de1..cfaa2e21e 100644 --- a/client/Windows/wf_cliprdr.c +++ b/client/Windows/wf_cliprdr.c @@ -24,7 +24,7 @@ #include #include -#include +#include #include #include "wf_cliprdr.h" @@ -59,23 +59,23 @@ static void wf_cliprdr_process_cb_data_response_event(wfInfo* wfi, RDP_CB_DATA_R } -void wf_process_cliprdr_event(wfInfo* wfi, RDP_EVENT* event) +void wf_process_cliprdr_event(wfInfo* wfi, wMessage* event) { - switch (event->event_type) + switch (GetMessageType(event->id)) { - case RDP_EVENT_TYPE_CB_MONITOR_READY: + case CliprdrChannel_MonitorReady: wf_cliprdr_process_cb_monitor_ready_event(wfi); break; - case RDP_EVENT_TYPE_CB_FORMAT_LIST: + case CliprdrChannel_FormatList: wf_cliprdr_process_cb_format_list_event(wfi, (RDP_CB_FORMAT_LIST_EVENT*) event); break; - case RDP_EVENT_TYPE_CB_DATA_REQUEST: + case CliprdrChannel_DataRequest: wf_cliprdr_process_cb_data_request_event(wfi, (RDP_CB_DATA_REQUEST_EVENT*) event); break; - case RDP_EVENT_TYPE_CB_DATA_RESPONSE: + case CliprdrChannel_DataResponse: wf_cliprdr_process_cb_data_response_event(wfi, (RDP_CB_DATA_RESPONSE_EVENT*) event); break; diff --git a/client/Windows/wf_cliprdr.h b/client/Windows/wf_cliprdr.h index ed1f1bbea..2239a5d79 100644 --- a/client/Windows/wf_cliprdr.h +++ b/client/Windows/wf_cliprdr.h @@ -23,7 +23,7 @@ void wf_cliprdr_init(wfInfo* wfi, rdpChannels* chanman); void wf_cliprdr_uninit(wfInfo* wfi); -void wf_process_cliprdr_event(wfInfo* wfi, RDP_EVENT* event); +void wf_process_cliprdr_event(wfInfo* wfi, wMessage* event); BOOL wf_cliprdr_process_selection_notify(wfInfo* wfi, HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam); BOOL wf_cliprdr_process_selection_request(wfInfo* wfi, HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam); BOOL wf_cliprdr_process_selection_clear(wfInfo* wfi, HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam); diff --git a/client/Windows/wf_event.c b/client/Windows/wf_event.c index 881ca0178..c96897fb5 100644 --- a/client/Windows/wf_event.c +++ b/client/Windows/wf_event.c @@ -37,6 +37,9 @@ static HWND g_focus_hWnd; #define X_POS(lParam) (lParam & 0xFFFF) #define Y_POS(lParam) ((lParam >> 16) & 0xFFFF) +BOOL wf_scale_blt(wfInfo* wfi, HDC hdc, int x, int y, int w, int h, HDC hdcSrc, int x1, int y1, DWORD rop); +void wf_scale_mouse_event(wfInfo* wfi, rdpInput* input, UINT16 flags, UINT16 x, UINT16 y); + LRESULT CALLBACK wf_ll_kbd_proc(int nCode, WPARAM wParam, LPARAM lParam) { wfInfo* wfi; @@ -167,6 +170,10 @@ LRESULT CALLBACK wf_event_proc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam switch (Msg) { + case WM_ERASEBKGND: + /* Say we handled it - prevents flickering */ + return (LRESULT) 1; + case WM_PAINT: hdc = BeginPaint(hWnd, &ps); @@ -175,31 +182,29 @@ LRESULT CALLBACK wf_event_proc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam w = ps.rcPaint.right - ps.rcPaint.left + 1; h = ps.rcPaint.bottom - ps.rcPaint.top + 1; - //printf("WM_PAINT: x:%d y:%d w:%d h:%d\n", x, y, w, h); - - BitBlt(hdc, x, y, w, h, wfi->primary->hdc, x - wfi->offset_x, y - wfi->offset_y, SRCCOPY); + wf_scale_blt(wfi, hdc, x, y, w, h, wfi->primary->hdc, x - wfi->offset_x, y - wfi->offset_y, SRCCOPY); EndPaint(hWnd, &ps); break; case WM_LBUTTONDOWN: - input->MouseEvent(input, PTR_FLAGS_DOWN | PTR_FLAGS_BUTTON1, X_POS(lParam) - wfi->offset_x, Y_POS(lParam) - wfi->offset_y); + wf_scale_mouse_event(wfi, input,PTR_FLAGS_DOWN | PTR_FLAGS_BUTTON1, X_POS(lParam) - wfi->offset_x, Y_POS(lParam) - wfi->offset_y); break; case WM_LBUTTONUP: - input->MouseEvent(input, PTR_FLAGS_BUTTON1, X_POS(lParam) - wfi->offset_x, Y_POS(lParam) - wfi->offset_y); + wf_scale_mouse_event(wfi, input, PTR_FLAGS_BUTTON1, X_POS(lParam) - wfi->offset_x, Y_POS(lParam) - wfi->offset_y); break; case WM_RBUTTONDOWN: - input->MouseEvent(input, PTR_FLAGS_DOWN | PTR_FLAGS_BUTTON2, X_POS(lParam) - wfi->offset_x, Y_POS(lParam) - wfi->offset_y); + wf_scale_mouse_event(wfi, input, PTR_FLAGS_DOWN | PTR_FLAGS_BUTTON2, X_POS(lParam) - wfi->offset_x, Y_POS(lParam) - wfi->offset_y); break; case WM_RBUTTONUP: - input->MouseEvent(input, PTR_FLAGS_BUTTON2, X_POS(lParam) - wfi->offset_x, Y_POS(lParam) - wfi->offset_y); + wf_scale_mouse_event(wfi, input, PTR_FLAGS_BUTTON2, X_POS(lParam) - wfi->offset_x, Y_POS(lParam) - wfi->offset_y); break; case WM_MOUSEMOVE: - input->MouseEvent(input, PTR_FLAGS_MOVE, X_POS(lParam) - wfi->offset_x, Y_POS(lParam) - wfi->offset_y); + wf_scale_mouse_event(wfi, input, PTR_FLAGS_MOVE, X_POS(lParam) - wfi->offset_x, Y_POS(lParam) - wfi->offset_y); break; case WM_MOUSEWHEEL: @@ -257,3 +262,60 @@ LRESULT CALLBACK wf_event_proc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam return 0; } + +BOOL wf_scale_blt(wfInfo* wfi, HDC hdc, int x, int y, int w, int h, HDC hdcSrc, int x1, int y1, DWORD rop) +{ + int ww, wh, dw, dh; + + if (!wfi->client_width) + wfi->client_width = wfi->width; + + if (!wfi->client_height) + wfi->client_height = wfi->height; + + ww = wfi->client_width; + wh = wfi->client_height; + dw = wfi->instance->settings->DesktopWidth; + dh = wfi->instance->settings->DesktopHeight; + + if (!ww) + ww = dw; + + if (!wh) + wh = dh; + + if (!wfi->instance->settings->SmartSizing || (ww == dw && wh == dh)) + { + return BitBlt(hdc, x, y, w, h, wfi->primary->hdc, x1, y1, SRCCOPY); + } + else + { + SetStretchBltMode(hdc, HALFTONE); + SetBrushOrgEx(hdc, 0, 0, NULL); + + return StretchBlt(hdc, x * ww / dw, y * wh / dh, ww, wh, wfi->primary->hdc, x1, y1, dw, dh, SRCCOPY); + } + + return TRUE; +} + +void wf_scale_mouse_event(wfInfo* wfi, rdpInput* input, UINT16 flags, UINT16 x, UINT16 y) +{ + int ww, wh, dw, dh; + + if (!wfi->client_width) + wfi->client_width = wfi->width; + + if (!wfi->client_height) + wfi->client_height = wfi->height; + + ww = wfi->client_width; + wh = wfi->client_height; + dw = wfi->instance->settings->DesktopWidth; + dh = wfi->instance->settings->DesktopHeight; + + if ((ww == dw) && (wh == dh)) + input->MouseEvent(input, flags, x, y); + else + input->MouseEvent(input, flags, x * dw / ww, y * dh / wh); +} diff --git a/client/Windows/wf_gdi.c b/client/Windows/wf_gdi.c index a78c281e3..3a15fe26a 100644 --- a/client/Windows/wf_gdi.c +++ b/client/Windows/wf_gdi.c @@ -62,7 +62,7 @@ BOOL wf_set_rop2(HDC hdc, int rop2) { if ((rop2 < 0x01) || (rop2 > 0x10)) { - printf("Unsupported ROP2: %d\n", rop2); + fprintf(stderr, "Unsupported ROP2: %d\n", rop2); return FALSE; } @@ -166,14 +166,54 @@ HBRUSH wf_create_brush(wfInfo * wfi, rdpBrush* brush, UINT32 color, int bpp) return br; } +void wf_scale_rect(wfInfo* wfi, RECT* source) +{ + int ww, wh, dw, dh; + + if (!wfi->client_width) + wfi->client_width = wfi->width; + + if (!wfi->client_height) + wfi->client_height = wfi->height; + + ww = wfi->client_width; + wh = wfi->client_height; + dw = wfi->instance->settings->DesktopWidth; + dh = wfi->instance->settings->DesktopHeight; + + if (!ww) + ww = dw; + + if (!wh) + wh = dh; + + if (wfi->instance->settings->SmartSizing && (ww != dw || wh != dh)) + { + source->bottom = MIN(dh, MAX(0, source->bottom * wh / dh + 2)); + source->top = MIN(dh, MAX(0, source->top * wh / dh - 2)); + source->left = MIN(dw, MAX(0, source->left * ww / dw - 2)); + source->right = MIN(dw, MAX(0, source->right * ww / dw + 2)); + } +} + void wf_invalidate_region(wfInfo* wfi, int x, int y, int width, int height) { + RECT rect; + wfi->update_rect.left = x + wfi->offset_x; wfi->update_rect.top = y + wfi->offset_y; wfi->update_rect.right = wfi->update_rect.left + width; wfi->update_rect.bottom = wfi->update_rect.top + height; + + wf_scale_rect(wfi, &(wfi->update_rect)); InvalidateRect(wfi->hwnd, &(wfi->update_rect), FALSE); - gdi_InvalidateRegion(wfi->hdc, x, y, width, height); + + rect.left = x; + rect.right = width; + rect.top = y; + rect.bottom = height; + wf_scale_rect(wfi, &rect); + gdi_InvalidateRegion(wfi->hdc, rect.left, rect.top, rect.right, rect.bottom); } void wf_update_offset(wfInfo* wfi) @@ -201,17 +241,38 @@ void wf_resize_window(wfInfo* wfi) SetWindowLongPtr(wfi->hwnd, GWL_STYLE, WS_POPUP); SetWindowPos(wfi->hwnd, HWND_TOP, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN), SWP_FRAMECHANGED); } + else if (!wfi->instance->settings->Decorations) + { + RECT rc_wnd; + RECT rc_client; + + SetWindowLongPtr(wfi->hwnd, GWL_STYLE, WS_CHILD); + + /* Now resize to get full canvas size and room for caption and borders */ + SetWindowPos(wfi->hwnd, HWND_TOP, 0, 0, wfi->width, wfi->height, SWP_FRAMECHANGED); + GetClientRect(wfi->hwnd, &rc_client); + GetWindowRect(wfi->hwnd, &rc_wnd); + + wfi->diff.x = (rc_wnd.right - rc_wnd.left) - rc_client.right; + wfi->diff.y = (rc_wnd.bottom - rc_wnd.top) - rc_client.bottom; + + SetWindowPos(wfi->hwnd, HWND_TOP, -1, -1, wfi->width + wfi->diff.x, wfi->height + wfi->diff.y, SWP_NOMOVE | SWP_FRAMECHANGED); + } else { - RECT rc_client, rc_wnd; + RECT rc_wnd; + RECT rc_client; SetWindowLongPtr(wfi->hwnd, GWL_STYLE, WS_CAPTION | WS_OVERLAPPED | WS_SYSMENU | WS_MINIMIZEBOX); + /* Now resize to get full canvas size and room for caption and borders */ SetWindowPos(wfi->hwnd, HWND_TOP, 10, 10, wfi->width, wfi->height, SWP_FRAMECHANGED); GetClientRect(wfi->hwnd, &rc_client); GetWindowRect(wfi->hwnd, &rc_wnd); + wfi->diff.x = (rc_wnd.right - rc_wnd.left) - rc_client.right; wfi->diff.y = (rc_wnd.bottom - rc_wnd.top) - rc_client.bottom; + SetWindowPos(wfi->hwnd, HWND_TOP, -1, -1, wfi->width + wfi->diff.x, wfi->height + wfi->diff.y, SWP_NOMOVE | SWP_FRAMECHANGED); } wf_update_offset(wfi); @@ -537,7 +598,7 @@ void wf_gdi_surface_bits(rdpContext* context, SURFACE_BITS_COMMAND* surface_bits } else { - printf("Unsupported codecID %d\n", surface_bits_command->codecID); + fprintf(stderr, "Unsupported codecID %d\n", surface_bits_command->codecID); } if (tile_bitmap != NULL) diff --git a/client/Windows/wf_graphics.c b/client/Windows/wf_graphics.c index 50714952d..9a7937215 100644 --- a/client/Windows/wf_graphics.c +++ b/client/Windows/wf_graphics.c @@ -161,7 +161,7 @@ void wf_Bitmap_Decompress(rdpContext* context, rdpBitmap* bitmap, if (status != TRUE) { - printf("Bitmap Decompression Failed\n"); + fprintf(stderr, "Bitmap Decompression Failed\n"); } } else diff --git a/client/Windows/wf_interface.c b/client/Windows/wf_interface.c index 87dbb73e6..09c465e88 100644 --- a/client/Windows/wf_interface.c +++ b/client/Windows/wf_interface.c @@ -84,7 +84,7 @@ int wf_create_console(void) return 1; freopen("CONOUT$", "w", stdout); - printf("Debug console created.\n"); + fprintf(stderr, "Debug console created.\n"); return 0; } @@ -222,7 +222,7 @@ BOOL wf_pre_connect(freerdp* instance) { file = freerdp_client_rdp_file_new(); - printf("Using connection file: %s\n", settings->ConnectionFile); + fprintf(stderr, "Using connection file: %s\n", settings->ConnectionFile); freerdp_client_parse_rdp_file(file, settings->ConnectionFile); freerdp_client_populate_settings_from_rdp_file(file, settings); @@ -291,7 +291,7 @@ BOOL wf_pre_connect(freerdp* instance) if ((settings->DesktopWidth < 64) || (settings->DesktopHeight < 64) || (settings->DesktopWidth > 4096) || (settings->DesktopHeight > 4096)) { - printf("wf_pre_connect: invalid dimensions %d %d\n", settings->DesktopWidth, settings->DesktopHeight); + fprintf(stderr, "wf_pre_connect: invalid dimensions %d %d\n", settings->DesktopWidth, settings->DesktopHeight); return 1; } @@ -305,6 +305,7 @@ BOOL wf_post_connect(freerdp* instance) { rdpGdi* gdi; wfInfo* wfi; + DWORD dwStyle; rdpCache* cache; wfContext* context; WCHAR lpWindowName[64]; @@ -366,10 +367,15 @@ BOOL wf_post_connect(freerdp* instance) else _snwprintf(lpWindowName, ARRAYSIZE(lpWindowName), L"FreeRDP: %S:%d", settings->ServerHostname, settings->ServerPort); + if (!settings->Decorations) + dwStyle = WS_CHILD | WS_BORDER; + else + dwStyle = 0; + if (!wfi->hwnd) { - wfi->hwnd = CreateWindowEx((DWORD) NULL, wfi->wndClassName, lpWindowName, - 0, 0, 0, 0, 0, wfi->hWndParent, NULL, wfi->hInstance, NULL); + wfi->hwnd = CreateWindowEx((DWORD) NULL, wfi->wndClassName, lpWindowName, dwStyle, + 0, 0, 0, 0, wfi->hWndParent, NULL, wfi->hInstance, NULL); SetWindowLongPtr(wfi->hwnd, GWLP_USERDATA, (LONG_PTR) wfi); } @@ -445,7 +451,7 @@ BOOL wf_authenticate(freerdp* instance, char** username, char** password, char** if (status != NO_ERROR) { - printf("CredUIPromptForCredentials unexpected status: 0x%08X\n", status); + fprintf(stderr, "CredUIPromptForCredentials unexpected status: 0x%08X\n", status); return FALSE; } @@ -454,7 +460,7 @@ BOOL wf_authenticate(freerdp* instance, char** username, char** password, char** status = CredUIParseUserNameA(UserName, User, sizeof(User), Domain, sizeof(Domain)); - //printf("User: %s Domain: %s Password: %s\n", User, Domain, Password); + //fprintf(stderr, "User: %s Domain: %s Password: %s\n", User, Domain, Password); *username = _strdup(User); @@ -504,7 +510,7 @@ int wf_receive_channel_data(freerdp* instance, int channelId, BYTE* data, int si void wf_process_channel_event(rdpChannels* channels, freerdp* instance) { - RDP_EVENT* event; + wMessage* event; event = freerdp_channels_pop_event(channels); @@ -528,6 +534,8 @@ DWORD WINAPI wf_thread(LPVOID lpParam) int index; int rcount; int wcount; + int width; + int height; BOOL msg_ret; int quit_msg; void* rfds[32]; @@ -554,17 +562,17 @@ DWORD WINAPI wf_thread(LPVOID lpParam) if (freerdp_get_fds(instance, rfds, &rcount, wfds, &wcount) != TRUE) { - printf("Failed to get FreeRDP file descriptor\n"); + fprintf(stderr, "Failed to get FreeRDP file descriptor\n"); break; } if (wf_get_fds(instance, rfds, &rcount, wfds, &wcount) != TRUE) { - printf("Failed to get wfreerdp file descriptor\n"); + fprintf(stderr, "Failed to get wfreerdp file descriptor\n"); break; } if (freerdp_channels_get_fds(channels, instance, rfds, &rcount, wfds, &wcount) != TRUE) { - printf("Failed to get channel manager file descriptor\n"); + fprintf(stderr, "Failed to get channel manager file descriptor\n"); break; } @@ -582,20 +590,20 @@ DWORD WINAPI wf_thread(LPVOID lpParam) /* exit if nothing to do */ if (fds_count == 0) { - printf("wfreerdp_run: fds_count is zero\n"); + fprintf(stderr, "wfreerdp_run: fds_count is zero\n"); break; } /* do the wait */ if (MsgWaitForMultipleObjects(fds_count, fds, FALSE, 1000, QS_ALLINPUT) == WAIT_FAILED) { - printf("wfreerdp_run: WaitForMultipleObjects failed: 0x%04X\n", GetLastError()); + fprintf(stderr, "wfreerdp_run: WaitForMultipleObjects failed: 0x%04X\n", GetLastError()); break; } if (freerdp_check_fds(instance) != TRUE) { - printf("Failed to check FreeRDP file descriptor\n"); + fprintf(stderr, "Failed to check FreeRDP file descriptor\n"); break; } if (freerdp_shall_disconnect(instance)) @@ -604,12 +612,12 @@ DWORD WINAPI wf_thread(LPVOID lpParam) } if (wf_check_fds(instance) != TRUE) { - printf("Failed to check wfreerdp file descriptor\n"); + fprintf(stderr, "Failed to check wfreerdp file descriptor\n"); break; } if (freerdp_channels_check_fds(channels, instance) != TRUE) { - printf("Failed to check channel manager file descriptor\n"); + fprintf(stderr, "Failed to check channel manager file descriptor\n"); break; } wf_process_channel_event(channels, instance); @@ -620,7 +628,30 @@ DWORD WINAPI wf_thread(LPVOID lpParam) { msg_ret = GetMessage(&msg, NULL, 0, 0); - if (msg_ret == 0 || msg_ret == -1) + if (instance->settings->EmbeddedWindow) + { + if ((msg.message == WM_SETFOCUS) && (msg.lParam == 1)) + { + PostMessage(((wfContext*) instance->context)->wfi->hwnd, WM_SETFOCUS, 0, 0); + } + else if ((msg.message == WM_KILLFOCUS) && (msg.lParam == 1)) + { + PostMessage(((wfContext*) instance->context)->wfi->hwnd, WM_KILLFOCUS, 0, 0); + } + } + + if (msg.message == WM_SIZE) + { + width = LOWORD(msg.lParam); + height = HIWORD(msg.lParam); + + ((wfContext*) instance->context)->wfi->client_width = width; + ((wfContext*) instance->context)->wfi->client_height = height; + + SetWindowPos(((wfContext*) instance->context)->wfi->hwnd, HWND_TOP, 0, 0, width, height, SWP_FRAMECHANGED); + } + + if ((msg_ret == 0) || (msg_ret == -1)) { quit_msg = TRUE; break; @@ -659,7 +690,7 @@ DWORD WINAPI wf_keyboard_thread(LPVOID lpParam) { if (status == -1) { - printf("keyboard thread error getting message\n"); + fprintf(stderr, "keyboard thread error getting message\n"); break; } else @@ -673,13 +704,13 @@ DWORD WINAPI wf_keyboard_thread(LPVOID lpParam) } else { - printf("failed to install keyboard hook\n"); + fprintf(stderr, "failed to install keyboard hook\n"); } return (DWORD) NULL; } -int wf_global_init() +int freerdp_client_global_init() { WSADATA wsaData; @@ -705,21 +736,20 @@ int wf_global_init() return 0; } -int wf_global_uninit() +int freerdp_client_global_uninit() { WSACleanup(); return 0; } -wfInfo* wf_new(HINSTANCE hInstance, HWND hWndParent, int argc, char** argv) +wfInfo* freerdp_client_new(int argc, char** argv) { + int index; + int status; wfInfo* wfi; freerdp* instance; - if (!hInstance) - hInstance = GetModuleHandle(NULL); - instance = freerdp_new(); instance->PreConnect = wf_pre_connect; instance->PostConnect = wf_post_connect; @@ -733,10 +763,30 @@ wfInfo* wf_new(HINSTANCE hInstance, HWND hWndParent, int argc, char** argv) freerdp_context_new(instance); wfi = ((wfContext*) (instance->context))->wfi; + wfi->instance = instance; + wfi->client = instance->context->client; instance->context->argc = argc; - instance->context->argv = argv; + instance->context->argv = (char**) malloc(sizeof(char*) * argc); + + for (index = 0; index < argc; index++) + instance->context->argv[index] = _strdup(argv[index]); + + status = freerdp_client_parse_command_line_arguments(instance->context->argc, instance->context->argv, instance->settings); + + return wfi; +} + +int freerdp_client_start(wfInfo* wfi) +{ + HWND hWndParent; + HINSTANCE hInstance; + freerdp* instance = wfi->instance; + + hInstance = GetModuleHandle(NULL); + hWndParent = (HWND) instance->settings->ParentWindowId; + instance->settings->EmbeddedWindow = (hWndParent) ? TRUE : FALSE; wfi->hWndParent = hWndParent; wfi->hInstance = hInstance; @@ -758,24 +808,14 @@ wfInfo* wf_new(HINSTANCE hInstance, HWND hWndParent, int argc, char** argv) wfi->wndClass.hIconSm = wfi->icon; RegisterClassEx(&(wfi->wndClass)); - return wfi; -} - -int wf_start(wfInfo* wfi) -{ - int status; - freerdp* instance = wfi->instance; - wfi->keyboardThread = CreateThread(NULL, 0, wf_keyboard_thread, (void*) wfi, 0, NULL); if (!wfi->keyboardThread) return -1; - status = freerdp_client_parse_command_line_arguments(instance->context->argc, instance->context->argv, instance->settings); - freerdp_client_load_addins(instance->context->channels, instance->settings); - wfi->thread = CreateThread(NULL, 0, wf_thread, (void*) instance, 0, NULL); + wfi->thread = CreateThread(NULL, 0, wf_thread, (void*) instance, 0, &wfi->mainThreadId); if (!wfi->thread) return -1; @@ -783,12 +823,35 @@ int wf_start(wfInfo* wfi) return 0; } -int wf_stop(wfInfo* wfi) +int freerdp_client_stop(wfInfo* wfi) { + PostThreadMessage(wfi->mainThreadId, WM_QUIT, 0, 0); return 0; } -int wf_free(wfInfo* wfi) +int freerdp_client_focus_in(wfInfo* wfi) +{ + PostThreadMessage(wfi->mainThreadId, WM_SETFOCUS, 0, 1); + return 0; +} + +int freerdp_client_focus_out(wfInfo* wfi) +{ + PostThreadMessage(wfi->mainThreadId, WM_KILLFOCUS, 0, 1); + return 0; +} + +int wf_set_window_size(wfInfo* wfi, int width, int height) +{ + if ((width != wfi->client_width) || (height != wfi->client_height)) + { + PostThreadMessage(wfi->mainThreadId, WM_SIZE, SIZE_RESTORED, ((UINT) height << 16) | (UINT) width); + } + + return 0; +} + +int freerdp_client_free(wfInfo* wfi) { freerdp* instance = wfi->instance; diff --git a/client/Windows/wf_interface.h b/client/Windows/wf_interface.h index 44d47f783..16891db82 100644 --- a/client/Windows/wf_interface.h +++ b/client/Windows/wf_interface.h @@ -38,6 +38,10 @@ #include "wf_event.h" +#ifdef __cplusplus +extern "C" { +#endif + struct wf_bitmap { rdpBitmap _bitmap; @@ -67,6 +71,8 @@ typedef struct wf_context wfContext; struct wf_info { + rdpClient* client; + int width; int height; int offset_x; @@ -75,6 +81,8 @@ struct wf_info int fullscreen; int percentscreen; char window_title[64]; + int client_width; + int client_height; HANDLE thread; HANDLE keyboardThread; @@ -99,21 +107,38 @@ struct wf_info HBRUSH brush; HBRUSH org_brush; RECT update_rect; + RECT scale_update_rect; wfBitmap* tile; + DWORD mainThreadId; RFX_CONTEXT* rfx_context; NSC_CONTEXT* nsc_context; BOOL sw_gdi; }; -FREERDP_API int wf_global_init(); -FREERDP_API int wf_global_uninit(); +/** + * Client Interface + */ -FREERDP_API int wf_start(wfInfo* wfi); -FREERDP_API int wf_stop(wfInfo* wfi); +#define cfInfo wfInfo -FREERDP_API wfInfo* wf_new(HINSTANCE hInstance, HWND hWndParent, int argc, char** argv); -FREERDP_API int wf_free(wfInfo* wfi); +FREERDP_API int freerdp_client_global_init(); +FREERDP_API int freerdp_client_global_uninit(); + +FREERDP_API int freerdp_client_start(wfInfo* cfi); +FREERDP_API int freerdp_client_stop(wfInfo* cfi); + +FREERDP_API int freerdp_client_focus_in(wfInfo* cfi); +FREERDP_API int freerdp_client_focus_out(wfInfo* cfi); + +FREERDP_API int freerdp_client_set_window_size(wfInfo* cfi, int width, int height); + +FREERDP_API cfInfo* freerdp_client_new(int argc, char** argv); +FREERDP_API int freerdp_client_free(wfInfo* cfi); + +#ifdef __cplusplus +} +#endif #endif diff --git a/client/Windows/wf_rail.c b/client/Windows/wf_rail.c index 9e2741097..5cc3c09fe 100644 --- a/client/Windows/wf_rail.c +++ b/client/Windows/wf_rail.c @@ -45,7 +45,7 @@ void wf_rail_send_activate(wfInfo* wfi, HWND window, BOOL enabled) { } -void wf_process_rail_event(wfInfo* wfi, rdpChannels* chanman, RDP_EVENT* event) +void wf_process_rail_event(wfInfo* wfi, rdpChannels* chanman, wMessage* event) { } diff --git a/client/Windows/wf_rail.h b/client/Windows/wf_rail.h index 1ea164f60..171733706 100644 --- a/client/Windows/wf_rail.h +++ b/client/Windows/wf_rail.h @@ -25,7 +25,7 @@ void wf_rail_paint(wfInfo* wfi, rdpRail* rail, INT32 uleft, INT32 utop, UINT32 u void wf_rail_register_callbacks(wfInfo* wfi, rdpRail* rail); void wf_rail_send_client_system_command(wfInfo* wfi, UINT32 windowId, UINT16 command); void wf_rail_send_activate(wfInfo* wfi, HWND window, BOOL enabled); -void wf_process_rail_event(wfInfo* wfi, rdpChannels* chanman, RDP_EVENT* event); +void wf_process_rail_event(wfInfo* wfi, rdpChannels* chanman, wMessage* event); void wf_rail_adjust_position(wfInfo* wfi, rdpWindow *window); void wf_rail_end_local_move(wfInfo* wfi, rdpWindow *window); diff --git a/client/X11/CMakeLists.txt b/client/X11/CMakeLists.txt index 735ebeb00..7d08ea670 100644 --- a/client/X11/CMakeLists.txt +++ b/client/X11/CMakeLists.txt @@ -15,8 +15,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -set(MODULE_NAME "xfreerdp") -set(MODULE_PREFIX "FREERDP_CLIENT_X11") +set(MODULE_NAME "xfreerdp-client") +set(MODULE_PREFIX "FREERDP_CLIENT_X11_CONTROL") include(FindXmlto) include_directories(${X11_INCLUDE_DIRS}) @@ -40,10 +40,20 @@ set(${MODULE_PREFIX}_SRCS xf_keyboard.h xf_window.c xf_window.h - xfreerdp.c - xfreerdp.h) + xf_interface.c + xf_interface.h) -add_executable(${MODULE_NAME} ${${MODULE_PREFIX}_SRCS}) +if(WITH_CLIENT_INTERFACE) + if(CLIENT_INTERFACE_SHARED) + add_library(${MODULE_NAME} SHARED ${${MODULE_PREFIX}_SRCS}) + else() + add_library(${MODULE_NAME} ${${MODULE_PREFIX}_SRCS}) + endif() + set_target_properties(${MODULE_NAME} PROPERTIES VERSION ${FREERDP_VERSION} SOVERSION ${FREERDP_API_VERSION} PREFIX "lib") +else() + set(${MODULE_PREFIX}_SRCS ${${MODULE_PREFIX}_SRCS} cli/xfreerdp.c cli/xfreerdp.h) + add_executable(${MODULE_NAME} ${${MODULE_PREFIX}_SRCS}) +endif() set(${MODULE_PREFIX}_LIBS ${X11_LIBRARIES} @@ -128,6 +138,12 @@ if(WITH_IPP) target_link_libraries(xfreerdp ${IPP_LIBRARY_LIST}) endif() -install(TARGETS ${MODULE_NAME} DESTINATION ${CMAKE_INSTALL_BINDIR}) +if(WITH_CLIENT_INTERFACE) + install(TARGETS ${MODULE_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT libraries) + add_subdirectory(cli) +else() + install(TARGETS ${MODULE_NAME} DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT client) +endif() set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "Client/X11") + diff --git a/client/X11/cli/.gitignore b/client/X11/cli/.gitignore new file mode 100644 index 000000000..6ddebc647 --- /dev/null +++ b/client/X11/cli/.gitignore @@ -0,0 +1,2 @@ +xfreerdp + diff --git a/client/X11/cli/CMakeLists.txt b/client/X11/cli/CMakeLists.txt new file mode 100644 index 000000000..b4d27b5d7 --- /dev/null +++ b/client/X11/cli/CMakeLists.txt @@ -0,0 +1,36 @@ +# FreeRDP: A Remote Desktop Protocol Implementation +# FreeRDP X11 cmake build script +# +# Copyright 2012 Marc-Andre Moreau +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set(MODULE_NAME "xfreerdp") +set(MODULE_PREFIX "FREERDP_CLIENT_X11") + +include_directories(..) + +set(${MODULE_PREFIX}_SRCS + xfreerdp.c + xfreerdp.h) + +add_executable(${MODULE_NAME} ${${MODULE_PREFIX}_SRCS}) + +set(${MODULE_PREFIX}_LIBS ${${MODULE_PREFIX}_LIBS} xfreerdp-client) + +target_link_libraries(${MODULE_NAME} ${${MODULE_PREFIX}_LIBS}) + +install(TARGETS ${MODULE_NAME} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT client) + +set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "Client/X11") + diff --git a/libfreerdp/utils/string.c b/client/X11/cli/xfreerdp.c similarity index 52% rename from libfreerdp/utils/string.c rename to client/X11/cli/xfreerdp.c index 09d426f03..0fa20b98b 100644 --- a/libfreerdp/utils/string.c +++ b/client/X11/cli/xfreerdp.c @@ -1,8 +1,9 @@ /** * FreeRDP: A Remote Desktop Protocol Implementation - * String Utils + * X11 Client * * Copyright 2011 Marc-Andre Moreau + * Copyright 2012 HP Development Company, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,33 +22,42 @@ #include "config.h" #endif -#include -#include -#include - #include +#include +#include -#include +#include -BOOL freerdp_string_read_length32(STREAM* s, rdpString* string) +#include "xf_interface.h" + +#include "xfreerdp.h" + +int main(int argc, char* argv[]) { - if(stream_get_left(s) < 4) - return FALSE; - stream_read_UINT32(s, string->length); - if(stream_get_left(s) < string->length) - return FALSE; - string->unicode = (char*) malloc(string->length); - stream_read(s, string->unicode, string->length); + xfInfo* xfi; + DWORD dwExitCode; + freerdp* instance; - ConvertFromUnicode(CP_UTF8, 0, (WCHAR*) string->unicode, string->length / 2, &string->ascii, 0, NULL, NULL); - return TRUE; -} - -void freerdp_string_free(rdpString* string) -{ - if (string->unicode != NULL) - free(string->unicode); - - if (string->ascii != NULL) - free(string->ascii); + freerdp_client_global_init(); + + xfi = freerdp_client_new(argc, argv); + + if (xfi == NULL) + { + return 1; + } + + instance = xfi->instance; + + freerdp_client_start(xfi); + + WaitForSingleObject(xfi->thread, INFINITE); + + GetExitCodeThread(xfi->thread, &dwExitCode); + + freerdp_client_free(xfi); + + freerdp_client_global_uninit(); + + return xf_exit_code_from_disconnect_reason(dwExitCode); } diff --git a/include/freerdp/utils/string.h b/client/X11/cli/xfreerdp.h similarity index 57% rename from include/freerdp/utils/string.h rename to client/X11/cli/xfreerdp.h index 4c3e2d9d3..c8e4780a6 100644 --- a/include/freerdp/utils/string.h +++ b/client/X11/cli/xfreerdp.h @@ -1,6 +1,6 @@ /** * FreeRDP: A Remote Desktop Protocol Implementation - * String Utils + * X11 Client * * Copyright 2011 Marc-Andre Moreau * @@ -17,30 +17,9 @@ * limitations under the License. */ -#ifndef FREERDP_UTILS_STRING_H -#define FREERDP_UTILS_STRING_H +#ifndef __XFREERDP_H +#define __XFREERDP_H -#include -#include -#include -struct rdp_string -{ - char* ascii; - char* unicode; - UINT32 length; -}; -typedef struct rdp_string rdpString; -#ifdef __cplusplus -extern "C" { -#endif - -FREERDP_API BOOL freerdp_string_read_length32(STREAM* s, rdpString* string); -FREERDP_API void freerdp_string_free(rdpString* string); - -#ifdef __cplusplus -} -#endif - -#endif /* FREERDP_UTILS_STRING_H */ +#endif /* __XFREERDP_H */ diff --git a/client/X11/xf_cliprdr.c b/client/X11/xf_cliprdr.c index 13ae748b1..c2acee2ac 100644 --- a/client/X11/xf_cliprdr.c +++ b/client/X11/xf_cliprdr.c @@ -26,13 +26,25 @@ #include #include +#include #include -#include #include #include "xf_cliprdr.h" +#ifdef WITH_DEBUG_X11 +#define DEBUG_X11(fmt, ...) DEBUG_CLASS(X11, fmt, ## __VA_ARGS__) +#else +#define DEBUG_X11(fmt, ...) DEBUG_NULL(fmt, ## __VA_ARGS__) +#endif + +#ifdef WITH_DEBUG_X11_CLIPRDR +#define DEBUG_X11_CLIPRDR(fmt, ...) DEBUG_CLASS(X11_CLIPRDR, fmt, ## __VA_ARGS__) +#else +#define DEBUG_X11_CLIPRDR(fmt, ...) DEBUG_NULL(fmt, ## __VA_ARGS__) +#endif + typedef struct clipboard_format_mapping clipboardFormatMapping; struct clipboard_format_mapping @@ -329,15 +341,15 @@ static void xf_cliprdr_send_raw_format_list(xfInfo* xfi) } DEBUG_X11_CLIPRDR("format=%d len=%d bytes_left=%d", format, (int) length, (int) bytes_left); - event = (RDP_CB_FORMAT_LIST_EVENT*) freerdp_event_new(RDP_EVENT_CLASS_CLIPRDR, - RDP_EVENT_TYPE_CB_FORMAT_LIST, NULL, NULL); + event = (RDP_CB_FORMAT_LIST_EVENT*) freerdp_event_new(CliprdrChannel_Class, + CliprdrChannel_FormatList, NULL, NULL); event->raw_format_data = (BYTE*) malloc(length); - memcpy(event->raw_format_data, format_data, length); + CopyMemory(event->raw_format_data, format_data, length); event->raw_format_data_size = length; XFree(format_data); - freerdp_channels_send_event(cb->channels, (RDP_EVENT*) event); + freerdp_channels_send_event(cb->channels, (wMessage*) event); } static void xf_cliprdr_send_null_format_list(xfInfo* xfi) @@ -345,12 +357,12 @@ static void xf_cliprdr_send_null_format_list(xfInfo* xfi) RDP_CB_FORMAT_LIST_EVENT* event; clipboardContext* cb = (clipboardContext*) xfi->clipboard_context; - event = (RDP_CB_FORMAT_LIST_EVENT*) freerdp_event_new(RDP_EVENT_CLASS_CLIPRDR, - RDP_EVENT_TYPE_CB_FORMAT_LIST, NULL, NULL); + event = (RDP_CB_FORMAT_LIST_EVENT*) freerdp_event_new(CliprdrChannel_Class, + CliprdrChannel_FormatList, NULL, NULL); event->num_formats = 0; - freerdp_channels_send_event(cb->channels, (RDP_EVENT*) event); + freerdp_channels_send_event(cb->channels, (wMessage*) event); } static void xf_cliprdr_send_supported_format_list(xfInfo* xfi) @@ -359,8 +371,8 @@ static void xf_cliprdr_send_supported_format_list(xfInfo* xfi) RDP_CB_FORMAT_LIST_EVENT* event; clipboardContext* cb = (clipboardContext*) xfi->clipboard_context; - event = (RDP_CB_FORMAT_LIST_EVENT*) freerdp_event_new(RDP_EVENT_CLASS_CLIPRDR, - RDP_EVENT_TYPE_CB_FORMAT_LIST, NULL, NULL); + event = (RDP_CB_FORMAT_LIST_EVENT*) freerdp_event_new(CliprdrChannel_Class, + CliprdrChannel_FormatList, NULL, NULL); event->formats = (UINT32*) malloc(sizeof(UINT32) * cb->num_format_mappings); event->num_formats = cb->num_format_mappings; @@ -368,7 +380,7 @@ static void xf_cliprdr_send_supported_format_list(xfInfo* xfi) for (i = 0; i < cb->num_format_mappings; i++) event->formats[i] = cb->format_mappings[i].format_id; - freerdp_channels_send_event(cb->channels, (RDP_EVENT*) event); + freerdp_channels_send_event(cb->channels, (wMessage*) event); } static void xf_cliprdr_send_format_list(xfInfo* xfi) @@ -396,12 +408,12 @@ static void xf_cliprdr_send_data_request(xfInfo* xfi, UINT32 format) RDP_CB_DATA_REQUEST_EVENT* event; clipboardContext* cb = (clipboardContext*) xfi->clipboard_context; - event = (RDP_CB_DATA_REQUEST_EVENT*) freerdp_event_new(RDP_EVENT_CLASS_CLIPRDR, - RDP_EVENT_TYPE_CB_DATA_REQUEST, NULL, NULL); + event = (RDP_CB_DATA_REQUEST_EVENT*) freerdp_event_new(CliprdrChannel_Class, + CliprdrChannel_DataRequest, NULL, NULL); event->format = format; - freerdp_channels_send_event(cb->channels, (RDP_EVENT*) event); + freerdp_channels_send_event(cb->channels, (wMessage*) event); } static void xf_cliprdr_send_data_response(xfInfo* xfi, BYTE* data, int size) @@ -409,13 +421,13 @@ static void xf_cliprdr_send_data_response(xfInfo* xfi, BYTE* data, int size) RDP_CB_DATA_RESPONSE_EVENT* event; clipboardContext* cb = (clipboardContext*) xfi->clipboard_context; - event = (RDP_CB_DATA_RESPONSE_EVENT*) freerdp_event_new(RDP_EVENT_CLASS_CLIPRDR, - RDP_EVENT_TYPE_CB_DATA_RESPONSE, NULL, NULL); + event = (RDP_CB_DATA_RESPONSE_EVENT*) freerdp_event_new(CliprdrChannel_Class, + CliprdrChannel_DataResponse, NULL, NULL); event->data = data; event->size = size; - freerdp_channels_send_event(cb->channels, (RDP_EVENT*) event); + freerdp_channels_send_event(cb->channels, (wMessage*) event); } static void xf_cliprdr_send_null_data_response(xfInfo* xfi) @@ -481,23 +493,24 @@ static void xf_cliprdr_get_requested_targets(xfInfo* xfi) clipboardContext* cb = (clipboardContext*) xfi->clipboard_context; XGetWindowProperty(xfi->display, xfi->drawable, cb->property_atom, - 0, 200, 0, XA_ATOM, - &atom, &format, &length, &bytes_left, &data); + 0, 200, 0, XA_ATOM, &atom, &format, &length, &bytes_left, &data); DEBUG_X11_CLIPRDR("type=%d format=%d length=%d bytes_left=%d", (int) atom, format, (int) length, (int) bytes_left); if (length > 0) { - event = (RDP_CB_FORMAT_LIST_EVENT*) freerdp_event_new(RDP_EVENT_CLASS_CLIPRDR, - RDP_EVENT_TYPE_CB_FORMAT_LIST, NULL, NULL); + event = (RDP_CB_FORMAT_LIST_EVENT*) freerdp_event_new(CliprdrChannel_Class, + CliprdrChannel_FormatList, NULL, NULL); event->formats = (UINT32*) malloc(sizeof(UINT32) * cb->num_format_mappings); num = 0; + for (i = 0; i < length; i++) { atom = ((Atom*) data)[i]; DEBUG_X11("atom %d", (int) atom); + for (j = 0; j < cb->num_format_mappings; j++) { if (cb->format_mappings[j].target_format == atom) @@ -509,10 +522,11 @@ static void xf_cliprdr_get_requested_targets(xfInfo* xfi) } } } + event->num_formats = num; XFree(data); - freerdp_channels_send_event(cb->channels, (RDP_EVENT*) event); + freerdp_channels_send_event(cb->channels, (wMessage*) event); } else { @@ -528,7 +542,7 @@ static BYTE* xf_cliprdr_process_requested_raw(BYTE* data, int* size) BYTE* outbuf; outbuf = (BYTE*) malloc(*size); - memcpy(outbuf, data, *size); + CopyMemory(outbuf, data, *size); return outbuf; } @@ -561,6 +575,7 @@ static BYTE* xf_cliprdr_process_requested_dib(BYTE* data, int* size) BYTE* outbuf; /* length should be at least BMP header (14) + sizeof(BITMAPINFOHEADER) */ + if (*size < 54) { DEBUG_X11_CLIPRDR("bmp length %d too short", *size); @@ -571,7 +586,7 @@ static BYTE* xf_cliprdr_process_requested_dib(BYTE* data, int* size) outbuf = (BYTE*) malloc(*size); ZeroMemory(outbuf, *size); - memcpy(outbuf, data + 14, *size); + CopyMemory(outbuf, data + 14, *size); return outbuf; } @@ -604,7 +619,7 @@ static BYTE* xf_cliprdr_process_requested_html(BYTE* data, int* size) inbuf = malloc(*size + 1); ZeroMemory(inbuf, *size + 1); - memcpy(inbuf, data, *size); + CopyMemory(inbuf, data, *size); } outbuf = (BYTE*) malloc(*size + 200); @@ -625,7 +640,7 @@ static BYTE* xf_cliprdr_process_requested_html(BYTE* data, int* size) } /* StartHTML */ snprintf(num, sizeof(num), "%010lu", (unsigned long) strlen((char*) outbuf)); - memcpy(outbuf + 23, num, 10); + CopyMemory(outbuf + 23, num, 10); if (in == NULL) { strcat((char*) outbuf, ""); @@ -633,11 +648,11 @@ static BYTE* xf_cliprdr_process_requested_html(BYTE* data, int* size) strcat((char*) outbuf, ""); /* StartFragment */ snprintf(num, sizeof(num), "%010lu", (unsigned long) strlen((char*) outbuf)); - memcpy(outbuf + 69, num, 10); + CopyMemory(outbuf + 69, num, 10); strcat((char*) outbuf, (char*) inbuf); /* EndFragment */ snprintf(num, sizeof(num), "%010lu", (unsigned long) strlen((char*) outbuf)); - memcpy(outbuf + 93, num, 10); + CopyMemory(outbuf + 93, num, 10); strcat((char*) outbuf, ""); if (in == NULL) { @@ -645,7 +660,7 @@ static BYTE* xf_cliprdr_process_requested_html(BYTE* data, int* size) } /* EndHTML */ snprintf(num, sizeof(num), "%010lu", (unsigned long) strlen((char*) outbuf)); - memcpy(outbuf + 43, num, 10); + CopyMemory(outbuf + 43, num, 10); *size = strlen((char*) outbuf) + 1; free(inbuf); @@ -773,7 +788,7 @@ static BOOL xf_cliprdr_get_requested_data(xfInfo* xfi, Atom target) bytes_left = length * format / 8; DEBUG_X11("%d bytes", (int)bytes_left); cb->incr_data = (BYTE*) realloc(cb->incr_data, cb->incr_data_length + bytes_left); - memcpy(cb->incr_data + cb->incr_data_length, data, bytes_left); + CopyMemory(cb->incr_data + cb->incr_data_length, data, bytes_left); cb->incr_data_length += bytes_left; XFree(data); data = NULL; @@ -859,6 +874,7 @@ static void xf_cliprdr_process_cb_format_list_event(xfInfo* xfi, RDP_CB_FORMAT_L event->num_formats = 0; cb->num_targets = 2; + for (i = 0; i < cb->num_formats; i++) { for (j = 0; j < cb->num_format_mappings; j++) @@ -872,6 +888,7 @@ static void xf_cliprdr_process_cb_format_list_event(xfInfo* xfi, RDP_CB_FORMAT_L } XSetSelectionOwner(xfi->display, cb->clipboard_atom, xfi->drawable, CurrentTime); + if (event->raw_format_data) { XChangeProperty(xfi->display, cb->root_window, cb->property_atom, @@ -885,7 +902,7 @@ static void xf_cliprdr_process_cb_format_list_event(xfInfo* xfi, RDP_CB_FORMAT_L static void xf_cliprdr_process_text(clipboardContext* cb, BYTE* data, int size) { cb->data = (BYTE*) malloc(size); - memcpy(cb->data, data, size); + CopyMemory(cb->data, data, size); cb->data_length = size; crlf2lf(cb->data, &cb->data_length); } @@ -898,12 +915,13 @@ static void xf_cliprdr_process_unicodetext(clipboardContext* cb, BYTE* data, int static void xf_cliprdr_process_dib(clipboardContext* cb, BYTE* data, int size) { - STREAM* s; + wStream* s; UINT16 bpp; UINT32 offset; UINT32 ncolors; /* size should be at least sizeof(BITMAPINFOHEADER) */ + if (size < 40) { DEBUG_X11_CLIPRDR("dib size %d too short", size); @@ -958,7 +976,7 @@ static void xf_cliprdr_process_html(clipboardContext* cb, BYTE* data, int size) } cb->data = (BYTE*) malloc(size - start + 1); - memcpy(cb->data, data + start, end - start); + CopyMemory(cb->data, data + start, end - start); cb->data_length = end - start; crlf2lf(cb->data, &cb->data_length); } @@ -969,7 +987,7 @@ static void xf_cliprdr_process_cb_data_response_event(xfInfo* xfi, RDP_CB_DATA_R DEBUG_X11_CLIPRDR("size=%d", event->size); - if (cb->respond == NULL) + if (!cb->respond) { DEBUG_X11_CLIPRDR("unexpected data"); return; @@ -986,6 +1004,7 @@ static void xf_cliprdr_process_cb_data_response_event(xfInfo* xfi, RDP_CB_DATA_R free(cb->data); cb->data = NULL; } + switch (cb->data_format) { case CB_FORMAT_RAW: @@ -1027,28 +1046,28 @@ static void xf_cliprdr_process_cb_data_response_event(xfInfo* xfi, RDP_CB_DATA_R cb->respond = NULL; } -void xf_process_cliprdr_event(xfInfo* xfi, RDP_EVENT* event) +void xf_process_cliprdr_event(xfInfo* xfi, wMessage* event) { - switch (event->event_type) + switch (GetMessageType(event->id)) { - case RDP_EVENT_TYPE_CB_MONITOR_READY: + case CliprdrChannel_MonitorReady: xf_cliprdr_process_cb_monitor_ready_event(xfi); break; - case RDP_EVENT_TYPE_CB_FORMAT_LIST: + case CliprdrChannel_FormatList: xf_cliprdr_process_cb_format_list_event(xfi, (RDP_CB_FORMAT_LIST_EVENT*) event); break; - case RDP_EVENT_TYPE_CB_DATA_REQUEST: + case CliprdrChannel_DataRequest: xf_cliprdr_process_cb_data_request_event(xfi, (RDP_CB_DATA_REQUEST_EVENT*) event); break; - case RDP_EVENT_TYPE_CB_DATA_RESPONSE: + case CliprdrChannel_DataResponse: xf_cliprdr_process_cb_data_response_event(xfi, (RDP_CB_DATA_RESPONSE_EVENT*) event); break; default: - DEBUG_X11_CLIPRDR("unknown event type %d", event->event_type); + DEBUG_X11_CLIPRDR("unknown event type %d", GetMessageType(event->id)); break; } } @@ -1144,7 +1163,7 @@ BOOL xf_cliprdr_process_selection_request(xfInfo* xfi, XEvent* xevent) } if (data) { - memcpy(&alt_format, data, 4); + CopyMemory(&alt_format, data, 4); XFree(data); } } diff --git a/client/X11/xf_cliprdr.h b/client/X11/xf_cliprdr.h index f5ec699b2..ead887606 100644 --- a/client/X11/xf_cliprdr.h +++ b/client/X11/xf_cliprdr.h @@ -20,21 +20,15 @@ #ifndef __XF_CLIPRDR_H #define __XF_CLIPRDR_H -#include "xfreerdp.h" +#include "xf_interface.h" void xf_cliprdr_init(xfInfo* xfi, rdpChannels* chanman); void xf_cliprdr_uninit(xfInfo* xfi); -void xf_process_cliprdr_event(xfInfo* xfi, RDP_EVENT* event); +void xf_process_cliprdr_event(xfInfo* xfi, wMessage* event); BOOL xf_cliprdr_process_selection_notify(xfInfo* xfi, XEvent* xevent); BOOL xf_cliprdr_process_selection_request(xfInfo* xfi, XEvent* xevent); BOOL xf_cliprdr_process_selection_clear(xfInfo* xfi, XEvent* xevent); BOOL xf_cliprdr_process_property_notify(xfInfo* xfi, XEvent* xevent); void xf_cliprdr_check_owner(xfInfo* xfi); -#ifdef WITH_DEBUG_X11_CLIPRDR -#define DEBUG_X11_CLIPRDR(fmt, ...) DEBUG_CLASS(X11_CLIPRDR, fmt, ## __VA_ARGS__) -#else -#define DEBUG_X11_CLIPRDR(fmt, ...) DEBUG_NULL(fmt, ## __VA_ARGS__) -#endif - #endif /* __XF_CLIPRDR_H */ diff --git a/client/X11/xf_event.c b/client/X11/xf_event.c index 836116ab3..f8ebbf110 100644 --- a/client/X11/xf_event.c +++ b/client/X11/xf_event.c @@ -32,8 +32,7 @@ #include "xf_event.h" -#ifdef WITH_DEBUG_X11 -static const char* const X11_EVENT_STRINGS[] = +const char* const X11_EVENT_STRINGS[] = { "", "", "KeyPress", @@ -71,6 +70,17 @@ static const char* const X11_EVENT_STRINGS[] = "MappingNotify", "GenericEvent", }; + +#ifdef WITH_DEBUG_X11 +#define DEBUG_X11(fmt, ...) DEBUG_CLASS(X11, fmt, ## __VA_ARGS__) +#else +#define DEBUG_X11(fmt, ...) DEBUG_NULL(fmt, ## __VA_ARGS__) +#endif + +#ifdef WITH_DEBUG_X11_LOCAL_MOVESIZE +#define DEBUG_X11_LMS(fmt, ...) DEBUG_CLASS(X11_LMS, fmt, ## __VA_ARGS__) +#else +#define DEBUG_X11_LMS(fmt, ...) DEBUG_NULL(fmt, ## __VA_ARGS__) #endif static BOOL xf_event_Expose(xfInfo* xfi, XEvent* event, BOOL app) @@ -121,7 +131,7 @@ static BOOL xf_event_MotionNotify(xfInfo* xfi, XEvent* event, BOOL app) x = event->xmotion.x; y = event->xmotion.y; - if (xfi->mouse_motion != TRUE) + if (!xfi->settings->MouseMotion) { if ((event->xmotion.state & (Button1Mask | Button2Mask | Button3Mask)) == 0) return TRUE; @@ -134,6 +144,7 @@ static BOOL xf_event_MotionNotify(xfInfo* xfi, XEvent* event, BOOL app) { return TRUE; } + /* Translate to desktop coordinates */ XTranslateCoordinates(xfi->display, event->xmotion.window, RootWindowOfScreen(xfi->screen), @@ -597,7 +608,7 @@ static BOOL xf_event_MapNotify(xfInfo* xfi, XEvent* event, BOOL app) */ //xf_rail_send_client_system_command(xfi, window->windowId, SC_RESTORE); - xfWindow *xfw = (xfWindow*) window->extra; + xfWindow* xfw = (xfWindow*) window->extra; xfw->is_mapped = TRUE; } } @@ -681,9 +692,10 @@ static BOOL xf_event_PropertyNotify(xfInfo* xfi, XEvent* event, BOOL app) if (window == NULL) return TRUE; - if ((((Atom)event->xproperty.atom == xfi->_NET_WM_STATE) && (event->xproperty.state != PropertyDelete)) || - (((Atom)event->xproperty.atom == xfi->WM_STATE) && (event->xproperty.state != PropertyDelete))) + if ((((Atom) event->xproperty.atom == xfi->_NET_WM_STATE) && (event->xproperty.state != PropertyDelete)) || + (((Atom) event->xproperty.atom == xfi->WM_STATE) && (event->xproperty.state != PropertyDelete))) { + int i; BOOL status; BOOL maxVert = FALSE; BOOL maxHorz = FALSE; @@ -691,68 +703,72 @@ static BOOL xf_event_PropertyNotify(xfInfo* xfi, XEvent* event, BOOL app) unsigned long nitems; unsigned long bytes; unsigned char* prop; - int i; - status = xf_GetWindowProperty(xfi, event->xproperty.window, - xfi->_NET_WM_STATE, 12, &nitems, &bytes, &prop); - - if (!status) + if ((Atom) event->xproperty.atom == xfi->_NET_WM_STATE) { - DEBUG_X11_LMS("No return _NET_WM_STATE, window is not maximized"); - } - - for (i = 0; i < nitems; i++) - { - if ((Atom) ((UINT16 **) prop)[i] == XInternAtom(xfi->display, "_NET_WM_STATE_MAXIMIZED_VERT", False)) - { - maxVert = TRUE; - } + status = xf_GetWindowProperty(xfi, event->xproperty.window, + xfi->_NET_WM_STATE, 12, &nitems, &bytes, &prop); - if ((Atom) ((UINT16 **)prop)[i] == XInternAtom(xfi->display, "_NET_WM_STATE_MAXIMIZED_HORZ", False)) - { - maxHorz = TRUE; - } + if (!status) + { + DEBUG_X11_LMS("No return _NET_WM_STATE, window is not maximized"); + } + + for (i = 0; i < nitems; i++) + { + if ((Atom) ((UINT16**) prop)[i] == XInternAtom(xfi->display, "_NET_WM_STATE_MAXIMIZED_VERT", False)) + { + maxVert = TRUE; + } + + if ((Atom) ((UINT16**) prop)[i] == XInternAtom(xfi->display, "_NET_WM_STATE_MAXIMIZED_HORZ", False)) + { + maxHorz = TRUE; + } + } + + XFree(prop); } - - XFree(prop); - status = xf_GetWindowProperty(xfi, event->xproperty.window, - xfi->WM_STATE, 1, &nitems, &bytes, &prop); - - if (!status) + if ((Atom) event->xproperty.atom == xfi->WM_STATE) { - DEBUG_X11_LMS("No return WM_STATE, window is not minimized"); + status = xf_GetWindowProperty(xfi, event->xproperty.window, xfi->WM_STATE, 1, &nitems, &bytes, &prop); + + if (!status) + { + DEBUG_X11_LMS("No return WM_STATE, window is not minimized"); + } + else + { + /* If the window is in the iconic state */ + if (((UINT32) *prop == 3)) + minimized = TRUE; + else + minimized = FALSE; + + XFree(prop); + } } - else - { - /* If the window is in the iconic state */ - if (((UINT32) *prop == 3)) - minimized = TRUE; - else - minimized = FALSE; - - XFree(prop); - } - if (maxVert && maxHorz && !minimized && (xfi->window->rail_state != WINDOW_SHOW_MAXIMIZED)) - { - DEBUG_X11_LMS("Send SC_MAXIMIZE command to rail server."); - xfi->window->rail_state = WINDOW_SHOW_MAXIMIZED; - xf_rail_send_client_system_command(xfi, window->windowId, SC_MAXIMIZE); - } - else if (minimized && (xfi->window->rail_state != WINDOW_SHOW_MINIMIZED)) - { - DEBUG_X11_LMS("Send SC_MINIMIZE command to rail server."); - xfi->window->rail_state = WINDOW_SHOW_MINIMIZED; - xf_rail_send_client_system_command(xfi, window->windowId, SC_MINIMIZE); - } - else if (!minimized && !maxVert && !maxHorz && (xfi->window->rail_state != WINDOW_SHOW)) - { - DEBUG_X11_LMS("Send SC_RESTORE command to rail server"); - xfi->window->rail_state = WINDOW_SHOW; - xf_rail_send_client_system_command(xfi, window->windowId, SC_RESTORE); - } + if (maxVert && maxHorz && !minimized && (xfi->window->rail_state != WINDOW_SHOW_MAXIMIZED)) + { + DEBUG_X11_LMS("Send SC_MAXIMIZE command to rail server."); + xfi->window->rail_state = WINDOW_SHOW_MAXIMIZED; + xf_rail_send_client_system_command(xfi, window->windowId, SC_MAXIMIZE); + } + else if (minimized && (xfi->window->rail_state != WINDOW_SHOW_MINIMIZED)) + { + DEBUG_X11_LMS("Send SC_MINIMIZE command to rail server."); + xfi->window->rail_state = WINDOW_SHOW_MINIMIZED; + xf_rail_send_client_system_command(xfi, window->windowId, SC_MINIMIZE); + } + else if (!minimized && !maxVert && !maxHorz && (xfi->window->rail_state != WINDOW_SHOW)) + { + DEBUG_X11_LMS("Send SC_RESTORE command to rail server"); + xfi->window->rail_state = WINDOW_SHOW; + xf_rail_send_client_system_command(xfi, window->windowId, SC_RESTORE); + } } } else diff --git a/client/X11/xf_event.h b/client/X11/xf_event.h index f0ef8da57..722a7a56e 100644 --- a/client/X11/xf_event.h +++ b/client/X11/xf_event.h @@ -22,7 +22,7 @@ #include "xf_keyboard.h" -#include "xfreerdp.h" +#include "xf_interface.h" BOOL xf_event_process(freerdp* instance, XEvent* event); void xf_event_SendClientEvent(xfInfo *xfi, xfWindow* window, Atom atom, unsigned int numArgs, ...); diff --git a/client/X11/xf_gdi.c b/client/X11/xf_gdi.c index 974f28d97..e21c00762 100644 --- a/client/X11/xf_gdi.c +++ b/client/X11/xf_gdi.c @@ -68,7 +68,7 @@ BOOL xf_set_rop2(xfInfo* xfi, int rop2) { if ((rop2 < 0x01) || (rop2 > 0x10)) { - printf("Unsupported ROP2: %d\n", rop2); + fprintf(stderr, "Unsupported ROP2: %d\n", rop2); return FALSE; } @@ -204,7 +204,7 @@ BOOL xf_set_rop3(xfInfo* xfi, int rop3) if (function < 0) { - printf("Unsupported ROP3: 0x%08X\n", rop3); + fprintf(stderr, "Unsupported ROP3: 0x%08X\n", rop3); XSetFunction(xfi->display, xfi->gc, GXclear); return FALSE; } @@ -395,7 +395,7 @@ void xf_gdi_patblt(rdpContext* context, PATBLT_ORDER* patblt) } else { - printf("unimplemented brush style:%d\n", brush->style); + fprintf(stderr, "unimplemented brush style:%d\n", brush->style); } if (xfi->drawing == xfi->primary) @@ -491,7 +491,7 @@ void xf_gdi_multi_opaque_rect(rdpContext* context, MULTI_OPAQUE_RECT_ORDER* mult void xf_gdi_draw_nine_grid(rdpContext* context, DRAW_NINE_GRID_ORDER* draw_nine_grid) { - printf("DrawNineGrid\n"); + fprintf(stderr, "DrawNineGrid\n"); } void xf_gdi_line_to(rdpContext* context, LINE_TO_ORDER* line_to) @@ -670,7 +670,7 @@ void xf_gdi_mem3blt(rdpContext* context, MEM3BLT_ORDER* mem3blt) } else { - printf("Mem3Blt unimplemented brush style:%d\n", brush->style); + fprintf(stderr, "Mem3Blt unimplemented brush style:%d\n", brush->style); } XCopyArea(xfi->display, bitmap->pixmap, xfi->drawing, xfi->gc, @@ -728,7 +728,7 @@ void xf_gdi_polygon_sc(rdpContext* context, POLYGON_SC_ORDER* polygon_sc) break; default: - printf("PolygonSC unknown fillMode: %d\n", polygon_sc->fillMode); + fprintf(stderr, "PolygonSC unknown fillMode: %d\n", polygon_sc->fillMode); break; } @@ -790,7 +790,7 @@ void xf_gdi_polygon_cb(rdpContext* context, POLYGON_CB_ORDER* polygon_cb) break; default: - printf("PolygonCB unknown fillMode: %d\n", polygon_cb->fillMode); + fprintf(stderr, "PolygonCB unknown fillMode: %d\n", polygon_cb->fillMode); break; } @@ -848,7 +848,7 @@ void xf_gdi_polygon_cb(rdpContext* context, POLYGON_CB_ORDER* polygon_cb) } else { - printf("PolygonCB unimplemented brush style:%d\n", brush->style); + fprintf(stderr, "PolygonCB unimplemented brush style:%d\n", brush->style); } XSetFunction(xfi->display, xfi->gc, GXcopy); @@ -859,12 +859,12 @@ void xf_gdi_polygon_cb(rdpContext* context, POLYGON_CB_ORDER* polygon_cb) void xf_gdi_ellipse_sc(rdpContext* context, ELLIPSE_SC_ORDER* ellipse_sc) { - printf("EllipseSC\n"); + fprintf(stderr, "EllipseSC\n"); } void xf_gdi_ellipse_cb(rdpContext* context, ELLIPSE_CB_ORDER* ellipse_cb) { - printf("EllipseCB\n"); + fprintf(stderr, "EllipseCB\n"); } void xf_gdi_surface_frame_marker(rdpContext* context, SURFACE_FRAME_MARKER* surface_frame_marker) @@ -1042,12 +1042,12 @@ void xf_gdi_surface_bits(rdpContext* context, SURFACE_BITS_COMMAND* surface_bits } else { - printf("Invalid bitmap size - data is %d bytes for %dx%d\n update", surface_bits_command->bitmapDataLength, surface_bits_command->width, surface_bits_command->height); + fprintf(stderr, "Invalid bitmap size - data is %d bytes for %dx%d\n update", surface_bits_command->bitmapDataLength, surface_bits_command->width, surface_bits_command->height); } } else { - printf("Unsupported codecID %d\n", surface_bits_command->codecID); + fprintf(stderr, "Unsupported codecID %d\n", surface_bits_command->codecID); } xf_unlock_x11(xfi, FALSE); diff --git a/client/X11/xf_gdi.h b/client/X11/xf_gdi.h index 2a30b8965..b3ac75df9 100644 --- a/client/X11/xf_gdi.h +++ b/client/X11/xf_gdi.h @@ -22,7 +22,7 @@ #include -#include "xfreerdp.h" +#include "xf_interface.h" void xf_gdi_register_update_callbacks(rdpUpdate* update); diff --git a/client/X11/xf_graphics.c b/client/X11/xf_graphics.c index 6a8a6d98c..da609790a 100644 --- a/client/X11/xf_graphics.c +++ b/client/X11/xf_graphics.c @@ -144,7 +144,7 @@ void xf_Bitmap_Decompress(rdpContext* context, rdpBitmap* bitmap, switch (codec_id) { case RDP_CODEC_ID_NSCODEC: - printf("xf_Bitmap_Decompress: nsc not done\n"); + fprintf(stderr, "xf_Bitmap_Decompress: nsc not done\n"); break; case RDP_CODEC_ID_REMOTEFX: @@ -153,7 +153,7 @@ void xf_Bitmap_Decompress(rdpContext* context, rdpBitmap* bitmap, if (msg == NULL) { - printf("xf_Bitmap_Decompress: rfx Decompression Failed\n"); + fprintf(stderr, "xf_Bitmap_Decompress: rfx Decompression Failed\n"); } else { @@ -176,7 +176,7 @@ void xf_Bitmap_Decompress(rdpContext* context, rdpBitmap* bitmap, case RDP_CODEC_ID_JPEG: if (!jpeg_decompress(data, bitmap->data, width, height, length, bpp)) { - printf("xf_Bitmap_Decompress: jpeg Decompression Failed\n"); + fprintf(stderr, "xf_Bitmap_Decompress: jpeg Decompression Failed\n"); } break; @@ -187,7 +187,7 @@ void xf_Bitmap_Decompress(rdpContext* context, rdpBitmap* bitmap, if (status == FALSE) { - printf("xf_Bitmap_Decompress: Bitmap Decompression Failed\n"); + fprintf(stderr, "xf_Bitmap_Decompress: Bitmap Decompression Failed\n"); } } else diff --git a/client/X11/xf_graphics.h b/client/X11/xf_graphics.h index b9256a86c..9d8cfd62f 100644 --- a/client/X11/xf_graphics.h +++ b/client/X11/xf_graphics.h @@ -20,7 +20,7 @@ #ifndef __XF_GRAPHICS_H #define __XF_GRAPHICS_H -#include "xfreerdp.h" +#include "xf_interface.h" void xf_register_graphics(rdpGraphics* graphics); diff --git a/client/X11/xfreerdp.c b/client/X11/xf_interface.c similarity index 83% rename from client/X11/xfreerdp.c rename to client/X11/xf_interface.c index 05520d2dd..7a84adc4f 100644 --- a/client/X11/xfreerdp.c +++ b/client/X11/xf_interface.c @@ -1,9 +1,8 @@ /** * FreeRDP: A Remote Desktop Protocol Implementation - * X11 Client + * X11 Client Interface * - * Copyright 2011 Marc-Andre Moreau - * Copyright 2012 HP Development Company, LLC + * Copyright 2013 Marc-Andre Moreau * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -75,20 +74,9 @@ #include "xf_graphics.h" #include "xf_keyboard.h" -#include "xfreerdp.h" - -static HANDLE g_sem; -static int g_thread_count = 0; -static BYTE g_disconnect_reason = 0; - static long xv_port = 0; static const size_t password_size = 512; -struct thread_data -{ - freerdp* instance; -}; - void xf_context_new(freerdp* instance, rdpContext* context) { context->channels = freerdp_channels_new(); @@ -381,47 +369,54 @@ BOOL xf_process_x_events(freerdp* instance) void xf_create_window(xfInfo* xfi) { XEvent xevent; - char* win_title; int width, height; + char* windowTitle; ZeroMemory(&xevent, sizeof(xevent)); width = xfi->width; height = xfi->height; - xfi->attribs.background_pixel = BlackPixelOfScreen(xfi->screen); - xfi->attribs.border_pixel = WhitePixelOfScreen(xfi->screen); - xfi->attribs.backing_store = xfi->primary ? NotUseful : Always; - xfi->attribs.override_redirect = xfi->grab_keyboard ? xfi->fullscreen : False; - xfi->attribs.colormap = xfi->colormap; - xfi->attribs.bit_gravity = NorthWestGravity; - xfi->attribs.win_gravity = NorthWestGravity; + if (!xfi->remote_app) + { + xfi->attribs.background_pixel = BlackPixelOfScreen(xfi->screen); + xfi->attribs.border_pixel = WhitePixelOfScreen(xfi->screen); + xfi->attribs.backing_store = xfi->primary ? NotUseful : Always; + xfi->attribs.override_redirect = xfi->grab_keyboard ? xfi->fullscreen : False; + xfi->attribs.colormap = xfi->colormap; + xfi->attribs.bit_gravity = NorthWestGravity; + xfi->attribs.win_gravity = NorthWestGravity; - if (xfi->instance->settings->WindowTitle != NULL) - { - win_title = _strdup(xfi->instance->settings->WindowTitle); - } - else if (xfi->instance->settings->ServerPort == 3389) - { - win_title = malloc(1 + sizeof("FreeRDP: ") + strlen(xfi->instance->settings->ServerHostname)); - sprintf(win_title, "FreeRDP: %s", xfi->instance->settings->ServerHostname); + if (xfi->instance->settings->WindowTitle) + { + windowTitle = _strdup(xfi->instance->settings->WindowTitle); + } + else if (xfi->instance->settings->ServerPort == 3389) + { + windowTitle = malloc(1 + sizeof("FreeRDP: ") + strlen(xfi->instance->settings->ServerHostname)); + sprintf(windowTitle, "FreeRDP: %s", xfi->instance->settings->ServerHostname); + } + else + { + windowTitle = malloc(1 + sizeof("FreeRDP: ") + strlen(xfi->instance->settings->ServerHostname) + sizeof(":00000")); + sprintf(windowTitle, "FreeRDP: %s:%i", xfi->instance->settings->ServerHostname, xfi->instance->settings->ServerPort); + } + + xfi->window = xf_CreateDesktopWindow(xfi, windowTitle, width, height, xfi->settings->Decorations); + free(windowTitle); + + if (xfi->fullscreen) + xf_SetWindowFullscreen(xfi, xfi->window, xfi->fullscreen); + + xfi->unobscured = (xevent.xvisibility.state == VisibilityUnobscured); + + XSetWMProtocols(xfi->display, xfi->window->handle, &(xfi->WM_DELETE_WINDOW), 1); + xfi->drawable = xfi->window->handle; } else { - win_title = malloc(1 + sizeof("FreeRDP: ") + strlen(xfi->instance->settings->ServerHostname) + sizeof(":00000")); - sprintf(win_title, "FreeRDP: %s:%i", xfi->instance->settings->ServerHostname, xfi->instance->settings->ServerPort); + xfi->drawable = DefaultRootWindow(xfi->display); } - - xfi->window = xf_CreateDesktopWindow(xfi, win_title, width, height, xfi->decorations); - free(win_title); - - if (xfi->fullscreen) - xf_SetWindowFullscreen(xfi, xfi->window, xfi->fullscreen); - - xfi->unobscured = (xevent.xvisibility.state == VisibilityUnobscured); - - XSetWMProtocols(xfi->display, xfi->window->handle, &(xfi->WM_DELETE_WINDOW), 1); - xfi->drawable = xfi->window->handle; } void xf_toggle_fullscreen(xfInfo* xfi) @@ -485,7 +480,7 @@ BOOL xf_get_pixmap_info(xfInfo* xfi) if (pfs == NULL) { - printf("xf_get_pixmap_info: XListPixmapFormats failed\n"); + fprintf(stderr, "xf_get_pixmap_info: XListPixmapFormats failed\n"); return 1; } @@ -508,7 +503,7 @@ BOOL xf_get_pixmap_info(xfInfo* xfi) if (XGetWindowAttributes(xfi->display, RootWindowOfScreen(xfi->screen), &window_attributes) == 0) { - printf("xf_get_pixmap_info: XGetWindowAttributes failed\n"); + fprintf(stderr, "xf_get_pixmap_info: XGetWindowAttributes failed\n"); return FALSE; } @@ -516,7 +511,7 @@ BOOL xf_get_pixmap_info(xfInfo* xfi) if (vis == NULL) { - printf("xf_get_pixmap_info: XGetVisualInfo failed\n"); + fprintf(stderr, "xf_get_pixmap_info: XGetVisualInfo failed\n"); return FALSE; } @@ -539,7 +534,7 @@ BOOL xf_get_pixmap_info(xfInfo* xfi) * (BGR vs RGB, or red being the least significant byte) */ - if (vi->red_mask & 0xFF) + if (vi->red_mask & 0xFF) { xfi->clrconv->invert = TRUE; } @@ -563,7 +558,7 @@ int xf_error_handler(Display* d, XErrorEvent* ev) int do_abort = TRUE; XGetErrorText(d, ev->error_code, buf, sizeof(buf)); - printf("%s", buf); + fprintf(stderr, "%s", buf); if (do_abort) abort(); @@ -596,16 +591,10 @@ int _xf_error_handler(Display* d, XErrorEvent* ev) */ BOOL xf_pre_connect(freerdp* instance) { - int status; xfInfo* xfi; - rdpFile* file; - BOOL bitmap_cache; rdpSettings* settings; - - xfi = (xfInfo*) malloc(sizeof(xfInfo)); - ZeroMemory(xfi, sizeof(xfInfo)); - ((xfContext*) instance->context)->xfi = xfi; + xfi = ((xfContext*) instance->context)->xfi; xfi->mutex = CreateMutex(NULL, FALSE, NULL); @@ -613,60 +602,12 @@ BOOL xf_pre_connect(freerdp* instance) xfi->context = (xfContext*) instance->context; xfi->context->settings = instance->settings; xfi->instance = instance; - - status = freerdp_client_parse_command_line_arguments(instance->context->argc, - instance->context->argv, instance->settings); - - if (status < 0) - exit(XF_EXIT_PARSE_ARGUMENTS); - - freerdp_client_load_addins(instance->context->channels, instance->settings); - settings = instance->settings; - if (settings->ConnectionFile) - { - file = freerdp_client_rdp_file_new(); + //if (status < 0) + // exit(XF_EXIT_PARSE_ARGUMENTS); - printf("Using connection file: %s\n", settings->ConnectionFile); - - freerdp_client_parse_rdp_file(file, settings->ConnectionFile); - freerdp_client_populate_settings_from_rdp_file(file, settings); - } - - bitmap_cache = settings->BitmapCacheEnabled; - - settings->OsMajorType = OSMAJORTYPE_UNIX; - settings->OsMinorType = OSMINORTYPE_NATIVE_XSERVER; - - settings->OrderSupport[NEG_DSTBLT_INDEX] = TRUE; - settings->OrderSupport[NEG_PATBLT_INDEX] = TRUE; - settings->OrderSupport[NEG_SCRBLT_INDEX] = TRUE; - settings->OrderSupport[NEG_OPAQUE_RECT_INDEX] = TRUE; - settings->OrderSupport[NEG_DRAWNINEGRID_INDEX] = FALSE; - settings->OrderSupport[NEG_MULTIDSTBLT_INDEX] = FALSE; - settings->OrderSupport[NEG_MULTIPATBLT_INDEX] = FALSE; - settings->OrderSupport[NEG_MULTISCRBLT_INDEX] = FALSE; - settings->OrderSupport[NEG_MULTIOPAQUERECT_INDEX] = TRUE; - settings->OrderSupport[NEG_MULTI_DRAWNINEGRID_INDEX] = FALSE; - settings->OrderSupport[NEG_LINETO_INDEX] = TRUE; - settings->OrderSupport[NEG_POLYLINE_INDEX] = TRUE; - settings->OrderSupport[NEG_MEMBLT_INDEX] = bitmap_cache; - - settings->OrderSupport[NEG_MEM3BLT_INDEX] = (settings->SoftwareGdi) ? TRUE : FALSE; - - settings->OrderSupport[NEG_MEMBLT_V2_INDEX] = bitmap_cache; - settings->OrderSupport[NEG_MEM3BLT_V2_INDEX] = FALSE; - settings->OrderSupport[NEG_SAVEBITMAP_INDEX] = FALSE; - settings->OrderSupport[NEG_GLYPH_INDEX_INDEX] = TRUE; - settings->OrderSupport[NEG_FAST_INDEX_INDEX] = TRUE; - settings->OrderSupport[NEG_FAST_GLYPH_INDEX] = TRUE; - - settings->OrderSupport[NEG_POLYGON_SC_INDEX] = (settings->SoftwareGdi) ? FALSE : TRUE; - settings->OrderSupport[NEG_POLYGON_CB_INDEX] = (settings->SoftwareGdi) ? FALSE : TRUE; - - settings->OrderSupport[NEG_ELLIPSE_SC_INDEX] = FALSE; - settings->OrderSupport[NEG_ELLIPSE_CB_INDEX] = FALSE; + freerdp_client_load_addins(instance->context->channels, instance->settings); freerdp_channels_pre_connect(xfi->_context->channels, instance); @@ -694,7 +635,7 @@ BOOL xf_pre_connect(freerdp* instance) { if (!XInitThreads()) { - printf("warning: XInitThreads() failure\n"); + fprintf(stderr, "warning: XInitThreads() failure\n"); xfi->UseXThreads = FALSE; } } @@ -703,14 +644,14 @@ BOOL xf_pre_connect(freerdp* instance) if (xfi->display == NULL) { - printf("xf_pre_connect: failed to open display: %s\n", XDisplayName(NULL)); - printf("Please check that the $DISPLAY environment variable is properly set.\n"); + fprintf(stderr, "xf_pre_connect: failed to open display: %s\n", XDisplayName(NULL)); + fprintf(stderr, "Please check that the $DISPLAY environment variable is properly set.\n"); return FALSE; } if (xfi->debug) { - printf("Enabling X11 debug mode.\n"); + fprintf(stderr, "Enabling X11 debug mode.\n"); XSynchronize(xfi->display, TRUE); _def_error_handler = XSetErrorHandler(_xf_error_handler); } @@ -725,7 +666,7 @@ BOOL xf_pre_connect(freerdp* instance) xfi->_NET_WM_WINDOW_TYPE_NORMAL = XInternAtom(xfi->display, "_NET_WM_WINDOW_TYPE_NORMAL", False); xfi->_NET_WM_WINDOW_TYPE_DIALOG = XInternAtom(xfi->display, "_NET_WM_WINDOW_TYPE_DIALOG", False); - xfi->_NET_WM_WINDOW_TYPE_POPUP= XInternAtom(xfi->display, "_NET_WM_WINDOW_TYPE_POPUP", False); + xfi->_NET_WM_WINDOW_TYPE_POPUP = XInternAtom(xfi->display, "_NET_WM_WINDOW_TYPE_POPUP", False); xfi->_NET_WM_WINDOW_TYPE_UTILITY = XInternAtom(xfi->display, "_NET_WM_WINDOW_TYPE_UTILITY", False); xfi->_NET_WM_WINDOW_TYPE_DROPDOWN_MENU = XInternAtom(xfi->display, "_NET_WM_WINDOW_TYPE_DROPDOWN_MENU", False); xfi->_NET_WM_STATE_SKIP_TASKBAR = XInternAtom(xfi->display, "_NET_WM_STATE_SKIP_TASKBAR", False); @@ -749,14 +690,10 @@ BOOL xf_pre_connect(freerdp* instance) xfi->depth = DefaultDepthOfScreen(xfi->screen); xfi->big_endian = (ImageByteOrder(xfi->display) == MSBFirst); - xfi->mouse_motion = settings->MouseMotion; xfi->complex_regions = TRUE; - xfi->decorations = settings->Decorations; xfi->fullscreen = settings->Fullscreen; xfi->grab_keyboard = settings->GrabKeyboard; xfi->fullscreen_toggle = settings->ToggleFullscreen; - xfi->sw_gdi = settings->SoftwareGdi; - xfi->parent_window = (Window) settings->ParentWindowId; xf_detect_monitors(xfi, settings); @@ -774,19 +711,21 @@ BOOL xf_post_connect(freerdp* instance) XGCValues gcv; rdpCache* cache; rdpChannels* channels; + rdpSettings* settings; RFX_CONTEXT* rfx_context = NULL; NSC_CONTEXT* nsc_context = NULL; xfi = ((xfContext*) instance->context)->xfi; cache = instance->context->cache; channels = xfi->_context->channels; + settings = instance->settings; - if (xf_get_pixmap_info(xfi) != TRUE) + if (!xf_get_pixmap_info(xfi)) return FALSE; xf_register_graphics(instance->context->graphics); - if (xfi->sw_gdi) + if (xfi->settings->SoftwareGdi) { rdpGdi* gdi; UINT32 flags; @@ -824,8 +763,11 @@ BOOL xf_post_connect(freerdp* instance) } } - xfi->width = instance->settings->DesktopWidth; - xfi->height = instance->settings->DesktopHeight; + xfi->width = settings->DesktopWidth; + xfi->height = settings->DesktopHeight; + + if (settings->RemoteApplicationMode) + xfi->remote_app = TRUE; xf_create_window(xfi); @@ -850,7 +792,7 @@ BOOL xf_post_connect(freerdp* instance) xfi->bmp_codec_none = (BYTE*) malloc(64 * 64 * 4); - if (xfi->sw_gdi) + if (xfi->settings->SoftwareGdi) { instance->update->BeginPaint = xf_sw_begin_paint; instance->update->EndPaint = xf_sw_end_paint; @@ -865,7 +807,7 @@ BOOL xf_post_connect(freerdp* instance) pointer_cache_register_callbacks(instance->update); - if (xfi->sw_gdi != TRUE) + if (!xfi->settings->SoftwareGdi) { glyph_cache_register_callbacks(instance->update); brush_cache_register_callbacks(instance->update); @@ -884,6 +826,8 @@ BOOL xf_post_connect(freerdp* instance) xf_cliprdr_init(xfi, channels); + IFCALL(xfi->client->OnResizeWindow, instance, settings->DesktopWidth, settings->DesktopHeight); + return TRUE; } @@ -961,6 +905,17 @@ BOOL xf_verify_certificate(freerdp* instance, char* subject, char* issuer, char* return FALSE; } +int xf_logon_error_info(freerdp* instance, UINT32 data, UINT32 type) +{ + xfInfo* xfi; + + xfi = ((xfContext*) instance->context)->xfi; + + xf_rail_disable_remoteapp_mode(xfi); + + return 1; +} + int xf_receive_channel_data(freerdp* instance, int channelId, BYTE* data, int size, int flags, int total_size) { return freerdp_channels_data(instance, channelId, data, size, flags, total_size); @@ -969,7 +924,7 @@ int xf_receive_channel_data(freerdp* instance, int channelId, BYTE* data, int si void xf_process_channel_event(rdpChannels* channels, freerdp* instance) { xfInfo* xfi; - RDP_EVENT* event; + wMessage* event; xfi = ((xfContext*) instance->context)->xfi; @@ -977,17 +932,17 @@ void xf_process_channel_event(rdpChannels* channels, freerdp* instance) if (event) { - switch (event->event_class) + switch (GetMessageClass(event->id)) { - case RDP_EVENT_CLASS_RAIL: + case RailChannel_Class: xf_process_rail_event(xfi, channels, event); break; - case RDP_EVENT_CLASS_TSMF: + case TsmfChannel_Class: xf_process_tsmf_event(xfi, event); break; - case RDP_EVENT_CLASS_CLIPRDR: + case CliprdrChannel_Class: xf_process_cliprdr_event(xfi, event); break; @@ -1006,19 +961,19 @@ void xf_window_free(xfInfo* xfi) XFreeModifiermap(xfi->modifier_map); xfi->modifier_map = 0; - if (xfi->gc != NULL) + if (xfi->gc) { XFreeGC(xfi->display, xfi->gc); xfi->gc = 0; } - if (xfi->gc_mono != NULL) + if (xfi->gc_mono) { XFreeGC(xfi->display, xfi->gc_mono); xfi->gc_mono = 0; } - if (xfi->window != NULL) + if (xfi->window) { xf_DestroyWindow(xfi, xfi->window); xfi->window = NULL; @@ -1043,7 +998,7 @@ void xf_window_free(xfInfo* xfi) xfi->image = NULL; } - if (context != NULL) + if (context) { cache_free(context->cache); context->cache = NULL; @@ -1052,7 +1007,7 @@ void xf_window_free(xfInfo* xfi) context->rail = NULL; } - if (xfi->rfx_context) + if (xfi->rfx_context) { rfx_context_free(xfi->rfx_context); xfi->rfx_context = NULL; @@ -1065,6 +1020,7 @@ void xf_window_free(xfInfo* xfi) } freerdp_clrconv_free(xfi->clrconv); + xfi->clrconv = NULL; if (xfi->hdc) gdi_DeleteDC(xfi->hdc); @@ -1073,17 +1029,6 @@ void xf_window_free(xfInfo* xfi) xf_cliprdr_uninit(xfi); } -void xf_free(xfInfo* xfi) -{ - xf_window_free(xfi); - - free(xfi->bmp_codec_none); - - XCloseDisplay(xfi->display); - - free(xfi); -} - void* xf_update_thread(void* arg) { int status; @@ -1190,7 +1135,7 @@ void* xf_channels_thread(void* arg) * @param instance - pointer to the rdp_freerdp structure that contains the session's settings * @return A code from the enum XF_EXIT_CODE (0 if successful) */ -int xfreerdp_run(freerdp* instance) +void* xf_thread(void* param) { int i; int fds; @@ -1198,18 +1143,20 @@ int xfreerdp_run(freerdp* instance) int max_fds; int rcount; int wcount; - int ret = 0; BOOL status; + int exit_code; void* rfds[32]; void* wfds[32]; fd_set rfds_set; fd_set wfds_set; + freerdp* instance; int fd_input_event; - HANDLE input_event = INVALID_HANDLE_VALUE; + HANDLE input_event; int select_status; BOOL async_update; BOOL async_input; BOOL async_channels; + BOOL async_transport; HANDLE update_thread; HANDLE input_thread; HANDLE channels_thread; @@ -1217,6 +1164,11 @@ int xfreerdp_run(freerdp* instance) rdpSettings* settings; struct timeval timeout; + exit_code = 0; + input_event = NULL; + + instance = (freerdp*) param; + ZeroMemory(rfds, sizeof(rfds)); ZeroMemory(wfds, sizeof(wfds)); ZeroMemory(&timeout, sizeof(struct timeval)); @@ -1235,8 +1187,8 @@ int xfreerdp_run(freerdp* instance) if (!status) { - xf_free(xfi); - return XF_EXIT_CONN_FAILED; + exit_code = XF_EXIT_CONN_FAILED; + ExitThread(exit_code); } channels = instance->context->channels; @@ -1245,6 +1197,7 @@ int xfreerdp_run(freerdp* instance) async_update = settings->AsyncUpdate; async_input = settings->AsyncInput; async_channels = settings->AsyncChannels; + async_transport = settings->AsyncTransport; if (async_update) { @@ -1266,19 +1219,22 @@ int xfreerdp_run(freerdp* instance) rcount = 0; wcount = 0; - if (freerdp_get_fds(instance, rfds, &rcount, wfds, &wcount) != TRUE) + if (!async_transport) { - printf("Failed to get FreeRDP file descriptor\n"); - ret = XF_EXIT_CONN_FAILED; - break; + if (freerdp_get_fds(instance, rfds, &rcount, wfds, &wcount) != TRUE) + { + fprintf(stderr, "Failed to get FreeRDP file descriptor\n"); + exit_code = XF_EXIT_CONN_FAILED; + break; + } } if (!async_channels) { if (freerdp_channels_get_fds(channels, instance, rfds, &rcount, wfds, &wcount) != TRUE) { - printf("Failed to get channel manager file descriptor\n"); - ret = XF_EXIT_CONN_FAILED; + fprintf(stderr, "Failed to get channel manager file descriptor\n"); + exit_code = XF_EXIT_CONN_FAILED; break; } } @@ -1287,8 +1243,8 @@ int xfreerdp_run(freerdp* instance) { if (xf_get_fds(instance, rfds, &rcount, wfds, &wcount) != TRUE) { - printf("Failed to get xfreerdp file descriptor\n"); - ret = XF_EXIT_CONN_FAILED; + fprintf(stderr, "Failed to get xfreerdp file descriptor\n"); + exit_code = XF_EXIT_CONN_FAILED; break; } } @@ -1331,22 +1287,25 @@ int xfreerdp_run(freerdp* instance) if (!((errno == EAGAIN) || (errno == EWOULDBLOCK) || (errno == EINPROGRESS) || (errno == EINTR))) /* signal occurred */ { - printf("xfreerdp_run: select failed\n"); + fprintf(stderr, "xfreerdp_run: select failed\n"); break; } } - if (freerdp_check_fds(instance) != TRUE) + if (!async_transport) { - printf("Failed to check FreeRDP file descriptor\n"); - break; + if (freerdp_check_fds(instance) != TRUE) + { + fprintf(stderr, "Failed to check FreeRDP file descriptor\n"); + break; + } } if (!async_channels) { if (freerdp_channels_check_fds(channels, instance) != TRUE) { - printf("Failed to check channel manager file descriptor\n"); + fprintf(stderr, "Failed to check channel manager file descriptor\n"); break; } @@ -1357,7 +1316,7 @@ int xfreerdp_run(freerdp* instance) { if (xf_process_x_events(instance) != TRUE) { - printf("Closed from X11\n"); + fprintf(stderr, "Closed from X11\n"); break; } } @@ -1367,7 +1326,7 @@ int xfreerdp_run(freerdp* instance) { if (!freerdp_message_queue_process_pending_messages(instance, FREERDP_INPUT_MESSAGE_QUEUE)) { - printf("User Disconnect\n"); + fprintf(stderr, "User Disconnect\n"); xfi->disconnect = TRUE; break; } @@ -1416,43 +1375,20 @@ int xfreerdp_run(freerdp* instance) } } - if (!ret) - ret = freerdp_error_info(instance); + if (!exit_code) + exit_code = freerdp_error_info(instance); freerdp_channels_close(channels, instance); freerdp_channels_free(channels); freerdp_disconnect(instance); gdi_free(instance); - xf_free(xfi); - return ret; + ExitThread(exit_code); } -/** Entry point for the thread that will deal with the session. - * It just calls xfreerdp_run() using the given instance as parameter. - * @param param - pointer to a thread_data structure that contains the initialized connection. - */ -void* thread_func(void* param) +DWORD xf_exit_code_from_disconnect_reason(DWORD reason) { - struct thread_data* data; - data = (struct thread_data*) param; - - g_disconnect_reason = xfreerdp_run(data->instance); - - free(data); - - g_thread_count--; - - if (g_thread_count < 1) - ReleaseSemaphore(g_sem, 1, NULL); - - pthread_exit(NULL); -} - -static BYTE exit_code_from_disconnect_reason(UINT32 reason) -{ - if (reason == 0 || - (reason >= XF_EXIT_PARSE_ARGUMENTS && reason <= XF_EXIT_CONN_FAILED)) + if (reason == 0 || (reason >= XF_EXIT_PARSE_ARGUMENTS && reason <= XF_EXIT_CONN_FAILED)) return reason; /* License error set */ @@ -1470,25 +1406,64 @@ static BYTE exit_code_from_disconnect_reason(UINT32 reason) return reason; } -int main(int argc, char* argv[]) +/** + * Client Interface + */ + +int freerdp_client_global_init() { - pthread_t thread; - freerdp* instance; - struct thread_data* data; - - freerdp_handle_signals(); - setlocale(LC_ALL, ""); - + freerdp_handle_signals(); freerdp_channels_global_init(); - g_sem = CreateSemaphore(NULL, 0, 1, NULL); + return 0; +} + +int freerdp_client_global_uninit() +{ + freerdp_channels_global_uninit(); + + return 0; +} + +int freerdp_client_start(xfInfo* xfi) +{ + xfi->thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) xf_thread, (void*) xfi->instance, 0, NULL); + + return 0; +} + +int freerdp_client_stop(xfInfo* xfi) +{ + if (xfi->instance->settings->AsyncInput) + { + wMessageQueue* queue; + queue = freerdp_get_message_queue(xfi->instance, FREERDP_INPUT_MESSAGE_QUEUE); + MessageQueue_PostQuit(queue, 0); + } + else + { + xfi->disconnect = TRUE; + } + + return 0; +} + +xfInfo* freerdp_client_new(int argc, char** argv) +{ + int index; + int status; + xfInfo* xfi; + rdpFile* file; + freerdp* instance; + rdpSettings* settings; instance = freerdp_new(); instance->PreConnect = xf_pre_connect; instance->PostConnect = xf_post_connect; instance->Authenticate = xf_authenticate; instance->VerifyCertificate = xf_verify_certificate; + instance->LogonErrorInfo = xf_logon_error_info; instance->ReceiveChannelData = xf_receive_channel_data; instance->context_size = sizeof(xfContext); @@ -1497,29 +1472,99 @@ int main(int argc, char* argv[]) freerdp_context_new(instance); instance->context->argc = argc; - instance->context->argv = argv; - instance->settings->SoftwareGdi = FALSE; + instance->context->argv = (char**) malloc(sizeof(char*) * argc); - data = (struct thread_data*) malloc(sizeof(struct thread_data)); - ZeroMemory(data, sizeof(struct thread_data)); + for (index = 0; index < argc; index++) + instance->context->argv[index] = _strdup(argv[index]); - data->instance = instance; + xfi = (xfInfo*) malloc(sizeof(xfInfo)); + ZeroMemory(xfi, sizeof(xfInfo)); - g_thread_count++; - pthread_create(&thread, 0, thread_func, data); + ((xfContext*) instance->context)->xfi = xfi; - while (g_thread_count > 0) + xfi->instance = instance; + settings = instance->settings; + xfi->client = instance->context->client; + xfi->settings = instance->context->settings; + + status = freerdp_client_parse_command_line_arguments(instance->context->argc, + instance->context->argv, settings); + if (status < 0) { - WaitForSingleObject(g_sem, INFINITE); + freerdp_context_free(xfi->instance); + freerdp_free(xfi->instance); + free(xfi); + return NULL; } - pthread_join(thread, NULL); - pthread_detach(thread); + if (settings->ConnectionFile) + { + file = freerdp_client_rdp_file_new(); - freerdp_context_free(instance); - freerdp_free(instance); + fprintf(stderr, "Using connection file: %s\n", settings->ConnectionFile); - freerdp_channels_global_uninit(); + freerdp_client_parse_rdp_file(file, settings->ConnectionFile); + freerdp_client_populate_settings_from_rdp_file(file, settings); + } - return exit_code_from_disconnect_reason(g_disconnect_reason); + settings->OsMajorType = OSMAJORTYPE_UNIX; + settings->OsMinorType = OSMINORTYPE_NATIVE_XSERVER; + + settings->OrderSupport[NEG_DSTBLT_INDEX] = TRUE; + settings->OrderSupport[NEG_PATBLT_INDEX] = TRUE; + settings->OrderSupport[NEG_SCRBLT_INDEX] = TRUE; + settings->OrderSupport[NEG_OPAQUE_RECT_INDEX] = TRUE; + settings->OrderSupport[NEG_DRAWNINEGRID_INDEX] = FALSE; + settings->OrderSupport[NEG_MULTIDSTBLT_INDEX] = FALSE; + settings->OrderSupport[NEG_MULTIPATBLT_INDEX] = FALSE; + settings->OrderSupport[NEG_MULTISCRBLT_INDEX] = FALSE; + settings->OrderSupport[NEG_MULTIOPAQUERECT_INDEX] = TRUE; + settings->OrderSupport[NEG_MULTI_DRAWNINEGRID_INDEX] = FALSE; + settings->OrderSupport[NEG_LINETO_INDEX] = TRUE; + settings->OrderSupport[NEG_POLYLINE_INDEX] = TRUE; + settings->OrderSupport[NEG_MEMBLT_INDEX] = settings->BitmapCacheEnabled; + + settings->OrderSupport[NEG_MEM3BLT_INDEX] = (settings->SoftwareGdi) ? TRUE : FALSE; + + settings->OrderSupport[NEG_MEMBLT_V2_INDEX] = settings->BitmapCacheEnabled; + settings->OrderSupport[NEG_MEM3BLT_V2_INDEX] = FALSE; + settings->OrderSupport[NEG_SAVEBITMAP_INDEX] = FALSE; + settings->OrderSupport[NEG_GLYPH_INDEX_INDEX] = TRUE; + settings->OrderSupport[NEG_FAST_INDEX_INDEX] = TRUE; + settings->OrderSupport[NEG_FAST_GLYPH_INDEX] = TRUE; + + settings->OrderSupport[NEG_POLYGON_SC_INDEX] = (settings->SoftwareGdi) ? FALSE : TRUE; + settings->OrderSupport[NEG_POLYGON_CB_INDEX] = (settings->SoftwareGdi) ? FALSE : TRUE; + + settings->OrderSupport[NEG_ELLIPSE_SC_INDEX] = FALSE; + settings->OrderSupport[NEG_ELLIPSE_CB_INDEX] = FALSE; + + return xfi; +} + +void freerdp_client_free(xfInfo* xfi) +{ + if (xfi) + { + int index; + rdpContext* context; + + xf_window_free(xfi); + + free(xfi->bmp_codec_none); + + XCloseDisplay(xfi->display); + + context = (rdpContext*) xfi->context; + + for (index = 0; index < context->argc; index++) + free(context->argv[index]); + + free(context->argv); + + freerdp_context_free(xfi->instance); + freerdp_free(xfi->instance); + + free(xfi); + } } diff --git a/client/X11/xfreerdp.h b/client/X11/xf_interface.h similarity index 84% rename from client/X11/xfreerdp.h rename to client/X11/xf_interface.h index 992c2edac..9f4483fc8 100644 --- a/client/X11/xfreerdp.h +++ b/client/X11/xf_interface.h @@ -1,8 +1,8 @@ /** * FreeRDP: A Remote Desktop Protocol Implementation - * X11 Client + * X11 Client Interface * - * Copyright 2011 Marc-Andre Moreau + * Copyright 2013 Marc-Andre Moreau * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,26 +17,32 @@ * limitations under the License. */ -#ifndef __XFREERDP_H -#define __XFREERDP_H - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif +#ifndef __XF_INTERFACE_H +#define __XF_INTERFACE_H +#include #include -#include + #include #include #include #include #include +#include + +#include +#include +#include typedef struct xf_info xfInfo; #include "xf_window.h" #include "xf_monitor.h" +#ifdef __cplusplus +extern "C" { +#endif + struct xf_WorkArea { UINT32 x; @@ -82,6 +88,9 @@ struct xf_info xfContext* context; rdpContext* _context; + rdpClient* client; + rdpSettings* settings; + GC gc; int bpp; int xfds; @@ -105,7 +114,6 @@ struct xf_info BOOL fullscreen; BOOL grab_keyboard; BOOL unobscured; - BOOL decorations; BOOL debug; xfWindow* window; xfWorkArea workArea; @@ -113,12 +121,11 @@ struct xf_info BOOL remote_app; BOOL disconnect; HCLRCONV clrconv; - Window parent_window; HANDLE mutex; + HANDLE thread; BOOL UseXThreads; HGDI_DC hdc; - BOOL sw_gdi; BYTE* primary_buffer; BOOL frame_begin; @@ -129,7 +136,6 @@ struct xf_info BOOL focused; BOOL mouse_active; - BOOL mouse_motion; BOOL suppress_output; BOOL fullscreen_toggle; UINT32 keyboard_layout_id; @@ -218,16 +224,25 @@ enum XF_EXIT_CODE void xf_lock_x11(xfInfo* xfi, BOOL display); void xf_unlock_x11(xfInfo* xfi, BOOL display); -#ifdef WITH_DEBUG_X11 -#define DEBUG_X11(fmt, ...) DEBUG_CLASS(X11, fmt, ## __VA_ARGS__) -#else -#define DEBUG_X11(fmt, ...) DEBUG_NULL(fmt, ## __VA_ARGS__) +DWORD xf_exit_code_from_disconnect_reason(DWORD reason); + +/** + * Client Interface + */ + +#define cfInfo xfInfo + +FREERDP_API int freerdp_client_global_init(); +FREERDP_API int freerdp_client_global_uninit(); + +FREERDP_API int freerdp_client_start(cfInfo* cfi); +FREERDP_API int freerdp_client_stop(cfInfo* cfi); + +FREERDP_API cfInfo* freerdp_client_new(int argc, char** argv); +FREERDP_API void freerdp_client_free(cfInfo* cfi); + +#ifdef __cplusplus +} #endif -#ifdef WITH_DEBUG_X11_LOCAL_MOVESIZE -#define DEBUG_X11_LMS(fmt, ...) DEBUG_CLASS(X11_LMS, fmt, ## __VA_ARGS__) -#else -#define DEBUG_X11_LMS(fmt, ...) DEBUG_NULL(fmt, ## __VA_ARGS__) -#endif - -#endif /* __XFREERDP_H */ +#endif /* __XF_INTERFACE_H */ diff --git a/client/X11/xf_keyboard.c b/client/X11/xf_keyboard.c index 7f4849d1f..73ae107da 100644 --- a/client/X11/xf_keyboard.c +++ b/client/X11/xf_keyboard.c @@ -97,7 +97,7 @@ void xf_kbd_send_key(xfInfo* xfi, BOOL down, BYTE keycode) if (rdp_scancode == RDP_SCANCODE_UNKNOWN) { - printf("Unknown key with X keycode 0x%02x\n", keycode); + fprintf(stderr, "Unknown key with X keycode 0x%02x\n", keycode); } else if (rdp_scancode == RDP_SCANCODE_PAUSE && !xf_kbd_key_pressed(xfi, XK_Control_L) && !xf_kbd_key_pressed(xfi, XK_Control_R)) diff --git a/client/X11/xf_keyboard.h b/client/X11/xf_keyboard.h index ec90e31c6..01ec6111a 100644 --- a/client/X11/xf_keyboard.h +++ b/client/X11/xf_keyboard.h @@ -22,7 +22,7 @@ #include -#include "xfreerdp.h" +#include "xf_interface.h" void xf_kbd_init(xfInfo* xfi); void xf_kbd_clear(xfInfo* xfi); diff --git a/client/X11/xf_monitor.h b/client/X11/xf_monitor.h index 42196f1da..1020817e6 100644 --- a/client/X11/xf_monitor.h +++ b/client/X11/xf_monitor.h @@ -40,7 +40,7 @@ struct _VIRTUAL_SCREEN }; typedef struct _VIRTUAL_SCREEN VIRTUAL_SCREEN; -#include "xfreerdp.h" +#include "xf_interface.h" BOOL xf_detect_monitors(xfInfo* xfi, rdpSettings* settings); diff --git a/client/X11/xf_rail.c b/client/X11/xf_rail.c index fe9f1c8b6..66ec20dae 100644 --- a/client/X11/xf_rail.c +++ b/client/X11/xf_rail.c @@ -32,9 +32,15 @@ #include "xf_window.h" #include "xf_rail.h" +#ifdef WITH_DEBUG_X11_LOCAL_MOVESIZE +#define DEBUG_X11_LMS(fmt, ...) DEBUG_CLASS(X11_LMS, fmt, ## __VA_ARGS__) +#else +#define DEBUG_X11_LMS(fmt, ...) DEBUG_NULL(fmt, ## __VA_ARGS__) +#endif + void xf_rail_enable_remoteapp_mode(xfInfo* xfi) { - if (xfi->remote_app == FALSE) + if (!xfi->remote_app) { xfi->remote_app = TRUE; xfi->drawable = DefaultRootWindow(xfi->display); @@ -45,7 +51,7 @@ void xf_rail_enable_remoteapp_mode(xfInfo* xfi) void xf_rail_disable_remoteapp_mode(xfInfo* xfi) { - if (xfi->remote_app == TRUE) + if (xfi->remote_app) { xfi->remote_app = FALSE; xf_create_window(xfi); @@ -101,9 +107,10 @@ void xf_rail_paint(xfInfo* xfi, rdpRail* rail, INT32 uleft, INT32 utop, UINT32 u void xf_rail_DesktopNonMonitored(rdpRail *rail, rdpWindow* window) { - xfInfo* xfi; - xfi = (xfInfo*) rail->extra; - xf_rail_disable_remoteapp_mode(xfi); + xfInfo* xfi; + + xfi = (xfInfo*) rail->extra; + xf_rail_disable_remoteapp_mode(xfi); } static void xf_rail_CreateWindow(rdpRail* rail, rdpWindow* window) @@ -242,25 +249,23 @@ void xf_rail_register_callbacks(xfInfo* xfi, rdpRail* rail) rail->rail_DesktopNonMonitored = xf_rail_DesktopNonMonitored; } -static void xf_on_free_rail_client_event(RDP_EVENT* event) +static void xf_on_free_rail_client_event(wMessage* event) { - if (event->event_class == RDP_EVENT_CLASS_RAIL) - { - rail_free_cloned_order(event->event_type, event->user_data); - } + rail_free_cloned_order(GetMessageType(event->id), event->wParam); } static void xf_send_rail_client_event(rdpChannels* channels, UINT16 event_type, void* param) { - RDP_EVENT* out_event = NULL; + wMessage* out_event = NULL; void* payload = NULL; payload = rail_clone_order(event_type, param); if (payload != NULL) { - out_event = freerdp_event_new(RDP_EVENT_CLASS_RAIL, event_type, + out_event = freerdp_event_new(RailChannel_Class, event_type, xf_on_free_rail_client_event, payload); + freerdp_channels_send_event(channels, out_event); } } @@ -283,7 +288,7 @@ void xf_rail_send_activate(xfInfo* xfi, Window xwindow, BOOL enabled) activate.windowId = rail_window->windowId; activate.enabled = enabled; - xf_send_rail_client_event(channels, RDP_EVENT_TYPE_RAIL_CLIENT_ACTIVATE, &activate); + xf_send_rail_client_event(channels, RailChannel_ClientActivate, &activate); } void xf_rail_send_client_system_command(xfInfo* xfi, UINT32 windowId, UINT16 command) @@ -296,7 +301,7 @@ void xf_rail_send_client_system_command(xfInfo* xfi, UINT32 windowId, UINT16 com syscommand.windowId = windowId; syscommand.command = command; - xf_send_rail_client_event(channels, RDP_EVENT_TYPE_RAIL_CLIENT_SYSCOMMAND, &syscommand); + xf_send_rail_client_event(channels, RailChannel_ClientSystemCommand, &syscommand); } /** @@ -305,7 +310,7 @@ void xf_rail_send_client_system_command(xfInfo* xfi, UINT32 windowId, UINT16 com * send an update to the RDP server informing it of the new window position * and size. */ -void xf_rail_adjust_position(xfInfo* xfi, rdpWindow *window) +void xf_rail_adjust_position(xfInfo* xfi, rdpWindow* window) { xfWindow* xfw; rdpChannels* channels; @@ -362,7 +367,7 @@ void xf_rail_adjust_position(xfInfo* xfi, rdpWindow *window) window->windowOffsetX, window->windowOffsetY, window->windowWidth, window->windowHeight); - xf_send_rail_client_event(channels, RDP_EVENT_TYPE_RAIL_CLIENT_WINDOW_MOVE, &window_move); + xf_send_rail_client_event(channels, RailChannel_ClientWindowMove, &window_move); } } @@ -416,8 +421,7 @@ void xf_rail_end_local_move(xfInfo* xfi, rdpWindow *window) window_move.right = window_move.left + xfw->width; /* In the update to RDP the position is one past the window */ window_move.bottom = window_move.top + xfw->height; - xf_send_rail_client_event(channels, - RDP_EVENT_TYPE_RAIL_CLIENT_WINDOW_MOVE, &window_move); + xf_send_rail_client_event(channels, RailChannel_ClientWindowMove, &window_move); /* * Simulate button up at new position to end the local move (per RDP spec) @@ -450,11 +454,11 @@ void xf_rail_end_local_move(xfInfo* xfi, rdpWindow *window) xfw->local_move.state = LMS_TERMINATING; } -void xf_process_rail_get_sysparams_event(xfInfo* xfi, rdpChannels* channels, RDP_EVENT* event) +void xf_process_rail_get_sysparams_event(xfInfo* xfi, rdpChannels* channels, wMessage* event) { RAIL_SYSPARAM_ORDER* sysparam; - sysparam = (RAIL_SYSPARAM_ORDER*) event->user_data; + sysparam = (RAIL_SYSPARAM_ORDER*) event->wParam; sysparam->workArea.left = xfi->workArea.x; sysparam->workArea.top = xfi->workArea.y; @@ -468,7 +472,7 @@ void xf_process_rail_get_sysparams_event(xfInfo* xfi, rdpChannels* channels, RDP sysparam->dragFullWindows = FALSE; - xf_send_rail_client_event(channels, RDP_EVENT_TYPE_RAIL_CLIENT_SET_SYSPARAMS, sysparam); + xf_send_rail_client_event(channels, RailChannel_ClientSystemParam, sysparam); } const char* error_code_names[] = @@ -482,15 +486,15 @@ const char* error_code_names[] = "RAIL_EXEC_E_SESSION_LOCKED" }; -void xf_process_rail_exec_result_event(xfInfo* xfi, rdpChannels* channels, RDP_EVENT* event) +void xf_process_rail_exec_result_event(xfInfo* xfi, rdpChannels* channels, wMessage* event) { RAIL_EXEC_RESULT_ORDER* exec_result; - exec_result = (RAIL_EXEC_RESULT_ORDER*) event->user_data; + exec_result = (RAIL_EXEC_RESULT_ORDER*) event->wParam; if (exec_result->execResult != RAIL_EXEC_S_OK) { - printf("RAIL exec error: execResult=%s NtError=0x%X\n", + fprintf(stderr, "RAIL exec error: execResult=%s NtError=0x%X\n", error_code_names[exec_result->execResult], exec_result->rawResult); xfi->disconnect = True; } @@ -500,9 +504,9 @@ void xf_process_rail_exec_result_event(xfInfo* xfi, rdpChannels* channels, RDP_E } } -void xf_process_rail_server_sysparam_event(xfInfo* xfi, rdpChannels* channels, RDP_EVENT* event) +void xf_process_rail_server_sysparam_event(xfInfo* xfi, rdpChannels* channels, wMessage* event) { - RAIL_SYSPARAM_ORDER* sysparam = (RAIL_SYSPARAM_ORDER*) event->user_data; + RAIL_SYSPARAM_ORDER* sysparam = (RAIL_SYSPARAM_ORDER*) event->wParam; switch (sysparam->param) { @@ -514,11 +518,11 @@ void xf_process_rail_server_sysparam_event(xfInfo* xfi, rdpChannels* channels, R } } -void xf_process_rail_server_minmaxinfo_event(xfInfo* xfi, rdpChannels* channels, RDP_EVENT* event) +void xf_process_rail_server_minmaxinfo_event(xfInfo* xfi, rdpChannels* channels, wMessage* event) { rdpRail* rail; rdpWindow* rail_window = NULL; - RAIL_MINMAXINFO_ORDER* minmax = (RAIL_MINMAXINFO_ORDER*) event->user_data; + RAIL_MINMAXINFO_ORDER* minmax = (RAIL_MINMAXINFO_ORDER*) event->wParam; rail = ((rdpContext*) xfi->context)->rail; rail_window = window_list_get_by_id(rail->list, minmax->windowId); @@ -556,14 +560,14 @@ const char* movetype_names[] = "RAIL_WMSZ_KEYSIZE" }; -void xf_process_rail_server_localmovesize_event(xfInfo* xfi, rdpChannels* channels, RDP_EVENT* event) +void xf_process_rail_server_localmovesize_event(xfInfo* xfi, rdpChannels* channels, wMessage* event) { int x, y; rdpRail* rail; int direction = 0; Window child_window; rdpWindow* rail_window = NULL; - RAIL_LOCALMOVESIZE_ORDER* movesize = (RAIL_LOCALMOVESIZE_ORDER*) event->user_data; + RAIL_LOCALMOVESIZE_ORDER* movesize = (RAIL_LOCALMOVESIZE_ORDER*) event->wParam; rail = ((rdpContext*) xfi->context)->rail; rail_window = window_list_get_by_id(rail->list, movesize->windowId); @@ -648,56 +652,56 @@ void xf_process_rail_server_localmovesize_event(xfInfo* xfi, rdpChannels* channe } } -void xf_process_rail_appid_resp_event(xfInfo* xfi, rdpChannels* channels, RDP_EVENT* event) +void xf_process_rail_appid_resp_event(xfInfo* xfi, rdpChannels* channels, wMessage* event) { RAIL_GET_APPID_RESP_ORDER* appid_resp = - (RAIL_GET_APPID_RESP_ORDER*) event->user_data; + (RAIL_GET_APPID_RESP_ORDER*) event->wParam; - printf("Server Application ID Response PDU: windowId=0x%X " + fprintf(stderr, "Server Application ID Response PDU: windowId=0x%X " "applicationId=(length=%d dump)\n", appid_resp->windowId, appid_resp->applicationId.length); winpr_HexDump(appid_resp->applicationId.string, appid_resp->applicationId.length); } -void xf_process_rail_langbarinfo_event(xfInfo* xfi, rdpChannels* channels, RDP_EVENT* event) +void xf_process_rail_langbarinfo_event(xfInfo* xfi, rdpChannels* channels, wMessage* event) { RAIL_LANGBAR_INFO_ORDER* langbar = - (RAIL_LANGBAR_INFO_ORDER*) event->user_data; + (RAIL_LANGBAR_INFO_ORDER*) event->wParam; - printf("Language Bar Information PDU: languageBarStatus=0x%X\n", + fprintf(stderr, "Language Bar Information PDU: languageBarStatus=0x%X\n", langbar->languageBarStatus); } -void xf_process_rail_event(xfInfo* xfi, rdpChannels* channels, RDP_EVENT* event) +void xf_process_rail_event(xfInfo* xfi, rdpChannels* channels, wMessage* event) { - switch (event->event_type) + switch (GetMessageType(event->id)) { - case RDP_EVENT_TYPE_RAIL_CHANNEL_GET_SYSPARAMS: + case RailChannel_GetSystemParam: xf_process_rail_get_sysparams_event(xfi, channels, event); break; - case RDP_EVENT_TYPE_RAIL_CHANNEL_EXEC_RESULTS: + case RailChannel_ServerExecuteResult: xf_process_rail_exec_result_event(xfi, channels, event); break; - case RDP_EVENT_TYPE_RAIL_CHANNEL_SERVER_SYSPARAM: + case RailChannel_ServerSystemParam: xf_process_rail_server_sysparam_event(xfi, channels, event); break; - case RDP_EVENT_TYPE_RAIL_CHANNEL_SERVER_MINMAXINFO: + case RailChannel_ServerMinMaxInfo: xf_process_rail_server_minmaxinfo_event(xfi, channels, event); break; - case RDP_EVENT_TYPE_RAIL_CHANNEL_SERVER_LOCALMOVESIZE: + case RailChannel_ServerLocalMoveSize: xf_process_rail_server_localmovesize_event(xfi, channels, event); break; - case RDP_EVENT_TYPE_RAIL_CHANNEL_APPID_RESP: + case RailChannel_ServerGetAppIdResponse: xf_process_rail_appid_resp_event(xfi, channels, event); break; - case RDP_EVENT_TYPE_RAIL_CHANNEL_LANGBARINFO: + case RailChannel_ServerLanguageBarInfo: xf_process_rail_langbarinfo_event(xfi, channels, event); break; diff --git a/client/X11/xf_rail.h b/client/X11/xf_rail.h index 67c24791c..e395681c9 100644 --- a/client/X11/xf_rail.h +++ b/client/X11/xf_rail.h @@ -20,14 +20,16 @@ #ifndef __XF_RAIL_H #define __XF_RAIL_H -#include "xfreerdp.h" +#include "xf_interface.h" void xf_rail_paint(xfInfo* xfi, rdpRail* rail, INT32 uleft, INT32 utop, UINT32 uright, UINT32 ubottom); void xf_rail_register_callbacks(xfInfo* xfi, rdpRail* rail); void xf_rail_send_client_system_command(xfInfo* xfi, UINT32 windowId, UINT16 command); void xf_rail_send_activate(xfInfo* xfi, Window xwindow, BOOL enabled); -void xf_process_rail_event(xfInfo* xfi, rdpChannels* chanman, RDP_EVENT* event); -void xf_rail_adjust_position(xfInfo* xfi, rdpWindow *window); -void xf_rail_end_local_move(xfInfo* xfi, rdpWindow *window); +void xf_process_rail_event(xfInfo* xfi, rdpChannels* channels, wMessage* event); +void xf_rail_adjust_position(xfInfo* xfi, rdpWindow* window); +void xf_rail_end_local_move(xfInfo* xfi, rdpWindow* window); +void xf_rail_enable_remoteapp_mode(xfInfo* xfi); +void xf_rail_disable_remoteapp_mode(xfInfo* xfi); #endif /* __XF_RAIL_H */ diff --git a/client/X11/xf_tsmf.c b/client/X11/xf_tsmf.c index 21a8cfa8b..420ff818f 100644 --- a/client/X11/xf_tsmf.c +++ b/client/X11/xf_tsmf.c @@ -140,7 +140,7 @@ void xf_tsmf_init(xfInfo* xfi, long xv_port) XFree(attr); #ifdef WITH_DEBUG_XV - printf("xf_tsmf_init: pixel format "); + fprintf(stderr, "xf_tsmf_init: pixel format "); #endif fo = XvListImageFormats(xfi->display, xv->xv_port, &ret); if (ret > 0) @@ -152,7 +152,7 @@ void xf_tsmf_init(xfInfo* xfi, long xv_port) { xv->xv_pixfmts[i] = fo[i].id; #ifdef WITH_DEBUG_XV - printf("%c%c%c%c ", ((char*)(xv->xv_pixfmts + i))[0], ((char*)(xv->xv_pixfmts + i))[1], + fprintf(stderr, "%c%c%c%c ", ((char*)(xv->xv_pixfmts + i))[0], ((char*)(xv->xv_pixfmts + i))[1], ((char*)(xv->xv_pixfmts + i))[2], ((char*)(xv->xv_pixfmts + i))[3]); #endif } @@ -160,7 +160,7 @@ void xf_tsmf_init(xfInfo* xfi, long xv_port) } XFree(fo); #ifdef WITH_DEBUG_XV - printf("\n"); + fprintf(stderr, "\n"); #endif } @@ -375,15 +375,15 @@ static void xf_process_tsmf_redraw_event(xfInfo* xfi, RDP_REDRAW_EVENT* revent) revent->x, revent->y, revent->width, revent->height, revent->x, revent->y); } -void xf_process_tsmf_event(xfInfo* xfi, RDP_EVENT* event) +void xf_process_tsmf_event(xfInfo* xfi, wMessage* event) { - switch (event->event_type) + switch (GetMessageType(event->id)) { - case RDP_EVENT_TYPE_TSMF_VIDEO_FRAME: + case TsmfChannel_VideoFrame: xf_process_tsmf_video_frame_event(xfi, (RDP_VIDEO_FRAME_EVENT*) event); break; - case RDP_EVENT_TYPE_TSMF_REDRAW: + case TsmfChannel_Redraw: xf_process_tsmf_redraw_event(xfi, (RDP_REDRAW_EVENT*) event); break; @@ -400,7 +400,7 @@ void xf_tsmf_uninit(xfInfo* xfi) { } -void xf_process_tsmf_event(xfInfo* xfi, RDP_EVENT* event) +void xf_process_tsmf_event(xfInfo* xfi, wMessage* event) { } diff --git a/client/X11/xf_tsmf.h b/client/X11/xf_tsmf.h index 7e1ca3090..db2395204 100644 --- a/client/X11/xf_tsmf.h +++ b/client/X11/xf_tsmf.h @@ -20,10 +20,10 @@ #ifndef __XF_TSMF_H #define __XF_TSMF_H -#include "xfreerdp.h" +#include "xf_interface.h" void xf_tsmf_init(xfInfo* xfi, long xv_port); void xf_tsmf_uninit(xfInfo* xfi); -void xf_process_tsmf_event(xfInfo* xfi, RDP_EVENT* event); +void xf_process_tsmf_event(xfInfo* xfi, wMessage* event); #endif /* __XF_TSMF_H */ diff --git a/client/X11/xf_window.c b/client/X11/xf_window.c index 7d9345aa6..fd6631c33 100644 --- a/client/X11/xf_window.c +++ b/client/X11/xf_window.c @@ -42,6 +42,18 @@ #include #endif +#ifdef WITH_DEBUG_X11 +#define DEBUG_X11(fmt, ...) DEBUG_CLASS(X11, fmt, ## __VA_ARGS__) +#else +#define DEBUG_X11(fmt, ...) DEBUG_NULL(fmt, ## __VA_ARGS__) +#endif + +#ifdef WITH_DEBUG_X11_LOCAL_MOVESIZE +#define DEBUG_X11_LMS(fmt, ...) DEBUG_CLASS(X11_LMS, fmt, ## __VA_ARGS__) +#else +#define DEBUG_X11_LMS(fmt, ...) DEBUG_NULL(fmt, ## __VA_ARGS__) +#endif + #include "FreeRDP_Icon_256px.h" #define xf_icon_prop FreeRDP_Icon_256px_prop @@ -171,7 +183,7 @@ BOOL xf_GetCurrentDesktop(xfInfo* xfi) status = xf_GetWindowProperty(xfi, DefaultRootWindow(xfi->display), xfi->_NET_CURRENT_DESKTOP, 1, &nitems, &bytes, &prop); - if (status != TRUE) + if (!status) return FALSE; xfi->current_desktop = (int) *prop; @@ -298,7 +310,7 @@ static void xf_SetWindowPID(xfInfo* xfi, xfWindow* window, pid_t pid) { Atom am_wm_pid; - if (pid == 0) + if (!pid) pid = getpid(); am_wm_pid = XInternAtom(xfi->display, "_NET_WM_PID", False); @@ -315,7 +327,7 @@ xfWindow* xf_CreateDesktopWindow(xfInfo* xfi, char* name, int width, int height, window = (xfWindow*) malloc(sizeof(xfWindow)); ZeroMemory(window, sizeof(xfWindow)); - if (window != NULL) + if (window) { int shmid; int input_mask; @@ -356,10 +368,15 @@ xfWindow* xf_CreateDesktopWindow(xfInfo* xfi, char* name, int width, int height, class_hints = XAllocClassHint(); - if (class_hints != NULL) + if (class_hints) { class_hints->res_name = "xfreerdp"; - class_hints->res_class = "xfreerdp"; + + if (xfi->instance->settings->WmClass) + class_hints->res_class = xfi->instance->settings->WmClass; + else + class_hints->res_class = "xfreerdp"; + XSetClassHint(xfi->display, window->handle, class_hints); XFree(class_hints); } @@ -379,8 +396,8 @@ xfWindow* xf_CreateDesktopWindow(xfInfo* xfi, char* name, int width, int height, XChangeProperty(xfi->display, window->handle, xfi->_NET_WM_ICON, XA_CARDINAL, 32, PropModeReplace, (BYTE*) xf_icon_prop, ARRAYSIZE(xf_icon_prop)); - if (xfi->parent_window) - XReparentWindow(xfi->display, window->handle, xfi->parent_window, 0, 0); + if (xfi->settings->ParentWindowId) + XReparentWindow(xfi->display, window->handle, (Window) xfi->settings->ParentWindowId, 0, 0); XSelectInput(xfi->display, window->handle, input_mask); XClearWindow(xfi->display, window->handle); @@ -388,7 +405,7 @@ xfWindow* xf_CreateDesktopWindow(xfInfo* xfi, char* name, int width, int height, /* * NOTE: This must be done here to handle reparenting the window, - * so that we dont miss the event and hang waiting for the next one + * so that we don't miss the event and hang waiting for the next one */ do { @@ -487,10 +504,13 @@ xfWindow* xf_CreateWindow(xfInfo* xfi, rdpWindow* wnd, int x, int y, int width, window->width = width; window->height = height; - /* this window need decorations - the WS_EX_APPWINDOW is used to tell the client to use local decorations - only sent from xrdp */ - window->decorations = (wnd->extendedStyle & WS_EX_APPWINDOW) ? TRUE : FALSE; + /* + * WS_EX_DECORATIONS is used by XRDP and instructs + * the client to use local window decorations + */ + + window->decorations = (wnd->extendedStyle & WS_EX_DECORATIONS) ? TRUE : FALSE; + window->fullscreen = FALSE; window->window = wnd; window->local_move.state = LMS_NOT_ACTIVE; @@ -513,16 +533,27 @@ xfWindow* xf_CreateWindow(xfInfo* xfi, rdpWindow* wnd, int x, int y, int width, class_hints = XAllocClassHint(); - if (class_hints != NULL) + if (class_hints) { - char* class; - class = malloc(sizeof(rail_window_class)); - snprintf(class, sizeof(rail_window_class), "RAIL:%08X", id); + char* class = NULL; + + if (xfi->instance->settings->WmClass != NULL) + { + class_hints->res_class = xfi->instance->settings->WmClass; + } + else + { + class = malloc(sizeof(rail_window_class)); + snprintf(class, sizeof(rail_window_class), "RAIL:%08X", id); + class_hints->res_class = class; + } + class_hints->res_name = "RAIL"; - class_hints->res_class = class; XSetClassHint(xfi->display, window->handle, class_hints); XFree(class_hints); - free(class); + + if (class) + free(class); } /* Set the input mode hint for the WM */ @@ -738,11 +769,9 @@ void xf_ShowWindow(xfInfo* xfi, xfWindow* window, BYTE state) if (window->rail_state == WINDOW_SHOW_MAXIMIZED) window->rail_ignore_configure = TRUE; - if (window->is_transient) - { xf_SetWindowUnlisted(xfi, window); - } + break; } @@ -761,7 +790,7 @@ void xf_SetWindowIcon(xfInfo* xfi, xfWindow* window, rdpIcon* icon) long* dstp; UINT32* srcp; - if (icon->big != TRUE) + if (!icon->big) return; pixels = icon->entry->width * icon->entry->height; @@ -808,8 +837,10 @@ void xf_SetWindowRects(xfInfo* xfi, xfWindow* window, RECTANGLE_16* rects, int n #ifdef WITH_XEXT /* * This is currently unsupported with the new logic to handle window placement with VisibleOffset variables - * XShapeCombineRectangles(xfi->display, window->handle, ShapeBounding, 0, 0, xrects, nrects, ShapeSet, 0); + * + * Marc: enabling it works, and is required for round corners. */ + XShapeCombineRectangles(xfi->display, window->handle, ShapeBounding, 0, 0, xrects, nrects, ShapeSet, 0); #endif free(xrects); @@ -836,8 +867,10 @@ void xf_SetWindowVisibilityRects(xfInfo* xfi, xfWindow* window, RECTANGLE_16* re #ifdef WITH_XEXT /* * This is currently unsupported with the new logic to handle window placement with VisibleOffset variables - * XShapeCombineRectangles(xfi->display, window->handle, ShapeBounding, 0, 0, xrects, nrects, ShapeSet, 0); + * + * Marc: enabling it works, and is required for round corners. */ + XShapeCombineRectangles(xfi->display, window->handle, ShapeBounding, 0, 0, xrects, nrects, ShapeSet, 0); #endif free(xrects); @@ -849,7 +882,7 @@ void xf_UpdateWindowArea(xfInfo* xfi, xfWindow* window, int x, int y, int width, rdpWindow* wnd; wnd = window->window; - /* Remote app mode uses visibleOffset instead of windowOffset */ + /* RemoteApp mode uses visibleOffset instead of windowOffset */ if (!xfi->remote_app) { @@ -876,7 +909,7 @@ void xf_UpdateWindowArea(xfInfo* xfi, xfWindow* window, int x, int y, int width, WaitForSingleObject(xfi->mutex, INFINITE); - if (xfi->sw_gdi) + if (xfi->settings->SoftwareGdi) { XPutImage(xfi->display, xfi->primary, window->gc, xfi->image, ax, ay, ax, ay, width, height); diff --git a/client/X11/xf_window.h b/client/X11/xf_window.h index f5379e8dd..257515925 100644 --- a/client/X11/xf_window.h +++ b/client/X11/xf_window.h @@ -27,7 +27,7 @@ typedef struct xf_localmove xfLocalMove; typedef struct xf_window xfWindow; -#include "xfreerdp.h" +#include "xf_interface.h" // Extended ICCM flags http://standards.freedesktop.org/wm-spec/wm-spec-latest.html #define _NET_WM_MOVERESIZE_SIZE_TOPLEFT 0 diff --git a/client/common/cmdline.c b/client/common/cmdline.c index 28ab422aa..dc5e6a681 100644 --- a/client/common/cmdline.c +++ b/client/common/cmdline.c @@ -52,6 +52,7 @@ COMMAND_LINE_ARGUMENT_A args[] = { "workarea", COMMAND_LINE_VALUE_FLAG, NULL, NULL, NULL, -1, NULL, "Work area" }, { "t", COMMAND_LINE_VALUE_REQUIRED, "", NULL, NULL, -1, "title", "Window title" }, { "decorations", COMMAND_LINE_VALUE_BOOL, NULL, NULL, BoolValueTrue, -1, NULL, "Window decorations" }, + { "smart-sizing", COMMAND_LINE_VALUE_BOOL, NULL, BoolValueFalse, NULL, -1, NULL, "Scale remote desktop to window size" }, { "a", COMMAND_LINE_VALUE_REQUIRED, NULL, NULL, NULL, -1, "addin", "Addin" }, { "vc", COMMAND_LINE_VALUE_REQUIRED, NULL, NULL, NULL, -1, NULL, "Static virtual channel" }, { "dvc", COMMAND_LINE_VALUE_REQUIRED, NULL, NULL, NULL, -1, NULL, "Dynamic virtual channel" }, @@ -62,6 +63,7 @@ COMMAND_LINE_ARGUMENT_A args[] = { "gu", COMMAND_LINE_VALUE_REQUIRED, "[<domain>\\]<user> or <user>[@<domain>]", NULL, NULL, -1, NULL, "Gateway username" }, { "gp", COMMAND_LINE_VALUE_REQUIRED, "<password>", NULL, NULL, -1, NULL, "Gateway password" }, { "gd", COMMAND_LINE_VALUE_REQUIRED, "<domain>", NULL, NULL, -1, NULL, "Gateway domain" }, + { "load-balance-info", COMMAND_LINE_VALUE_REQUIRED, "<info string>", NULL, NULL, -1, NULL, "Load balance info" }, { "app", COMMAND_LINE_VALUE_REQUIRED, "||<alias> or <executable path>", NULL, NULL, -1, NULL, "Remote application program" }, { "app-name", COMMAND_LINE_VALUE_REQUIRED, "<app name>", NULL, NULL, -1, NULL, "Remote application name for user interface" }, { "app-icon", COMMAND_LINE_VALUE_REQUIRED, "<icon path>", NULL, NULL, -1, NULL, "Remote application icon for user interface" }, @@ -123,7 +125,9 @@ COMMAND_LINE_ARGUMENT_A args[] = { "fast-path", COMMAND_LINE_VALUE_BOOL, NULL, BoolValueTrue, NULL, -1, NULL, "fast-path input/output" }, { "async-input", COMMAND_LINE_VALUE_BOOL, NULL, BoolValueFalse, NULL, -1, NULL, "asynchronous input" }, { "async-update", COMMAND_LINE_VALUE_BOOL, NULL, BoolValueFalse, NULL, -1, NULL, "asynchronous update" }, + { "async-transport", COMMAND_LINE_VALUE_BOOL, NULL, BoolValueFalse, NULL, -1, NULL, "asynchronous transport (unstable)" }, { "async-channels", COMMAND_LINE_VALUE_BOOL, NULL, BoolValueFalse, NULL, -1, NULL, "asynchronous channels (unstable)" }, + { "wm-class", COMMAND_LINE_VALUE_REQUIRED, "<class name>", NULL, NULL, -1, NULL, "set the WM_CLASS hint for the window instance" }, { "version", COMMAND_LINE_VALUE_FLAG | COMMAND_LINE_PRINT_VERSION, NULL, NULL, NULL, -1, NULL, "print version" }, { "help", COMMAND_LINE_VALUE_FLAG | COMMAND_LINE_PRINT_HELP, NULL, NULL, NULL, -1, "?", "print help" }, { NULL, 0, NULL, NULL, NULL, -1, NULL, NULL } @@ -931,7 +935,7 @@ int freerdp_client_parse_command_line_arguments(int argc, char** argv, rdpSettin if (compatibility) { - printf("WARNING: Using deprecated command-line interface!\n"); + fprintf(stderr, "WARNING: Using deprecated command-line interface!\n"); return freerdp_client_parse_old_command_line_arguments(argc, argv, settings); } else @@ -988,7 +992,7 @@ int freerdp_client_parse_command_line_arguments(int argc, char** argv, rdpSettin if (!settings->ConnectionFile && !(arg->Flags & COMMAND_LINE_VALUE_PRESENT)) { - printf("error: server hostname was not specified with /v:<server>[:port]\n"); + fprintf(stderr, "error: server hostname was not specified with /v:<server>[:port]\n"); return COMMAND_LINE_ERROR_MISSING_ARGUMENT; } @@ -1088,6 +1092,10 @@ int freerdp_client_parse_command_line_arguments(int argc, char** argv, rdpSettin { settings->Decorations = arg->Value ? TRUE : FALSE; } + CommandLineSwitchCase(arg, "smart-sizing") + { + settings->SmartSizing = arg->Value ? TRUE : FALSE; + } CommandLineSwitchCase(arg, "bpp") { settings->ColorDepth = atoi(arg->Value); @@ -1112,7 +1120,7 @@ int freerdp_client_parse_command_line_arguments(int argc, char** argv, rdpSettin if (!id) { - printf("Could not identify keyboard layout: %s\n", arg->Value); + fprintf(stderr, "Could not identify keyboard layout: %s\n", arg->Value); } } @@ -1207,6 +1215,11 @@ int freerdp_client_parse_command_line_arguments(int argc, char** argv, rdpSettin settings->DisableWallpaper = TRUE; settings->DisableFullWindowDrag = TRUE; } + CommandLineSwitchCase(arg, "load-balance-info") + { + settings->LoadBalanceInfo = (BYTE*) _strdup(arg->Value); + settings->LoadBalanceInfoLength = strlen((char*) settings->LoadBalanceInfo); + } CommandLineSwitchCase(arg, "app-name") { settings->RemoteApplicationName = _strdup(arg->Value); @@ -1411,7 +1424,7 @@ int freerdp_client_parse_command_line_arguments(int argc, char** argv, rdpSettin } else { - printf("unknown protocol security: %s\n", arg->Value); + fprintf(stderr, "unknown protocol security: %s\n", arg->Value); } } CommandLineSwitchCase(arg, "sec-rdp") @@ -1511,6 +1524,14 @@ int freerdp_client_parse_command_line_arguments(int argc, char** argv, rdpSettin { settings->AsyncChannels = arg->Value ? TRUE : FALSE; } + CommandLineSwitchCase(arg, "async-transport") + { + settings->AsyncTransport = arg->Value ? TRUE : FALSE; + } + CommandLineSwitchCase(arg, "wm-class") + { + settings->WmClass = _strdup(arg->Value); + } CommandLineSwitchDefault(arg) { @@ -1582,7 +1603,7 @@ int freerdp_client_load_static_channel_addin(rdpChannels* channels, rdpSettings* { if (freerdp_channels_client_load(channels, settings, entry, data) == 0) { - printf("loading channel %s\n", name); + fprintf(stderr, "loading channel %s\n", name); return 0; } } diff --git a/client/common/compatibility.c b/client/common/compatibility.c index f3dc49df3..8f14199b9 100644 --- a/client/common/compatibility.c +++ b/client/common/compatibility.c @@ -121,7 +121,7 @@ int freerdp_client_old_process_plugin(rdpSettings* settings, ADDIN_ARGV* args) if (strcmp(args->argv[0], "cliprdr") == 0) { settings->RedirectClipboard = TRUE; - printf("--plugin cliprdr -> +clipboard\n"); + fprintf(stderr, "--plugin cliprdr -> +clipboard\n"); } else if (strcmp(args->argv[0], "rdpdr") == 0) { @@ -401,37 +401,37 @@ int freerdp_client_parse_old_command_line_arguments(int argc, char** argv, rdpSe CommandLineSwitchCase(arg, "0") { settings->ConsoleSession = TRUE; - printf("-0 -> /admin\n"); + fprintf(stderr, "-0 -> /admin\n"); } CommandLineSwitchCase(arg, "a") { settings->ColorDepth = atoi(arg->Value); - printf("-a %s -> /bpp:%s\n", arg->Value, arg->Value); + fprintf(stderr, "-a %s -> /bpp:%s\n", arg->Value, arg->Value); } CommandLineSwitchCase(arg, "c") { settings->ShellWorkingDirectory = _strdup(arg->Value); - printf("-c %s -> /shell-dir:%s\n", arg->Value, arg->Value); + fprintf(stderr, "-c %s -> /shell-dir:%s\n", arg->Value, arg->Value); } CommandLineSwitchCase(arg, "D") { settings->Decorations = FALSE; - printf("-D -> -decorations\n"); + fprintf(stderr, "-D -> -decorations\n"); } CommandLineSwitchCase(arg, "T") { settings->WindowTitle = _strdup(arg->Value); - printf("-T %s -> /title:%s\n", arg->Value, arg->Value); + fprintf(stderr, "-T %s -> /title:%s\n", arg->Value, arg->Value); } CommandLineSwitchCase(arg, "d") { settings->Domain = _strdup(arg->Value); - printf("-d %s -> /d:%s\n", arg->Value, arg->Value); + fprintf(stderr, "-d %s -> /d:%s\n", arg->Value, arg->Value); } CommandLineSwitchCase(arg, "f") { settings->Fullscreen = TRUE; - printf("-f -> /f\n"); + fprintf(stderr, "-f -> /f\n"); } CommandLineSwitchCase(arg, "g") { @@ -448,18 +448,18 @@ int freerdp_client_parse_old_command_line_arguments(int argc, char** argv, rdpSe free(str); - printf("-g %s -> /size:%s or /w:%d /h:%d\n", arg->Value, arg->Value, + fprintf(stderr, "-g %s -> /size:%s or /w:%d /h:%d\n", arg->Value, arg->Value, settings->DesktopWidth, settings->DesktopHeight); } CommandLineSwitchCase(arg, "k") { sscanf(arg->Value, "%X", &(settings->KeyboardLayout)); - printf("-k %s -> /kbd:%s\n", arg->Value, arg->Value); + fprintf(stderr, "-k %s -> /kbd:%s\n", arg->Value, arg->Value); } CommandLineSwitchCase(arg, "K") { settings->GrabKeyboard = FALSE; - printf("-K -> -grab-keyboard\n"); + fprintf(stderr, "-K -> -grab-keyboard\n"); } CommandLineSwitchCase(arg, "n") { @@ -468,27 +468,27 @@ int freerdp_client_parse_old_command_line_arguments(int argc, char** argv, rdpSe CommandLineSwitchCase(arg, "o") { settings->RemoteConsoleAudio = TRUE; - printf("-o -> /audio-mode:1\n"); + fprintf(stderr, "-o -> /audio-mode:1\n"); } CommandLineSwitchCase(arg, "p") { settings->Password = _strdup(arg->Value); - printf("-p %s -> /p:%s\n", arg->Value, arg->Value); + fprintf(stderr, "-p %s -> /p:%s\n", arg->Value, arg->Value); } CommandLineSwitchCase(arg, "s") { settings->AlternateShell = _strdup(arg->Value); - printf("-s %s -> /shell:%s\n", arg->Value, arg->Value); + fprintf(stderr, "-s %s -> /shell:%s\n", arg->Value, arg->Value); } CommandLineSwitchCase(arg, "t") { settings->ServerPort = atoi(arg->Value); - printf("-t %s -> /port:%s\n", arg->Value, arg->Value); + fprintf(stderr, "-t %s -> /port:%s\n", arg->Value, arg->Value); } CommandLineSwitchCase(arg, "u") { settings->Username = _strdup(arg->Value); - printf("-u %s -> /u:%s\n", arg->Value, arg->Value); + fprintf(stderr, "-u %s -> /u:%s\n", arg->Value, arg->Value); } CommandLineSwitchCase(arg, "x") { @@ -515,31 +515,31 @@ int freerdp_client_parse_old_command_line_arguments(int argc, char** argv, rdpSe settings->PerformanceFlags = type; } - printf("-x %s -> /network ", arg->Value); + fprintf(stderr, "-x %s -> /network ", arg->Value); if (type == CONNECTION_TYPE_MODEM) - printf("modem"); + fprintf(stderr, "modem"); else if (CONNECTION_TYPE_BROADBAND_HIGH) - printf("broadband"); + fprintf(stderr, "broadband"); else if (CONNECTION_TYPE_LAN) - printf("lan"); + fprintf(stderr, "lan"); - printf("\n"); + fprintf(stderr, "\n"); } CommandLineSwitchCase(arg, "X") { settings->ParentWindowId = strtol(arg->Value, NULL, 0); - printf("-X %s -> /parent-window:%s\n", arg->Value, arg->Value); + fprintf(stderr, "-X %s -> /parent-window:%s\n", arg->Value, arg->Value); } CommandLineSwitchCase(arg, "z") { settings->CompressionEnabled = TRUE; - printf("-z -> /compression\n"); + fprintf(stderr, "-z -> /compression\n"); } CommandLineSwitchCase(arg, "app") { settings->RemoteApplicationMode = TRUE; - printf("--app -> /app + program name or alias\n"); + fprintf(stderr, "--app -> /app + program name or alias\n"); } CommandLineSwitchCase(arg, "ext") { @@ -548,7 +548,7 @@ int freerdp_client_parse_old_command_line_arguments(int argc, char** argv, rdpSe CommandLineSwitchCase(arg, "no-auth") { settings->Authentication = FALSE; - printf("--no-auth -> -authentication\n"); + fprintf(stderr, "--no-auth -> -authentication\n"); } CommandLineSwitchCase(arg, "authonly") { @@ -562,12 +562,12 @@ int freerdp_client_parse_old_command_line_arguments(int argc, char** argv, rdpSe { settings->FastPathInput = FALSE; settings->FastPathOutput = FALSE; - printf("--no-fastpath -> -fast-path\n"); + fprintf(stderr, "--no-fastpath -> -fast-path\n"); } CommandLineSwitchCase(arg, "no-motion") { settings->MouseMotion = FALSE; - printf("--no-motion -> -mouse-motion\n"); + fprintf(stderr, "--no-motion -> -mouse-motion\n"); } CommandLineSwitchCase(arg, "gdi") { @@ -576,26 +576,26 @@ int freerdp_client_parse_old_command_line_arguments(int argc, char** argv, rdpSe else if (strcmp(arg->Value, "hw") == 0) settings->SoftwareGdi = FALSE; - printf("--gdi %s -> /gdi:%s\n", arg->Value, arg->Value); + fprintf(stderr, "--gdi %s -> /gdi:%s\n", arg->Value, arg->Value); } CommandLineSwitchCase(arg, "no-osb") { settings->OffscreenSupportLevel = FALSE; - printf("--no-osb -> -offscreen-cache\n"); + fprintf(stderr, "--no-osb -> -offscreen-cache\n"); } CommandLineSwitchCase(arg, "no-bmp-cache") { settings->BitmapCacheEnabled = FALSE; - printf("--no-bmp-cache -> -bitmap-cache\n"); + fprintf(stderr, "--no-bmp-cache -> -bitmap-cache\n"); } CommandLineSwitchCase(arg, "plugin") { - printf("--plugin -> /a, /vc, /dvc and channel-specific options\n"); + fprintf(stderr, "--plugin -> /a, /vc, /dvc and channel-specific options\n"); } CommandLineSwitchCase(arg, "rfx") { settings->RemoteFxCodec = TRUE; - printf("--rfx -> /rfx\n"); + fprintf(stderr, "--rfx -> /rfx\n"); } CommandLineSwitchCase(arg, "rfx-mode") { @@ -604,37 +604,37 @@ int freerdp_client_parse_old_command_line_arguments(int argc, char** argv, rdpSe else if (arg->Value[0] == 'i') settings->RemoteFxCodecMode = 0x02; - printf("--rfx-mode -> /rfx-mode\n"); + fprintf(stderr, "--rfx-mode -> /rfx-mode\n"); } CommandLineSwitchCase(arg, "nsc") { settings->NSCodec = TRUE; - printf("--nsc -> /nsc\n"); + fprintf(stderr, "--nsc -> /nsc\n"); } CommandLineSwitchCase(arg, "disable-wallpaper") { settings->DisableWallpaper = TRUE; - printf("--disable-wallpaper -> -wallpaper\n"); + fprintf(stderr, "--disable-wallpaper -> -wallpaper\n"); } CommandLineSwitchCase(arg, "composition") { settings->AllowDesktopComposition = TRUE; - printf("--composition -> +composition\n"); + fprintf(stderr, "--composition -> +composition\n"); } CommandLineSwitchCase(arg, "disable-full-window-drag") { settings->DisableFullWindowDrag = TRUE; - printf("--disable-full-window-drag -> -window-drag\n"); + fprintf(stderr, "--disable-full-window-drag -> -window-drag\n"); } CommandLineSwitchCase(arg, "disable-menu-animations") { settings->DisableMenuAnims = TRUE; - printf("--disable-menu-animations -> -menu-anims\n"); + fprintf(stderr, "--disable-menu-animations -> -menu-anims\n"); } CommandLineSwitchCase(arg, "disable-theming") { settings->DisableThemes = TRUE; - printf("--disable-theming -> -themes\n"); + fprintf(stderr, "--disable-theming -> -themes\n"); } CommandLineSwitchCase(arg, "ntlm") { @@ -643,7 +643,7 @@ int freerdp_client_parse_old_command_line_arguments(int argc, char** argv, rdpSe CommandLineSwitchCase(arg, "ignore-certificate") { settings->IgnoreCertificate = TRUE; - printf("--ignore-certificate -> /cert-ignore\n"); + fprintf(stderr, "--ignore-certificate -> /cert-ignore\n"); } CommandLineSwitchCase(arg, "sec") { @@ -669,22 +669,22 @@ int freerdp_client_parse_old_command_line_arguments(int argc, char** argv, rdpSe settings->NlaSecurity = TRUE; } - printf("--sec %s -> /sec:%s\n", arg->Value, arg->Value); + fprintf(stderr, "--sec %s -> /sec:%s\n", arg->Value, arg->Value); } CommandLineSwitchCase(arg, "no-rdp") { settings->RdpSecurity = FALSE; - printf("--no-rdp -> -sec-rdp\n"); + fprintf(stderr, "--no-rdp -> -sec-rdp\n"); } CommandLineSwitchCase(arg, "no-tls") { settings->TlsSecurity = FALSE; - printf("--no-tls -> -sec-tls\n"); + fprintf(stderr, "--no-tls -> -sec-tls\n"); } CommandLineSwitchCase(arg, "no-nla") { settings->NlaSecurity = FALSE; - printf("--no-nla -> -sec-nla\n"); + fprintf(stderr, "--no-nla -> -sec-nla\n"); } CommandLineSwitchCase(arg, "secure-checksum") { @@ -699,12 +699,12 @@ int freerdp_client_parse_old_command_line_arguments(int argc, char** argv, rdpSe } while ((arg = CommandLineFindNextArgumentA(arg)) != NULL); - printf("%s -> /v:%s", settings->ServerHostname, settings->ServerHostname); + fprintf(stderr, "%s -> /v:%s", settings->ServerHostname, settings->ServerHostname); if (settings->ServerPort != 3389) - printf(" /port:%d", settings->ServerPort); + fprintf(stderr, " /port:%d", settings->ServerPort); - printf("\n"); + fprintf(stderr, "\n"); return 1; } diff --git a/client/common/file.c b/client/common/file.c index 0b5cff085..a13ca239b 100644 --- a/client/common/file.c +++ b/client/common/file.c @@ -52,7 +52,7 @@ static WCHAR CR_LF_STR_W[] = { '\r', '\n', '\0' }; BOOL freerdp_client_rdp_file_set_integer(rdpFile* file, char* name, int value) { #ifdef DEBUG_CLIENT_FILE - printf("%s:i:%d\n", name, value); + fprintf(stderr, "%s:i:%d\n", name, value); #endif if (_stricmp(name, "use multimon") == 0) @@ -222,7 +222,7 @@ void freerdp_client_parse_rdp_file_integer_ascii(rdpFile* file, char* name, char BOOL freerdp_client_rdp_file_set_string(rdpFile* file, char* name, char* value) { #ifdef DEBUG_CLIENT_FILE - printf("%s:s:%s\n", name, value); + fprintf(stderr, "%s:s:%s\n", name, value); #endif if (_stricmp(name, "username") == 0) @@ -308,7 +308,7 @@ BOOL freerdp_client_parse_rdp_file_buffer_ascii(rdpFile* file, BYTE* buffer, siz line = strtok_s((char*) buffer, "\r\n", &context); - while (line != NULL) + while (line) { length = strlen(line); @@ -458,8 +458,7 @@ BOOL freerdp_client_parse_rdp_file(rdpFile* file, char* name) if (file_size < 1) return FALSE; - buffer = (BYTE*) malloc(file_size); - + buffer = (BYTE*) malloc(file_size + 2); read_size = fread(buffer, file_size, 1, fp); if (!read_size) @@ -475,6 +474,9 @@ BOOL freerdp_client_parse_rdp_file(rdpFile* file, char* name) return FALSE; } + buffer[file_size] = '\0'; + buffer[file_size + 1] = '\0'; + return freerdp_client_parse_rdp_file_buffer(file, buffer, file_size); } @@ -497,7 +499,7 @@ BOOL freerdp_client_populate_settings_from_rdp_file(rdpFile* file, rdpSettings* if (~file->ServerPort) settings->ServerPort = file->ServerPort; if (~((size_t) file->FullAddress)) - settings->ServerHostname = file->FullAddress; + settings->ServerHostname = _strdup(file->FullAddress); if (~file->DesktopWidth) settings->DesktopWidth = file->DesktopWidth; if (~file->DesktopHeight) @@ -513,10 +515,16 @@ BOOL freerdp_client_populate_settings_from_rdp_file(rdpFile* file, rdpSettings* if (~file->EnableCredSSPSupport) settings->NlaSecurity = file->EnableCredSSPSupport; if (~((size_t) file->AlternateShell)) - settings->AlternateShell = file->AlternateShell; + settings->AlternateShell = _strdup(file->AlternateShell); if (~((size_t) file->ShellWorkingDirectory)) - settings->ShellWorkingDirectory = file->ShellWorkingDirectory; + settings->ShellWorkingDirectory = _strdup(file->ShellWorkingDirectory); + if (~((size_t) file->LoadBalanceInfo)) + { + settings->LoadBalanceInfo = (BYTE*) _strdup(file->LoadBalanceInfo); + settings->LoadBalanceInfoLength = strlen((char*) settings->LoadBalanceInfo); + } + if (~file->ConnectionType) { freerdp_set_connection_type(settings, file->ConnectionType); @@ -540,7 +548,7 @@ BOOL freerdp_client_populate_settings_from_rdp_file(rdpFile* file, rdpSettings* } if (~((size_t) file->GatewayHostname)) - settings->GatewayHostname = file->GatewayHostname; + settings->GatewayHostname = _strdup(file->GatewayHostname); if (~file->GatewayUsageMethod) settings->GatewayUsageMethod = TRUE; if (~file->PromptCredentialOnce) @@ -549,17 +557,17 @@ BOOL freerdp_client_populate_settings_from_rdp_file(rdpFile* file, rdpSettings* if (~file->RemoteApplicationMode) settings->RemoteApplicationMode = file->RemoteApplicationMode; if (~((size_t) file->RemoteApplicationProgram)) - settings->RemoteApplicationProgram = file->RemoteApplicationProgram; + settings->RemoteApplicationProgram = _strdup(file->RemoteApplicationProgram); if (~((size_t) file->RemoteApplicationName)) - settings->RemoteApplicationName = file->RemoteApplicationName; + settings->RemoteApplicationName = _strdup(file->RemoteApplicationName); if (~((size_t) file->RemoteApplicationIcon)) - settings->RemoteApplicationIcon = file->RemoteApplicationIcon; + settings->RemoteApplicationIcon = _strdup(file->RemoteApplicationIcon); if (~((size_t) file->RemoteApplicationFile)) - settings->RemoteApplicationFile = file->RemoteApplicationFile; + settings->RemoteApplicationFile = _strdup(file->RemoteApplicationFile); if (~((size_t) file->RemoteApplicationGuid)) - settings->RemoteApplicationGuid = file->RemoteApplicationGuid; + settings->RemoteApplicationGuid = _strdup(file->RemoteApplicationGuid); if (~((size_t) file->RemoteApplicationCmdLine)) - settings->RemoteApplicationCmdLine = file->RemoteApplicationCmdLine; + settings->RemoteApplicationCmdLine = _strdup(file->RemoteApplicationCmdLine); if (~file->SpanMonitors) settings->SpanMonitors = file->SpanMonitors; diff --git a/client/iOS/Additions/Toast+UIView.h b/client/iOS/Additions/Toast+UIView.h index 012d44191..623e70571 100644 --- a/client/iOS/Additions/Toast+UIView.h +++ b/client/iOS/Additions/Toast+UIView.h @@ -29,6 +29,7 @@ #import <Foundation/Foundation.h> +#import <UIKit/UIKit.h> @interface UIView (Toast) diff --git a/client/iOS/CMakeLists.txt b/client/iOS/CMakeLists.txt index 0dd5b20d6..f2f67f687 100644 --- a/client/iOS/CMakeLists.txt +++ b/client/iOS/CMakeLists.txt @@ -1,8 +1,7 @@ # FreeRDP: A Remote Desktop Protocol Implementation -# Android Client +# FreeRDP X11 Client # # Copyright 2012 Marc-Andre Moreau <marcandre.moreau@gmail.com> -# Copyright 2013 Martin Fleisz <mfleisz@thinstuff.at> # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -15,40 +14,122 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +project(iFreeRDP) -set(IOS_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) -set(IOS_PACKAGE_NAME "iFreeRDP") +set(MODULE_NAME "iFreeRDP") +set(MODULE_PREFIX "IFREERDP_CLIENT") +set(APP_TYPE MACOSX_BUNDLE) -CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/iFreeRDP.xcodeproj/project.pbxproj.cmake ${CMAKE_CURRENT_SOURCE_DIR}/iFreeRDP.xcodeproj/project.pbxproj @ONLY) +set(IOS_CLIENT_DIR ${CMAKE_CURRENT_SOURCE_DIR}) +set(IOS_CLIENT_ADDITIONS_DIR ${IOS_CLIENT_DIR}/Additions) +set(IOS_CLIENT_CONTROLLERS_DIR ${IOS_CLIENT_DIR}/Controllers) +set(IOS_CLIENT_FREERDP_DIR ${IOS_CLIENT_DIR}/FreeRDP) +set(IOS_CLIENT_MISC_DIR ${IOS_CLIENT_DIR}/Misc) +set(IOS_CLIENT_MODELS_DIR ${IOS_CLIENT_DIR}/Models) +set(IOS_CLIENT_VIEWS_DIR ${IOS_CLIENT_DIR}/Views) +set(IOS_CLIENT_RESOURCES_DIR ${IOS_CLIENT_DIR}/Resources) -if(IOS_BUILD_OBJC) - # And isn't shiped with the android ndk/sdk so - # we need to find it on the local machine - SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER, BOTH) - find_program(XCODEBUILD_COMMAND xcodebuild) - SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER, ONLY) +include_directories(${IOS_CLIENT_DIR}) +include_directories(${IOS_CLIENT_ADDITIONS_DIR}) +include_directories(${IOS_CLIENT_CONTROLLERS_DIR}) +include_directories(${IOS_CLIENT_FREERDP_DIR}) +include_directories(${IOS_CLIENT_MISC_DIR}) +include_directories(${IOS_CLIENT_MODELS_DIR}) +include_directories(${IOS_CLIENT_VIEWS_DIR}) +include_directories(${OPENSSL_INCLUDE_DIR}) - if(XCODEBUILD_COMMAND STREQUAL "XCODEBUILD_COMMAND-NOTFOUND") - message(FATAL_ERROR "xcodebuild not found but required to build ios objective-c") - endif() +# Add sources +set(${MODULE_PREFIX}_SRCS + AppDelegate.m + AppDelegate.h + main.m) - if(IOS_BUILD_OBJC_DEBUG) - set(IOS_BUILD_TYPE "Debug") - else() - set(IOS_BUILD_TYPE "Release") - endif() +file(GLOB IOS_CLIENT_ADDITIONS_SRCS ${IOS_CLIENT_ADDITIONS_DIR}/*.m) +file(GLOB IOS_CLIENT_ADDITIONS_HDRS ${IOS_CLIENT_ADDITIONS_DIR}/*.h) - set(IOS_APP_OUTPUT_DIR "${IOS_SOURCE_DIR}/bin/${IOS_BUILD_TYPE}") - set(IOS_APP "${IOS_APP_OUTPUT_DIR}/${IOS_PACKAGE_NAME}.app") - - # command to create the ios package - add_custom_command( - OUTPUT "${IOS_APP}" - COMMAND ${XCODEBUILD_COMMAND} -project "${IOS_SOURCE_DIR}/iFreeRDP.xcodeproj" -sdk ${CMAKE_IOS_SDK_ROOT} -configuration ${IOS_BUILD_TYPE} CONFIGURATION_BUILD_DIR="${IOS_APP_OUTPUT_DIR}" - WORKING_DIRECTORY "${IOS_SOURCE_DIR}" - MAIN_DEPENDENCY ${CMAKE_CURRENT_SOURCE_DIR}/iFreeRDP.xcodeproj/project.pbxproj - DEPENDS freerdp winpr +file(GLOB IOS_CLIENT_CONTROLLERS_SRCS ${IOS_CLIENT_CONTROLLERS_DIR}/*.m) +file(GLOB IOS_CLIENT_CONTROLLERS_HDRS ${IOS_CLIENT_CONTROLLERS_DIR}/*.h) + +file(GLOB IOS_CLIENT_FREERDP_SRCS ${IOS_CLIENT_FREERDP_DIR}/*.m) +file(GLOB IOS_CLIENT_FREERDP_HDRS ${IOS_CLIENT_FREERDP_DIR}/*.h) + +file(GLOB IOS_CLIENT_MISC_SRCS ${IOS_CLIENT_MISC_DIR}/*.m) +file(GLOB IOS_CLIENT_MISC_HDRS ${IOS_CLIENT_MISC_DIR}/*.h) + +file(GLOB IOS_CLIENT_MODELS_SRCS ${IOS_CLIENT_MODELS_DIR}/*.m) +file(GLOB IOS_CLIENT_MODELS_HDRS ${IOS_CLIENT_MODELS_DIR}/*.h) + +file(GLOB IOS_CLIENT_VIEWS_SRCS ${IOS_CLIENT_VIEWS_DIR}/*.m) +file(GLOB IOS_CLIENT_VIEWS_HDRS ${IOS_CLIENT_VIEWS_DIR}/*.h) + +# add resources +file(GLOB IOS_CLIENT_RESOURCES_XIBS ${IOS_CLIENT_RESOURCES_DIR}/*.xib) +file(GLOB IOS_CLIENT_RESOURCES_PNGS ${IOS_CLIENT_RESOURCES_DIR}/*.png) + +# Specify source grouping +source_group(Additions FILES ${IOS_CLIENT_ADDITIONS_SRCS} ${IOS_CLIENT_ADDITIONS_HDRS}) +source_group(Controllers FILES ${IOS_CLIENT_CONTROLLERS_SRCS} ${IOS_CLIENT_CONTROLLERS_HDRS}) +source_group(FreeRDP FILES ${IOS_CLIENT_FREERDP_SRCS} ${IOS_CLIENT_FREERDP_HDRS}) +source_group(Misc FILES ${IOS_CLIENT_MISC_SRCS} ${IOS_CLIENT_MISC_HDRS}) +source_group(Models FILES ${IOS_CLIENT_MODELS_SRCS} ${IOS_CLIENT_MODELS_HDRS}) +source_group(Views FILES ${IOS_CLIENT_RESOURCES_XIBS} ${IOS_CLIENT_VIEWS_SRCS} ${IOS_CLIENT_VIEWS_HDRS}) +source_group(Resources FILES ${IOS_CLIENT_RESOURCES_PNGS} ${IOS_CLIENT_RESOURCES_DIR}/about_page ${IOS_CLIENT_RESOURCES_DIR}/help_page ${IOS_CLIENT_RESOURCES_DIR}/en.lproj) + +# import libraries +find_library(FOUNDATION_FRAMEWORK Foundation) +find_library(COREGRAPHICS_FRAMEWORK CoreGraphics) +find_library(SECURITY_FRAMEWORK Security) +find_library(UIKIT_FRAMEWORK UIKit) +find_library(SYSTEMCONFIGURATION_FRAMEWORK SystemConfiguration) + +mark_as_advanced(FOUNDATION_FRAMEWORK COREGRAPHICS_FRAMEWORK SECURITY_FRAMEWORK UIKIT_FRAMEWORK SYSTEMCONFIGURATION_FRAMEWORK) +set(EXTRA_LIBS ${FOUNDATION_FRAMEWORK} ${COREGRAPHICS_FRAMEWORK} ${SECURITY_FRAMEWORK} ${UIKIT_FRAMEWORK} ${SYSTEMCONFIGURATION_FRAMEWORK}) + +set(${MODULE_NAME}_RESOURCES ${IOS_CLIENT_RESOURCES_XIBS}) +set(${MODULE_NAME}_RESOURCES ${${MODULE_NAME}_RESOURCES} ${IOS_CLIENT_RESOURCES_PNGS}) +set(${MODULE_NAME}_RESOURCES ${${MODULE_NAME}_RESOURCES} ${IOS_CLIENT_RESOURCES_DIR}/about_page ${IOS_CLIENT_RESOURCES_DIR}/help_page ${IOS_CLIENT_RESOURCES_DIR}/en.lproj) +set(${MODULE_NAME}_RESOURCES ${${MODULE_NAME}_RESOURCES} ${IOS_CLIENT_DIR}/Defaults.plist) + +add_executable(${MODULE_NAME} + ${APP_TYPE} + ${${MODULE_PREFIX}_SRCS} + ${IOS_CLIENT_ADDITIONS_SRCS} ${IOS_CLIENT_ADDITIONS_HDRS} + ${IOS_CLIENT_CONTROLLERS_SRCS} ${IOS_CLIENT_CONTROLLERS_HDRS} + ${IOS_CLIENT_FREERDP_SRCS} ${IOS_CLIENT_FREERDP_HDRS} + ${IOS_CLIENT_MISC_SRCS} ${IOS_CLIENT_MISC_HDRS} + ${IOS_CLIENT_MODELS_SRCS} ${IOS_CLIENT_MODELS_HDRS} + ${IOS_CLIENT_VIEWS_SRCS} ${IOS_CLIENT_VIEWS_HDRS} + ${${MODULE_NAME}_RESOURCES} ) - add_custom_target(ios-package ALL SOURCES "${IOS_APP}") - SET_DIRECTORY_PROPERTIES(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "bin;build") -endif() + +set_target_properties(${MODULE_NAME} PROPERTIES RESOURCE "${${MODULE_NAME}_RESOURCES}") + +set(EXECUTABLE_NAME "\${EXECUTABLE_NAME}") + +set_target_properties(${MODULE_NAME} PROPERTIES MACOSX_BUNDLE_INFO_PLIST ${IOS_CLIENT_DIR}/iFreeRDP.plist) +set_target_properties(${MODULE_NAME} PROPERTIES XCODE_ATTRIBUTE_IPHONEOS_DEPLOYMENT_TARGET "4.3") +set_target_properties(${MODULE_NAME} PROPERTIES XCODE_ATTRIBUTE_CLANG_CXX_LANGUAGE_STANDARD "gnu++0x") +set_target_properties(${MODULE_NAME} PROPERTIES XCODE_ATTRIBUTE_CLANG_CXX_LIBRARY "libc++") +set_target_properties(${MODULE_NAME} PROPERTIES XCODE_ATTRIBUTE_CLANG_ENABLE_OBJC_ARC NO) +set_target_properties(${MODULE_NAME} PROPERTIES XCODE_ATTRIBUTE_GCC_C_LANGUAGE_STANDARD "gnu99") +set_target_properties(${MODULE_NAME} PROPERTIES XCODE_ATTRIBUTE_TARGETED_DEVICE_FAMILY "1,2") +set_target_properties(${MODULE_NAME} PROPERTIES XCODE_ATTRIBUTE_COMBINE_HIDPI_IMAGES "NO") +set_target_properties(${MODULE_NAME} PROPERTIES XCODE_ATTRIBUTE_SKIP_INSTALL NO) +set_target_properties(${MODULE_NAME} PROPERTIES XCODE_ATTRIBUTE_INSTALL_PATH "/Applications") +set_target_properties(${MODULE_NAME} PROPERTIES XCODE_ATTRIBUTE_GCC_GENERATE_DEBUGGING_SYMBOLS YES) + +set(${MODULE_PREFIX}_LIBS ${${MODULE_PREFIX}_LIBS} ${EXTRA_LIBS}) + +set(${MODULE_PREFIX}_LIBS ${${MODULE_PREFIX}_LIBS} freerdp-client) + +set_complex_link_libraries(VARIABLE ${MODULE_PREFIX}_LIBS MONOLITHIC ${MONOLITHIC_BUILD} + MODULE freerdp + MODULES freerdp-core freerdp-gdi freerdp-locale freerdp-primitives freerdp-cache freerdp-utils) + +set_complex_link_libraries(VARIABLE ${MODULE_PREFIX}_LIBS MONOLITHIC ${MONOLITHIC_BUILD} + MODULE winpr + MODULES winpr-input winpr-crt winpr-utils) + +target_link_libraries(${MODULE_NAME} ${${MODULE_PREFIX}_LIBS}) + +set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "Client/iOS") diff --git a/client/iOS/Controllers/AboutController.h b/client/iOS/Controllers/AboutController.h index 0ace59c13..6d6917a7e 100644 --- a/client/iOS/Controllers/AboutController.h +++ b/client/iOS/Controllers/AboutController.h @@ -10,7 +10,7 @@ #import <UIKit/UIKit.h> -@interface AboutController : UIViewController <UIWebViewDelegate, UIAlertViewDelegate> +@interface AboutController : UIViewController <UIWebViewDelegate> { NSString* last_link_clicked; UIWebView* webView; diff --git a/client/iOS/Controllers/AboutController.m b/client/iOS/Controllers/AboutController.m index a30bb40ba..ba3cdb488 100644 --- a/client/iOS/Controllers/AboutController.m +++ b/client/iOS/Controllers/AboutController.m @@ -9,6 +9,7 @@ #import "AboutController.h" #import "Utils.h" +#import "BlockAlertView.h" @implementation AboutController @@ -76,24 +77,19 @@ { [last_link_clicked release]; last_link_clicked = [[[request URL] absoluteString] retain]; - UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"External Link", @"External Link Alert Title") - message:[NSString stringWithFormat:NSLocalizedString(@"Open [%@] in Browser?", @"Open link in browser (with link as parameter)"), last_link_clicked] - delegate:self - cancelButtonTitle:NSLocalizedString(@"OK", @"OK Button") - otherButtonTitles:NSLocalizedString(@"No", @"No Button"), nil]; - [alert show]; - [alert release]; + BlockAlertView *alert = [BlockAlertView alertWithTitle:NSLocalizedString(@"External Link", @"External Link Alert Title") + message:[NSString stringWithFormat:NSLocalizedString(@"Open [%@] in Browser?", @"Open link in browser (with link as parameter)"), last_link_clicked]]; + + [alert setCancelButtonWithTitle:NSLocalizedString(@"No", @"No Button") block:nil]; + [alert addButtonWithTitle:NSLocalizedString(@"OK", @"OK Button") block:^{ + [[UIApplication sharedApplication] openURL:[NSURL URLWithString:last_link_clicked]]; + }]; + + [alert show]; return NO; } return YES; } -#pragma mark UIAlertView delegate -- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex -{ - if (buttonIndex == 0) - [[UIApplication sharedApplication] openURL:[NSURL URLWithString:last_link_clicked]]; -} - @end diff --git a/client/iOS/Controllers/BookmarkEditorController.h b/client/iOS/Controllers/BookmarkEditorController.h index 1ca68d3e4..5cdf0c9e0 100644 --- a/client/iOS/Controllers/BookmarkEditorController.h +++ b/client/iOS/Controllers/BookmarkEditorController.h @@ -21,7 +21,7 @@ @end -@interface BookmarkEditorController : EditorBaseController <UIAlertViewDelegate> +@interface BookmarkEditorController : EditorBaseController { @private ComputerBookmark* _bookmark; diff --git a/client/iOS/Controllers/BookmarkEditorController.m b/client/iOS/Controllers/BookmarkEditorController.m index de80c50d3..57fa93f39 100644 --- a/client/iOS/Controllers/BookmarkEditorController.m +++ b/client/iOS/Controllers/BookmarkEditorController.m @@ -14,6 +14,7 @@ #import "PerformanceEditorController.h" #import "CredentialsEditorController.h" #import "AdvancedBookmarkEditorController.h" +#import "BlockAlertView.h" @implementation BookmarkEditorController @@ -32,8 +33,11 @@ if ((self = [super initWithStyle:UITableViewStyleGrouped])) { // set additional settings state according to bookmark data - _bookmark = [bookmark retain]; - _params = [bookmark params]; + if ([[bookmark uuid] length] == 0) + _bookmark = [bookmark copy]; + else + _bookmark = [bookmark copyWithUUID]; + _params = [_bookmark params]; // if this is a TSX Connect bookmark - disable server settings if([_bookmark isKindOfClass:NSClassFromString(@"TSXConnectComputerBookmark")]) @@ -335,18 +339,6 @@ return YES; } -#pragma mark - UIAlertViewDelegate methods - -- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex -{ - // clicked yes? - if (buttonIndex == 0) - { - // cancel bookmark editing and return to previous view controller - [[self navigationController] popViewControllerAnimated:YES]; - } -} - #pragma mark - #pragma mark Action Handlers @@ -360,8 +352,13 @@ { if ([[_bookmark label] length] == 0 || [[_params StringForKey:@"hostname"] length] == 0 || [_params intForKey:@"port"] == 0) { - UIAlertView* alertView = [[[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Cancel without saving?", @"Incomplete bookmark error title") message:NSLocalizedString(@"Press 'Cancel' to abort!\nPress 'Continue' to specify the required fields!", @"Incomplete bookmark error message") delegate:self cancelButtonTitle:NSLocalizedString(@"Cancel", @"Cancel Button") otherButtonTitles:NSLocalizedString(@"Continue", @"Continue Button"), nil] autorelease]; - [alertView show]; + BlockAlertView* alertView = [BlockAlertView alertWithTitle:NSLocalizedString(@"Cancel without saving?", @"Incomplete bookmark error title") message:NSLocalizedString(@"Press 'Cancel' to abort!\nPress 'Continue' to specify the required fields!", @"Incomplete bookmark error message")]; + [alertView setCancelButtonWithTitle:NSLocalizedString(@"Cancel", @"Cancel Button") block:^{ + // cancel bookmark editing and return to previous view controller + [[self navigationController] popViewControllerAnimated:YES]; + }]; + [alertView addButtonWithTitle:NSLocalizedString(@"Continue", @"Continue Button") block:nil]; + [alertView show]; return; } } diff --git a/client/iOS/Controllers/BookmarkListController.h b/client/iOS/Controllers/BookmarkListController.h index a8a046e94..e57ea9035 100644 --- a/client/iOS/Controllers/BookmarkListController.h +++ b/client/iOS/Controllers/BookmarkListController.h @@ -14,7 +14,7 @@ #import "BookmarkEditorController.h" #import "Reachability.h" -@interface BookmarkListController : UIViewController <UISearchBarDelegate, UITableViewDelegate, UITableViewDataSource, UIAlertViewDelegate, BookmarkEditorDelegate> +@interface BookmarkListController : UIViewController <UISearchBarDelegate, UITableViewDelegate, UITableViewDataSource, BookmarkEditorDelegate> { // custom bookmark and session table cells BookmarkTableCell* _bmTableCell; diff --git a/client/iOS/Controllers/BookmarkListController.m b/client/iOS/Controllers/BookmarkListController.m index b3f43c732..386917edd 100644 --- a/client/iOS/Controllers/BookmarkListController.m +++ b/client/iOS/Controllers/BookmarkListController.m @@ -14,6 +14,7 @@ #import "Toast+UIView.h" #import "Reachability.h" #import "GlobalDefaults.h" +#import "BlockAlertView.h" #define SECTION_SESSIONS 0 #define SECTION_BOOKMARKS 1 @@ -633,8 +634,17 @@ // ask the user if he wants to save the bookmark NSString* title = NSLocalizedString(@"Save Connection Settings?", @"Save connection settings title"); NSString* message = NSLocalizedString(@"Your Connection Settings have not been saved. Do you want to save them?", @"Save connection settings message"); - UIAlertView* alert = [[UIAlertView alloc] initWithTitle:title message:message delegate:self - cancelButtonTitle:NSLocalizedString(@"Yes", @"Yes Button") otherButtonTitles:NSLocalizedString(@"No", @"No Button"), nil]; + BlockAlertView* alert = [BlockAlertView alertWithTitle:title message:message]; + [alert setCancelButtonWithTitle:NSLocalizedString(@"No", @"No Button") block:nil]; + [alert addButtonWithTitle:NSLocalizedString(@"Yes", @"Yes Button") block:^{ + if (_temporary_bookmark) + { + [_manual_bookmarks addObject:_temporary_bookmark]; + [_tableView reloadSections:[NSIndexSet indexSetWithIndex:SECTION_BOOKMARKS] withRowAnimation:UITableViewRowAnimationNone]; + [_temporary_bookmark autorelease]; + _temporary_bookmark = nil; + } + }]; [alert show]; } } @@ -649,21 +659,6 @@ [[self view] makeToast:NSLocalizedString(@"Failed to connect to session!", @"Failed to connect error message") duration:ToastDurationNormal position:@"center"]; } -#pragma mark - UIAlertView delegates - -- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex -{ - // yes clicked? - if (buttonIndex == 0 && _temporary_bookmark) - { - [_manual_bookmarks addObject:_temporary_bookmark]; - [_tableView reloadSections:[NSIndexSet indexSetWithIndex:SECTION_BOOKMARKS] withRowAnimation:UITableViewRowAnimationNone]; - } - - [_temporary_bookmark autorelease]; - _temporary_bookmark = nil; -} - #pragma mark - Reachability notification - (void)reachabilityChanged:(NSNotification*)notification { @@ -680,10 +675,20 @@ - (void)commitBookmark:(ComputerBookmark *)bookmark { - // if we got a manual bookmark that is not in the list yet - add it - if (![_manual_bookmarks containsObject:bookmark]) + // if we got a manual bookmark that is not in the list yet - add it otherwise replace it + BOOL found = NO; + for (int idx = 0; idx < [_manual_bookmarks count]; ++idx) + { + if ([[bookmark uuid] isEqualToString:[[_manual_bookmarks objectAtIndex:idx] uuid]]) + { + [_manual_bookmarks replaceObjectAtIndex:idx withObject:bookmark]; + found = YES; + break; + } + } + if (!found) [_manual_bookmarks addObject:bookmark]; - + // remove any quick connect history entry with the same hostname NSString* hostname = [[bookmark params] StringForKey:@"hostname"]; if ([_connection_history containsObject:hostname]) diff --git a/client/iOS/Controllers/HelpController.m b/client/iOS/Controllers/HelpController.m index 5ed3bc90b..594dfb2ee 100644 --- a/client/iOS/Controllers/HelpController.m +++ b/client/iOS/Controllers/HelpController.m @@ -55,27 +55,4 @@ return YES; } -#pragma mark - -#pragma mark UIWebView callbacks -- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType -{ - if([[request URL] isFileURL]) - return YES; - - if(navigationType == UIWebViewNavigationTypeLinkClicked) - { - NSString* lastClickedLink = [[request URL] absoluteString]; - UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"External Link" - message:[NSString stringWithFormat:@"Open [%@] in Browser?", lastClickedLink] - delegate:self - cancelButtonTitle:@"OK" - otherButtonTitles:@"No", nil]; - [alert show]; - [alert release]; - - return NO; - } - return YES; -} - @end diff --git a/client/iOS/Controllers/MainTabBarController.h b/client/iOS/Controllers/MainTabBarController.h index 796c1fa75..499d3792e 100644 --- a/client/iOS/Controllers/MainTabBarController.h +++ b/client/iOS/Controllers/MainTabBarController.h @@ -8,7 +8,7 @@ */ #import <Foundation/Foundation.h> - +#import <UIKit/UIKit.h> @interface MainTabBarController : UITabBarController { diff --git a/client/iOS/Controllers/RDPSessionViewController.h b/client/iOS/Controllers/RDPSessionViewController.h index 52502bf9a..996c2915f 100644 --- a/client/iOS/Controllers/RDPSessionViewController.h +++ b/client/iOS/Controllers/RDPSessionViewController.h @@ -14,7 +14,7 @@ #import "TouchPointerView.h" #import "AdvancedKeyboardView.h" -@interface RDPSessionViewController : UIViewController <RDPSessionDelegate, TouchPointerDelegate, AdvancedKeyboardDelegate, RDPKeyboardDelegate, UIScrollViewDelegate, UITextFieldDelegate, UIAlertViewDelegate> +@interface RDPSessionViewController : UIViewController <RDPSessionDelegate, TouchPointerDelegate, AdvancedKeyboardDelegate, RDPKeyboardDelegate, UIScrollViewDelegate, UITextFieldDelegate> { // scrollview that hosts the rdp session view IBOutlet UIScrollView* _session_scrollview; diff --git a/client/iOS/Controllers/RDPSessionViewController.m b/client/iOS/Controllers/RDPSessionViewController.m index 87137548c..c431d8c51 100644 --- a/client/iOS/Controllers/RDPSessionViewController.m +++ b/client/iOS/Controllers/RDPSessionViewController.m @@ -15,6 +15,7 @@ #import "ConnectionParams.h" #import "CredentialsInputController.h" #import "VerifyCertificateController.h" +#import "BlockAlertView.h" #define TOOLBAR_HEIGHT 30 @@ -415,8 +416,12 @@ - (void)showGoProScreen:(RDPSession*)session { - UIAlertView* alertView = [[[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Pro Version", @"Pro version dialog title") - message:NSLocalizedString(@"Do you want to buy Thinstuff RDC Pro and enable the full RDP Experience", @"Pro version dialog message") delegate:self cancelButtonTitle:NSLocalizedString(@"No", @"No Button title") otherButtonTitles:NSLocalizedString(@"Yes", @"Yes button title"), nil] autorelease]; + BlockAlertView* alertView = [BlockAlertView alertWithTitle:NSLocalizedString(@"Unlicensed Client", @"Pro version dialog title") message:NSLocalizedString(@"You are connected to Thinstuff Remote Desktop Host (RDH). Do you want to purchase an access license for this client which allows you to connect to any computer running Thinstuff RDH?", @"Pro version dialog message")]; + + [alertView setCancelButtonWithTitle:NSLocalizedString(@"No", @"No Button title") block:nil]; + [alertView addButtonWithTitle:NSLocalizedString(@"Yes", @"Yes button title") block:^ { + }]; + [alertView show]; } @@ -556,16 +561,20 @@ - (void)onTransactionSuccess:(NSNotification*)notification { - UIAlertView* alertView = [[[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Transaction Succeeded", @"Pro version bought dialog title") - message:NSLocalizedString(@"Thanks for buying Thinstuff RDC Pro. In order for the purchase to take effect please reconnect your current session.", @"Pro version bought dialog message") delegate:nil cancelButtonTitle:NSLocalizedString(@"OK", @"OK Button title") otherButtonTitles:nil] autorelease]; + BlockAlertView* alertView = [BlockAlertView alertWithTitle:NSLocalizedString(@"Transaction Succeeded", @"Pro version bought dialog title") + message:NSLocalizedString(@"Thanks for buying Thinstuff RDC Pro. In order for the purchase to take effect please reconnect your current session.", @"Pro version bought dialog message")]; + [alertView setCancelButtonWithTitle:NSLocalizedString(@"OK", @"OK Button title") block:nil]; + [alertView show]; } - (void)onTransactionFailed:(NSNotification*)notification { - UIAlertView* alertView = [[[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Transaction Failed", @"Pro version buy failed dialog title") - message:NSLocalizedString(@"The transaction did not complete successfully!", @"Pro version buy failed dialog message") delegate:nil cancelButtonTitle:NSLocalizedString(@"OK", @"OK Button title") otherButtonTitles:nil] autorelease]; - [alertView show]; + BlockAlertView* alertView = [BlockAlertView alertWithTitle:NSLocalizedString(@"Transaction Failed", @"Pro version buy failed dialog title") + message:NSLocalizedString(@"The transaction did not complete successfully!", @"Pro version buy failed dialog message")]; + [alertView setCancelButtonWithTitle:NSLocalizedString(@"OK", @"OK Button title") block:nil]; + + [alertView show]; } #pragma mark - diff --git a/client/iOS/FreeRDP/ios_freerdp.h b/client/iOS/FreeRDP/ios_freerdp.h index 7219c6b3c..e16d3bb16 100644 --- a/client/iOS/FreeRDP/ios_freerdp.h +++ b/client/iOS/FreeRDP/ios_freerdp.h @@ -7,6 +7,8 @@ If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#import <CoreGraphics/CoreGraphics.h> + #import <freerdp/freerdp.h> #import <freerdp/channels/channels.h> #import "TSXTypes.h" diff --git a/client/iOS/FreeRDP/ios_freerdp.m b/client/iOS/FreeRDP/ios_freerdp.m index 55738bee7..ee0cdddc0 100644 --- a/client/iOS/FreeRDP/ios_freerdp.m +++ b/client/iOS/FreeRDP/ios_freerdp.m @@ -9,7 +9,9 @@ #import <freerdp/utils/event.h> #import <freerdp/gdi/gdi.h> -#import <freerdp/utils/file.h> +#import <freerdp/channels/channels.h> +#import <freerdp/client/channels.h> +#import <freerdp/client/cmdline.h> #import "ios_freerdp.h" #import "ios_freerdp_ui.h" @@ -64,7 +66,9 @@ ios_pre_connect(freerdp * instance) settings->FrameAcknowledge = 10; -// freerdp_channels_pre_connect(instance->context->channels, instance); + freerdp_client_load_addins(instance->context->channels, instance->settings); + + freerdp_channels_pre_connect(instance->context->channels, instance); return TRUE; } @@ -82,12 +86,24 @@ static BOOL ios_post_connect(freerdp* instance) instance->update->DesktopResize = ios_ui_resize_window; // Channel allocation -// freerdp_channels_post_connect(instance->context->channels, instance); + freerdp_channels_post_connect(instance->context->channels, instance); [mfi->session performSelectorOnMainThread:@selector(sessionDidConnect) withObject:nil waitUntilDone:YES]; return TRUE; } +static int ios_receive_channel_data(freerdp* instance, int channelId, UINT8* data, int size, int flags, int total_size) +{ + return freerdp_channels_data(instance, channelId, data, size, flags, total_size); +} + +void ios_process_channel_event(rdpChannels* channels, freerdp* instance) +{ + wMessage* event = freerdp_channels_pop_event(channels); + if (event) + freerdp_event_free(event); +} + #pragma mark - #pragma mark Running the connection @@ -96,7 +112,7 @@ ios_run_freerdp(freerdp * instance) { mfContext* context = (mfContext*)instance->context; mfInfo* mfi = context->mfi; -// rdpChannels* channels = instance->context->channels; + rdpChannels* channels = instance->context->channels; mfi->connection_state = TSXConnectionConnecting; @@ -138,12 +154,12 @@ ios_run_freerdp(freerdp * instance) break; } -/* if (freerdp_channels_get_fds(channels, instance, rfds, &rcount, wfds, &wcount) != TRUE) + if (freerdp_channels_get_fds(channels, instance, rfds, &rcount, wfds, &wcount) != TRUE) { NSLog(@"%s: freerdp_chanman_get_fds failed", __func__); break; } -*/ + if (ios_events_get_fds(mfi, rfds, &rcount, wfds, &wcount) != TRUE) { NSLog(@"%s: ios_events_get_fds", __func__); @@ -196,20 +212,22 @@ ios_run_freerdp(freerdp * instance) } // Check channel fds -/* if (freerdp_channels_check_fds(channels, instance) != TRUE) + if (freerdp_channels_check_fds(channels, instance) != TRUE) { NSLog(@"%s: freerdp_chanman_check_fds failed", __func__); break; } -*/ + ios_process_channel_event(channels, instance); + [pool release]; pool = nil; } - + + CGContextRelease(mfi->bitmap_context); + mfi->bitmap_context = NULL; mfi->connection_state = TSXConnectionDisconnected; // Cleanup -// freerdp_channels_close(channels, instance); -// freerdp_channels_free(channels); + freerdp_channels_close(channels, instance); freerdp_disconnect(instance); gdi_free(instance); cache_free(instance->context->cache); @@ -225,7 +243,7 @@ void ios_context_new(freerdp* instance, rdpContext* context) { mfInfo* mfi = (mfInfo*)calloc(1, sizeof(mfInfo)); ((mfContext*) context)->mfi = mfi; -// context->channels = freerdp_channels_new(); + context->channels = freerdp_channels_new(); ios_events_create_pipe(mfi); mfi->_context = context; @@ -237,6 +255,7 @@ void ios_context_new(freerdp* instance, rdpContext* context) void ios_context_free(freerdp* instance, rdpContext* context) { mfInfo* mfi = ((mfContext*) context)->mfi; + freerdp_channels_free(context->channels); ios_events_free_pipe(mfi); free(mfi); } @@ -253,19 +272,19 @@ freerdp* ios_freerdp_new() inst->Authenticate = ios_ui_authenticate; inst->VerifyCertificate = ios_ui_check_certificate; inst->VerifyChangedCertificate = ios_ui_check_changed_certificate; - + inst->ReceiveChannelData = ios_receive_channel_data; + inst->context_size = sizeof(mfContext); inst->ContextNew = ios_context_new; inst->ContextFree = ios_context_free; freerdp_context_new(inst); - + // determine new home path NSString* home_path = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject]; free(inst->settings->HomePath); free(inst->settings->ConfigPath); inst->settings->HomePath = strdup([home_path UTF8String]); - inst->settings->ConfigPath = NULL; - freerdp_detect_paths(inst->settings); + inst->settings->ConfigPath = strdup([[home_path stringByAppendingPathComponent:@".freerdp"] UTF8String]); return inst; } @@ -279,11 +298,12 @@ void ios_freerdp_free(freerdp* instance) void ios_init_freerdp() { signal(SIGPIPE, SIG_IGN); -// freerdp_channels_global_init(); + freerdp_channels_global_init(); + freerdp_register_addin_provider(freerdp_channels_load_static_addin_entry, 0); } void ios_uninit_freerdp() { -// freerdp_channels_global_uninit(); + freerdp_channels_global_uninit(); } diff --git a/client/iOS/FreeRDP/ios_freerdp_events.h b/client/iOS/FreeRDP/ios_freerdp_events.h index d2f9e799d..eb790d8f8 100755 --- a/client/iOS/FreeRDP/ios_freerdp_events.h +++ b/client/iOS/FreeRDP/ios_freerdp_events.h @@ -10,6 +10,7 @@ #ifndef IOS_RDP_EVENT_H #define IOS_RDP_EVENT_H +#import <Foundation/Foundation.h> #import "ios_freerdp.h" // For UI: use to send events diff --git a/client/iOS/Misc/Utils.h b/client/iOS/Misc/Utils.h index bca34e899..9a22da5f6 100644 --- a/client/iOS/Misc/Utils.h +++ b/client/iOS/Misc/Utils.h @@ -8,6 +8,7 @@ */ #import <Foundation/Foundation.h> +#import <CoreGraphics/CoreGraphics.h> #import "TSXTypes.h" // helper macro to encode a table path into a tag value (used to identify controls in their delegate handlers) diff --git a/client/iOS/Models/Bookmark.h b/client/iOS/Models/Bookmark.h index bcaaca0f3..b66eac804 100644 --- a/client/iOS/Models/Bookmark.h +++ b/client/iOS/Models/Bookmark.h @@ -9,6 +9,7 @@ #import <Foundation/Foundation.h> +#import <UIKit/UIKit.h> #import "ConnectionParams.h" @interface ComputerBookmark : NSObject <NSCoding> { @@ -29,6 +30,7 @@ // Creates a copy of this object, with a new UUID - (id)copy; +- (id)copyWithUUID; // Whether user can delete, move, or rename this entry - (BOOL)isDeletable; diff --git a/client/iOS/Models/Bookmark.m b/client/iOS/Models/Bookmark.m index 2ce7903b7..fbf85502f 100644 --- a/client/iOS/Models/Bookmark.m +++ b/client/iOS/Models/Bookmark.m @@ -39,7 +39,7 @@ // Designated initializer. - (id)initWithConnectionParameters:(ConnectionParams*)params { - if (!(self = [super init])) + if (!(self = [self init])) return nil; _connection_params = [params copy]; @@ -87,6 +87,13 @@ return copy; } +- (id)copyWithUUID +{ + ComputerBookmark* copy = [self copy]; + copy->_uuid = [[self uuid] copy]; + return copy; +} + - (void)encodeWithCoder:(NSCoder *)coder { if (![coder allowsKeyedCoding]) diff --git a/client/iOS/Models/RDPSession.h b/client/iOS/Models/RDPSession.h index c266cc9a6..3896ae8e0 100644 --- a/client/iOS/Models/RDPSession.h +++ b/client/iOS/Models/RDPSession.h @@ -8,6 +8,7 @@ */ #import <Foundation/Foundation.h> +#import <UIKit/UIKit.h> #include <freerdp/freerdp.h> diff --git a/client/iOS/Models/RDPSession.m b/client/iOS/Models/RDPSession.m index adb45abf9..6144637d1 100644 --- a/client/iOS/Models/RDPSession.m +++ b/client/iOS/Models/RDPSession.m @@ -104,6 +104,7 @@ NSString* TSXSessionDidFailToConnectNotification = @"TSXSessionDidFailToConnect" // enable NSCodec settings->NSCodec = TRUE; + settings->BitmapCacheV3Enabled = TRUE; // Performance flags settings->DisableWallpaper = ![_params boolForKey:@"perf_show_desktop" with3GEnabled:connected_via_3g]; @@ -189,7 +190,7 @@ NSString* TSXSessionDidFailToConnectNotification = @"TSXSessionDidFailToConnect" - (CGContextRef)bitmapContext { - return [self mfi]->bitmap_context; + return [self mfi]->bitmap_context; } #pragma mark - diff --git a/client/iOS/Resources/alert-black-button.png b/client/iOS/Resources/alert-black-button.png new file mode 100644 index 000000000..d06b66df1 Binary files /dev/null and b/client/iOS/Resources/alert-black-button.png differ diff --git a/client/iOS/Resources/alert-black-button@2x.png b/client/iOS/Resources/alert-black-button@2x.png new file mode 100644 index 000000000..4caec8ea3 Binary files /dev/null and b/client/iOS/Resources/alert-black-button@2x.png differ diff --git a/client/iOS/Resources/alert-gray-button.png b/client/iOS/Resources/alert-gray-button.png new file mode 100644 index 000000000..06548df51 Binary files /dev/null and b/client/iOS/Resources/alert-gray-button.png differ diff --git a/client/iOS/Resources/alert-gray-button@2x.png b/client/iOS/Resources/alert-gray-button@2x.png new file mode 100644 index 000000000..8333e6cfb Binary files /dev/null and b/client/iOS/Resources/alert-gray-button@2x.png differ diff --git a/client/iOS/Resources/alert-red-button.png b/client/iOS/Resources/alert-red-button.png new file mode 100644 index 000000000..896742f9c Binary files /dev/null and b/client/iOS/Resources/alert-red-button.png differ diff --git a/client/iOS/Resources/alert-red-button@2x.png b/client/iOS/Resources/alert-red-button@2x.png new file mode 100644 index 000000000..852bd3f4b Binary files /dev/null and b/client/iOS/Resources/alert-red-button@2x.png differ diff --git a/client/iOS/Resources/alert-window-landscape.png b/client/iOS/Resources/alert-window-landscape.png new file mode 100644 index 000000000..1149b28cd Binary files /dev/null and b/client/iOS/Resources/alert-window-landscape.png differ diff --git a/client/iOS/Resources/alert-window-landscape@2x.png b/client/iOS/Resources/alert-window-landscape@2x.png new file mode 100644 index 000000000..3bb3b8aab Binary files /dev/null and b/client/iOS/Resources/alert-window-landscape@2x.png differ diff --git a/client/iOS/Resources/alert-window.png b/client/iOS/Resources/alert-window.png new file mode 100644 index 000000000..e4907cf53 Binary files /dev/null and b/client/iOS/Resources/alert-window.png differ diff --git a/client/iOS/Resources/alert-window@2x.png b/client/iOS/Resources/alert-window@2x.png new file mode 100644 index 000000000..2ecd13855 Binary files /dev/null and b/client/iOS/Resources/alert-window@2x.png differ diff --git a/client/iOS/Resources/help_page/gestures.html b/client/iOS/Resources/help_page/gestures.html index 858387773..43425167f 100755 --- a/client/iOS/Resources/help_page/gestures.html +++ b/client/iOS/Resources/help_page/gestures.html @@ -148,7 +148,7 @@ a:hover, a:active, a:focus { /* this group of selectors will give a keyboard nav <div id="content"> <h1>Gestures</h1> <p> -aFreeRDP is designed for touch sensitive devices. +iFreeRDP is designed for touch sensitive devices. These gestures let you do the most usual operations with your fingers.</p> <p> <img src="gestures.png"></p> diff --git a/client/iOS/Resources/help_page/gestures_phone.html b/client/iOS/Resources/help_page/gestures_phone.html index 156d7c94d..5d95cfdd6 100755 --- a/client/iOS/Resources/help_page/gestures_phone.html +++ b/client/iOS/Resources/help_page/gestures_phone.html @@ -147,7 +147,7 @@ a:hover, a:active, a:focus { /* this group of selectors will give a keyboard nav <div id="content"> <h2> Gestures</h2> <p> -aFreeRDP is designed for touch sensitive devices. +iFreeRDP is designed for touch sensitive devices. These gestures let you do the most usual operations with your fingers.</p> <p> <img src="gestures_phone.png"></p> diff --git a/client/iOS/Views/BlockAlertView.h b/client/iOS/Views/BlockAlertView.h new file mode 100755 index 000000000..a7441b13c --- /dev/null +++ b/client/iOS/Views/BlockAlertView.h @@ -0,0 +1,41 @@ +// +// BlockAlertView.h +// +// + +#import <UIKit/UIKit.h> + +@interface BlockAlertView : NSObject { +@protected + UIView *_view; + NSMutableArray *_blocks; + CGFloat _height; + NSString *_title; + NSString *_message; + BOOL _shown; + BOOL _cancelBounce; +} + ++ (BlockAlertView *)alertWithTitle:(NSString *)title message:(NSString *)message; + ++ (void)showInfoAlertWithTitle:(NSString *)title message:(NSString *)message; ++ (void)showErrorAlert:(NSError *)error; + +- (id)initWithTitle:(NSString *)title message:(NSString *)message; + +- (void)setDestructiveButtonWithTitle:(NSString *)title block:(void (^)())block; +- (void)setCancelButtonWithTitle:(NSString *)title block:(void (^)())block; +- (void)addButtonWithTitle:(NSString *)title block:(void (^)())block; + +- (void)addComponents:(CGRect)frame; + +- (void)show; +- (void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)animated; + +- (void)setupDisplay; + +@property (nonatomic, retain) UIImage *backgroundImage; +@property (nonatomic, readonly) UIView *view; +@property (nonatomic, readwrite) BOOL vignetteBackground; + +@end diff --git a/client/iOS/Views/BlockAlertView.m b/client/iOS/Views/BlockAlertView.m new file mode 100755 index 000000000..2a7270047 --- /dev/null +++ b/client/iOS/Views/BlockAlertView.m @@ -0,0 +1,447 @@ +// +// BlockAlertView.m +// +// + +#import "BlockAlertView.h" +#import "BlockBackground.h" +#import "BlockUI.h" + +@implementation BlockAlertView + +@synthesize view = _view; +@synthesize backgroundImage = _backgroundImage; +@synthesize vignetteBackground = _vignetteBackground; + +static UIImage *background = nil; +static UIImage *backgroundlandscape = nil; +static UIFont *titleFont = nil; +static UIFont *messageFont = nil; +static UIFont *buttonFont = nil; + + +#pragma mark - init + ++ (void)initialize +{ + if (self == [BlockAlertView class]) + { + background = [UIImage imageNamed:kAlertViewBackground]; + background = [[background stretchableImageWithLeftCapWidth:0 topCapHeight:kAlertViewBackgroundCapHeight] retain]; + + backgroundlandscape = [UIImage imageNamed:kAlertViewBackgroundLandscape]; + backgroundlandscape = [[backgroundlandscape stretchableImageWithLeftCapWidth:0 topCapHeight:kAlertViewBackgroundCapHeight] retain]; + + titleFont = [kAlertViewTitleFont retain]; + messageFont = [kAlertViewMessageFont retain]; + buttonFont = [kAlertViewButtonFont retain]; + } +} + ++ (BlockAlertView *)alertWithTitle:(NSString *)title message:(NSString *)message +{ + return [[[BlockAlertView alloc] initWithTitle:title message:message] autorelease]; +} + ++ (void)showInfoAlertWithTitle:(NSString *)title message:(NSString *)message +{ + BlockAlertView *alert = [[BlockAlertView alloc] initWithTitle:title message:message]; + [alert setCancelButtonWithTitle:NSLocalizedString(@"Dismiss", nil) block:nil]; + [alert show]; + [alert release]; +} + ++ (void)showErrorAlert:(NSError *)error +{ + BlockAlertView *alert = [[BlockAlertView alloc] initWithTitle:NSLocalizedString(@"Operation Failed", nil) message:[NSString stringWithFormat:NSLocalizedString(@"The operation did not complete successfully: %@", nil), error]]; + [alert setCancelButtonWithTitle:@"Dismiss" block:nil]; + [alert show]; + [alert release]; +} + +/////////////////////////////////////////////////////////////////////////////////////////////////// +#pragma mark - NSObject + +- (void)addComponents:(CGRect)frame { + if (_title) + { + CGSize size = [_title sizeWithFont:titleFont + constrainedToSize:CGSizeMake(frame.size.width-kAlertViewBorder*2, 1000) + lineBreakMode:NSLineBreakByWordWrapping]; + + UILabel *labelView = [[UILabel alloc] initWithFrame:CGRectMake(kAlertViewBorder, _height, frame.size.width-kAlertViewBorder*2, size.height)]; + labelView.font = titleFont; + labelView.numberOfLines = 0; + labelView.lineBreakMode = NSLineBreakByWordWrapping; + labelView.textColor = kAlertViewTitleTextColor; + labelView.backgroundColor = [UIColor clearColor]; + labelView.textAlignment = NSTextAlignmentCenter; + labelView.shadowColor = kAlertViewTitleShadowColor; + labelView.shadowOffset = kAlertViewTitleShadowOffset; + labelView.text = _title; + [_view addSubview:labelView]; + [labelView release]; + + _height += size.height + kAlertViewBorder; + } + + if (_message) + { + CGSize size = [_message sizeWithFont:messageFont + constrainedToSize:CGSizeMake(frame.size.width-kAlertViewBorder*2, 1000) + lineBreakMode:NSLineBreakByWordWrapping]; + + UILabel *labelView = [[UILabel alloc] initWithFrame:CGRectMake(kAlertViewBorder, _height, frame.size.width-kAlertViewBorder*2, size.height)]; + labelView.font = messageFont; + labelView.numberOfLines = 0; + labelView.lineBreakMode = NSLineBreakByWordWrapping; + labelView.textColor = kAlertViewMessageTextColor; + labelView.backgroundColor = [UIColor clearColor]; + labelView.textAlignment = NSTextAlignmentCenter; + labelView.shadowColor = kAlertViewMessageShadowColor; + labelView.shadowOffset = kAlertViewMessageShadowOffset; + labelView.text = _message; + [_view addSubview:labelView]; + [labelView release]; + + _height += size.height + kAlertViewBorder; + } +} + +- (void)setupDisplay +{ + [[_view subviews] enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { + [obj removeFromSuperview]; + }]; + + UIWindow *parentView = [BlockBackground sharedInstance]; + CGRect frame = parentView.bounds; + frame.origin.x = floorf((frame.size.width - background.size.width) * 0.5); + frame.size.width = background.size.width; + + UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation]; + if (UIInterfaceOrientationIsLandscape(orientation)) { + frame.size.width += 150; + frame.origin.x -= 75; + } + + _view.frame = frame; + + _height = kAlertViewBorder + 15; + + if (NeedsLandscapePhoneTweaks) { + _height -= 15; // landscape phones need to trimmed a bit + } + + [self addComponents:frame]; + + if (_shown) + [self show]; +} + +- (id)initWithTitle:(NSString *)title message:(NSString *)message +{ + self = [super init]; + + if (self) + { + _title = [title copy]; + _message = [message copy]; + + _view = [[UIView alloc] init]; + + _view.autoresizingMask = UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin; + + _blocks = [[NSMutableArray alloc] init]; + + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(setupDisplay) + name:UIApplicationDidChangeStatusBarOrientationNotification + object:nil]; + + if ([self class] == [BlockAlertView class]) + [self setupDisplay]; + + _vignetteBackground = NO; + } + + return self; +} + +- (void)dealloc +{ + [_title release]; + [_message release]; + [_backgroundImage release]; + [_view release]; + [_blocks release]; + [super dealloc]; +} + +/////////////////////////////////////////////////////////////////////////////////////////////////// +#pragma mark - Public + +- (void)addButtonWithTitle:(NSString *)title color:(NSString*)color block:(void (^)())block +{ + [_blocks addObject:[NSArray arrayWithObjects: + block ? [[block copy] autorelease] : [NSNull null], + title, + color, + nil]]; +} + +- (void)addButtonWithTitle:(NSString *)title block:(void (^)())block +{ + [self addButtonWithTitle:title color:@"gray" block:block]; +} + +- (void)setCancelButtonWithTitle:(NSString *)title block:(void (^)())block +{ + [self addButtonWithTitle:title color:@"black" block:block]; +} + +- (void)setDestructiveButtonWithTitle:(NSString *)title block:(void (^)())block +{ + [self addButtonWithTitle:title color:@"red" block:block]; +} + +- (void)show +{ + _shown = YES; + + BOOL isSecondButton = NO; + NSUInteger index = 0; + for (NSUInteger i = 0; i < _blocks.count; i++) + { + NSArray *block = [_blocks objectAtIndex:i]; + NSString *title = [block objectAtIndex:1]; + NSString *color = [block objectAtIndex:2]; + + UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"alert-%@-button.png", color]]; + image = [image stretchableImageWithLeftCapWidth:(int)(image.size.width+1)>>1 topCapHeight:0]; + + CGFloat maxHalfWidth = floorf((_view.bounds.size.width-kAlertViewBorder*3)*0.5); + CGFloat width = _view.bounds.size.width-kAlertViewBorder*2; + CGFloat xOffset = kAlertViewBorder; + if (isSecondButton) + { + width = maxHalfWidth; + xOffset = width + kAlertViewBorder * 2; + isSecondButton = NO; + } + else if (i + 1 < _blocks.count) + { + // In this case there's another button. + // Let's check if they fit on the same line. + CGSize size = [title sizeWithFont:buttonFont + minFontSize:10 + actualFontSize:nil + forWidth:_view.bounds.size.width-kAlertViewBorder*2 + lineBreakMode:NSLineBreakByClipping]; + + if (size.width < maxHalfWidth - kAlertViewBorder) + { + // It might fit. Check the next Button + NSArray *block2 = [_blocks objectAtIndex:i+1]; + NSString *title2 = [block2 objectAtIndex:1]; + size = [title2 sizeWithFont:buttonFont + minFontSize:10 + actualFontSize:nil + forWidth:_view.bounds.size.width-kAlertViewBorder*2 + lineBreakMode:NSLineBreakByClipping]; + + if (size.width < maxHalfWidth - kAlertViewBorder) + { + // They'll fit! + isSecondButton = YES; // For the next iteration + width = maxHalfWidth; + } + } + } + else if (_blocks.count == 1) + { + // In this case this is the ony button. We'll size according to the text + CGSize size = [title sizeWithFont:buttonFont + minFontSize:10 + actualFontSize:nil + forWidth:_view.bounds.size.width-kAlertViewBorder*2 + lineBreakMode:UILineBreakModeClip]; + + size.width = MAX(size.width, 80); + if (size.width + 2 * kAlertViewBorder < width) + { + width = size.width + 2 * kAlertViewBorder; + xOffset = floorf((_view.bounds.size.width - width) * 0.5); + } + } + + UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; + button.frame = CGRectMake(xOffset, _height, width, kAlertButtonHeight); + button.titleLabel.font = buttonFont; + if (IOS_LESS_THAN_6) { +#pragma clan diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" + button.titleLabel.minimumFontSize = 10; +#pragma clan diagnostic pop + } + else { + button.titleLabel.adjustsFontSizeToFitWidth = YES; + button.titleLabel.adjustsLetterSpacingToFitWidth = YES; + button.titleLabel.minimumScaleFactor = 0.1; + } + button.titleLabel.textAlignment = NSTextAlignmentCenter; + button.titleLabel.shadowOffset = kAlertViewButtonShadowOffset; + button.backgroundColor = [UIColor clearColor]; + button.tag = i+1; + + [button setBackgroundImage:image forState:UIControlStateNormal]; + [button setTitleColor:kAlertViewButtonTextColor forState:UIControlStateNormal]; + [button setTitleShadowColor:kAlertViewButtonShadowColor forState:UIControlStateNormal]; + [button setTitle:title forState:UIControlStateNormal]; + button.accessibilityLabel = title; + + [button addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside]; + + [_view addSubview:button]; + + if (!isSecondButton) + _height += kAlertButtonHeight + kAlertViewBorder; + + index++; + } + + _height += 10; // Margin for the shadow + + if (_height < background.size.height) + { + CGFloat offset = background.size.height - _height; + _height = background.size.height; + CGRect frame; + for (NSUInteger i = 0; i < _blocks.count; i++) + { + UIButton *btn = (UIButton *)[_view viewWithTag:i+1]; + frame = btn.frame; + frame.origin.y += offset; + btn.frame = frame; + } + } + + + CGRect frame = _view.frame; + frame.origin.y = - _height; + frame.size.height = _height; + _view.frame = frame; + + UIImageView *modalBackground = [[UIImageView alloc] initWithFrame:_view.bounds]; + + if (UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation])) + modalBackground.image = backgroundlandscape; + else + modalBackground.image = background; + + modalBackground.contentMode = UIViewContentModeScaleToFill; + modalBackground.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; + [_view insertSubview:modalBackground atIndex:0]; + [modalBackground release]; + + if (_backgroundImage) + { + [BlockBackground sharedInstance].backgroundImage = _backgroundImage; + [_backgroundImage release]; + _backgroundImage = nil; + } + + [BlockBackground sharedInstance].vignetteBackground = _vignetteBackground; + [[BlockBackground sharedInstance] addToMainWindow:_view]; + + __block CGPoint center = _view.center; + center.y = floorf([BlockBackground sharedInstance].bounds.size.height * 0.5) + kAlertViewBounce; + + _cancelBounce = NO; + + [UIView animateWithDuration:0.4 + delay:0.0 + options:UIViewAnimationCurveEaseOut + animations:^{ + [BlockBackground sharedInstance].alpha = 1.0f; + _view.center = center; + } + completion:^(BOOL finished) { + if (_cancelBounce) return; + + [UIView animateWithDuration:0.1 + delay:0.0 + options:0 + animations:^{ + center.y -= kAlertViewBounce; + _view.center = center; + } + completion:^(BOOL finished) { + [[NSNotificationCenter defaultCenter] postNotificationName:@"AlertViewFinishedAnimations" object:nil]; + }]; + }]; + + [self retain]; +} + +- (void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)animated +{ + _shown = NO; + + [[NSNotificationCenter defaultCenter] removeObserver:self]; + + if (buttonIndex >= 0 && buttonIndex < [_blocks count]) + { + id obj = [[_blocks objectAtIndex: buttonIndex] objectAtIndex:0]; + if (![obj isEqual:[NSNull null]]) + { + ((void (^)())obj)(); + } + } + + if (animated) + { + [UIView animateWithDuration:0.1 + delay:0.0 + options:0 + animations:^{ + CGPoint center = _view.center; + center.y += 20; + _view.center = center; + } + completion:^(BOOL finished) { + [UIView animateWithDuration:0.4 + delay:0.0 + options:UIViewAnimationCurveEaseIn + animations:^{ + CGRect frame = _view.frame; + frame.origin.y = -frame.size.height; + _view.frame = frame; + [[BlockBackground sharedInstance] reduceAlphaIfEmpty]; + } + completion:^(BOOL finished) { + [[BlockBackground sharedInstance] removeView:_view]; + [_view release]; _view = nil; + [self autorelease]; + }]; + }]; + } + else + { + [[BlockBackground sharedInstance] removeView:_view]; + [_view release]; _view = nil; + [self autorelease]; + } +} + +/////////////////////////////////////////////////////////////////////////////////////////////////// +#pragma mark - Action + +- (void)buttonClicked:(id)sender +{ + /* Run the button's block */ + int buttonIndex = [sender tag] - 1; + [self dismissWithClickedButtonIndex:buttonIndex animated:YES]; +} + +@end diff --git a/client/iOS/Views/BlockBackground.h b/client/iOS/Views/BlockBackground.h new file mode 100644 index 000000000..8eabc209d --- /dev/null +++ b/client/iOS/Views/BlockBackground.h @@ -0,0 +1,25 @@ +// +// BlockBackground.h +// arrived +// +// Created by Gustavo Ambrozio on 29/11/11. +// Copyright (c) 2011 N/A. All rights reserved. +// + +#import <UIKit/UIKit.h> + +@interface BlockBackground : UIWindow { +@private + UIWindow *_previousKeyWindow; +} + ++ (BlockBackground *) sharedInstance; + +- (void)addToMainWindow:(UIView *)view; +- (void)reduceAlphaIfEmpty; +- (void)removeView:(UIView *)view; + +@property (nonatomic, retain) UIImage *backgroundImage; +@property (nonatomic, readwrite) BOOL vignetteBackground; + +@end diff --git a/client/iOS/Views/BlockBackground.m b/client/iOS/Views/BlockBackground.m new file mode 100644 index 000000000..9d7709a47 --- /dev/null +++ b/client/iOS/Views/BlockBackground.m @@ -0,0 +1,227 @@ +// +// BlockBackground.m +// arrived +// +// Created by Gustavo Ambrozio on 29/11/11. +// Copyright (c) 2011 N/A. All rights reserved. +// + +#import "BlockBackground.h" + +@implementation BlockBackground + +@synthesize backgroundImage = _backgroundImage; +@synthesize vignetteBackground = _vignetteBackground; + +static BlockBackground *_sharedInstance = nil; + ++ (BlockBackground*)sharedInstance +{ + if (_sharedInstance != nil) { + return _sharedInstance; + } + + @synchronized(self) { + if (_sharedInstance == nil) { + [[[self alloc] init] autorelease]; + } + } + + return _sharedInstance; +} + ++ (id)allocWithZone:(NSZone*)zone +{ + @synchronized(self) { + if (_sharedInstance == nil) { + _sharedInstance = [super allocWithZone:zone]; + return _sharedInstance; + } + } + NSAssert(NO, @ "[BlockBackground alloc] explicitly called on singleton class."); + return nil; +} + +- (id)copyWithZone:(NSZone*)zone +{ + return self; +} + +- (id)retain +{ + return self; +} + +- (unsigned)retainCount +{ + return UINT_MAX; +} + +- (oneway void)release +{ +} + +- (id)autorelease +{ + return self; +} + +- (void)setRotation:(NSNotification*)notification +{ + UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation]; + + CGRect orientationFrame = [UIScreen mainScreen].bounds; + + if( + (UIInterfaceOrientationIsLandscape(orientation) && orientationFrame.size.height > orientationFrame.size.width) || + (UIInterfaceOrientationIsPortrait(orientation) && orientationFrame.size.width > orientationFrame.size.height) + ) { + float temp = orientationFrame.size.width; + orientationFrame.size.width = orientationFrame.size.height; + orientationFrame.size.height = temp; + } + + self.transform = CGAffineTransformIdentity; + self.frame = orientationFrame; + + CGFloat posY = orientationFrame.size.height/2; + CGFloat posX = orientationFrame.size.width/2; + + CGPoint newCenter; + CGFloat rotateAngle; + + switch (orientation) { + case UIInterfaceOrientationPortraitUpsideDown: + rotateAngle = M_PI; + newCenter = CGPointMake(posX, orientationFrame.size.height-posY); + break; + case UIInterfaceOrientationLandscapeLeft: + rotateAngle = -M_PI/2.0f; + newCenter = CGPointMake(posY, posX); + break; + case UIInterfaceOrientationLandscapeRight: + rotateAngle = M_PI/2.0f; + newCenter = CGPointMake(orientationFrame.size.height-posY, posX); + break; + default: // UIInterfaceOrientationPortrait + rotateAngle = 0.0; + newCenter = CGPointMake(posX, posY); + break; + } + + self.transform = CGAffineTransformMakeRotation(rotateAngle); + self.center = newCenter; + + [self setNeedsLayout]; + [self layoutSubviews]; +} + +- (id)init +{ + self = [super initWithFrame:[[UIScreen mainScreen] bounds]]; + if (self) { + self.windowLevel = UIWindowLevelStatusBar; + self.hidden = YES; + self.userInteractionEnabled = NO; + self.backgroundColor = [UIColor colorWithWhite:0.4 alpha:0.5f]; + self.vignetteBackground = NO; + + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(setRotation:) + name:UIApplicationDidChangeStatusBarOrientationNotification + object:nil]; + [self setRotation:nil]; + + } + return self; +} + +- (void)addToMainWindow:(UIView *)view +{ + [self setRotation:nil]; + + if ([self.subviews containsObject:view]) return; + + if (self.hidden) + { + _previousKeyWindow = [[[UIApplication sharedApplication] keyWindow] retain]; + self.alpha = 0.0f; + self.hidden = NO; + self.userInteractionEnabled = YES; + [self makeKeyWindow]; + } + + if (self.subviews.count > 0) + { + ((UIView*)[self.subviews lastObject]).userInteractionEnabled = NO; + } + + if (_backgroundImage) + { + UIImageView *backgroundView = [[UIImageView alloc] initWithImage:_backgroundImage]; + backgroundView.frame = self.bounds; + backgroundView.contentMode = UIViewContentModeScaleToFill; + [self addSubview:backgroundView]; + [backgroundView release]; + [_backgroundImage release]; + _backgroundImage = nil; + } + + [self addSubview:view]; +} + +- (void)reduceAlphaIfEmpty +{ + if (self.subviews.count == 1 || (self.subviews.count == 2 && [[self.subviews objectAtIndex:0] isKindOfClass:[UIImageView class]])) + { + self.alpha = 0.0f; + self.userInteractionEnabled = NO; + } +} + +- (void)removeView:(UIView *)view +{ + [view removeFromSuperview]; + + UIView *topView = [self.subviews lastObject]; + if ([topView isKindOfClass:[UIImageView class]]) + { + // It's a background. Remove it too + [topView removeFromSuperview]; + } + + if (self.subviews.count == 0) + { + self.hidden = YES; + [_previousKeyWindow makeKeyWindow]; + [_previousKeyWindow release]; + _previousKeyWindow = nil; + } + else + { + ((UIView*)[self.subviews lastObject]).userInteractionEnabled = YES; + } +} + +- (void)drawRect:(CGRect)rect +{ + if (_backgroundImage || !_vignetteBackground) return; + CGContextRef context = UIGraphicsGetCurrentContext(); + + size_t locationsCount = 2; + CGFloat locations[2] = {0.0f, 1.0f}; + CGFloat colors[8] = {0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.75f}; + CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); + CGGradientRef gradient = CGGradientCreateWithColorComponents(colorSpace, colors, locations, locationsCount); + CGColorSpaceRelease(colorSpace); + + CGPoint center = CGPointMake(self.bounds.size.width/2, self.bounds.size.height/2); + float radius = MIN(self.bounds.size.width , self.bounds.size.height) ; + CGContextDrawRadialGradient (context, gradient, center, 0, center, radius, kCGGradientDrawsAfterEndLocation); + CGGradientRelease(gradient); +} + + + + +@end diff --git a/client/iOS/Views/BlockUI.h b/client/iOS/Views/BlockUI.h new file mode 100644 index 000000000..903b28646 --- /dev/null +++ b/client/iOS/Views/BlockUI.h @@ -0,0 +1,72 @@ +// +// BlockUI.h +// +// Created by Gustavo Ambrozio on 14/2/12. +// + +#ifndef BlockUI_h +#define BlockUI_h + +#if __IPHONE_OS_VERSION_MAX_ALLOWED < 60000 +#define NSTextAlignmentCenter UITextAlignmentCenter +#define NSLineBreakByWordWrapping UILineBreakModeWordWrap +#define NSLineBreakByClipping UILineBreakModeClip + +#endif + +#ifndef IOS_LESS_THAN_6 +#define IOS_LESS_THAN_6 !([[[UIDevice currentDevice] systemVersion] compare:@"6.0" options:NSNumericSearch] != NSOrderedAscending) + +#endif + +#define NeedsLandscapePhoneTweaks (UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation]) && UI_USER_INTERFACE_IDIOM() != UIUserInterfaceIdiomPad) + + +// Action Sheet constants + +#define kActionSheetBounce 10 +#define kActionSheetBorder 10 +#define kActionSheetButtonHeight 45 +#define kActionSheetTopMargin 15 + +#define kActionSheetTitleFont [UIFont systemFontOfSize:18] +#define kActionSheetTitleTextColor [UIColor whiteColor] +#define kActionSheetTitleShadowColor [UIColor blackColor] +#define kActionSheetTitleShadowOffset CGSizeMake(0, -1) + +#define kActionSheetButtonFont [UIFont boldSystemFontOfSize:20] +#define kActionSheetButtonTextColor [UIColor whiteColor] +#define kActionSheetButtonShadowColor [UIColor blackColor] +#define kActionSheetButtonShadowOffset CGSizeMake(0, -1) + +#define kActionSheetBackground @"action-sheet-panel.png" +#define kActionSheetBackgroundCapHeight 30 + + +// Alert View constants + +#define kAlertViewBounce 20 +#define kAlertViewBorder (NeedsLandscapePhoneTweaks ? 5 : 10) +#define kAlertButtonHeight (NeedsLandscapePhoneTweaks ? 35 : 44) + + +#define kAlertViewTitleFont [UIFont boldSystemFontOfSize:20] +#define kAlertViewTitleTextColor [UIColor colorWithWhite:244.0/255.0 alpha:1.0] +#define kAlertViewTitleShadowColor [UIColor blackColor] +#define kAlertViewTitleShadowOffset CGSizeMake(0, -1) + +#define kAlertViewMessageFont [UIFont systemFontOfSize:18] +#define kAlertViewMessageTextColor [UIColor colorWithWhite:244.0/255.0 alpha:1.0] +#define kAlertViewMessageShadowColor [UIColor blackColor] +#define kAlertViewMessageShadowOffset CGSizeMake(0, -1) + +#define kAlertViewButtonFont [UIFont boldSystemFontOfSize:18] +#define kAlertViewButtonTextColor [UIColor whiteColor] +#define kAlertViewButtonShadowColor [UIColor blackColor] +#define kAlertViewButtonShadowOffset CGSizeMake(0, -1) + +#define kAlertViewBackground @"alert-window.png" +#define kAlertViewBackgroundLandscape @"alert-window-landscape.png" +#define kAlertViewBackgroundCapHeight 38 + +#endif diff --git a/client/iOS/iFreeRDP.xcodeproj/project.pbxproj.cmake b/client/iOS/iFreeRDP.xcodeproj/project.pbxproj.cmake deleted file mode 100644 index 8cbdbd321..000000000 --- a/client/iOS/iFreeRDP.xcodeproj/project.pbxproj.cmake +++ /dev/null @@ -1,863 +0,0 @@ -// !$*UTF8*$! -{ - archiveVersion = 1; - classes = { - }; - objectVersion = 46; - objects = { - -/* Begin PBXBuildFile section */ - C495EE3416B8372D0041304E /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C495EE3316B8372D0041304E /* UIKit.framework */; }; - C495EE3616B8372D0041304E /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C495EE3516B8372D0041304E /* Foundation.framework */; }; - C495EE3816B8372D0041304E /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C495EE3716B8372D0041304E /* CoreGraphics.framework */; }; - C495EE7016B9107D0041304E /* Defaults.plist in Resources */ = {isa = PBXBuildFile; fileRef = C495EE6F16B9107D0041304E /* Defaults.plist */; }; - C495EE7716B910BC0041304E /* OrderedDictionary.m in Sources */ = {isa = PBXBuildFile; fileRef = C495EE7216B910BC0041304E /* OrderedDictionary.m */; }; - C495EE7816B910BC0041304E /* Toast+UIView.m in Sources */ = {isa = PBXBuildFile; fileRef = C495EE7416B910BC0041304E /* Toast+UIView.m */; }; - C495EE7916B910BC0041304E /* TSXAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = C495EE7616B910BC0041304E /* TSXAdditions.m */; }; - C495EE9B16B910DE0041304E /* AboutController.m in Sources */ = {isa = PBXBuildFile; fileRef = C495EE7C16B910DE0041304E /* AboutController.m */; }; - C495EE9C16B910DE0041304E /* AdvancedBookmarkEditorController.m in Sources */ = {isa = PBXBuildFile; fileRef = C495EE7E16B910DE0041304E /* AdvancedBookmarkEditorController.m */; }; - C495EE9D16B910DE0041304E /* AppSettingsController.m in Sources */ = {isa = PBXBuildFile; fileRef = C495EE8016B910DE0041304E /* AppSettingsController.m */; }; - C495EE9E16B910DE0041304E /* BookmarkEditorController.m in Sources */ = {isa = PBXBuildFile; fileRef = C495EE8216B910DE0041304E /* BookmarkEditorController.m */; }; - C495EE9F16B910DE0041304E /* BookmarkListController.m in Sources */ = {isa = PBXBuildFile; fileRef = C495EE8416B910DE0041304E /* BookmarkListController.m */; }; - C495EEA016B910DE0041304E /* CredentialsEditorController.m in Sources */ = {isa = PBXBuildFile; fileRef = C495EE8616B910DE0041304E /* CredentialsEditorController.m */; }; - C495EEA116B910DE0041304E /* CredentialsInputController.m in Sources */ = {isa = PBXBuildFile; fileRef = C495EE8816B910DE0041304E /* CredentialsInputController.m */; }; - C495EEA216B910DE0041304E /* EditorBaseController.m in Sources */ = {isa = PBXBuildFile; fileRef = C495EE8A16B910DE0041304E /* EditorBaseController.m */; }; - C495EEA316B910DE0041304E /* EditorSelectionController.m in Sources */ = {isa = PBXBuildFile; fileRef = C495EE8C16B910DE0041304E /* EditorSelectionController.m */; }; - C495EEA416B910DE0041304E /* EncryptionController.m in Sources */ = {isa = PBXBuildFile; fileRef = C495EE8E16B910DE0041304E /* EncryptionController.m */; }; - C495EEA516B910DE0041304E /* HelpController.m in Sources */ = {isa = PBXBuildFile; fileRef = C495EE9016B910DE0041304E /* HelpController.m */; }; - C495EEA616B910DE0041304E /* MainTabBarController.m in Sources */ = {isa = PBXBuildFile; fileRef = C495EE9216B910DE0041304E /* MainTabBarController.m */; }; - C495EEA716B910DE0041304E /* PerformanceEditorController.m in Sources */ = {isa = PBXBuildFile; fileRef = C495EE9416B910DE0041304E /* PerformanceEditorController.m */; }; - C495EEA816B910DE0041304E /* RDPSessionViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = C495EE9616B910DE0041304E /* RDPSessionViewController.m */; }; - C495EEA916B910DE0041304E /* ScreenSelectionController.m in Sources */ = {isa = PBXBuildFile; fileRef = C495EE9816B910DE0041304E /* ScreenSelectionController.m */; }; - C495EEAA16B910DE0041304E /* VerifyCertificateController.m in Sources */ = {isa = PBXBuildFile; fileRef = C495EE9A16B910DE0041304E /* VerifyCertificateController.m */; }; - C495EEB216B910F60041304E /* ios_freerdp_events.m in Sources */ = {isa = PBXBuildFile; fileRef = C495EEAD16B910F60041304E /* ios_freerdp_events.m */; }; - C495EEB316B910F60041304E /* ios_freerdp_ui.m in Sources */ = {isa = PBXBuildFile; fileRef = C495EEAF16B910F60041304E /* ios_freerdp_ui.m */; }; - C495EEB416B910F60041304E /* ios_freerdp.m in Sources */ = {isa = PBXBuildFile; fileRef = C495EEB116B910F60041304E /* ios_freerdp.m */; }; - C495EEBD16B9111A0041304E /* Reachability.m in Sources */ = {isa = PBXBuildFile; fileRef = C495EEB716B9111A0041304E /* Reachability.m */; }; - C495EEBE16B9111A0041304E /* SFHFKeychainUtils.m in Sources */ = {isa = PBXBuildFile; fileRef = C495EEB916B9111A0041304E /* SFHFKeychainUtils.m */; }; - C495EEBF16B9111A0041304E /* Utils.m in Sources */ = {isa = PBXBuildFile; fileRef = C495EEBC16B9111A0041304E /* Utils.m */; }; - C495EECD16B911290041304E /* Bookmark.m in Sources */ = {isa = PBXBuildFile; fileRef = C495EEC216B911290041304E /* Bookmark.m */; }; - C495EECE16B911290041304E /* ConnectionParams.m in Sources */ = {isa = PBXBuildFile; fileRef = C495EEC416B911290041304E /* ConnectionParams.m */; }; - C495EECF16B911290041304E /* Encryptor.m in Sources */ = {isa = PBXBuildFile; fileRef = C495EEC616B911290041304E /* Encryptor.m */; }; - C495EED016B911290041304E /* GlobalDefaults.m in Sources */ = {isa = PBXBuildFile; fileRef = C495EEC816B911290041304E /* GlobalDefaults.m */; }; - C495EED116B911290041304E /* RDPKeyboard.m in Sources */ = {isa = PBXBuildFile; fileRef = C495EECA16B911290041304E /* RDPKeyboard.m */; }; - C495EED216B911290041304E /* RDPSession.m in Sources */ = {isa = PBXBuildFile; fileRef = C495EECC16B911290041304E /* RDPSession.m */; }; - C495EF3216B911450041304E /* BookmarkListView.xib in Resources */ = {isa = PBXBuildFile; fileRef = C495EEDA16B911450041304E /* BookmarkListView.xib */; }; - C495EF3316B911450041304E /* BookmarkTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = C495EEDB16B911450041304E /* BookmarkTableViewCell.xib */; }; - C495EF3416B911450041304E /* cancel_button_background.png in Resources */ = {isa = PBXBuildFile; fileRef = C495EEDC16B911450041304E /* cancel_button_background.png */; }; - C495EF3516B911450041304E /* CredentialsInputView.xib in Resources */ = {isa = PBXBuildFile; fileRef = C495EEDD16B911450041304E /* CredentialsInputView.xib */; }; - C495EF3616B911450041304E /* Default-Landscape@2x~ipad.png in Resources */ = {isa = PBXBuildFile; fileRef = C495EEDE16B911450041304E /* Default-Landscape@2x~ipad.png */; }; - C495EF3716B911450041304E /* Default-Landscape~ipad.png in Resources */ = {isa = PBXBuildFile; fileRef = C495EEDF16B911450041304E /* Default-Landscape~ipad.png */; }; - C495EF3816B911450041304E /* Default-Portrait@2x~ipad.png in Resources */ = {isa = PBXBuildFile; fileRef = C495EEE016B911450041304E /* Default-Portrait@2x~ipad.png */; }; - C495EF3916B911450041304E /* Default-Portrait~ipad.png in Resources */ = {isa = PBXBuildFile; fileRef = C495EEE116B911450041304E /* Default-Portrait~ipad.png */; }; - C495EF3A16B911450041304E /* Default.png in Resources */ = {isa = PBXBuildFile; fileRef = C495EEE216B911450041304E /* Default.png */; }; - C495EF3B16B911450041304E /* Default@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = C495EEE316B911450041304E /* Default@2x.png */; }; - C495EF3C16B911450041304E /* EditButtonTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = C495EEE416B911450041304E /* EditButtonTableViewCell.xib */; }; - C495EF3D16B911450041304E /* EditFlagTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = C495EEE516B911450041304E /* EditFlagTableViewCell.xib */; }; - C495EF3E16B911450041304E /* EditSecretTextTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = C495EEE616B911450041304E /* EditSecretTextTableViewCell.xib */; }; - C495EF3F16B911450041304E /* EditSelectionTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = C495EEE716B911450041304E /* EditSelectionTableViewCell.xib */; }; - C495EF4016B911450041304E /* EditSubEditTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = C495EEE816B911450041304E /* EditSubEditTableViewCell.xib */; }; - C495EF4116B911450041304E /* EditTextTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = C495EEE916B911450041304E /* EditTextTableViewCell.xib */; }; - C495EF5316B911450041304E /* icon_accessory_star_off.png in Resources */ = {isa = PBXBuildFile; fileRef = C495EEFE16B911450041304E /* icon_accessory_star_off.png */; }; - C495EF5416B911450041304E /* icon_accessory_star_on.png in Resources */ = {isa = PBXBuildFile; fileRef = C495EEFF16B911450041304E /* icon_accessory_star_on.png */; }; - C495EF5516B911450041304E /* icon_key_arrow_down.png in Resources */ = {isa = PBXBuildFile; fileRef = C495EF0016B911450041304E /* icon_key_arrow_down.png */; }; - C495EF5616B911450041304E /* icon_key_arrow_left.png in Resources */ = {isa = PBXBuildFile; fileRef = C495EF0116B911450041304E /* icon_key_arrow_left.png */; }; - C495EF5716B911450041304E /* icon_key_arrow_right.png in Resources */ = {isa = PBXBuildFile; fileRef = C495EF0216B911450041304E /* icon_key_arrow_right.png */; }; - C495EF5816B911450041304E /* icon_key_arrow_up.png in Resources */ = {isa = PBXBuildFile; fileRef = C495EF0316B911450041304E /* icon_key_arrow_up.png */; }; - C495EF5916B911450041304E /* icon_key_arrows.png in Resources */ = {isa = PBXBuildFile; fileRef = C495EF0416B911450041304E /* icon_key_arrows.png */; }; - C495EF5A16B911450041304E /* icon_key_backspace.png in Resources */ = {isa = PBXBuildFile; fileRef = C495EF0516B911450041304E /* icon_key_backspace.png */; }; - C495EF5B16B911450041304E /* icon_key_menu.png in Resources */ = {isa = PBXBuildFile; fileRef = C495EF0616B911450041304E /* icon_key_menu.png */; }; - C495EF5C16B911450041304E /* icon_key_return.png in Resources */ = {isa = PBXBuildFile; fileRef = C495EF0716B911450041304E /* icon_key_return.png */; }; - C495EF5D16B911450041304E /* icon_key_win.png in Resources */ = {isa = PBXBuildFile; fileRef = C495EF0816B911450041304E /* icon_key_win.png */; }; - C495EF5E16B911450041304E /* Icon-72.png in Resources */ = {isa = PBXBuildFile; fileRef = C495EF0916B911450041304E /* Icon-72.png */; }; - C495EF5F16B911450041304E /* Icon-72@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = C495EF0A16B911450041304E /* Icon-72@2x.png */; }; - C495EF6016B911450041304E /* Icon.png in Resources */ = {isa = PBXBuildFile; fileRef = C495EF0B16B911450041304E /* Icon.png */; }; - C495EF6116B911450041304E /* Icon@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = C495EF0C16B911450041304E /* Icon@2x.png */; }; - C495EF6216B911450041304E /* keyboard_button_background.png in Resources */ = {isa = PBXBuildFile; fileRef = C495EF0D16B911450041304E /* keyboard_button_background.png */; }; - C495EF6316B911450041304E /* MainWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = C495EF0E16B911450041304E /* MainWindow.xib */; }; - C495EF6416B911450041304E /* RDPConnectingView.xib in Resources */ = {isa = PBXBuildFile; fileRef = C495EF0F16B911450041304E /* RDPConnectingView.xib */; }; - C495EF6516B911450041304E /* RDPSessionView.xib in Resources */ = {isa = PBXBuildFile; fileRef = C495EF1016B911450041304E /* RDPSessionView.xib */; }; - C495EF6616B911450041304E /* SessionTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = C495EF1116B911450041304E /* SessionTableViewCell.xib */; }; - C495EF6716B911450041304E /* tabbar_icon_about.png in Resources */ = {isa = PBXBuildFile; fileRef = C495EF1216B911450041304E /* tabbar_icon_about.png */; }; - C495EF6816B911450041304E /* tabbar_icon_help.png in Resources */ = {isa = PBXBuildFile; fileRef = C495EF1316B911450041304E /* tabbar_icon_help.png */; }; - C495EF6916B911450041304E /* tabbar_icon_settings.png in Resources */ = {isa = PBXBuildFile; fileRef = C495EF1416B911450041304E /* tabbar_icon_settings.png */; }; - C495EF6A16B911450041304E /* toolbar_icon_disconnect.png in Resources */ = {isa = PBXBuildFile; fileRef = C495EF1516B911450041304E /* toolbar_icon_disconnect.png */; }; - C495EF6B16B911450041304E /* toolbar_icon_extkeyboad.png in Resources */ = {isa = PBXBuildFile; fileRef = C495EF1616B911450041304E /* toolbar_icon_extkeyboad.png */; }; - C495EF6C16B911450041304E /* toolbar_icon_home.png in Resources */ = {isa = PBXBuildFile; fileRef = C495EF1716B911450041304E /* toolbar_icon_home.png */; }; - C495EF6D16B911450041304E /* toolbar_icon_keyboard.png in Resources */ = {isa = PBXBuildFile; fileRef = C495EF1816B911450041304E /* toolbar_icon_keyboard.png */; }; - C495EF6E16B911450041304E /* toolbar_icon_touchpointer.png in Resources */ = {isa = PBXBuildFile; fileRef = C495EF1916B911450041304E /* toolbar_icon_touchpointer.png */; }; - C495EF6F16B911450041304E /* toolbar_icon_win.png in Resources */ = {isa = PBXBuildFile; fileRef = C495EF1A16B911450041304E /* toolbar_icon_win.png */; }; - C495EF7016B911450041304E /* touch_pointer_active.png in Resources */ = {isa = PBXBuildFile; fileRef = C495EF1B16B911450041304E /* touch_pointer_active.png */; }; - C495EF7116B911450041304E /* touch_pointer_default.png in Resources */ = {isa = PBXBuildFile; fileRef = C495EF1C16B911450041304E /* touch_pointer_default.png */; }; - C495EF7216B911450041304E /* touch_pointer_extkeyboard.png in Resources */ = {isa = PBXBuildFile; fileRef = C495EF1D16B911450041304E /* touch_pointer_extkeyboard.png */; }; - C495EF7316B911450041304E /* touch_pointer_keyboard.png in Resources */ = {isa = PBXBuildFile; fileRef = C495EF1E16B911450041304E /* touch_pointer_keyboard.png */; }; - C495EF7416B911450041304E /* touch_pointer_lclick.png in Resources */ = {isa = PBXBuildFile; fileRef = C495EF1F16B911450041304E /* touch_pointer_lclick.png */; }; - C495EF7516B911450041304E /* touch_pointer_rclick.png in Resources */ = {isa = PBXBuildFile; fileRef = C495EF2016B911450041304E /* touch_pointer_rclick.png */; }; - C495EF7616B911450041304E /* touch_pointer_reset.png in Resources */ = {isa = PBXBuildFile; fileRef = C495EF2116B911450041304E /* touch_pointer_reset.png */; }; - C495EF7716B911450041304E /* touch_pointer_scroll.png in Resources */ = {isa = PBXBuildFile; fileRef = C495EF2216B911450041304E /* touch_pointer_scroll.png */; }; - C495EF7816B911450041304E /* VerifyCertificateView.xib in Resources */ = {isa = PBXBuildFile; fileRef = C495EF2316B911450041304E /* VerifyCertificateView.xib */; }; - C495EF9A16B911AC0041304E /* AdvancedKeyboardView.m in Sources */ = {isa = PBXBuildFile; fileRef = C495EF8316B911AB0041304E /* AdvancedKeyboardView.m */; }; - C495EF9B16B911AC0041304E /* BookmarkTableCell.m in Sources */ = {isa = PBXBuildFile; fileRef = C495EF8516B911AB0041304E /* BookmarkTableCell.m */; }; - C495EF9C16B911AC0041304E /* EditButtonTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = C495EF8716B911AB0041304E /* EditButtonTableViewCell.m */; }; - C495EF9D16B911AC0041304E /* EditFlagTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = C495EF8916B911AB0041304E /* EditFlagTableViewCell.m */; }; - C495EF9E16B911AC0041304E /* EditSecretTextTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = C495EF8B16B911AB0041304E /* EditSecretTextTableViewCell.m */; }; - C495EF9F16B911AC0041304E /* EditSelectionTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = C495EF8D16B911AB0041304E /* EditSelectionTableViewCell.m */; }; - C495EFA016B911AC0041304E /* EditSubEditTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = C495EF8F16B911AB0041304E /* EditSubEditTableViewCell.m */; }; - C495EFA116B911AC0041304E /* EditTextTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = C495EF9116B911AB0041304E /* EditTextTableViewCell.m */; }; - C495EFA216B911AC0041304E /* RDPSessionView.m in Sources */ = {isa = PBXBuildFile; fileRef = C495EF9316B911AB0041304E /* RDPSessionView.m */; }; - C495EFA316B911AC0041304E /* SessionTableCell.m in Sources */ = {isa = PBXBuildFile; fileRef = C495EF9516B911AB0041304E /* SessionTableCell.m */; }; - C495EFA416B911AC0041304E /* TouchPointerView.m in Sources */ = {isa = PBXBuildFile; fileRef = C495EF9716B911AB0041304E /* TouchPointerView.m */; }; - C495EFAB16B912C40041304E /* libfreerdp.a in Frameworks */ = {isa = PBXBuildFile; fileRef = C495EFAA16B912C40041304E /* libfreerdp.a */; }; - C495EFAE16B913980041304E /* libwinpr.a in Frameworks */ = {isa = PBXBuildFile; fileRef = C495EFAD16B913980041304E /* libwinpr.a */; }; - C495EFBB16B92E170041304E /* about_page in Resources */ = {isa = PBXBuildFile; fileRef = C495EFBA16B92E170041304E /* about_page */; }; - C495EFBD16B92E270041304E /* help_page in Resources */ = {isa = PBXBuildFile; fileRef = C495EFBC16B92E270041304E /* help_page */; }; - C495EFC216B92EA20041304E /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = C495EFC016B92EA20041304E /* Localizable.strings */; }; - C495EFCB16B933230041304E /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = C495EFC916B933230041304E /* AppDelegate.m */; }; - C495EFCC16B933230041304E /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = C495EFCA16B933230041304E /* main.m */; }; - C495F01716B937F90041304E /* libcrypto.a in Frameworks */ = {isa = PBXBuildFile; fileRef = C495F01516B937F80041304E /* libcrypto.a */; }; - C495F01816B937F90041304E /* libssl.a in Frameworks */ = {isa = PBXBuildFile; fileRef = C495F01616B937F90041304E /* libssl.a */; }; - C495F01A16B938210041304E /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C495F01916B938210041304E /* Security.framework */; }; - C495F01E16B938CB0041304E /* SystemConfiguration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C495F01D16B938CA0041304E /* SystemConfiguration.framework */; }; - C4C31C6F16BAD1890087BB12 /* Default-568h@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = C4C31C6E16BAD1890087BB12 /* Default-568h@2x.png */; }; -/* End PBXBuildFile section */ - -/* Begin PBXFileReference section */ - C495EE2F16B8372D0041304E /* iFreeRDP.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = iFreeRDP.app; sourceTree = BUILT_PRODUCTS_DIR; }; - C495EE3316B8372D0041304E /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; }; - C495EE3516B8372D0041304E /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; - C495EE3716B8372D0041304E /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; }; - C495EE4116B8372D0041304E /* iFreeRDP-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "iFreeRDP-Prefix.pch"; sourceTree = "<group>"; }; - C495EE6D16B910510041304E /* iFreeRDP.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = iFreeRDP.plist; sourceTree = SOURCE_ROOT; }; - C495EE6F16B9107D0041304E /* Defaults.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Defaults.plist; sourceTree = SOURCE_ROOT; }; - C495EE7116B910BC0041304E /* OrderedDictionary.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OrderedDictionary.h; path = Additions/OrderedDictionary.h; sourceTree = SOURCE_ROOT; }; - C495EE7216B910BC0041304E /* OrderedDictionary.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OrderedDictionary.m; path = Additions/OrderedDictionary.m; sourceTree = SOURCE_ROOT; }; - C495EE7316B910BC0041304E /* Toast+UIView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "Toast+UIView.h"; path = "Additions/Toast+UIView.h"; sourceTree = SOURCE_ROOT; }; - C495EE7416B910BC0041304E /* Toast+UIView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "Toast+UIView.m"; path = "Additions/Toast+UIView.m"; sourceTree = SOURCE_ROOT; }; - C495EE7516B910BC0041304E /* TSXAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = TSXAdditions.h; path = Additions/TSXAdditions.h; sourceTree = SOURCE_ROOT; }; - C495EE7616B910BC0041304E /* TSXAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = TSXAdditions.m; path = Additions/TSXAdditions.m; sourceTree = SOURCE_ROOT; }; - C495EE7B16B910DE0041304E /* AboutController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AboutController.h; path = Controllers/AboutController.h; sourceTree = SOURCE_ROOT; }; - C495EE7C16B910DE0041304E /* AboutController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = AboutController.m; path = Controllers/AboutController.m; sourceTree = SOURCE_ROOT; }; - C495EE7D16B910DE0041304E /* AdvancedBookmarkEditorController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AdvancedBookmarkEditorController.h; path = Controllers/AdvancedBookmarkEditorController.h; sourceTree = SOURCE_ROOT; }; - C495EE7E16B910DE0041304E /* AdvancedBookmarkEditorController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = AdvancedBookmarkEditorController.m; path = Controllers/AdvancedBookmarkEditorController.m; sourceTree = SOURCE_ROOT; }; - C495EE7F16B910DE0041304E /* AppSettingsController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AppSettingsController.h; path = Controllers/AppSettingsController.h; sourceTree = SOURCE_ROOT; }; - C495EE8016B910DE0041304E /* AppSettingsController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = AppSettingsController.m; path = Controllers/AppSettingsController.m; sourceTree = SOURCE_ROOT; }; - C495EE8116B910DE0041304E /* BookmarkEditorController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = BookmarkEditorController.h; path = Controllers/BookmarkEditorController.h; sourceTree = SOURCE_ROOT; }; - C495EE8216B910DE0041304E /* BookmarkEditorController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = BookmarkEditorController.m; path = Controllers/BookmarkEditorController.m; sourceTree = SOURCE_ROOT; }; - C495EE8316B910DE0041304E /* BookmarkListController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = BookmarkListController.h; path = Controllers/BookmarkListController.h; sourceTree = SOURCE_ROOT; }; - C495EE8416B910DE0041304E /* BookmarkListController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = BookmarkListController.m; path = Controllers/BookmarkListController.m; sourceTree = SOURCE_ROOT; }; - C495EE8516B910DE0041304E /* CredentialsEditorController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CredentialsEditorController.h; path = Controllers/CredentialsEditorController.h; sourceTree = SOURCE_ROOT; }; - C495EE8616B910DE0041304E /* CredentialsEditorController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = CredentialsEditorController.m; path = Controllers/CredentialsEditorController.m; sourceTree = SOURCE_ROOT; }; - C495EE8716B910DE0041304E /* CredentialsInputController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CredentialsInputController.h; path = Controllers/CredentialsInputController.h; sourceTree = SOURCE_ROOT; }; - C495EE8816B910DE0041304E /* CredentialsInputController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = CredentialsInputController.m; path = Controllers/CredentialsInputController.m; sourceTree = SOURCE_ROOT; }; - C495EE8916B910DE0041304E /* EditorBaseController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = EditorBaseController.h; path = Controllers/EditorBaseController.h; sourceTree = SOURCE_ROOT; }; - C495EE8A16B910DE0041304E /* EditorBaseController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = EditorBaseController.m; path = Controllers/EditorBaseController.m; sourceTree = SOURCE_ROOT; }; - C495EE8B16B910DE0041304E /* EditorSelectionController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = EditorSelectionController.h; path = Controllers/EditorSelectionController.h; sourceTree = SOURCE_ROOT; }; - C495EE8C16B910DE0041304E /* EditorSelectionController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = EditorSelectionController.m; path = Controllers/EditorSelectionController.m; sourceTree = SOURCE_ROOT; }; - C495EE8D16B910DE0041304E /* EncryptionController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = EncryptionController.h; path = Controllers/EncryptionController.h; sourceTree = SOURCE_ROOT; }; - C495EE8E16B910DE0041304E /* EncryptionController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = EncryptionController.m; path = Controllers/EncryptionController.m; sourceTree = SOURCE_ROOT; }; - C495EE8F16B910DE0041304E /* HelpController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = HelpController.h; path = Controllers/HelpController.h; sourceTree = SOURCE_ROOT; }; - C495EE9016B910DE0041304E /* HelpController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = HelpController.m; path = Controllers/HelpController.m; sourceTree = SOURCE_ROOT; }; - C495EE9116B910DE0041304E /* MainTabBarController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = MainTabBarController.h; path = Controllers/MainTabBarController.h; sourceTree = SOURCE_ROOT; }; - C495EE9216B910DE0041304E /* MainTabBarController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = MainTabBarController.m; path = Controllers/MainTabBarController.m; sourceTree = SOURCE_ROOT; }; - C495EE9316B910DE0041304E /* PerformanceEditorController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = PerformanceEditorController.h; path = Controllers/PerformanceEditorController.h; sourceTree = SOURCE_ROOT; }; - C495EE9416B910DE0041304E /* PerformanceEditorController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = PerformanceEditorController.m; path = Controllers/PerformanceEditorController.m; sourceTree = SOURCE_ROOT; }; - C495EE9516B910DE0041304E /* RDPSessionViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RDPSessionViewController.h; path = Controllers/RDPSessionViewController.h; sourceTree = SOURCE_ROOT; }; - C495EE9616B910DE0041304E /* RDPSessionViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = RDPSessionViewController.m; path = Controllers/RDPSessionViewController.m; sourceTree = SOURCE_ROOT; }; - C495EE9716B910DE0041304E /* ScreenSelectionController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ScreenSelectionController.h; path = Controllers/ScreenSelectionController.h; sourceTree = SOURCE_ROOT; }; - C495EE9816B910DE0041304E /* ScreenSelectionController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = ScreenSelectionController.m; path = Controllers/ScreenSelectionController.m; sourceTree = SOURCE_ROOT; }; - C495EE9916B910DE0041304E /* VerifyCertificateController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = VerifyCertificateController.h; path = Controllers/VerifyCertificateController.h; sourceTree = SOURCE_ROOT; }; - C495EE9A16B910DE0041304E /* VerifyCertificateController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = VerifyCertificateController.m; path = Controllers/VerifyCertificateController.m; sourceTree = SOURCE_ROOT; }; - C495EEAC16B910F60041304E /* ios_freerdp_events.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ios_freerdp_events.h; path = FreeRDP/ios_freerdp_events.h; sourceTree = SOURCE_ROOT; }; - C495EEAD16B910F60041304E /* ios_freerdp_events.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = ios_freerdp_events.m; path = FreeRDP/ios_freerdp_events.m; sourceTree = SOURCE_ROOT; }; - C495EEAE16B910F60041304E /* ios_freerdp_ui.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ios_freerdp_ui.h; path = FreeRDP/ios_freerdp_ui.h; sourceTree = SOURCE_ROOT; }; - C495EEAF16B910F60041304E /* ios_freerdp_ui.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = ios_freerdp_ui.m; path = FreeRDP/ios_freerdp_ui.m; sourceTree = SOURCE_ROOT; }; - C495EEB016B910F60041304E /* ios_freerdp.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ios_freerdp.h; path = FreeRDP/ios_freerdp.h; sourceTree = SOURCE_ROOT; }; - C495EEB116B910F60041304E /* ios_freerdp.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = ios_freerdp.m; path = FreeRDP/ios_freerdp.m; sourceTree = SOURCE_ROOT; }; - C495EEB616B9111A0041304E /* Reachability.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Reachability.h; path = Misc/Reachability.h; sourceTree = SOURCE_ROOT; }; - C495EEB716B9111A0041304E /* Reachability.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = Reachability.m; path = Misc/Reachability.m; sourceTree = SOURCE_ROOT; }; - C495EEB816B9111A0041304E /* SFHFKeychainUtils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SFHFKeychainUtils.h; path = Misc/SFHFKeychainUtils.h; sourceTree = SOURCE_ROOT; }; - C495EEB916B9111A0041304E /* SFHFKeychainUtils.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SFHFKeychainUtils.m; path = Misc/SFHFKeychainUtils.m; sourceTree = SOURCE_ROOT; }; - C495EEBA16B9111A0041304E /* TSXTypes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = TSXTypes.h; path = Misc/TSXTypes.h; sourceTree = SOURCE_ROOT; }; - C495EEBB16B9111A0041304E /* Utils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Utils.h; path = Misc/Utils.h; sourceTree = SOURCE_ROOT; }; - C495EEBC16B9111A0041304E /* Utils.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = Utils.m; path = Misc/Utils.m; sourceTree = SOURCE_ROOT; }; - C495EEC116B911290041304E /* Bookmark.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Bookmark.h; path = Models/Bookmark.h; sourceTree = SOURCE_ROOT; }; - C495EEC216B911290041304E /* Bookmark.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = Bookmark.m; path = Models/Bookmark.m; sourceTree = SOURCE_ROOT; }; - C495EEC316B911290041304E /* ConnectionParams.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ConnectionParams.h; path = Models/ConnectionParams.h; sourceTree = SOURCE_ROOT; }; - C495EEC416B911290041304E /* ConnectionParams.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = ConnectionParams.m; path = Models/ConnectionParams.m; sourceTree = SOURCE_ROOT; }; - C495EEC516B911290041304E /* Encryptor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Encryptor.h; path = Models/Encryptor.h; sourceTree = SOURCE_ROOT; }; - C495EEC616B911290041304E /* Encryptor.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = Encryptor.m; path = Models/Encryptor.m; sourceTree = SOURCE_ROOT; }; - C495EEC716B911290041304E /* GlobalDefaults.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = GlobalDefaults.h; path = Models/GlobalDefaults.h; sourceTree = SOURCE_ROOT; }; - C495EEC816B911290041304E /* GlobalDefaults.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = GlobalDefaults.m; path = Models/GlobalDefaults.m; sourceTree = SOURCE_ROOT; }; - C495EEC916B911290041304E /* RDPKeyboard.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RDPKeyboard.h; path = Models/RDPKeyboard.h; sourceTree = SOURCE_ROOT; }; - C495EECA16B911290041304E /* RDPKeyboard.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = RDPKeyboard.m; path = Models/RDPKeyboard.m; sourceTree = SOURCE_ROOT; }; - C495EECB16B911290041304E /* RDPSession.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RDPSession.h; path = Models/RDPSession.h; sourceTree = SOURCE_ROOT; }; - C495EECC16B911290041304E /* RDPSession.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = RDPSession.m; path = Models/RDPSession.m; sourceTree = SOURCE_ROOT; }; - C495EEDA16B911450041304E /* BookmarkListView.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = BookmarkListView.xib; path = Resources/BookmarkListView.xib; sourceTree = SOURCE_ROOT; }; - C495EEDB16B911450041304E /* BookmarkTableViewCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = BookmarkTableViewCell.xib; path = Resources/BookmarkTableViewCell.xib; sourceTree = SOURCE_ROOT; }; - C495EEDC16B911450041304E /* cancel_button_background.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = cancel_button_background.png; path = Resources/cancel_button_background.png; sourceTree = SOURCE_ROOT; }; - C495EEDD16B911450041304E /* CredentialsInputView.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = CredentialsInputView.xib; path = Resources/CredentialsInputView.xib; sourceTree = SOURCE_ROOT; }; - C495EEDE16B911450041304E /* Default-Landscape@2x~ipad.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "Default-Landscape@2x~ipad.png"; path = "Resources/Default-Landscape@2x~ipad.png"; sourceTree = SOURCE_ROOT; }; - C495EEDF16B911450041304E /* Default-Landscape~ipad.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "Default-Landscape~ipad.png"; path = "Resources/Default-Landscape~ipad.png"; sourceTree = SOURCE_ROOT; }; - C495EEE016B911450041304E /* Default-Portrait@2x~ipad.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "Default-Portrait@2x~ipad.png"; path = "Resources/Default-Portrait@2x~ipad.png"; sourceTree = SOURCE_ROOT; }; - C495EEE116B911450041304E /* Default-Portrait~ipad.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "Default-Portrait~ipad.png"; path = "Resources/Default-Portrait~ipad.png"; sourceTree = SOURCE_ROOT; }; - C495EEE216B911450041304E /* Default.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = Default.png; path = Resources/Default.png; sourceTree = SOURCE_ROOT; }; - C495EEE316B911450041304E /* Default@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "Default@2x.png"; path = "Resources/Default@2x.png"; sourceTree = SOURCE_ROOT; }; - C495EEE416B911450041304E /* EditButtonTableViewCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = EditButtonTableViewCell.xib; path = Resources/EditButtonTableViewCell.xib; sourceTree = SOURCE_ROOT; }; - C495EEE516B911450041304E /* EditFlagTableViewCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = EditFlagTableViewCell.xib; path = Resources/EditFlagTableViewCell.xib; sourceTree = SOURCE_ROOT; }; - C495EEE616B911450041304E /* EditSecretTextTableViewCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = EditSecretTextTableViewCell.xib; path = Resources/EditSecretTextTableViewCell.xib; sourceTree = SOURCE_ROOT; }; - C495EEE716B911450041304E /* EditSelectionTableViewCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = EditSelectionTableViewCell.xib; path = Resources/EditSelectionTableViewCell.xib; sourceTree = SOURCE_ROOT; }; - C495EEE816B911450041304E /* EditSubEditTableViewCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = EditSubEditTableViewCell.xib; path = Resources/EditSubEditTableViewCell.xib; sourceTree = SOURCE_ROOT; }; - C495EEE916B911450041304E /* EditTextTableViewCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = EditTextTableViewCell.xib; path = Resources/EditTextTableViewCell.xib; sourceTree = SOURCE_ROOT; }; - C495EEFE16B911450041304E /* icon_accessory_star_off.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = icon_accessory_star_off.png; path = Resources/icon_accessory_star_off.png; sourceTree = SOURCE_ROOT; }; - C495EEFF16B911450041304E /* icon_accessory_star_on.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = icon_accessory_star_on.png; path = Resources/icon_accessory_star_on.png; sourceTree = SOURCE_ROOT; }; - C495EF0016B911450041304E /* icon_key_arrow_down.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = icon_key_arrow_down.png; path = Resources/icon_key_arrow_down.png; sourceTree = SOURCE_ROOT; }; - C495EF0116B911450041304E /* icon_key_arrow_left.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = icon_key_arrow_left.png; path = Resources/icon_key_arrow_left.png; sourceTree = SOURCE_ROOT; }; - C495EF0216B911450041304E /* icon_key_arrow_right.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = icon_key_arrow_right.png; path = Resources/icon_key_arrow_right.png; sourceTree = SOURCE_ROOT; }; - C495EF0316B911450041304E /* icon_key_arrow_up.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = icon_key_arrow_up.png; path = Resources/icon_key_arrow_up.png; sourceTree = SOURCE_ROOT; }; - C495EF0416B911450041304E /* icon_key_arrows.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = icon_key_arrows.png; path = Resources/icon_key_arrows.png; sourceTree = SOURCE_ROOT; }; - C495EF0516B911450041304E /* icon_key_backspace.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = icon_key_backspace.png; path = Resources/icon_key_backspace.png; sourceTree = SOURCE_ROOT; }; - C495EF0616B911450041304E /* icon_key_menu.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = icon_key_menu.png; path = Resources/icon_key_menu.png; sourceTree = SOURCE_ROOT; }; - C495EF0716B911450041304E /* icon_key_return.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = icon_key_return.png; path = Resources/icon_key_return.png; sourceTree = SOURCE_ROOT; }; - C495EF0816B911450041304E /* icon_key_win.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = icon_key_win.png; path = Resources/icon_key_win.png; sourceTree = SOURCE_ROOT; }; - C495EF0916B911450041304E /* Icon-72.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "Icon-72.png"; path = "Resources/Icon-72.png"; sourceTree = SOURCE_ROOT; }; - C495EF0A16B911450041304E /* Icon-72@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "Icon-72@2x.png"; path = "Resources/Icon-72@2x.png"; sourceTree = SOURCE_ROOT; }; - C495EF0B16B911450041304E /* Icon.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = Icon.png; path = Resources/Icon.png; sourceTree = SOURCE_ROOT; }; - C495EF0C16B911450041304E /* Icon@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "Icon@2x.png"; path = "Resources/Icon@2x.png"; sourceTree = SOURCE_ROOT; }; - C495EF0D16B911450041304E /* keyboard_button_background.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = keyboard_button_background.png; path = Resources/keyboard_button_background.png; sourceTree = SOURCE_ROOT; }; - C495EF0E16B911450041304E /* MainWindow.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = MainWindow.xib; path = Resources/MainWindow.xib; sourceTree = SOURCE_ROOT; }; - C495EF0F16B911450041304E /* RDPConnectingView.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = RDPConnectingView.xib; path = Resources/RDPConnectingView.xib; sourceTree = SOURCE_ROOT; }; - C495EF1016B911450041304E /* RDPSessionView.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = RDPSessionView.xib; path = Resources/RDPSessionView.xib; sourceTree = SOURCE_ROOT; }; - C495EF1116B911450041304E /* SessionTableViewCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = SessionTableViewCell.xib; path = Resources/SessionTableViewCell.xib; sourceTree = SOURCE_ROOT; }; - C495EF1216B911450041304E /* tabbar_icon_about.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = tabbar_icon_about.png; path = Resources/tabbar_icon_about.png; sourceTree = SOURCE_ROOT; }; - C495EF1316B911450041304E /* tabbar_icon_help.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = tabbar_icon_help.png; path = Resources/tabbar_icon_help.png; sourceTree = SOURCE_ROOT; }; - C495EF1416B911450041304E /* tabbar_icon_settings.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = tabbar_icon_settings.png; path = Resources/tabbar_icon_settings.png; sourceTree = SOURCE_ROOT; }; - C495EF1516B911450041304E /* toolbar_icon_disconnect.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = toolbar_icon_disconnect.png; path = Resources/toolbar_icon_disconnect.png; sourceTree = SOURCE_ROOT; }; - C495EF1616B911450041304E /* toolbar_icon_extkeyboad.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = toolbar_icon_extkeyboad.png; path = Resources/toolbar_icon_extkeyboad.png; sourceTree = SOURCE_ROOT; }; - C495EF1716B911450041304E /* toolbar_icon_home.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = toolbar_icon_home.png; path = Resources/toolbar_icon_home.png; sourceTree = SOURCE_ROOT; }; - C495EF1816B911450041304E /* toolbar_icon_keyboard.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = toolbar_icon_keyboard.png; path = Resources/toolbar_icon_keyboard.png; sourceTree = SOURCE_ROOT; }; - C495EF1916B911450041304E /* toolbar_icon_touchpointer.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = toolbar_icon_touchpointer.png; path = Resources/toolbar_icon_touchpointer.png; sourceTree = SOURCE_ROOT; }; - C495EF1A16B911450041304E /* toolbar_icon_win.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = toolbar_icon_win.png; path = Resources/toolbar_icon_win.png; sourceTree = SOURCE_ROOT; }; - C495EF1B16B911450041304E /* touch_pointer_active.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = touch_pointer_active.png; path = Resources/touch_pointer_active.png; sourceTree = SOURCE_ROOT; }; - C495EF1C16B911450041304E /* touch_pointer_default.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = touch_pointer_default.png; path = Resources/touch_pointer_default.png; sourceTree = SOURCE_ROOT; }; - C495EF1D16B911450041304E /* touch_pointer_extkeyboard.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = touch_pointer_extkeyboard.png; path = Resources/touch_pointer_extkeyboard.png; sourceTree = SOURCE_ROOT; }; - C495EF1E16B911450041304E /* touch_pointer_keyboard.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = touch_pointer_keyboard.png; path = Resources/touch_pointer_keyboard.png; sourceTree = SOURCE_ROOT; }; - C495EF1F16B911450041304E /* touch_pointer_lclick.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = touch_pointer_lclick.png; path = Resources/touch_pointer_lclick.png; sourceTree = SOURCE_ROOT; }; - C495EF2016B911450041304E /* touch_pointer_rclick.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = touch_pointer_rclick.png; path = Resources/touch_pointer_rclick.png; sourceTree = SOURCE_ROOT; }; - C495EF2116B911450041304E /* touch_pointer_reset.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = touch_pointer_reset.png; path = Resources/touch_pointer_reset.png; sourceTree = SOURCE_ROOT; }; - C495EF2216B911450041304E /* touch_pointer_scroll.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = touch_pointer_scroll.png; path = Resources/touch_pointer_scroll.png; sourceTree = SOURCE_ROOT; }; - C495EF2316B911450041304E /* VerifyCertificateView.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = VerifyCertificateView.xib; path = Resources/VerifyCertificateView.xib; sourceTree = SOURCE_ROOT; }; - C495EF8216B911AB0041304E /* AdvancedKeyboardView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AdvancedKeyboardView.h; path = Views/AdvancedKeyboardView.h; sourceTree = SOURCE_ROOT; }; - C495EF8316B911AB0041304E /* AdvancedKeyboardView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = AdvancedKeyboardView.m; path = Views/AdvancedKeyboardView.m; sourceTree = SOURCE_ROOT; }; - C495EF8416B911AB0041304E /* BookmarkTableCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = BookmarkTableCell.h; path = Views/BookmarkTableCell.h; sourceTree = SOURCE_ROOT; }; - C495EF8516B911AB0041304E /* BookmarkTableCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = BookmarkTableCell.m; path = Views/BookmarkTableCell.m; sourceTree = SOURCE_ROOT; }; - C495EF8616B911AB0041304E /* EditButtonTableViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = EditButtonTableViewCell.h; path = Views/EditButtonTableViewCell.h; sourceTree = SOURCE_ROOT; }; - C495EF8716B911AB0041304E /* EditButtonTableViewCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = EditButtonTableViewCell.m; path = Views/EditButtonTableViewCell.m; sourceTree = SOURCE_ROOT; }; - C495EF8816B911AB0041304E /* EditFlagTableViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = EditFlagTableViewCell.h; path = Views/EditFlagTableViewCell.h; sourceTree = SOURCE_ROOT; }; - C495EF8916B911AB0041304E /* EditFlagTableViewCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = EditFlagTableViewCell.m; path = Views/EditFlagTableViewCell.m; sourceTree = SOURCE_ROOT; }; - C495EF8A16B911AB0041304E /* EditSecretTextTableViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = EditSecretTextTableViewCell.h; path = Views/EditSecretTextTableViewCell.h; sourceTree = SOURCE_ROOT; }; - C495EF8B16B911AB0041304E /* EditSecretTextTableViewCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = EditSecretTextTableViewCell.m; path = Views/EditSecretTextTableViewCell.m; sourceTree = SOURCE_ROOT; }; - C495EF8C16B911AB0041304E /* EditSelectionTableViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = EditSelectionTableViewCell.h; path = Views/EditSelectionTableViewCell.h; sourceTree = SOURCE_ROOT; }; - C495EF8D16B911AB0041304E /* EditSelectionTableViewCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = EditSelectionTableViewCell.m; path = Views/EditSelectionTableViewCell.m; sourceTree = SOURCE_ROOT; }; - C495EF8E16B911AB0041304E /* EditSubEditTableViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = EditSubEditTableViewCell.h; path = Views/EditSubEditTableViewCell.h; sourceTree = SOURCE_ROOT; }; - C495EF8F16B911AB0041304E /* EditSubEditTableViewCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = EditSubEditTableViewCell.m; path = Views/EditSubEditTableViewCell.m; sourceTree = SOURCE_ROOT; }; - C495EF9016B911AB0041304E /* EditTextTableViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = EditTextTableViewCell.h; path = Views/EditTextTableViewCell.h; sourceTree = SOURCE_ROOT; }; - C495EF9116B911AB0041304E /* EditTextTableViewCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = EditTextTableViewCell.m; path = Views/EditTextTableViewCell.m; sourceTree = SOURCE_ROOT; }; - C495EF9216B911AB0041304E /* RDPSessionView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RDPSessionView.h; path = Views/RDPSessionView.h; sourceTree = SOURCE_ROOT; }; - C495EF9316B911AB0041304E /* RDPSessionView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = RDPSessionView.m; path = Views/RDPSessionView.m; sourceTree = SOURCE_ROOT; }; - C495EF9416B911AB0041304E /* SessionTableCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SessionTableCell.h; path = Views/SessionTableCell.h; sourceTree = SOURCE_ROOT; }; - C495EF9516B911AB0041304E /* SessionTableCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SessionTableCell.m; path = Views/SessionTableCell.m; sourceTree = SOURCE_ROOT; }; - C495EF9616B911AB0041304E /* TouchPointerView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = TouchPointerView.h; path = Views/TouchPointerView.h; sourceTree = SOURCE_ROOT; }; - C495EF9716B911AB0041304E /* TouchPointerView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = TouchPointerView.m; path = Views/TouchPointerView.m; sourceTree = SOURCE_ROOT; }; - C495EFAA16B912C40041304E /* libfreerdp.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libfreerdp.a; path = ../../libfreerdp/libfreerdp.a; sourceTree = "<group>"; }; - C495EFAD16B913980041304E /* libwinpr.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libwinpr.a; path = ../../winpr/libwinpr/libwinpr.a; sourceTree = "<group>"; }; - C495EFBA16B92E170041304E /* about_page */ = {isa = PBXFileReference; lastKnownFileType = folder; name = about_page; path = Resources/about_page; sourceTree = SOURCE_ROOT; }; - C495EFBC16B92E270041304E /* help_page */ = {isa = PBXFileReference; lastKnownFileType = folder; name = help_page; path = Resources/help_page; sourceTree = SOURCE_ROOT; }; - C495EFC116B92EA20041304E /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = Resources/en.lproj/Localizable.strings; sourceTree = SOURCE_ROOT; }; - C495EFC816B933220041304E /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = SOURCE_ROOT; }; - C495EFC916B933230041304E /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = SOURCE_ROOT; }; - C495EFCA16B933230041304E /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = SOURCE_ROOT; }; - C495F01516B937F80041304E /* libcrypto.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libcrypto.a; path = @FREERDP_IOS_EXTERNAL_SSL_PATH@/lib/libcrypto.a; sourceTree = "<group>"; }; - C495F01616B937F90041304E /* libssl.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libssl.a; path = @FREERDP_IOS_EXTERNAL_SSL_PATH@/lib/libssl.a; sourceTree = "<group>"; }; - C495F01916B938210041304E /* Security.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Security.framework; path = System/Library/Frameworks/Security.framework; sourceTree = SDKROOT; }; - C495F01D16B938CA0041304E /* SystemConfiguration.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SystemConfiguration.framework; path = System/Library/Frameworks/SystemConfiguration.framework; sourceTree = SDKROOT; }; - C4C31C6E16BAD1890087BB12 /* Default-568h@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "Default-568h@2x.png"; path = "Resources/Default-568h@2x.png"; sourceTree = SOURCE_ROOT; }; -/* End PBXFileReference section */ - -/* Begin PBXFrameworksBuildPhase section */ - C495EE2C16B8372D0041304E /* Frameworks */ = { - isa = PBXFrameworksBuildPhase; - buildActionMask = 2147483647; - files = ( - C495F01716B937F90041304E /* libcrypto.a in Frameworks */, - C495F01816B937F90041304E /* libssl.a in Frameworks */, - C495EFAE16B913980041304E /* libwinpr.a in Frameworks */, - C495EFAB16B912C40041304E /* libfreerdp.a in Frameworks */, - C495EE3416B8372D0041304E /* UIKit.framework in Frameworks */, - C495EE3616B8372D0041304E /* Foundation.framework in Frameworks */, - C495EE3816B8372D0041304E /* CoreGraphics.framework in Frameworks */, - C495F01A16B938210041304E /* Security.framework in Frameworks */, - C495F01E16B938CB0041304E /* SystemConfiguration.framework in Frameworks */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXFrameworksBuildPhase section */ - -/* Begin PBXGroup section */ - C495EE2416B8372D0041304E = { - isa = PBXGroup; - children = ( - C495EE3916B8372D0041304E /* iFreeRDP */, - C495EE3216B8372D0041304E /* Frameworks */, - C495EE3016B8372D0041304E /* Products */, - ); - sourceTree = "<group>"; - }; - C495EE3016B8372D0041304E /* Products */ = { - isa = PBXGroup; - children = ( - C495EE2F16B8372D0041304E /* iFreeRDP.app */, - ); - name = Products; - sourceTree = "<group>"; - }; - C495EE3216B8372D0041304E /* Frameworks */ = { - isa = PBXGroup; - children = ( - C495EFAA16B912C40041304E /* libfreerdp.a */, - C495EFAD16B913980041304E /* libwinpr.a */, - C495F01516B937F80041304E /* libcrypto.a */, - C495F01616B937F90041304E /* libssl.a */, - C495F01D16B938CA0041304E /* SystemConfiguration.framework */, - C495F01916B938210041304E /* Security.framework */, - C495EE3316B8372D0041304E /* UIKit.framework */, - C495EE3516B8372D0041304E /* Foundation.framework */, - C495EE3716B8372D0041304E /* CoreGraphics.framework */, - ); - name = Frameworks; - sourceTree = "<group>"; - }; - C495EE3916B8372D0041304E /* iFreeRDP */ = { - isa = PBXGroup; - children = ( - C495EE3A16B8372D0041304E /* Cocoa and Foundation Additions */, - C495EE7A16B910CB0041304E /* Controllers */, - C495EEAB16B910E90041304E /* FreeRDP */, - C495EEB516B910FA0041304E /* Misc */, - C495EEC016B9111E0041304E /* Models */, - C495EED316B9112E0041304E /* Resources */, - C495EF8116B911940041304E /* Views */, - C495EFC816B933220041304E /* AppDelegate.h */, - C495EFC916B933230041304E /* AppDelegate.m */, - C495EFCA16B933230041304E /* main.m */, - C495EE6F16B9107D0041304E /* Defaults.plist */, - C495EE6D16B910510041304E /* iFreeRDP.plist */, - C495EE4116B8372D0041304E /* iFreeRDP-Prefix.pch */, - ); - path = iFreeRDP; - sourceTree = "<group>"; - }; - C495EE3A16B8372D0041304E /* Cocoa and Foundation Additions */ = { - isa = PBXGroup; - children = ( - C495EE7116B910BC0041304E /* OrderedDictionary.h */, - C495EE7216B910BC0041304E /* OrderedDictionary.m */, - C495EE7316B910BC0041304E /* Toast+UIView.h */, - C495EE7416B910BC0041304E /* Toast+UIView.m */, - C495EE7516B910BC0041304E /* TSXAdditions.h */, - C495EE7616B910BC0041304E /* TSXAdditions.m */, - ); - name = "Cocoa and Foundation Additions"; - sourceTree = "<group>"; - }; - C495EE7A16B910CB0041304E /* Controllers */ = { - isa = PBXGroup; - children = ( - C495EE7B16B910DE0041304E /* AboutController.h */, - C495EE7C16B910DE0041304E /* AboutController.m */, - C495EE7D16B910DE0041304E /* AdvancedBookmarkEditorController.h */, - C495EE7E16B910DE0041304E /* AdvancedBookmarkEditorController.m */, - C495EE7F16B910DE0041304E /* AppSettingsController.h */, - C495EE8016B910DE0041304E /* AppSettingsController.m */, - C495EE8116B910DE0041304E /* BookmarkEditorController.h */, - C495EE8216B910DE0041304E /* BookmarkEditorController.m */, - C495EE8316B910DE0041304E /* BookmarkListController.h */, - C495EE8416B910DE0041304E /* BookmarkListController.m */, - C495EE8516B910DE0041304E /* CredentialsEditorController.h */, - C495EE8616B910DE0041304E /* CredentialsEditorController.m */, - C495EE8716B910DE0041304E /* CredentialsInputController.h */, - C495EE8816B910DE0041304E /* CredentialsInputController.m */, - C495EE8916B910DE0041304E /* EditorBaseController.h */, - C495EE8A16B910DE0041304E /* EditorBaseController.m */, - C495EE8B16B910DE0041304E /* EditorSelectionController.h */, - C495EE8C16B910DE0041304E /* EditorSelectionController.m */, - C495EE8D16B910DE0041304E /* EncryptionController.h */, - C495EE8E16B910DE0041304E /* EncryptionController.m */, - C495EE8F16B910DE0041304E /* HelpController.h */, - C495EE9016B910DE0041304E /* HelpController.m */, - C495EE9116B910DE0041304E /* MainTabBarController.h */, - C495EE9216B910DE0041304E /* MainTabBarController.m */, - C495EE9316B910DE0041304E /* PerformanceEditorController.h */, - C495EE9416B910DE0041304E /* PerformanceEditorController.m */, - C495EE9516B910DE0041304E /* RDPSessionViewController.h */, - C495EE9616B910DE0041304E /* RDPSessionViewController.m */, - C495EE9716B910DE0041304E /* ScreenSelectionController.h */, - C495EE9816B910DE0041304E /* ScreenSelectionController.m */, - C495EE9916B910DE0041304E /* VerifyCertificateController.h */, - C495EE9A16B910DE0041304E /* VerifyCertificateController.m */, - ); - name = Controllers; - sourceTree = "<group>"; - }; - C495EEAB16B910E90041304E /* FreeRDP */ = { - isa = PBXGroup; - children = ( - C495EEAC16B910F60041304E /* ios_freerdp_events.h */, - C495EEAD16B910F60041304E /* ios_freerdp_events.m */, - C495EEAE16B910F60041304E /* ios_freerdp_ui.h */, - C495EEAF16B910F60041304E /* ios_freerdp_ui.m */, - C495EEB016B910F60041304E /* ios_freerdp.h */, - C495EEB116B910F60041304E /* ios_freerdp.m */, - ); - name = FreeRDP; - sourceTree = "<group>"; - }; - C495EEB516B910FA0041304E /* Misc */ = { - isa = PBXGroup; - children = ( - C495EEB616B9111A0041304E /* Reachability.h */, - C495EEB716B9111A0041304E /* Reachability.m */, - C495EEB816B9111A0041304E /* SFHFKeychainUtils.h */, - C495EEB916B9111A0041304E /* SFHFKeychainUtils.m */, - C495EEBA16B9111A0041304E /* TSXTypes.h */, - C495EEBB16B9111A0041304E /* Utils.h */, - C495EEBC16B9111A0041304E /* Utils.m */, - ); - name = Misc; - sourceTree = "<group>"; - }; - C495EEC016B9111E0041304E /* Models */ = { - isa = PBXGroup; - children = ( - C495EEC116B911290041304E /* Bookmark.h */, - C495EEC216B911290041304E /* Bookmark.m */, - C495EEC316B911290041304E /* ConnectionParams.h */, - C495EEC416B911290041304E /* ConnectionParams.m */, - C495EEC516B911290041304E /* Encryptor.h */, - C495EEC616B911290041304E /* Encryptor.m */, - C495EEC716B911290041304E /* GlobalDefaults.h */, - C495EEC816B911290041304E /* GlobalDefaults.m */, - C495EEC916B911290041304E /* RDPKeyboard.h */, - C495EECA16B911290041304E /* RDPKeyboard.m */, - C495EECB16B911290041304E /* RDPSession.h */, - C495EECC16B911290041304E /* RDPSession.m */, - ); - name = Models; - sourceTree = "<group>"; - }; - C495EED316B9112E0041304E /* Resources */ = { - isa = PBXGroup; - children = ( - C4C31C6E16BAD1890087BB12 /* Default-568h@2x.png */, - C495EFC016B92EA20041304E /* Localizable.strings */, - C495EFBC16B92E270041304E /* help_page */, - C495EFBA16B92E170041304E /* about_page */, - C495EEDC16B911450041304E /* cancel_button_background.png */, - C495EEDE16B911450041304E /* Default-Landscape@2x~ipad.png */, - C495EEDF16B911450041304E /* Default-Landscape~ipad.png */, - C495EEE016B911450041304E /* Default-Portrait@2x~ipad.png */, - C495EEE116B911450041304E /* Default-Portrait~ipad.png */, - C495EEE216B911450041304E /* Default.png */, - C495EEE316B911450041304E /* Default@2x.png */, - C495EEFE16B911450041304E /* icon_accessory_star_off.png */, - C495EEFF16B911450041304E /* icon_accessory_star_on.png */, - C495EF0016B911450041304E /* icon_key_arrow_down.png */, - C495EF0116B911450041304E /* icon_key_arrow_left.png */, - C495EF0216B911450041304E /* icon_key_arrow_right.png */, - C495EF0316B911450041304E /* icon_key_arrow_up.png */, - C495EF0416B911450041304E /* icon_key_arrows.png */, - C495EF0516B911450041304E /* icon_key_backspace.png */, - C495EF0616B911450041304E /* icon_key_menu.png */, - C495EF0716B911450041304E /* icon_key_return.png */, - C495EF0816B911450041304E /* icon_key_win.png */, - C495EF0916B911450041304E /* Icon-72.png */, - C495EF0A16B911450041304E /* Icon-72@2x.png */, - C495EF0B16B911450041304E /* Icon.png */, - C495EF0C16B911450041304E /* Icon@2x.png */, - C495EF0D16B911450041304E /* keyboard_button_background.png */, - C495EF1216B911450041304E /* tabbar_icon_about.png */, - C495EF1316B911450041304E /* tabbar_icon_help.png */, - C495EF1416B911450041304E /* tabbar_icon_settings.png */, - C495EF1516B911450041304E /* toolbar_icon_disconnect.png */, - C495EF1616B911450041304E /* toolbar_icon_extkeyboad.png */, - C495EF1716B911450041304E /* toolbar_icon_home.png */, - C495EF1816B911450041304E /* toolbar_icon_keyboard.png */, - C495EF1916B911450041304E /* toolbar_icon_touchpointer.png */, - C495EF1A16B911450041304E /* toolbar_icon_win.png */, - C495EF1B16B911450041304E /* touch_pointer_active.png */, - C495EF1C16B911450041304E /* touch_pointer_default.png */, - C495EF1D16B911450041304E /* touch_pointer_extkeyboard.png */, - C495EF1E16B911450041304E /* touch_pointer_keyboard.png */, - C495EF1F16B911450041304E /* touch_pointer_lclick.png */, - C495EF2016B911450041304E /* touch_pointer_rclick.png */, - C495EF2116B911450041304E /* touch_pointer_reset.png */, - C495EF2216B911450041304E /* touch_pointer_scroll.png */, - ); - name = Resources; - sourceTree = "<group>"; - }; - C495EF8116B911940041304E /* Views */ = { - isa = PBXGroup; - children = ( - C495EEDA16B911450041304E /* BookmarkListView.xib */, - C495EEDB16B911450041304E /* BookmarkTableViewCell.xib */, - C495EEDD16B911450041304E /* CredentialsInputView.xib */, - C495EEE416B911450041304E /* EditButtonTableViewCell.xib */, - C495EEE516B911450041304E /* EditFlagTableViewCell.xib */, - C495EEE616B911450041304E /* EditSecretTextTableViewCell.xib */, - C495EEE716B911450041304E /* EditSelectionTableViewCell.xib */, - C495EEE816B911450041304E /* EditSubEditTableViewCell.xib */, - C495EEE916B911450041304E /* EditTextTableViewCell.xib */, - C495EF0E16B911450041304E /* MainWindow.xib */, - C495EF0F16B911450041304E /* RDPConnectingView.xib */, - C495EF1016B911450041304E /* RDPSessionView.xib */, - C495EF1116B911450041304E /* SessionTableViewCell.xib */, - C495EF2316B911450041304E /* VerifyCertificateView.xib */, - C495EF8216B911AB0041304E /* AdvancedKeyboardView.h */, - C495EF8316B911AB0041304E /* AdvancedKeyboardView.m */, - C495EF8416B911AB0041304E /* BookmarkTableCell.h */, - C495EF8516B911AB0041304E /* BookmarkTableCell.m */, - C495EF8616B911AB0041304E /* EditButtonTableViewCell.h */, - C495EF8716B911AB0041304E /* EditButtonTableViewCell.m */, - C495EF8816B911AB0041304E /* EditFlagTableViewCell.h */, - C495EF8916B911AB0041304E /* EditFlagTableViewCell.m */, - C495EF8A16B911AB0041304E /* EditSecretTextTableViewCell.h */, - C495EF8B16B911AB0041304E /* EditSecretTextTableViewCell.m */, - C495EF8C16B911AB0041304E /* EditSelectionTableViewCell.h */, - C495EF8D16B911AB0041304E /* EditSelectionTableViewCell.m */, - C495EF8E16B911AB0041304E /* EditSubEditTableViewCell.h */, - C495EF8F16B911AB0041304E /* EditSubEditTableViewCell.m */, - C495EF9016B911AB0041304E /* EditTextTableViewCell.h */, - C495EF9116B911AB0041304E /* EditTextTableViewCell.m */, - C495EF9216B911AB0041304E /* RDPSessionView.h */, - C495EF9316B911AB0041304E /* RDPSessionView.m */, - C495EF9416B911AB0041304E /* SessionTableCell.h */, - C495EF9516B911AB0041304E /* SessionTableCell.m */, - C495EF9616B911AB0041304E /* TouchPointerView.h */, - C495EF9716B911AB0041304E /* TouchPointerView.m */, - ); - name = Views; - sourceTree = "<group>"; - }; -/* End PBXGroup section */ - -/* Begin PBXNativeTarget section */ - C495EE2E16B8372D0041304E /* iFreeRDP */ = { - isa = PBXNativeTarget; - buildConfigurationList = C495EE6216B8372D0041304E /* Build configuration list for PBXNativeTarget "iFreeRDP" */; - buildPhases = ( - C495EE2B16B8372D0041304E /* Sources */, - C495EE2C16B8372D0041304E /* Frameworks */, - C495EE2D16B8372D0041304E /* Resources */, - ); - buildRules = ( - ); - dependencies = ( - ); - name = iFreeRDP; - productName = iFreeRDP; - productReference = C495EE2F16B8372D0041304E /* iFreeRDP.app */; - productType = "com.apple.product-type.application"; - }; -/* End PBXNativeTarget section */ - -/* Begin PBXProject section */ - C495EE2616B8372D0041304E /* Project object */ = { - isa = PBXProject; - attributes = { - LastUpgradeCheck = 0450; - ORGANIZATIONNAME = freerdp; - }; - buildConfigurationList = C495EE2916B8372D0041304E /* Build configuration list for PBXProject "iFreeRDP" */; - compatibilityVersion = "Xcode 3.2"; - developmentRegion = English; - hasScannedForEncodings = 0; - knownRegions = ( - en, - ); - mainGroup = C495EE2416B8372D0041304E; - productRefGroup = C495EE3016B8372D0041304E /* Products */; - projectDirPath = ""; - projectRoot = ""; - targets = ( - C495EE2E16B8372D0041304E /* iFreeRDP */, - ); - }; -/* End PBXProject section */ - -/* Begin PBXResourcesBuildPhase section */ - C495EE2D16B8372D0041304E /* Resources */ = { - isa = PBXResourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - C495EE7016B9107D0041304E /* Defaults.plist in Resources */, - C495EF3216B911450041304E /* BookmarkListView.xib in Resources */, - C495EF3316B911450041304E /* BookmarkTableViewCell.xib in Resources */, - C495EF3416B911450041304E /* cancel_button_background.png in Resources */, - C495EF3516B911450041304E /* CredentialsInputView.xib in Resources */, - C495EF3616B911450041304E /* Default-Landscape@2x~ipad.png in Resources */, - C495EF3716B911450041304E /* Default-Landscape~ipad.png in Resources */, - C495EF3816B911450041304E /* Default-Portrait@2x~ipad.png in Resources */, - C495EF3916B911450041304E /* Default-Portrait~ipad.png in Resources */, - C495EF3A16B911450041304E /* Default.png in Resources */, - C495EF3B16B911450041304E /* Default@2x.png in Resources */, - C495EF3C16B911450041304E /* EditButtonTableViewCell.xib in Resources */, - C495EF3D16B911450041304E /* EditFlagTableViewCell.xib in Resources */, - C495EF3E16B911450041304E /* EditSecretTextTableViewCell.xib in Resources */, - C495EF3F16B911450041304E /* EditSelectionTableViewCell.xib in Resources */, - C495EF4016B911450041304E /* EditSubEditTableViewCell.xib in Resources */, - C495EF4116B911450041304E /* EditTextTableViewCell.xib in Resources */, - C495EF5316B911450041304E /* icon_accessory_star_off.png in Resources */, - C495EF5416B911450041304E /* icon_accessory_star_on.png in Resources */, - C495EF5516B911450041304E /* icon_key_arrow_down.png in Resources */, - C495EF5616B911450041304E /* icon_key_arrow_left.png in Resources */, - C495EF5716B911450041304E /* icon_key_arrow_right.png in Resources */, - C495EF5816B911450041304E /* icon_key_arrow_up.png in Resources */, - C495EF5916B911450041304E /* icon_key_arrows.png in Resources */, - C495EF5A16B911450041304E /* icon_key_backspace.png in Resources */, - C495EF5B16B911450041304E /* icon_key_menu.png in Resources */, - C495EF5C16B911450041304E /* icon_key_return.png in Resources */, - C495EF5D16B911450041304E /* icon_key_win.png in Resources */, - C495EF5E16B911450041304E /* Icon-72.png in Resources */, - C495EF5F16B911450041304E /* Icon-72@2x.png in Resources */, - C495EF6016B911450041304E /* Icon.png in Resources */, - C495EF6116B911450041304E /* Icon@2x.png in Resources */, - C495EF6216B911450041304E /* keyboard_button_background.png in Resources */, - C495EF6316B911450041304E /* MainWindow.xib in Resources */, - C495EF6416B911450041304E /* RDPConnectingView.xib in Resources */, - C495EF6516B911450041304E /* RDPSessionView.xib in Resources */, - C495EF6616B911450041304E /* SessionTableViewCell.xib in Resources */, - C495EF6716B911450041304E /* tabbar_icon_about.png in Resources */, - C495EF6816B911450041304E /* tabbar_icon_help.png in Resources */, - C495EF6916B911450041304E /* tabbar_icon_settings.png in Resources */, - C495EF6A16B911450041304E /* toolbar_icon_disconnect.png in Resources */, - C495EF6B16B911450041304E /* toolbar_icon_extkeyboad.png in Resources */, - C495EF6C16B911450041304E /* toolbar_icon_home.png in Resources */, - C495EF6D16B911450041304E /* toolbar_icon_keyboard.png in Resources */, - C495EF6E16B911450041304E /* toolbar_icon_touchpointer.png in Resources */, - C495EF6F16B911450041304E /* toolbar_icon_win.png in Resources */, - C495EF7016B911450041304E /* touch_pointer_active.png in Resources */, - C495EF7116B911450041304E /* touch_pointer_default.png in Resources */, - C495EF7216B911450041304E /* touch_pointer_extkeyboard.png in Resources */, - C495EF7316B911450041304E /* touch_pointer_keyboard.png in Resources */, - C495EF7416B911450041304E /* touch_pointer_lclick.png in Resources */, - C495EF7516B911450041304E /* touch_pointer_rclick.png in Resources */, - C495EF7616B911450041304E /* touch_pointer_reset.png in Resources */, - C495EF7716B911450041304E /* touch_pointer_scroll.png in Resources */, - C495EF7816B911450041304E /* VerifyCertificateView.xib in Resources */, - C495EFBB16B92E170041304E /* about_page in Resources */, - C495EFBD16B92E270041304E /* help_page in Resources */, - C495EFC216B92EA20041304E /* Localizable.strings in Resources */, - C4C31C6F16BAD1890087BB12 /* Default-568h@2x.png in Resources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXResourcesBuildPhase section */ - -/* Begin PBXSourcesBuildPhase section */ - C495EE2B16B8372D0041304E /* Sources */ = { - isa = PBXSourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - C495EE7716B910BC0041304E /* OrderedDictionary.m in Sources */, - C495EE7816B910BC0041304E /* Toast+UIView.m in Sources */, - C495EE7916B910BC0041304E /* TSXAdditions.m in Sources */, - C495EE9B16B910DE0041304E /* AboutController.m in Sources */, - C495EE9C16B910DE0041304E /* AdvancedBookmarkEditorController.m in Sources */, - C495EE9D16B910DE0041304E /* AppSettingsController.m in Sources */, - C495EE9E16B910DE0041304E /* BookmarkEditorController.m in Sources */, - C495EE9F16B910DE0041304E /* BookmarkListController.m in Sources */, - C495EEA016B910DE0041304E /* CredentialsEditorController.m in Sources */, - C495EEA116B910DE0041304E /* CredentialsInputController.m in Sources */, - C495EEA216B910DE0041304E /* EditorBaseController.m in Sources */, - C495EEA316B910DE0041304E /* EditorSelectionController.m in Sources */, - C495EEA416B910DE0041304E /* EncryptionController.m in Sources */, - C495EEA516B910DE0041304E /* HelpController.m in Sources */, - C495EEA616B910DE0041304E /* MainTabBarController.m in Sources */, - C495EEA716B910DE0041304E /* PerformanceEditorController.m in Sources */, - C495EEA816B910DE0041304E /* RDPSessionViewController.m in Sources */, - C495EEA916B910DE0041304E /* ScreenSelectionController.m in Sources */, - C495EEAA16B910DE0041304E /* VerifyCertificateController.m in Sources */, - C495EEB216B910F60041304E /* ios_freerdp_events.m in Sources */, - C495EEB316B910F60041304E /* ios_freerdp_ui.m in Sources */, - C495EEB416B910F60041304E /* ios_freerdp.m in Sources */, - C495EEBD16B9111A0041304E /* Reachability.m in Sources */, - C495EEBE16B9111A0041304E /* SFHFKeychainUtils.m in Sources */, - C495EEBF16B9111A0041304E /* Utils.m in Sources */, - C495EECD16B911290041304E /* Bookmark.m in Sources */, - C495EECE16B911290041304E /* ConnectionParams.m in Sources */, - C495EECF16B911290041304E /* Encryptor.m in Sources */, - C495EED016B911290041304E /* GlobalDefaults.m in Sources */, - C495EED116B911290041304E /* RDPKeyboard.m in Sources */, - C495EED216B911290041304E /* RDPSession.m in Sources */, - C495EF9A16B911AC0041304E /* AdvancedKeyboardView.m in Sources */, - C495EF9B16B911AC0041304E /* BookmarkTableCell.m in Sources */, - C495EF9C16B911AC0041304E /* EditButtonTableViewCell.m in Sources */, - C495EF9D16B911AC0041304E /* EditFlagTableViewCell.m in Sources */, - C495EF9E16B911AC0041304E /* EditSecretTextTableViewCell.m in Sources */, - C495EF9F16B911AC0041304E /* EditSelectionTableViewCell.m in Sources */, - C495EFA016B911AC0041304E /* EditSubEditTableViewCell.m in Sources */, - C495EFA116B911AC0041304E /* EditTextTableViewCell.m in Sources */, - C495EFA216B911AC0041304E /* RDPSessionView.m in Sources */, - C495EFA316B911AC0041304E /* SessionTableCell.m in Sources */, - C495EFA416B911AC0041304E /* TouchPointerView.m in Sources */, - C495EFCB16B933230041304E /* AppDelegate.m in Sources */, - C495EFCC16B933230041304E /* main.m in Sources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXSourcesBuildPhase section */ - -/* Begin PBXVariantGroup section */ - C495EFC016B92EA20041304E /* Localizable.strings */ = { - isa = PBXVariantGroup; - children = ( - C495EFC116B92EA20041304E /* en */, - ); - name = Localizable.strings; - sourceTree = "<group>"; - }; -/* End PBXVariantGroup section */ - -/* Begin XCBuildConfiguration section */ - C495EE6016B8372D0041304E /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; - CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; - CLANG_CXX_LIBRARY = "libc++"; - CLANG_ENABLE_OBJC_ARC = NO; - CLANG_WARN_EMPTY_BODY = YES; - CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - CODE_SIGN_IDENTITY = "iPhone Developer"; - "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; - COPY_PHASE_STRIP = NO; - GCC_C_LANGUAGE_STANDARD = gnu99; - GCC_DYNAMIC_NO_PIC = NO; - GCC_OPTIMIZATION_LEVEL = 0; - GCC_PREPROCESSOR_DEFINITIONS = ( - "DEBUG=1", - ); - GCC_SYMBOLS_PRIVATE_EXTERN = NO; - GCC_WARN_ABOUT_RETURN_TYPE = YES; - GCC_WARN_UNINITIALIZED_AUTOS = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 4.3; - ONLY_ACTIVE_ARCH = YES; - PROVISIONING_PROFILE = ""; - SDKROOT = iphoneos; - TARGETED_DEVICE_FAMILY = "1,2"; - }; - name = Debug; - }; - C495EE6116B8372D0041304E /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; - CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; - CLANG_CXX_LIBRARY = "libc++"; - CLANG_ENABLE_OBJC_ARC = NO; - CLANG_WARN_EMPTY_BODY = YES; - CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - CODE_SIGN_IDENTITY = "iPhone Developer"; - "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; - COPY_PHASE_STRIP = YES; - GCC_C_LANGUAGE_STANDARD = gnu99; - GCC_WARN_ABOUT_RETURN_TYPE = YES; - GCC_WARN_UNINITIALIZED_AUTOS = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 4.3; - OTHER_CFLAGS = "-DNS_BLOCK_ASSERTIONS=1"; - PROVISIONING_PROFILE = ""; - SDKROOT = iphoneos; - TARGETED_DEVICE_FAMILY = "1,2"; - VALIDATE_PRODUCT = YES; - }; - name = Release; - }; - C495EE6316B8372D0041304E /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - CLANG_ENABLE_OBJC_ARC = "$(INHERIT)"; - DEAD_CODE_STRIPPING = "$(INHERIT)"; - GCC_PRECOMPILE_PREFIX_HEADER = YES; - GCC_PREFIX_HEADER = "$(SRCROOT)/iFreeRDP-Prefix.pch"; - HEADER_SEARCH_PATHS = ( - "\"$(SRCROOT)/../../include\"", - "\"$(SRCROOT)/../../winpr/include\"", - "\"$(SRCROOT)/../../\"", - "\"@FREERDP_IOS_EXTERNAL_SSL_PATH@/include\"", - ); - INFOPLIST_FILE = "$(SRCROOT)/iFreeRDP.plist"; - IPHONEOS_DEPLOYMENT_TARGET = 4.3; - LIBRARY_SEARCH_PATHS = ( - "\"$(SRCROOT)/../../libfreerdp\"", - "\"$(SRCROOT)/../../winpr/libwinpr\"", - "\"@FREERDP_IOS_EXTERNAL_SSL_PATH@/lib\"", - "\"$(SRCROOT)/../common\"", - ); - PRODUCT_NAME = "$(TARGET_NAME)"; - WRAPPER_EXTENSION = app; - }; - name = Debug; - }; - C495EE6416B8372D0041304E /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - CLANG_ENABLE_OBJC_ARC = "$(INHERIT)"; - DEAD_CODE_STRIPPING = "$(INHERIT)"; - GCC_PRECOMPILE_PREFIX_HEADER = YES; - GCC_PREFIX_HEADER = "$(SRCROOT)/iFreeRDP-Prefix.pch"; - HEADER_SEARCH_PATHS = ( - "\"$(SRCROOT)/../../include\"", - "\"$(SRCROOT)/../../winpr/include\"", - "\"$(SRCROOT)/../../\"", - "\"@FREERDP_IOS_EXTERNAL_SSL_PATH@/include\"", - ); - INFOPLIST_FILE = "$(SRCROOT)/iFreeRDP.plist"; - IPHONEOS_DEPLOYMENT_TARGET = 4.3; - LIBRARY_SEARCH_PATHS = ( - "\"$(SRCROOT)/../../libfreerdp\"", - "\"$(SRCROOT)/../../winpr/libwinpr\"", - "\"@FREERDP_IOS_EXTERNAL_SSL_PATH@/lib\"", - "\"$(SRCROOT)/../common\"", - ); - PRODUCT_NAME = "$(TARGET_NAME)"; - WRAPPER_EXTENSION = app; - }; - name = Release; - }; -/* End XCBuildConfiguration section */ - -/* Begin XCConfigurationList section */ - C495EE2916B8372D0041304E /* Build configuration list for PBXProject "iFreeRDP" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - C495EE6016B8372D0041304E /* Debug */, - C495EE6116B8372D0041304E /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; - C495EE6216B8372D0041304E /* Build configuration list for PBXNativeTarget "iFreeRDP" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - C495EE6316B8372D0041304E /* Debug */, - C495EE6416B8372D0041304E /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; -/* End XCConfigurationList section */ - }; - rootObject = C495EE2616B8372D0041304E /* Project object */; -} diff --git a/cmake/AndroidToolchain.cmake b/cmake/AndroidToolchain.cmake index 30b9e2507..9216bf55d 100644 --- a/cmake/AndroidToolchain.cmake +++ b/cmake/AndroidToolchain.cmake @@ -303,10 +303,16 @@ set( CMAKE_SYSTEM_NAME Linux ) # this one not so much set( CMAKE_SYSTEM_VERSION 1 ) +# Android SDK + +if (NOT DEFINED ANDROID_SDK) + set(ANDROID_SDK "$ENV{ANDROID_SDK}") +endif() + # rpath makes low sence for Android set( CMAKE_SKIP_RPATH TRUE CACHE BOOL "If set, runtime paths are not added when using shared libraries." ) -set( ANDROID_SUPPORTED_NDK_VERSIONS ${ANDROID_EXTRA_NDK_VERSIONS} -r8d -r8c -r8b -r8 -r7c -r7b -r7 -r6b -r6 -r5c -r5b -r5 "" ) +set( ANDROID_SUPPORTED_NDK_VERSIONS ${ANDROID_EXTRA_NDK_VERSIONS} -r8e -r8d -r8c -r8b -r8 -r7c -r7b -r7 -r6b -r6 -r5c -r5b -r5 "" ) if(NOT DEFINED ANDROID_NDK_SEARCH_PATHS) if( CMAKE_HOST_WIN32 ) file( TO_CMAKE_PATH "$ENV{PROGRAMFILES}" ANDROID_NDK_SEARCH_PATHS ) @@ -510,7 +516,19 @@ if( ANDROID_NDK ) endif() set( ANDROID_NDK "${ANDROID_NDK}" CACHE INTERNAL "Path of the Android NDK" FORCE ) set( BUILD_WITH_ANDROID_NDK True ) - file( STRINGS "${ANDROID_NDK}/RELEASE.TXT" ANDROID_NDK_RELEASE LIMIT_COUNT 1 REGEX r[0-9]+[a-z]? ) + file( STRINGS "${ANDROID_NDK}/RELEASE.TXT" ANDROID_NDK_RELEASE_TXT LIMIT_COUNT 1 REGEX r[0-9]+[a-z]? ) + + if(${ANDROID_NDK_RELEASE_TXT} MATCHES "^r[0-9]+[a-z] \([^ ]+\)$") + string( REGEX REPLACE "^(r[0-9]+[a-z]) \(([^ ]+)\)$" "\\1" ANDROID_NDK_RELEASE "${ANDROID_NDK_RELEASE_TXT}" ) + string( REGEX REPLACE "^(r[0-9]+[a-z]) \(([^ ]+)\)$" "\\2" ANDROID_NDK_RELEASE_EXTRA "${ANDROID_NDK_RELEASE_TXT}" ) + + set( ANDROID_NDK_64BIT True) + set( ANDROID_NDK_HOST_SYSTEM_NAME "${ANDROID_NDK_HOST_SYSTEM_NAME}_64" ) + + else() + set( ANDROID_NDK_RELEASE "${ANDROID_NDK_RELEASE_TXT}" ) + endif() + elseif( ANDROID_STANDALONE_TOOLCHAIN ) get_filename_component( ANDROID_STANDALONE_TOOLCHAIN "${ANDROID_STANDALONE_TOOLCHAIN}" ABSOLUTE ) # try to detect change @@ -1535,9 +1553,9 @@ endif() # BUILD_ANDROID : always TRUE # BUILD_WITH_ANDROID_NDK : TRUE if NDK is used # BUILD_WITH_STANDALONE_TOOLCHAIN : TRUE if standalone toolchain is used -# ANDROID_NDK_HOST_SYSTEM_NAME : "windows", "linux-x86" or "darwin-x86" depending on host platform +# ANDROID_NDK_HOST_SYSTEM_NAME : "windows", "linux-x86", "linux-x86_64" or "darwin-x86" depending on host platform # ANDROID_NDK_ABI_NAME : "armeabi", "armeabi-v7a", "x86" or "mips" depending on ANDROID_ABI -# ANDROID_NDK_RELEASE : one of r5, r5b, r5c, r6, r6b, r7, r7b, r7c, r8, r8b, r8c, r8d; set only for NDK +# ANDROID_NDK_RELEASE : one of r5, r5b, r5c, r6, r6b, r7, r7b, r7c, r8, r8b, r8c, r8d, r8e; set only for NDK # ANDROID_ARCH_NAME : "arm" or "x86" or "mips" depending on ANDROID_ABI # ANDROID_SYSROOT : path to the compiler sysroot # TOOL_OS_SUFFIX : "" or ".exe" depending on host platform diff --git a/cmake/ConfigOptions.cmake b/cmake/ConfigOptions.cmake index 2c14142e9..07dfdc823 100644 --- a/cmake/ConfigOptions.cmake +++ b/cmake/ConfigOptions.cmake @@ -52,7 +52,7 @@ option(BUILD_TESTING "Build unit tests" OFF) option(WITH_SAMPLE "Build sample code" OFF) if(${CMAKE_VERSION} VERSION_GREATER 2.8.8) - if(ANDROID OR IOS) + if(ANDROID) option(MONOLITHIC_BUILD "Use monolithic build" ON) else() option(MONOLITHIC_BUILD "Use monolithic build" OFF) diff --git a/cmake/ConfigOptionsiOS.cmake b/cmake/ConfigOptionsiOS.cmake index 289057692..c9bd4fd0c 100644 --- a/cmake/ConfigOptionsiOS.cmake +++ b/cmake/ConfigOptionsiOS.cmake @@ -15,8 +15,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -option(IOS_BUILD_OBJC "Automatically build iOS objective-c code - build type depends on CMAKE_BUILD_TYPE" ON) -option(IOS_BUILD_OBJC_DEBUG "Create an iOS debug package" ON) if (NOT FREERDP_IOS_EXTERNAL_SSL_PATH) set(FREERDP_IOS_EXTERNAL_SSL_PATH "${CMAKE_CURRENT_SOURCE_DIR}/external/openssl") endif() diff --git a/cmake/FindGstreamer.cmake b/cmake/FindGstreamer.cmake index 4a290227c..c4451c61a 100644 --- a/cmake/FindGstreamer.cmake +++ b/cmake/FindGstreamer.cmake @@ -1,20 +1,12 @@ - include(FindPkgConfig) pkg_check_modules(PC_GSTREAMER_0_10 gstreamer-0.10) pkg_check_modules(PC_GSTREAMER_PLUGINS_BASE_0_10 gstreamer-plugins-base-0.10) if(PC_GSTREAMER_0_10_FOUND AND PC_GSTREAMER_PLUGINS_BASE_0_10_FOUND) - set(GSTREAMER_FOUND TRUE) -endif() - -include(FindPackageHandleStandardArgs) -FIND_PACKAGE_HANDLE_STANDARD_ARGS(GSTREAMER DEFAULT_MSG GSTREAMER_FOUND) - -if(GSTREAMER_FOUND) set(GSTREAMER_INCLUDE_DIRS ${PC_GSTREAMER_0_10_INCLUDE_DIRS} ${PC_GSTREAMER_PLUGINS_BASE_0_10_INCLUDE_DIRS}) set(GSTREAMER_LIBRARIES ${PC_GSTREAMER_0_10_LIBRARIES} ${PC_GSTREAMER_PLUGINS_BASE_0_10_LIBRARIES}) endif() -mark_as_advanced(GSTREAMER_FOUND GSTREAMER_INCLUDE_DIRS GSTREAMER_LIBRARIES) - +include(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(GSTREAMER DEFAULT_MSG GSTREAMER_LIBRARIES GSTREAMER_INCLUDE_DIRS) diff --git a/cunit/test_bitmap.c b/cunit/test_bitmap.c index e6a860757..f731ec120 100644 --- a/cunit/test_bitmap.c +++ b/cunit/test_bitmap.c @@ -19,7 +19,7 @@ #include <freerdp/freerdp.h> #include <winpr/print.h> -#include <freerdp/utils/stream.h> +#include <winpr/stream.h> #include <freerdp/codec/bitmap.h> #include "test_bitmap.h" diff --git a/cunit/test_cliprdr.c b/cunit/test_cliprdr.c index f4ed13f0f..6b329a8fd 100644 --- a/cunit/test_cliprdr.c +++ b/cunit/test_cliprdr.c @@ -95,7 +95,7 @@ static int test_rdp_channel_data(freerdp* instance, int chan_id, BYTE* data, int static int event_processed; -static void event_process_callback(RDP_EVENT* event) +static void event_process_callback(wMessage* event) { printf("Event %d processed.\n", event->event_type); event_processed = 1; @@ -107,7 +107,7 @@ void test_cliprdr(void) rdpChannels* channels; rdpSettings settings = { 0 }; freerdp instance = { 0 }; - RDP_EVENT* event; + wMessage* event; RDP_CB_FORMAT_LIST_EVENT* format_list_event; RDP_CB_DATA_REQUEST_EVENT* data_request_event; RDP_CB_DATA_RESPONSE_EVENT* data_response_event; diff --git a/cunit/test_freerdp.c b/cunit/test_freerdp.c index dc18a4186..f9a9644a5 100644 --- a/cunit/test_freerdp.c +++ b/cunit/test_freerdp.c @@ -63,13 +63,13 @@ void dump_data(unsigned char * p, int len, int width, char* name) printf("\n"); } -void assert_stream(STREAM* s, BYTE* data, int length, const char* func, int line) +void assert_stream(wStream* s, BYTE* data, int length, const char* func, int line) { int i; int actual_length; BYTE* actual_data; - actual_data = s->data; + actual_data = s->buffer; actual_length = stream_get_length(s); if (actual_length != length) diff --git a/cunit/test_freerdp.h b/cunit/test_freerdp.h index 1d6370e92..4ba11ae9c 100644 --- a/cunit/test_freerdp.h +++ b/cunit/test_freerdp.h @@ -22,8 +22,8 @@ #include <string.h> #include <CUnit/CUnit.h> #include <freerdp/types.h> -#include <freerdp/utils/stream.h> #include <winpr/print.h> +#include <winpr/stream.h> #define add_test_suite(name) \ CU_pSuite pSuite; \ @@ -38,6 +38,6 @@ } void dump_data(unsigned char * p, int len, int width, char* name); -void assert_stream(STREAM* s, BYTE* data, int length, const char* func, int line); +void assert_stream(wStream* s, BYTE* data, int length, const char* func, int line); #define ASSERT_STREAM(_s, _data, _length) assert_stream(_s, _data, _length, __FUNCTION__, __LINE__) diff --git a/cunit/test_gcc.c b/cunit/test_gcc.c index 3fd65a11e..e2f41ec7b 100644 --- a/cunit/test_gcc.c +++ b/cunit/test_gcc.c @@ -21,7 +21,7 @@ #include <freerdp/freerdp.h> #include <winpr/print.h> -#include <freerdp/utils/stream.h> +#include <winpr/stream.h> #include "test_gcc.h" @@ -92,12 +92,12 @@ BYTE gcc_conference_create_request_expected[307] = void test_gcc_write_conference_create_request(void) { - STREAM* s; - STREAM user_data; + wStream* s; + wStream user_data; - user_data.data = gcc_user_data; - user_data.size = sizeof(gcc_user_data); - user_data.p = user_data.data + user_data.size; + user_data.buffer = gcc_user_data; + user_data.capacity = sizeof(gcc_user_data); + user_data.pointer = user_data.buffer + user_data.capacity; s = stream_new(sizeof(gcc_conference_create_request_expected)); @@ -123,7 +123,7 @@ BYTE gcc_client_core_data_expected[216] = void test_gcc_write_client_core_data(void) { - STREAM* s; + wStream* s; rdpSettings* settings; s = stream_new(512); @@ -150,7 +150,7 @@ BYTE gcc_client_security_data_expected[12] = void test_gcc_write_client_security_data(void) { - STREAM* s; + wStream* s; rdpSettings* settings; s = stream_new(12); @@ -173,7 +173,7 @@ BYTE gcc_client_cluster_data_expected[12] = void test_gcc_write_client_cluster_data(void) { - STREAM* s; + wStream* s; rdpSettings* settings; s = stream_new(12); @@ -191,7 +191,7 @@ BYTE gcc_client_network_data_expected[44] = void test_gcc_write_client_network_data(void) { - STREAM* s; + wStream* s; rdpSettings* settings; s = stream_new(44); diff --git a/cunit/test_license.c b/cunit/test_license.c index 36f8aa5fa..e04510a5b 100644 --- a/cunit/test_license.c +++ b/cunit/test_license.c @@ -21,7 +21,7 @@ #include <freerdp/freerdp.h> #include <winpr/print.h> -#include <freerdp/utils/stream.h> +#include <winpr/stream.h> #include "test_license.h" @@ -313,14 +313,14 @@ BYTE platform_challenge[10] = "\x54\x00\x45\x00\x53\x00\x54\x00\x00\x00"; void test_license(void) { - STREAM _s, *s; + wStream _s, *s; s = &_s; memcpy(license->ClientRandom, client_random, sizeof(client_random)); memcpy(license->PremasterSecret, premaster_secret, sizeof(premaster_secret)); - s->data = server_license_request; - s->p = s->data + LICENSE_PREAMBLE_LENGTH; + s->buffer = server_license_request; + s->pointer = s->buffer + LICENSE_PREAMBLE_LENGTH; license_read_license_request_packet(license, s); #if 0 @@ -355,7 +355,7 @@ void test_license(void) printf("\n"); printf("modulus:\n"); - winpr_HexDump(license->certificate->cert_info.modulus.data, + winpr_HexDump(license->certificate->cert_info.modulus.buffer, license->certificate->cert_info.modulus.length); printf("\n"); @@ -364,13 +364,13 @@ void test_license(void) printf("\n"); printf("encrypted premaster secret:\n"); - winpr_HexDump(license->EncryptedPremasterSecret->data, + winpr_HexDump(license->EncryptedPremasterSecret->buffer, license->EncryptedPremasterSecret->length); printf("\n"); #endif - s->data = server_platform_challenge; - s->p = s->data + LICENSE_PREAMBLE_LENGTH; + s->buffer = server_platform_challenge; + s->pointer = s->buffer + LICENSE_PREAMBLE_LENGTH; license_read_platform_challenge_packet(license, s); } @@ -419,7 +419,7 @@ BYTE test_encrypted_premaster_secret[64] = void test_license_generate_keys(void) { - STREAM _s, *s; + wStream _s, *s; s = &_s; memcpy(license->ClientRandom, client_random, sizeof(client_random)); @@ -432,30 +432,30 @@ void test_license_generate_keys(void) license_generate_keys(license); license_encrypt_premaster_secret(license); - s->data = license->MasterSecret; - s->p = s->data + sizeof(test_master_secret); + s->buffer = license->MasterSecret; + s->pointer = s->buffer + sizeof(test_master_secret); ASSERT_STREAM(s, test_master_secret, sizeof(test_master_secret)); - s->data = license->SessionKeyBlob; - s->p = s->data + sizeof(test_session_key_blob); + s->buffer = license->SessionKeyBlob; + s->pointer = s->buffer + sizeof(test_session_key_blob); ASSERT_STREAM(s, test_session_key_blob, sizeof(test_session_key_blob)); - s->data = license->MacSaltKey; - s->p = s->data + sizeof(test_mac_salt_key); + s->buffer = license->MacSaltKey; + s->pointer = s->buffer + sizeof(test_mac_salt_key); ASSERT_STREAM(s, test_mac_salt_key, sizeof(test_mac_salt_key)); - s->data = license->LicensingEncryptionKey; - s->p = s->data + sizeof(test_licensing_encryption_key); + s->buffer = license->LicensingEncryptionKey; + s->pointer = s->buffer + sizeof(test_licensing_encryption_key); ASSERT_STREAM(s, test_licensing_encryption_key, sizeof(test_licensing_encryption_key)); - s->data = license->EncryptedPremasterSecret->data; - s->p = s->data + sizeof(test_encrypted_premaster_secret); + s->buffer = license->EncryptedPremasterSecret->data; + s->pointer = s->buffer + sizeof(test_encrypted_premaster_secret); ASSERT_STREAM(s, test_encrypted_premaster_secret, sizeof(test_encrypted_premaster_secret)); } void test_license_encrypt_premaster_secret(void) { - STREAM _s, *s; + wStream _s, *s; s = &_s; memcpy(license->PremasterSecret, premaster_secret, sizeof(premaster_secret)); @@ -463,8 +463,8 @@ void test_license_encrypt_premaster_secret(void) memcpy(license->certificate->cert_info.Modulus, test_modulus, sizeof(test_modulus)); license->certificate->cert_info.ModulusLength = sizeof(test_modulus); - s->data = license->EncryptedPremasterSecret->data; - s->p = s->data + sizeof(test_encrypted_premaster_secret); + s->buffer = license->EncryptedPremasterSecret->data; + s->pointer = s->buffer + sizeof(test_encrypted_premaster_secret); ASSERT_STREAM(s, test_encrypted_premaster_secret, sizeof(test_encrypted_premaster_secret)); } @@ -476,7 +476,7 @@ BYTE test_platform_challenge[10] = void test_license_decrypt_platform_challenge(void) { - STREAM _s, *s; + wStream _s, *s; s = &_s; memcpy(license->LicensingEncryptionKey, test_licensing_encryption_key, @@ -492,8 +492,8 @@ void test_license_decrypt_platform_challenge(void) license_decrypt_platform_challenge(license); - s->data = license->PlatformChallenge->data; - s->p = s->data + sizeof(test_platform_challenge); + s->buffer = license->PlatformChallenge->data; + s->pointer = s->buffer + sizeof(test_platform_challenge); ASSERT_STREAM(s, test_platform_challenge, sizeof(test_platform_challenge)); } diff --git a/cunit/test_mcs.c b/cunit/test_mcs.c index 2ddb70c47..f9a0e9dba 100644 --- a/cunit/test_mcs.c +++ b/cunit/test_mcs.c @@ -21,7 +21,7 @@ #include <freerdp/freerdp.h> #include <winpr/print.h> -#include <freerdp/utils/stream.h> +#include <winpr/stream.h> #include "test_mcs.h" @@ -96,15 +96,15 @@ BYTE mcs_connect_initial_expected[409] = void test_mcs_write_connect_initial(void) { - STREAM* s; + wStream* s; rdpMcs* mcs; - STREAM _user_data, *user_data; + wStream _user_data, *user_data; mcs = mcs_new((rdpTransport*) NULL); user_data = &_user_data; - user_data->data = gcc_CCrq; - user_data->p = user_data->data + sizeof(gcc_CCrq); + user_data->buffer = gcc_CCrq; + user_data->pointer = user_data->buffer + sizeof(gcc_CCrq); s = stream_new(512); mcs_write_connect_initial(s, mcs, user_data); diff --git a/cunit/test_nsc.c b/cunit/test_nsc.c index f26edf1a9..5376c4a31 100644 --- a/cunit/test_nsc.c +++ b/cunit/test_nsc.c @@ -348,7 +348,7 @@ void test_nsc_encode(void) { int i; BYTE* rgb_data; - STREAM* enc_stream; + wStream* enc_stream; NSC_CONTEXT* context; rgb_data = (BYTE *) malloc(64 * 64 * 3); diff --git a/cunit/test_orders.c b/cunit/test_orders.c index cd35e0413..08d030a65 100644 --- a/cunit/test_orders.c +++ b/cunit/test_orders.c @@ -19,7 +19,7 @@ #include <freerdp/freerdp.h> #include <winpr/print.h> -#include <freerdp/utils/stream.h> +#include <winpr/stream.h> #include "test_orders.h" #include "libfreerdp/core/orders.h" @@ -73,11 +73,11 @@ BYTE dstblt_order[] = "\x48\x00\x37\x01"; void test_read_dstblt_order(void) { - STREAM _s, *s; + wStream _s, *s; DSTBLT_ORDER dstblt; s = &_s; - s->p = s->data = dstblt_order; + s->pointer = s->buffer = dstblt_order; memset(orderInfo, 0, sizeof(ORDER_INFO)); orderInfo->fieldFlags = 0x0C; @@ -98,11 +98,11 @@ BYTE patblt_order[] = "\x1a\x00\xc3\x01\x0d\x00\x0d\x00\xf0\xff\xff\x00\x5b\xef\ void test_read_patblt_order(void) { - STREAM _s, *s; + wStream _s, *s; PATBLT_ORDER patblt; s = &_s; - s->p = s->data = patblt_order; + s->pointer = s->buffer = patblt_order; memset(orderInfo, 0, sizeof(ORDER_INFO)); orderInfo->fieldFlags = 0x027F; @@ -128,11 +128,11 @@ BYTE scrblt_order[] = "\x07\x00\xa1\x01\xf1\x00\xcc\x2f\x01\x8e\x00"; void test_read_scrblt_order(void) { - STREAM _s, *s; + wStream _s, *s; SCRBLT_ORDER scrblt; s = &_s; - s->p = s->data = scrblt_order; + s->pointer = s->buffer = scrblt_order; memset(orderInfo, 0, sizeof(ORDER_INFO)); orderInfo->fieldFlags = 0x7D; @@ -155,11 +155,11 @@ BYTE opaque_rect_order[] = "\x00\x04\x00\x03\x73\x02\x06"; void test_read_opaque_rect_order(void) { - STREAM _s, *s; + wStream _s, *s; OPAQUE_RECT_ORDER opaque_rect; s = &_s; - s->p = s->data = opaque_rect_order; + s->pointer = s->buffer = opaque_rect_order; memset(orderInfo, 0, sizeof(ORDER_INFO)); orderInfo->fieldFlags = 0x7C; @@ -180,11 +180,11 @@ BYTE draw_nine_grid_order[] = "\xfb\xf9\x0d\x00"; void test_read_draw_nine_grid_order(void) { - STREAM _s, *s; + wStream _s, *s; DRAW_NINE_GRID_ORDER draw_nine_grid; s = &_s; - s->p = s->data = draw_nine_grid_order; + s->pointer = s->buffer = draw_nine_grid_order; memset(orderInfo, 0, sizeof(ORDER_INFO)); orderInfo->fieldFlags = 0x1C; @@ -213,11 +213,11 @@ BYTE multi_opaque_rect_order[] = void test_read_multi_opaque_rect_order(void) { - STREAM _s, *s; + wStream _s, *s; MULTI_OPAQUE_RECT_ORDER multi_opaque_rect; s = &_s; - s->p = s->data = multi_opaque_rect_order; + s->pointer = s->buffer = multi_opaque_rect_order; memset(orderInfo, 0, sizeof(ORDER_INFO)); orderInfo->fieldFlags = 0x01BF; @@ -260,11 +260,11 @@ BYTE line_to_order[] = "\x03\xb1\x0e\xa6\x5b\xef\x00"; void test_read_line_to_order(void) { - STREAM _s, *s; + wStream _s, *s; LINE_TO_ORDER line_to; s = &_s; - s->p = s->data = line_to_order; + s->pointer = s->buffer = line_to_order; memset(orderInfo, 0, sizeof(ORDER_INFO)); orderInfo->fieldFlags = 0x021E; @@ -303,11 +303,11 @@ BYTE polyline_order[] = void test_read_polyline_order(void) { - STREAM _s, *s; + wStream _s, *s; POLYLINE_ORDER polyline; s = &_s; - s->p = s->data = polyline_order; + s->pointer = s->buffer = polyline_order; memset(orderInfo, 0, sizeof(ORDER_INFO)); orderInfo->fieldFlags = 0x73; @@ -371,11 +371,11 @@ BYTE glyph_index_order_2[] = void test_read_glyph_index_order(void) { - STREAM _s, *s; + wStream _s, *s; GLYPH_INDEX_ORDER glyph_index; s = &_s; - s->p = s->data = glyph_index_order_1; + s->pointer = s->buffer = glyph_index_order_1; memset(orderInfo, 0, sizeof(ORDER_INFO)); orderInfo->fieldFlags = 0x200100; @@ -389,7 +389,7 @@ void test_read_glyph_index_order(void) CU_ASSERT(stream_get_length(s) == (sizeof(glyph_index_order_1) - 1)); - s->p = s->data = glyph_index_order_2; + s->pointer = s->buffer = glyph_index_order_2; memset(orderInfo, 0, sizeof(ORDER_INFO)); orderInfo->fieldFlags = 0x383FE8; @@ -422,11 +422,11 @@ BYTE fast_index_order[] = void test_read_fast_index_order(void) { - STREAM _s, *s; + wStream _s, *s; FAST_INDEX_ORDER fast_index; s = &_s; - s->p = s->data = fast_index_order; + s->pointer = s->buffer = fast_index_order; memset(orderInfo, 0, sizeof(ORDER_INFO)); orderInfo->fieldFlags = 0x70FF; @@ -460,11 +460,11 @@ BYTE fast_glyph_order[] = void test_read_fast_glyph_order(void) { - STREAM _s, *s; + wStream _s, *s; FAST_GLYPH_ORDER fast_glyph; s = &_s; - s->p = s->data = fast_glyph_order; + s->pointer = s->buffer = fast_glyph_order; memset(orderInfo, 0, sizeof(ORDER_INFO)); orderInfo->fieldFlags = 0x7EFB; @@ -495,11 +495,11 @@ BYTE polygon_cb_order[] = void test_read_polygon_cb_order(void) { - STREAM _s, *s; + wStream _s, *s; POLYGON_CB_ORDER polygon_cb; s = &_s; - s->p = s->data = polygon_cb_order; + s->pointer = s->buffer = polygon_cb_order; memset(orderInfo, 0, sizeof(ORDER_INFO)); orderInfo->fieldFlags = 0x1BEF; @@ -527,13 +527,13 @@ BYTE cache_bitmap_order[] = "\x00\x00\x10\x01\x08\x01\x00\x00\x00\x10"; void test_read_cache_bitmap_order(void) { - STREAM _s, *s; + wStream _s, *s; UINT16 extraFlags; CACHE_BITMAP_ORDER cache_bitmap; s = &_s; extraFlags = 0x0400; - s->p = s->data = cache_bitmap_order; + s->pointer = s->buffer = cache_bitmap_order; memset(&cache_bitmap, 0, sizeof(CACHE_BITMAP_ORDER)); @@ -568,13 +568,13 @@ BYTE cache_bitmap_v2_order[] = void test_read_cache_bitmap_v2_order(void) { - STREAM _s, *s; + wStream _s, *s; UINT16 extraFlags; CACHE_BITMAP_V2_ORDER cache_bitmap_v2; s = &_s; extraFlags = 0x0CA1; - s->p = s->data = cache_bitmap_v2_order; + s->pointer = s->buffer = cache_bitmap_v2_order; memset(&cache_bitmap_v2, 0, sizeof(CACHE_BITMAP_V2_ORDER)); @@ -599,13 +599,13 @@ BYTE cache_bitmap_v3_order[] = void test_read_cache_bitmap_v3_order(void) { - STREAM _s, *s; + wStream _s, *s; UINT16 extraFlags; CACHE_BITMAP_V3_ORDER cache_bitmap_v3; s = &_s; extraFlags = 0x0C30; - s->p = s->data = cache_bitmap_v3_order; + s->pointer = s->buffer = cache_bitmap_v3_order; memset(&cache_bitmap_v3, 0, sizeof(CACHE_BITMAP_V3_ORDER)); @@ -629,11 +629,11 @@ BYTE cache_brush_order[] = "\x00\x01\x08\x08\x81\x08\xaa\x55\xaa\x55\xaa\x55\xaa void test_read_cache_brush_order(void) { - STREAM _s, *s; + wStream _s, *s; CACHE_BRUSH_ORDER cache_brush; s = &_s; - s->p = s->data = cache_brush_order; + s->pointer = s->buffer = cache_brush_order; memset(&cache_brush, 0, sizeof(CACHE_BRUSH_ORDER)); @@ -653,12 +653,12 @@ BYTE create_offscreen_bitmap_order[] = "\x00\x80\x60\x01\x10\x00\x01\x00\x02\x00 void test_read_create_offscreen_bitmap_order(void) { - STREAM _s, *s; + wStream _s, *s; OFFSCREEN_DELETE_LIST* deleteList; CREATE_OFFSCREEN_BITMAP_ORDER create_offscreen_bitmap; s = &_s; - s->p = s->data = create_offscreen_bitmap_order; + s->pointer = s->buffer = create_offscreen_bitmap_order; memset(&create_offscreen_bitmap, 0, sizeof(CREATE_OFFSCREEN_BITMAP_ORDER)); @@ -681,11 +681,11 @@ BYTE switch_surface_order[] = "\xff\xff"; void test_read_switch_surface_order(void) { - STREAM _s, *s; + wStream _s, *s; SWITCH_SURFACE_ORDER switch_surface; s = &_s; - s->p = s->data = switch_surface_order; + s->pointer = s->buffer = switch_surface_order; memset(&switch_surface, 0, sizeof(SWITCH_SURFACE_ORDER)); @@ -733,7 +733,7 @@ void test_patblt(rdpContext* context, PATBLT_ORDER* patblt) void test_update_recv_orders(void) { rdpRdp* rdp; - STREAM _s, *s; + wStream _s, *s; rdpUpdate* update; s = &_s; @@ -751,8 +751,8 @@ void test_update_recv_orders(void) update->primary->Polyline = test_polyline; update->primary->PatBlt = test_patblt; - s->p = s->data = orders_update_1; - s->size = sizeof(orders_update_1); + s->pointer = s->buffer = orders_update_1; + s->capacity = sizeof(orders_update_1); CU_ASSERT(update_recv(update, s)); @@ -760,8 +760,8 @@ void test_update_recv_orders(void) CU_ASSERT(polyline_count == 2); update->primary->order_info.orderType = ORDER_TYPE_PATBLT; - s->p = s->data = orders_update_2; - s->size = sizeof(orders_update_2); + s->pointer = s->buffer = orders_update_2; + s->capacity = sizeof(orders_update_2); CU_ASSERT(update_recv(update, s)); diff --git a/cunit/test_rail.c b/cunit/test_rail.c index a8b113091..601024d5c 100644 --- a/cunit/test_rail.c +++ b/cunit/test_rail.c @@ -426,7 +426,7 @@ typedef struct RAIL_EVENT in_events[20]; size_t in_events_number; - STREAM in_streams[20]; + wStream in_streams[20]; size_t in_streams_number; RDP_PLUGIN_DATA plugin_data; @@ -475,7 +475,7 @@ int stream_equal_dump(void * dataS, size_t sizeS, void * data, size_t size) return 1; } //----------------------------------------------------------------------------- -static void test_on_free_rail_client_event(RDP_EVENT* event) +static void test_on_free_rail_client_event(wMessage* event) { if (event->event_class == RDP_EVENT_CLASS_RAIL) { @@ -489,7 +489,7 @@ static void send_ui_event2plugin( void * data ) { - RDP_EVENT* out_event = NULL; + wMessage* out_event = NULL; void * payload = NULL; payload = rail_clone_order(event_type, data); @@ -522,11 +522,11 @@ static void save_dump(void* data, size_t size) thread_param * p = global_thread_params; if (p->in_streams_number < ARRAYSIZE(p->in_streams)) { - STREAM* s = &p->in_streams[p->in_streams_number]; - s->data = malloc(size); - s->size = size; + wStream* s = &p->in_streams[p->in_streams_number]; + s->buffer = malloc(size); + s->capacity = size; - memcpy(s->data, data, size); + memcpy(s->buffer, data, size); p->in_streams_number++; } } @@ -547,7 +547,7 @@ static int emulate_client_send_channel_data( return 0; } //----------------------------------------------------------------------------- -void save_event(RDP_EVENT* event, RAIL_EVENT* rail_event) +void save_event(wMessage* event, RAIL_EVENT* rail_event) { rail_event->event_type = event->event_type; @@ -610,7 +610,7 @@ void save_event(RDP_EVENT* event, RAIL_EVENT* rail_event) //----------------------------------------------------------------------------- static void process_events_and_channel_data_from_plugin(thread_param* param) { - RDP_EVENT* event; + wMessage* event; param->th_count++; while (param->th_to_finish == 0) @@ -663,7 +663,7 @@ void test_rail_plugin(void) freerdp* inst = &s_inst; size_t sn = 0; size_t en = 0; - STREAM* ss = NULL; + wStream* ss = NULL; RAIL_EVENT* ee = NULL; printf("\n"); diff --git a/cunit/test_rfx.c b/cunit/test_rfx.c index ff8e5c6bf..a69f85447 100644 --- a/cunit/test_rfx.c +++ b/cunit/test_rfx.c @@ -304,7 +304,7 @@ void test_decode(void) { RFX_CONTEXT* context; BYTE decode_buffer[4096 * 3]; - STREAM* s; + wStream* s; s = stream_new(sizeof(y_data) + sizeof(cb_data) + sizeof(cr_data)); stream_write(s, y_data, sizeof(y_data)); @@ -329,7 +329,7 @@ void test_decode(void) void test_encode(void) { RFX_CONTEXT* context; - STREAM* enc_stream; + wStream* enc_stream; int y_size, cb_size, cr_size; int i; BYTE decode_buffer[4096 * 3]; @@ -374,7 +374,7 @@ void test_encode(void) void test_message(void) { RFX_CONTEXT* context; - STREAM* s; + wStream* s; int i, j; RFX_RECT rect = {0, 0, 100, 80}; RFX_MESSAGE * message; @@ -401,7 +401,7 @@ void test_message(void) stream_seal(s); /*hexdump(buffer, size);*/ stream_set_pos(s, 0); - message = rfx_process_message(context, s->p, s->size); + message = rfx_process_message(context, s->pointer, s->capacity); if (i == 0) { for (j = 0; j < message->num_tiles; j++) diff --git a/docs/README.ios b/docs/README.ios index bc4a0c420..38f6a24a7 100644 --- a/docs/README.ios +++ b/docs/README.ios @@ -2,15 +2,7 @@ Overview ======== The FreeRDP iOS port allows users to enjoy FreeRDP features on Apple iOS devices. -The application was written to be compatible with devices running iOS 3.2 or higher. -Please note that Apple dropped armv6 support in their latest Xcode releases. -If you want to compile for armv6 devices you will have to use an older Xcode version and build the OpenSSL libraries for armv6 as well. - -For building the GUI part there are two possibilities: -* integrated build - have cmake to operate Xcode and build everything -* manual build - build FreeRDP libraries and invoke xcodebuild or Xcode manually for the frontend - -Manual builds should be used for development. +The application was written to be compatible with devices running iOS 4.3 or higher. Build requirements @@ -20,7 +12,6 @@ The following prerequisites are required in order to build the iOS port: - cmake version >= 2.8.9 - latest Xcode installed (>= 4.6) -- installed "Command Line Tools" component - installed Provisioning Profile and iOS Developer Certificate for code signing - pre-build static OpenSSL libraries (see below) @@ -43,35 +34,23 @@ If you build OpenSSL youself you need to set FREERDP_IOS_EXTERNAL_SSL_PATH when Building ======== -Integrated build ----------------- - Run the following commands in the top level FreeRDP directory: -cmake -DCMAKE_TOOLCHAIN_FILE=cmake/iOSToolchain.cmake -make +cmake -DCMAKE_TOOLCHAIN_FILE=cmake/iOSToolchain.cmake -GXcode -After that you should have a client/iOS/bin/<Debug or Release>/iFreeRDP.app application package. +This command will create a XCode project in the FreeRDP root folder called FreeRDP.xcodeproj. +Open the project in XCode and modify, build or run the app. -Manual iOS builds ------------------ +Alternatively you can also build the project from the command line using xcodebuild: -First run cmake to prepare the build: - -cmake -DCMAKE_TOOLCHAIN_FILE=cmake/iOSToolchain.cmake -DIOS_BUILD_OBJC=OFF -make - -Now you can run your favourite xcodebuild command in client/iOS like this: - -cd client/iOS -xcodebuild -project iFreeRDP.xcodeproj -configuration Debug -sdk iphoneos6.1 install +xcodebuild -project FreeRDP.xcodeproj -configuration Debug -sdk iphoneos6.1 Notes: * XCode, by default will build the application into its derived data location (usually in ~/Library/Developer/...). If you want to specify an output directory add CONFIGURATION_BUILD_DIR=<output-path-here> to the end of above command line. -* If using XCode choose "Open Other" from the welcome screen, browse to the client/iOS directory in your FreeRDP folder and select iFreeRDP.xcodeproj. +* If using XCode choose "Open Other" from the welcome screen, browse to the FreeRDP root directory and select FreeRDP.xcodeproj. cmake variables @@ -92,8 +71,3 @@ CMAKE_IOS_SDK_ROOT (used by toolchain file) FREERDP_IOS_EXTERNAL_SSL_PATH (used by FindOpenSSL) * absolut root path to the pre-built static OpenSSL libraries -IOS_BUILD_OBJC (used by client/iOS/CMakeLists.txt) -* can be ON/OFF (default ON) whether or not to build the objective-c UI with cmake - -IOS_BUILD_OBJC_DEBUG (used by client/iOS/CMakeLists.txt) -* can be ON/OFF (default ON) whether or not to build a debug version of the objective-c UI diff --git a/freerdp.pc.in b/freerdp.pc.in index da43af7b9..59e2b446c 100644 --- a/freerdp.pc.in +++ b/freerdp.pc.in @@ -8,6 +8,6 @@ Description: A free remote desktop protocol client URL: http://www.freerdp.com/ Version: @FREERDP_VERSION_FULL@ Requires: -Libs: -L${libdir} -lfreerdp-cache -lfreerdp-codec -lfreerdp-core -lfreerdp-crypto -lfreerdp-gdi -lfreerdp-locale -lfreerdp-rail -lfreerdp-utils -lwinpr-sspi -lwinpr-rpc +Libs: -L${libdir} -lfreerdp-cache -lfreerdp-codec -lfreerdp-core -lfreerdp-crypto -lfreerdp-gdi -lfreerdp-locale -lfreerdp-rail -lfreerdp-utils -lwinpr-sspi -lwinpr-rpc -lwinpr-utils Cflags: -I${includedir} diff --git a/include/freerdp/cache/bitmap.h b/include/freerdp/cache/bitmap.h index 6a68b8068..7883b4c51 100644 --- a/include/freerdp/cache/bitmap.h +++ b/include/freerdp/cache/bitmap.h @@ -24,7 +24,8 @@ #include <freerdp/types.h> #include <freerdp/update.h> #include <freerdp/freerdp.h> -#include <freerdp/utils/stream.h> + +#include <winpr/stream.h> typedef struct _BITMAP_V2_CELL BITMAP_V2_CELL; typedef struct rdp_bitmap_cache rdpBitmapCache; diff --git a/include/freerdp/cache/brush.h b/include/freerdp/cache/brush.h index 93d1fd679..3c3131541 100644 --- a/include/freerdp/cache/brush.h +++ b/include/freerdp/cache/brush.h @@ -24,7 +24,8 @@ #include <freerdp/types.h> #include <freerdp/freerdp.h> #include <freerdp/update.h> -#include <freerdp/utils/stream.h> + +#include <winpr/stream.h> typedef struct _BRUSH_ENTRY BRUSH_ENTRY; typedef struct rdp_brush_cache rdpBrushCache; diff --git a/include/freerdp/cache/cache.h b/include/freerdp/cache/cache.h index 7b0dbe4a8..a25812ba5 100644 --- a/include/freerdp/cache/cache.h +++ b/include/freerdp/cache/cache.h @@ -23,7 +23,8 @@ #include <freerdp/api.h> #include <freerdp/types.h> #include <freerdp/update.h> -#include <freerdp/utils/stream.h> + +#include <winpr/stream.h> #include <freerdp/cache/glyph.h> #include <freerdp/cache/brush.h> diff --git a/include/freerdp/cache/glyph.h b/include/freerdp/cache/glyph.h index 4e193987a..35f702598 100644 --- a/include/freerdp/cache/glyph.h +++ b/include/freerdp/cache/glyph.h @@ -23,7 +23,8 @@ #include <freerdp/api.h> #include <freerdp/types.h> #include <freerdp/update.h> -#include <freerdp/utils/stream.h> + +#include <winpr/stream.h> typedef struct _GLYPH_CACHE GLYPH_CACHE; typedef struct _FRAGMENT_CACHE_ENTRY FRAGMENT_CACHE_ENTRY; diff --git a/include/freerdp/cache/nine_grid.h b/include/freerdp/cache/nine_grid.h index 77e0f4636..3f5525bb4 100644 --- a/include/freerdp/cache/nine_grid.h +++ b/include/freerdp/cache/nine_grid.h @@ -24,7 +24,8 @@ #include <freerdp/types.h> #include <freerdp/freerdp.h> #include <freerdp/update.h> -#include <freerdp/utils/stream.h> + +#include <winpr/stream.h> typedef struct _NINE_GRID_ENTRY NINE_GRID_ENTRY; typedef struct rdp_nine_grid_cache rdpNineGridCache; diff --git a/include/freerdp/cache/offscreen.h b/include/freerdp/cache/offscreen.h index 4da367b75..0ed319769 100644 --- a/include/freerdp/cache/offscreen.h +++ b/include/freerdp/cache/offscreen.h @@ -24,7 +24,8 @@ #include <freerdp/types.h> #include <freerdp/update.h> #include <freerdp/freerdp.h> -#include <freerdp/utils/stream.h> + +#include <winpr/stream.h> typedef struct rdp_offscreen_cache rdpOffscreenCache; diff --git a/include/freerdp/cache/palette.h b/include/freerdp/cache/palette.h index 6e7d890ec..80fa747b1 100644 --- a/include/freerdp/cache/palette.h +++ b/include/freerdp/cache/palette.h @@ -24,7 +24,8 @@ #include <freerdp/types.h> #include <freerdp/update.h> #include <freerdp/freerdp.h> -#include <freerdp/utils/stream.h> + +#include <winpr/stream.h> typedef struct _PALETTE_TABLE_ENTRY PALETTE_TABLE_ENTRY; typedef struct rdp_palette_cache rdpPaletteCache; diff --git a/include/freerdp/cache/pointer.h b/include/freerdp/cache/pointer.h index ccfeae03b..949c3f0e6 100644 --- a/include/freerdp/cache/pointer.h +++ b/include/freerdp/cache/pointer.h @@ -25,7 +25,8 @@ #include <freerdp/update.h> #include <freerdp/freerdp.h> #include <freerdp/graphics.h> -#include <freerdp/utils/stream.h> + +#include <winpr/stream.h> typedef struct rdp_pointer_cache rdpPointerCache; diff --git a/include/freerdp/channels/channels.h b/include/freerdp/channels/channels.h index bd03bc42f..052b90931 100644 --- a/include/freerdp/channels/channels.h +++ b/include/freerdp/channels/channels.h @@ -41,11 +41,11 @@ FREERDP_API int freerdp_channels_pre_connect(rdpChannels* channels, freerdp* ins FREERDP_API int freerdp_channels_post_connect(rdpChannels* channels, freerdp* instance); FREERDP_API int freerdp_channels_data(freerdp* instance, int channel_id, void* data, int data_size, int flags, int total_size); -FREERDP_API int freerdp_channels_send_event(rdpChannels* channels, RDP_EVENT* event); +FREERDP_API int freerdp_channels_send_event(rdpChannels* channels, wMessage* event); FREERDP_API BOOL freerdp_channels_get_fds(rdpChannels* channels, freerdp* instance, void** read_fds, int* read_count, void** write_fds, int* write_count); FREERDP_API BOOL freerdp_channels_check_fds(rdpChannels* channels, freerdp* instance); -FREERDP_API RDP_EVENT* freerdp_channels_pop_event(rdpChannels* channels); +FREERDP_API wMessage* freerdp_channels_pop_event(rdpChannels* channels); FREERDP_API void freerdp_channels_close(rdpChannels* channels, freerdp* instance); FREERDP_API HANDLE freerdp_channels_get_event_handle(freerdp* instance); diff --git a/include/freerdp/channels/rdpdr.h b/include/freerdp/channels/rdpdr.h index 6a4c6412a..4aa209481 100644 --- a/include/freerdp/channels/rdpdr.h +++ b/include/freerdp/channels/rdpdr.h @@ -25,10 +25,10 @@ #include <winpr/file.h> #include <winpr/synch.h> #include <winpr/thread.h> +#include <winpr/stream.h> #include <winpr/interlocked.h> #include <freerdp/utils/list.h> -#include <freerdp/utils/stream.h> #include <freerdp/utils/svc_plugin.h> /* RDPDR_HEADER.Component */ @@ -465,7 +465,7 @@ struct _DEVICE UINT32 type; char* name; - STREAM* data; + wStream* data; pcIRPRequest IRPRequest; pcFreeDevice Free; @@ -483,10 +483,10 @@ struct _IRP UINT32 CompletionId; UINT32 MajorFunction; UINT32 MinorFunction; - STREAM* input; + wStream* input; UINT32 IoStatus; - STREAM* output; + wStream* output; pcIRPResponse Complete; pcIRPResponse Discard; diff --git a/include/freerdp/client.h b/include/freerdp/client.h new file mode 100644 index 000000000..5c0cc966d --- /dev/null +++ b/include/freerdp/client.h @@ -0,0 +1,62 @@ +/** + * FreeRDP: A Remote Desktop Protocol Implementation + * Client Interface + * + * Copyright 2013 Marc-Andre Moreau <marcandre.moreau@gmail.com> + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FREERDP_CLIENT_H +#define FREERDP_CLIENT_H + +typedef struct rdp_client rdpClient; + +#include <freerdp/api.h> +#include <freerdp/freerdp.h> + +#ifdef __cplusplus +extern "C" { +#endif + +typedef void (*pOnResizeWindow)(freerdp* instance, int width, int height); + +struct rdp_client +{ + pOnResizeWindow OnResizeWindow; +}; + +/** + * Generic Client Interface + */ + +#if 0 + +#define cfInfo void* + +FREERDP_API int freerdp_client_global_init(); +FREERDP_API int freerdp_client_global_uninit(); + +FREERDP_API int freerdp_client_start(cfInfo* cfi); +FREERDP_API int freerdp_client_stop(cfInfo* cfi); + +FREERDP_API cfInfo* freerdp_client_new(int argc, char** argv); +FREERDP_API void freerdp_client_free(cfInfo* cfi); + +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* FREERDP_CLIENT_H */ diff --git a/include/freerdp/client/cliprdr.h b/include/freerdp/client/cliprdr.h index c503de40d..ea0d1cf7a 100644 --- a/include/freerdp/client/cliprdr.h +++ b/include/freerdp/client/cliprdr.h @@ -21,12 +21,23 @@ #define FREERDP_CHANNEL_CLIENT_CLIPRDR_H /** - * Event Types + * Client Interface */ -#define RDP_EVENT_TYPE_CB_MONITOR_READY 1 -#define RDP_EVENT_TYPE_CB_FORMAT_LIST 2 -#define RDP_EVENT_TYPE_CB_DATA_REQUEST 3 -#define RDP_EVENT_TYPE_CB_DATA_RESPONSE 4 + +typedef struct _cliprdr_client_context CliprdrClientContext; + +typedef int (*pcCliprdrMonitorReady)(CliprdrClientContext* context); +typedef int (*pcCliprdrFormatList)(CliprdrClientContext* context); +typedef int (*pcCliprdrDataRequest)(CliprdrClientContext* context); +typedef int (*pcCliprdrDataResponse)(CliprdrClientContext* context); + +struct _cliprdr_client_context +{ + pcCliprdrMonitorReady MonitorReady; + pcCliprdrFormatList FormatList; + pcCliprdrDataRequest DataRequest; + pcCliprdrDataResponse DataResponse; +}; /** * Clipboard Formats @@ -44,11 +55,11 @@ /** * Clipboard Events */ -typedef RDP_EVENT RDP_CB_MONITOR_READY_EVENT; +typedef wMessage RDP_CB_MONITOR_READY_EVENT; struct _RDP_CB_FORMAT_LIST_EVENT { - RDP_EVENT event; + wMessage event; UINT32* formats; UINT16 num_formats; BYTE* raw_format_data; @@ -58,14 +69,14 @@ typedef struct _RDP_CB_FORMAT_LIST_EVENT RDP_CB_FORMAT_LIST_EVENT; struct _RDP_CB_DATA_REQUEST_EVENT { - RDP_EVENT event; + wMessage event; UINT32 format; }; typedef struct _RDP_CB_DATA_REQUEST_EVENT RDP_CB_DATA_REQUEST_EVENT; struct _RDP_CB_DATA_RESPONSE_EVENT { - RDP_EVENT event; + wMessage event; BYTE* data; UINT32 size; }; diff --git a/include/freerdp/client/tsmf.h b/include/freerdp/client/tsmf.h index 3a54fa2b7..d8b884f94 100644 --- a/include/freerdp/client/tsmf.h +++ b/include/freerdp/client/tsmf.h @@ -20,18 +20,9 @@ #ifndef FREERDP_CHANNEL_CLIENT_TSMF_H #define FREERDP_CHANNEL_CLIENT_TSMF_H -/** - * Event Types - */ -enum RDP_EVENT_TYPE_TSMF -{ - RDP_EVENT_TYPE_TSMF_VIDEO_FRAME = 1, - RDP_EVENT_TYPE_TSMF_REDRAW -}; - struct _RDP_VIDEO_FRAME_EVENT { - RDP_EVENT event; + wMessage event; BYTE* frame_data; UINT32 frame_size; UINT32 frame_pixfmt; @@ -48,7 +39,7 @@ typedef struct _RDP_VIDEO_FRAME_EVENT RDP_VIDEO_FRAME_EVENT; struct _RDP_REDRAW_EVENT { - RDP_EVENT event; + wMessage event; INT16 x; INT16 y; INT16 width; diff --git a/include/freerdp/codec/nsc.h b/include/freerdp/codec/nsc.h index 4ae32fd2f..16fc580f1 100644 --- a/include/freerdp/codec/nsc.h +++ b/include/freerdp/codec/nsc.h @@ -24,7 +24,8 @@ #include <freerdp/api.h> #include <freerdp/types.h> #include <freerdp/constants.h> -#include <freerdp/utils/stream.h> + +#include <winpr/stream.h> #ifdef __cplusplus extern "C" { @@ -68,7 +69,7 @@ FREERDP_API NSC_CONTEXT* nsc_context_new(void); FREERDP_API void nsc_context_set_pixel_format(NSC_CONTEXT* context, RDP_PIXEL_FORMAT pixel_format); FREERDP_API void nsc_process_message(NSC_CONTEXT* context, UINT16 bpp, UINT16 width, UINT16 height, BYTE* data, UINT32 length); -FREERDP_API void nsc_compose_message(NSC_CONTEXT* context, STREAM* s, +FREERDP_API void nsc_compose_message(NSC_CONTEXT* context, wStream* s, BYTE* bmpdata, int width, int height, int rowstride); FREERDP_API void nsc_context_free(NSC_CONTEXT* context); diff --git a/include/freerdp/codec/rfx.h b/include/freerdp/codec/rfx.h index 2e99607b2..d3ba0536a 100644 --- a/include/freerdp/codec/rfx.h +++ b/include/freerdp/codec/rfx.h @@ -23,7 +23,8 @@ #include <freerdp/api.h> #include <freerdp/types.h> #include <freerdp/constants.h> -#include <freerdp/utils/stream.h> + +#include <winpr/stream.h> #ifdef __cplusplus extern "C" { @@ -123,8 +124,8 @@ FREERDP_API UINT16 rfx_message_get_rect_count(RFX_MESSAGE* message); FREERDP_API RFX_RECT* rfx_message_get_rect(RFX_MESSAGE* message, int index); FREERDP_API void rfx_message_free(RFX_CONTEXT* context, RFX_MESSAGE* message); -FREERDP_API void rfx_compose_message_header(RFX_CONTEXT* context, STREAM* s); -FREERDP_API void rfx_compose_message(RFX_CONTEXT* context, STREAM* s, +FREERDP_API void rfx_compose_message_header(RFX_CONTEXT* context, wStream* s); +FREERDP_API void rfx_compose_message(RFX_CONTEXT* context, wStream* s, const RFX_RECT* rects, int num_rects, BYTE* image_data, int width, int height, int rowstride); #ifdef __cplusplus diff --git a/include/freerdp/crypto/ber.h b/include/freerdp/crypto/ber.h index 55263566c..2f04c87e3 100644 --- a/include/freerdp/crypto/ber.h +++ b/include/freerdp/crypto/ber.h @@ -22,7 +22,8 @@ #include <freerdp/api.h> #include <freerdp/types.h> -#include <freerdp/utils/stream.h> + +#include <winpr/stream.h> /* BER type */ @@ -51,34 +52,34 @@ #define BER_PC(_pc) (_pc ? BER_CONSTRUCT : BER_PRIMITIVE) -FREERDP_API BOOL ber_read_length(STREAM* s, int* length); -FREERDP_API int ber_write_length(STREAM* s, int length); +FREERDP_API BOOL ber_read_length(wStream* s, int* length); +FREERDP_API int ber_write_length(wStream* s, int length); FREERDP_API int _ber_skip_length(int length); FREERDP_API int ber_get_content_length(int length); -FREERDP_API BOOL ber_read_universal_tag(STREAM* s, BYTE tag, BOOL pc); -FREERDP_API void ber_write_universal_tag(STREAM* s, BYTE tag, BOOL pc); -FREERDP_API BOOL ber_read_application_tag(STREAM* s, BYTE tag, int* length); -FREERDP_API void ber_write_application_tag(STREAM* s, BYTE tag, int length); -FREERDP_API BOOL ber_read_application_tag(STREAM* s, BYTE tag, int* length); -FREERDP_API BOOL ber_read_enumerated(STREAM* s, BYTE* enumerated, BYTE count); -FREERDP_API void ber_write_enumerated(STREAM* s, BYTE enumerated, BYTE count); -FREERDP_API BOOL ber_read_contextual_tag(STREAM* s, BYTE tag, int* length, BOOL pc); -FREERDP_API int ber_write_contextual_tag(STREAM* s, BYTE tag, int length, BOOL pc); +FREERDP_API BOOL ber_read_universal_tag(wStream* s, BYTE tag, BOOL pc); +FREERDP_API void ber_write_universal_tag(wStream* s, BYTE tag, BOOL pc); +FREERDP_API BOOL ber_read_application_tag(wStream* s, BYTE tag, int* length); +FREERDP_API void ber_write_application_tag(wStream* s, BYTE tag, int length); +FREERDP_API BOOL ber_read_application_tag(wStream* s, BYTE tag, int* length); +FREERDP_API BOOL ber_read_enumerated(wStream* s, BYTE* enumerated, BYTE count); +FREERDP_API void ber_write_enumerated(wStream* s, BYTE enumerated, BYTE count); +FREERDP_API BOOL ber_read_contextual_tag(wStream* s, BYTE tag, int* length, BOOL pc); +FREERDP_API int ber_write_contextual_tag(wStream* s, BYTE tag, int length, BOOL pc); FREERDP_API int ber_skip_contextual_tag(int length); -FREERDP_API BOOL ber_read_sequence_tag(STREAM* s, int* length); -FREERDP_API int ber_write_sequence_tag(STREAM* s, int length); +FREERDP_API BOOL ber_read_sequence_tag(wStream* s, int* length); +FREERDP_API int ber_write_sequence_tag(wStream* s, int length); FREERDP_API int ber_skip_sequence(int length); FREERDP_API int ber_skip_sequence_tag(int length); -FREERDP_API BOOL ber_read_bit_string(STREAM* s, int* length, BYTE* padding); -FREERDP_API void ber_write_octet_string(STREAM* s, const BYTE* oct_str, int length); -FREERDP_API BOOL ber_read_octet_string_tag(STREAM* s, int* length); -FREERDP_API int ber_write_octet_string_tag(STREAM* s, int length); +FREERDP_API BOOL ber_read_bit_string(wStream* s, int* length, BYTE* padding); +FREERDP_API void ber_write_octet_string(wStream* s, const BYTE* oct_str, int length); +FREERDP_API BOOL ber_read_octet_string_tag(wStream* s, int* length); +FREERDP_API int ber_write_octet_string_tag(wStream* s, int length); FREERDP_API int ber_skip_octet_string(int length); -FREERDP_API BOOL ber_read_BOOL(STREAM* s, BOOL* value); -FREERDP_API void ber_write_BOOL(STREAM* s, BOOL value); -FREERDP_API BOOL ber_read_integer(STREAM* s, UINT32* value); -FREERDP_API int ber_write_integer(STREAM* s, UINT32 value); -FREERDP_API BOOL ber_read_integer_length(STREAM* s, int* length); +FREERDP_API BOOL ber_read_BOOL(wStream* s, BOOL* value); +FREERDP_API void ber_write_BOOL(wStream* s, BOOL value); +FREERDP_API BOOL ber_read_integer(wStream* s, UINT32* value); +FREERDP_API int ber_write_integer(wStream* s, UINT32 value); +FREERDP_API BOOL ber_read_integer_length(wStream* s, int* length); FREERDP_API int ber_skip_integer(UINT32 value); #endif /* FREERDP_CRYPTO_BER_H */ diff --git a/include/freerdp/crypto/certificate.h b/include/freerdp/crypto/certificate.h index 8a496b693..d634c90f4 100644 --- a/include/freerdp/crypto/certificate.h +++ b/include/freerdp/crypto/certificate.h @@ -28,8 +28,9 @@ typedef struct rdp_certificate_store rdpCertificateStore; #include <freerdp/api.h> #include <freerdp/settings.h> -#include <freerdp/utils/stream.h> + #include <winpr/print.h> +#include <winpr/stream.h> struct rdp_certificate_data { diff --git a/include/freerdp/crypto/der.h b/include/freerdp/crypto/der.h index b7fd3937e..20ace5f1b 100644 --- a/include/freerdp/crypto/der.h +++ b/include/freerdp/crypto/der.h @@ -23,13 +23,13 @@ #include <freerdp/crypto/er.h> FREERDP_API int _der_skip_length(int length); -FREERDP_API int der_write_length(STREAM* s, int length); +FREERDP_API int der_write_length(wStream* s, int length); FREERDP_API int der_get_content_length(int length); FREERDP_API int der_skip_octet_string(int length); FREERDP_API int der_skip_sequence_tag(int length); -FREERDP_API int der_write_sequence_tag(STREAM* s, int length); +FREERDP_API int der_write_sequence_tag(wStream* s, int length); FREERDP_API int der_skip_contextual_tag(int length); -FREERDP_API int der_write_contextual_tag(STREAM* s, BYTE tag, int length, BOOL pc); -FREERDP_API void der_write_octet_string(STREAM* s, BYTE* oct_str, int length); +FREERDP_API int der_write_contextual_tag(wStream* s, BYTE tag, int length, BOOL pc); +FREERDP_API void der_write_octet_string(wStream* s, BYTE* oct_str, int length); #endif /* FREERDP_CRYPTO_DER_H */ diff --git a/include/freerdp/crypto/er.h b/include/freerdp/crypto/er.h index bbbcc83b8..91110e184 100644 --- a/include/freerdp/crypto/er.h +++ b/include/freerdp/crypto/er.h @@ -23,7 +23,9 @@ #include <freerdp/api.h> #include <freerdp/types.h> -#include <freerdp/utils/stream.h> + + +#include <winpr/stream.h> /* ER type */ @@ -54,35 +56,35 @@ #define ER_PC(_pc) (_pc ? ER_CONSTRUCT : ER_PRIMITIVE) -FREERDP_API void er_read_length(STREAM* s, int* length); -FREERDP_API int er_write_length(STREAM* s, int length, BOOL flag); +FREERDP_API void er_read_length(wStream* s, int* length); +FREERDP_API int er_write_length(wStream* s, int length, BOOL flag); FREERDP_API int _er_skip_length(int length); FREERDP_API int er_get_content_length(int length); -FREERDP_API BOOL er_read_universal_tag(STREAM* s, BYTE tag, BOOL pc); -FREERDP_API void er_write_universal_tag(STREAM* s, BYTE tag, BOOL pc); -FREERDP_API BOOL er_read_application_tag(STREAM* s, BYTE tag, int* length); -FREERDP_API void er_write_application_tag(STREAM* s, BYTE tag, int length, BOOL flag); -FREERDP_API BOOL er_read_application_tag(STREAM* s, BYTE tag, int* length); -FREERDP_API BOOL er_read_enumerated(STREAM* s, BYTE* enumerated, BYTE count); -FREERDP_API void er_write_enumerated(STREAM* s, BYTE enumerated, BYTE count, BOOL flag); -FREERDP_API BOOL er_read_contextual_tag(STREAM* s, BYTE tag, int* length, BOOL pc); -FREERDP_API int er_write_contextual_tag(STREAM* s, BYTE tag, int length, BOOL pc, BOOL flag); +FREERDP_API BOOL er_read_universal_tag(wStream* s, BYTE tag, BOOL pc); +FREERDP_API void er_write_universal_tag(wStream* s, BYTE tag, BOOL pc); +FREERDP_API BOOL er_read_application_tag(wStream* s, BYTE tag, int* length); +FREERDP_API void er_write_application_tag(wStream* s, BYTE tag, int length, BOOL flag); +FREERDP_API BOOL er_read_application_tag(wStream* s, BYTE tag, int* length); +FREERDP_API BOOL er_read_enumerated(wStream* s, BYTE* enumerated, BYTE count); +FREERDP_API void er_write_enumerated(wStream* s, BYTE enumerated, BYTE count, BOOL flag); +FREERDP_API BOOL er_read_contextual_tag(wStream* s, BYTE tag, int* length, BOOL pc); +FREERDP_API int er_write_contextual_tag(wStream* s, BYTE tag, int length, BOOL pc, BOOL flag); FREERDP_API int er_skip_contextual_tag(int length); -FREERDP_API BOOL er_read_sequence_tag(STREAM* s, int* length); -FREERDP_API int er_write_sequence_tag(STREAM* s, int length, BOOL flag); +FREERDP_API BOOL er_read_sequence_tag(wStream* s, int* length); +FREERDP_API int er_write_sequence_tag(wStream* s, int length, BOOL flag); FREERDP_API int er_skip_sequence(int length); FREERDP_API int er_skip_sequence_tag(int length); -FREERDP_API BOOL er_read_bit_string(STREAM* s, int* length, BYTE* padding); -FREERDP_API BOOL er_write_bit_string_tag(STREAM* s, UINT32 length, BYTE padding, BOOL flag); -FREERDP_API BOOL er_read_octet_string(STREAM* s, int* length); -FREERDP_API void er_write_octet_string(STREAM* s, BYTE* oct_str, int length, BOOL flag); -FREERDP_API int er_write_octet_string_tag(STREAM* s, int length, BOOL flag); +FREERDP_API BOOL er_read_bit_string(wStream* s, int* length, BYTE* padding); +FREERDP_API BOOL er_write_bit_string_tag(wStream* s, UINT32 length, BYTE padding, BOOL flag); +FREERDP_API BOOL er_read_octet_string(wStream* s, int* length); +FREERDP_API void er_write_octet_string(wStream* s, BYTE* oct_str, int length, BOOL flag); +FREERDP_API int er_write_octet_string_tag(wStream* s, int length, BOOL flag); FREERDP_API int er_skip_octet_string(int length); -FREERDP_API BOOL er_read_BOOL(STREAM* s, BOOL* value); -FREERDP_API void er_write_BOOL(STREAM* s, BOOL value); -FREERDP_API BOOL er_read_integer(STREAM* s, UINT32* value); -FREERDP_API int er_write_integer(STREAM* s, INT32 value); -FREERDP_API BOOL er_read_integer_length(STREAM* s, int* length); +FREERDP_API BOOL er_read_BOOL(wStream* s, BOOL* value); +FREERDP_API void er_write_BOOL(wStream* s, BOOL value); +FREERDP_API BOOL er_read_integer(wStream* s, UINT32* value); +FREERDP_API int er_write_integer(wStream* s, INT32 value); +FREERDP_API BOOL er_read_integer_length(wStream* s, int* length); FREERDP_API int er_skip_integer(INT32 value); #endif /* FREERDP_CRYPTO_ER_H */ diff --git a/include/freerdp/crypto/per.h b/include/freerdp/crypto/per.h index 479784c2d..60487a81a 100644 --- a/include/freerdp/crypto/per.h +++ b/include/freerdp/crypto/per.h @@ -21,29 +21,30 @@ #define FREERDP_CRYPTO_PER_H #include <freerdp/api.h> -#include <freerdp/utils/stream.h> -FREERDP_API BOOL per_read_length(STREAM* s, UINT16* length); -FREERDP_API void per_write_length(STREAM* s, int length); -FREERDP_API BOOL per_read_choice(STREAM* s, BYTE* choice); -FREERDP_API void per_write_choice(STREAM* s, BYTE choice); -FREERDP_API BOOL per_read_selection(STREAM* s, BYTE* selection); -FREERDP_API void per_write_selection(STREAM* s, BYTE selection); -FREERDP_API BOOL per_read_number_of_sets(STREAM* s, BYTE* number); -FREERDP_API void per_write_number_of_sets(STREAM* s, BYTE number); -FREERDP_API BOOL per_read_padding(STREAM* s, int length); -FREERDP_API void per_write_padding(STREAM* s, int length); -FREERDP_API BOOL per_read_integer(STREAM* s, UINT32* integer); -FREERDP_API BOOL per_read_integer16(STREAM* s, UINT16* integer, UINT16 min); -FREERDP_API void per_write_integer(STREAM* s, UINT32 integer); -FREERDP_API void per_write_integer16(STREAM* s, UINT16 integer, UINT16 min); -FREERDP_API BOOL per_read_enumerated(STREAM* s, BYTE* enumerated, BYTE count); -FREERDP_API void per_write_enumerated(STREAM* s, BYTE enumerated, BYTE count); -FREERDP_API void per_write_object_identifier(STREAM* s, BYTE oid[6]); -FREERDP_API BOOL per_read_object_identifier(STREAM* s, BYTE oid[6]); -FREERDP_API BOOL per_read_octet_string(STREAM* s, BYTE* oct_str, int length, int min); -FREERDP_API void per_write_octet_string(STREAM* s, BYTE* oct_str, int length, int min); -FREERDP_API BOOL per_read_numeric_string(STREAM* s, int min); -FREERDP_API void per_write_numeric_string(STREAM* s, BYTE* num_str, int length, int min); +#include <winpr/stream.h> + +FREERDP_API BOOL per_read_length(wStream* s, UINT16* length); +FREERDP_API void per_write_length(wStream* s, int length); +FREERDP_API BOOL per_read_choice(wStream* s, BYTE* choice); +FREERDP_API void per_write_choice(wStream* s, BYTE choice); +FREERDP_API BOOL per_read_selection(wStream* s, BYTE* selection); +FREERDP_API void per_write_selection(wStream* s, BYTE selection); +FREERDP_API BOOL per_read_number_of_sets(wStream* s, BYTE* number); +FREERDP_API void per_write_number_of_sets(wStream* s, BYTE number); +FREERDP_API BOOL per_read_padding(wStream* s, int length); +FREERDP_API void per_write_padding(wStream* s, int length); +FREERDP_API BOOL per_read_integer(wStream* s, UINT32* integer); +FREERDP_API BOOL per_read_integer16(wStream* s, UINT16* integer, UINT16 min); +FREERDP_API void per_write_integer(wStream* s, UINT32 integer); +FREERDP_API void per_write_integer16(wStream* s, UINT16 integer, UINT16 min); +FREERDP_API BOOL per_read_enumerated(wStream* s, BYTE* enumerated, BYTE count); +FREERDP_API void per_write_enumerated(wStream* s, BYTE enumerated, BYTE count); +FREERDP_API void per_write_object_identifier(wStream* s, BYTE oid[6]); +FREERDP_API BOOL per_read_object_identifier(wStream* s, BYTE oid[6]); +FREERDP_API BOOL per_read_octet_string(wStream* s, BYTE* oct_str, int length, int min); +FREERDP_API void per_write_octet_string(wStream* s, BYTE* oct_str, int length, int min); +FREERDP_API BOOL per_read_numeric_string(wStream* s, int min); +FREERDP_API void per_write_numeric_string(wStream* s, BYTE* num_str, int length, int min); #endif /* FREERDP_CRYPTO_PER_H */ diff --git a/include/freerdp/crypto/tls.h b/include/freerdp/crypto/tls.h index 527f69ba0..258ee2ebb 100644 --- a/include/freerdp/crypto/tls.h +++ b/include/freerdp/crypto/tls.h @@ -31,7 +31,8 @@ #include <freerdp/api.h> #include <freerdp/types.h> -#include <freerdp/utils/stream.h> + +#include <winpr/stream.h> typedef struct rdp_tls rdpTls; diff --git a/include/freerdp/dvc.h b/include/freerdp/dvc.h index 727acb2c1..f2025a448 100644 --- a/include/freerdp/dvc.h +++ b/include/freerdp/dvc.h @@ -92,7 +92,7 @@ struct _IWTSVirtualChannelManager /* Push a virtual channel event. This is a FreeRDP extension to standard MS API. */ int (*PushEvent) (IWTSVirtualChannelManager* pChannelMgr, - RDP_EVENT* pEvent); + wMessage* pEvent); /* Find the channel or ID to send data to a specific endpoint. */ UINT32 (*GetChannelId) (IWTSVirtualChannel * channel); IWTSVirtualChannel* (*FindChannelById) (IWTSVirtualChannelManager* pChannelMgr, diff --git a/include/freerdp/freerdp.h b/include/freerdp/freerdp.h index 5f593a402..0a3beb346 100644 --- a/include/freerdp/freerdp.h +++ b/include/freerdp/freerdp.h @@ -36,7 +36,10 @@ typedef struct rdp_freerdp_peer freerdp_peer; #include <freerdp/error.h> #include <freerdp/settings.h> #include <freerdp/extension.h> -#include <freerdp/utils/stream.h> + +#include <winpr/stream.h> + +#include <freerdp/client.h> #include <freerdp/input.h> #include <freerdp/update.h> @@ -55,6 +58,8 @@ typedef BOOL (*pAuthenticate)(freerdp* instance, char** username, char** passwor typedef BOOL (*pVerifyCertificate)(freerdp* instance, char* subject, char* issuer, char* fingerprint); typedef BOOL (*pVerifyChangedCertificate)(freerdp* instance, char* subject, char* issuer, char* new_fingerprint, char* old_fingerprint); +typedef int (*pLogonErrorInfo)(freerdp* instance, UINT32 data, UINT32 type); + typedef int (*pSendChannelData)(freerdp* instance, int channelId, BYTE* data, int size); typedef int (*pReceiveChannelData)(freerdp* instance, int channelId, BYTE* data, int size, int flags, int total_size); @@ -101,7 +106,8 @@ struct rdp_context rdpInput* input; /* 38 */ rdpUpdate* update; /* 39 */ rdpSettings* settings; /* 40 */ - UINT32 paddingC[64 - 41]; /* 41 */ + rdpClient* client; /* 41 */ + UINT32 paddingC[64 - 42]; /* 42 */ }; /** Defines the options for a given instance of RDP connection. @@ -174,7 +180,10 @@ struct rdp_freerdp Callback for changed certificate validation. Used when a certificate differs from stored fingerprint. If returns TRUE, the new fingerprint will be trusted and old thrown out. */ - UINT32 paddingD[64 - 51]; /* 51 */ + + pLogonErrorInfo LogonErrorInfo; /**< (offset 53) Callback for logon error info, important for logon system messages with RemoteApp */ + + UINT32 paddingD[64 - 54]; /* 54 */ pSendChannelData SendChannelData; /* (offset 64) Callback for sending data to a channel. diff --git a/include/freerdp/input.h b/include/freerdp/input.h index f437dde28..a08637e1d 100644 --- a/include/freerdp/input.h +++ b/include/freerdp/input.h @@ -39,9 +39,9 @@ typedef struct rdp_input rdpInput; #define PTR_FLAGS_WHEEL_NEGATIVE 0x0100 #define PTR_FLAGS_MOVE 0x0800 #define PTR_FLAGS_DOWN 0x8000 -#define PTR_FLAGS_BUTTON1 0x1000 //left -#define PTR_FLAGS_BUTTON2 0x2000 //right -#define PTR_FLAGS_BUTTON3 0x4000 //middle +#define PTR_FLAGS_BUTTON1 0x1000 /* left */ +#define PTR_FLAGS_BUTTON2 0x2000 /* right */ +#define PTR_FLAGS_BUTTON3 0x4000 /* middle */ #define WheelRotationMask 0x01FF /* Extended Pointer Flags */ diff --git a/include/freerdp/message.h b/include/freerdp/message.h index 9eea25005..754802ba2 100644 --- a/include/freerdp/message.h +++ b/include/freerdp/message.h @@ -20,8 +20,10 @@ #ifndef FREERDP_CORE_MESSAGE_H #define FREERDP_CORE_MESSAGE_H -#define GetMessageType(_id) (_id & 0xFF) -#define GetMessageClass(_id) ((_id >> 16) & 0xFF) +#define GetMessageType(_id) (_id & 0xFF) +#define GetMessageClass(_id) ((_id >> 16) & 0xFF) + +#define GetMessageId(_class, _type) ((_class << 16) | _type) #define MakeMessageId(_class, _type) \ (((_class ##_Class) << 16) | (_class ## _ ## _type)) @@ -234,5 +236,93 @@ #define FREERDP_INPUT_MOUSE_EVENT MakeMessageId(Input, MouseEvent) #define FREERDP_INPUT_EXTENDED_MOUSE_EVENT MakeMessageId(Input, ExtendedMouseEvent) +/** + * Static Channel Message Queues + */ + +#define FREERDP_CHANNEL_MESSAGE_QUEUE 3 + +#define Channel_Base 20 + +/** + * Debug Channel + */ + +#define DebugChannel_Class (Channel_Base + 1) + +/** + * Clipboard Channel + */ + +#define CliprdrChannel_Class (Channel_Base + 2) + +#define CliprdrChannel_MonitorReady 1 +#define CliprdrChannel_FormatList 2 +#define CliprdrChannel_DataRequest 3 +#define CliprdrChannel_DataResponse 4 + +#define FREERDP_CLIPRDR_CHANNEL_MONITOR_READY MakeMessageId(CliprdrChannel, MonitorReady) +#define FREERDP_CLIPRDR_CHANNEL_FORMAT_LIST MakeMessageId(CliprdrChannel, FormatList) +#define FREERDP_CLIPRDR_CHANNEL_DATA_REQUEST MakeMessageId(CliprdrChannel, DataRequest) +#define FREERDP_CLIPRDR_CHANNEL_DATA_RESPONSE MakeMessageId(CliprdrChannel, DataResponse) + +/** + * Multimedia Redirection Channel + */ + +#define TsmfChannel_Class (Channel_Base + 3) + +#define TsmfChannel_VideoFrame 1 +#define TsmfChannel_Redraw 2 + +#define FREERDP_TSMF_CHANNEL_VIDEO_FRAME MakeMessageId(TsmfChannel, VideoFrame) +#define FREERDP_TSMF_CHANNEL_REDRAW MakeMessageId(TsmfChannel, Redraw) + +/** + * RemoteApp Channel + */ + +#define RailChannel_Class (Channel_Base + 4) + +#define RailChannel_ClientExecute 1 +#define RailChannel_ClientActivate 2 +#define RailChannel_GetSystemParam 3 +#define RailChannel_ClientSystemParam 4 +#define RailChannel_ServerSystemParam 5 +#define RailChannel_ClientSystemCommand 6 +#define RailChannel_ClientHandshake 7 +#define RailChannel_ServerHandshake 8 +#define RailChannel_ClientNotifyEvent 9 +#define RailChannel_ClientWindowMove 10 +#define RailChannel_ServerLocalMoveSize 11 +#define RailChannel_ServerMinMaxInfo 12 +#define RailChannel_ClientInformation 13 +#define RailChannel_ClientSystemMenu 14 +#define RailChannel_ClientLanguageBarInfo 15 +#define RailChannel_ServerLanguageBarInfo 16 +#define RailChannel_ServerExecuteResult 17 +#define RailChannel_ClientGetAppIdRequest 18 +#define RailChannel_ServerGetAppIdResponse 19 + +#define FREERDP_RAIL_CHANNEL_CLIENT_EXECUTE MakeMessageId(RailChannel, ClientExecute) +#define FREERDP_RAIL_CHANNEL_CLIENT_ACTIVATE MakeMessageId(RailChannel, ClientActivate) +#define FREERDP_RAIL_CHANNEL_GET_SYSTEM_PARAM MakeMessageId(RailChannel, GetSystemParam) +#define FREERDP_RAIL_CHANNEL_CLIENT_SYSTEM_PARAM MakeMessageId(RailChannel, ClientSystemParam) +#define FREERDP_RAIL_CHANNEL_SERVER_SYSTEM_PARAM MakeMessageId(RailChannel, ClientSystemParam) +#define FREERDP_RAIL_CHANNEL_CLIENT_SYSTEM_COMMAND MakeMessageId(RailChannel, ClientSystemCommand) +#define FREERDP_RAIL_CHANNEL_CLIENT_HANDSHAKE MakeMessageId(RailChannel, ClientHandshake) +#define FREERDP_RAIL_CHANNEL_SERVER_HANDSHAKE MakeMessageId(RailChannel, ServerHandshake) +#define FREERDP_RAIL_CHANNEL_CLIENT_NOTIFY_EVENT MakeMessageId(RailChannel, ClientNotifyEvent) +#define FREERDP_RAIL_CHANNEL_CLIENT_WINDOW_MOVE MakeMessageId(RailChannel, ClientWindowMove) +#define FREERDP_RAIL_CHANNEL_SERVER_LOCAL_MOVE_SIZE MakeMessageId(RailChannel, ServerLocalMoveSize) +#define FREERDP_RAIL_CHANNEL_SERVER_MIN_MAX_INFO MakeMessageId(RailChannel, ServerMinMaxInfo) +#define FREERDP_RAIL_CHANNEL_CLIENT_INFORMATION MakeMessageId(RailChannel, ClientInformation) +#define FREERDP_RAIL_CHANNEL_CLIENT_SYSTEM_MENU MakeMessageId(RailChannel, ClientSystemMenu) +#define FREERDP_RAIL_CHANNEL_CLIENT_LANGUAGE_BAR_INFO MakeMessageId(RailChannel, ClientLanguageBarInfo) +#define FREERDP_RAIL_CHANNEL_SERVER_LANGUAGE_BAR_INFO MakeMessageId(RailChannel, ServerLanguageBarInfo) +#define FREERDP_RAIL_CHANNEL_SERVER_EXECUTE_RESULT MakeMessageId(RailChannel, ServerExecuteResult) +#define FREERDP_RAIL_CHANNEL_CLIENT_GET_APP_ID_REQUEST MakeMessageId(RailChannel, ClientGetAppIdRequest) +#define FREERDP_RAIL_CHANNEL_SERVER_GET_APP_ID_RESPONSE MakeMessageId(RailChannel, ServerGetAppIdResponse) + #endif /* FREERDP_CORE_MESSAGE_H */ diff --git a/include/freerdp/rail.h b/include/freerdp/rail.h index 714e376d5..08225c0de 100644 --- a/include/freerdp/rail.h +++ b/include/freerdp/rail.h @@ -319,25 +319,4 @@ enum RDP_RAIL_PDU_TYPE RDP_RAIL_ORDER_GET_APPID_RESP = 0x000F }; -enum RDP_EVENT_TYPE_RAIL -{ - RDP_EVENT_TYPE_RAIL_CHANNEL_GET_SYSPARAMS = 1, - RDP_EVENT_TYPE_RAIL_CHANNEL_EXEC_RESULTS, - RDP_EVENT_TYPE_RAIL_CHANNEL_SERVER_SYSPARAM, - RDP_EVENT_TYPE_RAIL_CHANNEL_SERVER_MINMAXINFO, - RDP_EVENT_TYPE_RAIL_CHANNEL_SERVER_LOCALMOVESIZE, - RDP_EVENT_TYPE_RAIL_CHANNEL_APPID_RESP, - RDP_EVENT_TYPE_RAIL_CHANNEL_LANGBARINFO, - - RDP_EVENT_TYPE_RAIL_CLIENT_SET_SYSPARAMS, - RDP_EVENT_TYPE_RAIL_CLIENT_EXEC_REMOTE_APP, - RDP_EVENT_TYPE_RAIL_CLIENT_ACTIVATE, - RDP_EVENT_TYPE_RAIL_CLIENT_SYSMENU, - RDP_EVENT_TYPE_RAIL_CLIENT_SYSCOMMAND, - RDP_EVENT_TYPE_RAIL_CLIENT_NOTIFY_EVENT, - RDP_EVENT_TYPE_RAIL_CLIENT_WINDOW_MOVE, - RDP_EVENT_TYPE_RAIL_CLIENT_APPID_REQ, - RDP_EVENT_TYPE_RAIL_CLIENT_LANGBARINFO -}; - #endif /* FREERDP_RAIL_GLOBAL_H */ diff --git a/include/freerdp/rail/icon.h b/include/freerdp/rail/icon.h index 1a4cf68d4..109750afc 100644 --- a/include/freerdp/rail/icon.h +++ b/include/freerdp/rail/icon.h @@ -24,7 +24,8 @@ #include <freerdp/rail.h> #include <freerdp/types.h> #include <freerdp/update.h> -#include <freerdp/utils/stream.h> + +#include <winpr/stream.h> typedef struct rdp_icon rdpIcon; typedef struct rdp_icon_cache rdpIconCache; diff --git a/include/freerdp/rail/rail.h b/include/freerdp/rail/rail.h index 17d575437..cb8340717 100644 --- a/include/freerdp/rail/rail.h +++ b/include/freerdp/rail/rail.h @@ -25,9 +25,10 @@ #include <freerdp/types.h> #include <freerdp/update.h> #include <freerdp/freerdp.h> -#include <freerdp/utils/stream.h> #include <freerdp/codec/color.h> +#include <winpr/stream.h> + #include <freerdp/rail/icon.h> #include <freerdp/rail/window.h> #include <freerdp/rail/window_list.h> diff --git a/include/freerdp/rail/window.h b/include/freerdp/rail/window.h index 6eeadd1ba..0514951cb 100644 --- a/include/freerdp/rail/window.h +++ b/include/freerdp/rail/window.h @@ -24,7 +24,8 @@ #include <freerdp/rail.h> #include <freerdp/types.h> #include <freerdp/update.h> -#include <freerdp/utils/stream.h> + +#include <winpr/stream.h> typedef struct rdp_window rdpWindow; diff --git a/include/freerdp/rail/window_list.h b/include/freerdp/rail/window_list.h index a1fcf8b48..615c94ded 100644 --- a/include/freerdp/rail/window_list.h +++ b/include/freerdp/rail/window_list.h @@ -23,7 +23,8 @@ #include <freerdp/api.h> #include <freerdp/types.h> #include <freerdp/update.h> -#include <freerdp/utils/stream.h> + +#include <winpr/stream.h> typedef struct rdp_window_list rdpWindowList; diff --git a/include/freerdp/server/audin.h b/include/freerdp/server/audin.h index 9be2a4d67..9eb5f4be9 100644 --- a/include/freerdp/server/audin.h +++ b/include/freerdp/server/audin.h @@ -20,6 +20,7 @@ #ifndef FREERDP_CHANNEL_AUDIN_SERVER_H #define FREERDP_CHANNEL_AUDIN_SERVER_H +#include <freerdp/codec/audio.h> #include <freerdp/channels/wtsvc.h> #include <freerdp/channels/rdpsnd.h> diff --git a/include/freerdp/settings.h b/include/freerdp/settings.h index de4ac976f..0a078c280 100644 --- a/include/freerdp/settings.h +++ b/include/freerdp/settings.h @@ -226,6 +226,19 @@ struct _TARGET_NET_ADDRESS }; typedef struct _TARGET_NET_ADDRESS TARGET_NET_ADDRESS; +/* Logon Error Info */ + +#define LOGON_MSG_NO_PERMISSION 0xFFFFFFFA +#define LOGON_MSG_BUMP_OPTIONS 0xFFFFFFFB +#define LOGON_MSG_SESSION_RECONNECT 0xFFFFFFFC +#define LOGON_MSG_SESSION_TERMINATE 0xFFFFFFFD +#define LOGON_MSG_SESSION_CONTINUE 0xFFFFFFFE + +#define LOGON_FAILED_BAD_PASSWORD 0x00000000 +#define LOGON_FAILED_UPDATE_PASSWORD 0x00000001 +#define LOGON_FAILED_OTHER 0x00000002 +#define LOGON_WARNING 0x00000003 + /* SYSTEM_TIME */ typedef struct { @@ -448,6 +461,274 @@ typedef struct _RDPDR_PARALLEL RDPDR_PARALLEL; #endif #endif +/** + * FreeRDP Settings Ids + * This is generated with a script parsing the rdpSettings data structure + */ + +#define FreeRDP_instance 0 +#define FreeRDP_ServerMode 16 +#define FreeRDP_ShareId 17 +#define FreeRDP_PduSource 18 +#define FreeRDP_ServerPort 19 +#define FreeRDP_ServerHostname 20 +#define FreeRDP_Username 21 +#define FreeRDP_Password 22 +#define FreeRDP_Domain 23 +#define FreeRDP_RdpVersion 128 +#define FreeRDP_DesktopWidth 129 +#define FreeRDP_DesktopHeight 130 +#define FreeRDP_ColorDepth 131 +#define FreeRDP_ConnectionType 132 +#define FreeRDP_ClientBuild 133 +#define FreeRDP_ClientHostname 134 +#define FreeRDP_ClientProductId 135 +#define FreeRDP_EarlyCapabilityFlags 136 +#define FreeRDP_NetworkAutoDetect 137 +#define FreeRDP_SupportAsymetricKeys 138 +#define FreeRDP_SupportErrorInfoPdu 139 +#define FreeRDP_SupportStatusInfoPdu 140 +#define FreeRDP_SupportMonitorLayoutPdu 141 +#define FreeRDP_SupportGraphicsPipeline 142 +#define FreeRDP_SupportDynamicTimeZone 143 +#define FreeRDP_DisableEncryption 192 +#define FreeRDP_EncryptionMethods 193 +#define FreeRDP_ExtEncryptionMethods 194 +#define FreeRDP_EncryptionLevel 195 +#define FreeRDP_ServerRandom 196 +#define FreeRDP_ServerRandomLength 197 +#define FreeRDP_ServerCertificate 198 +#define FreeRDP_ServerCertificateLength 199 +#define FreeRDP_ChannelCount 256 +#define FreeRDP_ChannelDefArraySize 257 +#define FreeRDP_ChannelDefArray 258 +#define FreeRDP_ClusterInfoFlags 320 +#define FreeRDP_RedirectedSessionId 321 +#define FreeRDP_ConsoleSession 322 +#define FreeRDP_MonitorCount 384 +#define FreeRDP_MonitorDefArraySize 385 +#define FreeRDP_MonitorDefArray 386 +#define FreeRDP_SpanMonitors 387 +#define FreeRDP_UseMultimon 388 +#define FreeRDP_ForceMultimon 389 +#define FreeRDP_MultitransportFlags 512 +#define FreeRDP_AlternateShell 640 +#define FreeRDP_ShellWorkingDirectory 641 +#define FreeRDP_AutoLogonEnabled 704 +#define FreeRDP_CompressionEnabled 705 +#define FreeRDP_DisableCtrlAltDel 706 +#define FreeRDP_EnableWindowsKey 707 +#define FreeRDP_MaximizeShell 708 +#define FreeRDP_LogonNotify 709 +#define FreeRDP_LogonErrors 710 +#define FreeRDP_MouseAttached 711 +#define FreeRDP_MouseHasWheel 712 +#define FreeRDP_RemoteConsoleAudio 713 +#define FreeRDP_AudioPlayback 714 +#define FreeRDP_AudioCapture 715 +#define FreeRDP_VideoDisable 716 +#define FreeRDP_PasswordIsSmartcardPin 717 +#define FreeRDP_UsingSavedCredentials 718 +#define FreeRDP_ForceEncryptedCsPdu 719 +#define FreeRDP_IPv6Enabled 768 +#define FreeRDP_ClientAddress 769 +#define FreeRDP_ClientDir 770 +#define FreeRDP_AutoReconnectionEnabled 832 +#define FreeRDP_AutoReconnectMaxRetries 833 +#define FreeRDP_ClientAutoReconnectCookie 834 +#define FreeRDP_ServerAutoReconnectCookie 835 +#define FreeRDP_ClientTimeZone 896 +#define FreeRDP_DynamicDSTTimeZoneKeyName 897 +#define FreeRDP_DynamicDaylightTimeDisabled 898 +#define FreeRDP_PerformanceFlags 960 +#define FreeRDP_AllowFontSmoothing 961 +#define FreeRDP_DisableWallpaper 962 +#define FreeRDP_DisableFullWindowDrag 963 +#define FreeRDP_DisableMenuAnims 964 +#define FreeRDP_DisableThemes 965 +#define FreeRDP_DisableCursorShadow 966 +#define FreeRDP_DisableCursorBlinking 967 +#define FreeRDP_AllowDesktopComposition 968 +#define FreeRDP_TlsSecurity 1088 +#define FreeRDP_NlaSecurity 1089 +#define FreeRDP_RdpSecurity 1090 +#define FreeRDP_ExtSecurity 1091 +#define FreeRDP_Authentication 1092 +#define FreeRDP_RequestedProtocols 1093 +#define FreeRDP_SelectedProtocol 1094 +#define FreeRDP_NegotiationFlags 1095 +#define FreeRDP_NegotiateSecurityLayer 1096 +#define FreeRDP_MstscCookieMode 1152 +#define FreeRDP_CookieMaxLength 1153 +#define FreeRDP_PreconnectionId 1154 +#define FreeRDP_PreconnectionBlob 1155 +#define FreeRDP_SendPreconnectionPdu 1156 +#define FreeRDP_RedirectionFlags 1216 +#define FreeRDP_LoadBalanceInfo 1217 +#define FreeRDP_LoadBalanceInfoLength 1218 +#define FreeRDP_RedirectionUsername 1219 +#define FreeRDP_RedirectionUsernameLength 1220 +#define FreeRDP_RedirectionDomain 1221 +#define FreeRDP_RedirectionDomainLength 1222 +#define FreeRDP_RedirectionPassword 1223 +#define FreeRDP_RedirectionPasswordLength 1224 +#define FreeRDP_RedirectionTargetFQDN 1225 +#define FreeRDP_RedirectionTargetFQDNLength 1226 +#define FreeRDP_RedirectionTargetNetBiosName 1227 +#define FreeRDP_RedirectionTargetNetBiosNameLength 1228 +#define FreeRDP_RedirectionTsvUrl 1229 +#define FreeRDP_RedirectionTsvUrlLength 1230 +#define FreeRDP_TargetNetAddressCount 1231 +#define FreeRDP_TargetNetAddresses 1232 +#define FreeRDP_Password51 1280 +#define FreeRDP_Password51Length 1281 +#define FreeRDP_KerberosKdc 1344 +#define FreeRDP_KerberosRealm 1345 +#define FreeRDP_IgnoreCertificate 1408 +#define FreeRDP_CertificateName 1409 +#define FreeRDP_CertificateFile 1410 +#define FreeRDP_PrivateKeyFile 1411 +#define FreeRDP_RdpKeyFile 1412 +#define FreeRDP_RdpServerRsaKey 1413 +#define FreeRDP_RdpServerCertificate 1414 +#define FreeRDP_Workarea 1536 +#define FreeRDP_Fullscreen 1537 +#define FreeRDP_PercentScreen 1538 +#define FreeRDP_GrabKeyboard 1539 +#define FreeRDP_Decorations 1540 +#define FreeRDP_MouseMotion 1541 +#define FreeRDP_WindowTitle 1542 +#define FreeRDP_ParentWindowId 1543 +#define FreeRDP_AsyncInput 1544 +#define FreeRDP_AsyncUpdate 1545 +#define FreeRDP_AsyncChannels 1546 +#define FreeRDP_AsyncTransport 1547 +#define FreeRDP_ToggleFullscreen 1548 +#define FreeRDP_WmClass 1549 +#define FreeRDP_EmbeddedWindow 1550 +#define FreeRDP_SmartSizing 1551 +#define FreeRDP_SoftwareGdi 1601 +#define FreeRDP_LocalConnection 1602 +#define FreeRDP_AuthenticationOnly 1603 +#define FreeRDP_CredentialsFromStdin 1604 +#define FreeRDP_ComputerName 1664 +#define FreeRDP_ConnectionFile 1728 +#define FreeRDP_HomePath 1792 +#define FreeRDP_ConfigPath 1793 +#define FreeRDP_CurrentPath 1794 +#define FreeRDP_DumpRemoteFx 1856 +#define FreeRDP_PlayRemoteFx 1857 +#define FreeRDP_DumpRemoteFxFile 1858 +#define FreeRDP_PlayRemoteFxFile 1859 +#define FreeRDP_GatewayUsageMethod 1984 +#define FreeRDP_GatewayPort 1985 +#define FreeRDP_GatewayHostname 1986 +#define FreeRDP_GatewayUsername 1987 +#define FreeRDP_GatewayPassword 1988 +#define FreeRDP_GatewayDomain 1989 +#define FreeRDP_GatewayCredentialsSource 1990 +#define FreeRDP_GatewayUseSameCredentials 1991 +#define FreeRDP_RemoteApplicationMode 2112 +#define FreeRDP_RemoteApplicationName 2113 +#define FreeRDP_RemoteApplicationIcon 2114 +#define FreeRDP_RemoteApplicationProgram 2115 +#define FreeRDP_RemoteApplicationFile 2116 +#define FreeRDP_RemoteApplicationGuid 2117 +#define FreeRDP_RemoteApplicationCmdLine 2118 +#define FreeRDP_RemoteApplicationExpandCmdLine 2119 +#define FreeRDP_RemoteApplicationExpandWorkingDir 2120 +#define FreeRDP_DisableRemoteAppCapsCheck 2121 +#define FreeRDP_RemoteAppNumIconCaches 2122 +#define FreeRDP_RemoteAppNumIconCacheEntries 2123 +#define FreeRDP_RemoteAppLanguageBarSupported 2124 +#define FreeRDP_ReceivedCapabilities 2240 +#define FreeRDP_ReceivedCapabilitiesSize 2241 +#define FreeRDP_OsMajorType 2304 +#define FreeRDP_OsMinorType 2305 +#define FreeRDP_RefreshRect 2306 +#define FreeRDP_SuppressOutput 2307 +#define FreeRDP_FastPathOutput 2308 +#define FreeRDP_SaltedChecksum 2309 +#define FreeRDP_LongCredentialsSupported 2310 +#define FreeRDP_NoBitmapCompressionHeader 2311 +#define FreeRDP_DesktopResize 2368 +#define FreeRDP_DrawAllowDynamicColorFidelity 2369 +#define FreeRDP_DrawAllowColorSubsampling 2370 +#define FreeRDP_DrawAllowSkipAlpha 2371 +#define FreeRDP_OrderSupport 2432 +#define FreeRDP_BitmapCacheV3Enabled 2433 +#define FreeRDP_AltSecFrameMarkerSupport 2434 +#define FreeRDP_BitmapCacheEnabled 2497 +#define FreeRDP_BitmapCacheVersion 2498 +#define FreeRDP_AllowCacheWaitingList 2499 +#define FreeRDP_BitmapCachePersistEnabled 2500 +#define FreeRDP_BitmapCacheV2NumCells 2501 +#define FreeRDP_BitmapCacheV2CellInfo 2502 +#define FreeRDP_ColorPointerFlag 2560 +#define FreeRDP_PointerCacheSize 2561 +#define FreeRDP_KeyboardLayout 2624 +#define FreeRDP_KeyboardType 2625 +#define FreeRDP_KeyboardSubType 2626 +#define FreeRDP_KeyboardFunctionKey 2627 +#define FreeRDP_ImeFileName 2628 +#define FreeRDP_UnicodeInput 2629 +#define FreeRDP_FastPathInput 2630 +#define FreeRDP_BrushSupportLevel 2688 +#define FreeRDP_GlyphSupportLevel 2752 +#define FreeRDP_GlyphCache 2753 +#define FreeRDP_FragCache 2754 +#define FreeRDP_OffscreenSupportLevel 2816 +#define FreeRDP_OffscreenCacheSize 2817 +#define FreeRDP_OffscreenCacheEntries 2818 +#define FreeRDP_VirtualChannelCompressionFlags 2880 +#define FreeRDP_VirtualChannelChunkSize 2881 +#define FreeRDP_SoundBeepsEnabled 2944 +#define FreeRDP_MultifragMaxRequestSize 3328 +#define FreeRDP_LargePointerFlag 3392 +#define FreeRDP_CompDeskSupportLevel 3456 +#define FreeRDP_SurfaceCommandsEnabled 3520 +#define FreeRDP_FrameMarkerCommandEnabled 3521 +#define FreeRDP_RemoteFxOnly 3648 +#define FreeRDP_RemoteFxCodec 3649 +#define FreeRDP_RemoteFxCodecId 3650 +#define FreeRDP_RemoteFxCodecMode 3651 +#define FreeRDP_RemoteFxImageCodec 3652 +#define FreeRDP_RemoteFxCaptureFlags 3653 +#define FreeRDP_NSCodec 3712 +#define FreeRDP_NSCodecId 3713 +#define FreeRDP_FrameAcknowledge 3714 +#define FreeRDP_JpegCodec 3776 +#define FreeRDP_JpegCodecId 3777 +#define FreeRDP_JpegQuality 3778 +#define FreeRDP_BitmapCacheV3CodecId 3904 +#define FreeRDP_DrawNineGridEnabled 3968 +#define FreeRDP_DrawNineGridCacheSize 3969 +#define FreeRDP_DrawNineGridCacheEntries 3970 +#define FreeRDP_DrawGdiPlusEnabled 4032 +#define FreeRDP_DrawGdiPlusCacheEnabled 4033 +#define FreeRDP_DeviceRedirection 4160 +#define FreeRDP_DeviceCount 4161 +#define FreeRDP_DeviceArraySize 4162 +#define FreeRDP_DeviceArray 4163 +#define FreeRDP_RedirectDrives 4288 +#define FreeRDP_RedirectHomeDrive 4289 +#define FreeRDP_DrivesToRedirect 4290 +#define FreeRDP_RedirectSmartCards 4416 +#define FreeRDP_RedirectPrinters 4544 +#define FreeRDP_RedirectSerialPorts 4672 +#define FreeRDP_RedirectParallelPorts 4673 +#define FreeRDP_RedirectClipboard 4800 +#define FreeRDP_StaticChannelCount 4928 +#define FreeRDP_StaticChannelArraySize 4929 +#define FreeRDP_StaticChannelArray 4930 +#define FreeRDP_DynamicChannelCount 5056 +#define FreeRDP_DynamicChannelArraySize 5057 +#define FreeRDP_DynamicChannelArray 5058 + +/** + * FreeRDP Settings Data Structure + */ + struct rdp_settings { /** @@ -486,7 +767,7 @@ struct rdp_settings ALIGN64 UINT32 ClientBuild; /* 133 */ ALIGN64 char* ClientHostname; /* 134 */ ALIGN64 char* ClientProductId; /* 135 */ - ALIGN64 UINT32 EarlyCapabilitiesFlag; /* 136 */ + ALIGN64 UINT32 EarlyCapabilityFlags; /* 136 */ ALIGN64 BOOL NetworkAutoDetect; /* 137 */ ALIGN64 BOOL SupportAsymetricKeys; /* 138 */ ALIGN64 BOOL SupportErrorInfoPdu; /* 139 */ @@ -681,8 +962,12 @@ struct rdp_settings ALIGN64 BOOL AsyncInput; /* 1544 */ ALIGN64 BOOL AsyncUpdate; /* 1545 */ ALIGN64 BOOL AsyncChannels; /* 1546 */ - ALIGN64 BOOL ToggleFullscreen; /* 1547 */ - UINT64 padding1600[1600 - 1548]; /* 1548 */ + ALIGN64 BOOL AsyncTransport; /* 1547 */ + ALIGN64 BOOL ToggleFullscreen; /* 1548 */ + ALIGN64 char* WmClass; /* 1549 */ + ALIGN64 BOOL EmbeddedWindow; /* 1550 */ + ALIGN64 BOOL SmartSizing; /* 1551 */ + UINT64 padding1600[1600 - 1552]; /* 1552 */ /* Miscellaneous */ ALIGN64 BOOL SoftwareGdi; /* 1601 */ @@ -877,7 +1162,8 @@ struct rdp_settings ALIGN64 UINT32 RemoteFxCodecId; /* 3650 */ ALIGN64 UINT32 RemoteFxCodecMode; /* 3651 */ ALIGN64 BOOL RemoteFxImageCodec; /* 3652 */ - UINT64 padding3712[3712 - 3653]; /* 3653 */ + ALIGN64 UINT32 RemoteFxCaptureFlags; /* 3653 */ + UINT64 padding3712[3712 - 3654]; /* 3654 */ /* NSCodec */ ALIGN64 BOOL NSCodec; /* 3712 */ @@ -912,61 +1198,67 @@ struct rdp_settings UINT64 padding4096[4096 - 4034]; /* 4034 */ UINT64 padding4160[4160 - 4096]; /* 4096 */ - /** - * WARNING: End of ABI stable zone! - * - * The zone below this point is ABI unstable, and - * is therefore potentially subject to ABI breakage. - */ - /** * Device Redirection */ /* Device Redirection */ - ALIGN64 BOOL DeviceRedirection; /* */ - ALIGN64 UINT32 DeviceCount; /* */ - ALIGN64 UINT32 DeviceArraySize; /* */ - ALIGN64 RDPDR_DEVICE** DeviceArray; /* */ + ALIGN64 BOOL DeviceRedirection; /* 4160 */ + ALIGN64 UINT32 DeviceCount; /* 4161 */ + ALIGN64 UINT32 DeviceArraySize; /* 4162 */ + ALIGN64 RDPDR_DEVICE** DeviceArray; /* 4163 */ + UINT64 padding4288[4288 - 4164]; /* 4164 */ /* Drive Redirection */ - ALIGN64 BOOL RedirectDrives; /* */ - ALIGN64 BOOL RedirectHomeDrive; /* */ - ALIGN64 char* DrivesToRedirect; /* */ + ALIGN64 BOOL RedirectDrives; /* 4288 */ + ALIGN64 BOOL RedirectHomeDrive; /* 4289 */ + ALIGN64 char* DrivesToRedirect; /* 4290 */ + UINT64 padding4416[4416 - 4291]; /* 4291 */ /* Smartcard Redirection */ - ALIGN64 BOOL RedirectSmartCards; /* */ + ALIGN64 BOOL RedirectSmartCards; /* 4416 */ + UINT64 padding4544[4544 - 4417]; /* 4417 */ /* Printer Redirection */ - ALIGN64 BOOL RedirectPrinters; /* */ + ALIGN64 BOOL RedirectPrinters; /* 4544 */ + UINT64 padding4672[4672 - 4545]; /* 4545 */ - /* Serial Port Redirection */ - ALIGN64 BOOL RedirectSerialPorts; /* */ - - /* Parallel Port Redirection */ - ALIGN64 BOOL RedirectParallelPorts; /* */ + /* Serial and Parallel Port Redirection */ + ALIGN64 BOOL RedirectSerialPorts; /* 4672 */ + ALIGN64 BOOL RedirectParallelPorts; /* 4673 */ + UINT64 padding4800[4800 - 4674]; /* 4674 */ /** * Other Redirection */ - ALIGN64 BOOL RedirectClipboard; /* */ + ALIGN64 BOOL RedirectClipboard; /* 4800 */ + UINT64 padding4928[4928 - 4801]; /* 4801 */ /** * Static Virtual Channels */ - ALIGN64 UINT32 StaticChannelCount; - ALIGN64 UINT32 StaticChannelArraySize; - ALIGN64 ADDIN_ARGV** StaticChannelArray; + ALIGN64 UINT32 StaticChannelCount; /* 4928 */ + ALIGN64 UINT32 StaticChannelArraySize; /* 4929 */ + ALIGN64 ADDIN_ARGV** StaticChannelArray; /* 4930 */ + UINT64 padding5056[5056 - 4931]; /* 4931 */ /** * Dynamic Virtual Channels */ - ALIGN64 UINT32 DynamicChannelCount; - ALIGN64 UINT32 DynamicChannelArraySize; - ALIGN64 ADDIN_ARGV** DynamicChannelArray; + ALIGN64 UINT32 DynamicChannelCount; /* 5056 */ + ALIGN64 UINT32 DynamicChannelArraySize; /* 5057 */ + ALIGN64 ADDIN_ARGV** DynamicChannelArray; /* 5058 */ + UINT64 padding5184[5184 - 5059]; /* 5059 */ + + /** + * WARNING: End of ABI stable zone! + * + * The zone below this point is ABI unstable, and + * is therefore potentially subject to ABI breakage. + */ /* * Extensions @@ -1002,6 +1294,18 @@ FREERDP_API void freerdp_dynamic_channel_collection_add(rdpSettings* settings, A FREERDP_API ADDIN_ARGV* freerdp_dynamic_channel_collection_find(rdpSettings* settings, const char* name); FREERDP_API void freerdp_dynamic_channel_collection_free(rdpSettings* settings); +FREERDP_API BOOL freerdp_get_param_bool(rdpSettings* settings, int id); +FREERDP_API int freerdp_set_param_bool(rdpSettings* settings, int id, BOOL param); + +FREERDP_API UINT32 freerdp_get_param_uint32(rdpSettings* settings, int id); +FREERDP_API int freerdp_set_param_uint32(rdpSettings* settings, int id, UINT32 param); + +FREERDP_API UINT64 freerdp_get_param_uint64(rdpSettings* settings, int id); +FREERDP_API int freerdp_set_param_uint64(rdpSettings* settings, int id, UINT64 param); + +FREERDP_API char* freerdp_get_param_string(rdpSettings* settings, int id); +FREERDP_API int freerdp_set_param_string(rdpSettings* settings, int id, char* param); + #ifdef __cplusplus } #endif diff --git a/include/freerdp/svc.h b/include/freerdp/svc.h index 1f4fcd7ae..c09307fd9 100644 --- a/include/freerdp/svc.h +++ b/include/freerdp/svc.h @@ -42,48 +42,43 @@ typedef struct _CHANNEL_DEF CHANNEL_DEF; typedef CHANNEL_DEF* PCHANNEL_DEF; typedef CHANNEL_DEF** PPCHANNEL_DEF; -typedef void (FREERDP_CC * PCHANNEL_INIT_EVENT_FN)(void* pInitHandle, - UINT32 event, void* pData, UINT32 dataLength); +typedef void (FREERDP_CC * PCHANNEL_INIT_EVENT_FN)(void* pInitHandle, UINT32 event, void* pData, UINT32 dataLength); +typedef void (FREERDP_CC * PCHANNEL_OPEN_EVENT_FN)(UINT32 openHandle, UINT32 event, + void* pData, UINT32 dataLength, UINT32 totalLength, UINT32 dataFlags); -typedef void (FREERDP_CC * PCHANNEL_OPEN_EVENT_FN)(UINT32 openHandle, - UINT32 event, void* pData, UINT32 dataLength, - UINT32 totalLength, UINT32 dataFlags); +#define CHANNEL_RC_OK 0 +#define CHANNEL_RC_ALREADY_INITIALIZED 1 +#define CHANNEL_RC_NOT_INITIALIZED 2 +#define CHANNEL_RC_ALREADY_CONNECTED 3 +#define CHANNEL_RC_NOT_CONNECTED 4 +#define CHANNEL_RC_TOO_MANY_CHANNELS 5 +#define CHANNEL_RC_BAD_CHANNEL 6 +#define CHANNEL_RC_BAD_CHANNEL_HANDLE 7 +#define CHANNEL_RC_NO_BUFFER 8 +#define CHANNEL_RC_BAD_INIT_HANDLE 9 +#define CHANNEL_RC_NOT_OPEN 10 +#define CHANNEL_RC_BAD_PROC 11 +#define CHANNEL_RC_NO_MEMORY 12 +#define CHANNEL_RC_UNKNOWN_CHANNEL_NAME 13 +#define CHANNEL_RC_ALREADY_OPEN 14 +#define CHANNEL_RC_NOT_IN_VIRTUALCHANNELENTRY 15 +#define CHANNEL_RC_NULL_DATA 16 +#define CHANNEL_RC_ZERO_LENGTH 17 -#define CHANNEL_RC_OK 0 -#define CHANNEL_RC_ALREADY_INITIALIZED 1 -#define CHANNEL_RC_NOT_INITIALIZED 2 -#define CHANNEL_RC_ALREADY_CONNECTED 3 -#define CHANNEL_RC_NOT_CONNECTED 4 -#define CHANNEL_RC_TOO_MANY_CHANNELS 5 -#define CHANNEL_RC_BAD_CHANNEL 6 -#define CHANNEL_RC_BAD_CHANNEL_HANDLE 7 -#define CHANNEL_RC_NO_BUFFER 8 -#define CHANNEL_RC_BAD_INIT_HANDLE 9 -#define CHANNEL_RC_NOT_OPEN 10 -#define CHANNEL_RC_BAD_PROC 11 -#define CHANNEL_RC_NO_MEMORY 12 -#define CHANNEL_RC_UNKNOWN_CHANNEL_NAME 13 -#define CHANNEL_RC_ALREADY_OPEN 14 -#define CHANNEL_RC_NOT_IN_VIRTUALCHANNELENTRY 15 -#define CHANNEL_RC_NULL_DATA 16 -#define CHANNEL_RC_ZERO_LENGTH 17 +#define VIRTUAL_CHANNEL_VERSION_WIN2000 1 -#define VIRTUAL_CHANNEL_VERSION_WIN2000 1 +typedef UINT32 (FREERDP_CC * PVIRTUALCHANNELINIT)(void** ppInitHandle, PCHANNEL_DEF pChannel, + int channelCount, UINT32 versionRequested, PCHANNEL_INIT_EVENT_FN pChannelInitEventProc); + +typedef UINT32 (FREERDP_CC * PVIRTUALCHANNELOPEN)(void* pInitHandle, UINT32* pOpenHandle, + char* pChannelName, PCHANNEL_OPEN_EVENT_FN pChannelOpenEventProc); -typedef UINT32 (FREERDP_CC * PVIRTUALCHANNELINIT)(void** ppInitHandle, - PCHANNEL_DEF pChannel, int channelCount, UINT32 versionRequested, - PCHANNEL_INIT_EVENT_FN pChannelInitEventProc); -typedef UINT32 (FREERDP_CC * PVIRTUALCHANNELOPEN)(void* pInitHandle, - UINT32* pOpenHandle, char* pChannelName, - PCHANNEL_OPEN_EVENT_FN pChannelOpenEventProc); typedef UINT32 (FREERDP_CC * PVIRTUALCHANNELCLOSE)(UINT32 openHandle); -typedef UINT32 (FREERDP_CC * PVIRTUALCHANNELWRITE)(UINT32 openHandle, - void* pData, UINT32 dataLength, void* pUserData); +typedef UINT32 (FREERDP_CC * PVIRTUALCHANNELWRITE)(UINT32 openHandle, void* pData, UINT32 dataLength, void* pUserData); -typedef UINT32 (FREERDP_CC * PVIRTUALCHANNELEVENTPUSH)(UINT32 openHandle, - RDP_EVENT* event); +typedef UINT32 (FREERDP_CC * PVIRTUALCHANNELEVENTPUSH)(UINT32 openHandle, wMessage* event); struct _CHANNEL_ENTRY_POINTS { @@ -107,7 +102,11 @@ struct _CHANNEL_ENTRY_POINTS_EX PVIRTUALCHANNELOPEN pVirtualChannelOpen; PVIRTUALCHANNELCLOSE pVirtualChannelClose; PVIRTUALCHANNELWRITE pVirtualChannelWrite; - void* pExtendedData; /* extended data field to pass initial parameters */ + + /* Extended Fields */ + + void* pExtendedData; /* extended initial data */ + void* pInterface; /* channel callback interface */ PVIRTUALCHANNELEVENTPUSH pVirtualChannelEventPush; }; typedef struct _CHANNEL_ENTRY_POINTS_EX CHANNEL_ENTRY_POINTS_EX; diff --git a/include/freerdp/types.h b/include/freerdp/types.h index e36bea56a..2a1ce9162 100644 --- a/include/freerdp/types.h +++ b/include/freerdp/types.h @@ -59,24 +59,8 @@ struct _RECTANGLE_16 typedef struct _RECTANGLE_16 RECTANGLE_16; /* Plugin events */ -typedef struct _RDP_EVENT RDP_EVENT; -typedef void (*RDP_EVENT_CALLBACK) (RDP_EVENT* event); - -struct _RDP_EVENT -{ - UINT16 event_class; - UINT16 event_type; - RDP_EVENT_CALLBACK on_event_free_callback; - void* user_data; -}; - -enum RDP_EVENT_CLASS -{ - RDP_EVENT_CLASS_DEBUG = 0, - RDP_EVENT_CLASS_CLIPRDR, - RDP_EVENT_CLASS_TSMF, - RDP_EVENT_CLASS_RAIL -}; +#include <freerdp/message.h> +#include <winpr/collections.h> #endif /* __RDP_TYPES_H */ diff --git a/include/freerdp/update.h b/include/freerdp/update.h index ba2b9d9b6..047a4ec17 100644 --- a/include/freerdp/update.h +++ b/include/freerdp/update.h @@ -25,6 +25,7 @@ typedef struct rdp_update rdpUpdate; #include <winpr/crt.h> #include <winpr/synch.h> #include <winpr/thread.h> +#include <winpr/stream.h> #include <winpr/collections.h> #include <freerdp/rail.h> @@ -32,7 +33,6 @@ typedef struct rdp_update rdpUpdate; #include <freerdp/freerdp.h> #include <freerdp/graphics.h> #include <freerdp/utils/pcap.h> -#include <freerdp/utils/stream.h> #include <freerdp/primary.h> #include <freerdp/secondary.h> @@ -152,7 +152,7 @@ typedef void (*pPlaySound)(rdpContext* context, PLAY_SOUND_UPDATE* play_sound); typedef void (*pRefreshRect)(rdpContext* context, BYTE count, RECTANGLE_16* areas); typedef void (*pSuppressOutput)(rdpContext* context, BYTE allow, RECTANGLE_16* area); -typedef void (*pSurfaceCommand)(rdpContext* context, STREAM* s); +typedef void (*pSurfaceCommand)(rdpContext* context, wStream* s); typedef void (*pSurfaceBits)(rdpContext* context, SURFACE_BITS_COMMAND* surface_bits_command); typedef void (*pSurfaceFrameMarker)(rdpContext* context, SURFACE_FRAME_MARKER* surface_frame_marker); typedef void (*pSurfaceFrameAcknowledge)(rdpContext* context, UINT32 frameId); diff --git a/include/freerdp/utils/debug.h b/include/freerdp/utils/debug.h index 1e51c5428..eb6b61301 100644 --- a/include/freerdp/utils/debug.h +++ b/include/freerdp/utils/debug.h @@ -23,7 +23,7 @@ #include <stdio.h> #define DEBUG_NULL(fmt, ...) do { } while (0) -#define DEBUG_PRINT(_dbg_str, fmt, ...) printf(_dbg_str fmt "\n" , __FUNCTION__, __LINE__, ## __VA_ARGS__) +#define DEBUG_PRINT(_dbg_str, fmt, ...) fprintf(stderr, _dbg_str fmt "\n" , __FUNCTION__, __LINE__, ## __VA_ARGS__) #define DEBUG_CLASS(_dbg_class, fmt, ...) DEBUG_PRINT("DBG_" #_dbg_class " %s (%d): ", fmt, ## __VA_ARGS__) #define DEBUG_WARN(fmt, ...) DEBUG_PRINT("Warning %s (%d): ", fmt, ## __VA_ARGS__) diff --git a/include/freerdp/utils/event.h b/include/freerdp/utils/event.h index 1e0c98595..2b4440da3 100644 --- a/include/freerdp/utils/event.h +++ b/include/freerdp/utils/event.h @@ -27,9 +27,9 @@ extern "C" { #endif -FREERDP_API RDP_EVENT* freerdp_event_new(UINT16 event_class, UINT16 event_type, - RDP_EVENT_CALLBACK on_event_free_callback, void* user_data); -FREERDP_API void freerdp_event_free(RDP_EVENT* event); +FREERDP_API wMessage* freerdp_event_new(UINT16 event_class, UINT16 event_type, + MESSAGE_FREE_FN on_event_free_callback, void* user_data); +FREERDP_API void freerdp_event_free(wMessage* event); #ifdef __cplusplus } diff --git a/include/freerdp/utils/file.h b/include/freerdp/utils/file.h deleted file mode 100644 index 45198e4b1..000000000 --- a/include/freerdp/utils/file.h +++ /dev/null @@ -1,46 +0,0 @@ -/** - * FreeRDP: A Remote Desktop Protocol Implementation - * File Utils - * - * Copyright 2011 Marc-Andre Moreau <marcandre.moreau@gmail.com> - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef FREERDP_UTILS_FILE_H -#define FREERDP_UTILS_FILE_H - -#include <freerdp/api.h> -#include <freerdp/types.h> -#include <freerdp/settings.h> - -#ifdef __cplusplus -extern "C" { -#endif - -FREERDP_API void freerdp_mkdir(char* path); -FREERDP_API BOOL freerdp_check_file_exists(char* file); -FREERDP_API char* freerdp_get_home_path(rdpSettings* settings); -FREERDP_API char* freerdp_get_config_path(rdpSettings* settings); -FREERDP_API char* freerdp_get_current_path(rdpSettings* settings); -FREERDP_API char* freerdp_construct_path(char* base_path, char* relative_path); -FREERDP_API char* freerdp_append_shared_library_suffix(char* file_path); -FREERDP_API char* freerdp_get_parent_path(char* base_path, int depth); -FREERDP_API BOOL freerdp_path_contains_separator(char* path); -FREERDP_API void freerdp_detect_paths(rdpSettings* settings); - -#ifdef __cplusplus -} -#endif - -#endif /* FREERDP_UTILS_FILE_H */ diff --git a/include/freerdp/utils/msusb.h b/include/freerdp/utils/msusb.h index f5ce47d2a..01af385ad 100644 --- a/include/freerdp/utils/msusb.h +++ b/include/freerdp/utils/msusb.h @@ -24,7 +24,7 @@ #include <freerdp/api.h> #include <freerdp/types.h> -#include <freerdp/utils/stream.h> +#include <winpr/stream.h> /* a safer free helper */ #define zfree(p) do { if (p != NULL) {free(p); p = NULL;} } while (0) diff --git a/include/freerdp/utils/rail.h b/include/freerdp/utils/rail.h index 80f7f6746..7944538c2 100644 --- a/include/freerdp/utils/rail.h +++ b/include/freerdp/utils/rail.h @@ -22,7 +22,8 @@ #include <freerdp/api.h> #include <freerdp/rail.h> -#include <freerdp/utils/stream.h> + +#include <winpr/stream.h> #ifdef __cplusplus extern "C" { @@ -30,9 +31,9 @@ extern "C" { FREERDP_API void rail_unicode_string_alloc(RAIL_UNICODE_STRING* unicode_string, UINT16 cbString); FREERDP_API void rail_unicode_string_free(RAIL_UNICODE_STRING* unicode_string); -FREERDP_API BOOL rail_read_unicode_string(STREAM* s, RAIL_UNICODE_STRING* unicode_string); -FREERDP_API void rail_write_unicode_string(STREAM* s, RAIL_UNICODE_STRING* unicode_string); -FREERDP_API void rail_write_unicode_string_value(STREAM* s, RAIL_UNICODE_STRING* unicode_string); +FREERDP_API BOOL rail_read_unicode_string(wStream* s, RAIL_UNICODE_STRING* unicode_string); +FREERDP_API void rail_write_unicode_string(wStream* s, RAIL_UNICODE_STRING* unicode_string); +FREERDP_API void rail_write_unicode_string_value(wStream* s, RAIL_UNICODE_STRING* unicode_string); FREERDP_API void* rail_clone_order(UINT32 event_type, void* order); FREERDP_API void rail_free_cloned_order(UINT32 event_type, void* order); diff --git a/include/freerdp/utils/stream.h b/include/freerdp/utils/stream.h deleted file mode 100644 index 8e004eae8..000000000 --- a/include/freerdp/utils/stream.h +++ /dev/null @@ -1,191 +0,0 @@ -/** - * FreeRDP: A Remote Desktop Protocol Implementation - * Stream Utils - * - * Copyright 2009-2011 Jay Sorg - * Copyright 2011 Vic Lee - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef FREERDP_UTILS_STREAM_H -#define FREERDP_UTILS_STREAM_H - -#include <string.h> -#include <freerdp/api.h> -#include <freerdp/types.h> - -struct _STREAM -{ - int size; - BYTE* p; - BYTE* data; -}; -typedef struct _STREAM STREAM; - -#ifdef __cplusplus -extern "C" { -#endif - -FREERDP_API STREAM* stream_new(int size); -FREERDP_API void stream_free(STREAM* stream); - -#define stream_attach(_s, _buf, _size) do { \ - _s->size = _size; \ - _s->data = _buf; \ - _s->p = _buf; } while (0) -#define stream_detach(_s) memset(_s, 0, sizeof(STREAM)) -#define stream_clear(_s) memset(_s->data, 0, _s->size) - -FREERDP_API void stream_extend(STREAM* stream, int request_size); -#define stream_check_size(_s, _n) \ - while (_s->p - _s->data + (_n) > _s->size) \ - stream_extend(_s, _n) - -#define stream_get_pos(_s) (_s->p - _s->data) -#define stream_set_pos(_s,_m) _s->p = _s->data + (_m) -#define stream_seek(_s,_offset) _s->p += (_offset) -#define stream_rewind(_s,_offset) _s->p -= (_offset) -#define stream_seal(_s) _s->size = (_s->p - _s->data) -#define stream_get_mark(_s,_mark) _mark = _s->p -#define stream_set_mark(_s,_mark) _s->p = _mark -#define stream_get_head(_s) _s->data -#define stream_get_tail(_s) _s->p -#define stream_get_length(_s) (_s->p - _s->data) -#define stream_get_data(_s) (_s->data) -#define stream_get_size(_s) (_s->size) -#define stream_get_left(_s) (_s->size - (_s->p - _s->data)) - -#define stream_read_BYTE(_s, _v) do { _v = *_s->p++; } while (0) -#define stream_read_UINT16(_s, _v) do { _v = \ - (UINT16)(*_s->p) + \ - (UINT16)(((UINT16)(*(_s->p + 1))) << 8); \ - _s->p += 2; } while (0) -#define stream_read_UINT32(_s, _v) do { _v = \ - (UINT32)(*_s->p) + \ - (((UINT32)(*(_s->p + 1))) << 8) + \ - (((UINT32)(*(_s->p + 2))) << 16) + \ - (((UINT32)(*(_s->p + 3))) << 24); \ - _s->p += 4; } while (0) -#define stream_read_UINT64(_s, _v) do { _v = \ - (UINT64)(*_s->p) + \ - (((UINT64)(*(_s->p + 1))) << 8) + \ - (((UINT64)(*(_s->p + 2))) << 16) + \ - (((UINT64)(*(_s->p + 3))) << 24) + \ - (((UINT64)(*(_s->p + 4))) << 32) + \ - (((UINT64)(*(_s->p + 5))) << 40) + \ - (((UINT64)(*(_s->p + 6))) << 48) + \ - (((UINT64)(*(_s->p + 7))) << 56); \ - _s->p += 8; } while (0) -#define stream_read(_s, _b, _n) do { \ - memcpy(_b, (_s->p), (_n)); \ - _s->p += (_n); \ - } while (0) - -#define stream_write_BYTE(_s, _v) do { \ - *_s->p++ = (BYTE)(_v); } while (0) -#define stream_write_UINT16(_s, _v) do { \ - *_s->p++ = (_v) & 0xFF; \ - *_s->p++ = ((_v) >> 8) & 0xFF; } while (0) -#define stream_write_UINT32(_s, _v) do { \ - *_s->p++ = (_v) & 0xFF; \ - *_s->p++ = ((_v) >> 8) & 0xFF; \ - *_s->p++ = ((_v) >> 16) & 0xFF; \ - *_s->p++ = ((_v) >> 24) & 0xFF; } while (0) -#define stream_write_UINT64(_s, _v) do { \ - *_s->p++ = (UINT64)(_v) & 0xFF; \ - *_s->p++ = ((UINT64)(_v) >> 8) & 0xFF; \ - *_s->p++ = ((UINT64)(_v) >> 16) & 0xFF; \ - *_s->p++ = ((UINT64)(_v) >> 24) & 0xFF; \ - *_s->p++ = ((UINT64)(_v) >> 32) & 0xFF; \ - *_s->p++ = ((UINT64)(_v) >> 40) & 0xFF; \ - *_s->p++ = ((UINT64)(_v) >> 48) & 0xFF; \ - *_s->p++ = ((UINT64)(_v) >> 56) & 0xFF; } while (0) -#define stream_write(_s, _b, _n) do { \ - memcpy(_s->p, (_b), (_n)); \ - _s->p += (_n); \ - } while (0) -#define stream_write_zero(_s, _n) do { \ - memset(_s->p, '\0', (_n)); \ - _s->p += (_n); \ - } while (0) -#define stream_set_byte(_s, _v, _n) do { \ - memset(_s->p, _v, (_n)); \ - _s->p += (_n); \ - } while (0) - -#define stream_peek_BYTE(_s, _v) do { _v = *_s->p; } while (0) -#define stream_peek_UINT16(_s, _v) do { _v = \ - (UINT16)(*_s->p) + \ - (((UINT16)(*(_s->p + 1))) << 8); \ - } while (0) -#define stream_peek_UINT32(_s, _v) do { _v = \ - (UINT32)(*_s->p) + \ - (((UINT32)(*(_s->p + 1))) << 8) + \ - (((UINT32)(*(_s->p + 2))) << 16) + \ - (((UINT32)(*(_s->p + 3))) << 24); \ - } while (0) -#define stream_peek_UINT64(_s, _v) do { _v = \ - (UINT64)(*_s->p) + \ - (((UINT64)(*(_s->p + 1))) << 8) + \ - (((UINT64)(*(_s->p + 2))) << 16) + \ - (((UINT64)(*(_s->p + 3))) << 24) + \ - (((UINT64)(*(_s->p + 4))) << 32) + \ - (((UINT64)(*(_s->p + 5))) << 40) + \ - (((UINT64)(*(_s->p + 6))) << 48) + \ - (((UINT64)(*(_s->p + 7))) << 56); \ - } while (0) - -#define stream_seek_BYTE(_s) stream_seek(_s, 1) -#define stream_seek_UINT16(_s) stream_seek(_s, 2) -#define stream_seek_UINT32(_s) stream_seek(_s, 4) -#define stream_seek_UINT64(_s) stream_seek(_s, 8) - -#define stream_read_UINT16_be(_s, _v) do { _v = \ - (((UINT16)(*_s->p)) << 8) + \ - (UINT16)(*(_s->p + 1)); \ - _s->p += 2; } while (0) -#define stream_read_UINT32_be(_s, _v) do { _v = \ - (((UINT32)(*(_s->p))) << 24) + \ - (((UINT32)(*(_s->p + 1))) << 16) + \ - (((UINT32)(*(_s->p + 2))) << 8) + \ - (((UINT32)(*(_s->p + 3)))); \ - _s->p += 4; } while (0) - -#define stream_write_UINT16_be(_s, _v) do { \ - *_s->p++ = ((_v) >> 8) & 0xFF; \ - *_s->p++ = (_v) & 0xFF; } while (0) -#define stream_write_UINT32_be(_s, _v) do { \ - stream_write_UINT16_be(_s, ((_v) >> 16 & 0xFFFF)); \ - stream_write_UINT16_be(_s, ((_v) & 0xFFFF)); \ - } while (0) - -#define stream_copy(_dst, _src, _n) do { \ - memcpy(_dst->p, _src->p, _n); \ - _dst->p += _n; \ - _src->p += _n; \ - } while (0) - -static INLINE BOOL stream_skip(STREAM* s, int sz) { - if (stream_get_left(s) < sz) - return FALSE; - stream_seek(s, sz); - return TRUE; -} - -#ifdef __cplusplus -} -#endif - -#endif /* FREERDP_UTILS_STREAM_H */ - diff --git a/include/freerdp/utils/svc_plugin.h b/include/freerdp/utils/svc_plugin.h index ca792f8e7..7feeb7f7f 100644 --- a/include/freerdp/utils/svc_plugin.h +++ b/include/freerdp/utils/svc_plugin.h @@ -30,11 +30,11 @@ #include <winpr/crt.h> #include <winpr/synch.h> #include <winpr/thread.h> +#include <winpr/stream.h> #include <winpr/collections.h> #include <freerdp/utils/debug.h> #include <freerdp/utils/event.h> -#include <freerdp/utils/stream.h> typedef struct rdp_svc_plugin rdpSvcPlugin; @@ -44,12 +44,12 @@ struct rdp_svc_plugin CHANNEL_DEF channel_def; void (*connect_callback)(rdpSvcPlugin* plugin); - void (*receive_callback)(rdpSvcPlugin* plugin, STREAM* data_in); - void (*event_callback)(rdpSvcPlugin* plugin, RDP_EVENT* event); + void (*receive_callback)(rdpSvcPlugin* plugin, wStream* data_in); + void (*event_callback)(rdpSvcPlugin* plugin, wMessage* event); void (*terminate_callback)(rdpSvcPlugin* plugin); HANDLE thread; - STREAM* data_in; + wStream* data_in; void* init_handle; UINT32 open_handle; wMessagePipe* MsgPipe; @@ -60,8 +60,8 @@ extern "C" { #endif FREERDP_API void svc_plugin_init(rdpSvcPlugin* plugin, CHANNEL_ENTRY_POINTS* pEntryPoints); -FREERDP_API int svc_plugin_send(rdpSvcPlugin* plugin, STREAM* data_out); -FREERDP_API int svc_plugin_send_event(rdpSvcPlugin* plugin, RDP_EVENT* event); +FREERDP_API int svc_plugin_send(rdpSvcPlugin* plugin, wStream* data_out); +FREERDP_API int svc_plugin_send_event(rdpSvcPlugin* plugin, wMessage* event); #ifdef __cplusplus } diff --git a/include/freerdp/utils/thread.h b/include/freerdp/utils/thread.h deleted file mode 100644 index 4d21b493e..000000000 --- a/include/freerdp/utils/thread.h +++ /dev/null @@ -1,69 +0,0 @@ -/** - * FreeRDP: A Remote Desktop Protocol Implementation - * Thread Utils - * - * Copyright 2011 Vic Lee - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef FREERDP_UTILS_THREAD_H -#define FREERDP_UTILS_THREAD_H - -#include <freerdp/api.h> -#include <freerdp/types.h> - -#ifndef _WIN32 -#include <pthread.h> -#endif - -#include <winpr/synch.h> - -typedef struct _freerdp_thread freerdp_thread; - -struct _freerdp_thread -{ - HANDLE mutex; - - HANDLE signals[5]; - int num_signals; - - int status; -}; - -#ifdef __cplusplus -extern "C" { -#endif - -FREERDP_API freerdp_thread* freerdp_thread_new(void); -FREERDP_API void freerdp_thread_start(freerdp_thread* thread, void* func, void* arg); -FREERDP_API void freerdp_thread_stop(freerdp_thread* thread); -FREERDP_API void freerdp_thread_free(freerdp_thread* thread); - -#ifdef __cplusplus -} -#endif - -#define freerdp_thread_wait(_t) ((WaitForMultipleObjects(_t->num_signals, _t->signals, FALSE, INFINITE) == WAIT_FAILED) ? -1 : 0) -#define freerdp_thread_wait_timeout(_t, _timeout) ((WaitForMultipleObjects(_t->num_signals, _t->signals, FALSE, _timeout) == WAIT_FAILED) ? -1 : 0) -#define freerdp_thread_is_stopped(_t) (WaitForSingleObject(_t->signals[0], 0) == WAIT_OBJECT_0) -#define freerdp_thread_is_running(_t) (_t->status == 1) -#define freerdp_thread_quit(_t) do { \ - _t->status = -1; \ - ResetEvent(_t->signals[0]); } while (0) -#define freerdp_thread_signal(_t) SetEvent(_t->signals[1]) -#define freerdp_thread_reset(_t) ResetEvent(_t->signals[1]) -#define freerdp_thread_lock(_t) WaitForSingleObject(_t->mutex, INFINITE) -#define freerdp_thread_unlock(_t) ReleaseMutex(_t->mutex) - -#endif /* FREERDP_UTILS_THREAD_H */ diff --git a/include/freerdp/window.h b/include/freerdp/window.h index 94fa5c174..3357d89bd 100644 --- a/include/freerdp/window.h +++ b/include/freerdp/window.h @@ -120,6 +120,13 @@ #define WS_EX_WINDOWEDGE 0x00000100 #endif +/** + * This is a custom extended window style used by XRDP + * instructing the client to use local window decorations + */ + +#define WS_EX_DECORATIONS 0x40000000 + struct _WINDOW_ORDER_INFO { UINT32 windowId; diff --git a/libfreerdp/cache/bitmap.c b/libfreerdp/cache/bitmap.c index 2ed6bfaa3..a1136a08a 100644 --- a/libfreerdp/cache/bitmap.c +++ b/libfreerdp/cache/bitmap.c @@ -27,7 +27,7 @@ #include <freerdp/freerdp.h> #include <freerdp/constants.h> -#include <freerdp/utils/stream.h> +#include <winpr/stream.h> #include <freerdp/cache/bitmap.h> @@ -211,7 +211,7 @@ rdpBitmap* bitmap_cache_get(rdpBitmapCache* bitmap_cache, UINT32 id, UINT32 inde if (id > bitmap_cache->maxCells) { - printf("get invalid bitmap cell id: %d\n", id); + fprintf(stderr, "get invalid bitmap cell id: %d\n", id); return NULL; } @@ -221,7 +221,7 @@ rdpBitmap* bitmap_cache_get(rdpBitmapCache* bitmap_cache, UINT32 id, UINT32 inde } else if (index > bitmap_cache->cells[id].number) { - printf("get invalid bitmap index %d in cell id: %d\n", index, id); + fprintf(stderr, "get invalid bitmap index %d in cell id: %d\n", index, id); return NULL; } @@ -234,7 +234,7 @@ void bitmap_cache_put(rdpBitmapCache* bitmap_cache, UINT32 id, UINT32 index, rdp { if (id > bitmap_cache->maxCells) { - printf("put invalid bitmap cell id: %d\n", id); + fprintf(stderr, "put invalid bitmap cell id: %d\n", id); return; } @@ -244,7 +244,7 @@ void bitmap_cache_put(rdpBitmapCache* bitmap_cache, UINT32 id, UINT32 index, rdp } else if (index > bitmap_cache->cells[id].number) { - printf("put invalid bitmap index %d in cell id: %d\n", index, id); + fprintf(stderr, "put invalid bitmap index %d in cell id: %d\n", index, id); return; } diff --git a/libfreerdp/cache/brush.c b/libfreerdp/cache/brush.c index fa8464af7..8b991a395 100644 --- a/libfreerdp/cache/brush.c +++ b/libfreerdp/cache/brush.c @@ -27,7 +27,7 @@ #include <freerdp/update.h> #include <freerdp/freerdp.h> -#include <freerdp/utils/stream.h> +#include <winpr/stream.h> #include <freerdp/cache/brush.h> @@ -95,7 +95,7 @@ void* brush_cache_get(rdpBrushCache* brush, UINT32 index, UINT32* bpp) { if (index >= brush->maxMonoEntries) { - printf("invalid brush (%d bpp) index: 0x%04X\n", *bpp, index); + fprintf(stderr, "invalid brush (%d bpp) index: 0x%04X\n", *bpp, index); return NULL; } @@ -106,7 +106,7 @@ void* brush_cache_get(rdpBrushCache* brush, UINT32 index, UINT32* bpp) { if (index >= brush->maxEntries) { - printf("invalid brush (%d bpp) index: 0x%04X\n", *bpp, index); + fprintf(stderr, "invalid brush (%d bpp) index: 0x%04X\n", *bpp, index); return NULL; } @@ -116,7 +116,7 @@ void* brush_cache_get(rdpBrushCache* brush, UINT32 index, UINT32* bpp) if (entry == NULL) { - printf("invalid brush (%d bpp) at index: 0x%04X\n", *bpp, index); + fprintf(stderr, "invalid brush (%d bpp) at index: 0x%04X\n", *bpp, index); return NULL; } @@ -131,7 +131,7 @@ void brush_cache_put(rdpBrushCache* brush, UINT32 index, void* entry, UINT32 bpp { if (index >= brush->maxMonoEntries) { - printf("invalid brush (%d bpp) index: 0x%04X\n", bpp, index); + fprintf(stderr, "invalid brush (%d bpp) index: 0x%04X\n", bpp, index); return; } @@ -147,7 +147,7 @@ void brush_cache_put(rdpBrushCache* brush, UINT32 index, void* entry, UINT32 bpp { if (index >= brush->maxEntries) { - printf("invalid brush (%d bpp) index: 0x%04X\n", bpp, index); + fprintf(stderr, "invalid brush (%d bpp) index: 0x%04X\n", bpp, index); return; } diff --git a/libfreerdp/cache/cache.c b/libfreerdp/cache/cache.c index a4e47d1d2..bc6563f17 100644 --- a/libfreerdp/cache/cache.c +++ b/libfreerdp/cache/cache.c @@ -23,7 +23,7 @@ #include <winpr/crt.h> -#include <freerdp/utils/stream.h> +#include <winpr/stream.h> #include <freerdp/cache/cache.h> diff --git a/libfreerdp/cache/glyph.c b/libfreerdp/cache/glyph.c index 7b56ed29b..847ac3849 100644 --- a/libfreerdp/cache/glyph.c +++ b/libfreerdp/cache/glyph.c @@ -26,7 +26,7 @@ #include <winpr/crt.h> #include <freerdp/freerdp.h> -#include <freerdp/utils/stream.h> +#include <winpr/stream.h> #include <freerdp/cache/glyph.h> @@ -362,13 +362,13 @@ rdpGlyph* glyph_cache_get(rdpGlyphCache* glyph_cache, UINT32 id, UINT32 index) if (id > 9) { - printf("invalid glyph cache id: %d\n", id); + fprintf(stderr, "invalid glyph cache id: %d\n", id); return NULL; } if (index > glyph_cache->glyphCache[id].number) { - printf("invalid glyph cache index: %d in cache id: %d\n", index, id); + fprintf(stderr, "invalid glyph cache index: %d in cache id: %d\n", index, id); return NULL; } @@ -376,7 +376,7 @@ rdpGlyph* glyph_cache_get(rdpGlyphCache* glyph_cache, UINT32 id, UINT32 index) if (glyph == NULL) { - printf("invalid glyph at cache index: %d in cache id: %d\n", index, id); + fprintf(stderr, "invalid glyph at cache index: %d in cache id: %d\n", index, id); } return glyph; @@ -388,13 +388,13 @@ void glyph_cache_put(rdpGlyphCache* glyph_cache, UINT32 id, UINT32 index, rdpGly if (id > 9) { - printf("invalid glyph cache id: %d\n", id); + fprintf(stderr, "invalid glyph cache id: %d\n", id); return; } if (index > glyph_cache->glyphCache[id].number) { - printf("invalid glyph cache index: %d in cache id: %d\n", index, id); + fprintf(stderr, "invalid glyph cache index: %d in cache id: %d\n", index, id); return; } @@ -419,7 +419,7 @@ void* glyph_cache_fragment_get(rdpGlyphCache* glyph_cache, UINT32 index, UINT32* if (fragment == NULL) { - printf("invalid glyph fragment at index:%d\n", index); + fprintf(stderr, "invalid glyph fragment at index:%d\n", index); } return fragment; diff --git a/libfreerdp/cache/nine_grid.c b/libfreerdp/cache/nine_grid.c index e4de9deff..47245c8a8 100644 --- a/libfreerdp/cache/nine_grid.c +++ b/libfreerdp/cache/nine_grid.c @@ -27,7 +27,7 @@ #include <freerdp/update.h> #include <freerdp/freerdp.h> -#include <freerdp/utils/stream.h> +#include <winpr/stream.h> #include <freerdp/cache/nine_grid.h> @@ -60,7 +60,7 @@ void* nine_grid_cache_get(rdpNineGridCache* nine_grid, UINT32 index) if (index >= nine_grid->maxEntries) { - printf("invalid NineGrid index: 0x%04X\n", index); + fprintf(stderr, "invalid NineGrid index: 0x%04X\n", index); return NULL; } @@ -68,7 +68,7 @@ void* nine_grid_cache_get(rdpNineGridCache* nine_grid, UINT32 index) if (entry == NULL) { - printf("invalid NineGrid at index: 0x%04X\n", index); + fprintf(stderr, "invalid NineGrid at index: 0x%04X\n", index); return NULL; } @@ -81,7 +81,7 @@ void nine_grid_cache_put(rdpNineGridCache* nine_grid, UINT32 index, void* entry) if (index >= nine_grid->maxEntries) { - printf("invalid NineGrid index: 0x%04X\n", index); + fprintf(stderr, "invalid NineGrid index: 0x%04X\n", index); return; } diff --git a/libfreerdp/cache/offscreen.c b/libfreerdp/cache/offscreen.c index 4a696c0bf..ebca2d896 100644 --- a/libfreerdp/cache/offscreen.c +++ b/libfreerdp/cache/offscreen.c @@ -25,7 +25,7 @@ #include <winpr/crt.h> -#include <freerdp/utils/stream.h> +#include <winpr/stream.h> #include <freerdp/cache/offscreen.h> @@ -80,7 +80,7 @@ rdpBitmap* offscreen_cache_get(rdpOffscreenCache* offscreen_cache, UINT32 index) if (index >= offscreen_cache->maxEntries) { - printf("invalid offscreen bitmap index: 0x%04X\n", index); + fprintf(stderr, "invalid offscreen bitmap index: 0x%04X\n", index); return NULL; } @@ -88,7 +88,7 @@ rdpBitmap* offscreen_cache_get(rdpOffscreenCache* offscreen_cache, UINT32 index) if (bitmap == NULL) { - printf("invalid offscreen bitmap at index: 0x%04X\n", index); + fprintf(stderr, "invalid offscreen bitmap at index: 0x%04X\n", index); return NULL; } @@ -99,7 +99,7 @@ void offscreen_cache_put(rdpOffscreenCache* offscreen, UINT32 index, rdpBitmap* { if (index >= offscreen->maxEntries) { - printf("invalid offscreen bitmap index: 0x%04X\n", index); + fprintf(stderr, "invalid offscreen bitmap index: 0x%04X\n", index); return; } @@ -113,7 +113,7 @@ void offscreen_cache_delete(rdpOffscreenCache* offscreen, UINT32 index) if (index >= offscreen->maxEntries) { - printf("invalid offscreen bitmap index (delete): 0x%04X\n", index); + fprintf(stderr, "invalid offscreen bitmap index (delete): 0x%04X\n", index); return; } diff --git a/libfreerdp/cache/palette.c b/libfreerdp/cache/palette.c index b335f9149..0e249ec3c 100644 --- a/libfreerdp/cache/palette.c +++ b/libfreerdp/cache/palette.c @@ -44,7 +44,7 @@ void* palette_cache_get(rdpPaletteCache* palette_cache, UINT32 index) if (index >= palette_cache->maxEntries) { - printf("invalid color table index: 0x%04X\n", index); + fprintf(stderr, "invalid color table index: 0x%04X\n", index); return NULL; } @@ -52,7 +52,7 @@ void* palette_cache_get(rdpPaletteCache* palette_cache, UINT32 index) if (entry == NULL) { - printf("invalid color table at index: 0x%04X\n", index); + fprintf(stderr, "invalid color table at index: 0x%04X\n", index); return NULL; } @@ -63,7 +63,7 @@ void palette_cache_put(rdpPaletteCache* palette_cache, UINT32 index, void* entry { if (index >= palette_cache->maxEntries) { - printf("invalid color table index: 0x%04X\n", index); + fprintf(stderr, "invalid color table index: 0x%04X\n", index); return; } diff --git a/libfreerdp/cache/pointer.c b/libfreerdp/cache/pointer.c index c0765be5e..484c2985b 100644 --- a/libfreerdp/cache/pointer.c +++ b/libfreerdp/cache/pointer.c @@ -25,7 +25,7 @@ #include <winpr/crt.h> -#include <freerdp/utils/stream.h> +#include <winpr/stream.h> #include <freerdp/cache/pointer.h> @@ -47,7 +47,7 @@ void update_pointer_system(rdpContext* context, POINTER_SYSTEM_UPDATE* pointer_s break; default: - printf("Unknown system pointer type (0x%08X)\n", pointer_system->type); + fprintf(stderr, "Unknown system pointer type (0x%08X)\n", pointer_system->type); break; } } @@ -131,7 +131,7 @@ rdpPointer* pointer_cache_get(rdpPointerCache* pointer_cache, UINT32 index) if (index >= pointer_cache->cacheSize) { - printf("invalid pointer index:%d\n", index); + fprintf(stderr, "invalid pointer index:%d\n", index); return NULL; } @@ -146,7 +146,7 @@ void pointer_cache_put(rdpPointerCache* pointer_cache, UINT32 index, rdpPointer* if (index >= pointer_cache->cacheSize) { - printf("invalid pointer index:%d\n", index); + fprintf(stderr, "invalid pointer index:%d\n", index); return; } diff --git a/libfreerdp/codec/audio.c b/libfreerdp/codec/audio.c index 612f38e0a..1e45989d3 100644 --- a/libfreerdp/codec/audio.c +++ b/libfreerdp/codec/audio.c @@ -81,7 +81,7 @@ char* rdpsnd_get_audio_tag_string(UINT16 wFormatTag) void rdpsnd_print_audio_format(AUDIO_FORMAT* format) { - printf("%s:\t wFormatTag: 0x%04X nChannels: %d nSamplesPerSec: %d nAvgBytesPerSec: %d " + fprintf(stderr, "%s:\t wFormatTag: 0x%04X nChannels: %d nSamplesPerSec: %d nAvgBytesPerSec: %d " "nBlockAlign: %d wBitsPerSample: %d cbSize: %d\n", rdpsnd_get_audio_tag_string(format->wFormatTag), format->wFormatTag, format->nChannels, format->nSamplesPerSec, format->nAvgBytesPerSec, @@ -95,17 +95,17 @@ void rdpsnd_print_audio_formats(AUDIO_FORMAT* formats, UINT16 count) if (formats) { - printf("AUDIO_FORMATS (%d) =\n{\n", count); + fprintf(stderr, "AUDIO_FORMATS (%d) =\n{\n", count); for (index = 0; index < (int) count; index++) { format = &formats[index]; - printf("\t"); + fprintf(stderr, "\t"); rdpsnd_print_audio_format(format); } - printf("}\n"); + fprintf(stderr, "}\n"); } } diff --git a/libfreerdp/codec/bitmap.c b/libfreerdp/codec/bitmap.c index 34deb6bb8..598017081 100644 --- a/libfreerdp/codec/bitmap.c +++ b/libfreerdp/codec/bitmap.c @@ -21,7 +21,7 @@ #include "config.h" #endif -#include <freerdp/utils/stream.h> +#include <winpr/stream.h> #include <freerdp/codec/color.h> #include <freerdp/codec/bitmap.h> diff --git a/libfreerdp/codec/jpeg.c b/libfreerdp/codec/jpeg.c index 39174d76d..784b5a7df 100644 --- a/libfreerdp/codec/jpeg.c +++ b/libfreerdp/codec/jpeg.c @@ -21,7 +21,7 @@ #include "config.h" #endif -#include <freerdp/utils/stream.h> +#include <winpr/stream.h> #include <freerdp/codec/color.h> diff --git a/libfreerdp/codec/mppc_dec.c b/libfreerdp/codec/mppc_dec.c index 8a8761327..ebd8fdc29 100644 --- a/libfreerdp/codec/mppc_dec.c +++ b/libfreerdp/codec/mppc_dec.c @@ -151,7 +151,7 @@ int decompress_rdp(struct rdp_mppc_dec* dec, BYTE* cbuf, int len, int ctype, UIN break; default: - printf("mppc.c: invalid RDP compression code 0x%2.2x\n", type); + fprintf(stderr, "mppc.c: invalid RDP compression code 0x%2.2x\n", type); return FALSE; } } @@ -184,11 +184,11 @@ int decompress_rdp_4(struct rdp_mppc_dec* dec, BYTE* cbuf, int len, int ctype, U int tmp; UINT32 i32; - printf("decompress_rdp_4:\n"); + fprintf(stderr, "decompress_rdp_4:\n"); if ((dec == NULL) || (dec->history_buf == NULL)) { - printf("decompress_rdp_4: null\n"); + fprintf(stderr, "decompress_rdp_4: null\n"); return FALSE; } @@ -616,7 +616,7 @@ int decompress_rdp_5(struct rdp_mppc_dec* dec, BYTE* cbuf, int len, int ctype, U if ((dec == NULL) || (dec->history_buf == NULL)) { - printf("decompress_rdp_5: null\n"); + fprintf(stderr, "decompress_rdp_5: null\n"); return FALSE; } @@ -1082,7 +1082,7 @@ int decompress_rdp_6(struct rdp_mppc_dec* dec, BYTE* cbuf, int len, int ctype, U if ((dec == NULL) || (dec->history_buf == NULL)) { - printf("decompress_rdp_6: null\n"); + fprintf(stderr, "decompress_rdp_6: null\n"); return FALSE; } @@ -1417,7 +1417,7 @@ struct rdp_mppc_dec* mppc_dec_new(void) ptr = (struct rdp_mppc_dec*) malloc(sizeof(struct rdp_mppc_dec)); if (!ptr) { - printf("mppc_new(): system out of memory\n"); + fprintf(stderr, "mppc_new(): system out of memory\n"); return NULL; } @@ -1429,7 +1429,7 @@ struct rdp_mppc_dec* mppc_dec_new(void) if (!ptr->history_buf) { - printf("mppc_new(): system out of memory\n"); + fprintf(stderr, "mppc_new(): system out of memory\n"); free(ptr); return NULL; } diff --git a/libfreerdp/codec/nsc.c b/libfreerdp/codec/nsc.c index abc3353f2..9e9db09e1 100644 --- a/libfreerdp/codec/nsc.c +++ b/libfreerdp/codec/nsc.c @@ -169,7 +169,7 @@ static void nsc_rle_decompress_data(NSC_CONTEXT* context) } } -static void nsc_stream_initialize(NSC_CONTEXT* context, STREAM* s) +static void nsc_stream_initialize(NSC_CONTEXT* context, wStream* s) { int i; @@ -183,7 +183,7 @@ static void nsc_stream_initialize(NSC_CONTEXT* context, STREAM* s) context->nsc_stream.Planes = stream_get_tail(s); } -static void nsc_context_initialize(NSC_CONTEXT* context, STREAM* s) +static void nsc_context_initialize(NSC_CONTEXT* context, wStream* s) { int i; UINT32 length; @@ -327,7 +327,7 @@ void nsc_context_set_pixel_format(NSC_CONTEXT* context, RDP_PIXEL_FORMAT pixel_f void nsc_process_message(NSC_CONTEXT* context, UINT16 bpp, UINT16 width, UINT16 height, BYTE* data, UINT32 length) { - STREAM* s; + wStream* s; s = stream_new(0); stream_attach(s, data, length); diff --git a/libfreerdp/codec/nsc_encode.c b/libfreerdp/codec/nsc_encode.c index 56008d298..36c1988e9 100644 --- a/libfreerdp/codec/nsc_encode.c +++ b/libfreerdp/codec/nsc_encode.c @@ -329,7 +329,7 @@ static void nsc_rle_compress_data(NSC_CONTEXT* context) } } -void nsc_compose_message(NSC_CONTEXT* context, STREAM* s, +void nsc_compose_message(NSC_CONTEXT* context, wStream* s, BYTE* bmpdata, int width, int height, int rowstride) { int i; diff --git a/libfreerdp/codec/rfx.c b/libfreerdp/codec/rfx.c index 0df8d9967..05c5735a3 100644 --- a/libfreerdp/codec/rfx.c +++ b/libfreerdp/codec/rfx.c @@ -325,7 +325,7 @@ int rfx_tile_pool_return(RFX_CONTEXT* context, RFX_TILE* tile) return 0; } -static BOOL rfx_process_message_sync(RFX_CONTEXT* context, STREAM* s) +static BOOL rfx_process_message_sync(RFX_CONTEXT* context, wStream* s) { UINT32 magic; @@ -355,7 +355,7 @@ static BOOL rfx_process_message_sync(RFX_CONTEXT* context, STREAM* s) return TRUE; } -static BOOL rfx_process_message_codec_versions(RFX_CONTEXT* context, STREAM* s) +static BOOL rfx_process_message_codec_versions(RFX_CONTEXT* context, wStream* s) { BYTE numCodecs; @@ -386,7 +386,7 @@ static BOOL rfx_process_message_codec_versions(RFX_CONTEXT* context, STREAM* s) return TRUE; } -static BOOL rfx_process_message_channels(RFX_CONTEXT* context, STREAM* s) +static BOOL rfx_process_message_channels(RFX_CONTEXT* context, wStream* s) { BYTE channelId; BYTE numChannels; @@ -427,7 +427,7 @@ static BOOL rfx_process_message_channels(RFX_CONTEXT* context, STREAM* s) return TRUE; } -static BOOL rfx_process_message_context(RFX_CONTEXT* context, STREAM* s) +static BOOL rfx_process_message_context(RFX_CONTEXT* context, wStream* s) { BYTE ctxId; UINT16 tileSize; @@ -472,7 +472,7 @@ static BOOL rfx_process_message_context(RFX_CONTEXT* context, STREAM* s) return TRUE; } -static BOOL rfx_process_message_frame_begin(RFX_CONTEXT* context, RFX_MESSAGE* message, STREAM* s) +static BOOL rfx_process_message_frame_begin(RFX_CONTEXT* context, RFX_MESSAGE* message, wStream* s) { UINT32 frameIdx; UINT16 numRegions; @@ -489,12 +489,12 @@ static BOOL rfx_process_message_frame_begin(RFX_CONTEXT* context, RFX_MESSAGE* m return TRUE; } -static void rfx_process_message_frame_end(RFX_CONTEXT* context, RFX_MESSAGE* message, STREAM* s) +static void rfx_process_message_frame_end(RFX_CONTEXT* context, RFX_MESSAGE* message, wStream* s) { DEBUG_RFX("RFX_FRAME_END"); } -static BOOL rfx_process_message_region(RFX_CONTEXT* context, RFX_MESSAGE* message, STREAM* s) +static BOOL rfx_process_message_region(RFX_CONTEXT* context, RFX_MESSAGE* message, wStream* s) { int i; @@ -539,7 +539,7 @@ static BOOL rfx_process_message_region(RFX_CONTEXT* context, RFX_MESSAGE* messag return TRUE; } -static BOOL rfx_process_message_tile(RFX_CONTEXT* context, RFX_TILE* tile, STREAM* s) +static BOOL rfx_process_message_tile(RFX_CONTEXT* context, RFX_TILE* tile, wStream* s) { BYTE quantIdxY; BYTE quantIdxCb; @@ -578,7 +578,7 @@ static BOOL rfx_process_message_tile(RFX_CONTEXT* context, RFX_TILE* tile, STREA struct _RFX_TILE_WORK_PARAM { - STREAM s; + wStream s; RFX_TILE* tile; RFX_CONTEXT* context; }; @@ -590,7 +590,7 @@ void CALLBACK rfx_process_message_tile_work_callback(PTP_CALLBACK_INSTANCE insta rfx_process_message_tile(param->context, param->tile, &(param->s)); } -static BOOL rfx_process_message_tileset(RFX_CONTEXT* context, RFX_MESSAGE* message, STREAM* s) +static BOOL rfx_process_message_tileset(RFX_CONTEXT* context, RFX_MESSAGE* message, wStream* s) { int i; int pos; @@ -721,7 +721,7 @@ static BOOL rfx_process_message_tileset(RFX_CONTEXT* context, RFX_MESSAGE* messa { params[i].context = context; params[i].tile = message->tiles[i]; - CopyMemory(&(params[i].s), s, sizeof(STREAM)); + CopyMemory(&(params[i].s), s, sizeof(wStream)); work_objects[i] = CreateThreadpoolWork((PTP_WORK_CALLBACK) rfx_process_message_tile_work_callback, (void*) ¶ms[i], &context->priv->ThreadPoolEnv); @@ -750,7 +750,7 @@ static BOOL rfx_process_message_tileset(RFX_CONTEXT* context, RFX_MESSAGE* messa RFX_MESSAGE* rfx_process_message(RFX_CONTEXT* context, BYTE* data, UINT32 length) { int pos; - STREAM* s; + wStream* s; UINT32 blockLen; UINT32 blockType; RFX_MESSAGE* message; @@ -884,7 +884,7 @@ void rfx_message_free(RFX_CONTEXT* context, RFX_MESSAGE* message) } } -static void rfx_compose_message_sync(RFX_CONTEXT* context, STREAM* s) +static void rfx_compose_message_sync(RFX_CONTEXT* context, wStream* s) { stream_write_UINT16(s, WBT_SYNC); /* BlockT.blockType */ stream_write_UINT32(s, 12); /* BlockT.blockLen */ @@ -892,7 +892,7 @@ static void rfx_compose_message_sync(RFX_CONTEXT* context, STREAM* s) stream_write_UINT16(s, WF_VERSION_1_0); /* version */ } -static void rfx_compose_message_codec_versions(RFX_CONTEXT* context, STREAM* s) +static void rfx_compose_message_codec_versions(RFX_CONTEXT* context, wStream* s) { stream_write_UINT16(s, WBT_CODEC_VERSIONS); /* BlockT.blockType */ stream_write_UINT32(s, 10); /* BlockT.blockLen */ @@ -901,7 +901,7 @@ static void rfx_compose_message_codec_versions(RFX_CONTEXT* context, STREAM* s) stream_write_UINT16(s, WF_VERSION_1_0); /* codecs.version */ } -static void rfx_compose_message_channels(RFX_CONTEXT* context, STREAM* s) +static void rfx_compose_message_channels(RFX_CONTEXT* context, wStream* s) { stream_write_UINT16(s, WBT_CHANNELS); /* BlockT.blockType */ stream_write_UINT32(s, 12); /* BlockT.blockLen */ @@ -911,7 +911,7 @@ static void rfx_compose_message_channels(RFX_CONTEXT* context, STREAM* s) stream_write_UINT16(s, context->height); /* Channel.height */ } -static void rfx_compose_message_context(RFX_CONTEXT* context, STREAM* s) +static void rfx_compose_message_context(RFX_CONTEXT* context, wStream* s) { UINT16 properties; @@ -940,7 +940,7 @@ static void rfx_compose_message_context(RFX_CONTEXT* context, STREAM* s) context->properties = properties; } -void rfx_compose_message_header(RFX_CONTEXT* context, STREAM* s) +void rfx_compose_message_header(RFX_CONTEXT* context, wStream* s) { stream_check_size(s, 12 + 10 + 12 + 13); @@ -952,7 +952,7 @@ void rfx_compose_message_header(RFX_CONTEXT* context, STREAM* s) context->header_processed = TRUE; } -static void rfx_compose_message_frame_begin(RFX_CONTEXT* context, STREAM* s) +static void rfx_compose_message_frame_begin(RFX_CONTEXT* context, wStream* s) { stream_check_size(s, 14); @@ -966,7 +966,7 @@ static void rfx_compose_message_frame_begin(RFX_CONTEXT* context, STREAM* s) context->frame_idx++; } -static void rfx_compose_message_region(RFX_CONTEXT* context, STREAM* s, +static void rfx_compose_message_region(RFX_CONTEXT* context, wStream* s, const RFX_RECT* rects, int num_rects) { int size; @@ -994,7 +994,7 @@ static void rfx_compose_message_region(RFX_CONTEXT* context, STREAM* s, stream_write_UINT16(s, 1); /* numTilesets */ } -static void rfx_compose_message_tile(RFX_CONTEXT* context, STREAM* s, +static void rfx_compose_message_tile(RFX_CONTEXT* context, wStream* s, BYTE* tile_data, int tile_width, int tile_height, int rowstride, const UINT32* quantVals, int quantIdxY, int quantIdxCb, int quantIdxCr, int xIdx, int yIdx) @@ -1036,7 +1036,7 @@ static void rfx_compose_message_tile(RFX_CONTEXT* context, STREAM* s, stream_set_pos(s, end_pos); } -static void rfx_compose_message_tileset(RFX_CONTEXT* context, STREAM* s, +static void rfx_compose_message_tileset(RFX_CONTEXT* context, wStream* s, BYTE* image_data, int width, int height, int rowstride) { int i; @@ -1125,7 +1125,7 @@ static void rfx_compose_message_tileset(RFX_CONTEXT* context, STREAM* s, stream_set_pos(s, end_pos); } -static void rfx_compose_message_frame_end(RFX_CONTEXT* context, STREAM* s) +static void rfx_compose_message_frame_end(RFX_CONTEXT* context, wStream* s) { stream_check_size(s, 8); @@ -1135,7 +1135,7 @@ static void rfx_compose_message_frame_end(RFX_CONTEXT* context, STREAM* s) stream_write_BYTE(s, 0); /* CodecChannelT.channelId */ } -static void rfx_compose_message_data(RFX_CONTEXT* context, STREAM* s, +static void rfx_compose_message_data(RFX_CONTEXT* context, wStream* s, const RFX_RECT* rects, int num_rects, BYTE* image_data, int width, int height, int rowstride) { rfx_compose_message_frame_begin(context, s); @@ -1144,7 +1144,7 @@ static void rfx_compose_message_data(RFX_CONTEXT* context, STREAM* s, rfx_compose_message_frame_end(context, s); } -FREERDP_API void rfx_compose_message(RFX_CONTEXT* context, STREAM* s, +FREERDP_API void rfx_compose_message(RFX_CONTEXT* context, wStream* s, const RFX_RECT* rects, int num_rects, BYTE* image_data, int width, int height, int rowstride) { /* Only the first frame should send the RemoteFX header */ diff --git a/libfreerdp/codec/rfx_decode.c b/libfreerdp/codec/rfx_decode.c index a7c0b08a9..1acffda27 100644 --- a/libfreerdp/codec/rfx_decode.c +++ b/libfreerdp/codec/rfx_decode.c @@ -26,7 +26,7 @@ #include <stdlib.h> #include <string.h> -#include <freerdp/utils/stream.h> +#include <winpr/stream.h> #include <freerdp/primitives.h> #include "rfx_types.h" @@ -142,7 +142,7 @@ void CALLBACK rfx_decode_component_work_callback(PTP_CALLBACK_INSTANCE instance, } /* stride is bytes between rows in the output buffer. */ -BOOL rfx_decode_rgb(RFX_CONTEXT* context, STREAM* data_in, +BOOL rfx_decode_rgb(RFX_CONTEXT* context, wStream* data_in, int y_size, const UINT32* y_quants, int cb_size, const UINT32* cb_quants, int cr_size, const UINT32* cr_quants, BYTE* rgb_buffer, int stride) @@ -165,22 +165,22 @@ BOOL rfx_decode_rgb(RFX_CONTEXT* context, STREAM* data_in, params[0].context = context; params[0].quantization_values = y_quants; - params[0].data = stream_get_tail(data_in); - params[0].size = y_size; + params[0].buffer = stream_get_tail(data_in); + params[0].capacity = y_size; params[0].buffer = pSrcDst[0]; stream_seek(data_in, y_size); params[1].context = context; params[1].quantization_values = cb_quants; - params[1].data = stream_get_tail(data_in); - params[1].size = cb_size; + params[1].buffer = stream_get_tail(data_in); + params[1].capacity = cb_size; params[1].buffer = pSrcDst[1]; stream_seek(data_in, cb_size); params[2].context = context; params[2].quantization_values = cr_quants; - params[2].data = stream_get_tail(data_in); - params[2].size = cr_size; + params[2].buffer = stream_get_tail(data_in); + params[2].capacity = cr_size; params[2].buffer = pSrcDst[2]; stream_seek(data_in, cr_size); @@ -202,11 +202,12 @@ BOOL rfx_decode_rgb(RFX_CONTEXT* context, STREAM* data_in, else #endif { - if (stream_get_left(data_in) < y_size+cb_size+cr_size) + if (stream_get_left(data_in) < y_size + cb_size + cr_size) { DEBUG_WARN("rfx_decode_rgb: packet too small for y_size+cb_size+cr_size"); return FALSE; } + rfx_decode_component(context, y_quants, stream_get_tail(data_in), y_size, pSrcDst[0]); /* YData */ stream_seek(data_in, y_size); @@ -230,5 +231,6 @@ BOOL rfx_decode_rgb(RFX_CONTEXT* context, STREAM* data_in, BufferPool_Return(context->priv->BufferPool, (BYTE*)pSrcDst[0] - 16); BufferPool_Return(context->priv->BufferPool, (BYTE*)pSrcDst[1] - 16); BufferPool_Return(context->priv->BufferPool, (BYTE*)pSrcDst[2] - 16); + return TRUE; } diff --git a/libfreerdp/codec/rfx_decode.h b/libfreerdp/codec/rfx_decode.h index fa957cd69..469c2a576 100644 --- a/libfreerdp/codec/rfx_decode.h +++ b/libfreerdp/codec/rfx_decode.h @@ -23,7 +23,7 @@ #include <freerdp/codec/rfx.h> /* stride is bytes between rows in the output buffer. */ -BOOL rfx_decode_rgb(RFX_CONTEXT* context, STREAM* data_in, +BOOL rfx_decode_rgb(RFX_CONTEXT* context, wStream* data_in, int y_size, const UINT32 * y_quants, int cb_size, const UINT32 * cb_quants, int cr_size, const UINT32 * cr_quants, BYTE* rgb_buffer, diff --git a/libfreerdp/codec/rfx_encode.c b/libfreerdp/codec/rfx_encode.c index e6cf10a0a..af54d8997 100644 --- a/libfreerdp/codec/rfx_encode.c +++ b/libfreerdp/codec/rfx_encode.c @@ -219,7 +219,7 @@ static void rfx_encode_component(RFX_CONTEXT* context, const UINT32* quantizatio void rfx_encode_rgb(RFX_CONTEXT* context, const BYTE* rgb_data, int width, int height, int rowstride, const UINT32* y_quants, const UINT32* cb_quants, const UINT32* cr_quants, - STREAM* data_out, int* y_size, int* cb_size, int* cr_size) + wStream* data_out, int* y_size, int* cb_size, int* cr_size) { INT16* pSrcDst[3]; primitives_t* prims = primitives_get(); diff --git a/libfreerdp/codec/rfx_encode.h b/libfreerdp/codec/rfx_encode.h index 94dfc706d..e329bded2 100644 --- a/libfreerdp/codec/rfx_encode.h +++ b/libfreerdp/codec/rfx_encode.h @@ -24,7 +24,7 @@ void rfx_encode_rgb(RFX_CONTEXT* context, const BYTE* rgb_data, int width, int height, int rowstride, const UINT32* y_quants, const UINT32* cb_quants, const UINT32* cr_quants, - STREAM* data_out, int* y_size, int* cb_size, int* cr_size); + wStream* data_out, int* y_size, int* cb_size, int* cr_size); #endif diff --git a/libfreerdp/common/settings.c b/libfreerdp/common/settings.c index 89c11e9ab..c8a82cde8 100644 --- a/libfreerdp/common/settings.c +++ b/libfreerdp/common/settings.c @@ -292,3 +292,1855 @@ void freerdp_dynamic_channel_collection_free(rdpSettings* settings) settings->DynamicChannelArray = NULL; settings->DynamicChannelCount = 0; } + +/** + * Partially Generated Code + */ + +BOOL freerdp_get_param_bool(rdpSettings* settings, int id) +{ + switch (id) + { + case FreeRDP_ServerMode: + return settings->ServerMode; + break; + + case FreeRDP_NetworkAutoDetect: + return settings->NetworkAutoDetect; + break; + + case FreeRDP_SupportAsymetricKeys: + return settings->SupportAsymetricKeys; + break; + + case FreeRDP_SupportErrorInfoPdu: + return settings->SupportErrorInfoPdu; + break; + + case FreeRDP_SupportStatusInfoPdu: + return settings->SupportStatusInfoPdu; + break; + + case FreeRDP_SupportMonitorLayoutPdu: + return settings->SupportMonitorLayoutPdu; + break; + + case FreeRDP_SupportGraphicsPipeline: + return settings->SupportGraphicsPipeline; + break; + + case FreeRDP_SupportDynamicTimeZone: + return settings->SupportDynamicTimeZone; + break; + + case FreeRDP_DisableEncryption: + return settings->DisableEncryption; + break; + + case FreeRDP_ConsoleSession: + return settings->ConsoleSession; + break; + + case FreeRDP_SpanMonitors: + return settings->SpanMonitors; + break; + + case FreeRDP_UseMultimon: + return settings->UseMultimon; + break; + + case FreeRDP_ForceMultimon: + return settings->ForceMultimon; + break; + + case FreeRDP_AutoLogonEnabled: + return settings->AutoLogonEnabled; + break; + + case FreeRDP_CompressionEnabled: + return settings->CompressionEnabled; + break; + + case FreeRDP_DisableCtrlAltDel: + return settings->DisableCtrlAltDel; + break; + + case FreeRDP_EnableWindowsKey: + return settings->EnableWindowsKey; + break; + + case FreeRDP_MaximizeShell: + return settings->MaximizeShell; + break; + + case FreeRDP_LogonNotify: + return settings->LogonNotify; + break; + + case FreeRDP_LogonErrors: + return settings->LogonErrors; + break; + + case FreeRDP_MouseAttached: + return settings->MouseAttached; + break; + + case FreeRDP_MouseHasWheel: + return settings->MouseHasWheel; + break; + + case FreeRDP_RemoteConsoleAudio: + return settings->RemoteConsoleAudio; + break; + + case FreeRDP_AudioPlayback: + return settings->AudioPlayback; + break; + + case FreeRDP_AudioCapture: + return settings->AudioCapture; + break; + + case FreeRDP_VideoDisable: + return settings->VideoDisable; + break; + + case FreeRDP_PasswordIsSmartcardPin: + return settings->PasswordIsSmartcardPin; + break; + + case FreeRDP_UsingSavedCredentials: + return settings->UsingSavedCredentials; + break; + + case FreeRDP_ForceEncryptedCsPdu: + return settings->ForceEncryptedCsPdu; + break; + + case FreeRDP_IPv6Enabled: + return settings->IPv6Enabled; + break; + + case FreeRDP_AutoReconnectionEnabled: + return settings->AutoReconnectionEnabled; + break; + + case FreeRDP_DynamicDaylightTimeDisabled: + return settings->DynamicDaylightTimeDisabled; + break; + + case FreeRDP_AllowFontSmoothing: + return settings->AllowFontSmoothing; + break; + + case FreeRDP_DisableWallpaper: + return settings->DisableWallpaper; + break; + + case FreeRDP_DisableFullWindowDrag: + return settings->DisableFullWindowDrag; + break; + + case FreeRDP_DisableMenuAnims: + return settings->DisableMenuAnims; + break; + + case FreeRDP_DisableThemes: + return settings->DisableThemes; + break; + + case FreeRDP_DisableCursorShadow: + return settings->DisableCursorShadow; + break; + + case FreeRDP_DisableCursorBlinking: + return settings->DisableCursorBlinking; + break; + + case FreeRDP_AllowDesktopComposition: + return settings->AllowDesktopComposition; + break; + + case FreeRDP_TlsSecurity: + return settings->TlsSecurity; + break; + + case FreeRDP_NlaSecurity: + return settings->NlaSecurity; + break; + + case FreeRDP_RdpSecurity: + return settings->RdpSecurity; + break; + + case FreeRDP_ExtSecurity: + return settings->ExtSecurity; + break; + + case FreeRDP_Authentication: + return settings->Authentication; + break; + + case FreeRDP_NegotiateSecurityLayer: + return settings->NegotiateSecurityLayer; + break; + + case FreeRDP_MstscCookieMode: + return settings->MstscCookieMode; + break; + + case FreeRDP_SendPreconnectionPdu: + return settings->SendPreconnectionPdu; + break; + + case FreeRDP_IgnoreCertificate: + return settings->IgnoreCertificate; + break; + + case FreeRDP_Workarea: + return settings->Workarea; + break; + + case FreeRDP_Fullscreen: + return settings->Fullscreen; + break; + + case FreeRDP_GrabKeyboard: + return settings->GrabKeyboard; + break; + + case FreeRDP_Decorations: + return settings->Decorations; + break; + + case FreeRDP_MouseMotion: + return settings->MouseMotion; + break; + + case FreeRDP_AsyncInput: + return settings->AsyncInput; + break; + + case FreeRDP_AsyncUpdate: + return settings->AsyncUpdate; + break; + + case FreeRDP_AsyncChannels: + return settings->AsyncChannels; + break; + + case FreeRDP_ToggleFullscreen: + return settings->ToggleFullscreen; + break; + + case FreeRDP_SoftwareGdi: + return settings->SoftwareGdi; + break; + + case FreeRDP_LocalConnection: + return settings->LocalConnection; + break; + + case FreeRDP_AuthenticationOnly: + return settings->AuthenticationOnly; + break; + + case FreeRDP_CredentialsFromStdin: + return settings->CredentialsFromStdin; + break; + + case FreeRDP_DumpRemoteFx: + return settings->DumpRemoteFx; + break; + + case FreeRDP_PlayRemoteFx: + return settings->PlayRemoteFx; + break; + + case FreeRDP_GatewayUsageMethod: + return settings->GatewayUsageMethod; + break; + + case FreeRDP_GatewayUseSameCredentials: + return settings->GatewayUseSameCredentials; + break; + + case FreeRDP_RemoteApplicationMode: + return settings->RemoteApplicationMode; + break; + + case FreeRDP_RemoteAppLanguageBarSupported: + return settings->RemoteAppLanguageBarSupported; + break; + + case FreeRDP_RefreshRect: + return settings->RefreshRect; + break; + + case FreeRDP_SuppressOutput: + return settings->SuppressOutput; + break; + + case FreeRDP_FastPathOutput: + return settings->FastPathOutput; + break; + + case FreeRDP_SaltedChecksum: + return settings->SaltedChecksum; + break; + + case FreeRDP_LongCredentialsSupported: + return settings->LongCredentialsSupported; + break; + + case FreeRDP_NoBitmapCompressionHeader: + return settings->NoBitmapCompressionHeader; + break; + + case FreeRDP_DesktopResize: + return settings->DesktopResize; + break; + + case FreeRDP_DrawAllowDynamicColorFidelity: + return settings->DrawAllowDynamicColorFidelity; + break; + + case FreeRDP_DrawAllowColorSubsampling: + return settings->DrawAllowColorSubsampling; + break; + + case FreeRDP_DrawAllowSkipAlpha: + return settings->DrawAllowSkipAlpha; + break; + + case FreeRDP_BitmapCacheV3Enabled: + return settings->BitmapCacheV3Enabled; + break; + + case FreeRDP_AltSecFrameMarkerSupport: + return settings->AltSecFrameMarkerSupport; + break; + + case FreeRDP_BitmapCacheEnabled: + return settings->BitmapCacheEnabled; + break; + + case FreeRDP_AllowCacheWaitingList: + return settings->AllowCacheWaitingList; + break; + + case FreeRDP_BitmapCachePersistEnabled: + return settings->BitmapCachePersistEnabled; + break; + + case FreeRDP_ColorPointerFlag: + return settings->ColorPointerFlag; + break; + + case FreeRDP_UnicodeInput: + return settings->UnicodeInput; + break; + + case FreeRDP_FastPathInput: + return settings->FastPathInput; + break; + + case FreeRDP_SoundBeepsEnabled: + return settings->SoundBeepsEnabled; + break; + + case FreeRDP_SurfaceCommandsEnabled: + return settings->SurfaceCommandsEnabled; + break; + + case FreeRDP_FrameMarkerCommandEnabled: + return settings->FrameMarkerCommandEnabled; + break; + + case FreeRDP_RemoteFxOnly: + return settings->RemoteFxOnly; + break; + + case FreeRDP_RemoteFxCodec: + return settings->RemoteFxCodec; + break; + + case FreeRDP_RemoteFxImageCodec: + return settings->RemoteFxImageCodec; + break; + + case FreeRDP_NSCodec: + return settings->NSCodec; + break; + + case FreeRDP_FrameAcknowledge: + return settings->FrameAcknowledge; + break; + + case FreeRDP_JpegCodec: + return settings->JpegCodec; + break; + + case FreeRDP_DrawNineGridEnabled: + return settings->DrawNineGridEnabled; + break; + + case FreeRDP_DrawGdiPlusEnabled: + return settings->DrawGdiPlusEnabled; + break; + + case FreeRDP_DrawGdiPlusCacheEnabled: + return settings->DrawGdiPlusCacheEnabled; + break; + + case FreeRDP_DeviceRedirection: + return settings->DeviceRedirection; + break; + + case FreeRDP_RedirectDrives: + return settings->RedirectDrives; + break; + + case FreeRDP_RedirectHomeDrive: + return settings->RedirectHomeDrive; + break; + + case FreeRDP_RedirectSmartCards: + return settings->RedirectSmartCards; + break; + + case FreeRDP_RedirectPrinters: + return settings->RedirectPrinters; + break; + + case FreeRDP_RedirectSerialPorts: + return settings->RedirectSerialPorts; + break; + + case FreeRDP_RedirectParallelPorts: + return settings->RedirectParallelPorts; + break; + + case FreeRDP_RedirectClipboard: + return settings->RedirectClipboard; + break; + + default: + return -1; + break; + } + + return -1; +} + +int freerdp_set_param_bool(rdpSettings* settings, int id, BOOL param) +{ + switch (id) + { + case FreeRDP_ServerMode: + settings->ServerMode = param; + break; + + case FreeRDP_NetworkAutoDetect: + settings->NetworkAutoDetect = param; + break; + + case FreeRDP_SupportAsymetricKeys: + settings->SupportAsymetricKeys = param; + break; + + case FreeRDP_SupportErrorInfoPdu: + settings->SupportErrorInfoPdu = param; + break; + + case FreeRDP_SupportStatusInfoPdu: + settings->SupportStatusInfoPdu = param; + break; + + case FreeRDP_SupportMonitorLayoutPdu: + settings->SupportMonitorLayoutPdu = param; + break; + + case FreeRDP_SupportGraphicsPipeline: + settings->SupportGraphicsPipeline = param; + break; + + case FreeRDP_SupportDynamicTimeZone: + settings->SupportDynamicTimeZone = param; + break; + + case FreeRDP_DisableEncryption: + settings->DisableEncryption = param; + break; + + case FreeRDP_ConsoleSession: + settings->ConsoleSession = param; + break; + + case FreeRDP_SpanMonitors: + settings->SpanMonitors = param; + break; + + case FreeRDP_UseMultimon: + settings->UseMultimon = param; + break; + + case FreeRDP_ForceMultimon: + settings->ForceMultimon = param; + break; + + case FreeRDP_AutoLogonEnabled: + settings->AutoLogonEnabled = param; + break; + + case FreeRDP_CompressionEnabled: + settings->CompressionEnabled = param; + break; + + case FreeRDP_DisableCtrlAltDel: + settings->DisableCtrlAltDel = param; + break; + + case FreeRDP_EnableWindowsKey: + settings->EnableWindowsKey = param; + break; + + case FreeRDP_MaximizeShell: + settings->MaximizeShell = param; + break; + + case FreeRDP_LogonNotify: + settings->LogonNotify = param; + break; + + case FreeRDP_LogonErrors: + settings->LogonErrors = param; + break; + + case FreeRDP_MouseAttached: + settings->MouseAttached = param; + break; + + case FreeRDP_MouseHasWheel: + settings->MouseHasWheel = param; + break; + + case FreeRDP_RemoteConsoleAudio: + settings->RemoteConsoleAudio = param; + break; + + case FreeRDP_AudioPlayback: + settings->AudioPlayback = param; + break; + + case FreeRDP_AudioCapture: + settings->AudioCapture = param; + break; + + case FreeRDP_VideoDisable: + settings->VideoDisable = param; + break; + + case FreeRDP_PasswordIsSmartcardPin: + settings->PasswordIsSmartcardPin = param; + break; + + case FreeRDP_UsingSavedCredentials: + settings->UsingSavedCredentials = param; + break; + + case FreeRDP_ForceEncryptedCsPdu: + settings->ForceEncryptedCsPdu = param; + break; + + case FreeRDP_IPv6Enabled: + settings->IPv6Enabled = param; + break; + + case FreeRDP_AutoReconnectionEnabled: + settings->AutoReconnectionEnabled = param; + break; + + case FreeRDP_DynamicDaylightTimeDisabled: + settings->DynamicDaylightTimeDisabled = param; + break; + + case FreeRDP_AllowFontSmoothing: + settings->AllowFontSmoothing = param; + break; + + case FreeRDP_DisableWallpaper: + settings->DisableWallpaper = param; + break; + + case FreeRDP_DisableFullWindowDrag: + settings->DisableFullWindowDrag = param; + break; + + case FreeRDP_DisableMenuAnims: + settings->DisableMenuAnims = param; + break; + + case FreeRDP_DisableThemes: + settings->DisableThemes = param; + break; + + case FreeRDP_DisableCursorShadow: + settings->DisableCursorShadow = param; + break; + + case FreeRDP_DisableCursorBlinking: + settings->DisableCursorBlinking = param; + break; + + case FreeRDP_AllowDesktopComposition: + settings->AllowDesktopComposition = param; + break; + + case FreeRDP_TlsSecurity: + settings->TlsSecurity = param; + break; + + case FreeRDP_NlaSecurity: + settings->NlaSecurity = param; + break; + + case FreeRDP_RdpSecurity: + settings->RdpSecurity = param; + break; + + case FreeRDP_ExtSecurity: + settings->ExtSecurity = param; + break; + + case FreeRDP_Authentication: + settings->Authentication = param; + break; + + case FreeRDP_NegotiateSecurityLayer: + settings->NegotiateSecurityLayer = param; + break; + + case FreeRDP_MstscCookieMode: + settings->MstscCookieMode = param; + break; + + case FreeRDP_SendPreconnectionPdu: + settings->SendPreconnectionPdu = param; + break; + + case FreeRDP_IgnoreCertificate: + settings->IgnoreCertificate = param; + break; + + case FreeRDP_Workarea: + settings->Workarea = param; + break; + + case FreeRDP_Fullscreen: + settings->Fullscreen = param; + break; + + case FreeRDP_GrabKeyboard: + settings->GrabKeyboard = param; + break; + + case FreeRDP_Decorations: + settings->Decorations = param; + break; + + case FreeRDP_MouseMotion: + settings->MouseMotion = param; + break; + + case FreeRDP_AsyncInput: + settings->AsyncInput = param; + break; + + case FreeRDP_AsyncUpdate: + settings->AsyncUpdate = param; + break; + + case FreeRDP_AsyncChannels: + settings->AsyncChannels = param; + break; + + case FreeRDP_ToggleFullscreen: + settings->ToggleFullscreen = param; + break; + + case FreeRDP_SoftwareGdi: + settings->SoftwareGdi = param; + break; + + case FreeRDP_LocalConnection: + settings->LocalConnection = param; + break; + + case FreeRDP_AuthenticationOnly: + settings->AuthenticationOnly = param; + break; + + case FreeRDP_CredentialsFromStdin: + settings->CredentialsFromStdin = param; + break; + + case FreeRDP_DumpRemoteFx: + settings->DumpRemoteFx = param; + break; + + case FreeRDP_PlayRemoteFx: + settings->PlayRemoteFx = param; + break; + + case FreeRDP_GatewayUsageMethod: + settings->GatewayUsageMethod = param; + break; + + case FreeRDP_GatewayUseSameCredentials: + settings->GatewayUseSameCredentials = param; + break; + + case FreeRDP_RemoteApplicationMode: + settings->RemoteApplicationMode = param; + break; + + case FreeRDP_RemoteAppLanguageBarSupported: + settings->RemoteAppLanguageBarSupported = param; + break; + + case FreeRDP_RefreshRect: + settings->RefreshRect = param; + break; + + case FreeRDP_SuppressOutput: + settings->SuppressOutput = param; + break; + + case FreeRDP_FastPathOutput: + settings->FastPathOutput = param; + break; + + case FreeRDP_SaltedChecksum: + settings->SaltedChecksum = param; + break; + + case FreeRDP_LongCredentialsSupported: + settings->LongCredentialsSupported = param; + break; + + case FreeRDP_NoBitmapCompressionHeader: + settings->NoBitmapCompressionHeader = param; + break; + + case FreeRDP_DesktopResize: + settings->DesktopResize = param; + break; + + case FreeRDP_DrawAllowDynamicColorFidelity: + settings->DrawAllowDynamicColorFidelity = param; + break; + + case FreeRDP_DrawAllowColorSubsampling: + settings->DrawAllowColorSubsampling = param; + break; + + case FreeRDP_DrawAllowSkipAlpha: + settings->DrawAllowSkipAlpha = param; + break; + + case FreeRDP_BitmapCacheV3Enabled: + settings->BitmapCacheV3Enabled = param; + break; + + case FreeRDP_AltSecFrameMarkerSupport: + settings->AltSecFrameMarkerSupport = param; + break; + + case FreeRDP_BitmapCacheEnabled: + settings->BitmapCacheEnabled = param; + break; + + case FreeRDP_AllowCacheWaitingList: + settings->AllowCacheWaitingList = param; + break; + + case FreeRDP_BitmapCachePersistEnabled: + settings->BitmapCachePersistEnabled = param; + break; + + case FreeRDP_ColorPointerFlag: + settings->ColorPointerFlag = param; + break; + + case FreeRDP_UnicodeInput: + settings->UnicodeInput = param; + break; + + case FreeRDP_FastPathInput: + settings->FastPathInput = param; + break; + + case FreeRDP_SoundBeepsEnabled: + settings->SoundBeepsEnabled = param; + break; + + case FreeRDP_SurfaceCommandsEnabled: + settings->SurfaceCommandsEnabled = param; + break; + + case FreeRDP_FrameMarkerCommandEnabled: + settings->FrameMarkerCommandEnabled = param; + break; + + case FreeRDP_RemoteFxOnly: + settings->RemoteFxOnly = param; + break; + + case FreeRDP_RemoteFxCodec: + settings->RemoteFxCodec = param; + break; + + case FreeRDP_RemoteFxImageCodec: + settings->RemoteFxImageCodec = param; + break; + + case FreeRDP_NSCodec: + settings->NSCodec = param; + break; + + case FreeRDP_FrameAcknowledge: + settings->FrameAcknowledge = param; + break; + + case FreeRDP_JpegCodec: + settings->JpegCodec = param; + break; + + case FreeRDP_DrawNineGridEnabled: + settings->DrawNineGridEnabled = param; + break; + + case FreeRDP_DrawGdiPlusEnabled: + settings->DrawGdiPlusEnabled = param; + break; + + case FreeRDP_DrawGdiPlusCacheEnabled: + settings->DrawGdiPlusCacheEnabled = param; + break; + + case FreeRDP_DeviceRedirection: + settings->DeviceRedirection = param; + break; + + case FreeRDP_RedirectDrives: + settings->RedirectDrives = param; + break; + + case FreeRDP_RedirectHomeDrive: + settings->RedirectHomeDrive = param; + break; + + case FreeRDP_RedirectSmartCards: + settings->RedirectSmartCards = param; + break; + + case FreeRDP_RedirectPrinters: + settings->RedirectPrinters = param; + break; + + case FreeRDP_RedirectSerialPorts: + settings->RedirectSerialPorts = param; + break; + + case FreeRDP_RedirectParallelPorts: + settings->RedirectParallelPorts = param; + break; + + case FreeRDP_RedirectClipboard: + settings->RedirectClipboard = param; + break; + + default: + return -1; + break; + } + + return -1; +} + +UINT32 freerdp_get_param_uint32(rdpSettings* settings, int id) +{ + switch (id) + { + case FreeRDP_ShareId: + return settings->ShareId; + break; + + case FreeRDP_PduSource: + return settings->PduSource; + break; + + case FreeRDP_ServerPort: + return settings->ServerPort; + break; + + case FreeRDP_RdpVersion: + return settings->RdpVersion; + break; + + case FreeRDP_DesktopWidth: + return settings->DesktopWidth; + break; + + case FreeRDP_DesktopHeight: + return settings->DesktopHeight; + break; + + case FreeRDP_ColorDepth: + return settings->ColorDepth; + break; + + case FreeRDP_ConnectionType: + return settings->ConnectionType; + break; + + case FreeRDP_ClientBuild: + return settings->ClientBuild; + break; + + case FreeRDP_EarlyCapabilityFlags: + return settings->EarlyCapabilityFlags; + break; + + case FreeRDP_EncryptionMethods: + return settings->EncryptionMethods; + break; + + case FreeRDP_ExtEncryptionMethods: + return settings->ExtEncryptionMethods; + break; + + case FreeRDP_EncryptionLevel: + return settings->EncryptionLevel; + break; + + case FreeRDP_ChannelCount: + return settings->ChannelCount; + break; + + case FreeRDP_ChannelDefArraySize: + return settings->ChannelDefArraySize; + break; + + case FreeRDP_ClusterInfoFlags: + return settings->ClusterInfoFlags; + break; + + case FreeRDP_RedirectedSessionId: + return settings->RedirectedSessionId; + break; + + case FreeRDP_MonitorDefArraySize: + return settings->MonitorDefArraySize; + break; + + case FreeRDP_MultitransportFlags: + return settings->MultitransportFlags; + break; + + case FreeRDP_AutoReconnectMaxRetries: + return settings->AutoReconnectMaxRetries; + break; + + case FreeRDP_PerformanceFlags: + return settings->PerformanceFlags; + break; + + case FreeRDP_RequestedProtocols: + return settings->RequestedProtocols; + break; + + case FreeRDP_SelectedProtocol: + return settings->SelectedProtocol; + break; + + case FreeRDP_NegotiationFlags: + return settings->NegotiationFlags; + break; + + case FreeRDP_CookieMaxLength: + return settings->CookieMaxLength; + break; + + case FreeRDP_PreconnectionId: + return settings->PreconnectionId; + break; + + case FreeRDP_RedirectionFlags: + return settings->RedirectionFlags; + break; + + case FreeRDP_LoadBalanceInfoLength: + return settings->LoadBalanceInfoLength; + break; + + case FreeRDP_RedirectionUsernameLength: + return settings->RedirectionUsernameLength; + break; + + case FreeRDP_RedirectionDomainLength: + return settings->RedirectionDomainLength; + break; + + case FreeRDP_RedirectionPasswordLength: + return settings->RedirectionPasswordLength; + break; + + case FreeRDP_RedirectionTargetFQDNLength: + return settings->RedirectionTargetFQDNLength; + break; + + case FreeRDP_RedirectionTargetNetBiosNameLength: + return settings->RedirectionTargetNetBiosNameLength; + break; + + case FreeRDP_RedirectionTsvUrlLength: + return settings->RedirectionTsvUrlLength; + break; + + case FreeRDP_TargetNetAddressCount: + return settings->TargetNetAddressCount; + break; + + case FreeRDP_PercentScreen: + return settings->PercentScreen; + break; + + case FreeRDP_GatewayPort: + return settings->GatewayPort; + break; + + case FreeRDP_GatewayCredentialsSource: + return settings->GatewayCredentialsSource; + break; + + case FreeRDP_RemoteAppNumIconCaches: + return settings->RemoteAppNumIconCaches; + break; + + case FreeRDP_RemoteAppNumIconCacheEntries: + return settings->RemoteAppNumIconCacheEntries; + break; + + case FreeRDP_ReceivedCapabilitiesSize: + return settings->ReceivedCapabilitiesSize; + break; + + case FreeRDP_OsMajorType: + return settings->OsMajorType; + break; + + case FreeRDP_OsMinorType: + return settings->OsMinorType; + break; + + case FreeRDP_BitmapCacheVersion: + return settings->BitmapCacheVersion; + break; + + case FreeRDP_BitmapCacheV2NumCells: + return settings->BitmapCacheV2NumCells; + break; + + case FreeRDP_PointerCacheSize: + return settings->PointerCacheSize; + break; + + case FreeRDP_KeyboardLayout: + return settings->KeyboardLayout; + break; + + case FreeRDP_KeyboardType: + return settings->KeyboardType; + break; + + case FreeRDP_KeyboardSubType: + return settings->KeyboardSubType; + break; + + case FreeRDP_KeyboardFunctionKey: + return settings->KeyboardFunctionKey; + break; + + case FreeRDP_BrushSupportLevel: + return settings->BrushSupportLevel; + break; + + case FreeRDP_GlyphSupportLevel: + return settings->GlyphSupportLevel; + break; + + case FreeRDP_OffscreenSupportLevel: + return settings->OffscreenSupportLevel; + break; + + case FreeRDP_OffscreenCacheSize: + return settings->OffscreenCacheSize; + break; + + case FreeRDP_OffscreenCacheEntries: + return settings->OffscreenCacheEntries; + break; + + case FreeRDP_VirtualChannelCompressionFlags: + return settings->VirtualChannelCompressionFlags; + break; + + case FreeRDP_VirtualChannelChunkSize: + return settings->VirtualChannelChunkSize; + break; + + case FreeRDP_MultifragMaxRequestSize: + return settings->MultifragMaxRequestSize; + break; + + case FreeRDP_LargePointerFlag: + return settings->LargePointerFlag; + break; + + case FreeRDP_CompDeskSupportLevel: + return settings->CompDeskSupportLevel; + break; + + case FreeRDP_RemoteFxCodecId: + return settings->RemoteFxCodecId; + break; + + case FreeRDP_RemoteFxCodecMode: + return settings->RemoteFxCodecMode; + break; + + case FreeRDP_NSCodecId: + return settings->NSCodecId; + break; + + case FreeRDP_JpegCodecId: + return settings->JpegCodecId; + break; + + case FreeRDP_JpegQuality: + return settings->JpegQuality; + break; + + case FreeRDP_BitmapCacheV3CodecId: + return settings->BitmapCacheV3CodecId; + break; + + case FreeRDP_DrawNineGridCacheSize: + return settings->DrawNineGridCacheSize; + break; + + case FreeRDP_DrawNineGridCacheEntries: + return settings->DrawNineGridCacheEntries; + break; + + case FreeRDP_DeviceCount: + return settings->DeviceCount; + break; + + case FreeRDP_DeviceArraySize: + return settings->DeviceArraySize; + break; + + case FreeRDP_StaticChannelCount: + return settings->StaticChannelCount; + break; + + case FreeRDP_StaticChannelArraySize: + return settings->StaticChannelArraySize; + break; + + case FreeRDP_DynamicChannelCount: + return settings->DynamicChannelCount; + break; + + case FreeRDP_DynamicChannelArraySize: + return settings->DynamicChannelArraySize; + break; + + default: + return 0; + break; + } + + return 0; +} + +int freerdp_set_param_uint32(rdpSettings* settings, int id, UINT32 param) +{ + switch (id) + { + case FreeRDP_ShareId: + settings->ShareId = param; + break; + + case FreeRDP_PduSource: + settings->PduSource = param; + break; + + case FreeRDP_ServerPort: + settings->ServerPort = param; + break; + + case FreeRDP_RdpVersion: + settings->RdpVersion = param; + break; + + case FreeRDP_DesktopWidth: + settings->DesktopWidth = param; + break; + + case FreeRDP_DesktopHeight: + settings->DesktopHeight = param; + break; + + case FreeRDP_ColorDepth: + settings->ColorDepth = param; + break; + + case FreeRDP_ConnectionType: + settings->ConnectionType = param; + break; + + case FreeRDP_ClientBuild: + settings->ClientBuild = param; + break; + + case FreeRDP_EarlyCapabilityFlags: + settings->EarlyCapabilityFlags = param; + break; + + case FreeRDP_EncryptionMethods: + settings->EncryptionMethods = param; + break; + + case FreeRDP_ExtEncryptionMethods: + settings->ExtEncryptionMethods = param; + break; + + case FreeRDP_EncryptionLevel: + settings->EncryptionLevel = param; + break; + + case FreeRDP_ChannelCount: + settings->ChannelCount = param; + break; + + case FreeRDP_ChannelDefArraySize: + settings->ChannelDefArraySize = param; + break; + + case FreeRDP_ClusterInfoFlags: + settings->ClusterInfoFlags = param; + break; + + case FreeRDP_RedirectedSessionId: + settings->RedirectedSessionId = param; + break; + + case FreeRDP_MonitorDefArraySize: + settings->MonitorDefArraySize = param; + break; + + case FreeRDP_MultitransportFlags: + settings->MultitransportFlags = param; + break; + + case FreeRDP_AutoReconnectMaxRetries: + settings->AutoReconnectMaxRetries = param; + break; + + case FreeRDP_PerformanceFlags: + settings->PerformanceFlags = param; + break; + + case FreeRDP_RequestedProtocols: + settings->RequestedProtocols = param; + break; + + case FreeRDP_SelectedProtocol: + settings->SelectedProtocol = param; + break; + + case FreeRDP_NegotiationFlags: + settings->NegotiationFlags = param; + break; + + case FreeRDP_CookieMaxLength: + settings->CookieMaxLength = param; + break; + + case FreeRDP_PreconnectionId: + settings->PreconnectionId = param; + break; + + case FreeRDP_RedirectionFlags: + settings->RedirectionFlags = param; + break; + + case FreeRDP_LoadBalanceInfoLength: + settings->LoadBalanceInfoLength = param; + break; + + case FreeRDP_RedirectionUsernameLength: + settings->RedirectionUsernameLength = param; + break; + + case FreeRDP_RedirectionDomainLength: + settings->RedirectionDomainLength = param; + break; + + case FreeRDP_RedirectionPasswordLength: + settings->RedirectionPasswordLength = param; + break; + + case FreeRDP_RedirectionTargetFQDNLength: + settings->RedirectionTargetFQDNLength = param; + break; + + case FreeRDP_RedirectionTargetNetBiosNameLength: + settings->RedirectionTargetNetBiosNameLength = param; + break; + + case FreeRDP_RedirectionTsvUrlLength: + settings->RedirectionTsvUrlLength = param; + break; + + case FreeRDP_TargetNetAddressCount: + settings->TargetNetAddressCount = param; + break; + + case FreeRDP_PercentScreen: + settings->PercentScreen = param; + break; + + case FreeRDP_GatewayPort: + settings->GatewayPort = param; + break; + + case FreeRDP_GatewayCredentialsSource: + settings->GatewayCredentialsSource = param; + break; + + case FreeRDP_RemoteAppNumIconCaches: + settings->RemoteAppNumIconCaches = param; + break; + + case FreeRDP_RemoteAppNumIconCacheEntries: + settings->RemoteAppNumIconCacheEntries = param; + break; + + case FreeRDP_ReceivedCapabilitiesSize: + settings->ReceivedCapabilitiesSize = param; + break; + + case FreeRDP_OsMajorType: + settings->OsMajorType = param; + break; + + case FreeRDP_OsMinorType: + settings->OsMinorType = param; + break; + + case FreeRDP_BitmapCacheVersion: + settings->BitmapCacheVersion = param; + break; + + case FreeRDP_BitmapCacheV2NumCells: + settings->BitmapCacheV2NumCells = param; + break; + + case FreeRDP_PointerCacheSize: + settings->PointerCacheSize = param; + break; + + case FreeRDP_KeyboardLayout: + settings->KeyboardLayout = param; + break; + + case FreeRDP_KeyboardType: + settings->KeyboardType = param; + break; + + case FreeRDP_KeyboardSubType: + settings->KeyboardSubType = param; + break; + + case FreeRDP_KeyboardFunctionKey: + settings->KeyboardFunctionKey = param; + break; + + case FreeRDP_BrushSupportLevel: + settings->BrushSupportLevel = param; + break; + + case FreeRDP_GlyphSupportLevel: + settings->GlyphSupportLevel = param; + break; + + case FreeRDP_OffscreenSupportLevel: + settings->OffscreenSupportLevel = param; + break; + + case FreeRDP_OffscreenCacheSize: + settings->OffscreenCacheSize = param; + break; + + case FreeRDP_OffscreenCacheEntries: + settings->OffscreenCacheEntries = param; + break; + + case FreeRDP_VirtualChannelCompressionFlags: + settings->VirtualChannelCompressionFlags = param; + break; + + case FreeRDP_VirtualChannelChunkSize: + settings->VirtualChannelChunkSize = param; + break; + + case FreeRDP_MultifragMaxRequestSize: + settings->MultifragMaxRequestSize = param; + break; + + case FreeRDP_LargePointerFlag: + settings->LargePointerFlag = param; + break; + + case FreeRDP_CompDeskSupportLevel: + settings->CompDeskSupportLevel = param; + break; + + case FreeRDP_RemoteFxCodecId: + settings->RemoteFxCodecId = param; + break; + + case FreeRDP_RemoteFxCodecMode: + settings->RemoteFxCodecMode = param; + break; + + case FreeRDP_NSCodecId: + settings->NSCodecId = param; + break; + + case FreeRDP_JpegCodecId: + settings->JpegCodecId = param; + break; + + case FreeRDP_JpegQuality: + settings->JpegQuality = param; + break; + + case FreeRDP_BitmapCacheV3CodecId: + settings->BitmapCacheV3CodecId = param; + break; + + case FreeRDP_DrawNineGridCacheSize: + settings->DrawNineGridCacheSize = param; + break; + + case FreeRDP_DrawNineGridCacheEntries: + settings->DrawNineGridCacheEntries = param; + break; + + case FreeRDP_DeviceCount: + settings->DeviceCount = param; + break; + + case FreeRDP_DeviceArraySize: + settings->DeviceArraySize = param; + break; + + case FreeRDP_StaticChannelCount: + settings->StaticChannelCount = param; + break; + + case FreeRDP_StaticChannelArraySize: + settings->StaticChannelArraySize = param; + break; + + case FreeRDP_DynamicChannelCount: + settings->DynamicChannelCount = param; + break; + + case FreeRDP_DynamicChannelArraySize: + settings->DynamicChannelArraySize = param; + break; + + default: + return -1; + break; + } + + return 0; +} + +UINT64 freerdp_get_param_uint64(rdpSettings* settings, int id) +{ + switch (id) + { + case FreeRDP_ParentWindowId: + return settings->ParentWindowId; + break; + + default: + return -1; + break; + } + + return 0; +} + +int freerdp_set_param_uint64(rdpSettings* settings, int id, UINT64 param) +{ + switch (id) + { + case FreeRDP_ParentWindowId: + settings->ParentWindowId = param; + break; + + default: + return -1; + break; + } + + return 0; +} + +char* freerdp_get_param_string(rdpSettings* settings, int id) +{ + switch (id) + { + case FreeRDP_ServerHostname: + return settings->ServerHostname; + break; + + case FreeRDP_Username: + return settings->Username; + break; + + case FreeRDP_Password: + return settings->Password; + break; + + case FreeRDP_Domain: + return settings->Domain; + break; + + case FreeRDP_ClientHostname: + return settings->ClientHostname; + break; + + case FreeRDP_ClientProductId: + return settings->ClientProductId; + break; + + case FreeRDP_AlternateShell: + return settings->AlternateShell; + break; + + case FreeRDP_ShellWorkingDirectory: + return settings->ShellWorkingDirectory; + break; + + case FreeRDP_ClientAddress: + return settings->ClientAddress; + break; + + case FreeRDP_ClientDir: + return settings->ClientDir; + break; + + case FreeRDP_DynamicDSTTimeZoneKeyName: + return settings->DynamicDSTTimeZoneKeyName; + break; + + case FreeRDP_PreconnectionBlob: + return settings->PreconnectionBlob; + break; + + case FreeRDP_KerberosKdc: + return settings->KerberosKdc; + break; + + case FreeRDP_KerberosRealm: + return settings->KerberosRealm; + break; + + case FreeRDP_CertificateName: + return settings->CertificateName; + break; + + case FreeRDP_CertificateFile: + return settings->CertificateFile; + break; + + case FreeRDP_PrivateKeyFile: + return settings->PrivateKeyFile; + break; + + case FreeRDP_RdpKeyFile: + return settings->RdpKeyFile; + break; + + case FreeRDP_WindowTitle: + return settings->WindowTitle; + break; + + case FreeRDP_ComputerName: + return settings->ComputerName; + break; + + case FreeRDP_ConnectionFile: + return settings->ConnectionFile; + break; + + case FreeRDP_HomePath: + return settings->HomePath; + break; + + case FreeRDP_ConfigPath: + return settings->ConfigPath; + break; + + case FreeRDP_CurrentPath: + return settings->CurrentPath; + break; + + case FreeRDP_DumpRemoteFxFile: + return settings->DumpRemoteFxFile; + break; + + case FreeRDP_PlayRemoteFxFile: + return settings->PlayRemoteFxFile; + break; + + case FreeRDP_GatewayHostname: + return settings->GatewayHostname; + break; + + case FreeRDP_GatewayUsername: + return settings->GatewayUsername; + break; + + case FreeRDP_GatewayPassword: + return settings->GatewayPassword; + break; + + case FreeRDP_GatewayDomain: + return settings->GatewayDomain; + break; + + case FreeRDP_RemoteApplicationName: + return settings->RemoteApplicationName; + break; + + case FreeRDP_RemoteApplicationIcon: + return settings->RemoteApplicationIcon; + break; + + case FreeRDP_RemoteApplicationProgram: + return settings->RemoteApplicationProgram; + break; + + case FreeRDP_RemoteApplicationFile: + return settings->RemoteApplicationFile; + break; + + case FreeRDP_RemoteApplicationGuid: + return settings->RemoteApplicationGuid; + break; + + case FreeRDP_RemoteApplicationCmdLine: + return settings->RemoteApplicationCmdLine; + break; + + case FreeRDP_ImeFileName: + return settings->ImeFileName; + break; + + case FreeRDP_DrivesToRedirect: + return settings->DrivesToRedirect; + break; + + default: + return NULL; + break; + } + + return NULL; +} + +int freerdp_set_param_string(rdpSettings* settings, int id, char* param) +{ + switch (id) + { + case FreeRDP_ServerHostname: + settings->ServerHostname = _strdup(param); + break; + + case FreeRDP_Username: + settings->Username = _strdup(param); + break; + + case FreeRDP_Password: + settings->Password = _strdup(param); + break; + + case FreeRDP_Domain: + settings->Domain = _strdup(param); + break; + + case FreeRDP_ClientHostname: + settings->ClientHostname = _strdup(param); + break; + + case FreeRDP_ClientProductId: + settings->ClientProductId = _strdup(param); + break; + + case FreeRDP_AlternateShell: + settings->AlternateShell = _strdup(param); + break; + + case FreeRDP_ShellWorkingDirectory: + settings->ShellWorkingDirectory = _strdup(param); + break; + + case FreeRDP_ClientAddress: + settings->ClientAddress = _strdup(param); + break; + + case FreeRDP_ClientDir: + settings->ClientDir = _strdup(param); + break; + + case FreeRDP_DynamicDSTTimeZoneKeyName: + settings->DynamicDSTTimeZoneKeyName = _strdup(param); + break; + + case FreeRDP_PreconnectionBlob: + settings->PreconnectionBlob = _strdup(param); + break; + + case FreeRDP_KerberosKdc: + settings->KerberosKdc = _strdup(param); + break; + + case FreeRDP_KerberosRealm: + settings->KerberosRealm = _strdup(param); + break; + + case FreeRDP_CertificateName: + settings->CertificateName = _strdup(param); + break; + + case FreeRDP_CertificateFile: + settings->CertificateFile = _strdup(param); + break; + + case FreeRDP_PrivateKeyFile: + settings->PrivateKeyFile = _strdup(param); + break; + + case FreeRDP_RdpKeyFile: + settings->RdpKeyFile = _strdup(param); + break; + + case FreeRDP_WindowTitle: + settings->WindowTitle = _strdup(param); + break; + + case FreeRDP_ComputerName: + settings->ComputerName = _strdup(param); + break; + + case FreeRDP_ConnectionFile: + settings->ConnectionFile = _strdup(param); + break; + + case FreeRDP_HomePath: + settings->HomePath = _strdup(param); + break; + + case FreeRDP_ConfigPath: + settings->ConfigPath = _strdup(param); + break; + + case FreeRDP_CurrentPath: + settings->CurrentPath = _strdup(param); + break; + + case FreeRDP_DumpRemoteFxFile: + settings->DumpRemoteFxFile = _strdup(param); + break; + + case FreeRDP_PlayRemoteFxFile: + settings->PlayRemoteFxFile = _strdup(param); + break; + + case FreeRDP_GatewayHostname: + settings->GatewayHostname = _strdup(param); + break; + + case FreeRDP_GatewayUsername: + settings->GatewayUsername = _strdup(param); + break; + + case FreeRDP_GatewayPassword: + settings->GatewayPassword = _strdup(param); + break; + + case FreeRDP_GatewayDomain: + settings->GatewayDomain = _strdup(param); + break; + + case FreeRDP_RemoteApplicationName: + settings->RemoteApplicationName = _strdup(param); + break; + + case FreeRDP_RemoteApplicationIcon: + settings->RemoteApplicationIcon = _strdup(param); + break; + + case FreeRDP_RemoteApplicationProgram: + settings->RemoteApplicationProgram = _strdup(param); + break; + + case FreeRDP_RemoteApplicationFile: + settings->RemoteApplicationFile = _strdup(param); + break; + + case FreeRDP_RemoteApplicationGuid: + settings->RemoteApplicationGuid = _strdup(param); + break; + + case FreeRDP_RemoteApplicationCmdLine: + settings->RemoteApplicationCmdLine = _strdup(param); + break; + + case FreeRDP_ImeFileName: + settings->ImeFileName = _strdup(param); + break; + + case FreeRDP_DrivesToRedirect: + settings->DrivesToRedirect = _strdup(param); + break; + + default: + return -1; + break; + } + + return 0; +} diff --git a/libfreerdp/core/activation.c b/libfreerdp/core/activation.c index ca39ce5f9..61c7007dd 100644 --- a/libfreerdp/core/activation.c +++ b/libfreerdp/core/activation.c @@ -34,13 +34,13 @@ static const char* const CTRLACTION_STRINGS[] = }; */ -void rdp_write_synchronize_pdu(STREAM* s, rdpSettings* settings) +void rdp_write_synchronize_pdu(wStream* s, rdpSettings* settings) { stream_write_UINT16(s, SYNCMSGTYPE_SYNC); /* messageType (2 bytes) */ stream_write_UINT16(s, settings->PduSource); /* targetUser (2 bytes) */ } -BOOL rdp_recv_synchronize_pdu(rdpRdp* rdp, STREAM* s) +BOOL rdp_recv_synchronize_pdu(rdpRdp* rdp, wStream* s) { if (rdp->settings->ServerMode) return rdp_recv_server_synchronize_pdu(rdp, s); @@ -48,7 +48,7 @@ BOOL rdp_recv_synchronize_pdu(rdpRdp* rdp, STREAM* s) return rdp_recv_client_synchronize_pdu(rdp, s); } -BOOL rdp_recv_server_synchronize_pdu(rdpRdp* rdp, STREAM* s) +BOOL rdp_recv_server_synchronize_pdu(rdpRdp* rdp, wStream* s) { rdp->finalize_sc_pdus |= FINALIZE_SC_SYNCHRONIZE_PDU; return TRUE; @@ -56,7 +56,7 @@ BOOL rdp_recv_server_synchronize_pdu(rdpRdp* rdp, STREAM* s) BOOL rdp_send_server_synchronize_pdu(rdpRdp* rdp) { - STREAM* s; + wStream* s; s = rdp_data_pdu_init(rdp); @@ -64,7 +64,7 @@ BOOL rdp_send_server_synchronize_pdu(rdpRdp* rdp) return rdp_send_data_pdu(rdp, s, DATA_PDU_TYPE_SYNCHRONIZE, rdp->mcs->user_id); } -BOOL rdp_recv_client_synchronize_pdu(rdpRdp* rdp, STREAM* s) +BOOL rdp_recv_client_synchronize_pdu(rdpRdp* rdp, wStream* s) { UINT16 messageType; @@ -86,7 +86,7 @@ BOOL rdp_recv_client_synchronize_pdu(rdpRdp* rdp, STREAM* s) BOOL rdp_send_client_synchronize_pdu(rdpRdp* rdp) { - STREAM* s; + wStream* s; s = rdp_data_pdu_init(rdp); @@ -95,7 +95,7 @@ BOOL rdp_send_client_synchronize_pdu(rdpRdp* rdp) return rdp_send_data_pdu(rdp, s, DATA_PDU_TYPE_SYNCHRONIZE, rdp->mcs->user_id); } -BOOL rdp_recv_control_pdu(STREAM* s, UINT16* action) +BOOL rdp_recv_control_pdu(wStream* s, UINT16* action) { if (stream_get_left(s) < 8) return FALSE; @@ -107,14 +107,14 @@ BOOL rdp_recv_control_pdu(STREAM* s, UINT16* action) return TRUE; } -void rdp_write_client_control_pdu(STREAM* s, UINT16 action) +void rdp_write_client_control_pdu(wStream* s, UINT16 action) { stream_write_UINT16(s, action); /* action (2 bytes) */ stream_write_UINT16(s, 0); /* grantId (2 bytes) */ stream_write_UINT32(s, 0); /* controlId (4 bytes) */ } -BOOL rdp_recv_server_control_pdu(rdpRdp* rdp, STREAM* s) +BOOL rdp_recv_server_control_pdu(rdpRdp* rdp, wStream* s) { UINT16 action; @@ -137,7 +137,7 @@ BOOL rdp_recv_server_control_pdu(rdpRdp* rdp, STREAM* s) BOOL rdp_send_server_control_cooperate_pdu(rdpRdp* rdp) { - STREAM* s; + wStream* s; s = rdp_data_pdu_init(rdp); @@ -150,7 +150,7 @@ BOOL rdp_send_server_control_cooperate_pdu(rdpRdp* rdp) BOOL rdp_send_server_control_granted_pdu(rdpRdp* rdp) { - STREAM* s; + wStream* s; s = rdp_data_pdu_init(rdp); @@ -163,7 +163,7 @@ BOOL rdp_send_server_control_granted_pdu(rdpRdp* rdp) BOOL rdp_send_client_control_pdu(rdpRdp* rdp, UINT16 action) { - STREAM* s; + wStream* s; s = rdp_data_pdu_init(rdp); rdp_write_client_control_pdu(s, action); @@ -171,13 +171,13 @@ BOOL rdp_send_client_control_pdu(rdpRdp* rdp, UINT16 action) return rdp_send_data_pdu(rdp, s, DATA_PDU_TYPE_CONTROL, rdp->mcs->user_id); } -void rdp_write_persistent_list_entry(STREAM* s, UINT32 key1, UINT32 key2) +void rdp_write_persistent_list_entry(wStream* s, UINT32 key1, UINT32 key2) { stream_write_UINT32(s, key1); /* key1 (4 bytes) */ stream_write_UINT32(s, key2); /* key2 (4 bytes) */ } -void rdp_write_client_persistent_key_list_pdu(STREAM* s, rdpSettings* settings) +void rdp_write_client_persistent_key_list_pdu(wStream* s, rdpSettings* settings) { stream_write_UINT16(s, 0); /* numEntriesCache0 (2 bytes) */ stream_write_UINT16(s, 0); /* numEntriesCache1 (2 bytes) */ @@ -198,7 +198,7 @@ void rdp_write_client_persistent_key_list_pdu(STREAM* s, rdpSettings* settings) BOOL rdp_send_client_persistent_key_list_pdu(rdpRdp* rdp) { - STREAM* s; + wStream* s; s = rdp_data_pdu_init(rdp); rdp_write_client_persistent_key_list_pdu(s, rdp->settings); @@ -206,7 +206,7 @@ BOOL rdp_send_client_persistent_key_list_pdu(rdpRdp* rdp) return rdp_send_data_pdu(rdp, s, DATA_PDU_TYPE_BITMAP_CACHE_PERSISTENT_LIST, rdp->mcs->user_id); } -BOOL rdp_recv_client_font_list_pdu(STREAM* s) +BOOL rdp_recv_client_font_list_pdu(wStream* s) { if (stream_get_left(s) < 8) return FALSE; @@ -214,7 +214,7 @@ BOOL rdp_recv_client_font_list_pdu(STREAM* s) return TRUE; } -void rdp_write_client_font_list_pdu(STREAM* s, UINT16 flags) +void rdp_write_client_font_list_pdu(wStream* s, UINT16 flags) { stream_write_UINT16(s, 0); /* numberFonts (2 bytes) */ stream_write_UINT16(s, 0); /* totalNumFonts (2 bytes) */ @@ -224,7 +224,7 @@ void rdp_write_client_font_list_pdu(STREAM* s, UINT16 flags) BOOL rdp_send_client_font_list_pdu(rdpRdp* rdp, UINT16 flags) { - STREAM* s; + wStream* s; s = rdp_data_pdu_init(rdp); rdp_write_client_font_list_pdu(s, flags); @@ -232,7 +232,7 @@ BOOL rdp_send_client_font_list_pdu(rdpRdp* rdp, UINT16 flags) return rdp_send_data_pdu(rdp, s, DATA_PDU_TYPE_FONT_LIST, rdp->mcs->user_id); } -BOOL rdp_recv_font_map_pdu(rdpRdp* rdp, STREAM* s) +BOOL rdp_recv_font_map_pdu(rdpRdp* rdp, wStream* s) { if (rdp->settings->ServerMode) return rdp_recv_server_font_map_pdu(rdp, s); @@ -240,13 +240,13 @@ BOOL rdp_recv_font_map_pdu(rdpRdp* rdp, STREAM* s) return rdp_recv_client_font_map_pdu(rdp, s); } -BOOL rdp_recv_server_font_map_pdu(rdpRdp* rdp, STREAM* s) +BOOL rdp_recv_server_font_map_pdu(rdpRdp* rdp, wStream* s) { rdp->finalize_sc_pdus |= FINALIZE_SC_FONT_MAP_PDU; return TRUE; } -BOOL rdp_recv_client_font_map_pdu(rdpRdp* rdp, STREAM* s) +BOOL rdp_recv_client_font_map_pdu(rdpRdp* rdp, wStream* s) { rdp->finalize_sc_pdus |= FINALIZE_SC_FONT_MAP_PDU; if(stream_get_left(s) >= 8) @@ -262,7 +262,7 @@ BOOL rdp_recv_client_font_map_pdu(rdpRdp* rdp, STREAM* s) BOOL rdp_send_server_font_map_pdu(rdpRdp* rdp) { - STREAM* s; + wStream* s; s = rdp_data_pdu_init(rdp); @@ -274,7 +274,7 @@ BOOL rdp_send_server_font_map_pdu(rdpRdp* rdp) return rdp_send_data_pdu(rdp, s, DATA_PDU_TYPE_FONT_MAP, rdp->mcs->user_id); } -BOOL rdp_recv_deactivate_all(rdpRdp* rdp, STREAM* s) +BOOL rdp_recv_deactivate_all(rdpRdp* rdp, wStream* s) { UINT16 lengthSourceDescriptor; @@ -312,7 +312,7 @@ BOOL rdp_recv_deactivate_all(rdpRdp* rdp, STREAM* s) BOOL rdp_send_deactivate_all(rdpRdp* rdp) { - STREAM* s; + wStream* s; s = rdp_pdu_init(rdp); @@ -323,7 +323,7 @@ BOOL rdp_send_deactivate_all(rdpRdp* rdp) return rdp_send_pdu(rdp, s, PDU_TYPE_DEACTIVATE_ALL, rdp->mcs->user_id); } -BOOL rdp_server_accept_client_control_pdu(rdpRdp* rdp, STREAM* s) +BOOL rdp_server_accept_client_control_pdu(rdpRdp* rdp, wStream* s) { UINT16 action; @@ -337,7 +337,7 @@ BOOL rdp_server_accept_client_control_pdu(rdpRdp* rdp, STREAM* s) return TRUE; } -BOOL rdp_server_accept_client_font_list_pdu(rdpRdp* rdp, STREAM* s) +BOOL rdp_server_accept_client_font_list_pdu(rdpRdp* rdp, wStream* s) { if (!rdp_recv_client_font_list_pdu(s)) return FALSE; diff --git a/libfreerdp/core/activation.h b/libfreerdp/core/activation.h index 0c1c2540c..e64a2b9d4 100644 --- a/libfreerdp/core/activation.h +++ b/libfreerdp/core/activation.h @@ -37,28 +37,28 @@ #define FONTLIST_FIRST 0x0001 #define FONTLIST_LAST 0x0002 -BOOL rdp_recv_deactivate_all(rdpRdp* rdp, STREAM* s); +BOOL rdp_recv_deactivate_all(rdpRdp* rdp, wStream* s); BOOL rdp_send_deactivate_all(rdpRdp* rdp); -BOOL rdp_recv_synchronize_pdu(rdpRdp* rdp, STREAM* s); -BOOL rdp_recv_server_synchronize_pdu(rdpRdp* rdp, STREAM* s); +BOOL rdp_recv_synchronize_pdu(rdpRdp* rdp, wStream* s); +BOOL rdp_recv_server_synchronize_pdu(rdpRdp* rdp, wStream* s); BOOL rdp_send_server_synchronize_pdu(rdpRdp* rdp); -BOOL rdp_recv_client_synchronize_pdu(rdpRdp* rdp, STREAM* s); +BOOL rdp_recv_client_synchronize_pdu(rdpRdp* rdp, wStream* s); BOOL rdp_send_client_synchronize_pdu(rdpRdp* rdp); -BOOL rdp_recv_control_pdu(STREAM* s, UINT16* action); -BOOL rdp_recv_server_control_pdu(rdpRdp* rdp, STREAM* s); +BOOL rdp_recv_control_pdu(wStream* s, UINT16* action); +BOOL rdp_recv_server_control_pdu(rdpRdp* rdp, wStream* s); BOOL rdp_send_server_control_cooperate_pdu(rdpRdp* rdp); BOOL rdp_send_server_control_granted_pdu(rdpRdp* rdp); BOOL rdp_send_client_control_pdu(rdpRdp* rdp, UINT16 action); BOOL rdp_send_client_persistent_key_list_pdu(rdpRdp* rdp); -BOOL rdp_recv_client_font_list_pdu(STREAM* s); +BOOL rdp_recv_client_font_list_pdu(wStream* s); BOOL rdp_send_client_font_list_pdu(rdpRdp* rdp, UINT16 flags); -BOOL rdp_recv_font_map_pdu(rdpRdp* rdp, STREAM* s); -BOOL rdp_recv_server_font_map_pdu(rdpRdp* rdp, STREAM* s); -BOOL rdp_recv_client_font_map_pdu(rdpRdp* rdp, STREAM* s); +BOOL rdp_recv_font_map_pdu(rdpRdp* rdp, wStream* s); +BOOL rdp_recv_server_font_map_pdu(rdpRdp* rdp, wStream* s); +BOOL rdp_recv_client_font_map_pdu(rdpRdp* rdp, wStream* s); BOOL rdp_send_server_font_map_pdu(rdpRdp* rdp); -BOOL rdp_server_accept_client_control_pdu(rdpRdp* rdp, STREAM* s); -BOOL rdp_server_accept_client_font_list_pdu(rdpRdp* rdp, STREAM* s); +BOOL rdp_server_accept_client_control_pdu(rdpRdp* rdp, wStream* s); +BOOL rdp_server_accept_client_font_list_pdu(rdpRdp* rdp, wStream* s); #endif /* __ACTIVATION_H */ diff --git a/libfreerdp/core/capabilities.c b/libfreerdp/core/capabilities.c index da67ef59b..a927b3cc2 100644 --- a/libfreerdp/core/capabilities.c +++ b/libfreerdp/core/capabilities.c @@ -65,7 +65,7 @@ const char* const CAPSET_TYPE_STRINGS[] = #endif -BOOL rdp_print_capability_sets(STREAM* s, UINT16 numberCapabilities, BOOL receiving); +BOOL rdp_print_capability_sets(wStream* s, UINT16 numberCapabilities, BOOL receiving); /* CODEC_GUID_REMOTEFX: 0x76772F12BD724463AFB3B73C9C6F7886 */ @@ -112,19 +112,19 @@ GUID CODEC_GUID_JPEG = { 0x86, 0x9A, 0xCB, 0x8B, 0x37, 0xB6, 0x62, 0x37 } }; -void rdp_read_capability_set_header(STREAM* s, UINT16* length, UINT16* type) +void rdp_read_capability_set_header(wStream* s, UINT16* length, UINT16* type) { stream_read_UINT16(s, *type); /* capabilitySetType */ stream_read_UINT16(s, *length); /* lengthCapability */ } -void rdp_write_capability_set_header(STREAM* s, UINT16 length, UINT16 type) +void rdp_write_capability_set_header(wStream* s, UINT16 length, UINT16 type) { stream_write_UINT16(s, type); /* capabilitySetType */ stream_write_UINT16(s, length); /* lengthCapability */ } -BYTE* rdp_capability_set_start(STREAM* s) +BYTE* rdp_capability_set_start(wStream* s) { BYTE* header; @@ -134,12 +134,12 @@ BYTE* rdp_capability_set_start(STREAM* s) return header; } -void rdp_capability_set_finish(STREAM* s, BYTE* header, UINT16 type) +void rdp_capability_set_finish(wStream* s, BYTE* header, UINT16 type) { UINT16 length; BYTE* footer; - footer = s->p; + footer = s->pointer; length = footer - header; stream_set_mark(s, header); @@ -155,7 +155,7 @@ void rdp_capability_set_finish(STREAM* s, BYTE* header, UINT16 type) * @return if the operation completed successfully */ -BOOL rdp_read_general_capability_set(STREAM* s, UINT16 length, rdpSettings* settings) +BOOL rdp_read_general_capability_set(wStream* s, UINT16 length, rdpSettings* settings) { UINT16 extraFlags; BYTE refreshRectSupport; @@ -204,7 +204,7 @@ BOOL rdp_read_general_capability_set(STREAM* s, UINT16 length, rdpSettings* sett * @param settings settings */ -void rdp_write_general_capability_set(STREAM* s, rdpSettings* settings) +void rdp_write_general_capability_set(wStream* s, rdpSettings* settings) { BYTE* header; UINT16 extraFlags; @@ -237,7 +237,7 @@ void rdp_write_general_capability_set(STREAM* s, rdpSettings* settings) rdp_capability_set_finish(s, header, CAPSET_TYPE_GENERAL); } -BOOL rdp_print_general_capability_set(STREAM* s, UINT16 length) +BOOL rdp_print_general_capability_set(wStream* s, UINT16 length) { UINT16 osMajorType; UINT16 osMinorType; @@ -254,7 +254,7 @@ BOOL rdp_print_general_capability_set(STREAM* s, UINT16 length) if (length < 24) return FALSE; - printf("GeneralCapabilitySet (length %d):\n", length); + fprintf(stderr, "GeneralCapabilitySet (length %d):\n", length); stream_read_UINT16(s, osMajorType); /* osMajorType (2 bytes) */ stream_read_UINT16(s, osMinorType); /* osMinorType (2 bytes) */ @@ -268,17 +268,17 @@ BOOL rdp_print_general_capability_set(STREAM* s, UINT16 length) stream_read_BYTE(s, refreshRectSupport); /* refreshRectSupport (1 byte) */ stream_read_BYTE(s, suppressOutputSupport); /* suppressOutputSupport (1 byte) */ - printf("\tosMajorType: 0x%04X\n", osMajorType); - printf("\tosMinorType: 0x%04X\n", osMinorType); - printf("\tprotocolVersion: 0x%04X\n", protocolVersion); - printf("\tpad2OctetsA: 0x%04X\n", pad2OctetsA); - printf("\tgeneralCompressionTypes: 0x%04X\n", generalCompressionTypes); - printf("\textraFlags: 0x%04X\n", extraFlags); - printf("\tupdateCapabilityFlag: 0x%04X\n", updateCapabilityFlag); - printf("\tremoteUnshareFlag: 0x%04X\n", remoteUnshareFlag); - printf("\tgeneralCompressionLevel: 0x%04X\n", generalCompressionLevel); - printf("\trefreshRectSupport: 0x%02X\n", refreshRectSupport); - printf("\tsuppressOutputSupport: 0x%02X\n", suppressOutputSupport); + fprintf(stderr, "\tosMajorType: 0x%04X\n", osMajorType); + fprintf(stderr, "\tosMinorType: 0x%04X\n", osMinorType); + fprintf(stderr, "\tprotocolVersion: 0x%04X\n", protocolVersion); + fprintf(stderr, "\tpad2OctetsA: 0x%04X\n", pad2OctetsA); + fprintf(stderr, "\tgeneralCompressionTypes: 0x%04X\n", generalCompressionTypes); + fprintf(stderr, "\textraFlags: 0x%04X\n", extraFlags); + fprintf(stderr, "\tupdateCapabilityFlag: 0x%04X\n", updateCapabilityFlag); + fprintf(stderr, "\tremoteUnshareFlag: 0x%04X\n", remoteUnshareFlag); + fprintf(stderr, "\tgeneralCompressionLevel: 0x%04X\n", generalCompressionLevel); + fprintf(stderr, "\trefreshRectSupport: 0x%02X\n", refreshRectSupport); + fprintf(stderr, "\tsuppressOutputSupport: 0x%02X\n", suppressOutputSupport); return TRUE; } @@ -291,7 +291,7 @@ BOOL rdp_print_general_capability_set(STREAM* s, UINT16 length) * @return if the operation completed successfully */ -BOOL rdp_read_bitmap_capability_set(STREAM* s, UINT16 length, rdpSettings* settings) +BOOL rdp_read_bitmap_capability_set(wStream* s, UINT16 length, rdpSettings* settings) { BYTE drawingFlags; UINT16 desktopWidth; @@ -342,7 +342,7 @@ BOOL rdp_read_bitmap_capability_set(STREAM* s, UINT16 length, rdpSettings* setti * @param settings settings */ -void rdp_write_bitmap_capability_set(STREAM* s, rdpSettings* settings) +void rdp_write_bitmap_capability_set(wStream* s, rdpSettings* settings) { BYTE* header; BYTE drawingFlags = 0; @@ -378,7 +378,7 @@ void rdp_write_bitmap_capability_set(STREAM* s, rdpSettings* settings) rdp_capability_set_finish(s, header, CAPSET_TYPE_BITMAP); } -BOOL rdp_print_bitmap_capability_set(STREAM* s, UINT16 length) +BOOL rdp_print_bitmap_capability_set(wStream* s, UINT16 length) { UINT16 preferredBitsPerPixel; UINT16 receive1BitPerPixel; @@ -394,7 +394,7 @@ BOOL rdp_print_bitmap_capability_set(STREAM* s, UINT16 length) UINT16 multipleRectangleSupport; UINT16 pad2OctetsB; - printf("BitmapCapabilitySet (length %d):\n", length); + fprintf(stderr, "BitmapCapabilitySet (length %d):\n", length); if (length < 28) return FALSE; @@ -413,19 +413,19 @@ BOOL rdp_print_bitmap_capability_set(STREAM* s, UINT16 length) stream_read_UINT16(s, multipleRectangleSupport); /* multipleRectangleSupport (2 bytes) */ stream_read_UINT16(s, pad2OctetsB); /* pad2OctetsB (2 bytes) */ - printf("\tpreferredBitsPerPixel: 0x%04X\n", preferredBitsPerPixel); - printf("\treceive1BitPerPixel: 0x%04X\n", receive1BitPerPixel); - printf("\treceive4BitsPerPixel: 0x%04X\n", receive4BitsPerPixel); - printf("\treceive8BitsPerPixel: 0x%04X\n", receive8BitsPerPixel); - printf("\tdesktopWidth: 0x%04X\n", desktopWidth); - printf("\tdesktopHeight: 0x%04X\n", desktopHeight); - printf("\tpad2Octets: 0x%04X\n", pad2Octets); - printf("\tdesktopResizeFlag: 0x%04X\n", desktopResizeFlag); - printf("\tbitmapCompressionFlag: 0x%04X\n", bitmapCompressionFlag); - printf("\thighColorFlags: 0x%02X\n", highColorFlags); - printf("\tdrawingFlags: 0x%02X\n", drawingFlags); - printf("\tmultipleRectangleSupport: 0x%04X\n", multipleRectangleSupport); - printf("\tpad2OctetsB: 0x%04X\n", pad2OctetsB); + fprintf(stderr, "\tpreferredBitsPerPixel: 0x%04X\n", preferredBitsPerPixel); + fprintf(stderr, "\treceive1BitPerPixel: 0x%04X\n", receive1BitPerPixel); + fprintf(stderr, "\treceive4BitsPerPixel: 0x%04X\n", receive4BitsPerPixel); + fprintf(stderr, "\treceive8BitsPerPixel: 0x%04X\n", receive8BitsPerPixel); + fprintf(stderr, "\tdesktopWidth: 0x%04X\n", desktopWidth); + fprintf(stderr, "\tdesktopHeight: 0x%04X\n", desktopHeight); + fprintf(stderr, "\tpad2Octets: 0x%04X\n", pad2Octets); + fprintf(stderr, "\tdesktopResizeFlag: 0x%04X\n", desktopResizeFlag); + fprintf(stderr, "\tbitmapCompressionFlag: 0x%04X\n", bitmapCompressionFlag); + fprintf(stderr, "\thighColorFlags: 0x%02X\n", highColorFlags); + fprintf(stderr, "\tdrawingFlags: 0x%02X\n", drawingFlags); + fprintf(stderr, "\tmultipleRectangleSupport: 0x%04X\n", multipleRectangleSupport); + fprintf(stderr, "\tpad2OctetsB: 0x%04X\n", pad2OctetsB); return TRUE; } @@ -438,7 +438,7 @@ BOOL rdp_print_bitmap_capability_set(STREAM* s, UINT16 length) * @return if the operation completed successfully */ -BOOL rdp_read_order_capability_set(STREAM* s, UINT16 length, rdpSettings* settings) +BOOL rdp_read_order_capability_set(wStream* s, UINT16 length, rdpSettings* settings) { int i; UINT16 orderFlags; @@ -482,7 +482,7 @@ BOOL rdp_read_order_capability_set(STREAM* s, UINT16 length, rdpSettings* settin * @param settings settings */ -void rdp_write_order_capability_set(STREAM* s, rdpSettings* settings) +void rdp_write_order_capability_set(wStream* s, rdpSettings* settings) { BYTE* header; UINT16 orderFlags; @@ -530,7 +530,7 @@ void rdp_write_order_capability_set(STREAM* s, rdpSettings* settings) rdp_capability_set_finish(s, header, CAPSET_TYPE_ORDER); } -BOOL rdp_print_order_capability_set(STREAM* s, UINT16 length) +BOOL rdp_print_order_capability_set(wStream* s, UINT16 length) { BYTE terminalDescriptor[16]; UINT32 pad4OctetsA; @@ -550,7 +550,7 @@ BOOL rdp_print_order_capability_set(STREAM* s, UINT16 length) UINT16 textANSICodePage; UINT16 pad2OctetsE; - printf("OrderCapabilitySet (length %d):\n", length); + fprintf(stderr, "OrderCapabilitySet (length %d):\n", length); if (length < 88) return FALSE; @@ -573,56 +573,56 @@ BOOL rdp_print_order_capability_set(STREAM* s, UINT16 length) stream_read_UINT16(s, textANSICodePage); /* textANSICodePage (2 bytes) */ stream_read_UINT16(s, pad2OctetsE); /* pad2OctetsE (2 bytes) */ - printf("\tpad4OctetsA: 0x%08X\n", pad4OctetsA); - printf("\tdesktopSaveXGranularity: 0x%04X\n", desktopSaveXGranularity); - printf("\tdesktopSaveYGranularity: 0x%04X\n", desktopSaveYGranularity); - printf("\tpad2OctetsA: 0x%04X\n", pad2OctetsA); - printf("\tmaximumOrderLevel: 0x%04X\n", maximumOrderLevel); - printf("\tnumberFonts: 0x%04X\n", numberFonts); - printf("\torderFlags: 0x%04X\n", orderFlags); + fprintf(stderr, "\tpad4OctetsA: 0x%08X\n", pad4OctetsA); + fprintf(stderr, "\tdesktopSaveXGranularity: 0x%04X\n", desktopSaveXGranularity); + fprintf(stderr, "\tdesktopSaveYGranularity: 0x%04X\n", desktopSaveYGranularity); + fprintf(stderr, "\tpad2OctetsA: 0x%04X\n", pad2OctetsA); + fprintf(stderr, "\tmaximumOrderLevel: 0x%04X\n", maximumOrderLevel); + fprintf(stderr, "\tnumberFonts: 0x%04X\n", numberFonts); + fprintf(stderr, "\torderFlags: 0x%04X\n", orderFlags); - printf("\torderSupport:\n"); - printf("\t\tDSTBLT: %d\n", orderSupport[NEG_DSTBLT_INDEX]); - printf("\t\tPATBLT: %d\n", orderSupport[NEG_PATBLT_INDEX]); - printf("\t\tSCRBLT: %d\n", orderSupport[NEG_SCRBLT_INDEX]); - printf("\t\tMEMBLT: %d\n", orderSupport[NEG_MEMBLT_INDEX]); - printf("\t\tMEM3BLT: %d\n", orderSupport[NEG_MEM3BLT_INDEX]); - printf("\t\tATEXTOUT: %d\n", orderSupport[NEG_ATEXTOUT_INDEX]); - printf("\t\tAEXTTEXTOUT: %d\n", orderSupport[NEG_AEXTTEXTOUT_INDEX]); - printf("\t\tDRAWNINEGRID: %d\n", orderSupport[NEG_DRAWNINEGRID_INDEX]); - printf("\t\tLINETO: %d\n", orderSupport[NEG_LINETO_INDEX]); - printf("\t\tMULTI_DRAWNINEGRID: %d\n", orderSupport[NEG_MULTI_DRAWNINEGRID_INDEX]); - printf("\t\tOPAQUE_RECT: %d\n", orderSupport[NEG_OPAQUE_RECT_INDEX]); - printf("\t\tSAVEBITMAP: %d\n", orderSupport[NEG_SAVEBITMAP_INDEX]); - printf("\t\tWTEXTOUT: %d\n", orderSupport[NEG_WTEXTOUT_INDEX]); - printf("\t\tMEMBLT_V2: %d\n", orderSupport[NEG_MEMBLT_V2_INDEX]); - printf("\t\tMEM3BLT_V2: %d\n", orderSupport[NEG_MEM3BLT_V2_INDEX]); - printf("\t\tMULTIDSTBLT: %d\n", orderSupport[NEG_MULTIDSTBLT_INDEX]); - printf("\t\tMULTIPATBLT: %d\n", orderSupport[NEG_MULTIPATBLT_INDEX]); - printf("\t\tMULTISCRBLT: %d\n", orderSupport[NEG_MULTISCRBLT_INDEX]); - printf("\t\tMULTIOPAQUERECT: %d\n", orderSupport[NEG_MULTIOPAQUERECT_INDEX]); - printf("\t\tFAST_INDEX: %d\n", orderSupport[NEG_FAST_INDEX_INDEX]); - printf("\t\tPOLYGON_SC: %d\n", orderSupport[NEG_POLYGON_SC_INDEX]); - printf("\t\tPOLYGON_CB: %d\n", orderSupport[NEG_POLYGON_CB_INDEX]); - printf("\t\tPOLYLINE: %d\n", orderSupport[NEG_POLYLINE_INDEX]); - printf("\t\tUNUSED23: %d\n", orderSupport[NEG_UNUSED23_INDEX]); - printf("\t\tFAST_GLYPH: %d\n", orderSupport[NEG_FAST_GLYPH_INDEX]); - printf("\t\tELLIPSE_SC: %d\n", orderSupport[NEG_ELLIPSE_SC_INDEX]); - printf("\t\tELLIPSE_CB: %d\n", orderSupport[NEG_ELLIPSE_CB_INDEX]); - printf("\t\tGLYPH_INDEX: %d\n", orderSupport[NEG_GLYPH_INDEX_INDEX]); - printf("\t\tGLYPH_WEXTTEXTOUT: %d\n", orderSupport[NEG_GLYPH_WEXTTEXTOUT_INDEX]); - printf("\t\tGLYPH_WLONGTEXTOUT: %d\n", orderSupport[NEG_GLYPH_WLONGTEXTOUT_INDEX]); - printf("\t\tGLYPH_WLONGEXTTEXTOUT: %d\n", orderSupport[NEG_GLYPH_WLONGEXTTEXTOUT_INDEX]); - printf("\t\tUNUSED31: %d\n", orderSupport[NEG_UNUSED31_INDEX]); + fprintf(stderr, "\torderSupport:\n"); + fprintf(stderr, "\t\tDSTBLT: %d\n", orderSupport[NEG_DSTBLT_INDEX]); + fprintf(stderr, "\t\tPATBLT: %d\n", orderSupport[NEG_PATBLT_INDEX]); + fprintf(stderr, "\t\tSCRBLT: %d\n", orderSupport[NEG_SCRBLT_INDEX]); + fprintf(stderr, "\t\tMEMBLT: %d\n", orderSupport[NEG_MEMBLT_INDEX]); + fprintf(stderr, "\t\tMEM3BLT: %d\n", orderSupport[NEG_MEM3BLT_INDEX]); + fprintf(stderr, "\t\tATEXTOUT: %d\n", orderSupport[NEG_ATEXTOUT_INDEX]); + fprintf(stderr, "\t\tAEXTTEXTOUT: %d\n", orderSupport[NEG_AEXTTEXTOUT_INDEX]); + fprintf(stderr, "\t\tDRAWNINEGRID: %d\n", orderSupport[NEG_DRAWNINEGRID_INDEX]); + fprintf(stderr, "\t\tLINETO: %d\n", orderSupport[NEG_LINETO_INDEX]); + fprintf(stderr, "\t\tMULTI_DRAWNINEGRID: %d\n", orderSupport[NEG_MULTI_DRAWNINEGRID_INDEX]); + fprintf(stderr, "\t\tOPAQUE_RECT: %d\n", orderSupport[NEG_OPAQUE_RECT_INDEX]); + fprintf(stderr, "\t\tSAVEBITMAP: %d\n", orderSupport[NEG_SAVEBITMAP_INDEX]); + fprintf(stderr, "\t\tWTEXTOUT: %d\n", orderSupport[NEG_WTEXTOUT_INDEX]); + fprintf(stderr, "\t\tMEMBLT_V2: %d\n", orderSupport[NEG_MEMBLT_V2_INDEX]); + fprintf(stderr, "\t\tMEM3BLT_V2: %d\n", orderSupport[NEG_MEM3BLT_V2_INDEX]); + fprintf(stderr, "\t\tMULTIDSTBLT: %d\n", orderSupport[NEG_MULTIDSTBLT_INDEX]); + fprintf(stderr, "\t\tMULTIPATBLT: %d\n", orderSupport[NEG_MULTIPATBLT_INDEX]); + fprintf(stderr, "\t\tMULTISCRBLT: %d\n", orderSupport[NEG_MULTISCRBLT_INDEX]); + fprintf(stderr, "\t\tMULTIOPAQUERECT: %d\n", orderSupport[NEG_MULTIOPAQUERECT_INDEX]); + fprintf(stderr, "\t\tFAST_INDEX: %d\n", orderSupport[NEG_FAST_INDEX_INDEX]); + fprintf(stderr, "\t\tPOLYGON_SC: %d\n", orderSupport[NEG_POLYGON_SC_INDEX]); + fprintf(stderr, "\t\tPOLYGON_CB: %d\n", orderSupport[NEG_POLYGON_CB_INDEX]); + fprintf(stderr, "\t\tPOLYLINE: %d\n", orderSupport[NEG_POLYLINE_INDEX]); + fprintf(stderr, "\t\tUNUSED23: %d\n", orderSupport[NEG_UNUSED23_INDEX]); + fprintf(stderr, "\t\tFAST_GLYPH: %d\n", orderSupport[NEG_FAST_GLYPH_INDEX]); + fprintf(stderr, "\t\tELLIPSE_SC: %d\n", orderSupport[NEG_ELLIPSE_SC_INDEX]); + fprintf(stderr, "\t\tELLIPSE_CB: %d\n", orderSupport[NEG_ELLIPSE_CB_INDEX]); + fprintf(stderr, "\t\tGLYPH_INDEX: %d\n", orderSupport[NEG_GLYPH_INDEX_INDEX]); + fprintf(stderr, "\t\tGLYPH_WEXTTEXTOUT: %d\n", orderSupport[NEG_GLYPH_WEXTTEXTOUT_INDEX]); + fprintf(stderr, "\t\tGLYPH_WLONGTEXTOUT: %d\n", orderSupport[NEG_GLYPH_WLONGTEXTOUT_INDEX]); + fprintf(stderr, "\t\tGLYPH_WLONGEXTTEXTOUT: %d\n", orderSupport[NEG_GLYPH_WLONGEXTTEXTOUT_INDEX]); + fprintf(stderr, "\t\tUNUSED31: %d\n", orderSupport[NEG_UNUSED31_INDEX]); - printf("\ttextFlags: 0x%04X\n", textFlags); - printf("\torderSupportExFlags: 0x%04X\n", orderSupportExFlags); - printf("\tpad4OctetsB: 0x%08X\n", pad4OctetsB); - printf("\tdesktopSaveSize: 0x%08X\n", desktopSaveSize); - printf("\tpad2OctetsC: 0x%04X\n", pad2OctetsC); - printf("\tpad2OctetsD: 0x%04X\n", pad2OctetsD); - printf("\ttextANSICodePage: 0x%04X\n", textANSICodePage); - printf("\tpad2OctetsE: 0x%04X\n", pad2OctetsE); + fprintf(stderr, "\ttextFlags: 0x%04X\n", textFlags); + fprintf(stderr, "\torderSupportExFlags: 0x%04X\n", orderSupportExFlags); + fprintf(stderr, "\tpad4OctetsB: 0x%08X\n", pad4OctetsB); + fprintf(stderr, "\tdesktopSaveSize: 0x%08X\n", desktopSaveSize); + fprintf(stderr, "\tpad2OctetsC: 0x%04X\n", pad2OctetsC); + fprintf(stderr, "\tpad2OctetsD: 0x%04X\n", pad2OctetsD); + fprintf(stderr, "\ttextANSICodePage: 0x%04X\n", textANSICodePage); + fprintf(stderr, "\tpad2OctetsE: 0x%04X\n", pad2OctetsE); return TRUE; } @@ -635,7 +635,7 @@ BOOL rdp_print_order_capability_set(STREAM* s, UINT16 length) * @return if the operation completed successfully */ -BOOL rdp_read_bitmap_cache_capability_set(STREAM* s, UINT16 length, rdpSettings* settings) +BOOL rdp_read_bitmap_cache_capability_set(wStream* s, UINT16 length, rdpSettings* settings) { if (length < 40) return FALSE; @@ -663,7 +663,7 @@ BOOL rdp_read_bitmap_cache_capability_set(STREAM* s, UINT16 length, rdpSettings* * @param settings settings */ -void rdp_write_bitmap_cache_capability_set(STREAM* s, rdpSettings* settings) +void rdp_write_bitmap_cache_capability_set(wStream* s, rdpSettings* settings) { int bpp; UINT16 size; @@ -695,7 +695,7 @@ void rdp_write_bitmap_cache_capability_set(STREAM* s, rdpSettings* settings) rdp_capability_set_finish(s, header, CAPSET_TYPE_BITMAP_CACHE); } -BOOL rdp_print_bitmap_cache_capability_set(STREAM* s, UINT16 length) +BOOL rdp_print_bitmap_cache_capability_set(wStream* s, UINT16 length) { UINT32 pad1, pad2, pad3; UINT32 pad4, pad5, pad6; @@ -706,7 +706,7 @@ BOOL rdp_print_bitmap_cache_capability_set(STREAM* s, UINT16 length) UINT16 Cache2Entries; UINT16 Cache2MaximumCellSize; - printf("BitmapCacheCapabilitySet (length %d):\n", length); + fprintf(stderr, "BitmapCacheCapabilitySet (length %d):\n", length); if (length < 40) return FALSE; @@ -724,18 +724,18 @@ BOOL rdp_print_bitmap_cache_capability_set(STREAM* s, UINT16 length) stream_read_UINT16(s, Cache2Entries); /* Cache2Entries (2 bytes) */ stream_read_UINT16(s, Cache2MaximumCellSize); /* Cache2MaximumCellSize (2 bytes) */ - printf("\tpad1: 0x%08X\n", pad1); - printf("\tpad2: 0x%08X\n", pad2); - printf("\tpad3: 0x%08X\n", pad3); - printf("\tpad4: 0x%08X\n", pad4); - printf("\tpad5: 0x%08X\n", pad5); - printf("\tpad6: 0x%08X\n", pad6); - printf("\tCache0Entries: 0x%04X\n", Cache0Entries); - printf("\tCache0MaximumCellSize: 0x%04X\n", Cache0MaximumCellSize); - printf("\tCache1Entries: 0x%04X\n", Cache1Entries); - printf("\tCache1MaximumCellSize: 0x%04X\n", Cache1MaximumCellSize); - printf("\tCache2Entries: 0x%04X\n", Cache2Entries); - printf("\tCache2MaximumCellSize: 0x%04X\n", Cache2MaximumCellSize); + fprintf(stderr, "\tpad1: 0x%08X\n", pad1); + fprintf(stderr, "\tpad2: 0x%08X\n", pad2); + fprintf(stderr, "\tpad3: 0x%08X\n", pad3); + fprintf(stderr, "\tpad4: 0x%08X\n", pad4); + fprintf(stderr, "\tpad5: 0x%08X\n", pad5); + fprintf(stderr, "\tpad6: 0x%08X\n", pad6); + fprintf(stderr, "\tCache0Entries: 0x%04X\n", Cache0Entries); + fprintf(stderr, "\tCache0MaximumCellSize: 0x%04X\n", Cache0MaximumCellSize); + fprintf(stderr, "\tCache1Entries: 0x%04X\n", Cache1Entries); + fprintf(stderr, "\tCache1MaximumCellSize: 0x%04X\n", Cache1MaximumCellSize); + fprintf(stderr, "\tCache2Entries: 0x%04X\n", Cache2Entries); + fprintf(stderr, "\tCache2MaximumCellSize: 0x%04X\n", Cache2MaximumCellSize); return TRUE; } @@ -748,7 +748,7 @@ BOOL rdp_print_bitmap_cache_capability_set(STREAM* s, UINT16 length) * @return if the operation completed successfully */ -BOOL rdp_read_control_capability_set(STREAM* s, UINT16 length, rdpSettings* settings) +BOOL rdp_read_control_capability_set(wStream* s, UINT16 length, rdpSettings* settings) { if (length < 12) return FALSE; @@ -768,7 +768,7 @@ BOOL rdp_read_control_capability_set(STREAM* s, UINT16 length, rdpSettings* sett * @param settings settings */ -void rdp_write_control_capability_set(STREAM* s, rdpSettings* settings) +void rdp_write_control_capability_set(wStream* s, rdpSettings* settings) { BYTE* header; @@ -782,14 +782,14 @@ void rdp_write_control_capability_set(STREAM* s, rdpSettings* settings) rdp_capability_set_finish(s, header, CAPSET_TYPE_CONTROL); } -BOOL rdp_print_control_capability_set(STREAM* s, UINT16 length) +BOOL rdp_print_control_capability_set(wStream* s, UINT16 length) { UINT16 controlFlags; UINT16 remoteDetachFlag; UINT16 controlInterest; UINT16 detachInterest; - printf("ControlCapabilitySet (length %d):\n", length); + fprintf(stderr, "ControlCapabilitySet (length %d):\n", length); if (length < 12) return FALSE; @@ -799,10 +799,10 @@ BOOL rdp_print_control_capability_set(STREAM* s, UINT16 length) stream_read_UINT16(s, controlInterest); /* controlInterest (2 bytes) */ stream_read_UINT16(s, detachInterest); /* detachInterest (2 bytes) */ - printf("\tcontrolFlags: 0x%04X\n", controlFlags); - printf("\tremoteDetachFlag: 0x%04X\n", remoteDetachFlag); - printf("\tcontrolInterest: 0x%04X\n", controlInterest); - printf("\tdetachInterest: 0x%04X\n", detachInterest); + fprintf(stderr, "\tcontrolFlags: 0x%04X\n", controlFlags); + fprintf(stderr, "\tremoteDetachFlag: 0x%04X\n", remoteDetachFlag); + fprintf(stderr, "\tcontrolInterest: 0x%04X\n", controlInterest); + fprintf(stderr, "\tdetachInterest: 0x%04X\n", detachInterest); return TRUE; } @@ -815,7 +815,7 @@ BOOL rdp_print_control_capability_set(STREAM* s, UINT16 length) * @return if the operation completed successfully */ -BOOL rdp_read_window_activation_capability_set(STREAM* s, UINT16 length, rdpSettings* settings) +BOOL rdp_read_window_activation_capability_set(wStream* s, UINT16 length, rdpSettings* settings) { if (length < 12) return FALSE; @@ -835,7 +835,7 @@ BOOL rdp_read_window_activation_capability_set(STREAM* s, UINT16 length, rdpSett * @param settings settings */ -void rdp_write_window_activation_capability_set(STREAM* s, rdpSettings* settings) +void rdp_write_window_activation_capability_set(wStream* s, rdpSettings* settings) { BYTE* header; @@ -849,14 +849,14 @@ void rdp_write_window_activation_capability_set(STREAM* s, rdpSettings* settings rdp_capability_set_finish(s, header, CAPSET_TYPE_ACTIVATION); } -BOOL rdp_print_window_activation_capability_set(STREAM* s, UINT16 length) +BOOL rdp_print_window_activation_capability_set(wStream* s, UINT16 length) { UINT16 helpKeyFlag; UINT16 helpKeyIndexFlag; UINT16 helpExtendedKeyFlag; UINT16 windowManagerKeyFlag; - printf("WindowActivationCapabilitySet (length %d):\n", length); + fprintf(stderr, "WindowActivationCapabilitySet (length %d):\n", length); if (length < 12) return FALSE; @@ -866,10 +866,10 @@ BOOL rdp_print_window_activation_capability_set(STREAM* s, UINT16 length) stream_read_UINT16(s, helpExtendedKeyFlag); /* helpExtendedKeyFlag (2 bytes) */ stream_read_UINT16(s, windowManagerKeyFlag); /* windowManagerKeyFlag (2 bytes) */ - printf("\thelpKeyFlag: 0x%04X\n", helpKeyFlag); - printf("\thelpKeyIndexFlag: 0x%04X\n", helpKeyIndexFlag); - printf("\thelpExtendedKeyFlag: 0x%04X\n", helpExtendedKeyFlag); - printf("\twindowManagerKeyFlag: 0x%04X\n", windowManagerKeyFlag); + fprintf(stderr, "\thelpKeyFlag: 0x%04X\n", helpKeyFlag); + fprintf(stderr, "\thelpKeyIndexFlag: 0x%04X\n", helpKeyIndexFlag); + fprintf(stderr, "\thelpExtendedKeyFlag: 0x%04X\n", helpExtendedKeyFlag); + fprintf(stderr, "\twindowManagerKeyFlag: 0x%04X\n", windowManagerKeyFlag); return TRUE; } @@ -882,7 +882,7 @@ BOOL rdp_print_window_activation_capability_set(STREAM* s, UINT16 length) * @return if the operation completed successfully */ -BOOL rdp_read_pointer_capability_set(STREAM* s, UINT16 length, rdpSettings* settings) +BOOL rdp_read_pointer_capability_set(wStream* s, UINT16 length, rdpSettings* settings) { UINT16 colorPointerFlag; UINT16 colorPointerCacheSize; @@ -912,7 +912,7 @@ BOOL rdp_read_pointer_capability_set(STREAM* s, UINT16 length, rdpSettings* sett * @param settings settings */ -void rdp_write_pointer_capability_set(STREAM* s, rdpSettings* settings) +void rdp_write_pointer_capability_set(wStream* s, rdpSettings* settings) { BYTE* header; UINT16 colorPointerFlag; @@ -932,7 +932,7 @@ void rdp_write_pointer_capability_set(STREAM* s, rdpSettings* settings) rdp_capability_set_finish(s, header, CAPSET_TYPE_POINTER); } -BOOL rdp_print_pointer_capability_set(STREAM* s, UINT16 length) +BOOL rdp_print_pointer_capability_set(wStream* s, UINT16 length) { UINT16 colorPointerFlag; UINT16 colorPointerCacheSize; @@ -941,15 +941,15 @@ BOOL rdp_print_pointer_capability_set(STREAM* s, UINT16 length) if (length < 10) return FALSE; - printf("PointerCapabilitySet (length %d):\n", length); + fprintf(stderr, "PointerCapabilitySet (length %d):\n", length); stream_read_UINT16(s, colorPointerFlag); /* colorPointerFlag (2 bytes) */ stream_read_UINT16(s, colorPointerCacheSize); /* colorPointerCacheSize (2 bytes) */ stream_read_UINT16(s, pointerCacheSize); /* pointerCacheSize (2 bytes) */ - printf("\tcolorPointerFlag: 0x%04X\n", colorPointerFlag); - printf("\tcolorPointerCacheSize: 0x%04X\n", colorPointerCacheSize); - printf("\tpointerCacheSize: 0x%04X\n", pointerCacheSize); + fprintf(stderr, "\tcolorPointerFlag: 0x%04X\n", colorPointerFlag); + fprintf(stderr, "\tcolorPointerCacheSize: 0x%04X\n", colorPointerCacheSize); + fprintf(stderr, "\tpointerCacheSize: 0x%04X\n", pointerCacheSize); return TRUE; } @@ -962,7 +962,7 @@ BOOL rdp_print_pointer_capability_set(STREAM* s, UINT16 length) * @return if the operation completed successfully */ -BOOL rdp_read_share_capability_set(STREAM* s, UINT16 length, rdpSettings* settings) +BOOL rdp_read_share_capability_set(wStream* s, UINT16 length, rdpSettings* settings) { if (length < 8) return FALSE; @@ -980,7 +980,7 @@ BOOL rdp_read_share_capability_set(STREAM* s, UINT16 length, rdpSettings* settin * @param settings settings */ -void rdp_write_share_capability_set(STREAM* s, rdpSettings* settings) +void rdp_write_share_capability_set(wStream* s, rdpSettings* settings) { BYTE* header; UINT16 nodeId; @@ -995,12 +995,12 @@ void rdp_write_share_capability_set(STREAM* s, rdpSettings* settings) rdp_capability_set_finish(s, header, CAPSET_TYPE_SHARE); } -BOOL rdp_print_share_capability_set(STREAM* s, UINT16 length) +BOOL rdp_print_share_capability_set(wStream* s, UINT16 length) { UINT16 nodeId; UINT16 pad2Octets; - printf("ShareCapabilitySet (length %d):\n", length); + fprintf(stderr, "ShareCapabilitySet (length %d):\n", length); if (length < 8) return FALSE; @@ -1008,8 +1008,8 @@ BOOL rdp_print_share_capability_set(STREAM* s, UINT16 length) stream_read_UINT16(s, nodeId); /* nodeId (2 bytes) */ stream_read_UINT16(s, pad2Octets); /* pad2Octets (2 bytes) */ - printf("\tnodeId: 0x%04X\n", nodeId); - printf("\tpad2Octets: 0x%04X\n", pad2Octets); + fprintf(stderr, "\tnodeId: 0x%04X\n", nodeId); + fprintf(stderr, "\tpad2Octets: 0x%04X\n", pad2Octets); return TRUE; } @@ -1022,7 +1022,7 @@ BOOL rdp_print_share_capability_set(STREAM* s, UINT16 length) * @return if the operation completed successfully */ -BOOL rdp_read_color_cache_capability_set(STREAM* s, UINT16 length, rdpSettings* settings) +BOOL rdp_read_color_cache_capability_set(wStream* s, UINT16 length, rdpSettings* settings) { if (length < 8) return FALSE; @@ -1040,7 +1040,7 @@ BOOL rdp_read_color_cache_capability_set(STREAM* s, UINT16 length, rdpSettings* * @param settings settings */ -void rdp_write_color_cache_capability_set(STREAM* s, rdpSettings* settings) +void rdp_write_color_cache_capability_set(wStream* s, rdpSettings* settings) { BYTE* header; @@ -1052,12 +1052,12 @@ void rdp_write_color_cache_capability_set(STREAM* s, rdpSettings* settings) rdp_capability_set_finish(s, header, CAPSET_TYPE_COLOR_CACHE); } -BOOL rdp_print_color_cache_capability_set(STREAM* s, UINT16 length) +BOOL rdp_print_color_cache_capability_set(wStream* s, UINT16 length) { UINT16 colorTableCacheSize; UINT16 pad2Octets; - printf("ColorCacheCapabilitySet (length %d):\n", length); + fprintf(stderr, "ColorCacheCapabilitySet (length %d):\n", length); if (length < 8) return FALSE; @@ -1065,8 +1065,8 @@ BOOL rdp_print_color_cache_capability_set(STREAM* s, UINT16 length) stream_read_UINT16(s, colorTableCacheSize); /* colorTableCacheSize (2 bytes) */ stream_read_UINT16(s, pad2Octets); /* pad2Octets (2 bytes) */ - printf("\tcolorTableCacheSize: 0x%04X\n", colorTableCacheSize); - printf("\tpad2Octets: 0x%04X\n", pad2Octets); + fprintf(stderr, "\tcolorTableCacheSize: 0x%04X\n", colorTableCacheSize); + fprintf(stderr, "\tpad2Octets: 0x%04X\n", pad2Octets); return TRUE; } @@ -1079,7 +1079,7 @@ BOOL rdp_print_color_cache_capability_set(STREAM* s, UINT16 length) * @return if the operation completed successfully */ -BOOL rdp_read_sound_capability_set(STREAM* s, UINT16 length, rdpSettings* settings) +BOOL rdp_read_sound_capability_set(wStream* s, UINT16 length, rdpSettings* settings) { UINT16 soundFlags; @@ -1101,7 +1101,7 @@ BOOL rdp_read_sound_capability_set(STREAM* s, UINT16 length, rdpSettings* settin * @param settings settings */ -void rdp_write_sound_capability_set(STREAM* s, rdpSettings* settings) +void rdp_write_sound_capability_set(wStream* s, rdpSettings* settings) { BYTE* header; UINT16 soundFlags; @@ -1116,12 +1116,12 @@ void rdp_write_sound_capability_set(STREAM* s, rdpSettings* settings) rdp_capability_set_finish(s, header, CAPSET_TYPE_SOUND); } -BOOL rdp_print_sound_capability_set(STREAM* s, UINT16 length) +BOOL rdp_print_sound_capability_set(wStream* s, UINT16 length) { UINT16 soundFlags; UINT16 pad2OctetsA; - printf("SoundCapabilitySet (length %d):\n", length); + fprintf(stderr, "SoundCapabilitySet (length %d):\n", length); if (length < 8) return FALSE; @@ -1129,8 +1129,8 @@ BOOL rdp_print_sound_capability_set(STREAM* s, UINT16 length) stream_read_UINT16(s, soundFlags); /* soundFlags (2 bytes) */ stream_read_UINT16(s, pad2OctetsA); /* pad2OctetsA (2 bytes) */ - printf("\tsoundFlags: 0x%04X\n", soundFlags); - printf("\tpad2OctetsA: 0x%04X\n", pad2OctetsA); + fprintf(stderr, "\tsoundFlags: 0x%04X\n", soundFlags); + fprintf(stderr, "\tpad2OctetsA: 0x%04X\n", pad2OctetsA); return TRUE; } @@ -1143,7 +1143,7 @@ BOOL rdp_print_sound_capability_set(STREAM* s, UINT16 length) * @return if the operation completed successfully */ -BOOL rdp_read_input_capability_set(STREAM* s, UINT16 length, rdpSettings* settings) +BOOL rdp_read_input_capability_set(wStream* s, UINT16 length, rdpSettings* settings) { UINT16 inputFlags; @@ -1196,7 +1196,7 @@ BOOL rdp_read_input_capability_set(STREAM* s, UINT16 length, rdpSettings* settin * @param settings settings */ -void rdp_write_input_capability_set(STREAM* s, rdpSettings* settings) +void rdp_write_input_capability_set(wStream* s, rdpSettings* settings) { BYTE* header; UINT16 inputFlags; @@ -1222,7 +1222,7 @@ void rdp_write_input_capability_set(STREAM* s, rdpSettings* settings) rdp_capability_set_finish(s, header, CAPSET_TYPE_INPUT); } -BOOL rdp_print_input_capability_set(STREAM* s, UINT16 length) +BOOL rdp_print_input_capability_set(wStream* s, UINT16 length) { UINT16 inputFlags; UINT16 pad2OctetsA; @@ -1231,7 +1231,7 @@ BOOL rdp_print_input_capability_set(STREAM* s, UINT16 length) UINT32 keyboardSubType; UINT32 keyboardFunctionKey; - printf("InputCapabilitySet (length %d)\n", length); + fprintf(stderr, "InputCapabilitySet (length %d)\n", length); if (length < 88) return FALSE; @@ -1244,12 +1244,12 @@ BOOL rdp_print_input_capability_set(STREAM* s, UINT16 length) stream_read_UINT32(s, keyboardFunctionKey); /* keyboardFunctionKeys (4 bytes) */ stream_seek(s, 64); /* imeFileName (64 bytes) */ - printf("\tinputFlags: 0x%04X\n", inputFlags); - printf("\tpad2OctetsA: 0x%04X\n", pad2OctetsA); - printf("\tkeyboardLayout: 0x%08X\n", keyboardLayout); - printf("\tkeyboardType: 0x%08X\n", keyboardType); - printf("\tkeyboardSubType: 0x%08X\n", keyboardSubType); - printf("\tkeyboardFunctionKey: 0x%08X\n", keyboardFunctionKey); + fprintf(stderr, "\tinputFlags: 0x%04X\n", inputFlags); + fprintf(stderr, "\tpad2OctetsA: 0x%04X\n", pad2OctetsA); + fprintf(stderr, "\tkeyboardLayout: 0x%08X\n", keyboardLayout); + fprintf(stderr, "\tkeyboardType: 0x%08X\n", keyboardType); + fprintf(stderr, "\tkeyboardSubType: 0x%08X\n", keyboardSubType); + fprintf(stderr, "\tkeyboardFunctionKey: 0x%08X\n", keyboardFunctionKey); return TRUE; } @@ -1262,7 +1262,7 @@ BOOL rdp_print_input_capability_set(STREAM* s, UINT16 length) * @return if the operation completed successfully */ -BOOL rdp_read_font_capability_set(STREAM* s, UINT16 length, rdpSettings* settings) +BOOL rdp_read_font_capability_set(wStream* s, UINT16 length, rdpSettings* settings) { if (length > 4) stream_seek_UINT16(s); /* fontSupportFlags (2 bytes) */ @@ -1280,7 +1280,7 @@ BOOL rdp_read_font_capability_set(STREAM* s, UINT16 length, rdpSettings* setting * @param settings settings */ -void rdp_write_font_capability_set(STREAM* s, rdpSettings* settings) +void rdp_write_font_capability_set(wStream* s, rdpSettings* settings) { BYTE* header; @@ -1292,12 +1292,12 @@ void rdp_write_font_capability_set(STREAM* s, rdpSettings* settings) rdp_capability_set_finish(s, header, CAPSET_TYPE_FONT); } -BOOL rdp_print_font_capability_set(STREAM* s, UINT16 length) +BOOL rdp_print_font_capability_set(wStream* s, UINT16 length) { UINT16 fontSupportFlags = 0; UINT16 pad2Octets = 0; - printf("FontCapabilitySet (length %d):\n", length); + fprintf(stderr, "FontCapabilitySet (length %d):\n", length); if (length > 4) stream_read_UINT16(s, fontSupportFlags); /* fontSupportFlags (2 bytes) */ @@ -1305,8 +1305,8 @@ BOOL rdp_print_font_capability_set(STREAM* s, UINT16 length) if (length > 6) stream_read_UINT16(s, pad2Octets); /* pad2Octets (2 bytes) */ - printf("\tfontSupportFlags: 0x%04X\n", fontSupportFlags); - printf("\tpad2Octets: 0x%04X\n", pad2Octets); + fprintf(stderr, "\tfontSupportFlags: 0x%04X\n", fontSupportFlags); + fprintf(stderr, "\tpad2Octets: 0x%04X\n", pad2Octets); return TRUE; } @@ -1319,7 +1319,7 @@ BOOL rdp_print_font_capability_set(STREAM* s, UINT16 length) * @return if the operation completed successfully */ -BOOL rdp_read_brush_capability_set(STREAM* s, UINT16 length, rdpSettings* settings) +BOOL rdp_read_brush_capability_set(wStream* s, UINT16 length, rdpSettings* settings) { if (length < 8) return FALSE; @@ -1336,7 +1336,7 @@ BOOL rdp_read_brush_capability_set(STREAM* s, UINT16 length, rdpSettings* settin * @param settings settings */ -void rdp_write_brush_capability_set(STREAM* s, rdpSettings* settings) +void rdp_write_brush_capability_set(wStream* s, rdpSettings* settings) { BYTE* header; @@ -1347,18 +1347,18 @@ void rdp_write_brush_capability_set(STREAM* s, rdpSettings* settings) rdp_capability_set_finish(s, header, CAPSET_TYPE_BRUSH); } -BOOL rdp_print_brush_capability_set(STREAM* s, UINT16 length) +BOOL rdp_print_brush_capability_set(wStream* s, UINT16 length) { UINT32 brushSupportLevel; - printf("BrushCapabilitySet (length %d):\n", length); + fprintf(stderr, "BrushCapabilitySet (length %d):\n", length); if (length < 8) return FALSE; stream_read_UINT32(s, brushSupportLevel); /* brushSupportLevel (4 bytes) */ - printf("\tbrushSupportLevel: 0x%08X\n", brushSupportLevel); + fprintf(stderr, "\tbrushSupportLevel: 0x%08X\n", brushSupportLevel); return TRUE; } @@ -1368,7 +1368,7 @@ BOOL rdp_print_brush_capability_set(STREAM* s, UINT16 length) * @msdn{cc240566} * @param s stream */ -void rdp_read_cache_definition(STREAM* s, GLYPH_CACHE_DEFINITION* cache_definition) +void rdp_read_cache_definition(wStream* s, GLYPH_CACHE_DEFINITION* cache_definition) { stream_read_UINT16(s, cache_definition->cacheEntries); /* cacheEntries (2 bytes) */ stream_read_UINT16(s, cache_definition->cacheMaximumCellSize); /* cacheMaximumCellSize (2 bytes) */ @@ -1379,7 +1379,7 @@ void rdp_read_cache_definition(STREAM* s, GLYPH_CACHE_DEFINITION* cache_definiti * @msdn{cc240566} * @param s stream */ -void rdp_write_cache_definition(STREAM* s, GLYPH_CACHE_DEFINITION* cache_definition) +void rdp_write_cache_definition(wStream* s, GLYPH_CACHE_DEFINITION* cache_definition) { stream_write_UINT16(s, cache_definition->cacheEntries); /* cacheEntries (2 bytes) */ stream_write_UINT16(s, cache_definition->cacheMaximumCellSize); /* cacheMaximumCellSize (2 bytes) */ @@ -1393,7 +1393,7 @@ void rdp_write_cache_definition(STREAM* s, GLYPH_CACHE_DEFINITION* cache_definit * @return if the operation completed successfully */ -BOOL rdp_read_glyph_cache_capability_set(STREAM* s, UINT16 length, rdpSettings* settings) +BOOL rdp_read_glyph_cache_capability_set(wStream* s, UINT16 length, rdpSettings* settings) { UINT16 glyphSupportLevel; @@ -1417,7 +1417,7 @@ BOOL rdp_read_glyph_cache_capability_set(STREAM* s, UINT16 length, rdpSettings* * @param settings settings */ -void rdp_write_glyph_cache_capability_set(STREAM* s, rdpSettings* settings) +void rdp_write_glyph_cache_capability_set(wStream* s, rdpSettings* settings) { BYTE* header; @@ -1443,14 +1443,14 @@ void rdp_write_glyph_cache_capability_set(STREAM* s, rdpSettings* settings) rdp_capability_set_finish(s, header, CAPSET_TYPE_GLYPH_CACHE); } -BOOL rdp_print_glyph_cache_capability_set(STREAM* s, UINT16 length) +BOOL rdp_print_glyph_cache_capability_set(wStream* s, UINT16 length) { GLYPH_CACHE_DEFINITION glyphCache[10]; GLYPH_CACHE_DEFINITION fragCache; UINT16 glyphSupportLevel; UINT16 pad2Octets; - printf("GlyphCacheCapabilitySet (length %d):\n", length); + fprintf(stderr, "GlyphCacheCapabilitySet (length %d):\n", length); if (length < 52) return FALSE; @@ -1471,19 +1471,19 @@ BOOL rdp_print_glyph_cache_capability_set(STREAM* s, UINT16 length) stream_read_UINT16(s, glyphSupportLevel); /* glyphSupportLevel (2 bytes) */ stream_read_UINT16(s, pad2Octets); /* pad2Octets (2 bytes) */ - printf("\tglyphCache0: Entries: %d MaximumCellSize: %d\n", glyphCache[0].cacheEntries, glyphCache[0].cacheMaximumCellSize); - printf("\tglyphCache1: Entries: %d MaximumCellSize: %d\n", glyphCache[1].cacheEntries, glyphCache[1].cacheMaximumCellSize); - printf("\tglyphCache2: Entries: %d MaximumCellSize: %d\n", glyphCache[2].cacheEntries, glyphCache[2].cacheMaximumCellSize); - printf("\tglyphCache3: Entries: %d MaximumCellSize: %d\n", glyphCache[3].cacheEntries, glyphCache[3].cacheMaximumCellSize); - printf("\tglyphCache4: Entries: %d MaximumCellSize: %d\n", glyphCache[4].cacheEntries, glyphCache[4].cacheMaximumCellSize); - printf("\tglyphCache5: Entries: %d MaximumCellSize: %d\n", glyphCache[5].cacheEntries, glyphCache[5].cacheMaximumCellSize); - printf("\tglyphCache6: Entries: %d MaximumCellSize: %d\n", glyphCache[6].cacheEntries, glyphCache[6].cacheMaximumCellSize); - printf("\tglyphCache7: Entries: %d MaximumCellSize: %d\n", glyphCache[7].cacheEntries, glyphCache[7].cacheMaximumCellSize); - printf("\tglyphCache8: Entries: %d MaximumCellSize: %d\n", glyphCache[8].cacheEntries, glyphCache[8].cacheMaximumCellSize); - printf("\tglyphCache9: Entries: %d MaximumCellSize: %d\n", glyphCache[9].cacheEntries, glyphCache[9].cacheMaximumCellSize); - printf("\tfragCache: Entries: %d MaximumCellSize: %d\n", fragCache.cacheEntries, fragCache.cacheMaximumCellSize); - printf("\tglyphSupportLevel: 0x%04X\n", glyphSupportLevel); - printf("\tpad2Octets: 0x%04X\n", pad2Octets); + fprintf(stderr, "\tglyphCache0: Entries: %d MaximumCellSize: %d\n", glyphCache[0].cacheEntries, glyphCache[0].cacheMaximumCellSize); + fprintf(stderr, "\tglyphCache1: Entries: %d MaximumCellSize: %d\n", glyphCache[1].cacheEntries, glyphCache[1].cacheMaximumCellSize); + fprintf(stderr, "\tglyphCache2: Entries: %d MaximumCellSize: %d\n", glyphCache[2].cacheEntries, glyphCache[2].cacheMaximumCellSize); + fprintf(stderr, "\tglyphCache3: Entries: %d MaximumCellSize: %d\n", glyphCache[3].cacheEntries, glyphCache[3].cacheMaximumCellSize); + fprintf(stderr, "\tglyphCache4: Entries: %d MaximumCellSize: %d\n", glyphCache[4].cacheEntries, glyphCache[4].cacheMaximumCellSize); + fprintf(stderr, "\tglyphCache5: Entries: %d MaximumCellSize: %d\n", glyphCache[5].cacheEntries, glyphCache[5].cacheMaximumCellSize); + fprintf(stderr, "\tglyphCache6: Entries: %d MaximumCellSize: %d\n", glyphCache[6].cacheEntries, glyphCache[6].cacheMaximumCellSize); + fprintf(stderr, "\tglyphCache7: Entries: %d MaximumCellSize: %d\n", glyphCache[7].cacheEntries, glyphCache[7].cacheMaximumCellSize); + fprintf(stderr, "\tglyphCache8: Entries: %d MaximumCellSize: %d\n", glyphCache[8].cacheEntries, glyphCache[8].cacheMaximumCellSize); + fprintf(stderr, "\tglyphCache9: Entries: %d MaximumCellSize: %d\n", glyphCache[9].cacheEntries, glyphCache[9].cacheMaximumCellSize); + fprintf(stderr, "\tfragCache: Entries: %d MaximumCellSize: %d\n", fragCache.cacheEntries, fragCache.cacheMaximumCellSize); + fprintf(stderr, "\tglyphSupportLevel: 0x%04X\n", glyphSupportLevel); + fprintf(stderr, "\tpad2Octets: 0x%04X\n", pad2Octets); return TRUE; } @@ -1496,7 +1496,7 @@ BOOL rdp_print_glyph_cache_capability_set(STREAM* s, UINT16 length) * @return if the operation completed successfully */ -BOOL rdp_read_offscreen_bitmap_cache_capability_set(STREAM* s, UINT16 length, rdpSettings* settings) +BOOL rdp_read_offscreen_bitmap_cache_capability_set(wStream* s, UINT16 length, rdpSettings* settings) { UINT32 offscreenSupportLevel; @@ -1520,7 +1520,7 @@ BOOL rdp_read_offscreen_bitmap_cache_capability_set(STREAM* s, UINT16 length, rd * @param settings settings */ -void rdp_write_offscreen_bitmap_cache_capability_set(STREAM* s, rdpSettings* settings) +void rdp_write_offscreen_bitmap_cache_capability_set(wStream* s, rdpSettings* settings) { BYTE* header; UINT32 offscreenSupportLevel = FALSE; @@ -1537,13 +1537,13 @@ void rdp_write_offscreen_bitmap_cache_capability_set(STREAM* s, rdpSettings* set rdp_capability_set_finish(s, header, CAPSET_TYPE_OFFSCREEN_CACHE); } -BOOL rdp_print_offscreen_bitmap_cache_capability_set(STREAM* s, UINT16 length) +BOOL rdp_print_offscreen_bitmap_cache_capability_set(wStream* s, UINT16 length) { UINT32 offscreenSupportLevel; UINT16 offscreenCacheSize; UINT16 offscreenCacheEntries; - printf("OffscreenBitmapCacheCapabilitySet (length %d):\n", length); + fprintf(stderr, "OffscreenBitmapCacheCapabilitySet (length %d):\n", length); if (length < 12) return FALSE; @@ -1552,9 +1552,9 @@ BOOL rdp_print_offscreen_bitmap_cache_capability_set(STREAM* s, UINT16 length) stream_read_UINT16(s, offscreenCacheSize); /* offscreenCacheSize (2 bytes) */ stream_read_UINT16(s, offscreenCacheEntries); /* offscreenCacheEntries (2 bytes) */ - printf("\toffscreenSupportLevel: 0x%08X\n", offscreenSupportLevel); - printf("\toffscreenCacheSize: 0x%04X\n", offscreenCacheSize); - printf("\toffscreenCacheEntries: 0x%04X\n", offscreenCacheEntries); + fprintf(stderr, "\toffscreenSupportLevel: 0x%08X\n", offscreenSupportLevel); + fprintf(stderr, "\toffscreenCacheSize: 0x%04X\n", offscreenCacheSize); + fprintf(stderr, "\toffscreenCacheEntries: 0x%04X\n", offscreenCacheEntries); return TRUE; } @@ -1567,7 +1567,7 @@ BOOL rdp_print_offscreen_bitmap_cache_capability_set(STREAM* s, UINT16 length) * @return if the operation completed successfully */ -BOOL rdp_read_bitmap_cache_host_support_capability_set(STREAM* s, UINT16 length, rdpSettings* settings) +BOOL rdp_read_bitmap_cache_host_support_capability_set(wStream* s, UINT16 length, rdpSettings* settings) { BYTE cacheVersion; @@ -1591,7 +1591,7 @@ BOOL rdp_read_bitmap_cache_host_support_capability_set(STREAM* s, UINT16 length, * @param settings settings */ -void rdp_write_bitmap_cache_host_support_capability_set(STREAM* s, rdpSettings* settings) +void rdp_write_bitmap_cache_host_support_capability_set(wStream* s, rdpSettings* settings) { BYTE* header; @@ -1604,13 +1604,13 @@ void rdp_write_bitmap_cache_host_support_capability_set(STREAM* s, rdpSettings* rdp_capability_set_finish(s, header, CAPSET_TYPE_BITMAP_CACHE_HOST_SUPPORT); } -BOOL rdp_print_bitmap_cache_host_support_capability_set(STREAM* s, UINT16 length) +BOOL rdp_print_bitmap_cache_host_support_capability_set(wStream* s, UINT16 length) { BYTE cacheVersion; BYTE pad1; UINT16 pad2; - printf("BitmapCacheHostSupportCapabilitySet (length %d):\n", length); + fprintf(stderr, "BitmapCacheHostSupportCapabilitySet (length %d):\n", length); if (length < 8) return FALSE; @@ -1619,14 +1619,14 @@ BOOL rdp_print_bitmap_cache_host_support_capability_set(STREAM* s, UINT16 length stream_read_BYTE(s, pad1); /* pad1 (1 byte) */ stream_read_UINT16(s, pad2); /* pad2 (2 bytes) */ - printf("\tcacheVersion: 0x%02X\n", cacheVersion); - printf("\tpad1: 0x%02X\n", pad1); - printf("\tpad2: 0x%04X\n", pad2); + fprintf(stderr, "\tcacheVersion: 0x%02X\n", cacheVersion); + fprintf(stderr, "\tpad1: 0x%02X\n", pad1); + fprintf(stderr, "\tpad2: 0x%04X\n", pad2); return TRUE; } -void rdp_read_bitmap_cache_cell_info(STREAM* s, BITMAP_CACHE_V2_CELL_INFO* cellInfo) +void rdp_read_bitmap_cache_cell_info(wStream* s, BITMAP_CACHE_V2_CELL_INFO* cellInfo) { UINT32 info; @@ -1641,7 +1641,7 @@ void rdp_read_bitmap_cache_cell_info(STREAM* s, BITMAP_CACHE_V2_CELL_INFO* cellI cellInfo->persistent = (info & 0x80000000) ? 1 : 0; } -void rdp_write_bitmap_cache_cell_info(STREAM* s, BITMAP_CACHE_V2_CELL_INFO* cellInfo) +void rdp_write_bitmap_cache_cell_info(wStream* s, BITMAP_CACHE_V2_CELL_INFO* cellInfo) { UINT32 info; @@ -1662,7 +1662,7 @@ void rdp_write_bitmap_cache_cell_info(STREAM* s, BITMAP_CACHE_V2_CELL_INFO* cell * @return if the operation completed successfully */ -BOOL rdp_read_bitmap_cache_v2_capability_set(STREAM* s, UINT16 length, rdpSettings* settings) +BOOL rdp_read_bitmap_cache_v2_capability_set(wStream* s, UINT16 length, rdpSettings* settings) { if (length < 40) return FALSE; @@ -1687,7 +1687,7 @@ BOOL rdp_read_bitmap_cache_v2_capability_set(STREAM* s, UINT16 length, rdpSettin * @param settings settings */ -void rdp_write_bitmap_cache_v2_capability_set(STREAM* s, rdpSettings* settings) +void rdp_write_bitmap_cache_v2_capability_set(wStream* s, rdpSettings* settings) { BYTE* header; UINT16 cacheFlags; @@ -1712,14 +1712,14 @@ void rdp_write_bitmap_cache_v2_capability_set(STREAM* s, rdpSettings* settings) rdp_capability_set_finish(s, header, CAPSET_TYPE_BITMAP_CACHE_V2); } -BOOL rdp_print_bitmap_cache_v2_capability_set(STREAM* s, UINT16 length) +BOOL rdp_print_bitmap_cache_v2_capability_set(wStream* s, UINT16 length) { UINT16 cacheFlags; BYTE pad2; BYTE numCellCaches; BITMAP_CACHE_V2_CELL_INFO bitmapCacheV2CellInfo[5]; - printf("BitmapCacheV2CapabilitySet (length %d):\n", length); + fprintf(stderr, "BitmapCacheV2CapabilitySet (length %d):\n", length); if (length < 40) return FALSE; @@ -1734,14 +1734,14 @@ BOOL rdp_print_bitmap_cache_v2_capability_set(STREAM* s, UINT16 length) rdp_read_bitmap_cache_cell_info(s, &bitmapCacheV2CellInfo[4]); /* bitmapCache4CellInfo (4 bytes) */ stream_seek(s, 12); /* pad3 (12 bytes) */ - printf("\tcacheFlags: 0x%04X\n", cacheFlags); - printf("\tpad2: 0x%02X\n", pad2); - printf("\tnumCellCaches: 0x%02X\n", numCellCaches); - printf("\tbitmapCache0CellInfo: numEntries: %d persistent: %d\n", bitmapCacheV2CellInfo[0].numEntries, bitmapCacheV2CellInfo[0].persistent); - printf("\tbitmapCache1CellInfo: numEntries: %d persistent: %d\n", bitmapCacheV2CellInfo[1].numEntries, bitmapCacheV2CellInfo[1].persistent); - printf("\tbitmapCache2CellInfo: numEntries: %d persistent: %d\n", bitmapCacheV2CellInfo[2].numEntries, bitmapCacheV2CellInfo[2].persistent); - printf("\tbitmapCache3CellInfo: numEntries: %d persistent: %d\n", bitmapCacheV2CellInfo[3].numEntries, bitmapCacheV2CellInfo[3].persistent); - printf("\tbitmapCache4CellInfo: numEntries: %d persistent: %d\n", bitmapCacheV2CellInfo[4].numEntries, bitmapCacheV2CellInfo[4].persistent); + fprintf(stderr, "\tcacheFlags: 0x%04X\n", cacheFlags); + fprintf(stderr, "\tpad2: 0x%02X\n", pad2); + fprintf(stderr, "\tnumCellCaches: 0x%02X\n", numCellCaches); + fprintf(stderr, "\tbitmapCache0CellInfo: numEntries: %d persistent: %d\n", bitmapCacheV2CellInfo[0].numEntries, bitmapCacheV2CellInfo[0].persistent); + fprintf(stderr, "\tbitmapCache1CellInfo: numEntries: %d persistent: %d\n", bitmapCacheV2CellInfo[1].numEntries, bitmapCacheV2CellInfo[1].persistent); + fprintf(stderr, "\tbitmapCache2CellInfo: numEntries: %d persistent: %d\n", bitmapCacheV2CellInfo[2].numEntries, bitmapCacheV2CellInfo[2].persistent); + fprintf(stderr, "\tbitmapCache3CellInfo: numEntries: %d persistent: %d\n", bitmapCacheV2CellInfo[3].numEntries, bitmapCacheV2CellInfo[3].persistent); + fprintf(stderr, "\tbitmapCache4CellInfo: numEntries: %d persistent: %d\n", bitmapCacheV2CellInfo[4].numEntries, bitmapCacheV2CellInfo[4].persistent); return TRUE; } @@ -1754,7 +1754,7 @@ BOOL rdp_print_bitmap_cache_v2_capability_set(STREAM* s, UINT16 length) * @return if the operation completed successfully */ -BOOL rdp_read_virtual_channel_capability_set(STREAM* s, UINT16 length, rdpSettings* settings) +BOOL rdp_read_virtual_channel_capability_set(wStream* s, UINT16 length, rdpSettings* settings) { UINT32 flags; UINT32 VCChunkSize; @@ -1782,7 +1782,7 @@ BOOL rdp_read_virtual_channel_capability_set(STREAM* s, UINT16 length, rdpSettin * @param settings settings */ -void rdp_write_virtual_channel_capability_set(STREAM* s, rdpSettings* settings) +void rdp_write_virtual_channel_capability_set(wStream* s, rdpSettings* settings) { BYTE* header; UINT32 flags; @@ -1797,12 +1797,12 @@ void rdp_write_virtual_channel_capability_set(STREAM* s, rdpSettings* settings) rdp_capability_set_finish(s, header, CAPSET_TYPE_VIRTUAL_CHANNEL); } -BOOL rdp_print_virtual_channel_capability_set(STREAM* s, UINT16 length) +BOOL rdp_print_virtual_channel_capability_set(wStream* s, UINT16 length) { UINT32 flags; UINT32 VCChunkSize; - printf("VirtualChannelCapabilitySet (length %d):\n", length); + fprintf(stderr, "VirtualChannelCapabilitySet (length %d):\n", length); if (length < 8) return FALSE; @@ -1814,8 +1814,8 @@ BOOL rdp_print_virtual_channel_capability_set(STREAM* s, UINT16 length) else VCChunkSize = 1600; - printf("\tflags: 0x%08X\n", flags); - printf("\tVCChunkSize: 0x%08X\n", VCChunkSize); + fprintf(stderr, "\tflags: 0x%08X\n", flags); + fprintf(stderr, "\tVCChunkSize: 0x%08X\n", VCChunkSize); return TRUE; } @@ -1828,7 +1828,7 @@ BOOL rdp_print_virtual_channel_capability_set(STREAM* s, UINT16 length) * @return if the operation completed successfully */ -BOOL rdp_read_draw_nine_grid_cache_capability_set(STREAM* s, UINT16 length, rdpSettings* settings) +BOOL rdp_read_draw_nine_grid_cache_capability_set(wStream* s, UINT16 length, rdpSettings* settings) { UINT32 drawNineGridSupportLevel; @@ -1853,7 +1853,7 @@ BOOL rdp_read_draw_nine_grid_cache_capability_set(STREAM* s, UINT16 length, rdpS * @param settings settings */ -void rdp_write_draw_nine_grid_cache_capability_set(STREAM* s, rdpSettings* settings) +void rdp_write_draw_nine_grid_cache_capability_set(wStream* s, rdpSettings* settings) { BYTE* header; UINT32 drawNineGridSupportLevel; @@ -1869,7 +1869,7 @@ void rdp_write_draw_nine_grid_cache_capability_set(STREAM* s, rdpSettings* setti rdp_capability_set_finish(s, header, CAPSET_TYPE_DRAW_NINE_GRID_CACHE); } -void rdp_write_gdiplus_cache_entries(STREAM* s, UINT16 gce, UINT16 bce, UINT16 pce, UINT16 ice, UINT16 ace) +void rdp_write_gdiplus_cache_entries(wStream* s, UINT16 gce, UINT16 bce, UINT16 pce, UINT16 ice, UINT16 ace) { stream_write_UINT16(s, gce); /* gdipGraphicsCacheEntries (2 bytes) */ stream_write_UINT16(s, bce); /* gdipBrushCacheEntries (2 bytes) */ @@ -1878,7 +1878,7 @@ void rdp_write_gdiplus_cache_entries(STREAM* s, UINT16 gce, UINT16 bce, UINT16 p stream_write_UINT16(s, ace); /* gdipImageAttributesCacheEntries (2 bytes) */ } -void rdp_write_gdiplus_cache_chunk_size(STREAM* s, UINT16 gccs, UINT16 obccs, UINT16 opccs, UINT16 oiaccs) +void rdp_write_gdiplus_cache_chunk_size(wStream* s, UINT16 gccs, UINT16 obccs, UINT16 opccs, UINT16 oiaccs) { stream_write_UINT16(s, gccs); /* gdipGraphicsCacheChunkSize (2 bytes) */ stream_write_UINT16(s, obccs); /* gdipObjectBrushCacheChunkSize (2 bytes) */ @@ -1886,20 +1886,20 @@ void rdp_write_gdiplus_cache_chunk_size(STREAM* s, UINT16 gccs, UINT16 obccs, UI stream_write_UINT16(s, oiaccs); /* gdipObjectImageAttributesCacheChunkSize (2 bytes) */ } -void rdp_write_gdiplus_image_cache_properties(STREAM* s, UINT16 oiccs, UINT16 oicts, UINT16 oicms) +void rdp_write_gdiplus_image_cache_properties(wStream* s, UINT16 oiccs, UINT16 oicts, UINT16 oicms) { stream_write_UINT16(s, oiccs); /* gdipObjectImageCacheChunkSize (2 bytes) */ stream_write_UINT16(s, oicts); /* gdipObjectImageCacheTotalSize (2 bytes) */ stream_write_UINT16(s, oicms); /* gdipObjectImageCacheMaxSize (2 bytes) */ } -BOOL rdp_print_draw_nine_grid_cache_capability_set(STREAM* s, UINT16 length) +BOOL rdp_print_draw_nine_grid_cache_capability_set(wStream* s, UINT16 length) { UINT32 drawNineGridSupportLevel; UINT16 DrawNineGridCacheSize; UINT16 DrawNineGridCacheEntries; - printf("DrawNineGridCacheCapabilitySet (length %d):\n", length); + fprintf(stderr, "DrawNineGridCacheCapabilitySet (length %d):\n", length); if (length < 12) return FALSE; @@ -1919,7 +1919,7 @@ BOOL rdp_print_draw_nine_grid_cache_capability_set(STREAM* s, UINT16 length) * @return if the operation completed successfully */ -BOOL rdp_read_draw_gdiplus_cache_capability_set(STREAM* s, UINT16 length, rdpSettings* settings) +BOOL rdp_read_draw_gdiplus_cache_capability_set(wStream* s, UINT16 length, rdpSettings* settings) { UINT32 drawGDIPlusSupportLevel; UINT32 drawGdiplusCacheLevel; @@ -1950,7 +1950,7 @@ BOOL rdp_read_draw_gdiplus_cache_capability_set(STREAM* s, UINT16 length, rdpSet * @param settings settings */ -void rdp_write_draw_gdiplus_cache_capability_set(STREAM* s, rdpSettings* settings) +void rdp_write_draw_gdiplus_cache_capability_set(wStream* s, rdpSettings* settings) { BYTE* header; UINT32 drawGDIPlusSupportLevel; @@ -1971,13 +1971,13 @@ void rdp_write_draw_gdiplus_cache_capability_set(STREAM* s, rdpSettings* setting rdp_capability_set_finish(s, header, CAPSET_TYPE_DRAW_GDI_PLUS); } -BOOL rdp_print_draw_gdiplus_cache_capability_set(STREAM* s, UINT16 length) +BOOL rdp_print_draw_gdiplus_cache_capability_set(wStream* s, UINT16 length) { UINT32 drawGdiPlusSupportLevel; UINT32 GdipVersion; UINT32 drawGdiplusCacheLevel; - printf("DrawGdiPlusCacheCapabilitySet (length %d):\n", length); + fprintf(stderr, "DrawGdiPlusCacheCapabilitySet (length %d):\n", length); if (length < 40) return FALSE; @@ -2000,7 +2000,7 @@ BOOL rdp_print_draw_gdiplus_cache_capability_set(STREAM* s, UINT16 length) * @return if the operation completed successfully */ -BOOL rdp_read_remote_programs_capability_set(STREAM* s, UINT16 length, rdpSettings* settings) +BOOL rdp_read_remote_programs_capability_set(wStream* s, UINT16 length, rdpSettings* settings) { UINT32 railSupportLevel; @@ -2027,7 +2027,7 @@ BOOL rdp_read_remote_programs_capability_set(STREAM* s, UINT16 length, rdpSettin * @param settings settings */ -void rdp_write_remote_programs_capability_set(STREAM* s, rdpSettings* settings) +void rdp_write_remote_programs_capability_set(wStream* s, rdpSettings* settings) { BYTE* header; UINT32 railSupportLevel; @@ -2044,18 +2044,18 @@ void rdp_write_remote_programs_capability_set(STREAM* s, rdpSettings* settings) rdp_capability_set_finish(s, header, CAPSET_TYPE_RAIL); } -BOOL rdp_print_remote_programs_capability_set(STREAM* s, UINT16 length) +BOOL rdp_print_remote_programs_capability_set(wStream* s, UINT16 length) { UINT32 railSupportLevel; - printf("RemoteProgramsCapabilitySet (length %d):\n", length); + fprintf(stderr, "RemoteProgramsCapabilitySet (length %d):\n", length); if (length < 8) return FALSE; stream_read_UINT32(s, railSupportLevel); /* railSupportLevel (4 bytes) */ - printf("\trailSupportLevel: 0x%08X\n", railSupportLevel); + fprintf(stderr, "\trailSupportLevel: 0x%08X\n", railSupportLevel); return TRUE; } @@ -2068,7 +2068,7 @@ BOOL rdp_print_remote_programs_capability_set(STREAM* s, UINT16 length) * @return if the operation completed successfully */ -BOOL rdp_read_window_list_capability_set(STREAM* s, UINT16 length, rdpSettings* settings) +BOOL rdp_read_window_list_capability_set(wStream* s, UINT16 length, rdpSettings* settings) { if (length < 11) return FALSE; @@ -2087,7 +2087,7 @@ BOOL rdp_read_window_list_capability_set(STREAM* s, UINT16 length, rdpSettings* * @param settings settings */ -void rdp_write_window_list_capability_set(STREAM* s, rdpSettings* settings) +void rdp_write_window_list_capability_set(wStream* s, rdpSettings* settings) { BYTE* header; UINT32 wndSupportLevel; @@ -2103,13 +2103,13 @@ void rdp_write_window_list_capability_set(STREAM* s, rdpSettings* settings) rdp_capability_set_finish(s, header, CAPSET_TYPE_WINDOW); } -BOOL rdp_print_window_list_capability_set(STREAM* s, UINT16 length) +BOOL rdp_print_window_list_capability_set(wStream* s, UINT16 length) { UINT32 wndSupportLevel; BYTE numIconCaches; UINT16 numIconCacheEntries; - printf("WindowListCapabilitySet (length %d):\n", length); + fprintf(stderr, "WindowListCapabilitySet (length %d):\n", length); if (length < 11) return FALSE; @@ -2118,9 +2118,9 @@ BOOL rdp_print_window_list_capability_set(STREAM* s, UINT16 length) stream_read_BYTE(s, numIconCaches); /* numIconCaches (1 byte) */ stream_read_UINT16(s, numIconCacheEntries); /* numIconCacheEntries (2 bytes) */ - printf("\twndSupportLevel: 0x%08X\n", wndSupportLevel); - printf("\tnumIconCaches: 0x%02X\n", numIconCaches); - printf("\tnumIconCacheEntries: 0x%04X\n", numIconCacheEntries); + fprintf(stderr, "\twndSupportLevel: 0x%08X\n", wndSupportLevel); + fprintf(stderr, "\tnumIconCaches: 0x%02X\n", numIconCaches); + fprintf(stderr, "\tnumIconCacheEntries: 0x%04X\n", numIconCacheEntries); return TRUE; } @@ -2133,7 +2133,7 @@ BOOL rdp_print_window_list_capability_set(STREAM* s, UINT16 length) * @return if the operation completed successfully */ -BOOL rdp_read_desktop_composition_capability_set(STREAM* s, UINT16 length, rdpSettings* settings) +BOOL rdp_read_desktop_composition_capability_set(wStream* s, UINT16 length, rdpSettings* settings) { if (length < 6) return FALSE; @@ -2150,7 +2150,7 @@ BOOL rdp_read_desktop_composition_capability_set(STREAM* s, UINT16 length, rdpSe * @param settings settings */ -void rdp_write_desktop_composition_capability_set(STREAM* s, rdpSettings* settings) +void rdp_write_desktop_composition_capability_set(wStream* s, rdpSettings* settings) { BYTE* header; UINT16 compDeskSupportLevel; @@ -2164,18 +2164,18 @@ void rdp_write_desktop_composition_capability_set(STREAM* s, rdpSettings* settin rdp_capability_set_finish(s, header, CAPSET_TYPE_COMP_DESK); } -BOOL rdp_print_desktop_composition_capability_set(STREAM* s, UINT16 length) +BOOL rdp_print_desktop_composition_capability_set(wStream* s, UINT16 length) { UINT16 compDeskSupportLevel; - printf("DesktopCompositionCapabilitySet (length %d):\n", length); + fprintf(stderr, "DesktopCompositionCapabilitySet (length %d):\n", length); if (length < 6) return FALSE; stream_read_UINT16(s, compDeskSupportLevel); /* compDeskSupportLevel (2 bytes) */ - printf("\tcompDeskSupportLevel: 0x%04X\n", compDeskSupportLevel); + fprintf(stderr, "\tcompDeskSupportLevel: 0x%04X\n", compDeskSupportLevel); return TRUE; } @@ -2188,7 +2188,7 @@ BOOL rdp_print_desktop_composition_capability_set(STREAM* s, UINT16 length) * @return if the operation completed successfully */ -BOOL rdp_read_multifragment_update_capability_set(STREAM* s, UINT16 length, rdpSettings* settings) +BOOL rdp_read_multifragment_update_capability_set(wStream* s, UINT16 length, rdpSettings* settings) { UINT32 multifragMaxRequestSize; if (length < 8) @@ -2208,7 +2208,7 @@ BOOL rdp_read_multifragment_update_capability_set(STREAM* s, UINT16 length, rdpS * @param settings settings */ -void rdp_write_multifragment_update_capability_set(STREAM* s, rdpSettings* settings) +void rdp_write_multifragment_update_capability_set(wStream* s, rdpSettings* settings) { BYTE* header; @@ -2219,18 +2219,18 @@ void rdp_write_multifragment_update_capability_set(STREAM* s, rdpSettings* setti rdp_capability_set_finish(s, header, CAPSET_TYPE_MULTI_FRAGMENT_UPDATE); } -BOOL rdp_print_multifragment_update_capability_set(STREAM* s, UINT16 length) +BOOL rdp_print_multifragment_update_capability_set(wStream* s, UINT16 length) { UINT32 maxRequestSize; - printf("MultifragmentUpdateCapabilitySet (length %d):\n", length); + fprintf(stderr, "MultifragmentUpdateCapabilitySet (length %d):\n", length); if (length < 8) return FALSE; stream_read_UINT32(s, maxRequestSize); /* maxRequestSize (4 bytes) */ - printf("\tmaxRequestSize: 0x%04X\n", maxRequestSize); + fprintf(stderr, "\tmaxRequestSize: 0x%04X\n", maxRequestSize); return TRUE; } @@ -2243,7 +2243,7 @@ BOOL rdp_print_multifragment_update_capability_set(STREAM* s, UINT16 length) * @return if the operation completed successfully */ -BOOL rdp_read_large_pointer_capability_set(STREAM* s, UINT16 length, rdpSettings* settings) +BOOL rdp_read_large_pointer_capability_set(wStream* s, UINT16 length, rdpSettings* settings) { if (length < 6) return FALSE; @@ -2260,7 +2260,7 @@ BOOL rdp_read_large_pointer_capability_set(STREAM* s, UINT16 length, rdpSettings * @param settings settings */ -void rdp_write_large_pointer_capability_set(STREAM* s, rdpSettings* settings) +void rdp_write_large_pointer_capability_set(wStream* s, rdpSettings* settings) { BYTE* header; UINT16 largePointerSupportFlags; @@ -2274,18 +2274,18 @@ void rdp_write_large_pointer_capability_set(STREAM* s, rdpSettings* settings) rdp_capability_set_finish(s, header, CAPSET_TYPE_LARGE_POINTER); } -BOOL rdp_print_large_pointer_capability_set(STREAM* s, UINT16 length) +BOOL rdp_print_large_pointer_capability_set(wStream* s, UINT16 length) { UINT16 largePointerSupportFlags; - printf("LargePointerCapabilitySet (length %d):\n", length); + fprintf(stderr, "LargePointerCapabilitySet (length %d):\n", length); if (length < 6) return FALSE; stream_read_UINT16(s, largePointerSupportFlags); /* largePointerSupportFlags (2 bytes) */ - printf("\tlargePointerSupportFlags: 0x%04X\n", largePointerSupportFlags); + fprintf(stderr, "\tlargePointerSupportFlags: 0x%04X\n", largePointerSupportFlags); return TRUE; } @@ -2298,7 +2298,7 @@ BOOL rdp_print_large_pointer_capability_set(STREAM* s, UINT16 length) * @return if the operation completed successfully */ -BOOL rdp_read_surface_commands_capability_set(STREAM* s, UINT16 length, rdpSettings* settings) +BOOL rdp_read_surface_commands_capability_set(wStream* s, UINT16 length, rdpSettings* settings) { if (length < 12) return FALSE; @@ -2318,7 +2318,7 @@ BOOL rdp_read_surface_commands_capability_set(STREAM* s, UINT16 length, rdpSetti * @param settings settings */ -void rdp_write_surface_commands_capability_set(STREAM* s, rdpSettings* settings) +void rdp_write_surface_commands_capability_set(wStream* s, rdpSettings* settings) { BYTE* header; UINT32 cmdFlags; @@ -2335,12 +2335,12 @@ void rdp_write_surface_commands_capability_set(STREAM* s, rdpSettings* settings) rdp_capability_set_finish(s, header, CAPSET_TYPE_SURFACE_COMMANDS); } -BOOL rdp_print_surface_commands_capability_set(STREAM* s, UINT16 length) +BOOL rdp_print_surface_commands_capability_set(wStream* s, UINT16 length) { UINT32 cmdFlags; UINT32 reserved; - printf("SurfaceCommandsCapabilitySet (length %d):\n", length); + fprintf(stderr, "SurfaceCommandsCapabilitySet (length %d):\n", length); if (length < 12) return FALSE; @@ -2348,13 +2348,13 @@ BOOL rdp_print_surface_commands_capability_set(STREAM* s, UINT16 length) stream_read_UINT32(s, cmdFlags); /* cmdFlags (4 bytes) */ stream_read_UINT32(s, reserved); /* reserved (4 bytes) */ - printf("\tcmdFlags: 0x%08X\n", cmdFlags); - printf("\treserved: 0x%08X\n", reserved); + fprintf(stderr, "\tcmdFlags: 0x%08X\n", cmdFlags); + fprintf(stderr, "\treserved: 0x%08X\n", reserved); return TRUE; } -void rdp_read_bitmap_codec_guid(STREAM* s, GUID* guid) +void rdp_read_bitmap_codec_guid(wStream* s, GUID* guid) { BYTE g[16]; @@ -2373,7 +2373,7 @@ void rdp_read_bitmap_codec_guid(STREAM* s, GUID* guid) guid->Data4[7] = g[15]; } -void rdp_write_bitmap_codec_guid(STREAM* s, GUID* guid) +void rdp_write_bitmap_codec_guid(wStream* s, GUID* guid) { BYTE g[16]; @@ -2399,7 +2399,7 @@ void rdp_write_bitmap_codec_guid(STREAM* s, GUID* guid) void rdp_print_bitmap_codec_guid(GUID* guid) { - printf("%08X%04X%04X%02X%02X%02X%02X%02X%02X%02X%02X", + fprintf(stderr, "%08X%04X%04X%02X%02X%02X%02X%02X%02X%02X%02X", guid->Data1, guid->Data2, guid->Data3, guid->Data4[0], guid->Data4[1], guid->Data4[2], guid->Data4[3], guid->Data4[4], guid->Data4[5], guid->Data4[6], guid->Data4[7]); @@ -2431,7 +2431,7 @@ char* rdp_get_bitmap_codec_guid_name(GUID* guid) * @return if the operation completed successfully */ -BOOL rdp_read_bitmap_codecs_capability_set(STREAM* s, UINT16 length, rdpSettings* settings) +BOOL rdp_read_bitmap_codecs_capability_set(wStream* s, UINT16 length, rdpSettings* settings) { GUID codecGuid; RPC_STATUS rpc_status; @@ -2487,6 +2487,21 @@ BOOL rdp_read_bitmap_codecs_capability_set(STREAM* s, UINT16 length, rdpSettings if (remainingLength < codecPropertiesLength) return FALSE; + if (settings->ServerMode) + { + if (UuidEqual(&codecGuid, &CODEC_GUID_REMOTEFX, &rpc_status)) + { + stream_seek_UINT32(s); /* length */ + stream_read_UINT32(s, settings->RemoteFxCaptureFlags); /* captureFlags */ + stream_rewind(s, 8); + + if (settings->RemoteFxCaptureFlags & CARDP_CAPS_CAPTURE_NON_CAC) + { + settings->RemoteFxOnly = TRUE; + } + } + } + stream_seek(s, codecPropertiesLength); /* codecProperties */ remainingLength -= codecPropertiesLength; @@ -2501,12 +2516,12 @@ BOOL rdp_read_bitmap_codecs_capability_set(STREAM* s, UINT16 length, rdpSettings * @param s stream * @param settings settings */ -void rdp_write_rfx_client_capability_container(STREAM* s, rdpSettings* settings) +void rdp_write_rfx_client_capability_container(wStream* s, rdpSettings* settings) { UINT32 captureFlags; BYTE codecMode; - captureFlags = settings->RemoteFxOnly ? CARDP_CAPS_CAPTURE_NON_CAC : 0; + captureFlags = settings->RemoteFxOnly ? 0 : CARDP_CAPS_CAPTURE_NON_CAC; codecMode = settings->RemoteFxCodecMode; stream_write_UINT16(s, 49); /* codecPropertiesLength */ @@ -2551,7 +2566,7 @@ void rdp_write_rfx_client_capability_container(STREAM* s, rdpSettings* settings) * @param s stream * @param settings settings */ -void rdp_write_nsc_client_capability_container(STREAM* s, rdpSettings* settings) +void rdp_write_nsc_client_capability_container(wStream* s, rdpSettings* settings) { stream_write_UINT16(s, 3); /* codecPropertiesLength */ @@ -2561,7 +2576,7 @@ void rdp_write_nsc_client_capability_container(STREAM* s, rdpSettings* settings) stream_write_BYTE(s, 3); /* colorLossLevel */ } -void rdp_write_jpeg_client_capability_container(STREAM* s, rdpSettings* settings) +void rdp_write_jpeg_client_capability_container(wStream* s, rdpSettings* settings) { stream_write_UINT16(s, 1); /* codecPropertiesLength */ stream_write_BYTE(s, settings->JpegQuality); @@ -2572,13 +2587,13 @@ void rdp_write_jpeg_client_capability_container(STREAM* s, rdpSettings* settings * @param s stream * @param settings settings */ -void rdp_write_rfx_server_capability_container(STREAM* s, rdpSettings* settings) +void rdp_write_rfx_server_capability_container(wStream* s, rdpSettings* settings) { stream_write_UINT16(s, 4); /* codecPropertiesLength */ stream_write_UINT32(s, 0); /* reserved */ } -void rdp_write_jpeg_server_capability_container(STREAM* s, rdpSettings* settings) +void rdp_write_jpeg_server_capability_container(wStream* s, rdpSettings* settings) { stream_write_UINT16(s, 1); /* codecPropertiesLength */ stream_write_BYTE(s, 75); @@ -2589,7 +2604,7 @@ void rdp_write_jpeg_server_capability_container(STREAM* s, rdpSettings* settings * @param s stream * @param settings settings */ -void rdp_write_nsc_server_capability_container(STREAM* s, rdpSettings* settings) +void rdp_write_nsc_server_capability_container(wStream* s, rdpSettings* settings) { stream_write_UINT16(s, 4); /* codecPropertiesLength */ stream_write_UINT32(s, 0); /* reserved */ @@ -2602,7 +2617,7 @@ void rdp_write_nsc_server_capability_container(STREAM* s, rdpSettings* settings) * @param settings settings */ -void rdp_write_bitmap_codecs_capability_set(STREAM* s, rdpSettings* settings) +void rdp_write_bitmap_codecs_capability_set(wStream* s, rdpSettings* settings) { BYTE* header; BYTE bitmapCodecCount; @@ -2692,7 +2707,7 @@ void rdp_write_bitmap_codecs_capability_set(STREAM* s, rdpSettings* settings) rdp_capability_set_finish(s, header, CAPSET_TYPE_BITMAP_CODECS); } -BOOL rdp_print_bitmap_codecs_capability_set(STREAM* s, UINT16 length) +BOOL rdp_print_bitmap_codecs_capability_set(wStream* s, UINT16 length) { GUID codecGuid; BYTE bitmapCodecCount; @@ -2700,7 +2715,7 @@ BOOL rdp_print_bitmap_codecs_capability_set(STREAM* s, UINT16 length) UINT16 codecPropertiesLength; UINT16 remainingLength; - printf("BitmapCodecsCapabilitySet (length %d):\n", length); + fprintf(stderr, "BitmapCodecsCapabilitySet (length %d):\n", length); if (length < 5) return FALSE; @@ -2708,7 +2723,7 @@ BOOL rdp_print_bitmap_codecs_capability_set(STREAM* s, UINT16 length) stream_read_BYTE(s, bitmapCodecCount); /* bitmapCodecCount (1 byte) */ remainingLength = length - 5; - printf("\tbitmapCodecCount: %d\n", bitmapCodecCount); + fprintf(stderr, "\tbitmapCodecCount: %d\n", bitmapCodecCount); while (bitmapCodecCount > 0) { @@ -2718,14 +2733,14 @@ BOOL rdp_print_bitmap_codecs_capability_set(STREAM* s, UINT16 length) rdp_read_bitmap_codec_guid(s, &codecGuid); /* codecGuid (16 bytes) */ stream_read_BYTE(s, codecId); /* codecId (1 byte) */ - printf("\tcodecGuid: 0x"); + fprintf(stderr, "\tcodecGuid: 0x"); rdp_print_bitmap_codec_guid(&codecGuid); - printf(" (%s)\n", rdp_get_bitmap_codec_guid_name(&codecGuid)); + fprintf(stderr, " (%s)\n", rdp_get_bitmap_codec_guid_name(&codecGuid)); - printf("\tcodecId: %d\n", codecId); + fprintf(stderr, "\tcodecId: %d\n", codecId); stream_read_UINT16(s, codecPropertiesLength); /* codecPropertiesLength (2 bytes) */ - printf("\tcodecPropertiesLength: %d\n", codecPropertiesLength); + fprintf(stderr, "\tcodecPropertiesLength: %d\n", codecPropertiesLength); remainingLength -= 19; @@ -2748,7 +2763,7 @@ BOOL rdp_print_bitmap_codecs_capability_set(STREAM* s, UINT16 length) * @return if the operation completed successfully */ -BOOL rdp_read_frame_acknowledge_capability_set(STREAM* s, UINT16 length, rdpSettings* settings) +BOOL rdp_read_frame_acknowledge_capability_set(wStream* s, UINT16 length, rdpSettings* settings) { if (length < 8) return FALSE; @@ -2770,7 +2785,7 @@ BOOL rdp_read_frame_acknowledge_capability_set(STREAM* s, UINT16 length, rdpSett * @param settings settings */ -void rdp_write_frame_acknowledge_capability_set(STREAM* s, rdpSettings* settings) +void rdp_write_frame_acknowledge_capability_set(wStream* s, rdpSettings* settings) { BYTE* header; UINT32 frame_acknowledge; @@ -2783,23 +2798,23 @@ void rdp_write_frame_acknowledge_capability_set(STREAM* s, rdpSettings* settings rdp_capability_set_finish(s, header, CAPSET_TYPE_FRAME_ACKNOWLEDGE); } -BOOL rdp_print_frame_acknowledge_capability_set(STREAM* s, UINT16 length) +BOOL rdp_print_frame_acknowledge_capability_set(wStream* s, UINT16 length) { UINT32 frameAcknowledge; - printf("FrameAcknowledgeCapabilitySet (length %d):\n", length); + fprintf(stderr, "FrameAcknowledgeCapabilitySet (length %d):\n", length); if (length < 8) return FALSE; stream_read_UINT32(s, frameAcknowledge); /* frameAcknowledge (4 bytes) */ - printf("\tframeAcknowledge: 0x%08X\n", frameAcknowledge); + fprintf(stderr, "\tframeAcknowledge: 0x%08X\n", frameAcknowledge); return TRUE; } -BOOL rdp_read_bitmap_cache_v3_codec_id_capability_set(STREAM* s, UINT16 length, rdpSettings* settings) +BOOL rdp_read_bitmap_cache_v3_codec_id_capability_set(wStream* s, UINT16 length, rdpSettings* settings) { BYTE bitmapCacheV3CodecId; @@ -2811,7 +2826,7 @@ BOOL rdp_read_bitmap_cache_v3_codec_id_capability_set(STREAM* s, UINT16 length, return TRUE; } -void rdp_write_bitmap_cache_v3_codec_id_capability_set(STREAM* s, rdpSettings* settings) +void rdp_write_bitmap_cache_v3_codec_id_capability_set(wStream* s, rdpSettings* settings) { BYTE* header; @@ -2820,23 +2835,23 @@ void rdp_write_bitmap_cache_v3_codec_id_capability_set(STREAM* s, rdpSettings* s rdp_capability_set_finish(s, header, CAPSET_TYPE_BITMAP_CACHE_V3_CODEC_ID); } -BOOL rdp_print_bitmap_cache_v3_codec_id_capability_set(STREAM* s, UINT16 length) +BOOL rdp_print_bitmap_cache_v3_codec_id_capability_set(wStream* s, UINT16 length) { BYTE bitmapCacheV3CodecId; - printf("BitmapCacheV3CodecIdCapabilitySet (length %d):\n", length); + fprintf(stderr, "BitmapCacheV3CodecIdCapabilitySet (length %d):\n", length); if (length < 5) return FALSE; stream_read_BYTE(s, bitmapCacheV3CodecId); /* bitmapCacheV3CodecId (1 byte) */ - printf("\tbitmapCacheV3CodecId: 0x%02X\n", bitmapCacheV3CodecId); + fprintf(stderr, "\tbitmapCacheV3CodecId: 0x%02X\n", bitmapCacheV3CodecId); return TRUE; } -BOOL rdp_print_capability_sets(STREAM* s, UINT16 numberCapabilities, BOOL receiving) +BOOL rdp_print_capability_sets(wStream* s, UINT16 numberCapabilities, BOOL receiving) { UINT16 type; UINT16 length; @@ -2848,13 +2863,13 @@ BOOL rdp_print_capability_sets(STREAM* s, UINT16 numberCapabilities, BOOL receiv rdp_read_capability_set_header(s, &length, &type); - printf("%s ", receiving ? "Receiving" : "Sending"); + fprintf(stderr, "%s ", receiving ? "Receiving" : "Sending"); em = bm + length; if (stream_get_left(s) < length - 4) { - printf("error processing stream\n"); + fprintf(stderr, "error processing stream\n"); return FALSE; } @@ -3006,14 +3021,14 @@ BOOL rdp_print_capability_sets(STREAM* s, UINT16 numberCapabilities, BOOL receiv break; default: - printf("unknown capability type %d\n", type); + fprintf(stderr, "unknown capability type %d\n", type); break; } - if (s->p != em) + if (s->pointer != em) { - printf("incorrect offset, type:0x%02X actual:%d expected:%d\n", - type, (int) (s->p - bm), (int) (em - bm)); + fprintf(stderr, "incorrect offset, type:0x%02X actual:%d expected:%d\n", + type, (int) (s->pointer - bm), (int) (em - bm)); } stream_set_mark(s, em); @@ -3023,7 +3038,7 @@ BOOL rdp_print_capability_sets(STREAM* s, UINT16 numberCapabilities, BOOL receiv return TRUE; } -BOOL rdp_read_capability_sets(STREAM* s, rdpSettings* settings, UINT16 numberCapabilities) +BOOL rdp_read_capability_sets(wStream* s, rdpSettings* settings, UINT16 numberCapabilities) { BYTE* mark; UINT16 count; @@ -3045,7 +3060,7 @@ BOOL rdp_read_capability_sets(STREAM* s, rdpSettings* settings, UINT16 numberCap if (stream_get_left(s) < length - 4) { - printf("error processing stream\n"); + fprintf(stderr, "error processing stream\n"); return FALSE; } @@ -3197,14 +3212,14 @@ BOOL rdp_read_capability_sets(STREAM* s, rdpSettings* settings, UINT16 numberCap break; default: - printf("unknown capability type %d\n", type); + fprintf(stderr, "unknown capability type %d\n", type); break; } - if (s->p != em) + if (s->pointer != em) { - printf("incorrect offset, type:0x%02X actual:%d expected:%d\n", - type, (int) (s->p - bm), (int) (em - bm)); + fprintf(stderr, "incorrect offset, type:0x%02X actual:%d expected:%d\n", + type, (int) (s->pointer - bm), (int) (em - bm)); } stream_set_mark(s, em); @@ -3222,19 +3237,12 @@ BOOL rdp_read_capability_sets(STREAM* s, rdpSettings* settings, UINT16 numberCap return TRUE; } -BOOL rdp_recv_demand_active(rdpRdp* rdp, STREAM* s) +BOOL rdp_recv_get_active_header(rdpRdp* rdp, wStream* s, UINT16* pChannelId) { UINT16 length; - UINT16 channelId; - UINT16 pduType; - UINT16 pduLength; - UINT16 pduSource; - UINT16 numberCapabilities; - UINT16 lengthSourceDescriptor; - UINT16 lengthCombinedCapabilities; UINT16 securityFlags; - if (!rdp_read_header(rdp, s, &length, &channelId)) + if (!rdp_read_header(rdp, s, &length, pChannelId)) return FALSE; if (rdp->disconnect) @@ -3249,21 +3257,40 @@ BOOL rdp_recv_demand_active(rdpRdp* rdp, STREAM* s) { if (!rdp_decrypt(rdp, s, length - 4, securityFlags)) { - printf("rdp_decrypt failed\n"); + fprintf(stderr, "rdp_decrypt failed\n"); return FALSE; } } } - if (channelId != MCS_GLOBAL_CHANNEL_ID) + if (*pChannelId != MCS_GLOBAL_CHANNEL_ID) { - printf("expected MCS_GLOBAL_CHANNEL_ID %04x, got %04x\n", MCS_GLOBAL_CHANNEL_ID, channelId); + fprintf(stderr, "expected MCS_GLOBAL_CHANNEL_ID %04x, got %04x\n", MCS_GLOBAL_CHANNEL_ID, *pChannelId); return FALSE; } + return TRUE; +} + +BOOL rdp_recv_demand_active(rdpRdp* rdp, wStream* s) +{ + UINT16 channelId; + UINT16 pduType; + UINT16 pduLength; + UINT16 pduSource; + UINT16 numberCapabilities; + UINT16 lengthSourceDescriptor; + UINT16 lengthCombinedCapabilities; + + if (!rdp_recv_get_active_header(rdp, s, &channelId)) + return FALSE; + + if (rdp->disconnect) + return TRUE; + if (!rdp_read_share_control_header(s, &pduLength, &pduType, &pduSource)) { - printf("rdp_read_share_control_header failed\n"); + fprintf(stderr, "rdp_read_share_control_header failed\n"); return FALSE; } @@ -3271,7 +3298,7 @@ BOOL rdp_recv_demand_active(rdpRdp* rdp, STREAM* s) if (pduType != PDU_TYPE_DEMAND_ACTIVE) { - printf("expected PDU_TYPE_DEMAND_ACTIVE %04x, got %04x\n", PDU_TYPE_DEMAND_ACTIVE, pduType); + fprintf(stderr, "expected PDU_TYPE_DEMAND_ACTIVE %04x, got %04x\n", PDU_TYPE_DEMAND_ACTIVE, pduType); return FALSE; } @@ -3291,7 +3318,7 @@ BOOL rdp_recv_demand_active(rdpRdp* rdp, STREAM* s) /* capabilitySets */ if (!rdp_read_capability_sets(s, rdp->settings, numberCapabilities)) { - printf("rdp_read_capability_sets failed\n"); + fprintf(stderr, "rdp_read_capability_sets failed\n"); return FALSE; } @@ -3300,7 +3327,7 @@ BOOL rdp_recv_demand_active(rdpRdp* rdp, STREAM* s) return TRUE; } -void rdp_write_demand_active(STREAM* s, rdpSettings* settings) +void rdp_write_demand_active(wStream* s, rdpSettings* settings) { BYTE *bm, *em, *lm; UINT16 numberCapabilities; @@ -3362,7 +3389,7 @@ void rdp_write_demand_active(STREAM* s, rdpSettings* settings) BOOL rdp_send_demand_active(rdpRdp* rdp) { - STREAM* s; + wStream* s; s = rdp_pdu_init(rdp); @@ -3373,9 +3400,8 @@ BOOL rdp_send_demand_active(rdpRdp* rdp) return rdp_send_pdu(rdp, s, PDU_TYPE_DEMAND_ACTIVE, rdp->mcs->user_id); } -BOOL rdp_recv_confirm_active(rdpRdp* rdp, STREAM* s) +BOOL rdp_recv_confirm_active(rdpRdp* rdp, wStream* s) { - UINT16 length; UINT16 channelId; UINT16 pduType; UINT16 pduLength; @@ -3383,27 +3409,8 @@ BOOL rdp_recv_confirm_active(rdpRdp* rdp, STREAM* s) UINT16 lengthSourceDescriptor; UINT16 lengthCombinedCapabilities; UINT16 numberCapabilities; - UINT16 securityFlags; - if (!rdp_read_header(rdp, s, &length, &channelId)) - return FALSE; - - if (rdp->settings->DisableEncryption) - { - if (!rdp_read_security_header(s, &securityFlags)) - return FALSE; - - if (securityFlags & SEC_ENCRYPT) - { - if (!rdp_decrypt(rdp, s, length - 4, securityFlags)) - { - printf("rdp_decrypt failed\n"); - return FALSE; - } - } - } - - if (channelId != MCS_GLOBAL_CHANNEL_ID) + if (!rdp_recv_get_active_header(rdp, s, &channelId)) return FALSE; if (!rdp_read_share_control_header(s, &pduLength, &pduType, &pduSource)) @@ -3432,7 +3439,7 @@ BOOL rdp_recv_confirm_active(rdpRdp* rdp, STREAM* s) return rdp_read_capability_sets(s, rdp->settings, numberCapabilities); } -void rdp_write_confirm_active(STREAM* s, rdpSettings* settings) +void rdp_write_confirm_active(wStream* s, rdpSettings* settings) { BYTE *bm, *em, *lm; UINT16 numberCapabilities; @@ -3565,7 +3572,7 @@ void rdp_write_confirm_active(STREAM* s, rdpSettings* settings) BOOL rdp_send_confirm_active(rdpRdp* rdp) { - STREAM* s; + wStream* s; s = rdp_pdu_init(rdp); diff --git a/libfreerdp/core/capabilities.h b/libfreerdp/core/capabilities.h index 6fb7d5a81..4a6191d92 100644 --- a/libfreerdp/core/capabilities.h +++ b/libfreerdp/core/capabilities.h @@ -25,7 +25,8 @@ #include <freerdp/freerdp.h> #include <freerdp/constants.h> #include <freerdp/settings.h> -#include <freerdp/utils/stream.h> + +#include <winpr/stream.h> /* Capability Set Types */ #define CAPSET_TYPE_GENERAL 0x0001 @@ -164,11 +165,12 @@ #define CLW_ENTROPY_RLGR1 0x01 #define CLW_ENTROPY_RLGR3 0x04 -BOOL rdp_recv_demand_active(rdpRdp* rdp, STREAM* s); -void rdp_write_demand_active(STREAM* s, rdpSettings* settings); +BOOL rdp_recv_get_active_header(rdpRdp* rdp, wStream* s, UINT16* pChannelId); +BOOL rdp_recv_demand_active(rdpRdp* rdp, wStream* s); +void rdp_write_demand_active(wStream* s, rdpSettings* settings); BOOL rdp_send_demand_active(rdpRdp* rdp); -BOOL rdp_recv_confirm_active(rdpRdp* rdp, STREAM* s); -void rdp_write_confirm_active(STREAM* s, rdpSettings* settings); +BOOL rdp_recv_confirm_active(rdpRdp* rdp, wStream* s); +void rdp_write_confirm_active(wStream* s, rdpSettings* settings); BOOL rdp_send_confirm_active(rdpRdp* rdp); #endif /* __CAPABILITIES_H */ diff --git a/libfreerdp/core/certificate.c b/libfreerdp/core/certificate.c index 86f4eff9e..d97ba11a2 100644 --- a/libfreerdp/core/certificate.c +++ b/libfreerdp/core/certificate.c @@ -31,8 +31,6 @@ #include <openssl/pem.h> #include <openssl/rsa.h> -#include <freerdp/utils/file.h> - #include "certificate.h" /** @@ -154,7 +152,7 @@ static const char *certificate_read_errors[] = { BOOL certificate_read_x509_certificate(rdpCertBlob* cert, rdpCertInfo* info) { - STREAM* s; + wStream* s; int length; BYTE padding; UINT32 version; @@ -272,7 +270,7 @@ error2: free(info->Modulus); info->Modulus = 0; error1: - printf("error reading when reading certificate: part=%s error=%d\n", certificate_read_errors[error], error); + fprintf(stderr, "error reading when reading certificate: part=%s error=%d\n", certificate_read_errors[error], error); stream_detach(s); stream_free(s); return FALSE; @@ -319,7 +317,7 @@ void certificate_free_x509_certificate_chain(rdpX509CertChain* x509_cert_chain) } } -static BOOL certificate_process_server_public_key(rdpCertificate* certificate, STREAM* s, UINT32 length) +static BOOL certificate_process_server_public_key(rdpCertificate* certificate, wStream* s, UINT32 length) { BYTE magic[4]; UINT32 keylen; @@ -333,7 +331,7 @@ static BOOL certificate_process_server_public_key(rdpCertificate* certificate, S if (memcmp(magic, "RSA1", 4) != 0) { - printf("gcc_process_server_public_key: magic error\n"); + fprintf(stderr, "gcc_process_server_public_key: magic error\n"); return FALSE; } @@ -355,7 +353,7 @@ static BOOL certificate_process_server_public_key(rdpCertificate* certificate, S } static BOOL certificate_process_server_public_signature(rdpCertificate* certificate, - const BYTE* sigdata, int sigdatalen, STREAM* s, UINT32 siglen) + const BYTE* sigdata, int sigdatalen, wStream* s, UINT32 siglen) { int i, sum; CryptoMd5 md5ctx; @@ -376,7 +374,7 @@ static BOOL certificate_process_server_public_signature(rdpCertificate* certific if (sum != 0) { - printf("certificate_process_server_public_signature: invalid signature\n"); + fprintf(stderr, "certificate_process_server_public_signature: invalid signature\n"); //return FALSE; } @@ -387,7 +385,7 @@ static BOOL certificate_process_server_public_signature(rdpCertificate* certific /* Verify signature. */ if (memcmp(md5hash, sig, sizeof(md5hash)) != 0) { - printf("certificate_process_server_public_signature: invalid signature\n"); + fprintf(stderr, "certificate_process_server_public_signature: invalid signature\n"); //return FALSE; } @@ -403,7 +401,7 @@ static BOOL certificate_process_server_public_signature(rdpCertificate* certific if (sig[16] != 0x00 || sum != 0xFF * (62 - 17) || sig[62] != 0x01) { - printf("certificate_process_server_public_signature: invalid signature\n"); + fprintf(stderr, "certificate_process_server_public_signature: invalid signature\n"); //return FALSE; } @@ -416,7 +414,7 @@ static BOOL certificate_process_server_public_signature(rdpCertificate* certific * @param s stream */ -BOOL certificate_read_server_proprietary_certificate(rdpCertificate* certificate, STREAM* s) +BOOL certificate_read_server_proprietary_certificate(rdpCertificate* certificate, wStream* s) { UINT32 dwSigAlgId; UINT32 dwKeyAlgId; @@ -437,7 +435,7 @@ BOOL certificate_read_server_proprietary_certificate(rdpCertificate* certificate if (!(dwSigAlgId == SIGNATURE_ALG_RSA && dwKeyAlgId == KEY_EXCHANGE_ALG_RSA)) { - printf("certificate_read_server_proprietary_certificate: parse error 1\n"); + fprintf(stderr, "certificate_read_server_proprietary_certificate: parse error 1\n"); return FALSE; } @@ -445,7 +443,7 @@ BOOL certificate_read_server_proprietary_certificate(rdpCertificate* certificate if (wPublicKeyBlobType != BB_RSA_KEY_BLOB) { - printf("certificate_read_server_proprietary_certificate: parse error 2\n"); + fprintf(stderr, "certificate_read_server_proprietary_certificate: parse error 2\n"); return FALSE; } @@ -455,7 +453,7 @@ BOOL certificate_read_server_proprietary_certificate(rdpCertificate* certificate if (!certificate_process_server_public_key(certificate, s, wPublicKeyBlobLen)) { - printf("certificate_read_server_proprietary_certificate: parse error 3\n"); + fprintf(stderr, "certificate_read_server_proprietary_certificate: parse error 3\n"); return FALSE; } @@ -467,7 +465,7 @@ BOOL certificate_read_server_proprietary_certificate(rdpCertificate* certificate if (wSignatureBlobType != BB_RSA_SIGNATURE_BLOB) { - printf("certificate_read_server_proprietary_certificate: parse error 4\n"); + fprintf(stderr, "certificate_read_server_proprietary_certificate: parse error 4\n"); return FALSE; } @@ -477,13 +475,13 @@ BOOL certificate_read_server_proprietary_certificate(rdpCertificate* certificate if (wSignatureBlobLen != 72) { - printf("certificate_process_server_public_signature: invalid signature length (got %d, expected %d)\n", wSignatureBlobLen, 64); + fprintf(stderr, "certificate_process_server_public_signature: invalid signature length (got %d, expected %d)\n", wSignatureBlobLen, 64); return FALSE; } if (!certificate_process_server_public_signature(certificate, sigdata, sigdatalen, s, wSignatureBlobLen)) { - printf("certificate_read_server_proprietary_certificate: parse error 5\n"); + fprintf(stderr, "certificate_read_server_proprietary_certificate: parse error 5\n"); return FALSE; } @@ -496,7 +494,7 @@ BOOL certificate_read_server_proprietary_certificate(rdpCertificate* certificate * @param s stream */ -BOOL certificate_read_server_x509_certificate_chain(rdpCertificate* certificate, STREAM* s) +BOOL certificate_read_server_x509_certificate_chain(rdpCertificate* certificate, wStream* s) { int i; UINT32 certLength; @@ -534,7 +532,7 @@ BOOL certificate_read_server_x509_certificate_chain(rdpCertificate* certificate, if (cert_info.Modulus) free(cert_info.Modulus); if (!ret) { - printf("failed to read License Server, content follows:\n"); + fprintf(stderr, "failed to read License Server, content follows:\n"); winpr_HexDump(certificate->x509_cert_chain->array[i].data, certificate->x509_cert_chain->array[i].length); return FALSE; } @@ -560,7 +558,7 @@ BOOL certificate_read_server_x509_certificate_chain(rdpCertificate* certificate, int certificate_read_server_certificate(rdpCertificate* certificate, BYTE* server_cert, int length) { - STREAM* s; + wStream* s; UINT32 dwVersion; int status = 1; @@ -589,7 +587,7 @@ int certificate_read_server_certificate(rdpCertificate* certificate, BYTE* serve break; default: - printf("invalid certificate chain version:%d\n", dwVersion & CERT_CHAIN_VERSION_MASK); + fprintf(stderr, "invalid certificate chain version:%d\n", dwVersion & CERT_CHAIN_VERSION_MASK); status = -1; break; } @@ -615,7 +613,7 @@ rdpRsaKey* key_new(const char* keyfile) if (fp == NULL) { - printf("unable to load RSA key from %s: %s.", keyfile, strerror(errno)); + fprintf(stderr, "unable to load RSA key from %s: %s.", keyfile, strerror(errno)); free(key) ; return NULL; } @@ -636,7 +634,7 @@ rdpRsaKey* key_new(const char* keyfile) { case 0: RSA_free(rsa); - printf("invalid RSA key in %s", keyfile); + fprintf(stderr, "invalid RSA key in %s", keyfile); free(key) ; return NULL; @@ -645,7 +643,7 @@ rdpRsaKey* key_new(const char* keyfile) break; default: - ERR_print_errors_fp(stdout); + ERR_print_errors_fp(stderr); RSA_free(rsa); free(key) ; return NULL; @@ -654,7 +652,7 @@ rdpRsaKey* key_new(const char* keyfile) if (BN_num_bytes(rsa->e) > 4) { RSA_free(rsa); - printf("RSA public exponent too large in %s", keyfile); + fprintf(stderr, "RSA public exponent too large in %s", keyfile); free(key) ; return NULL; } diff --git a/libfreerdp/core/certificate.h b/libfreerdp/core/certificate.h index 5013d1f95..5008bb46d 100644 --- a/libfreerdp/core/certificate.h +++ b/libfreerdp/core/certificate.h @@ -26,8 +26,9 @@ #include <freerdp/crypto/crypto.h> #include <freerdp/settings.h> -#include <freerdp/utils/stream.h> + #include <winpr/print.h> +#include <winpr/stream.h> /* Certificate Version */ #define CERT_CHAIN_VERSION_1 0x00000001 @@ -47,8 +48,8 @@ BOOL certificate_read_x509_certificate(rdpCertBlob* cert, rdpCertInfo* info); rdpX509CertChain* certificate_new_x509_certificate_chain(UINT32 count); void certificate_free_x509_certificate_chain(rdpX509CertChain* x509_cert_chain); -BOOL certificate_read_server_proprietary_certificate(rdpCertificate* certificate, STREAM* s); -BOOL certificate_read_server_x509_certificate_chain(rdpCertificate* certificate, STREAM* s); +BOOL certificate_read_server_proprietary_certificate(rdpCertificate* certificate, wStream* s); +BOOL certificate_read_server_x509_certificate_chain(rdpCertificate* certificate, wStream* s); int certificate_read_server_certificate(rdpCertificate* certificate, BYTE* server_cert, int length); rdpCertificate* certificate_new(void); diff --git a/libfreerdp/core/channel.c b/libfreerdp/core/channel.c index ba9240241..45d11c8d9 100644 --- a/libfreerdp/core/channel.c +++ b/libfreerdp/core/channel.c @@ -28,14 +28,14 @@ #include <freerdp/freerdp.h> #include <freerdp/peer.h> #include <freerdp/constants.h> -#include <freerdp/utils/stream.h> +#include <winpr/stream.h> #include "rdp.h" #include "channel.h" BOOL freerdp_channel_send(rdpRdp* rdp, UINT16 channel_id, BYTE* data, int size) { - STREAM* s; + wStream* s; UINT32 flags; int i, left; int chunk_size; @@ -52,7 +52,7 @@ BOOL freerdp_channel_send(rdpRdp* rdp, UINT16 channel_id, BYTE* data, int size) if (!channel) { - printf("freerdp_channel_send: unknown channel_id %d\n", channel_id); + fprintf(stderr, "freerdp_channel_send: unknown channel_id %d\n", channel_id); return FALSE; } @@ -93,7 +93,7 @@ BOOL freerdp_channel_send(rdpRdp* rdp, UINT16 channel_id, BYTE* data, int size) return TRUE; } -BOOL freerdp_channel_process(freerdp* instance, STREAM* s, UINT16 channel_id) +BOOL freerdp_channel_process(freerdp* instance, wStream* s, UINT16 channel_id) { UINT32 length; UINT32 flags; @@ -112,7 +112,7 @@ BOOL freerdp_channel_process(freerdp* instance, STREAM* s, UINT16 channel_id) return TRUE; } -BOOL freerdp_channel_peer_process(freerdp_peer* client, STREAM* s, UINT16 channel_id) +BOOL freerdp_channel_peer_process(freerdp_peer* client, wStream* s, UINT16 channel_id) { UINT32 length; UINT32 flags; diff --git a/libfreerdp/core/channel.h b/libfreerdp/core/channel.h index 7956873bf..e6a926830 100644 --- a/libfreerdp/core/channel.h +++ b/libfreerdp/core/channel.h @@ -21,7 +21,7 @@ #define __CHANNEL_H BOOL freerdp_channel_send(rdpRdp* rdp, UINT16 channel_id, BYTE* data, int size); -BOOL freerdp_channel_process(freerdp* instance, STREAM* s, UINT16 channel_id); -BOOL freerdp_channel_peer_process(freerdp_peer* client, STREAM* s, UINT16 channel_id); +BOOL freerdp_channel_process(freerdp* instance, wStream* s, UINT16 channel_id); +BOOL freerdp_channel_peer_process(freerdp_peer* client, wStream* s, UINT16 channel_id); #endif /* __CHANNEL_H */ diff --git a/libfreerdp/core/connection.c b/libfreerdp/core/connection.c index b9f5d1982..4b60d868b 100644 --- a/libfreerdp/core/connection.c +++ b/libfreerdp/core/connection.c @@ -135,9 +135,12 @@ BOOL rdp_client_connect(rdpRdp* rdp) nego_set_cookie_max_length(rdp->nego, settings->CookieMaxLength); + if (settings->LoadBalanceInfo) + nego_set_routing_token(rdp->nego, settings->LoadBalanceInfo, settings->LoadBalanceInfoLength); + if (!nego_connect(rdp->nego)) { - printf("Error: protocol security negotiation or connection failure\n"); + fprintf(stderr, "Error: protocol security negotiation or connection failure\n"); return FALSE; } @@ -158,7 +161,7 @@ BOOL rdp_client_connect(rdpRdp* rdp) { connectErrorCode = MCSCONNECTINITIALERROR; } - printf("Error: unable to send MCS Connect Initial\n"); + fprintf(stderr, "Error: unable to send MCS Connect Initial\n"); return FALSE; } @@ -254,7 +257,7 @@ static BOOL rdp_client_establish_keys(rdpRdp* rdp) { BYTE* mod; BYTE* exp; - STREAM* s; + wStream* s; UINT32 length; UINT32 key_len; BYTE crypt_client_random[256 + 8]; @@ -316,7 +319,7 @@ static BOOL rdp_client_establish_keys(rdpRdp* rdp) return TRUE; } -static BOOL rdp_server_establish_keys(rdpRdp* rdp, STREAM* s) +static BOOL rdp_server_establish_keys(rdpRdp* rdp, wStream* s) { BYTE client_random[64]; /* Should be only 32 after successful decryption, but on failure might take up to 64 bytes. */ BYTE crypt_client_random[256 + 8]; @@ -333,7 +336,7 @@ static BOOL rdp_server_establish_keys(rdpRdp* rdp, STREAM* s) if (!rdp_read_header(rdp, s, &length, &channel_id)) { - printf("rdp_server_establish_keys: invalid RDP header\n"); + fprintf(stderr, "rdp_server_establish_keys: invalid RDP header\n"); return FALSE; } @@ -342,7 +345,7 @@ static BOOL rdp_server_establish_keys(rdpRdp* rdp, STREAM* s) if ((sec_flags & SEC_EXCHANGE_PKT) == 0) { - printf("rdp_server_establish_keys: missing SEC_EXCHANGE_PKT in security header\n"); + fprintf(stderr, "rdp_server_establish_keys: missing SEC_EXCHANGE_PKT in security header\n"); return FALSE; } @@ -356,7 +359,7 @@ static BOOL rdp_server_establish_keys(rdpRdp* rdp, STREAM* s) if (rand_len != key_len + 8) { - printf("rdp_server_establish_keys: invalid encrypted client random length\n"); + fprintf(stderr, "rdp_server_establish_keys: invalid encrypted client random length\n"); return FALSE; } @@ -394,11 +397,11 @@ static BOOL rdp_server_establish_keys(rdpRdp* rdp, STREAM* s) return TRUE; } -BOOL rdp_client_connect_mcs_connect_response(rdpRdp* rdp, STREAM* s) +BOOL rdp_client_connect_mcs_connect_response(rdpRdp* rdp, wStream* s) { if (!mcs_recv_connect_response(rdp->mcs, s)) { - printf("rdp_client_connect_mcs_connect_response: mcs_recv_connect_response failed\n"); + fprintf(stderr, "rdp_client_connect_mcs_connect_response: mcs_recv_connect_response failed\n"); return FALSE; } @@ -413,7 +416,7 @@ BOOL rdp_client_connect_mcs_connect_response(rdpRdp* rdp, STREAM* s) return TRUE; } -BOOL rdp_client_connect_mcs_attach_user_confirm(rdpRdp* rdp, STREAM* s) +BOOL rdp_client_connect_mcs_attach_user_confirm(rdpRdp* rdp, wStream* s) { if (!mcs_recv_attach_user_confirm(rdp->mcs, s)) return FALSE; @@ -426,7 +429,7 @@ BOOL rdp_client_connect_mcs_attach_user_confirm(rdpRdp* rdp, STREAM* s) return TRUE; } -BOOL rdp_client_connect_mcs_channel_join_confirm(rdpRdp* rdp, STREAM* s) +BOOL rdp_client_connect_mcs_channel_join_confirm(rdpRdp* rdp, wStream* s) { int i; UINT16 channel_id; @@ -497,14 +500,14 @@ BOOL rdp_client_connect_mcs_channel_join_confirm(rdpRdp* rdp, STREAM* s) return TRUE; } -BOOL rdp_client_connect_license(rdpRdp* rdp, STREAM* s) +BOOL rdp_client_connect_license(rdpRdp* rdp, wStream* s) { if (!license_recv(rdp->license, s)) return FALSE; if (rdp->license->state == LICENSE_STATE_ABORTED) { - printf("license connection sequence aborted.\n"); + fprintf(stderr, "license connection sequence aborted.\n"); return FALSE; } @@ -516,7 +519,7 @@ BOOL rdp_client_connect_license(rdpRdp* rdp, STREAM* s) return TRUE; } -BOOL rdp_client_connect_demand_active(rdpRdp* rdp, STREAM* s) +BOOL rdp_client_connect_demand_active(rdpRdp* rdp, wStream* s) { BYTE* mark; UINT16 width; @@ -529,8 +532,13 @@ BOOL rdp_client_connect_demand_active(rdpRdp* rdp, STREAM* s) if (!rdp_recv_demand_active(rdp, s)) { + UINT16 channelId; stream_set_mark(s, mark); - stream_seek(s, RDP_PACKET_HEADER_MAX_LENGTH); + rdp_recv_get_active_header(rdp, s, &channelId); + /* Was stream_seek(s, RDP_PACKET_HEADER_MAX_LENGTH); + * but the headers aren't always that length, + * so that could result in a bad offset. + */ if (rdp_recv_out_of_sequence_pdu(rdp, s) != TRUE) return FALSE; @@ -583,7 +591,7 @@ BOOL rdp_client_connect_finalize(rdpRdp* rdp) return TRUE; } -BOOL rdp_server_accept_nego(rdpRdp* rdp, STREAM* s) +BOOL rdp_server_accept_nego(rdpRdp* rdp, wStream* s) { BOOL status; rdpSettings* settings = rdp->settings; @@ -595,12 +603,12 @@ BOOL rdp_server_accept_nego(rdpRdp* rdp, STREAM* s) rdp->nego->selected_protocol = 0; - printf("Client Security: NLA:%d TLS:%d RDP:%d\n", + fprintf(stderr, "Client Security: NLA:%d TLS:%d RDP:%d\n", (rdp->nego->requested_protocols & PROTOCOL_NLA) ? 1 : 0, (rdp->nego->requested_protocols & PROTOCOL_TLS) ? 1 : 0, (rdp->nego->requested_protocols == PROTOCOL_RDP) ? 1: 0); - printf("Server Security: NLA:%d TLS:%d RDP:%d\n", + fprintf(stderr, "Server Security: NLA:%d TLS:%d RDP:%d\n", settings->NlaSecurity, settings->TlsSecurity, settings->RdpSecurity); if ((settings->NlaSecurity) && (rdp->nego->requested_protocols & PROTOCOL_NLA)) @@ -617,10 +625,10 @@ BOOL rdp_server_accept_nego(rdpRdp* rdp, STREAM* s) } else { - printf("Protocol security negotiation failure\n"); + fprintf(stderr, "Protocol security negotiation failure\n"); } - printf("Negotiated Security: NLA:%d TLS:%d RDP:%d\n", + fprintf(stderr, "Negotiated Security: NLA:%d TLS:%d RDP:%d\n", (rdp->nego->selected_protocol & PROTOCOL_NLA) ? 1 : 0, (rdp->nego->selected_protocol & PROTOCOL_TLS) ? 1 : 0, (rdp->nego->selected_protocol == PROTOCOL_RDP) ? 1: 0); @@ -646,21 +654,21 @@ BOOL rdp_server_accept_nego(rdpRdp* rdp, STREAM* s) return TRUE; } -BOOL rdp_server_accept_mcs_connect_initial(rdpRdp* rdp, STREAM* s) +BOOL rdp_server_accept_mcs_connect_initial(rdpRdp* rdp, wStream* s) { int i; if (!mcs_recv_connect_initial(rdp->mcs, s)) return FALSE; - printf("Accepted client: %s\n", rdp->settings->ClientHostname); - printf("Accepted channels:"); + fprintf(stderr, "Accepted client: %s\n", rdp->settings->ClientHostname); + fprintf(stderr, "Accepted channels:"); for (i = 0; i < rdp->settings->ChannelCount; i++) { - printf(" %s", rdp->settings->ChannelDefArray[i].Name); + fprintf(stderr, " %s", rdp->settings->ChannelDefArray[i].Name); } - printf("\n"); + fprintf(stderr, "\n"); if (!mcs_send_connect_response(rdp->mcs)) return FALSE; @@ -670,7 +678,7 @@ BOOL rdp_server_accept_mcs_connect_initial(rdpRdp* rdp, STREAM* s) return TRUE; } -BOOL rdp_server_accept_mcs_erect_domain_request(rdpRdp* rdp, STREAM* s) +BOOL rdp_server_accept_mcs_erect_domain_request(rdpRdp* rdp, wStream* s) { if (!mcs_recv_erect_domain_request(rdp->mcs, s)) return FALSE; @@ -680,7 +688,7 @@ BOOL rdp_server_accept_mcs_erect_domain_request(rdpRdp* rdp, STREAM* s) return TRUE; } -BOOL rdp_server_accept_mcs_attach_user_request(rdpRdp* rdp, STREAM* s) +BOOL rdp_server_accept_mcs_attach_user_request(rdpRdp* rdp, wStream* s) { if (!mcs_recv_attach_user_request(rdp->mcs, s)) return FALSE; @@ -693,7 +701,7 @@ BOOL rdp_server_accept_mcs_attach_user_request(rdpRdp* rdp, STREAM* s) return TRUE; } -BOOL rdp_server_accept_mcs_channel_join_request(rdpRdp* rdp, STREAM* s) +BOOL rdp_server_accept_mcs_channel_join_request(rdpRdp* rdp, wStream* s) { int i; UINT16 channel_id; @@ -725,7 +733,7 @@ BOOL rdp_server_accept_mcs_channel_join_request(rdpRdp* rdp, STREAM* s) return TRUE; } -BOOL rdp_server_accept_client_keys(rdpRdp* rdp, STREAM* s) +BOOL rdp_server_accept_client_keys(rdpRdp* rdp, wStream* s) { if (!rdp_server_establish_keys(rdp, s)) @@ -736,7 +744,7 @@ BOOL rdp_server_accept_client_keys(rdpRdp* rdp, STREAM* s) return TRUE; } -BOOL rdp_server_accept_client_info(rdpRdp* rdp, STREAM* s) +BOOL rdp_server_accept_client_info(rdpRdp* rdp, wStream* s) { if (!rdp_recv_client_info(rdp, s)) @@ -750,7 +758,7 @@ BOOL rdp_server_accept_client_info(rdpRdp* rdp, STREAM* s) return TRUE; } -BOOL rdp_server_accept_confirm_active(rdpRdp* rdp, STREAM* s) +BOOL rdp_server_accept_confirm_active(rdpRdp* rdp, wStream* s) { if (!rdp_recv_confirm_active(rdp, s)) return FALSE; diff --git a/libfreerdp/core/connection.h b/libfreerdp/core/connection.h index 22923de96..ec6f57415 100644 --- a/libfreerdp/core/connection.h +++ b/libfreerdp/core/connection.h @@ -46,21 +46,21 @@ enum CONNECTION_STATE BOOL rdp_client_connect(rdpRdp* rdp); BOOL rdp_client_redirect(rdpRdp* rdp); -BOOL rdp_client_connect_mcs_connect_response(rdpRdp* rdp, STREAM* s); -BOOL rdp_client_connect_mcs_attach_user_confirm(rdpRdp* rdp, STREAM* s); -BOOL rdp_client_connect_mcs_channel_join_confirm(rdpRdp* rdp, STREAM* s); -BOOL rdp_client_connect_license(rdpRdp* rdp, STREAM* s); -BOOL rdp_client_connect_demand_active(rdpRdp* rdp, STREAM* s); +BOOL rdp_client_connect_mcs_connect_response(rdpRdp* rdp, wStream* s); +BOOL rdp_client_connect_mcs_attach_user_confirm(rdpRdp* rdp, wStream* s); +BOOL rdp_client_connect_mcs_channel_join_confirm(rdpRdp* rdp, wStream* s); +BOOL rdp_client_connect_license(rdpRdp* rdp, wStream* s); +BOOL rdp_client_connect_demand_active(rdpRdp* rdp, wStream* s); BOOL rdp_client_connect_finalize(rdpRdp* rdp); -BOOL rdp_server_accept_nego(rdpRdp* rdp, STREAM* s); -BOOL rdp_server_accept_mcs_connect_initial(rdpRdp* rdp, STREAM* s); -BOOL rdp_server_accept_mcs_erect_domain_request(rdpRdp* rdp, STREAM* s); -BOOL rdp_server_accept_mcs_attach_user_request(rdpRdp* rdp, STREAM* s); -BOOL rdp_server_accept_mcs_channel_join_request(rdpRdp* rdp, STREAM* s); -BOOL rdp_server_accept_client_keys(rdpRdp* rdp, STREAM* s); -BOOL rdp_server_accept_client_info(rdpRdp* rdp, STREAM* s); -BOOL rdp_server_accept_confirm_active(rdpRdp* rdp, STREAM* s); +BOOL rdp_server_accept_nego(rdpRdp* rdp, wStream* s); +BOOL rdp_server_accept_mcs_connect_initial(rdpRdp* rdp, wStream* s); +BOOL rdp_server_accept_mcs_erect_domain_request(rdpRdp* rdp, wStream* s); +BOOL rdp_server_accept_mcs_attach_user_request(rdpRdp* rdp, wStream* s); +BOOL rdp_server_accept_mcs_channel_join_request(rdpRdp* rdp, wStream* s); +BOOL rdp_server_accept_client_keys(rdpRdp* rdp, wStream* s); +BOOL rdp_server_accept_client_info(rdpRdp* rdp, wStream* s); +BOOL rdp_server_accept_confirm_active(rdpRdp* rdp, wStream* s); BOOL rdp_server_reactivate(rdpRdp* rdp); #endif /* __CONNECTION_H */ diff --git a/libfreerdp/core/errinfo.c b/libfreerdp/core/errinfo.c index e1a634e55..2b78dbc51 100644 --- a/libfreerdp/core/errinfo.c +++ b/libfreerdp/core/errinfo.c @@ -453,13 +453,13 @@ void rdp_print_errinfo(UINT32 code) { if (code == errInfo->code) { - printf("%s (0x%08X):\n%s\n", errInfo->name, code, errInfo->info); + fprintf(stderr, "%s (0x%08X):\n%s\n", errInfo->name, code, errInfo->info); return; } errInfo++; } - printf("ERRINFO_UNKNOWN 0x%08X: Unknown error.\n", code); + fprintf(stderr, "ERRINFO_UNKNOWN 0x%08X: Unknown error.\n", code); } diff --git a/libfreerdp/core/extension.c b/libfreerdp/core/extension.c index d79eefd2d..496bfc91e 100644 --- a/libfreerdp/core/extension.c +++ b/libfreerdp/core/extension.c @@ -59,7 +59,7 @@ static UINT32 FREERDP_CC extension_register_plugin(rdpExtPlugin* plugin) if (ext->num_plugins >= FREERDP_EXT_MAX_COUNT) { - printf("extension_register_extension: maximum number of plugins reached.\n"); + fprintf(stderr, "extension_register_extension: maximum number of plugins reached.\n"); return 1; } @@ -73,7 +73,7 @@ static UINT32 FREERDP_CC extension_register_pre_connect_hook(rdpExtPlugin* plugi if (ext->num_pre_connect_hooks >= FREERDP_EXT_MAX_COUNT) { - printf("extension_register_pre_connect_hook: maximum plugin reached.\n"); + fprintf(stderr, "extension_register_pre_connect_hook: maximum plugin reached.\n"); return 1; } @@ -89,7 +89,7 @@ static UINT32 FREERDP_CC extension_register_post_connect_hook(rdpExtPlugin* plug if (ext->num_post_connect_hooks >= FREERDP_EXT_MAX_COUNT) { - printf("extension_register_post_connect_hook: maximum plugin reached.\n"); + fprintf(stderr, "extension_register_post_connect_hook: maximum plugin reached.\n"); return 1; } @@ -124,11 +124,11 @@ static int extension_load_plugins(rdpExtension* extension) sprintf_s(path, sizeof(path), "%s", settings->extensions[i].name); han = DLOPEN(path); - printf("extension_load_plugins: %s\n", path); + fprintf(stderr, "extension_load_plugins: %s\n", path); if (han == NULL) { - printf("extension_load_plugins: failed to load %s\n", path); + fprintf(stderr, "extension_load_plugins: failed to load %s\n", path); continue; } @@ -136,7 +136,7 @@ static int extension_load_plugins(rdpExtension* extension) if (entry == NULL) { DLCLOSE(han); - printf("extension_load_plugins: failed to find export function in %s\n", path); + fprintf(stderr, "extension_load_plugins: failed to find export function in %s\n", path); continue; } @@ -144,7 +144,7 @@ static int extension_load_plugins(rdpExtension* extension) if (entry(&entryPoints) != 0) { DLCLOSE(han); - printf("extension_load_plugins: %s entry returns error.\n", path); + fprintf(stderr, "extension_load_plugins: %s entry returns error.\n", path); continue; } } diff --git a/libfreerdp/core/fastpath.c b/libfreerdp/core/fastpath.c index e37fed785..8a680d7e7 100644 --- a/libfreerdp/core/fastpath.c +++ b/libfreerdp/core/fastpath.c @@ -29,7 +29,7 @@ #include <freerdp/api.h> #include <freerdp/crypto/per.h> -#include <freerdp/utils/stream.h> +#include <winpr/stream.h> #include "orders.h" #include "update.h" @@ -72,7 +72,7 @@ static const char* const FASTPATH_UPDATETYPE_STRINGS[] = * This function assumes that at least two bytes are available in the stream * and doesn't touch third byte. */ -UINT16 fastpath_header_length(STREAM* s) +UINT16 fastpath_header_length(wStream* s) { BYTE length1; @@ -89,7 +89,7 @@ UINT16 fastpath_header_length(STREAM* s) * @param encryptionFlags * @return length */ -UINT16 fastpath_read_header(rdpFastPath* fastpath, STREAM* s) +UINT16 fastpath_read_header(rdpFastPath* fastpath, wStream* s) { BYTE header; UINT16 length; @@ -107,7 +107,7 @@ UINT16 fastpath_read_header(rdpFastPath* fastpath, STREAM* s) return length; } -static INLINE void fastpath_read_update_header(STREAM* s, BYTE* updateCode, BYTE* fragmentation, BYTE* compression) +static INLINE void fastpath_read_update_header(wStream* s, BYTE* updateCode, BYTE* fragmentation, BYTE* compression) { BYTE updateHeader; @@ -117,7 +117,7 @@ static INLINE void fastpath_read_update_header(STREAM* s, BYTE* updateCode, BYTE *compression = (updateHeader >> 6) & 0x03; } -static INLINE void fastpath_write_update_header(STREAM* s, BYTE updateCode, BYTE fragmentation, BYTE compression) +static INLINE void fastpath_write_update_header(wStream* s, BYTE updateCode, BYTE fragmentation, BYTE compression) { BYTE updateHeader = 0; @@ -127,7 +127,7 @@ static INLINE void fastpath_write_update_header(STREAM* s, BYTE updateCode, BYTE stream_write_BYTE(s, updateHeader); } -BOOL fastpath_read_header_rdp(rdpFastPath* fastpath, STREAM* s, UINT16 *length) +BOOL fastpath_read_header_rdp(rdpFastPath* fastpath, wStream* s, UINT16 *length) { BYTE header; @@ -146,7 +146,7 @@ BOOL fastpath_read_header_rdp(rdpFastPath* fastpath, STREAM* s, UINT16 *length) return TRUE; } -static BOOL fastpath_recv_orders(rdpFastPath* fastpath, STREAM* s) +static BOOL fastpath_recv_orders(rdpFastPath* fastpath, wStream* s) { rdpUpdate* update = fastpath->rdp->update; UINT16 numberOrders; @@ -163,26 +163,27 @@ static BOOL fastpath_recv_orders(rdpFastPath* fastpath, STREAM* s) return TRUE; } -static BOOL fastpath_recv_update_common(rdpFastPath* fastpath, STREAM* s) +static BOOL fastpath_recv_update_common(rdpFastPath* fastpath, wStream* s) { UINT16 updateType; rdpUpdate* update = fastpath->rdp->update; rdpContext* context = update->context; - if(stream_get_left(s) < 2) + if (stream_get_left(s) < 2) return FALSE; + stream_read_UINT16(s, updateType); /* updateType (2 bytes) */ switch (updateType) { case UPDATE_TYPE_BITMAP: - if(!update_read_bitmap(update, s, &update->bitmap_update)) + if (!update_read_bitmap(update, s, &update->bitmap_update)) return FALSE; IFCALL(update->BitmapUpdate, context, &update->bitmap_update); break; case UPDATE_TYPE_PALETTE: - if(!update_read_palette(update, s, &update->palette_update)) + if (!update_read_palette(update, s, &update->palette_update)) return FALSE; IFCALL(update->Palette, context, &update->palette_update); break; @@ -190,7 +191,7 @@ static BOOL fastpath_recv_update_common(rdpFastPath* fastpath, STREAM* s) return TRUE; } -static BOOL fastpath_recv_update_synchronize(rdpFastPath* fastpath, STREAM* s) +static BOOL fastpath_recv_update_synchronize(rdpFastPath* fastpath, wStream* s) { /* server 2008 can send invalid synchronize packet with missing padding, so don't return FALSE even if the packet is invalid */ @@ -198,7 +199,7 @@ static BOOL fastpath_recv_update_synchronize(rdpFastPath* fastpath, STREAM* s) return TRUE; } -static int fastpath_recv_update(rdpFastPath* fastpath, BYTE updateCode, UINT32 size, STREAM* s) +static int fastpath_recv_update(rdpFastPath* fastpath, BYTE updateCode, UINT32 size, wStream* s) { int status = 0; rdpUpdate* update = fastpath->rdp->update; @@ -207,7 +208,7 @@ static int fastpath_recv_update(rdpFastPath* fastpath, BYTE updateCode, UINT32 s #ifdef WITH_DEBUG_RDP DEBUG_RDP("recv Fast-Path %s Update (0x%X), length:%d", - updateCode < ARRAYSIZE(FASTPATH_UPDATETYPE_STRINGS) ? FASTPATH_UPDATETYPE_STRINGS[updateCode] : "???", updateCode, size); + updateCode < ARRAYSIZE(FASTPATH_UPDATETYPE_STRINGS) ? FASTPATH_UPDATETYPE_STRINGS[updateCode] : "???", updateCode, capacity); #endif switch (updateCode) @@ -225,7 +226,7 @@ static int fastpath_recv_update(rdpFastPath* fastpath, BYTE updateCode, UINT32 s case FASTPATH_UPDATETYPE_SYNCHRONIZE: if (!fastpath_recv_update_synchronize(fastpath, s)) - printf("fastpath_recv_update_synchronize failure but we continue\n"); + fprintf(stderr, "fastpath_recv_update_synchronize failure but we continue\n"); else IFCALL(update->Synchronize, context); break; @@ -276,7 +277,7 @@ static int fastpath_recv_update(rdpFastPath* fastpath, BYTE updateCode, UINT32 s return status; } -static int fastpath_recv_update_data(rdpFastPath* fastpath, STREAM* s) +static int fastpath_recv_update_data(rdpFastPath* fastpath, wStream* s) { int status; UINT16 size; @@ -286,8 +287,8 @@ static int fastpath_recv_update_data(rdpFastPath* fastpath, STREAM* s) BYTE fragmentation; BYTE compression; BYTE compressionFlags; - STREAM* update_stream; - STREAM* comp_stream; + wStream* update_stream; + wStream* comp_stream; rdpRdp* rdp; UINT32 roff; UINT32 rlen; @@ -312,22 +313,23 @@ static int fastpath_recv_update_data(rdpFastPath* fastpath, STREAM* s) if (compressionFlags & PACKET_COMPRESSED) { - if (decompress_rdp(rdp->mppc_dec, s->p, size, compressionFlags, &roff, &rlen)) + if (decompress_rdp(rdp->mppc_dec, s->pointer, size, compressionFlags, &roff, &rlen)) { comp_stream = stream_new(0); - comp_stream->data = rdp->mppc_dec->history_buf + roff; - comp_stream->p = comp_stream->data; - comp_stream->size = rlen; - size = comp_stream->size; + comp_stream->buffer = rdp->mppc_dec->history_buf + roff; + comp_stream->pointer = comp_stream->buffer; + comp_stream->capacity = rlen; + size = comp_stream->capacity; } else { - printf("decompress_rdp() failed\n"); + fprintf(stderr, "decompress_rdp() failed\n"); stream_seek(s, size); } } update_stream = NULL; + if (fragmentation == FASTPATH_FRAGMENT_SINGLE) { totalSize = size; @@ -340,9 +342,10 @@ static int fastpath_recv_update_data(rdpFastPath* fastpath, STREAM* s) stream_check_size(fastpath->updateData, size); stream_copy(fastpath->updateData, comp_stream, size); + if (stream_get_length(fastpath->updateData) > rdp->settings->MultifragMaxRequestSize) { - printf("fastpath PDU is bigger than MultifragMaxRequestSize\n"); + fprintf(stderr, "fastpath PDU is bigger than MultifragMaxRequestSize\n"); return -1; } @@ -370,7 +373,7 @@ static int fastpath_recv_update_data(rdpFastPath* fastpath, STREAM* s) return status; } -int fastpath_recv_updates(rdpFastPath* fastpath, STREAM* s) +int fastpath_recv_updates(rdpFastPath* fastpath, wStream* s) { int status = 0; rdpUpdate* update = fastpath->rdp->update; @@ -388,7 +391,7 @@ int fastpath_recv_updates(rdpFastPath* fastpath, STREAM* s) return status; } -static BOOL fastpath_read_input_event_header(STREAM* s, BYTE* eventFlags, BYTE* eventCode) +static BOOL fastpath_read_input_event_header(wStream* s, BYTE* eventFlags, BYTE* eventCode) { BYTE eventHeader; @@ -403,7 +406,7 @@ static BOOL fastpath_read_input_event_header(STREAM* s, BYTE* eventFlags, BYTE* return TRUE; } -static BOOL fastpath_recv_input_event_scancode(rdpFastPath* fastpath, STREAM* s, BYTE eventFlags) +static BOOL fastpath_recv_input_event_scancode(rdpFastPath* fastpath, wStream* s, BYTE eventFlags) { UINT16 flags; UINT16 code; @@ -427,7 +430,7 @@ static BOOL fastpath_recv_input_event_scancode(rdpFastPath* fastpath, STREAM* s, return TRUE; } -static BOOL fastpath_recv_input_event_mouse(rdpFastPath* fastpath, STREAM* s, BYTE eventFlags) +static BOOL fastpath_recv_input_event_mouse(rdpFastPath* fastpath, wStream* s, BYTE eventFlags) { UINT16 pointerFlags; UINT16 xPos; @@ -445,7 +448,7 @@ static BOOL fastpath_recv_input_event_mouse(rdpFastPath* fastpath, STREAM* s, BY return TRUE; } -static BOOL fastpath_recv_input_event_mousex(rdpFastPath* fastpath, STREAM* s, BYTE eventFlags) +static BOOL fastpath_recv_input_event_mousex(rdpFastPath* fastpath, wStream* s, BYTE eventFlags) { UINT16 pointerFlags; UINT16 xPos; @@ -463,14 +466,14 @@ static BOOL fastpath_recv_input_event_mousex(rdpFastPath* fastpath, STREAM* s, B return TRUE; } -static BOOL fastpath_recv_input_event_sync(rdpFastPath* fastpath, STREAM* s, BYTE eventFlags) +static BOOL fastpath_recv_input_event_sync(rdpFastPath* fastpath, wStream* s, BYTE eventFlags) { IFCALL(fastpath->rdp->input->SynchronizeEvent, fastpath->rdp->input, eventFlags); return TRUE; } -static BOOL fastpath_recv_input_event_unicode(rdpFastPath* fastpath, STREAM* s, BYTE eventFlags) +static BOOL fastpath_recv_input_event_unicode(rdpFastPath* fastpath, wStream* s, BYTE eventFlags) { UINT16 unicodeCode; UINT16 flags; @@ -491,7 +494,7 @@ static BOOL fastpath_recv_input_event_unicode(rdpFastPath* fastpath, STREAM* s, return TRUE; } -static BOOL fastpath_recv_input_event(rdpFastPath* fastpath, STREAM* s) +static BOOL fastpath_recv_input_event(rdpFastPath* fastpath, wStream* s) { BYTE eventFlags; BYTE eventCode; @@ -527,14 +530,14 @@ static BOOL fastpath_recv_input_event(rdpFastPath* fastpath, STREAM* s) break; default: - printf("Unknown eventCode %d\n", eventCode); + fprintf(stderr, "Unknown eventCode %d\n", eventCode); break; } return TRUE; } -int fastpath_recv_inputs(rdpFastPath* fastpath, STREAM* s) +int fastpath_recv_inputs(rdpFastPath* fastpath, wStream* s) { BYTE i; @@ -575,10 +578,10 @@ static UINT32 fastpath_get_sec_bytes(rdpRdp* rdp) return sec_bytes; } -STREAM* fastpath_input_pdu_init(rdpFastPath* fastpath, BYTE eventFlags, BYTE eventCode) +wStream* fastpath_input_pdu_init(rdpFastPath* fastpath, BYTE eventFlags, BYTE eventCode) { rdpRdp *rdp; - STREAM* s; + wStream* s; rdp = fastpath->rdp; @@ -594,7 +597,7 @@ STREAM* fastpath_input_pdu_init(rdpFastPath* fastpath, BYTE eventFlags, BYTE eve return s; } -BOOL fastpath_send_input_pdu(rdpFastPath* fastpath, STREAM* s) +BOOL fastpath_send_input_pdu(rdpFastPath* fastpath, wStream* s) { rdpRdp *rdp; UINT16 length; @@ -606,7 +609,7 @@ BOOL fastpath_send_input_pdu(rdpFastPath* fastpath, STREAM* s) length = stream_get_length(s); if (length >= (2 << 14)) { - printf("Maximum FastPath PDU length is 32767\n"); + fprintf(stderr, "Maximum FastPath PDU length is 32767\n"); return FALSE; } @@ -651,9 +654,9 @@ BOOL fastpath_send_input_pdu(rdpFastPath* fastpath, STREAM* s) return TRUE; } -STREAM* fastpath_update_pdu_init(rdpFastPath* fastpath) +wStream* fastpath_update_pdu_init(rdpFastPath* fastpath) { - STREAM* s; + wStream* s; s = transport_send_stream_init(fastpath->rdp->transport, FASTPATH_MAX_PACKET_SIZE); stream_seek(s, 3); /* fpOutputHeader, length1 and length2 */ stream_seek(s, fastpath_get_sec_bytes(fastpath->rdp)); @@ -661,7 +664,7 @@ STREAM* fastpath_update_pdu_init(rdpFastPath* fastpath) return s; } -BOOL fastpath_send_update_pdu(rdpFastPath* fastpath, BYTE updateCode, STREAM* s) +BOOL fastpath_send_update_pdu(rdpFastPath* fastpath, BYTE updateCode, wStream* s) { rdpRdp* rdp; BYTE* bm; @@ -683,9 +686,9 @@ BOOL fastpath_send_update_pdu(rdpFastPath* fastpath, BYTE updateCode, STREAM* s) UINT32 totalLength; BYTE fragmentation; BYTE header; - STREAM* update; - STREAM* comp_update; - STREAM* ls; + wStream* update; + wStream* comp_update; + wStream* ls; result = TRUE; rdp = fastpath->rdp; @@ -708,7 +711,7 @@ BOOL fastpath_send_update_pdu(rdpFastPath* fastpath, BYTE updateCode, STREAM* s) pdu_data_bytes = dlen; if (try_comp) { - if (compress_rdp(rdp->mppc_enc, ls->p + header_bytes, dlen)) + if (compress_rdp(rdp->mppc_enc, ls->pointer + header_bytes, dlen)) { if (rdp->mppc_enc->flags & PACKET_COMPRESSED) { @@ -722,7 +725,7 @@ BOOL fastpath_send_update_pdu(rdpFastPath* fastpath, BYTE updateCode, STREAM* s) } } else - printf("fastpath_send_update_pdu: mppc_encode failed\n"); + fprintf(stderr, "fastpath_send_update_pdu: mppc_encode failed\n"); } totalLength -= dlen; diff --git a/libfreerdp/core/fastpath.h b/libfreerdp/core/fastpath.h index 3aa897a07..e7bcab46c 100644 --- a/libfreerdp/core/fastpath.h +++ b/libfreerdp/core/fastpath.h @@ -21,7 +21,8 @@ #define __FASTPATH_H #include "rdp.h" -#include <freerdp/utils/stream.h> + +#include <winpr/stream.h> typedef struct rdp_fastpath rdpFastPath; @@ -99,20 +100,20 @@ struct rdp_fastpath rdpRdp* rdp; BYTE encryptionFlags; BYTE numberEvents; - STREAM* updateData; + wStream* updateData; }; -UINT16 fastpath_header_length(STREAM* s); -UINT16 fastpath_read_header(rdpFastPath* fastpath, STREAM* s); -BOOL fastpath_read_header_rdp(rdpFastPath* fastpath, STREAM* s, UINT16 *length); -int fastpath_recv_updates(rdpFastPath* fastpath, STREAM* s); -int fastpath_recv_inputs(rdpFastPath* fastpath, STREAM* s); +UINT16 fastpath_header_length(wStream* s); +UINT16 fastpath_read_header(rdpFastPath* fastpath, wStream* s); +BOOL fastpath_read_header_rdp(rdpFastPath* fastpath, wStream* s, UINT16 *length); +int fastpath_recv_updates(rdpFastPath* fastpath, wStream* s); +int fastpath_recv_inputs(rdpFastPath* fastpath, wStream* s); -STREAM* fastpath_input_pdu_init(rdpFastPath* fastpath, BYTE eventFlags, BYTE eventCode); -BOOL fastpath_send_input_pdu(rdpFastPath* fastpath, STREAM* s); +wStream* fastpath_input_pdu_init(rdpFastPath* fastpath, BYTE eventFlags, BYTE eventCode); +BOOL fastpath_send_input_pdu(rdpFastPath* fastpath, wStream* s); -STREAM* fastpath_update_pdu_init(rdpFastPath* fastpath); -BOOL fastpath_send_update_pdu(rdpFastPath* fastpath, BYTE updateCode, STREAM* s); +wStream* fastpath_update_pdu_init(rdpFastPath* fastpath); +BOOL fastpath_send_update_pdu(rdpFastPath* fastpath, BYTE updateCode, wStream* s); BOOL fastpath_send_surfcmd_frame_marker(rdpFastPath* fastpath, UINT16 frameAction, UINT32 frameId); diff --git a/libfreerdp/core/freerdp.c b/libfreerdp/core/freerdp.c index a600189da..6770a1ab3 100644 --- a/libfreerdp/core/freerdp.c +++ b/libfreerdp/core/freerdp.c @@ -107,7 +107,7 @@ BOOL freerdp_connect(freerdp* instance) if (status != TRUE) { - printf("freerdp_post_connect failed\n"); + fprintf(stderr, "freerdp_post_connect failed\n"); if (!connectErrorCode) { @@ -119,7 +119,7 @@ BOOL freerdp_connect(freerdp* instance) if (instance->settings->PlayRemoteFx) { - STREAM* s; + wStream* s; rdpUpdate* update; pcap_record record; @@ -135,19 +135,19 @@ BOOL freerdp_connect(freerdp* instance) { pcap_get_next_record_header(update->pcap_rfx, &record); - s->data = (BYTE*) realloc(s->data, record.length); - record.data = s->data; - s->size = record.length; + s->buffer = (BYTE*) realloc(s->buffer, record.length); + record.data = s->buffer; + s->capacity = record.length; pcap_get_next_record_content(update->pcap_rfx, &record); stream_set_pos(s, 0); update->BeginPaint(update->context); - update_recv_surfcmds(update, s->size, s); + update_recv_surfcmds(update, s->capacity, s); update->EndPaint(update->context); } - free(s->data); + free(s->buffer); return TRUE; } } @@ -314,6 +314,9 @@ void freerdp_context_new(freerdp* instance) instance->context->update = instance->update; instance->context->settings = instance->settings; + instance->context->client = (rdpClient*) malloc(sizeof(rdpClient)); + ZeroMemory(instance->context->client, sizeof(rdpClient)); + instance->update->context = instance->context; instance->update->pointer->context = instance->context; instance->update->primary->context = instance->context; @@ -337,7 +340,7 @@ void freerdp_context_new(freerdp* instance) */ void freerdp_context_free(freerdp* instance) { - if (instance->context == NULL) + if (!instance->context) return; IFCALL(instance->ContextFree, instance, instance->context); @@ -345,6 +348,8 @@ void freerdp_context_free(freerdp* instance) rdp_free(instance->context->rdp); graphics_free(instance->context->graphics); + free(instance->context->client); + free(instance->context); instance->context = NULL; } diff --git a/libfreerdp/core/gateway/http.c b/libfreerdp/core/gateway/http.c index 6f7355fba..9c2ee81fb 100644 --- a/libfreerdp/core/gateway/http.c +++ b/libfreerdp/core/gateway/http.c @@ -386,9 +386,9 @@ void http_response_print(HttpResponse* http_response) for (i = 0; i < http_response->count; i++) { - printf("%s\n", http_response->lines[i]); + fprintf(stderr, "%s\n", http_response->lines[i]); } - printf("\n"); + fprintf(stderr, "\n"); } HttpResponse* http_response_recv(rdpTls* tls) @@ -441,7 +441,7 @@ HttpResponse* http_response_recv(rdpTls* tls) } else { - printf("http_response_recv: invalid response:\n"); + fprintf(stderr, "http_response_recv: invalid response:\n"); winpr_HexDump(buffer, status); http_response_free(http_response); return NULL; diff --git a/libfreerdp/core/gateway/ncacn_http.h b/libfreerdp/core/gateway/ncacn_http.h index 80e84c2f8..9c1d54ce1 100644 --- a/libfreerdp/core/gateway/ncacn_http.h +++ b/libfreerdp/core/gateway/ncacn_http.h @@ -27,7 +27,8 @@ #include <freerdp/crypto/crypto.h> #include <freerdp/utils/debug.h> -#include <freerdp/utils/stream.h> + +#include <winpr/stream.h> #include "rpc.h" diff --git a/libfreerdp/core/gateway/ntlm.c b/libfreerdp/core/gateway/ntlm.c index 75ba9bcf1..091aa1e42 100644 --- a/libfreerdp/core/gateway/ntlm.c +++ b/libfreerdp/core/gateway/ntlm.c @@ -71,7 +71,7 @@ BOOL ntlm_client_init(rdpNtlm* ntlm, BOOL http, char* user, char* domain, char* if (status != SEC_E_OK) { - printf("QuerySecurityPackageInfo status: 0x%08X\n", status); + fprintf(stderr, "QuerySecurityPackageInfo status: 0x%08X\n", status); return FALSE; } @@ -82,7 +82,7 @@ BOOL ntlm_client_init(rdpNtlm* ntlm, BOOL http, char* user, char* domain, char* if (status != SEC_E_OK) { - printf("AcquireCredentialsHandle status: 0x%08X\n", status); + fprintf(stderr, "AcquireCredentialsHandle status: 0x%08X\n", status); return FALSE; } @@ -242,7 +242,7 @@ BOOL ntlm_authenticate(rdpNtlm* ntlm) if (ntlm->table->QueryContextAttributes(&ntlm->context, SECPKG_ATTR_SIZES, &ntlm->ContextSizes) != SEC_E_OK) { - printf("QueryContextAttributes SECPKG_ATTR_SIZES failure\n"); + fprintf(stderr, "QueryContextAttributes SECPKG_ATTR_SIZES failure\n"); return FALSE; } diff --git a/libfreerdp/core/gateway/ntlm.h b/libfreerdp/core/gateway/ntlm.h index 073b3f0dc..257e84b05 100644 --- a/libfreerdp/core/gateway/ntlm.h +++ b/libfreerdp/core/gateway/ntlm.h @@ -38,8 +38,10 @@ typedef struct rdp_ntlm_http rdpNtlmHttp; #include <freerdp/crypto/tls.h> #include <freerdp/crypto/crypto.h> #include <freerdp/utils/debug.h> -#include <freerdp/utils/stream.h> + +#include <winpr/sspi.h> #include <winpr/print.h> +#include <winpr/stream.h> struct rdp_ntlm { diff --git a/libfreerdp/core/gateway/rpc.c b/libfreerdp/core/gateway/rpc.c index 69a5addb8..3e6f68b95 100644 --- a/libfreerdp/core/gateway/rpc.c +++ b/libfreerdp/core/gateway/rpc.c @@ -87,45 +87,45 @@ const RPC_SECURITY_PROVIDER_INFO RPC_SECURITY_PROVIDER_INFO_TABLE[] = void rpc_pdu_header_print(rpcconn_hdr_t* header) { - printf("rpc_vers: %d\n", header->common.rpc_vers); - printf("rpc_vers_minor: %d\n", header->common.rpc_vers_minor); + fprintf(stderr, "rpc_vers: %d\n", header->common.rpc_vers); + fprintf(stderr, "rpc_vers_minor: %d\n", header->common.rpc_vers_minor); if (header->common.ptype > PTYPE_RTS) - printf("ptype: %s (%d)\n", "PTYPE_UNKNOWN", header->common.ptype); + fprintf(stderr, "ptype: %s (%d)\n", "PTYPE_UNKNOWN", header->common.ptype); else - printf("ptype: %s (%d)\n", PTYPE_STRINGS[header->common.ptype], header->common.ptype); + fprintf(stderr, "ptype: %s (%d)\n", PTYPE_STRINGS[header->common.ptype], header->common.ptype); - printf("pfc_flags (0x%02X) = {", header->common.pfc_flags); + fprintf(stderr, "pfc_flags (0x%02X) = {", header->common.pfc_flags); if (header->common.pfc_flags & PFC_FIRST_FRAG) - printf(" PFC_FIRST_FRAG"); + fprintf(stderr, " PFC_FIRST_FRAG"); if (header->common.pfc_flags & PFC_LAST_FRAG) - printf(" PFC_LAST_FRAG"); + fprintf(stderr, " PFC_LAST_FRAG"); if (header->common.pfc_flags & PFC_PENDING_CANCEL) - printf(" PFC_PENDING_CANCEL"); + fprintf(stderr, " PFC_PENDING_CANCEL"); if (header->common.pfc_flags & PFC_RESERVED_1) - printf(" PFC_RESERVED_1"); + fprintf(stderr, " PFC_RESERVED_1"); if (header->common.pfc_flags & PFC_CONC_MPX) - printf(" PFC_CONC_MPX"); + fprintf(stderr, " PFC_CONC_MPX"); if (header->common.pfc_flags & PFC_DID_NOT_EXECUTE) - printf(" PFC_DID_NOT_EXECUTE"); + fprintf(stderr, " PFC_DID_NOT_EXECUTE"); if (header->common.pfc_flags & PFC_OBJECT_UUID) - printf(" PFC_OBJECT_UUID"); - printf(" }\n"); + fprintf(stderr, " PFC_OBJECT_UUID"); + fprintf(stderr, " }\n"); - printf("packed_drep[4]: %02X %02X %02X %02X\n", + fprintf(stderr, "packed_drep[4]: %02X %02X %02X %02X\n", header->common.packed_drep[0], header->common.packed_drep[1], header->common.packed_drep[2], header->common.packed_drep[3]); - printf("frag_length: %d\n", header->common.frag_length); - printf("auth_length: %d\n", header->common.auth_length); - printf("call_id: %d\n", header->common.call_id); + fprintf(stderr, "frag_length: %d\n", header->common.frag_length); + fprintf(stderr, "auth_length: %d\n", header->common.auth_length); + fprintf(stderr, "call_id: %d\n", header->common.call_id); if (header->common.ptype == PTYPE_RESPONSE) { - printf("alloc_hint: %d\n", header->response.alloc_hint); - printf("p_cont_id: %d\n", header->response.p_cont_id); - printf("cancel_count: %d\n", header->response.cancel_count); - printf("reserved: %d\n", header->response.reserved); + fprintf(stderr, "alloc_hint: %d\n", header->response.alloc_hint); + fprintf(stderr, "p_cont_id: %d\n", header->response.p_cont_id); + fprintf(stderr, "cancel_count: %d\n", header->response.cancel_count); + fprintf(stderr, "reserved: %d\n", header->response.reserved); } } @@ -285,7 +285,7 @@ BOOL rpc_get_stub_data_info(rdpRpc* rpc, BYTE* buffer, UINT32* offset, UINT32* l auth_pad_length = sec_trailer->auth_pad_length; #if 0 - printf("sec_trailer: type: %d level: %d pad_length: %d reserved: %d context_id: %d\n", + fprintf(stderr, "sec_trailer: type: %d level: %d pad_length: %d reserved: %d context_id: %d\n", sec_trailer->auth_type, sec_trailer->auth_level, sec_trailer->auth_pad_length, @@ -301,7 +301,7 @@ BOOL rpc_get_stub_data_info(rdpRpc* rpc, BYTE* buffer, UINT32* offset, UINT32* l if ((frag_length - (sec_trailer_offset + 8)) != auth_length) { - printf("invalid auth_length: actual: %d, expected: %d\n", auth_length, + fprintf(stderr, "invalid auth_length: actual: %d, expected: %d\n", auth_length, (frag_length - (sec_trailer_offset + 8))); } @@ -335,10 +335,10 @@ int rpc_in_write(rdpRpc* rpc, BYTE* data, int length) int status; #ifdef WITH_DEBUG_TSG - printf("Sending PDU (length: %d)\n", length); + fprintf(stderr, "Sending PDU (length: %d)\n", length); rpc_pdu_header_print((rpcconn_hdr_t*) data); winpr_HexDump(data, length); - printf("\n"); + fprintf(stderr, "\n"); #endif status = tls_write_all(rpc->TlsIn, data, length); @@ -362,7 +362,7 @@ int rpc_write(rdpRpc* rpc, BYTE* data, int length, UINT16 opnum) if (ntlm->table->QueryContextAttributes(&ntlm->context, SECPKG_ATTR_SIZES, &ntlm->ContextSizes) != SEC_E_OK) { - printf("QueryContextAttributes SECPKG_ATTR_SIZES failure\n"); + fprintf(stderr, "QueryContextAttributes SECPKG_ATTR_SIZES failure\n"); return -1; } @@ -432,7 +432,7 @@ int rpc_write(rdpRpc* rpc, BYTE* data, int length, UINT16 opnum) if (encrypt_status != SEC_E_OK) { - printf("EncryptMessage status: 0x%08X\n", encrypt_status); + fprintf(stderr, "EncryptMessage status: 0x%08X\n", encrypt_status); return -1; } @@ -453,7 +453,7 @@ BOOL rpc_connect(rdpRpc* rpc) if (!rts_connect(rpc)) { - printf("rts_connect error!\n"); + fprintf(stderr, "rts_connect error!\n"); return FALSE; } @@ -461,7 +461,7 @@ BOOL rpc_connect(rdpRpc* rpc) if (rpc_secure_bind(rpc) != 0) { - printf("rpc_secure_bind error!\n"); + fprintf(stderr, "rpc_secure_bind error!\n"); return FALSE; } diff --git a/libfreerdp/core/gateway/rpc.h b/libfreerdp/core/gateway/rpc.h index 1bfee5584..d10d665c7 100644 --- a/libfreerdp/core/gateway/rpc.h +++ b/libfreerdp/core/gateway/rpc.h @@ -77,7 +77,6 @@ typedef struct _RPC_PDU #include <freerdp/crypto/tls.h> #include <freerdp/crypto/crypto.h> #include <freerdp/utils/debug.h> -#include <freerdp/utils/stream.h> #include <winpr/print.h> /** diff --git a/libfreerdp/core/gateway/rpc_bind.c b/libfreerdp/core/gateway/rpc_bind.c index d524ff0d5..4bc93f57e 100644 --- a/libfreerdp/core/gateway/rpc_bind.c +++ b/libfreerdp/core/gateway/rpc_bind.c @@ -346,7 +346,7 @@ int rpc_secure_bind(rdpRpc* rpc) if (status <= 0) { - printf("rpc_secure_bind: error sending bind pdu!\n"); + fprintf(stderr, "rpc_secure_bind: error sending bind pdu!\n"); return -1; } @@ -358,13 +358,13 @@ int rpc_secure_bind(rdpRpc* rpc) if (!pdu) { - printf("rpc_secure_bind: error receiving bind ack pdu!\n"); + fprintf(stderr, "rpc_secure_bind: error receiving bind ack pdu!\n"); return -1; } if (rpc_recv_bind_ack_pdu(rpc, Stream_Buffer(pdu->s), Stream_Length(pdu->s)) <= 0) { - printf("rpc_secure_bind: error receiving bind ack pdu!\n"); + fprintf(stderr, "rpc_secure_bind: error receiving bind ack pdu!\n"); return -1; } @@ -372,7 +372,7 @@ int rpc_secure_bind(rdpRpc* rpc) if (rpc_send_rpc_auth_3_pdu(rpc) <= 0) { - printf("rpc_secure_bind: error sending rpc_auth_3 pdu!\n"); + fprintf(stderr, "rpc_secure_bind: error sending rpc_auth_3 pdu!\n"); return -1; } @@ -380,7 +380,7 @@ int rpc_secure_bind(rdpRpc* rpc) } else { - printf("rpc_secure_bind: invalid state: %d\n", rpc->State); + fprintf(stderr, "rpc_secure_bind: invalid state: %d\n", rpc->State); return -1; } } diff --git a/libfreerdp/core/gateway/rpc_client.c b/libfreerdp/core/gateway/rpc_client.c index 60999bc4d..d60ab3381 100644 --- a/libfreerdp/core/gateway/rpc_client.c +++ b/libfreerdp/core/gateway/rpc_client.c @@ -110,6 +110,7 @@ int rpc_client_on_fragment_received_event(rdpRpc* rpc) rpc_client_fragment_pool_return(rpc, fragment); Queue_Enqueue(rpc->client->ReceiveQueue, rpc->client->pdu); + SetEvent(rpc->transport->ReceiveEvent); rpc->client->pdu = NULL; return 0; @@ -119,14 +120,14 @@ int rpc_client_on_fragment_received_event(rdpRpc* rpc) { if (rpc->VirtualConnection->State >= VIRTUAL_CONNECTION_STATE_OPENED) { - //printf("Receiving Out-of-Sequence RTS PDU\n"); + //fprintf(stderr, "Receiving Out-of-Sequence RTS PDU\n"); rts_recv_out_of_sequence_pdu(rpc, buffer, header->common.frag_length); rpc_client_fragment_pool_return(rpc, fragment); } else { - printf("warning: unhandled RTS PDU\n"); + fprintf(stderr, "warning: unhandled RTS PDU\n"); } return 0; @@ -139,7 +140,7 @@ int rpc_client_on_fragment_received_event(rdpRpc* rpc) if (header->common.ptype != PTYPE_RESPONSE) { - printf("Unexpected RPC PDU type: %d\n", header->common.ptype); + fprintf(stderr, "Unexpected RPC PDU type: %d\n", header->common.ptype); return -1; } @@ -148,13 +149,13 @@ int rpc_client_on_fragment_received_event(rdpRpc* rpc) if (!rpc_get_stub_data_info(rpc, buffer, &StubOffset, &StubLength)) { - printf("rpc_recv_pdu_fragment: expected stub\n"); + fprintf(stderr, "rpc_recv_pdu_fragment: expected stub\n"); return -1; } if (StubLength == 4) { - //printf("Ignoring TsProxySendToServer Response\n"); + //fprintf(stderr, "Ignoring TsProxySendToServer Response\n"); rpc_client_fragment_pool_return(rpc, fragment); return 0; } @@ -168,7 +169,7 @@ int rpc_client_on_fragment_received_event(rdpRpc* rpc) if (rpc->StubCallId != header->common.call_id) { - printf("invalid call_id: actual: %d, expected: %d, frag_count: %d\n", + fprintf(stderr, "invalid call_id: actual: %d, expected: %d, frag_count: %d\n", rpc->StubCallId, header->common.call_id, rpc->StubFragCount); } @@ -179,7 +180,7 @@ int rpc_client_on_fragment_received_event(rdpRpc* rpc) if (rpc->VirtualConnection->DefaultOutChannel->ReceiverAvailableWindow < (rpc->ReceiveWindow / 2)) { - //printf("Sending Flow Control Ack PDU\n"); + //fprintf(stderr, "Sending Flow Control Ack PDU\n"); rts_send_flow_control_ack_pdu(rpc); } @@ -227,7 +228,7 @@ int rpc_client_on_read_event(rdpRpc* rpc) if (status < 0) { - printf("rpc_client_frag_read: error reading header\n"); + fprintf(stderr, "rpc_client_frag_read: error reading header\n"); return -1; } @@ -240,7 +241,7 @@ int rpc_client_on_read_event(rdpRpc* rpc) if (header->frag_length > rpc->max_recv_frag) { - printf("rpc_client_frag_read: invalid fragment size: %d (max: %d)\n", + fprintf(stderr, "rpc_client_frag_read: invalid fragment size: %d (max: %d)\n", header->frag_length, rpc->max_recv_frag); winpr_HexDump(Stream_Buffer(rpc->client->RecvFrag), Stream_Position(rpc->client->RecvFrag)); return -1; @@ -253,7 +254,7 @@ int rpc_client_on_read_event(rdpRpc* rpc) if (status < 0) { - printf("rpc_client_frag_read: error reading fragment body\n"); + fprintf(stderr, "rpc_client_frag_read: error reading fragment body\n"); return -1; } @@ -413,9 +414,9 @@ RPC_PDU* rpc_recv_dequeue_pdu(rdpRpc* rpc) #ifdef WITH_DEBUG_TSG if (pdu) { - printf("Receiving PDU (length: %d, CallId: %d)\n", pdu->s->length, pdu->CallId); + fprintf(stderr, "Receiving PDU (length: %d, CallId: %d)\n", pdu->s->length, pdu->CallId); winpr_HexDump(pdu->s->buffer, pdu->s->length); - printf("\n"); + fprintf(stderr, "\n"); } #endif @@ -425,6 +426,23 @@ RPC_PDU* rpc_recv_dequeue_pdu(rdpRpc* rpc) return pdu; } +RPC_PDU* rpc_recv_peek_pdu(rdpRpc* rpc) +{ + RPC_PDU* pdu; + DWORD dwMilliseconds; + + pdu = NULL; + dwMilliseconds = rpc->client->SynchronousReceive ? INFINITE : 0; + + if (WaitForSingleObject(Queue_Event(rpc->client->ReceiveQueue), dwMilliseconds) == WAIT_OBJECT_0) + { + pdu = (RPC_PDU*) Queue_Peek(rpc->client->ReceiveQueue); + return pdu; + } + + return pdu; +} + static void* rpc_client_thread(void* arg) { rdpRpc* rpc; diff --git a/libfreerdp/core/gateway/rpc_client.h b/libfreerdp/core/gateway/rpc_client.h index 38c79be85..569973f83 100644 --- a/libfreerdp/core/gateway/rpc_client.h +++ b/libfreerdp/core/gateway/rpc_client.h @@ -40,6 +40,7 @@ int rpc_send_dequeue_pdu(rdpRpc* rpc); int rpc_recv_enqueue_pdu(rdpRpc* rpc); RPC_PDU* rpc_recv_dequeue_pdu(rdpRpc* rpc); +RPC_PDU* rpc_recv_peek_pdu(rdpRpc* rpc); int rpc_client_new(rdpRpc* rpc); int rpc_client_start(rdpRpc* rpc); diff --git a/libfreerdp/core/gateway/rpc_fault.c b/libfreerdp/core/gateway/rpc_fault.c index c6282b74c..925efc6e8 100644 --- a/libfreerdp/core/gateway/rpc_fault.c +++ b/libfreerdp/core/gateway/rpc_fault.c @@ -315,7 +315,7 @@ int rpc_recv_fault_pdu(rpcconn_hdr_t* header) int index; UINT32 code; - printf("RPC Fault PDU:\n"); + fprintf(stderr, "RPC Fault PDU:\n"); code = rpc_map_status_code_to_win32_error_code(header->fault.status); @@ -323,7 +323,7 @@ int rpc_recv_fault_pdu(rpcconn_hdr_t* header) { if (RPC_FAULT_CODES[index].code == code) { - printf("status: %s (0x%08X)\n", RPC_FAULT_CODES[index].name, code); + fprintf(stderr, "status: %s (0x%08X)\n", RPC_FAULT_CODES[index].name, code); return 0; } } @@ -332,12 +332,12 @@ int rpc_recv_fault_pdu(rpcconn_hdr_t* header) { if (RPC_TSG_FAULT_CODES[index].code == code) { - printf("status: %s (0x%08X)\n", RPC_TSG_FAULT_CODES[index].name, code); + fprintf(stderr, "status: %s (0x%08X)\n", RPC_TSG_FAULT_CODES[index].name, code); return 0; } } - printf("status: %s (0x%08X)\n", "UNKNOWN", code); + fprintf(stderr, "status: %s (0x%08X)\n", "UNKNOWN", code); return 0; } diff --git a/libfreerdp/core/gateway/rts.c b/libfreerdp/core/gateway/rts.c index 15afc4625..2cd982f63 100644 --- a/libfreerdp/core/gateway/rts.c +++ b/libfreerdp/core/gateway/rts.c @@ -92,25 +92,25 @@ BOOL rts_connect(rdpRpc* rpc) if (!rpc_ntlm_http_out_connect(rpc)) { - printf("rpc_out_connect_http error!\n"); + fprintf(stderr, "rpc_out_connect_http error!\n"); return FALSE; } if (rts_send_CONN_A1_pdu(rpc) != 0) { - printf("rpc_send_CONN_A1_pdu error!\n"); + fprintf(stderr, "rpc_send_CONN_A1_pdu error!\n"); return FALSE; } if (!rpc_ntlm_http_in_connect(rpc)) { - printf("rpc_in_connect_http error!\n"); + fprintf(stderr, "rpc_in_connect_http error!\n"); return FALSE; } if (rts_send_CONN_B1_pdu(rpc) != 0) { - printf("rpc_send_CONN_B1_pdu error!\n"); + fprintf(stderr, "rpc_send_CONN_B1_pdu error!\n"); return FALSE; } @@ -149,7 +149,7 @@ BOOL rts_connect(rdpRpc* rpc) if (http_response->StatusCode != 200) { - printf("rts_connect error! Status Code: %d\n", http_response->StatusCode); + fprintf(stderr, "rts_connect error! Status Code: %d\n", http_response->StatusCode); http_response_print(http_response); http_response_free(http_response); return FALSE; @@ -188,7 +188,7 @@ BOOL rts_connect(rdpRpc* rpc) if (!rts_match_pdu_signature(rpc, &RTS_PDU_CONN_A3_SIGNATURE, rts)) { - printf("Unexpected RTS PDU: Expected CONN/A3\n"); + fprintf(stderr, "Unexpected RTS PDU: Expected CONN/A3\n"); return FALSE; } @@ -229,7 +229,7 @@ BOOL rts_connect(rdpRpc* rpc) if (!rts_match_pdu_signature(rpc, &RTS_PDU_CONN_C2_SIGNATURE, rts)) { - printf("Unexpected RTS PDU: Expected CONN/C2\n"); + fprintf(stderr, "Unexpected RTS PDU: Expected CONN/C2\n"); return FALSE; } @@ -842,9 +842,9 @@ int rts_recv_flow_control_ack_pdu(rdpRpc* rpc, BYTE* buffer, UINT32 length) &BytesReceived, &AvailableWindow, (BYTE*) &ChannelCookie) + 4; #if 0 - printf("BytesReceived: %d AvailableWindow: %d\n", + fprintf(stderr, "BytesReceived: %d AvailableWindow: %d\n", BytesReceived, AvailableWindow); - printf("ChannelCookie: " RPC_UUID_FORMAT_STRING "\n", RPC_UUID_FORMAT_ARGUMENTS(ChannelCookie)); + fprintf(stderr, "ChannelCookie: " RPC_UUID_FORMAT_STRING "\n", RPC_UUID_FORMAT_ARGUMENTS(ChannelCookie)); #endif rpc->VirtualConnection->DefaultInChannel->SenderAvailableWindow = @@ -883,9 +883,9 @@ int rts_recv_flow_control_ack_with_destination_pdu(rdpRpc* rpc, BYTE* buffer, UI &BytesReceived, &AvailableWindow, (BYTE*) &ChannelCookie) + 4; #if 0 - printf("Destination: %d BytesReceived: %d AvailableWindow: %d\n", + fprintf(stderr, "Destination: %d BytesReceived: %d AvailableWindow: %d\n", Destination, BytesReceived, AvailableWindow); - printf("ChannelCookie: " RPC_UUID_FORMAT_STRING "\n", RPC_UUID_FORMAT_ARGUMENTS(ChannelCookie)); + fprintf(stderr, "ChannelCookie: " RPC_UUID_FORMAT_STRING "\n", RPC_UUID_FORMAT_ARGUMENTS(ChannelCookie)); #endif rpc->VirtualConnection->DefaultInChannel->SenderAvailableWindow = @@ -986,7 +986,7 @@ int rts_command_length(rdpRpc* rpc, UINT32 CommandType, BYTE* buffer, UINT32 len break; default: - printf("Error: Unknown RTS Command Type: 0x%x\n", CommandType); + fprintf(stderr, "Error: Unknown RTS Command Type: 0x%x\n", CommandType); return -1; break; } @@ -1019,7 +1019,7 @@ int rts_recv_out_of_sequence_pdu(rdpRpc* rpc, BYTE* buffer, UINT32 length) } else { - printf("Unimplemented signature id: 0x%08X\n", SignatureId); + fprintf(stderr, "Unimplemented signature id: 0x%08X\n", SignatureId); rts_print_pdu_signature(rpc, &signature); } diff --git a/libfreerdp/core/gateway/rts_signature.c b/libfreerdp/core/gateway/rts_signature.c index f9b648451..34598fe71 100644 --- a/libfreerdp/core/gateway/rts_signature.c +++ b/libfreerdp/core/gateway/rts_signature.c @@ -320,13 +320,13 @@ int rts_print_pdu_signature(rdpRpc* rpc, RtsPduSignature* signature) UINT32 SignatureId; RTS_PDU_SIGNATURE_ENTRY* entry; - printf("RTS PDU Signature: Flags: 0x%04X NumberOfCommands: %d\n", + fprintf(stderr, "RTS PDU Signature: Flags: 0x%04X NumberOfCommands: %d\n", signature->Flags, signature->NumberOfCommands); SignatureId = rts_identify_pdu_signature(rpc, signature, &entry); if (SignatureId) - printf("Identified %s RTS PDU\n", entry->PduName); + fprintf(stderr, "Identified %s RTS PDU\n", entry->PduName); return 0; } diff --git a/libfreerdp/core/gateway/tsg.c b/libfreerdp/core/gateway/tsg.c index 47a1f570d..1aa2f9a5e 100644 --- a/libfreerdp/core/gateway/tsg.c +++ b/libfreerdp/core/gateway/tsg.c @@ -129,7 +129,7 @@ DWORD TsProxySendToServer(handle_t IDL_handle, byte pRpcMessage[], UINT32 count, if (status <= 0) { - printf("rpc_write failed!\n"); + fprintf(stderr, "rpc_write failed!\n"); return -1; } @@ -293,7 +293,7 @@ BOOL TsProxyCreateTunnelReadResponse(rdpTsg* tsg, RPC_PDU* pdu) if (versionCaps->tsgHeader.ComponentId != TS_GATEWAY_TRANSPORT) { - printf("Unexpected ComponentId: 0x%04X, Expected TS_GATEWAY_TRANSPORT\n", + fprintf(stderr, "Unexpected ComponentId: 0x%04X, Expected TS_GATEWAY_TRANSPORT\n", versionCaps->tsgHeader.ComponentId); return FALSE; } @@ -319,7 +319,7 @@ BOOL TsProxyCreateTunnelReadResponse(rdpTsg* tsg, RPC_PDU* pdu) if ((SwitchValue != TSG_CAPABILITY_TYPE_NAP) || (tsgCaps->capabilityType != TSG_CAPABILITY_TYPE_NAP)) { - printf("Unexpected CapabilityType: 0x%08X, Expected TSG_CAPABILITY_TYPE_NAP\n", + fprintf(stderr, "Unexpected CapabilityType: 0x%08X, Expected TSG_CAPABILITY_TYPE_NAP\n", tsgCaps->capabilityType); return FALSE; } @@ -336,9 +336,9 @@ BOOL TsProxyCreateTunnelReadResponse(rdpTsg* tsg, RPC_PDU* pdu) offset += 20; #ifdef WITH_DEBUG_TSG - printf("TSG TunnelContext:\n"); + fprintf(stderr, "TSG TunnelContext:\n"); winpr_HexDump((void*) &tsg->TunnelContext, 20); - printf("\n"); + fprintf(stderr, "\n"); #endif free(tsgCaps); @@ -394,7 +394,7 @@ BOOL TsProxyCreateTunnelReadResponse(rdpTsg* tsg, RPC_PDU* pdu) if (versionCaps->tsgHeader.ComponentId != TS_GATEWAY_TRANSPORT) { - printf("Unexpected ComponentId: 0x%04X, Expected TS_GATEWAY_TRANSPORT\n", + fprintf(stderr, "Unexpected ComponentId: 0x%04X, Expected TS_GATEWAY_TRANSPORT\n", versionCaps->tsgHeader.ComponentId); return FALSE; } @@ -421,9 +421,9 @@ BOOL TsProxyCreateTunnelReadResponse(rdpTsg* tsg, RPC_PDU* pdu) offset += 20; #ifdef WITH_DEBUG_TSG - printf("TSG TunnelContext:\n"); + fprintf(stderr, "TSG TunnelContext:\n"); winpr_HexDump((void*) &tsg->TunnelContext, 20); - printf("\n"); + fprintf(stderr, "\n"); #endif free(versionCaps); @@ -431,7 +431,7 @@ BOOL TsProxyCreateTunnelReadResponse(rdpTsg* tsg, RPC_PDU* pdu) } else { - printf("Unexpected PacketId: 0x%08X, Expected TSG_PACKET_TYPE_CAPS_RESPONSE " + fprintf(stderr, "Unexpected PacketId: 0x%08X, Expected TSG_PACKET_TYPE_CAPS_RESPONSE " "or TSG_PACKET_TYPE_QUARENC_RESPONSE\n", packet->packetId); return FALSE; } @@ -460,7 +460,7 @@ BOOL TsProxyCreateTunnel(rdpTsg* tsg, PTSG_PACKET tsgPacket, PTSG_PACKET* tsgPac if (!TsProxyCreateTunnelWriteRequest(tsg)) { - printf("TsProxyCreateTunnel: error writing request\n"); + fprintf(stderr, "TsProxyCreateTunnel: error writing request\n"); return FALSE; } @@ -562,7 +562,7 @@ BOOL TsProxyAuthorizeTunnelReadResponse(rdpTsg* tsg, RPC_PDU* pdu) if ((packet->packetId != TSG_PACKET_TYPE_RESPONSE) || (SwitchValue != TSG_PACKET_TYPE_RESPONSE)) { - printf("Unexpected PacketId: 0x%08X, Expected TSG_PACKET_TYPE_RESPONSE\n", packet->packetId); + fprintf(stderr, "Unexpected PacketId: 0x%08X, Expected TSG_PACKET_TYPE_RESPONSE\n", packet->packetId); return FALSE; } @@ -575,7 +575,7 @@ BOOL TsProxyAuthorizeTunnelReadResponse(rdpTsg* tsg, RPC_PDU* pdu) if (packetResponse->flags != TSG_PACKET_TYPE_QUARREQUEST) { - printf("Unexpected Packet Response Flags: 0x%08X, Expected TSG_PACKET_TYPE_QUARREQUEST\n", + fprintf(stderr, "Unexpected Packet Response Flags: 0x%08X, Expected TSG_PACKET_TYPE_QUARREQUEST\n", packetResponse->flags); return FALSE; } @@ -599,7 +599,7 @@ BOOL TsProxyAuthorizeTunnelReadResponse(rdpTsg* tsg, RPC_PDU* pdu) if (SizeValue != packetResponse->responseDataLen) { - printf("Unexpected size value: %d, expected: %d\n", SizeValue, packetResponse->responseDataLen); + fprintf(stderr, "Unexpected size value: %d, expected: %d\n", SizeValue, packetResponse->responseDataLen); return FALSE; } @@ -630,7 +630,7 @@ BOOL TsProxyAuthorizeTunnel(rdpTsg* tsg, PTUNNEL_CONTEXT_HANDLE_NOSERIALIZE tunn if (!TsProxyAuthorizeTunnelWriteRequest(tsg, tunnelContext)) { - printf("TsProxyAuthorizeTunnel: error writing request\n"); + fprintf(stderr, "TsProxyAuthorizeTunnel: error writing request\n"); return FALSE; } @@ -709,7 +709,7 @@ BOOL TsProxyMakeTunnelCallReadResponse(rdpTsg* tsg, RPC_PDU* pdu) if ((packet->packetId != TSG_PACKET_TYPE_MESSAGE_PACKET) || (SwitchValue != TSG_PACKET_TYPE_MESSAGE_PACKET)) { - printf("Unexpected PacketId: 0x%08X, Expected TSG_PACKET_TYPE_MESSAGE_PACKET\n", packet->packetId); + fprintf(stderr, "Unexpected PacketId: 0x%08X, Expected TSG_PACKET_TYPE_MESSAGE_PACKET\n", packet->packetId); return FALSE; } @@ -742,7 +742,7 @@ BOOL TsProxyMakeTunnelCallReadResponse(rdpTsg* tsg, RPC_PDU* pdu) ActualCount = *((UINT32*) &buffer[offset + 56]); /* ActualCount */ ConvertFromUnicode(CP_UTF8, 0, (WCHAR*) &buffer[offset + 60], ActualCount, &messageText, 0, NULL, NULL); - printf("Consent Message: %s\n", messageText); + fprintf(stderr, "Consent Message: %s\n", messageText); free(messageText); break; @@ -763,7 +763,7 @@ BOOL TsProxyMakeTunnelCallReadResponse(rdpTsg* tsg, RPC_PDU* pdu) ActualCount = *((UINT32*) &buffer[offset + 56]); /* ActualCount */ ConvertFromUnicode(CP_UTF8, 0, (WCHAR*) &buffer[offset + 60], ActualCount, &messageText, 0, NULL, NULL); - printf("Service Message: %s\n", messageText); + fprintf(stderr, "Service Message: %s\n", messageText); free(messageText); break; @@ -777,7 +777,7 @@ BOOL TsProxyMakeTunnelCallReadResponse(rdpTsg* tsg, RPC_PDU* pdu) break; default: - printf("TsProxyMakeTunnelCallReadResponse: unexpected message type: %d\n", SwitchValue); + fprintf(stderr, "TsProxyMakeTunnelCallReadResponse: unexpected message type: %d\n", SwitchValue); return FALSE; break; } @@ -803,7 +803,7 @@ BOOL TsProxyMakeTunnelCall(rdpTsg* tsg, PTUNNEL_CONTEXT_HANDLE_NOSERIALIZE tunne if (!TsProxyMakeTunnelCallWriteRequest(tsg, tunnelContext, procId)) { - printf("TsProxyMakeTunnelCall: error writing request\n"); + fprintf(stderr, "TsProxyMakeTunnelCall: error writing request\n"); return FALSE; } @@ -822,9 +822,9 @@ BOOL TsProxyCreateChannelWriteRequest(rdpTsg* tsg, PTUNNEL_CONTEXT_HANDLE_NOSERI count = _wcslen(tsg->Hostname) + 1; #ifdef WITH_DEBUG_TSG - printf("ResourceName:\n"); + fprintf(stderr, "ResourceName:\n"); winpr_HexDump((BYTE*) tsg->Hostname, (count - 1) * 2); - printf("\n"); + fprintf(stderr, "\n"); #endif length = 60 + (count * 2); @@ -888,9 +888,9 @@ BOOL TsProxyCreateChannelReadResponse(rdpTsg* tsg, RPC_PDU* pdu) CopyMemory(tsg->ChannelContext.ContextUuid, &buffer[offset + 4], 16); /* ContextUuid (16 bytes) */ #ifdef WITH_DEBUG_TSG - printf("ChannelContext:\n"); + fprintf(stderr, "ChannelContext:\n"); winpr_HexDump((void*) &tsg->ChannelContext, 20); - printf("\n"); + fprintf(stderr, "\n"); #endif rpc_client_receive_pool_return(rpc, pdu); @@ -916,7 +916,7 @@ BOOL TsProxyCreateChannel(rdpTsg* tsg, PTUNNEL_CONTEXT_HANDLE_NOSERIALIZE tunnel if (!TsProxyCreateChannelWriteRequest(tsg, tunnelContext)) { - printf("TsProxyCreateChannel: error writing request\n"); + fprintf(stderr, "TsProxyCreateChannel: error writing request\n"); return FALSE; } @@ -986,13 +986,13 @@ HRESULT TsProxyCloseChannel(rdpTsg* tsg, PCHANNEL_CONTEXT_HANDLE_NOSERIALIZE* co if (!TsProxyCloseChannelWriteRequest(tsg, context)) { - printf("TsProxyCloseChannel: error writing request\n"); + fprintf(stderr, "TsProxyCloseChannel: error writing request\n"); return FALSE; } if (!TsProxyCloseChannelReadResponse(tsg, pdu)) { - printf("TsProxyCloseChannel: error reading response\n"); + fprintf(stderr, "TsProxyCloseChannel: error reading response\n"); return FALSE; } @@ -1062,13 +1062,13 @@ HRESULT TsProxyCloseTunnel(rdpTsg* tsg, PTUNNEL_CONTEXT_HANDLE_SERIALIZE* contex if (!TsProxyCloseTunnelWriteRequest(tsg, context)) { - printf("TsProxyCloseTunnel: error writing request\n"); + fprintf(stderr, "TsProxyCloseTunnel: error writing request\n"); return FALSE; } if (!TsProxyCloseTunnelReadResponse(tsg, pdu)) { - printf("TsProxyCloseTunnel: error reading response\n"); + fprintf(stderr, "TsProxyCloseTunnel: error reading response\n"); return FALSE; } @@ -1123,7 +1123,7 @@ BOOL TsProxySetupReceivePipe(handle_t IDL_handle, BYTE* pRpcMessage) if (!TsProxySetupReceivePipeWriteRequest(tsg)) { - printf("TsProxySetupReceivePipe: error writing request\n"); + fprintf(stderr, "TsProxySetupReceivePipe: error writing request\n"); return FALSE; } @@ -1143,7 +1143,7 @@ BOOL tsg_connect(rdpTsg* tsg, const char* hostname, UINT16 port) if (!rpc_connect(rpc)) { - printf("rpc_connect failed!\n"); + fprintf(stderr, "rpc_connect failed!\n"); return FALSE; } @@ -1206,7 +1206,7 @@ BOOL tsg_connect(rdpTsg* tsg, const char* hostname, UINT16 port) if (!TsProxyCreateTunnelReadResponse(tsg, pdu)) { - printf("TsProxyCreateTunnel: error reading response\n"); + fprintf(stderr, "TsProxyCreateTunnel: error reading response\n"); return FALSE; } @@ -1252,7 +1252,7 @@ BOOL tsg_connect(rdpTsg* tsg, const char* hostname, UINT16 port) if (!TsProxyAuthorizeTunnelReadResponse(tsg, pdu)) { - printf("TsProxyAuthorizeTunnel: error reading response\n"); + fprintf(stderr, "TsProxyAuthorizeTunnel: error reading response\n"); return FALSE; } @@ -1296,7 +1296,7 @@ BOOL tsg_connect(rdpTsg* tsg, const char* hostname, UINT16 port) { if (!TsProxyMakeTunnelCallReadResponse(tsg, pdu)) { - printf("TsProxyMakeTunnelCall: error reading response\n"); + fprintf(stderr, "TsProxyMakeTunnelCall: error reading response\n"); return FALSE; } @@ -1305,7 +1305,7 @@ BOOL tsg_connect(rdpTsg* tsg, const char* hostname, UINT16 port) if (!TsProxyCreateChannelReadResponse(tsg, pdu)) { - printf("TsProxyCreateChannel: error reading response\n"); + fprintf(stderr, "TsProxyCreateChannel: error reading response\n"); return FALSE; } @@ -1334,7 +1334,7 @@ BOOL tsg_connect(rdpTsg* tsg, const char* hostname, UINT16 port) if (!TsProxySetupReceivePipeReadResponse(tsg, pdu)) { - printf("TsProxySetupReceivePipe: error reading response\n"); + fprintf(stderr, "TsProxySetupReceivePipe: error reading response\n"); return FALSE; } #endif @@ -1342,7 +1342,7 @@ BOOL tsg_connect(rdpTsg* tsg, const char* hostname, UINT16 port) rpc->client->SynchronousSend = TRUE; rpc->client->SynchronousReceive = TRUE; - printf("TS Gateway Connection Success\n"); + fprintf(stderr, "TS Gateway Connection Success\n"); return TRUE; } @@ -1399,6 +1399,7 @@ int tsg_read(rdpTsg* tsg, BYTE* data, UINT32 length) if (tsg->BytesAvailable < 1) { tsg->PendingPdu = FALSE; + rpc_recv_dequeue_pdu(rpc); rpc_client_receive_pool_return(rpc, tsg->pdu); } @@ -1406,7 +1407,7 @@ int tsg_read(rdpTsg* tsg, BYTE* data, UINT32 length) } else { - tsg->pdu = rpc_recv_dequeue_pdu(rpc); + tsg->pdu = rpc_recv_peek_pdu(rpc); if (!tsg->pdu) { @@ -1429,6 +1430,7 @@ int tsg_read(rdpTsg* tsg, BYTE* data, UINT32 length) if (tsg->BytesAvailable < 1) { tsg->PendingPdu = FALSE; + rpc_recv_dequeue_pdu(rpc); rpc_client_receive_pool_return(rpc, tsg->pdu); } @@ -1446,6 +1448,8 @@ BOOL tsg_set_blocking_mode(rdpTsg* tsg, BOOL blocking) tsg->rpc->client->SynchronousSend = TRUE; tsg->rpc->client->SynchronousReceive = blocking; + tsg->transport->GatewayEvent = Queue_Event(tsg->rpc->client->ReceiveQueue); + return TRUE; } diff --git a/libfreerdp/core/gcc.c b/libfreerdp/core/gcc.c index 856721049..2904fe619 100644 --- a/libfreerdp/core/gcc.c +++ b/libfreerdp/core/gcc.c @@ -137,7 +137,7 @@ BYTE h221_sc_key[4] = "McDn"; * @param settings rdp settings */ -BOOL gcc_read_conference_create_request(STREAM* s, rdpSettings* settings) +BOOL gcc_read_conference_create_request(wStream* s, rdpSettings* settings) { UINT16 length; BYTE choice; @@ -194,7 +194,7 @@ BOOL gcc_read_conference_create_request(STREAM* s, rdpSettings* settings) * @param user_data client data blocks */ -void gcc_write_conference_create_request(STREAM* s, STREAM* user_data) +void gcc_write_conference_create_request(wStream* s, wStream* user_data) { /* ConnectData */ per_write_choice(s, 0); /* From Key select object (0) of type OBJECT_IDENTIFIER */ @@ -219,10 +219,10 @@ void gcc_write_conference_create_request(STREAM* s, STREAM* user_data) per_write_octet_string(s, h221_cs_key, 4, 4); /* h221NonStandard, client-to-server H.221 key, "Duca" */ /* userData::value (OCTET_STRING) */ - per_write_octet_string(s, user_data->data, stream_get_length(user_data), 0); /* array of client data blocks */ + per_write_octet_string(s, user_data->buffer, stream_get_length(user_data), 0); /* array of client data blocks */ } -BOOL gcc_read_conference_create_response(STREAM* s, rdpSettings* settings) +BOOL gcc_read_conference_create_response(wStream* s, rdpSettings* settings) { UINT16 length; UINT32 tag; @@ -264,14 +264,14 @@ BOOL gcc_read_conference_create_response(STREAM* s, rdpSettings* settings) per_read_length(s, &length); if (!gcc_read_server_data_blocks(s, settings, length)) { - printf("gcc_read_conference_create_response: gcc_read_server_data_blocks failed\n"); + fprintf(stderr, "gcc_read_conference_create_response: gcc_read_server_data_blocks failed\n"); return FALSE; } return TRUE; } -void gcc_write_conference_create_response(STREAM* s, STREAM* user_data) +void gcc_write_conference_create_response(wStream* s, wStream* user_data) { /* ConnectData */ per_write_choice(s, 0); @@ -302,10 +302,10 @@ void gcc_write_conference_create_response(STREAM* s, STREAM* user_data) per_write_octet_string(s, h221_sc_key, 4, 4); /* h221NonStandard, server-to-client H.221 key, "McDn" */ /* userData (OCTET_STRING) */ - per_write_octet_string(s, user_data->data, stream_get_length(user_data), 0); /* array of server data blocks */ + per_write_octet_string(s, user_data->buffer, stream_get_length(user_data), 0); /* array of server data blocks */ } -BOOL gcc_read_client_data_blocks(STREAM* s, rdpSettings* settings, int length) +BOOL gcc_read_client_data_blocks(wStream* s, rdpSettings* settings, int length) { UINT16 type; UINT16 blockLength; @@ -355,7 +355,7 @@ BOOL gcc_read_client_data_blocks(STREAM* s, rdpSettings* settings, int length) return TRUE; } -void gcc_write_client_data_blocks(STREAM* s, rdpSettings* settings) +void gcc_write_client_data_blocks(wStream* s, rdpSettings* settings) { gcc_write_client_core_data(s, settings); gcc_write_client_cluster_data(s, settings); @@ -375,22 +375,22 @@ void gcc_write_client_data_blocks(STREAM* s, rdpSettings* settings) { if (settings->UseMultimon) { - printf("WARNING: true multi monitor support was not advertised by server!\n"); + fprintf(stderr, "WARNING: true multi monitor support was not advertised by server!\n"); if (settings->ForceMultimon) { - printf("Sending multi monitor information anyway (may break connectivity!)\n"); + fprintf(stderr, "Sending multi monitor information anyway (may break connectivity!)\n"); gcc_write_client_monitor_data(s, settings); } else { - printf("Use /multimon:force to force sending multi monitor information\n"); + fprintf(stderr, "Use /multimon:force to force sending multi monitor information\n"); } } } } -BOOL gcc_read_server_data_blocks(STREAM* s, rdpSettings* settings, int length) +BOOL gcc_read_server_data_blocks(wStream* s, rdpSettings* settings, int length) { UINT16 type; UINT16 offset = 0; @@ -399,11 +399,11 @@ BOOL gcc_read_server_data_blocks(STREAM* s, rdpSettings* settings, int length) while (offset < length) { - holdp = s->p; + holdp = s->pointer; if (!gcc_read_user_data_header(s, &type, &blockLength)) { - printf("gcc_read_server_data_blocks: gcc_read_user_data_header failed\n"); + fprintf(stderr, "gcc_read_server_data_blocks: gcc_read_user_data_header failed\n"); return FALSE; } @@ -412,7 +412,7 @@ BOOL gcc_read_server_data_blocks(STREAM* s, rdpSettings* settings, int length) case SC_CORE: if (!gcc_read_server_core_data(s, settings)) { - printf("gcc_read_server_data_blocks: gcc_read_server_core_data failed\n"); + fprintf(stderr, "gcc_read_server_data_blocks: gcc_read_server_core_data failed\n"); return FALSE; } break; @@ -420,7 +420,7 @@ BOOL gcc_read_server_data_blocks(STREAM* s, rdpSettings* settings, int length) case SC_SECURITY: if (!gcc_read_server_security_data(s, settings)) { - printf("gcc_read_server_data_blocks: gcc_read_server_security_data failed\n"); + fprintf(stderr, "gcc_read_server_data_blocks: gcc_read_server_security_data failed\n"); return FALSE; } break; @@ -428,30 +428,30 @@ BOOL gcc_read_server_data_blocks(STREAM* s, rdpSettings* settings, int length) case SC_NET: if (!gcc_read_server_network_data(s, settings)) { - printf("gcc_read_server_data_blocks: gcc_read_server_network_data failed\n"); + fprintf(stderr, "gcc_read_server_data_blocks: gcc_read_server_network_data failed\n"); return FALSE; } break; default: - printf("gcc_read_server_data_blocks: ignoring type=%hu\n", type); + fprintf(stderr, "gcc_read_server_data_blocks: ignoring type=%hu\n", type); break; } offset += blockLength; - s->p = holdp + blockLength; + s->pointer = holdp + blockLength; } return TRUE; } -void gcc_write_server_data_blocks(STREAM* s, rdpSettings* settings) +void gcc_write_server_data_blocks(wStream* s, rdpSettings* settings) { gcc_write_server_core_data(s, settings); gcc_write_server_network_data(s, settings); gcc_write_server_security_data(s, settings); } -BOOL gcc_read_user_data_header(STREAM* s, UINT16* type, UINT16* length) +BOOL gcc_read_user_data_header(wStream* s, UINT16* type, UINT16* length) { if (stream_get_left(s) < 4) return FALSE; @@ -473,7 +473,7 @@ BOOL gcc_read_user_data_header(STREAM* s, UINT16* type, UINT16* length) * @param length data block length */ -void gcc_write_user_data_header(STREAM* s, UINT16 type, UINT16 length) +void gcc_write_user_data_header(wStream* s, UINT16 type, UINT16 length) { stream_write_UINT16(s, type); /* type */ stream_write_UINT16(s, length); /* length */ @@ -486,7 +486,7 @@ void gcc_write_user_data_header(STREAM* s, UINT16 type, UINT16 length) * @param settings rdp settings */ -BOOL gcc_read_client_core_data(STREAM* s, rdpSettings* settings, UINT16 blockLength) +BOOL gcc_read_client_core_data(wStream* s, rdpSettings* settings, UINT16 blockLength) { char* str = NULL; UINT32 version; @@ -495,7 +495,6 @@ BOOL gcc_read_client_core_data(STREAM* s, rdpSettings* settings, UINT16 blockLen UINT16 postBeta2ColorDepth = 0; UINT16 highColorDepth = 0; UINT16 supportedColorDepths = 0; - UINT16 earlyCapabilityFlags = 0; UINT32 serverSelectedProtocol = 0; /* Length of all required fields, until imeFileName */ @@ -564,7 +563,7 @@ BOOL gcc_read_client_core_data(STREAM* s, rdpSettings* settings, UINT16 blockLen if (blockLength < 2) break; - stream_read_UINT16(s, earlyCapabilityFlags); /* earlyCapabilityFlags */ + stream_read_UINT16(s, settings->EarlyCapabilityFlags); /* earlyCapabilityFlags */ blockLength -= 2; if (blockLength < 64) @@ -597,7 +596,7 @@ BOOL gcc_read_client_core_data(STREAM* s, rdpSettings* settings, UINT16 blockLen if (highColorDepth > 0) { - if (earlyCapabilityFlags & RNS_UD_CS_WANT_32BPP_SESSION) + if (settings->EarlyCapabilityFlags & RNS_UD_CS_WANT_32BPP_SESSION) color_depth = 32; else color_depth = highColorDepth; @@ -657,7 +656,7 @@ BOOL gcc_read_client_core_data(STREAM* s, rdpSettings* settings, UINT16 blockLen * @param settings rdp settings */ -void gcc_write_client_core_data(STREAM* s, rdpSettings* settings) +void gcc_write_client_core_data(wStream* s, rdpSettings* settings) { UINT32 version; WCHAR* clientName = NULL; @@ -749,7 +748,7 @@ void gcc_write_client_core_data(STREAM* s, rdpSettings* settings) stream_write_UINT32(s, settings->SelectedProtocol); /* serverSelectedProtocol */ } -BOOL gcc_read_server_core_data(STREAM* s, rdpSettings* settings) +BOOL gcc_read_server_core_data(wStream* s, rdpSettings* settings) { UINT32 version; UINT32 clientRequestedProtocols; @@ -767,7 +766,7 @@ BOOL gcc_read_server_core_data(STREAM* s, rdpSettings* settings) return TRUE; } -void gcc_write_server_core_data(STREAM* s, rdpSettings* settings) +void gcc_write_server_core_data(wStream* s, rdpSettings* settings) { gcc_write_user_data_header(s, SC_CORE, 12); @@ -782,7 +781,7 @@ void gcc_write_server_core_data(STREAM* s, rdpSettings* settings) * @param settings rdp settings */ -BOOL gcc_read_client_security_data(STREAM* s, rdpSettings* settings, UINT16 blockLength) +BOOL gcc_read_client_security_data(wStream* s, rdpSettings* settings, UINT16 blockLength) { if (blockLength < 8) return FALSE; @@ -807,7 +806,7 @@ BOOL gcc_read_client_security_data(STREAM* s, rdpSettings* settings, UINT16 bloc * @param settings rdp settings */ -void gcc_write_client_security_data(STREAM* s, rdpSettings* settings) +void gcc_write_client_security_data(wStream* s, rdpSettings* settings) { gcc_write_user_data_header(s, CS_SECURITY, 12); @@ -824,7 +823,7 @@ void gcc_write_client_security_data(STREAM* s, rdpSettings* settings) } } -BOOL gcc_read_server_security_data(STREAM* s, rdpSettings* settings) +BOOL gcc_read_server_security_data(wStream* s, rdpSettings* settings) { BYTE* data; UINT32 length; @@ -930,7 +929,7 @@ const BYTE tssk_exponent[] = 0x5b, 0x7b, 0x88, 0xc0 }; -void gcc_write_server_security_data(STREAM* s, rdpSettings* settings) +void gcc_write_server_security_data(wStream* s, rdpSettings* settings) { CryptoMd5 md5; BYTE* sigData; @@ -1059,7 +1058,7 @@ void gcc_write_server_security_data(STREAM* s, rdpSettings* settings) * @param settings rdp settings */ -BOOL gcc_read_client_network_data(STREAM* s, rdpSettings* settings, UINT16 blockLength) +BOOL gcc_read_client_network_data(wStream* s, rdpSettings* settings, UINT16 blockLength) { int i; @@ -1091,7 +1090,7 @@ BOOL gcc_read_client_network_data(STREAM* s, rdpSettings* settings, UINT16 block * @param settings rdp settings */ -void gcc_write_client_network_data(STREAM* s, rdpSettings* settings) +void gcc_write_client_network_data(wStream* s, rdpSettings* settings) { int i; UINT16 length; @@ -1113,7 +1112,7 @@ void gcc_write_client_network_data(STREAM* s, rdpSettings* settings) } } -BOOL gcc_read_server_network_data(STREAM* s, rdpSettings* settings) +BOOL gcc_read_server_network_data(wStream* s, rdpSettings* settings) { int i; UINT16 MCSChannelId; @@ -1127,7 +1126,7 @@ BOOL gcc_read_server_network_data(STREAM* s, rdpSettings* settings) if (channelCount != settings->ChannelCount) { - printf("requested %d channels, got %d instead\n", + fprintf(stderr, "requested %d channels, got %d instead\n", settings->ChannelCount, channelCount); } @@ -1146,7 +1145,7 @@ BOOL gcc_read_server_network_data(STREAM* s, rdpSettings* settings) return TRUE; } -void gcc_write_server_network_data(STREAM* s, rdpSettings* settings) +void gcc_write_server_network_data(wStream* s, rdpSettings* settings) { int i; @@ -1171,7 +1170,7 @@ void gcc_write_server_network_data(STREAM* s, rdpSettings* settings) * @param settings rdp settings */ -BOOL gcc_read_client_cluster_data(STREAM* s, rdpSettings* settings, UINT16 blockLength) +BOOL gcc_read_client_cluster_data(wStream* s, rdpSettings* settings, UINT16 blockLength) { UINT32 flags; @@ -1197,7 +1196,7 @@ BOOL gcc_read_client_cluster_data(STREAM* s, rdpSettings* settings, UINT16 block * @param settings rdp settings */ -void gcc_write_client_cluster_data(STREAM* s, rdpSettings* settings) +void gcc_write_client_cluster_data(wStream* s, rdpSettings* settings) { UINT32 flags; @@ -1219,9 +1218,9 @@ void gcc_write_client_cluster_data(STREAM* s, rdpSettings* settings) * @param settings rdp settings */ -BOOL gcc_read_client_monitor_data(STREAM* s, rdpSettings* settings, UINT16 blockLength) +BOOL gcc_read_client_monitor_data(wStream* s, rdpSettings* settings, UINT16 blockLength) { - printf("CS_MONITOR\n"); + fprintf(stderr, "CS_MONITOR\n"); return TRUE; } @@ -1232,7 +1231,7 @@ BOOL gcc_read_client_monitor_data(STREAM* s, rdpSettings* settings, UINT16 block * @param settings rdp settings */ -void gcc_write_client_monitor_data(STREAM* s, rdpSettings* settings) +void gcc_write_client_monitor_data(wStream* s, rdpSettings* settings) { int i; UINT16 length; diff --git a/libfreerdp/core/gcc.h b/libfreerdp/core/gcc.h index 029090155..3432656b8 100644 --- a/libfreerdp/core/gcc.h +++ b/libfreerdp/core/gcc.h @@ -21,37 +21,39 @@ #define FREERDP_CORE_GCC_H #include "mcs.h" + #include <freerdp/crypto/per.h> #include <freerdp/freerdp.h> #include <freerdp/settings.h> -#include <freerdp/utils/stream.h> -BOOL gcc_read_conference_create_request(STREAM* s, rdpSettings* settings); -void gcc_write_conference_create_request(STREAM* s, STREAM* user_data); -BOOL gcc_read_conference_create_response(STREAM* s, rdpSettings* settings); -void gcc_write_conference_create_response(STREAM* s, STREAM* user_data); -BOOL gcc_read_client_data_blocks(STREAM* s, rdpSettings *settings, int length); -void gcc_write_client_data_blocks(STREAM* s, rdpSettings *settings); -BOOL gcc_read_server_data_blocks(STREAM* s, rdpSettings *settings, int length); -void gcc_write_server_data_blocks(STREAM* s, rdpSettings *settings); -BOOL gcc_read_user_data_header(STREAM* s, UINT16* type, UINT16* length); -void gcc_write_user_data_header(STREAM* s, UINT16 type, UINT16 length); -BOOL gcc_read_client_core_data(STREAM* s, rdpSettings *settings, UINT16 blockLength); -void gcc_write_client_core_data(STREAM* s, rdpSettings *settings); -BOOL gcc_read_server_core_data(STREAM* s, rdpSettings *settings); -void gcc_write_server_core_data(STREAM* s, rdpSettings *settings); -BOOL gcc_read_client_security_data(STREAM* s, rdpSettings *settings, UINT16 blockLength); -void gcc_write_client_security_data(STREAM* s, rdpSettings *settings); -BOOL gcc_read_server_security_data(STREAM* s, rdpSettings *settings); -void gcc_write_server_security_data(STREAM* s, rdpSettings *settings); -BOOL gcc_read_client_network_data(STREAM* s, rdpSettings *settings, UINT16 blockLength); -void gcc_write_client_network_data(STREAM* s, rdpSettings *settings); -BOOL gcc_read_server_network_data(STREAM* s, rdpSettings *settings); -void gcc_write_server_network_data(STREAM* s, rdpSettings *settings); -BOOL gcc_read_client_cluster_data(STREAM* s, rdpSettings *settings, UINT16 blockLength); -void gcc_write_client_cluster_data(STREAM* s, rdpSettings *settings); -BOOL gcc_read_client_monitor_data(STREAM* s, rdpSettings *settings, UINT16 blockLength); -void gcc_write_client_monitor_data(STREAM* s, rdpSettings *settings); +#include <winpr/stream.h> + +BOOL gcc_read_conference_create_request(wStream* s, rdpSettings* settings); +void gcc_write_conference_create_request(wStream* s, wStream* user_data); +BOOL gcc_read_conference_create_response(wStream* s, rdpSettings* settings); +void gcc_write_conference_create_response(wStream* s, wStream* user_data); +BOOL gcc_read_client_data_blocks(wStream* s, rdpSettings *settings, int length); +void gcc_write_client_data_blocks(wStream* s, rdpSettings *settings); +BOOL gcc_read_server_data_blocks(wStream* s, rdpSettings *settings, int length); +void gcc_write_server_data_blocks(wStream* s, rdpSettings *settings); +BOOL gcc_read_user_data_header(wStream* s, UINT16* type, UINT16* length); +void gcc_write_user_data_header(wStream* s, UINT16 type, UINT16 length); +BOOL gcc_read_client_core_data(wStream* s, rdpSettings *settings, UINT16 blockLength); +void gcc_write_client_core_data(wStream* s, rdpSettings *settings); +BOOL gcc_read_server_core_data(wStream* s, rdpSettings *settings); +void gcc_write_server_core_data(wStream* s, rdpSettings *settings); +BOOL gcc_read_client_security_data(wStream* s, rdpSettings *settings, UINT16 blockLength); +void gcc_write_client_security_data(wStream* s, rdpSettings *settings); +BOOL gcc_read_server_security_data(wStream* s, rdpSettings *settings); +void gcc_write_server_security_data(wStream* s, rdpSettings *settings); +BOOL gcc_read_client_network_data(wStream* s, rdpSettings *settings, UINT16 blockLength); +void gcc_write_client_network_data(wStream* s, rdpSettings *settings); +BOOL gcc_read_server_network_data(wStream* s, rdpSettings *settings); +void gcc_write_server_network_data(wStream* s, rdpSettings *settings); +BOOL gcc_read_client_cluster_data(wStream* s, rdpSettings *settings, UINT16 blockLength); +void gcc_write_client_cluster_data(wStream* s, rdpSettings *settings); +BOOL gcc_read_client_monitor_data(wStream* s, rdpSettings *settings, UINT16 blockLength); +void gcc_write_client_monitor_data(wStream* s, rdpSettings *settings); #endif /* FREERDP_CORE_GCC_H */ diff --git a/libfreerdp/core/info.c b/libfreerdp/core/info.c index fbcbd1c12..60caf5bf1 100644 --- a/libfreerdp/core/info.c +++ b/libfreerdp/core/info.c @@ -49,12 +49,12 @@ static const char* const INFO_TYPE_LOGON_STRINGS[] = * @param settings settings */ -BOOL rdp_read_server_auto_reconnect_cookie(STREAM* s, rdpSettings* settings) +BOOL rdp_read_server_auto_reconnect_cookie(wStream* s, rdpSettings* settings) { ARC_SC_PRIVATE_PACKET* autoReconnectCookie; autoReconnectCookie = settings->ServerAutoReconnectCookie; - if(stream_get_left(s) < 4+4+4+16) + if (stream_get_left(s) < 4+4+4+16) return FALSE; stream_read_UINT32(s, autoReconnectCookie->cbLen); /* cbLen (4 bytes) */ stream_read_UINT32(s, autoReconnectCookie->version); /* version (4 bytes) */ @@ -70,7 +70,7 @@ BOOL rdp_read_server_auto_reconnect_cookie(STREAM* s, rdpSettings* settings) * @param settings settings */ -BOOL rdp_read_client_auto_reconnect_cookie(STREAM* s, rdpSettings* settings) +BOOL rdp_read_client_auto_reconnect_cookie(wStream* s, rdpSettings* settings) { ARC_CS_PRIVATE_PACKET* autoReconnectCookie; autoReconnectCookie = settings->ClientAutoReconnectCookie; @@ -93,7 +93,7 @@ BOOL rdp_read_client_auto_reconnect_cookie(STREAM* s, rdpSettings* settings) * @param settings settings */ -void rdp_write_client_auto_reconnect_cookie(STREAM* s, rdpSettings* settings) +void rdp_write_client_auto_reconnect_cookie(wStream* s, rdpSettings* settings) { ARC_CS_PRIVATE_PACKET* autoReconnectCookie; autoReconnectCookie = settings->ClientAutoReconnectCookie; @@ -111,14 +111,14 @@ void rdp_write_client_auto_reconnect_cookie(STREAM* s, rdpSettings* settings) * @param settings settings */ -BOOL rdp_read_extended_info_packet(STREAM* s, rdpSettings* settings) +BOOL rdp_read_extended_info_packet(wStream* s, rdpSettings* settings) { UINT16 clientAddressFamily; UINT16 cbClientAddress; UINT16 cbClientDir; UINT16 cbAutoReconnectLen; - if(stream_get_left(s) < 4) + if (stream_get_left(s) < 4) return FALSE; stream_read_UINT16(s, clientAddressFamily); /* clientAddressFamily */ stream_read_UINT16(s, cbClientAddress); /* cbClientAddress */ @@ -131,7 +131,7 @@ BOOL rdp_read_extended_info_packet(STREAM* s, rdpSettings* settings) ConvertFromUnicode(CP_UTF8, 0, (WCHAR*) stream_get_tail(s), cbClientAddress / 2, &settings->ClientAddress, 0, NULL, NULL); stream_seek(s, cbClientAddress); - if(stream_get_left(s) < 2) + if (stream_get_left(s) < 2) return FALSE; stream_read_UINT16(s, cbClientDir); /* cbClientDir */ @@ -147,7 +147,7 @@ BOOL rdp_read_extended_info_packet(STREAM* s, rdpSettings* settings) if (!rdp_read_client_time_zone(s, settings)) return FALSE; - if(stream_get_left(s) < 10) + if (stream_get_left(s) < 10) return FALSE; stream_seek_UINT32(s); /* clientSessionId, should be set to 0 */ stream_read_UINT32(s, settings->PerformanceFlags); /* performanceFlags */ @@ -170,7 +170,7 @@ BOOL rdp_read_extended_info_packet(STREAM* s, rdpSettings* settings) * @param settings settings */ -void rdp_write_extended_info_packet(STREAM* s, rdpSettings* settings) +void rdp_write_extended_info_packet(wStream* s, rdpSettings* settings) { int clientAddressFamily; WCHAR* clientAddress = NULL; @@ -225,7 +225,7 @@ void rdp_write_extended_info_packet(STREAM* s, rdpSettings* settings) * @param settings settings */ -BOOL rdp_read_info_packet(STREAM* s, rdpSettings* settings) +BOOL rdp_read_info_packet(wStream* s, rdpSettings* settings) { UINT32 flags; UINT16 cbDomain; @@ -234,7 +234,7 @@ BOOL rdp_read_info_packet(STREAM* s, rdpSettings* settings) UINT16 cbAlternateShell; UINT16 cbWorkingDir; - if(stream_get_left(s) < 18) // invalid packet + if (stream_get_left(s) < 18) // invalid packet return FALSE; stream_seek_UINT32(s); /* CodePage */ @@ -314,7 +314,7 @@ BOOL rdp_read_info_packet(STREAM* s, rdpSettings* settings) * @param settings settings */ -void rdp_write_info_packet(STREAM* s, rdpSettings* settings) +void rdp_write_info_packet(wStream* s, rdpSettings* settings) { UINT32 flags; WCHAR* domain = NULL; @@ -430,7 +430,7 @@ void rdp_write_info_packet(STREAM* s, rdpSettings* settings) * @param s stream */ -BOOL rdp_recv_client_info(rdpRdp* rdp, STREAM* s) +BOOL rdp_recv_client_info(rdpRdp* rdp, wStream* s) { UINT16 length; UINT16 channelId; @@ -449,14 +449,15 @@ BOOL rdp_recv_client_info(rdpRdp* rdp, STREAM* s) { if (securityFlags & SEC_REDIRECTION_PKT) { - printf("Error: SEC_REDIRECTION_PKT unsupported\n"); + fprintf(stderr, "Error: SEC_REDIRECTION_PKT unsupported\n"); return FALSE; } + if (securityFlags & SEC_ENCRYPT) { if (!rdp_decrypt(rdp, s, length - 4, securityFlags)) { - printf("rdp_decrypt failed\n"); + fprintf(stderr, "rdp_decrypt failed\n"); return FALSE; } } @@ -473,7 +474,7 @@ BOOL rdp_recv_client_info(rdpRdp* rdp, STREAM* s) BOOL rdp_send_client_info(rdpRdp* rdp) { - STREAM* s; + wStream* s; //rdp->settings->crypt_flags |= SEC_INFO_PKT; rdp->sec_flags |= SEC_INFO_PKT; @@ -482,28 +483,31 @@ BOOL rdp_send_client_info(rdpRdp* rdp) return rdp_send(rdp, s, MCS_GLOBAL_CHANNEL_ID); } -BOOL rdp_recv_logon_info_v1(rdpRdp* rdp, STREAM* s) +BOOL rdp_recv_logon_info_v1(rdpRdp* rdp, wStream* s) { UINT32 cbDomain; UINT32 cbUserName; - if(stream_get_left(s) < 4+52+4+512+4) + if (stream_get_left(s) < (4 + 52 + 4 + 512 + 4)) return FALSE; + stream_read_UINT32(s, cbDomain); /* cbDomain (4 bytes) */ stream_seek(s, 52); /* domain (52 bytes) */ stream_read_UINT32(s, cbUserName); /* cbUserName (4 bytes) */ stream_seek(s, 512); /* userName (512 bytes) */ stream_seek_UINT32(s); /* sessionId (4 bytes) */ + return TRUE; } -BOOL rdp_recv_logon_info_v2(rdpRdp* rdp, STREAM* s) +BOOL rdp_recv_logon_info_v2(rdpRdp* rdp, wStream* s) { UINT32 cbDomain; UINT32 cbUserName; - if(stream_get_left(s) < 2+4+4+4+4+558) + if (stream_get_left(s) < (2 + 4 + 4 + 4 + 4 + 558)) return FALSE; + stream_seek_UINT16(s); /* version (2 bytes) */ stream_seek_UINT32(s); /* size (4 bytes) */ stream_seek_UINT32(s); /* sessionId (4 bytes) */ @@ -511,40 +515,48 @@ BOOL rdp_recv_logon_info_v2(rdpRdp* rdp, STREAM* s) stream_read_UINT32(s, cbUserName); /* cbUserName (4 bytes) */ stream_seek(s, 558); /* pad */ - if(stream_get_left(s) < cbDomain+cbUserName) + if (stream_get_left(s) < cbDomain+cbUserName) return FALSE; + stream_seek(s, cbDomain); /* domain */ stream_seek(s, cbUserName); /* userName */ + return TRUE; } -BOOL rdp_recv_logon_plain_notify(rdpRdp* rdp, STREAM* s) +BOOL rdp_recv_logon_plain_notify(rdpRdp* rdp, wStream* s) { - if(stream_get_left(s) < 576) + if (stream_get_left(s) < 576) return FALSE; + stream_seek(s, 576); /* pad */ + return TRUE; } -BOOL rdp_recv_logon_error_info(rdpRdp* rdp, STREAM* s) +BOOL rdp_recv_logon_error_info(rdpRdp* rdp, wStream* s) { - UINT32 errorNotificationType; UINT32 errorNotificationData; + UINT32 errorNotificationType; - if(stream_get_left(s) < 4) + if (stream_get_left(s) < 4) return FALSE; - stream_read_UINT32(s, errorNotificationType); /* errorNotificationType (4 bytes) */ + stream_read_UINT32(s, errorNotificationData); /* errorNotificationData (4 bytes) */ + stream_read_UINT32(s, errorNotificationType); /* errorNotificationType (4 bytes) */ + + IFCALL(rdp->instance->LogonErrorInfo, rdp->instance, errorNotificationData, errorNotificationType); + return TRUE; } -BOOL rdp_recv_logon_info_extended(rdpRdp* rdp, STREAM* s) +BOOL rdp_recv_logon_info_extended(rdpRdp* rdp, wStream* s) { UINT32 cbFieldData; UINT32 fieldsPresent; UINT16 Length; - if(stream_get_left(s) < 6) + if (stream_get_left(s) < 6) return FALSE; stream_read_UINT16(s, Length); /* The total size in bytes of this structure */ @@ -554,37 +566,43 @@ BOOL rdp_recv_logon_info_extended(rdpRdp* rdp, STREAM* s) if (fieldsPresent & LOGON_EX_AUTORECONNECTCOOKIE) { - if(stream_get_left(s) < 4) + if (stream_get_left(s) < 4) return FALSE; + stream_read_UINT32(s, cbFieldData); /* cbFieldData (4 bytes) */ - if(rdp_read_server_auto_reconnect_cookie(s, rdp->settings) == FALSE) + + if (rdp_read_server_auto_reconnect_cookie(s, rdp->settings) == FALSE) return FALSE; } if (fieldsPresent & LOGON_EX_LOGONERRORS) { - if(stream_get_left(s) < 4) + if (stream_get_left(s) < 4) return FALSE; + stream_read_UINT32(s, cbFieldData); /* cbFieldData (4 bytes) */ - if(rdp_recv_logon_error_info(rdp, s) == FALSE) + + if (rdp_recv_logon_error_info(rdp, s) == FALSE) return FALSE; } - if(stream_get_left(s) < 570) + if (stream_get_left(s) < 570) return FALSE; + stream_seek(s, 570); /* pad */ + return TRUE; } -BOOL rdp_recv_save_session_info(rdpRdp* rdp, STREAM* s) +BOOL rdp_recv_save_session_info(rdpRdp* rdp, wStream* s) { UINT32 infoType; - if(stream_get_left(s) < 4) + if (stream_get_left(s) < 4) return FALSE; stream_read_UINT32(s, infoType); /* infoType (4 bytes) */ - //printf("%s\n", INFO_TYPE_LOGON_STRINGS[infoType]); + //fprintf(stderr, "%s\n", INFO_TYPE_LOGON_STRINGS[infoType]); switch (infoType) { diff --git a/libfreerdp/core/info.h b/libfreerdp/core/info.h index e6598b47b..21ceac3c0 100644 --- a/libfreerdp/core/info.h +++ b/libfreerdp/core/info.h @@ -23,7 +23,8 @@ #include "rdp.h" #include <freerdp/freerdp.h> -#include <freerdp/utils/stream.h> + +#include <winpr/stream.h> /* Client Address Family */ #define ADDRESS_FAMILY_INET 0x0002 @@ -70,21 +71,21 @@ #define LOGON_FAILED_OTHER 0x00000002 #define LOGON_WARNING 0x00000003 -void rdp_read_system_time(STREAM* s, SYSTEM_TIME* system_time); -void rdp_write_system_time(STREAM* s, SYSTEM_TIME* system_time); -void rdp_get_client_time_zone(STREAM* s, rdpSettings* settings); -BOOL rdp_read_client_time_zone(STREAM* s, rdpSettings* settings); -void rdp_write_client_time_zone(STREAM* s, rdpSettings* settings); -BOOL rdp_read_server_auto_reconnect_cookie(STREAM* s, rdpSettings* settings); -BOOL rdp_read_client_auto_reconnect_cookie(STREAM* s, rdpSettings* settings); -void rdp_write_client_auto_reconnect_cookie(STREAM* s, rdpSettings* settings); -void rdp_write_auto_reconnect_cookie(STREAM* s, rdpSettings* settings); -BOOL rdp_read_extended_info_packet(STREAM* s, rdpSettings* settings); -void rdp_write_extended_info_packet(STREAM* s, rdpSettings* settings); -BOOL rdp_read_info_packet(STREAM* s, rdpSettings* settings); -void rdp_write_info_packet(STREAM* s, rdpSettings* settings); -BOOL rdp_recv_client_info(rdpRdp* rdp, STREAM* s); +void rdp_read_system_time(wStream* s, SYSTEM_TIME* system_time); +void rdp_write_system_time(wStream* s, SYSTEM_TIME* system_time); +void rdp_get_client_time_zone(wStream* s, rdpSettings* settings); +BOOL rdp_read_client_time_zone(wStream* s, rdpSettings* settings); +void rdp_write_client_time_zone(wStream* s, rdpSettings* settings); +BOOL rdp_read_server_auto_reconnect_cookie(wStream* s, rdpSettings* settings); +BOOL rdp_read_client_auto_reconnect_cookie(wStream* s, rdpSettings* settings); +void rdp_write_client_auto_reconnect_cookie(wStream* s, rdpSettings* settings); +void rdp_write_auto_reconnect_cookie(wStream* s, rdpSettings* settings); +BOOL rdp_read_extended_info_packet(wStream* s, rdpSettings* settings); +void rdp_write_extended_info_packet(wStream* s, rdpSettings* settings); +BOOL rdp_read_info_packet(wStream* s, rdpSettings* settings); +void rdp_write_info_packet(wStream* s, rdpSettings* settings); +BOOL rdp_recv_client_info(rdpRdp* rdp, wStream* s); BOOL rdp_send_client_info(rdpRdp* rdp); -BOOL rdp_recv_save_session_info(rdpRdp* rdp, STREAM* s); +BOOL rdp_recv_save_session_info(rdpRdp* rdp, wStream* s); #endif /* __INFO_H */ diff --git a/libfreerdp/core/input.c b/libfreerdp/core/input.c index 92b55bd98..06e31f84d 100644 --- a/libfreerdp/core/input.c +++ b/libfreerdp/core/input.c @@ -29,33 +29,33 @@ #include "input.h" -void rdp_write_client_input_pdu_header(STREAM* s, UINT16 number) +void rdp_write_client_input_pdu_header(wStream* s, UINT16 number) { stream_write_UINT16(s, 1); /* numberEvents (2 bytes) */ stream_write_UINT16(s, 0); /* pad2Octets (2 bytes) */ } -void rdp_write_input_event_header(STREAM* s, UINT32 time, UINT16 type) +void rdp_write_input_event_header(wStream* s, UINT32 time, UINT16 type) { stream_write_UINT32(s, time); /* eventTime (4 bytes) */ stream_write_UINT16(s, type); /* messageType (2 bytes) */ } -STREAM* rdp_client_input_pdu_init(rdpRdp* rdp, UINT16 type) +wStream* rdp_client_input_pdu_init(rdpRdp* rdp, UINT16 type) { - STREAM* s; + wStream* s; s = rdp_data_pdu_init(rdp); rdp_write_client_input_pdu_header(s, 1); rdp_write_input_event_header(s, 0, type); return s; } -void rdp_send_client_input_pdu(rdpRdp* rdp, STREAM* s) +void rdp_send_client_input_pdu(rdpRdp* rdp, wStream* s) { rdp_send_data_pdu(rdp, s, DATA_PDU_TYPE_INPUT, rdp->mcs->user_id); } -void input_write_synchronize_event(STREAM* s, UINT32 flags) +void input_write_synchronize_event(wStream* s, UINT32 flags) { stream_write_UINT16(s, 0); /* pad2Octets (2 bytes) */ stream_write_UINT32(s, flags); /* toggleFlags (4 bytes) */ @@ -63,7 +63,7 @@ void input_write_synchronize_event(STREAM* s, UINT32 flags) void input_send_synchronize_event(rdpInput* input, UINT32 flags) { - STREAM* s; + wStream* s; rdpRdp* rdp = input->context->rdp; s = rdp_client_input_pdu_init(rdp, INPUT_EVENT_SYNC); @@ -71,7 +71,7 @@ void input_send_synchronize_event(rdpInput* input, UINT32 flags) rdp_send_client_input_pdu(rdp, s); } -void input_write_keyboard_event(STREAM* s, UINT16 flags, UINT16 code) +void input_write_keyboard_event(wStream* s, UINT16 flags, UINT16 code) { stream_write_UINT16(s, flags); /* keyboardFlags (2 bytes) */ stream_write_UINT16(s, code); /* keyCode (2 bytes) */ @@ -80,7 +80,7 @@ void input_write_keyboard_event(STREAM* s, UINT16 flags, UINT16 code) void input_send_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code) { - STREAM* s; + wStream* s; rdpRdp* rdp = input->context->rdp; s = rdp_client_input_pdu_init(rdp, INPUT_EVENT_SCANCODE); @@ -88,7 +88,7 @@ void input_send_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code) rdp_send_client_input_pdu(rdp, s); } -void input_write_unicode_keyboard_event(STREAM* s, UINT16 flags, UINT16 code) +void input_write_unicode_keyboard_event(wStream* s, UINT16 flags, UINT16 code) { stream_write_UINT16(s, flags); /* keyboardFlags (2 bytes) */ stream_write_UINT16(s, code); /* unicodeCode (2 bytes) */ @@ -97,7 +97,7 @@ void input_write_unicode_keyboard_event(STREAM* s, UINT16 flags, UINT16 code) void input_send_unicode_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code) { - STREAM* s; + wStream* s; UINT16 keyboardFlags = 0; rdpRdp* rdp = input->context->rdp; @@ -117,7 +117,7 @@ void input_send_unicode_keyboard_event(rdpInput* input, UINT16 flags, UINT16 cod rdp_send_client_input_pdu(rdp, s); } -void input_write_mouse_event(STREAM* s, UINT16 flags, UINT16 x, UINT16 y) +void input_write_mouse_event(wStream* s, UINT16 flags, UINT16 x, UINT16 y) { stream_write_UINT16(s, flags); /* pointerFlags (2 bytes) */ stream_write_UINT16(s, x); /* xPos (2 bytes) */ @@ -126,7 +126,7 @@ void input_write_mouse_event(STREAM* s, UINT16 flags, UINT16 x, UINT16 y) void input_send_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y) { - STREAM* s; + wStream* s; rdpRdp* rdp = input->context->rdp; s = rdp_client_input_pdu_init(rdp, INPUT_EVENT_MOUSE); @@ -134,7 +134,7 @@ void input_send_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y) rdp_send_client_input_pdu(rdp, s); } -void input_write_extended_mouse_event(STREAM* s, UINT16 flags, UINT16 x, UINT16 y) +void input_write_extended_mouse_event(wStream* s, UINT16 flags, UINT16 x, UINT16 y) { stream_write_UINT16(s, flags); /* pointerFlags (2 bytes) */ stream_write_UINT16(s, x); /* xPos (2 bytes) */ @@ -143,7 +143,7 @@ void input_write_extended_mouse_event(STREAM* s, UINT16 flags, UINT16 x, UINT16 void input_send_extended_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y) { - STREAM* s; + wStream* s; rdpRdp* rdp = input->context->rdp; s = rdp_client_input_pdu_init(rdp, INPUT_EVENT_MOUSEX); @@ -153,7 +153,7 @@ void input_send_extended_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UI void input_send_fastpath_synchronize_event(rdpInput* input, UINT32 flags) { - STREAM* s; + wStream* s; rdpRdp* rdp = input->context->rdp; /* The FastPath Synchronization eventFlags has identical values as SlowPath */ @@ -163,7 +163,7 @@ void input_send_fastpath_synchronize_event(rdpInput* input, UINT32 flags) void input_send_fastpath_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code) { - STREAM* s; + wStream* s; BYTE eventFlags = 0; rdpRdp* rdp = input->context->rdp; @@ -176,7 +176,7 @@ void input_send_fastpath_keyboard_event(rdpInput* input, UINT16 flags, UINT16 co void input_send_fastpath_unicode_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code) { - STREAM* s; + wStream* s; BYTE eventFlags = 0; rdpRdp* rdp = input->context->rdp; @@ -188,7 +188,7 @@ void input_send_fastpath_unicode_keyboard_event(rdpInput* input, UINT16 flags, U void input_send_fastpath_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y) { - STREAM* s; + wStream* s; rdpRdp* rdp = input->context->rdp; s = fastpath_input_pdu_init(rdp->fastpath, 0, FASTPATH_INPUT_EVENT_MOUSE); @@ -198,7 +198,7 @@ void input_send_fastpath_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UI void input_send_fastpath_extended_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y) { - STREAM* s; + wStream* s; rdpRdp* rdp = input->context->rdp; s = fastpath_input_pdu_init(rdp->fastpath, 0, FASTPATH_INPUT_EVENT_MOUSEX); @@ -206,7 +206,7 @@ void input_send_fastpath_extended_mouse_event(rdpInput* input, UINT16 flags, UIN fastpath_send_input_pdu(rdp->fastpath, s); } -static BOOL input_recv_sync_event(rdpInput* input, STREAM* s) +static BOOL input_recv_sync_event(rdpInput* input, wStream* s) { UINT32 toggleFlags; @@ -221,7 +221,7 @@ static BOOL input_recv_sync_event(rdpInput* input, STREAM* s) return TRUE; } -static BOOL input_recv_keyboard_event(rdpInput* input, STREAM* s) +static BOOL input_recv_keyboard_event(rdpInput* input, wStream* s) { UINT16 keyboardFlags, keyCode; @@ -237,7 +237,7 @@ static BOOL input_recv_keyboard_event(rdpInput* input, STREAM* s) return TRUE; } -static BOOL input_recv_unicode_keyboard_event(rdpInput* input, STREAM* s) +static BOOL input_recv_unicode_keyboard_event(rdpInput* input, wStream* s) { UINT16 keyboardFlags, unicodeCode; @@ -266,7 +266,7 @@ static BOOL input_recv_unicode_keyboard_event(rdpInput* input, STREAM* s) return TRUE; } -static BOOL input_recv_mouse_event(rdpInput* input, STREAM* s) +static BOOL input_recv_mouse_event(rdpInput* input, wStream* s) { UINT16 pointerFlags, xPos, yPos; @@ -282,7 +282,7 @@ static BOOL input_recv_mouse_event(rdpInput* input, STREAM* s) return TRUE; } -static BOOL input_recv_extended_mouse_event(rdpInput* input, STREAM* s) +static BOOL input_recv_extended_mouse_event(rdpInput* input, wStream* s) { UINT16 pointerFlags, xPos, yPos; @@ -298,7 +298,7 @@ static BOOL input_recv_extended_mouse_event(rdpInput* input, STREAM* s) return TRUE; } -static BOOL input_recv_event(rdpInput* input, STREAM* s) +static BOOL input_recv_event(rdpInput* input, wStream* s) { UINT16 messageType; @@ -336,7 +336,7 @@ static BOOL input_recv_event(rdpInput* input, STREAM* s) break; default: - printf("Unknown messageType %u\n", messageType); + fprintf(stderr, "Unknown messageType %u\n", messageType); /* Each input event uses 6 bytes. */ stream_seek(s, 6); break; @@ -345,7 +345,7 @@ static BOOL input_recv_event(rdpInput* input, STREAM* s) return TRUE; } -BOOL input_recv(rdpInput* input, STREAM* s) +BOOL input_recv(rdpInput* input, wStream* s) { UINT16 i, numberEvents; diff --git a/libfreerdp/core/input.h b/libfreerdp/core/input.h index 11e9ad416..22f8501c9 100644 --- a/libfreerdp/core/input.h +++ b/libfreerdp/core/input.h @@ -26,7 +26,8 @@ #include <freerdp/input.h> #include <freerdp/freerdp.h> -#include <freerdp/utils/stream.h> + +#include <winpr/stream.h> /* Input Events */ #define INPUT_EVENT_SYNC 0x0000 @@ -49,7 +50,7 @@ void input_send_fastpath_unicode_keyboard_event(rdpInput* input, UINT16 flags, U void input_send_fastpath_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y); void input_send_fastpath_extended_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y); -BOOL input_recv(rdpInput* input, STREAM* s); +BOOL input_recv(rdpInput* input, wStream* s); int input_process_events(rdpInput* input); void input_register_client_callbacks(rdpInput* input); diff --git a/libfreerdp/core/license.c b/libfreerdp/core/license.c index 73581f5c4..be43a21ca 100644 --- a/libfreerdp/core/license.c +++ b/libfreerdp/core/license.c @@ -88,10 +88,10 @@ void license_print_product_info(PRODUCT_INFO* productInfo) ConvertFromUnicode(CP_UTF8, 0, (WCHAR*) productInfo->pbProductId, productInfo->cbProductId / 2, &ProductId, 0, NULL, NULL); - printf("ProductInfo:\n"); - printf("\tdwVersion: 0x%08X\n", productInfo->dwVersion); - printf("\tCompanyName: %s\n", CompanyName); - printf("\tProductId: %s\n", ProductId); + fprintf(stderr, "ProductInfo:\n"); + fprintf(stderr, "\tdwVersion: 0x%08X\n", productInfo->dwVersion); + fprintf(stderr, "\tCompanyName: %s\n", CompanyName); + fprintf(stderr, "\tProductId: %s\n", ProductId); free(CompanyName); free(ProductId); @@ -102,12 +102,12 @@ void license_print_scope_list(SCOPE_LIST* scopeList) int index; LICENSE_BLOB* scope; - printf("ScopeList (%d):\n", scopeList->count); + fprintf(stderr, "ScopeList (%d):\n", scopeList->count); for (index = 0; index < scopeList->count; index++) { scope = &scopeList->array[index]; - printf("\t%s\n", (char*) scope->data); + fprintf(stderr, "\t%s\n", (char*) scope->buffer); } } @@ -123,7 +123,7 @@ void license_print_scope_list(SCOPE_LIST* scopeList) * @return if the operation completed successfully */ -BOOL license_read_preamble(STREAM* s, BYTE* bMsgType, BYTE* flags, UINT16* wMsgSize) +BOOL license_read_preamble(wStream* s, BYTE* bMsgType, BYTE* flags, UINT16* wMsgSize) { /* preamble (4 bytes) */ if (stream_get_left(s) < 4) @@ -145,7 +145,7 @@ BOOL license_read_preamble(STREAM* s, BYTE* bMsgType, BYTE* flags, UINT16* wMsgS * @param wMsgSize message size */ -void license_write_preamble(STREAM* s, BYTE bMsgType, BYTE flags, UINT16 wMsgSize) +void license_write_preamble(wStream* s, BYTE bMsgType, BYTE flags, UINT16 wMsgSize) { /* preamble (4 bytes) */ stream_write_BYTE(s, bMsgType); /* bMsgType (1 byte) */ @@ -159,9 +159,9 @@ void license_write_preamble(STREAM* s, BYTE bMsgType, BYTE flags, UINT16 wMsgSiz * @return stream */ -STREAM* license_send_stream_init(rdpLicense* license) +wStream* license_send_stream_init(rdpLicense* license) { - STREAM* s; + wStream* s; s = transport_send_stream_init(license->rdp->transport, 4096); stream_seek(s, LICENSE_PACKET_HEADER_MAX_LENGTH); @@ -176,7 +176,7 @@ STREAM* license_send_stream_init(rdpLicense* license) * @param s stream */ -BOOL license_send(rdpLicense* license, STREAM* s, BYTE type) +BOOL license_send(rdpLicense* license, wStream* s, BYTE type) { int length; BYTE flags; @@ -202,8 +202,8 @@ BOOL license_send(rdpLicense* license, STREAM* s, BYTE type) license_write_preamble(s, type, flags, wMsgSize); #ifdef WITH_DEBUG_LICENSE - printf("Sending %s Packet, length %d\n", LICENSE_MESSAGE_STRINGS[type & 0x1F], wMsgSize); - winpr_HexDump(s->p - 4, wMsgSize); + fprintf(stderr, "Sending %s Packet, length %d\n", LICENSE_MESSAGE_STRINGS[type & 0x1F], wMsgSize); + winpr_HexDump(s->pointer - 4, wMsgSize); #endif stream_set_pos(s, length); @@ -222,7 +222,7 @@ BOOL license_send(rdpLicense* license, STREAM* s, BYTE type) * @return if the operation completed successfully */ -BOOL license_recv(rdpLicense* license, STREAM* s) +BOOL license_recv(rdpLicense* license, wStream* s) { BYTE flags; BYTE bMsgType; @@ -233,7 +233,7 @@ BOOL license_recv(rdpLicense* license, STREAM* s) if (!rdp_read_header(license->rdp, s, &length, &channelId)) { - printf("Incorrect RDP header.\n"); + fprintf(stderr, "Incorrect RDP header.\n"); return FALSE; } @@ -244,7 +244,7 @@ BOOL license_recv(rdpLicense* license, STREAM* s) { if (!rdp_decrypt(license->rdp, s, length - 4, securityFlags)) { - printf("rdp_decrypt failed\n"); + fprintf(stderr, "rdp_decrypt failed\n"); return FALSE; } } @@ -256,7 +256,7 @@ BOOL license_recv(rdpLicense* license, STREAM* s) if (rdp_recv_out_of_sequence_pdu(license->rdp, s) != TRUE) { - printf("Unexpected license packet.\n"); + fprintf(stderr, "Unexpected license packet.\n"); return FALSE; } @@ -296,7 +296,7 @@ BOOL license_recv(rdpLicense* license, STREAM* s) break; default: - printf("invalid bMsgType:%d\n", bMsgType); + fprintf(stderr, "invalid bMsgType:%d\n", bMsgType); return FALSE; } @@ -337,33 +337,33 @@ void license_generate_keys(rdpLicense* license) license->ServerRandom, license->LicensingEncryptionKey); /* LicensingEncryptionKey */ #ifdef WITH_DEBUG_LICENSE - printf("ClientRandom:\n"); + fprintf(stderr, "ClientRandom:\n"); winpr_HexDump(license->ClientRandom, CLIENT_RANDOM_LENGTH); - printf("\n"); + fprintf(stderr, "\n"); - printf("ServerRandom:\n"); + fprintf(stderr, "ServerRandom:\n"); winpr_HexDump(license->ServerRandom, SERVER_RANDOM_LENGTH); - printf("\n"); + fprintf(stderr, "\n"); - printf("PremasterSecret:\n"); + fprintf(stderr, "PremasterSecret:\n"); winpr_HexDump(license->PremasterSecret, PREMASTER_SECRET_LENGTH); - printf("\n"); + fprintf(stderr, "\n"); - printf("MasterSecret:\n"); + fprintf(stderr, "MasterSecret:\n"); winpr_HexDump(license->MasterSecret, MASTER_SECRET_LENGTH); - printf("\n"); + fprintf(stderr, "\n"); - printf("SessionKeyBlob:\n"); + fprintf(stderr, "SessionKeyBlob:\n"); winpr_HexDump(license->SessionKeyBlob, SESSION_KEY_BLOB_LENGTH); - printf("\n"); + fprintf(stderr, "\n"); - printf("MacSaltKey:\n"); + fprintf(stderr, "MacSaltKey:\n"); winpr_HexDump(license->MacSaltKey, MAC_SALT_KEY_LENGTH); - printf("\n"); + fprintf(stderr, "\n"); - printf("LicensingEncryptionKey:\n"); + fprintf(stderr, "LicensingEncryptionKey:\n"); winpr_HexDump(license->LicensingEncryptionKey, LICENSING_ENCRYPTION_KEY_LENGTH); - printf("\n"); + fprintf(stderr, "\n"); #endif } @@ -416,13 +416,13 @@ void license_encrypt_premaster_secret(rdpLicense* license) license_get_server_rsa_public_key(license); #ifdef WITH_DEBUG_LICENSE - printf("Modulus (%d bits):\n", license->ModulusLength * 8); + fprintf(stderr, "Modulus (%d bits):\n", license->ModulusLength * 8); winpr_HexDump(license->Modulus, license->ModulusLength); - printf("\n"); + fprintf(stderr, "\n"); - printf("Exponent:\n"); + fprintf(stderr, "Exponent:\n"); winpr_HexDump(license->Exponent, 4); - printf("\n"); + fprintf(stderr, "\n"); #endif EncryptedPremasterSecret = (BYTE*) malloc(license->ModulusLength); @@ -461,7 +461,7 @@ void license_decrypt_platform_challenge(rdpLicense* license) * @param productInfo product information */ -BOOL license_read_product_info(STREAM* s, PRODUCT_INFO* productInfo) +BOOL license_read_product_info(wStream* s, PRODUCT_INFO* productInfo) { if (stream_get_left(s) < 8) return FALSE; @@ -536,7 +536,7 @@ void license_free_product_info(PRODUCT_INFO* productInfo) * @param blob license binary blob */ -BOOL license_read_binary_blob(STREAM* s, LICENSE_BLOB* blob) +BOOL license_read_binary_blob(wStream* s, LICENSE_BLOB* blob) { UINT16 wBlobType; @@ -558,7 +558,7 @@ BOOL license_read_binary_blob(STREAM* s, LICENSE_BLOB* blob) if ((blob->type != wBlobType) && (blob->type != BB_ANY_BLOB)) { - printf("license binary blob type (%x) does not match expected type (%x).\n", wBlobType, blob->type); + fprintf(stderr, "license binary blob type (%x) does not match expected type (%x).\n", wBlobType, blob->type); } blob->type = wBlobType; @@ -575,7 +575,7 @@ BOOL license_read_binary_blob(STREAM* s, LICENSE_BLOB* blob) * @param blob license binary blob */ -void license_write_binary_blob(STREAM* s, LICENSE_BLOB* blob) +void license_write_binary_blob(wStream* s, LICENSE_BLOB* blob) { stream_write_UINT16(s, blob->type); /* wBlobType (2 bytes) */ stream_write_UINT16(s, blob->length); /* wBlobLen (2 bytes) */ @@ -584,7 +584,7 @@ void license_write_binary_blob(STREAM* s, LICENSE_BLOB* blob) stream_write(s, blob->data, blob->length); /* blobData */ } -void license_write_encrypted_premaster_secret_blob(STREAM* s, LICENSE_BLOB* blob, UINT32 ModulusLength) +void license_write_encrypted_premaster_secret_blob(wStream* s, LICENSE_BLOB* blob, UINT32 ModulusLength) { UINT32 length; @@ -592,7 +592,7 @@ void license_write_encrypted_premaster_secret_blob(STREAM* s, LICENSE_BLOB* blob if (blob->length > ModulusLength) { - printf("license_write_encrypted_premaster_secret_blob: invalid blob\n"); + fprintf(stderr, "license_write_encrypted_premaster_secret_blob: invalid blob\n"); return; } @@ -644,7 +644,7 @@ void license_free_binary_blob(LICENSE_BLOB* blob) * @param scopeList scope list */ -BOOL license_read_scope_list(STREAM* s, SCOPE_LIST* scopeList) +BOOL license_read_scope_list(wStream* s, SCOPE_LIST* scopeList) { UINT32 i; UINT32 scopeCount; @@ -719,7 +719,7 @@ void license_free_scope_list(SCOPE_LIST* scopeList) * @param s stream */ -BOOL license_read_license_request_packet(rdpLicense* license, STREAM* s) +BOOL license_read_license_request_packet(rdpLicense* license, wStream* s) { /* ServerRandom (32 bytes) */ if (stream_get_left(s) < 32) @@ -753,15 +753,15 @@ BOOL license_read_license_request_packet(rdpLicense* license, STREAM* s) license_encrypt_premaster_secret(license); #ifdef WITH_DEBUG_LICENSE - printf("ServerRandom:\n"); + fprintf(stderr, "ServerRandom:\n"); winpr_HexDump(license->ServerRandom, 32); - printf("\n"); + fprintf(stderr, "\n"); license_print_product_info(license->ProductInfo); - printf("\n"); + fprintf(stderr, "\n"); license_print_scope_list(license->ScopeList); - printf("\n"); + fprintf(stderr, "\n"); #endif return TRUE; @@ -774,7 +774,7 @@ BOOL license_read_license_request_packet(rdpLicense* license, STREAM* s) * @param s stream */ -BOOL license_read_platform_challenge_packet(rdpLicense* license, STREAM* s) +BOOL license_read_platform_challenge_packet(rdpLicense* license, wStream* s) { BYTE MacData[16]; UINT32 ConnectFlags = 0; @@ -799,20 +799,20 @@ BOOL license_read_platform_challenge_packet(rdpLicense* license, STREAM* s) license_decrypt_platform_challenge(license); #ifdef WITH_DEBUG_LICENSE - printf("ConnectFlags: 0x%08X\n", ConnectFlags); - printf("\n"); + fprintf(stderr, "ConnectFlags: 0x%08X\n", ConnectFlags); + fprintf(stderr, "\n"); - printf("EncryptedPlatformChallenge:\n"); - winpr_HexDump(license->EncryptedPlatformChallenge->data, license->EncryptedPlatformChallenge->length); - printf("\n"); + fprintf(stderr, "EncryptedPlatformChallenge:\n"); + winpr_HexDump(license->EncryptedPlatformChallenge->buffer, license->EncryptedPlatformChallenge->length); + fprintf(stderr, "\n"); - printf("PlatformChallenge:\n"); - winpr_HexDump(license->PlatformChallenge->data, license->PlatformChallenge->length); - printf("\n"); + fprintf(stderr, "PlatformChallenge:\n"); + winpr_HexDump(license->PlatformChallenge->buffer, license->PlatformChallenge->length); + fprintf(stderr, "\n"); - printf("MacData:\n"); + fprintf(stderr, "MacData:\n"); winpr_HexDump(MacData, 16); - printf("\n"); + fprintf(stderr, "\n"); #endif return TRUE; @@ -825,7 +825,7 @@ BOOL license_read_platform_challenge_packet(rdpLicense* license, STREAM* s) * @param s stream */ -void license_read_new_license_packet(rdpLicense* license, STREAM* s) +void license_read_new_license_packet(rdpLicense* license, wStream* s) { DEBUG_LICENSE("Receiving New License Packet"); license->state = LICENSE_STATE_COMPLETED; @@ -838,7 +838,7 @@ void license_read_new_license_packet(rdpLicense* license, STREAM* s) * @param s stream */ -void license_read_upgrade_license_packet(rdpLicense* license, STREAM* s) +void license_read_upgrade_license_packet(rdpLicense* license, wStream* s) { DEBUG_LICENSE("Receiving Upgrade License Packet"); license->state = LICENSE_STATE_COMPLETED; @@ -851,7 +851,7 @@ void license_read_upgrade_license_packet(rdpLicense* license, STREAM* s) * @param s stream */ -BOOL license_read_error_alert_packet(rdpLicense* license, STREAM* s) +BOOL license_read_error_alert_packet(rdpLicense* license, wStream* s) { UINT32 dwErrorCode; UINT32 dwStateTransition; @@ -866,7 +866,7 @@ BOOL license_read_error_alert_packet(rdpLicense* license, STREAM* s) return FALSE; #ifdef WITH_DEBUG_LICENSE - printf("dwErrorCode: %s, dwStateTransition: %s\n", + fprintf(stderr, "dwErrorCode: %s, dwStateTransition: %s\n", error_codes[dwErrorCode], state_transitions[dwStateTransition]); #endif @@ -907,7 +907,7 @@ BOOL license_read_error_alert_packet(rdpLicense* license, STREAM* s) * @param s stream */ -void license_write_new_license_request_packet(rdpLicense* license, STREAM* s) +void license_write_new_license_request_packet(rdpLicense* license, wStream* s) { UINT32 PlatformId; UINT32 PreferredKeyExchangeAlg = KEY_EXCHANGE_ALG_RSA; @@ -922,22 +922,22 @@ void license_write_new_license_request_packet(rdpLicense* license, STREAM* s) license_write_binary_blob(s, license->ClientMachineName); /* ClientMachineName */ #ifdef WITH_DEBUG_LICENSE - printf("PreferredKeyExchangeAlg: 0x%08X\n", PreferredKeyExchangeAlg); - printf("\n"); + fprintf(stderr, "PreferredKeyExchangeAlg: 0x%08X\n", PreferredKeyExchangeAlg); + fprintf(stderr, "\n"); - printf("ClientRandom:\n"); + fprintf(stderr, "ClientRandom:\n"); winpr_HexDump(license->ClientRandom, 32); - printf("\n"); + fprintf(stderr, "\n"); - printf("EncryptedPremasterSecret\n"); - winpr_HexDump(license->EncryptedPremasterSecret->data, license->EncryptedPremasterSecret->length); - printf("\n"); + fprintf(stderr, "EncryptedPremasterSecret\n"); + winpr_HexDump(license->EncryptedPremasterSecret->buffer, license->EncryptedPremasterSecret->length); + fprintf(stderr, "\n"); - printf("ClientUserName (%d): %s\n", license->ClientUserName->length, (char*) license->ClientUserName->data); - printf("\n"); + fprintf(stderr, "ClientUserName (%d): %s\n", license->ClientUserName->length, (char*) license->ClientUserName->buffer); + fprintf(stderr, "\n"); - printf("ClientMachineName (%d): %s\n", license->ClientMachineName->length, (char*) license->ClientMachineName->data); - printf("\n"); + fprintf(stderr, "ClientMachineName (%d): %s\n", license->ClientMachineName->length, (char*) license->ClientMachineName->buffer); + fprintf(stderr, "\n"); #endif } @@ -949,7 +949,7 @@ void license_write_new_license_request_packet(rdpLicense* license, STREAM* s) void license_send_new_license_request_packet(rdpLicense* license) { - STREAM* s; + wStream* s; char* username; DEBUG_LICENSE("Sending New License Packet"); @@ -986,7 +986,7 @@ void license_send_new_license_request_packet(rdpLicense* license) * @param mac_data signature */ -void license_write_platform_challenge_response_packet(rdpLicense* license, STREAM* s, BYTE* macData) +void license_write_platform_challenge_response_packet(rdpLicense* license, wStream* s, BYTE* macData) { license_write_binary_blob(s, license->EncryptedPlatformChallenge); /* EncryptedPlatformChallengeResponse */ license_write_binary_blob(s, license->EncryptedHardwareId); /* EncryptedHWID */ @@ -1001,7 +1001,7 @@ void license_write_platform_challenge_response_packet(rdpLicense* license, STREA void license_send_platform_challenge_response_packet(rdpLicense* license) { - STREAM* s; + wStream* s; int length; BYTE* buffer; CryptoRc4 rc4; @@ -1030,17 +1030,17 @@ void license_send_platform_challenge_response_packet(rdpLicense* license) license->EncryptedHardwareId->length = HWID_LENGTH; #ifdef WITH_DEBUG_LICENSE - printf("LicensingEncryptionKey:\n"); + fprintf(stderr, "LicensingEncryptionKey:\n"); winpr_HexDump(license->LicensingEncryptionKey, 16); - printf("\n"); + fprintf(stderr, "\n"); - printf("HardwareId:\n"); + fprintf(stderr, "HardwareId:\n"); winpr_HexDump(license->HardwareId, 20); - printf("\n"); + fprintf(stderr, "\n"); - printf("EncryptedHardwareId:\n"); - winpr_HexDump(license->EncryptedHardwareId->data, 20); - printf("\n"); + fprintf(stderr, "EncryptedHardwareId:\n"); + winpr_HexDump(license->EncryptedHardwareId->buffer, 20); + fprintf(stderr, "\n"); #endif license_write_platform_challenge_response_packet(license, s, mac_data); @@ -1056,7 +1056,7 @@ void license_send_platform_challenge_response_packet(rdpLicense* license) BOOL license_send_valid_client_error_packet(rdpLicense* license) { - STREAM* s; + wStream* s; s = license_send_stream_init(license); diff --git a/libfreerdp/core/license.h b/libfreerdp/core/license.h index 21ea814fb..423b85a3f 100644 --- a/libfreerdp/core/license.h +++ b/libfreerdp/core/license.h @@ -23,12 +23,14 @@ typedef struct rdp_license rdpLicense; #include "rdp.h" + #include <freerdp/crypto/crypto.h> #include <freerdp/crypto/certificate.h> #include <freerdp/freerdp.h> #include <freerdp/utils/debug.h> -#include <freerdp/utils/stream.h> + +#include <winpr/stream.h> /* Licensing Packet Types */ @@ -198,9 +200,9 @@ struct rdp_license SCOPE_LIST* ScopeList; }; -BOOL license_recv(rdpLicense* license, STREAM* s); -BOOL license_send(rdpLicense* license, STREAM* s, BYTE type); -STREAM* license_send_stream_init(rdpLicense* license); +BOOL license_recv(rdpLicense* license, wStream* s); +BOOL license_send(rdpLicense* license, wStream* s, BYTE type); +wStream* license_send_stream_init(rdpLicense* license); void license_generate_randoms(rdpLicense* license); void license_generate_keys(rdpLicense* license); @@ -210,27 +212,27 @@ void license_decrypt_platform_challenge(rdpLicense* license); PRODUCT_INFO* license_new_product_info(void); void license_free_product_info(PRODUCT_INFO* productInfo); -BOOL license_read_product_info(STREAM* s, PRODUCT_INFO* productInfo); +BOOL license_read_product_info(wStream* s, PRODUCT_INFO* productInfo); LICENSE_BLOB* license_new_binary_blob(UINT16 type); void license_free_binary_blob(LICENSE_BLOB* blob); -BOOL license_read_binary_blob(STREAM* s, LICENSE_BLOB* blob); -void license_write_binary_blob(STREAM* s, LICENSE_BLOB* blob); +BOOL license_read_binary_blob(wStream* s, LICENSE_BLOB* blob); +void license_write_binary_blob(wStream* s, LICENSE_BLOB* blob); SCOPE_LIST* license_new_scope_list(void); void license_free_scope_list(SCOPE_LIST* scopeList); -BOOL license_read_scope_list(STREAM* s, SCOPE_LIST* scopeList); +BOOL license_read_scope_list(wStream* s, SCOPE_LIST* scopeList); -BOOL license_read_license_request_packet(rdpLicense* license, STREAM* s); -BOOL license_read_platform_challenge_packet(rdpLicense* license, STREAM* s); -void license_read_new_license_packet(rdpLicense* license, STREAM* s); -void license_read_upgrade_license_packet(rdpLicense* license, STREAM* s); -BOOL license_read_error_alert_packet(rdpLicense* license, STREAM* s); +BOOL license_read_license_request_packet(rdpLicense* license, wStream* s); +BOOL license_read_platform_challenge_packet(rdpLicense* license, wStream* s); +void license_read_new_license_packet(rdpLicense* license, wStream* s); +void license_read_upgrade_license_packet(rdpLicense* license, wStream* s); +BOOL license_read_error_alert_packet(rdpLicense* license, wStream* s); -void license_write_new_license_request_packet(rdpLicense* license, STREAM* s); +void license_write_new_license_request_packet(rdpLicense* license, wStream* s); void license_send_new_license_request_packet(rdpLicense* license); -void license_write_platform_challenge_response_packet(rdpLicense* license, STREAM* s, BYTE* mac_data); +void license_write_platform_challenge_response_packet(rdpLicense* license, wStream* s, BYTE* mac_data); void license_send_platform_challenge_response_packet(rdpLicense* license); BOOL license_send_valid_client_error_packet(rdpLicense* license); diff --git a/libfreerdp/core/listener.c b/libfreerdp/core/listener.c index 850077046..2390542fb 100644 --- a/libfreerdp/core/listener.c +++ b/libfreerdp/core/listener.c @@ -163,7 +163,7 @@ static BOOL freerdp_listener_open(freerdp_listener* instance, const char* bind_a else sin_addr = &(((struct sockaddr_in6*) ai->ai_addr)->sin6_addr); - printf("Listening on %s port %s.\n", inet_ntop(ai->ai_family, sin_addr, buf, sizeof(buf)), servname); + fprintf(stderr, "Listening on %s port %s.\n", inet_ntop(ai->ai_family, sin_addr, buf, sizeof(buf)), servname); } freeaddrinfo(res); @@ -213,7 +213,7 @@ static BOOL freerdp_listener_open_local(freerdp_listener* instance, const char* listener->sockfds[listener->num_sockfds++] = sockfd; - printf("Listening on socket %s.\n", addr.sun_path); + fprintf(stderr, "Listening on socket %s.\n", addr.sun_path); return TRUE; #else diff --git a/libfreerdp/core/mcs.c b/libfreerdp/core/mcs.c index 5b4696315..560df65e1 100644 --- a/libfreerdp/core/mcs.c +++ b/libfreerdp/core/mcs.c @@ -191,7 +191,7 @@ static const char* const mcs_result_enumerated[] = * @return */ -BOOL mcs_read_domain_mcspdu_header(STREAM* s, enum DomainMCSPDU* domainMCSPDU, UINT16* length) +BOOL mcs_read_domain_mcspdu_header(wStream* s, enum DomainMCSPDU* domainMCSPDU, UINT16* length) { UINT16 li; BYTE choice; @@ -222,7 +222,7 @@ BOOL mcs_read_domain_mcspdu_header(STREAM* s, enum DomainMCSPDU* domainMCSPDU, U * @param length TPKT length */ -void mcs_write_domain_mcspdu_header(STREAM* s, enum DomainMCSPDU domainMCSPDU, UINT16 length, BYTE options) +void mcs_write_domain_mcspdu_header(wStream* s, enum DomainMCSPDU domainMCSPDU, UINT16 length, BYTE options) { tpkt_write_header(s, length); tpdu_write_data(s); @@ -258,7 +258,7 @@ static void mcs_init_domain_parameters(DomainParameters* domainParameters, * @param domainParameters domain parameters */ -BOOL mcs_read_domain_parameters(STREAM* s, DomainParameters* domainParameters) +BOOL mcs_read_domain_parameters(wStream* s, DomainParameters* domainParameters) { int length; return @@ -279,10 +279,10 @@ BOOL mcs_read_domain_parameters(STREAM* s, DomainParameters* domainParameters) * @param domainParameters domain parameters */ -void mcs_write_domain_parameters(STREAM* s, DomainParameters* domainParameters) +void mcs_write_domain_parameters(wStream* s, DomainParameters* domainParameters) { int length; - STREAM* tmps; + wStream* tmps; tmps = stream_new(stream_get_size(s)); ber_write_integer(tmps, domainParameters->maxChannelIds); @@ -307,16 +307,16 @@ void mcs_write_domain_parameters(STREAM* s, DomainParameters* domainParameters) void mcs_print_domain_parameters(DomainParameters* domainParameters) { - printf("DomainParameters {\n"); - printf("\tmaxChannelIds:%d\n", domainParameters->maxChannelIds); - printf("\tmaxUserIds:%d\n", domainParameters->maxUserIds); - printf("\tmaxTokenIds:%d\n", domainParameters->maxTokenIds); - printf("\tnumPriorities:%d\n", domainParameters->numPriorities); - printf("\tminThroughput:%d\n", domainParameters->minThroughput); - printf("\tmaxHeight:%d\n", domainParameters->maxHeight); - printf("\tmaxMCSPDUsize:%d\n", domainParameters->maxMCSPDUsize); - printf("\tprotocolVersion:%d\n", domainParameters->protocolVersion); - printf("}\n"); + fprintf(stderr, "DomainParameters {\n"); + fprintf(stderr, "\tmaxChannelIds:%d\n", domainParameters->maxChannelIds); + fprintf(stderr, "\tmaxUserIds:%d\n", domainParameters->maxUserIds); + fprintf(stderr, "\tmaxTokenIds:%d\n", domainParameters->maxTokenIds); + fprintf(stderr, "\tnumPriorities:%d\n", domainParameters->numPriorities); + fprintf(stderr, "\tminThroughput:%d\n", domainParameters->minThroughput); + fprintf(stderr, "\tmaxHeight:%d\n", domainParameters->maxHeight); + fprintf(stderr, "\tmaxMCSPDUsize:%d\n", domainParameters->maxMCSPDUsize); + fprintf(stderr, "\tprotocolVersion:%d\n", domainParameters->protocolVersion); + fprintf(stderr, "}\n"); } /** @@ -326,7 +326,7 @@ void mcs_print_domain_parameters(DomainParameters* domainParameters) * @param s stream */ -BOOL mcs_recv_connect_initial(rdpMcs* mcs, STREAM* s) +BOOL mcs_recv_connect_initial(rdpMcs* mcs, wStream* s) { UINT16 li; int length; @@ -383,10 +383,10 @@ BOOL mcs_recv_connect_initial(rdpMcs* mcs, STREAM* s) * @param user_data GCC Conference Create Request */ -void mcs_write_connect_initial(STREAM* s, rdpMcs* mcs, STREAM* user_data) +void mcs_write_connect_initial(wStream* s, rdpMcs* mcs, wStream* user_data) { int length; - STREAM* tmps; + wStream* tmps; tmps = stream_new(stream_get_size(s)); @@ -409,7 +409,7 @@ void mcs_write_connect_initial(STREAM* s, rdpMcs* mcs, STREAM* user_data) mcs_write_domain_parameters(tmps, &mcs->maximumParameters); /* userData (OCTET_STRING) */ - ber_write_octet_string(tmps, user_data->data, stream_get_length(user_data)); + ber_write_octet_string(tmps, user_data->buffer, stream_get_length(user_data)); length = stream_get_length(tmps); /* Connect-Initial (APPLICATION 101, IMPLICIT SEQUENCE) */ @@ -426,10 +426,10 @@ void mcs_write_connect_initial(STREAM* s, rdpMcs* mcs, STREAM* user_data) * @param user_data GCC Conference Create Response */ -void mcs_write_connect_response(STREAM* s, rdpMcs* mcs, STREAM* user_data) +void mcs_write_connect_response(wStream* s, rdpMcs* mcs, wStream* user_data) { int length; - STREAM* tmps; + wStream* tmps; tmps = stream_new(stream_get_size(s)); ber_write_enumerated(tmps, 0, MCS_Result_enum_length); @@ -437,7 +437,7 @@ void mcs_write_connect_response(STREAM* s, rdpMcs* mcs, STREAM* user_data) mcs->domainParameters = mcs->targetParameters; mcs_write_domain_parameters(tmps, &(mcs->domainParameters)); /* userData (OCTET_STRING) */ - ber_write_octet_string(tmps, user_data->data, stream_get_length(user_data)); + ber_write_octet_string(tmps, user_data->buffer, stream_get_length(user_data)); length = stream_get_length(tmps); ber_write_application_tag(s, MCS_TYPE_CONNECT_RESPONSE, length); @@ -453,11 +453,11 @@ void mcs_write_connect_response(STREAM* s, rdpMcs* mcs, STREAM* user_data) BOOL mcs_send_connect_initial(rdpMcs* mcs) { - STREAM* s; + wStream* s; int length; BYTE *bm, *em; - STREAM* gcc_CCrq; - STREAM* client_data; + wStream* gcc_CCrq; + wStream* client_data; int status; client_data = stream_new(512); @@ -494,7 +494,7 @@ BOOL mcs_send_connect_initial(rdpMcs* mcs) * @param mcs mcs module */ -BOOL mcs_recv_connect_response(rdpMcs* mcs, STREAM* s) +BOOL mcs_recv_connect_response(rdpMcs* mcs, wStream* s) { int length; BYTE result; @@ -517,7 +517,7 @@ BOOL mcs_recv_connect_response(rdpMcs* mcs, STREAM* s) if (!gcc_read_conference_create_response(s, mcs->transport->settings)) { - printf("mcs_recv_connect_response: gcc_read_conference_create_response failed\n"); + fprintf(stderr, "mcs_recv_connect_response: gcc_read_conference_create_response failed\n"); return FALSE; } @@ -532,12 +532,12 @@ BOOL mcs_recv_connect_response(rdpMcs* mcs, STREAM* s) BOOL mcs_send_connect_response(rdpMcs* mcs) { - STREAM* s; + wStream* s; int length; int ret; BYTE *bm, *em; - STREAM* gcc_CCrsp; - STREAM* server_data; + wStream* gcc_CCrsp; + wStream* server_data; server_data = stream_new(512); gcc_write_server_data_blocks(server_data, mcs->transport->settings); @@ -574,7 +574,7 @@ BOOL mcs_send_connect_response(rdpMcs* mcs) * @param s stream */ -BOOL mcs_recv_erect_domain_request(rdpMcs* mcs, STREAM* s) +BOOL mcs_recv_erect_domain_request(rdpMcs* mcs, wStream* s) { UINT16 length; enum DomainMCSPDU MCSPDU; @@ -591,7 +591,7 @@ BOOL mcs_recv_erect_domain_request(rdpMcs* mcs, STREAM* s) BOOL mcs_send_erect_domain_request(rdpMcs* mcs) { - STREAM* s; + wStream* s; UINT16 length = 12; s = transport_send_stream_init(mcs->transport, length); @@ -613,7 +613,7 @@ BOOL mcs_send_erect_domain_request(rdpMcs* mcs) * @param s stream */ -BOOL mcs_recv_attach_user_request(rdpMcs* mcs, STREAM* s) +BOOL mcs_recv_attach_user_request(rdpMcs* mcs, wStream* s) { UINT16 length; enum DomainMCSPDU MCSPDU; @@ -630,7 +630,7 @@ BOOL mcs_recv_attach_user_request(rdpMcs* mcs, STREAM* s) BOOL mcs_send_attach_user_request(rdpMcs* mcs) { - STREAM* s; + wStream* s; UINT16 length = 8; s = transport_send_stream_init(mcs->transport, length); @@ -648,7 +648,7 @@ BOOL mcs_send_attach_user_request(rdpMcs* mcs) * @param mcs mcs module */ -BOOL mcs_recv_attach_user_confirm(rdpMcs* mcs, STREAM* s) +BOOL mcs_recv_attach_user_confirm(rdpMcs* mcs, wStream* s) { UINT16 length; BYTE result; @@ -669,7 +669,7 @@ BOOL mcs_recv_attach_user_confirm(rdpMcs* mcs, STREAM* s) BOOL mcs_send_attach_user_confirm(rdpMcs* mcs) { - STREAM* s; + wStream* s; UINT16 length = 11; s = transport_send_stream_init(mcs->transport, length); @@ -692,7 +692,7 @@ BOOL mcs_send_attach_user_confirm(rdpMcs* mcs) * @param s stream */ -BOOL mcs_recv_channel_join_request(rdpMcs* mcs, STREAM* s, UINT16* channel_id) +BOOL mcs_recv_channel_join_request(rdpMcs* mcs, wStream* s, UINT16* channel_id) { UINT16 length; enum DomainMCSPDU MCSPDU; @@ -715,7 +715,7 @@ BOOL mcs_recv_channel_join_request(rdpMcs* mcs, STREAM* s, UINT16* channel_id) BOOL mcs_send_channel_join_request(rdpMcs* mcs, UINT16 channel_id) { - STREAM* s; + wStream* s; UINT16 length = 12; s = transport_send_stream_init(mcs->transport, 12); @@ -736,7 +736,7 @@ BOOL mcs_send_channel_join_request(rdpMcs* mcs, UINT16 channel_id) * @param mcs mcs module */ -BOOL mcs_recv_channel_join_confirm(rdpMcs* mcs, STREAM* s, UINT16* channel_id) +BOOL mcs_recv_channel_join_confirm(rdpMcs* mcs, wStream* s, UINT16* channel_id) { BOOL status; UINT16 length; @@ -765,7 +765,7 @@ BOOL mcs_recv_channel_join_confirm(rdpMcs* mcs, STREAM* s, UINT16* channel_id) BOOL mcs_send_channel_join_confirm(rdpMcs* mcs, UINT16 channel_id) { - STREAM* s; + wStream* s; UINT16 length = 15; s = transport_send_stream_init(mcs->transport, 15); @@ -788,7 +788,7 @@ BOOL mcs_send_channel_join_confirm(rdpMcs* mcs, UINT16 channel_id) BOOL mcs_send_disconnect_provider_ultimatum(rdpMcs* mcs) { - STREAM* s; + wStream* s; UINT16 length = 9; s = transport_send_stream_init(mcs->transport, 9); diff --git a/libfreerdp/core/mcs.h b/libfreerdp/core/mcs.h index 93a34aceb..1006231a7 100644 --- a/libfreerdp/core/mcs.h +++ b/libfreerdp/core/mcs.h @@ -21,10 +21,12 @@ #define __MCS_H #include "transport.h" + #include <freerdp/crypto/ber.h> #include <freerdp/types.h> -#include <freerdp/utils/stream.h> + +#include <winpr/stream.h> #define MCS_BASE_CHANNEL_ID 1001 #define MCS_GLOBAL_CHANNEL_ID 1003 @@ -129,26 +131,26 @@ typedef struct rdp_mcs rdpMcs; #define MCS_TYPE_CONNECT_INITIAL 0x65 #define MCS_TYPE_CONNECT_RESPONSE 0x66 -void mcs_write_connect_initial(STREAM* s, rdpMcs* mcs, STREAM* user_data); -void mcs_write_connect_response(STREAM* s, rdpMcs* mcs, STREAM* user_data); +void mcs_write_connect_initial(wStream* s, rdpMcs* mcs, wStream* user_data); +void mcs_write_connect_response(wStream* s, rdpMcs* mcs, wStream* user_data); -BOOL mcs_recv_connect_initial(rdpMcs* mcs, STREAM* s); +BOOL mcs_recv_connect_initial(rdpMcs* mcs, wStream* s); BOOL mcs_send_connect_initial(rdpMcs* mcs); -BOOL mcs_recv_connect_response(rdpMcs* mcs, STREAM* s); +BOOL mcs_recv_connect_response(rdpMcs* mcs, wStream* s); BOOL mcs_send_connect_response(rdpMcs* mcs); -BOOL mcs_recv_erect_domain_request(rdpMcs* mcs, STREAM* s); +BOOL mcs_recv_erect_domain_request(rdpMcs* mcs, wStream* s); BOOL mcs_send_erect_domain_request(rdpMcs* mcs); -BOOL mcs_recv_attach_user_request(rdpMcs* mcs, STREAM* s); +BOOL mcs_recv_attach_user_request(rdpMcs* mcs, wStream* s); BOOL mcs_send_attach_user_request(rdpMcs* mcs); -BOOL mcs_recv_attach_user_confirm(rdpMcs* mcs, STREAM* s); +BOOL mcs_recv_attach_user_confirm(rdpMcs* mcs, wStream* s); BOOL mcs_send_attach_user_confirm(rdpMcs* mcs); -BOOL mcs_recv_channel_join_request(rdpMcs* mcs, STREAM* s, UINT16* channel_id); +BOOL mcs_recv_channel_join_request(rdpMcs* mcs, wStream* s, UINT16* channel_id); BOOL mcs_send_channel_join_request(rdpMcs* mcs, UINT16 channel_id); -BOOL mcs_recv_channel_join_confirm(rdpMcs* mcs, STREAM* s, UINT16* channel_id); +BOOL mcs_recv_channel_join_confirm(rdpMcs* mcs, wStream* s, UINT16* channel_id); BOOL mcs_send_channel_join_confirm(rdpMcs* mcs, UINT16 channel_id); BOOL mcs_send_disconnect_provider_ultimatum(rdpMcs* mcs); -BOOL mcs_read_domain_mcspdu_header(STREAM* s, enum DomainMCSPDU* domainMCSPDU, UINT16* length); -void mcs_write_domain_mcspdu_header(STREAM* s, enum DomainMCSPDU domainMCSPDU, UINT16 length, BYTE options); +BOOL mcs_read_domain_mcspdu_header(wStream* s, enum DomainMCSPDU* domainMCSPDU, UINT16* length); +void mcs_write_domain_mcspdu_header(wStream* s, enum DomainMCSPDU domainMCSPDU, UINT16 length, BYTE options); rdpMcs* mcs_new(rdpTransport* transport); void mcs_free(rdpMcs* mcs); diff --git a/libfreerdp/core/message.c b/libfreerdp/core/message.c index 0e85442c0..3ccea28d3 100644 --- a/libfreerdp/core/message.c +++ b/libfreerdp/core/message.c @@ -21,11 +21,18 @@ #include "config.h" #endif +#include "rdp.h" #include "message.h" +#include "transport.h" + +#include <freerdp/freerdp.h> #include <winpr/crt.h> +#include <winpr/stream.h> #include <winpr/collections.h> +//#define WITH_STREAM_POOL 1 + /* Update */ static void update_message_BeginPaint(rdpContext* context) @@ -79,13 +86,15 @@ static void update_message_BitmapUpdate(rdpContext* context, BITMAP_UPDATE* bitm wParam->rectangles = (BITMAP_DATA*) malloc(sizeof(BITMAP_DATA) * wParam->number); CopyMemory(wParam->rectangles, bitmap->rectangles, sizeof(BITMAP_DATA) * wParam->number); - /* TODO: increment reference count to original stream instead of copying */ - for (index = 0; index < wParam->number; index++) { +#ifdef WITH_STREAM_POOL + StreamPool_AddRef(context->rdp->transport->ReceivePool, bitmap->rectangles[index].bitmapDataStream); +#else wParam->rectangles[index].bitmapDataStream = (BYTE*) malloc(wParam->rectangles[index].bitmapLength); CopyMemory(wParam->rectangles[index].bitmapDataStream, bitmap->rectangles[index].bitmapDataStream, wParam->rectangles[index].bitmapLength); +#endif } MessageQueue_Post(context->update->queue, (void*) context, @@ -139,15 +148,15 @@ static void update_message_SuppressOutput(rdpContext* context, BYTE allow, RECTA MakeMessageId(Update, SuppressOutput), (void*) (size_t) allow, (void*) lParam); } -static void update_message_SurfaceCommand(rdpContext* context, STREAM* s) +static void update_message_SurfaceCommand(rdpContext* context, wStream* s) { - STREAM* wParam; + wStream* wParam; - wParam = (STREAM*) malloc(sizeof(STREAM)); + wParam = (wStream*) malloc(sizeof(wStream)); - wParam->size = s->size; - wParam->data = (BYTE*) malloc(wParam->size); - wParam->p = wParam->data; + wParam->capacity = s->capacity; + wParam->buffer = (BYTE*) malloc(wParam->capacity); + wParam->pointer = wParam->buffer; MessageQueue_Post(context->update->queue, (void*) context, MakeMessageId(Update, SurfaceCommand), (void*) wParam, NULL); @@ -160,8 +169,12 @@ static void update_message_SurfaceBits(rdpContext* context, SURFACE_BITS_COMMAND wParam = (SURFACE_BITS_COMMAND*) malloc(sizeof(SURFACE_BITS_COMMAND)); CopyMemory(wParam, surfaceBitsCommand, sizeof(SURFACE_BITS_COMMAND)); +#ifdef WITH_STREAM_POOL + StreamPool_AddRef(context->rdp->transport->ReceivePool, surfaceBitsCommand->bitmapData); +#else wParam->bitmapData = (BYTE*) malloc(wParam->bitmapDataLength); CopyMemory(wParam->bitmapData, surfaceBitsCommand->bitmapData, wParam->bitmapDataLength); +#endif MessageQueue_Post(context->update->queue, (void*) context, MakeMessageId(Update, SurfaceBits), (void*) wParam, NULL); @@ -952,7 +965,14 @@ int update_message_process_update_class(rdpUpdateProxy* proxy, wMessage* msg, in BITMAP_UPDATE* wParam = (BITMAP_UPDATE*) msg->wParam; for (index = 0; index < wParam->number; index++) + { +#ifdef WITH_STREAM_POOL + rdpContext* context = (rdpContext*) msg->context; + StreamPool_Release(context->rdp->transport->ReceivePool, wParam->rectangles[index].bitmapDataStream); +#else free(wParam->rectangles[index].bitmapDataStream); +#endif + } free(wParam); } @@ -982,10 +1002,10 @@ int update_message_process_update_class(rdpUpdateProxy* proxy, wMessage* msg, in break; case Update_SurfaceCommand: - IFCALL(proxy->SurfaceCommand, msg->context, (STREAM*) msg->wParam); + IFCALL(proxy->SurfaceCommand, msg->context, (wStream*) msg->wParam); { - STREAM* s = (STREAM*) msg->wParam; - free(s->data); + wStream* s = (wStream*) msg->wParam; + free(s->buffer); free(s); } break; @@ -993,9 +1013,15 @@ int update_message_process_update_class(rdpUpdateProxy* proxy, wMessage* msg, in case Update_SurfaceBits: IFCALL(proxy->SurfaceBits, msg->context, (SURFACE_BITS_COMMAND*) msg->wParam); { +#ifdef WITH_STREAM_POOL + rdpContext* context = (rdpContext*) msg->context; + SURFACE_BITS_COMMAND* wParam = (SURFACE_BITS_COMMAND*) msg->wParam; + StreamPool_Release(context->rdp->transport->ReceivePool, wParam->bitmapData); +#else SURFACE_BITS_COMMAND* wParam = (SURFACE_BITS_COMMAND*) msg->wParam; free(wParam->bitmapData); free(wParam); +#endif } break; @@ -1481,7 +1507,7 @@ int update_message_process_class(rdpUpdateProxy* proxy, wMessage* msg, int msgCl } if (status < 0) - printf("Unknown message: class: %d type: %d\n", msgClass, msgType); + fprintf(stderr, "Unknown message: class: %d type: %d\n", msgClass, msgType); return status; } @@ -1854,7 +1880,7 @@ int input_message_process_class(rdpInputProxy* proxy, wMessage* msg, int msgClas } if (status < 0) - printf("Unknown event: class: %d type: %d\n", msgClass, msgType); + fprintf(stderr, "Unknown event: class: %d type: %d\n", msgClass, msgType); return status; } diff --git a/libfreerdp/core/nego.c b/libfreerdp/core/nego.c index bdbb126ab..0227620ae 100644 --- a/libfreerdp/core/nego.c +++ b/libfreerdp/core/nego.c @@ -253,7 +253,7 @@ int nego_transport_disconnect(rdpNego* nego) BOOL nego_send_preconnection_pdu(rdpNego* nego) { - STREAM* s; + wStream* s; UINT32 cbSize; UINT16 cchPCB = 0; WCHAR* wszPCB = NULL; @@ -462,7 +462,7 @@ void nego_attempt_rdp(rdpNego* nego) BOOL nego_recv_response(rdpNego* nego) { - STREAM* s = transport_recv_stream_init(nego->transport, 1024); + wStream* s = transport_recv_stream_init(nego->transport, 1024); if (transport_read(nego->transport, s) < 0) return FALSE; @@ -478,7 +478,7 @@ BOOL nego_recv_response(rdpNego* nego) * @param extra nego pointer */ -int nego_recv(rdpTransport* transport, STREAM* s, void* extra) +int nego_recv(rdpTransport* transport, wStream* s, void* extra) { BYTE li; BYTE type; @@ -490,7 +490,7 @@ int nego_recv(rdpTransport* transport, STREAM* s, void* extra) if (length == 0) return -1; - if(!tpdu_read_connection_confirm(s, &li)) + if (!tpdu_read_connection_confirm(s, &li)) return -1; if (li > 6) @@ -543,7 +543,7 @@ int nego_recv(rdpTransport* transport, STREAM* s, void* extra) } else { - printf("invalid negotiation response\n"); + fprintf(stderr, "invalid negotiation response\n"); nego->state = NEGO_STATE_FAIL; } @@ -556,19 +556,20 @@ int nego_recv(rdpTransport* transport, STREAM* s, void* extra) * @param s stream */ -BOOL nego_read_request(rdpNego* nego, STREAM* s) +BOOL nego_read_request(rdpNego* nego, wStream* s) { BYTE li; BYTE c; BYTE type; tpkt_read_header(s); - if(!tpdu_read_connection_request(s, &li)) + + if (!tpdu_read_connection_request(s, &li)) return FALSE; if (li != stream_get_left(s) + 6) { - printf("Incorrect TPDU length indicator.\n"); + fprintf(stderr, "Incorrect TPDU length indicator.\n"); return FALSE; } @@ -600,7 +601,7 @@ BOOL nego_read_request(rdpNego* nego, STREAM* s) if (type != TYPE_RDP_NEG_REQ) { - printf("Incorrect negotiation request type %d\n", type); + fprintf(stderr, "Incorrect negotiation request type %d\n", type); return FALSE; } @@ -638,7 +639,7 @@ void nego_send(rdpNego* nego) BOOL nego_send_negotiation_request(rdpNego* nego) { - STREAM* s; + wStream* s; int length; BYTE *bm, *em; int cookie_length; @@ -648,12 +649,14 @@ BOOL nego_send_negotiation_request(rdpNego* nego) stream_get_mark(s, bm); stream_seek(s, length); - if (nego->RoutingToken != NULL) + if (nego->RoutingToken) { stream_write(s, nego->RoutingToken, nego->RoutingTokenLength); - length += nego->RoutingTokenLength; + stream_write_BYTE(s, 0x0D); /* CR */ + stream_write_BYTE(s, 0x0A); /* LF */ + length += nego->RoutingTokenLength + 2; } - else if (nego->cookie != NULL) + else if (nego->cookie) { cookie_length = strlen(nego->cookie); @@ -669,7 +672,7 @@ BOOL nego_send_negotiation_request(rdpNego* nego) DEBUG_NEGO("requested_protocols: %d", nego->requested_protocols); - if (nego->requested_protocols > PROTOCOL_RDP) + if ((nego->requested_protocols > PROTOCOL_RDP) || (nego->sendNegoData)) { /* RDP_NEG_DATA must be present for TLS and NLA */ stream_write_BYTE(s, TYPE_RDP_NEG_REQ); @@ -697,7 +700,7 @@ BOOL nego_send_negotiation_request(rdpNego* nego) * @param s */ -void nego_process_negotiation_request(rdpNego* nego, STREAM* s) +void nego_process_negotiation_request(rdpNego* nego, wStream* s) { BYTE flags; UINT16 length; @@ -719,7 +722,7 @@ void nego_process_negotiation_request(rdpNego* nego, STREAM* s) * @param s */ -void nego_process_negotiation_response(rdpNego* nego, STREAM* s) +void nego_process_negotiation_response(rdpNego* nego, wStream* s) { UINT16 length; @@ -745,7 +748,7 @@ void nego_process_negotiation_response(rdpNego* nego, STREAM* s) * @param s */ -void nego_process_negotiation_failure(rdpNego* nego, STREAM* s) +void nego_process_negotiation_failure(rdpNego* nego, wStream* s) { BYTE flags; UINT16 length; @@ -762,18 +765,24 @@ void nego_process_negotiation_failure(rdpNego* nego, STREAM* s) case SSL_REQUIRED_BY_SERVER: DEBUG_NEGO("Error: SSL_REQUIRED_BY_SERVER"); break; + case SSL_NOT_ALLOWED_BY_SERVER: DEBUG_NEGO("Error: SSL_NOT_ALLOWED_BY_SERVER"); break; + case SSL_CERT_NOT_ON_SERVER: DEBUG_NEGO("Error: SSL_CERT_NOT_ON_SERVER"); + nego->sendNegoData = TRUE; break; + case INCONSISTENT_FLAGS: DEBUG_NEGO("Error: INCONSISTENT_FLAGS"); break; + case HYBRID_REQUIRED_BY_SERVER: DEBUG_NEGO("Error: HYBRID_REQUIRED_BY_SERVER"); break; + default: DEBUG_NEGO("Error: Unknown protocol security error %d", failureCode); break; @@ -789,7 +798,7 @@ void nego_process_negotiation_failure(rdpNego* nego, STREAM* s) BOOL nego_send_negotiation_response(rdpNego* nego) { - STREAM* s; + wStream* s; BYTE* bm; BYTE* em; int length; @@ -822,7 +831,7 @@ BOOL nego_send_negotiation_response(rdpNego* nego) * TODO: Check for other possibilities, * like SSL_NOT_ALLOWED_BY_SERVER. */ - printf("nego_send_negotiation_response: client supports only Standard RDP Security\n"); + fprintf(stderr, "nego_send_negotiation_response: client supports only Standard RDP Security\n"); stream_write_UINT32(s, SSL_REQUIRED_BY_SERVER); length += 8; status = FALSE; diff --git a/libfreerdp/core/nego.h b/libfreerdp/core/nego.h index 0d7f14b40..e8f429fb8 100644 --- a/libfreerdp/core/nego.h +++ b/libfreerdp/core/nego.h @@ -21,10 +21,12 @@ #define FREERDP_CORE_NEGO_H #include "transport.h" + #include <freerdp/types.h> #include <freerdp/settings.h> #include <freerdp/utils/debug.h> -#include <freerdp/utils/stream.h> + +#include <winpr/stream.h> /* Protocol Security Negotiation Protocols */ enum RDP_NEG_PROTOCOLS @@ -98,6 +100,7 @@ struct rdp_nego BOOL security_connected; UINT32 cookie_max_length; + BOOL sendNegoData; UINT32 selected_protocol; UINT32 requested_protocols; BOOL NegotiateSecurityLayer; @@ -117,14 +120,14 @@ void nego_attempt_tls(rdpNego* nego); void nego_attempt_rdp(rdpNego* nego); void nego_send(rdpNego* nego); -int nego_recv(rdpTransport* transport, STREAM* s, void* extra); +int nego_recv(rdpTransport* transport, wStream* s, void* extra); BOOL nego_recv_response(rdpNego* nego); -BOOL nego_read_request(rdpNego* nego, STREAM* s); +BOOL nego_read_request(rdpNego* nego, wStream* s); BOOL nego_send_negotiation_request(rdpNego* nego); -void nego_process_negotiation_request(rdpNego* nego, STREAM* s); -void nego_process_negotiation_response(rdpNego* nego, STREAM* s); -void nego_process_negotiation_failure(rdpNego* nego, STREAM* s); +void nego_process_negotiation_request(rdpNego* nego, wStream* s); +void nego_process_negotiation_response(rdpNego* nego, wStream* s); +void nego_process_negotiation_failure(rdpNego* nego, wStream* s); BOOL nego_send_negotiation_response(rdpNego* nego); rdpNego* nego_new(struct rdp_transport * transport); diff --git a/libfreerdp/core/nla.c b/libfreerdp/core/nla.c index 441bf9680..7d87ed9c0 100644 --- a/libfreerdp/core/nla.c +++ b/libfreerdp/core/nla.c @@ -216,7 +216,7 @@ int credssp_client_authenticate(rdpCredssp* credssp) if (status != SEC_E_OK) { - printf("QuerySecurityPackageInfo status: 0x%08X\n", status); + fprintf(stderr, "QuerySecurityPackageInfo status: 0x%08X\n", status); return 0; } @@ -227,7 +227,7 @@ int credssp_client_authenticate(rdpCredssp* credssp) if (status != SEC_E_OK) { - printf("AcquireCredentialsHandle status: 0x%08X\n", status); + fprintf(stderr, "AcquireCredentialsHandle status: 0x%08X\n", status); return 0; } @@ -278,7 +278,7 @@ int credssp_client_authenticate(rdpCredssp* credssp) if (credssp->table->QueryContextAttributes(&credssp->context, SECPKG_ATTR_SIZES, &credssp->ContextSizes) != SEC_E_OK) { - printf("QueryContextAttributes SECPKG_ATTR_SIZES failure\n"); + fprintf(stderr, "QueryContextAttributes SECPKG_ATTR_SIZES failure\n"); return 0; } @@ -298,7 +298,7 @@ int credssp_client_authenticate(rdpCredssp* credssp) credssp->negoToken.cbBuffer = output_buffer.cbBuffer; #ifdef WITH_DEBUG_CREDSSP - printf("Sending Authentication Token\n"); + fprintf(stderr, "Sending Authentication Token\n"); winpr_HexDump(credssp->negoToken.pvBuffer, credssp->negoToken.cbBuffer); #endif @@ -320,7 +320,7 @@ int credssp_client_authenticate(rdpCredssp* credssp) return -1; #ifdef WITH_DEBUG_CREDSSP - printf("Receiving Authentication Token (%d)\n", (int) credssp->negoToken.cbBuffer); + fprintf(stderr, "Receiving Authentication Token (%d)\n", (int) credssp->negoToken.cbBuffer); winpr_HexDump(credssp->negoToken.pvBuffer, credssp->negoToken.cbBuffer); #endif @@ -342,7 +342,7 @@ int credssp_client_authenticate(rdpCredssp* credssp) if (status != SEC_E_OK) { - printf("Could not verify public key echo!\n"); + fprintf(stderr, "Could not verify public key echo!\n"); return -1; } @@ -352,7 +352,7 @@ int credssp_client_authenticate(rdpCredssp* credssp) if (status != SEC_E_OK) { - printf("credssp_encrypt_ts_credentials status: 0x%08X\n", status); + fprintf(stderr, "credssp_encrypt_ts_credentials status: 0x%08X\n", status); return 0; } @@ -432,7 +432,7 @@ int credssp_server_authenticate(rdpCredssp* credssp) if (status != SEC_E_OK) { - printf("QuerySecurityPackageInfo status: 0x%08X\n", status); + fprintf(stderr, "QuerySecurityPackageInfo status: 0x%08X\n", status); return 0; } @@ -443,7 +443,7 @@ int credssp_server_authenticate(rdpCredssp* credssp) if (status != SEC_E_OK) { - printf("AcquireCredentialsHandle status: 0x%08X\n", status); + fprintf(stderr, "AcquireCredentialsHandle status: 0x%08X\n", status); return 0; } @@ -493,7 +493,7 @@ int credssp_server_authenticate(rdpCredssp* credssp) return -1; #ifdef WITH_DEBUG_CREDSSP - printf("Receiving Authentication Token\n"); + fprintf(stderr, "Receiving Authentication Token\n"); credssp_buffer_print(credssp); #endif @@ -502,7 +502,7 @@ int credssp_server_authenticate(rdpCredssp* credssp) if (credssp->negoToken.cbBuffer < 1) { - printf("CredSSP: invalid negoToken!\n"); + fprintf(stderr, "CredSSP: invalid negoToken!\n"); return -1; } @@ -538,13 +538,13 @@ int credssp_server_authenticate(rdpCredssp* credssp) if (credssp->table->QueryContextAttributes(&credssp->context, SECPKG_ATTR_SIZES, &credssp->ContextSizes) != SEC_E_OK) { - printf("QueryContextAttributes SECPKG_ATTR_SIZES failure\n"); + fprintf(stderr, "QueryContextAttributes SECPKG_ATTR_SIZES failure\n"); return 0; } if (credssp_decrypt_public_key_echo(credssp) != SEC_E_OK) { - printf("Error: could not verify client's public key echo\n"); + fprintf(stderr, "Error: could not verify client's public key echo\n"); return -1; } @@ -557,14 +557,14 @@ int credssp_server_authenticate(rdpCredssp* credssp) if ((status != SEC_E_OK) && (status != SEC_I_CONTINUE_NEEDED)) { - printf("AcceptSecurityContext status: 0x%08X\n", status); + fprintf(stderr, "AcceptSecurityContext status: 0x%08X\n", status); return -1; } /* send authentication token */ #ifdef WITH_DEBUG_CREDSSP - printf("Sending Authentication Token\n"); + fprintf(stderr, "Sending Authentication Token\n"); credssp_buffer_print(credssp); #endif @@ -584,13 +584,13 @@ int credssp_server_authenticate(rdpCredssp* credssp) if (credssp_decrypt_ts_credentials(credssp) != SEC_E_OK) { - printf("Could not decrypt TSCredentials status: 0x%08X\n", status); + fprintf(stderr, "Could not decrypt TSCredentials status: 0x%08X\n", status); return 0; } if (status != SEC_E_OK) { - printf("AcceptSecurityContext status: 0x%08X\n", status); + fprintf(stderr, "AcceptSecurityContext status: 0x%08X\n", status); return 0; } @@ -598,7 +598,7 @@ int credssp_server_authenticate(rdpCredssp* credssp) if (status != SEC_E_OK) { - printf("ImpersonateSecurityContext status: 0x%08X\n", status); + fprintf(stderr, "ImpersonateSecurityContext status: 0x%08X\n", status); return 0; } else @@ -607,7 +607,7 @@ int credssp_server_authenticate(rdpCredssp* credssp) if (status != SEC_E_OK) { - printf("RevertSecurityContext status: 0x%08X\n", status); + fprintf(stderr, "RevertSecurityContext status: 0x%08X\n", status); return 0; } } @@ -704,7 +704,7 @@ SECURITY_STATUS credssp_encrypt_public_key_echo(rdpCredssp* credssp) if (status != SEC_E_OK) { - printf("EncryptMessage status: 0x%08X\n", status); + fprintf(stderr, "EncryptMessage status: 0x%08X\n", status); return status; } @@ -725,7 +725,7 @@ SECURITY_STATUS credssp_decrypt_public_key_echo(rdpCredssp* credssp) if (credssp->PublicKey.cbBuffer + credssp->ContextSizes.cbMaxSignature != credssp->pubKeyAuth.cbBuffer) { - printf("unexpected pubKeyAuth buffer size:%d\n", (int) credssp->pubKeyAuth.cbBuffer); + fprintf(stderr, "unexpected pubKeyAuth buffer size:%d\n", (int) credssp->pubKeyAuth.cbBuffer); return SEC_E_INVALID_TOKEN; } @@ -752,7 +752,7 @@ SECURITY_STATUS credssp_decrypt_public_key_echo(rdpCredssp* credssp) if (status != SEC_E_OK) { - printf("DecryptMessage failure: 0x%08X\n", status); + fprintf(stderr, "DecryptMessage failure: 0x%08X\n", status); return status; } @@ -767,12 +767,12 @@ SECURITY_STATUS credssp_decrypt_public_key_echo(rdpCredssp* credssp) if (memcmp(public_key1, public_key2, public_key_length) != 0) { - printf("Could not verify server's public key echo\n"); + fprintf(stderr, "Could not verify server's public key echo\n"); - printf("Expected (length = %d):\n", public_key_length); + fprintf(stderr, "Expected (length = %d):\n", public_key_length); winpr_HexDump(public_key1, public_key_length); - printf("Actual (length = %d):\n", public_key_length); + fprintf(stderr, "Actual (length = %d):\n", public_key_length); winpr_HexDump(public_key2, public_key_length); return SEC_E_MESSAGE_ALTERED; /* DO NOT SEND CREDENTIALS! */ @@ -805,7 +805,7 @@ int credssp_skip_ts_password_creds(rdpCredssp* credssp) return length; } -void credssp_read_ts_password_creds(rdpCredssp* credssp, STREAM* s) +void credssp_read_ts_password_creds(rdpCredssp* credssp, wStream* s) { int length; @@ -817,7 +817,7 @@ void credssp_read_ts_password_creds(rdpCredssp* credssp, STREAM* s) ber_read_octet_string_tag(s, &length); credssp->identity.DomainLength = (UINT32) length; credssp->identity.Domain = (UINT16*) malloc(length); - CopyMemory(credssp->identity.Domain, s->p, credssp->identity.DomainLength); + CopyMemory(credssp->identity.Domain, s->pointer, credssp->identity.DomainLength); stream_seek(s, credssp->identity.DomainLength); credssp->identity.DomainLength /= 2; @@ -826,7 +826,7 @@ void credssp_read_ts_password_creds(rdpCredssp* credssp, STREAM* s) ber_read_octet_string_tag(s, &length); credssp->identity.UserLength = (UINT32) length; credssp->identity.User = (UINT16*) malloc(length); - CopyMemory(credssp->identity.User, s->p, credssp->identity.UserLength); + CopyMemory(credssp->identity.User, s->pointer, credssp->identity.UserLength); stream_seek(s, credssp->identity.UserLength); credssp->identity.UserLength /= 2; @@ -835,14 +835,14 @@ void credssp_read_ts_password_creds(rdpCredssp* credssp, STREAM* s) ber_read_octet_string_tag(s, &length); credssp->identity.PasswordLength = (UINT32) length; credssp->identity.Password = (UINT16*) malloc(length); - CopyMemory(credssp->identity.Password, s->p, credssp->identity.PasswordLength); + CopyMemory(credssp->identity.Password, s->pointer, credssp->identity.PasswordLength); stream_seek(s, credssp->identity.PasswordLength); credssp->identity.PasswordLength /= 2; credssp->identity.Flags = SEC_WINNT_AUTH_IDENTITY_UNICODE; } -void credssp_write_ts_password_creds(rdpCredssp* credssp, STREAM* s) +void credssp_write_ts_password_creds(rdpCredssp* credssp, wStream* s) { int length; @@ -887,7 +887,7 @@ int credssp_skip_ts_credentials(rdpCredssp* credssp) void credssp_read_ts_credentials(rdpCredssp* credssp, PSecBuffer ts_credentials) { - STREAM* s; + wStream* s; int length; int ts_password_creds_length; @@ -911,7 +911,7 @@ void credssp_read_ts_credentials(rdpCredssp* credssp, PSecBuffer ts_credentials) stream_free(s); } -void credssp_write_ts_credentials(rdpCredssp* credssp, STREAM* s) +void credssp_write_ts_credentials(rdpCredssp* credssp, wStream* s) { int length; int ts_password_creds_length; @@ -942,7 +942,7 @@ void credssp_write_ts_credentials(rdpCredssp* credssp, STREAM* s) void credssp_encode_ts_credentials(rdpCredssp* credssp) { - STREAM* s; + wStream* s; int length; s = stream_new(0); @@ -1002,7 +1002,7 @@ SECURITY_STATUS credssp_decrypt_ts_credentials(rdpCredssp* credssp) if (credssp->authInfo.cbBuffer < 1) { - printf("credssp_decrypt_ts_credentials missing authInfo buffer\n"); + fprintf(stderr, "credssp_decrypt_ts_credentials missing authInfo buffer\n"); return SEC_E_INVALID_TOKEN; } @@ -1077,7 +1077,7 @@ int credssp_skip_ts_request(int length) void credssp_send(rdpCredssp* credssp) { - STREAM* s; + wStream* s; int length; int ts_request_length; int nego_tokens_length; @@ -1140,7 +1140,7 @@ void credssp_send(rdpCredssp* credssp) int credssp_recv(rdpCredssp* credssp) { - STREAM* s; + wStream* s; int length; int status; UINT32 version; @@ -1148,11 +1148,11 @@ int credssp_recv(rdpCredssp* credssp) s = stream_new(4096); status = transport_read(credssp->transport, s); - s->size = status; + s->capacity = status; if (status < 0) { - printf("credssp_recv() error: %d\n", status); + fprintf(stderr, "credssp_recv() error: %d\n", status); stream_free(s); return -1; } @@ -1208,19 +1208,19 @@ void credssp_buffer_print(rdpCredssp* credssp) { if (credssp->negoToken.cbBuffer > 0) { - printf("CredSSP.negoToken (length = %d):\n", (int) credssp->negoToken.cbBuffer); + fprintf(stderr, "CredSSP.negoToken (length = %d):\n", (int) credssp->negoToken.cbBuffer); winpr_HexDump(credssp->negoToken.pvBuffer, credssp->negoToken.cbBuffer); } if (credssp->pubKeyAuth.cbBuffer > 0) { - printf("CredSSP.pubKeyAuth (length = %d):\n", (int) credssp->pubKeyAuth.cbBuffer); + fprintf(stderr, "CredSSP.pubKeyAuth (length = %d):\n", (int) credssp->pubKeyAuth.cbBuffer); winpr_HexDump(credssp->pubKeyAuth.pvBuffer, credssp->pubKeyAuth.cbBuffer); } if (credssp->authInfo.cbBuffer > 0) { - printf("CredSSP.authInfo (length = %d):\n", (int) credssp->authInfo.cbBuffer); + fprintf(stderr, "CredSSP.authInfo (length = %d):\n", (int) credssp->authInfo.cbBuffer); winpr_HexDump(credssp->authInfo.pvBuffer, credssp->authInfo.cbBuffer); } } diff --git a/libfreerdp/core/nla.h b/libfreerdp/core/nla.h index c23dc01e4..5a4baa299 100644 --- a/libfreerdp/core/nla.h +++ b/libfreerdp/core/nla.h @@ -24,9 +24,9 @@ typedef struct rdp_credssp rdpCredssp; #include <freerdp/api.h> #include <freerdp/freerdp.h> -#include <freerdp/utils/stream.h> #include <winpr/sspi.h> +#include <winpr/stream.h> #include <freerdp/crypto/tls.h> #include <freerdp/crypto/ber.h> diff --git a/libfreerdp/core/orders.c b/libfreerdp/core/orders.c index 066cb087e..32e4b1bed 100644 --- a/libfreerdp/core/orders.c +++ b/libfreerdp/core/orders.c @@ -145,7 +145,7 @@ static const BYTE BMF_BPP[] = 0, 1, 0, 8, 16, 24, 32 }; -static INLINE BOOL update_read_coord(STREAM* s, INT32* coord, BOOL delta) +static INLINE BOOL update_read_coord(wStream* s, INT32* coord, BOOL delta) { INT8 lsi8; INT16 lsi16; @@ -167,7 +167,7 @@ static INLINE BOOL update_read_coord(STREAM* s, INT32* coord, BOOL delta) return TRUE; } -static INLINE BOOL update_read_color(STREAM* s, UINT32* color) +static INLINE BOOL update_read_color(wStream* s, UINT32* color) { BYTE byte; @@ -182,7 +182,7 @@ static INLINE BOOL update_read_color(STREAM* s, UINT32* color) return TRUE; } -static INLINE void update_read_colorref(STREAM* s, UINT32* color) +static INLINE void update_read_colorref(wStream* s, UINT32* color) { BYTE byte; @@ -195,7 +195,7 @@ static INLINE void update_read_colorref(STREAM* s, UINT32* color) stream_seek_BYTE(s); } -static INLINE void update_read_color_quad(STREAM* s, UINT32* color) +static INLINE void update_read_color_quad(wStream* s, UINT32* color) { BYTE byte; @@ -208,7 +208,7 @@ static INLINE void update_read_color_quad(STREAM* s, UINT32* color) stream_seek_BYTE(s); } -static INLINE BOOL update_read_2byte_unsigned(STREAM* s, UINT32* value) +static INLINE BOOL update_read_2byte_unsigned(wStream* s, UINT32* value) { BYTE byte; @@ -232,7 +232,7 @@ static INLINE BOOL update_read_2byte_unsigned(STREAM* s, UINT32* value) return TRUE; } -static INLINE BOOL update_read_2byte_signed(STREAM* s, INT32* value) +static INLINE BOOL update_read_2byte_signed(wStream* s, INT32* value) { BYTE byte; BOOL negative; @@ -259,7 +259,7 @@ static INLINE BOOL update_read_2byte_signed(STREAM* s, INT32* value) return TRUE; } -static INLINE BOOL update_read_4byte_unsigned(STREAM* s, UINT32* value) +static INLINE BOOL update_read_4byte_unsigned(wStream* s, UINT32* value) { BYTE byte; BYTE count; @@ -308,7 +308,7 @@ static INLINE BOOL update_read_4byte_unsigned(STREAM* s, UINT32* value) return TRUE; } -static INLINE BOOL update_read_delta(STREAM* s, INT32* value) +static INLINE BOOL update_read_delta(wStream* s, INT32* value) { BYTE byte; @@ -331,7 +331,7 @@ static INLINE BOOL update_read_delta(STREAM* s, INT32* value) return TRUE; } -static INLINE void update_read_glyph_delta(STREAM* s, UINT16* value) +static INLINE void update_read_glyph_delta(wStream* s, UINT16* value) { BYTE byte; @@ -343,7 +343,7 @@ static INLINE void update_read_glyph_delta(STREAM* s, UINT16* value) *value = (byte & 0x3F); } -static INLINE void update_seek_glyph_delta(STREAM* s) +static INLINE void update_seek_glyph_delta(wStream* s) { BYTE byte; @@ -353,7 +353,7 @@ static INLINE void update_seek_glyph_delta(STREAM* s) stream_seek_BYTE(s); } -static INLINE BOOL update_read_brush(STREAM* s, rdpBrush* brush, BYTE fieldFlags) +static INLINE BOOL update_read_brush(wStream* s, rdpBrush* brush, BYTE fieldFlags) { if (fieldFlags & ORDER_FIELD_01) { @@ -410,7 +410,7 @@ static INLINE BOOL update_read_brush(STREAM* s, rdpBrush* brush, BYTE fieldFlags return TRUE; } -static INLINE BOOL update_read_delta_rects(STREAM* s, DELTA_RECT* rectangles, int number) +static INLINE BOOL update_read_delta_rects(wStream* s, DELTA_RECT* rectangles, int number) { int i; BYTE flags = 0; @@ -464,7 +464,7 @@ static INLINE BOOL update_read_delta_rects(STREAM* s, DELTA_RECT* rectangles, in return TRUE; } -static INLINE BOOL update_read_delta_points(STREAM* s, DELTA_POINT* points, int number, INT16 x, INT16 y) +static INLINE BOOL update_read_delta_points(wStream* s, DELTA_POINT* points, int number, INT16 x, INT16 y) { int i; BYTE flags = 0; @@ -502,7 +502,7 @@ static INLINE BOOL update_read_delta_points(STREAM* s, DELTA_POINT* points, int if (orderInfo->fieldFlags & (1 << (NO-1))) \ { \ if (stream_get_left(s) < 1) {\ - printf("%s: error reading %s\n", __FUNCTION__, #TARGET); \ + fprintf(stderr, "%s: error reading %s\n", __FUNCTION__, #TARGET); \ return FALSE; \ } \ stream_read_BYTE(s, TARGET); \ @@ -514,7 +514,7 @@ static INLINE BOOL update_read_delta_points(STREAM* s, DELTA_POINT* points, int if (orderInfo->fieldFlags & (1 << (NO-1))) \ { \ if (stream_get_left(s) < 2) { \ - printf("%s: error reading %s or %s\n", __FUNCTION__, #TARGET1, #TARGET2); \ + fprintf(stderr, "%s: error reading %s or %s\n", __FUNCTION__, #TARGET1, #TARGET2); \ return FALSE; \ } \ stream_read_BYTE(s, TARGET1); \ @@ -527,7 +527,7 @@ static INLINE BOOL update_read_delta_points(STREAM* s, DELTA_POINT* points, int if (orderInfo->fieldFlags & (1 << (NO-1))) \ { \ if (stream_get_left(s) < 2) { \ - printf("%s: error reading %s\n", __FUNCTION__, #TARGET); \ + fprintf(stderr, "%s: error reading %s\n", __FUNCTION__, #TARGET); \ return FALSE; \ } \ stream_read_UINT16(s, TARGET); \ @@ -538,7 +538,7 @@ static INLINE BOOL update_read_delta_points(STREAM* s, DELTA_POINT* points, int if (orderInfo->fieldFlags & (1 << (NO-1))) \ { \ if (stream_get_left(s) < 4) { \ - printf("%s: error reading %s\n", __FUNCTION__, #TARGET); \ + fprintf(stderr, "%s: error reading %s\n", __FUNCTION__, #TARGET); \ return FALSE; \ } \ stream_read_UINT32(s, TARGET); \ @@ -548,14 +548,14 @@ static INLINE BOOL update_read_delta_points(STREAM* s, DELTA_POINT* points, int #define ORDER_FIELD_COORD(NO, TARGET) \ do { \ if ((orderInfo->fieldFlags & (1 << (NO-1))) && !update_read_coord(s, &TARGET, orderInfo->deltaCoordinates)) { \ - printf("%s: error reading %s\n", __FUNCTION__, #TARGET); \ + fprintf(stderr, "%s: error reading %s\n", __FUNCTION__, #TARGET); \ return FALSE; \ } \ } while(0) #define ORDER_FIELD_COLOR(NO, TARGET) \ do { \ if ((orderInfo->fieldFlags & (1 << (NO-1))) && !update_read_color(s, &TARGET)) { \ - printf("%s: error reading %s\n", __FUNCTION__, #TARGET); \ + fprintf(stderr, "%s: error reading %s\n", __FUNCTION__, #TARGET); \ return FALSE; \ } \ } while(0) @@ -564,19 +564,19 @@ static INLINE BOOL update_read_delta_points(STREAM* s, DELTA_POINT* points, int #define FIELD_SKIP_BUFFER16(s, TARGET_LEN) \ do { \ if (stream_get_left(s) < 2) {\ - printf("%s: error reading length %s\n", __FUNCTION__, #TARGET_LEN); \ + fprintf(stderr, "%s: error reading length %s\n", __FUNCTION__, #TARGET_LEN); \ return FALSE; \ }\ stream_read_UINT16(s, TARGET_LEN); \ if (!stream_skip(s, TARGET_LEN)) { \ - printf("%s: error skipping %d bytes\n", __FUNCTION__, TARGET_LEN); \ + fprintf(stderr, "%s: error skipping %d bytes\n", __FUNCTION__, TARGET_LEN); \ return FALSE; \ } \ } while(0) /* Primary Drawing Orders */ -BOOL update_read_dstblt_order(STREAM* s, ORDER_INFO* orderInfo, DSTBLT_ORDER* dstblt) +BOOL update_read_dstblt_order(wStream* s, ORDER_INFO* orderInfo, DSTBLT_ORDER* dstblt) { ORDER_FIELD_COORD(1, dstblt->nLeftRect); ORDER_FIELD_COORD(2, dstblt->nTopRect); @@ -586,7 +586,7 @@ BOOL update_read_dstblt_order(STREAM* s, ORDER_INFO* orderInfo, DSTBLT_ORDER* ds return TRUE; } -BOOL update_read_patblt_order(STREAM* s, ORDER_INFO* orderInfo, PATBLT_ORDER* patblt) +BOOL update_read_patblt_order(wStream* s, ORDER_INFO* orderInfo, PATBLT_ORDER* patblt) { ORDER_FIELD_COORD(1, patblt->nLeftRect); ORDER_FIELD_COORD(2, patblt->nTopRect); @@ -598,7 +598,7 @@ BOOL update_read_patblt_order(STREAM* s, ORDER_INFO* orderInfo, PATBLT_ORDER* pa return update_read_brush(s, &patblt->brush, orderInfo->fieldFlags >> 7); } -BOOL update_read_scrblt_order(STREAM* s, ORDER_INFO* orderInfo, SCRBLT_ORDER* scrblt) +BOOL update_read_scrblt_order(wStream* s, ORDER_INFO* orderInfo, SCRBLT_ORDER* scrblt) { ORDER_FIELD_COORD(1, scrblt->nLeftRect); ORDER_FIELD_COORD(2, scrblt->nTopRect); @@ -610,7 +610,7 @@ BOOL update_read_scrblt_order(STREAM* s, ORDER_INFO* orderInfo, SCRBLT_ORDER* sc return TRUE; } -BOOL update_read_opaque_rect_order(STREAM* s, ORDER_INFO* orderInfo, OPAQUE_RECT_ORDER* opaque_rect) +BOOL update_read_opaque_rect_order(wStream* s, ORDER_INFO* orderInfo, OPAQUE_RECT_ORDER* opaque_rect) { BYTE byte; @@ -643,7 +643,7 @@ BOOL update_read_opaque_rect_order(STREAM* s, ORDER_INFO* orderInfo, OPAQUE_RECT return TRUE; } -BOOL update_read_draw_nine_grid_order(STREAM* s, ORDER_INFO* orderInfo, DRAW_NINE_GRID_ORDER* draw_nine_grid) +BOOL update_read_draw_nine_grid_order(wStream* s, ORDER_INFO* orderInfo, DRAW_NINE_GRID_ORDER* draw_nine_grid) { ORDER_FIELD_COORD(1, draw_nine_grid->srcLeft); ORDER_FIELD_COORD(2, draw_nine_grid->srcTop); @@ -653,7 +653,7 @@ BOOL update_read_draw_nine_grid_order(STREAM* s, ORDER_INFO* orderInfo, DRAW_NIN return TRUE; } -BOOL update_read_multi_dstblt_order(STREAM* s, ORDER_INFO* orderInfo, MULTI_DSTBLT_ORDER* multi_dstblt) +BOOL update_read_multi_dstblt_order(wStream* s, ORDER_INFO* orderInfo, MULTI_DSTBLT_ORDER* multi_dstblt) { ORDER_FIELD_COORD(1, multi_dstblt->nLeftRect); ORDER_FIELD_COORD(2, multi_dstblt->nTopRect); @@ -672,7 +672,7 @@ BOOL update_read_multi_dstblt_order(STREAM* s, ORDER_INFO* orderInfo, MULTI_DSTB return TRUE; } -BOOL update_read_multi_patblt_order(STREAM* s, ORDER_INFO* orderInfo, MULTI_PATBLT_ORDER* multi_patblt) +BOOL update_read_multi_patblt_order(wStream* s, ORDER_INFO* orderInfo, MULTI_PATBLT_ORDER* multi_patblt) { ORDER_FIELD_COORD(1, multi_patblt->nLeftRect); ORDER_FIELD_COORD(2, multi_patblt->nTopRect); @@ -698,7 +698,7 @@ BOOL update_read_multi_patblt_order(STREAM* s, ORDER_INFO* orderInfo, MULTI_PATB return TRUE; } -BOOL update_read_multi_scrblt_order(STREAM* s, ORDER_INFO* orderInfo, MULTI_SCRBLT_ORDER* multi_scrblt) +BOOL update_read_multi_scrblt_order(wStream* s, ORDER_INFO* orderInfo, MULTI_SCRBLT_ORDER* multi_scrblt) { ORDER_FIELD_COORD(1, multi_scrblt->nLeftRect); ORDER_FIELD_COORD(2, multi_scrblt->nTopRect); @@ -719,7 +719,7 @@ BOOL update_read_multi_scrblt_order(STREAM* s, ORDER_INFO* orderInfo, MULTI_SCRB return TRUE; } -BOOL update_read_multi_opaque_rect_order(STREAM* s, ORDER_INFO* orderInfo, MULTI_OPAQUE_RECT_ORDER* multi_opaque_rect) +BOOL update_read_multi_opaque_rect_order(wStream* s, ORDER_INFO* orderInfo, MULTI_OPAQUE_RECT_ORDER* multi_opaque_rect) { BYTE byte; ORDER_FIELD_COORD(1, multi_opaque_rect->nLeftRect); @@ -764,7 +764,7 @@ BOOL update_read_multi_opaque_rect_order(STREAM* s, ORDER_INFO* orderInfo, MULTI } -BOOL update_read_multi_draw_nine_grid_order(STREAM* s, ORDER_INFO* orderInfo, MULTI_DRAW_NINE_GRID_ORDER* multi_draw_nine_grid) +BOOL update_read_multi_draw_nine_grid_order(wStream* s, ORDER_INFO* orderInfo, MULTI_DRAW_NINE_GRID_ORDER* multi_draw_nine_grid) { ORDER_FIELD_COORD(1, multi_draw_nine_grid->srcLeft); ORDER_FIELD_COORD(2, multi_draw_nine_grid->srcTop); @@ -780,7 +780,7 @@ BOOL update_read_multi_draw_nine_grid_order(STREAM* s, ORDER_INFO* orderInfo, MU return TRUE; } -BOOL update_read_line_to_order(STREAM* s, ORDER_INFO* orderInfo, LINE_TO_ORDER* line_to) +BOOL update_read_line_to_order(wStream* s, ORDER_INFO* orderInfo, LINE_TO_ORDER* line_to) { ORDER_FIELD_UINT16(1, line_to->backMode); ORDER_FIELD_COORD(2, line_to->nXStart); @@ -795,7 +795,7 @@ BOOL update_read_line_to_order(STREAM* s, ORDER_INFO* orderInfo, LINE_TO_ORDER* return TRUE; } -BOOL update_read_polyline_order(STREAM* s, ORDER_INFO* orderInfo, POLYLINE_ORDER* polyline) +BOOL update_read_polyline_order(wStream* s, ORDER_INFO* orderInfo, POLYLINE_ORDER* polyline) { UINT16 word; @@ -822,7 +822,7 @@ BOOL update_read_polyline_order(STREAM* s, ORDER_INFO* orderInfo, POLYLINE_ORDER return TRUE; } -BOOL update_read_memblt_order(STREAM* s, ORDER_INFO* orderInfo, MEMBLT_ORDER* memblt) +BOOL update_read_memblt_order(wStream* s, ORDER_INFO* orderInfo, MEMBLT_ORDER* memblt) { ORDER_FIELD_UINT16(1, memblt->cacheId); ORDER_FIELD_COORD(2, memblt->nLeftRect); @@ -839,7 +839,7 @@ BOOL update_read_memblt_order(STREAM* s, ORDER_INFO* orderInfo, MEMBLT_ORDER* me return TRUE; } -BOOL update_read_mem3blt_order(STREAM* s, ORDER_INFO* orderInfo, MEM3BLT_ORDER* mem3blt) +BOOL update_read_mem3blt_order(wStream* s, ORDER_INFO* orderInfo, MEM3BLT_ORDER* mem3blt) { ORDER_FIELD_UINT16(1, mem3blt->cacheId); ORDER_FIELD_COORD(2, mem3blt->nLeftRect); @@ -861,7 +861,7 @@ BOOL update_read_mem3blt_order(STREAM* s, ORDER_INFO* orderInfo, MEM3BLT_ORDER* return TRUE; } -BOOL update_read_save_bitmap_order(STREAM* s, ORDER_INFO* orderInfo, SAVE_BITMAP_ORDER* save_bitmap) +BOOL update_read_save_bitmap_order(wStream* s, ORDER_INFO* orderInfo, SAVE_BITMAP_ORDER* save_bitmap) { ORDER_FIELD_UINT32(1, save_bitmap->savedBitmapPosition); ORDER_FIELD_COORD(2, save_bitmap->nLeftRect); @@ -872,7 +872,7 @@ BOOL update_read_save_bitmap_order(STREAM* s, ORDER_INFO* orderInfo, SAVE_BITMAP return TRUE; } -BOOL update_read_glyph_index_order(STREAM* s, ORDER_INFO* orderInfo, GLYPH_INDEX_ORDER* glyph_index) +BOOL update_read_glyph_index_order(wStream* s, ORDER_INFO* orderInfo, GLYPH_INDEX_ORDER* glyph_index) { ORDER_FIELD_BYTE(1, glyph_index->cacheId); ORDER_FIELD_BYTE(2, glyph_index->flAccel); @@ -903,13 +903,13 @@ BOOL update_read_glyph_index_order(STREAM* s, ORDER_INFO* orderInfo, GLYPH_INDEX if (stream_get_left(s) < glyph_index->cbData) return FALSE; - memcpy(glyph_index->data, s->p, glyph_index->cbData); + memcpy(glyph_index->data, s->pointer, glyph_index->cbData); stream_seek(s, glyph_index->cbData); } return TRUE; } -BOOL update_read_fast_index_order(STREAM* s, ORDER_INFO* orderInfo, FAST_INDEX_ORDER* fast_index) +BOOL update_read_fast_index_order(wStream* s, ORDER_INFO* orderInfo, FAST_INDEX_ORDER* fast_index) { ORDER_FIELD_BYTE(1, fast_index->cacheId); ORDER_FIELD_2BYTE(2, fast_index->ulCharInc, fast_index->flAccel); @@ -934,13 +934,13 @@ BOOL update_read_fast_index_order(STREAM* s, ORDER_INFO* orderInfo, FAST_INDEX_O if (stream_get_left(s) < fast_index->cbData) return FALSE; - memcpy(fast_index->data, s->p, fast_index->cbData); + memcpy(fast_index->data, s->pointer, fast_index->cbData); stream_seek(s, fast_index->cbData); } return TRUE; } -BOOL update_read_fast_glyph_order(STREAM* s, ORDER_INFO* orderInfo, FAST_GLYPH_ORDER* fast_glyph) +BOOL update_read_fast_glyph_order(wStream* s, ORDER_INFO* orderInfo, FAST_GLYPH_ORDER* fast_glyph) { BYTE* phold; GLYPH_DATA_V2* glyph; @@ -970,8 +970,8 @@ BOOL update_read_fast_glyph_order(STREAM* s, ORDER_INFO* orderInfo, FAST_GLYPH_O if (stream_get_left(s) < fast_glyph->cbData) return FALSE; - memcpy(fast_glyph->data, s->p, fast_glyph->cbData); - phold = s->p; + memcpy(fast_glyph->data, s->pointer, fast_glyph->cbData); + phold = s->pointer; if (!stream_skip(s, 1)) return FALSE; @@ -998,12 +998,12 @@ BOOL update_read_fast_glyph_order(STREAM* s, ORDER_INFO* orderInfo, FAST_GLYPH_O stream_read(s, glyph->aj, glyph->cb); } - s->p = phold + fast_glyph->cbData; + s->pointer = phold + fast_glyph->cbData; } return TRUE; } -BOOL update_read_polygon_sc_order(STREAM* s, ORDER_INFO* orderInfo, POLYGON_SC_ORDER* polygon_sc) +BOOL update_read_polygon_sc_order(wStream* s, ORDER_INFO* orderInfo, POLYGON_SC_ORDER* polygon_sc) { ORDER_FIELD_COORD(1, polygon_sc->xStart); ORDER_FIELD_COORD(2, polygon_sc->yStart); @@ -1028,7 +1028,7 @@ BOOL update_read_polygon_sc_order(STREAM* s, ORDER_INFO* orderInfo, POLYGON_SC_O return TRUE; } -BOOL update_read_polygon_cb_order(STREAM* s, ORDER_INFO* orderInfo, POLYGON_CB_ORDER* polygon_cb) +BOOL update_read_polygon_cb_order(wStream* s, ORDER_INFO* orderInfo, POLYGON_CB_ORDER* polygon_cb) { ORDER_FIELD_COORD(1, polygon_cb->xStart); ORDER_FIELD_COORD(2, polygon_cb->yStart); @@ -1062,7 +1062,7 @@ BOOL update_read_polygon_cb_order(STREAM* s, ORDER_INFO* orderInfo, POLYGON_CB_O return TRUE; } -BOOL update_read_ellipse_sc_order(STREAM* s, ORDER_INFO* orderInfo, ELLIPSE_SC_ORDER* ellipse_sc) +BOOL update_read_ellipse_sc_order(wStream* s, ORDER_INFO* orderInfo, ELLIPSE_SC_ORDER* ellipse_sc) { ORDER_FIELD_COORD(1, ellipse_sc->leftRect); ORDER_FIELD_COORD(2, ellipse_sc->topRect); @@ -1074,7 +1074,7 @@ BOOL update_read_ellipse_sc_order(STREAM* s, ORDER_INFO* orderInfo, ELLIPSE_SC_O return TRUE; } -BOOL update_read_ellipse_cb_order(STREAM* s, ORDER_INFO* orderInfo, ELLIPSE_CB_ORDER* ellipse_cb) +BOOL update_read_ellipse_cb_order(wStream* s, ORDER_INFO* orderInfo, ELLIPSE_CB_ORDER* ellipse_cb) { ORDER_FIELD_COORD(1, ellipse_cb->leftRect); ORDER_FIELD_COORD(2, ellipse_cb->topRect); @@ -1089,7 +1089,7 @@ BOOL update_read_ellipse_cb_order(STREAM* s, ORDER_INFO* orderInfo, ELLIPSE_CB_O /* Secondary Drawing Orders */ -BOOL update_read_cache_bitmap_order(STREAM* s, CACHE_BITMAP_ORDER* cache_bitmap_order, BOOL compressed, UINT16 flags) +BOOL update_read_cache_bitmap_order(wStream* s, CACHE_BITMAP_ORDER* cache_bitmap_order, BOOL compressed, UINT16 flags) { if (stream_get_left(s) < 9) return FALSE; @@ -1130,7 +1130,7 @@ BOOL update_read_cache_bitmap_order(STREAM* s, CACHE_BITMAP_ORDER* cache_bitmap_ return TRUE; } -BOOL update_read_cache_bitmap_v2_order(STREAM* s, CACHE_BITMAP_V2_ORDER* cache_bitmap_v2_order, BOOL compressed, UINT16 flags) +BOOL update_read_cache_bitmap_v2_order(wStream* s, CACHE_BITMAP_V2_ORDER* cache_bitmap_v2_order, BOOL compressed, UINT16 flags) { BYTE bitsPerPixelId; @@ -1198,7 +1198,7 @@ BOOL update_read_cache_bitmap_v2_order(STREAM* s, CACHE_BITMAP_V2_ORDER* cache_b return TRUE; } -BOOL update_read_cache_bitmap_v3_order(STREAM* s, CACHE_BITMAP_V3_ORDER* cache_bitmap_v3_order, BOOL compressed, UINT16 flags) +BOOL update_read_cache_bitmap_v3_order(wStream* s, CACHE_BITMAP_V3_ORDER* cache_bitmap_v3_order, BOOL compressed, UINT16 flags) { BYTE bitsPerPixelId; BITMAP_DATA_EX* bitmapData; @@ -1236,7 +1236,7 @@ BOOL update_read_cache_bitmap_v3_order(STREAM* s, CACHE_BITMAP_V3_ORDER* cache_b return TRUE; } -BOOL update_read_cache_color_table_order(STREAM* s, CACHE_COLOR_TABLE_ORDER* cache_color_table_order, UINT16 flags) +BOOL update_read_cache_color_table_order(wStream* s, CACHE_COLOR_TABLE_ORDER* cache_color_table_order, UINT16 flags) { int i; UINT32* colorTable; @@ -1266,7 +1266,7 @@ BOOL update_read_cache_color_table_order(STREAM* s, CACHE_COLOR_TABLE_ORDER* cac return TRUE; } -BOOL update_read_cache_glyph_order(STREAM* s, CACHE_GLYPH_ORDER* cache_glyph_order, UINT16 flags) +BOOL update_read_cache_glyph_order(wStream* s, CACHE_GLYPH_ORDER* cache_glyph_order, UINT16 flags) { int i; INT16 lsi16; @@ -1311,7 +1311,7 @@ BOOL update_read_cache_glyph_order(STREAM* s, CACHE_GLYPH_ORDER* cache_glyph_ord return TRUE; } -BOOL update_read_cache_glyph_v2_order(STREAM* s, CACHE_GLYPH_V2_ORDER* cache_glyph_v2_order, UINT16 flags) +BOOL update_read_cache_glyph_v2_order(wStream* s, CACHE_GLYPH_V2_ORDER* cache_glyph_v2_order, UINT16 flags) { int i; GLYPH_DATA_V2* glyph; @@ -1355,7 +1355,7 @@ BOOL update_read_cache_glyph_v2_order(STREAM* s, CACHE_GLYPH_V2_ORDER* cache_gly return TRUE; } -BOOL update_decompress_brush(STREAM* s, BYTE* output, BYTE bpp) +BOOL update_decompress_brush(wStream* s, BYTE* output, BYTE bpp) { int index; int x, y, k; @@ -1363,7 +1363,7 @@ BOOL update_decompress_brush(STREAM* s, BYTE* output, BYTE bpp) BYTE* palette; int bytesPerPixel; - palette = s->p + 16; + palette = s->pointer + 16; bytesPerPixel = ((bpp + 1) / 8); if (stream_get_left(s) < 16) // 64 / 4 @@ -1387,7 +1387,7 @@ BOOL update_decompress_brush(STREAM* s, BYTE* output, BYTE bpp) return TRUE; } -BOOL update_read_cache_brush_order(STREAM* s, CACHE_BRUSH_ORDER* cache_brush_order, UINT16 flags) +BOOL update_read_cache_brush_order(wStream* s, CACHE_BRUSH_ORDER* cache_brush_order, UINT16 flags) { int i; int size; @@ -1415,7 +1415,7 @@ BOOL update_read_cache_brush_order(STREAM* s, CACHE_BRUSH_ORDER* cache_brush_ord { if (cache_brush_order->length != 8) { - printf("incompatible 1bpp brush of length:%d\n", cache_brush_order->length); + fprintf(stderr, "incompatible 1bpp brush of length:%d\n", cache_brush_order->length); return TRUE; // should be FALSE ? } @@ -1464,7 +1464,7 @@ BOOL update_read_cache_brush_order(STREAM* s, CACHE_BRUSH_ORDER* cache_brush_ord /* Alternate Secondary Drawing Orders */ -BOOL update_read_create_offscreen_bitmap_order(STREAM* s, CREATE_OFFSCREEN_BITMAP_ORDER* create_offscreen_bitmap) +BOOL update_read_create_offscreen_bitmap_order(wStream* s, CREATE_OFFSCREEN_BITMAP_ORDER* create_offscreen_bitmap) { UINT16 flags; BOOL deleteListPresent; @@ -1508,7 +1508,7 @@ BOOL update_read_create_offscreen_bitmap_order(STREAM* s, CREATE_OFFSCREEN_BITMA return TRUE; } -BOOL update_read_switch_surface_order(STREAM* s, SWITCH_SURFACE_ORDER* switch_surface) +BOOL update_read_switch_surface_order(wStream* s, SWITCH_SURFACE_ORDER* switch_surface) { if (stream_get_left(s) < 2) return FALSE; @@ -1516,7 +1516,7 @@ BOOL update_read_switch_surface_order(STREAM* s, SWITCH_SURFACE_ORDER* switch_su return TRUE; } -BOOL update_read_create_nine_grid_bitmap_order(STREAM* s, CREATE_NINE_GRID_BITMAP_ORDER* create_nine_grid_bitmap) +BOOL update_read_create_nine_grid_bitmap_order(wStream* s, CREATE_NINE_GRID_BITMAP_ORDER* create_nine_grid_bitmap) { NINE_GRID_BITMAP_INFO* nineGridInfo; @@ -1535,7 +1535,7 @@ BOOL update_read_create_nine_grid_bitmap_order(STREAM* s, CREATE_NINE_GRID_BITMA return TRUE; } -BOOL update_read_frame_marker_order(STREAM* s, FRAME_MARKER_ORDER* frame_marker) +BOOL update_read_frame_marker_order(wStream* s, FRAME_MARKER_ORDER* frame_marker) { if (stream_get_left(s) < 4) return FALSE; @@ -1543,7 +1543,7 @@ BOOL update_read_frame_marker_order(STREAM* s, FRAME_MARKER_ORDER* frame_marker) return TRUE; } -BOOL update_read_stream_bitmap_first_order(STREAM* s, STREAM_BITMAP_FIRST_ORDER* stream_bitmap_first) +BOOL update_read_stream_bitmap_first_order(wStream* s, STREAM_BITMAP_FIRST_ORDER* stream_bitmap_first) { if (stream_get_left(s) < 10) // 8 + 2 at least return FALSE; @@ -1567,7 +1567,7 @@ BOOL update_read_stream_bitmap_first_order(STREAM* s, STREAM_BITMAP_FIRST_ORDER* return TRUE; } -BOOL update_read_stream_bitmap_next_order(STREAM* s, STREAM_BITMAP_NEXT_ORDER* stream_bitmap_next) +BOOL update_read_stream_bitmap_next_order(wStream* s, STREAM_BITMAP_NEXT_ORDER* stream_bitmap_next) { if (stream_get_left(s) < 5) return FALSE; @@ -1577,7 +1577,7 @@ BOOL update_read_stream_bitmap_next_order(STREAM* s, STREAM_BITMAP_NEXT_ORDER* s return TRUE; } -BOOL update_read_draw_gdiplus_first_order(STREAM* s, DRAW_GDIPLUS_FIRST_ORDER* draw_gdiplus_first) +BOOL update_read_draw_gdiplus_first_order(wStream* s, DRAW_GDIPLUS_FIRST_ORDER* draw_gdiplus_first) { if (stream_get_left(s) < 11) return FALSE; @@ -1589,7 +1589,7 @@ BOOL update_read_draw_gdiplus_first_order(STREAM* s, DRAW_GDIPLUS_FIRST_ORDER* d return stream_skip(s, draw_gdiplus_first->cbSize); /* emfRecords */ } -BOOL update_read_draw_gdiplus_next_order(STREAM* s, DRAW_GDIPLUS_NEXT_ORDER* draw_gdiplus_next) +BOOL update_read_draw_gdiplus_next_order(wStream* s, DRAW_GDIPLUS_NEXT_ORDER* draw_gdiplus_next) { if (stream_get_left(s) < 3) return FALSE; @@ -1598,7 +1598,7 @@ BOOL update_read_draw_gdiplus_next_order(STREAM* s, DRAW_GDIPLUS_NEXT_ORDER* dra return TRUE; } -BOOL update_read_draw_gdiplus_end_order(STREAM* s, DRAW_GDIPLUS_END_ORDER* draw_gdiplus_end) +BOOL update_read_draw_gdiplus_end_order(wStream* s, DRAW_GDIPLUS_END_ORDER* draw_gdiplus_end) { if (stream_get_left(s) < 11) return FALSE; @@ -1610,7 +1610,7 @@ BOOL update_read_draw_gdiplus_end_order(STREAM* s, DRAW_GDIPLUS_END_ORDER* draw_ return stream_skip(s, draw_gdiplus_end->cbSize); /* emfRecords */ } -BOOL update_read_draw_gdiplus_cache_first_order(STREAM* s, DRAW_GDIPLUS_CACHE_FIRST_ORDER* draw_gdiplus_cache_first) +BOOL update_read_draw_gdiplus_cache_first_order(wStream* s, DRAW_GDIPLUS_CACHE_FIRST_ORDER* draw_gdiplus_cache_first) { if (stream_get_left(s) < 11) return FALSE; @@ -1623,7 +1623,7 @@ BOOL update_read_draw_gdiplus_cache_first_order(STREAM* s, DRAW_GDIPLUS_CACHE_FI return stream_skip(s, draw_gdiplus_cache_first->cbSize); /* emfRecords */ } -BOOL update_read_draw_gdiplus_cache_next_order(STREAM* s, DRAW_GDIPLUS_CACHE_NEXT_ORDER* draw_gdiplus_cache_next) +BOOL update_read_draw_gdiplus_cache_next_order(wStream* s, DRAW_GDIPLUS_CACHE_NEXT_ORDER* draw_gdiplus_cache_next) { if (stream_get_left(s) < 7) return FALSE; @@ -1635,7 +1635,7 @@ BOOL update_read_draw_gdiplus_cache_next_order(STREAM* s, DRAW_GDIPLUS_CACHE_NEX } -BOOL update_read_draw_gdiplus_cache_end_order(STREAM* s, DRAW_GDIPLUS_CACHE_END_ORDER* draw_gdiplus_cache_end) +BOOL update_read_draw_gdiplus_cache_end_order(wStream* s, DRAW_GDIPLUS_CACHE_END_ORDER* draw_gdiplus_cache_end) { if (stream_get_left(s) < 11) return FALSE; @@ -1648,7 +1648,7 @@ BOOL update_read_draw_gdiplus_cache_end_order(STREAM* s, DRAW_GDIPLUS_CACHE_END_ return stream_skip(s, draw_gdiplus_cache_end->cbSize); /* emfRecords */ } -BOOL update_read_field_flags(STREAM* s, UINT32* fieldFlags, BYTE flags, BYTE fieldBytes) +BOOL update_read_field_flags(wStream* s, UINT32* fieldFlags, BYTE flags, BYTE fieldBytes) { int i; BYTE byte; @@ -1676,7 +1676,7 @@ BOOL update_read_field_flags(STREAM* s, UINT32* fieldFlags, BYTE flags, BYTE fie return TRUE; } -BOOL update_read_bounds(STREAM* s, rdpBounds* bounds) +BOOL update_read_bounds(wStream* s, rdpBounds* bounds) { BYTE flags; @@ -1730,7 +1730,7 @@ BOOL update_read_bounds(STREAM* s, rdpBounds* bounds) return TRUE; } -BOOL update_recv_primary_order(rdpUpdate* update, STREAM* s, BYTE flags) +BOOL update_recv_primary_order(rdpUpdate* update, wStream* s, BYTE flags) { ORDER_INFO* orderInfo; rdpContext* context = update->context; @@ -1743,7 +1743,7 @@ BOOL update_recv_primary_order(rdpUpdate* update, STREAM* s, BYTE flags) if (orderInfo->orderType >= PRIMARY_DRAWING_ORDER_COUNT) { - printf("Invalid Primary Drawing Order (0x%02X)\n", orderInfo->orderType); + fprintf(stderr, "Invalid Primary Drawing Order (0x%02X)\n", orderInfo->orderType); return FALSE; } @@ -1765,7 +1765,7 @@ BOOL update_recv_primary_order(rdpUpdate* update, STREAM* s, BYTE flags) orderInfo->deltaCoordinates = (flags & ORDER_DELTA_COORDINATES) ? TRUE : FALSE; #ifdef WITH_DEBUG_ORDERS - printf("%s Primary Drawing Order (0x%02X)\n", PRIMARY_DRAWING_ORDER_STRINGS[orderInfo->orderType], orderInfo->orderType); + fprintf(stderr, "%s Primary Drawing Order (0x%02X)\n", PRIMARY_DRAWING_ORDER_STRINGS[orderInfo->orderType], orderInfo->orderType); #endif switch (orderInfo->orderType) @@ -1914,7 +1914,7 @@ BOOL update_recv_primary_order(rdpUpdate* update, STREAM* s, BYTE flags) return TRUE; } -BOOL update_recv_secondary_order(rdpUpdate* update, STREAM* s, BYTE flags) +BOOL update_recv_secondary_order(rdpUpdate* update, wStream* s, BYTE flags) { BYTE* next; BYTE orderType; @@ -1929,13 +1929,13 @@ BOOL update_recv_secondary_order(rdpUpdate* update, STREAM* s, BYTE flags) stream_read_UINT16(s, extraFlags); /* extraFlags (2 bytes) */ stream_read_BYTE(s, orderType); /* orderType (1 byte) */ - next = s->p + ((INT16) orderLength) + 7; + next = s->pointer + ((INT16) orderLength) + 7; #ifdef WITH_DEBUG_ORDERS if (orderType < SECONDARY_DRAWING_ORDER_COUNT) - printf("%s Secondary Drawing Order (0x%02X)\n", SECONDARY_DRAWING_ORDER_STRINGS[orderType], orderType); + fprintf(stderr, "%s Secondary Drawing Order (0x%02X)\n", SECONDARY_DRAWING_ORDER_STRINGS[orderType], orderType); else - printf("Unknown Secondary Drawing Order (0x%02X)\n", orderType); + fprintf(stderr, "Unknown Secondary Drawing Order (0x%02X)\n", orderType); #endif switch (orderType) @@ -2001,11 +2001,11 @@ BOOL update_recv_secondary_order(rdpUpdate* update, STREAM* s, BYTE flags) break; } - s->p = next; + s->pointer = next; return TRUE; } -BOOL update_recv_altsec_order(rdpUpdate* update, STREAM* s, BYTE flags) +BOOL update_recv_altsec_order(rdpUpdate* update, wStream* s, BYTE flags) { BYTE orderType; rdpContext* context = update->context; @@ -2015,9 +2015,9 @@ BOOL update_recv_altsec_order(rdpUpdate* update, STREAM* s, BYTE flags) #ifdef WITH_DEBUG_ORDERS if (orderType < ALTSEC_DRAWING_ORDER_COUNT) - printf("%s Alternate Secondary Drawing Order (0x%02X)\n", ALTSEC_DRAWING_ORDER_STRINGS[orderType], orderType); + fprintf(stderr, "%s Alternate Secondary Drawing Order (0x%02X)\n", ALTSEC_DRAWING_ORDER_STRINGS[orderType], orderType); else - printf("Unknown Alternate Secondary Drawing Order: 0x%02X\n", orderType); + fprintf(stderr, "Unknown Alternate Secondary Drawing Order: 0x%02X\n", orderType); #endif switch (orderType) @@ -2107,7 +2107,7 @@ BOOL update_recv_altsec_order(rdpUpdate* update, STREAM* s, BYTE flags) return TRUE; } -BOOL update_recv_order(rdpUpdate* update, STREAM* s) +BOOL update_recv_order(rdpUpdate* update, wStream* s) { BYTE controlFlags; diff --git a/libfreerdp/core/orders.h b/libfreerdp/core/orders.h index 555b58f7c..d8f807394 100644 --- a/libfreerdp/core/orders.h +++ b/libfreerdp/core/orders.h @@ -21,9 +21,11 @@ #define __ORDERS_H #include "rdp.h" + #include <freerdp/types.h> #include <freerdp/update.h> -#include <freerdp/utils/stream.h> + +#include <winpr/stream.h> /* Order Control Flags */ #define ORDER_STANDARD 0x01 @@ -184,50 +186,50 @@ #define CG_GLYPH_UNICODE_PRESENT 0x0010 -BOOL update_recv_order(rdpUpdate* update, STREAM* s); +BOOL update_recv_order(rdpUpdate* update, wStream* s); -BOOL update_read_dstblt_order(STREAM* s, ORDER_INFO* orderInfo, DSTBLT_ORDER* dstblt); -BOOL update_read_patblt_order(STREAM* s, ORDER_INFO* orderInfo, PATBLT_ORDER* patblt); -BOOL update_read_scrblt_order(STREAM* s, ORDER_INFO* orderInfo, SCRBLT_ORDER* scrblt); -BOOL update_read_opaque_rect_order(STREAM* s, ORDER_INFO* orderInfo, OPAQUE_RECT_ORDER* opaque_rect); -BOOL update_read_draw_nine_grid_order(STREAM* s, ORDER_INFO* orderInfo, DRAW_NINE_GRID_ORDER* draw_nine_grid); -BOOL update_read_multi_dstblt_order(STREAM* s, ORDER_INFO* orderInfo, MULTI_DSTBLT_ORDER* multi_dstblt); -BOOL update_read_multi_patblt_order(STREAM* s, ORDER_INFO* orderInfo, MULTI_PATBLT_ORDER* multi_patblt); -BOOL update_read_multi_scrblt_order(STREAM* s, ORDER_INFO* orderInfo, MULTI_SCRBLT_ORDER* multi_scrblt); -BOOL update_read_multi_opaque_rect_order(STREAM* s, ORDER_INFO* orderInfo, MULTI_OPAQUE_RECT_ORDER* multi_opaque_rect); -BOOL update_read_multi_draw_nine_grid_order(STREAM* s, ORDER_INFO* orderInfo, MULTI_DRAW_NINE_GRID_ORDER* multi_draw_nine_grid); -BOOL update_read_line_to_order(STREAM* s, ORDER_INFO* orderInfo, LINE_TO_ORDER* line_to); -BOOL update_read_polyline_order(STREAM* s, ORDER_INFO* orderInfo, POLYLINE_ORDER* polyline); -BOOL update_read_memblt_order(STREAM* s, ORDER_INFO* orderInfo, MEMBLT_ORDER* memblt); -BOOL update_read_mem3blt_order(STREAM* s, ORDER_INFO* orderInfo, MEM3BLT_ORDER* mem3blt); -BOOL update_read_save_bitmap_order(STREAM* s, ORDER_INFO* orderInfo, SAVE_BITMAP_ORDER* save_bitmap); -BOOL update_read_glyph_index_order(STREAM* s, ORDER_INFO* orderInfo, GLYPH_INDEX_ORDER* glyph_index); -BOOL update_read_fast_index_order(STREAM* s, ORDER_INFO* orderInfo, FAST_INDEX_ORDER* fast_index); -BOOL update_read_fast_glyph_order(STREAM* s, ORDER_INFO* orderInfo, FAST_GLYPH_ORDER* fast_glyph); -BOOL update_read_polygon_sc_order(STREAM* s, ORDER_INFO* orderInfo, POLYGON_SC_ORDER* polygon_sc); -BOOL update_read_polygon_cb_order(STREAM* s, ORDER_INFO* orderInfo, POLYGON_CB_ORDER* polygon_cb); -BOOL update_read_ellipse_sc_order(STREAM* s, ORDER_INFO* orderInfo, ELLIPSE_SC_ORDER* ellipse_sc); -BOOL update_read_ellipse_cb_order(STREAM* s, ORDER_INFO* orderInfo, ELLIPSE_CB_ORDER* ellipse_cb); +BOOL update_read_dstblt_order(wStream* s, ORDER_INFO* orderInfo, DSTBLT_ORDER* dstblt); +BOOL update_read_patblt_order(wStream* s, ORDER_INFO* orderInfo, PATBLT_ORDER* patblt); +BOOL update_read_scrblt_order(wStream* s, ORDER_INFO* orderInfo, SCRBLT_ORDER* scrblt); +BOOL update_read_opaque_rect_order(wStream* s, ORDER_INFO* orderInfo, OPAQUE_RECT_ORDER* opaque_rect); +BOOL update_read_draw_nine_grid_order(wStream* s, ORDER_INFO* orderInfo, DRAW_NINE_GRID_ORDER* draw_nine_grid); +BOOL update_read_multi_dstblt_order(wStream* s, ORDER_INFO* orderInfo, MULTI_DSTBLT_ORDER* multi_dstblt); +BOOL update_read_multi_patblt_order(wStream* s, ORDER_INFO* orderInfo, MULTI_PATBLT_ORDER* multi_patblt); +BOOL update_read_multi_scrblt_order(wStream* s, ORDER_INFO* orderInfo, MULTI_SCRBLT_ORDER* multi_scrblt); +BOOL update_read_multi_opaque_rect_order(wStream* s, ORDER_INFO* orderInfo, MULTI_OPAQUE_RECT_ORDER* multi_opaque_rect); +BOOL update_read_multi_draw_nine_grid_order(wStream* s, ORDER_INFO* orderInfo, MULTI_DRAW_NINE_GRID_ORDER* multi_draw_nine_grid); +BOOL update_read_line_to_order(wStream* s, ORDER_INFO* orderInfo, LINE_TO_ORDER* line_to); +BOOL update_read_polyline_order(wStream* s, ORDER_INFO* orderInfo, POLYLINE_ORDER* polyline); +BOOL update_read_memblt_order(wStream* s, ORDER_INFO* orderInfo, MEMBLT_ORDER* memblt); +BOOL update_read_mem3blt_order(wStream* s, ORDER_INFO* orderInfo, MEM3BLT_ORDER* mem3blt); +BOOL update_read_save_bitmap_order(wStream* s, ORDER_INFO* orderInfo, SAVE_BITMAP_ORDER* save_bitmap); +BOOL update_read_glyph_index_order(wStream* s, ORDER_INFO* orderInfo, GLYPH_INDEX_ORDER* glyph_index); +BOOL update_read_fast_index_order(wStream* s, ORDER_INFO* orderInfo, FAST_INDEX_ORDER* fast_index); +BOOL update_read_fast_glyph_order(wStream* s, ORDER_INFO* orderInfo, FAST_GLYPH_ORDER* fast_glyph); +BOOL update_read_polygon_sc_order(wStream* s, ORDER_INFO* orderInfo, POLYGON_SC_ORDER* polygon_sc); +BOOL update_read_polygon_cb_order(wStream* s, ORDER_INFO* orderInfo, POLYGON_CB_ORDER* polygon_cb); +BOOL update_read_ellipse_sc_order(wStream* s, ORDER_INFO* orderInfo, ELLIPSE_SC_ORDER* ellipse_sc); +BOOL update_read_ellipse_cb_order(wStream* s, ORDER_INFO* orderInfo, ELLIPSE_CB_ORDER* ellipse_cb); -BOOL update_read_cache_bitmap_order(STREAM* s, CACHE_BITMAP_ORDER* cache_bitmap_order, BOOL compressed, UINT16 flags); -BOOL update_read_cache_bitmap_v2_order(STREAM* s, CACHE_BITMAP_V2_ORDER* cache_bitmap_v2_order, BOOL compressed, UINT16 flags); -BOOL update_read_cache_bitmap_v3_order(STREAM* s, CACHE_BITMAP_V3_ORDER* cache_bitmap_v3_order, BOOL compressed, UINT16 flags); -BOOL update_read_cache_color_table_order(STREAM* s, CACHE_COLOR_TABLE_ORDER* cache_color_table_order, UINT16 flags); -BOOL update_read_cache_glyph_order(STREAM* s, CACHE_GLYPH_ORDER* cache_glyph_order, UINT16 flags); -BOOL update_read_cache_glyph_v2_order(STREAM* s, CACHE_GLYPH_V2_ORDER* cache_glyph_v2_order, UINT16 flags); -BOOL update_read_cache_brush_order(STREAM* s, CACHE_BRUSH_ORDER* cache_brush_order, UINT16 flags); +BOOL update_read_cache_bitmap_order(wStream* s, CACHE_BITMAP_ORDER* cache_bitmap_order, BOOL compressed, UINT16 flags); +BOOL update_read_cache_bitmap_v2_order(wStream* s, CACHE_BITMAP_V2_ORDER* cache_bitmap_v2_order, BOOL compressed, UINT16 flags); +BOOL update_read_cache_bitmap_v3_order(wStream* s, CACHE_BITMAP_V3_ORDER* cache_bitmap_v3_order, BOOL compressed, UINT16 flags); +BOOL update_read_cache_color_table_order(wStream* s, CACHE_COLOR_TABLE_ORDER* cache_color_table_order, UINT16 flags); +BOOL update_read_cache_glyph_order(wStream* s, CACHE_GLYPH_ORDER* cache_glyph_order, UINT16 flags); +BOOL update_read_cache_glyph_v2_order(wStream* s, CACHE_GLYPH_V2_ORDER* cache_glyph_v2_order, UINT16 flags); +BOOL update_read_cache_brush_order(wStream* s, CACHE_BRUSH_ORDER* cache_brush_order, UINT16 flags); -BOOL update_read_create_offscreen_bitmap_order(STREAM* s, CREATE_OFFSCREEN_BITMAP_ORDER* create_offscreen_bitmap); -BOOL update_read_switch_surface_order(STREAM* s, SWITCH_SURFACE_ORDER* switch_surface); -BOOL update_read_create_nine_grid_bitmap_order(STREAM* s, CREATE_NINE_GRID_BITMAP_ORDER* create_nine_grid_bitmap); -BOOL update_read_frame_marker_order(STREAM* s, FRAME_MARKER_ORDER* frame_marker); -BOOL update_read_stream_bitmap_first_order(STREAM* s, STREAM_BITMAP_FIRST_ORDER* stream_bitmap_first); -BOOL update_read_stream_bitmap_next_order(STREAM* s, STREAM_BITMAP_NEXT_ORDER* stream_bitmap_next); -BOOL update_read_draw_gdiplus_first_order(STREAM* s, DRAW_GDIPLUS_FIRST_ORDER* draw_gdiplus_first); -BOOL update_read_draw_gdiplus_next_order(STREAM* s, DRAW_GDIPLUS_NEXT_ORDER* draw_gdiplus_next); -BOOL update_read_draw_gdiplus_end_order(STREAM* s, DRAW_GDIPLUS_END_ORDER* draw_gdiplus_end); -BOOL update_read_draw_gdiplus_cache_first_order(STREAM* s, DRAW_GDIPLUS_CACHE_FIRST_ORDER* draw_gdiplus_cache_first); -BOOL update_read_draw_gdiplus_cache_next_order(STREAM* s, DRAW_GDIPLUS_CACHE_NEXT_ORDER* draw_gdiplus_cache_next); -BOOL update_read_draw_gdiplus_cache_end_order(STREAM* s, DRAW_GDIPLUS_CACHE_END_ORDER* draw_gdiplus_cache_end); +BOOL update_read_create_offscreen_bitmap_order(wStream* s, CREATE_OFFSCREEN_BITMAP_ORDER* create_offscreen_bitmap); +BOOL update_read_switch_surface_order(wStream* s, SWITCH_SURFACE_ORDER* switch_surface); +BOOL update_read_create_nine_grid_bitmap_order(wStream* s, CREATE_NINE_GRID_BITMAP_ORDER* create_nine_grid_bitmap); +BOOL update_read_frame_marker_order(wStream* s, FRAME_MARKER_ORDER* frame_marker); +BOOL update_read_stream_bitmap_first_order(wStream* s, STREAM_BITMAP_FIRST_ORDER* stream_bitmap_first); +BOOL update_read_stream_bitmap_next_order(wStream* s, STREAM_BITMAP_NEXT_ORDER* stream_bitmap_next); +BOOL update_read_draw_gdiplus_first_order(wStream* s, DRAW_GDIPLUS_FIRST_ORDER* draw_gdiplus_first); +BOOL update_read_draw_gdiplus_next_order(wStream* s, DRAW_GDIPLUS_NEXT_ORDER* draw_gdiplus_next); +BOOL update_read_draw_gdiplus_end_order(wStream* s, DRAW_GDIPLUS_END_ORDER* draw_gdiplus_end); +BOOL update_read_draw_gdiplus_cache_first_order(wStream* s, DRAW_GDIPLUS_CACHE_FIRST_ORDER* draw_gdiplus_cache_first); +BOOL update_read_draw_gdiplus_cache_next_order(wStream* s, DRAW_GDIPLUS_CACHE_NEXT_ORDER* draw_gdiplus_cache_next); +BOOL update_read_draw_gdiplus_cache_end_order(wStream* s, DRAW_GDIPLUS_CACHE_END_ORDER* draw_gdiplus_cache_end); #endif /* __ORDERS_H */ diff --git a/libfreerdp/core/peer.c b/libfreerdp/core/peer.c index 88a296b57..daeefdf1e 100644 --- a/libfreerdp/core/peer.c +++ b/libfreerdp/core/peer.c @@ -68,7 +68,7 @@ static BOOL freerdp_peer_check_fds(freerdp_peer* client) return TRUE; } -static BOOL peer_recv_data_pdu(freerdp_peer* client, STREAM* s) +static BOOL peer_recv_data_pdu(freerdp_peer* client, wStream* s) { BYTE type; UINT16 length; @@ -151,14 +151,14 @@ static BOOL peer_recv_data_pdu(freerdp_peer* client, STREAM* s) break; default: - printf("Data PDU type %d\n", type); + fprintf(stderr, "Data PDU type %d\n", type); break; } return TRUE; } -static int peer_recv_tpkt_pdu(freerdp_peer* client, STREAM* s) +static int peer_recv_tpkt_pdu(freerdp_peer* client, wStream* s) { rdpRdp* rdp; UINT16 length; @@ -172,7 +172,7 @@ static int peer_recv_tpkt_pdu(freerdp_peer* client, STREAM* s) if (!rdp_read_header(rdp, s, &length, &channelId)) { - printf("Incorrect RDP header.\n"); + fprintf(stderr, "Incorrect RDP header.\n"); return -1; } @@ -185,7 +185,7 @@ static int peer_recv_tpkt_pdu(freerdp_peer* client, STREAM* s) { if (!rdp_decrypt(rdp, s, length - 4, securityFlags)) { - printf("rdp_decrypt failed\n"); + fprintf(stderr, "rdp_decrypt failed\n"); return -1; } } @@ -211,7 +211,7 @@ static int peer_recv_tpkt_pdu(freerdp_peer* client, STREAM* s) break; default: - printf("Client sent pduType %d\n", pduType); + fprintf(stderr, "Client sent pduType %d\n", pduType); return -1; } } @@ -219,7 +219,7 @@ static int peer_recv_tpkt_pdu(freerdp_peer* client, STREAM* s) return 0; } -static int peer_recv_fastpath_pdu(freerdp_peer* client, STREAM* s) +static int peer_recv_fastpath_pdu(freerdp_peer* client, wStream* s) { rdpRdp* rdp; UINT16 length; @@ -234,7 +234,7 @@ static int peer_recv_fastpath_pdu(freerdp_peer* client, STREAM* s) if ((length == 0) || (length > stream_get_left(s))) { - printf("incorrect FastPath PDU header length %d\n", length); + fprintf(stderr, "incorrect FastPath PDU header length %d\n", length); return -1; } @@ -247,7 +247,7 @@ static int peer_recv_fastpath_pdu(freerdp_peer* client, STREAM* s) return fastpath_recv_inputs(fastpath, s); } -static int peer_recv_pdu(freerdp_peer* client, STREAM* s) +static int peer_recv_pdu(freerdp_peer* client, wStream* s) { if (tpkt_verify_header(s)) return peer_recv_tpkt_pdu(client, s); @@ -255,7 +255,7 @@ static int peer_recv_pdu(freerdp_peer* client, STREAM* s) return peer_recv_fastpath_pdu(client, s); } -static int peer_recv_callback(rdpTransport* transport, STREAM* s, void* extra) +static int peer_recv_callback(rdpTransport* transport, wStream* s, void* extra) { freerdp_peer* client = (freerdp_peer*) extra; rdpRdp* rdp = client->context->rdp; @@ -337,7 +337,7 @@ static int peer_recv_callback(rdpTransport* transport, STREAM* s, void* extra) break; default: - printf("Invalid state %d\n", rdp->state); + fprintf(stderr, "Invalid state %d\n", rdp->state); return -1; } diff --git a/libfreerdp/core/rdp.c b/libfreerdp/core/rdp.c index 7eecc6880..d5ca4e2f9 100644 --- a/libfreerdp/core/rdp.c +++ b/libfreerdp/core/rdp.c @@ -77,7 +77,7 @@ static const char* const DATA_PDU_TYPE_STRINGS[] = * @param flags security flags */ -BOOL rdp_read_security_header(STREAM* s, UINT16* flags) +BOOL rdp_read_security_header(wStream* s, UINT16* flags) { /* Basic Security Header */ if(stream_get_left(s) < 4) @@ -94,14 +94,14 @@ BOOL rdp_read_security_header(STREAM* s, UINT16* flags) * @param flags security flags */ -void rdp_write_security_header(STREAM* s, UINT16 flags) +void rdp_write_security_header(wStream* s, UINT16 flags) { /* Basic Security Header */ stream_write_UINT16(s, flags); /* flags */ stream_write_UINT16(s, 0); /* flagsHi (unused) */ } -BOOL rdp_read_share_control_header(STREAM* s, UINT16* length, UINT16* type, UINT16* channel_id) +BOOL rdp_read_share_control_header(wStream* s, UINT16* length, UINT16* type, UINT16* channel_id) { if (stream_get_left(s) < 2) return FALSE; @@ -123,7 +123,7 @@ BOOL rdp_read_share_control_header(STREAM* s, UINT16* length, UINT16* type, UINT return TRUE; } -void rdp_write_share_control_header(STREAM* s, UINT16 length, UINT16 type, UINT16 channel_id) +void rdp_write_share_control_header(wStream* s, UINT16 length, UINT16 type, UINT16 channel_id) { length -= RDP_PACKET_HEADER_MAX_LENGTH; @@ -133,7 +133,7 @@ void rdp_write_share_control_header(STREAM* s, UINT16 length, UINT16 type, UINT1 stream_write_UINT16(s, channel_id); /* pduSource */ } -BOOL rdp_read_share_data_header(STREAM* s, UINT16* length, BYTE* type, UINT32* share_id, +BOOL rdp_read_share_data_header(wStream* s, UINT16* length, BYTE* type, UINT32* share_id, BYTE *compressed_type, UINT16 *compressed_len) { if (stream_get_left(s) < 12) @@ -150,7 +150,7 @@ BOOL rdp_read_share_data_header(STREAM* s, UINT16* length, BYTE* type, UINT32* s return TRUE; } -void rdp_write_share_data_header(STREAM* s, UINT16 length, BYTE type, UINT32 share_id) +void rdp_write_share_data_header(wStream* s, UINT16 length, BYTE type, UINT32 share_id) { length -= RDP_PACKET_HEADER_MAX_LENGTH; length -= RDP_SHARE_CONTROL_HEADER_LENGTH; @@ -166,7 +166,7 @@ void rdp_write_share_data_header(STREAM* s, UINT16 length, BYTE type, UINT32 sha stream_write_UINT16(s, 0); /* compressedLength (2 bytes) */ } -static int rdp_security_stream_init(rdpRdp* rdp, STREAM* s) +static int rdp_security_stream_init(rdpRdp* rdp, wStream* s) { if (rdp->do_crypt) { @@ -194,9 +194,9 @@ static int rdp_security_stream_init(rdpRdp* rdp, STREAM* s) * @return */ -STREAM* rdp_send_stream_init(rdpRdp* rdp) +wStream* rdp_send_stream_init(rdpRdp* rdp) { - STREAM* s; + wStream* s; s = transport_send_stream_init(rdp->transport, 2048); stream_seek(s, RDP_PACKET_HEADER_MAX_LENGTH); @@ -205,9 +205,9 @@ STREAM* rdp_send_stream_init(rdpRdp* rdp) return s; } -STREAM* rdp_pdu_init(rdpRdp* rdp) +wStream* rdp_pdu_init(rdpRdp* rdp) { - STREAM* s; + wStream* s; s = transport_send_stream_init(rdp->transport, 2048); stream_seek(s, RDP_PACKET_HEADER_MAX_LENGTH); rdp_security_stream_init(rdp, s); @@ -215,9 +215,9 @@ STREAM* rdp_pdu_init(rdpRdp* rdp) return s; } -STREAM* rdp_data_pdu_init(rdpRdp* rdp) +wStream* rdp_data_pdu_init(rdpRdp* rdp) { - STREAM* s; + wStream* s; s = transport_send_stream_init(rdp->transport, 2048); stream_seek(s, RDP_PACKET_HEADER_MAX_LENGTH); rdp_security_stream_init(rdp, s); @@ -234,7 +234,7 @@ STREAM* rdp_data_pdu_init(rdpRdp* rdp) * @param channel_id channel id */ -BOOL rdp_read_header(rdpRdp* rdp, STREAM* s, UINT16* length, UINT16* channel_id) +BOOL rdp_read_header(rdpRdp* rdp, wStream* s, UINT16* length, UINT16* channel_id) { UINT16 initiator; enum DomainMCSPDU MCSPDU; @@ -284,7 +284,7 @@ BOOL rdp_read_header(rdpRdp* rdp, STREAM* s, UINT16* length, UINT16* channel_id) * @param channel_id channel id */ -void rdp_write_header(rdpRdp* rdp, STREAM* s, UINT16 length, UINT16 channel_id) +void rdp_write_header(rdpRdp* rdp, wStream* s, UINT16 length, UINT16 channel_id) { int body_length; enum DomainMCSPDU MCSPDU; @@ -316,7 +316,7 @@ void rdp_write_header(rdpRdp* rdp, STREAM* s, UINT16 length, UINT16 channel_id) stream_write_UINT16_be(s, length); /* userData (OCTET_STRING) */ } -static UINT32 rdp_security_stream_out(rdpRdp* rdp, STREAM* s, int length) +static UINT32 rdp_security_stream_out(rdpRdp* rdp, wStream* s, int length) { BYTE* data; UINT32 sec_flags; @@ -332,9 +332,9 @@ static UINT32 rdp_security_stream_out(rdpRdp* rdp, STREAM* s, int length) { if (rdp->settings->EncryptionMethods == ENCRYPTION_METHOD_FIPS) { - data = s->p + 12; + data = s->pointer + 12; - length = length - (data - s->data); + length = length - (data - s->buffer); stream_write_UINT16(s, 0x10); /* length */ stream_write_BYTE(s, 0x1); /* TSFIPS_VERSION 1*/ @@ -348,20 +348,20 @@ static UINT32 rdp_security_stream_out(rdpRdp* rdp, STREAM* s, int length) stream_write_BYTE(s, pad); - security_hmac_signature(data, length, s->p, rdp); + security_hmac_signature(data, length, s->pointer, rdp); stream_seek(s, 8); security_fips_encrypt(data, length + pad, rdp); } else { - data = s->p + 8; - length = length - (data - s->data); + data = s->pointer + 8; + length = length - (data - s->buffer); if (sec_flags & SEC_SECURE_CHECKSUM) - security_salted_mac_signature(rdp, data, length, TRUE, s->p); + security_salted_mac_signature(rdp, data, length, TRUE, s->pointer); else - security_mac_signature(rdp, data, length, s->p); + security_mac_signature(rdp, data, length, s->pointer); stream_seek(s, 8); - security_encrypt(s->p, length, rdp); + security_encrypt(s->pointer, length, rdp); } } @@ -401,7 +401,7 @@ static UINT32 rdp_get_sec_bytes(rdpRdp* rdp) * @param channel_id channel id */ -BOOL rdp_send(rdpRdp* rdp, STREAM* s, UINT16 channel_id) +BOOL rdp_send(rdpRdp* rdp, wStream* s, UINT16 channel_id) { UINT16 length; UINT32 sec_bytes; @@ -413,10 +413,10 @@ BOOL rdp_send(rdpRdp* rdp, STREAM* s, UINT16 channel_id) rdp_write_header(rdp, s, length, channel_id); sec_bytes = rdp_get_sec_bytes(rdp); - sec_hold = s->p; + sec_hold = s->pointer; stream_seek(s, sec_bytes); - s->p = sec_hold; + s->pointer = sec_hold; length += rdp_security_stream_out(rdp, s, length); stream_set_pos(s, length); @@ -427,7 +427,7 @@ BOOL rdp_send(rdpRdp* rdp, STREAM* s, UINT16 channel_id) return TRUE; } -BOOL rdp_send_pdu(rdpRdp* rdp, STREAM* s, UINT16 type, UINT16 channel_id) +BOOL rdp_send_pdu(rdpRdp* rdp, wStream* s, UINT16 type, UINT16 channel_id) { UINT16 length; UINT32 sec_bytes; @@ -439,12 +439,12 @@ BOOL rdp_send_pdu(rdpRdp* rdp, STREAM* s, UINT16 type, UINT16 channel_id) rdp_write_header(rdp, s, length, MCS_GLOBAL_CHANNEL_ID); sec_bytes = rdp_get_sec_bytes(rdp); - sec_hold = s->p; + sec_hold = s->pointer; stream_seek(s, sec_bytes); rdp_write_share_control_header(s, length - sec_bytes, type, channel_id); - s->p = sec_hold; + s->pointer = sec_hold; length += rdp_security_stream_out(rdp, s, length); stream_set_pos(s, length); @@ -454,7 +454,7 @@ BOOL rdp_send_pdu(rdpRdp* rdp, STREAM* s, UINT16 type, UINT16 channel_id) return TRUE; } -BOOL rdp_send_data_pdu(rdpRdp* rdp, STREAM* s, BYTE type, UINT16 channel_id) +BOOL rdp_send_data_pdu(rdpRdp* rdp, wStream* s, BYTE type, UINT16 channel_id) { UINT16 length; UINT32 sec_bytes; @@ -466,13 +466,13 @@ BOOL rdp_send_data_pdu(rdpRdp* rdp, STREAM* s, BYTE type, UINT16 channel_id) rdp_write_header(rdp, s, length, MCS_GLOBAL_CHANNEL_ID); sec_bytes = rdp_get_sec_bytes(rdp); - sec_hold = s->p; + sec_hold = s->pointer; stream_seek(s, sec_bytes); rdp_write_share_control_header(s, length - sec_bytes, PDU_TYPE_DATA, channel_id); rdp_write_share_data_header(s, length - sec_bytes, type, rdp->settings->ShareId); - s->p = sec_hold; + s->pointer = sec_hold; length += rdp_security_stream_out(rdp, s, length); stream_set_pos(s, length); @@ -482,7 +482,7 @@ BOOL rdp_send_data_pdu(rdpRdp* rdp, STREAM* s, BYTE type, UINT16 channel_id) return TRUE; } -BOOL rdp_recv_set_error_info_data_pdu(rdpRdp* rdp, STREAM* s) +BOOL rdp_recv_set_error_info_data_pdu(rdpRdp* rdp, wStream* s) { if (stream_get_left(s) < 4) return FALSE; @@ -495,7 +495,7 @@ BOOL rdp_recv_set_error_info_data_pdu(rdpRdp* rdp, STREAM* s) return TRUE; } -int rdp_recv_data_pdu(rdpRdp* rdp, STREAM* s) +int rdp_recv_data_pdu(rdpRdp* rdp, wStream* s) { BYTE type; UINT16 length; @@ -504,7 +504,7 @@ int rdp_recv_data_pdu(rdpRdp* rdp, STREAM* s) UINT16 compressed_len; UINT32 roff; UINT32 rlen; - STREAM* comp_stream; + wStream* comp_stream; if (!rdp_read_share_data_header(s, &length, &type, &share_id, &compressed_type, &compressed_len)) return -1; @@ -515,19 +515,19 @@ int rdp_recv_data_pdu(rdpRdp* rdp, STREAM* s) { if (stream_get_left(s) < compressed_len - 18) { - printf("decompress_rdp: not enough bytes for compressed_len=%d\n", compressed_len); + fprintf(stderr, "decompress_rdp: not enough bytes for compressed_len=%d\n", compressed_len); return -1; } - if (decompress_rdp(rdp->mppc_dec, s->p, compressed_len - 18, compressed_type, &roff, &rlen)) + if (decompress_rdp(rdp->mppc_dec, s->pointer, compressed_len - 18, compressed_type, &roff, &rlen)) { comp_stream = stream_new(0); - comp_stream->data = rdp->mppc_dec->history_buf + roff; - comp_stream->p = comp_stream->data; - comp_stream->size = rlen; + comp_stream->buffer = rdp->mppc_dec->history_buf + roff; + comp_stream->pointer = comp_stream->buffer; + comp_stream->capacity = rlen; } else { - printf("decompress_rdp() failed\n"); + fprintf(stderr, "decompress_rdp() failed\n"); return -1; } stream_seek(s, compressed_len - 18); @@ -642,7 +642,7 @@ int rdp_recv_data_pdu(rdpRdp* rdp, STREAM* s) return 0; } -BOOL rdp_recv_out_of_sequence_pdu(rdpRdp* rdp, STREAM* s) +BOOL rdp_recv_out_of_sequence_pdu(rdpRdp* rdp, wStream* s) { UINT16 type; UINT16 length; @@ -672,7 +672,7 @@ BOOL rdp_recv_out_of_sequence_pdu(rdpRdp* rdp, STREAM* s) * @param length int */ -BOOL rdp_decrypt(rdpRdp* rdp, STREAM* s, int length, UINT16 securityFlags) +BOOL rdp_decrypt(rdpRdp* rdp, wStream* s, int length, UINT16 securityFlags) { BYTE cmac[8]; BYTE wmac[8]; @@ -690,25 +690,25 @@ BOOL rdp_decrypt(rdpRdp* rdp, STREAM* s, int length, UINT16 securityFlags) stream_read_BYTE(s, version); /* 0x1 */ stream_read_BYTE(s, pad); - sig = s->p; + sig = s->pointer; stream_seek(s, 8); /* signature */ length -= 12; - if (!security_fips_decrypt(s->p, length, rdp)) + if (!security_fips_decrypt(s->pointer, length, rdp)) { - printf("FATAL: cannot decrypt\n"); + fprintf(stderr, "FATAL: cannot decrypt\n"); return FALSE; /* TODO */ } - if (!security_fips_check_signature(s->p, length - pad, sig, rdp)) + if (!security_fips_check_signature(s->pointer, length - pad, sig, rdp)) { - printf("FATAL: invalid packet signature\n"); + fprintf(stderr, "FATAL: invalid packet signature\n"); return FALSE; /* TODO */ } /* is this what needs adjusting? */ - s->size -= pad; + s->capacity -= pad; return TRUE; } @@ -717,17 +717,17 @@ BOOL rdp_decrypt(rdpRdp* rdp, STREAM* s, int length, UINT16 securityFlags) stream_read(s, wmac, sizeof(wmac)); length -= sizeof(wmac); - if (!security_decrypt(s->p, length, rdp)) + if (!security_decrypt(s->pointer, length, rdp)) return FALSE; if (securityFlags & SEC_SECURE_CHECKSUM) - security_salted_mac_signature(rdp, s->p, length, FALSE, cmac); + security_salted_mac_signature(rdp, s->pointer, length, FALSE, cmac); else - security_mac_signature(rdp, s->p, length, cmac); + security_mac_signature(rdp, s->pointer, length, cmac); if (memcmp(wmac, cmac, sizeof(wmac)) != 0) { - printf("WARNING: invalid packet signature\n"); + fprintf(stderr, "WARNING: invalid packet signature\n"); /* * Because Standard RDP Security is totally broken, * and cannot protect against MITM, don't treat signature @@ -747,7 +747,7 @@ BOOL rdp_decrypt(rdpRdp* rdp, STREAM* s, int length, UINT16 securityFlags) * @param s stream */ -static int rdp_recv_tpkt_pdu(rdpRdp* rdp, STREAM* s) +static int rdp_recv_tpkt_pdu(rdpRdp* rdp, wStream* s) { UINT16 length; UINT16 pduType; @@ -759,7 +759,7 @@ static int rdp_recv_tpkt_pdu(rdpRdp* rdp, STREAM* s) if (!rdp_read_header(rdp, s, &length, &channelId)) { - printf("Incorrect RDP header.\n"); + fprintf(stderr, "Incorrect RDP header.\n"); return -1; } @@ -772,7 +772,7 @@ static int rdp_recv_tpkt_pdu(rdpRdp* rdp, STREAM* s) { if (!rdp_decrypt(rdp, s, length - 4, securityFlags)) { - printf("rdp_decrypt failed\n"); + fprintf(stderr, "rdp_decrypt failed\n"); return -1; } } @@ -783,7 +783,7 @@ static int rdp_recv_tpkt_pdu(rdpRdp* rdp, STREAM* s) * [MS-RDPBCGR] 2.2.13.2.1 * - no share control header, nor the 2 byte pad */ - s->p -= 2; + s->pointer -= 2; rdp_recv_enhanced_security_redirection_packet(rdp, s); return -1; } @@ -812,7 +812,7 @@ static int rdp_recv_tpkt_pdu(rdpRdp* rdp, STREAM* s) case PDU_TYPE_DATA: if (rdp_recv_data_pdu(rdp, s) < 0) { - printf("rdp_recv_data_pdu failed\n"); + fprintf(stderr, "rdp_recv_data_pdu failed\n"); return -1; } break; @@ -828,7 +828,7 @@ static int rdp_recv_tpkt_pdu(rdpRdp* rdp, STREAM* s) break; default: - printf("incorrect PDU type: 0x%04X\n", pduType); + fprintf(stderr, "incorrect PDU type: 0x%04X\n", pduType); break; } stream_set_mark(s, nextp); @@ -838,7 +838,7 @@ static int rdp_recv_tpkt_pdu(rdpRdp* rdp, STREAM* s) return 0; } -static int rdp_recv_fastpath_pdu(rdpRdp* rdp, STREAM* s) +static int rdp_recv_fastpath_pdu(rdpRdp* rdp, wStream* s) { UINT16 length; rdpFastPath* fastpath; @@ -850,7 +850,7 @@ static int rdp_recv_fastpath_pdu(rdpRdp* rdp, STREAM* s) if ((length == 0) || (length > stream_get_left(s))) { - printf("incorrect FastPath PDU header length %d\n", length); + fprintf(stderr, "incorrect FastPath PDU header length %d\n", length); return -1; } @@ -865,7 +865,7 @@ static int rdp_recv_fastpath_pdu(rdpRdp* rdp, STREAM* s) return fastpath_recv_updates(rdp->fastpath, s); } -static int rdp_recv_pdu(rdpRdp* rdp, STREAM* s) +static int rdp_recv_pdu(rdpRdp* rdp, wStream* s) { if (tpkt_verify_header(s)) return rdp_recv_tpkt_pdu(rdp, s); @@ -880,7 +880,7 @@ static int rdp_recv_pdu(rdpRdp* rdp, STREAM* s) void rdp_recv(rdpRdp* rdp) { - STREAM* s; + wStream* s; s = transport_recv_stream_init(rdp->transport, 4096); transport_read(rdp->transport, s); @@ -888,7 +888,7 @@ void rdp_recv(rdpRdp* rdp) rdp_recv_pdu(rdp, s); } -static int rdp_recv_callback(rdpTransport* transport, STREAM* s, void* extra) +static int rdp_recv_callback(rdpTransport* transport, wStream* s, void* extra) { int status = 0; rdpRdp* rdp = (rdpRdp*) extra; @@ -931,7 +931,7 @@ static int rdp_recv_callback(rdpTransport* transport, STREAM* s, void* extra) break; default: - printf("Invalid state %d\n", rdp->state); + fprintf(stderr, "Invalid state %d\n", rdp->state); status = -1; break; } diff --git a/libfreerdp/core/rdp.h b/libfreerdp/core/rdp.h index 8a3522c82..a8128c2ee 100644 --- a/libfreerdp/core/rdp.h +++ b/libfreerdp/core/rdp.h @@ -44,10 +44,11 @@ #include <freerdp/freerdp.h> #include <freerdp/settings.h> #include <freerdp/utils/debug.h> -#include <freerdp/utils/stream.h> #include <freerdp/codec/mppc_dec.h> #include <freerdp/codec/mppc_enc.h> +#include <winpr/stream.h> + /* Security Header Flags */ #define SEC_EXCHANGE_PKT 0x0001 #define SEC_ENCRYPT 0x0008 @@ -157,35 +158,35 @@ struct rdp_rdp BOOL disconnect; }; -BOOL rdp_read_security_header(STREAM* s, UINT16* flags); -void rdp_write_security_header(STREAM* s, UINT16 flags); +BOOL rdp_read_security_header(wStream* s, UINT16* flags); +void rdp_write_security_header(wStream* s, UINT16 flags); -BOOL rdp_read_share_control_header(STREAM* s, UINT16* length, UINT16* type, UINT16* channel_id); -void rdp_write_share_control_header(STREAM* s, UINT16 length, UINT16 type, UINT16 channel_id); +BOOL rdp_read_share_control_header(wStream* s, UINT16* length, UINT16* type, UINT16* channel_id); +void rdp_write_share_control_header(wStream* s, UINT16 length, UINT16 type, UINT16 channel_id); -BOOL rdp_read_share_data_header(STREAM* s, UINT16* length, BYTE* type, UINT32* share_id, +BOOL rdp_read_share_data_header(wStream* s, UINT16* length, BYTE* type, UINT32* share_id, BYTE *compressed_type, UINT16 *compressed_len); -void rdp_write_share_data_header(STREAM* s, UINT16 length, BYTE type, UINT32 share_id); +void rdp_write_share_data_header(wStream* s, UINT16 length, BYTE type, UINT32 share_id); -STREAM* rdp_send_stream_init(rdpRdp* rdp); +wStream* rdp_send_stream_init(rdpRdp* rdp); -BOOL rdp_read_header(rdpRdp* rdp, STREAM* s, UINT16* length, UINT16* channel_id); -void rdp_write_header(rdpRdp* rdp, STREAM* s, UINT16 length, UINT16 channel_id); +BOOL rdp_read_header(rdpRdp* rdp, wStream* s, UINT16* length, UINT16* channel_id); +void rdp_write_header(rdpRdp* rdp, wStream* s, UINT16 length, UINT16 channel_id); -STREAM* rdp_pdu_init(rdpRdp* rdp); -BOOL rdp_send_pdu(rdpRdp* rdp, STREAM* s, UINT16 type, UINT16 channel_id); +wStream* rdp_pdu_init(rdpRdp* rdp); +BOOL rdp_send_pdu(rdpRdp* rdp, wStream* s, UINT16 type, UINT16 channel_id); -STREAM* rdp_data_pdu_init(rdpRdp* rdp); -BOOL rdp_send_data_pdu(rdpRdp* rdp, STREAM* s, BYTE type, UINT16 channel_id); -int rdp_recv_data_pdu(rdpRdp* rdp, STREAM* s); +wStream* rdp_data_pdu_init(rdpRdp* rdp); +BOOL rdp_send_data_pdu(rdpRdp* rdp, wStream* s, BYTE type, UINT16 channel_id); +int rdp_recv_data_pdu(rdpRdp* rdp, wStream* s); -BOOL rdp_send(rdpRdp* rdp, STREAM* s, UINT16 channel_id); +BOOL rdp_send(rdpRdp* rdp, wStream* s, UINT16 channel_id); void rdp_recv(rdpRdp* rdp); int rdp_send_channel_data(rdpRdp* rdp, int channel_id, BYTE* data, int size); -BOOL rdp_recv_out_of_sequence_pdu(rdpRdp* rdp, STREAM* s); +BOOL rdp_recv_out_of_sequence_pdu(rdpRdp* rdp, wStream* s); void rdp_set_blocking_mode(rdpRdp* rdp, BOOL blocking); int rdp_check_fds(rdpRdp* rdp); @@ -199,6 +200,6 @@ void rdp_free(rdpRdp* rdp); #define DEBUG_RDP(fmt, ...) DEBUG_NULL(fmt, ## __VA_ARGS__) #endif -BOOL rdp_decrypt(rdpRdp* rdp, STREAM* s, int length, UINT16 securityFlags); +BOOL rdp_decrypt(rdpRdp* rdp, wStream* s, int length, UINT16 securityFlags); #endif /* __RDP_H */ diff --git a/libfreerdp/core/redirection.c b/libfreerdp/core/redirection.c index 095bcdfd9..6ca3dac65 100644 --- a/libfreerdp/core/redirection.c +++ b/libfreerdp/core/redirection.c @@ -29,45 +29,72 @@ void rdp_print_redirection_flags(UINT32 flags) { - printf("redirectionFlags = {\n"); + fprintf(stderr, "redirectionFlags = {\n"); if (flags & LB_TARGET_NET_ADDRESS) - printf("\tLB_TARGET_NET_ADDRESS\n"); + fprintf(stderr, "\tLB_TARGET_NET_ADDRESS\n"); if (flags & LB_LOAD_BALANCE_INFO) - printf("\tLB_LOAD_BALANCE_INFO\n"); + fprintf(stderr, "\tLB_LOAD_BALANCE_INFO\n"); if (flags & LB_USERNAME) - printf("\tLB_USERNAME\n"); + fprintf(stderr, "\tLB_USERNAME\n"); if (flags & LB_DOMAIN) - printf("\tLB_DOMAIN\n"); + fprintf(stderr, "\tLB_DOMAIN\n"); if (flags & LB_PASSWORD) - printf("\tLB_PASSWORD\n"); + fprintf(stderr, "\tLB_PASSWORD\n"); if (flags & LB_DONTSTOREUSERNAME) - printf("\tLB_DONTSTOREUSERNAME\n"); + fprintf(stderr, "\tLB_DONTSTOREUSERNAME\n"); if (flags & LB_SMARTCARD_LOGON) - printf("\tLB_SMARTCARD_LOGON\n"); + fprintf(stderr, "\tLB_SMARTCARD_LOGON\n"); if (flags & LB_NOREDIRECT) - printf("\tLB_NOREDIRECT\n"); + fprintf(stderr, "\tLB_NOREDIRECT\n"); if (flags & LB_TARGET_FQDN) - printf("\tLB_TARGET_FQDN\n"); + fprintf(stderr, "\tLB_TARGET_FQDN\n"); if (flags & LB_TARGET_NETBIOS_NAME) - printf("\tLB_TARGET_NETBIOS_NAME\n"); + fprintf(stderr, "\tLB_TARGET_NETBIOS_NAME\n"); if (flags & LB_TARGET_NET_ADDRESSES) - printf("\tLB_TARGET_NET_ADDRESSES\n"); + fprintf(stderr, "\tLB_TARGET_NET_ADDRESSES\n"); if (flags & LB_CLIENT_TSV_URL) - printf("\tLB_CLIENT_TSV_URL\n"); + fprintf(stderr, "\tLB_CLIENT_TSV_URL\n"); if (flags & LB_SERVER_TSV_CAPABLE) - printf("\tLB_SERVER_TSV_CAPABLE\n"); + fprintf(stderr, "\tLB_SERVER_TSV_CAPABLE\n"); - printf("}\n"); + fprintf(stderr, "}\n"); } -BOOL rdp_recv_server_redirection_pdu(rdpRdp* rdp, STREAM* s) +BOOL rdp_string_read_length32(wStream* s, rdpString* string) +{ + if(stream_get_left(s) < 4) + return FALSE; + + stream_read_UINT32(s, string->length); + + if(stream_get_left(s) < string->length) + return FALSE; + + string->unicode = (char*) malloc(string->length); + stream_read(s, string->unicode, string->length); + + ConvertFromUnicode(CP_UTF8, 0, (WCHAR*) string->unicode, string->length / 2, &string->ascii, 0, NULL, NULL); + + return TRUE; +} + +void rdp_string_free(rdpString* string) +{ + if (string->unicode != NULL) + free(string->unicode); + + if (string->ascii != NULL) + free(string->ascii); +} + +BOOL rdp_recv_server_redirection_pdu(rdpRdp* rdp, wStream* s) { UINT16 flags; UINT16 length; rdpRedirection* redirection = rdp->redirection; - if(stream_get_left(s) < 12) + if (stream_get_left(s) < 12) return FALSE; stream_read_UINT16(s, flags); /* flags (2 bytes) */ stream_read_UINT16(s, length); /* length (2 bytes) */ @@ -82,17 +109,17 @@ BOOL rdp_recv_server_redirection_pdu(rdpRdp* rdp, STREAM* s) if (redirection->flags & LB_TARGET_NET_ADDRESS) { - if(!freerdp_string_read_length32(s, &redirection->targetNetAddress)) + if (!rdp_string_read_length32(s, &redirection->targetNetAddress)) return FALSE; DEBUG_REDIR("targetNetAddress: %s", redirection->targetNetAddress.ascii); } if (redirection->flags & LB_LOAD_BALANCE_INFO) { - if(stream_get_left(s) < 4) + if (stream_get_left(s) < 4) return FALSE; stream_read_UINT32(s, redirection->LoadBalanceInfoLength); - if(stream_get_left(s) < redirection->LoadBalanceInfoLength) + if (stream_get_left(s) < redirection->LoadBalanceInfoLength) return FALSE; redirection->LoadBalanceInfo = (BYTE*) malloc(redirection->LoadBalanceInfoLength); @@ -105,14 +132,14 @@ BOOL rdp_recv_server_redirection_pdu(rdpRdp* rdp, STREAM* s) if (redirection->flags & LB_USERNAME) { - if(!freerdp_string_read_length32(s, &redirection->username)) + if (!rdp_string_read_length32(s, &redirection->username)) return FALSE; DEBUG_REDIR("username: %s", redirection->username.ascii); } if (redirection->flags & LB_DOMAIN) { - if(!freerdp_string_read_length32(s, &redirection->domain)) + if (!rdp_string_read_length32(s, &redirection->domain)) return FALSE; DEBUG_REDIR("domain: %s", redirection->domain.ascii); } @@ -120,7 +147,7 @@ BOOL rdp_recv_server_redirection_pdu(rdpRdp* rdp, STREAM* s) if (redirection->flags & LB_PASSWORD) { /* Note: length (hopefully) includes double zero termination */ - if(stream_get_left(s) < 4) + if (stream_get_left(s) < 4) return FALSE; stream_read_UINT32(s, redirection->PasswordCookieLength); redirection->PasswordCookie = (BYTE*) malloc(redirection->PasswordCookieLength); @@ -134,21 +161,21 @@ BOOL rdp_recv_server_redirection_pdu(rdpRdp* rdp, STREAM* s) if (redirection->flags & LB_TARGET_FQDN) { - if(!freerdp_string_read_length32(s, &redirection->targetFQDN)) + if (!rdp_string_read_length32(s, &redirection->targetFQDN)) return FALSE; DEBUG_REDIR("targetFQDN: %s", redirection->targetFQDN.ascii); } if (redirection->flags & LB_TARGET_NETBIOS_NAME) { - if(!freerdp_string_read_length32(s, &redirection->targetNetBiosName)) + if (!rdp_string_read_length32(s, &redirection->targetNetBiosName)) return FALSE; DEBUG_REDIR("targetNetBiosName: %s", redirection->targetNetBiosName.ascii); } if (redirection->flags & LB_CLIENT_TSV_URL) { - if(!freerdp_string_read_length32(s, &redirection->tsvUrl)) + if (!rdp_string_read_length32(s, &redirection->tsvUrl)) return FALSE; DEBUG_REDIR("tsvUrl: %s", redirection->tsvUrl.ascii); } @@ -159,7 +186,7 @@ BOOL rdp_recv_server_redirection_pdu(rdpRdp* rdp, STREAM* s) UINT32 count; UINT32 targetNetAddressesLength; - if(stream_get_left(s) < 8) + if (stream_get_left(s) < 8) return FALSE; stream_read_UINT32(s, targetNetAddressesLength); @@ -171,7 +198,7 @@ BOOL rdp_recv_server_redirection_pdu(rdpRdp* rdp, STREAM* s) for (i = 0; i < (int) count; i++) { - if(!freerdp_string_read_length32(s, &redirection->targetNetAddresses[i])) + if (!rdp_string_read_length32(s, &redirection->targetNetAddresses[i])) return FALSE; DEBUG_REDIR("targetNetAddresses: %s", (&redirection->targetNetAddresses[i])->ascii); } @@ -186,12 +213,12 @@ BOOL rdp_recv_server_redirection_pdu(rdpRdp* rdp, STREAM* s) return rdp_client_redirect(rdp); } -BOOL rdp_recv_redirection_packet(rdpRdp* rdp, STREAM* s) +BOOL rdp_recv_redirection_packet(rdpRdp* rdp, wStream* s) { return rdp_recv_server_redirection_pdu(rdp, s); } -BOOL rdp_recv_enhanced_security_redirection_packet(rdpRdp* rdp, STREAM* s) +BOOL rdp_recv_enhanced_security_redirection_packet(rdpRdp* rdp, wStream* s) { return stream_skip(s, 2) && /* pad2Octets (2 bytes) */ rdp_recv_server_redirection_pdu(rdp, s) && @@ -216,12 +243,12 @@ void redirection_free(rdpRedirection* redirection) { if (redirection != NULL) { - freerdp_string_free(&redirection->tsvUrl); - freerdp_string_free(&redirection->username); - freerdp_string_free(&redirection->domain); - freerdp_string_free(&redirection->targetFQDN); - freerdp_string_free(&redirection->targetNetBiosName); - freerdp_string_free(&redirection->targetNetAddress); + rdp_string_free(&redirection->tsvUrl); + rdp_string_free(&redirection->username); + rdp_string_free(&redirection->domain); + rdp_string_free(&redirection->targetFQDN); + rdp_string_free(&redirection->targetNetBiosName); + rdp_string_free(&redirection->targetNetAddress); if (redirection->LoadBalanceInfo) free(redirection->LoadBalanceInfo); @@ -234,7 +261,7 @@ void redirection_free(rdpRedirection* redirection) int i; for (i = 0; i < (int) redirection->targetNetAddressesCount; i++) - freerdp_string_free(&redirection->targetNetAddresses[i]); + rdp_string_free(&redirection->targetNetAddresses[i]); free(redirection->targetNetAddresses); } diff --git a/libfreerdp/core/redirection.h b/libfreerdp/core/redirection.h index 62279984e..22bb2f15a 100644 --- a/libfreerdp/core/redirection.h +++ b/libfreerdp/core/redirection.h @@ -24,8 +24,16 @@ #include <freerdp/freerdp.h> #include <freerdp/utils/debug.h> -#include <freerdp/utils/stream.h> -#include <freerdp/utils/string.h> + +#include <winpr/stream.h> + +struct rdp_string +{ + char* ascii; + char* unicode; + UINT32 length; +}; +typedef struct rdp_string rdpString; struct rdp_redirection { @@ -46,8 +54,8 @@ struct rdp_redirection }; typedef struct rdp_redirection rdpRedirection; -BOOL rdp_recv_redirection_packet(rdpRdp* rdp, STREAM* s); -BOOL rdp_recv_enhanced_security_redirection_packet(rdpRdp* rdp, STREAM* s); +BOOL rdp_recv_redirection_packet(rdpRdp* rdp, wStream* s); +BOOL rdp_recv_enhanced_security_redirection_packet(rdpRdp* rdp, wStream* s); rdpRedirection* redirection_new(void); void redirection_free(rdpRedirection* redirection); diff --git a/libfreerdp/core/security.c b/libfreerdp/core/security.c index 83298fdd1..568452820 100644 --- a/libfreerdp/core/security.c +++ b/libfreerdp/core/security.c @@ -373,7 +373,7 @@ BOOL security_establish_keys(const BYTE* client_random, rdpRdp* rdp) BYTE client_encrypt_key_t[CRYPTO_SHA1_DIGEST_LENGTH + 1]; BYTE client_decrypt_key_t[CRYPTO_SHA1_DIGEST_LENGTH + 1]; - printf("FIPS Compliant encryption level.\n"); + fprintf(stderr, "FIPS Compliant encryption level.\n"); /* disable fastpath input; it doesnt handle FIPS encryption yet */ rdp->settings->FastPathInput = FALSE; diff --git a/libfreerdp/core/security.h b/libfreerdp/core/security.h index d02741d4e..ffcebdfdd 100644 --- a/libfreerdp/core/security.h +++ b/libfreerdp/core/security.h @@ -24,7 +24,8 @@ #include <freerdp/crypto/crypto.h> #include <freerdp/freerdp.h> -#include <freerdp/utils/stream.h> + +#include <winpr/stream.h> void security_master_secret(const BYTE* premaster_secret, const BYTE* client_random, const BYTE* server_random, BYTE* output); void security_session_key_blob(const BYTE* master_secret, const BYTE* client_random, const BYTE* server_random, BYTE* output); diff --git a/libfreerdp/core/settings.c b/libfreerdp/core/settings.c index 08224ef2a..8411b4b88 100644 --- a/libfreerdp/core/settings.c +++ b/libfreerdp/core/settings.c @@ -29,11 +29,12 @@ #endif #include <winpr/crt.h> +#include <winpr/file.h> +#include <winpr/path.h> #include <winpr/sysinfo.h> #include <winpr/registry.h> #include <freerdp/settings.h> -#include <freerdp/utils/file.h> #ifdef _WIN32 #pragma warning(push) @@ -409,7 +410,8 @@ rdpSettings* freerdp_settings_new(void* instance) malloc(sizeof(ADDIN_ARGV*) * settings->DynamicChannelArraySize); ZeroMemory(settings->DynamicChannelArray, sizeof(ADDIN_ARGV*) * settings->DynamicChannelArraySize); - freerdp_detect_paths(settings); + settings->HomePath = GetKnownPath(KNOWN_PATH_HOME); + settings->ConfigPath = GetKnownSubPath(KNOWN_PATH_XDG_CONFIG_HOME, "freerdp"); settings_load_hkey_local_machine(settings); } @@ -452,6 +454,7 @@ void freerdp_settings_free(rdpSettings* settings) free(settings->ConfigPath); free(settings->CurrentPath); free(settings->HomePath); + free(settings->LoadBalanceInfo); freerdp_device_collection_free(settings); freerdp_static_channel_collection_free(settings); freerdp_dynamic_channel_collection_free(settings); diff --git a/libfreerdp/core/surface.c b/libfreerdp/core/surface.c index 3d43a4ba5..42d39f1ab 100644 --- a/libfreerdp/core/surface.c +++ b/libfreerdp/core/surface.c @@ -25,7 +25,7 @@ #include "surface.h" -static int update_recv_surfcmd_surface_bits(rdpUpdate* update, STREAM* s, UINT32 *length) +static int update_recv_surfcmd_surface_bits(rdpUpdate* update, wStream* s, UINT32* length) { int pos; SURFACE_BITS_COMMAND* cmd = &update->surface_bits_command; @@ -50,24 +50,24 @@ static int update_recv_surfcmd_surface_bits(rdpUpdate* update, STREAM* s, UINT32 pos = stream_get_pos(s) + cmd->bitmapDataLength; cmd->bitmapData = stream_get_tail(s); - IFCALL(update->SurfaceBits, update->context, cmd); - stream_set_pos(s, pos); *length = 20 + cmd->bitmapDataLength; + IFCALL(update->SurfaceBits, update->context, cmd); + return 0; } static void update_send_frame_acknowledge(rdpRdp* rdp, UINT32 frameId) { - STREAM* s; + wStream* s; s = rdp_data_pdu_init(rdp); stream_write_UINT32(s, frameId); rdp_send_data_pdu(rdp, s, DATA_PDU_TYPE_FRAME_ACKNOWLEDGE, rdp->mcs->user_id); } -static int update_recv_surfcmd_frame_marker(rdpUpdate* update, STREAM* s, UINT32 *length) +static int update_recv_surfcmd_frame_marker(rdpUpdate* update, wStream* s, UINT32 *length) { SURFACE_FRAME_MARKER* marker = &update->surface_frame_marker; @@ -91,7 +91,7 @@ static int update_recv_surfcmd_frame_marker(rdpUpdate* update, STREAM* s, UINT32 return 0; } -int update_recv_surfcmds(rdpUpdate* update, UINT32 size, STREAM* s) +int update_recv_surfcmds(rdpUpdate* update, UINT32 size, wStream* s) { BYTE* mark; UINT16 cmdType; @@ -134,7 +134,7 @@ int update_recv_surfcmds(rdpUpdate* update, UINT32 size, STREAM* s) return 0; } -void update_write_surfcmd_surface_bits_header(STREAM* s, SURFACE_BITS_COMMAND* cmd) +void update_write_surfcmd_surface_bits_header(wStream* s, SURFACE_BITS_COMMAND* cmd) { stream_check_size(s, SURFCMD_SURFACE_BITS_HEADER_LENGTH); @@ -152,7 +152,7 @@ void update_write_surfcmd_surface_bits_header(STREAM* s, SURFACE_BITS_COMMAND* c stream_write_UINT32(s, cmd->bitmapDataLength); } -void update_write_surfcmd_frame_marker(STREAM* s, UINT16 frameAction, UINT32 frameId) +void update_write_surfcmd_frame_marker(wStream* s, UINT16 frameAction, UINT32 frameId) { stream_check_size(s, SURFCMD_FRAME_MARKER_LENGTH); diff --git a/libfreerdp/core/surface.h b/libfreerdp/core/surface.h index 38ebbe12d..f415a9d7b 100644 --- a/libfreerdp/core/surface.h +++ b/libfreerdp/core/surface.h @@ -21,7 +21,8 @@ #define __SURFACE #include "rdp.h" -#include <freerdp/utils/stream.h> + +#include <winpr/stream.h> #define SURFCMD_SURFACE_BITS_HEADER_LENGTH 22 #define SURFCMD_FRAME_MARKER_LENGTH 8 @@ -33,10 +34,10 @@ enum SURFCMD_CMDTYPE CMDTYPE_STREAM_SURFACE_BITS = 0x0006 }; -int update_recv_surfcmds(rdpUpdate* update, UINT32 size, STREAM* s); +int update_recv_surfcmds(rdpUpdate* update, UINT32 size, wStream* s); -void update_write_surfcmd_surface_bits_header(STREAM* s, SURFACE_BITS_COMMAND* cmd); -void update_write_surfcmd_frame_marker(STREAM* s, UINT16 frameAction, UINT32 frameId); +void update_write_surfcmd_surface_bits_header(wStream* s, SURFACE_BITS_COMMAND* cmd); +void update_write_surfcmd_frame_marker(wStream* s, UINT16 frameAction, UINT32 frameId); #endif /* __SURFACE */ diff --git a/libfreerdp/core/tcp.c b/libfreerdp/core/tcp.c index 978bf0e11..cb63b4241 100644 --- a/libfreerdp/core/tcp.c +++ b/libfreerdp/core/tcp.c @@ -53,7 +53,7 @@ #include <freerdp/utils/tcp.h> #include <freerdp/utils/uds.h> -#include <freerdp/utils/stream.h> +#include <winpr/stream.h> #include "tcp.h" @@ -104,14 +104,14 @@ void tcp_get_mac_address(rdpTcp * tcp) if (ioctl(tcp->sockfd, SIOCGIFHWADDR, &if_req) != 0) { - printf("failed to obtain MAC address\n"); + fprintf(stderr, "failed to obtain MAC address\n"); return; } memmove((void*) mac, (void*) &if_req.ifr_ifru.ifru_hwaddr.sa_data[0], 6); #endif - /* printf("MAC: %02X:%02X:%02X:%02X:%02X:%02X\n", + /* fprintf(stderr, "MAC: %02X:%02X:%02X:%02X:%02X:%02X\n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); */ } @@ -194,7 +194,7 @@ BOOL tcp_set_blocking_mode(rdpTcp* tcp, BOOL blocking) if (flags == -1) { - printf("tcp_set_blocking_mode: fcntl failed.\n"); + fprintf(stderr, "tcp_set_blocking_mode: fcntl failed.\n"); return FALSE; } @@ -209,7 +209,7 @@ BOOL tcp_set_blocking_mode(rdpTcp* tcp, BOOL blocking) status = ioctlsocket(tcp->sockfd, FIONBIO, &arg); if (status != NO_ERROR) - printf("ioctlsocket() failed with error: %ld\n", status); + fprintf(stderr, "ioctlsocket() failed with error: %ld\n", status); tcp->wsa_event = WSACreateEvent(); WSAEventSelect(tcp->sockfd, tcp->wsa_event, FD_READ); diff --git a/libfreerdp/core/tcp.h b/libfreerdp/core/tcp.h index 62ebec617..baede4524 100644 --- a/libfreerdp/core/tcp.h +++ b/libfreerdp/core/tcp.h @@ -25,7 +25,8 @@ #include <freerdp/types.h> #include <freerdp/settings.h> -#include <freerdp/utils/stream.h> + +#include <winpr/stream.h> #ifndef MSG_NOSIGNAL #define MSG_NOSIGNAL 0 diff --git a/libfreerdp/core/timezone.c b/libfreerdp/core/timezone.c index f5cb0b46c..30a291ffc 100644 --- a/libfreerdp/core/timezone.c +++ b/libfreerdp/core/timezone.c @@ -32,7 +32,7 @@ * @param system_time system time structure */ -void rdp_read_system_time(STREAM* s, SYSTEM_TIME* system_time) +void rdp_read_system_time(wStream* s, SYSTEM_TIME* system_time) { stream_read_UINT16(s, system_time->wYear); /* wYear, must be set to 0 */ stream_read_UINT16(s, system_time->wMonth); /* wMonth */ @@ -51,7 +51,7 @@ void rdp_read_system_time(STREAM* s, SYSTEM_TIME* system_time) * @param system_time system time structure */ -void rdp_write_system_time(STREAM* s, SYSTEM_TIME* system_time) +void rdp_write_system_time(wStream* s, SYSTEM_TIME* system_time) { stream_write_UINT16(s, system_time->wYear); /* wYear, must be set to 0 */ stream_write_UINT16(s, system_time->wMonth); /* wMonth */ @@ -74,7 +74,7 @@ void rdp_write_system_time(STREAM* s, SYSTEM_TIME* system_time) * @param settings settings */ -BOOL rdp_read_client_time_zone(STREAM* s, rdpSettings* settings) +BOOL rdp_read_client_time_zone(wStream* s, rdpSettings* settings) { char* str = NULL; TIME_ZONE_INFO* clientTimeZone; @@ -115,11 +115,8 @@ BOOL rdp_read_client_time_zone(STREAM* s, rdpSettings* settings) * @param settings settings */ -void rdp_write_client_time_zone(STREAM* s, rdpSettings* settings) +void rdp_write_client_time_zone(wStream* s, rdpSettings* settings) { - UINT32 bias; - INT32 sbias; - UINT32 bias2c; WCHAR* standardName = NULL; WCHAR* daylightName = NULL; int standardNameLength; @@ -138,57 +135,34 @@ void rdp_write_client_time_zone(STREAM* s, rdpSettings* settings) if (daylightNameLength > 62) daylightNameLength = 62; - /* UTC = LocalTime + Bias <-> Bias = UTC - LocalTime */ - - /* Translate from biases used throughout libfreerdp-locale/timezone.c - * to what RDP expects, which is minutes *west* of UTC. - * Though MS-RDPBCGR specifies bias as unsigned, two's complement - * (a negative integer) works fine for zones east of UTC. - */ - - if (clientTimeZone->bias <= 720) - bias = -1 * clientTimeZone->bias; - else - bias = 1440 - clientTimeZone->bias; - - stream_write_UINT32(s, bias); /* Bias */ + /* Bias */ + stream_write_UINT32(s, clientTimeZone->bias); /* standardName (64 bytes) */ stream_write(s, standardName, standardNameLength); stream_write_zero(s, 64 - standardNameLength); - rdp_write_system_time(s, &clientTimeZone->standardDate); /* StandardDate */ + /* StandardDate */ + rdp_write_system_time(s, &clientTimeZone->standardDate); - DEBUG_TIMEZONE("bias=%d stdName='%s' dlName='%s'", - bias, clientTimeZone->standardName, clientTimeZone->daylightName); - - sbias = clientTimeZone->standardBias - clientTimeZone->bias; - - if (sbias < 0) - bias2c = (UINT32) sbias; - else - bias2c = ~((UINT32) sbias) + 1; + DEBUG_TIMEZONE("bias=%d stdName='%s' dlName='%s'", clientTimeZone->bias, clientTimeZone->standardName, clientTimeZone->daylightName); /* Note that StandardBias is ignored if no valid standardDate is provided. */ - stream_write_UINT32(s, bias2c); /* StandardBias */ - DEBUG_TIMEZONE("StandardBias=%d", bias2c); + /* StandardBias */ + stream_write_UINT32(s, clientTimeZone->standardBias); + DEBUG_TIMEZONE("StandardBias=%d", clientTimeZone->standardBias); /* daylightName (64 bytes) */ - stream_write(s, daylightName, daylightNameLength); - stream_write_zero(s, 64 - daylightNameLength); + stream_write(s, daylightName, daylightNameLength); + stream_write_zero(s, 64 - daylightNameLength); - rdp_write_system_time(s, &clientTimeZone->daylightDate); /* DaylightDate */ - - sbias = clientTimeZone->daylightBias - clientTimeZone->bias; - - if (sbias < 0) - bias2c = (UINT32) sbias; - else - bias2c = ~((UINT32) sbias) + 1; + /* DaylightDate */ + rdp_write_system_time(s, &clientTimeZone->daylightDate); /* Note that DaylightBias is ignored if no valid daylightDate is provided. */ - stream_write_UINT32(s, bias2c); /* DaylightBias */ - DEBUG_TIMEZONE("DaylightBias=%d", bias2c); + /* DaylightBias */ + stream_write_UINT32(s, clientTimeZone->daylightBias); + DEBUG_TIMEZONE("DaylightBias=%d", clientTimeZone->daylightBias); free(standardName); free(daylightName); diff --git a/libfreerdp/core/timezone.h b/libfreerdp/core/timezone.h index 0bdff4fcb..076a4bed5 100644 --- a/libfreerdp/core/timezone.h +++ b/libfreerdp/core/timezone.h @@ -27,14 +27,15 @@ #endif #include <freerdp/freerdp.h> -#include <freerdp/utils/stream.h> #include <freerdp/locale/timezone.h> -void rdp_read_system_time(STREAM* s, SYSTEM_TIME* system_time); -void rdp_write_system_time(STREAM* s, SYSTEM_TIME* system_time); -void rdp_get_client_time_zone(STREAM* s, rdpSettings* settings); -BOOL rdp_read_client_time_zone(STREAM* s, rdpSettings* settings); -void rdp_write_client_time_zone(STREAM* s, rdpSettings* settings); +#include <winpr/stream.h> + +void rdp_read_system_time(wStream* s, SYSTEM_TIME* system_time); +void rdp_write_system_time(wStream* s, SYSTEM_TIME* system_time); +void rdp_get_client_time_zone(wStream* s, rdpSettings* settings); +BOOL rdp_read_client_time_zone(wStream* s, rdpSettings* settings); +void rdp_write_client_time_zone(wStream* s, rdpSettings* settings); #ifdef WITH_DEBUG_TIMEZONE #define DEBUG_TIMEZONE(fmt, ...) DEBUG_CLASS(TIMEZONE, fmt, ## __VA_ARGS__) diff --git a/libfreerdp/core/tpdu.c b/libfreerdp/core/tpdu.c index 84fa37128..228d6e14a 100644 --- a/libfreerdp/core/tpdu.c +++ b/libfreerdp/core/tpdu.c @@ -66,7 +66,7 @@ * @return TPDU length indicator (LI) */ -BOOL tpdu_read_header(STREAM* s, BYTE* code, BYTE *li) +BOOL tpdu_read_header(wStream* s, BYTE* code, BYTE *li) { if(stream_get_left(s) < 3) return FALSE; @@ -96,7 +96,7 @@ BOOL tpdu_read_header(STREAM* s, BYTE* code, BYTE *li) * @param code TPDU code */ -void tpdu_write_header(STREAM* s, UINT16 length, BYTE code) +void tpdu_write_header(wStream* s, UINT16 length, BYTE code) { stream_write_BYTE(s, length); /* LI */ stream_write_BYTE(s, code); /* code */ @@ -119,7 +119,7 @@ void tpdu_write_header(STREAM* s, UINT16 length, BYTE code) * @return length indicator (LI) */ -BOOL tpdu_read_connection_request(STREAM* s, BYTE *li) +BOOL tpdu_read_connection_request(wStream* s, BYTE *li) { BYTE code; @@ -128,7 +128,7 @@ BOOL tpdu_read_connection_request(STREAM* s, BYTE *li) if (code != X224_TPDU_CONNECTION_REQUEST) { - printf("Error: expected X224_TPDU_CONNECTION_REQUEST\n"); + fprintf(stderr, "Error: expected X224_TPDU_CONNECTION_REQUEST\n"); return FALSE; } @@ -141,7 +141,7 @@ BOOL tpdu_read_connection_request(STREAM* s, BYTE *li) * @param length TPDU length */ -void tpdu_write_connection_request(STREAM* s, UINT16 length) +void tpdu_write_connection_request(wStream* s, UINT16 length) { tpdu_write_header(s, length, X224_TPDU_CONNECTION_REQUEST); } @@ -152,7 +152,7 @@ void tpdu_write_connection_request(STREAM* s, UINT16 length) * @return length indicator (LI) */ -BOOL tpdu_read_connection_confirm(STREAM* s, BYTE *li) +BOOL tpdu_read_connection_confirm(wStream* s, BYTE *li) { BYTE code; @@ -161,7 +161,7 @@ BOOL tpdu_read_connection_confirm(STREAM* s, BYTE *li) if (code != X224_TPDU_CONNECTION_CONFIRM) { - printf("Error: expected X224_TPDU_CONNECTION_CONFIRM\n"); + fprintf(stderr, "Error: expected X224_TPDU_CONNECTION_CONFIRM\n"); return FALSE; } @@ -174,7 +174,7 @@ BOOL tpdu_read_connection_confirm(STREAM* s, BYTE *li) * @param length TPDU length */ -void tpdu_write_connection_confirm(STREAM* s, UINT16 length) +void tpdu_write_connection_confirm(wStream* s, UINT16 length) { tpdu_write_header(s, length, X224_TPDU_CONNECTION_CONFIRM); } @@ -185,7 +185,7 @@ void tpdu_write_connection_confirm(STREAM* s, UINT16 length) * @param length TPDU length */ -void tpdu_write_disconnect_request(STREAM* s, UINT16 length) +void tpdu_write_disconnect_request(wStream* s, UINT16 length) { tpdu_write_header(s, length, X224_TPDU_DISCONNECT_REQUEST); } @@ -195,7 +195,7 @@ void tpdu_write_disconnect_request(STREAM* s, UINT16 length) * @param s stream */ -void tpdu_write_data(STREAM* s) +void tpdu_write_data(wStream* s) { tpdu_write_header(s, 2, X224_TPDU_DATA); } @@ -205,7 +205,7 @@ void tpdu_write_data(STREAM* s) * @param s stream */ -BOOL tpdu_read_data(STREAM* s, UINT16 *LI) +BOOL tpdu_read_data(wStream* s, UINT16 *LI) { BYTE code; BYTE li; diff --git a/libfreerdp/core/tpdu.h b/libfreerdp/core/tpdu.h index c81fba6b8..dbd0fe53d 100644 --- a/libfreerdp/core/tpdu.h +++ b/libfreerdp/core/tpdu.h @@ -20,7 +20,7 @@ #ifndef __TPDU_H #define __TPDU_H -#include <freerdp/utils/stream.h> +#include <winpr/stream.h> enum X224_TPDU_TYPE { @@ -41,14 +41,14 @@ enum X224_TPDU_TYPE #define TPDU_CONNECTION_CONFIRM_LENGTH (TPKT_HEADER_LENGTH + TPDU_CONNECTION_CONFIRM_HEADER_LENGTH) #define TPDU_DISCONNECT_REQUEST_LENGTH (TPKT_HEADER_LENGTH + TPDU_DISCONNECT_REQUEST_HEADER_LENGTH) -BOOL tpdu_read_header(STREAM* s, BYTE* code, BYTE *li); -void tpdu_write_header(STREAM* s, UINT16 length, BYTE code); -BOOL tpdu_read_connection_request(STREAM* s, BYTE *li); -void tpdu_write_connection_request(STREAM* s, UINT16 length); -BOOL tpdu_read_connection_confirm(STREAM* s, BYTE *li); -void tpdu_write_connection_confirm(STREAM* s, UINT16 length); -void tpdu_write_disconnect_request(STREAM* s, UINT16 length); -BOOL tpdu_read_data(STREAM* s, UINT16 *li); -void tpdu_write_data(STREAM* s); +BOOL tpdu_read_header(wStream* s, BYTE* code, BYTE *li); +void tpdu_write_header(wStream* s, UINT16 length, BYTE code); +BOOL tpdu_read_connection_request(wStream* s, BYTE *li); +void tpdu_write_connection_request(wStream* s, UINT16 length); +BOOL tpdu_read_connection_confirm(wStream* s, BYTE *li); +void tpdu_write_connection_confirm(wStream* s, UINT16 length); +void tpdu_write_disconnect_request(wStream* s, UINT16 length); +BOOL tpdu_read_data(wStream* s, UINT16 *li); +void tpdu_write_data(wStream* s); #endif /* __TPDU_H */ diff --git a/libfreerdp/core/tpkt.c b/libfreerdp/core/tpkt.c index a053941a9..f5f55eb79 100644 --- a/libfreerdp/core/tpkt.c +++ b/libfreerdp/core/tpkt.c @@ -63,7 +63,7 @@ * @return BOOL */ -BOOL tpkt_verify_header(STREAM* s) +BOOL tpkt_verify_header(wStream* s) { BYTE version; @@ -81,7 +81,7 @@ BOOL tpkt_verify_header(STREAM* s) * @return length */ -UINT16 tpkt_read_header(STREAM* s) +UINT16 tpkt_read_header(wStream* s) { BYTE version; UINT16 length; @@ -108,7 +108,7 @@ UINT16 tpkt_read_header(STREAM* s) * @param length */ -void tpkt_write_header(STREAM* s, UINT16 length) +void tpkt_write_header(wStream* s, UINT16 length) { stream_write_BYTE(s, 3); /* version */ stream_write_BYTE(s, 0); /* reserved */ diff --git a/libfreerdp/core/tpkt.h b/libfreerdp/core/tpkt.h index 73579d269..af984c11c 100644 --- a/libfreerdp/core/tpkt.h +++ b/libfreerdp/core/tpkt.h @@ -23,12 +23,12 @@ #include "tpdu.h" #include "transport.h" -#include <freerdp/utils/stream.h> +#include <winpr/stream.h> #define TPKT_HEADER_LENGTH 4 -BOOL tpkt_verify_header(STREAM* s); -UINT16 tpkt_read_header(STREAM* s); -void tpkt_write_header(STREAM* s, UINT16 length); +BOOL tpkt_verify_header(wStream* s); +UINT16 tpkt_read_header(wStream* s); +void tpkt_write_header(wStream* s, UINT16 length); #endif /* __TPKT_H */ diff --git a/libfreerdp/core/transport.c b/libfreerdp/core/transport.c index bd1f689f8..c1033e225 100644 --- a/libfreerdp/core/transport.c +++ b/libfreerdp/core/transport.c @@ -31,7 +31,7 @@ #include <freerdp/error.h> #include <freerdp/utils/tcp.h> -#include <freerdp/utils/stream.h> +#include <winpr/stream.h> #include <time.h> #include <errno.h> @@ -48,17 +48,19 @@ #define BUFFER_SIZE 16384 -STREAM* transport_recv_stream_init(rdpTransport* transport, int size) +static void* transport_client_thread(void* arg); + +wStream* transport_recv_stream_init(rdpTransport* transport, int size) { - STREAM* s = transport->ReceiveStream; + wStream* s = transport->ReceiveStream; stream_check_size(s, size); stream_set_pos(s, 0); return s; } -STREAM* transport_send_stream_init(rdpTransport* transport, int size) +wStream* transport_send_stream_init(rdpTransport* transport, int size) { - STREAM* s = transport->SendStream; + wStream* s = transport->SendStream; stream_check_size(s, size); stream_set_pos(s, 0); return s; @@ -118,6 +120,7 @@ BOOL transport_connect_tls(rdpTransport* transport) connectErrorCode = TLSCONNECTERROR; tls_free(transport->TlsIn); + if (transport->TlsIn == transport->TlsOut) transport->TlsIn = transport->TlsOut = NULL; else @@ -156,7 +159,7 @@ BOOL transport_connect_nla(rdpTransport* transport) if (!connectErrorCode) connectErrorCode = AUTHENTICATIONERROR; - printf("Authentication failure, check credentials.\n" + fprintf(stderr, "Authentication failure, check credentials.\n" "If credentials are valid, the NTLMSSP implementation may be to blame.\n"); credssp_free(transport->credssp); @@ -203,6 +206,16 @@ BOOL transport_connect(rdpTransport* transport, const char* hostname, UINT16 por BOOL status = FALSE; rdpSettings* settings = transport->settings; + transport->async = transport->settings->AsyncTransport; + + if (transport->async) + { + transport->stopEvent = CreateEvent(NULL, TRUE, FALSE, NULL); + + transport->thread = CreateThread(NULL, 0, + (LPTHREAD_START_ROUTINE) transport_client_thread, transport, 0, NULL); + } + if (transport->settings->GatewayUsageMethod) { transport->layer = TRANSPORT_LAYER_TSG; @@ -281,7 +294,7 @@ BOOL transport_accept_nla(rdpTransport* transport) if (credssp_authenticate(transport->credssp) < 0) { - printf("client authentication failure\n"); + fprintf(stderr, "client authentication failure\n"); credssp_free(transport->credssp); return FALSE; } @@ -291,40 +304,40 @@ BOOL transport_accept_nla(rdpTransport* transport) return TRUE; } -BOOL nla_verify_header(STREAM* s) +BOOL nla_verify_header(wStream* s) { - if ((s->p[0] == 0x30) && (s->p[1] & 0x80)) + if ((s->pointer[0] == 0x30) && (s->pointer[1] & 0x80)) return TRUE; return FALSE; } -UINT32 nla_read_header(STREAM* s) +UINT32 nla_read_header(wStream* s) { UINT32 length = 0; - if (s->p[1] & 0x80) + if (s->pointer[1] & 0x80) { - if ((s->p[1] & ~(0x80)) == 1) + if ((s->pointer[1] & ~(0x80)) == 1) { - length = s->p[2]; + length = s->pointer[2]; length += 3; stream_seek(s, 3); } - else if ((s->p[1] & ~(0x80)) == 2) + else if ((s->pointer[1] & ~(0x80)) == 2) { - length = (s->p[2] << 8) | s->p[3]; + length = (s->pointer[2] << 8) | s->pointer[3]; length += 4; stream_seek(s, 4); } else { - printf("Error reading TSRequest!\n"); + fprintf(stderr, "Error reading TSRequest!\n"); } } else { - length = s->p[1]; + length = s->pointer[1]; length += 2; stream_seek(s, 2); } @@ -332,18 +345,18 @@ UINT32 nla_read_header(STREAM* s) return length; } -UINT32 nla_header_length(STREAM* s) +UINT32 nla_header_length(wStream* s) { UINT32 length = 0; - if (s->p[1] & 0x80) + if (s->pointer[1] & 0x80) { - if ((s->p[1] & ~(0x80)) == 1) + if ((s->pointer[1] & ~(0x80)) == 1) length = 3; - else if ((s->p[1] & ~(0x80)) == 2) + else if ((s->pointer[1] & ~(0x80)) == 2) length = 4; else - printf("Error reading TSRequest!\n"); + fprintf(stderr, "Error reading TSRequest!\n"); } else { @@ -390,7 +403,7 @@ int transport_read_layer(rdpTransport* transport, UINT8* data, int bytes) return read; } -int transport_read(rdpTransport* transport, STREAM* s) +int transport_read(rdpTransport* transport, wStream* s) { int status; int pdu_bytes; @@ -405,7 +418,7 @@ int transport_read(rdpTransport* transport, STREAM* s) if (stream_bytes < 4) { - status = transport_read_layer(transport, s->data + stream_bytes, 4 - stream_bytes); + status = transport_read_layer(transport, s->buffer + stream_bytes, 4 - stream_bytes); if (status < 0) return status; @@ -419,36 +432,36 @@ int transport_read(rdpTransport* transport, STREAM* s) } /* if header is present, read in exactly one PDU */ - if (s->data[0] == 0x03) + if (s->buffer[0] == 0x03) { /* TPKT header */ - pdu_bytes = (s->data[2] << 8) | s->data[3]; + pdu_bytes = (s->buffer[2] << 8) | s->buffer[3]; } - else if (s->data[0] == 0x30) + else if (s->buffer[0] == 0x30) { /* TSRequest (NLA) */ - if (s->data[1] & 0x80) + if (s->buffer[1] & 0x80) { - if ((s->data[1] & ~(0x80)) == 1) + if ((s->buffer[1] & ~(0x80)) == 1) { - pdu_bytes = s->data[2]; + pdu_bytes = s->buffer[2]; pdu_bytes += 3; } - else if ((s->data[1] & ~(0x80)) == 2) + else if ((s->buffer[1] & ~(0x80)) == 2) { - pdu_bytes = (s->data[2] << 8) | s->data[3]; + pdu_bytes = (s->buffer[2] << 8) | s->buffer[3]; pdu_bytes += 4; } else { - printf("Error reading TSRequest!\n"); + fprintf(stderr, "Error reading TSRequest!\n"); } } else { - pdu_bytes = s->data[1]; + pdu_bytes = s->buffer[1]; pdu_bytes += 2; } } @@ -456,13 +469,13 @@ int transport_read(rdpTransport* transport, STREAM* s) { /* Fast-Path Header */ - if (s->data[1] & 0x80) - pdu_bytes = ((s->data[1] & 0x7f) << 8) | s->data[2]; + if (s->buffer[1] & 0x80) + pdu_bytes = ((s->buffer[1] & 0x7f) << 8) | s->buffer[2]; else - pdu_bytes = s->data[1]; + pdu_bytes = s->buffer[1]; } - status = transport_read_layer(transport, s->data + stream_bytes, pdu_bytes - stream_bytes); + status = transport_read_layer(transport, s->buffer + stream_bytes, pdu_bytes - stream_bytes); if (status < 0) return status; @@ -473,8 +486,8 @@ int transport_read(rdpTransport* transport, STREAM* s) /* dump when whole PDU is read */ if (stream_bytes + status >= pdu_bytes) { - printf("Local < Remote\n"); - winpr_HexDump(s->data, pdu_bytes); + fprintf(stderr, "Local < Remote\n"); + winpr_HexDump(s->buffer, pdu_bytes); } #endif @@ -496,7 +509,7 @@ static int transport_read_nonblocking(rdpTransport* transport) return status; } -int transport_write(rdpTransport* transport, STREAM* s) +int transport_write(rdpTransport* transport, wStream* s) { int status = -1; int length; @@ -507,8 +520,8 @@ int transport_write(rdpTransport* transport, STREAM* s) #ifdef WITH_DEBUG_TRANSPORT if (length > 0) { - printf("Local > Remote\n"); - winpr_HexDump(s->data, length); + fprintf(stderr, "Local > Remote\n"); + winpr_HexDump(s->buffer, length); } #endif @@ -586,6 +599,17 @@ void transport_get_fds(rdpTransport* transport, void** rfds, int* rcount) rfds[*rcount] = pfd; (*rcount)++; } + + if (transport->GatewayEvent) + { + pfd = GetEventWaitObject(transport->GatewayEvent); + + if (pfd) + { + rfds[*rcount] = pfd; + (*rcount)++; + } + } } int transport_check_fds(rdpTransport** ptransport) @@ -594,7 +618,7 @@ int transport_check_fds(rdpTransport** ptransport) int status; UINT16 length; int recv_status; - STREAM* received; + wStream* received; rdpTransport* transport = *ptransport; #ifdef _WIN32 @@ -667,7 +691,7 @@ int transport_check_fds(rdpTransport** ptransport) if (length == 0) { - printf("transport_check_fds: protocol error, not a TPKT or Fast Path header.\n"); + fprintf(stderr, "transport_check_fds: protocol error, not a TPKT or Fast Path header.\n"); winpr_HexDump(stream_get_head(transport->ReceiveBuffer), pos); return -1; } @@ -679,8 +703,7 @@ int transport_check_fds(rdpTransport** ptransport) } received = transport->ReceiveBuffer; - transport->ReceiveBuffer = ObjectPool_Take(transport->ReceivePool); - transport->ReceiveBuffer->p = transport->ReceiveBuffer->data; + transport->ReceiveBuffer = StreamPool_Take(transport->ReceivePool, 0); stream_set_pos(received, length); stream_seal(received); @@ -696,7 +719,7 @@ int transport_check_fds(rdpTransport** ptransport) recv_status = transport->ReceiveCallback(transport, received, transport->ReceiveExtra); - ObjectPool_Return(transport->ReceivePool, received); + Stream_Release(received); if (recv_status < 0) status = -1; @@ -736,14 +759,43 @@ BOOL transport_set_blocking_mode(rdpTransport* transport, BOOL blocking) return status; } -STREAM* transport_receive_buffer_pool_new() +static void* transport_client_thread(void* arg) { - STREAM* pdu = NULL; + DWORD status; + DWORD nCount; + HANDLE events[3]; + HANDLE ReadEvent; + freerdp* instance; + rdpTransport* transport; - pdu = stream_new(BUFFER_SIZE); - pdu->p = pdu->data; + transport = (rdpTransport*) arg; + instance = (freerdp*) transport->settings->instance; - return pdu; + ReadEvent = CreateFileDescriptorEvent(NULL, TRUE, FALSE, transport->TcpIn->sockfd); + + nCount = 0; + events[nCount++] = transport->stopEvent; + events[nCount++] = ReadEvent; + + while (1) + { + status = WaitForMultipleObjects(nCount, events, FALSE, INFINITE); + + if (WaitForSingleObject(transport->stopEvent, 0) == WAIT_OBJECT_0) + { + break; + } + + if (WaitForSingleObject(ReadEvent, 0) == WAIT_OBJECT_0) + { + if (!freerdp_check_fds(instance)) + break; + } + } + + CloseHandle(ReadEvent); + + return NULL; } rdpTransport* transport_new(rdpSettings* settings) @@ -751,10 +803,11 @@ rdpTransport* transport_new(rdpSettings* settings) rdpTransport* transport; transport = (rdpTransport*) malloc(sizeof(rdpTransport)); - ZeroMemory(transport, sizeof(rdpTransport)); if (transport != NULL) { + ZeroMemory(transport, sizeof(rdpTransport)); + transport->TcpIn = tcp_new(settings); transport->settings = settings; @@ -762,16 +815,14 @@ rdpTransport* transport_new(rdpSettings* settings) /* a small 0.1ms delay when transport is blocking. */ transport->SleepInterval = 100; - transport->ReceivePool = ObjectPool_New(TRUE); - ObjectPool_Object(transport->ReceivePool)->fnObjectFree = (OBJECT_FREE_FN) stream_free; - ObjectPool_Object(transport->ReceivePool)->fnObjectNew = (OBJECT_NEW_FN) transport_receive_buffer_pool_new; + transport->ReceivePool = StreamPool_New(TRUE, BUFFER_SIZE); /* receive buffer for non-blocking read. */ - transport->ReceiveBuffer = ObjectPool_Take(transport->ReceivePool); + transport->ReceiveBuffer = StreamPool_Take(transport->ReceivePool, 0); transport->ReceiveEvent = CreateEvent(NULL, TRUE, FALSE, NULL); /* buffers for blocking read/write */ - transport->ReceiveStream = stream_new(BUFFER_SIZE); + transport->ReceiveStream = StreamPool_Take(transport->ReceivePool, 0); transport->SendStream = stream_new(BUFFER_SIZE); transport->blocking = TRUE; @@ -787,11 +838,13 @@ void transport_free(rdpTransport* transport) if (transport != NULL) { if (transport->ReceiveBuffer) - ObjectPool_Return(transport->ReceivePool, transport->ReceiveBuffer); + Stream_Release(transport->ReceiveBuffer); - ObjectPool_Free(transport->ReceivePool); + if (transport->ReceiveStream) + Stream_Release(transport->ReceiveStream); + + StreamPool_Free(transport->ReceivePool); - stream_free(transport->ReceiveStream); stream_free(transport->SendStream); CloseHandle(transport->ReceiveEvent); diff --git a/libfreerdp/core/transport.h b/libfreerdp/core/transport.h index b8f33d083..67a2e2783 100644 --- a/libfreerdp/core/transport.h +++ b/libfreerdp/core/transport.h @@ -36,6 +36,9 @@ typedef struct rdp_transport rdpTransport; #include "gateway/tsg.h" #include <winpr/sspi.h> +#include <winpr/synch.h> +#include <winpr/thread.h> +#include <winpr/stream.h> #include <winpr/collections.h> #include <freerdp/crypto/tls.h> @@ -43,9 +46,8 @@ typedef struct rdp_transport rdpTransport; #include <time.h> #include <freerdp/types.h> #include <freerdp/settings.h> -#include <freerdp/utils/stream.h> -typedef int (*TransportRecv) (rdpTransport* transport, STREAM* stream, void* extra); +typedef int (*TransportRecv) (rdpTransport* transport, wStream* stream, void* extra); struct rdp_transport { @@ -58,19 +60,23 @@ struct rdp_transport rdpCredssp* credssp; rdpSettings* settings; UINT32 SleepInterval; - STREAM* SendStream; - STREAM* ReceiveStream; + wStream* SendStream; + wStream* ReceiveStream; void* ReceiveExtra; - STREAM* ReceiveBuffer; + wStream* ReceiveBuffer; TransportRecv ReceiveCallback; HANDLE ReceiveEvent; + HANDLE GatewayEvent; BOOL blocking; BOOL SplitInputOutput; - wObjectPool* ReceivePool; + wStreamPool* ReceivePool; + HANDLE stopEvent; + HANDLE thread; + BOOL async; }; -STREAM* transport_recv_stream_init(rdpTransport* transport, int size); -STREAM* transport_send_stream_init(rdpTransport* transport, int size); +wStream* transport_recv_stream_init(rdpTransport* transport, int size); +wStream* transport_send_stream_init(rdpTransport* transport, int size); BOOL transport_connect(rdpTransport* transport, const char* hostname, UINT16 port); void transport_attach(rdpTransport* transport, int sockfd); BOOL transport_disconnect(rdpTransport* transport); @@ -81,14 +87,14 @@ BOOL transport_connect_tsg(rdpTransport* transport); BOOL transport_accept_rdp(rdpTransport* transport); BOOL transport_accept_tls(rdpTransport* transport); BOOL transport_accept_nla(rdpTransport* transport); -int transport_read(rdpTransport* transport, STREAM* s); -int transport_write(rdpTransport* transport, STREAM* s); +int transport_read(rdpTransport* transport, wStream* s); +int transport_write(rdpTransport* transport, wStream* s); void transport_get_fds(rdpTransport* transport, void** rfds, int* rcount); int transport_check_fds(rdpTransport** ptransport); BOOL transport_set_blocking_mode(rdpTransport* transport, BOOL blocking); -STREAM* transport_receive_pool_take(rdpTransport* transport); -int transport_receive_pool_return(rdpTransport* transport, STREAM* pdu); +wStream* transport_receive_pool_take(rdpTransport* transport); +int transport_receive_pool_return(rdpTransport* transport, wStream* pdu); rdpTransport* transport_new(rdpSettings* settings); void transport_free(rdpTransport* transport); diff --git a/libfreerdp/core/update.c b/libfreerdp/core/update.c index 1b24b6118..578c5ed4d 100644 --- a/libfreerdp/core/update.c +++ b/libfreerdp/core/update.c @@ -42,7 +42,7 @@ static const char* const UPDATE_TYPE_STRINGS[] = }; */ -BOOL update_recv_orders(rdpUpdate* update, STREAM* s) +BOOL update_recv_orders(rdpUpdate* update, wStream* s) { UINT16 numberOrders; @@ -63,7 +63,7 @@ BOOL update_recv_orders(rdpUpdate* update, STREAM* s) return TRUE; } -BOOL update_read_bitmap_data(STREAM* s, BITMAP_DATA* bitmap_data) +BOOL update_read_bitmap_data(wStream* s, BITMAP_DATA* bitmap_data) { if (stream_get_left(s) < 18) return FALSE; @@ -104,7 +104,7 @@ BOOL update_read_bitmap_data(STREAM* s, BITMAP_DATA* bitmap_data) return TRUE; } -BOOL update_read_bitmap(rdpUpdate* update, STREAM* s, BITMAP_UPDATE* bitmap_update) +BOOL update_read_bitmap(rdpUpdate* update, wStream* s, BITMAP_UPDATE* bitmap_update) { int i; @@ -137,7 +137,7 @@ BOOL update_read_bitmap(rdpUpdate* update, STREAM* s, BITMAP_UPDATE* bitmap_upda return TRUE; } -BOOL update_read_palette(rdpUpdate* update, STREAM* s, PALETTE_UPDATE* palette_update) +BOOL update_read_palette(rdpUpdate* update, wStream* s, PALETTE_UPDATE* palette_update) { int i; PALETTE_ENTRY* entry; @@ -166,7 +166,7 @@ BOOL update_read_palette(rdpUpdate* update, STREAM* s, PALETTE_UPDATE* palette_u return TRUE; } -void update_read_synchronize(rdpUpdate* update, STREAM* s) +void update_read_synchronize(rdpUpdate* update, wStream* s) { stream_seek_UINT16(s); /* pad2Octets (2 bytes) */ @@ -176,7 +176,7 @@ void update_read_synchronize(rdpUpdate* update, STREAM* s) */ } -BOOL update_read_play_sound(STREAM* s, PLAY_SOUND_UPDATE* play_sound) +BOOL update_read_play_sound(wStream* s, PLAY_SOUND_UPDATE* play_sound) { if (stream_get_left(s) < 8) return FALSE; @@ -187,7 +187,7 @@ BOOL update_read_play_sound(STREAM* s, PLAY_SOUND_UPDATE* play_sound) return TRUE; } -BOOL update_recv_play_sound(rdpUpdate* update, STREAM* s) +BOOL update_recv_play_sound(rdpUpdate* update, wStream* s) { if (!update_read_play_sound(s, &update->play_sound)) return FALSE; @@ -196,7 +196,7 @@ BOOL update_recv_play_sound(rdpUpdate* update, STREAM* s) return TRUE; } -BOOL update_read_pointer_position(STREAM* s, POINTER_POSITION_UPDATE* pointer_position) +BOOL update_read_pointer_position(wStream* s, POINTER_POSITION_UPDATE* pointer_position) { if (stream_get_left(s) < 4) return FALSE; @@ -206,7 +206,7 @@ BOOL update_read_pointer_position(STREAM* s, POINTER_POSITION_UPDATE* pointer_po return TRUE; } -BOOL update_read_pointer_system(STREAM* s, POINTER_SYSTEM_UPDATE* pointer_system) +BOOL update_read_pointer_system(wStream* s, POINTER_SYSTEM_UPDATE* pointer_system) { if (stream_get_left(s) < 4) return FALSE; @@ -215,7 +215,7 @@ BOOL update_read_pointer_system(STREAM* s, POINTER_SYSTEM_UPDATE* pointer_system return TRUE; } -BOOL update_read_pointer_color(STREAM* s, POINTER_COLOR_UPDATE* pointer_color) +BOOL update_read_pointer_color(wStream* s, POINTER_COLOR_UPDATE* pointer_color) { if (stream_get_left(s) < 14) return FALSE; @@ -271,7 +271,7 @@ BOOL update_read_pointer_color(STREAM* s, POINTER_COLOR_UPDATE* pointer_color) return TRUE; } -BOOL update_read_pointer_new(STREAM* s, POINTER_NEW_UPDATE* pointer_new) +BOOL update_read_pointer_new(wStream* s, POINTER_NEW_UPDATE* pointer_new) { if (stream_get_left(s) < 2) return FALSE; @@ -280,7 +280,7 @@ BOOL update_read_pointer_new(STREAM* s, POINTER_NEW_UPDATE* pointer_new) return update_read_pointer_color(s, &pointer_new->colorPtrAttr); /* colorPtrAttr */ } -BOOL update_read_pointer_cached(STREAM* s, POINTER_CACHED_UPDATE* pointer_cached) +BOOL update_read_pointer_cached(wStream* s, POINTER_CACHED_UPDATE* pointer_cached) { if (stream_get_left(s) < 2) return FALSE; @@ -289,7 +289,7 @@ BOOL update_read_pointer_cached(STREAM* s, POINTER_CACHED_UPDATE* pointer_cached return TRUE; } -BOOL update_recv_pointer(rdpUpdate* update, STREAM* s) +BOOL update_recv_pointer(rdpUpdate* update, wStream* s) { UINT16 messageType; rdpContext* context = update->context; @@ -339,7 +339,7 @@ BOOL update_recv_pointer(rdpUpdate* update, STREAM* s) return TRUE; } -BOOL update_recv(rdpUpdate* update, STREAM* s) +BOOL update_recv(rdpUpdate* update, wStream* s) { UINT16 updateType; rdpContext* context = update->context; @@ -349,7 +349,7 @@ BOOL update_recv(rdpUpdate* update, STREAM* s) stream_read_UINT16(s, updateType); /* updateType (2 bytes) */ - //printf("%s Update Data PDU\n", UPDATE_TYPE_STRINGS[updateType]); + //fprintf(stderr, "%s Update Data PDU\n", UPDATE_TYPE_STRINGS[updateType]); IFCALL(update->BeginPaint, context); @@ -447,7 +447,7 @@ static void update_end_paint(rdpContext* context) } -static void update_write_refresh_rect(STREAM* s, BYTE count, RECTANGLE_16* areas) +static void update_write_refresh_rect(wStream* s, BYTE count, RECTANGLE_16* areas) { int i; @@ -465,7 +465,7 @@ static void update_write_refresh_rect(STREAM* s, BYTE count, RECTANGLE_16* areas static void update_send_refresh_rect(rdpContext* context, BYTE count, RECTANGLE_16* areas) { - STREAM* s; + wStream* s; rdpRdp* rdp = context->rdp; if (rdp->settings->RefreshRect) @@ -477,7 +477,7 @@ static void update_send_refresh_rect(rdpContext* context, BYTE count, RECTANGLE_ } } -static void update_write_suppress_output(STREAM* s, BYTE allow, RECTANGLE_16* area) +static void update_write_suppress_output(wStream* s, BYTE allow, RECTANGLE_16* area) { stream_write_BYTE(s, allow); /* allowDisplayUpdates (1 byte) */ stream_seek(s, 3); /* pad3Octets (3 bytes) */ @@ -493,7 +493,7 @@ static void update_write_suppress_output(STREAM* s, BYTE allow, RECTANGLE_16* ar static void update_send_suppress_output(rdpContext* context, BYTE allow, RECTANGLE_16* area) { - STREAM* s; + wStream* s; rdpRdp* rdp = context->rdp; if (rdp->settings->SuppressOutput) @@ -505,9 +505,9 @@ static void update_send_suppress_output(rdpContext* context, BYTE allow, RECTANG } } -static void update_send_surface_command(rdpContext* context, STREAM* s) +static void update_send_surface_command(rdpContext* context, wStream* s) { - STREAM* update; + wStream* update; rdpRdp* rdp = context->rdp; update = fastpath_update_pdu_init(rdp->fastpath); @@ -518,7 +518,7 @@ static void update_send_surface_command(rdpContext* context, STREAM* s) static void update_send_surface_bits(rdpContext* context, SURFACE_BITS_COMMAND* surface_bits_command) { - STREAM* s; + wStream* s; rdpRdp* rdp = context->rdp; s = fastpath_update_pdu_init(rdp->fastpath); @@ -530,7 +530,7 @@ static void update_send_surface_bits(rdpContext* context, SURFACE_BITS_COMMAND* static void update_send_surface_frame_marker(rdpContext* context, SURFACE_FRAME_MARKER* surface_frame_marker) { - STREAM* s; + wStream* s; rdpRdp* rdp = context->rdp; s = fastpath_update_pdu_init(rdp->fastpath); @@ -540,7 +540,7 @@ static void update_send_surface_frame_marker(rdpContext* context, SURFACE_FRAME_ static void update_send_frame_acknowledge(rdpContext* context, UINT32 frameId) { - STREAM* s; + wStream* s; rdpRdp* rdp = context->rdp; if (rdp->settings->ReceivedCapabilities[CAPSET_TYPE_FRAME_ACKNOWLEDGE]) @@ -553,7 +553,7 @@ static void update_send_frame_acknowledge(rdpContext* context, UINT32 frameId) static void update_send_synchronize(rdpContext* context) { - STREAM* s; + wStream* s; rdpRdp* rdp = context->rdp; s = fastpath_update_pdu_init(rdp->fastpath); @@ -571,7 +571,7 @@ static void update_send_desktop_resize(rdpContext* context) static void update_send_scrblt(rdpContext* context, SCRBLT_ORDER* scrblt) { - STREAM* s; + wStream* s; rdpRdp* rdp = context->rdp; s = fastpath_update_pdu_init(rdp->fastpath); @@ -594,7 +594,7 @@ static void update_send_scrblt(rdpContext* context, SCRBLT_ORDER* scrblt) static void update_send_pointer_system(rdpContext* context, POINTER_SYSTEM_UPDATE* pointer_system) { - STREAM* s; + wStream* s; BYTE updateCode; rdpRdp* rdp = context->rdp; @@ -608,7 +608,7 @@ static void update_send_pointer_system(rdpContext* context, POINTER_SYSTEM_UPDAT fastpath_send_update_pdu(rdp->fastpath, updateCode, s); } -static void update_write_pointer_color(STREAM* s, POINTER_COLOR_UPDATE* pointer_color) +static void update_write_pointer_color(wStream* s, POINTER_COLOR_UPDATE* pointer_color) { stream_check_size(s, 15 + (int) pointer_color->lengthAndMask + (int) pointer_color->lengthXorMask); @@ -631,7 +631,7 @@ static void update_write_pointer_color(STREAM* s, POINTER_COLOR_UPDATE* pointer_ static void update_send_pointer_color(rdpContext* context, POINTER_COLOR_UPDATE* pointer_color) { - STREAM* s; + wStream* s; rdpRdp* rdp = context->rdp; s = fastpath_update_pdu_init(rdp->fastpath); @@ -641,7 +641,7 @@ static void update_send_pointer_color(rdpContext* context, POINTER_COLOR_UPDATE* static void update_send_pointer_new(rdpContext* context, POINTER_NEW_UPDATE* pointer_new) { - STREAM* s; + wStream* s; rdpRdp* rdp = context->rdp; s = fastpath_update_pdu_init(rdp->fastpath); @@ -652,7 +652,7 @@ static void update_send_pointer_new(rdpContext* context, POINTER_NEW_UPDATE* poi static void update_send_pointer_cached(rdpContext* context, POINTER_CACHED_UPDATE* pointer_cached) { - STREAM* s; + wStream* s; rdpRdp* rdp = context->rdp; s = fastpath_update_pdu_init(rdp->fastpath); @@ -660,7 +660,7 @@ static void update_send_pointer_cached(rdpContext* context, POINTER_CACHED_UPDAT fastpath_send_update_pdu(rdp->fastpath, FASTPATH_UPDATETYPE_CACHED, s); } -BOOL update_read_refresh_rect(rdpUpdate* update, STREAM* s) +BOOL update_read_refresh_rect(rdpUpdate* update, wStream* s) { int index; BYTE numberOfAreas; @@ -691,7 +691,7 @@ BOOL update_read_refresh_rect(rdpUpdate* update, STREAM* s) return TRUE; } -BOOL update_read_suppress_output(rdpUpdate* update, STREAM* s) +BOOL update_read_suppress_output(rdpUpdate* update, wStream* s) { BYTE allowDisplayUpdates; diff --git a/libfreerdp/core/update.h b/libfreerdp/core/update.h index 541490d95..c3088f299 100644 --- a/libfreerdp/core/update.h +++ b/libfreerdp/core/update.h @@ -22,10 +22,12 @@ #include "rdp.h" #include "orders.h" + #include <freerdp/types.h> #include <freerdp/update.h> #include <freerdp/freerdp.h> -#include <freerdp/utils/stream.h> + +#include <winpr/stream.h> #define UPDATE_TYPE_ORDERS 0x0000 #define UPDATE_TYPE_BITMAP 0x0001 @@ -43,20 +45,20 @@ void update_free_bitmap(BITMAP_UPDATE* bitmap_update); void update_reset_state(rdpUpdate* update); void update_post_connect(rdpUpdate* update); -BOOL update_read_bitmap(rdpUpdate* update, STREAM* s, BITMAP_UPDATE* bitmap_update); -BOOL update_read_palette(rdpUpdate* update, STREAM* s, PALETTE_UPDATE* palette_update); -BOOL update_recv_play_sound(rdpUpdate* update, STREAM* s); -BOOL update_recv_pointer(rdpUpdate* update, STREAM* s); -BOOL update_recv(rdpUpdate* update, STREAM* s); +BOOL update_read_bitmap(rdpUpdate* update, wStream* s, BITMAP_UPDATE* bitmap_update); +BOOL update_read_palette(rdpUpdate* update, wStream* s, PALETTE_UPDATE* palette_update); +BOOL update_recv_play_sound(rdpUpdate* update, wStream* s); +BOOL update_recv_pointer(rdpUpdate* update, wStream* s); +BOOL update_recv(rdpUpdate* update, wStream* s); -BOOL update_read_pointer_position(STREAM* s, POINTER_POSITION_UPDATE* pointer_position); -BOOL update_read_pointer_system(STREAM* s, POINTER_SYSTEM_UPDATE* pointer_system); -BOOL update_read_pointer_color(STREAM* s, POINTER_COLOR_UPDATE* pointer_color); -BOOL update_read_pointer_new(STREAM* s, POINTER_NEW_UPDATE* pointer_new); -BOOL update_read_pointer_cached(STREAM* s, POINTER_CACHED_UPDATE* pointer_cached); +BOOL update_read_pointer_position(wStream* s, POINTER_POSITION_UPDATE* pointer_position); +BOOL update_read_pointer_system(wStream* s, POINTER_SYSTEM_UPDATE* pointer_system); +BOOL update_read_pointer_color(wStream* s, POINTER_COLOR_UPDATE* pointer_color); +BOOL update_read_pointer_new(wStream* s, POINTER_NEW_UPDATE* pointer_new); +BOOL update_read_pointer_cached(wStream* s, POINTER_CACHED_UPDATE* pointer_cached); -BOOL update_read_refresh_rect(rdpUpdate* update, STREAM* s); -BOOL update_read_suppress_output(rdpUpdate* update, STREAM* s); +BOOL update_read_refresh_rect(rdpUpdate* update, wStream* s); +BOOL update_read_suppress_output(rdpUpdate* update, wStream* s); void update_register_server_callbacks(rdpUpdate* update); void update_register_client_callbacks(rdpUpdate* update); diff --git a/libfreerdp/core/window.c b/libfreerdp/core/window.c index 6c5b207a7..418e4b696 100644 --- a/libfreerdp/core/window.c +++ b/libfreerdp/core/window.c @@ -28,7 +28,7 @@ #include "window.h" -BOOL update_read_icon_info(STREAM* s, ICON_INFO* icon_info) +BOOL update_read_icon_info(wStream* s, ICON_INFO* icon_info) { if(stream_get_left(s) < 8) return FALSE; @@ -78,7 +78,7 @@ BOOL update_read_icon_info(STREAM* s, ICON_INFO* icon_info) return TRUE; } -BOOL update_read_cached_icon_info(STREAM* s, CACHED_ICON_INFO* cached_icon_info) +BOOL update_read_cached_icon_info(wStream* s, CACHED_ICON_INFO* cached_icon_info) { if(stream_get_left(s) < 3) return FALSE; @@ -87,7 +87,7 @@ BOOL update_read_cached_icon_info(STREAM* s, CACHED_ICON_INFO* cached_icon_info) return TRUE; } -BOOL update_read_notify_icon_infotip(STREAM* s, NOTIFY_ICON_INFOTIP* notify_icon_infotip) +BOOL update_read_notify_icon_infotip(wStream* s, NOTIFY_ICON_INFOTIP* notify_icon_infotip) { if(stream_get_left(s) < 8) return FALSE; @@ -97,7 +97,7 @@ BOOL update_read_notify_icon_infotip(STREAM* s, NOTIFY_ICON_INFOTIP* notify_icon rail_read_unicode_string(s, ¬ify_icon_infotip->title); /* title */ } -BOOL update_read_window_state_order(STREAM* s, WINDOW_ORDER_INFO* orderInfo, WINDOW_STATE_ORDER* window_state) +BOOL update_read_window_state_order(wStream* s, WINDOW_ORDER_INFO* orderInfo, WINDOW_STATE_ORDER* window_state) { int i; int size; @@ -233,7 +233,7 @@ BOOL update_read_window_state_order(STREAM* s, WINDOW_ORDER_INFO* orderInfo, WIN return TRUE; } -BOOL update_read_window_icon_order(STREAM* s, WINDOW_ORDER_INFO* orderInfo, WINDOW_ICON_ORDER* window_icon) +BOOL update_read_window_icon_order(wStream* s, WINDOW_ORDER_INFO* orderInfo, WINDOW_ICON_ORDER* window_icon) { window_icon->iconInfo = (ICON_INFO*) malloc(sizeof(ICON_INFO)); ZeroMemory(window_icon->iconInfo, sizeof(ICON_INFO)); @@ -241,17 +241,17 @@ BOOL update_read_window_icon_order(STREAM* s, WINDOW_ORDER_INFO* orderInfo, WIND return update_read_icon_info(s, window_icon->iconInfo); /* iconInfo (ICON_INFO) */ } -BOOL update_read_window_cached_icon_order(STREAM* s, WINDOW_ORDER_INFO* orderInfo, WINDOW_CACHED_ICON_ORDER* window_cached_icon) +BOOL update_read_window_cached_icon_order(wStream* s, WINDOW_ORDER_INFO* orderInfo, WINDOW_CACHED_ICON_ORDER* window_cached_icon) { return update_read_cached_icon_info(s, &window_cached_icon->cachedIcon); /* cachedIcon (CACHED_ICON_INFO) */ } -void update_read_window_delete_order(STREAM* s, WINDOW_ORDER_INFO* orderInfo) +void update_read_window_delete_order(wStream* s, WINDOW_ORDER_INFO* orderInfo) { /* window deletion event */ } -BOOL update_recv_window_info_order(rdpUpdate* update, STREAM* s, WINDOW_ORDER_INFO* orderInfo) +BOOL update_recv_window_info_order(rdpUpdate* update, wStream* s, WINDOW_ORDER_INFO* orderInfo) { rdpContext* context = update->context; rdpWindowUpdate* window = update->window; @@ -294,7 +294,7 @@ BOOL update_recv_window_info_order(rdpUpdate* update, STREAM* s, WINDOW_ORDER_IN return TRUE; } -BOOL update_read_notification_icon_state_order(STREAM* s, WINDOW_ORDER_INFO* orderInfo, NOTIFY_ICON_STATE_ORDER* notify_icon_state) +BOOL update_read_notification_icon_state_order(wStream* s, WINDOW_ORDER_INFO* orderInfo, NOTIFY_ICON_STATE_ORDER* notify_icon_state) { if (orderInfo->fieldFlags & WINDOW_ORDER_FIELD_NOTIFY_VERSION) { if(stream_get_left(s) < 4) @@ -330,12 +330,12 @@ BOOL update_read_notification_icon_state_order(STREAM* s, WINDOW_ORDER_INFO* ord return TRUE; } -void update_read_notification_icon_delete_order(STREAM* s, WINDOW_ORDER_INFO* orderInfo) +void update_read_notification_icon_delete_order(wStream* s, WINDOW_ORDER_INFO* orderInfo) { /* notification icon deletion event */ } -BOOL update_recv_notification_icon_info_order(rdpUpdate* update, STREAM* s, WINDOW_ORDER_INFO* orderInfo) +BOOL update_recv_notification_icon_info_order(rdpUpdate* update, wStream* s, WINDOW_ORDER_INFO* orderInfo) { rdpContext* context = update->context; rdpWindowUpdate* window = update->window; @@ -365,7 +365,7 @@ BOOL update_recv_notification_icon_info_order(rdpUpdate* update, STREAM* s, WIND return TRUE; } -BOOL update_read_desktop_actively_monitored_order(STREAM* s, WINDOW_ORDER_INFO* orderInfo, MONITORED_DESKTOP_ORDER* monitored_desktop) +BOOL update_read_desktop_actively_monitored_order(wStream* s, WINDOW_ORDER_INFO* orderInfo, MONITORED_DESKTOP_ORDER* monitored_desktop) { int i; int size; @@ -401,12 +401,12 @@ BOOL update_read_desktop_actively_monitored_order(STREAM* s, WINDOW_ORDER_INFO* return TRUE; } -void update_read_desktop_non_monitored_order(STREAM* s, WINDOW_ORDER_INFO* orderInfo) +void update_read_desktop_non_monitored_order(wStream* s, WINDOW_ORDER_INFO* orderInfo) { /* non-monitored desktop notification event */ } -BOOL update_recv_desktop_info_order(rdpUpdate* update, STREAM* s, WINDOW_ORDER_INFO* orderInfo) +BOOL update_recv_desktop_info_order(rdpUpdate* update, wStream* s, WINDOW_ORDER_INFO* orderInfo) { rdpContext* context = update->context; rdpWindowUpdate* window = update->window; @@ -427,7 +427,7 @@ BOOL update_recv_desktop_info_order(rdpUpdate* update, STREAM* s, WINDOW_ORDER_I return TRUE; } -BOOL update_recv_altsec_window_order(rdpUpdate* update, STREAM* s) +BOOL update_recv_altsec_window_order(rdpUpdate* update, wStream* s) { UINT16 orderSize; rdpWindowUpdate* window = update->window; diff --git a/libfreerdp/core/window.h b/libfreerdp/core/window.h index 0b9725b08..b32e470ac 100644 --- a/libfreerdp/core/window.h +++ b/libfreerdp/core/window.h @@ -23,9 +23,9 @@ #include "update.h" -#include <freerdp/utils/stream.h> +#include <winpr/stream.h> -BOOL update_recv_altsec_window_order(rdpUpdate* update, STREAM* s); +BOOL update_recv_altsec_window_order(rdpUpdate* update, wStream* s); #ifdef WITH_DEBUG_WND #define DEBUG_WND(fmt, ...) DEBUG_CLASS(WND, fmt, ## __VA_ARGS__) diff --git a/libfreerdp/crypto/CMakeLists.txt b/libfreerdp/crypto/CMakeLists.txt index a1c96152b..15ab8894b 100644 --- a/libfreerdp/crypto/CMakeLists.txt +++ b/libfreerdp/crypto/CMakeLists.txt @@ -43,7 +43,7 @@ set(${MODULE_PREFIX}_LIBS if(MONOLITHIC_BUILD) set(${MODULE_PREFIX}_LIBS ${${MODULE_PREFIX}_LIBS} winpr) else() - set(${MODULE_PREFIX}_LIBS ${${MODULE_PREFIX}_LIBS} winpr-sspi winpr-library) + set(${MODULE_PREFIX}_LIBS ${${MODULE_PREFIX}_LIBS} winpr-sspi winpr-library winpr-path winpr-file) endif() if(WIN32) diff --git a/libfreerdp/crypto/ber.c b/libfreerdp/crypto/ber.c index 963471dce..3272ff687 100644 --- a/libfreerdp/crypto/ber.c +++ b/libfreerdp/crypto/ber.c @@ -22,9 +22,11 @@ #endif #include <stdio.h> +#include <winpr/crt.h> + #include <freerdp/crypto/ber.h> -BOOL ber_read_length(STREAM* s, int* length) +BOOL ber_read_length(wStream* s, int* length) { BYTE byte; @@ -59,7 +61,7 @@ BOOL ber_read_length(STREAM* s, int* length) * @param length length */ -int ber_write_length(STREAM* s, int length) +int ber_write_length(wStream* s, int length) { if (length > 0x7F) { @@ -97,7 +99,7 @@ int ber_get_content_length(int length) * @return */ -BOOL ber_read_universal_tag(STREAM* s, BYTE tag, BOOL pc) +BOOL ber_read_universal_tag(wStream* s, BYTE tag, BOOL pc) { BYTE byte; @@ -118,7 +120,7 @@ BOOL ber_read_universal_tag(STREAM* s, BYTE tag, BOOL pc) * @param pc primitive (FALSE) or constructed (TRUE) */ -void ber_write_universal_tag(STREAM* s, BYTE tag, BOOL pc) +void ber_write_universal_tag(wStream* s, BYTE tag, BOOL pc) { stream_write_BYTE(s, (BER_CLASS_UNIV | BER_PC(pc)) | (BER_TAG_MASK & tag)); } @@ -130,7 +132,7 @@ void ber_write_universal_tag(STREAM* s, BYTE tag, BOOL pc) * @param length length */ -BOOL ber_read_application_tag(STREAM* s, BYTE tag, int* length) +BOOL ber_read_application_tag(wStream* s, BYTE tag, int* length) { BYTE byte; @@ -174,7 +176,7 @@ BOOL ber_read_application_tag(STREAM* s, BYTE tag, int* length) * @param length length */ -void ber_write_application_tag(STREAM* s, BYTE tag, int length) +void ber_write_application_tag(wStream* s, BYTE tag, int length) { if (tag > 30) { @@ -189,7 +191,7 @@ void ber_write_application_tag(STREAM* s, BYTE tag, int length) } } -BOOL ber_read_contextual_tag(STREAM* s, BYTE tag, int* length, BOOL pc) +BOOL ber_read_contextual_tag(wStream* s, BYTE tag, int* length, BOOL pc) { BYTE byte; @@ -206,7 +208,7 @@ BOOL ber_read_contextual_tag(STREAM* s, BYTE tag, int* length, BOOL pc) return ber_read_length(s, length); } -int ber_write_contextual_tag(STREAM* s, BYTE tag, int length, BOOL pc) +int ber_write_contextual_tag(wStream* s, BYTE tag, int length, BOOL pc) { stream_write_BYTE(s, (BER_CLASS_CTXT | BER_PC(pc)) | (BER_TAG_MASK & tag)); return ber_write_length(s, length) + 1; @@ -217,7 +219,7 @@ int ber_skip_contextual_tag(int length) return _ber_skip_length(length) + 1; } -BOOL ber_read_sequence_tag(STREAM* s, int* length) +BOOL ber_read_sequence_tag(wStream* s, int* length) { BYTE byte; @@ -237,7 +239,7 @@ BOOL ber_read_sequence_tag(STREAM* s, int* length) * @param length length */ -int ber_write_sequence_tag(STREAM* s, int length) +int ber_write_sequence_tag(wStream* s, int length) { stream_write_BYTE(s, (BER_CLASS_UNIV | BER_CONSTRUCT) | (BER_TAG_MASK & BER_TAG_SEQUENCE)); return ber_write_length(s, length) + 1; @@ -253,7 +255,7 @@ int ber_skip_sequence_tag(int length) return 1 + _ber_skip_length(length); } -BOOL ber_read_enumerated(STREAM* s, BYTE* enumerated, BYTE count) +BOOL ber_read_enumerated(wStream* s, BYTE* enumerated, BYTE count) { int length; @@ -273,14 +275,14 @@ BOOL ber_read_enumerated(STREAM* s, BYTE* enumerated, BYTE count) return TRUE; } -void ber_write_enumerated(STREAM* s, BYTE enumerated, BYTE count) +void ber_write_enumerated(wStream* s, BYTE enumerated, BYTE count) { ber_write_universal_tag(s, BER_TAG_ENUMERATED, FALSE); ber_write_length(s, 1); stream_write_BYTE(s, enumerated); } -BOOL ber_read_bit_string(STREAM* s, int* length, BYTE* padding) +BOOL ber_read_bit_string(wStream* s, int* length, BYTE* padding) { if(!ber_read_universal_tag(s, BER_TAG_BIT_STRING, FALSE) || !ber_read_length(s, length)) @@ -299,21 +301,21 @@ BOOL ber_read_bit_string(STREAM* s, int* length, BYTE* padding) * @param length string length */ -void ber_write_octet_string(STREAM* s, const BYTE* oct_str, int length) +void ber_write_octet_string(wStream* s, const BYTE* oct_str, int length) { ber_write_universal_tag(s, BER_TAG_OCTET_STRING, FALSE); ber_write_length(s, length); stream_write(s, oct_str, length); } -BOOL ber_read_octet_string_tag(STREAM* s, int* length) +BOOL ber_read_octet_string_tag(wStream* s, int* length) { return ber_read_universal_tag(s, BER_TAG_OCTET_STRING, FALSE) && ber_read_length(s, length); } -int ber_write_octet_string_tag(STREAM* s, int length) +int ber_write_octet_string_tag(wStream* s, int length) { ber_write_universal_tag(s, BER_TAG_OCTET_STRING, FALSE); ber_write_length(s, length); @@ -331,7 +333,7 @@ int ber_skip_octet_string(int length) * @param value */ -BOOL ber_read_BOOL(STREAM* s, BOOL* value) +BOOL ber_read_BOOL(wStream* s, BOOL* value) { int length; BYTE v; @@ -354,14 +356,14 @@ BOOL ber_read_BOOL(STREAM* s, BOOL* value) * @param value */ -void ber_write_BOOL(STREAM* s, BOOL value) +void ber_write_BOOL(wStream* s, BOOL value) { ber_write_universal_tag(s, BER_TAG_BOOLEAN, FALSE); ber_write_length(s, 1); stream_write_BYTE(s, (value == TRUE) ? 0xFF : 0); } -BOOL ber_read_integer(STREAM* s, UINT32* value) +BOOL ber_read_integer(wStream* s, UINT32* value) { int length; @@ -397,12 +399,12 @@ BOOL ber_read_integer(STREAM* s, UINT32* value) } else if (length == 8) { - printf("%s: should implement reading an 8 bytes integer\n", __FUNCTION__); + fprintf(stderr, "%s: should implement reading an 8 bytes integer\n", __FUNCTION__); return FALSE; } else { - printf("%s: should implement reading an integer with length=%d\n", __FUNCTION__, length); + fprintf(stderr, "%s: should implement reading an integer with length=%d\n", __FUNCTION__, length); return FALSE; } @@ -415,7 +417,7 @@ BOOL ber_read_integer(STREAM* s, UINT32* value) * @param value */ -int ber_write_integer(STREAM* s, UINT32 value) +int ber_write_integer(wStream* s, UINT32 value) { ber_write_universal_tag(s, BER_TAG_INTEGER, FALSE); @@ -466,7 +468,7 @@ int ber_skip_integer(UINT32 value) return 0; } -BOOL ber_read_integer_length(STREAM* s, int* length) +BOOL ber_read_integer_length(wStream* s, int* length) { return ber_read_universal_tag(s, BER_TAG_INTEGER, FALSE) && diff --git a/libfreerdp/crypto/certificate.c b/libfreerdp/crypto/certificate.c index 01feefb15..5bfaa5c42 100644 --- a/libfreerdp/crypto/certificate.c +++ b/libfreerdp/crypto/certificate.c @@ -27,12 +27,12 @@ #include <string.h> #include <winpr/crt.h> +#include <winpr/file.h> +#include <winpr/path.h> #include <openssl/pem.h> #include <openssl/rsa.h> -#include <freerdp/utils/file.h> - static const char certificate_store_dir[] = "certs"; static const char certificate_known_hosts_file[] = "known_hosts"; @@ -40,29 +40,33 @@ static const char certificate_known_hosts_file[] = "known_hosts"; void certificate_store_init(rdpCertificateStore* certificate_store) { - char* config_path; rdpSettings* settings; settings = certificate_store->settings; - config_path = freerdp_get_config_path(settings); - certificate_store->path = freerdp_construct_path(config_path, (char*) certificate_store_dir); - - if (freerdp_check_file_exists(certificate_store->path) == FALSE) + if (!PathFileExistsA(settings->ConfigPath)) { - freerdp_mkdir(certificate_store->path); - printf("creating directory %s\n", certificate_store->path); + CreateDirectoryA(settings->ConfigPath, 0); + fprintf(stderr, "creating directory %s\n", settings->ConfigPath); } - certificate_store->file = freerdp_construct_path(config_path, (char*) certificate_known_hosts_file); + certificate_store->path = GetCombinedPath(settings->ConfigPath, (char*) certificate_store_dir); - if (freerdp_check_file_exists(certificate_store->file) == FALSE) + if (!PathFileExistsA(certificate_store->path)) + { + CreateDirectoryA(certificate_store->path, 0); + fprintf(stderr, "creating directory %s\n", certificate_store->path); + } + + certificate_store->file = GetCombinedPath(settings->ConfigPath, (char*) certificate_known_hosts_file); + + if (PathFileExistsA(certificate_store->file) == FALSE) { certificate_store->fp = fopen((char*) certificate_store->file, "w+"); if (certificate_store->fp == NULL) { - printf("certificate_store_open: error opening [%s] for writing\n", certificate_store->file); + fprintf(stderr, "certificate_store_open: error opening [%s] for writing\n", certificate_store->file); return; } diff --git a/libfreerdp/crypto/crypto.c b/libfreerdp/crypto/crypto.c index 6a8373396..483945f62 100644 --- a/libfreerdp/crypto/crypto.c +++ b/libfreerdp/crypto/crypto.c @@ -180,7 +180,7 @@ BOOL crypto_cert_get_public_key(CryptoCert cert, BYTE** PublicKey, DWORD* Public if (!pkey) { - printf("crypto_cert_get_public_key: X509_get_pubkey() failed\n"); + fprintf(stderr, "crypto_cert_get_public_key: X509_get_pubkey() failed\n"); status = FALSE; goto exit; } @@ -189,7 +189,7 @@ BOOL crypto_cert_get_public_key(CryptoCert cert, BYTE** PublicKey, DWORD* Public if (length < 1) { - printf("crypto_cert_get_public_key: i2d_PublicKey() failed\n"); + fprintf(stderr, "crypto_cert_get_public_key: i2d_PublicKey() failed\n"); status = FALSE; goto exit; } @@ -512,11 +512,11 @@ void crypto_cert_print_info(X509* xcert) issuer = crypto_cert_issuer(xcert); fp = crypto_cert_fingerprint(xcert); - printf("Certificate details:\n"); - printf("\tSubject: %s\n", subject); - printf("\tIssuer: %s\n", issuer); - printf("\tThumbprint: %s\n", fp); - printf("The above X.509 certificate could not be verified, possibly because you do not have " + fprintf(stderr, "Certificate details:\n"); + fprintf(stderr, "\tSubject: %s\n", subject); + fprintf(stderr, "\tIssuer: %s\n", issuer); + fprintf(stderr, "\tThumbprint: %s\n", fp); + fprintf(stderr, "The above X.509 certificate could not be verified, possibly because you do not have " "the CA certificate in your certificate store, or the certificate has expired. " "Please look at the documentation on how to create local certificate store for a private CA.\n"); diff --git a/libfreerdp/crypto/der.c b/libfreerdp/crypto/der.c index 888a00036..1cc5eb770 100644 --- a/libfreerdp/crypto/der.c +++ b/libfreerdp/crypto/der.c @@ -21,19 +21,21 @@ #include "config.h" #endif +#include <winpr/crt.h> + #include <freerdp/crypto/der.h> int _der_skip_length(int length) { - if (length > 0x81 && length <= 0x102) + if (length > 0x7F && length <= 0xFF) return 2; - else if (length > 0x102) + else if (length > 0xFF) return 3; else return 1; } -int der_write_length(STREAM* s, int length) +int der_write_length(wStream* s, int length) { if (length > 0x7F && length <= 0xFF) { @@ -69,13 +71,13 @@ int der_skip_contextual_tag(int length) return _der_skip_length(length) + 1; } -int der_write_contextual_tag(STREAM* s, BYTE tag, int length, BOOL pc) +int der_write_contextual_tag(wStream* s, BYTE tag, int length, BOOL pc) { stream_write_BYTE(s, (ER_CLASS_CTXT | ER_PC(pc)) | (ER_TAG_MASK & tag)); return der_write_length(s, length) + 1; } -void der_write_universal_tag(STREAM* s, BYTE tag, BOOL pc) +void der_write_universal_tag(wStream* s, BYTE tag, BOOL pc) { stream_write_BYTE(s, (ER_CLASS_UNIV | ER_PC(pc)) | (ER_TAG_MASK & tag)); } @@ -85,7 +87,7 @@ int der_skip_octet_string(int length) return 1 + _der_skip_length(length) + length; } -void der_write_octet_string(STREAM* s, BYTE* oct_str, int length) +void der_write_octet_string(wStream* s, BYTE* oct_str, int length) { der_write_universal_tag(s, ER_TAG_OCTET_STRING, FALSE); der_write_length(s, length); @@ -97,7 +99,7 @@ int der_skip_sequence_tag(int length) return 1 + _der_skip_length(length); } -int der_write_sequence_tag(STREAM* s, int length) +int der_write_sequence_tag(wStream* s, int length) { stream_write_BYTE(s, (ER_CLASS_UNIV | ER_CONSTRUCT) | (ER_TAG_MASK & ER_TAG_SEQUENCE)); return der_write_length(s, length) + 1; diff --git a/libfreerdp/crypto/er.c b/libfreerdp/crypto/er.c index e8109bba4..612752221 100644 --- a/libfreerdp/crypto/er.c +++ b/libfreerdp/crypto/er.c @@ -22,11 +22,13 @@ #include "config.h" #endif +#include <winpr/crt.h> + #include <freerdp/crypto/er.h> #include <freerdp/crypto/ber.h> #include <freerdp/crypto/der.h> -void er_read_length(STREAM* s, int* length) +void er_read_length(wStream* s, int* length) { BYTE byte; @@ -53,7 +55,7 @@ void er_read_length(STREAM* s, int* length) * @param length length */ -int er_write_length(STREAM* s, int length, BOOL flag) +int er_write_length(wStream* s, int length, BOOL flag) { if (flag) return der_write_length(s, length); @@ -84,7 +86,7 @@ int er_get_content_length(int length) * @return */ -BOOL er_read_universal_tag(STREAM* s, BYTE tag, BOOL pc) +BOOL er_read_universal_tag(wStream* s, BYTE tag, BOOL pc) { BYTE byte; @@ -103,7 +105,7 @@ BOOL er_read_universal_tag(STREAM* s, BYTE tag, BOOL pc) * @param pc primitive (FALSE) or constructed (TRUE) */ -void er_write_universal_tag(STREAM* s, BYTE tag, BOOL pc) +void er_write_universal_tag(wStream* s, BYTE tag, BOOL pc) { stream_write_BYTE(s, (ER_CLASS_UNIV | ER_PC(pc)) | (ER_TAG_MASK & tag)); } @@ -115,7 +117,7 @@ void er_write_universal_tag(STREAM* s, BYTE tag, BOOL pc) * @param length length */ -BOOL er_read_application_tag(STREAM* s, BYTE tag, int* length) +BOOL er_read_application_tag(wStream* s, BYTE tag, int* length) { BYTE byte; @@ -153,7 +155,7 @@ BOOL er_read_application_tag(STREAM* s, BYTE tag, int* length) * @param length length */ -void er_write_application_tag(STREAM* s, BYTE tag, int length, BOOL flag) +void er_write_application_tag(wStream* s, BYTE tag, int length, BOOL flag) { if (tag > 30) { @@ -168,7 +170,7 @@ void er_write_application_tag(STREAM* s, BYTE tag, int length, BOOL flag) } } -BOOL er_read_contextual_tag(STREAM* s, BYTE tag, int* length, BOOL pc) +BOOL er_read_contextual_tag(wStream* s, BYTE tag, int* length, BOOL pc) { BYTE byte; @@ -185,7 +187,7 @@ BOOL er_read_contextual_tag(STREAM* s, BYTE tag, int* length, BOOL pc) return TRUE; } -int er_write_contextual_tag(STREAM* s, BYTE tag, int length, BOOL pc, BOOL flag) +int er_write_contextual_tag(wStream* s, BYTE tag, int length, BOOL pc, BOOL flag) { stream_write_BYTE(s, (ER_CLASS_CTXT | ER_PC(pc)) | (ER_TAG_MASK & tag)); return er_write_length(s, length, flag) + 1; @@ -196,7 +198,7 @@ int er_skip_contextual_tag(int length) return _er_skip_length(length) + 1; } -BOOL er_read_sequence_tag(STREAM* s, int* length) +BOOL er_read_sequence_tag(wStream* s, int* length) { BYTE byte; @@ -216,7 +218,7 @@ BOOL er_read_sequence_tag(STREAM* s, int* length) * @param length length */ -int er_write_sequence_tag(STREAM* s, int length, BOOL flag) +int er_write_sequence_tag(wStream* s, int length, BOOL flag) { stream_write_BYTE(s, (ER_CLASS_UNIV | ER_CONSTRUCT) | (ER_TAG_MASK & ER_TAG_SEQUENCE)); return er_write_length(s, length, flag) + 1; @@ -232,7 +234,7 @@ int er_skip_sequence_tag(int length) return 1 + _er_skip_length(length); } -BOOL er_read_enumerated(STREAM* s, BYTE* enumerated, BYTE count) +BOOL er_read_enumerated(wStream* s, BYTE* enumerated, BYTE count) { int length; @@ -251,14 +253,14 @@ BOOL er_read_enumerated(STREAM* s, BYTE* enumerated, BYTE count) return TRUE; } -void er_write_enumerated(STREAM* s, BYTE enumerated, BYTE count, BOOL flag) +void er_write_enumerated(wStream* s, BYTE enumerated, BYTE count, BOOL flag) { er_write_universal_tag(s, ER_TAG_ENUMERATED, FALSE); er_write_length(s, 1, flag); stream_write_BYTE(s, enumerated); } -BOOL er_read_bit_string(STREAM* s, int* length, BYTE* padding) +BOOL er_read_bit_string(wStream* s, int* length, BYTE* padding) { er_read_universal_tag(s, ER_TAG_BIT_STRING, FALSE); er_read_length(s, length); @@ -267,7 +269,7 @@ BOOL er_read_bit_string(STREAM* s, int* length, BYTE* padding) return TRUE; } -BOOL er_write_bit_string_tag(STREAM* s, UINT32 length, BYTE padding, BOOL flag) +BOOL er_write_bit_string_tag(wStream* s, UINT32 length, BYTE padding, BOOL flag) { er_write_universal_tag(s, ER_TAG_BIT_STRING, FALSE); er_write_length(s, length, flag); @@ -275,7 +277,7 @@ BOOL er_write_bit_string_tag(STREAM* s, UINT32 length, BYTE padding, BOOL flag) return TRUE; } -BOOL er_read_octet_string(STREAM* s, int* length) +BOOL er_read_octet_string(wStream* s, int* length) { if(!er_read_universal_tag(s, ER_TAG_OCTET_STRING, FALSE)) return FALSE; @@ -291,14 +293,14 @@ BOOL er_read_octet_string(STREAM* s, int* length) * @param length string length */ -void er_write_octet_string(STREAM* s, BYTE* oct_str, int length, BOOL flag) +void er_write_octet_string(wStream* s, BYTE* oct_str, int length, BOOL flag) { er_write_universal_tag(s, ER_TAG_OCTET_STRING, FALSE); er_write_length(s, length, flag); stream_write(s, oct_str, length); } -int er_write_octet_string_tag(STREAM* s, int length, BOOL flag) +int er_write_octet_string_tag(wStream* s, int length, BOOL flag) { er_write_universal_tag(s, ER_TAG_OCTET_STRING, FALSE); er_write_length(s, length, flag); @@ -316,7 +318,7 @@ int er_skip_octet_string(int length) * @param value */ -BOOL er_read_BOOL(STREAM* s, BOOL* value) +BOOL er_read_BOOL(wStream* s, BOOL* value) { int length; BYTE v; @@ -337,14 +339,14 @@ BOOL er_read_BOOL(STREAM* s, BOOL* value) * @param value */ -void er_write_BOOL(STREAM* s, BOOL value) +void er_write_BOOL(wStream* s, BOOL value) { er_write_universal_tag(s, ER_TAG_BOOLEAN, FALSE); er_write_length(s, 1, FALSE); stream_write_BYTE(s, (value == TRUE) ? 0xFF : 0); } -BOOL er_read_integer(STREAM* s, UINT32* value) +BOOL er_read_integer(wStream* s, UINT32* value) { int length; @@ -382,7 +384,7 @@ BOOL er_read_integer(STREAM* s, UINT32* value) * @param value */ -int er_write_integer(STREAM* s, INT32 value) +int er_write_integer(wStream* s, INT32 value) { er_write_universal_tag(s, ER_TAG_INTEGER, FALSE); @@ -426,7 +428,7 @@ int er_skip_integer(INT32 value) return 0; } -BOOL er_read_integer_length(STREAM* s, int* length) +BOOL er_read_integer_length(wStream* s, int* length) { er_read_universal_tag(s, ER_TAG_INTEGER, FALSE); er_read_length(s, length); diff --git a/libfreerdp/crypto/per.c b/libfreerdp/crypto/per.c index 1665c0502..2a3631c01 100644 --- a/libfreerdp/crypto/per.c +++ b/libfreerdp/crypto/per.c @@ -30,7 +30,7 @@ * @return */ -BOOL per_read_length(STREAM* s, UINT16* length) +BOOL per_read_length(wStream* s, UINT16* length) { BYTE byte; @@ -63,7 +63,7 @@ BOOL per_read_length(STREAM* s, UINT16* length) * @param length length */ -void per_write_length(STREAM* s, int length) +void per_write_length(wStream* s, int length) { if (length > 0x7F) stream_write_UINT16_be(s, (length | 0x8000)); @@ -78,7 +78,7 @@ void per_write_length(STREAM* s, int length) * @return */ -BOOL per_read_choice(STREAM* s, BYTE* choice) +BOOL per_read_choice(wStream* s, BYTE* choice) { if (stream_get_left(s) < 1) return FALSE; @@ -93,7 +93,7 @@ BOOL per_read_choice(STREAM* s, BYTE* choice) * @param choice index of chosen field */ -void per_write_choice(STREAM* s, BYTE choice) +void per_write_choice(wStream* s, BYTE choice) { stream_write_BYTE(s, choice); } @@ -105,7 +105,7 @@ void per_write_choice(STREAM* s, BYTE choice) * @return */ -BOOL per_read_selection(STREAM* s, BYTE* selection) +BOOL per_read_selection(wStream* s, BYTE* selection) { if (stream_get_left(s) < 1) return FALSE; @@ -120,7 +120,7 @@ BOOL per_read_selection(STREAM* s, BYTE* selection) * @param selection bit map of selected fields */ -void per_write_selection(STREAM* s, BYTE selection) +void per_write_selection(wStream* s, BYTE selection) { stream_write_BYTE(s, selection); } @@ -132,7 +132,7 @@ void per_write_selection(STREAM* s, BYTE selection) * @return */ -BOOL per_read_number_of_sets(STREAM* s, BYTE* number) +BOOL per_read_number_of_sets(wStream* s, BYTE* number) { if (stream_get_left(s) < 1) return FALSE; @@ -147,7 +147,7 @@ BOOL per_read_number_of_sets(STREAM* s, BYTE* number) * @param number number of sets */ -void per_write_number_of_sets(STREAM* s, BYTE number) +void per_write_number_of_sets(wStream* s, BYTE number) { stream_write_BYTE(s, number); } @@ -158,7 +158,7 @@ void per_write_number_of_sets(STREAM* s, BYTE number) * @param length */ -BOOL per_read_padding(STREAM* s, int length) +BOOL per_read_padding(wStream* s, int length) { if (stream_get_left(s) < length) return FALSE; @@ -173,7 +173,7 @@ BOOL per_read_padding(STREAM* s, int length) * @param length */ -void per_write_padding(STREAM* s, int length) +void per_write_padding(wStream* s, int length) { int i; @@ -188,7 +188,7 @@ void per_write_padding(STREAM* s, int length) * @return */ -BOOL per_read_integer(STREAM* s, UINT32* integer) +BOOL per_read_integer(wStream* s, UINT32* integer) { UINT16 length; @@ -214,7 +214,7 @@ BOOL per_read_integer(STREAM* s, UINT32* integer) * @param integer integer */ -void per_write_integer(STREAM* s, UINT32 integer) +void per_write_integer(wStream* s, UINT32 integer) { if (integer <= 0xFF) { @@ -241,7 +241,7 @@ void per_write_integer(STREAM* s, UINT32 integer) * @return */ -BOOL per_read_integer16(STREAM* s, UINT16* integer, UINT16 min) +BOOL per_read_integer16(wStream* s, UINT16* integer, UINT16 min) { if (stream_get_left(s) < 2) return FALSE; @@ -263,7 +263,7 @@ BOOL per_read_integer16(STREAM* s, UINT16* integer, UINT16 min) * @param min minimum value */ -void per_write_integer16(STREAM* s, UINT16 integer, UINT16 min) +void per_write_integer16(wStream* s, UINT16 integer, UINT16 min) { stream_write_UINT16_be(s, integer - min); } @@ -276,7 +276,7 @@ void per_write_integer16(STREAM* s, UINT16 integer, UINT16 min) * @return */ -BOOL per_read_enumerated(STREAM* s, BYTE* enumerated, BYTE count) +BOOL per_read_enumerated(wStream* s, BYTE* enumerated, BYTE count) { if (stream_get_left(s) < 1) return FALSE; @@ -298,7 +298,7 @@ BOOL per_read_enumerated(STREAM* s, BYTE* enumerated, BYTE count) * @return */ -void per_write_enumerated(STREAM* s, BYTE enumerated, BYTE count) +void per_write_enumerated(wStream* s, BYTE enumerated, BYTE count) { stream_write_BYTE(s, enumerated); } @@ -310,7 +310,7 @@ void per_write_enumerated(STREAM* s, BYTE enumerated, BYTE count) * @return */ -BOOL per_read_object_identifier(STREAM* s, BYTE oid[6]) +BOOL per_read_object_identifier(wStream* s, BYTE oid[6]) { BYTE t12; UINT16 length; @@ -352,7 +352,7 @@ BOOL per_read_object_identifier(STREAM* s, BYTE oid[6]) * @param oid object identifier (oid) */ -void per_write_object_identifier(STREAM* s, BYTE oid[6]) +void per_write_object_identifier(wStream* s, BYTE oid[6]) { BYTE t12 = (oid[0] << 4) & (oid[1] & 0x0F); stream_write_BYTE(s, 5); /* length */ @@ -370,7 +370,7 @@ void per_write_object_identifier(STREAM* s, BYTE oid[6]) * @param length string length */ -void per_write_string(STREAM* s, BYTE* str, int length) +void per_write_string(wStream* s, BYTE* str, int length) { int i; @@ -387,7 +387,7 @@ void per_write_string(STREAM* s, BYTE* str, int length) * @return */ -BOOL per_read_octet_string(STREAM* s, BYTE* oct_str, int length, int min) +BOOL per_read_octet_string(wStream* s, BYTE* oct_str, int length, int min) { int i; UINT16 mlength; @@ -402,7 +402,7 @@ BOOL per_read_octet_string(STREAM* s, BYTE* oct_str, int length, int min) if (stream_get_left(s) < length) return FALSE; - a_oct_str = s->p; + a_oct_str = s->pointer; stream_seek(s, length); for (i = 0; i < length; i++) @@ -422,7 +422,7 @@ BOOL per_read_octet_string(STREAM* s, BYTE* oct_str, int length, int min) * @param min minimum string length */ -void per_write_octet_string(STREAM* s, BYTE* oct_str, int length, int min) +void per_write_octet_string(wStream* s, BYTE* oct_str, int length, int min) { int i; int mlength; @@ -443,7 +443,7 @@ void per_write_octet_string(STREAM* s, BYTE* oct_str, int length, int min) * @param min minimum string length */ -BOOL per_read_numeric_string(STREAM* s, int min) +BOOL per_read_numeric_string(wStream* s, int min) { int length; UINT16 mlength; @@ -468,7 +468,7 @@ BOOL per_read_numeric_string(STREAM* s, int min) * @param min minimum string length */ -void per_write_numeric_string(STREAM* s, BYTE* num_str, int length, int min) +void per_write_numeric_string(wStream* s, BYTE* num_str, int length, int min) { int i; int mlength; diff --git a/libfreerdp/crypto/tls.c b/libfreerdp/crypto/tls.c index 56d2e4759..878502f7f 100644 --- a/libfreerdp/crypto/tls.c +++ b/libfreerdp/crypto/tls.c @@ -24,7 +24,7 @@ #include <winpr/crt.h> #include <winpr/sspi.h> -#include <freerdp/utils/stream.h> +#include <winpr/stream.h> #include <freerdp/utils/tcp.h> #include <freerdp/crypto/tls.h> @@ -41,7 +41,7 @@ static CryptoCert tls_get_certificate(rdpTls* tls, BOOL peer) if (!server_cert) { - printf("tls_get_certificate: failed to get the server TLS certificate\n"); + fprintf(stderr, "tls_get_certificate: failed to get the server TLS certificate\n"); cert = NULL; } else @@ -105,7 +105,7 @@ BOOL tls_connect(rdpTls* tls) if (tls->ctx == NULL) { - printf("SSL_CTX_new failed\n"); + fprintf(stderr, "SSL_CTX_new failed\n"); return FALSE; } @@ -146,13 +146,13 @@ BOOL tls_connect(rdpTls* tls) if (tls->ssl == NULL) { - printf("SSL_new failed\n"); + fprintf(stderr, "SSL_new failed\n"); return FALSE; } if (SSL_set_fd(tls->ssl, tls->sockfd) < 1) { - printf("SSL_set_fd failed\n"); + fprintf(stderr, "SSL_set_fd failed\n"); return FALSE; } @@ -170,7 +170,7 @@ BOOL tls_connect(rdpTls* tls) if (cert == NULL) { - printf("tls_connect: tls_get_certificate failed to return the server certificate.\n"); + fprintf(stderr, "tls_connect: tls_get_certificate failed to return the server certificate.\n"); return FALSE; } @@ -178,14 +178,14 @@ BOOL tls_connect(rdpTls* tls) if (!crypto_cert_get_public_key(cert, &tls->PublicKey, &tls->PublicKeyLength)) { - printf("tls_connect: crypto_cert_get_public_key failed to return the server public key.\n"); + fprintf(stderr, "tls_connect: crypto_cert_get_public_key failed to return the server public key.\n"); tls_free_certificate(cert); return FALSE; } if (!tls_verify_certificate(tls, cert, tls->settings->ServerHostname)) { - printf("tls_connect: certificate not trusted, aborting.\n"); + fprintf(stderr, "tls_connect: certificate not trusted, aborting.\n"); tls_disconnect(tls); tls_free_certificate(cert); return FALSE; @@ -206,7 +206,7 @@ BOOL tls_accept(rdpTls* tls, const char* cert_file, const char* privatekey_file) if (tls->ctx == NULL) { - printf("SSL_CTX_new failed\n"); + fprintf(stderr, "SSL_CTX_new failed\n"); return FALSE; } @@ -249,11 +249,11 @@ BOOL tls_accept(rdpTls* tls, const char* cert_file, const char* privatekey_file) SSL_CTX_set_options(tls->ctx, options); - printf("private key file: %s\n", privatekey_file); + fprintf(stderr, "private key file: %s\n", privatekey_file); if (SSL_CTX_use_RSAPrivateKey_file(tls->ctx, privatekey_file, SSL_FILETYPE_PEM) <= 0) { - printf("SSL_CTX_use_RSAPrivateKey_file failed\n"); + fprintf(stderr, "SSL_CTX_use_RSAPrivateKey_file failed\n"); return FALSE; } @@ -261,13 +261,13 @@ BOOL tls_accept(rdpTls* tls, const char* cert_file, const char* privatekey_file) if (tls->ssl == NULL) { - printf("SSL_new failed\n"); + fprintf(stderr, "SSL_new failed\n"); return FALSE; } if (SSL_use_certificate_file(tls->ssl, cert_file, SSL_FILETYPE_PEM) <= 0) { - printf("SSL_use_certificate_file failed\n"); + fprintf(stderr, "SSL_use_certificate_file failed\n"); return FALSE; } @@ -275,13 +275,13 @@ BOOL tls_accept(rdpTls* tls, const char* cert_file, const char* privatekey_file) if (cert == NULL) { - printf("tls_connect: tls_get_certificate failed to return the server certificate.\n"); + fprintf(stderr, "tls_connect: tls_get_certificate failed to return the server certificate.\n"); return FALSE; } if (!crypto_cert_get_public_key(cert, &tls->PublicKey, &tls->PublicKeyLength)) { - printf("tls_connect: crypto_cert_get_public_key failed to return the server public key.\n"); + fprintf(stderr, "tls_connect: crypto_cert_get_public_key failed to return the server public key.\n"); tls_free_certificate(cert); return FALSE; } @@ -290,7 +290,7 @@ BOOL tls_accept(rdpTls* tls, const char* cert_file, const char* privatekey_file) if (SSL_set_fd(tls->ssl, tls->sockfd) < 1) { - printf("SSL_set_fd failed\n"); + fprintf(stderr, "SSL_set_fd failed\n"); return FALSE; } @@ -319,7 +319,7 @@ BOOL tls_accept(rdpTls* tls, const char* cert_file, const char* privatekey_file) } } - printf("TLS connection accepted\n"); + fprintf(stderr, "TLS connection accepted\n"); return TRUE; } @@ -343,7 +343,7 @@ int tls_read(rdpTls* tls, BYTE* data, int length) { error = SSL_get_error(tls->ssl, status); - //printf("tls_read: length: %d status: %d error: 0x%08X\n", + //fprintf(stderr, "tls_read: length: %d status: %d error: 0x%08X\n", // length, status, error); switch (error) @@ -392,7 +392,7 @@ int tls_write(rdpTls* tls, BYTE* data, int length) { error = SSL_get_error(tls->ssl, status); - //printf("tls_write: length: %d status: %d error: 0x%08X\n", length, status, error); + //fprintf(stderr, "tls_write: length: %d status: %d error: 0x%08X\n", length, status, error); switch (error) { @@ -454,7 +454,7 @@ static void tls_errors(const char *prefix) unsigned long error; while ((error = ERR_get_error()) != 0) - printf("%s: %s\n", prefix, ERR_error_string(error, NULL)); + fprintf(stderr, "%s: %s\n", prefix, ERR_error_string(error, NULL)); } BOOL tls_print_error(char* func, SSL* connection, int value) @@ -462,29 +462,29 @@ BOOL tls_print_error(char* func, SSL* connection, int value) switch (SSL_get_error(connection, value)) { case SSL_ERROR_ZERO_RETURN: - printf("%s: Server closed TLS connection\n", func); + fprintf(stderr, "%s: Server closed TLS connection\n", func); return TRUE; case SSL_ERROR_WANT_READ: - printf("%s: SSL_ERROR_WANT_READ\n", func); + fprintf(stderr, "%s: SSL_ERROR_WANT_READ\n", func); return FALSE; case SSL_ERROR_WANT_WRITE: - printf("%s: SSL_ERROR_WANT_WRITE\n", func); + fprintf(stderr, "%s: SSL_ERROR_WANT_WRITE\n", func); return FALSE; case SSL_ERROR_SYSCALL: - printf("%s: I/O error\n", func); + fprintf(stderr, "%s: I/O error\n", func); tls_errors(func); return TRUE; case SSL_ERROR_SSL: - printf("%s: Failure in SSL library (protocol error?)\n", func); + fprintf(stderr, "%s: Failure in SSL library (protocol error?)\n", func); tls_errors(func); return TRUE; default: - printf("%s: Unknown error\n", func); + fprintf(stderr, "%s: Unknown error\n", func); tls_errors(func); return TRUE; } @@ -647,48 +647,48 @@ BOOL tls_verify_certificate(rdpTls* tls, CryptoCert cert, char* hostname) void tls_print_certificate_error(char* hostname, char* fingerprint) { - printf("The host key for %s has changed\n", hostname); - printf("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n"); - printf("@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @\n"); - printf("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n"); - printf("IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!\n"); - printf("Someone could be eavesdropping on you right now (man-in-the-middle attack)!\n"); - printf("It is also possible that a host key has just been changed.\n"); - printf("The fingerprint for the host key sent by the remote host is\n%s\n", fingerprint); - printf("Please contact your system administrator.\n"); - printf("Add correct host key in ~/.freerdp/known_hosts to get rid of this message.\n"); - printf("Host key for %s has changed and you have requested strict checking.\n", hostname); - printf("Host key verification failed.\n"); + fprintf(stderr, "The host key for %s has changed\n", hostname); + fprintf(stderr, "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n"); + fprintf(stderr, "@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @\n"); + fprintf(stderr, "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n"); + fprintf(stderr, "IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!\n"); + fprintf(stderr, "Someone could be eavesdropping on you right now (man-in-the-middle attack)!\n"); + fprintf(stderr, "It is also possible that a host key has just been changed.\n"); + fprintf(stderr, "The fingerprint for the host key sent by the remote host is\n%s\n", fingerprint); + fprintf(stderr, "Please contact your system administrator.\n"); + fprintf(stderr, "Add correct host key in ~/.freerdp/known_hosts to get rid of this message.\n"); + fprintf(stderr, "Host key for %s has changed and you have requested strict checking.\n", hostname); + fprintf(stderr, "Host key verification failed.\n"); } void tls_print_certificate_name_mismatch_error(char* hostname, char* common_name, char** alt_names, int alt_names_count) { int index; - printf("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n"); - printf("@ WARNING: CERTIFICATE NAME MISMATCH! @\n"); - printf("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n"); - printf("The hostname used for this connection (%s) \n", hostname); + fprintf(stderr, "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n"); + fprintf(stderr, "@ WARNING: CERTIFICATE NAME MISMATCH! @\n"); + fprintf(stderr, "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n"); + fprintf(stderr, "The hostname used for this connection (%s) \n", hostname); if (alt_names_count < 1) { - printf("does not match the name given in the certificate:\n"); - printf("%s\n", common_name); + fprintf(stderr, "does not match the name given in the certificate:\n"); + fprintf(stderr, "%s\n", common_name); } else { - printf("does not match the names given in the certificate:\n"); - printf("%s", common_name); + fprintf(stderr, "does not match the names given in the certificate:\n"); + fprintf(stderr, "%s", common_name); for (index = 0; index < alt_names_count; index++) { - printf(", %s", alt_names[index]); + fprintf(stderr, ", %s", alt_names[index]); } - printf("\n"); + fprintf(stderr, "\n"); } - printf("A valid certificate for the wrong name should NOT be trusted!\n"); + fprintf(stderr, "A valid certificate for the wrong name should NOT be trusted!\n"); } rdpTls* tls_new(rdpSettings* settings) diff --git a/libfreerdp/gdi/16bpp.c b/libfreerdp/gdi/16bpp.c index e7826550e..f9e1a1be5 100644 --- a/libfreerdp/gdi/16bpp.c +++ b/libfreerdp/gdi/16bpp.c @@ -388,7 +388,7 @@ static int BitBlt_DSPDxax_16bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWi if (hdcSrc->bytesPerPixel != 1) { - printf("BitBlt_DSPDxax expects 1 bpp, unimplemented for %d\n", hdcSrc->bytesPerPixel); + fprintf(stderr, "BitBlt_DSPDxax expects 1 bpp, unimplemented for %d\n", hdcSrc->bytesPerPixel); return 0; } @@ -846,7 +846,7 @@ int BitBlt_16bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidth, int nHeigh break; } - printf("BitBlt: unknown rop: 0x%08X\n", rop); + fprintf(stderr, "BitBlt: unknown rop: 0x%08X\n", rop); return 1; } @@ -891,8 +891,7 @@ int PatBlt_16bpp(HGDI_DC hdc, int nXLeft, int nYLeft, int nWidth, int nHeight, i break; } - printf("PatBlt: unknown rop: 0x%08X\n", rop); - + fprintf(stderr, "PatBlt: unknown rop: 0x%08X\n", rop); return 1; } diff --git a/libfreerdp/gdi/32bpp.c b/libfreerdp/gdi/32bpp.c index de4fad7ad..3b3c05ef4 100644 --- a/libfreerdp/gdi/32bpp.c +++ b/libfreerdp/gdi/32bpp.c @@ -946,7 +946,7 @@ int BitBlt_32bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidth, int nHeigh break; } - printf("BitBlt: unknown rop: 0x%08X\n", rop); + fprintf(stderr, "BitBlt: unknown rop: 0x%08X\n", rop); return 1; } @@ -991,8 +991,7 @@ int PatBlt_32bpp(HGDI_DC hdc, int nXLeft, int nYLeft, int nWidth, int nHeight, i break; } - printf("PatBlt: unknown rop: 0x%08X\n", rop); - + fprintf(stderr, "PatBlt: unknown rop: 0x%08X\n", rop); return 1; } diff --git a/libfreerdp/gdi/8bpp.c b/libfreerdp/gdi/8bpp.c index a5b0d51d5..c4966cece 100644 --- a/libfreerdp/gdi/8bpp.c +++ b/libfreerdp/gdi/8bpp.c @@ -762,7 +762,7 @@ int BitBlt_8bpp(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight break; } - printf("BitBlt: unknown rop: 0x%08X\n", rop); + fprintf(stderr, "BitBlt: unknown rop: 0x%08X\n", rop); return 1; } @@ -807,7 +807,7 @@ int PatBlt_8bpp(HGDI_DC hdc, int nXLeft, int nYLeft, int nWidth, int nHeight, in break; } - printf("PatBlt: unknown rop: 0x%08X\n", rop); + fprintf(stderr, "PatBlt: unknown rop: 0x%08X\n", rop); return 1; } diff --git a/libfreerdp/gdi/gdi.c b/libfreerdp/gdi/gdi.c index f16dd45af..b68b31322 100644 --- a/libfreerdp/gdi/gdi.c +++ b/libfreerdp/gdi/gdi.c @@ -341,7 +341,7 @@ INLINE BYTE* gdi_get_bitmap_pointer(HGDI_DC hdcBmp, int x, int y) } else { - printf("gdi_get_bitmap_pointer: requesting invalid pointer: (%d,%d) in %dx%d\n", x, y, hBmp->width, hBmp->height); + fprintf(stderr, "gdi_get_bitmap_pointer: requesting invalid pointer: (%d,%d) in %dx%d\n", x, y, hBmp->width, hBmp->height); return 0; } } @@ -543,7 +543,7 @@ void gdi_patblt(rdpContext* context, PATBLT_ORDER* patblt) } else { - printf("unimplemented brush style:%d\n", brush->style); + fprintf(stderr, "unimplemented brush style:%d\n", brush->style); } } @@ -715,28 +715,28 @@ void gdi_mem3blt(rdpContext* context, MEM3BLT_ORDER* mem3blt) } else { - printf("Mem3Blt unimplemented brush style:%d\n", brush->style); + fprintf(stderr, "Mem3Blt unimplemented brush style:%d\n", brush->style); } } void gdi_polygon_sc(rdpContext* context, POLYGON_SC_ORDER* polygon_sc) { - printf("PolygonSC\n"); + fprintf(stderr, "PolygonSC\n"); } void gdi_polygon_cb(rdpContext* context, POLYGON_CB_ORDER* polygon_cb) { - printf("PolygonCB\n"); + fprintf(stderr, "PolygonCB\n"); } void gdi_ellipse_sc(rdpContext* context, ELLIPSE_SC_ORDER* ellipse_sc) { - printf("EllipseSC\n"); + fprintf(stderr, "EllipseSC\n"); } void gdi_ellipse_cb(rdpContext* context, ELLIPSE_CB_ORDER* ellipse_cb) { - printf("EllipseCB\n"); + fprintf(stderr, "EllipseCB\n"); } int tilenum = 0; @@ -845,7 +845,7 @@ void gdi_surface_bits(rdpContext* context, SURFACE_BITS_COMMAND* surface_bits_co } else { - printf("Unsupported codecID %d\n", surface_bits_command->codecID); + fprintf(stderr, "Unsupported codecID %d\n", surface_bits_command->codecID); } if (tile_bitmap != NULL) diff --git a/libfreerdp/gdi/graphics.c b/libfreerdp/gdi/graphics.c index 2ef87d23b..dcc3c46e7 100644 --- a/libfreerdp/gdi/graphics.c +++ b/libfreerdp/gdi/graphics.c @@ -30,6 +30,7 @@ #include <freerdp/gdi/bitmap.h> #include <freerdp/codec/jpeg.h> #include <freerdp/codec/rfx.h> +#include <freerdp/codec/nsc.h> #include <freerdp/gdi/drawing.h> #include <freerdp/gdi/clipping.h> #include <freerdp/codec/color.h> @@ -116,7 +117,9 @@ void gdi_Bitmap_Decompress(rdpContext* context, rdpBitmap* bitmap, switch (codec_id) { case RDP_CODEC_ID_NSCODEC: - printf("gdi_Bitmap_Decompress: nsc not done\n"); + gdi = context->gdi; + nsc_process_message(gdi->nsc_context, bpp, width, height, data, length); + freerdp_image_flip(((NSC_CONTEXT*)gdi->nsc_context)->bmpdata, bitmap->data, width, height, bpp); break; case RDP_CODEC_ID_REMOTEFX: gdi = context->gdi; @@ -124,7 +127,7 @@ void gdi_Bitmap_Decompress(rdpContext* context, rdpBitmap* bitmap, msg = rfx_process_message(gdi->rfx_context, data, length); if (msg == NULL) { - printf("gdi_Bitmap_Decompress: rfx Decompression Failed\n"); + fprintf(stderr, "gdi_Bitmap_Decompress: rfx Decompression Failed\n"); } else { @@ -147,7 +150,7 @@ void gdi_Bitmap_Decompress(rdpContext* context, rdpBitmap* bitmap, #ifdef WITH_JPEG if (!jpeg_decompress(data, bitmap->data, width, height, length, bpp)) { - printf("gdi_Bitmap_Decompress: jpeg Decompression Failed\n"); + fprintf(stderr, "gdi_Bitmap_Decompress: jpeg Decompression Failed\n"); } #endif break; @@ -158,7 +161,7 @@ void gdi_Bitmap_Decompress(rdpContext* context, rdpBitmap* bitmap, if (status == FALSE) { - printf("gdi_Bitmap_Decompress: Bitmap Decompression Failed\n"); + fprintf(stderr, "gdi_Bitmap_Decompress: Bitmap Decompression Failed\n"); } } else diff --git a/libfreerdp/locale/timezone.c b/libfreerdp/locale/timezone.c index 2b0492e37..3070f1fa6 100644 --- a/libfreerdp/locale/timezone.c +++ b/libfreerdp/locale/timezone.c @@ -1565,7 +1565,7 @@ char* freerdp_get_unix_timezone_identifier() return tzid; } - printf("Unable to detect time zone\n"); + fprintf(stderr, "Unable to detect time zone\n"); return tzid; #else return 0; @@ -1626,7 +1626,7 @@ TIME_ZONE_ENTRY* freerdp_detect_windows_time_zone(UINT32 bias) } } - printf("Unable to find a match for unix timezone: %s\n", tzid); + fprintf(stderr, "Unable to find a match for unix timezone: %s\n", tzid); free(tzid); return NULL; } @@ -1640,14 +1640,14 @@ TIME_ZONE_RULE_ENTRY* freerdp_get_current_time_zone_rule(TIME_ZONE_RULE_ENTRY* r for (i = 0; i < (int) count; i++) { - if ((rules[i].TicksStart <= windows_time) && (windows_time >= rules[i].TicksEnd)) + if ((rules[i].TicksStart >= windows_time) && (windows_time >= rules[i].TicksEnd)) { - /*printf("Got rule %d from table at %p with count %u\n", i, rules, count);*/ + /*fprintf(stderr, "Got rule %d from table at %p with count %u\n", i, rules, count);*/ return &rules[i]; } } - printf("Unable to get current timezone rule\n"); + fprintf(stderr, "Unable to get current timezone rule\n"); return NULL; } @@ -1657,14 +1657,14 @@ void freerdp_time_zone_detect(TIME_ZONE_INFO* clientTimeZone) TIME_ZONE_ENTRY* tz; struct tm* local_time; + clientTimeZone->standardBias = 0; + time(&t); local_time = localtime(&t); #ifdef HAVE_TM_GMTOFF - if (local_time->tm_gmtoff >= 0) - clientTimeZone->bias = (UINT32) (local_time->tm_gmtoff / 60); - else - clientTimeZone->bias = (UINT32) (1440 + (INT32) (local_time->tm_gmtoff / 60)); + clientTimeZone->bias = timezone / 60; + DEBUG_TIMEZONE("tzname[std]: %s, tzname[dst]: %s, timezone: %ld, Daylight: %d", tzname[0], tzname[1], timezone, daylight); #elif defined(sun) if (local_time->tm_isdst > 0) clientTimeZone->bias = (UINT32) (altzone / 3600); @@ -1673,19 +1673,6 @@ void freerdp_time_zone_detect(TIME_ZONE_INFO* clientTimeZone) #else clientTimeZone->bias = 0; #endif - if (local_time->tm_isdst > 0) - { - clientTimeZone->standardBias = clientTimeZone->bias - 60; - clientTimeZone->daylightBias = clientTimeZone->bias; - } - else - { - clientTimeZone->standardBias = clientTimeZone->bias; - clientTimeZone->daylightBias = clientTimeZone->bias + 60; - } - DEBUG_TIMEZONE("Bias: %d, StandardBias: %d, DaylightBias: %d", - clientTimeZone->bias, clientTimeZone->standardBias, - clientTimeZone->daylightBias); tz = freerdp_detect_windows_time_zone(clientTimeZone->bias); @@ -1694,8 +1681,7 @@ void freerdp_time_zone_detect(TIME_ZONE_INFO* clientTimeZone) DEBUG_TIMEZONE("tz: Id='%s' Bias=%d DST=%d dn='%s' sn='%s' dln='%s'", tz->Id, tz->Bias, tz->SupportsDST, tz->DisplayName, tz->StandardName, tz->DaylightName); - /* Not printed: RuleTable, RuleTableCount */ - clientTimeZone->bias = tz->Bias; + sprintf(clientTimeZone->standardName, "%s", tz->StandardName); sprintf(clientTimeZone->daylightName, "%s", tz->DaylightName); @@ -1704,11 +1690,9 @@ void freerdp_time_zone_detect(TIME_ZONE_INFO* clientTimeZone) TIME_ZONE_RULE_ENTRY* rule; rule = freerdp_get_current_time_zone_rule(tz->RuleTable, tz->RuleTableCount); - /* issue #574 -- temporarily disabled this block as it seems to be setting the wrong time if (rule != NULL) { - clientTimeZone->standardBias = 0; - clientTimeZone->daylightBias = rule->DaylightDelta; + clientTimeZone->daylightBias = -rule->DaylightDelta; clientTimeZone->standardDate.wYear = rule->StandardDate.wYear; clientTimeZone->standardDate.wMonth = rule->StandardDate.wMonth; @@ -1728,9 +1712,7 @@ void freerdp_time_zone_detect(TIME_ZONE_INFO* clientTimeZone) clientTimeZone->daylightDate.wSecond = rule->DaylightDate.wSecond; clientTimeZone->daylightDate.wMilliseconds = rule->DaylightDate.wMilliseconds; } - */ } - free(tz); } else diff --git a/libfreerdp/rail/icon.c b/libfreerdp/rail/icon.c index 15ca11412..0dbaab096 100644 --- a/libfreerdp/rail/icon.c +++ b/libfreerdp/rail/icon.c @@ -24,7 +24,7 @@ #include <winpr/crt.h> #include <winpr/print.h> -#include <freerdp/utils/stream.h> +#include <winpr/stream.h> #include <freerdp/rail/icon.h> @@ -34,13 +34,13 @@ ICON_INFO* icon_cache_get(rdpIconCache* cache, BYTE id, UINT16 index, void** ext if (id >= cache->numCaches) { - printf("invalid window icon cache id:%d\n", id); + fprintf(stderr, "invalid window icon cache id:%d\n", id); return (ICON_INFO*) NULL; } if (index >= cache->numCacheEntries) { - printf("invalid window icon cache index:%d in cache id:%d\n", index, id); + fprintf(stderr, "invalid window icon cache index:%d in cache id:%d\n", index, id); return (ICON_INFO*) NULL; } @@ -56,13 +56,13 @@ void icon_cache_put(rdpIconCache* cache, BYTE id, UINT16 index, ICON_INFO* entry { if (id >= cache->numCaches) { - printf("invalid window icon cache id:%d\n", id); + fprintf(stderr, "invalid window icon cache id:%d\n", id); return; } if (index >= cache->numCacheEntries) { - printf("invalid window icon cache index:%d in cache id:%d\n", index, id); + fprintf(stderr, "invalid window icon cache index:%d in cache id:%d\n", index, id); return; } diff --git a/libfreerdp/rail/rail.c b/libfreerdp/rail/rail.c index ae11d79a9..e3c994621 100644 --- a/libfreerdp/rail/rail.c +++ b/libfreerdp/rail/rail.c @@ -23,7 +23,7 @@ #include <winpr/crt.h> -#include <freerdp/utils/stream.h> +#include <winpr/stream.h> #include "librail.h" diff --git a/libfreerdp/rail/window.c b/libfreerdp/rail/window.c index 35a55e3b7..ed50de1f4 100644 --- a/libfreerdp/rail/window.c +++ b/libfreerdp/rail/window.c @@ -25,7 +25,7 @@ #include <winpr/print.h> #include <winpr/windows.h> -#include <freerdp/utils/stream.h> +#include <winpr/stream.h> #include "librail.h" @@ -100,7 +100,7 @@ void print_window_styles(UINT32 style) { int i; - printf("Window Styles:\n{\n"); + fprintf(stderr, "Window Styles:\n{\n"); for (i = 0; i < ARRAYSIZE(WINDOW_STYLES); i++) { if (style & WINDOW_STYLES[i].style) @@ -111,17 +111,17 @@ void print_window_styles(UINT32 style) continue; } - printf("\t%s\n", WINDOW_STYLES[i].name); + fprintf(stderr, "\t%s\n", WINDOW_STYLES[i].name); } } - printf("}\n"); + fprintf(stderr, "}\n"); } void print_extended_window_styles(UINT32 style) { int i; - printf("Extended Window Styles:\n{\n"); + fprintf(stderr, "Extended Window Styles:\n{\n"); for (i = 0; i < ARRAYSIZE(EXTENDED_WINDOW_STYLES); i++) { if (style & EXTENDED_WINDOW_STYLES[i].style) @@ -132,10 +132,10 @@ void print_extended_window_styles(UINT32 style) continue; } - printf("\t%s\n", EXTENDED_WINDOW_STYLES[i].name); + fprintf(stderr, "\t%s\n", EXTENDED_WINDOW_STYLES[i].name); } } - printf("}\n"); + fprintf(stderr, "}\n"); } void window_state_update(rdpWindow* window, WINDOW_ORDER_INFO* orderInfo, WINDOW_STATE_ORDER* window_state) diff --git a/libfreerdp/rail/window_list.c b/libfreerdp/rail/window_list.c index da27d8f9a..9fcbd2db8 100644 --- a/libfreerdp/rail/window_list.c +++ b/libfreerdp/rail/window_list.c @@ -23,7 +23,7 @@ #include <winpr/crt.h> -#include <freerdp/utils/stream.h> +#include <winpr/stream.h> #include "librail.h" diff --git a/libfreerdp/utils/CMakeLists.txt b/libfreerdp/utils/CMakeLists.txt index 55b3b7e46..e85e27d37 100644 --- a/libfreerdp/utils/CMakeLists.txt +++ b/libfreerdp/utils/CMakeLists.txt @@ -22,18 +22,14 @@ set(${MODULE_PREFIX}_SRCS event.c bitmap.c list.c - file.c passphrase.c pcap.c profiler.c rail.c signal.c stopwatch.c - stream.c - string.c svc_plugin.c tcp.c - thread.c time.c uds.c) @@ -62,7 +58,7 @@ endif() set_complex_link_libraries(VARIABLE ${MODULE_PREFIX}_LIBS MONOLITHIC ${MONOLITHIC_BUILD} MODULE winpr - MODULES winpr-crt winpr-synch winpr-thread winpr-utils) + MODULES winpr-crt winpr-synch winpr-thread winpr-utils winpr-path) if(MONOLITHIC_BUILD) set(FREERDP_LIBS ${FREERDP_LIBS} ${${MODULE_PREFIX}_LIBS} PARENT_SCOPE) diff --git a/libfreerdp/utils/bitmap.c b/libfreerdp/utils/bitmap.c index 65004c2a7..bc49d6d00 100644 --- a/libfreerdp/utils/bitmap.c +++ b/libfreerdp/utils/bitmap.c @@ -67,7 +67,7 @@ void freerdp_bitmap_write(char* filename, void* data, int width, int height, int if (fp == NULL) { - printf("failed to open file %s\n", filename); + fprintf(stderr, "failed to open file %s\n", filename); return; } diff --git a/libfreerdp/utils/event.c b/libfreerdp/utils/event.c index 39e186e5b..8b9e25e07 100644 --- a/libfreerdp/utils/event.c +++ b/libfreerdp/utils/event.c @@ -27,54 +27,59 @@ #include <winpr/crt.h> +#include <freerdp/message.h> #include <freerdp/utils/event.h> #include <freerdp/client/cliprdr.h> #include <freerdp/client/tsmf.h> #include <freerdp/rail.h> -static RDP_EVENT* freerdp_cliprdr_event_new(UINT16 event_type) +static wMessage* freerdp_cliprdr_event_new(UINT16 event_type) { - RDP_EVENT* event = NULL; + wMessage* event = NULL; switch (event_type) { - case RDP_EVENT_TYPE_CB_MONITOR_READY: - event = (RDP_EVENT*) malloc(sizeof(RDP_CB_MONITOR_READY_EVENT)); + case CliprdrChannel_MonitorReady: + event = (wMessage*) malloc(sizeof(RDP_CB_MONITOR_READY_EVENT)); ZeroMemory(event, sizeof(RDP_CB_MONITOR_READY_EVENT)); + event->id = MakeMessageId(CliprdrChannel, MonitorReady); break; - case RDP_EVENT_TYPE_CB_FORMAT_LIST: - event = (RDP_EVENT*) malloc(sizeof(RDP_CB_FORMAT_LIST_EVENT)); + case CliprdrChannel_FormatList: + event = (wMessage*) malloc(sizeof(RDP_CB_FORMAT_LIST_EVENT)); ZeroMemory(event, sizeof(RDP_CB_FORMAT_LIST_EVENT)); + event->id = MakeMessageId(CliprdrChannel, FormatList); break; - case RDP_EVENT_TYPE_CB_DATA_REQUEST: - event = (RDP_EVENT*) malloc(sizeof(RDP_CB_DATA_REQUEST_EVENT)); + case CliprdrChannel_DataRequest: + event = (wMessage*) malloc(sizeof(RDP_CB_DATA_REQUEST_EVENT)); ZeroMemory(event, sizeof(RDP_CB_DATA_REQUEST_EVENT)); + event->id = MakeMessageId(CliprdrChannel, DataRequest); break; - case RDP_EVENT_TYPE_CB_DATA_RESPONSE: - event = (RDP_EVENT*) malloc(sizeof(RDP_CB_DATA_RESPONSE_EVENT)); + case CliprdrChannel_DataResponse: + event = (wMessage*) malloc(sizeof(RDP_CB_DATA_RESPONSE_EVENT)); ZeroMemory(event, sizeof(RDP_CB_DATA_RESPONSE_EVENT)); + event->id = MakeMessageId(CliprdrChannel, DataResponse); break; } return event; } -static RDP_EVENT* freerdp_tsmf_event_new(UINT16 event_type) +static wMessage* freerdp_tsmf_event_new(UINT16 event_type) { - RDP_EVENT* event = NULL; + wMessage* event = NULL; switch (event_type) { - case RDP_EVENT_TYPE_TSMF_VIDEO_FRAME: - event = (RDP_EVENT*) malloc(sizeof(RDP_VIDEO_FRAME_EVENT)); + case TsmfChannel_VideoFrame: + event = (wMessage*) malloc(sizeof(RDP_VIDEO_FRAME_EVENT)); ZeroMemory(event, sizeof(RDP_VIDEO_FRAME_EVENT)); break; - case RDP_EVENT_TYPE_TSMF_REDRAW: - event = (RDP_EVENT*) malloc(sizeof(RDP_REDRAW_EVENT)); + case TsmfChannel_Redraw: + event = (wMessage*) malloc(sizeof(RDP_REDRAW_EVENT)); ZeroMemory(event, sizeof(RDP_REDRAW_EVENT)); break; } @@ -82,77 +87,77 @@ static RDP_EVENT* freerdp_tsmf_event_new(UINT16 event_type) return event; } -static RDP_EVENT* freerdp_rail_event_new(UINT16 event_type) +static wMessage* freerdp_rail_event_new(UINT16 event_type) { - RDP_EVENT* event = NULL; + wMessage* event = NULL; - event = (RDP_EVENT*) malloc(sizeof(RDP_EVENT)); - ZeroMemory(event, sizeof(RDP_EVENT)); + event = (wMessage*) malloc(sizeof(wMessage)); + ZeroMemory(event, sizeof(wMessage)); return event; } -RDP_EVENT* freerdp_event_new(UINT16 event_class, UINT16 event_type, - RDP_EVENT_CALLBACK on_event_free_callback, void* user_data) +wMessage* freerdp_event_new(UINT16 event_class, UINT16 event_type, + MESSAGE_FREE_FN on_event_free_callback, void* user_data) { - RDP_EVENT* event = NULL; + wMessage* event = NULL; switch (event_class) { - case RDP_EVENT_CLASS_DEBUG: - event = (RDP_EVENT*) malloc(sizeof(RDP_EVENT)); - ZeroMemory(event, sizeof(RDP_EVENT)); + case DebugChannel_Class: + event = (wMessage*) malloc(sizeof(wMessage)); + ZeroMemory(event, sizeof(wMessage)); break; - case RDP_EVENT_CLASS_CLIPRDR: + case CliprdrChannel_Class: event = freerdp_cliprdr_event_new(event_type); break; - case RDP_EVENT_CLASS_TSMF: + case TsmfChannel_Class: event = freerdp_tsmf_event_new(event_type); break; - case RDP_EVENT_CLASS_RAIL: + case RailChannel_Class: event = freerdp_rail_event_new(event_type); break; } if (event) { - event->event_class = event_class; - event->event_type = event_type; - event->on_event_free_callback = on_event_free_callback; - event->user_data = user_data; + event->wParam = user_data; + event->Free = (void*) on_event_free_callback; + event->id = GetMessageId(event_class, event_type); } return event; } -static void freerdp_cliprdr_event_free(RDP_EVENT* event) +static void freerdp_cliprdr_event_free(wMessage* event) { - switch (event->event_type) + switch (GetMessageType(event->id)) { - case RDP_EVENT_TYPE_CB_FORMAT_LIST: + case CliprdrChannel_FormatList: { - RDP_CB_FORMAT_LIST_EVENT* cb_event = (RDP_CB_FORMAT_LIST_EVENT*)event; + RDP_CB_FORMAT_LIST_EVENT* cb_event = (RDP_CB_FORMAT_LIST_EVENT*) event; free(cb_event->formats); free(cb_event->raw_format_data); } break; - case RDP_EVENT_TYPE_CB_DATA_RESPONSE: + + case CliprdrChannel_DataResponse: { - RDP_CB_DATA_RESPONSE_EVENT* cb_event = (RDP_CB_DATA_RESPONSE_EVENT*)event; + RDP_CB_DATA_RESPONSE_EVENT* cb_event = (RDP_CB_DATA_RESPONSE_EVENT*) event; free(cb_event->data); } break; } } -static void freerdp_tsmf_event_free(RDP_EVENT* event) +static void freerdp_tsmf_event_free(wMessage* event) { - switch (event->event_type) + switch (GetMessageType(event->id)) { - case RDP_EVENT_TYPE_TSMF_VIDEO_FRAME: + case TsmfChannel_VideoFrame: { RDP_VIDEO_FRAME_EVENT* vevent = (RDP_VIDEO_FRAME_EVENT*)event; free(vevent->frame_data); @@ -162,26 +167,29 @@ static void freerdp_tsmf_event_free(RDP_EVENT* event) } } -static void freerdp_rail_event_free(RDP_EVENT* event) +static void freerdp_rail_event_free(wMessage* event) { + } -void freerdp_event_free(RDP_EVENT* event) +void freerdp_event_free(wMessage* event) { if (event) { - if (event->on_event_free_callback) - event->on_event_free_callback(event); + if (event->Free) + event->Free(event); - switch (event->event_class) + switch (GetMessageClass(event->id)) { - case RDP_EVENT_CLASS_CLIPRDR: + case CliprdrChannel_Class: freerdp_cliprdr_event_free(event); break; - case RDP_EVENT_CLASS_TSMF: + + case TsmfChannel_Class: freerdp_tsmf_event_free(event); break; - case RDP_EVENT_CLASS_RAIL: + + case RailChannel_Class: freerdp_rail_event_free(event); break; } diff --git a/libfreerdp/utils/file.c b/libfreerdp/utils/file.c deleted file mode 100644 index b863a5557..000000000 --- a/libfreerdp/utils/file.c +++ /dev/null @@ -1,230 +0,0 @@ -/** - * FreeRDP: A Remote Desktop Protocol Implementation - * File Utils - * - * Copyright 2011 Marc-Andre Moreau <marcandre.moreau@gmail.com> - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <sys/stat.h> - -#include <winpr/crt.h> - -#include <freerdp/types.h> -#include <freerdp/settings.h> -#include <freerdp/utils/string.h> - -#ifndef _WIN32 -#include <unistd.h> -#else -#include <direct.h> -#define getcwd _getcwd -#endif - -#include <winpr/windows.h> -#include <freerdp/utils/file.h> - -#ifndef _WIN32 -#define PATH_SEPARATOR_STR "/" -#define PATH_SEPARATOR_CHR '/' -#define HOME_ENV_VARIABLE "HOME" -#else -#define PATH_SEPARATOR_STR "\\" -#define PATH_SEPARATOR_CHR '\\' -#define HOME_ENV_VARIABLE "HOME" -#endif - -#ifdef _WIN32 -#define SHARED_LIB_SUFFIX ".dll" -#elif defined(__APPLE__) -#define SHARED_LIB_SUFFIX ".dylib" -#else -#define SHARED_LIB_SUFFIX ".so" -#endif - -#define FREERDP_CONFIG_DIR ".freerdp" - -#define PARENT_PATH ".." PATH_SEPARATOR_STR - -void freerdp_mkdir(char* path) -{ -#ifndef _WIN32 - mkdir(path, S_IRUSR | S_IWUSR | S_IXUSR); -#else - CreateDirectoryA(path, 0); -#endif -} - -BOOL freerdp_check_file_exists(char* file) -{ - struct stat stat_info; - - if (stat(file, &stat_info) != 0) - return FALSE; - - return TRUE; -} - -char* freerdp_get_home_path(rdpSettings* settings) -{ - char* home_env = NULL; - - if (settings->HomePath == NULL) - { - home_env = getenv(HOME_ENV_VARIABLE); - - if (home_env) - settings->HomePath = _strdup(home_env); - } - - if (settings->HomePath == NULL) - settings->HomePath = _strdup("/"); - - return settings->HomePath; -} - -char* freerdp_get_config_path(rdpSettings* settings) -{ - if (settings->ConfigPath != NULL) - return settings->ConfigPath; - - settings->ConfigPath = (char*) malloc(strlen(settings->HomePath) + sizeof(FREERDP_CONFIG_DIR) + 2); - sprintf(settings->ConfigPath, "%s" PATH_SEPARATOR_STR "%s", settings->HomePath, FREERDP_CONFIG_DIR); - - if (!freerdp_check_file_exists(settings->ConfigPath)) - freerdp_mkdir(settings->ConfigPath); - - return settings->ConfigPath; -} - -char* freerdp_get_current_path(rdpSettings* settings) -{ - if (settings->CurrentPath == NULL) - settings->CurrentPath = getcwd(NULL, 0); - - return settings->CurrentPath; -} - -char* freerdp_construct_path(char* base_path, char* relative_path) -{ - char* path; - int length; - int base_path_length; - int relative_path_length; - - base_path_length = strlen(base_path); - relative_path_length = strlen(relative_path); - length = base_path_length + relative_path_length + 1; - - path = malloc(length + 1); - sprintf(path, "%s" PATH_SEPARATOR_STR "%s", base_path, relative_path); - - return path; -} - -char* freerdp_append_shared_library_suffix(char* file_path) -{ - char* p; - char* path = NULL; - int file_path_length; - int shared_lib_suffix_length; - - if (file_path == NULL) - return NULL; - - file_path_length = strlen(file_path); - shared_lib_suffix_length = strlen(SHARED_LIB_SUFFIX); - - if (file_path_length >= shared_lib_suffix_length) - { - p = &file_path[file_path_length - shared_lib_suffix_length]; - - if (strcmp(p, SHARED_LIB_SUFFIX) != 0) - { - path = malloc(file_path_length + shared_lib_suffix_length + 1); - sprintf(path, "%s%s", file_path, SHARED_LIB_SUFFIX); - } - else - { - path = _strdup(file_path); - } - } - else - { - path = malloc(file_path_length + shared_lib_suffix_length + 1); - sprintf(path, "%s%s", file_path, SHARED_LIB_SUFFIX); - } - - return path; -} - -char* freerdp_get_parent_path(char* base_path, int depth) -{ - int i; - char* p; - char* path; - int length; - int base_length; - - if (base_path == NULL) - return NULL; - - if (depth <= 0) - return _strdup(base_path); - - base_length = strlen(base_path); - - p = &base_path[base_length]; - - for (i = base_length - 1; ((i >= 0) && (depth > 0)); i--) - { - if (base_path[i] == PATH_SEPARATOR_CHR) - { - p = &base_path[i]; - depth--; - } - } - - length = (p - base_path); - - path = (char*) malloc(length + 1); - memcpy(path, base_path, length); - path[length] = '\0'; - - return path; -} - -BOOL freerdp_path_contains_separator(char* path) -{ - if (path == NULL) - return FALSE; - - if (strchr(path, PATH_SEPARATOR_CHR) == NULL) - return FALSE; - - return TRUE; -} - -void freerdp_detect_paths(rdpSettings* settings) -{ - freerdp_get_home_path(settings); - freerdp_get_config_path(settings); -} diff --git a/libfreerdp/utils/msusb.c b/libfreerdp/utils/msusb.c index 9c6ad9132..038997e04 100644 --- a/libfreerdp/utils/msusb.c +++ b/libfreerdp/utils/msusb.c @@ -315,41 +315,41 @@ void msusb_msconfig_dump(MSUSB_CONFIG_DESCRIPTOR* MsConfig) MSUSB_PIPE_DESCRIPTOR * MsPipe; int inum = 0, pnum = 0; - printf("=================MsConfig:========================\n"); - printf("wTotalLength:%d\n", MsConfig->wTotalLength); - printf("bConfigurationValue:%d\n", MsConfig->bConfigurationValue); - printf("ConfigurationHandle:0x%x\n", MsConfig->ConfigurationHandle); - printf("InitCompleted:%d\n", MsConfig->InitCompleted); - printf("MsOutSize:%d\n", MsConfig->MsOutSize); - printf("NumInterfaces:%d\n\n", MsConfig->NumInterfaces); + fprintf(stderr, "=================MsConfig:========================\n"); + fprintf(stderr, "wTotalLength:%d\n", MsConfig->wTotalLength); + fprintf(stderr, "bConfigurationValue:%d\n", MsConfig->bConfigurationValue); + fprintf(stderr, "ConfigurationHandle:0x%x\n", MsConfig->ConfigurationHandle); + fprintf(stderr, "InitCompleted:%d\n", MsConfig->InitCompleted); + fprintf(stderr, "MsOutSize:%d\n", MsConfig->MsOutSize); + fprintf(stderr, "NumInterfaces:%d\n\n", MsConfig->NumInterfaces); MsInterfaces = MsConfig->MsInterfaces; for(inum = 0; inum < MsConfig->NumInterfaces; inum++) { MsInterface = MsInterfaces[inum]; - printf(" Interfase: %d\n", MsInterface->InterfaceNumber); - printf(" Length: %d\n", MsInterface->Length); - printf(" NumberOfPipesExpected: %d\n", MsInterface->NumberOfPipesExpected); - printf(" AlternateSetting: %d\n", MsInterface->AlternateSetting); - printf(" NumberOfPipes: %d\n", MsInterface->NumberOfPipes); - printf(" InterfaceHandle: 0x%x\n", MsInterface->InterfaceHandle); - printf(" bInterfaceClass: 0x%x\n", MsInterface->bInterfaceClass); - printf(" bInterfaceSubClass: 0x%x\n", MsInterface->bInterfaceSubClass); - printf(" bInterfaceProtocol: 0x%x\n", MsInterface->bInterfaceProtocol); - printf(" InitCompleted: %d\n\n", MsInterface->InitCompleted); + fprintf(stderr, " Interfase: %d\n", MsInterface->InterfaceNumber); + fprintf(stderr, " Length: %d\n", MsInterface->Length); + fprintf(stderr, " NumberOfPipesExpected: %d\n", MsInterface->NumberOfPipesExpected); + fprintf(stderr, " AlternateSetting: %d\n", MsInterface->AlternateSetting); + fprintf(stderr, " NumberOfPipes: %d\n", MsInterface->NumberOfPipes); + fprintf(stderr, " InterfaceHandle: 0x%x\n", MsInterface->InterfaceHandle); + fprintf(stderr, " bInterfaceClass: 0x%x\n", MsInterface->bInterfaceClass); + fprintf(stderr, " bInterfaceSubClass: 0x%x\n", MsInterface->bInterfaceSubClass); + fprintf(stderr, " bInterfaceProtocol: 0x%x\n", MsInterface->bInterfaceProtocol); + fprintf(stderr, " InitCompleted: %d\n\n", MsInterface->InitCompleted); MsPipes = MsInterface->MsPipes; for (pnum = 0; pnum < MsInterface->NumberOfPipes; pnum++) { MsPipe = MsPipes[pnum]; - printf(" Pipe: %d\n", pnum); - printf(" MaximumPacketSize: 0x%x\n", MsPipe->MaximumPacketSize); - printf(" MaximumTransferSize: 0x%x\n", MsPipe->MaximumTransferSize); - printf(" PipeFlags: 0x%x\n", MsPipe->PipeFlags); - printf(" PipeHandle: 0x%x\n", MsPipe->PipeHandle); - printf(" bEndpointAddress: 0x%x\n", MsPipe->bEndpointAddress); - printf(" bInterval: %d\n", MsPipe->bInterval); - printf(" PipeType: 0x%x\n", MsPipe->PipeType); - printf(" InitCompleted: %d\n\n", MsPipe->InitCompleted); + fprintf(stderr, " Pipe: %d\n", pnum); + fprintf(stderr, " MaximumPacketSize: 0x%x\n", MsPipe->MaximumPacketSize); + fprintf(stderr, " MaximumTransferSize: 0x%x\n", MsPipe->MaximumTransferSize); + fprintf(stderr, " PipeFlags: 0x%x\n", MsPipe->PipeFlags); + fprintf(stderr, " PipeHandle: 0x%x\n", MsPipe->PipeHandle); + fprintf(stderr, " bEndpointAddress: 0x%x\n", MsPipe->bEndpointAddress); + fprintf(stderr, " bInterval: %d\n", MsPipe->bInterval); + fprintf(stderr, " PipeType: 0x%x\n", MsPipe->PipeType); + fprintf(stderr, " InitCompleted: %d\n\n", MsPipe->InitCompleted); } } - printf("==================================================\n"); + fprintf(stderr, "==================================================\n"); } diff --git a/libfreerdp/utils/profiler.c b/libfreerdp/utils/profiler.c index 3b52c72d0..f12a25cc9 100644 --- a/libfreerdp/utils/profiler.c +++ b/libfreerdp/utils/profiler.c @@ -57,12 +57,12 @@ void profiler_exit(PROFILER* profiler) void profiler_print_header() { - printf("\n"); - printf(" |-----------------------|\n" ); - printf(" PROFILER | elapsed seconds |\n" ); - printf("|--------------------------------------------|-----------------------|\n" ); - printf("| code section | iterations | total | avg. |\n" ); - printf("|-------------------------------|------------|-----------|-----------|\n" ); + fprintf(stderr, "\n"); + fprintf(stderr, " |-----------------------|\n" ); + fprintf(stderr, " PROFILER | elapsed seconds |\n" ); + fprintf(stderr, "|--------------------------------------------|-----------------------|\n" ); + fprintf(stderr, "| code section | iterations | total | avg. |\n" ); + fprintf(stderr, "|-------------------------------|------------|-----------|-----------|\n" ); } void profiler_print(PROFILER* profiler) @@ -70,10 +70,10 @@ void profiler_print(PROFILER* profiler) double elapsed_sec = stopwatch_get_elapsed_time_in_seconds(profiler->stopwatch); double avg_sec = elapsed_sec / (double) profiler->stopwatch->count; - printf("| %-30.30s| %'10lu | %'9f | %'9f |\n", profiler->name, profiler->stopwatch->count, elapsed_sec, avg_sec); + fprintf(stderr, "| %-30.30s| %'10lu | %'9f | %'9f |\n", profiler->name, profiler->stopwatch->count, elapsed_sec, avg_sec); } void profiler_print_footer() { - printf("|--------------------------------------------------------------------|\n" ); + fprintf(stderr, "|--------------------------------------------------------------------|\n" ); } diff --git a/libfreerdp/utils/rail.c b/libfreerdp/utils/rail.c index 95b607b86..521710091 100644 --- a/libfreerdp/utils/rail.c +++ b/libfreerdp/utils/rail.c @@ -46,12 +46,14 @@ void rail_unicode_string_free(RAIL_UNICODE_STRING* unicode_string) free(unicode_string->string); } -BOOL rail_read_unicode_string(STREAM* s, RAIL_UNICODE_STRING* unicode_string) +BOOL rail_read_unicode_string(wStream* s, RAIL_UNICODE_STRING* unicode_string) { - if(stream_get_left(s) < 2) + if (stream_get_left(s) < 2) return FALSE; + stream_read_UINT16(s, unicode_string->length); /* cbString (2 bytes) */ - if(stream_get_left(s) < unicode_string->length) + + if (stream_get_left(s) < unicode_string->length) return FALSE; if (unicode_string->string == NULL) @@ -60,17 +62,18 @@ BOOL rail_read_unicode_string(STREAM* s, RAIL_UNICODE_STRING* unicode_string) unicode_string->string = (BYTE*) realloc(unicode_string->string, unicode_string->length); stream_read(s, unicode_string->string, unicode_string->length); + return TRUE; } -void rail_write_unicode_string(STREAM* s, RAIL_UNICODE_STRING* unicode_string) +void rail_write_unicode_string(wStream* s, RAIL_UNICODE_STRING* unicode_string) { stream_check_size(s, 2 + unicode_string->length); stream_write_UINT16(s, unicode_string->length); /* cbString (2 bytes) */ stream_write(s, unicode_string->string, unicode_string->length); /* string */ } -void rail_write_unicode_string_value(STREAM* s, RAIL_UNICODE_STRING* unicode_string) +void rail_write_unicode_string_value(wStream* s, RAIL_UNICODE_STRING* unicode_string) { if (unicode_string->length > 0) { @@ -79,7 +82,7 @@ void rail_write_unicode_string_value(STREAM* s, RAIL_UNICODE_STRING* unicode_str } } -void rail_read_rectangle_16(STREAM* s, RECTANGLE_16* rectangle_16) +void rail_read_rectangle_16(wStream* s, RECTANGLE_16* rectangle_16) { stream_read_UINT16(s, rectangle_16->left); /* left (2 bytes) */ stream_read_UINT16(s, rectangle_16->top); /* top (2 bytes) */ @@ -87,7 +90,7 @@ void rail_read_rectangle_16(STREAM* s, RECTANGLE_16* rectangle_16) stream_read_UINT16(s, rectangle_16->bottom); /* bottom (2 bytes) */ } -void rail_write_rectangle_16(STREAM* s, RECTANGLE_16* rectangle_16) +void rail_write_rectangle_16(wStream* s, RECTANGLE_16* rectangle_16) { stream_write_UINT16(s, rectangle_16->left); /* left (2 bytes) */ stream_write_UINT16(s, rectangle_16->top); /* top (2 bytes) */ @@ -103,22 +106,22 @@ void* rail_clone_order(UINT32 event_type, void* order) UINT32 size; } ordersize_table[] = { - {RDP_EVENT_TYPE_RAIL_CHANNEL_GET_SYSPARAMS, sizeof(RAIL_SYSPARAM_ORDER)}, - {RDP_EVENT_TYPE_RAIL_CHANNEL_EXEC_RESULTS, sizeof(RAIL_EXEC_RESULT_ORDER)}, - {RDP_EVENT_TYPE_RAIL_CHANNEL_SERVER_SYSPARAM, sizeof(RAIL_SYSPARAM_ORDER)}, - {RDP_EVENT_TYPE_RAIL_CHANNEL_SERVER_MINMAXINFO, sizeof(RAIL_MINMAXINFO_ORDER)}, - {RDP_EVENT_TYPE_RAIL_CHANNEL_SERVER_LOCALMOVESIZE, sizeof(RAIL_LOCALMOVESIZE_ORDER)}, - {RDP_EVENT_TYPE_RAIL_CHANNEL_APPID_RESP, sizeof(RAIL_GET_APPID_RESP_ORDER)}, - {RDP_EVENT_TYPE_RAIL_CHANNEL_LANGBARINFO, sizeof(RAIL_LANGBAR_INFO_ORDER)}, - {RDP_EVENT_TYPE_RAIL_CLIENT_SET_SYSPARAMS, sizeof(RAIL_SYSPARAM_ORDER)}, - {RDP_EVENT_TYPE_RAIL_CLIENT_EXEC_REMOTE_APP, sizeof(RDP_PLUGIN_DATA)}, - {RDP_EVENT_TYPE_RAIL_CLIENT_ACTIVATE, sizeof(RAIL_ACTIVATE_ORDER)}, - {RDP_EVENT_TYPE_RAIL_CLIENT_SYSMENU, sizeof(RAIL_SYSMENU_ORDER)}, - {RDP_EVENT_TYPE_RAIL_CLIENT_SYSCOMMAND, sizeof(RAIL_SYSCOMMAND_ORDER)}, - {RDP_EVENT_TYPE_RAIL_CLIENT_NOTIFY_EVENT, sizeof(RAIL_NOTIFY_EVENT_ORDER)}, - {RDP_EVENT_TYPE_RAIL_CLIENT_WINDOW_MOVE, sizeof(RAIL_WINDOW_MOVE_ORDER)}, - {RDP_EVENT_TYPE_RAIL_CLIENT_APPID_REQ, sizeof(RAIL_GET_APPID_REQ_ORDER)}, - {RDP_EVENT_TYPE_RAIL_CLIENT_LANGBARINFO, sizeof(RAIL_LANGBAR_INFO_ORDER)}, + {RailChannel_GetSystemParam, sizeof(RAIL_SYSPARAM_ORDER)}, + {RailChannel_ServerExecuteResult, sizeof(RAIL_EXEC_RESULT_ORDER)}, + {RailChannel_ServerSystemParam, sizeof(RAIL_SYSPARAM_ORDER)}, + {RailChannel_ServerMinMaxInfo, sizeof(RAIL_MINMAXINFO_ORDER)}, + {RailChannel_ServerLocalMoveSize, sizeof(RAIL_LOCALMOVESIZE_ORDER)}, + {RailChannel_ServerGetAppIdResponse, sizeof(RAIL_GET_APPID_RESP_ORDER)}, + {RailChannel_ServerLanguageBarInfo, sizeof(RAIL_LANGBAR_INFO_ORDER)}, + {RailChannel_ClientSystemParam, sizeof(RAIL_SYSPARAM_ORDER)}, + {RailChannel_ClientExecute, sizeof(RDP_PLUGIN_DATA)}, + {RailChannel_ClientActivate, sizeof(RAIL_ACTIVATE_ORDER)}, + {RailChannel_ClientSystemMenu, sizeof(RAIL_SYSMENU_ORDER)}, + {RailChannel_ClientSystemCommand, sizeof(RAIL_SYSCOMMAND_ORDER)}, + {RailChannel_ClientNotifyEvent, sizeof(RAIL_NOTIFY_EVENT_ORDER)}, + {RailChannel_ClientWindowMove, sizeof(RAIL_WINDOW_MOVE_ORDER)}, + {RailChannel_ClientGetAppIdRequest, sizeof(RAIL_GET_APPID_REQ_ORDER)}, + {RailChannel_ClientLanguageBarInfo, sizeof(RAIL_LANGBAR_INFO_ORDER)}, }; size_t i = 0; size_t order_size = 0; @@ -134,42 +137,43 @@ void* rail_clone_order(UINT32 event_type, void* order) } // Event type not found. - if (order_size == 0) return NULL; + if (order_size == 0) + return NULL; new_order = malloc(order_size); - memcpy(new_order, order, order_size); + CopyMemory(new_order, order, order_size); - //printf("rail_clone_order: type=%d order=%p\n", event_type, new_order); + //fprintf(stderr, "rail_clone_order: type=%d order=%p\n", event_type, new_order); // Create copy of variable data for some orders - if ((event_type == RDP_EVENT_TYPE_RAIL_CHANNEL_GET_SYSPARAMS) || - (event_type == RDP_EVENT_TYPE_RAIL_CLIENT_SET_SYSPARAMS)) + if ((event_type == RailChannel_GetSystemParam) || + (event_type == RailChannel_ClientSystemParam)) { - RAIL_SYSPARAM_ORDER* new_sysparam = (RAIL_SYSPARAM_ORDER*)new_order; - RAIL_SYSPARAM_ORDER* old_sysparam = (RAIL_SYSPARAM_ORDER*)order; + RAIL_SYSPARAM_ORDER* new_sysparam = (RAIL_SYSPARAM_ORDER*) new_order; + RAIL_SYSPARAM_ORDER* old_sysparam = (RAIL_SYSPARAM_ORDER*) order; rail_unicode_string_alloc(&new_sysparam->highContrast.colorScheme, old_sysparam->highContrast.colorScheme.length); - memcpy(new_sysparam->highContrast.colorScheme.string, + CopyMemory(new_sysparam->highContrast.colorScheme.string, old_sysparam->highContrast.colorScheme.string, old_sysparam->highContrast.colorScheme.length); } - if (event_type == RDP_EVENT_TYPE_RAIL_CHANNEL_EXEC_RESULTS) + if (event_type == RailChannel_ServerExecuteResult) { - RAIL_EXEC_RESULT_ORDER* new_exec_result = (RAIL_EXEC_RESULT_ORDER*)new_order; - RAIL_EXEC_RESULT_ORDER* old_exec_result = (RAIL_EXEC_RESULT_ORDER*)order; + RAIL_EXEC_RESULT_ORDER* new_exec_result = (RAIL_EXEC_RESULT_ORDER*) new_order; + RAIL_EXEC_RESULT_ORDER* old_exec_result = (RAIL_EXEC_RESULT_ORDER*) order; rail_unicode_string_alloc(&new_exec_result->exeOrFile, old_exec_result->exeOrFile.length); - memcpy(new_exec_result->exeOrFile.string, + CopyMemory(new_exec_result->exeOrFile.string, old_exec_result->exeOrFile.string, old_exec_result->exeOrFile.length); } - if (event_type == RDP_EVENT_TYPE_RAIL_CHANNEL_APPID_RESP) + if (event_type == RailChannel_ServerGetAppIdResponse) { RAIL_GET_APPID_RESP_ORDER* new_app_resp = (RAIL_GET_APPID_RESP_ORDER*)new_order; @@ -181,18 +185,19 @@ void* rail_clone_order(UINT32 event_type, void* order) void rail_free_cloned_order(UINT32 event_type, void* order) { - //printf("rail_free_cloned_order: type=%d order=%p\n", event_type, order); - if ((event_type == RDP_EVENT_TYPE_RAIL_CHANNEL_GET_SYSPARAMS) || - (event_type == RDP_EVENT_TYPE_RAIL_CLIENT_SET_SYSPARAMS)) + //fprintf(stderr, "rail_free_cloned_order: type=%d order=%p\n", event_type, order); + if ((event_type == RailChannel_GetSystemParam) || + (event_type == RailChannel_ClientSystemParam)) { - RAIL_SYSPARAM_ORDER* sysparam = (RAIL_SYSPARAM_ORDER*)order; + RAIL_SYSPARAM_ORDER* sysparam = (RAIL_SYSPARAM_ORDER*) order; rail_unicode_string_free(&sysparam->highContrast.colorScheme); } - if (event_type == RDP_EVENT_TYPE_RAIL_CHANNEL_EXEC_RESULTS) + if (event_type == RailChannel_ServerExecuteResult) { - RAIL_EXEC_RESULT_ORDER* exec_result = (RAIL_EXEC_RESULT_ORDER*)order; + RAIL_EXEC_RESULT_ORDER* exec_result = (RAIL_EXEC_RESULT_ORDER*) order; rail_unicode_string_free(&exec_result->exeOrFile); } + free(order); } diff --git a/libfreerdp/utils/stream.c b/libfreerdp/utils/stream.c deleted file mode 100644 index bb2a69aa0..000000000 --- a/libfreerdp/utils/stream.c +++ /dev/null @@ -1,119 +0,0 @@ -/* - * FreeRDP: A Remote Desktop Protocol Implementation - * Stream Utils - * - * Copyright 2011 Vic Lee - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -#include <winpr/crt.h> - -#include <freerdp/utils/stream.h> - -/** - * Allocates and initializes a STREAM structure. - * STREAM are used to ease data access in read and write operations. - * They consist of a buffer containing the data we want to access, and an offset associated to it, and keeping - * track of the 'current' position in the stream. A list of functions can then be used to read/write different - * type of data to/from it. - * @see stream.h for the list of data access functions. - * - * @param size [in] - size of the buffer that will ba allocated to the stream. - * If 0, there will be no buffer attached to the stream. The caller - * then needs to call stream_attach() to link an existing buffer to this stream. - * Caution: calling stream_attach() on a stream with an existing buffer will result - * in this buffer being lost, and possible memory leak. - * - * @return A pointer to an allocated and initialized STREAM structure. - * This pointer need to be deallocated using the stream_free() function. - */ -STREAM* stream_new(int size) -{ - STREAM* stream; - - stream = malloc(sizeof(STREAM)); - ZeroMemory(stream, sizeof(STREAM)); - - if (stream != NULL) - { - if (size != 0) - { - size = size > 0 ? size : 0x400; - stream->data = (BYTE*) malloc(size); - ZeroMemory(stream->data, size); - stream->p = stream->data; - stream->size = size; - } - } - - return stream; -} - -/** - * This function is used to deallocate a stream that was allocated using stream_new(). - * Caution: the buffer linked to the stream will be deallocated in the process. If this buffer was attached - * using the stream_attach() function, the stream_detach() function needs to be called before calling stream_free() - * otherwise it will be freed in the process. - * - * @param stream [in] - Pointer to the STREAM structure that needs to be deallocated. - * This pointer is invalid on return. - */ -void stream_free(STREAM* stream) -{ - if (stream != NULL) - { - if (stream->data != NULL) - free(stream->data); - - free(stream); - } -} - -/** - * This function is used to extend the size of an existing stream. - * It will infact extend the attached buffer, fill the newly allocated region with 0, and reset the current - * stream position. - * If the stream did not have a buffer attached, a new one will be allocated and attached. - * - * @param stream [in/out] pointer to the STREAM structure that needs to be extended. - * @param request_size [in] Number of bytes to add to the existing stream. - * If the value is < the existing size, then the existing size is doubled. - */ -void stream_extend(STREAM* stream, int request_size) -{ - int pos; - int original_size; - int increased_size; - - pos = stream_get_pos(stream); - original_size = stream->size; - increased_size = (request_size > original_size ? request_size : original_size); - stream->size += increased_size; - - if (original_size == 0) - stream->data = (BYTE*) malloc(stream->size); - else - stream->data = (BYTE*) realloc(stream->data, stream->size); - - memset(stream->data + original_size, 0, increased_size); - stream_set_pos(stream, pos); -} diff --git a/libfreerdp/utils/svc_plugin.c b/libfreerdp/utils/svc_plugin.c index dc9b44d2e..a47898fd7 100644 --- a/libfreerdp/utils/svc_plugin.c +++ b/libfreerdp/utils/svc_plugin.c @@ -28,11 +28,11 @@ #include <winpr/crt.h> #include <winpr/synch.h> +#include <winpr/stream.h> #include <winpr/collections.h> #include <freerdp/constants.h> #include <freerdp/utils/debug.h> -#include <freerdp/utils/stream.h> #include <freerdp/utils/event.h> #include <freerdp/utils/svc_plugin.h> @@ -100,7 +100,7 @@ static void svc_plugin_remove(rdpSvcPlugin* plugin) static void svc_plugin_process_received(rdpSvcPlugin* plugin, void* pData, UINT32 dataLength, UINT32 totalLength, UINT32 dataFlags) { - STREAM* data_in; + wStream* data_in; if ((dataFlags & CHANNEL_FLAG_SUSPEND) || (dataFlags & CHANNEL_FLAG_RESUME)) { @@ -129,7 +129,7 @@ static void svc_plugin_process_received(rdpSvcPlugin* plugin, void* pData, UINT3 { if (stream_get_size(data_in) != stream_get_length(data_in)) { - printf("svc_plugin_process_received: read error\n"); + fprintf(stderr, "svc_plugin_process_received: read error\n"); } plugin->data_in = NULL; @@ -139,7 +139,7 @@ static void svc_plugin_process_received(rdpSvcPlugin* plugin, void* pData, UINT3 } } -static void svc_plugin_process_event(rdpSvcPlugin* plugin, RDP_EVENT* event_in) +static void svc_plugin_process_event(rdpSvcPlugin* plugin, wMessage* event_in) { MessageQueue_Post(plugin->MsgPipe->In, NULL, 1, (void*) event_in, NULL); } @@ -156,7 +156,7 @@ static void svc_plugin_open_event(UINT32 openHandle, UINT32 event, void* pData, if (!plugin) { - printf("svc_plugin_open_event: error no match\n"); + fprintf(stderr, "svc_plugin_open_event: error no match\n"); return; } @@ -167,19 +167,19 @@ static void svc_plugin_open_event(UINT32 openHandle, UINT32 event, void* pData, break; case CHANNEL_EVENT_WRITE_COMPLETE: - stream_free((STREAM*) pData); + stream_free((wStream*) pData); break; case CHANNEL_EVENT_USER: - svc_plugin_process_event(plugin, (RDP_EVENT*) pData); + svc_plugin_process_event(plugin, (wMessage*) pData); break; } } static void* svc_plugin_thread_func(void* arg) { - STREAM* data; - RDP_EVENT* event; + wStream* data; + wMessage* event; wMessage message; rdpSvcPlugin* plugin = (rdpSvcPlugin*) arg; @@ -199,12 +199,12 @@ static void* svc_plugin_thread_func(void* arg) if (message.id == 0) { - data = (STREAM*) message.wParam; + data = (wStream*) message.wParam; IFCALL(plugin->receive_callback, plugin, data); } else if (message.id == 1) { - event = (RDP_EVENT*) message.wParam; + event = (wMessage*) message.wParam; IFCALL(plugin->event_callback, plugin, event); } } @@ -224,7 +224,7 @@ static void svc_plugin_process_connected(rdpSvcPlugin* plugin, void* pData, UINT if (status != CHANNEL_RC_OK) { - printf("svc_plugin_process_connected: open failed\n"); + fprintf(stderr, "svc_plugin_process_connected: open failed: status: %d\n", status); return; } @@ -264,7 +264,7 @@ static void svc_plugin_init_event(void* pInitHandle, UINT32 event, void* pData, if (!plugin) { - printf("svc_plugin_init_event: error no match\n"); + fprintf(stderr, "svc_plugin_init_event: error no match\n"); return; } @@ -301,7 +301,7 @@ void svc_plugin_init(rdpSvcPlugin* plugin, CHANNEL_ENTRY_POINTS* pEntryPoints) &plugin->channel_def, 1, VIRTUAL_CHANNEL_VERSION_WIN2000, svc_plugin_init_event); } -int svc_plugin_send(rdpSvcPlugin* plugin, STREAM* data_out) +int svc_plugin_send(rdpSvcPlugin* plugin, wStream* data_out) { UINT32 status = 0; @@ -316,13 +316,13 @@ int svc_plugin_send(rdpSvcPlugin* plugin, STREAM* data_out) if (status != CHANNEL_RC_OK) { stream_free(data_out); - printf("svc_plugin_send: VirtualChannelWrite failed %d\n", status); + fprintf(stderr, "svc_plugin_send: VirtualChannelWrite failed %d\n", status); } return status; } -int svc_plugin_send_event(rdpSvcPlugin* plugin, RDP_EVENT* event) +int svc_plugin_send_event(rdpSvcPlugin* plugin, wMessage* event) { UINT32 status = 0; @@ -331,7 +331,7 @@ int svc_plugin_send_event(rdpSvcPlugin* plugin, RDP_EVENT* event) status = plugin->channel_entry_points.pVirtualChannelEventPush(plugin->open_handle, event); if (status != CHANNEL_RC_OK) - printf("svc_plugin_send_event: VirtualChannelEventPush failed %d\n", status); + fprintf(stderr, "svc_plugin_send_event: VirtualChannelEventPush failed %d\n", status); return status; } diff --git a/libfreerdp/utils/tcp.c b/libfreerdp/utils/tcp.c index 90e65415d..54188ca4c 100644 --- a/libfreerdp/utils/tcp.c +++ b/libfreerdp/utils/tcp.c @@ -85,7 +85,7 @@ int freerdp_tcp_connect(const char* hostname, int port) if (status != 0) { - printf("tcp_connect: getaddrinfo (%s)\n", gai_strerror(status)); + fprintf(stderr, "tcp_connect: getaddrinfo (%s)\n", gai_strerror(status)); return -1; } @@ -100,7 +100,7 @@ int freerdp_tcp_connect(const char* hostname, int port) if (connect(sockfd, ai->ai_addr, ai->ai_addrlen) == 0) { - printf("connected to %s:%s\n", hostname, servname); + fprintf(stderr, "connected to %s:%s\n", hostname, servname); break; } @@ -112,7 +112,7 @@ int freerdp_tcp_connect(const char* hostname, int port) if (sockfd == -1) { - printf("unable to connect to %s:%s\n", hostname, servname); + fprintf(stderr, "unable to connect to %s:%s\n", hostname, servname); return -1; } @@ -138,7 +138,7 @@ int freerdp_tcp_read(int sockfd, BYTE* data, int length) if (wsa_error == WSAEWOULDBLOCK) return 0; - printf("recv() error: %d\n", wsa_error); + fprintf(stderr, "recv() error: %d\n", wsa_error); #else /* No data available */ if (errno == EAGAIN || errno == EWOULDBLOCK) @@ -184,7 +184,7 @@ int freerdp_tcp_wait_read(int sockfd) fd_set fds; if(sockfd<1) { - printf("Invalid socket to watch: %d\n",sockfd); + fprintf(stderr, "Invalid socket to watch: %d\n", sockfd); return 0 ; } FD_ZERO(&fds); @@ -199,7 +199,7 @@ int freerdp_tcp_wait_write(int sockfd) fd_set fds; if(sockfd<1) { - printf("Invalid socket to watch: %d\n",sockfd); + fprintf(stderr, "Invalid socket to watch: %d\n", sockfd); return 0; } diff --git a/libfreerdp/utils/thread.c b/libfreerdp/utils/thread.c deleted file mode 100644 index 6eaaf406f..000000000 --- a/libfreerdp/utils/thread.c +++ /dev/null @@ -1,99 +0,0 @@ -/** - * FreeRDP: A Remote Desktop Protocol Implementation - * Thread Utils - * - * Copyright 2011 Vic Lee - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <time.h> - -#include <winpr/crt.h> -#include <winpr/synch.h> -#include <winpr/windows.h> - -#ifdef _WIN32 -#ifdef _MSC_VER -#include <process.h> -#endif -#endif - -#include <freerdp/utils/thread.h> - -freerdp_thread* freerdp_thread_new(void) -{ - freerdp_thread* thread; - - thread = (freerdp_thread*) malloc(sizeof(freerdp_thread)); - ZeroMemory(thread, sizeof(freerdp_thread)); - - thread->mutex = CreateMutex(NULL, FALSE, NULL); - thread->signals[0] = CreateEvent(NULL, TRUE, FALSE, NULL); - thread->signals[1] = CreateEvent(NULL, TRUE, FALSE, NULL); - thread->num_signals = 2; - - return thread; -} - -void freerdp_thread_start(freerdp_thread* thread, void* func, void* arg) -{ - thread->status = 1; - -#ifdef _WIN32 - { - CloseHandle(CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) func, arg, 0, NULL)); - } -#else - { - pthread_t th; - pthread_create(&th, 0, func, arg); - pthread_detach(th); - } -#endif -} - -void freerdp_thread_stop(freerdp_thread* thread) -{ - int i = 0; - - SetEvent(thread->signals[0]); - - while ((thread->status > 0) && (i < 1000)) - { - i++; - Sleep(100); - } -} - -void freerdp_thread_free(freerdp_thread* thread) -{ - int i; - - for (i = 0; i < thread->num_signals; i++) - CloseHandle(thread->signals[i]); - - thread->num_signals = 0; - - CloseHandle(thread->mutex); - thread->mutex = NULL; - - free(thread); -} diff --git a/libfreerdp/utils/time.c b/libfreerdp/utils/time.c index 62209ec9d..31b51564f 100644 --- a/libfreerdp/utils/time.c +++ b/libfreerdp/utils/time.c @@ -43,7 +43,7 @@ UINT64 freerdp_windows_gmtime() UINT64 freerdp_get_windows_time_from_unix_time(time_t unix_time) { UINT64 windows_time; - windows_time = (unix_time * 10000000) + 621355968000000000ULL; + windows_time = ((UINT64)unix_time * 10000000) + 621355968000000000ULL; return windows_time; } diff --git a/server/Mac/mf_audin.c b/server/Mac/mf_audin.c index fb5e54b45..94de80984 100644 --- a/server/Mac/mf_audin.c +++ b/server/Mac/mf_audin.c @@ -25,35 +25,28 @@ #include "mf_audin.h" -static const AUDIO_FORMAT audio_formats[] = +static const AUDIO_FORMAT supported_audio_formats[] = { - { 0x11, 2, 22050, 1024, 4, 0, NULL }, /* IMA ADPCM, 22050 Hz, 2 channels */ - { 0x11, 1, 22050, 512, 4, 0, NULL }, /* IMA ADPCM, 22050 Hz, 1 channels */ - { 0x01, 2, 22050, 4, 16, 0, NULL }, /* PCM, 22050 Hz, 2 channels, 16 bits */ - { 0x01, 1, 22050, 2, 16, 0, NULL }, /* PCM, 22050 Hz, 1 channels, 16 bits */ - { 0x01, 2, 44100, 4, 16, 0, NULL }, /* PCM, 44100 Hz, 2 channels, 16 bits */ - { 0x01, 1, 44100, 2, 16, 0, NULL }, /* PCM, 44100 Hz, 1 channels, 16 bits */ - { 0x01, 2, 11025, 4, 16, 0, NULL }, /* PCM, 11025 Hz, 2 channels, 16 bits */ - { 0x01, 1, 11025, 2, 16, 0, NULL }, /* PCM, 11025 Hz, 1 channels, 16 bits */ - { 0x01, 2, 8000, 4, 16, 0, NULL }, /* PCM, 8000 Hz, 2 channels, 16 bits */ - { 0x01, 1, 8000, 2, 16, 0, NULL } /* PCM, 8000 Hz, 1 channels, 16 bits */ + + { WAVE_FORMAT_PCM, 2, 44100, 176400, 4, 16, NULL }, + { WAVE_FORMAT_ALAW, 2, 22050, 44100, 2, 8, NULL } }; static void mf_peer_audin_opening(audin_server_context* context) { - printf("AUDIN opening.\n"); + fprintf(stderr, "AUDIN opening.\n"); /* Simply choose the first format supported by the client. */ context->SelectFormat(context, 0); } static void mf_peer_audin_open_result(audin_server_context* context, UINT32 result) { - printf("AUDIN open result %d.\n", result); + fprintf(stderr, "AUDIN open result %d.\n", result); } static void mf_peer_audin_receive_samples(audin_server_context* context, const void* buf, int nframes) { - printf("AUDIN receive %d frames.\n", nframes); + fprintf(stderr, "AUDIN receive %d frames.\n", nframes); } void mf_peer_audin_init(mfPeerContext* context) @@ -61,8 +54,8 @@ void mf_peer_audin_init(mfPeerContext* context) context->audin = audin_server_context_new(context->vcm); context->audin->data = context; - context->audin->server_formats = audio_formats; - context->audin->num_server_formats = sizeof(audio_formats) / sizeof(audio_formats[0]); + context->audin->server_formats = supported_audio_formats; + context->audin->num_server_formats = sizeof(supported_audio_formats) / sizeof(supported_audio_formats[0]); context->audin->dst_format.wFormatTag = 1; context->audin->dst_format.nChannels = 2; diff --git a/server/Mac/mf_event.c b/server/Mac/mf_event.c index 8171db39f..6e68e6b85 100644 --- a/server/Mac/mf_event.c +++ b/server/Mac/mf_event.c @@ -51,7 +51,7 @@ void mf_signal_event(mfEventQueue* event_queue) length = write(event_queue->pipe_fd[1], "sig", 4); if (length != 4) - printf("mf_signal_event: error\n"); + fprintf(stderr, "mf_signal_event: error\n"); } void mf_set_event(mfEventQueue* event_queue) @@ -61,7 +61,7 @@ void mf_set_event(mfEventQueue* event_queue) length = write(event_queue->pipe_fd[1], "sig", 4); if (length != 4) - printf("mf_set_event: error\n"); + fprintf(stderr, "mf_set_event: error\n"); } void mf_clear_events(mfEventQueue* event_queue) @@ -73,7 +73,7 @@ void mf_clear_events(mfEventQueue* event_queue) length = read(event_queue->pipe_fd[0], &length, 4); if (length != 4) - printf("mf_clear_event: error\n"); + fprintf(stderr, "mf_clear_event: error\n"); } } @@ -84,7 +84,7 @@ void mf_clear_event(mfEventQueue* event_queue) length = read(event_queue->pipe_fd[0], &length, 4); if (length != 4) - printf("mf_clear_event: error\n"); + fprintf(stderr, "mf_clear_event: error\n"); } void mf_event_push(mfEventQueue* event_queue, mfEvent* event) @@ -188,7 +188,7 @@ mfEventQueue* mf_event_queue_new() event_queue->events = (mfEvent**) malloc(sizeof(mfEvent*) * event_queue->size); if (pipe(event_queue->pipe_fd) < 0) - printf("mf_event_queue_new: pipe failed\n"); + fprintf(stderr, "mf_event_queue_new: pipe failed\n"); pthread_mutex_init(&(event_queue->mutex), NULL); } @@ -211,4 +211,4 @@ void mf_event_queue_free(mfEventQueue* event_queue) } pthread_mutex_destroy(&(event_queue->mutex)); -} \ No newline at end of file +} diff --git a/server/Mac/mf_input.c b/server/Mac/mf_input.c index b24748464..ce58f5476 100644 --- a/server/Mac/mf_input.c +++ b/server/Mac/mf_input.c @@ -356,8 +356,8 @@ void mf_input_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code) /* if (flags & KBD_FLAGS_EXTENDED) - printf("extended "); - printf("keypress: down = %d, SCAN=%#0X, VK=%#0X\n", keyDown, code, keymap[code]); + fprintf(stderr, "extended "); + fprintf(stderr, "keypress: down = %d, SCAN=%#0X, VK=%#0X\n", keyDown, code, keymap[code]); */ } @@ -548,7 +548,7 @@ void mf_input_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y) void mf_input_extended_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y) { - printf("Unhandled mouse event!!!\n"); + fprintf(stderr, "Unhandled mouse event!!!\n"); /* if ((flags & PTR_XFLAGS_BUTTON1) || (flags & PTR_XFLAGS_BUTTON2)) { @@ -615,4 +615,4 @@ void mf_input_mouse_event_dummy(rdpInput* input, UINT16 flags, UINT16 x, UINT16 void mf_input_extended_mouse_event_dummy(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y) { -} \ No newline at end of file +} diff --git a/server/Mac/mf_interface.h b/server/Mac/mf_interface.h index b81e00407..cf383ad89 100644 --- a/server/Mac/mf_interface.h +++ b/server/Mac/mf_interface.h @@ -26,7 +26,8 @@ #include <freerdp/codec/rfx.h> #include <freerdp/codec/nsc.h> #include <freerdp/listener.h> -#include <freerdp/utils/stream.h> + +#include <winpr/crt.h> //#ifdef WITH_SERVER_CHANNELS #include <freerdp/channels/wtsvc.h> @@ -50,7 +51,7 @@ struct mf_peer_context rdpContext _p; mfInfo* info; - STREAM* s; + wStream* s; BOOL activated; UINT32 frame_id; BOOL audin_open; @@ -101,4 +102,4 @@ struct mf_info BOOL force_all_disconnect; }; -#endif \ No newline at end of file +#endif diff --git a/server/Mac/mf_peer.c b/server/Mac/mf_peer.c index 39e873180..2d0c8ee61 100644 --- a/server/Mac/mf_peer.c +++ b/server/Mac/mf_peer.c @@ -23,7 +23,7 @@ #include <freerdp/listener.h> #include <freerdp/codec/rfx.h> -#include <freerdp/utils/stream.h> +#include <winpr/stream.h> #include <winpr/crt.h> @@ -83,7 +83,7 @@ BOOL mf_peer_check_fds(freerdp_peer* client) { if (event->type == MF_EVENT_TYPE_REGION) { - printf("unhandled event\n"); + fprintf(stderr, "unhandled event\n"); } else if (event->type == MF_EVENT_TYPE_FRAME_TICK) { @@ -121,7 +121,7 @@ void mf_peer_rfx_update(freerdp_peer* client) //encode - STREAM* s; + wStream* s; RFX_RECT rect; rdpUpdate* update; mfPeerContext* mfp; @@ -240,10 +240,10 @@ void mf_peer_init(freerdp_peer* client) if(info_timer) { - //printf("created timer\n"); + //fprintf(stderr, "created timer\n"); dispatch_source_set_timer(info_timer, DISPATCH_TIME_NOW, 42ull * NSEC_PER_MSEC, 100ull * NSEC_PER_MSEC); dispatch_source_set_event_handler(info_timer, ^{ - //printf("dispatch\n"); + //fprintf(stderr, "dispatch\n"); mfEvent* event = mf_event_new(MF_EVENT_TYPE_FRAME_TICK); mf_event_push(info_event_queue, (mfEvent*) event);} ); @@ -257,17 +257,17 @@ BOOL mf_peer_post_connect(freerdp_peer* client) mfPeerContext* context = (mfPeerContext*) client->context; rdpSettings* settings = client->settings; - printf("Client %s post connect\n", client->hostname); + fprintf(stderr, "Client %s post connect\n", client->hostname); if (client->settings->AutoLogonEnabled) { - printf(" and wants to login automatically as %s\\%s", + fprintf(stderr, " and wants to login automatically as %s\\%s", client->settings->Domain ? client->settings->Domain : "", client->settings->Username); /* A real server may perform OS login here if NLA is not executed previously. */ } - printf("\n"); + fprintf(stderr, "\n"); mfInfo* mfi = mf_info_get_instance(); mfi->scale = 1; @@ -278,7 +278,7 @@ BOOL mf_peer_post_connect(freerdp_peer* client) if ((settings->DesktopWidth != mfi->servscreen_width) || (settings->DesktopHeight != mfi->servscreen_height)) { - printf("Client requested resolution %dx%d, but will resize to %dx%d\n", + fprintf(stderr, "Client requested resolution %dx%d, but will resize to %dx%d\n", settings->DesktopWidth, settings->DesktopHeight, mfi->servscreen_width, mfi->servscreen_height); } @@ -332,7 +332,7 @@ BOOL mf_peer_activate(freerdp_peer* client) /*BOOL wf_peer_logon(freerdp_peer* client, SEC_WINNT_AUTH_IDENTITY* identity, BOOL automatic) { - printf("PeerLogon\n"); + fprintf(stderr, "PeerLogon\n"); if (automatic) { @@ -347,12 +347,12 @@ BOOL mf_peer_activate(freerdp_peer* client) void mf_peer_synchronize_event(rdpInput* input, UINT32 flags) { - printf("Client sent a synchronize event (flags:0x%08X)\n", flags); + fprintf(stderr, "Client sent a synchronize event (flags:0x%08X)\n", flags); } void mf_peer_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code) { - printf("Client sent a keyboard event (flags:0x%04X code:0x%04X)\n", flags, code); + fprintf(stderr, "Client sent a keyboard event (flags:0x%04X code:0x%04X)\n", flags, code); UINT16 down = 0x4000; //UINT16 up = 0x8000; @@ -374,28 +374,28 @@ void mf_peer_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code) void mf_peer_unicode_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code) { - printf("Client sent a unicode keyboard event (flags:0x%04X code:0x%04X)\n", flags, code); + fprintf(stderr, "Client sent a unicode keyboard event (flags:0x%04X code:0x%04X)\n", flags, code); } /*void mf_peer_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y) { - //printf("Client sent a mouse event (flags:0x%04X pos: %d,%d)\n", flags, x, y); + //fprintf(stderr, "Client sent a mouse event (flags:0x%04X pos: %d,%d)\n", flags, x, y); } void mf_peer_extended_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y) { - //printf("Client sent an extended mouse event (flags:0x%04X pos: %d,%d)\n", flags, x, y); + //fprintf(stderr, "Client sent an extended mouse event (flags:0x%04X pos: %d,%d)\n", flags, x, y); } */ /*static void mf_peer_refresh_rect(rdpContext* context, BYTE count, RECTANGLE_16* areas) { BYTE i; - printf("Client requested to refresh:\n"); + fprintf(stderr, "Client requested to refresh:\n"); for (i = 0; i < count; i++) { - printf(" (%d, %d) (%d, %d)\n", areas[i].left, areas[i].top, areas[i].right, areas[i].bottom); + fprintf(stderr, " (%d, %d) (%d, %d)\n", areas[i].left, areas[i].top, areas[i].right, areas[i].bottom); } }*/ @@ -403,11 +403,11 @@ static void mf_peer_suppress_output(rdpContext* context, BYTE allow, RECTANGLE_1 { if (allow > 0) { - printf("Client restore output (%d, %d) (%d, %d).\n", area->left, area->top, area->right, area->bottom); + fprintf(stderr, "Client restore output (%d, %d) (%d, %d).\n", area->left, area->top, area->right, area->bottom); } else { - printf("Client minimized and suppress output.\n"); + fprintf(stderr, "Client minimized and suppress output.\n"); } } @@ -432,7 +432,7 @@ void mf_peer_accepted(freerdp_listener* instance, freerdp_peer* client) ZeroMemory(rfds, sizeof(rfds)); context = (wfPeerContext*) client->context; - printf("PeerSocketListener\n"); + fprintf(stderr, "PeerSocketListener\n"); while (1) { @@ -440,7 +440,7 @@ void mf_peer_accepted(freerdp_listener* instance, freerdp_peer* client) if (client->GetFileDescriptor(client, rfds, &rcount) != TRUE) { - printf("Failed to get peer file descriptor\n"); + fprintf(stderr, "Failed to get peer file descriptor\n"); break; } @@ -469,7 +469,7 @@ void mf_peer_accepted(freerdp_listener* instance, freerdp_peer* client) break; } - printf("Exiting Peer Socket Listener Thread\n"); + fprintf(stderr, "Exiting Peer Socket Listener Thread\n"); return 0; } @@ -522,7 +522,7 @@ void* mf_peer_main_loop(void* arg) client->Initialize(client); context = (mfPeerContext*) client->context; - printf("We've got a client %s\n", client->local ? "(local)" : client->hostname); + fprintf(stderr, "We've got a client %s\n", client->local ? "(local)" : client->hostname); while (1) { @@ -530,12 +530,12 @@ void* mf_peer_main_loop(void* arg) if (client->GetFileDescriptor(client, rfds, &rcount) != TRUE) { - printf("Failed to get FreeRDP file descriptor\n"); + fprintf(stderr, "Failed to get FreeRDP file descriptor\n"); break; } if (mf_peer_get_fds(client, rfds, &rcount) != TRUE) { - printf("Failed to get mfreerdp file descriptor\n"); + fprintf(stderr, "Failed to get mfreerdp file descriptor\n"); break; } @@ -567,19 +567,19 @@ void* mf_peer_main_loop(void* arg) (errno == EINPROGRESS) || (errno == EINTR))) /* signal occurred */ { - printf("select failed\n"); + fprintf(stderr, "select failed\n"); break; } } if (client->CheckFileDescriptor(client) != TRUE) { - printf("Failed to check freerdp file descriptor\n"); + fprintf(stderr, "Failed to check freerdp file descriptor\n"); break; } if ((mf_peer_check_fds(client)) != TRUE) { - printf("Failed to check mfreerdp file descriptor\n"); + fprintf(stderr, "Failed to check mfreerdp file descriptor\n"); break; } @@ -591,7 +591,7 @@ void* mf_peer_main_loop(void* arg) } - printf("Client %s disconnected.\n", client->local ? "(local)" : client->hostname); + fprintf(stderr, "Client %s disconnected.\n", client->local ? "(local)" : client->hostname); client->Disconnect(client); freerdp_peer_context_free(client); diff --git a/server/Mac/mf_rdpsnd.c b/server/Mac/mf_rdpsnd.c index 1215837d1..2e273ded3 100644 --- a/server/Mac/mf_rdpsnd.c +++ b/server/Mac/mf_rdpsnd.c @@ -28,51 +28,27 @@ AQRecorderState recorderState; -static const AUDIO_FORMAT audio_formats[] = -{ - { 0x11, 2, 22050, 1024, 4, 0, NULL }, /* IMA ADPCM, 22050 Hz, 2 channels */ - { 0x11, 1, 22050, 512, 4, 0, NULL }, /* IMA ADPCM, 22050 Hz, 1 channels */ - { 0x01, 2, 22050, 4, 16, 0, NULL }, /* PCM, 22050 Hz, 2 channels, 16 bits */ - { 0x01, 1, 22050, 2, 16, 0, NULL }, /* PCM, 22050 Hz, 1 channels, 16 bits */ - { 0x01, 2, 44100, 4, 16, 0, NULL }, /* PCM, 44100 Hz, 2 channels, 16 bits */ - { 0x01, 1, 44100, 2, 16, 0, NULL }, /* PCM, 44100 Hz, 1 channels, 16 bits */ - { 0x01, 2, 11025, 4, 16, 0, NULL }, /* PCM, 11025 Hz, 2 channels, 16 bits */ - { 0x01, 1, 11025, 2, 16, 0, NULL }, /* PCM, 11025 Hz, 1 channels, 16 bits */ - { 0x01, 2, 8000, 4, 16, 0, NULL }, /* PCM, 8000 Hz, 2 channels, 16 bits */ - { 0x01, 1, 8000, 2, 16, 0, NULL } /* PCM, 8000 Hz, 1 channels, 16 bits */ -}; - -/* - UINT16 wFormatTag; - UINT16 nChannels; - UINT32 nSamplesPerSec; - UINT32 nAvgBytesPerSec; - UINT16 nBlockAlign; - UINT16 wBitsPerSample; - UINT16 cbSize; - BYTE* data; - */ static const AUDIO_FORMAT supported_audio_formats[] = { - { WAVE_FORMAT_PCM, 2, 44100, 176400, 4, 16, NULL }, { WAVE_FORMAT_ALAW, 2, 22050, 44100, 2, 8, NULL } }; - static void mf_peer_rdpsnd_activated(rdpsnd_server_context* context) { OSStatus status; int i, j; BOOL formatAgreed = FALSE; AUDIO_FORMAT* agreedFormat = NULL; + //we should actually loop through the list of client formats here //and see if we can send the client something that it supports... printf("Client supports the following %d formats: \n", context->num_client_formats); - for(i = 0; i < context->num_client_formats; i++) + + for (i = 0; i < context->num_client_formats; i++) { - //TODO: improve the way we agree on a format + /* TODO: improve the way we agree on a format */ for (j = 0; j < context->num_server_formats; j++) { if ((context->client_formats[i].wFormatTag == context->server_formats[j].wFormatTag) && diff --git a/server/Mac/mfreerdp.c b/server/Mac/mfreerdp.c index f433be2d0..e1679d36a 100644 --- a/server/Mac/mfreerdp.c +++ b/server/Mac/mfreerdp.c @@ -58,7 +58,7 @@ static void mf_server_main_loop(freerdp_listener* instance) if (instance->GetFileDescriptor(instance, rfds, &rcount) != TRUE) { - printf("Failed to get FreeRDP file descriptor\n"); + fprintf(stderr, "Failed to get FreeRDP file descriptor\n"); break; } @@ -86,14 +86,14 @@ static void mf_server_main_loop(freerdp_listener* instance) (errno == EINPROGRESS) || (errno == EINTR))) /* signal occurred */ { - printf("select failed\n"); + fprintf(stderr, "select failed\n"); break; } } if (instance->CheckFileDescriptor(instance) != TRUE) { - printf("Failed to check FreeRDP file descriptor\n"); + fprintf(stderr, "Failed to check FreeRDP file descriptor\n"); break; } } diff --git a/server/Sample/sf_audin.c b/server/Sample/sf_audin.c index 4baa6affc..3d2a5538d 100644 --- a/server/Sample/sf_audin.c +++ b/server/Sample/sf_audin.c @@ -27,16 +27,8 @@ static const AUDIO_FORMAT test_audio_formats[] = { - { 0x11, 2, 22050, 1024, 4, 0, NULL }, /* IMA ADPCM, 22050 Hz, 2 channels */ - { 0x11, 1, 22050, 512, 4, 0, NULL }, /* IMA ADPCM, 22050 Hz, 1 channels */ - { 0x01, 2, 22050, 4, 16, 0, NULL }, /* PCM, 22050 Hz, 2 channels, 16 bits */ - { 0x01, 1, 22050, 2, 16, 0, NULL }, /* PCM, 22050 Hz, 1 channels, 16 bits */ - { 0x01, 2, 44100, 4, 16, 0, NULL }, /* PCM, 44100 Hz, 2 channels, 16 bits */ - { 0x01, 1, 44100, 2, 16, 0, NULL }, /* PCM, 44100 Hz, 1 channels, 16 bits */ - { 0x01, 2, 11025, 4, 16, 0, NULL }, /* PCM, 11025 Hz, 2 channels, 16 bits */ - { 0x01, 1, 11025, 2, 16, 0, NULL }, /* PCM, 11025 Hz, 1 channels, 16 bits */ - { 0x01, 2, 8000, 4, 16, 0, NULL }, /* PCM, 8000 Hz, 2 channels, 16 bits */ - { 0x01, 1, 8000, 2, 16, 0, NULL } /* PCM, 8000 Hz, 1 channels, 16 bits */ + { WAVE_FORMAT_PCM, 2, 44100, 176400, 4, 16, 0, NULL }, + { WAVE_FORMAT_ALAW, 2, 22050, 44100, 2, 8, 0, NULL } }; static void sf_peer_audin_opening(audin_server_context* context) diff --git a/server/Sample/sf_rdpsnd.c b/server/Sample/sf_rdpsnd.c index 62845cb4c..568db3bb5 100644 --- a/server/Sample/sf_rdpsnd.c +++ b/server/Sample/sf_rdpsnd.c @@ -27,16 +27,8 @@ static const AUDIO_FORMAT test_audio_formats[] = { - { 0x11, 2, 22050, 1024, 4, 0, NULL }, /* IMA ADPCM, 22050 Hz, 2 channels */ - { 0x11, 1, 22050, 512, 4, 0, NULL }, /* IMA ADPCM, 22050 Hz, 1 channels */ - { 0x01, 2, 22050, 4, 16, 0, NULL }, /* PCM, 22050 Hz, 2 channels, 16 bits */ - { 0x01, 1, 22050, 2, 16, 0, NULL }, /* PCM, 22050 Hz, 1 channels, 16 bits */ - { 0x01, 2, 44100, 4, 16, 0, NULL }, /* PCM, 44100 Hz, 2 channels, 16 bits */ - { 0x01, 1, 44100, 2, 16, 0, NULL }, /* PCM, 44100 Hz, 1 channels, 16 bits */ - { 0x01, 2, 11025, 4, 16, 0, NULL }, /* PCM, 11025 Hz, 2 channels, 16 bits */ - { 0x01, 1, 11025, 2, 16, 0, NULL }, /* PCM, 11025 Hz, 1 channels, 16 bits */ - { 0x01, 2, 8000, 4, 16, 0, NULL }, /* PCM, 8000 Hz, 2 channels, 16 bits */ - { 0x01, 1, 8000, 2, 16, 0, NULL } /* PCM, 8000 Hz, 1 channels, 16 bits */ + { WAVE_FORMAT_PCM, 2, 44100, 176400, 4, 16, 0, NULL }, + { WAVE_FORMAT_ALAW, 2, 22050, 44100, 2, 8, 0, NULL } }; static void sf_peer_rdpsnd_activated(rdpsnd_server_context* context) diff --git a/server/Sample/sfreerdp.c b/server/Sample/sfreerdp.c index 8331b8bd6..323edc532 100644 --- a/server/Sample/sfreerdp.c +++ b/server/Sample/sfreerdp.c @@ -69,8 +69,9 @@ void test_peer_context_free(freerdp_peer* client, testPeerContext* context) { if (context->debug_channel_thread) { - freerdp_thread_stop(context->debug_channel_thread); - freerdp_thread_free(context->debug_channel_thread); + SetEvent(context->stopEvent); + WaitForSingleObject(context->debug_channel_thread, INFINITE); + CloseHandle(context->debug_channel_thread); } stream_free(context->s); @@ -101,7 +102,7 @@ static void test_peer_init(freerdp_peer* client) freerdp_peer_context_new(client); } -static STREAM* test_peer_stream_init(testPeerContext* context) +static wStream* test_peer_stream_init(testPeerContext* context) { stream_clear(context->s); stream_set_pos(context->s, 0); @@ -135,7 +136,7 @@ static void test_peer_end_frame(freerdp_peer* client) static void test_peer_draw_background(freerdp_peer* client) { int size; - STREAM* s; + wStream* s; RFX_RECT rect; BYTE* rgb_data; rdpUpdate* update = client->update; @@ -232,7 +233,7 @@ static void test_peer_load_icon(freerdp_peer* client) static void test_peer_draw_icon(freerdp_peer* client, int x, int y) { - STREAM* s; + wStream* s; RFX_RECT rect; rdpUpdate* update = client->update; SURFACE_BITS_COMMAND* cmd = &update->surface_bits_command; @@ -354,7 +355,7 @@ static BOOL test_sleep_tsdiff(UINT32 *old_sec, UINT32 *old_usec, UINT32 new_sec, void tf_peer_dump_rfx(freerdp_peer* client) { - STREAM* s; + wStream* s; UINT32 prev_seconds; UINT32 prev_useconds; rdpUpdate* update; @@ -375,12 +376,12 @@ void tf_peer_dump_rfx(freerdp_peer* client) { pcap_get_next_record_header(pcap_rfx, &record); - s->data = realloc(s->data, record.length); - record.data = s->data; - s->size = record.length; + s->buffer = realloc(s->buffer, record.length); + record.data = s->buffer; + s->capacity = record.length; pcap_get_next_record_content(pcap_rfx, &record); - s->p = s->data + s->size; + s->pointer = s->buffer + s->capacity; if (test_dump_rfx_realtime && test_sleep_tsdiff(&prev_seconds, &prev_useconds, record.header.ts_sec, record.header.ts_usec) == FALSE) break; @@ -392,17 +393,17 @@ void tf_peer_dump_rfx(freerdp_peer* client) static void* tf_debug_channel_thread_func(void* arg) { void* fd; - STREAM* s; + wStream* s; void* buffer; UINT32 bytes_returned = 0; testPeerContext* context = (testPeerContext*) arg; - freerdp_thread* thread = context->debug_channel_thread; if (WTSVirtualChannelQuery(context->debug_channel, WTSVirtualFileHandle, &buffer, &bytes_returned) == TRUE) { fd = *((void**) buffer); WTSFreeMemory(buffer); - thread->signals[thread->num_signals++] = CreateFileDescriptorEvent(NULL, TRUE, FALSE, ((int) (long) fd)); + + context->event = CreateWaitObjectEvent(NULL, TRUE, FALSE, fd); } s = stream_new(4096); @@ -411,9 +412,9 @@ static void* tf_debug_channel_thread_func(void* arg) while (1) { - freerdp_thread_wait(thread); + WaitForSingleObject(context->event, INFINITE); - if (freerdp_thread_is_stopped(thread)) + if (WaitForSingleObject(context->stopEvent, 0) == WAIT_OBJECT_0) break; stream_set_pos(s, 0); @@ -440,7 +441,6 @@ static void* tf_debug_channel_thread_func(void* arg) } stream_free(s); - freerdp_thread_quit(thread); return 0; } @@ -489,9 +489,11 @@ BOOL tf_peer_post_connect(freerdp_peer* client) if (context->debug_channel != NULL) { printf("Open channel rdpdbg.\n"); - context->debug_channel_thread = freerdp_thread_new(); - freerdp_thread_start(context->debug_channel_thread, - tf_debug_channel_thread_func, context); + + context->stopEvent = CreateEvent(NULL, TRUE, FALSE, NULL); + + context->debug_channel_thread = CreateThread(NULL, 0, + (LPTHREAD_START_ROUTINE) tf_debug_channel_thread_func, (void*) context, 0, NULL); } } else if (strncmp(client->settings->ChannelDefArray[i].Name, "rdpsnd", 6) == 0) @@ -712,6 +714,7 @@ static void* test_peer_mainloop(void* arg) if (client->CheckFileDescriptor(client) != TRUE) break; + if (WTSVirtualChannelManagerCheckFileDescriptor(context->vcm) != TRUE) break; } diff --git a/server/Sample/sfreerdp.h b/server/Sample/sfreerdp.h index a0b497627..b5a05a4cb 100644 --- a/server/Sample/sfreerdp.h +++ b/server/Sample/sfreerdp.h @@ -24,18 +24,21 @@ #include <freerdp/listener.h> #include <freerdp/codec/rfx.h> #include <freerdp/codec/nsc.h> -#include <freerdp/utils/thread.h> #include <freerdp/channels/wtsvc.h> #include <freerdp/server/audin.h> #include <freerdp/server/rdpsnd.h> +#include <winpr/crt.h> +#include <winpr/synch.h> +#include <winpr/thread.h> + struct test_peer_context { rdpContext _p; RFX_CONTEXT* rfx_context; NSC_CONTEXT* nsc_context; - STREAM* s; + wStream* s; BYTE* icon_data; BYTE* bg_data; int icon_width; @@ -43,9 +46,11 @@ struct test_peer_context int icon_x; int icon_y; BOOL activated; + HANDLE event; + HANDLE stopEvent; WTSVirtualChannelManager* vcm; void* debug_channel; - freerdp_thread* debug_channel_thread; + HANDLE debug_channel_thread; audin_server_context* audin; BOOL audin_open; UINT32 frame_id; diff --git a/server/Windows/wf_interface.h b/server/Windows/wf_interface.h index cd7fcca6f..6352c5e2d 100644 --- a/server/Windows/wf_interface.h +++ b/server/Windows/wf_interface.h @@ -42,7 +42,7 @@ typedef struct wf_peer_context wfPeerContext; struct wf_info { - STREAM* s; + wStream* s; //screen and monitor info int screenID; diff --git a/server/Windows/wf_peer.c b/server/Windows/wf_peer.c index 695e1b5ce..8148c3a2d 100644 --- a/server/Windows/wf_peer.c +++ b/server/Windows/wf_peer.c @@ -27,7 +27,7 @@ #include <freerdp/listener.h> #include <freerdp/codec/rfx.h> -#include <freerdp/utils/stream.h> +#include <winpr/stream.h> #include "wf_info.h" #include "wf_input.h" diff --git a/server/Windows/wf_rdpsnd.c b/server/Windows/wf_rdpsnd.c index d9b4d742c..6b6847b7d 100644 --- a/server/Windows/wf_rdpsnd.c +++ b/server/Windows/wf_rdpsnd.c @@ -40,10 +40,10 @@ #endif -static const AUDIO_FORMAT audio_formats[] = -{ - { WAVE_FORMAT_PCM, 2, 44100, 176400, 4, 16, NULL }, - { WAVE_FORMAT_ALAW, 2, 22050, 44100, 2, 8, NULL } +static const AUDIO_FORMAT supported_audio_formats[] = +{ + { WAVE_FORMAT_PCM, 2, 44100, 176400, 4, 16, 0, NULL }, + { WAVE_FORMAT_ALAW, 2, 22050, 44100, 2, 8, 0, NULL } }; static void wf_peer_rdpsnd_activated(rdpsnd_server_context* context) @@ -65,7 +65,7 @@ static void wf_peer_rdpsnd_activated(rdpsnd_server_context* context) (context->client_formats[i].nSamplesPerSec == context->server_formats[j].nSamplesPerSec)) { printf("agreed on format!\n"); - wfi->agreed_format = (AUDIO_FORMAT*)&context->server_formats[j]; + wfi->agreed_format = (AUDIO_FORMAT*) &context->server_formats[j]; break; } } @@ -149,9 +149,9 @@ BOOL wf_peer_rdpsnd_init(wfPeerContext* context) context->rdpsnd = rdpsnd_server_context_new(context->vcm); context->rdpsnd->data = context; - context->rdpsnd->server_formats = audio_formats; + context->rdpsnd->server_formats = supported_audio_formats; context->rdpsnd->num_server_formats = - sizeof(audio_formats) / sizeof(audio_formats[0]); + sizeof(supported_audio_formats) / sizeof(supported_audio_formats[0]); context->rdpsnd->src_format.wFormatTag = 1; context->rdpsnd->src_format.nChannels = 2; diff --git a/server/X11/xf_encode.c b/server/X11/xf_encode.c index 3d40336b5..ca10744c4 100644 --- a/server/X11/xf_encode.c +++ b/server/X11/xf_encode.c @@ -146,7 +146,7 @@ void* xf_monitor_updates(void* param) if (select_status == -1) { - printf("select failed\n"); + fprintf(stderr, "select failed\n"); } else if (select_status == 0) { diff --git a/server/X11/xf_input.c b/server/X11/xf_input.c index b13c782a4..feac6ebf5 100644 --- a/server/X11/xf_input.c +++ b/server/X11/xf_input.c @@ -31,7 +31,7 @@ void xf_input_synchronize_event(rdpInput* input, UINT32 flags) { - printf("Client sent a synchronize event (flags:0x%X)\n", flags); + fprintf(stderr, "Client sent a synchronize event (flags:0x%X)\n", flags); } void xf_input_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code) @@ -63,7 +63,7 @@ void xf_input_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code) void xf_input_unicode_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code) { - printf("Client sent a unicode keyboard event (flags:0x%X code:0x%X)\n", flags, code); + fprintf(stderr, "Client sent a unicode keyboard event (flags:0x%X code:0x%X)\n", flags, code); } void xf_input_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y) diff --git a/server/X11/xf_peer.c b/server/X11/xf_peer.c index 8c589c9d9..7a4baddd3 100644 --- a/server/X11/xf_peer.c +++ b/server/X11/xf_peer.c @@ -33,13 +33,13 @@ #include <sys/select.h> #include <winpr/crt.h> +#include <winpr/file.h> +#include <winpr/path.h> #include <winpr/synch.h> #include <freerdp/freerdp.h> -#include <freerdp/locale/keyboard.h> #include <freerdp/codec/color.h> -#include <freerdp/utils/file.h> -#include <freerdp/utils/thread.h> +#include <freerdp/locale/keyboard.h> #include "xf_input.h" #include "xf_encode.h" @@ -64,20 +64,20 @@ void xf_xdamage_init(xfInfo* xfi) if (pixmaps != True) { - printf("XShmQueryVersion failed\n"); + fprintf(stderr, "XShmQueryVersion failed\n"); return; } } else { - printf("XShmQueryExtension failed\n"); + fprintf(stderr, "XShmQueryExtension failed\n"); return; } } if (XDamageQueryExtension(xfi->display, &damage_event, &damage_error) == 0) { - printf("XDamageQueryExtension failed\n"); + fprintf(stderr, "XDamageQueryExtension failed\n"); return; } @@ -85,12 +85,12 @@ void xf_xdamage_init(xfInfo* xfi) if (XDamageQueryVersion(xfi->display, &major, &minor) == 0) { - printf("XDamageQueryVersion failed\n"); + fprintf(stderr, "XDamageQueryVersion failed\n"); return; } else if (major < 1) { - printf("XDamageQueryVersion failed: major:%d minor:%d\n", major, minor); + fprintf(stderr, "XDamageQueryVersion failed: major:%d minor:%d\n", major, minor); return; } @@ -99,7 +99,7 @@ void xf_xdamage_init(xfInfo* xfi) if (xfi->xdamage == None) { - printf("XDamageCreate failed\n"); + fprintf(stderr, "XDamageCreate failed\n"); return; } @@ -108,7 +108,7 @@ void xf_xdamage_init(xfInfo* xfi) if (xfi->xdamage_region == None) { - printf("XFixesCreateRegion failed\n"); + fprintf(stderr, "XFixesCreateRegion failed\n"); XDamageDestroy(xfi->display, xfi->xdamage); xfi->xdamage = None; return; @@ -132,7 +132,7 @@ void xf_xshm_init(xfInfo* xfi) if (!xfi->fb_image) { - printf("XShmCreateImage failed\n"); + fprintf(stderr, "XShmCreateImage failed\n"); return; } @@ -141,7 +141,7 @@ void xf_xshm_init(xfInfo* xfi) if (xfi->fb_shm_info.shmid == -1) { - printf("shmget failed\n"); + fprintf(stderr, "shmget failed\n"); return; } @@ -151,7 +151,7 @@ void xf_xshm_init(xfInfo* xfi) if (xfi->fb_shm_info.shmaddr == ((char*) -1)) { - printf("shmat failed\n"); + fprintf(stderr, "shmat failed\n"); return; } @@ -160,7 +160,7 @@ void xf_xshm_init(xfInfo* xfi) shmctl(xfi->fb_shm_info.shmid, IPC_RMID, 0); - printf("display: %p root_window: %p width: %d height: %d depth: %d\n", + fprintf(stderr, "display: %p root_window: %p width: %d height: %d depth: %d\n", xfi->display, (void*) xfi->root_window, xfi->fb_image->width, xfi->fb_image->height, xfi->fb_image->depth); xfi->fb_pixmap = XShmCreatePixmap(xfi->display, @@ -191,13 +191,13 @@ xfInfo* xf_info_init() xfi->use_xshm = FALSE; if (!XInitThreads()) - printf("warning: XInitThreads() failure\n"); + fprintf(stderr, "warning: XInitThreads() failure\n"); xfi->display = XOpenDisplay(NULL); if (!xfi->display) { - printf("failed to open display: %s\n", XDisplayName(NULL)); + fprintf(stderr, "failed to open display: %s\n", XDisplayName(NULL)); exit(1); } @@ -213,7 +213,7 @@ xfInfo* xf_info_init() if (!pfs) { - printf("XListPixmapFormats failed\n"); + fprintf(stderr, "XListPixmapFormats failed\n"); exit(1); } @@ -238,7 +238,7 @@ xfInfo* xf_info_init() if (vis == NULL) { - printf("XGetVisualInfo failed\n"); + fprintf(stderr, "XGetVisualInfo failed\n"); exit(1); } @@ -318,7 +318,7 @@ void xf_peer_init(freerdp_peer* client) pthread_mutex_init(&(xfp->mutex), NULL); } -STREAM* xf_peer_stream_init(xfPeerContext* context) +wStream* xf_peer_stream_init(xfPeerContext* context) { stream_clear(context->s); stream_set_pos(context->s, 0); @@ -333,7 +333,7 @@ void xf_peer_live_rfx(freerdp_peer* client) void xf_peer_rfx_update(freerdp_peer* client, int x, int y, int width, int height) { - STREAM* s; + wStream* s; BYTE* data; xfInfo* xfi; RFX_RECT rect; @@ -478,23 +478,23 @@ BOOL xf_peer_post_connect(freerdp_peer* client) * The server may start sending graphics output and receiving keyboard/mouse input after this * callback returns. */ - printf("Client %s is activated", client->hostname); + fprintf(stderr, "Client %s is activated", client->hostname); if (client->settings->AutoLogonEnabled) { - printf(" and wants to login automatically as %s\\%s", + fprintf(stderr, " and wants to login automatically as %s\\%s", client->settings->Domain ? client->settings->Domain : "", client->settings->Username); /* A real server may perform OS login here if NLA is not executed previously. */ } - printf("\n"); + fprintf(stderr, "\n"); - printf("Client requested desktop: %dx%dx%d\n", + fprintf(stderr, "Client requested desktop: %dx%dx%d\n", client->settings->DesktopWidth, client->settings->DesktopHeight, client->settings->ColorDepth); if (!client->settings->RemoteFxCodec) { - printf("Client does not support RemoteFX\n"); + fprintf(stderr, "Client does not support RemoteFX\n"); return FALSE; } @@ -536,7 +536,7 @@ void* xf_peer_main_loop(void* arg) ZeroMemory(rfds, sizeof(rfds)); - printf("We've got a client %s\n", client->hostname); + fprintf(stderr, "We've got a client %s\n", client->hostname); xf_peer_init(client); xfp = (xfPeerContext*) client->context; @@ -545,13 +545,13 @@ void* xf_peer_main_loop(void* arg) /* Initialize the real server settings here */ - server_file_path = freerdp_construct_path(settings->ConfigPath, "server"); + server_file_path = GetCombinedPath(settings->ConfigPath, "server"); - if (!freerdp_check_file_exists(server_file_path)) - freerdp_mkdir(server_file_path); + if (!PathFileExistsA(server_file_path)) + CreateDirectoryA(server_file_path, 0); - settings->CertificateFile = freerdp_construct_path(server_file_path, "server.crt"); - settings->PrivateKeyFile = freerdp_construct_path(server_file_path, "server.key"); + settings->CertificateFile = GetCombinedPath(server_file_path, "server.crt"); + settings->PrivateKeyFile = GetCombinedPath(server_file_path, "server.key"); settings->RemoteFxCodec = TRUE; settings->ColorDepth = 32; @@ -570,12 +570,12 @@ void* xf_peer_main_loop(void* arg) if (client->GetFileDescriptor(client, rfds, &rcount) != TRUE) { - printf("Failed to get FreeRDP file descriptor\n"); + fprintf(stderr, "Failed to get FreeRDP file descriptor\n"); break; } if (xf_peer_get_fds(client, rfds, &rcount) != TRUE) { - printf("Failed to get xfreerdp file descriptor\n"); + fprintf(stderr, "Failed to get xfreerdp file descriptor\n"); break; } @@ -603,24 +603,24 @@ void* xf_peer_main_loop(void* arg) (errno == EINPROGRESS) || (errno == EINTR))) /* signal occurred */ { - printf("select failed\n"); + fprintf(stderr, "select failed\n"); break; } } if (client->CheckFileDescriptor(client) != TRUE) { - printf("Failed to check freerdp file descriptor\n"); + fprintf(stderr, "Failed to check freerdp file descriptor\n"); break; } if ((xf_peer_check_fds(client)) != TRUE) { - printf("Failed to check xfreerdp file descriptor\n"); + fprintf(stderr, "Failed to check xfreerdp file descriptor\n"); break; } } - printf("Client %s disconnected.\n", client->hostname); + fprintf(stderr, "Client %s disconnected.\n", client->hostname); client->Disconnect(client); diff --git a/server/X11/xf_peer.h b/server/X11/xf_peer.h index 14bca7245..53135baa2 100644 --- a/server/X11/xf_peer.h +++ b/server/X11/xf_peer.h @@ -21,6 +21,7 @@ #define __XF_PEER_H #include <winpr/crt.h> +#include <winpr/stream.h> #include <winpr/collections.h> #include <freerdp/gdi/gdi.h> @@ -28,7 +29,6 @@ #include <freerdp/gdi/region.h> #include <freerdp/codec/rfx.h> #include <freerdp/listener.h> -#include <freerdp/utils/stream.h> #include <freerdp/utils/stopwatch.h> typedef struct xf_peer_context xfPeerContext; @@ -46,7 +46,7 @@ struct xf_peer_context rdpContext _p; int fps; - STREAM* s; + wStream* s; HGDI_DC hdc; xfInfo* info; int activations; diff --git a/server/X11/xfreerdp.c b/server/X11/xfreerdp.c index d0eb5c6c7..62bd98901 100644 --- a/server/X11/xfreerdp.c +++ b/server/X11/xfreerdp.c @@ -53,7 +53,7 @@ void xf_server_main_loop(freerdp_listener* instance) if (instance->GetFileDescriptor(instance, rfds, &rcount) != TRUE) { - printf("Failed to get FreeRDP file descriptor\n"); + fprintf(stderr, "Failed to get FreeRDP file descriptor\n"); break; } @@ -81,14 +81,14 @@ void xf_server_main_loop(freerdp_listener* instance) (errno == EINPROGRESS) || (errno == EINTR))) /* signal occurred */ { - printf("select failed\n"); + fprintf(stderr, "select failed\n"); break; } } if (instance->CheckFileDescriptor(instance) != TRUE) { - printf("Failed to check FreeRDP file descriptor\n"); + fprintf(stderr, "Failed to check FreeRDP file descriptor\n"); break; } } diff --git a/third-party/CMakeLists.txt b/third-party/CMakeLists.txt index 07bc7f806..09b1fd46e 100644 --- a/third-party/CMakeLists.txt +++ b/third-party/CMakeLists.txt @@ -29,3 +29,4 @@ foreach(dir ${all_valid_subdirs}) endif() endforeach(dir) +set(THIRD_PARTY_INCLUDES ${THIRD_PARTY_INCLUDES} PARENT_SCOPE) \ No newline at end of file diff --git a/winpr/include/winpr/collections.h b/winpr/include/winpr/collections.h index e8cafb01e..521e8578e 100644 --- a/winpr/include/winpr/collections.h +++ b/winpr/include/winpr/collections.h @@ -28,6 +28,7 @@ #include <winpr/wtypes.h> #include <winpr/synch.h> +#include <winpr/stream.h> typedef void* (*OBJECT_NEW_FN)(void); typedef void (*OBJECT_FREE_FN)(void* obj); @@ -61,8 +62,10 @@ struct _wQueue typedef struct _wQueue wQueue; WINPR_API int Queue_Count(wQueue* queue); -WINPR_API BOOL Queue_IsSynchronized(wQueue* queue); -WINPR_API HANDLE Queue_SyncRoot(wQueue* queue); + +WINPR_API BOOL Queue_Lock(wQueue* queue); +WINPR_API BOOL Queue_Unlock(wQueue* queue); + WINPR_API HANDLE Queue_Event(wQueue* queue); #define Queue_Object(_queue) (&_queue->object) @@ -276,6 +279,10 @@ WINPR_API void ObjectPool_Free(wObjectPool* pool); /* Message Queue */ +typedef struct _wMessage wMessage; + +typedef void (*MESSAGE_FREE_FN)(wMessage* message); + struct _wMessage { UINT32 id; @@ -283,8 +290,8 @@ struct _wMessage void* wParam; void* lParam; UINT64 time; + MESSAGE_FREE_FN Free; }; -typedef struct _wMessage wMessage; struct _wMessageQueue { diff --git a/winpr/include/winpr/error.h b/winpr/include/winpr/error.h index 8999d3858..077d2ca14 100644 --- a/winpr/include/winpr/error.h +++ b/winpr/include/winpr/error.h @@ -29,6 +29,10 @@ #else +#ifdef __cplusplus +extern "C" { +#endif + #ifndef NO_ERROR #define NO_ERROR 0 #endif @@ -2908,7 +2912,7 @@ WINPR_API UINT GetErrorMode(void); WINPR_API UINT SetErrorMode(UINT uMode); -WINPR_API DWORD GetLastError(VOID); +WINPR_API DWORD GetLastError(void); WINPR_API VOID SetLastError(DWORD dwErrCode); @@ -2928,6 +2932,10 @@ WINPR_API PVOID AddVectoredContinueHandler(ULONG First, PVECTORED_EXCEPTION_HAND WINPR_API ULONG RemoveVectoredContinueHandler(PVOID Handle); +#ifdef __cplusplus +} +#endif + #endif #endif /* WINPR_ERROR_H */ diff --git a/winpr/include/winpr/file.h b/winpr/include/winpr/file.h index 976312b50..efc190b23 100644 --- a/winpr/include/winpr/file.h +++ b/winpr/include/winpr/file.h @@ -257,18 +257,23 @@ WINPR_API BOOL FindNextFileW(HANDLE hFindFile, LPWIN32_FIND_DATAW lpFindFileData WINPR_API BOOL FindClose(HANDLE hFindFile); +WINPR_API BOOL CreateDirectoryA(LPCSTR lpPathName, LPSECURITY_ATTRIBUTES lpSecurityAttributes); +WINPR_API BOOL CreateDirectoryW(LPCWSTR lpPathName, LPSECURITY_ATTRIBUTES lpSecurityAttributes); + #ifdef UNICODE #define CreateFile CreateFileW #define DeleteFile DeleteFileW #define FindFirstFile FindFirstFileW #define FindFirstFileEx FindFirstFileExW #define FindNextFile FindNextFileW +#define CreateDirectory CreateDirectoryW #else #define CreateFile CreateFileA #define DeleteFile DeleteFileA #define FindFirstFile FindFirstFileA #define FindFirstFileEx FindFirstFileExA #define FindNextFile FindNextFileA +#define CreateDirectory CreateDirectoryA #endif #endif diff --git a/winpr/include/winpr/path.h b/winpr/include/winpr/path.h index e106d3e0c..d320ee17d 100644 --- a/winpr/include/winpr/path.h +++ b/winpr/include/winpr/path.h @@ -250,4 +250,32 @@ WINPR_API PCWSTR PathGetSharedLibraryExtensionW(unsigned long dwFlags); #endif +/** + * Shell Path Functions + */ + +#define KNOWN_PATH_HOME 1 +#define KNOWN_PATH_TEMP 2 +#define KNOWN_PATH_XDG_DATA_HOME 3 +#define KNOWN_PATH_XDG_CONFIG_HOME 4 +#define KNOWN_PATH_XDG_CACHE_HOME 5 +#define KNOWN_PATH_XDG_RUNTIME_DIR 6 + +WINPR_API char* GetKnownPath(int id); +WINPR_API char* GetKnownSubPath(int id, char* path); +WINPR_API char* GetCombinedPath(char* basePath, char* subPath); + +//#ifndef _WIN32 + +WINPR_API BOOL PathFileExistsA(LPCSTR pszPath); +WINPR_API BOOL PathFileExistsW(LPCWSTR pszPath); + +#ifdef UNICODE +#define PathFileExists PathFileExistsW +#else +#define PathFileExists PathFileExistsA +#endif + +//#endif + #endif /* WINPR_PATH_H */ diff --git a/winpr/include/winpr/security.h b/winpr/include/winpr/security.h index ab342cf3d..59f02d953 100644 --- a/winpr/include/winpr/security.h +++ b/winpr/include/winpr/security.h @@ -23,13 +23,6 @@ #include <winpr/winpr.h> #include <winpr/wtypes.h> -typedef struct _LSA_UNICODE_STRING -{ - USHORT Length; - USHORT MaximumLength; - PWSTR Buffer; -} LSA_UNICODE_STRING, *PLSA_UNICODE_STRING, UNICODE_STRING, *PUNICODE_STRING; - /** * Windows Integrity Mechanism Design: * http://msdn.microsoft.com/en-us/library/bb625963.aspx @@ -37,6 +30,13 @@ typedef struct _LSA_UNICODE_STRING #ifndef _WIN32 +typedef struct _LSA_UNICODE_STRING +{ + USHORT Length; + USHORT MaximumLength; + PWSTR Buffer; +} LSA_UNICODE_STRING, *PLSA_UNICODE_STRING, UNICODE_STRING, *PUNICODE_STRING; + #define SECURITY_MANDATORY_UNTRUSTED_RID 0x0000 #define SECURITY_MANDATORY_LOW_RID 0x1000 #define SECURITY_MANDATORY_MEDIUM_RID 0x2000 diff --git a/winpr/include/winpr/spec.h b/winpr/include/winpr/spec.h index 89c847d29..37b80f08f 100644 --- a/winpr/include/winpr/spec.h +++ b/winpr/include/winpr/spec.h @@ -20,23 +20,14 @@ #ifndef WINPR_SPEC_H #define WINPR_SPEC_H +#include <winpr/platform.h> + #ifdef _WIN32 #include <specstrings.h> #else -#if defined(__x86_64) && \ - !(defined(_X86_) || defined(__i386__) || defined(_IA64_)) -#if !defined(_AMD64_) -#define _AMD64_ -#endif -#endif /* _AMD64_ */ - -#ifdef _AMD64_ -#define _WIN64 -#endif - #ifndef DECLSPEC_ALIGN #if defined(_MSC_VER) && (_MSC_VER >= 1300) && !defined(MIDL_PASS) #define DECLSPEC_ALIGN(x) __declspec(align(x)) @@ -47,7 +38,7 @@ #endif #endif /* DECLSPEC_ALIGN */ -#ifdef _WIN64 +#ifdef _M_AMD64 #define MEMORY_ALLOCATION_ALIGNMENT 16 #else #define MEMORY_ALLOCATION_ALIGNMENT 8 @@ -55,7 +46,19 @@ #define DUMMYSTRUCTNAME s +#ifdef __GNUC__ +#ifndef __declspec +#define __declspec(e) __attribute__((e)) +#endif +#endif + +#ifndef DECLSPEC_NORETURN +#if (defined(__GNUC__) || defined(_MSC_VER)) +#define DECLSPEC_NORETURN __declspec(noreturn) +#else #define DECLSPEC_NORETURN +#endif +#endif /* DECLSPEC_NORETURN */ #endif diff --git a/winpr/include/winpr/stream.h b/winpr/include/winpr/stream.h index d4638fc88..6910734a0 100644 --- a/winpr/include/winpr/stream.h +++ b/winpr/include/winpr/stream.h @@ -24,14 +24,22 @@ #include <winpr/winpr.h> #include <winpr/wtypes.h> +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct _wStreamPool wStreamPool; + struct _wStream { BYTE* buffer; BYTE* pointer; size_t length; size_t capacity; -}; + DWORD count; + wStreamPool* pool; +}; typedef struct _wStream wStream; WINPR_API void Stream_EnsureCapacity(wStream* s, size_t size); @@ -186,4 +194,188 @@ WINPR_API void Stream_Free(wStream* s, BOOL bFreeBuffer); #define Stream_SetPosition(_s, _p) _s->pointer = _s->buffer + (_p) +/* Deprecated STREAM API */ + +WINPR_API wStream* stream_new(int size); +WINPR_API void stream_free(wStream* stream); + +#define stream_attach(_s, _buf, _size) do { \ + _s->capacity = _size; \ + _s->buffer = _buf; \ + _s->pointer = _buf; } while (0) +#define stream_detach(_s) memset(_s, 0, sizeof(wStream)) +#define stream_clear(_s) memset(_s->buffer, 0, _s->capacity) + +WINPR_API void stream_extend(wStream* stream, int request_size); +#define stream_check_size(_s, _n) \ + while (_s->pointer - _s->buffer + (_n) > _s->capacity) \ + stream_extend(_s, _n) + +#define stream_get_pos(_s) (_s->pointer - _s->buffer) +#define stream_set_pos(_s,_m) _s->pointer = _s->buffer + (_m) +#define stream_seek(_s,_offset) _s->pointer += (_offset) +#define stream_rewind(_s,_offset) _s->pointer -= (_offset) +#define stream_seal(_s) _s->capacity = (_s->pointer - _s->buffer) +#define stream_get_mark(_s,_mark) _mark = _s->pointer +#define stream_set_mark(_s,_mark) _s->pointer = _mark +#define stream_get_head(_s) _s->buffer +#define stream_get_tail(_s) _s->pointer +#define stream_get_length(_s) (_s->pointer - _s->buffer) +#define stream_get_data(_s) (_s->buffer) +#define stream_get_size(_s) (_s->capacity) +#define stream_get_left(_s) (_s->capacity - (_s->pointer - _s->buffer)) + +#define stream_read_BYTE(_s, _v) do { _v = *_s->pointer++; } while (0) +#define stream_read_UINT16(_s, _v) do { _v = \ + (UINT16)(*_s->pointer) + \ + (UINT16)(((UINT16)(*(_s->pointer + 1))) << 8); \ + _s->pointer += 2; } while (0) +#define stream_read_UINT32(_s, _v) do { _v = \ + (UINT32)(*_s->pointer) + \ + (((UINT32)(*(_s->pointer + 1))) << 8) + \ + (((UINT32)(*(_s->pointer + 2))) << 16) + \ + (((UINT32)(*(_s->pointer + 3))) << 24); \ + _s->pointer += 4; } while (0) +#define stream_read_UINT64(_s, _v) do { _v = \ + (UINT64)(*_s->pointer) + \ + (((UINT64)(*(_s->pointer + 1))) << 8) + \ + (((UINT64)(*(_s->pointer + 2))) << 16) + \ + (((UINT64)(*(_s->pointer + 3))) << 24) + \ + (((UINT64)(*(_s->pointer + 4))) << 32) + \ + (((UINT64)(*(_s->pointer + 5))) << 40) + \ + (((UINT64)(*(_s->pointer + 6))) << 48) + \ + (((UINT64)(*(_s->pointer + 7))) << 56); \ + _s->pointer += 8; } while (0) +#define stream_read(_s, _b, _n) do { \ + memcpy(_b, (_s->pointer), (_n)); \ + _s->pointer += (_n); \ + } while (0) + +#define stream_write_BYTE(_s, _v) do { \ + *_s->pointer++ = (BYTE)(_v); } while (0) +#define stream_write_UINT16(_s, _v) do { \ + *_s->pointer++ = (_v) & 0xFF; \ + *_s->pointer++ = ((_v) >> 8) & 0xFF; } while (0) +#define stream_write_UINT32(_s, _v) do { \ + *_s->pointer++ = (_v) & 0xFF; \ + *_s->pointer++ = ((_v) >> 8) & 0xFF; \ + *_s->pointer++ = ((_v) >> 16) & 0xFF; \ + *_s->pointer++ = ((_v) >> 24) & 0xFF; } while (0) +#define stream_write_UINT64(_s, _v) do { \ + *_s->pointer++ = (UINT64)(_v) & 0xFF; \ + *_s->pointer++ = ((UINT64)(_v) >> 8) & 0xFF; \ + *_s->pointer++ = ((UINT64)(_v) >> 16) & 0xFF; \ + *_s->pointer++ = ((UINT64)(_v) >> 24) & 0xFF; \ + *_s->pointer++ = ((UINT64)(_v) >> 32) & 0xFF; \ + *_s->pointer++ = ((UINT64)(_v) >> 40) & 0xFF; \ + *_s->pointer++ = ((UINT64)(_v) >> 48) & 0xFF; \ + *_s->pointer++ = ((UINT64)(_v) >> 56) & 0xFF; } while (0) +#define stream_write(_s, _b, _n) do { \ + memcpy(_s->pointer, (_b), (_n)); \ + _s->pointer += (_n); \ + } while (0) +#define stream_write_zero(_s, _n) do { \ + memset(_s->pointer, '\0', (_n)); \ + _s->pointer += (_n); \ + } while (0) +#define stream_set_byte(_s, _v, _n) do { \ + memset(_s->pointer, _v, (_n)); \ + _s->pointer += (_n); \ + } while (0) + +#define stream_peek_BYTE(_s, _v) do { _v = *_s->pointer; } while (0) +#define stream_peek_UINT16(_s, _v) do { _v = \ + (UINT16)(*_s->pointer) + \ + (((UINT16)(*(_s->pointer + 1))) << 8); \ + } while (0) +#define stream_peek_UINT32(_s, _v) do { _v = \ + (UINT32)(*_s->pointer) + \ + (((UINT32)(*(_s->pointer + 1))) << 8) + \ + (((UINT32)(*(_s->pointer + 2))) << 16) + \ + (((UINT32)(*(_s->pointer + 3))) << 24); \ + } while (0) +#define stream_peek_UINT64(_s, _v) do { _v = \ + (UINT64)(*_s->pointer) + \ + (((UINT64)(*(_s->pointer + 1))) << 8) + \ + (((UINT64)(*(_s->pointer + 2))) << 16) + \ + (((UINT64)(*(_s->pointer + 3))) << 24) + \ + (((UINT64)(*(_s->pointer + 4))) << 32) + \ + (((UINT64)(*(_s->pointer + 5))) << 40) + \ + (((UINT64)(*(_s->pointer + 6))) << 48) + \ + (((UINT64)(*(_s->pointer + 7))) << 56); \ + } while (0) + +#define stream_seek_BYTE(_s) stream_seek(_s, 1) +#define stream_seek_UINT16(_s) stream_seek(_s, 2) +#define stream_seek_UINT32(_s) stream_seek(_s, 4) +#define stream_seek_UINT64(_s) stream_seek(_s, 8) + +#define stream_read_UINT16_be(_s, _v) do { _v = \ + (((UINT16)(*_s->pointer)) << 8) + \ + (UINT16)(*(_s->pointer + 1)); \ + _s->pointer += 2; } while (0) +#define stream_read_UINT32_be(_s, _v) do { _v = \ + (((UINT32)(*(_s->pointer))) << 24) + \ + (((UINT32)(*(_s->pointer + 1))) << 16) + \ + (((UINT32)(*(_s->pointer + 2))) << 8) + \ + (((UINT32)(*(_s->pointer + 3)))); \ + _s->pointer += 4; } while (0) + +#define stream_write_UINT16_be(_s, _v) do { \ + *_s->pointer++ = ((_v) >> 8) & 0xFF; \ + *_s->pointer++ = (_v) & 0xFF; } while (0) +#define stream_write_UINT32_be(_s, _v) do { \ + stream_write_UINT16_be(_s, ((_v) >> 16 & 0xFFFF)); \ + stream_write_UINT16_be(_s, ((_v) & 0xFFFF)); \ + } while (0) + +#define stream_copy(_dst, _src, _n) do { \ + memcpy(_dst->pointer, _src->pointer, _n); \ + _dst->pointer += _n; \ + _src->pointer += _n; \ + } while (0) + +static INLINE BOOL stream_skip(wStream* s, int sz) { + if ((int) stream_get_left(s) < sz) + return FALSE; + stream_seek(s, sz); + return TRUE; +} + +/* StreamPool */ + +struct _wStreamPool +{ + int aSize; + int aCapacity; + wStream** aArray; + + int uSize; + int uCapacity; + wStream** uArray; + + HANDLE mutex; + BOOL synchronized; + size_t defaultSize; +}; + +WINPR_API wStream* StreamPool_Take(wStreamPool* pool, size_t size); +WINPR_API void StreamPool_Return(wStreamPool* pool, wStream* s); + +WINPR_API void Stream_AddRef(wStream* s); +WINPR_API void Stream_Release(wStream* s); + +WINPR_API wStream* StreamPool_Find(wStreamPool* pool, BYTE* ptr); +WINPR_API void StreamPool_AddRef(wStreamPool* pool, BYTE* ptr); +WINPR_API void StreamPool_Release(wStreamPool* pool, BYTE* ptr); + +WINPR_API void StreamPool_Clear(wStreamPool* pool); + +WINPR_API wStreamPool* StreamPool_New(BOOL synchronized, size_t defaultSize); +WINPR_API void StreamPool_Free(wStreamPool* pool); + +#ifdef __cplusplus +} +#endif + #endif /* WINPR_UTILS_STREAM_H */ diff --git a/winpr/include/winpr/string.h b/winpr/include/winpr/string.h index 6bcae3eee..8cb2466f0 100644 --- a/winpr/include/winpr/string.h +++ b/winpr/include/winpr/string.h @@ -25,6 +25,10 @@ #include <winpr/winpr.h> #include <winpr/wtypes.h> +#ifdef __cplusplus +extern "C" { +#endif + #ifndef _WIN32 #define CSTR_LESS_THAN 1 @@ -174,4 +178,8 @@ WINPR_API int ConvertToUnicode(UINT CodePage, DWORD dwFlags, LPCSTR lpMultiByteS WINPR_API int ConvertFromUnicode(UINT CodePage, DWORD dwFlags, LPCWSTR lpWideCharStr, int cchWideChar, LPSTR* lpMultiByteStr, int cbMultiByte, LPCSTR lpDefaultChar, LPBOOL lpUsedDefaultChar); +#ifdef __cplusplus +} +#endif + #endif /* WINPR_CRT_STRING_H */ diff --git a/winpr/include/winpr/thread.h b/winpr/include/winpr/thread.h index 6f7610277..5fe7adab0 100644 --- a/winpr/include/winpr/thread.h +++ b/winpr/include/winpr/thread.h @@ -23,8 +23,13 @@ #include <winpr/winpr.h> #include <winpr/wtypes.h> +#include <winpr/spec.h> #include <winpr/handle.h> +#ifdef __cplusplus +extern "C" { +#endif + #ifndef _WIN32 typedef struct _STARTUPINFOA @@ -105,10 +110,10 @@ WINPR_API BOOL CreateProcessAsUserW(HANDLE hToken, LPCWSTR lpApplicationName, LP #define CreateProcessAsUser CreateProcessAsUserA #endif -WINPR_API VOID ExitProcess(UINT uExitCode); +DECLSPEC_NORETURN WINPR_API VOID ExitProcess(UINT uExitCode); -WINPR_API HANDLE _GetCurrentProcess(VOID); -WINPR_API DWORD GetCurrentProcessId(VOID); +WINPR_API HANDLE _GetCurrentProcess(void); +WINPR_API DWORD GetCurrentProcessId(void); WINPR_API BOOL TerminateProcess(HANDLE hProcess, UINT uExitCode); @@ -123,26 +128,27 @@ WINPR_API HANDLE CreateThread(LPSECURITY_ATTRIBUTES lpThreadAttributes, SIZE_T d WINPR_API HANDLE CreateRemoteThread(HANDLE hProcess, LPSECURITY_ATTRIBUTES lpThreadAttributes, SIZE_T dwStackSize, LPTHREAD_START_ROUTINE lpStartAddress, LPVOID lpParameter, DWORD dwCreationFlags, LPDWORD lpThreadId); -WINPR_API VOID ExitThread(DWORD dwExitCode); +DECLSPEC_NORETURN WINPR_API VOID ExitThread(DWORD dwExitCode); +WINPR_API BOOL GetExitCodeThread(HANDLE hThread, LPDWORD lpExitCode); -WINPR_API HANDLE _GetCurrentThread(VOID); -WINPR_API DWORD GetCurrentThreadId(VOID); +WINPR_API HANDLE _GetCurrentThread(void); +WINPR_API DWORD GetCurrentThreadId(void); WINPR_API DWORD ResumeThread(HANDLE hThread); WINPR_API DWORD SuspendThread(HANDLE hThread); -WINPR_API BOOL SwitchToThread(VOID); +WINPR_API BOOL SwitchToThread(void); WINPR_API BOOL TerminateThread(HANDLE hThread, DWORD dwExitCode); /* Processor */ -WINPR_API DWORD GetCurrentProcessorNumber(VOID); +WINPR_API DWORD GetCurrentProcessorNumber(void); /* Thread-Local Storage */ #define TLS_OUT_OF_INDEXES ((DWORD) 0xFFFFFFFF) -WINPR_API DWORD TlsAlloc(VOID); +WINPR_API DWORD TlsAlloc(void); WINPR_API LPVOID TlsGetValue(DWORD dwTlsIndex); WINPR_API BOOL TlsSetValue(DWORD dwTlsIndex, LPVOID lpTlsValue); WINPR_API BOOL TlsFree(DWORD dwTlsIndex); @@ -157,5 +163,9 @@ WINPR_API BOOL TlsFree(DWORD dwTlsIndex); #endif +#ifdef __cplusplus +} +#endif + #endif /* WINPR_THREAD_H */ diff --git a/winpr/include/winpr/wtypes.h b/winpr/include/winpr/wtypes.h index d16bd2647..a840f16ad 100644 --- a/winpr/include/winpr/wtypes.h +++ b/winpr/include/winpr/wtypes.h @@ -26,6 +26,10 @@ #include <wchar.h> #include <winpr/windows.h> +#if defined(__OBJC__) && defined(__APPLE__) +#include <objc/objc.h> +#endif + #ifndef _WIN32 #define __int8 char diff --git a/winpr/libwinpr/crt/string.c b/winpr/libwinpr/crt/string.c index 2717ac06d..716c607a6 100644 --- a/winpr/libwinpr/crt/string.c +++ b/winpr/libwinpr/crt/string.c @@ -188,7 +188,7 @@ LPSTR CharUpperA(LPSTR lpsz) LPWSTR CharUpperW(LPWSTR lpsz) { - printf("CharUpperW unimplemented!\n"); + fprintf(stderr, "CharUpperW unimplemented!\n"); return (LPWSTR) NULL; } @@ -270,7 +270,7 @@ LPSTR CharLowerA(LPSTR lpsz) LPWSTR CharLowerW(LPWSTR lpsz) { - printf("CharLowerW unimplemented!\n"); + fprintf(stderr, "CharLowerW unimplemented!\n"); return (LPWSTR) NULL; } @@ -328,7 +328,7 @@ BOOL IsCharAlphaA(CHAR ch) BOOL IsCharAlphaW(WCHAR ch) { - printf("IsCharAlphaW unimplemented!\n"); + fprintf(stderr, "IsCharAlphaW unimplemented!\n"); return 0; } @@ -343,7 +343,7 @@ BOOL IsCharAlphaNumericA(CHAR ch) BOOL IsCharAlphaNumericW(WCHAR ch) { - printf("IsCharAlphaNumericW unimplemented!\n"); + fprintf(stderr, "IsCharAlphaNumericW unimplemented!\n"); return 0; } @@ -357,7 +357,7 @@ BOOL IsCharUpperA(CHAR ch) BOOL IsCharUpperW(WCHAR ch) { - printf("IsCharUpperW unimplemented!\n"); + fprintf(stderr, "IsCharUpperW unimplemented!\n"); return 0; } @@ -371,7 +371,7 @@ BOOL IsCharLowerA(CHAR ch) BOOL IsCharLowerW(WCHAR ch) { - printf("IsCharLowerW unimplemented!\n"); + fprintf(stderr, "IsCharLowerW unimplemented!\n"); return 0; } diff --git a/winpr/libwinpr/environment/CMakeLists.txt b/winpr/libwinpr/environment/CMakeLists.txt index 4951ec5e1..831fa7879 100644 --- a/winpr/libwinpr/environment/CMakeLists.txt +++ b/winpr/libwinpr/environment/CMakeLists.txt @@ -21,6 +21,10 @@ set(MODULE_PREFIX "WINPR_ENVIRONMENT") set(${MODULE_PREFIX}_SRCS environment.c) +if(MSVC AND (NOT MONOLITHIC_BUILD)) + set(${MODULE_PREFIX}_SRCS ${${MODULE_PREFIX}_SRCS} module.def) +endif() + add_complex_library(MODULE ${MODULE_NAME} TYPE "OBJECT" MONOLITHIC ${MONOLITHIC_BUILD} SOURCES ${${MODULE_PREFIX}_SRCS}) diff --git a/winpr/libwinpr/environment/environment.c b/winpr/libwinpr/environment/environment.c index 906198b31..058232d3c 100644 --- a/winpr/libwinpr/environment/environment.c +++ b/winpr/libwinpr/environment/environment.c @@ -132,7 +132,22 @@ BOOL NeedCurrentDirectoryForExePathW(LPCWSTR ExeName) DWORD GetEnvironmentVariableA(LPCSTR lpName, LPSTR lpBuffer, DWORD nSize) { - return 0; + int length; + char* env = NULL; + + env = getenv(lpName); + + if (!env) + return 0; + + length = strlen(env); + + if ((length + 1 > nSize) || (!lpBuffer)) + return length + 1; + + CopyMemory(lpBuffer, env, length + 1); + + return length; } DWORD GetEnvironmentVariableW(LPCWSTR lpName, LPWSTR lpBuffer, DWORD nSize) diff --git a/winpr/libwinpr/environment/module.def b/winpr/libwinpr/environment/module.def new file mode 100644 index 000000000..e46493ad3 --- /dev/null +++ b/winpr/libwinpr/environment/module.def @@ -0,0 +1,2 @@ +LIBRARY "libwinpr-environment" +EXPORTS diff --git a/winpr/libwinpr/file/file.c b/winpr/libwinpr/file/file.c index 00e5dc600..16cdabf63 100644 --- a/winpr/libwinpr/file/file.c +++ b/winpr/libwinpr/file/file.c @@ -426,5 +426,18 @@ BOOL FindClose(HANDLE hFindFile) return TRUE; } +BOOL CreateDirectoryA(LPCSTR lpPathName, LPSECURITY_ATTRIBUTES lpSecurityAttributes) +{ + if (!mkdir(lpPathName, S_IRUSR | S_IWUSR | S_IXUSR)) + return TRUE; + + return FALSE; +} + +BOOL CreateDirectoryW(LPCWSTR lpPathName, LPSECURITY_ATTRIBUTES lpSecurityAttributes) +{ + return TRUE; +} + #endif diff --git a/winpr/libwinpr/file/pattern.c b/winpr/libwinpr/file/pattern.c index a51677d1f..4a79cd3ce 100644 --- a/winpr/libwinpr/file/pattern.c +++ b/winpr/libwinpr/file/pattern.c @@ -190,7 +190,7 @@ BOOL FilePatternMatchSubExpressionA(LPCSTR lpFileName, size_t cchFileName, } else if (*lpWildcard == '~') { - printf("warning: unimplemented '~' pattern match\n"); + fprintf(stderr, "warning: unimplemented '~' pattern match\n"); return TRUE; } diff --git a/winpr/libwinpr/input/scancode.c b/winpr/libwinpr/input/scancode.c index d4a92ca8e..e543fa81d 100644 --- a/winpr/libwinpr/input/scancode.c +++ b/winpr/libwinpr/input/scancode.c @@ -567,28 +567,25 @@ DWORD KBD7X[128] = DWORD GetVirtualKeyCodeFromVirtualScanCode(DWORD scancode, DWORD dwKeyboardType) { - DWORD vkcode; + DWORD code_index; - vkcode = VK_NONE; + code_index = scancode & 0xff; + if (code_index > 127) + return VK_NONE; if ((dwKeyboardType != 4) && (dwKeyboardType != 7)) dwKeyboardType = 4; if (dwKeyboardType == 4) { - if (vkcode < 128) - vkcode = (scancode & KBDEXT) ? KBD4X[scancode] : KBD4T[scancode]; + return (scancode & KBDEXT) ? KBD4X[code_index] : KBD4T[code_index]; } else if (dwKeyboardType == 7) { - if (vkcode < 128) - vkcode = (scancode & KBDEXT) ? KBD7X[scancode] : KBD7T[scancode]; + return (scancode & KBDEXT) ? KBD7X[code_index] : KBD7T[code_index]; } - if (!vkcode) - vkcode = VK_NONE; - - return vkcode; + return VK_NONE; } DWORD GetVirtualScanCodeFromVirtualKeyCode(DWORD vkcode, DWORD dwKeyboardType) diff --git a/winpr/libwinpr/interlocked/interlocked.c b/winpr/libwinpr/interlocked/interlocked.c index 9065376d3..044c36684 100644 --- a/winpr/libwinpr/interlocked/interlocked.c +++ b/winpr/libwinpr/interlocked/interlocked.c @@ -236,7 +236,11 @@ LONG InterlockedCompareExchange(LONG volatile *Destination, LONG Exchange, LONG #endif /* _WIN32 */ -#if (_WIN32 && (_WIN32_WINNT < 0x0502)) +#if defined(_WIN64) + +/* InterlockedCompareExchange64 already defined */ + +#elif (_WIN32 && (_WIN32_WINNT < 0x0502)) static volatile HANDLE mutex = NULL; diff --git a/winpr/libwinpr/library/library.c b/winpr/libwinpr/library/library.c index 0706367e8..54c8b223b 100644 --- a/winpr/libwinpr/library/library.c +++ b/winpr/libwinpr/library/library.c @@ -87,7 +87,7 @@ HMODULE LoadLibraryA(LPCSTR lpLibFileName) if (library == NULL) { - printf("LoadLibraryA: %s\n", dlerror()); + fprintf(stderr, "LoadLibraryA: %s\n", dlerror()); return NULL; } @@ -107,7 +107,7 @@ HMODULE LoadLibraryExA(LPCSTR lpLibFileName, HANDLE hFile, DWORD dwFlags) if (library == NULL) { - printf("LoadLibraryA: failed to open %s: %s\n", lpLibFileName, dlerror()); + fprintf(stderr, "LoadLibraryA: failed to open %s: %s\n", lpLibFileName, dlerror()); return NULL; } @@ -127,7 +127,7 @@ FARPROC GetProcAddress(HMODULE hModule, LPCSTR lpProcName) if (proc == NULL) { - printf("GetProcAddress: could not find procedure %s: %s\n", lpProcName, dlerror()); + fprintf(stderr, "GetProcAddress: could not find procedure %s: %s\n", lpProcName, dlerror()); return (FARPROC) NULL; } diff --git a/winpr/libwinpr/path/CMakeLists.txt b/winpr/libwinpr/path/CMakeLists.txt index 549c58861..59eaf6875 100644 --- a/winpr/libwinpr/path/CMakeLists.txt +++ b/winpr/libwinpr/path/CMakeLists.txt @@ -19,7 +19,8 @@ set(MODULE_NAME "winpr-path") set(MODULE_PREFIX "WINPR_PATH") set(${MODULE_PREFIX}_SRCS - path.c) + path.c + shell.c) add_complex_library(MODULE ${MODULE_NAME} TYPE "OBJECT" MONOLITHIC ${MONOLITHIC_BUILD} @@ -30,7 +31,7 @@ set_target_properties(${MODULE_NAME} PROPERTIES VERSION ${WINPR_VERSION_FULL} SO if(MONOLITHIC_BUILD) else() - target_link_libraries(${MODULE_NAME} winpr-crt winpr-heap) + target_link_libraries(${MODULE_NAME} winpr-crt winpr-heap winpr-environment) install(TARGETS ${MODULE_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR}) endif() diff --git a/winpr/libwinpr/path/path.c b/winpr/libwinpr/path/path.c index ee672b4a4..22f8a1365 100644 --- a/winpr/libwinpr/path/path.c +++ b/winpr/libwinpr/path/path.c @@ -719,7 +719,7 @@ HRESULT PathCchConvertStyleA(PSTR pszPath, size_t cchPath, unsigned long dwFlags { size_t index; - if (dwFlags & PATH_STYLE_WINDOWS) + if (dwFlags == PATH_STYLE_WINDOWS) { for (index = 0; index < cchPath; index++) { @@ -727,7 +727,7 @@ HRESULT PathCchConvertStyleA(PSTR pszPath, size_t cchPath, unsigned long dwFlags pszPath[index] = PATH_BACKSLASH_CHR; } } - else if (dwFlags & PATH_STYLE_UNIX) + else if (dwFlags == PATH_STYLE_UNIX) { for (index = 0; index < cchPath; index++) { @@ -735,7 +735,7 @@ HRESULT PathCchConvertStyleA(PSTR pszPath, size_t cchPath, unsigned long dwFlags pszPath[index] = PATH_SLASH_CHR; } } - else if (dwFlags & PATH_STYLE_NATIVE) + else if (dwFlags == PATH_STYLE_NATIVE) { if (PATH_SEPARATOR_CHR == PATH_BACKSLASH_CHR) { @@ -776,7 +776,7 @@ HRESULT PathCchConvertStyleW(PWSTR pszPath, size_t cchPath, unsigned long dwFlag { size_t index; - if (dwFlags & PATH_STYLE_WINDOWS) + if (dwFlags == PATH_STYLE_WINDOWS) { for (index = 0; index < cchPath; index++) { @@ -784,7 +784,7 @@ HRESULT PathCchConvertStyleW(PWSTR pszPath, size_t cchPath, unsigned long dwFlag pszPath[index] = PATH_BACKSLASH_CHR; } } - else if (dwFlags & PATH_STYLE_UNIX) + else if (dwFlags == PATH_STYLE_UNIX) { for (index = 0; index < cchPath; index++) { @@ -792,7 +792,7 @@ HRESULT PathCchConvertStyleW(PWSTR pszPath, size_t cchPath, unsigned long dwFlag pszPath[index] = PATH_SLASH_CHR; } } - else if (dwFlags & PATH_STYLE_NATIVE) + else if (dwFlags == PATH_STYLE_NATIVE) { if (PATH_SEPARATOR_CHR == PATH_BACKSLASH_CHR) { diff --git a/winpr/libwinpr/path/shell.c b/winpr/libwinpr/path/shell.c new file mode 100644 index 000000000..c60baa7ac --- /dev/null +++ b/winpr/libwinpr/path/shell.c @@ -0,0 +1,320 @@ +/** + * WinPR: Windows Portable Runtime + * Path Functions + * + * Copyright 2012 Marc-Andre Moreau <marcandre.moreau@gmail.com> + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <sys/stat.h> + +#include <winpr/crt.h> +#include <winpr/heap.h> +#include <winpr/tchar.h> +#include <winpr/environment.h> + +#include <winpr/path.h> + +/** + * SHGetKnownFolderPath function: + * http://msdn.microsoft.com/en-us/library/windows/desktop/bb762188/ + */ + +/** + * XDG Base Directory Specification: + * http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html + */ + +char* GetEnvAlloc(LPCSTR lpName) +{ + DWORD length; + char* env = NULL; + + length = GetEnvironmentVariableA(lpName, NULL, 0); + + if (length > 0) + { + env = malloc(length + 1); + GetEnvironmentVariableA(lpName, env, length + 1); + env[length] = '\0'; + } + + return env; +} + +char* GetPath_HOME() +{ + char* path = NULL; + +#ifdef _WIN32 + path = GetEnvAlloc("UserProfile"); +#elif defined(ANDROID) + path = malloc(2); + strcpy(path, "/"); +#else + path = GetEnvAlloc("HOME"); +#endif + + return path; +} + +char* GetPath_TEMP() +{ + char* path = NULL; + +#ifdef _WIN32 + path = GetEnvAlloc("TEMP"); +#else + path = GetEnvAlloc("TMPDIR"); + + if (!path) + path = _strdup("/tmp"); +#endif + + return path; +} + +char* GetPath_XDG_DATA_HOME() +{ + char* path = NULL; + char* home = NULL; + + /** + * There is a single base directory relative to which user-specific data files should be written. + * This directory is defined by the environment variable $XDG_DATA_HOME. + * + * $XDG_DATA_HOME defines the base directory relative to which user specific data files should be stored. + * If $XDG_DATA_HOME is either not set or empty, a default equal to $HOME/.local/share should be used. + */ + + path = GetEnvAlloc("XDG_DATA_HOME"); + + if (path) + return path; + + home = GetPath_HOME(); + + path = (char*) malloc(strlen(home) + strlen("/.local/share") + 1); + sprintf(path, "%s%s", home, "/.local/share"); + + free(home); + + return path; +} + +char* GetPath_XDG_CONFIG_HOME() +{ + char* path = NULL; + char* home = NULL; + + /** + * There is a single base directory relative to which user-specific configuration files should be written. + * This directory is defined by the environment variable $XDG_CONFIG_HOME. + * + * $XDG_CONFIG_HOME defines the base directory relative to which user specific configuration files should be stored. + * If $XDG_CONFIG_HOME is either not set or empty, a default equal to $HOME/.config should be used. + */ + + path = GetEnvAlloc("XDG_CONFIG_HOME"); + + if (path) + return path; + + home = GetPath_HOME(); + + path = (char*) malloc(strlen(home) + strlen("/.config") + 1); + sprintf(path, "%s%s", home, "/.config"); + + free(home); + + return path; +} + +char* GetPath_XDG_CACHE_HOME() +{ + char* path = NULL; + char* home = NULL; + + /** + * There is a single base directory relative to which user-specific non-essential (cached) data should be written. + * This directory is defined by the environment variable $XDG_CACHE_HOME. + * + * $XDG_CACHE_HOME defines the base directory relative to which user specific non-essential data files should be stored. + * If $XDG_CACHE_HOME is either not set or empty, a default equal to $HOME/.cache should be used. + */ + + path = GetEnvAlloc("XDG_CACHE_HOME"); + + if (path) + return path; + + home = GetPath_HOME(); + + path = (char*) malloc(strlen(home) + strlen("/.cache") + 1); + sprintf(path, "%s%s", home, "/.cache"); + + free(home); + + return path; +} + +char* GetPath_XDG_RUNTIME_DIR() +{ + char* path = NULL; + + /** + * There is a single base directory relative to which user-specific runtime files and other file objects should be placed. + * This directory is defined by the environment variable $XDG_RUNTIME_DIR. + * + * $XDG_RUNTIME_DIR defines the base directory relative to which user-specific non-essential runtime files and other + * file objects (such as sockets, named pipes, ...) should be stored. The directory MUST be owned by the user, + * and he MUST be the only one having read and write access to it. Its Unix access mode MUST be 0700. + * + * The lifetime of the directory MUST be bound to the user being logged in. It MUST be created when the user first + * logs in and if the user fully logs out the directory MUST be removed. If the user logs in more than once he should + * get pointed to the same directory, and it is mandatory that the directory continues to exist from his first login + * to his last logout on the system, and not removed in between. Files in the directory MUST not survive reboot or a + * full logout/login cycle. + * + * The directory MUST be on a local file system and not shared with any other system. The directory MUST by fully-featured + * by the standards of the operating system. More specifically, on Unix-like operating systems AF_UNIX sockets, + * symbolic links, hard links, proper permissions, file locking, sparse files, memory mapping, file change notifications, + * a reliable hard link count must be supported, and no restrictions on the file name character set should be imposed. + * Files in this directory MAY be subjected to periodic clean-up. To ensure that your files are not removed, they should + * have their access time timestamp modified at least once every 6 hours of monotonic time or the 'sticky' bit should be + * set on the file. + * + * If $XDG_RUNTIME_DIR is not set applications should fall back to a replacement directory with similar capabilities and + * print a warning message. Applications should use this directory for communication and synchronization purposes and + * should not place larger files in it, since it might reside in runtime memory and cannot necessarily be swapped out to disk. + */ + + path = GetEnvAlloc("XDG_RUNTIME_DIR"); + + if (path) + return path; + + path = GetPath_TEMP(); + + return path; +} + +char* GetKnownPath(int id) +{ + char* path = NULL; + + switch (id) + { + case KNOWN_PATH_HOME: + path = GetPath_HOME(); + break; + + case KNOWN_PATH_TEMP: + path = GetPath_TEMP(); + break; + + case KNOWN_PATH_XDG_DATA_HOME: + path = GetPath_XDG_DATA_HOME(); + break; + + case KNOWN_PATH_XDG_CONFIG_HOME: + path = GetPath_XDG_CONFIG_HOME(); + break; + + case KNOWN_PATH_XDG_CACHE_HOME: + path = GetPath_XDG_CACHE_HOME(); + break; + + case KNOWN_PATH_XDG_RUNTIME_DIR: + path = GetPath_XDG_RUNTIME_DIR(); + break; + + default: + path = NULL; + break; + } + + return path; +} + +char* GetKnownSubPath(int id, char* path) +{ + char* subPath; + char* knownPath; + + knownPath = GetKnownPath(id); + subPath = GetCombinedPath(knownPath, path); + + free(knownPath); + + return subPath; +} + +char* GetCombinedPath(char* basePath, char* subPath) +{ + int length; + HRESULT status; + char* path = NULL; + int basePathLength; + int subPathLength; + + basePathLength = strlen(basePath); + subPathLength = strlen(subPath); + + length = basePathLength + subPathLength + 1; + path = (char*) malloc(length + 1); + + CopyMemory(path, basePath, basePathLength); + path[basePathLength] = '\0'; + + PathCchConvertStyleA(path, basePathLength, PATH_STYLE_NATIVE); + + if (!subPath) + return path; + + subPath = _strdup(subPath); + PathCchConvertStyleA(subPath, subPathLength, PATH_STYLE_NATIVE); + + status = NativePathCchAppendA(path, length + 1, subPath); + + free(subPath); + + return path; +} + +//#ifndef _WIN32 + +BOOL PathFileExistsA(LPCSTR pszPath) +{ + struct stat stat_info; + + if (stat(pszPath, &stat_info) != 0) + return FALSE; + + return TRUE; +} + +BOOL PathFileExistsW(LPCWSTR pszPath) +{ + return FALSE; +} + +//#endif diff --git a/winpr/libwinpr/path/test/CMakeLists.txt b/winpr/libwinpr/path/test/CMakeLists.txt index 25fb39485..6f9120af3 100644 --- a/winpr/libwinpr/path/test/CMakeLists.txt +++ b/winpr/libwinpr/path/test/CMakeLists.txt @@ -26,7 +26,8 @@ set(${MODULE_PREFIX}_TESTS TestPathCchSkipRoot.c TestPathCchStripToRoot.c TestPathCchStripPrefix.c - TestPathCchRemoveFileSpec.c) + TestPathCchRemoveFileSpec.c + TestPathShell.c) create_test_sourcelist(${MODULE_PREFIX}_SRCS ${${MODULE_PREFIX}_DRIVER} diff --git a/winpr/libwinpr/path/test/TestPathShell.c b/winpr/libwinpr/path/test/TestPathShell.c new file mode 100644 index 000000000..9887a8adf --- /dev/null +++ b/winpr/libwinpr/path/test/TestPathShell.c @@ -0,0 +1,35 @@ + +#include <stdio.h> +#include <winpr/crt.h> +#include <winpr/path.h> +#include <winpr/tchar.h> +#include <winpr/winpr.h> + +int TestPathShell(int argc, char* argv[]) +{ + char* path; + + path = GetKnownPath(KNOWN_PATH_HOME); + printf("KNOWN_PATH_HOME: %s\n", path); + + path = GetKnownPath(KNOWN_PATH_TEMP); + printf("KNOWN_PATH_TEMP: %s\n", path); + + path = GetKnownPath(KNOWN_PATH_XDG_DATA_HOME); + printf("KNOWN_PATH_DATA: %s\n", path); + + path = GetKnownPath(KNOWN_PATH_XDG_CONFIG_HOME); + printf("KNOWN_PATH_CONFIG: %s\n", path); + + path = GetKnownPath(KNOWN_PATH_XDG_CACHE_HOME); + printf("KNOWN_PATH_CACHE: %s\n", path); + + path = GetKnownPath(KNOWN_PATH_XDG_RUNTIME_DIR); + printf("KNOWN_PATH_RUNTIME: %s\n", path); + + path = GetKnownSubPath(KNOWN_PATH_XDG_CONFIG_HOME, "freerdp"); + printf("KNOWN_PATH_CONFIG SubPath: %s\n", path); + + return 0; +} + diff --git a/winpr/libwinpr/registry/registry_reg.c b/winpr/libwinpr/registry/registry_reg.c index 6082b2a25..93cd26031 100644 --- a/winpr/libwinpr/registry/registry_reg.c +++ b/winpr/libwinpr/registry/registry_reg.c @@ -158,7 +158,7 @@ RegVal* reg_load_value(Reg* reg, RegKey* key) } else { - printf("unimplemented format: %s\n", REG_DATA_TYPE_STRINGS[value->type]); + fprintf(stderr, "unimplemented format: %s\n", REG_DATA_TYPE_STRINGS[value->type]); } if (!key->values) @@ -312,7 +312,7 @@ void reg_unload_value(Reg* reg, RegVal* value) } else { - printf("unimplemented format: %s\n", REG_DATA_TYPE_STRINGS[value->type]); + fprintf(stderr, "unimplemented format: %s\n", REG_DATA_TYPE_STRINGS[value->type]); } free(value); @@ -406,19 +406,19 @@ void reg_close(Reg* reg) void reg_print_value(Reg* reg, RegVal* value) { - printf("\"%s\"=", value->name); + fprintf(stderr, "\"%s\"=", value->name); if (value->type == REG_DWORD) { - printf("dword:%08lX\n", value->data.dword); + fprintf(stderr, "dword:%08lX\n", value->data.dword); } else if (value->type == REG_SZ) { - printf("%s\"\n", value->data.string); + fprintf(stderr, "%s\"\n", value->data.string); } else { - printf("unimplemented format: %s\n", REG_DATA_TYPE_STRINGS[value->type]); + fprintf(stderr, "unimplemented format: %s\n", REG_DATA_TYPE_STRINGS[value->type]); } } @@ -428,7 +428,7 @@ void reg_print_key(Reg* reg, RegKey* key) pValue = key->values; - printf("[%s]\n", key->name); + fprintf(stderr, "[%s]\n", key->name); while (pValue != NULL) { diff --git a/winpr/libwinpr/rpc/ndr.c b/winpr/libwinpr/rpc/ndr.c index f10439731..0cec370e2 100644 --- a/winpr/libwinpr/rpc/ndr.c +++ b/winpr/libwinpr/rpc/ndr.c @@ -47,29 +47,29 @@ void NdrPrintParamAttributes(PARAM_ATTRIBUTES attributes) { if (attributes.ServerAllocSize) - printf("ServerAllocSize, "); + fprintf(stderr, "ServerAllocSize, "); if (attributes.SaveForAsyncFinish) - printf("SaveForAsyncFinish, "); + fprintf(stderr, "SaveForAsyncFinish, "); if (attributes.IsDontCallFreeInst) - printf("IsDontCallFreeInst, "); + fprintf(stderr, "IsDontCallFreeInst, "); if (attributes.IsSimpleRef) - printf("IsSimpleRef, "); + fprintf(stderr, "IsSimpleRef, "); if (attributes.IsByValue) - printf("IsByValue, "); + fprintf(stderr, "IsByValue, "); if (attributes.IsBasetype) - printf("IsBaseType, "); + fprintf(stderr, "IsBaseType, "); if (attributes.IsReturn) - printf("IsReturn, "); + fprintf(stderr, "IsReturn, "); if (attributes.IsOut) - printf("IsOut, "); + fprintf(stderr, "IsOut, "); if (attributes.IsIn) - printf("IsIn, "); + fprintf(stderr, "IsIn, "); if (attributes.IsPipe) - printf("IsPipe, "); + fprintf(stderr, "IsPipe, "); if (attributes.MustFree) - printf("MustFree, "); + fprintf(stderr, "MustFree, "); if (attributes.MustSize) - printf("MustSize, "); + fprintf(stderr, "MustSize, "); } void NdrProcessParam(PMIDL_STUB_MESSAGE pStubMsg, NDR_PHASE phase, unsigned char* pMemory, NDR_PARAM* param) @@ -139,7 +139,7 @@ void NdrProcessParams(PMIDL_STUB_MESSAGE pStubMsg, PFORMAT_STRING pFormat, NDR_P params = (NDR_PARAM*) pFormat; - printf("Params = \n{\n"); + fprintf(stderr, "Params = \n{\n"); for (i = 0; i < numberParams; i++) { @@ -156,11 +156,11 @@ void NdrProcessParams(PMIDL_STUB_MESSAGE pStubMsg, PFORMAT_STRING pFormat, NDR_P } #endif - printf("\t#%d\t", i); + fprintf(stderr, "\t#%d\t", i); type = (params[i].Attributes.IsBasetype) ? params[i].Type.FormatChar : *fmt; - printf(" type %s (0x%02X) ", FC_TYPE_STRINGS[type], type); + fprintf(stderr, " type %s (0x%02X) ", FC_TYPE_STRINGS[type], type); NdrPrintParamAttributes(params[i].Attributes); @@ -169,10 +169,10 @@ void NdrProcessParams(PMIDL_STUB_MESSAGE pStubMsg, PFORMAT_STRING pFormat, NDR_P NdrProcessParam(pStubMsg, phase, arg, ¶ms[i]); } - printf("\n"); + fprintf(stderr, "\n"); } - printf("}\n"); + fprintf(stderr, "}\n"); } void NdrClientInitializeNew(PRPC_MESSAGE pRpcMessage, PMIDL_STUB_MESSAGE pStubMsg, @@ -198,33 +198,33 @@ void NdrClientInitializeNew(PRPC_MESSAGE pRpcMessage, PMIDL_STUB_MESSAGE pStubMs void NdrPrintOptFlags(INTERPRETER_OPT_FLAGS optFlags) { if (optFlags.ClientMustSize) - printf("ClientMustSize, "); + fprintf(stderr, "ClientMustSize, "); if (optFlags.ServerMustSize) - printf("ServerMustSize, "); + fprintf(stderr, "ServerMustSize, "); if (optFlags.HasAsyncUuid) - printf("HasAsyncUiid, "); + fprintf(stderr, "HasAsyncUiid, "); if (optFlags.HasAsyncHandle) - printf("HasAsyncHandle, "); + fprintf(stderr, "HasAsyncHandle, "); if (optFlags.HasReturn) - printf("HasReturn, "); + fprintf(stderr, "HasReturn, "); if (optFlags.HasPipes) - printf("HasPipes, "); + fprintf(stderr, "HasPipes, "); if (optFlags.HasExtensions) - printf("HasExtensions, "); + fprintf(stderr, "HasExtensions, "); } void NdrPrintExtFlags(INTERPRETER_OPT_FLAGS2 extFlags) { if (extFlags.HasNewCorrDesc) - printf("HasNewCorrDesc, "); + fprintf(stderr, "HasNewCorrDesc, "); if (extFlags.ClientCorrCheck) - printf("ClientCorrCheck, "); + fprintf(stderr, "ClientCorrCheck, "); if (extFlags.ServerCorrCheck) - printf("ServerCorrCheck, "); + fprintf(stderr, "ServerCorrCheck, "); if (extFlags.HasNotify) - printf("HasNotify, "); + fprintf(stderr, "HasNotify, "); if (extFlags.HasNotify2) - printf("HasNotify2, "); + fprintf(stderr, "HasNotify2, "); } CLIENT_CALL_RETURN NdrClientCall(PMIDL_STUB_DESC pStubDescriptor, PFORMAT_STRING pFormat, void** stackTop, void** fpuStack) @@ -257,21 +257,21 @@ CLIENT_CALL_RETURN NdrClientCall(PMIDL_STUB_DESC pStubDescriptor, PFORMAT_STRING /* Procedure Header Descriptor: http://msdn.microsoft.com/en-us/library/windows/desktop/aa374387/ */ /* Handles: http://msdn.microsoft.com/en-us/library/windows/desktop/aa373932/ */ - printf("Oi Header: HandleType: 0x%02X OiFlags: 0x%02X ProcNum: %d StackSize: 0x%04X\n", + fprintf(stderr, "Oi Header: HandleType: 0x%02X OiFlags: 0x%02X ProcNum: %d StackSize: 0x%04X\n", handleType, *((unsigned char*) &flags), (unsigned short) procNum, (unsigned short) stackSize); if (handleType > 0) { /* implicit handle */ - printf("Implicit Handle\n"); + fprintf(stderr, "Implicit Handle\n"); oi2ProcHeader = (NDR_OI2_PROC_HEADER*) &pFormat[0]; pFormat += sizeof(NDR_OI2_PROC_HEADER); } else { /* explicit handle */ - printf("Explicit Handle\n"); + fprintf(stderr, "Explicit Handle\n"); oi2ProcHeader = (NDR_OI2_PROC_HEADER*) &pFormat[6]; pFormat += sizeof(NDR_OI2_PROC_HEADER) + 6; } @@ -279,15 +279,15 @@ CLIENT_CALL_RETURN NdrClientCall(PMIDL_STUB_DESC pStubDescriptor, PFORMAT_STRING optFlags = oi2ProcHeader->Oi2Flags; numberParams = oi2ProcHeader->NumberParams; - printf("Oi2 Header: Oi2Flags: 0x%02X, NumberParams: %d ClientBufferSize: %d ServerBufferSize: %d\n", + fprintf(stderr, "Oi2 Header: Oi2Flags: 0x%02X, NumberParams: %d ClientBufferSize: %d ServerBufferSize: %d\n", *((unsigned char*) &optFlags), (unsigned char) numberParams, oi2ProcHeader->ClientBufferSize, oi2ProcHeader->ServerBufferSize); - printf("Oi2Flags: "); + fprintf(stderr, "Oi2Flags: "); NdrPrintOptFlags(optFlags); - printf("\n"); + fprintf(stderr, "\n"); NdrClientInitializeNew(&rpcMsg, &stubMsg, pStubDescriptor, procNum); @@ -298,7 +298,7 @@ CLIENT_CALL_RETURN NdrClientCall(PMIDL_STUB_DESC pStubDescriptor, PFORMAT_STRING pFormat += extensions->Size; extFlags = extensions->Flags2; - printf("Extensions: Size: %d, flags2: 0x%02X\n", + fprintf(stderr, "Extensions: Size: %d, flags2: 0x%02X\n", extensions->Size, *((unsigned char*) &extensions->Flags2)); #ifdef __x86_64__ @@ -324,13 +324,13 @@ CLIENT_CALL_RETURN NdrClientCall(PMIDL_STUB_DESC pStubDescriptor, PFORMAT_STRING stubMsg.StackTop = (unsigned char*) stackTop; - printf("ExtFlags: "); + fprintf(stderr, "ExtFlags: "); NdrPrintExtFlags(extFlags); - printf("\n"); + fprintf(stderr, "\n"); NdrProcessParams(&stubMsg, pFormat, NDR_PHASE_SIZE, fpuStack, numberParams); - printf("stubMsg BufferLength: %d\n", (int) stubMsg.BufferLength); + fprintf(stderr, "stubMsg BufferLength: %d\n", (int) stubMsg.BufferLength); return client_call_return; } diff --git a/winpr/libwinpr/rpc/ndr_array.c b/winpr/libwinpr/rpc/ndr_array.c index 54b1ecc02..32503b9d7 100644 --- a/winpr/libwinpr/rpc/ndr_array.c +++ b/winpr/libwinpr/rpc/ndr_array.c @@ -52,11 +52,11 @@ void NdrConformantArrayBufferSize(PMIDL_STUB_MESSAGE pStubMsg, unsigned char* pM if (type != FC_CARRAY) { - printf("error: expected FC_CARRAY, got 0x%02X\n", type); + fprintf(stderr, "error: expected FC_CARRAY, got 0x%02X\n", type); return; } - printf("warning: NdrConformantArrayBufferSize unimplemented\n"); + fprintf(stderr, "warning: NdrConformantArrayBufferSize unimplemented\n"); } void NdrConformantVaryingArrayBufferSize(PMIDL_STUB_MESSAGE pStubMsg, unsigned char* pMemory, PFORMAT_STRING pFormat) @@ -72,7 +72,7 @@ void NdrConformantVaryingArrayBufferSize(PMIDL_STUB_MESSAGE pStubMsg, unsigned c * FC_END */ - printf("warning: NdrConformantVaryingArrayBufferSize unimplemented\n"); + fprintf(stderr, "warning: NdrConformantVaryingArrayBufferSize unimplemented\n"); } void NdrFixedArrayBufferSize(PMIDL_STUB_MESSAGE pStubMsg, unsigned char* pMemory, PFORMAT_STRING pFormat) @@ -95,7 +95,7 @@ void NdrFixedArrayBufferSize(PMIDL_STUB_MESSAGE pStubMsg, unsigned char* pMemory * FC_END */ - printf("warning: NdrFixedArrayBufferSize unimplemented\n"); + fprintf(stderr, "warning: NdrFixedArrayBufferSize unimplemented\n"); } void NdrVaryingArrayBufferSize(PMIDL_STUB_MESSAGE pStubMsg, unsigned char* pMemory, PFORMAT_STRING pFormat) @@ -124,7 +124,7 @@ void NdrVaryingArrayBufferSize(PMIDL_STUB_MESSAGE pStubMsg, unsigned char* pMemo * FC_END */ - printf("warning: NdrVaryingArrayBufferSize unimplemented\n"); + fprintf(stderr, "warning: NdrVaryingArrayBufferSize unimplemented\n"); } void NdrComplexArrayBufferSize(PMIDL_STUB_MESSAGE pStubMsg, unsigned char* pMemory, PFORMAT_STRING pFormat) @@ -139,7 +139,7 @@ void NdrComplexArrayBufferSize(PMIDL_STUB_MESSAGE pStubMsg, unsigned char* pMemo * FC_END */ - printf("warning: NdrComplexArrayBufferSize unimplemented\n"); + fprintf(stderr, "warning: NdrComplexArrayBufferSize unimplemented\n"); } #endif diff --git a/winpr/libwinpr/rpc/ndr_context.c b/winpr/libwinpr/rpc/ndr_context.c index 88120bdb2..7cb2555d5 100644 --- a/winpr/libwinpr/rpc/ndr_context.c +++ b/winpr/libwinpr/rpc/ndr_context.c @@ -43,7 +43,7 @@ void NdrContextHandleBufferSize(PMIDL_STUB_MESSAGE pStubMsg, unsigned char* pMem * offset<2> */ - printf("warning: NdrContextHandleBufferSize FC_BIND_PRIMITIVE unimplemented\n"); + fprintf(stderr, "warning: NdrContextHandleBufferSize FC_BIND_PRIMITIVE unimplemented\n"); } else if (type == FC_BIND_GENERIC) { @@ -55,7 +55,7 @@ void NdrContextHandleBufferSize(PMIDL_STUB_MESSAGE pStubMsg, unsigned char* pMem * FC_PAD */ - printf("warning: NdrContextHandleBufferSize FC_BIND_GENERIC unimplemented\n"); + fprintf(stderr, "warning: NdrContextHandleBufferSize FC_BIND_GENERIC unimplemented\n"); } else if (type == FC_BIND_CONTEXT) { diff --git a/winpr/libwinpr/rpc/ndr_correlation.c b/winpr/libwinpr/rpc/ndr_correlation.c index e048b7bcf..1afb31843 100644 --- a/winpr/libwinpr/rpc/ndr_correlation.c +++ b/winpr/libwinpr/rpc/ndr_correlation.c @@ -105,7 +105,7 @@ PFORMAT_STRING NdrpComputeCount(PMIDL_STUB_MESSAGE pStubMsg, unsigned char* pMem case FC_CALLBACK: { - printf("warning: NdrpComputeConformance FC_CALLBACK unimplemented\n"); + fprintf(stderr, "warning: NdrpComputeConformance FC_CALLBACK unimplemented\n"); } break; } diff --git a/winpr/libwinpr/rpc/ndr_pointer.c b/winpr/libwinpr/rpc/ndr_pointer.c index 691691d2d..9be782254 100644 --- a/winpr/libwinpr/rpc/ndr_pointer.c +++ b/winpr/libwinpr/rpc/ndr_pointer.c @@ -102,7 +102,7 @@ PFORMAT_STRING NdrpSkipPointerLayout(PFORMAT_STRING pFormat) } else { - printf("error: NdrpSkipPointerLayout unexpected 0x%02X\n", *pFormat); + fprintf(stderr, "error: NdrpSkipPointerLayout unexpected 0x%02X\n", *pFormat); break; } } @@ -155,7 +155,7 @@ void NdrpPointerBufferSize(unsigned char* pMemory, PFORMAT_STRING pFormat, PMIDL break; case FC_FP: /* Full Pointer */ - printf("warning: FC_FP unimplemented\n"); + fprintf(stderr, "warning: FC_FP unimplemented\n"); break; } @@ -325,7 +325,7 @@ void NdrPointerBufferSize(PMIDL_STUB_MESSAGE pStubMsg, unsigned char* pMemory, P void NdrByteCountPointerBufferSize(PMIDL_STUB_MESSAGE pStubMsg, unsigned char* pMemory, PFORMAT_STRING pFormat) { - printf("warning: NdrByteCountPointerBufferSize unimplemented\n"); + fprintf(stderr, "warning: NdrByteCountPointerBufferSize unimplemented\n"); } #endif diff --git a/winpr/libwinpr/rpc/ndr_string.c b/winpr/libwinpr/rpc/ndr_string.c index 40312b06a..3cb0e1129 100644 --- a/winpr/libwinpr/rpc/ndr_string.c +++ b/winpr/libwinpr/rpc/ndr_string.c @@ -32,12 +32,12 @@ void NdrConformantStringBufferSize(PMIDL_STUB_MESSAGE pStubMsg, unsigned char* pMemory, PFORMAT_STRING pFormat) { - printf("warning: NdrConformantStringBufferSize unimplemented\n"); + fprintf(stderr, "warning: NdrConformantStringBufferSize unimplemented\n"); } void NdrNonConformantStringBufferSize(PMIDL_STUB_MESSAGE pStubMsg, unsigned char* pMemory, PFORMAT_STRING pFormat) { - printf("warning: NdrNonConformantStringBufferSize unimplemented\n"); + fprintf(stderr, "warning: NdrNonConformantStringBufferSize unimplemented\n"); } #endif diff --git a/winpr/libwinpr/rpc/ndr_structure.c b/winpr/libwinpr/rpc/ndr_structure.c index fa6434677..06ad9ee1a 100644 --- a/winpr/libwinpr/rpc/ndr_structure.c +++ b/winpr/libwinpr/rpc/ndr_structure.c @@ -69,7 +69,7 @@ void NdrSimpleStructBufferSize(PMIDL_STUB_MESSAGE pStubMsg, unsigned char* pMemo if (*pFormat == FC_PSTRUCT) NdrpEmbeddedPointerBufferSize(pStubMsg, pMemory, pFormat); - printf("warning: NdrSimpleStructBufferSize unimplemented\n"); + fprintf(stderr, "warning: NdrSimpleStructBufferSize unimplemented\n"); } void NdrConformantStructBufferSize(PMIDL_STUB_MESSAGE pStubMsg, unsigned char* pMemory, PFORMAT_STRING pFormat) @@ -90,7 +90,7 @@ void NdrConformantStructBufferSize(PMIDL_STUB_MESSAGE pStubMsg, unsigned char* p * member_layout<> FC_END */ - printf("warning: NdrConformantStructBufferSize unimplemented\n"); + fprintf(stderr, "warning: NdrConformantStructBufferSize unimplemented\n"); } void NdrConformantVaryingStructBufferSize(PMIDL_STUB_MESSAGE pStubMsg, unsigned char* pMemory, PFORMAT_STRING pFormat) @@ -104,7 +104,7 @@ void NdrConformantVaryingStructBufferSize(PMIDL_STUB_MESSAGE pStubMsg, unsigned * FC_END */ - printf("warning: NdrConformantVaryingStructBufferSize unimplemented\n"); + fprintf(stderr, "warning: NdrConformantVaryingStructBufferSize unimplemented\n"); } ULONG NdrComplexStructMemberSize(PMIDL_STUB_MESSAGE pStubMsg, PFORMAT_STRING pFormat) @@ -195,11 +195,11 @@ ULONG NdrComplexStructMemberSize(PMIDL_STUB_MESSAGE pStubMsg, PFORMAT_STRING pFo break; case FC_EMBEDDED_COMPLEX: - printf("warning: NdrComplexStructMemberSize FC_EMBEDDED_COMPLEX unimplemented\n"); + fprintf(stderr, "warning: NdrComplexStructMemberSize FC_EMBEDDED_COMPLEX unimplemented\n"); break; default: - printf("warning: NdrComplexStructMemberSize 0x%02X unimplemented\n", *pFormat); + fprintf(stderr, "warning: NdrComplexStructMemberSize 0x%02X unimplemented\n", *pFormat); break; } @@ -241,7 +241,7 @@ void NdrComplexStructBufferSize(PMIDL_STUB_MESSAGE pStubMsg, unsigned char* pMem if (type != FC_BOGUS_STRUCT) { - printf("error: expected FC_BOGUS_STRUCT, got 0x%02X\n", type); + fprintf(stderr, "error: expected FC_BOGUS_STRUCT, got 0x%02X\n", type); return; } @@ -287,7 +287,7 @@ void NdrComplexStructBufferSize(PMIDL_STUB_MESSAGE pStubMsg, unsigned char* pMem array_type = conformant_array_description[0]; size = NdrComplexStructMemberSize(pStubMsg, pFormat); - printf("warning: NdrComplexStructBufferSize array_type: 0x%02X unimplemented\n", array_type); + fprintf(stderr, "warning: NdrComplexStructBufferSize array_type: 0x%02X unimplemented\n", array_type); NdrpComputeConformance(pStubMsg, pMemory + size, conformant_array_description); NdrpComputeVariance(pStubMsg, pMemory + size, conformant_array_description); @@ -307,7 +307,7 @@ void NdrComplexStructBufferSize(PMIDL_STUB_MESSAGE pStubMsg, unsigned char* pMem pStubMsg->ActualCount = ActualCount; pStubMsg->Offset = Offset; - printf("warning: NdrComplexStructBufferSize array_type: 0x%02X unimplemented\n", array_type); + fprintf(stderr, "warning: NdrComplexStructBufferSize array_type: 0x%02X unimplemented\n", array_type); } pStubMsg->Memory = pMemoryCopy; diff --git a/winpr/libwinpr/rpc/ndr_union.c b/winpr/libwinpr/rpc/ndr_union.c index fbe5be922..e18851529 100644 --- a/winpr/libwinpr/rpc/ndr_union.c +++ b/winpr/libwinpr/rpc/ndr_union.c @@ -32,12 +32,12 @@ void NdrEncapsulatedUnionBufferSize(PMIDL_STUB_MESSAGE pStubMsg, unsigned char* pMemory, PFORMAT_STRING pFormat) { - printf("warning: NdrEncapsulatedUnionBufferSize unimplemented\n"); + fprintf(stderr, "warning: NdrEncapsulatedUnionBufferSize unimplemented\n"); } void NdrNonEncapsulatedUnionBufferSize(PMIDL_STUB_MESSAGE pStubMsg, unsigned char* pMemory, PFORMAT_STRING pFormat) { - printf("warning: NdrNonEncapsulatedUnionBufferSize unimplemented\n"); + fprintf(stderr, "warning: NdrNonEncapsulatedUnionBufferSize unimplemented\n"); } #endif diff --git a/winpr/libwinpr/rpc/rpc.c b/winpr/libwinpr/rpc/rpc.c index 07dcd3ed8..3f6685925 100644 --- a/winpr/libwinpr/rpc/rpc.c +++ b/winpr/libwinpr/rpc/rpc.c @@ -522,7 +522,7 @@ RPC_STATUS RpcBindingServerFromClient(RPC_BINDING_HANDLE ClientBinding, RPC_BIND DECLSPEC_NORETURN void RpcRaiseException(RPC_STATUS exception) { - printf("RpcRaiseException: 0x%08luX\n", exception); + fprintf(stderr, "RpcRaiseException: 0x%08luX\n", exception); } RPC_STATUS RpcTestCancel() diff --git a/winpr/libwinpr/sspi/NTLM/ntlm.c b/winpr/libwinpr/sspi/NTLM/ntlm.c index adc0d0d79..d2137a865 100644 --- a/winpr/libwinpr/sspi/NTLM/ntlm.c +++ b/winpr/libwinpr/sspi/NTLM/ntlm.c @@ -670,13 +670,13 @@ SECURITY_STATUS SEC_ENTRY ntlm_EncryptMessage(PCtxtHandle phContext, ULONG fQOP, CopyMemory(data_buffer->pvBuffer, data, length); #ifdef WITH_DEBUG_NTLM - printf("Data Buffer (length = %d)\n", length); + fprintf(stderr, "Data Buffer (length = %d)\n", length); winpr_HexDump(data, length); - printf("\n"); + fprintf(stderr, "\n"); - printf("Encrypted Data Buffer (length = %d)\n", (int) data_buffer->cbBuffer); + fprintf(stderr, "Encrypted Data Buffer (length = %d)\n", (int) data_buffer->cbBuffer); winpr_HexDump(data_buffer->pvBuffer, data_buffer->cbBuffer); - printf("\n"); + fprintf(stderr, "\n"); #endif free(data); @@ -693,9 +693,9 @@ SECURITY_STATUS SEC_ENTRY ntlm_EncryptMessage(PCtxtHandle phContext, ULONG fQOP, context->SendSeqNum++; #ifdef WITH_DEBUG_NTLM - printf("Signature (length = %d)\n", (int) signature_buffer->cbBuffer); + fprintf(stderr, "Signature (length = %d)\n", (int) signature_buffer->cbBuffer); winpr_HexDump(signature_buffer->pvBuffer, signature_buffer->cbBuffer); - printf("\n"); + fprintf(stderr, "\n"); #endif return SEC_E_OK; @@ -754,13 +754,13 @@ SECURITY_STATUS SEC_ENTRY ntlm_DecryptMessage(PCtxtHandle phContext, PSecBufferD HMAC_CTX_cleanup(&hmac); #ifdef WITH_DEBUG_NTLM - printf("Encrypted Data Buffer (length = %d)\n", length); + fprintf(stderr, "Encrypted Data Buffer (length = %d)\n", length); winpr_HexDump(data, length); - printf("\n"); + fprintf(stderr, "\n"); - printf("Data Buffer (length = %d)\n", (int) data_buffer->cbBuffer); + fprintf(stderr, "Data Buffer (length = %d)\n", (int) data_buffer->cbBuffer); winpr_HexDump(data_buffer->pvBuffer, data_buffer->cbBuffer); - printf("\n"); + fprintf(stderr, "\n"); #endif free(data); @@ -777,11 +777,11 @@ SECURITY_STATUS SEC_ENTRY ntlm_DecryptMessage(PCtxtHandle phContext, PSecBufferD if (memcmp(signature_buffer->pvBuffer, expected_signature, 16) != 0) { /* signature verification failed! */ - printf("signature verification failed, something nasty is going on!\n"); + fprintf(stderr, "signature verification failed, something nasty is going on!\n"); - printf("Expected Signature:\n"); + fprintf(stderr, "Expected Signature:\n"); winpr_HexDump(expected_signature, 16); - printf("Actual Signature:\n"); + fprintf(stderr, "Actual Signature:\n"); winpr_HexDump(signature_buffer->pvBuffer, 16); return SEC_E_MESSAGE_ALTERED; diff --git a/winpr/libwinpr/sspi/NTLM/ntlm_av_pairs.c b/winpr/libwinpr/sspi/NTLM/ntlm_av_pairs.c index 755cf048e..810bc2223 100644 --- a/winpr/libwinpr/sspi/NTLM/ntlm_av_pairs.c +++ b/winpr/libwinpr/sspi/NTLM/ntlm_av_pairs.c @@ -80,11 +80,11 @@ void ntlm_print_av_pair_list(NTLM_AV_PAIR* pAvPairList) if (!pAvPair) return; - printf("AV_PAIRs =\n{\n"); + fprintf(stderr, "AV_PAIRs =\n{\n"); while (pAvPair->AvId != MsvAvEOL) { - printf("\t%s AvId: %d AvLen: %d\n", + fprintf(stderr, "\t%s AvId: %d AvLen: %d\n", AV_PAIR_STRINGS[pAvPair->AvId], pAvPair->AvId, pAvPair->AvLen); @@ -93,7 +93,7 @@ void ntlm_print_av_pair_list(NTLM_AV_PAIR* pAvPairList) pAvPair = ntlm_av_pair_get_next_pointer(pAvPair); } - printf("}\n"); + fprintf(stderr, "}\n"); } ULONG ntlm_av_pair_list_size(ULONG AvPairsCount, ULONG AvPairsValueLength) diff --git a/winpr/libwinpr/sspi/NTLM/ntlm_compute.c b/winpr/libwinpr/sspi/NTLM/ntlm_compute.c index 95cff51b7..050d1fabf 100644 --- a/winpr/libwinpr/sspi/NTLM/ntlm_compute.c +++ b/winpr/libwinpr/sspi/NTLM/ntlm_compute.c @@ -98,13 +98,13 @@ void ntlm_write_version_info(wStream* s, NTLM_VERSION_INFO* versionInfo) void ntlm_print_version_info(NTLM_VERSION_INFO* versionInfo) { - printf("VERSION =\n{\n"); - printf("\tProductMajorVersion: %d\n", versionInfo->ProductMajorVersion); - printf("\tProductMinorVersion: %d\n", versionInfo->ProductMinorVersion); - printf("\tProductBuild: %d\n", versionInfo->ProductBuild); - printf("\tReserved: 0x%02X%02X%02X\n", versionInfo->Reserved[0], + fprintf(stderr, "VERSION =\n{\n"); + fprintf(stderr, "\tProductMajorVersion: %d\n", versionInfo->ProductMajorVersion); + fprintf(stderr, "\tProductMinorVersion: %d\n", versionInfo->ProductMinorVersion); + fprintf(stderr, "\tProductBuild: %d\n", versionInfo->ProductBuild); + fprintf(stderr, "\tReserved: 0x%02X%02X%02X\n", versionInfo->Reserved[0], versionInfo->Reserved[1], versionInfo->Reserved[2]); - printf("\tNTLMRevisionCurrent: 0x%02X\n", versionInfo->NTLMRevisionCurrent); + fprintf(stderr, "\tNTLMRevisionCurrent: 0x%02X\n", versionInfo->NTLMRevisionCurrent); } void ntlm_read_ntlm_v2_client_challenge(wStream* s, NTLMv2_CLIENT_CHALLENGE* challenge) @@ -240,7 +240,7 @@ void ntlm_fetch_ntlm_v2_hash(NTLM_CONTEXT* context, char* hash) if (entry != NULL) { #ifdef WITH_DEBUG_NTLM - printf("NTLM Hash:\n"); + fprintf(stderr, "NTLM Hash:\n"); winpr_HexDump(entry->NtHash, 16); #endif @@ -261,7 +261,7 @@ void ntlm_fetch_ntlm_v2_hash(NTLM_CONTEXT* context, char* hash) if (entry != NULL) { #ifdef WITH_DEBUG_NTLM - printf("NTLM Hash:\n"); + fprintf(stderr, "NTLM Hash:\n"); winpr_HexDump(entry->NtHash, 16); #endif @@ -277,7 +277,7 @@ void ntlm_fetch_ntlm_v2_hash(NTLM_CONTEXT* context, char* hash) } else { - printf("Error: Could not find user in SAM database\n"); + fprintf(stderr, "Error: Could not find user in SAM database\n"); } } @@ -352,25 +352,25 @@ void ntlm_compute_ntlm_v2_response(NTLM_CONTEXT* context) ntlm_compute_ntlm_v2_hash(context, (char*) ntlm_v2_hash); #ifdef WITH_DEBUG_NTLM - printf("Password (length = %d)\n", context->identity.PasswordLength * 2); + fprintf(stderr, "Password (length = %d)\n", context->identity.PasswordLength * 2); winpr_HexDump((BYTE*) context->identity.Password, context->identity.PasswordLength * 2); - printf("\n"); + fprintf(stderr, "\n"); - printf("Username (length = %d)\n", context->identity.UserLength * 2); + fprintf(stderr, "Username (length = %d)\n", context->identity.UserLength * 2); winpr_HexDump((BYTE*) context->identity.User, context->identity.UserLength * 2); - printf("\n"); + fprintf(stderr, "\n"); - printf("Domain (length = %d)\n", context->identity.DomainLength * 2); + fprintf(stderr, "Domain (length = %d)\n", context->identity.DomainLength * 2); winpr_HexDump((BYTE*) context->identity.Domain, context->identity.DomainLength * 2); - printf("\n"); + fprintf(stderr, "\n"); - printf("Workstation (length = %d)\n", context->Workstation.Length); + fprintf(stderr, "Workstation (length = %d)\n", context->Workstation.Length); winpr_HexDump((BYTE*) context->Workstation.Buffer, context->Workstation.Length); - printf("\n"); + fprintf(stderr, "\n"); - printf("NTOWFv2, NTLMv2 Hash\n"); + fprintf(stderr, "NTOWFv2, NTLMv2 Hash\n"); winpr_HexDump(ntlm_v2_hash, 16); - printf("\n"); + fprintf(stderr, "\n"); #endif /* Construct temp */ @@ -384,9 +384,9 @@ void ntlm_compute_ntlm_v2_response(NTLM_CONTEXT* context) CopyMemory(&blob[28], TargetInfo->pvBuffer, TargetInfo->cbBuffer); #ifdef WITH_DEBUG_NTLM - printf("NTLMv2 Response Temp Blob\n"); + fprintf(stderr, "NTLMv2 Response Temp Blob\n"); winpr_HexDump(ntlm_v2_temp.pvBuffer, ntlm_v2_temp.cbBuffer); - printf("\n"); + fprintf(stderr, "\n"); #endif /* Concatenate server challenge with temp */ diff --git a/winpr/libwinpr/sspi/NTLM/ntlm_message.c b/winpr/libwinpr/sspi/NTLM/ntlm_message.c index 2607a294b..d4789c6e3 100644 --- a/winpr/libwinpr/sspi/NTLM/ntlm_message.c +++ b/winpr/libwinpr/sspi/NTLM/ntlm_message.c @@ -76,18 +76,18 @@ void ntlm_print_negotiate_flags(UINT32 flags) int i; const char* str; - printf("negotiateFlags \"0x%08X\"{\n", flags); + fprintf(stderr, "negotiateFlags \"0x%08X\"{\n", flags); for (i = 31; i >= 0; i--) { if ((flags >> i) & 1) { str = NTLM_NEGOTIATE_STRINGS[(31 - i)]; - printf("\t%s (%d),\n", str, (31 - i)); + fprintf(stderr, "\t%s (%d),\n", str, (31 - i)); } } - printf("}\n"); + fprintf(stderr, "}\n"); } void ntlm_read_message_header(wStream* s, NTLM_MESSAGE_HEADER* header) @@ -112,13 +112,13 @@ BOOL ntlm_validate_message_header(wStream* s, NTLM_MESSAGE_HEADER* header, UINT3 { if (memcmp(header->Signature, NTLM_SIGNATURE, sizeof(NTLM_SIGNATURE)) != 0) { - printf("Unexpected NTLM signature: %s, expected:%s\n", header->Signature, NTLM_SIGNATURE); + fprintf(stderr, "Unexpected NTLM signature: %s, expected:%s\n", header->Signature, NTLM_SIGNATURE); return FALSE; } if (header->MessageType != MessageType) { - printf("Unexpected NTLM message type: %d, expected: %d\n", header->MessageType, MessageType); + fprintf(stderr, "Unexpected NTLM message type: %d, expected: %d\n", header->MessageType, MessageType); return FALSE; } @@ -179,13 +179,13 @@ void ntlm_free_message_fields_buffer(NTLM_MESSAGE_FIELDS* fields) void ntlm_print_message_fields(NTLM_MESSAGE_FIELDS* fields, const char* name) { - printf("%s (Len: %d MaxLen: %d BufferOffset: %d)\n", + fprintf(stderr, "%s (Len: %d MaxLen: %d BufferOffset: %d)\n", name, fields->Len, fields->MaxLen, fields->BufferOffset); if (fields->Len > 0) winpr_HexDump(fields->Buffer, fields->Len); - printf("\n"); + fprintf(stderr, "\n"); } SECURITY_STATUS ntlm_read_NegotiateMessage(NTLM_CONTEXT* context, PSecBuffer buffer) @@ -241,9 +241,9 @@ SECURITY_STATUS ntlm_read_NegotiateMessage(NTLM_CONTEXT* context, PSecBuffer buf context->NegotiateMessage.BufferType = buffer->BufferType; #ifdef WITH_DEBUG_NTLM - printf("NEGOTIATE_MESSAGE (length = %d)\n", (int) context->NegotiateMessage.cbBuffer); + fprintf(stderr, "NEGOTIATE_MESSAGE (length = %d)\n", (int) context->NegotiateMessage.cbBuffer); winpr_HexDump(context->NegotiateMessage.pvBuffer, context->NegotiateMessage.cbBuffer); - printf("\n"); + fprintf(stderr, "\n"); ntlm_print_negotiate_flags(message->NegotiateFlags); @@ -325,9 +325,9 @@ SECURITY_STATUS ntlm_write_NegotiateMessage(NTLM_CONTEXT* context, PSecBuffer bu context->NegotiateMessage.BufferType = buffer->BufferType; #ifdef WITH_DEBUG_NTLM - printf("NEGOTIATE_MESSAGE (length = %d)\n", length); + fprintf(stderr, "NEGOTIATE_MESSAGE (length = %d)\n", length); winpr_HexDump(s->buffer, length); - printf("\n"); + fprintf(stderr, "\n"); if (message->NegotiateFlags & NTLMSSP_NEGOTIATE_VERSION) ntlm_print_version_info(&(message->Version)); @@ -413,9 +413,9 @@ SECURITY_STATUS ntlm_read_ChallengeMessage(NTLM_CONTEXT* context, PSecBuffer buf CopyMemory(context->ChallengeMessage.pvBuffer, StartOffset, length); #ifdef WITH_DEBUG_NTLM - printf("CHALLENGE_MESSAGE (length = %d)\n", length); + fprintf(stderr, "CHALLENGE_MESSAGE (length = %d)\n", length); winpr_HexDump(context->ChallengeMessage.pvBuffer, context->ChallengeMessage.cbBuffer); - printf("\n"); + fprintf(stderr, "\n"); ntlm_print_negotiate_flags(context->NegotiateFlags); @@ -427,7 +427,7 @@ SECURITY_STATUS ntlm_read_ChallengeMessage(NTLM_CONTEXT* context, PSecBuffer buf if (context->ChallengeTargetInfo.cbBuffer > 0) { - printf("ChallengeTargetInfo (%d):\n", (int) context->ChallengeTargetInfo.cbBuffer); + fprintf(stderr, "ChallengeTargetInfo (%d):\n", (int) context->ChallengeTargetInfo.cbBuffer); ntlm_print_av_pair_list(context->ChallengeTargetInfo.pvBuffer); } #endif @@ -474,49 +474,49 @@ SECURITY_STATUS ntlm_read_ChallengeMessage(NTLM_CONTEXT* context, PSecBuffer buf ntlm_init_rc4_seal_states(context); #ifdef WITH_DEBUG_NTLM - printf("ClientChallenge\n"); + fprintf(stderr, "ClientChallenge\n"); winpr_HexDump(context->ClientChallenge, 8); - printf("\n"); + fprintf(stderr, "\n"); - printf("ServerChallenge\n"); + fprintf(stderr, "ServerChallenge\n"); winpr_HexDump(context->ServerChallenge, 8); - printf("\n"); + fprintf(stderr, "\n"); - printf("SessionBaseKey\n"); + fprintf(stderr, "SessionBaseKey\n"); winpr_HexDump(context->SessionBaseKey, 16); - printf("\n"); + fprintf(stderr, "\n"); - printf("KeyExchangeKey\n"); + fprintf(stderr, "KeyExchangeKey\n"); winpr_HexDump(context->KeyExchangeKey, 16); - printf("\n"); + fprintf(stderr, "\n"); - printf("ExportedSessionKey\n"); + fprintf(stderr, "ExportedSessionKey\n"); winpr_HexDump(context->ExportedSessionKey, 16); - printf("\n"); + fprintf(stderr, "\n"); - printf("RandomSessionKey\n"); + fprintf(stderr, "RandomSessionKey\n"); winpr_HexDump(context->RandomSessionKey, 16); - printf("\n"); + fprintf(stderr, "\n"); - printf("ClientSigningKey\n"); + fprintf(stderr, "ClientSigningKey\n"); winpr_HexDump(context->ClientSigningKey, 16); - printf("\n"); + fprintf(stderr, "\n"); - printf("ClientSealingKey\n"); + fprintf(stderr, "ClientSealingKey\n"); winpr_HexDump(context->ClientSealingKey, 16); - printf("\n"); + fprintf(stderr, "\n"); - printf("ServerSigningKey\n"); + fprintf(stderr, "ServerSigningKey\n"); winpr_HexDump(context->ServerSigningKey, 16); - printf("\n"); + fprintf(stderr, "\n"); - printf("ServerSealingKey\n"); + fprintf(stderr, "ServerSealingKey\n"); winpr_HexDump(context->ServerSealingKey, 16); - printf("\n"); + fprintf(stderr, "\n"); - printf("Timestamp\n"); + fprintf(stderr, "Timestamp\n"); winpr_HexDump(context->Timestamp, 8); - printf("\n"); + fprintf(stderr, "\n"); #endif context->state = NTLM_STATE_AUTHENTICATE; @@ -613,9 +613,9 @@ SECURITY_STATUS ntlm_write_ChallengeMessage(NTLM_CONTEXT* context, PSecBuffer bu CopyMemory(context->ChallengeMessage.pvBuffer, s->buffer, length); #ifdef WITH_DEBUG_NTLM - printf("CHALLENGE_MESSAGE (length = %d)\n", length); + fprintf(stderr, "CHALLENGE_MESSAGE (length = %d)\n", length); winpr_HexDump(context->ChallengeMessage.pvBuffer, context->ChallengeMessage.cbBuffer); - printf("\n"); + fprintf(stderr, "\n"); ntlm_print_negotiate_flags(message->NegotiateFlags); @@ -733,9 +733,9 @@ SECURITY_STATUS ntlm_read_AuthenticateMessage(NTLM_CONTEXT* context, PSecBuffer } #ifdef WITH_DEBUG_NTLM - printf("AUTHENTICATE_MESSAGE (length = %d)\n", (int) context->AuthenticateMessage.cbBuffer); + fprintf(stderr, "AUTHENTICATE_MESSAGE (length = %d)\n", (int) context->AuthenticateMessage.cbBuffer); winpr_HexDump(context->AuthenticateMessage.pvBuffer, context->AuthenticateMessage.cbBuffer); - printf("\n"); + fprintf(stderr, "\n"); if (message->NegotiateFlags & NTLMSSP_NEGOTIATE_VERSION) ntlm_print_version_info(&(message->Version)); @@ -751,7 +751,7 @@ SECURITY_STATUS ntlm_read_AuthenticateMessage(NTLM_CONTEXT* context, PSecBuffer if (flags & MSV_AV_FLAGS_MESSAGE_INTEGRITY_CHECK) { - printf("MessageIntegrityCheck:\n"); + fprintf(stderr, "MessageIntegrityCheck:\n"); winpr_HexDump(message->MessageIntegrityCheck, 16); } #endif @@ -793,11 +793,11 @@ SECURITY_STATUS ntlm_read_AuthenticateMessage(NTLM_CONTEXT* context, PSecBuffer if (memcmp(context->MessageIntegrityCheck, message->MessageIntegrityCheck, 16) != 0) { - printf("Message Integrity Check (MIC) verification failed!\n"); + fprintf(stderr, "Message Integrity Check (MIC) verification failed!\n"); - printf("Expected MIC:\n"); + fprintf(stderr, "Expected MIC:\n"); winpr_HexDump(context->MessageIntegrityCheck, 16); - printf("Actual MIC:\n"); + fprintf(stderr, "Actual MIC:\n"); winpr_HexDump(message->MessageIntegrityCheck, 16); return SEC_E_MESSAGE_ALTERED; @@ -816,49 +816,49 @@ SECURITY_STATUS ntlm_read_AuthenticateMessage(NTLM_CONTEXT* context, PSecBuffer ntlm_init_rc4_seal_states(context); #ifdef WITH_DEBUG_NTLM - printf("ClientChallenge\n"); + fprintf(stderr, "ClientChallenge\n"); winpr_HexDump(context->ClientChallenge, 8); - printf("\n"); + fprintf(stderr, "\n"); - printf("ServerChallenge\n"); + fprintf(stderr, "ServerChallenge\n"); winpr_HexDump(context->ServerChallenge, 8); - printf("\n"); + fprintf(stderr, "\n"); - printf("SessionBaseKey\n"); + fprintf(stderr, "SessionBaseKey\n"); winpr_HexDump(context->SessionBaseKey, 16); - printf("\n"); + fprintf(stderr, "\n"); - printf("KeyExchangeKey\n"); + fprintf(stderr, "KeyExchangeKey\n"); winpr_HexDump(context->KeyExchangeKey, 16); - printf("\n"); + fprintf(stderr, "\n"); - printf("ExportedSessionKey\n"); + fprintf(stderr, "ExportedSessionKey\n"); winpr_HexDump(context->ExportedSessionKey, 16); - printf("\n"); + fprintf(stderr, "\n"); - printf("RandomSessionKey\n"); + fprintf(stderr, "RandomSessionKey\n"); winpr_HexDump(context->RandomSessionKey, 16); - printf("\n"); + fprintf(stderr, "\n"); - printf("ClientSigningKey\n"); + fprintf(stderr, "ClientSigningKey\n"); winpr_HexDump(context->ClientSigningKey, 16); - printf("\n"); + fprintf(stderr, "\n"); - printf("ClientSealingKey\n"); + fprintf(stderr, "ClientSealingKey\n"); winpr_HexDump(context->ClientSealingKey, 16); - printf("\n"); + fprintf(stderr, "\n"); - printf("ServerSigningKey\n"); + fprintf(stderr, "ServerSigningKey\n"); winpr_HexDump(context->ServerSigningKey, 16); - printf("\n"); + fprintf(stderr, "\n"); - printf("ServerSealingKey\n"); + fprintf(stderr, "ServerSealingKey\n"); winpr_HexDump(context->ServerSealingKey, 16); - printf("\n"); + fprintf(stderr, "\n"); - printf("Timestamp\n"); + fprintf(stderr, "Timestamp\n"); winpr_HexDump(context->Timestamp, 8); - printf("\n"); + fprintf(stderr, "\n"); #endif context->state = NTLM_STATE_FINAL; @@ -1030,9 +1030,9 @@ SECURITY_STATUS ntlm_write_AuthenticateMessage(NTLM_CONTEXT* context, PSecBuffer } #ifdef WITH_DEBUG_NTLM - printf("AUTHENTICATE_MESSAGE (length = %d)\n", length); + fprintf(stderr, "AUTHENTICATE_MESSAGE (length = %d)\n", length); winpr_HexDump(s->buffer, length); - printf("\n"); + fprintf(stderr, "\n"); ntlm_print_negotiate_flags(message->NegotiateFlags); @@ -1041,7 +1041,7 @@ SECURITY_STATUS ntlm_write_AuthenticateMessage(NTLM_CONTEXT* context, PSecBuffer if (context->AuthenticateTargetInfo.cbBuffer > 0) { - printf("AuthenticateTargetInfo (%d):\n", (int) context->AuthenticateTargetInfo.cbBuffer); + fprintf(stderr, "AuthenticateTargetInfo (%d):\n", (int) context->AuthenticateTargetInfo.cbBuffer); ntlm_print_av_pair_list(context->AuthenticateTargetInfo.pvBuffer); } @@ -1054,9 +1054,9 @@ SECURITY_STATUS ntlm_write_AuthenticateMessage(NTLM_CONTEXT* context, PSecBuffer if (context->UseMIC) { - printf("MessageIntegrityCheck (length = 16)\n"); + fprintf(stderr, "MessageIntegrityCheck (length = 16)\n"); winpr_HexDump(context->MessageIntegrityCheck, 16); - printf("\n"); + fprintf(stderr, "\n"); } #endif diff --git a/winpr/libwinpr/sspi/Schannel/schannel_openssl.c b/winpr/libwinpr/sspi/Schannel/schannel_openssl.c index 7214ea0cb..cdee13a2b 100644 --- a/winpr/libwinpr/sspi/Schannel/schannel_openssl.c +++ b/winpr/libwinpr/sspi/Schannel/schannel_openssl.c @@ -60,7 +60,7 @@ int schannel_openssl_client_init(SCHANNEL_OPENSSL* context) if (!context->ctx) { - printf("SSL_CTX_new failed\n"); + fprintf(stderr, "SSL_CTX_new failed\n"); return -1; } @@ -99,7 +99,7 @@ int schannel_openssl_client_init(SCHANNEL_OPENSSL* context) if (!context->ssl) { - printf("SSL_new failed\n"); + fprintf(stderr, "SSL_new failed\n"); return -1; } @@ -107,7 +107,7 @@ int schannel_openssl_client_init(SCHANNEL_OPENSSL* context) if (!context->bioRead) { - printf("BIO_new failed\n"); + fprintf(stderr, "BIO_new failed\n"); return -1; } @@ -117,7 +117,7 @@ int schannel_openssl_client_init(SCHANNEL_OPENSSL* context) if (!context->bioWrite) { - printf("BIO_new failed\n"); + fprintf(stderr, "BIO_new failed\n"); return -1; } @@ -143,7 +143,7 @@ int schannel_openssl_server_init(SCHANNEL_OPENSSL* context) if (!context->ctx) { - printf("SSL_CTX_new failed\n"); + fprintf(stderr, "SSL_CTX_new failed\n"); return -1; } @@ -188,7 +188,7 @@ int schannel_openssl_server_init(SCHANNEL_OPENSSL* context) if (SSL_CTX_use_RSAPrivateKey_file(context->ctx, "/tmp/localhost.key", SSL_FILETYPE_PEM) <= 0) { - printf("SSL_CTX_use_RSAPrivateKey_file failed\n"); + fprintf(stderr, "SSL_CTX_use_RSAPrivateKey_file failed\n"); return -1; } @@ -196,13 +196,13 @@ int schannel_openssl_server_init(SCHANNEL_OPENSSL* context) if (!context->ssl) { - printf("SSL_new failed\n"); + fprintf(stderr, "SSL_new failed\n"); return -1; } if (SSL_use_certificate_file(context->ssl, "/tmp/localhost.crt", SSL_FILETYPE_PEM) <= 0) { - printf("SSL_use_certificate_file failed\n"); + fprintf(stderr, "SSL_use_certificate_file failed\n"); return -1; } @@ -210,7 +210,7 @@ int schannel_openssl_server_init(SCHANNEL_OPENSSL* context) if (!context->bioRead) { - printf("BIO_new failed\n"); + fprintf(stderr, "BIO_new failed\n"); return -1; } @@ -220,7 +220,7 @@ int schannel_openssl_server_init(SCHANNEL_OPENSSL* context) if (!context->bioWrite) { - printf("BIO_new failed\n"); + fprintf(stderr, "BIO_new failed\n"); return -1; } @@ -262,7 +262,7 @@ SECURITY_STATUS schannel_openssl_client_process_tokens(SCHANNEL_OPENSSL* context if (status < 0) { ssl_error = SSL_get_error(context->ssl, status); - printf("SSL_connect error: %s\n", openssl_get_ssl_error_string(ssl_error)); + fprintf(stderr, "SSL_connect error: %s\n", openssl_get_ssl_error_string(ssl_error)); } if (status == 1) @@ -321,7 +321,7 @@ SECURITY_STATUS schannel_openssl_server_process_tokens(SCHANNEL_OPENSSL* context if (status < 0) { ssl_error = SSL_get_error(context->ssl, status); - printf("SSL_accept error: %s\n", openssl_get_ssl_error_string(ssl_error)); + fprintf(stderr, "SSL_accept error: %s\n", openssl_get_ssl_error_string(ssl_error)); } if (status == 1) @@ -379,7 +379,7 @@ SECURITY_STATUS schannel_openssl_encrypt_message(SCHANNEL_OPENSSL* context, PSec if (status < 0) { ssl_error = SSL_get_error(context->ssl, status); - printf("SSL_write: %s\n", openssl_get_ssl_error_string(ssl_error)); + fprintf(stderr, "SSL_write: %s\n", openssl_get_ssl_error_string(ssl_error)); } status = BIO_read(context->bioWrite, context->ReadBuffer, SCHANNEL_CB_MAX_TOKEN); @@ -425,7 +425,7 @@ SECURITY_STATUS schannel_openssl_decrypt_message(SCHANNEL_OPENSSL* context, PSec if (status < 0) { ssl_error = SSL_get_error(context->ssl, status); - printf("SSL_read: %s\n", openssl_get_ssl_error_string(ssl_error)); + fprintf(stderr, "SSL_read: %s\n", openssl_get_ssl_error_string(ssl_error)); } length = status; diff --git a/winpr/libwinpr/synch/event.c b/winpr/libwinpr/synch/event.c index 4b49a4d3f..7298cb56c 100644 --- a/winpr/libwinpr/synch/event.c +++ b/winpr/libwinpr/synch/event.c @@ -35,7 +35,6 @@ #include <unistd.h> #endif - #ifdef HAVE_EVENTFD_H #include <sys/eventfd.h> #include <errno.h> @@ -57,7 +56,7 @@ HANDLE CreateEventW(LPSECURITY_ATTRIBUTES lpEventAttributes, BOOL bManualReset, if (!event->bManualReset) { - printf("CreateEventW: auto-reset events not yet implemented\n"); + fprintf(stderr, "CreateEventW: auto-reset events not yet implemented\n"); } event->pipe_fd[0] = -1; @@ -65,15 +64,16 @@ HANDLE CreateEventW(LPSECURITY_ATTRIBUTES lpEventAttributes, BOOL bManualReset, #ifdef HAVE_EVENTFD_H event->pipe_fd[0] = eventfd(0, EFD_NONBLOCK); + if (event->pipe_fd[0] < 0) { - printf("CreateEventW: failed to create event\n"); + fprintf(stderr, "CreateEventW: failed to create event\n"); return NULL; } #else if (pipe(event->pipe_fd) < 0) { - printf("CreateEventW: failed to create event\n"); + fprintf(stderr, "CreateEventW: failed to create event\n"); return NULL; } #endif @@ -287,10 +287,13 @@ void* GetEventWaitObject(HANDLE hEvent) { #ifndef _WIN32 int fd; + void* obj; fd = GetEventFileDescriptor(hEvent); - return ((void*) (long) fd); + obj = ((void*) (long) fd); + + return obj; #else return hEvent; #endif diff --git a/winpr/libwinpr/synch/mutex.c b/winpr/libwinpr/synch/mutex.c index d4b001dd9..62c2e2611 100644 --- a/winpr/libwinpr/synch/mutex.c +++ b/winpr/libwinpr/synch/mutex.c @@ -39,15 +39,18 @@ HANDLE CreateMutexW(LPSECURITY_ATTRIBUTES lpMutexAttributes, BOOL bInitialOwner, LPCWSTR lpName) { - HANDLE handle; + HANDLE handle = NULL; pthread_mutex_t* pMutex; pMutex = (pthread_mutex_t*) malloc(sizeof(pthread_mutex_t)); if (pMutex) + { pthread_mutex_init(pMutex, 0); - - handle = winpr_Handle_Insert(HANDLE_TYPE_MUTEX, pMutex); + handle = winpr_Handle_Insert(HANDLE_TYPE_MUTEX, pMutex); + if (bInitialOwner) + pthread_mutex_lock(pMutex); + } return handle; } diff --git a/winpr/libwinpr/synch/semaphore.c b/winpr/libwinpr/synch/semaphore.c index 44602686c..d0b7f0945 100644 --- a/winpr/libwinpr/synch/semaphore.c +++ b/winpr/libwinpr/synch/semaphore.c @@ -48,7 +48,7 @@ HANDLE CreateSemaphoreW(LPSECURITY_ATTRIBUTES lpSemaphoreAttributes, LONG lIniti if (pipe(semaphore->pipe_fd) < 0) { - printf("CreateSemaphoreW: failed to create semaphore\n"); + fprintf(stderr, "CreateSemaphoreW: failed to create semaphore\n"); return NULL; } diff --git a/winpr/libwinpr/synch/wait.c b/winpr/libwinpr/synch/wait.c index 50fcca363..441d3ced9 100644 --- a/winpr/libwinpr/synch/wait.c +++ b/winpr/libwinpr/synch/wait.c @@ -56,19 +56,22 @@ DWORD WaitForSingleObject(HANDLE hHandle, DWORD dwMilliseconds) void* thread_status = NULL; if (dwMilliseconds != INFINITE) - printf("WaitForSingleObject: timeout not implemented for thread wait\n"); + fprintf(stderr, "WaitForSingleObject: timeout not implemented for thread wait\n"); thread = (WINPR_THREAD*) Object; status = pthread_join(thread->thread, &thread_status); if (status != 0) - printf("WaitForSingleObject: pthread_join failure: %d\n", status); + fprintf(stderr, "WaitForSingleObject: pthread_join failure: %d\n", status); + + if (thread_status) + thread->dwExitCode = ((DWORD) (size_t) thread_status); } else if (Type == HANDLE_TYPE_MUTEX) { if (dwMilliseconds != INFINITE) - printf("WaitForSingleObject: timeout not implemented for mutex wait\n"); + fprintf(stderr, "WaitForSingleObject: timeout not implemented for mutex wait\n"); pthread_mutex_lock((pthread_mutex_t*) Object); } @@ -148,7 +151,7 @@ DWORD WaitForSingleObject(HANDLE hHandle, DWORD dwMilliseconds) } else { - printf("WaitForSingleObject: unknown handle type %lu\n", Type); + fprintf(stderr, "WaitForSingleObject: unknown handle type %lu\n", Type); } return WAIT_OBJECT_0; @@ -177,7 +180,7 @@ DWORD WaitForMultipleObjects(DWORD nCount, const HANDLE* lpHandles, BOOL bWaitAl ZeroMemory(&timeout, sizeof(timeout)); if (bWaitAll) - printf("WaitForMultipleObjects: bWaitAll not yet implemented\n"); + fprintf(stderr, "WaitForMultipleObjects: bWaitAll not yet implemented\n"); for (index = 0; index < nCount; index++) { diff --git a/winpr/libwinpr/sysinfo/sysinfo.c b/winpr/libwinpr/sysinfo/sysinfo.c index 7b6d86df7..356b0a9b8 100644 --- a/winpr/libwinpr/sysinfo/sysinfo.c +++ b/winpr/libwinpr/sysinfo/sysinfo.c @@ -248,7 +248,7 @@ BOOL GetComputerNameExA(COMPUTER_NAME_FORMAT NameType, LPSTR lpBuffer, LPDWORD l BOOL GetComputerNameExW(COMPUTER_NAME_FORMAT NameType, LPWSTR lpBuffer, LPDWORD nSize) { - printf("GetComputerNameExW unimplemented\n"); + fprintf(stderr, "GetComputerNameExW unimplemented\n"); return 0; } @@ -288,7 +288,7 @@ BOOL GetVersionExA(LPOSVERSIONINFOA lpVersionInformation) BOOL GetVersionExW(LPOSVERSIONINFOW lpVersionInformation) { - printf("GetVersionExW unimplemented\n"); + fprintf(stderr, "GetVersionExW unimplemented\n"); return 1; } diff --git a/winpr/libwinpr/thread/thread.c b/winpr/libwinpr/thread/thread.c index 72290404a..895c14a1e 100644 --- a/winpr/libwinpr/thread/thread.c +++ b/winpr/libwinpr/thread/thread.c @@ -125,7 +125,23 @@ HANDLE CreateRemoteThread(HANDLE hProcess, LPSECURITY_ATTRIBUTES lpThreadAttribu VOID ExitThread(DWORD dwExitCode) { - pthread_exit((void*) dwExitCode); + pthread_exit((void*) (size_t) dwExitCode); +} + +BOOL GetExitCodeThread(HANDLE hThread, LPDWORD lpExitCode) +{ + ULONG Type; + PVOID Object; + WINPR_THREAD* thread; + + if (!winpr_Handle_GetInfo(hThread, &Type, &Object)) + return FALSE; + + thread = (WINPR_THREAD*) Object; + + *lpExitCode = thread->dwExitCode; + + return TRUE; } HANDLE _GetCurrentThread(VOID) diff --git a/winpr/libwinpr/thread/thread.h b/winpr/libwinpr/thread/thread.h index a9b3b2f8d..263512fee 100644 --- a/winpr/libwinpr/thread/thread.h +++ b/winpr/libwinpr/thread/thread.h @@ -31,6 +31,7 @@ typedef void *(*pthread_start_routine)(void*); struct winpr_thread { BOOL started; + DWORD dwExitCode; pthread_t thread; SIZE_T dwStackSize; LPVOID lpParameter; diff --git a/winpr/libwinpr/utils/CMakeLists.txt b/winpr/libwinpr/utils/CMakeLists.txt index 54c88f286..50c6eaad7 100644 --- a/winpr/libwinpr/utils/CMakeLists.txt +++ b/winpr/libwinpr/utils/CMakeLists.txt @@ -29,9 +29,21 @@ set(${MODULE_PREFIX}_COLLECTIONS_SRCS collections/CountdownEvent.c collections/BufferPool.c collections/ObjectPool.c + collections/StreamPool.c collections/MessageQueue.c collections/MessagePipe.c) +set(${MODULE_PREFIX}_TRIO_SRCS + trio/strio.h + trio/trio.c + trio/trio.h + trio/triodef.h + trio/trionan.c + trio/trionan.h + trio/triop.h + trio/triostr.c + trio/triostr.h) + set(${MODULE_PREFIX}_SRCS sam.c ntlm.c @@ -40,8 +52,10 @@ set(${MODULE_PREFIX}_SRCS cmdline.c) set(${MODULE_PREFIX}_SRCS ${${MODULE_PREFIX}_SRCS} - ${${MODULE_PREFIX}_COLLECTIONS_SRCS}) + ${${MODULE_PREFIX}_COLLECTIONS_SRCS} + ${${MODULE_PREFIX}_TRIO_SRCS}) +include_directories("trio") include_directories(${ZLIB_INCLUDE_DIRS}) include_directories(${OPENSSL_INCLUDE_DIR}) @@ -54,7 +68,11 @@ set_target_properties(${MODULE_NAME} PROPERTIES VERSION ${WINPR_VERSION_FULL} SO set(${MODULE_PREFIX}_LIBS ${ZLIB_LIBRARIES} ${OPENSSL_LIBRARIES}) - + +if(UNIX) + set(${MODULE_PREFIX}_LIBS ${${MODULE_PREFIX}_LIBS} m) +endif() + set_complex_link_libraries(VARIABLE ${MODULE_PREFIX}_LIBS MONOLITHIC ${MONOLITHIC_BUILD} INTERNAL MODULE winpr diff --git a/winpr/libwinpr/utils/collections/BufferPool.c b/winpr/libwinpr/utils/collections/BufferPool.c index 348e231b1..d10ba1360 100644 --- a/winpr/libwinpr/utils/collections/BufferPool.c +++ b/winpr/libwinpr/utils/collections/BufferPool.c @@ -60,7 +60,7 @@ void* BufferPool_Take(wBufferPool* pool, int bufferSize) } else { - printf("Variable-size BufferPool not yet implemented\n"); + fprintf(stderr, "Variable-size BufferPool not yet implemented\n"); } if (pool->synchronized) @@ -138,7 +138,7 @@ wBufferPool* BufferPool_New(BOOL synchronized, int fixedSize, DWORD alignment) if (!pool->fixedSize) { - printf("Variable-size BufferPool not yet implemented\n"); + fprintf(stderr, "Variable-size BufferPool not yet implemented\n"); } pool->size = 0; diff --git a/winpr/libwinpr/utils/collections/Queue.c b/winpr/libwinpr/utils/collections/Queue.c index 79c286dbb..fa33df76a 100644 --- a/winpr/libwinpr/utils/collections/Queue.c +++ b/winpr/libwinpr/utils/collections/Queue.c @@ -44,21 +44,21 @@ int Queue_Count(wQueue* queue) } /** - * Gets a value indicating whether access to the Queue is synchronized (thread safe). + * Lock access to the ArrayList */ -BOOL Queue_IsSynchronized(wQueue* queue) +BOOL Queue_Lock(wQueue* queue) { - return queue->synchronized; + return (WaitForSingleObject(queue->mutex, INFINITE) == WAIT_OBJECT_0) ? TRUE : FALSE; } /** - * Gets an object that can be used to synchronize access to the Queue. + * Unlock access to the ArrayList */ -HANDLE Queue_SyncRoot(wQueue* queue) +BOOL Queue_Unlock(wQueue* queue) { - return queue->mutex; + return ReleaseMutex(queue->mutex); } /** diff --git a/winpr/libwinpr/utils/collections/StreamPool.c b/winpr/libwinpr/utils/collections/StreamPool.c new file mode 100644 index 000000000..96a491acf --- /dev/null +++ b/winpr/libwinpr/utils/collections/StreamPool.c @@ -0,0 +1,323 @@ +/** + * WinPR: Windows Portable Runtime + * Object Pool + * + * Copyright 2012 Marc-Andre Moreau <marcandre.moreau@gmail.com> + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <winpr/crt.h> + +#include <winpr/collections.h> + +/** + * Methods + */ + +void StreamPool_ShiftUsed(wStreamPool* pool, int index, int count) +{ + if (count > 0) + { + if (pool->uSize + count > pool->uCapacity) + { + pool->uCapacity *= 2; + pool->uArray = (wStream**) realloc(pool->uArray, sizeof(wStream*) * pool->uCapacity); + } + + MoveMemory(&pool->uArray[index + count], &pool->uArray[index], (pool->uSize - index) * sizeof(wStream*)); + pool->uSize += count; + } + else if (count < 0) + { + MoveMemory(&pool->uArray[index], &pool->uArray[index - count], (pool->uSize + count) * sizeof(wStream*)); + pool->uSize += count; + } +} + +/** + * Adds a used stream to the pool. + */ + +void StreamPool_AddUsed(wStreamPool* pool, wStream* s) +{ + int index; + + if ((pool->uSize + 1) >= pool->uCapacity) + { + pool->uCapacity *= 2; + pool->uArray = (wStream**) realloc(pool->uArray, sizeof(wStream*) * pool->uCapacity); + } + + pool->uArray[(pool->uSize)++] = s; +} + +/** + * Removes a used stream from the pool. + */ + +void StreamPool_RemoveUsed(wStreamPool* pool, wStream* s) +{ + int index; + BOOL found = FALSE; + + for (index = 0; index < pool->uSize; index++) + { + if (pool->uArray[index] == s) + { + found = TRUE; + break; + } + } + + if (found) + StreamPool_ShiftUsed(pool, index, -1); +} + +/** + * Gets a stream from the pool. + */ + +wStream* StreamPool_Take(wStreamPool* pool, size_t size) +{ + wStream* s = NULL; + + if (pool->synchronized) + WaitForSingleObject(pool->mutex, INFINITE); + + if (pool->aSize > 0) + s = pool->aArray[--(pool->aSize)]; + + if (size == 0) + size = pool->defaultSize; + + if (!s) + { + s = Stream_New(NULL, size); + } + else + { + Stream_EnsureCapacity(s, size); + Stream_Pointer(s) = Stream_Buffer(s); + } + + s->pool = pool; + s->count = 1; + + StreamPool_AddUsed(pool, s); + + if (pool->synchronized) + ReleaseMutex(pool->mutex); + + return s; +} + +/** + * Returns an object to the pool. + */ + +void StreamPool_Return(wStreamPool* pool, wStream* s) +{ + if (pool->synchronized) + WaitForSingleObject(pool->mutex, INFINITE); + + if ((pool->aSize + 1) >= pool->aCapacity) + { + pool->aCapacity *= 2; + pool->aArray = (wStream**) realloc(pool->aArray, sizeof(wStream*) * pool->aCapacity); + } + + pool->aArray[(pool->aSize)++] = s; + StreamPool_RemoveUsed(pool, s); + + if (pool->synchronized) + ReleaseMutex(pool->mutex); +} + +/** + * Lock the stream pool + */ + +void StreamPool_Lock(wStreamPool* pool) +{ + WaitForSingleObject(pool->mutex, INFINITE); +} + +/** + * Unlock the stream pool + */ + +void StreamPool_Unlock(wStreamPool* pool) +{ + ReleaseMutex(pool->mutex); +} + +/** + * Increment stream reference count + */ + +void Stream_AddRef(wStream* s) +{ + if (s->pool) + { + StreamPool_Lock(s->pool); + s->count++; + StreamPool_Unlock(s->pool); + } +} + +/** + * Decrement stream reference count + */ + +void Stream_Release(wStream* s) +{ + DWORD count; + + if (s->pool) + { + StreamPool_Lock(s->pool); + count = --(s->count); + StreamPool_Unlock(s->pool); + + if (count == 0) + StreamPool_Return(s->pool, s); + } +} + +/** + * Find stream in pool using pointer inside buffer + */ + +wStream* StreamPool_Find(wStreamPool* pool, BYTE* ptr) +{ + int index; + wStream* s = NULL; + BOOL found = FALSE; + + WaitForSingleObject(pool->mutex, INFINITE); + + for (index = 0; index < pool->uSize; index++) + { + s = pool->uArray[index]; + + if ((ptr >= s->buffer) && (ptr < (s->buffer + s->capacity))) + { + found = TRUE; + break; + } + } + + ReleaseMutex(pool->mutex); + + return (found) ? s : NULL; +} + +/** + * Find stream in pool and increment reference count + */ + +void StreamPool_AddRef(wStreamPool* pool, BYTE* ptr) +{ + wStream* s; + + s = StreamPool_Find(pool, ptr); + + if (s) + Stream_AddRef(s); +} + +/** + * Find stream in pool and decrement reference count + */ + +void StreamPool_Release(wStreamPool* pool, BYTE* ptr) +{ + wStream* s; + + s = StreamPool_Find(pool, ptr); + + if (s) + Stream_Release(s); +} + +/** + * Releases the streams currently cached in the pool. + */ + +void StreamPool_Clear(wStreamPool* pool) +{ + if (pool->synchronized) + WaitForSingleObject(pool->mutex, INFINITE); + + while (pool->aSize > 0) + { + (pool->aSize)--; + Stream_Free(pool->aArray[pool->aSize], TRUE); + } + + if (pool->synchronized) + ReleaseMutex(pool->mutex); +} + +/** + * Construction, Destruction + */ + +wStreamPool* StreamPool_New(BOOL synchronized, size_t defaultSize) +{ + wStreamPool* pool = NULL; + + pool = (wStreamPool*) malloc(sizeof(wStreamPool)); + + if (pool) + { + ZeroMemory(pool, sizeof(wStreamPool)); + + pool->synchronized = synchronized; + pool->defaultSize = defaultSize; + + if (pool->synchronized) + pool->mutex = CreateMutex(NULL, FALSE, NULL); + + pool->aSize = 0; + pool->aCapacity = 32; + pool->aArray = (wStream**) malloc(sizeof(wStream*) * pool->aCapacity); + + pool->uSize = 0; + pool->uCapacity = 32; + pool->uArray = (wStream**) malloc(sizeof(wStream*) * pool->uCapacity); + } + + return pool; +} + +void StreamPool_Free(wStreamPool* pool) +{ + if (pool) + { + StreamPool_Clear(pool); + + if (pool->synchronized) + CloseHandle(pool->mutex); + + free(pool->aArray); + free(pool->uArray); + + free(pool); + } +} diff --git a/winpr/libwinpr/utils/print.c b/winpr/libwinpr/utils/print.c index e3991cdab..ed9f55af8 100644 --- a/winpr/libwinpr/utils/print.c +++ b/winpr/libwinpr/utils/print.c @@ -28,6 +28,8 @@ #include <winpr/crt.h> #include <winpr/print.h> +#include "trio.h" + void winpr_HexDump(BYTE* data, int length) { BYTE* p = data; @@ -35,7 +37,7 @@ void winpr_HexDump(BYTE* data, int length) while (offset < length) { - printf("%04x ", offset); + fprintf(stderr, "%04x ", offset); line = length - offset; @@ -43,390 +45,24 @@ void winpr_HexDump(BYTE* data, int length) line = WINPR_HEXDUMP_LINE_LENGTH; for (i = 0; i < line; i++) - printf("%02x ", p[i]); + fprintf(stderr, "%02x ", p[i]); for (; i < WINPR_HEXDUMP_LINE_LENGTH; i++) - printf(" "); + fprintf(stderr, " "); for (i = 0; i < line; i++) - printf("%c", (p[i] >= 0x20 && p[i] < 0x7F) ? p[i] : '.'); + fprintf(stderr, "%c", (p[i] >= 0x20 && p[i] < 0x7F) ? p[i] : '.'); - printf("\n"); + fprintf(stderr, "\n"); offset += line; p += line; } } -/*---------------------------------------------------------------------------- -Stripped-down printf() -Chris Giese <geezer@execpc.com> http://my.execpc.com/~geezer -Release date: Feb 3, 2008 - -This code is public domain (no copyright). -You can do whatever you want with it. - -%[flag][width][.prec][mod][conv] -flag: - left justify, pad right w/ blanks DONE - 0 pad left w/ 0 for numerics DONE - + always print sign, + or - no - ' ' (blank) no - # (???) no - -width: (field width) DONE - -prec: (precision) no - -conv: d,i decimal int DONE - u decimal unsigned DONE - o octal DONE - x,X hex DONE - f,e,g,E,G float no - c char DONE - s string DONE - p ptr DONE - -mod: N near ptr DONE - F far ptr no - h short (16-bit) int DONE - l long (32-bit) int DONE - L long long (64-bit) int no -----------------------------------------------------------------------------*/ - -/* flags used in processing format string */ -#define PR_LJ 0x01 /* left justify */ -#define PR_CA 0x02 /* use A-F instead of a-f for hex */ -#define PR_SG 0x04 /* signed numeric conversion (%d vs. %u) */ -#define PR_32 0x08 /* long (32-bit) numeric conversion */ -#define PR_16 0x10 /* short (16-bit) numeric conversion */ -#define PR_WS 0x20 /* PR_SG set and num was < 0 */ -#define PR_LZ 0x40 /* pad left with '0' instead of ' ' */ -#define PR_FP 0x80 /* pointers are far */ - -/* largest number handled is 2^32-1, lowest radix handled is 8. -2^32-1 in base 8 has 11 digits (add 5 for trailing NUL and for slop) */ -#define PR_BUFLEN 16 - -typedef int (*fnptr_t)(unsigned c, void **helper); - -int do_printf(const char *fmt, va_list args, fnptr_t fn, void *ptr) -{ - long num; - unsigned char state, radix; - unsigned char *where, buf[PR_BUFLEN]; - unsigned flags, actual_wd, count, given_wd; - - state = flags = count = given_wd = 0; - - /* begin scanning format specifier list */ - - for (; *fmt; fmt++) - { - switch (state) - { -/* STATE 0: AWAITING % */ - case 0: - if (*fmt != '%') /* not %... */ - { - fn(*fmt, &ptr); /* ...just echo it */ - count++; - break; - } - - /* found %, get next char and advance state to check if next char is a flag */ - - state++; - fmt++; - /* FALL THROUGH */ -/* STATE 1: AWAITING FLAGS (%-0) */ - case 1: - if (*fmt == '%') /* %% */ - { - fn(*fmt, &ptr); - count++; - state = flags = given_wd = 0; - break; - } - if (*fmt == '-') - { - if (flags & PR_LJ) /* %-- is illegal */ - state = flags = given_wd = 0; - else - flags |= PR_LJ; - break; - } - - /* not a flag char: advance state to check if it's field width */ - - state++; - - /* check now for '%0...' */ - - if (*fmt == '0') - { - flags |= PR_LZ; - fmt++; - } - /* FALL THROUGH */ -/* STATE 2: AWAITING (NUMERIC) FIELD WIDTH */ - case 2: - if (*fmt >= '0' && *fmt <= '9') - { - given_wd = 10 * given_wd + (*fmt - '0'); - break; - } - - /* not field width: advance state to check if it's a modifier */ - - state++; - /* FALL THROUGH */ -/* STATE 3: AWAITING MODIFIER CHARS (FNlh) */ - case 3: - if (*fmt == 'F') - { - flags |= PR_FP; - break; - } - if (*fmt == 'N') - { - break; - } - if (*fmt == 'l') - { - flags |= PR_32; - break; - } - if (*fmt == 'h') - { - flags |= PR_16; - break; - } - - /* not modifier: advance state to check if it's a conversion char */ - - state++; - /* FALL THROUGH */ -/* STATE 4: AWAITING CONVERSION CHARS (Xxpndiuocs) */ - case 4: - where = buf + PR_BUFLEN - 1; - *where = '\0'; - - switch (*fmt) - { - case 'X': - flags |= PR_CA; - /* FALL THROUGH */ - /* xxx - far pointers (%Fp, %Fn) not yet supported */ - case 'x': - case 'p': - case 'n': - radix = 16; - goto DO_NUM; - - case 'd': - case 'i': - flags |= PR_SG; - /* FALL THROUGH */ - case 'u': - radix = 10; - goto DO_NUM; - - case 'o': - radix = 8; -DO_NUM: if (flags & PR_32) - { - /* load the value to be printed. l=long=32 bits: */ - num = va_arg(args, unsigned long); - } - else if (flags & PR_16) - { - /* h=short=16 bits (signed or unsigned) */ - - if (flags & PR_SG) - num = (short) va_arg(args, int); - else - num = (unsigned short) va_arg(args, int); - } - else - { - /* no h nor l: sizeof(int) bits (signed or unsigned) */ - - if (flags & PR_SG) - num = va_arg(args, int); - else - num = va_arg(args, unsigned int); - } - - if (flags & PR_SG) - { - /* take care of sign */ - - if (num < 0) - { - flags |= PR_WS; - num = -num; - } - } - - /* - * convert binary to octal/decimal/hex ASCII - * OK, I found my mistake. The math here is _always_ unsigned - */ - - do - { - unsigned long temp; - - temp = (unsigned long) num % radix; - where--; - - if (temp < 10) - *where = temp + '0'; - else if (flags & PR_CA) - *where = temp - 10 + 'A'; - else - *where = temp - 10 + 'a'; - - num = (unsigned long) num / radix; - } - while (num != 0); - - goto EMIT; - - case 'c': - /* disallow pad-left-with-zeroes for %c */ - flags &= ~PR_LZ; - where--; - *where = (unsigned char) va_arg(args, int); - actual_wd = 1; - goto EMIT2; - - case 's': - /* disallow pad-left-with-zeroes for %s */ - flags &= ~PR_LZ; - where = va_arg(args, unsigned char*); -EMIT: - actual_wd = strlen((char*) where); - - if (flags & PR_WS) - actual_wd++; - - /* if we pad left with ZEROES, do the sign now */ - - if ((flags & (PR_WS | PR_LZ)) == (PR_WS | PR_LZ)) - { - fn('-', &ptr); - count++; - } - - /* pad on left with spaces or zeroes (for right justify) */ - -EMIT2: if ((flags & PR_LJ) == 0) - { - while (given_wd > actual_wd) - { - fn((flags & PR_LZ) ? '0' : ' ', &ptr); - count++; - given_wd--; - } - } - - /* if we pad left with SPACES, do the sign now */ - - if ((flags & (PR_WS | PR_LZ)) == PR_WS) - { - fn('-', &ptr); - count++; - } - - /* emit string/char/converted number */ - - while (*where != '\0') - { - fn(*where++, &ptr); - count++; - } - - /* pad on right with spaces (for left justify) */ - - if (given_wd < actual_wd) - given_wd = 0; - else - given_wd -= actual_wd; - - for (; given_wd; given_wd--) - { - fn(' ', &ptr); - count++; - } - - break; - - default: - break; - } - - default: - state = flags = given_wd = 0; - break; - } - } - - return count; -} - -static int vsprintf_help(unsigned c, void **ptr) -{ - char *dst; - - dst = *ptr; - *dst++ = (char) c; - *ptr = dst; - - return 0; -} - -int wvsprintfx(char *buf, const char *fmt, va_list args) -{ - int status; - - status = do_printf(fmt, args, vsprintf_help, (void*) buf); - buf[status] = '\0'; - - return status; -} - -static int discard(unsigned c_UNUSED, void **ptr_UNUSED) -{ - return 0; -} - -int wsprintfx(char *buf, const char *fmt, ...) -{ - va_list args; - int status; - - va_start(args, fmt); - - if (!buf) - status = do_printf(fmt, args, discard, NULL); - else - status = wvsprintfx(buf, fmt, args); - - va_end(args); - - return status; -} - -int vprintf_help(unsigned c, void **ptr_UNUSED) -{ - putchar(c); - return 0; -} - int wvprintfx(const char *fmt, va_list args) { - return do_printf(fmt, args, vprintf_help, NULL); + return trio_vprintf(fmt, args); } int wprintfx(const char *fmt, ...) @@ -435,7 +71,7 @@ int wprintfx(const char *fmt, ...) int status; va_start(args, fmt); - status = wvprintfx(fmt, args); + status = trio_vprintf(fmt, args); va_end(args); return status; diff --git a/winpr/libwinpr/utils/stream.c b/winpr/libwinpr/utils/stream.c index 671bbcfb5..1dad2ec92 100644 --- a/winpr/libwinpr/utils/stream.c +++ b/winpr/libwinpr/utils/stream.c @@ -69,3 +69,94 @@ void Stream_Free(wStream* s, BOOL bFreeBuffer) free(s); } } + +/* Deprecated STREAM API */ + +/** + * Allocates and initializes a STREAM structure. + * STREAM are used to ease data access in read and write operations. + * They consist of a buffer containing the data we want to access, and an offset associated to it, and keeping + * track of the 'current' position in the stream. A list of functions can then be used to read/write different + * type of data to/from it. + * @see stream.h for the list of data access functions. + * + * @param size [in] - size of the buffer that will ba allocated to the stream. + * If 0, there will be no buffer attached to the stream. The caller + * then needs to call stream_attach() to link an existing buffer to this stream. + * Caution: calling stream_attach() on a stream with an existing buffer will result + * in this buffer being lost, and possible memory leak. + * + * @return A pointer to an allocated and initialized STREAM structure. + * This pointer need to be deallocated using the stream_free() function. + */ +wStream* stream_new(int size) +{ + wStream* stream; + + stream = malloc(sizeof(wStream)); + ZeroMemory(stream, sizeof(wStream)); + + if (stream != NULL) + { + if (size != 0) + { + size = size > 0 ? size : 0x400; + stream->buffer = (BYTE*) malloc(size); + ZeroMemory(stream->buffer, size); + stream->pointer = stream->buffer; + stream->capacity = size; + } + } + + return stream; +} + +/** + * This function is used to deallocate a stream that was allocated using stream_new(). + * Caution: the buffer linked to the stream will be deallocated in the process. If this buffer was attached + * using the stream_attach() function, the stream_detach() function needs to be called before calling stream_free() + * otherwise it will be freed in the process. + * + * @param stream [in] - Pointer to the STREAM structure that needs to be deallocated. + * This pointer is invalid on return. + */ +void stream_free(wStream* stream) +{ + if (stream != NULL) + { + if (stream->buffer != NULL) + free(stream->buffer); + + free(stream); + } +} + +/** + * This function is used to extend the size of an existing stream. + * It will infact extend the attached buffer, fill the newly allocated region with 0, and reset the current + * stream position. + * If the stream did not have a buffer attached, a new one will be allocated and attached. + * + * @param stream [in/out] pointer to the STREAM structure that needs to be extended. + * @param request_size [in] Number of bytes to add to the existing stream. + * If the value is < the existing size, then the existing size is doubled. + */ +void stream_extend(wStream* stream, int request_size) +{ + int pos; + int original_size; + int increased_size; + + pos = stream_get_pos(stream); + original_size = stream->capacity; + increased_size = (request_size > original_size ? request_size : original_size); + stream->capacity += increased_size; + + if (original_size == 0) + stream->buffer = (BYTE*) malloc(stream->capacity); + else + stream->buffer = (BYTE*) realloc(stream->buffer, stream->capacity); + + memset(stream->buffer + original_size, 0, increased_size); + stream_set_pos(stream, pos); +} diff --git a/winpr/libwinpr/utils/test/CMakeLists.txt b/winpr/libwinpr/utils/test/CMakeLists.txt index cf967be4b..307aae204 100644 --- a/winpr/libwinpr/utils/test/CMakeLists.txt +++ b/winpr/libwinpr/utils/test/CMakeLists.txt @@ -9,6 +9,7 @@ set(${MODULE_PREFIX}_TESTS TestPrint.c TestArrayList.c TestCmdLine.c + TestStreamPool.c TestMessageQueue.c TestMessagePipe.c) diff --git a/winpr/libwinpr/utils/test/TestPrint.c b/winpr/libwinpr/utils/test/TestPrint.c index 0d46f7718..0d35518e7 100644 --- a/winpr/libwinpr/utils/test/TestPrint.c +++ b/winpr/libwinpr/utils/test/TestPrint.c @@ -37,7 +37,7 @@ int TestPrint(int argc, char* argv[]) _printf("%d\n",b); _printf("%3d\n",b); _printf("%03d\n",b); - c = 15.3; d = c / 3; + c = 15.3f; d = c / 3; _printf("%3.2f\n",d); /** diff --git a/winpr/libwinpr/utils/test/TestStreamPool.c b/winpr/libwinpr/utils/test/TestStreamPool.c new file mode 100644 index 000000000..ab8a371e4 --- /dev/null +++ b/winpr/libwinpr/utils/test/TestStreamPool.c @@ -0,0 +1,101 @@ + +#include <winpr/crt.h> +#include <winpr/stream.h> +#include <winpr/collections.h> + +#define BUFFER_SIZE 16384 + +int TestStreamPool(int argc, char* argv[]) +{ + wStream* s[5]; + wStreamPool* pool; + + pool = StreamPool_New(TRUE, BUFFER_SIZE); + + s[0] = StreamPool_Take(pool, 0); + s[1] = StreamPool_Take(pool, 0); + s[2] = StreamPool_Take(pool, 0); + + printf("StreamPool: aSize: %d uSize: %d\n", pool->aSize, pool->uSize); + + Stream_Release(s[0]); + Stream_Release(s[1]); + Stream_Release(s[2]); + + printf("StreamPool: aSize: %d uSize: %d\n", pool->aSize, pool->uSize); + + s[3] = StreamPool_Take(pool, 0); + s[4] = StreamPool_Take(pool, 0); + + printf("StreamPool: aSize: %d uSize: %d\n", pool->aSize, pool->uSize); + + Stream_Release(s[3]); + Stream_Release(s[4]); + + printf("StreamPool: aSize: %d uSize: %d\n", pool->aSize, pool->uSize); + + s[2] = StreamPool_Take(pool, 0); + s[3] = StreamPool_Take(pool, 0); + s[4] = StreamPool_Take(pool, 0); + + printf("StreamPool: aSize: %d uSize: %d\n", pool->aSize, pool->uSize); + + Stream_AddRef(s[2]); + + Stream_AddRef(s[3]); + Stream_AddRef(s[3]); + + Stream_AddRef(s[4]); + Stream_AddRef(s[4]); + Stream_AddRef(s[4]); + + Stream_Release(s[2]); + Stream_Release(s[2]); + + Stream_Release(s[3]); + Stream_Release(s[3]); + Stream_Release(s[3]); + + Stream_Release(s[4]); + Stream_Release(s[4]); + Stream_Release(s[4]); + Stream_Release(s[4]); + + printf("StreamPool: aSize: %d uSize: %d\n", pool->aSize, pool->uSize); + + s[2] = StreamPool_Take(pool, 0); + s[3] = StreamPool_Take(pool, 0); + s[4] = StreamPool_Take(pool, 0); + + printf("StreamPool: aSize: %d uSize: %d\n", pool->aSize, pool->uSize); + + StreamPool_AddRef(pool, s[2]->buffer + 1024); + + StreamPool_AddRef(pool, s[3]->buffer + 1024); + StreamPool_AddRef(pool, s[3]->buffer + 1024 * 2); + + StreamPool_AddRef(pool, s[4]->buffer + 1024); + StreamPool_AddRef(pool, s[4]->buffer + 1024 * 2); + StreamPool_AddRef(pool, s[4]->buffer + 1024 * 3); + + printf("StreamPool: aSize: %d uSize: %d\n", pool->aSize, pool->uSize); + + StreamPool_Release(pool, s[2]->buffer + 2048); + StreamPool_Release(pool, s[2]->buffer + 2048 * 2); + + StreamPool_Release(pool, s[3]->buffer + 2048); + StreamPool_Release(pool, s[3]->buffer + 2048 * 2); + StreamPool_Release(pool, s[3]->buffer + 2048 * 3); + + StreamPool_Release(pool, s[4]->buffer + 2048); + StreamPool_Release(pool, s[4]->buffer + 2048 * 2); + StreamPool_Release(pool, s[4]->buffer + 2048 * 3); + StreamPool_Release(pool, s[4]->buffer + 2048 * 4); + + printf("StreamPool: aSize: %d uSize: %d\n", pool->aSize, pool->uSize); + + StreamPool_Free(pool); + + return 0; +} + diff --git a/winpr/libwinpr/utils/trio/strio.h b/winpr/libwinpr/utils/trio/strio.h new file mode 100644 index 000000000..d90cfcfd8 --- /dev/null +++ b/winpr/libwinpr/utils/trio/strio.h @@ -0,0 +1,73 @@ +/************************************************************************* + * + * $Id: strio.h,v 1.11 2001/12/27 17:29:20 breese Exp $ + * + * Copyright (C) 1998 Bjorn Reese and Daniel Stenberg. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF + * MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE AUTHORS AND + * CONTRIBUTORS ACCEPT NO RESPONSIBILITY IN ANY CONCEIVABLE MANNER. + * + ************************************************************************ + * + * This maintains backwards compatibility with the strio functions. + * + ************************************************************************/ + +#ifndef TRIO_STRIO_H +#define TRIO_STRIO_H + +#if !(defined(DEBUG) || defined(NDEBUG)) +# define NDEBUG +#endif +#include "triostr.h" + +enum { + STRIO_HASH_NONE = TRIO_HASH_NONE, + STRIO_HASH_PLAIN = TRIO_HASH_PLAIN, + STRIO_HASH_TWOSIGNED = TRIO_HASH_TWOSIGNED +}; + +#define StrAlloc(n) trio_create(n) +#define StrAppend(x,y) ((void)trio_append((x),(y)),(x)) +#define StrAppendMax(x,n,y) ((void)trio_append_max((x),(n),(y)),(x)) +#define StrContains(x,y) trio_contains((x),(y)) +#define StrCopy(x,y) ((void)trio_copy((x),(y)),(x)) +#define StrCopyMax(x,n,y) ((void)trio_copy_max((x),(n),(y)),(x)) +#define StrDuplicate(x) trio_duplicate(x) +#define StrDuplicateMax(x,n) trio_duplicate((x),(n)) +#define StrEqual(x,y) trio_equal((x),(y)) +#define StrEqualCase(x,y) trio_equal_case((x),(y)) +#define StrEqualCaseMax(x,n,y) trio_equal_case_max((x),(n),(y)) +#define StrEqualLocale(x,y) trio_equal_locale((x),(y)) +#define StrEqualMax(x,n,y) trio_equal_max((x),(n),(y)) +#define StrError(n) trio_error(n) +#define StrFree(x) trio_destroy(x) +#define StrFormat trio_sprintf +#define StrFormatAlloc trio_aprintf +#define StrFormatAppendMax trio_snprintfcat +#define StrFormatDateMax(x,n,y,t) trio_format_date_max((x),(n),(y),(t)) +#define StrFormatMax trio_snprintf +#define StrHash(x,n) trio_hash((x),(n)) +#define StrIndex(x,y) trio_index((x),(y)) +#define StrIndexLast(x,y) trio_index_last((x),(y)) +#define StrLength(x) trio_length((x)) +#define StrMatch(x,y) trio_match((x),(y)) +#define StrMatchCase(x,y) trio_match_case((x),(y)) +#define StrScan trio_sscanf +#define StrSpanFunction(x,f) trio_span_function((x),(f)) +#define StrSubstring(x,y) trio_substring((x),(y)) +#define StrSubstringMax(x,n,y) trio_substring_max((x),(n),(y)) +#define StrToDouble(x,y) trio_to_double((x),(y)) +#define StrToFloat(x,y) trio_to_float((x),(y)) +#define StrTokenize(x,y) trio_tokenize((x),(y)) +#define StrToLong(x,y,n) trio_to_long((x),(y),(n)) +#define StrToUnsignedLong(x,y,n) trio_to_unsigned_long((x),(n),(y)) +#define StrToUpper(x) trio_upper(x) + +#endif /* TRIO_STRIO_H */ diff --git a/winpr/libwinpr/utils/trio/trio.c b/winpr/libwinpr/utils/trio/trio.c new file mode 100644 index 000000000..55eb76458 --- /dev/null +++ b/winpr/libwinpr/utils/trio/trio.c @@ -0,0 +1,7857 @@ +/************************************************************************* + * + * $Id: trio.c,v 1.131 2010/09/12 11:08:08 breese Exp $ + * + * Copyright (C) 1998, 2009 Bjorn Reese and Daniel Stenberg. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF + * MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE AUTHORS AND + * CONTRIBUTORS ACCEPT NO RESPONSIBILITY IN ANY CONCEIVABLE MANNER. + * + ************************************************************************* + * + * A note to trio contributors: + * + * Avoid heap allocation at all costs to ensure that the trio functions + * are async-safe. The exceptions are the printf/fprintf functions, which + * uses fputc, and the asprintf functions and the <alloc> modifier, which + * by design are required to allocate form the heap. + * + ************************************************************************/ + +/* + * TODO: + * - Scan is probably too permissive about its modifiers. + * - C escapes in %#[] ? + * - Multibyte characters (done for format parsing, except scan groups) + * - Complex numbers? (C99 _Complex) + * - Boolean values? (C99 _Bool) + * - C99 NaN(n-char-sequence) missing. The n-char-sequence can be used + * to print the mantissa, e.g. NaN(0xc000000000000000) + * - Should we support the GNU %a alloc modifier? GNU has an ugly hack + * for %a, because C99 used %a for other purposes. If specified as + * %as or %a[ it is interpreted as the alloc modifier, otherwise as + * the C99 hex-float. This means that you cannot scan %as as a hex-float + * immediately followed by an 's'. + * - Scanning of collating symbols. + */ + +/************************************************************************* + * Trio include files + */ +#include "triodef.h" +#include "trio.h" +#include "triop.h" + +#if defined(TRIO_EMBED_NAN) +# define TRIO_PUBLIC_NAN static +# if TRIO_FEATURE_FLOAT +# define TRIO_FUNC_NAN +# define TRIO_FUNC_NINF +# define TRIO_FUNC_PINF +# define TRIO_FUNC_FPCLASSIFY_AND_SIGNBIT +# define TRIO_FUNC_ISINF +# endif +#endif +#include "trionan.h" + +#if defined(TRIO_EMBED_STRING) +# define TRIO_PUBLIC_STRING static +# define TRIO_FUNC_LENGTH +# define TRIO_FUNC_LENGTH_MAX +# define TRIO_FUNC_TO_LONG +# if TRIO_FEATURE_LOCALE +# define TRIO_FUNC_COPY_MAX +# endif +# if TRIO_FEATURE_DYNAMICSTRING +# define TRIO_FUNC_XSTRING_DUPLICATE +# endif +# if TRIO_EXTENSION && TRIO_FEATURE_SCANF +# define TRIO_FUNC_EQUAL_LOCALE +# endif +# if TRIO_FEATURE_ERRNO +# define TRIO_FUNC_ERROR +# endif +# if TRIO_FEATURE_FLOAT && TRIO_FEATURE_SCANF +# define TRIO_FUNC_TO_DOUBLE +# endif +# if TRIO_FEATURE_DYNAMICSTRING +# define TRIO_FUNC_STRING_EXTRACT +# endif +# if TRIO_FEATURE_DYNAMICSTRING +# define TRIO_FUNC_STRING_TERMINATE +# endif +# if TRIO_FEATURE_USER_DEFINED +# define TRIO_FUNC_DUPLICATE +# endif +# if TRIO_FEATURE_DYNAMICSTRING +# define TRIO_FUNC_STRING_DESTROY +# endif +# if TRIO_FEATURE_USER_DEFINED +# define TRIO_FUNC_DESTROY +# endif +# if TRIO_FEATURE_USER_DEFINED || (TRIO_FEATURE_FLOAT && TRIO_FEATURE_SCANF) +# define TRIO_FUNC_EQUAL +# endif +# if TRIO_FEATURE_USER_DEFINED || TRIO_FEATURE_SCANF +# define TRIO_FUNC_EQUAL_CASE +# endif +# if (TRIO_EXTENSION && TRIO_FEATURE_SCANF) +# define TRIO_FUNC_EQUAL_MAX +# endif +# if TRIO_FEATURE_SCANF +# define TRIO_FUNC_TO_UPPER +# endif +# if TRIO_FEATURE_DYNAMICSTRING +# define TRIO_FUNC_XSTRING_APPEND_CHAR +# endif +#endif +#include "triostr.h" + +/************************************************************************** + * + * Definitions + * + *************************************************************************/ + +#include <limits.h> +#if TRIO_FEATURE_FLOAT +# include <math.h> +# include <float.h> +#endif + +#if defined(__STDC_ISO_10646__) || defined(MB_LEN_MAX) || defined(USE_MULTIBYTE) || TRIO_FEATURE_WIDECHAR +# if (!defined(TRIO_PLATFORM_WINCE) && !defined(ANDROID)) +# define TRIO_COMPILER_SUPPORTS_MULTIBYTE +# if !defined(MB_LEN_MAX) +# define MB_LEN_MAX 6 +# endif +# endif +#endif + +#if (TRIO_COMPILER_VISUALC - 0 >= 1100) || defined(TRIO_COMPILER_BORLAND) +# define TRIO_COMPILER_SUPPORTS_VISUALC_INT +#endif + +#if TRIO_FEATURE_FLOAT +# if defined(PREDEF_STANDARD_C99) \ + || defined(PREDEF_STANDARD_UNIX03) +# if !defined(HAVE_FLOORL) && !defined(TRIO_NO_FLOORL) +# define HAVE_FLOORL +# endif +# if !defined(HAVE_CEILL) && !defined(TRIO_NO_CEILL) +# define HAVE_CEILL +# endif +# if !defined(HAVE_POWL) && !defined(TRIO_NO_POWL) +# define HAVE_POWL +# endif +# if !defined(HAVE_FMODL) && !defined(TRIO_NO_FMODL) +# define HAVE_FMODL +# endif +# if !defined(HAVE_LOG10L) && !defined(TRIO_NO_LOG10L) +# define HAVE_LOG10L +# endif +# endif +# if defined(TRIO_COMPILER_VISUALC) +# if defined(floorl) +# define HAVE_FLOORL +# endif +# if defined(ceill) +# define HAVE_CEILL +# endif +# if defined(powl) +# define HAVE_POWL +# endif +# if defined(fmodl) +# define HAVE_FMODL +# endif +# if defined(log10l) +# define HAVE_LOG10L +# endif +# endif +#endif + +/************************************************************************* + * Generic definitions + */ + +#if !(defined(DEBUG) || defined(NDEBUG)) +# define NDEBUG +#endif + +#include <assert.h> +#include <ctype.h> +#if defined(PREDEF_STANDARD_C99) && !defined(isascii) +# define isascii(x) ((x) & 0x7F) +#endif +#if defined(TRIO_COMPILER_ANCIENT) +# include <varargs.h> +#else +# include <stdarg.h> +#endif +#include <stddef.h> +#if defined(TRIO_PLATFORM_WINCE) +extern int errno; +#else +# include <errno.h> +#endif + +#ifndef NULL +# define NULL 0 +#endif +#define NIL ((char)0) +#ifndef FALSE +# define FALSE (1 == 0) +# define TRUE (! FALSE) +#endif +#define BOOLEAN_T int + +/* mincore() can be used for debugging purposes */ +#define VALID(x) (NULL != (x)) + +#if TRIO_FEATURE_ERRORCODE + /* + * Encode the error code and the position. This is decoded + * with TRIO_ERROR_CODE and TRIO_ERROR_POSITION. + */ +# define TRIO_ERROR_RETURN(x,y) (- ((x) + ((y) << 8))) +#else +# define TRIO_ERROR_RETURN(x,y) (-1) +#endif + +typedef unsigned long trio_flags_t; + + +/************************************************************************* + * Platform specific definitions + */ +#if defined(TRIO_PLATFORM_UNIX) +# include <unistd.h> +# include <signal.h> +# include <locale.h> +# if !defined(TRIO_FEATURE_LOCALE) +# define USE_LOCALE +# endif +#endif /* TRIO_PLATFORM_UNIX */ +#if defined(TRIO_PLATFORM_VMS) +# include <unistd.h> +#endif +#if defined(TRIO_PLATFORM_WIN32) +# if defined(TRIO_PLATFORM_WINCE) +int read(int handle, char *buffer, unsigned int length); +int write(int handle, const char *buffer, unsigned int length); +# else +# include <io.h> +# define read _read +# define write _write +# endif +#endif /* TRIO_PLATFORM_WIN32 */ + +#if TRIO_FEATURE_WIDECHAR +# if defined(PREDEF_STANDARD_C94) +# include <wchar.h> +# include <wctype.h> +typedef wchar_t trio_wchar_t; +typedef wint_t trio_wint_t; +# else +typedef char trio_wchar_t; +typedef int trio_wint_t; +# define WCONST(x) L ## x +# define WEOF EOF +# define iswalnum(x) isalnum(x) +# define iswalpha(x) isalpha(x) +# define iswcntrl(x) iscntrl(x) +# define iswdigit(x) isdigit(x) +# define iswgraph(x) isgraph(x) +# define iswlower(x) islower(x) +# define iswprint(x) isprint(x) +# define iswpunct(x) ispunct(x) +# define iswspace(x) isspace(x) +# define iswupper(x) isupper(x) +# define iswxdigit(x) isxdigit(x) +# endif +#endif + + +/************************************************************************* + * Compiler dependent definitions + */ + +/* Support for long long */ +#ifndef __cplusplus +# if !defined(USE_LONGLONG) +# if defined(TRIO_COMPILER_GCC) && !defined(__STRICT_ANSI__) +# define USE_LONGLONG +# else +# if defined(TRIO_COMPILER_SUNPRO) +# define USE_LONGLONG +# else +# if defined(TRIO_COMPILER_MSVC) && (_MSC_VER >= 1400) +# define USE_LONGLONG +# else +# if defined(_LONG_LONG) || defined(_LONGLONG) +# define USE_LONGLONG +# endif +# endif +# endif +# endif +# endif +#endif + +/* The extra long numbers */ +#if defined(USE_LONGLONG) +typedef signed long long int trio_longlong_t; +typedef unsigned long long int trio_ulonglong_t; +#else +# if defined(TRIO_COMPILER_SUPPORTS_VISUALC_INT) +typedef signed __int64 trio_longlong_t; +typedef unsigned __int64 trio_ulonglong_t; +# else +typedef TRIO_SIGNED long int trio_longlong_t; +typedef unsigned long int trio_ulonglong_t; +# endif +#endif + +/* Maximal and fixed integer types */ +#if defined(PREDEF_STANDARD_C99) +# include <stdint.h> +typedef intmax_t trio_intmax_t; +typedef uintmax_t trio_uintmax_t; +typedef int8_t trio_int8_t; +typedef int16_t trio_int16_t; +typedef int32_t trio_int32_t; +typedef int64_t trio_int64_t; +#else +# if defined(PREDEF_STANDARD_UNIX98) +# include <inttypes.h> +typedef intmax_t trio_intmax_t; +typedef uintmax_t trio_uintmax_t; +typedef int8_t trio_int8_t; +typedef int16_t trio_int16_t; +typedef int32_t trio_int32_t; +typedef int64_t trio_int64_t; +# else +# if defined(TRIO_COMPILER_SUPPORTS_VISUALC_INT) +typedef trio_longlong_t trio_intmax_t; +typedef trio_ulonglong_t trio_uintmax_t; +typedef __int8 trio_int8_t; +typedef __int16 trio_int16_t; +typedef __int32 trio_int32_t; +typedef __int64 trio_int64_t; +# else +typedef trio_longlong_t trio_intmax_t; +typedef trio_ulonglong_t trio_uintmax_t; +# if defined(TRIO_INT8_T) +typedef TRIO_INT8_T trio_int8_t; +# else +typedef TRIO_SIGNED char trio_int8_t; +# endif +# if defined(TRIO_INT16_T) +typedef TRIO_INT16_T trio_int16_t; +# else +typedef TRIO_SIGNED short trio_int16_t; +# endif +# if defined(TRIO_INT32_T) +typedef TRIO_INT32_T trio_int32_t; +# else +typedef TRIO_SIGNED int trio_int32_t; +# endif +# if defined(TRIO_INT64_T) +typedef TRIO_INT64_T trio_int64_t; +# else +typedef trio_longlong_t trio_int64_t; +# endif +# endif +# endif +#endif + +#if defined(HAVE_FLOORL) +# define trio_floor(x) floorl((x)) +#else +# define trio_floor(x) floor((double)(x)) +#endif + +#if defined(HAVE_CEILL) +# define trio_ceil(x) ceill((x)) +#else +# define trio_ceil(x) ceil((double)(x)) +#endif + +#if defined(HAVE_FMODL) +# define trio_fmod(x,y) fmodl((x),(y)) +#else +# define trio_fmod(x,y) fmod((double)(x),(double)(y)) +#endif + +#if defined(HAVE_POWL) +# define trio_pow(x,y) powl((x),(y)) +#else +# define trio_pow(x,y) pow((double)(x),(double)(y)) +#endif + +#if defined(HAVE_LOG10L) +# define trio_log10(x) log10l((x)) +#else +# define trio_log10(x) log10((double)(x)) +#endif + +#if TRIO_FEATURE_FLOAT +# define TRIO_FABS(x) (((x) < 0.0) ? -(x) : (x)) +#endif + +/************************************************************************* + * Internal Definitions + */ + +#ifdef _WIN32 +#pragma warning(push) +#pragma warning(disable: 4244) +#endif + +#if TRIO_FEATURE_FLOAT + +# if !defined(DECIMAL_DIG) +# define DECIMAL_DIG DBL_DIG +# endif + +/* Long double sizes */ +# ifdef LDBL_DIG +# define MAX_MANTISSA_DIGITS LDBL_DIG +# define MAX_EXPONENT_DIGITS 4 +# define MAX_DOUBLE_DIGITS LDBL_MAX_10_EXP +# else +# define MAX_MANTISSA_DIGITS DECIMAL_DIG +# define MAX_EXPONENT_DIGITS 3 +# define MAX_DOUBLE_DIGITS DBL_MAX_10_EXP +# endif + +# if defined(TRIO_COMPILER_ANCIENT) || !defined(LDBL_DIG) +# undef LDBL_DIG +# undef LDBL_MANT_DIG +# undef LDBL_EPSILON +# define LDBL_DIG DBL_DIG +# define LDBL_MANT_DIG DBL_MANT_DIG +# define LDBL_EPSILON DBL_EPSILON +# endif + +#endif /* TRIO_FEATURE_FLOAT */ + +/* The maximal number of digits is for base 2 */ +#define MAX_CHARS_IN(x) (sizeof(x) * CHAR_BIT) +/* The width of a pointer. The number of bits in a hex digit is 4 */ +#define POINTER_WIDTH ((sizeof("0x") - 1) + sizeof(trio_pointer_t) * CHAR_BIT / 4) + +#if TRIO_FEATURE_FLOAT +/* Infinite and Not-A-Number for floating-point */ +# define INFINITE_LOWER "inf" +# define INFINITE_UPPER "INF" +# define LONG_INFINITE_LOWER "infinite" +# define LONG_INFINITE_UPPER "INFINITE" +# define NAN_LOWER "nan" +# define NAN_UPPER "NAN" +#endif + +/* Various constants */ +enum { + TYPE_PRINT = 1, +#if TRIO_FEATURE_SCANF + TYPE_SCAN = 2, +#endif + + /* Flags. FLAGS_LAST must be less than ULONG_MAX */ + FLAGS_NEW = 0, + FLAGS_STICKY = 1, + FLAGS_SPACE = 2 * FLAGS_STICKY, + FLAGS_SHOWSIGN = 2 * FLAGS_SPACE, + FLAGS_LEFTADJUST = 2 * FLAGS_SHOWSIGN, + FLAGS_ALTERNATIVE = 2 * FLAGS_LEFTADJUST, + FLAGS_SHORT = 2 * FLAGS_ALTERNATIVE, + FLAGS_SHORTSHORT = 2 * FLAGS_SHORT, + FLAGS_LONG = 2 * FLAGS_SHORTSHORT, + FLAGS_QUAD = 2 * FLAGS_LONG, + FLAGS_LONGDOUBLE = 2 * FLAGS_QUAD, + FLAGS_SIZE_T = 2 * FLAGS_LONGDOUBLE, + FLAGS_PTRDIFF_T = 2 * FLAGS_SIZE_T, + FLAGS_INTMAX_T = 2 * FLAGS_PTRDIFF_T, + FLAGS_NILPADDING = 2 * FLAGS_INTMAX_T, + FLAGS_UNSIGNED = 2 * FLAGS_NILPADDING, + FLAGS_UPPER = 2 * FLAGS_UNSIGNED, + FLAGS_WIDTH = 2 * FLAGS_UPPER, + FLAGS_WIDTH_PARAMETER = 2 * FLAGS_WIDTH, + FLAGS_PRECISION = 2 * FLAGS_WIDTH_PARAMETER, + FLAGS_PRECISION_PARAMETER = 2 * FLAGS_PRECISION, + FLAGS_BASE = 2 * FLAGS_PRECISION_PARAMETER, + FLAGS_BASE_PARAMETER = 2 * FLAGS_BASE, + FLAGS_FLOAT_E = 2 * FLAGS_BASE_PARAMETER, + FLAGS_FLOAT_G = 2 * FLAGS_FLOAT_E, + FLAGS_QUOTE = 2 * FLAGS_FLOAT_G, + FLAGS_WIDECHAR = 2 * FLAGS_QUOTE, + FLAGS_IGNORE = 2 * FLAGS_WIDECHAR, + FLAGS_IGNORE_PARAMETER = 2 * FLAGS_IGNORE, + FLAGS_VARSIZE_PARAMETER = 2 * FLAGS_IGNORE_PARAMETER, + FLAGS_FIXED_SIZE = 2 * FLAGS_VARSIZE_PARAMETER, + FLAGS_LAST = FLAGS_FIXED_SIZE, + /* Reused flags */ + FLAGS_EXCLUDE = FLAGS_SHORT, + FLAGS_USER_DEFINED = FLAGS_IGNORE, + FLAGS_USER_DEFINED_PARAMETER = FLAGS_IGNORE_PARAMETER, + FLAGS_ROUNDING = FLAGS_INTMAX_T, + /* Compounded flags */ + FLAGS_ALL_VARSIZES = FLAGS_LONG | FLAGS_QUAD | FLAGS_INTMAX_T | FLAGS_PTRDIFF_T | FLAGS_SIZE_T, + FLAGS_ALL_SIZES = FLAGS_ALL_VARSIZES | FLAGS_SHORTSHORT | FLAGS_SHORT, + + NO_POSITION = -1, + NO_WIDTH = 0, + NO_PRECISION = -1, + NO_SIZE = -1, + + /* Do not change these */ + NO_BASE = -1, + MIN_BASE = 2, + MAX_BASE = 36, + BASE_BINARY = 2, + BASE_OCTAL = 8, + BASE_DECIMAL = 10, + BASE_HEX = 16, + + /* Maximal number of allowed parameters */ + MAX_PARAMETERS = 64, + /* Maximal number of characters in class */ + MAX_CHARACTER_CLASS = UCHAR_MAX + 1, + +#if TRIO_FEATURE_USER_DEFINED + /* Maximal string lengths for user-defined specifiers */ + MAX_USER_NAME = 64, + MAX_USER_DATA = 256, +#endif + + /* Maximal length of locale separator strings */ + MAX_LOCALE_SEPARATOR_LENGTH = MB_LEN_MAX, + /* Maximal number of integers in grouping */ + MAX_LOCALE_GROUPS = 64 +}; + +#define NO_GROUPING ((int)CHAR_MAX) + +/* Fundamental formatting parameter types */ +#define FORMAT_SENTINEL -1 /* marks end of parameters array */ +#define FORMAT_UNKNOWN 0 +#define FORMAT_INT 1 +#define FORMAT_DOUBLE 2 +#define FORMAT_CHAR 3 +#define FORMAT_STRING 4 +#define FORMAT_POINTER 5 +#define FORMAT_COUNT 6 +#define FORMAT_PARAMETER 7 +#define FORMAT_GROUP 8 +#define FORMAT_ERRNO 9 +#define FORMAT_USER_DEFINED 10 + +/* Character constants */ +#define CHAR_IDENTIFIER '%' +#define CHAR_ALT_IDENTIFIER '$' +#define CHAR_BACKSLASH '\\' +#define CHAR_QUOTE '\"' +#define CHAR_ADJUST ' ' + +#if TRIO_EXTENSION +/* Character class expressions */ +# define CLASS_ALNUM "[:alnum:]" +# define CLASS_ALPHA "[:alpha:]" +# define CLASS_BLANK "[:blank:]" +# define CLASS_CNTRL "[:cntrl:]" +# define CLASS_DIGIT "[:digit:]" +# define CLASS_GRAPH "[:graph:]" +# define CLASS_LOWER "[:lower:]" +# define CLASS_PRINT "[:print:]" +# define CLASS_PUNCT "[:punct:]" +# define CLASS_SPACE "[:space:]" +# define CLASS_UPPER "[:upper:]" +# define CLASS_XDIGIT "[:xdigit:]" +#endif + +/* + * SPECIFIERS: + * + * + * a Hex-float + * A Hex-float + * c Character + * C Widechar character (wint_t) + * d Decimal + * e Float + * E Float + * F Float + * F Float + * g Float + * G Float + * i Integer + * m Error message + * n Count + * o Octal + * p Pointer + * s String + * S Widechar string (wchar_t *) + * u Unsigned + * x Hex + * X Hex + * [] Group + * <> User-defined + * + * Reserved: + * + * D Binary Coded Decimal %D(length,precision) (OS/390) + */ +#define SPECIFIER_CHAR 'c' +#define SPECIFIER_STRING 's' +#define SPECIFIER_DECIMAL 'd' +#define SPECIFIER_INTEGER 'i' +#define SPECIFIER_UNSIGNED 'u' +#define SPECIFIER_OCTAL 'o' +#define SPECIFIER_HEX 'x' +#define SPECIFIER_HEX_UPPER 'X' +#if TRIO_FEATURE_FLOAT +# define SPECIFIER_FLOAT_E 'e' +# define SPECIFIER_FLOAT_E_UPPER 'E' +# define SPECIFIER_FLOAT_F 'f' +# define SPECIFIER_FLOAT_F_UPPER 'F' +# define SPECIFIER_FLOAT_G 'g' +# define SPECIFIER_FLOAT_G_UPPER 'G' +#endif +#define SPECIFIER_POINTER 'p' +#if TRIO_FEATURE_SCANF +# define SPECIFIER_GROUP '[' +# define SPECIFIER_UNGROUP ']' +#endif +#define SPECIFIER_COUNT 'n' +#if TRIO_UNIX98 +# define SPECIFIER_CHAR_UPPER 'C' +# define SPECIFIER_STRING_UPPER 'S' +#endif +#define SPECIFIER_HEXFLOAT 'a' +#define SPECIFIER_HEXFLOAT_UPPER 'A' +#define SPECIFIER_ERRNO 'm' +#if TRIO_FEATURE_BINARY +# define SPECIFIER_BINARY 'b' +# define SPECIFIER_BINARY_UPPER 'B' +#endif +#if TRIO_FEATURE_USER_DEFINED +# define SPECIFIER_USER_DEFINED_BEGIN '<' +# define SPECIFIER_USER_DEFINED_END '>' +# define SPECIFIER_USER_DEFINED_SEPARATOR ':' +# define SPECIFIER_USER_DEFINED_EXTRA '|' +#endif + +/* + * QUALIFIERS: + * + * + * Numbers = d,i,o,u,x,X + * Float = a,A,e,E,f,F,g,G + * String = s + * Char = c + * + * + * 9$ Position + * Use the 9th parameter. 9 can be any number between 1 and + * the maximal argument + * + * 9 Width + * Set width to 9. 9 can be any number, but must not be postfixed + * by '$' + * + * h Short + * Numbers: + * (unsigned) short int + * + * hh Short short + * Numbers: + * (unsigned) char + * + * l Long + * Numbers: + * (unsigned) long int + * String: + * as the S specifier + * Char: + * as the C specifier + * + * ll Long Long + * Numbers: + * (unsigned) long long int + * + * L Long Double + * Float + * long double + * + * # Alternative + * Float: + * Decimal-point is always present + * String: + * non-printable characters are handled as \number + * + * Spacing + * + * + Sign + * + * - Alignment + * + * . Precision + * + * * Parameter + * print: use parameter + * scan: no parameter (ignore) + * + * q Quad + * + * Z size_t + * + * w Widechar + * + * ' Thousands/quote + * Numbers: + * Integer part grouped in thousands + * Binary numbers: + * Number grouped in nibbles (4 bits) + * String: + * Quoted string + * + * j intmax_t + * t prtdiff_t + * z size_t + * + * ! Sticky + * @ Parameter (for both print and scan) + * + * I n-bit Integer + * Numbers: + * The following options exists + * I8 = 8-bit integer + * I16 = 16-bit integer + * I32 = 32-bit integer + * I64 = 64-bit integer + */ +#define QUALIFIER_POSITION '$' +#define QUALIFIER_SHORT 'h' +#define QUALIFIER_LONG 'l' +#define QUALIFIER_LONG_UPPER 'L' +#define QUALIFIER_ALTERNATIVE '#' +#define QUALIFIER_SPACE ' ' +#define QUALIFIER_PLUS '+' +#define QUALIFIER_MINUS '-' +#define QUALIFIER_DOT '.' +#define QUALIFIER_STAR '*' +#define QUALIFIER_CIRCUMFLEX '^' /* For scanlists */ +#define QUALIFIER_SIZE_T 'z' +#define QUALIFIER_PTRDIFF_T 't' +#define QUALIFIER_INTMAX_T 'j' +#define QUALIFIER_QUAD 'q' +#define QUALIFIER_SIZE_T_UPPER 'Z' +#if TRIO_MISC +# define QUALIFIER_WIDECHAR 'w' +#endif +#define QUALIFIER_FIXED_SIZE 'I' +#define QUALIFIER_QUOTE '\'' +#define QUALIFIER_STICKY '!' +#define QUALIFIER_VARSIZE '&' /* This should remain undocumented */ +#define QUALIFIER_ROUNDING_UPPER 'R' +#if TRIO_EXTENSION +# define QUALIFIER_PARAM '@' /* Experimental */ +# define QUALIFIER_COLON ':' /* For scanlists */ +# define QUALIFIER_EQUAL '=' /* For scanlists */ +#endif + + +/************************************************************************* + * + * Internal Structures + * + *************************************************************************/ + +/* Parameters */ +typedef struct { + /* An indication of which entry in the data union is used */ + int type; + /* The flags */ + trio_flags_t flags; + /* The width qualifier */ + int width; + /* The precision qualifier */ + int precision; + /* The base qualifier */ + int base; + /* Base from specifier */ + int baseSpecifier; + /* The size for the variable size qualifier */ + int varsize; + /* Offset of the first character of the specifier */ + int beginOffset; + /* Offset of the first character after the specifier */ + int endOffset; + /* Position in the argument list that this parameter refers to */ + int position; + /* The data from the argument list */ + union { + char *string; +#if TRIO_FEATURE_WIDECHAR + trio_wchar_t *wstring; +#endif + trio_pointer_t pointer; + union { + trio_intmax_t as_signed; + trio_uintmax_t as_unsigned; + } number; +#if TRIO_FEATURE_FLOAT + double doubleNumber; + double *doublePointer; + trio_long_double_t longdoubleNumber; + trio_long_double_t *longdoublePointer; +#endif + int errorNumber; + } data; +#if TRIO_FEATURE_USER_DEFINED + /* For the user-defined specifier */ + union { + char namespace[MAX_USER_NAME]; + int handler; /* if flags & FLAGS_USER_DEFINED_PARAMETER */ + } user_defined; + char user_data[MAX_USER_DATA]; +#endif +} trio_parameter_t; + +/* Container for customized functions */ +typedef struct { + union { + trio_outstream_t out; + trio_instream_t in; + } stream; + trio_pointer_t closure; +} trio_custom_t; + +/* General trio "class" */ +typedef struct _trio_class_t { + /* + * The function to write characters to a stream. + */ + void (*OutStream) TRIO_PROTO((struct _trio_class_t *, int)); + /* + * The function to read characters from a stream. + */ + void (*InStream) TRIO_PROTO((struct _trio_class_t *, int *)); + /* + * The function to undo read characters from a stream. + */ + void (*UndoStream) TRIO_PROTO((struct _trio_class_t *)); + /* + * The current location in the stream. + */ + trio_pointer_t location; + /* + * The character currently being processed. + */ + int current; + /* + * The number of characters that would have been written/read + * if there had been sufficient space. + */ + int processed; + union { + /* + * The number of characters that are actually written. Processed and + * committed will only differ for the *nprintf functions. + */ + int committed; + /* + * The number of look-ahead characters read. + */ + int cached; + } actually; + /* + * The upper limit of characters that may be written/read. + */ + int max; + /* + * The last output error that was detected. + */ + int error; +} trio_class_t; + +/* References (for user-defined callbacks) */ +typedef struct _trio_reference_t { + trio_class_t *data; + trio_parameter_t *parameter; +} trio_reference_t; + +#if TRIO_FEATURE_USER_DEFINED +/* Registered entries (for user-defined callbacks) */ +typedef struct _trio_userdef_t { + struct _trio_userdef_t *next; + trio_callback_t callback; + char *name; +} trio_userdef_t; +#endif + +/************************************************************************* + * + * Internal Variables + * + *************************************************************************/ + +static TRIO_CONST char rcsid[] = "@(#)$Id: trio.c,v 1.131 2010/09/12 11:08:08 breese Exp $"; + +#if TRIO_FEATURE_FLOAT +/* + * Need this to workaround a parser bug in HP C/iX compiler that fails + * to resolves macro definitions that includes type 'long double', + * e.g: va_arg(arg_ptr, long double) + */ +# if defined(TRIO_PLATFORM_MPEIX) +static TRIO_CONST trio_long_double_t ___dummy_long_double = 0; +# endif +#endif + +static TRIO_CONST char internalNullString[] = "(nil)"; + +#if defined(USE_LOCALE) +static struct lconv *internalLocaleValues = NULL; +#endif + +/* + * UNIX98 says "in a locale where the radix character is not defined, + * the radix character defaults to a period (.)" + */ +#if TRIO_FEATURE_FLOAT || TRIO_FEATURE_LOCALE || defined(USE_LOCALE) +static int internalDecimalPointLength = 1; +static char internalDecimalPoint = '.'; +static char internalDecimalPointString[MAX_LOCALE_SEPARATOR_LENGTH + 1] = "."; +#endif +#if TRIO_FEATURE_QUOTE || TRIO_FEATURE_LOCALE || TRIO_EXTENSION +static int internalThousandSeparatorLength = 1; +static char internalThousandSeparator[MAX_LOCALE_SEPARATOR_LENGTH + 1] = ","; +static char internalGrouping[MAX_LOCALE_GROUPS] = { (char)NO_GROUPING }; +#endif + +static TRIO_CONST char internalDigitsLower[] = "0123456789abcdefghijklmnopqrstuvwxyz"; +static TRIO_CONST char internalDigitsUpper[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; +#if TRIO_FEATURE_SCANF +static BOOLEAN_T internalDigitsUnconverted = TRUE; +static int internalDigitArray[128]; +# if TRIO_EXTENSION +static BOOLEAN_T internalCollationUnconverted = TRUE; +static char internalCollationArray[MAX_CHARACTER_CLASS][MAX_CHARACTER_CLASS]; +# endif +#endif + +#if TRIO_FEATURE_USER_DEFINED +static TRIO_VOLATILE trio_callback_t internalEnterCriticalRegion = NULL; +static TRIO_VOLATILE trio_callback_t internalLeaveCriticalRegion = NULL; +static trio_userdef_t *internalUserDef = NULL; +#endif + + +/************************************************************************* + * + * Internal Functions + * + ************************************************************************/ + +#if defined(TRIO_EMBED_NAN) +# include "trionan.c" +#endif + +#if defined(TRIO_EMBED_STRING) +# include "triostr.c" +#endif + +/************************************************************************* + * TrioInitializeParameter + * + * Description: + * Initialize a trio_parameter_t struct. + */ +TRIO_PRIVATE void +TrioInitializeParameter +TRIO_ARGS1((parameter), + trio_parameter_t *parameter) +{ + parameter->type = FORMAT_UNKNOWN; + parameter->flags = 0; + parameter->width = 0; + parameter->precision = 0; + parameter->base = 0; + parameter->baseSpecifier = 0; + parameter->varsize = 0; + parameter->beginOffset = 0; + parameter->endOffset = 0; + parameter->position = 0; + parameter->data.pointer = 0; +#if TRIO_FEATURE_USER_DEFINED + parameter->user_defined.handler = 0; + parameter->user_data[0] = 0; +#endif +} + +/************************************************************************* + * TrioCopyParameter + * + * Description: + * Copies one trio_parameter_t struct to another. + */ +TRIO_PRIVATE void +TrioCopyParameter +TRIO_ARGS2((target, source), + trio_parameter_t *target, + TRIO_CONST trio_parameter_t *source) +{ +#if TRIO_FEATURE_USER_DEFINED + size_t i; +#endif + + target->type = source->type; + target->flags = source->flags; + target->width = source->width; + target->precision = source->precision; + target->base = source->base; + target->baseSpecifier = source->baseSpecifier; + target->varsize = source->varsize; + target->beginOffset = source->beginOffset; + target->endOffset = source->endOffset; + target->position = source->position; + target->data = source->data; + +#if TRIO_FEATURE_USER_DEFINED + target->user_defined = source->user_defined; + + for (i = 0U; i < sizeof(target->user_data); ++i) + { + if ((target->user_data[i] = source->user_data[i]) == NIL) + break; + } +#endif +} + +/************************************************************************* + * TrioIsQualifier + * + * Description: + * Remember to add all new qualifiers to this function. + * QUALIFIER_POSITION must not be added. + */ +TRIO_PRIVATE BOOLEAN_T +TrioIsQualifier +TRIO_ARGS1((character), + TRIO_CONST char character) +{ + /* QUALIFIER_POSITION is not included */ + switch (character) + { + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + case QUALIFIER_PLUS: + case QUALIFIER_MINUS: + case QUALIFIER_SPACE: + case QUALIFIER_DOT: + case QUALIFIER_STAR: + case QUALIFIER_ALTERNATIVE: + case QUALIFIER_SHORT: + case QUALIFIER_LONG: + case QUALIFIER_CIRCUMFLEX: + case QUALIFIER_LONG_UPPER: + case QUALIFIER_SIZE_T: + case QUALIFIER_PTRDIFF_T: + case QUALIFIER_INTMAX_T: + case QUALIFIER_QUAD: + case QUALIFIER_SIZE_T_UPPER: +#if defined(QUALIFIER_WIDECHAR) + case QUALIFIER_WIDECHAR: +#endif + case QUALIFIER_QUOTE: + case QUALIFIER_STICKY: + case QUALIFIER_VARSIZE: +#if defined(QUALIFIER_PARAM) + case QUALIFIER_PARAM: +#endif + case QUALIFIER_FIXED_SIZE: + case QUALIFIER_ROUNDING_UPPER: + return TRUE; + default: + return FALSE; + } +} + +/************************************************************************* + * TrioSetLocale + */ +#if defined(USE_LOCALE) +TRIO_PRIVATE void +TrioSetLocale(TRIO_NOARGS) +{ + internalLocaleValues = (struct lconv *)localeconv(); + if (internalLocaleValues) + { + if ((internalLocaleValues->decimal_point) && + (internalLocaleValues->decimal_point[0] != NIL)) + { + internalDecimalPointLength = trio_length(internalLocaleValues->decimal_point); + if (internalDecimalPointLength == 1) + { + internalDecimalPoint = internalLocaleValues->decimal_point[0]; + } + else + { + internalDecimalPoint = NIL; + trio_copy_max(internalDecimalPointString, + sizeof(internalDecimalPointString), + internalLocaleValues->decimal_point); + } + } +# if TRIO_EXTENSION + if ((internalLocaleValues->thousands_sep) && + (internalLocaleValues->thousands_sep[0] != NIL)) + { + trio_copy_max(internalThousandSeparator, + sizeof(internalThousandSeparator), + internalLocaleValues->thousands_sep); + internalThousandSeparatorLength = trio_length(internalThousandSeparator); + } +# endif +# if TRIO_EXTENSION + if ((internalLocaleValues->grouping) && + (internalLocaleValues->grouping[0] != NIL)) + { + trio_copy_max(internalGrouping, + sizeof(internalGrouping), + internalLocaleValues->grouping); + } +# endif + } +} +#endif /* defined(USE_LOCALE) */ + +#if TRIO_FEATURE_FLOAT && TRIO_FEATURE_QUOTE +TRIO_PRIVATE int +TrioCalcThousandSeparatorLength +TRIO_ARGS1((digits), + int digits) +{ + int count = 0; + int step = NO_GROUPING; + char *groupingPointer = internalGrouping; + + while (digits > 0) + { + if (*groupingPointer == CHAR_MAX) + { + /* Disable grouping */ + break; /* while */ + } + else if (*groupingPointer == 0) + { + /* Repeat last group */ + if (step == NO_GROUPING) + { + /* Error in locale */ + break; /* while */ + } + } + else + { + step = *groupingPointer++; + } + if (digits > step) + count += internalThousandSeparatorLength; + digits -= step; + } + return count; +} +#endif /* TRIO_FEATURE_FLOAT && TRIO_FEATURE_QUOTE */ + +#if TRIO_FEATURE_QUOTE +TRIO_PRIVATE BOOLEAN_T +TrioFollowedBySeparator +TRIO_ARGS1((position), + int position) +{ + int step = 0; + char *groupingPointer = internalGrouping; + + position--; + if (position == 0) + return FALSE; + while (position > 0) + { + if (*groupingPointer == CHAR_MAX) + { + /* Disable grouping */ + break; /* while */ + } + else if (*groupingPointer != 0) + { + step = *groupingPointer++; + } + if (step == 0) + break; + position -= step; + } + return (position == 0); +} +#endif /* TRIO_FEATURE_QUOTE */ + +/************************************************************************* + * TrioGetPosition + * + * Get the %n$ position. + */ +TRIO_PRIVATE int +TrioGetPosition +TRIO_ARGS2((format, offsetPointer), + TRIO_CONST char *format, + int *offsetPointer) +{ +#if TRIO_FEATURE_POSITIONAL + char *tmpformat; + int number = 0; + int offset = *offsetPointer; + + number = (int)trio_to_long(&format[offset], &tmpformat, BASE_DECIMAL); + offset = (int)(tmpformat - format); + if ((number != 0) && (QUALIFIER_POSITION == format[offset++])) + { + *offsetPointer = offset; + /* + * number is decreased by 1, because n$ starts from 1, whereas + * the array it is indexing starts from 0. + */ + return number - 1; + } +#endif + return NO_POSITION; +} + +/************************************************************************* + * TrioFindNamespace + * + * Find registered user-defined specifier. + * The prev argument is used for optimization only. + */ +#if TRIO_FEATURE_USER_DEFINED +TRIO_PRIVATE trio_userdef_t * +TrioFindNamespace +TRIO_ARGS2((name, prev), + TRIO_CONST char *name, + trio_userdef_t **prev) +{ + trio_userdef_t *def; + + if (internalEnterCriticalRegion) + (void)internalEnterCriticalRegion(NULL); + + for (def = internalUserDef; def; def = def->next) + { + /* Case-sensitive string comparison */ + if (trio_equal_case(def->name, name)) + break; + + if (prev) + *prev = def; + } + + if (internalLeaveCriticalRegion) + (void)internalLeaveCriticalRegion(NULL); + + return def; +} +#endif + +/************************************************************************* + * TrioPower + * + * Description: + * Calculate pow(base, exponent), where number and exponent are integers. + */ +#if TRIO_FEATURE_FLOAT +TRIO_PRIVATE trio_long_double_t +TrioPower +TRIO_ARGS2((number, exponent), + int number, + int exponent) +{ + trio_long_double_t result; + + if (number == 10) + { + switch (exponent) + { + /* Speed up calculation of common cases */ + case 0: + result = (trio_long_double_t)number * TRIO_SUFFIX_LONG(1E-1); + break; + case 1: + result = (trio_long_double_t)number * TRIO_SUFFIX_LONG(1E+0); + break; + case 2: + result = (trio_long_double_t)number * TRIO_SUFFIX_LONG(1E+1); + break; + case 3: + result = (trio_long_double_t)number * TRIO_SUFFIX_LONG(1E+2); + break; + case 4: + result = (trio_long_double_t)number * TRIO_SUFFIX_LONG(1E+3); + break; + case 5: + result = (trio_long_double_t)number * TRIO_SUFFIX_LONG(1E+4); + break; + case 6: + result = (trio_long_double_t)number * TRIO_SUFFIX_LONG(1E+5); + break; + case 7: + result = (trio_long_double_t)number * TRIO_SUFFIX_LONG(1E+6); + break; + case 8: + result = (trio_long_double_t)number * TRIO_SUFFIX_LONG(1E+7); + break; + case 9: + result = (trio_long_double_t)number * TRIO_SUFFIX_LONG(1E+8); + break; + default: + result = trio_pow((trio_long_double_t)number, + (trio_long_double_t)exponent); + break; + } + } + else + { + return trio_pow((trio_long_double_t)number, + (trio_long_double_t)exponent); + } + return result; +} +#endif /* TRIO_FEATURE_FLOAT */ + +/************************************************************************* + * TrioLogarithm + */ +#if TRIO_FEATURE_FLOAT +TRIO_PRIVATE trio_long_double_t +TrioLogarithm +TRIO_ARGS2((number, base), + trio_long_double_t number, + int base) +{ + trio_long_double_t result; + + if (number <= 0.0) + { + /* xlC crashes on log(0) */ + result = (number == 0.0) ? trio_ninf() : trio_nan(); + } + else + { + if (base == 10) + { + result = trio_log10(number); + } + else + { + result = trio_log10(number) / trio_log10((double)base); + } + } + return result; +} +#endif /* TRIO_FEATURE_FLOAT */ + +/************************************************************************* + * TrioLogarithmBase + */ +#if TRIO_FEATURE_FLOAT +TRIO_PRIVATE double +TrioLogarithmBase +TRIO_ARGS1((base), + int base) +{ + switch (base) + { + case BASE_BINARY : return 1.0; + case BASE_OCTAL : return 3.0; + case BASE_DECIMAL: return 3.321928094887362345; + case BASE_HEX : return 4.0; + default : return TrioLogarithm((double)base, 2); + } +} +#endif /* TRIO_FEATURE_FLOAT */ + +/************************************************************************* + * TrioParseQualifiers + * + * Description: + * Parse the qualifiers of a potential conversion specifier + */ +TRIO_PRIVATE int +TrioParseQualifiers +TRIO_ARGS4((type, format, offset, parameter), + int type, + TRIO_CONST char *format, + int offset, + trio_parameter_t *parameter) +{ + char ch; + int dots = 0; /* Count number of dots in modifier part */ + char *tmpformat; + + parameter->beginOffset = offset - 1; + parameter->flags = FLAGS_NEW; + parameter->position = TrioGetPosition(format, &offset); + + /* Default values */ + parameter->width = NO_WIDTH; + parameter->precision = NO_PRECISION; + parameter->base = NO_BASE; + parameter->varsize = NO_SIZE; + + while (TrioIsQualifier(format[offset])) + { + ch = format[offset++]; + + switch (ch) + { + case QUALIFIER_SPACE: + parameter->flags |= FLAGS_SPACE; + break; + + case QUALIFIER_PLUS: + parameter->flags |= FLAGS_SHOWSIGN; + break; + + case QUALIFIER_MINUS: + parameter->flags |= FLAGS_LEFTADJUST; + parameter->flags &= ~FLAGS_NILPADDING; + break; + + case QUALIFIER_ALTERNATIVE: + parameter->flags |= FLAGS_ALTERNATIVE; + break; + + case QUALIFIER_DOT: + if (dots == 0) /* Precision */ + { + dots++; + + /* Skip if no precision */ + if (QUALIFIER_DOT == format[offset]) + break; + + /* After the first dot we have the precision */ + parameter->flags |= FLAGS_PRECISION; + if ((QUALIFIER_STAR == format[offset]) +#if defined(QUALIFIER_PARAM) + || (QUALIFIER_PARAM == format[offset]) +#endif + ) + { + offset++; + parameter->flags |= FLAGS_PRECISION_PARAMETER; + parameter->precision = TrioGetPosition(format, &offset); + } + else + { + parameter->precision = trio_to_long(&format[offset], + &tmpformat, + BASE_DECIMAL); + offset = (int)(tmpformat - format); + } + } + else if (dots == 1) /* Base */ + { + dots++; + + /* After the second dot we have the base */ + parameter->flags |= FLAGS_BASE; + if ((QUALIFIER_STAR == format[offset]) +#if defined(QUALIFIER_PARAM) + || (QUALIFIER_PARAM == format[offset]) +#endif + ) + { + offset++; + parameter->flags |= FLAGS_BASE_PARAMETER; + parameter->base = TrioGetPosition(format, &offset); + } + else + { + parameter->base = trio_to_long(&format[offset], + &tmpformat, + BASE_DECIMAL); + if (parameter->base > MAX_BASE) + return TRIO_ERROR_RETURN(TRIO_EINVAL, offset); + offset = (int)(tmpformat - format); + } + } + else + { + return TRIO_ERROR_RETURN(TRIO_EINVAL, offset); + } + break; /* QUALIFIER_DOT */ + +#if defined(QUALIFIER_PARAM) + case QUALIFIER_PARAM: + parameter->type = TYPE_PRINT; + /* FALLTHROUGH */ +#endif + case QUALIFIER_STAR: + /* This has different meanings for print and scan */ + if (TYPE_PRINT == type) + { + /* Read with from parameter */ + int width = TrioGetPosition(format, &offset); + parameter->flags |= (FLAGS_WIDTH | FLAGS_WIDTH_PARAMETER); + if (NO_POSITION != width) + parameter->width = width; + /* else keep parameter->width = NO_WIDTH which != NO_POSITION */ + } +#if TRIO_FEATURE_SCANF + else + { + /* Scan, but do not store result */ + parameter->flags |= FLAGS_IGNORE; + } +#endif + break; /* QUALIFIER_STAR */ + + case '0': + if (! (parameter->flags & FLAGS_LEFTADJUST)) + parameter->flags |= FLAGS_NILPADDING; + /* FALLTHROUGH */ + case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + parameter->flags |= FLAGS_WIDTH; + /* + * &format[offset - 1] is used to "rewind" the read + * character from format + */ + parameter->width = trio_to_long(&format[offset - 1], + &tmpformat, + BASE_DECIMAL); + offset = (int)(tmpformat - format); + break; + + case QUALIFIER_SHORT: + if (parameter->flags & FLAGS_SHORTSHORT) + return TRIO_ERROR_RETURN(TRIO_EINVAL, offset); + else if (parameter->flags & FLAGS_SHORT) + parameter->flags |= FLAGS_SHORTSHORT; + else + parameter->flags |= FLAGS_SHORT; + break; + + case QUALIFIER_LONG: + if (parameter->flags & FLAGS_QUAD) + return TRIO_ERROR_RETURN(TRIO_EINVAL, offset); + else if (parameter->flags & FLAGS_LONG) + parameter->flags |= FLAGS_QUAD; + else + parameter->flags |= FLAGS_LONG; + break; + +#if TRIO_FEATURE_LONGDOUBLE + case QUALIFIER_LONG_UPPER: + parameter->flags |= FLAGS_LONGDOUBLE; + break; +#endif + +#if TRIO_FEATURE_SIZE_T + case QUALIFIER_SIZE_T: + parameter->flags |= FLAGS_SIZE_T; + /* Modify flags for later truncation of number */ + if (sizeof(size_t) == sizeof(trio_ulonglong_t)) + parameter->flags |= FLAGS_QUAD; + else if (sizeof(size_t) == sizeof(long)) + parameter->flags |= FLAGS_LONG; + break; +#endif + +#if TRIO_FEATURE_PTRDIFF_T + case QUALIFIER_PTRDIFF_T: + parameter->flags |= FLAGS_PTRDIFF_T; + if (sizeof(ptrdiff_t) == sizeof(trio_ulonglong_t)) + parameter->flags |= FLAGS_QUAD; + else if (sizeof(ptrdiff_t) == sizeof(long)) + parameter->flags |= FLAGS_LONG; + break; +#endif + +#if TRIO_FEATURE_INTMAX_T + case QUALIFIER_INTMAX_T: + parameter->flags |= FLAGS_INTMAX_T; + if (sizeof(trio_intmax_t) == sizeof(trio_ulonglong_t)) + parameter->flags |= FLAGS_QUAD; + else if (sizeof(trio_intmax_t) == sizeof(long)) + parameter->flags |= FLAGS_LONG; + break; +#endif + +#if TRIO_FEATURE_QUAD + case QUALIFIER_QUAD: + parameter->flags |= FLAGS_QUAD; + break; +#endif + +#if TRIO_FEATURE_FIXED_SIZE + case QUALIFIER_FIXED_SIZE: + if (parameter->flags & FLAGS_FIXED_SIZE) + return TRIO_ERROR_RETURN(TRIO_EINVAL, offset); + + if (parameter->flags & (FLAGS_ALL_SIZES | + FLAGS_LONGDOUBLE | + FLAGS_WIDECHAR | + FLAGS_VARSIZE_PARAMETER)) + return TRIO_ERROR_RETURN(TRIO_EINVAL, offset); + + if ((format[offset] == '6') && + (format[offset + 1] == '4')) + { + parameter->varsize = sizeof(trio_int64_t); + offset += 2; + } + else if ((format[offset] == '3') && + (format[offset + 1] == '2')) + { + parameter->varsize = sizeof(trio_int32_t); + offset += 2; + } + else if ((format[offset] == '1') && + (format[offset + 1] == '6')) + { + parameter->varsize = sizeof(trio_int16_t); + offset += 2; + } + else if (format[offset] == '8') + { + parameter->varsize = sizeof(trio_int8_t); + offset++; + } + else + return TRIO_ERROR_RETURN(TRIO_EINVAL, offset); + + parameter->flags |= FLAGS_FIXED_SIZE; + break; +#endif /* TRIO_FEATURE_FIXED_SIZE */ + +#if defined(QUALIFIER_WIDECHAR) + case QUALIFIER_WIDECHAR: + parameter->flags |= FLAGS_WIDECHAR; + break; +#endif + +#if TRIO_FEATURE_SIZE_T_UPPER + case QUALIFIER_SIZE_T_UPPER: + break; +#endif + +#if TRIO_FEATURE_QUOTE + case QUALIFIER_QUOTE: + parameter->flags |= FLAGS_QUOTE; + break; +#endif + +#if TRIO_FEATURE_STICKY + case QUALIFIER_STICKY: + parameter->flags |= FLAGS_STICKY; + break; +#endif + +#if TRIO_FEATURE_VARSIZE + case QUALIFIER_VARSIZE: + parameter->flags |= FLAGS_VARSIZE_PARAMETER; + break; +#endif + +#if TRIO_FEATURE_ROUNDING + case QUALIFIER_ROUNDING_UPPER: + parameter->flags |= FLAGS_ROUNDING; + break; +#endif + + default: + /* Bail out completely to make the error more obvious */ + return TRIO_ERROR_RETURN(TRIO_EINVAL, offset); + } + } /* while qualifier */ + + parameter->endOffset = offset; + + return 0; +} + +/************************************************************************* + * TrioParseSpecifier + * + * Description: + * Parse the specifier part of a potential conversion specifier + */ +TRIO_PRIVATE int +TrioParseSpecifier +TRIO_ARGS4((type, format, offset, parameter), + int type, + TRIO_CONST char *format, + int offset, + trio_parameter_t *parameter) +{ + parameter->baseSpecifier = NO_BASE; + + switch (format[offset++]) + { +#if defined(SPECIFIER_CHAR_UPPER) + case SPECIFIER_CHAR_UPPER: + parameter->flags |= FLAGS_WIDECHAR; + /* FALLTHROUGH */ +#endif + case SPECIFIER_CHAR: + if (parameter->flags & FLAGS_LONG) + parameter->flags |= FLAGS_WIDECHAR; + else if (parameter->flags & FLAGS_SHORT) + parameter->flags &= ~FLAGS_WIDECHAR; + parameter->type = FORMAT_CHAR; + break; + +#if defined(SPECIFIER_STRING_UPPER) + case SPECIFIER_STRING_UPPER: + parameter->flags |= FLAGS_WIDECHAR; + /* FALLTHROUGH */ +#endif + case SPECIFIER_STRING: + if (parameter->flags & FLAGS_LONG) + parameter->flags |= FLAGS_WIDECHAR; + else if (parameter->flags & FLAGS_SHORT) + parameter->flags &= ~FLAGS_WIDECHAR; + parameter->type = FORMAT_STRING; + break; + +#if defined(SPECIFIER_GROUP) + case SPECIFIER_GROUP: + if (TYPE_SCAN == type) + { + int depth = 1; + parameter->type = FORMAT_GROUP; + if (format[offset] == QUALIFIER_CIRCUMFLEX) + offset++; + if (format[offset] == SPECIFIER_UNGROUP) + offset++; + if (format[offset] == QUALIFIER_MINUS) + offset++; + /* Skip nested brackets */ + while (format[offset] != NIL) + { + if (format[offset] == SPECIFIER_GROUP) + { + depth++; + } + else if (format[offset] == SPECIFIER_UNGROUP) + { + if (--depth <= 0) + { + offset++; + break; + } + } + offset++; + } + } + break; +#endif /* defined(SPECIFIER_GROUP) */ + + case SPECIFIER_INTEGER: + parameter->type = FORMAT_INT; + break; + + case SPECIFIER_UNSIGNED: + parameter->flags |= FLAGS_UNSIGNED; + parameter->type = FORMAT_INT; + break; + + case SPECIFIER_DECIMAL: + parameter->baseSpecifier = BASE_DECIMAL; + parameter->type = FORMAT_INT; + break; + + case SPECIFIER_OCTAL: + parameter->flags |= FLAGS_UNSIGNED; + parameter->baseSpecifier = BASE_OCTAL; + parameter->type = FORMAT_INT; + break; + +#if TRIO_FEATURE_BINARY + case SPECIFIER_BINARY_UPPER: + parameter->flags |= FLAGS_UPPER; + /* FALLTHROUGH */ + case SPECIFIER_BINARY: + parameter->flags |= FLAGS_NILPADDING; + parameter->baseSpecifier = BASE_BINARY; + parameter->type = FORMAT_INT; + break; +#endif + + case SPECIFIER_HEX_UPPER: + parameter->flags |= FLAGS_UPPER; + /* FALLTHROUGH */ + case SPECIFIER_HEX: + parameter->flags |= FLAGS_UNSIGNED; + parameter->baseSpecifier = BASE_HEX; + parameter->type = FORMAT_INT; + break; + +#if defined(SPECIFIER_FLOAT_E) +# if defined(SPECIFIER_FLOAT_E_UPPER) + case SPECIFIER_FLOAT_E_UPPER: + parameter->flags |= FLAGS_UPPER; + /* FALLTHROUGH */ +# endif + case SPECIFIER_FLOAT_E: + parameter->flags |= FLAGS_FLOAT_E; + parameter->type = FORMAT_DOUBLE; + break; +#endif + +#if defined(SPECIFIER_FLOAT_G) +# if defined(SPECIFIER_FLOAT_G_UPPER) + case SPECIFIER_FLOAT_G_UPPER: + parameter->flags |= FLAGS_UPPER; + /* FALLTHROUGH */ +# endif + case SPECIFIER_FLOAT_G: + parameter->flags |= FLAGS_FLOAT_G; + parameter->type = FORMAT_DOUBLE; + break; +#endif + +#if defined(SPECIFIER_FLOAT_F) +# if defined(SPECIFIER_FLOAT_F_UPPER) + case SPECIFIER_FLOAT_F_UPPER: + parameter->flags |= FLAGS_UPPER; + /* FALLTHROUGH */ +# endif + case SPECIFIER_FLOAT_F: + parameter->type = FORMAT_DOUBLE; + break; +#endif + +#if defined(TRIO_COMPILER_VISUALC) +# pragma warning( push ) +# pragma warning( disable : 4127 ) /* Conditional expression is constant */ +#endif + case SPECIFIER_POINTER: + if (sizeof(trio_pointer_t) == sizeof(trio_ulonglong_t)) + parameter->flags |= FLAGS_QUAD; + else if (sizeof(trio_pointer_t) == sizeof(long)) + parameter->flags |= FLAGS_LONG; + parameter->type = FORMAT_POINTER; + break; +#if defined(TRIO_COMPILER_VISUALC) +# pragma warning( pop ) +#endif + + case SPECIFIER_COUNT: + parameter->type = FORMAT_COUNT; + break; + +#if TRIO_FEATURE_HEXFLOAT + case SPECIFIER_HEXFLOAT_UPPER: + parameter->flags |= FLAGS_UPPER; + /* FALLTHROUGH */ + case SPECIFIER_HEXFLOAT: + parameter->baseSpecifier = BASE_HEX; + parameter->type = FORMAT_DOUBLE; + break; +#endif + +#if TRIO_FEATURE_ERRNO + case SPECIFIER_ERRNO: + parameter->type = FORMAT_ERRNO; + break; +#endif + +#if TRIO_FEATURE_USER_DEFINED + case SPECIFIER_USER_DEFINED_BEGIN: + { + unsigned int max; + int without_namespace = TRUE; + char* tmpformat = (char *)&format[offset]; + int ch; + + parameter->type = FORMAT_USER_DEFINED; + parameter->user_defined.namespace[0] = NIL; + + while ((ch = format[offset]) != NIL) + { + offset++; + if ((ch == SPECIFIER_USER_DEFINED_END) || (ch == SPECIFIER_USER_DEFINED_EXTRA)) + { + if (without_namespace) + /* No namespace, handler will be passed as an argument */ + parameter->flags |= FLAGS_USER_DEFINED_PARAMETER; + + /* Copy the user data */ + max = (unsigned int)(&format[offset] - tmpformat); + if (max > MAX_USER_DATA) + max = MAX_USER_DATA; + trio_copy_max(parameter->user_data, max, tmpformat); + + /* Skip extra data (which is only there to keep the compiler happy) */ + while ((ch != NIL) && (ch != SPECIFIER_USER_DEFINED_END)) + ch = format[offset++]; + + break; /* while */ + } + + if (ch == SPECIFIER_USER_DEFINED_SEPARATOR) + { + without_namespace = FALSE; + /* Copy the namespace for later looking-up */ + max = (int)(&format[offset] - tmpformat); + if (max > MAX_USER_NAME) + max = MAX_USER_NAME; + trio_copy_max(parameter->user_defined.namespace, max, tmpformat); + tmpformat = (char *)&format[offset]; + } + } + + if (ch != SPECIFIER_USER_DEFINED_END) + return TRIO_ERROR_RETURN(TRIO_EINVAL, offset); + } + break; +#endif /* TRIO_FEATURE_USER_DEFINED */ + + default: + /* Bail out completely to make the error more obvious */ + return TRIO_ERROR_RETURN(TRIO_EINVAL, offset); + } + + parameter->endOffset = offset; + + return 0; +} + +/************************************************************************* + * TrioParse + * + * Description: + * Parse the format string + */ +TRIO_PRIVATE int +TrioParse +TRIO_ARGS6((type, format, parameters, arglist, argfunc, argarray), + int type, + TRIO_CONST char *format, + trio_parameter_t *parameters, + va_list arglist, + trio_argfunc_t argfunc, + trio_pointer_t *argarray) +{ + /* Count the number of times a parameter is referenced */ + unsigned short usedEntries[MAX_PARAMETERS]; + /* Parameter counters */ + int parameterPosition; + int maxParam = -1; + /* Utility variables */ + int offset; /* Offset into formatting string */ + BOOLEAN_T positional; /* Does the specifier have a positional? */ +#if TRIO_FEATURE_STICKY + BOOLEAN_T gotSticky = FALSE; /* Are there any sticky modifiers at all? */ +#endif + /* + * indices specifies the order in which the parameters must be + * read from the va_args (this is necessary to handle positionals) + */ + int indices[MAX_PARAMETERS]; + int pos = 0; + /* Various variables */ +#if defined(TRIO_COMPILER_SUPPORTS_MULTIBYTE) + int charlen; +#endif + int save_errno; + int i = -1; + int num; + trio_parameter_t workParameter; + int status; + + /* Both must be set or none must be set */ + assert(((argfunc == NULL) && (argarray == NULL)) || + ((argfunc != NULL) && (argarray != NULL))); + + /* + * The 'parameters' array is not initialized, but we need to + * know which entries we have used. + */ + memset(usedEntries, 0, sizeof(usedEntries)); + + save_errno = errno; + offset = 0; + parameterPosition = 0; +#if defined(TRIO_COMPILER_SUPPORTS_MULTIBYTE) + (void)mblen(NULL, 0); +#endif + + while (format[offset]) + { + TrioInitializeParameter(&workParameter); + +#if defined(TRIO_COMPILER_SUPPORTS_MULTIBYTE) + if (! isascii(format[offset])) + { + /* + * Multibyte characters cannot be legal specifiers or + * modifiers, so we skip over them. + */ + charlen = mblen(&format[offset], MB_LEN_MAX); + offset += (charlen > 0) ? charlen : 1; + continue; /* while */ + } +#endif /* TRIO_COMPILER_SUPPORTS_MULTIBYTE */ + + switch(format[offset++]) { + + case CHAR_IDENTIFIER: + { + if (CHAR_IDENTIFIER == format[offset]) + { + /* skip double "%" */ + offset++; + continue; /* while */ + } + + status = TrioParseQualifiers(type, format, offset, &workParameter); + if (status < 0) + return status; /* Return qualifier syntax error */ + + status = TrioParseSpecifier(type, format, workParameter.endOffset, &workParameter); + if (status < 0) + return status; /* Return specifier syntax error */ + } + break; + +#if TRIO_EXTENSION + case CHAR_ALT_IDENTIFIER: + { + status = TrioParseQualifiers(type, format, offset, &workParameter); + if (status < 0) + continue; /* False alert, not a user defined specifier */ + + status = TrioParseSpecifier(type, format, workParameter.endOffset, &workParameter); + if ((status < 0) || (FORMAT_USER_DEFINED != workParameter.type)) + continue; /* False alert, not a user defined specifier */ + } + break; +#endif + + default: + continue; /* while */ + } + + /* now handle the parsed conversion specification */ + positional = (NO_POSITION != workParameter.position); + + /* + * Parameters only need the type and value. The value is + * read later. + */ + if (workParameter.flags & FLAGS_WIDTH_PARAMETER) + { + if (workParameter.width == NO_WIDTH) + { + workParameter.width = parameterPosition++; + } + else + { + if (! positional) + workParameter.position = workParameter.width + 1; + } + + usedEntries[workParameter.width] += 1; + if (workParameter.width > maxParam) + maxParam = workParameter.width; + parameters[pos].type = FORMAT_PARAMETER; + parameters[pos].flags = 0; + indices[workParameter.width] = pos; + workParameter.width = pos++; + } + if (workParameter.flags & FLAGS_PRECISION_PARAMETER) + { + if (workParameter.precision == NO_PRECISION) + { + workParameter.precision = parameterPosition++; + } + else + { + if (! positional) + workParameter.position = workParameter.precision + 1; + } + + usedEntries[workParameter.precision] += 1; + if (workParameter.precision > maxParam) + maxParam = workParameter.precision; + parameters[pos].type = FORMAT_PARAMETER; + parameters[pos].flags = 0; + indices[workParameter.precision] = pos; + workParameter.precision = pos++; + } + if (workParameter.flags & FLAGS_BASE_PARAMETER) + { + if (workParameter.base == NO_BASE) + { + workParameter.base = parameterPosition++; + } + else + { + if (! positional) + workParameter.position = workParameter.base + 1; + } + + usedEntries[workParameter.base] += 1; + if (workParameter.base > maxParam) + maxParam = workParameter.base; + parameters[pos].type = FORMAT_PARAMETER; + parameters[pos].flags = 0; + indices[workParameter.base] = pos; + workParameter.base = pos++; + } +#if TRIO_FEATURE_VARSIZE + if (workParameter.flags & FLAGS_VARSIZE_PARAMETER) + { + workParameter.varsize = parameterPosition++; + + usedEntries[workParameter.varsize] += 1; + if (workParameter.varsize > maxParam) + maxParam = workParameter.varsize; + parameters[pos].type = FORMAT_PARAMETER; + parameters[pos].flags = 0; + indices[workParameter.varsize] = pos; + workParameter.varsize = pos++; + } +#endif +#if TRIO_FEATURE_USER_DEFINED + if (workParameter.flags & FLAGS_USER_DEFINED_PARAMETER) + { + workParameter.user_defined.handler = parameterPosition++; + + usedEntries[workParameter.user_defined.handler] += 1; + if (workParameter.user_defined.handler > maxParam) + maxParam = workParameter.user_defined.handler; + parameters[pos].type = FORMAT_PARAMETER; + parameters[pos].flags = FLAGS_USER_DEFINED; + indices[workParameter.user_defined.handler] = pos; + workParameter.user_defined.handler = pos++; + } +#endif + + if (NO_POSITION == workParameter.position) + { + workParameter.position = parameterPosition++; + } + + if (workParameter.position > maxParam) + maxParam = workParameter.position; + + if (workParameter.position >= MAX_PARAMETERS) + { + /* Bail out completely to make the error more obvious */ + return TRIO_ERROR_RETURN(TRIO_ETOOMANY, offset); + } + + indices[workParameter.position] = pos; + + /* Count the number of times this entry has been used */ + usedEntries[workParameter.position] += 1; + + /* Find last sticky parameters */ +#if TRIO_FEATURE_STICKY + if (workParameter.flags & FLAGS_STICKY) + { + gotSticky = TRUE; + } + else if (gotSticky) + { + for (i = pos - 1; i >= 0; i--) + { + if (parameters[i].type == FORMAT_PARAMETER) + continue; + if ((parameters[i].flags & FLAGS_STICKY) && + (parameters[i].type == workParameter.type)) + { + /* Do not overwrite current qualifiers */ + workParameter.flags |= (parameters[i].flags & (unsigned long)~FLAGS_STICKY); + if (workParameter.width == NO_WIDTH) + workParameter.width = parameters[i].width; + if (workParameter.precision == NO_PRECISION) + workParameter.precision = parameters[i].precision; + if (workParameter.base == NO_BASE) + workParameter.base = parameters[i].base; + break; + } + } + } +#endif + + if (workParameter.base == NO_BASE) + workParameter.base = BASE_DECIMAL; + + offset = workParameter.endOffset; + + TrioCopyParameter(¶meters[pos++], &workParameter); + } /* while format characters left */ + + parameters[pos].type = FORMAT_SENTINEL; /* end parameter array with sentinel */ + parameters[pos].beginOffset = offset; + + for (num = 0; num <= maxParam; num++) + { + if (usedEntries[num] != 1) + { + if (usedEntries[num] == 0) /* gap detected */ + return TRIO_ERROR_RETURN(TRIO_EGAP, num); + else /* double references detected */ + return TRIO_ERROR_RETURN(TRIO_EDBLREF, num); + } + + i = indices[num]; + + /* + * FORMAT_PARAMETERS are only present if they must be read, + * so it makes no sense to check the ignore flag (besides, + * the flags variable is not set for that particular type) + */ + if ((parameters[i].type != FORMAT_PARAMETER) && + (parameters[i].flags & FLAGS_IGNORE)) + continue; /* for all arguments */ + + /* + * The stack arguments are read according to ANSI C89 + * default argument promotions: + * + * char = int + * short = int + * unsigned char = unsigned int + * unsigned short = unsigned int + * float = double + * + * In addition to the ANSI C89 these types are read (the + * default argument promotions of C99 has not been + * considered yet) + * + * long long + * long double + * size_t + * ptrdiff_t + * intmax_t + */ + switch (parameters[i].type) + { + case FORMAT_GROUP: + case FORMAT_STRING: +#if TRIO_FEATURE_WIDECHAR + if (parameters[i].flags & FLAGS_WIDECHAR) + { + parameters[i].data.wstring = (argfunc == NULL) + ? va_arg(arglist, trio_wchar_t *) + : (trio_wchar_t *)(argfunc(argarray, num, TRIO_TYPE_PWCHAR)); + } + else +#endif + { + parameters[i].data.string = (argfunc == NULL) + ? va_arg(arglist, char *) + : (char *)(argfunc(argarray, num, TRIO_TYPE_PCHAR)); + } + break; + +#if TRIO_FEATURE_USER_DEFINED + case FORMAT_USER_DEFINED: +#endif + case FORMAT_POINTER: + case FORMAT_COUNT: + case FORMAT_UNKNOWN: + parameters[i].data.pointer = (argfunc == NULL) + ? va_arg(arglist, trio_pointer_t ) + : argfunc(argarray, num, TRIO_TYPE_POINTER); + break; + + case FORMAT_CHAR: + case FORMAT_INT: +#if TRIO_FEATURE_SCANF + if (TYPE_SCAN == type) + { + if (argfunc == NULL) + parameters[i].data.pointer = + (trio_pointer_t)va_arg(arglist, trio_pointer_t); + else + { + if (parameters[i].type == FORMAT_CHAR) + parameters[i].data.pointer = + (trio_pointer_t)((char *)argfunc(argarray, num, TRIO_TYPE_CHAR)); + else if (parameters[i].flags & FLAGS_SHORT) + parameters[i].data.pointer = + (trio_pointer_t)((short *)argfunc(argarray, num, TRIO_TYPE_SHORT)); + else + parameters[i].data.pointer = + (trio_pointer_t)((int *)argfunc(argarray, num, TRIO_TYPE_INT)); + } + } + else +#endif /* TRIO_FEATURE_SCANF */ + { +#if TRIO_FEATURE_VARSIZE || TRIO_FEATURE_FIXED_SIZE + if (parameters[i].flags + & (FLAGS_VARSIZE_PARAMETER | FLAGS_FIXED_SIZE)) + { + int varsize; + if (parameters[i].flags & FLAGS_VARSIZE_PARAMETER) + { + /* + * Variable sizes are mapped onto the fixed sizes, in + * accordance with integer promotion. + * + * Please note that this may not be portable, as we + * only guess the size, not the layout of the numbers. + * For example, if int is little-endian, and long is + * big-endian, then this will fail. + */ + varsize = (int)parameters[parameters[i].varsize].data.number.as_unsigned; + } + else + { + /* Used for the I<bits> modifiers */ + varsize = parameters[i].varsize; + } + parameters[i].flags &= ~FLAGS_ALL_VARSIZES; + + if (varsize <= (int)sizeof(int)) + ; + else if (varsize <= (int)sizeof(long)) + parameters[i].flags |= FLAGS_LONG; +#if TRIO_FEATURE_INTMAX_T + else if (varsize <= (int)sizeof(trio_longlong_t)) + parameters[i].flags |= FLAGS_QUAD; + else + parameters[i].flags |= FLAGS_INTMAX_T; +#else + else + parameters[i].flags |= FLAGS_QUAD; +#endif + } +#endif /* TRIO_FEATURE_VARSIZE */ +#if TRIO_FEATURE_SIZE_T || TRIO_FEATURE_SIZE_T_UPPER + if (parameters[i].flags & FLAGS_SIZE_T) + parameters[i].data.number.as_unsigned = (argfunc == NULL) + ? (trio_uintmax_t)va_arg(arglist, size_t) + : (trio_uintmax_t)(*((size_t *)argfunc(argarray, num, TRIO_TYPE_SIZE))); + else +#endif +#if TRIO_FEATURE_PTRDIFF_T + if (parameters[i].flags & FLAGS_PTRDIFF_T) + parameters[i].data.number.as_unsigned = (argfunc == NULL) + ? (trio_uintmax_t)va_arg(arglist, ptrdiff_t) + : (trio_uintmax_t)(*((ptrdiff_t *)argfunc(argarray, num, TRIO_TYPE_PTRDIFF))); + else +#endif +#if TRIO_FEATURE_INTMAX_T + if (parameters[i].flags & FLAGS_INTMAX_T) + parameters[i].data.number.as_unsigned = (argfunc == NULL) + ? (trio_uintmax_t)va_arg(arglist, trio_intmax_t) + : (trio_uintmax_t)(*((trio_intmax_t *)argfunc(argarray, num, TRIO_TYPE_UINTMAX))); + else +#endif + if (parameters[i].flags & FLAGS_QUAD) + parameters[i].data.number.as_unsigned = (argfunc == NULL) + ? (trio_uintmax_t)va_arg(arglist, trio_ulonglong_t) + : (trio_uintmax_t)(*((trio_ulonglong_t *)argfunc(argarray, num, TRIO_TYPE_ULONGLONG))); + else if (parameters[i].flags & FLAGS_LONG) + parameters[i].data.number.as_unsigned = (argfunc == NULL) + ? (trio_uintmax_t)va_arg(arglist, long) + : (trio_uintmax_t)(*((long *)argfunc(argarray, num, TRIO_TYPE_LONG))); + else + { + if (argfunc == NULL) + parameters[i].data.number.as_unsigned = (trio_uintmax_t)va_arg(arglist, int); + else + { + if (parameters[i].type == FORMAT_CHAR) + parameters[i].data.number.as_unsigned = + (trio_uintmax_t)(*((char *)argfunc(argarray, num, TRIO_TYPE_CHAR))); + else if (parameters[i].flags & FLAGS_SHORT) + parameters[i].data.number.as_unsigned = + (trio_uintmax_t)(*((short *)argfunc(argarray, num, TRIO_TYPE_SHORT))); + else + parameters[i].data.number.as_unsigned = + (trio_uintmax_t)(*((int *)argfunc(argarray, num, TRIO_TYPE_INT))); + } + } + } + break; + + case FORMAT_PARAMETER: + /* + * The parameter for the user-defined specifier is a pointer, + * whereas the rest (width, precision, base) uses an integer. + */ + if (parameters[i].flags & FLAGS_USER_DEFINED) + parameters[i].data.pointer = (argfunc == NULL) + ? va_arg(arglist, trio_pointer_t ) + : argfunc(argarray, num, TRIO_TYPE_POINTER); + else + parameters[i].data.number.as_unsigned = (argfunc == NULL) + ? (trio_uintmax_t)va_arg(arglist, int) + : (trio_uintmax_t)(*((int *)argfunc(argarray, num, TRIO_TYPE_INT))); + break; + +#if TRIO_FEATURE_FLOAT + case FORMAT_DOUBLE: +# if TRIO_FEATURE_SCANF + if (TYPE_SCAN == type) + { + if (parameters[i].flags & FLAGS_LONGDOUBLE) + parameters[i].data.longdoublePointer = (argfunc == NULL) + ? va_arg(arglist, trio_long_double_t *) + : (trio_long_double_t *)argfunc(argarray, num, TRIO_TYPE_LONGDOUBLE); + else + { + if (parameters[i].flags & FLAGS_LONG) + parameters[i].data.doublePointer = (argfunc == NULL) + ? va_arg(arglist, double *) + : (double *)argfunc(argarray, num, TRIO_TYPE_DOUBLE); + else + parameters[i].data.doublePointer = (argfunc == NULL) + ? (double *)va_arg(arglist, float *) + : (double *)argfunc(argarray, num, TRIO_TYPE_DOUBLE); + } + } + else +# endif /* TRIO_FEATURE_SCANF */ + { + if (parameters[i].flags & FLAGS_LONGDOUBLE) + parameters[i].data.longdoubleNumber = (argfunc == NULL) + ? va_arg(arglist, trio_long_double_t) + : (trio_long_double_t)(*((trio_long_double_t *)argfunc(argarray, num, TRIO_TYPE_LONGDOUBLE))); + else + { + if (argfunc == NULL) + parameters[i].data.longdoubleNumber = + (trio_long_double_t)va_arg(arglist, double); + else + { + if (parameters[i].flags & FLAGS_SHORT) + parameters[i].data.longdoubleNumber = + (trio_long_double_t)(*((float *)argfunc(argarray, num, TRIO_TYPE_FLOAT))); + else + parameters[i].data.longdoubleNumber = + (trio_long_double_t)(*((double *)argfunc(argarray, num, TRIO_TYPE_DOUBLE))); + } + } + } + break; +#endif /* TRIO_FEATURE_FLOAT */ + +#if TRIO_FEATURE_ERRNO + case FORMAT_ERRNO: + parameters[i].data.errorNumber = save_errno; + break; +#endif + + default: + break; + } + } /* for all specifiers */ + return num; +} + + +/************************************************************************* + * + * FORMATTING + * + ************************************************************************/ + + +/************************************************************************* + * TrioWriteNumber + * + * Description: + * Output a number. + * The complexity of this function is a result of the complexity + * of the dependencies of the flags. + */ +TRIO_PRIVATE void +TrioWriteNumber +TRIO_ARGS6((self, number, flags, width, precision, base), + trio_class_t *self, + trio_uintmax_t number, + trio_flags_t flags, + int width, + int precision, + int base) +{ + BOOLEAN_T isNegative; + BOOLEAN_T isNumberZero; + BOOLEAN_T isPrecisionZero; + BOOLEAN_T ignoreNumber; + char buffer[MAX_CHARS_IN(trio_uintmax_t) * (1 + MAX_LOCALE_SEPARATOR_LENGTH) + 1]; + char *bufferend; + char *pointer; + TRIO_CONST char *digits; + int i; +#if TRIO_FEATURE_QUOTE + int length; + char *p; +#endif + int count; + int digitOffset; + + assert(VALID(self)); + assert(VALID(self->OutStream)); + assert(((base >= MIN_BASE) && (base <= MAX_BASE)) || (base == NO_BASE)); + + digits = (flags & FLAGS_UPPER) ? internalDigitsUpper : internalDigitsLower; + if (base == NO_BASE) + base = BASE_DECIMAL; + + isNumberZero = (number == 0); + isPrecisionZero = (precision == 0); + ignoreNumber = (isNumberZero + && isPrecisionZero + && !((flags & FLAGS_ALTERNATIVE) && (base == BASE_OCTAL))); + + if (flags & FLAGS_UNSIGNED) + { + isNegative = FALSE; + flags &= ~FLAGS_SHOWSIGN; + } + else + { + isNegative = ((trio_intmax_t)number < 0); + if (isNegative) + number = -((trio_intmax_t)number); + } + + if (flags & FLAGS_QUAD) + number &= (trio_ulonglong_t)-1; + else if (flags & FLAGS_LONG) + number &= (unsigned long)-1; + else + number &= (unsigned int)-1; + + /* Build number */ + pointer = bufferend = &buffer[sizeof(buffer) - 1]; + *pointer-- = NIL; + for (i = 1; i < (int)sizeof(buffer); i++) + { + digitOffset = number % base; + *pointer-- = digits[digitOffset]; + number /= base; + if (number == 0) + break; + +#if TRIO_FEATURE_QUOTE + if ((flags & FLAGS_QUOTE) && TrioFollowedBySeparator(i + 1)) + { + /* + * We are building the number from the least significant + * to the most significant digit, so we have to copy the + * thousand separator backwards + */ + length = internalThousandSeparatorLength; + if (((int)(pointer - buffer) - length) > 0) + { + p = &internalThousandSeparator[length - 1]; + while (length-- > 0) + *pointer-- = *p--; + } + } +#endif + } + + if (! ignoreNumber) + { + /* Adjust width */ + width -= (bufferend - pointer) - 1; + } + + /* Adjust precision */ + if (NO_PRECISION != precision) + { + precision -= (bufferend - pointer) - 1; + if (precision < 0) + precision = 0; + flags |= FLAGS_NILPADDING; + } + + /* Calculate padding */ + count = (! ((flags & FLAGS_LEFTADJUST) || (precision == NO_PRECISION))) + ? precision + : 0; + + /* Adjust width further */ + if (isNegative || (flags & FLAGS_SHOWSIGN) || (flags & FLAGS_SPACE)) + width--; + if ((flags & FLAGS_ALTERNATIVE) && !isNumberZero) + { + switch (base) + { + case BASE_BINARY: + case BASE_HEX: + width -= 2; + break; + case BASE_OCTAL: + if (!(flags & FLAGS_NILPADDING) || (count == 0)) + width--; + break; + default: + break; + } + } + + /* Output prefixes spaces if needed */ + if (! ((flags & FLAGS_LEFTADJUST) || + ((flags & FLAGS_NILPADDING) && (precision == NO_PRECISION)))) + { + while (width-- > count) + self->OutStream(self, CHAR_ADJUST); + } + + /* width has been adjusted for signs and alternatives */ + if (isNegative) + self->OutStream(self, '-'); + else if (flags & FLAGS_SHOWSIGN) + self->OutStream(self, '+'); + else if (flags & FLAGS_SPACE) + self->OutStream(self, ' '); + + /* Prefix is not written when the value is zero */ + if ((flags & FLAGS_ALTERNATIVE) && !isNumberZero) + { + switch (base) + { + case BASE_BINARY: + self->OutStream(self, '0'); + self->OutStream(self, (flags & FLAGS_UPPER) ? 'B' : 'b'); + break; + + case BASE_OCTAL: + if (!(flags & FLAGS_NILPADDING) || (count == 0)) + self->OutStream(self, '0'); + break; + + case BASE_HEX: + self->OutStream(self, '0'); + self->OutStream(self, (flags & FLAGS_UPPER) ? 'X' : 'x'); + break; + + default: + break; + } /* switch base */ + } + + /* Output prefixed zero padding if needed */ + if (flags & FLAGS_NILPADDING) + { + if (precision == NO_PRECISION) + precision = width; + while (precision-- > 0) + { + self->OutStream(self, '0'); + width--; + } + } + + if (! ignoreNumber) + { + /* Output the number itself */ + while (*(++pointer)) + { + self->OutStream(self, *pointer); + } + } + + /* Output trailing spaces if needed */ + if (flags & FLAGS_LEFTADJUST) + { + while (width-- > 0) + self->OutStream(self, CHAR_ADJUST); + } +} + +/************************************************************************* + * TrioWriteStringCharacter + * + * Description: + * Output a single character of a string + */ +TRIO_PRIVATE void +TrioWriteStringCharacter +TRIO_ARGS3((self, ch, flags), + trio_class_t *self, + int ch, + trio_flags_t flags) +{ + if (flags & FLAGS_ALTERNATIVE) + { + if (! isprint(ch)) + { + /* + * Non-printable characters are converted to C escapes or + * \number, if no C escape exists. + */ + self->OutStream(self, CHAR_BACKSLASH); + switch (ch) + { + case '\007': self->OutStream(self, 'a'); break; + case '\b': self->OutStream(self, 'b'); break; + case '\f': self->OutStream(self, 'f'); break; + case '\n': self->OutStream(self, 'n'); break; + case '\r': self->OutStream(self, 'r'); break; + case '\t': self->OutStream(self, 't'); break; + case '\v': self->OutStream(self, 'v'); break; + case '\\': self->OutStream(self, '\\'); break; + default: + self->OutStream(self, 'x'); + TrioWriteNumber(self, (trio_uintmax_t)ch, + FLAGS_UNSIGNED | FLAGS_NILPADDING, + 2, 2, BASE_HEX); + break; + } + } + else if (ch == CHAR_BACKSLASH) + { + self->OutStream(self, CHAR_BACKSLASH); + self->OutStream(self, CHAR_BACKSLASH); + } + else + { + self->OutStream(self, ch); + } + } + else + { + self->OutStream(self, ch); + } +} + +/************************************************************************* + * TrioWriteString + * + * Description: + * Output a string + */ +TRIO_PRIVATE void +TrioWriteString +TRIO_ARGS5((self, string, flags, width, precision), + trio_class_t *self, + TRIO_CONST char *string, + trio_flags_t flags, + int width, + int precision) +{ + int length; + int ch; + + assert(VALID(self)); + assert(VALID(self->OutStream)); + + if (string == NULL) + { + string = internalNullString; + length = sizeof(internalNullString) - 1; +#if TRIO_FEATURE_QUOTE + /* Disable quoting for the null pointer */ + flags &= (~FLAGS_QUOTE); +#endif + width = 0; + } + else + { + if (precision == 0) + { + length = trio_length(string); + } + else + { + length = trio_length_max(string, precision); + } + } + if ((NO_PRECISION != precision) && + (precision < length)) + { + length = precision; + } + width -= length; + +#if TRIO_FEATURE_QUOTE + if (flags & FLAGS_QUOTE) + self->OutStream(self, CHAR_QUOTE); +#endif + + if (! (flags & FLAGS_LEFTADJUST)) + { + while (width-- > 0) + self->OutStream(self, CHAR_ADJUST); + } + + while (length-- > 0) + { + /* The ctype parameters must be an unsigned char (or EOF) */ + ch = (int)((unsigned char)(*string++)); + TrioWriteStringCharacter(self, ch, flags); + } + + if (flags & FLAGS_LEFTADJUST) + { + while (width-- > 0) + self->OutStream(self, CHAR_ADJUST); + } +#if TRIO_FEATURE_QUOTE + if (flags & FLAGS_QUOTE) + self->OutStream(self, CHAR_QUOTE); +#endif +} + +/************************************************************************* + * TrioWriteWideStringCharacter + * + * Description: + * Output a wide string as a multi-byte sequence + */ +#if TRIO_FEATURE_WIDECHAR +TRIO_PRIVATE int +TrioWriteWideStringCharacter +TRIO_ARGS4((self, wch, flags, width), + trio_class_t *self, + trio_wchar_t wch, + trio_flags_t flags, + int width) +{ + int size; + int i; + int ch; + char *string; + char buffer[MB_LEN_MAX + 1]; + + if (width == NO_WIDTH) + width = sizeof(buffer); + + size = wctomb(buffer, wch); + if ((size <= 0) || (size > width) || (buffer[0] == NIL)) + return 0; + + string = buffer; + i = size; + while ((width >= i) && (width-- > 0) && (i-- > 0)) + { + /* The ctype parameters must be an unsigned char (or EOF) */ + ch = (int)((unsigned char)(*string++)); + TrioWriteStringCharacter(self, ch, flags); + } + return size; +} +#endif /* TRIO_FEATURE_WIDECHAR */ + +/************************************************************************* + * TrioWriteWideString + * + * Description: + * Output a wide character string as a multi-byte string + */ +#if TRIO_FEATURE_WIDECHAR +TRIO_PRIVATE void +TrioWriteWideString +TRIO_ARGS5((self, wstring, flags, width, precision), + trio_class_t *self, + TRIO_CONST trio_wchar_t *wstring, + trio_flags_t flags, + int width, + int precision) +{ + int length; + int size; + + assert(VALID(self)); + assert(VALID(self->OutStream)); + +#if defined(TRIO_COMPILER_SUPPORTS_MULTIBYTE) + /* Required by TrioWriteWideStringCharacter */ + (void)mblen(NULL, 0); +#endif + + if (wstring == NULL) + { + TrioWriteString(self, NULL, flags, width, precision); + return; + } + + if (NO_PRECISION == precision) + { + length = INT_MAX; + } + else + { + length = precision; + width -= length; + } + +#if TRIO_FEATURE_QUOTE + if (flags & FLAGS_QUOTE) + self->OutStream(self, CHAR_QUOTE); +#endif + + if (! (flags & FLAGS_LEFTADJUST)) + { + while (width-- > 0) + self->OutStream(self, CHAR_ADJUST); + } + + while (length > 0) + { + size = TrioWriteWideStringCharacter(self, *wstring++, flags, length); + if (size == 0) + break; /* while */ + length -= size; + } + + if (flags & FLAGS_LEFTADJUST) + { + while (width-- > 0) + self->OutStream(self, CHAR_ADJUST); + } +#if TRIO_FEATURE_QUOTE + if (flags & FLAGS_QUOTE) + self->OutStream(self, CHAR_QUOTE); +#endif +} +#endif /* TRIO_FEATURE_WIDECHAR */ + +/************************************************************************* + * TrioWriteDouble + * + * http://wwwold.dkuug.dk/JTC1/SC22/WG14/www/docs/dr_211.htm + * + * "5.2.4.2.2 paragraph #4 + * + * The accuracy [...] is implementation defined, as is the accuracy + * of the conversion between floating-point internal representations + * and string representations performed by the libray routine in + * <stdio.h>" + */ +/* FIXME: handle all instances of constant long-double number (L) + * and *l() math functions. + */ +#if TRIO_FEATURE_FLOAT +TRIO_PRIVATE void +TrioWriteDouble +TRIO_ARGS6((self, number, flags, width, precision, base), + trio_class_t *self, + trio_long_double_t number, + trio_flags_t flags, + int width, + int precision, + int base) +{ + trio_long_double_t integerNumber; + trio_long_double_t fractionNumber; + trio_long_double_t workNumber; + int integerDigits; + int fractionDigits; + int exponentDigits; + int workDigits; + int baseDigits; + int integerThreshold; + int fractionThreshold; + int expectedWidth; + int exponent = 0; + unsigned int uExponent = 0; + int exponentBase; + trio_long_double_t dblBase; + trio_long_double_t dblFractionBase; + trio_long_double_t integerAdjust; + trio_long_double_t fractionAdjust; + trio_long_double_t workFractionNumber; + trio_long_double_t workFractionAdjust; + int fractionDigitsInspect; + BOOLEAN_T isNegative; + BOOLEAN_T isExponentNegative = FALSE; + BOOLEAN_T requireTwoDigitExponent; + BOOLEAN_T isHex; + TRIO_CONST char *digits; +# if TRIO_FEATURE_QUOTE + char *groupingPointer; +# endif + int i; + int offset; + BOOLEAN_T hasOnlyZeroes; + int leadingFractionZeroes = -1; + register int trailingZeroes; + BOOLEAN_T keepTrailingZeroes; + BOOLEAN_T keepDecimalPoint; + trio_long_double_t epsilon; + BOOLEAN_T adjustNumber = FALSE; + + assert(VALID(self)); + assert(VALID(self->OutStream)); + assert(((base >= MIN_BASE) && (base <= MAX_BASE)) || (base == NO_BASE)); + + /* Determine sign and look for special quantities */ + switch (trio_fpclassify_and_signbit(number, &isNegative)) + { + case TRIO_FP_NAN: + TrioWriteString(self, + (flags & FLAGS_UPPER) + ? NAN_UPPER + : NAN_LOWER, + flags, width, precision); + return; + + case TRIO_FP_INFINITE: + if (isNegative) + { + /* Negative infinity */ + TrioWriteString(self, + (flags & FLAGS_UPPER) + ? "-" INFINITE_UPPER + : "-" INFINITE_LOWER, + flags, width, precision); + return; + } + else + { + /* Positive infinity */ + TrioWriteString(self, + (flags & FLAGS_UPPER) + ? INFINITE_UPPER + : INFINITE_LOWER, + flags, width, precision); + return; + } + + default: + /* Finitude */ + break; + } + + /* Normal numbers */ + if (flags & FLAGS_LONGDOUBLE) + { + baseDigits = (base == 10) + ? LDBL_DIG + : (int)trio_floor(LDBL_MANT_DIG / TrioLogarithmBase(base)); + epsilon = LDBL_EPSILON; + } + else if (flags & FLAGS_SHORT) + { + baseDigits = (base == BASE_DECIMAL) + ? FLT_DIG + : (int)trio_floor(FLT_MANT_DIG / TrioLogarithmBase(base)); + epsilon = FLT_EPSILON; + } + else + { + baseDigits = (base == BASE_DECIMAL) + ? DBL_DIG + : (int)trio_floor(DBL_MANT_DIG / TrioLogarithmBase(base)); + epsilon = DBL_EPSILON; + } + + digits = (flags & FLAGS_UPPER) ? internalDigitsUpper : internalDigitsLower; + isHex = (base == BASE_HEX); + if (base == NO_BASE) + base = BASE_DECIMAL; + dblBase = (trio_long_double_t)base; + keepTrailingZeroes = !( (flags & FLAGS_ROUNDING) || + ( (flags & FLAGS_FLOAT_G) && + !(flags & FLAGS_ALTERNATIVE) ) ); + +# if TRIO_FEATURE_ROUNDING + if (flags & FLAGS_ROUNDING) + { + precision = baseDigits; + } +# endif + + if (precision == NO_PRECISION) + { + if (isHex) + { + keepTrailingZeroes = FALSE; + precision = FLT_MANT_DIG; + } + else + { + precision = FLT_DIG; + } + } + + if (isNegative) + { + number = -number; + } + + if (isHex) + { + flags |= FLAGS_FLOAT_E; + } + + reprocess: + + if (flags & FLAGS_FLOAT_G) + { + if (precision == 0) + precision = 1; + + if ( (number < TRIO_SUFFIX_LONG(1.0E-4)) || + (number >= TrioPower(base, (trio_long_double_t)precision)) ) + { + /* Use scientific notation */ + flags |= FLAGS_FLOAT_E; + } + else if (number < 1.0) + { + /* + * Use normal notation. If the integer part of the number is + * zero, then adjust the precision to include leading fractional + * zeros. + */ + workNumber = TrioLogarithm(number, base); + workNumber = TRIO_FABS(workNumber); + if (workNumber - trio_floor(workNumber) < epsilon) + workNumber--; + leadingFractionZeroes = (int)trio_floor(workNumber); + } + } + + if (flags & FLAGS_FLOAT_E) + { + /* Scale the number */ + workNumber = TrioLogarithm(number, base); + if (trio_isinf(workNumber) == -1) + { + exponent = 0; + /* Undo setting */ + if (flags & FLAGS_FLOAT_G) + flags &= ~FLAGS_FLOAT_E; + } + else + { + exponent = (int)trio_floor(workNumber); + workNumber = number; + /* + * The expression A * 10^-B is equivalent to A / 10^B but the former + * usually gives better accuracy. + */ + workNumber *= TrioPower(dblBase, (trio_long_double_t)-exponent); + if (trio_isinf(workNumber)) { + /* + * Scaling is done it two steps to avoid problems with subnormal + * numbers. + */ + workNumber /= TrioPower(dblBase, (trio_long_double_t)(exponent / 2)); + workNumber /= TrioPower(dblBase, (trio_long_double_t)(exponent - (exponent / 2))); + } + number = workNumber; + isExponentNegative = (exponent < 0); + uExponent = (isExponentNegative) ? -exponent : exponent; + if (isHex) + uExponent *= 4; /* log16(2) */ +#if TRIO_FEATURE_QUOTE + /* No thousand separators */ + flags &= ~FLAGS_QUOTE; +#endif + } + } + + integerNumber = trio_floor(number); + fractionNumber = number - integerNumber; + + /* + * Truncated number. + * + * Precision is number of significant digits for FLOAT_G and number of + * fractional digits for others. + */ + integerDigits = 1; + if (integerNumber > epsilon) + { + integerDigits += (int)TrioLogarithm(integerNumber, base); + } + + fractionDigits = precision; + if (flags & FLAGS_FLOAT_G) + { + if (leadingFractionZeroes > 0) + { + fractionDigits += leadingFractionZeroes; + } + if ((integerNumber > epsilon) || (number <= epsilon)) + { + fractionDigits -= integerDigits; + } + } + + dblFractionBase = TrioPower(base, fractionDigits); + + if (integerNumber < 1.0) + { + workNumber = number * dblFractionBase + TRIO_SUFFIX_LONG(0.5); + if (trio_floor(number * dblFractionBase) != trio_floor(workNumber)) + { + adjustNumber = TRUE; + /* Remove a leading fraction zero if fraction is rounded up */ + if ((int)TrioLogarithm(number * dblFractionBase, base) != (int)TrioLogarithm(workNumber, base)) + { + --leadingFractionZeroes; + } + } + workNumber /= dblFractionBase; + } + else + { + workNumber = number + TRIO_SUFFIX_LONG(0.5) / dblFractionBase; + adjustNumber = (trio_floor(number) != trio_floor(workNumber)); + } + if (adjustNumber) + { + if ((flags & FLAGS_FLOAT_G) && !(flags & FLAGS_FLOAT_E)) + { + /* The adjustment may require a change to scientific notation */ + if ( (workNumber < TRIO_SUFFIX_LONG(1.0E-4)) || + (workNumber >= TrioPower(base, (trio_long_double_t)precision)) ) + { + /* Use scientific notation */ + flags |= FLAGS_FLOAT_E; + goto reprocess; + } + } + + if (flags & FLAGS_FLOAT_E) + { + workDigits = 1 + TrioLogarithm(trio_floor(workNumber), base); + if (integerDigits == workDigits) + { + /* Adjust if the same number of digits are used */ + number += TRIO_SUFFIX_LONG(0.5) / dblFractionBase; + integerNumber = trio_floor(number); + fractionNumber = number - integerNumber; + } + else + { + /* Adjust if number was rounded up one digit (ie. 0.99 to 1.00) */ + exponent++; + isExponentNegative = (exponent < 0); + uExponent = (isExponentNegative) ? -exponent : exponent; + if (isHex) + uExponent *= 4; /* log16(2) */ + workNumber = (number + TRIO_SUFFIX_LONG(0.5) / dblFractionBase) / dblBase; + integerNumber = trio_floor(workNumber); + fractionNumber = workNumber - integerNumber; + } + } + else + { + if (workNumber > 1.0) + { + /* Adjust if number was rounded up one digit (ie. 99 to 100) */ + integerNumber = trio_floor(workNumber); + fractionNumber = 0.0; + integerDigits = (integerNumber > epsilon) + ? 1 + (int)TrioLogarithm(integerNumber, base) + : 1; + if (flags & FLAGS_FLOAT_G) + { + if (flags & FLAGS_ALTERNATIVE) + { + fractionDigits = precision; + if ((integerNumber > epsilon) || (number <= epsilon)) + { + fractionDigits -= integerDigits; + } + } + else + { + fractionDigits = 0; + } + } + } + else + { + integerNumber = trio_floor(workNumber); + fractionNumber = workNumber - integerNumber; + if (flags & FLAGS_FLOAT_G) + { + if (flags & FLAGS_ALTERNATIVE) + { + fractionDigits = precision; + if (leadingFractionZeroes > 0) + { + fractionDigits += leadingFractionZeroes; + } + if ((integerNumber > epsilon) || (number <= epsilon)) + { + fractionDigits -= integerDigits; + } + } + } + } + } + } + + /* Estimate accuracy */ + integerAdjust = fractionAdjust = TRIO_SUFFIX_LONG(0.5); +# if TRIO_FEATURE_ROUNDING + if (flags & FLAGS_ROUNDING) + { + if (integerDigits > baseDigits) + { + integerThreshold = baseDigits; + fractionDigits = 0; + dblFractionBase = 1.0; + fractionThreshold = 0; + precision = 0; /* Disable decimal-point */ + integerAdjust = TrioPower(base, integerDigits - integerThreshold - 1); + fractionAdjust = 0.0; + } + else + { + integerThreshold = integerDigits; + fractionThreshold = fractionDigits - integerThreshold; + fractionAdjust = 1.0; + } + } + else +# endif + { + integerThreshold = INT_MAX; + fractionThreshold = INT_MAX; + } + + /* + * Calculate expected width. + * sign + integer part + thousands separators + decimal point + * + fraction + exponent + */ + fractionAdjust /= dblFractionBase; + hasOnlyZeroes = (trio_floor((fractionNumber + fractionAdjust) * + dblFractionBase) < epsilon); + keepDecimalPoint = ( (flags & FLAGS_ALTERNATIVE) || + !((precision == 0) || + (!keepTrailingZeroes && hasOnlyZeroes)) ); + + expectedWidth = integerDigits + fractionDigits; + + if (!keepTrailingZeroes) + { + trailingZeroes = 0; + workFractionNumber = fractionNumber; + workFractionAdjust = fractionAdjust; + fractionDigitsInspect = fractionDigits; + + if (integerDigits > integerThreshold) + { + fractionDigitsInspect = 0; + } + else if (fractionThreshold <= fractionDigits) + { + fractionDigitsInspect = fractionThreshold + 1; + } + + trailingZeroes = fractionDigits - fractionDigitsInspect; + for (i = 0; i < fractionDigitsInspect; i++) + { + workFractionNumber *= dblBase; + workFractionAdjust *= dblBase; + workNumber = trio_floor(workFractionNumber + workFractionAdjust); + workFractionNumber -= workNumber; + offset = (int)trio_fmod(workNumber, dblBase); + if (offset == 0) + { + trailingZeroes++; + } + else + { + trailingZeroes = 0; + } + } + expectedWidth -= trailingZeroes; + } + + if (keepDecimalPoint) + { + expectedWidth += internalDecimalPointLength; + } + +#if TRIO_FEATURE_QUOTE + if (flags & FLAGS_QUOTE) + { + expectedWidth += TrioCalcThousandSeparatorLength(integerDigits); + } +#endif + + if (isNegative || (flags & FLAGS_SHOWSIGN) || (flags & FLAGS_SPACE)) + { + expectedWidth += sizeof("-") - 1; + } + + exponentDigits = 0; + if (flags & FLAGS_FLOAT_E) + { + exponentDigits = (uExponent == 0) + ? 1 + : (int)trio_ceil(TrioLogarithm((double)(uExponent + 1), + (isHex) ? 10 : base)); + } + requireTwoDigitExponent = ((base == BASE_DECIMAL) && (exponentDigits == 1)); + if (exponentDigits > 0) + { + expectedWidth += exponentDigits; + expectedWidth += (requireTwoDigitExponent + ? sizeof("E+0") - 1 + : sizeof("E+") - 1); + } + + if (isHex) + { + expectedWidth += sizeof("0X") - 1; + } + + /* Output prefixing */ + if (flags & FLAGS_NILPADDING) + { + /* Leading zeros must be after sign */ + if (isNegative) + self->OutStream(self, '-'); + else if (flags & FLAGS_SHOWSIGN) + self->OutStream(self, '+'); + else if (flags & FLAGS_SPACE) + self->OutStream(self, ' '); + if (isHex) + { + self->OutStream(self, '0'); + self->OutStream(self, (flags & FLAGS_UPPER) ? 'X' : 'x'); + } + if (!(flags & FLAGS_LEFTADJUST)) + { + for (i = expectedWidth; i < width; i++) + { + self->OutStream(self, '0'); + } + } + } + else + { + /* Leading spaces must be before sign */ + if (!(flags & FLAGS_LEFTADJUST)) + { + for (i = expectedWidth; i < width; i++) + { + self->OutStream(self, CHAR_ADJUST); + } + } + if (isNegative) + self->OutStream(self, '-'); + else if (flags & FLAGS_SHOWSIGN) + self->OutStream(self, '+'); + else if (flags & FLAGS_SPACE) + self->OutStream(self, ' '); + if (isHex) + { + self->OutStream(self, '0'); + self->OutStream(self, (flags & FLAGS_UPPER) ? 'X' : 'x'); + } + } + + /* Output the integer part and thousand separators */ + for (i = 0; i < integerDigits; i++) + { + workNumber = trio_floor(((integerNumber + integerAdjust) + / TrioPower(base, integerDigits - i - 1))); + if (i > integerThreshold) + { + /* Beyond accuracy */ + self->OutStream(self, digits[0]); + } + else + { + self->OutStream(self, digits[(int)trio_fmod(workNumber, dblBase)]); + } + +#if TRIO_FEATURE_QUOTE + if (((flags & (FLAGS_FLOAT_E | FLAGS_QUOTE)) == FLAGS_QUOTE) + && TrioFollowedBySeparator(integerDigits - i)) + { + for (groupingPointer = internalThousandSeparator; + *groupingPointer != NIL; + groupingPointer++) + { + self->OutStream(self, *groupingPointer); + } + } +#endif + } + + /* Insert decimal point and build the fraction part */ + trailingZeroes = 0; + + if (keepDecimalPoint) + { + if (internalDecimalPoint) + { + self->OutStream(self, internalDecimalPoint); + } + else + { + for (i = 0; i < internalDecimalPointLength; i++) + { + self->OutStream(self, internalDecimalPointString[i]); + } + } + } + + for (i = 0; i < fractionDigits; i++) + { + if ((integerDigits > integerThreshold) || (i > fractionThreshold)) + { + /* Beyond accuracy */ + trailingZeroes++; + } + else + { + fractionNumber *= dblBase; + fractionAdjust *= dblBase; + workNumber = trio_floor(fractionNumber + fractionAdjust); + if (workNumber > fractionNumber) + { + /* fractionNumber should never become negative */ + fractionNumber = 0.0; + fractionAdjust = 0.0; + } + else + { + fractionNumber -= workNumber; + } + offset = (int)trio_fmod(workNumber, dblBase); + if (offset == 0) + { + trailingZeroes++; + } + else + { + while (trailingZeroes > 0) + { + /* Not trailing zeroes after all */ + self->OutStream(self, digits[0]); + trailingZeroes--; + } + self->OutStream(self, digits[offset]); + } + } + } + + if (keepTrailingZeroes) + { + while (trailingZeroes > 0) + { + self->OutStream(self, digits[0]); + trailingZeroes--; + } + } + + /* Output exponent */ + if (exponentDigits > 0) + { + self->OutStream(self, + isHex + ? ((flags & FLAGS_UPPER) ? 'P' : 'p') + : ((flags & FLAGS_UPPER) ? 'E' : 'e')); + self->OutStream(self, (isExponentNegative) ? '-' : '+'); + + /* The exponent must contain at least two digits */ + if (requireTwoDigitExponent) + self->OutStream(self, '0'); + + if (isHex) + base = 10; + exponentBase = (int)TrioPower(base, exponentDigits - 1); + for (i = 0; i < exponentDigits; i++) + { + self->OutStream(self, digits[(uExponent / exponentBase) % base]); + exponentBase /= base; + } + } + /* Output trailing spaces */ + if (flags & FLAGS_LEFTADJUST) + { + for (i = expectedWidth; i < width; i++) + { + self->OutStream(self, CHAR_ADJUST); + } + } +} +#endif /* TRIO_FEATURE_FLOAT */ + +/************************************************************************* + * TrioFormatProcess + * + * Description: + * This is the main engine for formatting output + */ +TRIO_PRIVATE int +TrioFormatProcess +TRIO_ARGS3((data, format, parameters), + trio_class_t *data, + TRIO_CONST char *format, + trio_parameter_t *parameters) +{ + int i; +#if TRIO_FEATURE_ERRNO + TRIO_CONST char *string; +#endif + trio_pointer_t pointer; + trio_flags_t flags; + int width; + int precision; + int base; + int offset; + + offset = 0; + i = 0; + + for (;;) + { + /* Skip the parameter entries */ + while (parameters[i].type == FORMAT_PARAMETER) + i++; + + /* Copy non conversion-specifier part of format string */ + while (offset < parameters[i].beginOffset) + { + if (CHAR_IDENTIFIER == format[offset] && CHAR_IDENTIFIER == format[offset + 1]) + { + data->OutStream(data, CHAR_IDENTIFIER); + offset += 2; + } + else + { + data->OutStream(data, format[offset++]); + } + } + + /* Abort if we reached end of format string */ + if (parameters[i].type == FORMAT_SENTINEL) + break; + + /* Ouput parameter */ + flags = parameters[i].flags; + + /* Find width */ + width = parameters[i].width; + if (flags & FLAGS_WIDTH_PARAMETER) + { + /* Get width from parameter list */ + width = (int)parameters[width].data.number.as_signed; + if (width < 0) + { + /* + * A negative width is the same as the - flag and + * a positive width. + */ + flags |= FLAGS_LEFTADJUST; + flags &= ~FLAGS_NILPADDING; + width = -width; + } + } + + /* Find precision */ + if (flags & FLAGS_PRECISION) + { + precision = parameters[i].precision; + if (flags & FLAGS_PRECISION_PARAMETER) + { + /* Get precision from parameter list */ + precision = (int)parameters[precision].data.number.as_signed; + if (precision < 0) + { + /* + * A negative precision is the same as no + * precision + */ + precision = NO_PRECISION; + } + } + } + else + { + precision = NO_PRECISION; + } + + /* Find base */ + if (NO_BASE != parameters[i].baseSpecifier) + { + /* Base from specifier has priority */ + base = parameters[i].baseSpecifier; + } + else if (flags & FLAGS_BASE_PARAMETER) + { + /* Get base from parameter list */ + base = parameters[i].base; + base = (int)parameters[base].data.number.as_signed; + } + else + { + /* Use base from format string */ + base = parameters[i].base; + } + + switch (parameters[i].type) + { + case FORMAT_CHAR: +#if TRIO_FEATURE_QUOTE + if (flags & FLAGS_QUOTE) + data->OutStream(data, CHAR_QUOTE); +#endif + if (! (flags & FLAGS_LEFTADJUST)) + { + while (--width > 0) + data->OutStream(data, CHAR_ADJUST); + } +#if TRIO_FEATURE_WIDECHAR + if (flags & FLAGS_WIDECHAR) + { + TrioWriteWideStringCharacter(data, + (trio_wchar_t)parameters[i].data.number.as_signed, + flags, + NO_WIDTH); + } + else +#endif + { + TrioWriteStringCharacter(data, + (int)parameters[i].data.number.as_signed, + flags); + } + + if (flags & FLAGS_LEFTADJUST) + { + while(--width > 0) + data->OutStream(data, CHAR_ADJUST); + } +#if TRIO_FEATURE_QUOTE + if (flags & FLAGS_QUOTE) + data->OutStream(data, CHAR_QUOTE); +#endif + + break; /* FORMAT_CHAR */ + + case FORMAT_INT: + TrioWriteNumber(data, + parameters[i].data.number.as_unsigned, + flags, + width, + precision, + base); + + break; /* FORMAT_INT */ + +#if TRIO_FEATURE_FLOAT + case FORMAT_DOUBLE: + TrioWriteDouble(data, + parameters[i].data.longdoubleNumber, + flags, + width, + precision, + base); + break; /* FORMAT_DOUBLE */ +#endif + + case FORMAT_STRING: +#if TRIO_FEATURE_WIDECHAR + if (flags & FLAGS_WIDECHAR) + { + TrioWriteWideString(data, + parameters[i].data.wstring, + flags, + width, + precision); + } + else +#endif + { + TrioWriteString(data, + parameters[i].data.string, + flags, + width, + precision); + } + break; /* FORMAT_STRING */ + + case FORMAT_POINTER: + { + trio_reference_t reference; + + reference.data = data; + reference.parameter = ¶meters[i]; + trio_print_pointer(&reference, parameters[i].data.pointer); + } + break; /* FORMAT_POINTER */ + + case FORMAT_COUNT: + pointer = parameters[i].data.pointer; + if (NULL != pointer) + { + /* + * C99 paragraph 7.19.6.1.8 says "the number of + * characters written to the output stream so far by + * this call", which is data->actually.committed + */ +#if TRIO_FEATURE_SIZE_T || TRIO_FEATURE_SIZE_T_UPPER + if (flags & FLAGS_SIZE_T) + *(size_t *)pointer = (size_t)data->actually.committed; + else +#endif +#if TRIO_FEATURE_PTRDIFF_T + if (flags & FLAGS_PTRDIFF_T) + *(ptrdiff_t *)pointer = (ptrdiff_t)data->actually.committed; + else +#endif +#if TRIO_FEATURE_INTMAX_T + if (flags & FLAGS_INTMAX_T) + *(trio_intmax_t *)pointer = (trio_intmax_t)data->actually.committed; + else +#endif + if (flags & FLAGS_QUAD) + { + *(trio_ulonglong_t *)pointer = (trio_ulonglong_t)data->actually.committed; + } + else if (flags & FLAGS_LONG) + { + *(long int *)pointer = (long int)data->actually.committed; + } + else if (flags & FLAGS_SHORT) + { + *(short int *)pointer = (short int)data->actually.committed; + } + else + { + *(int *)pointer = (int)data->actually.committed; + } + } + break; /* FORMAT_COUNT */ + + case FORMAT_PARAMETER: + break; /* FORMAT_PARAMETER */ + +#if TRIO_FEATURE_ERRNO + case FORMAT_ERRNO: + string = trio_error(parameters[i].data.errorNumber); + if (string) + { + TrioWriteString(data, + string, + flags, + width, + precision); + } + else + { + data->OutStream(data, '#'); + TrioWriteNumber(data, + (trio_uintmax_t)parameters[i].data.errorNumber, + flags, + width, + precision, + BASE_DECIMAL); + } + break; /* FORMAT_ERRNO */ +#endif /* TRIO_FEATURE_ERRNO */ + +#if TRIO_FEATURE_USER_DEFINED + case FORMAT_USER_DEFINED: + { + trio_reference_t reference; + trio_userdef_t *def = NULL; + + if (parameters[i].flags & FLAGS_USER_DEFINED_PARAMETER) + { + /* Use handle */ + if ((i > 0) || + (parameters[i - 1].type == FORMAT_PARAMETER)) + def = (trio_userdef_t *)parameters[i - 1].data.pointer; + } + else + { + /* Look up namespace */ + def = TrioFindNamespace(parameters[i].user_defined.namespace, NULL); + } + if (def) + { + reference.data = data; + reference.parameter = ¶meters[i]; + def->callback(&reference); + } + } + break; +#endif /* TRIO_FEATURE_USER_DEFINED */ + + default: + break; + } /* switch parameter type */ + + /* Prepare for next */ + offset = parameters[i].endOffset; + i++; + } + + return data->processed; +} + +/************************************************************************* + * TrioFormatRef + */ +#if TRIO_EXTENSION +TRIO_PRIVATE int +TrioFormatRef +TRIO_ARGS5((reference, format, arglist, argfunc, argarray), + trio_reference_t *reference, + TRIO_CONST char *format, + va_list arglist, + trio_argfunc_t argfunc, + trio_pointer_t *argarray) +{ + int status; + trio_parameter_t parameters[MAX_PARAMETERS]; + + status = TrioParse(TYPE_PRINT, format, parameters, arglist, argfunc, argarray); + if (status < 0) + return status; + + status = TrioFormatProcess(reference->data, format, parameters); + if (reference->data->error != 0) + { + status = reference->data->error; + } + return status; +} +#endif /* TRIO_EXTENSION */ + +/************************************************************************* + * TrioFormat + */ +TRIO_PRIVATE int +TrioFormat +TRIO_ARGS7((destination, destinationSize, OutStream, format, arglist, argfunc, argarray), + trio_pointer_t destination, + size_t destinationSize, + void (*OutStream) TRIO_PROTO((trio_class_t *, int)), + TRIO_CONST char *format, + va_list arglist, + trio_argfunc_t argfunc, + trio_pointer_t *argarray) +{ + int status; + trio_class_t data; + trio_parameter_t parameters[MAX_PARAMETERS]; + + assert(VALID(OutStream)); + assert(VALID(format)); + + memset(&data, 0, sizeof(data)); + data.OutStream = OutStream; + data.location = destination; + data.max = destinationSize; + data.error = 0; + +#if defined(USE_LOCALE) + if (NULL == internalLocaleValues) + { + TrioSetLocale(); + } +#endif + + status = TrioParse(TYPE_PRINT, format, parameters, arglist, argfunc, argarray); + if (status < 0) + return status; + + status = TrioFormatProcess(&data, format, parameters); + if (data.error != 0) + { + status = data.error; + } + return status; +} + +/************************************************************************* + * TrioOutStreamFile + */ +#if TRIO_FEATURE_FILE || TRIO_FEATURE_STDIO +TRIO_PRIVATE void +TrioOutStreamFile +TRIO_ARGS2((self, output), + trio_class_t *self, + int output) +{ + FILE *file; + + assert(VALID(self)); + assert(VALID(self->location)); + + file = (FILE *)self->location; + self->processed++; + if (fputc(output, file) == EOF) + { + self->error = TRIO_ERROR_RETURN(TRIO_EOF, 0); + } + else + { + self->actually.committed++; + } +} +#endif /* TRIO_FEATURE_FILE || TRIO_FEATURE_STDIO */ + +/************************************************************************* + * TrioOutStreamFileDescriptor + */ +#if TRIO_FEATURE_FD +TRIO_PRIVATE void +TrioOutStreamFileDescriptor +TRIO_ARGS2((self, output), + trio_class_t *self, + int output) +{ + int fd; + char ch; + + assert(VALID(self)); + + fd = *((int *)self->location); + ch = (char)output; + self->processed++; + if (write(fd, &ch, sizeof(char)) == -1) + { + self->error = TRIO_ERROR_RETURN(TRIO_ERRNO, 0); + } + else + { + self->actually.committed++; + } +} +#endif /* TRIO_FEATURE_FD */ + +/************************************************************************* + * TrioOutStreamCustom + */ +#if TRIO_FEATURE_CLOSURE +TRIO_PRIVATE void +TrioOutStreamCustom +TRIO_ARGS2((self, output), + trio_class_t *self, + int output) +{ + int status; + trio_custom_t *data; + + assert(VALID(self)); + assert(VALID(self->location)); + + data = (trio_custom_t *)self->location; + if (data->stream.out) + { + status = (data->stream.out)(data->closure, output); + if (status >= 0) + { + self->actually.committed++; + } + else + { + if (self->error == 0) + { + self->error = TRIO_ERROR_RETURN(TRIO_ECUSTOM, -status); + } + } + } + self->processed++; +} +#endif /* TRIO_FEATURE_CLOSURE */ + +/************************************************************************* + * TrioOutStreamString + */ +TRIO_PRIVATE void +TrioOutStreamString +TRIO_ARGS2((self, output), + trio_class_t *self, + int output) +{ + char **buffer; + + assert(VALID(self)); + assert(VALID(self->location)); + + buffer = (char **)self->location; + **buffer = (char)output; + (*buffer)++; + self->processed++; + self->actually.committed++; +} + +/************************************************************************* + * TrioOutStreamStringMax + */ +TRIO_PRIVATE void +TrioOutStreamStringMax +TRIO_ARGS2((self, output), + trio_class_t *self, + int output) +{ + char **buffer; + + assert(VALID(self)); + assert(VALID(self->location)); + + buffer = (char **)self->location; + + if (self->processed < self->max) + { + **buffer = (char)output; + (*buffer)++; + self->actually.committed++; + } + self->processed++; +} + +/************************************************************************* + * TrioOutStreamStringDynamic + */ +#if TRIO_FEATURE_DYNAMICSTRING +TRIO_PRIVATE void +TrioOutStreamStringDynamic +TRIO_ARGS2((self, output), + trio_class_t *self, + int output) +{ + assert(VALID(self)); + assert(VALID(self->location)); + + if (self->error == 0) + { + trio_xstring_append_char((trio_string_t *)self->location, + (char)output); + self->actually.committed++; + } + /* The processed variable must always be increased */ + self->processed++; +} +#endif /* TRIO_FEATURE_DYNAMICSTRING */ + +/************************************************************************* + * TrioArrayGetter + */ +trio_pointer_t TrioArrayGetter(trio_pointer_t context, int index, int type) +{ + /* Utility function for the printfv family */ + trio_pointer_t *argarray = (trio_pointer_t *)context; + return argarray[index]; +} + +/************************************************************************* + * + * Formatted printing functions + * + ************************************************************************/ + +/** @addtogroup Printf + @{ +*/ + +/************************************************************************* + * printf + */ + +/** + Print to standard output stream. + + @param format Formatting string. + @param ... Arguments. + @return Number of printed characters. + */ +#if TRIO_FEATURE_STDIO +TRIO_PUBLIC int +trio_printf +TRIO_VARGS2((format, va_alist), + TRIO_CONST char *format, + TRIO_VA_DECL) +{ + int status; + va_list args; + + assert(VALID(format)); + + TRIO_VA_START(args, format); + status = TrioFormat(stdout, 0, TrioOutStreamFile, format, args, NULL, NULL); + TRIO_VA_END(args); + return status; +} +#endif /* TRIO_FEATURE_STDIO */ + +/** + Print to standard output stream. + + @param format Formatting string. + @param args Arguments. + @return Number of printed characters. + */ +#if TRIO_FEATURE_STDIO +TRIO_PUBLIC int +trio_vprintf +TRIO_ARGS2((format, args), + TRIO_CONST char *format, + va_list args) +{ + assert(VALID(format)); + + return TrioFormat(stdout, 0, TrioOutStreamFile, format, args, NULL, NULL); +} +#endif /* TRIO_FEATURE_STDIO */ + +/** + Print to standard output stream. + + @param format Formatting string. + @param args Arguments. + @return Number of printed characters. + */ +#if TRIO_FEATURE_STDIO +TRIO_PUBLIC int +trio_printfv +TRIO_ARGS2((format, args), + TRIO_CONST char *format, + trio_pointer_t * args) +{ + static va_list unused; + + assert(VALID(format)); + + return TrioFormat(stdout, 0, TrioOutStreamFile, format, + unused, TrioArrayGetter, args); +} +#endif /* TRIO_FEATURE_STDIO */ + +/************************************************************************* + * fprintf + */ + +/** + Print to file. + + @param file File pointer. + @param format Formatting string. + @param ... Arguments. + @return Number of printed characters. + */ +#if TRIO_FEATURE_FILE +TRIO_PUBLIC int +trio_fprintf +TRIO_VARGS3((file, format, va_alist), + FILE *file, + TRIO_CONST char *format, + TRIO_VA_DECL) +{ + int status; + va_list args; + + assert(VALID(file)); + assert(VALID(format)); + + TRIO_VA_START(args, format); + status = TrioFormat(file, 0, TrioOutStreamFile, format, args, NULL, NULL); + TRIO_VA_END(args); + return status; +} +#endif /* TRIO_FEATURE_FILE */ + +/** + Print to file. + + @param file File pointer. + @param format Formatting string. + @param args Arguments. + @return Number of printed characters. + */ +#if TRIO_FEATURE_FILE +TRIO_PUBLIC int +trio_vfprintf +TRIO_ARGS3((file, format, args), + FILE *file, + TRIO_CONST char *format, + va_list args) +{ + assert(VALID(file)); + assert(VALID(format)); + + return TrioFormat(file, 0, TrioOutStreamFile, format, args, NULL, NULL); +} +#endif /* TRIO_FEATURE_FILE */ + +/** + Print to file. + + @param file File pointer. + @param format Formatting string. + @param args Arguments. + @return Number of printed characters. + */ +#if TRIO_FEATURE_FILE +TRIO_PUBLIC int +trio_fprintfv +TRIO_ARGS3((file, format, args), + FILE *file, + TRIO_CONST char *format, + trio_pointer_t * args) +{ + static va_list unused; + + assert(VALID(file)); + assert(VALID(format)); + + return TrioFormat(file, 0, TrioOutStreamFile, format, + unused, TrioArrayGetter, args); +} +#endif /* TRIO_FEATURE_FILE */ + +/************************************************************************* + * dprintf + */ + +/** + Print to file descriptor. + + @param fd File descriptor. + @param format Formatting string. + @param ... Arguments. + @return Number of printed characters. + */ +#if TRIO_FEATURE_FD +TRIO_PUBLIC int +trio_dprintf +TRIO_VARGS3((fd, format, va_alist), + int fd, + TRIO_CONST char *format, + TRIO_VA_DECL) +{ + int status; + va_list args; + + assert(VALID(format)); + + TRIO_VA_START(args, format); + status = TrioFormat(&fd, 0, TrioOutStreamFileDescriptor, format, args, NULL, NULL); + TRIO_VA_END(args); + return status; +} +#endif /* TRIO_FEATURE_FD */ + +/** + Print to file descriptor. + + @param fd File descriptor. + @param format Formatting string. + @param args Arguments. + @return Number of printed characters. + */ +#if TRIO_FEATURE_FD +TRIO_PUBLIC int +trio_vdprintf +TRIO_ARGS3((fd, format, args), + int fd, + TRIO_CONST char *format, + va_list args) +{ + assert(VALID(format)); + + return TrioFormat(&fd, 0, TrioOutStreamFileDescriptor, format, args, NULL, NULL); +} +#endif /* TRIO_FEATURE_FD */ + +/** + Print to file descriptor. + + @param fd File descriptor. + @param format Formatting string. + @param args Arguments. + @return Number of printed characters. + */ +#if TRIO_FEATURE_FD +TRIO_PUBLIC int +trio_dprintfv +TRIO_ARGS3((fd, format, args), + int fd, + TRIO_CONST char *format, + trio_pointer_t *args) +{ + static va_list unused; + + assert(VALID(format)); + + return TrioFormat(&fd, 0, TrioOutStreamFileDescriptor, format, + unused, TrioArrayGetter, args); +} +#endif /* TRIO_FEATURE_FD */ + +/************************************************************************* + * cprintf + */ +#if TRIO_FEATURE_CLOSURE +TRIO_PUBLIC int +trio_cprintf +TRIO_VARGS4((stream, closure, format, va_alist), + trio_outstream_t stream, + trio_pointer_t closure, + TRIO_CONST char *format, + TRIO_VA_DECL) +{ + int status; + va_list args; + trio_custom_t data; + + assert(VALID(stream)); + assert(VALID(format)); + + TRIO_VA_START(args, format); + data.stream.out = stream; + data.closure = closure; + status = TrioFormat(&data, 0, TrioOutStreamCustom, format, args, NULL, NULL); + TRIO_VA_END(args); + return status; +} +#endif /* TRIO_FEATURE_CLOSURE */ + +#if TRIO_FEATURE_CLOSURE +TRIO_PUBLIC int +trio_vcprintf +TRIO_ARGS4((stream, closure, format, args), + trio_outstream_t stream, + trio_pointer_t closure, + TRIO_CONST char *format, + va_list args) +{ + trio_custom_t data; + + assert(VALID(stream)); + assert(VALID(format)); + + data.stream.out = stream; + data.closure = closure; + return TrioFormat(&data, 0, TrioOutStreamCustom, format, args, NULL, NULL); +} +#endif /* TRIO_FEATURE_CLOSURE */ + +#if TRIO_FEATURE_CLOSURE +TRIO_PUBLIC int +trio_cprintfv +TRIO_ARGS4((stream, closure, format, args), + trio_outstream_t stream, + trio_pointer_t closure, + TRIO_CONST char *format, + trio_pointer_t *args) +{ + static va_list unused; + trio_custom_t data; + + assert(VALID(stream)); + assert(VALID(format)); + + data.stream.out = stream; + data.closure = closure; + return TrioFormat(&data, 0, TrioOutStreamCustom, format, + unused, TrioArrayGetter, args); +} +#endif /* TRIO_FEATURE_CLOSURE */ + +#if TRIO_FEATURE_CLOSURE && TRIO_FEATURE_ARGFUNC +TRIO_PUBLIC int +trio_cprintff +TRIO_ARGS5((stream, closure, format, argfunc, context), + trio_outstream_t stream, + trio_pointer_t closure, + TRIO_CONST char *format, + trio_argfunc_t argfunc, + trio_pointer_t context) +{ + static va_list unused; + trio_custom_t data; + + assert(VALID(stream)); + assert(VALID(format)); + assert(VALID(argfunc)); + + data.stream.out = stream; + data.closure = closure; + return TrioFormat(&data, 0, TrioOutStreamCustom, format, + unused, argfunc, (trio_pointer_t *)context); +} +#endif /* TRIO_FEATURE_CLOSURE && TRIO_FEATURE_ARGFUNC */ + +/************************************************************************* + * sprintf + */ + +/** + Print to string. + + @param buffer Output string. + @param format Formatting string. + @param ... Arguments. + @return Number of printed characters. + */ +TRIO_PUBLIC int +trio_sprintf +TRIO_VARGS3((buffer, format, va_alist), + char *buffer, + TRIO_CONST char *format, + TRIO_VA_DECL) +{ + int status; + va_list args; + + assert(VALID(buffer)); + assert(VALID(format)); + + TRIO_VA_START(args, format); + status = TrioFormat(&buffer, 0, TrioOutStreamString, format, args, NULL, NULL); + *buffer = NIL; /* Terminate with NIL character */ + TRIO_VA_END(args); + return status; +} + +/** + Print to string. + + @param buffer Output string. + @param format Formatting string. + @param args Arguments. + @return Number of printed characters. + */ +TRIO_PUBLIC int +trio_vsprintf +TRIO_ARGS3((buffer, format, args), + char *buffer, + TRIO_CONST char *format, + va_list args) +{ + int status; + + assert(VALID(buffer)); + assert(VALID(format)); + + status = TrioFormat(&buffer, 0, TrioOutStreamString, format, args, NULL, NULL); + *buffer = NIL; + return status; +} + +/** + Print to string. + + @param buffer Output string. + @param format Formatting string. + @param args Arguments. + @return Number of printed characters. + */ +TRIO_PUBLIC int +trio_sprintfv +TRIO_ARGS3((buffer, format, args), + char *buffer, + TRIO_CONST char *format, + trio_pointer_t *args) +{ + static va_list unused; + int status; + + assert(VALID(buffer)); + assert(VALID(format)); + + status = TrioFormat(&buffer, 0, TrioOutStreamString, format, + unused, TrioArrayGetter, args); + *buffer = NIL; + return status; +} + +/************************************************************************* + * snprintf + */ + +/** + Print at most @p max characters to string. + + @param buffer Output string. + @param max Maximum number of characters to print. + @param format Formatting string. + @param ... Arguments. + @return Number of printed characters. + */ +TRIO_PUBLIC int +trio_snprintf +TRIO_VARGS4((buffer, max, format, va_alist), + char *buffer, + size_t max, + TRIO_CONST char *format, + TRIO_VA_DECL) +{ + int status; + va_list args; + + assert(VALID(buffer) || (max == 0)); + assert(VALID(format)); + + TRIO_VA_START(args, format); + status = TrioFormat(&buffer, max > 0 ? max - 1 : 0, + TrioOutStreamStringMax, format, args, NULL, NULL); + if (max > 0) + *buffer = NIL; + TRIO_VA_END(args); + return status; +} + +/** + Print at most @p max characters to string. + + @param buffer Output string. + @param max Maximum number of characters to print. + @param format Formatting string. + @param args Arguments. + @return Number of printed characters. + */ +TRIO_PUBLIC int +trio_vsnprintf +TRIO_ARGS4((buffer, max, format, args), + char *buffer, + size_t max, + TRIO_CONST char *format, + va_list args) +{ + int status; + + assert(VALID(buffer) || (max == 0)); + assert(VALID(format)); + + status = TrioFormat(&buffer, max > 0 ? max - 1 : 0, + TrioOutStreamStringMax, format, args, NULL, NULL); + if (max > 0) + *buffer = NIL; + return status; +} + +/** + Print at most @p max characters to string. + + @param buffer Output string. + @param max Maximum number of characters to print. + @param format Formatting string. + @param args Arguments. + @return Number of printed characters. + */ +TRIO_PUBLIC int +trio_snprintfv +TRIO_ARGS4((buffer, max, format, args), + char *buffer, + size_t max, + TRIO_CONST char *format, + trio_pointer_t *args) +{ + static va_list unused; + int status; + + assert(VALID(buffer) || (max == 0)); + assert(VALID(format)); + + status = TrioFormat(&buffer, max > 0 ? max - 1 : 0, + TrioOutStreamStringMax, format, + unused, TrioArrayGetter, args); + if (max > 0) + *buffer = NIL; + return status; +} + +/************************************************************************* + * snprintfcat + * Appends the new string to the buffer string overwriting the '\0' + * character at the end of buffer. + */ +#if TRIO_EXTENSION +TRIO_PUBLIC int +trio_snprintfcat +TRIO_VARGS4((buffer, max, format, va_alist), + char *buffer, + size_t max, + TRIO_CONST char *format, + TRIO_VA_DECL) +{ + int status; + va_list args; + size_t buf_len; + + TRIO_VA_START(args, format); + + assert(VALID(buffer)); + assert(VALID(format)); + + buf_len = trio_length(buffer); + buffer = &buffer[buf_len]; + + status = TrioFormat(&buffer, max - 1 - buf_len, + TrioOutStreamStringMax, format, args, NULL, NULL); + TRIO_VA_END(args); + *buffer = NIL; + return status; +} +#endif + +#if TRIO_EXTENSION +TRIO_PUBLIC int +trio_vsnprintfcat +TRIO_ARGS4((buffer, max, format, args), + char *buffer, + size_t max, + TRIO_CONST char *format, + va_list args) +{ + int status; + size_t buf_len; + + assert(VALID(buffer)); + assert(VALID(format)); + + buf_len = trio_length(buffer); + buffer = &buffer[buf_len]; + status = TrioFormat(&buffer, max - 1 - buf_len, + TrioOutStreamStringMax, format, args, NULL, NULL); + *buffer = NIL; + return status; +} +#endif + +/************************************************************************* + * trio_aprintf + */ + +#if TRIO_DEPRECATED && TRIO_FEATURE_DYNAMICSTRING +TRIO_PUBLIC char * +trio_aprintf +TRIO_VARGS2((format, va_alist), + TRIO_CONST char *format, + TRIO_VA_DECL) +{ + va_list args; + trio_string_t *info; + char *result = NULL; + + assert(VALID(format)); + + info = trio_xstring_duplicate(""); + if (info) + { + TRIO_VA_START(args, format); + (void)TrioFormat(info, 0, TrioOutStreamStringDynamic, + format, args, NULL, NULL); + TRIO_VA_END(args); + + trio_string_terminate(info); + result = trio_string_extract(info); + trio_string_destroy(info); + } + return result; +} +#endif /* TRIO_DEPRECATED && TRIO_FEATURE_DYNAMICSTRING */ + +#if TRIO_DEPRECATED && TRIO_FEATURE_DYNAMICSTRING +TRIO_PUBLIC char * +trio_vaprintf +TRIO_ARGS2((format, args), + TRIO_CONST char *format, + va_list args) +{ + trio_string_t *info; + char *result = NULL; + + assert(VALID(format)); + + info = trio_xstring_duplicate(""); + if (info) + { + (void)TrioFormat(info, 0, TrioOutStreamStringDynamic, + format, args, NULL, NULL); + trio_string_terminate(info); + result = trio_string_extract(info); + trio_string_destroy(info); + } + return result; +} +#endif /* TRIO_DEPRECATED && TRIO_FEATURE_DYNAMICSTRING */ + +/** + Allocate and print to string. + The memory allocated and returned by @p result must be freed by the + calling application. + + @param result Output string. + @param format Formatting string. + @param ... Arguments. + @return Number of printed characters. + */ +#if TRIO_FEATURE_DYNAMICSTRING +TRIO_PUBLIC int +trio_asprintf +TRIO_VARGS3((result, format, va_alist), + char **result, + TRIO_CONST char *format, + TRIO_VA_DECL) +{ + va_list args; + int status; + trio_string_t *info; + + assert(VALID(format)); + + *result = NULL; + + info = trio_xstring_duplicate(""); + if (info == NULL) + { + status = TRIO_ERROR_RETURN(TRIO_ENOMEM, 0); + } + else + { + TRIO_VA_START(args, format); + status = TrioFormat(info, 0, TrioOutStreamStringDynamic, + format, args, NULL, NULL); + TRIO_VA_END(args); + if (status >= 0) + { + trio_string_terminate(info); + *result = trio_string_extract(info); + } + trio_string_destroy(info); + } + return status; +} +#endif /* TRIO_FEATURE_DYNAMICSTRING */ + +/** + Allocate and print to string. + The memory allocated and returned by @p result must be freed by the + calling application. + + @param result Output string. + @param format Formatting string. + @param args Arguments. + @return Number of printed characters. + */ +#if TRIO_FEATURE_DYNAMICSTRING +TRIO_PUBLIC int +trio_vasprintf +TRIO_ARGS3((result, format, args), + char **result, + TRIO_CONST char *format, + va_list args) +{ + int status; + trio_string_t *info; + + assert(VALID(format)); + + *result = NULL; + + info = trio_xstring_duplicate(""); + if (info == NULL) + { + status = TRIO_ERROR_RETURN(TRIO_ENOMEM, 0); + } + else + { + status = TrioFormat(info, 0, TrioOutStreamStringDynamic, + format, args, NULL, NULL); + if (status >= 0) + { + trio_string_terminate(info); + *result = trio_string_extract(info); + } + trio_string_destroy(info); + } + return status; +} +#endif /* TRIO_FEATURE_DYNAMICSTRING */ + +/** + Allocate and print to string. + The memory allocated and returned by @p result must be freed by the + calling application. + + @param result Output string. + @param format Formatting string. + @param args Arguments. + @return Number of printed characters. + */ +#if TRIO_FEATURE_DYNAMICSTRING +TRIO_PUBLIC int +trio_asprintfv +TRIO_ARGS3((result, format, args), + char **result, + TRIO_CONST char *format, + trio_pointer_t * args) +{ + static va_list unused; + int status; + trio_string_t *info; + + assert(VALID(format)); + + *result = NULL; + + info = trio_xstring_duplicate(""); + if (info == NULL) + { + status = TRIO_ERROR_RETURN(TRIO_ENOMEM, 0); + } + else + { + status = TrioFormat(info, 0, TrioOutStreamStringDynamic, format, + unused, TrioArrayGetter, args); + if (status >= 0) + { + trio_string_terminate(info); + *result = trio_string_extract(info); + } + trio_string_destroy(info); + } + return status; +} +#endif /* TRIO_FEATURE_DYNAMICSTRING */ + +#if defined(TRIO_DOCUMENTATION) +# include "doc/doc_printf.h" +#endif + +/** @} End of Printf documentation module */ + +/************************************************************************* + * + * CALLBACK + * + ************************************************************************/ + +#if defined(TRIO_DOCUMENTATION) +# include "doc/doc_register.h" +#endif +/** + @addtogroup UserDefined + @{ +*/ + +#if TRIO_FEATURE_USER_DEFINED + +/************************************************************************* + * trio_register + */ + +/** + Register new user-defined specifier. + + @param callback + @param name + @return Handle. + */ +TRIO_PUBLIC trio_pointer_t +trio_register +TRIO_ARGS2((callback, name), + trio_callback_t callback, + TRIO_CONST char *name) +{ + trio_userdef_t *def; + trio_userdef_t *prev = NULL; + + if (callback == NULL) + return NULL; + + if (name) + { + /* Handle built-in namespaces */ + if (name[0] == ':') + { + if (trio_equal(name, ":enter")) + { + internalEnterCriticalRegion = callback; + } + else if (trio_equal(name, ":leave")) + { + internalLeaveCriticalRegion = callback; + } + return NULL; + } + + /* Bail out if namespace is too long */ + if (trio_length(name) >= MAX_USER_NAME) + return NULL; + + /* Bail out if namespace already is registered */ + def = TrioFindNamespace(name, &prev); + if (def) + return NULL; + } + + def = (trio_userdef_t *)TRIO_MALLOC(sizeof(trio_userdef_t)); + if (def) + { + if (internalEnterCriticalRegion) + (void)internalEnterCriticalRegion(NULL); + + if (name) + { + /* Link into internal list */ + if (prev == NULL) + internalUserDef = def; + else + prev->next = def; + } + /* Initialize */ + def->callback = callback; + def->name = (name == NULL) + ? NULL + : trio_duplicate(name); + def->next = NULL; + + if (internalLeaveCriticalRegion) + (void)internalLeaveCriticalRegion(NULL); + } + return (trio_pointer_t)def; +} + +/** + Unregister an existing user-defined specifier. + + @param handle + */ +void +trio_unregister +TRIO_ARGS1((handle), + trio_pointer_t handle) +{ + trio_userdef_t *self = (trio_userdef_t *)handle; + trio_userdef_t *def; + trio_userdef_t *prev = NULL; + + assert(VALID(self)); + + if (self->name) + { + def = TrioFindNamespace(self->name, &prev); + if (def) + { + if (internalEnterCriticalRegion) + (void)internalEnterCriticalRegion(NULL); + + if (prev == NULL) + internalUserDef = internalUserDef->next; + else + prev->next = def->next; + + if (internalLeaveCriticalRegion) + (void)internalLeaveCriticalRegion(NULL); + } + trio_destroy(self->name); + } + TRIO_FREE(self); +} + +/************************************************************************* + * trio_get_format [public] + */ +TRIO_CONST char * +trio_get_format +TRIO_ARGS1((ref), + trio_pointer_t ref) +{ +#if TRIO_FEATURE_USER_DEFINED + assert(((trio_reference_t *)ref)->parameter->type == FORMAT_USER_DEFINED); +#endif + + return (((trio_reference_t *)ref)->parameter->user_data); +} + +/************************************************************************* + * trio_get_argument [public] + */ +TRIO_CONST trio_pointer_t +trio_get_argument +TRIO_ARGS1((ref), + trio_pointer_t ref) +{ +#if TRIO_FEATURE_USER_DEFINED + assert(((trio_reference_t *)ref)->parameter->type == FORMAT_USER_DEFINED); +#endif + + return ((trio_reference_t *)ref)->parameter->data.pointer; +} + +/************************************************************************* + * trio_get_width / trio_set_width [public] + */ +int +trio_get_width +TRIO_ARGS1((ref), + trio_pointer_t ref) +{ + return ((trio_reference_t *)ref)->parameter->width; +} + +void +trio_set_width +TRIO_ARGS2((ref, width), + trio_pointer_t ref, + int width) +{ + ((trio_reference_t *)ref)->parameter->width = width; +} + +/************************************************************************* + * trio_get_precision / trio_set_precision [public] + */ +int +trio_get_precision +TRIO_ARGS1((ref), + trio_pointer_t ref) +{ + return (((trio_reference_t *)ref)->parameter->precision); +} + +void +trio_set_precision +TRIO_ARGS2((ref, precision), + trio_pointer_t ref, + int precision) +{ + ((trio_reference_t *)ref)->parameter->precision = precision; +} + +/************************************************************************* + * trio_get_base / trio_set_base [public] + */ +int +trio_get_base +TRIO_ARGS1((ref), + trio_pointer_t ref) +{ + return (((trio_reference_t *)ref)->parameter->base); +} + +void +trio_set_base +TRIO_ARGS2((ref, base), + trio_pointer_t ref, + int base) +{ + ((trio_reference_t *)ref)->parameter->base = base; +} + +/************************************************************************* + * trio_get_long / trio_set_long [public] + */ +int +trio_get_long +TRIO_ARGS1((ref), + trio_pointer_t ref) +{ + return (((trio_reference_t *)ref)->parameter->flags & FLAGS_LONG) + ? TRUE + : FALSE; +} + +void +trio_set_long +TRIO_ARGS2((ref, is_long), + trio_pointer_t ref, + int is_long) +{ + if (is_long) + ((trio_reference_t *)ref)->parameter->flags |= FLAGS_LONG; + else + ((trio_reference_t *)ref)->parameter->flags &= ~FLAGS_LONG; +} + +/************************************************************************* + * trio_get_longlong / trio_set_longlong [public] + */ +int +trio_get_longlong +TRIO_ARGS1((ref), + trio_pointer_t ref) +{ + return (((trio_reference_t *)ref)->parameter->flags & FLAGS_QUAD) + ? TRUE + : FALSE; +} + +void +trio_set_longlong +TRIO_ARGS2((ref, is_longlong), + trio_pointer_t ref, + int is_longlong) +{ + if (is_longlong) + ((trio_reference_t *)ref)->parameter->flags |= FLAGS_QUAD; + else + ((trio_reference_t *)ref)->parameter->flags &= ~FLAGS_QUAD; +} + +/************************************************************************* + * trio_get_longdouble / trio_set_longdouble [public] + */ +# if TRIO_FEATURE_FLOAT +int +trio_get_longdouble +TRIO_ARGS1((ref), + trio_pointer_t ref) +{ + return (((trio_reference_t *)ref)->parameter->flags & FLAGS_LONGDOUBLE) + ? TRUE + : FALSE; +} + +void +trio_set_longdouble +TRIO_ARGS2((ref, is_longdouble), + trio_pointer_t ref, + int is_longdouble) +{ + if (is_longdouble) + ((trio_reference_t *)ref)->parameter->flags |= FLAGS_LONGDOUBLE; + else + ((trio_reference_t *)ref)->parameter->flags &= ~FLAGS_LONGDOUBLE; +} +# endif /* TRIO_FEATURE_FLOAT */ + +/************************************************************************* + * trio_get_short / trio_set_short [public] + */ +int +trio_get_short +TRIO_ARGS1((ref), + trio_pointer_t ref) +{ + return (((trio_reference_t *)ref)->parameter->flags & FLAGS_SHORT) + ? TRUE + : FALSE; +} + +void +trio_set_short +TRIO_ARGS2((ref, is_short), + trio_pointer_t ref, + int is_short) +{ + if (is_short) + ((trio_reference_t *)ref)->parameter->flags |= FLAGS_SHORT; + else + ((trio_reference_t *)ref)->parameter->flags &= ~FLAGS_SHORT; +} + +/************************************************************************* + * trio_get_shortshort / trio_set_shortshort [public] + */ +int +trio_get_shortshort +TRIO_ARGS1((ref), + trio_pointer_t ref) +{ + return (((trio_reference_t *)ref)->parameter->flags & FLAGS_SHORTSHORT) + ? TRUE + : FALSE; +} + +void +trio_set_shortshort +TRIO_ARGS2((ref, is_shortshort), + trio_pointer_t ref, + int is_shortshort) +{ + if (is_shortshort) + ((trio_reference_t *)ref)->parameter->flags |= FLAGS_SHORTSHORT; + else + ((trio_reference_t *)ref)->parameter->flags &= ~FLAGS_SHORTSHORT; +} + +/************************************************************************* + * trio_get_alternative / trio_set_alternative [public] + */ +int +trio_get_alternative +TRIO_ARGS1((ref), + trio_pointer_t ref) +{ + return (((trio_reference_t *)ref)->parameter->flags & FLAGS_ALTERNATIVE) + ? TRUE + : FALSE; +} + +void +trio_set_alternative +TRIO_ARGS2((ref, is_alternative), + trio_pointer_t ref, + int is_alternative) +{ + if (is_alternative) + ((trio_reference_t *)ref)->parameter->flags |= FLAGS_ALTERNATIVE; + else + ((trio_reference_t *)ref)->parameter->flags &= ~FLAGS_ALTERNATIVE; +} + +/************************************************************************* + * trio_get_alignment / trio_set_alignment [public] + */ +int +trio_get_alignment +TRIO_ARGS1((ref), + trio_pointer_t ref) +{ + return (((trio_reference_t *)ref)->parameter->flags & FLAGS_LEFTADJUST) + ? TRUE + : FALSE; +} + +void +trio_set_alignment +TRIO_ARGS2((ref, is_leftaligned), + trio_pointer_t ref, + int is_leftaligned) +{ + if (is_leftaligned) + ((trio_reference_t *)ref)->parameter->flags |= FLAGS_LEFTADJUST; + else + ((trio_reference_t *)ref)->parameter->flags &= ~FLAGS_LEFTADJUST; +} + +/************************************************************************* + * trio_get_spacing /trio_set_spacing [public] + */ +int +trio_get_spacing +TRIO_ARGS1((ref), + trio_pointer_t ref) +{ + return (((trio_reference_t *)ref)->parameter->flags & FLAGS_SPACE) + ? TRUE + : FALSE; +} + +void +trio_set_spacing +TRIO_ARGS2((ref, is_space), + trio_pointer_t ref, + int is_space) +{ + if (is_space) + ((trio_reference_t *)ref)->parameter->flags |= FLAGS_SPACE; + else + ((trio_reference_t *)ref)->parameter->flags &= ~FLAGS_SPACE; +} + +/************************************************************************* + * trio_get_sign / trio_set_sign [public] + */ +int +trio_get_sign +TRIO_ARGS1((ref), + trio_pointer_t ref) +{ + return (((trio_reference_t *)ref)->parameter->flags & FLAGS_SHOWSIGN) + ? TRUE + : FALSE; +} + +void +trio_set_sign +TRIO_ARGS2((ref, is_sign), + trio_pointer_t ref, + int is_sign) +{ + if (is_sign) + ((trio_reference_t *)ref)->parameter->flags |= FLAGS_SHOWSIGN; + else + ((trio_reference_t *)ref)->parameter->flags &= ~FLAGS_SHOWSIGN; +} + +/************************************************************************* + * trio_get_padding / trio_set_padding [public] + */ +int +trio_get_padding +TRIO_ARGS1((ref), + trio_pointer_t ref) +{ + return (((trio_reference_t *)ref)->parameter->flags & FLAGS_NILPADDING) + ? TRUE + : FALSE; +} + +void +trio_set_padding +TRIO_ARGS2((ref, is_padding), + trio_pointer_t ref, + int is_padding) +{ + if (is_padding) + ((trio_reference_t *)ref)->parameter->flags |= FLAGS_NILPADDING; + else + ((trio_reference_t *)ref)->parameter->flags &= ~FLAGS_NILPADDING; +} + +/************************************************************************* + * trio_get_quote / trio_set_quote [public] + */ +# if TRIO_FEATURE_QUOTE +int +trio_get_quote +TRIO_ARGS1((ref), + trio_pointer_t ref) +{ + return (((trio_reference_t *)ref)->parameter->flags & FLAGS_QUOTE) + ? TRUE + : FALSE; +} + +void +trio_set_quote +TRIO_ARGS2((ref, is_quote), + trio_pointer_t ref, + int is_quote) +{ + if (is_quote) + ((trio_reference_t *)ref)->parameter->flags |= FLAGS_QUOTE; + else + ((trio_reference_t *)ref)->parameter->flags &= ~FLAGS_QUOTE; +} +#endif /* TRIO_FEATURE_QUOTE */ + +/************************************************************************* + * trio_get_upper / trio_set_upper [public] + */ +int +trio_get_upper +TRIO_ARGS1((ref), + trio_pointer_t ref) +{ + return (((trio_reference_t *)ref)->parameter->flags & FLAGS_UPPER) + ? TRUE + : FALSE; +} + +void +trio_set_upper +TRIO_ARGS2((ref, is_upper), + trio_pointer_t ref, + int is_upper) +{ + if (is_upper) + ((trio_reference_t *)ref)->parameter->flags |= FLAGS_UPPER; + else + ((trio_reference_t *)ref)->parameter->flags &= ~FLAGS_UPPER; +} + +/************************************************************************* + * trio_get_largest / trio_set_largest [public] + */ +#if TRIO_FEATURE_INTMAX_T +int +trio_get_largest +TRIO_ARGS1((ref), + trio_pointer_t ref) +{ + return (((trio_reference_t *)ref)->parameter->flags & FLAGS_INTMAX_T) + ? TRUE + : FALSE; +} + +void +trio_set_largest +TRIO_ARGS2((ref, is_largest), + trio_pointer_t ref, + int is_largest) +{ + if (is_largest) + ((trio_reference_t *)ref)->parameter->flags |= FLAGS_INTMAX_T; + else + ((trio_reference_t *)ref)->parameter->flags &= ~FLAGS_INTMAX_T; +} +#endif /* TRIO_FEATURE_INTMAX_T */ + +/************************************************************************* + * trio_get_ptrdiff / trio_set_ptrdiff [public] + */ +#if TRIO_FEATURE_PTRDIFF_T +int +trio_get_ptrdiff +TRIO_ARGS1((ref), + trio_pointer_t ref) +{ + return (((trio_reference_t *)ref)->parameter->flags & FLAGS_PTRDIFF_T) + ? TRUE + : FALSE; +} + +void +trio_set_ptrdiff +TRIO_ARGS2((ref, is_ptrdiff), + trio_pointer_t ref, + int is_ptrdiff) +{ + if (is_ptrdiff) + ((trio_reference_t *)ref)->parameter->flags |= FLAGS_PTRDIFF_T; + else + ((trio_reference_t *)ref)->parameter->flags &= ~FLAGS_PTRDIFF_T; +} +#endif /* TRIO_FEATURE_PTRDIFF_T */ + +/************************************************************************* + * trio_get_size / trio_set_size [public] + */ +#if TRIO_FEATURE_SIZE_T +int +trio_get_size +TRIO_ARGS1((ref), + trio_pointer_t ref) +{ + return (((trio_reference_t *)ref)->parameter->flags & FLAGS_SIZE_T) + ? TRUE + : FALSE; +} + +void +trio_set_size +TRIO_ARGS2((ref, is_size), + trio_pointer_t ref, + int is_size) +{ + if (is_size) + ((trio_reference_t *)ref)->parameter->flags |= FLAGS_SIZE_T; + else + ((trio_reference_t *)ref)->parameter->flags &= ~FLAGS_SIZE_T; +} +#endif /* TRIO_FEATURE_SIZE_T */ + +/************************************************************************* + * trio_print_int [public] + */ +void +trio_print_int +TRIO_ARGS2((ref, number), + trio_pointer_t ref, + int number) +{ + trio_reference_t *self = (trio_reference_t *)ref; + + TrioWriteNumber(self->data, + (trio_uintmax_t)number, + self->parameter->flags, + self->parameter->width, + self->parameter->precision, + self->parameter->base); +} + +/************************************************************************* + * trio_print_uint [public] + */ +void +trio_print_uint +TRIO_ARGS2((ref, number), + trio_pointer_t ref, + unsigned int number) +{ + trio_reference_t *self = (trio_reference_t *)ref; + + TrioWriteNumber(self->data, + (trio_uintmax_t)number, + self->parameter->flags | FLAGS_UNSIGNED, + self->parameter->width, + self->parameter->precision, + self->parameter->base); +} + +/************************************************************************* + * trio_print_double [public] + */ +#if TRIO_FEATURE_FLOAT +void +trio_print_double +TRIO_ARGS2((ref, number), + trio_pointer_t ref, + double number) +{ + trio_reference_t *self = (trio_reference_t *)ref; + + TrioWriteDouble(self->data, + number, + self->parameter->flags, + self->parameter->width, + self->parameter->precision, + self->parameter->base); +} +#endif /* TRIO_FEATURE_FLOAT */ + +/************************************************************************* + * trio_print_string [public] + */ +void +trio_print_string +TRIO_ARGS2((ref, string), + trio_pointer_t ref, + TRIO_CONST char *string) +{ + trio_reference_t *self = (trio_reference_t *)ref; + + TrioWriteString(self->data, + string, + self->parameter->flags, + self->parameter->width, + self->parameter->precision); +} + +/************************************************************************* + * trio_print_ref [public] + */ +int +trio_print_ref +TRIO_VARGS3((ref, format, va_alist), + trio_pointer_t ref, + TRIO_CONST char *format, + TRIO_VA_DECL) +{ + int status; + va_list arglist; + + assert(VALID(format)); + + TRIO_VA_START(arglist, format); + status = TrioFormatRef((trio_reference_t *)ref, format, arglist, NULL, NULL); + TRIO_VA_END(arglist); + return status; +} + +/************************************************************************* + * trio_vprint_ref [public] + */ +int +trio_vprint_ref +TRIO_ARGS3((ref, format, arglist), + trio_pointer_t ref, + TRIO_CONST char *format, + va_list arglist) +{ + assert(VALID(format)); + + return TrioFormatRef((trio_reference_t *)ref, format, arglist, NULL, NULL); +} + +/************************************************************************* + * trio_printv_ref [public] + */ +int +trio_printv_ref +TRIO_ARGS3((ref, format, argarray), + trio_pointer_t ref, + TRIO_CONST char *format, + trio_pointer_t *argarray) +{ + static va_list unused; + + assert(VALID(format)); + + return TrioFormatRef((trio_reference_t *)ref, format, + unused, TrioArrayGetter, argarray); +} + +#endif + +/************************************************************************* + * trio_print_pointer [public] + */ +void +trio_print_pointer +TRIO_ARGS2((ref, pointer), + trio_pointer_t ref, + trio_pointer_t pointer) +{ + trio_reference_t *self = (trio_reference_t *)ref; + trio_flags_t flags; + trio_uintmax_t number; + + if (NULL == pointer) + { + TRIO_CONST char *string = internalNullString; + while (*string) + self->data->OutStream(self->data, *string++); + } + else + { + /* + * The subtraction of the null pointer is a workaround + * to avoid a compiler warning. The performance overhead + * is negligible (and likely to be removed by an + * optimizing compiler). The (char *) casting is done + * to please ANSI C++. + */ + number = (trio_uintmax_t)((char *)pointer - (char *)0); + /* Shrink to size of pointer */ + number &= (trio_uintmax_t)-1; + flags = self->parameter->flags; + flags |= (FLAGS_UNSIGNED | FLAGS_ALTERNATIVE | + FLAGS_NILPADDING); + TrioWriteNumber(self->data, + number, + flags, + POINTER_WIDTH, + NO_PRECISION, + BASE_HEX); + } +} + +/** @} End of UserDefined documentation module */ + +/************************************************************************* + * + * LOCALES + * + ************************************************************************/ + +/************************************************************************* + * trio_locale_set_decimal_point + * + * Decimal point can only be one character. The input argument is a + * string to enable multibyte characters. At most MB_LEN_MAX characters + * will be used. + */ +#if TRIO_FEATURE_LOCALE +TRIO_PUBLIC void +trio_locale_set_decimal_point +TRIO_ARGS1((decimalPoint), + char *decimalPoint) +{ +#if defined(USE_LOCALE) + if (NULL == internalLocaleValues) + { + TrioSetLocale(); + } +#endif + internalDecimalPointLength = trio_length(decimalPoint); + if (internalDecimalPointLength == 1) + { + internalDecimalPoint = *decimalPoint; + } + else + { + internalDecimalPoint = NIL; + trio_copy_max(internalDecimalPointString, + sizeof(internalDecimalPointString), + decimalPoint); + } +} +#endif + +/************************************************************************* + * trio_locale_set_thousand_separator + * + * See trio_locale_set_decimal_point + */ +#if TRIO_FEATURE_LOCALE || TRIO_EXTENSION +TRIO_PUBLIC void +trio_locale_set_thousand_separator +TRIO_ARGS1((thousandSeparator), + char *thousandSeparator) +{ +# if defined(USE_LOCALE) + if (NULL == internalLocaleValues) + { + TrioSetLocale(); + } +# endif + trio_copy_max(internalThousandSeparator, + sizeof(internalThousandSeparator), + thousandSeparator); + internalThousandSeparatorLength = trio_length(internalThousandSeparator); +} +#endif + +/************************************************************************* + * trio_locale_set_grouping + * + * Array of bytes. Reversed order. + * + * CHAR_MAX : No further grouping + * 0 : Repeat last group for the remaining digits (not necessary + * as C strings are zero-terminated) + * n : Set current group to n + * + * Same order as the grouping attribute in LC_NUMERIC. + */ +#if TRIO_FEATURE_LOCALE || TRIO_EXTENSION +TRIO_PUBLIC void +trio_locale_set_grouping +TRIO_ARGS1((grouping), + char *grouping) +{ +# if defined(USE_LOCALE) + if (NULL == internalLocaleValues) + { + TrioSetLocale(); + } +# endif + trio_copy_max(internalGrouping, + sizeof(internalGrouping), + grouping); +} +#endif + + +/************************************************************************* + * + * SCANNING + * + ************************************************************************/ + +#if TRIO_FEATURE_SCANF + +/************************************************************************* + * TrioSkipWhitespaces + */ +TRIO_PRIVATE int +TrioSkipWhitespaces +TRIO_ARGS1((self), + trio_class_t *self) +{ + int ch; + + ch = self->current; + while (isspace(ch)) + { + self->InStream(self, &ch); + } + return ch; +} + +/************************************************************************* + * TrioGetCollation + */ +#if TRIO_EXTENSION +TRIO_PRIVATE void +TrioGetCollation(TRIO_NOARGS) +{ + int i; + int j; + int k; + char first[2]; + char second[2]; + + /* This is computationally expensive */ + first[1] = NIL; + second[1] = NIL; + for (i = 0; i < MAX_CHARACTER_CLASS; i++) + { + k = 0; + first[0] = (char)i; + for (j = 0; j < MAX_CHARACTER_CLASS; j++) + { + second[0] = (char)j; + if (trio_equal_locale(first, second)) + internalCollationArray[i][k++] = (char)j; + } + internalCollationArray[i][k] = NIL; + } +} +#endif + +/************************************************************************* + * TrioGetCharacterClass + * + * FIXME: + * multibyte + */ +TRIO_PRIVATE int +TrioGetCharacterClass +TRIO_ARGS4((format, offsetPointer, flagsPointer, characterclass), + TRIO_CONST char *format, + int *offsetPointer, + trio_flags_t *flagsPointer, + int *characterclass) +{ + int offset = *offsetPointer; + int i; + char ch; + char range_begin; + char range_end; + + *flagsPointer &= ~FLAGS_EXCLUDE; + + if (format[offset] == QUALIFIER_CIRCUMFLEX) + { + *flagsPointer |= FLAGS_EXCLUDE; + offset++; + } + /* + * If the ungroup character is at the beginning of the scanlist, + * it will be part of the class, and a second ungroup character + * must follow to end the group. + */ + if (format[offset] == SPECIFIER_UNGROUP) + { + characterclass[(int)SPECIFIER_UNGROUP]++; + offset++; + } + /* + * Minus is used to specify ranges. To include minus in the class, + * it must be at the beginning of the list + */ + if (format[offset] == QUALIFIER_MINUS) + { + characterclass[(int)QUALIFIER_MINUS]++; + offset++; + } + /* Collect characters */ + for (ch = format[offset]; + (ch != SPECIFIER_UNGROUP) && (ch != NIL); + ch = format[++offset]) + { + switch (ch) + { + case QUALIFIER_MINUS: /* Scanlist ranges */ + + /* + * Both C99 and UNIX98 describes ranges as implementation- + * defined. + * + * We support the following behaviour (although this may + * change as we become wiser) + * - only increasing ranges, ie. [a-b] but not [b-a] + * - transitive ranges, ie. [a-b-c] == [a-c] + * - trailing minus, ie. [a-] is interpreted as an 'a' + * and a '-' + * - duplicates (although we can easily convert these + * into errors) + */ + range_begin = format[offset - 1]; + range_end = format[++offset]; + if (range_end == SPECIFIER_UNGROUP) + { + /* Trailing minus is included */ + characterclass[(int)ch]++; + ch = range_end; + break; /* for */ + } + if (range_end == NIL) + return TRIO_ERROR_RETURN(TRIO_EINVAL, offset); + if (range_begin > range_end) + return TRIO_ERROR_RETURN(TRIO_ERANGE, offset); + + for (i = (int)range_begin; i <= (int)range_end; i++) + characterclass[i]++; + + ch = range_end; + break; + +#if TRIO_EXTENSION + + case SPECIFIER_GROUP: + + switch (format[offset + 1]) + { + case QUALIFIER_DOT: /* Collating symbol */ + /* + * FIXME: This will be easier to implement when multibyte + * characters have been implemented. Until now, we ignore + * this feature. + */ + for (i = offset + 2; ; i++) + { + if (format[i] == NIL) + /* Error in syntax */ + return -1; + else if (format[i] == QUALIFIER_DOT) + break; /* for */ + } + if (format[++i] != SPECIFIER_UNGROUP) + return -1; + + offset = i; + break; + + case QUALIFIER_EQUAL: /* Equivalence class expressions */ + { + unsigned int j; + unsigned int k; + + if (internalCollationUnconverted) + { + /* Lazy evaluation of collation array */ + TrioGetCollation(); + internalCollationUnconverted = FALSE; + } + for (i = offset + 2; ; i++) + { + if (format[i] == NIL) + /* Error in syntax */ + return -1; + else if (format[i] == QUALIFIER_EQUAL) + break; /* for */ + else + { + /* Mark any equivalent character */ + k = (unsigned int)format[i]; + for (j = 0; internalCollationArray[k][j] != NIL; j++) + characterclass[(int)internalCollationArray[k][j]]++; + } + } + if (format[++i] != SPECIFIER_UNGROUP) + return -1; + + offset = i; + } + break; + + case QUALIFIER_COLON: /* Character class expressions */ + + if (trio_equal_max(CLASS_ALNUM, sizeof(CLASS_ALNUM) - 1, + &format[offset])) + { + for (i = 0; i < MAX_CHARACTER_CLASS; i++) + if (isalnum(i)) + characterclass[i]++; + offset += sizeof(CLASS_ALNUM) - 1; + } + else if (trio_equal_max(CLASS_ALPHA, sizeof(CLASS_ALPHA) - 1, + &format[offset])) + { + for (i = 0; i < MAX_CHARACTER_CLASS; i++) + if (isalpha(i)) + characterclass[i]++; + offset += sizeof(CLASS_ALPHA) - 1; + } + else if (trio_equal_max(CLASS_CNTRL, sizeof(CLASS_CNTRL) - 1, + &format[offset])) + { + for (i = 0; i < MAX_CHARACTER_CLASS; i++) + if (iscntrl(i)) + characterclass[i]++; + offset += sizeof(CLASS_CNTRL) - 1; + } + else if (trio_equal_max(CLASS_DIGIT, sizeof(CLASS_DIGIT) - 1, + &format[offset])) + { + for (i = 0; i < MAX_CHARACTER_CLASS; i++) + if (isdigit(i)) + characterclass[i]++; + offset += sizeof(CLASS_DIGIT) - 1; + } + else if (trio_equal_max(CLASS_GRAPH, sizeof(CLASS_GRAPH) - 1, + &format[offset])) + { + for (i = 0; i < MAX_CHARACTER_CLASS; i++) + if (isgraph(i)) + characterclass[i]++; + offset += sizeof(CLASS_GRAPH) - 1; + } + else if (trio_equal_max(CLASS_LOWER, sizeof(CLASS_LOWER) - 1, + &format[offset])) + { + for (i = 0; i < MAX_CHARACTER_CLASS; i++) + if (islower(i)) + characterclass[i]++; + offset += sizeof(CLASS_LOWER) - 1; + } + else if (trio_equal_max(CLASS_PRINT, sizeof(CLASS_PRINT) - 1, + &format[offset])) + { + for (i = 0; i < MAX_CHARACTER_CLASS; i++) + if (isprint(i)) + characterclass[i]++; + offset += sizeof(CLASS_PRINT) - 1; + } + else if (trio_equal_max(CLASS_PUNCT, sizeof(CLASS_PUNCT) - 1, + &format[offset])) + { + for (i = 0; i < MAX_CHARACTER_CLASS; i++) + if (ispunct(i)) + characterclass[i]++; + offset += sizeof(CLASS_PUNCT) - 1; + } + else if (trio_equal_max(CLASS_SPACE, sizeof(CLASS_SPACE) - 1, + &format[offset])) + { + for (i = 0; i < MAX_CHARACTER_CLASS; i++) + if (isspace(i)) + characterclass[i]++; + offset += sizeof(CLASS_SPACE) - 1; + } + else if (trio_equal_max(CLASS_UPPER, sizeof(CLASS_UPPER) - 1, + &format[offset])) + { + for (i = 0; i < MAX_CHARACTER_CLASS; i++) + if (isupper(i)) + characterclass[i]++; + offset += sizeof(CLASS_UPPER) - 1; + } + else if (trio_equal_max(CLASS_XDIGIT, sizeof(CLASS_XDIGIT) - 1, + &format[offset])) + { + for (i = 0; i < MAX_CHARACTER_CLASS; i++) + if (isxdigit(i)) + characterclass[i]++; + offset += sizeof(CLASS_XDIGIT) - 1; + } + else + { + characterclass[(int)ch]++; + } + break; + + default: + characterclass[(int)ch]++; + break; + } + break; + +#endif /* TRIO_EXTENSION */ + + default: + characterclass[(int)ch]++; + break; + } + } + return 0; +} + +/************************************************************************* + * TrioReadNumber + * + * We implement our own number conversion in preference of strtol and + * strtoul, because we must handle 'long long' and thousand separators. + */ +TRIO_PRIVATE BOOLEAN_T +TrioReadNumber +TRIO_ARGS5((self, target, flags, width, base), + trio_class_t *self, + trio_uintmax_t *target, + trio_flags_t flags, + int width, + int base) +{ + trio_uintmax_t number = 0; + int digit; + int count; + BOOLEAN_T isNegative = FALSE; + BOOLEAN_T gotNumber = FALSE; + int j; + + assert(VALID(self)); + assert(VALID(self->InStream)); + assert((base >= MIN_BASE && base <= MAX_BASE) || (base == NO_BASE)); + + if (internalDigitsUnconverted) + { + /* Lazy evaluation of digits array */ + memset(internalDigitArray, -1, sizeof(internalDigitArray)); + for (j = 0; j < (int)sizeof(internalDigitsLower) - 1; j++) + { + internalDigitArray[(int)internalDigitsLower[j]] = j; + internalDigitArray[(int)internalDigitsUpper[j]] = j; + } + internalDigitsUnconverted = FALSE; + } + + TrioSkipWhitespaces(self); + + /* Leading sign */ + if (self->current == '+') + { + self->InStream(self, NULL); + } + else if (self->current == '-') + { + self->InStream(self, NULL); + isNegative = TRUE; + } + + count = self->processed; + + if (flags & FLAGS_ALTERNATIVE) + { + switch (base) + { + case NO_BASE: + case BASE_OCTAL: + case BASE_HEX: + case BASE_BINARY: + if (self->current == '0') + { + self->InStream(self, NULL); + if (self->current) + { + if ((base == BASE_HEX) && + (trio_to_upper(self->current) == 'X')) + { + self->InStream(self, NULL); + } + else if ((base == BASE_BINARY) && + (trio_to_upper(self->current) == 'B')) + { + self->InStream(self, NULL); + } + } + } + else + return FALSE; + break; + default: + break; + } + } + + while (((width == NO_WIDTH) || (self->processed - count < width)) && + (! ((self->current == EOF) || isspace(self->current)))) + { + if (isascii(self->current)) + { + digit = internalDigitArray[self->current]; + /* Abort if digit is not allowed in the specified base */ + if ((digit == -1) || (digit >= base)) + break; + } +#if TRIO_FEATURE_QUOTE + else if (flags & FLAGS_QUOTE) + { + /* Compare with thousands separator */ + for (j = 0; internalThousandSeparator[j] && self->current; j++) + { + if (internalThousandSeparator[j] != self->current) + break; + + self->InStream(self, NULL); + } + if (internalThousandSeparator[j]) + break; /* Mismatch */ + else + continue; /* Match */ + } +#endif + else + break; + + number *= base; + number += digit; + gotNumber = TRUE; /* we need at least one digit */ + + self->InStream(self, NULL); + } + + /* Was anything read at all? */ + if (!gotNumber) + return FALSE; + + if (target) + *target = (isNegative) ? (trio_uintmax_t)(-((trio_intmax_t)number)) : number; + return TRUE; +} + +/************************************************************************* + * TrioReadChar + */ +TRIO_PRIVATE int +TrioReadChar +TRIO_ARGS4((self, target, flags, width), + trio_class_t *self, + char *target, + trio_flags_t flags, + int width) +{ + int i; + char ch; + trio_uintmax_t number; + + assert(VALID(self)); + assert(VALID(self->InStream)); + + for (i = 0; + (self->current != EOF) && (i < width); + i++) + { + ch = (char)self->current; + self->InStream(self, NULL); + if ((flags & FLAGS_ALTERNATIVE) && (ch == CHAR_BACKSLASH)) + { + switch (self->current) + { + case '\\': ch = '\\'; break; + case 'a': ch = '\007'; break; + case 'b': ch = '\b'; break; + case 'f': ch = '\f'; break; + case 'n': ch = '\n'; break; + case 'r': ch = '\r'; break; + case 't': ch = '\t'; break; + case 'v': ch = '\v'; break; + default: + if (isdigit(self->current)) + { + /* Read octal number */ + if (!TrioReadNumber(self, &number, 0, 3, BASE_OCTAL)) + return 0; + ch = (char)number; + } + else if (trio_to_upper(self->current) == 'X') + { + /* Read hexadecimal number */ + self->InStream(self, NULL); + if (!TrioReadNumber(self, &number, 0, 2, BASE_HEX)) + return 0; + ch = (char)number; + } + else + { + ch = (char)self->current; + } + break; + } + } + + if (target) + target[i] = ch; + } + return i + 1; +} + +/************************************************************************* + * TrioReadString + */ +TRIO_PRIVATE BOOLEAN_T +TrioReadString +TRIO_ARGS4((self, target, flags, width), + trio_class_t *self, + char *target, + trio_flags_t flags, + int width) +{ + int i; + + assert(VALID(self)); + assert(VALID(self->InStream)); + + TrioSkipWhitespaces(self); + + /* + * Continue until end of string is reached, a whitespace is encountered, + * or width is exceeded + */ + for (i = 0; + ((width == NO_WIDTH) || (i < width)) && + (! ((self->current == EOF) || isspace(self->current))); + i++) + { + if (TrioReadChar(self, (target ? &target[i] : 0), flags, 1) == 0) + break; /* for */ + } + if (target) + target[i] = NIL; + return TRUE; +} + +/************************************************************************* + * TrioReadWideChar + */ +#if TRIO_FEATURE_WIDECHAR +TRIO_PRIVATE int +TrioReadWideChar +TRIO_ARGS4((self, target, flags, width), + trio_class_t *self, + trio_wchar_t *target, + trio_flags_t flags, + int width) +{ + int i; + int j; + int size; + int amount = 0; + trio_wchar_t wch; + char buffer[MB_LEN_MAX + 1]; + + assert(VALID(self)); + assert(VALID(self->InStream)); + + for (i = 0; + (self->current != EOF) && (i < width); + i++) + { + if (isascii(self->current)) + { + if (TrioReadChar(self, buffer, flags, 1) == 0) + return 0; + buffer[1] = NIL; + } + else + { + /* + * Collect a multibyte character, by enlarging buffer until + * it contains a fully legal multibyte character, or the + * buffer is full. + */ + j = 0; + do + { + buffer[j++] = (char)self->current; + buffer[j] = NIL; + self->InStream(self, NULL); + } + while ((j < (int)sizeof(buffer)) && (mblen(buffer, (size_t)j) != j)); + } + if (target) + { + size = mbtowc(&wch, buffer, sizeof(buffer)); + if (size > 0) + target[i] = wch; + } + amount += size; + self->InStream(self, NULL); + } + return amount; +} +#endif /* TRIO_FEATURE_WIDECHAR */ + +/************************************************************************* + * TrioReadWideString + */ +#if TRIO_FEATURE_WIDECHAR +TRIO_PRIVATE BOOLEAN_T +TrioReadWideString +TRIO_ARGS4((self, target, flags, width), + trio_class_t *self, + trio_wchar_t *target, + trio_flags_t flags, + int width) +{ + int i; + int size; + + assert(VALID(self)); + assert(VALID(self->InStream)); + + TrioSkipWhitespaces(self); + +#if defined(TRIO_COMPILER_SUPPORTS_MULTIBYTE) + /* Required by TrioReadWideChar */ + (void)mblen(NULL, 0); +#endif + + /* + * Continue until end of string is reached, a whitespace is encountered, + * or width is exceeded + */ + for (i = 0; + ((width == NO_WIDTH) || (i < width)) && + (! ((self->current == EOF) || isspace(self->current))); + ) + { + size = TrioReadWideChar(self, &target[i], flags, 1); + if (size == 0) + break; /* for */ + + i += size; + } + if (target) + target[i] = WCONST('\0'); + return TRUE; +} +#endif /* TRIO_FEATURE_WIDECHAR */ + +/************************************************************************* + * TrioReadGroup + * + * Reads non-empty character groups. + * + * FIXME: characterclass does not work with multibyte characters + */ +TRIO_PRIVATE BOOLEAN_T +TrioReadGroup +TRIO_ARGS5((self, target, characterclass, flags, width), + trio_class_t *self, + char *target, + int *characterclass, + trio_flags_t flags, + int width) +{ + int ch; + int i; + + assert(VALID(self)); + assert(VALID(self->InStream)); + + ch = self->current; + for (i = 0; + ((width == NO_WIDTH) || (i < width)) && + (! ((ch == EOF) || + (((flags & FLAGS_EXCLUDE) != 0) ^ (characterclass[ch] == 0)))); + i++) + { + if (target) + target[i] = (char)ch; + self->InStream(self, &ch); + } + + if (i == 0) + return FALSE; + + /* Terminate the string if input saved */ + if (target) + target[i] = NIL; + return TRUE; +} + +/************************************************************************* + * TrioReadDouble + * + * FIXME: + * add long double + * handle base + */ +#if TRIO_FEATURE_FLOAT +TRIO_PRIVATE BOOLEAN_T +TrioReadDouble +TRIO_ARGS4((self, target, flags, width), + trio_class_t *self, + trio_pointer_t target, + trio_flags_t flags, + int width) +{ + int ch; + char doubleString[512]; + int offset = 0; + int start; +# if TRIO_FEATURE_QUOTE + int j; +# endif + BOOLEAN_T isHex = FALSE; + trio_long_double_t infinity; + + doubleString[0] = 0; + + if ((width == NO_WIDTH) || (width > (int)sizeof(doubleString) - 1)) + width = sizeof(doubleString) - 1; + + TrioSkipWhitespaces(self); + + /* + * Read entire double number from stream. trio_to_double requires + * a string as input, but InStream can be anything, so we have to + * collect all characters. + */ + ch = self->current; + if ((ch == '+') || (ch == '-')) + { + doubleString[offset++] = (char)ch; + self->InStream(self, &ch); + width--; + } + + start = offset; + switch (ch) + { + case 'n': + case 'N': + /* Not-a-number */ + if (offset != 0) + break; + /* FALLTHROUGH */ + case 'i': + case 'I': + /* Infinity */ + while (isalpha(ch) && (offset - start < width)) + { + doubleString[offset++] = (char)ch; + self->InStream(self, &ch); + } + doubleString[offset] = NIL; + + /* Case insensitive string comparison */ + if (trio_equal(&doubleString[start], INFINITE_UPPER) || + trio_equal(&doubleString[start], LONG_INFINITE_UPPER)) + { + infinity = ((start == 1) && (doubleString[0] == '-')) + ? trio_ninf() + : trio_pinf(); + if (flags & FLAGS_LONGDOUBLE) + { + *((trio_long_double_t *)target) = infinity; + } + else if (flags & FLAGS_LONG) + { + *((double *)target) = infinity; + } + else + { + *((float *)target) = infinity; + } + return TRUE; + } + if (trio_equal(doubleString, NAN_UPPER)) + { + /* NaN must not have a preceeding + nor - */ + if (flags & FLAGS_LONGDOUBLE) + { + *((trio_long_double_t *)target) = trio_nan(); + } + else if (flags & FLAGS_LONG) + { + *((double *)target) = trio_nan(); + } + else + { + *((float *)target) = trio_nan(); + } + return TRUE; + } + return FALSE; + + case '0': + doubleString[offset++] = (char)ch; + self->InStream(self, &ch); + if (trio_to_upper(ch) == 'X') + { + isHex = TRUE; + doubleString[offset++] = (char)ch; + self->InStream(self, &ch); + } + break; + + default: + break; + } + + while ((ch != EOF) && (offset - start < width)) + { + /* Integer part */ + if (isHex ? isxdigit(ch) : isdigit(ch)) + { + doubleString[offset++] = (char)ch; + self->InStream(self, &ch); + } +# if TRIO_FEATURE_QUOTE + else if (flags & FLAGS_QUOTE) + { + /* Compare with thousands separator */ + for (j = 0; internalThousandSeparator[j] && self->current; j++) + { + if (internalThousandSeparator[j] != self->current) + break; + + self->InStream(self, &ch); + } + if (internalThousandSeparator[j]) + break; /* Mismatch */ + else + continue; /* Match */ + } +# endif + else + break; /* while */ + } + if (ch == '.') + { + /* Decimal part */ + doubleString[offset++] = (char)ch; + self->InStream(self, &ch); + while ((isHex ? isxdigit(ch) : isdigit(ch)) && + (offset - start < width)) + { + doubleString[offset++] = (char)ch; + self->InStream(self, &ch); + } + } + if (isHex ? (trio_to_upper(ch) == 'P') : (trio_to_upper(ch) == 'E')) + { + /* Exponent */ + doubleString[offset++] = (char)ch; + self->InStream(self, &ch); + if ((ch == '+') || (ch == '-')) + { + doubleString[offset++] = (char)ch; + self->InStream(self, &ch); + } + while (isdigit(ch) && (offset - start < width)) + { + doubleString[offset++] = (char)ch; + self->InStream(self, &ch); + } + } + + if ((offset == start) || (*doubleString == NIL)) + return FALSE; + + doubleString[offset] = 0; + + if (flags & FLAGS_LONGDOUBLE) + { + *((trio_long_double_t *)target) = trio_to_long_double(doubleString, NULL); + } + else if (flags & FLAGS_LONG) + { + *((double *)target) = trio_to_double(doubleString, NULL); + } + else + { + *((float *)target) = trio_to_float(doubleString, NULL); + } + return TRUE; +} +#endif /* TRIO_FEATURE_FLOAT */ + +/************************************************************************* + * TrioReadPointer + */ +TRIO_PRIVATE BOOLEAN_T +TrioReadPointer +TRIO_ARGS3((self, target, flags), + trio_class_t *self, + trio_pointer_t *target, + trio_flags_t flags) +{ + trio_uintmax_t number; + char buffer[sizeof(internalNullString)]; + + flags |= (FLAGS_UNSIGNED | FLAGS_ALTERNATIVE | FLAGS_NILPADDING); + + if (TrioReadNumber(self, + &number, + flags, + POINTER_WIDTH, + BASE_HEX)) + { + if (target) + { +#if defined(TRIO_COMPILER_GCC) || defined(TRIO_COMPILER_MIPSPRO) + /* + * The strange assignment of number is a workaround for a compiler + * warning + */ + *target = &((char *)0)[number]; +#else + *target = (trio_pointer_t)number; +#endif + } + return TRUE; + } + else if (TrioReadString(self, + (flags & FLAGS_IGNORE) + ? NULL + : buffer, + 0, + sizeof(internalNullString) - 1)) + { + if (trio_equal_case(buffer, internalNullString)) + { + if (target) + *target = NULL; + return TRUE; + } + } + return FALSE; +} + +/************************************************************************* + * TrioScanProcess + */ +TRIO_PRIVATE int +TrioScanProcess +TRIO_ARGS3((data, format, parameters), + trio_class_t *data, + TRIO_CONST char *format, + trio_parameter_t *parameters) +{ + int status; + int assignment; + int ch; + int offset; /* Offset of format string */ + int i; /* Offset of current parameter */ + trio_flags_t flags; + int width; + int base; + trio_pointer_t pointer; + + /* Return on empty format string */ + if (format[0] == NIL) + return 0; + + status = 0; + assignment = 0; + i = 0; + offset = 0; + data->InStream(data, &ch); + + for (;;) + { + /* Skip the parameter entries */ + while (parameters[i].type == FORMAT_PARAMETER) + { + assert(i <= MAX_PARAMETERS); + i++; + } + + /* Compare non conversion-specifier part of format string */ + while (offset < parameters[i].beginOffset) + { + if ((CHAR_IDENTIFIER == format[offset]) && + (CHAR_IDENTIFIER == format[offset + 1])) + { + /* Two % in format matches one % in input stream */ + if (CHAR_IDENTIFIER == ch) + { + data->InStream(data, &ch); + offset += 2; + continue; /* while format chars left */ + } + else + { + status = TRIO_ERROR_RETURN(TRIO_EINVAL, offset); + goto end; + } + } + else /* Not an % identifier */ + { + if (isspace((int)format[offset])) + { + /* Whitespaces may match any amount of whitespaces */ + ch = TrioSkipWhitespaces(data); + } + else if (ch == format[offset]) + { + data->InStream(data, &ch); + } + else + { + status = assignment; + goto end; + } + + offset++; + } + } + + if (parameters[i].type == FORMAT_SENTINEL) + break; + + if ((EOF == ch) && (parameters[i].type != FORMAT_COUNT)) + { + status = (assignment > 0) ? assignment : EOF; + goto end; + } + + flags = parameters[i].flags; + + /* Find width */ + width = parameters[i].width; + if (flags & FLAGS_WIDTH_PARAMETER) + { + /* Get width from parameter list */ + width = (int)parameters[width].data.number.as_signed; + } + + /* Find base */ + if (NO_BASE != parameters[i].baseSpecifier) + { + /* Base from specifier has priority */ + base = parameters[i].baseSpecifier; + } + else if (flags & FLAGS_BASE_PARAMETER) + { + /* Get base from parameter list */ + base = parameters[i].base; + base = (int)parameters[base].data.number.as_signed; + } + else + { + /* Use base from format string */ + base = parameters[i].base; + } + + switch (parameters[i].type) + { + case FORMAT_INT: + { + trio_uintmax_t number; + + if (0 == base) + base = BASE_DECIMAL; + + if (!TrioReadNumber(data, + &number, + flags, + width, + base)) + { + status = assignment; + goto end; + } + + if (!(flags & FLAGS_IGNORE)) + { + assignment++; + + pointer = parameters[i].data.pointer; +#if TRIO_FEATURE_SIZE_T || TRIO_FEATURE_SIZE_T_UPPER + if (flags & FLAGS_SIZE_T) + *(size_t *)pointer = (size_t)number; + else +#endif +#if TRIO_FEATURE_PTRDIFF_T + if (flags & FLAGS_PTRDIFF_T) + *(ptrdiff_t *)pointer = (ptrdiff_t)number; + else +#endif +#if TRIO_FEATURE_INTMAX_T + if (flags & FLAGS_INTMAX_T) + *(trio_intmax_t *)pointer = (trio_intmax_t)number; + else +#endif + if (flags & FLAGS_QUAD) + *(trio_ulonglong_t *)pointer = (trio_ulonglong_t)number; + else if (flags & FLAGS_LONG) + *(long int *)pointer = (long int)number; + else if (flags & FLAGS_SHORT) + *(short int *)pointer = (short int)number; + else + *(int *)pointer = (int)number; + } + } + break; /* FORMAT_INT */ + + case FORMAT_STRING: +#if TRIO_FEATURE_WIDECHAR + if (flags & FLAGS_WIDECHAR) + { + if (!TrioReadWideString(data, + (flags & FLAGS_IGNORE) + ? NULL + : parameters[i].data.wstring, + flags, + width)) + { + status = assignment; + goto end; + } + } + else +#endif + { + if (!TrioReadString(data, + (flags & FLAGS_IGNORE) + ? NULL + : parameters[i].data.string, + flags, + width)) + { + status = assignment; + goto end; + } + } + if (!(flags & FLAGS_IGNORE)) + assignment++; + break; /* FORMAT_STRING */ + +#if TRIO_FEATURE_FLOAT + case FORMAT_DOUBLE: + { + if (flags & FLAGS_IGNORE) + { + pointer = NULL; + } + else + { + pointer = (flags & FLAGS_LONGDOUBLE) + ? (trio_pointer_t)parameters[i].data.longdoublePointer + : (trio_pointer_t)parameters[i].data.doublePointer; + } + if (!TrioReadDouble(data, pointer, flags, width)) + { + status = assignment; + goto end; + } + if (!(flags & FLAGS_IGNORE)) + { + assignment++; + } + break; /* FORMAT_DOUBLE */ + } +#endif + + case FORMAT_GROUP: + { + int characterclass[MAX_CHARACTER_CLASS + 1]; + + /* Skip over modifiers */ + while (format[offset] != SPECIFIER_GROUP) + { + offset++; + } + /* Skip over group specifier */ + offset++; + + memset(characterclass, 0, sizeof(characterclass)); + status = TrioGetCharacterClass(format, + &offset, + &flags, + characterclass); + if (status < 0) + goto end; + + if (!TrioReadGroup(data, + (flags & FLAGS_IGNORE) + ? NULL + : parameters[i].data.string, + characterclass, + flags, + parameters[i].width)) + { + status = assignment; + goto end; + } + if (!(flags & FLAGS_IGNORE)) + assignment++; + } + break; /* FORMAT_GROUP */ + + case FORMAT_COUNT: + pointer = parameters[i].data.pointer; + if (NULL != pointer) + { + int count = data->processed; + if (ch != EOF) + count--; /* a character is read, but is not consumed yet */ +#if TRIO_FEATURE_SIZE_T || TRIO_FEATURE_SIZE_T_UPPER + if (flags & FLAGS_SIZE_T) + *(size_t *)pointer = (size_t)count; + else +#endif +#if TRIO_FEATURE_PTRDIFF_T + if (flags & FLAGS_PTRDIFF_T) + *(ptrdiff_t *)pointer = (ptrdiff_t)count; + else +#endif +#if TRIO_FEATURE_INTMAX_T + if (flags & FLAGS_INTMAX_T) + *(trio_intmax_t *)pointer = (trio_intmax_t)count; + else +#endif + if (flags & FLAGS_QUAD) + { + *(trio_ulonglong_t *)pointer = (trio_ulonglong_t)count; + } + else if (flags & FLAGS_LONG) + { + *(long int *)pointer = (long int)count; + } + else if (flags & FLAGS_SHORT) + { + *(short int *)pointer = (short int)count; + } + else + { + *(int *)pointer = (int)count; + } + } + break; /* FORMAT_COUNT */ + + case FORMAT_CHAR: +#if TRIO_FEATURE_WIDECHAR + if (flags & FLAGS_WIDECHAR) + { + if (TrioReadWideChar(data, + (flags & FLAGS_IGNORE) + ? NULL + : parameters[i].data.wstring, + flags, + (width == NO_WIDTH) ? 1 : width) == 0) + { + status = assignment; + goto end; + } + } + else +#endif + { + if (TrioReadChar(data, + (flags & FLAGS_IGNORE) + ? NULL + : parameters[i].data.string, + flags, + (width == NO_WIDTH) ? 1 : width) == 0) + { + status = assignment; + goto end; + } + } + if (!(flags & FLAGS_IGNORE)) + assignment++; + break; /* FORMAT_CHAR */ + + case FORMAT_POINTER: + if (!TrioReadPointer(data, + (flags & FLAGS_IGNORE) + ? NULL + : (trio_pointer_t *)parameters[i].data.pointer, + flags)) + { + status = assignment; + goto end; + } + if (!(flags & FLAGS_IGNORE)) + assignment++; + break; /* FORMAT_POINTER */ + + case FORMAT_PARAMETER: + break; /* FORMAT_PARAMETER */ + + default: + status = TRIO_ERROR_RETURN(TRIO_EINVAL, offset); + goto end; + } + + ch = data->current; + offset = parameters[i].endOffset; + i++; + } + + status = assignment; + end: + if (data->UndoStream) + data->UndoStream(data); + return status; +} + +/************************************************************************* + * TrioScan + */ +TRIO_PRIVATE int +TrioScan +TRIO_ARGS8((source, sourceSize, InStream, UndoStream, format, arglist, argfunc, argarray), + trio_pointer_t source, + size_t sourceSize, + void (*InStream) TRIO_PROTO((trio_class_t *, int *)), + void (*UndoStream) TRIO_PROTO((trio_class_t *)), + TRIO_CONST char *format, + va_list arglist, + trio_argfunc_t argfunc, + trio_pointer_t *argarray) +{ + int status; + trio_parameter_t parameters[MAX_PARAMETERS]; + trio_class_t data; + + assert(VALID(InStream)); + assert(VALID(format)); + + memset(&data, 0, sizeof(data)); + data.InStream = InStream; + data.UndoStream = UndoStream; + data.location = (trio_pointer_t)source; + data.max = sourceSize; + data.error = 0; + +#if defined(USE_LOCALE) + if (NULL == internalLocaleValues) + { + TrioSetLocale(); + } +#endif + + status = TrioParse(TYPE_SCAN, format, parameters, arglist, argfunc, argarray); + if (status < 0) + return status; + + status = TrioScanProcess(&data, format, parameters); + if (data.error != 0) + { + status = data.error; + } + return status; +} + +/************************************************************************* + * TrioInStreamFile + */ +#if TRIO_FEATURE_FILE || TRIO_FEATURE_STDIO +TRIO_PRIVATE void +TrioInStreamFile +TRIO_ARGS2((self, intPointer), + trio_class_t *self, + int *intPointer) +{ + FILE *file = (FILE *)self->location; + + assert(VALID(self)); + assert(VALID(file)); + + self->actually.cached = 0; + + /* The initial value of self->current is zero */ + if (self->current == EOF) + { + self->error = (ferror(file)) + ? TRIO_ERROR_RETURN(TRIO_ERRNO, 0) + : TRIO_ERROR_RETURN(TRIO_EOF, 0); + } + else + { + self->processed++; + self->actually.cached++; + } + + self->current = fgetc(file); + + if (VALID(intPointer)) + { + *intPointer = self->current; + } +} +#endif /* TRIO_FEATURE_FILE || TRIO_FEATURE_STDIO */ + +/************************************************************************* + * TrioUndoStreamFile + */ +#if TRIO_FEATURE_FILE || TRIO_FEATURE_STDIO +TRIO_PRIVATE void +TrioUndoStreamFile +TRIO_ARGS1((self), + trio_class_t *self) +{ + FILE *file = (FILE *)self->location; + + assert(VALID(self)); + assert(VALID(file)); + + if (self->actually.cached > 0) + { + assert(self->actually.cached == 1); + + self->current = ungetc(self->current, file); + self->actually.cached = 0; + } +} +#endif /* TRIO_FEATURE_FILE || TRIO_FEATURE_STDIO */ + +/************************************************************************* + * TrioInStreamFileDescriptor + */ +#if TRIO_FEATURE_FD +TRIO_PRIVATE void +TrioInStreamFileDescriptor +TRIO_ARGS2((self, intPointer), + trio_class_t *self, + int *intPointer) +{ + int fd = *((int *)self->location); + int size; + unsigned char input; + + assert(VALID(self)); + + self->actually.cached = 0; + + size = read(fd, &input, sizeof(char)); + if (size == -1) + { + self->error = TRIO_ERROR_RETURN(TRIO_ERRNO, 0); + self->current = EOF; + } + else + { + self->current = (size == 0) ? EOF : input; + } + if (self->current != EOF) + { + self->actually.cached++; + self->processed++; + } + + if (VALID(intPointer)) + { + *intPointer = self->current; + } +} +#endif /* TRIO_FEATURE_FD */ + +/************************************************************************* + * TrioInStreamCustom + */ +#if TRIO_FEATURE_CLOSURE +TRIO_PRIVATE void +TrioInStreamCustom +TRIO_ARGS2((self, intPointer), + trio_class_t *self, + int *intPointer) +{ + trio_custom_t *data; + + assert(VALID(self)); + assert(VALID(self->location)); + + self->actually.cached = 0; + + data = (trio_custom_t *)self->location; + + self->current = (data->stream.in == NULL) + ? NIL + : (data->stream.in)(data->closure); + + if (self->current == NIL) + { + self->current = EOF; + } + else + { + self->processed++; + self->actually.cached++; + } + + if (VALID(intPointer)) + { + *intPointer = self->current; + } +} +#endif /* TRIO_FEATURE_CLOSURE */ + +/************************************************************************* + * TrioInStreamString + */ +TRIO_PRIVATE void +TrioInStreamString +TRIO_ARGS2((self, intPointer), + trio_class_t *self, + int *intPointer) +{ + unsigned char **buffer; + + assert(VALID(self)); + assert(VALID(self->location)); + + self->actually.cached = 0; + + buffer = (unsigned char **)self->location; + self->current = (*buffer)[0]; + if (self->current == NIL) + { + self->current = EOF; + } + else + { + (*buffer)++; + self->processed++; + self->actually.cached++; + } + + if (VALID(intPointer)) + { + *intPointer = self->current; + } +} + +/************************************************************************* + * + * Formatted scanning functions + * + ************************************************************************/ + +#if defined(TRIO_DOCUMENTATION) +# include "doc/doc_scanf.h" +#endif +/** @addtogroup Scanf + @{ +*/ + +/************************************************************************* + * scanf + */ + +/** + Scan characters from standard input stream. + + @param format Formatting string. + @param ... Arguments. + @return Number of scanned characters. + */ +#if TRIO_FEATURE_STDIO +TRIO_PUBLIC int +trio_scanf +TRIO_VARGS2((format, va_alist), + TRIO_CONST char *format, + TRIO_VA_DECL) +{ + int status; + va_list args; + + assert(VALID(format)); + + TRIO_VA_START(args, format); + status = TrioScan((trio_pointer_t)stdin, 0, + TrioInStreamFile, + TrioUndoStreamFile, + format, args, NULL, NULL); + TRIO_VA_END(args); + return status; +} +#endif /* TRIO_FEATURE_STDIO */ + +/** + Scan characters from standard input stream. + + @param format Formatting string. + @param args Arguments. + @return Number of scanned characters. + */ +#if TRIO_FEATURE_STDIO +TRIO_PUBLIC int +trio_vscanf +TRIO_ARGS2((format, args), + TRIO_CONST char *format, + va_list args) +{ + assert(VALID(format)); + + return TrioScan((trio_pointer_t)stdin, 0, + TrioInStreamFile, + TrioUndoStreamFile, + format, args, NULL, NULL); +} +#endif /* TRIO_FEATURE_STDIO */ + +/** + Scan characters from standard input stream. + + @param format Formatting string. + @param args Arguments. + @return Number of scanned characters. + */ +#if TRIO_FEATURE_STDIO +TRIO_PUBLIC int +trio_scanfv +TRIO_ARGS2((format, args), + TRIO_CONST char *format, + trio_pointer_t *args) +{ + static va_list unused; + + assert(VALID(format)); + + return TrioScan((trio_pointer_t)stdin, 0, + TrioInStreamFile, + TrioUndoStreamFile, + format, + unused, TrioArrayGetter, args); +} +#endif /* TRIO_FEATURE_STDIO */ + +/************************************************************************* + * fscanf + */ + +/** + Scan characters from file. + + @param file File pointer. + @param format Formatting string. + @param ... Arguments. + @return Number of scanned characters. + */ +#if TRIO_FEATURE_FILE +TRIO_PUBLIC int +trio_fscanf +TRIO_VARGS3((file, format, va_alist), + FILE *file, + TRIO_CONST char *format, + TRIO_VA_DECL) +{ + int status; + va_list args; + + assert(VALID(file)); + assert(VALID(format)); + + TRIO_VA_START(args, format); + status = TrioScan((trio_pointer_t)file, 0, + TrioInStreamFile, + TrioUndoStreamFile, + format, args, NULL, NULL); + TRIO_VA_END(args); + return status; +} +#endif /* TRIO_FEATURE_FILE */ + +/** + Scan characters from file. + + @param file File pointer. + @param format Formatting string. + @param args Arguments. + @return Number of scanned characters. + */ +#if TRIO_FEATURE_FILE +TRIO_PUBLIC int +trio_vfscanf +TRIO_ARGS3((file, format, args), + FILE *file, + TRIO_CONST char *format, + va_list args) +{ + assert(VALID(file)); + assert(VALID(format)); + + return TrioScan((trio_pointer_t)file, 0, + TrioInStreamFile, + TrioUndoStreamFile, + format, args, NULL, NULL); +} +#endif /* TRIO_FEATURE_FILE */ + +/** + Scan characters from file. + + @param file File pointer. + @param format Formatting string. + @param args Arguments. + @return Number of scanned characters. + */ +#if TRIO_FEATURE_FILE +TRIO_PUBLIC int +trio_fscanfv +TRIO_ARGS3((file, format, args), + FILE *file, + TRIO_CONST char *format, + trio_pointer_t *args) +{ + static va_list unused; + + assert(VALID(file)); + assert(VALID(format)); + + return TrioScan((trio_pointer_t)file, 0, + TrioInStreamFile, + TrioUndoStreamFile, + format, + unused, TrioArrayGetter, args); +} +#endif /* TRIO_FEATURE_FILE */ + +/************************************************************************* + * dscanf + */ + +/** + Scan characters from file descriptor. + + @param fd File descriptor. + @param format Formatting string. + @param ... Arguments. + @return Number of scanned characters. + */ +#if TRIO_FEATURE_FD +TRIO_PUBLIC int +trio_dscanf +TRIO_VARGS3((fd, format, va_alist), + int fd, + TRIO_CONST char *format, + TRIO_VA_DECL) +{ + int status; + va_list args; + + assert(VALID(format)); + + TRIO_VA_START(args, format); + status = TrioScan((trio_pointer_t)&fd, 0, + TrioInStreamFileDescriptor, + NULL, + format, args, NULL, NULL); + TRIO_VA_END(args); + return status; +} +#endif /* TRIO_FEATURE_FD */ + +/** + Scan characters from file descriptor. + + @param fd File descriptor. + @param format Formatting string. + @param args Arguments. + @return Number of scanned characters. + */ +#if TRIO_FEATURE_FD +TRIO_PUBLIC int +trio_vdscanf +TRIO_ARGS3((fd, format, args), + int fd, + TRIO_CONST char *format, + va_list args) +{ + assert(VALID(format)); + + return TrioScan((trio_pointer_t)&fd, 0, + TrioInStreamFileDescriptor, + NULL, + format, args, NULL, NULL); +} +#endif /* TRIO_FEATURE_FD */ + +/** + Scan characters from file descriptor. + + @param fd File descriptor. + @param format Formatting string. + @param args Arguments. + @return Number of scanned characters. + */ +#if TRIO_FEATURE_FD +TRIO_PUBLIC int +trio_dscanfv +TRIO_ARGS3((fd, format, args), + int fd, + TRIO_CONST char *format, + trio_pointer_t *args) +{ + static va_list unused; + + assert(VALID(format)); + + return TrioScan((trio_pointer_t)&fd, 0, + TrioInStreamFileDescriptor, + NULL, + format, + unused, TrioArrayGetter, args); +} +#endif /* TRIO_FEATURE_FD */ + +/************************************************************************* + * cscanf + */ +#if TRIO_FEATURE_CLOSURE +TRIO_PUBLIC int +trio_cscanf +TRIO_VARGS4((stream, closure, format, va_alist), + trio_instream_t stream, + trio_pointer_t closure, + TRIO_CONST char *format, + TRIO_VA_DECL) +{ + int status; + va_list args; + trio_custom_t data; + + assert(VALID(stream)); + assert(VALID(format)); + + TRIO_VA_START(args, format); + data.stream.in = stream; + data.closure = closure; + status = TrioScan(&data, 0, TrioInStreamCustom, NULL, format, args, NULL, NULL); + TRIO_VA_END(args); + return status; +} +#endif /* TRIO_FEATURE_CLOSURE */ + +#if TRIO_FEATURE_CLOSURE +TRIO_PUBLIC int +trio_vcscanf +TRIO_ARGS4((stream, closure, format, args), + trio_instream_t stream, + trio_pointer_t closure, + TRIO_CONST char *format, + va_list args) +{ + trio_custom_t data; + + assert(VALID(stream)); + assert(VALID(format)); + + data.stream.in = stream; + data.closure = closure; + return TrioScan(&data, 0, TrioInStreamCustom, NULL, format, args, NULL, NULL); +} +#endif /* TRIO_FEATURE_CLOSURE */ + +#if TRIO_FEATURE_CLOSURE +TRIO_PUBLIC int +trio_cscanfv +TRIO_ARGS4((stream, closure, format, args), + trio_instream_t stream, + trio_pointer_t closure, + TRIO_CONST char *format, + trio_pointer_t *args) +{ + static va_list unused; + trio_custom_t data; + + assert(VALID(stream)); + assert(VALID(format)); + + data.stream.in = stream; + data.closure = closure; + return TrioScan(&data, 0, TrioInStreamCustom, NULL, format, + unused, TrioArrayGetter, args); +} +#endif /* TRIO_FEATURE_CLOSURE */ + +#if TRIO_FEATURE_CLOSURE && TRIO_FEATURE_ARGFUNC +TRIO_PUBLIC int +trio_cscanff +TRIO_ARGS5((stream, closure, format, argfunc, context), + trio_instream_t stream, + trio_pointer_t closure, + TRIO_CONST char *format, + trio_argfunc_t argfunc, + trio_pointer_t context) +{ + static va_list unused; + trio_custom_t data; + + assert(VALID(stream)); + assert(VALID(format)); + assert(VALID(argfunc)); + + data.stream.in = stream; + data.closure = closure; + return TrioScan(&data, 0, TrioInStreamCustom, NULL, format, + unused, argfunc, (trio_pointer_t *)context); +} +#endif /* TRIO_FEATURE_CLOSURE && TRIO_FEATURE_ARGFUNC */ + +/************************************************************************* + * sscanf + */ + +/** + Scan characters from string. + + @param buffer Input string. + @param format Formatting string. + @param ... Arguments. + @return Number of scanned characters. + */ +TRIO_PUBLIC int +trio_sscanf +TRIO_VARGS3((buffer, format, va_alist), + TRIO_CONST char *buffer, + TRIO_CONST char *format, + TRIO_VA_DECL) +{ + int status; + va_list args; + + assert(VALID(buffer)); + assert(VALID(format)); + + TRIO_VA_START(args, format); + status = TrioScan((trio_pointer_t)&buffer, 0, + TrioInStreamString, + NULL, + format, args, NULL, NULL); + TRIO_VA_END(args); + return status; +} + +/** + Scan characters from string. + + @param buffer Input string. + @param format Formatting string. + @param args Arguments. + @return Number of scanned characters. + */ +TRIO_PUBLIC int +trio_vsscanf +TRIO_ARGS3((buffer, format, args), + TRIO_CONST char *buffer, + TRIO_CONST char *format, + va_list args) +{ + assert(VALID(buffer)); + assert(VALID(format)); + + return TrioScan((trio_pointer_t)&buffer, 0, + TrioInStreamString, + NULL, + format, args, NULL, NULL); +} + +/** + Scan characters from string. + + @param buffer Input string. + @param format Formatting string. + @param args Arguments. + @return Number of scanned characters. + */ +TRIO_PUBLIC int +trio_sscanfv +TRIO_ARGS3((buffer, format, args), + TRIO_CONST char *buffer, + TRIO_CONST char *format, + trio_pointer_t *args) +{ + static va_list unused; + + assert(VALID(buffer)); + assert(VALID(format)); + + return TrioScan((trio_pointer_t)&buffer, 0, + TrioInStreamString, + NULL, + format, + unused, TrioArrayGetter, args); +} + +#endif /* TRIO_FEATURE_SCANF */ + +/** @} End of Scanf documentation module */ + +/************************************************************************* + * trio_strerror + */ +TRIO_PUBLIC TRIO_CONST char * +trio_strerror +TRIO_ARGS1((errorcode), + int errorcode) +{ +#if TRIO_FEATURE_STRERR + /* Textual versions of the error codes */ + switch (TRIO_ERROR_CODE(errorcode)) + { + case TRIO_EOF: + return "End of file"; + case TRIO_EINVAL: + return "Invalid argument"; + case TRIO_ETOOMANY: + return "Too many arguments"; + case TRIO_EDBLREF: + return "Double reference"; + case TRIO_EGAP: + return "Reference gap"; + case TRIO_ENOMEM: + return "Out of memory"; + case TRIO_ERANGE: + return "Invalid range"; + case TRIO_ECUSTOM: + return "Custom error"; + default: + return "Unknown"; + } +#else + return "Unknown"; +#endif +} + +#ifdef _WIN32 +#pragma warning(pop) +#endif diff --git a/winpr/libwinpr/utils/trio/trio.h b/winpr/libwinpr/utils/trio/trio.h new file mode 100644 index 000000000..f91ca7905 --- /dev/null +++ b/winpr/libwinpr/utils/trio/trio.h @@ -0,0 +1,260 @@ +/************************************************************************* + * + * $Id: trio.h,v 1.20 2010/09/12 11:08:08 breese Exp $ + * + * Copyright (C) 1998 Bjorn Reese and Daniel Stenberg. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF + * MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE AUTHORS AND + * CONTRIBUTORS ACCEPT NO RESPONSIBILITY IN ANY CONCEIVABLE MANNER. + * + ************************************************************************* + * + * http://ctrio.sourceforge.net/ + * + ************************************************************************/ + +#ifndef TRIO_TRIO_H +#define TRIO_TRIO_H + +#if !defined(WITHOUT_TRIO) + +/* + * Use autoconf defines if present. Packages using trio must define + * HAVE_CONFIG_H as a compiler option themselves. + */ +#if defined(HAVE_CONFIG_H) +# include <config.h> +#endif + +#include "triop.h" + +#include <stdio.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * Error codes. + * + * Remember to add a textual description to trio_strerror. + */ +enum { + TRIO_EOF = 1, + TRIO_EINVAL = 2, + TRIO_ETOOMANY = 3, + TRIO_EDBLREF = 4, + TRIO_EGAP = 5, + TRIO_ENOMEM = 6, + TRIO_ERANGE = 7, + TRIO_ERRNO = 8, + TRIO_ECUSTOM = 9 +}; + +/* Error macros */ +#define TRIO_ERROR_CODE(x) ((-(x)) & 0x00FF) +#define TRIO_ERROR_POSITION(x) ((-(x)) >> 8) +#define TRIO_ERROR_NAME(x) trio_strerror(x) + +/* Argument function types */ +enum { + TRIO_TYPE_POINTER = 1, + TRIO_TYPE_CHAR = 2, + TRIO_TYPE_SHORT = 3, + TRIO_TYPE_INT = 4, + TRIO_TYPE_LONG = 5, + TRIO_TYPE_ULONGLONG = 6, + TRIO_TYPE_UINTMAX = 7, + TRIO_TYPE_PTRDIFF = 8, + TRIO_TYPE_SIZE = 9, + TRIO_TYPE_PCHAR = 10, + TRIO_TYPE_PWCHAR = 11, + TRIO_TYPE_FLOAT = 12, + TRIO_TYPE_DOUBLE = 13, + TRIO_TYPE_LONGDOUBLE = 14 +}; + +typedef trio_pointer_t (*trio_argfunc_t) TRIO_PROTO((trio_pointer_t, int, int)); +typedef int (*trio_outstream_t) TRIO_PROTO((trio_pointer_t, int)); +typedef int (*trio_instream_t) TRIO_PROTO((trio_pointer_t)); + +TRIO_CONST char *trio_strerror TRIO_PROTO((int)); + +/************************************************************************* + * Print Functions + */ + +int trio_printf TRIO_PROTO((TRIO_CONST char *format, ...)); +int trio_vprintf TRIO_PROTO((TRIO_CONST char *format, va_list args)); +int trio_printfv TRIO_PROTO((TRIO_CONST char *format, trio_pointer_t *args)); + +int trio_fprintf TRIO_PROTO((FILE *file, TRIO_CONST char *format, ...)); +int trio_vfprintf TRIO_PROTO((FILE *file, TRIO_CONST char *format, va_list args)); +int trio_fprintfv TRIO_PROTO((FILE *file, TRIO_CONST char *format, trio_pointer_t *args)); + +int trio_dprintf TRIO_PROTO((int fd, TRIO_CONST char *format, ...)); +int trio_vdprintf TRIO_PROTO((int fd, TRIO_CONST char *format, va_list args)); +int trio_dprintfv TRIO_PROTO((int fd, TRIO_CONST char *format, trio_pointer_t *args)); + +int trio_cprintf TRIO_PROTO((trio_outstream_t stream, trio_pointer_t closure, + TRIO_CONST char *format, ...)); +int trio_vcprintf TRIO_PROTO((trio_outstream_t stream, trio_pointer_t closure, + TRIO_CONST char *format, va_list args)); +int trio_cprintfv TRIO_PROTO((trio_outstream_t stream, trio_pointer_t closure, + TRIO_CONST char *format, trio_pointer_t *args)); +int trio_cprintff TRIO_PROTO((trio_outstream_t stream, trio_pointer_t closure, + TRIO_CONST char *format, + trio_argfunc_t func, trio_pointer_t context)); + +int trio_sprintf TRIO_PROTO((char *buffer, TRIO_CONST char *format, ...)); +int trio_vsprintf TRIO_PROTO((char *buffer, TRIO_CONST char *format, va_list args)); +int trio_sprintfv TRIO_PROTO((char *buffer, TRIO_CONST char *format, trio_pointer_t *args)); + +int trio_snprintf TRIO_PROTO((char *buffer, size_t max, TRIO_CONST char *format, ...)); +int trio_vsnprintf TRIO_PROTO((char *buffer, size_t bufferSize, TRIO_CONST char *format, + va_list args)); +int trio_snprintfv TRIO_PROTO((char *buffer, size_t bufferSize, TRIO_CONST char *format, + trio_pointer_t *args)); + +int trio_snprintfcat TRIO_PROTO((char *buffer, size_t max, TRIO_CONST char *format, ...)); +int trio_vsnprintfcat TRIO_PROTO((char *buffer, size_t bufferSize, TRIO_CONST char *format, + va_list args)); + +#if defined(TRIO_DEPRECATED) +char *trio_aprintf TRIO_PROTO((TRIO_CONST char *format, ...)); +char *trio_vaprintf TRIO_PROTO((TRIO_CONST char *format, va_list args)); +#endif + +int trio_asprintf TRIO_PROTO((char **ret, TRIO_CONST char *format, ...)); +int trio_vasprintf TRIO_PROTO((char **ret, TRIO_CONST char *format, va_list args)); +int trio_asprintfv TRIO_PROTO((char **result, TRIO_CONST char *format, trio_pointer_t * args)); + +/************************************************************************* + * Scan Functions + */ +int trio_scanf TRIO_PROTO((TRIO_CONST char *format, ...)); +int trio_vscanf TRIO_PROTO((TRIO_CONST char *format, va_list args)); +int trio_scanfv TRIO_PROTO((TRIO_CONST char *format, void **args)); + +int trio_fscanf TRIO_PROTO((FILE *file, TRIO_CONST char *format, ...)); +int trio_vfscanf TRIO_PROTO((FILE *file, TRIO_CONST char *format, va_list args)); +int trio_fscanfv TRIO_PROTO((FILE *file, TRIO_CONST char *format, void **args)); + +int trio_dscanf TRIO_PROTO((int fd, TRIO_CONST char *format, ...)); +int trio_vdscanf TRIO_PROTO((int fd, TRIO_CONST char *format, va_list args)); +int trio_dscanfv TRIO_PROTO((int fd, TRIO_CONST char *format, void **args)); + +int trio_cscanf TRIO_PROTO((trio_instream_t stream, trio_pointer_t closure, + TRIO_CONST char *format, ...)); +int trio_vcscanf TRIO_PROTO((trio_instream_t stream, trio_pointer_t closure, + TRIO_CONST char *format, va_list args)); +int trio_cscanfv TRIO_PROTO((trio_instream_t stream, trio_pointer_t closure, + TRIO_CONST char *format, void **args)); +int trio_cscanff TRIO_PROTO((trio_instream_t stream, trio_pointer_t closure, + TRIO_CONST char *format, + trio_argfunc_t func, trio_pointer_t context)); + +int trio_sscanf TRIO_PROTO((TRIO_CONST char *buffer, TRIO_CONST char *format, ...)); +int trio_vsscanf TRIO_PROTO((TRIO_CONST char *buffer, TRIO_CONST char *format, va_list args)); +int trio_sscanfv TRIO_PROTO((TRIO_CONST char *buffer, TRIO_CONST char *format, void **args)); + +/************************************************************************* + * Locale Functions + */ +void trio_locale_set_decimal_point TRIO_PROTO((char *decimalPoint)); +void trio_locale_set_thousand_separator TRIO_PROTO((char *thousandSeparator)); +void trio_locale_set_grouping TRIO_PROTO((char *grouping)); + +/************************************************************************* + * Renaming + */ +#ifdef TRIO_REPLACE_STDIO +/* Replace the <stdio.h> functions */ +#ifndef HAVE_PRINTF +# undef printf +# define printf trio_printf +#endif +#ifndef HAVE_VPRINTF +# undef vprintf +# define vprintf trio_vprintf +#endif +#ifndef HAVE_FPRINTF +# undef fprintf +# define fprintf trio_fprintf +#endif +#ifndef HAVE_VFPRINTF +# undef vfprintf +# define vfprintf trio_vfprintf +#endif +#ifndef HAVE_SPRINTF +# undef sprintf +# define sprintf trio_sprintf +#endif +#ifndef HAVE_VSPRINTF +# undef vsprintf +# define vsprintf trio_vsprintf +#endif +#ifndef HAVE_SNPRINTF +# undef snprintf +# define snprintf trio_snprintf +#endif +#ifndef HAVE_VSNPRINTF +# undef vsnprintf +# define vsnprintf trio_vsnprintf +#endif +#ifndef HAVE_SCANF +# undef scanf +# define scanf trio_scanf +#endif +#ifndef HAVE_VSCANF +# undef vscanf +# define vscanf trio_vscanf +#endif +#ifndef HAVE_FSCANF +# undef fscanf +# define fscanf trio_fscanf +#endif +#ifndef HAVE_VFSCANF +# undef vfscanf +# define vfscanf trio_vfscanf +#endif +#ifndef HAVE_SSCANF +# undef sscanf +# define sscanf trio_sscanf +#endif +#ifndef HAVE_VSSCANF +# undef vsscanf +# define vsscanf trio_vsscanf +#endif +/* These aren't stdio functions, but we make them look similar */ +#undef dprintf +#define dprintf trio_dprintf +#undef vdprintf +#define vdprintf trio_vdprintf +#undef aprintf +#define aprintf trio_aprintf +#undef vaprintf +#define vaprintf trio_vaprintf +#undef asprintf +#define asprintf trio_asprintf +#undef vasprintf +#define vasprintf trio_vasprintf +#undef dscanf +#define dscanf trio_dscanf +#undef vdscanf +#define vdscanf trio_vdscanf +#endif + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* WITHOUT_TRIO */ + +#endif /* TRIO_TRIO_H */ diff --git a/winpr/libwinpr/utils/trio/triodef.h b/winpr/libwinpr/utils/trio/triodef.h new file mode 100644 index 000000000..11c14b9c4 --- /dev/null +++ b/winpr/libwinpr/utils/trio/triodef.h @@ -0,0 +1,337 @@ +/************************************************************************* + * + * $Id: triodef.h,v 1.36 2010/09/12 11:08:08 breese Exp $ + * + * Copyright (C) 2001 Bjorn Reese <breese@users.sourceforge.net> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF + * MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE AUTHORS AND + * CONTRIBUTORS ACCEPT NO RESPONSIBILITY IN ANY CONCEIVABLE MANNER. + * + ************************************************************************/ + +#ifndef TRIO_TRIODEF_H +#define TRIO_TRIODEF_H + +/************************************************************************* + * Compiler support detection + */ + +#if defined(__GNUC__) +# define TRIO_COMPILER_GCC +#endif + +#if defined(__SUNPRO_CC) +# define TRIO_COMPILER_SUNPRO __SUNPRO_CC +#else +# if defined(__SUNPRO_C) +# define TRIO_COMPILER_SUNPRO __SUNPRO_C +# endif +#endif + +#if defined(__xlC__) || defined(__IBMC__) || defined(__IBMCPP__) +# define TRIO_COMPILER_XLC +#else +# if defined(_AIX) && !defined(__GNUC__) +# define TRIO_COMPILER_XLC /* Workaround for old xlc */ +# endif +#endif + +#if defined(__DECC) || defined(__DECCXX) +# define TRIO_COMPILER_DECC +#else +# if defined(__osf__) && defined(__LANGUAGE_C__) && !defined(__GNUC__) +# define TRIO_COMPILER_DECC /* Workaround for old DEC C compilers */ +# endif +#endif + +#if defined(__HP_aCC) || defined(__HP_cc) +# define TRIO_COMPILER_HP +#endif + +#if defined(sgi) || defined(__sgi) +# define TRIO_COMPILER_MIPSPRO +#endif + +#if defined(_MSC_VER) +# define TRIO_COMPILER_MSVC +#endif + +#if defined(__BORLANDC__) +# define TRIO_COMPILER_BCB +#endif + +/************************************************************************* + * Platform support detection + */ + +#if defined(VMS) || defined(__VMS) +# define TRIO_PLATFORM_VMS +#endif + +#if defined(unix) || defined(__unix) || defined(__unix__) +# define TRIO_PLATFORM_UNIX +#endif + +#if defined(TRIO_COMPILER_XLC) || defined(_AIX) +# define TRIO_PLATFORM_UNIX +#endif + +#if defined(TRIO_COMPILER_DECC) || defined(__osf___) +# if !defined(TRIO_PLATFORM_VMS) +# define TRIO_PLATFORM_UNIX +# endif +#endif + +#if defined(__NetBSD__) +# define TRIO_PLATFORM_UNIX +#endif + +#if defined(__Lynx__) +# define TRIO_PLATFORM_UNIX +# define TRIO_PLATFORM_LYNX +#endif + +#if defined(__APPLE__) && defined(__MACH__) +# define TRIO_PLATFORM_UNIX +#endif + +#if defined(__QNX__) +# define TRIO_PLATFORM_UNIX +# define TRIO_PLATFORM_QNX +#endif + +#if defined(__CYGWIN__) +# define TRIO_PLATFORM_UNIX +#endif + +#if defined(AMIGA) && defined(TRIO_COMPILER_GCC) +# define TRIO_PLATFORM_UNIX +#endif + +#if defined(TRIO_COMPILER_MSVC) || defined(WIN32) || defined(_WIN32) +# define TRIO_PLATFORM_WIN32 +#endif + +#if defined(_WIN32_WCE) +# define TRIO_PLATFORM_WINCE +#endif + +#if defined(mpeix) || defined(__mpexl) +# define TRIO_PLATFORM_MPEIX +#endif + +#if defined(_AIX) +# define TRIO_PLATFORM_AIX +#endif + +#if defined(__hpux) +# define TRIO_PLATFORM_HPUX +#endif + +#if defined(sun) || defined(__sun__) +# if defined(__SVR4) || defined(__svr4__) +# define TRIO_PLATFORM_SOLARIS +# else +# define TRIO_PLATFORM_SUNOS +# endif +#endif + +/************************************************************************* + * Standards support detection + */ + +#if defined(__STDC__) \ + || defined(_MSC_EXTENSIONS) \ + || defined(TRIO_COMPILER_BCB) +# define PREDEF_STANDARD_C89 +#endif +#if defined(__STDC_VERSION__) +# define PREDEF_STANDARD_C90 +#endif +#if (__STDC_VERSION__ - 0 >= 199409L) +# define PREDEF_STANDARD_C94 +#endif +#if (__STDC_VERSION__ - 0 >= 199901L) +# define PREDEF_STANDARD_C99 +#endif +#if defined(TRIO_COMPILER_SUNPRO) && (TRIO_COMPILER_SUNPRO >= 0x420) +# if !defined(PREDEF_STANDARD_C94) +# define PREDEF_STANDARD_C94 +# endif +#endif + +#if defined(__cplusplus) +# define PREDEF_STANDARD_CXX +#endif +#if __cplusplus - 0 >= 199711L +# define PREDEF_STANDARD_CXX89 +#endif + +#if defined(TRIO_PLATFORM_UNIX) +# include <unistd.h> +#endif + +#if defined(_POSIX_VERSION) +# define PREDEF_STANDARD_POSIX _POSIX_VERSION +# if (_POSIX_VERSION >= 199506L) +# define PREDEF_STANDARD_POSIX_1996 +# endif +#endif + +#if (_XOPEN_VERSION - 0 >= 3) || defined(_XOPEN_XPG3) +# define PREDEF_STANDARD_XPG3 +#endif +#if (_XOPEN_VERSION - 0 >= 4) || defined(_XOPEN_XPG4) +# define PREDEF_STANDARD_XPG4 +#endif +#if (_XOPEN_VERSION - 0 > 4) \ + || (defined(_XOPEN_UNIX) && (_XOPEN_VERSION - 0 == 4)) +# define PREDEF_STANDARD_UNIX95 +#endif +#if (_XOPEN_VERSION - 0 >= 500) +# define PREDEF_STANDARD_UNIX98 +#endif +#if (_XOPEN_VERSION - 0 >= 600) +# define PREDEF_STANDARD_UNIX03 +#endif + +/************************************************************************* + * Generic defines + */ + +#if !defined(TRIO_PUBLIC) +# define TRIO_PUBLIC +#endif +#if !defined(TRIO_PRIVATE) +# define TRIO_PRIVATE static +#endif + +#if !(defined(PREDEF_STANDARD_C89) || defined(PREDEF_STANDARD_CXX)) +# define TRIO_COMPILER_ANCIENT +#endif + +#if defined(TRIO_COMPILER_ANCIENT) +# define TRIO_CONST +# define TRIO_VOLATILE +# define TRIO_SIGNED +typedef double trio_long_double_t; +typedef char * trio_pointer_t; +# define TRIO_SUFFIX_LONG(x) x +# define TRIO_PROTO(x) () +# define TRIO_NOARGS +# define TRIO_ARGS1(list,a1) list a1; +# define TRIO_ARGS2(list,a1,a2) list a1; a2; +# define TRIO_ARGS3(list,a1,a2,a3) list a1; a2; a3; +# define TRIO_ARGS4(list,a1,a2,a3,a4) list a1; a2; a3; a4; +# define TRIO_ARGS5(list,a1,a2,a3,a4,a5) list a1; a2; a3; a4; a5; +# define TRIO_ARGS6(list,a1,a2,a3,a4,a5,a6) list a1; a2; a3; a4; a5; a6; +# define TRIO_ARGS7(list,a1,a2,a3,a4,a5,a6,a7) list a1; a2; a3; a4; a5; a6; a7; +# define TRIO_ARGS8(list,a1,a2,a3,a4,a5,a6,a7,a8) list a1; a2; a3; a4; a5; a6; a7; a8; +# define TRIO_VARGS2(list,a1,a2) list a1; a2 +# define TRIO_VARGS3(list,a1,a2,a3) list a1; a2; a3 +# define TRIO_VARGS4(list,a1,a2,a3,a4) list a1; a2; a3; a4 +# define TRIO_VARGS5(list,a1,a2,a3,a4,a5) list a1; a2; a3; a4; a5 +# define TRIO_VA_DECL va_dcl +# define TRIO_VA_START(x,y) va_start(x) +# define TRIO_VA_END(x) va_end(x) +#else /* ANSI C */ +# define TRIO_CONST const +# define TRIO_VOLATILE volatile +# define TRIO_SIGNED signed +typedef long double trio_long_double_t; +typedef void * trio_pointer_t; +# define TRIO_SUFFIX_LONG(x) x ## L +# define TRIO_PROTO(x) x +# define TRIO_NOARGS void +# define TRIO_ARGS1(list,a1) (a1) +# define TRIO_ARGS2(list,a1,a2) (a1,a2) +# define TRIO_ARGS3(list,a1,a2,a3) (a1,a2,a3) +# define TRIO_ARGS4(list,a1,a2,a3,a4) (a1,a2,a3,a4) +# define TRIO_ARGS5(list,a1,a2,a3,a4,a5) (a1,a2,a3,a4,a5) +# define TRIO_ARGS6(list,a1,a2,a3,a4,a5,a6) (a1,a2,a3,a4,a5,a6) +# define TRIO_ARGS7(list,a1,a2,a3,a4,a5,a6,a7) (a1,a2,a3,a4,a5,a6,a7) +# define TRIO_ARGS8(list,a1,a2,a3,a4,a5,a6,a7,a8) (a1,a2,a3,a4,a5,a6,a7,a8) +# define TRIO_VARGS2 TRIO_ARGS2 +# define TRIO_VARGS3 TRIO_ARGS3 +# define TRIO_VARGS4 TRIO_ARGS4 +# define TRIO_VARGS5 TRIO_ARGS5 +# define TRIO_VA_DECL ... +# define TRIO_VA_START(x,y) va_start(x,y) +# define TRIO_VA_END(x) va_end(x) +#endif + +#if defined(PREDEF_STANDARD_C99) || defined(PREDEF_STANDARD_CXX) +# define TRIO_INLINE inline +#else +# if defined(TRIO_COMPILER_GCC) +# define TRIO_INLINE __inline__ +# endif +# if defined(TRIO_COMPILER_MSVC) +# define TRIO_INLINE _inline +# endif +# if defined(TRIO_COMPILER_BCB) +# define TRIO_INLINE __inline +# endif +#endif +#if !defined(TRIO_INLINE) +# define TRIO_INLINE +#endif + +/************************************************************************* + * Workarounds + */ + +#if defined(TRIO_PLATFORM_VMS) +/* + * Computations done with constants at compile time can trigger these + * even when compiling with IEEE enabled. + */ +# pragma message disable (UNDERFLOW, FLOATOVERFL) + +# if (__CRTL_VER < 80210001) +/* + * Although the compiler supports C99 language constructs, the C + * run-time library does not contain all C99 functions. + */ +# if defined(PREDEF_STANDARD_C99) +# undef PREDEF_STANDARD_C99 +# endif +# endif +#endif + +/* + * Not all preprocessors supports the LL token. + */ +#if defined(TRIO_COMPILER_MSVC) || defined(TRIO_COMPILER_BCB) +#else +# define TRIO_COMPILER_SUPPORTS_LL +#endif + +#if defined(__CYGWIN__) +/* + * Cygwin defines the macros for hosted C99, but does not support certain + * long double math functions. + */ +# include <cygwin/version.h> +# define TRIO_CYGWIN_VERSION_API CYGWIN_VERSION_API_MAJOR * 1000 + \ + CYGWIN_VERSION_API_MINOR +/* + * Please change the version number below when the Cygwin API supports + * long double math functions (powl, fmodl, etc.) + */ +# if TRIO_CYGWIN_VERSION_API < 99999999 +# define TRIO_NO_FLOORL 1 +# define TRIO_NO_CEILL 1 +# define TRIO_NO_POWL 1 +# define TRIO_NO_FMODL 1 +# define TRIO_NO_LOG10L 1 +# endif +#endif + +#endif /* TRIO_TRIODEF_H */ diff --git a/winpr/libwinpr/utils/trio/trionan.c b/winpr/libwinpr/utils/trio/trionan.c new file mode 100644 index 000000000..301632257 --- /dev/null +++ b/winpr/libwinpr/utils/trio/trionan.c @@ -0,0 +1,1257 @@ +/************************************************************************* + * + * $Id: trionan.c,v 1.33 2005/05/29 11:57:25 breese Exp $ + * + * Copyright (C) 2001 Bjorn Reese <breese@users.sourceforge.net> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF + * MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE AUTHORS AND + * CONTRIBUTORS ACCEPT NO RESPONSIBILITY IN ANY CONCEIVABLE MANNER. + * + ************************************************************************ + * + * Functions to handle special quantities in floating-point numbers + * (that is, NaNs and infinity). They provide the capability to detect + * and fabricate special quantities. + * + * Although written to be as portable as possible, it can never be + * guaranteed to work on all platforms, as not all hardware supports + * special quantities. + * + * The approach used here (approximately) is to: + * + * 1. Use C99 functionality when available. + * 2. Use IEEE 754 bit-patterns if possible. + * 3. Use platform-specific techniques. + * + ************************************************************************/ + +/************************************************************************* + * Include files + */ +#include "triodef.h" +#include "trionan.h" + +#include <math.h> +#include <string.h> +#include <limits.h> +#if !defined(TRIO_PLATFORM_SYMBIAN) +# include <float.h> +#endif +#if defined(TRIO_PLATFORM_UNIX) +# include <signal.h> +#endif +#if defined(TRIO_COMPILER_DECC) +# include <fp_class.h> +#endif +#include <assert.h> + +#if defined(TRIO_DOCUMENTATION) +# include "doc/doc_nan.h" +#endif +/** @addtogroup SpecialQuantities + @{ +*/ + +/************************************************************************* + * Definitions + */ + +#if !defined(TRIO_PUBLIC_NAN) +# define TRIO_PUBLIC_NAN TRIO_PUBLIC +#endif +#if !defined(TRIO_PRIVATE_NAN) +# define TRIO_PRIVATE_NAN TRIO_PRIVATE +#endif + +#define TRIO_TRUE (1 == 1) +#define TRIO_FALSE (0 == 1) + +/* + * We must enable IEEE floating-point on Alpha + */ +#if defined(__alpha) && !defined(_IEEE_FP) +# if defined(TRIO_COMPILER_DECC) +# if defined(TRIO_PLATFORM_VMS) +# error "Must be compiled with option /IEEE_MODE=UNDERFLOW_TO_ZERO/FLOAT=IEEE" +# else +# if !defined(_CFE) +# error "Must be compiled with option -ieee" +# endif +# endif +# else +# if defined(TRIO_COMPILER_GCC) +# error "Must be compiled with option -mieee" +# endif +# endif +#endif /* __alpha && ! _IEEE_FP */ + +/* + * In ANSI/IEEE 754-1985 64-bits double format numbers have the + * following properties (amoungst others) + * + * o FLT_RADIX == 2: binary encoding + * o DBL_MAX_EXP == 1024: 11 bits exponent, where one bit is used + * to indicate special numbers (e.g. NaN and Infinity), so the + * maximum exponent is 10 bits wide (2^10 == 1024). + * o DBL_MANT_DIG == 53: The mantissa is 52 bits wide, but because + * numbers are normalized the initial binary 1 is represented + * implicitly (the so-called "hidden bit"), which leaves us with + * the ability to represent 53 bits wide mantissa. + */ +#if defined(__STDC_IEC_559__) +# define TRIO_IEEE_754 +#else +# if (FLT_RADIX - 0 == 2) && (DBL_MAX_EXP - 0 == 1024) && (DBL_MANT_DIG - 0 == 53) +# define TRIO_IEEE_754 +# endif +#endif + +/* + * Determine which fpclassify_and_sign() function to use. + */ +#if defined(TRIO_FUNC_FPCLASSIFY_AND_SIGNBIT) +# if defined(PREDEF_STANDARD_C99) && defined(fpclassify) +# define TRIO_FUNC_C99_FPCLASSIFY_AND_SIGNBIT +# else +# if defined(TRIO_COMPILER_DECC) +# define TRIO_FUNC_DECC_FPCLASSIFY_AND_SIGNBIT +# else +# if defined(TRIO_COMPILER_VISUALC) || defined(TRIO_COMPILER_BORLAND) +# define TRIO_FUNC_MS_FPCLASSIFY_AND_SIGNBIT +# else +# if defined(TRIO_COMPILER_HP) && defined(FP_PLUS_NORM) +# define TRIO_FUNC_HP_FPCLASSIFY_AND_SIGNBIT +# else +# if defined(TRIO_COMPILER_XLC) && defined(FP_PLUS_NORM) +# define TRIO_FUNC_XLC_FPCLASSIFY_AND_SIGNBIT +# else +# define TRIO_FUNC_INTERNAL_FPCLASSIFY_AND_SIGNBIT +# endif +# endif +# endif +# endif +# endif +#endif + +/* + * Determine how to generate negative zero. + */ +#if defined(TRIO_FUNC_NZERO) +# if defined(TRIO_IEEE_754) +# define TRIO_NZERO_IEEE_754 +# else +# define TRIO_NZERO_FALLBACK +# endif +#endif + +/* + * Determine how to generate positive infinity. + */ +#if defined(TRIO_FUNC_PINF) +# if defined(INFINITY) && defined(__STDC_IEC_559__) +# define TRIO_PINF_C99_MACRO +# else +# if defined(TRIO_IEEE_754) +# define TRIO_PINF_IEEE_754 +# else +# define TRIO_PINF_FALLBACK +# endif +# endif +#endif + +/* + * Determine how to generate NaN. + */ +#if defined(TRIO_FUNC_NAN) +# if defined(PREDEF_STANDARD_C99) && !defined(TRIO_COMPILER_DECC) +# define TRIO_NAN_C99_FUNCTION +# else +# if defined(NAN) && defined(__STDC_IEC_559__) +# define TRIO_NAN_C99_MACRO +# else +# if defined(TRIO_IEEE_754) +# define TRIO_NAN_IEEE_754 +# else +# define TRIO_NAN_FALLBACK +# endif +# endif +# endif +#endif + +/* + * Resolve internal dependencies. + */ +#if defined(TRIO_FUNC_INTERNAL_FPCLASSIFY_AND_SIGNBIT) +# define TRIO_FUNC_INTERNAL_ISNAN +# define TRIO_FUNC_INTERNAL_ISINF +# if defined(TRIO_IEEE_754) +# define TRIO_FUNC_INTERNAL_IS_SPECIAL_QUANTITY +# define TRIO_FUNC_INTERNAL_IS_NEGATIVE +# endif +#endif + +#if defined(TRIO_NZERO_IEEE_754) \ + || defined(TRIO_PINF_IEEE_754) \ + || defined(TRIO_NAN_IEEE_754) +# define TRIO_FUNC_INTERNAL_MAKE_DOUBLE +#endif + +#if defined(TRIO_FUNC_INTERNAL_ISNAN) +# if defined(PREDEF_STANDARD_XPG3) +# define TRIO_INTERNAL_ISNAN_XPG3 +# else +# if defined(TRIO_IEEE_754) +# define TRIO_INTERNAL_ISNAN_IEEE_754 +# else +# define TRIO_INTERNAL_ISNAN_FALLBACK +# endif +# endif +#endif + +#if defined(TRIO_FUNC_INTERNAL_ISINF) +# if defined(TRIO_IEEE_754) +# define TRIO_INTERNAL_ISINF_IEEE_754 +# else +# define TRIO_INTERNAL_ISINF_FALLBACK +# endif +#endif + +/************************************************************************* + * Constants + */ + +#if !defined(TRIO_EMBED_NAN) +static TRIO_CONST char rcsid[] = "@(#)$Id: trionan.c,v 1.33 2005/05/29 11:57:25 breese Exp $"; +#endif + +#if defined(TRIO_FUNC_INTERNAL_MAKE_DOUBLE) \ + || defined(TRIO_FUNC_INTERNAL_IS_SPECIAL_QUANTITY) \ + || defined(TRIO_FUNC_INTERNAL_IS_NEGATIVE) +/* + * Endian-agnostic indexing macro. + * + * The value of internalEndianMagic, when converted into a 64-bit + * integer, becomes 0x0706050403020100 (we could have used a 64-bit + * integer value instead of a double, but not all platforms supports + * that type). The value is automatically encoded with the correct + * endianess by the compiler, which means that we can support any + * kind of endianess. The individual bytes are then used as an index + * for the IEEE 754 bit-patterns and masks. + */ +#define TRIO_DOUBLE_INDEX(x) (((unsigned char *)&internalEndianMagic)[7-(x)]) +static TRIO_CONST double internalEndianMagic = 7.949928895127363e-275; +#endif + +#if defined(TRIO_FUNC_INTERNAL_IS_SPECIAL_QUANTITY) +/* Mask for the exponent */ +static TRIO_CONST unsigned char ieee_754_exponent_mask[] = { + 0x7F, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +}; + +/* Mask for the mantissa */ +static TRIO_CONST unsigned char ieee_754_mantissa_mask[] = { + 0x00, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF +}; +#endif + +#if defined(TRIO_FUNC_INTERNAL_IS_NEGATIVE) +/* Mask for the sign bit */ +static TRIO_CONST unsigned char ieee_754_sign_mask[] = { + 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +}; +#endif + +#if defined(TRIO_NZERO_IEEE_754) +/* Bit-pattern for negative zero */ +static TRIO_CONST unsigned char ieee_754_negzero_array[] = { + 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +}; +#endif + +#if defined(TRIO_PINF_IEEE_754) +/* Bit-pattern for infinity */ +static TRIO_CONST unsigned char ieee_754_infinity_array[] = { + 0x7F, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +}; +#endif + +#if defined(TRIO_NAN_IEEE_754) +/* Bit-pattern for quiet NaN */ +static TRIO_CONST unsigned char ieee_754_qnan_array[] = { + 0x7F, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +}; +#endif + + +/************************************************************************* + * Internal functions + */ + +/* + * internal_make_double + */ +#if defined(TRIO_FUNC_INTERNAL_MAKE_DOUBLE) + +TRIO_PRIVATE_NAN double +internal_make_double +TRIO_ARGS1((values), + TRIO_CONST unsigned char *values) +{ + TRIO_VOLATILE double result; + int i; + + for (i = 0; i < (int)sizeof(double); i++) { + ((TRIO_VOLATILE unsigned char *)&result)[TRIO_DOUBLE_INDEX(i)] = values[i]; + } + return result; +} + +#endif + +/* + * internal_is_special_quantity + */ +#if defined(TRIO_FUNC_INTERNAL_IS_SPECIAL_QUANTITY) + +TRIO_PRIVATE_NAN int +internal_is_special_quantity +TRIO_ARGS2((number, has_mantissa), + double number, + int *has_mantissa) +{ + unsigned int i; + unsigned char current; + int is_special_quantity = TRIO_TRUE; + + *has_mantissa = 0; + + for (i = 0; i < (unsigned int)sizeof(double); i++) { + current = ((unsigned char *)&number)[TRIO_DOUBLE_INDEX(i)]; + is_special_quantity + &= ((current & ieee_754_exponent_mask[i]) == ieee_754_exponent_mask[i]); + *has_mantissa |= (current & ieee_754_mantissa_mask[i]); + } + return is_special_quantity; +} + +#endif + +/* + * internal_is_negative + */ +#if defined(TRIO_FUNC_INTERNAL_IS_NEGATIVE) + +TRIO_PRIVATE_NAN int +internal_is_negative +TRIO_ARGS1((number), + double number) +{ + unsigned int i; + int is_negative = TRIO_FALSE; + + for (i = 0; i < (unsigned int)sizeof(double); i++) { + is_negative |= (((unsigned char *)&number)[TRIO_DOUBLE_INDEX(i)] + & ieee_754_sign_mask[i]); + } + return is_negative; +} + +#endif + +#if defined(TRIO_FUNC_C99_FPCLASSIFY_AND_SIGNBIT) + +TRIO_PRIVATE_NAN TRIO_INLINE int +c99_fpclassify_and_signbit +TRIO_ARGS2((number, is_negative), + double number, + int *is_negative) +{ + *is_negative = signbit(number); + switch (fpclassify(number)) { + case FP_NAN: + return TRIO_FP_NAN; + case FP_INFINITE: + return TRIO_FP_INFINITE; + case FP_SUBNORMAL: + return TRIO_FP_SUBNORMAL; + case FP_ZERO: + return TRIO_FP_ZERO; + default: + return TRIO_FP_NORMAL; + } +} + +#endif /* TRIO_FUNC_C99_FPCLASSIFY_AND_SIGNBIT */ + +#if defined(TRIO_FUNC_DECC_FPCLASSIFY_AND_SIGNBIT) + +TRIO_PRIVATE_NAN TRIO_INLINE int +decc_fpclassify_and_signbit +TRIO_ARGS2((number, is_negative), + double number, + int *is_negative) +{ + switch (fp_class(number)) { + case FP_QNAN: + case FP_SNAN: + *is_negative = TRIO_FALSE; /* NaN has no sign */ + return TRIO_FP_NAN; + case FP_POS_INF: + *is_negative = TRIO_FALSE; + return TRIO_FP_INFINITE; + case FP_NEG_INF: + *is_negative = TRIO_TRUE; + return TRIO_FP_INFINITE; + case FP_POS_DENORM: + *is_negative = TRIO_FALSE; + return TRIO_FP_SUBNORMAL; + case FP_NEG_DENORM: + *is_negative = TRIO_TRUE; + return TRIO_FP_SUBNORMAL; + case FP_POS_ZERO: + *is_negative = TRIO_FALSE; + return TRIO_FP_ZERO; + case FP_NEG_ZERO: + *is_negative = TRIO_TRUE; + return TRIO_FP_ZERO; + case FP_POS_NORM: + *is_negative = TRIO_FALSE; + return TRIO_FP_NORMAL; + case FP_NEG_NORM: + *is_negative = TRIO_TRUE; + return TRIO_FP_NORMAL; + default: + *is_negative = (number < 0.0); + return TRIO_FP_NORMAL; + } +} + +#endif /* TRIO_FUNC_DECC_FPCLASSIFY_AND_SIGNBIT */ + +#if defined(TRIO_FUNC_MS_FPCLASSIFY_AND_SIGNBIT) + +TRIO_PRIVATE_NAN int +ms_fpclassify_and_signbit +TRIO_ARGS2((number, is_negative), + double number, + int *is_negative) +{ + int result; +# if defined(TRIO_COMPILER_BORLAND) + /* + * The floating-point precision may be changed by the Borland _fpclass() + * function, so we have to save and restore the floating-point control mask. + */ + unsigned int mask; + /* Remember the old mask */ + mask = _control87(0, 0); +# endif + + switch (_fpclass(number)) { + case _FPCLASS_QNAN: + case _FPCLASS_SNAN: + *is_negative = TRIO_FALSE; /* NaN has no sign */ + result = TRIO_FP_NAN; + break; + case _FPCLASS_PINF: + *is_negative = TRIO_FALSE; + result = TRIO_FP_INFINITE; + break; + case _FPCLASS_NINF: + *is_negative = TRIO_TRUE; + result = TRIO_FP_INFINITE; + break; + case _FPCLASS_PD: + *is_negative = TRIO_FALSE; + result = TRIO_FP_SUBNORMAL; + break; + case _FPCLASS_ND: + *is_negative = TRIO_TRUE; + result = TRIO_FP_SUBNORMAL; + break; + case _FPCLASS_PZ: + *is_negative = TRIO_FALSE; + result = TRIO_FP_ZERO; + break; + case _FPCLASS_NZ: + *is_negative = TRIO_TRUE; + result = TRIO_FP_ZERO; + break; + case _FPCLASS_PN: + *is_negative = TRIO_FALSE; + result = TRIO_FP_NORMAL; + break; + case _FPCLASS_NN: + *is_negative = TRIO_TRUE; + result = TRIO_FP_NORMAL; + break; + default: + *is_negative = (number < 0.0); + result = TRIO_FP_NORMAL; + break; + } + +# if defined(TRIO_COMPILER_BORLAND) + /* Restore the old precision */ + (void)_control87(mask, MCW_PC); +# endif + + return result; +} + +#endif /* TRIO_FUNC_MS_FPCLASSIFY_AND_SIGNBIT */ + +#if defined(TRIO_FUNC_HP_FPCLASSIFY_AND_SIGNBIT) + +TRIO_PRIVATE_NAN TRIO_INLINE int +hp_fpclassify_and_signbit +TRIO_ARGS2((number, is_negative), + double number, + int *is_negative) +{ + /* + * HP-UX 9.x and 10.x have an fpclassify() function, that is different + * from the C99 fpclassify() macro supported on HP-UX 11.x. + */ + switch (fpclassify(number)) { + case FP_QNAN: + case FP_SNAN: + *is_negative = TRIO_FALSE; /* NaN has no sign */ + return TRIO_FP_NAN; + case FP_PLUS_INF: + *is_negative = TRIO_FALSE; + return TRIO_FP_INFINITE; + case FP_MINUS_INF: + *is_negative = TRIO_TRUE; + return TRIO_FP_INFINITE; + case FP_PLUS_DENORM: + *is_negative = TRIO_FALSE; + return TRIO_FP_SUBNORMAL; + case FP_MINUS_DENORM: + *is_negative = TRIO_TRUE; + return TRIO_FP_SUBNORMAL; + case FP_PLUS_ZERO: + *is_negative = TRIO_FALSE; + return TRIO_FP_ZERO; + case FP_MINUS_ZERO: + *is_negative = TRIO_TRUE; + return TRIO_FP_ZERO; + case FP_PLUS_NORM: + *is_negative = TRIO_FALSE; + return TRIO_FP_NORMAL; + case FP_MINUS_NORM: + *is_negative = TRIO_TRUE; + return TRIO_FP_NORMAL; + default: + *is_negative = (number < 0.0); + return TRIO_FP_NORMAL; + } +} + +#endif /* TRIO_FUNC_HP_FPCLASSIFY_AND_SIGNBIT */ + +#if defined(TRIO_FUNC_XLC_FPCLASSIFY_AND_SIGNBIT) + +TRIO_PRIVATE_NAN TRIO_INLINE int +xlc_fpclassify_and_signbit +TRIO_ARGS2((number, is_negative), + double number, + int *is_negative) +{ + /* + * AIX has class() for C, and _class() for C++ + */ +# if defined(__cplusplus) +# define AIX_CLASS(n) _class(n) +# else +# define AIX_CLASS(n) class(n) +# endif + + switch (AIX_CLASS(number)) { + case FP_QNAN: + case FP_SNAN: + *is_negative = TRIO_FALSE; /* NaN has no sign */ + return TRIO_FP_NAN; + case FP_PLUS_INF: + *is_negative = TRIO_FALSE; + return TRIO_FP_INFINITE; + case FP_MINUS_INF: + *is_negative = TRIO_TRUE; + return TRIO_FP_INFINITE; + case FP_PLUS_DENORM: + *is_negative = TRIO_FALSE; + return TRIO_FP_SUBNORMAL; + case FP_MINUS_DENORM: + *is_negative = TRIO_TRUE; + return TRIO_FP_SUBNORMAL; + case FP_PLUS_ZERO: + *is_negative = TRIO_FALSE; + return TRIO_FP_ZERO; + case FP_MINUS_ZERO: + *is_negative = TRIO_TRUE; + return TRIO_FP_ZERO; + case FP_PLUS_NORM: + *is_negative = TRIO_FALSE; + return TRIO_FP_NORMAL; + case FP_MINUS_NORM: + *is_negative = TRIO_TRUE; + return TRIO_FP_NORMAL; + default: + *is_negative = (number < 0.0); + return TRIO_FP_NORMAL; + } +} + +#endif /* TRIO_FUNC_XLC_FPCLASSIFY_AND_SIGNBIT */ + +#if defined(TRIO_FUNC_INTERNAL_ISNAN) + +TRIO_PRIVATE_NAN TRIO_INLINE int +internal_isnan +TRIO_ARGS1((number), + double number) +{ +# if defined(TRIO_INTERNAL_ISNAN_XPG3) || defined(TRIO_PLATFORM_SYMBIAN) + /* + * XPG3 defines isnan() as a function. + */ + return isnan(number); + +# endif + +# if defined(TRIO_INTERNAL_ISNAN_IEEE_754) + + /* + * Examine IEEE 754 bit-pattern. A NaN must have a special exponent + * pattern, and a non-empty mantissa. + */ + int has_mantissa; + int is_special_quantity; + + is_special_quantity = internal_is_special_quantity(number, &has_mantissa); + + return (is_special_quantity && has_mantissa); + +# endif + +# if defined(TRIO_INTERNAL_ISNAN_FALLBACK) + + /* + * Fallback solution + */ + int status; + double integral, fraction; + +# if defined(TRIO_PLATFORM_UNIX) + void (*signal_handler)(int) = signal(SIGFPE, SIG_IGN); +# endif + + status = (/* + * NaN is the only number which does not compare to itself + */ + ((TRIO_VOLATILE double)number != (TRIO_VOLATILE double)number) || + /* + * Fallback solution if NaN compares to NaN + */ + ((number != 0.0) && + (fraction = modf(number, &integral), + integral == fraction))); + +# if defined(TRIO_PLATFORM_UNIX) + signal(SIGFPE, signal_handler); +# endif + + return status; + +# endif +} + +#endif /* TRIO_FUNC_INTERNAL_ISNAN */ + +#if defined(TRIO_FUNC_INTERNAL_ISINF) + +TRIO_PRIVATE_NAN TRIO_INLINE int +internal_isinf +TRIO_ARGS1((number), + double number) +{ +# if defined(TRIO_PLATFORM_SYMBIAN) + + return isinf(number); + +# endif + +# if defined(TRIO_INTERNAL_ISINF_IEEE_754) + /* + * Examine IEEE 754 bit-pattern. Infinity must have a special exponent + * pattern, and an empty mantissa. + */ + int has_mantissa; + int is_special_quantity; + + is_special_quantity = internal_is_special_quantity(number, &has_mantissa); + + return (is_special_quantity && !has_mantissa) + ? ((number < 0.0) ? -1 : 1) + : 0; + +# endif + +# if defined(TRIO_INTERNAL_ISINF_FALLBACK) + + /* + * Fallback solution. + */ + int status; + +# if defined(TRIO_PLATFORM_UNIX) + void (*signal_handler)(int) = signal(SIGFPE, SIG_IGN); +# endif + + double infinity = trio_pinf(); + + status = ((number == infinity) + ? 1 + : ((number == -infinity) ? -1 : 0)); + +# if defined(TRIO_PLATFORM_UNIX) + signal(SIGFPE, signal_handler); +# endif + + return status; + +# endif +} + +#endif /* TRIO_FUNC_INTERNAL_ISINF */ + +/************************************************************************* + * Public functions + */ + +#if defined(TRIO_FUNC_FPCLASSIFY_AND_SIGNBIT) + +TRIO_PUBLIC_NAN int +trio_fpclassify_and_signbit +TRIO_ARGS2((number, is_negative), + double number, + int *is_negative) +{ + /* The TRIO_FUNC_xxx_FPCLASSIFY_AND_SIGNBIT macros are mutually exclusive */ + +#if defined(TRIO_FUNC_C99_FPCLASSIFY_AND_SIGNBIT) + + return c99_fpclassify_and_signbit(number, is_negative); + +#endif + +#if defined(TRIO_FUNC_DECC_FPCLASSIFY_AND_SIGNBIT) + + return decc_fpclassify_and_signbit(number, is_negative); + +#endif + +#if defined(TRIO_FUNC_MS_FPCLASSIFY_AND_SIGNBIT) + + return ms_fpclassify_and_signbit(number, is_negative); + +#endif + +#if defined(TRIO_FUNC_HP_FPCLASSIFY_AND_SIGNBIT) + + return hp_fpclassify_and_signbit(number, is_negative); + +#endif + +#if defined(TRIO_FUNC_XLC_FPCLASSIFY_AND_SIGNBIT) + + return xlc_fpclassify_and_signbit(number, is_negative); + +#endif + +#if defined(TRIO_FUNC_INTERNAL_FPCLASSIFY_AND_SIGNBIT) + + /* + * Fallback solution. + */ + int rc; + + if (number == 0.0) { + /* + * In IEEE 754 the sign of zero is ignored in comparisons, so we + * have to handle this as a special case by examining the sign bit + * directly. + */ +# if defined(TRIO_IEEE_754) + *is_negative = internal_is_negative(number); +# else + *is_negative = TRIO_FALSE; /* FIXME */ +# endif + return TRIO_FP_ZERO; + } + if (internal_isnan(number)) { + *is_negative = TRIO_FALSE; + return TRIO_FP_NAN; + } + rc = internal_isinf(number); + if (rc != 0) { + *is_negative = (rc == -1); + return TRIO_FP_INFINITE; + } + if ((number > 0.0) && (number < DBL_MIN)) { + *is_negative = TRIO_FALSE; + return TRIO_FP_SUBNORMAL; + } + if ((number < 0.0) && (number > -DBL_MIN)) { + *is_negative = TRIO_TRUE; + return TRIO_FP_SUBNORMAL; + } + *is_negative = (number < 0.0); + return TRIO_FP_NORMAL; + +#endif +} + +#endif + +/** + Check for NaN. + + @param number An arbitrary floating-point number. + @return Boolean value indicating whether or not the number is a NaN. +*/ +#if defined(TRIO_FUNC_ISNAN) + +TRIO_PUBLIC_NAN int +trio_isnan +TRIO_ARGS1((number), + double number) +{ + int dummy; + + return (trio_fpclassify_and_signbit(number, &dummy) == TRIO_FP_NAN); +} + +#endif + +/** + Check for infinity. + + @param number An arbitrary floating-point number. + @return 1 if positive infinity, -1 if negative infinity, 0 otherwise. +*/ +#if defined(TRIO_FUNC_ISINF) + +TRIO_PUBLIC_NAN int +trio_isinf +TRIO_ARGS1((number), + double number) +{ + int is_negative; + + if (trio_fpclassify_and_signbit(number, &is_negative) == TRIO_FP_INFINITE) + { + return (is_negative) ? -1 : 1; + } + else + { + return 0; + } +} + +#endif + +/** + Check for finity. + + @param number An arbitrary floating-point number. + @return Boolean value indicating whether or not the number is a finite. +*/ +#if defined(TRIO_FUNC_ISFINITE) + +TRIO_PUBLIC_NAN int +trio_isfinite +TRIO_ARGS1((number), + double number) +{ + int dummy; + + switch (trio_fpclassify_and_signbit(number, &dummy)) + { + case TRIO_FP_INFINITE: + case TRIO_FP_NAN: + return 0; + default: + return 1; + } +} + +#endif + +/** + Examine the sign of a number. + + @param number An arbitrary floating-point number. + @return Boolean value indicating whether or not the number has the + sign bit set (i.e. is negative). +*/ +#if defined(TRIO_FUNC_SIGNBIT) + +TRIO_PUBLIC_NAN int +trio_signbit +TRIO_ARGS1((number), + double number) +{ + int is_negative; + + (void)trio_fpclassify_and_signbit(number, &is_negative); + return is_negative; +} + +#endif + +/** + Examine the class of a number. + + @param number An arbitrary floating-point number. + @return Enumerable value indicating the class of @p number +*/ +#if defined(TRIO_FUNC_FPCLASSIFY) + +TRIO_PUBLIC_NAN int +trio_fpclassify +TRIO_ARGS1((number), + double number) +{ + int dummy; + + return trio_fpclassify_and_signbit(number, &dummy); +} + +#endif + +/** + Generate negative zero. + + @return Floating-point representation of negative zero. +*/ +#if defined(TRIO_FUNC_NZERO) + +TRIO_PUBLIC_NAN double +trio_nzero(TRIO_NOARGS) +{ +# if defined(TRIO_NZERO_IEEE_754) + + return internal_make_double(ieee_754_negzero_array); + +# endif + +# if defined(TRIO_NZERO_FALLBACK) + + TRIO_VOLATILE double zero = 0.0; + + return -zero; + +# endif +} + +#endif + +/** + Generate positive infinity. + + @return Floating-point representation of positive infinity. +*/ +#if defined(TRIO_FUNC_PINF) + +TRIO_PUBLIC_NAN double +trio_pinf(TRIO_NOARGS) +{ + /* Cache the result */ + static double pinf_value = 0.0; + + if (pinf_value == 0.0) { + +# if defined(TRIO_PINF_C99_MACRO) + + pinf_value = (double)INFINITY; + +# endif + +# if defined(TRIO_PINF_IEEE_754) + + pinf_value = internal_make_double(ieee_754_infinity_array); + +# endif + +# if defined(TRIO_PINF_FALLBACK) + /* + * If HUGE_VAL is different from DBL_MAX, then HUGE_VAL is used + * as infinity. Otherwise we have to resort to an overflow + * operation to generate infinity. + */ +# if defined(TRIO_PLATFORM_UNIX) + void (*signal_handler)(int) = signal(SIGFPE, SIG_IGN); +# endif + + pinf_value = HUGE_VAL; + if (HUGE_VAL == DBL_MAX) { + /* Force overflow */ + pinf_value += HUGE_VAL; + } + +# if defined(TRIO_PLATFORM_UNIX) + signal(SIGFPE, signal_handler); +# endif + +# endif + } + return pinf_value; +} + +#endif + +/** + Generate negative infinity. + + @return Floating-point value of negative infinity. +*/ +#if defined(TRIO_FUNC_NINF) + +TRIO_PUBLIC_NAN double +trio_ninf(TRIO_NOARGS) +{ + static double ninf_value = 0.0; + + if (ninf_value == 0.0) { + /* + * Negative infinity is calculated by negating positive infinity, + * which can be done because it is legal to do calculations on + * infinity (for example, 1 / infinity == 0). + */ + ninf_value = -trio_pinf(); + } + return ninf_value; +} + +#endif + +/** + Generate NaN. + + @return Floating-point representation of NaN. +*/ +#if defined(TRIO_FUNC_NAN) + +TRIO_PUBLIC_NAN double +trio_nan(TRIO_NOARGS) +{ + /* Cache the result */ + static double nan_value = 0.0; + + if (nan_value == 0.0) { + +# if defined(TRIO_NAN_C99_FUNCTION) || defined(TRIO_PLATFORM_SYMBIAN) + + nan_value = nan(""); + +# endif + +# if defined(TRIO_NAN_C99_MACRO) + + nan_value = (double)NAN; + +# endif + +# if defined(TRIO_NAN_IEEE_754) + + nan_value = internal_make_double(ieee_754_qnan_array); + +# endif + +# if defined(TRIO_NAN_FALLBACK) + /* + * There are several ways to generate NaN. The one used here is + * to divide infinity by infinity. I would have preferred to add + * negative infinity to positive infinity, but that yields wrong + * result (infinity) on FreeBSD. + * + * This may fail if the hardware does not support NaN, or if + * the Invalid Operation floating-point exception is unmasked. + */ +# if defined(TRIO_PLATFORM_UNIX) + void (*signal_handler)(int) = signal(SIGFPE, SIG_IGN); +# endif + + nan_value = trio_pinf() / trio_pinf(); + +# if defined(TRIO_PLATFORM_UNIX) + signal(SIGFPE, signal_handler); +# endif + +# endif + } + return nan_value; +} + +#endif + +/** @} SpecialQuantities */ + +/************************************************************************* + * For test purposes. + * + * Add the following compiler option to include this test code. + * + * Unix : -DSTANDALONE + * VMS : /DEFINE=(STANDALONE) + */ +#if defined(STANDALONE) +# include <stdio.h> + +static TRIO_CONST char * +getClassification +TRIO_ARGS1((type), + int type) +{ + switch (type) { + case TRIO_FP_INFINITE: + return "FP_INFINITE"; + case TRIO_FP_NAN: + return "FP_NAN"; + case TRIO_FP_NORMAL: + return "FP_NORMAL"; + case TRIO_FP_SUBNORMAL: + return "FP_SUBNORMAL"; + case TRIO_FP_ZERO: + return "FP_ZERO"; + default: + return "FP_UNKNOWN"; + } +} + +static void +print_class +TRIO_ARGS2((prefix, number), + TRIO_CONST char *prefix, + double number) +{ + printf("%-6s: %s %-15s %g\n", + prefix, + trio_signbit(number) ? "-" : "+", + getClassification(trio_fpclassify(number)), + number); +} + +int main(TRIO_NOARGS) +{ + double my_nan; + double my_pinf; + double my_ninf; +# if defined(TRIO_PLATFORM_UNIX) + void (*signal_handler) TRIO_PROTO((int)); +# endif + + my_nan = trio_nan(); + my_pinf = trio_pinf(); + my_ninf = trio_ninf(); + + print_class("Nan", my_nan); + print_class("PInf", my_pinf); + print_class("NInf", my_ninf); + print_class("PZero", 0.0); + print_class("NZero", -0.0); + print_class("PNorm", 1.0); + print_class("NNorm", -1.0); + print_class("PSub", 1.01e-307 - 1.00e-307); + print_class("NSub", 1.00e-307 - 1.01e-307); + + printf("NaN : %4g 0x%02x%02x%02x%02x%02x%02x%02x%02x (%2d, %2d, %2d)\n", + my_nan, + ((unsigned char *)&my_nan)[0], + ((unsigned char *)&my_nan)[1], + ((unsigned char *)&my_nan)[2], + ((unsigned char *)&my_nan)[3], + ((unsigned char *)&my_nan)[4], + ((unsigned char *)&my_nan)[5], + ((unsigned char *)&my_nan)[6], + ((unsigned char *)&my_nan)[7], + trio_isnan(my_nan), trio_isinf(my_nan), trio_isfinite(my_nan)); + printf("PInf: %4g 0x%02x%02x%02x%02x%02x%02x%02x%02x (%2d, %2d, %2d)\n", + my_pinf, + ((unsigned char *)&my_pinf)[0], + ((unsigned char *)&my_pinf)[1], + ((unsigned char *)&my_pinf)[2], + ((unsigned char *)&my_pinf)[3], + ((unsigned char *)&my_pinf)[4], + ((unsigned char *)&my_pinf)[5], + ((unsigned char *)&my_pinf)[6], + ((unsigned char *)&my_pinf)[7], + trio_isnan(my_pinf), trio_isinf(my_pinf), trio_isfinite(my_pinf)); + printf("NInf: %4g 0x%02x%02x%02x%02x%02x%02x%02x%02x (%2d, %2d, %2d)\n", + my_ninf, + ((unsigned char *)&my_ninf)[0], + ((unsigned char *)&my_ninf)[1], + ((unsigned char *)&my_ninf)[2], + ((unsigned char *)&my_ninf)[3], + ((unsigned char *)&my_ninf)[4], + ((unsigned char *)&my_ninf)[5], + ((unsigned char *)&my_ninf)[6], + ((unsigned char *)&my_ninf)[7], + trio_isnan(my_ninf), trio_isinf(my_ninf), trio_isfinite(my_ninf)); + +# if defined(TRIO_PLATFORM_UNIX) + signal_handler = signal(SIGFPE, SIG_IGN); +# endif + + my_pinf = DBL_MAX + DBL_MAX; + my_ninf = -my_pinf; + my_nan = my_pinf / my_pinf; + +# if defined(TRIO_PLATFORM_UNIX) + signal(SIGFPE, signal_handler); +# endif + + printf("NaN : %4g 0x%02x%02x%02x%02x%02x%02x%02x%02x (%2d, %2d, %2d)\n", + my_nan, + ((unsigned char *)&my_nan)[0], + ((unsigned char *)&my_nan)[1], + ((unsigned char *)&my_nan)[2], + ((unsigned char *)&my_nan)[3], + ((unsigned char *)&my_nan)[4], + ((unsigned char *)&my_nan)[5], + ((unsigned char *)&my_nan)[6], + ((unsigned char *)&my_nan)[7], + trio_isnan(my_nan), trio_isinf(my_nan), trio_isfinite(my_nan)); + printf("PInf: %4g 0x%02x%02x%02x%02x%02x%02x%02x%02x (%2d, %2d, %2d)\n", + my_pinf, + ((unsigned char *)&my_pinf)[0], + ((unsigned char *)&my_pinf)[1], + ((unsigned char *)&my_pinf)[2], + ((unsigned char *)&my_pinf)[3], + ((unsigned char *)&my_pinf)[4], + ((unsigned char *)&my_pinf)[5], + ((unsigned char *)&my_pinf)[6], + ((unsigned char *)&my_pinf)[7], + trio_isnan(my_pinf), trio_isinf(my_pinf), trio_isfinite(my_pinf)); + printf("NInf: %4g 0x%02x%02x%02x%02x%02x%02x%02x%02x (%2d, %2d, %2d)\n", + my_ninf, + ((unsigned char *)&my_ninf)[0], + ((unsigned char *)&my_ninf)[1], + ((unsigned char *)&my_ninf)[2], + ((unsigned char *)&my_ninf)[3], + ((unsigned char *)&my_ninf)[4], + ((unsigned char *)&my_ninf)[5], + ((unsigned char *)&my_ninf)[6], + ((unsigned char *)&my_ninf)[7], + trio_isnan(my_ninf), trio_isinf(my_ninf), trio_isfinite(my_ninf)); + + return 0; +} +#endif diff --git a/winpr/libwinpr/utils/trio/trionan.h b/winpr/libwinpr/utils/trio/trionan.h new file mode 100644 index 000000000..a38b1cc26 --- /dev/null +++ b/winpr/libwinpr/utils/trio/trionan.h @@ -0,0 +1,183 @@ +/************************************************************************* + * + * $Id: trionan.h,v 1.9 2005/03/27 18:52:45 breese Exp $ + * + * Copyright (C) 2001 Bjorn Reese <breese@users.sourceforge.net> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF + * MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE AUTHORS AND + * CONTRIBUTORS ACCEPT NO RESPONSIBILITY IN ANY CONCEIVABLE MANNER. + * + ************************************************************************/ + +#ifndef TRIO_TRIONAN_H +#define TRIO_TRIONAN_H + +#include "triodef.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#if !defined(TRIO_PUBLIC_NAN) +# if !defined(TRIO_PUBLIC) +# define TRIO_PUBLIC +# endif +# define TRIO_PUBLIC_NAN TRIO_PUBLIC +#endif + +enum { + TRIO_FP_INFINITE, + TRIO_FP_NAN, + TRIO_FP_NORMAL, + TRIO_FP_SUBNORMAL, + TRIO_FP_ZERO +}; + +/************************************************************************* + * Dependencies + */ + +#if defined(TRIO_EMBED_NAN) + +/* + * The application that trionan is embedded in must define which functions + * it uses. + * + * The following resolves internal dependencies. + */ + +# if defined(TRIO_FUNC_ISNAN) \ + || defined(TRIO_FUNC_ISINF) +# if !defined(TRIO_FUNC_FPCLASSIFY_AND_SIGNBIT) +# define TRIO_FUNC_FPCLASSIFY_AND_SIGNBIT +# endif +# endif + +# if defined(TRIO_FUNC_NAN) +# if !defined(TRIO_FUNC_PINF) +# define TRIO_FUNC_PINF +# endif +# endif + +# if defined(TRIO_FUNC_NINF) +# if !defined(TRIO_FUNC_PINF) +# define TRIO_FUNC_PINF +# endif +# endif + +#else + +/* + * When trionan is not embedded all all functions are defined. + */ + +# define TRIO_FUNC_NAN +# define TRIO_FUNC_PINF +# define TRIO_FUNC_NINF +# define TRIO_FUNC_NZERO +# define TRIO_FUNC_ISNAN +# define TRIO_FUNC_ISINF +# define TRIO_FUNC_ISFINITE +# define TRIO_FUNC_SIGNBIT +# define TRIO_FUNC_FPCLASSIFY +# define TRIO_FUNC_FPCLASSIFY_AND_SIGNBIT + +#endif + +/************************************************************************* + * Functions + */ + +/* + * Return NaN (Not-a-Number). + */ +#if defined(TRIO_FUNC_NAN) +TRIO_PUBLIC_NAN double +trio_nan +TRIO_PROTO((void)); +#endif + +/* + * Return positive infinity. + */ +#if defined(TRIO_FUNC_PINF) +TRIO_PUBLIC_NAN double +trio_pinf +TRIO_PROTO((void)); +#endif + +/* + * Return negative infinity. + */ +#if defined(TRIO_FUNC_NINF) +TRIO_PUBLIC_NAN double +trio_ninf +TRIO_PROTO((void)); +#endif + +/* + * Return negative zero. + */ +#if defined(TRIO_FUNC_NZERO) +TRIO_PUBLIC_NAN double +trio_nzero +TRIO_PROTO((TRIO_NOARGS)); +#endif + +/* + * If number is a NaN return non-zero, otherwise return zero. + */ +#if defined(TRIO_FUNC_ISNAN) +TRIO_PUBLIC_NAN int +trio_isnan +TRIO_PROTO((double number)); +#endif + +/* + * If number is positive infinity return 1, if number is negative + * infinity return -1, otherwise return 0. + */ +#if defined(TRIO_FUNC_ISINF) +TRIO_PUBLIC_NAN int +trio_isinf +TRIO_PROTO((double number)); +#endif + +/* + * If number is finite return non-zero, otherwise return zero. + */ +#if defined(TRIO_FUNC_ISFINITE) +TRIO_PUBLIC_NAN int +trio_isfinite +TRIO_PROTO((double number)); +#endif + +#if defined(TRIO_FUNC_SIGNBIT) +TRIO_PUBLIC_NAN int +trio_signbit +TRIO_PROTO((double number)); +#endif + +#if defined(TRIO_FUNC_FPCLASSIFY) +TRIO_PUBLIC_NAN int +trio_fpclassify +TRIO_PROTO((double number)); +#endif + +#if defined(TRIO_FUNC_FPCLASSIFY_AND_SIGNBIT) +TRIO_PUBLIC_NAN int +trio_fpclassify_and_signbit +TRIO_PROTO((double number, int *is_negative)); +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* TRIO_TRIONAN_H */ diff --git a/winpr/libwinpr/utils/trio/triop.h b/winpr/libwinpr/utils/trio/triop.h new file mode 100644 index 000000000..2f676998e --- /dev/null +++ b/winpr/libwinpr/utils/trio/triop.h @@ -0,0 +1,496 @@ +/************************************************************************* + * + * $Id: triop.h,v 1.19 2010/09/12 11:08:08 breese Exp $ + * + * Copyright (C) 2000 Bjorn Reese and Daniel Stenberg. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF + * MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE AUTHORS AND + * CONTRIBUTORS ACCEPT NO RESPONSIBILITY IN ANY CONCEIVABLE MANNER. + * + ************************************************************************ + * + * Private functions, types, etc. used for callback functions. + * + * The ref pointer is an opaque type and should remain as such. + * Private data must only be accessible through the getter and + * setter functions. + * + ************************************************************************/ + +#ifndef TRIO_TRIOP_H +#define TRIO_TRIOP_H + +#include "triodef.h" + +#include <stdlib.h> +#if defined(TRIO_COMPILER_ANCIENT) +# include <varargs.h> +#else +# include <stdarg.h> +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +/************************************************************************* + * Supported standards + */ + +/* + * TRIO_C99 (=0 or =1) + * + * Define this to 0 to disable C99 format specifier extensions, or + * define to 1 to enable them. The format specifiers that are + * disabled by this switch are labelled with [C99] in the format + * specifier documentation. + */ +#if !defined(TRIO_C99) +# define TRIO_C99 1 +#endif + +/* + * TRIO_BSD (=0 or =1) + * + * Define this to 0 to disable BSD format specifier extensions, or + * define to 1 to enable them. The format specifiers that are + * disabled by this switch are labelled with [BSD] in the format + * specifier documentation. + */ +#if !defined(TRIO_BSD) +# define TRIO_BSD 1 +#endif + +/* + * TRIO_GNU (=0 or =1) + * + * Define this to 0 to disable GNU format specifier extensions, or + * define to 1 to enable them. The format specifiers that are + * disabled by this switch are labelled with [GNU] in the format + * specifier documentation. + */ +#if !defined(TRIO_GNU) +# define TRIO_GNU 1 +#endif + +/* + * TRIO_MISC (=0 or =1) + * + * Define this to 0 to disable miscellaneous format specifier + * extensions, or define to 1 to enable them. The format specifiers + * that are disabled by this switch are labelled with [MISC] in the + * format specifier documentation. + */ +#if !defined(TRIO_MISC) +# define TRIO_MISC 1 +#endif + +/* + * TRIO_UNIX98 (=0 or =1) + * + * Define this to 0 to disable UNIX98 format specifier extensions, + * or define to 1 to enable them. The format specifiers that are + * disabled by this switch are labelled with [UNIX98] in the format + * specifier documentation. + */ +#if !defined(TRIO_UNIX98) +# define TRIO_UNIX98 1 +#endif + +/* + * TRIO_MICROSOFT (=0 or =1) + * + * Define this to 0 to disable Microsoft Visual C format specifier + * extensions, or define to 1 to enable them. The format specifiers + * that are disabled by this switch are labelled with [MSVC] in the + * format specifier documentation. + */ +#if !defined(TRIO_MICROSOFT) +# define TRIO_MICROSOFT 1 +#endif + +/* + * TRIO_EXTENSION (=0 or =1) + * + * Define this to 0 to disable Trio-specific extensions, or define + * to 1 to enable them. This has two effects: it controls whether + * or not the Trio user-defined formating mechanism + * (trio_register() etc) is supported, and it enables or disables + * Trio's own format specifier extensions. The format specifiers + * that are disabled by this switch are labelled with [TRIO] in + * the format specifier documentation. + */ +#if !defined(TRIO_EXTENSION) +# define TRIO_EXTENSION 1 +#endif + +/* + * TRIO_DEPRECATED (=0 or =1) + * + * Define this to 0 to disable deprecated functionality, or define + * to 1 to enable them. + */ +#if !defined(TRIO_DEPRECATED) +# define TRIO_DEPRECATED 1 +#endif + +/************************************************************************* + * Features + */ + +#if defined(TRIO_SNPRINTF_ONLY) +# define TRIO_FEATURE_SCANF 0 +# define TRIO_FEATURE_FILE 0 +# define TRIO_FEATURE_STDIO 0 +# define TRIO_FEATURE_FD 0 +# define TRIO_FEATURE_DYNAMICSTRING 0 +# define TRIO_FEATURE_CLOSURE 0 +# define TRIO_FEATURE_ARGFUNC 0 +# define TRIO_FEATURE_STRERR 0 +# define TRIO_FEATURE_LOCALE 0 +# define TRIO_EMBED_NAN 1 +# define TRIO_EMBED_STRING 1 +#endif + +/* + * TRIO_FEATURE_SCANF (=0 or =1) + * + * Define this to 0 to disable all the scanf() variants, or define to 1 + * to enable them. + */ +#if !defined(TRIO_FEATURE_SCANF) +# define TRIO_FEATURE_SCANF 1 +#endif + +/* + * TRIO_FEATURE_FILE (=0 or =1) + * + * Define this to 0 to disable compilation of the trio_fprintf() and + * trio_fscanf() family of functions, or define to 1 to enable them. + * + * This may be useful on an embedded platform with no filesystem. + * Note that trio_printf() uses fwrite to write to stdout, so if you + * do not have an implementation of fwrite() at all then you must also + * define TRIO_FEATURE_STDIO to 0. + */ +#if !defined(TRIO_FEATURE_FILE) +# define TRIO_FEATURE_FILE 1 +#endif + +/* + * TRIO_FEATURE_STDIO (=0 or =1) + * + * Define this to 0 to disable compilation of the trio_printf() and + * trio_scanf() family of functions, or define to 1 to enable them. + * + * This may be useful on an embedded platform with no standard I/O. + */ +#if !defined(TRIO_FEATURE_STDIO) +# define TRIO_FEATURE_STDIO 1 +#endif + +/* + * TRIO_FEATURE_FD (=0 or =1) + * + * Define this to 0 to disable compilation of the trio_dprintf() and + * trio_dscanf() family of functions, or define to 1 to enable them. + * + * This may be useful on an embedded platform with no filesystem, or on + * a platform that supports file I/O using FILE* but not using raw file + * descriptors. + */ +#if !defined(TRIO_FEATURE_FD) +# define TRIO_FEATURE_FD 1 +#endif + +/* + * TRIO_FEATURE_DYNAMICSTRING (=0 or =1) + * + * Define this to 0 to disable compilation of the trio_aprintf() + * family of functions, or define to 1 to enable them. + * + * If you define both this and TRIO_MINIMAL to 0, then Trio will never + * call malloc or free. + */ +#if !defined(TRIO_FEATURE_DYNAMICSTRING) +# define TRIO_FEATURE_DYNAMICSTRING 1 +#endif + +/* + * TRIO_FEATURE_CLOSURE (=0 or =1) + * + * Define this to 0 to disable compilation of the trio_cprintf() and + * trio_cscanf() family of functions, or define to 1 to enable them. + * + * These functions are rarely needed. This saves a (small) amount of code. + */ +#if !defined(TRIO_FEATURE_CLOSURE) +# define TRIO_FEATURE_CLOSURE 1 +#endif + +/* + * TRIO_FEATURE_ARGFUNC (=0 or =1) + * + * Define this to 0 to disable compilation of trio_cprintff() and + * trio_cscanff() functions and related code (might have a tiny + * performance gain), or define to 1 to enable them. + * + * This functionality is needed only if you have to fetch the arguments using + * a pull model instead of passing them all at once (for example if you plan + * to plug the library into a script interpreter or validate the types). + * + * Only the closure family of functions are available with this interface, + * because if you need this, you usually provide custom input/output + * handling too (and so this forces TRIO_FEATURE_CLOSURE to enabled). + */ +#if !defined(TRIO_FEATURE_ARGFUNC) +# define TRIO_FEATURE_ARGFUNC 1 +#endif +#if TRIO_FEATURE_ARGFUNC +# undef TRIO_FEATURE_CLOSURE +# define TRIO_FEATURE_CLOSURE 1 +#endif + +/* + * TRIO_FEATURE_ERRORCODE (=0 or =1) + * + * Define this to 0 to return -1 from the print and scan function on + * error, or define to 1 to return a negative number with debugging + * information as part of the return code. + * + * If enabled, the return code will be a negative number, which encodes + * an error code and an error location. These can be decoded with the + * TRIO_ERROR_CODE and TRIO_ERROR_POSITION macros. + */ +#if defined(TRIO_ERRORS) +# define TRIO_FEATURE_ERRORCODE TRIO_ERRORS +#endif +#if !defined(TRIO_FEATURE_ERRORCODE) +# define TRIO_FEATURE_ERRORCODE 1 +#endif + +/* + * TRIO_FEATURE_STRERR (=0 or =1) + * + * Define this to 0 if you do not use trio_strerror(), or define to 1 if + * you do use it. + * + * This saves a (small) amount of code. + */ +#if !defined(TRIO_FEATURE_STRERR) +# define TRIO_FEATURE_STRERR 1 +#endif + +/* + * TRIO_FEATURE_FLOAT (=0 or =1) + * + * Define this to 0 to disable all floating-point support, or define + * to 1 to enable it. + * + * This is useful in restricted embedded platforms that do not support + * floating-point. Obviously you cannot use floating-point format + * specifiers if you define this. + * + * Do not compile trionan.c if you disable this. + */ +#if !defined(TRIO_FEATURE_FLOAT) +# define TRIO_FEATURE_FLOAT 1 +#endif + +/* + * TRIO_FEATURE_LOCALE (=0 or =1) + * + * Define this to 0 to disable customized locale support, or define + * to 1 to enable it. + * + * This saves a (small) amount of code. + */ +#if !defined(TRIO_FEATURE_LOCALE) +# define TRIO_FEATURE_LOCALE 1 +#endif + +/* + * TRIO_MINIMAL + * + * Define this to disable building the public trionan.h and triostr.h. + * If you define this, then you must not compile trionan.c and triostr.c + * separately. + */ +#if defined(TRIO_MINIMAL) +# if !defined(TRIO_EMBED_NAN) +# define TRIO_EMBED_NAN +# endif +# if !defined(TRIO_EMBED_STRING) +# define TRIO_EMBED_STRING +# endif +#endif + +/* Does not work yet. Do not enable */ +#ifndef TRIO_FEATURE_WIDECHAR +# define TRIO_FEATURE_WIDECHAR 0 +#endif + +/************************************************************************* + * Mapping standards to internal features + */ + +#if !defined(TRIO_FEATURE_HEXFLOAT) +# define TRIO_FEATURE_HEXFLOAT (TRIO_C99 && TRIO_FEATURE_FLOAT) +#endif + +#if !defined(TRIO_FEATURE_LONGDOUBLE) +# define TRIO_FEATURE_LONGDOUBLE TRIO_FEATURE_FLOAT +#endif + +#if !defined(TRIO_FEATURE_ERRNO) +# define TRIO_FEATURE_ERRNO TRIO_GNU +#endif + +#if !defined(TRIO_FEATURE_QUAD) +# define TRIO_FEATURE_QUAD (TRIO_BSD || TRIO_GNU) +#endif + +#if !defined(TRIO_FEATURE_SIZE_T) +# define TRIO_FEATURE_SIZE_T TRIO_C99 +#endif + +#if !defined(TRIO_FEATURE_SIZE_T_UPPER) +# define TRIO_FEATURE_SIZE_T_UPPER TRIO_GNU +#endif + +#if !defined(TRIO_FEATURE_PTRDIFF_T) +# define TRIO_FEATURE_PTRDIFF_T TRIO_C99 +#endif + +#if !defined(TRIO_FEATURE_INTMAX_T) +# define TRIO_FEATURE_INTMAX_T TRIO_C99 +#endif + +#if !defined(TRIO_FEATURE_FIXED_SIZE) +# define TRIO_FEATURE_FIXED_SIZE TRIO_MICROSOFT +#endif + +#if !defined(TRIO_FEATURE_POSITIONAL) +# define TRIO_FEATURE_POSITIONAL TRIO_UNIX98 +#endif + +#if !defined(TRIO_FEATURE_USER_DEFINED) +# define TRIO_FEATURE_USER_DEFINED TRIO_EXTENSION +#endif + +#if !defined(TRIO_FEATURE_BINARY) +# define TRIO_FEATURE_BINARY TRIO_EXTENSION +#endif + +#if !defined(TRIO_FEATURE_QUOTE) +# define TRIO_FEATURE_QUOTE TRIO_EXTENSION +#endif + +#if !defined(TRIO_FEATURE_STICKY) +# define TRIO_FEATURE_STICKY TRIO_EXTENSION +#endif + +#if !defined(TRIO_FEATURE_VARSIZE) +# define TRIO_FEATURE_VARSIZE TRIO_EXTENSION +#endif + +#if !defined(TRIO_FEATURE_ROUNDING) +# define TRIO_FEATURE_ROUNDING TRIO_EXTENSION +#endif + +/************************************************************************* + * Memory handling + */ +#ifndef TRIO_MALLOC +# define TRIO_MALLOC(n) malloc(n) +#endif +#ifndef TRIO_REALLOC +# define TRIO_REALLOC(x,n) realloc((x),(n)) +#endif +#ifndef TRIO_FREE +# define TRIO_FREE(x) free(x) +#endif + + +/************************************************************************* + * User-defined specifiers + */ + +typedef int (*trio_callback_t) TRIO_PROTO((trio_pointer_t)); + +trio_pointer_t trio_register TRIO_PROTO((trio_callback_t callback, const char *name)); +void trio_unregister TRIO_PROTO((trio_pointer_t handle)); + +TRIO_CONST char *trio_get_format TRIO_PROTO((trio_pointer_t ref)); +TRIO_CONST trio_pointer_t trio_get_argument TRIO_PROTO((trio_pointer_t ref)); + +/* Modifiers */ +int trio_get_width TRIO_PROTO((trio_pointer_t ref)); +void trio_set_width TRIO_PROTO((trio_pointer_t ref, int width)); +int trio_get_precision TRIO_PROTO((trio_pointer_t ref)); +void trio_set_precision TRIO_PROTO((trio_pointer_t ref, int precision)); +int trio_get_base TRIO_PROTO((trio_pointer_t ref)); +void trio_set_base TRIO_PROTO((trio_pointer_t ref, int base)); +int trio_get_padding TRIO_PROTO((trio_pointer_t ref)); +void trio_set_padding TRIO_PROTO((trio_pointer_t ref, int is_padding)); +int trio_get_short TRIO_PROTO((trio_pointer_t ref)); /* h */ +void trio_set_shortshort TRIO_PROTO((trio_pointer_t ref, int is_shortshort)); +int trio_get_shortshort TRIO_PROTO((trio_pointer_t ref)); /* hh */ +void trio_set_short TRIO_PROTO((trio_pointer_t ref, int is_short)); +int trio_get_long TRIO_PROTO((trio_pointer_t ref)); /* l */ +void trio_set_long TRIO_PROTO((trio_pointer_t ref, int is_long)); +int trio_get_longlong TRIO_PROTO((trio_pointer_t ref)); /* ll */ +void trio_set_longlong TRIO_PROTO((trio_pointer_t ref, int is_longlong)); +int trio_get_longdouble TRIO_PROTO((trio_pointer_t ref)); /* L */ +void trio_set_longdouble TRIO_PROTO((trio_pointer_t ref, int is_longdouble)); +int trio_get_alternative TRIO_PROTO((trio_pointer_t ref)); /* # */ +void trio_set_alternative TRIO_PROTO((trio_pointer_t ref, int is_alternative)); +int trio_get_alignment TRIO_PROTO((trio_pointer_t ref)); /* - */ +void trio_set_alignment TRIO_PROTO((trio_pointer_t ref, int is_leftaligned)); +int trio_get_spacing TRIO_PROTO((trio_pointer_t ref)); /* (space) */ +void trio_set_spacing TRIO_PROTO((trio_pointer_t ref, int is_space)); +int trio_get_sign TRIO_PROTO((trio_pointer_t ref)); /* + */ +void trio_set_sign TRIO_PROTO((trio_pointer_t ref, int is_showsign)); +#if TRIO_FEATURE_QUOTE +int trio_get_quote TRIO_PROTO((trio_pointer_t ref)); /* ' */ +void trio_set_quote TRIO_PROTO((trio_pointer_t ref, int is_quote)); +#endif +int trio_get_upper TRIO_PROTO((trio_pointer_t ref)); +void trio_set_upper TRIO_PROTO((trio_pointer_t ref, int is_upper)); +#if TRIO_FEATURE_INTMAX_T +int trio_get_largest TRIO_PROTO((trio_pointer_t ref)); /* j */ +void trio_set_largest TRIO_PROTO((trio_pointer_t ref, int is_largest)); +#endif +#if TRIO_FEATURE_PTRDIFF_T +int trio_get_ptrdiff TRIO_PROTO((trio_pointer_t ref)); /* t */ +void trio_set_ptrdiff TRIO_PROTO((trio_pointer_t ref, int is_ptrdiff)); +#endif +#if TRIO_FEATURE_SIZE_T +int trio_get_size TRIO_PROTO((trio_pointer_t ref)); /* z / Z */ +void trio_set_size TRIO_PROTO((trio_pointer_t ref, int is_size)); +#endif + +/* Printing */ +int trio_print_ref TRIO_PROTO((trio_pointer_t ref, const char *format, ...)); +int trio_vprint_ref TRIO_PROTO((trio_pointer_t ref, const char *format, va_list args)); +int trio_printv_ref TRIO_PROTO((trio_pointer_t ref, const char *format, trio_pointer_t *args)); + +void trio_print_int TRIO_PROTO((trio_pointer_t ref, int number)); +void trio_print_uint TRIO_PROTO((trio_pointer_t ref, unsigned int number)); +/* void trio_print_long TRIO_PROTO((trio_pointer_t ref, long number)); */ +/* void trio_print_ulong TRIO_PROTO((trio_pointer_t ref, unsigned long number)); */ +void trio_print_double TRIO_PROTO((trio_pointer_t ref, double number)); +void trio_print_string TRIO_PROTO((trio_pointer_t ref, TRIO_CONST char *string)); +void trio_print_pointer TRIO_PROTO((trio_pointer_t ref, trio_pointer_t pointer)); + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* TRIO_TRIOP_H */ diff --git a/winpr/libwinpr/utils/trio/triostr.c b/winpr/libwinpr/utils/trio/triostr.c new file mode 100644 index 000000000..5721b7cb0 --- /dev/null +++ b/winpr/libwinpr/utils/trio/triostr.c @@ -0,0 +1,2385 @@ +/************************************************************************* + * + * $Id: triostr.c,v 1.36 2010/01/26 13:02:02 breese Exp $ + * + * Copyright (C) 2001 Bjorn Reese and Daniel Stenberg. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF + * MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE AUTHORS AND + * CONTRIBUTORS ACCEPT NO RESPONSIBILITY IN ANY CONCEIVABLE MANNER. + * + ************************************************************************/ + +/************************************************************************* + * Include files + */ + +#if defined(HAVE_CONFIG_H) +# include <config.h> +#endif +#include <assert.h> +#include <stdlib.h> +#include <string.h> +#include <ctype.h> +#include "triodef.h" +#include "triostr.h" +#if defined(TRIO_FUNC_TO_LONG_DOUBLE) +# define USE_MATH +#endif +#if defined(USE_MATH) +# include <math.h> +#endif + +/************************************************************************* + * Definitions + */ + +#if !defined(TRIO_PUBLIC_STRING) +# define TRIO_PUBLIC_STRING TRIO_PUBLIC +#endif +#if !defined(TRIO_PRIVATE_STRING) +# define TRIO_PRIVATE_STRING TRIO_PRIVATE +#endif + +#if !defined(NULL) +# define NULL 0 +#endif +#if !defined(NIL) +# define NIL ((char)0) +#endif +#if !defined(FALSE) +# define FALSE (1 == 0) +# define TRUE (! FALSE) +#endif +#if !defined(BOOLEAN_T) +# define BOOLEAN_T int +#endif + +#if defined(USE_MATH) +# if defined(PREDEF_STANDARD_C99) +# if defined(TRIO_COMPILER_DECC) +# if (TRIO_COMPILER_DECC - 0 > 80000000) +/* + * The OSF/1 runtime that comes with the DECC compiler does not support + * hexfloats conversion. + */ +# define USE_STRTOD +# define USE_STRTOF +# endif +# else +# define USE_STRTOD +# define USE_STRTOF +# endif +# else +# if defined(TRIO_COMPILER_VISUALC) +# define USE_STRTOD +# endif +#endif +#endif + +#if defined(TRIO_PLATFORM_UNIX) +# if defined(PREDEF_STANDARD_UNIX95) +# define USE_STRCASECMP +# define USE_STRNCASECMP +# endif +# if defined(TRIO_PLATFORM_SUNOS) +# define USE_SYS_ERRLIST +# else +# define USE_STRERROR +# endif +# if defined(TRIO_PLATFORM_QNX) +# define strcasecmp(x,y) stricmp(x,y) +# define strncasecmp(x,y,n) strnicmp(x,y,n) +# endif +#endif + +#if defined(TRIO_PLATFORM_WIN32) +# define USE_STRCASECMP +# if defined(TRIO_PLATFORM_WINCE) +# define strcasecmp(x,y) _stricmp(x,y) +# else +# define strcasecmp(x,y) strcmpi(x,y) +# endif +#endif + +#if !defined(HAVE_CONFIG_H) +# if !(defined(TRIO_PLATFORM_SUNOS)) +# define HAVE_TOLOWER +# define HAVE_TOUPPER +# endif +#endif + +#if defined(USE_MATH) && !defined(TRIO_NO_POWL) +# if !defined(HAVE_POWL) +# if defined(PREDEF_STANDARD_C99) \ + || defined(PREDEF_STANDARD_UNIX03) +# define HAVE_POWL +# else +# if defined(TRIO_COMPILER_VISUALC) +# if defined(powl) +# define HAVE_POWL +# endif +# endif +# endif +# endif +#endif + +#if defined(HAVE_POWL) +# define trio_powl(x,y) powl((x),(y)) +#else +# define trio_powl(x,y) pow((double)(x),(double)(y)) +#endif + +#if defined(TRIO_FUNC_TO_UPPER) \ + || (defined(TRIO_FUNC_EQUAL) && !defined(USE_STRCASECMP)) \ + || (defined(TRIO_FUNC_EQUAL_MAX) && !defined(USE_STRNCASECMP)) \ + || defined(TRIO_FUNC_MATCH) \ + || defined(TRIO_FUNC_TO_LONG_DOUBLE) \ + || defined(TRIO_FUNC_UPPER) +# define TRIO_FUNC_INTERNAL_TO_UPPER +#endif + +/************************************************************************* + * Structures + */ + +struct _trio_string_t +{ + char *content; + size_t length; + size_t allocated; +}; + +/************************************************************************* + * Constants + */ + +#if !defined(TRIO_EMBED_STRING) +static TRIO_CONST char rcsid[] = "@(#)$Id: triostr.c,v 1.36 2010/01/26 13:02:02 breese Exp $"; +#endif + +/************************************************************************* + * Static String Functions + */ + +#if defined(TRIO_DOCUMENTATION) +# include "doc/doc_static.h" +#endif +/** @addtogroup StaticStrings + @{ +*/ + +/* + * internal_duplicate_max + */ +#if defined(TRIO_FUNC_DUPLICATE) \ + || defined(TRIO_FUNC_DUPLICATE_MAX) \ + || defined(TRIO_FUNC_STRING_DUPLICATE) \ + || defined(TRIO_FUNC_XSTRING_DUPLICATE) + +TRIO_PRIVATE_STRING char * +internal_duplicate_max +TRIO_ARGS2((source, size), + TRIO_CONST char *source, + size_t size) +{ + char *target; + + assert(source); + + /* Make room for string plus a terminating zero */ + size++; + target = trio_create(size); + if (target) + { + trio_copy_max(target, size, source); + } + return target; +} + +#endif + +/* + * internal_string_alloc + */ +#if defined(TRIO_FUNC_STRING_CREATE) \ + || defined(TRIO_FUNC_STRING_DUPLICATE) \ + || defined(TRIO_FUNC_XSTRING_DUPLICATE) + +TRIO_PRIVATE_STRING trio_string_t * +internal_string_alloc(TRIO_NOARGS) +{ + trio_string_t *self; + + self = (trio_string_t *)TRIO_MALLOC(sizeof(trio_string_t)); + if (self) + { + self->content = NULL; + self->length = 0; + self->allocated = 0; + } + return self; +} + +#endif + +/* + * internal_string_grow + * + * The size of the string will be increased by 'delta' characters. If + * 'delta' is zero, the size will be doubled. + */ +#if defined(TRIO_FUNC_STRING_CREATE) \ + || defined(TRIO_FUNC_STRING_APPEND) \ + || defined(TRIO_FUNC_XSTRING_APPEND) \ + || defined(TRIO_FUNC_XSTRING_APPEND_CHAR) + +TRIO_PRIVATE_STRING BOOLEAN_T +internal_string_grow +TRIO_ARGS2((self, delta), + trio_string_t *self, + size_t delta) +{ + BOOLEAN_T status = FALSE; + char *new_content; + size_t new_size; + + new_size = (delta == 0) + ? ( (self->allocated == 0) ? 1 : self->allocated * 2 ) + : self->allocated + delta; + + new_content = (char *)TRIO_REALLOC(self->content, new_size); + if (new_content) + { + self->content = new_content; + self->allocated = new_size; + status = TRUE; + } + return status; +} + +#endif + +/* + * internal_string_grow_to + * + * The size of the string will be increased to 'length' plus one characters. + * If 'length' is less than the original size, the original size will be + * used (that is, the size of the string is never decreased). + */ +#if defined(TRIO_FUNC_STRING_APPEND) \ + || defined(TRIO_FUNC_XSTRING_APPEND) \ + || defined(TRIO_FUNC_XSTRING_APPEND_MAX) + +TRIO_PRIVATE_STRING BOOLEAN_T +internal_string_grow_to +TRIO_ARGS2((self, length), + trio_string_t *self, + size_t length) +{ + length++; /* Room for terminating zero */ + return (self->allocated < length) + ? internal_string_grow(self, length - self->allocated) + : TRUE; +} + +#endif + +#if defined(TRIO_FUNC_INTERNAL_TO_UPPER) + +TRIO_PRIVATE_STRING TRIO_INLINE int +internal_to_upper +TRIO_ARGS1((source), + int source) +{ +# if defined(HAVE_TOUPPER) + + return toupper(source); + +# else + + /* Does not handle locales or non-contiguous alphabetic characters */ + return ((source >= (int)'a') && (source <= (int)'z')) + ? source - 'a' + 'A' + : source; + +# endif +} + +#endif + + +/** + Create new string. + + @param size Size of new string. + @return Pointer to string, or NULL if allocation failed. +*/ +#if defined(TRIO_FUNC_CREATE) + +TRIO_PUBLIC_STRING char * +trio_create +TRIO_ARGS1((size), + size_t size) +{ + return (char *)TRIO_MALLOC(size); +} + +#endif + +/** + Destroy string. + + @param string String to be freed. +*/ +#if defined(TRIO_FUNC_DESTROY) + +TRIO_PUBLIC_STRING void +trio_destroy +TRIO_ARGS1((string), + char *string) +{ + if (string) + { + TRIO_FREE(string); + } +} + +#endif + +/** + Count the number of characters in a string. + + @param string String to measure. + @return Number of characters in @p string. +*/ +#if defined(TRIO_FUNC_LENGTH) + +TRIO_PUBLIC_STRING size_t +trio_length +TRIO_ARGS1((string), + TRIO_CONST char *string) +{ + return strlen(string); +} + +#endif + +/** + Count at most @p max characters in a string. + + @param string String to measure. + @param max Maximum number of characters to count. + @return The maximum value of @p max and number of characters in @p string. +*/ +#if defined(TRIO_FUNC_LENGTH_MAX) + +TRIO_PUBLIC_STRING size_t +trio_length_max +TRIO_ARGS2((string, max), + TRIO_CONST char *string, + size_t max) +{ + size_t i; + + for (i = 0; i < max; ++i) + { + if (string[i] == 0) + break; + } + return i; +} + +#endif + +/** + Append @p source at the end of @p target. + + @param target Target string. + @param source Source string. + @return Boolean value indicating success or failure. + + @pre @p target must point to a memory chunk with sufficient room to + contain the @p target string and @p source string. + @pre No boundary checking is performed, so insufficient memory will + result in a buffer overrun. + @post @p target will be zero terminated. +*/ +#if defined(TRIO_FUNC_APPEND) + +TRIO_PUBLIC_STRING int +trio_append +TRIO_ARGS2((target, source), + char *target, + TRIO_CONST char *source) +{ + assert(target); + assert(source); + + return (strcat(target, source) != NULL); +} + +#endif + +/** + Append at most @p max characters from @p source to @p target. + + @param target Target string. + @param max Maximum number of characters to append. + @param source Source string. + @return Boolean value indicating success or failure. + + @pre @p target must point to a memory chuck with sufficient room to + contain the @p target string and the @p source string (at most @p max + characters). + @pre No boundary checking is performed, so insufficient memory will + result in a buffer overrun. + @post @p target will be zero terminated. +*/ +#if defined(TRIO_FUNC_APPEND_MAX) + +TRIO_PUBLIC_STRING int +trio_append_max +TRIO_ARGS3((target, max, source), + char *target, + size_t max, + TRIO_CONST char *source) +{ + size_t length; + + assert(target); + assert(source); + + length = trio_length(target); + + if (max > length) + { + strncat(target, source, max - length - 1); + } + return TRUE; +} + +#endif + +/** + Determine if a string contains a substring. + + @param string String to be searched. + @param substring String to be found. + @return Boolean value indicating success or failure. +*/ +#if defined(TRIO_FUNC_CONTAINS) + +TRIO_PUBLIC_STRING int +trio_contains +TRIO_ARGS2((string, substring), + TRIO_CONST char *string, + TRIO_CONST char *substring) +{ + assert(string); + assert(substring); + + return (0 != strstr(string, substring)); +} + +#endif + +/** + Copy @p source to @p target. + + @param target Target string. + @param source Source string. + @return Boolean value indicating success or failure. + + @pre @p target must point to a memory chunk with sufficient room to + contain the @p source string. + @pre No boundary checking is performed, so insufficient memory will + result in a buffer overrun. + @post @p target will be zero terminated. +*/ +#if defined(TRIO_FUNC_COPY) + +TRIO_PUBLIC_STRING int +trio_copy +TRIO_ARGS2((target, source), + char *target, + TRIO_CONST char *source) +{ + assert(target); + assert(source); + + (void)strcpy(target, source); + return TRUE; +} + +#endif + +/** + Copy at most @p max - 1 characters from @p source to @p target. + + @param target Target string. + @param max Maximum number of characters to append (one of which is + a NUL terminator). In other words @p source must point to at least + @p max - 1 bytes, but @p target must point to at least @p max + bytes. + @param source Source string. + @return Boolean value indicating success or failure. + + @pre @p target must point to a memory chunk with sufficient room to + contain the @p source string and a NUL terminator (at most @p max + bytes total). + @pre No boundary checking is performed, so insufficient memory will + result in a buffer overrun. + @post @p target will be zero terminated. +*/ +#if defined(TRIO_FUNC_COPY_MAX) + +TRIO_PUBLIC_STRING int +trio_copy_max +TRIO_ARGS3((target, max, source), + char *target, + size_t max, + TRIO_CONST char *source) +{ + assert(target); + assert(source); + assert(max > 0); /* Includes != 0 */ + + (void)strncpy(target, source, max - 1); + target[max - 1] = (char)0; + return TRUE; +} + +#endif + +/** + Duplicate @p source. + + @param source Source string. + @return A copy of the @p source string. + + @post @p target will be zero terminated. +*/ +#if defined(TRIO_FUNC_DUPLICATE) + +TRIO_PUBLIC_STRING char * +trio_duplicate +TRIO_ARGS1((source), + TRIO_CONST char *source) +{ + return internal_duplicate_max(source, trio_length(source)); +} + +#endif + +/** + Duplicate at most @p max characters of @p source. + + @param source Source string. + @param max Maximum number of characters to duplicate. + @return A copy of the @p source string. + + @post @p target will be zero terminated. +*/ +#if defined(TRIO_FUNC_DUPLICATE_MAX) + +TRIO_PUBLIC_STRING char * +trio_duplicate_max +TRIO_ARGS2((source, max), + TRIO_CONST char *source, + size_t max) +{ + size_t length; + + assert(source); + assert(max > 0); + + length = trio_length(source); + if (length > max) + { + length = max; + } + return internal_duplicate_max(source, length); +} + +#endif + +/** + Compare if two strings are equal. + + @param first First string. + @param second Second string. + @return Boolean indicating whether the two strings are equal or not. + + Case-insensitive comparison. +*/ +#if defined(TRIO_FUNC_EQUAL) + +TRIO_PUBLIC_STRING int +trio_equal +TRIO_ARGS2((first, second), + TRIO_CONST char *first, + TRIO_CONST char *second) +{ + assert(first); + assert(second); + + if ((first != NULL) && (second != NULL)) + { +# if defined(USE_STRCASECMP) + return (0 == strcasecmp(first, second)); +# else + while ((*first != NIL) && (*second != NIL)) + { + if (internal_to_upper(*first) != internal_to_upper(*second)) + { + break; + } + first++; + second++; + } + return ((*first == NIL) && (*second == NIL)); +# endif + } + return FALSE; +} + +#endif + +/** + Compare if two strings are equal. + + @param first First string. + @param second Second string. + @return Boolean indicating whether the two strings are equal or not. + + Case-sensitive comparison. +*/ +#if defined(TRIO_FUNC_EQUAL_CASE) + +TRIO_PUBLIC_STRING int +trio_equal_case +TRIO_ARGS2((first, second), + TRIO_CONST char *first, + TRIO_CONST char *second) +{ + assert(first); + assert(second); + + if ((first != NULL) && (second != NULL)) + { + return (0 == strcmp(first, second)); + } + return FALSE; +} + +#endif + +/** + Compare if two strings up until the first @p max characters are equal. + + @param first First string. + @param max Maximum number of characters to compare. + @param second Second string. + @return Boolean indicating whether the two strings are equal or not. + + Case-sensitive comparison. +*/ +#if defined(TRIO_FUNC_EQUAL_CASE_MAX) + +TRIO_PUBLIC_STRING int +trio_equal_case_max +TRIO_ARGS3((first, max, second), + TRIO_CONST char *first, + size_t max, + TRIO_CONST char *second) +{ + assert(first); + assert(second); + + if ((first != NULL) && (second != NULL)) + { + return (0 == strncmp(first, second, max)); + } + return FALSE; +} + +#endif + +/** + Compare if two strings are equal. + + @param first First string. + @param second Second string. + @return Boolean indicating whether the two strings are equal or not. + + Collating characters are considered equal. +*/ +#if defined(TRIO_FUNC_EQUAL_LOCALE) + +TRIO_PUBLIC_STRING int +trio_equal_locale +TRIO_ARGS2((first, second), + TRIO_CONST char *first, + TRIO_CONST char *second) +{ + assert(first); + assert(second); + +# if defined(LC_COLLATE) + return (strcoll(first, second) == 0); +# else + return trio_equal(first, second); +# endif +} + +#endif + +/** + Compare if two strings up until the first @p max characters are equal. + + @param first First string. + @param max Maximum number of characters to compare. + @param second Second string. + @return Boolean indicating whether the two strings are equal or not. + + Case-insensitive comparison. +*/ +#if defined(TRIO_FUNC_EQUAL_MAX) + +TRIO_PUBLIC_STRING int +trio_equal_max +TRIO_ARGS3((first, max, second), + TRIO_CONST char *first, + size_t max, + TRIO_CONST char *second) +{ + assert(first); + assert(second); + + if ((first != NULL) && (second != NULL)) + { +# if defined(USE_STRNCASECMP) + return (0 == strncasecmp(first, second, max)); +# else + /* Not adequately tested yet */ + size_t cnt = 0; + while ((*first != NIL) && (*second != NIL) && (cnt <= max)) + { + if (internal_to_upper(*first) != internal_to_upper(*second)) + { + break; + } + first++; + second++; + cnt++; + } + return ((cnt == max) || ((*first == NIL) && (*second == NIL))); +# endif + } + return FALSE; +} + +#endif + +/** + Provide a textual description of an error code (errno). + + @param error_number Error number. + @return Textual description of @p error_number. +*/ +#if defined(TRIO_FUNC_ERROR) + +TRIO_PUBLIC_STRING TRIO_CONST char * +trio_error +TRIO_ARGS1((error_number), + int error_number) +{ +# if defined(USE_STRERROR) + + return strerror(error_number); + +# else +# if defined(USE_SYS_ERRLIST) + + extern char *sys_errlist[]; + extern int sys_nerr; + + return ((error_number < 0) || (error_number >= sys_nerr)) + ? "unknown" + : sys_errlist[error_number]; + +# else + + return "unknown"; + +# endif +# endif +} + +#endif + +/** + Format the date/time according to @p format. + + @param target Target string. + @param max Maximum number of characters to format. + @param format Formatting string. + @param datetime Date/time structure. + @return Number of formatted characters. + + The formatting string accepts the same specifiers as the standard C + function strftime. +*/ +#if defined(TRIO_FUNC_FORMAT_DATE_MAX) + +TRIO_PUBLIC_STRING size_t +trio_format_date_max +TRIO_ARGS4((target, max, format, datetime), + char *target, + size_t max, + TRIO_CONST char *format, + TRIO_CONST struct tm *datetime) +{ + assert(target); + assert(format); + assert(datetime); + assert(max > 0); + + return strftime(target, max, format, datetime); +} + +#endif + +/** + Calculate a hash value for a string. + + @param string String to be calculated on. + @param type Hash function. + @return Calculated hash value. + + @p type can be one of the following + @li @c TRIO_HASH_PLAIN Plain hash function. +*/ +#if defined(TRIO_FUNC_HASH) + +TRIO_PUBLIC_STRING unsigned long +trio_hash +TRIO_ARGS2((string, type), + TRIO_CONST char *string, + int type) +{ + unsigned long value = 0L; + char ch; + + assert(string); + + switch (type) + { + case TRIO_HASH_PLAIN: + while ( (ch = *string++) != NIL ) + { + value *= 31; + value += (unsigned long)ch; + } + break; + default: + assert(FALSE); + break; + } + return value; +} + +#endif + +/** + Find first occurrence of a character in a string. + + @param string String to be searched. + @param character Character to be found. + @return A pointer to the found character, or NULL if character was not found. + */ +#if defined(TRIO_FUNC_INDEX) + +TRIO_PUBLIC_STRING char * +trio_index +TRIO_ARGS2((string, character), + TRIO_CONST char *string, + int character) +{ + assert(string); + + return strchr(string, character); +} + +#endif + +/** + Find last occurrence of a character in a string. + + @param string String to be searched. + @param character Character to be found. + @return A pointer to the found character, or NULL if character was not found. + */ +#if defined(TRIO_FUNC_INDEX_LAST) + +TRIO_PUBLIC_STRING char * +trio_index_last +TRIO_ARGS2((string, character), + TRIO_CONST char *string, + int character) +{ + assert(string); + + return strchr(string, character); +} + +#endif + +/** + Convert the alphabetic letters in the string to lower-case. + + @param target String to be converted. + @return Number of processed characters (converted or not). +*/ +#if defined(TRIO_FUNC_LOWER) + +TRIO_PUBLIC_STRING int +trio_lower +TRIO_ARGS1((target), + char *target) +{ + assert(target); + + return trio_span_function(target, target, trio_to_lower); +} + +#endif + +/** + Compare two strings using wildcards. + + @param string String to be searched. + @param pattern Pattern, including wildcards, to search for. + @return Boolean value indicating success or failure. + + Case-insensitive comparison. + + The following wildcards can be used + @li @c * Match any number of characters. + @li @c ? Match a single character. +*/ +#if defined(TRIO_FUNC_MATCH) + +TRIO_PUBLIC_STRING int +trio_match +TRIO_ARGS2((string, pattern), + TRIO_CONST char *string, + TRIO_CONST char *pattern) +{ + assert(string); + assert(pattern); + + for (; ('*' != *pattern); ++pattern, ++string) + { + if (NIL == *string) + { + return (NIL == *pattern); + } + if ((internal_to_upper((int)*string) != internal_to_upper((int)*pattern)) + && ('?' != *pattern)) + { + return FALSE; + } + } + /* two-line patch to prevent *too* much recursiveness: */ + while ('*' == pattern[1]) + pattern++; + + do + { + if ( trio_match(string, &pattern[1]) ) + { + return TRUE; + } + } + while (*string++); + + return FALSE; +} + +#endif + +/** + Compare two strings using wildcards. + + @param string String to be searched. + @param pattern Pattern, including wildcards, to search for. + @return Boolean value indicating success or failure. + + Case-sensitive comparison. + + The following wildcards can be used + @li @c * Match any number of characters. + @li @c ? Match a single character. +*/ +#if defined(TRIO_FUNC_MATCH_CASE) + +TRIO_PUBLIC_STRING int +trio_match_case +TRIO_ARGS2((string, pattern), + TRIO_CONST char *string, + TRIO_CONST char *pattern) +{ + assert(string); + assert(pattern); + + for (; ('*' != *pattern); ++pattern, ++string) + { + if (NIL == *string) + { + return (NIL == *pattern); + } + if ((*string != *pattern) + && ('?' != *pattern)) + { + return FALSE; + } + } + /* two-line patch to prevent *too* much recursiveness: */ + while ('*' == pattern[1]) + pattern++; + + do + { + if ( trio_match_case(string, &pattern[1]) ) + { + return TRUE; + } + } + while (*string++); + + return FALSE; +} + +#endif + +/** + Execute a function on each character in string. + + @param target Target string. + @param source Source string. + @param Function Function to be executed. + @return Number of processed characters. +*/ +#if defined(TRIO_FUNC_SPAN_FUNCTION) + +TRIO_PUBLIC_STRING size_t +trio_span_function +TRIO_ARGS3((target, source, Function), + char *target, + TRIO_CONST char *source, + int (*Function) TRIO_PROTO((int))) +{ + size_t count = 0; + + assert(target); + assert(source); + assert(Function); + + while (*source != NIL) + { + *target++ = Function(*source++); + count++; + } + return count; +} + +#endif + +/** + Search for a substring in a string. + + @param string String to be searched. + @param substring String to be found. + @return Pointer to first occurrence of @p substring in @p string, or NULL + if no match was found. +*/ +#if defined(TRIO_FUNC_SUBSTRING) + +TRIO_PUBLIC_STRING char * +trio_substring +TRIO_ARGS2((string, substring), + TRIO_CONST char *string, + TRIO_CONST char *substring) +{ + assert(string); + assert(substring); + + return strstr(string, substring); +} + +#endif + +/** + Search for a substring in the first @p max characters of a string. + + @param string String to be searched. + @param max Maximum characters to be searched. + @param substring String to be found. + @return Pointer to first occurrence of @p substring in @p string, or NULL + if no match was found. +*/ +#if defined(TRIO_FUNC_SUBSTRING_MAX) + +TRIO_PUBLIC_STRING char * +trio_substring_max +TRIO_ARGS3((string, max, substring), + TRIO_CONST char *string, + size_t max, + TRIO_CONST char *substring) +{ + size_t count; + size_t size; + char *result = NULL; + + assert(string); + assert(substring); + + size = trio_length(substring); + if (size <= max) + { + for (count = 0; count <= max - size; count++) + { + if (trio_equal_max(substring, size, &string[count])) + { + result = (char *)&string[count]; + break; + } + } + } + return result; +} + +#endif + +/** + Tokenize string. + + @param string String to be tokenized. + @param delimiters String containing list of delimiting characters. + @return Start of new token. + + @warning @p string will be destroyed. +*/ +#if defined(TRIO_FUNC_TOKENIZE) + +TRIO_PUBLIC_STRING char * +trio_tokenize +TRIO_ARGS2((string, delimiters), + char *string, + TRIO_CONST char *delimiters) +{ + assert(delimiters); + + return strtok(string, delimiters); +} + +#endif + +/** + Convert string to floating-point number. + + @param source String to be converted. + @param endp Pointer to end of the converted string. + @return A floating-point number. + + The following Extended Backus-Naur form is used + @verbatim + double ::= [ <sign> ] + ( <number> | + <number> <decimal_point> <number> | + <decimal_point> <number> ) + [ <exponential> [ <sign> ] <number> ] + number ::= 1*( <digit> ) + digit ::= ( '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' ) + exponential ::= ( 'e' | 'E' ) + sign ::= ( '-' | '+' ) + decimal_point ::= '.' + @endverbatim +*/ +#if defined(TRIO_FUNC_TO_LONG_DOUBLE) + +/* FIXME: Add EBNF for hex-floats */ +TRIO_PUBLIC_STRING trio_long_double_t +trio_to_long_double +TRIO_ARGS2((source, endp), + TRIO_CONST char *source, + char **endp) +{ +# if defined(USE_STRTOLD) + return strtold(source, endp); +# else + int isNegative = FALSE; + int isExponentNegative = FALSE; + trio_long_double_t integer = 0.0; + trio_long_double_t fraction = 0.0; + unsigned long exponent = 0; + trio_long_double_t base; + trio_long_double_t fracdiv = 1.0; + trio_long_double_t value = 0.0; + + /* First try hex-floats */ + if ((source[0] == '0') && ((source[1] == 'x') || (source[1] == 'X'))) + { + base = 16.0; + source += 2; + while (isxdigit((int)*source)) + { + integer *= base; + integer += (isdigit((int)*source) + ? (*source - '0') + : 10 + (internal_to_upper((int)*source) - 'A')); + source++; + } + if (*source == '.') + { + source++; + while (isxdigit((int)*source)) + { + fracdiv /= base; + fraction += fracdiv * (isdigit((int)*source) + ? (*source - '0') + : 10 + (internal_to_upper((int)*source) - 'A')); + source++; + } + if ((*source == 'p') || (*source == 'P')) + { + source++; + if ((*source == '+') || (*source == '-')) + { + isExponentNegative = (*source == '-'); + source++; + } + while (isdigit((int)*source)) + { + exponent *= 10; + exponent += (*source - '0'); + source++; + } + } + } + /* For later use with exponent */ + base = 2.0; + } + else /* Then try normal decimal floats */ + { + base = 10.0; + isNegative = (*source == '-'); + /* Skip sign */ + if ((*source == '+') || (*source == '-')) + source++; + + /* Integer part */ + while (isdigit((int)*source)) + { + integer *= base; + integer += (*source - '0'); + source++; + } + + if (*source == '.') + { + source++; /* skip decimal point */ + while (isdigit((int)*source)) + { + fracdiv /= base; + fraction += (*source - '0') * fracdiv; + source++; + } + } + if ((*source == 'e') + || (*source == 'E') +# if TRIO_MICROSOFT + || (*source == 'd') + || (*source == 'D') +# endif + ) + { + source++; /* Skip exponential indicator */ + isExponentNegative = (*source == '-'); + if ((*source == '+') || (*source == '-')) + source++; + while (isdigit((int)*source)) + { + exponent *= (int)base; + exponent += (*source - '0'); + source++; + } + } + } + + value = integer + fraction; + if (exponent != 0) + { + if (isExponentNegative) + value /= trio_powl(base, (trio_long_double_t)exponent); + else + value *= trio_powl(base, (trio_long_double_t)exponent); + } + if (isNegative) + value = -value; + + if (endp) + *endp = (char *)source; + return value; +# endif +} + +#endif + +/** + Convert string to floating-point number. + + @param source String to be converted. + @param endp Pointer to end of the converted string. + @return A floating-point number. + + See @ref trio_to_long_double. +*/ +#if defined(TRIO_FUNC_TO_DOUBLE) + +TRIO_PUBLIC_STRING double +trio_to_double +TRIO_ARGS2((source, endp), + TRIO_CONST char *source, + char **endp) +{ +#if defined(USE_STRTOD) + return strtod(source, endp); +#else + return (double)trio_to_long_double(source, endp); +#endif +} + +#endif + +/** + Convert string to floating-point number. + + @param source String to be converted. + @param endp Pointer to end of the converted string. + @return A floating-point number. + + See @ref trio_to_long_double. +*/ +#if defined(TRIO_FUNC_TO_FLOAT) + +TRIO_PUBLIC_STRING float +trio_to_float +TRIO_ARGS2((source, endp), + TRIO_CONST char *source, + char **endp) +{ +# if defined(USE_STRTOF) + return strtof(source, endp); +# else + return (float)trio_to_long_double(source, endp); +# endif +} + +#endif + +/** + Convert string to signed integer. + + @param string String to be converted. + @param endp Pointer to end of converted string. + @param base Radix number of number. +*/ +#if defined(TRIO_FUNC_TO_LONG) + +TRIO_PUBLIC_STRING long +trio_to_long +TRIO_ARGS3((string, endp, base), + TRIO_CONST char *string, + char **endp, + int base) +{ + assert(string); + assert((base >= 2) && (base <= 36)); + + return strtol(string, endp, base); +} + +#endif + +/** + Convert one alphabetic letter to lower-case. + + @param source The letter to be converted. + @return The converted letter. +*/ +#if defined(TRIO_FUNC_TO_LOWER) + +TRIO_PUBLIC_STRING int +trio_to_lower +TRIO_ARGS1((source), + int source) +{ +# if defined(HAVE_TOLOWER) + + return tolower(source); + +# else + + /* Does not handle locales or non-contiguous alphabetic characters */ + return ((source >= (int)'A') && (source <= (int)'Z')) + ? source - 'A' + 'a' + : source; + +# endif +} + +#endif + +/** + Convert string to unsigned integer. + + @param string String to be converted. + @param endp Pointer to end of converted string. + @param base Radix number of number. +*/ +#if defined(TRIO_FUNC_TO_UNSIGNED_LONG) + +TRIO_PUBLIC_STRING unsigned long +trio_to_unsigned_long +TRIO_ARGS3((string, endp, base), + TRIO_CONST char *string, + char **endp, + int base) +{ + assert(string); + assert((base >= 2) && (base <= 36)); + + return strtoul(string, endp, base); +} + +#endif + +/** + Convert one alphabetic letter to upper-case. + + @param source The letter to be converted. + @return The converted letter. +*/ +#if defined(TRIO_FUNC_TO_UPPER) + +TRIO_PUBLIC_STRING int +trio_to_upper +TRIO_ARGS1((source), + int source) +{ + return internal_to_upper(source); +} + +#endif + +/** + Convert the alphabetic letters in the string to upper-case. + + @param target The string to be converted. + @return The number of processed characters (converted or not). +*/ +#if defined(TRIO_FUNC_UPPER) + +TRIO_PUBLIC_STRING int +trio_upper +TRIO_ARGS1((target), + char *target) +{ + assert(target); + + return trio_span_function(target, target, internal_to_upper); +} + +#endif + +/** @} End of StaticStrings */ + + +/************************************************************************* + * Dynamic String Functions + */ + +#if defined(TRIO_DOCUMENTATION) +# include "doc/doc_dynamic.h" +#endif +/** @addtogroup DynamicStrings + @{ +*/ + +/** + Create a new dynamic string. + + @param initial_size Initial size of the buffer. + @return Newly allocated dynamic string, or NULL if memory allocation failed. +*/ +#if defined(TRIO_FUNC_STRING_CREATE) + +TRIO_PUBLIC_STRING trio_string_t * +trio_string_create +TRIO_ARGS1((initial_size), + int initial_size) +{ + trio_string_t *self; + + self = internal_string_alloc(); + if (self) + { + if (internal_string_grow(self, + (size_t)((initial_size > 0) ? initial_size : 1))) + { + self->content[0] = (char)0; + self->allocated = initial_size; + } + else + { + trio_string_destroy(self); + self = NULL; + } + } + return self; +} + +#endif + +/** + Deallocate the dynamic string and its contents. + + @param self Dynamic string +*/ +#if defined(TRIO_FUNC_STRING_DESTROY) + +TRIO_PUBLIC_STRING void +trio_string_destroy +TRIO_ARGS1((self), + trio_string_t *self) +{ + assert(self); + + if (self) + { + trio_destroy(self->content); + TRIO_FREE(self); + } +} + +#endif + +/** + Get a pointer to the content. + + @param self Dynamic string. + @param offset Offset into content. + @return Pointer to the content. + + @p Offset can be zero, positive, or negative. If @p offset is zero, + then the start of the content will be returned. If @p offset is positive, + then a pointer to @p offset number of characters from the beginning of the + content is returned. If @p offset is negative, then a pointer to @p offset + number of characters from the ending of the string, starting at the + terminating zero, is returned. +*/ +#if defined(TRIO_FUNC_STRING_GET) + +TRIO_PUBLIC_STRING char * +trio_string_get +TRIO_ARGS2((self, offset), + trio_string_t *self, + int offset) +{ + char *result = NULL; + + assert(self); + + if (self->content != NULL) + { + if (self->length == 0) + { + (void)trio_string_length(self); + } + if (offset >= 0) + { + if (offset > (int)self->length) + { + offset = self->length; + } + } + else + { + offset += self->length + 1; + if (offset < 0) + { + offset = 0; + } + } + result = &(self->content[offset]); + } + return result; +} + +#endif + +/** + Extract the content. + + @param self Dynamic String + @return Content of dynamic string. + + The content is removed from the dynamic string. This enables destruction + of the dynamic string without deallocation of the content. +*/ +#if defined(TRIO_FUNC_STRING_EXTRACT) + +TRIO_PUBLIC_STRING char * +trio_string_extract +TRIO_ARGS1((self), + trio_string_t *self) +{ + char *result; + + assert(self); + + result = self->content; + /* FIXME: Allocate new empty buffer? */ + self->content = NULL; + self->length = self->allocated = 0; + return result; +} + +#endif + +/** + Set the content of the dynamic string. + + @param self Dynamic String + @param buffer The new content. + + Sets the content of the dynamic string to a copy @p buffer. + An existing content will be deallocated first, if necessary. + + @remark + This function will make a copy of @p buffer. + You are responsible for deallocating @p buffer yourself. +*/ +#if defined(TRIO_FUNC_XSTRING_SET) + +TRIO_PUBLIC_STRING void +trio_xstring_set +TRIO_ARGS2((self, buffer), + trio_string_t *self, + char *buffer) +{ + assert(self); + + trio_destroy(self->content); + self->content = trio_duplicate(buffer); +} + +#endif + +/* + * trio_string_size + */ +#if defined(TRIO_FUNC_STRING_SIZE) + +TRIO_PUBLIC_STRING int +trio_string_size +TRIO_ARGS1((self), + trio_string_t *self) +{ + assert(self); + + return self->allocated; +} + +#endif + +/* + * trio_string_terminate + */ +#if defined(TRIO_FUNC_STRING_TERMINATE) + +TRIO_PUBLIC_STRING void +trio_string_terminate +TRIO_ARGS1((self), + trio_string_t *self) +{ + trio_xstring_append_char(self, 0); +} + +#endif + +/** + Append the second string to the first. + + @param self Dynamic string to be modified. + @param other Dynamic string to copy from. + @return Boolean value indicating success or failure. +*/ +#if defined(TRIO_FUNC_STRING_APPEND) + +TRIO_PUBLIC_STRING int +trio_string_append +TRIO_ARGS2((self, other), + trio_string_t *self, + trio_string_t *other) +{ + size_t length; + + assert(self); + assert(other); + + length = self->length + other->length; + if (!internal_string_grow_to(self, length)) + goto error; + trio_copy(&self->content[self->length], other->content); + self->length = length; + return TRUE; + + error: + return FALSE; +} + +#endif + + +/* + * trio_xstring_append + */ +#if defined(TRIO_FUNC_XSTRING_APPEND) + +TRIO_PUBLIC_STRING int +trio_xstring_append +TRIO_ARGS2((self, other), + trio_string_t *self, + TRIO_CONST char *other) +{ + size_t length; + + assert(self); + assert(other); + + length = self->length + trio_length(other); + if (!internal_string_grow_to(self, length)) + goto error; + trio_copy(&self->content[self->length], other); + self->length = length; + return TRUE; + + error: + return FALSE; +} + +#endif + +/* + * trio_xstring_append_char + */ +#if defined(TRIO_FUNC_XSTRING_APPEND_CHAR) + +TRIO_PUBLIC_STRING int +trio_xstring_append_char +TRIO_ARGS2((self, character), + trio_string_t *self, + char character) +{ + assert(self); + + if ((int)self->length >= trio_string_size(self)) + { + if (!internal_string_grow(self, 0)) + goto error; + } + self->content[self->length] = character; + self->length++; + return TRUE; + + error: + return FALSE; +} + +#endif + +/* + * trio_xstring_append_max + */ +#if defined(TRIO_FUNC_XSTRING_APPEND_MAX) + +TRIO_PUBLIC_STRING int +trio_xstring_append_max +TRIO_ARGS3((self, other, max), + trio_string_t *self, + TRIO_CONST char *other, + size_t max) +{ + size_t length; + + assert(self); + assert(other); + + length = self->length + trio_length_max(other, max); + if (!internal_string_grow_to(self, length)) + goto error; + + /* + * Pass max + 1 since trio_copy_max copies one character less than + * this from the source to make room for a terminating zero. + */ + trio_copy_max(&self->content[self->length], max + 1, other); + self->length = length; + return TRUE; + + error: + return FALSE; +} + +#endif + +/** + Search for the first occurrence of second parameter in the first. + + @param self Dynamic string to be modified. + @param other Dynamic string to copy from. + @return Boolean value indicating success or failure. +*/ +#if defined(TRIO_FUNC_STRING_CONTAINS) + +TRIO_PUBLIC_STRING int +trio_string_contains +TRIO_ARGS2((self, other), + trio_string_t *self, + trio_string_t *other) +{ + assert(self); + assert(other); + + return trio_contains(self->content, other->content); +} + +#endif + +/* + * trio_xstring_contains + */ +#if defined(TRIO_FUNC_XSTRING_CONTAINS) + +TRIO_PUBLIC_STRING int +trio_xstring_contains +TRIO_ARGS2((self, other), + trio_string_t *self, + TRIO_CONST char *other) +{ + assert(self); + assert(other); + + return trio_contains(self->content, other); +} + +#endif + +/* + * trio_string_copy + */ +#if defined(TRIO_FUNC_STRING_COPY) + +TRIO_PUBLIC_STRING int +trio_string_copy +TRIO_ARGS2((self, other), + trio_string_t *self, + trio_string_t *other) +{ + assert(self); + assert(other); + + self->length = 0; + return trio_string_append(self, other); +} + +#endif + + +/* + * trio_xstring_copy + */ +#if defined(TRIO_FUNC_XSTRING_COPY) + +TRIO_PUBLIC_STRING int +trio_xstring_copy +TRIO_ARGS2((self, other), + trio_string_t *self, + TRIO_CONST char *other) +{ + assert(self); + assert(other); + + self->length = 0; + return trio_xstring_append(self, other); +} + +#endif + +/* + * trio_string_duplicate + */ +#if defined(TRIO_FUNC_STRING_DUPLICATE) + +TRIO_PUBLIC_STRING trio_string_t * +trio_string_duplicate +TRIO_ARGS1((other), + trio_string_t *other) +{ + trio_string_t *self; + + assert(other); + + self = internal_string_alloc(); + if (self) + { + self->content = internal_duplicate_max(other->content, other->length); + if (self->content) + { + self->length = other->length; + self->allocated = self->length + 1; + } + else + { + self->length = self->allocated = 0; + } + } + return self; +} + +#endif + +/* + * trio_xstring_duplicate + */ +#if defined(TRIO_FUNC_XSTRING_DUPLICATE) + +TRIO_PUBLIC_STRING trio_string_t * +trio_xstring_duplicate +TRIO_ARGS1((other), + TRIO_CONST char *other) +{ + trio_string_t *self; + + assert(other); + + self = internal_string_alloc(); + if (self) + { + self->content = internal_duplicate_max(other, trio_length(other)); + if (self->content) + { + self->length = trio_length(self->content); + self->allocated = self->length + 1; + } + else + { + self->length = self->allocated = 0; + } + } + return self; +} + +#endif + +/* + * trio_string_equal + */ +#if defined(TRIO_FUNC_STRING_EQUAL) + +TRIO_PUBLIC_STRING int +trio_string_equal +TRIO_ARGS2((self, other), + trio_string_t *self, + trio_string_t *other) +{ + assert(self); + assert(other); + + return trio_equal(self->content, other->content); +} + +#endif + + +/* + * trio_xstring_equal + */ +#if defined(TRIO_FUNC_XSTRING_EQUAL) + +TRIO_PUBLIC_STRING int +trio_xstring_equal +TRIO_ARGS2((self, other), + trio_string_t *self, + TRIO_CONST char *other) +{ + assert(self); + assert(other); + + return trio_equal(self->content, other); +} + +#endif + +/* + * trio_string_equal_max + */ +#if defined(TRIO_FUNC_STRING_EQUAL_MAX) + +TRIO_PUBLIC_STRING int +trio_string_equal_max +TRIO_ARGS3((self, max, other), + trio_string_t *self, + size_t max, + trio_string_t *other) +{ + assert(self); + assert(other); + + return trio_equal_max(self->content, max, other->content); +} +#endif + +/* + * trio_xstring_equal_max + */ +#if defined(TRIO_FUNC_XSTRING_EQUAL_MAX) + +TRIO_PUBLIC_STRING int +trio_xstring_equal_max +TRIO_ARGS3((self, max, other), + trio_string_t *self, + size_t max, + TRIO_CONST char *other) +{ + assert(self); + assert(other); + + return trio_equal_max(self->content, max, other); +} + +#endif + +/* + * trio_string_equal_case + */ +#if defined(TRIO_FUNC_STRING_EQUAL_CASE) + +TRIO_PUBLIC_STRING int +trio_string_equal_case +TRIO_ARGS2((self, other), + trio_string_t *self, + trio_string_t *other) +{ + assert(self); + assert(other); + + return trio_equal_case(self->content, other->content); +} + +#endif + +/* + * trio_xstring_equal_case + */ +#if defined(TRIO_FUNC_XSTRING_EQUAL_CASE) + +TRIO_PUBLIC_STRING int +trio_xstring_equal_case +TRIO_ARGS2((self, other), + trio_string_t *self, + TRIO_CONST char *other) +{ + assert(self); + assert(other); + + return trio_equal_case(self->content, other); +} + +#endif + +/* + * trio_string_equal_case_max + */ +#if defined(TRIO_FUNC_STRING_EQUAL_CASE_MAX) + +TRIO_PUBLIC_STRING int +trio_string_equal_case_max +TRIO_ARGS3((self, max, other), + trio_string_t *self, + size_t max, + trio_string_t *other) +{ + assert(self); + assert(other); + + return trio_equal_case_max(self->content, max, other->content); +} + +#endif + +/* + * trio_xstring_equal_case_max + */ +#if defined(TRIO_FUNC_XSTRING_EQUAL_CASE_MAX) + +TRIO_PUBLIC_STRING int +trio_xstring_equal_case_max +TRIO_ARGS3((self, max, other), + trio_string_t *self, + size_t max, + TRIO_CONST char *other) +{ + assert(self); + assert(other); + + return trio_equal_case_max(self->content, max, other); +} + +#endif + +/* + * trio_string_format_data_max + */ +#if defined(TRIO_FUNC_STRING_FORMAT_DATE_MAX) + +TRIO_PUBLIC_STRING size_t +trio_string_format_date_max +TRIO_ARGS4((self, max, format, datetime), + trio_string_t *self, + size_t max, + TRIO_CONST char *format, + TRIO_CONST struct tm *datetime) +{ + assert(self); + + return trio_format_date_max(self->content, max, format, datetime); +} + +#endif + +/* + * trio_string_index + */ +#if defined(TRIO_FUNC_STRING_INDEX) + +TRIO_PUBLIC_STRING char * +trio_string_index +TRIO_ARGS2((self, character), + trio_string_t *self, + int character) +{ + assert(self); + + return trio_index(self->content, character); +} + +#endif + +/* + * trio_string_index_last + */ +#if defined(TRIO_FUNC_STRING_INDEX_LAST) + +TRIO_PUBLIC_STRING char * +trio_string_index_last +TRIO_ARGS2((self, character), + trio_string_t *self, + int character) +{ + assert(self); + + return trio_index_last(self->content, character); +} + +#endif + +/* + * trio_string_length + */ +#if defined(TRIO_FUNC_STRING_LENGTH) + +TRIO_PUBLIC_STRING int +trio_string_length +TRIO_ARGS1((self), + trio_string_t *self) +{ + assert(self); + + if (self->length == 0) + { + self->length = trio_length(self->content); + } + return self->length; +} + +#endif + +/* + * trio_string_lower + */ +#if defined(TRIO_FUNC_STRING_LOWER) + +TRIO_PUBLIC_STRING int +trio_string_lower +TRIO_ARGS1((self), + trio_string_t *self) +{ + assert(self); + + return trio_lower(self->content); +} + +#endif + +/* + * trio_string_match + */ +#if defined(TRIO_FUNC_STRING_MATCH) + +TRIO_PUBLIC_STRING int +trio_string_match +TRIO_ARGS2((self, other), + trio_string_t *self, + trio_string_t *other) +{ + assert(self); + assert(other); + + return trio_match(self->content, other->content); +} + +#endif + +/* + * trio_xstring_match + */ +#if defined(TRIO_FUNC_XSTRING_MATCH) + +TRIO_PUBLIC_STRING int +trio_xstring_match +TRIO_ARGS2((self, other), + trio_string_t *self, + TRIO_CONST char *other) +{ + assert(self); + assert(other); + + return trio_match(self->content, other); +} + +#endif + +/* + * trio_string_match_case + */ +#if defined(TRIO_FUNC_STRING_MATCH_CASE) + +TRIO_PUBLIC_STRING int +trio_string_match_case +TRIO_ARGS2((self, other), + trio_string_t *self, + trio_string_t *other) +{ + assert(self); + assert(other); + + return trio_match_case(self->content, other->content); +} + +#endif + +/* + * trio_xstring_match_case + */ +#if defined(TRIO_FUNC_XSTRING_MATCH_CASE) + +TRIO_PUBLIC_STRING int +trio_xstring_match_case +TRIO_ARGS2((self, other), + trio_string_t *self, + TRIO_CONST char *other) +{ + assert(self); + assert(other); + + return trio_match_case(self->content, other); +} + +#endif + +/* + * trio_string_substring + */ +#if defined(TRIO_FUNC_STRING_SUBSTRING) + +TRIO_PUBLIC_STRING char * +trio_string_substring +TRIO_ARGS2((self, other), + trio_string_t *self, + trio_string_t *other) +{ + assert(self); + assert(other); + + return trio_substring(self->content, other->content); +} + +#endif + +/* + * trio_xstring_substring + */ +#if defined(TRIO_FUNC_XSTRING_SUBSTRING) + +TRIO_PUBLIC_STRING char * +trio_xstring_substring +TRIO_ARGS2((self, other), + trio_string_t *self, + TRIO_CONST char *other) +{ + assert(self); + assert(other); + + return trio_substring(self->content, other); +} + +#endif + +/* + * trio_string_upper + */ +#if defined(TRIO_FUNC_STRING_UPPER) + +TRIO_PUBLIC_STRING int +trio_string_upper +TRIO_ARGS1((self), + trio_string_t *self) +{ + assert(self); + + return trio_upper(self->content); +} + +#endif + +/** @} End of DynamicStrings */ diff --git a/winpr/libwinpr/utils/trio/triostr.h b/winpr/libwinpr/utils/trio/triostr.h new file mode 100644 index 000000000..847fb7232 --- /dev/null +++ b/winpr/libwinpr/utils/trio/triostr.h @@ -0,0 +1,681 @@ +/************************************************************************* + * + * $Id: triostr.h,v 1.18 2010/01/26 13:02:02 breese Exp $ + * + * Copyright (C) 2001 Bjorn Reese and Daniel Stenberg. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF + * MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE AUTHORS AND + * CONTRIBUTORS ACCEPT NO RESPONSIBILITY IN ANY CONCEIVABLE MANNER. + * + ************************************************************************/ + +#ifndef TRIO_TRIOSTR_H +#define TRIO_TRIOSTR_H + +/* + * Documentation is located in triostr.c + */ + +#include <assert.h> +#include <stdlib.h> +#include <string.h> +#include <time.h> +#include "triodef.h" +#include "triop.h" + +#ifdef __cplusplus +extern "C" { +#endif + +enum { + TRIO_HASH_NONE = 0, + TRIO_HASH_PLAIN, + TRIO_HASH_TWOSIGNED +}; + +#if !defined(TRIO_PUBLIC_STRING) +# if !defined(TRIO_PUBLIC) +# define TRIO_PUBLIC +# endif +# define TRIO_PUBLIC_STRING TRIO_PUBLIC +#endif + +/************************************************************************* + * Dependencies + */ + +#if defined(TRIO_EMBED_STRING) + +/* + * The application that triostr is embedded in must define which functions + * it uses. + * + * The following resolves internal dependencies. + */ + +# if defined(TRIO_FUNC_XSTRING_SET) +# if !defined(TRIO_FUNC_DUPLICATE) +# define TRIO_FUNC_DUPLICATE +# endif +# endif + +# if defined(TRIO_FUNC_DUPLICATE) \ + || defined(TRIO_FUNC_DUPLICATE_MAX) \ + || defined(TRIO_FUNC_STRING_DUPLICATE) \ + || defined(TRIO_FUNC_XSTRING_DUPLICATE) +# if !defined(TRIO_FUNC_CREATE) +# define TRIO_FUNC_CREATE +# endif +# if !defined(TRIO_FUNC_COPY_MAX) +# define TRIO_FUNC_COPY_MAX +# endif +# endif + +# if defined(TRIO_FUNC_STRING_CREATE) +# if !defined(TRIO_FUNC_STRING_DESTROY) +# define TRIO_FUNC_STRING_DESTROY +# endif +# endif + +# if defined(TRIO_FUNC_STRING_DESTROY) \ + || defined(TRIO_FUNC_XSTRING_SET) +# if !defined(TRIO_FUNC_DESTROY) +# define TRIO_FUNC_DESTROY +# endif +# endif + +# if defined(TRIO_FUNC_EQUAL_LOCALE) \ + || defined(TRIO_FUNC_STRING_EQUAL) \ + || defined(TRIO_FUNC_XSTRING_EQUAL) +# if !defined(TRIO_FUNC_EQUAL) +# define TRIO_FUNC_EQUAL +# endif +# endif + +# if defined(TRIO_FUNC_EQUAL_CASE) \ + || defined(TRIO_FUNC_STRING_EQUAL_CASE) \ + || defined(TRIO_FUNC_XSTRING_EQUAL_CASE) +# if !defined(TRIO_FUNC_EQUAL_CASE) +# define TRIO_FUNC_EQUAL_CASE +# endif +# endif + +# if defined(TRIO_FUNC_SUBSTRING_MAX) \ + || defined(TRIO_FUNC_STRING_EQUAL_MAX) \ + || defined(TRIO_FUNC_XSTRING_EQUAL_MAX) +# if !defined(TRIO_FUNC_EQUAL_MAX) +# define TRIO_FUNC_EQUAL_MAX +# endif +# endif + +# if defined(TRIO_FUNC_TO_DOUBLE) \ + || defined(TRIO_FUNC_TO_FLOAT) +# if !defined(TRIO_FUNC_TO_LONG_DOUBLE) +# define TRIO_FUNC_TO_LONG_DOUBLE +# endif +# endif + +# if defined(TRIO_FUNC_STRING_TERMINATE) +# if !defined(TRIO_FUNC_XSTRING_APPEND_CHAR) +# define TRIO_FUNC_XSTRING_APPEND_CHAR +# endif +# endif + +# if defined(TRIO_FUNC_XSTRING_APPEND_CHAR) +# if !defined(TRIO_FUNC_STRING_SIZE) +# define TRIO_FUNC_STRING_SIZE +# endif +# endif + +#else + +/* + * When triostr is not embedded all functions are defined. + */ + +# define TRIO_FUNC_APPEND +# define TRIO_FUNC_APPEND_MAX +# define TRIO_FUNC_CONTAINS +# define TRIO_FUNC_COPY +# define TRIO_FUNC_COPY_MAX +# define TRIO_FUNC_CREATE +# define TRIO_FUNC_DESTROY +# define TRIO_FUNC_DUPLICATE +# define TRIO_FUNC_DUPLICATE_MAX +# define TRIO_FUNC_EQUAL +# define TRIO_FUNC_EQUAL_CASE +# define TRIO_FUNC_EQUAL_CASE_MAX +# define TRIO_FUNC_EQUAL_LOCALE +# define TRIO_FUNC_EQUAL_MAX +# define TRIO_FUNC_ERROR +# if !defined(TRIO_PLATFORM_WINCE) +# define TRIO_FUNC_FORMAT_DATE_MAX +# endif +# define TRIO_FUNC_HASH +# define TRIO_FUNC_INDEX +# define TRIO_FUNC_INDEX_LAST +# define TRIO_FUNC_LENGTH +# define TRIO_FUNC_LENGTH_MAX +# define TRIO_FUNC_LOWER +# define TRIO_FUNC_MATCH +# define TRIO_FUNC_MATCH_CASE +# define TRIO_FUNC_SPAN_FUNCTION +# define TRIO_FUNC_SUBSTRING +# define TRIO_FUNC_SUBSTRING_MAX +# define TRIO_FUNC_TO_DOUBLE +# define TRIO_FUNC_TO_FLOAT +# define TRIO_FUNC_TO_LONG +# define TRIO_FUNC_TO_LONG_DOUBLE +# define TRIO_FUNC_TO_LOWER +# define TRIO_FUNC_TO_UNSIGNED_LONG +# define TRIO_FUNC_TO_UPPER +# define TRIO_FUNC_TOKENIZE +# define TRIO_FUNC_UPPER + +# define TRIO_FUNC_STRING_APPEND +# define TRIO_FUNC_STRING_CONTAINS +# define TRIO_FUNC_STRING_COPY +# define TRIO_FUNC_STRING_CREATE +# define TRIO_FUNC_STRING_DESTROY +# define TRIO_FUNC_STRING_DUPLICATE +# define TRIO_FUNC_STRING_EQUAL +# define TRIO_FUNC_STRING_EQUAL_CASE +# define TRIO_FUNC_STRING_EQUAL_CASE_MAX +# define TRIO_FUNC_STRING_EQUAL_MAX +# define TRIO_FUNC_STRING_EXTRACT +# if !defined(TRIO_PLATFORM_WINCE) +# define TRIO_FUNC_STRING_FORMAT_DATE_MAX +# endif +# define TRIO_FUNC_STRING_GET +# define TRIO_FUNC_STRING_INDEX +# define TRIO_FUNC_STRING_INDEX_LAST +# define TRIO_FUNC_STRING_LENGTH +# define TRIO_FUNC_STRING_LOWER +# define TRIO_FUNC_STRING_MATCH +# define TRIO_FUNC_STRING_MATCH_CASE +# define TRIO_FUNC_STRING_SIZE +# define TRIO_FUNC_STRING_SUBSTRING +# define TRIO_FUNC_STRING_TERMINATE +# define TRIO_FUNC_STRING_UPPER + +# define TRIO_FUNC_XSTRING_APPEND +# define TRIO_FUNC_XSTRING_APPEND_CHAR +# define TRIO_FUNC_XSTRING_APPEND_MAX +# define TRIO_FUNC_XSTRING_CONTAINS +# define TRIO_FUNC_XSTRING_COPY +# define TRIO_FUNC_XSTRING_DUPLICATE +# define TRIO_FUNC_XSTRING_EQUAL +# define TRIO_FUNC_XSTRING_EQUAL_CASE +# define TRIO_FUNC_XSTRING_EQUAL_CASE_MAX +# define TRIO_FUNC_XSTRING_EQUAL_MAX +# define TRIO_FUNC_XSTRING_MATCH +# define TRIO_FUNC_XSTRING_MATCH_CASE +# define TRIO_FUNC_XSTRING_SET +# define TRIO_FUNC_XSTRING_SUBSTRING + +#endif + + +/************************************************************************* + * String functions + */ + +#if defined(TRIO_FUNC_APPEND) +TRIO_PUBLIC_STRING int +trio_append +TRIO_PROTO((char *target, TRIO_CONST char *source)); +#endif + +#if defined(TRIO_FUNC_APPEND_MAX) +TRIO_PUBLIC_STRING int +trio_append_max +TRIO_PROTO((char *target, size_t max, TRIO_CONST char *source)); +#endif + +#if defined(TRIO_FUNC_CONTAINS) +TRIO_PUBLIC_STRING int +trio_contains +TRIO_PROTO((TRIO_CONST char *string, TRIO_CONST char *substring)); +#endif + +#if defined(TRIO_FUNC_COPY) +TRIO_PUBLIC_STRING int +trio_copy +TRIO_PROTO((char *target, TRIO_CONST char *source)); +#endif + +#if defined(TRIO_FUNC_COPY_MAX) +TRIO_PUBLIC_STRING int +trio_copy_max +TRIO_PROTO((char *target, size_t max, TRIO_CONST char *source)); +#endif + +#if defined(TRIO_FUNC_CREATE) +TRIO_PUBLIC_STRING char * +trio_create +TRIO_PROTO((size_t size)); +#endif + +#if defined(TRIO_FUNC_DESTROY) +TRIO_PUBLIC_STRING void +trio_destroy +TRIO_PROTO((char *string)); +#endif + +#if defined(TRIO_FUNC_DUPLICATE) +TRIO_PUBLIC_STRING char * +trio_duplicate +TRIO_PROTO((TRIO_CONST char *source)); +#endif + +#if defined(TRIO_FUNC_DUPLICATE_MAX) +TRIO_PUBLIC_STRING char * +trio_duplicate_max +TRIO_PROTO((TRIO_CONST char *source, size_t max)); +#endif + +#if defined(TRIO_FUNC_EQUAL) +TRIO_PUBLIC_STRING int +trio_equal +TRIO_PROTO((TRIO_CONST char *first, TRIO_CONST char *second)); +#endif + +#if defined(TRIO_FUNC_EQUAL_CASE) +TRIO_PUBLIC_STRING int +trio_equal_case +TRIO_PROTO((TRIO_CONST char *first, TRIO_CONST char *second)); +#endif + +#if defined(TRIO_FUNC_EQUAL_CASE_MAX) +TRIO_PUBLIC_STRING int +trio_equal_case_max +TRIO_PROTO((TRIO_CONST char *first, size_t max, TRIO_CONST char *second)); +#endif + +#if defined(TRIO_FUNC_EQUAL_LOCALE) +TRIO_PUBLIC_STRING int +trio_equal_locale +TRIO_PROTO((TRIO_CONST char *first, TRIO_CONST char *second)); +#endif + +#if defined(TRIO_FUNC_EQUAL_MAX) +TRIO_PUBLIC_STRING int +trio_equal_max +TRIO_PROTO((TRIO_CONST char *first, size_t max, TRIO_CONST char *second)); +#endif + +#if defined(TRIO_FUNC_ERROR) +TRIO_PUBLIC_STRING TRIO_CONST char * +trio_error +TRIO_PROTO((int)); +#endif + +#if defined(TRIO_FUNC_FORMAT_DATE_MAX) +TRIO_PUBLIC_STRING size_t +trio_format_date_max +TRIO_PROTO((char *target, size_t max, TRIO_CONST char *format, TRIO_CONST struct tm *datetime)); +#endif + +#if defined(TRIO_FUNC_HASH) +TRIO_PUBLIC_STRING unsigned long +trio_hash +TRIO_PROTO((TRIO_CONST char *string, int type)); +#endif + +#if defined(TRIO_FUNC_INDEX) +TRIO_PUBLIC_STRING char * +trio_index +TRIO_PROTO((TRIO_CONST char *string, int character)); +#endif + +#if defined(TRIO_FUNC_INDEX_LAST) +TRIO_PUBLIC_STRING char * +trio_index_last +TRIO_PROTO((TRIO_CONST char *string, int character)); +#endif + +#if defined(TRIO_FUNC_LENGTH) +TRIO_PUBLIC_STRING size_t +trio_length +TRIO_PROTO((TRIO_CONST char *string)); +#endif + +#if defined(TRIO_FUNC_LENGTH_MAX) +TRIO_PUBLIC_STRING size_t +trio_length_max +TRIO_PROTO((TRIO_CONST char *string, size_t max)); +#endif + +#if defined(TRIO_FUNC_LOWER) +TRIO_PUBLIC_STRING int +trio_lower +TRIO_PROTO((char *target)); +#endif + +#if defined(TRIO_FUNC_MATCH) +TRIO_PUBLIC_STRING int +trio_match +TRIO_PROTO((TRIO_CONST char *string, TRIO_CONST char *pattern)); +#endif + +#if defined(TRIO_FUNC_MATCH_CASE) +TRIO_PUBLIC_STRING int +trio_match_case +TRIO_PROTO((TRIO_CONST char *string, TRIO_CONST char *pattern)); +#endif + +#if defined(TRIO_FUNC_SPAN_FUNCTION) +TRIO_PUBLIC_STRING size_t +trio_span_function +TRIO_PROTO((char *target, TRIO_CONST char *source, int (*Function) TRIO_PROTO((int)))); +#endif + +#if defined(TRIO_FUNC_SUBSTRING) +TRIO_PUBLIC_STRING char * +trio_substring +TRIO_PROTO((TRIO_CONST char *string, TRIO_CONST char *substring)); +#endif + +#if defined(TRIO_FUNC_SUBSTRING_MAX) +TRIO_PUBLIC_STRING char * +trio_substring_max +TRIO_PROTO((TRIO_CONST char *string, size_t max, TRIO_CONST char *substring)); +#endif + +#if defined(TRIO_FUNC_TO_DOUBLE) +TRIO_PUBLIC_STRING double +trio_to_double +TRIO_PROTO((TRIO_CONST char *source, char **endp)); +#endif + +#if defined(TRIO_FUNC_TO_FLOAT) +TRIO_PUBLIC_STRING float +trio_to_float +TRIO_PROTO((TRIO_CONST char *source, char **endp)); +#endif + +#if defined(TRIO_FUNC_TO_LONG) +TRIO_PUBLIC_STRING long +trio_to_long +TRIO_PROTO((TRIO_CONST char *source, char **endp, int base)); +#endif + +#if defined(TRIO_FUNC_TO_LOWER) +TRIO_PUBLIC_STRING int +trio_to_lower +TRIO_PROTO((int source)); +#endif + +#if defined(TRIO_FUNC_TO_LONG_DOUBLE) +TRIO_PUBLIC_STRING trio_long_double_t +trio_to_long_double +TRIO_PROTO((TRIO_CONST char *source, char **endp)); +#endif + +#if defined(TRIO_FUNC_TO_UNSIGNED_LONG) +TRIO_PUBLIC_STRING unsigned long +trio_to_unsigned_long +TRIO_PROTO((TRIO_CONST char *source, char **endp, int base)); +#endif + +#if defined(TRIO_FUNC_TO_UPPER) +TRIO_PUBLIC_STRING int +trio_to_upper +TRIO_PROTO((int source)); +#endif + +#if defined(TRIO_FUNC_TOKENIZE) +TRIO_PUBLIC_STRING char * +trio_tokenize +TRIO_PROTO((char *string, TRIO_CONST char *delimiters)); +#endif + +#if defined(TRIO_FUNC_UPPER) +TRIO_PUBLIC_STRING int +trio_upper +TRIO_PROTO((char *target)); +#endif + +/************************************************************************* + * Dynamic string functions + */ + +/* + * Opaque type for dynamic strings + */ + +typedef struct _trio_string_t trio_string_t; + +#if defined(TRIO_FUNC_STRING_APPEND) +TRIO_PUBLIC_STRING int +trio_string_append +TRIO_PROTO((trio_string_t *self, trio_string_t *other)); +#endif + +#if defined(TRIO_FUNC_STRING_CONTAINS) +TRIO_PUBLIC_STRING int +trio_string_contains +TRIO_PROTO((trio_string_t *self, trio_string_t *other)); +#endif + +#if defined(TRIO_FUNC_STRING_COPY) +TRIO_PUBLIC_STRING int +trio_string_copy +TRIO_PROTO((trio_string_t *self, trio_string_t *other)); +#endif + +#if defined(TRIO_FUNC_STRING_CREATE) +TRIO_PUBLIC_STRING trio_string_t * +trio_string_create +TRIO_PROTO((int initial_size)); +#endif + +#if defined(TRIO_FUNC_STRING_DESTROY) +TRIO_PUBLIC_STRING void +trio_string_destroy +TRIO_PROTO((trio_string_t *self)); +#endif + +#if defined(TRIO_FUNC_STRING_DUPLICATE) +TRIO_PUBLIC_STRING trio_string_t * +trio_string_duplicate +TRIO_PROTO((trio_string_t *other)); +#endif + +#if defined(TRIO_FUNC_STRING_EQUAL) +TRIO_PUBLIC_STRING int +trio_string_equal +TRIO_PROTO((trio_string_t *self, trio_string_t *other)); +#endif + +#if defined(TRIO_FUNC_STRING_EQUAL_MAX) +TRIO_PUBLIC_STRING int +trio_string_equal_max +TRIO_PROTO((trio_string_t *self, size_t max, trio_string_t *second)); +#endif + +#if defined(TRIO_FUNC_STRING_EQUAL_CASE) +TRIO_PUBLIC_STRING int +trio_string_equal_case +TRIO_PROTO((trio_string_t *self, trio_string_t *other)); +#endif + +#if defined(TRIO_FUNC_STRING_EQUAL_CASE_MAX) +TRIO_PUBLIC_STRING int +trio_string_equal_case_max +TRIO_PROTO((trio_string_t *self, size_t max, trio_string_t *other)); +#endif + +#if defined(TRIO_FUNC_STRING_EXTRACT) +TRIO_PUBLIC_STRING char * +trio_string_extract +TRIO_PROTO((trio_string_t *self)); +#endif + +#if defined(TRIO_FUNC_STRING_FORMAT_DATE_MAX) +TRIO_PUBLIC_STRING size_t +trio_string_format_date_max +TRIO_PROTO((trio_string_t *self, size_t max, TRIO_CONST char *format, TRIO_CONST struct tm *datetime)); +#endif + +#if defined(TRIO_FUNC_STRING_GET) +TRIO_PUBLIC_STRING char * +trio_string_get +TRIO_PROTO((trio_string_t *self, int offset)); +#endif + +#if defined(TRIO_FUNC_STRING_INDEX) +TRIO_PUBLIC_STRING char * +trio_string_index +TRIO_PROTO((trio_string_t *self, int character)); +#endif + +#if defined(TRIO_FUNC_STRING_INDEX_LAST) +TRIO_PUBLIC_STRING char * +trio_string_index_last +TRIO_PROTO((trio_string_t *self, int character)); +#endif + +#if defined(TRIO_FUNC_STRING_LENGTH) +TRIO_PUBLIC_STRING int +trio_string_length +TRIO_PROTO((trio_string_t *self)); +#endif + +#if defined(TRIO_FUNC_STRING_LOWER) +TRIO_PUBLIC_STRING int +trio_string_lower +TRIO_PROTO((trio_string_t *self)); +#endif + +#if defined(TRIO_FUNC_STRING_MATCH) +TRIO_PUBLIC_STRING int +trio_string_match +TRIO_PROTO((trio_string_t *self, trio_string_t *other)); +#endif + +#if defined(TRIO_FUNC_STRING_MATCH_CASE) +TRIO_PUBLIC_STRING int +trio_string_match_case +TRIO_PROTO((trio_string_t *self, trio_string_t *other)); +#endif + +#if defined(TRIO_FUNC_STRING_SIZE) +TRIO_PUBLIC_STRING int +trio_string_size +TRIO_PROTO((trio_string_t *self)); +#endif + +#if defined(TRIO_FUNC_STRING_SUBSTRING) +TRIO_PUBLIC_STRING char * +trio_string_substring +TRIO_PROTO((trio_string_t *self, trio_string_t *other)); +#endif + +#if defined(TRIO_FUNC_STRING_TERMINATE) +TRIO_PUBLIC_STRING void +trio_string_terminate +TRIO_PROTO((trio_string_t *self)); +#endif + +#if defined(TRIO_FUNC_STRING_UPPER) +TRIO_PUBLIC_STRING int +trio_string_upper +TRIO_PROTO((trio_string_t *self)); +#endif + +#if defined(TRIO_FUNC_XSTRING_APPEND) +TRIO_PUBLIC_STRING int +trio_xstring_append +TRIO_PROTO((trio_string_t *self, TRIO_CONST char *other)); +#endif + +#if defined(TRIO_FUNC_XSTRING_APPEND_CHAR) +TRIO_PUBLIC_STRING int +trio_xstring_append_char +TRIO_PROTO((trio_string_t *self, char character)); +#endif + +#if defined(TRIO_FUNC_XSTRING_APPEND_MAX) +TRIO_PUBLIC_STRING int +trio_xstring_append_max +TRIO_PROTO((trio_string_t *self, TRIO_CONST char *other, size_t max)); +#endif + +#if defined(TRIO_FUNC_XSTRING_CONTAINS) +TRIO_PUBLIC_STRING int +trio_xstring_contains +TRIO_PROTO((trio_string_t *self, TRIO_CONST char *other)); +#endif + +#if defined(TRIO_FUNC_XSTRING_COPY) +TRIO_PUBLIC_STRING int +trio_xstring_copy +TRIO_PROTO((trio_string_t *self, TRIO_CONST char *other)); +#endif + +#if defined(TRIO_FUNC_XSTRING_DUPLICATE) +TRIO_PUBLIC_STRING trio_string_t * +trio_xstring_duplicate +TRIO_PROTO((TRIO_CONST char *other)); +#endif + +#if defined(TRIO_FUNC_XSTRING_EQUAL) +TRIO_PUBLIC_STRING int +trio_xstring_equal +TRIO_PROTO((trio_string_t *self, TRIO_CONST char *other)); +#endif + +#if defined(TRIO_FUNC_XSTRING_EQUAL_MAX) +TRIO_PUBLIC_STRING int +trio_xstring_equal_max +TRIO_PROTO((trio_string_t *self, size_t max, TRIO_CONST char *other)); +#endif + +#if defined(TRIO_FUNC_XSTRING_EQUAL_CASE) +TRIO_PUBLIC_STRING int +trio_xstring_equal_case +TRIO_PROTO((trio_string_t *self, TRIO_CONST char *other)); +#endif + +#if defined(TRIO_FUNC_XSTRING_EQUAL_CASE_MAX) +TRIO_PUBLIC_STRING int +trio_xstring_equal_case_max +TRIO_PROTO((trio_string_t *self, size_t max, TRIO_CONST char *other)); +#endif + +#if defined(TRIO_FUNC_XSTRING_MATCH) +TRIO_PUBLIC_STRING int +trio_xstring_match +TRIO_PROTO((trio_string_t *self, TRIO_CONST char *other)); +#endif + +#if defined(TRIO_FUNC_XSTRING_MATCH_CASE) +TRIO_PUBLIC_STRING int +trio_xstring_match_case +TRIO_PROTO((trio_string_t *self, TRIO_CONST char *other)); +#endif + +#if defined(TRIO_FUNC_XSTRING_SET) +TRIO_PUBLIC_STRING void +trio_xstring_set +TRIO_PROTO((trio_string_t *self, char *buffer)); +#endif + +#if defined(TRIO_FUNC_XSTRING_SUBSTRING) +TRIO_PUBLIC_STRING char * +trio_xstring_substring +TRIO_PROTO((trio_string_t *self, TRIO_CONST char *other)); +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* TRIO_TRIOSTR_H */ diff --git a/winpr/tools/makecert/CMakeLists.txt b/winpr/tools/makecert/CMakeLists.txt index 33de8ce90..17b164aae 100644 --- a/winpr/tools/makecert/CMakeLists.txt +++ b/winpr/tools/makecert/CMakeLists.txt @@ -15,16 +15,17 @@ # See the License for the specific language governing permissions and # limitations under the License. -set(MODULE_NAME "winpr-makecert") -set(MODULE_PREFIX "WINPR_TOOLS_MAKECERT") +set(MODULE_NAME "winpr-makecert-tool") +set(MODULE_PREFIX "WINPR_MAKECERT_TOOL") set(${MODULE_PREFIX}_SRCS - makecert.c) + makecert.c + makecert.h) include_directories(${ZLIB_INCLUDE_DIRS}) include_directories(${OPENSSL_INCLUDE_DIR}) -add_executable(${MODULE_NAME} ${${MODULE_PREFIX}_SRCS}) +add_library(${MODULE_NAME} ${${MODULE_PREFIX}_SRCS}) set(${MODULE_PREFIX}_LIBS ${ZLIB_LIBRARIES} @@ -33,9 +34,12 @@ set(${MODULE_PREFIX}_LIBS set_complex_link_libraries(VARIABLE ${MODULE_PREFIX}_LIBS MONOLITHIC ${MONOLITHIC_BUILD} MODULE winpr - MODULES winpr-crt winpr-utils winpr-sysinfo) + MODULES winpr-crt winpr-utils winpr-sysinfo winpr-file winpr-path) target_link_libraries(${MODULE_NAME} ${${MODULE_PREFIX}_LIBS}) +install(TARGETS ${MODULE_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT libraries) +add_subdirectory(cli) + set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "WinPR/Tools") diff --git a/winpr/tools/makecert/cli/CMakeLists.txt b/winpr/tools/makecert/cli/CMakeLists.txt new file mode 100644 index 000000000..c2856a396 --- /dev/null +++ b/winpr/tools/makecert/cli/CMakeLists.txt @@ -0,0 +1,33 @@ +# WinPR: Windows Portable Runtime +# winpr-makecert cmake build script +# +# Copyright 2012 Marc-Andre Moreau <marcandre.moreau@gmail.com> +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set(MODULE_NAME "winpr-makecert") +set(MODULE_PREFIX "WINPR_MAKECERT") + +include_directories(..) + +set(${MODULE_PREFIX}_SRCS + main.c) + +add_executable(${MODULE_NAME} ${${MODULE_PREFIX}_SRCS}) + +set(${MODULE_PREFIX}_LIBS winpr-makecert-tool) + +target_link_libraries(${MODULE_NAME} ${${MODULE_PREFIX}_LIBS}) + +set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "WinPR/Tools") + diff --git a/winpr/tools/makecert/cli/main.c b/winpr/tools/makecert/cli/main.c new file mode 100644 index 000000000..90ec0c60f --- /dev/null +++ b/winpr/tools/makecert/cli/main.c @@ -0,0 +1,41 @@ +/** + * WinPR: Windows Portable Runtime + * makecert replacement + * + * Copyright 2012 Marc-Andre Moreau <marcandre.moreau@gmail.com> + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <stdio.h> +#include <string.h> +#include <stdlib.h> + +#include <winpr/crt.h> +#include <winpr/cmdline.h> +#include <winpr/sysinfo.h> + +#include "makecert.h" + +int main(int argc, char* argv[]) +{ + MAKECERT_CONTEXT* context; + + context = makecert_context_new(); + + makecert_context_process(context, argc, argv); + + makecert_context_free(context); + + return 0; +} diff --git a/winpr/tools/makecert/makecert.c b/winpr/tools/makecert/makecert.c index ec750d0dc..0a5538fa9 100644 --- a/winpr/tools/makecert/makecert.c +++ b/winpr/tools/makecert/makecert.c @@ -22,6 +22,8 @@ #include <stdlib.h> #include <winpr/crt.h> +#include <winpr/file.h> +#include <winpr/path.h> #include <winpr/cmdline.h> #include <winpr/sysinfo.h> @@ -33,17 +35,41 @@ #include <openssl/applink.c> #endif -X509* x509 = NULL; -EVP_PKEY* pkey = NULL; -char* output_file = NULL; +#include "makecert.h" + +struct _MAKECERT_CONTEXT +{ + int argc; + char** argv; + + BIO* bio; + RSA* rsa; + X509* x509; + EVP_PKEY* pkey; + + BOOL live; + BOOL silent; + + char* output_file; + char* default_name; +}; COMMAND_LINE_ARGUMENT_A args[] = { - /* Basic Options */ + /* Custom Options */ { "rdp", COMMAND_LINE_VALUE_FLAG, NULL, NULL, NULL, -1, NULL, "Generate certificate with required options for RDP usage." }, + { "silent", COMMAND_LINE_VALUE_FLAG, NULL, NULL, NULL, -1, NULL, + "Silently generate certificate without verbose output." + }, + { "live", COMMAND_LINE_VALUE_FLAG, NULL, NULL, NULL, -1, NULL, + "Generate certificate live in memory when used as a library." + }, + + /* Basic Options */ + { "n", COMMAND_LINE_VALUE_REQUIRED, "<name>", NULL, NULL, -1, NULL, "Specifies the subject's certificate name. This name must conform to the X.500 standard. " "The simplest method is to specify the name in double quotes, preceded by CN=; for example, -n \"CN=myName\"." @@ -269,36 +295,178 @@ char* x509_get_default_name() return ComputerName; } -int makecert() +int command_line_pre_filter(MAKECERT_CONTEXT* context, int index, int argc, LPCSTR* argv) +{ + if (index == (argc - 1)) + { + if (argv[index][0] != '-') + context->output_file = (char*) argv[index]; + } + + return 0; +} + +int makecert_context_parse_arguments(MAKECERT_CONTEXT* context, int argc, char** argv) +{ + int status; + DWORD flags; + COMMAND_LINE_ARGUMENT_A* arg; + + /** + * makecert -r -pe -n "CN=%COMPUTERNAME%" -eku 1.3.6.1.5.5.7.3.1 -ss my -sr LocalMachine + * -sky exchange -sp "Microsoft RSA SChannel Cryptographic Provider" -sy 12 + */ + + CommandLineClearArgumentsA(args); + + flags = COMMAND_LINE_SEPARATOR_SPACE | COMMAND_LINE_SIGIL_DASH; + status = CommandLineParseArgumentsA(argc, (const char**) argv, args, flags, context, + (COMMAND_LINE_PRE_FILTER_FN_A) command_line_pre_filter, NULL); + + if (status & COMMAND_LINE_STATUS_PRINT_HELP) + { + makecert_print_command_line_help(argc, argv); + return 0; + } + + arg = args; + + do + { + if (!(arg->Flags & COMMAND_LINE_VALUE_PRESENT)) + continue; + + CommandLineSwitchStart(arg) + + /* Basic Options */ + + CommandLineSwitchCase(arg, "silent") + { + context->silent = TRUE; + } + CommandLineSwitchCase(arg, "live") + { + context->live = TRUE; + } + + CommandLineSwitchDefault(arg) + { + + } + + CommandLineSwitchEnd(arg) + } + while ((arg = CommandLineFindNextArgumentA(arg)) != NULL); + + + return 1; +} + +int makecert_context_output_certificate_file(MAKECERT_CONTEXT* context, char* path) { - BIO* bio; FILE* fp; + int length; + char* filename; + char* fullpath; + + if (!context->output_file) + context->output_file = context->default_name; + + /* + * Output Certificate File + */ + + length = strlen(context->output_file); + filename = malloc(length + 8); + strcpy(filename, context->output_file); + strcpy(&filename[length], ".crt"); + + if (path) + fullpath = GetCombinedPath(path, filename); + else + fullpath = _strdup(filename); + + fp = fopen(fullpath, "w+"); + + if (fp) + { + PEM_write_X509(fp, context->x509); + fclose(fp); + } + + free(filename); + free(fullpath); + + return 1; +} + +int makecert_context_output_private_key_file(MAKECERT_CONTEXT* context, char* path) +{ + FILE* fp; + int length; + char* filename; + char* fullpath; + + if (!context->output_file) + context->output_file = context->default_name; + + /** + * Output Private Key File + */ + + length = strlen(context->output_file); + filename = malloc(length + 8); + strcpy(filename, context->output_file); + strcpy(&filename[length], ".key"); + length = strlen(filename); + + if (path) + fullpath = GetCombinedPath(path, filename); + else + fullpath = _strdup(filename); + + fp = fopen(fullpath, "w+"); + + if (fp) + { + PEM_write_PrivateKey(fp, context->pkey, NULL, NULL, 0, NULL, NULL); + fclose(fp); + } + + free(filename); + free(fullpath); + + return 1; +} + +int makecert_context_process(MAKECERT_CONTEXT* context, int argc, char** argv) +{ int length; char* entry; int key_length; - char* filename; - RSA* rsa = NULL; long serial = 0; - char* default_name; X509_NAME* name = NULL; const EVP_MD* md = NULL; COMMAND_LINE_ARGUMENT_A* arg; - default_name = x509_get_default_name(); + if (makecert_context_parse_arguments(context, argc, argv) < 1) + return 0; + + context->default_name = x509_get_default_name(); CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON); - bio = BIO_new_fp(stderr, BIO_NOCLOSE); + context->bio = BIO_new_fp(stderr, BIO_NOCLOSE); - if (!pkey) - pkey = EVP_PKEY_new(); + if (!context->pkey) + context->pkey = EVP_PKEY_new(); - if (!pkey) + if (!context->pkey) return -1; - if (!x509) - x509 = X509_new(); + if (!context->x509) + context->x509 = X509_new(); - if (!x509) + if (!context->x509) return -1; key_length = 2048; @@ -310,14 +478,14 @@ int makecert() key_length = atoi(arg->Value); } - rsa = RSA_generate_key(key_length, RSA_F4, NULL, NULL); + context->rsa = RSA_generate_key(key_length, RSA_F4, NULL, NULL); - if (!EVP_PKEY_assign_RSA(pkey, rsa)) + if (!EVP_PKEY_assign_RSA(context->pkey, context->rsa)) return -1; - rsa = NULL; + context->rsa = NULL; - X509_set_version(x509, 2); + X509_set_version(context->x509, 2); arg = CommandLineFindArgumentA(args, "#"); @@ -326,13 +494,13 @@ int makecert() else serial = (long) GetTickCount64(); - ASN1_INTEGER_set(X509_get_serialNumber(x509), serial); + ASN1_INTEGER_set(X509_get_serialNumber(context->x509), serial); - X509_gmtime_adj(X509_get_notBefore(x509), 0); - X509_gmtime_adj(X509_get_notAfter(x509), (long) 60 * 60 * 24 * 365); - X509_set_pubkey(x509, pkey); + X509_gmtime_adj(X509_get_notBefore(context->x509), 0); + X509_gmtime_adj(X509_get_notAfter(context->x509), (long) 60 * 60 * 24 * 365); + X509_set_pubkey(context->x509, context->pkey); - name = X509_get_subject_name(x509); + name = X509_get_subject_name(context->x509); arg = CommandLineFindArgumentA(args, "n"); @@ -367,7 +535,7 @@ int makecert() if (!entry) { - entry = default_name; + entry = context->default_name; length = strlen(entry); } @@ -375,16 +543,16 @@ int makecert() } else { - entry = default_name; + entry = context->default_name; length = strlen(entry); X509_NAME_add_entry_by_txt(name, "CN", MBSTRING_UTF8, (const unsigned char*) entry, length, -1, 0); } - X509_set_issuer_name(x509, name); + X509_set_issuer_name(context->x509, name); - x509_add_ext(x509, NID_ext_key_usage, "serverAuth"); - x509_add_ext(x509, NID_key_usage, "keyEncipherment,dataEncipherment"); + x509_add_ext(context->x509, NID_ext_key_usage, "serverAuth"); + x509_add_ext(context->x509, NID_key_usage, "keyEncipherment,dataEncipherment"); arg = CommandLineFindArgumentA(args, "a"); @@ -404,260 +572,57 @@ int makecert() md = EVP_sha512(); } - if (!X509_sign(x509, pkey, md)) + if (!X509_sign(context->x509, context->pkey, md)) return -1; /** - * Print Certificate + * Print certificate */ - X509_print_fp(stdout, x509); - - if (!output_file) - output_file = default_name; - - /* - * Output Certificate File - */ - - length = strlen(output_file); - filename = malloc(length + 8); - strcpy(filename, output_file); - strcpy(&filename[length], ".crt"); - fp = fopen(filename, "w+"); - - if (fp) - { - PEM_write_X509(fp, x509); - fclose(fp); - } - - free(filename); + if (!context->silent) + X509_print_fp(stdout, context->x509); /** - * Output Private Key File + * Output certificate and private key to files */ - length = strlen(output_file); - filename = malloc(length + 8); - strcpy(filename, output_file); - strcpy(&filename[length], ".key"); - fp = fopen(filename, "w+"); - - if (fp) + if (!context->live) { - PEM_write_PrivateKey(fp, pkey, NULL, NULL, 0, NULL, NULL); - fclose(fp); + makecert_context_output_certificate_file(context, NULL); + makecert_context_output_private_key_file(context, NULL); } - free(filename); - - X509_free(x509); - EVP_PKEY_free(pkey); - - free(default_name); - - CRYPTO_cleanup_all_ex_data(); - - CRYPTO_mem_leaks(bio); - BIO_free(bio); - return 0; } -int command_line_pre_filter(void* context, int index, int argc, LPCSTR* argv) +MAKECERT_CONTEXT* makecert_context_new() { - if (index == (argc - 1)) + MAKECERT_CONTEXT* context = NULL; + + context = (MAKECERT_CONTEXT*) malloc(sizeof(MAKECERT_CONTEXT)); + + if (context) { - if (argv[index][0] != '-') - output_file = (char*) argv[index]; + ZeroMemory(context, sizeof(MAKECERT_CONTEXT)); } - return 0; + return context; } -int main(int argc, char* argv[]) +void makecert_context_free(MAKECERT_CONTEXT* context) { - int status; - DWORD flags; - COMMAND_LINE_ARGUMENT_A* arg; - - /** - * makecert -r -pe -n "CN=%COMPUTERNAME%" -eku 1.3.6.1.5.5.7.3.1 -ss my -sr LocalMachine - * -sky exchange -sp "Microsoft RSA SChannel Cryptographic Provider" -sy 12 - */ - - flags = COMMAND_LINE_SEPARATOR_SPACE | COMMAND_LINE_SIGIL_DASH; - status = CommandLineParseArgumentsA(argc, (const char**) argv, args, flags, NULL, command_line_pre_filter, NULL); - - if (status & COMMAND_LINE_STATUS_PRINT_HELP) + if (context) { - makecert_print_command_line_help(argc, argv); - return 0; + X509_free(context->x509); + EVP_PKEY_free(context->pkey); + + free(context->default_name); + + CRYPTO_cleanup_all_ex_data(); + + CRYPTO_mem_leaks(context->bio); + BIO_free(context->bio); + + free(context); } - - arg = args; - - do - { - if (!(arg->Flags & COMMAND_LINE_VALUE_PRESENT)) - continue; - - CommandLineSwitchStart(arg) - - /* Basic Options */ - - CommandLineSwitchCase(arg, "n") - { - - } - CommandLineSwitchCase(arg, "pe") - { - - } - CommandLineSwitchCase(arg, "sk") - { - - } - CommandLineSwitchCase(arg, "sr") - { - - } - CommandLineSwitchCase(arg, "ss") - { - - } - CommandLineSwitchCase(arg, "#") - { - - } - CommandLineSwitchCase(arg, "$") - { - - } - - /* Extended Options */ - - CommandLineSwitchCase(arg, "a") - { - - } - CommandLineSwitchCase(arg, "b") - { - - } - CommandLineSwitchCase(arg, "crl") - { - - } - CommandLineSwitchCase(arg, "cy") - { - - } - CommandLineSwitchCase(arg, "e") - { - - } - CommandLineSwitchCase(arg, "eku") - { - - } - CommandLineSwitchCase(arg, "h") - { - - } - CommandLineSwitchCase(arg, "ic") - { - - } - CommandLineSwitchCase(arg, "ik") - { - - } - CommandLineSwitchCase(arg, "iky") - { - - } - CommandLineSwitchCase(arg, "in") - { - - } - CommandLineSwitchCase(arg, "ip") - { - - } - CommandLineSwitchCase(arg, "ir") - { - - } - CommandLineSwitchCase(arg, "is") - { - - } - CommandLineSwitchCase(arg, "iv") - { - - } - CommandLineSwitchCase(arg, "iy") - { - - } - CommandLineSwitchCase(arg, "l") - { - - } - CommandLineSwitchCase(arg, "l") - { - - } - CommandLineSwitchCase(arg, "m") - { - - } - CommandLineSwitchCase(arg, "nscp") - { - - } - CommandLineSwitchCase(arg, "r") - { - - } - CommandLineSwitchCase(arg, "sc") - { - - } - CommandLineSwitchCase(arg, "sky") - { - - } - CommandLineSwitchCase(arg, "sp") - { - - } - CommandLineSwitchCase(arg, "sv") - { - - } - CommandLineSwitchCase(arg, "sy") - { - - } - CommandLineSwitchCase(arg, "tbs") - { - - } - - CommandLineSwitchDefault(arg) - { - - } - - CommandLineSwitchEnd(arg) - } - while ((arg = CommandLineFindNextArgumentA(arg)) != NULL); - - makecert(); - - return 0; } - diff --git a/winpr/tools/makecert/makecert.h b/winpr/tools/makecert/makecert.h new file mode 100644 index 000000000..b46e5c320 --- /dev/null +++ b/winpr/tools/makecert/makecert.h @@ -0,0 +1,36 @@ +/** + * WinPR: Windows Portable Runtime + * makecert replacement + * + * Copyright 2012 Marc-Andre Moreau <marcandre.moreau@gmail.com> + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef MAKECERT_TOOL_H +#define MAKECERT_TOOL_H + +#include <winpr/winpr.h> +#include <winpr/wtypes.h> + +typedef struct _MAKECERT_CONTEXT MAKECERT_CONTEXT; + +WINPR_API int makecert_context_process(MAKECERT_CONTEXT* context, int argc, char** argv); + +WINPR_API int makecert_context_output_certificate_file(MAKECERT_CONTEXT* context, char* path); +WINPR_API int makecert_context_output_private_key_file(MAKECERT_CONTEXT* context, char* path); + +WINPR_API MAKECERT_CONTEXT* makecert_context_new(); +WINPR_API void makecert_context_free(MAKECERT_CONTEXT* context); + +#endif /* MAKECERT_TOOL_H */