Merge pull request #3151 from akallabeth/timezone_refactor

Timezone refactor
This commit is contained in:
Martin Fleisz 2016-02-26 09:57:35 +01:00
commit 4f22682ed2
8 changed files with 1783 additions and 1901 deletions

View File

@ -1,37 +0,0 @@
/**
* FreeRDP: A Remote Desktop Protocol Implementation
* 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.
*/
#ifndef FREERDP_LOCALE_TIMEZONE_H
#define FREERDP_LOCALE_TIMEZONE_H
#include <freerdp/api.h>
#include <freerdp/types.h>
#include <freerdp/settings.h>
#ifdef __cplusplus
extern "C" {
#endif
FREERDP_API void freerdp_time_zone_detect(TIME_ZONE_INFO* clientTimeZone);
#ifdef __cplusplus
}
#endif
#endif /* FREERDP_LOCALE_TIMEZONE_H */

View File

@ -21,6 +21,8 @@
#ifndef FREERDP_SETTINGS_H
#define FREERDP_SETTINGS_H
#include <winpr/timezone.h>
#include <freerdp/api.h>
#include <freerdp/types.h>
@ -269,32 +271,6 @@ typedef struct _TARGET_NET_ADDRESS TARGET_NET_ADDRESS;
#define ORIENTATION_LANDSCAPE_FLIPPED 180
#define ORIENTATION_PORTRAIT_FLIPPED 270
/* SYSTEM_TIME */
typedef struct
{
UINT16 wYear;
UINT16 wMonth;
UINT16 wDayOfWeek;
UINT16 wDay;
UINT16 wHour;
UINT16 wMinute;
UINT16 wSecond;
UINT16 wMilliseconds;
} SYSTEM_TIME;
/* TIME_ZONE_INFORMATION */
struct _TIME_ZONE_INFO
{
UINT32 bias;
char standardName[32];
SYSTEM_TIME standardDate;
UINT32 standardBias;
char daylightName[32];
SYSTEM_TIME daylightDate;
UINT32 daylightBias;
};
typedef struct _TIME_ZONE_INFO TIME_ZONE_INFO;
/* ARC_CS_PRIVATE_PACKET */
typedef struct
{
@ -977,7 +953,7 @@ struct rdp_settings
UINT64 padding0896[896 - 837]; /* 837 */
/* Client Info (Time Zone) */
ALIGN64 TIME_ZONE_INFO* ClientTimeZone; /* 896 */
ALIGN64 LPTIME_ZONE_INFORMATION ClientTimeZone; /* 896 */
ALIGN64 char* DynamicDSTTimeZoneKeyName; /* 897 */
ALIGN64 BOOL DynamicDaylightTimeDisabled; /* 898 */
UINT64 padding0960[960 - 899]; /* 899 */

View File

@ -472,7 +472,7 @@ rdpSettings* freerdp_settings_new(DWORD flags)
if (!settings->ServerAutoReconnectCookie)
goto out_fail;
settings->ClientTimeZone = (TIME_ZONE_INFO*) calloc(1,sizeof(TIME_ZONE_INFO));
settings->ClientTimeZone = (LPTIME_ZONE_INFORMATION) calloc(1,sizeof(TIME_ZONE_INFORMATION));
if (!settings->ClientTimeZone)
goto out_fail;
@ -762,10 +762,10 @@ rdpSettings* freerdp_settings_clone(rdpSettings* settings)
CopyMemory(_settings->ClientAutoReconnectCookie, settings->ClientAutoReconnectCookie, sizeof(ARC_CS_PRIVATE_PACKET));
CopyMemory(_settings->ServerAutoReconnectCookie, settings->ServerAutoReconnectCookie, sizeof(ARC_SC_PRIVATE_PACKET));
_settings->ClientTimeZone = (TIME_ZONE_INFO*) malloc(sizeof(TIME_ZONE_INFO));
_settings->ClientTimeZone = (LPTIME_ZONE_INFORMATION) malloc(sizeof(TIME_ZONE_INFORMATION));
if (!_settings->ClientTimeZone)
goto out_fail;
CopyMemory(_settings->ClientTimeZone, settings->ClientTimeZone, sizeof(TIME_ZONE_INFO));
CopyMemory(_settings->ClientTimeZone, settings->ClientTimeZone, sizeof(TIME_ZONE_INFORMATION));
_settings->TargetNetAddressCount = settings->TargetNetAddressCount;
@ -815,7 +815,7 @@ rdpSettings* freerdp_settings_clone(rdpSettings* settings)
goto out_fail;
}
if (_settings->DeviceArraySize < _settings->DeviceCount)
if (_settings->DeviceArraySize < _settings->DeviceCount)
{
_settings->DeviceCount = 0;
_settings->DeviceArraySize = 0;

View File

@ -22,9 +22,13 @@
#endif
#include <winpr/crt.h>
#include <winpr/timezone.h>
#include "timezone.h"
static void rdp_read_system_time(wStream* s, SYSTEMTIME* system_time);
static void rdp_write_system_time(wStream* s, SYSTEMTIME* system_time);
/**
* Read SYSTEM_TIME structure (TS_SYSTEMTIME).\n
* @msdn{cc240478}
@ -32,7 +36,7 @@
* @param system_time system time structure
*/
void rdp_read_system_time(wStream* s, SYSTEM_TIME* system_time)
void rdp_read_system_time(wStream* s, SYSTEMTIME* system_time)
{
Stream_Read_UINT16(s, system_time->wYear); /* wYear, must be set to 0 */
Stream_Read_UINT16(s, system_time->wMonth); /* wMonth */
@ -51,7 +55,7 @@ void rdp_read_system_time(wStream* s, SYSTEM_TIME* system_time)
* @param system_time system time structure
*/
void rdp_write_system_time(wStream* s, SYSTEM_TIME* system_time)
void rdp_write_system_time(wStream* s, SYSTEMTIME* system_time)
{
Stream_Write_UINT16(s, system_time->wYear); /* wYear, must be set to 0 */
Stream_Write_UINT16(s, system_time->wMonth); /* wMonth */
@ -76,34 +80,31 @@ void rdp_write_system_time(wStream* s, SYSTEM_TIME* system_time)
BOOL rdp_read_client_time_zone(wStream* s, rdpSettings* settings)
{
char* str = NULL;
TIME_ZONE_INFO* clientTimeZone;
LPTIME_ZONE_INFORMATION tz;
if (!s || !settings)
return FALSE;
if (Stream_GetRemainingLength(s) < 172)
return FALSE;
clientTimeZone = settings->ClientTimeZone;
tz = settings->ClientTimeZone;
if (!tz)
return FALSE;
Stream_Read_UINT32(s, clientTimeZone->bias); /* Bias */
Stream_Read_UINT32(s, tz->Bias); /* Bias */
/* standardName (64 bytes) */
ConvertFromUnicode(CP_UTF8, 0, (WCHAR*) Stream_Pointer(s), 64 / 2, &str, 0, NULL, NULL);
Stream_Seek(s, 64);
strncpy(clientTimeZone->standardName, str, sizeof(clientTimeZone->standardName));
free(str);
str = NULL;
Stream_Read(s, tz->StandardName, sizeof(tz->StandardName));
rdp_read_system_time(s, &clientTimeZone->standardDate); /* StandardDate */
Stream_Read_UINT32(s, clientTimeZone->standardBias); /* StandardBias */
rdp_read_system_time(s, &tz->StandardDate); /* StandardDate */
Stream_Read_UINT32(s, tz->StandardBias); /* StandardBias */
/* daylightName (64 bytes) */
ConvertFromUnicode(CP_UTF8, 0, (WCHAR*) Stream_Pointer(s), 64 / 2, &str, 0, NULL, NULL);
Stream_Seek(s, 64);
strncpy(clientTimeZone->daylightName, str, sizeof(clientTimeZone->daylightName));
free(str);
Stream_Read(s, tz->DaylightName, sizeof(tz->DaylightName));
rdp_read_system_time(s, &clientTimeZone->daylightDate); /* DaylightDate */
Stream_Read_UINT32(s, clientTimeZone->daylightBias); /* DaylightBias */
rdp_read_system_time(s, &tz->DaylightDate); /* DaylightDate */
Stream_Read_UINT32(s, tz->DaylightBias); /* DaylightBias */
return TRUE;
}
@ -115,55 +116,45 @@ BOOL rdp_read_client_time_zone(wStream* s, rdpSettings* settings)
* @param settings settings
*/
void rdp_write_client_time_zone(wStream* s, rdpSettings* settings)
BOOL rdp_write_client_time_zone(wStream* s, rdpSettings* settings)
{
WCHAR* standardName = NULL;
WCHAR* daylightName = NULL;
int standardNameLength;
int daylightNameLength;
TIME_ZONE_INFO* clientTimeZone;
LPTIME_ZONE_INFORMATION tz;
DWORD rc;
clientTimeZone = settings->ClientTimeZone;
freerdp_time_zone_detect(clientTimeZone);
tz = settings->ClientTimeZone;
if (!tz)
return FALSE;
standardNameLength = ConvertToUnicode(CP_UTF8, 0, clientTimeZone->standardName, -1, &standardName, 0) * 2;
daylightNameLength = ConvertToUnicode(CP_UTF8, 0, clientTimeZone->daylightName, -1, &daylightName, 0) * 2;
rc = GetTimeZoneInformation(tz);
if (standardNameLength > 62)
standardNameLength = 62;
if (daylightNameLength > 62)
daylightNameLength = 62;
/* Bias */
Stream_Write_UINT32(s, clientTimeZone->bias);
/* Bias */
Stream_Write_UINT32(s, tz->Bias);
/* standardName (64 bytes) */
Stream_Write(s, standardName, standardNameLength);
Stream_Zero(s, 64 - standardNameLength);
Stream_Write(s, tz->StandardName, sizeof(tz->StandardName));
/* StandardDate */
rdp_write_system_time(s, &clientTimeZone->standardDate);
/* StandardDate */
rdp_write_system_time(s, &tz->StandardDate);
DEBUG_TIMEZONE("bias=%d stdName='%s' dlName='%s'", clientTimeZone->bias, clientTimeZone->standardName, clientTimeZone->daylightName);
DEBUG_TIMEZONE("bias=%d stdName='%s' dlName='%s'", tz->Bias,
tz->StandardName, tz->DaylightName);
/* Note that StandardBias is ignored if no valid standardDate is provided. */
/* StandardBias */
Stream_Write_UINT32(s, clientTimeZone->standardBias);
DEBUG_TIMEZONE("StandardBias=%d", clientTimeZone->standardBias);
/* StandardBias */
Stream_Write_UINT32(s, tz->StandardBias);
DEBUG_TIMEZONE("StandardBias=%d", tz->StandardBias);
/* daylightName (64 bytes) */
Stream_Write(s, daylightName, daylightNameLength);
Stream_Zero(s, 64 - daylightNameLength);
Stream_Write(s, tz->DaylightName, sizeof(tz->DaylightName));
/* DaylightDate */
rdp_write_system_time(s, &clientTimeZone->daylightDate);
/* DaylightDate */
rdp_write_system_time(s, &tz->DaylightDate);
/* Note that DaylightBias is ignored if no valid daylightDate is provided. */
/* DaylightBias */
Stream_Write_UINT32(s, clientTimeZone->daylightBias);
DEBUG_TIMEZONE("DaylightBias=%d", clientTimeZone->daylightBias);
/* DaylightBias */
Stream_Write_UINT32(s, tz->DaylightBias);
DEBUG_TIMEZONE("DaylightBias=%d", tz->DaylightBias);
free(standardName);
free(daylightName);
return TRUE;
}

View File

@ -28,15 +28,11 @@
#include <freerdp/log.h>
#include <freerdp/freerdp.h>
#include <freerdp/locale/timezone.h>
#include <winpr/stream.h>
void rdp_read_system_time(wStream* s, SYSTEM_TIME* system_time);
void rdp_write_system_time(wStream* s, SYSTEM_TIME* system_time);
void rdp_get_client_time_zone(wStream* s, rdpSettings* settings);
BOOL rdp_read_client_time_zone(wStream* s, rdpSettings* settings);
void rdp_write_client_time_zone(wStream* s, rdpSettings* settings);
BOOL rdp_write_client_time_zone(wStream* s, rdpSettings* settings);
#define TIMEZONE_TAG FREERDP_TAG("core.timezone")
#ifdef WITH_DEBUG_TIMEZONE

View File

@ -22,7 +22,6 @@ set(${MODULE_PREFIX}_SRCS
keyboard_layout.c
keyboard.c
locale.c
timezone.c
liblocale.h)
set(${MODULE_PREFIX}_X11_SRCS

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff