4 * This module handles the loading/saving and maintenance of the
5 * system's Internet configuration. It's not an optional component; I
6 * wrote it as a module merely to keep things as clean and loosely coupled
9 * Copyright (c) 1987-2009 by the citadel.org team
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 3 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
34 #include <sys/types.h>
36 #if TIME_WITH_SYS_TIME
37 # include <sys/time.h>
41 # include <sys/time.h>
50 #include <libcitadel.h>
53 #include "citserver.h"
61 #include "internet_addressing.h"
66 #include "ctdl_module.h"
69 void inetcfg_setTo(struct CtdlMessage *msg) {
73 if (msg->cm_fields['M']==NULL) return;
74 conf = strdup(msg->cm_fields['M']);
78 extract_token(buf, conf, 0, '\n', sizeof buf);
79 strcpy(conf, &conf[strlen(buf)+1]);
80 } while ( (!IsEmptyStr(conf)) && (!IsEmptyStr(buf)) );
82 if (inetcfg != NULL) free(inetcfg);
88 #ifdef ___NOT_CURRENTLY_IN_USE___
89 void spamstrings_setTo(struct CtdlMessage *msg) {
92 struct spamstrings_t *sptr;
95 /* Clear out the existing list */
96 while (spamstrings != NULL) {
98 spamstrings = spamstrings->next;
103 /* Read in the new list */
104 if (msg->cm_fields['M']==NULL) return;
105 conf = strdup(msg->cm_fields['M']);
106 if (conf == NULL) return;
108 n = num_tokens(conf, '\n');
109 for (i=0; i<n; ++i) {
110 extract_token(buf, conf, i, '\n', sizeof buf);
111 sptr = malloc(sizeof(struct spamstrings_t));
112 sptr->string = strdup(buf);
113 sptr->next = spamstrings;
122 * This handler detects changes being made to the system's Internet
125 int inetcfg_aftersave(struct CtdlMessage *msg) {
129 /* If this isn't the configuration room, or if this isn't a MIME
130 * message, don't bother.
132 if (strcasecmp(msg->cm_fields['O'], SYSCONFIGROOM)) return(0);
133 if (msg->cm_format_type != 4) return(0);
135 ptr = msg->cm_fields['M'];
136 while (ptr != NULL) {
138 linelen = strcspn(ptr, "\n");
139 if (linelen == 0) return(0); /* end of headers */
141 if (!strncasecmp(ptr, "Content-type: ", 14)) {
142 if (!strncasecmp(&ptr[14], INTERNETCFG,
143 strlen(INTERNETCFG))) {
144 inetcfg_setTo(msg); /* changing configs */
148 ptr = strchr((char *)ptr, '\n');
149 if (ptr != NULL) ++ptr;
156 void inetcfg_init_backend(long msgnum, void *userdata) {
157 struct CtdlMessage *msg;
159 msg = CtdlFetchMessage(msgnum, 1);
162 CtdlFreeMessage(msg);
167 #ifdef ___NOT_CURRENTLY_IN_USE___
168 void spamstrings_init_backend(long msgnum, void *userdata) {
169 struct CtdlMessage *msg;
171 msg = CtdlFetchMessage(msgnum, 1);
173 spamstrings_setTo(msg);
174 CtdlFreeMessage(msg);
180 void inetcfg_init(void) {
181 if (getroom(&CC->room, SYSCONFIGROOM) != 0) return;
182 CtdlForEachMessage(MSGS_LAST, 1, NULL, INTERNETCFG, NULL,
183 inetcfg_init_backend, NULL);
189 /*****************************************************************************/
190 /* MODULE INITIALIZATION STUFF */
191 /*****************************************************************************/
194 CTDL_MODULE_INIT(inetcfg)
198 CtdlRegisterMessageHook(inetcfg_aftersave, EVT_AFTERSAVE);
202 /* return our Subversion id for the Log */