Subversion Repositories Tewi

Rev

Rev 138 | Rev 161 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 138 Rev 156
Line 1... Line 1...
1
/* $Id: config.c 138 2024-09-23 11:12:46Z nishi $ */
1
/* $Id: config.c 156 2024-09-25 12:28:10Z nishi $ */
2
 
2
 
3
#define SOURCE
3
#define SOURCE
4
 
4
 
5
#include "tw_config.h"
5
#include "tw_config.h"
6
#include "tw_module.h"
6
#include "tw_module.h"
Line 70... Line 70...
70
	int i;
70
	int i;
71
	for(i = 0; i < MAX_PORTS + 1; i++) {
71
	for(i = 0; i < MAX_PORTS + 1; i++) {
72
		config.ports[i] = -1;
72
		config.ports[i] = -1;
73
	}
73
	}
74
	for(i = 0; i < MAX_VHOSTS; i++) {
74
	for(i = 0; i < MAX_VHOSTS; i++) {
-
 
75
#ifndef NO_SSL
75
		config.vhosts[i].sslkey = NULL;
76
		config.vhosts[i].sslkey = NULL;
76
		config.vhosts[i].sslcert = NULL;
77
		config.vhosts[i].sslcert = NULL;
-
 
78
#endif
77
		config.vhosts[i].root = NULL;
79
		config.vhosts[i].root = NULL;
-
 
80
#ifdef HAS_CHROOT
-
 
81
		config.vhosts[i].chroot_path = NULL;
-
 
82
#endif
78
	}
83
	}
-
 
84
#ifndef NO_SSL
79
	config.root.sslkey = NULL;
85
	config.root.sslkey = NULL;
80
	config.root.sslcert = NULL;
86
	config.root.sslcert = NULL;
-
 
87
#endif
81
	config.root.root = NULL;
88
	config.root.root = NULL;
82
	config.root.mime_count = 0;
89
	config.root.mime_count = 0;
83
	config.root.dir_count = 0;
90
	config.root.dir_count = 0;
84
	config.root.icon_count = 0;
91
	config.root.icon_count = 0;
85
	config.root.index_count = 0;
92
	config.root.index_count = 0;
86
	config.root.readme_count = 0;
93
	config.root.readme_count = 0;
87
	config.root.hideport = 0;
94
	config.root.hideport = 0;
-
 
95
#ifdef HAS_CHROOT
-
 
96
	config.root.chroot_path = NULL;
-
 
97
#endif
88
	config.vhost_count = 0;
98
	config.vhost_count = 0;
89
	config.module_count = 0;
99
	config.module_count = 0;
90
	config.extension = NULL;
100
	config.extension = NULL;
91
	config.server_root = cm_strdup(PREFIX);
101
	config.server_root = cm_strdup(PREFIX);
92
	config.server_admin = cm_strdup(SERVER_ADMIN);
102
	config.server_admin = cm_strdup(SERVER_ADMIN);
-
 
103
	config.defined[0] = NULL;
93
	gethostname(config.hostname, 1024);
104
	gethostname(config.hostname, 1024);
94
}
105
}
95
 
106
 
96
int tw_config_read(const char* path) {
107
int tw_config_read(const char* path) {
97
	cm_log("Config", "Reading %s", path);
108
	cm_log("Config", "Reading %s", path);
98
	char cbuf[2];
109
	char cbuf[2];
99
	cbuf[1] = 0;
110
	cbuf[1] = 0;
100
	int ln = 0;
111
	int ln = 0;
-
 
112
	int ifbr = 0;
-
 
113
	int ignore = -1;
101
	FILE* f = fopen(path, "r");
114
	FILE* f = fopen(path, "r");
102
	if(f != NULL) {
115
	if(f != NULL) {
103
		char* line = malloc(1);
116
		char* line = malloc(1);
104
		line[0] = 0;
117
		line[0] = 0;
105
		int stop = 0;
118
		int stop = 0;
Line 112... Line 125...
112
				ln++;
125
				ln++;
113
				char* l = cm_trim(line);
126
				char* l = cm_trim(line);
114
				if(strlen(l) > 0 && l[0] != '#') {
127
				if(strlen(l) > 0 && l[0] != '#') {
115
					char** r = cm_split(l, " \t");
128
					char** r = cm_split(l, " \t");
116
					int i;
129
					int i;
-
 
130
					if(ignore != -1 && ifbr >= ignore) {
-
 
131
						if(cm_strcaseequ(r[0], "EndIf")) ifbr--;
-
 
132
						if(ifbr == 0) {
-
 
133
							ignore = -1;
-
 
134
						}
117
					if(cm_strcaseequ(r[0], "Include") || cm_strcaseequ(r[0], "IncludeOptional")) {
135
					} else if(cm_strcaseequ(r[0], "Include") || cm_strcaseequ(r[0], "IncludeOptional")) {
118
						for(i = 1; r[i] != NULL; i++) {
136
						for(i = 1; r[i] != NULL; i++) {
119
							if(tw_config_read(r[i]) != 0 && cm_strcaseequ(r[0], "Include")) {
137
							if(tw_config_read(r[i]) != 0 && cm_strcaseequ(r[0], "Include")) {
120
								stop = 1;
138
								stop = 1;
121
								break;
139
								break;
122
							}
140
							}
123
						}
141
						}
-
 
142
					} else if(cm_strcaseequ(r[0], "Define")) {
-
 
143
						if(r[1] == NULL) {
-
 
144
							cm_log("Config", "Missing name at line %d", ln);
-
 
145
							stop = 1;
-
 
146
						} else {
-
 
147
							tw_add_define(r[1]);
-
 
148
						}
-
 
149
					} else if(cm_strcaseequ(r[0], "Undefine")) {
-
 
150
						if(r[1] == NULL) {
-
 
151
							cm_log("Config", "Missing name at line %d", ln);
-
 
152
							stop = 1;
-
 
153
						} else {
-
 
154
							tw_delete_define(r[1]);
-
 
155
						}
124
					} else if(cm_strcaseequ(r[0], "BeginDirectory")) {
156
					} else if(cm_strcaseequ(r[0], "BeginDirectory")) {
125
						if(dir != NULL) {
157
						if(dir != NULL) {
126
							cm_log("Config", "Already in directory section at line %d", ln);
158
							cm_log("Config", "Already in directory section at line %d", ln);
127
							stop = 1;
159
							stop = 1;
128
						} else {
160
						} else {
Line 221... Line 253...
221
						}
253
						}
222
					} else if(cm_strcaseequ(r[0], "HidePort")) {
254
					} else if(cm_strcaseequ(r[0], "HidePort")) {
223
						current->hideport = 1;
255
						current->hideport = 1;
224
					} else if(cm_strcaseequ(r[0], "ShowPort")) {
256
					} else if(cm_strcaseequ(r[0], "ShowPort")) {
225
						current->hideport = 0;
257
						current->hideport = 0;
-
 
258
#ifndef NO_SSL
226
					} else if(cm_strcaseequ(r[0], "SSLKey")) {
259
					} else if(cm_strcaseequ(r[0], "SSLKey")) {
227
						if(r[1] == NULL) {
260
						if(r[1] == NULL) {
228
							cm_log("Config", "Missing path at line %d", ln);
261
							cm_log("Config", "Missing path at line %d", ln);
229
							stop = 1;
262
							stop = 1;
230
						} else {
263
						} else {
Line 237... Line 270...
237
							stop = 1;
270
							stop = 1;
238
						} else {
271
						} else {
239
							if(current->sslcert != NULL) free(current->sslcert);
272
							if(current->sslcert != NULL) free(current->sslcert);
240
							current->sslcert = cm_strdup(r[1]);
273
							current->sslcert = cm_strdup(r[1]);
241
						}
274
						}
-
 
275
#endif
-
 
276
					} else if(cm_strcaseequ(r[0], "ForceLog")) {
-
 
277
						if(r[1] == NULL) {
-
 
278
							cm_log("Config", "Missing log at line %d", ln);
-
 
279
							stop = 1;
-
 
280
						} else {
-
 
281
							cm_force_log(r[1]);
-
 
282
						}
-
 
283
					} else if(cm_strcaseequ(r[0], "EndIf")) {
-
 
284
						if(ifbr == 0) {
-
 
285
							cm_log("Config", "Missing BeginIf at line %d", ln);
-
 
286
							stop = 1;
-
 
287
						}
-
 
288
						ifbr--;
-
 
289
					} else if(cm_strcaseequ(r[0], "BeginIf") || cm_strcaseequ(r[0], "BeginIfNot")) {
-
 
290
						if(r[1] == NULL) {
-
 
291
							cm_log("Config", "Missing condition type at line %d", ln);
-
 
292
						} else {
-
 
293
							ifbr++;
-
 
294
							bool ign = false;
-
 
295
							if(cm_strcaseequ(r[1], "False")) {
-
 
296
								ign = true;
-
 
297
							} else if(cm_strcaseequ(r[1], "True")) {
-
 
298
							} else if(cm_strcaseequ(r[1], "Defined")) {
-
 
299
								if(r[2] == NULL) {
-
 
300
									cm_log("Config", "Missing name at line %d", ln);
-
 
301
									stop = 1;
-
 
302
								} else {
-
 
303
									int i;
-
 
304
									bool fndit = false;
-
 
305
									for(i = 0; config.defined[i] != NULL; i++) {
-
 
306
										if(strcmp(config.defined[i], r[2]) == 0) {
-
 
307
											fndit = true;
-
 
308
											break;
-
 
309
										}
-
 
310
									}
-
 
311
									if(!fndit) {
-
 
312
										ign = true;
-
 
313
									}
-
 
314
								}
-
 
315
							} else {
-
 
316
								cm_log("Config", "Unknown condition type at line %d", ln);
-
 
317
								stop = 1;
-
 
318
							}
-
 
319
							if(cm_strcaseequ(r[0], "BeginIfNot")) ign = !ign;
-
 
320
							if(ign) {
-
 
321
								ignore = ifbr - 1;
-
 
322
							}
-
 
323
						}
242
					} else if(cm_strcaseequ(r[0], "ServerRoot")) {
324
					} else if(cm_strcaseequ(r[0], "ServerRoot")) {
243
						if(r[1] == NULL) {
325
						if(r[1] == NULL) {
244
							cm_log("Config", "Missing path at line %d", ln);
326
							cm_log("Config", "Missing path at line %d", ln);
245
							stop = 1;
327
							stop = 1;
246
						} else {
328
						} else {