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 "dynloader.h"
48 #include "internet_addressing.h"
55 void inetcfg_setTo(struct CtdlMessage *msg) {
59 if (msg->cm_fields['M']==NULL) return;
60 conf = strdoop(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) phree(inetcfg);
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 = strdoop(msg->cm_fields['M']);
91 if (conf == NULL) return;
93 n = num_tokens(conf, '\n');
95 extract_token(buf, conf, i, '\n');
96 sptr = mallok(sizeof(struct spamstrings_t));
97 sptr->string = strdoop(buf);
98 sptr->next = spamstrings;
106 * This handler detects changes being made to the system's Internet
109 int inetcfg_aftersave(struct CtdlMessage *msg) {
113 /* If this isn't the configuration room, or if this isn't a MIME
114 * message, don't bother.
116 if (strcasecmp(msg->cm_fields['O'], SYSCONFIGROOM)) return(0);
117 if (msg->cm_format_type != 4) return(0);
119 ptr = msg->cm_fields['M'];
120 while (ptr != NULL) {
122 linelen = strcspn(ptr, "\n");
123 if (linelen == 0) return(0); /* end of headers */
125 if (!strncasecmp(ptr, "Content-type: ", 14)) {
126 if (!strncasecmp(&ptr[14], INTERNETCFG,
127 strlen(INTERNETCFG))) {
128 inetcfg_setTo(msg); /* changing configs */
130 if (!strncasecmp(&ptr[14], SPAMSTRINGS,
131 strlen(INTERNETCFG))) {
132 spamstrings_setTo(msg); /* changing configs */
136 ptr = strchr((char *)ptr, '\n');
137 if (ptr != NULL) ++ptr;
144 void inetcfg_init_backend(long msgnum, void *userdata) {
145 struct CtdlMessage *msg;
147 msg = CtdlFetchMessage(msgnum);
150 CtdlFreeMessage(msg);
155 void spamstrings_init_backend(long msgnum, void *userdata) {
156 struct CtdlMessage *msg;
158 msg = CtdlFetchMessage(msgnum);
160 spamstrings_setTo(msg);
161 CtdlFreeMessage(msg);
166 void inetcfg_init(void) {
167 if (getroom(&CC->quickroom, SYSCONFIGROOM) != 0) return;
168 CtdlForEachMessage(MSGS_LAST, 1, INTERNETCFG, NULL,
169 inetcfg_init_backend, NULL);
170 CtdlForEachMessage(MSGS_LAST, 1, SPAMSTRINGS, NULL,
171 spamstrings_init_backend, NULL);
177 /*****************************************************************************/
178 /* MODULE INITIALIZATION STUFF */
179 /*****************************************************************************/
182 char *Dynamic_Module_Init(void)
184 CtdlRegisterMessageHook(inetcfg_aftersave, EVT_AFTERSAVE);