]> the.earth.li Git - onak.git/blob - onak-conf.c
Add subkey support to keydb_fs backend.
[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(const char *configfile) {
47         FILE *conffile;
48         char  curline[1024];
49         int   i;
50
51         curline[1023] = 0;
52         if (configfile == NULL) {
53                 conffile = fopen(CONFIGFILE, "r");
54         } else {
55                 conffile = fopen(configfile, "r");
56         }
57         if (conffile != NULL) {
58                 fgets(curline, 1023, conffile);
59
60                 while (!feof(conffile)) {
61                 for (i = strlen(curline) - 1; isspace(curline[i]); i--) {
62                         curline[i] = 0;
63                 }
64
65                 if (curline[0] == '#' || curline[0] == 0) {
66                         /*
67                          * Comment line, ignore.
68                          */
69                 } else if (!strncmp("db_dir ", curline, 7)) {
70                         config.db_dir = strdup(&curline[7]);
71                 } else if (!strncmp("debug ", curline, 6)) {
72                         /*
73                          * Not supported yet; ignore for compatibility with
74                          * pksd.
75                          */
76                 } else if (!strncmp("default_language ", curline, 17)) {
77                         /*
78                          * Not supported yet; ignore for compatibility with
79                          * pksd.
80                          */
81                 } else if (!strncmp("mail_delivery_client ", curline, 21)) {
82                         config.mta = strdup(&curline[21]);
83                 } else if (!strncmp("maintainer_email ", curline, 17)) {
84                         config.adminemail = strdup(&curline[17]);
85                 } else if (!strncmp("mail_intro_file ", curline, 16)) {
86                         /*
87                          * Not supported yet; ignore for compatibility with
88                          * pksd.
89                          */
90                 } else if (!strncmp("help_dir ", curline, 9)) {
91                         /*
92                          * Not supported yet; ignore for compatibility with
93                          * pksd.
94                          */
95                 } else if (!strncmp("max_last ", curline, 9)) {
96                         /*
97                          * Not supported yet; ignore for compatibility with
98                          * pksd.
99                          */
100                 } else if (!strncmp("max_reply_keys ", curline, 15)) {
101                         config.maxkeys = atoi(&curline[15]);
102                 } else if (!strncmp("pg_dbhost ", curline, 10)) {
103                         config.pg_dbhost = strdup(&curline[10]);
104                 } else if (!strncmp("pg_dbname ", curline, 10)) {
105                         config.pg_dbname = strdup(&curline[10]);
106                 } else if (!strncmp("pg_dbuser ", curline, 10)) {
107                         config.pg_dbuser = strdup(&curline[10]);
108                 } else if (!strncmp("pg_dbpass ", curline, 10)) {
109                         config.pg_dbpass = strdup(&curline[10]);
110                 } else if (!strncmp("syncsite ", curline, 9)) {
111                         config.syncsites =
112                                 lladd(config.syncsites, strdup(&curline[9]));
113                 } else if (!strncmp("logfile ", curline, 8)) {
114                         config.logfile = strdup(&curline[8]);
115                 } else if (!strncmp("loglevel ", curline, 9)) {
116                         setlogthreshold(atoi(&curline[9]));
117                 } else if (!strncmp("this_site ", curline, 10)) {
118                         config.thissite = strdup(&curline[10]);
119                 } else if (!strncmp("socket_name ", curline, 12) ||
120                                 !strncmp("pks_bin_dir ", curline, 12) ||
121                                 !strncmp("mail_dir ", curline, 9) ||
122                                 !strncmp("www_port ", curline, 9)) {
123                         /*
124                          * Not applicable; ignored for compatibility with pksd.
125                          */
126                 } else {
127                         logthing(LOGTHING_ERROR,
128                                 "Unknown config line: %s", curline);
129                 }
130
131                         fgets(curline, 1023, conffile);
132                 }
133                 fclose(conffile);
134         } else {
135                 logthing(LOGTHING_NOTICE,
136                                 "Couldn't open config file; using defaults.");
137         }
138 }
139
140 void cleanupconfig(void) {
141         if (config.thissite != NULL) {
142                 free(config.thissite);
143                 config.thissite = NULL;
144         }
145         if (config.adminemail != NULL) {
146                 free(config.adminemail);
147                 config.adminemail = NULL;
148         }
149         if (config.mta != NULL) {
150                 free(config.mta);
151                 config.mta = NULL;
152         }
153         if (config.db_dir != NULL) {
154                 free(config.db_dir);
155                 config.db_dir = NULL;
156         }
157         if (config.pg_dbhost != NULL) {
158                 free(config.pg_dbhost);
159                 config.pg_dbhost = NULL;
160         }
161         if (config.pg_dbname != NULL) {
162                 free(config.pg_dbname);
163                 config.pg_dbname = NULL;
164         }
165         if (config.pg_dbuser != NULL) {
166                 free(config.pg_dbuser);
167                 config.pg_dbuser = NULL;
168         }
169         if (config.pg_dbpass != NULL) {
170                 free(config.pg_dbpass);
171                 config.pg_dbpass = NULL;
172         }
173         if (config.syncsites != NULL) {
174                 llfree(config.syncsites, free);
175                 config.syncsites = NULL;
176         }
177         if (config.logfile != NULL) {
178                 free(config.logfile);
179                 config.logfile = NULL;
180         }
181 }