mirror of
https://github.com/inverse-inc/sogo.git
synced 2026-05-23 12:25:23 +00:00
simplified defaults override code, for sogod and other SOGo-based processes, by giving prescendence to the user "user defaults", followed by sogo.conf, debconf.conf and finally SOGoDefaults.plist", and by adding "sogod" in the list of defaults "suites"
This commit is contained in:
@@ -68,96 +68,79 @@ BootstrapNSUserDefaults ()
|
||||
}
|
||||
}
|
||||
|
||||
+ (void) injectSOGoDefaults: (NSUserDefaults *) ud
|
||||
static void
|
||||
_migrateSOGo09Configuration (NSUserDefaults *ud, NSObject *logger)
|
||||
{
|
||||
NSBundle *bundle;
|
||||
NSDictionary *baseSOGoDefaults;
|
||||
NSString *filename;
|
||||
NSDictionary *domain;
|
||||
|
||||
bundle = [NSBundle bundleForClass: self];
|
||||
filename = [bundle pathForResource: @"SOGoDefaults" ofType: @"plist"];
|
||||
if (filename
|
||||
&& [[NSFileManager defaultManager] fileExistsAtPath: filename])
|
||||
domain = [ud persistentDomainForName: @"sogod-0.9"];
|
||||
if ([domain count])
|
||||
{
|
||||
baseSOGoDefaults
|
||||
= [[NSDictionary alloc] initWithContentsOfFile: filename];
|
||||
if (baseSOGoDefaults)
|
||||
{
|
||||
[ud registerDefaults: baseSOGoDefaults];
|
||||
[baseSOGoDefaults autorelease];
|
||||
}
|
||||
else
|
||||
[bundle errorWithFormat: @"Unable to deserialize SOGoDefaults.plist"];
|
||||
[logger logWithFormat: @"migrating user defaults from sogod-0.9"];
|
||||
[ud setPersistentDomain: domain forName: @"sogod"];
|
||||
[ud removePersistentDomainForName: @"sogod-0.9"];
|
||||
[ud synchronize];
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
_injectConfigurationFromFile (NSUserDefaults *ud,
|
||||
NSString *filename, NSObject *logger)
|
||||
{
|
||||
NSFileManager *fm;
|
||||
NSDictionary *newConfig;
|
||||
|
||||
fm = [NSFileManager defaultManager];
|
||||
if ([fm fileExistsAtPath: filename])
|
||||
{
|
||||
newConfig = [NSDictionary dictionaryWithContentsOfFile: filename];
|
||||
if (newConfig)
|
||||
[ud registerDefaults: newConfig];
|
||||
else
|
||||
{
|
||||
[logger errorWithFormat: @"Cannot read configuration from '%@'.",
|
||||
filename];
|
||||
exit (1);
|
||||
}
|
||||
}
|
||||
else
|
||||
[bundle errorWithFormat: @"SOGoDefaults.plist not found"];
|
||||
}
|
||||
|
||||
+ (void) prepareUserDefaults
|
||||
{
|
||||
NSString *redirectURL;
|
||||
NSUserDefaults *ud;
|
||||
SOGoStartupLogger *logger;
|
||||
NSBundle *bundle;
|
||||
NSString *confFiles[] = {@"/etc/sogo/debconf.conf",
|
||||
@"/etc/sogo/sogo.conf"};
|
||||
NSString *filename, *redirectURL;
|
||||
NSUInteger count;
|
||||
|
||||
logger = [SOGoStartupLogger sharedLogger];
|
||||
|
||||
/* we load the configuration from the standard user default files */
|
||||
ud = [NSUserDefaults standardUserDefaults];
|
||||
if ([[NSFileManager defaultManager] fileExistsAtPath: @"/etc/sogo/sogo.conf"])
|
||||
{
|
||||
NSMutableDictionary *domain;
|
||||
|
||||
domain = [[NSMutableDictionary alloc] initWithContentsOfFile: @"/etc/sogo/sogo.conf"];
|
||||
if (domain)
|
||||
{
|
||||
if ([[NSFileManager defaultManager] fileExistsAtPath: @"/etc/sogo/debconf.conf"])
|
||||
{
|
||||
NSMutableDictionary *dbconfig;
|
||||
/* if "sogod" does not exist, maybe "sogod-0.9" still exists from an old
|
||||
configuration */
|
||||
if (![[ud persistentDomainForName: @"sogod"] count])
|
||||
_migrateSOGo09Configuration (ud, logger);
|
||||
|
||||
dbconfig = [[NSMutableDictionary alloc] initWithContentsOfFile: @"/etc/sogo/debconf.conf"];
|
||||
if (dbconfig)
|
||||
{
|
||||
[domain addEntriesFromDictionary: dbconfig];
|
||||
[dbconfig autorelease];
|
||||
}
|
||||
else
|
||||
{
|
||||
[logger warnWithFormat: @"Can't deserialize /etc/sogo/debconf.conf, exiting."];
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
[ud removePersistentDomainForName: @"sogod"];
|
||||
[ud setVolatileDomain: domain forName: @"sogod"];
|
||||
[domain autorelease];
|
||||
}
|
||||
else
|
||||
{
|
||||
[logger errorWithFormat: @"Can't deserialize /etc/sogo/sogo.conf, exiting."];
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
NSDictionary *domain;
|
||||
domain = [ud persistentDomainForName: @"sogod"];
|
||||
if (![domain count])
|
||||
{
|
||||
domain = [ud persistentDomainForName: @"sogod-0.9"];
|
||||
if ([domain count])
|
||||
{
|
||||
[logger logWithFormat: @"migrating user defaults from sogod-0.9"];
|
||||
[ud setPersistentDomain: domain forName: @"sogod"];
|
||||
[ud removePersistentDomainForName: @"sogod-0.9"];
|
||||
[ud synchronize];
|
||||
}
|
||||
else
|
||||
{
|
||||
[logger warnWithFormat: @"No configuration found, exiting."];
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
[self injectSOGoDefaults: ud];
|
||||
/* reregister defaults from domain "sogod" into default domain, for
|
||||
non-sogod processes */
|
||||
[ud addSuiteNamed: @"sogod"];
|
||||
|
||||
/* we populate the configuration with the values from SOGoDefaults.plist */
|
||||
bundle = [NSBundle bundleForClass: self];
|
||||
filename = [bundle pathForResource: @"SOGoDefaults" ofType: @"plist"];
|
||||
if (filename)
|
||||
_injectConfigurationFromFile (ud, filename, logger);
|
||||
|
||||
/* fill the possibly missing values with the configuration stored
|
||||
in "/etc" */
|
||||
for (count = 0; count < sizeof(confFiles)/sizeof(confFiles[0]); count++)
|
||||
_injectConfigurationFromFile (ud, confFiles[count], logger);
|
||||
|
||||
/* issue a warning if WOApplicationRedirectURL is used */
|
||||
redirectURL = [ud stringForKey: @"WOApplicationRedirectURL"];
|
||||
if (redirectURL)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user