void rail_string_to_unicode_string(rdpRailOrder* rail_order, char* string, RAIL_UNICODE_STRING* unicode_string)
{
- char* buffer;
- size_t length = 0;
+ WCHAR* buffer;
+ int length = 0;
if (unicode_string->string != NULL)
xfree(unicode_string->string);
if (string == NULL || strlen(string) < 1)
return;
- buffer = freerdp_uniconv_out(string, &length);
+ length = freerdp_AsciiToUnicodeAlloc(string, &buffer, 0) * 2;
unicode_string->string = (uint8*) buffer;
unicode_string->length = (uint16) length;
boolean disk_file_query_directory(DISK_FILE* file, uint32 FsInformationClass, uint8 InitialQuery,
const char* path, STREAM* output)
{
- struct dirent* ent;
- char* ent_path;
- struct STAT st;
- size_t len;
+ int length;
boolean ret;
+ WCHAR* ent_path;
+ struct STAT st;
+ struct dirent* ent;
DEBUG_SVC("path %s FsInformationClass %d InitialQuery %d", path, FsInformationClass, InitialQuery);
}
memset(&st, 0, sizeof(struct STAT));
- ent_path = xmalloc(strlen(file->fullpath) + strlen(ent->d_name) + 2);
- sprintf(ent_path, "%s/%s", file->fullpath, ent->d_name);
+ ent_path = (WCHAR*) malloc(strlen(file->fullpath) + strlen(ent->d_name) + 2);
+ sprintf((char*) ent_path, "%s/%s", file->fullpath, ent->d_name);
- if (STAT(ent_path, &st) != 0)
+ if (STAT((char*) ent_path, &st) != 0)
{
- DEBUG_WARN("stat %s failed. errno = %d", ent_path, errno);
+ DEBUG_WARN("stat %s failed. errno = %d", (char*) ent_path, errno);
}
DEBUG_SVC(" pattern %s matched %s", file->pattern, ent_path);
xfree(ent_path);
- ent_path = freerdp_uniconv_out(ent->d_name, &len);
+ length = freerdp_AsciiToUnicodeAlloc(ent->d_name, &ent_path, 0) * 2;
ret = true;
+
switch (FsInformationClass)
{
case FileDirectoryInformation:
/* http://msdn.microsoft.com/en-us/library/cc232097.aspx */
- stream_write_uint32(output, 64 + len); /* Length */
- stream_check_size(output, 64 + len);
+ stream_write_uint32(output, 64 + length); /* Length */
+ stream_check_size(output, 64 + length);
stream_write_uint32(output, 0); /* NextEntryOffset */
stream_write_uint32(output, 0); /* FileIndex */
stream_write_uint64(output, FILE_TIME_SYSTEM_TO_RDP(st.st_mtime)); /* CreationTime */
stream_write_uint64(output, st.st_size); /* EndOfFile */
stream_write_uint64(output, st.st_size); /* AllocationSize */
stream_write_uint32(output, FILE_ATTR_SYSTEM_TO_RDP(file, st)); /* FileAttributes */
- stream_write_uint32(output, len); /* FileNameLength */
- stream_write(output, ent_path, len);
+ stream_write_uint32(output, length); /* FileNameLength */
+ stream_write(output, ent_path, length);
break;
case FileFullDirectoryInformation:
/* http://msdn.microsoft.com/en-us/library/cc232068.aspx */
- stream_write_uint32(output, 68 + len); /* Length */
- stream_check_size(output, 68 + len);
+ stream_write_uint32(output, 68 + length); /* Length */
+ stream_check_size(output, 68 + length);
stream_write_uint32(output, 0); /* NextEntryOffset */
stream_write_uint32(output, 0); /* FileIndex */
stream_write_uint64(output, FILE_TIME_SYSTEM_TO_RDP(st.st_mtime)); /* CreationTime */
stream_write_uint64(output, st.st_size); /* EndOfFile */
stream_write_uint64(output, st.st_size); /* AllocationSize */
stream_write_uint32(output, FILE_ATTR_SYSTEM_TO_RDP(file, st)); /* FileAttributes */
- stream_write_uint32(output, len); /* FileNameLength */
+ stream_write_uint32(output, length); /* FileNameLength */
stream_write_uint32(output, 0); /* EaSize */
- stream_write(output, ent_path, len);
+ stream_write(output, ent_path, length);
break;
case FileBothDirectoryInformation:
/* http://msdn.microsoft.com/en-us/library/cc232095.aspx */
- stream_write_uint32(output, 93 + len); /* Length */
- stream_check_size(output, 93 + len);
+ stream_write_uint32(output, 93 + length); /* Length */
+ stream_check_size(output, 93 + length);
stream_write_uint32(output, 0); /* NextEntryOffset */
stream_write_uint32(output, 0); /* FileIndex */
stream_write_uint64(output, FILE_TIME_SYSTEM_TO_RDP(st.st_mtime)); /* CreationTime */
stream_write_uint64(output, st.st_size); /* EndOfFile */
stream_write_uint64(output, st.st_size); /* AllocationSize */
stream_write_uint32(output, FILE_ATTR_SYSTEM_TO_RDP(file, st)); /* FileAttributes */
- stream_write_uint32(output, len); /* FileNameLength */
+ stream_write_uint32(output, length); /* FileNameLength */
stream_write_uint32(output, 0); /* EaSize */
stream_write_uint8(output, 0); /* ShortNameLength */
/* Reserved(1), MUST NOT be added! */
stream_write_zero(output, 24); /* ShortName */
- stream_write(output, ent_path, len);
+ stream_write(output, ent_path, length);
break;
case FileNamesInformation:
/* http://msdn.microsoft.com/en-us/library/cc232077.aspx */
- stream_write_uint32(output, 12 + len); /* Length */
- stream_check_size(output, 12 + len);
+ stream_write_uint32(output, 12 + length); /* Length */
+ stream_check_size(output, 12 + length);
stream_write_uint32(output, 0); /* NextEntryOffset */
stream_write_uint32(output, 0); /* FileIndex */
- stream_write_uint32(output, len); /* FileNameLength */
- stream_write(output, ent_path, len);
+ stream_write_uint32(output, length); /* FileNameLength */
+ stream_write(output, ent_path, length);
break;
default:
STREAM* output = irp->output;
struct STATVFS svfst;
struct STAT st;
- char* volumeLabel = {"FREERDP"}; /* TODO: Add sub routine to correctly pick up Volume Label name for each O/S supported */
+ char* volumeLabel = {"FREERDP"};
char* diskType = {"FAT32"};
- char* outStr;
- size_t len;
+ WCHAR* outStr;
+ int length;
stream_read_uint32(irp->input, FsInformationClass);
{
case FileFsVolumeInformation:
/* http://msdn.microsoft.com/en-us/library/cc232108.aspx */
- outStr = freerdp_uniconv_out(volumeLabel, &len);
- stream_write_uint32(output, 17 + len); /* Length */
- stream_check_size(output, 17 + len);
+ length = freerdp_AsciiToUnicodeAlloc(volumeLabel, &outStr, 0) * 2;
+ stream_write_uint32(output, 17 + length); /* Length */
+ stream_check_size(output, 17 + length);
stream_write_uint64(output, FILE_TIME_SYSTEM_TO_RDP(st.st_ctime)); /* VolumeCreationTime */
stream_write_uint32(output, svfst.f_fsid); /* VolumeSerialNumber */
- stream_write_uint32(output, len); /* VolumeLabelLength */
+ stream_write_uint32(output, length); /* VolumeLabelLength */
stream_write_uint8(output, 0); /* SupportsObjects */
/* Reserved(1), MUST NOT be added! */
- stream_write(output, outStr, len); /* VolumeLabel (Unicode) */
+ stream_write(output, outStr, length); /* VolumeLabel (Unicode) */
xfree(outStr);
break;
case FileFsAttributeInformation:
/* http://msdn.microsoft.com/en-us/library/cc232101.aspx */
- outStr = freerdp_uniconv_out(diskType, &len);
-
- stream_write_uint32(output, 12 + len); /* Length */
- stream_check_size(output, 12 + len);
+ length = freerdp_AsciiToUnicodeAlloc(diskType, &outStr, 0) * 2;
+ stream_write_uint32(output, 12 + length); /* Length */
+ stream_check_size(output, 12 + length);
stream_write_uint32(output,
FILE_CASE_SENSITIVE_SEARCH |
FILE_CASE_PRESERVED_NAMES |
FILE_UNICODE_ON_DISK); /* FileSystemAttributes */
stream_write_uint32(output, svfst.f_namemax/*510*/); /* MaximumComponentNameLength */
- stream_write_uint32(output, len); /* FileSystemNameLength */
- stream_write(output, outStr, len); /* FileSystemName (Unicode) */
+ stream_write_uint32(output, length); /* FileSystemNameLength */
+ stream_write(output, outStr, length); /* FileSystemName (Unicode) */
xfree(outStr);
break;
{
char* name;
char* path;
- int i, len;
+ int i, length;
DISK_DEVICE* disk;
name = (char*) pEntryPoints->plugin_data->data[1];
disk->device.IRPRequest = disk_irp_request;
disk->device.Free = disk_free;
- len = strlen(name);
- disk->device.data = stream_new(len + 1);
+ length = strlen(name);
+ disk->device.data = stream_new(length + 1);
- for (i = 0; i <= len; i++)
+ for (i = 0; i <= length; i++)
stream_write_uint8(disk->device.data, name[i] < 0 ? '_' : name[i]);
disk->path = path;
{
char* port;
uint32 Flags;
- size_t DriverNameLen;
- char* DriverName;
- size_t PrintNameLen;
- char* PrintName;
+ int DriverNameLen;
+ WCHAR* DriverName;
+ int PrintNameLen;
+ WCHAR* PrintName;
uint32 CachedFieldsLen;
uint8* CachedPrinterConfigData;
PRINTER_DEVICE* printer_dev;
DEBUG_SVC("Printer %s registered", printer->name);
Flags = 0;
+
if (printer->is_default)
Flags |= RDPDR_PRINTER_ANNOUNCE_FLAG_DEFAULTPRINTER;
- DriverName = freerdp_uniconv_out(printer->driver, &DriverNameLen);
- PrintName = freerdp_uniconv_out(printer->name, &PrintNameLen);
+ DriverNameLen = freerdp_AsciiToUnicodeAlloc(printer->driver, &DriverName, 0) * 2;
+ PrintNameLen = freerdp_AsciiToUnicodeAlloc(printer->name, &PrintName, 0) * 2;
printer_dev->device.data = stream_new(28 + DriverNameLen + PrintNameLen + CachedFieldsLen);
stream_write_uint16(printer_dev->device.data, 0);
stream_write(printer_dev->device.data, PrintName, PrintNameLen);
stream_write_uint16(printer_dev->device.data, 0);
+
if (CachedFieldsLen > 0)
{
stream_write(printer_dev->device.data, CachedPrinterConfigData, CachedFieldsLen);
static void rdpdr_send_client_name_request(rdpdrPlugin* rdpdr)
{
- char* s;
STREAM* data_out;
+ WCHAR* computerNameW;
size_t computerNameLenW;
if (!rdpdr->computerName[0])
gethostname(rdpdr->computerName, sizeof(rdpdr->computerName) - 1);
- s = freerdp_uniconv_out(rdpdr->computerName, &computerNameLenW);
+ computerNameLenW = freerdp_AsciiToUnicodeAlloc(rdpdr->computerName, &computerNameW, 0) * 2;
+
data_out = stream_new(16 + computerNameLenW + 2);
stream_write_uint16(data_out, RDPDR_CTYP_CORE);
stream_write_uint32(data_out, 1); /* unicodeFlag, 0 for ASCII and 1 for Unicode */
stream_write_uint32(data_out, 0); /* codePage, must be set to zero */
stream_write_uint32(data_out, computerNameLenW + 2); /* computerNameLen, including null terminator */
- stream_write(data_out, s, computerNameLenW);
+ stream_write(data_out, computerNameW, computerNameLenW);
stream_write_uint16(data_out, 0); /* null terminator */
- xfree(s);
+ xfree(computerNameW);
svc_plugin_send((rdpSvcPlugin*) rdpdr, data_out);
}
static uint8* xf_cliprdr_process_requested_unicodetext(uint8* data, int* size)
{
- uint8* inbuf;
- uint8* outbuf;
- size_t out_size;
-
- inbuf = lf2crlf(data, size);
-
- outbuf = (uint8*) freerdp_uniconv_out((char*) inbuf, &out_size);
+ char* inbuf;
+ WCHAR* outbuf;
+ int out_size;
+ inbuf = (char*) lf2crlf(data, size);
+ out_size = freerdp_AsciiToUnicodeAlloc(inbuf, &outbuf, 0);
xfree(inbuf);
- *size = (int) out_size + 2;
+ *size = (int) ((out_size + 1) * 2);
- return outbuf;
+ return (uint8*) outbuf;
}
static uint8* xf_cliprdr_process_requested_text(uint8* data, int* size)
#include <freerdp/api.h>
FREERDP_API char* freerdp_uniconv_in(unsigned char* pin, size_t in_len);
-FREERDP_API char* freerdp_uniconv_out(const char *str, size_t *pout_len);
#include <freerdp/types.h>
}
/*
- * If we are in server mode, accepth client's color depth only if
+ * If we are in server mode, accept client's color depth only if
* it is smaller than ours. This is what Windows server does.
*/
if (color_depth < settings->color_depth || !settings->server_mode)
void gcc_write_client_core_data(STREAM* s, rdpSettings* settings)
{
uint32 version;
- char* clientName;
- size_t clientNameLength;
+ WCHAR* clientName;
+ int clientNameLength;
uint8 connectionType;
uint16 highColorDepth;
uint16 supportedColorDepths;
uint16 earlyCapabilityFlags;
- char* clientDigProductId;
- size_t clientDigProductIdLength;
+ WCHAR* clientDigProductId;
+ int clientDigProductIdLength;
gcc_write_user_data_header(s, CS_CORE, 216);
version = settings->rdp_version >= 5 ? RDP_VERSION_5_PLUS : RDP_VERSION_4;
- clientName = freerdp_uniconv_out(settings->client_hostname, &clientNameLength);
- clientDigProductId = freerdp_uniconv_out(settings->client_product_id, &clientDigProductIdLength);
+
+ clientNameLength = freerdp_AsciiToUnicodeAlloc(settings->client_hostname, &clientName, 0);
+ clientDigProductIdLength = freerdp_AsciiToUnicodeAlloc(settings->client_product_id, &clientDigProductId, 0);
stream_write_uint32(s, version); /* version */
stream_write_uint16(s, settings->width); /* desktopWidth */
stream_write_uint32(s, settings->client_build); /* clientBuild */
/* clientName (32 bytes, null-terminated unicode, truncated to 15 characters) */
- if (clientNameLength > 30)
+
+ if (clientNameLength > 15)
{
- clientNameLength = 30;
+ clientNameLength = 15;
clientName[clientNameLength] = 0;
- clientName[clientNameLength + 1] = 0;
}
- stream_write(s, clientName, clientNameLength + 2);
- stream_write_zero(s, 32 - clientNameLength - 2);
+
+ stream_write(s, clientName, ((clientNameLength + 1) * 2));
+ stream_write_zero(s, 32 - ((clientNameLength + 1) * 2));
xfree(clientName);
stream_write_uint32(s, settings->kbd_type); /* keyboardType */
void rdp_write_extended_info_packet(STREAM* s, rdpSettings* settings)
{
- size_t length;
- uint16 clientAddressFamily;
- uint8* clientAddress;
- uint16 cbClientAddress;
- uint8* clientDir;
- uint16 cbClientDir;
- uint16 cbAutoReconnectLen;
+ int clientAddressFamily;
+ WCHAR* clientAddress;
+ int cbClientAddress;
+ WCHAR* clientDir;
+ int cbClientDir;
+ int cbAutoReconnectLen;
clientAddressFamily = settings->ipv6 ? ADDRESS_FAMILY_INET6 : ADDRESS_FAMILY_INET;
- clientAddress = (uint8*) freerdp_uniconv_out(settings->ip_address, &length);
- cbClientAddress = length;
+ cbClientAddress = freerdp_AsciiToUnicodeAlloc(settings->ip_address, &clientAddress, 0) * 2;
- clientDir = (uint8*) freerdp_uniconv_out(settings->client_dir, &length);
- cbClientDir = length;
+ cbClientDir = freerdp_AsciiToUnicodeAlloc(settings->client_dir, &clientDir, 0) * 2;
- cbAutoReconnectLen = settings->client_auto_reconnect_cookie->cbLen;
+ cbAutoReconnectLen = (int) settings->client_auto_reconnect_cookie->cbLen;
stream_write_uint16(s, clientAddressFamily); /* clientAddressFamily */
void rdp_write_info_packet(STREAM* s, rdpSettings* settings)
{
- size_t length;
uint32 flags;
- uint8* domain;
- uint16 cbDomain;
- uint8* userName;
- uint16 cbUserName;
- uint8* password;
- uint16 cbPassword;
- uint8* alternateShell;
- uint16 cbAlternateShell;
- uint8* workingDir;
- uint16 cbWorkingDir;
+ WCHAR* domain;
+ int cbDomain;
+ WCHAR* userName;
+ int cbUserName;
+ WCHAR* password;
+ int cbPassword;
+ WCHAR* alternateShell;
+ int cbAlternateShell;
+ WCHAR* workingDir;
+ int cbWorkingDir;
boolean usedPasswordCookie = false;
flags = INFO_MOUSE |
if (settings->compression)
flags |= INFO_COMPRESSION | INFO_PACKET_COMPR_TYPE_RDP6;
- domain = (uint8*) freerdp_uniconv_out(settings->domain, &length);
- cbDomain = length;
+ if (settings->domain)
+ {
+ cbDomain = freerdp_AsciiToUnicodeAlloc(settings->domain, &domain, 0) * 2;
+ }
+ else
+ {
+ domain = NULL;
+ cbDomain = 0;
+ }
- userName = (uint8*) freerdp_uniconv_out(settings->username, &length);
- cbUserName = length;
+ cbUserName = freerdp_AsciiToUnicodeAlloc(settings->username, &userName, 0) * 2;
if (settings->password_cookie && settings->password_cookie->length > 0)
{
usedPasswordCookie = true;
- password = (uint8*)settings->password_cookie->data;
+ password = (WCHAR*) settings->password_cookie->data;
cbPassword = settings->password_cookie->length - 2; /* Strip double zero termination */
}
else
{
- password = (uint8*) freerdp_uniconv_out(settings->password, &length);
- cbPassword = length;
+ cbPassword = freerdp_AsciiToUnicodeAlloc(settings->password, &password, 0) * 2;
}
- alternateShell = (uint8*) freerdp_uniconv_out(settings->shell, &length);
- cbAlternateShell = length;
+ cbAlternateShell = freerdp_AsciiToUnicodeAlloc(settings->shell, &alternateShell, 0) * 2;
- workingDir = (uint8*) freerdp_uniconv_out(settings->directory, &length);
- cbWorkingDir = length;
+ cbWorkingDir = freerdp_AsciiToUnicodeAlloc(settings->directory, &workingDir, 0) * 2;
stream_write_uint32(s, 0); /* CodePage */
stream_write_uint32(s, flags); /* flags */
{
STREAM* s;
uint32 cbSize;
- uint16 cchPCB_times2 = 0;
- char* wszPCB = NULL;
+ uint16 cchPCB = 0;
+ WCHAR* wszPCB = NULL;
if (!nego->send_preconnection_pdu)
return true;
if (nego->preconnection_blob)
{
- size_t size;
- wszPCB = freerdp_uniconv_out(nego->preconnection_blob, &size);
- cchPCB_times2 = (uint16) size;
- cchPCB_times2 += 2; /* zero-termination */
- cbSize += cchPCB_times2;
+ cchPCB = (uint16) freerdp_AsciiToUnicodeAlloc(nego->preconnection_blob, &wszPCB, 0);
+ cchPCB += 1; /* zero-termination */
+ cbSize += cchPCB * 2;
}
s = transport_send_stream_init(nego->transport, cbSize);
stream_write_uint32(s, 0); /* Flags */
stream_write_uint32(s, PRECONNECTION_PDU_V2); /* Version */
stream_write_uint32(s, nego->preconnection_id); /* Id */
- stream_write_uint16(s, cchPCB_times2 / 2); /* cchPCB */
+ stream_write_uint16(s, cchPCB); /* cchPCB */
if (wszPCB)
{
- stream_write(s, wszPCB, cchPCB_times2); /* wszPCB */
+ stream_write(s, wszPCB, cchPCB * 2); /* wszPCB */
xfree(wszPCB);
}
uint32 bias;
sint32 sbias;
uint32 bias2c;
- size_t length;
- uint8* standardName;
- uint8* daylightName;
- size_t standardNameLength;
- size_t daylightNameLength;
+ WCHAR* standardName;
+ WCHAR* daylightName;
+ int standardNameLength;
+ int daylightNameLength;
TIME_ZONE_INFO* clientTimeZone;
clientTimeZone = settings->client_time_zone;
freerdp_time_zone_detect(clientTimeZone);
- standardName = (uint8*) freerdp_uniconv_out(clientTimeZone->standardName, &length);
- standardNameLength = length;
-
- daylightName = (uint8*) freerdp_uniconv_out(clientTimeZone->daylightName, &length);
- daylightNameLength = length;
+ standardNameLength = freerdp_AsciiToUnicodeAlloc(clientTimeZone->standardName, &standardName, 0) * 2;
+ daylightNameLength = freerdp_AsciiToUnicodeAlloc(clientTimeZone->daylightName, &daylightName, 0) * 2;
if (standardNameLength > 62)
standardNameLength = 62;
stream_write_zero(s, 64 - standardNameLength);
rdp_write_system_time(s, &clientTimeZone->standardDate); /* StandardDate */
+
DEBUG_TIMEZONE("bias=%d stdName='%s' dlName='%s'",
bias, clientTimeZone->standardName, clientTimeZone->daylightName);
STREAM* s_p4;
int status = -1;
rdpRpc* rpc = tsg->rpc;
- uint8* dest_addr_unic;
- uint32 dest_addr_unic_len;
+ WCHAR* dest_addr_unic;
+ int dest_addr_unic_len;
if (!rpc_connect(rpc))
{
}
status = -1;
- dest_addr_unic = (uint8*) freerdp_uniconv_out(hostname, (size_t*) &dest_addr_unic_len);
+ dest_addr_unic_len = freerdp_AsciiToUnicodeAlloc(hostname, &dest_addr_unic, 0) * 2;
memcpy(tsg_packet4 + 4, tsg->TunnelContext, 16);
memcpy(tsg_packet4 + 38, &port, 2);
#include <winpr/crt.h>
-char* freerdp_uniconv_out(const char *str, size_t* pout_len)
-{
- WCHAR* wstr;
- int length;
-
- length = freerdp_AsciiToUnicodeAlloc(str, &wstr, 0);
- *pout_len = (size_t) length;
-
- return (char*) wstr;
-}
-
int freerdp_AsciiToUnicodeAlloc(const CHAR* str, WCHAR** wstr, int length)
{
if (!str)
MultiByteToWideChar(CP_UTF8, 0, str, length, (LPWSTR) (*wstr), length * sizeof(WCHAR));
(*wstr)[length] = 0;
- length *= 2;
-
return length;
}