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-2009 by the citadel.org team
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
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.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
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['M']==NULL) return;
70 conf = strdup(msg->cm_fields['M']);
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);
84 #ifdef ___NOT_CURRENTLY_IN_USE___
85 void spamstrings_setTo(struct CtdlMessage *msg) {
88 struct spamstrings_t *sptr;
91 /* Clear out the existing list */
92 while (spamstrings != NULL) {
94 spamstrings = spamstrings->next;
99 /* Read in the new list */
100 if (msg->cm_fields['M']==NULL) return;
101 conf = strdup(msg->cm_fields['M']);
102 if (conf == NULL) return;
104 n = num_tokens(conf, '\n');
105 for (i=0; i<n; ++i) {
106 extract_token(buf, conf, i, '\n', sizeof buf);
107 sptr = malloc(sizeof(struct spamstrings_t));
108 sptr->string = strdup(buf);
109 sptr->next = spamstrings;
118 * This handler detects changes being made to the system's Internet
121 int inetcfg_aftersave(struct CtdlMessage *msg) {
125 /* If this isn't the configuration room, or if this isn't a MIME
126 * message, don't bother.
128 if (strcasecmp(msg->cm_fields['O'], SYSCONFIGROOM)) return(0);
129 if (msg->cm_format_type != 4) return(0);
131 ptr = msg->cm_fields['M'];
132 while (ptr != NULL) {
134 linelen = strcspn(ptr, "\n");
135 if (linelen == 0) return(0); /* end of headers */
137 if (!strncasecmp(ptr, "Content-type: ", 14)) {
138 if (!strncasecmp(&ptr[14], INTERNETCFG,
139 strlen(INTERNETCFG))) {
140 inetcfg_setTo(msg); /* changing configs */
144 ptr = strchr((char *)ptr, '\n');
145 if (ptr != NULL) ++ptr;
152 void inetcfg_init_backend(long msgnum, void *userdata) {
153 struct CtdlMessage *msg;
155 msg = CtdlFetchMessage(msgnum, 1);
158 CtdlFreeMessage(msg);
163 #ifdef ___NOT_CURRENTLY_IN_USE___
164 void spamstrings_init_backend(long msgnum, void *userdata) {
165 struct CtdlMessage *msg;
167 msg = CtdlFetchMessage(msgnum, 1);
169 spamstrings_setTo(msg);
170 CtdlFreeMessage(msg);
176 void inetcfg_init(void) {
177 if (CtdlGetRoom(&CC->room, SYSCONFIGROOM) != 0) return;
178 CtdlForEachMessage(MSGS_LAST, 1, NULL, INTERNETCFG, NULL,
179 inetcfg_init_backend, NULL);
185 /*****************************************************************************/
186 /* MODULE INITIALIZATION STUFF */
187 /*****************************************************************************/
188 void clenaup_inetcfg(void)
198 CTDL_MODULE_INIT(inetcfg)
202 CtdlRegisterMessageHook(inetcfg_aftersave, EVT_AFTERSAVE);
204 CtdlRegisterCleanupHook(clenaup_inetcfg);
207 /* return our Subversion id for the Log */