Assert that we don't always have a valid session.
[citadel.git] / citadel / config.c
index fffdadc6e0a8adfcba8f6b11c862103cf9a0f5e5..b6c386b6e56dc7c0ee9d31ed8ea909860ca903c1 100644 (file)
@@ -256,15 +256,15 @@ void initialize_config_system(void) {
                exit(CTDLEXIT_HOME);
        }
 
-       memset(&config, 0, sizeof(struct legacy_config));
+       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);
                }
-               rv = fread((char *) &config, sizeof(struct legacy_config), 1, cfp);
+               rv = fread((char *) &lconfig, sizeof(struct legacy_config), 1, cfp);
                if (rv != 1)
                {
                        fprintf(stderr, 
@@ -296,7 +296,7 @@ void initialize_config_system(void) {
 
        /* Only allow LDAP auth mode if we actually have LDAP support */
 #ifndef HAVE_LDAP
-       if ((config.c_auth_mode == AUTHMODE_LDAP) || (config.c_auth_mode == AUTHMODE_LDAP_AD)) {
+       if ((CtdlGetConfigInt("c_auth_mode") == AUTHMODE_LDAP) || (CtdlGetConfigInt("c_auth_mode") == AUTHMODE_LDAP_AD)) {
                fprintf(stderr, "Your system is configured for LDAP authentication,\n"
                                "but you are running a server built without OpenLDAP support.\n");
                exit(CTDL_EXIT_UNSUP_AUTH);
@@ -356,6 +356,9 @@ void CtdlSetConfigStr(char *key, char *value)
        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);
 
@@ -401,9 +404,18 @@ char *CtdlGetConfigStr(char *key)
        struct cdbdata *cdb;
        int key_len = strlen(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))
        {
+               if (strcmp(key, "c_min_workers")) syslog(LOG_DEBUG, "\033[32mGET CONFIG: '%s' = '%s'\033[0m", key, value);
                return value;
        }
 
@@ -412,6 +424,7 @@ char *CtdlGetConfigStr(char *key)
        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);
        }
 
@@ -419,10 +432,31 @@ char *CtdlGetConfigStr(char *key)
        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;
 }
 
 
+/*
+ * 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;
+}
 
 
 
@@ -468,7 +502,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);