2021-01-12 21:55:34 +00:00
|
|
|
/*-
|
2021-01-12 22:16:18 +00:00
|
|
|
* Copyright (c) 2017-2021 Carsten Sonne Larsen <cs@innolan.net>
|
2021-01-12 21:55:34 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
2021-01-12 22:02:29 +00:00
|
|
|
*
|
2021-01-12 21:55:34 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "message.h"
|
2021-01-12 22:02:29 +00:00
|
|
|
#include "setting.h"
|
2021-01-31 19:10:59 +00:00
|
|
|
#include "text.h"
|
2021-01-12 22:16:18 +00:00
|
|
|
#include "conv.h"
|
2021-01-31 19:10:59 +00:00
|
|
|
#include "sync.h"
|
2021-01-12 21:55:34 +00:00
|
|
|
#include "log.h"
|
2021-01-12 22:16:18 +00:00
|
|
|
#include "mem.h"
|
|
|
|
#include "val.h"
|
|
|
|
#include "win.h"
|
2021-01-31 19:10:59 +00:00
|
|
|
#include "tz.h"
|
2021-01-12 22:02:29 +00:00
|
|
|
|
|
|
|
#include "logmod.h"
|
2021-01-12 22:16:18 +00:00
|
|
|
#define MODULENAME "Settings"
|
2021-01-12 21:55:34 +00:00
|
|
|
|
|
|
|
static void ValidateInterval(void)
|
|
|
|
{
|
2021-01-12 22:02:29 +00:00
|
|
|
if (Settings->Interval < INTERVAL_MIN)
|
2021-01-12 21:55:34 +00:00
|
|
|
{
|
2021-01-12 22:02:29 +00:00
|
|
|
LogInfo(settingTooLow,
|
|
|
|
SettingKeys->Interval,
|
|
|
|
INTERVAL_MIN);
|
2021-01-12 22:16:18 +00:00
|
|
|
LogNotice(settingChangedLong,
|
|
|
|
SettingKeys->Interval,
|
|
|
|
Settings->Interval,
|
|
|
|
INTERVAL_MIN);
|
2021-01-12 22:02:29 +00:00
|
|
|
Settings->Interval = INTERVAL_MIN;
|
2021-01-12 21:55:34 +00:00
|
|
|
}
|
2021-01-31 19:10:59 +00:00
|
|
|
else if (Settings->Interval > INTERVAL_MAX)
|
|
|
|
{
|
|
|
|
LogInfo(settingTooHigh,
|
|
|
|
SettingKeys->Interval,
|
|
|
|
INTERVAL_MAX);
|
|
|
|
LogNotice(settingChangedLong,
|
|
|
|
SettingKeys->Interval,
|
|
|
|
Settings->Interval,
|
|
|
|
INTERVAL_MAX);
|
|
|
|
Settings->Interval = INTERVAL_MAX;
|
|
|
|
}
|
2021-01-12 21:55:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void ValidateTimeout(void)
|
|
|
|
{
|
2021-01-12 22:02:29 +00:00
|
|
|
if (Settings->Timeout < TIMEOUT_MIN)
|
2021-01-12 21:55:34 +00:00
|
|
|
{
|
2021-01-12 22:02:29 +00:00
|
|
|
LogInfo(settingTooLow,
|
|
|
|
SettingKeys->Timeout,
|
|
|
|
TIMEOUT_MIN);
|
2021-01-12 22:16:18 +00:00
|
|
|
LogNotice(settingChangedLong,
|
|
|
|
SettingKeys->Timeout,
|
|
|
|
Settings->Timeout,
|
|
|
|
TIMEOUT_MIN);
|
2021-01-12 22:02:29 +00:00
|
|
|
Settings->Timeout = TIMEOUT_MIN;
|
2021-01-12 21:55:34 +00:00
|
|
|
}
|
|
|
|
|
2021-01-12 22:02:29 +00:00
|
|
|
if (Settings->Timeout > Settings->Interval / 2)
|
2021-01-12 21:55:34 +00:00
|
|
|
{
|
2021-01-12 22:02:29 +00:00
|
|
|
LogInfo(settingGreaterThan,
|
|
|
|
SettingKeys->Timeout,
|
|
|
|
SettingKeys->Interval);
|
2021-01-12 22:16:18 +00:00
|
|
|
LogNotice(settingChangedLong,
|
|
|
|
SettingKeys->Timeout,
|
|
|
|
Settings->Timeout,
|
|
|
|
Settings->Interval / 2);
|
2021-01-12 22:02:29 +00:00
|
|
|
Settings->Timeout = Settings->Interval / 2;
|
2021-01-12 21:55:34 +00:00
|
|
|
}
|
|
|
|
|
2021-01-12 22:02:29 +00:00
|
|
|
if (Settings->Timeout > TIMEOUT_MAX)
|
2021-01-12 21:55:34 +00:00
|
|
|
{
|
2021-01-12 22:02:29 +00:00
|
|
|
LogInfo(settingTooHigh,
|
|
|
|
SettingKeys->Timeout,
|
|
|
|
TIMEOUT_MAX);
|
2021-01-12 22:16:18 +00:00
|
|
|
LogNotice(settingChangedLong,
|
|
|
|
SettingKeys->Timeout,
|
|
|
|
Settings->Timeout,
|
|
|
|
TIMEOUT_MAX);
|
2021-01-12 22:02:29 +00:00
|
|
|
Settings->Timeout = TIMEOUT_MAX;
|
2021-01-12 21:55:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ValidatePriority(void)
|
|
|
|
{
|
2021-01-12 22:02:29 +00:00
|
|
|
if (Settings->Priority < PRIORITY_MIN)
|
2021-01-12 21:55:34 +00:00
|
|
|
{
|
2021-01-12 22:02:29 +00:00
|
|
|
LogInfo(settingTooLow,
|
|
|
|
SettingKeys->Priority,
|
|
|
|
PRIORITY_MIN);
|
2021-01-12 22:16:18 +00:00
|
|
|
LogNotice(settingChangedLong,
|
|
|
|
SettingKeys->Priority,
|
|
|
|
Settings->Priority,
|
|
|
|
PRIORITY_MIN);
|
2021-01-12 22:02:29 +00:00
|
|
|
Settings->Priority = PRIORITY_MIN;
|
2021-01-12 21:55:34 +00:00
|
|
|
}
|
2021-01-12 22:16:18 +00:00
|
|
|
else if (Settings->Priority > PRIORITY_MAX)
|
2021-01-12 21:55:34 +00:00
|
|
|
{
|
2021-01-12 22:02:29 +00:00
|
|
|
LogInfo(settingTooHigh,
|
|
|
|
SettingKeys->Priority,
|
|
|
|
PRIORITY_MAX);
|
2021-01-12 22:16:18 +00:00
|
|
|
LogNotice(settingChangedLong,
|
|
|
|
SettingKeys->Priority,
|
|
|
|
Settings->Priority,
|
|
|
|
PRIORITY_MAX);
|
2021-01-12 22:02:29 +00:00
|
|
|
Settings->Priority = PRIORITY_MAX;
|
2021-01-12 21:55:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ValidateThreshold(void)
|
|
|
|
{
|
2021-01-12 22:02:29 +00:00
|
|
|
if (Settings->Threshold < THRESHOLD_MIN)
|
2021-01-12 21:55:34 +00:00
|
|
|
{
|
2021-01-31 19:10:59 +00:00
|
|
|
LogInfo(settingTooLow, SettingKeys->Threshold, THRESHOLD_MIN);
|
|
|
|
LogNotice(settingChangedLong, SettingKeys->Threshold,
|
|
|
|
Settings->Threshold, THRESHOLD_MIN);
|
2021-01-12 22:02:29 +00:00
|
|
|
Settings->Threshold = THRESHOLD_MIN;
|
2021-01-12 21:55:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-31 19:10:59 +00:00
|
|
|
static void ValidateTimeZoneDisplay(void)
|
|
|
|
{
|
|
|
|
if (Settings->TimeZoneDisplay < TZD_MIN)
|
|
|
|
{
|
|
|
|
LogInfo(settingTooLow, SettingKeys->TimeZoneDisplay, TZD_MIN);
|
|
|
|
LogNotice(settingChangedLong, SettingKeys->TimeZoneDisplay,
|
|
|
|
Settings->TimeZoneDisplay, TZD_MIN);
|
|
|
|
Settings->TimeZoneDisplay = TZD_MIN;
|
|
|
|
}
|
|
|
|
else if (Settings->TimeZoneDisplay > TZD_MAX)
|
|
|
|
{
|
|
|
|
LogInfo(settingTooHigh, SettingKeys->TimeZoneDisplay, TZD_MAX);
|
|
|
|
LogNotice(settingChangedLong, SettingKeys->TimeZoneDisplay,
|
|
|
|
Settings->TimeZoneDisplay, TZD_MAX);
|
|
|
|
Settings->TimeZoneDisplay = TZD_MAX;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ValidateTimeZoneValue(void)
|
|
|
|
{
|
|
|
|
if (Settings->TimeZoneValue < TZVALUE_MIN)
|
|
|
|
{
|
|
|
|
LogInfo(settingTooLow, SettingKeys->TimeZoneValue, TZVALUE_MIN);
|
|
|
|
LogNotice(settingChangedLong, SettingKeys->TimeZoneValue,
|
|
|
|
Settings->TimeZoneValue, TZVALUE_MIN);
|
|
|
|
Settings->TimeZoneValue = TZVALUE_MIN;
|
|
|
|
}
|
|
|
|
else if (Settings->TimeZoneValue != TZVALUE_DEF &&
|
|
|
|
Settings->TimeZoneValue > TZVALUE_MAX)
|
|
|
|
{
|
|
|
|
LogInfo(settingTooHigh, SettingKeys->TimeZoneValue, TZVALUE_MAX);
|
|
|
|
LogNotice(settingChangedLong, SettingKeys->TimeZoneValue,
|
|
|
|
Settings->TimeZoneValue, TZVALUE_MAX);
|
|
|
|
Settings->TimeZoneValue = TZVALUE_MAX;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Settings->TimeZoneValue % 60 >= 60)
|
|
|
|
{
|
|
|
|
long oldValue = Settings->TimeZoneValue;
|
|
|
|
Settings->TimeZoneValue = (Settings->TimeZoneValue / 60) * 60;
|
|
|
|
LogInfo(settingInvalid, SettingKeys->TimeZoneValue, oldValue);
|
|
|
|
LogNotice(settingChangedLong, SettingKeys->TimeZoneValue,
|
|
|
|
oldValue, Settings->TimeZoneValue);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-12 22:16:18 +00:00
|
|
|
static bool ValidateServer(char *name)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool ValidatePort(char *name)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-01-12 21:55:34 +00:00
|
|
|
void SanitizeSettings(void)
|
|
|
|
{
|
2021-01-31 19:10:59 +00:00
|
|
|
LogDebug(validatingSettings);
|
2021-01-12 21:55:34 +00:00
|
|
|
ValidateInterval();
|
|
|
|
ValidateTimeout();
|
|
|
|
ValidatePriority();
|
|
|
|
ValidateThreshold();
|
2021-01-31 19:10:59 +00:00
|
|
|
ValidateTimeZoneDisplay();
|
|
|
|
ValidateTimeZoneValue();
|
|
|
|
LogTrace(validatedSettings);
|
2021-01-12 22:16:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SetInterval(long value, long opt)
|
|
|
|
{
|
|
|
|
long oldValue = Settings->Interval;
|
|
|
|
if (Settings->Interval != value)
|
|
|
|
{
|
|
|
|
LogNotice(settingChangedLong,
|
|
|
|
SettingKeys->Interval,
|
|
|
|
Settings->Interval,
|
|
|
|
value);
|
|
|
|
Settings->Interval = value;
|
|
|
|
ValidateInterval();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((opt & APPLY_UI_BACK) == APPLY_UI_BACK)
|
|
|
|
{
|
|
|
|
Forbid();
|
|
|
|
if (WindowSettings != NULL)
|
|
|
|
{
|
|
|
|
WindowSettings->Interval = Settings->Interval;
|
|
|
|
}
|
|
|
|
Permit();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((opt & APPLY_UI_FRONT) == APPLY_UI_FRONT)
|
|
|
|
{
|
|
|
|
WriteUiInterval();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((opt & APPLY_RUNTIME) == APPLY_RUNTIME && Settings->Interval != oldValue)
|
|
|
|
{
|
|
|
|
SendBrokerMessage(ATK_RESTART);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetTimeout(long value, long opt)
|
|
|
|
{
|
|
|
|
long oldValue = Settings->Timeout;
|
|
|
|
if (Settings->Timeout != value)
|
|
|
|
{
|
|
|
|
LogNotice(settingChangedLong,
|
|
|
|
SettingKeys->Timeout,
|
|
|
|
Settings->Timeout,
|
|
|
|
value);
|
|
|
|
Settings->Timeout = value;
|
|
|
|
ValidateTimeout();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((opt & APPLY_UI_BACK) == APPLY_UI_BACK)
|
|
|
|
{
|
|
|
|
Forbid();
|
|
|
|
if (WindowSettings != NULL)
|
|
|
|
{
|
|
|
|
WindowSettings->Timeout = Settings->Timeout;
|
|
|
|
}
|
|
|
|
Permit();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((opt & APPLY_UI_FRONT) == APPLY_UI_FRONT)
|
|
|
|
{
|
|
|
|
WriteUiTimeout();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((opt & APPLY_RUNTIME) == APPLY_RUNTIME && Settings->Timeout != oldValue)
|
|
|
|
{
|
|
|
|
SendBrokerMessage(ATK_RESTART);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetThreshold(char *valueString, long opt)
|
|
|
|
{
|
|
|
|
unsigned long long value;
|
|
|
|
long long oldValue = Settings->Threshold;
|
|
|
|
int p = StrToLongLong(valueString, &value);
|
|
|
|
|
|
|
|
if (p != -1 && Settings->Threshold != value)
|
|
|
|
{
|
|
|
|
char newValueString[MAXLONGLONGCHARSIZE];
|
|
|
|
char oldValueString[MAXLONGLONGCHARSIZE];
|
|
|
|
LongLongToStr(Settings->Threshold, oldValueString);
|
|
|
|
LongLongToStr(value, newValueString);
|
|
|
|
LogNotice(settingChangedString,
|
|
|
|
SettingKeys->Threshold,
|
|
|
|
oldValueString,
|
|
|
|
newValueString);
|
|
|
|
Settings->Threshold = value;
|
|
|
|
ValidateThreshold();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((opt & APPLY_UI_BACK) == APPLY_UI_BACK)
|
|
|
|
{
|
|
|
|
Forbid();
|
|
|
|
if (WindowSettings != NULL)
|
|
|
|
{
|
|
|
|
WindowSettings->Threshold = Settings->Threshold;
|
|
|
|
}
|
|
|
|
Permit();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((opt & APPLY_UI_FRONT) == APPLY_UI_FRONT)
|
|
|
|
{
|
|
|
|
WriteUiThreshold();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((opt & APPLY_RUNTIME) == APPLY_RUNTIME && Settings->Threshold != oldValue)
|
|
|
|
{
|
|
|
|
SendBrokerMessage(ATK_RESTART);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetPriority(char *valueString, long opt)
|
|
|
|
{
|
|
|
|
LONG value, oldValue = Settings->Priority;
|
|
|
|
int p = StrToLong((STRPTR)valueString, &value);
|
|
|
|
|
|
|
|
if (p != -1 && Settings->Priority != value)
|
|
|
|
{
|
|
|
|
LogNotice(settingChangedLong,
|
|
|
|
SettingKeys->Priority,
|
|
|
|
Settings->Priority,
|
|
|
|
value);
|
|
|
|
Settings->Priority = value;
|
|
|
|
ValidatePriority();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((opt & APPLY_UI_BACK) == APPLY_UI_BACK)
|
|
|
|
{
|
|
|
|
Forbid();
|
|
|
|
if (WindowSettings != NULL)
|
|
|
|
{
|
|
|
|
WindowSettings->Priority = Settings->Priority;
|
|
|
|
}
|
|
|
|
Permit();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((opt & APPLY_UI_FRONT) == APPLY_UI_FRONT)
|
|
|
|
{
|
|
|
|
WriteUiCxPriority();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((opt & APPLY_RUNTIME) == APPLY_RUNTIME && Settings->Priority != oldValue)
|
|
|
|
{
|
|
|
|
SetBrokerPriority(Settings->Priority);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetServer(char *valueString, long opt)
|
|
|
|
{
|
|
|
|
char *oldSettingValue, *newSettingValue;
|
|
|
|
char *oldValue;
|
|
|
|
|
|
|
|
if (!ValidateServer(valueString))
|
|
|
|
return;
|
|
|
|
|
|
|
|
oldValue = StrDupSafe(Settings->DestinationAddress);
|
|
|
|
if (Stricmp((STRPTR)oldValue, (STRPTR)valueString) == 0)
|
|
|
|
{
|
|
|
|
FreeMemSafe(oldValue);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
LogNotice(settingChangedString,
|
|
|
|
SettingKeys->Threshold,
|
|
|
|
oldValue,
|
|
|
|
valueString);
|
|
|
|
FreeMemSafe(oldValue);
|
|
|
|
|
2021-01-31 19:10:59 +00:00
|
|
|
bool active = SynchronizerRunning;
|
|
|
|
if ((opt & APPLY_RUNTIME) == APPLY_RUNTIME && active)
|
2021-01-12 22:16:18 +00:00
|
|
|
{
|
|
|
|
Deactivate();
|
|
|
|
}
|
|
|
|
|
|
|
|
newSettingValue = StrDupSafe(valueString);
|
|
|
|
Forbid();
|
|
|
|
oldSettingValue = Settings->DestinationAddress;
|
|
|
|
Settings->DestinationAddress = newSettingValue;
|
|
|
|
Permit();
|
|
|
|
FreeMemSafe(oldSettingValue);
|
|
|
|
|
|
|
|
if ((opt & APPLY_UI_BACK) == APPLY_UI_BACK)
|
|
|
|
{
|
|
|
|
newSettingValue = StrDupSafe(valueString);
|
|
|
|
oldSettingValue = NULL;
|
|
|
|
|
|
|
|
Forbid();
|
|
|
|
if (WindowSettings != NULL)
|
|
|
|
{
|
|
|
|
oldSettingValue = WindowSettings->DestinationAddress;
|
|
|
|
WindowSettings->DestinationAddress = newSettingValue;
|
|
|
|
}
|
|
|
|
Permit();
|
|
|
|
|
|
|
|
if (oldSettingValue == NULL)
|
|
|
|
FreeMemSafe(newSettingValue);
|
|
|
|
else
|
|
|
|
FreeMemSafe(oldSettingValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((opt & APPLY_UI_FRONT) == APPLY_UI_FRONT)
|
|
|
|
{
|
|
|
|
WriteUiServer();
|
|
|
|
}
|
|
|
|
|
2021-01-31 19:10:59 +00:00
|
|
|
if ((opt & APPLY_RUNTIME) == APPLY_RUNTIME && active)
|
2021-01-12 22:16:18 +00:00
|
|
|
{
|
2021-01-31 19:10:59 +00:00
|
|
|
while (SynchronizerRunning)
|
|
|
|
Delay(10);
|
2021-01-12 22:16:18 +00:00
|
|
|
Activate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetPort(char *valueString, long opt)
|
|
|
|
{
|
|
|
|
char *oldSettingValue, *newSettingValue;
|
|
|
|
char *oldValue;
|
|
|
|
|
|
|
|
if (!ValidatePort(valueString))
|
|
|
|
return;
|
|
|
|
|
|
|
|
oldValue = StrDupSafe(Settings->DestinationPort);
|
|
|
|
if (Stricmp((STRPTR)oldValue, (STRPTR)valueString) == 0)
|
|
|
|
{
|
|
|
|
FreeMemSafe(oldValue);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
LogNotice(settingChangedString,
|
|
|
|
SettingKeys->DestinationPort,
|
|
|
|
oldValue,
|
|
|
|
valueString);
|
|
|
|
FreeMemSafe(oldValue);
|
|
|
|
|
2021-01-31 19:10:59 +00:00
|
|
|
bool active = SynchronizerRunning;
|
|
|
|
if ((opt & APPLY_RUNTIME) == APPLY_RUNTIME && active)
|
2021-01-12 22:16:18 +00:00
|
|
|
{
|
|
|
|
Deactivate();
|
|
|
|
}
|
|
|
|
|
|
|
|
newSettingValue = StrDupSafe(valueString);
|
|
|
|
Forbid();
|
|
|
|
oldSettingValue = Settings->DestinationPort;
|
|
|
|
Settings->DestinationPort = newSettingValue;
|
|
|
|
Permit();
|
|
|
|
FreeMemSafe(oldSettingValue);
|
|
|
|
|
|
|
|
if ((opt & APPLY_UI_BACK) == APPLY_UI_BACK)
|
|
|
|
{
|
|
|
|
newSettingValue = StrDupSafe(valueString);
|
|
|
|
oldSettingValue = NULL;
|
|
|
|
|
|
|
|
Forbid();
|
|
|
|
if (WindowSettings != NULL)
|
|
|
|
{
|
|
|
|
oldSettingValue = WindowSettings->DestinationPort;
|
|
|
|
WindowSettings->DestinationPort = newSettingValue;
|
|
|
|
}
|
|
|
|
Permit();
|
|
|
|
|
|
|
|
if (oldSettingValue == NULL)
|
|
|
|
FreeMemSafe(newSettingValue);
|
|
|
|
else
|
|
|
|
FreeMemSafe(oldSettingValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((opt & APPLY_UI_FRONT) == APPLY_UI_FRONT)
|
|
|
|
{
|
|
|
|
WriteUiPort();
|
|
|
|
}
|
|
|
|
|
2021-01-31 19:10:59 +00:00
|
|
|
if ((opt & APPLY_RUNTIME) == APPLY_RUNTIME && active)
|
2021-01-12 22:16:18 +00:00
|
|
|
{
|
2021-01-31 19:10:59 +00:00
|
|
|
while (SynchronizerRunning)
|
|
|
|
Delay(10);
|
2021-01-12 22:16:18 +00:00
|
|
|
Activate();
|
|
|
|
}
|
2021-01-12 21:55:34 +00:00
|
|
|
}
|
2021-01-31 19:10:59 +00:00
|
|
|
|
|
|
|
void SetTimeZoneSetting(const char *settingKey, char **setting, char *valueString, long opt)
|
|
|
|
{
|
|
|
|
char *oldSettingValue, *newSettingValue;
|
|
|
|
char *oldValue;
|
|
|
|
|
|
|
|
oldValue = StrDupSafe(*setting);
|
|
|
|
if (Stricmp((STRPTR)oldValue, (STRPTR)valueString) == 0)
|
|
|
|
{
|
|
|
|
FreeMemSafe(oldValue);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
LogNotice(settingChangedString,
|
|
|
|
settingKey,
|
|
|
|
oldValue,
|
|
|
|
valueString);
|
|
|
|
FreeMemSafe(oldValue);
|
|
|
|
|
|
|
|
bool active = SynchronizerRunning;
|
|
|
|
if ((opt & APPLY_RUNTIME) == APPLY_RUNTIME && active)
|
|
|
|
{
|
|
|
|
Deactivate();
|
|
|
|
}
|
|
|
|
|
|
|
|
newSettingValue = StrDupSafe(valueString);
|
|
|
|
Forbid();
|
|
|
|
oldSettingValue = *setting;
|
|
|
|
*setting = newSettingValue;
|
|
|
|
Permit();
|
|
|
|
FreeMemSafe(oldSettingValue);
|
|
|
|
|
|
|
|
if ((opt & APPLY_RUNTIME) == APPLY_RUNTIME && settingKey == SettingKeys->TZ)
|
|
|
|
{
|
|
|
|
InitTimezone();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((opt & APPLY_UI_FRONT) == APPLY_UI_FRONT)
|
|
|
|
{
|
|
|
|
SendWindowMessage(ATK_TZ_CHANGED);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((opt & APPLY_RUNTIME) == APPLY_RUNTIME && active)
|
|
|
|
{
|
|
|
|
while (SynchronizerRunning)
|
|
|
|
Delay(10);
|
|
|
|
Activate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetTimeZoneSettingLong(const char *settingKey, long *setting, char *valueString, long opt)
|
|
|
|
{
|
|
|
|
LONG value, oldValue = *setting;
|
|
|
|
int p = StrToLong((STRPTR)valueString, &value);
|
|
|
|
|
|
|
|
if (p != -1 && oldValue != value)
|
|
|
|
{
|
|
|
|
LogNotice(settingChangedLong,
|
|
|
|
settingKey,
|
|
|
|
oldValue,
|
|
|
|
value);
|
|
|
|
*setting = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((opt & APPLY_RUNTIME) == APPLY_RUNTIME)
|
|
|
|
{
|
|
|
|
if (settingKey == SettingKeys->TimeZoneValue || settingKey == SettingKeys->TimeZoneDst)
|
|
|
|
{
|
|
|
|
InitTimezone();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((opt & APPLY_UI_FRONT) == APPLY_UI_FRONT)
|
|
|
|
{
|
|
|
|
SendWindowMessage(ATK_TZ_CHANGED);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((opt & APPLY_RUNTIME) == APPLY_RUNTIME)
|
|
|
|
{
|
|
|
|
SendBrokerMessage(ATK_RESTART);
|
|
|
|
}
|
|
|
|
}
|