Subversion Repositories Tewi

Rev

Rev 240 | Rev 258 | 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 257 2024-10-04 05:34:27Z 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
 
219 nishi 17
#if defined(__MINGW32__) || defined(_MSC_VER) || defined(__BORLANDC__) || defined(__WATCOMC__)
240 nishi 18
#ifdef USE_WINSOCK1
19
#include <winsock.h>
20
#else
21 nishi 21
#include <winsock2.h>
240 nishi 22
#endif
21 nishi 23
#define NO_IPV6
24
#else
187 nishi 25
#ifdef __PPU__
26
#include <net/net.h>
27
#endif
21 nishi 28
#include <netinet/in.h>
81 nishi 29
#ifdef __HAIKU__
30
#define NO_IPV6
21 nishi 31
#endif
81 nishi 32
#endif
6 nishi 33
 
21 nishi 34
#ifdef NO_IPV6
35
#define SOCKADDR struct sockaddr_in
36
#else
37
#define SOCKADDR struct sockaddr_in6
38
#endif
39
 
22 nishi 40
#define MAX_PORTS 1024
41
#define MAX_VHOSTS 1024
42
#define MAX_MODULES 1024
43
#define MAX_DIRS 1024
257 nishi 44
#define MAX_MIME 4096
22 nishi 45
#define MAX_ICON 1024
24 nishi 46
#define MAX_INDEX 1024
33 nishi 47
#define MAX_README 8
21 nishi 48
 
215 nishi 49
#if defined(_MSC_VER) || defined(__BORLANDC__)
212 nishi 50
#define NUM1024 1024UL
51
#else
52
#define NUM1024 1024ULL
53
#endif
54
 
21 nishi 55
enum TW_DIR_TYPE {
56
	TW_DIR_ALLOW = 0,
57
	TW_DIR_DENY
58
};
59
 
60
struct tw_dir_entry {
61
	char* name;
62
	char* dir;
63
	int type;
64
};
65
 
66
struct tw_mime_entry {
67
	char* ext;
68
	char* mime;
69
};
70
 
22 nishi 71
struct tw_icon_entry {
72
	char* mime;
73
	char* icon;
74
};
75
 
12 nishi 76
struct tw_config_entry {
77
	char* name;
78
	int port;
156 nishi 79
#ifndef NO_SSL
12 nishi 80
	char* sslkey;
81
	char* sslcert;
156 nishi 82
#endif
19 nishi 83
	char* root;
123 nishi 84
	int hideport;
21 nishi 85
	struct tw_dir_entry dirs[MAX_DIRS];
86
	int dir_count;
257 nishi 87
	struct tw_mime_entry mimes[MAX_MIME];
21 nishi 88
	int mime_count;
257 nishi 89
	struct tw_icon_entry icons[MAX_ICON];
22 nishi 90
	int icon_count;
24 nishi 91
	char* indexes[MAX_INDEX];
92
	int index_count;
33 nishi 93
	char* readmes[MAX_README];
94
	int readme_count;
156 nishi 95
#ifdef HAS_CHROOT
96
	char* chroot_path;
97
#endif
12 nishi 98
};
99
 
6 nishi 100
struct tw_config {
215 nishi 101
#if defined(_MSC_VER) || defined(__BORLANDC__)
212 nishi 102
	uint32_t ports[MAX_PORTS + 1];
103
#else
7 nishi 104
	uint64_t ports[MAX_PORTS + 1]; /* If port & (1 << 32) is non-zero, it is SSL */
212 nishi 105
#endif
12 nishi 106
	char hostname[1025];
156 nishi 107
	char* defined[1025];
6 nishi 108
	struct tw_config_entry root;
12 nishi 109
	struct tw_config_entry vhosts[MAX_VHOSTS];
18 nishi 110
	void* modules[MAX_MODULES];
111
	int module_count;
12 nishi 112
	int vhost_count;
128 nishi 113
	char* server_admin;
17 nishi 114
	char* server_root;
18 nishi 115
	char* extension;
6 nishi 116
};
117
 
118
void tw_config_init(void);
4 nishi 119
int tw_config_read(const char* path);
12 nishi 120
struct tw_config_entry* tw_vhost_match(const char* name, int port);
21 nishi 121
bool tw_permission_allowed(const char* path, SOCKADDR addr, struct tw_http_request req, struct tw_config_entry* vhost);
4 nishi 122
 
140 nishi 123
#ifdef __cplusplus
124
}
4 nishi 125
#endif
140 nishi 126
 
127
#endif