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>
27 #include "sysdep_decls.h"
28 #include "citserver.h"
31 #include "dynloader.h"
38 #include "internet_addressing.h"
42 void inetcfg_setTo(struct CtdlMessage *msg) {
46 if (msg->cm_fields['M']==NULL) return;
47 conf = strdoop(msg->cm_fields['M']);
51 extract_token(buf, conf, 0, '\n');
52 strcpy(conf, &conf[strlen(buf)+1]);
53 } while ( (strlen(conf)>0) && (strlen(buf)>0) );
55 if (inetcfg != NULL) phree(inetcfg);
62 * This handler detects changes being made to the system's Internet
65 int inetcfg_aftersave(struct CtdlMessage *msg) {
69 /* If this isn't the configuration room, or if this isn't a MIME
70 * message, don't bother.
72 if (strcasecmp(msg->cm_fields['O'], SYSCONFIGROOM)) return(0);
73 if (msg->cm_format_type != 4) return(0);
75 ptr = msg->cm_fields['M'];
78 linelen = strcspn(ptr, "\n");
79 if (linelen == 0) return(0); /* end of headers */
81 if ( (!strncasecmp(ptr, "Content-type: ", 14))
82 && (!strncasecmp(&ptr[14], INTERNETCFG,
83 strlen(INTERNETCFG) )) ) {
84 /* Bingo! The user is changing configs.
89 ptr = strchr((char *)ptr, '\n');
90 if (ptr != NULL) ++ptr;
97 void inetcfg_init_backend(long msgnum, void *userdata) {
98 struct CtdlMessage *msg;
100 msg = CtdlFetchMessage(msgnum);
103 CtdlFreeMessage(msg);
108 void inetcfg_init(void) {
109 if (getroom(&CC->quickroom, SYSCONFIGROOM) != 0) return;
110 CtdlForEachMessage(MSGS_LAST, 1, (-127), INTERNETCFG, NULL,
111 inetcfg_init_backend, NULL);
117 /*****************************************************************************/
118 /* MODULE INITIALIZATION STUFF */
119 /*****************************************************************************/
122 char *Dynamic_Module_Init(void)
124 CtdlRegisterMessageHook(inetcfg_aftersave, EVT_AFTERSAVE);