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
19 #include <sys/types.h>
21 #if TIME_WITH_SYS_TIME
22 # include <sys/time.h>
26 # include <sys/time.h>
35 #include <libcitadel.h>
38 #include "citserver.h"
46 #include "internet_addressing.h"
51 #include "ctdl_module.h"
54 void inetcfg_setTo(struct CtdlMessage *msg) {
58 if (msg->cm_fields['M']==NULL) return;
59 conf = strdup(msg->cm_fields['M']);
63 extract_token(buf, conf, 0, '\n', sizeof buf);
64 strcpy(conf, &conf[strlen(buf)+1]);
65 } while ( (!IsEmptyStr(conf)) && (!IsEmptyStr(buf)) );
67 if (inetcfg != NULL) free(inetcfg);
73 #ifdef ___NOT_CURRENTLY_IN_USE___
74 void spamstrings_setTo(struct CtdlMessage *msg) {
77 struct spamstrings_t *sptr;
80 /* Clear out the existing list */
81 while (spamstrings != NULL) {
83 spamstrings = spamstrings->next;
88 /* Read in the new list */
89 if (msg->cm_fields['M']==NULL) return;
90 conf = strdup(msg->cm_fields['M']);
91 if (conf == NULL) return;
93 n = num_tokens(conf, '\n');
95 extract_token(buf, conf, i, '\n', sizeof buf);
96 sptr = malloc(sizeof(struct spamstrings_t));
97 sptr->string = strdup(buf);
98 sptr->next = spamstrings;
107 * This handler detects changes being made to the system's Internet
110 int inetcfg_aftersave(struct CtdlMessage *msg) {
114 /* If this isn't the configuration room, or if this isn't a MIME
115 * message, don't bother.
117 if (strcasecmp(msg->cm_fields['O'], SYSCONFIGROOM)) return(0);
118 if (msg->cm_format_type != 4) return(0);
120 ptr = msg->cm_fields['M'];
121 while (ptr != NULL) {
123 linelen = strcspn(ptr, "\n");
124 if (linelen == 0) return(0); /* end of headers */
126 if (!strncasecmp(ptr, "Content-type: ", 14)) {
127 if (!strncasecmp(&ptr[14], INTERNETCFG,
128 strlen(INTERNETCFG))) {
129 inetcfg_setTo(msg); /* changing configs */
133 ptr = strchr((char *)ptr, '\n');
134 if (ptr != NULL) ++ptr;
141 void inetcfg_init_backend(long msgnum, void *userdata) {
142 struct CtdlMessage *msg;
144 msg = CtdlFetchMessage(msgnum, 1);
147 CtdlFreeMessage(msg);
152 #ifdef ___NOT_CURRENTLY_IN_USE___
153 void spamstrings_init_backend(long msgnum, void *userdata) {
154 struct CtdlMessage *msg;
156 msg = CtdlFetchMessage(msgnum, 1);
158 spamstrings_setTo(msg);
159 CtdlFreeMessage(msg);
165 void inetcfg_init(void) {
166 if (getroom(&CC->room, SYSCONFIGROOM) != 0) return;
167 CtdlForEachMessage(MSGS_LAST, 1, NULL, INTERNETCFG, NULL,
168 inetcfg_init_backend, NULL);
174 /*****************************************************************************/
175 /* MODULE INITIALIZATION STUFF */
176 /*****************************************************************************/
179 CTDL_MODULE_INIT(inetcfg)
183 CtdlRegisterMessageHook(inetcfg_aftersave, EVT_AFTERSAVE);
187 /* return our Subversion id for the Log */