From 4708119cea3c8b38057650eeb9af7765d29a3054 Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Sun, 1 Aug 2021 14:10:29 -0400 Subject: [PATCH] CtdlGetSysConfig() and CtdlPutSysConfig() now have the ability to store large configuration items as message texts in the Local System Configuration room by saving their message numbers as items in the regular configuration database. This eliminates the last place where we did 'Delete all other messages in this room which have the same MIME type' and that ability has therefore been removed from the code. There is enough code remaining to read configurations saved the old way, but they are upgraded the first time they are read. --- citadel/config.c | 44 ++++++++++++++++++------ citadel/modules/calendar/serv_calendar.c | 1 - citadel/modules/vcard/serv_vcard.c | 1 - citadel/msgbase.c | 18 +++------- citadel/msgbase.h | 3 +- textclient/tuiconfig.c | 31 ++++++----------- 6 files changed, 51 insertions(+), 47 deletions(-) diff --git a/citadel/config.c b/citadel/config.c index 326c82c02..c84d8f9e4 100644 --- a/citadel/config.c +++ b/citadel/config.c @@ -447,9 +447,13 @@ void CtdlGetSysConfigBackend(long msgnum, void *userdata) { } + +/* + * 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]; @@ -460,14 +464,22 @@ char *CtdlGetSysConfig(char *sysconfname) { 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 { @@ -483,7 +495,7 @@ char *CtdlGetSysConfig(char *sysconfname) { 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]); @@ -495,5 +507,17 @@ char *CtdlGetSysConfig(char *sysconfname) { void CtdlPutSysConfig(char *sysconfname, char *sysconfdata) { - CtdlWriteObject(SYSCONFIGROOM, sysconfname, sysconfdata, (strlen(sysconfdata)+1), NULL, 0, 1, 0); + long msgnum = -1; + + // Search for the previous copy of this config item, deleting it if it is found. + msgnum = CtdlGetConfigLong(sysconfname); + if (msgnum > 0) { + CtdlDeleteMessages(SYSCONFIGROOM, &msgnum, 1, ""); + } + + // Go ahead and save it, and write the new msgnum to the config database so we can find it again + msgnum = CtdlWriteObject(SYSCONFIGROOM, sysconfname, sysconfdata, (strlen(sysconfdata)+1), NULL, 0, 0); + if (msgnum > 0) { + CtdlSetConfigLong(sysconfname, msgnum); + } } diff --git a/citadel/modules/calendar/serv_calendar.c b/citadel/modules/calendar/serv_calendar.c index 55d64d9ff..0a9090d17 100644 --- a/citadel/modules/calendar/serv_calendar.c +++ b/citadel/modules/calendar/serv_calendar.c @@ -120,7 +120,6 @@ void ical_write_to_cal(struct ctdluser *u, icalcomponent *cal) { serlen + 1, /* length */ u, /* which user */ 0, /* not binary */ - 0, /* don't delete others of this type */ 0 /* no flags */ ); } diff --git a/citadel/modules/vcard/serv_vcard.c b/citadel/modules/vcard/serv_vcard.c index dbb9255f9..d828dc73c 100644 --- a/citadel/modules/vcard/serv_vcard.c +++ b/citadel/modules/vcard/serv_vcard.c @@ -533,7 +533,6 @@ void vcard_write_user(struct ctdluser *u, struct vCard *v) { strlen(ser)+1, /* length */ u, /* which user */ 0, /* not binary */ - 0, /* don't delete others of this type */ 0); /* no flags */ free(ser); diff --git a/citadel/msgbase.c b/citadel/msgbase.c index 77bc94615..63bbf006c 100644 --- a/citadel/msgbase.c +++ b/citadel/msgbase.c @@ -3478,16 +3478,14 @@ void AdjRefCount(long msgnum, int incr) /* * Write a generic object to this room * - * Note: this could be much more efficient. Right now we use two temporary - * files, and still pull the message into memory as with all others. + * Returns the message number of the written object, in case you need it. */ -void CtdlWriteObject(char *req_room, /* Room to stuff it in */ +long CtdlWriteObject(char *req_room, /* Room to stuff it in */ char *content_type, /* MIME type of this object */ char *raw_message, /* Data to be written */ off_t raw_length, /* Size of raw_message */ struct ctdluser *is_mailbox, /* Mailbox room? */ int is_binary, /* Is encoding necessary? */ - int is_unique, /* Del others of this type? */ unsigned int flags /* Internal save flags */ ) { struct ctdlroom qrbuf; @@ -3545,17 +3543,11 @@ void CtdlWriteObject(char *req_room, /* Room to stuff it in */ if (CtdlGetRoom(&qrbuf, roomname) != 0) { CtdlCreateRoom(roomname, ( (is_mailbox != NULL) ? 5 : 3 ), "", 0, 1, 0, VIEW_BBS); } - /* If the caller specified this object as unique, delete all - * other objects of this type that are currently in the room. - */ - if (is_unique) { - syslog(LOG_DEBUG, "msgbase: deleted %d other msgs of this type", - CtdlDeleteMessages(roomname, NULL, 0, content_type) - ); - } + /* Now write the data */ - CtdlSubmitMsg(msg, NULL, roomname); + long new_msgnum = CtdlSubmitMsg(msg, NULL, roomname); CM_Free(msg); + return new_msgnum; } diff --git a/citadel/msgbase.h b/citadel/msgbase.h index aecfc4bf9..053e43d07 100644 --- a/citadel/msgbase.h +++ b/citadel/msgbase.h @@ -96,13 +96,12 @@ int CtdlForEachMessage(int mode, ForEachMsgCallback CallBack, void *userdata); int CtdlDeleteMessages(const char *, long *, int, char *); -void CtdlWriteObject(char *req_room, /* Room to stuff it in */ +long CtdlWriteObject(char *req_room, /* Room to stuff it in */ char *content_type, /* MIME type of this object */ char *raw_message, /* Data to be written */ off_t raw_length, /* Size of raw_message */ struct ctdluser *is_mailbox, /* Mailbox room? */ int is_binary, /* Is encoding necessary? */ - int is_unique, /* Del others of this type? */ unsigned int flags /* Internal save flags */ ); struct CtdlMessage *CtdlFetchMessage(long msgnum, int with_body); diff --git a/textclient/tuiconfig.c b/textclient/tuiconfig.c index 6372daf87..4a5fb9709 100644 --- a/textclient/tuiconfig.c +++ b/textclient/tuiconfig.c @@ -25,11 +25,7 @@ char editor_path[PATH_MAX]; /* * General system configuration command */ -void do_system_configuration(CtdlIPC * ipc) -{ - - /* NUM_CONFIGS is now defined in citadel.h */ - +void do_system_configuration(CtdlIPC * ipc) { char buf[256]; char sc[NUM_CONFIGS][256]; char *resp = NULL; @@ -53,8 +49,9 @@ void do_system_configuration(CtdlIPC * ipc) } } } - if (resp) + if (resp) { free(resp); + } resp = NULL; /* Fetch the expire policy (this will silently fail on old servers, * resulting in "default" policy) @@ -91,13 +88,15 @@ void do_system_configuration(CtdlIPC * ipc) if (!IsEmptyStr(&sc[18][0])) { logpages = 1; - } else { + } + else { logpages = 0; } logpages = boolprompt("Log all instant messages", logpages); if (logpages) { strprompt("Name of logging room", &sc[18][0], ROOMNAMELEN); - } else { + } + else { sc[18][0] = 0; } @@ -117,7 +116,6 @@ void do_system_configuration(CtdlIPC * ipc) strprompt("Minimum number of worker threads", &sc[21][0], 3); strprompt("Maximum number of worker threads", &sc[22][0], 3); snprintf(sc[43], sizeof sc[43], "%d", (boolprompt("Automatically delete committed database logs", atoi(&sc[43][0])))); - strprompt("Server IP address (* for 'any')", &sc[37][0], 15); strprompt("POP3 server port (-1 to disable)", &sc[23][0], 5); strprompt("POP3S server port (-1 to disable)", &sc[40][0], 5); @@ -130,10 +128,8 @@ void do_system_configuration(CtdlIPC * ipc) strprompt("NNTPS server port (-1 to disable)", &sc[71][0], 5); strprompt("Postfix TCP Dictionary Port server port (-1 to disable)", &sc[50][0], 5); strprompt("ManageSieve server port (-1 to disable)", &sc[51][0], 5); - strprompt("XMPP (Jabber) client to server port (-1 to disable)", &sc[62][0], 5); - /* No prompt because we don't implement this service yet, it's just a placeholder */ - /* strprompt("XMPP (Jabber) server to server port (-1 to disable)", &sc[63][0], 5); */ + // strprompt("XMPP (Jabber) server to server port (-1 to disable)", &sc[63][0], 5); This is just a placeholder. /* This logic flips the question around, because it's one of those * situations where 0=yes and 1=no @@ -233,9 +229,7 @@ void do_system_configuration(CtdlIPC * ipc) strprompt("Default frequency to run POP3 collection (in seconds)", &sc[64][0], 5); strprompt("Fastest frequency to run POP3 collection (in seconds)", &sc[65][0], 5); strprompt("Hour to run purges (0-23)", &sc[31][0], 2); - snprintf(sc[42], sizeof sc[42], "%d", (boolprompt("Enable full text search index (warning: resource intensive)", - atoi(&sc[42][0])))); - + snprintf(sc[42], sizeof sc[42], "%d", (boolprompt("Enable full text search index (warning: resource intensive)", atoi(&sc[42][0])))); snprintf(sc[46], sizeof sc[46], "%d", (boolprompt("Perform journaling of email messages", atoi(&sc[46][0])))); snprintf(sc[47], sizeof sc[47], "%d", (boolprompt("Perform journaling of non-email messages", atoi(&sc[47][0])))); if ((atoi(&sc[46][0])) || (atoi(&sc[47][0]))) { @@ -250,8 +244,9 @@ void do_system_configuration(CtdlIPC * ipc) /* External pager stuff */ int yes_pager = 0; - if (strlen(sc[60]) > 0) + if (strlen(sc[60]) > 0) { yes_pager = 1; + } yes_pager = boolprompt("Configure an external pager tool", yes_pager); if (yes_pager) { strprompt("External pager tool", &sc[60][0], 255); @@ -754,10 +749,6 @@ void do_pop3client_configuration(CtdlIPC * ipc) } - - - - /* * RSS feed retrieval client configuration */ -- 2.30.2