Begin removing the decimal point from our version number (901 instead of 9.01)
[citadel.git] / citadel / config.c
index 846eb052f99d5424282c0440913d82e233dc71fd..eadd6cb2fd990e9b9d840e040647fb689be5dfef 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * 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.
@@ -16,6 +16,7 @@
 #include <stdio.h>
 #include <sys/utsname.h>
 #include <libcitadel.h>
+#include <assert.h>
 #include "config.h"
 #include "ctdl_module.h"
 
@@ -238,12 +239,8 @@ void initialize_config_system(void) {
 
        /* 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);
        }
 
@@ -259,7 +256,7 @@ void initialize_config_system(void) {
        memset(&lconfig, 0, sizeof(struct legacy_config));
        cfp = fopen(file_citadel_config, "rb");
        if (cfp != NULL) {
-               if (CtdlGetConfigLong("c_config_created_or_migrated") <= 0) {
+               if (CtdlGetConfigLong("c_config_created_or_migrated") > 0) {
                        fprintf(stderr, "Citadel Server found BOTH legacy and new configurations present.\n");
                        fprintf(stderr, "Exiting to prevent data corruption.\n");
                        exit(CTDLEXIT_CONFIG);
@@ -392,6 +389,32 @@ void CtdlSetConfigInt(char *key, int value)
 }
 
 
+
+/*
+ * 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.
  */
@@ -403,12 +426,6 @@ char *CtdlGetConfigStr(char *key)
 
        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))
        {
@@ -431,6 +448,26 @@ char *CtdlGetConfigStr(char *key)
 }
 
 
+/*
+ * Fetch a system config value - integer
+ */
+int CtdlGetConfigInt(char *key)
+{
+       char *s = CtdlGetConfigStr(key);
+       if (s) return atoi(s);
+       return 0;
+}
+
+
+/*
+ * Fetch a system config value - long integer
+ */
+long CtdlGetConfigLong(char *key)
+{
+       char *s = CtdlGetConfigStr(key);
+       if (s) return atol(s);
+       return 0;
+}
 
 
 
@@ -476,7 +513,7 @@ char *CtdlGetSysConfig(char *sysconfname) {
                conf = NULL;
        }
        else {
-               msg = CtdlFetchMessage(msgnum, 1);
+               msg = CtdlFetchMessage(msgnum, 1, 1);
                if (msg != NULL) {
                        conf = strdup(msg->cm_fields[eMesageText]);
                        CM_Free(msg);