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>
37 #include "sysdep_decls.h"
38 #include "citserver.h"
41 #include "serv_extensions.h"
48 #include "internet_addressing.h"
55 void inetcfg_setTo(struct CtdlMessage *msg) {
59 if (msg->cm_fields['M']==NULL) return;
60 conf = strdup(msg->cm_fields['M']);
64 extract_token(buf, conf, 0, '\n');
65 strcpy(conf, &conf[strlen(buf)+1]);
66 } while ( (strlen(conf)>0) && (strlen(buf)>0) );
68 if (inetcfg != NULL) free(inetcfg);
74 #ifdef ___NOT_CURRENTLY_IN_USE___
75 void spamstrings_setTo(struct CtdlMessage *msg) {
78 struct spamstrings_t *sptr;
81 /* Clear out the existing list */
82 while (spamstrings != NULL) {
84 spamstrings = spamstrings->next;
89 /* Read in the new list */
90 if (msg->cm_fields['M']==NULL) return;
91 conf = strdup(msg->cm_fields['M']);
92 if (conf == NULL) return;
94 n = num_tokens(conf, '\n');
96 extract_token(buf, conf, i, '\n');
97 sptr = malloc(sizeof(struct spamstrings_t));
98 sptr->string = strdup(buf);
99 sptr->next = spamstrings;
108 * This handler detects changes being made to the system's Internet
111 int inetcfg_aftersave(struct CtdlMessage *msg) {
115 /* If this isn't the configuration room, or if this isn't a MIME
116 * message, don't bother.
118 if (strcasecmp(msg->cm_fields['O'], SYSCONFIGROOM)) return(0);
119 if (msg->cm_format_type != 4) return(0);
121 ptr = msg->cm_fields['M'];
122 while (ptr != NULL) {
124 linelen = strcspn(ptr, "\n");
125 if (linelen == 0) return(0); /* end of headers */
127 if (!strncasecmp(ptr, "Content-type: ", 14)) {
128 if (!strncasecmp(&ptr[14], INTERNETCFG,
129 strlen(INTERNETCFG))) {
130 inetcfg_setTo(msg); /* changing configs */
132 #ifdef ___NOT_CURRENTLY_IN_USE___
133 if (!strncasecmp(&ptr[14], SPAMSTRINGS,
134 strlen(INTERNETCFG))) {
135 spamstrings_setTo(msg); /* changing configs */
140 ptr = strchr((char *)ptr, '\n');
141 if (ptr != NULL) ++ptr;
148 void inetcfg_init_backend(long msgnum, void *userdata) {
149 struct CtdlMessage *msg;
151 msg = CtdlFetchMessage(msgnum);
154 CtdlFreeMessage(msg);
159 #ifdef ___NOT_CURRENTLY_IN_USE___
160 void spamstrings_init_backend(long msgnum, void *userdata) {
161 struct CtdlMessage *msg;
163 msg = CtdlFetchMessage(msgnum);
165 spamstrings_setTo(msg);
166 CtdlFreeMessage(msg);
172 void inetcfg_init(void) {
173 if (getroom(&CC->room, SYSCONFIGROOM) != 0) return;
174 CtdlForEachMessage(MSGS_LAST, 1, INTERNETCFG, NULL,
175 inetcfg_init_backend, NULL);
177 CtdlForEachMessage(MSGS_LAST, 1, SPAMSTRINGS, NULL,
178 spamstrings_init_backend, NULL);
185 /*****************************************************************************/
186 /* MODULE INITIALIZATION STUFF */
187 /*****************************************************************************/
190 char *serv_inetcfg_init(void)
192 CtdlRegisterMessageHook(inetcfg_aftersave, EVT_AFTERSAVE);