2012-07-25 06:16:00 +04:00
|
|
|
/**
|
|
|
|
* xrdp: A Remote Desktop Protocol server.
|
|
|
|
*
|
|
|
|
* Copyright (C) Jay Sorg 2009-2012
|
2012-08-12 21:51:45 +04:00
|
|
|
* Copyright (C) Laxmikant Rashinkar 2012
|
2012-07-25 06:16:00 +04:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
2009-04-19 21:16:46 +04:00
|
|
|
/*
|
2009-08-15 06:47:51 +04:00
|
|
|
for help see
|
|
|
|
http://tronche.com/gui/x/icccm/sec-2.html#s-2
|
|
|
|
.../kde/kdebase/workspace/klipper/clipboardpoll.cpp
|
2012-08-12 21:51:45 +04:00
|
|
|
|
|
|
|
Revision:
|
|
|
|
Aug 05, 2012:
|
|
|
|
Laxmikant Rashinkar (LK dot Rashinkar at gmail.com)
|
|
|
|
added clipboard support for BMP images
|
2012-11-14 21:44:43 +04:00
|
|
|
|
|
|
|
http://msdn.microsoft.com/en-us/library/cc241066%28v=prot.20%29.aspx
|
|
|
|
|
2009-04-19 21:16:46 +04:00
|
|
|
*/
|
|
|
|
|
2012-10-05 09:55:06 +04:00
|
|
|
/*
|
|
|
|
TARGETS
|
|
|
|
MULTIPLE
|
|
|
|
image/tiff
|
|
|
|
image/jpeg
|
|
|
|
image/x-MS-bmp
|
|
|
|
image/x-bmp
|
|
|
|
image/bmp
|
|
|
|
image/png
|
|
|
|
SAVE_TARGETS
|
|
|
|
TIMESTAMP
|
|
|
|
|
|
|
|
wininfo - show window info
|
|
|
|
xlsatoms - dump atoms
|
|
|
|
|
2012-11-05 13:04:04 +04:00
|
|
|
dolphin 1.4 KDE 4.4.5 (debian 6) copy one file
|
|
|
|
text/uri-list
|
|
|
|
text/x-moz-url
|
|
|
|
text/plain
|
|
|
|
UTF8_STRING
|
|
|
|
STRING
|
|
|
|
TEXT
|
|
|
|
COMPOUND_TEXT
|
|
|
|
application/x-qiconlist
|
|
|
|
TARGETS
|
|
|
|
MULTIPLE
|
|
|
|
TIMESTAMP
|
|
|
|
SAVE_TARGETS
|
|
|
|
|
|
|
|
dolphin 1.6.1 KDE 4.6.5 (kubuntu 11.04) copy one file
|
2012-11-05 01:52:33 +04:00
|
|
|
text/uri-list
|
|
|
|
text/x-moz-url
|
|
|
|
text/plain
|
|
|
|
UTF8_STRING
|
|
|
|
STRING
|
|
|
|
TEXT
|
|
|
|
COMPOUND_TEXT
|
|
|
|
application/x-qiconlist
|
|
|
|
TARGETS
|
|
|
|
MULTIPLE
|
|
|
|
TIMESTAMP
|
|
|
|
SAVE_TARGETS
|
|
|
|
|
|
|
|
kolourpaint 4.4.5 KDE 4.4.5 copy image area
|
|
|
|
application/x-kolourpaint-selection-400
|
|
|
|
application/x-qt-image
|
|
|
|
image/png
|
|
|
|
image/bw
|
|
|
|
image/eps
|
|
|
|
image/epsf
|
|
|
|
image/epsi
|
|
|
|
image/pcx
|
|
|
|
image/rgb
|
|
|
|
image/rgba
|
|
|
|
image/sgi
|
|
|
|
image/tga
|
|
|
|
image/bmp
|
|
|
|
image/ico
|
|
|
|
image/jp2
|
|
|
|
image/jpeg
|
|
|
|
image/jpg
|
|
|
|
image/ppm
|
|
|
|
PIXMAP
|
|
|
|
image/tif
|
|
|
|
image/tiff
|
|
|
|
image/xbm
|
|
|
|
image/xpm
|
|
|
|
image/xv
|
|
|
|
TARGETS
|
|
|
|
MULTIPLE
|
|
|
|
TIMESTAMP
|
|
|
|
SAVE_TARGETS
|
|
|
|
|
|
|
|
kate 3.4.5 KDE 4.4.5 copy text
|
|
|
|
text/plain
|
|
|
|
UTF8_STRING
|
|
|
|
STRING
|
|
|
|
TEXT
|
|
|
|
COMPOUND_TEXT
|
|
|
|
TARGETS
|
|
|
|
MULTIPLE
|
|
|
|
TIMESTAMP
|
|
|
|
SAVE_TARGETS
|
|
|
|
|
|
|
|
gimp 2.6.10 copy image area
|
|
|
|
TIMESTAMP
|
|
|
|
TARGETS
|
|
|
|
MULTIPLE
|
|
|
|
SAVE_TARGETS
|
|
|
|
image/png
|
|
|
|
image/bmp
|
|
|
|
image/x-bmp
|
|
|
|
image/x-MS-bmp
|
|
|
|
image/tiff
|
|
|
|
image/x-icon
|
|
|
|
image/x-ico
|
|
|
|
image/x-win-bitmap
|
|
|
|
image/jpeg
|
|
|
|
|
2012-11-05 13:04:04 +04:00
|
|
|
thunar 1.2.1 copy a file
|
|
|
|
TIMESTAMP
|
|
|
|
TARGETS
|
|
|
|
MULTIPLE
|
|
|
|
x-special/gnome-copied-files
|
|
|
|
UTF8_STRING
|
|
|
|
|
|
|
|
dolphin 1.6.1 KDE 4.6.5 (kubuntu 11.04) copy two files
|
|
|
|
text/uri-list
|
|
|
|
/home/jay/temp/jetstream1.txt
|
|
|
|
/home/jay/temp/jpeg64x64.jpg
|
|
|
|
0000 66 69 6c 65 3a 2f 2f 2f 68 6f 6d 65 2f 6a 61 79 file:///home/jay
|
|
|
|
0010 2f 74 65 6d 70 2f 6a 65 74 73 74 72 65 61 6d 31 /temp/jetstream1
|
|
|
|
0020 2e 74 78 74 0d 0a 66 69 6c 65 3a 2f 2f 2f 68 6f .txt..file:///ho
|
|
|
|
0030 6d 65 2f 6a 61 79 2f 74 65 6d 70 2f 6a 70 65 67 me/jay/temp/jpeg
|
|
|
|
0040 36 34 78 36 34 2e 6a 70 67 64x64.jpg
|
|
|
|
|
|
|
|
thunar 1.2.1 (kubuntu 11.04) copy two files
|
|
|
|
x-special/gnome-copied-files
|
|
|
|
/home/jay/temp/jetstream1.txt
|
|
|
|
/home/jay/temp/jpeg64x64.jpg
|
|
|
|
0000 63 6f 70 79 0a 66 69 6c 65 3a 2f 2f 2f 68 6f 6d copy.file:///hom
|
|
|
|
0010 65 2f 6a 61 79 2f 74 65 6d 70 2f 6a 65 74 73 74 e/jay/temp/jetst
|
|
|
|
0020 72 65 61 6d 31 2e 74 78 74 0d 0a 66 69 6c 65 3a ream1.txt..file:
|
|
|
|
0030 2f 2f 2f 68 6f 6d 65 2f 6a 61 79 2f 74 65 6d 70 ///home/jay/temp
|
|
|
|
0040 2f 6a 70 65 67 36 34 78 36 34 2e 6a 70 67 0d 0a /jpeg64x64.jpg..
|
|
|
|
|
|
|
|
|
2012-10-05 09:55:06 +04:00
|
|
|
*/
|
|
|
|
|
2017-03-03 07:33:23 +03:00
|
|
|
#if defined(HAVE_CONFIG_H)
|
|
|
|
#include <config_ac.h>
|
|
|
|
#endif
|
|
|
|
|
2009-08-15 06:47:51 +04:00
|
|
|
#include <X11/Xlib.h>
|
|
|
|
#include <X11/Xatom.h>
|
|
|
|
#include <X11/extensions/Xfixes.h>
|
2009-04-19 21:16:46 +04:00
|
|
|
#include "arch.h"
|
|
|
|
#include "parse.h"
|
|
|
|
#include "os_calls.h"
|
2020-12-21 15:36:00 +03:00
|
|
|
#include "string_calls.h"
|
2009-08-15 06:47:51 +04:00
|
|
|
#include "chansrv.h"
|
2021-12-14 08:43:49 +03:00
|
|
|
#include "chansrv_common.h"
|
2020-07-06 13:53:56 +03:00
|
|
|
#include "chansrv_config.h"
|
2012-06-11 10:47:08 +04:00
|
|
|
#include "clipboard.h"
|
2012-10-14 22:46:01 +04:00
|
|
|
#include "clipboard_file.h"
|
2012-10-19 05:43:04 +04:00
|
|
|
#include "clipboard_common.h"
|
2012-07-27 08:37:48 +04:00
|
|
|
#include "xcommon.h"
|
2012-10-30 07:12:24 +04:00
|
|
|
#include "chansrv_fuse.h"
|
2021-05-27 17:34:13 +03:00
|
|
|
#include "ms-rdpeclip.h"
|
2023-08-04 19:08:42 +03:00
|
|
|
#include "xrdp_constants.h"
|
2012-10-05 09:55:06 +04:00
|
|
|
|
2024-06-18 02:57:58 +03:00
|
|
|
#define BMPFILEHEADER_LEN 14
|
|
|
|
#define BMPINFOHEADER_LEN 40
|
2024-06-17 14:18:17 +03:00
|
|
|
|
2012-07-27 01:38:02 +04:00
|
|
|
extern int g_cliprdr_chan_id; /* in chansrv.c */
|
|
|
|
|
2012-09-20 07:51:34 +04:00
|
|
|
extern Display *g_display; /* in xcommon.c */
|
2012-07-27 01:38:02 +04:00
|
|
|
extern int g_x_socket; /* in xcommon.c */
|
|
|
|
extern tbus g_x_wait_obj; /* in xcommon.c */
|
2012-09-20 07:51:34 +04:00
|
|
|
extern Screen *g_screen; /* in xcommon.c */
|
2012-07-27 01:38:02 +04:00
|
|
|
extern int g_screen_num; /* in xcommon.c */
|
|
|
|
|
2020-07-06 13:53:56 +03:00
|
|
|
extern struct config_chansrv *g_cfg; /* in chansrv.c */
|
2018-11-19 15:04:43 +03:00
|
|
|
|
2012-07-27 01:38:02 +04:00
|
|
|
int g_clip_up = 0;
|
|
|
|
|
2012-10-19 05:43:04 +04:00
|
|
|
static Atom g_clipboard_atom = 0; /* CLIPBOARD */
|
|
|
|
static Atom g_clip_property_atom = 0; /* XRDP_CLIP_PROPERTY_ATOM */
|
|
|
|
static Atom g_timestamp_atom = 0; /* TIMESTAMP */
|
|
|
|
static Atom g_multiple_atom = 0; /* MULTIPLE */
|
|
|
|
static Atom g_targets_atom = 0; /* TARGETS */
|
|
|
|
static Atom g_primary_atom = 0; /* PRIMARY */
|
|
|
|
static Atom g_secondary_atom = 0; /* SECONDARY */
|
|
|
|
static Atom g_get_time_atom = 0; /* XRDP_GET_TIME_ATOM */
|
|
|
|
static Atom g_utf8_atom = 0; /* UTF8_STRING */
|
|
|
|
static Atom g_image_bmp_atom = 0; /* image/bmp */
|
|
|
|
static Atom g_file_atom1 = 0; /* text/uri-list */
|
|
|
|
static Atom g_file_atom2 = 0; /* x-special/gnome-copied-files */
|
|
|
|
static Atom g_incr_atom = 0; /* INCR */
|
2012-08-12 21:51:45 +04:00
|
|
|
|
2009-08-15 06:47:51 +04:00
|
|
|
static Window g_wnd = 0;
|
|
|
|
static int g_xfixes_event_base = 0;
|
|
|
|
|
|
|
|
static int g_got_selection = 0; /* boolean */
|
|
|
|
static Time g_selection_time = 0;
|
2009-04-19 21:16:46 +04:00
|
|
|
|
2012-09-20 07:51:34 +04:00
|
|
|
static struct stream *g_ins = 0;
|
2009-08-23 04:48:20 +04:00
|
|
|
|
2012-08-12 21:51:45 +04:00
|
|
|
/* for image data */
|
|
|
|
static XSelectionRequestEvent g_saved_selection_req_event;
|
|
|
|
|
2012-10-18 08:23:31 +04:00
|
|
|
/* xserver maximum request size in bytes */
|
|
|
|
static int g_incr_max_req_size = 0;
|
|
|
|
|
2012-10-19 05:43:04 +04:00
|
|
|
/* server to client, pasting from linux app to mstsc */
|
|
|
|
struct clip_s2c g_clip_s2c;
|
|
|
|
/* client to server, pasting from mstsc to linux app */
|
|
|
|
struct clip_c2s g_clip_c2s;
|
2012-08-12 21:51:45 +04:00
|
|
|
|
2012-10-14 09:48:29 +04:00
|
|
|
/* default version and flags */
|
2021-05-27 17:34:13 +03:00
|
|
|
static int g_cliprdr_version = CB_CAPS_VERSION_2;
|
2012-10-05 09:55:06 +04:00
|
|
|
static int g_cliprdr_flags = CB_USE_LONG_FORMAT_NAMES |
|
|
|
|
CB_STREAM_FILECLIP_ENABLED |
|
|
|
|
CB_FILECLIP_NO_FILE_PATHS;
|
|
|
|
|
2012-10-19 05:43:04 +04:00
|
|
|
/* from client to server */
|
2016-01-14 19:32:09 +03:00
|
|
|
/* last received CLIPRDR_FORMAT_LIST(CLIPRDR_FORMAT_ANNOUNCE) */
|
2012-10-05 09:55:06 +04:00
|
|
|
static int g_formatIds[16];
|
|
|
|
static int g_num_formatIds = 0;
|
2012-08-12 21:51:45 +04:00
|
|
|
|
2023-08-04 19:08:42 +03:00
|
|
|
/* Format ID assigned to "FileGroupDescriptorW" by the client */
|
|
|
|
static int g_file_group_descriptor_format_id = -1;
|
2012-11-05 13:04:04 +04:00
|
|
|
|
2013-08-08 20:21:40 +04:00
|
|
|
static char g_last_atom_name[256] = "";
|
|
|
|
|
2023-08-04 19:08:42 +03:00
|
|
|
/*
|
|
|
|
* Values for the named formats we send to the client in
|
|
|
|
* a Format List PDU
|
|
|
|
*/
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
CB_FORMAT_FILE_GROUP_DESCRIPTOR = 0xc0bc
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-08-08 08:02:22 +04:00
|
|
|
/*****************************************************************************/
|
2019-02-26 09:40:10 +03:00
|
|
|
static char *
|
2013-08-08 08:02:22 +04:00
|
|
|
get_atom_text(Atom atom)
|
|
|
|
{
|
2019-02-26 09:40:10 +03:00
|
|
|
char *name;
|
2013-08-08 08:02:22 +04:00
|
|
|
int failed;
|
|
|
|
|
|
|
|
failed = 0;
|
|
|
|
/* sanity check */
|
|
|
|
if ((atom < 1) || (atom > 512))
|
|
|
|
{
|
|
|
|
failed = 1;
|
|
|
|
}
|
|
|
|
if (!failed)
|
|
|
|
{
|
2013-09-26 22:28:07 +04:00
|
|
|
name = XGetAtomName(g_display, atom);
|
2013-08-08 08:02:22 +04:00
|
|
|
if (name == 0)
|
|
|
|
{
|
|
|
|
failed = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (failed)
|
|
|
|
{
|
|
|
|
g_snprintf(g_last_atom_name, 255, "unknown atom 0x%8.8x", (int)atom);
|
|
|
|
return g_last_atom_name;
|
|
|
|
}
|
|
|
|
g_strncpy(g_last_atom_name, name, 255);
|
|
|
|
XFree(name);
|
|
|
|
return g_last_atom_name;
|
|
|
|
}
|
|
|
|
|
2009-08-27 06:15:49 +04:00
|
|
|
/*****************************************************************************/
|
|
|
|
/* this is one way to get the current time from the x server */
|
2017-03-12 19:35:00 +03:00
|
|
|
static Time
|
2009-09-01 01:25:06 +04:00
|
|
|
clipboard_get_server_time(void)
|
2009-08-15 06:47:51 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
XEvent xevent;
|
|
|
|
unsigned char no_text[4];
|
|
|
|
|
|
|
|
/* append nothing */
|
|
|
|
no_text[0] = 0;
|
|
|
|
XChangeProperty(g_display, g_wnd, g_get_time_atom, XA_STRING, 8,
|
|
|
|
PropModeAppend, no_text, 0);
|
|
|
|
|
|
|
|
/* wait for PropertyNotify */
|
|
|
|
do
|
|
|
|
{
|
|
|
|
XMaskEvent(g_display, PropertyChangeMask, &xevent);
|
|
|
|
}
|
|
|
|
while (xevent.type != PropertyNotify);
|
|
|
|
|
|
|
|
return xevent.xproperty.time;
|
2009-08-15 06:47:51 +04:00
|
|
|
}
|
|
|
|
|
2012-10-18 08:23:31 +04:00
|
|
|
/*****************************************************************************/
|
2017-03-12 19:35:00 +03:00
|
|
|
static int
|
2012-10-18 08:23:31 +04:00
|
|
|
clipboard_find_format_id(int format_id)
|
|
|
|
{
|
|
|
|
int index;
|
|
|
|
|
|
|
|
for (index = 0; index < g_num_formatIds; index++)
|
|
|
|
{
|
|
|
|
if (g_formatIds[index] == format_id)
|
|
|
|
{
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2009-08-15 06:47:51 +04:00
|
|
|
/*****************************************************************************/
|
|
|
|
/* returns error */
|
2017-03-12 19:35:00 +03:00
|
|
|
int
|
2009-04-19 21:16:46 +04:00
|
|
|
clipboard_init(void)
|
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
struct stream *s;
|
|
|
|
int size;
|
|
|
|
int rv;
|
|
|
|
int input_mask;
|
|
|
|
int dummy;
|
|
|
|
int ver_maj;
|
|
|
|
int ver_min;
|
|
|
|
Status st;
|
|
|
|
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_INFO, "clipboard_init:");
|
2012-09-20 07:51:34 +04:00
|
|
|
|
|
|
|
if (g_clip_up)
|
2009-08-15 06:47:51 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
return 0;
|
2009-08-15 06:47:51 +04:00
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
|
2013-03-09 03:37:30 +04:00
|
|
|
xfuse_init();
|
2012-09-20 07:51:34 +04:00
|
|
|
xcommon_init();
|
2012-10-17 12:13:37 +04:00
|
|
|
g_incr_max_req_size = XMaxRequestSize(g_display) * 4 - 24;
|
2012-10-18 08:23:31 +04:00
|
|
|
g_memset(&g_clip_c2s, 0, sizeof(g_clip_c2s));
|
2012-10-18 20:58:23 +04:00
|
|
|
g_memset(&g_clip_s2c, 0, sizeof(g_clip_s2c));
|
2012-09-20 07:51:34 +04:00
|
|
|
rv = 0;
|
|
|
|
if (rv == 0)
|
2009-08-15 06:47:51 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
g_clipboard_atom = XInternAtom(g_display, "CLIPBOARD", False);
|
|
|
|
|
|
|
|
if (g_clipboard_atom == None)
|
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_ERROR, "clipboard_init: XInternAtom failed");
|
2012-09-20 07:51:34 +04:00
|
|
|
rv = 3;
|
|
|
|
}
|
2009-08-15 06:47:51 +04:00
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
|
|
|
|
if (rv == 0)
|
2012-08-20 06:45:31 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
if (!XFixesQueryExtension(g_display, &g_xfixes_event_base, &dummy))
|
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_ERROR, "clipboard_init: no xfixes");
|
2012-09-20 07:51:34 +04:00
|
|
|
rv = 5;
|
|
|
|
}
|
2012-08-20 06:45:31 +04:00
|
|
|
}
|
2012-08-12 21:51:45 +04:00
|
|
|
|
2012-09-20 07:51:34 +04:00
|
|
|
if (rv == 0)
|
2009-08-15 06:47:51 +04:00
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "clipboard_init: g_xfixes_event_base %d",
|
2020-11-30 03:36:20 +03:00
|
|
|
g_xfixes_event_base);
|
2012-09-20 07:51:34 +04:00
|
|
|
st = XFixesQueryVersion(g_display, &ver_maj, &ver_min);
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG(LOG_LEVEL_DEBUG, "clipboard_init st %d, maj %d min %d", st,
|
2020-11-30 03:36:20 +03:00
|
|
|
ver_maj, ver_min);
|
2012-09-20 07:51:34 +04:00
|
|
|
g_clip_property_atom = XInternAtom(g_display, "XRDP_CLIP_PROPERTY_ATOM",
|
|
|
|
False);
|
|
|
|
g_get_time_atom = XInternAtom(g_display, "XRDP_GET_TIME_ATOM",
|
|
|
|
False);
|
|
|
|
g_timestamp_atom = XInternAtom(g_display, "TIMESTAMP", False);
|
|
|
|
g_targets_atom = XInternAtom(g_display, "TARGETS", False);
|
|
|
|
g_multiple_atom = XInternAtom(g_display, "MULTIPLE", False);
|
|
|
|
g_primary_atom = XInternAtom(g_display, "PRIMARY", False);
|
|
|
|
g_secondary_atom = XInternAtom(g_display, "SECONDARY", False);
|
|
|
|
g_utf8_atom = XInternAtom(g_display, "UTF8_STRING", False);
|
|
|
|
|
|
|
|
g_image_bmp_atom = XInternAtom(g_display, "image/bmp", False);
|
2012-10-05 09:55:06 +04:00
|
|
|
g_file_atom1 = XInternAtom(g_display, "text/uri-list", False);
|
|
|
|
g_file_atom2 = XInternAtom(g_display, "x-special/gnome-copied-files", False);
|
2012-09-20 07:51:34 +04:00
|
|
|
g_incr_atom = XInternAtom(g_display, "INCR", False);
|
|
|
|
|
|
|
|
if (g_image_bmp_atom == None)
|
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_ERROR, "clipboard_init: g_image_bmp_atom was "
|
2020-11-30 03:36:20 +03:00
|
|
|
"not allocated");
|
2012-09-20 07:51:34 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
g_wnd = XCreateSimpleWindow(g_display, RootWindowOfScreen(g_screen),
|
|
|
|
0, 0, 4, 4, 0, 0, 0);
|
|
|
|
input_mask = StructureNotifyMask | PropertyChangeMask;
|
|
|
|
XSelectInput(g_display, g_wnd, input_mask);
|
|
|
|
//XMapWindow(g_display, g_wnd);
|
|
|
|
XFixesSelectSelectionInput(g_display, g_wnd,
|
|
|
|
g_clipboard_atom,
|
|
|
|
XFixesSetSelectionOwnerNotifyMask |
|
|
|
|
XFixesSelectionWindowDestroyNotifyMask |
|
|
|
|
XFixesSelectionClientCloseNotifyMask);
|
2009-08-15 06:47:51 +04:00
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
|
2012-10-05 09:55:06 +04:00
|
|
|
make_stream(s);
|
2012-09-20 07:51:34 +04:00
|
|
|
if (rv == 0)
|
|
|
|
{
|
2012-10-05 09:55:06 +04:00
|
|
|
/* set clipboard caps first */
|
2012-09-20 07:51:34 +04:00
|
|
|
init_stream(s, 8192);
|
2012-10-05 09:55:06 +04:00
|
|
|
/* CLIPRDR_HEADER */
|
|
|
|
out_uint16_le(s, CB_CLIP_CAPS); /* msgType */
|
|
|
|
out_uint16_le(s, 0); /* msgFlags */
|
|
|
|
out_uint32_le(s, 16); /* dataLen */
|
|
|
|
out_uint16_le(s, 1); /* cCapabilitiesSets */
|
|
|
|
out_uint16_le(s, 0); /* pad1 */
|
|
|
|
/* CLIPRDR_GENERAL_CAPABILITY */
|
2021-05-27 17:34:13 +03:00
|
|
|
out_uint16_le(s, CB_CAPSTYPE_GENERAL); /* capabilitySetType */
|
2012-10-05 09:55:06 +04:00
|
|
|
out_uint16_le(s, 12); /* lengthCapability */
|
|
|
|
out_uint32_le(s, g_cliprdr_version); /* version */
|
|
|
|
out_uint32_le(s, g_cliprdr_flags); /* generalFlags */
|
2012-09-20 07:51:34 +04:00
|
|
|
out_uint32_le(s, 0); /* extra 4 bytes ? */
|
|
|
|
s_mark_end(s);
|
|
|
|
size = (int)(s->end - s->data);
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "clipboard_init: data out, sending "
|
2020-11-30 03:36:20 +03:00
|
|
|
"CB_CLIP_CAPS (clip_msg_id = 1)");
|
2012-09-20 07:51:34 +04:00
|
|
|
rv = send_channel_data(g_cliprdr_chan_id, s->data, size);
|
|
|
|
if (rv != 0)
|
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_ERROR, "clipboard_init: send_channel_data failed "
|
2020-11-30 03:36:20 +03:00
|
|
|
"rv = %d", rv);
|
2012-09-20 07:51:34 +04:00
|
|
|
rv = 4;
|
|
|
|
}
|
2012-10-05 09:55:06 +04:00
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
|
2012-10-05 09:55:06 +04:00
|
|
|
if (rv == 0)
|
|
|
|
{
|
|
|
|
/* report clipboard ready */
|
|
|
|
init_stream(s, 8192);
|
|
|
|
out_uint16_le(s, CB_MONITOR_READY); /* msgType */
|
|
|
|
out_uint16_le(s, 0); /* msgFlags */
|
|
|
|
out_uint32_le(s, 0); /* dataLen */
|
|
|
|
out_uint32_le(s, 0); /* extra 4 bytes ? */
|
|
|
|
s_mark_end(s);
|
|
|
|
size = (int)(s->end - s->data);
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "clipboard_init: data out, sending "
|
2020-11-30 03:36:20 +03:00
|
|
|
"CB_MONITOR_READY (clip_msg_id = 1)");
|
2012-10-05 09:55:06 +04:00
|
|
|
rv = send_channel_data(g_cliprdr_chan_id, s->data, size);
|
|
|
|
if (rv != 0)
|
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_ERROR, "clipboard_init: send_channel_data failed "
|
2020-11-30 03:36:20 +03:00
|
|
|
"rv = %d", rv);
|
2012-10-05 09:55:06 +04:00
|
|
|
rv = 4;
|
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
}
|
2012-10-05 09:55:06 +04:00
|
|
|
free_stream(s);
|
2012-09-20 07:51:34 +04:00
|
|
|
|
|
|
|
if (rv == 0)
|
|
|
|
{
|
|
|
|
g_clip_up = 1;
|
|
|
|
make_stream(g_ins);
|
|
|
|
init_stream(g_ins, 8192);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_ERROR, "xrdp-chansrv: clipboard_init: error on exit");
|
2012-09-20 07:51:34 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
2009-08-15 06:47:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2017-03-12 19:35:00 +03:00
|
|
|
int
|
2009-08-15 06:47:51 +04:00
|
|
|
clipboard_deinit(void)
|
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_INFO, "clipboard_deinit:");
|
2012-09-20 07:51:34 +04:00
|
|
|
if (g_wnd != 0)
|
|
|
|
{
|
|
|
|
XDestroyWindow(g_display, g_wnd);
|
|
|
|
g_wnd = 0;
|
|
|
|
}
|
|
|
|
|
2013-03-09 03:37:30 +04:00
|
|
|
xfuse_deinit();
|
2012-10-30 07:12:24 +04:00
|
|
|
|
2012-10-18 08:23:31 +04:00
|
|
|
g_free(g_clip_c2s.data);
|
|
|
|
g_clip_c2s.data = 0;
|
2012-10-18 20:58:23 +04:00
|
|
|
g_free(g_clip_s2c.data);
|
|
|
|
g_clip_s2c.data = 0;
|
2012-10-18 08:23:31 +04:00
|
|
|
|
2012-09-20 07:51:34 +04:00
|
|
|
free_stream(g_ins);
|
|
|
|
g_ins = 0;
|
|
|
|
g_clip_up = 0;
|
|
|
|
return 0;
|
2009-08-15 06:47:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2017-03-12 19:35:00 +03:00
|
|
|
static int
|
2012-10-14 09:48:29 +04:00
|
|
|
clipboard_send_data_request(int format_id)
|
2009-08-15 06:47:51 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
struct stream *s;
|
|
|
|
int size;
|
|
|
|
int rv;
|
|
|
|
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "clipboard_send_data_request:");
|
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "clipboard_send_data_request: %d", format_id);
|
2012-11-12 07:33:53 +04:00
|
|
|
g_clip_c2s.in_request = 1;
|
2012-09-20 07:51:34 +04:00
|
|
|
make_stream(s);
|
|
|
|
init_stream(s, 8192);
|
2012-10-14 09:48:29 +04:00
|
|
|
out_uint16_le(s, CB_FORMAT_DATA_REQUEST); /* 4 CLIPRDR_DATA_REQUEST */
|
2012-09-20 07:51:34 +04:00
|
|
|
out_uint16_le(s, 0); /* status */
|
|
|
|
out_uint32_le(s, 4); /* length */
|
2012-10-14 09:48:29 +04:00
|
|
|
out_uint32_le(s, format_id);
|
|
|
|
out_uint32_le(s, 0);
|
2012-09-20 07:51:34 +04:00
|
|
|
s_mark_end(s);
|
|
|
|
size = (int)(s->end - s->data);
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "clipboard_send_data_request: data out, sending "
|
2020-11-30 03:36:20 +03:00
|
|
|
"CLIPRDR_DATA_REQUEST (clip_msg_id = 4)");
|
2012-09-20 07:51:34 +04:00
|
|
|
rv = send_channel_data(g_cliprdr_chan_id, s->data, size);
|
|
|
|
free_stream(s);
|
|
|
|
return rv;
|
2009-08-15 06:47:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2017-03-12 19:35:00 +03:00
|
|
|
static int
|
2009-08-15 06:47:51 +04:00
|
|
|
clipboard_send_format_ack(void)
|
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
struct stream *s;
|
|
|
|
int size;
|
|
|
|
int rv;
|
|
|
|
|
|
|
|
make_stream(s);
|
|
|
|
init_stream(s, 8192);
|
2012-10-14 22:46:01 +04:00
|
|
|
out_uint16_le(s, CB_FORMAT_LIST_RESPONSE); /* 3 CLIPRDR_FORMAT_ACK */
|
|
|
|
out_uint16_le(s, CB_RESPONSE_OK); /* 1 status */
|
2012-09-20 07:51:34 +04:00
|
|
|
out_uint32_le(s, 0); /* length */
|
2012-10-14 22:46:01 +04:00
|
|
|
out_uint32_le(s, 0); /* extra 4 bytes */
|
2012-09-20 07:51:34 +04:00
|
|
|
s_mark_end(s);
|
|
|
|
size = (int)(s->end - s->data);
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "clipboard_send_format_ack: data out, sending "
|
2020-11-30 03:36:20 +03:00
|
|
|
"CLIPRDR_FORMAT_ACK (clip_msg_id = 3)");
|
2012-09-20 07:51:34 +04:00
|
|
|
rv = send_channel_data(g_cliprdr_chan_id, s->data, size);
|
|
|
|
free_stream(s);
|
|
|
|
return rv;
|
2009-08-15 06:47:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2023-10-16 15:43:29 +03:00
|
|
|
/**
|
|
|
|
* Output null-terminated string as Unicode with a null terminator
|
|
|
|
* @param s stream
|
|
|
|
* @param text UTF-8 String
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
clipboard_out_utf8_as_utf16_le(struct stream *s, const char *text)
|
2009-08-15 06:47:51 +04:00
|
|
|
{
|
2023-10-16 15:43:29 +03:00
|
|
|
out_utf8_as_utf16_le(s, text, strlen(text) + 1);
|
2009-08-15 06:47:51 +04:00
|
|
|
}
|
|
|
|
|
2012-10-05 09:55:06 +04:00
|
|
|
/*****************************************************************************/
|
2023-10-16 15:43:29 +03:00
|
|
|
unsigned int
|
|
|
|
clipboard_in_utf16_le_as_utf8(struct stream *s, char *text,
|
|
|
|
unsigned int num_chars)
|
2012-10-05 09:55:06 +04:00
|
|
|
{
|
2023-10-16 15:43:29 +03:00
|
|
|
char *orig_p = s->p;
|
|
|
|
unsigned int needed_chars;
|
2012-10-05 09:55:06 +04:00
|
|
|
|
2023-10-16 15:43:29 +03:00
|
|
|
if ((num_chars < 1) || (text == 0))
|
2012-10-05 09:55:06 +04:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2023-10-16 15:43:29 +03:00
|
|
|
|
|
|
|
needed_chars = in_utf16_le_terminated_as_utf8(s, text, num_chars);
|
|
|
|
if (needed_chars > num_chars)
|
2012-10-05 09:55:06 +04:00
|
|
|
{
|
2023-10-16 15:43:29 +03:00
|
|
|
LOG(LOG_LEVEL_WARNING, "UTF-16 string was truncated on input");
|
2012-10-05 09:55:06 +04:00
|
|
|
}
|
2023-10-16 15:43:29 +03:00
|
|
|
return s->p - orig_p;
|
2012-10-05 09:55:06 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static char windows_native_format[] =
|
|
|
|
{
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
|
|
|
};
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2017-03-12 19:35:00 +03:00
|
|
|
static int
|
2012-10-14 09:48:29 +04:00
|
|
|
clipboard_send_format_announce(int xrdp_clip_type)
|
2012-10-05 09:55:06 +04:00
|
|
|
{
|
|
|
|
struct stream *s;
|
|
|
|
int size;
|
|
|
|
int rv;
|
|
|
|
char *holdp;
|
|
|
|
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "clipboard_send_format_announce:");
|
2012-10-05 09:55:06 +04:00
|
|
|
make_stream(s);
|
|
|
|
init_stream(s, 8192);
|
2012-10-14 09:48:29 +04:00
|
|
|
out_uint16_le(s, CB_FORMAT_LIST); /* 2 CLIPRDR_FORMAT_ANNOUNCE */
|
2012-10-05 09:55:06 +04:00
|
|
|
out_uint16_le(s, 0); /* status */
|
|
|
|
holdp = s->p;
|
|
|
|
out_uint32_le(s, 0); /* set later */
|
|
|
|
if (g_cliprdr_flags & CB_USE_LONG_FORMAT_NAMES)
|
|
|
|
{
|
2012-10-14 09:48:29 +04:00
|
|
|
switch (xrdp_clip_type)
|
2012-10-05 09:55:06 +04:00
|
|
|
{
|
2012-10-14 09:48:29 +04:00
|
|
|
case XRDP_CB_FILE:
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "clipboard_send_format_announce: XRDP_CB_FILE");
|
2012-10-14 09:48:29 +04:00
|
|
|
/* canned response for "file" */
|
2023-08-04 19:08:42 +03:00
|
|
|
out_uint32_le(s, CB_FORMAT_FILE_GROUP_DESCRIPTOR);
|
2023-10-16 15:43:29 +03:00
|
|
|
clipboard_out_utf8_as_utf16_le(s, "FileGroupDescriptorW");
|
2012-10-14 09:48:29 +04:00
|
|
|
out_uint32_le(s, 0x0000c0ba);
|
2023-10-16 15:43:29 +03:00
|
|
|
clipboard_out_utf8_as_utf16_le(s, "FileContents");
|
2012-10-14 09:48:29 +04:00
|
|
|
out_uint32_le(s, 0x0000c0c1);
|
2023-10-16 15:43:29 +03:00
|
|
|
clipboard_out_utf8_as_utf16_le(s, "DropEffect");
|
2012-10-14 09:48:29 +04:00
|
|
|
break;
|
|
|
|
case XRDP_CB_BITMAP:
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "clipboard_send_format_announce: XRDP_CB_BITMAP");
|
2012-10-14 09:48:29 +04:00
|
|
|
/* canned response for "bitmap" */
|
|
|
|
out_uint32_le(s, 0x0000c004);
|
2023-10-16 15:43:29 +03:00
|
|
|
clipboard_out_utf8_as_utf16_le(s, "Native");
|
2012-10-14 09:48:29 +04:00
|
|
|
out_uint32_le(s, 0x00000003);
|
2023-10-16 15:43:29 +03:00
|
|
|
clipboard_out_utf8_as_utf16_le(s, "");
|
2012-10-14 09:48:29 +04:00
|
|
|
out_uint32_le(s, 0x00000008);
|
2023-10-16 15:43:29 +03:00
|
|
|
clipboard_out_utf8_as_utf16_le(s, "");
|
2012-10-14 09:48:29 +04:00
|
|
|
out_uint32_le(s, 0x00000011);
|
2023-10-16 15:43:29 +03:00
|
|
|
clipboard_out_utf8_as_utf16_le(s, "");
|
2012-10-14 09:48:29 +04:00
|
|
|
break;
|
|
|
|
case XRDP_CB_TEXT:
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "clipboard_send_format_announce: XRDP_CB_TEXT");
|
2012-10-14 09:48:29 +04:00
|
|
|
/* canned response for "bitmap" */
|
|
|
|
out_uint32_le(s, 0x0000000d);
|
2023-10-16 15:43:29 +03:00
|
|
|
clipboard_out_utf8_as_utf16_le(s, "");
|
2012-10-14 09:48:29 +04:00
|
|
|
out_uint32_le(s, 0x00000010);
|
2023-10-16 15:43:29 +03:00
|
|
|
clipboard_out_utf8_as_utf16_le(s, "");
|
2012-10-14 09:48:29 +04:00
|
|
|
out_uint32_le(s, 0x00000001);
|
2023-10-16 15:43:29 +03:00
|
|
|
clipboard_out_utf8_as_utf16_le(s, "");
|
2012-10-14 09:48:29 +04:00
|
|
|
out_uint32_le(s, 0x00000007);
|
2023-10-16 15:43:29 +03:00
|
|
|
clipboard_out_utf8_as_utf16_le(s, "");
|
2012-10-14 09:48:29 +04:00
|
|
|
break;
|
|
|
|
default:
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "clipboard_send_format_announce: unknown "
|
2020-11-30 03:36:20 +03:00
|
|
|
"xrdp_clip_type %d", xrdp_clip_type);
|
2012-10-14 09:48:29 +04:00
|
|
|
break;
|
2012-10-05 09:55:06 +04:00
|
|
|
}
|
|
|
|
}
|
2012-10-19 05:43:04 +04:00
|
|
|
else /* old method */
|
2012-10-05 09:55:06 +04:00
|
|
|
{
|
2012-10-19 05:43:04 +04:00
|
|
|
switch (xrdp_clip_type)
|
|
|
|
{
|
|
|
|
case XRDP_CB_FILE:
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "clipboard_send_format_announce: XRDP_CB_FILE");
|
2012-10-19 05:43:04 +04:00
|
|
|
/* canned response for "file" */
|
2023-08-04 19:08:42 +03:00
|
|
|
out_uint32_le(s, CB_FORMAT_FILE_GROUP_DESCRIPTOR);
|
2012-10-19 05:43:04 +04:00
|
|
|
out_uint8p(s, windows_native_format, sizeof(windows_native_format));
|
|
|
|
out_uint32_le(s, 0x0000c0ba);
|
|
|
|
out_uint8p(s, windows_native_format, sizeof(windows_native_format));
|
|
|
|
out_uint32_le(s, 0x0000c0c1);
|
|
|
|
out_uint8p(s, windows_native_format, sizeof(windows_native_format));
|
|
|
|
break;
|
|
|
|
case XRDP_CB_BITMAP:
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "clipboard_send_format_announce: XRDP_CB_BITMAP");
|
2012-10-19 05:43:04 +04:00
|
|
|
/* canned response for "bitmap" */
|
|
|
|
out_uint32_le(s, 0x0000c004);
|
|
|
|
out_uint8p(s, windows_native_format, sizeof(windows_native_format));
|
|
|
|
out_uint32_le(s, 0x00000003);
|
|
|
|
out_uint8p(s, windows_native_format, sizeof(windows_native_format));
|
|
|
|
out_uint32_le(s, 0x00000008);
|
|
|
|
out_uint8p(s, windows_native_format, sizeof(windows_native_format));
|
|
|
|
out_uint32_le(s, 0x00000011);
|
|
|
|
out_uint8p(s, windows_native_format, sizeof(windows_native_format));
|
|
|
|
break;
|
|
|
|
case XRDP_CB_TEXT:
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "clipboard_send_format_announce: XRDP_CB_TEXT");
|
2012-10-19 05:43:04 +04:00
|
|
|
/* canned response for "bitmap" */
|
|
|
|
out_uint32_le(s, 0x0000000d);
|
|
|
|
out_uint8p(s, windows_native_format, sizeof(windows_native_format));
|
|
|
|
out_uint32_le(s, 0x00000010);
|
|
|
|
out_uint8p(s, windows_native_format, sizeof(windows_native_format));
|
|
|
|
out_uint32_le(s, 0x00000001);
|
|
|
|
out_uint8p(s, windows_native_format, sizeof(windows_native_format));
|
|
|
|
out_uint32_le(s, 0x00000007);
|
|
|
|
out_uint8p(s, windows_native_format, sizeof(windows_native_format));
|
|
|
|
break;
|
|
|
|
default:
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "clipboard_send_format_announce: unknown "
|
2020-11-30 03:36:20 +03:00
|
|
|
"xrdp_clip_type %d", xrdp_clip_type);
|
2012-10-19 05:43:04 +04:00
|
|
|
break;
|
|
|
|
}
|
2012-10-05 09:55:06 +04:00
|
|
|
}
|
|
|
|
size = (int)(s->p - holdp);
|
|
|
|
size -= 4;
|
|
|
|
holdp[0] = (size >> 0) & 0xff;
|
|
|
|
holdp[1] = (size >> 8) & 0xff;
|
|
|
|
holdp[2] = (size >> 16) & 0xff;
|
|
|
|
holdp[3] = (size >> 24) & 0xff;
|
2012-10-14 09:48:29 +04:00
|
|
|
out_uint32_le(s, 0);
|
2012-10-05 09:55:06 +04:00
|
|
|
s_mark_end(s);
|
|
|
|
size = (int)(s->end - s->data);
|
2020-11-30 03:36:20 +03:00
|
|
|
LOG_DEVEL_HEXDUMP(LOG_LEVEL_TRACE, "clipboard data:", s->data, size);
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "clipboard_send_format_announce: data out, sending "
|
2020-11-30 03:36:20 +03:00
|
|
|
"CLIPRDR_FORMAT_ANNOUNCE (clip_msg_id = 2)");
|
2012-10-05 09:55:06 +04:00
|
|
|
rv = send_channel_data(g_cliprdr_chan_id, s->data, size);
|
|
|
|
free_stream(s);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2012-08-12 21:51:45 +04:00
|
|
|
/*****************************************************************************/
|
2017-03-12 19:35:00 +03:00
|
|
|
static int
|
2017-01-22 21:27:50 +03:00
|
|
|
clipboard_send_data_response_for_image(const char *data, int data_size)
|
2012-08-12 21:51:45 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
struct stream *s;
|
|
|
|
int size;
|
|
|
|
int rv;
|
|
|
|
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "clipboard_send_data_response_for_image: data_size %d",
|
2020-11-30 03:36:20 +03:00
|
|
|
data_size);
|
2012-09-20 07:51:34 +04:00
|
|
|
make_stream(s);
|
2012-10-14 09:48:29 +04:00
|
|
|
init_stream(s, 64 + data_size);
|
|
|
|
out_uint16_le(s, CB_FORMAT_DATA_RESPONSE); /* 5 CLIPRDR_DATA_RESPONSE */
|
|
|
|
out_uint16_le(s, CB_RESPONSE_OK); /* 1 status */
|
|
|
|
out_uint32_le(s, data_size); /* length */
|
|
|
|
out_uint8p(s, data, data_size);
|
2012-09-20 07:51:34 +04:00
|
|
|
out_uint32_le(s, 0);
|
|
|
|
s_mark_end(s);
|
|
|
|
size = (int)(s->end - s->data);
|
|
|
|
rv = send_channel_data(g_cliprdr_chan_id, s->data, size);
|
|
|
|
free_stream(s);
|
|
|
|
return rv;
|
2012-08-12 21:51:45 +04:00
|
|
|
}
|
|
|
|
|
2009-08-15 06:47:51 +04:00
|
|
|
/*****************************************************************************/
|
2017-03-12 19:35:00 +03:00
|
|
|
static int
|
2017-01-22 21:27:50 +03:00
|
|
|
clipboard_send_data_response_for_text(const char *data, int data_size)
|
2009-08-15 06:47:51 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
struct stream *s;
|
|
|
|
int size;
|
|
|
|
int rv;
|
2023-10-16 15:43:29 +03:00
|
|
|
int num_words;
|
2012-09-20 07:51:34 +04:00
|
|
|
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "clipboard_send_data_response_for_text: data_size %d",
|
2020-11-30 03:36:20 +03:00
|
|
|
data_size);
|
|
|
|
LOG_DEVEL_HEXDUMP(LOG_LEVEL_TRACE, "clipboard send data response:", data, data_size);
|
2023-10-16 15:43:29 +03:00
|
|
|
num_words = utf8_as_utf16_word_count(data, data_size);
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "clipboard_send_data_response_for_text: data_size %d "
|
2023-10-16 15:43:29 +03:00
|
|
|
"num_words %d", data_size, num_words);
|
2012-10-14 09:48:29 +04:00
|
|
|
make_stream(s);
|
2023-10-16 15:43:29 +03:00
|
|
|
init_stream(s, 64 + num_words * 2);
|
2012-10-14 09:48:29 +04:00
|
|
|
out_uint16_le(s, CB_FORMAT_DATA_RESPONSE); /* 5 CLIPRDR_DATA_RESPONSE */
|
|
|
|
out_uint16_le(s, CB_RESPONSE_OK); /* 1 status */
|
2023-10-16 15:43:29 +03:00
|
|
|
out_uint32_le(s, num_words * 2 + 2); /* length */
|
|
|
|
out_utf8_as_utf16_le(s, data, data_size);
|
2012-10-14 09:48:29 +04:00
|
|
|
out_uint16_le(s, 0); /* nil for string */
|
|
|
|
out_uint32_le(s, 0);
|
|
|
|
s_mark_end(s);
|
|
|
|
size = (int)(s->end - s->data);
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "clipboard_send_data_response_for_text: data out, "
|
2020-11-30 03:36:20 +03:00
|
|
|
"sending CLIPRDR_DATA_RESPONSE (clip_msg_id = 5) size %d "
|
2023-10-16 15:43:29 +03:00
|
|
|
"num_words %d", size, num_words);
|
2012-10-14 09:48:29 +04:00
|
|
|
rv = send_channel_data(g_cliprdr_chan_id, s->data, size);
|
|
|
|
free_stream(s);
|
|
|
|
return rv;
|
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
|
2012-10-14 09:48:29 +04:00
|
|
|
/*****************************************************************************/
|
2017-03-12 19:35:00 +03:00
|
|
|
static int
|
2017-01-22 21:27:50 +03:00
|
|
|
clipboard_send_data_response(int xrdp_clip_type, const char *data, int data_size)
|
2012-10-14 09:48:29 +04:00
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "clipboard_send_data_response:");
|
2012-10-15 09:13:22 +04:00
|
|
|
if (data != 0)
|
2012-10-14 09:48:29 +04:00
|
|
|
{
|
2012-10-15 09:13:22 +04:00
|
|
|
if (xrdp_clip_type == XRDP_CB_FILE)
|
2012-10-14 09:48:29 +04:00
|
|
|
{
|
|
|
|
return clipboard_send_data_response_for_file(data, data_size);
|
|
|
|
}
|
2012-10-15 09:13:22 +04:00
|
|
|
else if (xrdp_clip_type == XRDP_CB_BITMAP)
|
2012-10-14 09:48:29 +04:00
|
|
|
{
|
|
|
|
return clipboard_send_data_response_for_image(data, data_size);
|
|
|
|
}
|
2012-10-15 09:13:22 +04:00
|
|
|
else if (xrdp_clip_type == XRDP_CB_TEXT)
|
2012-10-14 09:48:29 +04:00
|
|
|
{
|
|
|
|
return clipboard_send_data_response_for_text(data, data_size);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "clipboard_send_data_response: unknown "
|
2020-11-30 03:36:20 +03:00
|
|
|
"xrdp_clip_type %d", xrdp_clip_type);
|
2012-10-14 09:48:29 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_ERROR, "clipboard_send_data_response: data is nil");
|
2012-10-14 09:48:29 +04:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-09-02 00:39:06 +04:00
|
|
|
/*****************************************************************************/
|
2017-03-12 19:35:00 +03:00
|
|
|
static int
|
2009-09-02 00:39:06 +04:00
|
|
|
clipboard_set_selection_owner(void)
|
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
Window owner;
|
2009-09-02 00:39:06 +04:00
|
|
|
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "clipboard_set_selection_owner:");
|
2012-09-20 07:51:34 +04:00
|
|
|
g_selection_time = clipboard_get_server_time();
|
|
|
|
XSetSelectionOwner(g_display, g_clipboard_atom, g_wnd, g_selection_time);
|
|
|
|
owner = XGetSelectionOwner(g_display, g_clipboard_atom);
|
|
|
|
|
|
|
|
if (owner != g_wnd)
|
|
|
|
{
|
|
|
|
g_got_selection = 0;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_got_selection = 1;
|
|
|
|
return 0;
|
2009-09-02 00:39:06 +04:00
|
|
|
}
|
|
|
|
|
2009-09-02 06:52:30 +04:00
|
|
|
/*****************************************************************************/
|
2017-03-12 19:35:00 +03:00
|
|
|
static int
|
2012-10-21 07:23:01 +04:00
|
|
|
clipboard_provide_selection_c2s(XSelectionRequestEvent *req, Atom type)
|
2009-09-02 06:52:30 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
XEvent xev;
|
2012-10-17 12:13:37 +04:00
|
|
|
long val1[2];
|
2012-10-15 05:08:06 +04:00
|
|
|
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "clipboard_provide_selection_c2s: bytes %d",
|
2020-11-30 03:36:20 +03:00
|
|
|
g_clip_c2s.total_bytes);
|
2012-10-21 07:23:01 +04:00
|
|
|
if (g_clip_c2s.total_bytes < g_incr_max_req_size)
|
2012-10-15 05:08:06 +04:00
|
|
|
{
|
|
|
|
XChangeProperty(g_display, req->requestor, req->property,
|
2012-10-21 07:23:01 +04:00
|
|
|
type, 8, PropModeReplace,
|
|
|
|
(tui8 *)g_clip_c2s.data, g_clip_c2s.total_bytes);
|
2012-10-15 05:08:06 +04:00
|
|
|
g_memset(&xev, 0, sizeof(xev));
|
|
|
|
xev.xselection.type = SelectionNotify;
|
|
|
|
xev.xselection.send_event = True;
|
|
|
|
xev.xselection.display = req->display;
|
|
|
|
xev.xselection.requestor = req->requestor;
|
|
|
|
xev.xselection.selection = req->selection;
|
|
|
|
xev.xselection.target = req->target;
|
|
|
|
xev.xselection.property = req->property;
|
|
|
|
xev.xselection.time = req->time;
|
|
|
|
XSendEvent(g_display, req->requestor, False, NoEventMask, &xev);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-10-21 07:23:01 +04:00
|
|
|
/* start the INCR process */
|
2012-10-18 20:58:23 +04:00
|
|
|
g_clip_c2s.incr_in_progress = 1;
|
|
|
|
g_clip_c2s.incr_bytes_done = 0;
|
|
|
|
g_clip_c2s.type = type;
|
|
|
|
g_clip_c2s.property = req->property;
|
|
|
|
g_clip_c2s.window = req->requestor;
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "clipboard_provide_selection_c2s: start INCR property %s "
|
2020-11-30 03:36:20 +03:00
|
|
|
"type %s", get_atom_text(req->property),
|
|
|
|
get_atom_text(type));
|
2012-10-21 07:23:01 +04:00
|
|
|
val1[0] = g_clip_c2s.total_bytes;
|
2012-10-17 12:13:37 +04:00
|
|
|
val1[1] = 0;
|
2012-10-15 05:08:06 +04:00
|
|
|
XChangeProperty(g_display, req->requestor, req->property,
|
2012-10-17 12:13:37 +04:00
|
|
|
g_incr_atom, 32, PropModeReplace, (tui8 *)val1, 1);
|
|
|
|
/* we need events from that other window */
|
|
|
|
XSelectInput(g_display, req->requestor, PropertyChangeMask);
|
2012-10-15 05:08:06 +04:00
|
|
|
g_memset(&xev, 0, sizeof(xev));
|
|
|
|
xev.xselection.type = SelectionNotify;
|
|
|
|
xev.xselection.send_event = True;
|
|
|
|
xev.xselection.display = req->display;
|
|
|
|
xev.xselection.requestor = req->requestor;
|
|
|
|
xev.xselection.selection = req->selection;
|
|
|
|
xev.xselection.target = req->target;
|
|
|
|
xev.xselection.property = req->property;
|
|
|
|
xev.xselection.time = req->time;
|
|
|
|
XSendEvent(g_display, req->requestor, False, NoEventMask, &xev);
|
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
return 0;
|
2009-09-02 06:52:30 +04:00
|
|
|
}
|
|
|
|
|
2012-10-21 07:23:01 +04:00
|
|
|
/*****************************************************************************/
|
2017-03-12 19:35:00 +03:00
|
|
|
static int
|
2012-10-21 07:23:01 +04:00
|
|
|
clipboard_provide_selection(XSelectionRequestEvent *req, Atom type, int format,
|
|
|
|
char *data, int length)
|
|
|
|
{
|
|
|
|
XEvent xev;
|
|
|
|
int bytes;
|
|
|
|
|
|
|
|
bytes = FORMAT_TO_BYTES(format);
|
|
|
|
bytes *= length;
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "clipboard_provide_selection: bytes %d", bytes);
|
2012-10-21 07:23:01 +04:00
|
|
|
if (bytes < g_incr_max_req_size)
|
|
|
|
{
|
|
|
|
XChangeProperty(g_display, req->requestor, req->property,
|
2017-01-17 17:18:23 +03:00
|
|
|
type, format, PropModeReplace, (tui8 *)data, length);
|
2012-10-21 07:23:01 +04:00
|
|
|
g_memset(&xev, 0, sizeof(xev));
|
|
|
|
xev.xselection.type = SelectionNotify;
|
|
|
|
xev.xselection.send_event = True;
|
|
|
|
xev.xselection.display = req->display;
|
|
|
|
xev.xselection.requestor = req->requestor;
|
|
|
|
xev.xselection.selection = req->selection;
|
|
|
|
xev.xselection.target = req->target;
|
|
|
|
xev.xselection.property = req->property;
|
|
|
|
xev.xselection.time = req->time;
|
|
|
|
XSendEvent(g_display, req->requestor, False, NoEventMask, &xev);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2009-09-02 06:52:30 +04:00
|
|
|
/*****************************************************************************/
|
2017-03-12 19:35:00 +03:00
|
|
|
static int
|
2012-09-20 07:51:34 +04:00
|
|
|
clipboard_refuse_selection(XSelectionRequestEvent *req)
|
2009-09-02 06:52:30 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
XEvent xev;
|
|
|
|
|
|
|
|
g_memset(&xev, 0, sizeof(xev));
|
|
|
|
xev.xselection.type = SelectionNotify;
|
|
|
|
xev.xselection.send_event = True;
|
|
|
|
xev.xselection.display = req->display;
|
|
|
|
xev.xselection.requestor = req->requestor;
|
|
|
|
xev.xselection.selection = req->selection;
|
|
|
|
xev.xselection.target = req->target;
|
|
|
|
xev.xselection.property = None;
|
|
|
|
xev.xselection.time = req->time;
|
|
|
|
XSendEvent(g_display, req->requestor, False, NoEventMask, &xev);
|
|
|
|
return 0;
|
2009-09-02 06:52:30 +04:00
|
|
|
}
|
|
|
|
|
2009-08-15 06:47:51 +04:00
|
|
|
/*****************************************************************************/
|
2012-08-20 06:45:31 +04:00
|
|
|
/* sent by client or server when its local system clipboard is
|
|
|
|
updated with new clipboard data; contains Clipboard Format ID
|
|
|
|
and name pairs of new Clipboard Formats on the clipboard. */
|
2017-03-12 19:35:00 +03:00
|
|
|
static int
|
2012-09-20 07:51:34 +04:00
|
|
|
clipboard_process_format_announce(struct stream *s, int clip_msg_status,
|
2009-08-23 04:48:20 +04:00
|
|
|
int clip_msg_len)
|
2009-08-15 06:47:51 +04:00
|
|
|
{
|
2012-10-05 09:55:06 +04:00
|
|
|
int formatId;
|
|
|
|
int bytes;
|
|
|
|
char desc[256];
|
|
|
|
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "clipboard_process_format_announce: "
|
2020-11-30 03:36:20 +03:00
|
|
|
"CLIPRDR_FORMAT_ANNOUNCE");
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "clipboard_process_format_announce %d", clip_msg_len);
|
2012-09-20 07:51:34 +04:00
|
|
|
clipboard_send_format_ack();
|
2012-11-05 13:04:04 +04:00
|
|
|
|
2013-03-09 03:37:30 +04:00
|
|
|
xfuse_clear_clip_dir();
|
2012-11-05 13:04:04 +04:00
|
|
|
g_clip_c2s.converted = 0;
|
|
|
|
|
2012-10-05 09:55:06 +04:00
|
|
|
desc[0] = 0;
|
|
|
|
g_num_formatIds = 0;
|
|
|
|
while (clip_msg_len > 3)
|
|
|
|
{
|
|
|
|
in_uint32_le(s, formatId);
|
|
|
|
clip_msg_len -= 4;
|
|
|
|
if (g_cliprdr_flags & CB_USE_LONG_FORMAT_NAMES)
|
|
|
|
{
|
|
|
|
/* CLIPRDR_LONG_FORMAT_NAME */
|
2023-10-16 15:43:29 +03:00
|
|
|
bytes = clipboard_in_utf16_le_as_utf8(s, desc, sizeof(desc));
|
2012-10-05 09:55:06 +04:00
|
|
|
clip_msg_len -= bytes;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* CLIPRDR_SHORT_FORMAT_NAME */
|
|
|
|
/* 32 ASCII 8 characters or 16 Unicode characters */
|
2023-10-16 15:43:29 +03:00
|
|
|
in_utf16_le_fixed_as_utf8(s, 16, desc, sizeof(desc));
|
2012-10-05 09:55:06 +04:00
|
|
|
desc[15] = 0;
|
|
|
|
clip_msg_len -= 32;
|
|
|
|
}
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "clipboard_process_format_announce: formatId 0x%8.8x "
|
2020-11-30 03:36:20 +03:00
|
|
|
"wszFormatName [%s] clip_msg_len %d", formatId, desc,
|
|
|
|
clip_msg_len);
|
2014-07-20 22:11:20 +04:00
|
|
|
if (g_num_formatIds <= 15)
|
|
|
|
{
|
|
|
|
g_formatIds[g_num_formatIds] = formatId;
|
|
|
|
g_num_formatIds++;
|
|
|
|
}
|
2012-10-05 09:55:06 +04:00
|
|
|
if (g_num_formatIds > 15)
|
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "clipboard_process_format_announce: max formats");
|
2012-10-05 09:55:06 +04:00
|
|
|
}
|
2012-11-05 13:04:04 +04:00
|
|
|
|
2023-08-04 19:08:42 +03:00
|
|
|
/* format id for file copy copy is dynamic and announced by the
|
|
|
|
* client */
|
2012-11-04 05:47:04 +04:00
|
|
|
if (g_strcmp(desc, "FileGroupDescriptorW") == 0)
|
2012-10-30 07:12:24 +04:00
|
|
|
{
|
2023-08-04 19:08:42 +03:00
|
|
|
g_file_group_descriptor_format_id = formatId;
|
2012-10-30 07:12:24 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-22 09:15:31 +04:00
|
|
|
if ((g_num_formatIds > 0) &&
|
2019-02-26 09:40:10 +03:00
|
|
|
(g_clip_c2s.incr_in_progress == 0) && /* don't interrupt incr */
|
|
|
|
(g_clip_s2c.incr_in_progress == 0))
|
2012-09-20 07:51:34 +04:00
|
|
|
{
|
2012-10-05 09:55:06 +04:00
|
|
|
if (clipboard_set_selection_owner() != 0)
|
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_ERROR, "clipboard_process_format_announce: "
|
2020-11-30 03:36:20 +03:00
|
|
|
"XSetSelectionOwner failed");
|
2012-10-05 09:55:06 +04:00
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2009-08-15 06:47:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2012-08-20 06:45:31 +04:00
|
|
|
/* response to CB_FORMAT_LIST; used to indicate whether
|
|
|
|
processing of the Format List PDU was successful */
|
2017-03-12 19:35:00 +03:00
|
|
|
static int
|
2016-02-14 07:41:07 +03:00
|
|
|
clipboard_process_format_ack(struct stream *s, int clip_msg_status,
|
2009-08-23 04:48:20 +04:00
|
|
|
int clip_msg_len)
|
2009-08-15 06:47:51 +04:00
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "clipboard_process_format_ack: CLIPRDR_FORMAT_ACK");
|
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "clipboard_process_format_ack:");
|
2012-09-20 07:51:34 +04:00
|
|
|
return 0;
|
2009-08-15 06:47:51 +04:00
|
|
|
}
|
|
|
|
|
2012-10-14 09:48:29 +04:00
|
|
|
/*****************************************************************************/
|
|
|
|
static int
|
|
|
|
clipboard_send_data_response_failed(void)
|
|
|
|
{
|
|
|
|
struct stream *s;
|
|
|
|
int size;
|
|
|
|
int rv;
|
|
|
|
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_ERROR, "clipboard_send_data_response_failed:");
|
2012-10-14 09:48:29 +04:00
|
|
|
make_stream(s);
|
|
|
|
init_stream(s, 64);
|
|
|
|
out_uint16_le(s, CB_FORMAT_DATA_RESPONSE); /* 5 CLIPRDR_DATA_RESPONSE */
|
|
|
|
out_uint16_le(s, CB_RESPONSE_FAIL); /* 2 status */
|
|
|
|
out_uint32_le(s, 0);
|
|
|
|
s_mark_end(s);
|
|
|
|
size = (int)(s->end - s->data);
|
|
|
|
rv = send_channel_data(g_cliprdr_chan_id, s->data, size);
|
|
|
|
free_stream(s);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2009-08-15 06:47:51 +04:00
|
|
|
/*****************************************************************************/
|
2012-10-21 07:23:01 +04:00
|
|
|
/* sent from server to client
|
2012-10-19 05:43:04 +04:00
|
|
|
* sent by recipient of CB_FORMAT_LIST; used to request data for one
|
|
|
|
* of the formats that was listed in CB_FORMAT_LIST */
|
2017-03-12 19:35:00 +03:00
|
|
|
static int
|
2012-09-20 07:51:34 +04:00
|
|
|
clipboard_process_data_request(struct stream *s, int clip_msg_status,
|
2009-08-23 04:48:20 +04:00
|
|
|
int clip_msg_len)
|
2009-08-15 06:47:51 +04:00
|
|
|
{
|
2012-10-14 09:48:29 +04:00
|
|
|
int requestedFormatId;
|
|
|
|
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "clipboard_process_data_request: "
|
2020-11-30 03:36:20 +03:00
|
|
|
"CLIPRDR_DATA_REQUEST");
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "clipboard_process_data_request:");
|
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, " %d", g_clip_s2c.xrdp_clip_type);
|
2012-10-14 09:48:29 +04:00
|
|
|
in_uint32_le(s, requestedFormatId);
|
|
|
|
switch (requestedFormatId)
|
|
|
|
{
|
2023-08-04 19:08:42 +03:00
|
|
|
case CB_FORMAT_FILE_GROUP_DESCRIPTOR:
|
2012-10-21 07:23:01 +04:00
|
|
|
if ((g_clip_s2c.xrdp_clip_type == XRDP_CB_FILE) && g_clip_s2c.converted)
|
2012-10-15 05:08:06 +04:00
|
|
|
{
|
2023-08-04 19:08:42 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "clipboard_process_data_request: CB_FORMAT_FILE_GROUP_DESCRIPTOR");
|
2012-10-21 07:23:01 +04:00
|
|
|
clipboard_send_data_response(XRDP_CB_FILE, g_clip_s2c.data,
|
|
|
|
g_clip_s2c.total_bytes);
|
2012-10-15 05:08:06 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-08-04 19:08:42 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "clipboard_process_data_request: CB_FORMAT_FILE_GROUP_DESCRIPTOR, "
|
2020-11-30 03:36:20 +03:00
|
|
|
"calling XConvertSelection to g_utf8_atom");
|
2012-10-21 07:23:01 +04:00
|
|
|
g_clip_s2c.xrdp_clip_type = XRDP_CB_FILE;
|
2012-11-05 13:04:04 +04:00
|
|
|
XConvertSelection(g_display, g_clipboard_atom, g_clip_s2c.type,
|
2012-10-15 05:08:06 +04:00
|
|
|
g_clip_property_atom, g_wnd, CurrentTime);
|
|
|
|
}
|
2012-10-14 09:48:29 +04:00
|
|
|
break;
|
2023-08-04 19:08:42 +03:00
|
|
|
case CF_DIB:
|
2012-10-21 07:23:01 +04:00
|
|
|
if ((g_clip_s2c.xrdp_clip_type == XRDP_CB_BITMAP) && g_clip_s2c.converted)
|
2012-10-15 05:08:06 +04:00
|
|
|
{
|
2023-08-04 19:08:42 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "clipboard_process_data_request: CF_DIB");
|
2012-10-21 07:23:01 +04:00
|
|
|
clipboard_send_data_response(XRDP_CB_BITMAP, g_clip_s2c.data,
|
|
|
|
g_clip_s2c.total_bytes);
|
2012-10-15 05:08:06 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-08-04 19:08:42 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "clipboard_process_data_request: CF_DIB, "
|
2020-11-30 03:36:20 +03:00
|
|
|
"calling XConvertSelection to g_image_bmp_atom");
|
2012-10-21 07:23:01 +04:00
|
|
|
g_clip_s2c.xrdp_clip_type = XRDP_CB_BITMAP;
|
2012-10-15 05:08:06 +04:00
|
|
|
XConvertSelection(g_display, g_clipboard_atom, g_image_bmp_atom,
|
|
|
|
g_clip_property_atom, g_wnd, CurrentTime);
|
|
|
|
}
|
2012-10-14 09:48:29 +04:00
|
|
|
break;
|
2023-08-04 19:08:42 +03:00
|
|
|
case CF_UNICODETEXT:
|
2012-10-21 07:23:01 +04:00
|
|
|
if ((g_clip_s2c.xrdp_clip_type == XRDP_CB_TEXT) && g_clip_s2c.converted)
|
2012-10-15 05:08:06 +04:00
|
|
|
{
|
2023-08-04 19:08:42 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "clipboard_process_data_request: CF_UNICODETEXT");
|
2012-10-21 07:23:01 +04:00
|
|
|
clipboard_send_data_response(XRDP_CB_TEXT, g_clip_s2c.data,
|
|
|
|
g_clip_s2c.total_bytes);
|
2012-10-15 05:08:06 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-08-04 19:08:42 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "clipboard_process_data_request: CF_UNICODETEXT, "
|
2020-11-30 03:36:20 +03:00
|
|
|
"calling XConvertSelection to g_utf8_atom");
|
2012-10-21 07:23:01 +04:00
|
|
|
g_clip_s2c.xrdp_clip_type = XRDP_CB_TEXT;
|
2012-10-15 05:08:06 +04:00
|
|
|
XConvertSelection(g_display, g_clipboard_atom, g_utf8_atom,
|
|
|
|
g_clip_property_atom, g_wnd, CurrentTime);
|
|
|
|
}
|
2012-10-14 09:48:29 +04:00
|
|
|
break;
|
|
|
|
default:
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "clipboard_process_data_request: unknown type %d",
|
2020-11-30 03:36:20 +03:00
|
|
|
requestedFormatId);
|
2012-10-14 09:48:29 +04:00
|
|
|
clipboard_send_data_response_failed();
|
|
|
|
break;
|
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
return 0;
|
2009-08-15 06:47:51 +04:00
|
|
|
}
|
|
|
|
|
2023-08-04 18:43:42 +03:00
|
|
|
/**************************************************************************//**
|
|
|
|
* Process a CB_FORMAT_DATA_RESPONSE for an X client requesting an image
|
|
|
|
*
|
|
|
|
* @param s Stream containing CLIPRDR_FILELIST ([MS-RDPECLIP])
|
|
|
|
* @param clip_msg_status msgFlags from Clipboard PDU Header
|
|
|
|
* @param clip_msg_len dataLen from Clipboard PDU Header
|
|
|
|
*
|
|
|
|
* @return Status
|
|
|
|
*/
|
2017-03-12 19:35:00 +03:00
|
|
|
static int
|
2012-09-20 07:51:34 +04:00
|
|
|
clipboard_process_data_response_for_image(struct stream *s,
|
2019-02-26 09:40:10 +03:00
|
|
|
int clip_msg_status,
|
|
|
|
int clip_msg_len)
|
2012-08-12 21:51:45 +04:00
|
|
|
{
|
2012-10-21 07:23:01 +04:00
|
|
|
XSelectionRequestEvent *lxev;
|
2012-09-20 07:51:34 +04:00
|
|
|
int len;
|
2024-06-18 02:57:58 +03:00
|
|
|
struct stream *bmp_hs;
|
2012-09-20 07:51:34 +04:00
|
|
|
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "clipboard_process_data_response_for_image: "
|
2020-11-30 03:36:20 +03:00
|
|
|
"CLIPRDR_DATA_RESPONSE_FOR_IMAGE");
|
2012-10-21 07:23:01 +04:00
|
|
|
lxev = &g_saved_selection_req_event;
|
2012-09-20 07:51:34 +04:00
|
|
|
len = (int)(s->end - s->p);
|
|
|
|
if (len < 1)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2012-10-21 07:23:01 +04:00
|
|
|
if (g_clip_c2s.type != g_image_bmp_atom)
|
2012-09-20 07:51:34 +04:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2024-06-17 14:18:17 +03:00
|
|
|
|
2012-10-21 07:23:01 +04:00
|
|
|
g_free(g_clip_c2s.data);
|
2024-06-17 14:18:17 +03:00
|
|
|
g_clip_c2s.data = (char *) g_malloc(len + BMPFILEHEADER_LEN, 0);
|
2012-10-21 07:23:01 +04:00
|
|
|
if (g_clip_c2s.data == 0)
|
2012-09-20 07:51:34 +04:00
|
|
|
{
|
2012-10-21 07:23:01 +04:00
|
|
|
g_clip_c2s.total_bytes = 0;
|
|
|
|
return 0;
|
2012-09-20 07:51:34 +04:00
|
|
|
}
|
2024-06-17 14:18:17 +03:00
|
|
|
g_clip_c2s.total_bytes = len + BMPFILEHEADER_LEN;
|
2012-11-14 21:44:43 +04:00
|
|
|
g_clip_c2s.read_bytes_done = g_clip_c2s.total_bytes;
|
2024-06-17 14:18:17 +03:00
|
|
|
|
2024-06-18 02:57:58 +03:00
|
|
|
/*
|
|
|
|
* Assemble bitmap file header
|
|
|
|
* https://en.wikipedia.org/wiki/BMP_file_format#Bitmap_file_header
|
|
|
|
*/
|
|
|
|
make_stream(bmp_hs);
|
|
|
|
if (bmp_hs == 0)
|
2024-06-17 14:18:17 +03:00
|
|
|
{
|
2024-06-18 02:57:58 +03:00
|
|
|
g_free(g_clip_c2s.data);
|
|
|
|
g_clip_c2s.total_bytes = 0;
|
|
|
|
return 0;
|
2024-06-17 14:18:17 +03:00
|
|
|
}
|
2024-06-18 02:57:58 +03:00
|
|
|
init_stream(bmp_hs, BMPFILEHEADER_LEN);
|
|
|
|
out_uint8(bmp_hs, 'B');
|
|
|
|
out_uint8(bmp_hs, 'M');
|
|
|
|
out_uint32_le(bmp_hs, g_clip_c2s.total_bytes);
|
|
|
|
out_uint16_le(bmp_hs, 0);
|
|
|
|
out_uint16_le(bmp_hs, 0);
|
|
|
|
out_uint32_le(bmp_hs, BMPFILEHEADER_LEN + BMPINFOHEADER_LEN);
|
|
|
|
|
|
|
|
/* Copy header and data to output stream */
|
|
|
|
g_memcpy(g_clip_c2s.data, bmp_hs->data, BMPFILEHEADER_LEN);
|
2024-06-17 14:18:17 +03:00
|
|
|
in_uint8a(s, g_clip_c2s.data + BMPFILEHEADER_LEN, len);
|
2024-06-18 02:57:58 +03:00
|
|
|
|
|
|
|
free_stream(bmp_hs);
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "clipboard_process_data_response_for_image: calling "
|
2020-11-30 03:36:20 +03:00
|
|
|
"clipboard_provide_selection_c2s");
|
2012-10-21 07:23:01 +04:00
|
|
|
clipboard_provide_selection_c2s(lxev, lxev->target);
|
2024-06-17 14:18:17 +03:00
|
|
|
|
2012-08-20 06:45:31 +04:00
|
|
|
return 0;
|
2012-08-12 21:51:45 +04:00
|
|
|
}
|
|
|
|
|
2021-09-14 16:34:47 +03:00
|
|
|
/**************************************************************************//**
|
|
|
|
* Process a CB_FORMAT_DATA_RESPONSE for an X client requesting a file list
|
|
|
|
*
|
|
|
|
* @param s Stream containing CLIPRDR_FILELIST ([MS-RDPECLIP])
|
|
|
|
* @param clip_msg_status msgFlags from Clipboard PDU Header
|
|
|
|
* @param clip_msg_len dataLen from Clipboard PDU Header
|
|
|
|
*
|
|
|
|
* @return Status
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
clipboard_process_data_response_for_file(struct stream *s,
|
|
|
|
int clip_msg_status,
|
|
|
|
int clip_msg_len)
|
|
|
|
{
|
|
|
|
XSelectionRequestEvent *lxev;
|
|
|
|
int rv = 0;
|
|
|
|
|
|
|
|
LOG_DEVEL(LOG_LEVEL_TRACE, "clipboard_process_data_response_for_file: ");
|
|
|
|
lxev = &g_saved_selection_req_event;
|
|
|
|
|
|
|
|
const int flist_size = 1024 * 1024;
|
|
|
|
g_free(g_clip_c2s.data);
|
|
|
|
g_clip_c2s.data = (char *)g_malloc(flist_size, 0);
|
|
|
|
if (g_clip_c2s.data == NULL)
|
|
|
|
{
|
|
|
|
LOG(LOG_LEVEL_ERROR, "clipboard_process_data_response_for_file: "
|
|
|
|
"Can't allocate memory");
|
|
|
|
rv = 1;
|
|
|
|
}
|
|
|
|
/* text/uri-list */
|
|
|
|
else if (g_clip_c2s.type == g_file_atom1)
|
|
|
|
{
|
2021-09-14 16:43:33 +03:00
|
|
|
rv = clipboard_c2s_in_files(s, g_clip_c2s.data, flist_size,
|
|
|
|
"file://");
|
2021-09-14 16:34:47 +03:00
|
|
|
}
|
|
|
|
/* x-special/gnome-copied-files */
|
|
|
|
else if (g_clip_c2s.type == g_file_atom2)
|
|
|
|
{
|
|
|
|
g_strcpy(g_clip_c2s.data, "copy\n");
|
2021-09-14 16:43:33 +03:00
|
|
|
rv = clipboard_c2s_in_files(s, g_clip_c2s.data + 5, flist_size - 5,
|
|
|
|
"file://");
|
|
|
|
}
|
|
|
|
else if ((g_clip_c2s.type == XA_STRING) ||
|
|
|
|
(g_clip_c2s.type == g_utf8_atom))
|
|
|
|
{
|
2021-09-14 17:00:01 +03:00
|
|
|
if (g_cfg->use_nautilus3_flist_format)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* This file list format is only used by GNOME 3
|
|
|
|
* versions >= 3.29.92. It is not used by GNOME 4. Remove
|
|
|
|
* this workaround when GNOME 3 is no longer supported by
|
|
|
|
* long-term distros */
|
|
|
|
#define LIST_PREFIX "x-special/nautilus-clipboard\ncopy\n"
|
|
|
|
#define LIST_PREFIX_LEN (sizeof(LIST_PREFIX) - 1)
|
|
|
|
g_strcpy(g_clip_c2s.data, LIST_PREFIX);
|
|
|
|
rv = clipboard_c2s_in_files(s,
|
|
|
|
g_clip_c2s.data + LIST_PREFIX_LEN,
|
|
|
|
flist_size - LIST_PREFIX_LEN - 1,
|
|
|
|
"file://");
|
|
|
|
g_strcat(g_clip_c2s.data, "\n");
|
|
|
|
#undef LIST_PREFIX_LEN
|
|
|
|
#undef LIST_PREFIX
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rv = clipboard_c2s_in_files(s, g_clip_c2s.data, flist_size, "");
|
|
|
|
}
|
2021-09-14 16:34:47 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LOG_DEVEL(LOG_LEVEL_ERROR,
|
|
|
|
"clipboard_process_data_response_for_file: "
|
|
|
|
"Unrecognised target");
|
|
|
|
rv = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rv != 0 && g_clip_c2s.data != NULL)
|
|
|
|
{
|
|
|
|
g_clip_c2s.data[0] = '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
g_clip_c2s.total_bytes =
|
|
|
|
(g_clip_c2s.data == NULL) ? 0 : g_strlen(g_clip_c2s.data);
|
|
|
|
g_clip_c2s.read_bytes_done = g_clip_c2s.total_bytes;
|
|
|
|
clipboard_provide_selection_c2s(lxev, lxev->target);
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2023-08-04 18:43:42 +03:00
|
|
|
/**************************************************************************//**
|
|
|
|
* Process a CB_FORMAT_DATA_RESPONSE for an X client requesting text
|
|
|
|
*
|
|
|
|
* @param s Stream containing CLIPRDR_FILELIST ([MS-RDPECLIP])
|
|
|
|
* @param clip_msg_status msgFlags from Clipboard PDU Header
|
|
|
|
* @param clip_msg_len dataLen from Clipboard PDU Header
|
|
|
|
*
|
|
|
|
* @return Status
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
clipboard_process_data_response_for_text(struct stream *s,
|
|
|
|
int clip_msg_status,
|
|
|
|
int clip_msg_len)
|
|
|
|
{
|
|
|
|
XSelectionRequestEvent *lxev = &g_saved_selection_req_event;
|
2023-10-16 15:43:29 +03:00
|
|
|
unsigned int byte_count;
|
2023-08-04 18:43:42 +03:00
|
|
|
|
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "clipboard_process_data_response_for_text: ");
|
2023-10-16 15:43:29 +03:00
|
|
|
|
|
|
|
/* Get the buffer size we need */
|
|
|
|
byte_count = in_utf16_le_terminated_as_utf8_length(s);
|
|
|
|
|
|
|
|
g_free(g_clip_c2s.data);
|
|
|
|
g_clip_c2s.total_bytes = 0;
|
|
|
|
if ((g_clip_c2s.data = (char *)g_malloc(byte_count, 0)) == NULL)
|
2023-08-04 18:43:42 +03:00
|
|
|
{
|
2023-10-16 15:43:29 +03:00
|
|
|
LOG(LOG_LEVEL_ERROR, "Can't allocate %u bytes for text clip response",
|
2023-08-04 18:43:42 +03:00
|
|
|
byte_count);
|
|
|
|
|
|
|
|
clipboard_refuse_selection(lxev);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-10-16 15:43:29 +03:00
|
|
|
/* Re-parse the data into the allocated buffer */
|
|
|
|
in_utf16_le_terminated_as_utf8(s, g_clip_c2s.data, byte_count);
|
|
|
|
--byte_count; /* Ignore the terminator at the end */
|
|
|
|
|
|
|
|
g_clip_c2s.total_bytes = byte_count;
|
|
|
|
g_clip_c2s.read_bytes_done = byte_count;
|
|
|
|
clipboard_provide_selection_c2s(lxev, lxev->target);
|
2023-08-04 18:43:42 +03:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-08-12 21:51:45 +04:00
|
|
|
/*****************************************************************************/
|
2012-10-21 07:23:01 +04:00
|
|
|
/* client to server */
|
2012-08-12 21:51:45 +04:00
|
|
|
/* sent as a reply to CB_FORMAT_DATA_REQUEST; used to indicate whether
|
|
|
|
processing of the CB_FORMAT_DATA_REQUEST was successful; if processing was
|
|
|
|
successful, CB_FORMAT_DATA_RESPONSE includes contents of requested
|
|
|
|
clipboard data. */
|
2009-08-15 06:47:51 +04:00
|
|
|
/*****************************************************************************/
|
2017-03-12 19:35:00 +03:00
|
|
|
static int
|
2012-09-20 07:51:34 +04:00
|
|
|
clipboard_process_data_response(struct stream *s, int clip_msg_status,
|
2009-08-23 04:48:20 +04:00
|
|
|
int clip_msg_len)
|
2009-08-15 06:47:51 +04:00
|
|
|
{
|
2023-08-04 18:43:42 +03:00
|
|
|
int rv = 0;
|
|
|
|
|
|
|
|
XSelectionRequestEvent *lxev = &g_saved_selection_req_event;
|
2012-09-20 07:51:34 +04:00
|
|
|
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "clipboard_process_data_response:");
|
2012-11-12 07:33:53 +04:00
|
|
|
g_clip_c2s.in_request = 0;
|
2023-08-04 18:43:42 +03:00
|
|
|
|
|
|
|
if ((clip_msg_status & CB_RESPONSE_FAIL) != 0)
|
2009-08-30 01:20:27 +04:00
|
|
|
{
|
2023-08-04 18:43:42 +03:00
|
|
|
/* Requested data was not returned from the client. Most likely
|
|
|
|
* the client has lost the selection between announcing it and
|
|
|
|
* responding to our request */
|
|
|
|
clipboard_refuse_selection(lxev);
|
2009-08-30 01:20:27 +04:00
|
|
|
}
|
2023-08-04 18:43:42 +03:00
|
|
|
else if ((clip_msg_status & CB_RESPONSE_OK) == 0)
|
2012-09-20 07:51:34 +04:00
|
|
|
{
|
2023-08-04 18:43:42 +03:00
|
|
|
/* One of CB_RESPONSE_FAIL or CB_RESPONSE_OK MUST be set in
|
|
|
|
* a CLIPRDR_FORMAT_DATA_RESPONSE msg */
|
|
|
|
LOG(LOG_LEVEL_ERROR, "CLIPRDR_FORMAT_DATA_RESPONSE is badly formed");
|
|
|
|
clipboard_refuse_selection(lxev);
|
2012-09-20 07:51:34 +04:00
|
|
|
}
|
2023-08-04 18:43:42 +03:00
|
|
|
else if (g_clip_c2s.xrdp_clip_type == XRDP_CB_BITMAP)
|
2009-08-30 01:20:27 +04:00
|
|
|
{
|
2023-08-04 18:43:42 +03:00
|
|
|
clipboard_process_data_response_for_image(s, clip_msg_status,
|
|
|
|
clip_msg_len);
|
2009-08-30 01:20:27 +04:00
|
|
|
}
|
2023-08-04 18:43:42 +03:00
|
|
|
else if (g_clip_c2s.xrdp_clip_type == XRDP_CB_FILE)
|
2012-09-20 07:51:34 +04:00
|
|
|
{
|
2023-08-04 18:43:42 +03:00
|
|
|
clipboard_process_data_response_for_file(s, clip_msg_status,
|
|
|
|
clip_msg_len);
|
2012-09-20 07:51:34 +04:00
|
|
|
}
|
2023-08-04 18:43:42 +03:00
|
|
|
else
|
2012-09-20 07:51:34 +04:00
|
|
|
{
|
2023-08-04 18:43:42 +03:00
|
|
|
clipboard_process_data_response_for_text(s, clip_msg_status,
|
|
|
|
clip_msg_len);
|
2012-09-20 07:51:34 +04:00
|
|
|
}
|
2023-08-04 18:43:42 +03:00
|
|
|
return rv;
|
2009-04-19 21:16:46 +04:00
|
|
|
}
|
|
|
|
|
2023-08-04 18:43:42 +03:00
|
|
|
|
2012-10-05 09:55:06 +04:00
|
|
|
/*****************************************************************************/
|
2017-03-12 19:35:00 +03:00
|
|
|
static int
|
2012-10-05 09:55:06 +04:00
|
|
|
clipboard_process_clip_caps(struct stream *s, int clip_msg_status,
|
|
|
|
int clip_msg_len)
|
|
|
|
{
|
|
|
|
int cCapabilitiesSets;
|
|
|
|
int capabilitySetType;
|
|
|
|
int lengthCapability;
|
|
|
|
int index;
|
|
|
|
int version;
|
|
|
|
int flags;
|
|
|
|
char *holdp;
|
|
|
|
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "clipboard_process_clip_caps:");
|
2020-11-30 03:36:20 +03:00
|
|
|
//LOG_DEVEL_HEXDUMP(LOG_LEVEL_TRACE, "", s->p, s->end - s->p);
|
2012-10-05 09:55:06 +04:00
|
|
|
in_uint16_le(s, cCapabilitiesSets);
|
|
|
|
in_uint8s(s, 2); /* pad */
|
|
|
|
for (index = 0; index < cCapabilitiesSets; index++)
|
|
|
|
{
|
|
|
|
holdp = s->p;
|
|
|
|
in_uint16_le(s, capabilitySetType);
|
|
|
|
in_uint16_le(s, lengthCapability);
|
|
|
|
switch (capabilitySetType)
|
|
|
|
{
|
|
|
|
case CB_CAPSTYPE_GENERAL:
|
|
|
|
in_uint32_le(s, version); /* version */
|
|
|
|
in_uint32_le(s, flags); /* generalFlags */
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "clipboard_process_clip_caps: "
|
2020-11-30 03:36:20 +03:00
|
|
|
"g_cliprdr_version %d version %d "
|
|
|
|
"g_cliprdr_flags 0x%x flags 0x%x",
|
|
|
|
g_cliprdr_version, version,
|
|
|
|
g_cliprdr_flags, flags);
|
2012-10-05 09:55:06 +04:00
|
|
|
if (version < g_cliprdr_version)
|
|
|
|
{
|
|
|
|
g_cliprdr_version = version;
|
|
|
|
}
|
|
|
|
g_cliprdr_flags &= flags;
|
|
|
|
break;
|
|
|
|
default:
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "clipboard_process_clip_caps: unknown "
|
2020-11-30 03:36:20 +03:00
|
|
|
"capabilitySetType %d", capabilitySetType);
|
2012-10-05 09:55:06 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
s->p = holdp + lengthCapability;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-10-14 09:48:29 +04:00
|
|
|
/*****************************************************************************/
|
2017-03-12 19:35:00 +03:00
|
|
|
int
|
2012-09-20 07:51:34 +04:00
|
|
|
clipboard_data_in(struct stream *s, int chan_id, int chan_flags, int length,
|
2009-04-19 21:16:46 +04:00
|
|
|
int total_length)
|
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
int clip_msg_id;
|
|
|
|
int clip_msg_len;
|
|
|
|
int clip_msg_status;
|
|
|
|
int rv;
|
|
|
|
struct stream *ls;
|
2012-11-12 07:33:53 +04:00
|
|
|
|
2013-06-24 01:17:59 +04:00
|
|
|
if (!g_clip_up)
|
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_ERROR, "aborting clipboard_data_in - clipboard has not "
|
2020-11-30 03:36:20 +03:00
|
|
|
"been initialized");
|
2016-01-14 19:32:09 +03:00
|
|
|
/* we return 0 here to indicate no protocol problem occurred */
|
2013-06-23 00:57:16 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "clipboard_data_in: chan_id %d "
|
2020-11-30 03:36:20 +03:00
|
|
|
"chan_flags 0x%x length %d total_length %d "
|
|
|
|
"in_request %d g_ins->size %d",
|
|
|
|
chan_id, chan_flags, length, total_length,
|
|
|
|
g_clip_c2s.in_request, g_ins->size);
|
2012-09-20 07:51:34 +04:00
|
|
|
|
|
|
|
if ((chan_flags & 3) == 3)
|
2009-08-23 04:48:20 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
ls = s;
|
2009-08-23 04:48:20 +04:00
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
else
|
2009-08-23 04:48:20 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
if (chan_flags & 1)
|
|
|
|
{
|
|
|
|
init_stream(g_ins, total_length);
|
|
|
|
}
|
|
|
|
|
|
|
|
in_uint8a(s, g_ins->end, length);
|
|
|
|
g_ins->end += length;
|
|
|
|
|
|
|
|
if ((chan_flags & 2) == 0)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
ls = g_ins;
|
2009-08-23 04:48:20 +04:00
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
|
|
|
|
in_uint16_le(ls, clip_msg_id);
|
|
|
|
in_uint16_le(ls, clip_msg_status);
|
|
|
|
in_uint32_le(ls, clip_msg_len);
|
2012-11-14 21:44:43 +04:00
|
|
|
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "clipboard_data_in: clip_msg_id %d "
|
2020-11-30 03:36:20 +03:00
|
|
|
"clip_msg_status %d clip_msg_len %d",
|
|
|
|
clip_msg_id, clip_msg_status, clip_msg_len);
|
2012-09-20 07:51:34 +04:00
|
|
|
rv = 0;
|
|
|
|
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "clipboard_data_in: %d", clip_msg_id);
|
2012-09-20 07:51:34 +04:00
|
|
|
switch (clip_msg_id)
|
|
|
|
{
|
2019-02-26 09:40:10 +03:00
|
|
|
/* sent by client or server when its local system clipboard is */
|
|
|
|
/* updated with new clipboard data; contains Clipboard Format ID */
|
|
|
|
/* and name pairs of new Clipboard Formats on the clipboard. */
|
2012-10-14 09:48:29 +04:00
|
|
|
case CB_FORMAT_LIST: /* 2 CLIPRDR_FORMAT_ANNOUNCE */
|
2012-09-20 07:51:34 +04:00
|
|
|
rv = clipboard_process_format_announce(ls, clip_msg_status,
|
|
|
|
clip_msg_len);
|
|
|
|
break;
|
2019-02-26 09:40:10 +03:00
|
|
|
/* response to CB_FORMAT_LIST; used to indicate whether */
|
|
|
|
/* processing of the Format List PDU was successful */
|
2012-10-14 09:48:29 +04:00
|
|
|
case CB_FORMAT_LIST_RESPONSE: /* 3 CLIPRDR_FORMAT_ACK */
|
2016-02-14 07:41:07 +03:00
|
|
|
rv = clipboard_process_format_ack(ls, clip_msg_status,
|
2012-09-20 07:51:34 +04:00
|
|
|
clip_msg_len);
|
|
|
|
break;
|
2019-02-26 09:40:10 +03:00
|
|
|
/* sent by recipient of CB_FORMAT_LIST; used to request data for one */
|
|
|
|
/* of the formats that was listed in CB_FORMAT_LIST */
|
2012-10-14 09:48:29 +04:00
|
|
|
case CB_FORMAT_DATA_REQUEST: /* 4 CLIPRDR_DATA_REQUEST */
|
2012-09-20 07:51:34 +04:00
|
|
|
rv = clipboard_process_data_request(ls, clip_msg_status,
|
|
|
|
clip_msg_len);
|
|
|
|
break;
|
2019-02-26 09:40:10 +03:00
|
|
|
/* sent as a reply to CB_FORMAT_DATA_REQUEST; used to indicate */
|
|
|
|
/* whether processing of the CB_FORMAT_DATA_REQUEST was */
|
|
|
|
/* successful; if processing was successful, */
|
|
|
|
/* CB_FORMAT_DATA_RESPONSE includes contents of requested */
|
|
|
|
/* clipboard data. */
|
2012-10-14 09:48:29 +04:00
|
|
|
case CB_FORMAT_DATA_RESPONSE: /* 5 CLIPRDR_DATA_RESPONSE */
|
2012-09-20 07:51:34 +04:00
|
|
|
rv = clipboard_process_data_response(ls, clip_msg_status,
|
|
|
|
clip_msg_len);
|
|
|
|
break;
|
2012-10-14 09:48:29 +04:00
|
|
|
case CB_CLIP_CAPS: /* 7 */
|
2012-10-05 09:55:06 +04:00
|
|
|
rv = clipboard_process_clip_caps(ls, clip_msg_status,
|
|
|
|
clip_msg_len);
|
|
|
|
break;
|
2012-10-14 09:48:29 +04:00
|
|
|
case CB_FILECONTENTS_REQUEST: /* 8 */
|
|
|
|
rv = clipboard_process_file_request(ls, clip_msg_status,
|
|
|
|
clip_msg_len);
|
|
|
|
break;
|
2012-11-05 01:52:33 +04:00
|
|
|
case CB_FILECONTENTS_RESPONSE: /* 9 */
|
|
|
|
rv = clipboard_process_file_response(ls, clip_msg_status,
|
|
|
|
clip_msg_len);
|
|
|
|
break;
|
2012-09-20 07:51:34 +04:00
|
|
|
default:
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_ERROR, "clipboard_data_in: unknown clip_msg_id %d", clip_msg_id);
|
2012-09-20 07:51:34 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
XFlush(g_display);
|
|
|
|
return rv;
|
2009-08-15 06:47:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2009-08-27 06:15:49 +04:00
|
|
|
/* this happens when a new app copies something to the clipboard
|
|
|
|
'CLIPBOARD' Atom
|
2012-08-20 06:45:31 +04:00
|
|
|
typedef struct
|
|
|
|
{
|
2009-08-27 06:15:49 +04:00
|
|
|
int type;
|
|
|
|
unsigned long serial;
|
|
|
|
Bool send_event;
|
|
|
|
Display *display;
|
|
|
|
Window window;
|
|
|
|
int subtype;
|
|
|
|
Window owner;
|
|
|
|
Atom selection;
|
|
|
|
Time timestamp;
|
|
|
|
Time selection_timestamp;
|
2012-08-20 06:45:31 +04:00
|
|
|
} XFixesSelectionNotifyEvent; */
|
2017-03-12 19:35:00 +03:00
|
|
|
static int
|
2012-09-20 07:51:34 +04:00
|
|
|
clipboard_event_selection_owner_notify(XEvent *xevent)
|
2009-08-15 06:47:51 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
XFixesSelectionNotifyEvent *lxevent;
|
|
|
|
|
|
|
|
lxevent = (XFixesSelectionNotifyEvent *)xevent;
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "clipboard_event_selection_owner_notify: 0x%lx", lxevent->owner);
|
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "clipboard_event_selection_owner_notify: "
|
2020-11-30 03:36:20 +03:00
|
|
|
"window %ld subtype %d owner %ld g_wnd %ld",
|
|
|
|
lxevent->window, lxevent->subtype, lxevent->owner, g_wnd);
|
2012-09-20 07:51:34 +04:00
|
|
|
|
|
|
|
if (lxevent->owner == g_wnd)
|
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "clipboard_event_selection_owner_notify: matches g_wnd");
|
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "clipboard_event_selection_owner_notify: skipping, "
|
2020-11-30 03:36:20 +03:00
|
|
|
"owner == g_wnd");
|
2012-09-20 07:51:34 +04:00
|
|
|
g_got_selection = 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_got_selection = 0;
|
2012-10-22 09:15:31 +04:00
|
|
|
if (lxevent->owner != 0) /* nil owner comes when selection */
|
2019-02-26 09:40:10 +03:00
|
|
|
{
|
|
|
|
/* window is closed */
|
2012-10-22 09:15:31 +04:00
|
|
|
XConvertSelection(g_display, g_clipboard_atom, g_targets_atom,
|
|
|
|
g_clip_property_atom, g_wnd, lxevent->timestamp);
|
|
|
|
}
|
2009-08-30 01:20:27 +04:00
|
|
|
return 0;
|
2009-04-19 21:16:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2009-08-15 06:47:51 +04:00
|
|
|
/* returns error
|
2009-08-27 06:15:49 +04:00
|
|
|
get a window property from wnd */
|
2017-03-12 19:35:00 +03:00
|
|
|
static int
|
2012-09-20 07:51:34 +04:00
|
|
|
clipboard_get_window_property(Window wnd, Atom prop, Atom *type, int *fmt,
|
|
|
|
int *n_items, char **xdata, int *xdata_size)
|
2009-08-15 06:47:51 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
int lfmt;
|
|
|
|
int lxdata_size;
|
|
|
|
unsigned long ln_items;
|
|
|
|
unsigned long llen_after;
|
|
|
|
tui8 *lxdata;
|
|
|
|
Atom ltype;
|
|
|
|
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "clipboard_get_window_property:");
|
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, " prop %ld name %s", prop, get_atom_text(prop));
|
2012-09-20 07:51:34 +04:00
|
|
|
lxdata = 0;
|
|
|
|
ltype = 0;
|
2012-10-19 05:43:04 +04:00
|
|
|
XGetWindowProperty(g_display, wnd, prop, 0, 0, 0,
|
2012-09-20 07:51:34 +04:00
|
|
|
AnyPropertyType, <ype, &lfmt, &ln_items,
|
|
|
|
&llen_after, &lxdata);
|
2012-08-20 06:45:31 +04:00
|
|
|
if (lxdata != 0)
|
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
XFree(lxdata);
|
2012-08-20 06:45:31 +04:00
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
if (ltype == 0)
|
|
|
|
{
|
|
|
|
/* XGetWindowProperty failed */
|
2012-10-19 05:43:04 +04:00
|
|
|
return 4;
|
2012-09-20 07:51:34 +04:00
|
|
|
}
|
|
|
|
if (llen_after < 1)
|
2012-08-20 06:45:31 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
/* no data, ok */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
lxdata = 0;
|
|
|
|
ltype = 0;
|
2012-10-19 05:43:04 +04:00
|
|
|
XGetWindowProperty(g_display, wnd, prop, 0, (llen_after + 3) / 4, 0,
|
2012-09-20 07:51:34 +04:00
|
|
|
AnyPropertyType, <ype, &lfmt, &ln_items,
|
|
|
|
&llen_after, &lxdata);
|
|
|
|
if (ltype == 0)
|
|
|
|
{
|
|
|
|
/* XGetWindowProperty failed */
|
|
|
|
if (lxdata != 0)
|
|
|
|
{
|
|
|
|
XFree(lxdata);
|
|
|
|
}
|
|
|
|
return 1;
|
2012-08-20 06:45:31 +04:00
|
|
|
}
|
2012-10-17 12:13:37 +04:00
|
|
|
lxdata_size = FORMAT_TO_BYTES(lfmt);
|
|
|
|
lxdata_size *= ln_items;
|
2012-09-20 07:51:34 +04:00
|
|
|
if (lxdata_size < 1)
|
|
|
|
{
|
|
|
|
/* should not happen */
|
|
|
|
if (lxdata != 0)
|
|
|
|
{
|
|
|
|
XFree(lxdata);
|
|
|
|
}
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
if (llen_after > 0)
|
|
|
|
{
|
|
|
|
/* should not happen */
|
|
|
|
if (lxdata != 0)
|
|
|
|
{
|
|
|
|
XFree(lxdata);
|
|
|
|
}
|
|
|
|
return 3;
|
|
|
|
}
|
|
|
|
if (xdata != 0)
|
|
|
|
{
|
2012-10-05 09:55:06 +04:00
|
|
|
*xdata = (char *) g_malloc(lxdata_size, 0);
|
2012-09-20 07:51:34 +04:00
|
|
|
g_memcpy(*xdata, lxdata, lxdata_size);
|
|
|
|
}
|
2012-08-20 06:45:31 +04:00
|
|
|
if (lxdata != 0)
|
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
XFree(lxdata);
|
|
|
|
}
|
|
|
|
if (xdata_size != 0)
|
|
|
|
{
|
|
|
|
*xdata_size = lxdata_size;
|
|
|
|
}
|
|
|
|
if (fmt != 0)
|
|
|
|
{
|
|
|
|
*fmt = (int)lfmt;
|
|
|
|
}
|
|
|
|
if (n_items != 0)
|
|
|
|
{
|
|
|
|
*n_items = (int)ln_items;
|
2012-08-20 06:45:31 +04:00
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
if (type != 0)
|
|
|
|
{
|
|
|
|
*type = ltype;
|
|
|
|
}
|
|
|
|
return 0;
|
2009-08-15 06:47:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
/* returns error
|
|
|
|
process the SelectionNotify X event, uses XSelectionEvent
|
|
|
|
typedef struct {
|
|
|
|
int type; // SelectionNotify
|
|
|
|
unsigned long serial; // # of last request processed by server
|
|
|
|
Bool send_event; // true if this came from a SendEvent request
|
|
|
|
Display *display; // Display the event was read from
|
|
|
|
Window requestor;
|
|
|
|
Atom selection;
|
|
|
|
Atom target;
|
|
|
|
Atom property; // atom or None
|
|
|
|
Time time;
|
|
|
|
} XSelectionEvent; */
|
2017-03-12 19:35:00 +03:00
|
|
|
static int
|
2012-09-20 07:51:34 +04:00
|
|
|
clipboard_event_selection_notify(XEvent *xevent)
|
2009-08-15 06:47:51 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
XSelectionEvent *lxevent;
|
|
|
|
char *data;
|
|
|
|
int data_size;
|
|
|
|
int n_items;
|
|
|
|
int fmt;
|
|
|
|
int rv;
|
|
|
|
int index;
|
2012-10-14 09:48:29 +04:00
|
|
|
int got_string;
|
|
|
|
int got_utf8;
|
|
|
|
int got_bmp_image;
|
2012-09-20 07:51:34 +04:00
|
|
|
int send_format_announce;
|
2012-11-05 13:04:04 +04:00
|
|
|
Atom got_file_atom;
|
2012-10-15 09:13:22 +04:00
|
|
|
Atom atom;
|
2012-09-20 07:51:34 +04:00
|
|
|
Atom *atoms;
|
|
|
|
Atom type;
|
|
|
|
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "clipboard_event_selection_notify:");
|
2012-09-20 07:51:34 +04:00
|
|
|
data_size = 0;
|
|
|
|
n_items = 0;
|
|
|
|
fmt = 0;
|
2012-10-14 09:48:29 +04:00
|
|
|
got_string = 0;
|
|
|
|
got_utf8 = 0;
|
|
|
|
got_bmp_image = 0;
|
2012-11-05 13:04:04 +04:00
|
|
|
got_file_atom = 0;
|
2012-09-20 07:51:34 +04:00
|
|
|
send_format_announce = 0;
|
|
|
|
rv = 0;
|
|
|
|
data = 0;
|
|
|
|
type = 0;
|
|
|
|
lxevent = (XSelectionEvent *)xevent;
|
|
|
|
|
|
|
|
if (lxevent->property == None)
|
2012-08-12 21:51:45 +04:00
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_ERROR, "clipboard_event_selection_notify: clip could "
|
2020-11-30 03:36:20 +03:00
|
|
|
"not be converted");
|
2012-09-20 07:51:34 +04:00
|
|
|
rv = 1;
|
2012-08-12 21:51:45 +04:00
|
|
|
}
|
|
|
|
|
2012-09-20 07:51:34 +04:00
|
|
|
if (rv == 0)
|
2009-08-15 06:47:51 +04:00
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "clipboard_event_selection_notify: wnd 0x%lx prop %s",
|
2020-11-30 03:36:20 +03:00
|
|
|
lxevent->requestor,
|
|
|
|
get_atom_text(lxevent->property));
|
2012-09-20 07:51:34 +04:00
|
|
|
rv = clipboard_get_window_property(lxevent->requestor, lxevent->property,
|
|
|
|
&type, &fmt,
|
|
|
|
&n_items, &data, &data_size);
|
|
|
|
if (rv != 0)
|
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_ERROR, "clipboard_event_selection_notify: "
|
2020-11-30 03:36:20 +03:00
|
|
|
"clipboard_get_window_property failed error %d", rv);
|
2012-10-19 05:43:04 +04:00
|
|
|
return 0;
|
2012-09-20 07:51:34 +04:00
|
|
|
}
|
2020-11-30 03:36:20 +03:00
|
|
|
//LOG_DEVEL_HEXDUMP(LOG_LEVEL_TRACE, "", data, data_size);
|
2012-09-20 07:51:34 +04:00
|
|
|
XDeleteProperty(g_display, lxevent->requestor, lxevent->property);
|
2012-10-15 05:08:06 +04:00
|
|
|
if (type == g_incr_atom)
|
|
|
|
{
|
2016-01-14 19:32:09 +03:00
|
|
|
/* nothing more to do here, the data is coming in through
|
2012-10-15 05:08:06 +04:00
|
|
|
PropertyNotify */
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "clipboard_event_selection_notify: type is INCR "
|
2020-11-30 03:36:20 +03:00
|
|
|
"data_size %d property name %s type %s", data_size,
|
|
|
|
get_atom_text(lxevent->property),
|
|
|
|
get_atom_text(lxevent->type));
|
2012-10-18 20:58:23 +04:00
|
|
|
g_clip_s2c.incr_in_progress = 1;
|
2012-10-19 05:43:04 +04:00
|
|
|
g_clip_s2c.property = lxevent->property;
|
|
|
|
g_clip_s2c.type = lxevent->target;
|
|
|
|
g_clip_s2c.total_bytes = 0;
|
|
|
|
g_free(g_clip_s2c.data);
|
|
|
|
g_clip_s2c.data = 0;
|
2020-11-30 03:36:20 +03:00
|
|
|
//LOG_DEVEL_HEXDUMP(LOG_LEVEL_TRACE, "", data, sizeof(long));
|
2012-10-17 12:13:37 +04:00
|
|
|
g_free(data);
|
2012-10-15 05:08:06 +04:00
|
|
|
return 0;
|
|
|
|
}
|
2009-08-15 06:47:51 +04:00
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
|
|
|
|
if (rv == 0)
|
2009-08-15 06:47:51 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
if (lxevent->selection == g_clipboard_atom)
|
2009-08-30 01:20:27 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
if (lxevent->target == g_targets_atom)
|
|
|
|
{
|
2012-10-15 09:13:22 +04:00
|
|
|
/* 32 implies long */
|
2012-09-20 07:51:34 +04:00
|
|
|
if ((type == XA_ATOM) && (fmt == 32))
|
|
|
|
{
|
|
|
|
atoms = (Atom *)data;
|
|
|
|
for (index = 0; index < n_items; index++)
|
|
|
|
{
|
|
|
|
atom = atoms[index];
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG,
|
2020-11-30 03:36:20 +03:00
|
|
|
"clipboard_event_selection_notify: 0x%lx %s 0x%lx",
|
|
|
|
atom, get_atom_text(atom), XA_STRING);
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "clipboard_event_selection_notify: 0x%lx %s",
|
2020-11-30 03:36:20 +03:00
|
|
|
atom, get_atom_text(atom));
|
2012-09-20 07:51:34 +04:00
|
|
|
if (atom == g_utf8_atom)
|
|
|
|
{
|
2012-10-14 09:48:29 +04:00
|
|
|
got_utf8 = 1;
|
2012-09-20 07:51:34 +04:00
|
|
|
}
|
|
|
|
else if (atom == XA_STRING)
|
|
|
|
{
|
2012-10-14 09:48:29 +04:00
|
|
|
got_string = 1;
|
2012-09-20 07:51:34 +04:00
|
|
|
}
|
|
|
|
else if (atom == g_image_bmp_atom)
|
|
|
|
{
|
2012-10-14 09:48:29 +04:00
|
|
|
got_bmp_image = 1;
|
2012-09-20 07:51:34 +04:00
|
|
|
}
|
2012-10-05 09:55:06 +04:00
|
|
|
else if ((atom == g_file_atom1) || (atom == g_file_atom2))
|
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "clipboard_event_selection_notify: file");
|
2012-11-05 13:04:04 +04:00
|
|
|
got_file_atom = atom;
|
2012-10-05 09:55:06 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_ERROR, "clipboard_event_selection_notify: unknown atom 0x%lx", atom);
|
2012-10-05 09:55:06 +04:00
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_ERROR, "clipboard_event_selection_notify: error, "
|
2020-11-30 03:36:20 +03:00
|
|
|
"target is 'TARGETS' and type[%ld] or fmt[%d] not right, "
|
|
|
|
"should be type[%ld], fmt[%d]", type, fmt, XA_ATOM, 32);
|
2012-09-20 07:51:34 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (lxevent->target == g_utf8_atom)
|
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "clipboard_event_selection_notify: UTF8_STRING "
|
2020-11-30 03:36:20 +03:00
|
|
|
"data_size %d", data_size);
|
2012-10-18 20:58:23 +04:00
|
|
|
if ((g_clip_s2c.incr_in_progress == 0) && (data_size > 0))
|
2012-10-05 09:55:06 +04:00
|
|
|
{
|
2012-10-19 05:43:04 +04:00
|
|
|
g_free(g_clip_s2c.data);
|
|
|
|
g_clip_s2c.total_bytes = data_size;
|
|
|
|
g_clip_s2c.data = (char *) g_malloc(g_clip_s2c.total_bytes + 1, 0);
|
|
|
|
g_memcpy(g_clip_s2c.data, data, g_clip_s2c.total_bytes);
|
|
|
|
g_clip_s2c.data[g_clip_s2c.total_bytes] = 0;
|
|
|
|
if (g_clip_s2c.xrdp_clip_type == XRDP_CB_FILE)
|
2012-10-14 09:48:29 +04:00
|
|
|
{
|
2021-12-14 08:43:49 +03:00
|
|
|
if (g_cfg->restrict_outbound_clipboard & CLIP_RESTRICT_FILE)
|
|
|
|
{
|
|
|
|
LOG(LOG_LEVEL_DEBUG,
|
|
|
|
"outbound clipboard(file) UTF8_STRING(%s) is restricted because of config",
|
|
|
|
g_clip_s2c.data);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
clipboard_send_data_response_for_file(g_clip_s2c.data,
|
|
|
|
g_clip_s2c.total_bytes);
|
|
|
|
}
|
2012-10-14 09:48:29 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-12-14 08:43:49 +03:00
|
|
|
if (g_cfg->restrict_outbound_clipboard & CLIP_RESTRICT_TEXT)
|
|
|
|
{
|
|
|
|
LOG(LOG_LEVEL_DEBUG,
|
|
|
|
"outbound clipboard(text) UTF8_STRING(%s) is restricted because of config",
|
|
|
|
g_clip_s2c.data);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
clipboard_send_data_response_for_text(g_clip_s2c.data,
|
|
|
|
g_clip_s2c.total_bytes);
|
|
|
|
}
|
2012-10-14 09:48:29 +04:00
|
|
|
}
|
2021-12-14 08:43:49 +03:00
|
|
|
|
2012-10-05 09:55:06 +04:00
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
}
|
|
|
|
else if (lxevent->target == XA_STRING)
|
2009-09-02 06:52:30 +04:00
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "clipboard_event_selection_notify: XA_STRING "
|
2020-11-30 03:36:20 +03:00
|
|
|
"data_size %d", data_size);
|
2012-10-18 20:58:23 +04:00
|
|
|
if ((g_clip_s2c.incr_in_progress == 0) && (data_size > 0))
|
2012-10-14 09:48:29 +04:00
|
|
|
{
|
2012-10-19 05:43:04 +04:00
|
|
|
g_free(g_clip_s2c.data);
|
|
|
|
g_clip_s2c.total_bytes = data_size;
|
|
|
|
g_clip_s2c.data = (char *) g_malloc(g_clip_s2c.total_bytes + 1, 0);
|
|
|
|
g_memcpy(g_clip_s2c.data, data, g_clip_s2c.total_bytes);
|
|
|
|
g_clip_s2c.data[g_clip_s2c.total_bytes] = 0;
|
2021-12-14 08:43:49 +03:00
|
|
|
if (g_cfg->restrict_outbound_clipboard & CLIP_RESTRICT_TEXT)
|
|
|
|
{
|
|
|
|
LOG(LOG_LEVEL_DEBUG,
|
|
|
|
"outbound clipboard(text) XA_STRING(%s) is restricted because of config",
|
|
|
|
g_clip_s2c.data);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
clipboard_send_data_response_for_text(g_clip_s2c.data,
|
|
|
|
g_clip_s2c.total_bytes);
|
|
|
|
}
|
|
|
|
|
2012-10-14 09:48:29 +04:00
|
|
|
}
|
2009-09-02 06:52:30 +04:00
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
else if (lxevent->target == g_image_bmp_atom)
|
2009-08-30 01:20:27 +04:00
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "clipboard_event_selection_notify: image/bmp "
|
2020-11-30 03:36:20 +03:00
|
|
|
"data_size %d", data_size);
|
2012-10-18 20:58:23 +04:00
|
|
|
if ((g_clip_s2c.incr_in_progress == 0) && (data_size > 14))
|
2012-10-14 09:48:29 +04:00
|
|
|
{
|
2012-10-19 05:43:04 +04:00
|
|
|
g_free(g_clip_s2c.data);
|
2021-12-14 08:43:49 +03:00
|
|
|
|
|
|
|
if (g_cfg->restrict_outbound_clipboard & CLIP_RESTRICT_IMAGE)
|
|
|
|
{
|
|
|
|
LOG(LOG_LEVEL_DEBUG,
|
|
|
|
"outbound clipboard(image) image/bmp is restricted because of config");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_clip_s2c.total_bytes = data_size;
|
|
|
|
g_clip_s2c.data = (char *) g_malloc(data_size, 0);
|
|
|
|
g_memcpy(g_clip_s2c.data, data, data_size);
|
|
|
|
clipboard_send_data_response_for_image(g_clip_s2c.data + 14,
|
|
|
|
data_size - 14);
|
|
|
|
}
|
|
|
|
|
2012-10-14 09:48:29 +04:00
|
|
|
}
|
2009-08-30 01:20:27 +04:00
|
|
|
}
|
2012-11-05 13:04:04 +04:00
|
|
|
else if (lxevent->target == g_file_atom1)
|
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "clipboard_event_selection_notify: text/uri-list "
|
2020-11-30 03:36:20 +03:00
|
|
|
"data_size %d", data_size);
|
2012-11-05 13:04:04 +04:00
|
|
|
if ((g_clip_s2c.incr_in_progress == 0) && (data_size > 0))
|
|
|
|
{
|
|
|
|
g_free(g_clip_s2c.data);
|
|
|
|
g_clip_s2c.total_bytes = data_size;
|
|
|
|
g_clip_s2c.data = (char *) g_malloc(g_clip_s2c.total_bytes + 1, 0);
|
|
|
|
g_memcpy(g_clip_s2c.data, data, g_clip_s2c.total_bytes);
|
|
|
|
g_clip_s2c.data[g_clip_s2c.total_bytes] = 0;
|
2021-12-14 08:43:49 +03:00
|
|
|
if (g_cfg->restrict_outbound_clipboard & CLIP_RESTRICT_FILE)
|
|
|
|
{
|
|
|
|
LOG(LOG_LEVEL_DEBUG,
|
|
|
|
"outbound clipboard(file) text/uri-list(%s) is restricted because of config",
|
|
|
|
g_clip_s2c.data);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
clipboard_send_data_response_for_file(g_clip_s2c.data,
|
|
|
|
g_clip_s2c.total_bytes);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-11-05 13:04:04 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (lxevent->target == g_file_atom2)
|
|
|
|
{
|
2021-12-06 06:37:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "clipboard_event_selection_notify: x-special/gnome-copied-files "
|
2020-11-30 03:36:20 +03:00
|
|
|
"data_size %d", data_size);
|
2012-11-05 13:04:04 +04:00
|
|
|
if ((g_clip_s2c.incr_in_progress == 0) && (data_size > 0))
|
|
|
|
{
|
|
|
|
g_free(g_clip_s2c.data);
|
|
|
|
g_clip_s2c.total_bytes = data_size;
|
|
|
|
g_clip_s2c.data = (char *) g_malloc(g_clip_s2c.total_bytes + 1, 0);
|
|
|
|
g_memcpy(g_clip_s2c.data, data, g_clip_s2c.total_bytes);
|
|
|
|
g_clip_s2c.data[g_clip_s2c.total_bytes] = 0;
|
2021-12-14 08:43:49 +03:00
|
|
|
if (g_cfg->restrict_outbound_clipboard & CLIP_RESTRICT_FILE)
|
|
|
|
{
|
|
|
|
LOG(LOG_LEVEL_DEBUG,
|
|
|
|
"outbound clipboard(file) x-special/gnome-copied-files(%s) is restricted because of config",
|
|
|
|
g_clip_s2c.data);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
clipboard_send_data_response_for_file(g_clip_s2c.data,
|
|
|
|
g_clip_s2c.total_bytes);
|
|
|
|
}
|
|
|
|
|
2012-11-05 13:04:04 +04:00
|
|
|
}
|
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
else
|
2012-08-12 21:51:45 +04:00
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_ERROR, "clipboard_event_selection_notify: "
|
2020-11-30 03:36:20 +03:00
|
|
|
"unknown target");
|
2012-08-12 21:51:45 +04:00
|
|
|
}
|
2009-08-30 01:20:27 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_ERROR, "clipboard_event_selection_notify: "
|
2020-11-30 03:36:20 +03:00
|
|
|
"unknown selection");
|
2009-08-30 01:20:27 +04:00
|
|
|
}
|
2009-08-15 06:47:51 +04:00
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
|
2012-11-05 13:04:04 +04:00
|
|
|
if (got_file_atom != 0)
|
2012-10-05 09:55:06 +04:00
|
|
|
{
|
2012-11-05 13:04:04 +04:00
|
|
|
/* text/uri-list or x-special/gnome-copied-files */
|
2021-12-14 08:43:49 +03:00
|
|
|
|
|
|
|
if (g_cfg->restrict_outbound_clipboard & CLIP_RESTRICT_FILE)
|
|
|
|
{
|
|
|
|
LOG(LOG_LEVEL_DEBUG,
|
|
|
|
"outbound clipboard(file) is restricted because of config");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_clip_s2c.type = got_file_atom;
|
|
|
|
g_clip_s2c.xrdp_clip_type = XRDP_CB_FILE;
|
|
|
|
g_clip_s2c.converted = 0;
|
|
|
|
g_clip_s2c.clip_time = lxevent->time;
|
|
|
|
send_format_announce = 1;
|
|
|
|
}
|
|
|
|
|
2012-10-05 09:55:06 +04:00
|
|
|
}
|
2012-10-14 09:48:29 +04:00
|
|
|
else if (got_utf8)
|
2009-08-15 06:47:51 +04:00
|
|
|
{
|
2021-12-14 08:43:49 +03:00
|
|
|
|
|
|
|
if (g_cfg->restrict_outbound_clipboard & CLIP_RESTRICT_TEXT)
|
|
|
|
{
|
|
|
|
LOG(LOG_LEVEL_DEBUG,
|
|
|
|
"outbound clipboard(text) is restricted because of config");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_clip_s2c.type = g_utf8_atom;
|
|
|
|
g_clip_s2c.xrdp_clip_type = XRDP_CB_TEXT;
|
|
|
|
g_clip_s2c.converted = 0;
|
|
|
|
g_clip_s2c.clip_time = lxevent->time;
|
|
|
|
send_format_announce = 1;
|
|
|
|
}
|
|
|
|
|
2009-08-15 06:47:51 +04:00
|
|
|
}
|
2012-10-14 09:48:29 +04:00
|
|
|
else if (got_string)
|
2009-08-15 06:47:51 +04:00
|
|
|
{
|
2021-12-14 08:43:49 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* In most cases, when copying text, TARGETS atom and UTF8_STRING atom exists,
|
|
|
|
* it means that this code block which checks STRING atom might not be never executed
|
|
|
|
* in recent platforms.
|
|
|
|
* Use echo foo | xclip -selection clipboard -noutf8 to reproduce it.
|
|
|
|
*/
|
|
|
|
if (g_cfg->restrict_outbound_clipboard & CLIP_RESTRICT_TEXT)
|
|
|
|
{
|
|
|
|
LOG(LOG_LEVEL_DEBUG,
|
|
|
|
"outbound clipboard(text) is restricted because of config");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_clip_s2c.type = XA_STRING;
|
|
|
|
g_clip_s2c.xrdp_clip_type = XRDP_CB_TEXT;
|
|
|
|
g_clip_s2c.converted = 0;
|
|
|
|
g_clip_s2c.clip_time = lxevent->time;
|
|
|
|
send_format_announce = 1;
|
|
|
|
}
|
|
|
|
|
2009-08-15 06:47:51 +04:00
|
|
|
}
|
2012-10-14 09:48:29 +04:00
|
|
|
else if (got_bmp_image)
|
2012-09-20 07:51:34 +04:00
|
|
|
{
|
2021-12-14 08:43:49 +03:00
|
|
|
|
|
|
|
if (g_cfg->restrict_outbound_clipboard & CLIP_RESTRICT_IMAGE)
|
|
|
|
{
|
|
|
|
LOG(LOG_LEVEL_DEBUG,
|
|
|
|
"outbound clipboard(image) is restricted because of config");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_clip_s2c.type = g_image_bmp_atom;
|
|
|
|
g_clip_s2c.xrdp_clip_type = XRDP_CB_BITMAP;
|
|
|
|
g_clip_s2c.converted = 0;
|
|
|
|
g_clip_s2c.clip_time = lxevent->time;
|
|
|
|
send_format_announce = 1;
|
|
|
|
}
|
|
|
|
|
2012-09-20 07:51:34 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (send_format_announce)
|
|
|
|
{
|
2012-10-19 05:43:04 +04:00
|
|
|
if (clipboard_send_format_announce(g_clip_s2c.xrdp_clip_type) != 0)
|
2012-09-20 07:51:34 +04:00
|
|
|
{
|
|
|
|
rv = 4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free(data);
|
|
|
|
return rv;
|
2009-08-15 06:47:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
/* returns error
|
|
|
|
process the SelectionRequest X event, uses XSelectionRequestEvent
|
|
|
|
typedef struct {
|
|
|
|
int type; // SelectionRequest
|
|
|
|
unsigned long serial; // # of last request processed by server
|
|
|
|
Bool send_event; // true if this came from a SendEvent request
|
|
|
|
Display *display; // Display the event was read from
|
|
|
|
Window owner;
|
|
|
|
Window requestor;
|
|
|
|
Atom selection;
|
|
|
|
Atom target;
|
|
|
|
Atom property;
|
|
|
|
Time time;
|
|
|
|
} XSelectionRequestEvent; */
|
2012-08-12 21:51:45 +04:00
|
|
|
/*
|
|
|
|
* When XGetWindowProperty and XChangeProperty talk about "format 32" it
|
|
|
|
* doesn't mean a 32bit value, but actually a long. So 32 means 4 bytes on
|
|
|
|
* a 32bit machine and 8 bytes on a 64 machine
|
|
|
|
*/
|
2017-03-12 19:35:00 +03:00
|
|
|
static int
|
2012-09-20 07:51:34 +04:00
|
|
|
clipboard_event_selection_request(XEvent *xevent)
|
2009-08-15 06:47:51 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
XSelectionRequestEvent *lxev;
|
|
|
|
Atom atom_buf[10];
|
|
|
|
Atom type;
|
2012-10-18 08:23:31 +04:00
|
|
|
int atom_count;
|
2012-09-20 07:51:34 +04:00
|
|
|
int fmt;
|
|
|
|
int n_items;
|
|
|
|
int xdata_size;
|
|
|
|
char *xdata;
|
|
|
|
|
|
|
|
lxev = (XSelectionRequestEvent *)xevent;
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "clipboard_event_selection_request: 0x%lx", lxev->property);
|
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "clipboard_event_selection_request: g_wnd %ld, "
|
2020-11-30 03:36:20 +03:00
|
|
|
".requestor %ld .owner %ld .selection %ld '%s' .target %ld .property %ld",
|
|
|
|
g_wnd, lxev->requestor, lxev->owner, lxev->selection,
|
|
|
|
get_atom_text(lxev->selection),
|
|
|
|
lxev->target, lxev->property);
|
2012-09-20 07:51:34 +04:00
|
|
|
|
|
|
|
if (lxev->property == None)
|
2009-08-27 06:15:49 +04:00
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "clipboard_event_selection_request: "
|
2020-11-30 03:36:20 +03:00
|
|
|
"lxev->property is None");
|
2009-08-27 06:15:49 +04:00
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
else if (lxev->target == g_targets_atom)
|
2009-08-30 01:20:27 +04:00
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "clipboard_event_selection_request: g_targets_atom");
|
2012-09-20 07:51:34 +04:00
|
|
|
/* requestor is asking what the selection can be converted to */
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "clipboard_event_selection_request: "
|
2020-11-30 03:36:20 +03:00
|
|
|
"g_targets_atom");
|
2012-09-20 07:51:34 +04:00
|
|
|
atom_buf[0] = g_targets_atom;
|
|
|
|
atom_buf[1] = g_timestamp_atom;
|
|
|
|
atom_buf[2] = g_multiple_atom;
|
2022-01-14 14:11:03 +03:00
|
|
|
atom_count = 3;
|
2023-08-04 18:46:02 +03:00
|
|
|
|
|
|
|
/* Only announce text if the client is advertising text, or
|
|
|
|
* a file list */
|
2023-08-04 19:08:42 +03:00
|
|
|
if (clipboard_find_format_id(CF_UNICODETEXT) >= 0 ||
|
|
|
|
clipboard_find_format_id(CF_OEMTEXT) >= 0 ||
|
|
|
|
clipboard_find_format_id(CF_TEXT) >= 0 ||
|
|
|
|
clipboard_find_format_id(g_file_group_descriptor_format_id) >= 0)
|
2022-01-14 14:11:03 +03:00
|
|
|
{
|
2023-08-04 18:46:02 +03:00
|
|
|
if ((g_cfg->restrict_inbound_clipboard & CLIP_RESTRICT_TEXT) == 0)
|
|
|
|
{
|
|
|
|
atom_buf[atom_count] = XA_STRING;
|
|
|
|
atom_count++;
|
|
|
|
atom_buf[atom_count] = g_utf8_atom;
|
|
|
|
atom_count++;
|
|
|
|
}
|
2022-01-14 14:11:03 +03:00
|
|
|
}
|
2023-08-04 19:08:42 +03:00
|
|
|
if (clipboard_find_format_id(CF_DIB) >= 0 &&
|
2022-01-14 14:11:03 +03:00
|
|
|
(g_cfg->restrict_inbound_clipboard & CLIP_RESTRICT_IMAGE) == 0)
|
2012-10-18 08:23:31 +04:00
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, " reporting image/bmp");
|
2012-10-18 08:23:31 +04:00
|
|
|
atom_buf[atom_count] = g_image_bmp_atom;
|
|
|
|
atom_count++;
|
|
|
|
}
|
2023-08-04 19:08:42 +03:00
|
|
|
if (clipboard_find_format_id(g_file_group_descriptor_format_id) >= 0 &&
|
2022-01-14 14:11:03 +03:00
|
|
|
(g_cfg->restrict_inbound_clipboard & CLIP_RESTRICT_FILE) == 0)
|
2012-11-05 13:04:04 +04:00
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, " reporting text/uri-list");
|
2012-11-05 13:04:04 +04:00
|
|
|
atom_buf[atom_count] = g_file_atom1;
|
|
|
|
atom_count++;
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, " reporting x-special/gnome-copied-files");
|
2012-11-05 13:04:04 +04:00
|
|
|
atom_buf[atom_count] = g_file_atom2;
|
|
|
|
atom_count++;
|
|
|
|
}
|
2012-10-21 07:23:01 +04:00
|
|
|
atom_buf[atom_count] = 0;
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, " reporting %d formats", atom_count);
|
2012-10-18 08:23:31 +04:00
|
|
|
return clipboard_provide_selection(lxev, XA_ATOM, 32,
|
|
|
|
(char *)atom_buf, atom_count);
|
2009-08-30 01:20:27 +04:00
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
else if (lxev->target == g_timestamp_atom)
|
2009-08-30 01:20:27 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
/* requestor is asking the time I got the selection */
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "clipboard_event_selection_request: "
|
2020-11-30 03:36:20 +03:00
|
|
|
"g_timestamp_atom");
|
2012-09-20 07:51:34 +04:00
|
|
|
atom_buf[0] = g_selection_time;
|
2012-10-05 09:55:06 +04:00
|
|
|
atom_buf[1] = 0;
|
2012-10-21 07:23:01 +04:00
|
|
|
return clipboard_provide_selection(lxev, XA_INTEGER, 32,
|
|
|
|
(char *)atom_buf, 1);
|
2009-08-30 01:20:27 +04:00
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
else if (lxev->target == g_multiple_atom)
|
2009-08-30 01:20:27 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
/* target, property pairs */
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "clipboard_event_selection_request: "
|
2020-11-30 03:36:20 +03:00
|
|
|
"g_multiple_atom");
|
2012-09-20 07:51:34 +04:00
|
|
|
|
2012-10-19 05:43:04 +04:00
|
|
|
xdata = 0;
|
2013-08-08 08:02:22 +04:00
|
|
|
if (clipboard_get_window_property(lxev->requestor, lxev->property,
|
2012-09-20 07:51:34 +04:00
|
|
|
&type, &fmt, &n_items, &xdata,
|
|
|
|
&xdata_size) == 0)
|
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "clipboard_event_selection_request: g_multiple_atom "
|
2020-11-30 03:36:20 +03:00
|
|
|
"n_items %d", n_items);
|
2012-09-20 07:51:34 +04:00
|
|
|
/* todo */
|
|
|
|
g_free(xdata);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ((lxev->target == XA_STRING) || (lxev->target == g_utf8_atom))
|
|
|
|
{
|
2023-08-04 19:08:42 +03:00
|
|
|
if (clipboard_find_format_id(g_file_group_descriptor_format_id) >= 0)
|
2021-09-14 16:43:33 +03:00
|
|
|
{
|
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "clipboard_event_selection_request: "
|
|
|
|
"text requested when files available");
|
2021-12-14 08:45:54 +03:00
|
|
|
|
|
|
|
if (g_cfg->restrict_inbound_clipboard & CLIP_RESTRICT_FILE)
|
|
|
|
{
|
|
|
|
LOG(LOG_LEVEL_DEBUG,
|
|
|
|
"inbound clipboard %s is restricted because of config",
|
|
|
|
lxev->target == XA_STRING ? "XA_STRING" : "UTF8_STRING");
|
|
|
|
clipboard_refuse_selection(lxev);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_memcpy(&g_saved_selection_req_event, lxev,
|
|
|
|
sizeof(g_saved_selection_req_event));
|
|
|
|
g_clip_c2s.type = lxev->target;
|
|
|
|
g_clip_c2s.xrdp_clip_type = XRDP_CB_FILE;
|
2023-08-04 19:08:42 +03:00
|
|
|
clipboard_send_data_request(g_file_group_descriptor_format_id);
|
2021-12-14 08:45:54 +03:00
|
|
|
}
|
|
|
|
|
2021-09-14 16:43:33 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-12-14 08:45:54 +03:00
|
|
|
|
|
|
|
if (g_cfg->restrict_inbound_clipboard & CLIP_RESTRICT_TEXT)
|
|
|
|
{
|
|
|
|
LOG(LOG_LEVEL_DEBUG,
|
|
|
|
"inbound clipboard %s is restricted because of config",
|
|
|
|
lxev->target == XA_STRING ? "XA_STRING" : "UTF8_STRING");
|
|
|
|
clipboard_refuse_selection(lxev);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-08-04 18:46:02 +03:00
|
|
|
/* The client may have advertised CF_TEXT or CF_OEMTEXT,
|
|
|
|
* but the Windows clipboard will convert these formats
|
|
|
|
* to Unicode if asked */
|
2021-12-14 08:45:54 +03:00
|
|
|
g_memcpy(&g_saved_selection_req_event, lxev,
|
|
|
|
sizeof(g_saved_selection_req_event));
|
|
|
|
g_clip_c2s.type = lxev->target;
|
|
|
|
g_clip_c2s.xrdp_clip_type = XRDP_CB_TEXT;
|
2023-08-04 19:08:42 +03:00
|
|
|
clipboard_send_data_request(CF_UNICODETEXT);
|
2021-12-14 08:45:54 +03:00
|
|
|
}
|
|
|
|
|
2021-09-14 16:43:33 +03:00
|
|
|
}
|
2012-10-21 07:23:01 +04:00
|
|
|
return 0;
|
2012-09-20 07:51:34 +04:00
|
|
|
}
|
|
|
|
else if (lxev->target == g_image_bmp_atom)
|
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "clipboard_event_selection_request: image/bmp");
|
2012-11-05 13:04:04 +04:00
|
|
|
if ((g_clip_c2s.type == lxev->target) && g_clip_c2s.converted)
|
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "clipboard_event_selection_request: -------------------------------------------");
|
2021-12-14 08:45:54 +03:00
|
|
|
|
|
|
|
if (g_cfg->restrict_inbound_clipboard & CLIP_RESTRICT_IMAGE)
|
|
|
|
{
|
|
|
|
LOG(LOG_LEVEL_DEBUG,
|
|
|
|
"inbound clipboard image/bmp converted is restricted because of config");
|
|
|
|
clipboard_refuse_selection(lxev);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
clipboard_provide_selection_c2s(lxev, lxev->target);
|
|
|
|
}
|
2012-11-05 13:04:04 +04:00
|
|
|
return 0;
|
2021-12-14 08:45:54 +03:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (g_cfg->restrict_inbound_clipboard & CLIP_RESTRICT_IMAGE)
|
|
|
|
{
|
|
|
|
LOG(LOG_LEVEL_DEBUG,
|
|
|
|
"inbound clipboard image/bmp is restricted because of config");
|
|
|
|
clipboard_refuse_selection(lxev);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_memcpy(&g_saved_selection_req_event, lxev,
|
|
|
|
sizeof(g_saved_selection_req_event));
|
|
|
|
g_clip_c2s.type = g_image_bmp_atom;
|
|
|
|
g_clip_c2s.xrdp_clip_type = XRDP_CB_BITMAP;
|
2023-08-04 19:08:42 +03:00
|
|
|
clipboard_send_data_request(CF_DIB);
|
2012-11-05 13:04:04 +04:00
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
return 0;
|
2021-12-14 08:45:54 +03:00
|
|
|
|
2009-08-30 01:20:27 +04:00
|
|
|
}
|
2012-11-05 13:04:04 +04:00
|
|
|
else if (lxev->target == g_file_atom1)
|
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "clipboard_event_selection_request: g_file_atom1");
|
2012-11-05 13:04:04 +04:00
|
|
|
if ((g_clip_c2s.type == lxev->target) && g_clip_c2s.converted)
|
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "clipboard_event_selection_request: -------------------------------------------");
|
2021-12-14 08:45:54 +03:00
|
|
|
if (g_cfg->restrict_inbound_clipboard & CLIP_RESTRICT_FILE)
|
|
|
|
{
|
|
|
|
LOG(LOG_LEVEL_DEBUG,
|
|
|
|
"inbound clipboard text/uri-list is restricted because of config");
|
|
|
|
clipboard_refuse_selection(lxev);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
clipboard_provide_selection_c2s(lxev, lxev->target);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (g_cfg->restrict_inbound_clipboard & CLIP_RESTRICT_FILE)
|
|
|
|
{
|
|
|
|
LOG(LOG_LEVEL_DEBUG,
|
|
|
|
"inbound clipboard text/uri-list is restricted because of config");
|
|
|
|
clipboard_refuse_selection(lxev);
|
2012-11-05 13:04:04 +04:00
|
|
|
return 0;
|
|
|
|
}
|
2021-12-14 08:45:54 +03:00
|
|
|
else
|
|
|
|
{
|
|
|
|
g_memcpy(&g_saved_selection_req_event, lxev,
|
|
|
|
sizeof(g_saved_selection_req_event));
|
|
|
|
g_clip_c2s.type = g_file_atom1;
|
|
|
|
g_clip_c2s.xrdp_clip_type = XRDP_CB_FILE;
|
2023-08-04 19:08:42 +03:00
|
|
|
clipboard_send_data_request(g_file_group_descriptor_format_id);
|
2021-12-14 08:45:54 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-11-05 13:04:04 +04:00
|
|
|
}
|
|
|
|
else if (lxev->target == g_file_atom2)
|
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "clipboard_event_selection_request: g_file_atom2");
|
2021-12-14 08:45:54 +03:00
|
|
|
|
2012-11-05 13:04:04 +04:00
|
|
|
if ((g_clip_c2s.type == lxev->target) && g_clip_c2s.converted)
|
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "clipboard_event_selection_request: -------------------------------------------");
|
2021-12-14 08:45:54 +03:00
|
|
|
if (g_cfg->restrict_inbound_clipboard & CLIP_RESTRICT_FILE)
|
|
|
|
{
|
|
|
|
LOG(LOG_LEVEL_DEBUG,
|
|
|
|
"inbound clipboard x-special/gnome-copied-files converted is restricted because of config");
|
|
|
|
clipboard_refuse_selection(lxev);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
clipboard_provide_selection_c2s(lxev, lxev->target);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (g_cfg->restrict_inbound_clipboard & CLIP_RESTRICT_FILE)
|
|
|
|
{
|
|
|
|
LOG(LOG_LEVEL_DEBUG,
|
|
|
|
"inbound clipboard x-special/gnome-copied-files is restricted because of config");
|
|
|
|
clipboard_refuse_selection(lxev);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_memcpy(&g_saved_selection_req_event, lxev,
|
|
|
|
sizeof(g_saved_selection_req_event));
|
|
|
|
g_clip_c2s.type = g_file_atom2;
|
|
|
|
g_clip_c2s.xrdp_clip_type = XRDP_CB_FILE;
|
2023-08-04 19:08:42 +03:00
|
|
|
clipboard_send_data_request(g_file_group_descriptor_format_id);
|
2012-11-05 13:04:04 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
else
|
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG(LOG_LEVEL_ERROR, "clipboard_event_selection_request: unknown "
|
2020-11-30 03:36:20 +03:00
|
|
|
"target %s", get_atom_text(lxev->target));
|
2012-09-20 07:51:34 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
clipboard_refuse_selection(lxev);
|
2012-08-20 06:45:31 +04:00
|
|
|
return 0;
|
2009-08-15 06:47:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
/* returns error
|
|
|
|
process the SelectionClear X event, uses XSelectionClearEvent
|
|
|
|
typedef struct {
|
|
|
|
int type; // SelectionClear
|
|
|
|
unsigned long serial; // # of last request processed by server
|
|
|
|
Bool send_event; // true if this came from a SendEvent request
|
|
|
|
Display *display; // Display the event was read from
|
|
|
|
Window window;
|
|
|
|
Atom selection;
|
|
|
|
Time time;
|
|
|
|
} XSelectionClearEvent; */
|
2017-03-12 19:35:00 +03:00
|
|
|
static int
|
2012-09-20 07:51:34 +04:00
|
|
|
clipboard_event_selection_clear(XEvent *xevent)
|
2009-08-15 06:47:51 +04:00
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "clipboard_event_selection_clear:");
|
2012-09-20 07:51:34 +04:00
|
|
|
return 0;
|
2009-08-15 06:47:51 +04:00
|
|
|
}
|
|
|
|
|
2009-09-01 10:42:40 +04:00
|
|
|
/*****************************************************************************/
|
|
|
|
/* returns error
|
|
|
|
typedef struct {
|
|
|
|
int type; // PropertyNotify
|
|
|
|
unsigned long serial; // # of last request processed by server
|
|
|
|
Bool send_event; // true if this came from a SendEvent request
|
|
|
|
Display *display; // Display the event was read from
|
|
|
|
Window window;
|
|
|
|
Atom atom;
|
|
|
|
Time time;
|
|
|
|
int state; // PropertyNewValue or PropertyDelete
|
|
|
|
} XPropertyEvent; */
|
2017-03-12 19:35:00 +03:00
|
|
|
static int
|
2012-09-20 07:51:34 +04:00
|
|
|
clipboard_event_property_notify(XEvent *xevent)
|
2009-09-01 10:42:40 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
Atom actual_type_return;
|
|
|
|
int actual_format_return;
|
|
|
|
unsigned long nitems_returned;
|
|
|
|
unsigned long bytes_left;
|
|
|
|
unsigned char *data;
|
|
|
|
int rv;
|
|
|
|
int format_in_bytes;
|
|
|
|
int new_data_len;
|
2012-11-14 21:44:43 +04:00
|
|
|
int data_bytes;
|
2012-09-20 07:51:34 +04:00
|
|
|
char *cptr;
|
|
|
|
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "clipboard_event_property_notify: PropertyNotify .window %ld "
|
2020-11-30 03:36:20 +03:00
|
|
|
".state %d .atom %ld %s", xevent->xproperty.window,
|
|
|
|
xevent->xproperty.state, xevent->xproperty.atom,
|
|
|
|
get_atom_text(xevent->xproperty.atom));
|
2012-09-20 07:51:34 +04:00
|
|
|
|
2012-10-18 08:23:31 +04:00
|
|
|
if (g_clip_c2s.incr_in_progress &&
|
2012-10-22 09:15:31 +04:00
|
|
|
(xevent->xproperty.window == g_clip_c2s.window) &&
|
2012-10-19 05:43:04 +04:00
|
|
|
(xevent->xproperty.atom == g_clip_c2s.property) &&
|
2012-10-15 05:08:06 +04:00
|
|
|
(xevent->xproperty.state == PropertyDelete))
|
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "clipboard_event_property_notify: INCR PropertyDelete");
|
2012-10-15 05:08:06 +04:00
|
|
|
/* this is used for when copying a large clipboard to the other app,
|
|
|
|
it will delete the property so we know to send the next one */
|
2012-10-17 12:13:37 +04:00
|
|
|
|
2012-10-18 20:58:23 +04:00
|
|
|
if ((g_clip_c2s.data == 0) || (g_clip_c2s.total_bytes < 1))
|
2012-10-17 12:13:37 +04:00
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "clipboard_event_property_notify: INCR error");
|
2012-10-17 12:13:37 +04:00
|
|
|
return 0;
|
|
|
|
}
|
2012-10-18 20:58:23 +04:00
|
|
|
data = (tui8 *)(g_clip_c2s.data + g_clip_c2s.incr_bytes_done);
|
2012-11-14 21:44:43 +04:00
|
|
|
data_bytes = g_clip_c2s.read_bytes_done - g_clip_c2s.incr_bytes_done;
|
|
|
|
if ((data_bytes < 1) &&
|
2019-02-26 09:40:10 +03:00
|
|
|
(g_clip_c2s.read_bytes_done < g_clip_c2s.total_bytes))
|
2012-11-14 21:44:43 +04:00
|
|
|
{
|
|
|
|
g_clip_c2s.incr_in_progress = 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (data_bytes > g_incr_max_req_size)
|
2012-10-17 12:13:37 +04:00
|
|
|
{
|
2012-11-14 21:44:43 +04:00
|
|
|
data_bytes = g_incr_max_req_size;
|
2012-10-17 12:13:37 +04:00
|
|
|
}
|
2012-11-14 21:44:43 +04:00
|
|
|
g_clip_c2s.incr_bytes_done += data_bytes;
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "clipboard_event_property_notify: data_bytes %d", data_bytes);
|
2012-10-17 12:13:37 +04:00
|
|
|
XChangeProperty(xevent->xproperty.display, xevent->xproperty.window,
|
2012-10-18 20:58:23 +04:00
|
|
|
xevent->xproperty.atom, g_clip_c2s.type, 8,
|
2012-11-14 21:44:43 +04:00
|
|
|
PropModeReplace, data, data_bytes);
|
|
|
|
if (data_bytes < 1)
|
2012-10-17 12:13:37 +04:00
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "clipboard_event_property_notify: INCR done");
|
2012-10-18 08:23:31 +04:00
|
|
|
g_clip_c2s.incr_in_progress = 0;
|
2012-10-17 12:13:37 +04:00
|
|
|
/* we no longer need property notify */
|
|
|
|
XSelectInput(xevent->xproperty.display, xevent->xproperty.window,
|
|
|
|
NoEventMask);
|
2012-11-14 21:44:43 +04:00
|
|
|
g_clip_c2s.converted = 1;
|
2012-10-17 12:13:37 +04:00
|
|
|
}
|
2012-10-15 05:08:06 +04:00
|
|
|
}
|
2012-10-18 20:58:23 +04:00
|
|
|
if (g_clip_s2c.incr_in_progress &&
|
2012-10-22 09:15:31 +04:00
|
|
|
(xevent->xproperty.window == g_wnd) &&
|
2012-10-19 05:43:04 +04:00
|
|
|
(xevent->xproperty.atom == g_clip_s2c.property) &&
|
2012-09-20 07:51:34 +04:00
|
|
|
(xevent->xproperty.state == PropertyNewValue))
|
2012-08-12 21:51:45 +04:00
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "clipboard_event_property_notify: INCR PropertyNewValue");
|
2012-10-19 05:43:04 +04:00
|
|
|
rv = XGetWindowProperty(g_display, g_wnd, g_clip_s2c.property, 0, 0, 0,
|
2012-09-20 07:51:34 +04:00
|
|
|
AnyPropertyType, &actual_type_return, &actual_format_return,
|
2012-10-17 12:13:37 +04:00
|
|
|
&nitems_returned, &bytes_left, &data);
|
2012-09-20 07:51:34 +04:00
|
|
|
|
2016-05-07 04:31:03 +03:00
|
|
|
if (rv != Success)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2012-08-12 21:51:45 +04:00
|
|
|
if (data != 0)
|
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
XFree(data);
|
|
|
|
data = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bytes_left <= 0)
|
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "clipboard_event_property_notify: INCR done");
|
2012-09-20 07:51:34 +04:00
|
|
|
/* clipboard INCR cycle has completed */
|
2012-10-18 20:58:23 +04:00
|
|
|
g_clip_s2c.incr_in_progress = 0;
|
2012-10-19 05:43:04 +04:00
|
|
|
if (g_clip_s2c.type == g_image_bmp_atom)
|
2012-09-20 07:51:34 +04:00
|
|
|
{
|
2012-10-19 05:43:04 +04:00
|
|
|
g_clip_s2c.xrdp_clip_type = XRDP_CB_BITMAP;
|
2020-11-30 03:36:20 +03:00
|
|
|
//LOG_DEVEL_HEXDUMP(LOG_LEVEL_TRACE, "", g_last_clip_data, 64);
|
2012-10-14 09:48:29 +04:00
|
|
|
/* skip header */
|
2012-10-19 05:43:04 +04:00
|
|
|
clipboard_send_data_response(g_clip_s2c.xrdp_clip_type,
|
|
|
|
g_clip_s2c.data + 14,
|
|
|
|
g_clip_s2c.total_bytes - 14);
|
2012-10-14 09:48:29 +04:00
|
|
|
}
|
2012-10-19 05:43:04 +04:00
|
|
|
else if ((g_clip_s2c.type == XA_STRING) ||
|
|
|
|
(g_clip_s2c.type == g_utf8_atom))
|
2012-10-14 09:48:29 +04:00
|
|
|
{
|
2012-10-19 05:43:04 +04:00
|
|
|
g_clip_s2c.xrdp_clip_type = XRDP_CB_TEXT;
|
|
|
|
clipboard_send_data_response(g_clip_s2c.xrdp_clip_type,
|
|
|
|
g_clip_s2c.data,
|
|
|
|
g_clip_s2c.total_bytes);
|
2012-10-14 09:48:29 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_ERROR, "clipboard_event_property_notify: error unknown type %ld",
|
2020-11-30 03:36:20 +03:00
|
|
|
g_clip_s2c.type);
|
2012-10-14 09:48:29 +04:00
|
|
|
clipboard_send_data_response_failed();
|
2012-09-20 07:51:34 +04:00
|
|
|
}
|
|
|
|
|
2012-10-19 05:43:04 +04:00
|
|
|
XDeleteProperty(g_display, g_wnd, g_clip_s2c.property);
|
2012-09-20 07:51:34 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-10-19 05:43:04 +04:00
|
|
|
rv = XGetWindowProperty(g_display, g_wnd, g_clip_s2c.property, 0, bytes_left, 0,
|
2012-09-20 07:51:34 +04:00
|
|
|
AnyPropertyType, &actual_type_return, &actual_format_return,
|
2012-10-17 12:13:37 +04:00
|
|
|
&nitems_returned, &bytes_left, &data);
|
2012-09-20 07:51:34 +04:00
|
|
|
|
2016-05-07 04:31:03 +03:00
|
|
|
if (rv != Success)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2012-10-17 12:13:37 +04:00
|
|
|
format_in_bytes = FORMAT_TO_BYTES(actual_format_return);
|
2012-09-20 07:51:34 +04:00
|
|
|
new_data_len = nitems_returned * format_in_bytes;
|
2012-10-19 05:43:04 +04:00
|
|
|
cptr = (char *) g_malloc(g_clip_s2c.total_bytes + new_data_len, 0);
|
2012-09-20 07:51:34 +04:00
|
|
|
if (cptr == NULL)
|
|
|
|
{
|
2023-09-04 12:32:12 +03:00
|
|
|
/* cannot add any more data */
|
|
|
|
g_free(g_clip_s2c.data);
|
2012-10-19 05:43:04 +04:00
|
|
|
g_clip_s2c.data = 0;
|
2012-09-20 07:51:34 +04:00
|
|
|
|
|
|
|
if (data != 0)
|
|
|
|
{
|
|
|
|
XFree(data);
|
|
|
|
}
|
|
|
|
|
2012-10-19 05:43:04 +04:00
|
|
|
XDeleteProperty(g_display, g_wnd, g_clip_s2c.property);
|
2012-09-20 07:51:34 +04:00
|
|
|
return 0;
|
|
|
|
}
|
2023-09-04 12:32:12 +03:00
|
|
|
g_memcpy(cptr, g_clip_s2c.data, g_clip_s2c.total_bytes);
|
|
|
|
g_free(g_clip_s2c.data);
|
2012-09-20 07:51:34 +04:00
|
|
|
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "clipboard_event_property_notify: new_data_len %d", new_data_len);
|
2012-10-19 05:43:04 +04:00
|
|
|
g_clip_s2c.data = cptr;
|
2012-09-20 07:51:34 +04:00
|
|
|
if (data)
|
|
|
|
{
|
2023-09-04 12:32:12 +03:00
|
|
|
g_memcpy(g_clip_s2c.data + g_clip_s2c.total_bytes, data, new_data_len);
|
|
|
|
g_clip_s2c.total_bytes += new_data_len;
|
2012-09-20 07:51:34 +04:00
|
|
|
XFree(data);
|
|
|
|
}
|
|
|
|
|
2012-10-19 05:43:04 +04:00
|
|
|
XDeleteProperty(g_display, g_wnd, g_clip_s2c.property);
|
2012-08-12 21:51:45 +04:00
|
|
|
}
|
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
|
|
|
|
return 0;
|
2009-09-01 10:42:40 +04:00
|
|
|
}
|
|
|
|
|
2009-08-15 06:47:51 +04:00
|
|
|
/*****************************************************************************/
|
2012-07-27 01:38:02 +04:00
|
|
|
/* returns 0, event handled, 1 unhandled */
|
2017-03-12 19:35:00 +03:00
|
|
|
int
|
2012-09-20 07:51:34 +04:00
|
|
|
clipboard_xevent(void *xevent)
|
2009-04-19 21:16:46 +04:00
|
|
|
{
|
2012-09-20 07:51:34 +04:00
|
|
|
XEvent *lxevent;
|
|
|
|
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "clipboard_xevent: event detected");
|
2018-11-19 15:04:43 +03:00
|
|
|
|
2012-09-20 07:51:34 +04:00
|
|
|
if (!g_clip_up)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
lxevent = (XEvent *)xevent;
|
|
|
|
|
|
|
|
switch (lxevent->type)
|
|
|
|
{
|
|
|
|
case SelectionNotify:
|
2021-12-14 08:43:49 +03:00
|
|
|
clipboard_event_selection_notify(lxevent);
|
2012-09-20 07:51:34 +04:00
|
|
|
break;
|
|
|
|
case SelectionRequest:
|
|
|
|
clipboard_event_selection_request(lxevent);
|
|
|
|
break;
|
|
|
|
case SelectionClear:
|
|
|
|
clipboard_event_selection_clear(lxevent);
|
|
|
|
break;
|
|
|
|
case MappingNotify:
|
|
|
|
break;
|
|
|
|
case PropertyNotify:
|
|
|
|
clipboard_event_property_notify(lxevent);
|
|
|
|
break;
|
|
|
|
case UnmapNotify:
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "chansrv::clipboard_xevent: got UnmapNotify");
|
2012-09-20 07:51:34 +04:00
|
|
|
break;
|
|
|
|
case ClientMessage:
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "chansrv::clipboard_xevent: got ClientMessage");
|
2012-09-20 07:51:34 +04:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
|
|
|
|
if (lxevent->type == g_xfixes_event_base +
|
|
|
|
XFixesSetSelectionOwnerNotify)
|
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "clipboard_xevent: got XFixesSetSelectionOwnerNotify");
|
2012-09-20 07:51:34 +04:00
|
|
|
clipboard_event_selection_owner_notify(lxevent);
|
|
|
|
break;
|
|
|
|
}
|
2012-10-14 09:48:29 +04:00
|
|
|
if (lxevent->type == g_xfixes_event_base +
|
|
|
|
XFixesSelectionWindowDestroyNotify)
|
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "clipboard_xevent: got XFixesSelectionWindowDestroyNotify");
|
2012-10-14 09:48:29 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (lxevent->type == g_xfixes_event_base +
|
|
|
|
XFixesSelectionClientCloseNotify)
|
|
|
|
{
|
2020-10-08 04:55:08 +03:00
|
|
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "clipboard_xevent: got XFixesSelectionClientCloseNotify");
|
2012-10-14 09:48:29 +04:00
|
|
|
break;
|
|
|
|
}
|
2012-09-20 07:51:34 +04:00
|
|
|
|
|
|
|
/* we didn't handle this message */
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2009-04-19 21:16:46 +04:00
|
|
|
}
|