diff --git a/channels/cliprdr/cliprdr_format.c b/channels/cliprdr/cliprdr_format.c index 166ed112f..3b3835bd9 100644 --- a/channels/cliprdr/cliprdr_format.c +++ b/channels/cliprdr/cliprdr_format.c @@ -132,3 +132,21 @@ void cliprdr_process_format_list(cliprdrPlugin* cliprdr, STREAM* data_in, uint32 svc_plugin_send_event((rdpSvcPlugin*)cliprdr, (FRDP_EVENT*)cb_event); cliprdr_send_format_list_response(cliprdr); } + +void cliprdr_process_format_data_request(cliprdrPlugin* cliprdr, STREAM* data_in) +{ + FRDP_CB_DATA_REQUEST_EVENT* cb_event; + + cb_event = (FRDP_CB_DATA_REQUEST_EVENT*)freerdp_event_new(FRDP_EVENT_TYPE_CB_DATA_REQUEST, NULL, NULL); + stream_read_uint32(data_in, cb_event->format); + svc_plugin_send_event((rdpSvcPlugin*)cliprdr, (FRDP_EVENT*)cb_event); +} + +void cliprdr_process_data_response_event(cliprdrPlugin* cliprdr, FRDP_CB_DATA_RESPONSE_EVENT* cb_event) +{ + STREAM* data_out; + + data_out = cliprdr_packet_new(CB_FORMAT_DATA_RESPONSE, CB_RESPONSE_OK, cb_event->size); + stream_write(data_out, cb_event->data, cb_event->size); + cliprdr_packet_send(cliprdr, data_out); +} diff --git a/channels/cliprdr/cliprdr_format.h b/channels/cliprdr/cliprdr_format.h index 4abddc0e4..6b311dcd8 100644 --- a/channels/cliprdr/cliprdr_format.h +++ b/channels/cliprdr/cliprdr_format.h @@ -24,4 +24,7 @@ void cliprdr_process_format_list_event(cliprdrPlugin* cliprdr, FRDP_CB_FORMAT_LIST_EVENT* cb_event); void cliprdr_process_format_list(cliprdrPlugin* cliprdr, STREAM* data_in, uint32 dataLen); +void cliprdr_process_format_data_request(cliprdrPlugin* cliprdr, STREAM* data_in); +void cliprdr_process_data_response_event(cliprdrPlugin* cliprdr, FRDP_CB_DATA_RESPONSE_EVENT* cb_event); + #endif /* __CLIPRDR_FORMAT_H */ diff --git a/channels/cliprdr/cliprdr_main.c b/channels/cliprdr/cliprdr_main.c index 94fbe7f33..9d233ed7e 100644 --- a/channels/cliprdr/cliprdr_main.c +++ b/channels/cliprdr/cliprdr_main.c @@ -126,6 +126,10 @@ static void cliprdr_process_receive(rdpSvcPlugin* plugin, STREAM* data_in) case CB_FORMAT_LIST_RESPONSE: break; + case CB_FORMAT_DATA_REQUEST: + cliprdr_process_format_data_request(cliprdr, data_in); + break; + default: DEBUG_WARN("unknown msgType %d", msgType); break; @@ -142,6 +146,10 @@ static void cliprdr_process_event(rdpSvcPlugin* plugin, FRDP_EVENT* event) cliprdr_process_format_list_event((cliprdrPlugin*)plugin, (FRDP_CB_FORMAT_LIST_EVENT*)event); break; + case FRDP_EVENT_TYPE_CB_DATA_RESPONSE: + cliprdr_process_data_response_event((cliprdrPlugin*)plugin, (FRDP_CB_DATA_RESPONSE_EVENT*)event); + break; + default: DEBUG_WARN("unknown event type %d", event->event_type); break; diff --git a/cunit/test_cliprdr.c b/cunit/test_cliprdr.c index f7cc1252e..7596e44e1 100644 --- a/cunit/test_cliprdr.c +++ b/cunit/test_cliprdr.c @@ -25,6 +25,7 @@ #include #include #include +#include #include "test_cliprdr.h" @@ -74,6 +75,17 @@ static const uint8 test_format_list_response_data[] = "\x03\x00\x01\x00\x00\x00\x00\x00" }; +static const uint8 test_data_request_data[] = +{ + "\x04\x00\x00\x00\x04\x00\x00\x00\x01\x00\x00\x00" +}; + +static const uint8 test_data_response_data[] = +{ + "\x05\x00\x01\x00\x18\x00\x00\x00\x68\x00\x65\x00\x6C\x00\x6C\x00" + "\x6F\x00\x20\x00\x77\x00\x6F\x00\x72\x00\x6c\x00\x64\x00\x00\x00" +}; + static int test_rdp_channel_data(rdpInst* inst, int chan_id, char* data, int data_size) { printf("chan_id %d data_size %d\n", chan_id, data_size); @@ -95,6 +107,8 @@ void test_cliprdr(void) rdpInst inst = { 0 }; FRDP_EVENT* event; FRDP_CB_FORMAT_LIST_EVENT* format_list_event; + FRDP_CB_DATA_REQUEST_EVENT* data_request_event; + FRDP_CB_DATA_RESPONSE_EVENT* data_response_event; int i; settings.hostname = "testhost"; @@ -162,6 +176,39 @@ void test_cliprdr(void) } freerdp_event_free(event); + /* server sends data request PDU to cliprdr */ + freerdp_chanman_data(&inst, 0, (char*)test_data_request_data, sizeof(test_data_request_data) - 1, + CHANNEL_FLAG_FIRST | CHANNEL_FLAG_LAST, sizeof(test_data_request_data) - 1); + + /* cliprdr sends data request event to UI */ + while ((event = freerdp_chanman_pop_event(chan_man)) == NULL) + { + freerdp_chanman_check_fds(chan_man, &inst); + } + printf("Got event %d\n", event->event_type); + CU_ASSERT(event->event_type == FRDP_EVENT_TYPE_CB_DATA_REQUEST); + if (event->event_type == FRDP_EVENT_TYPE_CB_DATA_REQUEST) + { + data_request_event = (FRDP_CB_DATA_REQUEST_EVENT*)event; + printf("Requested format: 0x%X\n", data_request_event->format); + } + freerdp_event_free(event); + + /* UI sends data response event to cliprdr */ + event = freerdp_event_new(FRDP_EVENT_TYPE_CB_DATA_RESPONSE, event_process_callback, NULL); + data_response_event = (FRDP_CB_DATA_RESPONSE_EVENT*)event; + data_response_event->data = (uint8*)xmalloc(6); + strcpy(data_response_event->data, "hello"); + data_response_event->size = 6; + event_processed = 0; + freerdp_chanman_send_event(chan_man, "cliprdr", event); + + /* cliprdr sends data response PDU to server */ + while (!event_processed) + { + freerdp_chanman_check_fds(chan_man, &inst); + } + freerdp_chanman_close(chan_man, &inst); freerdp_chanman_free(chan_man); }