2012-02-16 10:53:58 +04:00
|
|
|
/**
|
2012-10-09 07:02:04 +04:00
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
2012-02-16 10:53:58 +04:00
|
|
|
* Time Zone Redirection
|
|
|
|
*
|
|
|
|
* Copyright 2012 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-12-17 08:34:07 +04:00
|
|
|
#include <winpr/crt.h>
|
|
|
|
|
2012-02-16 10:53:58 +04:00
|
|
|
#include "timezone.h"
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Read SYSTEM_TIME structure (TS_SYSTEMTIME).\n
|
|
|
|
* @msdn{cc240478}
|
|
|
|
* @param s stream
|
|
|
|
* @param system_time system time structure
|
|
|
|
*/
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
void rdp_read_system_time(wStream* s, SYSTEM_TIME* system_time)
|
2012-02-16 10:53:58 +04:00
|
|
|
{
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT16(s, system_time->wYear); /* wYear, must be set to 0 */
|
|
|
|
Stream_Read_UINT16(s, system_time->wMonth); /* wMonth */
|
|
|
|
Stream_Read_UINT16(s, system_time->wDayOfWeek); /* wDayOfWeek */
|
|
|
|
Stream_Read_UINT16(s, system_time->wDay); /* wDay */
|
|
|
|
Stream_Read_UINT16(s, system_time->wHour); /* wHour */
|
|
|
|
Stream_Read_UINT16(s, system_time->wMinute); /* wMinute */
|
|
|
|
Stream_Read_UINT16(s, system_time->wSecond); /* wSecond */
|
|
|
|
Stream_Read_UINT16(s, system_time->wMilliseconds); /* wMilliseconds */
|
2012-02-16 10:53:58 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Write SYSTEM_TIME structure (TS_SYSTEMTIME).\n
|
|
|
|
* @msdn{cc240478}
|
|
|
|
* @param s stream
|
|
|
|
* @param system_time system time structure
|
|
|
|
*/
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
void rdp_write_system_time(wStream* s, SYSTEM_TIME* system_time)
|
2012-02-16 10:53:58 +04:00
|
|
|
{
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write_UINT16(s, system_time->wYear); /* wYear, must be set to 0 */
|
|
|
|
Stream_Write_UINT16(s, system_time->wMonth); /* wMonth */
|
|
|
|
Stream_Write_UINT16(s, system_time->wDayOfWeek); /* wDayOfWeek */
|
|
|
|
Stream_Write_UINT16(s, system_time->wDay); /* wDay */
|
|
|
|
Stream_Write_UINT16(s, system_time->wHour); /* wHour */
|
|
|
|
Stream_Write_UINT16(s, system_time->wMinute); /* wMinute */
|
|
|
|
Stream_Write_UINT16(s, system_time->wSecond); /* wSecond */
|
|
|
|
Stream_Write_UINT16(s, system_time->wMilliseconds); /* wMilliseconds */
|
2012-08-02 22:33:58 +04:00
|
|
|
DEBUG_TIMEZONE("Time: y=%d,m=%d,dow=%d,d=%d, %02d:%02d:%02d.%03d",
|
|
|
|
system_time->wYear, system_time->wMonth, system_time->wDayOfWeek,
|
|
|
|
system_time->wDay, system_time->wHour, system_time->wMinute,
|
|
|
|
system_time->wSecond, system_time->wMilliseconds);
|
2012-02-16 10:53:58 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Read client time zone information (TS_TIME_ZONE_INFORMATION).\n
|
|
|
|
* @msdn{cc240477}
|
|
|
|
* @param s stream
|
|
|
|
* @param settings settings
|
|
|
|
*/
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
BOOL rdp_read_client_time_zone(wStream* s, rdpSettings* settings)
|
2012-02-16 10:53:58 +04:00
|
|
|
{
|
2013-01-16 04:14:03 +04:00
|
|
|
char* str = NULL;
|
2012-02-16 10:53:58 +04:00
|
|
|
TIME_ZONE_INFO* clientTimeZone;
|
|
|
|
|
2013-04-30 06:35:15 +04:00
|
|
|
if (Stream_GetRemainingLength(s) < 172)
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2012-02-16 10:53:58 +04:00
|
|
|
|
2012-11-08 00:13:14 +04:00
|
|
|
clientTimeZone = settings->ClientTimeZone;
|
2012-02-16 10:53:58 +04:00
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT32(s, clientTimeZone->bias); /* Bias */
|
2012-02-16 10:53:58 +04:00
|
|
|
|
|
|
|
/* standardName (64 bytes) */
|
2013-04-30 06:35:15 +04:00
|
|
|
ConvertFromUnicode(CP_UTF8, 0, (WCHAR*) Stream_Pointer(s), 64 / 2, &str, 0, NULL, NULL);
|
|
|
|
Stream_Seek(s, 64);
|
2012-02-16 10:53:58 +04:00
|
|
|
strncpy(clientTimeZone->standardName, str, sizeof(clientTimeZone->standardName));
|
2012-10-09 07:21:26 +04:00
|
|
|
free(str);
|
2013-01-16 04:14:03 +04:00
|
|
|
str = NULL;
|
2012-02-16 10:53:58 +04:00
|
|
|
|
|
|
|
rdp_read_system_time(s, &clientTimeZone->standardDate); /* StandardDate */
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT32(s, clientTimeZone->standardBias); /* StandardBias */
|
2012-02-16 10:53:58 +04:00
|
|
|
|
|
|
|
/* daylightName (64 bytes) */
|
2013-04-30 06:35:15 +04:00
|
|
|
ConvertFromUnicode(CP_UTF8, 0, (WCHAR*) Stream_Pointer(s), 64 / 2, &str, 0, NULL, NULL);
|
|
|
|
Stream_Seek(s, 64);
|
2012-02-16 10:53:58 +04:00
|
|
|
strncpy(clientTimeZone->daylightName, str, sizeof(clientTimeZone->daylightName));
|
2012-10-09 07:21:26 +04:00
|
|
|
free(str);
|
2012-02-16 10:53:58 +04:00
|
|
|
|
|
|
|
rdp_read_system_time(s, &clientTimeZone->daylightDate); /* DaylightDate */
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT32(s, clientTimeZone->daylightBias); /* DaylightBias */
|
2012-02-16 10:53:58 +04:00
|
|
|
|
2012-10-09 10:31:28 +04:00
|
|
|
return TRUE;
|
2012-02-16 10:53:58 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Write client time zone information (TS_TIME_ZONE_INFORMATION).\n
|
|
|
|
* @msdn{cc240477}
|
|
|
|
* @param s stream
|
|
|
|
* @param settings settings
|
|
|
|
*/
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
void rdp_write_client_time_zone(wStream* s, rdpSettings* settings)
|
2012-02-16 10:53:58 +04:00
|
|
|
{
|
2013-01-11 00:30:32 +04:00
|
|
|
WCHAR* standardName = NULL;
|
|
|
|
WCHAR* daylightName = NULL;
|
2012-09-24 03:49:13 +04:00
|
|
|
int standardNameLength;
|
|
|
|
int daylightNameLength;
|
2012-02-16 10:53:58 +04:00
|
|
|
TIME_ZONE_INFO* clientTimeZone;
|
|
|
|
|
2012-11-08 00:13:14 +04:00
|
|
|
clientTimeZone = settings->ClientTimeZone;
|
2012-02-20 06:08:12 +04:00
|
|
|
freerdp_time_zone_detect(clientTimeZone);
|
2012-02-16 10:53:58 +04:00
|
|
|
|
2012-12-17 19:20:25 +04:00
|
|
|
standardNameLength = ConvertToUnicode(CP_UTF8, 0, clientTimeZone->standardName, -1, &standardName, 0) * 2;
|
|
|
|
daylightNameLength = ConvertToUnicode(CP_UTF8, 0, clientTimeZone->daylightName, -1, &daylightName, 0) * 2;
|
2012-02-16 10:53:58 +04:00
|
|
|
|
|
|
|
if (standardNameLength > 62)
|
|
|
|
standardNameLength = 62;
|
|
|
|
|
|
|
|
if (daylightNameLength > 62)
|
|
|
|
daylightNameLength = 62;
|
|
|
|
|
2013-04-08 17:42:49 +04:00
|
|
|
/* Bias */
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write_UINT32(s, clientTimeZone->bias);
|
2012-02-16 10:53:58 +04:00
|
|
|
|
|
|
|
/* standardName (64 bytes) */
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write(s, standardName, standardNameLength);
|
2013-05-09 00:27:21 +04:00
|
|
|
Stream_Zero(s, 64 - standardNameLength);
|
2012-02-16 10:53:58 +04:00
|
|
|
|
2013-04-08 17:42:49 +04:00
|
|
|
/* StandardDate */
|
|
|
|
rdp_write_system_time(s, &clientTimeZone->standardDate);
|
2012-07-29 01:57:41 +04:00
|
|
|
|
2013-04-08 17:42:49 +04:00
|
|
|
DEBUG_TIMEZONE("bias=%d stdName='%s' dlName='%s'", clientTimeZone->bias, clientTimeZone->standardName, clientTimeZone->daylightName);
|
2012-08-13 04:43:24 +04:00
|
|
|
|
2012-08-02 22:33:58 +04:00
|
|
|
/* Note that StandardBias is ignored if no valid standardDate is provided. */
|
2013-04-08 17:42:49 +04:00
|
|
|
/* StandardBias */
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write_UINT32(s, clientTimeZone->standardBias);
|
2013-04-08 17:42:49 +04:00
|
|
|
DEBUG_TIMEZONE("StandardBias=%d", clientTimeZone->standardBias);
|
2012-02-16 10:53:58 +04:00
|
|
|
|
|
|
|
/* daylightName (64 bytes) */
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write(s, daylightName, daylightNameLength);
|
2013-05-09 00:27:21 +04:00
|
|
|
Stream_Zero(s, 64 - daylightNameLength);
|
2012-08-13 04:43:24 +04:00
|
|
|
|
2013-04-08 17:42:49 +04:00
|
|
|
/* DaylightDate */
|
|
|
|
rdp_write_system_time(s, &clientTimeZone->daylightDate);
|
2012-08-13 04:43:24 +04:00
|
|
|
|
2012-08-02 22:33:58 +04:00
|
|
|
/* Note that DaylightBias is ignored if no valid daylightDate is provided. */
|
2013-04-08 17:42:49 +04:00
|
|
|
/* DaylightBias */
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write_UINT32(s, clientTimeZone->daylightBias);
|
2013-04-08 17:42:49 +04:00
|
|
|
DEBUG_TIMEZONE("DaylightBias=%d", clientTimeZone->daylightBias);
|
2012-02-16 10:53:58 +04:00
|
|
|
|
2012-10-09 07:21:26 +04:00
|
|
|
free(standardName);
|
|
|
|
free(daylightName);
|
2012-02-16 10:53:58 +04:00
|
|
|
}
|