20 #include <freerdp/config.h>
22 #include <winpr/crt.h>
23 #include <winpr/assert.h>
24 #include <winpr/timezone.h>
29 #include <freerdp/log.h>
30 #define TAG FREERDP_TAG("core.timezone")
32 #if !defined(WITH_DEBUG_TIMEZONE)
33 #define log_timezone(tzif, result)
35 #define log_timezone(tzif, result) log_timezone_((tzif), (result), __FILE__, __func__, __LINE__)
36 static const char* weekday2str(WORD wDayOfWeek)
55 return "DAY-OF-MAGIC";
59 static char* systemtime2str(
const SYSTEMTIME* t,
char* buffer,
size_t len)
61 const SYSTEMTIME empty = { 0 };
63 if (memcmp(t, &empty,
sizeof(SYSTEMTIME)) == 0)
64 _snprintf(buffer, len,
"{ not set }");
67 _snprintf(buffer, len,
68 "{ %" PRIu16
"-%" PRIu16
"-%" PRIu16
" [%s] %" PRIu16
":%" PRIu16
":%" PRIu16
70 t->wYear, t->wMonth, t->wDay, weekday2str(t->wDayOfWeek), t->wHour, t->wMinute,
71 t->wSecond, t->wMilliseconds);
76 static void log_print(wLog* log, DWORD level,
const char* file,
const char* fkt,
size_t line, ...)
78 if (!WLog_IsLevelActive(log, level))
83 WLog_PrintMessageVA(log, WLOG_MESSAGE_TEXT, level, line, file, fkt, ap);
88 const char* fkt,
size_t line)
92 char buffer[64] = { 0 };
93 DWORD level = WLOG_TRACE;
94 wLog* log = WLog_Get(TIMEZONE_TAG);
95 log_print(log, level, file, fkt, line,
"TIME_ZONE_INFORMATION {");
96 log_print(log, level, file, fkt, line,
" Bias=%" PRIu32, tzif->Bias);
97 (void)ConvertWCharNToUtf8(tzif->StandardName, ARRAYSIZE(tzif->StandardName), buffer,
99 log_print(log, level, file, fkt, line,
" StandardName=%s", buffer);
100 log_print(log, level, file, fkt, line,
" StandardDate=%s",
101 systemtime2str(&tzif->StandardDate, buffer,
sizeof(buffer)));
102 log_print(log, level, file, fkt, line,
" StandardBias=%" PRIu32, tzif->StandardBias);
104 (void)ConvertWCharNToUtf8(tzif->DaylightName, ARRAYSIZE(tzif->DaylightName), buffer,
106 log_print(log, level, file, fkt, line,
" DaylightName=%s", buffer);
107 log_print(log, level, file, fkt, line,
" DaylightDate=%s",
108 systemtime2str(&tzif->DaylightDate, buffer,
sizeof(buffer)));
109 log_print(log, level, file, fkt, line,
" DaylightBias=%" PRIu32, tzif->DaylightBias);
113 case TIME_ZONE_ID_DAYLIGHT:
114 log_print(log, level, file, fkt, line,
" DaylightDate in use");
116 case TIME_ZONE_ID_STANDARD:
117 log_print(log, level, file, fkt, line,
" StandardDate in use");
120 log_print(log, level, file, fkt, line,
" UnknownDate in use");
123 log_print(log, level, file, fkt, line,
"}");
127 static BOOL rdp_read_system_time(
wStream* s, SYSTEMTIME* system_time);
128 static BOOL rdp_write_system_time(
wStream* s,
const SYSTEMTIME* system_time);
137 BOOL rdp_read_system_time(
wStream* s, SYSTEMTIME* system_time)
139 WINPR_ASSERT(system_time);
141 if (!Stream_CheckAndLogRequiredLength(TAG, s, 16ull))
144 Stream_Read_UINT16(s, system_time->wYear);
145 Stream_Read_UINT16(s, system_time->wMonth);
146 Stream_Read_UINT16(s, system_time->wDayOfWeek);
147 Stream_Read_UINT16(s, system_time->wDay);
148 Stream_Read_UINT16(s, system_time->wHour);
149 Stream_Read_UINT16(s, system_time->wMinute);
150 Stream_Read_UINT16(s, system_time->wSecond);
151 Stream_Read_UINT16(s, system_time->wMilliseconds);
162 BOOL rdp_write_system_time(
wStream* s,
const SYSTEMTIME* system_time)
164 WINPR_ASSERT(system_time);
165 if (!Stream_EnsureRemainingCapacity(s, 16ull))
168 Stream_Write_UINT16(s, system_time->wYear);
169 Stream_Write_UINT16(s, system_time->wMonth);
170 Stream_Write_UINT16(s, system_time->wDayOfWeek);
171 Stream_Write_UINT16(s, system_time->wDay);
172 Stream_Write_UINT16(s, system_time->wHour);
173 Stream_Write_UINT16(s, system_time->wMinute);
174 Stream_Write_UINT16(s, system_time->wSecond);
175 Stream_Write_UINT16(s, system_time->wMilliseconds);
188 BOOL rdp_read_client_time_zone(
wStream* s, rdpSettings* settings)
195 if (!Stream_CheckAndLogRequiredLength(TAG, s, 172))
198 tz = settings->ClientTimeZone;
203 Stream_Read_UINT32(s, tz->Bias);
205 Stream_Read(s, tz->StandardName,
sizeof(tz->StandardName));
206 if (!rdp_read_system_time(s, &tz->StandardDate))
208 Stream_Read_UINT32(s, tz->StandardBias);
210 Stream_Read(s, tz->DaylightName,
sizeof(tz->DaylightName));
211 if (!rdp_read_system_time(s, &tz->DaylightDate))
213 Stream_Read_UINT32(s, tz->DaylightBias);
227 BOOL rdp_write_client_time_zone(
wStream* s, rdpSettings* settings)
229 WINPR_ASSERT(settings);
236 if (!Stream_EnsureRemainingCapacity(s, 4ull +
sizeof(tz->StandardName)))
244 Stream_Write_INT32(s, tz->Bias);
246 Stream_Write(s, tz->StandardName,
sizeof(tz->StandardName));
248 if (!rdp_write_system_time(s, &tz->StandardDate))
253 if (!Stream_EnsureRemainingCapacity(s, 4ull +
sizeof(tz->DaylightName)))
261 Stream_Write_INT32(s, tz->StandardBias);
264 Stream_Write(s, tz->DaylightName,
sizeof(tz->DaylightName));
266 if (!rdp_write_system_time(s, &tz->DaylightDate))
270 if (!Stream_EnsureRemainingCapacity(s, 4ull))
278 Stream_Write_INT32(s, tz->DaylightBias);