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 */
37 * Options for directory backends.
42 * Options for the Postgres backend.
50 * Options for dynamic backends.
52 NULL, /* db_backend */
53 NULL, /* backends_dir */
55 &DBFUNCS, /* Default dbfuncs struct */
58 void readconfig(const char *configfile) {
64 if (configfile == NULL) {
65 conffile = fopen(CONFIGFILE, "r");
67 conffile = fopen(configfile, "r");
69 if (conffile != NULL) {
70 fgets(curline, 1023, conffile);
72 while (!feof(conffile)) {
73 for (i = strlen(curline) - 1;
74 i >= 0 && isspace(curline[i]);
79 if (curline[0] == '#' || curline[0] == 0) {
81 * Comment line, ignore.
83 } else if (!strncmp("db_dir ", curline, 7)) {
84 config.db_dir = strdup(&curline[7]);
85 } else if (!strncmp("debug ", curline, 6)) {
87 * Not supported yet; ignore for compatibility with
90 } else if (!strncmp("default_language ", curline, 17)) {
92 * Not supported yet; ignore for compatibility with
95 } else if (!strncmp("mail_delivery_client ", curline, 21)) {
96 config.mta = strdup(&curline[21]);
97 } else if (!strncmp("maintainer_email ", curline, 17)) {
98 config.adminemail = strdup(&curline[17]);
99 } else if (!strncmp("mail_intro_file ", curline, 16)) {
101 * Not supported yet; ignore for compatibility with
104 } else if (!strncmp("help_dir ", curline, 9)) {
106 * Not supported yet; ignore for compatibility with
109 } else if (!strncmp("max_last ", curline, 9)) {
111 * Not supported yet; ignore for compatibility with
114 } else if (!strncmp("max_reply_keys ", curline, 15)) {
115 config.maxkeys = atoi(&curline[15]);
116 } else if (!strncmp("pg_dbhost ", curline, 10)) {
117 config.pg_dbhost = strdup(&curline[10]);
118 } else if (!strncmp("pg_dbname ", curline, 10)) {
119 config.pg_dbname = strdup(&curline[10]);
120 } else if (!strncmp("pg_dbuser ", curline, 10)) {
121 config.pg_dbuser = strdup(&curline[10]);
122 } else if (!strncmp("pg_dbpass ", curline, 10)) {
123 config.pg_dbpass = strdup(&curline[10]);
124 } else if (!strncmp("syncsite ", curline, 9)) {
126 lladd(config.syncsites, strdup(&curline[9]));
127 } else if (!strncmp("logfile ", curline, 8)) {
128 config.logfile = strdup(&curline[8]);
129 } else if (!strncmp("loglevel ", curline, 9)) {
130 setlogthreshold(atoi(&curline[9]));
131 } else if (!strncmp("this_site ", curline, 10)) {
132 config.thissite = strdup(&curline[10]);
133 } else if (!strncmp("socket_name ", curline, 12) ||
134 !strncmp("pks_bin_dir ", curline, 12) ||
135 !strncmp("mail_dir ", curline, 9) ||
136 !strncmp("www_port ", curline, 9)) {
138 * Not applicable; ignored for compatibility with pksd.
140 } else if (!strncmp("db_backend ", curline, 11)) {
141 config.db_backend = strdup(&curline[11]);
142 } else if (!strncmp("backends_dir ", curline, 13)) {
143 config.backends_dir = strdup(&curline[13]);
145 logthing(LOGTHING_ERROR,
146 "Unknown config line: %s", curline);
149 fgets(curline, 1023, conffile);
153 logthing(LOGTHING_NOTICE,
154 "Couldn't open config file; using defaults.");
158 void cleanupconfig(void) {
159 if (config.thissite != NULL) {
160 free(config.thissite);
161 config.thissite = NULL;
163 if (config.adminemail != NULL) {
164 free(config.adminemail);
165 config.adminemail = NULL;
167 if (config.mta != NULL) {
171 if (config.db_dir != NULL) {
173 config.db_dir = NULL;
175 if (config.pg_dbhost != NULL) {
176 free(config.pg_dbhost);
177 config.pg_dbhost = NULL;
179 if (config.pg_dbname != NULL) {
180 free(config.pg_dbname);
181 config.pg_dbname = NULL;
183 if (config.pg_dbuser != NULL) {
184 free(config.pg_dbuser);
185 config.pg_dbuser = NULL;
187 if (config.pg_dbpass != NULL) {
188 free(config.pg_dbpass);
189 config.pg_dbpass = NULL;
191 if (config.syncsites != NULL) {
192 llfree(config.syncsites, free);
193 config.syncsites = NULL;
195 if (config.logfile != NULL) {
196 free(config.logfile);
197 config.logfile = NULL;
199 if (config.db_backend != NULL) {
200 free(config.db_backend);
201 config.db_backend = NULL;
203 if (config.backends_dir != NULL) {
204 free(config.backends_dir);
205 config.backends_dir = NULL;