Subversion Repositories Tewi

Rev

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