/* returns error */ int DEFAULT_CC my_trans_data_in(struct trans *trans) { struct stream *s = (struct stream *)NULL; int id = 0; int size = 0; int error = 0; if (trans == 0) { return 0; } if (trans != g_con_trans) { return 1; } LOGM((LOG_LEVEL_DEBUG, "my_trans_data_in:")); s = trans_get_in_s(trans); in_uint32_le(s, id); in_uint32_le(s, size); error = trans_force_read(trans, size - 8); if (error == 0) { /* here, the entire message block is read in, process it */ error = process_message(); } return error; }
static int APP_CC xrdp_mm_sesman_data_in(struct trans* trans) { struct xrdp_mm* self = (struct xrdp_mm *)NULL; struct stream* s = (struct stream *)NULL; int version = 0; int size = 0; int error = 0; int code = 0; if (trans == 0) { return 1; } self = (struct xrdp_mm*)(trans->callback_data); s = trans_get_in_s(trans); if (s == 0) { return 1; } in_uint32_be(s, version); in_uint32_be(s, size); error = trans_force_read(trans, size - 8); if (error == 0) { in_uint16_be(s, code); switch (code) { case 3: error = xrdp_mm_process_login_response(self, s); break; default: g_writeln("xrdp_mm_sesman_data_in: unknown code %d", code); break; } } return error; }
/* data coming in from audio source, eg pulse, alsa */ static int DEFAULT_CC sound_trans_audio_data_in(struct trans *trans) { struct stream *s; int id; int size; int error; if (trans == 0) { return 0; } if (trans != g_audio_c_trans) { return 1; } s = trans_get_in_s(trans); in_uint32_le(s, id); in_uint32_le(s, size); if ((id != 0) || (size > 128 * 1024 + 8) || (size < 8)) { LOG(0, ("sound_trans_audio_data_in: bad message id %d size %d", id, size)); return 1; } LOG(10, ("sound_trans_audio_data_in: good message id %d size %d", id, size)); error = trans_force_read(trans, size - 8); if (error == 0) { /* here, the entire message block is read in, process it */ error = process_pcm_message(id, size - 8, s); } return error; }
/* * called when WTSVirtualChannelOpenEx is invoked in xrdpapi.c * ******************************************************************************/ int DEFAULT_CC my_api_trans_conn_in(struct trans *trans, struct trans *new_trans) { struct xrdp_api_data *ad; struct stream *s; int error; int index; char chan_pri; if ((trans == 0) || (trans != g_api_lis_trans) || (new_trans == 0)) { return 1; } LOGM((LOG_LEVEL_DEBUG, "my_api_trans_conn_in:")); LOG(10, ("my_api_trans_conn_in: got incoming")); s = trans_get_in_s(new_trans); s->end = s->data; error = trans_force_read(new_trans, 64); if (error != 0) { LOG(0, ("my_api_trans_conn_in: trans_force_read failed")); trans_delete(new_trans); } s->end = s->data; ad = (struct xrdp_api_data *) g_malloc(sizeof(struct xrdp_api_data), 1); g_memcpy(ad->header, s->data, 64); ad->flags = GGET_UINT32(ad->header, 16); ad->chan_id = -1; ad->dvc_chan_id = -1; if (ad->flags > 0) { /* opening a dynamic virtual channel */ if ((index = find_empty_slot_in_dvc_channels()) < 0) { /* exceeded MAX_DVC_CHANNELS */ LOG(0, ("my_api_trans_conn_in: MAX_DVC_CHANNELS reached; giving up!")) g_free(ad); trans_delete(new_trans); return 1; } g_dvc_channels[index] = ad; chan_pri = 4 - ad->flags; ad->dvc_chan_id = g_dvc_chan_id++; ad->is_connected = 0; ad->transp = new_trans; drdynvc_send_open_channel_request(chan_pri, ad->dvc_chan_id, ad->header); } else { /* opening a static virtual channel */ for (index = 0; index < g_num_chan_items; index++) { LOG(10, ("my_api_trans_conn_in: %s %s", ad->header, g_chan_items[index].name)); if (g_strcasecmp(ad->header, g_chan_items[index].name) == 0) { LOG(10, ("my_api_trans_conn_in: found it at %d", index)); ad->chan_id = g_chan_items[index].id; break; } } if (index == g_num_chan_items) { g_writeln("did not find SVC named %s", ad->header); } } new_trans->callback_data = ad; trans_delete(g_api_con_trans); g_api_con_trans = new_trans; g_api_con_trans->trans_data_in = my_api_trans_data_in; g_api_con_trans->header_size = 0; return 0; }
/* * called when WTSVirtualChannelWrite() is invoked in xrdpapi.c * ******************************************************************************/ int DEFAULT_CC my_api_trans_data_in(struct trans *trans) { struct stream *s; int bytes_read; int i32; struct xrdp_api_data *ad; //g_writeln("my_api_trans_data_in:"); LOG(10, ("my_api_trans_data_in:")); if (trans == 0) { return 0; } if (trans != g_api_con_trans) { return 1; } LOGM((LOG_LEVEL_DEBUG, "my_api_trans_data_in:")); s = trans_get_in_s(trans); bytes_read = g_tcp_recv(trans->sck, s->data, 16, 0); if (bytes_read == 16) { if (g_memcmp(s->data, g_xrdpapi_magic, 12) == 0) { in_uint8s(s, 12); in_uint32_le(s, bytes_read); init_stream(s, bytes_read); trans_force_read(trans, bytes_read); } else if (g_tcp_select(trans->sck, 0) & 1) { i32 = bytes_read; bytes_read = g_tcp_recv(trans->sck, s->data + bytes_read, 8192 * 4 - bytes_read, 0); if (bytes_read > 0) { bytes_read += i32; } } } //g_writeln("bytes_read %d", bytes_read); if (bytes_read > 0) { LOG(10, ("my_api_trans_data_in: got data %d", bytes_read)); ad = (struct xrdp_api_data *) trans->callback_data; if (ad->dvc_chan_id < 0) { /* writing data to a static virtual channel */ if (send_channel_data(ad->chan_id, s->data, bytes_read) != 0) { LOG(0, ("my_api_trans_data_in: send_channel_data failed")); } } else { /* writing data to a dynamic virtual channel */ drdynvc_write_data(ad->dvc_chan_id, s->data, bytes_read); } } else { ad = (struct xrdp_api_data *) (trans->callback_data); if ((ad != NULL) && (ad->dvc_chan_id > 0)) { /* WTSVirtualChannelClose() was invoked, or connection dropped */ LOG(10, ("my_api_trans_data_in: g_tcp_recv failed or disconnected for DVC")); ad->transp = NULL; ad->is_connected = 0; remove_struct_with_chan_id(ad->dvc_chan_id); } else { LOG(10, ("my_api_trans_data_in: g_tcp_recv failed or disconnected for SVC")); } return 1; } return 0; }