2 * onak-conf.c - Routines related to runtime config.
4 * Jonathan McDowell <noodles@earth.li>
6 * Copyright 2002 Project Purple
15 #include "onak-conf.h"
18 * config - Runtime configuration for onak.
20 * This is the default config; normally overridden with values from the
23 struct onak_config config = {
26 NULL, /* adminemail */
31 * Options for directory backends.
36 * Options for the Postgres backend.
44 void readconfig(void) {
50 conffile = fopen(CONFIGFILE, "r");
51 if (conffile != NULL) {
52 fgets(curline, 1023, conffile);
54 while (!feof(conffile)) {
55 for (i = strlen(curline) - 1; isspace(curline[i]); i--) {
59 if (curline[0] == '#' || curline[0] == 0) {
61 * Comment line, ignore.
63 } else if (!strncmp("db_dir ", curline, 7)) {
64 config.db_dir = strdup(&curline[7]);
65 } else if (!strncmp("debug ", curline, 6)) {
67 * Not supported yet; ignore for compatibility with
70 } else if (!strncmp("default_language ", curline, 17)) {
72 * Not supported yet; ignore for compatibility with
75 } else if (!strncmp("mail_delivery_client ", curline, 21)) {
76 config.mta = strdup(&curline[21]);
77 } else if (!strncmp("maintainer_email ", curline, 17)) {
78 config.adminemail = strdup(&curline[17]);
79 } else if (!strncmp("mail_intro_file ", curline, 16)) {
81 * Not supported yet; ignore for compatibility with
84 } else if (!strncmp("help_dir ", curline, 9)) {
86 * Not supported yet; ignore for compatibility with
89 } else if (!strncmp("max_last ", curline, 9)) {
91 * Not supported yet; ignore for compatibility with
94 } else if (!strncmp("max_reply_keys ", curline, 15)) {
95 config.maxkeys = atoi(&curline[15]);
96 } else if (!strncmp("pg_dbhost ", curline, 10)) {
97 config.pg_dbhost = strdup(&curline[10]);
98 } else if (!strncmp("pg_dbname ", curline, 10)) {
99 config.pg_dbname = strdup(&curline[10]);
100 } else if (!strncmp("pg_dbuser ", curline, 10)) {
101 config.pg_dbuser = strdup(&curline[10]);
102 } else if (!strncmp("pg_dbpass ", curline, 10)) {
103 config.pg_dbpass = strdup(&curline[10]);
104 } else if (!strncmp("syncsite ", curline, 9)) {
106 lladd(config.syncsites, strdup(&curline[9]));
107 } else if (!strncmp("this_site ", curline, 10)) {
108 config.thissite = strdup(&curline[10]);
109 } else if (!strncmp("socket_name ", curline, 12) ||
110 !strncmp("pks_bin_dir ", curline, 12) ||
111 !strncmp("mail_dir ", curline, 9) ||
112 !strncmp("www_port ", curline, 9)) {
114 * Not applicable; ignored for compatibility with pksd.
117 fprintf(stderr, "Unknown config line: %s\n", curline);
120 fgets(curline, 1023, conffile);
124 fprintf(stderr, "Couldn't open config file; using defaults.\n");
128 void cleanupconfig(void) {
129 if (config.thissite != NULL) {
130 free(config.thissite);
131 config.thissite = NULL;
133 if (config.adminemail != NULL) {
134 free(config.adminemail);
135 config.adminemail = NULL;
137 if (config.mta != NULL) {
141 if (config.db_dir != NULL) {
143 config.db_dir = NULL;
145 if (config.pg_dbhost != NULL) {
146 free(config.pg_dbhost);
147 config.pg_dbhost = NULL;
149 if (config.pg_dbname != NULL) {
150 free(config.pg_dbname);
151 config.pg_dbname = NULL;
153 if (config.pg_dbuser != NULL) {
154 free(config.pg_dbuser);
155 config.pg_dbuser = NULL;
157 if (config.pg_dbpass != NULL) {
158 free(config.pg_dbpass);
159 config.pg_dbpass = NULL;
161 if (config.syncsites != NULL) {
162 llfree(config.syncsites, free);
163 config.syncsites = NULL;