2011-07-02 19:38:50 +04:00
|
|
|
/**
|
|
|
|
* FreeRDP: A Remote Desktop Protocol Client
|
|
|
|
* Stream Utils
|
|
|
|
*
|
|
|
|
* Copyright 2011 Vic Lee
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <freerdp/utils/memory.h>
|
|
|
|
#include <freerdp/utils/stream.h>
|
|
|
|
|
2011-07-10 13:27:21 +04:00
|
|
|
STREAM* stream_new(int size)
|
2011-07-02 19:38:50 +04:00
|
|
|
{
|
2011-07-10 13:27:21 +04:00
|
|
|
STREAM* stream;
|
2011-07-02 19:38:50 +04:00
|
|
|
|
2011-07-13 18:23:55 +04:00
|
|
|
stream = xnew(STREAM);
|
2011-07-07 19:27:24 +04:00
|
|
|
|
2011-07-02 19:38:50 +04:00
|
|
|
if (stream != NULL)
|
|
|
|
{
|
2011-07-07 19:27:24 +04:00
|
|
|
if (size != 0)
|
|
|
|
{
|
|
|
|
size = size > 0 ? size : 0x400;
|
2011-09-02 18:15:54 +04:00
|
|
|
stream->data = (uint8*)xzalloc(size);
|
2011-07-07 19:27:24 +04:00
|
|
|
stream->p = stream->data;
|
|
|
|
stream->size = size;
|
|
|
|
}
|
2011-07-02 19:38:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return stream;
|
|
|
|
}
|
|
|
|
|
2011-07-10 13:27:21 +04:00
|
|
|
void stream_free(STREAM* stream)
|
2011-07-02 19:38:50 +04:00
|
|
|
{
|
|
|
|
if (stream != NULL)
|
|
|
|
{
|
2011-07-06 07:18:00 +04:00
|
|
|
xfree(stream->data);
|
2011-07-02 19:38:50 +04:00
|
|
|
xfree(stream);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-12 13:12:57 +04:00
|
|
|
void stream_extend(STREAM* stream, int request_size)
|
2011-07-02 19:38:50 +04:00
|
|
|
{
|
2011-09-07 13:09:40 +04:00
|
|
|
int original_size;
|
2011-09-02 18:15:54 +04:00
|
|
|
int increased_size;
|
2011-07-02 19:38:50 +04:00
|
|
|
int pos;
|
|
|
|
|
|
|
|
pos = stream_get_pos(stream);
|
2011-09-07 13:09:40 +04:00
|
|
|
original_size = stream->size;
|
|
|
|
increased_size = (request_size > original_size ? request_size : original_size);
|
2011-09-02 18:15:54 +04:00
|
|
|
stream->size += increased_size;
|
2011-07-13 18:23:55 +04:00
|
|
|
stream->data = (uint8*)xrealloc(stream->data, stream->size);
|
2011-09-07 13:09:40 +04:00
|
|
|
memset(stream->data + original_size, 0, increased_size);
|
2011-07-02 19:38:50 +04:00
|
|
|
stream_set_pos(stream, pos);
|
|
|
|
}
|