- need php_stream_open_wrapper_*ex* to pass a stream context
[m6w6/ext-http] / php_http_send_api.h
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-2006, Michael Wallner <mike@php.net> |
10 +--------------------------------------------------------------------+
11 */
12
13 /* $Id$ */
14
15 #ifndef PHP_HTTP_SEND_API_H
16 #define PHP_HTTP_SEND_API_H
17
18 typedef enum {
19 SEND_DATA,
20 SEND_RSRC
21 } http_send_mode;
22
23 #define HTTP_REDIRECT 0L
24 #define HTTP_REDIRECT_PERM 301L
25 #define HTTP_REDIRECT_FOUND 302L
26 #define HTTP_REDIRECT_POST 303L
27 #define HTTP_REDIRECT_PROXY 305L
28 #define HTTP_REDIRECT_TEMP 307L
29
30 extern PHP_MINIT_FUNCTION(http_send);
31
32 #define http_send_status(s) sapi_header_op(SAPI_HEADER_SET_STATUS, (void *) (s) TSRMLS_CC)
33 #define http_send_header(n, v, r) _http_send_header_ex((n), strlen(n), (v), strlen(v), (r) TSRMLS_CC)
34 #define http_send_header_ex(n, nl, v, vl, r, s) _http_send_header_ex((n), (nl), (v), (vl), (r), (s) TSRMLS_CC)
35 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);
36 #define http_send_header_string(h) _http_send_status_header_ex(0, (h), strlen(h), 1 TSRMLS_CC)
37 #define http_send_header_string_ex(h, l, r) _http_send_status_header_ex(0, (h), (l), (r) TSRMLS_CC)
38 #define http_send_status_header(s, h) _http_send_status_header_ex((s), (h), (h)?strlen(h):0, 1 TSRMLS_CC)
39 #define http_send_status_header_ex(s, h, l, r) _http_send_status_header_ex((s), (h), (l), (r) TSRMLS_CC)
40 PHP_HTTP_API STATUS _http_send_status_header_ex(int status, const char *header, size_t header_len, zend_bool replace TSRMLS_DC);
41
42 #define http_send_last_modified(t) _http_send_last_modified_ex((t), NULL TSRMLS_CC)
43 #define http_send_last_modified_ex(t, s) _http_send_last_modified_ex((t), (s) TSRMLS_CC)
44 PHP_HTTP_API STATUS _http_send_last_modified_ex(time_t t, char **sent_header TSRMLS_DC);
45
46 #define http_send_etag(e, l) _http_send_etag_ex((e), (l), NULL TSRMLS_CC)
47 #define http_send_etag_ex(e, l, s) _http_send_etag_ex((e), (l), (s) TSRMLS_CC)
48 PHP_HTTP_API STATUS _http_send_etag_ex(const char *etag, size_t etag_len, char **sent_header TSRMLS_DC);
49
50 #define http_send_cache_control(cc, cl) http_send_header_ex("Cache-Control", lenof("Cache-Control"), (cc), (cl), 1, NULL)
51
52 #define http_send_content_type(c, l) _http_send_content_type((c), (l) TSRMLS_CC)
53 PHP_HTTP_API STATUS _http_send_content_type(const char *content_type, size_t ct_len TSRMLS_DC);
54
55 #define http_send_content_disposition(f, l, i) _http_send_content_disposition((f), (l), (i) TSRMLS_CC)
56 PHP_HTTP_API STATUS _http_send_content_disposition(const char *filename, size_t f_len, zend_bool send_inline TSRMLS_DC);
57
58 #define http_send_data(d, l) http_send((d), (l), SEND_DATA)
59 #define http_send_data_ex(d, l, nc) http_send_ex((d), (l), SEND_DATA, (nc))
60 #define http_send(d, s, m) _http_send_ex((d), (s), (m), 0 TSRMLS_CC)
61 #define http_send_ex(d, s, m, nc) _http_send_ex((d), (s), (m), (nc) TSRMLS_CC)
62 PHP_HTTP_API STATUS _http_send_ex(const void *data, size_t data_size, http_send_mode mode, zend_bool no_cache TSRMLS_DC);
63
64 #define http_send_file(f) http_send_stream_ex(php_stream_open_wrapper_ex(f, "rb", REPORT_ERRORS|ENFORCE_SAFE_MODE, NULL, HTTP_DEFAULT_STREAM_CONTEXT), 1, 0)
65 #define http_send_file_ex(f, nc) http_send_stream_ex(php_stream_open_wrapper_ex(f, "rb", REPORT_ERRORS|ENFORCE_SAFE_MODE, NULL, HTTP_DEFAULT_STREAM_CONTEXT), 1, (nc))
66 #define http_send_stream(s) http_send_stream_ex((s), 0, 0)
67 #define http_send_stream_ex(s, c, nc) _http_send_stream_ex((s), (c), (nc) TSRMLS_CC)
68 PHP_HTTP_API STATUS _http_send_stream_ex(php_stream *s, zend_bool close_stream, zend_bool no_cache TSRMLS_DC);
69
70 #define http_guess_content_type(mf, mm, d, l, m) _http_guess_content_type((mf), (mm), (d), (l), (m) TSRMLS_CC)
71 PHP_HTTP_API char *_http_guess_content_type(const char *magic_file, long magic_mode, void *data_ptr, size_t data_len, http_send_mode mode TSRMLS_DC);
72
73 #endif
74
75 /*
76 * Local variables:
77 * tab-width: 4
78 * c-basic-offset: 4
79 * End:
80 * vim600: noet sw=4 ts=4 fdm=marker
81 * vim<600: noet sw=4 ts=4
82 */
83