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