2011-07-28 21:46:36 +04:00
|
|
|
/**
|
2012-10-09 07:02:04 +04:00
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
2011-07-28 21:46:36 +04:00
|
|
|
* DirectFB Client
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2011-07-29 01:44:09 +04:00
|
|
|
#include <errno.h>
|
2011-07-28 21:46:36 +04:00
|
|
|
#include <pthread.h>
|
2011-08-09 04:31:21 +04:00
|
|
|
#include <locale.h>
|
2012-09-19 03:40:54 +04:00
|
|
|
|
|
|
|
#include <freerdp/freerdp.h>
|
2011-08-03 09:59:12 +04:00
|
|
|
#include <freerdp/constants.h>
|
2012-11-26 21:49:21 +04:00
|
|
|
#include <freerdp/utils/event.h>
|
2014-09-12 19:13:01 +04:00
|
|
|
|
2012-11-26 21:49:21 +04:00
|
|
|
#include <freerdp/client/file.h>
|
|
|
|
#include <freerdp/client/cmdline.h>
|
2012-10-09 20:38:18 +04:00
|
|
|
#include <freerdp/client/channels.h>
|
2012-10-09 04:33:58 +04:00
|
|
|
#include <freerdp/client/cliprdr.h>
|
2011-07-28 21:46:36 +04:00
|
|
|
|
2012-11-20 08:49:08 +04:00
|
|
|
#include <winpr/crt.h>
|
2012-09-19 03:40:54 +04:00
|
|
|
#include <winpr/synch.h>
|
|
|
|
|
2011-07-29 01:44:09 +04:00
|
|
|
#include "df_event.h"
|
2011-11-12 03:34:06 +04:00
|
|
|
#include "df_graphics.h"
|
2011-07-29 01:44:09 +04:00
|
|
|
|
2011-07-28 21:46:36 +04:00
|
|
|
#include "dfreerdp.h"
|
|
|
|
|
2014-09-12 19:13:01 +04:00
|
|
|
#include <freerdp/log.h>
|
|
|
|
#define TAG CLIENT_TAG("directFB")
|
|
|
|
|
2012-09-19 03:40:54 +04:00
|
|
|
static HANDLE g_sem;
|
2011-07-28 21:46:36 +04:00
|
|
|
static int g_thread_count = 0;
|
|
|
|
|
|
|
|
struct thread_data
|
|
|
|
{
|
|
|
|
freerdp* instance;
|
|
|
|
};
|
|
|
|
|
2013-06-14 05:34:46 +04:00
|
|
|
int df_context_new(freerdp* instance, rdpContext* context)
|
2011-10-16 08:50:10 +04:00
|
|
|
{
|
2011-10-21 07:15:18 +04:00
|
|
|
context->channels = freerdp_channels_new();
|
2013-06-14 05:34:46 +04:00
|
|
|
return 0;
|
2011-10-16 08:50:10 +04:00
|
|
|
}
|
|
|
|
|
2011-10-21 07:15:18 +04:00
|
|
|
void df_context_free(freerdp* instance, rdpContext* context)
|
2011-07-28 21:46:36 +04:00
|
|
|
{
|
|
|
|
|
2011-10-16 08:50:10 +04:00
|
|
|
}
|
|
|
|
|
2011-11-22 04:41:49 +04:00
|
|
|
void df_begin_paint(rdpContext* context)
|
2011-10-16 08:50:10 +04:00
|
|
|
{
|
2011-11-22 04:41:49 +04:00
|
|
|
rdpGdi* gdi = context->gdi;
|
2011-07-28 21:46:36 +04:00
|
|
|
gdi->primary->hdc->hwnd->invalid->null = 1;
|
|
|
|
}
|
|
|
|
|
2011-11-22 04:41:49 +04:00
|
|
|
void df_end_paint(rdpContext* context)
|
2011-07-28 21:46:36 +04:00
|
|
|
{
|
2011-10-16 08:50:10 +04:00
|
|
|
rdpGdi* gdi;
|
2011-07-28 21:46:36 +04:00
|
|
|
dfInfo* dfi;
|
|
|
|
|
2011-11-22 04:41:49 +04:00
|
|
|
gdi = context->gdi;
|
|
|
|
dfi = ((dfContext*) context)->dfi;
|
2011-07-28 21:46:36 +04:00
|
|
|
|
|
|
|
if (gdi->primary->hdc->hwnd->invalid->null)
|
2011-07-28 22:32:16 +04:00
|
|
|
return;
|
2011-07-28 21:46:36 +04:00
|
|
|
|
2011-08-06 00:56:40 +04:00
|
|
|
#if 1
|
2011-07-28 21:46:36 +04:00
|
|
|
dfi->update_rect.x = gdi->primary->hdc->hwnd->invalid->x;
|
|
|
|
dfi->update_rect.y = gdi->primary->hdc->hwnd->invalid->y;
|
|
|
|
dfi->update_rect.w = gdi->primary->hdc->hwnd->invalid->w;
|
|
|
|
dfi->update_rect.h = gdi->primary->hdc->hwnd->invalid->h;
|
2011-08-06 00:56:40 +04:00
|
|
|
#else
|
|
|
|
dfi->update_rect.x = 0;
|
|
|
|
dfi->update_rect.y = 0;
|
|
|
|
dfi->update_rect.w = gdi->width;
|
|
|
|
dfi->update_rect.h = gdi->height;
|
|
|
|
#endif
|
2011-07-28 21:46:36 +04:00
|
|
|
|
|
|
|
dfi->primary->Blit(dfi->primary, dfi->surface, &(dfi->update_rect), dfi->update_rect.x, dfi->update_rect.y);
|
|
|
|
}
|
|
|
|
|
2012-10-09 10:38:39 +04:00
|
|
|
BOOL df_get_fds(freerdp* instance, void** rfds, int* rcount, void** wfds, int* wcount)
|
2011-07-28 21:46:36 +04:00
|
|
|
{
|
2011-07-29 01:44:09 +04:00
|
|
|
dfInfo* dfi;
|
|
|
|
|
2011-10-16 08:50:10 +04:00
|
|
|
dfi = ((dfContext*) instance->context)->dfi;
|
2011-07-29 01:44:09 +04:00
|
|
|
|
|
|
|
rfds[*rcount] = (void*)(long)(dfi->read_fds);
|
|
|
|
(*rcount)++;
|
|
|
|
|
2012-10-09 10:31:28 +04:00
|
|
|
return TRUE;
|
2011-07-28 21:46:36 +04:00
|
|
|
}
|
|
|
|
|
2012-10-09 10:38:39 +04:00
|
|
|
BOOL df_check_fds(freerdp* instance, fd_set* set)
|
2011-07-28 21:46:36 +04:00
|
|
|
{
|
2011-07-29 01:44:09 +04:00
|
|
|
dfInfo* dfi;
|
|
|
|
|
2011-10-16 08:50:10 +04:00
|
|
|
dfi = ((dfContext*) instance->context)->dfi;
|
2011-07-29 01:44:09 +04:00
|
|
|
|
|
|
|
if (!FD_ISSET(dfi->read_fds, set))
|
2012-10-09 10:31:28 +04:00
|
|
|
return TRUE;
|
2011-07-29 01:44:09 +04:00
|
|
|
|
|
|
|
if (read(dfi->read_fds, &(dfi->event), sizeof(dfi->event)) > 0)
|
|
|
|
df_event_process(instance, &(dfi->event));
|
|
|
|
|
2012-10-09 10:31:28 +04:00
|
|
|
return TRUE;
|
2011-07-28 21:46:36 +04:00
|
|
|
}
|
|
|
|
|
2012-10-09 10:38:39 +04:00
|
|
|
BOOL df_pre_connect(freerdp* instance)
|
2011-07-28 21:46:36 +04:00
|
|
|
{
|
|
|
|
dfInfo* dfi;
|
2012-10-09 10:38:39 +04:00
|
|
|
BOOL bitmap_cache;
|
2011-10-16 08:50:10 +04:00
|
|
|
dfContext* context;
|
2011-08-05 00:22:15 +04:00
|
|
|
rdpSettings* settings;
|
2011-07-28 21:46:36 +04:00
|
|
|
|
2012-11-20 08:49:08 +04:00
|
|
|
dfi = (dfInfo*) malloc(sizeof(dfInfo));
|
|
|
|
ZeroMemory(dfi, sizeof(dfInfo));
|
|
|
|
|
2011-10-16 08:50:10 +04:00
|
|
|
context = ((dfContext*) instance->context);
|
|
|
|
context->dfi = dfi;
|
2011-07-28 21:46:36 +04:00
|
|
|
|
2011-08-05 00:22:15 +04:00
|
|
|
settings = instance->settings;
|
2012-11-08 00:13:14 +04:00
|
|
|
bitmap_cache = settings->BitmapCacheEnabled;
|
|
|
|
|
|
|
|
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] = 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] = FALSE;
|
|
|
|
settings->OrderSupport[NEG_FAST_INDEX_INDEX] = FALSE;
|
|
|
|
settings->OrderSupport[NEG_FAST_GLYPH_INDEX] = FALSE;
|
|
|
|
settings->OrderSupport[NEG_POLYGON_SC_INDEX] = FALSE;
|
|
|
|
settings->OrderSupport[NEG_POLYGON_CB_INDEX] = FALSE;
|
|
|
|
settings->OrderSupport[NEG_ELLIPSE_SC_INDEX] = FALSE;
|
|
|
|
settings->OrderSupport[NEG_ELLIPSE_CB_INDEX] = FALSE;
|
2011-08-05 00:22:15 +04:00
|
|
|
|
2012-11-22 05:21:08 +04:00
|
|
|
dfi->clrconv = (CLRCONV*) malloc(sizeof(CLRCONV));
|
|
|
|
ZeroMemory(dfi->clrconv, sizeof(CLRCONV));
|
|
|
|
|
2011-11-12 03:34:06 +04:00
|
|
|
dfi->clrconv->alpha = 1;
|
|
|
|
dfi->clrconv->invert = 0;
|
|
|
|
dfi->clrconv->rgb555 = 0;
|
2012-11-22 05:21:08 +04:00
|
|
|
|
|
|
|
dfi->clrconv->palette = (rdpPalette*) malloc(sizeof(rdpPalette));
|
|
|
|
ZeroMemory(dfi->clrconv->palette, sizeof(rdpPalette));
|
2011-11-12 03:34:06 +04:00
|
|
|
|
2011-10-17 04:10:09 +04:00
|
|
|
freerdp_channels_pre_connect(instance->context->channels, instance);
|
2012-10-09 20:38:18 +04:00
|
|
|
|
|
|
|
instance->context->cache = cache_new(instance->settings);
|
2011-08-02 12:04:30 +04:00
|
|
|
|
2012-10-09 10:31:28 +04:00
|
|
|
return TRUE;
|
2011-07-28 21:46:36 +04:00
|
|
|
}
|
|
|
|
|
2012-10-09 10:38:39 +04:00
|
|
|
BOOL df_post_connect(freerdp* instance)
|
2011-07-28 21:46:36 +04:00
|
|
|
{
|
2011-10-16 08:50:10 +04:00
|
|
|
rdpGdi* gdi;
|
2011-07-28 21:46:36 +04:00
|
|
|
dfInfo* dfi;
|
2011-10-16 08:50:10 +04:00
|
|
|
dfContext* context;
|
2011-07-28 21:46:36 +04:00
|
|
|
|
2011-10-16 08:50:10 +04:00
|
|
|
context = ((dfContext*) instance->context);
|
|
|
|
dfi = context->dfi;
|
2011-07-28 21:46:36 +04:00
|
|
|
|
2011-12-13 20:36:05 +04:00
|
|
|
gdi_init(instance, CLRCONV_ALPHA | CLRCONV_INVERT | CLRBUF_16BPP | CLRBUF_32BPP, NULL);
|
2011-10-16 08:50:10 +04:00
|
|
|
gdi = instance->context->gdi;
|
2011-07-28 21:46:36 +04:00
|
|
|
|
|
|
|
dfi->err = DirectFBCreate(&(dfi->dfb));
|
|
|
|
|
|
|
|
dfi->dsc.flags = DSDESC_CAPS;
|
|
|
|
dfi->dsc.caps = DSCAPS_PRIMARY;
|
|
|
|
dfi->err = dfi->dfb->CreateSurface(dfi->dfb, &(dfi->dsc), &(dfi->primary));
|
|
|
|
dfi->err = dfi->primary->GetSize(dfi->primary, &(gdi->width), &(gdi->height));
|
|
|
|
dfi->dfb->SetVideoMode(dfi->dfb, gdi->width, gdi->height, gdi->dstBpp);
|
|
|
|
dfi->dfb->CreateInputEventBuffer(dfi->dfb, DICAPS_ALL, DFB_TRUE, &(dfi->event_buffer));
|
|
|
|
dfi->event_buffer->CreateFileDescriptor(dfi->event_buffer, &(dfi->read_fds));
|
|
|
|
|
|
|
|
dfi->dfb->GetDisplayLayer(dfi->dfb, 0, &(dfi->layer));
|
|
|
|
dfi->layer->EnableCursor(dfi->layer, 1);
|
|
|
|
|
|
|
|
dfi->dsc.flags = DSDESC_CAPS | DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_PREALLOCATED | DSDESC_PIXELFORMAT;
|
|
|
|
dfi->dsc.caps = DSCAPS_SYSTEMONLY;
|
|
|
|
dfi->dsc.width = gdi->width;
|
|
|
|
dfi->dsc.height = gdi->height;
|
|
|
|
|
|
|
|
if (gdi->dstBpp == 32 || gdi->dstBpp == 24)
|
|
|
|
dfi->dsc.pixelformat = DSPF_AiRGB;
|
|
|
|
else if (gdi->dstBpp == 16 || gdi->dstBpp == 15)
|
|
|
|
dfi->dsc.pixelformat = DSPF_RGB16;
|
|
|
|
else if (gdi->dstBpp == 8)
|
|
|
|
dfi->dsc.pixelformat = DSPF_RGB332;
|
|
|
|
else
|
|
|
|
dfi->dsc.pixelformat = DSPF_AiRGB;
|
|
|
|
|
|
|
|
dfi->dsc.preallocated[0].data = gdi->primary_buffer;
|
|
|
|
dfi->dsc.preallocated[0].pitch = gdi->width * gdi->bytesPerPixel;
|
|
|
|
dfi->dfb->CreateSurface(dfi->dfb, &(dfi->dsc), &(dfi->surface));
|
|
|
|
|
|
|
|
instance->update->BeginPaint = df_begin_paint;
|
|
|
|
instance->update->EndPaint = df_end_paint;
|
|
|
|
|
2011-08-01 20:24:29 +04:00
|
|
|
df_keyboard_init();
|
|
|
|
|
2011-11-12 03:34:06 +04:00
|
|
|
pointer_cache_register_callbacks(instance->update);
|
|
|
|
df_register_graphics(instance->context->graphics);
|
|
|
|
|
2011-10-17 04:10:09 +04:00
|
|
|
freerdp_channels_post_connect(instance->context->channels, instance);
|
2011-08-02 12:04:30 +04:00
|
|
|
|
2012-10-09 10:31:28 +04:00
|
|
|
return TRUE;
|
2011-07-28 21:46:36 +04:00
|
|
|
}
|
|
|
|
|
2012-10-09 10:38:39 +04:00
|
|
|
BOOL df_verify_certificate(freerdp* instance, char* subject, char* issuer, char* fingerprint)
|
2011-10-18 19:02:05 +04:00
|
|
|
{
|
2012-11-26 21:49:21 +04:00
|
|
|
char answer;
|
2014-09-12 19:13:01 +04:00
|
|
|
WLog_INFO(TAG, "Certificate details:");
|
|
|
|
WLog_INFO(TAG, "\tSubject: %s", subject);
|
|
|
|
WLog_INFO(TAG, "\tIssuer: %s", issuer);
|
|
|
|
WLog_INFO(TAG, "\tThumbprint: %s", fingerprint);
|
|
|
|
WLog_INFO(TAG, "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.");
|
2011-10-18 19:02:05 +04:00
|
|
|
|
|
|
|
while (1)
|
|
|
|
{
|
2014-09-12 19:13:01 +04:00
|
|
|
WLog_INFO(TAG, "Do you trust the above certificate? (Y/N) ");
|
2011-10-18 19:02:05 +04:00
|
|
|
answer = fgetc(stdin);
|
|
|
|
|
|
|
|
if (answer == 'y' || answer == 'Y')
|
|
|
|
{
|
2012-10-09 10:31:28 +04:00
|
|
|
return TRUE;
|
2011-10-18 19:02:05 +04:00
|
|
|
}
|
|
|
|
else if (answer == 'n' || answer == 'N')
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2011-10-18 19:02:05 +04:00
|
|
|
}
|
|
|
|
|
2014-09-12 19:39:21 +04:00
|
|
|
static int df_receive_channel_data(freerdp* instance, UINT16 channelId, BYTE* data, int size, int flags, int total_size)
|
2011-08-03 07:01:20 +04:00
|
|
|
{
|
2011-10-16 22:57:15 +04:00
|
|
|
return freerdp_channels_data(instance, channelId, data, size, flags, total_size);
|
2011-08-03 07:01:20 +04:00
|
|
|
}
|
|
|
|
|
2012-10-09 20:38:18 +04:00
|
|
|
static void df_process_cb_monitor_ready_event(rdpChannels* channels, freerdp* instance)
|
2011-08-03 09:59:12 +04:00
|
|
|
{
|
2013-03-29 05:13:56 +04:00
|
|
|
wMessage* event;
|
2011-08-18 01:28:26 +04:00
|
|
|
RDP_CB_FORMAT_LIST_EVENT* format_list_event;
|
2011-08-03 09:59:12 +04:00
|
|
|
|
2013-03-29 02:29:57 +04:00
|
|
|
event = freerdp_event_new(CliprdrChannel_Class, CliprdrChannel_FormatList, NULL, NULL);
|
2011-08-03 09:59:12 +04:00
|
|
|
|
2013-03-29 02:29:57 +04:00
|
|
|
format_list_event = (RDP_CB_FORMAT_LIST_EVENT*) event;
|
2011-08-03 09:59:12 +04:00
|
|
|
format_list_event->num_formats = 0;
|
|
|
|
|
2011-10-17 05:39:11 +04:00
|
|
|
freerdp_channels_send_event(channels, event);
|
2011-08-03 09:59:12 +04:00
|
|
|
}
|
|
|
|
|
2012-10-09 20:38:18 +04:00
|
|
|
static void df_process_channel_event(rdpChannels* channels, freerdp* instance)
|
2011-08-03 09:59:12 +04:00
|
|
|
{
|
2013-03-29 05:13:56 +04:00
|
|
|
wMessage* event;
|
2011-08-03 09:59:12 +04:00
|
|
|
|
2011-10-17 05:39:11 +04:00
|
|
|
event = freerdp_channels_pop_event(channels);
|
2011-10-16 08:50:10 +04:00
|
|
|
|
2011-08-03 09:59:12 +04:00
|
|
|
if (event)
|
|
|
|
{
|
2013-03-29 02:29:57 +04:00
|
|
|
switch (GetMessageType(event->id))
|
2011-08-03 09:59:12 +04:00
|
|
|
{
|
2013-03-29 02:29:57 +04:00
|
|
|
case CliprdrChannel_MonitorReady:
|
2011-11-01 03:15:27 +04:00
|
|
|
df_process_cb_monitor_ready_event(channels, instance);
|
2011-08-03 09:59:12 +04:00
|
|
|
break;
|
2013-03-29 02:29:57 +04:00
|
|
|
|
2011-08-03 09:59:12 +04:00
|
|
|
default:
|
2014-09-12 19:13:01 +04:00
|
|
|
WLog_ERR(TAG, "df_process_channel_event: unknown event type %d", GetMessageType(event->id));
|
2011-08-03 09:59:12 +04:00
|
|
|
break;
|
|
|
|
}
|
2011-10-16 08:50:10 +04:00
|
|
|
|
2011-08-03 09:59:12 +04:00
|
|
|
freerdp_event_free(event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-13 08:12:20 +04:00
|
|
|
static void df_free(dfInfo* dfi)
|
|
|
|
{
|
|
|
|
dfi->dfb->Release(dfi->dfb);
|
2012-10-09 07:21:26 +04:00
|
|
|
free(dfi);
|
2011-08-13 08:12:20 +04:00
|
|
|
}
|
|
|
|
|
2011-07-28 21:46:36 +04:00
|
|
|
int dfreerdp_run(freerdp* instance)
|
|
|
|
{
|
2011-07-29 01:44:09 +04:00
|
|
|
int i;
|
|
|
|
int fds;
|
|
|
|
int max_fds;
|
2011-07-28 21:46:36 +04:00
|
|
|
int rcount;
|
|
|
|
int wcount;
|
|
|
|
void* rfds[32];
|
|
|
|
void* wfds[32];
|
|
|
|
fd_set rfds_set;
|
|
|
|
fd_set wfds_set;
|
2011-08-10 18:51:55 +04:00
|
|
|
dfInfo* dfi;
|
2011-10-16 08:50:10 +04:00
|
|
|
dfContext* context;
|
2011-10-17 04:10:09 +04:00
|
|
|
rdpChannels* channels;
|
2011-07-28 21:46:36 +04:00
|
|
|
|
2013-03-29 02:29:57 +04:00
|
|
|
ZeroMemory(rfds, sizeof(rfds));
|
|
|
|
ZeroMemory(wfds, sizeof(wfds));
|
2011-07-28 21:46:36 +04:00
|
|
|
|
2011-10-17 05:02:28 +04:00
|
|
|
if (!freerdp_connect(instance))
|
2011-08-22 13:42:16 +04:00
|
|
|
return 0;
|
2011-08-13 08:12:20 +04:00
|
|
|
|
2011-10-16 08:50:10 +04:00
|
|
|
context = (dfContext*) instance->context;
|
|
|
|
|
|
|
|
dfi = context->dfi;
|
2011-10-17 04:10:09 +04:00
|
|
|
channels = instance->context->channels;
|
2011-08-03 07:01:20 +04:00
|
|
|
|
2011-07-29 01:44:09 +04:00
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
rcount = 0;
|
|
|
|
wcount = 0;
|
|
|
|
|
2012-10-09 10:31:28 +04:00
|
|
|
if (freerdp_get_fds(instance, rfds, &rcount, wfds, &wcount) != TRUE)
|
2011-07-29 01:44:09 +04:00
|
|
|
{
|
2014-09-12 19:13:01 +04:00
|
|
|
WLog_ERR(TAG, "Failed to get FreeRDP file descriptor");
|
2011-07-29 01:44:09 +04:00
|
|
|
break;
|
|
|
|
}
|
2012-10-09 10:31:28 +04:00
|
|
|
if (freerdp_channels_get_fds(channels, instance, rfds, &rcount, wfds, &wcount) != TRUE)
|
2011-08-03 07:01:20 +04:00
|
|
|
{
|
2014-09-12 19:13:01 +04:00
|
|
|
WLog_ERR(TAG, "Failed to get channel manager file descriptor");
|
2011-08-03 07:01:20 +04:00
|
|
|
break;
|
|
|
|
}
|
2012-10-09 10:31:28 +04:00
|
|
|
if (df_get_fds(instance, rfds, &rcount, wfds, &wcount) != TRUE)
|
2011-07-29 01:44:09 +04:00
|
|
|
{
|
2014-09-12 19:13:01 +04:00
|
|
|
WLog_ERR(TAG, "Failed to get dfreerdp file descriptor");
|
2011-07-29 01:44:09 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
max_fds = 0;
|
|
|
|
FD_ZERO(&rfds_set);
|
2011-08-16 07:13:30 +04:00
|
|
|
FD_ZERO(&wfds_set);
|
2011-07-29 01:44:09 +04:00
|
|
|
|
|
|
|
for (i = 0; i < rcount; i++)
|
|
|
|
{
|
|
|
|
fds = (int)(long)(rfds[i]);
|
|
|
|
|
|
|
|
if (fds > max_fds)
|
|
|
|
max_fds = fds;
|
|
|
|
|
2011-08-01 20:24:29 +04:00
|
|
|
FD_SET(fds, &rfds_set);
|
2011-07-29 01:44:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (max_fds == 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (select(max_fds + 1, &rfds_set, &wfds_set, NULL, NULL) == -1)
|
|
|
|
{
|
|
|
|
/* these are not really errors */
|
|
|
|
if (!((errno == EAGAIN) ||
|
|
|
|
(errno == EWOULDBLOCK) ||
|
|
|
|
(errno == EINPROGRESS) ||
|
|
|
|
(errno == EINTR))) /* signal occurred */
|
|
|
|
{
|
2014-09-12 19:13:01 +04:00
|
|
|
WLog_ERR(TAG, "dfreerdp_run: select failed");
|
2011-07-29 01:44:09 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-09 10:31:28 +04:00
|
|
|
if (freerdp_check_fds(instance) != TRUE)
|
2011-07-29 01:44:09 +04:00
|
|
|
{
|
2014-09-12 19:13:01 +04:00
|
|
|
WLog_ERR(TAG, "Failed to check FreeRDP file descriptor");
|
2011-07-29 01:44:09 +04:00
|
|
|
break;
|
|
|
|
}
|
2012-10-09 10:31:28 +04:00
|
|
|
if (df_check_fds(instance, &rfds_set) != TRUE)
|
2011-08-03 07:01:20 +04:00
|
|
|
{
|
2014-09-12 19:13:01 +04:00
|
|
|
WLog_ERR(TAG, "Failed to check dfreerdp file descriptor");
|
2011-08-03 07:01:20 +04:00
|
|
|
break;
|
|
|
|
}
|
2012-10-09 10:31:28 +04:00
|
|
|
if (freerdp_channels_check_fds(channels, instance) != TRUE)
|
2011-07-29 01:44:09 +04:00
|
|
|
{
|
2014-09-12 19:13:01 +04:00
|
|
|
WLog_ERR(TAG, "Failed to check channel manager file descriptor");
|
2011-07-29 01:44:09 +04:00
|
|
|
break;
|
|
|
|
}
|
2011-10-17 04:10:09 +04:00
|
|
|
df_process_channel_event(channels, instance);
|
2011-07-29 01:44:09 +04:00
|
|
|
}
|
|
|
|
|
2015-01-20 13:24:14 +03:00
|
|
|
freerdp_channels_disconnect(channels, instance);
|
|
|
|
freerdp_disconnect(instance);
|
|
|
|
|
2011-10-17 04:10:09 +04:00
|
|
|
freerdp_channels_close(channels, instance);
|
|
|
|
freerdp_channels_free(channels);
|
2011-08-13 08:12:20 +04:00
|
|
|
df_free(dfi);
|
2011-08-10 18:51:55 +04:00
|
|
|
gdi_free(instance);
|
2011-10-17 05:02:28 +04:00
|
|
|
freerdp_disconnect(instance);
|
2011-07-28 21:46:36 +04:00
|
|
|
freerdp_free(instance);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void* thread_func(void* param)
|
|
|
|
{
|
|
|
|
struct thread_data* data;
|
|
|
|
data = (struct thread_data*) param;
|
|
|
|
|
|
|
|
dfreerdp_run(data->instance);
|
|
|
|
|
2012-10-09 07:21:26 +04:00
|
|
|
free(data);
|
2011-07-28 21:46:36 +04:00
|
|
|
|
|
|
|
pthread_detach(pthread_self());
|
|
|
|
|
|
|
|
g_thread_count--;
|
|
|
|
|
|
|
|
if (g_thread_count < 1)
|
2012-09-19 03:40:54 +04:00
|
|
|
ReleaseSemaphore(g_sem, 1, NULL);
|
2011-07-28 21:46:36 +04:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char* argv[])
|
|
|
|
{
|
2012-11-26 21:49:21 +04:00
|
|
|
int status;
|
2011-07-28 21:46:36 +04:00
|
|
|
pthread_t thread;
|
|
|
|
freerdp* instance;
|
2011-10-16 08:50:10 +04:00
|
|
|
dfContext* context;
|
2011-10-17 04:10:09 +04:00
|
|
|
rdpChannels* channels;
|
2011-07-28 21:46:36 +04:00
|
|
|
struct thread_data* data;
|
2011-08-02 12:04:30 +04:00
|
|
|
|
2011-08-09 04:31:21 +04:00
|
|
|
setlocale(LC_ALL, "");
|
|
|
|
|
2012-09-19 03:40:54 +04:00
|
|
|
g_sem = CreateSemaphore(NULL, 0, 1, NULL);
|
2011-07-28 21:46:36 +04:00
|
|
|
|
|
|
|
instance = freerdp_new();
|
|
|
|
instance->PreConnect = df_pre_connect;
|
|
|
|
instance->PostConnect = df_post_connect;
|
2011-10-18 19:02:05 +04:00
|
|
|
instance->VerifyCertificate = df_verify_certificate;
|
2011-08-03 07:01:20 +04:00
|
|
|
instance->ReceiveChannelData = df_receive_channel_data;
|
2011-07-28 21:46:36 +04:00
|
|
|
|
2013-06-14 05:34:46 +04:00
|
|
|
instance->ContextSize = sizeof(dfContext);
|
2011-10-21 07:15:18 +04:00
|
|
|
instance->ContextNew = df_context_new;
|
|
|
|
instance->ContextFree = df_context_free;
|
2011-10-16 08:50:10 +04:00
|
|
|
freerdp_context_new(instance);
|
|
|
|
|
|
|
|
context = (dfContext*) instance->context;
|
2011-10-17 04:10:09 +04:00
|
|
|
channels = instance->context->channels;
|
2011-08-02 12:04:30 +04:00
|
|
|
|
2011-07-28 21:46:36 +04:00
|
|
|
DirectFBInit(&argc, &argv);
|
2012-11-26 21:49:21 +04:00
|
|
|
|
|
|
|
instance->context->argc = argc;
|
|
|
|
instance->context->argv = argv;
|
|
|
|
|
2013-10-13 05:07:12 +04:00
|
|
|
status = freerdp_client_settings_parse_command_line(instance->settings, argc, argv);
|
2012-11-26 21:49:21 +04:00
|
|
|
|
|
|
|
if (status < 0)
|
|
|
|
exit(0);
|
|
|
|
|
|
|
|
freerdp_client_load_addins(instance->context->channels, instance->settings);
|
2011-07-28 21:46:36 +04:00
|
|
|
|
2012-11-20 08:49:08 +04:00
|
|
|
data = (struct thread_data*) malloc(sizeof(struct thread_data));
|
|
|
|
ZeroMemory(data, sizeof(sizeof(struct thread_data)));
|
|
|
|
|
2011-07-28 21:46:36 +04:00
|
|
|
data->instance = instance;
|
|
|
|
|
|
|
|
g_thread_count++;
|
|
|
|
pthread_create(&thread, 0, thread_func, data);
|
|
|
|
|
|
|
|
while (g_thread_count > 0)
|
|
|
|
{
|
2012-09-19 03:40:54 +04:00
|
|
|
WaitForSingleObject(g_sem, INFINITE);
|
2011-07-28 21:46:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|