1 |
/* |
2 |
* Boa, an http server |
3 |
* Copyright (C) 1995 Paul Phillips <paulp@go2net.com> |
4 |
* Some changes Copyright (C) 1996,97 Larry Doolittle <ldoolitt@jlab.org> |
5 |
* Some changes Copyright (C) 1997 Jon Nelson <jnelson@boa.org> |
6 |
* |
7 |
* This program is free software; you can redistribute it and/or modify |
8 |
* it under the terms of the GNU General Public License as published by |
9 |
* the Free Software Foundation; either version 1, or (at your option) |
10 |
* any later version. |
11 |
* |
12 |
* This program is distributed in the hope that it will be useful, |
13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
* GNU General Public License for more details. |
16 |
* |
17 |
* You should have received a copy of the GNU General Public License |
18 |
* along with this program; if not, write to the Free Software |
19 |
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
20 |
* |
21 |
*/ |
22 |
|
23 |
/* $Id: globals.h,v 1.26 2002/10/21 18:46:26 nmav Exp $*/ |
24 |
|
25 |
#ifndef _GLOBALS_H |
26 |
#define _GLOBALS_H |
27 |
|
28 |
#ifdef ENABLE_SSL |
29 |
# include <gnutls/gnutls.h> |
30 |
#endif |
31 |
|
32 |
typedef struct { |
33 |
int socket; |
34 |
int secure; /* ssl or not. NOTE: 0 or 1. Nothing else. */ |
35 |
int port; |
36 |
int pending_requests; |
37 |
} socket_type; |
38 |
|
39 |
struct mmap_entry { |
40 |
dev_t dev; |
41 |
ino_t ino; |
42 |
char *mmap; |
43 |
int use_count; |
44 |
size_t len; |
45 |
int available; |
46 |
int times_used; |
47 |
}; |
48 |
|
49 |
typedef struct { |
50 |
hic_shutdown_func shutdown; |
51 |
hic_init_func init; |
52 |
hic_request_func request; |
53 |
void *dl_handle; |
54 |
char* sym_prefix; /* ie. "_php" */ |
55 |
char* content_type; /* ie. "application/x-httpd-php" */ |
56 |
int content_type_len; |
57 |
} hic_module_st; |
58 |
|
59 |
struct alias { |
60 |
char *fakename; /* URI path to file */ |
61 |
char *realname; /* Actual path to file */ |
62 |
int type; /* ALIAS, SCRIPTALIAS, REDIRECT */ |
63 |
int fake_len; /* strlen of fakename */ |
64 |
int real_len; /* strlen of realname */ |
65 |
struct alias *next; |
66 |
}; |
67 |
|
68 |
typedef struct alias alias; |
69 |
|
70 |
typedef struct _virthost { |
71 |
char *ip; /* This virthost will be visible in this IP */ |
72 |
char *host; /* The hostname of the virtual host */ |
73 |
char* document_root; /* The document root of this virtual host */ |
74 |
char* user_dir; /* The user dir of this virtual host */ |
75 |
int user_dir_len; /* strlen of user_dir */ |
76 |
int ip_len; /* strlen of IP */ |
77 |
int host_len; /* strlen of hostname */ |
78 |
int document_root_len; /* strlen of document root */ |
79 |
alias *alias_hashtable[ALIAS_HASHTABLE_SIZE]; /* aliases in this virthost */ |
80 |
struct _virthost *next; |
81 |
} virthost; |
82 |
|
83 |
struct request { /* pending requests */ |
84 |
int fd; /* client's socket fd */ |
85 |
#ifdef USE_POLL |
86 |
int pollfd_id; |
87 |
#endif |
88 |
#ifdef ENABLE_SSL |
89 |
gnutls_session ssl_state; |
90 |
char * certificate_verified; /* a string that describes the output of the |
91 |
* certificate verification function. Needed |
92 |
* in CGIs. |
93 |
*/ |
94 |
#endif |
95 |
int secure; /* whether ssl or not */ |
96 |
int alert_to_send; /* in SEND_ALERT state */ |
97 |
|
98 |
int status; /* see #defines.h */ |
99 |
time_t time_last; /* time of last succ. op. */ |
100 |
char *pathname; /* pathname of requested file */ |
101 |
off64_t range_start; /* send file from byte ... */ |
102 |
off64_t range_stop; /* to byte */ |
103 |
off64_t pipe_range_stop; /* This is used only if the file is sent by the pipe_read() method. |
104 |
* Indicates how many bytes to send from a file (actually a copy of range_stop, |
105 |
* but it is modified. */ |
106 |
int simple; /* simple request? */ |
107 |
int keepalive; /* keepalive status */ |
108 |
int kacount; /* keepalive count */ |
109 |
|
110 |
int data_fd; /* fd of data */ |
111 |
off64_t filesize; /* filesize */ |
112 |
off64_t filepos; /* position in file */ |
113 |
char *data_mem; /* mmapped/malloced char array */ |
114 |
int method; /* M_GET, M_POST, etc. */ |
115 |
|
116 |
char *logline; /* line to log file */ |
117 |
|
118 |
char *header_line; /* beginning of un or incompletely processed header line */ |
119 |
char *header_end; /* last known end of header, or end of processed data */ |
120 |
int parse_pos; /* how much have we parsed */ |
121 |
int client_stream_pos; /* how much have we read... */ |
122 |
|
123 |
int buffer_start; /* where the buffer starts */ |
124 |
int buffer_end; /* where the buffer ends */ |
125 |
|
126 |
char *http_version; /* HTTP/?.? of req */ |
127 |
int response_status; /* R_NOT_FOUND etc. */ |
128 |
|
129 |
char *if_modified_since; /* If-Modified-Since */ |
130 |
time_t last_modified; /* Last-modified: */ |
131 |
|
132 |
char *if_none_match_etag; |
133 |
char *if_match_etag; |
134 |
char *if_range_etag; /* These are the Etags sent by the client |
135 |
* In If-* requests. |
136 |
*/ |
137 |
int if_types; /* If-Match, If-None-Match, If-Range |
138 |
* and OR of the MATCH_* definitions. |
139 |
*/ |
140 |
|
141 |
char local_ip_addr[NI_MAXHOST]; /* for virtualhost */ |
142 |
char *hostname; |
143 |
char document_root[MAX_PATH_LENGTH + 1]; |
144 |
char user_dir[MAX_USER_DIR_LENGTH + 1]; |
145 |
|
146 |
/* CGI vars */ |
147 |
|
148 |
int remote_port; /* could be used for ident */ |
149 |
|
150 |
char remote_ip_addr[NI_MAXHOST]; /* after inet_ntoa */ |
151 |
|
152 |
int is_cgi; /* true if CGI/NPH */ |
153 |
int cgi_status; |
154 |
int cgi_env_index; /* index into array */ |
155 |
|
156 |
/* Agent and referer for logfiles */ |
157 |
char *header_user_agent; |
158 |
char *header_referer; |
159 |
|
160 |
int post_data_fd; /* fd for post data tmpfile */ |
161 |
|
162 |
char *path_info; /* env variable */ |
163 |
char *path_translated; /* env variable */ |
164 |
char *script_name; /* env variable */ |
165 |
char *query_string; /* env variable */ |
166 |
char *content_type; /* env variable */ |
167 |
char *content_length; /* env variable */ |
168 |
|
169 |
struct mmap_entry *mmap_entry_var; |
170 |
|
171 |
struct request *next; /* next */ |
172 |
struct request *prev; /* previous */ |
173 |
|
174 |
/* everything below this line is kept regardless */ |
175 |
char buffer[BUFFER_SIZE + 1]; /* generic I/O buffer */ |
176 |
char request_uri[MAX_HEADER_LENGTH + 1]; /* uri */ |
177 |
char client_stream[CLIENT_STREAM_SIZE]; /* data from client - fit or be hosed */ |
178 |
char *cgi_env[CGI_ENV_MAX + 4]; /* CGI environment */ |
179 |
|
180 |
#ifdef ACCEPT_ON |
181 |
char accept[MAX_ACCEPT_LENGTH]; /* Accept: fields */ |
182 |
#endif |
183 |
}; |
184 |
|
185 |
typedef struct request request; |
186 |
|
187 |
struct status { |
188 |
long requests; |
189 |
long errors; |
190 |
}; |
191 |
|
192 |
|
193 |
extern char *optarg; /* For getopt */ |
194 |
extern FILE *yyin; /* yacc input */ |
195 |
|
196 |
typedef struct { |
197 |
#ifdef ENABLE_SMP |
198 |
pthread_t tid; |
199 |
#endif |
200 |
request* request_ready; |
201 |
request* request_block; |
202 |
request* request_free; |
203 |
|
204 |
socket_type server_s[2]; |
205 |
|
206 |
#ifdef USE_POLL |
207 |
struct pollfd *pfds; |
208 |
int pfd_len; |
209 |
#else |
210 |
fd_set block_read_fdset; /* fds blocked on read */ |
211 |
fd_set block_write_fdset; /* fds blocked on write */ |
212 |
#endif |
213 |
|
214 |
struct timeval req_timeout; |
215 |
int sighup_flag; /* 1 => signal has happened, needs attention */ |
216 |
int sigchld_flag; /* 1 => signal has happened, needs attention */ |
217 |
int sigalrm_flag; /* 1 => signal has happened, needs attention */ |
218 |
int sigusr1_flag; /* 1 => signal has happened, needs attention */ |
219 |
int sigterm_flag; /* lame duck mode */ |
220 |
|
221 |
int max_fd; |
222 |
|
223 |
int sockbufsize; |
224 |
struct status status; |
225 |
int total_connections; |
226 |
|
227 |
/* for SIGBUS handling */ |
228 |
jmp_buf env; |
229 |
int handle_sigbus; |
230 |
|
231 |
} server_params; |
232 |
|
233 |
/* HIC request stuff |
234 |
*/ |
235 |
typedef struct _hic_request { |
236 |
struct _hic_request *next; |
237 |
struct _hic_request *prev; |
238 |
hic_stuff command; |
239 |
} hic_request; |
240 |
|
241 |
/* parameters passed to a hic thread */ |
242 |
typedef struct { |
243 |
#ifdef ENABLE_SMP |
244 |
pthread_t tid; |
245 |
pthread_mutex_t lock; |
246 |
#endif |
247 |
int sigchld_flag; /* 1 => signal has happened, needs attention */ |
248 |
int sighup_flag; |
249 |
hic_request* request_head; |
250 |
} hic_params; |
251 |
|
252 |
/* global server variables */ |
253 |
|
254 |
extern int mmap_list_entries_used; |
255 |
extern char *access_log_name; |
256 |
extern char *error_log_name; |
257 |
extern char *cgi_log_name; |
258 |
extern int cgi_log_fd; |
259 |
extern int use_localtime; |
260 |
|
261 |
extern int max_files_cache; |
262 |
extern int max_file_size_cache; |
263 |
|
264 |
extern int boa_ssl; |
265 |
|
266 |
extern int server_port; |
267 |
extern int ssl_port; |
268 |
extern uid_t server_uid; |
269 |
extern gid_t server_gid; |
270 |
extern char *server_admin; |
271 |
extern char *server_root; |
272 |
extern char *server_name; |
273 |
extern char *server_ip; |
274 |
extern int max_fd; |
275 |
|
276 |
extern char *default_type; |
277 |
extern char *default_charset; |
278 |
extern char *dirmaker; |
279 |
extern char *mime_types; |
280 |
extern char *pid_file; |
281 |
extern char *cachedir; |
282 |
|
283 |
extern char *default_document_root; |
284 |
extern int default_document_root_size; |
285 |
|
286 |
extern int system_bufsize; /* Default size of SNDBUF given by system */ |
287 |
|
288 |
extern char *tempdir; |
289 |
extern int tempdir_len; |
290 |
|
291 |
extern char *cgi_path; |
292 |
extern int single_post_limit; |
293 |
|
294 |
extern int ka_timeout; |
295 |
extern int ka_max; |
296 |
|
297 |
extern time_t start_time; |
298 |
|
299 |
extern int max_server_threads; |
300 |
extern int max_hic_threads; |
301 |
|
302 |
extern int cgi_umask; |
303 |
|
304 |
extern long int max_connections; |
305 |
|
306 |
extern int verbose_cgi_logs; |
307 |
|
308 |
extern int backlog; |
309 |
extern time_t current_time; |
310 |
|
311 |
/* Global stuff that is shared by all threads. |
312 |
* Use with extreme care, or don't use. |
313 |
*/ |
314 |
extern server_params *global_server_params; |
315 |
extern int global_server_params_size; |
316 |
|
317 |
#ifdef ENABLE_HIC |
318 |
extern hic_params *global_hic_params; |
319 |
extern int global_hic_params_size; |
320 |
#endif |
321 |
|
322 |
/* These contain a string of the form: "Server: Hydra/0.0.x\r\n" |
323 |
*/ |
324 |
extern char boa_tls_version[]; |
325 |
extern char boa_version[]; |
326 |
|
327 |
#endif |