-/*
- * Read and write the citadel.config file
- *
- * Copyright (c) 1987-2021 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.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- */
+//
+// Read and write the citadel.config file
+//
+// Copyright (c) 1987-2021 by the citadel.org team
+//
+// This program is open source software. Use, duplication, or disclosure
+// is subject to the terms of the GNU General Public License, version 3.
+// The program is distributed without any warranty, expressed or implied.
#include "sysdep.h"
#include <stdlib.h>
/*
* Fetch a system config value - long integer
*/
-long CtdlGetConfigLong(char *key)
-{
+long CtdlGetConfigLong(char *key) {
char *s = CtdlGetConfigStr(key);
if (s) return atol(s);
return 0;
}
+/*
+ * This is for fetching longer configuration sets which are stored in the message base.
+ */
char *CtdlGetSysConfig(char *sysconfname) {
char hold_rm[ROOMNAMELEN];
- long msgnum;
+ long msgnum = -1;
char *conf;
struct CtdlMessage *msg;
char buf[SIZ];
return NULL;
}
- /* We want the last (and probably only) config in this room */
- begin_critical_section(S_CONFIG);
- config_msgnum = (-1L);
- CtdlForEachMessage(MSGS_LAST, 1, NULL, sysconfname, NULL, CtdlGetSysConfigBackend, NULL);
- msgnum = config_msgnum;
- end_critical_section(S_CONFIG);
+ /* The new way: hunt for the message number in the config database */
+ msgnum = CtdlGetConfigLong(sysconfname);
+
+ /* Legacy format: hunt through the local system configuration room for a message with a matching MIME type */
+ if (msgnum <= 0) {
+ begin_critical_section(S_CONFIG);
+ config_msgnum = -1;
+ CtdlForEachMessage(MSGS_LAST, 1, NULL, sysconfname, NULL, CtdlGetSysConfigBackend, NULL);
+ msgnum = config_msgnum;
+ end_critical_section(S_CONFIG);
+ if (msgnum > 0) {
+ CtdlSetConfigLong(sysconfname, msgnum); // store it the new way so we don't have to do this again
+ }
+ }
- if (msgnum < 0L) {
+ if (msgnum <= 0) {
conf = NULL;
}
else {
CtdlGetRoom(&CC->room, hold_rm);
- if (conf != NULL) {
+ if (conf != NULL) { // Strip the MIME headers, leaving only the content
do {
extract_token(buf, conf, 0, '\n', sizeof buf);
strcpy(conf, &conf[strlen(buf)+1]);
}
+/*
+ * This is for storing longer configuration sets which are stored in the message base.
+ */
void CtdlPutSysConfig(char *sysconfname, char *sysconfdata) {
- CtdlWriteObject(SYSCONFIGROOM, sysconfname, sysconfdata, (strlen(sysconfdata)+1), NULL, 0, 1, 0);
+ long old_msgnum = -1;
+ long new_msgnum = -1;
+
+ // Search for the previous copy of this config item, so we can delete it
+ old_msgnum = CtdlGetConfigLong(sysconfname);
+
+ // Go ahead and save it, and write the new msgnum to the config database so we can find it again
+ new_msgnum = CtdlWriteObject(SYSCONFIGROOM, sysconfname, sysconfdata, (strlen(sysconfdata)+1), NULL, 0, 0);
+ if (new_msgnum > 0) {
+ CtdlSetConfigLong(sysconfname, new_msgnum);
+
+ // Now delete the old copy
+ if (old_msgnum > 0) {
+ CtdlDeleteMessages(SYSCONFIGROOM, &old_msgnum, 1, "");
+ }
+ }
}