1 |
nmav |
1.1 |
/* |
2 |
nmav |
1.15 |
* Hydra, an http server |
3 |
nmav |
1.1 |
* Copyright (C) 1995 Paul Phillips <paulp@go2net.com> |
4 |
|
|
* Some changes Copyright (C) 1996,97 Larry Doolittle <ldoolitt@boa.org> |
5 |
|
|
* Some changes Copyright (C) 1996-2002 Jon Nelson <jnelson@boa.org> |
6 |
|
|
* Portions Copyright (C) 2002 Nikos Mavroyanopoulos <nmav@gnutls.org> |
7 |
|
|
* |
8 |
|
|
* This program is free software; you can redistribute it and/or modify |
9 |
|
|
* it under the terms of the GNU General Public License as published by |
10 |
|
|
* the Free Software Foundation; either version 1, or (at your option) |
11 |
|
|
* any later version. |
12 |
|
|
* |
13 |
|
|
* This program is distributed in the hope that it will be useful, |
14 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 |
|
|
* GNU General Public License for more details. |
17 |
|
|
* |
18 |
|
|
* You should have received a copy of the GNU General Public License |
19 |
|
|
* along with this program; if not, write to the Free Software |
20 |
|
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
21 |
|
|
* |
22 |
|
|
*/ |
23 |
|
|
|
24 |
nmav |
1.28 |
/* $Id: request.c,v 1.27 2002/10/04 19:09:12 nmav Exp $*/ |
25 |
nmav |
1.1 |
|
26 |
|
|
#include "boa.h" |
27 |
|
|
#include <stddef.h> /* for offsetof */ |
28 |
|
|
#include "ssl.h" |
29 |
|
|
#include "socket.h" |
30 |
|
|
|
31 |
|
|
extern int boa_ssl; |
32 |
|
|
|
33 |
|
|
/* function prototypes located in this file only */ |
34 |
|
|
static void free_request( server_params* params, request ** list_head_addr, |
35 |
|
|
request * req); |
36 |
|
|
|
37 |
|
|
/* |
38 |
|
|
* Name: new_request |
39 |
|
|
* Description: Obtains a request struct off the free list, or if the |
40 |
|
|
* free list is empty, allocates memory |
41 |
|
|
* |
42 |
|
|
* Return value: pointer to initialized request |
43 |
|
|
*/ |
44 |
|
|
|
45 |
|
|
request *new_request(server_params* params) |
46 |
|
|
{ |
47 |
|
|
request *req; |
48 |
|
|
|
49 |
|
|
if (params->request_free) { |
50 |
|
|
req = params->request_free; /* first on free list */ |
51 |
|
|
dequeue(¶ms->request_free, params->request_free); /* dequeue the head */ |
52 |
|
|
} else { |
53 |
|
|
req = (request *) malloc(sizeof (request)); |
54 |
|
|
if (!req) { |
55 |
|
|
log_error_time(); |
56 |
|
|
perror("malloc for new request"); |
57 |
|
|
return NULL; |
58 |
|
|
} |
59 |
|
|
} |
60 |
|
|
|
61 |
|
|
memset(req, 0, offsetof(request, buffer) + 1); |
62 |
|
|
req->data_fd = -1; |
63 |
|
|
req->post_data_fd = -1; |
64 |
|
|
|
65 |
|
|
return req; |
66 |
|
|
} |
67 |
|
|
|
68 |
|
|
#ifdef ENABLE_SMP |
69 |
nmav |
1.25 |
static pthread_mutex_t accept_mutex = PTHREAD_MUTEX_INITIALIZER; |
70 |
nmav |
1.1 |
#endif |
71 |
|
|
|
72 |
nmav |
1.25 |
static int total_global_connections = 0; |
73 |
|
|
|
74 |
|
|
/* Decreases total_global_connections, but does some locking |
75 |
|
|
* too. |
76 |
|
|
*/ |
77 |
|
|
inline |
78 |
|
|
static void decrease_global_total_connections() |
79 |
|
|
{ |
80 |
|
|
/* if we do want to serv as much as possible, then |
81 |
|
|
* don't bother counting connections. |
82 |
|
|
*/ |
83 |
|
|
if (max_connections == INT_MAX) return; |
84 |
|
|
|
85 |
|
|
#ifdef ENABLE_SMP |
86 |
|
|
pthread_mutex_lock( &accept_mutex); |
87 |
|
|
#endif |
88 |
|
|
total_global_connections--; |
89 |
|
|
#ifdef ENABLE_SMP |
90 |
|
|
pthread_mutex_unlock( &accept_mutex); |
91 |
|
|
#endif |
92 |
|
|
|
93 |
|
|
} |
94 |
|
|
|
95 |
nmav |
1.1 |
/* |
96 |
|
|
* Name: get_request |
97 |
|
|
* |
98 |
|
|
* Description: Polls the server socket for a request. If one exists, |
99 |
|
|
* does some basic initialization and adds it to the ready queue;. |
100 |
|
|
*/ |
101 |
|
|
|
102 |
nmav |
1.5 |
void get_request(server_params* params, socket_type *server_s) |
103 |
nmav |
1.1 |
{ |
104 |
|
|
int fd; /* socket */ |
105 |
|
|
struct SOCKADDR remote_addr; /* address */ |
106 |
|
|
struct SOCKADDR salocal; |
107 |
|
|
int remote_addrlen = sizeof (struct SOCKADDR); |
108 |
|
|
request *conn; /* connection */ |
109 |
nmav |
1.26 |
int len; |
110 |
nmav |
1.1 |
static int system_bufsize = 0; /* Default size of SNDBUF given by system */ |
111 |
nmav |
1.14 |
#ifdef ENABLE_SSL |
112 |
nmav |
1.1 |
gnutls_session ssl_state = NULL; |
113 |
nmav |
1.14 |
#endif |
114 |
nmav |
1.1 |
|
115 |
|
|
remote_addr.S_FAMILY = 0xdead; |
116 |
|
|
|
117 |
|
|
#ifdef ENABLE_SMP |
118 |
nmav |
1.3 |
/* here we make use of the fact that server_s.secure is |
119 |
|
|
* 0 or 1, and we have 2 mutexes, one for the secure port, |
120 |
|
|
* and one of the normal http port. |
121 |
|
|
*/ |
122 |
nmav |
1.25 |
pthread_mutex_lock( &accept_mutex); |
123 |
nmav |
1.1 |
#endif |
124 |
nmav |
1.25 |
|
125 |
|
|
/* If we have reached our max connections limit |
126 |
|
|
*/ |
127 |
|
|
if (total_global_connections >= max_connections) { |
128 |
|
|
server_s->pending_requests = 0; |
129 |
|
|
goto unlock; |
130 |
|
|
} |
131 |
|
|
|
132 |
nmav |
1.5 |
fd = accept(server_s->socket, (struct sockaddr *) &remote_addr, |
133 |
nmav |
1.1 |
&remote_addrlen); |
134 |
|
|
|
135 |
|
|
if (fd == -1) { |
136 |
|
|
if (errno != EAGAIN && errno != EWOULDBLOCK) |
137 |
|
|
/* abnormal error */ |
138 |
|
|
WARN("accept"); |
139 |
|
|
else |
140 |
|
|
/* no requests */ |
141 |
nmav |
1.5 |
server_s->pending_requests = 0; |
142 |
nmav |
1.25 |
goto unlock; |
143 |
nmav |
1.1 |
} |
144 |
nmav |
1.25 |
|
145 |
|
|
/* only count, if we have enabled a connection limit */ |
146 |
|
|
if (max_connections != INT_MAX) |
147 |
|
|
total_global_connections++; |
148 |
|
|
|
149 |
|
|
#ifdef ENABLE_SMP |
150 |
|
|
/* No dead lock conditions here, since accept() is non blocking. |
151 |
|
|
*/ |
152 |
|
|
pthread_mutex_unlock( &accept_mutex); |
153 |
|
|
#endif |
154 |
|
|
|
155 |
nmav |
1.1 |
if (fd >= FD_SETSIZE) { |
156 |
|
|
WARN("Got fd >= FD_SETSIZE."); |
157 |
|
|
close(fd); |
158 |
|
|
return; |
159 |
|
|
} |
160 |
|
|
#ifdef DEBUGNONINET |
161 |
|
|
/* This shows up due to race conditions in some Linux kernels |
162 |
|
|
when the client closes the socket sometime between |
163 |
|
|
the select() and accept() syscalls. |
164 |
|
|
Code and description by Larry Doolittle <ldoolitt@boa.org> |
165 |
|
|
*/ |
166 |
|
|
#define HEX(x) (((x)>9)?(('a'-10)+(x)):('0'+(x))) |
167 |
|
|
if (remote_addr.sin_family != AF_INET) { |
168 |
|
|
struct sockaddr *bogus = (struct sockaddr *) &remote_addr; |
169 |
|
|
char *ap, ablock[44]; |
170 |
|
|
int i; |
171 |
|
|
close(fd); |
172 |
|
|
log_error_time(); |
173 |
|
|
for (ap = ablock, i = 0; i < remote_addrlen && i < 14; i++) { |
174 |
|
|
*ap++ = ' '; |
175 |
|
|
*ap++ = HEX((bogus->sa_data[i] >> 4) & 0x0f); |
176 |
|
|
*ap++ = HEX(bogus->sa_data[i] & 0x0f); |
177 |
|
|
} |
178 |
|
|
*ap = '\0'; |
179 |
|
|
fprintf(stderr, "non-INET connection attempt: socket %d, " |
180 |
|
|
"sa_family = %hu, sa_data[%d] = %s\n", |
181 |
|
|
fd, bogus->sa_family, remote_addrlen, ablock); |
182 |
|
|
return; |
183 |
|
|
} |
184 |
|
|
#endif |
185 |
|
|
|
186 |
|
|
/* XXX Either delete this, or document why it's needed */ |
187 |
|
|
/* Pointed out 3-Oct-1999 by Paul Saab <paul@mu.org> */ |
188 |
|
|
#ifdef REUSE_EACH_CLIENT_CONNECTION_SOCKET |
189 |
|
|
if ((setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (void *) &sock_opt, |
190 |
|
|
sizeof (sock_opt))) == -1) { |
191 |
|
|
DIE("setsockopt: unable to set SO_REUSEADDR"); |
192 |
|
|
} |
193 |
|
|
#endif |
194 |
|
|
|
195 |
|
|
#ifdef ENABLE_SSL |
196 |
nmav |
1.5 |
if ( server_s->secure) { |
197 |
nmav |
1.1 |
ssl_state = initialize_ssl_session(); |
198 |
|
|
if (ssl_state == NULL) { |
199 |
|
|
WARN("Could not initialize ssl state."); |
200 |
|
|
close(fd); |
201 |
|
|
return; |
202 |
|
|
} |
203 |
|
|
|
204 |
|
|
gnutls_transport_set_ptr( ssl_state, fd); |
205 |
|
|
} |
206 |
|
|
#endif |
207 |
|
|
|
208 |
|
|
len = sizeof(salocal); |
209 |
|
|
|
210 |
|
|
if (getsockname(fd, (struct sockaddr *) &salocal, &len) != 0) { |
211 |
|
|
WARN("getsockname"); |
212 |
|
|
close(fd); |
213 |
|
|
return; |
214 |
|
|
} |
215 |
|
|
|
216 |
|
|
conn = new_request( params); |
217 |
|
|
if (!conn) { |
218 |
|
|
close(fd); |
219 |
|
|
return; |
220 |
|
|
} |
221 |
|
|
conn->fd = fd; |
222 |
nmav |
1.14 |
#ifdef ENABLE_SSL |
223 |
nmav |
1.1 |
conn->ssl_state = ssl_state; |
224 |
nmav |
1.14 |
#endif |
225 |
nmav |
1.1 |
|
226 |
nmav |
1.5 |
if (server_s->secure != 0) conn->secure = 1; |
227 |
nmav |
1.1 |
else conn->secure = 0; |
228 |
|
|
|
229 |
nmav |
1.5 |
if ( server_s->secure != 0) |
230 |
nmav |
1.1 |
conn->status = FINISH_HANDSHAKE; |
231 |
|
|
else conn->status = READ_HEADER; |
232 |
|
|
|
233 |
|
|
conn->header_line = conn->client_stream; |
234 |
|
|
conn->time_last = current_time; |
235 |
|
|
conn->kacount = ka_max; |
236 |
|
|
|
237 |
|
|
ascii_sockaddr(&salocal, conn->local_ip_addr, NI_MAXHOST); |
238 |
nmav |
1.7 |
|
239 |
|
|
if (default_document_root) |
240 |
|
|
memcpy( conn->document_root, default_document_root, default_document_root_size + 1); |
241 |
nmav |
1.1 |
|
242 |
nmav |
1.8 |
if (server_name) |
243 |
|
|
conn->hostname = server_name; |
244 |
|
|
|
245 |
nmav |
1.1 |
/* nonblocking socket */ |
246 |
|
|
if (set_nonblock_fd(conn->fd) == -1) |
247 |
|
|
WARN("fcntl: unable to set new socket to non-block"); |
248 |
|
|
|
249 |
|
|
/* set close on exec to true */ |
250 |
|
|
if (fcntl(conn->fd, F_SETFD, 1) == -1) |
251 |
|
|
WARN("fctnl: unable to set close-on-exec for new socket"); |
252 |
|
|
|
253 |
|
|
/* Increase buffer size if we have to. |
254 |
|
|
* Only ask the system the buffer size on the first request, |
255 |
|
|
* and assume all subsequent sockets have the same size. |
256 |
|
|
*/ |
257 |
|
|
if (system_bufsize == 0) { |
258 |
|
|
len = sizeof (system_bufsize); |
259 |
|
|
if (getsockopt |
260 |
|
|
(conn->fd, SOL_SOCKET, SO_SNDBUF, &system_bufsize, &len) == 0 |
261 |
|
|
&& len == sizeof (system_bufsize)) { |
262 |
|
|
/* |
263 |
|
|
fprintf(stderr, "%sgetsockopt reports SNDBUF %d\n", |
264 |
|
|
get_commonlog_time(), system_bufsize); |
265 |
|
|
*/ |
266 |
|
|
; |
267 |
|
|
} else { |
268 |
|
|
WARN("getsockopt(SNDBUF)"); |
269 |
|
|
system_bufsize = 1; |
270 |
|
|
} |
271 |
|
|
} |
272 |
|
|
if (system_bufsize < params->sockbufsize) { |
273 |
|
|
if (setsockopt |
274 |
|
|
(conn->fd, SOL_SOCKET, SO_SNDBUF, (void *) ¶ms->sockbufsize, |
275 |
|
|
sizeof (params->sockbufsize)) == -1) { |
276 |
|
|
WARN("setsockopt: unable to set socket buffer size"); |
277 |
|
|
#ifdef DIE_ON_ERROR_TUNING_SNDBUF |
278 |
|
|
exit(errno); |
279 |
|
|
#endif |
280 |
|
|
} |
281 |
|
|
} |
282 |
|
|
|
283 |
|
|
/* for log file and possible use by CGI programs */ |
284 |
|
|
ascii_sockaddr(&remote_addr, conn->remote_ip_addr, NI_MAXHOST); |
285 |
|
|
|
286 |
|
|
/* for possible use by CGI programs */ |
287 |
|
|
conn->remote_port = net_port(&remote_addr); |
288 |
|
|
|
289 |
|
|
params->status.requests++; |
290 |
|
|
|
291 |
nmav |
1.28 |
socket_set_options(conn->fd); |
292 |
nmav |
1.5 |
|
293 |
nmav |
1.1 |
params->total_connections++; |
294 |
|
|
|
295 |
|
|
enqueue(¶ms->request_ready, conn); |
296 |
nmav |
1.25 |
|
297 |
|
|
return; |
298 |
|
|
|
299 |
|
|
unlock: |
300 |
|
|
#ifdef ENABLE_SMP |
301 |
|
|
pthread_mutex_unlock( &accept_mutex); |
302 |
|
|
#endif |
303 |
|
|
return; |
304 |
nmav |
1.1 |
} |
305 |
|
|
|
306 |
|
|
|
307 |
|
|
/* |
308 |
|
|
* Name: free_request |
309 |
|
|
* |
310 |
|
|
* Description: Deallocates memory for a finished request and closes |
311 |
|
|
* down socket. |
312 |
|
|
*/ |
313 |
|
|
|
314 |
|
|
static void free_request( server_params *params, request ** list_head_addr, request * req) |
315 |
|
|
{ |
316 |
|
|
int i; |
317 |
|
|
/* free_request should *never* get called by anything but |
318 |
|
|
process_requests */ |
319 |
|
|
|
320 |
|
|
if (req->buffer_end && req->status != DEAD) { |
321 |
|
|
req->status = DONE; |
322 |
|
|
return; |
323 |
|
|
} |
324 |
|
|
/* put request on the free list */ |
325 |
|
|
dequeue(list_head_addr, req); /* dequeue from ready or block list */ |
326 |
|
|
|
327 |
|
|
if (req->logline) /* access log */ |
328 |
|
|
log_access(req); |
329 |
|
|
|
330 |
|
|
if (req->mmap_entry_var) |
331 |
|
|
release_mmap( req->mmap_entry_var); |
332 |
|
|
/* FIXME: Why is it needed? */ else if (req->data_mem) |
333 |
|
|
munmap(req->data_mem, req->filesize); |
334 |
|
|
|
335 |
|
|
if (req->data_fd != -1) |
336 |
|
|
close(req->data_fd); |
337 |
|
|
|
338 |
|
|
if (req->post_data_fd != -1) |
339 |
|
|
close(req->post_data_fd); |
340 |
|
|
|
341 |
|
|
if (req->response_status >= 400) |
342 |
|
|
params->status.errors++; |
343 |
|
|
|
344 |
|
|
for (i = COMMON_CGI_COUNT; i < req->cgi_env_index; ++i) { |
345 |
|
|
if (req->cgi_env[i]) { |
346 |
|
|
free(req->cgi_env[i]); |
347 |
|
|
} else { |
348 |
|
|
log_error_time(); |
349 |
|
|
fprintf(stderr, "Warning: CGI Environment contains NULL value" \ |
350 |
|
|
"(index %d of %d).\n", i, req->cgi_env_index); |
351 |
|
|
} |
352 |
|
|
} |
353 |
|
|
|
354 |
|
|
if (req->pathname) |
355 |
|
|
free(req->pathname); |
356 |
nmav |
1.20 |
if (req->query_string) |
357 |
|
|
free(req->query_string); |
358 |
nmav |
1.1 |
if (req->path_info) |
359 |
|
|
free(req->path_info); |
360 |
|
|
if (req->path_translated) |
361 |
|
|
free(req->path_translated); |
362 |
|
|
if (req->script_name) |
363 |
|
|
free(req->script_name); |
364 |
|
|
|
365 |
|
|
if ((req->keepalive == KA_ACTIVE) && |
366 |
|
|
(req->response_status < 500) && req->kacount > 0) { |
367 |
|
|
int bytes_to_move; |
368 |
|
|
|
369 |
|
|
request *conn = new_request( params); |
370 |
|
|
if (!conn) { |
371 |
|
|
/* errors already reported */ |
372 |
|
|
enqueue(¶ms->request_free, req); |
373 |
|
|
close(req->fd); |
374 |
|
|
params->total_connections--; |
375 |
nmav |
1.25 |
decrease_global_total_connections(); |
376 |
nmav |
1.1 |
return; |
377 |
|
|
} |
378 |
|
|
conn->fd = req->fd; |
379 |
|
|
|
380 |
|
|
#ifdef ENABLE_SSL |
381 |
|
|
if ( req->secure != 0) { |
382 |
|
|
conn->ssl_state = initialize_ssl_session(); |
383 |
|
|
conn->secure = 1; |
384 |
|
|
|
385 |
|
|
if (conn->ssl_state == NULL) { |
386 |
|
|
enqueue(¶ms->request_free, req); |
387 |
|
|
close(req->fd); |
388 |
|
|
params->total_connections--; |
389 |
nmav |
1.25 |
decrease_global_total_connections(); |
390 |
nmav |
1.1 |
return; |
391 |
|
|
} |
392 |
|
|
|
393 |
|
|
gnutls_transport_set_ptr( conn->ssl_state, conn->fd); |
394 |
|
|
conn->status = FINISH_HANDSHAKE; |
395 |
|
|
} else { |
396 |
|
|
#endif |
397 |
|
|
conn->secure = 0; |
398 |
|
|
conn->status = READ_HEADER; |
399 |
|
|
#ifdef ENABLE_SSL |
400 |
nmav |
1.14 |
conn->ssl_state = NULL; |
401 |
nmav |
1.1 |
} |
402 |
|
|
#endif |
403 |
|
|
|
404 |
|
|
conn->header_line = conn->client_stream; |
405 |
|
|
conn->kacount = req->kacount - 1; |
406 |
|
|
|
407 |
|
|
/* close enough and we avoid a call to time(NULL) */ |
408 |
|
|
conn->time_last = req->time_last; |
409 |
|
|
|
410 |
|
|
/* for log file and possible use by CGI programs */ |
411 |
|
|
memcpy(conn->remote_ip_addr, req->remote_ip_addr, NI_MAXHOST); |
412 |
|
|
memcpy(conn->local_ip_addr, req->local_ip_addr, NI_MAXHOST); |
413 |
|
|
|
414 |
|
|
/* for possible use by CGI programs */ |
415 |
|
|
conn->remote_port = req->remote_port; |
416 |
|
|
|
417 |
|
|
params->status.requests++; |
418 |
|
|
|
419 |
|
|
/* we haven't parsed beyond req->parse_pos, so... */ |
420 |
|
|
bytes_to_move = req->client_stream_pos - req->parse_pos; |
421 |
|
|
|
422 |
|
|
if (bytes_to_move) { |
423 |
|
|
memcpy(conn->client_stream, |
424 |
|
|
req->client_stream + req->parse_pos, bytes_to_move); |
425 |
|
|
conn->client_stream_pos = bytes_to_move; |
426 |
|
|
} |
427 |
|
|
enqueue(¶ms->request_block, conn); |
428 |
|
|
|
429 |
|
|
BOA_FD_SET(conn->fd, ¶ms->block_read_fdset); |
430 |
|
|
|
431 |
|
|
enqueue(¶ms->request_free, req); |
432 |
|
|
|
433 |
|
|
return; |
434 |
|
|
} |
435 |
|
|
|
436 |
|
|
/* |
437 |
|
|
While debugging some weird errors, Jon Nelson learned that |
438 |
|
|
some versions of Netscape Navigator break the |
439 |
|
|
HTTP specification. |
440 |
|
|
|
441 |
|
|
Some research on the issue brought up: |
442 |
|
|
|
443 |
|
|
http://www.apache.org/docs/misc/known_client_problems.html |
444 |
|
|
|
445 |
|
|
As quoted here: |
446 |
|
|
|
447 |
|
|
" |
448 |
|
|
Trailing CRLF on POSTs |
449 |
|
|
|
450 |
|
|
This is a legacy issue. The CERN webserver required POST |
451 |
|
|
data to have an extra CRLF following it. Thus many |
452 |
|
|
clients send an extra CRLF that is not included in the |
453 |
|
|
Content-Length of the request. Apache works around this |
454 |
|
|
problem by eating any empty lines which appear before a |
455 |
|
|
request. |
456 |
|
|
" |
457 |
|
|
|
458 |
|
|
Boa will (for now) hack around this stupid bug in Netscape |
459 |
|
|
(and Internet Exploder) |
460 |
|
|
by reading up to 32k after the connection is all but closed. |
461 |
|
|
This should eliminate any remaining spurious crlf sent |
462 |
|
|
by the client. |
463 |
|
|
|
464 |
|
|
Building bugs *into* software to be compatable is |
465 |
|
|
just plain wrong |
466 |
|
|
*/ |
467 |
|
|
|
468 |
|
|
if (req->method == M_POST) { |
469 |
|
|
char buf[32768]; |
470 |
|
|
|
471 |
|
|
socket_recv( req, buf, sizeof(buf)); |
472 |
|
|
} |
473 |
|
|
|
474 |
|
|
#ifdef ENABLE_SSL |
475 |
|
|
if ( req->secure) { |
476 |
|
|
gnutls_bye(req->ssl_state, GNUTLS_SHUT_WR); |
477 |
|
|
gnutls_deinit( req->ssl_state); |
478 |
|
|
} |
479 |
|
|
#endif |
480 |
|
|
close(req->fd); |
481 |
|
|
|
482 |
|
|
params->total_connections--; |
483 |
nmav |
1.25 |
decrease_global_total_connections(); |
484 |
nmav |
1.1 |
|
485 |
|
|
enqueue(¶ms->request_free, req); |
486 |
|
|
|
487 |
|
|
return; |
488 |
|
|
} |
489 |
|
|
|
490 |
|
|
/* |
491 |
|
|
* Name: process_requests |
492 |
|
|
* |
493 |
|
|
* Description: Iterates through the ready queue, passing each request |
494 |
|
|
* to the appropriate handler for processing. It monitors the |
495 |
|
|
* return value from handler functions, all of which return -1 |
496 |
|
|
* to indicate a block, 0 on completion and 1 to remain on the |
497 |
|
|
* ready list for more procesing. |
498 |
|
|
*/ |
499 |
|
|
|
500 |
nmav |
1.5 |
void process_requests(server_params* params, socket_type *server_s) |
501 |
nmav |
1.1 |
{ |
502 |
|
|
int retval = 0; |
503 |
|
|
request *current, *trailer; |
504 |
|
|
|
505 |
nmav |
1.5 |
if (server_s->pending_requests) { |
506 |
nmav |
1.1 |
get_request(params, server_s); |
507 |
|
|
#ifdef ORIGINAL_BEHAVIOR |
508 |
nmav |
1.5 |
server_s->pending_requests = 0; |
509 |
nmav |
1.1 |
#endif |
510 |
|
|
} |
511 |
|
|
|
512 |
|
|
current = params->request_ready; |
513 |
|
|
|
514 |
|
|
while (current) { |
515 |
|
|
time(¤t_time); |
516 |
|
|
if (current->buffer_end && /* there is data in the buffer */ |
517 |
|
|
current->status != DEAD && current->status != DONE) { |
518 |
|
|
retval = req_flush(current); |
519 |
|
|
/* |
520 |
|
|
* retval can be -2=error, -1=blocked, or bytes left |
521 |
|
|
*/ |
522 |
|
|
if (retval == -2) { /* error */ |
523 |
|
|
current->status = DEAD; |
524 |
|
|
retval = 0; |
525 |
|
|
} else if (retval >= 0) { |
526 |
|
|
/* notice the >= which is different from below? |
527 |
|
|
Here, we may just be flushing headers. |
528 |
|
|
We don't want to return 0 because we are not DONE |
529 |
|
|
or DEAD */ |
530 |
|
|
|
531 |
|
|
retval = 1; |
532 |
|
|
} |
533 |
|
|
} else { |
534 |
|
|
switch (current->status) { |
535 |
|
|
#ifdef ENABLE_SSL |
536 |
|
|
case FINISH_HANDSHAKE: |
537 |
|
|
retval = finish_handshake( current); |
538 |
|
|
break; |
539 |
|
|
case SEND_ALERT: |
540 |
|
|
retval = send_alert( current); |
541 |
|
|
break; |
542 |
|
|
#endif |
543 |
|
|
case READ_HEADER: |
544 |
|
|
case ONE_CR: |
545 |
|
|
case ONE_LF: |
546 |
|
|
case TWO_CR: |
547 |
|
|
retval = read_header(params, current); |
548 |
|
|
break; |
549 |
|
|
case BODY_READ: |
550 |
|
|
retval = read_body(current); |
551 |
|
|
break; |
552 |
|
|
case BODY_WRITE: |
553 |
|
|
retval = write_body(current); |
554 |
|
|
break; |
555 |
|
|
case WRITE: |
556 |
|
|
retval = process_get(params, current); |
557 |
|
|
break; |
558 |
|
|
case PIPE_READ: |
559 |
|
|
retval = read_from_pipe(current); |
560 |
|
|
break; |
561 |
|
|
case PIPE_WRITE: |
562 |
|
|
retval = write_from_pipe(current); |
563 |
|
|
break; |
564 |
|
|
case DONE: |
565 |
|
|
/* a non-status that will terminate the request */ |
566 |
|
|
retval = req_flush(current); |
567 |
|
|
/* |
568 |
|
|
* retval can be -2=error, -1=blocked, or bytes left |
569 |
|
|
*/ |
570 |
|
|
if (retval == -2) { /* error */ |
571 |
|
|
current->status = DEAD; |
572 |
|
|
retval = 0; |
573 |
|
|
} else if (retval > 0) { |
574 |
|
|
retval = 1; |
575 |
|
|
} |
576 |
|
|
break; |
577 |
|
|
case DEAD: |
578 |
|
|
retval = 0; |
579 |
|
|
current->buffer_end = 0; |
580 |
|
|
SQUASH_KA(current); |
581 |
|
|
break; |
582 |
|
|
default: |
583 |
|
|
retval = 0; |
584 |
|
|
fprintf(stderr, "Unknown status (%d), " |
585 |
|
|
"closing!\n", current->status); |
586 |
|
|
current->status = DEAD; |
587 |
|
|
break; |
588 |
|
|
} |
589 |
|
|
|
590 |
|
|
} |
591 |
|
|
|
592 |
|
|
if (params->sigterm_flag) |
593 |
|
|
SQUASH_KA(current); |
594 |
|
|
|
595 |
|
|
/* we put this here instead of after the switch so that |
596 |
|
|
* if we are on the last request, and get_request is successful, |
597 |
|
|
* current->next is valid! |
598 |
|
|
*/ |
599 |
nmav |
1.5 |
if (server_s->pending_requests) |
600 |
nmav |
1.1 |
get_request(params, server_s); |
601 |
|
|
|
602 |
|
|
switch (retval) { |
603 |
|
|
case -1: /* request blocked */ |
604 |
|
|
trailer = current; |
605 |
|
|
current = current->next; |
606 |
|
|
block_request(params, trailer); |
607 |
|
|
break; |
608 |
|
|
case 0: /* request complete */ |
609 |
|
|
current->time_last = current_time; |
610 |
|
|
trailer = current; |
611 |
|
|
current = current->next; |
612 |
|
|
free_request(params, ¶ms->request_ready, trailer); |
613 |
|
|
break; |
614 |
|
|
case 1: /* more to do */ |
615 |
|
|
current->time_last = current_time; |
616 |
|
|
current = current->next; |
617 |
|
|
break; |
618 |
|
|
default: |
619 |
|
|
log_error_time(); |
620 |
|
|
fprintf(stderr, "Unknown retval in process.c - " |
621 |
|
|
"Status: %d, retval: %d\n", current->status, retval); |
622 |
|
|
current = current->next; |
623 |
|
|
break; |
624 |
|
|
} |
625 |
|
|
} |
626 |
|
|
} |
627 |
|
|
|
628 |
|
|
/* |
629 |
|
|
* Name: process_logline |
630 |
|
|
* |
631 |
|
|
* Description: This is called with the first req->header_line received |
632 |
|
|
* by a request, called "logline" because it is logged to a file. |
633 |
|
|
* It is parsed to determine request type and method, then passed to |
634 |
|
|
* translate_uri for further parsing. Also sets up CGI environment if |
635 |
|
|
* needed. |
636 |
|
|
*/ |
637 |
nmav |
1.2 |
#define SIMPLE_HTTP_VERSION "HTTP/0.9" |
638 |
nmav |
1.1 |
int process_logline(request * req) |
639 |
|
|
{ |
640 |
|
|
char *stop, *stop2; |
641 |
|
|
|
642 |
|
|
req->logline = req->client_stream; |
643 |
|
|
if (!memcmp(req->logline, "GET ", 4)) |
644 |
|
|
req->method = M_GET; |
645 |
|
|
else if (!memcmp(req->logline, "HEAD ", 5)) |
646 |
|
|
/* head is just get w/no body */ |
647 |
|
|
req->method = M_HEAD; |
648 |
|
|
else if (!memcmp(req->logline, "POST ", 5)) |
649 |
|
|
req->method = M_POST; |
650 |
|
|
else { |
651 |
|
|
log_error_time(); |
652 |
|
|
fprintf(stderr, "malformed request: \"%s\"\n", req->logline); |
653 |
|
|
send_r_not_implemented(req); |
654 |
|
|
return 0; |
655 |
|
|
} |
656 |
|
|
|
657 |
|
|
req->http_version = SIMPLE_HTTP_VERSION; |
658 |
|
|
req->simple = 1; |
659 |
|
|
|
660 |
|
|
/* Guaranteed to find ' ' since we matched a method above */ |
661 |
|
|
stop = req->logline + 3; |
662 |
|
|
if (*stop != ' ') |
663 |
|
|
++stop; |
664 |
|
|
|
665 |
|
|
/* scan to start of non-whitespace */ |
666 |
|
|
while (*(++stop) == ' '); |
667 |
|
|
|
668 |
|
|
stop2 = stop; |
669 |
|
|
|
670 |
|
|
/* scan to end of non-whitespace */ |
671 |
|
|
while (*stop2 != '\0' && *stop2 != ' ') |
672 |
|
|
++stop2; |
673 |
|
|
|
674 |
|
|
if (stop2 - stop > MAX_HEADER_LENGTH) { |
675 |
|
|
log_error_time(); |
676 |
|
|
fprintf(stderr, "URI too long %d: \"%s\"\n", MAX_HEADER_LENGTH, |
677 |
|
|
req->logline); |
678 |
|
|
send_r_bad_request(req); |
679 |
|
|
return 0; |
680 |
|
|
} |
681 |
|
|
memcpy(req->request_uri, stop, stop2 - stop); |
682 |
|
|
req->request_uri[stop2 - stop] = '\0'; |
683 |
|
|
|
684 |
|
|
if (*stop2 == ' ') { |
685 |
|
|
/* if found, we should get an HTTP/x.x */ |
686 |
|
|
unsigned int p1, p2; |
687 |
|
|
|
688 |
|
|
/* scan to end of whitespace */ |
689 |
|
|
++stop2; |
690 |
|
|
while (*stop2 == ' ' && *stop2 != '\0') |
691 |
|
|
++stop2; |
692 |
|
|
|
693 |
|
|
/* scan in HTTP/major.minor */ |
694 |
|
|
if (sscanf(stop2, "HTTP/%u.%u", &p1, &p2) == 2) { |
695 |
|
|
/* HTTP/{0.9,1.0,1.1} */ |
696 |
nmav |
1.18 |
if (p1 == 1) { /* We accept all HTTP/1.x versions */ |
697 |
nmav |
1.1 |
req->http_version = stop2; |
698 |
|
|
req->simple = 0; |
699 |
nmav |
1.18 |
} else if (p1 > 1) { /* major number > 1 is invalid for us */ |
700 |
nmav |
1.1 |
goto BAD_VERSION; |
701 |
|
|
} |
702 |
|
|
} else { |
703 |
|
|
goto BAD_VERSION; |
704 |
|
|
} |
705 |
|
|
} |
706 |
|
|
|
707 |
|
|
if (req->method == M_HEAD && req->simple) { |
708 |
|
|
send_r_bad_request(req); |
709 |
|
|
return 0; |
710 |
|
|
} |
711 |
|
|
req->cgi_env_index = COMMON_CGI_COUNT; |
712 |
|
|
|
713 |
|
|
return 1; |
714 |
|
|
|
715 |
|
|
BAD_VERSION: |
716 |
|
|
log_error_time(); |
717 |
|
|
fprintf(stderr, "bogus HTTP version: \"%s\"\n", stop2); |
718 |
|
|
send_r_bad_request(req); |
719 |
|
|
return 0; |
720 |
|
|
} |
721 |
|
|
|
722 |
|
|
/* |
723 |
|
|
* Name: process_header_end |
724 |
|
|
* |
725 |
|
|
* Description: takes a request and performs some final checking before |
726 |
|
|
* init_cgi or init_get |
727 |
|
|
* Returns 0 for error or NPH, or 1 for success |
728 |
|
|
*/ |
729 |
|
|
|
730 |
|
|
int process_header_end(server_params* params, request * req) |
731 |
|
|
{ |
732 |
nmav |
1.23 |
char *p = NULL; |
733 |
nmav |
1.20 |
|
734 |
nmav |
1.1 |
if (!req->logline) { |
735 |
|
|
send_r_error(req); |
736 |
|
|
return 0; |
737 |
|
|
} |
738 |
|
|
|
739 |
|
|
/* Percent-decode request */ |
740 |
nmav |
1.20 |
if (unescape_uri(req->request_uri, &p) == 0) { |
741 |
nmav |
1.1 |
log_error_doc(req); |
742 |
|
|
fputs("Problem unescaping uri\n", stderr); |
743 |
|
|
send_r_bad_request(req); |
744 |
|
|
return 0; |
745 |
nmav |
1.20 |
} |
746 |
|
|
|
747 |
nmav |
1.21 |
if (p) { |
748 |
|
|
req->query_string = strdup( p); |
749 |
|
|
if (req->query_string == NULL) { |
750 |
|
|
send_r_error( req); |
751 |
|
|
return 0; |
752 |
|
|
} |
753 |
nmav |
1.1 |
} |
754 |
|
|
|
755 |
|
|
/* clean pathname */ |
756 |
|
|
clean_pathname(req->request_uri); |
757 |
|
|
|
758 |
|
|
if (req->request_uri[0] != '/') { |
759 |
|
|
send_r_bad_request(req); |
760 |
|
|
return 0; |
761 |
|
|
} |
762 |
|
|
|
763 |
|
|
if (translate_uri(req) == 0) { /* unescape, parse uri */ |
764 |
|
|
SQUASH_KA(req); |
765 |
|
|
return 0; /* failure, close down */ |
766 |
|
|
} |
767 |
|
|
|
768 |
|
|
if (req->method == M_POST) { |
769 |
|
|
req->post_data_fd = create_temporary_file(1, NULL, 0); |
770 |
nmav |
1.12 |
if (req->post_data_fd == -1) |
771 |
nmav |
1.1 |
return(0); |
772 |
|
|
return(1); /* success */ |
773 |
|
|
} |
774 |
|
|
|
775 |
|
|
if (req->is_cgi) { |
776 |
|
|
return init_cgi(req); |
777 |
|
|
} |
778 |
|
|
|
779 |
|
|
req->status = WRITE; |
780 |
|
|
return init_get(params, req); /* get and head */ |
781 |
|
|
} |
782 |
|
|
|
783 |
nmav |
1.4 |
/* Parses HTTP/1.1 range values. |
784 |
|
|
*/ |
785 |
nmav |
1.26 |
static int parse_range( const char* value, off64_t *val1, off64_t *val2) |
786 |
nmav |
1.4 |
{ |
787 |
|
|
int len; |
788 |
nmav |
1.26 |
char *p; |
789 |
nmav |
1.4 |
|
790 |
nmav |
1.26 |
*val1 = *val2 = 0; |
791 |
nmav |
1.4 |
|
792 |
|
|
len = strlen( value); |
793 |
|
|
if (len < 7) return -1; |
794 |
|
|
|
795 |
nmav |
1.26 |
/* we do not accept ranges of the form "bytes=10-20,21-30" |
796 |
nmav |
1.4 |
*/ |
797 |
|
|
if (strchr( value, ',') != NULL) return -1; |
798 |
|
|
|
799 |
|
|
if ( memcmp("bytes=", value, 6) != 0) { |
800 |
|
|
return -1; |
801 |
|
|
} else value += 6; |
802 |
|
|
|
803 |
nmav |
1.26 |
while( *value==' ') value++; |
804 |
|
|
if ((p=strchr( value, '-')) == NULL) return -1; |
805 |
nmav |
1.4 |
|
806 |
nmav |
1.26 |
if (value[0] == '-') { /* Handle case "bytes=-1024" */ |
807 |
|
|
*val1 = 0; |
808 |
|
|
*val2 = boa_atoll( &value[1]); |
809 |
nmav |
1.13 |
return 0; |
810 |
nmav |
1.26 |
} else { |
811 |
|
|
char buf[43]; |
812 |
|
|
int len; |
813 |
|
|
|
814 |
|
|
/* two values of the form "xxx-yyy" */ |
815 |
|
|
|
816 |
|
|
if ((len=strlen( value)) >= sizeof(buf)) |
817 |
|
|
return -1; |
818 |
|
|
|
819 |
|
|
memcpy( buf, value, len); |
820 |
|
|
buf[len] = 0; |
821 |
|
|
|
822 |
|
|
p=strchr( buf, '-'); |
823 |
|
|
if (p==NULL) return -1; |
824 |
|
|
*p = 0; |
825 |
|
|
p++; |
826 |
|
|
|
827 |
|
|
while( *p==' ') p++; |
828 |
|
|
|
829 |
|
|
*val1 = boa_atoll( buf); |
830 |
|
|
|
831 |
|
|
if (*p == '\0') /* form: "xxx-" */ |
832 |
|
|
*val2 = 0; |
833 |
|
|
else |
834 |
|
|
*val2 = boa_atoll( p); |
835 |
|
|
|
836 |
|
|
if ( *val1 == -1) return -1; |
837 |
|
|
|
838 |
|
|
return 0; |
839 |
|
|
} |
840 |
nmav |
1.4 |
|
841 |
|
|
return -1; |
842 |
|
|
} |
843 |
|
|
|
844 |
nmav |
1.8 |
inline |
845 |
|
|
static void init_range_stuff( request* req, char* value) |
846 |
|
|
{ |
847 |
nmav |
1.26 |
off64_t p1, p2; |
848 |
nmav |
1.8 |
if (parse_range( value, &p1, &p2) == 0) { |
849 |
|
|
req->range_start = p1; |
850 |
|
|
req->range_stop = p2; |
851 |
|
|
} else { |
852 |
|
|
req->range_start = 0; |
853 |
|
|
req->range_stop = 0; |
854 |
|
|
log_error_time(); |
855 |
|
|
fprintf(stderr, "bogus range: \"%s\"\n", value); |
856 |
nmav |
1.16 |
/* we just ignore a bogus range */ |
857 |
|
|
/* send_r_bad_request(req); */ |
858 |
nmav |
1.8 |
} |
859 |
|
|
} |
860 |
|
|
|
861 |
|
|
inline |
862 |
|
|
static void init_vhost_stuff( request* req, char* value) |
863 |
|
|
{ |
864 |
|
|
virthost* vhost; |
865 |
|
|
int valuelen; |
866 |
|
|
|
867 |
|
|
valuelen = strlen(value); |
868 |
|
|
|
869 |
|
|
vhost = find_virthost( value, valuelen); |
870 |
|
|
|
871 |
|
|
if ( vhost && ( vhost->ip == NULL || !memcmp( vhost->ip, req->local_ip_addr, vhost->ip_len) )) |
872 |
|
|
{ |
873 |
|
|
req->hostname = value; |
874 |
|
|
memcpy( req->document_root, vhost->document_root, vhost->document_root_len + 1); |
875 |
|
|
if (vhost->user_dir) |
876 |
|
|
memcpy( req->user_dir, vhost->user_dir, vhost->user_dir_len + 1); |
877 |
|
|
|
878 |
|
|
} else { /* No virtual host found. use defaults */ |
879 |
|
|
if ( default_document_root) |
880 |
|
|
memcpy( req->document_root, default_document_root, default_document_root_size + 1); |
881 |
|
|
} |
882 |
|
|
} |
883 |
nmav |
1.4 |
|
884 |
nmav |
1.1 |
/* |
885 |
|
|
* Name: process_option_line |
886 |
|
|
* |
887 |
|
|
* Description: Parses the contents of req->header_line and takes |
888 |
|
|
* appropriate action. |
889 |
|
|
*/ |
890 |
|
|
|
891 |
|
|
int process_option_line(request * req) |
892 |
|
|
{ |
893 |
|
|
char c, *value, *line = req->header_line; |
894 |
|
|
|
895 |
|
|
/* Start by aggressively hacking the in-place copy of the header line */ |
896 |
|
|
|
897 |
|
|
#ifdef FASCIST_LOGGING |
898 |
|
|
log_error_time(); |
899 |
|
|
fprintf(stderr, "%s:%d - Parsing \"%s\"\n", __FILE__, __LINE__, line); |
900 |
|
|
#endif |
901 |
|
|
|
902 |
|
|
value = strchr(line, ':'); |
903 |
|
|
if (value == NULL) |
904 |
|
|
return 0; |
905 |
|
|
*value++ = '\0'; /* overwrite the : */ |
906 |
|
|
to_upper(line); /* header types are case-insensitive */ |
907 |
|
|
while ((c = *value) && (c == ' ' || c == '\t')) |
908 |
|
|
value++; |
909 |
|
|
|
910 |
|
|
|
911 |
nmav |
1.17 |
if (!memcmp(line, "CONTENT_TYPE", 13) && !req->content_type) |
912 |
nmav |
1.1 |
req->content_type = value; |
913 |
|
|
|
914 |
|
|
else if (!memcmp(line, "CONTENT_LENGTH", 15) && !req->content_length) |
915 |
|
|
req->content_length = value; |
916 |
|
|
|
917 |
|
|
else if (!memcmp(line, "CONNECTION", 11) && |
918 |
|
|
ka_max && req->keepalive != KA_STOPPED) { |
919 |
|
|
req->keepalive = (!strncasecmp(value, "Keep-Alive", 10) ? |
920 |
|
|
KA_ACTIVE : KA_STOPPED); |
921 |
|
|
} |
922 |
|
|
/* #ifdef ACCEPT_ON */ |
923 |
|
|
else if (!memcmp(line, "ACCEPT", 7)) |
924 |
|
|
add_accept_header(req, value); |
925 |
|
|
/* #endif */ |
926 |
|
|
|
927 |
|
|
/* Need agent and referer for logs */ |
928 |
|
|
else if (!memcmp(line, "REFERER", 8)) { |
929 |
|
|
req->header_referer = value; |
930 |
|
|
if (!add_cgi_env(req, "REFERER", value, 1)) |
931 |
|
|
return 0; |
932 |
|
|
} else if (!memcmp(line, "USER_AGENT", 11)) { |
933 |
|
|
req->header_user_agent = value; |
934 |
|
|
if (!add_cgi_env(req, "USER_AGENT", value, 1)) |
935 |
nmav |
1.4 |
return 0; |
936 |
|
|
} else if (!memcmp(line, "RANGE", 5)) { |
937 |
nmav |
1.8 |
init_range_stuff( req, value); |
938 |
nmav |
1.6 |
} else if (!memcmp(line, "HOST", 4)) { |
939 |
nmav |
1.8 |
init_vhost_stuff( req, value); |
940 |
nmav |
1.10 |
if (!add_cgi_env(req, "HOST", value, 1)) |
941 |
nmav |
1.16 |
return 0; |
942 |
nmav |
1.19 |
} else if (!memcmp(line, "IF_", 3)) { |
943 |
nmav |
1.16 |
char *p = line+3; |
944 |
|
|
|
945 |
nmav |
1.19 |
if (!memcmp( p, "MODIFIED_SINCE", 15) && !req->if_modified_since) { |
946 |
|
|
req->if_types |= IF_MODIFIED_SINCE; |
947 |
nmav |
1.17 |
req->if_modified_since = value; |
948 |
|
|
|
949 |
nmav |
1.19 |
} else if (!memcmp( p, "MATCH", 5) && !req->if_match_etag) { |
950 |
|
|
req->if_types |= IF_MATCH; |
951 |
|
|
req->if_match_etag = value; |
952 |
|
|
|
953 |
|
|
} else if (!memcmp( p, "NONE_MATCH", 10) && !req->if_none_match_etag) { |
954 |
|
|
req->if_types |= IF_NONE_MATCH; |
955 |
|
|
req->if_none_match_etag = value; |
956 |
|
|
|
957 |
|
|
} else if (!memcmp( p, "RANGE", 5) && !req->if_range_etag) { |
958 |
|
|
req->if_types |= IF_RANGE; |
959 |
|
|
req->if_range_etag = value; |
960 |
nmav |
1.17 |
} |
961 |
nmav |
1.16 |
|
962 |
|
|
if (!add_cgi_env(req, line, value, 1)) |
963 |
nmav |
1.10 |
return 0; |
964 |
nmav |
1.1 |
} else { |
965 |
|
|
if (!add_cgi_env(req, line, value, 1)) |
966 |
|
|
return 0; |
967 |
|
|
} |
968 |
nmav |
1.27 |
|
969 |
nmav |
1.1 |
return 1; |
970 |
|
|
} |
971 |
|
|
|
972 |
|
|
/* |
973 |
|
|
* Name: add_accept_header |
974 |
|
|
* Description: Adds a mime_type to a requests accept char buffer |
975 |
|
|
* silently ignore any that don't fit - |
976 |
|
|
* shouldn't happen because of relative buffer sizes |
977 |
|
|
*/ |
978 |
|
|
|
979 |
|
|
void add_accept_header(request * req, char *mime_type) |
980 |
|
|
{ |
981 |
|
|
#ifdef ACCEPT_ON |
982 |
|
|
int l = strlen(req->accept); |
983 |
|
|
int l2 = strlen(mime_type); |
984 |
|
|
|
985 |
|
|
if ((l + l2 + 2) >= MAX_HEADER_LENGTH) |
986 |
|
|
return; |
987 |
|
|
|
988 |
|
|
if (req->accept[0] == '\0') |
989 |
|
|
strcpy(req->accept, mime_type); |
990 |
|
|
else { |
991 |
|
|
req->accept[l] = ','; |
992 |
|
|
req->accept[l + 1] = ' '; |
993 |
|
|
memcpy(req->accept + l + 2, mime_type, l2 + 1); |
994 |
|
|
/* the +1 is for the '\0' */ |
995 |
|
|
/* |
996 |
|
|
sprintf(req->accept + l, ", %s", mime_type); |
997 |
|
|
*/ |
998 |
|
|
} |
999 |
|
|
#endif |
1000 |
|
|
} |
1001 |
|
|
|
1002 |
|
|
void free_requests(server_params* params) |
1003 |
|
|
{ |
1004 |
|
|
request *ptr, *next; |
1005 |
|
|
|
1006 |
|
|
ptr = params->request_free; |
1007 |
|
|
while (ptr != NULL) { |
1008 |
|
|
next = ptr->next; |
1009 |
|
|
free(ptr); |
1010 |
|
|
ptr = next; |
1011 |
|
|
} |
1012 |
|
|
params->request_free = NULL; |
1013 |
|
|
} |