7d7c54aeceb26fb83ca15ef25e6a972fcab19abb
[citadel.git] / citadel / serv_inetcfg.c
1 /* $Id$ 
2  *
3  * This module handles the loading/saving and maintenance of the
4  * system's Internet configuration.
5  */
6
7 #include "sysdep.h"
8 #include <stdlib.h>
9 #include <unistd.h>
10 #include <stdio.h>
11 #include <fcntl.h>
12 #include <signal.h>
13 #include <pwd.h>
14 #include <errno.h>
15 #include <sys/types.h>
16 #include <sys/time.h>
17 #include <sys/wait.h>
18 #include <string.h>
19 #include <limits.h>
20 #include "citadel.h"
21 #include "server.h"
22 #include <time.h>
23 #include "sysdep_decls.h"
24 #include "citserver.h"
25 #include "support.h"
26 #include "config.h"
27 #include "dynloader.h"
28 #include "room_ops.h"
29 #include "user_ops.h"
30 #include "policy.h"
31 #include "database.h"
32 #include "msgbase.h"
33 #include "tools.h"
34 #include "internet_addressing.h"
35 #include "genstamp.h"
36 #include "domain.h"
37
38
39 /*
40  * This handler detects changes being made to the system's Internet
41  * configuration.
42  */
43 int inetcfg_aftersave(struct CtdlMessage *msg) {
44         char *ptr;
45         int linelen;
46
47         /* If this isn't the configuration room, or if this isn't a MIME
48          * message, don't bother.
49          */
50         if (strcasecmp(msg->cm_fields['O'], SYSCONFIGROOM)) return(0);
51         if (msg->cm_format_type != 4) return(0);
52
53         ptr = msg->cm_fields['M'];
54         while (ptr != NULL) {
55         
56                 linelen = strcspn(ptr, "\n");
57                 if (linelen == 0) return(0);    /* end of headers */    
58                 
59                 if ( (!strncasecmp(ptr, "Content-type: ", 14))
60                    && (!strncasecmp(&ptr[14], INTERNETCFG,
61                    strlen(INTERNETCFG) )) ) {
62                         /* Bingo!  The user is changing configs.
63                          */
64                         lprintf(9, "Internet configuration changed FIX\n");
65                 }
66
67                 ptr = strchr((char *)ptr, '\n');
68                 if (ptr != NULL) ++ptr;
69         }
70
71         return(0);
72 }
73
74
75
76 /*****************************************************************************/
77 /*                      MODULE INITIALIZATION STUFF                          */
78 /*****************************************************************************/
79
80
81 char *Dynamic_Module_Init(void)
82 {
83         CtdlRegisterMessageHook(inetcfg_aftersave, EVT_AFTERSAVE);
84         return "$Id$";
85 }
86