Blame libfreerdp/core/timezone.c

Packit Service fa4841
/**
Packit Service fa4841
 * FreeRDP: A Remote Desktop Protocol Implementation
Packit Service fa4841
 * Time Zone Redirection
Packit Service fa4841
 *
Packit Service fa4841
 * Copyright 2012 Marc-Andre Moreau <marcandre.moreau@gmail.com>
Packit Service fa4841
 *
Packit Service fa4841
 * Licensed under the Apache License, Version 2.0 (the "License");
Packit Service fa4841
 * you may not use this file except in compliance with the License.
Packit Service fa4841
 * You may obtain a copy of the License at
Packit Service fa4841
 *
Packit Service fa4841
 *     http://www.apache.org/licenses/LICENSE-2.0
Packit Service fa4841
 *
Packit Service fa4841
 * Unless required by applicable law or agreed to in writing, software
Packit Service fa4841
 * distributed under the License is distributed on an "AS IS" BASIS,
Packit Service fa4841
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Packit Service fa4841
 * See the License for the specific language governing permissions and
Packit Service fa4841
 * limitations under the License.
Packit Service fa4841
 */
Packit Service fa4841
Packit Service fa4841
#ifdef HAVE_CONFIG_H
Packit Service fa4841
#include "config.h"
Packit Service fa4841
#endif
Packit Service fa4841
Packit Service fa4841
#include <winpr/crt.h>
Packit Service fa4841
#include <winpr/timezone.h>
Packit Service fa4841
Packit Service fa4841
#include "timezone.h"
Packit Service fa4841
Packit Service fa4841
static void rdp_read_system_time(wStream* s, SYSTEMTIME* system_time);
Packit Service fa4841
static void rdp_write_system_time(wStream* s, SYSTEMTIME* system_time);
Packit Service fa4841
Packit Service fa4841
/**
Packit Service fa4841
 * Read SYSTEM_TIME structure (TS_SYSTEMTIME).\n
Packit Service fa4841
 * @msdn{cc240478}
Packit Service fa4841
 * @param s stream
Packit Service fa4841
 * @param system_time system time structure
Packit Service fa4841
 */
Packit Service fa4841
Packit Service fa4841
void rdp_read_system_time(wStream* s, SYSTEMTIME* system_time)
Packit Service fa4841
{
Packit Service fa4841
	Stream_Read_UINT16(s, system_time->wYear);         /* wYear, must be set to 0 */
Packit Service fa4841
	Stream_Read_UINT16(s, system_time->wMonth);        /* wMonth */
Packit Service fa4841
	Stream_Read_UINT16(s, system_time->wDayOfWeek);    /* wDayOfWeek */
Packit Service fa4841
	Stream_Read_UINT16(s, system_time->wDay);          /* wDay */
Packit Service fa4841
	Stream_Read_UINT16(s, system_time->wHour);         /* wHour */
Packit Service fa4841
	Stream_Read_UINT16(s, system_time->wMinute);       /* wMinute */
Packit Service fa4841
	Stream_Read_UINT16(s, system_time->wSecond);       /* wSecond */
Packit Service fa4841
	Stream_Read_UINT16(s, system_time->wMilliseconds); /* wMilliseconds */
Packit Service fa4841
}
Packit Service fa4841
Packit Service fa4841
/**
Packit Service fa4841
 * Write SYSTEM_TIME structure (TS_SYSTEMTIME).\n
Packit Service fa4841
 * @msdn{cc240478}
Packit Service fa4841
 * @param s stream
Packit Service fa4841
 * @param system_time system time structure
Packit Service fa4841
 */
Packit Service fa4841
Packit Service fa4841
void rdp_write_system_time(wStream* s, SYSTEMTIME* system_time)
Packit Service fa4841
{
Packit Service fa4841
	Stream_Write_UINT16(s, system_time->wYear);         /* wYear, must be set to 0 */
Packit Service fa4841
	Stream_Write_UINT16(s, system_time->wMonth);        /* wMonth */
Packit Service fa4841
	Stream_Write_UINT16(s, system_time->wDayOfWeek);    /* wDayOfWeek */
Packit Service fa4841
	Stream_Write_UINT16(s, system_time->wDay);          /* wDay */
Packit Service fa4841
	Stream_Write_UINT16(s, system_time->wHour);         /* wHour */
Packit Service fa4841
	Stream_Write_UINT16(s, system_time->wMinute);       /* wMinute */
Packit Service fa4841
	Stream_Write_UINT16(s, system_time->wSecond);       /* wSecond */
Packit Service fa4841
	Stream_Write_UINT16(s, system_time->wMilliseconds); /* wMilliseconds */
Packit Service fa4841
	DEBUG_TIMEZONE("Time: y=%" PRIu16 ",m=%" PRIu16 ",dow=%" PRIu16 ",d=%" PRIu16 ", %02" PRIu16
Packit Service fa4841
	               ":%02" PRIu16 ":%02" PRIu16 ".%03" PRIu16 "",
Packit Service fa4841
	               system_time->wYear, system_time->wMonth, system_time->wDayOfWeek,
Packit Service fa4841
	               system_time->wDay, system_time->wHour, system_time->wMinute,
Packit Service fa4841
	               system_time->wSecond, system_time->wMilliseconds);
Packit Service fa4841
}
Packit Service fa4841
Packit Service fa4841
/**
Packit Service fa4841
 * Read client time zone information (TS_TIME_ZONE_INFORMATION).\n
Packit Service fa4841
 * @msdn{cc240477}
Packit Service fa4841
 * @param s stream
Packit Service fa4841
 * @param settings settings
Packit Service fa4841
 */
Packit Service fa4841
Packit Service fa4841
BOOL rdp_read_client_time_zone(wStream* s, rdpSettings* settings)
Packit Service fa4841
{
Packit Service fa4841
	LPTIME_ZONE_INFORMATION tz;
Packit Service fa4841
Packit Service fa4841
	if (!s || !settings)
Packit Service fa4841
		return FALSE;
Packit Service fa4841
Packit Service fa4841
	if (Stream_GetRemainingLength(s) < 172)
Packit Service fa4841
		return FALSE;
Packit Service fa4841
Packit Service fa4841
	tz = settings->ClientTimeZone;
Packit Service fa4841
Packit Service fa4841
	if (!tz)
Packit Service fa4841
		return FALSE;
Packit Service fa4841
Packit Service fa4841
	Stream_Read_UINT32(s, tz->Bias); /* Bias */
Packit Service fa4841
	/* standardName (64 bytes) */
Packit Service fa4841
	Stream_Read(s, tz->StandardName, sizeof(tz->StandardName));
Packit Service fa4841
	rdp_read_system_time(s, &tz->StandardDate); /* StandardDate */
Packit Service fa4841
	Stream_Read_UINT32(s, tz->StandardBias);    /* StandardBias */
Packit Service fa4841
	/* daylightName (64 bytes) */
Packit Service fa4841
	Stream_Read(s, tz->DaylightName, sizeof(tz->DaylightName));
Packit Service fa4841
	rdp_read_system_time(s, &tz->DaylightDate); /* DaylightDate */
Packit Service fa4841
	Stream_Read_UINT32(s, tz->DaylightBias);    /* DaylightBias */
Packit Service fa4841
	return TRUE;
Packit Service fa4841
}
Packit Service fa4841
Packit Service fa4841
/**
Packit Service fa4841
 * Write client time zone information (TS_TIME_ZONE_INFORMATION).\n
Packit Service fa4841
 * @msdn{cc240477}
Packit Service fa4841
 * @param s stream
Packit Service fa4841
 * @param settings settings
Packit Service fa4841
 */
Packit Service fa4841
Packit Service fa4841
BOOL rdp_write_client_time_zone(wStream* s, rdpSettings* settings)
Packit Service fa4841
{
Packit Service fa4841
	LPTIME_ZONE_INFORMATION tz;
Packit Service fa4841
	tz = settings->ClientTimeZone;
Packit Service fa4841
Packit Service fa4841
	if (!tz)
Packit Service fa4841
		return FALSE;
Packit Service fa4841
Packit Service fa4841
	GetTimeZoneInformation(tz);
Packit Service fa4841
	/* Bias */
Packit Service fa4841
	Stream_Write_UINT32(s, tz->Bias);
Packit Service fa4841
	/* standardName (64 bytes) */
Packit Service fa4841
	Stream_Write(s, tz->StandardName, sizeof(tz->StandardName));
Packit Service fa4841
	/* StandardDate */
Packit Service fa4841
	rdp_write_system_time(s, &tz->StandardDate);
Packit Service fa4841
#ifdef WITH_DEBUG_TIMEZONE
Packit Service fa4841
	WLog_DBG(TIMEZONE_TAG, "bias=%" PRId32 "", tz->Bias);
Packit Service fa4841
	WLog_DBG(TIMEZONE_TAG, "StandardName:");
Packit Service fa4841
	winpr_HexDump(TIMEZONE_TAG, WLOG_DEBUG, (const BYTE*)tz->StandardName,
Packit Service fa4841
	              sizeof(tz->StandardName));
Packit Service fa4841
	WLog_DBG(TIMEZONE_TAG, "DaylightName:");
Packit Service fa4841
	winpr_HexDump(TIMEZONE_TAG, WLOG_DEBUG, (const BYTE*)tz->DaylightName,
Packit Service fa4841
	              sizeof(tz->DaylightName));
Packit Service fa4841
#endif
Packit Service fa4841
	/* Note that StandardBias is ignored if no valid standardDate is provided. */
Packit Service fa4841
	/* StandardBias */
Packit Service fa4841
	Stream_Write_UINT32(s, tz->StandardBias);
Packit Service fa4841
	DEBUG_TIMEZONE("StandardBias=%" PRId32 "", tz->StandardBias);
Packit Service fa4841
	/* daylightName (64 bytes) */
Packit Service fa4841
	Stream_Write(s, tz->DaylightName, sizeof(tz->DaylightName));
Packit Service fa4841
	/* DaylightDate */
Packit Service fa4841
	rdp_write_system_time(s, &tz->DaylightDate);
Packit Service fa4841
	/* Note that DaylightBias is ignored if no valid daylightDate is provided. */
Packit Service fa4841
	/* DaylightBias */
Packit Service fa4841
	Stream_Write_UINT32(s, tz->DaylightBias);
Packit Service fa4841
	DEBUG_TIMEZONE("DaylightBias=%" PRId32 "", tz->DaylightBias);
Packit Service fa4841
	return TRUE;
Packit Service fa4841
}