int freerdp_client_parse_command_line(rdpContext* context, int argc, char** argv) { int status; rdpSettings* settings; context->argc = argc; context->argv = argv; if (context->argc < 1) return 0; if (!context->argv) return -1; settings = context->settings; status = freerdp_client_parse_command_line_arguments(context->argc, context->argv, settings); if (settings->ConnectionFile) { return freerdp_client_parse_connection_file(context, settings->ConnectionFile); } return status; }
int freerdp_client_parse_command_line(rdpContext* context, int argc, char** argv) { int status; rdpSettings* settings; context->argc = argc; context->argv = argv; if (context->argc < 1) return 0; if (!context->argv) return -1; settings = context->settings; status = freerdp_client_parse_command_line_arguments(context->argc, context->argv, settings); if (settings->ConnectionFile) { rdpFile* file = freerdp_client_rdp_file_new(); freerdp_client_parse_rdp_file(file, settings->ConnectionFile); freerdp_client_populate_settings_from_rdp_file(file, settings); freerdp_client_rdp_file_free(file); } return status; }
int main(int argc, char* argv[]) { int status; pthread_t thread; freerdp* instance; dfContext* context; rdpChannels* channels; struct thread_data* data; setlocale(LC_ALL, ""); freerdp_channels_global_init(); g_sem = CreateSemaphore(NULL, 0, 1, NULL); instance = freerdp_new(); instance->PreConnect = df_pre_connect; instance->PostConnect = df_post_connect; instance->VerifyCertificate = df_verify_certificate; instance->ReceiveChannelData = df_receive_channel_data; instance->ContextSize = sizeof(dfContext); instance->ContextNew = df_context_new; instance->ContextFree = df_context_free; freerdp_context_new(instance); context = (dfContext*) instance->context; channels = instance->context->channels; DirectFBInit(&argc, &argv); instance->context->argc = argc; instance->context->argv = argv; status = freerdp_client_parse_command_line_arguments(argc, argv, instance->settings); if (status < 0) exit(0); freerdp_client_load_addins(instance->context->channels, instance->settings); data = (struct thread_data*) malloc(sizeof(struct thread_data)); ZeroMemory(data, sizeof(sizeof(struct thread_data))); data->instance = instance; g_thread_count++; pthread_create(&thread, 0, thread_func, data); while (g_thread_count > 0) { WaitForSingleObject(g_sem, INFINITE); } freerdp_channels_global_uninit(); return 0; }
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); if (!wfi->thread) return -1; return 0; }
BOOL freerdp_client_populate_settings_from_rdp_file(rdpFile* file, rdpSettings* settings) { if (~((size_t) file->Domain)) freerdp_set_param_string(settings, FreeRDP_Domain, file->Domain); if (~((size_t) file->Username)) { char* user = NULL; char* domain = NULL; freerdp_parse_username(file->Username, &user, &domain); freerdp_set_param_string(settings, FreeRDP_Username, user); if (domain) freerdp_set_param_string(settings, FreeRDP_Domain, domain); if (user) free(user); if (domain) free(domain); } if (~file->ServerPort) freerdp_set_param_uint32(settings, FreeRDP_ServerPort, file->ServerPort); if (~((size_t) file->FullAddress)) freerdp_set_param_string(settings, FreeRDP_ServerHostname, file->FullAddress); if (~file->DesktopWidth) freerdp_set_param_uint32(settings, FreeRDP_DesktopWidth, file->DesktopWidth); if (~file->DesktopHeight) freerdp_set_param_uint32(settings, FreeRDP_DesktopHeight, file->DesktopHeight); if (~file->SessionBpp) freerdp_set_param_uint32(settings, FreeRDP_ColorDepth, file->SessionBpp); if (~file->ConnectToConsole) freerdp_set_param_uint32(settings, FreeRDP_ConsoleSession, file->ConnectToConsole); if (~file->AdministrativeSession) freerdp_set_param_uint32(settings, FreeRDP_ConsoleSession, file->AdministrativeSession); if (~file->NegotiateSecurityLayer) freerdp_set_param_uint32(settings, FreeRDP_NegotiateSecurityLayer, file->NegotiateSecurityLayer); if (~file->EnableCredSSPSupport) freerdp_set_param_uint32(settings, FreeRDP_NlaSecurity, file->EnableCredSSPSupport); if (~((size_t) file->AlternateShell)) freerdp_set_param_string(settings, FreeRDP_AlternateShell, file->AlternateShell); if (~((size_t) file->ShellWorkingDirectory)) freerdp_set_param_string(settings, FreeRDP_ShellWorkingDirectory, file->ShellWorkingDirectory); if (~file->ScreenModeId) { /** * Screen Mode Id: * http://technet.microsoft.com/en-us/library/ff393692/ * * This setting corresponds to the selection in the Display * configuration slider on the Display tab under Options in RDC. * * Values: * * 0: The remote session will appear in a window. * 1: The remote session will appear full screen. */ freerdp_set_param_bool(settings, FreeRDP_Fullscreen, (file->ScreenModeId == 1) ? TRUE : FALSE); } if (~((size_t) file->LoadBalanceInfo)) { settings->LoadBalanceInfo = (BYTE*) _strdup(file->LoadBalanceInfo); settings->LoadBalanceInfoLength = strlen((char*) settings->LoadBalanceInfo); } if (~file->AuthenticationLevel) { /** * Authentication Level: * http://technet.microsoft.com/en-us/library/ff393709/ * * This setting corresponds to the selection in the If server authentication * fails drop-down list on the Advanced tab under Options in RDC. * * Values: * * 0: If server authentication fails, connect to the computer without warning (Connect and don’t warn me). * 1: If server authentication fails, do not establish a connection (Do not connect). * 2: If server authentication fails, show a warning and allow me to connect or refuse the connection (Warn me). * 3: No authentication requirement is specified. */ freerdp_set_param_bool(settings, FreeRDP_IgnoreCertificate, (file->AuthenticationLevel == 0) ? TRUE : FALSE); } if (~file->ConnectionType) freerdp_set_param_uint32(settings, FreeRDP_ConnectionType, file->ConnectionType); if (~file->AudioMode) { if (file->AudioMode == AUDIO_MODE_REDIRECT) { freerdp_set_param_bool(settings, FreeRDP_AudioPlayback, TRUE); } else if (file->AudioMode == AUDIO_MODE_PLAY_ON_SERVER) { freerdp_set_param_bool(settings, FreeRDP_RemoteConsoleAudio, TRUE); } else if (file->AudioMode == AUDIO_MODE_NONE) { freerdp_set_param_bool(settings, FreeRDP_AudioPlayback, FALSE); freerdp_set_param_bool(settings, FreeRDP_RemoteConsoleAudio, FALSE); } } if (~file->Compression) freerdp_set_param_bool(settings, FreeRDP_CompressionEnabled, file->Compression); if (~((size_t) file->GatewayHostname)) freerdp_set_param_string(settings, FreeRDP_GatewayHostname, file->GatewayHostname); if (~file->GatewayUsageMethod) { freerdp_set_param_uint32(settings, FreeRDP_GatewayUsageMethod, file->GatewayUsageMethod); if (file->GatewayUsageMethod == TSC_PROXY_MODE_DIRECT) freerdp_set_param_bool(settings, FreeRDP_GatewayEnabled, TRUE); else if (file->GatewayUsageMethod == TSC_PROXY_MODE_DETECT) freerdp_set_param_bool(settings, FreeRDP_GatewayEnabled, TRUE); else if (file->GatewayUsageMethod == TSC_PROXY_MODE_DEFAULT) freerdp_set_param_bool(settings, FreeRDP_GatewayEnabled, TRUE); else if (file->GatewayUsageMethod == TSC_PROXY_MODE_NONE_DETECT) freerdp_set_param_bool(settings, FreeRDP_GatewayEnabled, FALSE); } if (~file->PromptCredentialOnce) freerdp_set_param_bool(settings, FreeRDP_GatewayUseSameCredentials, TRUE); if (~file->RemoteApplicationMode) freerdp_set_param_bool(settings, FreeRDP_RemoteApplicationMode, file->RemoteApplicationMode); if (~((size_t) file->RemoteApplicationProgram)) freerdp_set_param_string(settings, FreeRDP_RemoteApplicationProgram, file->RemoteApplicationProgram); if (~((size_t) file->RemoteApplicationName)) freerdp_set_param_string(settings, FreeRDP_RemoteApplicationName, file->RemoteApplicationName); if (~((size_t) file->RemoteApplicationIcon)) freerdp_set_param_string(settings, FreeRDP_RemoteApplicationIcon, file->RemoteApplicationIcon); if (~((size_t) file->RemoteApplicationFile)) freerdp_set_param_string(settings, FreeRDP_RemoteApplicationGuid, file->RemoteApplicationGuid); if (~((size_t) file->RemoteApplicationGuid)) freerdp_set_param_string(settings, FreeRDP_RemoteApplicationGuid, file->RemoteApplicationGuid); if (~((size_t) file->RemoteApplicationCmdLine)) freerdp_set_param_string(settings, FreeRDP_RemoteApplicationCmdLine, file->RemoteApplicationCmdLine); if (~file->SpanMonitors) freerdp_set_param_bool(settings, FreeRDP_SpanMonitors, file->SpanMonitors); if (~file->UseMultiMon) freerdp_set_param_bool(settings, FreeRDP_UseMultimon, file->UseMultiMon); if (~file->AllowFontSmoothing) freerdp_set_param_bool(settings, FreeRDP_AllowFontSmoothing, file->AllowFontSmoothing); if (~file->DisableWallpaper) freerdp_set_param_bool(settings, FreeRDP_DisableWallpaper, file->DisableWallpaper); if (~file->DisableFullWindowDrag) freerdp_set_param_bool(settings, FreeRDP_DisableFullWindowDrag, file->DisableFullWindowDrag); if (~file->DisableMenuAnims) freerdp_set_param_bool(settings, FreeRDP_DisableMenuAnims, file->DisableMenuAnims); if (~file->DisableThemes) freerdp_set_param_bool(settings, FreeRDP_DisableThemes, file->DisableThemes); if (~file->AllowDesktopComposition) freerdp_set_param_bool(settings, FreeRDP_DisableCursorShadow, file->AllowDesktopComposition); if (~file->BitmapCachePersistEnable) freerdp_set_param_bool(settings, FreeRDP_BitmapCachePersistEnabled, file->BitmapCachePersistEnable); if (~file->DisableRemoteAppCapsCheck) freerdp_set_param_bool(settings, FreeRDP_DisableRemoteAppCapsCheck, file->DisableRemoteAppCapsCheck); if (~file->AutoReconnectionEnabled) freerdp_set_param_bool(settings, FreeRDP_AutoReconnectionEnabled, file->AutoReconnectionEnabled); if (~file->AutoReconnectMaxRetries) freerdp_set_param_uint32(settings, FreeRDP_AutoReconnectMaxRetries, file->AutoReconnectMaxRetries); if (~file->RedirectSmartCards) freerdp_set_param_bool(settings, FreeRDP_RedirectSmartCards, file->RedirectSmartCards); if (~file->RedirectClipboard) freerdp_set_param_bool(settings, FreeRDP_RedirectClipboard, file->RedirectClipboard); if (~file->RedirectPrinters) freerdp_set_param_bool(settings, FreeRDP_RedirectPrinters, file->RedirectPrinters); if (~file->RedirectDrives) freerdp_set_param_bool(settings, FreeRDP_RedirectDrives, file->RedirectDrives); if (~file->RedirectPosDevices) { freerdp_set_param_bool(settings, FreeRDP_RedirectSerialPorts, file->RedirectComPorts); freerdp_set_param_bool(settings, FreeRDP_RedirectParallelPorts, file->RedirectComPorts); } if (~file->RedirectComPorts) { freerdp_set_param_bool(settings, FreeRDP_RedirectSerialPorts, file->RedirectComPorts); freerdp_set_param_bool(settings, FreeRDP_RedirectParallelPorts, file->RedirectComPorts); } if (~file->RedirectDirectX) { /* What is this?! */ } if (~((size_t) file->DevicesToRedirect)) { /** * Devices to redirect: * http://technet.microsoft.com/en-us/library/ff393728/ * * This setting corresponds to the selections for Other supported Plug and Play * (PnP) devices under More on the Local Resources tab under Options in RDC. * * Values: * * '*': * Redirect all supported Plug and Play devices. * * 'DynamicDevices': * Redirect any supported Plug and Play devices that are connected later. * * The hardware ID for the supported Plug and Play device: * Redirect the specified supported Plug and Play device. * * Examples: * devicestoredirect:s:* * devicestoredirect:s:DynamicDevices * devicestoredirect:s:USB\VID_04A9&PID_30C1\6&4BD985D&0&2;,DynamicDevices * */ freerdp_set_param_bool(settings, FreeRDP_RedirectDrives, TRUE); } if (~((size_t) file->DrivesToRedirect)) { /* * Drives to redirect: * * Very similar to DevicesToRedirect, but can contain a * comma-separated list of drive letters to redirect. */ freerdp_set_param_bool(settings, FreeRDP_RedirectDrives, TRUE); } if (file->argc > 1) { freerdp_client_parse_command_line_arguments(file->argc, file->argv, settings); } return TRUE; }
INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { freerdp* instance; thread_data* data; WSADATA wsa_data; WNDCLASSEX wnd_cls; if (NULL == getenv("HOME")) { char home[MAX_PATH * 2] = "HOME="; strcat(home, getenv("HOMEDRIVE")); strcat(home, getenv("HOMEPATH")); _putenv(home); } if (WSAStartup(0x101, &wsa_data) != 0) return 1; g_done_event = CreateEvent(0, 1, 0, 0); #if defined(WITH_DEBUG) || defined(_DEBUG) wf_create_console(); #endif g_default_cursor = LoadCursor(NULL, IDC_ARROW); wnd_cls.cbSize = sizeof(WNDCLASSEX); wnd_cls.style = CS_HREDRAW | CS_VREDRAW; wnd_cls.lpfnWndProc = wf_event_proc; wnd_cls.cbClsExtra = 0; wnd_cls.cbWndExtra = 0; wnd_cls.hIcon = LoadIcon(NULL, IDI_APPLICATION); wnd_cls.hCursor = g_default_cursor; wnd_cls.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH); wnd_cls.lpszMenuName = NULL; wnd_cls.lpszClassName = g_wnd_class_name; wnd_cls.hInstance = hInstance; wnd_cls.hIconSm = LoadIcon(NULL, IDI_APPLICATION); RegisterClassEx(&wnd_cls); g_hInstance = hInstance; freerdp_channels_global_init(); instance = freerdp_new(); instance->PreConnect = wf_pre_connect; instance->PostConnect = wf_post_connect; instance->Authenticate = wf_authenticate; instance->VerifyCertificate = wf_verify_certificate; instance->ReceiveChannelData = wf_receive_channel_data; instance->context_size = sizeof(wfContext); instance->ContextNew = wf_context_new; instance->ContextFree = wf_context_free; freerdp_context_new(instance); instance->context->argc = __argc; instance->context->argv = __argv; if (!CreateThread(NULL, 0, kbd_thread_func, NULL, 0, NULL)) printf("error creating keyboard handler thread"); //while (1) { int status; data = (thread_data*) malloc(sizeof(thread_data)); ZeroMemory(data, sizeof(thread_data)); data->instance = instance; freerdp_register_addin_provider(freerdp_channels_load_static_addin_entry, 0); status = freerdp_client_parse_command_line_arguments(__argc, __argv, instance->settings); freerdp_client_load_addins(instance->context->channels, instance->settings); if (status < 0) { printf("failed to parse arguments.\n"); #ifdef _DEBUG system("pause"); #endif exit(-1); } if (CreateThread(NULL, 0, thread_func, data, 0, NULL) != 0) g_thread_count++; } if (g_thread_count > 0) WaitForSingleObject(g_done_event, INFINITE); else MessageBox(GetConsoleWindow(), L"Failed to start wfreerdp.\n\nPlease check the debug output.", L"FreeRDP Error", MB_ICONSTOP); freerdp_context_free(instance); freerdp_free(instance); WSACleanup(); #ifdef _DEBUG system("pause"); #endif return 0; }