2011-09-04 00:36:27 +04:00
|
|
|
/**
|
2012-10-09 07:02:04 +04:00
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
2011-09-04 00:36:27 +04:00
|
|
|
* String Utils
|
|
|
|
*
|
|
|
|
* Copyright 2011 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2012-08-15 01:09:01 +04:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2012-10-09 07:21:26 +04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2012-12-17 08:34:07 +04:00
|
|
|
#include <winpr/crt.h>
|
2011-09-04 00:36:27 +04:00
|
|
|
|
|
|
|
#include <freerdp/utils/string.h>
|
|
|
|
|
2013-01-11 04:21:24 +04:00
|
|
|
BOOL freerdp_string_read_length32(STREAM* s, rdpString* string)
|
2011-09-04 00:36:27 +04:00
|
|
|
{
|
2013-01-11 04:21:24 +04:00
|
|
|
if(stream_get_left(s) < 4)
|
|
|
|
return FALSE;
|
2012-10-09 11:26:39 +04:00
|
|
|
stream_read_UINT32(s, string->length);
|
2013-01-11 04:21:24 +04:00
|
|
|
if(stream_get_left(s) < string->length)
|
|
|
|
return FALSE;
|
2012-10-09 07:21:26 +04:00
|
|
|
string->unicode = (char*) malloc(string->length);
|
2011-09-04 00:36:27 +04:00
|
|
|
stream_read(s, string->unicode, string->length);
|
2012-12-17 08:34:07 +04:00
|
|
|
|
|
|
|
ConvertFromUnicode(CP_UTF8, 0, (WCHAR*) string->unicode, string->length / 2, &string->ascii, 0, NULL, NULL);
|
2013-01-11 04:21:24 +04:00
|
|
|
return TRUE;
|
2011-09-04 00:36:27 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void freerdp_string_free(rdpString* string)
|
|
|
|
{
|
|
|
|
if (string->unicode != NULL)
|
2012-10-09 07:21:26 +04:00
|
|
|
free(string->unicode);
|
2011-09-04 00:36:27 +04:00
|
|
|
|
|
|
|
if (string->ascii != NULL)
|
2012-10-09 07:21:26 +04:00
|
|
|
free(string->ascii);
|
2011-09-04 00:36:27 +04:00
|
|
|
}
|