Subversion Repositories Tewi

Rev

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