2 * This module handles the loading/saving and maintenance of the
3 * system's Internet configuration. It's not an optional component; I
4 * wrote it as a module merely to keep things as clean and loosely coupled
7 * Copyright (c) 1987-2022 by the citadel.org team
9 * This program is open source software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 3.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
18 #include "../../sysdep.h"
26 #include <sys/types.h>
31 #include <libcitadel.h>
32 #include "../../citadel.h"
33 #include "../../server.h"
34 #include "../../citserver.h"
35 #include "../../support.h"
36 #include "../../config.h"
37 #include "../../user_ops.h"
38 #include "../../database.h"
39 #include "../../msgbase.h"
40 #include "../../internet_addressing.h"
41 #include "../../genstamp.h"
42 #include "../../domain.h"
43 #include "../../ctdl_module.h"
46 void inetcfg_setTo(struct CtdlMessage *msg) {
50 if (CM_IsEmpty(msg, eMesageText)) return;
51 conf = strdup(msg->cm_fields[eMesageText]);
55 extract_token(buf, conf, 0, '\n', sizeof buf);
56 strcpy(conf, &conf[strlen(buf)+1]);
57 } while ( (!IsEmptyStr(conf)) && (!IsEmptyStr(buf)) );
59 if (inetcfg != NULL) free(inetcfg);
66 * This handler detects changes being made to the system's Internet
69 int inetcfg_aftersave(struct CtdlMessage *msg, struct recptypes *recp) {
73 /* If this isn't the configuration room, or if this isn't a MIME
74 * message, don't bother.
76 if ((msg->cm_fields[eOriginalRoom]) && (strcasecmp(msg->cm_fields[eOriginalRoom], SYSCONFIGROOM))) {
79 if (msg->cm_format_type != 4) {
83 ptr = msg->cm_fields[eMesageText];
86 linelen = strcspn(ptr, "\n");
88 return(0); /* end of headers */
91 if (!strncasecmp(ptr, "Content-type: ", 14)) {
92 if (!strncasecmp(&ptr[14], INTERNETCFG, strlen(INTERNETCFG))) {
93 inetcfg_setTo(msg); /* changing configs */
97 ptr = strchr((char *)ptr, '\n');
98 if (ptr != NULL) ++ptr;
105 void inetcfg_init_backend(long msgnum, void *userdata) {
106 struct CtdlMessage *msg;
108 msg = CtdlFetchMessage(msgnum, 1);
116 void inetcfg_init(void) {
117 syslog(LOG_DEBUG, "EVQ: called inetcfg_init()");
118 if (CtdlGetRoom(&CC->room, SYSCONFIGROOM) != 0) {
121 CtdlForEachMessage(MSGS_LAST, 1, NULL, INTERNETCFG, NULL, inetcfg_init_backend, NULL);
125 /*****************************************************************************/
126 /* MODULE INITIALIZATION STUFF */
127 /*****************************************************************************/
130 char *ctdl_module_init_inetcfg(void) {
132 CtdlRegisterMessageHook(inetcfg_aftersave, EVT_AFTERSAVE);
136 /* return our module name for the log */