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', sizeof buf);
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', sizeof buf);
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 */
134 ptr = strchr((char *)ptr, '\n');
135 if (ptr != NULL) ++ptr;
142 void inetcfg_init_backend(long msgnum, void *userdata) {
143 struct CtdlMessage *msg;
145 msg = CtdlFetchMessage(msgnum, 1);
148 CtdlFreeMessage(msg);
153 #ifdef ___NOT_CURRENTLY_IN_USE___
154 void spamstrings_init_backend(long msgnum, void *userdata) {
155 struct CtdlMessage *msg;
157 msg = CtdlFetchMessage(msgnum, 1);
159 spamstrings_setTo(msg);
160 CtdlFreeMessage(msg);
166 void inetcfg_init(void) {
167 if (getroom(&CC->room, SYSCONFIGROOM) != 0) return;
168 CtdlForEachMessage(MSGS_LAST, 1, NULL, INTERNETCFG, NULL,
169 inetcfg_init_backend, NULL);
175 /*****************************************************************************/
176 /* MODULE INITIALIZATION STUFF */
177 /*****************************************************************************/
180 char *serv_inetcfg_init(void)
182 CtdlRegisterMessageHook(inetcfg_aftersave, EVT_AFTERSAVE);