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"
60 #include "internet_addressing.h"
65 #include "ctdl_module.h"
68 void inetcfg_setTo(struct CtdlMessage *msg) {
72 if (msg->cm_fields['M']==NULL) return;
73 conf = strdup(msg->cm_fields['M']);
77 extract_token(buf, conf, 0, '\n', sizeof buf);
78 strcpy(conf, &conf[strlen(buf)+1]);
79 } while ( (!IsEmptyStr(conf)) && (!IsEmptyStr(buf)) );
81 if (inetcfg != NULL) free(inetcfg);
87 #ifdef ___NOT_CURRENTLY_IN_USE___
88 void spamstrings_setTo(struct CtdlMessage *msg) {
91 struct spamstrings_t *sptr;
94 /* Clear out the existing list */
95 while (spamstrings != NULL) {
97 spamstrings = spamstrings->next;
102 /* Read in the new list */
103 if (msg->cm_fields['M']==NULL) return;
104 conf = strdup(msg->cm_fields['M']);
105 if (conf == NULL) return;
107 n = num_tokens(conf, '\n');
108 for (i=0; i<n; ++i) {
109 extract_token(buf, conf, i, '\n', sizeof buf);
110 sptr = malloc(sizeof(struct spamstrings_t));
111 sptr->string = strdup(buf);
112 sptr->next = spamstrings;
121 * This handler detects changes being made to the system's Internet
124 int inetcfg_aftersave(struct CtdlMessage *msg) {
128 /* If this isn't the configuration room, or if this isn't a MIME
129 * message, don't bother.
131 if (strcasecmp(msg->cm_fields['O'], SYSCONFIGROOM)) return(0);
132 if (msg->cm_format_type != 4) return(0);
134 ptr = msg->cm_fields['M'];
135 while (ptr != NULL) {
137 linelen = strcspn(ptr, "\n");
138 if (linelen == 0) return(0); /* end of headers */
140 if (!strncasecmp(ptr, "Content-type: ", 14)) {
141 if (!strncasecmp(&ptr[14], INTERNETCFG,
142 strlen(INTERNETCFG))) {
143 inetcfg_setTo(msg); /* changing configs */
147 ptr = strchr((char *)ptr, '\n');
148 if (ptr != NULL) ++ptr;
155 void inetcfg_init_backend(long msgnum, void *userdata) {
156 struct CtdlMessage *msg;
158 msg = CtdlFetchMessage(msgnum, 1);
161 CtdlFreeMessage(msg);
166 #ifdef ___NOT_CURRENTLY_IN_USE___
167 void spamstrings_init_backend(long msgnum, void *userdata) {
168 struct CtdlMessage *msg;
170 msg = CtdlFetchMessage(msgnum, 1);
172 spamstrings_setTo(msg);
173 CtdlFreeMessage(msg);
179 void inetcfg_init(void) {
180 if (CtdlGetRoom(&CC->room, SYSCONFIGROOM) != 0) return;
181 CtdlForEachMessage(MSGS_LAST, 1, NULL, INTERNETCFG, NULL,
182 inetcfg_init_backend, NULL);
188 /*****************************************************************************/
189 /* MODULE INITIALIZATION STUFF */
190 /*****************************************************************************/
193 CTDL_MODULE_INIT(inetcfg)
197 CtdlRegisterMessageHook(inetcfg_aftersave, EVT_AFTERSAVE);
201 /* return our Subversion id for the Log */