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