work on clipboard

This commit is contained in:
jsorg71 2009-08-27 02:15:49 +00:00
parent acd9f3d82d
commit 23068b5fa1
3 changed files with 219 additions and 126 deletions

View File

@ -103,7 +103,7 @@ send_init_response_message(void)
{ {
struct stream* s; struct stream* s;
g_writeln("xrdp-chansrv: send_init_response_message:"); LOG(1, ("send_init_response_message:"));
s = trans_get_out_s(g_con_trans, 8192); s = trans_get_out_s(g_con_trans, 8192);
if (s == 0) if (s == 0)
{ {
@ -124,7 +124,7 @@ send_channel_setup_response_message(void)
{ {
struct stream* s; struct stream* s;
g_writeln("xrdp-chansrv: send_channel_setup_response_message:"); LOG(10, ("send_channel_setup_response_message:"));
s = trans_get_out_s(g_con_trans, 8192); s = trans_get_out_s(g_con_trans, 8192);
if (s == 0) if (s == 0)
{ {
@ -145,7 +145,7 @@ send_channel_data_response_message(void)
{ {
struct stream* s; struct stream* s;
g_writeln("xrdp-chansrv: send_channel_data_response_message:"); LOG(10, ("send_channel_data_response_message:"));
s = trans_get_out_s(g_con_trans, 8192); s = trans_get_out_s(g_con_trans, 8192);
if (s == 0) if (s == 0)
{ {
@ -164,7 +164,7 @@ send_channel_data_response_message(void)
static int APP_CC static int APP_CC
process_message_init(struct stream* s) process_message_init(struct stream* s)
{ {
g_writeln("xrdp-chansrv: process_message_init:"); LOG(10, ("process_message_init:"));
return send_init_response_message(); return send_init_response_message();
} }
@ -178,10 +178,9 @@ process_message_channel_setup(struct stream* s)
int rv; int rv;
struct chan_item* ci; struct chan_item* ci;
g_writeln("xrdp-chansrv: process_message_channel_setup:"); LOG(10, ("process_message_channel_setup:"));
in_uint16_le(s, num_chans); in_uint16_le(s, num_chans);
g_writeln("xrdp-chansrv: process_message_channel_setup: num_chans %d", LOG(10, ("process_message_channel_setup: num_chans %d", num_chans));
num_chans);
for (index = 0; index < num_chans; index++) for (index = 0; index < num_chans; index++)
{ {
ci = &(g_chan_items[g_num_chan_items]); ci = &(g_chan_items[g_num_chan_items]);
@ -189,8 +188,8 @@ process_message_channel_setup(struct stream* s)
in_uint8a(s, ci->name, 8); in_uint8a(s, ci->name, 8);
in_uint16_le(s, ci->id); in_uint16_le(s, ci->id);
in_uint16_le(s, ci->flags); in_uint16_le(s, ci->flags);
g_writeln("xrdp-chansrv: process_message_channel_setup: chan name %s " LOG(10, ("process_message_channel_setup: chan name '%s' "
"id %d flags %8.8x", ci->name, ci->id, ci->flags); "id %d flags %8.8x", ci->name, ci->id, ci->flags));
if (g_strcasecmp(ci->name, "cliprdr") == 0) if (g_strcasecmp(ci->name, "cliprdr") == 0)
{ {
g_cliprdr_index = g_num_chan_items; g_cliprdr_index = g_num_chan_items;
@ -239,8 +238,8 @@ process_message_channel_data(struct stream* s)
in_uint16_le(s, chan_flags); in_uint16_le(s, chan_flags);
in_uint16_le(s, length); in_uint16_le(s, length);
in_uint32_le(s, total_length); in_uint32_le(s, total_length);
g_writeln("xrdp-chansrv: process_message_channel_data: chan_id %d " LOG(10, ("process_message_channel_data: chan_id %d "
"chan_flags %d", chan_id, chan_flags); "chan_flags %d", chan_id, chan_flags));
rv = send_channel_data_response_message(); rv = send_channel_data_response_message();
if (rv == 0) if (rv == 0)
{ {
@ -265,7 +264,7 @@ process_message_channel_data(struct stream* s)
static int APP_CC static int APP_CC
process_message_channel_data_response(struct stream* s) process_message_channel_data_response(struct stream* s)
{ {
g_writeln("xrdp-chansrv: process_message_channel_data_response:"); LOG(10, ("process_message_channel_data_response:"));
return 0; return 0;
} }
@ -311,8 +310,8 @@ process_message(void)
rv = process_message_channel_data_response(s); rv = process_message_channel_data_response(s);
break; break;
default: default:
g_writeln("xrdp-chansrv: process_message: error in process_message " LOG(0, ("process_message: error in process_message "
"unknown msg %d", id); "unknown msg %d", id));
break; break;
} }
if (rv != 0) if (rv != 0)
@ -342,7 +341,7 @@ my_trans_data_in(struct trans* trans)
{ {
return 1; return 1;
} }
g_writeln("xrdp-chansrv: my_trans_data_in:"); LOG(10, ("my_trans_data_in:"));
s = trans_get_in_s(trans); s = trans_get_in_s(trans);
in_uint32_le(s, id); in_uint32_le(s, id);
in_uint32_le(s, size); in_uint32_le(s, size);
@ -375,7 +374,7 @@ my_trans_conn_in(struct trans* trans, struct trans* new_trans)
{ {
return 1; return 1;
} }
g_writeln("xrdp-chansrv: my_trans_conn_in:"); LOG(10, ("my_trans_conn_in:"));
g_con_trans = new_trans; g_con_trans = new_trans;
g_con_trans->trans_data_in = my_trans_data_in; g_con_trans->trans_data_in = my_trans_data_in;
g_con_trans->header_size = 8; g_con_trans->header_size = 8;
@ -402,7 +401,7 @@ setup_listen(void)
error = trans_listen(g_lis_trans, text); error = trans_listen(g_lis_trans, text);
if (error != 0) if (error != 0)
{ {
g_writeln("xrdp-chansrv: setup_listen: trans_listen failed"); LOG(0, ("setup_listen: trans_listen failed"));
return 1; return 1;
} }
return 0; return 0;
@ -418,7 +417,7 @@ channel_thread_loop(void* in_val)
int error; int error;
THREAD_RV rv; THREAD_RV rv;
g_writeln("xrdp-chansrv: channel_thread_loop: thread start"); LOG(1, ("channel_thread_loop: thread start"));
rv = 0; rv = 0;
error = setup_listen(); error = setup_listen();
if (error == 0) if (error == 0)
@ -432,7 +431,7 @@ channel_thread_loop(void* in_val)
{ {
if (g_is_wait_obj_set(g_term_event)) if (g_is_wait_obj_set(g_term_event))
{ {
g_writeln("xrdp-chansrv: channel_thread_loop: g_term_event set"); LOG(0, ("channel_thread_loop: g_term_event set"));
clipboard_deinit(); clipboard_deinit();
sound_deinit(); sound_deinit();
dev_redir_deinit(); dev_redir_deinit();
@ -442,16 +441,15 @@ channel_thread_loop(void* in_val)
{ {
if (trans_check_wait_objs(g_lis_trans) != 0) if (trans_check_wait_objs(g_lis_trans) != 0)
{ {
g_writeln("xrdp-chansrv: channel_thread_loop: " LOG(0, ("channel_thread_loop: trans_check_wait_objs error"));
"trans_check_wait_objs error");
} }
} }
if (g_con_trans != 0) if (g_con_trans != 0)
{ {
if (trans_check_wait_objs(g_con_trans) != 0) if (trans_check_wait_objs(g_con_trans) != 0)
{ {
g_writeln("xrdp-chansrv: channel_thread_loop: " LOG(0, ("channel_thread_loop: "
"trans_check_wait_objs error resetting"); "trans_check_wait_objs error resetting"));
/* delete g_con_trans */ /* delete g_con_trans */
trans_delete(g_con_trans); trans_delete(g_con_trans);
g_con_trans = 0; g_con_trans = 0;
@ -481,7 +479,7 @@ channel_thread_loop(void* in_val)
g_lis_trans = 0; g_lis_trans = 0;
trans_delete(g_con_trans); trans_delete(g_con_trans);
g_con_trans = 0; g_con_trans = 0;
g_writeln("xrdp-chansrv: channel_thread_loop: thread stop"); LOG(0, ("channel_thread_loop: thread stop"));
g_set_wait_obj(g_thread_done_event); g_set_wait_obj(g_thread_done_event);
return rv; return rv;
} }
@ -490,7 +488,7 @@ channel_thread_loop(void* in_val)
void DEFAULT_CC void DEFAULT_CC
term_signal_handler(int sig) term_signal_handler(int sig)
{ {
g_writeln("xrdp-chansrv: term_signal_handler: got signal %d", sig); LOG(1, ("term_signal_handler: got signal %d", sig));
g_set_wait_obj(g_term_event); g_set_wait_obj(g_term_event);
} }
@ -498,7 +496,7 @@ term_signal_handler(int sig)
void DEFAULT_CC void DEFAULT_CC
nil_signal_handler(int sig) nil_signal_handler(int sig)
{ {
g_writeln("xrdp-chansrv: nil_signal_handler: got signal %d", sig); LOG(1, ("nil_signal_handler: got signal %d", sig));
} }
/*****************************************************************************/ /*****************************************************************************/
@ -560,7 +558,7 @@ my_error_handler(Display* dis, XErrorEvent* xer)
char text[256]; char text[256];
XGetErrorText(dis, xer->error_code, text, 255); XGetErrorText(dis, xer->error_code, text, 255);
g_writeln("xrdp-chansrv: error [%s]", text); LOG(1, ("error [%s]", text));
return 0; return 0;
} }
@ -571,7 +569,7 @@ my_error_handler(Display* dis, XErrorEvent* xer)
int DEFAULT_CC int DEFAULT_CC
my_fatal_handler(Display* dis) my_fatal_handler(Display* dis)
{ {
g_writeln("xrdp-chansrv: fatal error, exiting"); LOG(1, ("fatal error, exiting"));
g_delete_wait_obj(g_term_event); g_delete_wait_obj(g_term_event);
g_delete_wait_obj(g_thread_done_event); g_delete_wait_obj(g_thread_done_event);
return 0; return 0;
@ -587,24 +585,24 @@ main(int argc, char** argv)
g_init(); /* os_calls */ g_init(); /* os_calls */
pid = g_getpid(); pid = g_getpid();
g_writeln("xrdp-chansrv: main: app started pid %d(0x%8.8x)", pid, pid); LOG(1, ("main: app started pid %d(0x%8.8x)", pid, pid));
g_signal_kill(term_signal_handler); /* SIGKILL */ g_signal_kill(term_signal_handler); /* SIGKILL */
g_signal_terminate(term_signal_handler); /* SIGTERM */ g_signal_terminate(term_signal_handler); /* SIGTERM */
g_signal_user_interrupt(term_signal_handler); /* SIGINT */ g_signal_user_interrupt(term_signal_handler); /* SIGINT */
g_signal_pipe(nil_signal_handler); /* SIGPIPE */ g_signal_pipe(nil_signal_handler); /* SIGPIPE */
display_text = g_getenv("DISPLAY"); display_text = g_getenv("DISPLAY");
g_writeln("xrdp-chansrv: main: DISPLAY env var set to %s", display_text); LOG(1, ("main: DISPLAY env var set to %s", display_text));
get_display_num_from_display(display_text); get_display_num_from_display(display_text);
if (g_display_num == 0) if (g_display_num == 0)
{ {
g_writeln("xrdp-chansrv: main: error, display is zero"); LOG(0, ("main: error, display is zero"));
return 1; return 1;
} }
g_writeln("xrdp-chansrv: main: using DISPLAY %d", g_display_num); LOG(1, ("main: using DISPLAY %d", g_display_num));
g_display = XOpenDisplay(0); g_display = XOpenDisplay(0);
if (g_display == 0) if (g_display == 0)
{ {
g_writeln("xrdp-chansrv: main: XOpenDisplay failed"); LOG(0, ("main: XOpenDisplay failed"));
return 1; return 1;
} }
XSetErrorHandler(my_error_handler); XSetErrorHandler(my_error_handler);
@ -618,7 +616,7 @@ main(int argc, char** argv)
{ {
if (g_obj_wait(&g_term_event, 1, 0, 0, 0) != 0) if (g_obj_wait(&g_term_event, 1, 0, 0, 0) != 0)
{ {
g_writeln("xrdp-chansrv: main: error, g_obj_wait failed"); LOG(0, ("main: error, g_obj_wait failed"));
break; break;
} }
} }
@ -627,14 +625,14 @@ main(int argc, char** argv)
/* wait for thread to exit */ /* wait for thread to exit */
if (g_obj_wait(&g_thread_done_event, 1, 0, 0, 0) != 0) if (g_obj_wait(&g_thread_done_event, 1, 0, 0, 0) != 0)
{ {
g_writeln("xrdp-chansrv: main: error, g_obj_wait failed"); LOG(0, ("main: error, g_obj_wait failed"));
break; break;
} }
} }
/* cleanup */ /* cleanup */
g_delete_wait_obj(g_term_event); g_delete_wait_obj(g_term_event);
g_delete_wait_obj(g_thread_done_event); g_delete_wait_obj(g_thread_done_event);
g_writeln("xrdp-chansrv: main: app exiting pid %d(0x%8.8x)", pid, pid); LOG(1, ("main: app exiting pid %d(0x%8.8x)", pid, pid));
g_deinit(); /* os_calls */ g_deinit(); /* os_calls */
return 0; return 0;
} }

View File

@ -15,4 +15,15 @@ struct chan_item
int APP_CC int APP_CC
send_channel_data(int chan_id, char* data, int size); send_channel_data(int chan_id, char* data, int size);
#define LOG_LEVEL 10
#define LOG(_a, _params) \
{ \
if (_a < LOG_LEVEL) \
{ \
g_write("xrdp-chansrv [%10.10d]: ", g_time3()); \
g_writeln _params ; \
} \
}
#endif #endif

View File

@ -37,6 +37,7 @@ static Atom g_multiple_atom = 0;
static Atom g_targets_atom = 0; static Atom g_targets_atom = 0;
static Atom g_primary_atom = 0; static Atom g_primary_atom = 0;
static Atom g_secondary_atom = 0; static Atom g_secondary_atom = 0;
static Atom g_get_time_atom = 0;
static int g_x_socket = 0; static int g_x_socket = 0;
static tbus g_x_wait_obj = 0; static tbus g_x_wait_obj = 0;
static int g_clip_up = 0; static int g_clip_up = 0;
@ -57,15 +58,27 @@ static struct stream* g_ins = 0;
extern int g_cliprdr_chan_id; /* in chansrv.c */ extern int g_cliprdr_chan_id; /* in chansrv.c */
extern Display* g_display; /* in chansrv.c */ extern Display* g_display; /* in chansrv.c */
/*****************************************************************************/
/* returns time in miliseconds /* returns time in miliseconds
this is like g_time2 in os_calls, but not miliseconds since machine was this is like g_time2 in os_calls, but not miliseconds since machine was
up, something else up, something else
this is a time value similar to what the xserver uses */ this is a time value similar to what the xserver uses */
/*****************************************************************************/
/* this is one way to get the current time from the x server */
static Time APP_CC static Time APP_CC
clipboard_get_time(void) clipboard_get_time(void)
{ {
return g_time3(); XEvent xevent;
/* append nothing */
XChangeProperty(g_display, g_wnd, g_get_time_atom, XA_STRING, 8,
PropModeAppend, "", 0);
/* wait for PropertyNotify */
do
{
XMaskEvent(g_display, PropertyChangeMask, &xevent);
} while (xevent.type != PropertyNotify);
return xevent.xproperty.time;
} }
/*****************************************************************************/ /*****************************************************************************/
@ -92,7 +105,7 @@ clipboard_init(void)
g_x_socket = XConnectionNumber(g_display); g_x_socket = XConnectionNumber(g_display);
if (g_x_socket == 0) if (g_x_socket == 0)
{ {
g_writeln("xrdp-chansrv: clipboard_init: XConnectionNumber failed"); LOG(0, ("clipboard_init: XConnectionNumber failed"));
rv = 2; rv = 2;
} }
g_x_wait_obj = g_create_wait_obj_from_socket(g_x_socket, 0); g_x_wait_obj = g_create_wait_obj_from_socket(g_x_socket, 0);
@ -102,7 +115,7 @@ clipboard_init(void)
g_clipboard_atom = XInternAtom(g_display, "CLIPBOARD", False); g_clipboard_atom = XInternAtom(g_display, "CLIPBOARD", False);
if (g_clipboard_atom == None) if (g_clipboard_atom == None)
{ {
g_writeln("xrdp-chansrv: clipboard_init: XInternAtom failed"); LOG(0, ("clipboard_init: XInternAtom failed"));
rv = 3; rv = 3;
} }
} }
@ -110,21 +123,21 @@ clipboard_init(void)
{ {
if (!XFixesQueryExtension(g_display, &g_xfixes_event_base, &dummy)) if (!XFixesQueryExtension(g_display, &g_xfixes_event_base, &dummy))
{ {
g_writeln("xrdp-chansrv: clipboard_init: no xfixes"); LOG(0, ("clipboard_init: no xfixes"));
rv = 5; rv = 5;
} }
} }
if (rv == 0) if (rv == 0)
{ {
g_writeln("xrdp-chansrv: clipboard_init: g_xfixes_event_base %d", LOG(1, ("clipboard_init: g_xfixes_event_base %d", g_xfixes_event_base));
g_xfixes_event_base);
st = XFixesQueryVersion(g_display, &ver_maj, &ver_min); st = XFixesQueryVersion(g_display, &ver_maj, &ver_min);
g_writeln("xrdp-chansrv: clipboard_init st %d, maj %d min %d", LOG(1, ("clipboard_init st %d, maj %d min %d", st, ver_maj, ver_min));
st, ver_maj, ver_min);
g_screen_num = DefaultScreen(g_display); g_screen_num = DefaultScreen(g_display);
g_screen = ScreenOfDisplay(g_display, g_screen_num); g_screen = ScreenOfDisplay(g_display, g_screen_num);
g_clip_property_atom = XInternAtom(g_display, "XRDP_CLIP_PROPERTY_ATOM", g_clip_property_atom = XInternAtom(g_display, "XRDP_CLIP_PROPERTY_ATOM",
False); False);
g_get_time_atom = XInternAtom(g_display, "XRDP_GET_TIME_ATOM",
False);
g_timestamp_atom = XInternAtom(g_display, "TIMESTAMP", False); g_timestamp_atom = XInternAtom(g_display, "TIMESTAMP", False);
g_targets_atom = XInternAtom(g_display, "TARGETS", False); g_targets_atom = XInternAtom(g_display, "TARGETS", False);
g_multiple_atom = XInternAtom(g_display, "MULTIPLE", False); g_multiple_atom = XInternAtom(g_display, "MULTIPLE", False);
@ -132,7 +145,7 @@ clipboard_init(void)
g_secondary_atom = XInternAtom(g_display, "SECONDARY", False); g_secondary_atom = XInternAtom(g_display, "SECONDARY", False);
g_wnd = XCreateSimpleWindow(g_display, RootWindowOfScreen(g_screen), g_wnd = XCreateSimpleWindow(g_display, RootWindowOfScreen(g_screen),
0, 0, 4, 4, 0, 0, 0); 0, 0, 4, 4, 0, 0, 0);
input_mask = StructureNotifyMask; input_mask = StructureNotifyMask | PropertyChangeMask;
XSelectInput(g_display, g_wnd, input_mask); XSelectInput(g_display, g_wnd, input_mask);
//XMapWindow(g_display, g_wnd); //XMapWindow(g_display, g_wnd);
XFixesSelectSelectionInput(g_display, g_wnd, XFixesSelectSelectionInput(g_display, g_wnd,
@ -151,13 +164,13 @@ clipboard_init(void)
out_uint32_le(s, 0); /* extra 4 bytes ? */ out_uint32_le(s, 0); /* extra 4 bytes ? */
s_mark_end(s); s_mark_end(s);
size = (int)(s->end - s->data); size = (int)(s->end - s->data);
g_writeln("xrdp-chansrv: clipboard_init: data out, sending " LOG(1, ("clipboard_init: data out, sending "
"CLIPRDR_CONNECT (clip_msg_id = 1)"); "CLIPRDR_CONNECT (clip_msg_id = 1)"));
rv = send_channel_data(g_cliprdr_chan_id, s->data, size); rv = send_channel_data(g_cliprdr_chan_id, s->data, size);
if (rv != 0) if (rv != 0)
{ {
g_writeln("xrdp-chansrv: clipboard_init: send_channel_data failed " LOG(0, ("clipboard_init: send_channel_data failed "
"rv = %d", rv); "rv = %d", rv));
rv = 4; rv = 4;
} }
free_stream(s); free_stream(s);
@ -167,8 +180,6 @@ clipboard_init(void)
g_clip_up = 1; g_clip_up = 1;
make_stream(g_ins); make_stream(g_ins);
init_stream(g_ins, 8192) init_stream(g_ins, 8192)
//g_writeln("xrdp-chansrv: clipboard_init: dumping env");
//g_system("env");
} }
return rv; return rv;
} }
@ -202,7 +213,7 @@ clipboard_send_data_request(void)
int rv; int rv;
int num_chars; int num_chars;
g_writeln("xrdp-chansrv: clipboard_send_data_request:"); LOG(1, ("clipboard_send_data_request:"));
make_stream(s); make_stream(s);
init_stream(s, 8192); init_stream(s, 8192);
out_uint16_le(s, 4); /* CLIPRDR_DATA_REQUEST */ out_uint16_le(s, 4); /* CLIPRDR_DATA_REQUEST */
@ -211,8 +222,8 @@ clipboard_send_data_request(void)
out_uint32_le(s, 0x0d); out_uint32_le(s, 0x0d);
s_mark_end(s); s_mark_end(s);
size = (int)(s->end - s->data); size = (int)(s->end - s->data);
g_writeln("xrdp-chansrv: clipboard_send_data_request: data out, sending " LOG(1, ("clipboard_send_data_request: data out, sending "
"CLIPRDR_DATA_REQUEST (clip_msg_id = 4)"); "CLIPRDR_DATA_REQUEST (clip_msg_id = 4)"));
rv = send_channel_data(g_cliprdr_chan_id, s->data, size); rv = send_channel_data(g_cliprdr_chan_id, s->data, size);
free_stream(s); free_stream(s);
return rv; return rv;
@ -234,8 +245,8 @@ clipboard_send_format_ack(void)
out_uint32_le(s, 0); /* extra 4 bytes ? */ out_uint32_le(s, 0); /* extra 4 bytes ? */
s_mark_end(s); s_mark_end(s);
size = (int)(s->end - s->data); size = (int)(s->end - s->data);
g_writeln("xrdp-chansrv: clipboard_send_format_ack: data out, sending " LOG(1, ("clipboard_send_format_ack: data out, sending "
"CLIPRDR_FORMAT_ACK (clip_msg_id = 3)"); "CLIPRDR_FORMAT_ACK (clip_msg_id = 3)"));
rv = send_channel_data(g_cliprdr_chan_id, s->data, size); rv = send_channel_data(g_cliprdr_chan_id, s->data, size);
free_stream(s); free_stream(s);
return rv; return rv;
@ -258,8 +269,8 @@ clipboard_send_format_announce(void)
out_uint8s(s, 0x90); out_uint8s(s, 0x90);
s_mark_end(s); s_mark_end(s);
size = (int)(s->end - s->data); size = (int)(s->end - s->data);
g_writeln("xrdp-chansrv: clipboard_send_format_announce: data out, sending " LOG(1, ("clipboard_send_format_announce: data out, sending "
"CLIPRDR_FORMAT_ANNOUNCE (clip_msg_id = 2)"); "CLIPRDR_FORMAT_ANNOUNCE (clip_msg_id = 2)"));
rv = send_channel_data(g_cliprdr_chan_id, s->data, size); rv = send_channel_data(g_cliprdr_chan_id, s->data, size);
free_stream(s); free_stream(s);
return rv; return rv;
@ -304,22 +315,22 @@ clipboard_send_data_response(void)
int rv; int rv;
int num_chars; int num_chars;
g_writeln("xrdp-chansrv: clipboard_send_data_response:"); LOG(10, ("clipboard_send_data_response:"));
num_chars = 0; num_chars = 0;
if (g_last_clip_data != 0) if (g_last_clip_data != 0)
{ {
if (g_last_clip_type == XA_STRING) if (g_last_clip_type == XA_STRING)
{ {
num_chars = g_mbstowcs(0, g_last_clip_data, 1024); num_chars = g_mbstowcs(0, g_last_clip_data, 0);
if (num_chars < 0) if (num_chars < 0)
{ {
g_writeln("xrdp-chansrv: clipboard_send_data_response: bad string"); LOG(0, ("clipboard_send_data_response: bad string"));
num_chars = 0; num_chars = 0;
} }
} }
} }
g_writeln("xrdp-chansrv: clipboard_send_data_response: g_last_clip_size %d " LOG(10, ("clipboard_send_data_response: g_last_clip_size %d "
"num_chars %d", g_last_clip_size, num_chars); "num_chars %d", g_last_clip_size, num_chars));
make_stream(s); make_stream(s);
init_stream(s, 64 + num_chars * 2); init_stream(s, 64 + num_chars * 2);
out_uint16_le(s, 5); /* CLIPRDR_DATA_RESPONSE */ out_uint16_le(s, 5); /* CLIPRDR_DATA_RESPONSE */
@ -327,15 +338,16 @@ clipboard_send_data_response(void)
out_uint32_le(s, num_chars * 2 + 2); /* length */ out_uint32_le(s, num_chars * 2 + 2); /* length */
if (clipboard_out_unicode(s, g_last_clip_data, num_chars) != num_chars * 2) if (clipboard_out_unicode(s, g_last_clip_data, num_chars) != num_chars * 2)
{ {
g_writeln("xrdp-chansrv: clipboard_send_data_response: error " LOG(0, ("clipboard_send_data_response: error "
"clipboard_out_unicode didn't write right number of bytes"); "clipboard_out_unicode didn't write right number of bytes"));
} }
out_uint16_le(s, 0); /* nil for string */ out_uint16_le(s, 0); /* nil for string */
out_uint32_le(s, 0); out_uint32_le(s, 0);
s_mark_end(s); s_mark_end(s);
size = (int)(s->end - s->data); size = (int)(s->end - s->data);
g_writeln("xrdp-chansrv: clipboard_send_format_announce: data out, sending " LOG(1, ("clipboard_send_data_response: data out, sending "
"CLIPRDR_DATA_RESPONSE (clip_msg_id = 5)"); "CLIPRDR_DATA_RESPONSE (clip_msg_id = 5) size %d num_chars %d",
size, num_chars));
rv = send_channel_data(g_cliprdr_chan_id, s->data, size); rv = send_channel_data(g_cliprdr_chan_id, s->data, size);
free_stream(s); free_stream(s);
return rv; return rv;
@ -346,15 +358,11 @@ static int APP_CC
clipboard_process_format_announce(struct stream* s, int clip_msg_status, clipboard_process_format_announce(struct stream* s, int clip_msg_status,
int clip_msg_len) int clip_msg_len)
{ {
Time now; LOG(1, ("clipboard_process_format_announce: CLIPRDR_FORMAT_ANNOUNCE"));
//g_hexdump(s->p, s->end - s->p);
g_writeln("xrdp-chansrv: clipboard_process_format_announce:");
g_hexdump(s->p, s->end - s->p);
clipboard_send_format_ack(); clipboard_send_format_ack();
g_writeln("------------------------------"); g_selection_time = clipboard_get_time();
now = clipboard_get_time(); XSetSelectionOwner(g_display, g_clipboard_atom, g_wnd, g_selection_time);
XSetSelectionOwner(g_display, g_clipboard_atom, g_wnd, now);
//XSetSelectionOwner(g_display, g_primary_atom, g_wnd, CurrentTime);
return 0; return 0;
} }
@ -363,8 +371,8 @@ static int APP_CC
clipboard_prcoess_format_ack(struct stream* s, int clip_msg_status, clipboard_prcoess_format_ack(struct stream* s, int clip_msg_status,
int clip_msg_len) int clip_msg_len)
{ {
g_writeln("xrdp-chansrv: clipboard_prcoess_format_ack:"); LOG(1, ("clipboard_prcoess_format_ack: CLIPRDR_FORMAT_ACK"));
g_hexdump(s->p, s->end - s->p); //g_hexdump(s->p, s->end - s->p);
return 0; return 0;
} }
@ -373,8 +381,8 @@ static int APP_CC
clipboard_process_data_request(struct stream* s, int clip_msg_status, clipboard_process_data_request(struct stream* s, int clip_msg_status,
int clip_msg_len) int clip_msg_len)
{ {
g_writeln("xrdp-chansrv: clipboard_process_data_request:"); LOG(1, ("clipboard_process_data_request: CLIPRDR_DATA_REQUEST"));
g_hexdump(s->p, s->end - s->p); //g_hexdump(s->p, s->end - s->p);
clipboard_send_data_response(); clipboard_send_data_response();
return 0; return 0;
} }
@ -384,8 +392,8 @@ static int APP_CC
clipboard_process_data_response(struct stream* s, int clip_msg_status, clipboard_process_data_response(struct stream* s, int clip_msg_status,
int clip_msg_len) int clip_msg_len)
{ {
g_writeln("xrdp-chansrv: clipboard_process_data_response:"); LOG(1, ("clipboard_process_data_response: CLIPRDR_DATA_RESPONSE"));
g_hexdump(s->p, s->end - s->p); //g_hexdump(s->p, s->end - s->p);
return 0; return 0;
} }
@ -400,9 +408,9 @@ clipboard_data_in(struct stream* s, int chan_id, int chan_flags, int length,
int rv; int rv;
struct stream* ls; struct stream* ls;
g_writeln("xrdp-chansrv: clipboard_data_in: chan_is %d " LOG(10, ("clipboard_data_in: chan_is %d "
"chan_flags %d length %d total_length %d", "chan_flags %d length %d total_length %d",
chan_id, chan_flags, length, total_length); chan_id, chan_flags, length, total_length));
if ((chan_flags & 3) == 3) if ((chan_flags & 3) == 3)
{ {
ls = s; ls = s;
@ -424,9 +432,9 @@ clipboard_data_in(struct stream* s, int chan_id, int chan_flags, int length,
in_uint16_le(ls, clip_msg_id); in_uint16_le(ls, clip_msg_id);
in_uint16_le(ls, clip_msg_status); in_uint16_le(ls, clip_msg_status);
in_uint32_le(ls, clip_msg_len); in_uint32_le(ls, clip_msg_len);
g_writeln("xrdp-chansrv: clipboard_data_in: clip_msg_id %d " LOG(10, ("clipboard_data_in: clip_msg_id %d "
"clip_msg_status %d clip_msg_len %d", "clip_msg_status %d clip_msg_len %d",
clip_msg_id, clip_msg_status, clip_msg_len); clip_msg_id, clip_msg_status, clip_msg_len));
rv = 0; rv = 0;
switch (clip_msg_id) switch (clip_msg_id)
{ {
@ -447,23 +455,36 @@ clipboard_data_in(struct stream* s, int chan_id, int chan_flags, int length,
clip_msg_len); clip_msg_len);
break; break;
default: default:
g_writeln("xrdp-chansrv: clipboard_data_in: unknown clip_msg_id %d", LOG(0, ("clipboard_data_in: unknown clip_msg_id %d", clip_msg_id));
clip_msg_id);
break; break;
} }
return rv; return rv;
} }
/*****************************************************************************/ /*****************************************************************************/
/* this happens when a new app copies something to the clipboard
'CLIPBOARD' Atom
typedef struct {
int type;
unsigned long serial;
Bool send_event;
Display *display;
Window window;
int subtype;
Window owner;
Atom selection;
Time timestamp;
Time selection_timestamp;
} XFixesSelectionNotifyEvent; */
static int APP_CC static int APP_CC
clipboard_process_selection_owner_notify(XEvent* xevent) clipboard_process_selection_owner_notify(XEvent* xevent)
{ {
XFixesSelectionNotifyEvent* lxevent; XFixesSelectionNotifyEvent* lxevent;
lxevent = (XFixesSelectionNotifyEvent*)xevent; lxevent = (XFixesSelectionNotifyEvent*)xevent;
g_writeln("xrdp-chansrv: clipboard_process_selection_owner_notify: " LOG(1, ("clipboard_process_selection_owner_notify: "
"window %d subtype %d owner %d", "window %d subtype %d owner %d",
lxevent->window, lxevent->subtype, lxevent->owner); lxevent->window, lxevent->subtype, lxevent->owner));
if (lxevent->subtype == 0) if (lxevent->subtype == 0)
{ {
XConvertSelection(g_display, g_clipboard_atom, XA_STRING, XConvertSelection(g_display, g_clipboard_atom, XA_STRING,
@ -474,10 +495,10 @@ clipboard_process_selection_owner_notify(XEvent* xevent)
/*****************************************************************************/ /*****************************************************************************/
/* returns error /* returns error
get a window property from g_wnd */ get a window property from wnd */
static int APP_CC static int APP_CC
clipboard_get_window_property(Atom prop, Atom* type, int* fmt, int* n_items, clipboard_get_window_property(Window wnd, Atom prop, Atom* type, int* fmt,
char** xdata, int* xdata_size) int* n_items, char** xdata, int* xdata_size)
{ {
int lfmt; int lfmt;
int lxdata_size; int lxdata_size;
@ -576,30 +597,30 @@ clipboard_process_selection_notify(XEvent* xevent)
int rv; int rv;
Atom type; Atom type;
LOG(1, ("clipboard_process_selection_notify:"));
rv = 0; rv = 0;
data = 0; data = 0;
type = 0; type = 0;
lxevent = (XSelectionEvent*)xevent; lxevent = (XSelectionEvent*)xevent;
if (lxevent->property == None) if (lxevent->property == None)
{ {
g_writeln("xrdp-chansrv: clipboard_process_selection_notify: clip cound " LOG(0, ("clipboard_process_selection_notify: clip could "
"not be converted"); "not be converted"));
rv = 1; rv = 1;
} }
if (rv == 0) if (rv == 0)
{ {
rv = clipboard_get_window_property(lxevent->property, &type, &fmt, rv = clipboard_get_window_property(g_wnd, lxevent->property, &type, &fmt,
&n_items, &data, &data_size); &n_items, &data, &data_size);
if (rv != 0) if (rv != 0)
{ {
g_writeln("xrdp-chansrv: clipboard_process_selection_notify: " LOG(0, ("clipboard_process_selection_notify: "
"clipboard_get_window_property failed error %d", rv); "clipboard_get_window_property failed error %d", rv));
} }
XDeleteProperty(g_display, g_wnd, g_clip_property_atom);
} }
if (rv == 0) if (rv == 0)
{ {
g_writeln("xrdp-chansrv: clipboard_process_selection_notify: got "
"not be converted");
if (type == XA_STRING) if (type == XA_STRING)
{ {
g_free(g_last_clip_data); g_free(g_last_clip_data);
@ -611,12 +632,11 @@ clipboard_process_selection_notify(XEvent* xevent)
} }
else else
{ {
g_writeln("xrdp-chansrv: clipboard_process_selection_notify: unknown " LOG(0, ("clipboard_process_selection_notify: unknown "
"clipboard data type %d", type); "clipboard data type %d", type));
rv = 3; rv = 3;
} }
} }
XDeleteProperty(g_display, g_wnd, g_clip_property_atom);
if (rv == 0) if (rv == 0)
{ {
if (clipboard_send_format_announce() != 0) if (clipboard_send_format_announce() != 0)
@ -648,37 +668,99 @@ clipboard_process_selection_request(XEvent* xevent)
{ {
XEvent xev; XEvent xev;
XSelectionRequestEvent* lxevent; XSelectionRequestEvent* lxevent;
tui32 ui32[4];
Atom type;
int fmt;
int n_items;
int xdata_size;
char* xdata;
lxevent = (XSelectionRequestEvent*)xevent; lxevent = (XSelectionRequestEvent*)xevent;
g_writeln("xrdp-chansrv: clipboard_process_selection_request: g_wnd %d, " LOG(1, ("clipboard_process_selection_request: g_wnd %d, "
".requestor %d .owner %d .select %d .target %d .property %d", ".requestor %d .owner %d .select %d .target %d .property %d",
g_wnd, lxevent->requestor, lxevent->owner, lxevent->selection, g_wnd, lxevent->requestor, lxevent->owner, lxevent->selection,
lxevent->target, lxevent->property); lxevent->target, lxevent->property));
/* requestor is asking what the selection can be converted to */ if (lxevent->property == None)
if (lxevent->target == g_targets_atom)
{ {
g_writeln("xrdp-chansrv: clipboard_process_selection_request: g_targets_atom"); LOG(1, ("clipboard_process_selection_request: lxevent->property is None"));
}
else if (lxevent->target == g_targets_atom)
{
/* requestor is asking what the selection can be converted to */
LOG(1, ("clipboard_process_selection_request: g_targets_atom"));
ui32[0] = g_targets_atom;
ui32[1] = g_timestamp_atom;
ui32[2] = g_multiple_atom;
ui32[3] = XA_STRING;
XChangeProperty(g_display, lxevent->requestor, lxevent->property,
XA_ATOM, 32, PropModeReplace, (tui8*)ui32, 4);
g_memset(&xev, 0, sizeof(xev));
xev.xselection.type = SelectionNotify;
xev.xselection.serial = 0;
xev.xselection.send_event = True;
xev.xselection.requestor = lxevent->requestor;
xev.xselection.selection = lxevent->selection;
xev.xselection.target = lxevent->target;
xev.xselection.property = lxevent->property;
xev.xselection.time = lxevent->time;
XSendEvent(g_display, lxevent->requestor, False, NoEventMask, &xev);
return 0;
} }
/* requestor is asking the time I got the selection */
else if (lxevent->target == g_timestamp_atom) else if (lxevent->target == g_timestamp_atom)
{ {
g_writeln("xrdp-chansrv: clipboard_process_selection_request: g_timestamp_atom"); /* requestor is asking the time I got the selection */
LOG(1, ("clipboard_process_selection_request: g_timestamp_atom"));
ui32[0] = g_selection_time;
XChangeProperty(g_display, lxevent->requestor, lxevent->property,
XA_INTEGER, 32, PropModeReplace, (tui8*)ui32, 1);
g_memset(&xev, 0, sizeof(xev));
xev.xselection.type = SelectionNotify;
xev.xselection.serial = 0;
xev.xselection.send_event = True;
xev.xselection.requestor = lxevent->requestor;
xev.xselection.selection = lxevent->selection;
xev.xselection.target = lxevent->target;
xev.xselection.property = lxevent->property;
xev.xselection.time = lxevent->time;
XSendEvent(g_display, lxevent->requestor, False, NoEventMask, &xev);
return 0;
} }
else if (lxevent->target == g_multiple_atom) else if (lxevent->target == g_multiple_atom)
{ {
g_writeln("xrdp-chansrv: clipboard_process_selection_request: g_multiple_atom"); /* target, property pairs */
LOG(1, ("clipboard_process_selection_request: g_multiple_atom"));
if (clipboard_get_window_property(xev.xselection.requestor,
xev.xselection.property,
&type, &fmt, &n_items, &xdata,
&xdata_size) == 0)
{
LOG(1, ("clipboard_process_selection_request: g_multiple_atom "
"n_items %d", n_items));
/* todo */
g_free(xdata);
}
} }
else if (lxevent->target == XA_STRING) else if (lxevent->target == XA_STRING)
{ {
g_writeln("xrdp-chansrv: clipboard_process_selection_request: XA_STRING"); LOG(1, ("clipboard_process_selection_request: XA_STRING"));
//XChangeProperty(g_display, lxevent->requestor, lxevent->property, XChangeProperty(g_display, lxevent->requestor, lxevent->property,
// XA_STRING, 8, PropModeReplace, "tes", 4); XA_STRING, 8, PropModeReplace, "test", 5);
//xev.xselection.property = lxevent->property; g_memset(&xev, 0, sizeof(xev));
xev.xselection.type = SelectionNotify;
xev.xselection.serial = 0;
xev.xselection.send_event = True;
xev.xselection.requestor = lxevent->requestor;
xev.xselection.selection = lxevent->selection;
xev.xselection.target = lxevent->target;
xev.xselection.property = lxevent->property;
xev.xselection.time = lxevent->time;
XSendEvent(g_display, lxevent->requestor, False, NoEventMask, &xev);
return 0;
} }
else else
{ {
g_writeln("xrdp-chansrv: clipboard_process_selection_request: unknown " LOG(1, ("clipboard_process_selection_request: unknown "
"target %s", XGetAtomName(g_display, lxevent->target)); "target %s", XGetAtomName(g_display, lxevent->target)));
} }
g_memset(&xev, 0, sizeof(xev)); g_memset(&xev, 0, sizeof(xev));
xev.xselection.type = SelectionNotify; xev.xselection.type = SelectionNotify;
@ -708,7 +790,7 @@ clipboard_process_selection_request(XEvent* xevent)
static int APP_CC static int APP_CC
clipboard_process_selection_clear(XEvent* xevent) clipboard_process_selection_clear(XEvent* xevent)
{ {
g_writeln("xrdp-chansrv: clipboard_process_selection_clear:"); LOG(1, ("clipboard_process_selection_clear:"));
g_got_selection = 0; g_got_selection = 0;
return 0; return 0;
} }
@ -748,7 +830,7 @@ clipboard_check_wait_objs(void)
if (XPending(g_display) < 1) if (XPending(g_display) < 1)
{ {
/* something is wrong, should not get here */ /* something is wrong, should not get here */
g_writeln("xrdp-chansrv: clipboard_check_wait_objs: sck closed"); LOG(0, ("clipboard_check_wait_objs: sck closed"));
return 0; return 0;
} }
while (XPending(g_display) > 0) while (XPending(g_display) > 0)
@ -767,6 +849,8 @@ clipboard_check_wait_objs(void)
break; break;
case MappingNotify: case MappingNotify:
break; break;
case PropertyNotify:
break;
default: default:
if (xevent.type == g_xfixes_event_base + if (xevent.type == g_xfixes_event_base +
XFixesSetSelectionOwnerNotify) XFixesSetSelectionOwnerNotify)
@ -774,8 +858,8 @@ clipboard_check_wait_objs(void)
clipboard_process_selection_owner_notify(&xevent); clipboard_process_selection_owner_notify(&xevent);
break; break;
} }
g_writeln("xrdp-chansrv: clipboard_check_wait_objs unknown type %d", LOG(0, ("clipboard_check_wait_objs unknown type %d",
xevent.type); xevent.type));
break; break;
} }
} }