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 void readconfig(const char *configfile) {
54 if (configfile == NULL) {
55 conffile = fopen(CONFIGFILE, "r");
57 conffile = fopen(configfile, "r");
59 if (conffile != NULL) {
60 fgets(curline, 1023, conffile);
62 while (!feof(conffile)) {
63 for (i = strlen(curline) - 1;
64 i >= 0 && isspace(curline[i]);
69 if (curline[0] == '#' || curline[0] == 0) {
71 * Comment line, ignore.
73 } else if (!strncmp("db_dir ", curline, 7)) {
74 config.db_dir = strdup(&curline[7]);
75 } else if (!strncmp("debug ", curline, 6)) {
77 * Not supported yet; ignore for compatibility with
80 } else if (!strncmp("default_language ", curline, 17)) {
82 * Not supported yet; ignore for compatibility with
85 } else if (!strncmp("mail_delivery_client ", curline, 21)) {
86 config.mta = strdup(&curline[21]);
87 } else if (!strncmp("maintainer_email ", curline, 17)) {
88 config.adminemail = strdup(&curline[17]);
89 } else if (!strncmp("mail_intro_file ", curline, 16)) {
91 * Not supported yet; ignore for compatibility with
94 } else if (!strncmp("help_dir ", curline, 9)) {
96 * Not supported yet; ignore for compatibility with
99 } else if (!strncmp("max_last ", curline, 9)) {
101 * Not supported yet; ignore for compatibility with
104 } else if (!strncmp("max_reply_keys ", curline, 15)) {
105 config.maxkeys = atoi(&curline[15]);
106 } else if (!strncmp("pg_dbhost ", curline, 10)) {
107 config.pg_dbhost = strdup(&curline[10]);
108 } else if (!strncmp("pg_dbname ", curline, 10)) {
109 config.pg_dbname = strdup(&curline[10]);
110 } else if (!strncmp("pg_dbuser ", curline, 10)) {
111 config.pg_dbuser = strdup(&curline[10]);
112 } else if (!strncmp("pg_dbpass ", curline, 10)) {
113 config.pg_dbpass = strdup(&curline[10]);
114 } else if (!strncmp("syncsite ", curline, 9)) {
116 lladd(config.syncsites, strdup(&curline[9]));
117 } else if (!strncmp("logfile ", curline, 8)) {
118 config.logfile = strdup(&curline[8]);
119 } else if (!strncmp("loglevel ", curline, 9)) {
120 setlogthreshold(atoi(&curline[9]));
121 } else if (!strncmp("this_site ", curline, 10)) {
122 config.thissite = strdup(&curline[10]);
123 } else if (!strncmp("socket_name ", curline, 12) ||
124 !strncmp("pks_bin_dir ", curline, 12) ||
125 !strncmp("mail_dir ", curline, 9) ||
126 !strncmp("www_port ", curline, 9)) {
128 * Not applicable; ignored for compatibility with pksd.
131 logthing(LOGTHING_ERROR,
132 "Unknown config line: %s", curline);
135 fgets(curline, 1023, conffile);
139 logthing(LOGTHING_NOTICE,
140 "Couldn't open config file; using defaults.");
144 void cleanupconfig(void) {
145 if (config.thissite != NULL) {
146 free(config.thissite);
147 config.thissite = NULL;
149 if (config.adminemail != NULL) {
150 free(config.adminemail);
151 config.adminemail = NULL;
153 if (config.mta != NULL) {
157 if (config.db_dir != NULL) {
159 config.db_dir = NULL;
161 if (config.pg_dbhost != NULL) {
162 free(config.pg_dbhost);
163 config.pg_dbhost = NULL;
165 if (config.pg_dbname != NULL) {
166 free(config.pg_dbname);
167 config.pg_dbname = NULL;
169 if (config.pg_dbuser != NULL) {
170 free(config.pg_dbuser);
171 config.pg_dbuser = NULL;
173 if (config.pg_dbpass != NULL) {
174 free(config.pg_dbpass);
175 config.pg_dbpass = NULL;
177 if (config.syncsites != NULL) {
178 llfree(config.syncsites, free);
179 config.syncsites = NULL;
181 if (config.logfile != NULL) {
182 free(config.logfile);
183 config.logfile = NULL;