rdpContext* rdpcontext;
} AudinALSADevice;
-static BOOL audin_alsa_set_params(AudinALSADevice* alsa, snd_pcm_t* capture_handle)
+static BOOL audin_alsa_set_params(AudinALSADevice* alsa,
+ snd_pcm_t* capture_handle)
{
int error;
snd_pcm_hw_params_t* hw_params;
if ((error = snd_pcm_hw_params_malloc(&hw_params)) < 0)
{
WLog_ERR(TAG, "snd_pcm_hw_params_malloc (%s)",
- snd_strerror(error));
+ snd_strerror(error));
return FALSE;
}
snd_pcm_hw_params_any(capture_handle, hw_params);
- snd_pcm_hw_params_set_access(capture_handle, hw_params, SND_PCM_ACCESS_RW_INTERLEAVED);
+ snd_pcm_hw_params_set_access(capture_handle, hw_params,
+ SND_PCM_ACCESS_RW_INTERLEAVED);
snd_pcm_hw_params_set_format(capture_handle, hw_params, alsa->format);
- snd_pcm_hw_params_set_rate_near(capture_handle, hw_params, &alsa->actual_rate, NULL);
- snd_pcm_hw_params_set_channels_near(capture_handle, hw_params, &alsa->actual_channels);
+ snd_pcm_hw_params_set_rate_near(capture_handle, hw_params, &alsa->actual_rate,
+ NULL);
+ snd_pcm_hw_params_set_channels_near(capture_handle, hw_params,
+ &alsa->actual_channels);
snd_pcm_hw_params(capture_handle, hw_params);
snd_pcm_hw_params_free(hw_params);
snd_pcm_prepare(capture_handle);
if ((alsa->actual_rate != alsa->target_rate) ||
- (alsa->actual_channels != alsa->target_channels))
+ (alsa->actual_channels != alsa->target_channels))
{
DEBUG_DVC("actual rate %d / channel %d is "
- "different from target rate %d / channel %d, resampling required.",
- alsa->actual_rate, alsa->actual_channels,
- alsa->target_rate, alsa->target_channels);
+ "different from target rate %d / channel %d, resampling required.",
+ alsa->actual_rate, alsa->actual_channels,
+ alsa->target_rate, alsa->target_channels);
}
return TRUE;
*
* @return 0 on success, otherwise a Win32 error code
*/
-static UINT audin_alsa_thread_receive(AudinALSADevice* alsa, BYTE* src, int size)
+static UINT audin_alsa_thread_receive(AudinALSADevice* alsa, BYTE* src,
+ int size)
{
int frames;
int cframes;
BYTE* encoded_data;
int rbytes_per_frame;
int tbytes_per_frame;
- int status;
-
+ int status;
rbytes_per_frame = alsa->actual_channels * alsa->bytes_per_channel;
tbytes_per_frame = alsa->target_channels * alsa->bytes_per_channel;
if ((alsa->target_rate == alsa->actual_rate) &&
- (alsa->target_channels == alsa->actual_channels))
+ (alsa->target_channels == alsa->actual_channels))
{
frames = size / rbytes_per_frame;
}
else
{
alsa->dsp_context->resample(alsa->dsp_context, src, alsa->bytes_per_channel,
- alsa->actual_channels, alsa->actual_rate, size / rbytes_per_frame,
- alsa->target_channels, alsa->target_rate);
+ alsa->actual_channels, alsa->actual_rate, size / rbytes_per_frame,
+ alsa->target_channels, alsa->target_rate);
frames = alsa->dsp_context->resampled_frames;
DEBUG_DVC("resampled %d frames at %d to %d frames at %d",
- size / rbytes_per_frame, alsa->actual_rate, frames, alsa->target_rate);
+ size / rbytes_per_frame, alsa->actual_rate, frames, alsa->target_rate);
size = frames * tbytes_per_frame;
src = alsa->dsp_context->resampled_buffer;
}
while (frames > 0)
{
- status = WaitForSingleObject(alsa->stopEvent, 0);
+ status = WaitForSingleObject(alsa->stopEvent, 0);
- if (status == WAIT_FAILED)
- {
- ret = GetLastError();
- WLog_ERR(TAG, "WaitForSingleObject failed with error %lu!", ret);
- break;
- }
+ if (status == WAIT_FAILED)
+ {
+ ret = GetLastError();
+ WLog_ERR(TAG, "WaitForSingleObject failed with error %lu!", ret);
+ break;
+ }
if (status == WAIT_OBJECT_0)
break;
if (cframes > frames)
cframes = frames;
- CopyMemory(alsa->buffer + alsa->buffer_frames * tbytes_per_frame, src, cframes * tbytes_per_frame);
-
+ CopyMemory(alsa->buffer + alsa->buffer_frames * tbytes_per_frame, src,
+ cframes * tbytes_per_frame);
alsa->buffer_frames += cframes;
if (alsa->buffer_frames >= alsa->frames_per_packet)
if (alsa->wformat == WAVE_FORMAT_DVI_ADPCM)
{
if (!alsa->dsp_context->encode_ima_adpcm(alsa->dsp_context,
- alsa->buffer, alsa->buffer_frames * tbytes_per_frame,
- alsa->target_channels, alsa->block_size))
+ alsa->buffer, alsa->buffer_frames * tbytes_per_frame,
+ alsa->target_channels, alsa->block_size))
{
ret = ERROR_INTERNAL_ERROR;
break;
encoded_data = alsa->dsp_context->adpcm_buffer;
encoded_size = alsa->dsp_context->adpcm_size;
-
DEBUG_DVC("encoded %d to %d",
- alsa->buffer_frames * tbytes_per_frame, encoded_size);
+ alsa->buffer_frames * tbytes_per_frame, encoded_size);
}
else
{
encoded_size = alsa->buffer_frames * tbytes_per_frame;
}
- status = WaitForSingleObject(alsa->stopEvent, 0);
+ status = WaitForSingleObject(alsa->stopEvent, 0);
- if (status == WAIT_FAILED)
- {
- ret = GetLastError();
- WLog_ERR(TAG, "WaitForSingleObject failed with error %lu!", ret);
- break;
- }
+ if (status == WAIT_FAILED)
+ {
+ ret = GetLastError();
+ WLog_ERR(TAG, "WaitForSingleObject failed with error %lu!", ret);
+ break;
+ }
- if (status == WAIT_OBJECT_0)
+ if (status == WAIT_OBJECT_0)
break;
else
{
DEBUG_DVC("encoded %d [%d] to %d [%X]", alsa->buffer_frames,
- tbytes_per_frame, encoded_size,
- alsa->wformat);
+ tbytes_per_frame, encoded_size,
+ alsa->wformat);
ret = alsa->receive(encoded_data, encoded_size, alsa->user_data);
}
snd_pcm_t* capture_handle = NULL;
AudinALSADevice* alsa = (AudinALSADevice*) arg;
DWORD status;
-
DEBUG_DVC("in");
-
freerdp_channel_init_thread_context(alsa->rdpcontext);
-
rbytes_per_frame = alsa->actual_channels * alsa->bytes_per_channel;
tbytes_per_frame = alsa->target_channels * alsa->bytes_per_channel;
buffer = (BYTE*) calloc(1, rbytes_per_frame * alsa->frames_per_packet);
+
if (!buffer)
{
WLog_ERR(TAG, "calloc failed!");
- error = CHANNEL_RC_NO_MEMORY;
+ error = CHANNEL_RC_NO_MEMORY;
+
if (alsa->rdpcontext)
setChannelError(alsa->rdpcontext, error, "calloc failed!");
- goto out;
+
+ goto out;
}
freerdp_dsp_context_reset_adpcm(alsa->dsp_context);
- if ((error = snd_pcm_open(&capture_handle, alsa->device_name, SND_PCM_STREAM_CAPTURE, 0)) < 0)
- {
- WLog_ERR(TAG, "snd_pcm_open (%s)", snd_strerror(error));
- goto out;
- }
-
- if (!audin_alsa_set_params(alsa, capture_handle))
- {
- WLog_ERR(TAG, "audin_alsa_set_params failed");
- goto out;
- }
-
- while(1)
- {
- status = WaitForSingleObject(alsa->stopEvent, 0);
-
- if (status == WAIT_FAILED)
+ if ((error = snd_pcm_open(&capture_handle, alsa->device_name,
+ SND_PCM_STREAM_CAPTURE, 0)) < 0)
{
- error = GetLastError();
- WLog_ERR(TAG, "WaitForSingleObject failed with error %lu!", error);
- break;
+ WLog_ERR(TAG, "snd_pcm_open (%s)", snd_strerror(error));
+ goto out;
}
- if (status == WAIT_OBJECT_0)
- break;
-
- error = snd_pcm_readi(capture_handle, buffer, alsa->frames_per_packet);
-
- if (error == -EPIPE)
+ if (!audin_alsa_set_params(alsa, capture_handle))
{
- snd_pcm_recover(capture_handle, error, 0);
- continue;
- }
- else if (error < 0)
- {
- WLog_ERR(TAG, "snd_pcm_readi (%s)", snd_strerror(error));
- break;
+ WLog_ERR(TAG, "audin_alsa_set_params failed");
+ goto out;
}
- if ((error = audin_alsa_thread_receive(alsa, buffer, error * rbytes_per_frame)))
+ while (1)
{
- WLog_ERR(TAG, "audin_alsa_thread_receive failed with error %lu", error);
- break;
- }
+ status = WaitForSingleObject(alsa->stopEvent, 0);
+
+ if (status == WAIT_FAILED)
+ {
+ error = GetLastError();
+ WLog_ERR(TAG, "WaitForSingleObject failed with error %lu!", error);
+ break;
+ }
+
+ if (status == WAIT_OBJECT_0)
+ break;
+
+ error = snd_pcm_readi(capture_handle, buffer, alsa->frames_per_packet);
+
+ if (error == -EPIPE)
+ {
+ snd_pcm_recover(capture_handle, error, 0);
+ continue;
+ }
+ else if (error < 0)
+ {
+ WLog_ERR(TAG, "snd_pcm_readi (%s)", snd_strerror(error));
+ break;
+ }
- }
+ if ((error = audin_alsa_thread_receive(alsa, buffer, error * rbytes_per_frame)))
+ {
+ WLog_ERR(TAG, "audin_alsa_thread_receive failed with error %lu", error);
+ break;
+ }
+ }
free(buffer);
if (capture_handle)
snd_pcm_close(capture_handle);
+
out:
DEBUG_DVC("out");
+
if (error && alsa->rdpcontext)
- setChannelError(alsa->rdpcontext, error, "audin_alsa_thread_func reported an error");
- ExitThread((DWORD)error);
+ setChannelError(alsa->rdpcontext, error,
+ "audin_alsa_thread_func reported an error");
+ ExitThread((DWORD)error);
return NULL;
}
static UINT audin_alsa_free(IAudinDevice* device)
{
AudinALSADevice* alsa = (AudinALSADevice*) device;
-
freerdp_dsp_context_free(alsa->dsp_context);
-
free(alsa->device_name);
-
free(alsa);
return CHANNEL_RC_OK;
}
-static BOOL audin_alsa_format_supported(IAudinDevice* device, audinFormat* format)
+static BOOL audin_alsa_format_supported(IAudinDevice* device,
+ audinFormat* format)
{
switch (format->wFormatTag)
{
case WAVE_FORMAT_PCM:
if (format->cbSize == 0 &&
- (format->nSamplesPerSec <= 48000) &&
- (format->wBitsPerSample == 8 || format->wBitsPerSample == 16) &&
- (format->nChannels == 1 || format->nChannels == 2))
+ (format->nSamplesPerSec <= 48000) &&
+ (format->wBitsPerSample == 8 || format->wBitsPerSample == 16) &&
+ (format->nChannels == 1 || format->nChannels == 2))
{
return TRUE;
}
+
break;
case WAVE_FORMAT_DVI_ADPCM:
if ((format->nSamplesPerSec <= 48000) &&
- (format->wBitsPerSample == 4) &&
- (format->nChannels == 1 || format->nChannels == 2))
+ (format->wBitsPerSample == 4) &&
+ (format->nChannels == 1 || format->nChannels == 2))
{
return TRUE;
}
+
break;
}
*
* @return 0 on success, otherwise a Win32 error code
*/
-static UINT audin_alsa_set_format(IAudinDevice* device, audinFormat* format, UINT32 FramesPerPacket)
+static UINT audin_alsa_set_format(IAudinDevice* device, audinFormat* format,
+ UINT32 FramesPerPacket)
{
int bs;
AudinALSADevice* alsa = (AudinALSADevice*) device;
-
alsa->target_rate = format->nSamplesPerSec;
alsa->actual_rate = format->nSamplesPerSec;
alsa->target_channels = format->nChannels;
alsa->format = SND_PCM_FORMAT_S8;
alsa->bytes_per_channel = 1;
break;
+
case 16:
alsa->format = SND_PCM_FORMAT_S16_LE;
alsa->bytes_per_channel = 2;
break;
}
+
break;
case WAVE_FORMAT_DVI_ADPCM:
alsa->bytes_per_channel = 2;
bs = (format->nBlockAlign - 4 * format->nChannels) * 4;
alsa->frames_per_packet = (alsa->frames_per_packet * format->nChannels * 2 /
- bs + 1) * bs / (format->nChannels * 2);
+ bs + 1) * bs / (format->nChannels * 2);
DEBUG_DVC("aligned FramesPerPacket=%d",
- alsa->frames_per_packet);
+ alsa->frames_per_packet);
break;
}
*
* @return 0 on success, otherwise a Win32 error code
*/
-static UINT audin_alsa_open(IAudinDevice* device, AudinReceive receive, void* user_data)
+static UINT audin_alsa_open(IAudinDevice* device, AudinReceive receive,
+ void* user_data)
{
int tbytes_per_frame;
AudinALSADevice* alsa = (AudinALSADevice*) device;
-
alsa->receive = receive;
alsa->user_data = user_data;
-
tbytes_per_frame = alsa->target_channels * alsa->bytes_per_channel;
alsa->buffer = (BYTE*) calloc(1, tbytes_per_frame * alsa->frames_per_packet);
+
if (!alsa->buffer)
{
WLog_ERR(TAG, "calloc failed!");
return ERROR_NOT_ENOUGH_MEMORY;
}
+
alsa->buffer_frames = 0;
if (!(alsa->stopEvent = CreateEvent(NULL, TRUE, FALSE, NULL)))
WLog_ERR(TAG, "CreateEvent failed!");
goto error_out;
}
+
if (!(alsa->thread = CreateThread(NULL, 0,
- (LPTHREAD_START_ROUTINE) audin_alsa_thread_func, alsa, 0, NULL)))
+ (LPTHREAD_START_ROUTINE) audin_alsa_thread_func, alsa, 0, NULL)))
{
WLog_ERR(TAG, "CreateThread failed!");
goto error_out;
}
+
return CHANNEL_RC_OK;
error_out:
free(alsa->buffer);
*/
static UINT audin_alsa_close(IAudinDevice* device)
{
- UINT error = CHANNEL_RC_OK;
+ UINT error = CHANNEL_RC_OK;
AudinALSADevice* alsa = (AudinALSADevice*) device;
if (alsa->stopEvent)
{
SetEvent(alsa->stopEvent);
+
if (WaitForSingleObject(alsa->thread, INFINITE) == WAIT_FAILED)
- {
- error = GetLastError();
- WLog_ERR(TAG, "WaitForSingleObject failed with error %lu", error);
- return error;
- }
+ {
+ error = GetLastError();
+ WLog_ERR(TAG, "WaitForSingleObject failed with error %lu", error);
+ return error;
+ }
CloseHandle(alsa->stopEvent);
alsa->stopEvent = NULL;
-
CloseHandle(alsa->thread);
alsa->thread = NULL;
}
free(alsa->buffer);
alsa->buffer = NULL;
-
alsa->receive = NULL;
alsa->user_data = NULL;
-
return error;
}
*
* @return 0 on success, otherwise a Win32 error code
*/
-static UINT audin_alsa_parse_addin_args(AudinALSADevice* device, ADDIN_ARGV* args)
+static UINT audin_alsa_parse_addin_args(AudinALSADevice* device,
+ ADDIN_ARGV* args)
{
int status;
DWORD flags;
COMMAND_LINE_ARGUMENT_A* arg;
AudinALSADevice* alsa = (AudinALSADevice*) device;
-
- flags = COMMAND_LINE_SIGIL_NONE | COMMAND_LINE_SEPARATOR_COLON | COMMAND_LINE_IGN_UNKNOWN_KEYWORD;
-
- status = CommandLineParseArgumentsA(args->argc, (const char**) args->argv, audin_alsa_args, flags, alsa, NULL, NULL);
-
+ flags = COMMAND_LINE_SIGIL_NONE | COMMAND_LINE_SEPARATOR_COLON |
+ COMMAND_LINE_IGN_UNKNOWN_KEYWORD;
+ status = CommandLineParseArgumentsA(args->argc, (const char**) args->argv,
+ audin_alsa_args, flags, alsa, NULL, NULL);
arg = audin_alsa_args;
do
continue;
CommandLineSwitchStart(arg)
-
CommandLineSwitchCase(arg, "dev")
{
alsa->device_name = _strdup(arg->Value);
- if(!alsa->device_name)
+
+ if (!alsa->device_name)
{
WLog_ERR(TAG, "_strdup failed!");
return CHANNEL_RC_NO_MEMORY;
}
}
-
CommandLineSwitchEnd(arg)
}
while ((arg = CommandLineFindNextArgumentA(arg)) != NULL);
*
* @return 0 on success, otherwise a Win32 error code
*/
-UINT freerdp_audin_client_subsystem_entry(PFREERDP_AUDIN_DEVICE_ENTRY_POINTS pEntryPoints)
+UINT freerdp_audin_client_subsystem_entry(PFREERDP_AUDIN_DEVICE_ENTRY_POINTS
+ pEntryPoints)
{
ADDIN_ARGV* args;
AudinALSADevice* alsa;
UINT error;
-
alsa = (AudinALSADevice*) calloc(1, sizeof(AudinALSADevice));
+
if (!alsa)
{
WLog_ERR(TAG, "calloc failed!");
alsa->iface.Close = audin_alsa_close;
alsa->iface.Free = audin_alsa_free;
alsa->rdpcontext = pEntryPoints->rdpcontext;
-
args = pEntryPoints->args;
if ((error = audin_alsa_parse_addin_args(alsa, args)))
if (!alsa->device_name)
{
alsa->device_name = _strdup("default");
+
if (!alsa->device_name)
{
WLog_ERR(TAG, "_strdup failed!");
alsa->target_channels = 2;
alsa->actual_channels = 2;
alsa->bytes_per_channel = 2;
-
alsa->dsp_context = freerdp_dsp_context_new();
+
if (!alsa->dsp_context)
{
WLog_ERR(TAG, "freerdp_dsp_context_new failed!");
goto error_out;
}
- if ((error = pEntryPoints->pRegisterAudinDevice(pEntryPoints->plugin, (IAudinDevice*) alsa)))
+ if ((error = pEntryPoints->pRegisterAudinDevice(pEntryPoints->plugin,
+ (IAudinDevice*) alsa)))
{
WLog_ERR(TAG, "RegisterAudinDevice failed with error %lu!", error);
goto error_out;
switch (format->wFormatTag)
{
case WAVE_FORMAT_PCM:
-
switch (format->wBitsPerSample)
{
case 8:
return AFMT_S8;
+
case 16:
return AFMT_S16_LE;
}
break;
+
case WAVE_FORMAT_ALAW:
return AFMT_A_LAW;
#if 0 /* This does not work on my desktop. */
+
case WAVE_FORMAT_MULAW:
return AFMT_MU_LAW;
#endif
+
case WAVE_FORMAT_ADPCM:
case WAVE_FORMAT_DVI_ADPCM:
return AFMT_S16_LE;
return 0;
}
-static BOOL audin_oss_format_supported(IAudinDevice* device, audinFormat* format)
+static BOOL audin_oss_format_supported(IAudinDevice* device,
+ audinFormat* format)
{
int req_fmt = 0;
switch (format->wFormatTag)
{
case WAVE_FORMAT_PCM:
-
if (format->cbSize != 0 ||
- format->nSamplesPerSec > 48000 ||
- (format->wBitsPerSample != 8 && format->wBitsPerSample != 16) ||
- (format->nChannels != 1 && format->nChannels != 2))
+ format->nSamplesPerSec > 48000 ||
+ (format->wBitsPerSample != 8 && format->wBitsPerSample != 16) ||
+ (format->nChannels != 1 && format->nChannels != 2))
return FALSE;
break;
+
case WAVE_FORMAT_ADPCM:
case WAVE_FORMAT_DVI_ADPCM:
-
if (format->nSamplesPerSec > 48000 ||
- format->wBitsPerSample != 4 ||
- (format->nChannels != 1 && format->nChannels != 2))
+ format->wBitsPerSample != 4 ||
+ (format->nChannels != 1 && format->nChannels != 2))
return FALSE;
break;
*
* @return 0 on success, otherwise a Win32 error code
*/
-static UINT audin_oss_set_format(IAudinDevice* device, audinFormat* format, UINT32 FramesPerPacket)
+static UINT audin_oss_set_format(IAudinDevice* device, audinFormat* format,
+ UINT32 FramesPerPacket)
{
AudinOSSDevice* oss = (AudinOSSDevice*)device;
oss->format.wBitsPerSample *= 4;
break;
}
+
return CHANNEL_RC_OK;
}
if (ioctl(pcm_handle, SNDCTL_DSP_SETFRAGMENT, &tmp) == -1)
OSS_LOG_ERR("SNDCTL_DSP_SETFRAGMENT failed", errno);
- buffer_size = (oss->FramesPerPacket * oss->format.nChannels * (oss->format.wBitsPerSample / 8));
+ buffer_size = (oss->FramesPerPacket * oss->format.nChannels *
+ (oss->format.wBitsPerSample / 8));
buffer = (BYTE*)calloc((buffer_size + sizeof(void*)), sizeof(BYTE));
if (NULL == buffer)
continue;
/* Process. */
- switch (oss->format.wFormatTag) {
- case WAVE_FORMAT_ADPCM:
- if (!oss->dsp_context->encode_ms_adpcm(oss->dsp_context,
- buffer, buffer_size, oss->format.nChannels, oss->format.nBlockAlign))
- {
- error = ERROR_INTERNAL_ERROR;
- goto err_out;
- }
- encoded_data = oss->dsp_context->adpcm_buffer;
- encoded_size = oss->dsp_context->adpcm_size;
- break;
- case WAVE_FORMAT_DVI_ADPCM:
- if (!oss->dsp_context->encode_ima_adpcm(oss->dsp_context,
- buffer, buffer_size, oss->format.nChannels, oss->format.nBlockAlign))
- {
- error = ERROR_INTERNAL_ERROR;
- goto err_out;
- }
- encoded_data = oss->dsp_context->adpcm_buffer;
- encoded_size = oss->dsp_context->adpcm_size;
- break;
- default:
- encoded_data = buffer;
- encoded_size = buffer_size;
- break;
+ switch (oss->format.wFormatTag)
+ {
+ case WAVE_FORMAT_ADPCM:
+ if (!oss->dsp_context->encode_ms_adpcm(oss->dsp_context,
+ buffer, buffer_size, oss->format.nChannels, oss->format.nBlockAlign))
+ {
+ error = ERROR_INTERNAL_ERROR;
+ goto err_out;
+ }
+
+ encoded_data = oss->dsp_context->adpcm_buffer;
+ encoded_size = oss->dsp_context->adpcm_size;
+ break;
+
+ case WAVE_FORMAT_DVI_ADPCM:
+ if (!oss->dsp_context->encode_ima_adpcm(oss->dsp_context,
+ buffer, buffer_size, oss->format.nChannels, oss->format.nBlockAlign))
+ {
+ error = ERROR_INTERNAL_ERROR;
+ goto err_out;
+ }
+
+ encoded_data = oss->dsp_context->adpcm_buffer;
+ encoded_size = oss->dsp_context->adpcm_size;
+ break;
+
+ default:
+ encoded_data = buffer;
+ encoded_size = buffer_size;
+ break;
}
+
if ((error = oss->receive(encoded_data, encoded_size, oss->user_data)))
{
WLog_ERR(TAG, "oss->receive failed with error %lu", error);
break;
}
-
}
err_out:
if (error && oss->rdpcontext)
- setChannelError(oss->rdpcontext, error, "audin_oss_thread_func reported an error");
+ setChannelError(oss->rdpcontext, error,
+ "audin_oss_thread_func reported an error");
if (pcm_handle != -1)
{
*
* @return 0 on success, otherwise a Win32 error code
*/
-static UINT audin_oss_open(IAudinDevice *device, AudinReceive receive, void *user_data) {
- AudinOSSDevice *oss = (AudinOSSDevice*)device;
-
+static UINT audin_oss_open(IAudinDevice* device, AudinReceive receive,
+ void* user_data)
+{
+ AudinOSSDevice* oss = (AudinOSSDevice*)device;
oss->receive = receive;
oss->user_data = user_data;
WLog_ERR(TAG, "CreateEvent failed!");
return ERROR_INTERNAL_ERROR;
}
+
if (!(oss->thread = CreateThread(NULL, 0,
- (LPTHREAD_START_ROUTINE)audin_oss_thread_func, oss, 0, NULL)))
+ (LPTHREAD_START_ROUTINE)audin_oss_thread_func, oss, 0, NULL)))
{
WLog_ERR(TAG, "CreateThread failed!");
CloseHandle(oss->stopEvent);
*
* @return 0 on success, otherwise a Win32 error code
*/
-static UINT audin_oss_close(IAudinDevice *device)
+static UINT audin_oss_close(IAudinDevice* device)
{
UINT error;
- AudinOSSDevice *oss = (AudinOSSDevice*)device;
+ AudinOSSDevice* oss = (AudinOSSDevice*)device;
if (device == NULL)
return ERROR_INVALID_PARAMETER;
if (oss->stopEvent != NULL)
{
SetEvent(oss->stopEvent);
+
if (WaitForSingleObject(oss->thread, INFINITE) == WAIT_FAILED)
{
error = GetLastError();
WLog_ERR(TAG, "WaitForSingleObject failed with error %lu", error);
return error;
}
+
CloseHandle(oss->stopEvent);
oss->stopEvent = NULL;
CloseHandle(oss->thread);
oss->receive = NULL;
oss->user_data = NULL;
-
return CHANNEL_RC_OK;
}
*/
static UINT audin_oss_free(IAudinDevice* device)
{
- AudinOSSDevice *oss = (AudinOSSDevice*)device;
-
+ AudinOSSDevice* oss = (AudinOSSDevice*)device;
int error;
if (device == NULL)
{
WLog_ERR(TAG, "audin_oss_close failed with error code %d!", error);
}
+
freerdp_dsp_context_free(oss->dsp_context);
free(oss);
-
return CHANNEL_RC_OK;
}
*
* @return 0 on success, otherwise a Win32 error code
*/
-static UINT audin_oss_parse_addin_args(AudinOSSDevice *device, ADDIN_ARGV *args)
+static UINT audin_oss_parse_addin_args(AudinOSSDevice* device, ADDIN_ARGV* args)
{
int status;
char* str_num, *eptr;
DWORD flags;
COMMAND_LINE_ARGUMENT_A* arg;
AudinOSSDevice* oss = (AudinOSSDevice*)device;
- flags = COMMAND_LINE_SIGIL_NONE | COMMAND_LINE_SEPARATOR_COLON | COMMAND_LINE_IGN_UNKNOWN_KEYWORD;
- status = CommandLineParseArgumentsA(args->argc, (const char**)args->argv, audin_oss_args, flags, oss, NULL, NULL);
+ flags = COMMAND_LINE_SIGIL_NONE | COMMAND_LINE_SEPARATOR_COLON |
+ COMMAND_LINE_IGN_UNKNOWN_KEYWORD;
+ status = CommandLineParseArgumentsA(args->argc, (const char**)args->argv,
+ audin_oss_args, flags, oss, NULL, NULL);
if (status < 0)
return ERROR_INVALID_PARAMETER;
CommandLineSwitchCase(arg, "dev")
{
str_num = _strdup(arg->Value);
+
if (!str_num)
{
WLog_ERR(TAG, "_strdup failed!");
return CHANNEL_RC_NO_MEMORY;
}
+
oss->dev_unit = strtol(str_num, &eptr, 10);
if (oss->dev_unit < 0 || *eptr != '\0')
CommandLineSwitchEnd(arg)
}
while ((arg = CommandLineFindNextArgumentA(arg)) != NULL);
+
return CHANNEL_RC_OK;
}
*
* @return 0 on success, otherwise a Win32 error code
*/
-UINT freerdp_audin_client_subsystem_entry(PFREERDP_AUDIN_DEVICE_ENTRY_POINTS pEntryPoints)
+UINT freerdp_audin_client_subsystem_entry(PFREERDP_AUDIN_DEVICE_ENTRY_POINTS
+ pEntryPoints)
{
- ADDIN_ARGV *args;
- AudinOSSDevice *oss;
+ ADDIN_ARGV* args;
+ AudinOSSDevice* oss;
UINT error;
-
oss = (AudinOSSDevice*)calloc(1, sizeof(AudinOSSDevice));
+
if (!oss)
{
WLog_ERR(TAG, "calloc failed!");
oss->iface.Close = audin_oss_close;
oss->iface.Free = audin_oss_free;
oss->rdpcontext = pEntryPoints->rdpcontext;
-
oss->dev_unit = -1;
args = pEntryPoints->args;
}
oss->dsp_context = freerdp_dsp_context_new();
+
if (!oss->dsp_context)
{
WLog_ERR(TAG, "freerdp_dsp_context_new failed!");
goto error_out;
}
- if ((error = pEntryPoints->pRegisterAudinDevice(pEntryPoints->plugin, (IAudinDevice*) oss)))
+ if ((error = pEntryPoints->pRegisterAudinDevice(pEntryPoints->plugin,
+ (IAudinDevice*) oss)))
{
WLog_ERR(TAG, "RegisterAudinDevice failed with error %lu!", error);
goto error_out;
freerdp_dsp_context_free(oss->dsp_context);
free(oss);
return error;
-
}
*
* @return 0 on success, otherwise a Win32 error code
*/
-static UINT audin_server_select_format(audin_server_context* context, int client_format_index)
+static UINT audin_server_select_format(audin_server_context* context,
+ int client_format_index)
{
audin_server* audin = (audin_server*) context;
if (client_format_index >= context->num_client_formats)
{
- WLog_ERR(TAG, "error in protocol: client_format_index >= context->num_client_formats!");
+ WLog_ERR(TAG,
+ "error in protocol: client_format_index >= context->num_client_formats!");
return ERROR_INVALID_DATA;
}
{
/* TODO: send MSG_SNDIN_FORMATCHANGE */
}
+
return CHANNEL_RC_OK;
}
static UINT audin_server_send_version(audin_server* audin, wStream* s)
{
ULONG written;
-
Stream_Write_UINT8(s, MSG_SNDIN_VERSION);
Stream_Write_UINT32(s, 1); /* Version (4 bytes) */
- if (!WTSVirtualChannelWrite(audin->audin_channel, (PCHAR) Stream_Buffer(s), Stream_GetPosition(s), &written))
+
+ if (!WTSVirtualChannelWrite(audin->audin_channel, (PCHAR) Stream_Buffer(s),
+ Stream_GetPosition(s), &written))
{
WLog_ERR(TAG, "WTSVirtualChannelWrite failed!");
return ERROR_INTERNAL_ERROR;
}
+
return CHANNEL_RC_OK;
}
*
* @return 0 on success, otherwise a Win32 error code
*/
-static UINT audin_server_recv_version(audin_server* audin, wStream* s, UINT32 length)
+static UINT audin_server_recv_version(audin_server* audin, wStream* s,
+ UINT32 length)
{
UINT32 Version;
if (length < 4)
{
- WLog_ERR(TAG, "error parsing version info: expected at least 4 bytes, got %d", length);
+ WLog_ERR(TAG, "error parsing version info: expected at least 4 bytes, got %d",
+ length);
return ERROR_INVALID_DATA;
}
int i;
UINT32 nAvgBytesPerSec;
ULONG written;
-
Stream_SetPosition(s, 0);
Stream_Write_UINT8(s, MSG_SNDIN_FORMATS);
- Stream_Write_UINT32(s, audin->context.num_server_formats); /* NumFormats (4 bytes) */
- Stream_Write_UINT32(s, 0); /* cbSizeFormatsPacket (4 bytes), client-to-server only */
+ Stream_Write_UINT32(s,
+ audin->context.num_server_formats); /* NumFormats (4 bytes) */
+ Stream_Write_UINT32(s,
+ 0); /* cbSizeFormatsPacket (4 bytes), client-to-server only */
for (i = 0; i < audin->context.num_server_formats; i++)
{
nAvgBytesPerSec = audin->context.server_formats[i].nSamplesPerSec *
- audin->context.server_formats[i].nChannels *
- audin->context.server_formats[i].wBitsPerSample / 8;
+ audin->context.server_formats[i].nChannels *
+ audin->context.server_formats[i].wBitsPerSample / 8;
if (!Stream_EnsureRemainingCapacity(s, 18))
{
}
Stream_Write(s, audin->context.server_formats[i].data,
- audin->context.server_formats[i].cbSize);
+ audin->context.server_formats[i].cbSize);
}
}
- return WTSVirtualChannelWrite(audin->audin_channel, (PCHAR) Stream_Buffer(s), Stream_GetPosition(s), &written) ? CHANNEL_RC_OK : ERROR_INTERNAL_ERROR;
+ return WTSVirtualChannelWrite(audin->audin_channel, (PCHAR) Stream_Buffer(s),
+ Stream_GetPosition(s), &written) ? CHANNEL_RC_OK : ERROR_INTERNAL_ERROR;
}
/**
*
* @return 0 on success, otherwise a Win32 error code
*/
-static UINT audin_server_recv_formats(audin_server* audin, wStream* s, UINT32 length)
+static UINT audin_server_recv_formats(audin_server* audin, wStream* s,
+ UINT32 length)
{
int i;
UINT success = CHANNEL_RC_OK;
if (length < 8)
{
- WLog_ERR(TAG, "error parsing rec formats: expected at least 8 bytes, got %d", length);
+ WLog_ERR(TAG, "error parsing rec formats: expected at least 8 bytes, got %d",
+ length);
return ERROR_INVALID_DATA;
}
- Stream_Read_UINT32(s, audin->context.num_client_formats); /* NumFormats (4 bytes) */
+ Stream_Read_UINT32(s,
+ audin->context.num_client_formats); /* NumFormats (4 bytes) */
Stream_Seek_UINT32(s); /* cbSizeFormatsPacket (4 bytes) */
length -= 8;
if (audin->context.num_client_formats <= 0)
{
- WLog_ERR(TAG, "num_client_formats expected > 0 but got %d", audin->context.num_client_formats);
+ WLog_ERR(TAG, "num_client_formats expected > 0 but got %d",
+ audin->context.num_client_formats);
return ERROR_INVALID_DATA;
}
- audin->context.client_formats = malloc(audin->context.num_client_formats * sizeof(AUDIO_FORMAT));
- ZeroMemory(audin->context.client_formats, audin->context.num_client_formats * sizeof(AUDIO_FORMAT));
+ audin->context.client_formats = malloc(audin->context.num_client_formats *
+ sizeof(AUDIO_FORMAT));
+ ZeroMemory(audin->context.client_formats,
+ audin->context.num_client_formats * sizeof(AUDIO_FORMAT));
for (i = 0; i < audin->context.num_client_formats; i++)
{
}
IFCALLRET(audin->context.Opening, success, &audin->context);
- if (success)
- WLog_ERR(TAG, "context.Opening failed with error %lu", success);
+
+ if (success)
+ WLog_ERR(TAG, "context.Opening failed with error %lu", success);
+
return success;
}
if (audin->context.selected_client_format < 0)
{
WLog_ERR(TAG, "audin->context.selected_client_format = %d",
- audin->context.selected_client_format);
+ audin->context.selected_client_format);
return ERROR_INVALID_DATA;
}
audin->opened = TRUE;
-
Stream_SetPosition(s, 0);
Stream_Write_UINT8(s, MSG_SNDIN_OPEN);
- Stream_Write_UINT32(s, audin->context.frames_per_packet); /* FramesPerPacket (4 bytes) */
- Stream_Write_UINT32(s, audin->context.selected_client_format); /* initialFormat (4 bytes) */
+ Stream_Write_UINT32(s,
+ audin->context.frames_per_packet); /* FramesPerPacket (4 bytes) */
+ Stream_Write_UINT32(s,
+ audin->context.selected_client_format); /* initialFormat (4 bytes) */
/*
* [MS-RDPEAI] 3.2.5.1.6
* The second format specify the format that SHOULD be used to capture data from
Stream_Write_UINT16(s, 4); /* nBlockAlign */
Stream_Write_UINT16(s, 16); /* wBitsPerSample */
Stream_Write_UINT16(s, 0); /* cbSize */
-
- return WTSVirtualChannelWrite(audin->audin_channel, (PCHAR) Stream_Buffer(s), Stream_GetPosition(s), &written) ? CHANNEL_RC_OK : ERROR_INTERNAL_ERROR;
+ return WTSVirtualChannelWrite(audin->audin_channel, (PCHAR) Stream_Buffer(s),
+ Stream_GetPosition(s), &written) ? CHANNEL_RC_OK : ERROR_INTERNAL_ERROR;
}
/**
*
* @return 0 on success, otherwise a Win32 error code
*/
-static UINT audin_server_recv_open_reply(audin_server* audin, wStream* s, UINT32 length)
+static UINT audin_server_recv_open_reply(audin_server* audin, wStream* s,
+ UINT32 length)
{
-
UINT32 Result;
UINT success = CHANNEL_RC_OK;
if (length < 4)
{
- WLog_ERR(TAG, "error parsing version info: expected at least 4 bytes, got %d", length);
+ WLog_ERR(TAG, "error parsing version info: expected at least 4 bytes, got %d",
+ length);
return ERROR_INVALID_DATA;
}
Stream_Read_UINT32(s, Result);
-
IFCALLRET(audin->context.OpenResult, success, &audin->context, Result);
- if (success)
- WLog_ERR(TAG, "context.OpenResult failed with error %lu", success);
+ if (success)
+ WLog_ERR(TAG, "context.OpenResult failed with error %lu", success);
return success;
}
*
* @return 0 on success, otherwise a Win32 error code
*/
-static UINT audin_server_recv_data(audin_server* audin, wStream* s, UINT32 length)
+static UINT audin_server_recv_data(audin_server* audin, wStream* s,
+ UINT32 length)
{
AUDIO_FORMAT* format;
int sbytes_per_sample;
if (audin->context.selected_client_format < 0)
{
WLog_ERR(TAG, "audin->context.selected_client_format = %d",
- audin->context.selected_client_format);
+ audin->context.selected_client_format);
return ERROR_INVALID_DATA;
}
if (format->wFormatTag == WAVE_FORMAT_ADPCM)
{
audin->dsp_context->decode_ms_adpcm(audin->dsp_context,
- Stream_Pointer(s), length, format->nChannels, format->nBlockAlign);
+ Stream_Pointer(s), length, format->nChannels, format->nBlockAlign);
size = audin->dsp_context->adpcm_size;
src = audin->dsp_context->adpcm_buffer;
sbytes_per_sample = 2;
else if (format->wFormatTag == WAVE_FORMAT_DVI_ADPCM)
{
audin->dsp_context->decode_ima_adpcm(audin->dsp_context,
- Stream_Pointer(s), length, format->nChannels, format->nBlockAlign);
+ Stream_Pointer(s), length, format->nChannels, format->nBlockAlign);
size = audin->dsp_context->adpcm_size;
src = audin->dsp_context->adpcm_buffer;
sbytes_per_sample = 2;
sbytes_per_frame = format->nChannels * sbytes_per_sample;
}
- if (format->nSamplesPerSec == audin->context.dst_format.nSamplesPerSec && format->nChannels == audin->context.dst_format.nChannels)
+ if (format->nSamplesPerSec == audin->context.dst_format.nSamplesPerSec
+ && format->nChannels == audin->context.dst_format.nChannels)
{
frames = size / sbytes_per_frame;
}
else
{
audin->dsp_context->resample(audin->dsp_context, src, sbytes_per_sample,
- format->nChannels, format->nSamplesPerSec, size / sbytes_per_frame,
- audin->context.dst_format.nChannels, audin->context.dst_format.nSamplesPerSec);
+ format->nChannels, format->nSamplesPerSec, size / sbytes_per_frame,
+ audin->context.dst_format.nChannels, audin->context.dst_format.nSamplesPerSec);
frames = audin->dsp_context->resampled_frames;
src = audin->dsp_context->resampled_buffer;
}
IFCALLRET(audin->context.ReceiveSamples, success, &audin->context, src, frames);
- if (success)
- WLog_ERR(TAG, "context.ReceiveSamples failed with error %lu", success);
+ if (success)
+ WLog_ERR(TAG, "context.ReceiveSamples failed with error %lu", success);
- return success;
+ return success;
}
static void* audin_server_thread_func(void* arg)
audin_server* audin = (audin_server*) arg;
UINT error = CHANNEL_RC_OK;
DWORD status;
-
buffer = NULL;
BytesReturned = 0;
ChannelEvent = NULL;
-
freerdp_channel_init_thread_context(audin->context.rdpcontext);
- if (WTSVirtualChannelQuery(audin->audin_channel, WTSVirtualEventHandle, &buffer, &BytesReturned) == TRUE)
+
+ if (WTSVirtualChannelQuery(audin->audin_channel, WTSVirtualEventHandle, &buffer,
+ &BytesReturned) == TRUE)
{
if (BytesReturned == sizeof(HANDLE))
CopyMemory(&ChannelEvent, buffer, sizeof(HANDLE));
while (1)
{
- if ((status = WaitForMultipleObjects(nCount, events, FALSE, 100)) == WAIT_OBJECT_0)
+ if ((status = WaitForMultipleObjects(nCount, events, FALSE,
+ 100)) == WAIT_OBJECT_0)
goto out;
if (status == WAIT_FAILED)
{
- error = GetLastError();
+ error = GetLastError();
WLog_ERR(TAG, "WaitForMultipleObjects failed with error %lu", error);
goto out;
}
- if (WTSVirtualChannelQuery(audin->audin_channel, WTSVirtualChannelReady, &buffer, &BytesReturned) == FALSE)
+ if (WTSVirtualChannelQuery(audin->audin_channel, WTSVirtualChannelReady,
+ &buffer, &BytesReturned) == FALSE)
{
WLog_ERR(TAG, "WTSVirtualChannelQuery failed");
error = ERROR_INTERNAL_ERROR;
}
ready = *((BOOL*) buffer);
-
WTSFreeMemory(buffer);
if (ready)
}
s = Stream_New(NULL, 4096);
+
if (!s)
{
WLog_ERR(TAG, "Stream_New failed!");
goto out;
}
-
if (ready)
{
if ((error = audin_server_send_version(audin, s)))
while (ready)
{
- if ((status = WaitForMultipleObjects(nCount, events, FALSE, INFINITE)) == WAIT_OBJECT_0)
+ if ((status = WaitForMultipleObjects(nCount, events, FALSE,
+ INFINITE)) == WAIT_OBJECT_0)
break;
if (status == WAIT_FAILED)
{
- error = GetLastError();
- WLog_ERR(TAG, "WaitForMultipleObjects failed with error %lu", error);
- goto out;
+ error = GetLastError();
+ WLog_ERR(TAG, "WaitForMultipleObjects failed with error %lu", error);
+ goto out;
}
Stream_SetPosition(s, 0);
error = ERROR_INTERNAL_ERROR;
break;
}
+
if (BytesReturned < 1)
continue;
+
if (!Stream_EnsureRemainingCapacity(s, BytesReturned))
break;
+
if (WTSVirtualChannelRead(audin->audin_channel, 0, (PCHAR) Stream_Buffer(s),
- Stream_Capacity(s), &BytesReturned) == FALSE)
+ Stream_Capacity(s), &BytesReturned) == FALSE)
{
WLog_ERR(TAG, "WTSVirtualChannelRead failed!");
error = ERROR_INTERNAL_ERROR;
case MSG_SNDIN_VERSION:
if ((error = audin_server_recv_version(audin, s, BytesReturned)))
{
- WLog_ERR(TAG, "audin_server_recv_version failed with error %lu!", error);
- goto out_capacity;
- }
+ WLog_ERR(TAG, "audin_server_recv_version failed with error %lu!", error);
+ goto out_capacity;
+ }
+
if ((error = audin_server_send_formats(audin, s)))
{
WLog_ERR(TAG, "audin_server_send_formats failed with error %lu!", error);
goto out_capacity;
}
+
break;
case MSG_SNDIN_FORMATS:
WLog_ERR(TAG, "audin_server_recv_formats failed with error %lu!", error);
goto out_capacity;
}
+
if ((error = audin_server_send_open(audin, s)))
{
WLog_ERR(TAG, "audin_server_send_open failed with error %lu!", error);
goto out_capacity;
}
+
break;
case MSG_SNDIN_OPEN_REPLY:
WLog_ERR(TAG, "audin_server_recv_open_reply failed with error %lu!", error);
goto out_capacity;
}
+
break;
case MSG_SNDIN_DATA_INCOMING:
WLog_ERR(TAG, "audin_server_recv_data failed with error %lu!", error);
goto out_capacity;
};
+
break;
case MSG_SNDIN_FORMATCHANGE:
out:
WTSVirtualChannelClose(audin->audin_channel);
audin->audin_channel = NULL;
+
if (error && audin->context.rdpcontext)
- setChannelError(audin->context.rdpcontext, error, "audin_server_thread_func reported an error");
+ setChannelError(audin->context.rdpcontext, error,
+ "audin_server_thread_func reported an error");
ExitThread((DWORD)error);
return NULL;
{
PULONG pSessionId = NULL;
DWORD BytesReturned = 0;
-
audin->SessionId = WTS_CURRENT_SESSION;
if (WTSQuerySessionInformationA(context->vcm, WTS_CURRENT_SESSION,
- WTSSessionId, (LPSTR*) &pSessionId, &BytesReturned))
+ WTSSessionId, (LPSTR*) &pSessionId, &BytesReturned))
{
- audin->SessionId = (DWORD) *pSessionId;
+ audin->SessionId = (DWORD) * pSessionId;
WTSFreeMemory(pSessionId);
}
audin->audin_channel = WTSVirtualChannelOpenEx(audin->SessionId,
- "AUDIO_INPUT", WTS_CHANNEL_OPTION_DYNAMIC);
+ "AUDIO_INPUT", WTS_CHANNEL_OPTION_DYNAMIC);
if (!audin->audin_channel)
{
}
if (!(audin->thread = CreateThread(NULL, 0,
- (LPTHREAD_START_ROUTINE) audin_server_thread_func, (void*) audin, 0, NULL)))
+ (LPTHREAD_START_ROUTINE) audin_server_thread_func, (void*) audin, 0, NULL)))
{
WLog_ERR(TAG, "CreateThread failed!");
CloseHandle(audin->stopEvent);
return TRUE;
}
+
WLog_ERR(TAG, "thread already running!");
return FALSE;
}
if (audin->thread)
{
SetEvent(audin->stopEvent);
+
if (WaitForSingleObject(audin->thread, INFINITE) == WAIT_FAILED)
- {
- WLog_ERR(TAG, "WaitForSingleObject failed with error %lu", GetLastError());
- return FALSE;
- }
+ {
+ WLog_ERR(TAG, "WaitForSingleObject failed with error %lu", GetLastError());
+ return FALSE;
+ }
CloseHandle(audin->thread);
CloseHandle(audin->stopEvent);
}
audin->context.selected_client_format = -1;
-
return TRUE;
}
audin_server_context* audin_server_context_new(HANDLE vcm)
{
audin_server* audin;
+ audin = (audin_server*)calloc(1, sizeof(audin_server));
- audin = (audin_server *)calloc(1, sizeof(audin_server));
if (!audin)
{
WLog_ERR(TAG, "calloc failed!");
audin->context.SelectFormat = audin_server_select_format;
audin->context.Open = audin_server_open;
audin->context.Close = audin_server_close;
-
audin->dsp_context = freerdp_dsp_context_new();
if (!audin->dsp_context)
void audin_server_context_free(audin_server_context* context)
{
audin_server* audin = (audin_server*) context;
-
audin_server_close(context);
if (audin->dsp_context)
}
static wStream* cliprdr_packet_new(UINT16 msgType, UINT16 msgFlags,
- UINT32 dataLen)
+ UINT32 dataLen)
{
wStream* s;
s = Stream_New(NULL, dataLen + 8);
else
{
status = cliprdr->channelEntryPoints.pVirtualChannelWrite(cliprdr->OpenHandle,
- Stream_Buffer(s), (UINT32) Stream_GetPosition(s), s);
+ Stream_Buffer(s), (UINT32) Stream_GetPosition(s), s);
}
if (status != CHANNEL_RC_OK)
WLog_ERR(TAG, "VirtualChannelWrite failed with %s [%08X]",
- WTSErrorToString(status), status);
+ WTSErrorToString(status), status);
return status;
}
* @return 0 on success, otherwise a Win32 error code
*/
static UINT cliprdr_process_general_capability(cliprdrPlugin* cliprdr,
- wStream* s)
+ wStream* s)
{
UINT32 version;
UINT32 generalFlags;
if (cliprdr->useLongFormatNames)
cliprdr->useLongFormatNames = (generalFlags & CB_USE_LONG_FORMAT_NAMES) ? TRUE :
- FALSE;
+ FALSE;
if (cliprdr->streamFileClipEnabled)
cliprdr->streamFileClipEnabled = (generalFlags & CB_STREAM_FILECLIP_ENABLED) ?
- TRUE : FALSE;
+ TRUE : FALSE;
if (cliprdr->fileClipNoFilePaths)
cliprdr->fileClipNoFilePaths = (generalFlags & CB_FILECLIP_NO_FILE_PATHS) ?
- TRUE : FALSE;
+ TRUE : FALSE;
if (cliprdr->canLockClipData)
cliprdr->canLockClipData = (generalFlags & CB_CAN_LOCK_CLIPDATA) ? TRUE : FALSE;
capabilities.cCapabilitiesSets = 1;
capabilities.capabilitySets = (CLIPRDR_CAPABILITY_SET*) &
- (generalCapabilitySet);
+ (generalCapabilitySet);
generalCapabilitySet.capabilitySetType = CB_CAPSTYPE_GENERAL;
generalCapabilitySet.capabilitySetLength = 12;
generalCapabilitySet.version = version;
* @return 0 on success, otherwise a Win32 error code
*/
static UINT cliprdr_process_clip_caps(cliprdrPlugin* cliprdr, wStream* s,
- UINT16 length, UINT16 flags)
+ UINT16 length, UINT16 flags)
{
UINT16 index;
UINT16 lengthCapability;
if ((error = cliprdr_process_general_capability(cliprdr, s)))
{
WLog_ERR(TAG, "cliprdr_process_general_capability failed with error %lu!",
- error);
+ error);
return error;
}
* @return 0 on success, otherwise a Win32 error code
*/
static UINT cliprdr_process_monitor_ready(cliprdrPlugin* cliprdr, wStream* s,
- UINT16 length, UINT16 flags)
+ UINT16 length, UINT16 flags)
{
CLIPRDR_MONITOR_READY monitorReady;
CliprdrClientContext* context = cliprdr_get_client_interface(cliprdr);
* @return 0 on success, otherwise a Win32 error code
*/
static UINT cliprdr_process_filecontents_request(cliprdrPlugin* cliprdr,
- wStream* s, UINT32 length, UINT16 flags)
+ wStream* s, UINT32 length, UINT16 flags)
{
CLIPRDR_FILE_CONTENTS_REQUEST request;
CliprdrClientContext* context = cliprdr_get_client_interface(cliprdr);
* @return 0 on success, otherwise a Win32 error code
*/
static UINT cliprdr_process_filecontents_response(cliprdrPlugin* cliprdr,
- wStream* s, UINT32 length, UINT16 flags)
+ wStream* s, UINT32 length, UINT16 flags)
{
CLIPRDR_FILE_CONTENTS_RESPONSE response;
CliprdrClientContext* context = cliprdr_get_client_interface(cliprdr);
* @return 0 on success, otherwise a Win32 error code
*/
static UINT cliprdr_process_lock_clipdata(cliprdrPlugin* cliprdr, wStream* s,
- UINT32 length, UINT16 flags)
+ UINT32 length, UINT16 flags)
{
CLIPRDR_LOCK_CLIPBOARD_DATA lockClipboardData;
CliprdrClientContext* context = cliprdr_get_client_interface(cliprdr);
* @return 0 on success, otherwise a Win32 error code
*/
static UINT cliprdr_process_unlock_clipdata(cliprdrPlugin* cliprdr, wStream* s,
- UINT32 length, UINT16 flags)
+ UINT32 length, UINT16 flags)
{
CLIPRDR_UNLOCK_CLIPBOARD_DATA unlockClipboardData;
CliprdrClientContext* context = cliprdr_get_client_interface(cliprdr);
unlockClipboardData.msgFlags = flags;
unlockClipboardData.dataLen = length;
Stream_Read_UINT32(s,
- unlockClipboardData.clipDataId); /* clipDataId (4 bytes) */
+ unlockClipboardData.clipDataId); /* clipDataId (4 bytes) */
IFCALLRET(context->ServerUnlockClipboardData, error, context,
- &unlockClipboardData);
+ &unlockClipboardData);
if (error)
WLog_ERR(TAG, "ServerUnlockClipboardData failed with error %lu!", error);
Stream_Read_UINT32(s, dataLen); /* dataLen (4 bytes) */
#ifdef WITH_DEBUG_CLIPRDR
WLog_DBG(TAG, "msgType: %s (%d), msgFlags: %d dataLen: %d",
- CB_MSG_TYPE_STRINGS[msgType], msgType, msgFlags, dataLen);
+ CB_MSG_TYPE_STRINGS[msgType], msgType, msgFlags, dataLen);
winpr_HexDump(TAG, WLOG_DEBUG, Stream_Buffer(s), dataLen + 8);
#endif
case CB_FORMAT_LIST_RESPONSE:
if ((error = cliprdr_process_format_list_response(cliprdr, s, dataLen,
- msgFlags)))
+ msgFlags)))
WLog_ERR(TAG, "cliprdr_process_format_list_response failed with error %lu!",
- error);
+ error);
break;
case CB_FORMAT_DATA_REQUEST:
if ((error = cliprdr_process_format_data_request(cliprdr, s, dataLen,
- msgFlags)))
+ msgFlags)))
WLog_ERR(TAG, "cliprdr_process_format_data_request failed with error %lu!",
- error);
+ error);
break;
case CB_FORMAT_DATA_RESPONSE:
if ((error = cliprdr_process_format_data_response(cliprdr, s, dataLen,
- msgFlags)))
+ msgFlags)))
WLog_ERR(TAG, "cliprdr_process_format_data_response failed with error %lu!",
- error);
+ error);
break;
case CB_FILECONTENTS_REQUEST:
if ((error = cliprdr_process_filecontents_request(cliprdr, s, dataLen,
- msgFlags)))
+ msgFlags)))
WLog_ERR(TAG, "cliprdr_process_filecontents_request failed with error %lu!",
- error);
+ error);
break;
case CB_FILECONTENTS_RESPONSE:
if ((error = cliprdr_process_filecontents_response(cliprdr, s, dataLen,
- msgFlags)))
+ msgFlags)))
WLog_ERR(TAG, "cliprdr_process_filecontents_response failed with error %lu!",
- error);
+ error);
break;
* @return 0 on success, otherwise a Win32 error code
*/
static UINT cliprdr_client_capabilities(CliprdrClientContext* context,
- CLIPRDR_CAPABILITIES* capabilities)
+ CLIPRDR_CAPABILITIES* capabilities)
{
wStream* s;
CLIPRDR_GENERAL_CAPABILITY_SET* generalCapabilitySet;
Stream_Write_UINT16(s, 1); /* cCapabilitiesSets */
Stream_Write_UINT16(s, 0); /* pad1 */
generalCapabilitySet = (CLIPRDR_GENERAL_CAPABILITY_SET*)
- capabilities->capabilitySets;
+ capabilities->capabilitySets;
Stream_Write_UINT16(s,
- generalCapabilitySet->capabilitySetType); /* capabilitySetType */
+ generalCapabilitySet->capabilitySetType); /* capabilitySetType */
Stream_Write_UINT16(s,
- generalCapabilitySet->capabilitySetLength); /* lengthCapability */
+ generalCapabilitySet->capabilitySetLength); /* lengthCapability */
Stream_Write_UINT32(s, generalCapabilitySet->version); /* version */
Stream_Write_UINT32(s, generalCapabilitySet->generalFlags); /* generalFlags */
WLog_Print(cliprdr->log, WLOG_DEBUG, "ClientCapabilities");
* @return 0 on success, otherwise a Win32 error code
*/
static UINT cliprdr_temp_directory(CliprdrClientContext* context,
- CLIPRDR_TEMP_DIRECTORY* tempDirectory)
+ CLIPRDR_TEMP_DIRECTORY* tempDirectory)
{
int length;
wStream* s;
}
length = ConvertToUnicode(CP_UTF8, 0, tempDirectory->szTempDir, -1, &wszTempDir,
- 0);
+ 0);
if (length < 0)
return ERROR_INTERNAL_ERROR;
Stream_Zero(s, (520 - length) * 2);
free(wszTempDir);
WLog_Print(cliprdr->log, WLOG_DEBUG, "TempDirectory: %s",
- tempDirectory->szTempDir);
+ tempDirectory->szTempDir);
return cliprdr_packet_send(cliprdr, s);
}
* @return 0 on success, otherwise a Win32 error code
*/
static UINT cliprdr_client_format_list(CliprdrClientContext* context,
- CLIPRDR_FORMAT_LIST* formatList)
+ CLIPRDR_FORMAT_LIST* formatList)
{
wStream* s;
UINT32 index;
if (szFormatName)
formatNameSize = ConvertToUnicode(CP_UTF8, 0, szFormatName, -1, &wszFormatName,
- 0);
+ 0);
if (formatNameSize > 15)
formatNameSize = 15;
if (format->formatName)
formatNameSize = MultiByteToWideChar(CP_UTF8, 0, format->formatName, -1, NULL,
- 0) * 2;
+ 0) * 2;
length += formatNameSize;
}
lpWideCharStr = (LPWSTR) Stream_Pointer(s);
cchWideChar = (Stream_Capacity(s) - Stream_GetPosition(s)) / 2;
formatNameSize = MultiByteToWideChar(CP_UTF8, 0,
- format->formatName, -1, lpWideCharStr, cchWideChar) * 2;
+ format->formatName, -1, lpWideCharStr, cchWideChar) * 2;
Stream_Seek(s, formatNameSize);
}
else
}
WLog_Print(cliprdr->log, WLOG_DEBUG, "ClientFormatList: numFormats: %d",
- formatList->numFormats);
+ formatList->numFormats);
return cliprdr_packet_send(cliprdr, s);
}
* @return 0 on success, otherwise a Win32 error code
*/
static UINT cliprdr_client_format_list_response(CliprdrClientContext* context,
- CLIPRDR_FORMAT_LIST_RESPONSE* formatListResponse)
+ CLIPRDR_FORMAT_LIST_RESPONSE* formatListResponse)
{
wStream* s;
cliprdrPlugin* cliprdr = (cliprdrPlugin*) context->handle;
formatListResponse->msgType = CB_FORMAT_LIST_RESPONSE;
formatListResponse->dataLen = 0;
s = cliprdr_packet_new(formatListResponse->msgType,
- formatListResponse->msgFlags, formatListResponse->dataLen);
+ formatListResponse->msgFlags, formatListResponse->dataLen);
if (!s)
{
* @return 0 on success, otherwise a Win32 error code
*/
static UINT cliprdr_client_lock_clipboard_data(CliprdrClientContext* context,
- CLIPRDR_LOCK_CLIPBOARD_DATA* lockClipboardData)
+ CLIPRDR_LOCK_CLIPBOARD_DATA* lockClipboardData)
{
wStream* s;
cliprdrPlugin* cliprdr = (cliprdrPlugin*) context->handle;
}
Stream_Write_UINT32(s,
- lockClipboardData->clipDataId); /* clipDataId (4 bytes) */
+ lockClipboardData->clipDataId); /* clipDataId (4 bytes) */
WLog_Print(cliprdr->log, WLOG_DEBUG,
- "ClientLockClipboardData: clipDataId: 0x%04X",
- lockClipboardData->clipDataId);
+ "ClientLockClipboardData: clipDataId: 0x%04X",
+ lockClipboardData->clipDataId);
return cliprdr_packet_send(cliprdr, s);;
}
* @return 0 on success, otherwise a Win32 error code
*/
static UINT cliprdr_client_unlock_clipboard_data(CliprdrClientContext* context,
- CLIPRDR_UNLOCK_CLIPBOARD_DATA* unlockClipboardData)
+ CLIPRDR_UNLOCK_CLIPBOARD_DATA* unlockClipboardData)
{
wStream* s;
cliprdrPlugin* cliprdr = (cliprdrPlugin*) context->handle;
}
Stream_Write_UINT32(s,
- unlockClipboardData->clipDataId); /* clipDataId (4 bytes) */
+ unlockClipboardData->clipDataId); /* clipDataId (4 bytes) */
WLog_Print(cliprdr->log, WLOG_DEBUG,
- "ClientUnlockClipboardData: clipDataId: 0x%04X",
- unlockClipboardData->clipDataId);
+ "ClientUnlockClipboardData: clipDataId: 0x%04X",
+ unlockClipboardData->clipDataId);
return cliprdr_packet_send(cliprdr, s);
}
* @return 0 on success, otherwise a Win32 error code
*/
static UINT cliprdr_client_format_data_request(CliprdrClientContext* context,
- CLIPRDR_FORMAT_DATA_REQUEST* formatDataRequest)
+ CLIPRDR_FORMAT_DATA_REQUEST* formatDataRequest)
{
wStream* s;
cliprdrPlugin* cliprdr = (cliprdrPlugin*) context->handle;
formatDataRequest->msgFlags = 0;
formatDataRequest->dataLen = 4;
s = cliprdr_packet_new(formatDataRequest->msgType, formatDataRequest->msgFlags,
- formatDataRequest->dataLen);
+ formatDataRequest->dataLen);
if (!s)
{
}
Stream_Write_UINT32(s,
- formatDataRequest->requestedFormatId); /* requestedFormatId (4 bytes) */
+ formatDataRequest->requestedFormatId); /* requestedFormatId (4 bytes) */
WLog_Print(cliprdr->log, WLOG_DEBUG, "ClientFormatDataRequest");
return cliprdr_packet_send(cliprdr, s);
}
* @return 0 on success, otherwise a Win32 error code
*/
static UINT cliprdr_client_format_data_response(CliprdrClientContext* context,
- CLIPRDR_FORMAT_DATA_RESPONSE* formatDataResponse)
+ CLIPRDR_FORMAT_DATA_RESPONSE* formatDataResponse)
{
wStream* s;
cliprdrPlugin* cliprdr = (cliprdrPlugin*) context->handle;
formatDataResponse->msgType = CB_FORMAT_DATA_RESPONSE;
s = cliprdr_packet_new(formatDataResponse->msgType,
- formatDataResponse->msgFlags, formatDataResponse->dataLen);
+ formatDataResponse->msgFlags, formatDataResponse->dataLen);
if (!s)
{
}
Stream_Write(s, formatDataResponse->requestedFormatData,
- formatDataResponse->dataLen);
+ formatDataResponse->dataLen);
WLog_Print(cliprdr->log, WLOG_DEBUG, "ClientFormatDataResponse");
return cliprdr_packet_send(cliprdr, s);
}
* @return 0 on success, otherwise a Win32 error code
*/
static UINT cliprdr_client_file_contents_request(CliprdrClientContext* context,
- CLIPRDR_FILE_CONTENTS_REQUEST* fileContentsRequest)
+ CLIPRDR_FILE_CONTENTS_REQUEST* fileContentsRequest)
{
wStream* s;
cliprdrPlugin* cliprdr = (cliprdrPlugin*) context->handle;
Stream_Write_UINT32(s, fileContentsRequest->streamId); /* streamId (4 bytes) */
Stream_Write_UINT32(s,
- fileContentsRequest->listIndex); /* listIndex (4 bytes) */
+ fileContentsRequest->listIndex); /* listIndex (4 bytes) */
Stream_Write_UINT32(s, fileContentsRequest->dwFlags); /* dwFlags (4 bytes) */
Stream_Write_UINT32(s,
- fileContentsRequest->nPositionLow); /* nPositionLow (4 bytes) */
+ fileContentsRequest->nPositionLow); /* nPositionLow (4 bytes) */
Stream_Write_UINT32(s,
- fileContentsRequest->nPositionHigh); /* nPositionHigh (4 bytes) */
+ fileContentsRequest->nPositionHigh); /* nPositionHigh (4 bytes) */
Stream_Write_UINT32(s,
- fileContentsRequest->cbRequested); /* cbRequested (4 bytes) */
+ fileContentsRequest->cbRequested); /* cbRequested (4 bytes) */
Stream_Write_UINT32(s,
- fileContentsRequest->clipDataId); /* clipDataId (4 bytes) */
+ fileContentsRequest->clipDataId); /* clipDataId (4 bytes) */
WLog_Print(cliprdr->log, WLOG_DEBUG,
- "ClientFileContentsRequest: streamId: 0x%04X",
- fileContentsRequest->streamId);
+ "ClientFileContentsRequest: streamId: 0x%04X",
+ fileContentsRequest->streamId);
return cliprdr_packet_send(cliprdr, s);
}
* @return 0 on success, otherwise a Win32 error code
*/
static UINT cliprdr_client_file_contents_response(CliprdrClientContext* context,
- CLIPRDR_FILE_CONTENTS_RESPONSE* fileContentsResponse)
+ CLIPRDR_FILE_CONTENTS_RESPONSE* fileContentsResponse)
{
wStream* s;
cliprdrPlugin* cliprdr = (cliprdrPlugin*) context->handle;
fileContentsResponse->cbRequested = sizeof(UINT64);
s = cliprdr_packet_new(CB_FILECONTENTS_RESPONSE, fileContentsResponse->msgFlags,
- 4 + fileContentsResponse->cbRequested);
+ 4 + fileContentsResponse->cbRequested);
if (!s)
{
* FILECONTENTS_RANGE: file data from requested range
*/
Stream_Write(s, fileContentsResponse->requestedData,
- fileContentsResponse->cbRequested);
+ fileContentsResponse->cbRequested);
WLog_Print(cliprdr->log, WLOG_DEBUG,
- "ClientFileContentsResponse: streamId: 0x%04X",
- fileContentsResponse->streamId);
+ "ClientFileContentsResponse: streamId: 0x%04X",
+ fileContentsResponse->streamId);
return cliprdr_packet_send(cliprdr, s);
}
* @return 0 on success, otherwise a Win32 error code
*/
static UINT cliprdr_virtual_channel_event_data_received(cliprdrPlugin* cliprdr,
- void* pData, UINT32 dataLength, UINT32 totalLength, UINT32 dataFlags)
+ void* pData, UINT32 dataLength, UINT32 totalLength, UINT32 dataFlags)
{
wStream* data_in;
}
static VOID VCAPITYPE cliprdr_virtual_channel_open_event(DWORD openHandle,
- UINT event,
- LPVOID pData, UINT32 dataLength, UINT32 totalLength, UINT32 dataFlags)
+ UINT event,
+ LPVOID pData, UINT32 dataLength, UINT32 totalLength, UINT32 dataFlags)
{
cliprdrPlugin* cliprdr = s_TLSPluginContext;
UINT error = CHANNEL_RC_OK;
{
case CHANNEL_EVENT_DATA_RECEIVED:
error = cliprdr_virtual_channel_event_data_received(cliprdr, pData, dataLength,
- totalLength, dataFlags);
+ totalLength, dataFlags);
break;
case CHANNEL_EVENT_WRITE_COMPLETE:
if (error && cliprdr->context->rdpcontext)
setChannelError(cliprdr->context->rdpcontext, error,
- "cliprdr_virtual_channel_open_event reported an error");
+ "cliprdr_virtual_channel_open_event reported an error");
}
static void* cliprdr_virtual_channel_client_thread(void* arg)
wMessage message;
cliprdrPlugin* cliprdr = (cliprdrPlugin*) arg;
UINT error = CHANNEL_RC_OK;
-
freerdp_channel_init_thread_context(cliprdr->context->rdpcontext);
while (1)
if (error && cliprdr->context->rdpcontext)
setChannelError(cliprdr->context->rdpcontext, error,
- "cliprdr_virtual_channel_client_thread reported an error");
+ "cliprdr_virtual_channel_client_thread reported an error");
ExitThread((DWORD)error);
return NULL;
* @return 0 on success, otherwise a Win32 error code
*/
static UINT cliprdr_virtual_channel_event_connected(cliprdrPlugin* cliprdr,
- LPVOID pData, UINT32 dataLength)
+ LPVOID pData, UINT32 dataLength)
{
UINT32 status;
status = cliprdr->channelEntryPoints.pVirtualChannelOpen(cliprdr->InitHandle,
- &cliprdr->OpenHandle, cliprdr->channelDef.name,
- cliprdr_virtual_channel_open_event);
+ &cliprdr->OpenHandle, cliprdr->channelDef.name,
+ cliprdr_virtual_channel_open_event);
if (status != CHANNEL_RC_OK)
{
WLog_ERR(TAG, "pVirtualChannelOpen failed with %s [%08X]",
- WTSErrorToString(status), status);
+ WTSErrorToString(status), status);
return status;
}
}
if (!(cliprdr->thread = CreateThread(NULL, 0,
- (LPTHREAD_START_ROUTINE) cliprdr_virtual_channel_client_thread, (void*) cliprdr,
- 0, NULL)))
+ (LPTHREAD_START_ROUTINE) cliprdr_virtual_channel_client_thread, (void*) cliprdr,
+ 0, NULL)))
{
WLog_ERR(TAG, "CreateThread failed!");
MessageQueue_Free(cliprdr->queue);
if (CHANNEL_RC_OK != rc)
{
WLog_ERR(TAG, "pVirtualChannelClose failed with %s [%08X]",
- WTSErrorToString(rc), rc);
+ WTSErrorToString(rc), rc);
return rc;
}
}
static VOID VCAPITYPE cliprdr_virtual_channel_init_event(LPVOID pInitHandle,
- UINT event, LPVOID pData,
- UINT dataLength)
+ UINT event, LPVOID pData,
+ UINT dataLength)
{
cliprdrPlugin* cliprdr = s_TLSPluginContext;
UINT error = CHANNEL_RC_OK;
{
case CHANNEL_EVENT_CONNECTED:
if ((error = cliprdr_virtual_channel_event_connected(cliprdr, pData,
- dataLength)))
+ dataLength)))
WLog_ERR(TAG, "cliprdr_virtual_channel_event_connected failed with error %lu!",
- error);
+ error);
break;
case CHANNEL_EVENT_DISCONNECTED:
if ((error = cliprdr_virtual_channel_event_disconnected(cliprdr)))
WLog_ERR(TAG,
- "cliprdr_virtual_channel_event_disconnected failed with error %lu!", error);
+ "cliprdr_virtual_channel_event_disconnected failed with error %lu!", error);
break;
case CHANNEL_EVENT_TERMINATED:
if ((error = cliprdr_virtual_channel_event_terminated(cliprdr)))
WLog_ERR(TAG, "cliprdr_virtual_channel_event_terminated failed with error %lu!",
- error);
+ error);
break;
}
if (error && cliprdr->context->rdpcontext)
setChannelError(cliprdr->context->rdpcontext, error,
- "cliprdr_virtual_channel_init_event reported an error");
+ "cliprdr_virtual_channel_init_event reported an error");
}
/* cliprdr is always built-in */
cliprdr->canLockClipData = FALSE;
WLog_Print(cliprdr->log, WLOG_DEBUG, "VirtualChannelEntry");
CopyMemory(&(cliprdr->channelEntryPoints), pEntryPoints,
- sizeof(CHANNEL_ENTRY_POINTS_FREERDP));
+ sizeof(CHANNEL_ENTRY_POINTS_FREERDP));
rc = cliprdr->channelEntryPoints.pVirtualChannelInit(&cliprdr->InitHandle,
- &cliprdr->channelDef, 1, VIRTUAL_CHANNEL_VERSION_WIN2000,
- cliprdr_virtual_channel_init_event);
+ &cliprdr->channelDef, 1, VIRTUAL_CHANNEL_VERSION_WIN2000,
+ cliprdr_virtual_channel_init_event);
if (CHANNEL_RC_OK != rc)
{
WLog_ERR(TAG, "pVirtualChannelInit failed with %s [%08X]",
- WTSErrorToString(rc), rc);
+ WTSErrorToString(rc), rc);
+
if (context)
*(pEntryPointsEx->ppInterface) = NULL;
}
cliprdr->channelEntryPoints.pInterface = *
- (cliprdr->channelEntryPoints.ppInterface);
+ (cliprdr->channelEntryPoints.ppInterface);
cliprdr->channelEntryPoints.ppInterface = &
- (cliprdr->channelEntryPoints.pInterface);
+ (cliprdr->channelEntryPoints.pInterface);
s_TLSPluginContext = cliprdr;
return TRUE;
}
*
*/
-wStream* cliprdr_server_packet_new(UINT16 msgType, UINT16 msgFlags, UINT32 dataLen)
+wStream* cliprdr_server_packet_new(UINT16 msgType, UINT16 msgFlags,
+ UINT32 dataLen)
{
wStream* s;
-
s = Stream_New(NULL, dataLen + 8);
- if(!s)
+ if (!s)
{
WLog_ERR(TAG, "Stream_New failed!");
return NULL;
Stream_Write_UINT16(s, msgType);
Stream_Write_UINT16(s, msgFlags);
-
/* Write actual length after the entire packet has been constructed. */
Stream_Seek(s, 4);
-
return s;
}
BOOL status;
UINT32 dataLen;
UINT32 written;
-
pos = Stream_GetPosition(s);
-
dataLen = pos - 8;
-
Stream_SetPosition(s, 4);
Stream_Write_UINT32(s, dataLen);
Stream_SetPosition(s, pos);
-
- status = WTSVirtualChannelWrite(cliprdr->ChannelHandle, (PCHAR) Stream_Buffer(s), Stream_Length(s), &written);
-
+ status = WTSVirtualChannelWrite(cliprdr->ChannelHandle,
+ (PCHAR) Stream_Buffer(s), Stream_Length(s), &written);
Stream_Free(s, TRUE);
-
return status ? CHANNEL_RC_OK : ERROR_INTERNAL_ERROR;
}
*
* @return 0 on success, otherwise a Win32 error code
*/
-static UINT cliprdr_server_capabilities(CliprdrServerContext* context, CLIPRDR_CAPABILITIES* capabilities)
+static UINT cliprdr_server_capabilities(CliprdrServerContext* context,
+ CLIPRDR_CAPABILITIES* capabilities)
{
wStream* s;
CLIPRDR_GENERAL_CAPABILITY_SET* generalCapabilitySet;
CliprdrServerPrivate* cliprdr = (CliprdrServerPrivate*) context->handle;
-
capabilities->msgType = CB_CLIP_CAPS;
capabilities->msgFlags = 0;
-
s = cliprdr_server_packet_new(CB_CLIP_CAPS, 0, 4 + CB_CAPSTYPE_GENERAL_LEN);
+
if (!s)
{
WLog_ERR(TAG, "cliprdr_server_packet_new failed!");
Stream_Write_UINT16(s, 1); /* cCapabilitiesSets (2 bytes) */
Stream_Write_UINT16(s, 0); /* pad1 (2 bytes) */
-
- generalCapabilitySet = (CLIPRDR_GENERAL_CAPABILITY_SET*) capabilities->capabilitySets;
- Stream_Write_UINT16(s, generalCapabilitySet->capabilitySetType); /* capabilitySetType (2 bytes) */
- Stream_Write_UINT16(s, generalCapabilitySet->capabilitySetLength); /* lengthCapability (2 bytes) */
+ generalCapabilitySet = (CLIPRDR_GENERAL_CAPABILITY_SET*)
+ capabilities->capabilitySets;
+ Stream_Write_UINT16(s,
+ generalCapabilitySet->capabilitySetType); /* capabilitySetType (2 bytes) */
+ Stream_Write_UINT16(s,
+ generalCapabilitySet->capabilitySetLength); /* lengthCapability (2 bytes) */
Stream_Write_UINT32(s, generalCapabilitySet->version); /* version (4 bytes) */
- Stream_Write_UINT32(s, generalCapabilitySet->generalFlags); /* generalFlags (4 bytes) */
-
+ Stream_Write_UINT32(s,
+ generalCapabilitySet->generalFlags); /* generalFlags (4 bytes) */
WLog_DBG(TAG, "ServerCapabilities");
return cliprdr_server_packet_send(cliprdr, s);
}
*
* @return 0 on success, otherwise a Win32 error code
*/
-static UINT cliprdr_server_monitor_ready(CliprdrServerContext* context, CLIPRDR_MONITOR_READY* monitorReady)
+static UINT cliprdr_server_monitor_ready(CliprdrServerContext* context,
+ CLIPRDR_MONITOR_READY* monitorReady)
{
wStream* s;
CliprdrServerPrivate* cliprdr = (CliprdrServerPrivate*) context->handle;
-
monitorReady->msgType = CB_MONITOR_READY;
monitorReady->msgFlags = 0;
monitorReady->dataLen = 0;
-
s = cliprdr_server_packet_new(monitorReady->msgType,
- monitorReady->msgFlags, monitorReady->dataLen);
+ monitorReady->msgFlags, monitorReady->dataLen);
+
if (!s)
{
WLog_ERR(TAG, "cliprdr_server_packet_new failed!");
*
* @return 0 on success, otherwise a Win32 error code
*/
-static UINT cliprdr_server_format_list(CliprdrServerContext* context, CLIPRDR_FORMAT_LIST* formatList)
+static UINT cliprdr_server_format_list(CliprdrServerContext* context,
+ CLIPRDR_FORMAT_LIST* formatList)
{
wStream* s;
UINT32 index;
if (!context->useLongFormatNames)
{
length = formatList->numFormats * 36;
-
s = cliprdr_server_packet_new(CB_FORMAT_LIST, 0, length);
+
if (!s)
{
WLog_ERR(TAG, "cliprdr_server_packet_new failed!");
for (index = 0; index < formatList->numFormats; index++)
{
- format = (CLIPRDR_FORMAT*) &(formatList->formats[index]);
-
+ format = (CLIPRDR_FORMAT*) & (formatList->formats[index]);
Stream_Write_UINT32(s, format->formatId); /* formatId (4 bytes) */
-
formatNameSize = 0;
formatNameLength = 0;
-
szFormatName = format->formatName;
if (asciiNames)
wszFormatName = NULL;
if (szFormatName)
- formatNameSize = ConvertToUnicode(CP_UTF8, 0, szFormatName, -1, &wszFormatName, 0);
+ formatNameSize = ConvertToUnicode(CP_UTF8, 0, szFormatName, -1, &wszFormatName,
+ 0);
if (formatNameSize > 15)
formatNameSize = 15;
Stream_Write(s, wszFormatName, formatNameSize * 2);
Stream_Zero(s, 32 - (formatNameSize * 2));
-
free(wszFormatName);
}
}
{
for (index = 0; index < formatList->numFormats; index++)
{
- format = (CLIPRDR_FORMAT*) &(formatList->formats[index]);
+ format = (CLIPRDR_FORMAT*) & (formatList->formats[index]);
length += 4;
formatNameSize = 2;
if (format->formatName)
- formatNameSize = MultiByteToWideChar(CP_UTF8, 0, format->formatName, -1, NULL, 0) * 2;
+ formatNameSize = MultiByteToWideChar(CP_UTF8, 0, format->formatName, -1, NULL,
+ 0) * 2;
length += formatNameSize;
}
for (index = 0; index < formatList->numFormats; index++)
{
- format = (CLIPRDR_FORMAT*) &(formatList->formats[index]);
+ format = (CLIPRDR_FORMAT*) & (formatList->formats[index]);
Stream_Write_UINT32(s, format->formatId); /* formatId (4 bytes) */
if (format->formatName)
lpWideCharStr = (LPWSTR) Stream_Pointer(s);
cchWideChar = (Stream_Capacity(s) - Stream_GetPosition(s)) / 2;
formatNameSize = MultiByteToWideChar(CP_UTF8, 0,
- format->formatName, -1, lpWideCharStr, cchWideChar) * 2;
+ format->formatName, -1, lpWideCharStr, cchWideChar) * 2;
Stream_Seek(s, formatNameSize);
}
else
}
WLog_DBG(TAG, "ServerFormatList: numFormats: %d",
- formatList->numFormats);
-
+ formatList->numFormats);
return cliprdr_server_packet_send(cliprdr, s);
}
*
* @return 0 on success, otherwise a Win32 error code
*/
-static UINT cliprdr_server_format_list_response(CliprdrServerContext* context, CLIPRDR_FORMAT_LIST_RESPONSE* formatListResponse)
+static UINT cliprdr_server_format_list_response(CliprdrServerContext* context,
+ CLIPRDR_FORMAT_LIST_RESPONSE* formatListResponse)
{
wStream* s;
CliprdrServerPrivate* cliprdr = (CliprdrServerPrivate*) context->handle;
-
formatListResponse->msgType = CB_FORMAT_LIST_RESPONSE;
formatListResponse->dataLen = 0;
-
s = cliprdr_server_packet_new(formatListResponse->msgType,
- formatListResponse->msgFlags, formatListResponse->dataLen);
+ formatListResponse->msgFlags, formatListResponse->dataLen);
if (!s)
{
*
* @return 0 on success, otherwise a Win32 error code
*/
-static UINT cliprdr_server_lock_clipboard_data(CliprdrServerContext* context, CLIPRDR_LOCK_CLIPBOARD_DATA* lockClipboardData)
+static UINT cliprdr_server_lock_clipboard_data(CliprdrServerContext* context,
+ CLIPRDR_LOCK_CLIPBOARD_DATA* lockClipboardData)
{
wStream* s;
CliprdrServerPrivate* cliprdr = (CliprdrServerPrivate*) context->handle;
-
s = cliprdr_server_packet_new(CB_LOCK_CLIPDATA, 0, 4);
if (!s)
return ERROR_INTERNAL_ERROR;
}
- Stream_Write_UINT32(s, lockClipboardData->clipDataId); /* clipDataId (4 bytes) */
-
+ Stream_Write_UINT32(s,
+ lockClipboardData->clipDataId); /* clipDataId (4 bytes) */
WLog_DBG(TAG, "ServerLockClipboardData: clipDataId: 0x%04X",
- lockClipboardData->clipDataId);
-
+ lockClipboardData->clipDataId);
return cliprdr_server_packet_send(cliprdr, s);
}
*
* @return 0 on success, otherwise a Win32 error code
*/
-static UINT cliprdr_server_unlock_clipboard_data(CliprdrServerContext* context, CLIPRDR_UNLOCK_CLIPBOARD_DATA* unlockClipboardData)
+static UINT cliprdr_server_unlock_clipboard_data(CliprdrServerContext* context,
+ CLIPRDR_UNLOCK_CLIPBOARD_DATA* unlockClipboardData)
{
wStream* s;
CliprdrServerPrivate* cliprdr = (CliprdrServerPrivate*) context->handle;
-
s = cliprdr_server_packet_new(CB_UNLOCK_CLIPDATA, 0, 4);
if (!s)
return ERROR_INTERNAL_ERROR;
}
- Stream_Write_UINT32(s, unlockClipboardData->clipDataId); /* clipDataId (4 bytes) */
-
+ Stream_Write_UINT32(s,
+ unlockClipboardData->clipDataId); /* clipDataId (4 bytes) */
WLog_DBG(TAG, "ServerUnlockClipboardData: clipDataId: 0x%04X",
- unlockClipboardData->clipDataId);
-
+ unlockClipboardData->clipDataId);
return cliprdr_server_packet_send(cliprdr, s);
}
*
* @return 0 on success, otherwise a Win32 error code
*/
-static UINT cliprdr_server_format_data_request(CliprdrServerContext* context, CLIPRDR_FORMAT_DATA_REQUEST* formatDataRequest)
+static UINT cliprdr_server_format_data_request(CliprdrServerContext* context,
+ CLIPRDR_FORMAT_DATA_REQUEST* formatDataRequest)
{
wStream* s;
CliprdrServerPrivate* cliprdr = (CliprdrServerPrivate*) context->handle;
-
formatDataRequest->msgType = CB_FORMAT_DATA_REQUEST;
formatDataRequest->msgFlags = 0;
formatDataRequest->dataLen = 4;
-
- s = cliprdr_server_packet_new(formatDataRequest->msgType, formatDataRequest->msgFlags, formatDataRequest->dataLen);
+ s = cliprdr_server_packet_new(formatDataRequest->msgType,
+ formatDataRequest->msgFlags, formatDataRequest->dataLen);
if (!s)
{
return ERROR_INTERNAL_ERROR;
}
- Stream_Write_UINT32(s, formatDataRequest->requestedFormatId); /* requestedFormatId (4 bytes) */
-
+ Stream_Write_UINT32(s,
+ formatDataRequest->requestedFormatId); /* requestedFormatId (4 bytes) */
WLog_DBG(TAG, "ClientFormatDataRequest");
return cliprdr_server_packet_send(cliprdr, s);
}
*
* @return 0 on success, otherwise a Win32 error code
*/
-static UINT cliprdr_server_format_data_response(CliprdrServerContext* context, CLIPRDR_FORMAT_DATA_RESPONSE* formatDataResponse)
+static UINT cliprdr_server_format_data_response(CliprdrServerContext* context,
+ CLIPRDR_FORMAT_DATA_RESPONSE* formatDataResponse)
{
wStream* s;
CliprdrServerPrivate* cliprdr = (CliprdrServerPrivate*) context->handle;
-
formatDataResponse->msgType = CB_FORMAT_DATA_RESPONSE;
-
- s = cliprdr_server_packet_new(formatDataResponse->msgType, formatDataResponse->msgFlags, formatDataResponse->dataLen);
+ s = cliprdr_server_packet_new(formatDataResponse->msgType,
+ formatDataResponse->msgFlags, formatDataResponse->dataLen);
if (!s)
{
return ERROR_INTERNAL_ERROR;
}
- Stream_Write(s, formatDataResponse->requestedFormatData, formatDataResponse->dataLen);
-
+ Stream_Write(s, formatDataResponse->requestedFormatData,
+ formatDataResponse->dataLen);
WLog_DBG(TAG, "ServerFormatDataResponse");
return cliprdr_server_packet_send(cliprdr, s);
}
*
* @return 0 on success, otherwise a Win32 error code
*/
-static UINT cliprdr_server_file_contents_request(CliprdrServerContext* context, CLIPRDR_FILE_CONTENTS_REQUEST* fileContentsRequest)
+static UINT cliprdr_server_file_contents_request(CliprdrServerContext* context,
+ CLIPRDR_FILE_CONTENTS_REQUEST* fileContentsRequest)
{
wStream* s;
CliprdrServerPrivate* cliprdr = (CliprdrServerPrivate*) context->handle;
-
s = cliprdr_server_packet_new(CB_FILECONTENTS_REQUEST, 0, 28);
if (!s)
}
Stream_Write_UINT32(s, fileContentsRequest->streamId); /* streamId (4 bytes) */
- Stream_Write_UINT32(s, fileContentsRequest->listIndex); /* listIndex (4 bytes) */
+ Stream_Write_UINT32(s,
+ fileContentsRequest->listIndex); /* listIndex (4 bytes) */
Stream_Write_UINT32(s, fileContentsRequest->dwFlags); /* dwFlags (4 bytes) */
- Stream_Write_UINT32(s, fileContentsRequest->nPositionLow); /* nPositionLow (4 bytes) */
- Stream_Write_UINT32(s, fileContentsRequest->nPositionHigh); /* nPositionHigh (4 bytes) */
- Stream_Write_UINT32(s, fileContentsRequest->cbRequested); /* cbRequested (4 bytes) */
- Stream_Write_UINT32(s, fileContentsRequest->clipDataId); /* clipDataId (4 bytes) */
-
+ Stream_Write_UINT32(s,
+ fileContentsRequest->nPositionLow); /* nPositionLow (4 bytes) */
+ Stream_Write_UINT32(s,
+ fileContentsRequest->nPositionHigh); /* nPositionHigh (4 bytes) */
+ Stream_Write_UINT32(s,
+ fileContentsRequest->cbRequested); /* cbRequested (4 bytes) */
+ Stream_Write_UINT32(s,
+ fileContentsRequest->clipDataId); /* clipDataId (4 bytes) */
WLog_DBG(TAG, "ServerFileContentsRequest: streamId: 0x%04X",
- fileContentsRequest->streamId);
-
+ fileContentsRequest->streamId);
return cliprdr_server_packet_send(cliprdr, s);
}
*
* @return 0 on success, otherwise a Win32 error code
*/
-static UINT cliprdr_server_file_contents_response(CliprdrServerContext* context, CLIPRDR_FILE_CONTENTS_RESPONSE* fileContentsResponse)
+static UINT cliprdr_server_file_contents_response(CliprdrServerContext* context,
+ CLIPRDR_FILE_CONTENTS_RESPONSE* fileContentsResponse)
{
wStream* s;
CliprdrServerPrivate* cliprdr = (CliprdrServerPrivate*) context->handle;
if (fileContentsResponse->dwFlags & FILECONTENTS_SIZE)
fileContentsResponse->cbRequested = sizeof(UINT64);
- s = cliprdr_server_packet_new(CB_FILECONTENTS_RESPONSE, fileContentsResponse->msgFlags,
- 4 + fileContentsResponse->cbRequested);
+ s = cliprdr_server_packet_new(CB_FILECONTENTS_RESPONSE,
+ fileContentsResponse->msgFlags,
+ 4 + fileContentsResponse->cbRequested);
if (!s)
{
}
Stream_Write_UINT32(s, fileContentsResponse->streamId); /* streamId (4 bytes) */
-
/**
* requestedFileContentsData:
* FILECONTENTS_SIZE: file size as UINT64
* FILECONTENTS_RANGE: file data from requested range
*/
-
- Stream_Write(s, fileContentsResponse->requestedData, fileContentsResponse->cbRequested);
-
+ Stream_Write(s, fileContentsResponse->requestedData,
+ fileContentsResponse->cbRequested);
WLog_DBG(TAG, "ServerFileContentsResponse: streamId: 0x%04X",
- fileContentsResponse->streamId);
-
+ fileContentsResponse->streamId);
return cliprdr_server_packet_send(cliprdr, s);
}
*
* @return 0 on success, otherwise a Win32 error code
*/
-static UINT cliprdr_server_receive_general_capability(CliprdrServerContext* context, wStream* s)
+static UINT cliprdr_server_receive_general_capability(CliprdrServerContext*
+ context, wStream* s)
{
UINT32 version;
UINT32 generalFlags;
-
Stream_Read_UINT32(s, version); /* version (4 bytes) */
Stream_Read_UINT32(s, generalFlags); /* generalFlags (4 bytes) */
if (context->useLongFormatNames)
- context->useLongFormatNames = (generalFlags & CB_USE_LONG_FORMAT_NAMES) ? TRUE : FALSE;
+ context->useLongFormatNames = (generalFlags & CB_USE_LONG_FORMAT_NAMES) ? TRUE :
+ FALSE;
if (context->streamFileClipEnabled)
- context->streamFileClipEnabled = (generalFlags & CB_STREAM_FILECLIP_ENABLED) ? TRUE : FALSE;
+ context->streamFileClipEnabled = (generalFlags & CB_STREAM_FILECLIP_ENABLED) ?
+ TRUE : FALSE;
if (context->fileClipNoFilePaths)
- context->fileClipNoFilePaths = (generalFlags & CB_FILECLIP_NO_FILE_PATHS) ? TRUE : FALSE;
+ context->fileClipNoFilePaths = (generalFlags & CB_FILECLIP_NO_FILE_PATHS) ?
+ TRUE : FALSE;
if (context->canLockClipData)
context->canLockClipData = (generalFlags & CB_CAN_LOCK_CLIPDATA) ? TRUE : FALSE;
*
* @return 0 on success, otherwise a Win32 error code
*/
-static UINT cliprdr_server_receive_capabilities(CliprdrServerContext* context, wStream* s, CLIPRDR_HEADER* header)
+static UINT cliprdr_server_receive_capabilities(CliprdrServerContext* context,
+ wStream* s, CLIPRDR_HEADER* header)
{
UINT16 index;
UINT16 cCapabilitiesSets;
UINT16 capabilitySetType;
UINT16 lengthCapability;
UINT error;
-
WLog_DBG(TAG, "CliprdrClientCapabilities");
-
Stream_Read_UINT16(s, cCapabilitiesSets); /* cCapabilitiesSets (2 bytes) */
Stream_Seek_UINT16(s); /* pad1 (2 bytes) */
case CB_CAPSTYPE_GENERAL:
if ((error = cliprdr_server_receive_general_capability(context, s)))
{
- WLog_ERR(TAG, "cliprdr_server_receive_general_capability failed with error %lu", error);
+ WLog_ERR(TAG, "cliprdr_server_receive_general_capability failed with error %lu",
+ error);
return error;
}
+
break;
default:
*
* @return 0 on success, otherwise a Win32 error code
*/
-static UINT cliprdr_server_receive_temporary_directory(CliprdrServerContext* context, wStream* s, CLIPRDR_HEADER* header)
+static UINT cliprdr_server_receive_temporary_directory(CliprdrServerContext*
+ context, wStream* s, CLIPRDR_HEADER* header)
{
int length;
WCHAR* wszTempDir;
if ((slength = Stream_GetRemainingLength(s)) < 520)
{
- WLog_ERR(TAG, "Stream_GetRemainingLength returned %d but should at least be 520", slength);
+ WLog_ERR(TAG,
+ "Stream_GetRemainingLength returned %d but should at least be 520", slength);
return CHANNEL_RC_NO_MEMORY;
}
cliprdr->temporaryDirectory = NULL;
if (ConvertFromUnicode(CP_UTF8, 0, wszTempDir, -1,
- &(cliprdr->temporaryDirectory), 0, NULL, NULL) < 1)
+ &(cliprdr->temporaryDirectory), 0, NULL, NULL) < 1)
{
WLog_ERR(TAG, "failed to convert temporary directory name");
return ERROR_INVALID_DATA;
CopyMemory(tempDirectory.szTempDir, cliprdr->temporaryDirectory, length);
tempDirectory.szTempDir[length] = '\0';
-
WLog_DBG(TAG, "CliprdrTemporaryDirectory: %s", cliprdr->temporaryDirectory);
-
IFCALLRET(context->TempDirectory, error, context, &tempDirectory);
+
if (error)
WLog_ERR(TAG, "TempDirectory failed with error %lu!", error);
*
* @return 0 on success, otherwise a Win32 error code
*/
-static UINT cliprdr_server_receive_format_list(CliprdrServerContext* context, wStream* s, CLIPRDR_HEADER* header)
+static UINT cliprdr_server_receive_format_list(CliprdrServerContext* context,
+ wStream* s, CLIPRDR_HEADER* header)
{
UINT32 index;
UINT32 dataLen;
CLIPRDR_FORMAT* formats = NULL;
CLIPRDR_FORMAT_LIST formatList;
UINT error = CHANNEL_RC_OK;
-
dataLen = header->dataLen;
asciiNames = (header->msgFlags & CB_ASCII_NAMES) ? TRUE : FALSE;
-
formatList.msgType = CB_FORMAT_LIST;
formatList.msgFlags = header->msgFlags;
formatList.dataLen = header->dataLen;
-
index = 0;
formatList.numFormats = 0;
position = Stream_GetPosition(s);
}
if (formatList.numFormats)
- formats = (CLIPRDR_FORMAT*) calloc(formatList.numFormats, sizeof(CLIPRDR_FORMAT));
+ formats = (CLIPRDR_FORMAT*) calloc(formatList.numFormats,
+ sizeof(CLIPRDR_FORMAT));
if (!formats)
{
{
Stream_Read_UINT32(s, formats[index].formatId); /* formatId (4 bytes) */
dataLen -= 4;
-
formats[index].formatName = NULL;
/* According to MS-RDPECLIP 2.2.3.1.1.1 formatName is "a 32-byte block containing
* string on success, even if the source string isn't.
*/
if (ConvertFromUnicode(CP_UTF8, 0, wszFormatName, 16,
- &(formats[index].formatName), 0, NULL, NULL) < 1)
+ &(formats[index].formatName), 0, NULL, NULL) < 1)
{
WLog_ERR(TAG, "failed to convert short clipboard format name");
error = ERROR_INVALID_DATA;
{
Stream_Seek(s, 4); /* formatId (4 bytes) */
dataLen -= 4;
-
wszFormatName = (WCHAR*) Stream_Pointer(s);
if (!wszFormatName[0])
Stream_Seek(s, (formatNameLength + 1) * 2);
dataLen -= ((formatNameLength + 1) * 2);
-
formatList.numFormats++;
}
Stream_SetPosition(s, position);
if (formatList.numFormats)
- formats = (CLIPRDR_FORMAT*) calloc(formatList.numFormats, sizeof(CLIPRDR_FORMAT));
+ formats = (CLIPRDR_FORMAT*) calloc(formatList.numFormats,
+ sizeof(CLIPRDR_FORMAT));
if (!formats)
{
{
Stream_Read_UINT32(s, formats[index].formatId); /* formatId (4 bytes) */
dataLen -= 4;
-
formats[index].formatName = NULL;
-
wszFormatName = (WCHAR*) Stream_Pointer(s);
if (!wszFormatName[0])
if (formatNameLength)
{
if (ConvertFromUnicode(CP_UTF8, 0, wszFormatName, -1,
- &(formats[index].formatName), 0, NULL, NULL) < 1)
+ &(formats[index].formatName), 0, NULL, NULL) < 1)
{
WLog_ERR(TAG, "failed to convert long clipboard format name");
error = ERROR_INVALID_DATA;
Stream_Seek(s, (formatNameLength + 1) * 2);
dataLen -= ((formatNameLength + 1) * 2);
-
index++;
}
}
WLog_DBG(TAG, "ClientFormatList: numFormats: %d",
- formatList.numFormats);
-
+ formatList.numFormats);
IFCALLRET(context->ClientFormatList, error, context, &formatList);
+
if (error)
WLog_ERR(TAG, "ClientFormatList failed with error %lu!", error);
out:
+
for (index = 0; index < formatList.numFormats; index++)
{
free(formatList.formats[index].formatName);
}
free(formatList.formats);
-
return error;
}
*
* @return 0 on success, otherwise a Win32 error code
*/
-static UINT cliprdr_server_receive_format_list_response(CliprdrServerContext* context, wStream* s, CLIPRDR_HEADER* header)
+static UINT cliprdr_server_receive_format_list_response(
+ CliprdrServerContext* context, wStream* s, CLIPRDR_HEADER* header)
{
CLIPRDR_FORMAT_LIST_RESPONSE formatListResponse;
UINT error = CHANNEL_RC_OK;
-
WLog_DBG(TAG, "CliprdrClientFormatListResponse");
-
formatListResponse.msgType = CB_FORMAT_LIST_RESPONSE;
formatListResponse.msgFlags = header->msgFlags;
formatListResponse.dataLen = header->dataLen;
+ IFCALLRET(context->ClientFormatListResponse, error, context,
+ &formatListResponse);
- IFCALLRET(context->ClientFormatListResponse, error, context, &formatListResponse);
if (error)
WLog_ERR(TAG, "ClientFormatListResponse failed with error %lu!", error);
*
* @return 0 on success, otherwise a Win32 error code
*/
-static UINT cliprdr_server_receive_lock_clipdata(CliprdrServerContext* context, wStream* s, CLIPRDR_HEADER* header)
+static UINT cliprdr_server_receive_lock_clipdata(CliprdrServerContext* context,
+ wStream* s, CLIPRDR_HEADER* header)
{
CLIPRDR_LOCK_CLIPBOARD_DATA lockClipboardData;
UINT error = CHANNEL_RC_OK;
-
WLog_DBG(TAG, "CliprdrClientLockClipData");
if (Stream_GetRemainingLength(s) < 4)
lockClipboardData.msgType = CB_LOCK_CLIPDATA;
lockClipboardData.msgFlags = header->msgFlags;
lockClipboardData.dataLen = header->dataLen;
-
Stream_Read_UINT32(s, lockClipboardData.clipDataId); /* clipDataId (4 bytes) */
-
IFCALLRET(context->ClientLockClipboardData, error, context, &lockClipboardData);
+
if (error)
WLog_ERR(TAG, "ClientLockClipboardData failed with error %lu!", error);
*
* @return 0 on success, otherwise a Win32 error code
*/
-static UINT cliprdr_server_receive_unlock_clipdata(CliprdrServerContext* context, wStream* s, CLIPRDR_HEADER* header)
+static UINT cliprdr_server_receive_unlock_clipdata(CliprdrServerContext*
+ context, wStream* s, CLIPRDR_HEADER* header)
{
CLIPRDR_UNLOCK_CLIPBOARD_DATA unlockClipboardData;
UINT error = CHANNEL_RC_OK;
-
WLog_DBG(TAG, "CliprdrClientUnlockClipData");
-
unlockClipboardData.msgType = CB_UNLOCK_CLIPDATA;
unlockClipboardData.msgFlags = header->msgFlags;
unlockClipboardData.dataLen = header->dataLen;
return ERROR_INVALID_DATA;
}
- Stream_Read_UINT32(s, unlockClipboardData.clipDataId); /* clipDataId (4 bytes) */
+ Stream_Read_UINT32(s,
+ unlockClipboardData.clipDataId); /* clipDataId (4 bytes) */
+ IFCALLRET(context->ClientUnlockClipboardData, error, context,
+ &unlockClipboardData);
- IFCALLRET(context->ClientUnlockClipboardData, error, context, &unlockClipboardData);
if (error)
WLog_ERR(TAG, "ClientUnlockClipboardData failed with error %lu!", error);
*
* @return 0 on success, otherwise a Win32 error code
*/
-static UINT cliprdr_server_receive_format_data_request(CliprdrServerContext* context, wStream* s, CLIPRDR_HEADER* header)
+static UINT cliprdr_server_receive_format_data_request(CliprdrServerContext*
+ context, wStream* s, CLIPRDR_HEADER* header)
{
CLIPRDR_FORMAT_DATA_REQUEST formatDataRequest;
UINT error = CHANNEL_RC_OK;
-
WLog_DBG(TAG, "CliprdrClientFormatDataRequest");
-
formatDataRequest.msgType = CB_FORMAT_DATA_REQUEST;
formatDataRequest.msgFlags = header->msgFlags;
formatDataRequest.dataLen = header->dataLen;
return ERROR_INVALID_DATA;
}
- Stream_Read_UINT32(s, formatDataRequest.requestedFormatId); /* requestedFormatId (4 bytes) */
-
+ Stream_Read_UINT32(s,
+ formatDataRequest.requestedFormatId); /* requestedFormatId (4 bytes) */
IFCALLRET(context->ClientFormatDataRequest, error, context, &formatDataRequest);
+
if (error)
WLog_ERR(TAG, "ClientFormatDataRequest failed with error %lu!", error);
*
* @return 0 on success, otherwise a Win32 error code
*/
-static UINT cliprdr_server_receive_format_data_response(CliprdrServerContext* context, wStream* s, CLIPRDR_HEADER* header)
+static UINT cliprdr_server_receive_format_data_response(
+ CliprdrServerContext* context, wStream* s, CLIPRDR_HEADER* header)
{
CLIPRDR_FORMAT_DATA_RESPONSE formatDataResponse;
UINT error = CHANNEL_RC_OK;
-
WLog_DBG(TAG, "CliprdrClientFormatDataResponse");
-
formatDataResponse.msgType = CB_FORMAT_DATA_RESPONSE;
formatDataResponse.msgFlags = header->msgFlags;
formatDataResponse.dataLen = header->dataLen;
Stream_Read(s, formatDataResponse.requestedFormatData, header->dataLen);
}
- IFCALLRET(context->ClientFormatDataResponse, error, context, &formatDataResponse);
+ IFCALLRET(context->ClientFormatDataResponse, error, context,
+ &formatDataResponse);
+
if (error)
WLog_ERR(TAG, "ClientFormatDataResponse failed with error %lu!", error);
free(formatDataResponse.requestedFormatData);
-
return error;
}
*
* @return 0 on success, otherwise a Win32 error code
*/
-static UINT cliprdr_server_receive_filecontents_request(CliprdrServerContext* context, wStream* s, CLIPRDR_HEADER* header)
+static UINT cliprdr_server_receive_filecontents_request(
+ CliprdrServerContext* context, wStream* s, CLIPRDR_HEADER* header)
{
CLIPRDR_FILE_CONTENTS_REQUEST request;
UINT error = CHANNEL_RC_OK;
-
WLog_DBG(TAG, "CliprdrClientFileContentsRequest");
-
request.msgType = CB_FILECONTENTS_REQUEST;
request.msgFlags = header->msgFlags;
request.dataLen = header->dataLen;
Stream_Read_UINT32(s, request.nPositionLow); /* nPositionLow (4 bytes) */
Stream_Read_UINT32(s, request.nPositionHigh); /* nPositionHigh (4 bytes) */
Stream_Read_UINT32(s, request.cbRequested); /* cbRequested (4 bytes) */
+
if (Stream_GetRemainingLength(s) < 4) /* clipDataId (4 bytes) optional */
request.clipDataId = 0;
else
Stream_Read_UINT32(s, request.clipDataId);
IFCALLRET(context->ClientFileContentsRequest, error, context, &request);
+
if (error)
WLog_ERR(TAG, "ClientFileContentsRequest failed with error %lu!", error);
*
* @return 0 on success, otherwise a Win32 error code
*/
-static UINT cliprdr_server_receive_filecontents_response(CliprdrServerContext* context, wStream* s, CLIPRDR_HEADER* header)
+static UINT cliprdr_server_receive_filecontents_response(
+ CliprdrServerContext* context, wStream* s, CLIPRDR_HEADER* header)
{
CLIPRDR_FILE_CONTENTS_RESPONSE response;
UINT error = CHANNEL_RC_OK;
-
WLog_DBG(TAG, "CliprdrClientFileContentsResponse");
-
response.msgType = CB_FILECONTENTS_RESPONSE;
response.msgFlags = header->msgFlags;
response.dataLen = header->dataLen;
}
Stream_Read_UINT32(s, response.streamId); /* streamId (4 bytes) */
-
response.cbRequested = header->dataLen - 4;
response.requestedData = Stream_Pointer(s); /* requestedFileContentsData */
-
IFCALLRET(context->ClientFileContentsResponse, error, context, &response);
+
if (error)
WLog_ERR(TAG, "ClientFileContentsResponse failed with error %lu!", error);
*
* @return 0 on success, otherwise a Win32 error code
*/
-static UINT cliprdr_server_receive_pdu(CliprdrServerContext* context, wStream* s, CLIPRDR_HEADER* header)
+static UINT cliprdr_server_receive_pdu(CliprdrServerContext* context,
+ wStream* s, CLIPRDR_HEADER* header)
{
UINT error;
- WLog_DBG(TAG, "CliprdrServerReceivePdu: msgType: %d msgFlags: 0x%08X dataLen: %d",
- header->msgType, header->msgFlags, header->dataLen);
+ WLog_DBG(TAG,
+ "CliprdrServerReceivePdu: msgType: %d msgFlags: 0x%08X dataLen: %d",
+ header->msgType, header->msgFlags, header->dataLen);
switch (header->msgType)
{
case CB_CLIP_CAPS:
if ((error = cliprdr_server_receive_capabilities(context, s, header)))
- WLog_ERR(TAG, "cliprdr_server_receive_capabilities failed with error %lu!", error);
+ WLog_ERR(TAG, "cliprdr_server_receive_capabilities failed with error %lu!",
+ error);
+
break;
case CB_TEMP_DIRECTORY:
if ((error = cliprdr_server_receive_temporary_directory(context, s, header)))
- WLog_ERR(TAG, "cliprdr_server_receive_temporary_directory failed with error %lu!", error);
+ WLog_ERR(TAG,
+ "cliprdr_server_receive_temporary_directory failed with error %lu!", error);
+
break;
case CB_FORMAT_LIST:
if ((error = cliprdr_server_receive_format_list(context, s, header)))
- WLog_ERR(TAG, "cliprdr_server_receive_format_list failed with error %lu!", error);
+ WLog_ERR(TAG, "cliprdr_server_receive_format_list failed with error %lu!",
+ error);
+
break;
case CB_FORMAT_LIST_RESPONSE:
if ((error = cliprdr_server_receive_format_list_response(context, s, header)))
- WLog_ERR(TAG, "cliprdr_server_receive_format_list_response failed with error %lu!", error);
+ WLog_ERR(TAG,
+ "cliprdr_server_receive_format_list_response failed with error %lu!", error);
+
break;
case CB_LOCK_CLIPDATA:
if ((error = cliprdr_server_receive_lock_clipdata(context, s, header)))
- WLog_ERR(TAG, "cliprdr_server_receive_lock_clipdata failed with error %lu!", error);
+ WLog_ERR(TAG, "cliprdr_server_receive_lock_clipdata failed with error %lu!",
+ error);
+
break;
case CB_UNLOCK_CLIPDATA:
if ((error = cliprdr_server_receive_unlock_clipdata(context, s, header)))
- WLog_ERR(TAG, "cliprdr_server_receive_unlock_clipdata failed with error %lu!", error);
+ WLog_ERR(TAG, "cliprdr_server_receive_unlock_clipdata failed with error %lu!",
+ error);
+
break;
case CB_FORMAT_DATA_REQUEST:
if ((error = cliprdr_server_receive_format_data_request(context, s, header)))
- WLog_ERR(TAG, "cliprdr_server_receive_format_data_request failed with error %lu!", error);
+ WLog_ERR(TAG,
+ "cliprdr_server_receive_format_data_request failed with error %lu!", error);
+
break;
case CB_FORMAT_DATA_RESPONSE:
if ((error = cliprdr_server_receive_format_data_response(context, s, header)))
- WLog_ERR(TAG, "cliprdr_server_receive_format_data_response failed with error %lu!", error);
+ WLog_ERR(TAG,
+ "cliprdr_server_receive_format_data_response failed with error %lu!", error);
+
break;
case CB_FILECONTENTS_REQUEST:
if ((error = cliprdr_server_receive_filecontents_request(context, s, header)))
- WLog_ERR(TAG, "cliprdr_server_receive_filecontents_request failed with error %lu!", error);
+ WLog_ERR(TAG,
+ "cliprdr_server_receive_filecontents_request failed with error %lu!", error);
+
break;
case CB_FILECONTENTS_RESPONSE:
if ((error = cliprdr_server_receive_filecontents_response(context, s, header)))
- WLog_ERR(TAG, "cliprdr_server_receive_filecontents_response failed with error %lu!", error);
+ WLog_ERR(TAG,
+ "cliprdr_server_receive_filecontents_response failed with error %lu!", error);
+
break;
default:
CLIPRDR_MONITOR_READY monitorReady;
CLIPRDR_GENERAL_CAPABILITY_SET generalCapabilitySet;
UINT error;
-
ZeroMemory(&capabilities, sizeof(capabilities));
ZeroMemory(&monitorReady, sizeof(monitorReady));
-
generalFlags = 0;
if (context->useLongFormatNames)
capabilities.msgType = CB_CLIP_CAPS;
capabilities.msgFlags = 0;
capabilities.dataLen = 4 + CB_CAPSTYPE_GENERAL_LEN;
-
capabilities.cCapabilitiesSets = 1;
capabilities.capabilitySets = (CLIPRDR_CAPABILITY_SET*) &generalCapabilitySet;
-
generalCapabilitySet.capabilitySetType = CB_CAPSTYPE_GENERAL;
generalCapabilitySet.capabilitySetLength = CB_CAPSTYPE_GENERAL_LEN;
generalCapabilitySet.version = CB_CAPS_VERSION_2;
WLog_ERR(TAG, "ServerCapabilities failed with error %lu!", error);
return error;
}
+
if ((error = context->MonitorReady(context, &monitorReady)))
{
WLog_ERR(TAG, "MonitorReady failed with error %lu!", error);
CLIPRDR_HEADER header;
CliprdrServerPrivate* cliprdr = (CliprdrServerPrivate*) context->handle;
UINT error;
- DWORD status;
-
+ DWORD status;
s = cliprdr->s;
if (Stream_GetPosition(s) < CLIPRDR_HEADER_LENGTH)
{
BytesReturned = 0;
BytesToRead = CLIPRDR_HEADER_LENGTH - Stream_GetPosition(s);
-
- status = WaitForSingleObject(cliprdr->ChannelEvent, 0);
+ status = WaitForSingleObject(cliprdr->ChannelEvent, 0);
if (status == WAIT_FAILED)
- {
- error = GetLastError();
- WLog_ERR(TAG, "WaitForSingleObject failed with error %lu", error);
- return error;
- }
+ {
+ error = GetLastError();
+ WLog_ERR(TAG, "WaitForSingleObject failed with error %lu", error);
+ return error;
+ }
- if (status == WAIT_TIMEOUT)
- return CHANNEL_RC_OK;
+ if (status == WAIT_TIMEOUT)
+ return CHANNEL_RC_OK;
if (!WTSVirtualChannelRead(cliprdr->ChannelHandle, 0,
- (PCHAR) Stream_Pointer(s), BytesToRead, &BytesReturned))
+ (PCHAR) Stream_Pointer(s), BytesToRead, &BytesReturned))
{
WLog_ERR(TAG, "WTSVirtualChannelRead failed!");
return ERROR_INTERNAL_ERROR;
{
position = Stream_GetPosition(s);
Stream_SetPosition(s, 0);
-
Stream_Read_UINT16(s, header.msgType); /* msgType (2 bytes) */
Stream_Read_UINT16(s, header.msgFlags); /* msgFlags (2 bytes) */
Stream_Read_UINT32(s, header.dataLen); /* dataLen (4 bytes) */
{
BytesReturned = 0;
BytesToRead = (header.dataLen + CLIPRDR_HEADER_LENGTH) - Stream_GetPosition(s);
+ status = WaitForSingleObject(cliprdr->ChannelEvent, 0);
- status = WaitForSingleObject(cliprdr->ChannelEvent, 0);
-
- if (status == WAIT_FAILED)
- {
- error = GetLastError();
- WLog_ERR(TAG, "WaitForSingleObject failed with error %lu", error);
- return error;
- }
+ if (status == WAIT_FAILED)
+ {
+ error = GetLastError();
+ WLog_ERR(TAG, "WaitForSingleObject failed with error %lu", error);
+ return error;
+ }
- if (status == WAIT_TIMEOUT)
- return CHANNEL_RC_OK;
+ if (status == WAIT_TIMEOUT)
+ return CHANNEL_RC_OK;
if (!WTSVirtualChannelRead(cliprdr->ChannelHandle, 0,
- (PCHAR) Stream_Pointer(s), BytesToRead, &BytesReturned))
+ (PCHAR) Stream_Pointer(s), BytesToRead, &BytesReturned))
{
WLog_ERR(TAG, "WTSVirtualChannelRead failed!");
return ERROR_INTERNAL_ERROR;
}
Stream_SetPosition(s, 0);
-
/* check for trailing zero bytes */
+ status = WaitForSingleObject(cliprdr->ChannelEvent, 0);
- status = WaitForSingleObject(cliprdr->ChannelEvent, 0);
-
- if (status == WAIT_FAILED)
- {
- error = GetLastError();
- WLog_ERR(TAG, "WaitForSingleObject failed with error %lu", error);
- return error;
- }
+ if (status == WAIT_FAILED)
+ {
+ error = GetLastError();
+ WLog_ERR(TAG, "WaitForSingleObject failed with error %lu", error);
+ return error;
+ }
- if (status == WAIT_TIMEOUT)
- return CHANNEL_RC_OK;
+ if (status == WAIT_TIMEOUT)
+ return CHANNEL_RC_OK;
BytesReturned = 0;
BytesToRead = 4;
if (!WTSVirtualChannelRead(cliprdr->ChannelHandle, 0,
- (PCHAR) Stream_Pointer(s), BytesToRead, &BytesReturned))
+ (PCHAR) Stream_Pointer(s), BytesToRead, &BytesReturned))
{
WLog_ERR(TAG, "WTSVirtualChannelRead failed!");
return ERROR_INTERNAL_ERROR;
CliprdrServerContext* context = (CliprdrServerContext*) arg;
CliprdrServerPrivate* cliprdr = (CliprdrServerPrivate*) context->handle;
UINT error;
-
freerdp_channel_init_thread_context(context->rdpcontext);
ChannelEvent = context->GetEventHandle(context);
-
nCount = 0;
events[nCount++] = cliprdr->StopEvent;
events[nCount++] = ChannelEvent;
if (status == WAIT_FAILED)
{
- error = GetLastError();
- WLog_ERR(TAG, "WaitForMultipleObjects failed with error %lu", error);
- goto out;
+ error = GetLastError();
+ WLog_ERR(TAG, "WaitForMultipleObjects failed with error %lu", error);
+ goto out;
}
- status = WaitForSingleObject(cliprdr->StopEvent, 0);
+ status = WaitForSingleObject(cliprdr->StopEvent, 0);
- if (status == WAIT_FAILED)
- {
- error = GetLastError();
- WLog_ERR(TAG, "WaitForSingleObject failed with error %lu", error);
- goto out;
- }
+ if (status == WAIT_FAILED)
+ {
+ error = GetLastError();
+ WLog_ERR(TAG, "WaitForSingleObject failed with error %lu", error);
+ goto out;
+ }
if (status == WAIT_OBJECT_0)
break;
- status = WaitForSingleObject(ChannelEvent, 0);
+ status = WaitForSingleObject(ChannelEvent, 0);
- if (status == WAIT_FAILED)
- {
- error = GetLastError();
- WLog_ERR(TAG, "WaitForSingleObject failed with error %lu", error);
- goto out;
- }
+ if (status == WAIT_FAILED)
+ {
+ error = GetLastError();
+ WLog_ERR(TAG, "WaitForSingleObject failed with error %lu", error);
+ goto out;
+ }
if (status == WAIT_OBJECT_0)
{
}
}
}
+
out:
+
if (error && context->rdpcontext)
- setChannelError(context->rdpcontext, error, "cliprdr_server_thread reported an error");
+ setChannelError(context->rdpcontext, error,
+ "cliprdr_server_thread reported an error");
ExitThread((DWORD)error);
return NULL;
void* buffer = NULL;
DWORD BytesReturned = 0;
CliprdrServerPrivate* cliprdr = (CliprdrServerPrivate*) context->handle;
-
- cliprdr->ChannelHandle = WTSVirtualChannelOpen(cliprdr->vcm, WTS_CURRENT_SESSION, "cliprdr");
+ cliprdr->ChannelHandle = WTSVirtualChannelOpen(cliprdr->vcm,
+ WTS_CURRENT_SESSION, "cliprdr");
if (!cliprdr->ChannelHandle)
{
cliprdr->ChannelEvent = NULL;
- if (WTSVirtualChannelQuery(cliprdr->ChannelHandle, WTSVirtualEventHandle, &buffer, &BytesReturned))
+ if (WTSVirtualChannelQuery(cliprdr->ChannelHandle, WTSVirtualEventHandle,
+ &buffer, &BytesReturned))
{
if (BytesReturned != sizeof(HANDLE))
{
WLog_ERR(TAG, "BytesReturned has not size of HANDLE!");
return ERROR_INTERNAL_ERROR;
}
- CopyMemory(&(cliprdr->ChannelEvent), buffer, sizeof(HANDLE));
-
+ CopyMemory(&(cliprdr->ChannelEvent), buffer, sizeof(HANDLE));
WTSFreeMemory(buffer);
}
}
if (!(cliprdr->Thread = CreateThread(NULL, 0,
- (LPTHREAD_START_ROUTINE) cliprdr_server_thread, (void*) context, 0, NULL)))
+ (LPTHREAD_START_ROUTINE) cliprdr_server_thread, (void*) context, 0, NULL)))
{
WLog_ERR(TAG, "CreateThread failed!");
CloseHandle(cliprdr->StopEvent);
*/
static UINT cliprdr_server_stop(CliprdrServerContext* context)
{
- UINT error = CHANNEL_RC_OK;
+ UINT error = CHANNEL_RC_OK;
CliprdrServerPrivate* cliprdr = (CliprdrServerPrivate*) context->handle;
if (cliprdr->StopEvent)
{
SetEvent(cliprdr->StopEvent);
+
if (WaitForSingleObject(cliprdr->Thread, INFINITE) == WAIT_FAILED)
- {
- error = GetLastError();
- WLog_ERR(TAG, "WaitForSingleObject failed with error %lu", error);
- return error;
- }
+ {
+ error = GetLastError();
+ WLog_ERR(TAG, "WaitForSingleObject failed with error %lu", error);
+ return error;
+ }
+
CloseHandle(cliprdr->Thread);
CloseHandle(cliprdr->StopEvent);
}
{
CliprdrServerContext* context;
CliprdrServerPrivate* cliprdr;
-
context = (CliprdrServerContext*) calloc(1, sizeof(CliprdrServerContext));
if (context)
context->Stop = cliprdr_server_stop;
context->GetEventHandle = cliprdr_server_get_event_handle;
context->CheckEventHandle = cliprdr_server_check_event_handle;
-
context->ServerCapabilities = cliprdr_server_capabilities;
context->MonitorReady = cliprdr_server_monitor_ready;
context->ServerFormatList = cliprdr_server_format_list;
context->ServerFormatDataResponse = cliprdr_server_format_data_response;
context->ServerFileContentsRequest = cliprdr_server_file_contents_request;
context->ServerFileContentsResponse = cliprdr_server_file_contents_response;
-
- cliprdr = context->handle = (CliprdrServerPrivate*) calloc(1, sizeof(CliprdrServerPrivate));
+ cliprdr = context->handle = (CliprdrServerPrivate*) calloc(1,
+ sizeof(CliprdrServerPrivate));
if (cliprdr)
{
cliprdr->vcm = vcm;
-
cliprdr->s = Stream_New(NULL, 4096);
- if(!cliprdr->s)
+ if (!cliprdr->s)
{
WLog_ERR(TAG, "Stream_New failed!");
free(context->handle);
free(context);
return NULL;
}
- } else {
+ }
+ else
+ {
WLog_ERR(TAG, "calloc failed!");
free(context);
return NULL;
static void dvcman_channel_free(void* channel);
static UINT drdynvc_write_data(drdynvcPlugin* drdynvc, UINT32 ChannelId,
- const BYTE* data, UINT32 dataSize);
+ const BYTE* data, UINT32 dataSize);
/**
* Function description
* @return 0 on success, otherwise a Win32 error code
*/
static UINT dvcman_get_configuration(IWTSListener* pListener,
- void** ppPropertyBag)
+ void** ppPropertyBag)
{
*ppPropertyBag = NULL;
return ERROR_INTERNAL_ERROR;
* @return 0 on success, otherwise a Win32 error code
*/
static UINT dvcman_create_listener(IWTSVirtualChannelManager* pChannelMgr,
- const char* pszChannelName, ULONG ulFlags,
- IWTSListenerCallback* pListenerCallback, IWTSListener** ppListener)
+ const char* pszChannelName, ULONG ulFlags,
+ IWTSListenerCallback* pListenerCallback, IWTSListener** ppListener)
{
DVCMAN* dvcman = (DVCMAN*) pChannelMgr;
DVCMAN_LISTENER* listener;
* @return 0 on success, otherwise a Win32 error code
*/
static UINT dvcman_register_plugin(IDRDYNVC_ENTRY_POINTS* pEntryPoints,
- const char* name, IWTSPlugin* pPlugin)
+ const char* name, IWTSPlugin* pPlugin)
{
DVCMAN* dvcman = ((DVCMAN_ENTRY_POINTS*) pEntryPoints)->dvcman;
else
{
WLog_ERR(TAG, "register_plugin: Maximum DVC plugin number %d reached.",
- MAX_PLUGINS);
+ MAX_PLUGINS);
return ERROR_INTERNAL_ERROR;
}
}
static IWTSPlugin* dvcman_get_plugin(IDRDYNVC_ENTRY_POINTS* pEntryPoints,
- const char* name)
+ const char* name)
{
int i;
DVCMAN* dvcman = ((DVCMAN_ENTRY_POINTS*) pEntryPoints)->dvcman;
}
static IWTSVirtualChannel* dvcman_find_channel_by_id(IWTSVirtualChannelManager*
- pChannelMgr,
- UINT32 ChannelId)
+ pChannelMgr,
+ UINT32 ChannelId)
{
int index;
BOOL found = FALSE;
}
static void* dvcman_get_channel_interface_by_name(IWTSVirtualChannelManager*
- pChannelMgr,
- const char* ChannelName)
+ pChannelMgr,
+ const char* ChannelName)
{
int i;
BOOL found = FALSE;
* @return 0 on success, otherwise a Win32 error code
*/
static UINT dvcman_load_addin(IWTSVirtualChannelManager* pChannelMgr,
- ADDIN_ARGV* args,
- rdpSettings* settings)
+ ADDIN_ARGV* args,
+ rdpSettings* settings)
{
DVCMAN_ENTRY_POINTS entryPoints;
PDVC_PLUGIN_ENTRY pDVCPluginEntry = NULL;
WLog_INFO(TAG, "Loading Dynamic Virtual Channel %s", args->argv[0]);
pDVCPluginEntry = (PDVC_PLUGIN_ENTRY) freerdp_load_channel_addin_entry(
- args->argv[0],
- NULL, NULL, FREERDP_ADDIN_CHANNEL_DYNAMIC);
+ args->argv[0],
+ NULL, NULL, FREERDP_ADDIN_CHANNEL_DYNAMIC);
if (pDVCPluginEntry)
{
}
static DVCMAN_CHANNEL* dvcman_channel_new(IWTSVirtualChannelManager*
- pChannelMgr,
- UINT32 ChannelId, const char* ChannelName)
+ pChannelMgr,
+ UINT32 ChannelId, const char* ChannelName)
{
DVCMAN_CHANNEL* channel;
if (dvcman_find_channel_by_id(pChannelMgr, ChannelId))
{
WLog_ERR(TAG, "Protocol error: Duplicated ChannelId %d (%s)!", ChannelId,
- ChannelName);
+ ChannelName);
return NULL;
}
* @return 0 on success, otherwise a Win32 error code
*/
static UINT dvcman_write_channel(IWTSVirtualChannel* pChannel, ULONG cbSize,
- const BYTE* pBuffer, void* pReserved)
+ const BYTE* pBuffer, void* pReserved)
{
UINT status;
DVCMAN_CHANNEL* channel = (DVCMAN_CHANNEL*) pChannel;
EnterCriticalSection(&(channel->lock));
status = drdynvc_write_data(channel->dvcman->drdynvc,
- channel->channel_id, pBuffer, cbSize);
+ channel->channel_id, pBuffer, cbSize);
LeaveCriticalSection(&(channel->lock));
return status;
}
* @return 0 on success, otherwise a Win32 error code
*/
static UINT dvcman_create_channel(IWTSVirtualChannelManager* pChannelMgr,
- UINT32 ChannelId, const char* ChannelName)
+ UINT32 ChannelId, const char* ChannelName)
{
int i;
BOOL bAccept;
pCallback = NULL;
if ((error = listener->listener_callback->OnNewChannelConnection(
- listener->listener_callback,
- (IWTSVirtualChannel*) channel, NULL, &bAccept, &pCallback)) == CHANNEL_RC_OK
+ listener->listener_callback,
+ (IWTSVirtualChannel*) channel, NULL, &bAccept, &pCallback)) == CHANNEL_RC_OK
&& bAccept)
{
WLog_DBG(TAG, "listener %s created new channel %d",
- listener->channel_name, channel->channel_id);
+ listener->channel_name, channel->channel_id);
channel->status = 0;
channel->channel_callback = pCallback;
channel->pInterface = listener->iface.pInterface;
context = dvcman->drdynvc->context;
IFCALLRET(context->OnChannelConnected, error, context, ChannelName,
- listener->iface.pInterface);
+ listener->iface.pInterface);
if (error)
WLog_ERR(TAG, "context.ReceiveSamples failed with error %lu", error);
* @return 0 on success, otherwise a Win32 error code
*/
static UINT dvcman_open_channel(IWTSVirtualChannelManager* pChannelMgr,
- UINT32 ChannelId)
+ UINT32 ChannelId)
{
DVCMAN_CHANNEL* channel;
IWTSVirtualChannelCallback* pCallback;
* @return 0 on success, otherwise a Win32 error code
*/
static UINT dvcman_close_channel(IWTSVirtualChannelManager* pChannelMgr,
- UINT32 ChannelId)
+ UINT32 ChannelId)
{
DVCMAN_CHANNEL* channel;
IWTSVirtualChannel* ichannel;
{
context = dvcman->drdynvc->context;
IFCALLRET(context->OnChannelDisconnected, error, context, channel->channel_name,
- channel->pInterface);
+ channel->pInterface);
if (error)
{
* @return 0 on success, otherwise a Win32 error code
*/
static UINT dvcman_receive_channel_data_first(IWTSVirtualChannelManager*
- pChannelMgr,
- UINT32 ChannelId, UINT32 length)
+ pChannelMgr,
+ UINT32 ChannelId, UINT32 length)
{
DVCMAN_CHANNEL* channel;
channel = (DVCMAN_CHANNEL*) dvcman_find_channel_by_id(pChannelMgr, ChannelId);
* @return 0 on success, otherwise a Win32 error code
*/
static UINT dvcman_receive_channel_data(IWTSVirtualChannelManager* pChannelMgr,
- UINT32 ChannelId, wStream* data)
+ UINT32 ChannelId, wStream* data)
{
UINT status = CHANNEL_RC_OK;
DVCMAN_CHANNEL* channel;
{
/* Fragmented data */
if (Stream_GetPosition(channel->dvc_data) + dataSize > (UINT32) Stream_Capacity(
- channel->dvc_data))
+ channel->dvc_data))
{
WLog_ERR(TAG, "data exceeding declared length!");
Stream_Release(channel->dvc_data);
Stream_SealLength(channel->dvc_data);
Stream_SetPosition(channel->dvc_data, 0);
status = channel->channel_callback->OnDataReceived(channel->channel_callback,
- channel->dvc_data);
+ channel->dvc_data);
Stream_Release(channel->dvc_data);
channel->dvc_data = NULL;
}
else
{
status = channel->channel_callback->OnDataReceived(channel->channel_callback,
- data);
+ data);
}
return status;
else
{
status = drdynvc->channelEntryPoints.pVirtualChannelWrite(drdynvc->OpenHandle,
- Stream_Buffer(s), (UINT32) Stream_GetPosition(s), s);
+ Stream_Buffer(s), (UINT32) Stream_GetPosition(s), s);
}
if (status != CHANNEL_RC_OK)
{
Stream_Free(s, TRUE);
WLog_ERR(TAG, "VirtualChannelWrite failed with %s [%08X]",
- WTSErrorToString(status), status);
+ WTSErrorToString(status), status);
}
return status;
* @return 0 on success, otherwise a Win32 error code
*/
static UINT drdynvc_write_data(drdynvcPlugin* drdynvc, UINT32 ChannelId,
- const BYTE* data, UINT32 dataSize)
+ const BYTE* data, UINT32 dataSize)
{
wStream* data_out;
unsigned long pos;
if (status != CHANNEL_RC_OK)
{
WLog_ERR(TAG, "VirtualChannelWrite failed with %s [%08X]",
- WTSErrorToString(status), status);
+ WTSErrorToString(status), status);
return status;
}
}
Stream_Write_UINT16(s,
- 0x0050); /* Cmd+Sp+cbChId+Pad. Note: MSTSC sends 0x005c */
+ 0x0050); /* Cmd+Sp+cbChId+Pad. Note: MSTSC sends 0x005c */
Stream_Write_UINT16(s, drdynvc->version);
status = drdynvc_send(drdynvc, s);
if (status != CHANNEL_RC_OK)
{
WLog_ERR(TAG, "VirtualChannelWrite failed with %s [%08X]",
- WTSErrorToString(status), status);
+ WTSErrorToString(status), status);
}
return status;
* @return 0 on success, otherwise a Win32 error code
*/
static UINT drdynvc_process_capability_request(drdynvcPlugin* drdynvc, int Sp,
- int cbChId, wStream* s)
+ int cbChId, wStream* s)
{
UINT status;
WLog_DBG(TAG, "capability_request Sp=%d cbChId=%d", Sp, cbChId);
* @return 0 on success, otherwise a Win32 error code
*/
static UINT drdynvc_process_create_request(drdynvcPlugin* drdynvc, int Sp,
- int cbChId, wStream* s)
+ int cbChId, wStream* s)
{
unsigned long pos;
UINT status;
ChannelId = drdynvc_read_variable_uint(s, cbChId);
pos = Stream_GetPosition(s);
WLog_DBG(TAG, "process_create_request: ChannelId=%d ChannelName=%s", ChannelId,
- Stream_Pointer(s));
+ Stream_Pointer(s));
channel_status = dvcman_create_channel(drdynvc->channel_mgr, ChannelId,
- (char*) Stream_Pointer(s));
+ (char*) Stream_Pointer(s));
data_out = Stream_New(NULL, pos + 4);
if (!s)
{
WLog_DBG(TAG, "no listener");
Stream_Write_UINT32(data_out,
- (UINT32) 0xC0000001); /* same code used by mstsc */
+ (UINT32) 0xC0000001); /* same code used by mstsc */
}
status = drdynvc_send(drdynvc, data_out);
if (status != CHANNEL_RC_OK)
{
WLog_ERR(TAG, "VirtualChannelWrite failed with %s [%08X]",
- WTSErrorToString(status), status);
+ WTSErrorToString(status), status);
return status;
}
* @return 0 on success, otherwise a Win32 error code
*/
static UINT drdynvc_process_data_first(drdynvcPlugin* drdynvc, int Sp,
- int cbChId, wStream* s)
+ int cbChId, wStream* s)
{
UINT status;
UINT32 Length;
ChannelId = drdynvc_read_variable_uint(s, cbChId);
Length = drdynvc_read_variable_uint(s, Sp);
WLog_DBG(TAG, "process_data_first: Sp=%d cbChId=%d, ChannelId=%d Length=%d", Sp,
- cbChId, ChannelId, Length);
+ cbChId, ChannelId, Length);
status = dvcman_receive_channel_data_first(drdynvc->channel_mgr, ChannelId,
- Length);
+ Length);
if (status)
return status;
* @return 0 on success, otherwise a Win32 error code
*/
static UINT drdynvc_process_data(drdynvcPlugin* drdynvc, int Sp, int cbChId,
- wStream* s)
+ wStream* s)
{
UINT32 ChannelId;
ChannelId = drdynvc_read_variable_uint(s, cbChId);
WLog_DBG(TAG, "process_data: Sp=%d cbChId=%d, ChannelId=%d", Sp, cbChId,
- ChannelId);
+ ChannelId);
return dvcman_receive_channel_data(drdynvc->channel_mgr, ChannelId, s);
}
* @return 0 on success, otherwise a Win32 error code
*/
static UINT drdynvc_process_close_request(drdynvcPlugin* drdynvc, int Sp,
- int cbChId, wStream* s)
+ int cbChId, wStream* s)
{
int value;
UINT error;
wStream* data_out;
ChannelId = drdynvc_read_variable_uint(s, cbChId);
WLog_DBG(TAG, "process_close_request: Sp=%d cbChId=%d, ChannelId=%d", Sp,
- cbChId, ChannelId);
+ cbChId, ChannelId);
if ((error = dvcman_close_channel(drdynvc->channel_mgr, ChannelId)))
{
if (error)
WLog_ERR(TAG, "VirtualChannelWrite failed with %s [%08X]",
- WTSErrorToString(error), error);
+ WTSErrorToString(error), error);
return error;
}
Sp = (value & 0x0c) >> 2;
cbChId = (value & 0x03) >> 0;
WLog_DBG(TAG, "order_recv: Cmd=0x%x, Sp=%d cbChId=%d, ChannelId=%d", Cmd, Sp,
- cbChId);
+ cbChId);
switch (Cmd)
{
* @return 0 on success, otherwise a Win32 error code
*/
static UINT drdynvc_virtual_channel_event_data_received(drdynvcPlugin* drdynvc,
- void* pData, UINT32 dataLength, UINT32 totalLength, UINT32 dataFlags)
+ void* pData, UINT32 dataLength, UINT32 totalLength, UINT32 dataFlags)
{
wStream* data_in;
}
static void VCAPITYPE drdynvc_virtual_channel_open_event(DWORD openHandle,
- UINT event,
- LPVOID pData, UINT32 dataLength, UINT32 totalLength, UINT32 dataFlags)
+ UINT event,
+ LPVOID pData, UINT32 dataLength, UINT32 totalLength, UINT32 dataFlags)
{
drdynvcPlugin* drdynvc = s_TLSPluginContext;
UINT error = CHANNEL_RC_OK;
{
case CHANNEL_EVENT_DATA_RECEIVED:
if ((error = drdynvc_virtual_channel_event_data_received(drdynvc, pData,
- dataLength, totalLength, dataFlags)))
+ dataLength, totalLength, dataFlags)))
WLog_ERR(TAG,
- "drdynvc_virtual_channel_event_data_received failed with error %lu", error);
+ "drdynvc_virtual_channel_event_data_received failed with error %lu", error);
break;
if (error && drdynvc->rdpcontext)
setChannelError(drdynvc->rdpcontext, error,
- "drdynvc_virtual_channel_open_event reported an error");
+ "drdynvc_virtual_channel_open_event reported an error");
}
static void* drdynvc_virtual_channel_client_thread(void* arg)
if (error && drdynvc->rdpcontext)
setChannelError(drdynvc->rdpcontext, error,
- "drdynvc_virtual_channel_client_thread reported an error");
+ "drdynvc_virtual_channel_client_thread reported an error");
ExitThread((DWORD) error);
return NULL;
* @return 0 on success, otherwise a Win32 error code
*/
static UINT drdynvc_virtual_channel_event_connected(drdynvcPlugin* drdynvc,
- LPVOID pData, UINT32 dataLength)
+ LPVOID pData, UINT32 dataLength)
{
UINT32 status;
UINT32 index;
rdpSettings* settings;
UINT error;
status = drdynvc->channelEntryPoints.pVirtualChannelOpen(drdynvc->InitHandle,
- &drdynvc->OpenHandle, drdynvc->channelDef.name,
- drdynvc_virtual_channel_open_event);
+ &drdynvc->OpenHandle, drdynvc->channelDef.name,
+ drdynvc_virtual_channel_open_event);
if (status != CHANNEL_RC_OK)
{
WLog_ERR(TAG, "pVirtualChannelOpen failed with %s [%08X]",
- WTSErrorToString(status), status);
+ WTSErrorToString(status), status);
return status;
}
drdynvc->state = DRDYNVC_STATE_CAPABILITIES;
if (!(drdynvc->thread = CreateThread(NULL, 0,
- (LPTHREAD_START_ROUTINE) drdynvc_virtual_channel_client_thread, (void*) drdynvc,
- 0, NULL)))
+ (LPTHREAD_START_ROUTINE) drdynvc_virtual_channel_client_thread, (void*) drdynvc,
+ 0, NULL)))
{
error = ERROR_INTERNAL_ERROR;
WLog_ERR(TAG, "CreateThread failed!");
if (status != CHANNEL_RC_OK)
{
WLog_ERR(TAG, "pVirtualChannelClose failed with %s [%08X]",
- WTSErrorToString(status), status);
+ WTSErrorToString(status), status);
}
drdynvc->OpenHandle = 0;
}
static VOID VCAPITYPE drdynvc_virtual_channel_init_event(LPVOID pInitHandle,
- UINT event, LPVOID pData,
- UINT dataLength)
+ UINT event, LPVOID pData,
+ UINT dataLength)
{
drdynvcPlugin* drdynvc = s_TLSPluginContext;
UINT error = CHANNEL_RC_OK;
{
case CHANNEL_EVENT_CONNECTED:
if ((error = drdynvc_virtual_channel_event_connected(drdynvc, pData,
- dataLength)))
+ dataLength)))
WLog_ERR(TAG, "drdynvc_virtual_channel_event_connected failed with error %lu",
- error);
+ error);
break;
case CHANNEL_EVENT_DISCONNECTED:
if ((error = drdynvc_virtual_channel_event_disconnected(drdynvc)))
WLog_ERR(TAG,
- "drdynvc_virtual_channel_event_disconnected failed with error %lu", error);
+ "drdynvc_virtual_channel_event_disconnected failed with error %lu", error);
break;
case CHANNEL_EVENT_TERMINATED:
if ((error = drdynvc_virtual_channel_event_terminated(drdynvc)))
WLog_ERR(TAG, "drdynvc_virtual_channel_event_terminated failed with error %lu",
- error);
+ error);
break;
}
if (error && drdynvc->rdpcontext)
setChannelError(drdynvc->rdpcontext, error,
- "drdynvc_virtual_channel_init_event reported an error");
+ "drdynvc_virtual_channel_init_event reported an error");
}
/**
drdynvc->log = WLog_Get("com.freerdp.channels.drdynvc.client");
WLog_Print(drdynvc->log, WLOG_DEBUG, "VirtualChannelEntry");
CopyMemory(&(drdynvc->channelEntryPoints), pEntryPoints,
- sizeof(CHANNEL_ENTRY_POINTS_FREERDP));
+ sizeof(CHANNEL_ENTRY_POINTS_FREERDP));
rc = drdynvc->channelEntryPoints.pVirtualChannelInit(&drdynvc->InitHandle,
- &drdynvc->channelDef, 1, VIRTUAL_CHANNEL_VERSION_WIN2000,
- drdynvc_virtual_channel_init_event);
+ &drdynvc->channelDef, 1, VIRTUAL_CHANNEL_VERSION_WIN2000,
+ drdynvc_virtual_channel_init_event);
if (CHANNEL_RC_OK != rc)
{
WLog_ERR(TAG, "pVirtualChannelInit failed with %s [%08X]",
- WTSErrorToString(rc), rc);
+ WTSErrorToString(rc), rc);
+
if (context)
*(pEntryPointsEx->ppInterface) = NULL;
}
drdynvc->channelEntryPoints.pInterface = *
- (drdynvc->channelEntryPoints.ppInterface);
+ (drdynvc->channelEntryPoints.ppInterface);
drdynvc->channelEntryPoints.ppInterface = &
- (drdynvc->channelEntryPoints.pInterface);
+ (drdynvc->channelEntryPoints.pInterface);
s_TLSPluginContext = drdynvc;
return TRUE;
}
DWORD BytesReturned;
DrdynvcServerContext* context;
UINT error = ERROR_INTERNAL_ERROR;
-
context = (DrdynvcServerContext*) arg;
-
buffer = NULL;
BytesReturned = 0;
ChannelEvent = NULL;
-
freerdp_channel_init_thread_context(context->rdpcontext);
s = Stream_New(NULL, 4096);
+
if (!s)
{
WLog_ERR(TAG, "Stream_New failed!");
return NULL;
}
- if (WTSVirtualChannelQuery(context->priv->ChannelHandle, WTSVirtualEventHandle, &buffer, &BytesReturned) == TRUE)
+ if (WTSVirtualChannelQuery(context->priv->ChannelHandle, WTSVirtualEventHandle,
+ &buffer, &BytesReturned) == TRUE)
{
if (BytesReturned == sizeof(HANDLE))
CopyMemory(&ChannelEvent, buffer, sizeof(HANDLE));
break;
}
- if (!WTSVirtualChannelRead(context->priv->ChannelHandle, 0, NULL, 0, &BytesReturned))
+ if (!WTSVirtualChannelRead(context->priv->ChannelHandle, 0, NULL, 0,
+ &BytesReturned))
{
WLog_ERR(TAG, "WTSVirtualChannelRead failed!");
break;
}
+
if (BytesReturned < 1)
continue;
+
if (!Stream_EnsureRemainingCapacity(s, BytesReturned))
{
WLog_ERR(TAG, "Stream_EnsureRemainingCapacity failed!");
}
if (!WTSVirtualChannelRead(context->priv->ChannelHandle, 0,
- (PCHAR) Stream_Buffer(s), Stream_Capacity(s), &BytesReturned))
+ (PCHAR) Stream_Buffer(s), Stream_Capacity(s), &BytesReturned))
{
WLog_ERR(TAG, "WTSVirtualChannelRead failed!");
break;
*/
static UINT drdynvc_server_start(DrdynvcServerContext* context)
{
- context->priv->ChannelHandle = WTSVirtualChannelOpen(context->vcm, WTS_CURRENT_SESSION, "drdynvc");
+ context->priv->ChannelHandle = WTSVirtualChannelOpen(context->vcm,
+ WTS_CURRENT_SESSION, "drdynvc");
if (!context->priv->ChannelHandle)
{
WLog_ERR(TAG, "CreateEvent failed!");
return ERROR_INTERNAL_ERROR;
}
+
if (!(context->priv->Thread = CreateThread(NULL, 0,
- (LPTHREAD_START_ROUTINE) drdynvc_server_thread, (void*) context, 0, NULL)))
+ (LPTHREAD_START_ROUTINE) drdynvc_server_thread, (void*) context, 0, NULL)))
{
WLog_ERR(TAG, "CreateThread failed!");
CloseHandle(context->priv->StopEvent);
*/
static UINT drdynvc_server_stop(DrdynvcServerContext* context)
{
- UINT error;
+ UINT error;
SetEvent(context->priv->StopEvent);
if (WaitForSingleObject(context->priv->Thread, INFINITE) == WAIT_FAILED)
- {
- error = GetLastError();
- WLog_ERR(TAG, "WaitForSingleObject failed with error %lu!", error);
- return error;
- }
- CloseHandle(context->priv->Thread);
+ {
+ error = GetLastError();
+ WLog_ERR(TAG, "WaitForSingleObject failed with error %lu!", error);
+ return error;
+ }
+ CloseHandle(context->priv->Thread);
return CHANNEL_RC_OK;
}
DrdynvcServerContext* drdynvc_server_context_new(HANDLE vcm)
{
DrdynvcServerContext* context;
-
context = (DrdynvcServerContext*) calloc(1, sizeof(DrdynvcServerContext));
if (context)
{
context->vcm = vcm;
-
context->Start = drdynvc_server_start;
context->Stop = drdynvc_server_stop;
-
context->priv = (DrdynvcServerPrivate*) calloc(1, sizeof(DrdynvcServerPrivate));
+
if (!context->priv)
{
WLog_ERR(TAG, "calloc failed!");
case EACCES:
rc = STATUS_ACCESS_DENIED;
break;
+
case ENOENT:
rc = STATUS_NO_SUCH_FILE;
break;
+
case EBUSY:
rc = STATUS_DEVICE_BUSY;
break;
+
case EEXIST:
rc = STATUS_OBJECT_NAME_COLLISION;
break;
+
case EISDIR:
rc = STATUS_FILE_IS_A_DIRECTORY;
break;
static DRIVE_FILE* drive_get_file_by_id(DRIVE_DEVICE* drive, UINT32 id)
{
DRIVE_FILE* file = NULL;
- void* key = (void*) (size_t) id;
-
+ void* key = (void*)(size_t) id;
file = (DRIVE_FILE*) ListDictionary_GetItemValue(drive->files, key);
-
return file;
}
UINT32 CreateOptions;
UINT32 PathLength;
char* path = NULL;
-
Stream_Read_UINT32(irp->input, DesiredAccess);
- Stream_Seek(irp->input, 16); /* AllocationSize(8), FileAttributes(4), SharedAccess(4) */
+ Stream_Seek(irp->input,
+ 16); /* AllocationSize(8), FileAttributes(4), SharedAccess(4) */
Stream_Read_UINT32(irp->input, CreateDisposition);
Stream_Read_UINT32(irp->input, CreateOptions);
Stream_Read_UINT32(irp->input, PathLength);
-
status = ConvertFromUnicode(CP_UTF8, 0, (WCHAR*) Stream_Pointer(irp->input),
- PathLength / 2, &path, 0, NULL, NULL);
+ PathLength / 2, &path, 0, NULL, NULL);
if (status < 1)
{
path = (char*) calloc(1, 1);
+
if (!path)
{
WLog_ERR(TAG, "calloc failed!");
}
}
-
FileId = irp->devman->id_sequence++;
-
file = drive_file_new(drive->path, path, FileId,
- DesiredAccess, CreateDisposition, CreateOptions);
+ DesiredAccess, CreateDisposition, CreateOptions);
if (!file)
{
{
FileId = 0;
Information = 0;
-
/* map errno to windows result */
irp->IoStatus = drive_map_posix_err(file->err);
drive_file_free(file);
}
else
{
- key = (void*) (size_t) file->id;
+ key = (void*)(size_t) file->id;
+
if (!ListDictionary_Add(drive->files, key, file))
{
WLog_ERR(TAG, "ListDictionary_Add failed!");
case FILE_OVERWRITE:
Information = FILE_SUPERSEDED;
break;
+
case FILE_OPEN_IF:
Information = FILE_OPENED;
break;
+
case FILE_OVERWRITE_IF:
Information = FILE_OVERWRITTEN;
break;
+
default:
Information = 0;
break;
Stream_Write_UINT32(irp->output, FileId);
Stream_Write_UINT8(irp->output, Information);
-
free(path);
-
return irp->Complete(irp);
}
{
void* key;
DRIVE_FILE* file;
-
file = drive_get_file_by_id(drive, irp->FileId);
-
- key = (void*) (size_t) irp->FileId;
+ key = (void*)(size_t) irp->FileId;
if (!file)
{
}
Stream_Zero(irp->output, 5); /* Padding(5) */
-
return irp->Complete(irp);
}
UINT32 Length;
UINT64 Offset;
BYTE* buffer = NULL;
-
Stream_Read_UINT32(irp->input, Length);
Stream_Read_UINT64(irp->input, Offset);
-
file = drive_get_file_by_id(drive, irp->FileId);
if (!file)
else
{
buffer = (BYTE*) malloc(Length);
+
if (!buffer)
{
WLog_ERR(TAG, "malloc failed!");
WLog_ERR(TAG, "Stream_EnsureRemainingCapacity failed!");
return ERROR_INTERNAL_ERROR;
}
+
Stream_Write(irp->output, buffer, Length);
}
free(buffer);
-
return irp->Complete(irp);
}
DRIVE_FILE* file;
UINT32 Length;
UINT64 Offset;
-
Stream_Read_UINT32(irp->input, Length);
Stream_Read_UINT64(irp->input, Offset);
Stream_Seek(irp->input, 20); /* Padding */
-
file = drive_get_file_by_id(drive, irp->FileId);
if (!file)
Stream_Write_UINT32(irp->output, Length);
Stream_Write_UINT8(irp->output, 0); /* Padding */
-
return irp->Complete(irp);
}
{
DRIVE_FILE* file;
UINT32 FsInformationClass;
-
Stream_Read_UINT32(irp->input, FsInformationClass);
-
file = drive_get_file_by_id(drive, irp->FileId);
if (!file)
DRIVE_FILE* file;
UINT32 FsInformationClass;
UINT32 Length;
-
Stream_Read_UINT32(irp->input, FsInformationClass);
Stream_Read_UINT32(irp->input, Length);
Stream_Seek(irp->input, 24); /* Padding */
-
file = drive_get_file_by_id(drive, irp->FileId);
if (!file)
{
irp->IoStatus = STATUS_UNSUCCESSFUL;
}
- else if (!drive_file_set_information(file, FsInformationClass, Length, irp->input))
+ else if (!drive_file_set_information(file, FsInformationClass, Length,
+ irp->input))
{
irp->IoStatus = STATUS_UNSUCCESSFUL;
}
irp->IoStatus = STATUS_DIRECTORY_NOT_EMPTY;
Stream_Write_UINT32(irp->output, Length);
-
return irp->Complete(irp);
}
*
* @return 0 on success, otherwise a Win32 error code
*/
-static UINT drive_process_irp_query_volume_information(DRIVE_DEVICE* drive, IRP* irp)
+static UINT drive_process_irp_query_volume_information(DRIVE_DEVICE* drive,
+ IRP* irp)
{
UINT32 FsInformationClass;
wStream* output = irp->output;
char* diskType = {"FAT32"};
WCHAR* outStr = NULL;
int length;
-
Stream_Read_UINT32(irp->input, FsInformationClass);
-
STATVFS(drive->path, &svfst);
STAT(drive->path, &st);
/* http://msdn.microsoft.com/en-us/library/cc232108.aspx */
length = ConvertToUnicode(sys_code_page, 0, volumeLabel, -1, &outStr, 0) * 2;
Stream_Write_UINT32(output, 17 + length); /* Length */
+
if (!Stream_EnsureRemainingCapacity(output, 17 + length))
{
WLog_ERR(TAG, "Stream_EnsureRemainingCapacity failed!");
return CHANNEL_RC_NO_MEMORY;
}
- Stream_Write_UINT64(output, FILE_TIME_SYSTEM_TO_RDP(st.st_ctime)); /* VolumeCreationTime */
+ Stream_Write_UINT64(output,
+ FILE_TIME_SYSTEM_TO_RDP(st.st_ctime)); /* VolumeCreationTime */
#ifdef ANDROID
Stream_Write_UINT32(output, svfst.f_fsid.__val[0]); /* VolumeSerialNumber */
#else
case FileFsSizeInformation:
/* http://msdn.microsoft.com/en-us/library/cc232107.aspx */
Stream_Write_UINT32(output, 24); /* Length */
+
if (!Stream_EnsureRemainingCapacity(output, 24))
{
WLog_ERR(TAG, "Stream_EnsureRemainingCapacity failed!");
return CHANNEL_RC_NO_MEMORY;
}
+
Stream_Write_UINT64(output, svfst.f_blocks); /* TotalAllocationUnits */
Stream_Write_UINT64(output, svfst.f_bavail); /* AvailableAllocationUnits */
Stream_Write_UINT32(output, 1); /* SectorsPerAllocationUnit */
/* http://msdn.microsoft.com/en-us/library/cc232101.aspx */
length = ConvertToUnicode(sys_code_page, 0, diskType, -1, &outStr, 0) * 2;
Stream_Write_UINT32(output, 12 + length); /* Length */
+
if (!Stream_EnsureRemainingCapacity(output, 12 + length))
{
WLog_ERR(TAG, "Stream_EnsureRemainingCapacity failed!");
return CHANNEL_RC_NO_MEMORY;
}
+
Stream_Write_UINT32(output,
- FILE_CASE_SENSITIVE_SEARCH |
- FILE_CASE_PRESERVED_NAMES |
- FILE_UNICODE_ON_DISK); /* FileSystemAttributes */
+ FILE_CASE_SENSITIVE_SEARCH |
+ FILE_CASE_PRESERVED_NAMES |
+ FILE_UNICODE_ON_DISK); /* FileSystemAttributes */
#ifdef ANDROID
Stream_Write_UINT32(output, 255); /* MaximumComponentNameLength */
#else
- Stream_Write_UINT32(output, svfst.f_namemax/*510*/); /* MaximumComponentNameLength */
+ Stream_Write_UINT32(output,
+ svfst.f_namemax/*510*/); /* MaximumComponentNameLength */
#endif
Stream_Write_UINT32(output, length); /* FileSystemNameLength */
Stream_Write(output, outStr, length); /* FileSystemName (Unicode) */
case FileFsFullSizeInformation:
/* http://msdn.microsoft.com/en-us/library/cc232104.aspx */
Stream_Write_UINT32(output, 32); /* Length */
+
if (!Stream_EnsureRemainingCapacity(output, 32))
{
WLog_ERR(TAG, "Stream_EnsureRemainingCapacity failed!");
return CHANNEL_RC_NO_MEMORY;
}
+
Stream_Write_UINT64(output, svfst.f_blocks); /* TotalAllocationUnits */
- Stream_Write_UINT64(output, svfst.f_bavail); /* CallerAvailableAllocationUnits */
+ Stream_Write_UINT64(output,
+ svfst.f_bavail); /* CallerAvailableAllocationUnits */
Stream_Write_UINT64(output, svfst.f_bfree); /* AvailableAllocationUnits */
Stream_Write_UINT32(output, 1); /* SectorsPerAllocationUnit */
Stream_Write_UINT32(output, svfst.f_bsize); /* BytesPerSector */
case FileFsDeviceInformation:
/* http://msdn.microsoft.com/en-us/library/cc232109.aspx */
Stream_Write_UINT32(output, 8); /* Length */
+
if (!Stream_EnsureRemainingCapacity(output, 8))
{
WLog_ERR(TAG, "Stream_EnsureRemainingCapacity failed!");
return CHANNEL_RC_NO_MEMORY;
}
+
Stream_Write_UINT32(output, FILE_DEVICE_DISK); /* DeviceType */
Stream_Write_UINT32(output, 0); /* Characteristics */
break;
{
UINT32 FsInformationClass;
wStream* output = irp->output;
-
Stream_Read_UINT32(irp->input, FsInformationClass);
-
Stream_Write_UINT32(output, 0); /* Length */
-
return irp->Complete(irp);
}
BYTE InitialQuery;
UINT32 PathLength;
UINT32 FsInformationClass;
-
Stream_Read_UINT32(irp->input, FsInformationClass);
Stream_Read_UINT8(irp->input, InitialQuery);
Stream_Read_UINT32(irp->input, PathLength);
Stream_Seek(irp->input, 23); /* Padding */
-
status = ConvertFromUnicode(CP_UTF8, 0, (WCHAR*) Stream_Pointer(irp->input),
- PathLength / 2, &path, 0, NULL, NULL);
+ PathLength / 2, &path, 0, NULL, NULL);
if (status < 1)
if (!(path = (char*) calloc(1, 1)))
irp->IoStatus = STATUS_UNSUCCESSFUL;
Stream_Write_UINT32(irp->output, 0); /* Length */
}
- else if (!drive_file_query_directory(file, FsInformationClass, InitialQuery, path, irp->output))
+ else if (!drive_file_query_directory(file, FsInformationClass, InitialQuery,
+ path, irp->output))
{
irp->IoStatus = STATUS_NO_MORE_FILES;
}
free(path);
-
return irp->Complete(irp);
}
return irp->Complete(irp);
break;
}
+
return CHANNEL_RC_OK;
}
static UINT drive_process_irp(DRIVE_DEVICE* drive, IRP* irp)
{
UINT error;
-
irp->IoStatus = STATUS_SUCCESS;
switch (irp->MajorFunction)
error = irp->Complete(irp);
break;
}
+
return error;
}
wMessage message;
DRIVE_DEVICE* drive = (DRIVE_DEVICE*) arg;
UINT error = CHANNEL_RC_OK;
-
freerdp_channel_init_thread_context(drive->rdpcontext);
+
while (1)
{
if (!MessageQueue_Wait(drive->IrpQueue))
}
if (error && drive->rdpcontext)
- setChannelError(drive->rdpcontext, error, "drive_thread_func reported an error");
+ setChannelError(drive->rdpcontext, error,
+ "drive_thread_func reported an error");
+
ExitThread((DWORD)error);
return NULL;
}
static UINT drive_irp_request(DEVICE* device, IRP* irp)
{
DRIVE_DEVICE* drive = (DRIVE_DEVICE*) device;
+
if (!MessageQueue_Post(drive->IrpQueue, NULL, 0, (void*) irp, NULL))
{
WLog_ERR(TAG, "MessageQueue_Post failed!");
return ERROR_INTERNAL_ERROR;
}
+
return CHANNEL_RC_OK;
}
static UINT drive_free(DEVICE* device)
{
DRIVE_DEVICE* drive = (DRIVE_DEVICE*) device;
- UINT error = CHANNEL_RC_OK;
+ UINT error = CHANNEL_RC_OK;
- if (MessageQueue_PostQuit(drive->IrpQueue, 0) && (WaitForSingleObject(drive->thread, INFINITE) == WAIT_FAILED))
- {
- error = GetLastError();
- WLog_ERR(TAG, "WaitForSingleObject failed with error %lu", error);
- return error;
- }
+ if (MessageQueue_PostQuit(drive->IrpQueue, 0)
+ && (WaitForSingleObject(drive->thread, INFINITE) == WAIT_FAILED))
+ {
+ error = GetLastError();
+ WLog_ERR(TAG, "WaitForSingleObject failed with error %lu", error);
+ return error;
+ }
CloseHandle(drive->thread);
-
ListDictionary_Free(drive->files);
MessageQueue_Free(drive->IrpQueue);
-
Stream_Free(drive->device.data, TRUE);
-
free(drive);
- return error;
+ return error;
}
/**
*
* @return 0 on success, otherwise a Win32 error code
*/
-UINT drive_register_drive_path(PDEVICE_SERVICE_ENTRY_POINTS pEntryPoints, char* name, char* path)
+UINT drive_register_drive_path(PDEVICE_SERVICE_ENTRY_POINTS pEntryPoints,
+ char* name, char* path)
{
int i, length;
DRIVE_DEVICE* drive;
UINT error;
-
#ifdef WIN32
+
/*
* We cannot enter paths like c:\ because : is an arg separator
* thus, paths are entered as c+\ and the + is substituted here
*/
if (path[1] == '+')
{
- if ((path[0]>='a' && path[0]<='z') || (path[0]>='A' && path[0]<='Z'))
+ if ((path[0] >= 'a' && path[0] <= 'z') || (path[0] >= 'A' && path[0] <= 'Z'))
{
path[1] = ':';
}
}
+
#endif
if (name[0] && path[0])
{
drive = (DRIVE_DEVICE*) calloc(1, sizeof(DRIVE_DEVICE));
+
if (!drive)
{
WLog_ERR(TAG, "calloc failed!");
drive->device.IRPRequest = drive_irp_request;
drive->device.Free = drive_free;
drive->rdpcontext = pEntryPoints->rdpcontext;
-
length = (int) strlen(name);
drive->device.data = Stream_New(NULL, length + 1);
+
if (!drive->device.data)
{
WLog_ERR(TAG, "Stream_New failed!");
Stream_Write_UINT8(drive->device.data, name[i] < 0 ? '_' : name[i]);
drive->path = path;
-
drive->files = ListDictionary_New(TRUE);
+
if (!drive->files)
{
WLog_ERR(TAG, "ListDictionary_New failed!");
error = CHANNEL_RC_NO_MEMORY;
goto out_error;
}
- ListDictionary_ValueObject(drive->files)->fnObjectFree = (OBJECT_FREE_FN) drive_file_free;
+ ListDictionary_ValueObject(drive->files)->fnObjectFree =
+ (OBJECT_FREE_FN) drive_file_free;
drive->IrpQueue = MessageQueue_New(NULL);
+
if (!drive->IrpQueue)
{
WLog_ERR(TAG, "ListDictionary_New failed!");
goto out_error;
}
- if ((error = pEntryPoints->RegisterDevice(pEntryPoints->devman, (DEVICE*) drive)))
+ if ((error = pEntryPoints->RegisterDevice(pEntryPoints->devman,
+ (DEVICE*) drive)))
{
WLog_ERR(TAG, "RegisterDevice failed with error %lu!", error);
goto out_error;
}
- if (!(drive->thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) drive_thread_func, drive, CREATE_SUSPENDED, NULL)))
+ if (!(drive->thread = CreateThread(NULL, 0,
+ (LPTHREAD_START_ROUTINE) drive_thread_func, drive, CREATE_SUSPENDED, NULL)))
{
WLog_ERR(TAG, "CreateThread failed!");
goto out_error;
ResumeThread(drive->thread);
}
+
return CHANNEL_RC_OK;
out_error:
MessageQueue_Free(drive->IrpQueue);
char* dev;
int len;
char devlist[512], buf[512];
- char *bufdup;
- char *devdup;
+ char* bufdup;
+ char* devdup;
#endif
-
drive = (RDPDR_DRIVE*) pEntryPoints->device;
-
#ifndef WIN32
-
sys_code_page = CP_UTF8;
+
if (strcmp(drive->Path, "*") == 0)
{
/* all drives */
-
free(drive->Path);
drive->Path = _strdup("/");
+
if (!drive->Path)
{
WLog_ERR(TAG, "_strdup failed!");
else if (strcmp(drive->Path, "%") == 0)
{
char* home_env = NULL;
-
/* home directory */
-
home_env = getenv("HOME");
free(drive->Path);
if (home_env)
{
drive->Path = _strdup(home_env);
+
if (!drive->Path)
{
WLog_ERR(TAG, "_strdup failed!");
else
{
drive->Path = _strdup("/");
+
if (!drive->Path)
{
WLog_ERR(TAG, "_strdup failed!");
}
error = drive_register_drive_path(pEntryPoints, drive->Name, drive->Path);
-
#else
sys_code_page = GetACP();
+
/* Special case: path[0] == '*' -> export all drives */
/* Special case: path[0] == '%' -> user home dir */
if (strcmp(drive->Path, "%") == 0)
{
GetEnvironmentVariableA("USERPROFILE", buf, sizeof(buf));
PathCchAddBackslashA(buf, sizeof(buf));
-
free(drive->Path);
drive->Path = _strdup(buf);
+
if (!drive->Path)
{
WLog_ERR(TAG, "_strdup failed!");
return CHANNEL_RC_NO_MEMORY;
}
+
error = drive_register_drive_path(pEntryPoints, drive->Name, drive->Path);
}
else if (strcmp(drive->Path, "*") == 0)
{
int i;
-
/* Enumerate all devices: */
GetLogicalDriveStringsA(sizeof(devlist) - 1, devlist);
buf[len + 1] = dev[0];
buf[len + 2] = 0;
buf[len + 3] = 0;
+
if (!(bufdup = _strdup(buf)))
{
WLog_ERR(TAG, "_strdup failed!");
return CHANNEL_RC_NO_MEMORY;
}
+
if (!(devdup = _strdup(dev)))
{
WLog_ERR(TAG, "_strdup failed!");
{
error = drive_register_drive_path(pEntryPoints, drive->Name, drive->Path);
}
-#endif
+#endif
return error;
}
PULONG pSessionId = NULL;
if (WTSQuerySessionInformationA(echo->context.vcm, WTS_CURRENT_SESSION,
- WTSSessionId, (LPSTR*) &pSessionId, &BytesReturned) == FALSE)
+ WTSSessionId, (LPSTR*) &pSessionId, &BytesReturned) == FALSE)
{
WLog_ERR(TAG, "WTSQuerySessionInformationA failed!");
return ERROR_INTERNAL_ERROR;
}
- echo->SessionId = (DWORD) *pSessionId;
+ echo->SessionId = (DWORD) * pSessionId;
WTSFreeMemory(pSessionId);
-
hEvent = WTSVirtualChannelManagerGetEventHandle(echo->context.vcm);
StartTick = GetTickCount();
while (echo->echo_channel == NULL)
{
if (WaitForSingleObject(hEvent, 1000) == WAIT_FAILED)
- {
- Error = GetLastError();
- WLog_ERR(TAG, "WaitForSingleObject failed with error %lu!", Error);
- return Error;
- }
+ {
+ Error = GetLastError();
+ WLog_ERR(TAG, "WaitForSingleObject failed with error %lu!", Error);
+ return Error;
+ }
echo->echo_channel = WTSVirtualChannelOpenEx(echo->SessionId,
- "ECHO", WTS_CHANNEL_OPTION_DYNAMIC);
+ "ECHO", WTS_CHANNEL_OPTION_DYNAMIC);
if (echo->echo_channel)
break;
Error = GetLastError();
+
if (Error == ERROR_NOT_FOUND)
break;
echo_server* echo = (echo_server*) arg;
UINT error;
DWORD status;
-
freerdp_channel_init_thread_context(echo->context.rdpcontext);
+
if ((error = echo_server_open_channel(echo)))
{
UINT error2 = 0;
WLog_ERR(TAG, "echo_server_open_channel failed with error %lu!", error);
- IFCALLRET(echo->context.OpenResult, error2, &echo->context, ECHO_SERVER_OPEN_RESULT_NOTSUPPORTED);
+ IFCALLRET(echo->context.OpenResult, error2, &echo->context,
+ ECHO_SERVER_OPEN_RESULT_NOTSUPPORTED);
+
if (error2)
- WLog_ERR(TAG, "echo server's OpenResult callback failed with error %lu", error2);
+ WLog_ERR(TAG, "echo server's OpenResult callback failed with error %lu",
+ error2);
+
goto out;
}
BytesReturned = 0;
ChannelEvent = NULL;
- if (WTSVirtualChannelQuery(echo->echo_channel, WTSVirtualEventHandle, &buffer, &BytesReturned) == TRUE)
+ if (WTSVirtualChannelQuery(echo->echo_channel, WTSVirtualEventHandle, &buffer,
+ &BytesReturned) == TRUE)
{
if (BytesReturned == sizeof(HANDLE))
CopyMemory(&ChannelEvent, buffer, sizeof(HANDLE));
if (status == WAIT_OBJECT_0)
{
- IFCALLRET(echo->context.OpenResult, error, &echo->context, ECHO_SERVER_OPEN_RESULT_CLOSED);
+ IFCALLRET(echo->context.OpenResult, error, &echo->context,
+ ECHO_SERVER_OPEN_RESULT_CLOSED);
+
if (error)
WLog_ERR(TAG, "OpenResult failed with error %lu!", error);
+
break;
}
- if (WTSVirtualChannelQuery(echo->echo_channel, WTSVirtualChannelReady, &buffer, &BytesReturned) == FALSE)
+ if (WTSVirtualChannelQuery(echo->echo_channel, WTSVirtualChannelReady, &buffer,
+ &BytesReturned) == FALSE)
{
- IFCALLRET(echo->context.OpenResult, error, &echo->context, ECHO_SERVER_OPEN_RESULT_ERROR);
+ IFCALLRET(echo->context.OpenResult, error, &echo->context,
+ ECHO_SERVER_OPEN_RESULT_ERROR);
+
if (error)
WLog_ERR(TAG, "OpenResult failed with error %lu!", error);
+
break;
}
ready = *((BOOL*) buffer);
-
WTSFreeMemory(buffer);
if (ready)
{
- IFCALLRET(echo->context.OpenResult, error, &echo->context, ECHO_SERVER_OPEN_RESULT_OK);
+ IFCALLRET(echo->context.OpenResult, error, &echo->context,
+ ECHO_SERVER_OPEN_RESULT_OK);
+
if (error)
WLog_ERR(TAG, "OpenResult failed with error %lu!", error);
+
break;
}
}
s = Stream_New(NULL, 4096);
+
if (!s)
{
WLog_ERR(TAG, "Stream_New failed!");
while (ready)
{
- status = WaitForMultipleObjects(nCount, events, FALSE, INFINITE);
+ status = WaitForMultipleObjects(nCount, events, FALSE, INFINITE);
- if (status == WAIT_FAILED)
- {
- error = GetLastError();
- WLog_ERR(TAG, "WaitForMultipleObjects failed with error %lu", error);
- break;
- }
+ if (status == WAIT_FAILED)
+ {
+ error = GetLastError();
+ WLog_ERR(TAG, "WaitForMultipleObjects failed with error %lu", error);
+ break;
+ }
- if (status == WAIT_OBJECT_0)
+ if (status == WAIT_OBJECT_0)
break;
Stream_SetPosition(s, 0);
-
WTSVirtualChannelRead(echo->echo_channel, 0, NULL, 0, &BytesReturned);
+
if (BytesReturned < 1)
continue;
+
if (!Stream_EnsureRemainingCapacity(s, BytesReturned))
{
WLog_ERR(TAG, "Stream_EnsureRemainingCapacity failed!");
}
if (WTSVirtualChannelRead(echo->echo_channel, 0, (PCHAR) Stream_Buffer(s),
- (ULONG) Stream_Capacity(s), &BytesReturned) == FALSE)
+ (ULONG) Stream_Capacity(s), &BytesReturned) == FALSE)
{
WLog_ERR(TAG, "WTSVirtualChannelRead failed!");
error = ERROR_INTERNAL_ERROR;
break;
}
- IFCALLRET(echo->context.Response, error, &echo->context, (BYTE *) Stream_Buffer(s), BytesReturned);
+ IFCALLRET(echo->context.Response, error, &echo->context,
+ (BYTE*) Stream_Buffer(s), BytesReturned);
+
if (error)
{
WLog_ERR(TAG, "Response failed with error %lu!", error);
break;
}
}
+
Stream_Free(s, TRUE);
WTSVirtualChannelClose(echo->echo_channel);
echo->echo_channel = NULL;
out:
+
if (error && echo->context.rdpcontext)
- setChannelError(echo->context.rdpcontext, error, "echo_server_thread_func reported an error");
+ setChannelError(echo->context.rdpcontext, error,
+ "echo_server_thread_func reported an error");
ExitThread((DWORD)error);
return NULL;
return ERROR_INTERNAL_ERROR;
}
- if (!(echo->thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) echo_server_thread_func, (void*) echo, 0, NULL)))
+ if (!(echo->thread = CreateThread(NULL, 0,
+ (LPTHREAD_START_ROUTINE) echo_server_thread_func, (void*) echo, 0, NULL)))
{
WLog_ERR(TAG, "CreateEvent failed!");
CloseHandle(echo->stopEvent);
return ERROR_INTERNAL_ERROR;
}
}
+
return CHANNEL_RC_OK;
}
*/
static UINT echo_server_close(echo_server_context* context)
{
- UINT error = CHANNEL_RC_OK;
+ UINT error = CHANNEL_RC_OK;
echo_server* echo = (echo_server*) context;
if (echo->thread)
SetEvent(echo->stopEvent);
if (WaitForSingleObject(echo->thread, INFINITE) == WAIT_FAILED)
- {
- error = GetLastError();
- WLog_ERR(TAG, "WaitForSingleObject failed with error %lu", error);
- return error;
- }
+ {
+ error = GetLastError();
+ WLog_ERR(TAG, "WaitForSingleObject failed with error %lu", error);
+ return error;
+ }
CloseHandle(echo->thread);
CloseHandle(echo->stopEvent);
echo->thread = NULL;
echo->stopEvent = NULL;
}
+
return error;
}
-static BOOL echo_server_request(echo_server_context* context, const BYTE* buffer, UINT32 length)
+static BOOL echo_server_request(echo_server_context* context,
+ const BYTE* buffer, UINT32 length)
{
echo_server* echo = (echo_server*) context;
-
return WTSVirtualChannelWrite(echo->echo_channel, (PCHAR) buffer, length, NULL);
}
echo_server_context* echo_server_context_new(HANDLE vcm)
{
echo_server* echo;
-
echo = (echo_server*) calloc(1, sizeof(echo_server));
if (echo)
void echo_server_context_free(echo_server_context* context)
{
echo_server* echo = (echo_server*) context;
-
echo_server_close(context);
-
free(echo);
}
winpr_HexDump(Stream_Buffer(s), Stream_Length(s));
#endif
status = encomsp->channelEntryPoints.pVirtualChannelWrite(encomsp->OpenHandle,
- Stream_Buffer(s), (UINT32) Stream_Length(s), s);
+ Stream_Buffer(s), (UINT32) Stream_Length(s), s);
if (status != CHANNEL_RC_OK)
WLog_ERR(TAG, "VirtualChannelWrite failed with %s [%08X]",
- WTSErrorToString(status), status);
+ WTSErrorToString(status), status);
return status;
}
* @return 0 on success, otherwise a Win32 error code
*/
static UINT encomsp_recv_filter_updated_pdu(encomspPlugin* encomsp, wStream* s,
- ENCOMSP_ORDER_HEADER* header)
+ ENCOMSP_ORDER_HEADER* header)
{
int beg, end;
EncomspClientContext* context;
* @return 0 on success, otherwise a Win32 error code
*/
static UINT encomsp_recv_application_created_pdu(encomspPlugin* encomsp,
- wStream* s, ENCOMSP_ORDER_HEADER* header)
+ wStream* s, ENCOMSP_ORDER_HEADER* header)
{
int beg, end;
EncomspClientContext* context;
* @return 0 on success, otherwise a Win32 error code
*/
static UINT encomsp_recv_application_removed_pdu(encomspPlugin* encomsp,
- wStream* s, ENCOMSP_ORDER_HEADER* header)
+ wStream* s, ENCOMSP_ORDER_HEADER* header)
{
int beg, end;
EncomspClientContext* context;
* @return 0 on success, otherwise a Win32 error code
*/
static UINT encomsp_recv_window_created_pdu(encomspPlugin* encomsp, wStream* s,
- ENCOMSP_ORDER_HEADER* header)
+ ENCOMSP_ORDER_HEADER* header)
{
int beg, end;
EncomspClientContext* context;
* @return 0 on success, otherwise a Win32 error code
*/
static UINT encomsp_recv_window_removed_pdu(encomspPlugin* encomsp, wStream* s,
- ENCOMSP_ORDER_HEADER* header)
+ ENCOMSP_ORDER_HEADER* header)
{
int beg, end;
EncomspClientContext* context;
* @return 0 on success, otherwise a Win32 error code
*/
static UINT encomsp_recv_show_window_pdu(encomspPlugin* encomsp, wStream* s,
- ENCOMSP_ORDER_HEADER* header)
+ ENCOMSP_ORDER_HEADER* header)
{
int beg, end;
EncomspClientContext* context;
* @return 0 on success, otherwise a Win32 error code
*/
static UINT encomsp_recv_participant_created_pdu(encomspPlugin* encomsp,
- wStream* s, ENCOMSP_ORDER_HEADER* header)
+ wStream* s, ENCOMSP_ORDER_HEADER* header)
{
int beg, end;
EncomspClientContext* context;
* @return 0 on success, otherwise a Win32 error code
*/
static UINT encomsp_recv_participant_removed_pdu(encomspPlugin* encomsp,
- wStream* s, ENCOMSP_ORDER_HEADER* header)
+ wStream* s, ENCOMSP_ORDER_HEADER* header)
{
int beg, end;
EncomspClientContext* context;
if (error)
WLog_ERR(TAG, "context->ChangeParticipantControlLevel failed with error %lu",
- error);
+ error);
return error;
}
* @return 0 on success, otherwise a Win32 error code
*/
static UINT encomsp_recv_graphics_stream_paused_pdu(encomspPlugin* encomsp,
- wStream* s, ENCOMSP_ORDER_HEADER* header)
+ wStream* s, ENCOMSP_ORDER_HEADER* header)
{
int beg, end;
EncomspClientContext* context;
* @return 0 on success, otherwise a Win32 error code
*/
static UINT encomsp_recv_graphics_stream_resumed_pdu(encomspPlugin* encomsp,
- wStream* s, ENCOMSP_ORDER_HEADER* header)
+ wStream* s, ENCOMSP_ORDER_HEADER* header)
{
int beg, end;
EncomspClientContext* context;
if ((error = encomsp_recv_application_removed_pdu(encomsp, s, &header)))
{
WLog_ERR(TAG, "encomsp_recv_application_removed_pdu failed with error %lu!",
- error);
+ error);
return error;
}
if ((error = encomsp_recv_application_created_pdu(encomsp, s, &header)))
{
WLog_ERR(TAG, "encomsp_recv_application_removed_pdu failed with error %lu!",
- error);
+ error);
return error;
}
if ((error = encomsp_recv_participant_removed_pdu(encomsp, s, &header)))
{
WLog_ERR(TAG, "encomsp_recv_participant_removed_pdu failed with error %lu!",
- error);
+ error);
return error;
}
if ((error = encomsp_recv_participant_created_pdu(encomsp, s, &header)))
{
WLog_ERR(TAG, "encomsp_recv_participant_created_pdu failed with error %lu!",
- error);
+ error);
return error;
}
case ODTYPE_PARTICIPANT_CTRL_CHANGED:
if ((error = encomsp_recv_change_participant_control_level_pdu(encomsp, s,
- &header)))
+ &header)))
{
WLog_ERR(TAG,
- "encomsp_recv_change_participant_control_level_pdu failed with error %lu!",
- error);
+ "encomsp_recv_change_participant_control_level_pdu failed with error %lu!",
+ error);
return error;
}
if ((error = encomsp_recv_graphics_stream_paused_pdu(encomsp, s, &header)))
{
WLog_ERR(TAG, "encomsp_recv_graphics_stream_paused_pdu failed with error %lu!",
- error);
+ error);
return error;
}
if ((error = encomsp_recv_graphics_stream_resumed_pdu(encomsp, s, &header)))
{
WLog_ERR(TAG, "encomsp_recv_graphics_stream_resumed_pdu failed with error %lu!",
- error);
+ error);
return error;
}
else
{
status = plugin->channelEntryPoints.pVirtualChannelWrite(plugin->OpenHandle,
- Stream_Buffer(s), (UINT32) Stream_GetPosition(s), s);
+ Stream_Buffer(s), (UINT32) Stream_GetPosition(s), s);
}
if (status != CHANNEL_RC_OK)
{
Stream_Free(s, TRUE);
WLog_ERR(TAG, "VirtualChannelWrite failed with %s [%08X]",
- WTSErrorToString(status), status);
+ WTSErrorToString(status), status);
}
return status;
* @return 0 on success, otherwise a Win32 error code
*/
static UINT encomsp_virtual_channel_event_data_received(encomspPlugin* encomsp,
- void* pData, UINT32 dataLength, UINT32 totalLength, UINT32 dataFlags)
+ void* pData, UINT32 dataLength, UINT32 totalLength, UINT32 dataFlags)
{
wStream* data_in;
}
static VOID VCAPITYPE encomsp_virtual_channel_open_event(DWORD openHandle,
- UINT event,
- LPVOID pData, UINT32 dataLength, UINT32 totalLength, UINT32 dataFlags)
+ UINT event,
+ LPVOID pData, UINT32 dataLength, UINT32 totalLength, UINT32 dataFlags)
{
encomspPlugin* encomsp = s_TLSPluginContext;
UINT error = CHANNEL_RC_OK;
{
case CHANNEL_EVENT_DATA_RECEIVED:
if ((error = encomsp_virtual_channel_event_data_received(encomsp, pData,
- dataLength, totalLength, dataFlags)))
+ dataLength, totalLength, dataFlags)))
WLog_ERR(TAG,
- "encomsp_virtual_channel_event_data_received failed with error %lu", error);
+ "encomsp_virtual_channel_event_data_received failed with error %lu", error);
break;
if (error && encomsp->rdpcontext)
setChannelError(encomsp->rdpcontext, error,
- "encomsp_virtual_channel_open_event reported an error");
+ "encomsp_virtual_channel_open_event reported an error");
return;
}
wMessage message;
encomspPlugin* encomsp = (encomspPlugin*) arg;
UINT error = CHANNEL_RC_OK;
-
freerdp_channel_init_thread_context(encomsp->rdpcontext);
encomsp_process_connect(encomsp);
if (error && encomsp->rdpcontext)
setChannelError(encomsp->rdpcontext, error,
- "encomsp_virtual_channel_client_thread reported an error");
+ "encomsp_virtual_channel_client_thread reported an error");
ExitThread((DWORD)error);
return NULL;
* @return 0 on success, otherwise a Win32 error code
*/
static UINT encomsp_virtual_channel_event_connected(encomspPlugin* encomsp,
- LPVOID pData, UINT32 dataLength)
+ LPVOID pData, UINT32 dataLength)
{
UINT32 status;
status = encomsp->channelEntryPoints.pVirtualChannelOpen(encomsp->InitHandle,
- &encomsp->OpenHandle, encomsp->channelDef.name,
- encomsp_virtual_channel_open_event);
+ &encomsp->OpenHandle, encomsp->channelDef.name,
+ encomsp_virtual_channel_open_event);
if (status != CHANNEL_RC_OK)
{
WLog_ERR(TAG, "pVirtualChannelOpen failed with %s [%08X]",
- WTSErrorToString(status), status);
+ WTSErrorToString(status), status);
return status;
}
}
if (!(encomsp->thread = CreateThread(NULL, 0,
- (LPTHREAD_START_ROUTINE) encomsp_virtual_channel_client_thread, (void*) encomsp,
- 0, NULL)))
+ (LPTHREAD_START_ROUTINE) encomsp_virtual_channel_client_thread, (void*) encomsp,
+ 0, NULL)))
{
WLog_ERR(TAG, "CreateThread failed!");
MessageQueue_Free(encomsp->queue);
if (CHANNEL_RC_OK != rc)
{
WLog_ERR(TAG, "pVirtualChannelClose failed with %s [%08X]",
- WTSErrorToString(rc), rc);
+ WTSErrorToString(rc), rc);
return rc;
}
}
static VOID VCAPITYPE encomsp_virtual_channel_init_event(LPVOID pInitHandle,
- UINT event, LPVOID pData,
- UINT dataLength)
+ UINT event, LPVOID pData,
+ UINT dataLength)
{
encomspPlugin* encomsp = s_TLSPluginContext;
UINT error = CHANNEL_RC_OK;
{
case CHANNEL_EVENT_CONNECTED:
if ((error = encomsp_virtual_channel_event_connected(encomsp, pData,
- dataLength)))
+ dataLength)))
WLog_ERR(TAG, "encomsp_virtual_channel_event_connected failed with error %lu",
- error);
+ error);
break;
case CHANNEL_EVENT_DISCONNECTED:
if ((error = encomsp_virtual_channel_event_disconnected(encomsp)))
WLog_ERR(TAG,
- "encomsp_virtual_channel_event_disconnected failed with error %lu", error);
+ "encomsp_virtual_channel_event_disconnected failed with error %lu", error);
break;
if (error && encomsp->rdpcontext)
setChannelError(encomsp->rdpcontext, error,
- "encomsp_virtual_channel_init_event reported an error");
+ "encomsp_virtual_channel_init_event reported an error");
}
/* encomsp is always built-in */
}
CopyMemory(&(encomsp->channelEntryPoints), pEntryPoints,
- sizeof(CHANNEL_ENTRY_POINTS_FREERDP));
+ sizeof(CHANNEL_ENTRY_POINTS_FREERDP));
rc = encomsp->channelEntryPoints.pVirtualChannelInit(&encomsp->InitHandle,
- &encomsp->channelDef, 1, VIRTUAL_CHANNEL_VERSION_WIN2000,
- encomsp_virtual_channel_init_event);
+ &encomsp->channelDef, 1, VIRTUAL_CHANNEL_VERSION_WIN2000,
+ encomsp_virtual_channel_init_event);
if (CHANNEL_RC_OK != rc)
{
WLog_ERR(TAG, "pVirtualChannelInit failed with %s [%08X]",
- WTSErrorToString(rc), rc);
+ WTSErrorToString(rc), rc);
goto error_out;
}
encomsp->channelEntryPoints.pInterface = *
- (encomsp->channelEntryPoints.ppInterface);
+ (encomsp->channelEntryPoints.ppInterface);
encomsp->channelEntryPoints.ppInterface = &
- (encomsp->channelEntryPoints.pInterface);
+ (encomsp->channelEntryPoints.pInterface);
s_TLSPluginContext = encomsp;
return TRUE;
error_out:
+
if (context)
*(pEntryPointsEx->ppInterface) = NULL;
Stream_Read_UINT16(s, header->Type); /* Type (2 bytes) */
Stream_Read_UINT16(s, header->Length); /* Length (2 bytes) */
-
return CHANNEL_RC_OK;
}
{
Stream_Write_UINT16(s, header->Type); /* Type (2 bytes) */
Stream_Write_UINT16(s, header->Length); /* Length (2 bytes) */
-
return 1;
}
return -1;
Stream_Read(s, &(str->wString), (str->cchString * 2)); /* String (variable) */
-
return 1;
}
*
* @return 0 on success, otherwise a Win32 error code
*/
-static UINT encomsp_recv_change_participant_control_level_pdu(EncomspServerContext* context, wStream* s, ENCOMSP_ORDER_HEADER* header)
+static UINT encomsp_recv_change_participant_control_level_pdu(
+ EncomspServerContext* context, wStream* s, ENCOMSP_ORDER_HEADER* header)
{
int beg, end;
ENCOMSP_CHANGE_PARTICIPANT_CONTROL_LEVEL_PDU pdu;
UINT error = CHANNEL_RC_OK;
-
beg = ((int) Stream_GetPosition(s)) - ENCOMSP_ORDER_HEADER_SIZE;
-
CopyMemory(&pdu, header, sizeof(ENCOMSP_ORDER_HEADER));
if (Stream_GetRemainingLength(s) < 6)
Stream_Read_UINT16(s, pdu.Flags); /* Flags (2 bytes) */
Stream_Read_UINT32(s, pdu.ParticipantId); /* ParticipantId (4 bytes) */
-
end = (int) Stream_GetPosition(s);
if ((beg + header->Length) < end)
}
IFCALLRET(context->ChangeParticipantControlLevel, error, context, &pdu);
+
if (error)
- WLog_ERR(TAG, "context->ChangeParticipantControlLevel failed with error %lu", error);
+ WLog_ERR(TAG, "context->ChangeParticipantControlLevel failed with error %lu",
+ error);
return error;
}
*
* @return 0 on success, otherwise a Win32 error code
*/
-static UINT encomsp_server_receive_pdu(EncomspServerContext* context, wStream* s)
+static UINT encomsp_server_receive_pdu(EncomspServerContext* context,
+ wStream* s)
{
UINT error = CHANNEL_RC_OK;
ENCOMSP_ORDER_HEADER header;
return error;
}
- WLog_INFO(TAG, "EncomspReceive: Type: %d Length: %d", header.Type, header.Length);
+ WLog_INFO(TAG, "EncomspReceive: Type: %d Length: %d", header.Type,
+ header.Length);
switch (header.Type)
{
case ODTYPE_PARTICIPANT_CTRL_CHANGED:
- if ((error = encomsp_recv_change_participant_control_level_pdu(context, s, &header)))
+ if ((error = encomsp_recv_change_participant_control_level_pdu(context, s,
+ &header)))
{
- WLog_ERR(TAG, "encomsp_recv_change_participant_control_level_pdu failed with error %lu!", error);
+ WLog_ERR(TAG,
+ "encomsp_recv_change_participant_control_level_pdu failed with error %lu!",
+ error);
return error;
}
ENCOMSP_ORDER_HEADER* header;
EncomspServerContext* context;
UINT error = CHANNEL_RC_OK;
- DWORD status;
-
+ DWORD status;
context = (EncomspServerContext*) arg;
-
freerdp_channel_init_thread_context(context->rdpcontext);
buffer = NULL;
BytesReturned = 0;
ChannelEvent = NULL;
-
s = Stream_New(NULL, 4096);
+
if (!s)
{
WLog_ERR(TAG, "Stream_New failed!");
goto out;
}
- if (WTSVirtualChannelQuery(context->priv->ChannelHandle, WTSVirtualEventHandle, &buffer, &BytesReturned) == TRUE)
+ if (WTSVirtualChannelQuery(context->priv->ChannelHandle, WTSVirtualEventHandle,
+ &buffer, &BytesReturned) == TRUE)
{
if (BytesReturned == sizeof(HANDLE))
CopyMemory(&ChannelEvent, buffer, sizeof(HANDLE));
while (1)
{
- status = WaitForMultipleObjects(nCount, events, FALSE, INFINITE);
+ status = WaitForMultipleObjects(nCount, events, FALSE, INFINITE);
- if (status == WAIT_FAILED)
- {
- error = GetLastError();
- WLog_ERR(TAG, "WaitForMultipleObjects failed with error %lu", error);
- break;
- }
+ if (status == WAIT_FAILED)
+ {
+ error = GetLastError();
+ WLog_ERR(TAG, "WaitForMultipleObjects failed with error %lu", error);
+ break;
+ }
- status = WaitForSingleObject(context->priv->StopEvent, 0);
+ status = WaitForSingleObject(context->priv->StopEvent, 0);
- if (status == WAIT_FAILED)
- {
- error = GetLastError();
- WLog_ERR(TAG, "WaitForSingleObject failed with error %lu", error);
- break;
- }
+ if (status == WAIT_FAILED)
+ {
+ error = GetLastError();
+ WLog_ERR(TAG, "WaitForSingleObject failed with error %lu", error);
+ break;
+ }
if (status == WAIT_OBJECT_0)
{
}
WTSVirtualChannelRead(context->priv->ChannelHandle, 0, NULL, 0, &BytesReturned);
+
if (BytesReturned < 1)
continue;
+
if (!Stream_EnsureRemainingCapacity(s, BytesReturned))
{
WLog_ERR(TAG, "Stream_EnsureRemainingCapacity failed!");
error = CHANNEL_RC_NO_MEMORY;
break;
}
+
if (!WTSVirtualChannelRead(context->priv->ChannelHandle, 0,
- (PCHAR) Stream_Buffer(s), Stream_Capacity(s), &BytesReturned))
+ (PCHAR) Stream_Buffer(s), Stream_Capacity(s), &BytesReturned))
{
WLog_ERR(TAG, "WTSVirtualChannelRead failed!");
error = ERROR_INTERNAL_ERROR;
{
Stream_SealLength(s);
Stream_SetPosition(s, 0);
+
if ((error = encomsp_server_receive_pdu(context, s)))
{
WLog_ERR(TAG, "encomsp_server_receive_pdu failed with error %lu!", error);
break;
}
+
Stream_SetPosition(s, 0);
}
}
Stream_Free(s, TRUE);
out:
+
if (error && context->rdpcontext)
- setChannelError(context->rdpcontext, error, "encomsp_server_thread reported an error");
+ setChannelError(context->rdpcontext, error,
+ "encomsp_server_thread reported an error");
ExitThread((DWORD)error);
return NULL;
*/
static UINT encomsp_server_start(EncomspServerContext* context)
{
- context->priv->ChannelHandle = WTSVirtualChannelOpen(context->vcm, WTS_CURRENT_SESSION, "encomsp");
+ context->priv->ChannelHandle = WTSVirtualChannelOpen(context->vcm,
+ WTS_CURRENT_SESSION, "encomsp");
if (!context->priv->ChannelHandle)
return CHANNEL_RC_BAD_CHANNEL;
}
if (!(context->priv->Thread = CreateThread(NULL, 0,
- (LPTHREAD_START_ROUTINE) encomsp_server_thread, (void*) context, 0, NULL)))
+ (LPTHREAD_START_ROUTINE) encomsp_server_thread, (void*) context, 0, NULL)))
{
WLog_ERR(TAG, "CreateThread failed!");
CloseHandle(context->priv->StopEvent);
*/
static UINT encomsp_server_stop(EncomspServerContext* context)
{
- UINT error = CHANNEL_RC_OK;
+ UINT error = CHANNEL_RC_OK;
SetEvent(context->priv->StopEvent);
if (WaitForSingleObject(context->priv->Thread, INFINITE) == WAIT_FAILED)
- {
- error = GetLastError();
- WLog_ERR(TAG, "WaitForSingleObject failed with error %lu", error);
- return error;
- }
- CloseHandle(context->priv->Thread);
+ {
+ error = GetLastError();
+ WLog_ERR(TAG, "WaitForSingleObject failed with error %lu", error);
+ return error;
+ }
+ CloseHandle(context->priv->Thread);
return error;
}
EncomspServerContext* encomsp_server_context_new(HANDLE vcm)
{
EncomspServerContext* context;
-
context = (EncomspServerContext*) calloc(1, sizeof(EncomspServerContext));
if (context)
{
context->vcm = vcm;
-
context->Start = encomsp_server_start;
context->Stop = encomsp_server_stop;
-
context->priv = (EncomspServerPrivate*) calloc(1, sizeof(EncomspServerPrivate));
if (!context->priv)
char* path = NULL;
int status;
UINT32 PathLength;
-
Stream_Seek(irp->input, 28);
/* DesiredAccess(4) AllocationSize(8), FileAttributes(4) */
/* SharedAccess(4) CreateDisposition(4), CreateOptions(4) */
Stream_Read_UINT32(irp->input, PathLength);
-
status = ConvertFromUnicode(CP_UTF8, 0, (WCHAR*) Stream_Pointer(irp->input),
- PathLength / 2, &path, 0, NULL, NULL);
+ PathLength / 2, &path, 0, NULL, NULL);
if (status < 1)
if (!(path = (char*) calloc(1, 1)))
/* all read and write operations should be non-blocking */
if (fcntl(parallel->file, F_SETFL, O_NONBLOCK) == -1)
{
-
}
}
Stream_Write_UINT32(irp->output, parallel->id);
Stream_Write_UINT8(irp->output, 0);
-
free(path);
-
return irp->Complete(irp);
}
{
if (close(parallel->file) < 0)
{
-
}
else
{
-
}
Stream_Zero(irp->output, 5); /* Padding(5) */
-
return irp->Complete(irp);
}
UINT64 Offset;
ssize_t status;
BYTE* buffer = NULL;
-
Stream_Read_UINT32(irp->input, Length);
Stream_Read_UINT64(irp->input, Offset);
-
buffer = (BYTE*) malloc(Length);
+
if (!buffer)
{
WLog_ERR(TAG, "malloc failed!");
}
else
{
-
}
Stream_Write_UINT32(irp->output, Length);
free(buffer);
return CHANNEL_RC_NO_MEMORY;
}
+
Stream_Write(irp->output, buffer, Length);
}
free(buffer);
-
return irp->Complete(irp);
}
UINT32 Length;
UINT64 Offset;
ssize_t status;
-
Stream_Read_UINT32(irp->input, Length);
Stream_Read_UINT64(irp->input, Offset);
Stream_Seek(irp->input, 20); /* Padding */
-
len = Length;
while (len > 0)
Stream_Write_UINT32(irp->output, Length);
Stream_Write_UINT8(irp->output, 0); /* Padding */
-
return irp->Complete(irp);
}
*
* @return 0 on success, otherwise a Win32 error code
*/
-static UINT parallel_process_irp_device_control(PARALLEL_DEVICE* parallel, IRP* irp)
+static UINT parallel_process_irp_device_control(PARALLEL_DEVICE* parallel,
+ IRP* irp)
{
Stream_Write_UINT32(irp->output, 0); /* OutputBufferLength */
return irp->Complete(irp);
WLog_ERR(TAG, "parallel_process_irp_create failed with error %d!", error);
return error;
}
+
break;
case IRP_MJ_CLOSE:
WLog_ERR(TAG, "parallel_process_irp_close failed with error %d!", error);
return error;
}
+
break;
case IRP_MJ_READ:
WLog_ERR(TAG, "parallel_process_irp_read failed with error %d!", error);
return error;
}
+
break;
case IRP_MJ_WRITE:
WLog_ERR(TAG, "parallel_process_irp_write failed with error %d!", error);
return error;
}
+
break;
case IRP_MJ_DEVICE_CONTROL:
if ((error = parallel_process_irp_device_control(parallel, irp)))
{
- WLog_ERR(TAG, "parallel_process_irp_device_control failed with error %d!", error);
+ WLog_ERR(TAG, "parallel_process_irp_device_control failed with error %d!",
+ error);
return error;
}
+
break;
default:
return irp->Complete(irp);
break;
}
+
return CHANNEL_RC_OK;
}
wMessage message;
PARALLEL_DEVICE* parallel = (PARALLEL_DEVICE*) arg;
UINT error = CHANNEL_RC_OK;
-
freerdp_channel_init_thread_context(parallel->rdpcontext);
+
while (1)
{
if (!MessageQueue_Wait(parallel->queue))
break;
}
}
+
if (error && parallel->rdpcontext)
- setChannelError(parallel->rdpcontext, error, "parallel_thread_func reported an error");
+ setChannelError(parallel->rdpcontext, error,
+ "parallel_thread_func reported an error");
ExitThread((DWORD)error);
return NULL;
WLog_ERR(TAG, "MessageQueue_Post failed!");
return ERROR_INTERNAL_ERROR;
}
+
return CHANNEL_RC_OK;
}
*/
static UINT parallel_free(DEVICE* device)
{
- UINT error;
+ UINT error;
PARALLEL_DEVICE* parallel = (PARALLEL_DEVICE*) device;
- if (MessageQueue_PostQuit(parallel->queue, 0) && (WaitForSingleObject(parallel->thread, INFINITE) == WAIT_FAILED))
- {
- error = GetLastError();
- WLog_ERR(TAG, "WaitForSingleObject failed with error %lu!", error);
- return error;
- }
- CloseHandle(parallel->thread);
+ if (MessageQueue_PostQuit(parallel->queue, 0)
+ && (WaitForSingleObject(parallel->thread, INFINITE) == WAIT_FAILED))
+ {
+ error = GetLastError();
+ WLog_ERR(TAG, "WaitForSingleObject failed with error %lu!", error);
+ return error;
+ }
+ CloseHandle(parallel->thread);
Stream_Free(parallel->device.data, TRUE);
MessageQueue_Free(parallel->queue);
-
free(parallel);
- return CHANNEL_RC_OK;
+ return CHANNEL_RC_OK;
}
#ifdef BUILTIN_CHANNELS
RDPDR_PARALLEL* device;
PARALLEL_DEVICE* parallel;
UINT error;
-
device = (RDPDR_PARALLEL*) pEntryPoints->device;
name = device->Name;
path = device->Path;
if (name[0] && path[0])
{
parallel = (PARALLEL_DEVICE*) calloc(1, sizeof(PARALLEL_DEVICE));
+
if (!parallel)
{
WLog_ERR(TAG, "calloc failed!");
parallel->device.IRPRequest = parallel_irp_request;
parallel->device.Free = parallel_free;
parallel->rdpcontext = pEntryPoints->rdpcontext;
-
length = strlen(name);
parallel->device.data = Stream_New(NULL, length + 1);
+
if (!parallel->device.data)
{
WLog_ERR(TAG, "Stream_New failed!");
Stream_Write_UINT8(parallel->device.data, name[i] < 0 ? '_' : name[i]);
parallel->path = path;
-
parallel->queue = MessageQueue_New(NULL);
+
if (!parallel->queue)
{
WLog_ERR(TAG, "MessageQueue_New failed!");
goto error_out;
}
- if ((error = pEntryPoints->RegisterDevice(pEntryPoints->devman, (DEVICE*) parallel)))
+ if ((error = pEntryPoints->RegisterDevice(pEntryPoints->devman,
+ (DEVICE*) parallel)))
{
WLog_ERR(TAG, "RegisterDevice failed with error %lu!", error);
goto error_out;
}
-
- if (!(parallel->thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) parallel_thread_func, (void*) parallel, 0, NULL)))
+ if (!(parallel->thread = CreateThread(NULL, 0,
+ (LPTHREAD_START_ROUTINE) parallel_thread_func, (void*) parallel, 0, NULL)))
{
WLog_ERR(TAG, "CreateThread failed!");
error = ERROR_INTERNAL_ERROR;
else
{
status = rail->channelEntryPoints.pVirtualChannelWrite(rail->OpenHandle,
- Stream_Buffer(s), (UINT32) Stream_GetPosition(s), s);
+ Stream_Buffer(s), (UINT32) Stream_GetPosition(s), s);
}
if (status != CHANNEL_RC_OK)
{
Stream_Free(s, TRUE);
WLog_ERR(TAG, "VirtualChannelWrite failed with %s [%08X]",
- WTSErrorToString(status), status);
+ WTSErrorToString(status), status);
}
return status;
* @return 0 on success, otherwise a Win32 error code
*/
static UINT rail_client_execute(RailClientContext* context,
- RAIL_EXEC_ORDER* exec)
+ RAIL_EXEC_ORDER* exec)
{
char* exeOrFile;
railPlugin* rail = (railPlugin*) context->handle;
}
rail_string_to_unicode_string(exec->RemoteApplicationProgram,
- &exec->exeOrFile); /* RemoteApplicationProgram */
+ &exec->exeOrFile); /* RemoteApplicationProgram */
rail_string_to_unicode_string(exec->RemoteApplicationWorkingDir,
- &exec->workingDir); /* ShellWorkingDirectory */
+ &exec->workingDir); /* ShellWorkingDirectory */
rail_string_to_unicode_string(exec->RemoteApplicationArguments,
- &exec->arguments); /* RemoteApplicationCmdLine */
+ &exec->arguments); /* RemoteApplicationCmdLine */
return rail_send_client_exec_order(rail, exec);
}
* @return 0 on success, otherwise a Win32 error code
*/
static UINT rail_client_activate(RailClientContext* context,
- RAIL_ACTIVATE_ORDER* activate)
+ RAIL_ACTIVATE_ORDER* activate)
{
railPlugin* rail = (railPlugin*) context->handle;
return rail_send_client_activate_order(rail, activate);
* @return 0 on success, otherwise a Win32 error code
*/
static UINT rail_send_client_sysparam(RailClientContext* context,
- RAIL_SYSPARAM_ORDER* sysparam)
+ RAIL_SYSPARAM_ORDER* sysparam)
{
wStream* s;
int length;
* @return 0 on success, otherwise a Win32 error code
*/
static UINT rail_client_system_param(RailClientContext* context,
- RAIL_SYSPARAM_ORDER* sysparam)
+ RAIL_SYSPARAM_ORDER* sysparam)
{
UINT error = CHANNEL_RC_OK;
* @return 0 on success, otherwise a Win32 error code
*/
static UINT rail_server_system_param(RailClientContext* context,
- RAIL_SYSPARAM_ORDER* sysparam)
+ RAIL_SYSPARAM_ORDER* sysparam)
{
return CHANNEL_RC_OK; /* stub - should be registered by client */
}
* @return 0 on success, otherwise a Win32 error code
*/
static UINT rail_client_system_command(RailClientContext* context,
- RAIL_SYSCOMMAND_ORDER* syscommand)
+ RAIL_SYSCOMMAND_ORDER* syscommand)
{
railPlugin* rail = (railPlugin*) context->handle;
return rail_send_client_syscommand_order(rail, syscommand);
* @return 0 on success, otherwise a Win32 error code
*/
static UINT rail_client_handshake(RailClientContext* context,
- RAIL_HANDSHAKE_ORDER* handshake)
+ RAIL_HANDSHAKE_ORDER* handshake)
{
railPlugin* rail = (railPlugin*) context->handle;
return rail_send_handshake_order(rail, handshake);
* @return 0 on success, otherwise a Win32 error code
*/
static UINT rail_server_handshake(RailClientContext* context,
- RAIL_HANDSHAKE_ORDER* handshake)
+ RAIL_HANDSHAKE_ORDER* handshake)
{
return CHANNEL_RC_OK; /* stub - should be registered by client */
}
* @return 0 on success, otherwise a Win32 error code
*/
static UINT rail_client_handshake_ex(RailClientContext* context,
- RAIL_HANDSHAKE_EX_ORDER* handshakeEx)
+ RAIL_HANDSHAKE_EX_ORDER* handshakeEx)
{
railPlugin* rail = (railPlugin*) context->handle;
return rail_send_handshake_ex_order(rail, handshakeEx);
* @return 0 on success, otherwise a Win32 error code
*/
static UINT rail_server_handshake_ex(RailClientContext* context,
- RAIL_HANDSHAKE_EX_ORDER* handshakeEx)
+ RAIL_HANDSHAKE_EX_ORDER* handshakeEx)
{
return CHANNEL_RC_OK; /* stub - should be registered by client */
}
* @return 0 on success, otherwise a Win32 error code
*/
static UINT rail_client_notify_event(RailClientContext* context,
- RAIL_NOTIFY_EVENT_ORDER* notifyEvent)
+ RAIL_NOTIFY_EVENT_ORDER* notifyEvent)
{
railPlugin* rail = (railPlugin*) context->handle;
return rail_send_client_notify_event_order(rail, notifyEvent);
* @return 0 on success, otherwise a Win32 error code
*/
static UINT rail_client_window_move(RailClientContext* context,
- RAIL_WINDOW_MOVE_ORDER* windowMove)
+ RAIL_WINDOW_MOVE_ORDER* windowMove)
{
railPlugin* rail = (railPlugin*) context->handle;
return rail_send_client_window_move_order(rail, windowMove);
* @return 0 on success, otherwise a Win32 error code
*/
static UINT rail_server_local_move_size(RailClientContext* context,
- RAIL_LOCALMOVESIZE_ORDER* localMoveSize)
+ RAIL_LOCALMOVESIZE_ORDER* localMoveSize)
{
return CHANNEL_RC_OK; /* stub - should be registered by client */
}
* @return 0 on success, otherwise a Win32 error code
*/
static UINT rail_server_min_max_info(RailClientContext* context,
- RAIL_MINMAXINFO_ORDER* minMaxInfo)
+ RAIL_MINMAXINFO_ORDER* minMaxInfo)
{
return CHANNEL_RC_OK; /* stub - should be registered by client */
}
* @return 0 on success, otherwise a Win32 error code
*/
static UINT rail_client_information(RailClientContext* context,
- RAIL_CLIENT_STATUS_ORDER* clientStatus)
+ RAIL_CLIENT_STATUS_ORDER* clientStatus)
{
railPlugin* rail = (railPlugin*) context->handle;
return rail_send_client_status_order(rail, clientStatus);
* @return 0 on success, otherwise a Win32 error code
*/
static UINT rail_client_system_menu(RailClientContext* context,
- RAIL_SYSMENU_ORDER* sysmenu)
+ RAIL_SYSMENU_ORDER* sysmenu)
{
railPlugin* rail = (railPlugin*) context->handle;
return rail_send_client_sysmenu_order(rail, sysmenu);
* @return 0 on success, otherwise a Win32 error code
*/
static UINT rail_client_language_bar_info(RailClientContext* context,
- RAIL_LANGBAR_INFO_ORDER* langBarInfo)
+ RAIL_LANGBAR_INFO_ORDER* langBarInfo)
{
railPlugin* rail = (railPlugin*) context->handle;
return rail_send_client_langbar_info_order(rail, langBarInfo);
* @return 0 on success, otherwise a Win32 error code
*/
static UINT rail_server_language_bar_info(RailClientContext* context,
- RAIL_LANGBAR_INFO_ORDER* langBarInfo)
+ RAIL_LANGBAR_INFO_ORDER* langBarInfo)
{
return CHANNEL_RC_OK; /* stub - should be registered by client */
}
* @return 0 on success, otherwise a Win32 error code
*/
static UINT rail_server_execute_result(RailClientContext* context,
- RAIL_EXEC_RESULT_ORDER* execResult)
+ RAIL_EXEC_RESULT_ORDER* execResult)
{
return CHANNEL_RC_OK; /* stub - should be registered by client */
}
* @return 0 on success, otherwise a Win32 error code
*/
static UINT rail_client_get_appid_request(RailClientContext* context,
- RAIL_GET_APPID_REQ_ORDER* getAppIdReq)
+ RAIL_GET_APPID_REQ_ORDER* getAppIdReq)
{
railPlugin* rail = (railPlugin*) context->handle;
return rail_send_client_get_appid_req_order(rail, getAppIdReq);
* @return 0 on success, otherwise a Win32 error code
*/
static UINT rail_server_get_appid_response(RailClientContext* context,
- RAIL_GET_APPID_RESP_ORDER* getAppIdResp)
+ RAIL_GET_APPID_RESP_ORDER* getAppIdResp)
{
return CHANNEL_RC_OK; /* stub - should be registered by client */
}
* @return 0 on success, otherwise a Win32 error code
*/
static UINT rail_virtual_channel_event_data_received(railPlugin* rail,
- void* pData, UINT32 dataLength, UINT32 totalLength, UINT32 dataFlags)
+ void* pData, UINT32 dataLength, UINT32 totalLength, UINT32 dataFlags)
{
wStream* data_in;
}
static VOID VCAPITYPE rail_virtual_channel_open_event(DWORD openHandle,
- UINT event,
- LPVOID pData, UINT32 dataLength, UINT32 totalLength, UINT32 dataFlags)
+ UINT event,
+ LPVOID pData, UINT32 dataLength, UINT32 totalLength, UINT32 dataFlags)
{
railPlugin* rail = s_TLSPluginContext;
UINT error = CHANNEL_RC_OK;
{
case CHANNEL_EVENT_DATA_RECEIVED:
if ((error = rail_virtual_channel_event_data_received(rail, pData, dataLength,
- totalLength, dataFlags)))
+ totalLength, dataFlags)))
WLog_ERR(TAG, "rail_virtual_channel_event_data_received failed with error %lu!",
- error);
+ error);
break;
if (error && rail->rdpcontext)
setChannelError(rail->rdpcontext, error,
- "rail_virtual_channel_open_event reported an error");
+ "rail_virtual_channel_open_event reported an error");
return;
}
wMessage message;
railPlugin* rail = (railPlugin*) arg;
UINT error = CHANNEL_RC_OK;
-
freerdp_channel_init_thread_context(rail->rdpcontext);
+
while (1)
{
if (!MessageQueue_Wait(rail->queue))
if (error && rail->rdpcontext)
setChannelError(rail->rdpcontext, error,
- "rail_virtual_channel_client_thread reported an error");
+ "rail_virtual_channel_client_thread reported an error");
ExitThread((DWORD)error);
return NULL;
* @return 0 on success, otherwise a Win32 error code
*/
static UINT rail_virtual_channel_event_connected(railPlugin* rail, LPVOID pData,
- UINT32 dataLength)
+ UINT32 dataLength)
{
UINT status;
status = rail->channelEntryPoints.pVirtualChannelOpen(rail->InitHandle,
- &rail->OpenHandle, rail->channelDef.name, rail_virtual_channel_open_event);
+ &rail->OpenHandle, rail->channelDef.name, rail_virtual_channel_open_event);
if (status != CHANNEL_RC_OK)
{
WLog_ERR(TAG, "pVirtualChannelOpen failed with %s [%08X]",
- WTSErrorToString(status), status);
+ WTSErrorToString(status), status);
return status;
}
}
if (!(rail->thread = CreateThread(NULL, 0,
- (LPTHREAD_START_ROUTINE) rail_virtual_channel_client_thread, (void*) rail, 0,
- NULL)))
+ (LPTHREAD_START_ROUTINE) rail_virtual_channel_client_thread, (void*) rail, 0,
+ NULL)))
{
WLog_ERR(TAG, "CreateThread failed!");
MessageQueue_Free(rail->queue);
if (CHANNEL_RC_OK != rc)
{
WLog_ERR(TAG, "pVirtualChannelClose failed with %s [%08X]",
- WTSErrorToString(rc), rc);
+ WTSErrorToString(rc), rc);
return rc;
}
}
static VOID VCAPITYPE rail_virtual_channel_init_event(LPVOID pInitHandle,
- UINT event, LPVOID pData, UINT dataLength)
+ UINT event, LPVOID pData, UINT dataLength)
{
railPlugin* rail = s_TLSPluginContext;
UINT error = CHANNEL_RC_OK;
case CHANNEL_EVENT_CONNECTED:
if ((error = rail_virtual_channel_event_connected(rail, pData, dataLength)))
WLog_ERR(TAG, "rail_virtual_channel_event_connected failed with error %lu!",
- error);
+ error);
break;
case CHANNEL_EVENT_DISCONNECTED:
if ((error = rail_virtual_channel_event_disconnected(rail)))
WLog_ERR(TAG, "rail_virtual_channel_event_disconnected failed with error %lu!",
- error);
+ error);
break;
if (error && rail->rdpcontext)
setChannelError(rail->rdpcontext, error,
- "rail_virtual_channel_init_event reported an error");
+ "rail_virtual_channel_init_event reported an error");
}
/* rail is always built-in */
rail->log = WLog_Get("com.freerdp.channels.rail.client");
WLog_Print(rail->log, WLOG_DEBUG, "VirtualChannelEntry");
CopyMemory(&(rail->channelEntryPoints), pEntryPoints,
- sizeof(CHANNEL_ENTRY_POINTS_FREERDP));
+ sizeof(CHANNEL_ENTRY_POINTS_FREERDP));
rc = rail->channelEntryPoints.pVirtualChannelInit(&rail->InitHandle,
- &rail->channelDef, 1, VIRTUAL_CHANNEL_VERSION_WIN2000,
- rail_virtual_channel_init_event);
+ &rail->channelDef, 1, VIRTUAL_CHANNEL_VERSION_WIN2000,
+ rail_virtual_channel_init_event);
if (CHANNEL_RC_OK != rc)
{
WLog_ERR(TAG, "pVirtualChannelInit failed with %s [%08X]",
- WTSErrorToString(rc), rc);
+ WTSErrorToString(rc), rc);
goto error_out;
}
* @return 0 on success, otherwise a Win32 error code
*/
static UINT rdpdr_send_device_list_announce_request(rdpdrPlugin* rdpdr,
- BOOL userLoggedOn);
+ BOOL userLoggedOn);
/**
* Function description
* @return 0 on success, otherwise a Win32 error code
*/
static UINT rdpdr_send_device_list_remove_request(rdpdrPlugin* rdpdr,
- UINT32 count, UINT32 ids[])
+ UINT32 count, UINT32 ids[])
{
UINT32 i;
wStream* s;
drive_path[1] = '\0';
drive->Name = _strdup(drive_path);
devman_load_device_service(rdpdr->devman, (RDPDR_DEVICE*)drive,
- rdpdr->rdpcontext);
+ rdpdr->rdpcontext);
}
}
drive_path[1] = '\0';
drive->Name = _strdup(drive_path);
devman_load_device_service(rdpdr->devman, (RDPDR_DEVICE*)drive,
- rdpdr->rdpcontext);
+ rdpdr->rdpcontext);
rdpdr_send_device_list_announce_request(rdpdr, TRUE);
}
}
for (j = 0; j < count; j++)
{
device_ext = (DEVICE_DRIVE_EXT*)ListDictionary_GetItemValue(
- rdpdr->devman->devices, (void*)keys[j]);
+ rdpdr->devman->devices, (void*)keys[j]);
if (device_ext->path[0] == drive_name_upper
|| device_ext->path[0] == drive_name_lower)
{
// dont end on error, just report ?
WLog_ERR(TAG, "rdpdr_send_device_list_remove_request failed with error %lu!",
- error);
+ error);
}
break;
RegisterClassEx(&wnd_cls);
/* create window */
hwnd = CreateWindowEx(0, L"DRIVE_HOTPLUG", NULL,
- 0, 0, 0, 0, 0,
- NULL, NULL, NULL, NULL);
+ 0, 0, 0, 0, 0,
+ NULL, NULL, NULL, NULL);
SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)rdpdr);
rdpdr->hotplug_wnd = hwnd;
/* register device interface to hwnd */
NotificationFilter.dbch_size = sizeof(DEV_BROADCAST_HANDLE);
NotificationFilter.dbch_devicetype = DBT_DEVTYP_HANDLE;
hDevNotify = RegisterDeviceNotification(hwnd, &NotificationFilter,
- DEVICE_NOTIFY_WINDOW_HANDLE);
+ DEVICE_NOTIFY_WINDOW_HANDLE);
/* message loop */
while ((bRet = GetMessage(&msg, 0, 0, 0)) != 0)
{
BOOL dev_found = FALSE;
device_ext = (DEVICE_DRIVE_EXT*)ListDictionary_GetItemValue(
- rdpdr->devman->devices, (void*)keys[j]);
+ rdpdr->devman->devices, (void*)keys[j]);
if (!device_ext)
continue;
if ((error = rdpdr_send_device_list_remove_request(rdpdr, 1, ids)))
{
WLog_ERR(TAG, "rdpdr_send_device_list_remove_request failed with error %lu!",
- error);
+ error);
goto cleanup;
}
}
}
if ((error = devman_load_device_service(rdpdr->devman, (RDPDR_DEVICE*)drive,
- rdpdr->rdpcontext)))
+ rdpdr->rdpcontext)))
{
WLog_ERR(TAG, "devman_load_device_service failed!");
free(drive->Path);
static void drive_hotplug_fsevent_callback(ConstFSEventStreamRef streamRef,
- void* clientCallBackInfo,
- size_t numEvents, void* eventPaths, const FSEventStreamEventFlags eventFlags[],
- const FSEventStreamEventId eventIds[])
+ void* clientCallBackInfo,
+ size_t numEvents, void* eventPaths, const FSEventStreamEventFlags eventFlags[],
+ const FSEventStreamEventId eventIds[])
{
rdpdrPlugin* rdpdr;
int i;
rdpdr = (rdpdrPlugin*) arg;
CFStringRef path = CFSTR("/Volumes/");
CFArrayRef pathsToWatch = CFArrayCreate(kCFAllocatorMalloc, (const void**)&path,
- 1, NULL);
+ 1, NULL);
FSEventStreamContext ctx;
ZeroMemory(&ctx, sizeof(ctx));
ctx.info = arg;
fsev = FSEventStreamCreate(kCFAllocatorMalloc, drive_hotplug_fsevent_callback,
- &ctx, pathsToWatch, kFSEventStreamEventIdSinceNow, 1,
- kFSEventStreamCreateFlagNone);
+ &ctx, pathsToWatch, kFSEventStreamEventIdSinceNow, 1,
+ kFSEventStreamCreateFlagNone);
rdpdr->runLoop = CFRunLoopGetCurrent();
FSEventStreamScheduleWithRunLoop(fsev, rdpdr->runLoop, kCFRunLoopDefaultMode);
FSEventStreamStart(fsev);
{
BOOL dev_found = FALSE;
device_ext = (DEVICE_DRIVE_EXT*)ListDictionary_GetItemValue(
- rdpdr->devman->devices, (void*)keys[j]);
+ rdpdr->devman->devices, (void*)keys[j]);
if (!device_ext || !device_ext->path)
continue;
if ((error = rdpdr_send_device_list_remove_request(rdpdr, 1, ids)))
{
WLog_ERR(TAG, "rdpdr_send_device_list_remove_request failed with error %lu!",
- error);
+ error);
goto cleanup;
}
}
}
if ((error = devman_load_device_service(rdpdr->devman, (RDPDR_DEVICE*)drive,
- rdpdr->rdpcontext)))
+ rdpdr->rdpcontext)))
{
WLog_ERR(TAG, "devman_load_device_service failed!");
free(drive->Path);
UINT error = 0;
DWORD status;
rdpdr = (rdpdrPlugin*) arg;
-
freerdp_channel_init_thread_context(rdpdr->rdpcontext);
+
if (!(rdpdr->stopEvent = CreateEvent(NULL, TRUE, FALSE, NULL)))
{
WLog_ERR(TAG, "CreateEvent failed!");
if (error && rdpdr->rdpcontext)
setChannelError(rdpdr->rdpcontext, error,
- "drive_hotplug_thread_func reported an error");
+ "drive_hotplug_thread_func reported an error");
CloseHandle(rdpdr->stopEvent);
ExitThread((DWORD)error);
if (settings->ClientHostname)
strncpy(rdpdr->computerName, settings->ClientHostname,
- sizeof(rdpdr->computerName) - 1);
+ sizeof(rdpdr->computerName) - 1);
else
strncpy(rdpdr->computerName, settings->ComputerName,
- sizeof(rdpdr->computerName) - 1);
+ sizeof(rdpdr->computerName) - 1);
for (index = 0; index < settings->DeviceCount; index++)
{
first_hotplug(rdpdr);
if (!(rdpdr->hotplugThread = CreateThread(NULL, 0,
- (LPTHREAD_START_ROUTINE) drive_hotplug_thread_func, rdpdr, 0, NULL)))
+ (LPTHREAD_START_ROUTINE) drive_hotplug_thread_func, rdpdr, 0, NULL)))
{
WLog_ERR(TAG, "CreateThread failed!");
return ERROR_INTERNAL_ERROR;
}
if ((error = devman_load_device_service(rdpdr->devman, device,
- rdpdr->rdpcontext)))
+ rdpdr->rdpcontext)))
{
WLog_ERR(TAG, "devman_load_device_service failed with error %lu!", error);
return error;
}
static UINT rdpdr_process_server_announce_request(rdpdrPlugin* rdpdr,
- wStream* s)
+ wStream* s)
{
if (Stream_GetRemainingLength(s) < 8)
return ERROR_INVALID_DATA;
gethostname(rdpdr->computerName, sizeof(rdpdr->computerName) - 1);
computerNameLenW = ConvertToUnicode(CP_UTF8, 0, rdpdr->computerName, -1,
- &computerNameW, 0) * 2;
+ &computerNameW, 0) * 2;
s = Stream_New(NULL, 16 + computerNameLenW + 2);
if (!s)
Stream_Write_UINT32(s, 1); /* unicodeFlag, 0 for ASCII and 1 for Unicode */
Stream_Write_UINT32(s, 0); /* codePage, must be set to zero */
Stream_Write_UINT32(s, computerNameLenW +
- 2); /* computerNameLen, including null terminator */
+ 2); /* computerNameLen, including null terminator */
Stream_Write(s, computerNameW, computerNameLenW);
Stream_Write_UINT16(s, 0); /* null terminator */
free(computerNameW);
}
static UINT rdpdr_process_server_clientid_confirm(rdpdrPlugin* rdpdr,
- wStream* s)
+ wStream* s)
{
UINT16 versionMajor;
UINT16 versionMinor;
* @return 0 on success, otherwise a Win32 error code
*/
static UINT rdpdr_send_device_list_announce_request(rdpdrPlugin* rdpdr,
- BOOL userLoggedOn)
+ BOOL userLoggedOn)
{
int i;
BYTE c;
for (index = 0; index < keyCount; index++)
{
device = (DEVICE*) ListDictionary_GetItemValue(rdpdr->devman->devices,
- (void*) pKeys[index]);
+ (void*) pKeys[index]);
/**
* 1. versionMinor 0x0005 doesn't send PAKID_CORE_USER_LOGGEDON
count++;
WLog_INFO(TAG, "registered device #%d: %s (type=%d id=%d)",
- count, device->name, device->type, device->id);
+ count, device->name, device->type, device->id);
}
}
for (index = 0; index < keyCount; index++)
{
device = (DEVICE*) ListDictionary_GetItemValue(rdpdr->devman->devices,
- (void*) pKeys[index]);
+ (void*) pKeys[index]);
IFCALLRET(device->Init, error, device);
if (error != CHANNEL_RC_OK)
if ((error = rdpdr_send_device_list_announce_request(rdpdr, FALSE)))
{
WLog_ERR(TAG, "rdpdr_send_device_list_announce_request failed with error %lu",
- error);
+ error);
return error;
}
if ((error = rdpdr_send_device_list_announce_request(rdpdr, TRUE)))
{
WLog_ERR(TAG, "rdpdr_send_device_list_announce_request failed with error %lu",
- error);
+ error);
return error;
}
Stream_Read_UINT32(s, eventID);
WLog_ERR(TAG,
- "Ignoring unhandled message PAKID_PRN_CACHE_DATA (EventID: 0x%04X)", eventID);
+ "Ignoring unhandled message PAKID_PRN_CACHE_DATA (EventID: 0x%04X)", eventID);
}
break;
else
{
WLog_ERR(TAG, "Unknown message: Component: 0x%04X PacketId: 0x%04X", component,
- packetId);
+ packetId);
return ERROR_INVALID_DATA;
}
else
{
status = plugin->channelEntryPoints.pVirtualChannelWrite(plugin->OpenHandle,
- Stream_Buffer(s), (UINT32) Stream_GetPosition(s), s);
+ Stream_Buffer(s), (UINT32) Stream_GetPosition(s), s);
}
if (status != CHANNEL_RC_OK)
{
Stream_Free(s, TRUE);
WLog_ERR(TAG, "VirtualChannelWrite failed with %s [%08X]",
- WTSErrorToString(status), status);
+ WTSErrorToString(status), status);
}
return status;
* @return 0 on success, otherwise a Win32 error code
*/
static UINT rdpdr_virtual_channel_event_data_received(rdpdrPlugin* rdpdr,
- void* pData, UINT32 dataLength, UINT32 totalLength, UINT32 dataFlags)
+ void* pData, UINT32 dataLength, UINT32 totalLength, UINT32 dataFlags)
{
wStream* data_in;
}
static VOID VCAPITYPE rdpdr_virtual_channel_open_event(DWORD openHandle,
- UINT event,
- LPVOID pData, UINT32 dataLength, UINT32 totalLength, UINT32 dataFlags)
+ UINT event,
+ LPVOID pData, UINT32 dataLength, UINT32 totalLength, UINT32 dataFlags)
{
rdpdrPlugin* rdpdr = s_TLSPluginContext;
UINT error = CHANNEL_RC_OK;
{
case CHANNEL_EVENT_DATA_RECEIVED:
if ((error = rdpdr_virtual_channel_event_data_received(rdpdr, pData,
- dataLength, totalLength, dataFlags)))
+ dataLength, totalLength, dataFlags)))
WLog_ERR(TAG,
- "rdpdr_virtual_channel_event_data_received failed with error %lu!", error);
+ "rdpdr_virtual_channel_event_data_received failed with error %lu!", error);
break;
if (error && rdpdr->rdpcontext)
setChannelError(rdpdr->rdpcontext, error,
- "rdpdr_virtual_channel_open_event reported an error");
+ "rdpdr_virtual_channel_open_event reported an error");
return;
}
freerdp_channel_init_thread_context(rdpdr->rdpcontext);
s_TLSPluginContext = rdpdr;
+
if ((error = rdpdr_process_connect(rdpdr)))
{
WLog_ERR(TAG, "rdpdr_process_connect failed with error %lu!", error);
if (rdpdr->rdpcontext)
setChannelError(rdpdr->rdpcontext, error,
- "rdpdr_virtual_channel_client_thread reported an error");
+ "rdpdr_virtual_channel_client_thread reported an error");
ExitThread((DWORD) error);
return NULL;
if (rdpdr->rdpcontext)
setChannelError(rdpdr->rdpcontext, error,
- "rdpdr_virtual_channel_client_thread reported an error");
+ "rdpdr_virtual_channel_client_thread reported an error");
ExitThread((DWORD) error);
return NULL;
* @return 0 on success, otherwise a Win32 error code
*/
static UINT rdpdr_virtual_channel_event_connected(rdpdrPlugin* rdpdr,
- LPVOID pData, UINT32 dataLength)
+ LPVOID pData, UINT32 dataLength)
{
UINT32 status;
status = rdpdr->channelEntryPoints.pVirtualChannelOpen(rdpdr->InitHandle,
- &rdpdr->OpenHandle, rdpdr->channelDef.name, rdpdr_virtual_channel_open_event);
+ &rdpdr->OpenHandle, rdpdr->channelDef.name, rdpdr_virtual_channel_open_event);
if (status != CHANNEL_RC_OK)
{
WLog_ERR(TAG, "pVirtualChannelOpen failed with %s [%08X]",
- WTSErrorToString(status), status);
+ WTSErrorToString(status), status);
return status;
}
}
if (!(rdpdr->thread = CreateThread(NULL, 0,
- (LPTHREAD_START_ROUTINE) rdpdr_virtual_channel_client_thread, (void*) rdpdr, 0,
- NULL)))
+ (LPTHREAD_START_ROUTINE) rdpdr_virtual_channel_client_thread, (void*) rdpdr, 0,
+ NULL)))
{
WLog_ERR(TAG, "CreateThread failed!");
return ERROR_INTERNAL_ERROR;
if (CHANNEL_RC_OK != error)
{
WLog_ERR(TAG, "pVirtualChannelClose failed with %s [%08X]",
- WTSErrorToString(error), error);
+ WTSErrorToString(error), error);
}
rdpdr->OpenHandle = 0;
}
static VOID VCAPITYPE rdpdr_virtual_channel_init_event(LPVOID pInitHandle,
- UINT event,
- LPVOID pData, UINT dataLength)
+ UINT event,
+ LPVOID pData, UINT dataLength)
{
rdpdrPlugin* rdpdr = s_TLSPluginContext;
UINT error = CHANNEL_RC_OK;
case CHANNEL_EVENT_CONNECTED:
if ((error = rdpdr_virtual_channel_event_connected(rdpdr, pData, dataLength)))
WLog_ERR(TAG, "rdpdr_virtual_channel_event_connected failed with error %lu!",
- error);
+ error);
break;
case CHANNEL_EVENT_DISCONNECTED:
if ((error = rdpdr_virtual_channel_event_disconnected(rdpdr)))
WLog_ERR(TAG, "rdpdr_virtual_channel_event_disconnected failed with error %lu!",
- error);
+ error);
break;
if (error && rdpdr->rdpcontext)
setChannelError(rdpdr->rdpcontext, error,
- "rdpdr_virtual_channel_init_event reported an error");
+ "rdpdr_virtual_channel_init_event reported an error");
}
/* rdpdr is always built-in */
}
CopyMemory(&(rdpdr->channelEntryPoints), pEntryPoints,
- sizeof(CHANNEL_ENTRY_POINTS_FREERDP));
+ sizeof(CHANNEL_ENTRY_POINTS_FREERDP));
rc = rdpdr->channelEntryPoints.pVirtualChannelInit(&rdpdr->InitHandle,
- &rdpdr->channelDef, 1, VIRTUAL_CHANNEL_VERSION_WIN2000,
- rdpdr_virtual_channel_init_event);
+ &rdpdr->channelDef, 1, VIRTUAL_CHANNEL_VERSION_WIN2000,
+ rdpdr_virtual_channel_init_event);
if (CHANNEL_RC_OK != rc)
{
WLog_ERR(TAG, "pVirtualChannelInit failed with %s [%08X]",
- WTSErrorToString(rc), rc);
+ WTSErrorToString(rc), rc);
free(rdpdr);
return FALSE;
}
static RDPDR_IRP* rdpdr_server_irp_new()
{
RDPDR_IRP* irp;
-
irp = (RDPDR_IRP*) calloc(1, sizeof(RDPDR_IRP));
-
return irp;
}
free(irp);
}
-static BOOL rdpdr_server_enqueue_irp(RdpdrServerContext* context, RDPDR_IRP* irp)
+static BOOL rdpdr_server_enqueue_irp(RdpdrServerContext* context,
+ RDPDR_IRP* irp)
{
- return ListDictionary_Add(context->priv->IrpList, (void*) (size_t) irp->CompletionId, irp);
+ return ListDictionary_Add(context->priv->IrpList,
+ (void*)(size_t) irp->CompletionId, irp);
}
-static RDPDR_IRP* rdpdr_server_dequeue_irp(RdpdrServerContext* context, UINT32 completionId)
+static RDPDR_IRP* rdpdr_server_dequeue_irp(RdpdrServerContext* context,
+ UINT32 completionId)
{
RDPDR_IRP* irp;
-
- irp = (RDPDR_IRP*) ListDictionary_Remove(context->priv->IrpList, (void*) (size_t) completionId);
-
+ irp = (RDPDR_IRP*) ListDictionary_Remove(context->priv->IrpList,
+ (void*)(size_t) completionId);
return irp;
}
BOOL status;
RDPDR_HEADER header;
ULONG written;
-
WLog_DBG(TAG, "RdpdrServerSendAnnounceRequest");
-
header.Component = RDPDR_CTYP_CORE;
header.PacketId = PAKID_CORE_SERVER_ANNOUNCE;
-
s = Stream_New(NULL, RDPDR_HEADER_LENGTH + 8);
+
if (!s)
{
WLog_ERR(TAG, "Stream_New failed!");
return CHANNEL_RC_NO_MEMORY;
}
+
Stream_Write_UINT16(s, header.Component); /* Component (2 bytes) */
Stream_Write_UINT16(s, header.PacketId); /* PacketId (2 bytes) */
- Stream_Write_UINT16(s, context->priv->VersionMajor); /* VersionMajor (2 bytes) */
- Stream_Write_UINT16(s, context->priv->VersionMinor); /* VersionMinor (2 bytes) */
+ Stream_Write_UINT16(s,
+ context->priv->VersionMajor); /* VersionMajor (2 bytes) */
+ Stream_Write_UINT16(s,
+ context->priv->VersionMinor); /* VersionMinor (2 bytes) */
Stream_Write_UINT32(s, context->priv->ClientId); /* ClientId (4 bytes) */
-
Stream_SealLength(s);
-
winpr_HexDump(TAG, WLOG_DEBUG, Stream_Buffer(s), Stream_Length(s));
-
- status = WTSVirtualChannelWrite(context->priv->ChannelHandle, (PCHAR) Stream_Buffer(s), Stream_Length(s), &written);
-
+ status = WTSVirtualChannelWrite(context->priv->ChannelHandle,
+ (PCHAR) Stream_Buffer(s), Stream_Length(s), &written);
Stream_Free(s, TRUE);
return status ? CHANNEL_RC_OK : ERROR_INTERNAL_ERROR;
}
*
* @return 0 on success, otherwise a Win32 error code
*/
-static UINT rdpdr_server_receive_announce_response(RdpdrServerContext* context, wStream* s, RDPDR_HEADER* header)
+static UINT rdpdr_server_receive_announce_response(RdpdrServerContext* context,
+ wStream* s, RDPDR_HEADER* header)
{
UINT32 ClientId;
UINT16 VersionMajor;
Stream_Read_UINT16(s, VersionMajor); /* VersionMajor (2 bytes) */
Stream_Read_UINT16(s, VersionMinor); /* VersionMinor (2 bytes) */
Stream_Read_UINT32(s, ClientId); /* ClientId (4 bytes) */
-
- WLog_DBG(TAG, "Client Announce Response: VersionMajor: 0x%04X VersionMinor: 0x%04X ClientId: 0x%04X",
- VersionMajor, VersionMinor, ClientId);
-
+ WLog_DBG(TAG,
+ "Client Announce Response: VersionMajor: 0x%04X VersionMinor: 0x%04X ClientId: 0x%04X",
+ VersionMajor, VersionMinor, ClientId);
context->priv->ClientId = ClientId;
return CHANNEL_RC_OK;
}
*
* @return 0 on success, otherwise a Win32 error code
*/
-static UINT rdpdr_server_receive_client_name_request(RdpdrServerContext* context, wStream* s, RDPDR_HEADER* header)
+static UINT rdpdr_server_receive_client_name_request(RdpdrServerContext*
+ context, wStream* s, RDPDR_HEADER* header)
{
UINT32 UnicodeFlag;
UINT32 ComputerNameLen;
return ERROR_INVALID_DATA;
}
-
Stream_Read_UINT32(s, UnicodeFlag); /* UnicodeFlag (4 bytes) */
Stream_Seek_UINT32(s); /* CodePage (4 bytes), MUST be set to zero */
Stream_Read_UINT32(s, ComputerNameLen); /* ComputerNameLen (4 bytes) */
-
if (UnicodeFlag > 1) /* must be 0x00000000 or 0x00000001 */
{
WLog_ERR(TAG, "invalid UnicodeFlag value: 0x%08X", UnicodeFlag);
return ERROR_INVALID_DATA;
}
-
/**
* Caution: ComputerNameLen is given *bytes*,
* not in characters, including the NULL terminator!
/* ComputerName must be null terminated, check if it really is */
- if (Stream_Pointer(s)[ComputerNameLen-1] ||
- (UnicodeFlag && Stream_Pointer(s)[ComputerNameLen-2]))
+ if (Stream_Pointer(s)[ComputerNameLen - 1] ||
+ (UnicodeFlag && Stream_Pointer(s)[ComputerNameLen - 2]))
{
WLog_ERR(TAG, "computer name must be null terminated");
return ERROR_INVALID_DATA;
}
-
if (context->priv->ClientComputerName)
{
free(context->priv->ClientComputerName);
if (UnicodeFlag)
{
if (ConvertFromUnicode(CP_UTF8, 0, (WCHAR*) Stream_Pointer(s), -1,
- &(context->priv->ClientComputerName), 0, NULL, NULL) < 1)
+ &(context->priv->ClientComputerName), 0, NULL, NULL) < 1)
{
WLog_ERR(TAG, "failed to convert client computer name");
return ERROR_INVALID_DATA;
else
{
context->priv->ClientComputerName = _strdup((char*) Stream_Pointer(s));
+
if (!context->priv->ClientComputerName)
{
WLog_ERR(TAG, "failed to duplicate client computer name");
}
Stream_Seek(s, ComputerNameLen);
-
WLog_DBG(TAG, "ClientComputerName: %s", context->priv->ClientComputerName);
return CHANNEL_RC_OK;
}
*
* @return 0 on success, otherwise a Win32 error code
*/
-static UINT rdpdr_server_read_capability_set_header(wStream* s, RDPDR_CAPABILITY_HEADER* header)
+static UINT rdpdr_server_read_capability_set_header(wStream* s,
+ RDPDR_CAPABILITY_HEADER* header)
{
if (Stream_GetRemainingLength(s) < 8)
{
}
Stream_Read_UINT16(s, header->CapabilityType); /* CapabilityType (2 bytes) */
- Stream_Read_UINT16(s, header->CapabilityLength); /* CapabilityLength (2 bytes) */
+ Stream_Read_UINT16(s,
+ header->CapabilityLength); /* CapabilityLength (2 bytes) */
Stream_Read_UINT32(s, header->Version); /* Version (4 bytes) */
return CHANNEL_RC_OK;
}
*
* @return 0 on success, otherwise a Win32 error code
*/
-static UINT rdpdr_server_write_capability_set_header(wStream* s, RDPDR_CAPABILITY_HEADER* header)
+static UINT rdpdr_server_write_capability_set_header(wStream* s,
+ RDPDR_CAPABILITY_HEADER* header)
{
if (!Stream_EnsureRemainingCapacity(s, 8))
{
}
Stream_Write_UINT16(s, header->CapabilityType); /* CapabilityType (2 bytes) */
- Stream_Write_UINT16(s, header->CapabilityLength); /* CapabilityLength (2 bytes) */
+ Stream_Write_UINT16(s,
+ header->CapabilityLength); /* CapabilityLength (2 bytes) */
Stream_Write_UINT32(s, header->Version); /* Version (4 bytes) */
return CHANNEL_RC_OK;
}
*
* @return 0 on success, otherwise a Win32 error code
*/
-static UINT rdpdr_server_read_general_capability_set(RdpdrServerContext* context, wStream* s, RDPDR_CAPABILITY_HEADER* header)
+static UINT rdpdr_server_read_general_capability_set(RdpdrServerContext*
+ context, wStream* s, RDPDR_CAPABILITY_HEADER* header)
{
UINT32 ioCode1;
UINT32 extraFlags1;
Stream_Read_UINT16(s, VersionMajor); /* protocolMajorVersion (2 bytes) */
Stream_Read_UINT16(s, VersionMinor); /* protocolMinorVersion (2 bytes) */
Stream_Read_UINT32(s, ioCode1); /* ioCode1 (4 bytes) */
- Stream_Seek_UINT32(s); /* ioCode2 (4 bytes), must be set to zero, reserved for future use */
+ Stream_Seek_UINT32(
+ s); /* ioCode2 (4 bytes), must be set to zero, reserved for future use */
Stream_Read_UINT32(s, extendedPdu); /* extendedPdu (4 bytes) */
Stream_Read_UINT32(s, extraFlags1); /* extraFlags1 (4 bytes) */
- Stream_Seek_UINT32(s); /* extraFlags2 (4 bytes), must be set to zero, reserved for future use */
+ Stream_Seek_UINT32(
+ s); /* extraFlags2 (4 bytes), must be set to zero, reserved for future use */
if (header->Version == GENERAL_CAPABILITY_VERSION_02)
{
return ERROR_INVALID_DATA;
}
- Stream_Read_UINT32(s, SpecialTypeDeviceCap); /* SpecialTypeDeviceCap (4 bytes) */
+ Stream_Read_UINT32(s,
+ SpecialTypeDeviceCap); /* SpecialTypeDeviceCap (4 bytes) */
}
- context->priv->UserLoggedOnPdu = (extendedPdu & RDPDR_USER_LOGGEDON_PDU) ? TRUE : FALSE;
+ context->priv->UserLoggedOnPdu = (extendedPdu & RDPDR_USER_LOGGEDON_PDU) ?
+ TRUE : FALSE;
return CHANNEL_RC_OK;
}
*
* @return 0 on success, otherwise a Win32 error code
*/
-static UINT rdpdr_server_write_general_capability_set(RdpdrServerContext* context, wStream* s)
+static UINT rdpdr_server_write_general_capability_set(RdpdrServerContext*
+ context, wStream* s)
{
UINT32 ioCode1;
UINT32 extendedPdu;
UINT32 extraFlags1;
UINT32 SpecialTypeDeviceCap;
RDPDR_CAPABILITY_HEADER header;
-
header.CapabilityType = CAP_GENERAL_TYPE;
header.CapabilityLength = RDPDR_CAPABILITY_HEADER_LENGTH + 36;
header.Version = GENERAL_CAPABILITY_VERSION_02;
}
rdpdr_server_write_capability_set_header(s, &header);
-
Stream_Write_UINT32(s, 0); /* osType (4 bytes), ignored on receipt */
- Stream_Write_UINT32(s, 0); /* osVersion (4 bytes), unused and must be set to zero */
- Stream_Write_UINT16(s, context->priv->VersionMajor); /* protocolMajorVersion (2 bytes) */
- Stream_Write_UINT16(s, context->priv->VersionMinor); /* protocolMinorVersion (2 bytes) */
+ Stream_Write_UINT32(s,
+ 0); /* osVersion (4 bytes), unused and must be set to zero */
+ Stream_Write_UINT16(s,
+ context->priv->VersionMajor); /* protocolMajorVersion (2 bytes) */
+ Stream_Write_UINT16(s,
+ context->priv->VersionMinor); /* protocolMinorVersion (2 bytes) */
Stream_Write_UINT32(s, ioCode1); /* ioCode1 (4 bytes) */
- Stream_Write_UINT32(s, 0); /* ioCode2 (4 bytes), must be set to zero, reserved for future use */
+ Stream_Write_UINT32(s,
+ 0); /* ioCode2 (4 bytes), must be set to zero, reserved for future use */
Stream_Write_UINT32(s, extendedPdu); /* extendedPdu (4 bytes) */
Stream_Write_UINT32(s, extraFlags1); /* extraFlags1 (4 bytes) */
- Stream_Write_UINT32(s, 0); /* extraFlags2 (4 bytes), must be set to zero, reserved for future use */
- Stream_Write_UINT32(s, SpecialTypeDeviceCap); /* SpecialTypeDeviceCap (4 bytes) */
+ Stream_Write_UINT32(s,
+ 0); /* extraFlags2 (4 bytes), must be set to zero, reserved for future use */
+ Stream_Write_UINT32(s,
+ SpecialTypeDeviceCap); /* SpecialTypeDeviceCap (4 bytes) */
return CHANNEL_RC_OK;
}
*
* @return 0 on success, otherwise a Win32 error code
*/
-static UINT rdpdr_server_read_printer_capability_set(RdpdrServerContext* context, wStream* s, RDPDR_CAPABILITY_HEADER* header)
+static UINT rdpdr_server_read_printer_capability_set(RdpdrServerContext*
+ context, wStream* s, RDPDR_CAPABILITY_HEADER* header)
{
return CHANNEL_RC_OK;
}
*
* @return 0 on success, otherwise a Win32 error code
*/
-static UINT rdpdr_server_write_printer_capability_set(RdpdrServerContext* context, wStream* s)
+static UINT rdpdr_server_write_printer_capability_set(RdpdrServerContext*
+ context, wStream* s)
{
RDPDR_CAPABILITY_HEADER header;
-
header.CapabilityType = CAP_PRINTER_TYPE;
header.CapabilityLength = RDPDR_CAPABILITY_HEADER_LENGTH;
header.Version = PRINT_CAPABILITY_VERSION_01;
WLog_ERR(TAG, "Stream_EnsureRemainingCapacity failed!");
return CHANNEL_RC_NO_MEMORY;
}
+
return rdpdr_server_write_capability_set_header(s, &header);
}
*
* @return 0 on success, otherwise a Win32 error code
*/
-static UINT rdpdr_server_read_port_capability_set(RdpdrServerContext* context, wStream* s, RDPDR_CAPABILITY_HEADER* header)
+static UINT rdpdr_server_read_port_capability_set(RdpdrServerContext* context,
+ wStream* s, RDPDR_CAPABILITY_HEADER* header)
{
return CHANNEL_RC_OK;
}
*
* @return 0 on success, otherwise a Win32 error code
*/
-static UINT rdpdr_server_write_port_capability_set(RdpdrServerContext* context, wStream* s)
+static UINT rdpdr_server_write_port_capability_set(RdpdrServerContext* context,
+ wStream* s)
{
RDPDR_CAPABILITY_HEADER header;
-
header.CapabilityType = CAP_PORT_TYPE;
header.CapabilityLength = RDPDR_CAPABILITY_HEADER_LENGTH;
header.Version = PORT_CAPABILITY_VERSION_01;
WLog_ERR(TAG, "Stream_EnsureRemainingCapacity failed!");
return CHANNEL_RC_NO_MEMORY;
}
+
return rdpdr_server_write_capability_set_header(s, &header);
}
*
* @return 0 on success, otherwise a Win32 error code
*/
-static UINT rdpdr_server_read_drive_capability_set(RdpdrServerContext* context, wStream* s, RDPDR_CAPABILITY_HEADER* header)
+static UINT rdpdr_server_read_drive_capability_set(RdpdrServerContext* context,
+ wStream* s, RDPDR_CAPABILITY_HEADER* header)
{
return CHANNEL_RC_OK;
}
*
* @return 0 on success, otherwise a Win32 error code
*/
-static UINT rdpdr_server_write_drive_capability_set(RdpdrServerContext* context, wStream* s)
+static UINT rdpdr_server_write_drive_capability_set(RdpdrServerContext* context,
+ wStream* s)
{
RDPDR_CAPABILITY_HEADER header;
-
header.CapabilityType = CAP_DRIVE_TYPE;
header.CapabilityLength = RDPDR_CAPABILITY_HEADER_LENGTH;
header.Version = DRIVE_CAPABILITY_VERSION_02;
WLog_ERR(TAG, "Stream_EnsureRemainingCapacity failed!");
return CHANNEL_RC_NO_MEMORY;
}
+
return rdpdr_server_write_capability_set_header(s, &header);
}
*
* @return 0 on success, otherwise a Win32 error code
*/
-static UINT rdpdr_server_read_smartcard_capability_set(RdpdrServerContext* context, wStream* s, RDPDR_CAPABILITY_HEADER* header)
+static UINT rdpdr_server_read_smartcard_capability_set(RdpdrServerContext*
+ context, wStream* s, RDPDR_CAPABILITY_HEADER* header)
{
return CHANNEL_RC_OK;
}
*
* @return 0 on success, otherwise a Win32 error code
*/
-static UINT rdpdr_server_write_smartcard_capability_set(RdpdrServerContext* context, wStream* s)
+static UINT rdpdr_server_write_smartcard_capability_set(
+ RdpdrServerContext* context, wStream* s)
{
RDPDR_CAPABILITY_HEADER header;
-
header.CapabilityType = CAP_SMARTCARD_TYPE;
header.CapabilityLength = RDPDR_CAPABILITY_HEADER_LENGTH;
header.Version = SMARTCARD_CAPABILITY_VERSION_01;
WLog_ERR(TAG, "Stream_EnsureRemainingCapacity failed!");
return CHANNEL_RC_OK;
}
+
return rdpdr_server_write_capability_set_header(s, &header);
}
*
* @return 0 on success, otherwise a Win32 error code
*/
-static UINT rdpdr_server_send_core_capability_request(RdpdrServerContext* context)
+static UINT rdpdr_server_send_core_capability_request(RdpdrServerContext*
+ context)
{
wStream* s;
BOOL status;
UINT16 numCapabilities;
ULONG written;
UINT error;
-
WLog_DBG(TAG, "RdpdrServerSendCoreCapabilityRequest");
-
header.Component = RDPDR_CTYP_CORE;
header.PacketId = PAKID_CORE_SERVER_CAPABILITY;
-
numCapabilities = 1;
if (context->supportsDrives)
numCapabilities++;
+
if (context->supportsPorts)
numCapabilities++;
+
if (context->supportsPrinters)
numCapabilities++;
+
if (context->supportsSmartcards)
numCapabilities++;
WLog_ERR(TAG, "Stream_New failed!");
return CHANNEL_RC_NO_MEMORY;
}
+
Stream_Write_UINT16(s, header.Component); /* Component (2 bytes) */
Stream_Write_UINT16(s, header.PacketId); /* PacketId (2 bytes) */
Stream_Write_UINT16(s, numCapabilities); /* numCapabilities (2 bytes) */
if ((error = rdpdr_server_write_general_capability_set(context, s)))
{
- WLog_ERR(TAG, "rdpdr_server_write_general_capability_set failed with error %lu!", error);
+ WLog_ERR(TAG,
+ "rdpdr_server_write_general_capability_set failed with error %lu!", error);
return error;
}
-
if (context->supportsDrives)
{
if ((error = rdpdr_server_write_drive_capability_set(context, s)))
{
- WLog_ERR(TAG, "rdpdr_server_write_drive_capability_set failed with error %lu!", error);
+ WLog_ERR(TAG, "rdpdr_server_write_drive_capability_set failed with error %lu!",
+ error);
return error;
}
}
{
if ((error = rdpdr_server_write_port_capability_set(context, s)))
{
- WLog_ERR(TAG, "rdpdr_server_write_port_capability_set failed with error %lu!", error);
+ WLog_ERR(TAG, "rdpdr_server_write_port_capability_set failed with error %lu!",
+ error);
return error;
}
}
{
if ((error = rdpdr_server_write_printer_capability_set(context, s)))
{
- WLog_ERR(TAG, "rdpdr_server_write_printer_capability_set failed with error %lu!", error);
+ WLog_ERR(TAG,
+ "rdpdr_server_write_printer_capability_set failed with error %lu!", error);
return error;
}
}
{
if ((error = rdpdr_server_write_smartcard_capability_set(context, s)))
{
- WLog_ERR(TAG, "rdpdr_server_write_printer_capability_set failed with error %lu!", error);
+ WLog_ERR(TAG,
+ "rdpdr_server_write_printer_capability_set failed with error %lu!", error);
return error;
}
}
Stream_SealLength(s);
-
winpr_HexDump(TAG, WLOG_DEBUG, Stream_Buffer(s), Stream_Length(s));
-
- status = WTSVirtualChannelWrite(context->priv->ChannelHandle, (PCHAR) Stream_Buffer(s), Stream_Length(s), &written);
-
+ status = WTSVirtualChannelWrite(context->priv->ChannelHandle,
+ (PCHAR) Stream_Buffer(s), Stream_Length(s), &written);
Stream_Free(s, TRUE);
return status ? CHANNEL_RC_OK : ERROR_INTERNAL_ERROR;
}
*
* @return 0 on success, otherwise a Win32 error code
*/
-static UINT rdpdr_server_receive_core_capability_response(RdpdrServerContext* context, wStream* s, RDPDR_HEADER* header)
+static UINT rdpdr_server_receive_core_capability_response(
+ RdpdrServerContext* context, wStream* s, RDPDR_HEADER* header)
{
int i;
UINT status;
{
if ((status = rdpdr_server_read_capability_set_header(s, &capabilityHeader)))
{
- WLog_ERR(TAG, "rdpdr_server_read_capability_set_header failed with error %lu!", status);
+ WLog_ERR(TAG, "rdpdr_server_read_capability_set_header failed with error %lu!",
+ status);
return status;
}
switch (capabilityHeader.CapabilityType)
{
case CAP_GENERAL_TYPE:
- if ((status = rdpdr_server_read_general_capability_set(context, s, &capabilityHeader)))
+ if ((status = rdpdr_server_read_general_capability_set(context, s,
+ &capabilityHeader)))
{
- WLog_ERR(TAG, "rdpdr_server_read_general_capability_set failed with error %lu!", status);
+ WLog_ERR(TAG, "rdpdr_server_read_general_capability_set failed with error %lu!",
+ status);
return status;
}
+
break;
case CAP_PRINTER_TYPE:
- if ((status = rdpdr_server_read_printer_capability_set(context, s, &capabilityHeader)))
+ if ((status = rdpdr_server_read_printer_capability_set(context, s,
+ &capabilityHeader)))
{
- WLog_ERR(TAG, "rdpdr_server_read_printer_capability_set failed with error %lu!", status);
+ WLog_ERR(TAG, "rdpdr_server_read_printer_capability_set failed with error %lu!",
+ status);
return status;
}
+
break;
case CAP_PORT_TYPE:
- if ((status = rdpdr_server_read_port_capability_set(context, s, &capabilityHeader)))
+ if ((status = rdpdr_server_read_port_capability_set(context, s,
+ &capabilityHeader)))
{
- WLog_ERR(TAG, "rdpdr_server_read_port_capability_set failed with error %lu!", status);
+ WLog_ERR(TAG, "rdpdr_server_read_port_capability_set failed with error %lu!",
+ status);
return status;
}
+
break;
case CAP_DRIVE_TYPE:
- if ((status = rdpdr_server_read_drive_capability_set(context, s, &capabilityHeader)))
+ if ((status = rdpdr_server_read_drive_capability_set(context, s,
+ &capabilityHeader)))
{
- WLog_ERR(TAG, "rdpdr_server_read_drive_capability_set failed with error %lu!", status);
+ WLog_ERR(TAG, "rdpdr_server_read_drive_capability_set failed with error %lu!",
+ status);
return status;
}
+
break;
case CAP_SMARTCARD_TYPE:
- if ((status = rdpdr_server_read_smartcard_capability_set(context, s, &capabilityHeader)))
+ if ((status = rdpdr_server_read_smartcard_capability_set(context, s,
+ &capabilityHeader)))
{
- WLog_ERR(TAG, "rdpdr_server_read_smartcard_capability_set failed with error %lu!", status);
+ WLog_ERR(TAG,
+ "rdpdr_server_read_smartcard_capability_set failed with error %lu!", status);
return status;
}
+
break;
default:
WLog_DBG(TAG, "Unknown capabilityType %d", capabilityHeader.CapabilityType);
- Stream_Seek(s, capabilityHeader.CapabilityLength - RDPDR_CAPABILITY_HEADER_LENGTH);
+ Stream_Seek(s, capabilityHeader.CapabilityLength -
+ RDPDR_CAPABILITY_HEADER_LENGTH);
return ERROR_INVALID_DATA;
break;
}
BOOL status;
RDPDR_HEADER header;
ULONG written;
-
WLog_DBG(TAG, "RdpdrServerSendClientIdConfirm");
-
header.Component = RDPDR_CTYP_CORE;
header.PacketId = PAKID_CORE_CLIENTID_CONFIRM;
-
s = Stream_New(NULL, RDPDR_HEADER_LENGTH + 8);
+
if (!s)
{
WLog_ERR(TAG, "Stream_New failed!");
return CHANNEL_RC_NO_MEMORY;
}
+
Stream_Write_UINT16(s, header.Component); /* Component (2 bytes) */
Stream_Write_UINT16(s, header.PacketId); /* PacketId (2 bytes) */
- Stream_Write_UINT16(s, context->priv->VersionMajor); /* VersionMajor (2 bytes) */
- Stream_Write_UINT16(s, context->priv->VersionMinor); /* VersionMinor (2 bytes) */
+ Stream_Write_UINT16(s,
+ context->priv->VersionMajor); /* VersionMajor (2 bytes) */
+ Stream_Write_UINT16(s,
+ context->priv->VersionMinor); /* VersionMinor (2 bytes) */
Stream_Write_UINT32(s, context->priv->ClientId); /* ClientId (4 bytes) */
-
Stream_SealLength(s);
-
winpr_HexDump(TAG, WLOG_DEBUG, Stream_Buffer(s), Stream_Length(s));
-
- status = WTSVirtualChannelWrite(context->priv->ChannelHandle, (PCHAR) Stream_Buffer(s), Stream_Length(s), &written);
-
+ status = WTSVirtualChannelWrite(context->priv->ChannelHandle,
+ (PCHAR) Stream_Buffer(s), Stream_Length(s), &written);
Stream_Free(s, TRUE);
return status ? CHANNEL_RC_OK : ERROR_INTERNAL_ERROR;
}
*
* @return 0 on success, otherwise a Win32 error code
*/
-static UINT rdpdr_server_receive_device_list_announce_request(RdpdrServerContext* context, wStream* s, RDPDR_HEADER* header)
+static UINT rdpdr_server_receive_device_list_announce_request(
+ RdpdrServerContext* context, wStream* s, RDPDR_HEADER* header)
{
int i;
UINT32 DeviceCount;
}
Stream_Read_UINT32(s, DeviceCount); /* DeviceCount (4 bytes) */
-
WLog_DBG(TAG, "DeviceCount: %d", DeviceCount);
for (i = 0; i < DeviceCount; i++)
}
DeviceData = Stream_Pointer(s);
-
WLog_DBG(TAG, "Device %d Name: %s Id: 0x%04X DataLength: %d",
- i, PreferredDosName, DeviceId, DeviceDataLength);
+ i, PreferredDosName, DeviceId, DeviceDataLength);
switch (DeviceType)
{
{
IFCALL(context->OnDriveCreate, context, DeviceId, PreferredDosName);
}
+
break;
case RDPDR_DTYP_PRINT:
{
IFCALL(context->OnPrinterCreate, context, DeviceId, PreferredDosName);
}
+
break;
case RDPDR_DTYP_SERIAL:
{
IFCALL(context->OnPortCreate, context, DeviceId, PreferredDosName);
}
+
break;
case RDPDR_DTYP_SMARTCARD:
{
IFCALL(context->OnSmartcardCreate, context, DeviceId, PreferredDosName);
}
+
break;
default:
*
* @return 0 on success, otherwise a Win32 error code
*/
-static UINT rdpdr_server_receive_device_list_remove_request(RdpdrServerContext* context, wStream* s, RDPDR_HEADER* header)
+static UINT rdpdr_server_receive_device_list_remove_request(
+ RdpdrServerContext* context, wStream* s, RDPDR_HEADER* header)
{
int i;
UINT32 DeviceCount;
}
Stream_Read_UINT32(s, DeviceCount); /* DeviceCount (4 bytes) */
-
WLog_DBG(TAG, "DeviceCount: %d", DeviceCount);
for (i = 0; i < DeviceCount; i++)
}
Stream_Read_UINT32(s, DeviceId); /* DeviceId (4 bytes) */
-
WLog_DBG(TAG, "Device %d Id: 0x%04X", i, DeviceId);
-
DeviceType = 0; /* TODO: Save the device type on the announce request. */
switch (DeviceType)
{
IFCALL(context->OnDriveDelete, context, DeviceId);
}
+
break;
case RDPDR_DTYP_PRINT:
{
IFCALL(context->OnPrinterDelete, context, DeviceId);
}
+
break;
case RDPDR_DTYP_SERIAL:
{
IFCALL(context->OnPortDelete, context, DeviceId);
}
+
break;
case RDPDR_DTYP_SMARTCARD:
{
IFCALL(context->OnSmartcardDelete, context, DeviceId);
}
+
break;
default:
*
* @return 0 on success, otherwise a Win32 error code
*/
-static UINT rdpdr_server_receive_device_io_completion(RdpdrServerContext* context, wStream* s, RDPDR_HEADER* header)
+static UINT rdpdr_server_receive_device_io_completion(RdpdrServerContext*
+ context, wStream* s, RDPDR_HEADER* header)
{
UINT32 deviceId;
UINT32 completionId;
Stream_Read_UINT32(s, deviceId);
Stream_Read_UINT32(s, completionId);
Stream_Read_UINT32(s, ioStatus);
-
- WLog_DBG(TAG, "deviceId=%d, completionId=0x%x, ioStatus=0x%x", deviceId, completionId, ioStatus);
-
+ WLog_DBG(TAG, "deviceId=%d, completionId=0x%x, ioStatus=0x%x", deviceId,
+ completionId, ioStatus);
irp = rdpdr_server_dequeue_irp(context, completionId);
if (!irp)
{
error = (*irp->Callback)(context, s, irp, deviceId, completionId, ioStatus);
}
+
return error;
}
BOOL status;
RDPDR_HEADER header;
ULONG written;
-
WLog_DBG(TAG, "RdpdrServerSendUserLoggedOn");
-
header.Component = RDPDR_CTYP_CORE;
header.PacketId = PAKID_CORE_USER_LOGGEDON;
-
s = Stream_New(NULL, RDPDR_HEADER_LENGTH);
+
if (!s)
{
WLog_ERR(TAG, "Stream_New failed!");
return CHANNEL_RC_NO_MEMORY;
}
+
Stream_Write_UINT16(s, header.Component); /* Component (2 bytes) */
Stream_Write_UINT16(s, header.PacketId); /* PacketId (2 bytes) */
-
Stream_SealLength(s);
-
winpr_HexDump(TAG, WLOG_DEBUG, Stream_Buffer(s), Stream_Length(s));
-
- status = WTSVirtualChannelWrite(context->priv->ChannelHandle, (PCHAR) Stream_Buffer(s), Stream_Length(s), &written);
-
+ status = WTSVirtualChannelWrite(context->priv->ChannelHandle,
+ (PCHAR) Stream_Buffer(s), Stream_Length(s), &written);
Stream_Free(s, TRUE);
return status ? CHANNEL_RC_OK : ERROR_INTERNAL_ERROR;
}
*
* @return 0 on success, otherwise a Win32 error code
*/
-static UINT rdpdr_server_receive_pdu(RdpdrServerContext* context, wStream* s, RDPDR_HEADER* header)
+static UINT rdpdr_server_receive_pdu(RdpdrServerContext* context, wStream* s,
+ RDPDR_HEADER* header)
{
UINT error = CHANNEL_RC_OK;
-
WLog_DBG(TAG, "RdpdrServerReceivePdu: Component: 0x%04X PacketId: 0x%04X",
- header->Component, header->PacketId);
-
+ header->Component, header->PacketId);
winpr_HexDump(TAG, WLOG_DEBUG, Stream_Buffer(s), Stream_Length(s));
if (header->Component == RDPDR_CTYP_CORE)
case PAKID_CORE_CLIENTID_CONFIRM:
if ((error = rdpdr_server_receive_announce_response(context, s, header)))
{
- WLog_ERR(TAG, "rdpdr_server_receive_announce_response failed with error %lu!", error);
+ WLog_ERR(TAG, "rdpdr_server_receive_announce_response failed with error %lu!",
+ error);
return error;
}
+
break;
case PAKID_CORE_CLIENT_NAME:
if ((error = rdpdr_server_receive_client_name_request(context, s, header)))
{
- WLog_ERR(TAG, "rdpdr_server_receive_client_name_request failed with error %lu!", error);
+ WLog_ERR(TAG, "rdpdr_server_receive_client_name_request failed with error %lu!",
+ error);
return error;
}
-
- if((error = rdpdr_server_send_core_capability_request(context)))
+ if ((error = rdpdr_server_send_core_capability_request(context)))
{
- WLog_ERR(TAG, "rdpdr_server_send_core_capability_request failed with error %lu!", error);
+ WLog_ERR(TAG,
+ "rdpdr_server_send_core_capability_request failed with error %lu!", error);
return error;
}
-
if ((error = rdpdr_server_send_client_id_confirm(context)))
{
- WLog_ERR(TAG, "rdpdr_server_send_client_id_confirm failed with error %lu!", error);
+ WLog_ERR(TAG, "rdpdr_server_send_client_id_confirm failed with error %lu!",
+ error);
return error;
}
case PAKID_CORE_CLIENT_CAPABILITY:
if ((error = rdpdr_server_receive_core_capability_response(context, s, header)))
{
- WLog_ERR(TAG, "rdpdr_server_receive_core_capability_response failed with error %lu!", error);
+ WLog_ERR(TAG,
+ "rdpdr_server_receive_core_capability_response failed with error %lu!", error);
return error;
}
if (context->priv->UserLoggedOnPdu)
- if((error = rdpdr_server_send_user_logged_on(context)))
+ if ((error = rdpdr_server_send_user_logged_on(context)))
{
WLog_ERR(TAG, "rdpdr_server_send_user_logged_on failed with error %lu!", error);
return error;
}
+
break;
case PAKID_CORE_DEVICELIST_ANNOUNCE:
- if ((error = rdpdr_server_receive_device_list_announce_request(context, s, header)))
+ if ((error = rdpdr_server_receive_device_list_announce_request(context, s,
+ header)))
{
- WLog_ERR(TAG, "rdpdr_server_receive_device_list_announce_request failed with error %lu!", error);
+ WLog_ERR(TAG,
+ "rdpdr_server_receive_device_list_announce_request failed with error %lu!",
+ error);
return error;
}
+
break;
case PAKID_CORE_DEVICE_REPLY:
case PAKID_CORE_DEVICE_IOCOMPLETION:
if ((error = rdpdr_server_receive_device_io_completion(context, s, header)))
{
- WLog_ERR(TAG, "rdpdr_server_receive_device_io_completion failed with error %lu!", error);
+ WLog_ERR(TAG,
+ "rdpdr_server_receive_device_io_completion failed with error %lu!", error);
return error;
}
+
break;
case PAKID_CORE_DEVICELIST_REMOVE:
- if((error = rdpdr_server_receive_device_list_remove_request(context, s, header)))
+ if ((error = rdpdr_server_receive_device_list_remove_request(context, s,
+ header)))
{
- WLog_ERR(TAG, "rdpdr_server_receive_device_io_completion failed with error %lu!", error);
+ WLog_ERR(TAG,
+ "rdpdr_server_receive_device_io_completion failed with error %lu!", error);
return error;
}
+
break;
default:
DWORD BytesReturned;
RdpdrServerContext* context;
UINT error;
-
context = (RdpdrServerContext*) arg;
buffer = NULL;
BytesReturned = 0;
ChannelEvent = NULL;
-
freerdp_channel_init_thread_context(context->rdpcontext);
s = Stream_New(NULL, 4096);
+
if (!s)
{
WLog_ERR(TAG, "Stream_New failed!");
goto out;
}
- if (WTSVirtualChannelQuery(context->priv->ChannelHandle, WTSVirtualEventHandle, &buffer, &BytesReturned) == TRUE)
+ if (WTSVirtualChannelQuery(context->priv->ChannelHandle, WTSVirtualEventHandle,
+ &buffer, &BytesReturned) == TRUE)
{
if (BytesReturned == sizeof(HANDLE))
CopyMemory(&ChannelEvent, buffer, sizeof(HANDLE));
nCount = 0;
events[nCount++] = ChannelEvent;
events[nCount++] = context->priv->StopEvent;
+
if ((error = rdpdr_server_send_announce_request(context)))
{
- WLog_ERR(TAG, "rdpdr_server_send_announce_request failed with error %lu!", error);
+ WLog_ERR(TAG, "rdpdr_server_send_announce_request failed with error %lu!",
+ error);
goto out_stream;
}
BytesReturned = 0;
status = WaitForMultipleObjects(nCount, events, FALSE, INFINITE);
- if (status == WAIT_FAILED)
- {
- error = GetLastError();
- WLog_ERR(TAG, "WaitForMultipleObjects failed with error %lu!", error);
- goto out_stream;
- }
-
- status = WaitForSingleObject(context->priv->StopEvent, 0);
+ if (status == WAIT_FAILED)
+ {
+ error = GetLastError();
+ WLog_ERR(TAG, "WaitForMultipleObjects failed with error %lu!", error);
+ goto out_stream;
+ }
- if (status == WAIT_FAILED)
- {
- error = GetLastError();
- WLog_ERR(TAG, "WaitForSingleObject failed with error %lu!", error);
- goto out_stream;
- }
+ status = WaitForSingleObject(context->priv->StopEvent, 0);
+ if (status == WAIT_FAILED)
+ {
+ error = GetLastError();
+ WLog_ERR(TAG, "WaitForSingleObject failed with error %lu!", error);
+ goto out_stream;
+ }
- if (status == WAIT_OBJECT_0)
+ if (status == WAIT_OBJECT_0)
break;
if (!WTSVirtualChannelRead(context->priv->ChannelHandle, 0,
- (PCHAR) Stream_Buffer(s), Stream_Capacity(s), &BytesReturned))
+ (PCHAR) Stream_Buffer(s), Stream_Capacity(s), &BytesReturned))
{
WLog_ERR(TAG, "WTSVirtualChannelRead failed!");
error = ERROR_INTERNAL_ERROR;
}
}
}
+
out_stream:
Stream_Free(s, TRUE);
out:
+
if (error && context->rdpcontext)
- setChannelError(context->rdpcontext, error, "rdpdr_server_thread reported an error");
+ setChannelError(context->rdpcontext, error,
+ "rdpdr_server_thread reported an error");
ExitThread((DWORD) error);
return NULL;
*/
static UINT rdpdr_server_start(RdpdrServerContext* context)
{
- context->priv->ChannelHandle = WTSVirtualChannelOpen(context->vcm, WTS_CURRENT_SESSION, "rdpdr");
+ context->priv->ChannelHandle = WTSVirtualChannelOpen(context->vcm,
+ WTS_CURRENT_SESSION, "rdpdr");
if (!context->priv->ChannelHandle)
{
WLog_ERR(TAG, "CreateEvent failed!");
return ERROR_INTERNAL_ERROR;
}
+
if (!(context->priv->Thread = CreateThread(NULL, 0,
- (LPTHREAD_START_ROUTINE) rdpdr_server_thread, (void*) context, 0, NULL)))
+ (LPTHREAD_START_ROUTINE) rdpdr_server_thread, (void*) context, 0, NULL)))
{
WLog_ERR(TAG, "CreateThread failed!");
CloseHandle(context->priv->StopEvent);
context->priv->StopEvent = NULL;
return ERROR_INTERNAL_ERROR;
}
+
return CHANNEL_RC_OK;
}
*/
static UINT rdpdr_server_stop(RdpdrServerContext* context)
{
- UINT error;
+ UINT error;
+
if (context->priv->StopEvent)
{
SetEvent(context->priv->StopEvent);
+
if (WaitForSingleObject(context->priv->Thread, INFINITE) == WAIT_FAILED)
- {
- error = GetLastError();
- WLog_ERR(TAG, "WaitForSingleObject failed with error %lu!", error);
- return error;
- }
+ {
+ error = GetLastError();
+ WLog_ERR(TAG, "WaitForSingleObject failed with error %lu!", error);
+ return error;
+ }
+
CloseHandle(context->priv->Thread);
context->priv->Thread = NULL;
CloseHandle(context->priv->StopEvent);
}
static void rdpdr_server_write_device_iorequest(
- wStream* s,
- UINT32 deviceId,
- UINT32 fileId,
- UINT32 completionId,
- UINT32 majorFunction,
- UINT32 minorFunction)
+ wStream* s,
+ UINT32 deviceId,
+ UINT32 fileId,
+ UINT32 completionId,
+ UINT32 majorFunction,
+ UINT32 minorFunction)
{
Stream_Write_UINT16(s, RDPDR_CTYP_CORE); /* Component (2 bytes) */
Stream_Write_UINT16(s, PAKID_CORE_DEVICE_IOREQUEST); /* PacketId (2 bytes) */
*
* @return 0 on success, otherwise a Win32 error code
*/
-static UINT rdpdr_server_read_file_directory_information(wStream* s, FILE_DIRECTORY_INFORMATION* fdi)
+static UINT rdpdr_server_read_file_directory_information(wStream* s,
+ FILE_DIRECTORY_INFORMATION* fdi)
{
UINT32 fileNameLength;
-
ZeroMemory(fdi, sizeof(FILE_DIRECTORY_INFORMATION));
if (Stream_GetRemainingLength(s) < 64)
return ERROR_INVALID_DATA;
}
- WideCharToMultiByte(CP_ACP, 0, (LPCWSTR) Stream_Pointer(s), fileNameLength / 2, fdi->FileName, sizeof(fdi->FileName), NULL, NULL);
+ WideCharToMultiByte(CP_ACP, 0, (LPCWSTR) Stream_Pointer(s), fileNameLength / 2,
+ fdi->FileName, sizeof(fdi->FileName), NULL, NULL);
Stream_Seek(s, fileNameLength);
-
return CHANNEL_RC_OK;
}
* @return 0 on success, otherwise a Win32 error code
*/
static UINT rdpdr_server_send_device_create_request(
- RdpdrServerContext* context,
- UINT32 deviceId,
- UINT32 completionId,
- const char* path,
- UINT32 desiredAccess,
- UINT32 createOptions,
- UINT32 createDisposition)
+ RdpdrServerContext* context,
+ UINT32 deviceId,
+ UINT32 completionId,
+ const char* path,
+ UINT32 desiredAccess,
+ UINT32 createOptions,
+ UINT32 createDisposition)
{
UINT32 pathLength;
ULONG written;
BOOL status;
wStream* s;
-
- WLog_DBG(TAG, "RdpdrServerSendDeviceCreateRequest: deviceId=%d, path=%s, desiredAccess=0x%x createOptions=0x%x createDisposition=0x%x",
- deviceId, path, desiredAccess, createOptions, createDisposition);
-
+ WLog_DBG(TAG,
+ "RdpdrServerSendDeviceCreateRequest: deviceId=%d, path=%s, desiredAccess=0x%x createOptions=0x%x createDisposition=0x%x",
+ deviceId, path, desiredAccess, createOptions, createDisposition);
/* Compute the required Unicode size. */
pathLength = (strlen(path) + 1) * sizeof(WCHAR);
-
s = Stream_New(NULL, 256 + pathLength);
if (!s)
return CHANNEL_RC_NO_MEMORY;
}
- rdpdr_server_write_device_iorequest(s, deviceId, 0, completionId, IRP_MJ_CREATE, 0);
-
+ rdpdr_server_write_device_iorequest(s, deviceId, 0, completionId, IRP_MJ_CREATE,
+ 0);
Stream_Write_UINT32(s, desiredAccess); /* DesiredAccess (4 bytes) */
Stream_Write_UINT32(s, 0); /* AllocationSize (8 bytes) */
Stream_Write_UINT32(s, 0);
Stream_Write_UINT32(s, createDisposition); /* CreateDisposition (4 bytes) */
Stream_Write_UINT32(s, createOptions); /* CreateOptions (4 bytes) */
Stream_Write_UINT32(s, pathLength); /* PathLength (4 bytes) */
-
/* Convert the path to Unicode. */
- MultiByteToWideChar(CP_ACP, 0, path, -1, (LPWSTR) Stream_Pointer(s), pathLength);
+ MultiByteToWideChar(CP_ACP, 0, path, -1, (LPWSTR) Stream_Pointer(s),
+ pathLength);
Stream_Seek(s, pathLength);
-
Stream_SealLength(s);
-
- status = WTSVirtualChannelWrite(context->priv->ChannelHandle, (PCHAR) Stream_Buffer(s), Stream_Length(s), &written);
-
+ status = WTSVirtualChannelWrite(context->priv->ChannelHandle,
+ (PCHAR) Stream_Buffer(s), Stream_Length(s), &written);
Stream_Free(s, TRUE);
-
return status ? CHANNEL_RC_OK : ERROR_INTERNAL_ERROR;
}
* @return 0 on success, otherwise a Win32 error code
*/
static UINT rdpdr_server_send_device_close_request(
- RdpdrServerContext* context,
- UINT32 deviceId,
- UINT32 fileId,
- UINT32 completionId)
+ RdpdrServerContext* context,
+ UINT32 deviceId,
+ UINT32 fileId,
+ UINT32 completionId)
{
ULONG written;
BOOL status;
wStream* s;
-
- WLog_DBG(TAG, "RdpdrServerSendDeviceCloseRequest: deviceId=%d, fileId=%d", deviceId, fileId);
-
+ WLog_DBG(TAG, "RdpdrServerSendDeviceCloseRequest: deviceId=%d, fileId=%d",
+ deviceId, fileId);
s = Stream_New(NULL, 128);
if (!s)
return CHANNEL_RC_NO_MEMORY;
}
- rdpdr_server_write_device_iorequest(s, deviceId, fileId, completionId, IRP_MJ_CLOSE, 0);
-
+ rdpdr_server_write_device_iorequest(s, deviceId, fileId, completionId,
+ IRP_MJ_CLOSE, 0);
Stream_Zero(s, 32); /* Padding (32 bytes) */
-
Stream_SealLength(s);
-
- status = WTSVirtualChannelWrite(context->priv->ChannelHandle, (PCHAR) Stream_Buffer(s), Stream_Length(s), &written);
-
+ status = WTSVirtualChannelWrite(context->priv->ChannelHandle,
+ (PCHAR) Stream_Buffer(s), Stream_Length(s), &written);
Stream_Free(s, TRUE);
-
return status ? CHANNEL_RC_OK : ERROR_INTERNAL_ERROR;
}
* @return 0 on success, otherwise a Win32 error code
*/
static UINT rdpdr_server_send_device_read_request(
- RdpdrServerContext* context,
- UINT32 deviceId,
- UINT32 fileId,
- UINT32 completionId,
- UINT32 length,
- UINT32 offset)
+ RdpdrServerContext* context,
+ UINT32 deviceId,
+ UINT32 fileId,
+ UINT32 completionId,
+ UINT32 length,
+ UINT32 offset)
{
ULONG written;
BOOL status;
wStream* s;
-
- WLog_DBG(TAG, "RdpdrServerSendDeviceReadRequest: deviceId=%d, fileId=%d, length=%d, offset=%d",
- deviceId, fileId, length, offset);
-
+ WLog_DBG(TAG,
+ "RdpdrServerSendDeviceReadRequest: deviceId=%d, fileId=%d, length=%d, offset=%d",
+ deviceId, fileId, length, offset);
s = Stream_New(NULL, 128);
if (!s)
return CHANNEL_RC_NO_MEMORY;
}
- rdpdr_server_write_device_iorequest(s, deviceId, fileId, completionId, IRP_MJ_READ, 0);
-
+ rdpdr_server_write_device_iorequest(s, deviceId, fileId, completionId,
+ IRP_MJ_READ, 0);
Stream_Write_UINT32(s, length); /* Length (4 bytes) */
Stream_Write_UINT32(s, offset); /* Offset (8 bytes) */
Stream_Write_UINT32(s, 0);
Stream_Zero(s, 20); /* Padding (20 bytes) */
-
Stream_SealLength(s);
-
- status = WTSVirtualChannelWrite(context->priv->ChannelHandle, (PCHAR) Stream_Buffer(s), Stream_Length(s), &written);
-
+ status = WTSVirtualChannelWrite(context->priv->ChannelHandle,
+ (PCHAR) Stream_Buffer(s), Stream_Length(s), &written);
Stream_Free(s, TRUE);
-
return status ? CHANNEL_RC_OK : ERROR_INTERNAL_ERROR;
}
* @return 0 on success, otherwise a Win32 error code
*/
static UINT rdpdr_server_send_device_write_request(
- RdpdrServerContext* context,
- UINT32 deviceId,
- UINT32 fileId,
- UINT32 completionId,
- const char* data,
- UINT32 length,
- UINT32 offset)
+ RdpdrServerContext* context,
+ UINT32 deviceId,
+ UINT32 fileId,
+ UINT32 completionId,
+ const char* data,
+ UINT32 length,
+ UINT32 offset)
{
ULONG written;
BOOL status;
wStream* s;
-
- WLog_DBG(TAG, "RdpdrServerSendDeviceWriteRequest: deviceId=%d, fileId=%d, length=%d, offset=%d",
- deviceId, fileId, length, offset);
-
+ WLog_DBG(TAG,
+ "RdpdrServerSendDeviceWriteRequest: deviceId=%d, fileId=%d, length=%d, offset=%d",
+ deviceId, fileId, length, offset);
s = Stream_New(NULL, 64 + length);
if (!s)
return CHANNEL_RC_NO_MEMORY;
}
- rdpdr_server_write_device_iorequest(s, deviceId, fileId, completionId, IRP_MJ_WRITE, 0);
-
+ rdpdr_server_write_device_iorequest(s, deviceId, fileId, completionId,
+ IRP_MJ_WRITE, 0);
Stream_Write_UINT32(s, length); /* Length (4 bytes) */
Stream_Write_UINT32(s, offset); /* Offset (8 bytes) */
Stream_Write_UINT32(s, 0);
Stream_Zero(s, 20); /* Padding (20 bytes) */
Stream_Write(s, data, length); /* WriteData (variable) */
-
Stream_SealLength(s);
-
- status = WTSVirtualChannelWrite(context->priv->ChannelHandle, (PCHAR) Stream_Buffer(s), Stream_Length(s), &written);
-
+ status = WTSVirtualChannelWrite(context->priv->ChannelHandle,
+ (PCHAR) Stream_Buffer(s), Stream_Length(s), &written);
Stream_Free(s, TRUE);
-
return status ? CHANNEL_RC_OK : ERROR_INTERNAL_ERROR;
}
* @return 0 on success, otherwise a Win32 error code
*/
static UINT rdpdr_server_send_device_query_directory_request(
- RdpdrServerContext* context,
- UINT32 deviceId,
- UINT32 fileId,
- UINT32 completionId,
- const char* path)
+ RdpdrServerContext* context,
+ UINT32 deviceId,
+ UINT32 fileId,
+ UINT32 completionId,
+ const char* path)
{
UINT32 pathLength;
ULONG written;
BOOL status;
wStream* s;
-
- WLog_DBG(TAG, "RdpdrServerSendDeviceQueryDirectoryRequest: deviceId=%d, fileId=%d, path=%s",
- deviceId, fileId, path);
-
+ WLog_DBG(TAG,
+ "RdpdrServerSendDeviceQueryDirectoryRequest: deviceId=%d, fileId=%d, path=%s",
+ deviceId, fileId, path);
/* Compute the required Unicode size. */
pathLength = path ? (strlen(path) + 1) * sizeof(WCHAR) : 0;
-
s = Stream_New(NULL, 64 + pathLength);
if (!s)
return CHANNEL_RC_NO_MEMORY;
}
- rdpdr_server_write_device_iorequest(s, deviceId, fileId, completionId, IRP_MJ_DIRECTORY_CONTROL, IRP_MN_QUERY_DIRECTORY);
-
- Stream_Write_UINT32(s, FileDirectoryInformation); /* FsInformationClass (4 bytes) */
+ rdpdr_server_write_device_iorequest(s, deviceId, fileId, completionId,
+ IRP_MJ_DIRECTORY_CONTROL, IRP_MN_QUERY_DIRECTORY);
+ Stream_Write_UINT32(s,
+ FileDirectoryInformation); /* FsInformationClass (4 bytes) */
Stream_Write_UINT8(s, path ? 1 : 0); /* InitialQuery (1 byte) */
Stream_Write_UINT32(s, pathLength); /* PathLength (4 bytes) */
Stream_Zero(s, 23); /* Padding (23 bytes) */
/* Convert the path to Unicode. */
if (pathLength > 0)
{
- MultiByteToWideChar(CP_ACP, 0, path, -1, (LPWSTR) Stream_Pointer(s), pathLength);
+ MultiByteToWideChar(CP_ACP, 0, path, -1, (LPWSTR) Stream_Pointer(s),
+ pathLength);
Stream_Seek(s, pathLength);
}
Stream_SealLength(s);
-
- status = WTSVirtualChannelWrite(context->priv->ChannelHandle, (PCHAR) Stream_Buffer(s), Stream_Length(s), &written);
-
+ status = WTSVirtualChannelWrite(context->priv->ChannelHandle,
+ (PCHAR) Stream_Buffer(s), Stream_Length(s), &written);
Stream_Free(s, TRUE);
-
- return status? CHANNEL_RC_OK : ERROR_INTERNAL_ERROR;
+ return status ? CHANNEL_RC_OK : ERROR_INTERNAL_ERROR;
}
/**
* @return 0 on success, otherwise a Win32 error code
*/
static UINT rdpdr_server_send_device_file_rename_request(
- RdpdrServerContext* context,
- UINT32 deviceId,
- UINT32 fileId,
- UINT32 completionId,
- const char* path)
+ RdpdrServerContext* context,
+ UINT32 deviceId,
+ UINT32 fileId,
+ UINT32 completionId,
+ const char* path)
{
UINT32 pathLength;
ULONG written;
BOOL status;
wStream* s;
-
- WLog_DBG(TAG, "RdpdrServerSendDeviceFileNameRequest: deviceId=%d, fileId=%d, path=%s",
- deviceId, fileId, path);
-
+ WLog_DBG(TAG,
+ "RdpdrServerSendDeviceFileNameRequest: deviceId=%d, fileId=%d, path=%s",
+ deviceId, fileId, path);
/* Compute the required Unicode size. */
pathLength = path ? (strlen(path) + 1) * sizeof(WCHAR) : 0;
-
s = Stream_New(NULL, 64 + pathLength);
if (!s)
return CHANNEL_RC_NO_MEMORY;
}
- rdpdr_server_write_device_iorequest(s, deviceId, fileId, completionId, IRP_MJ_SET_INFORMATION, 0);
-
- Stream_Write_UINT32(s, FileRenameInformation); /* FsInformationClass (4 bytes) */
+ rdpdr_server_write_device_iorequest(s, deviceId, fileId, completionId,
+ IRP_MJ_SET_INFORMATION, 0);
+ Stream_Write_UINT32(s,
+ FileRenameInformation); /* FsInformationClass (4 bytes) */
Stream_Write_UINT32(s, pathLength + 6); /* Length (4 bytes) */
Stream_Zero(s, 24); /* Padding (24 bytes) */
-
/* RDP_FILE_RENAME_INFORMATION */
Stream_Write_UINT8(s, 0); /* ReplaceIfExists (1 byte) */
Stream_Write_UINT8(s, 0); /* RootDirectory (1 byte) */
/* Convert the path to Unicode. */
if (pathLength > 0)
{
- MultiByteToWideChar(CP_ACP, 0, path, -1, (LPWSTR) Stream_Pointer(s), pathLength);
+ MultiByteToWideChar(CP_ACP, 0, path, -1, (LPWSTR) Stream_Pointer(s),
+ pathLength);
Stream_Seek(s, pathLength);
}
Stream_SealLength(s);
-
- status = WTSVirtualChannelWrite(context->priv->ChannelHandle, (PCHAR) Stream_Buffer(s), Stream_Length(s), &written);
-
+ status = WTSVirtualChannelWrite(context->priv->ChannelHandle,
+ (PCHAR) Stream_Buffer(s), Stream_Length(s), &written);
Stream_Free(s, TRUE);
-
return status ? CHANNEL_RC_OK : ERROR_INTERNAL_ERROR;
}
*
* @return 0 on success, otherwise a Win32 error code
*/
-static UINT rdpdr_server_drive_create_directory_callback2(RdpdrServerContext* context, wStream* s, RDPDR_IRP* irp, UINT32 deviceId, UINT32 completionId, UINT32 ioStatus)
+static UINT rdpdr_server_drive_create_directory_callback2(
+ RdpdrServerContext* context, wStream* s, RDPDR_IRP* irp, UINT32 deviceId,
+ UINT32 completionId, UINT32 ioStatus)
{
- WLog_DBG(TAG, "RdpdrServerDriveCreateDirectoryCallback2: deviceId=%d, completionId=%d, ioStatus=0x%x",
- deviceId, completionId, ioStatus);
-
+ WLog_DBG(TAG,
+ "RdpdrServerDriveCreateDirectoryCallback2: deviceId=%d, completionId=%d, ioStatus=0x%x",
+ deviceId, completionId, ioStatus);
/* Invoke the create directory completion routine. */
context->OnDriveCreateDirectoryComplete(context, irp->CallbackData, ioStatus);
-
/* Destroy the IRP. */
rdpdr_server_irp_free(irp);
-
return CHANNEL_RC_OK;
}
*
* @return 0 on success, otherwise a Win32 error code
*/
-static UINT rdpdr_server_drive_create_directory_callback1(RdpdrServerContext* context, wStream* s, RDPDR_IRP* irp, UINT32 deviceId, UINT32 completionId, UINT32 ioStatus)
+static UINT rdpdr_server_drive_create_directory_callback1(
+ RdpdrServerContext* context, wStream* s, RDPDR_IRP* irp, UINT32 deviceId,
+ UINT32 completionId, UINT32 ioStatus)
{
UINT32 fileId;
UINT8 information;
-
- WLog_DBG(TAG, "RdpdrServerDriveCreateDirectoryCallback1: deviceId=%d, completionId=%d, ioStatus=0x%x",
- deviceId, completionId, ioStatus);
+ WLog_DBG(TAG,
+ "RdpdrServerDriveCreateDirectoryCallback1: deviceId=%d, completionId=%d, ioStatus=0x%x",
+ deviceId, completionId, ioStatus);
if (ioStatus != STATUS_SUCCESS)
{
/* Invoke the create directory completion routine. */
context->OnDriveCreateDirectoryComplete(context, irp->CallbackData, ioStatus);
-
/* Destroy the IRP. */
rdpdr_server_irp_free(irp);
-
return CHANNEL_RC_OK;
}
Stream_Read_UINT32(s, fileId); /* FileId (4 bytes) */
Stream_Read_UINT8(s, information); /* Information (1 byte) */
-
/* Setup the IRP. */
irp->CompletionId = context->priv->NextCompletionId++;
irp->Callback = rdpdr_server_drive_create_directory_callback2;
}
/* Send a request to close the file */
- return rdpdr_server_send_device_close_request(context, deviceId, fileId, irp->CompletionId);
+ return rdpdr_server_send_device_close_request(context, deviceId, fileId,
+ irp->CompletionId);
}
/**
*
* @return 0 on success, otherwise a Win32 error code
*/
-static UINT rdpdr_server_drive_create_directory(RdpdrServerContext* context, void* callbackData, UINT32 deviceId, const char* path)
+static UINT rdpdr_server_drive_create_directory(RdpdrServerContext* context,
+ void* callbackData, UINT32 deviceId, const char* path)
{
RDPDR_IRP* irp;
-
irp = rdpdr_server_irp_new();
if (!irp)
irp->CallbackData = callbackData;
irp->DeviceId = deviceId;
strncpy(irp->PathName, path, sizeof(irp->PathName));
-
rdpdr_server_convert_slashes(irp->PathName, sizeof(irp->PathName));
if (!rdpdr_server_enqueue_irp(context, irp))
}
/* Send a request to open the file. */
- return rdpdr_server_send_device_create_request(context, deviceId, irp->CompletionId, irp->PathName,
- FILE_READ_DATA | SYNCHRONIZE, FILE_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT, FILE_CREATE);
+ return rdpdr_server_send_device_create_request(context, deviceId,
+ irp->CompletionId, irp->PathName,
+ FILE_READ_DATA | SYNCHRONIZE,
+ FILE_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT, FILE_CREATE);
}
/*************************************************
*
* @return 0 on success, otherwise a Win32 error code
*/
-static UINT rdpdr_server_drive_delete_directory_callback2(RdpdrServerContext* context, wStream* s, RDPDR_IRP* irp, UINT32 deviceId, UINT32 completionId, UINT32 ioStatus)
+static UINT rdpdr_server_drive_delete_directory_callback2(
+ RdpdrServerContext* context, wStream* s, RDPDR_IRP* irp, UINT32 deviceId,
+ UINT32 completionId, UINT32 ioStatus)
{
- WLog_DBG(TAG, "RdpdrServerDriveDeleteDirectoryCallback2: deviceId=%d, completionId=%d, ioStatus=0x%x",
- deviceId, completionId, ioStatus);
-
+ WLog_DBG(TAG,
+ "RdpdrServerDriveDeleteDirectoryCallback2: deviceId=%d, completionId=%d, ioStatus=0x%x",
+ deviceId, completionId, ioStatus);
/* Invoke the delete directory completion routine. */
context->OnDriveDeleteDirectoryComplete(context, irp->CallbackData, ioStatus);
-
/* Destroy the IRP. */
rdpdr_server_irp_free(irp);
-
return CHANNEL_RC_OK;
}
*
* @return 0 on success, otherwise a Win32 error code
*/
-static UINT rdpdr_server_drive_delete_directory_callback1(RdpdrServerContext* context, wStream* s, RDPDR_IRP* irp, UINT32 deviceId, UINT32 completionId, UINT32 ioStatus)
+static UINT rdpdr_server_drive_delete_directory_callback1(
+ RdpdrServerContext* context, wStream* s, RDPDR_IRP* irp, UINT32 deviceId,
+ UINT32 completionId, UINT32 ioStatus)
{
UINT32 fileId;
UINT8 information;
-
- WLog_DBG(TAG, "RdpdrServerDriveDeleteDirectoryCallback1: deviceId=%d, completionId=%d, ioStatus=0x%x",
- deviceId, completionId, ioStatus);
+ WLog_DBG(TAG,
+ "RdpdrServerDriveDeleteDirectoryCallback1: deviceId=%d, completionId=%d, ioStatus=0x%x",
+ deviceId, completionId, ioStatus);
if (ioStatus != STATUS_SUCCESS)
{
/* Invoke the delete directory completion routine. */
context->OnDriveDeleteFileComplete(context, irp->CallbackData, ioStatus);
-
/* Destroy the IRP. */
rdpdr_server_irp_free(irp);
-
return CHANNEL_RC_OK;
}
Stream_Read_UINT32(s, fileId); /* FileId (4 bytes) */
Stream_Read_UINT8(s, information); /* Information (1 byte) */
-
/* Setup the IRP. */
irp->CompletionId = context->priv->NextCompletionId++;
irp->Callback = rdpdr_server_drive_delete_directory_callback2;
}
/* Send a request to close the file */
- return rdpdr_server_send_device_close_request(context, deviceId, fileId, irp->CompletionId);
+ return rdpdr_server_send_device_close_request(context, deviceId, fileId,
+ irp->CompletionId);
}
/**
*
* @return 0 on success, otherwise a Win32 error code
*/
-static UINT rdpdr_server_drive_delete_directory(RdpdrServerContext* context, void* callbackData, UINT32 deviceId, const char* path)
+static UINT rdpdr_server_drive_delete_directory(RdpdrServerContext* context,
+ void* callbackData, UINT32 deviceId, const char* path)
{
RDPDR_IRP* irp;
-
irp = rdpdr_server_irp_new();
if (!irp)
irp->CallbackData = callbackData;
irp->DeviceId = deviceId;
strncpy(irp->PathName, path, sizeof(irp->PathName));
-
rdpdr_server_convert_slashes(irp->PathName, sizeof(irp->PathName));
if (!rdpdr_server_enqueue_irp(context, irp))
}
/* Send a request to open the file. */
- return rdpdr_server_send_device_create_request(context, deviceId, irp->CompletionId, irp->PathName,
- DELETE | SYNCHRONIZE, FILE_DIRECTORY_FILE | FILE_DELETE_ON_CLOSE | FILE_SYNCHRONOUS_IO_NONALERT, FILE_OPEN);
+ return rdpdr_server_send_device_create_request(context, deviceId,
+ irp->CompletionId, irp->PathName,
+ DELETE | SYNCHRONIZE, FILE_DIRECTORY_FILE | FILE_DELETE_ON_CLOSE |
+ FILE_SYNCHRONOUS_IO_NONALERT, FILE_OPEN);
}
/*************************************************
*
* @return 0 on success, otherwise a Win32 error code
*/
-static UINT rdpdr_server_drive_query_directory_callback2(RdpdrServerContext* context, wStream* s, RDPDR_IRP* irp, UINT32 deviceId, UINT32 completionId, UINT32 ioStatus)
+static UINT rdpdr_server_drive_query_directory_callback2(
+ RdpdrServerContext* context, wStream* s, RDPDR_IRP* irp, UINT32 deviceId,
+ UINT32 completionId, UINT32 ioStatus)
{
UINT error;
UINT32 length;
FILE_DIRECTORY_INFORMATION fdi;
-
- WLog_DBG(TAG, "RdpdrServerDriveQueryDirectoryCallback2: deviceId=%d, completionId=%d, ioStatus=0x%x",
- deviceId, completionId, ioStatus);
+ WLog_DBG(TAG,
+ "RdpdrServerDriveQueryDirectoryCallback2: deviceId=%d, completionId=%d, ioStatus=0x%x",
+ deviceId, completionId, ioStatus);
if (Stream_GetRemainingLength(s) < 4)
{
{
if ((error = rdpdr_server_read_file_directory_information(s, &fdi)))
{
- WLog_ERR(TAG, "rdpdr_server_read_file_directory_information failed with error %lu!", error);
+ WLog_ERR(TAG,
+ "rdpdr_server_read_file_directory_information failed with error %lu!", error);
return error;
}
}
if (ioStatus == STATUS_SUCCESS)
{
/* Invoke the query directory completion routine. */
- context->OnDriveQueryDirectoryComplete(context, irp->CallbackData, ioStatus, length > 0 ? &fdi : NULL);
-
+ context->OnDriveQueryDirectoryComplete(context, irp->CallbackData, ioStatus,
+ length > 0 ? &fdi : NULL);
/* Setup the IRP. */
irp->CompletionId = context->priv->NextCompletionId++;
irp->Callback = rdpdr_server_drive_query_directory_callback2;
}
/* Send a request to query the directory. */
- return rdpdr_server_send_device_query_directory_request(context, irp->DeviceId, irp->FileId, irp->CompletionId, NULL);
+ return rdpdr_server_send_device_query_directory_request(context, irp->DeviceId,
+ irp->FileId, irp->CompletionId, NULL);
}
else
{
/* Invoke the query directory completion routine. */
- context->OnDriveQueryDirectoryComplete(context, irp->CallbackData, ioStatus, NULL);
-
+ context->OnDriveQueryDirectoryComplete(context, irp->CallbackData, ioStatus,
+ NULL);
/* Destroy the IRP. */
rdpdr_server_irp_free(irp);
}
*
* @return 0 on success, otherwise a Win32 error code
*/
-static UINT rdpdr_server_drive_query_directory_callback1(RdpdrServerContext* context, wStream* s, RDPDR_IRP* irp, UINT32 deviceId, UINT32 completionId, UINT32 ioStatus)
+static UINT rdpdr_server_drive_query_directory_callback1(
+ RdpdrServerContext* context, wStream* s, RDPDR_IRP* irp, UINT32 deviceId,
+ UINT32 completionId, UINT32 ioStatus)
{
UINT32 fileId;
-
- WLog_DBG(TAG, "RdpdrServerDriveQueryDirectoryCallback1: deviceId=%d, completionId=%d, ioStatus=0x%x",
- deviceId, completionId, ioStatus);
+ WLog_DBG(TAG,
+ "RdpdrServerDriveQueryDirectoryCallback1: deviceId=%d, completionId=%d, ioStatus=0x%x",
+ deviceId, completionId, ioStatus);
if (ioStatus != STATUS_SUCCESS)
{
/* Invoke the query directory completion routine. */
- context->OnDriveQueryDirectoryComplete(context, irp->CallbackData, ioStatus, NULL);
-
+ context->OnDriveQueryDirectoryComplete(context, irp->CallbackData, ioStatus,
+ NULL);
/* Destroy the IRP. */
rdpdr_server_irp_free(irp);
-
return CHANNEL_RC_OK;
}
}
Stream_Read_UINT32(s, fileId);
-
/* Setup the IRP. */
irp->CompletionId = context->priv->NextCompletionId++;
irp->Callback = rdpdr_server_drive_query_directory_callback2;
irp->DeviceId = deviceId;
irp->FileId = fileId;
-
strcat(irp->PathName, "\\*.*");
if (!rdpdr_server_enqueue_irp(context, irp))
}
/* Send a request to query the directory. */
- return rdpdr_server_send_device_query_directory_request(context, deviceId, fileId, irp->CompletionId, irp->PathName);
+ return rdpdr_server_send_device_query_directory_request(context, deviceId,
+ fileId, irp->CompletionId, irp->PathName);
}
/**
*
* @return 0 on success, otherwise a Win32 error code
*/
-static UINT rdpdr_server_drive_query_directory(RdpdrServerContext* context, void* callbackData, UINT32 deviceId, const char* path)
+static UINT rdpdr_server_drive_query_directory(RdpdrServerContext* context,
+ void* callbackData, UINT32 deviceId, const char* path)
{
RDPDR_IRP* irp;
-
irp = rdpdr_server_irp_new();
if (!irp)
irp->CallbackData = callbackData;
irp->DeviceId = deviceId;
strncpy(irp->PathName, path, sizeof(irp->PathName));
-
rdpdr_server_convert_slashes(irp->PathName, sizeof(irp->PathName));
if (!rdpdr_server_enqueue_irp(context, irp))
}
/* Send a request to open the directory. */
- return rdpdr_server_send_device_create_request(context, deviceId, irp->CompletionId, irp->PathName,
- FILE_READ_DATA | SYNCHRONIZE, FILE_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT, FILE_OPEN);
+ return rdpdr_server_send_device_create_request(context, deviceId,
+ irp->CompletionId, irp->PathName,
+ FILE_READ_DATA | SYNCHRONIZE,
+ FILE_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT, FILE_OPEN);
}
/*************************************************
*
* @return 0 on success, otherwise a Win32 error code
*/
-static UINT rdpdr_server_drive_open_file_callback(RdpdrServerContext* context, wStream* s, RDPDR_IRP* irp, UINT32 deviceId, UINT32 completionId, UINT32 ioStatus)
+static UINT rdpdr_server_drive_open_file_callback(RdpdrServerContext* context,
+ wStream* s, RDPDR_IRP* irp, UINT32 deviceId, UINT32 completionId,
+ UINT32 ioStatus)
{
UINT32 fileId;
UINT8 information;
-
- WLog_DBG(TAG, "RdpdrServerDriveOpenFileCallback: deviceId=%d, completionId=%d, ioStatus=0x%x",
- deviceId, completionId, ioStatus);
+ WLog_DBG(TAG,
+ "RdpdrServerDriveOpenFileCallback: deviceId=%d, completionId=%d, ioStatus=0x%x",
+ deviceId, completionId, ioStatus);
if (Stream_GetRemainingLength(s) < 5)
{
Stream_Read_UINT32(s, fileId); /* FileId (4 bytes) */
Stream_Read_UINT8(s, information); /* Information (1 byte) */
-
/* Invoke the open file completion routine. */
- context->OnDriveOpenFileComplete(context, irp->CallbackData, ioStatus, deviceId, fileId);
-
+ context->OnDriveOpenFileComplete(context, irp->CallbackData, ioStatus, deviceId,
+ fileId);
/* Destroy the IRP. */
rdpdr_server_irp_free(irp);
-
return CHANNEL_RC_OK;
}
*
* @return 0 on success, otherwise a Win32 error code
*/
-static UINT rdpdr_server_drive_open_file(RdpdrServerContext* context, void* callbackData, UINT32 deviceId, const char* path, UINT32 desiredAccess, UINT32 createDisposition)
+static UINT rdpdr_server_drive_open_file(RdpdrServerContext* context,
+ void* callbackData, UINT32 deviceId, const char* path, UINT32 desiredAccess,
+ UINT32 createDisposition)
{
RDPDR_IRP* irp;
-
irp = rdpdr_server_irp_new();
if (!irp)
irp->CallbackData = callbackData;
irp->DeviceId = deviceId;
strncpy(irp->PathName, path, sizeof(irp->PathName));
-
rdpdr_server_convert_slashes(irp->PathName, sizeof(irp->PathName));
if (!rdpdr_server_enqueue_irp(context, irp))
}
/* Send a request to open the file. */
- return rdpdr_server_send_device_create_request(context, deviceId, irp->CompletionId, irp->PathName,
- desiredAccess | SYNCHRONIZE, FILE_SYNCHRONOUS_IO_NONALERT, createDisposition);
+ return rdpdr_server_send_device_create_request(context, deviceId,
+ irp->CompletionId, irp->PathName,
+ desiredAccess | SYNCHRONIZE, FILE_SYNCHRONOUS_IO_NONALERT, createDisposition);
}
/*************************************************
*
* @return 0 on success, otherwise a Win32 error code
*/
-static UINT rdpdr_server_drive_read_file_callback(RdpdrServerContext* context, wStream* s, RDPDR_IRP* irp, UINT32 deviceId, UINT32 completionId, UINT32 ioStatus)
+static UINT rdpdr_server_drive_read_file_callback(RdpdrServerContext* context,
+ wStream* s, RDPDR_IRP* irp, UINT32 deviceId, UINT32 completionId,
+ UINT32 ioStatus)
{
UINT32 length;
char* buffer = NULL;
-
- WLog_DBG(TAG, "RdpdrServerDriveReadFileCallback: deviceId=%d, completionId=%d, ioStatus=0x%x",
- deviceId, completionId, ioStatus);
+ WLog_DBG(TAG,
+ "RdpdrServerDriveReadFileCallback: deviceId=%d, completionId=%d, ioStatus=0x%x",
+ deviceId, completionId, ioStatus);
if (Stream_GetRemainingLength(s) < 4)
{
}
/* Invoke the read file completion routine. */
- context->OnDriveReadFileComplete(context, irp->CallbackData, ioStatus, buffer, length);
-
+ context->OnDriveReadFileComplete(context, irp->CallbackData, ioStatus, buffer,
+ length);
/* Destroy the IRP. */
rdpdr_server_irp_free(irp);
-
return CHANNEL_RC_OK;
}
*
* @return 0 on success, otherwise a Win32 error code
*/
-static UINT rdpdr_server_drive_read_file(RdpdrServerContext* context, void* callbackData, UINT32 deviceId, UINT32 fileId, UINT32 length, UINT32 offset)
+static UINT rdpdr_server_drive_read_file(RdpdrServerContext* context,
+ void* callbackData, UINT32 deviceId, UINT32 fileId, UINT32 length,
+ UINT32 offset)
{
RDPDR_IRP* irp;
-
irp = rdpdr_server_irp_new();
if (!irp)
}
/* Send a request to open the directory. */
- return rdpdr_server_send_device_read_request(context, deviceId, fileId, irp->CompletionId, length, offset);
+ return rdpdr_server_send_device_read_request(context, deviceId, fileId,
+ irp->CompletionId, length, offset);
}
/*************************************************
*
* @return 0 on success, otherwise a Win32 error code
*/
-static UINT rdpdr_server_drive_write_file_callback(RdpdrServerContext* context, wStream* s, RDPDR_IRP* irp, UINT32 deviceId, UINT32 completionId, UINT32 ioStatus)
+static UINT rdpdr_server_drive_write_file_callback(RdpdrServerContext* context,
+ wStream* s, RDPDR_IRP* irp, UINT32 deviceId, UINT32 completionId,
+ UINT32 ioStatus)
{
UINT32 length;
-
- WLog_DBG(TAG, "RdpdrServerDriveWriteFileCallback: deviceId=%d, completionId=%d, ioStatus=0x%x",
- deviceId, completionId, ioStatus);
+ WLog_DBG(TAG,
+ "RdpdrServerDriveWriteFileCallback: deviceId=%d, completionId=%d, ioStatus=0x%x",
+ deviceId, completionId, ioStatus);
if (Stream_GetRemainingLength(s) < 5)
{
/* Invoke the write file completion routine. */
context->OnDriveWriteFileComplete(context, irp->CallbackData, ioStatus, length);
-
/* Destroy the IRP. */
rdpdr_server_irp_free(irp);
-
return CHANNEL_RC_OK;
}
*
* @return 0 on success, otherwise a Win32 error code
*/
-static UINT rdpdr_server_drive_write_file(RdpdrServerContext* context, void* callbackData, UINT32 deviceId, UINT32 fileId, const char* buffer, UINT32 length, UINT32 offset)
+static UINT rdpdr_server_drive_write_file(RdpdrServerContext* context,
+ void* callbackData, UINT32 deviceId, UINT32 fileId, const char* buffer,
+ UINT32 length, UINT32 offset)
{
RDPDR_IRP* irp;
-
irp = rdpdr_server_irp_new();
if (!irp)
}
/* Send a request to open the directory. */
- return rdpdr_server_send_device_write_request(context, deviceId, fileId, irp->CompletionId, buffer, length, offset);
+ return rdpdr_server_send_device_write_request(context, deviceId, fileId,
+ irp->CompletionId, buffer, length, offset);
}
/*************************************************
*
* @return 0 on success, otherwise a Win32 error code
*/
-static UINT rdpdr_server_drive_close_file_callback(RdpdrServerContext* context, wStream* s, RDPDR_IRP* irp, UINT32 deviceId, UINT32 completionId, UINT32 ioStatus)
+static UINT rdpdr_server_drive_close_file_callback(RdpdrServerContext* context,
+ wStream* s, RDPDR_IRP* irp, UINT32 deviceId, UINT32 completionId,
+ UINT32 ioStatus)
{
- WLog_DBG(TAG, "RdpdrServerDriveCloseFileCallback: deviceId=%d, completionId=%d, ioStatus=0x%x",
- deviceId, completionId, ioStatus);
-
+ WLog_DBG(TAG,
+ "RdpdrServerDriveCloseFileCallback: deviceId=%d, completionId=%d, ioStatus=0x%x",
+ deviceId, completionId, ioStatus);
/* Invoke the close file completion routine. */
context->OnDriveCloseFileComplete(context, irp->CallbackData, ioStatus);
-
/* Destroy the IRP. */
rdpdr_server_irp_free(irp);
-
return CHANNEL_RC_OK;
}
*
* @return 0 on success, otherwise a Win32 error code
*/
-static UINT rdpdr_server_drive_close_file(RdpdrServerContext* context, void* callbackData, UINT32 deviceId, UINT32 fileId)
+static UINT rdpdr_server_drive_close_file(RdpdrServerContext* context,
+ void* callbackData, UINT32 deviceId, UINT32 fileId)
{
RDPDR_IRP* irp;
-
irp = rdpdr_server_irp_new();
if (!irp)
}
/* Send a request to open the directory. */
- return rdpdr_server_send_device_close_request(context, deviceId, fileId, irp->CompletionId);
+ return rdpdr_server_send_device_close_request(context, deviceId, fileId,
+ irp->CompletionId);
}
/*************************************************
*
* @return 0 on success, otherwise a Win32 error code
*/
-static UINT rdpdr_server_drive_delete_file_callback2(RdpdrServerContext* context, wStream* s, RDPDR_IRP* irp, UINT32 deviceId, UINT32 completionId, UINT32 ioStatus)
+static UINT rdpdr_server_drive_delete_file_callback2(RdpdrServerContext*
+ context, wStream* s, RDPDR_IRP* irp, UINT32 deviceId, UINT32 completionId,
+ UINT32 ioStatus)
{
- WLog_DBG(TAG, "RdpdrServerDriveDeleteFileCallback2: deviceId=%d, completionId=%d, ioStatus=0x%x",
- deviceId, completionId, ioStatus);
-
+ WLog_DBG(TAG,
+ "RdpdrServerDriveDeleteFileCallback2: deviceId=%d, completionId=%d, ioStatus=0x%x",
+ deviceId, completionId, ioStatus);
/* Invoke the delete file completion routine. */
context->OnDriveDeleteFileComplete(context, irp->CallbackData, ioStatus);
-
/* Destroy the IRP. */
rdpdr_server_irp_free(irp);
-
return CHANNEL_RC_OK;
}
*
* @return 0 on success, otherwise a Win32 error code
*/
-static UINT rdpdr_server_drive_delete_file_callback1(RdpdrServerContext* context, wStream* s, RDPDR_IRP* irp, UINT32 deviceId, UINT32 completionId, UINT32 ioStatus)
+static UINT rdpdr_server_drive_delete_file_callback1(RdpdrServerContext*
+ context, wStream* s, RDPDR_IRP* irp, UINT32 deviceId, UINT32 completionId,
+ UINT32 ioStatus)
{
UINT32 fileId;
UINT8 information;
-
- WLog_DBG(TAG, "RdpdrServerDriveDeleteFileCallback1: deviceId=%d, completionId=%d, ioStatus=0x%x",
- deviceId, completionId, ioStatus);
+ WLog_DBG(TAG,
+ "RdpdrServerDriveDeleteFileCallback1: deviceId=%d, completionId=%d, ioStatus=0x%x",
+ deviceId, completionId, ioStatus);
if (ioStatus != STATUS_SUCCESS)
{
/* Invoke the close file completion routine. */
context->OnDriveDeleteFileComplete(context, irp->CallbackData, ioStatus);
-
/* Destroy the IRP. */
rdpdr_server_irp_free(irp);
-
return CHANNEL_RC_OK;
}
Stream_Read_UINT32(s, fileId); /* FileId (4 bytes) */
Stream_Read_UINT8(s, information); /* Information (1 byte) */
-
/* Setup the IRP. */
irp->CompletionId = context->priv->NextCompletionId++;
irp->Callback = rdpdr_server_drive_delete_file_callback2;
}
/* Send a request to close the file */
- return rdpdr_server_send_device_close_request(context, deviceId, fileId, irp->CompletionId);
+ return rdpdr_server_send_device_close_request(context, deviceId, fileId,
+ irp->CompletionId);
}
/**
*
* @return 0 on success, otherwise a Win32 error code
*/
-static UINT rdpdr_server_drive_delete_file(RdpdrServerContext* context, void* callbackData, UINT32 deviceId, const char* path)
+static UINT rdpdr_server_drive_delete_file(RdpdrServerContext* context,
+ void* callbackData, UINT32 deviceId, const char* path)
{
RDPDR_IRP* irp;
-
irp = rdpdr_server_irp_new();
if (!irp)
irp->CallbackData = callbackData;
irp->DeviceId = deviceId;
strncpy(irp->PathName, path, sizeof(irp->PathName));
-
rdpdr_server_convert_slashes(irp->PathName, sizeof(irp->PathName));
if (!rdpdr_server_enqueue_irp(context, irp))
}
/* Send a request to open the file. */
- return rdpdr_server_send_device_create_request(context, deviceId, irp->CompletionId, irp->PathName,
- FILE_READ_DATA | SYNCHRONIZE, FILE_DELETE_ON_CLOSE | FILE_SYNCHRONOUS_IO_NONALERT, FILE_OPEN);
-
+ return rdpdr_server_send_device_create_request(context, deviceId,
+ irp->CompletionId, irp->PathName,
+ FILE_READ_DATA | SYNCHRONIZE,
+ FILE_DELETE_ON_CLOSE | FILE_SYNCHRONOUS_IO_NONALERT, FILE_OPEN);
}
/*************************************************
*
* @return 0 on success, otherwise a Win32 error code
*/
-static UINT rdpdr_server_drive_rename_file_callback3(RdpdrServerContext* context, wStream* s, RDPDR_IRP* irp, UINT32 deviceId, UINT32 completionId, UINT32 ioStatus)
+static UINT rdpdr_server_drive_rename_file_callback3(RdpdrServerContext*
+ context, wStream* s, RDPDR_IRP* irp, UINT32 deviceId, UINT32 completionId,
+ UINT32 ioStatus)
{
- WLog_DBG(TAG, "RdpdrServerDriveRenameFileCallback3: deviceId=%d, completionId=%d, ioStatus=0x%x",
- deviceId, completionId, ioStatus);
-
+ WLog_DBG(TAG,
+ "RdpdrServerDriveRenameFileCallback3: deviceId=%d, completionId=%d, ioStatus=0x%x",
+ deviceId, completionId, ioStatus);
/* Destroy the IRP. */
rdpdr_server_irp_free(irp);
-
return CHANNEL_RC_OK;
}
*
* @return 0 on success, otherwise a Win32 error code
*/
-static UINT rdpdr_server_drive_rename_file_callback2(RdpdrServerContext* context, wStream* s, RDPDR_IRP* irp, UINT32 deviceId, UINT32 completionId, UINT32 ioStatus)
+static UINT rdpdr_server_drive_rename_file_callback2(RdpdrServerContext*
+ context, wStream* s, RDPDR_IRP* irp, UINT32 deviceId, UINT32 completionId,
+ UINT32 ioStatus)
{
UINT32 length;
-
- WLog_DBG(TAG, "RdpdrServerDriveRenameFileCallback2: deviceId=%d, completionId=%d, ioStatus=0x%x",
- deviceId, completionId, ioStatus);
+ WLog_DBG(TAG,
+ "RdpdrServerDriveRenameFileCallback2: deviceId=%d, completionId=%d, ioStatus=0x%x",
+ deviceId, completionId, ioStatus);
if (Stream_GetRemainingLength(s) < 5)
{
Stream_Read_UINT32(s, length); /* Length (4 bytes) */
Stream_Seek(s, 1); /* Padding (1 byte) */
-
/* Invoke the rename file completion routine. */
context->OnDriveRenameFileComplete(context, irp->CallbackData, ioStatus);
-
/* Setup the IRP. */
irp->CompletionId = context->priv->NextCompletionId++;
irp->Callback = rdpdr_server_drive_rename_file_callback3;
}
/* Send a request to close the file */
- return rdpdr_server_send_device_close_request(context, deviceId, irp->FileId, irp->CompletionId);
+ return rdpdr_server_send_device_close_request(context, deviceId, irp->FileId,
+ irp->CompletionId);
}
/**
*
* @return 0 on success, otherwise a Win32 error code
*/
-static UINT rdpdr_server_drive_rename_file_callback1(RdpdrServerContext* context, wStream* s, RDPDR_IRP* irp, UINT32 deviceId, UINT32 completionId, UINT32 ioStatus)
+static UINT rdpdr_server_drive_rename_file_callback1(RdpdrServerContext*
+ context, wStream* s, RDPDR_IRP* irp, UINT32 deviceId, UINT32 completionId,
+ UINT32 ioStatus)
{
UINT32 fileId;
UINT8 information;
-
- WLog_DBG(TAG, "RdpdrServerDriveRenameFileCallback1: deviceId=%d, completionId=%d, ioStatus=0x%x",
- deviceId, completionId, ioStatus);
+ WLog_DBG(TAG,
+ "RdpdrServerDriveRenameFileCallback1: deviceId=%d, completionId=%d, ioStatus=0x%x",
+ deviceId, completionId, ioStatus);
if (ioStatus != STATUS_SUCCESS)
{
/* Invoke the rename file completion routine. */
context->OnDriveRenameFileComplete(context, irp->CallbackData, ioStatus);
-
/* Destroy the IRP. */
rdpdr_server_irp_free(irp);
-
return CHANNEL_RC_OK;
}
Stream_Read_UINT32(s, fileId); /* FileId (4 bytes) */
Stream_Read_UINT8(s, information); /* Information (1 byte) */
-
/* Setup the IRP. */
irp->CompletionId = context->priv->NextCompletionId++;
irp->Callback = rdpdr_server_drive_rename_file_callback2;
}
/* Send a request to rename the file */
- return rdpdr_server_send_device_file_rename_request(context, deviceId, fileId, irp->CompletionId, irp->ExtraBuffer);
+ return rdpdr_server_send_device_file_rename_request(context, deviceId, fileId,
+ irp->CompletionId, irp->ExtraBuffer);
}
/**
*
* @return 0 on success, otherwise a Win32 error code
*/
-static UINT rdpdr_server_drive_rename_file(RdpdrServerContext* context, void* callbackData, UINT32 deviceId, const char* oldPath, const char* newPath)
+static UINT rdpdr_server_drive_rename_file(RdpdrServerContext* context,
+ void* callbackData, UINT32 deviceId, const char* oldPath, const char* newPath)
{
RDPDR_IRP* irp;
-
irp = rdpdr_server_irp_new();
if (!irp)
irp->DeviceId = deviceId;
strncpy(irp->PathName, oldPath, sizeof(irp->PathName));
strncpy(irp->ExtraBuffer, newPath, sizeof(irp->ExtraBuffer));
-
rdpdr_server_convert_slashes(irp->PathName, sizeof(irp->PathName));
rdpdr_server_convert_slashes(irp->ExtraBuffer, sizeof(irp->ExtraBuffer));
}
/* Send a request to open the file. */
- return rdpdr_server_send_device_create_request(context, deviceId, irp->CompletionId, irp->PathName,
- FILE_READ_DATA | SYNCHRONIZE, FILE_SYNCHRONOUS_IO_NONALERT, FILE_OPEN);
+ return rdpdr_server_send_device_create_request(context, deviceId,
+ irp->CompletionId, irp->PathName,
+ FILE_READ_DATA | SYNCHRONIZE, FILE_SYNCHRONOUS_IO_NONALERT, FILE_OPEN);
}
RdpdrServerContext* rdpdr_server_context_new(HANDLE vcm)
{
RdpdrServerContext* context;
-
context = (RdpdrServerContext*) calloc(1, sizeof(RdpdrServerContext));
if (context)
{
context->vcm = vcm;
-
context->Start = rdpdr_server_start;
context->Stop = rdpdr_server_stop;
-
context->DriveCreateDirectory = rdpdr_server_drive_create_directory;
context->DriveDeleteDirectory = rdpdr_server_drive_delete_directory;
context->DriveQueryDirectory = rdpdr_server_drive_query_directory;
context->DriveCloseFile = rdpdr_server_drive_close_file;
context->DriveDeleteFile = rdpdr_server_drive_delete_file;
context->DriveRenameFile = rdpdr_server_drive_rename_file;
-
context->priv = (RdpdrServerPrivate*) calloc(1, sizeof(RdpdrServerPrivate));
if (!context->priv)
context->priv->ClientId = g_ClientId++;
context->priv->UserLoggedOnPdu = TRUE;
context->priv->NextCompletionId = 1;
-
context->priv->IrpList = ListDictionary_New(TRUE);
if (!context->priv->IrpList)
if (context->priv)
{
ListDictionary_Free(context->priv->IrpList);
-
free(context->priv);
}
int i;
RDPINPUT_CONTACT_DATA* contact;
RDPEI_PLUGIN* rdpei = (RDPEI_PLUGIN*) context->handle;
-
rdpei->frame.contactCount = 0;
for (i = 0; i < rdpei->maxTouchContacts; i++)
{
- contact = (RDPINPUT_CONTACT_DATA*) &(rdpei->contactPoints[i].data);
+ contact = (RDPINPUT_CONTACT_DATA*) & (rdpei->contactPoints[i].data);
if (rdpei->contactPoints[i].dirty)
{
- CopyMemory(&(rdpei->contacts[rdpei->frame.contactCount]), contact, sizeof(RDPINPUT_CONTACT_DATA));
+ CopyMemory(&(rdpei->contacts[rdpei->frame.contactCount]), contact,
+ sizeof(RDPINPUT_CONTACT_DATA));
rdpei->contactPoints[i].dirty = FALSE;
rdpei->frame.contactCount++;
}
contact->contactFlags |= CONTACT_FLAG_INCONTACT;
}
- CopyMemory(&(rdpei->contacts[rdpei->frame.contactCount]), contact, sizeof(RDPINPUT_CONTACT_DATA));
+ CopyMemory(&(rdpei->contacts[rdpei->frame.contactCount]), contact,
+ sizeof(RDPINPUT_CONTACT_DATA));
rdpei->frame.contactCount++;
}
}
RdpeiClientContext* context = (RdpeiClientContext*) rdpei->iface.pInterface;
HANDLE hdl[] = {rdpei->event, rdpei->stopEvent};
UINT error = CHANNEL_RC_OK;
-
freerdp_channel_init_thread_context(rdpei->rdpcontext);
+
if (!rdpei)
{
error = ERROR_INVALID_PARAMETER;
goto out;
}
-
if (!context)
{
error = ERROR_INVALID_PARAMETER;
{
status = WaitForMultipleObjects(2, hdl, FALSE, 20);
- if (status == WAIT_FAILED)
- {
- error = GetLastError();
- WLog_ERR(TAG, "WaitForMultipleObjects failed with error %lu!", error);
- break;
- }
+ if (status == WAIT_FAILED)
+ {
+ error = GetLastError();
+ WLog_ERR(TAG, "WaitForMultipleObjects failed with error %lu!", error);
+ break;
+ }
if (status == WAIT_OBJECT_0 + 1)
break;
}
out:
+
if (error && rdpei->rdpcontext)
- setChannelError(rdpei->rdpcontext, error, "rdpei_schedule_thread reported an error");
+ setChannelError(rdpei->rdpcontext, error,
+ "rdpei_schedule_thread reported an error");
ExitThread(0);
-
return NULL;
}
*
* @return 0 on success, otherwise a Win32 error code
*/
-UINT rdpei_send_pdu(RDPEI_CHANNEL_CALLBACK* callback, wStream* s, UINT16 eventId, UINT32 pduLength)
+UINT rdpei_send_pdu(RDPEI_CHANNEL_CALLBACK* callback, wStream* s,
+ UINT16 eventId, UINT32 pduLength)
{
UINT status;
-
Stream_SetPosition(s, 0);
Stream_Write_UINT16(s, eventId); /* eventId (2 bytes) */
Stream_Write_UINT32(s, pduLength); /* pduLength (4 bytes) */
Stream_SetPosition(s, Stream_Length(s));
-
- status = callback->channel->Write(callback->channel, (UINT32) Stream_Length(s), Stream_Buffer(s), NULL);
-
+ status = callback->channel->Write(callback->channel, (UINT32) Stream_Length(s),
+ Stream_Buffer(s), NULL);
#ifdef WITH_DEBUG_RDPEI
WLog_DBG(TAG, "rdpei_send_pdu: eventId: %d (%s) length: %d status: %d",
- eventId, RDPEI_EVENTID_STRINGS[eventId], pduLength, status);
+ eventId, RDPEI_EVENTID_STRINGS[eventId], pduLength, status);
#endif
-
return status;
}
UINT32 flags;
UINT32 pduLength;
RDPEI_PLUGIN* rdpei = (RDPEI_PLUGIN*) callback->plugin;
-
flags = 0;
flags |= READY_FLAGS_SHOW_TOUCH_VISUALS;
//flags |= READY_FLAGS_DISABLE_TIMESTAMP_INJECTION;
-
pduLength = RDPINPUT_HEADER_LENGTH + 10;
s = Stream_New(NULL, pduLength);
+
if (!s)
{
WLog_ERR(TAG, "Stream_New failed!");
return CHANNEL_RC_NO_MEMORY;
}
- Stream_Seek(s, RDPINPUT_HEADER_LENGTH);
+ Stream_Seek(s, RDPINPUT_HEADER_LENGTH);
Stream_Write_UINT32(s, flags); /* flags (4 bytes) */
Stream_Write_UINT32(s, RDPINPUT_PROTOCOL_V10); /* protocolVersion (4 bytes) */
- Stream_Write_UINT16(s, rdpei->maxTouchContacts); /* maxTouchContacts (2 bytes) */
-
+ Stream_Write_UINT16(s,
+ rdpei->maxTouchContacts); /* maxTouchContacts (2 bytes) */
Stream_SealLength(s);
-
status = rdpei_send_pdu(callback, s, EVENTID_CS_READY, pduLength);
Stream_Free(s, TRUE);
-
return status;
}
UINT32 index;
int rectSize = 2;
RDPINPUT_CONTACT_DATA* contact;
-
#ifdef WITH_DEBUG_RDPEI
WLog_DBG(TAG, "contactCount: %d", frame->contactCount);
WLog_DBG(TAG, "frameOffset: 0x%08X", (UINT32) frame->frameOffset);
#endif
-
- rdpei_write_2byte_unsigned(s, frame->contactCount); /* contactCount (TWO_BYTE_UNSIGNED_INTEGER) */
-
+ rdpei_write_2byte_unsigned(s,
+ frame->contactCount); /* contactCount (TWO_BYTE_UNSIGNED_INTEGER) */
/**
* the time offset from the previous frame (in microseconds).
* If this is the first frame being transmitted then this field MUST be set to zero.
*/
- rdpei_write_8byte_unsigned(s, frame->frameOffset * 1000); /* frameOffset (EIGHT_BYTE_UNSIGNED_INTEGER) */
+ rdpei_write_8byte_unsigned(s,
+ frame->frameOffset * 1000); /* frameOffset (EIGHT_BYTE_UNSIGNED_INTEGER) */
if (!Stream_EnsureRemainingCapacity(s, (size_t) frame->contactCount * 64))
{
for (index = 0; index < frame->contactCount; index++)
{
contact = &frame->contacts[index];
-
contact->fieldsPresent |= CONTACT_DATA_CONTACTRECT_PRESENT;
contact->contactRectLeft = contact->x - rectSize;
contact->contactRectTop = contact->y - rectSize;
contact->contactRectRight = contact->x + rectSize;
contact->contactRectBottom = contact->y + rectSize;
-
#ifdef WITH_DEBUG_RDPEI
WLog_DBG(TAG, "contact[%d].contactId: %d", index, contact->contactId);
WLog_DBG(TAG, "contact[%d].fieldsPresent: %d", index, contact->fieldsPresent);
WLog_DBG(TAG, "contact[%d].contactFlags: 0x%04X", index, contact->contactFlags);
rdpei_print_contact_flags(contact->contactFlags);
#endif
-
Stream_Write_UINT8(s, contact->contactId); /* contactId (1 byte) */
-
/* fieldsPresent (TWO_BYTE_UNSIGNED_INTEGER) */
rdpei_write_2byte_unsigned(s, contact->fieldsPresent);
-
rdpei_write_4byte_signed(s, contact->x); /* x (FOUR_BYTE_SIGNED_INTEGER) */
rdpei_write_4byte_signed(s, contact->y); /* y (FOUR_BYTE_SIGNED_INTEGER) */
-
/* contactFlags (FOUR_BYTE_UNSIGNED_INTEGER) */
rdpei_write_4byte_unsigned(s, contact->contactFlags);
*
* @return 0 on success, otherwise a Win32 error code
*/
-UINT rdpei_send_touch_event_pdu(RDPEI_CHANNEL_CALLBACK* callback, RDPINPUT_TOUCH_FRAME* frame)
+UINT rdpei_send_touch_event_pdu(RDPEI_CHANNEL_CALLBACK* callback,
+ RDPINPUT_TOUCH_FRAME* frame)
{
UINT status;
wStream* s;
UINT32 pduLength;
-
pduLength = 64 + (frame->contactCount * 64);
-
s = Stream_New(NULL, pduLength);
+
if (!s)
{
WLog_ERR(TAG, "Stream_New failed!");
return CHANNEL_RC_NO_MEMORY;
}
- Stream_Seek(s, RDPINPUT_HEADER_LENGTH);
+ Stream_Seek(s, RDPINPUT_HEADER_LENGTH);
/**
* the time that has elapsed (in milliseconds) from when the oldest touch frame
* was generated to when it was encoded for transmission by the client.
*/
- rdpei_write_4byte_unsigned(s, (UINT32) frame->frameOffset); /* encodeTime (FOUR_BYTE_UNSIGNED_INTEGER) */
-
+ rdpei_write_4byte_unsigned(s,
+ (UINT32) frame->frameOffset); /* encodeTime (FOUR_BYTE_UNSIGNED_INTEGER) */
rdpei_write_2byte_unsigned(s, 1); /* (frameCount) TWO_BYTE_UNSIGNED_INTEGER */
if ((status = rdpei_write_touch_frame(s, frame)))
Stream_SealLength(s);
pduLength = Stream_Length(s);
-
status = rdpei_send_pdu(callback, s, EVENTID_TOUCH, pduLength);
Stream_Free(s, TRUE);
-
return status;
}
UINT rdpei_recv_sc_ready_pdu(RDPEI_CHANNEL_CALLBACK* callback, wStream* s)
{
UINT32 protocolVersion;
-
Stream_Read_UINT32(s, protocolVersion); /* protocolVersion (4 bytes) */
-
#if 0
+
if (protocolVersion != RDPINPUT_PROTOCOL_V10)
{
WLog_ERR(TAG, "Unknown [MS-RDPEI] protocolVersion: 0x%08X", protocolVersion);
return -1;
}
-#endif
+#endif
return CHANNEL_RC_OK;
}
{
RdpeiClientContext* rdpei = (RdpeiClientContext*) callback->plugin->pInterface;
UINT error = CHANNEL_RC_OK;
-
IFCALLRET(rdpei->SuspendTouch, error, rdpei);
+
if (error)
WLog_ERR(TAG, "rdpei->SuspendTouch failed with error %lu!", error);
{
RdpeiClientContext* rdpei = (RdpeiClientContext*) callback->plugin->pInterface;
UINT error = CHANNEL_RC_OK;
-
IFCALLRET(rdpei->ResumeTouch, error, rdpei);
+
if (error)
WLog_ERR(TAG, "rdpei->ResumeTouch failed with error %lu!", error);
UINT16 eventId;
UINT32 pduLength;
UINT error;
-
Stream_Read_UINT16(s, eventId); /* eventId (2 bytes) */
Stream_Read_UINT32(s, pduLength); /* pduLength (4 bytes) */
-
#ifdef WITH_DEBUG_RDPEI
WLog_DBG(TAG, "rdpei_recv_pdu: eventId: %d (%s) length: %d",
- eventId, RDPEI_EVENTID_STRINGS[eventId], pduLength);
+ eventId, RDPEI_EVENTID_STRINGS[eventId], pduLength);
#endif
switch (eventId)
WLog_ERR(TAG, "rdpei_recv_sc_ready_pdu failed with error %lu!", error);
return error;
}
+
if ((error = rdpei_send_cs_ready_pdu(callback)))
{
WLog_ERR(TAG, "rdpei_send_cs_ready_pdu failed with error %lu!", error);
return error;
}
+
break;
case EVENTID_SUSPEND_TOUCH:
WLog_ERR(TAG, "rdpei_recv_suspend_touch_pdu failed with error %lu!", error);
return error;
}
+
break;
case EVENTID_RESUME_TOUCH:
WLog_ERR(TAG, "rdpei_recv_resume_touch_pdu failed with error %lu!", error);
return error;
}
+
break;
default:
*
* @return 0 on success, otherwise a Win32 error code
*/
-static UINT rdpei_on_data_received(IWTSVirtualChannelCallback* pChannelCallback, wStream *data)
+static UINT rdpei_on_data_received(IWTSVirtualChannelCallback* pChannelCallback,
+ wStream* data)
{
RDPEI_CHANNEL_CALLBACK* callback = (RDPEI_CHANNEL_CALLBACK*) pChannelCallback;
-
return rdpei_recv_pdu(callback, data);
}
static UINT rdpei_on_close(IWTSVirtualChannelCallback* pChannelCallback)
{
RDPEI_CHANNEL_CALLBACK* callback = (RDPEI_CHANNEL_CALLBACK*) pChannelCallback;
-
free(callback);
-
return CHANNEL_RC_OK;
}
*
* @return 0 on success, otherwise a Win32 error code
*/
-static UINT rdpei_on_new_channel_connection(IWTSListenerCallback* pListenerCallback,
- IWTSVirtualChannel* pChannel, BYTE* Data, BOOL* pbAccept,
- IWTSVirtualChannelCallback** ppCallback)
+static UINT rdpei_on_new_channel_connection(IWTSListenerCallback*
+ pListenerCallback,
+ IWTSVirtualChannel* pChannel, BYTE* Data, BOOL* pbAccept,
+ IWTSVirtualChannelCallback** ppCallback)
{
RDPEI_CHANNEL_CALLBACK* callback;
- RDPEI_LISTENER_CALLBACK* listener_callback = (RDPEI_LISTENER_CALLBACK*) pListenerCallback;
-
+ RDPEI_LISTENER_CALLBACK* listener_callback = (RDPEI_LISTENER_CALLBACK*)
+ pListenerCallback;
callback = (RDPEI_CHANNEL_CALLBACK*) calloc(1, sizeof(RDPEI_CHANNEL_CALLBACK));
+
if (!callback)
{
- WLog_ERR(TAG,"calloc failed!");
+ WLog_ERR(TAG, "calloc failed!");
return CHANNEL_RC_NO_MEMORY;
}
callback->channel_mgr = listener_callback->channel_mgr;
callback->channel = pChannel;
listener_callback->channel_callback = callback;
-
*ppCallback = (IWTSVirtualChannelCallback*) callback;
-
return CHANNEL_RC_OK;
}
*
* @return 0 on success, otherwise a Win32 error code
*/
-static UINT rdpei_plugin_initialize(IWTSPlugin* pPlugin, IWTSVirtualChannelManager* pChannelMgr)
+static UINT rdpei_plugin_initialize(IWTSPlugin* pPlugin,
+ IWTSVirtualChannelManager* pChannelMgr)
{
UINT error;
RDPEI_PLUGIN* rdpei = (RDPEI_PLUGIN*) pPlugin;
+ rdpei->listener_callback = (RDPEI_LISTENER_CALLBACK*) calloc(1 ,
+ sizeof(RDPEI_LISTENER_CALLBACK));
- rdpei->listener_callback = (RDPEI_LISTENER_CALLBACK*) calloc(1 ,sizeof(RDPEI_LISTENER_CALLBACK));
if (!rdpei->listener_callback)
{
WLog_ERR(TAG, "calloc failed!");
return CHANNEL_RC_NO_MEMORY;
}
- rdpei->listener_callback->iface.OnNewChannelConnection = rdpei_on_new_channel_connection;
+ rdpei->listener_callback->iface.OnNewChannelConnection =
+ rdpei_on_new_channel_connection;
rdpei->listener_callback->plugin = pPlugin;
rdpei->listener_callback->channel_mgr = pChannelMgr;
if ((error = pChannelMgr->CreateListener(pChannelMgr, RDPEI_DVC_CHANNEL_NAME, 0,
- (IWTSListenerCallback*) rdpei->listener_callback, &(rdpei->listener))))
+ (IWTSListenerCallback*) rdpei->listener_callback, &(rdpei->listener))))
{
WLog_ERR(TAG, "ChannelMgr->CreateListener failed with error %lu!", error);
goto error_out;
}
rdpei->listener->pInterface = rdpei->iface.pInterface;
-
InitializeCriticalSection(&rdpei->lock);
+
if (!(rdpei->event = CreateEvent(NULL, TRUE, FALSE, NULL)))
{
WLog_ERR(TAG, "CreateEvent failed!");
goto error_out;
-
}
if (!(rdpei->stopEvent = CreateEvent(NULL, TRUE, FALSE, NULL)))
{
WLog_ERR(TAG, "CreateEvent failed!");
goto error_out;
-
}
if (!(rdpei->thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)
- rdpei_schedule_thread, (void*) rdpei, 0, NULL)))
+ rdpei_schedule_thread, (void*) rdpei, 0, NULL)))
{
WLog_ERR(TAG, "CreateThread failed!");
goto error_out;
-
}
return error;
static UINT rdpei_plugin_terminated(IWTSPlugin* pPlugin)
{
RDPEI_PLUGIN* rdpei = (RDPEI_PLUGIN*) pPlugin;
- UINT error;
+ UINT error;
if (!pPlugin)
return ERROR_INVALID_PARAMETER;
EnterCriticalSection(&rdpei->lock);
if (WaitForSingleObject(rdpei->thread, INFINITE) == WAIT_FAILED)
- {
- error = GetLastError();
- WLog_ERR(TAG, "WaitForSingleObject failed with error %lu!", error);
- return error;
- }
+ {
+ error = GetLastError();
+ WLog_ERR(TAG, "WaitForSingleObject failed with error %lu!", error);
+ return error;
+ }
CloseHandle(rdpei->stopEvent);
CloseHandle(rdpei->event);
CloseHandle(rdpei->thread);
-
DeleteCriticalSection(&rdpei->lock);
-
free(rdpei->listener_callback);
free(rdpei->context);
free(rdpei);
-
return CHANNEL_RC_OK;
}
RDPEI_PLUGIN* rdpei = (RDPEI_PLUGIN*) context->handle;
RDPEI_CHANNEL_CALLBACK* callback = rdpei->listener_callback->channel_callback;
UINT error;
-
currentTime = GetTickCount64();
if (!rdpei->previousFrameTime && !rdpei->currentFrameTime)
WLog_ERR(TAG, "rdpei_send_touch_event_pdu failed with error %lu!", error);
return error;
}
+
rdpei->previousFrameTime = rdpei->currentFrameTime;
rdpei->frame.contactCount = 0;
-
return error;
}
*
* @return 0 on success, otherwise a Win32 error code
*/
-UINT rdpei_add_contact(RdpeiClientContext* context, RDPINPUT_CONTACT_DATA* contact)
+UINT rdpei_add_contact(RdpeiClientContext* context,
+ RDPINPUT_CONTACT_DATA* contact)
{
RDPINPUT_CONTACT_POINT* contactPoint;
RDPEI_PLUGIN* rdpei = (RDPEI_PLUGIN*) context->handle;
-
EnterCriticalSection(&rdpei->lock);
-
- contactPoint = (RDPINPUT_CONTACT_POINT*) &rdpei->contactPoints[contact->contactId];
+ contactPoint = (RDPINPUT_CONTACT_POINT*)
+ &rdpei->contactPoints[contact->contactId];
CopyMemory(&(contactPoint->data), contact, sizeof(RDPINPUT_CONTACT_DATA));
contactPoint->dirty = TRUE;
-
SetEvent(rdpei->event);
-
LeaveCriticalSection(&rdpei->lock);
-
return CHANNEL_RC_OK;
}
*
* @return 0 on success, otherwise a Win32 error code
*/
-UINT rdpei_touch_begin(RdpeiClientContext* context, int externalId, int x, int y, int* contactId)
+UINT rdpei_touch_begin(RdpeiClientContext* context, int externalId, int x,
+ int y, int* contactId)
{
unsigned int i;
int contactIdlocal = -1;
if (contactIdlocal >= 0)
{
ZeroMemory(&contact, sizeof(RDPINPUT_CONTACT_DATA));
-
contactPoint->lastX = x;
contactPoint->lastY = y;
-
contact.x = x;
contact.y = y;
contact.contactId = (UINT32) contactIdlocal;
-
contact.contactFlags |= CONTACT_FLAG_DOWN;
contact.contactFlags |= CONTACT_FLAG_INRANGE;
contact.contactFlags |= CONTACT_FLAG_INCONTACT;
-
error = context->AddContact(context, &contact);
}
+
*contactId = contactIdlocal;
return error;
}
*
* @return 0 on success, otherwise a Win32 error code
*/
-UINT rdpei_touch_update(RdpeiClientContext* context, int externalId, int x, int y, int* contactId)
+UINT rdpei_touch_update(RdpeiClientContext* context, int externalId, int x,
+ int y, int* contactId)
{
unsigned int i;
int contactIdlocal = -1;
if (contactIdlocal >= 0)
{
ZeroMemory(&contact, sizeof(RDPINPUT_CONTACT_DATA));
-
contactPoint->lastX = x;
contactPoint->lastY = y;
-
contact.x = x;
contact.y = y;
contact.contactId = (UINT32) contactIdlocal;
-
contact.contactFlags |= CONTACT_FLAG_UPDATE;
contact.contactFlags |= CONTACT_FLAG_INRANGE;
contact.contactFlags |= CONTACT_FLAG_INCONTACT;
-
error = context->AddContact(context, &contact);
}
*contactId = contactIdlocal;
-
return error;
}
*
* @return 0 on success, otherwise a Win32 error code
*/
-UINT rdpei_touch_end(RdpeiClientContext* context, int externalId, int x, int y, int* contactId)
+UINT rdpei_touch_end(RdpeiClientContext* context, int externalId, int x, int y,
+ int* contactId)
{
unsigned int i;
int contactIdlocal = -1;
contact.x = x;
contact.y = y;
contact.contactId = (UINT32) contactIdlocal;
-
contact.contactFlags |= CONTACT_FLAG_UP;
if ((error = context->AddContact(context, &contact)))
contactPoint->contactId = 0;
contactPoint->state = RDPINPUT_CONTACT_STATE_OUT_OF_RANGE;
}
- *contactId = contactIdlocal;
+ *contactId = contactIdlocal;
return CHANNEL_RC_OK;
}
UINT error;
RDPEI_PLUGIN* rdpei = NULL;
RdpeiClientContext* context = NULL;
-
rdpei = (RDPEI_PLUGIN*) pEntryPoints->GetPlugin(pEntryPoints, "rdpei");
if (!rdpei)
{
size_t size;
-
rdpei = (RDPEI_PLUGIN*) calloc(1, sizeof(RDPEI_PLUGIN));
- if(!rdpei)
+
+ if (!rdpei)
{
WLog_ERR(TAG, "calloc failed!");
return CHANNEL_RC_NO_MEMORY;
rdpei->iface.Connected = NULL;
rdpei->iface.Disconnected = NULL;
rdpei->iface.Terminated = rdpei_plugin_terminated;
-
rdpei->version = 1;
rdpei->currentFrameTime = 0;
rdpei->previousFrameTime = 0;
rdpei->frame.contacts = (RDPINPUT_CONTACT_DATA*) rdpei->contacts;
-
rdpei->maxTouchContacts = 10;
size = rdpei->maxTouchContacts * sizeof(RDPINPUT_CONTACT_POINT);
rdpei->contactPoints = (RDPINPUT_CONTACT_POINT*) calloc(1, size);
-
- rdpei->rdpcontext = ((freerdp*)((rdpSettings*) pEntryPoints->GetRdpSettings(pEntryPoints))->instance)->context;
-
+ rdpei->rdpcontext = ((freerdp*)((rdpSettings*) pEntryPoints->GetRdpSettings(
+ pEntryPoints))->instance)->context;
if (!rdpei->contactPoints)
{
}
context = (RdpeiClientContext*) calloc(1, sizeof(RdpeiClientContext));
+
if (!context)
{
WLog_ERR(TAG, "calloc failed!");
context->handle = (void*) rdpei;
context->GetVersion = rdpei_get_version;
context->AddContact = rdpei_add_contact;
-
context->TouchBegin = rdpei_touch_begin;
context->TouchUpdate = rdpei_touch_update;
context->TouchEnd = rdpei_touch_end;
-
rdpei->iface.pInterface = (void*) context;
- if ((error = pEntryPoints->RegisterPlugin(pEntryPoints, "rdpei", (IWTSPlugin*) rdpei)))
+ if ((error = pEntryPoints->RegisterPlugin(pEntryPoints, "rdpei",
+ (IWTSPlugin*) rdpei)))
{
WLog_ERR(TAG, "EntryPoints->RegisterPlugin failed with error %lu!", error);
error = CHANNEL_RC_NO_MEMORY;
}
static INLINE UINT rdpgfx_server_packet_init_header(wStream* s,
- UINT16 cmdId, UINT32 pduLength)
+ UINT16 cmdId, UINT32 pduLength)
{
RDPGFX_HEADER header;
header.flags = 0;
* @param s stream
* @param start saved start pos of the packet in the stream
*/
-static INLINE void rdpgfx_server_packet_complete_header(wStream* s, size_t start)
+static INLINE void rdpgfx_server_packet_complete_header(wStream* s,
+ size_t start)
{
size_t current = Stream_GetPosition(s);
/* Fill actual length */
* descriptor (1 bytes) + segmentCount (2 bytes) + uncompressedSize (4 bytes)
* + segmentCount * size (4 bytes) */
fs = Stream_New(NULL, SrcSize + 7
- + (SrcSize/ZGFX_SEGMENTED_MAXSIZE + 1) * 4);
+ + (SrcSize / ZGFX_SEGMENTED_MAXSIZE + 1) * 4);
if (!fs)
{
}
if (zgfx_compress_to_stream(context->priv->zgfx, fs, pSrcData,
- SrcSize, &flags) < 0)
+ SrcSize, &flags) < 0)
{
WLog_ERR(TAG, "zgfx_compress_to_stream failed!");
error = ERROR_INTERNAL_ERROR;
}
if (!WTSVirtualChannelWrite(context->priv->rdpgfx_channel,
- (PCHAR) Stream_Buffer(fs),
- Stream_GetPosition(fs), &written))
+ (PCHAR) Stream_Buffer(fs),
+ Stream_GetPosition(fs), &written))
{
WLog_ERR(TAG, "WTSVirtualChannelWrite failed!");
error = ERROR_INTERNAL_ERROR;
if (written < Stream_GetPosition(fs))
{
WLog_WARN(TAG, "Unexpected bytes written: %lu/%lu",
- written, Stream_GetPosition(fs));
+ written, Stream_GetPosition(fs));
}
error = CHANNEL_RC_OK;
* @return 0 on success, otherwise a Win32 error code
*/
static INLINE UINT rdpgfx_server_single_packet_send(
- RdpgfxServerContext* context, wStream* s)
+ RdpgfxServerContext* context, wStream* s)
{
/* Fill actual length */
rdpgfx_server_packet_complete_header(s, 0);
* @return 0 on success, otherwise a Win32 error code
*/
static UINT rdpgfx_send_caps_confirm_pdu(RdpgfxServerContext* context,
- RDPGFX_CAPS_CONFIRM_PDU* capsConfirm)
+ RDPGFX_CAPS_CONFIRM_PDU* capsConfirm)
{
RDPGFX_CAPSET* capsSet = capsConfirm->capsSet;
wStream* s = rdpgfx_server_single_packet_new(
- RDPGFX_CMDID_CAPSCONFIRM, RDPGFX_CAPSET_SIZE);
+ RDPGFX_CMDID_CAPSCONFIRM, RDPGFX_CAPSET_SIZE);
if (!s)
{
* @return 0 on success, otherwise a Win32 error code
*/
static UINT rdpgfx_send_reset_graphics_pdu(RdpgfxServerContext* context,
- RDPGFX_RESET_GRAPHICS_PDU* pdu)
+ RDPGFX_RESET_GRAPHICS_PDU* pdu)
{
UINT32 index;
MONITOR_DEF* monitor;
if (pdu->monitorCount >= 16)
{
WLog_ERR(TAG, "Monitor count MUST be less than or equal to 16: %lu",
- pdu->monitorCount);
+ pdu->monitorCount);
return ERROR_INVALID_DATA;
}
s = rdpgfx_server_single_packet_new(
- RDPGFX_CMDID_RESETGRAPHICS,
- RDPGFX_RESET_GRAPHICS_PDU_SIZE - RDPGFX_HEADER_SIZE);
+ RDPGFX_CMDID_RESETGRAPHICS,
+ RDPGFX_RESET_GRAPHICS_PDU_SIZE - RDPGFX_HEADER_SIZE);
if (!s)
{
* @return 0 on success, otherwise a Win32 error code
*/
static UINT rdpgfx_send_evict_cache_entry_pdu(RdpgfxServerContext* context,
- RDPGFX_EVICT_CACHE_ENTRY_PDU* pdu)
+ RDPGFX_EVICT_CACHE_ENTRY_PDU* pdu)
{
wStream* s = rdpgfx_server_single_packet_new(RDPGFX_CMDID_EVICTCACHEENTRY, 2);
* @return 0 on success, otherwise a Win32 error code
*/
static UINT rdpgfx_send_cache_import_reply_pdu(RdpgfxServerContext* context,
- RDPGFX_CACHE_IMPORT_REPLY_PDU* pdu)
+ RDPGFX_CACHE_IMPORT_REPLY_PDU* pdu)
{
UINT16 index;
wStream* s = rdpgfx_server_single_packet_new(
- RDPGFX_CMDID_CACHEIMPORTREPLY,
- 2 + 2 * pdu->importedEntriesCount);
+ RDPGFX_CMDID_CACHEIMPORTREPLY,
+ 2 + 2 * pdu->importedEntriesCount);
if (!s)
{
* @return 0 on success, otherwise a Win32 error code
*/
static UINT rdpgfx_send_create_surface_pdu(RdpgfxServerContext* context,
- RDPGFX_CREATE_SURFACE_PDU* pdu)
+ RDPGFX_CREATE_SURFACE_PDU* pdu)
{
wStream* s = rdpgfx_server_single_packet_new(RDPGFX_CMDID_CREATESURFACE, 7);
* @return 0 on success, otherwise a Win32 error code
*/
UINT rdpgfx_send_delete_surface_pdu(RdpgfxServerContext* context,
- RDPGFX_DELETE_SURFACE_PDU* pdu)
+ RDPGFX_DELETE_SURFACE_PDU* pdu)
{
wStream* s = rdpgfx_server_single_packet_new(RDPGFX_CMDID_DELETESURFACE, 2);
}
static INLINE void rdpgfx_write_start_frame_pdu(wStream* s,
- RDPGFX_START_FRAME_PDU* pdu)
+ RDPGFX_START_FRAME_PDU* pdu)
{
Stream_Write_UINT32(s, pdu->timestamp); /* timestamp (4 bytes) */
Stream_Write_UINT32(s, pdu->frameId); /* frameId (4 bytes) */
}
static INLINE void rdpgfx_write_end_frame_pdu(wStream* s,
- RDPGFX_END_FRAME_PDU* pdu)
+ RDPGFX_END_FRAME_PDU* pdu)
{
Stream_Write_UINT32(s, pdu->frameId); /* frameId (4 bytes) */
}
* @return 0 on success, otherwise a Win32 error code
*/
static UINT rdpgfx_send_start_frame_pdu(RdpgfxServerContext* context,
- RDPGFX_START_FRAME_PDU* pdu)
+ RDPGFX_START_FRAME_PDU* pdu)
{
wStream* s = rdpgfx_server_single_packet_new(
- RDPGFX_CMDID_STARTFRAME,
- RDPGFX_START_FRAME_PDU_SIZE);
+ RDPGFX_CMDID_STARTFRAME,
+ RDPGFX_START_FRAME_PDU_SIZE);
if (!s)
{
* @return 0 on success, otherwise a Win32 error code
*/
static UINT rdpgfx_send_end_frame_pdu(RdpgfxServerContext* context,
- RDPGFX_END_FRAME_PDU* pdu)
+ RDPGFX_END_FRAME_PDU* pdu)
{
wStream* s = rdpgfx_server_single_packet_new(
- RDPGFX_CMDID_ENDFRAME,
- RDPGFX_END_FRAME_PDU_SIZE);
+ RDPGFX_CMDID_ENDFRAME,
+ RDPGFX_END_FRAME_PDU_SIZE);
if (!s)
{
* @return estimated size
*/
static INLINE UINT32 rdpgfx_estimate_h264_avc420(
- RDPGFX_AVC420_BITMAP_STREAM* havc420)
+ RDPGFX_AVC420_BITMAP_STREAM* havc420)
{
/* H264 metadata + H264 stream. See rdpgfx_write_h264_avc420 */
return sizeof(UINT32) /* numRegionRects */
- + 10 /* regionRects + quantQualityVals */
- * havc420->meta.numRegionRects
- + havc420->length;
+ + 10 /* regionRects + quantQualityVals */
+ * havc420->meta.numRegionRects
+ + havc420->length;
}
/**
*
* @return estimated size
*/
-static INLINE UINT32 rdpgfx_estimate_surface_command(RDPGFX_SURFACE_COMMAND* cmd)
+static INLINE UINT32 rdpgfx_estimate_surface_command(RDPGFX_SURFACE_COMMAND*
+ cmd)
{
RDPGFX_AVC420_BITMAP_STREAM* havc420 = NULL;
RDPGFX_AVC444_BITMAP_STREAM* havc444 = NULL;
case RDPGFX_CODECID_CAPROGRESSIVE:
case RDPGFX_CODECID_CAPROGRESSIVE_V2:
return RDPGFX_WIRE_TO_SURFACE_PDU_2_SIZE + cmd->length;
+
case RDPGFX_CODECID_AVC420:
havc420 = (RDPGFX_AVC420_BITMAP_STREAM*)cmd->extra;
h264Size = rdpgfx_estimate_h264_avc420(havc420);
return RDPGFX_WIRE_TO_SURFACE_PDU_1_SIZE + h264Size;
+
case RDPGFX_CODECID_AVC444:
havc444 = (RDPGFX_AVC444_BITMAP_STREAM*)cmd->extra;
h264Size = sizeof(UINT32); /* cbAvc420EncodedBitstream1 */
}
return RDPGFX_WIRE_TO_SURFACE_PDU_1_SIZE + h264Size;
+
default:
return RDPGFX_WIRE_TO_SURFACE_PDU_1_SIZE + cmd->length;
}
static INLINE UINT16 rdpgfx_surface_command_cmdid(RDPGFX_SURFACE_COMMAND* cmd)
{
if (cmd->codecId == RDPGFX_CODECID_CAPROGRESSIVE ||
- cmd->codecId == RDPGFX_CODECID_CAPROGRESSIVE_V2)
+ cmd->codecId == RDPGFX_CODECID_CAPROGRESSIVE_V2)
{
return RDPGFX_CMDID_WIRETOSURFACE_2;
}
{
quantQualityVal = &(meta->quantQualityVals[index]);
Stream_Write_UINT8(s, quantQualityVal->qp
- | (quantQualityVal->r << 6)
- | (quantQualityVal->p << 7)); /* qpVal (1 byte) */
+ | (quantQualityVal->r << 6)
+ | (quantQualityVal->p << 7)); /* qpVal (1 byte) */
/* qualityVal (1 byte) */
Stream_Write_UINT8(s, quantQualityVal->qualityVal);
}
* @return 0 on success, otherwise a Win32 error code
*/
static INLINE UINT rdpgfx_write_h264_avc420(wStream* s,
- RDPGFX_AVC420_BITMAP_STREAM* havc420)
+ RDPGFX_AVC420_BITMAP_STREAM* havc420)
{
UINT error = CHANNEL_RC_OK;
if ((error = rdpgfx_write_h264_metablock(s, &(havc420->meta))))
{
WLog_ERR(TAG, "rdpgfx_write_h264_metablock failed with error %lu!",
- error);
+ error);
return error;
}
*
* @return 0 on success, otherwise a Win32 error code
*/
-static UINT rdpgfx_write_surface_command(wStream* s, RDPGFX_SURFACE_COMMAND* cmd)
+static UINT rdpgfx_write_surface_command(wStream* s,
+ RDPGFX_SURFACE_COMMAND* cmd)
{
UINT error = CHANNEL_RC_OK;
RDPGFX_AVC420_BITMAP_STREAM* havc420 = NULL;
UINT32 bitmapDataLength = 0;
if (cmd->codecId == RDPGFX_CODECID_CAPROGRESSIVE ||
- cmd->codecId == RDPGFX_CODECID_CAPROGRESSIVE_V2)
+ cmd->codecId == RDPGFX_CODECID_CAPROGRESSIVE_V2)
{
/* Write RDPGFX_CMDID_WIRETOSURFACE_2 format for CAPROGRESSIVE */
Stream_Write_UINT16(s, cmd->surfaceId); /* surfaceId (2 bytes) */
* @return 0 on success, otherwise a Win32 error code
*/
static UINT rdpgfx_send_surface_command(RdpgfxServerContext* context,
- RDPGFX_SURFACE_COMMAND* cmd)
+ RDPGFX_SURFACE_COMMAND* cmd)
{
UINT error = CHANNEL_RC_OK;
wStream* s;
s = rdpgfx_server_single_packet_new(
- rdpgfx_surface_command_cmdid(cmd),
- rdpgfx_estimate_surface_command(cmd));
+ rdpgfx_surface_command_cmdid(cmd),
+ rdpgfx_estimate_surface_command(cmd));
if (!s)
{
* @return 0 on success, otherwise a Win32 error code
*/
static UINT rdpgfx_send_surface_frame_command(RdpgfxServerContext* context,
- RDPGFX_SURFACE_COMMAND* cmd, RDPGFX_START_FRAME_PDU* startFrame,
- RDPGFX_END_FRAME_PDU* endFrame)
+ RDPGFX_SURFACE_COMMAND* cmd, RDPGFX_START_FRAME_PDU* startFrame,
+ RDPGFX_END_FRAME_PDU* endFrame)
{
UINT error = CHANNEL_RC_OK;
{
position = Stream_GetPosition(s);
error = rdpgfx_server_packet_init_header(s,
- RDPGFX_CMDID_STARTFRAME, 0);
+ RDPGFX_CMDID_STARTFRAME, 0);
if (error != CHANNEL_RC_OK)
{
/* Write RDPGFX_CMDID_WIRETOSURFACE_1 or RDPGFX_CMDID_WIRETOSURFACE_2 */
position = Stream_GetPosition(s);
error = rdpgfx_server_packet_init_header(s,
- rdpgfx_surface_command_cmdid(cmd),
- 0); // Actual length will be filled later
+ rdpgfx_surface_command_cmdid(cmd),
+ 0); // Actual length will be filled later
if (error != CHANNEL_RC_OK)
{
{
position = Stream_GetPosition(s);
error = rdpgfx_server_packet_init_header(s,
- RDPGFX_CMDID_ENDFRAME, 0);
+ RDPGFX_CMDID_ENDFRAME, 0);
if (error != CHANNEL_RC_OK)
{
*
* @return 0 on success, otherwise a Win32 error code
*/
-static UINT rdpgfx_send_delete_encoding_context_pdu(RdpgfxServerContext* context,
- RDPGFX_DELETE_ENCODING_CONTEXT_PDU* pdu)
+static UINT rdpgfx_send_delete_encoding_context_pdu(RdpgfxServerContext*
+ context,
+ RDPGFX_DELETE_ENCODING_CONTEXT_PDU* pdu)
{
wStream* s = rdpgfx_server_single_packet_new(
- RDPGFX_CMDID_DELETEENCODINGCONTEXT, 6);
+ RDPGFX_CMDID_DELETEENCODINGCONTEXT, 6);
if (!s)
{
* @return 0 on success, otherwise a Win32 error code
*/
UINT rdpgfx_send_solid_fill_pdu(RdpgfxServerContext* context,
- RDPGFX_SOLID_FILL_PDU* pdu)
+ RDPGFX_SOLID_FILL_PDU* pdu)
{
UINT error = CHANNEL_RC_OK;
UINT16 index;
RECTANGLE_16* fillRect;
wStream* s = rdpgfx_server_single_packet_new(
- RDPGFX_CMDID_SOLIDFILL,
- 8 + 8 * pdu->fillRectCount);
+ RDPGFX_CMDID_SOLIDFILL,
+ 8 + 8 * pdu->fillRectCount);
if (!s)
{
* @return 0 on success, otherwise a Win32 error code
*/
static UINT rdpgfx_send_surface_to_surface_pdu(RdpgfxServerContext* context,
- RDPGFX_SURFACE_TO_SURFACE_PDU* pdu)
+ RDPGFX_SURFACE_TO_SURFACE_PDU* pdu)
{
UINT error = CHANNEL_RC_OK;
UINT16 index;
RDPGFX_POINT16* destPt;
wStream* s = rdpgfx_server_single_packet_new(
- RDPGFX_CMDID_SURFACETOSURFACE,
- 14 + 4 * pdu->destPtsCount);
+ RDPGFX_CMDID_SURFACETOSURFACE,
+ 14 + 4 * pdu->destPtsCount);
if (!s)
{
* @return 0 on success, otherwise a Win32 error code
*/
static UINT rdpgfx_send_surface_to_cache_pdu(RdpgfxServerContext* context,
- RDPGFX_SURFACE_TO_CACHE_PDU* pdu)
+ RDPGFX_SURFACE_TO_CACHE_PDU* pdu)
{
UINT error = CHANNEL_RC_OK;
wStream* s = rdpgfx_server_single_packet_new(
- RDPGFX_CMDID_SURFACETOCACHE, 20);
+ RDPGFX_CMDID_SURFACETOCACHE, 20);
if (!s)
{
* @return 0 on success, otherwise a Win32 error code
*/
static UINT rdpgfx_send_cache_to_surface_pdu(RdpgfxServerContext* context,
- RDPGFX_CACHE_TO_SURFACE_PDU* pdu)
+ RDPGFX_CACHE_TO_SURFACE_PDU* pdu)
{
UINT error = CHANNEL_RC_OK;
UINT16 index;
RDPGFX_POINT16* destPt;
wStream* s = rdpgfx_server_single_packet_new(
- RDPGFX_CMDID_CACHETOSURFACE,
- 6 + 4 * pdu->destPtsCount);
+ RDPGFX_CMDID_CACHETOSURFACE,
+ 6 + 4 * pdu->destPtsCount);
if (!s)
{
* @return 0 on success, otherwise a Win32 error code
*/
static UINT rdpgfx_send_map_surface_to_output_pdu(RdpgfxServerContext* context,
- RDPGFX_MAP_SURFACE_TO_OUTPUT_PDU* pdu)
+ RDPGFX_MAP_SURFACE_TO_OUTPUT_PDU* pdu)
{
wStream* s = rdpgfx_server_single_packet_new(
- RDPGFX_CMDID_MAPSURFACETOOUTPUT, 12);
+ RDPGFX_CMDID_MAPSURFACETOOUTPUT, 12);
if (!s)
{
* @return 0 on success, otherwise a Win32 error code
*/
static UINT rdpgfx_send_map_surface_to_window_pdu(RdpgfxServerContext* context,
- RDPGFX_MAP_SURFACE_TO_WINDOW_PDU* pdu)
+ RDPGFX_MAP_SURFACE_TO_WINDOW_PDU* pdu)
{
wStream* s = rdpgfx_server_single_packet_new(
- RDPGFX_CMDID_MAPSURFACETOWINDOW, 18);
+ RDPGFX_CMDID_MAPSURFACETOWINDOW, 18);
if (!s)
{
* @return 0 on success, otherwise a Win32 error code
*/
static UINT rdpgfx_recv_frame_acknowledge_pdu(RdpgfxServerContext* context,
- wStream* s)
+ wStream* s)
{
RDPGFX_FRAME_ACKNOWLEDGE_PDU pdu;
UINT error = CHANNEL_RC_OK;
if (error)
WLog_ERR(TAG, "context->FrameAcknowledge failed with error %lu",
- error);
+ error);
}
return error;
* @return 0 on success, otherwise a Win32 error code
*/
static UINT rdpgfx_recv_cache_import_offer_pdu(RdpgfxServerContext* context,
- wStream* s)
+ wStream* s)
{
UINT16 index;
RDPGFX_CACHE_IMPORT_OFFER_PDU pdu;
}
pdu.cacheEntries = (RDPGFX_CACHE_ENTRY_METADATA*)
- calloc(pdu.cacheEntriesCount,
- sizeof(RDPGFX_CACHE_ENTRY_METADATA));
+ calloc(pdu.cacheEntriesCount,
+ sizeof(RDPGFX_CACHE_ENTRY_METADATA));
if (!pdu.cacheEntries)
{
if (error)
WLog_ERR(TAG, "context->CacheImportOffer failed with error %lu",
- error);
+ error);
}
free(pdu.cacheEntries);
* @return 0 on success, otherwise a Win32 error code
*/
static UINT rdpgfx_recv_caps_advertise_pdu(RdpgfxServerContext* context,
- wStream* s)
+ wStream* s)
{
UINT16 index;
RDPGFX_CAPSET* capsSet;
if (capsDataLength != 4)
{
WLog_ERR(TAG, "capsDataLength does not equal to 4: %lu",
- capsDataLength);
+ capsDataLength);
return ERROR_INVALID_DATA;
}
* @return 0 on success, otherwise a Win32 error code
*/
static UINT rdpgfx_recv_qoe_frame_acknowledge_pdu(RdpgfxServerContext* context,
- wStream* s)
+ wStream* s)
{
RDPGFX_QOE_FRAME_ACKNOWLEDGE_PDU pdu;
UINT error = CHANNEL_RC_OK;
if (error)
WLog_ERR(TAG, "context->QoeFrameAcknowledge failed with error %lu",
- error);
+ error);
}
return error;
}
WLog_DBG(TAG, "cmdId: %s (0x%04X) flags: 0x%04X pduLength: %d",
- rdpgfx_get_cmd_id_string(header.cmdId), header.cmdId,
- header.flags, header.pduLength);
+ rdpgfx_get_cmd_id_string(header.cmdId), header.cmdId,
+ header.flags, header.pduLength);
switch (header.cmdId)
{
case RDPGFX_CMDID_FRAMEACKNOWLEDGE:
-
if ((error = rdpgfx_recv_frame_acknowledge_pdu(context, s)))
WLog_ERR(TAG, "rdpgfx_recv_frame_acknowledge_pdu "
- "failed with error %lu!", error);
+ "failed with error %lu!", error);
break;
- case RDPGFX_CMDID_CACHEIMPORTOFFER:
+ case RDPGFX_CMDID_CACHEIMPORTOFFER:
if ((error = rdpgfx_recv_cache_import_offer_pdu(context, s)))
WLog_ERR(TAG, "rdpgfx_recv_cache_import_offer_pdu "
- "failed with error %lu!", error);
+ "failed with error %lu!", error);
break;
- case RDPGFX_CMDID_CAPSADVERTISE:
+ case RDPGFX_CMDID_CAPSADVERTISE:
if ((error = rdpgfx_recv_caps_advertise_pdu(context, s)))
WLog_ERR(TAG, "rdpgfx_recv_caps_advertise_pdu "
- "failed with error %lu!", error);
+ "failed with error %lu!", error);
break;
- case RDPGFX_CMDID_QOEFRAMEACKNOWLEDGE:
+ case RDPGFX_CMDID_QOEFRAMEACKNOWLEDGE:
if ((error = rdpgfx_recv_qoe_frame_acknowledge_pdu(context, s)))
WLog_ERR(TAG, "rdpgfx_recv_qoe_frame_acknowledge_pdu "
- "failed with error %lu!", error);
+ "failed with error %lu!", error);
break;
+
default:
error = CHANNEL_RC_BAD_PROC;
break;
if (error)
{
WLog_ERR(TAG, "Error while parsing GFX cmdId: %s (0x%04X)",
- rdpgfx_get_cmd_id_string(header.cmdId), header.cmdId);
+ rdpgfx_get_cmd_id_string(header.cmdId), header.cmdId);
return error;
}
if (end != (beg + header.pduLength))
{
WLog_ERR(TAG, "Unexpected gfx pdu end: Actual: %d, Expected: %d",
- end, (beg + header.pduLength));
+ end, (beg + header.pduLength));
Stream_SetPosition(s, (beg + header.pduLength));
}
buffer = NULL;
BytesReturned = 0;
nCount = 0;
-
freerdp_channel_init_thread_context(context->rdpcontext);
events[nCount++] = priv->stopEvent;
events[nCount++] = priv->channelEvent;
if ((error = rdpgfx_server_handle_messages(context)))
{
WLog_ERR(TAG, "rdpgfx_server_handle_messages failed with error %lu",
- error);
+ error);
break;
}
}
if (error && context->rdpcontext)
setChannelError(context->rdpcontext, error,
- "rdpgfx_server_thread_func reported an error");
+ "rdpgfx_server_thread_func reported an error");
ExitThread((DWORD)error);
return NULL;
priv->SessionId = WTS_CURRENT_SESSION;
if (WTSQuerySessionInformationA(context->vcm, WTS_CURRENT_SESSION,
- WTSSessionId, (LPSTR*) &pSessionId,
- &BytesReturned) == FALSE)
+ WTSSessionId, (LPSTR*) &pSessionId,
+ &BytesReturned) == FALSE)
{
WLog_ERR(TAG, "WTSQuerySessionInformationA failed!");
return FALSE;
}
- priv->SessionId = (DWORD) *pSessionId;
+ priv->SessionId = (DWORD) * pSessionId;
WTSFreeMemory(pSessionId);
priv->rdpgfx_channel = WTSVirtualChannelOpenEx(priv->SessionId,
- RDPGFX_DVC_CHANNEL_NAME,
- WTS_CHANNEL_OPTION_DYNAMIC);
+ RDPGFX_DVC_CHANNEL_NAME,
+ WTS_CHANNEL_OPTION_DYNAMIC);
if (!priv->rdpgfx_channel)
{
/* Query for channel event handle */
if (!WTSVirtualChannelQuery(priv->rdpgfx_channel, WTSVirtualEventHandle,
- &buffer, &BytesReturned)
- || (BytesReturned != sizeof(HANDLE)))
+ &buffer, &BytesReturned)
+ || (BytesReturned != sizeof(HANDLE)))
{
WLog_ERR(TAG, "WTSVirtualChannelQuery failed "
- "or invalid returned size(%d)",
- BytesReturned);
+ "or invalid returned size(%d)",
+ BytesReturned);
if (buffer)
WTSFreeMemory(buffer);
}
if (!(priv->thread = CreateThread(NULL, 0,
- (LPTHREAD_START_ROUTINE)
- rdpgfx_server_thread_func,
- (void*) context, 0, NULL)))
+ (LPTHREAD_START_ROUTINE)
+ rdpgfx_server_thread_func,
+ (void*) context, 0, NULL)))
{
WLog_ERR(TAG, "CreateThread failed!");
goto out_stopEvent;
if (WaitForSingleObject(priv->thread, INFINITE) == WAIT_FAILED)
{
WLog_ERR(TAG, "WaitForSingleObject failed with error %lu",
- GetLastError());
+ GetLastError());
return FALSE;
}
context->FrameAcknowledge = NULL;
context->QoeFrameAcknowledge = NULL;
context->priv = priv = (RdpgfxServerPrivate*)
- calloc(1, sizeof(RdpgfxServerPrivate));
+ calloc(1, sizeof(RdpgfxServerPrivate));
if (!priv)
{
if (!priv->isReady)
{
if (WTSVirtualChannelQuery(priv->rdpgfx_channel,
- WTSVirtualChannelReady,
- &buffer, &BytesReturned) == FALSE)
+ WTSVirtualChannelReady,
+ &buffer, &BytesReturned) == FALSE)
{
if (GetLastError() == ERROR_NO_DATA)
return ERROR_NO_DATA;
Stream_SetPosition(s, 0);
if (!WTSVirtualChannelRead(priv->rdpgfx_channel,
- 0, NULL, 0, &BytesReturned))
+ 0, NULL, 0, &BytesReturned))
{
if (GetLastError() == ERROR_NO_DATA)
return ERROR_NO_DATA;
}
if (WTSVirtualChannelRead(priv->rdpgfx_channel, 0,
- (PCHAR) Stream_Buffer(s),
- Stream_Capacity(s), &BytesReturned) == FALSE)
+ (PCHAR) Stream_Buffer(s),
+ Stream_Capacity(s), &BytesReturned) == FALSE)
{
WLog_ERR(TAG, "WTSVirtualChannelRead failed!");
return ERROR_INTERNAL_ERROR;
if ((ret = rdpgfx_server_receive_pdu(context, s)))
{
WLog_ERR(TAG, "rdpgfx_server_receive_pdu "
- "failed with error %lu!", ret);
+ "failed with error %lu!", ret);
return ret;
}
}
HANDLE events[2];
UINT error = CHANNEL_RC_OK;
DWORD status;
-
freerdp_channel_init_thread_context(rdpsnd->rdpcontext);
events[0] = MessageQueue_Event(rdpsnd->MsgPipe->Out);
events[1] = rdpsnd->stopEvent;
if (error && rdpsnd->rdpcontext)
setChannelError(rdpsnd->rdpcontext, error,
- "rdpsnd_schedule_thread reported an error");
+ "rdpsnd_schedule_thread reported an error");
ExitThread((DWORD)error);
return NULL;
return;
rdpsnd->ClientFormats = (AUDIO_FORMAT*) malloc(sizeof(AUDIO_FORMAT) *
- rdpsnd->NumberOfServerFormats);
+ rdpsnd->NumberOfServerFormats);
for (index = 0; index < (int) rdpsnd->NumberOfServerFormats; index++)
{
#if 0
WLog_ERR(TAG, "Server ");
rdpsnd_print_audio_formats(rdpsnd->ServerFormats,
- rdpsnd->NumberOfServerFormats);
+ rdpsnd->NumberOfServerFormats);
WLog_ERR(TAG, "");
WLog_ERR(TAG, "Client ");
rdpsnd_print_audio_formats(rdpsnd->ClientFormats,
- rdpsnd->NumberOfClientFormats);
+ rdpsnd->NumberOfClientFormats);
WLog_ERR(TAG, "");
#endif
}
* @return 0 on success, otherwise a Win32 error code
*/
static UINT rdpsnd_recv_server_audio_formats_pdu(rdpsndPlugin* rdpsnd,
- wStream* s)
+ wStream* s)
{
int index;
UINT16 wVersion;
return ERROR_BAD_LENGTH;
rdpsnd->ServerFormats = (AUDIO_FORMAT*) calloc(wNumberOfFormats,
- sizeof(AUDIO_FORMAT));
+ sizeof(AUDIO_FORMAT));
if (!rdpsnd->ServerFormats)
return CHANNEL_RC_NO_MEMORY;
* @return 0 on success, otherwise a Win32 error code
*/
static UINT rdpsnd_send_training_confirm_pdu(rdpsndPlugin* rdpsnd,
- UINT16 wTimeStamp, UINT16 wPackSize)
+ UINT16 wTimeStamp, UINT16 wPackSize)
{
wStream* pdu;
pdu = Stream_New(NULL, 8);
Stream_Write_UINT16(pdu, wTimeStamp);
Stream_Write_UINT16(pdu, wPackSize);
WLog_Print(rdpsnd->log, WLOG_DEBUG,
- "Training Response: wTimeStamp: %d wPackSize: %d",
- wTimeStamp, wPackSize);
+ "Training Response: wTimeStamp: %d wPackSize: %d",
+ wTimeStamp, wPackSize);
return rdpsnd_virtual_channel_write(rdpsnd, pdu);
}
Stream_Read_UINT16(s, wTimeStamp);
Stream_Read_UINT16(s, wPackSize);
WLog_Print(rdpsnd->log, WLOG_DEBUG,
- "Training Request: wTimeStamp: %d wPackSize: %d",
- wTimeStamp, wPackSize);
+ "Training Request: wTimeStamp: %d wPackSize: %d",
+ wTimeStamp, wPackSize);
return rdpsnd_send_training_confirm_pdu(rdpsnd, wTimeStamp, wPackSize);
}
* @return 0 on success, otherwise a Win32 error code
*/
static UINT rdpsnd_recv_wave_info_pdu(rdpsndPlugin* rdpsnd, wStream* s,
- UINT16 BodySize)
+ UINT16 BodySize)
{
UINT16 wFormatNo;
AUDIO_FORMAT* format;
rdpsnd->waveDataSize = BodySize - 8;
format = &rdpsnd->ClientFormats[wFormatNo];
WLog_Print(rdpsnd->log, WLOG_DEBUG, "WaveInfo: cBlockNo: %d wFormatNo: %d",
- rdpsnd->cBlockNo, wFormatNo);
+ rdpsnd->cBlockNo, wFormatNo);
if (!rdpsnd->isOpen)
{
* @return 0 on success, otherwise a Win32 error code
*/
static UINT rdpsnd_send_wave_confirm_pdu(rdpsndPlugin* rdpsnd,
- UINT16 wTimeStamp, BYTE cConfirmedBlockNo)
+ UINT16 wTimeStamp, BYTE cConfirmedBlockNo)
{
wStream* pdu;
pdu = Stream_New(NULL, 8);
static UINT rdpsnd_confirm_wave(rdpsndPlugin* rdpsnd, RDPSND_WAVE* wave)
{
WLog_Print(rdpsnd->log, WLOG_DEBUG,
- "WaveConfirm: cBlockNo: %d wTimeStamp: %d wTimeDiff: %d",
- wave->cBlockNo, wave->wTimeStampB, wave->wTimeStampB - wave->wTimeStampA);
+ "WaveConfirm: cBlockNo: %d wTimeStamp: %d wTimeDiff: %d",
+ wave->cBlockNo, wave->wTimeStampB, wave->wTimeStampB - wave->wTimeStampA);
return rdpsnd_send_wave_confirm_pdu(rdpsnd, wave->wTimeStampB, wave->cBlockNo);
}
* @return 0 on success, otherwise a Win32 error code
*/
static UINT rdpsnd_device_send_wave_confirm_pdu(rdpsndDevicePlugin* device,
- RDPSND_WAVE* wave)
+ RDPSND_WAVE* wave)
{
if (device->DisableConfirmThread)
return rdpsnd_confirm_wave(device->rdpsnd, wave);
if (!MessageQueue_Post(device->rdpsnd->MsgPipe->Out, NULL, 0, (void*) wave,
- NULL))
+ NULL))
{
WLog_ERR(TAG, "MessageQueue_Post failed!");
return ERROR_INTERNAL_ERROR;
format = &rdpsnd->ClientFormats[rdpsnd->wCurrentFormatNo];
wave->wAudioLength = rdpsnd_compute_audio_time_length(format, size);
WLog_Print(rdpsnd->log, WLOG_DEBUG, "Wave: cBlockNo: %d wTimeStamp: %d",
- wave->cBlockNo, wave->wTimeStampA);
+ wave->cBlockNo, wave->wTimeStampA);
if (!rdpsnd->device)
{
}
static void rdpsnd_register_device_plugin(rdpsndPlugin* rdpsnd,
- rdpsndDevicePlugin* device)
+ rdpsndDevicePlugin* device)
{
if (rdpsnd->device)
{
* @return 0 on success, otherwise a Win32 error code
*/
static UINT rdpsnd_load_device_plugin(rdpsndPlugin* rdpsnd, const char* name,
- ADDIN_ARGV* args)
+ ADDIN_ARGV* args)
{
PFREERDP_RDPSND_DEVICE_ENTRY entry;
FREERDP_RDPSND_DEVICE_ENTRY_POINTS entryPoints;
\
UINT error;
entry = (PFREERDP_RDPSND_DEVICE_ENTRY)
- freerdp_load_channel_addin_entry("rdpsnd", (LPSTR) name, NULL, 0);
+ freerdp_load_channel_addin_entry("rdpsnd", (LPSTR) name, NULL, 0);
if (!entry)
return ERROR_INTERNAL_ERROR;
{
flags = COMMAND_LINE_SIGIL_NONE | COMMAND_LINE_SEPARATOR_COLON;
status = CommandLineParseArgumentsA(args->argc, (const char**) args->argv,
- rdpsnd_args, flags, rdpsnd, NULL, NULL);
+ rdpsnd_args, flags, rdpsnd, NULL, NULL);
if (status < 0)
return CHANNEL_RC_INITIALIZATION_ERROR;
if ((status = rdpsnd_load_device_plugin(rdpsnd, rdpsnd->subsystem, args)))
{
WLog_ERR(TAG, "unable to load the %s subsystem plugin because of error %lu",
- rdpsnd->subsystem, status);
+ rdpsnd->subsystem, status);
return status;
}
}
if ((status = rdpsnd_load_device_plugin(rdpsnd, subsystem_name, args)))
WLog_ERR(TAG, "unable to load the %s subsystem plugin because of error %lu",
- subsystem_name, status);
+ subsystem_name, status);
}
#endif
if ((status = rdpsnd_load_device_plugin(rdpsnd, subsystem_name, args)))
WLog_ERR(TAG, "unable to load the %s subsystem plugin because of error %lu",
- subsystem_name, status);
+ subsystem_name, status);
}
#endif
if ((status = rdpsnd_load_device_plugin(rdpsnd, subsystem_name, args)))
WLog_ERR(TAG, "unable to load the %s subsystem plugin because of error %lu",
- subsystem_name, status);
+ subsystem_name, status);
}
#endif
if ((status = rdpsnd_load_device_plugin(rdpsnd, subsystem_name, args)))
WLog_ERR(TAG, "unable to load the %s subsystem plugin because of error %lu",
- subsystem_name, status);
+ subsystem_name, status);
}
#endif
if ((status = rdpsnd_load_device_plugin(rdpsnd, subsystem_name, args)))
WLog_ERR(TAG, "unable to load the %s subsystem plugin because of error %lu",
- subsystem_name, status);
+ subsystem_name, status);
}
#endif
if ((status = rdpsnd_load_device_plugin(rdpsnd, subsystem_name, args)))
WLog_ERR(TAG, "unable to load the %s subsystem plugin because of error %lu",
- subsystem_name, status);
+ subsystem_name, status);
}
#endif
if ((status = rdpsnd_load_device_plugin(rdpsnd, subsystem_name, args)))
WLog_ERR(TAG, "unable to load the %s subsystem plugin because of error %lu",
- subsystem_name, status);
+ subsystem_name, status);
}
#endif
}
rdpsnd->ScheduleThread = CreateThread(NULL, 0,
- (LPTHREAD_START_ROUTINE) rdpsnd_schedule_thread,
- (void*) rdpsnd, 0, NULL);
+ (LPTHREAD_START_ROUTINE) rdpsnd_schedule_thread,
+ (void*) rdpsnd, 0, NULL);
if (!rdpsnd->ScheduleThread)
{
else
{
status = rdpsnd->channelEntryPoints.pVirtualChannelWrite(rdpsnd->OpenHandle,
- Stream_Buffer(s), (UINT32) Stream_GetPosition(s), s);
+ Stream_Buffer(s), (UINT32) Stream_GetPosition(s), s);
}
if (status != CHANNEL_RC_OK)
{
Stream_Free(s, TRUE);
WLog_ERR(TAG, "VirtualChannelWrite failed with %s [%08X]",
- WTSErrorToString(status), status);
+ WTSErrorToString(status), status);
}
return status;
* @return 0 on success, otherwise a Win32 error code
*/
static UINT rdpsnd_virtual_channel_event_data_received(rdpsndPlugin* plugin,
- void* pData, UINT32 dataLength, UINT32 totalLength, UINT32 dataFlags)
+ void* pData, UINT32 dataLength, UINT32 totalLength, UINT32 dataFlags)
{
wStream* s;
}
static VOID VCAPITYPE rdpsnd_virtual_channel_open_event(DWORD openHandle,
- UINT event,
- LPVOID pData, UINT32 dataLength, UINT32 totalLength, UINT32 dataFlags)
+ UINT event,
+ LPVOID pData, UINT32 dataLength, UINT32 totalLength, UINT32 dataFlags)
{
rdpsndPlugin* rdpsnd = s_TLSPluginContext;
UINT error = CHANNEL_RC_OK;
{
case CHANNEL_EVENT_DATA_RECEIVED:
if ((error = rdpsnd_virtual_channel_event_data_received(rdpsnd, pData,
- dataLength, totalLength, dataFlags)))
+ dataLength, totalLength, dataFlags)))
WLog_ERR(TAG,
- "rdpsnd_virtual_channel_event_data_received failed with error %lu", error);
+ "rdpsnd_virtual_channel_event_data_received failed with error %lu", error);
break;
if (error && rdpsnd->rdpcontext)
setChannelError(rdpsnd->rdpcontext, error,
- "rdpsnd_virtual_channel_open_event reported an error");
+ "rdpsnd_virtual_channel_open_event reported an error");
}
static void* rdpsnd_virtual_channel_client_thread(void* arg)
wMessage message;
rdpsndPlugin* rdpsnd = (rdpsndPlugin*) arg;
UINT error;
-
freerdp_channel_init_thread_context(rdpsnd->rdpcontext);
+
if ((error = rdpsnd_process_connect(rdpsnd)))
{
WLog_ERR(TAG, "error connecting sound channel");
if (error && rdpsnd->rdpcontext)
setChannelError(rdpsnd->rdpcontext, error,
- "rdpsnd_virtual_channel_client_thread reported an error");
+ "rdpsnd_virtual_channel_client_thread reported an error");
rdpsnd_process_disconnect(rdpsnd);
ExitThread((DWORD)error);
* @return 0 on success, otherwise a Win32 error code
*/
static UINT rdpsnd_virtual_channel_event_connected(rdpsndPlugin* plugin,
- LPVOID pData, UINT32 dataLength)
+ LPVOID pData, UINT32 dataLength)
{
UINT32 status;
status = plugin->channelEntryPoints.pVirtualChannelOpen(plugin->InitHandle,
- &plugin->OpenHandle, plugin->channelDef.name,
- rdpsnd_virtual_channel_open_event);
+ &plugin->OpenHandle, plugin->channelDef.name,
+ rdpsnd_virtual_channel_open_event);
if (status != CHANNEL_RC_OK)
{
WLog_ERR(TAG, "pVirtualChannelOpen failed with %s [%08X]",
- WTSErrorToString(status), status);
+ WTSErrorToString(status), status);
return status;
}
}
plugin->thread = CreateThread(NULL, 0,
- (LPTHREAD_START_ROUTINE) rdpsnd_virtual_channel_client_thread, (void*) plugin,
- 0, NULL);
+ (LPTHREAD_START_ROUTINE) rdpsnd_virtual_channel_client_thread, (void*) plugin,
+ 0, NULL);
if (!plugin->thread)
{
if (CHANNEL_RC_OK != error)
{
WLog_ERR(TAG, "pVirtualChannelClose failed with %s [%08X]",
- WTSErrorToString(error), error);
+ WTSErrorToString(error), error);
return error;
}
}
static VOID VCAPITYPE rdpsnd_virtual_channel_init_event(LPVOID pInitHandle,
- UINT event, LPVOID pData, UINT dataLength)
+ UINT event, LPVOID pData, UINT dataLength)
{
rdpsndPlugin* plugin = s_TLSPluginContext;
UINT error = CHANNEL_RC_OK;
case CHANNEL_EVENT_CONNECTED:
if ((error = rdpsnd_virtual_channel_event_connected(plugin, pData, dataLength)))
WLog_ERR(TAG, "rdpsnd_virtual_channel_event_connected failed with error %lu!",
- error);
+ error);
break;
case CHANNEL_EVENT_DISCONNECTED:
if ((error = rdpsnd_virtual_channel_event_disconnected(plugin)))
WLog_ERR(TAG,
- "rdpsnd_virtual_channel_event_disconnected failed with error %lu!", error);
+ "rdpsnd_virtual_channel_event_disconnected failed with error %lu!", error);
break;
if (error && plugin->rdpcontext)
setChannelError(plugin->rdpcontext, error,
- "rdpsnd_virtual_channel_init_event reported an error");
+ "rdpsnd_virtual_channel_init_event reported an error");
}
/* rdpsnd is always built-in */
}
CopyMemory(&(rdpsnd->channelEntryPoints), pEntryPoints,
- sizeof(CHANNEL_ENTRY_POINTS_FREERDP));
+ sizeof(CHANNEL_ENTRY_POINTS_FREERDP));
rdpsnd->log = WLog_Get("com.freerdp.channels.rdpsnd.client");
rc = rdpsnd->channelEntryPoints.pVirtualChannelInit(&rdpsnd->InitHandle,
- &rdpsnd->channelDef, 1, VIRTUAL_CHANNEL_VERSION_WIN2000,
- rdpsnd_virtual_channel_init_event);
+ &rdpsnd->channelDef, 1, VIRTUAL_CHANNEL_VERSION_WIN2000,
+ rdpsnd_virtual_channel_init_event);
if (CHANNEL_RC_OK != rc)
{
WLog_ERR(TAG, "pVirtualChannelInit failed with %s [%08X]",
- WTSErrorToString(rc), rc);
+ WTSErrorToString(rc), rc);
free(rdpsnd);
return FALSE;
}
UINT16 i;
BOOL status;
ULONG written;
-
Stream_Write_UINT8(s, SNDC_FORMATS);
Stream_Write_UINT8(s, 0);
Stream_Seek_UINT16(s);
-
Stream_Write_UINT32(s, 0); /* dwFlags */
Stream_Write_UINT32(s, 0); /* dwVolume */
Stream_Write_UINT32(s, 0); /* dwPitch */
for (i = 0; i < context->num_server_formats; i++)
{
- Stream_Write_UINT16(s, context->server_formats[i].wFormatTag); /* wFormatTag (WAVE_FORMAT_PCM) */
+ Stream_Write_UINT16(s,
+ context->server_formats[i].wFormatTag); /* wFormatTag (WAVE_FORMAT_PCM) */
Stream_Write_UINT16(s, context->server_formats[i].nChannels); /* nChannels */
- Stream_Write_UINT32(s, context->server_formats[i].nSamplesPerSec); /* nSamplesPerSec */
-
+ Stream_Write_UINT32(s,
+ context->server_formats[i].nSamplesPerSec); /* nSamplesPerSec */
Stream_Write_UINT32(s, context->server_formats[i].nSamplesPerSec *
- context->server_formats[i].nChannels *
- context->server_formats[i].wBitsPerSample / 8); /* nAvgBytesPerSec */
-
- Stream_Write_UINT16(s, context->server_formats[i].nBlockAlign); /* nBlockAlign */
- Stream_Write_UINT16(s, context->server_formats[i].wBitsPerSample); /* wBitsPerSample */
+ context->server_formats[i].nChannels *
+ context->server_formats[i].wBitsPerSample / 8); /* nAvgBytesPerSec */
+ Stream_Write_UINT16(s,
+ context->server_formats[i].nBlockAlign); /* nBlockAlign */
+ Stream_Write_UINT16(s,
+ context->server_formats[i].wBitsPerSample); /* wBitsPerSample */
Stream_Write_UINT16(s, context->server_formats[i].cbSize); /* cbSize */
if (context->server_formats[i].cbSize > 0)
{
- Stream_Write(s, context->server_formats[i].data, context->server_formats[i].cbSize);
+ Stream_Write(s, context->server_formats[i].data,
+ context->server_formats[i].cbSize);
}
}
Stream_SetPosition(s, 2);
Stream_Write_UINT16(s, pos - 4);
Stream_SetPosition(s, pos);
- status = WTSVirtualChannelWrite(context->priv->ChannelHandle, (PCHAR) Stream_Buffer(s), Stream_GetPosition(s), &written);
+ status = WTSVirtualChannelWrite(context->priv->ChannelHandle,
+ (PCHAR) Stream_Buffer(s), Stream_GetPosition(s), &written);
Stream_SetPosition(s, 0);
-
- return status ? CHANNEL_RC_OK: ERROR_INTERNAL_ERROR;
+ return status ? CHANNEL_RC_OK : ERROR_INTERNAL_ERROR;
}
/**
*
* @return 0 on success, otherwise a Win32 error code
*/
-static UINT rdpsnd_server_recv_waveconfirm(RdpsndServerContext* context, wStream* s)
+static UINT rdpsnd_server_recv_waveconfirm(RdpsndServerContext* context,
+ wStream* s)
{
UINT16 timestamp;
BYTE confirmBlockNum;
Stream_Read_UINT16(s, timestamp);
Stream_Read_UINT8(s, confirmBlockNum);
Stream_Seek_UINT8(s);
-
IFCALLRET(context->ConfirmBlock, error, context, confirmBlockNum, timestamp);
+
if (error)
WLog_ERR(TAG, "context->ConfirmBlock failed with error %lu", error);
*
* @return 0 on success, otherwise a Win32 error code
*/
-static UINT rdpsnd_server_recv_quality_mode(RdpsndServerContext* context, wStream* s)
+static UINT rdpsnd_server_recv_quality_mode(RdpsndServerContext* context,
+ wStream* s)
{
UINT16 quality;
return ERROR_INTERNAL_ERROR;
}
- context->client_formats = (AUDIO_FORMAT *)calloc(context->num_client_formats, sizeof(AUDIO_FORMAT));
+ context->client_formats = (AUDIO_FORMAT*)calloc(context->num_client_formats,
+ sizeof(AUDIO_FORMAT));
+
if (!context->client_formats)
{
WLog_ERR(TAG, "calloc failed!");
goto out_free;
}
-
Stream_Read_UINT16(s, context->client_formats[i].wFormatTag);
Stream_Read_UINT16(s, context->client_formats[i].nChannels);
Stream_Read_UINT32(s, context->client_formats[i].nSamplesPerSec);
error = ERROR_INTERNAL_ERROR;
goto out_free;
}
-
}
if (context->client_formats[i].wFormatTag != 0)
}
return CHANNEL_RC_OK;
-
out_free:
free(context->client_formats);
return error;
HANDLE events[8];
RdpsndServerContext* context;
UINT error = CHANNEL_RC_OK;
-
- context = (RdpsndServerContext *)arg;
-
+ context = (RdpsndServerContext*)arg;
freerdp_channel_init_thread_context(context->rdpcontext);
nCount = 0;
events[nCount++] = context->priv->channelEvent;
{
status = WaitForMultipleObjects(nCount, events, FALSE, INFINITE);
- if (status == WAIT_FAILED)
- {
- error = GetLastError();
- WLog_ERR(TAG, "WaitForMultipleObjects failed with error %lu!", error);
- break;
- }
-
- status = WaitForSingleObject(context->priv->StopEvent, 0);
+ if (status == WAIT_FAILED)
+ {
+ error = GetLastError();
+ WLog_ERR(TAG, "WaitForMultipleObjects failed with error %lu!", error);
+ break;
+ }
- if (status == WAIT_FAILED)
- {
- error = GetLastError();
- WLog_ERR(TAG, "WaitForSingleObject failed with error %lu!", error);
- break;
- }
+ status = WaitForSingleObject(context->priv->StopEvent, 0);
+ if (status == WAIT_FAILED)
+ {
+ error = GetLastError();
+ WLog_ERR(TAG, "WaitForSingleObject failed with error %lu!", error);
+ break;
+ }
if (status == WAIT_OBJECT_0)
break;
}
out:
+
if (error && context->rdpcontext)
- setChannelError(context->rdpcontext, error, "rdpsnd_server_thread reported an error");
+ setChannelError(context->rdpcontext, error,
+ "rdpsnd_server_thread reported an error");
+
ExitThread((DWORD)error);
return NULL;
}
*
* @return 0 on success, otherwise a Win32 error code
*/
-static UINT rdpsnd_server_initialize(RdpsndServerContext* context, BOOL ownThread)
+static UINT rdpsnd_server_initialize(RdpsndServerContext* context,
+ BOOL ownThread)
{
context->priv->ownThread = ownThread;
return context->Start(context);
*
* @return 0 on success, otherwise a Win32 error code
*/
-static UINT rdpsnd_server_select_format(RdpsndServerContext* context, int client_format_index)
+static UINT rdpsnd_server_select_format(RdpsndServerContext* context,
+ int client_format_index)
{
int bs;
int out_buffer_size;
- AUDIO_FORMAT *format;
+ AUDIO_FORMAT* format;
UINT error = CHANNEL_RC_OK;
- if (client_format_index < 0 || client_format_index >= context->num_client_formats)
+ if (client_format_index < 0
+ || client_format_index >= context->num_client_formats)
{
WLog_ERR(TAG, "index %d is not correct.", client_format_index);
return ERROR_INVALID_DATA;
}
EnterCriticalSection(&context->priv->lock);
-
context->priv->src_bytes_per_sample = context->src_format.wBitsPerSample / 8;
- context->priv->src_bytes_per_frame = context->priv->src_bytes_per_sample * context->src_format.nChannels;
-
+ context->priv->src_bytes_per_frame = context->priv->src_bytes_per_sample *
+ context->src_format.nChannels;
context->selected_client_format = client_format_index;
format = &context->client_formats[client_format_index];
if (context->latency <= 0)
context->latency = 50;
- context->priv->out_frames = context->src_format.nSamplesPerSec * context->latency / 1000;
+
+ context->priv->out_frames = context->src_format.nSamplesPerSec *
+ context->latency / 1000;
+
if (context->priv->out_frames < 1)
context->priv->out_frames = 1;
- switch(format->wFormatTag)
+
+ switch (format->wFormatTag)
{
case WAVE_FORMAT_DVI_ADPCM:
bs = (format->nBlockAlign - 4 * format->nChannels) * 4;
context->priv->out_frames -= context->priv->out_frames % bs;
+
if (context->priv->out_frames < bs)
context->priv->out_frames = bs;
+
break;
case WAVE_FORMAT_ADPCM:
bs = (format->nBlockAlign - 7 * format->nChannels) * 2 / format->nChannels + 2;
context->priv->out_frames -= context->priv->out_frames % bs;
+
if (context->priv->out_frames < bs)
context->priv->out_frames = bs;
+
break;
}
- context->priv->out_pending_frames = 0;
- out_buffer_size = context->priv->out_frames * context->priv->src_bytes_per_frame;
+ context->priv->out_pending_frames = 0;
+ out_buffer_size = context->priv->out_frames *
+ context->priv->src_bytes_per_frame;
if (context->priv->out_buffer_size < out_buffer_size)
{
- BYTE *newBuffer;
+ BYTE* newBuffer;
+ newBuffer = (BYTE*)realloc(context->priv->out_buffer, out_buffer_size);
- newBuffer = (BYTE *)realloc(context->priv->out_buffer, out_buffer_size);
if (!newBuffer)
{
WLog_ERR(TAG, "realloc failed!");
}
freerdp_dsp_context_reset_adpcm(context->priv->dsp_context);
-
out:
LeaveCriticalSection(&context->priv->lock);
return error;
*
* @return 0 on success, otherwise a Win32 error code
*/
-static UINT rdpsnd_server_send_audio_pdu(RdpsndServerContext* context, UINT16 wTimestamp)
+static UINT rdpsnd_server_send_audio_pdu(RdpsndServerContext* context,
+ UINT16 wTimestamp)
{
int size;
BYTE* src;
ULONG written;
wStream* s = context->priv->rdpsnd_pdu;
UINT error = CHANNEL_RC_OK;
-
format = &context->client_formats[context->selected_client_format];
tbytes_per_frame = format->nChannels * context->priv->src_bytes_per_sample;
if ((format->nSamplesPerSec == context->src_format.nSamplesPerSec) &&
- (format->nChannels == context->src_format.nChannels))
+ (format->nChannels == context->src_format.nChannels))
{
src = context->priv->out_buffer;
frames = context->priv->out_pending_frames;
}
else
{
- context->priv->dsp_context->resample(context->priv->dsp_context, context->priv->out_buffer,
- context->priv->src_bytes_per_sample, context->src_format.nChannels,
- context->src_format.nSamplesPerSec, context->priv->out_pending_frames,
- format->nChannels, format->nSamplesPerSec);
+ context->priv->dsp_context->resample(context->priv->dsp_context,
+ context->priv->out_buffer,
+ context->priv->src_bytes_per_sample, context->src_format.nChannels,
+ context->src_format.nSamplesPerSec, context->priv->out_pending_frames,
+ format->nChannels, format->nSamplesPerSec);
frames = context->priv->dsp_context->resampled_frames;
src = context->priv->dsp_context->resampled_buffer;
}
+
size = frames * tbytes_per_frame;
if (format->wFormatTag == WAVE_FORMAT_DVI_ADPCM)
{
context->priv->dsp_context->encode_ima_adpcm(context->priv->dsp_context,
- src, size, format->nChannels, format->nBlockAlign);
+ src, size, format->nChannels, format->nBlockAlign);
src = context->priv->dsp_context->adpcm_buffer;
size = context->priv->dsp_context->adpcm_size;
}
else if (format->wFormatTag == WAVE_FORMAT_ADPCM)
{
context->priv->dsp_context->encode_ms_adpcm(context->priv->dsp_context,
- src, size, format->nChannels, format->nBlockAlign);
+ src, size, format->nChannels, format->nBlockAlign);
src = context->priv->dsp_context->adpcm_buffer;
size = context->priv->dsp_context->adpcm_size;
}
context->block_no = (context->block_no + 1) % 256;
-
/* Fill to nBlockAlign for the last audio packet */
-
fill_size = 0;
- if ((format->wFormatTag == WAVE_FORMAT_DVI_ADPCM || format->wFormatTag == WAVE_FORMAT_ADPCM) &&
- (context->priv->out_pending_frames < context->priv->out_frames) && ((size % format->nBlockAlign) != 0))
+ if ((format->wFormatTag == WAVE_FORMAT_DVI_ADPCM
+ || format->wFormatTag == WAVE_FORMAT_ADPCM) &&
+ (context->priv->out_pending_frames < context->priv->out_frames)
+ && ((size % format->nBlockAlign) != 0))
{
fill_size = format->nBlockAlign - (size % format->nBlockAlign);
}
Stream_Write_UINT8(s, SNDC_WAVE); /* msgType */
Stream_Write_UINT8(s, 0); /* bPad */
Stream_Write_UINT16(s, size + fill_size + 8); /* BodySize */
-
Stream_Write_UINT16(s, wTimestamp); /* wTimeStamp */
Stream_Write_UINT16(s, context->selected_client_format); /* wFormatNo */
Stream_Write_UINT8(s, context->block_no); /* cBlockNo */
Stream_Seek(s, 3); /* bPad */
Stream_Write(s, src, 4);
+ status = WTSVirtualChannelWrite(context->priv->ChannelHandle,
+ (PCHAR) Stream_Buffer(s), Stream_GetPosition(s), &written);
- status = WTSVirtualChannelWrite(context->priv->ChannelHandle, (PCHAR) Stream_Buffer(s), Stream_GetPosition(s), &written);
if (!status)
{
WLog_ERR(TAG, "WTSVirtualChannelWrite failed!");
error = CHANNEL_RC_NO_MEMORY;
goto out;
}
+
Stream_Write_UINT32(s, 0); /* bPad */
Stream_Write(s, src + 4, size - 4);
if (fill_size > 0)
Stream_Zero(s, fill_size);
- status = WTSVirtualChannelWrite(context->priv->ChannelHandle, (PCHAR) Stream_Buffer(s), Stream_GetPosition(s), &written);
+ status = WTSVirtualChannelWrite(context->priv->ChannelHandle,
+ (PCHAR) Stream_Buffer(s), Stream_GetPosition(s), &written);
if (!status)
{
*
* @return 0 on success, otherwise a Win32 error code
*/
-static UINT rdpsnd_server_send_samples(RdpsndServerContext* context, const void* buf, int nframes, UINT16 wTimestamp)
+static UINT rdpsnd_server_send_samples(RdpsndServerContext* context,
+ const void* buf, int nframes, UINT16 wTimestamp)
{
int cframes;
int cframesize;
UINT error = CHANNEL_RC_OK;
-
EnterCriticalSection(&context->priv->lock);
if (context->selected_client_format < 0)
while (nframes > 0)
{
- cframes = MIN(nframes, context->priv->out_frames - context->priv->out_pending_frames);
+ cframes = MIN(nframes, context->priv->out_frames -
+ context->priv->out_pending_frames);
cframesize = cframes * context->priv->src_bytes_per_frame;
-
CopyMemory(context->priv->out_buffer +
- (context->priv->out_pending_frames * context->priv->src_bytes_per_frame), buf, cframesize);
+ (context->priv->out_pending_frames * context->priv->src_bytes_per_frame), buf,
+ cframesize);
buf = (BYTE*) buf + cframesize;
nframes -= cframes;
context->priv->out_pending_frames += cframes;
*
* @return 0 on success, otherwise a Win32 error code
*/
-static UINT rdpsnd_server_set_volume(RdpsndServerContext* context, int left, int right)
+static UINT rdpsnd_server_set_volume(RdpsndServerContext* context, int left,
+ int right)
{
int pos;
BOOL status;
ULONG written;
wStream* s = context->priv->rdpsnd_pdu;
-
Stream_Write_UINT8(s, SNDC_SETVOLUME);
Stream_Write_UINT8(s, 0);
Stream_Seek_UINT16(s);
-
Stream_Write_UINT16(s, left);
Stream_Write_UINT16(s, right);
-
pos = Stream_GetPosition(s);
Stream_SetPosition(s, 2);
Stream_Write_UINT16(s, pos - 4);
Stream_SetPosition(s, pos);
- status = WTSVirtualChannelWrite(context->priv->ChannelHandle, (PCHAR) Stream_Buffer(s), Stream_GetPosition(s), &written);
+ status = WTSVirtualChannelWrite(context->priv->ChannelHandle,
+ (PCHAR) Stream_Buffer(s), Stream_GetPosition(s), &written);
Stream_SetPosition(s, 0);
-
return status ? CHANNEL_RC_OK : ERROR_INTERNAL_ERROR;
}
ULONG written;
wStream* s = context->priv->rdpsnd_pdu;
UINT error = CHANNEL_RC_OK;
-
EnterCriticalSection(&context->priv->lock);
if (context->priv->out_pending_frames > 0)
return error;
context->selected_client_format = -1;
-
Stream_Write_UINT8(s, SNDC_CLOSE);
Stream_Write_UINT8(s, 0);
Stream_Seek_UINT16(s);
-
pos = Stream_GetPosition(s);
Stream_SetPosition(s, 2);
Stream_Write_UINT16(s, pos - 4);
Stream_SetPosition(s, pos);
- status = WTSVirtualChannelWrite(context->priv->ChannelHandle, (PCHAR) Stream_Buffer(s), Stream_GetPosition(s), &written);
+ status = WTSVirtualChannelWrite(context->priv->ChannelHandle,
+ (PCHAR) Stream_Buffer(s), Stream_GetPosition(s), &written);
Stream_SetPosition(s, 0);
-
return status ? CHANNEL_RC_OK : ERROR_INTERNAL_ERROR;
}
*/
static UINT rdpsnd_server_start(RdpsndServerContext* context)
{
- void *buffer = NULL;
+ void* buffer = NULL;
DWORD bytesReturned;
- RdpsndServerPrivate *priv = context->priv;
+ RdpsndServerPrivate* priv = context->priv;
UINT error = ERROR_INTERNAL_ERROR;
+ priv->ChannelHandle = WTSVirtualChannelOpen(context->vcm, WTS_CURRENT_SESSION,
+ "rdpsnd");
- priv->ChannelHandle = WTSVirtualChannelOpen(context->vcm, WTS_CURRENT_SESSION, "rdpsnd");
if (!priv->ChannelHandle)
{
WLog_ERR(TAG, "WTSVirtualChannelOpen failed!");
return ERROR_INTERNAL_ERROR;
}
- if (!WTSVirtualChannelQuery(priv->ChannelHandle, WTSVirtualEventHandle, &buffer, &bytesReturned) || (bytesReturned != sizeof(HANDLE)))
+ if (!WTSVirtualChannelQuery(priv->ChannelHandle, WTSVirtualEventHandle, &buffer,
+ &bytesReturned) || (bytesReturned != sizeof(HANDLE)))
{
- WLog_ERR(TAG, "error during WTSVirtualChannelQuery(WTSVirtualEventHandle) or invalid returned size(%d)",
- bytesReturned);
+ WLog_ERR(TAG,
+ "error during WTSVirtualChannelQuery(WTSVirtualEventHandle) or invalid returned size(%d)",
+ bytesReturned);
if (buffer)
WTSFreeMemory(buffer);
+
goto out_close;
}
+
CopyMemory(&priv->channelEvent, buffer, sizeof(HANDLE));
WTSFreeMemory(buffer);
-
priv->rdpsnd_pdu = Stream_New(NULL, 4096);
+
if (!priv->rdpsnd_pdu)
{
WLog_ERR(TAG, "Stream_New failed!");
if (priv->ownThread)
{
context->priv->StopEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
+
if (!context->priv->StopEvent)
{
WLog_ERR(TAG, "CreateEvent failed!");
}
context->priv->Thread = CreateThread(NULL, 0,
- (LPTHREAD_START_ROUTINE) rdpsnd_server_thread, (void*) context, 0, NULL);
+ (LPTHREAD_START_ROUTINE) rdpsnd_server_thread, (void*) context, 0, NULL);
+
if (!context->priv->Thread)
{
WLog_ERR(TAG, "CreateThread failed!");
goto out_stopEvent;
}
-
}
return CHANNEL_RC_OK;
-
out_stopEvent:
CloseHandle(context->priv->StopEvent);
context->priv->StopEvent = NULL;
*/
static UINT rdpsnd_server_stop(RdpsndServerContext* context)
{
- UINT error = CHANNEL_RC_OK;
+ UINT error = CHANNEL_RC_OK;
+
if (context->priv->ownThread)
{
if (context->priv->StopEvent)
SetEvent(context->priv->StopEvent);
if (WaitForSingleObject(context->priv->Thread, INFINITE) == WAIT_FAILED)
- {
- error = GetLastError();
- WLog_ERR(TAG, "WaitForSingleObject failed with error %lu!", error);
- return error;
- }
+ {
+ error = GetLastError();
+ WLog_ERR(TAG, "WaitForSingleObject failed with error %lu!", error);
+ return error;
+ }
+
CloseHandle(context->priv->Thread);
CloseHandle(context->priv->StopEvent);
}
RdpsndServerContext* rdpsnd_server_context_new(HANDLE vcm)
{
RdpsndServerContext* context;
- RdpsndServerPrivate *priv;
+ RdpsndServerPrivate* priv;
+ context = (RdpsndServerContext*)calloc(1, sizeof(RdpsndServerContext));
- context = (RdpsndServerContext *)calloc(1, sizeof(RdpsndServerContext));
if (!context)
{
WLog_ERR(TAG, "calloc failed!");
}
context->vcm = vcm;
-
context->Start = rdpsnd_server_start;
context->Stop = rdpsnd_server_stop;
-
context->selected_client_format = -1;
context->Initialize = rdpsnd_server_initialize;
context->SelectFormat = rdpsnd_server_select_format;
context->SendSamples = rdpsnd_server_send_samples;
context->SetVolume = rdpsnd_server_set_volume;
context->Close = rdpsnd_server_close;
+ context->priv = priv = (RdpsndServerPrivate*)calloc(1,
+ sizeof(RdpsndServerPrivate));
- context->priv = priv = (RdpsndServerPrivate *)calloc(1, sizeof(RdpsndServerPrivate));
if (!priv)
{
WLog_ERR(TAG, "calloc failed!");
}
priv->dsp_context = freerdp_dsp_context_new();
+
if (!priv->dsp_context)
{
WLog_ERR(TAG, "freerdp_dsp_context_new failed!");
}
priv->input_stream = Stream_New(NULL, 4);
+
if (!priv->input_stream)
{
WLog_ERR(TAG, "Stream_New failed!");
priv->waitingHeader = TRUE;
priv->ownThread = TRUE;
return context;
-
out_free_dsp:
freerdp_dsp_context_free(priv->dsp_context);
out_free_priv:
}
-void rdpsnd_server_context_reset(RdpsndServerContext *context)
+void rdpsnd_server_context_reset(RdpsndServerContext* context)
{
context->priv->expectedBytes = 4;
context->priv->waitingHeader = TRUE;
-
Stream_SetPosition(context->priv->input_stream, 0);
}
Stream_Free(context->priv->input_stream, TRUE);
free(context->client_formats);
-
free(context->priv);
-
free(context);
}
-HANDLE rdpsnd_server_get_event_handle(RdpsndServerContext *context)
+HANDLE rdpsnd_server_get_event_handle(RdpsndServerContext* context)
{
return context->priv->channelEvent;
}
*
* @return 0 on success, otherwise a Win32 error code
*/
-UINT rdpsnd_server_handle_messages(RdpsndServerContext *context)
+UINT rdpsnd_server_handle_messages(RdpsndServerContext* context)
{
DWORD bytesReturned;
UINT ret = CHANNEL_RC_OK;
+ RdpsndServerPrivate* priv = context->priv;
+ wStream* s = priv->input_stream;
- RdpsndServerPrivate *priv = context->priv;
- wStream *s = priv->input_stream;
-
- if (!WTSVirtualChannelRead(priv->ChannelHandle, 0, (PCHAR)Stream_Pointer(s), priv->expectedBytes, &bytesReturned))
+ if (!WTSVirtualChannelRead(priv->ChannelHandle, 0, (PCHAR)Stream_Pointer(s),
+ priv->expectedBytes, &bytesReturned))
{
if (GetLastError() == ERROR_NO_DATA)
return ERROR_NO_DATA;
WLog_ERR(TAG, "channel connection closed");
return ERROR_INTERNAL_ERROR;
}
+
priv->expectedBytes -= bytesReturned;
Stream_Seek(s, bytesReturned);
Stream_SealLength(s);
Stream_SetPosition(s, 0);
+
if (priv->waitingHeader)
{
/* header case */
Stream_Read_UINT8(s, priv->msgType);
Stream_Seek_UINT8(s); /* bPad */
Stream_Read_UINT16(s, priv->expectedBytes);
-
priv->waitingHeader = FALSE;
Stream_SetPosition(s, 0);
+
if (priv->expectedBytes)
{
if (!Stream_EnsureCapacity(s, priv->expectedBytes))
WLog_ERR(TAG, "Stream_EnsureCapacity failed!");
return CHANNEL_RC_NO_MEMORY;
}
+
return CHANNEL_RC_OK;
}
}
case SNDC_QUALITYMODE:
ret = rdpsnd_server_recv_quality_mode(context, s);
- Stream_SetPosition(s, 0); /* in case the Activated callback tries to treat some messages */
+ Stream_SetPosition(s,
+ 0); /* in case the Activated callback tries to treat some messages */
if ((ret == CHANNEL_RC_OK) && (context->clientVersion >= 6))
IFCALL(context->Activated, context);
+
break;
default:
ret = ERROR_INVALID_DATA;
break;
}
- Stream_SetPosition(s, 0);
+ Stream_SetPosition(s, 0);
return ret;
}
}
status = remdesk->channelEntryPoints.pVirtualChannelWrite(remdesk->OpenHandle,
- Stream_Buffer(s), (UINT32) Stream_Length(s), s);
+ Stream_Buffer(s), (UINT32) Stream_Length(s), s);
if (status != CHANNEL_RC_OK)
WLog_ERR(TAG, "VirtualChannelWrite failed with %s [%08X]",
- WTSErrorToString(status), status);
+ WTSErrorToString(status), status);
return status;
}
name = "Expert";
remdesk->EncryptedPassStub = freerdp_assistance_encrypt_pass_stub(password,
- settings->RemoteAssistancePassStub, &(remdesk->EncryptedPassStubSize));
+ settings->RemoteAssistancePassStub, &(remdesk->EncryptedPassStubSize));
if (!remdesk->EncryptedPassStub)
{
}
pass = freerdp_assistance_bin_to_hex_string(remdesk->EncryptedPassStub,
- remdesk->EncryptedPassStubSize);
+ remdesk->EncryptedPassStubSize);
if (!pass)
{
* @return 0 on success, otherwise a Win32 error code
*/
static UINT remdesk_read_channel_header(wStream* s,
- REMDESK_CHANNEL_HEADER* header)
+ REMDESK_CHANNEL_HEADER* header)
{
int status;
UINT32 ChannelNameLen;
ZeroMemory(header->ChannelName, sizeof(header->ChannelName));
pChannelName = (char*) header->ChannelName;
status = ConvertFromUnicode(CP_UTF8, 0, (WCHAR*) Stream_Pointer(s),
- ChannelNameLen / 2, &pChannelName, 32, NULL, NULL);
+ ChannelNameLen / 2, &pChannelName, 32, NULL, NULL);
Stream_Seek(s, ChannelNameLen);
if (status <= 0)
* @return 0 on success, otherwise a Win32 error code
*/
static UINT remdesk_write_channel_header(wStream* s,
- REMDESK_CHANNEL_HEADER* header)
+ REMDESK_CHANNEL_HEADER* header)
{
int index;
UINT32 ChannelNameLen;
* @return 0 on success, otherwise a Win32 error code
*/
static UINT remdesk_prepare_ctl_header(REMDESK_CTL_HEADER* ctlHeader,
- UINT32 msgType, UINT32 msgSize)
+ UINT32 msgType, UINT32 msgSize)
{
ctlHeader->msgType = msgType;
strcpy(ctlHeader->ChannelName, REMDESK_CHANNEL_CTL_NAME);
* @return 0 on success, otherwise a Win32 error code
*/
static UINT remdesk_recv_ctl_server_announce_pdu(remdeskPlugin* remdesk,
- wStream* s, REMDESK_CHANNEL_HEADER* header)
+ wStream* s, REMDESK_CHANNEL_HEADER* header)
{
return CHANNEL_RC_OK;
}
* @return 0 on success, otherwise a Win32 error code
*/
static UINT remdesk_recv_ctl_version_info_pdu(remdeskPlugin* remdesk,
- wStream* s, REMDESK_CHANNEL_HEADER* header)
+ wStream* s, REMDESK_CHANNEL_HEADER* header)
{
UINT32 versionMajor;
UINT32 versionMinor;
* @return 0 on success, otherwise a Win32 error code
*/
static UINT remdesk_recv_ctl_result_pdu(remdeskPlugin* remdesk, wStream* s,
- REMDESK_CHANNEL_HEADER* header, UINT32* pResult)
+ REMDESK_CHANNEL_HEADER* header, UINT32* pResult)
{
UINT32 result;
pdu.expertBlob = remdesk->ExpertBlob;
pdu.raConnectionString = remdesk->settings->RemoteAssistanceRCTicket;
status = ConvertToUnicode(CP_UTF8, 0, pdu.raConnectionString, -1,
- &raConnectionStringW, 0);
+ &raConnectionStringW, 0);
if (status <= 0)
{
cbExpertBlobW = status * 2;
remdesk_prepare_ctl_header(&(pdu.ctlHeader), REMDESK_CTL_AUTHENTICATE,
- cbRaConnectionStringW + cbExpertBlobW);
+ cbRaConnectionStringW + cbExpertBlobW);
s = Stream_New(NULL, REMDESK_CHANNEL_CTL_SIZE + pdu.ctlHeader.DataLength);
if (!s)
REMDESK_CTL_REMOTE_CONTROL_DESKTOP_PDU pdu;
pdu.raConnectionString = remdesk->settings->RemoteAssistanceRCTicket;
status = ConvertToUnicode(CP_UTF8, 0, pdu.raConnectionString, -1,
- &raConnectionStringW, 0);
+ &raConnectionStringW, 0);
if (status <= 0)
{
cbRaConnectionStringW = status * 2;
remdesk_prepare_ctl_header(&(pdu.ctlHeader), REMDESK_CTL_REMOTE_CONTROL_DESKTOP,
- cbRaConnectionStringW);
+ cbRaConnectionStringW);
s = Stream_New(NULL, REMDESK_CHANNEL_CTL_SIZE + pdu.ctlHeader.DataLength);
if (!s)
cbExpertBlobW = status * 2;
remdesk_prepare_ctl_header(&(pdu.ctlHeader), REMDESK_CTL_VERIFY_PASSWORD,
- cbExpertBlobW);
+ cbExpertBlobW);
s = Stream_New(NULL, REMDESK_CHANNEL_CTL_SIZE + pdu.ctlHeader.DataLength);
if (!s)
pdu.EncryptedPasswordLength = remdesk->EncryptedPassStubSize;
pdu.EncryptedPassword = remdesk->EncryptedPassStub;
remdesk_prepare_ctl_header(&(pdu.ctlHeader), REMDESK_CTL_EXPERT_ON_VISTA,
- pdu.EncryptedPasswordLength);
+ pdu.EncryptedPasswordLength);
s = Stream_New(NULL, REMDESK_CHANNEL_CTL_SIZE + pdu.ctlHeader.DataLength);
if (!s)
* @return 0 on success, otherwise a Win32 error code
*/
static UINT remdesk_recv_ctl_pdu(remdeskPlugin* remdesk, wStream* s,
- REMDESK_CHANNEL_HEADER* header)
+ REMDESK_CHANNEL_HEADER* header)
{
UINT error = CHANNEL_RC_OK;
UINT32 msgType = 0;
case REMDESK_CTL_SERVER_ANNOUNCE:
if ((error = remdesk_recv_ctl_server_announce_pdu(remdesk, s, header)))
WLog_ERR(TAG, "remdesk_recv_ctl_server_announce_pdu failed with error %lu",
- error);
+ error);
break;
if ((error = remdesk_send_ctl_remote_control_desktop_pdu(remdesk)))
{
WLog_ERR(TAG,
- "remdesk_send_ctl_remote_control_desktop_pdu failed with error %lu", error);
+ "remdesk_send_ctl_remote_control_desktop_pdu failed with error %lu", error);
break;
}
}
if ((error = remdesk_send_ctl_expert_on_vista_pdu(remdesk)))
{
WLog_ERR(TAG, "remdesk_send_ctl_expert_on_vista_pdu failed with error %lu",
- error);
+ error);
break;
}
if ((error = remdesk_send_ctl_verify_password_pdu(remdesk)))
{
WLog_ERR(TAG, "remdesk_send_ctl_verify_password_pdu failed with error %lu",
- error);
+ error);
break;
}
}
else
{
status = plugin->channelEntryPoints.pVirtualChannelWrite(plugin->OpenHandle,
- Stream_Buffer(s), (UINT32) Stream_GetPosition(s), s);
+ Stream_Buffer(s), (UINT32) Stream_GetPosition(s), s);
}
if (status != CHANNEL_RC_OK)
{
Stream_Free(s, TRUE);
WLog_ERR(TAG, "VirtualChannelWrite failed with %s [%08X]",
- WTSErrorToString(status), status);
+ WTSErrorToString(status), status);
}
return status;
* @return 0 on success, otherwise a Win32 error code
*/
static UINT remdesk_virtual_channel_event_data_received(remdeskPlugin* remdesk,
- void* pData, UINT32 dataLength, UINT32 totalLength, UINT32 dataFlags)
+ void* pData, UINT32 dataLength, UINT32 totalLength, UINT32 dataFlags)
{
wStream* data_in;
}
static VOID VCAPITYPE remdesk_virtual_channel_open_event(DWORD openHandle,
- UINT event,
- LPVOID pData, UINT32 dataLength, UINT32 totalLength, UINT32 dataFlags)
+ UINT event,
+ LPVOID pData, UINT32 dataLength, UINT32 totalLength, UINT32 dataFlags)
{
remdeskPlugin* remdesk = s_TLSPluginContext;
UINT error = CHANNEL_RC_OK;
{
case CHANNEL_EVENT_DATA_RECEIVED:
if ((error = remdesk_virtual_channel_event_data_received(remdesk, pData,
- dataLength, totalLength, dataFlags)))
+ dataLength, totalLength, dataFlags)))
WLog_ERR(TAG,
- "remdesk_virtual_channel_event_data_received failed with error %lu!", error);
+ "remdesk_virtual_channel_event_data_received failed with error %lu!", error);
break;
if (error && remdesk->rdpcontext)
setChannelError(remdesk->rdpcontext, error,
- "remdesk_virtual_channel_open_event reported an error");
+ "remdesk_virtual_channel_open_event reported an error");
}
static void* remdesk_virtual_channel_client_thread(void* arg)
wMessage message;
remdeskPlugin* remdesk = (remdeskPlugin*) arg;
UINT error = CHANNEL_RC_OK;
-
freerdp_channel_init_thread_context(remdesk->rdpcontext);
remdesk_process_connect(remdesk);
if (error && remdesk->rdpcontext)
setChannelError(remdesk->rdpcontext, error,
- "remdesk_virtual_channel_client_thread reported an error");
+ "remdesk_virtual_channel_client_thread reported an error");
ExitThread((DWORD)error);
return NULL;
* @return 0 on success, otherwise a Win32 error code
*/
static UINT remdesk_virtual_channel_event_connected(remdeskPlugin* remdesk,
- LPVOID pData, UINT32 dataLength)
+ LPVOID pData, UINT32 dataLength)
{
UINT32 status;
UINT error;
status = remdesk->channelEntryPoints.pVirtualChannelOpen(remdesk->InitHandle,
- &remdesk->OpenHandle, remdesk->channelDef.name,
- remdesk_virtual_channel_open_event);
+ &remdesk->OpenHandle, remdesk->channelDef.name,
+ remdesk_virtual_channel_open_event);
if (status != CHANNEL_RC_OK)
{
WLog_ERR(TAG, "pVirtualChannelOpen failed with %s [%08X]",
- WTSErrorToString(status), status);
+ WTSErrorToString(status), status);
return status;
}
}
remdesk->thread = CreateThread(NULL, 0,
- (LPTHREAD_START_ROUTINE) remdesk_virtual_channel_client_thread, (void*) remdesk,
- 0, NULL);
+ (LPTHREAD_START_ROUTINE) remdesk_virtual_channel_client_thread, (void*) remdesk,
+ 0, NULL);
if (!remdesk->thread)
{
if (CHANNEL_RC_OK != rc)
{
WLog_ERR(TAG, "pVirtualChannelClose failed with %s [%08X]",
- WTSErrorToString(rc), rc);
+ WTSErrorToString(rc), rc);
}
remdesk->OpenHandle = 0;
}
static VOID VCAPITYPE remdesk_virtual_channel_init_event(LPVOID pInitHandle,
- UINT event, LPVOID pData,
- UINT dataLength)
+ UINT event, LPVOID pData,
+ UINT dataLength)
{
remdeskPlugin* remdesk = s_TLSPluginContext;
UINT error = CHANNEL_RC_OK;
{
case CHANNEL_EVENT_CONNECTED:
if ((error = remdesk_virtual_channel_event_connected(remdesk, pData,
- dataLength)))
+ dataLength)))
WLog_ERR(TAG, "remdesk_virtual_channel_event_connected failed with error %lu",
- error);
+ error);
break;
case CHANNEL_EVENT_DISCONNECTED:
if ((error = remdesk_virtual_channel_event_disconnected(remdesk)))
WLog_ERR(TAG,
- "remdesk_virtual_channel_event_disconnected failed with error %lu", error);
+ "remdesk_virtual_channel_event_disconnected failed with error %lu", error);
break;
if (error && remdesk->rdpcontext)
setChannelError(remdesk->rdpcontext, error,
- "remdesk_virtual_channel_init_event reported an error");
+ "remdesk_virtual_channel_init_event reported an error");
}
/* remdesk is always built-in */
}
CopyMemory(&(remdesk->channelEntryPoints), pEntryPoints,
- sizeof(CHANNEL_ENTRY_POINTS_FREERDP));
+ sizeof(CHANNEL_ENTRY_POINTS_FREERDP));
rc = remdesk->channelEntryPoints.pVirtualChannelInit(&remdesk->InitHandle,
- &remdesk->channelDef, 1, VIRTUAL_CHANNEL_VERSION_WIN2000,
- remdesk_virtual_channel_init_event);
+ &remdesk->channelDef, 1, VIRTUAL_CHANNEL_VERSION_WIN2000,
+ remdesk_virtual_channel_init_event);
if (CHANNEL_RC_OK != rc)
{
WLog_ERR(TAG, "pVirtualChannelInit failed with %s [%08X]",
- WTSErrorToString(rc), rc);
+ WTSErrorToString(rc), rc);
goto error_out;
}
remdesk->channelEntryPoints.pInterface = *
- (remdesk->channelEntryPoints.ppInterface);
+ (remdesk->channelEntryPoints.ppInterface);
remdesk->channelEntryPoints.ppInterface = &
- (remdesk->channelEntryPoints.pInterface);
+ (remdesk->channelEntryPoints.pInterface);
s_TLSPluginContext = remdesk;
return TRUE;
error_out:
+
if (context)
*(pEntryPointsEx->ppInterface) = NULL;
+
free(remdesk);
free(context);
return FALSE;
*
* @return 0 on success, otherwise a Win32 error code
*/
-static UINT remdesk_virtual_channel_write(RemdeskServerContext* context, wStream* s)
+static UINT remdesk_virtual_channel_write(RemdeskServerContext* context,
+ wStream* s)
{
BOOL status;
ULONG BytesWritten = 0;
-
status = WTSVirtualChannelWrite(context->priv->ChannelHandle,
- (PCHAR) Stream_Buffer(s), Stream_Length(s), &BytesWritten);
-
+ (PCHAR) Stream_Buffer(s), Stream_Length(s), &BytesWritten);
return (status) ? CHANNEL_RC_OK : ERROR_INTERNAL_ERROR;
}
*
* @return 0 on success, otherwise a Win32 error code
*/
-static UINT remdesk_read_channel_header(wStream* s, REMDESK_CHANNEL_HEADER* header)
+static UINT remdesk_read_channel_header(wStream* s,
+ REMDESK_CHANNEL_HEADER* header)
{
int status;
UINT32 ChannelNameLen;
}
ZeroMemory(header->ChannelName, sizeof(header->ChannelName));
-
pChannelName = (char*) header->ChannelName;
status = ConvertFromUnicode(CP_UTF8, 0, (WCHAR*) Stream_Pointer(s),
- ChannelNameLen / 2, &pChannelName, 32, NULL, NULL);
-
+ ChannelNameLen / 2, &pChannelName, 32, NULL, NULL);
Stream_Seek(s, ChannelNameLen);
if (status <= 0)
*
* @return 0 on success, otherwise a Win32 error code
*/
-static UINT remdesk_write_channel_header(wStream* s, REMDESK_CHANNEL_HEADER* header)
+static UINT remdesk_write_channel_header(wStream* s,
+ REMDESK_CHANNEL_HEADER* header)
{
int index;
UINT32 ChannelNameLen;
WCHAR ChannelNameW[32];
-
ZeroMemory(ChannelNameW, sizeof(ChannelNameW));
for (index = 0; index < 32; index++)
}
ChannelNameLen = (strlen(header->ChannelName) + 1) * 2;
-
Stream_Write_UINT32(s, ChannelNameLen); /* ChannelNameLen (4 bytes) */
Stream_Write_UINT32(s, header->DataLength); /* DataLen (4 bytes) */
-
Stream_Write(s, ChannelNameW, ChannelNameLen); /* ChannelName (variable) */
-
return CHANNEL_RC_OK;
}
static UINT remdesk_write_ctl_header(wStream* s, REMDESK_CTL_HEADER* ctlHeader)
{
UINT error;
- if ((error = remdesk_write_channel_header(s, (REMDESK_CHANNEL_HEADER*) ctlHeader)))
+
+ if ((error = remdesk_write_channel_header(s,
+ (REMDESK_CHANNEL_HEADER*) ctlHeader)))
{
WLog_ERR(TAG, "remdesk_write_channel_header failed with error %lu!", error);
return error;
}
+
Stream_Write_UINT32(s, ctlHeader->msgType); /* msgType (4 bytes) */
return CHANNEL_RC_OK;
}
*
* @return 0 on success, otherwise a Win32 error code
*/
-static UINT remdesk_prepare_ctl_header(REMDESK_CTL_HEADER* ctlHeader, UINT32 msgType, UINT32 msgSize)
+static UINT remdesk_prepare_ctl_header(REMDESK_CTL_HEADER* ctlHeader,
+ UINT32 msgType, UINT32 msgSize)
{
ctlHeader->msgType = msgType;
strcpy(ctlHeader->ChannelName, REMDESK_CHANNEL_CTL_NAME);
*
* @return 0 on success, otherwise a Win32 error code
*/
-static UINT remdesk_send_ctl_result_pdu(RemdeskServerContext* context, UINT32 result)
+static UINT remdesk_send_ctl_result_pdu(RemdeskServerContext* context,
+ UINT32 result)
{
wStream* s;
REMDESK_CTL_RESULT_PDU pdu;
UINT error;
-
pdu.result = result;
- if ((error = remdesk_prepare_ctl_header(&(pdu.ctlHeader), REMDESK_CTL_RESULT, 4)))
+ if ((error = remdesk_prepare_ctl_header(&(pdu.ctlHeader), REMDESK_CTL_RESULT,
+ 4)))
{
WLog_ERR(TAG, "remdesk_prepare_ctl_header failed with error %lu!", error);
return error;
}
s = Stream_New(NULL, REMDESK_CHANNEL_CTL_SIZE + pdu.ctlHeader.DataLength);
+
if (!s)
{
WLog_ERR(TAG, "Stream_New failed!");
goto out;
}
-
Stream_Write_UINT32(s, pdu.result); /* result (4 bytes) */
-
Stream_SealLength(s);
if ((error = remdesk_virtual_channel_write(context, s)))
WLog_ERR(TAG, "remdesk_virtual_channel_write failed with error %lu!", error);
+
out:
Stream_Free(s, TRUE);
-
return error;
}
REMDESK_CTL_VERSION_INFO_PDU pdu;
UINT error;
- if ((error = remdesk_prepare_ctl_header(&(pdu.ctlHeader), REMDESK_CTL_VERSIONINFO, 8)))
+ if ((error = remdesk_prepare_ctl_header(&(pdu.ctlHeader),
+ REMDESK_CTL_VERSIONINFO, 8)))
{
WLog_ERR(TAG, "remdesk_prepare_ctl_header failed with error %lu!", error);
return error;
pdu.versionMajor = 1;
pdu.versionMinor = 2;
-
s = Stream_New(NULL, REMDESK_CHANNEL_CTL_SIZE + pdu.ctlHeader.DataLength);
+
if (!s)
{
WLog_ERR(TAG, "Stream_New failed!");
Stream_Write_UINT32(s, pdu.versionMajor); /* versionMajor (4 bytes) */
Stream_Write_UINT32(s, pdu.versionMinor); /* versionMinor (4 bytes) */
-
Stream_SealLength(s);
if ((error = remdesk_virtual_channel_write(context, s)))
WLog_ERR(TAG, "remdesk_virtual_channel_write failed with error %lu!", error);
+
out:
Stream_Free(s, TRUE);
-
return error;
}
*
* @return 0 on success, otherwise a Win32 error code
*/
-static UINT remdesk_recv_ctl_version_info_pdu(RemdeskServerContext* context, wStream* s, REMDESK_CHANNEL_HEADER* header)
+static UINT remdesk_recv_ctl_version_info_pdu(RemdeskServerContext* context,
+ wStream* s, REMDESK_CHANNEL_HEADER* header)
{
UINT32 versionMajor;
UINT32 versionMinor;
Stream_Read_UINT32(s, versionMajor); /* versionMajor (4 bytes) */
Stream_Read_UINT32(s, versionMinor); /* versionMinor (4 bytes) */
-
return CHANNEL_RC_OK;
}
*
* @return 0 on success, otherwise a Win32 error code
*/
-static UINT remdesk_recv_ctl_remote_control_desktop_pdu(RemdeskServerContext* context, wStream* s, REMDESK_CHANNEL_HEADER* header)
+static UINT remdesk_recv_ctl_remote_control_desktop_pdu(
+ RemdeskServerContext* context, wStream* s, REMDESK_CHANNEL_HEADER* header)
{
int status;
int cchStringW;
WCHAR* raConnectionStringW = NULL;
REMDESK_CTL_REMOTE_CONTROL_DESKTOP_PDU pdu;
UINT error;
-
msgLength = header->DataLength - 4;
-
pStringW = (WCHAR*) Stream_Pointer(s);
raConnectionStringW = pStringW;
cchStringW = 0;
cchStringW++;
cbRaConnectionStringW = cchStringW * 2;
-
pdu.raConnectionString = NULL;
-
status = ConvertFromUnicode(CP_UTF8, 0, raConnectionStringW,
- cbRaConnectionStringW / 2, &pdu.raConnectionString, 0, NULL, NULL);
+ cbRaConnectionStringW / 2, &pdu.raConnectionString, 0, NULL, NULL);
if (status <= 0)
{
}
WLog_INFO(TAG, "RaConnectionString: %s",
- pdu.raConnectionString);
+ pdu.raConnectionString);
free(pdu.raConnectionString);
if ((error = remdesk_send_ctl_result_pdu(context, 0)))
*
* @return 0 on success, otherwise a Win32 error code
*/
-static UINT remdesk_recv_ctl_authenticate_pdu(RemdeskServerContext* context, wStream* s, REMDESK_CHANNEL_HEADER* header)
+static UINT remdesk_recv_ctl_authenticate_pdu(RemdeskServerContext* context,
+ wStream* s, REMDESK_CHANNEL_HEADER* header)
{
int status;
int cchStringW;
int cbRaConnectionStringW = 0;
WCHAR* raConnectionStringW = NULL;
REMDESK_CTL_AUTHENTICATE_PDU pdu;
-
msgLength = header->DataLength - 4;
-
pStringW = (WCHAR*) Stream_Pointer(s);
raConnectionStringW = pStringW;
cchStringW = 0;
cchStringW++;
cbRaConnectionStringW = cchStringW * 2;
-
pStringW += cchStringW;
expertBlobW = pStringW;
cchStringW = 0;
cchStringW++;
cbExpertBlobW = cchStringW * 2;
-
pdu.raConnectionString = NULL;
-
status = ConvertFromUnicode(CP_UTF8, 0, raConnectionStringW,
- cbRaConnectionStringW / 2, &pdu.raConnectionString, 0, NULL, NULL);
+ cbRaConnectionStringW / 2, &pdu.raConnectionString, 0, NULL, NULL);
if (status <= 0)
{
}
pdu.expertBlob = NULL;
-
status = ConvertFromUnicode(CP_UTF8, 0, expertBlobW,
- cbExpertBlobW / 2, &pdu.expertBlob, 0, NULL, NULL);
+ cbExpertBlobW / 2, &pdu.expertBlob, 0, NULL, NULL);
if (status <= 0)
{
}
WLog_INFO(TAG, "RaConnectionString: %s ExpertBlob: %s",
- pdu.raConnectionString, pdu.expertBlob);
+ pdu.raConnectionString, pdu.expertBlob);
free(pdu.raConnectionString);
free(pdu.expertBlob);
-
return CHANNEL_RC_OK;
}
*
* @return 0 on success, otherwise a Win32 error code
*/
-static UINT remdesk_recv_ctl_verify_password_pdu(RemdeskServerContext* context, wStream* s, REMDESK_CHANNEL_HEADER* header)
+static UINT remdesk_recv_ctl_verify_password_pdu(RemdeskServerContext* context,
+ wStream* s, REMDESK_CHANNEL_HEADER* header)
{
int status;
int cbExpertBlobW = 0;
pdu.expertBlob = NULL;
expertBlobW = (WCHAR*) Stream_Pointer(s);
cbExpertBlobW = header->DataLength - 4;
-
- status = ConvertFromUnicode(CP_UTF8, 0, expertBlobW, cbExpertBlobW / 2, &pdu.expertBlob, 0, NULL, NULL);
+ status = ConvertFromUnicode(CP_UTF8, 0, expertBlobW, cbExpertBlobW / 2,
+ &pdu.expertBlob, 0, NULL, NULL);
if (status <= 0)
{
}
WLog_INFO(TAG, "ExpertBlob: %s", pdu.expertBlob);
+
if ((error = remdesk_send_ctl_result_pdu(context, 0)))
WLog_ERR(TAG, "remdesk_send_ctl_result_pdu failed with error %lu!", error);
*
* @return 0 on success, otherwise a Win32 error code
*/
-static UINT remdesk_recv_ctl_pdu(RemdeskServerContext* context, wStream* s, REMDESK_CHANNEL_HEADER* header)
+static UINT remdesk_recv_ctl_pdu(RemdeskServerContext* context, wStream* s,
+ REMDESK_CHANNEL_HEADER* header)
{
UINT error = CHANNEL_RC_OK;
UINT32 msgType = 0;
case REMDESK_CTL_REMOTE_CONTROL_DESKTOP:
if ((error = remdesk_recv_ctl_remote_control_desktop_pdu(context, s, header)))
{
- WLog_ERR(TAG, "remdesk_recv_ctl_remote_control_desktop_pdu failed with error %lu!", error);
+ WLog_ERR(TAG,
+ "remdesk_recv_ctl_remote_control_desktop_pdu failed with error %lu!", error);
return error;
}
+
break;
case REMDESK_CTL_AUTHENTICATE:
if ((error = remdesk_recv_ctl_authenticate_pdu(context, s, header)))
{
- WLog_ERR(TAG, "remdesk_recv_ctl_authenticate_pdu failed with error %lu!", error);
+ WLog_ERR(TAG, "remdesk_recv_ctl_authenticate_pdu failed with error %lu!",
+ error);
return error;
}
+
break;
case REMDESK_CTL_DISCONNECT:
break;
case REMDESK_CTL_VERSIONINFO:
- if((error = remdesk_recv_ctl_version_info_pdu(context, s, header)))
+ if ((error = remdesk_recv_ctl_version_info_pdu(context, s, header)))
{
- WLog_ERR(TAG, "remdesk_recv_ctl_version_info_pdu failed with error %lu!", error);
+ WLog_ERR(TAG, "remdesk_recv_ctl_version_info_pdu failed with error %lu!",
+ error);
return error;
}
+
break;
case REMDESK_CTL_ISCONNECTED:
case REMDESK_CTL_VERIFY_PASSWORD:
if ((error = remdesk_recv_ctl_verify_password_pdu(context, s, header)))
{
- WLog_ERR(TAG, "remdesk_recv_ctl_verify_password_pdu failed with error %lu!", error);
+ WLog_ERR(TAG, "remdesk_recv_ctl_verify_password_pdu failed with error %lu!",
+ error);
return error;
}
+
break;
case REMDESK_CTL_EXPERT_ON_VISTA:
*
* @return 0 on success, otherwise a Win32 error code
*/
-static UINT remdesk_server_receive_pdu(RemdeskServerContext* context, wStream* s)
+static UINT remdesk_server_receive_pdu(RemdeskServerContext* context,
+ wStream* s)
{
UINT error = CHANNEL_RC_OK;
REMDESK_CHANNEL_HEADER header;
-
#if 0
WLog_INFO(TAG, "RemdeskReceive: %d", Stream_GetRemainingLength(s));
winpr_HexDump(Stream_Pointer(s), Stream_GetRemainingLength(s));
return error;
}
-
if (strcmp(header.ChannelName, "RC_CTL") == 0)
{
if ((error = remdesk_recv_ctl_pdu(context, s, &header)))
}
else if (strcmp(header.ChannelName, "70") == 0)
{
-
}
else if (strcmp(header.ChannelName, "71") == 0)
{
-
}
else if (strcmp(header.ChannelName, ".") == 0)
{
-
}
else if (strcmp(header.ChannelName, "1000.") == 0)
{
-
}
else if (strcmp(header.ChannelName, "RA_FX") == 0)
{
-
}
else
{
-
}
return error;
DWORD BytesReturned;
RemdeskServerContext* context;
UINT error;
-
context = (RemdeskServerContext*) arg;
-
freerdp_channel_init_thread_context(context->rdpcontext);
buffer = NULL;
BytesReturned = 0;
ChannelEvent = NULL;
-
s = Stream_New(NULL, 4096);
+
if (!s)
{
WLog_ERR(TAG, "Stream_New failed!");
goto out;
}
- if (WTSVirtualChannelQuery(context->priv->ChannelHandle, WTSVirtualEventHandle, &buffer, &BytesReturned) == TRUE)
+ if (WTSVirtualChannelQuery(context->priv->ChannelHandle, WTSVirtualEventHandle,
+ &buffer, &BytesReturned) == TRUE)
{
if (BytesReturned == sizeof(HANDLE))
CopyMemory(&ChannelEvent, buffer, sizeof(HANDLE));
if ((error = remdesk_send_ctl_version_info_pdu(context)))
{
- WLog_ERR(TAG, "remdesk_send_ctl_version_info_pdu failed with error %lu!", error);
+ WLog_ERR(TAG, "remdesk_send_ctl_version_info_pdu failed with error %lu!",
+ error);
goto out;
}
{
status = WaitForMultipleObjects(nCount, events, FALSE, INFINITE);
- if (status == WAIT_FAILED)
- {
- error = GetLastError();
- WLog_ERR(TAG, "WaitForMultipleObjects failed with error %lu", error);
- break;
- }
-
- status = WaitForSingleObject(context->priv->StopEvent, 0);
+ if (status == WAIT_FAILED)
+ {
+ error = GetLastError();
+ WLog_ERR(TAG, "WaitForMultipleObjects failed with error %lu", error);
+ break;
+ }
- if (status == WAIT_FAILED)
- {
- error = GetLastError();
- WLog_ERR(TAG, "WaitForSingleObject failed with error %lu", error);
- break;
- }
+ status = WaitForSingleObject(context->priv->StopEvent, 0);
+ if (status == WAIT_FAILED)
+ {
+ error = GetLastError();
+ WLog_ERR(TAG, "WaitForSingleObject failed with error %lu", error);
+ break;
+ }
if (status == WAIT_OBJECT_0)
{
}
if (WTSVirtualChannelRead(context->priv->ChannelHandle, 0,
- (PCHAR) Stream_Buffer(s), Stream_Capacity(s), &BytesReturned))
+ (PCHAR) Stream_Buffer(s), Stream_Capacity(s), &BytesReturned))
{
if (BytesReturned)
Stream_Seek(s, BytesReturned);
{
Stream_SealLength(s);
Stream_SetPosition(s, 0);
+
if ((error = remdesk_server_receive_pdu(context, s)))
{
WLog_ERR(TAG, "remdesk_server_receive_pdu failed with error %lu!", error);
break;
}
+
Stream_SetPosition(s, 0);
}
}
Stream_Free(s, TRUE);
out:
+
if (error && context->rdpcontext)
- setChannelError(context->rdpcontext, error, "remdesk_server_thread reported an error");
+ setChannelError(context->rdpcontext, error,
+ "remdesk_server_thread reported an error");
ExitThread((DWORD)error);
return NULL;
*/
static UINT remdesk_server_start(RemdeskServerContext* context)
{
- context->priv->ChannelHandle = WTSVirtualChannelOpen(context->vcm, WTS_CURRENT_SESSION, "remdesk");
+ context->priv->ChannelHandle = WTSVirtualChannelOpen(context->vcm,
+ WTS_CURRENT_SESSION, "remdesk");
if (!context->priv->ChannelHandle)
{
}
if (!(context->priv->Thread = CreateThread(NULL, 0,
- (LPTHREAD_START_ROUTINE) remdesk_server_thread, (void*) context, 0, NULL)))
+ (LPTHREAD_START_ROUTINE) remdesk_server_thread, (void*) context, 0, NULL)))
{
WLog_ERR(TAG, "CreateThread failed!");
CloseHandle(context->priv->StopEvent);
*/
static UINT remdesk_server_stop(RemdeskServerContext* context)
{
- UINT error;
-
+ UINT error;
SetEvent(context->priv->StopEvent);
if (WaitForSingleObject(context->priv->Thread, INFINITE) == WAIT_FAILED)
- {
- error = GetLastError();
- WLog_ERR(TAG, "WaitForSingleObject failed with error %lu!", error);
- return error;
- }
- CloseHandle(context->priv->Thread);
+ {
+ error = GetLastError();
+ WLog_ERR(TAG, "WaitForSingleObject failed with error %lu!", error);
+ return error;
+ }
+ CloseHandle(context->priv->Thread);
return CHANNEL_RC_OK;
}
RemdeskServerContext* remdesk_server_context_new(HANDLE vcm)
{
RemdeskServerContext* context;
-
context = (RemdeskServerContext*) calloc(1, sizeof(RemdeskServerContext));
if (context)
{
context->vcm = vcm;
-
context->Start = remdesk_server_start;
context->Stop = remdesk_server_stop;
-
context->priv = (RemdeskServerPrivate*) calloc(1, sizeof(RemdeskServerPrivate));
if (!context->priv)
free(context);
return NULL;
}
+
context->priv->Version = 1;
}
wMessageQueue* MainIrpQueue;
/* one thread per pending IRP and indexed according their CompletionId */
- wListDictionary *IrpThreads;
+ wListDictionary* IrpThreads;
UINT32 IrpThreadToBeTerminatedCount;
CRITICAL_SECTION TerminatingIrpThreadsLock;
rdpContext* rdpcontext;
struct _IRP_THREAD_DATA
{
- SERIAL_DEVICE *serial;
- IRP *irp;
+ SERIAL_DEVICE* serial;
+ IRP* irp;
};
static UINT32 _GetLastErrorToIoStatus(SERIAL_DEVICE* serial)
{
/* http://msdn.microsoft.com/en-us/library/ff547466%28v=vs.85%29.aspx#generic_status_values_for_serial_device_control_requests */
-
- switch(GetLastError())
+ switch (GetLastError())
{
case ERROR_BAD_DEVICE:
return STATUS_INVALID_DEVICE_REQUEST;
case ERROR_TIMEOUT:
return STATUS_TIMEOUT;
-
- /* no default */
+ /* no default */
}
- WLog_Print(serial->log, WLOG_DEBUG, "unexpected last-error: 0x%lx", GetLastError());
+ WLog_Print(serial->log, WLOG_DEBUG, "unexpected last-error: 0x%lx",
+ GetLastError());
return STATUS_UNSUCCESSFUL;
}
DWORD SharedAccess;
DWORD CreateDisposition;
UINT32 PathLength;
-
Stream_Read_UINT32(irp->input, DesiredAccess); /* DesiredAccess (4 bytes) */
Stream_Seek_UINT64(irp->input); /* AllocationSize (8 bytes) */
Stream_Seek_UINT32(irp->input); /* FileAttributes (4 bytes) */
Stream_Read_UINT32(irp->input, SharedAccess); /* SharedAccess (4 bytes) */
- Stream_Read_UINT32(irp->input, CreateDisposition); /* CreateDisposition (4 bytes) */
+ Stream_Read_UINT32(irp->input,
+ CreateDisposition); /* CreateDisposition (4 bytes) */
Stream_Seek_UINT32(irp->input); /* CreateOptions (4 bytes) */
Stream_Read_UINT32(irp->input, PathLength); /* PathLength (4 bytes) */
Stream_Seek(irp->input, PathLength); /* Path (variable) */
-
assert(PathLength == 0); /* MS-RDPESP 2.2.2.2 */
-
-
#ifndef _WIN32
/* Windows 2012 server sends on a first call :
* DesiredAccess = 0x00100080: SYNCHRONIZE | FILE_READ_ATTRIBUTES
* assert(CreateDisposition == OPEN_EXISTING);
*
*/
-
- WLog_Print(serial->log, WLOG_DEBUG, "DesiredAccess: 0x%lX, SharedAccess: 0x%lX, CreateDisposition: 0x%lX", DesiredAccess, SharedAccess, CreateDisposition);
-
+ WLog_Print(serial->log, WLOG_DEBUG,
+ "DesiredAccess: 0x%lX, SharedAccess: 0x%lX, CreateDisposition: 0x%lX",
+ DesiredAccess, SharedAccess, CreateDisposition);
/* FIXME: As of today only the flags below are supported by CommCreateFileA: */
DesiredAccess = GENERIC_READ | GENERIC_WRITE;
SharedAccess = 0;
CreateDisposition = OPEN_EXISTING;
#endif
-
serial->hComm = CreateFile(serial->device.name,
- DesiredAccess,
- SharedAccess,
- NULL, /* SecurityAttributes */
- CreateDisposition,
- 0, /* FlagsAndAttributes */
- NULL); /* TemplateFile */
+ DesiredAccess,
+ SharedAccess,
+ NULL, /* SecurityAttributes */
+ CreateDisposition,
+ 0, /* FlagsAndAttributes */
+ NULL); /* TemplateFile */
if (!serial->hComm || (serial->hComm == INVALID_HANDLE_VALUE))
{
- WLog_Print(serial->log, WLOG_WARN, "CreateFile failure: %s last-error: 0x%lX\n", serial->device.name, GetLastError());
-
+ WLog_Print(serial->log, WLOG_WARN, "CreateFile failure: %s last-error: 0x%lX\n",
+ serial->device.name, GetLastError());
irp->IoStatus = STATUS_UNSUCCESSFUL;
goto error_handle;
}
_comm_setServerSerialDriver(serial->hComm, serial->ServerSerialDriverId);
-
_comm_set_permissive(serial->hComm, serial->permissive);
-
/* NOTE: binary mode/raw mode required for the redirection. On
* Linux, CommCreateFileA forces this setting.
*/
/* GetCommState(serial->hComm, &dcb); */
/* dcb.fBinary = TRUE; */
/* SetCommState(serial->hComm, &dcb); */
-
assert(irp->FileId == 0);
- irp->FileId = irp->devman->id_sequence++; /* FIXME: why not ((WINPR_COMM*)hComm)->fd? */
-
+ irp->FileId =
+ irp->devman->id_sequence++; /* FIXME: why not ((WINPR_COMM*)hComm)->fd? */
irp->IoStatus = STATUS_SUCCESS;
-
- WLog_Print(serial->log, WLOG_DEBUG, "%s (DeviceId: %d, FileId: %d) created.", serial->device.name, irp->device->id, irp->FileId);
-
- error_handle:
+ WLog_Print(serial->log, WLOG_DEBUG, "%s (DeviceId: %d, FileId: %d) created.",
+ serial->device.name, irp->device->id, irp->FileId);
+error_handle:
Stream_Write_UINT32(irp->output, irp->FileId); /* FileId (4 bytes) */
Stream_Write_UINT8(irp->output, 0); /* Information (1 byte) */
}
if (!CloseHandle(serial->hComm))
{
- WLog_Print(serial->log, WLOG_WARN, "CloseHandle failure: %s (%d) closed.", serial->device.name, irp->device->id);
+ WLog_Print(serial->log, WLOG_WARN, "CloseHandle failure: %s (%d) closed.",
+ serial->device.name, irp->device->id);
irp->IoStatus = STATUS_UNSUCCESSFUL;
goto error_handle;
}
- WLog_Print(serial->log, WLOG_DEBUG, "%s (DeviceId: %d, FileId: %d) closed.", serial->device.name, irp->device->id, irp->FileId);
-
+ WLog_Print(serial->log, WLOG_DEBUG, "%s (DeviceId: %d, FileId: %d) closed.",
+ serial->device.name, irp->device->id, irp->FileId);
serial->hComm = NULL;
irp->IoStatus = STATUS_SUCCESS;
-
- error_handle:
+error_handle:
Stream_Zero(irp->output, 5); /* Padding (5 bytes) */
}
UINT64 Offset;
BYTE* buffer = NULL;
DWORD nbRead = 0;
-
Stream_Read_UINT32(irp->input, Length); /* Length (4 bytes) */
Stream_Read_UINT64(irp->input, Offset); /* Offset (8 bytes) */
Stream_Seek(irp->input, 20); /* Padding (20 bytes) */
-
-
buffer = (BYTE*)calloc(Length, sizeof(BYTE));
+
if (buffer == NULL)
{
irp->IoStatus = STATUS_NO_MEMORY;
goto error_handle;
}
-
/* MS-RDPESP 3.2.5.1.4: If the Offset field is not set to 0, the value MUST be ignored
* assert(Offset == 0);
*/
-
-
- WLog_Print(serial->log, WLOG_DEBUG, "reading %d bytes from %s", Length, serial->device.name);
+ WLog_Print(serial->log, WLOG_DEBUG, "reading %d bytes from %s", Length,
+ serial->device.name);
/* FIXME: CommReadFile to be replaced by ReadFile */
if (CommReadFile(serial->hComm, buffer, Length, &nbRead, NULL))
}
else
{
- WLog_Print(serial->log, WLOG_DEBUG, "read failure to %s, nbRead=%ld, last-error: 0x%lX", serial->device.name, nbRead, GetLastError());
-
+ WLog_Print(serial->log, WLOG_DEBUG,
+ "read failure to %s, nbRead=%ld, last-error: 0x%lX", serial->device.name,
+ nbRead, GetLastError());
irp->IoStatus = _GetLastErrorToIoStatus(serial);
}
- WLog_Print(serial->log, WLOG_DEBUG, "%lu bytes read from %s", nbRead, serial->device.name);
-
- error_handle:
-
+ WLog_Print(serial->log, WLOG_DEBUG, "%lu bytes read from %s", nbRead,
+ serial->device.name);
+error_handle:
Stream_Write_UINT32(irp->output, nbRead); /* Length (4 bytes) */
if (nbRead > 0)
free(buffer);
return CHANNEL_RC_NO_MEMORY;
}
+
Stream_Write(irp->output, buffer, nbRead); /* ReadData */
}
UINT32 Length;
UINT64 Offset;
DWORD nbWritten = 0;
-
Stream_Read_UINT32(irp->input, Length); /* Length (4 bytes) */
Stream_Read_UINT64(irp->input, Offset); /* Offset (8 bytes) */
Stream_Seek(irp->input, 20); /* Padding (20 bytes) */
-
/* MS-RDPESP 3.2.5.1.5: The Offset field is ignored
* assert(Offset == 0);
*
* Using a serial printer, noticed though this field could be
* set.
*/
-
- WLog_Print(serial->log, WLOG_DEBUG, "writing %d bytes to %s", Length, serial->device.name);
+ WLog_Print(serial->log, WLOG_DEBUG, "writing %d bytes to %s", Length,
+ serial->device.name);
/* FIXME: CommWriteFile to be replaced by WriteFile */
- if (CommWriteFile(serial->hComm, Stream_Pointer(irp->input), Length, &nbWritten, NULL))
+ if (CommWriteFile(serial->hComm, Stream_Pointer(irp->input), Length, &nbWritten,
+ NULL))
{
irp->IoStatus = STATUS_SUCCESS;
}
else
{
- WLog_Print(serial->log, WLOG_DEBUG, "write failure to %s, nbWritten=%ld, last-error: 0x%lX", serial->device.name, nbWritten, GetLastError());
-
+ WLog_Print(serial->log, WLOG_DEBUG,
+ "write failure to %s, nbWritten=%ld, last-error: 0x%lX", serial->device.name,
+ nbWritten, GetLastError());
irp->IoStatus = _GetLastErrorToIoStatus(serial);
}
- WLog_Print(serial->log, WLOG_DEBUG, "%lu bytes written to %s", nbWritten, serial->device.name);
-
+ WLog_Print(serial->log, WLOG_DEBUG, "%lu bytes written to %s", nbWritten,
+ serial->device.name);
Stream_Write_UINT32(irp->output, nbWritten); /* Length (4 bytes) */
Stream_Write_UINT8(irp->output, 0); /* Padding (1 byte) */
}
UINT32 OutputBufferLength;
BYTE* OutputBuffer = NULL;
DWORD BytesReturned = 0;
-
- Stream_Read_UINT32(irp->input, OutputBufferLength); /* OutputBufferLength (4 bytes) */
- Stream_Read_UINT32(irp->input, InputBufferLength); /* InputBufferLength (4 bytes) */
+ Stream_Read_UINT32(irp->input,
+ OutputBufferLength); /* OutputBufferLength (4 bytes) */
+ Stream_Read_UINT32(irp->input,
+ InputBufferLength); /* InputBufferLength (4 bytes) */
Stream_Read_UINT32(irp->input, IoControlCode); /* IoControlCode (4 bytes) */
Stream_Seek(irp->input, 20); /* Padding (20 bytes) */
-
OutputBuffer = (BYTE*)calloc(OutputBufferLength, sizeof(BYTE));
+
if (OutputBuffer == NULL)
{
irp->IoStatus = STATUS_NO_MEMORY;
}
InputBuffer = (BYTE*)calloc(InputBufferLength, sizeof(BYTE));
+
if (InputBuffer == NULL)
{
irp->IoStatus = STATUS_NO_MEMORY;
}
Stream_Read(irp->input, InputBuffer, InputBufferLength);
-
- WLog_Print(serial->log, WLOG_DEBUG, "CommDeviceIoControl: CompletionId=%d, IoControlCode=[0x%X] %s", irp->CompletionId, IoControlCode, _comm_serial_ioctl_name(IoControlCode));
+ WLog_Print(serial->log, WLOG_DEBUG,
+ "CommDeviceIoControl: CompletionId=%d, IoControlCode=[0x%X] %s",
+ irp->CompletionId, IoControlCode, _comm_serial_ioctl_name(IoControlCode));
/* FIXME: CommDeviceIoControl to be replaced by DeviceIoControl() */
- if (CommDeviceIoControl(serial->hComm, IoControlCode, InputBuffer, InputBufferLength, OutputBuffer, OutputBufferLength, &BytesReturned, NULL))
+ if (CommDeviceIoControl(serial->hComm, IoControlCode, InputBuffer,
+ InputBufferLength, OutputBuffer, OutputBufferLength, &BytesReturned, NULL))
{
/* WLog_Print(serial->log, WLOG_DEBUG, "CommDeviceIoControl: CompletionId=%d, IoControlCode=[0x%X] %s done", irp->CompletionId, IoControlCode, _comm_serial_ioctl_name(IoControlCode)); */
-
irp->IoStatus = STATUS_SUCCESS;
}
else
{
- WLog_Print(serial->log, WLOG_DEBUG, "CommDeviceIoControl failure: IoControlCode=[0x%X] %s, last-error: 0x%lX",
- IoControlCode, _comm_serial_ioctl_name(IoControlCode), GetLastError());
-
+ WLog_Print(serial->log, WLOG_DEBUG,
+ "CommDeviceIoControl failure: IoControlCode=[0x%X] %s, last-error: 0x%lX",
+ IoControlCode, _comm_serial_ioctl_name(IoControlCode), GetLastError());
irp->IoStatus = _GetLastErrorToIoStatus(serial);
}
- error_handle:
-
+error_handle:
/* FIXME: find out whether it's required or not to get
* BytesReturned == OutputBufferLength when
* CommDeviceIoControl returns FALSE */
assert(OutputBufferLength == BytesReturned);
-
- Stream_Write_UINT32(irp->output, BytesReturned); /* OutputBufferLength (4 bytes) */
+ Stream_Write_UINT32(irp->output,
+ BytesReturned); /* OutputBufferLength (4 bytes) */
if (BytesReturned > 0)
{
Stream_Write(irp->output, OutputBuffer, BytesReturned); /* OutputBuffer */
}
+
/* FIXME: Why at least Windows 2008R2 gets lost with this
* extra byte and likely on a IOCTL_SERIAL_SET_BAUD_RATE? The
* extra byte is well required according MS-RDPEFS
/* { */
/* Stream_Write_UINT8(irp->output, 0); /\* Padding (1 byte) *\/ */
/* } */
-
free(InputBuffer);
free(OutputBuffer);
return CHANNEL_RC_OK;
static UINT serial_process_irp(SERIAL_DEVICE* serial, IRP* irp)
{
UINT error = CHANNEL_RC_OK;
- WLog_Print(serial->log, WLOG_DEBUG, "IRP MajorFunction: 0x%04X MinorFunction: 0x%04X\n",
- irp->MajorFunction, irp->MinorFunction);
+ WLog_Print(serial->log, WLOG_DEBUG,
+ "IRP MajorFunction: 0x%04X MinorFunction: 0x%04X\n",
+ irp->MajorFunction, irp->MinorFunction);
switch (irp->MajorFunction)
{
case IRP_MJ_READ:
if ((error = serial_process_irp_read(serial, irp)))
WLog_ERR(TAG, "serial_process_irp_read failed with error %lu!", error);
+
break;
case IRP_MJ_WRITE:
case IRP_MJ_DEVICE_CONTROL:
if ((error = serial_process_irp_device_control(serial, irp)))
- WLog_ERR(TAG, "serial_process_irp_device_control failed with error %lu!", error);
+ WLog_ERR(TAG, "serial_process_irp_device_control failed with error %lu!",
+ error);
+
break;
default:
irp->IoStatus = STATUS_NOT_SUPPORTED;
break;
}
+
return error;
}
static void* irp_thread_func(void* arg)
{
- IRP_THREAD_DATA *data = (IRP_THREAD_DATA*)arg;
+ IRP_THREAD_DATA* data = (IRP_THREAD_DATA*)arg;
UINT error;
-
freerdp_channel_init_thread_context(data->serial->rdpcontext);
/* blocks until the end of the request */
EnterCriticalSection(&data->serial->TerminatingIrpThreadsLock);
data->serial->IrpThreadToBeTerminatedCount++;
-
error = data->irp->Complete(data->irp);
-
LeaveCriticalSection(&data->serial->TerminatingIrpThreadsLock);
-
error_out:
+
if (error && data->serial->rdpcontext)
- setChannelError(data->serial->rdpcontext, error, "irp_thread_func reported an error");
+ setChannelError(data->serial->rdpcontext, error,
+ "irp_thread_func reported an error");
/* NB: At this point, the server might already being reusing
* the CompletionId whereas the thread is not yet
* terminated */
-
free(data);
-
ExitThread((DWORD)error);
return NULL;
}
-static void create_irp_thread(SERIAL_DEVICE *serial, IRP *irp)
+static void create_irp_thread(SERIAL_DEVICE* serial, IRP* irp)
{
- IRP_THREAD_DATA *data = NULL;
+ IRP_THREAD_DATA* data = NULL;
HANDLE irpThread;
HANDLE previousIrpThread;
uintptr_t key;
-
/* for a test/debug purpose, uncomment the code below to get a
* single thread for all IRPs. NB: two IRPs could not be
* processed at the same time, typically two concurent
/* serial_process_irp(serial, irp); */
/* irp->Complete(irp); */
/* return; */
-
-
/* NOTE: for good or bad, this implementation relies on the
* server to avoid a flooding of requests. see also _purge().
*/
-
EnterCriticalSection(&serial->TerminatingIrpThreadsLock);
+
while (serial->IrpThreadToBeTerminatedCount > 0)
{
/* Cleaning up termitating and pending irp
* threads. See also: irp_thread_func() */
-
HANDLE irpThread;
- ULONG_PTR *ids;
+ ULONG_PTR* ids;
int i, nbIds;
-
nbIds = ListDictionary_GetKeys(serial->IrpThreads, &ids);
- for (i=0; i<nbIds; i++)
+
+ for (i = 0; i < nbIds; i++)
{
/* Checking if ids[i] is terminating or pending */
-
DWORD waitResult;
ULONG_PTR id = ids[i];
-
irpThread = ListDictionary_GetItemValue(serial->IrpThreads, (void*)id);
-
/* FIXME: not quite sure a zero timeout is a good thing to check whether a thread is stil alived or not */
waitResult = WaitForSingleObject(irpThread, 0);
if (waitResult == WAIT_OBJECT_0)
{
/* terminating thread */
-
/* WLog_Print(serial->log, WLOG_DEBUG, "IRP thread with CompletionId=%d naturally died", id); */
-
CloseHandle(irpThread);
ListDictionary_Remove(serial->IrpThreads, (void*)id);
-
serial->IrpThreadToBeTerminatedCount--;
}
else if (waitResult != WAIT_TIMEOUT)
{
/* unexpected thread state */
-
- WLog_Print(serial->log, WLOG_WARN, "WaitForSingleObject, got an unexpected result=0x%lX\n", waitResult);
+ WLog_Print(serial->log, WLOG_WARN,
+ "WaitForSingleObject, got an unexpected result=0x%lX\n", waitResult);
assert(FALSE);
}
+
/* pending thread (but not yet terminating thread) if waitResult == WAIT_TIMEOUT */
}
-
if (serial->IrpThreadToBeTerminatedCount > 0)
{
- WLog_Print(serial->log, WLOG_DEBUG, "%d IRP thread(s) not yet terminated", serial->IrpThreadToBeTerminatedCount);
+ WLog_Print(serial->log, WLOG_DEBUG, "%d IRP thread(s) not yet terminated",
+ serial->IrpThreadToBeTerminatedCount);
Sleep(1); /* 1 ms */
}
}
- LeaveCriticalSection(&serial->TerminatingIrpThreadsLock);
+ LeaveCriticalSection(&serial->TerminatingIrpThreadsLock);
/* NB: At this point and thanks to the synchronization we're
* sure that the incoming IRP uses well a recycled
* CompletionId or the server sent again an IRP already posted
* FIXME: behavior documented somewhere? behavior not yet
* observed with FreeRDP).
*/
-
key = irp->CompletionId;
previousIrpThread = ListDictionary_GetItemValue(serial->IrpThreads, (void*)key);
+
if (previousIrpThread)
{
/* Thread still alived <=> Request still pending */
-
- WLog_Print(serial->log, WLOG_DEBUG, "IRP recall: IRP with the CompletionId=%d not yet completed!", irp->CompletionId);
-
+ WLog_Print(serial->log, WLOG_DEBUG,
+ "IRP recall: IRP with the CompletionId=%d not yet completed!",
+ irp->CompletionId);
assert(FALSE); /* unimplemented */
-
/* TODO: asserts that previousIrpThread handles well
* the same request by checking more details. Need an
* access to the IRP object used by previousIrpThread
*/
-
/* TODO: taking over the pending IRP or sending a kind
* of wake up signal to accelerate the pending
* request
* pComm->PendingEvents |= SERIAL_EV_FREERDP_*;
* }
*/
-
irp->Discard(irp);
return;
}
-
if (ListDictionary_Count(serial->IrpThreads) >= MAX_IRP_THREADS)
{
- WLog_Print(serial->log, WLOG_WARN, "Number of IRP threads threshold reached: %d, keep on anyway", ListDictionary_Count(serial->IrpThreads));
-
+ WLog_Print(serial->log, WLOG_WARN,
+ "Number of IRP threads threshold reached: %d, keep on anyway",
+ ListDictionary_Count(serial->IrpThreads));
assert(FALSE); /* unimplemented */
-
/* TODO: MAX_IRP_THREADS has been thought to avoid a
* flooding of pending requests. Use
* WaitForMultipleObjects() when available in winpr
*/
}
-
/* error_handle to be used ... */
-
data = (IRP_THREAD_DATA*)calloc(1, sizeof(IRP_THREAD_DATA));
+
if (data == NULL)
{
WLog_Print(serial->log, WLOG_WARN, "Could not allocate a new IRP_THREAD_DATA.");
data->serial = serial;
data->irp = irp;
-
/* data freed by irp_thread_func */
-
irpThread = CreateThread(NULL,
- 0,
- (LPTHREAD_START_ROUTINE)irp_thread_func,
- (void*)data,
- 0,
- NULL);
+ 0,
+ (LPTHREAD_START_ROUTINE)irp_thread_func,
+ (void*)data,
+ 0,
+ NULL);
if (irpThread == INVALID_HANDLE_VALUE)
{
goto error_handle;
}
-
key = irp->CompletionId;
+
if (!ListDictionary_Add(serial->IrpThreads, (void*)key, irpThread))
{
WLog_ERR(TAG, "ListDictionary_Add failed!");
}
return;
-
- error_handle:
-
+error_handle:
irp->IoStatus = STATUS_NO_MEMORY;
irp->Complete(irp);
-
free(data);
}
-static void terminate_pending_irp_threads(SERIAL_DEVICE *serial)
+static void terminate_pending_irp_threads(SERIAL_DEVICE* serial)
{
- ULONG_PTR *ids;
+ ULONG_PTR* ids;
int i, nbIds;
-
nbIds = ListDictionary_GetKeys(serial->IrpThreads, &ids);
-
WLog_Print(serial->log, WLOG_DEBUG, "Terminating %d IRP thread(s)", nbIds);
- for (i=0; i<nbIds; i++)
+ for (i = 0; i < nbIds; i++)
{
HANDLE irpThread;
ULONG_PTR id = ids[i];
-
irpThread = ListDictionary_GetItemValue(serial->IrpThreads, (void*)id);
-
TerminateThread(irpThread, 0);
if (WaitForSingleObject(irpThread, INFINITE) == WAIT_FAILED)
- {
- WLog_ERR(TAG,"WaitForSingleObject failed!");
- continue;
- }
+ {
+ WLog_ERR(TAG, "WaitForSingleObject failed!");
+ continue;
+ }
CloseHandle(irpThread);
-
- WLog_Print(serial->log, WLOG_DEBUG, "IRP thread terminated, CompletionId %d", id);
+ WLog_Print(serial->log, WLOG_DEBUG, "IRP thread terminated, CompletionId %d",
+ id);
}
ListDictionary_Clear(serial->IrpThreads);
wMessage message;
SERIAL_DEVICE* serial = (SERIAL_DEVICE*) arg;
UINT error = CHANNEL_RC_OK;
-
freerdp_channel_init_thread_context(serial->rdpcontext);
+
while (1)
{
if (!MessageQueue_Wait(serial->MainIrpQueue))
}
if (error && serial->rdpcontext)
- setChannelError(serial->rdpcontext, error, "serial_thread_func reported an error");
+ setChannelError(serial->rdpcontext, error,
+ "serial_thread_func reported an error");
ExitThread((DWORD) error);
return NULL;
static UINT serial_irp_request(DEVICE* device, IRP* irp)
{
SERIAL_DEVICE* serial = (SERIAL_DEVICE*) device;
-
assert(irp != NULL);
if (irp == NULL)
WLog_ERR(TAG, "MessageQueue_Post failed!");
return ERROR_INTERNAL_ERROR;
}
+
return CHANNEL_RC_OK;
}
*/
static UINT serial_free(DEVICE* device)
{
- UINT error;
+ UINT error;
SERIAL_DEVICE* serial = (SERIAL_DEVICE*) device;
-
WLog_Print(serial->log, WLOG_DEBUG, "freeing");
-
MessageQueue_PostQuit(serial->MainIrpQueue, 0);
+
if (WaitForSingleObject(serial->MainThread, INFINITE) == WAIT_FAILED)
- {
- error = GetLastError();
- WLog_ERR(TAG, "WaitForSingleObject failed with error %lu!", error);
- return error;
- }
+ {
+ error = GetLastError();
+ WLog_ERR(TAG, "WaitForSingleObject failed with error %lu!", error);
+ return error;
+ }
+
CloseHandle(serial->MainThread);
if (serial->hComm)
MessageQueue_Free(serial->MainIrpQueue);
ListDictionary_Free(serial->IrpThreads);
DeleteCriticalSection(&serial->TerminatingIrpThreadsLock);
-
free(serial);
- return CHANNEL_RC_OK;
+ return CHANNEL_RC_OK;
}
#endif /* __linux__ */
SERIAL_DEVICE* serial;
#endif /* __linux__ */
UINT error = CHANNEL_RC_OK;
-
device = (RDPDR_SERIAL*) pEntryPoints->device;
name = device->Name;
path = device->Path;
if ((name && name[0]) && (path && path[0]))
{
wLog* log;
-
WLog_Init();
log = WLog_Get("com.freerdp.channel.serial.client");
WLog_Print(log, WLOG_DEBUG, "initializing");
-
#ifndef __linux__ /* to be removed */
-
- WLog_Print(log, WLOG_WARN, "Serial ports redirection not supported on this platform.");
+ WLog_Print(log, WLOG_WARN,
+ "Serial ports redirection not supported on this platform.");
return CHANNEL_RC_INITIALIZATION_ERROR;
-
#else /* __linux __ */
-
WLog_Print(log, WLOG_DEBUG, "Defining %s as %s", name, path);
if (!DefineCommDevice(name /* eg: COM1 */, path /* eg: /dev/ttyS0 */))
}
serial = (SERIAL_DEVICE*) calloc(1, sizeof(SERIAL_DEVICE));
+
if (!serial)
{
WLog_ERR(TAG, "calloc failed!");
}
serial->log = log;
-
serial->device.type = RDPDR_DTYP_SERIAL;
serial->device.name = name;
serial->device.IRPRequest = serial_irp_request;
serial->device.Free = serial_free;
serial->rdpcontext = pEntryPoints->rdpcontext;
-
len = strlen(name);
serial->device.data = Stream_New(NULL, len + 1);
+
if (!serial->device.data)
{
WLog_ERR(TAG, "calloc failed!");
else
{
assert(FALSE);
-
- WLog_Print(serial->log, WLOG_DEBUG, "Unknown server's serial driver: %s. SerCx2 will be used", driver);
+ WLog_Print(serial->log, WLOG_DEBUG,
+ "Unknown server's serial driver: %s. SerCx2 will be used", driver);
serial->ServerSerialDriverId = SerialDriverSerialSys;
}
}
serial->ServerSerialDriverId = SerialDriverSerialSys;
}
-
if (device->Permissive != NULL)
{
if (_stricmp(device->Permissive, "permissive") == 0)
}
}
-
- WLog_Print(serial->log, WLOG_DEBUG, "Server's serial driver: %s (id: %d)", driver, serial->ServerSerialDriverId);
+ WLog_Print(serial->log, WLOG_DEBUG, "Server's serial driver: %s (id: %d)",
+ driver, serial->ServerSerialDriverId);
/* TODO: implement auto detection of the server's serial driver */
-
serial->MainIrpQueue = MessageQueue_New(NULL);
+
if (!serial->MainIrpQueue)
{
WLog_ERR(TAG, "MessageQueue_New failed!");
/* IrpThreads content only modified by create_irp_thread() */
serial->IrpThreads = ListDictionary_New(FALSE);
- if(!serial->IrpThreads)
+
+ if (!serial->IrpThreads)
{
WLog_ERR(TAG, "ListDictionary_New failed!");
error = CHANNEL_RC_NO_MEMORY;
goto error_out;
}
+
serial->IrpThreadToBeTerminatedCount = 0;
InitializeCriticalSection(&serial->TerminatingIrpThreadsLock);
- if ((error = pEntryPoints->RegisterDevice(pEntryPoints->devman, (DEVICE*) serial)))
+ if ((error = pEntryPoints->RegisterDevice(pEntryPoints->devman,
+ (DEVICE*) serial)))
{
WLog_ERR(TAG, "EntryPoints->RegisterDevice failed with error %lu!", error);
goto error_out;
}
if (!(serial->MainThread = CreateThread(NULL,
- 0,
- (LPTHREAD_START_ROUTINE) serial_thread_func,
- (void*) serial,
- 0,
- NULL)))
+ 0,
+ (LPTHREAD_START_ROUTINE) serial_thread_func,
+ (void*) serial,
+ 0,
+ NULL)))
{
WLog_ERR(TAG, "CreateThread failed!");
error = ERROR_INTERNAL_ERROR;
goto error_out;
}
+
#endif /* __linux __ */
}
SMARTCARD_DEVICE* smartcard;
SMARTCARD_OPERATION* operation;
UINT error = CHANNEL_RC_OK;
-
smartcard = pContext->smartcard;
freerdp_channel_init_thread_context(smartcard->rdpcontext);
-
nCount = 0;
hEvents[nCount++] = MessageQueue_Event(pContext->IrpQueue);
break;
}
-
if (message.id == WMQ_QUIT)
break;
{
if ((status = smartcard_irp_device_control_call(smartcard, operation)))
{
- WLog_ERR(TAG, "smartcard_irp_device_control_call failed with error %lu", status);
+ WLog_ERR(TAG, "smartcard_irp_device_control_call failed with error %lu",
+ status);
break;
}
WLog_ERR(TAG, "Queue_Enqueue failed!");
status = ERROR_INTERNAL_ERROR;
break;
-
}
free(operation);
}
if (status && smartcard->rdpcontext)
- setChannelError(smartcard->rdpcontext, error, "smartcard_context_thread reported an error");
+ setChannelError(smartcard->rdpcontext, error,
+ "smartcard_context_thread reported an error");
ExitThread((DWORD)status);
return NULL;
}
-SMARTCARD_CONTEXT* smartcard_context_new(SMARTCARD_DEVICE* smartcard, SCARDCONTEXT hContext)
+SMARTCARD_CONTEXT* smartcard_context_new(SMARTCARD_DEVICE* smartcard,
+ SCARDCONTEXT hContext)
{
SMARTCARD_CONTEXT* pContext;
-
pContext = (SMARTCARD_CONTEXT*) calloc(1, sizeof(SMARTCARD_CONTEXT));
+
if (!pContext)
{
WLog_ERR(TAG, "calloc failed!");
pContext->smartcard = smartcard;
pContext->hContext = hContext;
-
pContext->IrpQueue = MessageQueue_New(NULL);
+
if (!pContext->IrpQueue)
{
WLog_ERR(TAG, "MessageQueue_New failed!");
}
pContext->thread = CreateThread(NULL, 0,
- (LPTHREAD_START_ROUTINE) smartcard_context_thread,
- pContext, 0, NULL);
+ (LPTHREAD_START_ROUTINE) smartcard_context_thread,
+ pContext, 0, NULL);
+
if (!pContext->thread)
{
WLog_ERR(TAG, "CreateThread failed!");
}
return pContext;
-
error_thread:
MessageQueue_Free(pContext->IrpQueue);
error_irpqueue:
/* cancel blocking calls like SCardGetStatusChange */
SCardCancel(pContext->hContext);
- if (MessageQueue_PostQuit(pContext->IrpQueue, 0) && (WaitForSingleObject(pContext->thread, INFINITE) == WAIT_FAILED))
+
+ if (MessageQueue_PostQuit(pContext->IrpQueue, 0)
+ && (WaitForSingleObject(pContext->thread, INFINITE) == WAIT_FAILED))
WLog_ERR(TAG, "WaitForSingleObject failed with error %lu!", GetLastError());
CloseHandle(pContext->thread);
-
MessageQueue_Free(pContext->IrpQueue);
-
free(pContext);
}
-static void smartcard_release_all_contexts(SMARTCARD_DEVICE* smartcard) {
+static void smartcard_release_all_contexts(SMARTCARD_DEVICE* smartcard)
+{
int index;
int keyCount;
ULONG_PTR* pKeys;
for (index = 0; index < keyCount; index++)
{
- pContext = (SMARTCARD_CONTEXT*) ListDictionary_GetItemValue(smartcard->rgSCardContextList, (void*) pKeys[index]);
+ pContext = (SMARTCARD_CONTEXT*) ListDictionary_GetItemValue(
+ smartcard->rgSCardContextList, (void*) pKeys[index]);
if (!pContext)
continue;
for (index = 0; index < keyCount; index++)
{
- pContext = (SMARTCARD_CONTEXT*) ListDictionary_Remove(smartcard->rgSCardContextList, (void*) pKeys[index]);
+ pContext = (SMARTCARD_CONTEXT*) ListDictionary_Remove(
+ smartcard->rgSCardContextList, (void*) pKeys[index]);
if (!pContext)
continue;
{
UINT error;
SMARTCARD_DEVICE* smartcard = (SMARTCARD_DEVICE*) device;
-
/**
* Calling smartcard_release_all_contexts to unblock all operations waiting for transactions
* to unlock.
*/
-
smartcard_release_all_contexts(smartcard);
/* Stopping all threads and cancelling all IRPs */
if (smartcard->IrpQueue)
{
- if (MessageQueue_PostQuit(smartcard->IrpQueue, 0) && (WaitForSingleObject(smartcard->thread, INFINITE) == WAIT_FAILED))
+ if (MessageQueue_PostQuit(smartcard->IrpQueue, 0)
+ && (WaitForSingleObject(smartcard->thread, INFINITE) == WAIT_FAILED))
{
error = GetLastError();
WLog_ERR(TAG, "WaitForSingleObject failed with error %lu!", error);
MessageQueue_Free(smartcard->IrpQueue);
smartcard->IrpQueue = NULL;
-
CloseHandle(smartcard->thread);
smartcard->thread = NULL;
}
}
free(device);
-
return CHANNEL_RC_OK;
}
static UINT smartcard_init(DEVICE* device)
{
SMARTCARD_DEVICE* smartcard = (SMARTCARD_DEVICE*) device;
-
smartcard_release_all_contexts(smartcard);
-
return CHANNEL_RC_OK;
}
UINT smartcard_complete_irp(SMARTCARD_DEVICE* smartcard, IRP* irp)
{
void* key;
-
- key = (void*) (size_t) irp->CompletionId;
+ key = (void*)(size_t) irp->CompletionId;
ListDictionary_Remove(smartcard->rgOutstandingMessages, key);
-
return irp->Complete(irp);
}
BOOL asyncIrp = FALSE;
SMARTCARD_CONTEXT* pContext = NULL;
SMARTCARD_OPERATION* operation = NULL;
+ key = (void*)(size_t) irp->CompletionId;
- key = (void*) (size_t) irp->CompletionId;
if (!ListDictionary_Add(smartcard->rgOutstandingMessages, key, irp))
{
WLog_ERR(TAG, "ListDictionary_Add failed!");
}
operation->irp = irp;
-
status = smartcard_irp_device_control_decode(smartcard, operation);
if (status != SCARD_S_SUCCESS)
break;
}
- pContext = ListDictionary_GetItemValue(smartcard->rgSCardContextList, (void*) operation->hContext);
+ pContext = ListDictionary_GetItemValue(smartcard->rgSCardContextList,
+ (void*) operation->hContext);
if (!pContext)
asyncIrp = FALSE;
{
if ((status = smartcard_irp_device_control_call(smartcard, operation)))
{
- WLog_ERR(TAG, "smartcard_irp_device_control_call failed with error %lu!", status);
+ WLog_ERR(TAG, "smartcard_irp_device_control_call failed with error %lu!",
+ status);
return (UINT32)status;
}
+
if (!Queue_Enqueue(smartcard->CompletedIrpQueue, (void*) irp))
{
WLog_ERR(TAG, "Queue_Enqueue failed!");
return ERROR_INTERNAL_ERROR;
}
+
free(operation);
}
else
}
else
{
- WLog_ERR(TAG, "Unexpected SmartCard IRP: MajorFunction 0x%08X MinorFunction: 0x%08X",
- irp->MajorFunction, irp->MinorFunction);
+ WLog_ERR(TAG,
+ "Unexpected SmartCard IRP: MajorFunction 0x%08X MinorFunction: 0x%08X",
+ irp->MajorFunction, irp->MinorFunction);
irp->IoStatus = (UINT32)STATUS_NOT_SUPPORTED;
if (!Queue_Enqueue(smartcard->CompletedIrpQueue, (void*) irp))
return ERROR_INTERNAL_ERROR;
}
}
+
return CHANNEL_RC_OK;
}
wMessage message;
SMARTCARD_DEVICE* smartcard = (SMARTCARD_DEVICE*) arg;
UINT error = CHANNEL_RC_OK;
-
freerdp_channel_init_thread_context(smartcard->rdpcontext);
-
nCount = 0;
hEvents[nCount++] = MessageQueue_Event(smartcard->IrpQueue);
hEvents[nCount++] = Queue_Event(smartcard->CompletedIrpQueue);
break;
}
-
if (message.id == WMQ_QUIT)
{
while (1)
if (status == WAIT_OBJECT_0)
{
-
irp = (IRP*) Queue_Dequeue(smartcard->CompletedIrpQueue);
if (irp)
}
}
}
+
out:
+
if (error && smartcard->rdpcontext)
- setChannelError(smartcard->rdpcontext, error, "smartcard_thread_func reported an error");
+ setChannelError(smartcard->rdpcontext, error,
+ "smartcard_thread_func reported an error");
ExitThread((DWORD)error);
return NULL;
static UINT smartcard_irp_request(DEVICE* device, IRP* irp)
{
SMARTCARD_DEVICE* smartcard = (SMARTCARD_DEVICE*) device;
+
if (!MessageQueue_Post(smartcard->IrpQueue, NULL, 0, (void*) irp, NULL))
{
WLog_ERR(TAG, "MessageQueue_Post failed!");
return ERROR_INTERNAL_ERROR;
}
+
return CHANNEL_RC_OK;
}
RDPDR_SMARTCARD* device;
SMARTCARD_DEVICE* smartcard;
UINT error = CHANNEL_RC_NO_MEMORY;
-
device = (RDPDR_SMARTCARD*) pEntryPoints->device;
-
name = device->Name;
path = device->Path;
-
smartcard = (SMARTCARD_DEVICE*) calloc(1, sizeof(SMARTCARD_DEVICE));
+
if (!smartcard)
{
WLog_ERR(TAG, "calloc failed!");
smartcard->device.Init = smartcard_init;
smartcard->device.Free = smartcard_free;
smartcard->rdpcontext = pEntryPoints->rdpcontext;
-
length = strlen(smartcard->device.name);
smartcard->device.data = Stream_New(NULL, length + 1);
+
if (!smartcard->device.data)
{
WLog_ERR(TAG, "Stream_New failed!");
}
Stream_Write(smartcard->device.data, "SCARD", 6);
-
smartcard->name = NULL;
smartcard->path = NULL;
}
smartcard->IrpQueue = MessageQueue_New(NULL);
+
if (!smartcard->IrpQueue)
{
WLog_ERR(TAG, "MessageQueue_New failed!");
goto error_irp_queue;
}
-
smartcard->CompletedIrpQueue = Queue_New(TRUE, -1, -1);
+
if (!smartcard->CompletedIrpQueue)
{
WLog_ERR(TAG, "Queue_New failed!");
}
smartcard->rgSCardContextList = ListDictionary_New(TRUE);
+
if (!smartcard->rgSCardContextList)
{
WLog_ERR(TAG, "ListDictionary_New failed!");
}
ListDictionary_ValueObject(smartcard->rgSCardContextList)->fnObjectFree =
- (OBJECT_FREE_FN) smartcard_context_free;
-
+ (OBJECT_FREE_FN) smartcard_context_free;
smartcard->rgOutstandingMessages = ListDictionary_New(TRUE);
+
if (!smartcard->rgOutstandingMessages)
{
WLog_ERR(TAG, "ListDictionary_New failed!");
goto error_outstanding_messages;
}
- if ((error = pEntryPoints->RegisterDevice(pEntryPoints->devman, (DEVICE*) smartcard)))
+ if ((error = pEntryPoints->RegisterDevice(pEntryPoints->devman,
+ (DEVICE*) smartcard)))
{
WLog_ERR(TAG, "RegisterDevice failed!");
goto error_outstanding_messages;
}
+ smartcard->thread = CreateThread(NULL, 0,
+ (LPTHREAD_START_ROUTINE) smartcard_thread_func,
+ smartcard, CREATE_SUSPENDED, NULL);
- smartcard->thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) smartcard_thread_func,
- smartcard, CREATE_SUSPENDED, NULL);
if (!smartcard->thread)
{
WLog_ERR(TAG, "ListDictionary_New failed!");
}
ResumeThread(smartcard->thread);
-
return CHANNEL_RC_OK;
-
error_thread:
ListDictionary_Free(smartcard->rgOutstandingMessages);
error_outstanding_messages:
{
BYTE presentation_id[GUID_SIZE];
- const char *audio_name;
- const char *audio_device;
+ const char* audio_name;
+ const char* audio_device;
- IWTSVirtualChannelCallback *channel_callback;
+ IWTSVirtualChannelCallback* channel_callback;
UINT64 audio_start_time;
UINT64 audio_end_time;
UINT32 volume;
UINT32 muted;
- wArrayList *stream_list;
+ wArrayList* stream_list;
int x;
int y;
int height;
int nr_rects;
- void *rects;
+ void* rects;
};
struct _TSMF_STREAM
TSMF_PRESENTATION* presentation;
- ITSMFDecoder *decoder;
+ ITSMFDecoder* decoder;
int major_type;
int eos;
UINT32 width;
UINT32 height;
- ITSMFAudioDevice *audio;
+ ITSMFAudioDevice* audio;
UINT32 sample_rate;
UINT32 channels;
UINT32 bits_per_sample;
HANDLE stopEvent;
HANDLE ready;
- wQueue *sample_list;
- wQueue *sample_ack_list;
+ wQueue* sample_list;
+ wQueue* sample_ack_list;
rdpContext* rdpcontext;
BOOL seeking;
UINT64 duration;
UINT32 extensions;
UINT32 data_size;
- BYTE *data;
+ BYTE* data;
UINT32 decoded_size;
UINT32 pixfmt;
BOOL invalidTimestamps;
TSMF_STREAM* stream;
- IWTSVirtualChannelCallback *channel_callback;
+ IWTSVirtualChannelCallback* channel_callback;
UINT64 ack_time;
};
-static wArrayList *presentation_list = NULL;
+static wArrayList* presentation_list = NULL;
static int TERMINATING = 0;
static void _tsmf_presentation_free(TSMF_PRESENTATION* presentation);
{
UINT32 index;
UINT32 count;
- TSMF_STREAM *s;
+ TSMF_STREAM* s;
TSMF_SAMPLE* sample;
BOOL pending = FALSE;
TSMF_PRESENTATION* presentation = stream->presentation;
for (index = 0; index < count; index++)
{
- s = (TSMF_STREAM *) ArrayList_GetItem(presentation->stream_list, index);
+ s = (TSMF_STREAM*) ArrayList_GetItem(presentation->stream_list, index);
/* Start time is more reliable than end time as some stream types seem to have incorrect
* end times from the server
*/
if (s != stream && !s->eos && s->last_start_time &&
- s->last_start_time < stream->last_start_time - AUDIO_TOLERANCE)
+ s->last_start_time < stream->last_start_time - AUDIO_TOLERANCE)
{
DEBUG_TSMF("Pending due to audio tolerance");
pending = TRUE;
if (pending)
return NULL;
- sample = (TSMF_SAMPLE *) Queue_Dequeue(stream->sample_list);
+ sample = (TSMF_SAMPLE*) Queue_Dequeue(stream->sample_list);
/* Only update stream last end time if the sample end time is valid and greater than the current stream end time */
- if (sample && (sample->end_time > stream->last_end_time) && (!sample->invalidTimestamps))
+ if (sample && (sample->end_time > stream->last_end_time)
+ && (!sample->invalidTimestamps))
stream->last_end_time = sample->end_time;
/* Only update stream last start time if the sample start time is valid and greater than the current stream start time */
- if (sample && (sample->start_time > stream->last_start_time) && (!sample->invalidTimestamps))
+ if (sample && (sample->start_time > stream->last_start_time)
+ && (!sample->invalidTimestamps))
stream->last_start_time = sample->start_time;
return sample;
}
-static void tsmf_sample_free(void *arg)
+static void tsmf_sample_free(void* arg)
{
TSMF_SAMPLE* sample = arg;
if (!sample)
return FALSE;
- return tsmf_playback_ack(sample->channel_callback, sample->sample_id, sample->duration, sample->data_size);
+ return tsmf_playback_ack(sample->channel_callback, sample->sample_id,
+ sample->duration, sample->data_size);
}
static BOOL tsmf_sample_queue_ack(TSMF_SAMPLE* sample)
dequeue:
sample = Queue_Dequeue(stream->sample_ack_list);
+
if (sample)
{
tsmf_sample_ack(sample);
return rc;
}
-TSMF_PRESENTATION* tsmf_presentation_new(const BYTE* guid, IWTSVirtualChannelCallback* pChannelCallback)
+TSMF_PRESENTATION* tsmf_presentation_new(const BYTE* guid,
+ IWTSVirtualChannelCallback* pChannelCallback)
{
TSMF_PRESENTATION* presentation;
return NULL;
presentation = (TSMF_PRESENTATION*) calloc(1, sizeof(TSMF_PRESENTATION));
+
if (!presentation)
{
WLog_ERR(TAG, "calloc failed");
presentation->channel_callback = pChannelCallback;
presentation->volume = 5000; /* 50% */
presentation->muted = 0;
+
if (!(presentation->stream_list = ArrayList_New(TRUE)))
goto error_stream_list;
- ArrayList_Object(presentation->stream_list)->fnObjectFree = (OBJECT_FREE_FN) _tsmf_stream_free;
+ ArrayList_Object(presentation->stream_list)->fnObjectFree =
+ (OBJECT_FREE_FN) _tsmf_stream_free;
if (ArrayList_Add(presentation_list, presentation) < 0)
goto error_add;
return presentation;
-
error_add:
ArrayList_Free(presentation->stream_list);
error_stream_list:
free(presentation);
return NULL;
-
}
static char* guid_to_string(const BYTE* guid, char* str, size_t len)
if (!guid || !str)
return NULL;
- for (i=0; i<GUID_SIZE && len > 2*i; i++)
- sprintf_s(str + (2*i), len - 2*i, "%02X", guid[i]);
+ for (i = 0; i < GUID_SIZE && len > 2 * i; i++)
+ sprintf_s(str + (2 * i), len - 2 * i, "%02X", guid[i]);
return str;
}
-TSMF_PRESENTATION* tsmf_presentation_find_by_id(const BYTE *guid)
+TSMF_PRESENTATION* tsmf_presentation_find_by_id(const BYTE* guid)
{
UINT32 index;
UINT32 count;
BOOL found = FALSE;
char guid_str[GUID_SIZE * 2 + 1];
TSMF_PRESENTATION* presentation;
-
ArrayList_Lock(presentation_list);
count = ArrayList_Count(presentation_list);
ArrayList_Unlock(presentation_list);
if (!found)
- WLog_WARN(TAG, "presentation id %s not found", guid_to_string(guid, guid_str, sizeof(guid_str)));
+ WLog_WARN(TAG, "presentation id %s not found", guid_to_string(guid, guid_str,
+ sizeof(guid_str)));
return (found) ? presentation : NULL;
}
TSMF_VIDEO_FRAME_EVENT event;
TSMF_STREAM* stream = sample->stream;
TSMF_PRESENTATION* presentation = stream->presentation;
- TSMF_CHANNEL_CALLBACK* callback = (TSMF_CHANNEL_CALLBACK*) sample->channel_callback;
+ TSMF_CHANNEL_CALLBACK* callback = (TSMF_CHANNEL_CALLBACK*)
+ sample->channel_callback;
TsmfClientContext* tsmf = (TsmfClientContext*) callback->plugin->pInterface;
-
DEBUG_TSMF("MessageId %d EndTime %d data_size %d consumed.",
- sample->sample_id, (int) sample->end_time, sample->data_size);
+ sample->sample_id, (int) sample->end_time, sample->data_size);
if (sample->data)
{
* end times from the server
*/
if (stream->next_start_time > t &&
- ((sample->start_time >= presentation->audio_start_time) ||
- ((sample->start_time < stream->last_start_time) && (!sample->invalidTimestamps))))
+ ((sample->start_time >= presentation->audio_start_time) ||
+ ((sample->start_time < stream->last_start_time)
+ && (!sample->invalidTimestamps))))
{
USleep((stream->next_start_time - t) / 10);
}
stream->next_start_time = t + sample->duration - 50000;
-
ZeroMemory(&event, sizeof(TSMF_VIDEO_FRAME_EVENT));
-
event.frameData = sample->data;
event.frameSize = sample->decoded_size;
event.framePixFmt = sample->pixfmt;
event.frameWidth = sample->stream->width;
event.frameHeight = sample->stream->height;
-
#if 0
/* Dump a .ppm image for every 30 frames. Assuming the frame is in YUV format, we
extract the Y values to create a grayscale image. */
static int frame_id = 0;
char buf[100];
- FILE *fp;
+ FILE* fp;
if ((frame_id % 30) == 0)
{
sprintf_s(buf, sizeof(buf), "/tmp/FreeRDP_Frame_%d.ppm", frame_id);
fp = fopen(buf, "wb");
fwrite("P5\n", 1, 3, fp);
- sprintf_s(buf, sizeof(buf), "%d %d\n", sample->stream->width, sample->stream->height);
+ sprintf_s(buf, sizeof(buf), "%d %d\n", sample->stream->width,
+ sample->stream->height);
fwrite(buf, 1, strlen(buf), fp);
fwrite("255\n", 1, 4, fp);
fwrite(sample->data, 1, sample->stream->width * sample->stream->height, fp);
frame_id++;
#endif
-
/* The frame data ownership is passed to the event object, and is freed after the event is processed. */
sample->data = NULL;
sample->decoded_size = 0;
free(event.frameData);
}
+
return TRUE;
}
UINT64 latency = 0;
TSMF_STREAM* stream = sample->stream;
BOOL ret;
-
DEBUG_TSMF("MessageId %d EndTime %d consumed.",
- sample->sample_id, (int)sample->end_time);
+ sample->sample_id, (int)sample->end_time);
if (stream->audio && sample->data)
{
- ret = sample->stream->audio->Play(sample->stream->audio, sample->data, sample->decoded_size);
+ ret = sample->stream->audio->Play(sample->stream->audio, sample->data,
+ sample->decoded_size);
sample->data = NULL;
sample->decoded_size = 0;
stream->presentation->audio_start_time = sample->start_time + latency;
stream->presentation->audio_end_time = sample->end_time + latency;
}
+
return ret;
}
ArrayList_Lock(presentation->stream_list);
int count = ArrayList_Count(presentation->stream_list);
int index = 0;
+
for (index = 0; index < count; index++)
{
UINT64 time_diff;
+ temp_stream = (TSMF_STREAM*) ArrayList_GetItem(presentation->stream_list,
+ index);
- temp_stream = (TSMF_STREAM*) ArrayList_GetItem(presentation->stream_list, index);
if (temp_stream->major_type == TSMF_MAJOR_TYPE_AUDIO)
{
UINT64 video_time = (UINT64) stream->decoder->GetRunningTime(stream->decoder);
- UINT64 audio_time = (UINT64) temp_stream->decoder->GetRunningTime(temp_stream->decoder);
+ UINT64 audio_time = (UINT64) temp_stream->decoder->GetRunningTime(
+ temp_stream->decoder);
UINT64 max_adjust = VIDEO_ADJUST_MAX;
if (video_time < audio_time)
time_diff = time_diff < VIDEO_ADJUST_MAX ? time_diff : max_adjust;
sample->start_time += time_diff;
sample->end_time += time_diff;
-
break;
}
}
+
ArrayList_Unlock(presentation->stream_list);
}
- ret = stream->decoder->DecodeEx(stream->decoder, sample->data, sample->data_size, sample->extensions,
- sample->start_time, sample->end_time, sample->duration);
+ ret = stream->decoder->DecodeEx(stream->decoder, sample->data,
+ sample->data_size, sample->extensions,
+ sample->start_time, sample->end_time, sample->duration);
}
else
{
- ret = stream->decoder->Decode(stream->decoder, sample->data, sample->data_size, sample->extensions);
+ ret = stream->decoder->Decode(stream->decoder, sample->data, sample->data_size,
+ sample->extensions);
}
}
if (!ret)
{
WLog_ERR(TAG, "decode error, queue ack anyways");
+
if (!tsmf_sample_queue_ack(sample))
{
WLog_ERR(TAG, "error queuing sample for ack");
{
pixfmt = stream->decoder->GetDecodedFormat(stream->decoder);
- if (pixfmt == ((UINT32) -1))
+ if (pixfmt == ((UINT32) - 1))
{
WLog_ERR(TAG, "unable to decode video format");
+
if (!tsmf_sample_queue_ack(sample))
{
WLog_ERR(TAG, "error queuing sample for ack");
}
+
return FALSE;
}
if (stream->decoder->GetDecodedData)
{
- sample->data = stream->decoder->GetDecodedData(stream->decoder, &sample->decoded_size);
+ sample->data = stream->decoder->GetDecodedData(stream->decoder,
+ &sample->decoded_size);
switch (sample->stream->major_type)
{
case TSMF_MAJOR_TYPE_VIDEO:
ret = tsmf_sample_playback_video(sample) &&
- tsmf_sample_queue_ack(sample);
+ tsmf_sample_queue_ack(sample);
break;
case TSMF_MAJOR_TYPE_AUDIO:
ret = tsmf_sample_playback_audio(sample) &&
- tsmf_sample_queue_ack(sample);
+ tsmf_sample_queue_ack(sample);
break;
}
}
if (buffer_filled)
{
- ack_anticipation_time += (sample->duration/2 < MAX_ACK_TIME) ? sample->duration/2 : MAX_ACK_TIME;
+ ack_anticipation_time += (sample->duration / 2 < MAX_ACK_TIME) ?
+ sample->duration / 2 : MAX_ACK_TIME;
}
else
{
- ack_anticipation_time += (sample->duration/2 < MAX_ACK_TIME) ? sample->duration/2 : MAX_ACK_TIME;
+ ack_anticipation_time += (sample->duration / 2 < MAX_ACK_TIME) ?
+ sample->duration / 2 : MAX_ACK_TIME;
}
switch (sample->stream->major_type)
{
case TSMF_MAJOR_TYPE_VIDEO:
- {
- break;
- }
+ {
+ break;
+ }
case TSMF_MAJOR_TYPE_AUDIO:
- {
- break;
- }
+ {
+ break;
+ }
}
sample->ack_time = ack_anticipation_time;
+
if (!tsmf_sample_queue_ack(sample))
{
WLog_ERR(TAG, "error queuing sample for ack");
return ret;
}
-static void* tsmf_stream_ack_func(void *arg)
+static void* tsmf_stream_ack_func(void* arg)
{
HANDLE hdl[2];
TSMF_STREAM* stream = (TSMF_STREAM*) arg;
UINT error = CHANNEL_RC_OK;
DEBUG_TSMF("in %d", stream->stream_id);
-
freerdp_channel_init_thread_context(stream->rdpcontext);
hdl[0] = stream->stopEvent;
hdl[1] = Queue_Event(stream->sample_ack_list);
if (stream->eos)
{
- while ((stream->currentBufferLevel > 0) || !(tsmf_stream_process_ack(stream, TRUE)))
+ while ((stream->currentBufferLevel > 0)
+ || !(tsmf_stream_process_ack(stream, TRUE)))
{
DEBUG_TSMF("END OF STREAM PROCESSING!");
+
if (stream->decoder->BufferLevel)
stream->currentBufferLevel = stream->decoder->BufferLevel(stream->decoder);
else
if (ev == WAIT_OBJECT_0)
{
DEBUG_TSMF("ack: Stream stopped!");
- while(1)
+
+ while (1)
{
if (tsmf_stream_process_ack(stream, TRUE))
break;
+
USleep(1000);
}
+
break;
}
}
if (error && stream->rdpcontext)
- setChannelError(stream->rdpcontext, error, "tsmf_stream_ack_func reported an error");
+ setChannelError(stream->rdpcontext, error,
+ "tsmf_stream_ack_func reported an error");
DEBUG_TSMF("out %d", stream->stream_id);
ExitThread(0);
return NULL;
}
-static void* tsmf_stream_playback_func(void *arg)
+static void* tsmf_stream_playback_func(void* arg)
{
HANDLE hdl[2];
TSMF_SAMPLE* sample = NULL;
- TSMF_STREAM* stream = (TSMF_STREAM *) arg;
+ TSMF_STREAM* stream = (TSMF_STREAM*) arg;
TSMF_PRESENTATION* presentation = stream->presentation;
UINT error = CHANNEL_RC_OK;
DWORD status;
-
DEBUG_TSMF("in %d", stream->stream_id);
-
freerdp_channel_init_thread_context(stream->rdpcontext);
if (stream->major_type == TSMF_MAJOR_TYPE_AUDIO &&
- stream->sample_rate && stream->channels && stream->bits_per_sample)
+ stream->sample_rate && stream->channels && stream->bits_per_sample)
{
if (stream->decoder)
{
if (stream->decoder->GetDecodedData)
{
stream->audio = tsmf_load_audio_device(
- presentation->audio_name && presentation->audio_name[0] ? presentation->audio_name : NULL,
- presentation->audio_device && presentation->audio_device[0] ? presentation->audio_device : NULL);
+ presentation->audio_name
+ && presentation->audio_name[0] ? presentation->audio_name : NULL,
+ presentation->audio_device
+ && presentation->audio_device[0] ? presentation->audio_device : NULL);
if (stream->audio)
{
- stream->audio->SetFormat(stream->audio, stream->sample_rate, stream->channels, stream->bits_per_sample);
+ stream->audio->SetFormat(stream->audio, stream->sample_rate, stream->channels,
+ stream->bits_per_sample);
}
}
}
USleep(1000);
}
-
if (stream->audio)
{
stream->audio->Free(stream->audio);
}
if (error && stream->rdpcontext)
- setChannelError(stream->rdpcontext, error, "tsmf_stream_playback_func reported an error");
+ setChannelError(stream->rdpcontext, error,
+ "tsmf_stream_playback_func reported an error");
DEBUG_TSMF("out %d", stream->stream_id);
ExitThread(0);
static BOOL tsmf_stream_start(TSMF_STREAM* stream)
{
- if (!stream || !stream->presentation || !stream->decoder || !stream->decoder->Control)
+ if (!stream || !stream->presentation || !stream->decoder
+ || !stream->decoder->Control)
return TRUE;
stream->eos = 0;
-
return stream->decoder->Control(stream->decoder, Control_Restart, NULL);
}
{
DEBUG_TSMF("Stop with no pending eos response, so do it immediately.");
tsmf_stream_flush(stream);
-
return stream->decoder->Control(stream->decoder, Control_Stop, NULL);
}
}
return TRUE;
stream->eos = 0;
-
return stream->decoder->Control(stream->decoder, Control_Restart, NULL);
}
-static BOOL tsmf_stream_change_volume(TSMF_STREAM* stream, UINT32 newVolume, UINT32 muted)
+static BOOL tsmf_stream_change_volume(TSMF_STREAM* stream, UINT32 newVolume,
+ UINT32 muted)
{
if (!stream || !stream->decoder)
return TRUE;
{
return stream->audio->ChangeVolume(stream->audio, newVolume, muted);
}
+
return TRUE;
}
-BOOL tsmf_presentation_volume_changed(TSMF_PRESENTATION* presentation, UINT32 newVolume, UINT32 muted)
+BOOL tsmf_presentation_volume_changed(TSMF_PRESENTATION* presentation,
+ UINT32 newVolume, UINT32 muted)
{
UINT32 index;
UINT32 count;
TSMF_STREAM* stream;
BOOL ret = TRUE;
-
presentation->volume = newVolume;
presentation->muted = muted;
-
ArrayList_Lock(presentation->stream_list);
-
count = ArrayList_Count(presentation->stream_list);
+
for (index = 0; index < count; index++)
{
- stream = (TSMF_STREAM *) ArrayList_GetItem(presentation->stream_list, index);
+ stream = (TSMF_STREAM*) ArrayList_GetItem(presentation->stream_list, index);
ret &= tsmf_stream_change_volume(stream, newVolume, muted);
}
UINT32 count;
TSMF_STREAM* stream;
BOOL ret = TRUE;
-
ArrayList_Lock(presentation->stream_list);
count = ArrayList_Count(presentation->stream_list);
for (index = 0; index < count; index++)
{
- stream = (TSMF_STREAM *) ArrayList_GetItem(presentation->stream_list, index);
+ stream = (TSMF_STREAM*) ArrayList_GetItem(presentation->stream_list, index);
ret &= tsmf_stream_pause(stream);
}
UINT32 count;
TSMF_STREAM* stream;
BOOL ret = TRUE;
-
ArrayList_Lock(presentation->stream_list);
count = ArrayList_Count(presentation->stream_list);
for (index = 0; index < count; index++)
{
- stream = (TSMF_STREAM *) ArrayList_GetItem(presentation->stream_list, index);
+ stream = (TSMF_STREAM*) ArrayList_GetItem(presentation->stream_list, index);
ret &= tsmf_stream_restart(stream);
}
UINT32 count;
TSMF_STREAM* stream;
BOOL ret = TRUE;
-
ArrayList_Lock(presentation->stream_list);
count = ArrayList_Count(presentation->stream_list);
for (index = 0; index < count; index++)
{
- stream = (TSMF_STREAM *) ArrayList_GetItem(presentation->stream_list, index);
+ stream = (TSMF_STREAM*) ArrayList_GetItem(presentation->stream_list, index);
ret &= tsmf_stream_start(stream);
}
UINT32 index;
UINT32 count;
UINT error;
-
ArrayList_Lock(presentation->stream_list);
count = ArrayList_Count(presentation->stream_list);
for (index = 0; index < count; index++)
{
- TSMF_STREAM* stream = (TSMF_STREAM *) ArrayList_GetItem(presentation->stream_list, index);
+ TSMF_STREAM* stream = (TSMF_STREAM*) ArrayList_GetItem(
+ presentation->stream_list, index);
+
if (WaitForSingleObject(stream->ready, 500) == WAIT_FAILED)
{
error = GetLastError();
UINT32 count;
TSMF_STREAM* stream;
BOOL ret = TRUE;
-
ArrayList_Lock(presentation->stream_list);
count = ArrayList_Count(presentation->stream_list);
for (index = 0; index < count; index++)
{
- stream = (TSMF_STREAM *) ArrayList_GetItem(presentation->stream_list, index);
+ stream = (TSMF_STREAM*) ArrayList_GetItem(presentation->stream_list, index);
ret &= tsmf_stream_stop(stream);
}
ArrayList_Unlock(presentation->stream_list);
presentation->audio_start_time = 0;
presentation->audio_end_time = 0;
-
return ret;
}
BOOL tsmf_presentation_set_geometry_info(TSMF_PRESENTATION* presentation,
- UINT32 x, UINT32 y, UINT32 width, UINT32 height, int num_rects, RDP_RECT *rects)
+ UINT32 x, UINT32 y, UINT32 width, UINT32 height, int num_rects, RDP_RECT* rects)
{
UINT32 index;
UINT32 count;
TSMF_STREAM* stream;
- void *tmp_rects = NULL;
+ void* tmp_rects = NULL;
BOOL ret = TRUE;
/* The server may send messages with invalid width / height.
* added to the presentation. Also, num_rects is used to indicate whether or not the window is visible.
* So, always process a valid message with unchanged position/size and/or no visibility rects.
*/
-
presentation->x = x;
presentation->y = y;
presentation->width = width;
presentation->height = height;
-
tmp_rects = realloc(presentation->rects, sizeof(RDP_RECT) * num_rects);
-
presentation->nr_rects = num_rects;
presentation->rects = tmp_rects;
-
CopyMemory(presentation->rects, rects, sizeof(RDP_RECT) * num_rects);
-
ArrayList_Lock(presentation->stream_list);
count = ArrayList_Count(presentation->stream_list);
for (index = 0; index < count; index++)
{
- stream = (TSMF_STREAM *) ArrayList_GetItem(presentation->stream_list, index);
+ stream = (TSMF_STREAM*) ArrayList_GetItem(presentation->stream_list, index);
if (!stream->decoder)
continue;
if (stream->decoder->UpdateRenderingArea)
{
- ret = stream->decoder->UpdateRenderingArea(stream->decoder, x, y, width, height, num_rects, rects);
+ ret = stream->decoder->UpdateRenderingArea(stream->decoder, x, y, width, height,
+ num_rects, rects);
}
}
return ret;
}
-void tsmf_presentation_set_audio_device(TSMF_PRESENTATION* presentation, const char *name, const char *device)
+void tsmf_presentation_set_audio_device(TSMF_PRESENTATION* presentation,
+ const char* name, const char* device)
{
presentation->audio_name = name;
presentation->audio_device = device;
stream->presentation->audio_start_time = 0;
stream->presentation->audio_end_time = 0;
}
+
return TRUE;
}
tsmf_presentation_stop(presentation);
ArrayList_Clear(presentation->stream_list);
ArrayList_Free(presentation->stream_list);
-
free(presentation->rects);
-
ZeroMemory(presentation, sizeof(TSMF_PRESENTATION));
free(presentation);
}
ArrayList_Remove(presentation_list, presentation);
}
-TSMF_STREAM* tsmf_stream_new(TSMF_PRESENTATION* presentation, UINT32 stream_id, rdpContext* rdpcontext)
+TSMF_STREAM* tsmf_stream_new(TSMF_PRESENTATION* presentation, UINT32 stream_id,
+ rdpContext* rdpcontext)
{
TSMF_STREAM* stream;
stream = tsmf_stream_find_by_id(presentation, stream_id);
}
stream = (TSMF_STREAM*) calloc(1, sizeof(TSMF_STREAM));
+
if (!stream)
{
WLog_ERR(TAG, "Calloc failed");
stream->minBufferLevel = VIDEO_MIN_BUFFER_LEVEL;
stream->maxBufferLevel = VIDEO_MAX_BUFFER_LEVEL;
stream->currentBufferLevel = 1;
-
stream->seeking = FALSE;
stream->eos = 0;
stream->eos_message_id = 0;
stream->stream_id = stream_id;
stream->presentation = presentation;
stream->stopEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
+
if (!stream->stopEvent)
goto error_stopEvent;
+
stream->ready = CreateEvent(NULL, TRUE, TRUE, NULL);
+
if (!stream->ready)
goto error_ready;
+
stream->sample_list = Queue_New(TRUE, -1, -1);
+
if (!stream->sample_list)
goto error_sample_list;
+
stream->sample_list->object.fnObjectFree = tsmf_sample_free;
stream->sample_ack_list = Queue_New(TRUE, -1, -1);
+
if (!stream->sample_ack_list)
goto error_sample_ack_list;
+
stream->sample_ack_list->object.fnObjectFree = tsmf_sample_free;
+ stream->play_thread = CreateThread(NULL, 0,
+ (LPTHREAD_START_ROUTINE) tsmf_stream_playback_func, stream, 0, NULL);
- stream->play_thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) tsmf_stream_playback_func, stream, 0, NULL);
if (!stream->play_thread)
goto error_play_thread;
- stream->ack_thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)tsmf_stream_ack_func, stream, 0, NULL);
+
+ stream->ack_thread = CreateThread(NULL, 0,
+ (LPTHREAD_START_ROUTINE)tsmf_stream_ack_func, stream, 0, NULL);
+
if (!stream->ack_thread)
goto error_ack_thread;
goto error_add;
stream->rdpcontext = rdpcontext;
-
return stream;
-
error_add:
SetEvent(stream->stopEvent);
+
if (WaitForSingleObject(stream->ack_thread, INFINITE) == WAIT_FAILED)
WLog_ERR(TAG, "WaitForSingleObject failed with error %lu!", GetLastError());
+
error_ack_thread:
SetEvent(stream->stopEvent);
+
if (WaitForSingleObject(stream->play_thread, INFINITE) == WAIT_FAILED)
WLog_ERR(TAG, "WaitForSingleObject failed with error %lu!", GetLastError());
+
error_play_thread:
Queue_Free(stream->sample_ack_list);
error_sample_ack_list:
return NULL;
}
-TSMF_STREAM *tsmf_stream_find_by_id(TSMF_PRESENTATION* presentation, UINT32 stream_id)
+TSMF_STREAM* tsmf_stream_find_by_id(TSMF_PRESENTATION* presentation,
+ UINT32 stream_id)
{
UINT32 index;
UINT32 count;
BOOL found = FALSE;
TSMF_STREAM* stream;
-
ArrayList_Lock(presentation->stream_list);
count = ArrayList_Count(presentation->stream_list);
return (found) ? stream : NULL;
}
-static void tsmf_stream_resync(void *arg)
+static void tsmf_stream_resync(void* arg)
{
TSMF_STREAM* stream = arg;
ResetEvent(stream->ready);
}
-BOOL tsmf_stream_set_format(TSMF_STREAM* stream, const char *name, wStream *s)
+BOOL tsmf_stream_set_format(TSMF_STREAM* stream, const char* name, wStream* s)
{
TS_AM_MEDIA_TYPE mediatype;
BOOL ret = TRUE;
if (mediatype.MajorType == TSMF_MAJOR_TYPE_VIDEO)
{
DEBUG_TSMF("video width %d height %d bit_rate %d frame_rate %f codec_data %d",
- mediatype.Width, mediatype.Height, mediatype.BitRate,
- (double) mediatype.SamplesPerSecond.Numerator / (double) mediatype.SamplesPerSecond.Denominator,
- mediatype.ExtraDataSize);
-
+ mediatype.Width, mediatype.Height, mediatype.BitRate,
+ (double) mediatype.SamplesPerSecond.Numerator / (double)
+ mediatype.SamplesPerSecond.Denominator,
+ mediatype.ExtraDataSize);
stream->minBufferLevel = VIDEO_MIN_BUFFER_LEVEL;
stream->maxBufferLevel = VIDEO_MAX_BUFFER_LEVEL;
}
else if (mediatype.MajorType == TSMF_MAJOR_TYPE_AUDIO)
{
DEBUG_TSMF("audio channel %d sample_rate %d bits_per_sample %d codec_data %d",
- mediatype.Channels, mediatype.SamplesPerSecond.Numerator, mediatype.BitsPerSample,
- mediatype.ExtraDataSize);
+ mediatype.Channels, mediatype.SamplesPerSecond.Numerator,
+ mediatype.BitsPerSample,
+ mediatype.ExtraDataSize);
stream->sample_rate = mediatype.SamplesPerSecond.Numerator;
stream->channels = mediatype.Channels;
stream->bits_per_sample = mediatype.BitsPerSample;
stream->width = mediatype.Width;
stream->height = mediatype.Height;
stream->decoder = tsmf_load_decoder(name, &mediatype);
- ret &= tsmf_stream_change_volume(stream, stream->presentation->volume, stream->presentation->muted);
+ ret &= tsmf_stream_change_volume(stream, stream->presentation->volume,
+ stream->presentation->muted);
if (!stream->decoder)
return FALSE;
if (stream->decoder->SetAckFunc)
- ret &= stream->decoder->SetAckFunc(stream->decoder, tsmf_stream_process_ack, stream);
+ ret &= stream->decoder->SetAckFunc(stream->decoder, tsmf_stream_process_ack,
+ stream);
if (stream->decoder->SetSyncFunc)
- ret &= stream->decoder->SetSyncFunc(stream->decoder, tsmf_stream_resync, stream);
+ ret &= stream->decoder->SetSyncFunc(stream->decoder, tsmf_stream_resync,
+ stream);
+
return ret;
}
-void tsmf_stream_end(TSMF_STREAM* stream, UINT32 message_id, IWTSVirtualChannelCallback* pChannelCallback)
+void tsmf_stream_end(TSMF_STREAM* stream, UINT32 message_id,
+ IWTSVirtualChannelCallback* pChannelCallback)
{
if (!stream)
return;
WLog_ERR(TAG, "WaitForSingleObject failed with error %lu!", GetLastError());
return;
}
+
CloseHandle(stream->ack_thread);
stream->ack_thread = NULL;
}
ArrayList_Remove(presentation->stream_list, stream);
}
-BOOL tsmf_stream_push_sample(TSMF_STREAM* stream, IWTSVirtualChannelCallback *pChannelCallback,
- UINT32 sample_id, UINT64 start_time, UINT64 end_time, UINT64 duration, UINT32 extensions,
- UINT32 data_size, BYTE *data)
+BOOL tsmf_stream_push_sample(TSMF_STREAM* stream,
+ IWTSVirtualChannelCallback* pChannelCallback,
+ UINT32 sample_id, UINT64 start_time, UINT64 end_time, UINT64 duration,
+ UINT32 extensions,
+ UINT32 data_size, BYTE* data)
{
TSMF_SAMPLE* sample;
SetEvent(stream->ready);
return TRUE;
sample = (TSMF_SAMPLE*) calloc(1, sizeof(TSMF_SAMPLE));
+
if (!sample)
{
WLog_ERR(TAG, "calloc sample failed!");
sample->end_time = end_time;
sample->duration = duration;
sample->extensions = extensions;
+
if ((sample->extensions & 0x00000080) || (sample->extensions & 0x00000040))
sample->invalidTimestamps = TRUE;
else
sample->invalidTimestamps = FALSE;
+
sample->stream = stream;
sample->channel_callback = pChannelCallback;
sample->data_size = data_size;
if (!presentation_list)
{
presentation_list = ArrayList_New(TRUE);
+
if (!presentation_list)
return FALSE;
- ArrayList_Object(presentation_list)->fnObjectFree = (OBJECT_FREE_FN) _tsmf_presentation_free;
+
+ ArrayList_Object(presentation_list)->fnObjectFree = (OBJECT_FREE_FN)
+ _tsmf_presentation_free;
}
+
return TRUE;
}