Subversion Repositories Tewi

Rev

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