Subversion Repositories Tewi

Rev

Rev 140 | Rev 187 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
4 nishi 1
/* $Id: tw_config.h 156 2024-09-25 12:28:10Z nishi $ */
2
 
3
#ifndef __TW_CONFIG_H__
4
#define __TW_CONFIG_H__
5
 
140 nishi 6
#ifdef __cplusplus
7
extern "C" {
8
#endif
9
 
156 nishi 10
#include "../config.h"
11
 
21 nishi 12
#include "tw_http.h"
13
 
7 nishi 14
#include <stdint.h>
21 nishi 15
#include <stdbool.h>
7 nishi 16
 
21 nishi 17
#ifdef __MINGW32__
18
#include <winsock2.h>
19
#define NO_IPV6
20
#else
21
#include <netinet/in.h>
81 nishi 22
#ifdef __HAIKU__
23
#define NO_IPV6
21 nishi 24
#endif
81 nishi 25
#endif
6 nishi 26
 
21 nishi 27
#ifdef NO_IPV6
28
#define SOCKADDR struct sockaddr_in
29
#else
30
#define SOCKADDR struct sockaddr_in6
31
#endif
32
 
22 nishi 33
#define MAX_PORTS 1024
34
#define MAX_VHOSTS 1024
35
#define MAX_MODULES 1024
36
#define MAX_DIRS 1024
37
#define MAX_MIME 1024
38
#define MAX_ICON 1024
24 nishi 39
#define MAX_INDEX 1024
33 nishi 40
#define MAX_README 8
21 nishi 41
 
42
enum TW_DIR_TYPE {
43
	TW_DIR_ALLOW = 0,
44
	TW_DIR_DENY
45
};
46
 
47
struct tw_dir_entry {
48
	char* name;
49
	char* dir;
50
	int type;
51
};
52
 
53
struct tw_mime_entry {
54
	char* ext;
55
	char* mime;
56
};
57
 
22 nishi 58
struct tw_icon_entry {
59
	char* mime;
60
	char* icon;
61
};
62
 
12 nishi 63
struct tw_config_entry {
64
	char* name;
65
	int port;
156 nishi 66
#ifndef NO_SSL
12 nishi 67
	char* sslkey;
68
	char* sslcert;
156 nishi 69
#endif
19 nishi 70
	char* root;
123 nishi 71
	int hideport;
21 nishi 72
	struct tw_dir_entry dirs[MAX_DIRS];
73
	int dir_count;
74
	struct tw_mime_entry mimes[MAX_DIRS];
75
	int mime_count;
22 nishi 76
	struct tw_icon_entry icons[MAX_DIRS];
77
	int icon_count;
24 nishi 78
	char* indexes[MAX_INDEX];
79
	int index_count;
33 nishi 80
	char* readmes[MAX_README];
81
	int readme_count;
156 nishi 82
#ifdef HAS_CHROOT
83
	char* chroot_path;
84
#endif
12 nishi 85
};
86
 
6 nishi 87
struct tw_config {
7 nishi 88
	uint64_t ports[MAX_PORTS + 1]; /* If port & (1 << 32) is non-zero, it is SSL */
12 nishi 89
	char hostname[1025];
156 nishi 90
	char* defined[1025];
6 nishi 91
	struct tw_config_entry root;
12 nishi 92
	struct tw_config_entry vhosts[MAX_VHOSTS];
18 nishi 93
	void* modules[MAX_MODULES];
94
	int module_count;
12 nishi 95
	int vhost_count;
128 nishi 96
	char* server_admin;
17 nishi 97
	char* server_root;
18 nishi 98
	char* extension;
6 nishi 99
};
100
 
101
void tw_config_init(void);
4 nishi 102
int tw_config_read(const char* path);
12 nishi 103
struct tw_config_entry* tw_vhost_match(const char* name, int port);
21 nishi 104
bool tw_permission_allowed(const char* path, SOCKADDR addr, struct tw_http_request req, struct tw_config_entry* vhost);
4 nishi 105
 
140 nishi 106
#ifdef __cplusplus
107
}
4 nishi 108
#endif
140 nishi 109
 
110
#endif