/*
* Read and write the citadel.config file
*
- * Copyright (c) 1987-2015 by the citadel.org team
+ * Copyright (c) 1987-2016 by the citadel.org team
*
* This program is open source software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3.
#include <stdio.h>
#include <sys/utsname.h>
#include <libcitadel.h>
+#include <assert.h>
#include "config.h"
#include "ctdl_module.h"
/* Ensure that we are linked to the correct version of libcitadel */
if (libcitadel_version_number() < LIBCITADEL_VERSION_NUMBER) {
- fprintf(stderr, "You are running libcitadel version %d.%02d\n",
- (libcitadel_version_number() / 100), (libcitadel_version_number() % 100)
- );
- fprintf(stderr, "citserver was compiled against version %d.%02d\n",
- (LIBCITADEL_VERSION_NUMBER / 100), (LIBCITADEL_VERSION_NUMBER % 100)
- );
+ fprintf(stderr, "You are running libcitadel version %d\n", libcitadel_version_number());
+ fprintf(stderr, "citserver was compiled against version %d\n", LIBCITADEL_VERSION_NUMBER);
exit(CTDLEXIT_LIBCITADEL);
}
int key_len = strlen(key);
int value_len = strlen(value);
- /* FIXME we are noisy logging for now */
- syslog(LOG_DEBUG, "\033[31mSET CONFIG: '%s' = '%s'\033[0m", key, value);
-
/* Save it in memory */
Put(ctdlconfig, key, key_len, strdup(value), NULL);
}
+
+/*
+ * Delete a system config value.
+ */
+void CtdlDelConfig(char *key)
+{
+ int key_len = strlen(key);
+
+ if (IsEmptyStr(key)) return;
+
+ /* Delete from the database. */
+ cdb_delete(CDB_CONFIG, key, key_len);
+
+ /* Delete from the in-memory cache */
+ HashPos *Pos = GetNewHashPos(ctdlconfig, 1);
+ if (GetHashPosFromKey(ctdlconfig, key, key_len, Pos)) {
+ DeleteEntryFromHash(ctdlconfig, Pos);
+ }
+ DeleteHashPos(&Pos);
+
+ assert(Pos == NULL); // no memory leaks allowed
+}
+
+
+
+
/*
* Fetch a system config value. Caller does *not* own the returned value and may not alter it.
*/
if (IsEmptyStr(key)) return(NULL);
- /* Temporary hack to make sure we didn't mess up any porting - FIXME remove this after testing thoroughly */
- if (!strncmp(key, "config", 6)) {
- syslog(LOG_EMERG, "You requested a key starting with 'config' which probably means a porting error: %s", key);
- abort();
- }
-
/* First look in memory */
if (GetHash(ctdlconfig, key, key_len, (void *)&value))
{
- if (strcmp(key, "c_min_workers")) syslog(LOG_DEBUG, "\033[32mGET CONFIG: '%s' = '%s'\033[0m", key, value);
return value;
}
cdb = cdb_fetch(CDB_CONFIG, key, key_len);
if (cdb == NULL) { /* nope, not there either. */
- syslog(LOG_DEBUG, "\033[32mGET CONFIG: '%s' = NULL\033[0m", key);
return(NULL);
}
value = strdup(cdb->ptr + key_len + 1); /* The key was stored there too; skip past it */
cdb_free(cdb);
Put(ctdlconfig, key, key_len, value, NULL);
- syslog(LOG_DEBUG, "\033[32mGET CONFIG: '%s' = '%s'\033[0m", key, value);
return value;
}