1 |
nmav |
1.1 |
/* |
2 |
|
|
* Boa, an http server |
3 |
|
|
* Copyright (C) 1995 Paul Phillips <paulp@go2net.com> |
4 |
|
|
* Some changes Copyright (C) 1996-99 Larry Doolittle <ldoolitt@jlab.org> |
5 |
|
|
* Some changes Copyright (C) 1997-99 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 |
nmav |
1.26 |
/* $Id: boa.h,v 1.25 2002/10/04 19:09:12 nmav Exp $*/ |
24 |
nmav |
1.1 |
|
25 |
|
|
#ifndef _BOA_H |
26 |
|
|
#define _BOA_H |
27 |
|
|
|
28 |
|
|
#include <errno.h> |
29 |
|
|
#include <stdlib.h> /* malloc, free, etc. */ |
30 |
|
|
#include <stdio.h> /* stdin, stdout, stderr */ |
31 |
|
|
#include <string.h> /* strdup */ |
32 |
|
|
#include <ctype.h> |
33 |
|
|
#include <time.h> /* localtime, time */ |
34 |
|
|
#include <pwd.h> |
35 |
|
|
#include <grp.h> |
36 |
|
|
#include <unistd.h> |
37 |
|
|
#include <fcntl.h> |
38 |
|
|
#include <limits.h> /* OPEN_MAX */ |
39 |
|
|
#include <setjmp.h> |
40 |
|
|
|
41 |
|
|
#include <netdb.h> |
42 |
|
|
#include <netinet/in.h> |
43 |
|
|
|
44 |
|
|
#include <sys/mman.h> |
45 |
|
|
#include <sys/select.h> |
46 |
|
|
#include <sys/types.h> /* socket, bind, accept */ |
47 |
|
|
#include <sys/socket.h> /* socket, bind, accept, setsockopt, */ |
48 |
|
|
#include <sys/stat.h> /* open */ |
49 |
|
|
|
50 |
|
|
#include "compat.h" /* oh what fun is porting */ |
51 |
|
|
#include "defines.h" |
52 |
nmav |
1.14 |
#include "hic.h" |
53 |
nmav |
1.10 |
|
54 |
|
|
#ifdef ENABLE_SMP |
55 |
|
|
# include <pthread.h> |
56 |
|
|
#endif |
57 |
nmav |
1.4 |
|
58 |
|
|
#ifdef HAVE_NETINET_TCP_H |
59 |
|
|
# include <netinet/tcp.h> |
60 |
|
|
#endif |
61 |
|
|
|
62 |
nmav |
1.1 |
#include "globals.h" |
63 |
|
|
|
64 |
nmav |
1.24 |
|
65 |
nmav |
1.1 |
/* alias */ |
66 |
nmav |
1.7 |
void add_alias(char* hostname, char *fakename, char *realname, int script); |
67 |
nmav |
1.1 |
int translate_uri(request * req); |
68 |
|
|
int init_script_alias(request * req, alias * current, int uri_len); |
69 |
nmav |
1.7 |
void dump_alias( virthost*); |
70 |
nmav |
1.5 |
|
71 |
|
|
/* virthost */ |
72 |
|
|
void add_virthost(const char *host, const char *ip, const char* document_root, const char* user_dir); |
73 |
|
|
virthost *find_virthost(const char *host, int hostlen); |
74 |
nmav |
1.6 |
void dump_virthost(void); |
75 |
nmav |
1.9 |
|
76 |
|
|
/* directory_index */ |
77 |
|
|
char *find_and_open_directory_index(const char *directory, int dirlen, int* fd); |
78 |
|
|
void dump_directory_index(void); |
79 |
|
|
void add_directory_index( const char* index); |
80 |
|
|
char* find_default_directory_index( void); |
81 |
nmav |
1.1 |
|
82 |
|
|
/* config */ |
83 |
|
|
void read_config_files(void); |
84 |
|
|
|
85 |
|
|
/* escape */ |
86 |
|
|
#include "escape.h" |
87 |
|
|
|
88 |
|
|
/* get */ |
89 |
|
|
|
90 |
|
|
int init_get(server_params*, request * req); |
91 |
|
|
int process_get(server_params*, request * req); |
92 |
nmav |
1.24 |
int get_dir(request * req, stat_st *statbuf); |
93 |
nmav |
1.11 |
const char* hydra_method_str( int method); |
94 |
nmav |
1.1 |
|
95 |
|
|
/* hash */ |
96 |
|
|
unsigned get_mime_hash_value(char *extension); |
97 |
nmav |
1.19 |
char *get_mime_type(const char *filename); |
98 |
nmav |
1.1 |
char *get_home_dir(char *name); |
99 |
|
|
void dump_mime(void); |
100 |
|
|
void dump_passwd(void); |
101 |
|
|
void show_hash_stats(void); |
102 |
|
|
|
103 |
nmav |
1.15 |
int get_hash_value( const char* str); |
104 |
|
|
|
105 |
|
|
#define get_alias_hash_value(x) (get_hash_value(x)%ALIAS_HASHTABLE_SIZE) |
106 |
|
|
#define get_host_hash_value(x) (get_hash_value(x)%VIRTHOST_HASHTABLE_SIZE) |
107 |
nmav |
1.16 |
#define get_hic_module_hash_value(x) (get_hash_value(x)%MODULE_HASHTABLE_SIZE) |
108 |
nmav |
1.15 |
|
109 |
nmav |
1.1 |
/* log */ |
110 |
|
|
void open_logs(void); |
111 |
|
|
void close_access_log(void); |
112 |
|
|
void log_access(request * req); |
113 |
|
|
void log_error_doc(request * req); |
114 |
|
|
void boa_perror(request * req, char *message); |
115 |
|
|
void log_error_time(void); |
116 |
|
|
void log_error_mesg(char *file, int line, char *mesg); |
117 |
|
|
|
118 |
|
|
/* queue */ |
119 |
|
|
void block_request(server_params*, request * req); |
120 |
|
|
void ready_request(server_params*, request * req); |
121 |
|
|
void dequeue(request ** head, request * req); |
122 |
|
|
void enqueue(request ** head, request * req); |
123 |
|
|
|
124 |
|
|
/* read */ |
125 |
|
|
int read_header(server_params*, request * req); |
126 |
|
|
int read_body(request * req); |
127 |
|
|
int write_body(request * req); |
128 |
|
|
|
129 |
|
|
/* request */ |
130 |
|
|
request *new_request(server_params* params); |
131 |
nmav |
1.4 |
void get_request(server_params* params, socket_type*); |
132 |
|
|
void process_requests(server_params* params, socket_type* server_s); |
133 |
nmav |
1.1 |
int process_header_end(server_params*, request * req); |
134 |
|
|
int process_header_line(request * req); |
135 |
|
|
int process_logline(request * req); |
136 |
|
|
int process_option_line(request * req); |
137 |
|
|
void add_accept_header(request * req, char *mime_type); |
138 |
|
|
void free_requests(server_params* params); |
139 |
|
|
|
140 |
|
|
/* response */ |
141 |
|
|
void print_ka_phrase(request * req); |
142 |
|
|
void print_content_type(request * req); |
143 |
|
|
void print_content_length(request * req); |
144 |
|
|
void print_last_modified(request * req); |
145 |
|
|
void print_http_headers(request * req); |
146 |
|
|
|
147 |
|
|
void send_r_request_ok(request * req); /* 200 */ |
148 |
nmav |
1.3 |
void send_r_request_partial(request * req); /* 206 */ |
149 |
nmav |
1.1 |
void send_r_moved_perm(request * req, char *url); /* 301 */ |
150 |
|
|
void send_r_moved_temp(request * req, char *url, char *more_hdr); /* 302 */ |
151 |
|
|
void send_r_not_modified(request * req); /* 304 */ |
152 |
|
|
void send_r_bad_request(request * req); /* 400 */ |
153 |
|
|
void send_r_unauthorized(request * req, char *name); /* 401 */ |
154 |
|
|
void send_r_forbidden(request * req); /* 403 */ |
155 |
|
|
void send_r_not_found(request * req); /* 404 */ |
156 |
nmav |
1.22 |
void send_r_precondition_failed(request * req); /* 412 */ |
157 |
nmav |
1.3 |
void send_r_range_unsatisfiable(request * req); /* 416 */ |
158 |
nmav |
1.1 |
void send_r_error(request * req); /* 500 */ |
159 |
|
|
void send_r_not_implemented(request * req); /* 501 */ |
160 |
|
|
void send_r_bad_gateway(request * req); /* 502 */ |
161 |
|
|
void send_r_service_unavailable(request * req); /* 503 */ |
162 |
|
|
void send_r_bad_version(request * req); /* 505 */ |
163 |
|
|
|
164 |
|
|
/* cgi */ |
165 |
|
|
void create_common_env(void); |
166 |
|
|
void clear_common_env(void); |
167 |
nmav |
1.12 |
int add_cgi_env(request * req, const char *key, const char *value, int http_prefix); |
168 |
nmav |
1.25 |
int complete_env_ssl( request* req); |
169 |
nmav |
1.1 |
int complete_env(request * req); |
170 |
|
|
void create_argv(request * req, char **aargv); |
171 |
|
|
int init_cgi(request * req); |
172 |
nmav |
1.19 |
int is_executable_cgi( request* req, const char* filename); |
173 |
nmav |
1.1 |
|
174 |
|
|
/* signals */ |
175 |
|
|
void init_signals(void); |
176 |
|
|
void block_main_signals(void); |
177 |
|
|
void unblock_main_signals(void); |
178 |
nmav |
1.18 |
void block_sigusr2(void); |
179 |
|
|
void unblock_sigusr2(void); |
180 |
nmav |
1.1 |
void sighup_run(void); |
181 |
|
|
void sigchld_run(void); |
182 |
|
|
void sigalrm_run(void); |
183 |
|
|
void sigusr1_run(void); |
184 |
|
|
void sigterm_stage1_run(void); |
185 |
|
|
void sigterm_stage2_run(void); |
186 |
|
|
|
187 |
|
|
/* smp */ |
188 |
|
|
void smp_reinit(); |
189 |
nmav |
1.20 |
void hic_init(); |
190 |
nmav |
1.1 |
|
191 |
|
|
/* util.c */ |
192 |
|
|
void clean_pathname(char *pathname); |
193 |
nmav |
1.2 |
void get_commonlog_time(char buf[30]); |
194 |
nmav |
1.1 |
void rfc822_time_buf(char *buf, time_t s); |
195 |
nmav |
1.24 |
int simple_itoa(off64_t i, char buf[22]); |
196 |
nmav |
1.3 |
int boa_atoi(const char *s); |
197 |
nmav |
1.24 |
off64_t boa_atoll(const char *s); |
198 |
nmav |
1.23 |
int create_etag(unsigned long int size, unsigned long int mod_time, |
199 |
|
|
char buf[MAX_ETAG_LENGTH]); |
200 |
nmav |
1.1 |
char *escape_string(char *inp, char *buf); |
201 |
|
|
int month2int(char *month); |
202 |
nmav |
1.22 |
int modified_since(time_t mtime, char *if_modified_since); |
203 |
nmav |
1.1 |
char *to_upper(char *str); |
204 |
|
|
int unescape_uri(char *uri, char **query_string); |
205 |
|
|
int create_temporary_file(short want_unlink, char *storage, int size); |
206 |
|
|
char * normalize_path(char *path); |
207 |
|
|
int real_set_block_fd(int fd); |
208 |
|
|
int real_set_nonblock_fd(int fd); |
209 |
nmav |
1.21 |
void create_url( char * buffer, int buffer_size, int secure, |
210 |
|
|
const char* hostname, int port, const char* request_uri); |
211 |
nmav |
1.26 |
void break_comma_list(char *list, |
212 |
|
|
char *broken_list[MAX_COMMA_SEP_ELEMENTS], int *elements); |
213 |
nmav |
1.21 |
|
214 |
nmav |
1.1 |
/* buffer */ |
215 |
nmav |
1.2 |
int req_write(request * req, const char *msg); |
216 |
nmav |
1.1 |
void reset_output_buffer(request *req); |
217 |
|
|
int req_write_escape_http(request * req, char *msg); |
218 |
|
|
int req_write_escape_html(request * req, char *msg); |
219 |
|
|
int req_flush(request * req); |
220 |
|
|
char *escape_uri(char *uri); |
221 |
|
|
|
222 |
|
|
/* timestamp */ |
223 |
|
|
void timestamp(void); |
224 |
|
|
|
225 |
|
|
/* mmap_cache */ |
226 |
nmav |
1.24 |
struct mmap_entry *find_mmap( int data_fd, stat_st *s); |
227 |
nmav |
1.1 |
void release_mmap( struct mmap_entry *e); |
228 |
nmav |
1.8 |
void initialize_mmap( void); |
229 |
|
|
void mmap_reinit( void); |
230 |
nmav |
1.1 |
|
231 |
|
|
/* sublog */ |
232 |
|
|
int open_gen_fd(char *spec); |
233 |
|
|
int process_cgi_header(request * req); |
234 |
|
|
|
235 |
|
|
/* pipe */ |
236 |
|
|
int read_from_pipe(request * req); |
237 |
|
|
int write_from_pipe(request * req); |
238 |
|
|
|
239 |
|
|
/* ip */ |
240 |
|
|
int bind_server(int server_s, char *ip, int port); |
241 |
|
|
char *ascii_sockaddr(struct SOCKADDR *s, char *dest, int len); |
242 |
|
|
int net_port(struct SOCKADDR *s); |
243 |
|
|
|
244 |
|
|
/* select */ |
245 |
|
|
void* select_loop(void*); |
246 |
nmav |
1.14 |
|
247 |
|
|
/* HIC stuff */ |
248 |
nmav |
1.13 |
void* hic_main_loop(void*); |
249 |
|
|
|
250 |
nmav |
1.15 |
void dump_hic_modules( void); |
251 |
nmav |
1.14 |
void add_hic_module(const char *module, const char* sym_prefix, const char* file_suffix); |
252 |
nmav |
1.15 |
hic_module_st *find_hic_appr_module(const char *content_type, int content_type_len); |
253 |
|
|
|
254 |
nmav |
1.13 |
int hic_send_command( request *req, int out_fd); |
255 |
nmav |
1.26 |
|
256 |
|
|
/* SSL */ |
257 |
|
|
void ssl_reinit(); |
258 |
nmav |
1.1 |
|
259 |
|
|
#endif |