citadel
About: Citadel is an advanced messaging and collaboration system for groupware and BBS applications (preferred OS: Linux).
  Fossies Dox: citadel.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

serv_inetcfg.c
Go to the documentation of this file.
1/*
2 * This module handles the loading/saving and maintenance of the
3 * system's Internet configuration. It's not an optional component; I
4 * wrote it as a module merely to keep things as clean and loosely coupled
5 * as possible.
6 *
7 * Copyright (c) 1987-2021 by the citadel.org team
8 *
9 * This program is open source software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 3.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 */
17
18#include "sysdep.h"
19#include <stdlib.h>
20#include <unistd.h>
21#include <stdio.h>
22#include <fcntl.h>
23#include <signal.h>
24#include <pwd.h>
25#include <errno.h>
26#include <sys/types.h>
27#include <time.h>
28#include <sys/wait.h>
29#include <string.h>
30#include <limits.h>
31#include <libcitadel.h>
32#include "citadel.h"
33#include "server.h"
34#include "citserver.h"
35#include "support.h"
36#include "config.h"
37#include "user_ops.h"
38#include "database.h"
39#include "msgbase.h"
40#include "internet_addressing.h"
41#include "genstamp.h"
42#include "domain.h"
43#include "ctdl_module.h"
44
45
46void inetcfg_setTo(struct CtdlMessage *msg) {
47 char *conf;
48 char buf[SIZ];
49
50 if (CM_IsEmpty(msg, eMesageText)) return;
51 conf = strdup(msg->cm_fields[eMesageText]);
52
53 if (conf != NULL) {
54 do {
55 extract_token(buf, conf, 0, '\n', sizeof buf);
56 strcpy(conf, &conf[strlen(buf)+1]);
57 } while ( (!IsEmptyStr(conf)) && (!IsEmptyStr(buf)) );
58
59 if (inetcfg != NULL) free(inetcfg);
60 inetcfg = conf;
61 }
62}
63
64
65/*
66 * This handler detects changes being made to the system's Internet
67 * configuration.
68 */
69int inetcfg_aftersave(struct CtdlMessage *msg, struct recptypes *recp) {
70 char *ptr;
71 int linelen;
72
73 /* If this isn't the configuration room, or if this isn't a MIME
74 * message, don't bother.
75 */
76 if ((msg->cm_fields[eOriginalRoom]) && (strcasecmp(msg->cm_fields[eOriginalRoom], SYSCONFIGROOM))) {
77 return(0);
78 }
79 if (msg->cm_format_type != 4) {
80 return(0);
81 }
82
83 ptr = msg->cm_fields[eMesageText];
84 while (ptr != NULL) {
85
86 linelen = strcspn(ptr, "\n");
87 if (linelen == 0) {
88 return(0); /* end of headers */
89 }
90
91 if (!strncasecmp(ptr, "Content-type: ", 14)) {
92 if (!strncasecmp(&ptr[14], INTERNETCFG, strlen(INTERNETCFG))) {
93 inetcfg_setTo(msg); /* changing configs */
94 }
95 }
96
97 ptr = strchr((char *)ptr, '\n');
98 if (ptr != NULL) ++ptr;
99 }
100
101 return(0);
102}
103
104
105void inetcfg_init_backend(long msgnum, void *userdata) {
106 struct CtdlMessage *msg;
107
108 msg = CtdlFetchMessage(msgnum, 1);
109 if (msg != NULL) {
110 inetcfg_setTo(msg);
111 CM_Free(msg);
112 }
113}
114
115
116void inetcfg_init(void) {
117 syslog(LOG_DEBUG, "EVQ: called inetcfg_init()");
118 if (CtdlGetRoom(&CC->room, SYSCONFIGROOM) != 0) {
119 return;
120 }
121 CtdlForEachMessage(MSGS_LAST, 1, NULL, INTERNETCFG, NULL, inetcfg_init_backend, NULL);
122}
123
124
125/*****************************************************************************/
126/* MODULE INITIALIZATION STUFF */
127/*****************************************************************************/
128
129
131{
132 if (!threading)
133 {
135 inetcfg_init();
136 }
137
138 /* return our module name for the log */
139 return "inetcfg";
140}
#define CC
Definition: context.h:140
int CtdlGetRoom(struct ctdlroom *qrbuf, const char *room_name)
Definition: room_ops.c:342
void CtdlRegisterMessageHook(int(*handler)(struct CtdlMessage *, struct recptypes *), int EventType)
#define CTDL_MODULE_INIT(module_name)
Definition: ctdl_module.h:50
char * inetcfg
void CM_Free(struct CtdlMessage *msg)
Definition: msgbase.c:310
int CtdlForEachMessage(int mode, long ref, char *search_string, char *content_type, struct CtdlMessage *compare, ForEachMsgCallback CallBack, void *userdata)
Definition: msgbase.c:626
struct CtdlMessage * CtdlFetchMessage(long msgnum, int with_body)
Definition: msgbase.c:1135
int CM_IsEmpty(struct CtdlMessage *Msg, eMsgField which)
Definition: msgbase.c:137
@ MSGS_LAST
Definition: msgbase.h:10
void free(void *)
void inetcfg_init(void)
Definition: serv_inetcfg.c:116
void inetcfg_setTo(struct CtdlMessage *msg)
Definition: serv_inetcfg.c:46
int inetcfg_aftersave(struct CtdlMessage *msg, struct recptypes *recp)
Definition: serv_inetcfg.c:69
void inetcfg_init_backend(long msgnum, void *userdata)
Definition: serv_inetcfg.c:105
@ eMesageText
Definition: server.h:315
@ eOriginalRoom
Definition: server.h:316
#define EVT_AFTERSAVE
Definition: server.h:232
char * cm_fields[256]
Definition: server.h:37
char cm_format_type
Definition: server.h:36
#define SIZ
Definition: sysconfig.h:33
#define SYSCONFIGROOM
Definition: sysconfig.h:72