2011-08-07 17:52:40 +04:00
|
|
|
/**
|
|
|
|
* FreeRDP: A Remote Desktop Protocol Client
|
|
|
|
* X11 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-08-07 21:41:54 +04:00
|
|
|
#include <X11/Xlib.h>
|
|
|
|
#include <X11/Xutil.h>
|
|
|
|
|
2011-09-29 08:33:16 +04:00
|
|
|
#ifdef WITH_XCURSOR
|
|
|
|
#include <X11/Xcursor/Xcursor.h>
|
|
|
|
#endif
|
|
|
|
|
2011-08-20 07:15:49 +04:00
|
|
|
#ifdef WITH_XINERAMA
|
|
|
|
#include <X11/extensions/Xinerama.h>
|
|
|
|
#endif
|
|
|
|
|
2011-09-19 02:44:49 +04:00
|
|
|
#include <errno.h>
|
2011-08-26 06:01:33 +04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2011-08-09 04:31:21 +04:00
|
|
|
#include <locale.h>
|
2011-09-19 02:44:49 +04:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <string.h>
|
2011-09-08 10:41:08 +04:00
|
|
|
#include <termios.h>
|
2011-09-19 02:44:49 +04:00
|
|
|
#include <pthread.h>
|
|
|
|
#include <sys/wait.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/select.h>
|
|
|
|
#include <freerdp/constants.h>
|
2011-10-04 13:40:03 +04:00
|
|
|
#include <freerdp/codec/nsc.h>
|
2011-10-03 04:52:17 +04:00
|
|
|
#include <freerdp/codec/rfx.h>
|
2011-10-03 04:28:20 +04:00
|
|
|
#include <freerdp/codec/color.h>
|
2011-10-21 01:28:59 +04:00
|
|
|
#include <freerdp/codec/bitmap.h>
|
2011-08-07 17:52:40 +04:00
|
|
|
#include <freerdp/utils/args.h>
|
|
|
|
#include <freerdp/utils/memory.h>
|
|
|
|
#include <freerdp/utils/semaphore.h>
|
2011-09-29 08:33:16 +04:00
|
|
|
#include <freerdp/utils/memory.h>
|
2011-08-07 17:52:40 +04:00
|
|
|
#include <freerdp/utils/event.h>
|
2011-09-29 08:37:30 +04:00
|
|
|
#include <freerdp/utils/signal.h>
|
2011-09-25 03:08:16 +04:00
|
|
|
#include <freerdp/utils/passphrase.h>
|
2011-08-11 07:07:03 +04:00
|
|
|
#include <freerdp/plugins/cliprdr.h>
|
|
|
|
#include <freerdp/rail.h>
|
2011-08-07 17:52:40 +04:00
|
|
|
|
2011-08-26 02:07:52 +04:00
|
|
|
#include "xf_gdi.h"
|
2011-08-16 08:22:00 +04:00
|
|
|
#include "xf_rail.h"
|
2011-09-20 12:27:59 +04:00
|
|
|
#include "xf_tsmf.h"
|
2011-08-07 17:52:40 +04:00
|
|
|
#include "xf_event.h"
|
2011-09-23 07:37:17 +04:00
|
|
|
#include "xf_cliprdr.h"
|
2011-08-31 04:59:42 +04:00
|
|
|
#include "xf_monitor.h"
|
2011-10-21 01:28:59 +04:00
|
|
|
#include "xf_graphics.h"
|
2011-08-26 06:01:33 +04:00
|
|
|
#include "xf_keyboard.h"
|
2011-08-07 17:52:40 +04:00
|
|
|
|
|
|
|
#include "xfreerdp.h"
|
|
|
|
|
2011-12-01 04:22:22 +04:00
|
|
|
static freerdp_sem g_sem;
|
2011-08-07 17:52:40 +04:00
|
|
|
static int g_thread_count = 0;
|
2011-10-24 22:46:19 +04:00
|
|
|
static uint8 g_disconnect_reason = 0;
|
2011-08-07 17:52:40 +04:00
|
|
|
|
2011-09-20 12:27:59 +04:00
|
|
|
static long xv_port = 0;
|
2011-12-01 04:22:22 +04:00
|
|
|
static const size_t password_size = 512;
|
2011-09-20 12:27:59 +04:00
|
|
|
|
2011-08-07 17:52:40 +04:00
|
|
|
struct thread_data
|
|
|
|
{
|
|
|
|
freerdp* instance;
|
|
|
|
};
|
|
|
|
|
2011-10-17 05:39:11 +04:00
|
|
|
int xf_process_client_args(rdpSettings* settings, const char* opt, const char* val, void* user_data);
|
|
|
|
int xf_process_plugin_args(rdpSettings* settings, const char* name, RDP_PLUGIN_DATA* plugin_data, void* user_data);
|
|
|
|
|
2011-10-21 07:15:18 +04:00
|
|
|
void xf_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();
|
2011-10-16 08:50:10 +04:00
|
|
|
}
|
|
|
|
|
2011-10-21 07:15:18 +04:00
|
|
|
void xf_context_free(freerdp* instance, rdpContext* context)
|
2011-10-16 08:50:10 +04:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-11-22 04:41:49 +04:00
|
|
|
void xf_sw_begin_paint(rdpContext* context)
|
2011-08-07 17:52:40 +04:00
|
|
|
{
|
2011-11-22 04:41:49 +04:00
|
|
|
rdpGdi* gdi = context->gdi;
|
2011-08-07 17:52:40 +04:00
|
|
|
gdi->primary->hdc->hwnd->invalid->null = 1;
|
2011-08-24 09:47:43 +04:00
|
|
|
gdi->primary->hdc->hwnd->ninvalid = 0;
|
2011-08-07 17:52:40 +04:00
|
|
|
}
|
|
|
|
|
2011-11-22 04:41:49 +04:00
|
|
|
void xf_sw_end_paint(rdpContext* context)
|
2011-08-07 17:52:40 +04:00
|
|
|
{
|
2011-10-16 08:50:10 +04:00
|
|
|
rdpGdi* gdi;
|
2011-08-07 17:52:40 +04:00
|
|
|
xfInfo* xfi;
|
2011-08-07 22:09:18 +04:00
|
|
|
sint32 x, y;
|
|
|
|
uint32 w, h;
|
2011-08-07 17:52:40 +04:00
|
|
|
|
2011-11-22 04:41:49 +04:00
|
|
|
xfi = ((xfContext*) context)->xfi;
|
|
|
|
gdi = context->gdi;
|
2011-08-07 17:52:40 +04:00
|
|
|
|
2011-11-19 21:19:16 +04:00
|
|
|
if (xfi->remote_app != true)
|
2011-08-18 09:16:49 +04:00
|
|
|
{
|
2011-11-19 21:19:16 +04:00
|
|
|
if (xfi->complex_regions != true)
|
2011-08-26 21:37:23 +04:00
|
|
|
{
|
|
|
|
if (gdi->primary->hdc->hwnd->invalid->null)
|
|
|
|
return;
|
2011-08-25 06:35:55 +04:00
|
|
|
|
2011-08-26 21:37:23 +04: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;
|
|
|
|
|
|
|
|
XPutImage(xfi->display, xfi->primary, xfi->gc, xfi->image, x, y, x, y, w, h);
|
|
|
|
XCopyArea(xfi->display, xfi->primary, xfi->window->handle, xfi->gc, x, y, w, h, x, y);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int ninvalid;
|
|
|
|
HGDI_RGN cinvalid;
|
2011-08-25 06:35:55 +04:00
|
|
|
|
2011-08-26 21:37:23 +04:00
|
|
|
if (gdi->primary->hdc->hwnd->ninvalid < 1)
|
|
|
|
return;
|
2011-08-24 09:47:43 +04:00
|
|
|
|
2011-08-26 21:37:23 +04:00
|
|
|
ninvalid = gdi->primary->hdc->hwnd->ninvalid;
|
|
|
|
cinvalid = gdi->primary->hdc->hwnd->cinvalid;
|
2011-08-24 09:47:43 +04:00
|
|
|
|
2011-08-26 21:37:23 +04:00
|
|
|
for (i = 0; i < ninvalid; i++)
|
|
|
|
{
|
|
|
|
x = cinvalid[i].x;
|
|
|
|
y = cinvalid[i].y;
|
|
|
|
w = cinvalid[i].w;
|
|
|
|
h = cinvalid[i].h;
|
2011-08-24 09:47:43 +04:00
|
|
|
|
2011-08-26 21:37:23 +04:00
|
|
|
XPutImage(xfi->display, xfi->primary, xfi->gc, xfi->image, x, y, x, y, w, h);
|
|
|
|
XCopyArea(xfi->display, xfi->primary, xfi->window->handle, xfi->gc, x, y, w, h, x, y);
|
|
|
|
}
|
2011-08-24 09:47:43 +04:00
|
|
|
|
2011-08-26 21:37:23 +04:00
|
|
|
XFlush(xfi->display);
|
2011-08-24 09:47:43 +04:00
|
|
|
}
|
2011-08-18 09:16:49 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-08-24 09:47:43 +04:00
|
|
|
if (gdi->primary->hdc->hwnd->invalid->null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
2011-11-22 04:41:49 +04:00
|
|
|
xf_rail_paint(xfi, context->rail, x, y, x + w - 1, y + h - 1);
|
2011-08-18 09:16:49 +04:00
|
|
|
}
|
2011-08-07 17:52:40 +04:00
|
|
|
}
|
|
|
|
|
2011-11-22 04:41:49 +04:00
|
|
|
void xf_sw_desktop_resize(rdpContext* context)
|
2011-09-23 08:06:39 +04:00
|
|
|
{
|
|
|
|
xfInfo* xfi;
|
|
|
|
rdpSettings* settings;
|
|
|
|
|
2011-11-22 04:41:49 +04:00
|
|
|
xfi = ((xfContext*) context)->xfi;
|
2011-09-23 08:06:39 +04:00
|
|
|
settings = xfi->instance->settings;
|
|
|
|
|
2011-11-19 21:19:16 +04:00
|
|
|
if (xfi->fullscreen != true)
|
2011-09-23 08:06:39 +04:00
|
|
|
{
|
2011-11-22 04:41:49 +04:00
|
|
|
rdpGdi* gdi = context->gdi;
|
2011-09-23 08:06:39 +04:00
|
|
|
gdi_resize(gdi, xfi->width, xfi->height);
|
|
|
|
|
|
|
|
if (xfi->image)
|
|
|
|
{
|
|
|
|
xfi->image->data = NULL;
|
|
|
|
XDestroyImage(xfi->image);
|
|
|
|
xfi->image = XCreateImage(xfi->display, xfi->visual, xfi->depth, ZPixmap, 0,
|
|
|
|
(char*) gdi->primary_buffer, gdi->width, gdi->height, xfi->scanline_pad, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-22 04:41:49 +04:00
|
|
|
void xf_hw_begin_paint(rdpContext* context)
|
2011-09-23 08:06:39 +04:00
|
|
|
{
|
|
|
|
xfInfo* xfi;
|
2011-11-22 04:41:49 +04:00
|
|
|
xfi = ((xfContext*) context)->xfi;
|
2011-09-23 08:06:39 +04:00
|
|
|
xfi->hdc->hwnd->invalid->null = 1;
|
|
|
|
xfi->hdc->hwnd->ninvalid = 0;
|
|
|
|
}
|
|
|
|
|
2011-11-22 04:41:49 +04:00
|
|
|
void xf_hw_end_paint(rdpContext* context)
|
2011-09-23 08:06:39 +04:00
|
|
|
{
|
|
|
|
xfInfo* xfi;
|
|
|
|
sint32 x, y;
|
|
|
|
uint32 w, h;
|
|
|
|
|
2011-11-22 04:41:49 +04:00
|
|
|
xfi = ((xfContext*) context)->xfi;
|
2011-09-23 08:06:39 +04:00
|
|
|
|
|
|
|
if (xfi->remote_app)
|
|
|
|
{
|
|
|
|
if (xfi->hdc->hwnd->invalid->null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
x = xfi->hdc->hwnd->invalid->x;
|
|
|
|
y = xfi->hdc->hwnd->invalid->y;
|
|
|
|
w = xfi->hdc->hwnd->invalid->w;
|
|
|
|
h = xfi->hdc->hwnd->invalid->h;
|
|
|
|
|
2011-11-22 04:41:49 +04:00
|
|
|
xf_rail_paint(xfi, context->rail, x, y, x + w - 1, y + h - 1);
|
2011-09-23 08:06:39 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-22 04:41:49 +04:00
|
|
|
void xf_hw_desktop_resize(rdpContext* context)
|
2011-09-06 12:22:53 +04:00
|
|
|
{
|
|
|
|
xfInfo* xfi;
|
2011-09-07 09:27:39 +04:00
|
|
|
boolean same;
|
2011-09-06 12:22:53 +04:00
|
|
|
rdpSettings* settings;
|
|
|
|
|
2011-11-22 04:41:49 +04:00
|
|
|
xfi = ((xfContext*) context)->xfi;
|
2011-09-06 12:22:53 +04:00
|
|
|
settings = xfi->instance->settings;
|
|
|
|
|
2011-11-19 21:19:16 +04:00
|
|
|
if (xfi->fullscreen != true)
|
2011-09-07 09:27:39 +04:00
|
|
|
{
|
|
|
|
xfi->width = settings->width;
|
|
|
|
xfi->height = settings->height;
|
|
|
|
|
|
|
|
if (xfi->window)
|
|
|
|
xf_ResizeDesktopWindow(xfi, xfi->window, settings->width, settings->height);
|
|
|
|
|
|
|
|
if (xfi->primary)
|
|
|
|
{
|
2011-11-19 21:19:16 +04:00
|
|
|
same = (xfi->primary == xfi->drawing) ? true : false;
|
2011-09-23 08:06:39 +04:00
|
|
|
|
2011-09-07 09:27:39 +04:00
|
|
|
XFreePixmap(xfi->display, xfi->primary);
|
|
|
|
|
2011-09-23 08:06:39 +04:00
|
|
|
xfi->primary = XCreatePixmap(xfi->display, xfi->drawable,
|
|
|
|
xfi->width, xfi->height, xfi->depth);
|
2011-09-07 09:27:39 +04:00
|
|
|
|
2011-09-23 08:06:39 +04:00
|
|
|
if (same)
|
|
|
|
xfi->drawing = xfi->primary;
|
2011-09-07 09:27:39 +04:00
|
|
|
}
|
|
|
|
}
|
2011-09-06 12:22:53 +04:00
|
|
|
}
|
|
|
|
|
2011-08-07 17:52:40 +04:00
|
|
|
boolean xf_get_fds(freerdp* instance, void** rfds, int* rcount, void** wfds, int* wcount)
|
|
|
|
{
|
2011-10-16 08:50:10 +04:00
|
|
|
xfInfo* xfi = ((xfContext*) instance->context)->xfi;
|
2011-08-07 17:52:40 +04:00
|
|
|
|
2011-08-07 21:41:54 +04:00
|
|
|
rfds[*rcount] = (void*)(long)(xfi->xfds);
|
|
|
|
(*rcount)++;
|
|
|
|
|
2011-11-19 21:19:16 +04:00
|
|
|
return true;
|
2011-08-07 17:52:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
boolean xf_check_fds(freerdp* instance, fd_set* set)
|
|
|
|
{
|
2011-08-07 21:41:54 +04:00
|
|
|
XEvent xevent;
|
2011-10-16 08:50:10 +04:00
|
|
|
xfInfo* xfi = ((xfContext*) instance->context)->xfi;
|
2011-08-07 21:41:54 +04:00
|
|
|
|
|
|
|
while (XPending(xfi->display))
|
|
|
|
{
|
|
|
|
memset(&xevent, 0, sizeof(xevent));
|
|
|
|
XNextEvent(xfi->display, &xevent);
|
|
|
|
|
2011-11-19 21:19:16 +04:00
|
|
|
if (xf_event_process(instance, &xevent) != true)
|
|
|
|
return false;
|
2011-08-07 21:41:54 +04:00
|
|
|
}
|
2011-08-07 17:52:40 +04:00
|
|
|
|
2011-11-19 21:19:16 +04:00
|
|
|
return true;
|
2011-08-07 17:52:40 +04:00
|
|
|
}
|
|
|
|
|
2011-10-04 14:44:52 +04:00
|
|
|
void xf_create_window(xfInfo* xfi)
|
|
|
|
{
|
|
|
|
XEvent xevent;
|
2011-12-02 18:58:38 +04:00
|
|
|
char* win_title;
|
2011-10-07 23:50:07 +04:00
|
|
|
int width, height;
|
2011-10-04 14:44:52 +04:00
|
|
|
|
2011-10-07 23:50:07 +04:00
|
|
|
width = xfi->width;
|
|
|
|
height = xfi->height;
|
2011-10-04 14:44:52 +04:00
|
|
|
|
|
|
|
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->fullscreen;
|
|
|
|
xfi->attribs.colormap = xfi->colormap;
|
2011-12-03 02:51:30 +04:00
|
|
|
xfi->attribs.bit_gravity = ForgetGravity;
|
|
|
|
xfi->attribs.win_gravity = StaticGravity;
|
2011-10-04 14:44:52 +04:00
|
|
|
|
2012-01-02 13:27:04 +04:00
|
|
|
if (xfi->instance->settings->window_title != NULL)
|
2011-10-04 14:44:52 +04:00
|
|
|
{
|
2012-01-14 02:32:14 +04:00
|
|
|
win_title = xstrdup(xfi->instance->settings->window_title);
|
2012-01-02 13:27:04 +04:00
|
|
|
}
|
|
|
|
else if (xfi->instance->settings->port == 3389)
|
|
|
|
{
|
2012-01-14 02:32:14 +04:00
|
|
|
win_title = xmalloc(1 + sizeof("FreeRDP: ") + strlen(xfi->instance->settings->hostname));
|
2012-01-02 13:27:04 +04:00
|
|
|
sprintf(win_title, "FreeRDP: %s", xfi->instance->settings->hostname);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-01-14 02:32:14 +04:00
|
|
|
win_title = xmalloc(1 + sizeof("FreeRDP: ") + strlen(xfi->instance->settings->hostname) + sizeof(":00000"));
|
2012-01-02 13:27:04 +04:00
|
|
|
sprintf(win_title, "FreeRDP: %s:%i", xfi->instance->settings->hostname, xfi->instance->settings->port);
|
|
|
|
}
|
2011-12-09 22:53:19 +04:00
|
|
|
|
2012-01-02 13:27:04 +04:00
|
|
|
xfi->window = xf_CreateDesktopWindow(xfi, win_title, width, height, xfi->decorations);
|
|
|
|
xfree(win_title);
|
2011-10-04 14:44:52 +04:00
|
|
|
|
2012-01-02 13:27:04 +04:00
|
|
|
if (xfi->parent_window)
|
|
|
|
XReparentWindow(xfi->display, xfi->window->handle, xfi->parent_window, 0, 0);
|
2011-10-04 14:44:52 +04:00
|
|
|
|
2012-01-02 13:27:04 +04:00
|
|
|
if (xfi->fullscreen)
|
|
|
|
xf_SetWindowFullscreen(xfi, xfi->window, xfi->fullscreen);
|
2011-10-04 14:44:52 +04:00
|
|
|
|
2012-01-02 13:27:04 +04:00
|
|
|
/* wait for VisibilityNotify */
|
|
|
|
do
|
2011-10-04 14:44:52 +04:00
|
|
|
{
|
2012-01-02 13:27:04 +04:00
|
|
|
XMaskEvent(xfi->display, VisibilityChangeMask, &xevent);
|
2011-10-04 14:44:52 +04:00
|
|
|
}
|
2012-01-02 13:27:04 +04:00
|
|
|
while (xevent.type != VisibilityNotify);
|
|
|
|
|
|
|
|
xfi->unobscured = (xevent.xvisibility.state == VisibilityUnobscured);
|
|
|
|
|
|
|
|
XSetWMProtocols(xfi->display, xfi->window->handle, &(xfi->WM_DELETE_WINDOW), 1);
|
|
|
|
xfi->drawable = xfi->window->handle;
|
2011-10-04 14:44:52 +04:00
|
|
|
}
|
|
|
|
|
2011-08-24 08:46:34 +04:00
|
|
|
void xf_toggle_fullscreen(xfInfo* xfi)
|
|
|
|
{
|
|
|
|
Pixmap contents = 0;
|
|
|
|
|
|
|
|
contents = XCreatePixmap(xfi->display, xfi->window->handle, xfi->width, xfi->height, xfi->depth);
|
|
|
|
XCopyArea(xfi->display, xfi->primary, contents, xfi->gc, 0, 0, xfi->width, xfi->height, 0, 0);
|
|
|
|
|
2011-09-14 06:20:04 +04:00
|
|
|
XDestroyWindow(xfi->display, xfi->window->handle);
|
2011-11-19 21:19:16 +04:00
|
|
|
xfi->fullscreen = (xfi->fullscreen) ? false : true;
|
2011-10-04 14:44:52 +04:00
|
|
|
xf_create_window(xfi);
|
2011-08-24 08:46:34 +04:00
|
|
|
|
|
|
|
XCopyArea(xfi->display, contents, xfi->primary, xfi->gc, 0, 0, xfi->width, xfi->height, 0, 0);
|
|
|
|
XFreePixmap(xfi->display, contents);
|
|
|
|
}
|
|
|
|
|
|
|
|
boolean xf_get_pixmap_info(xfInfo* xfi)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int vi_count;
|
|
|
|
int pf_count;
|
|
|
|
XVisualInfo* vi;
|
|
|
|
XVisualInfo* vis;
|
|
|
|
XVisualInfo template;
|
|
|
|
XPixmapFormatValues* pf;
|
|
|
|
XPixmapFormatValues* pfs;
|
2012-02-27 21:08:38 +04:00
|
|
|
XWindowAttributes window_attributes;
|
2011-08-24 08:46:34 +04:00
|
|
|
|
|
|
|
pfs = XListPixmapFormats(xfi->display, &pf_count);
|
|
|
|
|
|
|
|
if (pfs == NULL)
|
|
|
|
{
|
|
|
|
printf("xf_get_pixmap_info: XListPixmapFormats failed\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < pf_count; i++)
|
|
|
|
{
|
|
|
|
pf = pfs + i;
|
|
|
|
|
|
|
|
if (pf->depth == xfi->depth)
|
|
|
|
{
|
|
|
|
xfi->bpp = pf->bits_per_pixel;
|
|
|
|
xfi->scanline_pad = pf->scanline_pad;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
XFree(pfs);
|
|
|
|
|
|
|
|
memset(&template, 0, sizeof(template));
|
|
|
|
template.class = TrueColor;
|
|
|
|
template.screen = xfi->screen_number;
|
|
|
|
|
2012-02-27 21:08:38 +04:00
|
|
|
if (XGetWindowAttributes(xfi->display, RootWindowOfScreen(xfi->screen), &window_attributes) == 0)
|
|
|
|
{
|
|
|
|
printf("xf_get_pixmap_info: XGetWindowAttributes failed\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-08-24 08:46:34 +04:00
|
|
|
vis = XGetVisualInfo(xfi->display, VisualClassMask | VisualScreenMask, &template, &vi_count);
|
|
|
|
|
|
|
|
if (vis == NULL)
|
|
|
|
{
|
|
|
|
printf("xf_get_pixmap_info: XGetVisualInfo failed\n");
|
2011-11-19 21:19:16 +04:00
|
|
|
return false;
|
2011-08-24 08:46:34 +04:00
|
|
|
}
|
|
|
|
|
2011-12-29 17:26:34 +04:00
|
|
|
vi = NULL;
|
2011-08-24 08:46:34 +04:00
|
|
|
for (i = 0; i < vi_count; i++)
|
|
|
|
{
|
|
|
|
vi = vis + i;
|
|
|
|
|
2012-02-27 21:08:38 +04:00
|
|
|
if (vi->visual == window_attributes.visual)
|
2011-08-24 08:46:34 +04:00
|
|
|
{
|
|
|
|
xfi->visual = vi->visual;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2011-12-22 02:58:15 +04:00
|
|
|
|
|
|
|
if (vi)
|
|
|
|
{
|
2011-12-30 19:00:03 +04:00
|
|
|
/*
|
|
|
|
* Detect if the server visual has an inverted colormap
|
|
|
|
* (BGR vs RGB, or red being the least significant byte)
|
|
|
|
*/
|
|
|
|
|
2011-12-22 02:58:15 +04:00
|
|
|
if (vi->red_mask & 0xFF)
|
|
|
|
{
|
|
|
|
xfi->clrconv->invert = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-24 08:46:34 +04:00
|
|
|
XFree(vis);
|
|
|
|
|
|
|
|
if ((xfi->visual == NULL) || (xfi->scanline_pad == 0))
|
|
|
|
{
|
2011-11-19 21:19:16 +04:00
|
|
|
return false;
|
2011-08-24 08:46:34 +04:00
|
|
|
}
|
|
|
|
|
2011-11-19 21:19:16 +04:00
|
|
|
return true;
|
2011-08-24 08:46:34 +04:00
|
|
|
}
|
|
|
|
|
2011-12-21 21:50:22 +04:00
|
|
|
static int (*_def_error_handler)(Display*, XErrorEvent*);
|
|
|
|
int xf_error_handler(Display* d, XErrorEvent* ev)
|
|
|
|
{
|
|
|
|
char buf[256];
|
|
|
|
int do_abort = true;
|
|
|
|
|
|
|
|
XGetErrorText(d, ev->error_code, buf, sizeof(buf));
|
2011-12-29 17:26:34 +04:00
|
|
|
printf("%s", buf);
|
2011-12-21 21:50:22 +04:00
|
|
|
|
|
|
|
if (do_abort)
|
|
|
|
abort();
|
|
|
|
|
|
|
|
_def_error_handler(d, ev);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
int _xf_error_handler(Display* d, XErrorEvent* ev)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* ungrab the keyboard, in case a debugger is running in
|
|
|
|
* another window. This make xf_error_handler() a potential
|
|
|
|
* debugger breakpoint.
|
|
|
|
*/
|
|
|
|
XUngrabKeyboard(d, CurrentTime);
|
|
|
|
return xf_error_handler(d, ev);
|
|
|
|
}
|
|
|
|
|
2012-02-23 19:22:05 +04:00
|
|
|
/**
|
|
|
|
* Callback given to freerdp_connect() to process the pre-connect operations.
|
|
|
|
* It will parse the command line parameters given to xfreerdp (using freerdp_parse_args())
|
|
|
|
* and fill the rdp_freerdp structure (instance) with the appropriate options to use for the connection.
|
|
|
|
*
|
|
|
|
* @param instance - pointer to the rdp_freerdp structure that contains the connection's parameters, and will
|
|
|
|
* be filled with the appropriate informations.
|
|
|
|
*
|
|
|
|
* @return true if successful. false otherwise.
|
|
|
|
* Can exit with error code XF_EXIT_PARSE_ARGUMENTS if there is an error in the parameters.
|
|
|
|
*/
|
2011-08-07 17:52:40 +04:00
|
|
|
boolean xf_pre_connect(freerdp* instance)
|
|
|
|
{
|
|
|
|
xfInfo* xfi;
|
2011-10-05 05:29:01 +04:00
|
|
|
boolean bitmap_cache;
|
2011-08-07 17:52:40 +04:00
|
|
|
rdpSettings* settings;
|
2012-01-15 01:30:48 +04:00
|
|
|
int arg_parse_result;
|
|
|
|
|
2011-08-07 17:52:40 +04:00
|
|
|
xfi = (xfInfo*) xzalloc(sizeof(xfInfo));
|
2011-10-16 08:50:10 +04:00
|
|
|
((xfContext*) instance->context)->xfi = xfi;
|
2011-10-17 04:10:09 +04:00
|
|
|
|
|
|
|
xfi->_context = instance->context;
|
2011-10-16 08:50:10 +04:00
|
|
|
xfi->context = (xfContext*) instance->context;
|
|
|
|
xfi->context->settings = instance->settings;
|
2011-08-07 21:41:54 +04:00
|
|
|
xfi->instance = instance;
|
2012-01-15 01:30:48 +04:00
|
|
|
|
|
|
|
arg_parse_result = freerdp_parse_args(instance->settings, instance->context->argc,instance->context->argv,
|
|
|
|
xf_process_plugin_args, instance->context->channels, xf_process_client_args, xfi);
|
|
|
|
|
|
|
|
if (arg_parse_result < 0)
|
2011-10-17 05:39:11 +04:00
|
|
|
{
|
2012-01-15 01:30:48 +04:00
|
|
|
if (arg_parse_result == FREERDP_ARGS_PARSE_FAILURE)
|
|
|
|
printf("failed to parse arguments.\n");
|
|
|
|
|
2011-10-24 22:46:19 +04:00
|
|
|
exit(XF_EXIT_PARSE_ARGUMENTS);
|
2011-10-17 05:39:11 +04:00
|
|
|
}
|
|
|
|
|
2011-08-07 17:52:40 +04:00
|
|
|
settings = instance->settings;
|
2011-10-05 05:29:01 +04:00
|
|
|
bitmap_cache = settings->bitmap_cache;
|
2011-08-07 17:52:40 +04:00
|
|
|
|
2011-12-24 11:48:11 +04:00
|
|
|
settings->os_major_type = OSMAJORTYPE_UNIX;
|
|
|
|
settings->os_minor_type = OSMINORTYPE_NATIVE_XSERVER;
|
2012-02-13 00:21:08 +04:00
|
|
|
|
2011-11-19 21:19:16 +04:00
|
|
|
settings->order_support[NEG_DSTBLT_INDEX] = true;
|
|
|
|
settings->order_support[NEG_PATBLT_INDEX] = true;
|
|
|
|
settings->order_support[NEG_SCRBLT_INDEX] = true;
|
|
|
|
settings->order_support[NEG_OPAQUE_RECT_INDEX] = true;
|
|
|
|
settings->order_support[NEG_DRAWNINEGRID_INDEX] = false;
|
|
|
|
settings->order_support[NEG_MULTIDSTBLT_INDEX] = false;
|
|
|
|
settings->order_support[NEG_MULTIPATBLT_INDEX] = false;
|
|
|
|
settings->order_support[NEG_MULTISCRBLT_INDEX] = false;
|
|
|
|
settings->order_support[NEG_MULTIOPAQUERECT_INDEX] = true;
|
|
|
|
settings->order_support[NEG_MULTI_DRAWNINEGRID_INDEX] = false;
|
|
|
|
settings->order_support[NEG_LINETO_INDEX] = true;
|
|
|
|
settings->order_support[NEG_POLYLINE_INDEX] = true;
|
2011-10-05 05:29:01 +04:00
|
|
|
settings->order_support[NEG_MEMBLT_INDEX] = bitmap_cache;
|
2012-02-13 03:12:28 +04:00
|
|
|
|
2012-02-13 04:41:39 +04:00
|
|
|
settings->order_support[NEG_MEM3BLT_INDEX] = (settings->sw_gdi) ? true : false;
|
2012-02-13 03:12:28 +04:00
|
|
|
|
2011-10-05 05:29:01 +04:00
|
|
|
settings->order_support[NEG_MEMBLT_V2_INDEX] = bitmap_cache;
|
2011-11-19 21:19:16 +04:00
|
|
|
settings->order_support[NEG_MEM3BLT_V2_INDEX] = false;
|
|
|
|
settings->order_support[NEG_SAVEBITMAP_INDEX] = false;
|
|
|
|
settings->order_support[NEG_GLYPH_INDEX_INDEX] = true;
|
|
|
|
settings->order_support[NEG_FAST_INDEX_INDEX] = true;
|
|
|
|
settings->order_support[NEG_FAST_GLYPH_INDEX] = true;
|
2012-02-13 02:14:59 +04:00
|
|
|
|
|
|
|
settings->order_support[NEG_POLYGON_SC_INDEX] = (settings->sw_gdi) ? false : true;
|
|
|
|
settings->order_support[NEG_POLYGON_CB_INDEX] = (settings->sw_gdi) ? false : true;
|
|
|
|
|
2011-11-19 21:19:16 +04:00
|
|
|
settings->order_support[NEG_ELLIPSE_SC_INDEX] = false;
|
|
|
|
settings->order_support[NEG_ELLIPSE_CB_INDEX] = false;
|
2011-08-07 17:52:40 +04:00
|
|
|
|
2011-10-17 04:10:09 +04:00
|
|
|
freerdp_channels_pre_connect(xfi->_context->channels, instance);
|
2011-08-07 17:52:40 +04:00
|
|
|
|
2011-08-07 21:41:54 +04:00
|
|
|
xfi->display = XOpenDisplay(NULL);
|
|
|
|
|
|
|
|
if (xfi->display == NULL)
|
|
|
|
{
|
|
|
|
printf("xf_pre_connect: failed to open display: %s\n", XDisplayName(NULL));
|
2011-12-09 22:53:19 +04:00
|
|
|
printf("Please check that the $DISPLAY environment variable is properly set.\n");
|
2011-11-19 21:19:16 +04:00
|
|
|
return false;
|
2011-08-07 21:41:54 +04:00
|
|
|
}
|
|
|
|
|
2011-12-21 21:50:22 +04:00
|
|
|
if (xfi->debug)
|
|
|
|
{
|
|
|
|
printf("Enabling X11 debug mode.\n");
|
|
|
|
XSynchronize(xfi->display, true);
|
|
|
|
_def_error_handler = XSetErrorHandler(_xf_error_handler);
|
|
|
|
}
|
|
|
|
|
2011-12-22 22:01:29 +04:00
|
|
|
xfi->_NET_WM_ICON = XInternAtom(xfi->display, "_NET_WM_ICON", False);
|
2011-12-27 19:26:20 +04:00
|
|
|
xfi->_MOTIF_WM_HINTS = XInternAtom(xfi->display, "_MOTIF_WM_HINTS", False);
|
|
|
|
xfi->_NET_CURRENT_DESKTOP = XInternAtom(xfi->display, "_NET_CURRENT_DESKTOP", False);
|
|
|
|
xfi->_NET_WORKAREA = XInternAtom(xfi->display, "_NET_WORKAREA", False);
|
|
|
|
xfi->_NET_WM_STATE = XInternAtom(xfi->display, "_NET_WM_STATE", False);
|
|
|
|
xfi->_NET_WM_STATE_FULLSCREEN = XInternAtom(xfi->display, "_NET_WM_STATE_FULLSCREEN", False);
|
|
|
|
xfi->_NET_WM_WINDOW_TYPE = XInternAtom(xfi->display, "_NET_WM_WINDOW_TYPE", False);
|
|
|
|
|
|
|
|
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_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);
|
|
|
|
xfi->_NET_WM_STATE_SKIP_PAGER = XInternAtom(xfi->display, "_NET_WM_STATE_SKIP_PAGER", False);
|
|
|
|
xfi->_NET_WM_MOVERESIZE = XInternAtom(xfi->display, "_NET_WM_MOVERESIZE", False);
|
|
|
|
xfi->_NET_MOVERESIZE_WINDOW = XInternAtom(xfi->display, "_NET_MOVERESIZE_WINDOW", False);
|
|
|
|
|
|
|
|
xfi->WM_PROTOCOLS = XInternAtom(xfi->display, "WM_PROTOCOLS", False);
|
|
|
|
xfi->WM_DELETE_WINDOW = XInternAtom(xfi->display, "WM_DELETE_WINDOW", False);
|
2011-09-21 16:36:49 +04:00
|
|
|
|
2011-08-07 21:41:54 +04:00
|
|
|
xf_kbd_init(xfi);
|
|
|
|
|
2012-02-02 03:42:20 +04:00
|
|
|
xfi->clrconv = freerdp_clrconv_new(CLRCONV_ALPHA);
|
2011-08-26 22:48:51 +04:00
|
|
|
|
2011-10-16 08:50:10 +04:00
|
|
|
instance->context->cache = cache_new(instance->settings);
|
2011-08-26 22:48:51 +04:00
|
|
|
|
2011-08-07 21:41:54 +04:00
|
|
|
xfi->xfds = ConnectionNumber(xfi->display);
|
|
|
|
xfi->screen_number = DefaultScreen(xfi->display);
|
|
|
|
xfi->screen = ScreenOfDisplay(xfi->display, xfi->screen_number);
|
|
|
|
xfi->depth = DefaultDepthOfScreen(xfi->screen);
|
|
|
|
xfi->big_endian = (ImageByteOrder(xfi->display) == MSBFirst);
|
|
|
|
|
2011-08-27 02:33:07 +04:00
|
|
|
xfi->mouse_motion = settings->mouse_motion;
|
2011-11-19 21:19:16 +04:00
|
|
|
xfi->complex_regions = true;
|
2011-10-07 23:50:07 +04:00
|
|
|
xfi->decorations = settings->decorations;
|
2011-08-19 19:12:30 +04:00
|
|
|
xfi->fullscreen = settings->fullscreen;
|
2011-10-05 02:46:49 +04:00
|
|
|
xfi->grab_keyboard = settings->grab_keyboard;
|
2011-11-19 21:19:16 +04:00
|
|
|
xfi->fullscreen_toggle = true;
|
2011-09-23 08:06:39 +04:00
|
|
|
xfi->sw_gdi = settings->sw_gdi;
|
2011-12-09 22:53:19 +04:00
|
|
|
xfi->parent_window = (Window) settings->parent_window_xid;
|
2011-08-17 22:13:44 +04:00
|
|
|
|
2011-08-31 04:59:42 +04:00
|
|
|
xf_detect_monitors(xfi, settings);
|
2011-08-20 07:15:49 +04:00
|
|
|
|
2011-11-19 21:19:16 +04:00
|
|
|
return true;
|
2011-08-07 21:41:54 +04:00
|
|
|
}
|
|
|
|
|
2011-10-29 18:01:50 +04:00
|
|
|
void cpuid(unsigned info, unsigned *eax, unsigned *ebx, unsigned *ecx, unsigned *edx)
|
|
|
|
{
|
|
|
|
#ifdef __GNUC__
|
|
|
|
#if defined(__i386__) || defined(__x86_64__)
|
|
|
|
*eax = info;
|
|
|
|
__asm volatile
|
|
|
|
("mov %%ebx, %%edi;" /* 32bit PIC: don't clobber ebx */
|
|
|
|
"cpuid;"
|
|
|
|
"mov %%ebx, %%esi;"
|
|
|
|
"mov %%edi, %%ebx;"
|
|
|
|
:"+a" (*eax), "=S" (*ebx), "=c" (*ecx), "=d" (*edx)
|
|
|
|
: :"edi");
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32 xf_detect_cpu()
|
|
|
|
{
|
|
|
|
unsigned int eax, ebx, ecx, edx = 0;
|
|
|
|
uint32 cpu_opt = 0;
|
|
|
|
|
|
|
|
cpuid(1, &eax, &ebx, &ecx, &edx);
|
|
|
|
|
|
|
|
if (edx & (1<<26))
|
|
|
|
{
|
|
|
|
DEBUG("SSE2 detected");
|
|
|
|
cpu_opt |= CPU_SSE2;
|
|
|
|
}
|
|
|
|
|
|
|
|
return cpu_opt;
|
|
|
|
}
|
|
|
|
|
2012-02-23 19:22:05 +04:00
|
|
|
/**
|
|
|
|
* Callback given to freerdp_connect() to perform post-connection operations.
|
|
|
|
* It will be called only if the connection was initialized properly, and will continue the initialization based on the
|
|
|
|
* newly created connection.
|
|
|
|
*/
|
2011-08-07 17:52:40 +04:00
|
|
|
boolean xf_post_connect(freerdp* instance)
|
|
|
|
{
|
|
|
|
xfInfo* xfi;
|
2011-08-07 21:41:54 +04:00
|
|
|
XGCValues gcv;
|
2011-10-16 08:50:10 +04:00
|
|
|
rdpCache* cache;
|
2011-10-17 04:10:09 +04:00
|
|
|
rdpChannels* channels;
|
2011-10-29 18:01:50 +04:00
|
|
|
RFX_CONTEXT* rfx_context = NULL;
|
2011-08-07 17:52:40 +04:00
|
|
|
|
2011-10-16 08:50:10 +04:00
|
|
|
xfi = ((xfContext*) instance->context)->xfi;
|
|
|
|
cache = instance->context->cache;
|
2011-10-17 04:10:09 +04:00
|
|
|
channels = xfi->_context->channels;
|
2011-08-07 17:52:40 +04:00
|
|
|
|
2011-11-19 21:19:16 +04:00
|
|
|
if (xf_get_pixmap_info(xfi) != true)
|
|
|
|
return false;
|
2011-08-07 21:41:54 +04:00
|
|
|
|
2011-10-21 02:18:45 +04:00
|
|
|
xf_register_graphics(instance->context->graphics);
|
|
|
|
|
2011-09-23 08:06:39 +04:00
|
|
|
if (xfi->sw_gdi)
|
|
|
|
{
|
2011-10-16 08:50:10 +04:00
|
|
|
rdpGdi* gdi;
|
2011-09-28 01:10:07 +04:00
|
|
|
uint32 flags;
|
|
|
|
|
2011-12-30 19:00:03 +04:00
|
|
|
flags = CLRCONV_ALPHA;
|
2011-09-28 01:10:07 +04:00
|
|
|
|
|
|
|
if (xfi->bpp > 16)
|
|
|
|
flags |= CLRBUF_32BPP;
|
|
|
|
else
|
|
|
|
flags |= CLRBUF_16BPP;
|
|
|
|
|
2011-10-05 02:35:47 +04:00
|
|
|
gdi_init(instance, flags, NULL);
|
2011-10-16 08:50:10 +04:00
|
|
|
gdi = instance->context->gdi;
|
2011-09-23 08:06:39 +04:00
|
|
|
xfi->primary_buffer = gdi->primary_buffer;
|
2011-10-29 18:01:50 +04:00
|
|
|
|
|
|
|
rfx_context = gdi->rfx_context;
|
2011-09-23 08:06:39 +04:00
|
|
|
}
|
|
|
|
else
|
2011-08-26 22:48:51 +04:00
|
|
|
{
|
|
|
|
xfi->srcBpp = instance->settings->color_depth;
|
|
|
|
xf_gdi_register_update_callbacks(instance->update);
|
2011-09-12 05:22:03 +04:00
|
|
|
|
2012-02-02 03:42:20 +04:00
|
|
|
xfi->hdc = gdi_CreateDC(xfi->clrconv, xfi->bpp);
|
2011-09-23 08:06:39 +04:00
|
|
|
|
2011-09-12 05:22:03 +04:00
|
|
|
if (instance->settings->rfx_codec)
|
2011-10-29 18:01:50 +04:00
|
|
|
{
|
|
|
|
rfx_context = (void*) rfx_context_new();
|
|
|
|
xfi->rfx_context = rfx_context;
|
|
|
|
}
|
2011-10-03 23:42:32 +04:00
|
|
|
|
|
|
|
if (instance->settings->ns_codec)
|
|
|
|
xfi->nsc_context = (void*) nsc_context_new();
|
2011-08-26 22:48:51 +04:00
|
|
|
}
|
2011-08-26 02:07:52 +04:00
|
|
|
|
2011-10-29 18:01:50 +04:00
|
|
|
if (rfx_context)
|
|
|
|
{
|
|
|
|
#ifdef WITH_SSE2
|
|
|
|
/* detect only if needed */
|
|
|
|
rfx_context_set_cpu_opt(rfx_context, xf_detect_cpu());
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2011-10-07 23:50:07 +04:00
|
|
|
xfi->width = instance->settings->width;
|
|
|
|
xfi->height = instance->settings->height;
|
2011-08-07 21:41:54 +04:00
|
|
|
|
2011-10-04 14:44:52 +04:00
|
|
|
xf_create_window(xfi);
|
2011-08-07 21:41:54 +04:00
|
|
|
|
2011-08-18 09:16:49 +04:00
|
|
|
memset(&gcv, 0, sizeof(gcv));
|
|
|
|
xfi->modifier_map = XGetModifierMapping(xfi->display);
|
2011-08-07 21:41:54 +04:00
|
|
|
|
2011-10-10 05:23:18 +04:00
|
|
|
xfi->gc = XCreateGC(xfi->display, xfi->drawable, GCGraphicsExposures, &gcv);
|
|
|
|
xfi->primary = XCreatePixmap(xfi->display, xfi->drawable, xfi->width, xfi->height, xfi->depth);
|
2011-08-26 22:48:51 +04:00
|
|
|
xfi->drawing = xfi->primary;
|
2011-08-07 21:41:54 +04:00
|
|
|
|
2011-10-10 05:23:18 +04:00
|
|
|
xfi->bitmap_mono = XCreatePixmap(xfi->display, xfi->drawable, 8, 8, 1);
|
2011-09-12 06:32:22 +04:00
|
|
|
xfi->gc_mono = XCreateGC(xfi->display, xfi->bitmap_mono, GCGraphicsExposures, &gcv);
|
|
|
|
|
2011-08-07 21:41:54 +04:00
|
|
|
XSetForeground(xfi->display, xfi->gc, BlackPixelOfScreen(xfi->screen));
|
|
|
|
XFillRectangle(xfi->display, xfi->primary, xfi->gc, 0, 0, xfi->width, xfi->height);
|
|
|
|
|
2011-08-07 22:09:18 +04:00
|
|
|
xfi->image = XCreateImage(xfi->display, xfi->visual, xfi->depth, ZPixmap, 0,
|
2011-09-23 08:06:39 +04:00
|
|
|
(char*) xfi->primary_buffer, xfi->width, xfi->height, xfi->scanline_pad, 0);
|
2011-08-07 22:09:18 +04:00
|
|
|
|
2011-09-14 22:47:04 +04:00
|
|
|
xfi->bmp_codec_none = (uint8*) xmalloc(64 * 64 * 4);
|
|
|
|
|
2011-09-23 08:06:39 +04:00
|
|
|
if (xfi->sw_gdi)
|
|
|
|
{
|
|
|
|
instance->update->BeginPaint = xf_sw_begin_paint;
|
|
|
|
instance->update->EndPaint = xf_sw_end_paint;
|
|
|
|
instance->update->DesktopResize = xf_sw_desktop_resize;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
instance->update->BeginPaint = xf_hw_begin_paint;
|
|
|
|
instance->update->EndPaint = xf_hw_end_paint;
|
|
|
|
instance->update->DesktopResize = xf_hw_desktop_resize;
|
|
|
|
}
|
2011-08-07 17:52:40 +04:00
|
|
|
|
2011-10-12 02:51:45 +04:00
|
|
|
pointer_cache_register_callbacks(instance->update);
|
2011-09-29 08:33:16 +04:00
|
|
|
|
2011-11-19 21:19:16 +04:00
|
|
|
if (xfi->sw_gdi != true)
|
2011-10-13 23:51:07 +04:00
|
|
|
{
|
2011-11-24 22:01:34 +04:00
|
|
|
glyph_cache_register_callbacks(instance->update);
|
2011-10-21 07:15:18 +04:00
|
|
|
brush_cache_register_callbacks(instance->update);
|
2011-10-13 23:51:07 +04:00
|
|
|
bitmap_cache_register_callbacks(instance->update);
|
|
|
|
offscreen_cache_register_callbacks(instance->update);
|
2011-11-11 11:07:53 +04:00
|
|
|
palette_cache_register_callbacks(instance->update);
|
2011-10-13 23:51:07 +04:00
|
|
|
}
|
|
|
|
|
2011-10-16 08:50:10 +04:00
|
|
|
instance->context->rail = rail_new(instance->settings);
|
|
|
|
rail_register_update_callbacks(instance->context->rail, instance->update);
|
|
|
|
xf_rail_register_callbacks(xfi, instance->context->rail);
|
2011-08-16 08:22:00 +04:00
|
|
|
|
2011-10-17 04:10:09 +04:00
|
|
|
freerdp_channels_post_connect(channels, instance);
|
2011-08-07 17:52:40 +04:00
|
|
|
|
2011-09-20 12:27:59 +04:00
|
|
|
xf_tsmf_init(xfi, xv_port);
|
2011-09-23 18:49:59 +04:00
|
|
|
|
2012-01-02 13:27:04 +04:00
|
|
|
xf_cliprdr_init(xfi, channels);
|
2011-09-20 12:27:59 +04:00
|
|
|
|
2011-11-19 21:19:16 +04:00
|
|
|
return true;
|
2011-08-07 17:52:40 +04:00
|
|
|
}
|
|
|
|
|
2012-02-26 00:55:59 +04:00
|
|
|
/** Callback set in the rdp_freerdp structure, and used to get the user's password,
|
|
|
|
* if required to establish the connection.
|
|
|
|
* This function is actually called in credssp_ntlmssp_client_init()
|
|
|
|
* @see rdp_server_accept_nego() and rdp_check_fds()
|
|
|
|
* @param instance - pointer to the rdp_freerdp structure that contains the connection settings
|
|
|
|
* @param username - unused
|
|
|
|
* @param password - on return: pointer to a character string that will be filled by the password entered by the user.
|
|
|
|
* Note that this character string will be allocated inside the function, and needs to be deallocated by the caller
|
|
|
|
* using xfree(), even in case this function fails.
|
|
|
|
* @param domain - unused
|
|
|
|
* @return true if a password was successfully entered. See freerdp_passphrase_read() for more details.
|
|
|
|
*/
|
2011-09-29 09:03:07 +04:00
|
|
|
boolean xf_authenticate(freerdp* instance, char** username, char** password, char** domain)
|
|
|
|
{
|
2012-02-26 00:55:59 +04:00
|
|
|
// FIXME: seems this callback may be called when 'username' is not known.
|
|
|
|
// But it doesn't do anything to fix it...
|
2011-09-29 09:03:07 +04:00
|
|
|
*password = xmalloc(password_size * sizeof(char));
|
|
|
|
|
|
|
|
if (freerdp_passphrase_read("Password: ", *password, password_size) == NULL)
|
2011-11-19 21:19:16 +04:00
|
|
|
return false;
|
2011-09-29 09:03:07 +04:00
|
|
|
|
2011-11-19 21:19:16 +04:00
|
|
|
return true;
|
2011-09-29 09:03:07 +04:00
|
|
|
}
|
|
|
|
|
2012-02-26 00:55:59 +04:00
|
|
|
/** Callback set in the rdp_freerdp structure, and used to make a certificate validation
|
|
|
|
* when the connection requires it.
|
|
|
|
* This function will actually be called by tls_verify_certificate().
|
|
|
|
* @see rdp_client_connect() and tls_connect()
|
|
|
|
* @param instance - pointer to the rdp_freerdp structure that contains the connection settings
|
|
|
|
* @param subject
|
|
|
|
* @param issuer
|
|
|
|
* @param fingerprint
|
|
|
|
* @return true if the certificate is trusted. false otherwise.
|
|
|
|
*/
|
2011-10-18 19:02:05 +04:00
|
|
|
boolean xf_verify_certificate(freerdp* instance, char* subject, char* issuer, char* fingerprint)
|
|
|
|
{
|
2012-02-04 11:21:39 +04:00
|
|
|
char answer;
|
|
|
|
|
2011-10-18 19:02:05 +04:00
|
|
|
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 "
|
2011-12-10 20:23:48 +04:00
|
|
|
"the CA certificate in your certificate store, or the certificate has expired. "
|
2011-10-18 19:02:05 +04:00
|
|
|
"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 (answer == 'y' || answer == 'Y')
|
|
|
|
{
|
2011-11-19 21:19:16 +04:00
|
|
|
return true;
|
2011-10-18 19:02:05 +04:00
|
|
|
}
|
|
|
|
else if (answer == 'n' || answer == 'N')
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2012-02-04 11:21:39 +04:00
|
|
|
printf("\n");
|
2011-10-18 19:02:05 +04:00
|
|
|
}
|
|
|
|
|
2011-11-19 21:19:16 +04:00
|
|
|
return false;
|
2011-10-18 19:02:05 +04:00
|
|
|
}
|
|
|
|
|
2012-02-26 00:55:59 +04:00
|
|
|
/** Used to parse xfreerdp-specific commandline parameters.
|
|
|
|
* This function is provided as a parameter to freerdp_parse_args(), that will call it
|
|
|
|
* each time a parameter is not recognized by the library.
|
|
|
|
* @see xf_pre_connect(), where freerdp_parse_args() is called.
|
|
|
|
*
|
|
|
|
* @param settings
|
|
|
|
* @param opt
|
|
|
|
* @param val
|
|
|
|
* @param user_data
|
|
|
|
* @return the number of parameters that where taken into account.
|
|
|
|
* 0 means no options recognized.
|
|
|
|
* freerdp_parse_args() will use this number to move forward in the parameters parsing.
|
|
|
|
*/
|
2011-10-17 05:39:11 +04:00
|
|
|
int xf_process_client_args(rdpSettings* settings, const char* opt, const char* val, void* user_data)
|
2011-08-26 06:01:33 +04:00
|
|
|
{
|
2011-09-20 12:27:59 +04:00
|
|
|
int argc = 0;
|
2011-12-21 21:50:22 +04:00
|
|
|
xfInfo* xfi = (xfInfo*) user_data;
|
2011-09-20 12:27:59 +04:00
|
|
|
|
2011-08-26 06:01:33 +04:00
|
|
|
if (strcmp("--kbd-list", opt) == 0)
|
|
|
|
{
|
|
|
|
int i;
|
2012-02-20 02:36:39 +04:00
|
|
|
RDP_KEYBOARD_LAYOUT* layouts;
|
2011-08-26 06:01:33 +04:00
|
|
|
|
2012-02-19 07:04:28 +04:00
|
|
|
layouts = freerdp_keyboard_get_layouts(RDP_KEYBOARD_LAYOUT_TYPE_STANDARD);
|
2012-02-21 21:00:02 +04:00
|
|
|
|
2011-08-26 06:01:33 +04:00
|
|
|
printf("\nKeyboard Layouts\n");
|
|
|
|
for (i = 0; layouts[i].code; i++)
|
2012-02-21 21:00:02 +04:00
|
|
|
{
|
2011-08-26 06:01:33 +04:00
|
|
|
printf("0x%08X\t%s\n", layouts[i].code, layouts[i].name);
|
2012-02-21 21:00:02 +04:00
|
|
|
xfree(layouts[i].name);
|
|
|
|
}
|
|
|
|
xfree(layouts);
|
2011-08-26 06:01:33 +04:00
|
|
|
|
2012-02-19 07:04:28 +04:00
|
|
|
layouts = freerdp_keyboard_get_layouts(RDP_KEYBOARD_LAYOUT_TYPE_VARIANT);
|
2012-02-21 21:00:02 +04:00
|
|
|
|
2011-08-26 06:01:33 +04:00
|
|
|
printf("\nKeyboard Layout Variants\n");
|
|
|
|
for (i = 0; layouts[i].code; i++)
|
2012-02-21 21:00:02 +04:00
|
|
|
{
|
2011-08-26 06:01:33 +04:00
|
|
|
printf("0x%08X\t%s\n", layouts[i].code, layouts[i].name);
|
2012-02-21 21:00:02 +04:00
|
|
|
xfree(layouts[i].name);
|
|
|
|
}
|
|
|
|
xfree(layouts);
|
2011-08-26 06:01:33 +04:00
|
|
|
|
2012-02-19 07:04:28 +04:00
|
|
|
layouts = freerdp_keyboard_get_layouts(RDP_KEYBOARD_LAYOUT_TYPE_IME);
|
2012-02-21 21:00:02 +04:00
|
|
|
|
2011-08-26 06:01:33 +04:00
|
|
|
printf("\nKeyboard Input Method Editors (IMEs)\n");
|
|
|
|
for (i = 0; layouts[i].code; i++)
|
2012-02-21 21:00:02 +04:00
|
|
|
{
|
2011-08-26 06:01:33 +04:00
|
|
|
printf("0x%08X\t%s\n", layouts[i].code, layouts[i].name);
|
2012-02-21 21:00:02 +04:00
|
|
|
xfree(layouts[i].name);
|
|
|
|
}
|
|
|
|
xfree(layouts);
|
2011-08-26 06:01:33 +04:00
|
|
|
|
|
|
|
exit(0);
|
|
|
|
}
|
2011-09-20 12:27:59 +04:00
|
|
|
else if (strcmp("--xv-port", opt) == 0)
|
|
|
|
{
|
|
|
|
xv_port = atoi(val);
|
|
|
|
argc = 2;
|
|
|
|
}
|
2011-12-21 21:50:22 +04:00
|
|
|
else if (strcmp("--dbg-x11", opt) == 0)
|
|
|
|
{
|
|
|
|
xfi->debug = true;
|
|
|
|
argc = 1;
|
|
|
|
}
|
2011-08-26 06:01:33 +04:00
|
|
|
|
2011-09-20 12:27:59 +04:00
|
|
|
return argc;
|
2011-08-26 06:01:33 +04:00
|
|
|
}
|
|
|
|
|
2012-02-26 00:55:59 +04:00
|
|
|
/** Used to load plugins based on the commandline parameters.
|
|
|
|
* This function is provided as a parameter to freerdp_parse_args(), that will call it
|
|
|
|
* each time a plugin name is found on the command line.
|
|
|
|
* This function just calls freerdp_channels_load_plugin() for the given plugin, and always returns 1.
|
|
|
|
* @see xf_pre_connect(), where freerdp_parse_args() is called.
|
|
|
|
*
|
|
|
|
* @param settings
|
|
|
|
* @param name
|
|
|
|
* @param plugin_data
|
|
|
|
* @param user_data
|
|
|
|
* @return 1
|
|
|
|
*/
|
2011-08-18 01:28:26 +04:00
|
|
|
int xf_process_plugin_args(rdpSettings* settings, const char* name, RDP_PLUGIN_DATA* plugin_data, void* user_data)
|
2011-08-07 17:52:40 +04:00
|
|
|
{
|
2011-10-17 05:39:11 +04:00
|
|
|
rdpChannels* channels = (rdpChannels*) user_data;
|
2011-08-07 17:52:40 +04:00
|
|
|
|
2011-09-02 21:29:17 +04:00
|
|
|
printf("loading plugin %s\n", name);
|
2011-10-17 05:39:11 +04:00
|
|
|
freerdp_channels_load_plugin(channels, settings, name, plugin_data);
|
2012-02-26 00:55:59 +04:00
|
|
|
// FIXME we should check the return code for freerdp_channels_load_plugin()
|
|
|
|
// and report any error to the caller. freerdp_parse_args() actually expect to get
|
|
|
|
// an error code when there is a loading error.
|
|
|
|
// Is it as easy as "return freerdp_channels_load_plugin()" ?
|
2011-08-07 17:52:40 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2011-08-07 21:41:54 +04:00
|
|
|
int xf_receive_channel_data(freerdp* instance, int channelId, uint8* data, int size, int flags, int total_size)
|
2011-08-07 17:52:40 +04:00
|
|
|
{
|
2011-10-16 22:57:15 +04:00
|
|
|
return freerdp_channels_data(instance, channelId, data, size, flags, total_size);
|
2011-08-07 17:52:40 +04:00
|
|
|
}
|
|
|
|
|
2011-10-16 22:57:15 +04:00
|
|
|
void xf_process_channel_event(rdpChannels* chanman, freerdp* instance)
|
2011-08-07 17:52:40 +04:00
|
|
|
{
|
2011-08-18 05:33:22 +04:00
|
|
|
xfInfo* xfi;
|
2011-08-18 01:28:26 +04:00
|
|
|
RDP_EVENT* event;
|
2011-08-07 17:52:40 +04:00
|
|
|
|
2011-10-16 08:50:10 +04:00
|
|
|
xfi = ((xfContext*) instance->context)->xfi;
|
2011-08-18 05:33:22 +04:00
|
|
|
|
2011-10-16 22:57:15 +04:00
|
|
|
event = freerdp_channels_pop_event(chanman);
|
2011-08-18 05:33:22 +04:00
|
|
|
|
2011-08-07 17:52:40 +04:00
|
|
|
if (event)
|
|
|
|
{
|
2011-08-18 05:33:22 +04:00
|
|
|
switch (event->event_class)
|
|
|
|
{
|
|
|
|
case RDP_EVENT_CLASS_RAIL:
|
|
|
|
xf_process_rail_event(xfi, chanman, event);
|
|
|
|
break;
|
|
|
|
|
2011-09-20 12:27:59 +04:00
|
|
|
case RDP_EVENT_CLASS_TSMF:
|
|
|
|
xf_process_tsmf_event(xfi, event);
|
2011-08-18 05:33:22 +04:00
|
|
|
break;
|
|
|
|
|
2011-09-20 12:27:59 +04:00
|
|
|
case RDP_EVENT_CLASS_CLIPRDR:
|
2011-09-23 07:37:17 +04:00
|
|
|
xf_process_cliprdr_event(xfi, event);
|
2011-08-07 17:52:40 +04:00
|
|
|
break;
|
2011-09-20 12:27:59 +04:00
|
|
|
|
2011-08-07 17:52:40 +04:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2011-09-20 12:27:59 +04:00
|
|
|
|
2011-08-07 17:52:40 +04:00
|
|
|
freerdp_event_free(event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-07 21:41:54 +04:00
|
|
|
void xf_window_free(xfInfo* xfi)
|
|
|
|
{
|
2011-10-16 08:50:10 +04:00
|
|
|
rdpContext* context = xfi->instance->context;
|
|
|
|
|
2011-08-07 21:41:54 +04:00
|
|
|
XFreeModifiermap(xfi->modifier_map);
|
|
|
|
xfi->modifier_map = 0;
|
|
|
|
|
|
|
|
XFreeGC(xfi->display, xfi->gc);
|
|
|
|
xfi->gc = 0;
|
|
|
|
|
2012-02-02 06:11:46 +04:00
|
|
|
XFreeGC(xfi->display, xfi->gc_mono);
|
|
|
|
xfi->gc_mono = 0;
|
|
|
|
|
2012-01-02 13:27:04 +04:00
|
|
|
if (xfi->window != NULL)
|
|
|
|
{
|
|
|
|
xf_DestroyWindow(xfi, xfi->window);
|
|
|
|
xfi->window = NULL;
|
|
|
|
}
|
2011-08-07 21:41:54 +04:00
|
|
|
|
|
|
|
if (xfi->primary)
|
|
|
|
{
|
|
|
|
XFreePixmap(xfi->display, xfi->primary);
|
|
|
|
xfi->primary = 0;
|
|
|
|
}
|
2011-09-07 09:51:29 +04:00
|
|
|
|
|
|
|
if (xfi->image)
|
|
|
|
{
|
|
|
|
xfi->image->data = NULL;
|
|
|
|
XDestroyImage(xfi->image);
|
|
|
|
xfi->image = NULL;
|
|
|
|
}
|
|
|
|
|
2011-10-17 05:39:11 +04:00
|
|
|
if (context != NULL)
|
2011-09-07 09:51:29 +04:00
|
|
|
{
|
2011-10-17 05:39:11 +04:00
|
|
|
cache_free(context->cache);
|
|
|
|
context->cache = NULL;
|
2012-02-03 18:27:04 +04:00
|
|
|
|
2011-10-17 05:39:11 +04:00
|
|
|
rail_free(context->rail);
|
|
|
|
context->rail = NULL;
|
2011-09-07 09:51:29 +04:00
|
|
|
}
|
2011-09-07 10:19:11 +04:00
|
|
|
|
2011-10-19 00:50:40 +04:00
|
|
|
if (xfi->rfx_context)
|
|
|
|
{
|
|
|
|
rfx_context_free(xfi->rfx_context);
|
|
|
|
xfi->rfx_context = NULL;
|
|
|
|
}
|
2012-02-02 03:42:20 +04:00
|
|
|
|
|
|
|
freerdp_clrconv_free(xfi->clrconv);
|
2012-02-10 06:01:13 +04:00
|
|
|
|
|
|
|
if (xfi->hdc)
|
|
|
|
gdi_DeleteDC(xfi->hdc);
|
2011-09-20 12:27:59 +04:00
|
|
|
|
|
|
|
xf_tsmf_uninit(xfi);
|
2011-09-23 07:37:17 +04:00
|
|
|
xf_cliprdr_uninit(xfi);
|
2011-08-07 21:41:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void xf_free(xfInfo* xfi)
|
|
|
|
{
|
|
|
|
xf_window_free(xfi);
|
2012-02-02 03:42:20 +04:00
|
|
|
|
2012-02-03 18:27:04 +04:00
|
|
|
xfree(xfi->bmp_codec_none);
|
2012-02-02 03:42:20 +04:00
|
|
|
|
2011-08-07 21:41:54 +04:00
|
|
|
XCloseDisplay(xfi->display);
|
2012-02-02 06:11:46 +04:00
|
|
|
|
2011-08-13 07:46:00 +04:00
|
|
|
xfree(xfi);
|
2011-08-07 21:41:54 +04:00
|
|
|
}
|
|
|
|
|
2012-02-26 00:55:59 +04:00
|
|
|
/** Main loop for the rdp connection.
|
|
|
|
* It will be run from the thread's entry point (thread_func()).
|
|
|
|
* It initiates the connection, and will continue to run until the session ends,
|
|
|
|
* processing events as they are received.
|
|
|
|
* @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 successfull)
|
|
|
|
*/
|
2011-08-13 07:46:00 +04:00
|
|
|
int xfreerdp_run(freerdp* instance)
|
2011-08-07 17:52:40 +04:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int fds;
|
2011-08-07 21:41:54 +04:00
|
|
|
xfInfo* xfi;
|
2011-08-07 17:52:40 +04:00
|
|
|
int max_fds;
|
|
|
|
int rcount;
|
|
|
|
int wcount;
|
2011-12-12 03:05:32 +04:00
|
|
|
int ret = 0;
|
2011-08-07 17:52:40 +04:00
|
|
|
void* rfds[32];
|
|
|
|
void* wfds[32];
|
|
|
|
fd_set rfds_set;
|
|
|
|
fd_set wfds_set;
|
2011-12-12 03:05:32 +04:00
|
|
|
int select_status;
|
2011-10-17 04:10:09 +04:00
|
|
|
rdpChannels* channels;
|
2011-12-12 03:05:32 +04:00
|
|
|
struct timeval timeout;
|
2011-08-07 17:52:40 +04:00
|
|
|
|
|
|
|
memset(rfds, 0, sizeof(rfds));
|
|
|
|
memset(wfds, 0, sizeof(wfds));
|
2011-12-12 03:05:32 +04:00
|
|
|
memset(&timeout, 0, sizeof(struct timeval));
|
2011-08-07 17:52:40 +04:00
|
|
|
|
2011-10-17 05:02:28 +04:00
|
|
|
if (!freerdp_connect(instance))
|
2011-10-24 22:46:19 +04:00
|
|
|
return XF_EXIT_CONN_FAILED;
|
2011-08-13 07:46:00 +04:00
|
|
|
|
2011-10-16 08:50:10 +04:00
|
|
|
xfi = ((xfContext*) instance->context)->xfi;
|
2011-10-17 04:10:09 +04:00
|
|
|
channels = instance->context->channels;
|
2011-08-07 17:52:40 +04:00
|
|
|
|
2012-02-07 01:37:18 +04:00
|
|
|
while (!xfi->disconnect && !freerdp_shall_disconnect(instance))
|
2011-08-07 17:52:40 +04:00
|
|
|
{
|
|
|
|
rcount = 0;
|
|
|
|
wcount = 0;
|
|
|
|
|
2011-11-19 21:19:16 +04:00
|
|
|
if (freerdp_get_fds(instance, rfds, &rcount, wfds, &wcount) != true)
|
2011-08-07 17:52:40 +04:00
|
|
|
{
|
|
|
|
printf("Failed to get FreeRDP file descriptor\n");
|
2011-10-24 22:46:19 +04:00
|
|
|
ret = XF_EXIT_CONN_FAILED;
|
2011-08-07 17:52:40 +04:00
|
|
|
break;
|
|
|
|
}
|
2011-11-19 21:19:16 +04:00
|
|
|
if (freerdp_channels_get_fds(channels, instance, rfds, &rcount, wfds, &wcount) != true)
|
2011-08-07 17:52:40 +04:00
|
|
|
{
|
|
|
|
printf("Failed to get channel manager file descriptor\n");
|
2011-10-24 22:46:19 +04:00
|
|
|
ret = XF_EXIT_CONN_FAILED;
|
2011-08-07 17:52:40 +04:00
|
|
|
break;
|
|
|
|
}
|
2011-11-19 21:19:16 +04:00
|
|
|
if (xf_get_fds(instance, rfds, &rcount, wfds, &wcount) != true)
|
2011-08-07 17:52:40 +04:00
|
|
|
{
|
2011-08-07 21:41:54 +04:00
|
|
|
printf("Failed to get xfreerdp file descriptor\n");
|
2011-10-24 22:46:19 +04:00
|
|
|
ret = XF_EXIT_CONN_FAILED;
|
2011-08-07 17:52:40 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
max_fds = 0;
|
|
|
|
FD_ZERO(&rfds_set);
|
2011-08-16 07:13:30 +04:00
|
|
|
FD_ZERO(&wfds_set);
|
2011-08-07 17:52:40 +04:00
|
|
|
|
|
|
|
for (i = 0; i < rcount; i++)
|
|
|
|
{
|
|
|
|
fds = (int)(long)(rfds[i]);
|
|
|
|
|
|
|
|
if (fds > max_fds)
|
|
|
|
max_fds = fds;
|
|
|
|
|
|
|
|
FD_SET(fds, &rfds_set);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (max_fds == 0)
|
|
|
|
break;
|
|
|
|
|
2011-12-12 03:05:32 +04:00
|
|
|
timeout.tv_sec = 5;
|
|
|
|
select_status = select(max_fds + 1, &rfds_set, &wfds_set, NULL, &timeout);
|
|
|
|
|
|
|
|
if (select_status == 0)
|
|
|
|
{
|
|
|
|
//freerdp_send_keep_alive(instance);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else if (select_status == -1)
|
2011-08-07 17:52:40 +04:00
|
|
|
{
|
|
|
|
/* these are not really errors */
|
|
|
|
if (!((errno == EAGAIN) ||
|
|
|
|
(errno == EWOULDBLOCK) ||
|
|
|
|
(errno == EINPROGRESS) ||
|
|
|
|
(errno == EINTR))) /* signal occurred */
|
|
|
|
{
|
2011-08-07 21:41:54 +04:00
|
|
|
printf("xfreerdp_run: select failed\n");
|
2011-08-07 17:52:40 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-19 21:19:16 +04:00
|
|
|
if (freerdp_check_fds(instance) != true)
|
2011-08-07 17:52:40 +04:00
|
|
|
{
|
|
|
|
printf("Failed to check FreeRDP file descriptor\n");
|
|
|
|
break;
|
|
|
|
}
|
2011-11-19 21:19:16 +04:00
|
|
|
if (xf_check_fds(instance, &rfds_set) != true)
|
2011-08-07 17:52:40 +04:00
|
|
|
{
|
2011-08-07 21:41:54 +04:00
|
|
|
printf("Failed to check xfreerdp file descriptor\n");
|
2011-08-07 17:52:40 +04:00
|
|
|
break;
|
|
|
|
}
|
2011-11-19 21:19:16 +04:00
|
|
|
if (freerdp_channels_check_fds(channels, instance) != true)
|
2011-08-07 17:52:40 +04:00
|
|
|
{
|
|
|
|
printf("Failed to check channel manager file descriptor\n");
|
|
|
|
break;
|
|
|
|
}
|
2011-10-17 04:10:09 +04:00
|
|
|
xf_process_channel_event(channels, instance);
|
2011-08-07 17:52:40 +04:00
|
|
|
}
|
|
|
|
|
2011-10-24 22:46:19 +04:00
|
|
|
if (!ret)
|
|
|
|
ret = freerdp_error_info(instance);
|
|
|
|
|
2011-10-17 04:10:09 +04:00
|
|
|
freerdp_channels_close(channels, instance);
|
|
|
|
freerdp_channels_free(channels);
|
2011-10-17 05:02:28 +04:00
|
|
|
freerdp_disconnect(instance);
|
2011-09-07 09:51:29 +04:00
|
|
|
gdi_free(instance);
|
2011-08-07 21:41:54 +04:00
|
|
|
xf_free(xfi);
|
2011-08-07 17:52:40 +04:00
|
|
|
|
2012-02-27 19:55:49 +04:00
|
|
|
freerdp_context_free(instance);
|
|
|
|
|
2011-11-16 00:41:00 +04:00
|
|
|
freerdp_free(instance);
|
|
|
|
|
2011-10-24 22:46:19 +04:00
|
|
|
return ret;
|
2011-08-07 17:52:40 +04:00
|
|
|
}
|
|
|
|
|
2012-02-26 00:55:59 +04:00
|
|
|
/** Entry point for the thread that will deal with the session.
|
|
|
|
* It just calls xfreerdp_run() using the given instance as parameter.
|
|
|
|
* @param - pointer to a thread_data structure that contains the initialized connection.
|
|
|
|
*/
|
2011-08-07 17:52:40 +04:00
|
|
|
void* thread_func(void* param)
|
|
|
|
{
|
|
|
|
struct thread_data* data;
|
|
|
|
data = (struct thread_data*) param;
|
|
|
|
|
2011-10-24 22:46:19 +04:00
|
|
|
g_disconnect_reason = xfreerdp_run(data->instance);
|
2011-08-07 17:52:40 +04:00
|
|
|
|
|
|
|
xfree(data);
|
|
|
|
|
|
|
|
pthread_detach(pthread_self());
|
|
|
|
|
|
|
|
g_thread_count--;
|
|
|
|
|
|
|
|
if (g_thread_count < 1)
|
2011-08-13 07:46:00 +04:00
|
|
|
freerdp_sem_signal(g_sem);
|
2011-08-07 17:52:40 +04:00
|
|
|
|
2012-02-02 06:11:46 +04:00
|
|
|
pthread_exit(NULL);
|
2011-08-07 17:52:40 +04:00
|
|
|
}
|
|
|
|
|
2011-10-24 22:46:19 +04:00
|
|
|
static uint8 exit_code_from_disconnect_reason(uint32 reason)
|
|
|
|
{
|
|
|
|
if (reason == 0 ||
|
|
|
|
(reason >= XF_EXIT_PARSE_ARGUMENTS && reason <= XF_EXIT_CONN_FAILED))
|
|
|
|
return reason;
|
|
|
|
|
|
|
|
/* Licence error set */
|
|
|
|
else if (reason >= 0x100 && reason <= 0x10A)
|
|
|
|
reason -= 0x100 + XF_EXIT_LICENSE_INTERNAL;
|
|
|
|
|
|
|
|
/* RDP protocol error set */
|
|
|
|
else if (reason >= 0x10c9 && reason <= 0x1193)
|
|
|
|
reason = XF_EXIT_RDP;
|
|
|
|
|
|
|
|
/* There's no need to test protocol-independent codes: they match */
|
|
|
|
else if (!(reason <= 0xB))
|
|
|
|
reason = XF_EXIT_UNKNOWN;
|
|
|
|
|
|
|
|
return reason;
|
|
|
|
}
|
|
|
|
|
2011-08-07 17:52:40 +04:00
|
|
|
int main(int argc, char* argv[])
|
|
|
|
{
|
|
|
|
pthread_t thread;
|
|
|
|
freerdp* instance;
|
2011-09-29 09:03:07 +04:00
|
|
|
struct thread_data* data;
|
2011-08-07 17:52:40 +04:00
|
|
|
|
2011-09-28 09:27:14 +04:00
|
|
|
freerdp_handle_signals();
|
|
|
|
|
2011-08-09 04:31:21 +04:00
|
|
|
setlocale(LC_ALL, "");
|
|
|
|
|
2011-10-16 22:57:15 +04:00
|
|
|
freerdp_channels_global_init();
|
2011-08-07 17:52:40 +04:00
|
|
|
|
|
|
|
g_sem = freerdp_sem_new(1);
|
|
|
|
|
|
|
|
instance = freerdp_new();
|
|
|
|
instance->PreConnect = xf_pre_connect;
|
|
|
|
instance->PostConnect = xf_post_connect;
|
2011-09-29 09:03:07 +04:00
|
|
|
instance->Authenticate = xf_authenticate;
|
2011-10-18 19:02:05 +04:00
|
|
|
instance->VerifyCertificate = xf_verify_certificate;
|
2011-08-07 17:52:40 +04:00
|
|
|
instance->ReceiveChannelData = xf_receive_channel_data;
|
|
|
|
|
2011-10-21 07:15:18 +04:00
|
|
|
instance->context_size = sizeof(xfContext);
|
|
|
|
instance->ContextNew = (pContextNew) xf_context_new;
|
|
|
|
instance->ContextFree = (pContextFree) xf_context_free;
|
2011-10-16 08:50:10 +04:00
|
|
|
freerdp_context_new(instance);
|
2011-08-07 17:52:40 +04:00
|
|
|
|
2011-10-17 05:39:11 +04:00
|
|
|
instance->context->argc = argc;
|
|
|
|
instance->context->argv = argv;
|
2011-11-19 21:19:16 +04:00
|
|
|
instance->settings->sw_gdi = false;
|
2011-10-25 09:22:56 +04:00
|
|
|
|
2011-08-07 17:52:40 +04:00
|
|
|
data = (struct thread_data*) xzalloc(sizeof(struct thread_data));
|
|
|
|
data->instance = instance;
|
|
|
|
|
|
|
|
g_thread_count++;
|
|
|
|
pthread_create(&thread, 0, thread_func, data);
|
|
|
|
|
|
|
|
while (g_thread_count > 0)
|
|
|
|
{
|
|
|
|
freerdp_sem_wait(g_sem);
|
|
|
|
}
|
|
|
|
|
2011-10-16 22:57:15 +04:00
|
|
|
freerdp_channels_global_uninit();
|
2011-08-07 17:52:40 +04:00
|
|
|
|
2011-10-24 22:46:19 +04:00
|
|
|
return exit_code_from_disconnect_reason(g_disconnect_reason);
|
2011-08-07 17:52:40 +04:00
|
|
|
}
|