void test_drdynvc(void) { rdpChanMan* chan_man; rdpSettings settings = { 0 }; freerdp instance = { 0 }; settings.hostname = "testhost"; instance.settings = &settings; instance.ChannelDataInput = test_rdp_channel_data; chan_man = freerdp_chanman_new(); freerdp_chanman_load_plugin(chan_man, &settings, "../channels/drdynvc/drdynvc.so", NULL); freerdp_chanman_pre_connect(chan_man, &instance); freerdp_chanman_post_connect(chan_man, &instance); /* server sends capability request PDU */ freerdp_chanman_data(&instance, 0, (char*)test_capability_request_data, sizeof(test_capability_request_data) - 1, CHANNEL_FLAG_FIRST | CHANNEL_FLAG_LAST, sizeof(test_capability_request_data) - 1); /* drdynvc sends capability response PDU to server */ data_received = 0; while (!data_received) { freerdp_chanman_check_fds(chan_man, &instance); } freerdp_chanman_close(chan_man, &instance); freerdp_chanman_free(chan_man); }
void freerdp_chanman_close(rdpChanMan* chan_man, freerdp* instance) { int index; struct lib_data* llib; DEBUG_CHANMAN("closing"); chan_man->is_connected = 0; freerdp_chanman_check_fds(chan_man, instance); /* tell all libraries we are shutting down */ for (index = 0; index < chan_man->num_libs; index++) { llib = chan_man->libs + index; if (llib->init_event_proc != 0) { llib->init_event_proc(llib->init_handle, CHANNEL_EVENT_TERMINATED, 0, 0); } } }
//----------------------------------------------------------------------------- static void process_events_and_channel_data_from_plugin(thread_param* param) { FRDP_EVENT* event; param->th_count++; while (param->th_to_finish == 0) { freerdp_chanman_check_fds(param->chan_man, param->instance); event = freerdp_chanman_pop_event(param->chan_man); if (event) { DEBUG_RAIL("UI receive %d event.", event->event_type); debug_event(event); // add to global event list freerdp_event_free(event); } usleep(1000); } param->th_count--; }
static int run_dfbfreerdp(rdpSet * settings, rdpChanMan * chan_man) { rdpInst * inst; void * dfb_info; void * read_fds[32]; void * write_fds[32]; int read_count; int write_count; int index; int sck; int max_sck; fd_set rfds; fd_set wfds; memset(read_fds, 0, sizeof(read_fds)); memset(write_fds, 0, sizeof(write_fds)); printf("run_dfbfreerdp:\n"); /* create an instance of the library */ inst = freerdp_new(settings); if (inst == NULL) { printf("run_dfbfreerdp: freerdp_new failed\n"); return 1; } if ((inst->version != FREERDP_INTERFACE_VERSION) || (inst->size != sizeof(rdpInst))) { printf("run_dfbfreerdp: freerdp_new size, version / size do not " "match expecting v %d s %d got v %d s %d\n", FREERDP_INTERFACE_VERSION, (int)sizeof(rdpInst), inst->version, inst->size); return 1; } if (dfb_pre_connect(inst) != 0) { printf("run_dfbfreerdp: dfb_pre_connect failed\n"); return 1; } if (freerdp_chanman_pre_connect(chan_man, inst) != 0) { printf("run_dfbfreerdp: freerdp_chanman_pre_connect failed\n"); return 1; } /* call connect */ printf("keyboard_layout: %X\n", inst->settings->keyboard_layout); if (inst->rdp_connect(inst) != 0) { printf("run_dfbfreerdp: inst->rdp_connect failed\n"); return 1; } if (freerdp_chanman_post_connect(chan_man, inst) != 0) { printf("run_dfbfreerdp: freerdp_chanman_post_connect failed\n"); return 1; } if (dfb_post_connect(inst) != 0) { printf("run_dfbfreerdp: dfb_post_connect failed\n"); return 1; } /* program main loop */ while (1) { read_count = 0; write_count = 0; /* get libfreerdp fds */ if (inst->rdp_get_fds(inst, read_fds, &read_count, write_fds, &write_count) != 0) { printf("run_dfbfreerdp: inst->rdp_get_fds failed\n"); break; } /* get DirectFB fds */ if (dfb_get_fds(inst, read_fds, &read_count, write_fds, &write_count) != 0) { printf("run_dfbfreerdp: dfb_get_fds failed\n"); break; } /* get channel fds */ if (freerdp_chanman_get_fds(chan_man, inst, read_fds, &read_count, write_fds, &write_count) != 0) { printf("run_dfbfreerdp: freerdp_chanman_get_fds failed\n"); break; } max_sck = 0; /* setup read fds */ FD_ZERO(&rfds); for (index = 0; index < read_count; index++) { sck = (int)(long) (read_fds[index]); if (sck > max_sck) max_sck = sck; FD_SET(sck, &rfds); } /* setup write fds */ FD_ZERO(&wfds); for (index = 0; index < write_count; index++) { sck = (int)(long) (write_fds[index]); if (sck > max_sck) max_sck = sck; FD_SET(sck, &wfds); } /* exit if nothing to do */ if (max_sck == 0) { printf("run_dfbfreerdp: max_sck is zero\n"); break; } /* do the wait */ if (select(max_sck + 1, &rfds, &wfds, NULL, NULL) == -1) { /* these are not really errors */ if (!((errno == EAGAIN) || (errno == EWOULDBLOCK) || (errno == EINPROGRESS) || (errno == EINTR))) /* signal occurred */ { printf("run_dfbfreerdp: select failed\n"); break; } } /* check the libfreerdp fds */ if (inst->rdp_check_fds(inst) != 0) { printf("run_dfbfreerdp: inst->rdp_check_fds failed\n"); break; } /* check DirectFB fds */ if (dfb_check_fds(inst, &rfds) != 0) { printf("run_dfbfreerdp: dfb_check_fds failed\n"); break; } /* check channel fds */ if (freerdp_chanman_check_fds(chan_man, inst) != 0) { printf("run_dfbfreerdp: freerdp_chanman_check_fds failed\n"); break; } } /* cleanup */ dfb_info = inst->param1; inst->rdp_disconnect(inst); freerdp_free(inst); dfb_uninit(dfb_info); return 0; }
static int run_wfreerdp(wfInfo * wfi) { rdpInst * inst; void * read_fds[32]; void * write_fds[32]; int read_count; int write_count; int index; HANDLE fds[64]; int fds_count; int gmcode; int alldone; MSG msg; DEBUG("run_wfreerdp:\n"); /* create an instance of the library */ wfi->inst = inst = freerdp_new(wfi->settings); if (inst == NULL) { printf("run_wfreerdp: freerdp_new failed\n"); return 1; } SET_WFI(inst, wfi); if ((inst->version != FREERDP_INTERFACE_VERSION) || (inst->size != sizeof(rdpInst))) { printf("run_wfreerdp: freerdp_new size, version / size do not " "match expecting v %d s %d got v %d s %d\n", FREERDP_INTERFACE_VERSION, sizeof(rdpInst), inst->version, inst->size); return 1; } inst->settings->keyboard_layout = (int)GetKeyboardLayout(0) & 0x0000FFFF; printf("keyboard_layout: 0x%X\n", inst->settings->keyboard_layout); if (wf_pre_connect(wfi) != 0) { printf("run_wfreerdp: wf_pre_connect failed\n"); return 1; } if (freerdp_chanman_pre_connect(wfi->chan_man, inst) != 0) { printf("run_wfreerdp: freerdp_chanman_pre_connect failed\n"); return 1; } /* call connect */ if (inst->rdp_connect(inst) != 0) { printf("run_wfreerdp: inst->rdp_connect failed\n"); return 1; } if (freerdp_chanman_post_connect(wfi->chan_man, inst) != 0) { printf("run_wfreerdp: freerdp_chanman_post_connect failed\n"); return 1; } if (wf_post_connect(wfi) != 0) { printf("run_wfreerdp: wf_post_connect failed\n"); return 1; } /* program main loop */ while (1) { read_count = 0; write_count = 0; /* get libfreerdp fds */ if (inst->rdp_get_fds(inst, read_fds, &read_count, write_fds, &write_count) != 0) { printf("run_wfreerdp: inst->rdp_get_fds failed\n"); break; } /* get channel fds */ if (freerdp_chanman_get_fds(wfi->chan_man, inst, read_fds, &read_count, write_fds, &write_count) != 0) { printf("run_wfreerdp: freerdp_chanman_get_fds failed\n"); break; } fds_count = 0; /* setup read fds */ for (index = 0; index < read_count; index++) { fds[fds_count++] = read_fds[index]; } /* setup write fds */ for (index = 0; index < write_count; index++) { fds[fds_count++] = write_fds[index]; } /* exit if nothing to do */ if (fds_count == 0) { printf("run_wfreerdp: fds_count is zero\n"); break; } /* do the wait */ if (MsgWaitForMultipleObjects(fds_count, fds, FALSE, INFINITE, QS_ALLINPUT) == WAIT_FAILED) { printf("run_wfreerdp: WaitForMultipleObjects failed\n"); break; } /* check the libfreerdp fds */ if (inst->rdp_check_fds(inst) != 0) { printf("run_wfreerdp: inst->rdp_check_fds failed\n"); break; } /* check channel fds */ if (freerdp_chanman_check_fds(wfi->chan_man, inst) != 0) { printf("run_wfreerdp: freerdp_chanman_check_fds failed\n"); break; } alldone = FALSE; while (PeekMessage(&msg, 0, 0, 0, PM_NOREMOVE)) { gmcode = GetMessage(&msg, 0, 0, 0); if (gmcode == 0 || gmcode == -1) { alldone = TRUE; break; } TranslateMessage(&msg); DispatchMessage(&msg); } if (alldone) { break; } } /* cleanup */ wf_uninit(wfi); freerdp_chanman_free(wfi->chan_man); freerdp_free(inst); free(wfi->settings); free(wfi); return 0; }
int tfreerdp_run(freerdp* instance) { int i; int fds; int max_fds; int rcount; int wcount; void* rfds[32]; void* wfds[32]; fd_set rfds_set; fd_set wfds_set; rdpChanMan* chanman; memset(rfds, 0, sizeof(rfds)); memset(wfds, 0, sizeof(wfds)); chanman = GET_CHANMAN(instance); instance->Connect(instance); while (1) { rcount = 0; wcount = 0; if (instance->GetFileDescriptor(instance, rfds, &rcount, wfds, &wcount) != True) { printf("Failed to get FreeRDP file descriptor\n"); break; } if (freerdp_chanman_get_fds(chanman, instance, rfds, &rcount, wfds, &wcount) != True) { printf("Failed to get channel manager file descriptor\n"); break; } max_fds = 0; FD_ZERO(&rfds_set); for (i = 0; i < rcount; i++) { fds = (int)(long)(rfds[i]); if (fds > max_fds) max_fds = fds; FD_SET(fds, &rfds_set); } if (max_fds == 0) break; if (select(max_fds + 1, &rfds_set, &wfds_set, NULL, NULL) == -1) { /* these are not really errors */ if (!((errno == EAGAIN) || (errno == EWOULDBLOCK) || (errno == EINPROGRESS) || (errno == EINTR))) /* signal occurred */ { printf("tfreerdp_run: select failed\n"); break; } } if (instance->CheckFileDescriptor(instance) != True) { printf("Failed to check FreeRDP file descriptor\n"); break; } if (freerdp_chanman_check_fds(chanman, instance) != True) { printf("Failed to check channel manager file descriptor\n"); break; } tf_process_channel_event(chanman, instance); } freerdp_chanman_close(chanman, instance); freerdp_chanman_free(chanman); freerdp_free(instance); return 0; }
void test_cliprdr(void) { int i; rdpChanMan* chan_man; rdpSettings settings = { 0 }; freerdp instance = { 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; settings.hostname = "testhost"; instance.settings = &settings; instance.SendChannelData = test_rdp_channel_data; chan_man = freerdp_chanman_new(); freerdp_chanman_load_plugin(chan_man, &settings, "../channels/cliprdr/cliprdr.so", NULL); freerdp_chanman_pre_connect(chan_man, &instance); freerdp_chanman_post_connect(chan_man, &instance); /* server sends cliprdr capabilities and monitor ready PDU */ freerdp_chanman_data(&instance, 0, (char*)test_clip_caps_data, sizeof(test_clip_caps_data) - 1, CHANNEL_FLAG_FIRST | CHANNEL_FLAG_LAST, sizeof(test_clip_caps_data) - 1); freerdp_chanman_data(&instance, 0, (char*)test_monitor_ready_data, sizeof(test_monitor_ready_data) - 1, CHANNEL_FLAG_FIRST | CHANNEL_FLAG_LAST, sizeof(test_monitor_ready_data) - 1); /* cliprdr sends clipboard_sync event to UI */ while ((event = freerdp_chanman_pop_event(chan_man)) == NULL) { freerdp_chanman_check_fds(chan_man, &instance); } printf("Got event %d\n", event->event_type); CU_ASSERT(event->event_type == FRDP_EVENT_TYPE_CB_SYNC); freerdp_event_free(event); /* UI sends format_list event to cliprdr */ event = freerdp_event_new(FRDP_EVENT_TYPE_CB_FORMAT_LIST, event_process_callback, NULL); format_list_event = (FRDP_CB_FORMAT_LIST_EVENT*)event; format_list_event->num_formats = 2; format_list_event->formats = (uint32*)xmalloc(sizeof(uint32) * 2); format_list_event->formats[0] = CB_FORMAT_TEXT; format_list_event->formats[1] = CB_FORMAT_HTML; event_processed = 0; freerdp_chanman_send_event(chan_man, "cliprdr", event); /* cliprdr sends format list PDU to server */ while (!event_processed) { freerdp_chanman_check_fds(chan_man, &instance); } /* server sends format list response PDU to cliprdr */ freerdp_chanman_data(&instance, 0, (char*)test_format_list_response_data, sizeof(test_format_list_response_data) - 1, CHANNEL_FLAG_FIRST | CHANNEL_FLAG_LAST, sizeof(test_format_list_response_data) - 1); /* server sends format list PDU to cliprdr */ freerdp_chanman_data(&instance, 0, (char*)test_format_list_data, sizeof(test_format_list_data) - 1, CHANNEL_FLAG_FIRST | CHANNEL_FLAG_LAST, sizeof(test_format_list_data) - 1); /* cliprdr sends format_list event to UI */ while ((event = freerdp_chanman_pop_event(chan_man)) == NULL) { freerdp_chanman_check_fds(chan_man, &instance); } printf("Got event %d\n", event->event_type); CU_ASSERT(event->event_type == FRDP_EVENT_TYPE_CB_FORMAT_LIST); if (event->event_type == FRDP_EVENT_TYPE_CB_FORMAT_LIST) { format_list_event = (FRDP_CB_FORMAT_LIST_EVENT*)event; for (i = 0; i < format_list_event->num_formats; i++) printf("Format: 0x%X\n", format_list_event->formats[i]); } freerdp_event_free(event); /* server sends data request PDU to cliprdr */ freerdp_chanman_data(&instance, 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, &instance); } 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((char*)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, &instance); } /* UI sends data request event to cliprdr */ event = freerdp_event_new(FRDP_EVENT_TYPE_CB_DATA_REQUEST, event_process_callback, NULL); data_request_event = (FRDP_CB_DATA_REQUEST_EVENT*)event; data_request_event->format = CB_FORMAT_UNICODETEXT; event_processed = 0; freerdp_chanman_send_event(chan_man, "cliprdr", event); /* cliprdr sends data request PDU to server */ while (!event_processed) { freerdp_chanman_check_fds(chan_man, &instance); } /* server sends data response PDU to cliprdr */ freerdp_chanman_data(&instance, 0, (char*)test_data_response_data, sizeof(test_data_response_data) - 1, CHANNEL_FLAG_FIRST | CHANNEL_FLAG_LAST, sizeof(test_data_response_data) - 1); /* cliprdr sends data response event to UI */ while ((event = freerdp_chanman_pop_event(chan_man)) == NULL) { freerdp_chanman_check_fds(chan_man, &instance); } printf("Got event %d\n", event->event_type); CU_ASSERT(event->event_type == FRDP_EVENT_TYPE_CB_DATA_RESPONSE); if (event->event_type == FRDP_EVENT_TYPE_CB_DATA_RESPONSE) { data_response_event = (FRDP_CB_DATA_RESPONSE_EVENT*)event; printf("Data response size: %d\n", data_response_event->size); freerdp_hexdump(data_response_event->data, data_response_event->size); } freerdp_event_free(event); freerdp_chanman_close(chan_man, &instance); freerdp_chanman_free(chan_man); }
static int run_xfreerdp(xfInfo * xfi) { rdpInst * inst; void * read_fds[32]; void * write_fds[32]; int read_count; int write_count; int index; int sck; int max_sck; fd_set rfds; fd_set wfds; RD_EVENT * event; /* create an instance of the library */ inst = freerdp_new(xfi->settings); if (inst == NULL) { printf("run_xfreerdp: freerdp_new failed\n"); return XF_EXIT_MEMORY; } if ((inst->version != FREERDP_INTERFACE_VERSION) || (inst->size != sizeof(rdpInst))) { printf("run_xfreerdp: freerdp_new size, version / size do not " "match expecting v %d s %d got v %d s %d\n", FREERDP_INTERFACE_VERSION, (int)sizeof(rdpInst), inst->version, inst->size); return XF_EXIT_PROTOCOL; } xfi->inst = inst; SET_XFI(inst, xfi); if (xf_pre_connect(xfi) != 0) { printf("run_xfreerdp: xf_pre_connect failed\n"); return XF_EXIT_CONN_FAILED; } if (freerdp_chanman_pre_connect(xfi->chan_man, inst) != 0) { printf("run_xfreerdp: freerdp_chanman_pre_connect failed\n"); return XF_EXIT_CONN_FAILED; } xf_kb_init(xfi->display, xfi->keyboard_layout_id); xf_kb_inst_init(xfi); printf("keyboard_layout: 0x%X\n", inst->settings->keyboard_layout); /* call connect */ if (inst->rdp_connect(inst) != 0) { printf("run_xfreerdp: inst->rdp_connect failed\n"); return XF_EXIT_CONN_FAILED; } if (freerdp_chanman_post_connect(xfi->chan_man, inst) != 0) { printf("run_xfreerdp: freerdp_chanman_post_connect failed\n"); return XF_EXIT_CONN_FAILED; } if (xf_post_connect(xfi) != 0) { printf("run_xfreerdp: xf_post_connect failed\n"); return XF_EXIT_CONN_FAILED; } xf_video_init(xfi); xf_decode_init(xfi); /* program main loop */ while (1) { read_count = 0; write_count = 0; /* get libfreerdp fds */ if (inst->rdp_get_fds(inst, read_fds, &read_count, write_fds, &write_count) != 0) { printf("run_xfreerdp: inst->rdp_get_fds failed\n"); break; } /* get x fds */ if (xf_get_fds(xfi, read_fds, &read_count, write_fds, &write_count) != 0) { printf("run_xfreerdp: xf_get_fds failed\n"); break; } /* get channel fds */ if (freerdp_chanman_get_fds(xfi->chan_man, inst, read_fds, &read_count, write_fds, &write_count) != 0) { printf("run_xfreerdp: freerdp_chanman_get_fds failed\n"); break; } max_sck = 0; /* setup read fds */ FD_ZERO(&rfds); for (index = 0; index < read_count; index++) { sck = (int)(long) (read_fds[index]); if (sck > max_sck) max_sck = sck; FD_SET(sck, &rfds); } /* setup write fds */ FD_ZERO(&wfds); for (index = 0; index < write_count; index++) { sck = (int)(long) (write_fds[index]); if (sck > max_sck) max_sck = sck; FD_SET(sck, &wfds); } /* exit if nothing to do */ if (max_sck == 0) { printf("run_xfreerdp: max_sck is zero\n"); break; } /* do the wait */ if (select(max_sck + 1, &rfds, &wfds, NULL, NULL) == -1) { /* these are not really errors */ if (!((errno == EAGAIN) || (errno == EWOULDBLOCK) || (errno == EINPROGRESS) || (errno == EINTR))) /* signal occurred */ { printf("run_xfreerdp: select failed\n"); break; } } /* check the libfreerdp fds */ if (inst->rdp_check_fds(inst) != 0) { printf("run_xfreerdp: inst->rdp_check_fds failed\n"); break; } /* check x fds */ if (xf_check_fds(xfi) != 0) { /* xfreerdp is usually terminated by this failing because the X windows has been closed */ DEBUG_X11("xf_check_fds failed"); break; } /* check channel fds */ if (freerdp_chanman_check_fds(xfi->chan_man, inst) != 0) { printf("run_xfreerdp: freerdp_chanman_check_fds failed\n"); break; } /* check channel event */ event = freerdp_chanman_pop_event(xfi->chan_man); if (event) { switch (event->event_type) { case RD_EVENT_TYPE_VIDEO_FRAME: xf_video_process_frame(xfi, (RD_VIDEO_FRAME_EVENT *) event); break; case RD_EVENT_TYPE_REDRAW: xf_handle_redraw_event(xfi, (RD_REDRAW_EVENT *) event); break; default: printf("run_xfreerdp: unknown event type %d\n", event->event_type); break; } freerdp_chanman_free_event(xfi->chan_man, event); } } g_disconnect_reason = inst->disc_reason; /* cleanup */ xf_decode_uninit(xfi); xf_video_uninit(xfi); freerdp_chanman_close(xfi->chan_man, inst); inst->rdp_disconnect(inst); freerdp_free(inst); xf_uninit(xfi); return 0; }