fix memory curruption, thanks to Rob
[m6w6/ext-http] / http_send_api.c
1 /*
2 +--------------------------------------------------------------------+
3 | PECL :: http |
4 +--------------------------------------------------------------------+
5 | Redistribution and use in source and binary forms, with or without |
6 | modification, are permitted provided that the conditions mentioned |
7 | in the accompanying LICENSE file are met. |
8 +--------------------------------------------------------------------+
9 | Copyright (c) 2004-2007, Michael Wallner <mike@php.net> |
10 +--------------------------------------------------------------------+
11 */
12
13 /* $Id$ */
14
15 #define HTTP_WANT_SAPI
16 #define HTTP_WANT_ZLIB
17 #define HTTP_WANT_MAGIC
18 #include "php_http.h"
19
20 #include "php_streams.h"
21
22 #include "php_http_api.h"
23 #include "php_http_cache_api.h"
24 #include "php_http_date_api.h"
25 #include "php_http_encoding_api.h"
26 #include "php_http_headers_api.h"
27 #include "php_http_send_api.h"
28
29 /* {{{ http_flush() */
30 #define http_flush(d, l) _http_flush(NULL, (d), (l) TSRMLS_CC)
31 static inline void _http_flush(void *nothing, const char *data, size_t data_len TSRMLS_DC)
32 {
33 PHPWRITE(data, data_len);
34 /* we really only need to flush when throttling is enabled,
35 because we push the data as fast as possible anyway if not */
36 if (HTTP_G->send.throttle_delay >= HTTP_DIFFSEC) {
37 if (OG(ob_nesting_level)) {
38 php_end_ob_buffer(1, 1 TSRMLS_CC);
39 }
40 if (!OG(implicit_flush)) {
41 sapi_flush(TSRMLS_C);
42 }
43 http_sleep(HTTP_G->send.throttle_delay);
44 }
45 }
46 /* }}} */
47
48 /* {{{ http_send_response_start */
49 #define http_send_response_start(b, cl) _http_send_response_start((b), (cl) TSRMLS_CC)
50 static inline void _http_send_response_start(void **buffer, size_t content_length TSRMLS_DC)
51 {
52 int encoding;
53
54 if ((encoding = http_encoding_response_start(content_length, 0))) {
55 #ifdef HTTP_HAVE_ZLIB
56 *((http_encoding_stream **) buffer) = http_encoding_deflate_stream_init(NULL,
57 (encoding == HTTP_ENCODING_GZIP) ?
58 HTTP_DEFLATE_TYPE_GZIP : HTTP_DEFLATE_TYPE_ZLIB);
59 #endif
60 }
61 /* flush headers */
62 sapi_flush(TSRMLS_C);
63 }
64 /* }}} */
65
66 /* {{{ http_send_response_data_plain */
67 #define http_send_response_data_plain(b, d, dl) _http_send_response_data_plain((b), (d), (dl) TSRMLS_CC)
68 static inline void _http_send_response_data_plain(void **buffer, const char *data, size_t data_len TSRMLS_DC)
69 {
70 if (HTTP_G->send.deflate.response && HTTP_G->send.deflate.encoding) {
71 #ifdef HTTP_HAVE_ZLIB
72 char *encoded;
73 size_t encoded_len;
74 http_encoding_stream *s = *((http_encoding_stream **) buffer);
75
76 http_encoding_deflate_stream_update(s, data, data_len, &encoded, &encoded_len);
77 if (HTTP_G->send.buffer_size) {
78 phpstr_chunked_output((phpstr **) &s->storage, encoded, encoded_len, HTTP_G->send.buffer_size, _http_flush, NULL TSRMLS_CC);
79 } else {
80 http_flush(encoded, encoded_len);
81 }
82 efree(encoded);
83 #else
84 http_error(HE_ERROR, HTTP_E_RESPONSE, "Attempt to send GZIP response despite being able to do so; please report this bug");
85 #endif
86 } else if (HTTP_G->send.buffer_size) {
87 phpstr_chunked_output((phpstr **) buffer, data, data_len, HTTP_G->send.buffer_size, _http_flush, NULL TSRMLS_CC);
88 } else {
89 http_flush(data, data_len);
90 }
91 }
92 /* }}} */
93
94 /* {{{ http_send_response_data_fetch */
95 #define http_send_response_data_fetch(b, d, l, m, s, e) _http_send_response_data_fetch((b), (d), (l), (m), (s), (e) TSRMLS_CC)
96 static inline void _http_send_response_data_fetch(void **buffer, const void *data, size_t data_len, http_send_mode mode, size_t begin, size_t end TSRMLS_DC)
97 {
98 long bsz, got, len = end - begin;
99
100 if (!(bsz = HTTP_G->send.buffer_size)) {
101 bsz = HTTP_SENDBUF_SIZE;
102 }
103
104 switch (mode) {
105 case SEND_RSRC: {
106 php_stream *s = (php_stream *) data;
107 if (SUCCESS == php_stream_seek(s, begin, SEEK_SET)) {
108 char *buf = emalloc(bsz);
109
110 while (len > 0) {
111 got = php_stream_read(s, buf, MIN(len, bsz));
112 http_send_response_data_plain(buffer, buf, got);
113 len -= got;
114 }
115
116 efree(buf);
117 }
118 break;
119 }
120 case SEND_DATA: {
121 const char *buf = ((const char *) data) + begin;
122 while (len > 0) {
123 got = MIN(len, bsz);
124 http_send_response_data_plain(buffer, buf, got);
125 len -= got;
126 buf += got;
127 }
128 break;
129 }
130 EMPTY_SWITCH_DEFAULT_CASE();
131 }
132 }
133 /* }}} */
134
135 /* {{{ http_send_response_finish */
136 #define http_send_response_finish(b) _http_send_response_finish((b) TSRMLS_CC)
137 static inline void _http_send_response_finish(void **buffer TSRMLS_DC)
138 {
139 if (HTTP_G->send.deflate.response && HTTP_G->send.deflate.encoding) {
140 #ifdef HTTP_HAVE_ZLIB
141 char *encoded = NULL;
142 size_t encoded_len = 0;
143 http_encoding_stream *s = *((http_encoding_stream **) buffer);
144
145 http_encoding_deflate_stream_finish(s, &encoded, &encoded_len);
146 if (HTTP_G->send.buffer_size) {
147 phpstr_chunked_output((phpstr **) &s->storage, encoded, encoded_len, 0, _http_flush, NULL TSRMLS_CC);
148 } else {
149 http_flush(encoded, encoded_len);
150 }
151 http_encoding_deflate_stream_free(&s);
152 STR_FREE(encoded);
153 #else
154 http_error(HE_ERROR, HTTP_E_RESPONSE, "Attempt to send GZIP response despite being able to do so; please report this bug");
155 #endif
156 } else if (HTTP_G->send.buffer_size) {
157 phpstr_chunked_output((phpstr **) buffer, NULL, 0, 0, _http_flush, NULL TSRMLS_CC);
158 }
159 }
160 /* }}} */
161
162 /* {{{ */
163 PHP_MINIT_FUNCTION(http_send)
164 {
165 HTTP_LONG_CONSTANT("HTTP_REDIRECT", HTTP_REDIRECT);
166 HTTP_LONG_CONSTANT("HTTP_REDIRECT_PERM", HTTP_REDIRECT_PERM);
167 HTTP_LONG_CONSTANT("HTTP_REDIRECT_FOUND", HTTP_REDIRECT_FOUND);
168 HTTP_LONG_CONSTANT("HTTP_REDIRECT_POST", HTTP_REDIRECT_POST);
169 HTTP_LONG_CONSTANT("HTTP_REDIRECT_PROXY", HTTP_REDIRECT_PROXY);
170 HTTP_LONG_CONSTANT("HTTP_REDIRECT_TEMP", HTTP_REDIRECT_TEMP);
171
172 return SUCCESS;
173 }
174 /* }}} */
175
176 /* {{{ http_find_header */
177 typedef struct {
178 const char *h;
179 size_t l;
180 } http_response_header_t;
181
182 static int http_find_header(void *data, void *arg)
183 {
184 http_response_header_t *h = arg;
185 sapi_header_struct *s = data;
186
187 return (!strncasecmp(s->header, h->h, h->l)) && s->header[h->l] == ':';
188 }
189 /* }}} */
190
191 /* {{{ void http_hide_header(char *) */
192 PHP_HTTP_API void _http_hide_header_ex(const char *name, size_t name_len TSRMLS_DC)
193 {
194 http_response_header_t h = {name, name_len};
195 zend_llist_del_element(&SG(sapi_headers).headers, (void *) &h, http_find_header);
196 }
197 /* }}} */
198
199 /* {{{ void http_send_header_zval(char*, zval **, zend_bool) */
200 PHP_HTTP_API void _http_send_header_zval_ex(const char *name, size_t name_len, zval **val, zend_bool replace TSRMLS_DC)
201 {
202 if (!val || !*val || Z_TYPE_PP(val) == IS_NULL || (Z_TYPE_PP(val) == IS_STRING && !Z_STRLEN_PP(val))) {
203 http_hide_header_ex(name, name_len);
204 } else if (Z_TYPE_PP(val) == IS_ARRAY || Z_TYPE_PP(val) == IS_OBJECT) {
205 zend_bool first = replace;
206 zval **data;
207 HashPosition pos;
208
209 FOREACH_HASH_VAL(pos, HASH_OF(*val), data) {
210 zval *orig = *data;
211
212 convert_to_string_ex(data);
213 http_send_header_ex(name, name_len, Z_STRVAL_PP(data), Z_STRLEN_PP(data), first, NULL);
214 if (orig != *data) {
215 zval_ptr_dtor(data);
216 }
217 first = 0;
218 }
219 } else {
220 zval *orig = *val;
221
222 convert_to_string_ex(val);
223 http_send_header_ex(name, name_len, Z_STRVAL_PP(val), Z_STRLEN_PP(val), replace, NULL);
224 if (orig != *val) {
225 zval_ptr_dtor(val);
226 }
227 }
228 }
229 /* }}} */
230
231 /* {{{ STATUS http_send_header(char *, char *, zend_bool) */
232 PHP_HTTP_API STATUS _http_send_header_ex(const char *name, size_t name_len, const char *value, size_t value_len, zend_bool replace, char **sent_header TSRMLS_DC)
233 {
234 STATUS ret;
235
236 if (value && value_len) {
237 size_t header_len = sizeof(": ") + name_len + value_len + 1;
238 char *header = emalloc(header_len + 1);
239
240 header[header_len] = '\0';
241 header_len = snprintf(header, header_len, "%s: %s", name, value);
242 ret = http_send_header_string_ex(header, header_len, replace);
243 if (sent_header) {
244 *sent_header = header;
245 } else {
246 efree(header);
247 }
248 } else {
249 http_hide_header_ex(name, name_len);
250 ret = SUCCESS;
251 }
252 return ret;
253 }
254 /* }}} */
255
256 /* {{{ STATUS http_send_status_header(int, char *) */
257 PHP_HTTP_API STATUS _http_send_status_header_ex(int status, const char *header, size_t header_len, zend_bool replace TSRMLS_DC)
258 {
259 STATUS ret;
260 sapi_header_line h = {(char *) header, header_len, status};
261 if (SUCCESS != (ret = sapi_header_op(replace ? SAPI_HEADER_REPLACE : SAPI_HEADER_ADD, &h TSRMLS_CC))) {
262 http_error_ex(HE_WARNING, HTTP_E_HEADER, "Could not send header: %s (%d)", header, status);
263 }
264 return ret;
265 }
266 /* }}} */
267
268 /* {{{ STATUS http_send_last_modified(int) */
269 PHP_HTTP_API STATUS _http_send_last_modified_ex(time_t t, char **sent_header TSRMLS_DC)
270 {
271 STATUS ret;
272 char *date = http_date(t);
273
274 if (!date) {
275 return FAILURE;
276 }
277
278 ret = http_send_header_ex("Last-Modified", lenof("Last-Modified"), date, strlen(date), 1, sent_header);
279 efree(date);
280
281 /* remember */
282 HTTP_G->send.last_modified = t;
283
284 return ret;
285 }
286 /* }}} */
287
288 /* {{{ STATUS http_send_etag(char *, size_t) */
289 PHP_HTTP_API STATUS _http_send_etag_ex(const char *etag, size_t etag_len, char **sent_header TSRMLS_DC)
290 {
291 STATUS status;
292 char *etag_header;
293 size_t etag_header_len;
294
295 if (!etag_len){
296 http_error_ex(HE_WARNING, HTTP_E_HEADER, "Attempt to send empty ETag (previous: %s)\n", HTTP_G->send.unquoted_etag);
297 return FAILURE;
298 }
299
300 etag_header_len = spprintf(&etag_header, 0, "ETag: \"%s\"", etag);
301 status = http_send_header_string_ex(etag_header, etag_header_len, 1);
302
303 /* remember */
304 STR_SET(HTTP_G->send.unquoted_etag, estrndup(etag, etag_len));
305
306 if (sent_header) {
307 *sent_header = etag_header;
308 } else {
309 efree(etag_header);
310 }
311
312 return status;
313 }
314 /* }}} */
315
316 /* {{{ STATUS http_send_content_type(char *, size_t) */
317 PHP_HTTP_API STATUS _http_send_content_type(const char *content_type, size_t ct_len TSRMLS_DC)
318 {
319 HTTP_CHECK_CONTENT_TYPE(content_type, return FAILURE);
320
321 /* remember for multiple ranges */
322 STR_FREE(HTTP_G->send.content_type);
323 HTTP_G->send.content_type = estrndup(content_type, ct_len);
324
325 return http_send_header_ex("Content-Type", lenof("Content-Type"), content_type, ct_len, 1, NULL);
326 }
327 /* }}} */
328
329 /* {{{ STATUS http_send_content_disposition(char *, size_t, zend_bool) */
330 PHP_HTTP_API STATUS _http_send_content_disposition(const char *filename, size_t f_len, zend_bool send_inline TSRMLS_DC)
331 {
332 STATUS status;
333 char *cd_header;
334
335 if (send_inline) {
336 cd_header = ecalloc(1, sizeof("Content-Disposition: inline; filename=\"\"") + f_len);
337 sprintf(cd_header, "Content-Disposition: inline; filename=\"%s\"", filename);
338 } else {
339 cd_header = ecalloc(1, sizeof("Content-Disposition: attachment; filename=\"\"") + f_len);
340 sprintf(cd_header, "Content-Disposition: attachment; filename=\"%s\"", filename);
341 }
342
343 status = http_send_header_string(cd_header);
344 efree(cd_header);
345 return status;
346 }
347 /* }}} */
348
349 /* {{{ STATUS http_send(void *, size_t, http_send_mode) */
350 PHP_HTTP_API STATUS _http_send_ex(const void *data_ptr, size_t data_size, http_send_mode data_mode, zend_bool no_cache TSRMLS_DC)
351 {
352 void *s = NULL;
353 HashTable ranges;
354 http_range_status range_status;
355
356 if (!data_ptr) {
357 return FAILURE;
358 }
359 if (!data_size) {
360 return SUCCESS;
361 }
362
363 /* enable partial dl and resume */
364 http_send_header_string("Accept-Ranges: bytes");
365
366 zend_hash_init(&ranges, 0, NULL, ZVAL_PTR_DTOR, 0);
367 range_status = http_get_request_ranges(&ranges, data_size);
368
369 switch (range_status) {
370 case RANGE_ERR:
371 {
372 zend_hash_destroy(&ranges);
373 http_send_status(416);
374 return FAILURE;
375 }
376 case RANGE_OK:
377 {
378 /* Range Request - only send ranges if entity hasn't changed */
379 if ( http_got_server_var("HTTP_IF_RANGE") &&
380 !http_match_etag("HTTP_IF_RANGE", HTTP_G->send.unquoted_etag) &&
381 !http_match_last_modified("HTTP_IF_RANGE", HTTP_G->send.last_modified)) {
382 /* fallthrough to send full entity with 200 Ok */
383 no_cache = 1;
384 } else if ( !http_match_etag_ex("HTTP_IF_MATCH", HTTP_G->send.unquoted_etag, 0) ||
385 !http_match_last_modified_ex("HTTP_IF_UNMODIFIED_SINCE", HTTP_G->send.last_modified, 0) ||
386 !http_match_last_modified_ex("HTTP_UNLESS_MODIFIED_SINCE", HTTP_G->send.last_modified, 0)) {
387 /* 412 Precondition failed */
388 zend_hash_destroy(&ranges);
389 http_send_status(412);
390 return FAILURE;
391 } else if (zend_hash_num_elements(&ranges) == 1) {
392 /* single range */
393 zval **range, **begin, **end;
394
395 if ( SUCCESS != zend_hash_index_find(&ranges, 0, (void *) &range) ||
396 SUCCESS != zend_hash_index_find(Z_ARRVAL_PP(range), 0, (void *) &begin) ||
397 SUCCESS != zend_hash_index_find(Z_ARRVAL_PP(range), 1, (void *) &end)) {
398 /* this should never happen */
399 zend_hash_destroy(&ranges);
400 http_send_status(500);
401 return FAILURE;
402 } else {
403 char range_header_str[256];
404 size_t range_header_len;
405
406 range_header_len = snprintf(range_header_str, sizeof(range_header_str), "Content-Range: bytes %ld-%ld/%zu", Z_LVAL_PP(begin), Z_LVAL_PP(end), data_size);
407 http_send_status_header_ex(206, range_header_str, range_header_len, 1);
408 http_send_response_start(&s, Z_LVAL_PP(end)-Z_LVAL_PP(begin)+1);
409 http_send_response_data_fetch(&s, data_ptr, data_size, data_mode, Z_LVAL_PP(begin), Z_LVAL_PP(end) + 1);
410 http_send_response_finish(&s);
411 zend_hash_destroy(&ranges);
412 return SUCCESS;
413 }
414 } else {
415 /* multi range */
416 HashPosition pos;
417 zval **range, **begin, **end;
418 const char *content_type = HTTP_G->send.content_type;
419 char boundary_str[32], range_header_str[256];
420 size_t boundary_len, range_header_len;
421
422 boundary_len = http_boundary(boundary_str, sizeof(boundary_str));
423 range_header_len = snprintf(range_header_str, sizeof(range_header_str), "Content-Type: multipart/byteranges; boundary=%s", boundary_str);
424
425 http_send_status_header_ex(206, range_header_str, range_header_len, 1);
426 http_send_response_start(&s, 0);
427
428 if (!content_type) {
429 content_type = "application/x-octetstream";
430 }
431
432 FOREACH_HASH_VAL(pos, &ranges, range) {
433 if ( SUCCESS == zend_hash_index_find(Z_ARRVAL_PP(range), 0, (void *) &begin) &&
434 SUCCESS == zend_hash_index_find(Z_ARRVAL_PP(range), 1, (void *) &end)) {
435 char preface_str[512];
436 size_t preface_len;
437
438 #define HTTP_RANGE_PREFACE \
439 HTTP_CRLF "--%s" \
440 HTTP_CRLF "Content-Type: %s" \
441 HTTP_CRLF "Content-Range: bytes %ld-%ld/%zu" \
442 HTTP_CRLF HTTP_CRLF
443
444 preface_len = snprintf(preface_str, sizeof(preface_str), HTTP_RANGE_PREFACE, boundary_str, content_type, Z_LVAL_PP(begin), Z_LVAL_PP(end), data_size);
445 http_send_response_data_plain(&s, preface_str, preface_len);
446 http_send_response_data_fetch(&s, data_ptr, data_size, data_mode, Z_LVAL_PP(begin), Z_LVAL_PP(end) + 1);
447 }
448 }
449
450 http_send_response_data_plain(&s, HTTP_CRLF "--", lenof(HTTP_CRLF "--"));
451 http_send_response_data_plain(&s, boundary_str, boundary_len);
452 http_send_response_data_plain(&s, "--", lenof("--"));
453
454 http_send_response_finish(&s);
455 zend_hash_destroy(&ranges);
456 return SUCCESS;
457 }
458 }
459 case RANGE_NO:
460 {
461 zend_hash_destroy(&ranges);
462
463 /* send 304 Not Modified if etag matches - DON'T return on ETag generation failure */
464 if (!no_cache && (http_interrupt_ob_etaghandler() || (HTTP_G->send.unquoted_etag != NULL))) {
465 char *etag = NULL;
466
467 if (HTTP_G->send.unquoted_etag) {
468 etag = estrdup(HTTP_G->send.unquoted_etag);
469 }
470
471 if (etag || (etag = http_etag(data_ptr, data_size, data_mode))) {
472 char *sent_header = NULL;
473
474 http_send_etag_ex(etag, strlen(etag), &sent_header);
475 if (http_match_etag("HTTP_IF_NONE_MATCH", etag)) {
476 return http_exit_ex(304, sent_header, NULL, 0);
477 } else {
478 STR_FREE(sent_header);
479 /* no caching for Last-Modified if ETags really don't match */
480 no_cache = http_got_server_var("HTTP_IF_NONE_MATCH");
481 }
482 efree(etag);
483 }
484 }
485
486 /* send 304 Not Modified if last modified matches */
487 if (!no_cache && http_match_last_modified("HTTP_IF_MODIFIED_SINCE", HTTP_G->send.last_modified)) {
488 char *sent_header = NULL;
489 http_send_last_modified_ex(HTTP_G->send.last_modified, &sent_header);
490 return http_exit_ex(304, sent_header, NULL, 0);
491 }
492
493 /* send full response */
494 http_send_response_start(&s, data_size);
495 http_send_response_data_fetch(&s, data_ptr, data_size, data_mode, 0, data_size);
496 http_send_response_finish(&s);
497 return SUCCESS;
498 }
499 }
500 return FAILURE;
501 }
502 /* }}} */
503
504 /* {{{ STATUS http_send_stream(php_stream *) */
505 PHP_HTTP_API STATUS _http_send_stream_ex(php_stream *file, zend_bool close_stream, zend_bool no_cache TSRMLS_DC)
506 {
507 STATUS status;
508 php_stream_statbuf ssb;
509 int orig_flags;
510
511 if ((!file) || php_stream_stat(file, &ssb)) {
512 char *defct = sapi_get_default_content_type(TSRMLS_C);
513
514 http_hide_header("Content-Disposition");
515 http_send_content_type(defct, strlen(defct));
516 http_error(HE_WARNING, HTTP_E_RESPONSE, "File not found; stat failed");
517 STR_FREE(defct);
518
519 if (HTTP_G->send.not_found_404) {
520 http_exit_ex(404, NULL, estrdup("File not found\n"), 0);
521 }
522 return FAILURE;
523 }
524
525 orig_flags = file->flags;
526 file->flags |= PHP_STREAM_FLAG_NO_BUFFER;
527 status = http_send_ex(file, ssb.sb.st_size, SEND_RSRC, no_cache);
528 file->flags = orig_flags;
529
530 if (close_stream) {
531 php_stream_close(file);
532 }
533
534 return status;
535 }
536 /* }}} */
537
538 /* {{{ char *http_guess_content_type(char *magic_file, long magic_mode, void *data, size_t size, http_send_mode mode) */
539 PHP_HTTP_API char *_http_guess_content_type(const char *magicfile, long magicmode, void *data_ptr, size_t data_len, http_send_mode data_mode TSRMLS_DC)
540 {
541 char *ct = NULL;
542
543 #ifdef HTTP_HAVE_MAGIC
544 struct magic_set *magic = NULL;
545
546 HTTP_CHECK_OPEN_BASEDIR(magicfile, return NULL);
547
548 if (!data_ptr) {
549 http_error(HE_WARNING, HTTP_E_INVALID_PARAM, "Supplied payload is empty");
550 } else if (!(magic = magic_open(magicmode &~ MAGIC_MIME))) {
551 http_error_ex(HE_WARNING, HTTP_E_INVALID_PARAM, "Invalid magic mode: %ld", magicmode);
552 } else if (-1 == magic_load(magic, magicfile)) {
553 http_error_ex(HE_WARNING, HTTP_E_RUNTIME, "Failed to load magic database '%s' (%s)", magicfile, magic_error(magic));
554 } else {
555 const char *ctype = NULL;
556
557 magic_setflags(magic, magicmode);
558
559 switch (data_mode) {
560 case SEND_RSRC:
561 {
562 char *buffer;
563 size_t b_len;
564
565 b_len = php_stream_copy_to_mem(data_ptr, &buffer, 65536, 0);
566 ctype = magic_buffer(magic, buffer, b_len);
567 efree(buffer);
568 break;
569 }
570
571 case SEND_DATA:
572 ctype = magic_buffer(magic, data_ptr, data_len);
573 break;
574
575 default:
576 HTTP_CHECK_OPEN_BASEDIR(data_ptr, magic_close(magic); return NULL);
577 ctype = magic_file(magic, data_ptr);
578 break;
579 }
580
581 if (ctype) {
582 ct = estrdup(ctype);
583 } else {
584 http_error_ex(HE_WARNING, HTTP_E_RUNTIME, "Failed to guess Content-Type: %s", magic_error(magic));
585 }
586 }
587 if (magic) {
588 magic_close(magic);
589 }
590 #else
591 http_error(HE_WARNING, HTTP_E_RUNTIME, "Cannot guess Content-Type; libmagic not available");
592 #endif
593
594 return ct;
595 }
596 /* }}} */
597
598 /*
599 * Local variables:
600 * tab-width: 4
601 * c-basic-offset: 4
602 * End:
603 * vim600: sw=4 ts=4 fdm=marker
604 * vim<600: sw=4 ts=4
605 */
606