clipboard: Tell the X11 client if a selection is unavailable
This commit is contained in:
parent
011009681e
commit
680bba8a02
@ -1157,12 +1157,15 @@ clipboard_process_data_request(struct stream *s, int clip_msg_status,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/**************************************************************************//**
|
||||||
/* client to server */
|
* Process a CB_FORMAT_DATA_RESPONSE for an X client requesting an image
|
||||||
/* sent as a reply to CB_FORMAT_DATA_REQUEST; used to indicate whether
|
*
|
||||||
processing of the CB_FORMAT_DATA_REQUEST was successful; if processing
|
* @param s Stream containing CLIPRDR_FILELIST ([MS-RDPECLIP])
|
||||||
was successful, CB_FORMAT_DATA_RESPONSE includes contents of requested
|
* @param clip_msg_status msgFlags from Clipboard PDU Header
|
||||||
clipboard data. */
|
* @param clip_msg_len dataLen from Clipboard PDU Header
|
||||||
|
*
|
||||||
|
* @return Status
|
||||||
|
*/
|
||||||
static int
|
static int
|
||||||
clipboard_process_data_response_for_image(struct stream *s,
|
clipboard_process_data_response_for_image(struct stream *s,
|
||||||
int clip_msg_status,
|
int clip_msg_status,
|
||||||
@ -1289,50 +1292,44 @@ clipboard_process_data_response_for_file(struct stream *s,
|
|||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/**************************************************************************//**
|
||||||
/* client to server */
|
* Process a CB_FORMAT_DATA_RESPONSE for an X client requesting text
|
||||||
/* 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
|
* @param s Stream containing CLIPRDR_FILELIST ([MS-RDPECLIP])
|
||||||
successful, CB_FORMAT_DATA_RESPONSE includes contents of requested
|
* @param clip_msg_status msgFlags from Clipboard PDU Header
|
||||||
clipboard data. */
|
* @param clip_msg_len dataLen from Clipboard PDU Header
|
||||||
/*****************************************************************************/
|
*
|
||||||
|
* @return Status
|
||||||
|
*/
|
||||||
static int
|
static int
|
||||||
clipboard_process_data_response(struct stream *s, int clip_msg_status,
|
clipboard_process_data_response_for_text(struct stream *s,
|
||||||
|
int clip_msg_status,
|
||||||
int clip_msg_len)
|
int clip_msg_len)
|
||||||
{
|
{
|
||||||
XSelectionRequestEvent *lxev;
|
XSelectionRequestEvent *lxev = &g_saved_selection_req_event;
|
||||||
twchar *wtext;
|
twchar *wtext;
|
||||||
twchar wchr;
|
twchar wchr;
|
||||||
int len;
|
int len;
|
||||||
int index;
|
int index;
|
||||||
|
int byte_count;
|
||||||
|
|
||||||
LOG_DEVEL(LOG_LEVEL_DEBUG, "clipboard_process_data_response:");
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "clipboard_process_data_response_for_text: ");
|
||||||
lxev = &g_saved_selection_req_event;
|
|
||||||
g_clip_c2s.in_request = 0;
|
|
||||||
if (g_clip_c2s.xrdp_clip_type == XRDP_CB_BITMAP)
|
|
||||||
{
|
|
||||||
clipboard_process_data_response_for_image(s, clip_msg_status,
|
|
||||||
clip_msg_len);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
if (g_clip_c2s.xrdp_clip_type == XRDP_CB_FILE)
|
|
||||||
{
|
|
||||||
clipboard_process_data_response_for_file(s, clip_msg_status,
|
|
||||||
clip_msg_len);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
LOG_DEVEL(LOG_LEVEL_DEBUG, "clipboard_process_data_response: "
|
|
||||||
"CLIPRDR_DATA_RESPONSE");
|
|
||||||
len = (int)(s->end - s->p);
|
len = (int)(s->end - s->p);
|
||||||
if (len < 1)
|
if (len < 1)
|
||||||
{
|
{
|
||||||
return 0;
|
len = 0;
|
||||||
}
|
}
|
||||||
wtext = (twchar *) g_malloc(((len / 2) + 1) * sizeof(twchar), 0);
|
byte_count = ((len / 2) + 1) * sizeof(twchar);
|
||||||
|
wtext = (twchar *) g_malloc(byte_count, 0);
|
||||||
if (wtext == 0)
|
if (wtext == 0)
|
||||||
{
|
{
|
||||||
return 0;
|
LOG(LOG_LEVEL_ERROR, "Can't allocate %d bytes for text clip response",
|
||||||
|
byte_count);
|
||||||
|
|
||||||
|
clipboard_refuse_selection(lxev);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
index = 0;
|
index = 0;
|
||||||
while (s_check_rem(s, 2))
|
while (s_check_rem(s, 2))
|
||||||
{
|
{
|
||||||
@ -1349,26 +1346,87 @@ clipboard_process_data_response(struct stream *s, int clip_msg_status,
|
|||||||
g_clip_c2s.data = 0;
|
g_clip_c2s.data = 0;
|
||||||
g_clip_c2s.total_bytes = 0;
|
g_clip_c2s.total_bytes = 0;
|
||||||
len = g_wcstombs(0, wtext, 0);
|
len = g_wcstombs(0, wtext, 0);
|
||||||
if (len >= 0)
|
if (len < 0)
|
||||||
{
|
{
|
||||||
g_clip_c2s.data = (char *) g_malloc(len + 16, 0);
|
LOG(LOG_LEVEL_ERROR,
|
||||||
|
"Received malformed Unicode paste text from client");
|
||||||
|
clipboard_refuse_selection(lxev);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
byte_count = len + 16;
|
||||||
|
g_clip_c2s.data = (char *) g_malloc(byte_count, 0);
|
||||||
if (g_clip_c2s.data == 0)
|
if (g_clip_c2s.data == 0)
|
||||||
{
|
{
|
||||||
g_free(wtext);
|
LOG(LOG_LEVEL_ERROR,
|
||||||
return 0;
|
"Can't allocate %d bytes for text clip response",
|
||||||
|
byte_count);
|
||||||
|
clipboard_refuse_selection(lxev);
|
||||||
}
|
}
|
||||||
g_wcstombs(g_clip_c2s.data, wtext, len + 1);
|
else
|
||||||
}
|
|
||||||
if (g_clip_c2s.data != 0)
|
|
||||||
{
|
{
|
||||||
|
g_wcstombs(g_clip_c2s.data, wtext, len + 1);
|
||||||
g_clip_c2s.total_bytes = g_strlen(g_clip_c2s.data);
|
g_clip_c2s.total_bytes = g_strlen(g_clip_c2s.data);
|
||||||
g_clip_c2s.read_bytes_done = g_clip_c2s.total_bytes;
|
g_clip_c2s.read_bytes_done = g_clip_c2s.total_bytes;
|
||||||
clipboard_provide_selection_c2s(lxev, lxev->target);
|
clipboard_provide_selection_c2s(lxev, lxev->target);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
g_free(wtext);
|
g_free(wtext);
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/* client to server */
|
||||||
|
/* 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. */
|
||||||
|
/*****************************************************************************/
|
||||||
|
static int
|
||||||
|
clipboard_process_data_response(struct stream *s, int clip_msg_status,
|
||||||
|
int clip_msg_len)
|
||||||
|
{
|
||||||
|
int rv = 0;
|
||||||
|
|
||||||
|
XSelectionRequestEvent *lxev = &g_saved_selection_req_event;
|
||||||
|
|
||||||
|
LOG_DEVEL(LOG_LEVEL_DEBUG, "clipboard_process_data_response:");
|
||||||
|
g_clip_c2s.in_request = 0;
|
||||||
|
|
||||||
|
if ((clip_msg_status & CB_RESPONSE_FAIL) != 0)
|
||||||
|
{
|
||||||
|
/* 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);
|
||||||
|
}
|
||||||
|
else if ((clip_msg_status & CB_RESPONSE_OK) == 0)
|
||||||
|
{
|
||||||
|
/* 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);
|
||||||
|
}
|
||||||
|
else if (g_clip_c2s.xrdp_clip_type == XRDP_CB_BITMAP)
|
||||||
|
{
|
||||||
|
clipboard_process_data_response_for_image(s, clip_msg_status,
|
||||||
|
clip_msg_len);
|
||||||
|
}
|
||||||
|
else if (g_clip_c2s.xrdp_clip_type == XRDP_CB_FILE)
|
||||||
|
{
|
||||||
|
clipboard_process_data_response_for_file(s, clip_msg_status,
|
||||||
|
clip_msg_len);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
clipboard_process_data_response_for_text(s, clip_msg_status,
|
||||||
|
clip_msg_len);
|
||||||
|
}
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
static int
|
static int
|
||||||
clipboard_process_clip_caps(struct stream *s, int clip_msg_status,
|
clipboard_process_clip_caps(struct stream *s, int clip_msg_status,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user