]> code.citadel.org Git - citadel.git/blob - citadel/serv_inetcfg.c
* Started working on the spam filter
[citadel.git] / citadel / serv_inetcfg.c
1 /*
2  * $Id$ 
3  *
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
7  * as possible.
8  *
9  */
10
11 #include "sysdep.h"
12 #include <stdlib.h>
13 #include <unistd.h>
14 #include <stdio.h>
15 #include <fcntl.h>
16 #include <signal.h>
17 #include <pwd.h>
18 #include <errno.h>
19 #include <sys/types.h>
20
21 #if TIME_WITH_SYS_TIME
22 # include <sys/time.h>
23 # include <time.h>
24 #else
25 # if HAVE_SYS_TIME_H
26 #  include <sys/time.h>
27 # else
28 #  include <time.h>
29 # endif
30 #endif
31
32 #include <sys/wait.h>
33 #include <string.h>
34 #include <limits.h>
35 #include "citadel.h"
36 #include "server.h"
37 #include "sysdep_decls.h"
38 #include "citserver.h"
39 #include "support.h"
40 #include "config.h"
41 #include "dynloader.h"
42 #include "room_ops.h"
43 #include "user_ops.h"
44 #include "policy.h"
45 #include "database.h"
46 #include "msgbase.h"
47 #include "tools.h"
48 #include "internet_addressing.h"
49 #include "genstamp.h"
50 #include "domain.h"
51
52 void inetcfg_setTo(struct CtdlMessage *msg) {
53         char *conf;
54         char buf[SIZ];
55
56         if (msg->cm_fields['M']==NULL) return;
57         conf = strdoop(msg->cm_fields['M']);
58
59         if (conf != NULL) {
60                 do {
61                         extract_token(buf, conf, 0, '\n');
62                         strcpy(conf, &conf[strlen(buf)+1]);
63                 } while ( (strlen(conf)>0) && (strlen(buf)>0) );
64
65                 if (inetcfg != NULL) phree(inetcfg);
66                 inetcfg = conf;
67         }
68 }
69
70
71 /*
72  * This handler detects changes being made to the system's Internet
73  * configuration.
74  */
75 int inetcfg_aftersave(struct CtdlMessage *msg) {
76         char *ptr;
77         int linelen;
78
79         /* If this isn't the configuration room, or if this isn't a MIME
80          * message, don't bother.
81          */
82         if (strcasecmp(msg->cm_fields['O'], SYSCONFIGROOM)) return(0);
83         if (msg->cm_format_type != 4) return(0);
84
85         ptr = msg->cm_fields['M'];
86         while (ptr != NULL) {
87         
88                 linelen = strcspn(ptr, "\n");
89                 if (linelen == 0) return(0);    /* end of headers */    
90                 
91                 if (!strncasecmp(ptr, "Content-type: ", 14)) {
92                         if (!strncasecmp(&ptr[14], INTERNETCFG,
93                            strlen(INTERNETCFG))) {
94                                 /* Bingo!  The user is changing configs.
95                                 */
96                                 inetcfg_setTo(msg);
97                         }
98                 }
99
100                 ptr = strchr((char *)ptr, '\n');
101                 if (ptr != NULL) ++ptr;
102         }
103
104         return(0);
105 }
106
107
108 void inetcfg_init_backend(long msgnum, void *userdata) {
109         struct CtdlMessage *msg;
110
111         msg = CtdlFetchMessage(msgnum);
112         if (msg != NULL) {
113                 inetcfg_setTo(msg);
114                 CtdlFreeMessage(msg);
115         }
116 }
117
118
119 void inetcfg_init(void) {
120         if (getroom(&CC->quickroom, SYSCONFIGROOM) != 0) return;
121         CtdlForEachMessage(MSGS_LAST, 1, INTERNETCFG, NULL,
122                 inetcfg_init_backend, NULL);
123 }
124
125
126
127
128 /*****************************************************************************/
129 /*                      MODULE INITIALIZATION STUFF                          */
130 /*****************************************************************************/
131
132
133 char *Dynamic_Module_Init(void)
134 {
135         CtdlRegisterMessageHook(inetcfg_aftersave, EVT_AFTERSAVE);
136         inetcfg_init();
137         return "$Id$";
138 }
139