Merge branch 'master' of github.com:FreeRDP/FreeRDP into winpr

This commit is contained in:
Marc-André Moreau 2012-05-20 17:04:28 -04:00
commit 23cbda9468
68 changed files with 782 additions and 267 deletions

View File

@ -41,7 +41,8 @@ typedef struct _AudinALSADevice
int bytes_per_channel;
int wformat;
int block_size;
ADPCM adpcm;
FREERDP_DSP_CONTEXT* dsp_context;
freerdp_thread* thread;
@ -96,7 +97,6 @@ static boolean audin_alsa_thread_receive(AudinALSADevice* alsa, uint8* src, int
uint8* encoded_data;
int rbytes_per_frame;
int tbytes_per_frame;
uint8* resampled_data;
rbytes_per_frame = alsa->actual_channels * alsa->bytes_per_channel;
tbytes_per_frame = alsa->target_channels * alsa->bytes_per_channel;
@ -104,18 +104,18 @@ static boolean audin_alsa_thread_receive(AudinALSADevice* alsa, uint8* src, int
if ((alsa->target_rate == alsa->actual_rate) &&
(alsa->target_channels == alsa->actual_channels))
{
resampled_data = NULL;
frames = size / rbytes_per_frame;
}
else
{
resampled_data = dsp_resample(src, alsa->bytes_per_channel,
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, &frames);
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 = frames * tbytes_per_frame;
src = resampled_data;
src = alsa->dsp_context->resampled_buffer;
}
while (frames > 0)
@ -133,9 +133,11 @@ static boolean audin_alsa_thread_receive(AudinALSADevice* alsa, uint8* src, int
{
if (alsa->wformat == 0x11)
{
encoded_data = dsp_encode_ima_adpcm(&alsa->adpcm,
alsa->dsp_context->encode_ima_adpcm(alsa->dsp_context,
alsa->buffer, alsa->buffer_frames * tbytes_per_frame,
alsa->target_channels, alsa->block_size, &encoded_size);
alsa->target_channels, alsa->block_size);
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);
}
@ -153,8 +155,6 @@ static boolean audin_alsa_thread_receive(AudinALSADevice* alsa, uint8* src, int
else
ret = alsa->receive(encoded_data, encoded_size, alsa->user_data);
alsa->buffer_frames = 0;
if (encoded_data != alsa->buffer)
xfree(encoded_data);
if (!ret)
break;
}
@ -162,9 +162,6 @@ static boolean audin_alsa_thread_receive(AudinALSADevice* alsa, uint8* src, int
frames -= cframes;
}
if (resampled_data)
xfree(resampled_data);
return ret;
}
@ -184,7 +181,7 @@ static void* audin_alsa_thread_func(void* arg)
alsa->buffer = (uint8*) xzalloc(tbytes_per_frame * alsa->frames_per_packet);
alsa->buffer_frames = 0;
buffer = (uint8*) xzalloc(rbytes_per_frame * alsa->frames_per_packet);
memset(&alsa->adpcm, 0, sizeof(ADPCM));
freerdp_dsp_context_reset_adpcm(alsa->dsp_context);
do
{
if ((error = snd_pcm_open(&capture_handle, alsa->device_name, SND_PCM_STREAM_CAPTURE, 0)) < 0)
@ -233,6 +230,7 @@ static void audin_alsa_free(IAudinDevice* device)
AudinALSADevice* alsa = (AudinALSADevice*) device;
freerdp_thread_free(alsa->thread);
freerdp_dsp_context_free(alsa->dsp_context);
xfree(alsa);
}
@ -365,6 +363,8 @@ int FreeRDPAudinDeviceEntry(PFREERDP_AUDIN_DEVICE_ENTRY_POINTS pEntryPoints)
alsa->bytes_per_channel = 2;
alsa->thread = freerdp_thread_new();
alsa->dsp_context = freerdp_dsp_context_new();
pEntryPoints->pRegisterAudinDevice(pEntryPoints->plugin, (IAudinDevice*) alsa);
return 0;

View File

@ -39,7 +39,8 @@ typedef struct _AudinPulseDevice
pa_stream* stream;
int format;
int block_size;
ADPCM adpcm;
FREERDP_DSP_CONTEXT* dsp_context;
int bytes_per_frame;
uint8* buffer;
@ -145,6 +146,7 @@ static void audin_pulse_free(IAudinDevice* device)
pa_threaded_mainloop_free(pulse->mainloop);
pulse->mainloop = NULL;
}
freerdp_dsp_context_free(pulse->dsp_context);
xfree(pulse);
}
@ -297,9 +299,11 @@ static void audin_pulse_stream_request_callback(pa_stream* stream, size_t length
{
if (pulse->format == 0x11)
{
encoded_data = dsp_encode_ima_adpcm(&pulse->adpcm,
pulse->dsp_context->encode_ima_adpcm(pulse->dsp_context,
pulse->buffer, pulse->buffer_frames * pulse->bytes_per_frame,
pulse->sample_spec.channels, pulse->block_size, &encoded_size);
pulse->sample_spec.channels, pulse->block_size);
encoded_data = pulse->dsp_context->adpcm_buffer;
encoded_size = pulse->dsp_context->adpcm_size;
DEBUG_DVC("encoded %d to %d",
pulse->buffer_frames * pulse->bytes_per_frame, encoded_size);
}
@ -311,8 +315,6 @@ static void audin_pulse_stream_request_callback(pa_stream* stream, size_t length
ret = pulse->receive(encoded_data, encoded_size, pulse->user_data);
pulse->buffer_frames = 0;
if (encoded_data != pulse->buffer)
xfree(encoded_data);
if (!ret)
break;
}
@ -412,7 +414,7 @@ static void audin_pulse_open(IAudinDevice* device, AudinReceive receive, void* u
pa_threaded_mainloop_unlock(pulse->mainloop);
if (state == PA_STREAM_READY)
{
memset(&pulse->adpcm, 0, sizeof(ADPCM));
freerdp_dsp_context_reset_adpcm(pulse->dsp_context);
pulse->buffer = xzalloc(pulse->bytes_per_frame * pulse->frames_per_packet);
pulse->buffer_frames = 0;
DEBUG_DVC("connected");
@ -443,6 +445,8 @@ int FreeRDPAudinDeviceEntry(PFREERDP_AUDIN_DEVICE_ENTRY_POINTS pEntryPoints)
strncpy(pulse->device_name, (char*)data->data[2], sizeof(pulse->device_name));
}
pulse->dsp_context = freerdp_dsp_context_new();
pulse->mainloop = pa_threaded_mainloop_new();
if (!pulse->mainloop)
{

View File

@ -40,6 +40,8 @@ typedef struct _TSMFALSAAudioDevice
uint32 source_channels;
uint32 actual_channels;
uint32 bytes_per_sample;
FREERDP_DSP_CONTEXT* dsp_context;
} TSMFALSAAudioDevice;
static boolean tsmf_alsa_open_device(TSMFALSAAudioDevice* alsa)
@ -151,7 +153,6 @@ static boolean tsmf_alsa_play(ITSMFAudioDevice* audio, uint8* data, uint32 data_
uint8* pindex;
int rbytes_per_frame;
int sbytes_per_frame;
uint8* resampled_data;
TSMFALSAAudioDevice* alsa = (TSMFALSAAudioDevice*) audio;
DEBUG_DVC("data_size %d", data_size);
@ -164,18 +165,18 @@ static boolean tsmf_alsa_play(ITSMFAudioDevice* audio, uint8* data, uint32 data_
if ((alsa->source_rate == alsa->actual_rate) &&
(alsa->source_channels == alsa->actual_channels))
{
resampled_data = NULL;
src = data;
}
else
{
resampled_data = dsp_resample(data, alsa->bytes_per_sample,
alsa->dsp_context->resample(alsa->dsp_context, data, alsa->bytes_per_sample,
alsa->source_channels, alsa->source_rate, data_size / sbytes_per_frame,
alsa->actual_channels, alsa->actual_rate, &frames);
alsa->actual_channels, alsa->actual_rate);
frames = alsa->dsp_context->resampled_frames;
DEBUG_DVC("resampled %d frames at %d to %d frames at %d",
data_size / sbytes_per_frame, alsa->source_rate, frames, alsa->actual_rate);
data_size = frames * rbytes_per_frame;
src = resampled_data;
src = alsa->dsp_context->resampled_buffer;
}
pindex = src;
@ -203,9 +204,6 @@ static boolean tsmf_alsa_play(ITSMFAudioDevice* audio, uint8* data, uint32 data_
break;
pindex += error * rbytes_per_frame;
}
if (resampled_data)
xfree(resampled_data);
}
xfree(data);
@ -242,6 +240,7 @@ static void tsmf_alsa_free(ITSMFAudioDevice* audio)
snd_pcm_drain(alsa->out_handle);
snd_pcm_close(alsa->out_handle);
}
freerdp_dsp_context_free(alsa->dsp_context);
xfree(alsa);
}
@ -258,6 +257,8 @@ ITSMFAudioDevice* TSMFAudioDeviceEntry(void)
alsa->iface.Flush = tsmf_alsa_flush;
alsa->iface.Free = tsmf_alsa_free;
alsa->dsp_context = freerdp_dsp_context_new();
return (ITSMFAudioDevice*) alsa;
}

View File

@ -128,7 +128,8 @@ int tsmf_ifman_on_new_presentation(TSMF_IFMAN* ifman)
presentation = tsmf_presentation_new(stream_get_tail(ifman->input), ifman->channel_callback);
if (presentation == NULL)
error = 1;
tsmf_presentation_set_audio_device(presentation, ifman->audio_name, ifman->audio_device);
else
tsmf_presentation_set_audio_device(presentation, ifman->audio_name, ifman->audio_device);
ifman->output_pending = true;
return error;
}
@ -389,9 +390,12 @@ int tsmf_ifman_on_end_of_stream(TSMF_IFMAN* ifman)
presentation = tsmf_presentation_find_by_id(stream_get_tail(ifman->input));
stream_seek(ifman->input, 16);
stream_read_uint32(ifman->input, StreamId);
stream = tsmf_stream_find_by_id(presentation, StreamId);
tsmf_stream_end(stream);
if (presentation)
{
stream = tsmf_stream_find_by_id(presentation, StreamId);
if (stream)
tsmf_stream_end(stream);
}
DEBUG_DVC("StreamId %d", StreamId);
stream_check_size(ifman->output, 16);

View File

@ -140,7 +140,7 @@ static TSMF_SAMPLE* tsmf_stream_pop_sample(TSMF_STREAM* stream, int sync)
boolean pending = false;
TSMF_PRESENTATION* presentation = stream->presentation;
if (!stream->sample_list->head)
if (list_size(stream->sample_list) == 0)
return NULL;
if (sync)
@ -210,10 +210,10 @@ static void tsmf_stream_process_ack(TSMF_STREAM* stream)
uint64 ack_time;
ack_time = get_current_time();
while (stream->sample_ack_list->head && !freerdp_thread_is_stopped(stream->thread))
while (list_size(stream->sample_ack_list) > 0 && !freerdp_thread_is_stopped(stream->thread))
{
sample = (TSMF_SAMPLE*) list_peek(stream->sample_ack_list);
if (sample->ack_time > ack_time)
if (!sample || sample->ack_time > ack_time)
break;
sample = list_dequeue(stream->sample_ack_list);
@ -448,6 +448,7 @@ static void tsmf_sample_playback(TSMF_SAMPLE* sample)
sample->pixfmt = pixfmt;
}
ret = false ;
if (stream->decoder->GetDecodedDimension)
ret = stream->decoder->GetDecodedDimension(stream->decoder, &width, &height);
if (ret && (width != stream->width || height != stream->height))
@ -646,9 +647,9 @@ void tsmf_presentation_free(TSMF_PRESENTATION* presentation)
tsmf_presentation_stop(presentation);
list_remove(presentation_list, presentation);
while (presentation->stream_list->head)
while (list_size(presentation->stream_list) > 0)
{
stream = (TSMF_STREAM*) list_peek(presentation->stream_list);
stream = (TSMF_STREAM*) list_dequeue(presentation->stream_list);
tsmf_stream_free(stream);
}
list_free(presentation->stream_list);

View File

@ -450,6 +450,7 @@ void rail_send_handshake_order(rdpRailOrder* rail_order)
s = rail_pdu_init(RAIL_HANDSHAKE_ORDER_LENGTH);
rail_write_handshake_order(s, &rail_order->handshake);
rail_send_pdu(rail_order, s, RAIL_ORDER_TYPE_HANDSHAKE);
stream_free(s) ;
}
void rail_send_client_status_order(rdpRailOrder* rail_order)
@ -458,6 +459,7 @@ void rail_send_client_status_order(rdpRailOrder* rail_order)
s = rail_pdu_init(RAIL_CLIENT_STATUS_ORDER_LENGTH);
rail_write_client_status_order(s, &rail_order->client_status);
rail_send_pdu(rail_order, s, RAIL_ORDER_TYPE_CLIENT_STATUS);
stream_free(s) ;
}
void rail_send_client_exec_order(rdpRailOrder* rail_order)
@ -473,6 +475,7 @@ void rail_send_client_exec_order(rdpRailOrder* rail_order)
s = rail_pdu_init(RAIL_EXEC_ORDER_LENGTH);
rail_write_client_exec_order(s, &rail_order->exec);
rail_send_pdu(rail_order, s, RAIL_ORDER_TYPE_EXEC);
stream_free(s) ;
}
void rail_send_client_sysparam_order(rdpRailOrder* rail_order)
@ -505,6 +508,7 @@ void rail_send_client_sysparam_order(rdpRailOrder* rail_order)
s = rail_pdu_init(RAIL_SYSPARAM_ORDER_LENGTH + 8);
rail_write_client_sysparam_order(s, &rail_order->sysparam);
rail_send_pdu(rail_order, s, RAIL_ORDER_TYPE_SYSPARAM);
stream_free(s) ;
}
void rail_send_client_sysparams_order(rdpRailOrder* rail_order)
@ -558,6 +562,7 @@ void rail_send_client_activate_order(rdpRailOrder* rail_order)
s = rail_pdu_init(RAIL_ACTIVATE_ORDER_LENGTH);
rail_write_client_activate_order(s, &rail_order->activate);
rail_send_pdu(rail_order, s, RAIL_ORDER_TYPE_ACTIVATE);
stream_free(s) ;
}
void rail_send_client_sysmenu_order(rdpRailOrder* rail_order)
@ -566,6 +571,7 @@ void rail_send_client_sysmenu_order(rdpRailOrder* rail_order)
s = rail_pdu_init(RAIL_SYSMENU_ORDER_LENGTH);
rail_write_client_sysmenu_order(s, &rail_order->sysmenu);
rail_send_pdu(rail_order, s, RAIL_ORDER_TYPE_SYSMENU);
stream_free(s) ;
}
void rail_send_client_syscommand_order(rdpRailOrder* rail_order)
@ -574,6 +580,7 @@ void rail_send_client_syscommand_order(rdpRailOrder* rail_order)
s = rail_pdu_init(RAIL_SYSCOMMAND_ORDER_LENGTH);
rail_write_client_syscommand_order(s, &rail_order->syscommand);
rail_send_pdu(rail_order, s, RAIL_ORDER_TYPE_SYSCOMMAND);
stream_free(s) ;
}
void rail_send_client_notify_event_order(rdpRailOrder* rail_order)
@ -582,6 +589,7 @@ void rail_send_client_notify_event_order(rdpRailOrder* rail_order)
s = rail_pdu_init(RAIL_NOTIFY_EVENT_ORDER_LENGTH);
rail_write_client_notify_event_order(s, &rail_order->notify_event);
rail_send_pdu(rail_order, s, RAIL_ORDER_TYPE_NOTIFY_EVENT);
stream_free(s) ;
}
void rail_send_client_window_move_order(rdpRailOrder* rail_order)
@ -590,6 +598,7 @@ void rail_send_client_window_move_order(rdpRailOrder* rail_order)
s = rail_pdu_init(RAIL_WINDOW_MOVE_ORDER_LENGTH);
rail_write_client_window_move_order(s, &rail_order->window_move);
rail_send_pdu(rail_order, s, RAIL_ORDER_TYPE_WINDOW_MOVE);
stream_free(s) ;
}
void rail_send_client_get_appid_req_order(rdpRailOrder* rail_order)
@ -598,6 +607,7 @@ void rail_send_client_get_appid_req_order(rdpRailOrder* rail_order)
s = rail_pdu_init(RAIL_GET_APPID_REQ_ORDER_LENGTH);
rail_write_client_get_appid_req_order(s, &rail_order->get_appid_req);
rail_send_pdu(rail_order, s, RAIL_ORDER_TYPE_GET_APPID_REQ);
stream_free(s) ;
}
void rail_send_client_langbar_info_order(rdpRailOrder* rail_order)
@ -606,6 +616,7 @@ void rail_send_client_langbar_info_order(rdpRailOrder* rail_order)
s = rail_pdu_init(RAIL_LANGBAR_INFO_ORDER_LENGTH);
rail_write_langbar_info_order(s, &rail_order->langbar_info);
rail_send_pdu(rail_order, s, RAIL_ORDER_TYPE_LANGBAR_INFO);
stream_free(s) ;
}
rdpRailOrder* rail_order_new()

View File

@ -434,13 +434,21 @@ boolean serial_tty_write(SERIAL_TTY* tty, uint8* buffer, uint32 Length)
return true;
}
/**
* This function is used to deallocated a SERIAL_TTY structure.
*
* @param tty [in] - pointer to the SERIAL_TTY structure to deallocate.
* This will typically be allocated by a call to serial_tty_new().
* On return, this pointer is invalid.
*/
void serial_tty_free(SERIAL_TTY* tty)
{
DEBUG_SVC("in");
if (tty->fd >= 0)
{
tcsetattr(tty->fd, TCSANOW, tty->pold_termios);
if (tty->pold_termios)
tcsetattr(tty->fd, TCSANOW, tty->pold_termios);
close(tty->fd);
}
@ -449,6 +457,7 @@ void serial_tty_free(SERIAL_TTY* tty)
xfree(tty);
}
SERIAL_TTY* serial_tty_new(const char* path, uint32 id)
{
SERIAL_TTY* tty;
@ -460,21 +469,32 @@ SERIAL_TTY* serial_tty_new(const char* path, uint32 id)
{
perror("open");
DEBUG_WARN("failed to open device %s", path);
serial_tty_free(tty) ;
return NULL;
}
else
DEBUG_SVC("tty fd %d successfully opened", tty->fd);
tty->ptermios = (struct termios*) malloc(sizeof(struct termios));
memset(tty->ptermios, 0, sizeof(struct termios));
tty->pold_termios = (struct termios*) malloc(sizeof(struct termios));
memset(tty->pold_termios, 0, sizeof(struct termios));
tty->ptermios = (struct termios*) xzalloc(sizeof(struct termios));
if (tty->ptermios == NULL)
{
serial_tty_free(tty) ;
return NULL ;
}
tty->pold_termios = (struct termios*) xzalloc(sizeof(struct termios));
if (tty->pold_termios == NULL)
{
serial_tty_free(tty) ;
return NULL ;
}
tcgetattr(tty->fd, tty->pold_termios);
if (!tty_get_termios(tty))
{
DEBUG_WARN("%s access denied", path);
fflush(stdout);
serial_tty_free(tty) ;
return NULL;
}
@ -497,6 +517,7 @@ SERIAL_TTY* serial_tty_new(const char* path, uint32 id)
{
DEBUG_WARN("%s fcntl", path);
perror("fcntl");
serial_tty_free(tty) ;
return NULL;
}

View File

@ -45,7 +45,8 @@ struct rdpsnd_alsa_plugin
int wformat;
int block_size;
int latency;
ADPCM adpcm;
FREERDP_DSP_CONTEXT* dsp_context;
};
static void rdpsnd_alsa_set_params(rdpsndAlsaPlugin* alsa)
@ -74,7 +75,7 @@ static void rdpsnd_alsa_set_params(rdpsndAlsaPlugin* alsa)
snd_pcm_hw_params_set_channels_near(alsa->out_handle, hw_params,
&alsa->actual_channels);
if (alsa->latency < 0)
frames = alsa->actual_rate * 4; /* Default to 4-second buffer */
frames = alsa->actual_rate * 4 / 10; /* Default to 400ms buffer */
else
frames = alsa->latency * alsa->actual_rate * 2 / 1000; /* Double of the latency */
if (frames < alsa->actual_rate / 2)
@ -169,7 +170,7 @@ static void rdpsnd_alsa_open(rdpsndDevicePlugin* device, rdpsndFormat* format, i
}
else
{
memset(&alsa->adpcm, 0, sizeof(ADPCM));
freerdp_dsp_context_reset_adpcm(alsa->dsp_context);
rdpsnd_alsa_set_format(device, format, latency);
}
}
@ -193,6 +194,7 @@ static void rdpsnd_alsa_free(rdpsndDevicePlugin* device)
rdpsnd_alsa_close(device);
xfree(alsa->device_name);
freerdp_dsp_context_free(alsa->dsp_context);
xfree(alsa);
}
@ -229,10 +231,7 @@ static void rdpsnd_alsa_set_volume(rdpsndDevicePlugin* device, uint32 value)
static void rdpsnd_alsa_play(rdpsndDevicePlugin* device, uint8* data, int size)
{
rdpsndAlsaPlugin* alsa = (rdpsndAlsaPlugin*)device;
uint8* decoded_data;
int decoded_size;
uint8* src;
uint8* resampled_data;
int len;
int error;
int frames;
@ -246,14 +245,13 @@ static void rdpsnd_alsa_play(rdpsndDevicePlugin* device, uint8* data, int size)
if (alsa->wformat == 0x11)
{
decoded_data = dsp_decode_ima_adpcm(&alsa->adpcm,
data, size, alsa->source_channels, alsa->block_size, &decoded_size);
size = decoded_size;
src = decoded_data;
alsa->dsp_context->decode_ima_adpcm(alsa->dsp_context,
data, size, alsa->source_channels, alsa->block_size);
size = alsa->dsp_context->adpcm_size;
src = alsa->dsp_context->adpcm_buffer;
}
else
{
decoded_data = NULL;
src = data;
}
@ -268,17 +266,17 @@ static void rdpsnd_alsa_play(rdpsndDevicePlugin* device, uint8* data, int size)
if ((alsa->source_rate == alsa->actual_rate) &&
(alsa->source_channels == alsa->actual_channels))
{
resampled_data = NULL;
}
else
{
resampled_data = dsp_resample(src, alsa->bytes_per_channel,
alsa->dsp_context->resample(alsa->dsp_context, src, alsa->bytes_per_channel,
alsa->source_channels, alsa->source_rate, size / sbytes_per_frame,
alsa->actual_channels, alsa->actual_rate, &frames);
alsa->actual_channels, alsa->actual_rate);
frames = alsa->dsp_context->resampled_frames;
DEBUG_SVC("resampled %d frames at %d to %d frames at %d",
size / sbytes_per_frame, alsa->source_rate, frames, alsa->actual_rate);
size = frames * rbytes_per_frame;
src = resampled_data;
src = alsa->dsp_context->resampled_buffer;
}
pindex = src;
@ -303,11 +301,6 @@ static void rdpsnd_alsa_play(rdpsndDevicePlugin* device, uint8* data, int size)
}
pindex += error * rbytes_per_frame;
}
if (resampled_data)
xfree(resampled_data);
if (decoded_data)
xfree(decoded_data);
}
static void rdpsnd_alsa_start(rdpsndDevicePlugin* device)
@ -353,6 +346,8 @@ int FreeRDPRdpsndDeviceEntry(PFREERDP_RDPSND_DEVICE_ENTRY_POINTS pEntryPoints)
alsa->actual_channels = 2;
alsa->bytes_per_channel = 2;
alsa->dsp_context = freerdp_dsp_context_new();
pEntryPoints->pRegisterRdpsndDevice(pEntryPoints->rdpsnd, (rdpsndDevicePlugin*)alsa);
return 0;

View File

@ -41,7 +41,8 @@ struct rdpsnd_pulse_plugin
int format;
int block_size;
int latency;
ADPCM adpcm;
FREERDP_DSP_CONTEXT* dsp_context;
};
static void rdpsnd_pulse_context_state_callback(pa_context* context, void* userdata)
@ -297,7 +298,7 @@ static void rdpsnd_pulse_open(rdpsndDevicePlugin* device, rdpsndFormat* format,
pa_threaded_mainloop_unlock(pulse->mainloop);
if (state == PA_STREAM_READY)
{
memset(&pulse->adpcm, 0, sizeof(ADPCM));
freerdp_dsp_context_reset_adpcm(pulse->dsp_context);
DEBUG_SVC("connected");
}
else
@ -329,6 +330,7 @@ static void rdpsnd_pulse_free(rdpsndDevicePlugin* device)
pulse->mainloop = NULL;
}
xfree(pulse->device_name);
freerdp_dsp_context_free(pulse->dsp_context);
xfree(pulse);
}
@ -398,23 +400,20 @@ static void rdpsnd_pulse_play(rdpsndDevicePlugin* device, uint8* data, int size)
rdpsndPulsePlugin* pulse = (rdpsndPulsePlugin*)device;
int len;
int ret;
uint8* decoded_data;
uint8* src;
int decoded_size;
if (!pulse->stream)
return;
if (pulse->format == 0x11)
{
decoded_data = dsp_decode_ima_adpcm(&pulse->adpcm,
data, size, pulse->sample_spec.channels, pulse->block_size, &decoded_size);
size = decoded_size;
src = decoded_data;
pulse->dsp_context->decode_ima_adpcm(pulse->dsp_context,
data, size, pulse->sample_spec.channels, pulse->block_size);
size = pulse->dsp_context->adpcm_size;
src = pulse->dsp_context->adpcm_buffer;
}
else
{
decoded_data = NULL;
src = data;
}
@ -440,9 +439,6 @@ static void rdpsnd_pulse_play(rdpsndDevicePlugin* device, uint8* data, int size)
size -= len;
}
pa_threaded_mainloop_unlock(pulse->mainloop);
if (decoded_data)
xfree(decoded_data);
}
static void rdpsnd_pulse_start(rdpsndDevicePlugin* device)
@ -474,12 +470,14 @@ int FreeRDPRdpsndDeviceEntry(PFREERDP_RDPSND_DEVICE_ENTRY_POINTS pEntryPoints)
data = pEntryPoints->plugin_data;
if (data && strcmp((char*)data->data[0], "pulse") == 0)
{
if(strlen((char*)data->data[1]) > 0)
if(data->data[1] && strlen((char*)data->data[1]) > 0)
pulse->device_name = xstrdup((char*)data->data[1]);
else
pulse->device_name = NULL;
}
pulse->dsp_context = freerdp_dsp_context_new();
pulse->mainloop = pa_threaded_mainloop_new();
if (!pulse->mainloop)
{

View File

@ -107,11 +107,11 @@ static void rdpsnd_process_interval(rdpSvcPlugin* plugin)
struct data_out_item* item;
uint32 cur_time;
while (rdpsnd->data_out_list->head)
while (list_size(rdpsnd->data_out_list) > 0)
{
item = (struct data_out_item*)rdpsnd->data_out_list->head->data;
item = (struct data_out_item*)list_peek(rdpsnd->data_out_list) ;
cur_time = get_mstime();
if (cur_time <= item->out_timestamp)
if (!item || cur_time <= item->out_timestamp)
break;
item = (struct data_out_item*)list_dequeue(rdpsnd->data_out_list);
@ -135,7 +135,7 @@ static void rdpsnd_process_interval(rdpSvcPlugin* plugin)
}
}
if (rdpsnd->data_out_list->head == NULL && !rdpsnd->is_open)
if (list_size(rdpsnd->data_out_list) == 0 && !rdpsnd->is_open)
{
rdpsnd->plugin.interval_ms = 0;
}

View File

@ -92,7 +92,7 @@ uint8* wf_glyph_convert(wfInfo* wfi, int width, int height, uint8* data)
src_bytes_per_row = (width + 7) / 8;
dst_bytes_per_row = src_bytes_per_row + (src_bytes_per_row % 2);
cdata = (uint8 *) malloc(dst_bytes_per_row * height);
cdata = (uint8 *) xmalloc(dst_bytes_per_row * height);
src = data;
for (indexy = 0; indexy < height; indexy++)

View File

@ -67,7 +67,7 @@ wfBitmap* wf_image_new(wfInfo* wfi, int width, int height, int bpp, uint8* data)
wfBitmap* image;
hdc = GetDC(NULL);
image = (wfBitmap*) malloc(sizeof(wfBitmap));
image = (wfBitmap*) xmalloc(sizeof(wfBitmap));
image->hdc = CreateCompatibleDC(hdc);
if (data == NULL)
@ -87,7 +87,7 @@ wfBitmap* wf_bitmap_new(wfInfo* wfi, int width, int height, int bpp, uint8* data
wfBitmap* bitmap;
hdc = GetDC(NULL);
bitmap = (wfBitmap*) malloc(sizeof(wfBitmap));
bitmap = (wfBitmap*) xmalloc(sizeof(wfBitmap));
bitmap->hdc = CreateCompatibleDC(hdc);
bitmap->bitmap = wf_create_dib(wfi, width, height, bpp, data, &(bitmap->pdata));
bitmap->org_bitmap = (HBITMAP) SelectObject(bitmap->hdc, bitmap->bitmap);

View File

@ -296,12 +296,12 @@ boolean wf_post_connect(freerdp* instance)
wfi->hdc->alpha = wfi->clrconv->alpha;
wfi->hdc->invert = wfi->clrconv->invert;
wfi->hdc->hwnd = (HGDI_WND) malloc(sizeof(GDI_WND));
wfi->hdc->hwnd = (HGDI_WND) xmalloc(sizeof(GDI_WND));
wfi->hdc->hwnd->invalid = gdi_CreateRectRgn(0, 0, 0, 0);
wfi->hdc->hwnd->invalid->null = 1;
wfi->hdc->hwnd->count = 32;
wfi->hdc->hwnd->cinvalid = (HGDI_RGN) malloc(sizeof(GDI_RGN) * wfi->hdc->hwnd->count);
wfi->hdc->hwnd->cinvalid = (HGDI_RGN) xmalloc(sizeof(GDI_RGN) * wfi->hdc->hwnd->count);
wfi->hdc->hwnd->ninvalid = 0;
wfi->image = wf_bitmap_new(wfi, 64, 64, 32, NULL);

View File

@ -334,8 +334,8 @@ void xf_gdi_patblt(rdpContext* context, PATBLT_ORDER* patblt)
brush = &patblt->brush;
xf_set_rop3(xfi, gdi_rop3_code(patblt->bRop));
foreColor = freerdp_color_convert_rgb(patblt->foreColor, xfi->srcBpp, 32, xfi->clrconv);
backColor = freerdp_color_convert_rgb(patblt->backColor, xfi->srcBpp, 32, xfi->clrconv);
foreColor = freerdp_color_convert_rgb(patblt->foreColor, xfi->srcBpp, xfi->bpp, xfi->clrconv);
backColor = freerdp_color_convert_rgb(patblt->backColor, xfi->srcBpp, xfi->bpp, xfi->clrconv);
if (brush->style == GDI_BS_SOLID)
{
@ -506,7 +506,7 @@ void xf_gdi_line_to(rdpContext* context, LINE_TO_ORDER* line_to)
xfInfo* xfi = ((xfContext*) context)->xfi;
xf_set_rop2(xfi, line_to->bRop2);
color = freerdp_color_convert_rgb(line_to->penColor, xfi->srcBpp, 32, xfi->clrconv);
color = freerdp_color_convert_rgb(line_to->penColor, xfi->srcBpp, xfi->bpp, xfi->clrconv);
XSetFillStyle(xfi->display, xfi->gc, FillSolid);
XSetForeground(xfi->display, xfi->gc, color);
@ -641,8 +641,8 @@ void xf_gdi_mem3blt(rdpContext* context, MEM3BLT_ORDER* mem3blt)
brush = &mem3blt->brush;
bitmap = (xfBitmap*) mem3blt->bitmap;
xf_set_rop3(xfi, gdi_rop3_code(mem3blt->bRop));
foreColor = freerdp_color_convert_rgb(mem3blt->foreColor, xfi->srcBpp, 32, xfi->clrconv);
backColor = freerdp_color_convert_rgb(mem3blt->backColor, xfi->srcBpp, 32, xfi->clrconv);
foreColor = freerdp_color_convert_rgb(mem3blt->foreColor, xfi->srcBpp, xfi->bpp, xfi->clrconv);
backColor = freerdp_color_convert_rgb(mem3blt->backColor, xfi->srcBpp, xfi->bpp, xfi->clrconv);
if (brush->style == GDI_BS_PATTERN)
{
@ -768,8 +768,8 @@ void xf_gdi_polygon_cb(rdpContext* context, POLYGON_CB_ORDER* polygon_cb)
brush = &(polygon_cb->brush);
xf_set_rop2(xfi, polygon_cb->bRop2);
foreColor = freerdp_color_convert_rgb(polygon_cb->foreColor, xfi->srcBpp, 32, xfi->clrconv);
backColor = freerdp_color_convert_rgb(polygon_cb->backColor, xfi->srcBpp, 32, xfi->clrconv);
foreColor = freerdp_color_convert_rgb(polygon_cb->foreColor, xfi->srcBpp, xfi->bpp, xfi->clrconv);
backColor = freerdp_color_convert_rgb(polygon_cb->backColor, xfi->srcBpp, xfi->bpp, xfi->clrconv);
npoints = polygon_cb->numPoints + 1;
points = xmalloc(sizeof(XPoint) * npoints);

View File

@ -161,8 +161,7 @@ void xf_Pointer_New(rdpContext* context, rdpPointer* pointer)
ci.height = pointer->height;
ci.xhot = pointer->xPos;
ci.yhot = pointer->yPos;
ci.pixels = (XcursorPixel*) malloc(ci.width * ci.height * 4);
memset(ci.pixels, 0, ci.width * ci.height * 4);
ci.pixels = (XcursorPixel*) xzalloc(ci.width * ci.height * 4);
if ((pointer->andMaskData != 0) && (pointer->xorMaskData != 0))
{

View File

@ -0,0 +1,39 @@
/*
* File: errorcodes.h
* Author: Arvid
*
* Created on April 13, 2012, 9:09 AM
*/
#ifndef ERRORCODES_H
#define ERRORCODES_H
#ifdef __cplusplus
extern "C" {
#endif
/**
* This static variable holds an error code if the return value from connect is false.
* This variable is always set to 0 in the beginning of the connect sequence.
* The returned code can be used to inform the user of the detailed connect error.
* The value can hold one of the defined error codes below OR an error according to errno
*/
extern int connectErrorCode ;
#define ERRORSTART 10000
#define PREECONNECTERROR ERRORSTART + 1
#define UNDEFINEDCONNECTERROR ERRORSTART + 2
#define POSTCONNECTERROR ERRORSTART + 3
#define DNSERROR ERRORSTART + 4 /* general DNS ERROR */
#define DNSNAMENOTFOUND ERRORSTART + 5 /* EAI_NONAME */
#define CONNECTERROR ERRORSTART + 6 /* a connect error if errno is not define during tcp connect */
#define MCSCONNECTINITIALERROR ERRORSTART + 7
#define TLSCONNECTERROR ERRORSTART + 8
#define AUTHENTICATIONERROR ERRORSTART + 9
#ifdef __cplusplus
}
#endif
#endif /* ERRORCODES_H */

View File

@ -39,6 +39,7 @@ typedef struct rdp_freerdp_peer freerdp_peer;
#include <freerdp/input.h>
#include <freerdp/update.h>
#include <freerdp/errorcodes.h>
#ifdef __cplusplus
extern "C" {

View File

@ -67,6 +67,8 @@ struct rdp_freerdp_peer
psPeerSendChannelData SendChannelData;
psPeerReceiveChannelData ReceiveChannelData;
uint32 ack_frame_id;
};
FREERDP_API void freerdp_peer_context_new(freerdp_peer* client);

View File

@ -391,7 +391,7 @@ struct rdp_settings
ALIGN64 uint32 rfx_codec_id; /* 282 */
ALIGN64 uint32 ns_codec_id; /* 283 */
ALIGN64 uint32 rfx_codec_mode; /* 284 */
ALIGN64 boolean frame_acknowledge; /* 285 */
ALIGN64 uint32 frame_acknowledge; /* 285 */
ALIGN64 uint64 paddingM[296 - 286]; /* 286 */
/* Recording */

View File

@ -123,6 +123,12 @@ struct _SURFACE_FRAME_MARKER
};
typedef struct _SURFACE_FRAME_MARKER SURFACE_FRAME_MARKER;
enum SURFCMD_FRAMEACTION
{
SURFACECMD_FRAMEACTION_BEGIN = 0x0000,
SURFACECMD_FRAMEACTION_END = 0x0001
};
/* Update Interface */
typedef void (*pBeginPaint)(rdpContext* context);

View File

@ -29,14 +29,34 @@ struct _ADPCM
};
typedef struct _ADPCM ADPCM;
FREERDP_API uint8* dsp_resample(uint8* src, int bytes_per_sample,
uint32 schan, uint32 srate, int sframes,
uint32 rchan, uint32 rrate, int * prframes);
typedef struct _FREERDP_DSP_CONTEXT FREERDP_DSP_CONTEXT;
struct _FREERDP_DSP_CONTEXT
{
uint8* resampled_buffer;
uint32 resampled_size;
uint32 resampled_frames;
uint32 resampled_maxlength;
FREERDP_API uint8* dsp_decode_ima_adpcm(ADPCM* adpcm,
uint8* src, int size, int channels, int block_size, int* out_size);
FREERDP_API uint8* dsp_encode_ima_adpcm(ADPCM* adpcm,
uint8* src, int size, int channels, int block_size, int* out_size);
uint8* adpcm_buffer;
uint32 adpcm_size;
uint32 adpcm_maxlength;
ADPCM adpcm;
void (*resample)(FREERDP_DSP_CONTEXT* context,
const uint8* src, int bytes_per_sample,
uint32 schan, uint32 srate, int sframes,
uint32 rchan, uint32 rrate);
void (*decode_ima_adpcm)(FREERDP_DSP_CONTEXT* context,
const uint8* src, int size, int channels, int block_size);
void (*encode_ima_adpcm)(FREERDP_DSP_CONTEXT* context,
const uint8* src, int size, int channels, int block_size);
};
FREERDP_API FREERDP_DSP_CONTEXT* freerdp_dsp_context_new(void);
FREERDP_API void freerdp_dsp_context_free(FREERDP_DSP_CONTEXT* context);
#define freerdp_dsp_context_reset_adpcm(_c) memset(&_c->adpcm, 0, sizeof(ADPCM))
#endif /* __DSP_UTILS_H */

View File

@ -198,8 +198,6 @@ typedef struct _MIDL_STUB_MESSAGE
INT_PTR Reserved51_5;
} MIDL_STUB_MESSAGE, *PMIDL_STUB_MESSAGE;
typedef struct _MIDL_STUB_MESSAGE MIDL_STUB_MESSAGE, *PMIDL_STUB_MESSAGE;
typedef void (*EXPR_EVAL)(struct _MIDL_STUB_MESSAGE*);
typedef void (*XMIT_HELPER_ROUTINE)(PMIDL_STUB_MESSAGE);

View File

@ -906,12 +906,15 @@ static void freerdp_channels_process_sync(rdpChannels* channels, freerdp* instan
rdpChannel* lrdp_channel;
struct channel_data* lchannel_data;
while (channels->sync_data_list->head != NULL)
while (list_size(channels->sync_data_list) > 0)
{
freerdp_mutex_lock(channels->sync_data_mutex);
item = (struct sync_data*)list_dequeue(channels->sync_data_list);
freerdp_mutex_unlock(channels->sync_data_mutex);
if (!item)
break ;
lchannel_data = channels->channels_data + item->index;
lrdp_channel = freerdp_channels_find_channel_by_name(channels, instance->settings,
lchannel_data->name, &item->index);

View File

@ -291,11 +291,12 @@ boolean WTSVirtualChannelRead(
/* remove the first element (same as what we just peek) */
freerdp_mutex_lock(channel->mutex);
list_dequeue(channel->receive_queue);
if (channel->receive_queue->head == NULL)
if (list_size(channel->receive_queue) == 0)
wait_obj_clear(channel->receive_event);
freerdp_mutex_unlock(channel->mutex);
memcpy(Buffer, item->buffer, item->length);
wts_data_item_free(item) ;
return true;
}

View File

@ -337,7 +337,7 @@ uint32 freerdp_color_convert_var(uint32 srcColor, int srcBpp, int dstBpp, HCLRCO
uint32 freerdp_color_convert_var_rgb(uint32 srcColor, int srcBpp, int dstBpp, HCLRCONV clrconv)
{
if (srcBpp > 16)
return freerdp_color_convert_bgr_rgb(srcColor, srcBpp, 32, clrconv);
return freerdp_color_convert_bgr_rgb(srcColor, srcBpp, dstBpp, clrconv);
else
return freerdp_color_convert_rgb(srcColor, srcBpp, dstBpp, clrconv);
}
@ -345,7 +345,7 @@ uint32 freerdp_color_convert_var_rgb(uint32 srcColor, int srcBpp, int dstBpp, HC
uint32 freerdp_color_convert_var_bgr(uint32 srcColor, int srcBpp, int dstBpp, HCLRCONV clrconv)
{
if (srcBpp > 16)
return freerdp_color_convert_bgr(srcColor, srcBpp, 32, clrconv);
return freerdp_color_convert_bgr(srcColor, srcBpp, dstBpp, clrconv);
else
return freerdp_color_convert_rgb_bgr(srcColor, srcBpp, dstBpp, clrconv);
}
@ -364,7 +364,7 @@ uint8* freerdp_image_convert_8bpp(uint8* srcData, uint8* dstData, int width, int
if (dstBpp == 8)
{
if (dstData == NULL)
dstData = (uint8*) malloc(width * height);
dstData = (uint8*) xmalloc(width * height);
memcpy(dstData, srcData, width * height);
return dstData;
@ -372,7 +372,7 @@ uint8* freerdp_image_convert_8bpp(uint8* srcData, uint8* dstData, int width, int
else if (dstBpp == 15 || (dstBpp == 16 && clrconv->rgb555))
{
if (dstData == NULL)
dstData = (uint8*) malloc(width * height * 2);
dstData = (uint8*) xmalloc(width * height * 2);
dst16 = (uint16 *) dstData;
for (i = width * height; i > 0; i--)
@ -391,7 +391,7 @@ uint8* freerdp_image_convert_8bpp(uint8* srcData, uint8* dstData, int width, int
else if (dstBpp == 16)
{
if (dstData == NULL)
dstData = (uint8*) malloc(width * height * 2);
dstData = (uint8*) xmalloc(width * height * 2);
dst16 = (uint16 *) dstData;
for (i = width * height; i > 0; i--)
@ -410,7 +410,7 @@ uint8* freerdp_image_convert_8bpp(uint8* srcData, uint8* dstData, int width, int
else if (dstBpp == 32)
{
if (dstData == NULL)
dstData = (uint8*) malloc(width * height * 4);
dstData = (uint8*) xmalloc(width * height * 4);
src8 = (uint8*) srcData;
dst32 = (uint32*) dstData;
@ -445,7 +445,7 @@ uint8* freerdp_image_convert_15bpp(uint8* srcData, uint8* dstData, int width, in
if (dstBpp == 15 || (dstBpp == 16 && clrconv->rgb555))
{
if (dstData == NULL)
dstData = (uint8*) malloc(width * height * 2);
dstData = (uint8*) xmalloc(width * height * 2);
memcpy(dstData, srcData, width * height * 2);
@ -454,7 +454,7 @@ uint8* freerdp_image_convert_15bpp(uint8* srcData, uint8* dstData, int width, in
else if (dstBpp == 32)
{
if (dstData == NULL)
dstData = (uint8*) malloc(width * height * 4);
dstData = (uint8*) xmalloc(width * height * 4);
src16 = (uint16 *) srcData;
dst32 = (uint32 *) dstData;
@ -472,7 +472,7 @@ uint8* freerdp_image_convert_15bpp(uint8* srcData, uint8* dstData, int width, in
else if (dstBpp == 16)
{
if (dstData == NULL)
dstData = (uint8*) malloc(width * height * 2);
dstData = (uint8*) xmalloc(width * height * 2);
src16 = (uint16 *) srcData;
dst16 = (uint16 *) dstData;
@ -500,7 +500,7 @@ uint8* freerdp_image_convert_16bpp(uint8* srcData, uint8* dstData, int width, in
if (dstBpp == 16)
{
if (dstData == NULL)
dstData = (uint8*) malloc(width * height * 2);
dstData = (uint8*) xmalloc(width * height * 2);
if (clrconv->rgb555)
{
@ -533,7 +533,7 @@ uint8* freerdp_image_convert_16bpp(uint8* srcData, uint8* dstData, int width, in
uint8 red, green, blue;
if (dstData == NULL)
dstData = (uint8*) malloc(width * height * 3);
dstData = (uint8*) xmalloc(width * height * 3);
dst8 = (uint8*) dstData;
src16 = (uint16*) srcData;
@ -567,7 +567,7 @@ uint8* freerdp_image_convert_16bpp(uint8* srcData, uint8* dstData, int width, in
uint8 red, green, blue;
if (dstData == NULL)
dstData = (uint8*) malloc(width * height * 4);
dstData = (uint8*) xmalloc(width * height * 4);
src16 = (uint16*) srcData;
dst32 = (uint32*) dstData;
@ -595,7 +595,7 @@ uint8* freerdp_image_convert_24bpp(uint8* srcData, uint8* dstData, int width, in
{
uint8 *dstp;
if (dstData == NULL)
dstData = (uint8*) malloc(width * height * 4);
dstData = (uint8*) xmalloc(width * height * 4);
dstp = dstData;
for (i = width * height; i > 0; i--)
@ -621,7 +621,7 @@ uint8* freerdp_image_convert_32bpp(uint8* srcData, uint8* dstData, int width, in
uint8 red, green, blue;
if (dstData == NULL)
dstData = (uint8*) malloc(width * height * 2);
dstData = (uint8*) xmalloc(width * height * 2);
dst16 = (uint16*) dstData;
src32 = (uint32*) srcData;
@ -642,7 +642,7 @@ uint8* freerdp_image_convert_32bpp(uint8* srcData, uint8* dstData, int width, in
uint8 red, green, blue;
if (dstData == NULL)
dstData = (uint8*) malloc(width * height * 3);
dstData = (uint8*) xmalloc(width * height * 3);
dstp = dstData;
for (index = 0; index < width * height; index++)
@ -676,7 +676,7 @@ uint8* freerdp_image_convert_32bpp(uint8* srcData, uint8* dstData, int width, in
uint8 *dstp;
if (dstData == NULL)
dstData = (uint8*) malloc(width * height * 4);
dstData = (uint8*) xmalloc(width * height * 4);
memcpy(dstData, srcData, width * height * 4);
@ -694,7 +694,7 @@ uint8* freerdp_image_convert_32bpp(uint8* srcData, uint8* dstData, int width, in
else
{
if (dstData == NULL)
dstData = (uint8*) malloc(width * height * 4);
dstData = (uint8*) xmalloc(width * height * 4);
memcpy(dstData, srcData, width * height * 4);
}
@ -780,10 +780,10 @@ uint8* freerdp_image_flip(uint8* srcData, uint8* dstData, int width, int height,
{
int scanline;
scanline = width * (bpp / 8);
scanline = width * ((bpp + 7) / 8);
if (dstData == NULL)
dstData = (uint8*) xmalloc(width * height * (bpp / 8));
dstData = (uint8*) xmalloc(width * height * ((bpp + 7) / 8));
freerdp_bitmap_flip(srcData, dstData, scanline, height);
return dstData;
@ -791,38 +791,52 @@ uint8* freerdp_image_flip(uint8* srcData, uint8* dstData, int width, int height,
uint8* freerdp_icon_convert(uint8* srcData, uint8* dstData, uint8* mask, int width, int height, int bpp, HCLRCONV clrconv)
{
int x, y;
int pixel;
int x, y, bit;
int maskIndex;
uint8* data;
uint8 bmask;
uint32 pmask;
uint32* icon;
pixel = 0;
if (bpp == 16)
{
/* Server sends 16 bpp field, but data is usually 15-bit 555 */
bpp = 15;
}
data = freerdp_image_flip(srcData, dstData, width, height, bpp);
dstData = freerdp_image_convert(data, NULL, width, height, bpp, 32, clrconv);
free(data);
bmask = mask[pixel];
icon = (uint32*) dstData;
/* Read the AND alpha plane */
if (bpp < 32)
{
maskIndex = 0;
icon = (uint32*) dstData;
for (y = 0; y < height; y++)
{
for (x = 0; x < width; x++)
for (x = 0; x < width-7; x+=8)
{
if (pixel % 8 == 0)
bmask = mask[pixel / 8];
else
bmask <<= 1;
pmask = (bmask & 0x80) ? 0x00000000 : 0xFF000000;
*icon++ |= pmask;
pixel++;
bmask = mask[maskIndex++];
for (bit = 0; bit < 8; bit++)
if ((bmask & (0x80 >> bit)) == 0)
*(icon + (height - y) * width + x + bit) |= 0xFF000000;
}
if ((width % 8) != 0)
{
bmask = mask[maskIndex++];
for (bit = 0; bit < width % 8; bit++)
if ((bmask & (0x80 >> bit)) == 0)
*(icon + (height - y) * width + x + bit) |= 0xFF000000;
}
/* Skip padding */
if ((width % 32) != 0)
maskIndex += (32 - (width % 32)) / 8;
}
}
@ -846,7 +860,7 @@ uint8* freerdp_glyph_convert(int width, int height, uint8* data)
*/
scanline = (width + 7) / 8;
dstData = (uint8*) malloc(width * height);
dstData = (uint8*) xmalloc(width * height);
memset(dstData, 0, width * height);
dstp = dstData;
@ -930,7 +944,7 @@ uint8* freerdp_mono_image_convert(uint8* srcData, int width, int height, int src
}
}
dstData = (uint8*) malloc(width * height * 2);
dstData = (uint8*) xmalloc(width * height * 2);
dst16 = (uint16*) dstData;
for (index = height; index > 0; index--)
@ -955,7 +969,7 @@ uint8* freerdp_mono_image_convert(uint8* srcData, int width, int height, int src
}
else if (dstBpp == 32)
{
dstData = (uint8*) malloc(width * height * 4);
dstData = (uint8*) xmalloc(width * height * 4);
dst32 = (uint32*) dstData;
for (index = height; index > 0; index--)

View File

@ -1613,7 +1613,14 @@ void rdp_write_bitmap_codecs_capability_set(STREAM* s, rdpSettings* settings)
void rdp_read_frame_acknowledge_capability_set(STREAM* s, uint16 length, rdpSettings* settings)
{
stream_seek_uint32(s); /* (4 bytes) */
if (settings->server_mode)
{
stream_read_uint32(s, settings->frame_acknowledge); /* (4 bytes) */
}
else
{
stream_seek_uint32(s); /* (4 bytes) */
}
}
/**
@ -1628,7 +1635,7 @@ void rdp_write_frame_acknowledge_capability_set(STREAM* s, rdpSettings* settings
header = rdp_capability_set_start(s);
stream_write_uint32(s, 2); /* (4 bytes) */
stream_write_uint32(s, settings->frame_acknowledge); /* (4 bytes) */
rdp_capability_set_finish(s, header, CAPSET_TYPE_FRAME_ACKNOWLEDGE);
}
@ -1873,7 +1880,7 @@ void rdp_write_demand_active(STREAM* s, rdpSettings* settings)
stream_seek_uint16(s); /* numberCapabilities (2 bytes) */
stream_write_uint16(s, 0); /* pad2Octets (2 bytes) */
numberCapabilities = 13;
numberCapabilities = 14;
rdp_write_general_capability_set(s, settings);
rdp_write_bitmap_capability_set(s, settings);
rdp_write_order_capability_set(s, settings);
@ -1887,6 +1894,7 @@ void rdp_write_demand_active(STREAM* s, rdpSettings* settings)
rdp_write_desktop_composition_capability_set(s, settings);
rdp_write_surface_commands_capability_set(s, settings);
rdp_write_bitmap_codecs_capability_set(s, settings);
rdp_write_frame_acknowledge_capability_set(s, settings);
if (settings->persistent_bitmap_cache)
{
@ -2068,7 +2076,7 @@ void rdp_write_confirm_active(STREAM* s, rdpSettings* settings)
if (settings->received_caps[CAPSET_TYPE_FRAME_ACKNOWLEDGE])
{
if (settings->frame_acknowledge)
if (settings->frame_acknowledge > 0)
{
numberCapabilities++;
rdp_write_frame_acknowledge_capability_set(s, settings);

View File

@ -491,6 +491,7 @@ rdpKey* key_new(const char* keyfile)
if (fp == NULL)
{
printf("unable to load RSA key from %s: %s.", keyfile, strerror(errno));
xfree(key) ;
return NULL;
}
@ -500,6 +501,7 @@ rdpKey* key_new(const char* keyfile)
{
ERR_print_errors_fp(stdout);
fclose(fp);
xfree(key) ;
return NULL;
}
@ -510,6 +512,7 @@ rdpKey* key_new(const char* keyfile)
case 0:
RSA_free(rsa);
printf("invalid RSA key in %s", keyfile);
xfree(key) ;
return NULL;
case 1:
@ -519,6 +522,7 @@ rdpKey* key_new(const char* keyfile)
default:
ERR_print_errors_fp(stdout);
RSA_free(rsa);
xfree(key) ;
return NULL;
}
@ -526,6 +530,7 @@ rdpKey* key_new(const char* keyfile)
{
RSA_free(rsa);
printf("RSA public exponent too large in %s", keyfile);
xfree(key) ;
return NULL;
}

View File

@ -107,6 +107,9 @@ boolean rdp_client_connect(rdpRdp* rdp)
if (mcs_send_connect_initial(rdp->mcs) != true)
{
if(!connectErrorCode){
connectErrorCode = MCSCONNECTINITIALERROR;
}
printf("Error: unable to send MCS Connect Initial\n");
return false;
}

View File

@ -28,6 +28,8 @@
#include <freerdp/freerdp.h>
#include <freerdp/utils/memory.h>
/* connectErrorCode is 'extern' in errorcodes.h. See comment there.*/
/** Creates a new connection based on the settings found in the "instance" parameter
* It will use the callbacks registered on the structure to process the pre/post connect operations
* that the caller requires.
@ -43,6 +45,8 @@ boolean freerdp_connect(freerdp* instance)
{
rdpRdp* rdp;
boolean status = false;
/* We always set the return code to 0 before we start the connect sequence*/
connectErrorCode = 0 ;
rdp = instance->context->rdp;
@ -52,6 +56,9 @@ boolean freerdp_connect(freerdp* instance)
if (status != true)
{
if(!connectErrorCode){
connectErrorCode = PREECONNECTERROR;
}
printf("freerdp_pre_connect failed\n");
return false;
}
@ -74,6 +81,9 @@ boolean freerdp_connect(freerdp* instance)
if (status != true)
{
printf("freerdp_post_connect failed\n");
if(!connectErrorCode){
connectErrorCode = POSTCONNECTERROR;
}
return false;
}
@ -109,7 +119,9 @@ boolean freerdp_connect(freerdp* instance)
return true;
}
}
if(!connectErrorCode){
connectErrorCode = UNDEFINEDCONNECTERROR;
}
return status;
}

View File

@ -488,7 +488,8 @@ boolean gcc_read_client_core_data(STREAM* s, rdpSettings* settings, uint16 block
/* clientName (32 bytes, null-terminated unicode, truncated to 15 characters) */
str = freerdp_uniconv_in(settings->uniconv, stream_get_tail(s), 32);
stream_seek(s, 32);
snprintf(settings->client_hostname, sizeof(settings->client_hostname), "%s", str);
snprintf(settings->client_hostname, 31, "%s", str);
settings->client_hostname[31] = 0;
xfree(str);
stream_read_uint32(s, settings->kbd_type); /* keyboardType */
@ -1130,7 +1131,7 @@ boolean gcc_read_client_cluster_data(STREAM* s, rdpSettings* settings, uint16 bl
stream_read_uint32(s, flags); /* flags */
if ((flags | REDIRECTED_SESSIONID_FIELD_VALID))
if ((flags & REDIRECTED_SESSIONID_FIELD_VALID))
stream_read_uint32(s, settings->redirected_session_id); /* redirectedSessionID */
return true;
@ -1208,4 +1209,3 @@ void gcc_write_client_monitor_data(STREAM* s, rdpSettings* settings)
}
}
}

View File

@ -373,6 +373,7 @@ HttpResponse* http_response_recv(rdpTls* tls)
}
else
{
http_response_free(http_response) ;
return NULL;
break;
}

View File

@ -579,11 +579,19 @@ void license_free_scope_list(SCOPE_LIST* scopeList)
{
uint32 i;
/*
* We must NOT call license_free_binary_blob() on each scopelist->array[i] element,
* because scopelist->array was allocated at once, by a single call to xmalloc. The elements
* it contains cannot be deallocated separately then.
* To make things clean, we must deallocate each scopelist->array[].data,
* and finish by deallocating scopelist->array with a single call to xfree().
*/
for (i = 0; i < scopeList->count; i++)
{
license_free_binary_blob(&scopeList->array[i]);
xfree(scopeList->array[i].data);
}
xfree(scopeList->array) ;
xfree(scopeList);
}

View File

@ -25,6 +25,7 @@
static boolean freerdp_peer_initialize(freerdp_peer* client)
{
client->context->rdp->settings->server_mode = true;
client->context->rdp->settings->frame_acknowledge = 0;
client->context->rdp->state = CONNECTION_STATE_INITIAL;
if (client->context->rdp->settings->rdp_key_file != NULL)
@ -120,6 +121,10 @@ static boolean peer_recv_data_pdu(freerdp_peer* client, STREAM* s)
mcs_send_disconnect_provider_ultimatum(client->context->rdp->mcs);
return false;
case DATA_PDU_TYPE_FRAME_ACKNOWLEDGE:
stream_read_uint32(s, client->ack_frame_id);
break;
default:
printf("Data PDU type %d\n", type);
break;

View File

@ -224,7 +224,8 @@ boolean rdp_read_header(rdpRdp* rdp, STREAM* s, uint16* length, uint16* channel_
enum DomainMCSPDU MCSPDU;
MCSPDU = (rdp->settings->server_mode) ? DomainMCSPDU_SendDataRequest : DomainMCSPDU_SendDataIndication;
mcs_read_domain_mcspdu_header(s, &MCSPDU, length);
if (!mcs_read_domain_mcspdu_header(s, &MCSPDU, length))
return false ;
if (*length - 8 > stream_get_left(s))
return false;

View File

@ -104,6 +104,7 @@
#define DATA_PDU_TYPE_ARC_STATUS 0x32
#define DATA_PDU_TYPE_STATUS_INFO 0x36
#define DATA_PDU_TYPE_MONITOR_LAYOUT 0x37
#define DATA_PDU_TYPE_FRAME_ACKNOWLEDGE 0x38
/* Stream Identifiers */
#define STREAM_UNDEFINED 0x00

View File

@ -128,7 +128,7 @@ boolean ntlm_authenticate(rdpNtlm* ntlm)
if (ntlm->table->QueryContextAttributes(&ntlm->context, SECPKG_ATTR_SIZES, &ntlm->ContextSizes) != SEC_E_OK)
{
printf("QueryContextAttributes SECPKG_ATTR_SIZES failure\n");
return 0;
return false ;
}
if (status == SEC_I_COMPLETE_NEEDED)
@ -477,6 +477,7 @@ boolean rpc_send_bind_pdu(rdpRpc* rpc)
rpc_in_write(rpc, pdu->data, pdu->size);
stream_free(pdu) ;
xfree(bind_pdu);
return true;
@ -493,6 +494,8 @@ int rpc_recv_bind_ack_pdu(rdpRpc* rpc)
int pdu_length = 0x8FFF;
pdu = xmalloc(pdu_length);
if (pdu == NULL)
return -1 ;
status = rpc_out_read(rpc, pdu, pdu_length);
if (status > 0)
@ -504,6 +507,11 @@ int rpc_recv_bind_ack_pdu(rdpRpc* rpc)
stream_free(s);
auth_data = xmalloc(header.auth_length);
if (auth_data == NULL)
{
xfree(pdu) ;
return -1 ;
}
p = (pdu + (header.frag_length - header.auth_length));
memcpy(auth_data, p, header.auth_length);
@ -566,6 +574,7 @@ boolean rpc_send_rpc_auth_3_pdu(rdpRpc* rpc)
rpc_in_write(rpc, pdu->data, stream_get_length(pdu));
stream_free(pdu) ;
xfree(rpc_auth_3_pdu);
return true;
@ -583,6 +592,11 @@ int rpc_out_read(rdpRpc* rpc, uint8* data, int length)
rts_send_flow_control_ack_pdu(rpc); /* Send FlowControlAck every time AvailableWindow reaches the half */
pdu = xmalloc(0xFFFF);
if (pdu == NULL)
{
printf("rpc_out_read error: memory allocation failed") ;
return -1 ;
}
status = tls_read(rpc->tls_out, pdu, 16); /* read first 16 bytes to get RPC PDU Header */
@ -612,6 +626,7 @@ int rpc_out_read(rdpRpc* rpc, uint8* data, int length)
if (header.ptype == PTYPE_RTS) /* RTS PDU */
{
printf("rpc_out_read error: Unexpected RTS PDU\n");
xfree(pdu);
return -1;
}
else
@ -624,6 +639,7 @@ int rpc_out_read(rdpRpc* rpc, uint8* data, int length)
if (length < header.frag_length)
{
printf("rpc_out_read error! receive buffer is not large enough\n");
xfree(pdu);
return -1;
}
@ -636,7 +652,6 @@ int rpc_out_read(rdpRpc* rpc, uint8* data, int length)
#endif
xfree(pdu);
return header.frag_length;
}
@ -704,9 +719,14 @@ int rpc_tsg_write(rdpRpc* rpc, uint8* data, int length, uint16 opnum)
stream_write(pdu, &request_pdu->auth_verifier.auth_type, 8);
xfree(request_pdu->auth_verifier.auth_value);
xfree(request_pdu->auth_verifier.auth_pad);
xfree(request_pdu);
if (ntlm->table->QueryContextAttributes(&ntlm->context, SECPKG_ATTR_SIZES, &ntlm->ContextSizes) != SEC_E_OK)
{
printf("QueryContextAttributes SECPKG_ATTR_SIZES failure\n");
stream_free(pdu) ;
return 0;
}
@ -728,6 +748,7 @@ int rpc_tsg_write(rdpRpc* rpc, uint8* data, int length, uint16 opnum)
if (encrypt_status != SEC_E_OK)
{
printf("EncryptMessage status: 0x%08X\n", encrypt_status);
stream_free(pdu) ;
return 0;
}
@ -735,9 +756,7 @@ int rpc_tsg_write(rdpRpc* rpc, uint8* data, int length, uint16 opnum)
status = rpc_in_write(rpc, pdu->data, pdu->p - pdu->data);
xfree(request_pdu->auth_verifier.auth_value);
xfree(request_pdu->auth_verifier.auth_pad);
xfree(request_pdu);
stream_free(pdu) ;
if (status < 0)
{
@ -760,11 +779,18 @@ int rpc_read(rdpRpc* rpc, uint8* data, int length)
int rpc_length = length + 0xFF;
uint8* rpc_data = xmalloc(rpc_length);
if (rpc_data == NULL)
{
printf("rpc_read error: memory allocation failed\n") ;
return -1 ;
}
if (rpc->read_buffer_len > 0)
{
if (rpc->read_buffer_len > (uint32) length)
{
printf("rpc_read error: receiving buffer is not large enough\n");
xfree(rpc_data) ;
return -1;
}
@ -826,7 +852,6 @@ int rpc_read(rdpRpc* rpc, uint8* data, int length)
}
xfree(rpc_data);
return read;
}
@ -847,7 +872,7 @@ boolean rpc_connect(rdpRpc* rpc)
return false;
}
if (!rpc_recv_bind_ack_pdu(rpc))
if (rpc_recv_bind_ack_pdu(rpc) <= 0)
{
printf("rpc_recv_bind_ack_pdu error!\n");
return false;

View File

@ -78,6 +78,7 @@ boolean rts_connect(rdpRpc* rpc)
{
printf("rts_connect error!\n");
http_response_print(http_response);
http_response_free(http_response) ;
return false;
}
@ -563,9 +564,6 @@ int rts_recv_pdu_commands(rdpRpc* rpc, RTS_PDU* rts_pdu)
STREAM* s;
uint32 CommandType;
s = stream_new(0);
stream_attach(s, rts_pdu->content, rts_pdu->header.frag_length);
DEBUG_RTS("numberOfCommands:%d", rts_pdu->header.numberOfCommands);
if (rts_pdu->header.flags & RTS_FLAG_PING)
@ -574,6 +572,9 @@ int rts_recv_pdu_commands(rdpRpc* rpc, RTS_PDU* rts_pdu)
return 0;
}
s = stream_new(0);
stream_attach(s, rts_pdu->content, rts_pdu->header.frag_length);
for (i = 0; i < rts_pdu->header.numberOfCommands; i++)
{
stream_read_uint32(s, CommandType); /* CommandType (4 bytes) */
@ -644,6 +645,8 @@ int rts_recv_pdu_commands(rdpRpc* rpc, RTS_PDU* rts_pdu)
default:
printf("Error: Unknown RTS Command Type: 0x%x\n", CommandType);
stream_detach(s) ;
stream_free(s) ;
return -1;
break;
}

View File

@ -171,8 +171,11 @@ rdpSettings* settings_new(void* instance)
settings->fastpath_input = true;
settings->fastpath_output = true;
settings->frame_acknowledge = 2;
settings->uniconv = freerdp_uniconv_new();
gethostname(settings->client_hostname, sizeof(settings->client_hostname) - 1);
gethostname(settings->client_hostname, 31);
settings->client_hostname[31] = 0;
settings->mouse_motion = true;
settings->client_auto_reconnect_cookie = xnew(ARC_CS_PRIVATE_PACKET);

View File

@ -46,6 +46,15 @@ static int update_recv_surfcmd_surface_bits(rdpUpdate* update, STREAM* s)
return 20 + cmd->bitmapDataLength;
}
static void update_send_frame_acknowledge(rdpRdp* rdp, uint32 frameId)
{
STREAM* s;
s = rdp_data_pdu_init(rdp);
stream_write_uint32(s, frameId);
rdp_send_data_pdu(rdp, s, DATA_PDU_TYPE_FRAME_ACKNOWLEDGE, rdp->mcs->user_id);
}
static int update_recv_surfcmd_frame_marker(rdpUpdate* update, STREAM* s)
{
SURFACE_FRAME_MARKER* marker = &update->surface_frame_marker;
@ -55,6 +64,11 @@ static int update_recv_surfcmd_frame_marker(rdpUpdate* update, STREAM* s)
IFCALL(update->SurfaceFrameMarker, update->context, marker);
if (update->context->rdp->settings->received_caps[CAPSET_TYPE_FRAME_ACKNOWLEDGE] && update->context->rdp->settings->frame_acknowledge > 0 && marker->frameAction == SURFACECMD_FRAMEACTION_END)
{
update_send_frame_acknowledge(update->context->rdp, marker->frameId);
}
return 6;
}

View File

@ -33,12 +33,6 @@ enum SURFCMD_CMDTYPE
CMDTYPE_STREAM_SURFACE_BITS = 0x0006
};
enum SURFCMD_FRAMEACTION
{
SURFACECMD_FRAMEACTION_BEGIN = 0x0000,
SURFACECMD_FRAMEACTION_END = 0x0001
};
boolean update_recv_surfcmds(rdpUpdate* update, uint32 size, STREAM* s);
void update_write_surfcmd_surface_bits_header(STREAM* s, SURFACE_BITS_COMMAND* cmd);

View File

@ -25,6 +25,7 @@
#include <freerdp/utils/stream.h>
#include <freerdp/utils/memory.h>
#include <freerdp/utils/hexdump.h>
#include <freerdp/errorcodes.h>
#include <time.h>
#include <errno.h>
@ -88,6 +89,9 @@ boolean transport_connect_tls(rdpTransport* transport)
transport->tls->sockfd = transport->tcp->sockfd;
if (tls_connect(transport->tls) != true) {
if(!connectErrorCode){
connectErrorCode = TLSCONNECTERROR;
}
tls_free(transport->tls);
transport->tls = NULL;
return false;
@ -108,6 +112,9 @@ boolean transport_connect_nla(rdpTransport* transport)
transport->tls->sockfd = transport->tcp->sockfd;
if (tls_connect(transport->tls) != true) {
if(!connectErrorCode){
connectErrorCode = TLSCONNECTERROR;
}
tls_free(transport->tls);
transport->tls = NULL;
return false;
@ -126,6 +133,9 @@ boolean transport_connect_nla(rdpTransport* transport)
if (credssp_authenticate(transport->credssp) < 0)
{
if(!connectErrorCode){
connectErrorCode = AUTHENTICATIONERROR;
}
printf("Authentication failure, check credentials.\n"
"If credentials are valid, the NTLMSSP implementation may be to blame.\n");

View File

@ -1613,9 +1613,9 @@ DWORD TsProxySendToServer(handle_t IDL_handle, byte pRpcMessage[], uint32 count,
int status;
int length;
rdpTsg* tsg;
byte* buffer1;
byte* buffer2;
byte* buffer3;
byte* buffer1 = NULL ;
byte* buffer2 = NULL ;
byte* buffer3 = NULL ;
uint32 buffer1Length;
uint32 buffer2Length;
uint32 buffer3Length;
@ -1730,11 +1730,17 @@ boolean tsg_connect(rdpTsg* tsg, const char* hostname, uint16 port)
length = 0x8FFF;
data = xmalloc(length);
if (data == NULL)
{
printf("rpc_recv - memory allocation error\n") ;
return false ;
}
status = rpc_read(rpc, data, length);
if (status <= 0)
{
printf("rpc_recv failed!\n");
xfree(data) ;
return false;
}
@ -1765,6 +1771,7 @@ boolean tsg_connect(rdpTsg* tsg, const char* hostname, uint16 port)
if (status <= 0)
{
printf("rpc_write opnum=2 failed!\n");
xfree(data) ;
return false;
}
@ -1773,6 +1780,7 @@ boolean tsg_connect(rdpTsg* tsg, const char* hostname, uint16 port)
if (status <= 0)
{
printf("rpc_recv failed!\n");
xfree(data) ;
return false;
}
@ -1795,6 +1803,7 @@ boolean tsg_connect(rdpTsg* tsg, const char* hostname, uint16 port)
if (status <= 0)
{
printf("rpc_write opnum=3 failed!\n");
xfree(data) ;
return false;
}
status = -1;
@ -1814,6 +1823,8 @@ boolean tsg_connect(rdpTsg* tsg, const char* hostname, uint16 port)
stream_write(s_p4, dest_addr_unic, dest_addr_unic_len);
stream_write_uint16(s_p4, 0x0000); /* unicode zero to terminate hostname string */
xfree(dest_addr_unic);
/**
* OpNum = 4
*
@ -1831,15 +1842,18 @@ boolean tsg_connect(rdpTsg* tsg, const char* hostname, uint16 port)
if (status <= 0)
{
printf("rpc_write opnum=4 failed!\n");
stream_free(s_p4) ;
xfree(data) ;
return false;
}
xfree(dest_addr_unic);
status = rpc_read(rpc, data, length);
if (status < 0)
{
printf("rpc_recv failed!\n");
stream_free(s_p4) ;
xfree(data) ;
return false;
}
@ -1867,9 +1881,13 @@ boolean tsg_connect(rdpTsg* tsg, const char* hostname, uint16 port)
if (status <= 0)
{
printf("rpc_write opnum=8 failed!\n");
stream_free(s_p4) ;
xfree(data) ;
return false;
}
stream_free(s_p4) ;
xfree(data) ;
return true;
}
#else

View File

@ -398,8 +398,8 @@ char** crypto_cert_subject_alt_name(X509* xcert, int* count, int** lengths)
return NULL;
num_subject_alt_names = sk_GENERAL_NAME_num(subject_alt_names);
strings = (char**) malloc(sizeof(char*) * num_subject_alt_names);
*lengths = (int*) malloc(sizeof(int*) * num_subject_alt_names);
strings = (char**) xmalloc(sizeof(char*) * num_subject_alt_names);
*lengths = (int*) xmalloc(sizeof(int*) * num_subject_alt_names);
for (index = 0; index < num_subject_alt_names; ++index)
{
@ -415,7 +415,12 @@ char** crypto_cert_subject_alt_name(X509* xcert, int* count, int** lengths)
}
if (*count < 1)
{
xfree(strings) ;
xfree(*lengths) ;
*lengths = NULL ;
return NULL;
}
return strings;
}

View File

@ -52,6 +52,7 @@ boolean der_write_general_string(STREAM* s, char* str)
stream_copy(s, tmp_s, strlen(str));
stream_detach(tmp_s);
stream_free(tmp_s) ;
return true;
}
@ -121,6 +122,7 @@ int der_write_generalized_time(STREAM* s, char* tstr)
stream_copy(s, tmp_s, len);
stream_detach(tmp_s);
stream_free(tmp_s) ;
return len + 2;
}

View File

@ -112,6 +112,7 @@ boolean tls_connect(rdpTls* tls)
if (!crypto_cert_get_public_key(cert, &tls->public_key))
{
printf("tls_connect: crypto_cert_get_public_key failed to return the server public key.\n");
tls_free_certificate(cert) ;
return false;
}
@ -177,9 +178,12 @@ boolean tls_accept(rdpTls* tls, const char* cert_file, const char* privatekey_fi
if (!crypto_cert_get_public_key(cert, &tls->public_key))
{
printf("tls_connect: crypto_cert_get_public_key failed to return the server public key.\n");
tls_free_certificate(cert);
return false;
}
tls_free_certificate(cert);
if (SSL_set_fd(tls->ssl, tls->sockfd) < 1)
{
printf("SSL_set_fd failed\n");
@ -459,6 +463,7 @@ boolean tls_verify_certificate(rdpTls* tls, CryptoCert cert, char* hostname)
xfree(alt_names[index]);
xfree(alt_names);
xfree(alt_names_lengths) ;
}
#endif

View File

@ -24,6 +24,7 @@
#include <freerdp/freerdp.h>
#include <freerdp/gdi/gdi.h>
#include <freerdp/codec/color.h>
#include <freerdp/utils/memory.h>
#include <freerdp/gdi/32bpp.h>
#include <freerdp/gdi/16bpp.h>
@ -130,7 +131,7 @@ INLINE void gdi_SetPixel_32bpp(HGDI_BITMAP hBmp, int X, int Y, uint32 pixel)
HGDI_BITMAP gdi_CreateBitmap(int nWidth, int nHeight, int cBitsPerPixel, uint8* data)
{
HGDI_BITMAP hBitmap = (HGDI_BITMAP) malloc(sizeof(GDI_BITMAP));
HGDI_BITMAP hBitmap = (HGDI_BITMAP) xmalloc(sizeof(GDI_BITMAP));
hBitmap->objectType = GDIOBJECT_BITMAP;
hBitmap->bitsPerPixel = cBitsPerPixel;
hBitmap->bytesPerPixel = (cBitsPerPixel + 1) / 8;
@ -152,13 +153,13 @@ HGDI_BITMAP gdi_CreateBitmap(int nWidth, int nHeight, int cBitsPerPixel, uint8*
HGDI_BITMAP gdi_CreateCompatibleBitmap(HGDI_DC hdc, int nWidth, int nHeight)
{
HGDI_BITMAP hBitmap = (HGDI_BITMAP) malloc(sizeof(GDI_BITMAP));
HGDI_BITMAP hBitmap = (HGDI_BITMAP) xmalloc(sizeof(GDI_BITMAP));
hBitmap->objectType = GDIOBJECT_BITMAP;
hBitmap->bytesPerPixel = hdc->bytesPerPixel;
hBitmap->bitsPerPixel = hdc->bitsPerPixel;
hBitmap->width = nWidth;
hBitmap->height = nHeight;
hBitmap->data = malloc(nWidth * nHeight * hBitmap->bytesPerPixel);
hBitmap->data = xmalloc(nWidth * nHeight * hBitmap->bytesPerPixel);
hBitmap->scanline = nWidth * hBitmap->bytesPerPixel;
return hBitmap;
}

View File

@ -25,6 +25,7 @@
#include <freerdp/freerdp.h>
#include <freerdp/gdi/gdi.h>
#include <freerdp/utils/memory.h>
#include <freerdp/gdi/32bpp.h>
#include <freerdp/gdi/16bpp.h>
@ -50,7 +51,7 @@ p_PatBlt PatBlt_[5] =
HGDI_BRUSH gdi_CreateSolidBrush(GDI_COLOR crColor)
{
HGDI_BRUSH hBrush = (HGDI_BRUSH) malloc(sizeof(GDI_BRUSH));
HGDI_BRUSH hBrush = (HGDI_BRUSH) xmalloc(sizeof(GDI_BRUSH));
hBrush->objectType = GDIOBJECT_BRUSH;
hBrush->style = GDI_BS_SOLID;
hBrush->color = crColor;
@ -66,7 +67,7 @@ HGDI_BRUSH gdi_CreateSolidBrush(GDI_COLOR crColor)
HGDI_BRUSH gdi_CreatePatternBrush(HGDI_BITMAP hbmp)
{
HGDI_BRUSH hBrush = (HGDI_BRUSH) malloc(sizeof(GDI_BRUSH));
HGDI_BRUSH hBrush = (HGDI_BRUSH) xmalloc(sizeof(GDI_BRUSH));
hBrush->objectType = GDIOBJECT_BRUSH;
hBrush->style = GDI_BS_PATTERN;
hBrush->pattern = hbmp;

View File

@ -25,6 +25,7 @@
#include <freerdp/freerdp.h>
#include <freerdp/gdi/gdi.h>
#include <freerdp/codec/color.h>
#include <freerdp/utils/memory.h>
#include <freerdp/gdi/region.h>
@ -38,7 +39,7 @@
HGDI_DC gdi_GetDC()
{
HGDI_DC hDC = (HGDI_DC) malloc(sizeof(GDI_DC));
HGDI_DC hDC = (HGDI_DC) xmalloc(sizeof(GDI_DC));
hDC->bytesPerPixel = 4;
hDC->bitsPerPixel = 32;
hDC->drawMode = GDI_R2_BLACK;
@ -56,7 +57,7 @@ HGDI_DC gdi_GetDC()
HGDI_DC gdi_CreateDC(HCLRCONV clrconv, int bpp)
{
HGDI_DC hDC = (HGDI_DC) malloc(sizeof(GDI_DC));
HGDI_DC hDC = (HGDI_DC) xmalloc(sizeof(GDI_DC));
hDC->drawMode = GDI_R2_BLACK;
hDC->clip = gdi_CreateRectRgn(0, 0, 0, 0);
@ -70,12 +71,12 @@ HGDI_DC gdi_CreateDC(HCLRCONV clrconv, int bpp)
hDC->invert = clrconv->invert;
hDC->rgb555 = clrconv->rgb555;
hDC->hwnd = (HGDI_WND) malloc(sizeof(GDI_WND));
hDC->hwnd = (HGDI_WND) xmalloc(sizeof(GDI_WND));
hDC->hwnd->invalid = gdi_CreateRectRgn(0, 0, 0, 0);
hDC->hwnd->invalid->null = 1;
hDC->hwnd->count = 32;
hDC->hwnd->cinvalid = (HGDI_RGN) malloc(sizeof(GDI_RGN) * hDC->hwnd->count);
hDC->hwnd->cinvalid = (HGDI_RGN) xmalloc(sizeof(GDI_RGN) * hDC->hwnd->count);
hDC->hwnd->ninvalid = 0;
return hDC;
@ -90,7 +91,7 @@ HGDI_DC gdi_CreateDC(HCLRCONV clrconv, int bpp)
HGDI_DC gdi_CreateCompatibleDC(HGDI_DC hdc)
{
HGDI_DC hDC = (HGDI_DC) malloc(sizeof(GDI_DC));
HGDI_DC hDC = (HGDI_DC) xmalloc(sizeof(GDI_DC));
hDC->bytesPerPixel = hdc->bytesPerPixel;
hDC->bitsPerPixel = hdc->bitsPerPixel;
hDC->drawMode = hdc->drawMode;

View File

@ -371,7 +371,7 @@ gdiBitmap* gdi_glyph_new(rdpGdi* gdi, GLYPH_DATA* glyph)
uint8* extra;
gdiBitmap* gdi_bmp;
gdi_bmp = (gdiBitmap*) malloc(sizeof(gdiBitmap));
gdi_bmp = (gdiBitmap*) xmalloc(sizeof(gdiBitmap));
gdi_bmp->hdc = gdi_GetDC();
gdi_bmp->hdc->bytesPerPixel = 1;
@ -403,7 +403,7 @@ gdiBitmap* gdi_bitmap_new_ex(rdpGdi* gdi, int width, int height, int bpp, uint8*
{
gdiBitmap* bitmap;
bitmap = (gdiBitmap*) malloc(sizeof(gdiBitmap));
bitmap = (gdiBitmap*) xmalloc(sizeof(gdiBitmap));
bitmap->hdc = gdi_CreateCompatibleDC(gdi->hdc);
DEBUG_GDI("gdi_bitmap_new: width:%d height:%d bpp:%d", width, height, bpp);
@ -838,12 +838,12 @@ void gdi_init_primary(rdpGdi* gdi)
if (gdi->drawing == NULL)
gdi->drawing = gdi->primary;
gdi->primary->hdc->hwnd = (HGDI_WND) malloc(sizeof(GDI_WND));
gdi->primary->hdc->hwnd = (HGDI_WND) xmalloc(sizeof(GDI_WND));
gdi->primary->hdc->hwnd->invalid = gdi_CreateRectRgn(0, 0, 0, 0);
gdi->primary->hdc->hwnd->invalid->null = 1;
gdi->primary->hdc->hwnd->count = 32;
gdi->primary->hdc->hwnd->cinvalid = (HGDI_RGN) malloc(sizeof(GDI_RGN) * gdi->primary->hdc->hwnd->count);
gdi->primary->hdc->hwnd->cinvalid = (HGDI_RGN) xmalloc(sizeof(GDI_RGN) * gdi->primary->hdc->hwnd->count);
gdi->primary->hdc->hwnd->ninvalid = 0;
}
@ -875,8 +875,7 @@ int gdi_init(freerdp* instance, uint32 flags, uint8* buffer)
rdpGdi* gdi;
rdpCache* cache;
gdi = (rdpGdi*) malloc(sizeof(rdpGdi));
memset(gdi, 0, sizeof(rdpGdi));
gdi = (rdpGdi*) xzalloc(sizeof(rdpGdi));
instance->context->gdi = gdi;
cache = instance->context->cache;
@ -926,11 +925,11 @@ int gdi_init(freerdp* instance, uint32 flags, uint8* buffer)
gdi->hdc->bitsPerPixel = gdi->dstBpp;
gdi->hdc->bytesPerPixel = gdi->bytesPerPixel;
gdi->clrconv = (HCLRCONV) malloc(sizeof(CLRCONV));
gdi->clrconv = (HCLRCONV) xmalloc(sizeof(CLRCONV));
gdi->clrconv->alpha = (flags & CLRCONV_ALPHA) ? 1 : 0;
gdi->clrconv->invert = (flags & CLRCONV_INVERT) ? 1 : 0;
gdi->clrconv->rgb555 = (flags & CLRCONV_RGB555) ? 1 : 0;
gdi->clrconv->palette = (rdpPalette*) malloc(sizeof(rdpPalette));
gdi->clrconv->palette = (rdpPalette*) xmalloc(sizeof(rdpPalette));
gdi->hdc->alpha = gdi->clrconv->alpha;
gdi->hdc->invert = gdi->clrconv->invert;

View File

@ -25,6 +25,7 @@
#include <freerdp/freerdp.h>
#include <freerdp/gdi/gdi.h>
#include <freerdp/utils/memory.h>
#include <freerdp/gdi/palette.h>
@ -66,9 +67,9 @@ static const GDI_PALETTEENTRY default_system_palette[20] =
HGDI_PALETTE gdi_CreatePalette(HGDI_PALETTE palette)
{
HGDI_PALETTE hPalette = (HGDI_PALETTE) malloc(sizeof(GDI_PALETTE));
HGDI_PALETTE hPalette = (HGDI_PALETTE) xmalloc(sizeof(GDI_PALETTE));
hPalette->count = palette->count;
hPalette->entries = (GDI_PALETTEENTRY*) malloc(sizeof(GDI_PALETTEENTRY) * hPalette->count);
hPalette->entries = (GDI_PALETTEENTRY*) xmalloc(sizeof(GDI_PALETTEENTRY) * hPalette->count);
memcpy(hPalette->entries, palette->entries, sizeof(GDI_PALETTEENTRY) * hPalette->count);
return hPalette;
}
@ -80,10 +81,10 @@ HGDI_PALETTE gdi_CreatePalette(HGDI_PALETTE palette)
HGDI_PALETTE CreateSystemPalette()
{
HGDI_PALETTE palette = (HGDI_PALETTE) malloc(sizeof(GDI_PALETTE));
HGDI_PALETTE palette = (HGDI_PALETTE) xmalloc(sizeof(GDI_PALETTE));
palette->count = 256;
palette->entries = (GDI_PALETTEENTRY*) malloc(sizeof(GDI_PALETTEENTRY) * 256);
palette->entries = (GDI_PALETTEENTRY*) xmalloc(sizeof(GDI_PALETTEENTRY) * 256);
memset(palette->entries, 0, sizeof(GDI_PALETTEENTRY) * 256);
memcpy(&palette->entries[0], &default_system_palette[0], 10 * sizeof(GDI_PALETTEENTRY));

View File

@ -26,6 +26,7 @@
#include <freerdp/api.h>
#include <freerdp/freerdp.h>
#include <freerdp/gdi/gdi.h>
#include <freerdp/utils/memory.h>
#include <freerdp/gdi/pen.h>
@ -40,7 +41,7 @@
HGDI_PEN gdi_CreatePen(int fnPenStyle, int nWidth, int crColor)
{
HGDI_PEN hPen = (HGDI_PEN) malloc(sizeof(GDI_PEN));
HGDI_PEN hPen = (HGDI_PEN) xmalloc(sizeof(GDI_PEN));
hPen->objectType = GDIOBJECT_PEN;
hPen->style = fnPenStyle;
hPen->color = crColor;

View File

@ -24,6 +24,7 @@
#include <freerdp/api.h>
#include <freerdp/freerdp.h>
#include <freerdp/gdi/gdi.h>
#include <freerdp/utils/memory.h>
#include <freerdp/gdi/region.h>
@ -39,7 +40,7 @@
HGDI_RGN gdi_CreateRectRgn(int nLeftRect, int nTopRect, int nRightRect, int nBottomRect)
{
HGDI_RGN hRgn = (HGDI_RGN) malloc(sizeof(GDI_RGN));
HGDI_RGN hRgn = (HGDI_RGN) xmalloc(sizeof(GDI_RGN));
hRgn->objectType = GDIOBJECT_REGION;
hRgn->x = nLeftRect;
hRgn->y = nTopRect;
@ -60,7 +61,7 @@ HGDI_RGN gdi_CreateRectRgn(int nLeftRect, int nTopRect, int nRightRect, int nBot
HGDI_RECT gdi_CreateRect(int xLeft, int yTop, int xRight, int yBottom)
{
HGDI_RECT hRect = (HGDI_RECT) malloc(sizeof(GDI_RECT));
HGDI_RECT hRect = (HGDI_RECT) xmalloc(sizeof(GDI_RECT));
hRect->objectType = GDIOBJECT_RECT;
hRect->left = xLeft;
hRect->top = yTop;

View File

@ -1503,7 +1503,10 @@ char* freerdp_get_unix_timezone_identifier()
fseek(fp, 0, SEEK_SET);
if (length < 2)
{
fclose(fp) ;
return NULL;
}
tzid = (char*) xmalloc(length + 1);
fread(tzid, length, 1, fp);
@ -1511,6 +1514,8 @@ char* freerdp_get_unix_timezone_identifier()
if (tzid[length - 1] == '\n')
tzid[length - 1] = '\0';
fclose(fp) ;
}
return tzid;
@ -1605,9 +1610,9 @@ void freerdp_time_zone_detect(TIME_ZONE_INFO* clientTimeZone)
#ifdef HAVE_TM_GMTOFF
if (local_time->tm_gmtoff >= 0)
clientTimeZone->bias = (uint32) (local_time->tm_gmtoff / 60);
clientTimeZone->bias = (uint32) (-1 * local_time->tm_gmtoff / 60);
else
clientTimeZone->bias = (uint32) ((-1 * local_time->tm_gmtoff) / 60 + 720);
clientTimeZone->bias = (uint32) ((-1 * local_time->tm_gmtoff) / 60);
#elif sun
if (local_time->tm_isdst > 0)
clientTimeZone->bias = (uint32) (altzone / 3600);

View File

@ -55,6 +55,8 @@ static void rail_WindowIcon(rdpContext* context, WINDOW_ORDER_INFO* orderInfo, W
}
window = window_list_get_by_id(rail->list, orderInfo->windowId);
if (!window)
return ;
icon = (rdpIcon*) xzalloc(sizeof(rdpIcon));
icon->entry = window_icon->iconInfo;

View File

@ -89,6 +89,7 @@ int freerdp_parse_args(rdpSettings* settings, int argc, char** argv,
" --plugin: load a virtual channel plugin\n"
" --rfx: enable RemoteFX\n"
" --rfx-mode: RemoteFX operational flags (v[ideo], i[mage]), default is video\n"
" --frame-ack: number of frames pending to be acknowledged, default is 2 (disable with 0)\n"
" --nsc: enable NSCodec (experimental)\n"
" --disable-wallpaper: disables wallpaper\n"
" --composition: enable desktop composition\n"
@ -265,8 +266,8 @@ int freerdp_parse_args(rdpSettings* settings, int argc, char** argv,
printf("missing client hostname\n");
return FREERDP_ARGS_PARSE_FAILURE;
}
strncpy(settings->client_hostname, argv[index], sizeof(settings->client_hostname) - 1);
settings->client_hostname[sizeof(settings->client_hostname) - 1] = 0;
strncpy(settings->client_hostname, argv[index], 31);
settings->client_hostname[31] = 0;
}
else if (strcmp("-o", argv[index]) == 0)
{
@ -352,7 +353,6 @@ int freerdp_parse_args(rdpSettings* settings, int argc, char** argv,
settings->rfx_codec = true;
settings->fastpath_output = true;
settings->color_depth = 32;
settings->frame_acknowledge = false;
settings->performance_flags = PERF_FLAG_NONE;
settings->large_pointer = true;
}
@ -378,6 +378,16 @@ int freerdp_parse_args(rdpSettings* settings, int argc, char** argv,
return FREERDP_ARGS_PARSE_FAILURE;
}
}
else if (strcmp("--frame-ack", argv[index]) == 0)
{
index++;
if (index == argc)
{
printf("missing frame acknowledge number\n");
return FREERDP_ARGS_PARSE_FAILURE;
}
settings->frame_acknowledge = atoi(argv[index]);
}
else if (strcmp("--nsc", argv[index]) == 0)
{
settings->ns_codec = true;

View File

@ -24,9 +24,10 @@
#include <freerdp/utils/memory.h>
#include <freerdp/utils/dsp.h>
uint8* dsp_resample(uint8* src, int bytes_per_sample,
static void freerdp_dsp_resample(FREERDP_DSP_CONTEXT* context,
const uint8* src, int bytes_per_sample,
uint32 schan, uint32 srate, int sframes,
uint32 rchan, uint32 rrate, int * prframes)
uint32 rchan, uint32 rrate)
{
uint8* dst;
uint8* p;
@ -39,9 +40,13 @@ uint8* dsp_resample(uint8* src, int bytes_per_sample,
sbytes = bytes_per_sample * schan;
rbytes = bytes_per_sample * rchan;
rframes = sframes * rrate / srate;
*prframes = rframes;
rsize = rbytes * rframes;
dst = (uint8*) xzalloc(rsize);
if (rsize > context->resampled_maxlength)
{
context->resampled_maxlength = rsize + 1024;
context->resampled_buffer = xrealloc(context->resampled_buffer, context->resampled_maxlength);
}
dst = context->resampled_buffer;
p = dst;
for (i = 0; i < rframes; i++)
@ -59,7 +64,8 @@ uint8* dsp_resample(uint8* src, int bytes_per_sample,
}
}
return dst;
context->resampled_frames = rframes;
context->resampled_size = rsize;
}
/**
@ -122,35 +128,39 @@ static uint16 dsp_decode_ima_adpcm_sample(ADPCM* adpcm,
return (uint16) d;
}
uint8* dsp_decode_ima_adpcm(ADPCM* adpcm,
uint8* src, int size, int channels, int block_size, int* out_size)
static void freerdp_dsp_decode_ima_adpcm(FREERDP_DSP_CONTEXT* context,
const uint8* src, int size, int channels, int block_size)
{
uint8* out;
uint8* dst;
uint8 sample;
uint16 decoded;
uint32 out_size;
int channel;
int i;
*out_size = size * 4;
out = (uint8 *) xzalloc(*out_size);
dst = out;
out_size = size * 4;
if (out_size > context->adpcm_maxlength)
{
context->adpcm_maxlength = out_size + 1024;
context->adpcm_buffer = xrealloc(context->adpcm_buffer, context->adpcm_maxlength);
}
dst = context->adpcm_buffer;
while (size > 0)
{
if (size % block_size == 0)
{
adpcm->last_sample[0] = (sint16) (((uint16)(*src)) | (((uint16)(*(src + 1))) << 8));
adpcm->last_step[0] = (sint16) (*(src + 2));
context->adpcm.last_sample[0] = (sint16) (((uint16)(*src)) | (((uint16)(*(src + 1))) << 8));
context->adpcm.last_step[0] = (sint16) (*(src + 2));
src += 4;
size -= 4;
*out_size -= 16;
out_size -= 16;
if (channels > 1)
{
adpcm->last_sample[1] = (sint16) (((uint16)(*src)) | (((uint16)(*(src + 1))) << 8));
adpcm->last_step[1] = (sint16) (*(src + 2));
context->adpcm.last_sample[1] = (sint16) (((uint16)(*src)) | (((uint16)(*(src + 1))) << 8));
context->adpcm.last_step[1] = (sint16) (*(src + 2));
src += 4;
size -= 4;
*out_size -= 16;
out_size -= 16;
}
}
@ -160,11 +170,11 @@ uint8* dsp_decode_ima_adpcm(ADPCM* adpcm,
{
channel = (i < 4 ? 0 : 1);
sample = ((*src) & 0x0f);
decoded = dsp_decode_ima_adpcm_sample(adpcm, channel, sample);
decoded = dsp_decode_ima_adpcm_sample(&context->adpcm, channel, sample);
dst[((i & 3) << 3) + (channel << 1)] = (decoded & 0xff);
dst[((i & 3) << 3) + (channel << 1) + 1] = (decoded >> 8);
sample = ((*src) >> 4);
decoded = dsp_decode_ima_adpcm_sample(adpcm, channel, sample);
decoded = dsp_decode_ima_adpcm_sample(&context->adpcm, channel, sample);
dst[((i & 3) << 3) + (channel << 1) + 4] = (decoded & 0xff);
dst[((i & 3) << 3) + (channel << 1) + 5] = (decoded >> 8);
src++;
@ -175,18 +185,19 @@ uint8* dsp_decode_ima_adpcm(ADPCM* adpcm,
else
{
sample = ((*src) & 0x0f);
decoded = dsp_decode_ima_adpcm_sample(adpcm, 0, sample);
decoded = dsp_decode_ima_adpcm_sample(&context->adpcm, 0, sample);
*dst++ = (decoded & 0xff);
*dst++ = (decoded >> 8);
sample = ((*src) >> 4);
decoded = dsp_decode_ima_adpcm_sample(adpcm, 0, sample);
decoded = dsp_decode_ima_adpcm_sample(&context->adpcm, 0, sample);
*dst++ = (decoded & 0xff);
*dst++ = (decoded >> 8);
src++;
size--;
}
}
return out;
context->adpcm_size = out_size;
}
/**
@ -277,30 +288,35 @@ static uint8 dsp_encode_ima_adpcm_sample(ADPCM* adpcm,
return enc;
}
uint8* dsp_encode_ima_adpcm(ADPCM* adpcm,
uint8* src, int size, int channels, int block_size, int* out_size)
static void freerdp_dsp_encode_ima_adpcm(FREERDP_DSP_CONTEXT* context,
const uint8* src, int size, int channels, int block_size)
{
uint8* out;
uint8* dst;
sint16 sample;
uint8 encoded;
uint32 out_size;
int i;
out = (uint8*) xzalloc(size / 2);
dst = out;
out_size = size / 2;
if (out_size > context->adpcm_maxlength)
{
context->adpcm_maxlength = out_size + 1024;
context->adpcm_buffer = xrealloc(context->adpcm_buffer, context->adpcm_maxlength);
}
dst = context->adpcm_buffer;
while (size > 0)
{
if ((dst - out) % block_size == 0)
if ((dst - context->adpcm_buffer) % block_size == 0)
{
*dst++ = adpcm->last_sample[0] & 0xff;
*dst++ = (adpcm->last_sample[0] >> 8) & 0xff;
*dst++ = (uint8) adpcm->last_step[0];
*dst++ = context->adpcm.last_sample[0] & 0xff;
*dst++ = (context->adpcm.last_sample[0] >> 8) & 0xff;
*dst++ = (uint8) context->adpcm.last_step[0];
*dst++ = 0;
if (channels > 1)
{
*dst++ = adpcm->last_sample[1] & 0xff;
*dst++ = (adpcm->last_sample[1] >> 8) & 0xff;
*dst++ = (uint8) adpcm->last_step[1];
*dst++ = context->adpcm.last_sample[1] & 0xff;
*dst++ = (context->adpcm.last_sample[1] >> 8) & 0xff;
*dst++ = (uint8) context->adpcm.last_step[1];
*dst++ = 0;
}
}
@ -312,7 +328,7 @@ uint8* dsp_encode_ima_adpcm(ADPCM* adpcm,
{
sample = (sint16) (((uint16)(*src)) | (((uint16)(*(src + 1))) << 8));
src += 2;
encoded = dsp_encode_ima_adpcm_sample(adpcm, i % 2, sample);
encoded = dsp_encode_ima_adpcm_sample(&context->adpcm, i % 2, sample);
dst[ima_stereo_encode_map[i].byte_num] |= encoded << ima_stereo_encode_map[i].byte_shift;
}
dst += 8;
@ -322,15 +338,39 @@ uint8* dsp_encode_ima_adpcm(ADPCM* adpcm,
{
sample = (sint16) (((uint16)(*src)) | (((uint16)(*(src + 1))) << 8));
src += 2;
encoded = dsp_encode_ima_adpcm_sample(adpcm, 0, sample);
encoded = dsp_encode_ima_adpcm_sample(&context->adpcm, 0, sample);
sample = (sint16) (((uint16)(*src)) | (((uint16)(*(src + 1))) << 8));
src += 2;
encoded |= dsp_encode_ima_adpcm_sample(adpcm, 0, sample) << 4;
encoded |= dsp_encode_ima_adpcm_sample(&context->adpcm, 0, sample) << 4;
*dst++ = encoded;
size -= 4;
}
}
*out_size = dst - out;
return out;
context->adpcm_size = dst - context->adpcm_buffer;
}
FREERDP_DSP_CONTEXT* freerdp_dsp_context_new(void)
{
FREERDP_DSP_CONTEXT* context;
context = xnew(FREERDP_DSP_CONTEXT);
context->resample = freerdp_dsp_resample;
context->decode_ima_adpcm = freerdp_dsp_decode_ima_adpcm;
context->encode_ima_adpcm = freerdp_dsp_encode_ima_adpcm;
return context;
}
void freerdp_dsp_context_free(FREERDP_DSP_CONTEXT* context)
{
if (context)
{
if (context->resampled_buffer)
xfree(context->resampled_buffer);
if (context->adpcm_buffer)
xfree(context->adpcm_buffer);
xfree(context);
}
}

View File

@ -23,15 +23,33 @@
#include <freerdp/utils/memory.h>
#include <freerdp/utils/list.h>
/**
* Allocates a new LIST_ITEM element. This will be used to store the data provided by the caller,
* and will be used as a new element in a list.
*
* @param data - pointer to the data that must be stored by the new item.
*
* @return An allocated LIST_ITEM element that contains the 'data' pointer.
*/
static LIST_ITEM* list_item_new(void* data)
{
LIST_ITEM* item;
item = xnew(LIST_ITEM);
item->data = data;
if (item)
item->data = data;
return item;
}
/**
* Searches an element in the list.
* The element is verified by its pointer value - there is no way to verify the buffer's content.
*
* @param list - pointer to a valid LIST structure
* @param data - pointer to the data that must be found.
*
* @return the LIST_ITEM element that contains the 'data' pointer. NULL if 'data' was not found.
*/
static LIST_ITEM* list_item_find(LIST* list, void* data)
{
LIST_ITEM* item;
@ -44,6 +62,18 @@ static LIST_ITEM* list_item_find(LIST* list, void* data)
return NULL;
}
/**
* Allocates a new LIST structure.
* The list_*() API implements a chainlist and allows to store data of arbitrary type in FIFO mode.
* @see list_enqueue() to add elements to the list.
* @see list_dequeue() to remove the first element of the list and get a pointer to it.
* @see list_peek() to retrieve the first element of the list (and keep it there).
* @see list_free() to deallocate the list.
* @see list_size() to get the current number of elements in the list.
*
* @return A pointer to the allocated LIST structure. It must be deallocated by a call to list_free().
*
*/
LIST* list_new(void)
{
LIST* list;
@ -53,6 +83,12 @@ LIST* list_new(void)
return list;
}
/**
* Deallocates a LIST structure.
* All elements of the list will be removed (but not deallocated). Only the list-specific resources are freed.
*
* @param list - pointer to the LIST that must be deallocated.
*/
void list_free(LIST* list)
{
while (list->head)
@ -60,6 +96,12 @@ void list_free(LIST* list)
xfree(list);
}
/**
* Add an element at the end of an existing list.
*
* @param list - pointer to the LIST that will contain the new element
* @param data - pointer to the buffer that will be added to the list
*/
void list_enqueue(LIST* list, void* data)
{
LIST_ITEM* item;
@ -79,6 +121,14 @@ void list_enqueue(LIST* list, void* data)
list->count++;
}
/**
* Removes the first element of a list, and returns a pointer to it.
* The list-specific resources associated to this element are freed in the process.
*
* @param list - pointer to a valid LIST structure
*
* @return a pointer to the data of the first element of this list. NULL if the list is empty.
*/
void* list_dequeue(LIST* list)
{
LIST_ITEM* item;
@ -100,6 +150,14 @@ void* list_dequeue(LIST* list)
return data;
}
/**
* Returns a pointer to the data from the first element of the list.
* The element itself is not removed from the list by this call.
*
* @param list - pointerto a valid LIST structure
*
* @return a pointer to the data of the first element of this list. NULL if the list is empty.
*/
void* list_peek(LIST* list)
{
LIST_ITEM* item;
@ -108,6 +166,18 @@ void* list_peek(LIST* list)
return item ? item->data : NULL;
}
/**
* Searches for the data provided in parameter, and returns a pointer to the element next to it.
* If the item is not found, or if it is the last in the list, the function will return NULL.
*
* @param list - pointer to the list that must be searched.
* @param data - pointer to the buffer that must be found. The comparison is done on the pointer value - not the buffer's content.
*
* @return a pointer to the data of the element that resides after the 'data' parameter in the list.
* NULL if 'data' was not found in the list, or if it is the last element.
*
* @see list_item_find() for more information on list item searches.
*/
void* list_next(LIST* list, void* data)
{
LIST_ITEM* item;
@ -122,6 +192,15 @@ void* list_next(LIST* list, void* data)
return data;
}
/**
* Searches for the data provided in parameter, and removes it from the list if it is found.
*
* @param list - pointer to the list that must be searched.
* @param data - pointer to the buffer that must be found. The comparison is done on the pointer value - not the buffer's content.
*
* @return the 'data' pointer, if the element was found, and successfully removed from the list.
* NULL if the element was not found.
*/
void* list_remove(LIST* list, void* data)
{
LIST_ITEM* item;
@ -145,6 +224,14 @@ void* list_remove(LIST* list, void* data)
return data;
}
/**
* Returns the current size of the list (number of elements).
* This number is kept up to date by the list_enqueue and list_dequeue functions.
*
* @param list - pointer to a valide LIST structure.
*
* @return the number of elements in that list.
*/
int list_size(LIST* list)
{
return list->count;

View File

@ -1,4 +1,4 @@
/**
/*
* FreeRDP: A Remote Desktop Protocol Client
* Stream Utils
*
@ -24,6 +24,23 @@
#include <freerdp/utils/memory.h>
#include <freerdp/utils/stream.h>
/**
* Allocates and initializes a STREAM structure.
* STREAM are used to ease data access in read and write operations.
* They consist of a buffer containing the data we want to access, and an offset associated to it, and keeping
* track of the 'current' position in the stream. A list of functions can then be used to read/write different
* type of data to/from it.
* @see stream.h for the list of data access functions.
*
* @param size [in] - size of the buffer that will ba allocated to the stream.
* If 0, there will be no buffer attached to the stream. The caller
* then needs to call stream_attach() to link an existing buffer to this stream.
* Caution: calling stream_attach() on a stream with an existing buffer will result
* in this buffer being lost, and possible memory leak.
*
* @return A pointer to an allocated and initialized STREAM structure.
* This pointer need to be deallocated using the stream_free() function.
*/
STREAM* stream_new(int size)
{
STREAM* stream;
@ -44,6 +61,15 @@ STREAM* stream_new(int size)
return stream;
}
/**
* This function is used to deallocate a stream that was allocated using stream_new().
* Caution: the buffer linked to the stream will be deallocated in the process. If this buffer was attached
* using the stream_attach() function, the stream_detach() function needs to be called before calling stream_free()
* otherwise it will be freed in the process.
*
* @param stream [in] - Pointer to the STREAM structure that needs to be deallocated.
* This pointer is invalid on return.
*/
void stream_free(STREAM* stream)
{
if (stream != NULL)
@ -55,6 +81,16 @@ void stream_free(STREAM* stream)
}
}
/**
* This function is used to extend the size of an existing stream.
* It will infact extend the attached buffer, fill the newly allocated region with 0, and reset the current
* stream position.
* If the stream did not have a buffer attached, a new one will be allocated and attached.
*
* @param stream [in/out] pointer to the STREAM structure that needs to be extended.
* @param request_size [in] Number of bytes to add to the existing stream.
* If the value is < the existing size, then the existing size is doubled.
*/
void stream_extend(STREAM* stream, int request_size)
{
int pos;

View File

@ -144,6 +144,15 @@ static void svc_plugin_process_received(rdpSvcPlugin* plugin, void* pData, uint3
{
STREAM* data_in;
svc_data_in_item* item;
if ( (dataFlags & CHANNEL_FLAG_SUSPEND) || (dataFlags & CHANNEL_FLAG_RESUME))
{
/* According to MS-RDPBCGR 2.2.6.1, "All virtual channel traffic MUST be suspended.
This flag is only valid in server-to-client virtual channel traffic. It MUST be
ignored in client-to-server data." Thus it would be best practice to cease data
transmission. However, simply returing here avoids a crash. */
return;
}
if (dataFlags & CHANNEL_FLAG_FIRST)
{

View File

@ -19,6 +19,7 @@
#include <freerdp/utils/tcp.h>
#include <freerdp/utils/print.h>
#include <freerdp/errorcodes.h>
#include <stdio.h>
#include <stdlib.h>
@ -55,6 +56,9 @@
#endif
/* connectErrorCode is 'extern' in errorcodes.h. See comment there.*/
int connectErrorCode ;
int freerdp_tcp_connect(const char* hostname, int port)
{
int status;
@ -73,6 +77,14 @@ int freerdp_tcp_connect(const char* hostname, int port)
if (status != 0)
{
if(status==EAI_NONAME){
if(!connectErrorCode){
connectErrorCode = DNSNAMENOTFOUND;
}
}
if(!connectErrorCode){
connectErrorCode = DNSERROR;
}
printf("tcp_connect: getaddrinfo (%s)\n", gai_strerror(status));
return -1;
}
@ -90,7 +102,14 @@ int freerdp_tcp_connect(const char* hostname, int port)
printf("connected to %s:%s\n", hostname, servname);
break;
}
if(!connectErrorCode){
int tmperror = errno ;
if(tmperror!=0){
connectErrorCode = tmperror ;
}else{
connectErrorCode = CONNECTERROR;
}
}
close(sockfd);
sockfd = -1;
}

View File

@ -254,7 +254,7 @@ PFORMAT_STRING NdrpEmbeddedPointerBufferSize(PMIDL_STUB_MESSAGE pStubMsg, unsign
char PointerLengthSet;
PFORMAT_STRING pFormatCopy;
unsigned long BufferLength;
unsigned long BufferLengthCopy;
unsigned long BufferLengthCopy = 0;
unsigned long PointerLength;
unsigned char* pMemoryPtr = NULL;

View File

@ -720,6 +720,7 @@ int krb_asrep_recv(KRB_CONTEXT* krb_ctx)
if(krb_decode_kdc_rep(s, &(krb_asrep->kdc_rep), totlen) == 0)
{
krb_ctx->state = KRB_PACKET_ERROR;
xfree(krb_asrep);
goto finish;
}
kdc_rep = &(krb_asrep->kdc_rep);
@ -784,6 +785,8 @@ void krb_tgsreq_send(KRB_CONTEXT* krb_ctx, uint8 errcode)
/* PA-TGS-REQ */
krb_apreq = krb_apreq_new(krb_ctx, &(krb_ctx->asticket), krb_auth);
curlen = krb_encode_apreq(sapreq, krb_apreq);
xfree(krb_apreq) ;
msg.data = sapreq->p;
msg.length = curlen;
(*pa_data)->type = 1;
@ -852,6 +855,7 @@ int krb_tgsrep_recv(KRB_CONTEXT* krb_ctx)
if(krb_decode_kdc_rep(s, &(krb_tgsrep->kdc_rep), totlen) == 0)
{
krb_ctx->state = KRB_PACKET_ERROR;
xfree(krb_tgsrep);
goto finish;
}
kdc_rep = &(krb_tgsrep->kdc_rep);
@ -887,7 +891,6 @@ int krb_verify_kdcrep(KRB_CONTEXT* krb_ctx, KrbKDCREP* kdc_rep, int msgtype)
return -1;
}
/* decrypt enc-part */
decmsg = xnew(rdpBlob);
if(krb_ctx->askey->enctype != kdc_rep->enc_part.enctype && msgtype == KRB_TAG_ASREP)
{
freerdp_blob_free(&(krb_ctx->askey->skey));

View File

@ -107,7 +107,12 @@ rdpBlob* crypto_kdcmsg_decrypt_rc4(rdpBlob* msg, uint8* key, uint32 msgtype)
crypto_rc4_free(rc4);
HMAC(EVP_md5(), (void*) K1, 16, (uint8*)edata->Confounder, len - 16, (void*)&(edata->Checksum), NULL);
if(memcmp(msg->data, &edata->Checksum, 16))
{
xfree(edata) ;
xfree(K1) ;
xfree(K3) ;
return NULL;
}
decmsg = xnew(rdpBlob);
freerdp_blob_alloc(decmsg, len);
memcpy(decmsg->data, edata, len);

View File

@ -782,10 +782,13 @@ ENCKDCREPPart* krb_decode_enc_reppart(rdpBlob* msg, uint8 apptag)
goto err;
stream_detach(s);
stream_free(s) ;
return reppart;
err:
krb_free_reppart(reppart);
xfree(reppart);
stream_detach(s) ;
stream_free(s) ;
return NULL;
}

View File

@ -261,8 +261,9 @@ SECURITY_STATUS SEC_ENTRY ntlm_QueryCredentialsAttributesA(PCredHandle phCredent
return SEC_E_UNSUPPORTED_FUNCTION;
}
/* http://msdn.microsoft.com/en-us/library/windows/desktop/aa375512/ */
/**
* @see http://msdn.microsoft.com/en-us/library/windows/desktop/aa374707
*/
SECURITY_STATUS SEC_ENTRY ntlm_AcceptSecurityContext(PCredHandle phCredential, PCtxtHandle phContext,
PSecBufferDesc pInput, uint32 fContextReq, uint32 TargetDataRep, PCtxtHandle phNewContext,
PSecBufferDesc pOutput, uint32* pfContextAttr, PTimeStamp ptsTimeStamp)
@ -278,6 +279,8 @@ SECURITY_STATUS SEC_ENTRY ntlm_AcceptSecurityContext(PCredHandle phCredential, P
if (!context)
{
context = ntlm_ContextNew();
if (!context)
return SEC_E_INSUFFICIENT_MEMORY ;
context->server = true;
credentials = (CREDENTIALS*) sspi_SecureHandleGetLowerPointer(phCredential);
@ -293,9 +296,6 @@ SECURITY_STATUS SEC_ENTRY ntlm_AcceptSecurityContext(PCredHandle phCredential, P
{
context->state = NTLM_STATE_NEGOTIATE;
if (!context)
return SEC_E_INVALID_HANDLE;
if (!pInput)
return SEC_E_INVALID_TOKEN;
@ -335,9 +335,6 @@ SECURITY_STATUS SEC_ENTRY ntlm_AcceptSecurityContext(PCredHandle phCredential, P
}
else if (context->state == NTLM_STATE_AUTHENTICATE)
{
if (!context)
return SEC_E_INVALID_HANDLE;
if (!pInput)
return SEC_E_INVALID_TOKEN;
@ -373,6 +370,9 @@ SECURITY_STATUS SEC_ENTRY ntlm_InitializeSecurityContextW(PCredHandle phCredenti
return SEC_E_OK;
}
/**
* @see http://msdn.microsoft.com/en-us/library/windows/desktop/aa375512%28v=vs.85%29.aspx
*/
SECURITY_STATUS SEC_ENTRY ntlm_InitializeSecurityContextA(PCredHandle phCredential, PCtxtHandle phContext,
SEC_CHAR* pszTargetName, uint32 fContextReq, uint32 Reserved1, uint32 TargetDataRep,
PSecBufferDesc pInput, uint32 Reserved2, PCtxtHandle phNewContext,
@ -389,6 +389,8 @@ SECURITY_STATUS SEC_ENTRY ntlm_InitializeSecurityContextA(PCredHandle phCredenti
if (!context)
{
context = ntlm_ContextNew();
if (!context)
return SEC_E_INSUFFICIENT_MEMORY ;
if (fContextReq & ISC_REQ_CONFIDENTIALITY)
context->confidentiality = true;
@ -416,7 +418,7 @@ SECURITY_STATUS SEC_ENTRY ntlm_InitializeSecurityContextA(PCredHandle phCredenti
return SEC_E_INVALID_TOKEN;
if (output_buffer->cbBuffer < 1)
return SEC_E_INSUFFICIENT_MEMORY;
return SEC_E_INVALID_TOKEN;
if (context->state == NTLM_STATE_INITIAL)
context->state = NTLM_STATE_NEGOTIATE;
@ -428,12 +430,6 @@ SECURITY_STATUS SEC_ENTRY ntlm_InitializeSecurityContextA(PCredHandle phCredenti
}
else
{
if (!context)
return SEC_E_INVALID_HANDLE;
if (!pInput)
return SEC_E_INVALID_TOKEN;
if (pInput->cBuffers < 1)
return SEC_E_INVALID_TOKEN;

View File

@ -168,11 +168,17 @@ SECURITY_STATUS ntlm_read_NegotiateMessage(NTLM_CONTEXT* context, PSecBuffer buf
if (memcmp(Signature, NTLM_SIGNATURE, 8) != 0)
{
printf("Unexpected NTLM signature: %s, expected:%s\n", Signature, NTLM_SIGNATURE);
stream_detach(s) ;
stream_free(s) ;
return SEC_E_INVALID_TOKEN;
}
if (MessageType != MESSAGE_TYPE_NEGOTIATE)
{
stream_detach(s) ;
stream_free(s) ;
return SEC_E_INVALID_TOKEN;
}
stream_read_uint32(s, NegotiateFlags); /* NegotiateFlags (4 bytes) */
@ -339,11 +345,17 @@ SECURITY_STATUS ntlm_read_ChallengeMessage(NTLM_CONTEXT* context, PSecBuffer buf
if (memcmp(Signature, NTLM_SIGNATURE, 8) != 0)
{
printf("Unexpected NTLM signature: %s, expected:%s\n", Signature, NTLM_SIGNATURE);
stream_detach(s) ;
stream_free(s) ;
return SEC_E_INVALID_TOKEN;
}
if (MessageType != MESSAGE_TYPE_CHALLENGE)
{
stream_detach(s) ;
stream_free(s) ;
return SEC_E_INVALID_TOKEN;
}
StartOffset = s->p - 12;
@ -676,11 +688,17 @@ SECURITY_STATUS ntlm_read_AuthenticateMessage(NTLM_CONTEXT* context, PSecBuffer
if (memcmp(Signature, NTLM_SIGNATURE, 8) != 0)
{
printf("Unexpected NTLM signature: %s, expected:%s\n", Signature, NTLM_SIGNATURE);
stream_detach(s) ;
stream_free(s) ;
return SEC_E_INVALID_TOKEN;
}
if (MessageType != MESSAGE_TYPE_AUTHENTICATE)
{
stream_detach(s) ;
stream_free(s) ;
return SEC_E_INVALID_TOKEN;
}
/* LmChallengeResponseFields (8 bytes) */
stream_read_uint16(s, LmChallengeResponseLen); /* LmChallengeResponseLen */

View File

@ -916,7 +916,10 @@ int credssp_recv(rdpCredssp* credssp)
status = tls_read(credssp->tls, s->data, stream_get_left(s));
if (status < 0)
{
stream_free(s) ;
return -1;
}
/* TSRequest */
ber_read_sequence_tag(s, &length);

View File

@ -60,6 +60,7 @@ struct test_peer_context
WTSVirtualChannelManager* vcm;
void* debug_channel;
freerdp_thread* debug_channel_thread;
uint32 frame_id;
};
typedef struct test_peer_context testPeerContext;
@ -120,6 +121,30 @@ static STREAM* test_peer_stream_init(testPeerContext* context)
return context->s;
}
static void test_peer_begin_frame(freerdp_peer* client)
{
rdpUpdate* update = client->update;
SURFACE_FRAME_MARKER* fm = &update->surface_frame_marker;
testPeerContext* context = (testPeerContext*) client->context;
fm->frameAction = SURFACECMD_FRAMEACTION_BEGIN;
fm->frameId = context->frame_id;
update->SurfaceFrameMarker(update->context, fm);
}
static void test_peer_end_frame(freerdp_peer* client)
{
rdpUpdate* update = client->update;
SURFACE_FRAME_MARKER* fm = &update->surface_frame_marker;
testPeerContext* context = (testPeerContext*) client->context;
fm->frameAction = SURFACECMD_FRAMEACTION_END;
fm->frameId = context->frame_id;
update->SurfaceFrameMarker(update->context, fm);
context->frame_id++;
}
static void test_peer_draw_background(freerdp_peer* client)
{
testPeerContext* context = (testPeerContext*) client->context;
@ -133,6 +158,8 @@ static void test_peer_draw_background(freerdp_peer* client)
if (!client->settings->rfx_codec && !client->settings->ns_codec)
return;
test_peer_begin_frame(client);
s = test_peer_stream_init(context);
rect.x = 0;
@ -169,6 +196,8 @@ static void test_peer_draw_background(freerdp_peer* client)
update->SurfaceBits(update->context, cmd);
xfree(rgb_data);
test_peer_end_frame(client);
}
static void test_peer_load_icon(freerdp_peer* client)
@ -229,6 +258,8 @@ static void test_peer_draw_icon(freerdp_peer* client, int x, int y)
if (context->icon_width < 1 || !context->activated)
return;
test_peer_begin_frame(client);
rect.x = 0;
rect.y = 0;
rect.width = context->icon_width;
@ -289,6 +320,8 @@ static void test_peer_draw_icon(freerdp_peer* client, int x, int y)
context->icon_x = x;
context->icon_y = y;
test_peer_end_frame(client);
}
static boolean test_sleep_tsdiff(uint32 *old_sec, uint32 *old_usec, uint32 new_sec, uint32 new_usec)