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