2 * onak-conf.c - Routines related to runtime config.
4 * Jonathan McDowell <noodles@earth.li>
6 * Copyright 2002 Project Purple
8 * $Id: onak-conf.c,v 1.7 2003/06/04 20:57:11 noodles Exp $
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 void readconfig(void) {
54 conffile = fopen(CONFIGFILE, "r");
55 if (conffile != NULL) {
56 fgets(curline, 1023, conffile);
58 while (!feof(conffile)) {
59 for (i = strlen(curline) - 1; isspace(curline[i]); i--) {
63 if (curline[0] == '#' || curline[0] == 0) {
65 * Comment line, ignore.
67 } else if (!strncmp("db_dir ", curline, 7)) {
68 config.db_dir = strdup(&curline[7]);
69 } else if (!strncmp("debug ", curline, 6)) {
71 * Not supported yet; ignore for compatibility with
74 } else if (!strncmp("default_language ", curline, 17)) {
76 * Not supported yet; ignore for compatibility with
79 } else if (!strncmp("mail_delivery_client ", curline, 21)) {
80 config.mta = strdup(&curline[21]);
81 } else if (!strncmp("maintainer_email ", curline, 17)) {
82 config.adminemail = strdup(&curline[17]);
83 } else if (!strncmp("mail_intro_file ", curline, 16)) {
85 * Not supported yet; ignore for compatibility with
88 } else if (!strncmp("help_dir ", curline, 9)) {
90 * Not supported yet; ignore for compatibility with
93 } else if (!strncmp("max_last ", curline, 9)) {
95 * Not supported yet; ignore for compatibility with
98 } else if (!strncmp("max_reply_keys ", curline, 15)) {
99 config.maxkeys = atoi(&curline[15]);
100 } else if (!strncmp("pg_dbhost ", curline, 10)) {
101 config.pg_dbhost = strdup(&curline[10]);
102 } else if (!strncmp("pg_dbname ", curline, 10)) {
103 config.pg_dbname = strdup(&curline[10]);
104 } else if (!strncmp("pg_dbuser ", curline, 10)) {
105 config.pg_dbuser = strdup(&curline[10]);
106 } else if (!strncmp("pg_dbpass ", curline, 10)) {
107 config.pg_dbpass = strdup(&curline[10]);
108 } else if (!strncmp("syncsite ", curline, 9)) {
110 lladd(config.syncsites, strdup(&curline[9]));
111 } else if (!strncmp("logfile ", curline, 8)) {
112 config.logfile = strdup(&curline[8]);
113 } else if (!strncmp("this_site ", curline, 10)) {
114 config.thissite = strdup(&curline[10]);
115 } else if (!strncmp("socket_name ", curline, 12) ||
116 !strncmp("pks_bin_dir ", curline, 12) ||
117 !strncmp("mail_dir ", curline, 9) ||
118 !strncmp("www_port ", curline, 9)) {
120 * Not applicable; ignored for compatibility with pksd.
123 logthing(LOGTHING_ERROR,
124 "Unknown config line: %s", curline);
127 fgets(curline, 1023, conffile);
131 logthing(LOGTHING_NOTICE,
132 "Couldn't open config file; using defaults.");
136 void cleanupconfig(void) {
137 if (config.thissite != NULL) {
138 free(config.thissite);
139 config.thissite = NULL;
141 if (config.adminemail != NULL) {
142 free(config.adminemail);
143 config.adminemail = NULL;
145 if (config.mta != NULL) {
149 if (config.db_dir != NULL) {
151 config.db_dir = NULL;
153 if (config.pg_dbhost != NULL) {
154 free(config.pg_dbhost);
155 config.pg_dbhost = NULL;
157 if (config.pg_dbname != NULL) {
158 free(config.pg_dbname);
159 config.pg_dbname = NULL;
161 if (config.pg_dbuser != NULL) {
162 free(config.pg_dbuser);
163 config.pg_dbuser = NULL;
165 if (config.pg_dbpass != NULL) {
166 free(config.pg_dbpass);
167 config.pg_dbpass = NULL;
169 if (config.syncsites != NULL) {
170 llfree(config.syncsites, free);
171 config.syncsites = NULL;
173 if (config.logfile != NULL) {
174 free(config.logfile);
175 config.logfile = NULL;