/* this registers two channels but only cliprdr is used */ int VirtualChannelEntry(PCHANNEL_ENTRY_POINTS pEntryPoints) { cliprdrPlugin * plugin; LLOGLN(10, ("VirtualChannelEntry:")); plugin = (cliprdrPlugin *) malloc(sizeof(cliprdrPlugin)); memset(plugin, 0, sizeof(cliprdrPlugin)); chan_plugin_init((rdpChanPlugin *) plugin); plugin->data_in_size = 0; plugin->data_in = 0; plugin->ep = *pEntryPoints; memset(&(plugin->channel_def), 0, sizeof(plugin->channel_def)); plugin->channel_def.options = CHANNEL_OPTION_INITIALIZED | CHANNEL_OPTION_ENCRYPT_RDP | CHANNEL_OPTION_COMPRESS_RDP | CHANNEL_OPTION_SHOW_PROTOCOL; strcpy(plugin->channel_def.name, "cliprdr"); plugin->in_mutex = (pthread_mutex_t *) malloc(sizeof(pthread_mutex_t)); pthread_mutex_init(plugin->in_mutex, 0); plugin->in_list_head = 0; plugin->in_list_tail = 0; plugin->term_event = wait_obj_new("freerdpcliprdrterm"); plugin->data_in_event = wait_obj_new("freerdpcliprdrdatain"); plugin->ep.pVirtualChannelInit(&plugin->chan_plugin.init_handle, &plugin->channel_def, 1, VIRTUAL_CHANNEL_VERSION_WIN2000, InitEvent); plugin->device_data = clipboard_new(plugin); return 1; }
freerdp_thread* freerdp_thread_new(void) { freerdp_thread* thread; thread = xnew(freerdp_thread); thread->mutex = freerdp_mutex_new(); thread->signals[0] = wait_obj_new(); thread->signals[1] = wait_obj_new(); thread->num_signals = 2; return thread; }
freerdp_thread* freerdp_thread_new(void) { freerdp_thread* thread; thread = xnew(freerdp_thread); thread->mutex = CreateMutex(NULL, FALSE, NULL); thread->signals[0] = wait_obj_new(); thread->signals[1] = wait_obj_new(); thread->num_signals = 2; return thread; }
/* * Used for opening channel and sent to core channel pointer to RAIL session. * * Main difference between core channels and plugin channels is time of * calling plugin 'VirtualChannelEntry'. * For plugin 'VirtualChannelEntry' is called when rdpInst for channel manager * is not yet defined. So we can't link it with rdp session. * * For core virtual channels 'VirtualChannelEntry' is called when rdpInst * linked with channel manager in 'freerdp_chanman_pre_connect' routine by * library consumer (in UI). * * So on this stage all rdpInst structure already builded, so we can call * core function for linking with RAIL session structure. */ int RailCoreVirtualChannelEntry(PCHANNEL_ENTRY_POINTS pEntryPoints) { railCorePlugin * plugin; LLOGLN(10, ("rail_core_plugin:Rail Core plugin VirtualChannelEntry:")); plugin = (railCorePlugin *) malloc(sizeof(railCorePlugin)); memset(plugin, 0, sizeof(railCorePlugin)); chan_plugin_init((rdpChanPlugin *) plugin); plugin->data_in_size = 0; plugin->data_in = NULL; plugin->ep = *pEntryPoints; memset(&(plugin->channel_def), 0, sizeof(plugin->channel_def)); plugin->channel_def.options = CHANNEL_OPTION_INITIALIZED | CHANNEL_OPTION_ENCRYPT_RDP | CHANNEL_OPTION_COMPRESS_RDP | CHANNEL_OPTION_SHOW_PROTOCOL; strcpy(plugin->channel_def.name, "rail"); plugin->in_mutex = (pthread_mutex_t *) malloc(sizeof(pthread_mutex_t)); pthread_mutex_init(plugin->in_mutex, 0); plugin->in_list_head = NULL; plugin->in_list_tail = NULL; plugin->term_event = wait_obj_new("freerdprailterm"); plugin->data_in_event = wait_obj_new("freerdpraildatain"); plugin->session = NULL; if (pEntryPoints->cbSize >= sizeof(CHANNEL_ENTRY_POINTS_EX)) { RAIL_VCHANNEL_SENDER sender = {0}; sender.sender_object = plugin; sender.send_rail_vchannel_data = rail_core_plugin_send_rail_vchannel_data; plugin->session = (((PCHANNEL_ENTRY_POINTS_EX)pEntryPoints)->pExtendedData); rail_register_channel_sender(plugin->session, &sender); plugin->ep.pVirtualChannelInit(&plugin->chan_plugin.init_handle, &plugin->channel_def, 1, VIRTUAL_CHANNEL_VERSION_WIN2000, InitEvent); } return 1; }
rdpTransport* transport_new(rdpSettings* settings) { rdpTransport* transport; transport = (rdpTransport*) xzalloc(sizeof(rdpTransport)); if (transport != NULL) { transport->tcp = tcp_new(settings); transport->settings = settings; /* a small 0.1ms delay when transport is blocking. */ transport->usleep_interval = 100; /* receive buffer for non-blocking read. */ transport->recv_buffer = stream_new(BUFFER_SIZE); transport->recv_event = wait_obj_new(); /* buffers for blocking read/write */ transport->recv_stream = stream_new(BUFFER_SIZE); transport->send_stream = stream_new(BUFFER_SIZE); transport->blocking = True; transport->layer = TRANSPORT_LAYER_TCP; } return transport; }
int VirtualChannelEntry(PCHANNEL_ENTRY_POINTS pEntryPoints) { drdynvcPlugin * plugin; RD_PLUGIN_DATA * data; LLOGLN(10, ("VirtualChannelEntry:")); plugin = (drdynvcPlugin *) malloc(sizeof(drdynvcPlugin)); memset(plugin, 0, sizeof(drdynvcPlugin)); chan_plugin_init((rdpChanPlugin *) plugin); plugin->data_in_size = 0; plugin->data_in = 0; plugin->ep = *pEntryPoints; memset(&(plugin->channel_def), 0, sizeof(plugin->channel_def)); plugin->channel_def.options = CHANNEL_OPTION_INITIALIZED | CHANNEL_OPTION_ENCRYPT_RDP | CHANNEL_OPTION_COMPRESS_RDP; strcpy(plugin->channel_def.name, "drdynvc"); plugin->in_mutex = (pthread_mutex_t *) malloc(sizeof(pthread_mutex_t)); pthread_mutex_init(plugin->in_mutex, 0); plugin->in_list_head = 0; plugin->in_list_tail = 0; plugin->term_event = wait_obj_new("freerdprdrynvcterm"); plugin->data_in_event = wait_obj_new("freerdpdrdynvcdatain"); plugin->thread_status = 0; plugin->ep.pVirtualChannelInit(&plugin->chan_plugin.init_handle, &plugin->channel_def, 1, VIRTUAL_CHANNEL_VERSION_WIN2000, InitEvent); plugin->channel_mgr = dvcman_new(plugin); if (pEntryPoints->cbSize >= sizeof(CHANNEL_ENTRY_POINTS_EX)) { data = (RD_PLUGIN_DATA *) (((PCHANNEL_ENTRY_POINTS_EX)pEntryPoints)->pExtendedData); while (data && data->size > 0) { dvcman_load_plugin(plugin->channel_mgr, (char*)data->data[0]); data = (RD_PLUGIN_DATA *) (((void *) data) + data->size); } } return 1; }
WTSVirtualChannelManager* WTSCreateVirtualChannelManager(freerdp_peer* client) { WTSVirtualChannelManager* vcm; vcm = xnew(WTSVirtualChannelManager); if (vcm != NULL) { vcm->client = client; vcm->send_event = wait_obj_new(); vcm->send_queue = list_new(); vcm->mutex = freerdp_mutex_new(); client->ReceiveChannelData = WTSReceiveChannelData; } return vcm; }
WTSVirtualChannelManager* WTSCreateVirtualChannelManager(freerdp_peer* client) { WTSVirtualChannelManager* vcm; vcm = xnew(WTSVirtualChannelManager); if (vcm != NULL) { vcm->client = client; vcm->send_event = wait_obj_new(); vcm->send_queue = list_new(); vcm->mutex = CreateMutex(NULL, FALSE, NULL); vcm->dvc_channel_id_seq = 1; vcm->dvc_channel_list = list_new(); client->ReceiveChannelData = WTSReceiveChannelData; } return vcm; }
void test_wait_obj(void) { struct wait_obj* wo; int set; wo = wait_obj_new(); set = wait_obj_is_set(wo); CU_ASSERT(set == 0); wait_obj_set(wo); set = wait_obj_is_set(wo); CU_ASSERT(set == 1); wait_obj_clear(wo); set = wait_obj_is_set(wo); CU_ASSERT(set == 0); wait_obj_select(&wo, 1, 1000); wait_obj_free(wo); }
rdpChanMan* freerdp_chanman_new(void) { rdpChanMan* chan_man; rdpChanManList* list; chan_man = xnew(rdpChanMan); chan_man->sync_data_sem = freerdp_sem_new(1); chan_man->event_sem = freerdp_sem_new(1); chan_man->signal = wait_obj_new(); /* Add it to the global list */ list = xnew(rdpChanManList); list->chan_man = chan_man; freerdp_mutex_lock(g_mutex_list); list->next = g_chan_man_list; g_chan_man_list = list; freerdp_mutex_unlock(g_mutex_list); return chan_man; }
int DeviceServiceEntry(PDEVICE_SERVICE_ENTRY_POINTS pEntryPoints) { SERIAL_DEVICE* serial; char* name; char* path; int i, len; name = (char*)pEntryPoints->plugin_data->data[1]; path = (char*)pEntryPoints->plugin_data->data[2]; if (name[0] && path[0]) { serial = xnew(SERIAL_DEVICE); serial->device.type = RDPDR_DTYP_SERIAL; serial->device.name = name; serial->device.IRPRequest = serial_irp_request; serial->device.Free = serial_free; len = strlen(name); serial->device.data = stream_new(len + 1); for (i = 0; i <= len; i++) stream_write_uint8(serial->device.data, name[i] < 0 ? '_' : name[i]); serial->path = path; serial->irp_list = list_new(); serial->pending_irps = list_new(); serial->thread = freerdp_thread_new(); serial->in_event = wait_obj_new(); pEntryPoints->RegisterDevice(pEntryPoints->devman, (DEVICE*)serial); freerdp_thread_start(serial->thread, serial_thread_func, serial); } return 0; }
void* WTSVirtualChannelOpenEx( /* __in */ WTSVirtualChannelManager* vcm, /* __in */ const char* pVirtualName, /* __in */ uint32 flags) { int i; int len; rdpPeerChannel* channel; const char* channel_name; freerdp_peer* client = vcm->client; channel_name = ((flags & WTS_CHANNEL_OPTION_DYNAMIC) != 0 ? "drdynvc" : pVirtualName); len = strlen(channel_name); if (len > 8) return NULL; for (i = 0; i < client->settings->num_channels; i++) { if (client->settings->channels[i].joined && strncmp(client->settings->channels[i].name, channel_name, len) == 0) { break; } } if (i >= client->settings->num_channels) return NULL; channel = (rdpPeerChannel*) client->settings->channels[i].handle; if (channel == NULL) { channel = xnew(rdpPeerChannel); channel->vcm = vcm; channel->client = client; channel->channel_id = client->settings->channels[i].channel_id; channel->index = i; channel->receive_data = stream_new(client->settings->vc_chunk_size); if ((flags & WTS_CHANNEL_OPTION_DYNAMIC) != 0) { channel->channel_type = RDP_PEER_CHANNEL_TYPE_DVC; vcm->drdynvc_channel = channel; } else { channel->channel_type = RDP_PEER_CHANNEL_TYPE_SVC; channel->receive_event = wait_obj_new(); channel->receive_queue = list_new(); channel->mutex = freerdp_mutex_new(); } client->settings->channels[i].handle = channel; } if (channel->channel_type == RDP_PEER_CHANNEL_TYPE_DVC) { /* TODO: do DVC channel initialization here using pVirtualName */ /* A sub-channel should be created and returned, instead of using the main drdynvc channel */ /* Set channel->index to num_channels */ } return channel; }
/* this registers two channels but only rdpsnd is used */ int VirtualChannelEntry(PCHANNEL_ENTRY_POINTS pEntryPoints) { rdpsndPlugin * plugin; RD_PLUGIN_DATA * data; RD_PLUGIN_DATA default_data[2] = { { 0 }, { 0 } }; LLOGLN(10, ("VirtualChannelEntry:")); plugin = (rdpsndPlugin *) malloc(sizeof(rdpsndPlugin)); memset(plugin, 0, sizeof(rdpsndPlugin)); chan_plugin_init((rdpChanPlugin *) plugin); plugin->data_in_size = 0; plugin->data_in = 0; plugin->ep = *pEntryPoints; memset(&(plugin->channel_def), 0, sizeof(plugin->channel_def)); plugin->channel_def.options = CHANNEL_OPTION_INITIALIZED | CHANNEL_OPTION_ENCRYPT_RDP; strcpy(plugin->channel_def.name, "rdpsnd"); plugin->in_mutex = (pthread_mutex_t *) malloc(sizeof(pthread_mutex_t)); pthread_mutex_init(plugin->in_mutex, 0); plugin->in_list_head = 0; plugin->in_list_tail = 0; plugin->out_list_head = 0; plugin->out_list_tail = 0; plugin->term_event = wait_obj_new("freerdprdpsndterm"); plugin->data_in_event = wait_obj_new("freerdprdpsnddatain"); plugin->expectingWave = 0; plugin->current_format = -1; plugin->thread_status = 0; plugin->ep.pVirtualChannelInit(&plugin->chan_plugin.init_handle, &plugin->channel_def, 1, VIRTUAL_CHANNEL_VERSION_WIN2000, InitEvent); if (pEntryPoints->cbSize >= sizeof(CHANNEL_ENTRY_POINTS_EX)) { data = (RD_PLUGIN_DATA *) (((PCHANNEL_ENTRY_POINTS_EX)pEntryPoints)->pExtendedData); } else { data = NULL; } while (data && data->size > 0) { rdpsnd_process_plugin_data(plugin, data); data = (RD_PLUGIN_DATA *) (((void *) data) + data->size); } if (plugin->device_plugin == NULL) { default_data[0].size = sizeof(RD_PLUGIN_DATA); default_data[0].data[0] = "alsa"; default_data[0].data[1] = "default"; rdpsnd_load_device_plugin(plugin, "alsa", default_data); } if (plugin->device_plugin == NULL) { LLOGLN(0, ("rdpsnd: no sound device.")); } return 1; }
void* WTSVirtualChannelOpenEx( /* __in */ WTSVirtualChannelManager* vcm, /* __in */ const char* pVirtualName, /* __in */ uint32 flags) { int i; int len; rdpPeerChannel* channel; freerdp_peer* client = vcm->client; STREAM* s; if ((flags & WTS_CHANNEL_OPTION_DYNAMIC) != 0) { if (vcm->drdynvc_channel == NULL || vcm->drdynvc_state != DRDYNVC_STATE_READY) { DEBUG_DVC("Dynamic virtual channel not ready."); return NULL; } channel = xnew(rdpPeerChannel); channel->vcm = vcm; channel->client = client; channel->channel_type = RDP_PEER_CHANNEL_TYPE_DVC; channel->receive_data = stream_new(client->settings->vc_chunk_size); channel->receive_event = wait_obj_new(); channel->receive_queue = list_new(); channel->mutex = CreateMutex(NULL, FALSE, NULL); WaitForSingleObject(vcm->mutex, INFINITE); channel->channel_id = vcm->dvc_channel_id_seq++; list_enqueue(vcm->dvc_channel_list, channel); ReleaseMutex(vcm->mutex); s = stream_new(64); wts_write_drdynvc_create_request(s, channel->channel_id, pVirtualName); WTSVirtualChannelWrite(vcm->drdynvc_channel, stream_get_head(s), stream_get_length(s), NULL); stream_free(s); DEBUG_DVC("ChannelId %d.%s (total %d)", channel->channel_id, pVirtualName, list_size(vcm->dvc_channel_list)); } else { len = strlen(pVirtualName); if (len > 8) return NULL; for (i = 0; i < client->settings->num_channels; i++) { if (client->settings->channels[i].joined && strncmp(client->settings->channels[i].name, pVirtualName, len) == 0) { break; } } if (i >= client->settings->num_channels) return NULL; channel = (rdpPeerChannel*) client->settings->channels[i].handle; if (channel == NULL) { channel = xnew(rdpPeerChannel); channel->vcm = vcm; channel->client = client; channel->channel_id = client->settings->channels[i].channel_id; channel->index = i; channel->channel_type = RDP_PEER_CHANNEL_TYPE_SVC; channel->receive_data = stream_new(client->settings->vc_chunk_size); channel->receive_event = wait_obj_new(); channel->receive_queue = list_new(); channel->mutex = CreateMutex(NULL, FALSE, NULL); client->settings->channels[i].handle = channel; } } return channel; }