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"
21 * config - Runtime configuration for onak.
23 * This is the default config; normally overridden with values from the
26 struct onak_config config = {
29 NULL, /* adminemail */
35 * Options for directory backends.
40 * Options for the Postgres backend.
48 * Options for dynamic backends.
50 NULL, /* db_backend */
51 NULL, /* backends_dir */
54 void readconfig(const char *configfile) {
60 if (configfile == NULL) {
61 conffile = fopen(CONFIGFILE, "r");
63 conffile = fopen(configfile, "r");
65 if (conffile != NULL) {
66 fgets(curline, 1023, conffile);
68 while (!feof(conffile)) {
69 for (i = strlen(curline) - 1;
70 i >= 0 && isspace(curline[i]);
75 if (curline[0] == '#' || curline[0] == 0) {
77 * Comment line, ignore.
79 } else if (!strncmp("db_dir ", curline, 7)) {
80 config.db_dir = strdup(&curline[7]);
81 } else if (!strncmp("debug ", curline, 6)) {
83 * Not supported yet; ignore for compatibility with
86 } else if (!strncmp("default_language ", curline, 17)) {
88 * Not supported yet; ignore for compatibility with
91 } else if (!strncmp("mail_delivery_client ", curline, 21)) {
92 config.mta = strdup(&curline[21]);
93 } else if (!strncmp("maintainer_email ", curline, 17)) {
94 config.adminemail = strdup(&curline[17]);
95 } else if (!strncmp("mail_intro_file ", curline, 16)) {
97 * Not supported yet; ignore for compatibility with
100 } else if (!strncmp("help_dir ", curline, 9)) {
102 * Not supported yet; ignore for compatibility with
105 } else if (!strncmp("max_last ", curline, 9)) {
107 * Not supported yet; ignore for compatibility with
110 } else if (!strncmp("max_reply_keys ", curline, 15)) {
111 config.maxkeys = atoi(&curline[15]);
112 } else if (!strncmp("pg_dbhost ", curline, 10)) {
113 config.pg_dbhost = strdup(&curline[10]);
114 } else if (!strncmp("pg_dbname ", curline, 10)) {
115 config.pg_dbname = strdup(&curline[10]);
116 } else if (!strncmp("pg_dbuser ", curline, 10)) {
117 config.pg_dbuser = strdup(&curline[10]);
118 } else if (!strncmp("pg_dbpass ", curline, 10)) {
119 config.pg_dbpass = strdup(&curline[10]);
120 } else if (!strncmp("syncsite ", curline, 9)) {
122 lladd(config.syncsites, strdup(&curline[9]));
123 } else if (!strncmp("logfile ", curline, 8)) {
124 config.logfile = strdup(&curline[8]);
125 } else if (!strncmp("loglevel ", curline, 9)) {
126 setlogthreshold(atoi(&curline[9]));
127 } else if (!strncmp("this_site ", curline, 10)) {
128 config.thissite = strdup(&curline[10]);
129 } else if (!strncmp("socket_name ", curline, 12) ||
130 !strncmp("pks_bin_dir ", curline, 12) ||
131 !strncmp("mail_dir ", curline, 9) ||
132 !strncmp("www_port ", curline, 9)) {
134 * Not applicable; ignored for compatibility with pksd.
136 } else if (!strncmp("db_backend ", curline, 11)) {
137 config.db_backend = strdup(&curline[11]);
138 } else if (!strncmp("backends_dir ", curline, 13)) {
139 config.backends_dir = strdup(&curline[13]);
141 logthing(LOGTHING_ERROR,
142 "Unknown config line: %s", curline);
145 fgets(curline, 1023, conffile);
149 logthing(LOGTHING_NOTICE,
150 "Couldn't open config file; using defaults.");
154 void cleanupconfig(void) {
155 if (config.thissite != NULL) {
156 free(config.thissite);
157 config.thissite = NULL;
159 if (config.adminemail != NULL) {
160 free(config.adminemail);
161 config.adminemail = NULL;
163 if (config.mta != NULL) {
167 if (config.db_dir != NULL) {
169 config.db_dir = NULL;
171 if (config.pg_dbhost != NULL) {
172 free(config.pg_dbhost);
173 config.pg_dbhost = NULL;
175 if (config.pg_dbname != NULL) {
176 free(config.pg_dbname);
177 config.pg_dbname = NULL;
179 if (config.pg_dbuser != NULL) {
180 free(config.pg_dbuser);
181 config.pg_dbuser = NULL;
183 if (config.pg_dbpass != NULL) {
184 free(config.pg_dbpass);
185 config.pg_dbpass = NULL;
187 if (config.syncsites != NULL) {
188 llfree(config.syncsites, free);
189 config.syncsites = NULL;
191 if (config.logfile != NULL) {
192 free(config.logfile);
193 config.logfile = NULL;
195 if (config.db_backend != NULL) {
196 free(config.db_backend);
197 config.db_backend = NULL;
199 if (config.backends_dir != NULL) {
200 free(config.backends_dir);
201 config.backends_dir = NULL;