]> git.sommitrealweird.co.uk Git - onak.git/blob - onak-conf.c
cscvs to tla changeset 73
[onak.git] / onak-conf.c
1 /*
2  * onak-conf.c - Routines related to runtime config.
3  *
4  * Jonathan McDowell <noodles@earth.li>
5  *
6  * Copyright 2002 Project Purple
7  */
8
9 #include <ctype.h>
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <string.h>
13
14 #include "ll.h"
15 #include "log.h"
16 #include "onak-conf.h"
17
18 /*
19  *      config - Runtime configuration for onak.
20  *
21  *      This is the default config; normally overridden with values from the
22  *      config file.
23  */
24 struct onak_config config = {
25         128,                    /* maxkeys */
26         NULL,                   /* thissite */
27         NULL,                   /* adminemail */
28         NULL,                   /* mta */
29         NULL,                   /* syncsites */
30         NULL,                   /* logfile */
31
32         /*
33          * Options for directory backends.
34          */
35         NULL,                   /* db_dir */
36
37         /*
38          * Options for the Postgres backend.
39          */
40         NULL,                   /* pg_dbhost */
41         NULL,                   /* pg_dbname */
42         NULL,                   /* pg_dbuser */
43         NULL,                   /* pg_dbpass */
44 };
45
46 void readconfig(void) {
47         FILE *conffile;
48         char  curline[1024];
49         int   i;
50
51         curline[1023] = 0;
52         conffile = fopen(CONFIGFILE, "r");
53         if (conffile != NULL) {
54                 fgets(curline, 1023, conffile);
55
56                 while (!feof(conffile)) {
57                 for (i = strlen(curline) - 1; isspace(curline[i]); i--) {
58                         curline[i] = 0;
59                 }
60
61                 if (curline[0] == '#' || curline[0] == 0) {
62                         /*
63                          * Comment line, ignore.
64                          */
65                 } else if (!strncmp("db_dir ", curline, 7)) {
66                         config.db_dir = strdup(&curline[7]);
67                 } else if (!strncmp("debug ", curline, 6)) {
68                         /*
69                          * Not supported yet; ignore for compatibility with
70                          * pksd.
71                          */
72                 } else if (!strncmp("default_language ", curline, 17)) {
73                         /*
74                          * Not supported yet; ignore for compatibility with
75                          * pksd.
76                          */
77                 } else if (!strncmp("mail_delivery_client ", curline, 21)) {
78                         config.mta = strdup(&curline[21]);
79                 } else if (!strncmp("maintainer_email ", curline, 17)) {
80                         config.adminemail = strdup(&curline[17]);
81                 } else if (!strncmp("mail_intro_file ", curline, 16)) {
82                         /*
83                          * Not supported yet; ignore for compatibility with
84                          * pksd.
85                          */
86                 } else if (!strncmp("help_dir ", curline, 9)) {
87                         /*
88                          * Not supported yet; ignore for compatibility with
89                          * pksd.
90                          */
91                 } else if (!strncmp("max_last ", curline, 9)) {
92                         /*
93                          * Not supported yet; ignore for compatibility with
94                          * pksd.
95                          */
96                 } else if (!strncmp("max_reply_keys ", curline, 15)) {
97                         config.maxkeys = atoi(&curline[15]);
98                 } else if (!strncmp("pg_dbhost ", curline, 10)) {
99                         config.pg_dbhost = strdup(&curline[10]);
100                 } else if (!strncmp("pg_dbname ", curline, 10)) {
101                         config.pg_dbname = strdup(&curline[10]);
102                 } else if (!strncmp("pg_dbuser ", curline, 10)) {
103                         config.pg_dbuser = strdup(&curline[10]);
104                 } else if (!strncmp("pg_dbpass ", curline, 10)) {
105                         config.pg_dbpass = strdup(&curline[10]);
106                 } else if (!strncmp("syncsite ", curline, 9)) {
107                         config.syncsites =
108                                 lladd(config.syncsites, strdup(&curline[9]));
109                 } else if (!strncmp("logfile ", curline, 8)) {
110                         config.logfile = strdup(&curline[8]);
111                 } else if (!strncmp("this_site ", curline, 10)) {
112                         config.thissite = strdup(&curline[10]);
113                 } else if (!strncmp("socket_name ", curline, 12) ||
114                                 !strncmp("pks_bin_dir ", curline, 12) ||
115                                 !strncmp("mail_dir ", curline, 9) ||
116                                 !strncmp("www_port ", curline, 9)) {
117                         /*
118                          * Not applicable; ignored for compatibility with pksd.
119                          */
120                 } else {
121                         logthing(LOGTHING_ERROR,
122                                 "Unknown config line: %s", curline);
123                 }
124
125                         fgets(curline, 1023, conffile);
126                 }
127                 fclose(conffile);
128         } else {
129                 logthing(LOGTHING_NOTICE,
130                                 "Couldn't open config file; using defaults.");
131         }
132 }
133
134 void cleanupconfig(void) {
135         if (config.thissite != NULL) {
136                 free(config.thissite);
137                 config.thissite = NULL;
138         }
139         if (config.adminemail != NULL) {
140                 free(config.adminemail);
141                 config.adminemail = NULL;
142         }
143         if (config.mta != NULL) {
144                 free(config.mta);
145                 config.mta = NULL;
146         }
147         if (config.db_dir != NULL) {
148                 free(config.db_dir);
149                 config.db_dir = NULL;
150         }
151         if (config.pg_dbhost != NULL) {
152                 free(config.pg_dbhost);
153                 config.pg_dbhost = NULL;
154         }
155         if (config.pg_dbname != NULL) {
156                 free(config.pg_dbname);
157                 config.pg_dbname = NULL;
158         }
159         if (config.pg_dbuser != NULL) {
160                 free(config.pg_dbuser);
161                 config.pg_dbuser = NULL;
162         }
163         if (config.pg_dbpass != NULL) {
164                 free(config.pg_dbpass);
165                 config.pg_dbpass = NULL;
166         }
167         if (config.syncsites != NULL) {
168                 llfree(config.syncsites, free);
169                 config.syncsites = NULL;
170         }
171         if (config.logfile != NULL) {
172                 free(config.logfile);
173                 config.logfile = NULL;
174         }
175 }