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"
52 void inetcfg_setTo(struct CtdlMessage *msg) {
56 if (msg->cm_fields['M']==NULL) return;
57 conf = strdoop(msg->cm_fields['M']);
61 extract_token(buf, conf, 0, '\n');
62 strcpy(conf, &conf[strlen(buf)+1]);
63 } while ( (strlen(conf)>0) && (strlen(buf)>0) );
65 if (inetcfg != NULL) phree(inetcfg);
72 * This handler detects changes being made to the system's Internet
75 int inetcfg_aftersave(struct CtdlMessage *msg) {
79 /* If this isn't the configuration room, or if this isn't a MIME
80 * message, don't bother.
82 if (strcasecmp(msg->cm_fields['O'], SYSCONFIGROOM)) return(0);
83 if (msg->cm_format_type != 4) return(0);
85 ptr = msg->cm_fields['M'];
88 linelen = strcspn(ptr, "\n");
89 if (linelen == 0) return(0); /* end of headers */
91 if ( (!strncasecmp(ptr, "Content-type: ", 14))
92 && (!strncasecmp(&ptr[14], INTERNETCFG,
93 strlen(INTERNETCFG) )) ) {
94 /* Bingo! The user is changing configs.
99 ptr = strchr((char *)ptr, '\n');
100 if (ptr != NULL) ++ptr;
107 void inetcfg_init_backend(long msgnum, void *userdata) {
108 struct CtdlMessage *msg;
110 msg = CtdlFetchMessage(msgnum);
113 CtdlFreeMessage(msg);
118 void inetcfg_init(void) {
119 if (getroom(&CC->quickroom, SYSCONFIGROOM) != 0) return;
120 CtdlForEachMessage(MSGS_LAST, 1, INTERNETCFG, NULL,
121 inetcfg_init_backend, NULL);
127 /*****************************************************************************/
128 /* MODULE INITIALIZATION STUFF */
129 /*****************************************************************************/
132 char *Dynamic_Module_Init(void)
134 CtdlRegisterMessageHook(inetcfg_aftersave, EVT_AFTERSAVE);