Merge pull request #3 from zstegi/stable-1.0
backported timezone redirection
This commit is contained in:
commit
093470673e
@ -24,6 +24,7 @@ set(CMAKE_COLOR_MAKEFILE ON)
|
||||
# Include cmake modules
|
||||
include(CheckIncludeFiles)
|
||||
include(CheckLibraryExists)
|
||||
include(CheckStructHasMember)
|
||||
include(FindPkgConfig)
|
||||
include(TestBigEndian)
|
||||
|
||||
@ -98,6 +99,8 @@ check_include_files(stdint.h HAVE_STDINT_H)
|
||||
check_include_files(stdbool.h HAVE_STDBOOL_H)
|
||||
check_include_files(inttypes.h HAVE_INTTYPES_H)
|
||||
|
||||
check_struct_has_member("struct tm" tm_gmtoff time.h HAVE_TM_GMTOFF)
|
||||
|
||||
# Libraries that we have a hard dependency on
|
||||
find_required_package(OpenSSL)
|
||||
|
||||
|
@ -2,6 +2,7 @@ option(WITH_DEBUG_TRANSPORT "Print transport debug messages." OFF)
|
||||
option(WITH_DEBUG_CHANNELS "Print channel manager debug messages." OFF)
|
||||
option(WITH_DEBUG_SVC "Print static virtual channel debug messages." OFF)
|
||||
option(WITH_DEBUG_DVC "Print dynamic virtual channel debug messages." OFF)
|
||||
option(WITH_DEBUG_TIMEZONE "Print timezone redirection related messages." OFF)
|
||||
option(WITH_DEBUG_KBD "Print keyboard related debug messages." OFF)
|
||||
option(WITH_DEBUG_NLA "Print authentication related debug messages." OFF)
|
||||
option(WITH_DEBUG_NEGO "Print negotiation related debug messages." OFF)
|
||||
|
@ -19,6 +19,8 @@
|
||||
#cmakedefine HAVE_STDBOOL_H
|
||||
#cmakedefine HAVE_INTTYPES_H
|
||||
|
||||
#cmakedefine HAVE_TM_GMTOFF
|
||||
|
||||
/* Endian */
|
||||
#cmakedefine BIG_ENDIAN
|
||||
|
||||
@ -27,6 +29,7 @@
|
||||
#cmakedefine WITH_DEBUG_CHANNELS
|
||||
#cmakedefine WITH_DEBUG_SVC
|
||||
#cmakedefine WITH_DEBUG_DVC
|
||||
#cmakedefine WITH_DEBUG_TIMEZONE
|
||||
#cmakedefine WITH_DEBUG_KBD
|
||||
#cmakedefine WITH_DEBUG_NLA
|
||||
#cmakedefine WITH_DEBUG_NEGO
|
||||
|
@ -230,99 +230,6 @@
|
||||
#define YORUBA 0x046A
|
||||
#define ZULU 0x0435
|
||||
|
||||
|
||||
/*
|
||||
Time zones, taken from Windows Server 2008
|
||||
|
||||
(GMT -12:00) International Date Line West
|
||||
(GMT -11:00) Midway Island, Samoa
|
||||
(GMT -10:00) Hawaii
|
||||
(GMT -09:00) Alaska
|
||||
(GMT -08:00) Pacific Time (US & Canada)
|
||||
(GMT -08:00) Tijuana, Baja California
|
||||
(GMT -07:00) Arizona
|
||||
(GMT -07:00) Chihuahua, La Paz, Mazatlan
|
||||
(GMT -07:00) Mountain Time (US & Canada)
|
||||
(GMT -06:00) Central America
|
||||
(GMT -06:00) Central Time (US & Canada)
|
||||
(GMT -06:00) Guadalajara, Mexico City, Monterrey
|
||||
(GMT -06:00) Saskatchewan
|
||||
(GMT -05:00) Bogota, Lima, Quito, Rio Branco
|
||||
(GMT -05:00) Eastern Time (US & Canada)
|
||||
(GMT -05:00) Indiana (East)
|
||||
(GMT -04:30) Caracas
|
||||
(GMT -04:00) Atlantic Time (Canada)
|
||||
(GMT -04:00) La Paz
|
||||
(GMT -04:00) Manaus
|
||||
(GMT -04:00) Santiago
|
||||
(GMT -03:30) Newfoundland
|
||||
(GMT -03:00) Brasilia
|
||||
(GMT -03:00) Buenos Aires
|
||||
(GMT -03:00) Georgetown
|
||||
(GMT -03:00) Greenland
|
||||
(GMT -03:00) Montevideo
|
||||
(GMT -02:00) Mid-Atlantic
|
||||
(GMT -01:00) Azores
|
||||
(GMT -01:00) Cape Verde Is.
|
||||
(GMT +00:00) Casablanca
|
||||
(GMT +00:00) Greenwich Mean Time: Dublin, Edinburgh, Lisbon, London
|
||||
(GMT +00:00) Monrovia, Reykjavik
|
||||
(GMT +01:00) Amsterdam, Berlin, Bern, Rome, Stockholm, Vienna
|
||||
(GMT +01:00) Belgrade, Bratislava, Budapest, Ljubljana, Prague
|
||||
(GMT +01:00) Brussels, Copenhagen, Madrid, Paris
|
||||
(GMT +01:00) Sarajevo, Skopje, Warsaw, Zagreb
|
||||
(GMT +01:00) West Central Africa
|
||||
(GMT +02:00) Amman
|
||||
(GMT +02:00) Athens, Bucharest, Istanbul
|
||||
(GMT +02:00) Beirut
|
||||
(GMT +02:00) Cairo
|
||||
(GMT +02:00) Harare, Pretoria
|
||||
(GMT +02:00) Helsinki, Kyiv, Riga, Sofia, Tallinn, Vilnius
|
||||
(GMT +02:00) Jerusalem
|
||||
(GMT +02:00) Minsk
|
||||
(GMT +02:00) Windhoek
|
||||
(GMT +03:00) Baghdad
|
||||
(GMT +03:00) Kuwait, Riyadh
|
||||
(GMT +03:00) Moscow, St. Petersburg, Volgograd
|
||||
(GMT +03:00) Nairobi
|
||||
(GMT +03:00) Tbilisi
|
||||
(GMT +03:30) Tehran
|
||||
(GMT +04:00) Abu Dhabi, Muscat
|
||||
(GMT +04:00) Baku
|
||||
(GMT +04:00) Port Louis
|
||||
(GMT +04:00) Yerevan
|
||||
(GMT +04:30) Kabul
|
||||
(GMT +05:00) Ekaterinburg
|
||||
(GMT +05:00) Islamabad, Karachi
|
||||
(GMT +05:00) Tashkent
|
||||
(GMT +05:30) Chennai, Kolkata, Mumbai, New Delhi
|
||||
(GMT +05:30) Sri Jayawardenepura
|
||||
(GMT +05:45) Kathmandu
|
||||
(GMT +06:00) Almaty, Novosibirsk
|
||||
(GMT +06:00) Astana, Dhaka
|
||||
(GMT +06:30) Yangon (Rangoon)
|
||||
(GMT +07:00) Bangkok, Hanoi, Jakarta
|
||||
(GMT +07:00) Krasnoyarsk
|
||||
(GMT +08:00) Beijing, Chongqing, Hong Kong, Urumqi
|
||||
(GMT +08:00) Irkutsk, Ulaan Bataar
|
||||
(GMT +08:00) Kuala Lumpur, Singapore
|
||||
(GMT +08:00) Perth
|
||||
(GMT +08:00) Taipei
|
||||
(GMT +09:00) Osaka, Sapporo, Tokyo
|
||||
(GMT +09:00) Seoul
|
||||
(GMT +09:00) Yakutsk
|
||||
(GMT +09:30) Adelaide
|
||||
(GMT +09:30) Darwin
|
||||
(GMT +10:00) Brisbane
|
||||
(GMT +10:00) Canberra, Melbourne, Sydney
|
||||
(GMT +10:00) Guam, Port Moresby
|
||||
(GMT +10:00) Hobart, Vladivostok
|
||||
(GMT +11:00) Magadan, Solomon Is., New Caledonia
|
||||
(GMT +12:00) Auckland, Wellington
|
||||
(GMT +12:00) Fiji, Kamchatka, Marshall Is.
|
||||
(GMT +13:00) Nuku'alofa
|
||||
*/
|
||||
|
||||
FREERDP_API uint32 detect_keyboard_layout_from_locale(void);
|
||||
|
||||
#endif /* __LOCALES_H */
|
||||
|
@ -31,4 +31,6 @@ FREERDP_API char* xstrdup(const char* str);
|
||||
|
||||
#define xnew(_type) (_type*)xzalloc(sizeof(_type))
|
||||
|
||||
#define ARRAY_SIZE(_x) (sizeof(_x)/sizeof(*(_x)))
|
||||
|
||||
#endif /* __MEMORY_UTILS_H */
|
||||
|
36
include/freerdp/utils/time.h
Normal file
36
include/freerdp/utils/time.h
Normal file
@ -0,0 +1,36 @@
|
||||
/**
|
||||
* FreeRDP: A Remote Desktop Protocol Client
|
||||
* Time Utils
|
||||
*
|
||||
* 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_TIME_UTILS_H
|
||||
#define FREERDP_TIME_UTILS_H
|
||||
|
||||
#include <time.h>
|
||||
|
||||
#ifndef _WIN32
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include <freerdp/api.h>
|
||||
#include <freerdp/types.h>
|
||||
|
||||
FREERDP_API uint64 rdp_windows_gmtime();
|
||||
FREERDP_API uint64 rdp_get_windows_time_from_unix_time(time_t unix_time);
|
||||
FREERDP_API time_t rdp_get_unix_time_from_windows_time(uint64 windows_time);
|
||||
|
||||
#endif /* FREERDP_TIME_UTILS_H */
|
@ -63,6 +63,8 @@ set(LIBFREERDP_CORE_SRCS
|
||||
connection.h
|
||||
redirection.c
|
||||
redirection.h
|
||||
timezone.c
|
||||
timezone.h
|
||||
rdp.c
|
||||
rdp.h
|
||||
per.c
|
||||
|
@ -17,6 +17,8 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "timezone.h"
|
||||
|
||||
#include "info.h"
|
||||
|
||||
#define INFO_TYPE_LOGON 0x00000000
|
||||
@ -34,182 +36,6 @@ static const char* const INFO_TYPE_LOGON_STRINGS[] =
|
||||
};
|
||||
*/
|
||||
|
||||
/**
|
||||
* Read SYSTEM_TIME structure (TS_SYSTEMTIME).\n
|
||||
* @msdn{cc240478}
|
||||
* @param s stream
|
||||
* @param system_time system time structure
|
||||
*/
|
||||
|
||||
void rdp_read_system_time(STREAM* s, SYSTEM_TIME* system_time)
|
||||
{
|
||||
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 */
|
||||
}
|
||||
|
||||
/**
|
||||
* Write SYSTEM_TIME structure (TS_SYSTEMTIME).\n
|
||||
* @msdn{cc240478}
|
||||
* @param s stream
|
||||
* @param system_time system time structure
|
||||
*/
|
||||
|
||||
void rdp_write_system_time(STREAM* s, SYSTEM_TIME* system_time)
|
||||
{
|
||||
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 */
|
||||
}
|
||||
|
||||
/**
|
||||
* Get client time zone information.\n
|
||||
* @param s stream
|
||||
* @param settings settings
|
||||
*/
|
||||
|
||||
void rdp_get_client_time_zone(STREAM* s, rdpSettings* settings)
|
||||
{
|
||||
time_t t;
|
||||
struct tm* local_time;
|
||||
TIME_ZONE_INFO* clientTimeZone;
|
||||
|
||||
time(&t);
|
||||
local_time = localtime(&t);
|
||||
clientTimeZone = settings->client_time_zone;
|
||||
|
||||
#if defined(sun)
|
||||
if(local_time->tm_isdst > 0)
|
||||
clientTimeZone->bias = (uint32) (altzone / 3600);
|
||||
else
|
||||
clientTimeZone->bias = (uint32) (timezone / 3600);
|
||||
#elif defined(HAVE_TM_GMTOFF)
|
||||
if(local_time->tm_gmtoff >= 0)
|
||||
clientTimeZone->bias = (uint32) (local_time->tm_gmtoff / 60);
|
||||
else
|
||||
clientTimeZone->bias = (uint32) ((-1 * local_time->tm_gmtoff) / 60 + 720);
|
||||
#else
|
||||
clientTimeZone->bias = 0;
|
||||
#endif
|
||||
|
||||
if(local_time->tm_isdst > 0)
|
||||
{
|
||||
clientTimeZone->standardBias = clientTimeZone->bias - 60;
|
||||
clientTimeZone->daylightBias = clientTimeZone->bias;
|
||||
}
|
||||
else
|
||||
{
|
||||
clientTimeZone->standardBias = clientTimeZone->bias;
|
||||
clientTimeZone->daylightBias = clientTimeZone->bias + 60;
|
||||
}
|
||||
|
||||
strftime(clientTimeZone->standardName, 32, "%Z, Standard Time", local_time);
|
||||
clientTimeZone->standardName[31] = 0;
|
||||
strftime(clientTimeZone->daylightName, 32, "%Z, Summer Time", local_time);
|
||||
clientTimeZone->daylightName[31] = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read client time zone information (TS_TIME_ZONE_INFORMATION).\n
|
||||
* @msdn{cc240477}
|
||||
* @param s stream
|
||||
* @param settings settings
|
||||
*/
|
||||
|
||||
boolean rdp_read_client_time_zone(STREAM* s, rdpSettings* settings)
|
||||
{
|
||||
char* str;
|
||||
TIME_ZONE_INFO* clientTimeZone;
|
||||
|
||||
if (stream_get_left(s) < 172)
|
||||
return false;
|
||||
|
||||
clientTimeZone = settings->client_time_zone;
|
||||
|
||||
stream_read_uint32(s, clientTimeZone->bias); /* Bias */
|
||||
|
||||
/* standardName (64 bytes) */
|
||||
str = freerdp_uniconv_in(settings->uniconv, stream_get_tail(s), 64);
|
||||
stream_seek(s, 64);
|
||||
strncpy(clientTimeZone->standardName, str, sizeof(clientTimeZone->standardName));
|
||||
xfree(str);
|
||||
|
||||
rdp_read_system_time(s, &clientTimeZone->standardDate); /* StandardDate */
|
||||
stream_read_uint32(s, clientTimeZone->standardBias); /* StandardBias */
|
||||
|
||||
/* daylightName (64 bytes) */
|
||||
str = freerdp_uniconv_in(settings->uniconv, stream_get_tail(s), 64);
|
||||
stream_seek(s, 64);
|
||||
strncpy(clientTimeZone->daylightName, str, sizeof(clientTimeZone->daylightName));
|
||||
xfree(str);
|
||||
|
||||
rdp_read_system_time(s, &clientTimeZone->daylightDate); /* DaylightDate */
|
||||
stream_read_uint32(s, clientTimeZone->daylightBias); /* DaylightBias */
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write client time zone information (TS_TIME_ZONE_INFORMATION).\n
|
||||
* @msdn{cc240477}
|
||||
* @param s stream
|
||||
* @param settings settings
|
||||
*/
|
||||
|
||||
void rdp_write_client_time_zone(STREAM* s, rdpSettings* settings)
|
||||
{
|
||||
size_t length;
|
||||
uint8* standardName;
|
||||
uint8* daylightName;
|
||||
size_t standardNameLength;
|
||||
size_t daylightNameLength;
|
||||
TIME_ZONE_INFO* clientTimeZone;
|
||||
|
||||
rdp_get_client_time_zone(s, settings);
|
||||
clientTimeZone = settings->client_time_zone;
|
||||
|
||||
standardName = (uint8*) freerdp_uniconv_out(settings->uniconv, clientTimeZone->standardName, &length);
|
||||
standardNameLength = length;
|
||||
|
||||
daylightName = (uint8*) freerdp_uniconv_out(settings->uniconv, clientTimeZone->daylightName, &length);
|
||||
daylightNameLength = length;
|
||||
|
||||
if (standardNameLength > 62)
|
||||
standardNameLength = 62;
|
||||
|
||||
if (daylightNameLength > 62)
|
||||
daylightNameLength = 62;
|
||||
|
||||
stream_write_uint32(s, clientTimeZone->bias); /* Bias */
|
||||
|
||||
/* standardName (64 bytes) */
|
||||
stream_write(s, standardName, standardNameLength);
|
||||
stream_write_zero(s, 64 - standardNameLength);
|
||||
|
||||
rdp_write_system_time(s, &clientTimeZone->standardDate); /* StandardDate */
|
||||
stream_write_uint32(s, clientTimeZone->standardBias); /* StandardBias */
|
||||
|
||||
/* daylightName (64 bytes) */
|
||||
stream_write(s, daylightName, daylightNameLength);
|
||||
stream_write_zero(s, 64 - daylightNameLength);
|
||||
|
||||
rdp_write_system_time(s, &clientTimeZone->daylightDate); /* DaylightDate */
|
||||
stream_write_uint32(s, clientTimeZone->daylightBias); /* DaylightBias */
|
||||
|
||||
xfree(standardName);
|
||||
xfree(daylightName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read Server Auto Reconnect Cookie (ARC_SC_PRIVATE_PACKET).\n
|
||||
* @msdn{cc240540}
|
||||
|
1868
libfreerdp-core/timezone.c
Normal file
1868
libfreerdp-core/timezone.c
Normal file
File diff suppressed because it is too large
Load Diff
42
libfreerdp-core/timezone.h
Normal file
42
libfreerdp-core/timezone.h
Normal file
@ -0,0 +1,42 @@
|
||||
/**
|
||||
* FreeRDP: A Remote Desktop Protocol Client
|
||||
* 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 __TIMEZONE_H
|
||||
#define __TIMEZONE_H
|
||||
|
||||
#include "rdp.h"
|
||||
#include "config.h"
|
||||
|
||||
#include <freerdp/freerdp.h>
|
||||
#include <freerdp/utils/stream.h>
|
||||
#include <freerdp/utils/time.h>
|
||||
|
||||
void rdp_read_system_time(STREAM* s, SYSTEM_TIME* system_time);
|
||||
void rdp_write_system_time(STREAM* s, SYSTEM_TIME* system_time);
|
||||
void rdp_get_client_time_zone(STREAM* s, rdpSettings* settings);
|
||||
boolean rdp_read_client_time_zone(STREAM* s, rdpSettings* settings);
|
||||
void rdp_write_client_time_zone(STREAM* s, rdpSettings* settings);
|
||||
|
||||
#ifdef WITH_DEBUG_TIMEZONE
|
||||
#define DEBUG_TIMEZONE(fmt, ...) DEBUG_CLASS(TIMEZONE, fmt, ## __VA_ARGS__)
|
||||
#else
|
||||
#define DEBUG_TIMEZONE(fmt, ...) DEBUG_NULL(fmt, ## __VA_ARGS__)
|
||||
#endif
|
||||
|
||||
#endif /* __TIMEZONE_H */
|
@ -46,6 +46,7 @@ set(FREERDP_UTILS_SRCS
|
||||
string.c
|
||||
svc_plugin.c
|
||||
thread.c
|
||||
time.c
|
||||
unicode.c
|
||||
wait_obj.c)
|
||||
|
||||
|
45
libfreerdp-utils/time.c
Normal file
45
libfreerdp-utils/time.c
Normal file
@ -0,0 +1,45 @@
|
||||
/**
|
||||
* FreeRDP: A Remote Desktop Protocol Client
|
||||
* Time Utils
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <freerdp/utils/time.h>
|
||||
|
||||
uint64 rdp_windows_gmtime()
|
||||
{
|
||||
time_t unix_time;
|
||||
uint64 windows_time;
|
||||
|
||||
time(&unix_time);
|
||||
windows_time = rdp_get_windows_time_from_unix_time(unix_time);
|
||||
|
||||
return windows_time;
|
||||
}
|
||||
|
||||
uint64 rdp_get_windows_time_from_unix_time(time_t unix_time)
|
||||
{
|
||||
uint64 windows_time;
|
||||
windows_time = ((uint64)unix_time * 10000000) + 621355968000000000ULL;
|
||||
return windows_time;
|
||||
}
|
||||
|
||||
time_t rdp_get_unix_time_from_windows_time(uint64 windows_time)
|
||||
{
|
||||
time_t unix_time;
|
||||
unix_time = (windows_time - 621355968000000000ULL) / 10000000;
|
||||
return unix_time;
|
||||
}
|
247
scripts/TimeZones.cs
Normal file
247
scripts/TimeZones.cs
Normal file
@ -0,0 +1,247 @@
|
||||
/**
|
||||
* FreeRDP: A Remote Desktop Protocol Client
|
||||
* Time Zone Redirection Table Generator
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Globalization;
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
namespace TimeZones
|
||||
{
|
||||
struct SYSTEM_TIME_ENTRY
|
||||
{
|
||||
public UInt16 wYear;
|
||||
public UInt16 wMonth;
|
||||
public UInt16 wDayOfWeek;
|
||||
public UInt16 wDay;
|
||||
public UInt16 wHour;
|
||||
public UInt16 wMinute;
|
||||
public UInt16 wSecond;
|
||||
public UInt16 wMilliseconds;
|
||||
};
|
||||
|
||||
struct TIME_ZONE_RULE_ENTRY
|
||||
{
|
||||
public long TicksStart;
|
||||
public long TicksEnd;
|
||||
public Int32 DaylightDelta;
|
||||
public SYSTEM_TIME_ENTRY StandardDate;
|
||||
public SYSTEM_TIME_ENTRY DaylightDate;
|
||||
};
|
||||
|
||||
struct TIME_ZONE_ENTRY
|
||||
{
|
||||
public string Id;
|
||||
public UInt32 Bias;
|
||||
public bool SupportsDST;
|
||||
public string DisplayName;
|
||||
public string StandardName;
|
||||
public string DaylightName;
|
||||
public string RuleTable;
|
||||
public UInt32 RuleTableCount;
|
||||
};
|
||||
|
||||
class TimeZones
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
int i;
|
||||
UInt32 index;
|
||||
const string file = @"TimeZones.txt";
|
||||
TimeZoneInfo.AdjustmentRule[] rules;
|
||||
StreamWriter stream = new StreamWriter(file, false);
|
||||
ReadOnlyCollection<TimeZoneInfo> timeZones = TimeZoneInfo.GetSystemTimeZones();
|
||||
|
||||
stream.WriteLine();
|
||||
|
||||
stream.WriteLine("struct _SYSTEM_TIME_ENTRY");
|
||||
stream.WriteLine("{");
|
||||
stream.WriteLine("\tuint16 wYear;");
|
||||
stream.WriteLine("\tuint16 wMonth;");
|
||||
stream.WriteLine("\tuint16 wDayOfWeek;");
|
||||
stream.WriteLine("\tuint16 wDay;");
|
||||
stream.WriteLine("\tuint16 wHour;");
|
||||
stream.WriteLine("\tuint16 wMinute;");
|
||||
stream.WriteLine("\tuint16 wSecond;");
|
||||
stream.WriteLine("\tuint16 wMilliseconds;");
|
||||
stream.WriteLine("};");
|
||||
stream.WriteLine("typedef struct _SYSTEM_TIME_ENTRY SYSTEM_TIME_ENTRY;");
|
||||
stream.WriteLine();
|
||||
|
||||
stream.WriteLine("struct _TIME_ZONE_RULE_ENTRY");
|
||||
stream.WriteLine("{");
|
||||
stream.WriteLine("\tuint64 TicksStart;");
|
||||
stream.WriteLine("\tuint64 TicksEnd;");
|
||||
stream.WriteLine("\tsint32 DaylightDelta;");
|
||||
stream.WriteLine("\tSYSTEM_TIME_ENTRY StandardDate;");
|
||||
stream.WriteLine("\tSYSTEM_TIME_ENTRY DaylightDate;");
|
||||
stream.WriteLine("};");
|
||||
stream.WriteLine("typedef struct _TIME_ZONE_RULE_ENTRY TIME_ZONE_RULE_ENTRY;");
|
||||
stream.WriteLine();
|
||||
|
||||
stream.WriteLine("struct _TIME_ZONE_ENTRY");
|
||||
stream.WriteLine("{");
|
||||
stream.WriteLine("\tconst char* Id;");
|
||||
stream.WriteLine("\tuint32 Bias;");
|
||||
stream.WriteLine("\tboolean SupportsDST;");
|
||||
stream.WriteLine("\tconst char* DisplayName;");
|
||||
stream.WriteLine("\tconst char* StandardName;");
|
||||
stream.WriteLine("\tconst char* DaylightName;");
|
||||
stream.WriteLine("\tTIME_ZONE_RULE_ENTRY* RuleTable;");
|
||||
stream.WriteLine("\tuint32 RuleTableCount;");
|
||||
stream.WriteLine("};");
|
||||
stream.WriteLine("typedef struct _TIME_ZONE_ENTRY TIME_ZONE_ENTRY;");
|
||||
stream.WriteLine();
|
||||
|
||||
index = 0;
|
||||
|
||||
foreach (TimeZoneInfo timeZone in timeZones)
|
||||
{
|
||||
rules = timeZone.GetAdjustmentRules();
|
||||
|
||||
if ((!timeZone.SupportsDaylightSavingTime) || (rules.Length < 1))
|
||||
{
|
||||
index++;
|
||||
continue;
|
||||
}
|
||||
|
||||
stream.WriteLine("static const TIME_ZONE_RULE_ENTRY TimeZoneRuleTable_{0}[] =", index);
|
||||
stream.WriteLine("{");
|
||||
|
||||
i = 0;
|
||||
foreach (TimeZoneInfo.AdjustmentRule rule in rules)
|
||||
{
|
||||
DateTime time;
|
||||
TIME_ZONE_RULE_ENTRY tzr;
|
||||
TimeZoneInfo.TransitionTime transition;
|
||||
|
||||
tzr.TicksStart = rule.DateEnd.ToUniversalTime().Ticks;
|
||||
tzr.TicksEnd = rule.DateStart.ToUniversalTime().Ticks;
|
||||
tzr.DaylightDelta = (Int32)rule.DaylightDelta.TotalMinutes;
|
||||
|
||||
transition = rule.DaylightTransitionEnd;
|
||||
time = transition.TimeOfDay;
|
||||
|
||||
tzr.StandardDate.wYear = (UInt16)0;
|
||||
tzr.StandardDate.wMonth = (UInt16)transition.Month;
|
||||
tzr.StandardDate.wDayOfWeek = (UInt16)transition.DayOfWeek;
|
||||
tzr.StandardDate.wDay = (UInt16)transition.Day;
|
||||
tzr.StandardDate.wHour = (UInt16)time.Hour;
|
||||
tzr.StandardDate.wMinute = (UInt16)time.Minute;
|
||||
tzr.StandardDate.wSecond = (UInt16)time.Second;
|
||||
tzr.StandardDate.wMilliseconds = (UInt16)time.Millisecond;
|
||||
|
||||
transition = rule.DaylightTransitionStart;
|
||||
time = transition.TimeOfDay;
|
||||
|
||||
tzr.DaylightDate.wYear = (UInt16)0;
|
||||
tzr.DaylightDate.wMonth = (UInt16)transition.Month;
|
||||
tzr.DaylightDate.wDayOfWeek = (UInt16)transition.DayOfWeek;
|
||||
tzr.DaylightDate.wDay = (UInt16)transition.Day;
|
||||
tzr.DaylightDate.wHour = (UInt16)time.Hour;
|
||||
tzr.DaylightDate.wMinute = (UInt16)time.Minute;
|
||||
tzr.DaylightDate.wSecond = (UInt16)time.Second;
|
||||
tzr.DaylightDate.wMilliseconds = (UInt16)time.Millisecond;
|
||||
|
||||
stream.Write("\t{");
|
||||
stream.Write(" {0}, {1}, {2},", tzr.TicksStart, tzr.TicksEnd, tzr.DaylightDelta);
|
||||
|
||||
stream.Write(" { ");
|
||||
stream.Write("{0}, {1}, {2}, {3}, {4}, {5}",
|
||||
tzr.StandardDate.wYear, tzr.StandardDate.wMonth, tzr.StandardDate.wDayOfWeek,
|
||||
tzr.StandardDate.wDay, tzr.StandardDate.wHour, tzr.StandardDate.wMinute,
|
||||
tzr.StandardDate.wSecond, tzr.StandardDate.wMilliseconds);
|
||||
stream.Write(" }, ");
|
||||
|
||||
stream.Write("{ ");
|
||||
stream.Write("{0}, {1}, {2}, {3}, {4}, {5}",
|
||||
tzr.DaylightDate.wYear, tzr.DaylightDate.wMonth, tzr.DaylightDate.wDayOfWeek,
|
||||
tzr.DaylightDate.wDay, tzr.DaylightDate.wHour, tzr.DaylightDate.wMinute,
|
||||
tzr.DaylightDate.wSecond, tzr.DaylightDate.wMilliseconds);
|
||||
stream.Write(" },");
|
||||
|
||||
if (++i < rules.Length)
|
||||
stream.WriteLine(" },");
|
||||
else
|
||||
stream.WriteLine(" }");
|
||||
}
|
||||
|
||||
stream.WriteLine("};");
|
||||
stream.WriteLine();
|
||||
index++;
|
||||
}
|
||||
|
||||
index = 0;
|
||||
stream.WriteLine("static const TIME_ZONE_ENTRY TimeZoneTable[] =");
|
||||
stream.WriteLine("{");
|
||||
|
||||
foreach (TimeZoneInfo timeZone in timeZones)
|
||||
{
|
||||
TIME_ZONE_ENTRY tz;
|
||||
TimeSpan offset = timeZone.BaseUtcOffset;
|
||||
|
||||
rules = timeZone.GetAdjustmentRules();
|
||||
|
||||
tz.Id = timeZone.Id;
|
||||
|
||||
if (offset.Hours >= 0)
|
||||
tz.Bias = (UInt32)((offset.Hours * 60) + offset.Minutes);
|
||||
else
|
||||
tz.Bias = (UInt32)(((-1 * offset.Hours) * 60) + offset.Minutes + 720);
|
||||
|
||||
tz.SupportsDST = timeZone.SupportsDaylightSavingTime;
|
||||
|
||||
tz.DisplayName = timeZone.DisplayName;
|
||||
tz.StandardName = timeZone.StandardName;
|
||||
tz.DaylightName = timeZone.DaylightName;
|
||||
|
||||
if ((!tz.SupportsDST) || (rules.Length < 1))
|
||||
{
|
||||
tz.RuleTableCount = 0;
|
||||
tz.RuleTable = "NULL";
|
||||
}
|
||||
else
|
||||
{
|
||||
tz.RuleTableCount = (UInt32)rules.Length;
|
||||
tz.RuleTable = "&TimeZoneRuleTable_" + index;
|
||||
tz.RuleTable = "(TIME_ZONE_RULE_ENTRY*) &TimeZoneRuleTable_" + index;
|
||||
}
|
||||
|
||||
stream.WriteLine("\t{");
|
||||
|
||||
stream.WriteLine("\t\t\"{0}\", {1}, {2}, \"{0}\",",
|
||||
tz.Id, tz.Bias, tz.SupportsDST ? "true" : "false", tz.DisplayName);
|
||||
|
||||
stream.WriteLine("\t\t\"{0}\", \"{0}\",", tz.StandardName, tz.DaylightName);
|
||||
stream.WriteLine("\t\t{0}, {1}", tz.RuleTable, tz.RuleTableCount);
|
||||
|
||||
index++;
|
||||
|
||||
if ((int) index < timeZones.Count)
|
||||
stream.WriteLine("\t},");
|
||||
else
|
||||
stream.WriteLine("\t}");
|
||||
}
|
||||
stream.WriteLine("};");
|
||||
stream.WriteLine();
|
||||
|
||||
stream.Close();
|
||||
}
|
||||
}
|
||||
}
|
90
scripts/WindowsZones.cs
Normal file
90
scripts/WindowsZones.cs
Normal file
@ -0,0 +1,90 @@
|
||||
/**
|
||||
* FreeRDP: A Remote Desktop Protocol Client
|
||||
* TZID to Windows TimeZone Identifier Table Generator
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Xml;
|
||||
using System.Text;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
/*
|
||||
* this script uses windowsZones.xml which can be obtained at:
|
||||
* http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/zone_tzid.html
|
||||
*/
|
||||
|
||||
namespace WindowsZones
|
||||
{
|
||||
class MainClass
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
string tzid, windows;
|
||||
const string file = @"WindowsZones.txt";
|
||||
List<string> list = new List<string>();
|
||||
StreamWriter stream = new StreamWriter(file, false);
|
||||
XmlTextReader reader = new XmlTextReader(@"windowsZones.xml");
|
||||
|
||||
stream.WriteLine("struct _WINDOWS_TZID_ENTRY");
|
||||
stream.WriteLine("{");
|
||||
stream.WriteLine("\tconst char* windows;");
|
||||
stream.WriteLine("\tconst char* tzid;");
|
||||
stream.WriteLine("};");
|
||||
stream.WriteLine("typedef struct _WINDOWS_TZID_ENTRY WINDOWS_TZID_ENTRY;");
|
||||
stream.WriteLine();
|
||||
|
||||
while (reader.Read())
|
||||
{
|
||||
switch (reader.NodeType)
|
||||
{
|
||||
case XmlNodeType.Element:
|
||||
|
||||
if (reader.Name.Equals("mapZone"))
|
||||
{
|
||||
tzid = reader.GetAttribute("type");
|
||||
windows = reader.GetAttribute("other");
|
||||
|
||||
string entry = String.Format("\"{0}\", \"{1}\"", windows, tzid);
|
||||
|
||||
if (!list.Contains(entry))
|
||||
list.Add(entry);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
list.Sort();
|
||||
|
||||
stream.WriteLine("const WINDOWS_TZID_ENTRY WindowsTimeZoneIdTable[] =");
|
||||
stream.WriteLine("{");
|
||||
|
||||
foreach (string entry in list)
|
||||
{
|
||||
stream.Write("\t{ ");
|
||||
stream.Write(entry);
|
||||
stream.WriteLine(" },");
|
||||
}
|
||||
|
||||
stream.WriteLine("};");
|
||||
|
||||
stream.Close();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user