2 * onak-conf.c - Routines related to runtime config.
4 * Jonathan McDowell <noodles@earth.li>
6 * Copyright 2002 Project Purple
18 #include "onak-conf.h"
20 extern struct dbfuncs DBFUNCS;
23 * config - Runtime configuration for onak.
25 * This is the default config; normally overridden with values from the
28 struct onak_config config = {
31 NULL, /* adminemail */
39 * Options for directory backends.
44 * Options for the Postgres backend.
52 * Options for dynamic backends.
54 NULL, /* db_backend */
55 NULL, /* backends_dir */
57 &DBFUNCS, /* Default dbfuncs struct */
60 bool parsebool(char *str, bool fallback)
62 if (!strcasecmp(str, "false") || !strcasecmp(str, "no") ||
63 !strcasecmp(str, "0")) {
65 } else if (!strcasecmp(str, "true") || !strcasecmp(str, "yes") ||
66 !strcasecmp(str, "1")) {
69 logthing(LOGTHING_CRITICAL,
70 "Couldn't parse %s as a boolean config variable, "
71 "returning fallback of '%s'.",
73 fallback ? "true" : "false");
78 void readconfig(const char *configfile) {
84 if (configfile == NULL) {
85 conffile = fopen(CONFIGFILE, "r");
87 conffile = fopen(configfile, "r");
89 if (conffile != NULL) {
90 fgets(curline, 1023, conffile);
92 while (!feof(conffile)) {
93 for (i = strlen(curline) - 1;
94 i >= 0 && isspace(curline[i]);
99 if (curline[0] == '#' || curline[0] == 0) {
101 * Comment line, ignore.
103 } else if (!strncmp("db_dir ", curline, 7)) {
104 config.db_dir = strdup(&curline[7]);
105 } else if (!strncmp("debug ", curline, 6)) {
107 * Not supported yet; ignore for compatibility with
110 } else if (!strncmp("default_language ", curline, 17)) {
112 * Not supported yet; ignore for compatibility with
115 } else if (!strncmp("mail_delivery_client ", curline, 21)) {
116 config.mta = strdup(&curline[21]);
117 } else if (!strncmp("maintainer_email ", curline, 17)) {
118 config.adminemail = strdup(&curline[17]);
119 } else if (!strncmp("mail_intro_file ", curline, 16)) {
121 * Not supported yet; ignore for compatibility with
124 } else if (!strncmp("help_dir ", curline, 9)) {
126 * Not supported yet; ignore for compatibility with
129 } else if (!strncmp("max_last ", curline, 9)) {
131 * Not supported yet; ignore for compatibility with
134 } else if (!strncmp("max_reply_keys ", curline, 15)) {
135 config.maxkeys = atoi(&curline[15]);
136 } else if (!strncmp("pg_dbhost ", curline, 10)) {
137 config.pg_dbhost = strdup(&curline[10]);
138 } else if (!strncmp("pg_dbname ", curline, 10)) {
139 config.pg_dbname = strdup(&curline[10]);
140 } else if (!strncmp("pg_dbuser ", curline, 10)) {
141 config.pg_dbuser = strdup(&curline[10]);
142 } else if (!strncmp("pg_dbpass ", curline, 10)) {
143 config.pg_dbpass = strdup(&curline[10]);
144 } else if (!strncmp("syncsite ", curline, 9)) {
146 lladd(config.syncsites, strdup(&curline[9]));
147 } else if (!strncmp("logfile ", curline, 8)) {
148 config.logfile = strdup(&curline[8]);
149 } else if (!strncmp("loglevel ", curline, 9)) {
150 setlogthreshold(atoi(&curline[9]));
151 } else if (!strncmp("this_site ", curline, 10)) {
152 config.thissite = strdup(&curline[10]);
153 } else if (!strncmp("socket_name ", curline, 12) ||
154 !strncmp("pks_bin_dir ", curline, 12) ||
155 !strncmp("mail_dir ", curline, 9) ||
156 !strncmp("www_port ", curline, 9)) {
158 * Not applicable; ignored for compatibility with pksd.
160 } else if (!strncmp("db_backend ", curline, 11)) {
161 config.db_backend = strdup(&curline[11]);
162 } else if (!strncmp("backends_dir ", curline, 13)) {
163 config.backends_dir = strdup(&curline[13]);
164 } else if (!strncmp("use_keyd ", curline, 9)) {
165 config.use_keyd = parsebool(&curline[9],
168 logthing(LOGTHING_ERROR,
169 "Unknown config line: %s", curline);
172 fgets(curline, 1023, conffile);
176 logthing(LOGTHING_NOTICE,
177 "Couldn't open config file; using defaults.");
181 void cleanupconfig(void) {
182 if (config.thissite != NULL) {
183 free(config.thissite);
184 config.thissite = NULL;
186 if (config.adminemail != NULL) {
187 free(config.adminemail);
188 config.adminemail = NULL;
190 if (config.mta != NULL) {
194 if (config.db_dir != NULL) {
196 config.db_dir = NULL;
198 if (config.pg_dbhost != NULL) {
199 free(config.pg_dbhost);
200 config.pg_dbhost = NULL;
202 if (config.pg_dbname != NULL) {
203 free(config.pg_dbname);
204 config.pg_dbname = NULL;
206 if (config.pg_dbuser != NULL) {
207 free(config.pg_dbuser);
208 config.pg_dbuser = NULL;
210 if (config.pg_dbpass != NULL) {
211 free(config.pg_dbpass);
212 config.pg_dbpass = NULL;
214 if (config.syncsites != NULL) {
215 llfree(config.syncsites, free);
216 config.syncsites = NULL;
218 if (config.logfile != NULL) {
219 free(config.logfile);
220 config.logfile = NULL;
222 if (config.db_backend != NULL) {
223 free(config.db_backend);
224 config.db_backend = NULL;
226 if (config.backends_dir != NULL) {
227 free(config.backends_dir);
228 config.backends_dir = NULL;