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.5 |
/* $Id: boa.h,v 1.4 2002/09/23 17:56:41 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.4 |
|
53 |
|
|
#ifdef HAVE_NETINET_TCP_H |
54 |
|
|
# include <netinet/tcp.h> |
55 |
|
|
#endif |
56 |
|
|
|
57 |
nmav |
1.1 |
#include "globals.h" |
58 |
|
|
|
59 |
|
|
/* alias */ |
60 |
|
|
void add_alias(char *fakename, char *realname, int script); |
61 |
|
|
int translate_uri(request * req); |
62 |
|
|
int init_script_alias(request * req, alias * current, int uri_len); |
63 |
|
|
void dump_alias(void); |
64 |
nmav |
1.5 |
void dump_virthost(void); |
65 |
|
|
|
66 |
|
|
/* virthost */ |
67 |
|
|
void add_virthost(const char *host, const char *ip, const char* document_root, const char* user_dir); |
68 |
|
|
virthost *find_virthost(const char *host, int hostlen); |
69 |
nmav |
1.1 |
|
70 |
|
|
/* config */ |
71 |
|
|
void read_config_files(void); |
72 |
|
|
|
73 |
|
|
/* escape */ |
74 |
|
|
#include "escape.h" |
75 |
|
|
|
76 |
|
|
/* get */ |
77 |
|
|
|
78 |
|
|
int init_get(server_params*, request * req); |
79 |
|
|
int process_get(server_params*, request * req); |
80 |
|
|
int get_dir(request * req, struct stat *statbuf); |
81 |
|
|
|
82 |
|
|
/* hash */ |
83 |
|
|
unsigned get_mime_hash_value(char *extension); |
84 |
|
|
char *get_mime_type(char *filename); |
85 |
|
|
char *get_home_dir(char *name); |
86 |
|
|
void dump_mime(void); |
87 |
|
|
void dump_passwd(void); |
88 |
|
|
void show_hash_stats(void); |
89 |
|
|
|
90 |
|
|
/* log */ |
91 |
|
|
void open_logs(void); |
92 |
|
|
void close_access_log(void); |
93 |
|
|
void log_access(request * req); |
94 |
|
|
void log_error_doc(request * req); |
95 |
|
|
void boa_perror(request * req, char *message); |
96 |
|
|
void log_error_time(void); |
97 |
|
|
void log_error_mesg(char *file, int line, char *mesg); |
98 |
|
|
|
99 |
|
|
/* queue */ |
100 |
|
|
void block_request(server_params*, request * req); |
101 |
|
|
void ready_request(server_params*, request * req); |
102 |
|
|
void dequeue(request ** head, request * req); |
103 |
|
|
void enqueue(request ** head, request * req); |
104 |
|
|
|
105 |
|
|
/* read */ |
106 |
|
|
int read_header(server_params*, request * req); |
107 |
|
|
int read_body(request * req); |
108 |
|
|
int write_body(request * req); |
109 |
|
|
|
110 |
|
|
/* request */ |
111 |
|
|
request *new_request(server_params* params); |
112 |
nmav |
1.4 |
void get_request(server_params* params, socket_type*); |
113 |
|
|
void process_requests(server_params* params, socket_type* server_s); |
114 |
nmav |
1.1 |
int process_header_end(server_params*, request * req); |
115 |
|
|
int process_header_line(request * req); |
116 |
|
|
int process_logline(request * req); |
117 |
|
|
int process_option_line(request * req); |
118 |
|
|
void add_accept_header(request * req, char *mime_type); |
119 |
|
|
void free_requests(server_params* params); |
120 |
|
|
|
121 |
|
|
/* response */ |
122 |
|
|
void print_ka_phrase(request * req); |
123 |
|
|
void print_content_type(request * req); |
124 |
|
|
void print_content_length(request * req); |
125 |
|
|
void print_last_modified(request * req); |
126 |
|
|
void print_http_headers(request * req); |
127 |
|
|
|
128 |
|
|
void send_r_request_ok(request * req); /* 200 */ |
129 |
nmav |
1.3 |
void send_r_request_partial(request * req); /* 206 */ |
130 |
nmav |
1.1 |
void send_r_moved_perm(request * req, char *url); /* 301 */ |
131 |
|
|
void send_r_moved_temp(request * req, char *url, char *more_hdr); /* 302 */ |
132 |
|
|
void send_r_not_modified(request * req); /* 304 */ |
133 |
|
|
void send_r_bad_request(request * req); /* 400 */ |
134 |
|
|
void send_r_unauthorized(request * req, char *name); /* 401 */ |
135 |
|
|
void send_r_forbidden(request * req); /* 403 */ |
136 |
|
|
void send_r_not_found(request * req); /* 404 */ |
137 |
nmav |
1.3 |
void send_r_range_unsatisfiable(request * req); /* 416 */ |
138 |
nmav |
1.1 |
void send_r_error(request * req); /* 500 */ |
139 |
|
|
void send_r_not_implemented(request * req); /* 501 */ |
140 |
|
|
void send_r_bad_gateway(request * req); /* 502 */ |
141 |
|
|
void send_r_service_unavailable(request * req); /* 503 */ |
142 |
|
|
void send_r_bad_version(request * req); /* 505 */ |
143 |
|
|
|
144 |
|
|
/* cgi */ |
145 |
|
|
void create_common_env(void); |
146 |
|
|
void clear_common_env(void); |
147 |
|
|
int add_cgi_env(request * req, char *key, char *value, int http_prefix); |
148 |
|
|
int complete_env(request * req); |
149 |
|
|
void create_argv(request * req, char **aargv); |
150 |
|
|
int init_cgi(request * req); |
151 |
|
|
|
152 |
|
|
/* signals */ |
153 |
|
|
void init_signals(void); |
154 |
|
|
void block_main_signals(void); |
155 |
|
|
void unblock_main_signals(void); |
156 |
|
|
void sighup_run(void); |
157 |
|
|
void sigchld_run(void); |
158 |
|
|
void sigalrm_run(void); |
159 |
|
|
void sigusr1_run(void); |
160 |
|
|
void sigterm_stage1_run(void); |
161 |
|
|
void sigterm_stage2_run(void); |
162 |
|
|
|
163 |
|
|
/* smp */ |
164 |
|
|
void smp_reinit(); |
165 |
|
|
|
166 |
|
|
/* util.c */ |
167 |
|
|
void clean_pathname(char *pathname); |
168 |
nmav |
1.2 |
void get_commonlog_time(char buf[30]); |
169 |
nmav |
1.1 |
void rfc822_time_buf(char *buf, time_t s); |
170 |
nmav |
1.3 |
void simple_itoa(unsigned long int i, char buf[22]); |
171 |
|
|
int boa_atoi(const char *s); |
172 |
nmav |
1.1 |
char *escape_string(char *inp, char *buf); |
173 |
|
|
int month2int(char *month); |
174 |
|
|
int modified_since(time_t * mtime, char *if_modified_since); |
175 |
|
|
char *to_upper(char *str); |
176 |
|
|
int unescape_uri(char *uri, char **query_string); |
177 |
|
|
int create_temporary_file(short want_unlink, char *storage, int size); |
178 |
|
|
char * normalize_path(char *path); |
179 |
|
|
int real_set_block_fd(int fd); |
180 |
|
|
int real_set_nonblock_fd(int fd); |
181 |
|
|
|
182 |
|
|
/* buffer */ |
183 |
nmav |
1.2 |
int req_write(request * req, const char *msg); |
184 |
nmav |
1.1 |
void reset_output_buffer(request *req); |
185 |
|
|
int req_write_escape_http(request * req, char *msg); |
186 |
|
|
int req_write_escape_html(request * req, char *msg); |
187 |
|
|
int req_flush(request * req); |
188 |
|
|
char *escape_uri(char *uri); |
189 |
|
|
|
190 |
|
|
/* timestamp */ |
191 |
|
|
void timestamp(void); |
192 |
|
|
|
193 |
|
|
/* mmap_cache */ |
194 |
|
|
struct mmap_entry *find_mmap( int data_fd, struct stat *s); |
195 |
|
|
void release_mmap( struct mmap_entry *e); |
196 |
|
|
|
197 |
|
|
/* sublog */ |
198 |
|
|
int open_gen_fd(char *spec); |
199 |
|
|
int process_cgi_header(request * req); |
200 |
|
|
|
201 |
|
|
/* pipe */ |
202 |
|
|
int read_from_pipe(request * req); |
203 |
|
|
int write_from_pipe(request * req); |
204 |
|
|
|
205 |
|
|
/* ip */ |
206 |
|
|
int bind_server(int server_s, char *ip, int port); |
207 |
|
|
char *ascii_sockaddr(struct SOCKADDR *s, char *dest, int len); |
208 |
|
|
int net_port(struct SOCKADDR *s); |
209 |
|
|
|
210 |
|
|
/* select */ |
211 |
|
|
void* select_loop(void*); |
212 |
|
|
|
213 |
|
|
#endif |