2014-10-13 13:43:16 +04:00
|
|
|
/**
|
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
2014-11-17 18:36:28 +03:00
|
|
|
* Wayland Client
|
2014-10-13 13:43:16 +04:00
|
|
|
*
|
|
|
|
* Copyright 2014 Manuel Bachmann <tarnyko@tarnyko.net>
|
|
|
|
*
|
|
|
|
* 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 <errno.h>
|
|
|
|
|
|
|
|
#include <freerdp/client/cmdline.h>
|
|
|
|
#include <freerdp/channels/channels.h>
|
|
|
|
#include <freerdp/gdi/gdi.h>
|
|
|
|
|
2014-11-17 18:36:28 +03:00
|
|
|
#include "wlfreerdp.h"
|
2014-10-13 13:43:16 +04:00
|
|
|
|
2015-04-28 18:00:41 +03:00
|
|
|
static BOOL wl_context_new(freerdp* instance, rdpContext* context)
|
2014-10-13 13:43:16 +04:00
|
|
|
{
|
2015-04-28 18:00:41 +03:00
|
|
|
if (!(context->channels = freerdp_channels_new()))
|
|
|
|
return FALSE;
|
2014-10-13 13:43:16 +04:00
|
|
|
|
2015-04-28 18:00:41 +03:00
|
|
|
return TRUE;
|
2014-10-13 13:43:16 +04:00
|
|
|
}
|
|
|
|
|
2015-04-20 17:20:16 +03:00
|
|
|
static void wl_context_free(freerdp* instance, rdpContext* context)
|
2014-10-13 13:43:16 +04:00
|
|
|
{
|
2015-04-20 17:20:16 +03:00
|
|
|
if (context && context->channels)
|
|
|
|
{
|
|
|
|
freerdp_channels_close(context->channels, instance);
|
|
|
|
freerdp_channels_free(context->channels);
|
2015-04-28 18:00:41 +03:00
|
|
|
context->channels = NULL;
|
2015-04-20 17:20:16 +03:00
|
|
|
}
|
2014-10-13 13:43:16 +04:00
|
|
|
}
|
|
|
|
|
2015-04-20 17:20:16 +03:00
|
|
|
static BOOL wl_begin_paint(rdpContext* context)
|
2014-10-13 13:43:16 +04:00
|
|
|
{
|
|
|
|
rdpGdi* gdi;
|
|
|
|
|
|
|
|
gdi = context->gdi;
|
|
|
|
gdi->primary->hdc->hwnd->invalid->null = 1;
|
2015-04-14 11:14:23 +03:00
|
|
|
return TRUE;
|
2014-10-13 13:43:16 +04:00
|
|
|
}
|
|
|
|
|
2015-04-20 17:20:16 +03:00
|
|
|
static BOOL wl_end_paint(rdpContext* context)
|
2014-10-13 13:43:16 +04:00
|
|
|
{
|
|
|
|
rdpGdi* gdi;
|
2014-11-17 18:36:28 +03:00
|
|
|
wlfDisplay* display;
|
|
|
|
wlfWindow* window;
|
|
|
|
wlfContext* context_w;
|
2014-11-26 12:38:12 +03:00
|
|
|
INT32 x, y;
|
|
|
|
UINT32 w, h;
|
|
|
|
int i;
|
2014-10-13 13:43:16 +04:00
|
|
|
|
|
|
|
gdi = context->gdi;
|
|
|
|
if (gdi->primary->hdc->hwnd->invalid->null)
|
2015-04-14 11:14:23 +03:00
|
|
|
return TRUE;
|
2014-10-13 13:43:16 +04:00
|
|
|
|
2014-11-26 12:38:12 +03:00
|
|
|
x = gdi->primary->hdc->hwnd->invalid->x;
|
|
|
|
y = gdi->primary->hdc->hwnd->invalid->y;
|
|
|
|
w = gdi->primary->hdc->hwnd->invalid->w;
|
|
|
|
h = gdi->primary->hdc->hwnd->invalid->h;
|
|
|
|
|
2014-11-17 18:36:28 +03:00
|
|
|
context_w = (wlfContext*) context;
|
2014-10-13 13:43:16 +04:00
|
|
|
display = context_w->display;
|
|
|
|
window = context_w->window;
|
|
|
|
|
2014-11-26 12:38:12 +03:00
|
|
|
for (i = 0; i < h; i++)
|
|
|
|
memcpy(window->data + ((i+y)*(gdi->width*4)) + x*4,
|
|
|
|
gdi->primary_buffer + ((i+y)*(gdi->width*4)) + x*4,
|
|
|
|
w*4);
|
2014-11-17 18:36:28 +03:00
|
|
|
|
2015-04-14 11:14:23 +03:00
|
|
|
return wlf_RefreshDisplay(display);
|
2014-10-13 13:43:16 +04:00
|
|
|
}
|
|
|
|
|
2015-04-20 17:20:16 +03:00
|
|
|
static BOOL wl_pre_connect(freerdp* instance)
|
2014-10-13 13:43:16 +04:00
|
|
|
{
|
2014-11-17 18:36:28 +03:00
|
|
|
wlfDisplay* display;
|
|
|
|
wlfInput* input;
|
|
|
|
wlfContext* context;
|
2014-10-13 13:43:16 +04:00
|
|
|
|
2015-04-20 17:20:16 +03:00
|
|
|
if (freerdp_channels_pre_connect(instance->context->channels, instance))
|
|
|
|
return FALSE;
|
2014-10-13 13:43:16 +04:00
|
|
|
|
2014-11-17 18:36:28 +03:00
|
|
|
context = (wlfContext*) instance->context;
|
2015-04-20 17:20:16 +03:00
|
|
|
if (!context)
|
|
|
|
return FALSE;
|
2014-10-13 13:43:16 +04:00
|
|
|
|
2014-11-17 18:36:28 +03:00
|
|
|
display = wlf_CreateDisplay();
|
2015-04-20 17:20:16 +03:00
|
|
|
if (!display)
|
|
|
|
return FALSE;
|
|
|
|
|
2014-10-13 13:43:16 +04:00
|
|
|
context->display = display;
|
|
|
|
|
2014-11-17 18:36:28 +03:00
|
|
|
input = wlf_CreateInput(context);
|
2015-04-20 17:20:16 +03:00
|
|
|
if (!input)
|
|
|
|
return FALSE;
|
|
|
|
|
2014-11-17 18:36:28 +03:00
|
|
|
context->input = input;
|
|
|
|
|
2014-10-13 13:43:16 +04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2015-04-20 17:20:16 +03:00
|
|
|
static BOOL wl_post_connect(freerdp* instance)
|
2014-10-13 13:43:16 +04:00
|
|
|
{
|
|
|
|
rdpGdi* gdi;
|
2014-11-17 18:36:28 +03:00
|
|
|
wlfWindow* window;
|
|
|
|
wlfContext* context;
|
2014-10-13 13:43:16 +04:00
|
|
|
|
2015-05-08 22:39:23 +03:00
|
|
|
if (!gdi_init(instance, CLRCONV_ALPHA | CLRBUF_32BPP, NULL))
|
|
|
|
return FALSE;
|
|
|
|
|
2014-10-13 13:43:16 +04:00
|
|
|
gdi = instance->context->gdi;
|
2015-04-20 17:20:16 +03:00
|
|
|
if (!gdi)
|
|
|
|
return FALSE;
|
2014-10-13 13:43:16 +04:00
|
|
|
|
2014-11-17 18:36:28 +03:00
|
|
|
context = (wlfContext*) instance->context;
|
|
|
|
window = wlf_CreateDesktopWindow(context, "FreeRDP", gdi->width, gdi->height, FALSE);
|
2015-04-20 17:20:16 +03:00
|
|
|
if (!window)
|
|
|
|
return FALSE;
|
2014-11-17 18:36:28 +03:00
|
|
|
|
2014-10-13 13:43:16 +04:00
|
|
|
/* fill buffer with first image here */
|
|
|
|
window->data = malloc (gdi->width * gdi->height *4);
|
2015-04-20 17:20:16 +03:00
|
|
|
if (!window->data)
|
|
|
|
return FALSE;
|
|
|
|
|
2014-10-13 13:43:16 +04:00
|
|
|
memcpy(window->data, (void*) gdi->primary_buffer, gdi->width * gdi->height * 4);
|
|
|
|
instance->update->BeginPaint = wl_begin_paint;
|
|
|
|
instance->update->EndPaint = wl_end_paint;
|
|
|
|
|
|
|
|
/* put Wayland data in the context here */
|
|
|
|
context->window = window;
|
|
|
|
|
2015-04-20 17:20:16 +03:00
|
|
|
if (freerdp_channels_post_connect(instance->context->channels, instance))
|
|
|
|
return FALSE;
|
2014-10-13 13:43:16 +04:00
|
|
|
|
2014-11-17 18:36:28 +03:00
|
|
|
wlf_UpdateWindowArea(context, window, 0, 0, gdi->width, gdi->height);
|
2014-10-13 13:43:16 +04:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2015-04-20 17:20:16 +03:00
|
|
|
static void wl_post_disconnect(freerdp* instance)
|
|
|
|
{
|
|
|
|
wlfContext *context;
|
|
|
|
if (!instance)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!instance->context)
|
|
|
|
return;
|
|
|
|
|
|
|
|
context = (wlfContext*) instance->context;
|
|
|
|
|
|
|
|
if (context->display)
|
|
|
|
wlf_DestroyDisplay(context, context->display);
|
|
|
|
|
|
|
|
if (context->input)
|
|
|
|
wlf_DestroyInput(context, context->input);
|
|
|
|
|
|
|
|
gdi_free(instance);
|
|
|
|
if (context->window)
|
|
|
|
wlf_DestroyWindow(context, context->window);
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL wl_verify_certificate(freerdp* instance, char* subject, char* issuer, char* fingerprint)
|
2014-11-12 18:59:17 +03:00
|
|
|
{
|
|
|
|
char answer;
|
|
|
|
|
|
|
|
printf("Certificate details:\n");
|
|
|
|
printf("\tSubject: %s\n", subject);
|
|
|
|
printf("\tIssuer: %s\n", issuer);
|
|
|
|
printf("\tThumbprint: %s\n", fingerprint);
|
|
|
|
printf("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");
|
|
|
|
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
printf("Do you trust the above certificate? (Y/N) ");
|
|
|
|
answer = fgetc(stdin);
|
|
|
|
|
|
|
|
if (feof(stdin))
|
|
|
|
{
|
|
|
|
printf("\nError: Could not read answer from stdin.");
|
|
|
|
if (instance->settings->CredentialsFromStdin)
|
|
|
|
printf(" - Run without parameter \"--from-stdin\" to set trust.");
|
|
|
|
printf("\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (answer == 'y' || answer == 'Y')
|
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
else if (answer == 'n' || answer == 'N')
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2015-04-22 12:05:29 +03:00
|
|
|
static int wlfreerdp_run(freerdp* instance)
|
2014-10-13 13:43:16 +04:00
|
|
|
{
|
2015-04-22 12:05:29 +03:00
|
|
|
DWORD count;
|
|
|
|
HANDLE handles[64];
|
|
|
|
DWORD status;
|
2014-10-13 13:43:16 +04:00
|
|
|
|
2015-04-22 12:05:29 +03:00
|
|
|
if (!freerdp_connect(instance))
|
|
|
|
{
|
|
|
|
printf("Failed to connect\n");
|
|
|
|
return -1;
|
|
|
|
}
|
2014-10-13 13:43:16 +04:00
|
|
|
|
2015-04-22 12:05:29 +03:00
|
|
|
while (!freerdp_shall_disconnect(instance))
|
2014-10-13 13:43:16 +04:00
|
|
|
{
|
2015-04-22 12:05:29 +03:00
|
|
|
count = freerdp_get_event_handles(instance->context, handles, 64);
|
|
|
|
if (!count)
|
2014-10-13 13:43:16 +04:00
|
|
|
{
|
2015-04-22 12:05:29 +03:00
|
|
|
printf("Failed to get FreeRDP file descriptor\n");
|
2014-10-13 13:43:16 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-04-22 12:05:29 +03:00
|
|
|
status = WaitForMultipleObjects(count, handles, FALSE, INFINITE);
|
|
|
|
if (WAIT_FAILED == status)
|
2014-10-13 13:43:16 +04:00
|
|
|
{
|
2015-04-22 12:05:29 +03:00
|
|
|
printf("%s: WaitForMultipleObjects failed\n", __FUNCTION__);
|
2014-10-13 13:43:16 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-04-22 12:05:29 +03:00
|
|
|
if (freerdp_check_event_handles(instance->context) != TRUE)
|
2014-10-13 13:43:16 +04:00
|
|
|
{
|
|
|
|
printf("Failed to check FreeRDP file descriptor\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-20 13:24:36 +03:00
|
|
|
freerdp_channels_disconnect(instance->context->channels, instance);
|
|
|
|
freerdp_disconnect(instance);
|
|
|
|
|
2014-10-13 13:43:16 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char* argv[])
|
|
|
|
{
|
|
|
|
int status;
|
|
|
|
freerdp* instance;
|
|
|
|
|
|
|
|
instance = freerdp_new();
|
|
|
|
instance->PreConnect = wl_pre_connect;
|
|
|
|
instance->PostConnect = wl_post_connect;
|
2015-04-20 17:20:16 +03:00
|
|
|
instance->PostDisconnect = wl_post_disconnect;
|
2014-11-12 18:59:17 +03:00
|
|
|
instance->VerifyCertificate = wl_verify_certificate;
|
2014-10-13 13:43:16 +04:00
|
|
|
|
2014-11-17 18:36:28 +03:00
|
|
|
instance->ContextSize = sizeof(wlfContext);
|
2014-10-13 13:43:16 +04:00
|
|
|
instance->ContextNew = wl_context_new;
|
|
|
|
instance->ContextFree = wl_context_free;
|
2015-04-20 17:20:16 +03:00
|
|
|
|
2014-10-13 13:43:16 +04:00
|
|
|
freerdp_context_new(instance);
|
|
|
|
|
2015-03-16 12:15:37 +03:00
|
|
|
status = freerdp_client_settings_parse_command_line_arguments(instance->settings, argc, argv, FALSE);
|
2014-10-16 17:44:48 +04:00
|
|
|
|
2014-11-17 18:56:40 +03:00
|
|
|
status = freerdp_client_settings_command_line_status_print(instance->settings, status, argc, argv);
|
2014-10-13 13:43:16 +04:00
|
|
|
|
2014-10-16 17:44:48 +04:00
|
|
|
if (status)
|
2014-10-13 13:43:16 +04:00
|
|
|
exit(0);
|
|
|
|
|
|
|
|
freerdp_client_load_addins(instance->context->channels, instance->settings);
|
|
|
|
|
|
|
|
wlfreerdp_run(instance);
|
|
|
|
|
2015-04-20 17:20:16 +03:00
|
|
|
freerdp_context_free(instance);
|
|
|
|
|
|
|
|
freerdp_free(instance);
|
|
|
|
|
2014-10-13 13:43:16 +04:00
|
|
|
return 0;
|
|
|
|
}
|