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.
|
|
|
|
*/
|
|
|
|
|
2022-02-16 13:20:38 +03:00
|
|
|
#include <freerdp/config.h>
|
2012-08-15 01:09:01 +04:00
|
|
|
|
2012-12-17 08:34:07 +04:00
|
|
|
#include <winpr/crt.h>
|
2022-12-14 12:43:07 +03:00
|
|
|
#include <winpr/assert.h>
|
2016-02-23 20:08:18 +03:00
|
|
|
#include <winpr/timezone.h>
|
2012-12-17 08:34:07 +04:00
|
|
|
|
2012-02-16 10:53:58 +04:00
|
|
|
#include "timezone.h"
|
|
|
|
|
2022-04-19 15:29:17 +03:00
|
|
|
#include <freerdp/log.h>
|
|
|
|
#define TAG FREERDP_TAG("core.timezone")
|
|
|
|
|
2022-12-14 12:43:07 +03:00
|
|
|
static BOOL rdp_read_system_time(wStream* s, SYSTEMTIME* system_time);
|
|
|
|
static BOOL rdp_write_system_time(wStream* s, const SYSTEMTIME* system_time);
|
2016-02-23 20:08:18 +03:00
|
|
|
|
2012-02-16 10:53:58 +04:00
|
|
|
/**
|
2022-12-09 16:35:03 +03:00
|
|
|
* Read SYSTEM_TIME structure (TS_SYSTEMTIME).
|
|
|
|
* msdn{cc240478}
|
2012-02-16 10:53:58 +04:00
|
|
|
* @param s stream
|
|
|
|
* @param system_time system time structure
|
|
|
|
*/
|
|
|
|
|
2022-12-14 12:43:07 +03:00
|
|
|
BOOL rdp_read_system_time(wStream* s, SYSTEMTIME* system_time)
|
2012-02-16 10:53:58 +04:00
|
|
|
{
|
2022-12-14 12:43:07 +03:00
|
|
|
WINPR_ASSERT(system_time);
|
|
|
|
|
|
|
|
if (!Stream_CheckAndLogRequiredLength(TAG, s, 16ull))
|
|
|
|
return FALSE;
|
|
|
|
|
2019-11-06 17:24:51 +03: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 */
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT16(s, system_time->wMilliseconds); /* wMilliseconds */
|
2022-12-14 12:43:07 +03:00
|
|
|
return TRUE;
|
2012-02-16 10:53:58 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-12-09 16:35:03 +03:00
|
|
|
* Write SYSTEM_TIME structure (TS_SYSTEMTIME).
|
|
|
|
* msdn{cc240478}
|
2012-02-16 10:53:58 +04:00
|
|
|
* @param s stream
|
|
|
|
* @param system_time system time structure
|
|
|
|
*/
|
|
|
|
|
2022-12-14 12:43:07 +03:00
|
|
|
BOOL rdp_write_system_time(wStream* s, const SYSTEMTIME* system_time)
|
2012-02-16 10:53:58 +04:00
|
|
|
{
|
2022-12-14 12:43:07 +03:00
|
|
|
WINPR_ASSERT(system_time);
|
|
|
|
if (!Stream_EnsureRemainingCapacity(s, 16ull))
|
|
|
|
return FALSE;
|
|
|
|
|
2019-11-06 17:24:51 +03: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 */
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write_UINT16(s, system_time->wMilliseconds); /* wMilliseconds */
|
2019-11-06 17:24:51 +03:00
|
|
|
DEBUG_TIMEZONE("Time: y=%" PRIu16 ",m=%" PRIu16 ",dow=%" PRIu16 ",d=%" PRIu16 ", %02" PRIu16
|
|
|
|
":%02" PRIu16 ":%02" PRIu16 ".%03" PRIu16 "",
|
2017-02-20 20:31:58 +03:00
|
|
|
system_time->wYear, system_time->wMonth, system_time->wDayOfWeek,
|
|
|
|
system_time->wDay, system_time->wHour, system_time->wMinute,
|
|
|
|
system_time->wSecond, system_time->wMilliseconds);
|
2022-12-14 12:43:07 +03:00
|
|
|
return TRUE;
|
2012-02-16 10:53:58 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-12-09 16:35:03 +03:00
|
|
|
* Read client time zone information (TS_TIME_ZONE_INFORMATION).
|
|
|
|
* msdn{cc240477}
|
2012-02-16 10:53:58 +04:00
|
|
|
* @param s stream
|
|
|
|
* @param settings settings
|
2022-12-09 16:35:03 +03:00
|
|
|
*
|
|
|
|
* @return \b TRUE for success, \b FALSE otherwise
|
2012-02-16 10:53:58 +04:00
|
|
|
*/
|
|
|
|
|
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
|
|
|
{
|
2022-12-14 12:43:07 +03:00
|
|
|
LPTIME_ZONE_INFORMATION tz = { 0 };
|
2012-02-16 10:53:58 +04:00
|
|
|
|
2016-02-25 11:02:46 +03:00
|
|
|
if (!s || !settings)
|
|
|
|
return FALSE;
|
2016-02-24 22:16:33 +03:00
|
|
|
|
2022-04-19 15:29:17 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredLength(TAG, s, 172))
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2012-02-16 10:53:58 +04:00
|
|
|
|
2016-02-23 20:08:18 +03:00
|
|
|
tz = settings->ClientTimeZone;
|
2017-02-20 20:31:58 +03:00
|
|
|
|
2016-02-25 11:02:46 +03:00
|
|
|
if (!tz)
|
|
|
|
return FALSE;
|
2012-02-16 10:53:58 +04:00
|
|
|
|
2016-02-23 20:08:18 +03:00
|
|
|
Stream_Read_UINT32(s, tz->Bias); /* Bias */
|
2012-02-16 10:53:58 +04:00
|
|
|
/* standardName (64 bytes) */
|
2016-02-23 20:08:18 +03:00
|
|
|
Stream_Read(s, tz->StandardName, sizeof(tz->StandardName));
|
2022-12-14 12:43:07 +03:00
|
|
|
if (!rdp_read_system_time(s, &tz->StandardDate)) /* StandardDate */
|
|
|
|
return FALSE;
|
2019-11-06 17:24:51 +03:00
|
|
|
Stream_Read_UINT32(s, tz->StandardBias); /* StandardBias */
|
2012-02-16 10:53:58 +04:00
|
|
|
/* daylightName (64 bytes) */
|
2016-02-23 20:08:18 +03:00
|
|
|
Stream_Read(s, tz->DaylightName, sizeof(tz->DaylightName));
|
2022-12-14 12:43:07 +03:00
|
|
|
if (!rdp_read_system_time(s, &tz->DaylightDate)) /* DaylightDate */
|
|
|
|
return FALSE;
|
2019-11-06 17:24:51 +03:00
|
|
|
Stream_Read_UINT32(s, tz->DaylightBias); /* DaylightBias */
|
2012-10-09 10:31:28 +04:00
|
|
|
return TRUE;
|
2012-02-16 10:53:58 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-12-09 16:35:03 +03:00
|
|
|
* Write client time zone information (TS_TIME_ZONE_INFORMATION).
|
|
|
|
* msdn{cc240477}
|
2012-02-16 10:53:58 +04:00
|
|
|
* @param s stream
|
|
|
|
* @param settings settings
|
2022-12-09 16:35:03 +03:00
|
|
|
*
|
|
|
|
* @return \b TRUE for success, \b FALSE otherwise
|
2012-02-16 10:53:58 +04:00
|
|
|
*/
|
|
|
|
|
2016-02-24 22:16:33 +03:00
|
|
|
BOOL rdp_write_client_time_zone(wStream* s, rdpSettings* settings)
|
2012-02-16 10:53:58 +04:00
|
|
|
{
|
2022-12-14 12:43:07 +03:00
|
|
|
LPTIME_ZONE_INFORMATION tz = { 0 };
|
|
|
|
|
|
|
|
WINPR_ASSERT(settings);
|
2016-02-23 20:08:18 +03:00
|
|
|
tz = settings->ClientTimeZone;
|
2017-02-20 20:31:58 +03:00
|
|
|
|
2016-02-25 11:02:46 +03:00
|
|
|
if (!tz)
|
|
|
|
return FALSE;
|
2016-02-24 22:16:33 +03:00
|
|
|
|
2017-02-20 20:31:58 +03:00
|
|
|
GetTimeZoneInformation(tz);
|
2022-12-14 12:43:07 +03:00
|
|
|
if (!Stream_EnsureRemainingCapacity(s, 4ull + sizeof(tz->StandardName)))
|
|
|
|
return FALSE;
|
|
|
|
|
2016-02-23 20:08:18 +03:00
|
|
|
/* Bias */
|
|
|
|
Stream_Write_UINT32(s, tz->Bias);
|
2012-02-16 10:53:58 +04:00
|
|
|
/* standardName (64 bytes) */
|
2016-02-23 20:08:18 +03:00
|
|
|
Stream_Write(s, tz->StandardName, sizeof(tz->StandardName));
|
|
|
|
/* StandardDate */
|
2022-12-14 12:43:07 +03:00
|
|
|
if (!rdp_write_system_time(s, &tz->StandardDate))
|
|
|
|
return FALSE;
|
|
|
|
|
2016-12-14 00:47:08 +03:00
|
|
|
#ifdef WITH_DEBUG_TIMEZONE
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_DBG(TIMEZONE_TAG, "bias=%" PRId32 "", tz->Bias);
|
2016-12-14 00:47:08 +03:00
|
|
|
WLog_DBG(TIMEZONE_TAG, "StandardName:");
|
2019-11-06 17:24:51 +03:00
|
|
|
winpr_HexDump(TIMEZONE_TAG, WLOG_DEBUG, (const BYTE*)tz->StandardName,
|
|
|
|
sizeof(tz->StandardName));
|
2016-12-14 00:47:08 +03:00
|
|
|
WLog_DBG(TIMEZONE_TAG, "DaylightName:");
|
2019-11-06 17:24:51 +03:00
|
|
|
winpr_HexDump(TIMEZONE_TAG, WLOG_DEBUG, (const BYTE*)tz->DaylightName,
|
|
|
|
sizeof(tz->DaylightName));
|
2016-12-14 00:47:08 +03:00
|
|
|
#endif
|
2012-08-02 22:33:58 +04:00
|
|
|
/* Note that StandardBias is ignored if no valid standardDate is provided. */
|
2016-02-23 20:08:18 +03:00
|
|
|
/* StandardBias */
|
2022-12-14 12:43:07 +03:00
|
|
|
if (!Stream_EnsureRemainingCapacity(s, 4ull + sizeof(tz->DaylightName)))
|
|
|
|
return FALSE;
|
2016-02-23 20:08:18 +03:00
|
|
|
Stream_Write_UINT32(s, tz->StandardBias);
|
2019-11-06 17:24:51 +03:00
|
|
|
DEBUG_TIMEZONE("StandardBias=%" PRId32 "", tz->StandardBias);
|
2012-02-16 10:53:58 +04:00
|
|
|
/* daylightName (64 bytes) */
|
2016-02-23 20:08:18 +03:00
|
|
|
Stream_Write(s, tz->DaylightName, sizeof(tz->DaylightName));
|
|
|
|
/* DaylightDate */
|
2022-12-14 12:43:07 +03:00
|
|
|
if (!rdp_write_system_time(s, &tz->DaylightDate))
|
|
|
|
return FALSE;
|
2012-08-02 22:33:58 +04:00
|
|
|
/* Note that DaylightBias is ignored if no valid daylightDate is provided. */
|
2016-02-23 20:08:18 +03:00
|
|
|
/* DaylightBias */
|
2022-12-14 12:43:07 +03:00
|
|
|
if (!Stream_EnsureRemainingCapacity(s, 4ull))
|
|
|
|
return FALSE;
|
2016-02-23 20:08:18 +03:00
|
|
|
Stream_Write_UINT32(s, tz->DaylightBias);
|
2019-11-06 17:24:51 +03:00
|
|
|
DEBUG_TIMEZONE("DaylightBias=%" PRId32 "", tz->DaylightBias);
|
2016-02-25 11:02:46 +03:00
|
|
|
return TRUE;
|
2012-02-16 10:53:58 +04:00
|
|
|
}
|