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-2017 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.
26 #include <sys/types.h>
28 #if TIME_WITH_SYS_TIME
29 # include <sys/time.h>
33 # include <sys/time.h>
42 #include <libcitadel.h>
45 #include "citserver.h"
51 #include "internet_addressing.h"
54 #include "ctdl_module.h"
57 void inetcfg_setTo(struct CtdlMessage *msg) {
61 if (CM_IsEmpty(msg, eMesageText)) return;
62 conf = strdup(msg->cm_fields[eMesageText]);
66 extract_token(buf, conf, 0, '\n', sizeof buf);
67 strcpy(conf, &conf[strlen(buf)+1]);
68 } while ( (!IsEmptyStr(conf)) && (!IsEmptyStr(buf)) );
70 if (inetcfg != NULL) free(inetcfg);
77 * This handler detects changes being made to the system's Internet
80 int inetcfg_aftersave(struct CtdlMessage *msg, recptypes *recp) {
84 /* If this isn't the configuration room, or if this isn't a MIME
85 * message, don't bother.
87 if ((msg->cm_fields[eOriginalRoom]) && (strcasecmp(msg->cm_fields[eOriginalRoom], SYSCONFIGROOM))) {
90 if (msg->cm_format_type != 4) {
94 ptr = msg->cm_fields[eMesageText];
97 linelen = strcspn(ptr, "\n");
99 return(0); /* end of headers */
102 if (!strncasecmp(ptr, "Content-type: ", 14)) {
103 if (!strncasecmp(&ptr[14], INTERNETCFG, strlen(INTERNETCFG))) {
104 inetcfg_setTo(msg); /* changing configs */
108 ptr = strchr((char *)ptr, '\n');
109 if (ptr != NULL) ++ptr;
116 void inetcfg_init_backend(long msgnum, void *userdata) {
117 struct CtdlMessage *msg;
119 msg = CtdlFetchMessage(msgnum, 1, 1);
127 void inetcfg_init(void) {
128 syslog(LOG_DEBUG, "EVQ: called inetcfg_init()");
129 if (CtdlGetRoom(&CC->room, SYSCONFIGROOM) != 0) {
132 CtdlForEachMessage(MSGS_LAST, 1, NULL, INTERNETCFG, NULL, inetcfg_init_backend, NULL);
136 /*****************************************************************************/
137 /* MODULE INITIALIZATION STUFF */
138 /*****************************************************************************/
139 void cleanup_inetcfg(void)
150 CTDL_MODULE_INIT(inetcfg)
154 CtdlRegisterMessageHook(inetcfg_aftersave, EVT_AFTERSAVE);
156 CtdlRegisterCleanupHook(cleanup_inetcfg);
159 /* return our module name for the log */