20#include <freerdp/config.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__)
36static const char* weekday2str(WORD wDayOfWeek)
55 return "DAY-OF-MAGIC";
59static char* systemtime2str(
const SYSTEMTIME* t,
char* buffer,
size_t len)
63 if (memcmp(t, &empty,
sizeof(
SYSTEMTIME)) == 0)
64 (void)_snprintf(buffer, len,
"{ not set }");
67 (void)_snprintf(buffer, len,
68 "{ %" PRIu16
"-%" PRIu16
"-%" PRIu16
" [%s] %" PRIu16
":%" PRIu16
69 ":%" PRIu16
".%" PRIu16
"}",
70 t->wYear, t->wMonth, t->wDay, weekday2str(t->wDayOfWeek), t->wHour,
71 t->wMinute, t->wSecond, t->wMilliseconds);
76WINPR_ATTR_FORMAT_ARG(6, 7)
77static
void log_print(wLog* log, DWORD level, const
char* file, const
char* fkt,
size_t line,
78 WINPR_FORMAT_ARG const
char* fmt, ...)
80 if (!WLog_IsLevelActive(log, level))
85 WLog_PrintTextMessageVA(log, level, line, file, fkt, fmt, ap);
90 const char* fkt,
size_t line)
94 char buffer[64] = { 0 };
95 DWORD level = WLOG_TRACE;
96 wLog* log = WLog_Get(TIMEZONE_TAG);
97 log_print(log, level, file, fkt, line,
"TIME_ZONE_INFORMATION {");
98 log_print(log, level, file, fkt, line,
" Bias=%" PRId32, tzif->Bias);
99 (void)ConvertWCharNToUtf8(tzif->StandardName, ARRAYSIZE(tzif->StandardName), buffer,
101 log_print(log, level, file, fkt, line,
" StandardName=%s", buffer);
102 log_print(log, level, file, fkt, line,
" StandardDate=%s",
103 systemtime2str(&tzif->StandardDate, buffer,
sizeof(buffer)));
104 log_print(log, level, file, fkt, line,
" StandardBias=%" PRId32, tzif->StandardBias);
106 (void)ConvertWCharNToUtf8(tzif->DaylightName, ARRAYSIZE(tzif->DaylightName), buffer,
108 log_print(log, level, file, fkt, line,
" DaylightName=%s", buffer);
109 log_print(log, level, file, fkt, line,
" DaylightDate=%s",
110 systemtime2str(&tzif->DaylightDate, buffer,
sizeof(buffer)));
111 log_print(log, level, file, fkt, line,
" DaylightBias=%" PRId32, tzif->DaylightBias);
115 case TIME_ZONE_ID_DAYLIGHT:
116 log_print(log, level, file, fkt, line,
" DaylightDate in use");
118 case TIME_ZONE_ID_STANDARD:
119 log_print(log, level, file, fkt, line,
" StandardDate in use");
122 log_print(log, level, file, fkt, line,
" UnknownDate in use");
125 log_print(log, level, file, fkt, line,
"}");
141 WINPR_ASSERT(system_time);
143 if (!Stream_CheckAndLogRequiredLength(TAG, s, 16ull))
146 Stream_Read_UINT16(s, system_time->wYear);
147 Stream_Read_UINT16(s, system_time->wMonth);
148 Stream_Read_UINT16(s, system_time->wDayOfWeek);
149 Stream_Read_UINT16(s, system_time->wDay);
150 Stream_Read_UINT16(s, system_time->wHour);
151 Stream_Read_UINT16(s, system_time->wMinute);
152 Stream_Read_UINT16(s, system_time->wSecond);
153 Stream_Read_UINT16(s, system_time->wMilliseconds);
166 WINPR_ASSERT(system_time);
167 if (!Stream_EnsureRemainingCapacity(s, 16ull))
170 Stream_Write_UINT16(s, system_time->wYear);
171 Stream_Write_UINT16(s, system_time->wMonth);
172 Stream_Write_UINT16(s, system_time->wDayOfWeek);
173 Stream_Write_UINT16(s, system_time->wDay);
174 Stream_Write_UINT16(s, system_time->wHour);
175 Stream_Write_UINT16(s, system_time->wMinute);
176 Stream_Write_UINT16(s, system_time->wSecond);
177 Stream_Write_UINT16(s, system_time->wMilliseconds);
190BOOL rdp_read_client_time_zone(
wStream* s, rdpSettings* settings)
197 if (!Stream_CheckAndLogRequiredLength(TAG, s, 172))
200 tz = settings->ClientTimeZone;
205 Stream_Read_INT32(s, tz->Bias);
207 Stream_Read(s, tz->StandardName,
sizeof(tz->StandardName));
208 if (!rdp_read_system_time(s, &tz->StandardDate))
210 Stream_Read_INT32(s, tz->StandardBias);
212 Stream_Read(s, tz->DaylightName,
sizeof(tz->DaylightName));
213 if (!rdp_read_system_time(s, &tz->DaylightDate))
215 Stream_Read_INT32(s, tz->DaylightBias);
229BOOL rdp_write_client_time_zone(
wStream* s, rdpSettings* settings)
231 WINPR_ASSERT(settings);
238 if (!Stream_EnsureRemainingCapacity(s, 4ull +
sizeof(tz->StandardName)))
246 Stream_Write_INT32(s, tz->Bias);
248 Stream_Write(s, tz->StandardName,
sizeof(tz->StandardName));
250 if (!rdp_write_system_time(s, &tz->StandardDate))
255 if (!Stream_EnsureRemainingCapacity(s, 4ull +
sizeof(tz->DaylightName)))
263 Stream_Write_INT32(s, tz->StandardBias);
266 Stream_Write(s, tz->DaylightName,
sizeof(tz->DaylightName));
268 if (!rdp_write_system_time(s, &tz->DaylightDate))
272 if (!Stream_EnsureRemainingCapacity(s, 4ull))
280 Stream_Write_INT32(s, tz->DaylightBias);