Subversion Repositories Tewi

Rev

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