|
|
@ -1,25 +1,24 @@
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* xrdp: A Remote Desktop Protocol server.
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* Copyright (C) Jay Sorg 2009-2012
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* 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.
|
|
|
|
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
|
|
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
xrdp: A Remote Desktop Protocol server.
|
|
|
|
|
|
|
|
Copyright (C) Jay Sorg 2009-2010
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for help see
|
|
|
|
for help see
|
|
|
|
http://tronche.com/gui/x/icccm/sec-2.html#s-2
|
|
|
|
http://tronche.com/gui/x/icccm/sec-2.html#s-2
|
|
|
|
.../kde/kdebase/workspace/klipper/clipboardpoll.cpp
|
|
|
|
.../kde/kdebase/workspace/klipper/clipboardpoll.cpp
|
|
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include <X11/Xlib.h>
|
|
|
|
#include <X11/Xlib.h>
|
|
|
@ -29,7 +28,6 @@
|
|
|
|
#include "parse.h"
|
|
|
|
#include "parse.h"
|
|
|
|
#include "os_calls.h"
|
|
|
|
#include "os_calls.h"
|
|
|
|
#include "chansrv.h"
|
|
|
|
#include "chansrv.h"
|
|
|
|
#include "log.h"
|
|
|
|
|
|
|
|
#include "clipboard.h"
|
|
|
|
#include "clipboard.h"
|
|
|
|
|
|
|
|
|
|
|
|
static Atom g_clipboard_atom = 0;
|
|
|
|
static Atom g_clipboard_atom = 0;
|
|
|
@ -80,7 +78,7 @@ clipboard_error_handler(Display* dis, XErrorEvent* xer)
|
|
|
|
char text[256];
|
|
|
|
char text[256];
|
|
|
|
|
|
|
|
|
|
|
|
XGetErrorText(dis, xer->error_code, text, 255);
|
|
|
|
XGetErrorText(dis, xer->error_code, text, 255);
|
|
|
|
log_message(LOG_LEVEL_ERROR,"error [%s]", text);
|
|
|
|
LOGM((LOG_LEVEL_ERROR,"error [%s]", text));
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -91,7 +89,7 @@ clipboard_error_handler(Display* dis, XErrorEvent* xer)
|
|
|
|
int DEFAULT_CC
|
|
|
|
int DEFAULT_CC
|
|
|
|
clipboard_fatal_handler(Display* dis)
|
|
|
|
clipboard_fatal_handler(Display* dis)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
log_message(LOG_LEVEL_ALWAYS,"fatal error, exiting");
|
|
|
|
LOGM((LOG_LEVEL_ALWAYS, "fatal error, exiting"));
|
|
|
|
main_cleanup();
|
|
|
|
main_cleanup();
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -141,7 +139,7 @@ clipboard_init(void)
|
|
|
|
int ver_min;
|
|
|
|
int ver_min;
|
|
|
|
Status st;
|
|
|
|
Status st;
|
|
|
|
|
|
|
|
|
|
|
|
log_message(LOG_LEVEL_DEBUG,"xrdp-chansrv: in clipboard_init");
|
|
|
|
LOGM((LOG_LEVEL_DEBUG, "xrdp-chansrv: in clipboard_init"));
|
|
|
|
if (g_clip_up)
|
|
|
|
if (g_clip_up)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
@ -155,7 +153,7 @@ clipboard_init(void)
|
|
|
|
g_display = XOpenDisplay(0);
|
|
|
|
g_display = XOpenDisplay(0);
|
|
|
|
if (g_display == 0)
|
|
|
|
if (g_display == 0)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
log_message(LOG_LEVEL_ERROR,"clipboard_init: XOpenDisplay failed");
|
|
|
|
LOGM((LOG_LEVEL_ERROR, "clipboard_init: XOpenDisplay failed"));
|
|
|
|
rv = 1;
|
|
|
|
rv = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (rv == 0)
|
|
|
|
if (rv == 0)
|
|
|
@ -163,7 +161,7 @@ clipboard_init(void)
|
|
|
|
g_x_socket = XConnectionNumber(g_display);
|
|
|
|
g_x_socket = XConnectionNumber(g_display);
|
|
|
|
if (g_x_socket == 0)
|
|
|
|
if (g_x_socket == 0)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
log_message(LOG_LEVEL_ERROR,"clipboard_init: XConnectionNumber failed");
|
|
|
|
LOGM((LOG_LEVEL_ERROR, "clipboard_init: XConnectionNumber failed"));
|
|
|
|
rv = 2;
|
|
|
|
rv = 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
g_x_wait_obj = g_create_wait_obj_from_socket(g_x_socket, 0);
|
|
|
|
g_x_wait_obj = g_create_wait_obj_from_socket(g_x_socket, 0);
|
|
|
@ -173,7 +171,7 @@ clipboard_init(void)
|
|
|
|
g_clipboard_atom = XInternAtom(g_display, "CLIPBOARD", False);
|
|
|
|
g_clipboard_atom = XInternAtom(g_display, "CLIPBOARD", False);
|
|
|
|
if (g_clipboard_atom == None)
|
|
|
|
if (g_clipboard_atom == None)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
log_message(LOG_LEVEL_ERROR,"clipboard_init: XInternAtom failed");
|
|
|
|
LOGM((LOG_LEVEL_ERROR, "clipboard_init: XInternAtom failed"));
|
|
|
|
rv = 3;
|
|
|
|
rv = 3;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -181,15 +179,17 @@ clipboard_init(void)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (!XFixesQueryExtension(g_display, &g_xfixes_event_base, &dummy))
|
|
|
|
if (!XFixesQueryExtension(g_display, &g_xfixes_event_base, &dummy))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
log_message(LOG_LEVEL_ERROR,"clipboard_init: no xfixes");
|
|
|
|
LOGM((LOG_LEVEL_ERROR, "clipboard_init: no xfixes"));
|
|
|
|
rv = 5;
|
|
|
|
rv = 5;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (rv == 0)
|
|
|
|
if (rv == 0)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
log_message(LOG_LEVEL_ERROR,"clipboard_init: g_xfixes_event_base %d", g_xfixes_event_base);
|
|
|
|
LOGM((LOG_LEVEL_ERROR, "clipboard_init: g_xfixes_event_base %d",
|
|
|
|
|
|
|
|
g_xfixes_event_base));
|
|
|
|
st = XFixesQueryVersion(g_display, &ver_maj, &ver_min);
|
|
|
|
st = XFixesQueryVersion(g_display, &ver_maj, &ver_min);
|
|
|
|
log_message(LOG_LEVEL_ERROR,"clipboard_init st %d, maj %d min %d", st, ver_maj, ver_min);
|
|
|
|
LOGM((LOG_LEVEL_ERROR, "clipboard_init st %d, maj %d min %d", st,
|
|
|
|
|
|
|
|
ver_maj, ver_min));
|
|
|
|
g_screen_num = DefaultScreen(g_display);
|
|
|
|
g_screen_num = DefaultScreen(g_display);
|
|
|
|
g_screen = ScreenOfDisplay(g_display, g_screen_num);
|
|
|
|
g_screen = ScreenOfDisplay(g_display, g_screen_num);
|
|
|
|
g_clip_property_atom = XInternAtom(g_display, "XRDP_CLIP_PROPERTY_ATOM",
|
|
|
|
g_clip_property_atom = XInternAtom(g_display, "XRDP_CLIP_PROPERTY_ATOM",
|
|
|
@ -223,13 +223,13 @@ clipboard_init(void)
|
|
|
|
out_uint32_le(s, 0); /* extra 4 bytes ? */
|
|
|
|
out_uint32_le(s, 0); /* extra 4 bytes ? */
|
|
|
|
s_mark_end(s);
|
|
|
|
s_mark_end(s);
|
|
|
|
size = (int)(s->end - s->data);
|
|
|
|
size = (int)(s->end - s->data);
|
|
|
|
log_message(LOG_LEVEL_DEBUG,"clipboard_init: data out, sending "
|
|
|
|
LOGM((LOG_LEVEL_DEBUG, "clipboard_init: data out, sending "
|
|
|
|
"CLIPRDR_CONNECT (clip_msg_id = 1)");
|
|
|
|
"CLIPRDR_CONNECT (clip_msg_id = 1)"));
|
|
|
|
rv = send_channel_data(g_cliprdr_chan_id, s->data, size);
|
|
|
|
rv = send_channel_data(g_cliprdr_chan_id, s->data, size);
|
|
|
|
if (rv != 0)
|
|
|
|
if (rv != 0)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
log_message(LOG_LEVEL_ERROR,"clipboard_init: send_channel_data failed "
|
|
|
|
LOGM((LOG_LEVEL_ERROR, "clipboard_init: send_channel_data failed "
|
|
|
|
"rv = %d", rv);
|
|
|
|
"rv = %d", rv));
|
|
|
|
rv = 4;
|
|
|
|
rv = 4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free_stream(s);
|
|
|
|
free_stream(s);
|
|
|
@ -242,7 +242,7 @@ clipboard_init(void)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
else
|
|
|
|
{
|
|
|
|
{
|
|
|
|
log_message(LOG_LEVEL_ERROR,"xrdp-chansrv: clipboard_init: error on exit");
|
|
|
|
LOGM((LOG_LEVEL_ERROR, "xrdp-chansrv: clipboard_init: error on exit"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -284,10 +284,11 @@ clipboard_send_data_request(void)
|
|
|
|
int size;
|
|
|
|
int size;
|
|
|
|
int rv;
|
|
|
|
int rv;
|
|
|
|
|
|
|
|
|
|
|
|
log_message(LOG_LEVEL_DEBUG,"clipboard_send_data_request:");
|
|
|
|
LOGM((LOG_LEVEL_DEBUG, "clipboard_send_data_request:"));
|
|
|
|
if (!g_got_format_announce)
|
|
|
|
if (!g_got_format_announce)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
log_message(LOG_LEVEL_ERROR,"clipboard_send_data_request: error, no format announce");
|
|
|
|
LOGM((LOG_LEVEL_ERROR, "clipboard_send_data_request: error, "
|
|
|
|
|
|
|
|
"no format announce"));
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
g_got_format_announce = 0;
|
|
|
|
g_got_format_announce = 0;
|
|
|
@ -299,8 +300,8 @@ clipboard_send_data_request(void)
|
|
|
|
out_uint32_le(s, 0x0d);
|
|
|
|
out_uint32_le(s, 0x0d);
|
|
|
|
s_mark_end(s);
|
|
|
|
s_mark_end(s);
|
|
|
|
size = (int)(s->end - s->data);
|
|
|
|
size = (int)(s->end - s->data);
|
|
|
|
log_message(LOG_LEVEL_DEBUG,"clipboard_send_data_request: data out, sending "
|
|
|
|
LOGM((LOG_LEVEL_DEBUG,"clipboard_send_data_request: data out, sending "
|
|
|
|
"CLIPRDR_DATA_REQUEST (clip_msg_id = 4)");
|
|
|
|
"CLIPRDR_DATA_REQUEST (clip_msg_id = 4)"));
|
|
|
|
rv = send_channel_data(g_cliprdr_chan_id, s->data, size);
|
|
|
|
rv = send_channel_data(g_cliprdr_chan_id, s->data, size);
|
|
|
|
free_stream(s);
|
|
|
|
free_stream(s);
|
|
|
|
return rv;
|
|
|
|
return rv;
|
|
|
@ -322,8 +323,8 @@ clipboard_send_format_ack(void)
|
|
|
|
out_uint32_le(s, 0); /* extra 4 bytes ? */
|
|
|
|
out_uint32_le(s, 0); /* extra 4 bytes ? */
|
|
|
|
s_mark_end(s);
|
|
|
|
s_mark_end(s);
|
|
|
|
size = (int)(s->end - s->data);
|
|
|
|
size = (int)(s->end - s->data);
|
|
|
|
log_message(LOG_LEVEL_DEBUG,"clipboard_send_format_ack: data out, sending "
|
|
|
|
LOGM((LOG_LEVEL_DEBUG,"clipboard_send_format_ack: data out, sending "
|
|
|
|
"CLIPRDR_FORMAT_ACK (clip_msg_id = 3)");
|
|
|
|
"CLIPRDR_FORMAT_ACK (clip_msg_id = 3)"));
|
|
|
|
rv = send_channel_data(g_cliprdr_chan_id, s->data, size);
|
|
|
|
rv = send_channel_data(g_cliprdr_chan_id, s->data, size);
|
|
|
|
free_stream(s);
|
|
|
|
free_stream(s);
|
|
|
|
return rv;
|
|
|
|
return rv;
|
|
|
@ -346,8 +347,8 @@ clipboard_send_format_announce(void)
|
|
|
|
out_uint8s(s, 0x90);
|
|
|
|
out_uint8s(s, 0x90);
|
|
|
|
s_mark_end(s);
|
|
|
|
s_mark_end(s);
|
|
|
|
size = (int)(s->end - s->data);
|
|
|
|
size = (int)(s->end - s->data);
|
|
|
|
log_message(LOG_LEVEL_DEBUG,"clipboard_send_format_announce: data out, sending "
|
|
|
|
LOGM((LOG_LEVEL_DEBUG,"clipboard_send_format_announce: data out, sending "
|
|
|
|
"CLIPRDR_FORMAT_ANNOUNCE (clip_msg_id = 2)");
|
|
|
|
"CLIPRDR_FORMAT_ANNOUNCE (clip_msg_id = 2)"));
|
|
|
|
rv = send_channel_data(g_cliprdr_chan_id, s->data, size);
|
|
|
|
rv = send_channel_data(g_cliprdr_chan_id, s->data, size);
|
|
|
|
free_stream(s);
|
|
|
|
free_stream(s);
|
|
|
|
return rv;
|
|
|
|
return rv;
|
|
|
@ -401,7 +402,7 @@ clipboard_send_data_response(void)
|
|
|
|
num_chars = g_mbstowcs(0, g_last_clip_data, 0);
|
|
|
|
num_chars = g_mbstowcs(0, g_last_clip_data, 0);
|
|
|
|
if (num_chars < 0)
|
|
|
|
if (num_chars < 0)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
log_message(LOG_LEVEL_ERROR,"clipboard_send_data_response: bad string");
|
|
|
|
LOGM((LOG_LEVEL_ERROR, "clipboard_send_data_response: bad string"));
|
|
|
|
num_chars = 0;
|
|
|
|
num_chars = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -415,16 +416,16 @@ clipboard_send_data_response(void)
|
|
|
|
out_uint32_le(s, num_chars * 2 + 2); /* length */
|
|
|
|
out_uint32_le(s, num_chars * 2 + 2); /* length */
|
|
|
|
if (clipboard_out_unicode(s, g_last_clip_data, num_chars) != num_chars * 2)
|
|
|
|
if (clipboard_out_unicode(s, g_last_clip_data, num_chars) != num_chars * 2)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
log_message(LOG_LEVEL_ERROR,"clipboard_send_data_response: error "
|
|
|
|
LOGM((LOG_LEVEL_ERROR,"clipboard_send_data_response: error "
|
|
|
|
"clipboard_out_unicode didn't write right number of bytes");
|
|
|
|
"clipboard_out_unicode didn't write right number of bytes"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
out_uint16_le(s, 0); /* nil for string */
|
|
|
|
out_uint16_le(s, 0); /* nil for string */
|
|
|
|
out_uint32_le(s, 0);
|
|
|
|
out_uint32_le(s, 0);
|
|
|
|
s_mark_end(s);
|
|
|
|
s_mark_end(s);
|
|
|
|
size = (int)(s->end - s->data);
|
|
|
|
size = (int)(s->end - s->data);
|
|
|
|
log_message(LOG_LEVEL_DEBUG,"clipboard_send_data_response: data out, sending "
|
|
|
|
LOGM((LOG_LEVEL_DEBUG,"clipboard_send_data_response: data out, sending "
|
|
|
|
"CLIPRDR_DATA_RESPONSE (clip_msg_id = 5) size %d num_chars %d",
|
|
|
|
"CLIPRDR_DATA_RESPONSE (clip_msg_id = 5) size %d num_chars %d",
|
|
|
|
size, num_chars);
|
|
|
|
size, num_chars));
|
|
|
|
rv = send_channel_data(g_cliprdr_chan_id, s->data, size);
|
|
|
|
rv = send_channel_data(g_cliprdr_chan_id, s->data, size);
|
|
|
|
free_stream(s);
|
|
|
|
free_stream(s);
|
|
|
|
return rv;
|
|
|
|
return rv;
|
|
|
@ -494,14 +495,16 @@ static int APP_CC
|
|
|
|
clipboard_process_format_announce(struct stream* s, int clip_msg_status,
|
|
|
|
clipboard_process_format_announce(struct stream* s, int clip_msg_status,
|
|
|
|
int clip_msg_len)
|
|
|
|
int clip_msg_len)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
log_message(LOG_LEVEL_DEBUG,"clipboard_process_format_announce: CLIPRDR_FORMAT_ANNOUNCE");
|
|
|
|
LOGM((LOG_LEVEL_DEBUG, "clipboard_process_format_announce: "
|
|
|
|
|
|
|
|
"CLIPRDR_FORMAT_ANNOUNCE"));
|
|
|
|
//g_hexdump(s->p, s->end - s->p);
|
|
|
|
//g_hexdump(s->p, s->end - s->p);
|
|
|
|
clipboard_send_format_ack();
|
|
|
|
clipboard_send_format_ack();
|
|
|
|
g_got_format_announce = 1;
|
|
|
|
g_got_format_announce = 1;
|
|
|
|
g_data_in_up_to_date = 0;
|
|
|
|
g_data_in_up_to_date = 0;
|
|
|
|
if (clipboard_set_selection_owner() != 0)
|
|
|
|
if (clipboard_set_selection_owner() != 0)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
log_message(LOG_LEVEL_ERROR,"clipboard_process_format_announce: XSetSelectionOwner failed");
|
|
|
|
LOGM((LOG_LEVEL_ERROR, "clipboard_process_format_announce: "
|
|
|
|
|
|
|
|
"XSetSelectionOwner failed"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -511,7 +514,7 @@ static int APP_CC
|
|
|
|
clipboard_prcoess_format_ack(struct stream* s, int clip_msg_status,
|
|
|
|
clipboard_prcoess_format_ack(struct stream* s, int clip_msg_status,
|
|
|
|
int clip_msg_len)
|
|
|
|
int clip_msg_len)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
log_message(LOG_LEVEL_DEBUG,"clipboard_prcoess_format_ack: CLIPRDR_FORMAT_ACK");
|
|
|
|
LOGM((LOG_LEVEL_DEBUG,"clipboard_prcoess_format_ack: CLIPRDR_FORMAT_ACK"));
|
|
|
|
//g_hexdump(s->p, s->end - s->p);
|
|
|
|
//g_hexdump(s->p, s->end - s->p);
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -521,7 +524,8 @@ static int APP_CC
|
|
|
|
clipboard_process_data_request(struct stream* s, int clip_msg_status,
|
|
|
|
clipboard_process_data_request(struct stream* s, int clip_msg_status,
|
|
|
|
int clip_msg_len)
|
|
|
|
int clip_msg_len)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
log_message(LOG_LEVEL_DEBUG,"clipboard_process_data_request: CLIPRDR_DATA_REQUEST");
|
|
|
|
LOGM((LOG_LEVEL_DEBUG,"clipboard_process_data_request: "
|
|
|
|
|
|
|
|
"CLIPRDR_DATA_REQUEST"));
|
|
|
|
//g_hexdump(s->p, s->end - s->p);
|
|
|
|
//g_hexdump(s->p, s->end - s->p);
|
|
|
|
clipboard_send_data_response();
|
|
|
|
clipboard_send_data_response();
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
@ -539,7 +543,8 @@ clipboard_process_data_response(struct stream* s, int clip_msg_status,
|
|
|
|
int index;
|
|
|
|
int index;
|
|
|
|
int data_in_len;
|
|
|
|
int data_in_len;
|
|
|
|
|
|
|
|
|
|
|
|
log_message(LOG_LEVEL_DEBUG,"clipboard_process_data_response: CLIPRDR_DATA_RESPONSE");
|
|
|
|
LOGM((LOG_LEVEL_DEBUG,"clipboard_process_data_response: "
|
|
|
|
|
|
|
|
"CLIPRDR_DATA_RESPONSE"));
|
|
|
|
g_waiting_for_data_response = 0;
|
|
|
|
g_waiting_for_data_response = 0;
|
|
|
|
len = (int)(s->end - s->p);
|
|
|
|
len = (int)(s->end - s->p);
|
|
|
|
if (len < 1)
|
|
|
|
if (len < 1)
|
|
|
@ -590,8 +595,8 @@ clipboard_process_data_response(struct stream* s, int clip_msg_status,
|
|
|
|
lxev = &(g_selection_request_event[index]);
|
|
|
|
lxev = &(g_selection_request_event[index]);
|
|
|
|
clipboard_provide_selection(lxev, lxev->target, 8, g_data_in,
|
|
|
|
clipboard_provide_selection(lxev, lxev->target, 8, g_data_in,
|
|
|
|
data_in_len);
|
|
|
|
data_in_len);
|
|
|
|
log_message(LOG_LEVEL_DEBUG,"clipboard_process_data_response: requestor %d data_in_len %d",
|
|
|
|
LOGM((LOG_LEVEL_DEBUG,"clipboard_process_data_response: requestor %d "
|
|
|
|
lxev->requestor, data_in_len);
|
|
|
|
"data_in_len %d", lxev->requestor, data_in_len));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
g_selection_request_event_count = 0;
|
|
|
|
g_selection_request_event_count = 0;
|
|
|
@ -657,7 +662,8 @@ clipboard_data_in(struct stream* s, int chan_id, int chan_flags, int length,
|
|
|
|
clip_msg_len);
|
|
|
|
clip_msg_len);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
default:
|
|
|
|
log_message(LOG_LEVEL_ERROR,"clipboard_data_in: unknown clip_msg_id %d", clip_msg_id);
|
|
|
|
LOGM((LOG_LEVEL_ERROR, "clipboard_data_in: unknown clip_msg_id %d",
|
|
|
|
|
|
|
|
clip_msg_id));
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
XFlush(g_display);
|
|
|
|
XFlush(g_display);
|
|
|
@ -685,13 +691,13 @@ clipboard_event_selection_owner_notify(XEvent* xevent)
|
|
|
|
XFixesSelectionNotifyEvent* lxevent;
|
|
|
|
XFixesSelectionNotifyEvent* lxevent;
|
|
|
|
|
|
|
|
|
|
|
|
lxevent = (XFixesSelectionNotifyEvent*)xevent;
|
|
|
|
lxevent = (XFixesSelectionNotifyEvent*)xevent;
|
|
|
|
log_message(LOG_LEVEL_DEBUG,"clipboard_event_selection_owner_notify: "
|
|
|
|
LOGM((LOG_LEVEL_DEBUG, "clipboard_event_selection_owner_notify: "
|
|
|
|
"window %d subtype %d owner %d g_wnd %d",
|
|
|
|
"window %d subtype %d owner %d g_wnd %d",
|
|
|
|
lxevent->window, lxevent->subtype, lxevent->owner, g_wnd);
|
|
|
|
lxevent->window, lxevent->subtype, lxevent->owner, g_wnd));
|
|
|
|
if (lxevent->owner == g_wnd)
|
|
|
|
if (lxevent->owner == g_wnd)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
log_message(LOG_LEVEL_DEBUG,"clipboard_event_selection_owner_notify: skipping, "
|
|
|
|
LOGM((LOG_LEVEL_DEBUG,"clipboard_event_selection_owner_notify: skipping, "
|
|
|
|
"onwer == g_wnd");
|
|
|
|
"onwer == g_wnd"));
|
|
|
|
g_got_selection = 1;
|
|
|
|
g_got_selection = 1;
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -811,7 +817,10 @@ clipboard_event_selection_notify(XEvent* xevent)
|
|
|
|
int* atoms;
|
|
|
|
int* atoms;
|
|
|
|
Atom type;
|
|
|
|
Atom type;
|
|
|
|
|
|
|
|
|
|
|
|
log_message(LOG_LEVEL_DEBUG,"clipboard_event_selection_notify:");
|
|
|
|
LOGM((LOG_LEVEL_DEBUG, "clipboard_event_selection_notify:"));
|
|
|
|
|
|
|
|
data_size = 0;
|
|
|
|
|
|
|
|
n_items = 0;
|
|
|
|
|
|
|
|
fmt = 0;
|
|
|
|
convert_to_string = 0;
|
|
|
|
convert_to_string = 0;
|
|
|
|
convert_to_utf8 = 0;
|
|
|
|
convert_to_utf8 = 0;
|
|
|
|
send_format_announce = 0;
|
|
|
|
send_format_announce = 0;
|
|
|
@ -821,8 +830,8 @@ clipboard_event_selection_notify(XEvent* xevent)
|
|
|
|
lxevent = (XSelectionEvent*)xevent;
|
|
|
|
lxevent = (XSelectionEvent*)xevent;
|
|
|
|
if (lxevent->property == None)
|
|
|
|
if (lxevent->property == None)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
log_message(LOG_LEVEL_ERROR,"clipboard_event_selection_notify: clip could "
|
|
|
|
LOGM((LOG_LEVEL_ERROR, "clipboard_event_selection_notify: clip could "
|
|
|
|
"not be converted");
|
|
|
|
"not be converted"));
|
|
|
|
rv = 1;
|
|
|
|
rv = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (rv == 0)
|
|
|
|
if (rv == 0)
|
|
|
@ -832,8 +841,8 @@ clipboard_event_selection_notify(XEvent* xevent)
|
|
|
|
&n_items, &data, &data_size);
|
|
|
|
&n_items, &data, &data_size);
|
|
|
|
if (rv != 0)
|
|
|
|
if (rv != 0)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
log_message(LOG_LEVEL_ERROR,"clipboard_event_selection_notify: "
|
|
|
|
LOGM((LOG_LEVEL_ERROR, "clipboard_event_selection_notify: "
|
|
|
|
"clipboard_get_window_property failed error %d", rv);
|
|
|
|
"clipboard_get_window_property failed error %d", rv));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
XDeleteProperty(g_display, lxevent->requestor, lxevent->property);
|
|
|
|
XDeleteProperty(g_display, lxevent->requestor, lxevent->property);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -849,8 +858,8 @@ clipboard_event_selection_notify(XEvent* xevent)
|
|
|
|
for (index = 0; index < n_items; index++)
|
|
|
|
for (index = 0; index < n_items; index++)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
atom = atoms[index];
|
|
|
|
atom = atoms[index];
|
|
|
|
log_message(LOG_LEVEL_DEBUG,"clipboard_event_selection_notify: %d %s %d", atom,
|
|
|
|
LOGM((LOG_LEVEL_DEBUG, "clipboard_event_selection_notify: %d %s %d",
|
|
|
|
XGetAtomName(g_display, atom), XA_STRING);
|
|
|
|
atom, XGetAtomName(g_display, atom), XA_STRING));
|
|
|
|
if (atom == g_utf8_atom)
|
|
|
|
if (atom == g_utf8_atom)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
convert_to_utf8 = 1;
|
|
|
|
convert_to_utf8 = 1;
|
|
|
@ -863,15 +872,15 @@ clipboard_event_selection_notify(XEvent* xevent)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
else
|
|
|
|
{
|
|
|
|
{
|
|
|
|
log_message(LOG_LEVEL_ERROR,"clipboard_event_selection_notify: error, target is "
|
|
|
|
LOGM((LOG_LEVEL_ERROR, "clipboard_event_selection_notify: error, "
|
|
|
|
"'TARGETS' and type[%d] or fmt[%d] not right, should be "
|
|
|
|
"target is 'TARGETS' and type[%d] or fmt[%d] not right, "
|
|
|
|
"type[%d], fmt[%d]", type, fmt, XA_ATOM, 32);
|
|
|
|
"should be type[%d], fmt[%d]", type, fmt, XA_ATOM, 32));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (lxevent->target == g_utf8_atom)
|
|
|
|
else if (lxevent->target == g_utf8_atom)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
log_message(LOG_LEVEL_DEBUG,"clipboard_event_selection_notify: UTF8_STRING data_size %d",
|
|
|
|
LOGM((LOG_LEVEL_DEBUG,"clipboard_event_selection_notify: UTF8_STRING "
|
|
|
|
data_size);
|
|
|
|
"data_size %d", data_size));
|
|
|
|
g_free(g_last_clip_data);
|
|
|
|
g_free(g_last_clip_data);
|
|
|
|
g_last_clip_size = data_size;
|
|
|
|
g_last_clip_size = data_size;
|
|
|
|
g_last_clip_data = g_malloc(g_last_clip_size + 1, 0);
|
|
|
|
g_last_clip_data = g_malloc(g_last_clip_size + 1, 0);
|
|
|
@ -882,8 +891,8 @@ clipboard_event_selection_notify(XEvent* xevent)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (lxevent->target == XA_STRING)
|
|
|
|
else if (lxevent->target == XA_STRING)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
log_message(LOG_LEVEL_DEBUG,"clipboard_event_selection_notify: XA_STRING data_size %d",
|
|
|
|
LOGM((LOG_LEVEL_DEBUG,"clipboard_event_selection_notify: XA_STRING "
|
|
|
|
data_size);
|
|
|
|
"data_size %d", data_size));
|
|
|
|
g_free(g_last_clip_data);
|
|
|
|
g_free(g_last_clip_data);
|
|
|
|
g_last_clip_size = data_size;
|
|
|
|
g_last_clip_size = data_size;
|
|
|
|
g_last_clip_data = g_malloc(g_last_clip_size + 1, 0);
|
|
|
|
g_last_clip_data = g_malloc(g_last_clip_size + 1, 0);
|
|
|
@ -894,12 +903,14 @@ clipboard_event_selection_notify(XEvent* xevent)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
else
|
|
|
|
{
|
|
|
|
{
|
|
|
|
log_message(LOG_LEVEL_ERROR,"clipboard_event_selection_notify: unknown target");
|
|
|
|
LOGM((LOG_LEVEL_ERROR, "clipboard_event_selection_notify: "
|
|
|
|
|
|
|
|
"unknown target"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
else
|
|
|
|
{
|
|
|
|
{
|
|
|
|
log_message(LOG_LEVEL_ERROR,"clipboard_event_selection_notify: unknown selection");
|
|
|
|
LOGM((LOG_LEVEL_ERROR,"clipboard_event_selection_notify: "
|
|
|
|
|
|
|
|
"unknown selection"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (convert_to_utf8)
|
|
|
|
if (convert_to_utf8)
|
|
|
@ -941,7 +952,7 @@ clipboard_event_selection_notify(XEvent* xevent)
|
|
|
|
static int APP_CC
|
|
|
|
static int APP_CC
|
|
|
|
clipboard_event_selection_request(XEvent* xevent)
|
|
|
|
clipboard_event_selection_request(XEvent* xevent)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
XEvent xev;
|
|
|
|
//XEvent xev;
|
|
|
|
XSelectionRequestEvent* lxev;
|
|
|
|
XSelectionRequestEvent* lxev;
|
|
|
|
tui32 ui32[8];
|
|
|
|
tui32 ui32[8];
|
|
|
|
Atom type;
|
|
|
|
Atom type;
|
|
|
@ -951,19 +962,21 @@ clipboard_event_selection_request(XEvent* xevent)
|
|
|
|
char* xdata;
|
|
|
|
char* xdata;
|
|
|
|
|
|
|
|
|
|
|
|
lxev = (XSelectionRequestEvent*)xevent;
|
|
|
|
lxev = (XSelectionRequestEvent*)xevent;
|
|
|
|
log_message(LOG_LEVEL_DEBUG,"clipboard_event_selection_request: g_wnd %d, "
|
|
|
|
LOGM((LOG_LEVEL_DEBUG, "clipboard_event_selection_request: g_wnd %d, "
|
|
|
|
".requestor %d .owner %d .selection %d '%s' .target %d .property %d",
|
|
|
|
".requestor %d .owner %d .selection %d '%s' .target %d .property %d",
|
|
|
|
g_wnd, lxev->requestor, lxev->owner, lxev->selection,
|
|
|
|
g_wnd, lxev->requestor, lxev->owner, lxev->selection,
|
|
|
|
XGetAtomName(g_display, lxev->selection),
|
|
|
|
XGetAtomName(g_display, lxev->selection),
|
|
|
|
lxev->target, lxev->property);
|
|
|
|
lxev->target, lxev->property));
|
|
|
|
if (lxev->property == None)
|
|
|
|
if (lxev->property == None)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
log_message(LOG_LEVEL_DEBUG,"clipboard_event_selection_request: lxev->property is None");
|
|
|
|
LOGM((LOG_LEVEL_DEBUG, "clipboard_event_selection_request: "
|
|
|
|
|
|
|
|
"lxev->property is None"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (lxev->target == g_targets_atom)
|
|
|
|
else if (lxev->target == g_targets_atom)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
/* requestor is asking what the selection can be converted to */
|
|
|
|
/* requestor is asking what the selection can be converted to */
|
|
|
|
log_message(LOG_LEVEL_DEBUG,"clipboard_event_selection_request: g_targets_atom");
|
|
|
|
LOGM((LOG_LEVEL_DEBUG, "clipboard_event_selection_request: "
|
|
|
|
|
|
|
|
"g_targets_atom"));
|
|
|
|
ui32[0] = g_targets_atom;
|
|
|
|
ui32[0] = g_targets_atom;
|
|
|
|
ui32[1] = g_timestamp_atom;
|
|
|
|
ui32[1] = g_timestamp_atom;
|
|
|
|
ui32[2] = g_multiple_atom;
|
|
|
|
ui32[2] = g_multiple_atom;
|
|
|
@ -974,29 +987,33 @@ clipboard_event_selection_request(XEvent* xevent)
|
|
|
|
else if (lxev->target == g_timestamp_atom)
|
|
|
|
else if (lxev->target == g_timestamp_atom)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
/* requestor is asking the time I got the selection */
|
|
|
|
/* requestor is asking the time I got the selection */
|
|
|
|
log_message(LOG_LEVEL_DEBUG,"clipboard_event_selection_request: g_timestamp_atom");
|
|
|
|
LOGM((LOG_LEVEL_DEBUG, "clipboard_event_selection_request: "
|
|
|
|
|
|
|
|
"g_timestamp_atom"));
|
|
|
|
ui32[0] = g_selection_time;
|
|
|
|
ui32[0] = g_selection_time;
|
|
|
|
return clipboard_provide_selection(lxev, XA_INTEGER, 32, (char*)ui32, 1);
|
|
|
|
return clipboard_provide_selection(lxev, XA_INTEGER, 32, (char*)ui32, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (lxev->target == g_multiple_atom)
|
|
|
|
else if (lxev->target == g_multiple_atom)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
/* target, property pairs */
|
|
|
|
/* target, property pairs */
|
|
|
|
log_message(LOG_LEVEL_DEBUG,"clipboard_event_selection_request: g_multiple_atom");
|
|
|
|
LOGM((LOG_LEVEL_DEBUG, "clipboard_event_selection_request: "
|
|
|
|
|
|
|
|
"g_multiple_atom"));
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
if (clipboard_get_window_property(xev.xselection.requestor,
|
|
|
|
if (clipboard_get_window_property(xev.xselection.requestor,
|
|
|
|
xev.xselection.property,
|
|
|
|
xev.xselection.property,
|
|
|
|
&type, &fmt, &n_items, &xdata,
|
|
|
|
&type, &fmt, &n_items, &xdata,
|
|
|
|
&xdata_size) == 0)
|
|
|
|
&xdata_size) == 0)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
log_message(LOG_LEVEL_DEBUG,"clipboard_event_selection_request: g_multiple_atom "
|
|
|
|
LOGM((LOG_LEVEL_DEBUG, "clipboard_event_selection_request: g_multiple_atom "
|
|
|
|
"n_items %d", n_items);
|
|
|
|
"n_items %d", n_items));
|
|
|
|
/* todo */
|
|
|
|
/* todo */
|
|
|
|
g_free(xdata);
|
|
|
|
g_free(xdata);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ((lxev->target == XA_STRING) || (lxev->target == g_utf8_atom))
|
|
|
|
else if ((lxev->target == XA_STRING) || (lxev->target == g_utf8_atom))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
log_message(LOG_LEVEL_DEBUG,"clipboard_event_selection_request: %s",
|
|
|
|
LOGM((LOG_LEVEL_DEBUG, "clipboard_event_selection_request: %s",
|
|
|
|
XGetAtomName(g_display, lxev->target));
|
|
|
|
XGetAtomName(g_display, lxev->target)));
|
|
|
|
if (g_data_in_up_to_date)
|
|
|
|
if (g_data_in_up_to_date)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return clipboard_provide_selection(lxev, lxev->target, 8,
|
|
|
|
return clipboard_provide_selection(lxev, lxev->target, 8,
|
|
|
@ -1004,7 +1021,8 @@ clipboard_event_selection_request(XEvent* xevent)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (g_selection_request_event_count > 10)
|
|
|
|
if (g_selection_request_event_count > 10)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
log_message(LOG_LEVEL_ERROR,"clipboard_event_selection_request: error, too many requests");
|
|
|
|
LOGM((LOG_LEVEL_ERROR, "clipboard_event_selection_request: error, "
|
|
|
|
|
|
|
|
"too many requests"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
else
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -1022,8 +1040,8 @@ clipboard_event_selection_request(XEvent* xevent)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
else
|
|
|
|
{
|
|
|
|
{
|
|
|
|
log_message(LOG_LEVEL_ERROR,"clipboard_event_selection_request: unknown "
|
|
|
|
LOGM((LOG_LEVEL_ERROR,"clipboard_event_selection_request: unknown "
|
|
|
|
"target %s", XGetAtomName(g_display, lxev->target));
|
|
|
|
"target %s", XGetAtomName(g_display, lxev->target)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
clipboard_refuse_selection(lxev);
|
|
|
|
clipboard_refuse_selection(lxev);
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
@ -1044,7 +1062,7 @@ clipboard_event_selection_request(XEvent* xevent)
|
|
|
|
static int APP_CC
|
|
|
|
static int APP_CC
|
|
|
|
clipboard_event_selection_clear(XEvent* xevent)
|
|
|
|
clipboard_event_selection_clear(XEvent* xevent)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
log_message(LOG_LEVEL_DEBUG,"clipboard_event_selection_clear:");
|
|
|
|
LOGM((LOG_LEVEL_DEBUG, "clipboard_event_selection_clear:"));
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -1105,7 +1123,7 @@ clipboard_check_wait_objs(void)
|
|
|
|
if (XPending(g_display) < 1)
|
|
|
|
if (XPending(g_display) < 1)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
/* something is wrong, should not get here */
|
|
|
|
/* something is wrong, should not get here */
|
|
|
|
log_message(LOG_LEVEL_ERROR,"clipboard_check_wait_objs: sck closed");
|
|
|
|
LOGM((LOG_LEVEL_ERROR, "clipboard_check_wait_objs: sck closed"));
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (g_waiting_for_data_response)
|
|
|
|
if (g_waiting_for_data_response)
|
|
|
@ -1114,8 +1132,8 @@ clipboard_check_wait_objs(void)
|
|
|
|
g_waiting_for_data_response_time;
|
|
|
|
g_waiting_for_data_response_time;
|
|
|
|
if (time_diff > 1000)
|
|
|
|
if (time_diff > 1000)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
log_message(LOG_LEVEL_ERROR,"clipboard_check_wait_objs: warning, waiting for "
|
|
|
|
LOGM((LOG_LEVEL_ERROR, "clipboard_check_wait_objs: warning, "
|
|
|
|
"data response too long");
|
|
|
|
"waiting for data response too long"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (XPending(g_display) > 0)
|
|
|
|
while (XPending(g_display) > 0)
|
|
|
@ -1144,8 +1162,8 @@ clipboard_check_wait_objs(void)
|
|
|
|
clipboard_event_selection_owner_notify(&xevent);
|
|
|
|
clipboard_event_selection_owner_notify(&xevent);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
log_message(LOG_LEVEL_ERROR,"clipboard_check_wait_objs unknown type %d",
|
|
|
|
LOGM((LOG_LEVEL_ERROR, "clipboard_check_wait_objs unknown type %d",
|
|
|
|
xevent.type);
|
|
|
|
xevent.type));
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|