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-2012 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.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
32 #include <sys/types.h>
34 #if TIME_WITH_SYS_TIME
35 # include <sys/time.h>
39 # include <sys/time.h>
48 #include <libcitadel.h>
51 #include "citserver.h"
57 #include "internet_addressing.h"
62 #include "ctdl_module.h"
65 void inetcfg_setTo(struct CtdlMessage *msg) {
69 if (msg->cm_fields[eMesageText]==NULL) return;
70 conf = strdup(msg->cm_fields[eMesageText]);
74 extract_token(buf, conf, 0, '\n', sizeof buf);
75 strcpy(conf, &conf[strlen(buf)+1]);
76 } while ( (!IsEmptyStr(conf)) && (!IsEmptyStr(buf)) );
78 if (inetcfg != NULL) free(inetcfg);
85 * This handler detects changes being made to the system's Internet
88 int inetcfg_aftersave(struct CtdlMessage *msg) {
92 /* If this isn't the configuration room, or if this isn't a MIME
93 * message, don't bother.
95 if (strcasecmp(msg->cm_fields[eOriginalRoom], SYSCONFIGROOM)) return(0);
96 if (msg->cm_format_type != 4) return(0);
98 ptr = msg->cm_fields[eMesageText];
101 linelen = strcspn(ptr, "\n");
102 if (linelen == 0) return(0); /* end of headers */
104 if (!strncasecmp(ptr, "Content-type: ", 14)) {
105 if (!strncasecmp(&ptr[14], INTERNETCFG,
106 strlen(INTERNETCFG))) {
107 inetcfg_setTo(msg); /* changing configs */
111 ptr = strchr((char *)ptr, '\n');
112 if (ptr != NULL) ++ptr;
119 void inetcfg_init_backend(long msgnum, void *userdata) {
120 struct CtdlMessage *msg;
122 msg = CtdlFetchMessage(msgnum, 1);
125 CtdlFreeMessage(msg);
130 void inetcfg_init(void) {
131 if (CtdlGetRoom(&CC->room, SYSCONFIGROOM) != 0) return;
132 CtdlForEachMessage(MSGS_LAST, 1, NULL, INTERNETCFG, NULL,
133 inetcfg_init_backend, NULL);
139 /*****************************************************************************/
140 /* MODULE INITIALIZATION STUFF */
141 /*****************************************************************************/
142 void clenaup_inetcfg(void)
152 CTDL_MODULE_INIT(inetcfg)
156 CtdlRegisterMessageHook(inetcfg_aftersave, EVT_AFTERSAVE);
158 CtdlRegisterCleanupHook(clenaup_inetcfg);
161 /* return our module name for the log */