Subversion Repositories Tewi

Rev

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