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"
59 #include "internet_addressing.h"
64 #include "ctdl_module.h"
67 void inetcfg_setTo(struct CtdlMessage *msg) {
71 if (msg->cm_fields['M']==NULL) return;
72 conf = strdup(msg->cm_fields['M']);
76 extract_token(buf, conf, 0, '\n', sizeof buf);
77 strcpy(conf, &conf[strlen(buf)+1]);
78 } while ( (!IsEmptyStr(conf)) && (!IsEmptyStr(buf)) );
80 if (inetcfg != NULL) free(inetcfg);
86 #ifdef ___NOT_CURRENTLY_IN_USE___
87 void spamstrings_setTo(struct CtdlMessage *msg) {
90 struct spamstrings_t *sptr;
93 /* Clear out the existing list */
94 while (spamstrings != NULL) {
96 spamstrings = spamstrings->next;
101 /* Read in the new list */
102 if (msg->cm_fields['M']==NULL) return;
103 conf = strdup(msg->cm_fields['M']);
104 if (conf == NULL) return;
106 n = num_tokens(conf, '\n');
107 for (i=0; i<n; ++i) {
108 extract_token(buf, conf, i, '\n', sizeof buf);
109 sptr = malloc(sizeof(struct spamstrings_t));
110 sptr->string = strdup(buf);
111 sptr->next = spamstrings;
120 * This handler detects changes being made to the system's Internet
123 int inetcfg_aftersave(struct CtdlMessage *msg) {
127 /* If this isn't the configuration room, or if this isn't a MIME
128 * message, don't bother.
130 if (strcasecmp(msg->cm_fields['O'], SYSCONFIGROOM)) return(0);
131 if (msg->cm_format_type != 4) return(0);
133 ptr = msg->cm_fields['M'];
134 while (ptr != NULL) {
136 linelen = strcspn(ptr, "\n");
137 if (linelen == 0) return(0); /* end of headers */
139 if (!strncasecmp(ptr, "Content-type: ", 14)) {
140 if (!strncasecmp(&ptr[14], INTERNETCFG,
141 strlen(INTERNETCFG))) {
142 inetcfg_setTo(msg); /* changing configs */
146 ptr = strchr((char *)ptr, '\n');
147 if (ptr != NULL) ++ptr;
154 void inetcfg_init_backend(long msgnum, void *userdata) {
155 struct CtdlMessage *msg;
157 msg = CtdlFetchMessage(msgnum, 1);
160 CtdlFreeMessage(msg);
165 #ifdef ___NOT_CURRENTLY_IN_USE___
166 void spamstrings_init_backend(long msgnum, void *userdata) {
167 struct CtdlMessage *msg;
169 msg = CtdlFetchMessage(msgnum, 1);
171 spamstrings_setTo(msg);
172 CtdlFreeMessage(msg);
178 void inetcfg_init(void) {
179 if (CtdlGetRoom(&CC->room, SYSCONFIGROOM) != 0) return;
180 CtdlForEachMessage(MSGS_LAST, 1, NULL, INTERNETCFG, NULL,
181 inetcfg_init_backend, NULL);
187 /*****************************************************************************/
188 /* MODULE INITIALIZATION STUFF */
189 /*****************************************************************************/
192 CTDL_MODULE_INIT(inetcfg)
196 CtdlRegisterMessageHook(inetcfg_aftersave, EVT_AFTERSAVE);
200 /* return our Subversion id for the Log */