]> git.sommitrealweird.co.uk Git - onak.git/blob - onak-conf.c
126bd565d4409515bf2f084333e8f27244791283
[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         "/home/noodles/onak-db",        /* db_dir */
34
35         /*
36          * Options for the Postgres backend.
37          */
38         NULL,                   /* pg_dbhost */
39         "noodles",              /* 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 }