22 #include <freerdp/config.h>
34 #include "transport.h"
35 #include "connection.h"
37 #include <freerdp/buildflags.h>
38 #include "gateway/rpc_fault.h"
40 #include <winpr/assert.h>
42 #include <winpr/crt.h>
43 #include <winpr/string.h>
44 #include <winpr/stream.h>
45 #include <winpr/wtsapi.h>
46 #include <winpr/ssl.h>
47 #include <winpr/debug.h>
49 #include <freerdp/freerdp.h>
50 #include <freerdp/streamdump.h>
51 #include <freerdp/error.h>
52 #include <freerdp/event.h>
53 #include <freerdp/locale/keyboard.h>
54 #include <freerdp/locale/locale.h>
55 #include <freerdp/channels/channels.h>
56 #include <freerdp/version.h>
57 #include <freerdp/log.h>
58 #include <freerdp/utils/signal.h>
60 #include "../cache/pointer.h"
63 #define TAG FREERDP_TAG("core")
65 static void sig_abort_connect(
int signum,
const char* signame,
void* ctx)
67 rdpContext* context = (rdpContext*)ctx;
69 WLog_INFO(TAG,
"Signal %s [%d], terminating session %p", signame, signum, context);
71 freerdp_abort_connect_context(context);
85 static int freerdp_connect_begin(freerdp* instance)
90 rdpSettings* settings = NULL;
91 UINT32 KeyboardLayout = 0;
96 WINPR_ASSERT(instance->context);
99 instance->ConnectionCallbackState = CLIENT_STATE_INITIAL;
100 freerdp_set_last_error_log(instance->context, FREERDP_ERROR_SUCCESS);
101 clearChannelError(instance->context);
102 if (!utils_reset_abort(instance->context->rdp))
105 rdp = instance->context->rdp;
108 settings = instance->context->settings;
109 WINPR_ASSERT(settings);
111 freerdp_channels_register_instance(instance->context->channels, instance);
113 if (!freerdp_settings_set_default_order_support(settings))
116 freerdp_add_signal_cleanup_handler(instance->context, sig_abort_connect);
118 IFCALLRET(instance->PreConnect, status, instance);
119 instance->ConnectionCallbackState = CLIENT_STATE_PRECONNECT_PASSED;
121 freerdp_settings_print_warnings(settings);
123 status = freerdp_settings_enforce_monitor_exists(settings);
126 status = freerdp_settings_check_client_after_preconnect(settings);
129 status = rdp_set_backup_settings(rdp);
131 status = utils_reload_channels(instance->context);
134 KeyboardLayout = freerdp_get_keyboard_default_layout_for_locale(cp);
135 if (KeyboardLayout == 0)
138 switch (KeyboardLayout)
141 case KBD_JAPANESE_INPUT_SYSTEM_MS_IME2002:
144 WINPR_KBD_TYPE_JAPANESE))
158 rdpContext* context = instance->context;
159 WINPR_ASSERT(context);
160 freerdp_set_last_error_if_not(context, FREERDP_ERROR_PRE_CONNECT_FAILED);
162 WLog_Print(context->log, WLOG_ERROR,
"freerdp_pre_connect failed");
166 rc = rdp_client_connect(rdp);
171 rdpContext* context = rdp->context;
172 WINPR_ASSERT(context);
173 WLog_Print(context->log, WLOG_ERROR,
"Authentication only, exit status %" PRId32
"", rc);
180 BOOL freerdp_connect(freerdp* instance)
183 ConnectionResultEventArgs e = { 0 };
184 const int rc = freerdp_connect_begin(instance);
186 UINT status2 = ERROR_INTERNAL_ERROR;
188 WINPR_ASSERT(instance);
189 WINPR_ASSERT(instance->context);
191 rdp = instance->context->rdp;
193 WINPR_ASSERT(rdp->settings);
199 goto freerdp_connect_finally;
207 up->pcap_rfx = pcap_open(
217 pointer_cache_register_callbacks(instance->context->update);
218 status = IFCALLRESULT(TRUE, instance->PostConnect, instance);
219 instance->ConnectionCallbackState = CLIENT_STATE_POSTCONNECT_PASSED;
222 status2 = freerdp_channels_post_connect(instance->context->channels, instance);
226 status2 = CHANNEL_RC_OK;
227 if (freerdp_get_last_error(instance->context) == FREERDP_ERROR_CONNECT_TRANSPORT_FAILED)
228 status = freerdp_reconnect(instance);
230 goto freerdp_connect_finally;
233 if (!status || (status2 != CHANNEL_RC_OK) || !update_post_connect(instance->context->update))
235 rdpContext* context = instance->context;
236 WINPR_ASSERT(context);
237 WLog_Print(context->log, WLOG_ERROR,
"freerdp_post_connect failed");
239 freerdp_set_last_error_if_not(context, FREERDP_ERROR_POST_CONNECT_FAILED);
242 goto freerdp_connect_finally;
245 if (rdp->settings->PlayRemoteFx)
249 pcap_record record = { 0 };
251 WINPR_ASSERT(update);
252 update->pcap_rfx = pcap_open(rdp->settings->PlayRemoteFxFile, FALSE);
255 if (!update->pcap_rfx)
256 goto freerdp_connect_finally;
258 update->play_rfx = TRUE;
262 while (pcap_has_next_record(update->pcap_rfx) && status)
264 pcap_get_next_record_header(update->pcap_rfx, &record);
266 s = transport_take_from_pool(rdp->transport, record.length);
270 record.data = Stream_Buffer(s);
271 pcap_get_next_record_content(update->pcap_rfx, &record);
272 Stream_SetLength(s, record.length);
273 Stream_SetPosition(s, 0);
275 if (!update_begin_paint(&update->common))
279 if (update_recv_surfcmds(&update->common, s) < 0)
282 if (!update_end_paint(&update->common))
289 pcap_close(update->pcap_rfx);
290 update->pcap_rfx = NULL;
291 goto freerdp_connect_finally;
294 if (rdp->errorInfo == ERRINFO_SERVER_INSUFFICIENT_PRIVILEGES)
295 freerdp_set_last_error_log(instance->context, FREERDP_ERROR_INSUFFICIENT_PRIVILEGES);
297 transport_set_connected_event(rdp->transport);
299 freerdp_connect_finally:
300 EventArgsInit(&e,
"freerdp");
301 e.result = status ? 0 : -1;
302 PubSub_OnConnectionResult(rdp->pubSub, instance->context, &e);
305 freerdp_disconnect(instance);
310 BOOL freerdp_abort_connect(freerdp* instance)
315 return freerdp_abort_connect_context(instance->context);
318 BOOL freerdp_abort_connect_context(rdpContext* context)
323 freerdp_set_last_error_if_not(context, FREERDP_ERROR_CONNECT_CANCELLED);
325 return utils_abort_connect(context->rdp);
328 #if defined(WITH_FREERDP_DEPRECATED)
329 BOOL freerdp_get_fds(freerdp* instance,
void** rfds,
int* rcount,
void** wfds,
int* wcount)
333 WINPR_ASSERT(instance);
334 WINPR_ASSERT(instance->context);
336 rdp = instance->context->rdp;
339 transport_get_fds(rdp->transport, rfds, rcount);
344 BOOL freerdp_check_fds(freerdp* instance)
352 if (!instance->context)
355 if (!instance->context->rdp)
358 rdp = instance->context->rdp;
359 status = rdp_check_fds(rdp);
363 TerminateEventArgs e;
364 rdpContext* context = instance->context;
365 WINPR_ASSERT(context);
367 WLog_Print(context->log, WLOG_DEBUG,
"rdp_check_fds() - %i", status);
368 EventArgsInit(&e,
"freerdp");
370 PubSub_OnTerminate(rdp->pubSub, context, &e);
377 DWORD freerdp_get_event_handles(rdpContext* context, HANDLE* events, DWORD count)
381 WINPR_ASSERT(context);
382 WINPR_ASSERT(context->rdp);
383 WINPR_ASSERT(events || (count == 0));
385 nCount += transport_get_event_handles(context->rdp->transport, events, count);
390 if (events && (nCount < count + 2))
392 events[nCount++] = freerdp_channels_get_event_handle(context->instance);
393 events[nCount++] = getChannelErrorEventHandle(context);
394 events[nCount++] = utils_get_abort_event(context->rdp);
399 const SSIZE_T rc = freerdp_client_channel_get_registered_event_handles(
400 context->channels, &events[nCount], count - nCount);
403 return nCount + (DWORD)rc;
407 static BOOL freerdp_prevent_session_lock(rdpContext* context)
409 WINPR_ASSERT(context);
410 WINPR_ASSERT(context->input);
414 UINT32 FakeMouseMotionInterval =
416 if (FakeMouseMotionInterval && in->lastInputTimestamp)
418 const time_t now = time(NULL);
419 if (now - in->lastInputTimestamp > FakeMouseMotionInterval)
421 WLog_Print(context->log, WLOG_DEBUG,
422 "fake mouse move: x=%d y=%d lastInputTimestamp=%" PRIu64
" "
423 "FakeMouseMotionInterval=%" PRIu32,
424 in->lastX, in->lastY, in->lastInputTimestamp, FakeMouseMotionInterval);
426 BOOL status = freerdp_input_send_mouse_event(context->input, PTR_FLAGS_MOVE, in->lastX,
430 if (freerdp_get_last_error(context) == FREERDP_ERROR_SUCCESS)
431 WLog_Print(context->log, WLOG_ERROR,
432 "freerdp_prevent_session_lock() failed - %" PRIi32
"", status);
444 BOOL freerdp_check_event_handles(rdpContext* context)
446 WINPR_ASSERT(context);
448 BOOL status = freerdp_check_fds(context->instance);
452 if (freerdp_get_last_error(context) == FREERDP_ERROR_SUCCESS)
453 WLog_Print(context->log, WLOG_ERROR,
"freerdp_check_fds() failed - %" PRIi32
"",
459 status = freerdp_channels_check_fds(context->channels, context->instance);
463 if (freerdp_get_last_error(context) == FREERDP_ERROR_SUCCESS)
464 WLog_Print(context->log, WLOG_ERROR,
465 "freerdp_channels_check_fds() failed - %" PRIi32
"", status);
470 status = checkChannelErrorEvent(context);
474 if (freerdp_get_last_error(context) == FREERDP_ERROR_SUCCESS)
475 WLog_Print(context->log, WLOG_ERROR,
"checkChannelErrorEvent() failed - %" PRIi32
"",
481 status = freerdp_prevent_session_lock(context);
486 wMessageQueue* freerdp_get_message_queue(freerdp* instance, DWORD
id)
488 wMessageQueue* queue = NULL;
490 WINPR_ASSERT(instance);
492 rdpContext* context = instance->context;
493 WINPR_ASSERT(context);
497 case FREERDP_UPDATE_MESSAGE_QUEUE:
500 queue = update->queue;
504 case FREERDP_INPUT_MESSAGE_QUEUE:
507 queue = input->queue;
517 HANDLE freerdp_get_message_queue_event_handle(freerdp* instance, DWORD
id)
520 wMessageQueue* queue = freerdp_get_message_queue(instance,
id);
523 event = MessageQueue_Event(queue);
528 int freerdp_message_queue_process_message(freerdp* instance, DWORD
id, wMessage* message)
531 rdpContext* context = NULL;
533 WINPR_ASSERT(instance);
535 context = instance->context;
536 WINPR_ASSERT(context);
540 case FREERDP_UPDATE_MESSAGE_QUEUE:
541 status = update_message_queue_process_message(context->update, message);
544 case FREERDP_INPUT_MESSAGE_QUEUE:
545 status = input_message_queue_process_message(context->input, message);
554 int freerdp_message_queue_process_pending_messages(freerdp* instance, DWORD
id)
557 rdpContext* context = NULL;
559 WINPR_ASSERT(instance);
561 context = instance->context;
562 WINPR_ASSERT(context);
566 case FREERDP_UPDATE_MESSAGE_QUEUE:
567 status = update_message_queue_process_pending_messages(context->update);
570 case FREERDP_INPUT_MESSAGE_QUEUE:
571 status = input_message_queue_process_pending_messages(context->input);
580 static BOOL freerdp_send_channel_data(freerdp* instance, UINT16 channelId,
const BYTE* data,
583 WINPR_ASSERT(instance);
584 WINPR_ASSERT(instance->context);
585 WINPR_ASSERT(instance->context->rdp);
586 return rdp_send_channel_data(instance->context->rdp, channelId, data, size);
589 static BOOL freerdp_send_channel_packet(freerdp* instance, UINT16 channelId,
size_t totalSize,
590 UINT32 flags,
const BYTE* data,
size_t chunkSize)
592 WINPR_ASSERT(instance);
593 WINPR_ASSERT(instance->context);
594 WINPR_ASSERT(instance->context->rdp);
595 return rdp_channel_send_packet(instance->context->rdp, channelId, totalSize, flags, data,
599 BOOL freerdp_disconnect(freerdp* instance)
605 if (!instance || !instance->context)
608 rdp = instance->context->rdp;
609 utils_abort_connect(rdp);
611 if (!rdp_client_disconnect(rdp))
614 up = update_cast(rdp->update);
616 update_post_disconnect(rdp->update);
618 IFCALL(instance->PostDisconnect, instance);
622 up->dump_rfx = FALSE;
623 pcap_close(up->pcap_rfx);
627 freerdp_channels_close(instance->context->channels, instance);
629 IFCALL(instance->PostFinalDisconnect, instance);
631 freerdp_del_signal_cleanup_handler(instance->context, sig_abort_connect);
635 BOOL freerdp_disconnect_before_reconnect(freerdp* instance)
637 WINPR_ASSERT(instance);
638 return freerdp_disconnect_before_reconnect_context(instance->context);
641 BOOL freerdp_disconnect_before_reconnect_context(rdpContext* context)
645 WINPR_ASSERT(context);
648 return rdp_client_disconnect_and_clear(rdp);
651 BOOL freerdp_reconnect(freerdp* instance)
655 WINPR_ASSERT(instance);
656 WINPR_ASSERT(instance->context);
658 if (freerdp_get_last_error(instance->context) == FREERDP_ERROR_CONNECT_CANCELLED)
661 rdp = instance->context->rdp;
663 if (!utils_reset_abort(instance->context->rdp))
665 return rdp_client_reconnect(rdp);
668 BOOL freerdp_shall_disconnect(freerdp* instance)
673 return freerdp_shall_disconnect_context(instance->context);
676 BOOL freerdp_shall_disconnect_context(
const rdpContext* context)
681 return utils_abort_event_is_set(context->rdp);
684 BOOL freerdp_focus_required(freerdp* instance)
687 BOOL bRetCode = FALSE;
689 WINPR_ASSERT(instance);
690 WINPR_ASSERT(instance->context);
692 rdp = instance->context->rdp;
695 if (rdp->resendFocus)
698 rdp->resendFocus = FALSE;
704 void freerdp_set_focus(freerdp* instance)
708 WINPR_ASSERT(instance);
709 WINPR_ASSERT(instance->context);
711 rdp = instance->context->rdp;
714 rdp->resendFocus = TRUE;
717 void freerdp_get_version(
int* major,
int* minor,
int* revision)
720 *major = FREERDP_VERSION_MAJOR;
723 *minor = FREERDP_VERSION_MINOR;
725 if (revision != NULL)
726 *revision = FREERDP_VERSION_REVISION;
729 const char* freerdp_get_version_string(
void)
731 return FREERDP_VERSION_FULL;
734 const char* freerdp_get_build_config(
void)
736 WINPR_PRAGMA_DIAG_PUSH
737 WINPR_PRAGMA_DIAG_IGNORED_OVERLENGTH_STRINGS
738 static const char build_config[] =
739 "Build configuration: " FREERDP_BUILD_CONFIG
"\n"
740 "Build type: " FREERDP_BUILD_TYPE
"\n"
741 "CFLAGS: " FREERDP_CFLAGS
"\n"
742 "Compiler: " FREERDP_COMPILER_ID
", " FREERDP_COMPILER_VERSION
"\n"
743 "Target architecture: " FREERDP_TARGET_ARCH
"\n";
744 WINPR_PRAGMA_DIAG_POP
748 const char* freerdp_get_build_revision(
void)
750 return FREERDP_GIT_REVISION;
754 DEFINE_EVENT_ENTRY(WindowStateChange), DEFINE_EVENT_ENTRY(ResizeWindow),
755 DEFINE_EVENT_ENTRY(LocalResizeWindow), DEFINE_EVENT_ENTRY(EmbedWindow),
756 DEFINE_EVENT_ENTRY(PanningChange), DEFINE_EVENT_ENTRY(ZoomingChange),
757 DEFINE_EVENT_ENTRY(ErrorInfo), DEFINE_EVENT_ENTRY(Terminate),
758 DEFINE_EVENT_ENTRY(ConnectionResult), DEFINE_EVENT_ENTRY(ChannelConnected),
759 DEFINE_EVENT_ENTRY(ChannelDisconnected), DEFINE_EVENT_ENTRY(MouseEvent),
760 DEFINE_EVENT_ENTRY(Activated), DEFINE_EVENT_ENTRY(Timer),
761 DEFINE_EVENT_ENTRY(GraphicsReset)
774 BOOL freerdp_context_new(freerdp* instance)
776 return freerdp_context_new_ex(instance, NULL);
779 BOOL freerdp_context_new_ex(freerdp* instance, rdpSettings* settings)
782 rdpContext* context = NULL;
785 WINPR_ASSERT(instance);
787 instance->context = context = (rdpContext*)calloc(1, instance->ContextSize);
792 context->log = WLog_Get(TAG);
797 context->settings = settings;
798 context->instance = instance;
799 context->ServerMode = FALSE;
800 context->disconnectUltimatum = 0;
802 context->metrics = metrics_new(context);
804 if (!context->metrics)
807 rdp = rdp_new(context);
812 rdp_log_build_warnings(rdp);
814 context->pubSub = rdp->pubSub;
816 if (!context->pubSub)
819 PubSub_AddEventTypes(rdp->pubSub, FreeRDP_Events, ARRAYSIZE(FreeRDP_Events));
821 #if defined(WITH_FREERDP_DEPRECATED)
822 instance->input = rdp->input;
823 instance->update = rdp->update;
824 instance->settings = rdp->settings;
825 instance->autodetect = rdp->autodetect;
828 instance->heartbeat = rdp->heartbeat;
829 context->graphics = graphics_new(context);
831 if (!context->graphics)
834 context->input = rdp->input;
835 context->update = rdp->update;
836 context->settings = rdp->settings;
837 context->autodetect = rdp->autodetect;
839 if (!(context->errorDescription = calloc(1, 500)))
841 WLog_Print(context->log, WLOG_ERROR,
"calloc failed!");
845 if (!(context->channelErrorEvent = CreateEvent(NULL, TRUE, FALSE, NULL)))
847 WLog_Print(context->log, WLOG_ERROR,
"CreateEvent failed!");
851 update_register_client_callbacks(rdp->update);
853 if (!(context->channels = freerdp_channels_new(instance)))
856 context->dump = stream_dump_new();
860 IFCALLRET(instance->ContextNew, ret, instance, context);
866 freerdp_context_free(instance);
870 BOOL freerdp_context_reset(freerdp* instance)
875 WINPR_ASSERT(instance->context);
876 rdpRdp* rdp = instance->context->rdp;
878 return rdp_reset_runtime_settings(rdp);
889 void freerdp_context_free(freerdp* instance)
891 rdpContext* ctx = NULL;
896 if (!instance->context)
899 ctx = instance->context;
901 IFCALL(instance->ContextFree, instance, ctx);
904 ctx->settings = NULL;
906 graphics_free(ctx->graphics);
907 ctx->graphics = NULL;
909 metrics_free(ctx->metrics);
912 if (ctx->channelErrorEvent)
913 (void)CloseHandle(ctx->channelErrorEvent);
914 ctx->channelErrorEvent = NULL;
916 free(ctx->errorDescription);
917 ctx->errorDescription = NULL;
919 freerdp_channels_free(ctx->channels);
920 ctx->channels = NULL;
922 freerdp_client_codecs_free(ctx->codecs);
925 stream_dump_free(ctx->dump);
930 ctx->settings = NULL;
931 ctx->autodetect = NULL;
934 instance->context = NULL;
935 #if defined(WITH_FREERDP_DEPRECATED)
936 instance->input = NULL;
937 instance->update = NULL;
938 instance->settings = NULL;
939 instance->autodetect = NULL;
941 instance->heartbeat = NULL;
944 int freerdp_get_disconnect_ultimatum(rdpContext* context)
946 WINPR_ASSERT(context);
947 return context->disconnectUltimatum;
950 UINT32 freerdp_error_info(freerdp* instance)
952 WINPR_ASSERT(instance);
953 WINPR_ASSERT(instance->context);
954 WINPR_ASSERT(instance->context->rdp);
955 return instance->context->rdp->errorInfo;
958 void freerdp_set_error_info(rdpRdp* rdp, UINT32 error)
963 rdp_set_error_info(rdp, error);
966 BOOL freerdp_send_error_info(rdpRdp* rdp)
971 return rdp_send_error_info(rdp);
974 UINT32 freerdp_get_last_error(rdpContext* context)
976 WINPR_ASSERT(context);
977 return context->LastError;
980 const char* freerdp_get_last_error_name(UINT32 code)
982 const char* name = NULL;
983 const UINT32 cls = GET_FREERDP_ERROR_CLASS(code);
984 const UINT32 type = GET_FREERDP_ERROR_TYPE(code);
988 case FREERDP_ERROR_ERRBASE_CLASS:
989 name = freerdp_get_error_base_name(type);
992 case FREERDP_ERROR_ERRINFO_CLASS:
993 name = freerdp_get_error_info_name(type);
996 case FREERDP_ERROR_CONNECT_CLASS:
997 name = freerdp_get_error_connect_name(type);
1001 name = rpc_error_to_string(code);
1008 const char* freerdp_get_last_error_string(UINT32 code)
1010 const char*
string = NULL;
1011 const UINT32 cls = GET_FREERDP_ERROR_CLASS(code);
1012 const UINT32 type = GET_FREERDP_ERROR_TYPE(code);
1016 case FREERDP_ERROR_ERRBASE_CLASS:
1017 string = freerdp_get_error_base_string(type);
1020 case FREERDP_ERROR_ERRINFO_CLASS:
1021 string = freerdp_get_error_info_string(type);
1024 case FREERDP_ERROR_CONNECT_CLASS:
1025 string = freerdp_get_error_connect_string(type);
1029 string = rpc_error_to_string(code);
1036 const char* freerdp_get_last_error_category(UINT32 code)
1038 const char*
string = NULL;
1039 const UINT32 cls = GET_FREERDP_ERROR_CLASS(code);
1040 const UINT32 type = GET_FREERDP_ERROR_TYPE(code);
1044 case FREERDP_ERROR_ERRBASE_CLASS:
1045 string = freerdp_get_error_base_category(type);
1048 case FREERDP_ERROR_ERRINFO_CLASS:
1049 string = freerdp_get_error_info_category(type);
1052 case FREERDP_ERROR_CONNECT_CLASS:
1053 string = freerdp_get_error_connect_category(type);
1057 string = rpc_error_to_category(code);
1064 void freerdp_set_last_error_ex(rdpContext* context, UINT32 lastError,
const char* fkt,
1065 const char* file,
int line)
1067 WINPR_ASSERT(context);
1068 WINPR_ASSERT(line >= 0);
1072 if (WLog_IsLevelActive(context->log, WLOG_ERROR))
1074 WLog_PrintMessage(context->log, WLOG_MESSAGE_TEXT, WLOG_ERROR, (
size_t)line, file, fkt,
1075 "%s [0x%08" PRIX32
"]", freerdp_get_last_error_name(lastError),
1080 if (lastError == FREERDP_ERROR_SUCCESS)
1082 if (WLog_IsLevelActive(context->log, WLOG_DEBUG))
1083 WLog_PrintMessage(context->log, WLOG_MESSAGE_TEXT, WLOG_DEBUG, (
size_t)line, file, fkt,
1084 "resetting error state");
1086 else if (context->LastError != FREERDP_ERROR_SUCCESS)
1088 if (WLog_IsLevelActive(context->log, WLOG_ERROR))
1090 WLog_PrintMessage(context->log, WLOG_MESSAGE_TEXT, WLOG_ERROR, (
size_t)line, file, fkt,
1091 "TODO: Trying to set error code %s, but %s already set!",
1092 freerdp_get_last_error_name(lastError),
1093 freerdp_get_last_error_name(context->LastError));
1096 context->LastError = lastError;
1099 const char* freerdp_get_logon_error_info_type_ex(UINT32 type,
char* buffer,
size_t size)
1101 const char* str = freerdp_get_logon_error_info_type(type);
1102 (void)_snprintf(buffer, size,
"%s(0x%04" PRIx32
")", str, type);
1106 const char* freerdp_get_logon_error_info_type(UINT32 type)
1110 case LOGON_MSG_DISCONNECT_REFUSED:
1111 return "LOGON_MSG_DISCONNECT_REFUSED";
1113 case LOGON_MSG_NO_PERMISSION:
1114 return "LOGON_MSG_NO_PERMISSION";
1116 case LOGON_MSG_BUMP_OPTIONS:
1117 return "LOGON_MSG_BUMP_OPTIONS";
1119 case LOGON_MSG_RECONNECT_OPTIONS:
1120 return "LOGON_MSG_RECONNECT_OPTIONS";
1122 case LOGON_MSG_SESSION_TERMINATE:
1123 return "LOGON_MSG_SESSION_TERMINATE";
1125 case LOGON_MSG_SESSION_CONTINUE:
1126 return "LOGON_MSG_SESSION_CONTINUE";
1133 const char* freerdp_get_logon_error_info_data(UINT32 data)
1137 case LOGON_FAILED_BAD_PASSWORD:
1138 return "LOGON_FAILED_BAD_PASSWORD";
1140 case LOGON_FAILED_UPDATE_PASSWORD:
1141 return "LOGON_FAILED_UPDATE_PASSWORD";
1143 case LOGON_FAILED_OTHER:
1144 return "LOGON_FAILED_OTHER";
1147 return "LOGON_WARNING";
1150 return "SESSION_ID";
1154 const char* freerdp_get_logon_error_info_data_ex(UINT32 data,
char* buffer,
size_t size)
1156 const char* str = freerdp_get_logon_error_info_data(data);
1157 (void)_snprintf(buffer, size,
"%s(0x%04" PRIx32
")", str, data);
1164 freerdp* freerdp_new(
void)
1166 freerdp* instance = NULL;
1167 instance = (freerdp*)calloc(1,
sizeof(freerdp));
1172 instance->ContextSize =
sizeof(rdpContext);
1173 instance->SendChannelData = freerdp_send_channel_data;
1174 instance->SendChannelPacket = freerdp_send_channel_packet;
1175 instance->ReceiveChannelData = freerdp_channels_data;
1183 void freerdp_free(freerdp* instance)
1188 ULONG freerdp_get_transport_sent(rdpContext* context, BOOL resetCount)
1190 WINPR_ASSERT(context);
1191 WINPR_ASSERT(context->rdp);
1192 return transport_get_bytes_sent(context->rdp->transport, resetCount);
1195 BOOL freerdp_nla_impersonate(rdpContext* context)
1205 if (!context->rdp->transport)
1208 nla = transport_get_nla(context->rdp->transport);
1209 return nla_impersonate(nla);
1212 BOOL freerdp_nla_revert_to_self(rdpContext* context)
1222 if (!context->rdp->transport)
1225 nla = transport_get_nla(context->rdp->transport);
1226 return nla_revert_to_self(nla);
1229 UINT32 freerdp_get_nla_sspi_error(rdpContext* context)
1233 WINPR_ASSERT(context);
1234 WINPR_ASSERT(context->rdp);
1235 WINPR_ASSERT(context->rdp->transport);
1237 nla = transport_get_nla(context->rdp->transport);
1239 return nla_get_sspi_error(nla);
1242 BOOL freerdp_nla_encrypt(rdpContext* context,
const SecBuffer* inBuffer,
SecBuffer* outBuffer)
1244 WINPR_ASSERT(context);
1245 WINPR_ASSERT(context->rdp);
1247 rdpNla* nla = context->rdp->nla;
1248 return nla_encrypt(nla, inBuffer, outBuffer);
1251 BOOL freerdp_nla_decrypt(rdpContext* context,
const SecBuffer* inBuffer,
SecBuffer* outBuffer)
1253 WINPR_ASSERT(context);
1254 WINPR_ASSERT(context->rdp);
1256 rdpNla* nla = context->rdp->nla;
1257 return nla_decrypt(nla, inBuffer, outBuffer);
1260 SECURITY_STATUS freerdp_nla_QueryContextAttributes(rdpContext* context, DWORD ulAttr, PVOID pBuffer)
1262 WINPR_ASSERT(context);
1263 WINPR_ASSERT(context->rdp);
1265 return nla_QueryContextAttributes(context->rdp->nla, ulAttr, pBuffer);
1268 HANDLE getChannelErrorEventHandle(rdpContext* context)
1270 WINPR_ASSERT(context);
1271 return context->channelErrorEvent;
1274 BOOL checkChannelErrorEvent(rdpContext* context)
1276 WINPR_ASSERT(context);
1278 if (WaitForSingleObject(context->channelErrorEvent, 0) == WAIT_OBJECT_0)
1280 WLog_Print(context->log, WLOG_ERROR,
"%s. Error was %" PRIu32
"", context->errorDescription,
1281 context->channelErrorNum);
1293 UINT getChannelError(rdpContext* context)
1295 WINPR_ASSERT(context);
1296 return context->channelErrorNum;
1299 const char* getChannelErrorDescription(rdpContext* context)
1301 WINPR_ASSERT(context);
1302 return context->errorDescription;
1305 void clearChannelError(rdpContext* context)
1307 WINPR_ASSERT(context);
1308 context->channelErrorNum = 0;
1309 memset(context->errorDescription, 0, 500);
1310 (void)ResetEvent(context->channelErrorEvent);
1313 WINPR_ATTR_FORMAT_ARG(3, 4)
1314 void setChannelError(rdpContext* context, UINT errorNum, WINPR_FORMAT_ARG const
char* format, ...)
1317 va_start(ap, format);
1319 WINPR_ASSERT(context);
1321 context->channelErrorNum = errorNum;
1322 (void)vsnprintf(context->errorDescription, 499, format, ap);
1324 (void)SetEvent(context->channelErrorEvent);
1327 const char* freerdp_nego_get_routing_token(rdpContext* context, DWORD* length)
1329 if (!context || !context->rdp)
1332 return (
const char*)nego_get_routing_token(context->rdp->nego, length);
1335 BOOL freerdp_io_callback_set_event(rdpContext* context, BOOL set)
1337 WINPR_ASSERT(context);
1338 return rdp_io_callback_set_event(context->rdp, set);
1341 const rdpTransportIo* freerdp_get_io_callbacks(rdpContext* context)
1343 WINPR_ASSERT(context);
1344 return rdp_get_io_callbacks(context->rdp);
1347 BOOL freerdp_set_io_callbacks(rdpContext* context,
const rdpTransportIo* io_callbacks)
1349 WINPR_ASSERT(context);
1350 return rdp_set_io_callbacks(context->rdp, io_callbacks);
1353 BOOL freerdp_set_io_callback_context(rdpContext* context,
void* usercontext)
1355 WINPR_ASSERT(context);
1356 return rdp_set_io_callback_context(context->rdp, usercontext);
1359 void* freerdp_get_io_callback_context(rdpContext* context)
1361 WINPR_ASSERT(context);
1362 return rdp_get_io_callback_context(context->rdp);
1365 CONNECTION_STATE freerdp_get_state(
const rdpContext* context)
1367 WINPR_ASSERT(context);
1368 return rdp_get_state(context->rdp);
1371 const char* freerdp_state_string(CONNECTION_STATE state)
1373 return rdp_state_string(state);
1376 BOOL freerdp_is_active_state(
const rdpContext* context)
1378 WINPR_ASSERT(context);
1379 return rdp_is_active_state(context->rdp);
1382 BOOL freerdp_channels_from_mcs(rdpSettings* settings,
const rdpContext* context)
1384 WINPR_ASSERT(context);
1385 return rdp_channels_from_mcs(settings, context->rdp);
1388 HANDLE freerdp_abort_event(rdpContext* context)
1390 WINPR_ASSERT(context);
1391 return utils_get_abort_event(context->rdp);
1394 static void test_mcs_free(rdpMcs* mcs)
1399 rdpTransport* transport = mcs->transport;
1400 rdpContext* context = transport_get_context(transport);
1403 rdpSettings* settings = context->settings;
1407 transport_free(transport);
1412 static rdpMcs* test_mcs_new(
void)
1414 rdpTransport* transport = NULL;
1416 rdpContext* context = calloc(1,
sizeof(rdpContext));
1425 context->settings = settings;
1426 transport = transport_new(context);
1429 return mcs_new(transport);
1432 transport_free(transport);
1439 BOOL freerdp_is_valid_mcs_create_request(
const BYTE* data,
size_t size)
1443 wStream* s = Stream_StaticConstInit(&sbuffer, data, size);
1445 WINPR_ASSERT(data || (size == 0));
1448 rdpMcs* mcs = test_mcs_new();
1451 BOOL result = mcs_recv_connect_initial(mcs, s);
1456 BOOL freerdp_is_valid_mcs_create_response(
const BYTE* data,
size_t size)
1460 wStream* s = Stream_StaticConstInit(&sbuffer, data, size);
1462 WINPR_ASSERT(data || (size == 0));
1465 rdpMcs* mcs = test_mcs_new();
1468 BOOL result = mcs_recv_connect_response(mcs, s);
FREERDP_API UINT32 freerdp_settings_get_uint32(const rdpSettings *settings, FreeRDP_Settings_Keys_UInt32 id)
Returns a UINT32 settings value.
FREERDP_API BOOL freerdp_settings_get_bool(const rdpSettings *settings, FreeRDP_Settings_Keys_Bool id)
Returns a boolean settings value.
FREERDP_API rdpSettings * freerdp_settings_new(DWORD flags)
creates a new setting struct
FREERDP_API const char * freerdp_settings_get_string(const rdpSettings *settings, FreeRDP_Settings_Keys_String id)
Returns a immutable string settings value.
FREERDP_API void freerdp_settings_free(rdpSettings *settings)
Free a settings struct with all data in it.
FREERDP_API BOOL freerdp_settings_set_uint32(rdpSettings *settings, FreeRDP_Settings_Keys_UInt32 id, UINT32 param)
Sets a UINT32 settings value.
FREERDP_API BOOL freerdp_settings_set_bool(rdpSettings *settings, FreeRDP_Settings_Keys_Bool id, BOOL param)
Sets a BOOL settings value.