1 |
nishi |
1.1 |
/* $Id: tw_config.h 359 2024-10-16 14:34:51Z nishi $ */ |
2 |
|
|
|
3 |
|
|
#ifndef __TW_CONFIG_H__ |
4 |
|
|
#define __TW_CONFIG_H__ |
5 |
|
|
|
6 |
|
|
#ifdef __cplusplus |
7 |
|
|
extern "C" { |
8 |
|
|
#endif |
9 |
|
|
|
10 |
|
|
#include "../config.h" |
11 |
|
|
|
12 |
|
|
#include "tw_http.h" |
13 |
|
|
|
14 |
|
|
#include <stdint.h> |
15 |
|
|
#include <stdbool.h> |
16 |
|
|
#ifdef __NeXT__ |
17 |
|
|
#include <sys/types.h> |
18 |
|
|
#endif |
19 |
|
|
|
20 |
|
|
#if defined(__MINGW32__) || defined(_MSC_VER) || defined(__BORLANDC__) || (defined(__WATCOMC__) && !defined(__OS2__) && !defined(__NETWARE__) && !defined(__DOS__)) |
21 |
|
|
#ifdef USE_WINSOCK1 |
22 |
|
|
#include <winsock.h> |
23 |
|
|
#else |
24 |
|
|
#include <winsock2.h> |
25 |
|
|
#endif |
26 |
|
|
#define NO_IPV6 |
27 |
|
|
#else |
28 |
|
|
#ifdef __PPU__ |
29 |
|
|
#include <net/net.h> |
30 |
|
|
#endif |
31 |
|
|
#if !defined(__OS2__) && !defined(__NETWARE__) |
32 |
|
|
#include <netinet/in.h> |
33 |
|
|
#endif |
34 |
|
|
#ifdef __HAIKU__ |
35 |
|
|
#define NO_IPV6 |
36 |
|
|
#endif |
37 |
|
|
#endif |
38 |
|
|
|
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 |
|
|
|
51 |
|
|
#if defined(NO_IPV6) |
52 |
|
|
#define SOCKADDR struct sockaddr_in |
53 |
|
|
#else |
54 |
|
|
#define SOCKADDR struct sockaddr_in6 |
55 |
|
|
#endif |
56 |
|
|
|
57 |
|
|
#define MAX_PORTS 1024 |
58 |
|
|
#define MAX_VHOSTS 1024 |
59 |
|
|
#define MAX_MODULES 1024 |
60 |
|
|
#define MAX_DIRS 1024 |
61 |
|
|
#define MAX_MIME 4096 |
62 |
|
|
#define MAX_ICON 1024 |
63 |
|
|
#define MAX_INDEX 32 |
64 |
|
|
#define MAX_README 8 |
65 |
|
|
|
66 |
|
|
#if defined(_MSC_VER) || defined(__BORLANDC__) |
67 |
|
|
#define NUM1024 1024UL |
68 |
|
|
#else |
69 |
|
|
#define NUM1024 1024ULL |
70 |
|
|
#endif |
71 |
|
|
|
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 |
|
|
|
88 |
|
|
struct tw_icon_entry { |
89 |
|
|
char* mime; |
90 |
|
|
char* icon; |
91 |
|
|
}; |
92 |
|
|
|
93 |
|
|
struct tw_config_entry { |
94 |
|
|
char* name; |
95 |
|
|
int port; |
96 |
|
|
#ifndef NO_SSL |
97 |
|
|
char* sslkey; |
98 |
|
|
char* sslcert; |
99 |
|
|
#endif |
100 |
|
|
char* root; |
101 |
|
|
int hideport; |
102 |
|
|
struct tw_dir_entry dirs[MAX_DIRS]; |
103 |
|
|
int dir_count; |
104 |
|
|
struct tw_mime_entry mimes[MAX_MIME]; |
105 |
|
|
int mime_count; |
106 |
|
|
struct tw_icon_entry icons[MAX_ICON]; |
107 |
|
|
int icon_count; |
108 |
|
|
char* indexes[MAX_INDEX]; |
109 |
|
|
int index_count; |
110 |
|
|
char* readmes[MAX_README]; |
111 |
|
|
int readme_count; |
112 |
|
|
#ifdef HAS_CHROOT |
113 |
|
|
char* chroot_path; |
114 |
|
|
#endif |
115 |
|
|
}; |
116 |
|
|
|
117 |
|
|
struct tw_config { |
118 |
|
|
#if defined(_MSC_VER) || defined(__BORLANDC__) |
119 |
|
|
uint32_t ports[MAX_PORTS + 1]; |
120 |
|
|
#else |
121 |
|
|
uint64_t ports[MAX_PORTS + 1]; /* If port & (1 << 32) is non-zero, it is SSL */ |
122 |
|
|
#endif |
123 |
|
|
char hostname[1025]; |
124 |
|
|
char* defined[1025]; |
125 |
|
|
struct tw_config_entry root; |
126 |
|
|
struct tw_config_entry vhosts[MAX_VHOSTS]; |
127 |
|
|
void* modules[MAX_MODULES]; |
128 |
|
|
int module_count; |
129 |
|
|
int vhost_count; |
130 |
|
|
char* server_admin; |
131 |
|
|
char* server_root; |
132 |
|
|
char* extension; |
133 |
|
|
}; |
134 |
|
|
|
135 |
|
|
void tw_config_init(void); |
136 |
|
|
int tw_config_read(const char* path); |
137 |
|
|
struct tw_config_entry* tw_vhost_match(const char* name, int port); |
138 |
|
|
bool tw_permission_allowed(const char* path, SOCKADDR addr, struct tw_http_request req, struct tw_config_entry* vhost); |
139 |
|
|
|
140 |
|
|
#ifdef __cplusplus |
141 |
|
|
} |
142 |
|
|
#endif |
143 |
|
|
|
144 |
|
|
#endif |