2 +----------------------------------------------------------------------+
4 +----------------------------------------------------------------------+
5 | This source file is subject to version 3.0 of the PHP license, that |
6 | is bundled with this package in the file LICENSE, and is available |
7 | through the world-wide-web at http://www.php.net/license/3_0.txt. |
8 | If you did not receive a copy of the PHP license and are unable to |
9 | obtain it through the world-wide-web, please send a note to |
10 | license@php.net so we can mail you a copy immediately. |
11 +----------------------------------------------------------------------+
12 | Copyright (c) 2004-2005 Michael Wallner <mike@php.net> |
13 +----------------------------------------------------------------------+
19 #define ZEND_INCLUDE_FULL_WINDOWS_HEADERS
28 #include "php_version.h"
29 #include "php_streams.h"
31 #include "ext/standard/md5.h"
32 #include "ext/standard/url.h"
33 #include "ext/standard/base64.h"
34 #include "ext/standard/php_string.h"
35 #include "ext/standard/php_smart_str.h"
36 #include "ext/standard/php_lcg.h"
41 # include "ext/standard/php_http.h"
43 #include "http_build_query.c"
47 #include "php_http_api.h"
52 # include <winsock2.h>
53 # include <sys/types.h>
56 # include <curl/curl.h>
57 # include <curl/easy.h>
62 ZEND_DECLARE_MODULE_GLOBALS(http
)
64 /* {{{ day/month names */
65 static const char *days
[] = {
66 "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
68 static const char *wkdays
[] = {
69 "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"
71 static const char *weekdays
[] = {
72 "Monday", "Tuesday", "Wednesday",
73 "Thursday", "Friday", "Saturday", "Sunday"
75 static const char *months
[] = {
76 "Jan", "Feb", "Mar", "Apr", "May", "Jun",
77 "Jul", "Aug", "Sep", "Okt", "Nov", "Dec"
84 static const struct time_zone
{
88 {"GMT", 0}, /* Greenwich Mean */
89 {"UTC", 0}, /* Universal (Coordinated) */
90 {"WET", 0}, /* Western European */
91 {"BST", 0}, /* British Summer */
92 {"WAT", 60}, /* West Africa */
93 {"AST", 240}, /* Atlantic Standard */
94 {"ADT", 240}, /* Atlantic Daylight */
95 {"EST", 300}, /* Eastern Standard */
96 {"EDT", 300}, /* Eastern Daylight */
97 {"CST", 360}, /* Central Standard */
98 {"CDT", 360}, /* Central Daylight */
99 {"MST", 420}, /* Mountain Standard */
100 {"MDT", 420}, /* Mountain Daylight */
101 {"PST", 480}, /* Pacific Standard */
102 {"PDT", 480}, /* Pacific Daylight */
103 {"YST", 540}, /* Yukon Standard */
104 {"YDT", 540}, /* Yukon Daylight */
105 {"HST", 600}, /* Hawaii Standard */
106 {"HDT", 600}, /* Hawaii Daylight */
107 {"CAT", 600}, /* Central Alaska */
108 {"AHST", 600}, /* Alaska-Hawaii Standard */
109 {"NT", 660}, /* Nome */
110 {"IDLW", 720}, /* International Date Line West */
111 {"CET", -60}, /* Central European */
112 {"MET", -60}, /* Middle European */
113 {"MEWT", -60}, /* Middle European Winter */
114 {"MEST", -120}, /* Middle European Summer */
115 {"CEST", -120}, /* Central European Summer */
116 {"MESZ", -60}, /* Middle European Summer */
117 {"FWT", -60}, /* French Winter */
118 {"FST", -60}, /* French Summer */
119 {"EET", -120}, /* Eastern Europe, USSR Zone 1 */
120 {"WAST", -420}, /* West Australian Standard */
121 {"WADT", -420}, /* West Australian Daylight */
122 {"CCT", -480}, /* China Coast, USSR Zone 7 */
123 {"JST", -540}, /* Japan Standard, USSR Zone 8 */
124 {"EAST", -600}, /* Eastern Australian Standard */
125 {"EADT", -600}, /* Eastern Australian Daylight */
126 {"GST", -600}, /* Guam Standard, USSR Zone 9 */
127 {"NZT", -720}, /* New Zealand */
128 {"NZST", -720}, /* New Zealand Standard */
129 {"NZDT", -720}, /* New Zealand Daylight */
130 {"IDLE", -720}, /* International Date Line East */
136 static int http_sort_q(const void *a
, const void *b TSRMLS_DC
);
137 #define http_send_chunk(d, b, e, m) _http_send_chunk((d), (b), (e), (m) TSRMLS_CC)
138 static STATUS
_http_send_chunk(const void *data
, const size_t begin
, const size_t end
, const http_send_mode mode TSRMLS_DC
);
140 static int check_day(char *day
, size_t len
);
141 static int check_month(char *month
);
142 static int check_tzone(char *tzone
);
144 static char *pretty_key(char *key
, int key_len
, int uctitle
, int xhyphen
);
146 static int http_ob_stack_get(php_ob_buffer
*, php_ob_buffer
**);
149 #ifdef HTTP_HAVE_CURL
150 #define http_curl_initbuf(m) _http_curl_initbuf((m) TSRMLS_CC)
151 static inline void _http_curl_initbuf(http_curlbuf_member member TSRMLS_DC
);
152 #define http_curl_freebuf(m) _http_curl_freebuf((m) TSRMLS_CC)
153 static inline void _http_curl_freebuf(http_curlbuf_member member TSRMLS_DC
);
154 #define http_curl_sizebuf(m, l) _http_curl_sizebuf((m), (l) TSRMLS_CC)
155 static inline void _http_curl_sizebuf(http_curlbuf_member member
, size_t len TSRMLS_DC
);
156 #define http_curl_movebuf(m, d, l) _http_curl_movebuf((m), (d), (l) TSRMLS_CC)
157 static inline void _http_curl_movebuf(http_curlbuf_member member
, char **data
, size_t *data_len TSRMLS_DC
);
158 #define http_curl_copybuf(m, d, l) _http_curl_copybuf((m), (d), (l) TSRMLS_CC)
159 static inline void _http_curl_copybuf(http_curlbuf_member member
, char **data
, size_t *data_len TSRMLS_DC
);
160 #define http_curl_setopts(c, u, o) _http_curl_setopts((c), (u), (o) TSRMLS_CC)
161 static inline void _http_curl_setopts(CURL
*ch
, const char *url
, HashTable
*options TSRMLS_DC
);
163 #define http_curl_getopt(o, k) _http_curl_getopt((o), (k) TSRMLS_CC, 0)
164 #define http_curl_getopt1(o, k, t1) _http_curl_getopt((o), (k) TSRMLS_CC, 1, (t1))
165 #define http_curl_getopt2(o, k, t1, t2) _http_curl_getopt((o), (k) TSRMLS_CC, 2, (t1), (t2))
166 static inline zval
*_http_curl_getopt(HashTable
*options
, char *key TSRMLS_DC
, int checks
, ...);
168 static size_t http_curl_body_callback(char *, size_t, size_t, void *);
169 static size_t http_curl_hdrs_callback(char *, size_t, size_t, void *);
171 #define http_curl_getinfo(c, h) _http_curl_getinfo((c), (h) TSRMLS_CC)
172 static inline void _http_curl_getinfo(CURL
*ch
, HashTable
*info TSRMLS_DC
);
173 #define http_curl_getinfo_ex(c, i, a) _http_curl_getinfo_ex((c), (i), (a) TSRMLS_CC)
174 static inline void _http_curl_getinfo_ex(CURL
*ch
, CURLINFO i
, zval
*array TSRMLS_DC
);
175 #define http_curl_getinfoname(i) _http_curl_getinfoname((i) TSRMLS_CC)
176 static inline char *_http_curl_getinfoname(CURLINFO i TSRMLS_DC
);
181 /* {{{ inline char *http_etag(void *, size_t, http_send_mode) */
182 inline char *_http_etag(const void *data_ptr
, const size_t data_len
,
183 const http_send_mode data_mode TSRMLS_DC
)
185 char ssb_buf
[128] = {0};
186 unsigned char digest
[16];
188 char *new_etag
= ecalloc(33, 1);
195 PHP_MD5Update(&ctx
, data_ptr
, data_len
);
199 if (!HTTP_G(ssb
).sb
.st_ino
) {
200 if (php_stream_stat((php_stream
*) data_ptr
, &HTTP_G(ssb
))) {
204 snprintf(ssb_buf
, 127, "%ld=%ld=%ld",
205 HTTP_G(ssb
).sb
.st_mtime
,
206 HTTP_G(ssb
).sb
.st_ino
,
207 HTTP_G(ssb
).sb
.st_size
209 PHP_MD5Update(&ctx
, ssb_buf
, strlen(ssb_buf
));
218 PHP_MD5Final(digest
, &ctx
);
219 make_digest(new_etag
, digest
);
225 /* {{{ inline http_lmod(void *, http_send_mode) */
226 inline time_t _http_lmod(const void *data_ptr
, const http_send_mode data_mode TSRMLS_DC
)
237 if (!HTTP_G(ssb
).sb
.st_mtime
) {
238 if (php_stream_stat((php_stream
*) data_ptr
, &HTTP_G(ssb
))) {
242 return HTTP_G(ssb
).sb
.st_mtime
;
248 php_stat(Z_STRVAL_P((zval
*) data_ptr
), Z_STRLEN_P((zval
*) data_ptr
), FS_MTIME
, &mtime TSRMLS_CC
);
249 return Z_LVAL(mtime
);
255 /* {{{inline int http_is_range_request(void) */
256 inline int _http_is_range_request(TSRMLS_D
)
258 return zend_hash_exists(Z_ARRVAL_P(PG(http_globals
)[TRACK_VARS_SERVER
]),
259 "HTTP_RANGE", strlen("HTTP_RANGE") + 1);
263 /* {{{ static int http_sort_q(const void *, const void *) */
264 static int http_sort_q(const void *a
, const void *b TSRMLS_DC
)
267 zval result
, *first
, *second
;
269 f
= *((Bucket
**) a
);
270 s
= *((Bucket
**) b
);
272 first
= *((zval
**) f
->pData
);
273 second
= *((zval
**) s
->pData
);
275 if (numeric_compare_function(&result
, first
, second TSRMLS_CC
) != SUCCESS
) {
278 return (Z_LVAL(result
) > 0 ? -1 : (Z_LVAL(result
) < 0 ? 1 : 0));
282 /* {{{ static STATUS http_send_chunk(const void *, size_t, size_t,
284 static STATUS
_http_send_chunk(const void *data
, const size_t begin
,
285 const size_t end
, const http_send_mode mode TSRMLS_DC
)
289 long len
= end
- begin
;
295 s
= (php_stream
*) data
;
296 if (php_stream_seek(s
, begin
, SEEK_SET
)) {
299 buf
= (char *) ecalloc(1, HTTP_BUF_SIZE
);
300 /* read into buf and write out */
301 while ((len
-= HTTP_BUF_SIZE
) >= 0) {
302 if (!(read
= php_stream_read(s
, buf
, HTTP_BUF_SIZE
))) {
306 if (read
- php_body_write(buf
, read TSRMLS_CC
)) {
312 /* read & write left over */
314 if (read
= php_stream_read(s
, buf
, HTTP_BUF_SIZE
+ len
)) {
315 if (read
- php_body_write(buf
, read TSRMLS_CC
)) {
329 return len
== php_body_write(((char *)data
) + begin
, len TSRMLS_CC
)
341 #ifdef HTTP_HAVE_CURL
343 /* {{{ static inline void http_curl_initbuf(http_curlbuf_member) */
344 static inline void _http_curl_initbuf(http_curlbuf_member member TSRMLS_DC
)
346 http_curl_freebuf(member
);
348 if (member
& CURLBUF_HDRS
) {
349 HTTP_G(curlbuf
).hdrs
.data
= emalloc(HTTP_CURLBUF_HDRSSIZE
);
350 HTTP_G(curlbuf
).hdrs
.free
= HTTP_CURLBUF_HDRSSIZE
;
352 if (member
& CURLBUF_BODY
) {
353 HTTP_G(curlbuf
).body
.data
= emalloc(HTTP_CURLBUF_BODYSIZE
);
354 HTTP_G(curlbuf
).body
.free
= HTTP_CURLBUF_BODYSIZE
;
359 /* {{{ static inline void http_curl_freebuf(http_curlbuf_member) */
360 static inline void _http_curl_freebuf(http_curlbuf_member member TSRMLS_DC
)
362 if (member
& CURLBUF_HDRS
) {
363 if (HTTP_G(curlbuf
).hdrs
.data
) {
364 efree(HTTP_G(curlbuf
).hdrs
.data
);
365 HTTP_G(curlbuf
).hdrs
.data
= NULL
;
367 HTTP_G(curlbuf
).hdrs
.used
= 0;
368 HTTP_G(curlbuf
).hdrs
.free
= 0;
370 if (member
& CURLBUF_BODY
) {
371 if (HTTP_G(curlbuf
).body
.data
) {
372 efree(HTTP_G(curlbuf
).body
.data
);
373 HTTP_G(curlbuf
).body
.data
= NULL
;
375 HTTP_G(curlbuf
).body
.used
= 0;
376 HTTP_G(curlbuf
).body
.free
= 0;
381 /* {{{ static inline void http_curl_copybuf(http_curlbuf_member, char **,
383 static inline void _http_curl_copybuf(http_curlbuf_member member
, char **data
,
384 size_t *data_len TSRMLS_DC
)
389 if ((member
& CURLBUF_HDRS
) && HTTP_G(curlbuf
).hdrs
.used
) {
390 if ((member
& CURLBUF_BODY
) && HTTP_G(curlbuf
).body
.used
) {
391 *data
= emalloc(HTTP_G(curlbuf
).hdrs
.used
+ HTTP_G(curlbuf
).body
.used
+ 1);
393 *data
= emalloc(HTTP_G(curlbuf
).hdrs
.used
+ 1);
395 memcpy(*data
, HTTP_G(curlbuf
).hdrs
.data
, HTTP_G(curlbuf
).hdrs
.used
);
396 *data_len
= HTTP_G(curlbuf
).hdrs
.used
;
399 if ((member
& CURLBUF_BODY
) && HTTP_G(curlbuf
).body
.used
) {
401 memcpy((*data
) + HTTP_G(curlbuf
).hdrs
.used
,
402 HTTP_G(curlbuf
).body
.data
, HTTP_G(curlbuf
).body
.used
);
403 *data_len
= HTTP_G(curlbuf
).hdrs
.used
+ HTTP_G(curlbuf
).body
.used
;
405 emalloc(HTTP_G(curlbuf
).body
.used
+ 1);
406 memcpy(*data
, HTTP_G(curlbuf
).body
.data
, HTTP_G(curlbuf
).body
.used
);
407 *data_len
= HTTP_G(curlbuf
).body
.used
;
411 (*data
)[*data_len
] = 0;
418 /* {{{ static inline void http_curl_movebuf(http_curlbuf_member, char **,
420 static inline void _http_curl_movebuf(http_curlbuf_member member
, char **data
,
421 size_t *data_len TSRMLS_DC
)
423 http_curl_copybuf(member
, data
, data_len
);
424 http_curl_freebuf(member
);
428 /* {{{ static size_t http_curl_body_callback(char *, size_t, size_t, void *) */
429 static size_t http_curl_body_callback(char *buf
, size_t len
, size_t n
, void *s
)
433 if ((len
*= n
) > HTTP_G(curlbuf
).body
.free
) {
434 size_t bsize
= HTTP_CURLBUF_BODYSIZE
;
435 while (bsize
< len
) {
438 HTTP_G(curlbuf
).body
.data
= erealloc(HTTP_G(curlbuf
).body
.data
,
439 HTTP_G(curlbuf
).body
.used
+ bsize
);
440 HTTP_G(curlbuf
).body
.free
+= bsize
;
443 memcpy(HTTP_G(curlbuf
).body
.data
+ HTTP_G(curlbuf
).body
.used
, buf
, len
);
444 HTTP_G(curlbuf
).body
.free
-= len
;
445 HTTP_G(curlbuf
).body
.used
+= len
;
451 /* {{{ static size_t http_curl_hdrs_callback(char*, size_t, size_t, void *) */
452 static size_t http_curl_hdrs_callback(char *buf
, size_t len
, size_t n
, void *s
)
456 /* discard previous headers */
457 if ((HTTP_G(curlbuf
).hdrs
.used
) && (!strncmp(buf
, "HTTP/1.", strlen("HTTP/1.")))) {
458 http_curl_initbuf(CURLBUF_HDRS
);
461 if ((len
*= n
) > HTTP_G(curlbuf
).hdrs
.free
) {
462 size_t bsize
= HTTP_CURLBUF_HDRSSIZE
;
463 while (bsize
< len
) {
466 HTTP_G(curlbuf
).hdrs
.data
= erealloc(HTTP_G(curlbuf
).hdrs
.data
,
467 HTTP_G(curlbuf
).hdrs
.used
+ bsize
);
468 HTTP_G(curlbuf
).hdrs
.free
+= bsize
;
471 memcpy(HTTP_G(curlbuf
).hdrs
.data
+ HTTP_G(curlbuf
).hdrs
.used
, buf
, len
);
472 HTTP_G(curlbuf
).hdrs
.free
-= len
;
473 HTTP_G(curlbuf
).hdrs
.used
+= len
;
479 /* {{{ static inline zval *http_curl_getopt(HashTable *, char *, int, ...) */
480 static inline zval
*_http_curl_getopt(HashTable
*options
, char *key TSRMLS_DC
, int checks
, ...)
486 if (SUCCESS
!= zend_hash_find(options
, key
, strlen(key
) + 1, (void **) &zoption
)) {
493 va_start(types
, checks
);
494 for (i
= 0; i
< checks
; ++i
) {
495 if ((va_arg(types
, int)) == (Z_TYPE_PP(zoption
))) {
505 /* {{{ static inline void http_curl_setopts(CURL *, char *, HashTable *) */
506 static inline void _http_curl_setopts(CURL
*ch
, const char *url
, HashTable
*options TSRMLS_DC
)
510 /* standard options */
511 curl_easy_setopt(ch
, CURLOPT_URL
, url
);
512 curl_easy_setopt(ch
, CURLOPT_HEADER
, 0);
513 curl_easy_setopt(ch
, CURLOPT_NOPROGRESS
, 1);
514 curl_easy_setopt(ch
, CURLOPT_AUTOREFERER
, 1);
515 curl_easy_setopt(ch
, CURLOPT_WRITEFUNCTION
, http_curl_body_callback
);
516 curl_easy_setopt(ch
, CURLOPT_HEADERFUNCTION
, http_curl_hdrs_callback
);
518 curl_easy_setopt(ch
, CURLOPT_NOSIGNAL
, 1);
521 if ((!options
) || (1 > zend_hash_num_elements(options
))) {
525 /* redirects, defaults to 0 */
526 if (zoption
= http_curl_getopt1(options
, "redirect", IS_LONG
)) {
527 curl_easy_setopt(ch
, CURLOPT_FOLLOWLOCATION
, Z_LVAL_P(zoption
) ? 1 : 0);
528 curl_easy_setopt(ch
, CURLOPT_MAXREDIRS
, Z_LVAL_P(zoption
));
529 if (zoption
= http_curl_getopt2(options
, "unrestrictedauth", IS_LONG
, IS_BOOL
)) {
530 curl_easy_setopt(ch
, CURLOPT_UNRESTRICTED_AUTH
, Z_LVAL_P(zoption
));
533 curl_easy_setopt(ch
, CURLOPT_FOLLOWLOCATION
, 0);
537 if (zoption
= http_curl_getopt1(options
, "proxyhost", IS_STRING
)) {
538 curl_easy_setopt(ch
, CURLOPT_PROXY
, Z_STRVAL_P(zoption
));
540 if (zoption
= http_curl_getopt1(options
, "proxyport", IS_LONG
)) {
541 curl_easy_setopt(ch
, CURLOPT_PROXYPORT
, Z_LVAL_P(zoption
));
544 if (zoption
= http_curl_getopt1(options
, "proxyauth", IS_STRING
)) {
545 curl_easy_setopt(ch
, CURLOPT_PROXYUSERPWD
, Z_STRVAL_P(zoption
));
548 if (zoption
= http_curl_getopt1(options
, "proxyauthtype", IS_LONG
)) {
549 curl_easy_setopt(ch
, CURLOPT_PROXYAUTH
, Z_LVAL_P(zoption
));
554 if (zoption
= http_curl_getopt1(options
, "httpauth", IS_STRING
)) {
555 curl_easy_setopt(ch
, CURLOPT_USERPWD
, Z_STRVAL_P(zoption
));
557 if (zoption
= http_curl_getopt1(options
, "httpauthtype", IS_LONG
)) {
558 curl_easy_setopt(ch
, CURLOPT_HTTPAUTH
, Z_LVAL_P(zoption
));
561 /* compress, enabled by default (empty string enables deflate and gzip) */
562 if (zoption
= http_curl_getopt2(options
, "compress", IS_LONG
, IS_BOOL
)) {
563 if (Z_LVAL_P(zoption
)) {
564 curl_easy_setopt(ch
, CURLOPT_ENCODING
, "");
567 curl_easy_setopt(ch
, CURLOPT_ENCODING
, "");
571 if (zoption
= http_curl_getopt1(options
, "port", IS_LONG
)) {
572 curl_easy_setopt(ch
, CURLOPT_PORT
, Z_LVAL_P(zoption
));
576 if (zoption
= http_curl_getopt1(options
, "referer", IS_STRING
)) {
577 curl_easy_setopt(ch
, CURLOPT_REFERER
, Z_STRVAL_P(zoption
));
580 /* useragent, default "PECL::HTTP/version (PHP/version)" */
581 if (zoption
= http_curl_getopt1(options
, "useragent", IS_STRING
)) {
582 curl_easy_setopt(ch
, CURLOPT_USERAGENT
, Z_STRVAL_P(zoption
));
584 curl_easy_setopt(ch
, CURLOPT_USERAGENT
,
585 "PECL::HTTP/" PHP_EXT_HTTP_VERSION
" (PHP/" PHP_VERSION
")");
588 /* cookies, array('name' => 'value') */
589 if (zoption
= http_curl_getopt1(options
, "cookies", IS_ARRAY
)) {
593 smart_str qstr
= {0};
595 zend_hash_internal_pointer_reset(Z_ARRVAL_P(zoption
));
596 while (HASH_KEY_NON_EXISTANT
!= (key_type
= zend_hash_get_current_key_type(Z_ARRVAL_P(zoption
)))) {
597 if (key_type
== HASH_KEY_IS_STRING
) {
598 zend_hash_get_current_key(Z_ARRVAL_P(zoption
), &cookie_key
, NULL
, 0);
599 zend_hash_get_current_data(Z_ARRVAL_P(zoption
), (void **) &cookie_val
);
600 smart_str_appends(&qstr
, cookie_key
);
601 smart_str_appendl(&qstr
, "=", 1);
602 smart_str_appendl(&qstr
, Z_STRVAL_PP(cookie_val
), Z_STRLEN_PP(cookie_val
));
603 smart_str_appendl(&qstr
, "; ", 2);
604 zend_hash_move_forward(Z_ARRVAL_P(zoption
));
610 curl_easy_setopt(ch
, CURLOPT_COOKIE
, qstr
.c
);
615 if (zoption
= http_curl_getopt1(options
, "cookiestore", IS_STRING
)) {
616 curl_easy_setopt(ch
, CURLOPT_COOKIEFILE
, Z_STRVAL_P(zoption
));
617 curl_easy_setopt(ch
, CURLOPT_COOKIEJAR
, Z_STRVAL_P(zoption
));
620 /* additional headers, array('name' => 'value') */
621 if (zoption
= http_curl_getopt1(options
, "headers", IS_ARRAY
)) {
623 char *header_key
, header
[1024] = {0};
625 struct curl_slist
*headers
= NULL
;
627 zend_hash_internal_pointer_reset(Z_ARRVAL_P(zoption
));
628 while (HASH_KEY_NON_EXISTANT
!= (key_type
= zend_hash_get_current_key_type(Z_ARRVAL_P(zoption
)))) {
629 if (key_type
== HASH_KEY_IS_STRING
) {
630 zend_hash_get_current_key(Z_ARRVAL_P(zoption
), &header_key
, NULL
, 0);
631 zend_hash_get_current_data(Z_ARRVAL_P(zoption
), (void **) &header_val
);
632 snprintf(header
, 1023, "%s: %s", header_key
, Z_STRVAL_PP(header_val
));
633 headers
= curl_slist_append(headers
, header
);
634 zend_hash_move_forward(Z_ARRVAL_P(zoption
));
638 curl_easy_setopt(ch
, CURLOPT_HTTPHEADER
, headers
);
644 /* {{{ static inline char *http_curl_getinfoname(CURLINFO) */
645 static inline char *_http_curl_getinfoname(CURLINFO i TSRMLS_DC
)
647 #define CASE(I) case CURLINFO_ ##I : return pretty_key(estrdup( #I ), strlen(#I), 0, 0)
650 /* CURLINFO_EFFECTIVE_URL = CURLINFO_STRING +1, */
652 /* CURLINFO_RESPONSE_CODE = CURLINFO_LONG +2, */
654 /* CURLINFO_TOTAL_TIME = CURLINFO_DOUBLE +3, */
656 /* CURLINFO_NAMELOOKUP_TIME = CURLINFO_DOUBLE +4, */
657 CASE(NAMELOOKUP_TIME
);
658 /* CURLINFO_CONNECT_TIME = CURLINFO_DOUBLE +5, */
660 /* CURLINFO_PRETRANSFER_TIME = CURLINFO_DOUBLE +6, */
661 CASE(PRETRANSFER_TIME
);
662 /* CURLINFO_SIZE_UPLOAD = CURLINFO_DOUBLE +7, */
664 /* CURLINFO_SIZE_DOWNLOAD = CURLINFO_DOUBLE +8, */
666 /* CURLINFO_SPEED_DOWNLOAD = CURLINFO_DOUBLE +9, */
667 CASE(SPEED_DOWNLOAD
);
668 /* CURLINFO_SPEED_UPLOAD = CURLINFO_DOUBLE +10, */
670 /* CURLINFO_HEADER_SIZE = CURLINFO_LONG +11, */
672 /* CURLINFO_REQUEST_SIZE = CURLINFO_LONG +12, */
674 /* CURLINFO_SSL_VERIFYRESULT = CURLINFO_LONG +13, */
675 CASE(SSL_VERIFYRESULT
);
676 /* CURLINFO_FILETIME = CURLINFO_LONG +14, */
678 /* CURLINFO_CONTENT_LENGTH_DOWNLOAD = CURLINFO_DOUBLE +15, */
679 CASE(CONTENT_LENGTH_DOWNLOAD
);
680 /* CURLINFO_CONTENT_LENGTH_UPLOAD = CURLINFO_DOUBLE +16, */
681 CASE(CONTENT_LENGTH_UPLOAD
);
682 /* CURLINFO_STARTTRANSFER_TIME = CURLINFO_DOUBLE +17, */
683 CASE(STARTTRANSFER_TIME
);
684 /* CURLINFO_CONTENT_TYPE = CURLINFO_STRING +18, */
686 /* CURLINFO_REDIRECT_TIME = CURLINFO_DOUBLE +19, */
688 /* CURLINFO_REDIRECT_COUNT = CURLINFO_LONG +20, */
689 CASE(REDIRECT_COUNT
);
690 /* CURLINFO_PRIVATE = CURLINFO_STRING +21, */
692 /* CURLINFO_HTTP_CONNECTCODE = CURLINFO_LONG +22, */
693 CASE(HTTP_CONNECTCODE
);
694 /* CURLINFO_HTTPAUTH_AVAIL = CURLINFO_LONG +23, */
695 CASE(HTTPAUTH_AVAIL
);
696 /* CURLINFO_PROXYAUTH_AVAIL = CURLINFO_LONG +24, */
697 CASE(PROXYAUTH_AVAIL
);
704 /* {{{ static inline void http_curl_getinfo_ex(CURL, CURLINFO, zval *) */
705 static inline void _http_curl_getinfo_ex(CURL
*ch
, CURLINFO i
, zval
*array TSRMLS_DC
)
708 if (key
= http_curl_getinfoname(i
)) {
709 switch (i
& ~CURLINFO_MASK
)
711 case CURLINFO_STRING
:
714 if (CURLE_OK
== curl_easy_getinfo(ch
, i
, &c
)) {
715 add_assoc_string(array
, key
, c
? c
: "", 1);
720 case CURLINFO_DOUBLE
:
723 if (CURLE_OK
== curl_easy_getinfo(ch
, i
, &d
)) {
724 add_assoc_double(array
, key
, d
);
732 if (CURLE_OK
== curl_easy_getinfo(ch
, i
, &l
)) {
733 add_assoc_long(array
, key
, l
);
742 /* {{{ static inline http_curl_getinfo(CURL, HashTable *) */
743 static inline void _http_curl_getinfo(CURL
*ch
, HashTable
*info TSRMLS_DC
)
746 Z_ARRVAL(array
) = info
;
748 #define INFO(I) http_curl_getinfo_ex(ch, CURLINFO_ ##I , &array)
749 /* CURLINFO_EFFECTIVE_URL = CURLINFO_STRING +1, */
751 /* CURLINFO_RESPONSE_CODE = CURLINFO_LONG +2, */
753 /* CURLINFO_TOTAL_TIME = CURLINFO_DOUBLE +3, */
755 /* CURLINFO_NAMELOOKUP_TIME = CURLINFO_DOUBLE +4, */
756 INFO(NAMELOOKUP_TIME
);
757 /* CURLINFO_CONNECT_TIME = CURLINFO_DOUBLE +5, */
759 /* CURLINFO_PRETRANSFER_TIME = CURLINFO_DOUBLE +6, */
760 INFO(PRETRANSFER_TIME
);
761 /* CURLINFO_SIZE_UPLOAD = CURLINFO_DOUBLE +7, */
763 /* CURLINFO_SIZE_DOWNLOAD = CURLINFO_DOUBLE +8, */
765 /* CURLINFO_SPEED_DOWNLOAD = CURLINFO_DOUBLE +9, */
766 INFO(SPEED_DOWNLOAD
);
767 /* CURLINFO_SPEED_UPLOAD = CURLINFO_DOUBLE +10, */
769 /* CURLINFO_HEADER_SIZE = CURLINFO_LONG +11, */
771 /* CURLINFO_REQUEST_SIZE = CURLINFO_LONG +12, */
773 /* CURLINFO_SSL_VERIFYRESULT = CURLINFO_LONG +13, */
774 INFO(SSL_VERIFYRESULT
);
775 /* CURLINFO_FILETIME = CURLINFO_LONG +14, */
777 /* CURLINFO_CONTENT_LENGTH_DOWNLOAD = CURLINFO_DOUBLE +15, */
778 INFO(CONTENT_LENGTH_DOWNLOAD
);
779 /* CURLINFO_CONTENT_LENGTH_UPLOAD = CURLINFO_DOUBLE +16, */
780 INFO(CONTENT_LENGTH_UPLOAD
);
781 /* CURLINFO_STARTTRANSFER_TIME = CURLINFO_DOUBLE +17, */
782 INFO(STARTTRANSFER_TIME
);
783 /* CURLINFO_CONTENT_TYPE = CURLINFO_STRING +18, */
785 /* CURLINFO_REDIRECT_TIME = CURLINFO_DOUBLE +19, */
787 /* CURLINFO_REDIRECT_COUNT = CURLINFO_LONG +20, */
788 INFO(REDIRECT_COUNT
);
789 /* CURLINFO_PRIVATE = CURLINFO_STRING +21, */
791 /* CURLINFO_HTTP_CONNECTCODE = CURLINFO_LONG +22, */
792 INFO(HTTP_CONNECTCODE
);
793 /* CURLINFO_HTTPAUTH_AVAIL = CURLINFO_LONG +23, */
794 INFO(HTTPAUTH_AVAIL
);
795 /* CURLINFO_PROXYAUTH_AVAIL = CURLINFO_LONG +24, */
796 INFO(PROXYAUTH_AVAIL
);
804 /* {{{ Day/Month/TZ checks for http_parse_date()
805 Originally by libcurl, Copyright (C) 1998 - 2004, Daniel Stenberg, <daniel@haxx.se>, et al. */
806 static int check_day(char *day
, size_t len
)
809 const char * const *check
= (len
> 3) ? &weekdays
[0] : &wkdays
[0];
810 for (i
= 0; i
< 7; i
++) {
811 if (!strcmp(day
, check
[0])) {
819 static int check_month(char *month
)
822 const char * const *check
= &months
[0];
823 for (i
= 0; i
< 12; i
++) {
824 if (!strcmp(month
, check
[0])) {
832 /* return the time zone offset between GMT and the input one, in number
833 of seconds or -1 if the timezone wasn't found/legal */
835 static int check_tzone(char *tzone
)
838 const struct time_zone
*check
= time_zones
;
839 for (i
= 0; i
< sizeof(time_zones
) / sizeof(time_zones
[0]); i
++) {
840 if (!strcmp(tzone
, check
->name
)) {
841 return check
->offset
* 60;
849 /* static char *pretty_key(char *, int, int, int) */
850 static char *pretty_key(char *key
, int key_len
, int uctitle
, int xhyphen
)
852 if (key
&& key_len
) {
854 if (wasalpha
= isalpha(key
[0])) {
855 key
[0] = uctitle
? toupper(key
[0]) : tolower(key
[0]);
857 for (i
= 1; i
< key_len
; i
++) {
858 if (isalpha(key
[i
])) {
859 key
[i
] = ((!wasalpha
) && uctitle
) ? toupper(key
[i
]) : tolower(key
[i
]);
862 if (xhyphen
&& (key
[i
] == '_')) {
873 /* {{{ static STATUS http_ob_stack_get(php_ob_buffer *, php_ob_buffer **) */
874 static STATUS
http_ob_stack_get(php_ob_buffer
*o
, php_ob_buffer
**s
)
877 php_ob_buffer
*b
= emalloc(sizeof(php_ob_buffer
));
878 b
->handler_name
= estrdup(o
->handler_name
);
879 b
->buffer
= estrndup(o
->buffer
, o
->text_length
);
880 b
->text_length
= o
->text_length
;
881 b
->chunk_size
= o
->chunk_size
;
892 /* {{{ char *http_date(time_t) */
893 PHP_HTTP_API
char *_http_date(time_t t TSRMLS_DC
)
895 struct tm
*gmtime
, tmbuf
;
896 char *date
= ecalloc(31, 1);
898 gmtime
= php_gmtime_r(&t
, &tmbuf
);
900 "%s, %02d %s %04d %02d:%02d:%02d GMT",
901 days
[gmtime
->tm_wday
], gmtime
->tm_mday
,
902 months
[gmtime
->tm_mon
], gmtime
->tm_year
+ 1900,
903 gmtime
->tm_hour
, gmtime
->tm_min
, gmtime
->tm_sec
909 /* {{{ time_t http_parse_date(char *)
910 Originally by libcurl, Copyright (C) 1998 - 2004, Daniel Stenberg, <daniel@haxx.se>, et al. */
911 PHP_HTTP_API
time_t _http_parse_date(const char *date
)
914 int tz_offset
= -1, year
= -1, month
= -1, monthday
= -1, weekday
= -1,
915 hours
= -1, minutes
= -1, seconds
= -1;
917 enum assume_next dignext
= DATE_MDAY
;
918 const char *indate
= date
;
920 int found
= 0, part
= 0; /* max 6 parts */
922 while (*date
&& (part
< 6)) {
925 while (*date
&& !isalnum(*date
)) {
929 if (isalpha(*date
)) {
930 /* a name coming up */
933 sscanf(date
, "%31[A-Za-z]", buf
);
937 weekday
= check_day(buf
, len
);
943 if (!found
&& (month
== -1)) {
944 month
= check_month(buf
);
950 if (!found
&& (tz_offset
== -1)) {
951 /* this just must be a time zone string */
952 tz_offset
= check_tzone(buf
);
953 if (tz_offset
!= -1) {
959 return -1; /* bad string */
963 else if (isdigit(*date
)) {
967 if((seconds
== -1) && (3 == sscanf(date
, "%02d:%02d:%02d", &hours
, &minutes
, &seconds
))) {
973 val
= (int) strtol(date
, &end
, 10);
975 if ((tz_offset
== -1) && ((end
- date
) == 4) && (val
< 1300) && (indate
< date
) && ((date
[-1] == '+' || date
[-1] == '-'))) {
976 /* four digits and a value less than 1300 and it is preceeded with
977 a plus or minus. This is a time zone indication. */
979 tz_offset
= (val
/ 100 * 60 + val
% 100) * 60;
981 /* the + and - prefix indicates the local time compared to GMT,
982 this we need ther reversed math to get what we want */
983 tz_offset
= date
[-1] == '+' ? -tz_offset
: tz_offset
;
986 if (((end
- date
) == 8) && (year
== -1) && (month
== -1) && (monthday
== -1)) {
987 /* 8 digits, no year, month or day yet. This is YYYYMMDD */
990 month
= (val
% 10000) / 100 - 1; /* month is 0 - 11 */
991 monthday
= val
% 100;
994 if (!found
&& (dignext
== DATE_MDAY
) && (monthday
== -1)) {
995 if ((val
> 0) && (val
< 32)) {
1002 if (!found
&& (dignext
== DATE_YEAR
) && (year
== -1)) {
1006 year
+= year
> 70 ? 1900 : 2000;
1008 if(monthday
== -1) {
1009 dignext
= DATE_MDAY
;
1024 if (-1 == seconds
) {
1025 seconds
= minutes
= hours
= 0; /* no time, make it zero */
1028 if ((-1 == monthday
) || (-1 == month
) || (-1 == year
)) {
1029 /* lacks vital info, fail */
1033 if (sizeof(time_t) < 5) {
1034 /* 32 bit time_t can only hold dates to the beginning of 2038 */
1040 tm
.tm_sec
= seconds
;
1041 tm
.tm_min
= minutes
;
1043 tm
.tm_mday
= monthday
;
1045 tm
.tm_year
= year
- 1900;
1052 /* time zone adjust */
1054 struct tm
*gmt
, keeptime2
;
1058 if(!(gmt
= php_gmtime_r(&t
, &keeptime2
))) {
1059 return -1; /* illegal date/time */
1064 /* Add the time zone diff (between the given timezone and GMT) and the
1065 diff between the local time zone and GMT. */
1066 delta
= (tz_offset
!= -1 ? tz_offset
: 0) + (t
- t2
);
1068 if((delta
> 0) && (t
+ delta
< t
)) {
1069 return -1; /* time_t overflow */
1079 /* {{{ inline STATUS http_send_status(int) */
1080 PHP_HTTP_API
inline STATUS
_http_send_status(const int status TSRMLS_DC
)
1083 return sapi_header_op(SAPI_HEADER_SET_STATUS
, (void *) s TSRMLS_CC
);
1087 /* {{{ inline STATUS http_send_header(char *) */
1088 PHP_HTTP_API
inline STATUS
_http_send_header(const char *header TSRMLS_DC
)
1090 return http_send_status_header(0, header
);
1094 /* {{{ inline STATUS http_send_status_header(int, char *) */
1095 PHP_HTTP_API
inline STATUS
_http_send_status_header(const int status
, const char *header TSRMLS_DC
)
1097 sapi_header_line h
= {(char *) header
, strlen(header
), status
};
1098 return sapi_header_op(SAPI_HEADER_REPLACE
, &h TSRMLS_CC
);
1102 /* {{{ inline zval *http_get_server_var(char *) */
1103 PHP_HTTP_API
inline zval
*_http_get_server_var(const char *key TSRMLS_DC
)
1106 if (SUCCESS
== zend_hash_find(
1108 (char *) key
, strlen(key
) + 1, (void **) &var
)) {
1115 /* {{{ void http_ob_etaghandler(char *, uint, char **, uint *, int) */
1116 PHP_HTTP_API
void _http_ob_etaghandler(char *output
, uint output_len
,
1117 char **handled_output
, uint
*handled_output_len
, int mode TSRMLS_DC
)
1119 char etag
[33] = { 0 };
1120 unsigned char digest
[16];
1122 if (mode
& PHP_OUTPUT_HANDLER_START
) {
1123 PHP_MD5Init(&HTTP_G(etag_md5
));
1126 PHP_MD5Update(&HTTP_G(etag_md5
), output
, output_len
);
1128 if (mode
& PHP_OUTPUT_HANDLER_END
) {
1129 PHP_MD5Final(digest
, &HTTP_G(etag_md5
));
1131 /* just do that if desired */
1132 if (HTTP_G(etag_started
)) {
1133 make_digest(etag
, digest
);
1135 if (http_etag_match("HTTP_IF_NONE_MATCH", etag
)) {
1136 http_send_status(304);
1138 http_send_etag(etag
, 32);
1143 *handled_output_len
= output_len
;
1144 *handled_output
= estrndup(output
, output_len
);
1148 /* {{{ STATUS http_start_ob_handler(php_output_handler_func_t, char *, uint, zend_bool) */
1149 PHP_HTTP_API STATUS
_http_start_ob_handler(php_output_handler_func_t handler_func
,
1150 char *handler_name
, uint chunk_size
, zend_bool erase TSRMLS_DC
)
1152 php_ob_buffer
**stack
;
1155 if (count
= OG(ob_nesting_level
)) {
1156 stack
= ecalloc(sizeof(php_ob_buffer
*), count
);
1159 zend_stack_apply_with_argument(&OG(ob_buffers
), ZEND_STACK_APPLY_BOTTOMUP
,
1160 (int (*)(void *elem
, void *)) http_ob_stack_get
, stack
);
1164 http_ob_stack_get(&OG(active_ob_buffer
), stack
);
1167 while (OG(ob_nesting_level
)) {
1168 php_end_ob_buffer(0, 0 TSRMLS_CC
);
1172 php_ob_set_internal_handler(handler_func
, chunk_size
, handler_name
, erase TSRMLS_CC
);
1174 for (i
= 0; i
< count
; i
++) {
1175 php_ob_buffer
*s
= stack
[i
];
1176 if (strcmp(s
->handler_name
, "default output handler")) {
1177 php_start_ob_buffer_named(s
->handler_name
, s
->chunk_size
, s
->erase TSRMLS_CC
);
1179 php_body_write(s
->buffer
, s
->text_length TSRMLS_CC
);
1180 efree(s
->handler_name
);
1192 /* {{{ int http_modified_match(char *, int) */
1193 PHP_HTTP_API
int _http_modified_match(const char *entry
, const time_t t TSRMLS_DC
)
1197 char *modified
, *chr_ptr
;
1199 HTTP_GSC(zmodified
, entry
, 0);
1201 modified
= estrndup(Z_STRVAL_P(zmodified
), Z_STRLEN_P(zmodified
));
1202 if (chr_ptr
= strrchr(modified
, ';')) {
1205 retval
= (t
<= http_parse_date(modified
));
1211 /* {{{ int http_etag_match(char *, char *) */
1212 PHP_HTTP_API
int _http_etag_match(const char *entry
, const char *etag TSRMLS_DC
)
1218 HTTP_GSC(zetag
, entry
, 0);
1220 if (NULL
!= strchr(Z_STRVAL_P(zetag
), '*')) {
1224 quoted_etag
= (char *) emalloc(strlen(etag
) + 3);
1225 sprintf(quoted_etag
, "\"%s\"", etag
);
1227 if (!strchr(Z_STRVAL_P(zetag
), ',')) {
1228 result
= !strcmp(Z_STRVAL_P(zetag
), quoted_etag
);
1230 result
= (NULL
!= strstr(Z_STRVAL_P(zetag
), quoted_etag
));
1237 /* {{{ STATUS http_send_last_modified(int) */
1238 PHP_HTTP_API STATUS
_http_send_last_modified(const time_t t TSRMLS_DC
)
1240 char modified
[96] = "Last-Modified: ", *date
;
1241 date
= http_date(t
);
1242 strcat(modified
, date
);
1248 return http_send_header(modified
);
1252 /* {{{ static STATUS http_send_etag(char *, int) */
1253 PHP_HTTP_API STATUS
_http_send_etag(const char *etag
,
1254 const int etag_len TSRMLS_DC
)
1260 php_error_docref(NULL TSRMLS_CC
,E_ERROR
,
1261 "Attempt to send empty ETag (previous: %s)\n", HTTP_G(etag
));
1267 efree(HTTP_G(etag
));
1269 HTTP_G(etag
) = estrdup(etag
);
1271 etag_header
= ecalloc(sizeof("ETag: \"\"") + etag_len
, 1);
1272 sprintf(etag_header
, "ETag: \"%s\"", etag
);
1273 if (SUCCESS
!= (status
= http_send_header(etag_header
))) {
1274 php_error_docref(NULL TSRMLS_CC
, E_WARNING
, "Couldn't send '%s' header", etag_header
);
1281 /* {{{ STATUS http_send_cache_control(char *, size_t) */
1282 PHP_HTTP_API STATUS
_http_send_cache_control(const char *cache_control
,
1283 const size_t cc_len TSRMLS_DC
)
1286 char *cc_header
= ecalloc(sizeof("Cache-Control: ") + cc_len
, 1);
1288 sprintf(cc_header
, "Cache-Control: %s", cache_control
);
1289 if (SUCCESS
!= (status
= http_send_header(cc_header
))) {
1290 php_error_docref(NULL TSRMLS_CC
, E_NOTICE
,
1291 "Could not send '%s' header", cc_header
);
1298 /* {{{ STATUS http_send_content_type(char *, size_t) */
1299 PHP_HTTP_API STATUS
_http_send_content_type(const char *content_type
,
1300 const size_t ct_len TSRMLS_DC
)
1305 if (!strchr(content_type
, '/')) {
1306 php_error_docref(NULL TSRMLS_CC
, E_WARNING
,
1307 "Content-Type '%s' doesn't seem to consist of a primary and a secondary part",
1312 /* remember for multiple ranges */
1313 if (HTTP_G(ctype
)) {
1314 efree(HTTP_G(ctype
));
1316 HTTP_G(ctype
) = estrndup(content_type
, ct_len
);
1318 ct_header
= ecalloc(sizeof("Content-Type: ") + ct_len
, 1);
1319 sprintf(ct_header
, "Content-Type: %s", content_type
);
1321 if (SUCCESS
!= (status
= http_send_header(ct_header
))) {
1322 php_error_docref(NULL TSRMLS_CC
, E_WARNING
,
1323 "Couldn't send '%s' header", ct_header
);
1330 /* {{{ STATUS http_send_content_disposition(char *, size_t, zend_bool) */
1331 PHP_HTTP_API STATUS
_http_send_content_disposition(const char *filename
,
1332 const size_t f_len
, const zend_bool send_inline TSRMLS_DC
)
1338 cd_header
= ecalloc(sizeof("Content-Disposition: inline; filename=\"\"") + f_len
, 1);
1339 sprintf(cd_header
, "Content-Disposition: inline; filename=\"%s\"", filename
);
1341 cd_header
= ecalloc(sizeof("Content-Disposition: attachment; filename=\"\"") + f_len
, 1);
1342 sprintf(cd_header
, "Content-Disposition: attachment; filename=\"%s\"", filename
);
1345 if (SUCCESS
!= (status
= http_send_header(cd_header
))) {
1346 php_error_docref(NULL TSRMLS_CC
, E_WARNING
, "Couldn't send '%s' header", cd_header
);
1353 /* {{{ STATUS http_cache_last_modified(time_t, time_t, char *, size_t) */
1354 PHP_HTTP_API STATUS
_http_cache_last_modified(const time_t last_modified
,
1355 const time_t send_modified
, const char *cache_control
, const size_t cc_len TSRMLS_DC
)
1358 http_send_cache_control(cache_control
, cc_len
);
1361 if (http_modified_match("HTTP_IF_MODIFIED_SINCE", last_modified
)) {
1362 if (SUCCESS
== http_send_status(304)) {
1365 php_error_docref(NULL TSRMLS_CC
, E_WARNING
, "Could not send 304 Not Modified");
1369 return http_send_last_modified(send_modified
);
1373 /* {{{ STATUS http_cache_etag(char *, size_t, char *, size_t) */
1374 PHP_HTTP_API STATUS
_http_cache_etag(const char *etag
, const size_t etag_len
,
1375 const char *cache_control
, const size_t cc_len TSRMLS_DC
)
1378 http_send_cache_control(cache_control
, cc_len
);
1382 http_send_etag(etag
, etag_len
);
1383 if (http_etag_match("HTTP_IF_NONE_MATCH", etag
)) {
1384 if (SUCCESS
== http_send_status(304)) {
1387 php_error_docref(NULL TSRMLS_CC
, E_WARNING
, "Could not send 304 Not Modified");
1393 /* if no etag is given and we didn't already start ob_etaghandler -- start it */
1394 if (!HTTP_G(etag_started
)) {
1395 if (SUCCESS
== http_start_ob_handler(_http_ob_etaghandler
, "ob_etaghandler", 4096, 1)) {
1396 HTTP_G(etag_started
) = 1;
1399 php_error_docref(NULL TSRMLS_CC
, E_WARNING
, "Could not start ob_etaghandler");
1407 /* {{{ char *http_absolute_uri(char *, char *) */
1408 PHP_HTTP_API
char *_http_absolute_uri(const char *url
,
1409 const char *proto TSRMLS_DC
)
1411 char URI
[HTTP_URI_MAXLEN
+ 1], *PTR
, *proto_ptr
, *host
, *path
;
1414 if (!url
|| !strlen(url
)) {
1415 if (!SG(request_info
).request_uri
) {
1418 url
= SG(request_info
).request_uri
;
1420 /* Mess around with already absolute URIs */
1421 else if (proto_ptr
= strstr(url
, "://")) {
1422 if (!proto
|| !strncmp(url
, proto
, strlen(proto
))) {
1423 return estrdup(url
);
1425 snprintf(URI
, HTTP_URI_MAXLEN
, "%s%s", proto
, proto_ptr
+ 3);
1426 return estrdup(URI
);
1430 /* protocol defaults to http */
1431 if (!proto
|| !strlen(proto
)) {
1436 if ( (zhost
= http_get_server_var("HTTP_HOST")) ||
1437 (zhost
= http_get_server_var("SERVER_NAME"))) {
1438 host
= Z_STRVAL_P(zhost
);
1445 if (url
[0] == '/') {
1446 snprintf(URI
, HTTP_URI_MAXLEN
, "%s://%s%s", proto
, host
, url
);
1447 } else if (SG(request_info
).request_uri
) {
1448 path
= estrdup(SG(request_info
).request_uri
);
1449 php_dirname(path
, strlen(path
));
1450 snprintf(URI
, HTTP_URI_MAXLEN
, "%s://%s%s/%s", proto
, host
, path
, url
);
1453 snprintf(URI
, HTTP_URI_MAXLEN
, "%s://%s/%s", proto
, host
, url
);
1456 /* strip everything after a new line */
1459 if (*PTR
== '\n' || *PTR
== '\r') {
1466 return estrdup(URI
);
1470 /* {{{ char *http_negotiate_q(char *, zval *, char *, hash_entry_type) */
1471 PHP_HTTP_API
char *_http_negotiate_q(const char *entry
, const zval
*supported
,
1472 const char *def TSRMLS_DC
)
1474 zval
*zaccept
, *zarray
, *zdelim
, **zentry
, *zentries
, **zsupp
;
1475 char *q_ptr
, *result
;
1479 HTTP_GSC(zaccept
, entry
, estrdup(def
));
1481 MAKE_STD_ZVAL(zarray
);
1484 MAKE_STD_ZVAL(zdelim
);
1485 ZVAL_STRING(zdelim
, ",", 0);
1486 php_explode(zdelim
, zaccept
, zarray
, -1);
1489 MAKE_STD_ZVAL(zentries
);
1490 array_init(zentries
);
1492 c
= zend_hash_num_elements(Z_ARRVAL_P(zarray
));
1493 for (i
= 0; i
< c
; i
++, zend_hash_move_forward(Z_ARRVAL_P(zarray
))) {
1495 if (SUCCESS
!= zend_hash_get_current_data(
1496 Z_ARRVAL_P(zarray
), (void **) &zentry
)) {
1497 php_error_docref(NULL TSRMLS_CC
, E_WARNING
,
1498 "Cannot parse %s header: %s", entry
, Z_STRVAL_P(zaccept
));
1502 /* check for qualifier */
1503 if (NULL
!= (q_ptr
= strrchr(Z_STRVAL_PP(zentry
), ';'))) {
1504 qual
= strtod(q_ptr
+ 3, NULL
);
1509 /* walk through the supported array */
1510 for ( zend_hash_internal_pointer_reset(Z_ARRVAL_P(supported
));
1511 SUCCESS
== zend_hash_get_current_data(
1512 Z_ARRVAL_P(supported
), (void **) &zsupp
);
1513 zend_hash_move_forward(Z_ARRVAL_P(supported
))) {
1514 if (!strcasecmp(Z_STRVAL_PP(zsupp
), Z_STRVAL_PP(zentry
))) {
1515 add_assoc_double(zentries
, Z_STRVAL_PP(zsupp
), qual
);
1524 zend_hash_internal_pointer_reset(Z_ARRVAL_P(zentries
));
1526 if ( (SUCCESS
!= zend_hash_sort(Z_ARRVAL_P(zentries
), zend_qsort
,
1527 http_sort_q
, 0 TSRMLS_CC
)) ||
1528 (HASH_KEY_NON_EXISTANT
== zend_hash_get_current_key(
1529 Z_ARRVAL_P(zentries
), &result
, 0, 1))) {
1530 result
= estrdup(def
);
1533 zval_dtor(zentries
);
1540 /* {{{ http_range_status http_get_request_ranges(zval *zranges, size_t) */
1541 PHP_HTTP_API http_range_status
_http_get_request_ranges(zval
*zranges
,
1542 const size_t length TSRMLS_DC
)
1546 long begin
= -1, end
= -1, *ptr
;
1548 HTTP_GSC(zrange
, "HTTP_RANGE", RANGE_NO
);
1549 range
= Z_STRVAL_P(zrange
);
1551 if (strncmp(range
, "bytes=", strlen("bytes="))) {
1552 php_error_docref(NULL TSRMLS_CC
, E_NOTICE
, "Range header misses bytes=");
1557 range
+= strlen("bytes=");
1560 switch (c
= *(range
++))
1566 case '1': case '2': case '3':
1567 case '4': case '5': case '6':
1568 case '7': case '8': case '9':
1570 * If the value of the pointer is already set (non-negative)
1571 * then multiply its value by ten and add the current value,
1572 * else initialise the pointers value with the current value
1574 * This let us recognize empty fields when validating the
1575 * ranges, i.e. a "-10" for begin and "12345" for the end
1576 * was the following range request: "Range: bytes=0-12345";
1577 * While a "-1" for begin and "12345" for the end would
1578 * have been: "Range: bytes=-12345".
1593 /* IE - ignore for now */
1600 /* validate ranges */
1605 if ((length
- end
) < 1) {
1613 if ((length
- end
) < 1) {
1616 begin
= length
- end
;
1626 if ((length
- begin
) < 1) {
1634 if ( ((length
- begin
) < 1) ||
1635 ((length
- end
) < 1) ||
1636 ((begin
- end
) >= 0)) {
1646 MAKE_STD_ZVAL(zentry
);
1648 add_index_long(zentry
, 0, begin
);
1649 add_index_long(zentry
, 1, end
);
1650 add_next_index_zval(zranges
, zentry
);
1668 /* {{{ STATUS http_send_ranges(zval *, void *, size_t, http_send_mode) */
1669 PHP_HTTP_API STATUS
_http_send_ranges(zval
*zranges
, const void *data
, const size_t size
, const http_send_mode mode TSRMLS_DC
)
1672 long **begin
, **end
;
1675 /* Send HTTP 206 Partial Content */
1676 http_send_status(206);
1679 if ((c
= zend_hash_num_elements(Z_ARRVAL_P(zranges
))) == 1) {
1680 char range_header
[256] = {0};
1682 zend_hash_index_find(Z_ARRVAL_P(zranges
), 0, (void **) &zrange
);
1683 zend_hash_index_find(Z_ARRVAL_PP(zrange
), 0, (void **) &begin
);
1684 zend_hash_index_find(Z_ARRVAL_PP(zrange
), 1, (void **) &end
);
1686 /* send content range header */
1687 snprintf(range_header
, 255, "Content-Range: bytes %d-%d/%d", **begin
, **end
, size
);
1688 http_send_header(range_header
);
1690 /* send requested chunk */
1691 return http_send_chunk(data
, **begin
, **end
+ 1, mode
);
1697 char bound
[23] = {0}, preface
[1024] = {0},
1698 multi_header
[68] = "Content-Type: multipart/byteranges; boundary=";
1700 snprintf(bound
, 22, "--%d%0.9f", time(NULL
), php_combined_lcg(TSRMLS_C
));
1701 strncat(multi_header
, bound
+ 2, 21);
1702 http_send_header(multi_header
);
1704 /* send each requested chunk */
1705 for ( i
= 0, zend_hash_internal_pointer_reset(Z_ARRVAL_P(zranges
));
1707 i
++, zend_hash_move_forward(Z_ARRVAL_P(zranges
))) {
1708 if ( HASH_KEY_NON_EXISTANT
== zend_hash_get_current_data(
1709 Z_ARRVAL_P(zranges
), (void **) &zrange
) ||
1710 SUCCESS
!= zend_hash_index_find(
1711 Z_ARRVAL_PP(zrange
), 0, (void **) &begin
) ||
1712 SUCCESS
!= zend_hash_index_find(
1713 Z_ARRVAL_PP(zrange
), 1, (void **) &end
)) {
1717 snprintf(preface
, 1023,
1719 HTTP_CRLF
"Content-Type: %s"
1720 HTTP_CRLF
"Content-Range: bytes %ld-%ld/%ld"
1725 HTTP_G(ctype
) ? HTTP_G(ctype
) : "application/x-octetstream",
1731 php_body_write(preface
, strlen(preface
) TSRMLS_CC
);
1732 http_send_chunk(data
, **begin
, **end
+ 1, mode
);
1735 /* write boundary once more */
1736 php_body_write(HTTP_CRLF
, 2 TSRMLS_CC
);
1737 php_body_write(bound
, strlen(bound
) TSRMLS_CC
);
1744 /* {{{ STATUS http_send(void *, sizezo_t, http_send_mode) */
1745 PHP_HTTP_API STATUS
_http_send(const void *data_ptr
, const size_t data_size
,
1746 const http_send_mode data_mode TSRMLS_DC
)
1748 int is_range_request
= http_is_range_request();
1755 if (HTTP_G(etag_started
)) {
1758 HTTP_G(etag_started
) = 0;
1759 /* never ever use the output to compute the ETag if http_send() is used */
1760 php_end_ob_buffer(0, 0 TSRMLS_CC
);
1761 if (!(etag
= http_etag(data_ptr
, data_size
, data_mode
))) {
1765 /* send 304 Not Modified if etag matches */
1766 if ((!is_range_request
) && http_etag_match("HTTP_IF_NONE_MATCH", etag
)) {
1768 return http_send_status(304);
1771 http_send_etag(etag
, 32);
1775 /* send 304 Not Modified if last-modified matches*/
1776 if ((!is_range_request
) && http_modified_match("HTTP_IF_MODIFIED_SINCE", HTTP_G(lmod
))) {
1777 return http_send_status(304);
1780 if (is_range_request
) {
1782 /* only send ranges if entity hasn't changed */
1784 ((!zend_hash_exists(HTTP_SERVER_VARS
, "HTTP_IF_MATCH", 13)) ||
1785 http_etag_match("HTTP_IF_MATCH", HTTP_G(etag
)))
1787 ((!zend_hash_exists(HTTP_SERVER_VARS
, "HTTP_IF_UNMODIFIED_SINCE", 25)) ||
1788 http_modified_match("HTTP_IF_UNMODIFIED_SINCE", HTTP_G(lmod
)))
1791 STATUS result
= FAILURE
;
1792 zval
*zranges
= NULL
;
1793 MAKE_STD_ZVAL(zranges
);
1794 array_init(zranges
);
1796 switch (http_get_request_ranges(zranges
, data_size
))
1801 /* go ahead and send all */
1805 result
= http_send_ranges(zranges
, data_ptr
, data_size
, data_mode
);
1814 http_send_status(416);
1825 return http_send_chunk(data_ptr
, 0, data_size
, data_mode
);
1829 /* {{{ STATUS http_send_data(zval *) */
1830 PHP_HTTP_API STATUS
_http_send_data(const zval
*zdata TSRMLS_DC
)
1832 if (!Z_STRLEN_P(zdata
)) {
1835 if (!Z_STRVAL_P(zdata
)) {
1839 return http_send(Z_STRVAL_P(zdata
), Z_STRLEN_P(zdata
), SEND_DATA
);
1843 /* {{{ STATUS http_send_stream(php_stream *) */
1844 PHP_HTTP_API STATUS
_http_send_stream(const php_stream
*file TSRMLS_DC
)
1846 if (php_stream_stat((php_stream
*) file
, &HTTP_G(ssb
))) {
1850 return http_send(file
, HTTP_G(ssb
).sb
.st_size
, SEND_RSRC
);
1854 /* {{{ STATUS http_send_file(zval *) */
1855 PHP_HTTP_API STATUS
_http_send_file(const zval
*zfile TSRMLS_DC
)
1860 if (!Z_STRLEN_P(zfile
)) {
1864 if (!(file
= php_stream_open_wrapper(Z_STRVAL_P(zfile
), "rb",
1865 REPORT_ERRORS
|ENFORCE_SAFE_MODE
, NULL
))) {
1869 ret
= http_send_stream(file
);
1870 php_stream_close(file
);
1875 /* {{{ proto STATUS http_chunked_decode(char *, size_t, char **, size_t *) */
1876 PHP_HTTP_API STATUS
_http_chunked_decode(const char *encoded
,
1877 const size_t encoded_len
, char **decoded
, size_t *decoded_len TSRMLS_DC
)
1883 *decoded
= (char *) ecalloc(encoded_len
, 1);
1887 while (((e_ptr
- encoded
) - encoded_len
) > 0) {
1888 char hex_len
[9] = {0};
1889 size_t chunk_len
= 0;
1892 /* read in chunk size */
1893 while (isxdigit(*e_ptr
)) {
1895 php_error_docref(NULL TSRMLS_CC
, E_WARNING
,
1896 "Chunk size is too long: 0x%s...", hex_len
);
1900 hex_len
[i
++] = *e_ptr
++;
1903 /* reached the end */
1904 if (!strcmp(hex_len
, "0")) {
1909 if (strncmp(e_ptr
, HTTP_CRLF
, 2)) {
1910 php_error_docref(NULL TSRMLS_CC
, E_WARNING
,
1911 "Invalid character (expected 0x0D 0x0A; got: %x %x)",
1912 *e_ptr
, *(e_ptr
+ 1));
1920 chunk_len
= strtol(hex_len
, &error
, 16);
1921 if (error
== hex_len
) {
1922 php_error_docref(NULL TSRMLS_CC
, E_WARNING
,
1923 "Invalid chunk size string: '%s'", hex_len
);
1929 memcpy(d_ptr
, e_ptr
+= 2, chunk_len
);
1931 e_ptr
+= chunk_len
+ 2;
1932 *decoded_len
+= chunk_len
;
1939 /* {{{ proto STATUS http_split_response(zval *, zval *, zval *) */
1940 PHP_HTTP_API STATUS
_http_split_response(const zval
*zresponse
, zval
*zheaders
,
1941 zval
*zbody TSRMLS_DC
)
1943 char *header
, *response
, *body
= NULL
;
1944 long response_len
= Z_STRLEN_P(zresponse
);
1945 header
= response
= Z_STRVAL_P(zresponse
);
1947 while ((response
- Z_STRVAL_P(zresponse
) + 3) < response_len
) {
1948 if ( (*response
++ == '\r') &&
1949 (*response
++ == '\n') &&
1950 (*response
++ == '\r') &&
1951 (*response
++ == '\n')) {
1957 if (body
&& (response_len
- (body
- header
))) {
1958 ZVAL_STRINGL(zbody
, body
, response_len
- (body
- header
) - 1, 1);
1960 Z_TYPE_P(zbody
) = IS_NULL
;
1963 return http_parse_headers(header
, body
- Z_STRVAL_P(zresponse
), zheaders
);
1967 /* {{{ STATUS http_parse_headers(char *, long, zval *) */
1968 PHP_HTTP_API STATUS
_http_parse_headers(char *header
, int header_len
, zval
*array TSRMLS_DC
)
1970 char *colon
= NULL
, *line
= NULL
, *begin
= header
;
1972 if (header_len
< 2) {
1977 if (!strncmp(header
, "HTTP/1.", 7)) {
1978 char *end
= strstr(header
, HTTP_CRLF
);
1979 add_assoc_stringl(array
, "Status",
1980 header
+ strlen("HTTP/1.x "),
1981 end
- (header
+ strlen("HTTP/1.x ")), 1);
1987 while (header_len
>= (line
- begin
)) {
1993 --value_len
; /* we don't have CR so value length is one char less */
1995 if (colon
&& ((!(*line
- 1)) || ((*line
!= ' ') && (*line
!= '\t')))) {
1997 /* skip empty key */
1998 if (header
!= colon
) {
1999 char *key
= estrndup(header
, colon
- header
);
2000 value_len
+= line
- colon
- 1;
2002 /* skip leading ws */
2003 while (isspace(*(++colon
))) --value_len
;
2004 /* skip trailing ws */
2005 while (isspace(colon
[value_len
- 1])) --value_len
;
2007 if (value_len
< 1) {
2008 /* hm, empty header? */
2009 add_assoc_stringl(array
, key
, "", 0, 1);
2011 add_assoc_stringl(array
, key
, colon
, value_len
, 1);
2018 header
+= line
- header
;
2033 /* {{{ void http_get_request_headers(zval *) */
2034 PHP_HTTP_API
void _http_get_request_headers(zval
*array TSRMLS_DC
)
2038 for ( zend_hash_internal_pointer_reset(HTTP_SERVER_VARS
);
2039 zend_hash_get_current_key(HTTP_SERVER_VARS
, &key
, NULL
, 0) != HASH_KEY_NON_EXISTANT
;
2040 zend_hash_move_forward(HTTP_SERVER_VARS
)) {
2041 if (!strncmp(key
, "HTTP_", 5)) {
2043 zend_hash_get_current_data(HTTP_SERVER_VARS
, (void **) &header
);
2044 add_assoc_stringl(array
, pretty_key(key
+ 5, strlen(key
) - 5, 1, 1), Z_STRVAL_PP(header
), Z_STRLEN_PP(header
), 1);
2051 #ifdef HTTP_HAVE_CURL
2053 /* {{{ STATUS http_get(char *, HashTable *, HashTable *, char **, size_t *) */
2054 PHP_HTTP_API STATUS
_http_get(const char *URL
, HashTable
*options
,
2055 HashTable
*info
, char **data
, size_t *data_len TSRMLS_DC
)
2058 CURL
*ch
= curl_easy_init();
2061 php_error_docref(NULL TSRMLS_CC
, E_WARNING
, "Could not initialize curl");
2065 rs
= http_get_ex(ch
, URL
, options
, info
, data
, data_len
);
2066 curl_easy_cleanup(ch
);
2071 /* {{{ STATUS http_get_ex(CURL *, char *, HashTable *, HashTable *, char **, size_t *) */
2072 PHP_HTTP_API STATUS
_http_get_ex(CURL
*ch
, const char *URL
, HashTable
*options
,
2073 HashTable
*info
, char **data
, size_t *data_len TSRMLS_DC
)
2075 http_curl_initbuf(CURLBUF_EVRY
);
2076 http_curl_setopts(ch
, URL
, options
);
2077 curl_easy_setopt(ch
, CURLOPT_NOBODY
, 0);
2078 curl_easy_setopt(ch
, CURLOPT_POST
, 0);
2080 if (CURLE_OK
!= curl_easy_perform(ch
)) {
2081 http_curl_freebuf(CURLBUF_EVRY
);
2082 php_error_docref(NULL TSRMLS_CC
, E_WARNING
, "Could not perform request");
2086 http_curl_getinfo(ch
, info
);
2088 http_curl_movebuf(CURLBUF_EVRY
, data
, data_len
);
2092 /* {{{ STATUS http_head(char *, HashTable *, HashTable *, char **data, size_t *) */
2093 PHP_HTTP_API STATUS
_http_head(const char *URL
, HashTable
*options
,
2094 HashTable
*info
, char **data
, size_t *data_len TSRMLS_DC
)
2097 CURL
*ch
= curl_easy_init();
2100 php_error_docref(NULL TSRMLS_CC
, E_WARNING
, "Could not initialize curl");
2104 rs
= http_head_ex(ch
, URL
, options
, info
, data
, data_len
);
2105 curl_easy_cleanup(ch
);
2110 /* {{{ STATUS http_head_ex(CURL *, char *, HashTable *, HashTable *, char **data, size_t *) */
2111 PHP_HTTP_API STATUS
_http_head_ex(CURL
*ch
, const char *URL
, HashTable
*options
,
2112 HashTable
*info
, char **data
, size_t *data_len TSRMLS_DC
)
2114 http_curl_initbuf(CURLBUF_HDRS
);
2115 http_curl_setopts(ch
, URL
, options
);
2116 curl_easy_setopt(ch
, CURLOPT_NOBODY
, 1);
2117 curl_easy_setopt(ch
, CURLOPT_POST
, 0);
2119 if (CURLE_OK
!= curl_easy_perform(ch
)) {
2120 http_curl_freebuf(CURLBUF_HDRS
);
2121 php_error_docref(NULL TSRMLS_CC
, E_WARNING
, "Could not perform request");
2125 http_curl_getinfo(ch
, info
);
2127 http_curl_movebuf(CURLBUF_HDRS
, data
, data_len
);
2131 /* {{{ STATUS http_post_data(char *, char *, size_t, HashTable *, HashTable *, char **, size_t *) */
2132 PHP_HTTP_API STATUS
_http_post_data(const char *URL
, char *postdata
,
2133 size_t postdata_len
, HashTable
*options
, HashTable
*info
, char **data
,
2134 size_t *data_len TSRMLS_DC
)
2137 CURL
*ch
= curl_easy_init();
2140 php_error_docref(NULL TSRMLS_CC
, E_WARNING
, "Could not initialize curl");
2143 rs
= http_post_data_ex(ch
, URL
, postdata
, postdata_len
, options
, info
, data
, data_len
);
2144 curl_easy_cleanup(ch
);
2149 /* {{{ STATUS http_post_data_ex(CURL *, char *, char *, size_t, HashTable *, HashTable *, char **, size_t *) */
2150 PHP_HTTP_API STATUS
_http_post_data_ex(CURL
*ch
, const char *URL
, char *postdata
,
2151 size_t postdata_len
, HashTable
*options
, HashTable
*info
, char **data
,
2152 size_t *data_len TSRMLS_DC
)
2154 http_curl_initbuf(CURLBUF_EVRY
);
2155 http_curl_setopts(ch
, URL
, options
);
2156 curl_easy_setopt(ch
, CURLOPT_POST
, 1);
2157 curl_easy_setopt(ch
, CURLOPT_POSTFIELDS
, postdata
);
2158 curl_easy_setopt(ch
, CURLOPT_POSTFIELDSIZE
, postdata_len
);
2160 if (CURLE_OK
!= curl_easy_perform(ch
)) {
2161 http_curl_freebuf(CURLBUF_EVRY
);
2162 php_error_docref(NULL TSRMLS_CC
, E_WARNING
, "Could not perform request");
2166 http_curl_getinfo(ch
, info
);
2168 http_curl_movebuf(CURLBUF_EVRY
, data
, data_len
);
2173 /* {{{ STATUS http_post_array(char *, HashTable *, HashTable *, HashTable *, char **, size_t *) */
2174 PHP_HTTP_API STATUS
_http_post_array(const char *URL
, HashTable
*postarray
,
2175 HashTable
*options
, HashTable
*info
, char **data
, size_t *data_len TSRMLS_DC
)
2177 smart_str qstr
= {0};
2180 if (php_url_encode_hash_ex(postarray
, &qstr
, NULL
,0,NULL
,0,NULL
,0,NULL TSRMLS_CC
) != SUCCESS
) {
2184 php_error_docref(NULL TSRMLS_CC
, E_WARNING
, "Could not encode post data");
2189 status
= http_post_data(URL
, qstr
.c
, qstr
.len
, options
, info
, data
, data_len
);
2200 /* {{{ STATUS http_auth_header(char *, char*) */
2201 PHP_HTTP_API STATUS
_http_auth_header(const char *type
, const char *realm TSRMLS_DC
)
2203 char realm_header
[1024] = {0};
2204 snprintf(realm_header
, 1023, "WWW-Authenticate: %s realm=\"%s\"", type
, realm
);
2205 return http_send_status_header(401, realm_header
);
2209 /* {{{ STATUS http_auth_credentials(char **, char **) */
2210 PHP_HTTP_API STATUS
_http_auth_credentials(char **user
, char **pass TSRMLS_DC
)
2212 if (strncmp(sapi_module
.name
, "isapi", 5)) {
2213 zval
*zuser
, *zpass
;
2215 HTTP_GSC(zuser
, "PHP_AUTH_USER", FAILURE
);
2216 HTTP_GSC(zpass
, "PHP_AUTH_PW", FAILURE
);
2218 *user
= estrndup(Z_STRVAL_P(zuser
), Z_STRLEN_P(zuser
));
2219 *pass
= estrndup(Z_STRVAL_P(zpass
), Z_STRLEN_P(zpass
));
2224 HTTP_GSC(zauth
, "HTTP_AUTHORIZATION", FAILURE
);
2226 char *decoded
, *colon
;
2228 decoded
= php_base64_decode(Z_STRVAL_P(zauth
), Z_STRLEN_P(zauth
),
2231 if (colon
= strchr(decoded
+ 6, ':')) {
2232 *user
= estrndup(decoded
+ 6, colon
- decoded
- 6);
2233 *pass
= estrndup(colon
+ 1, decoded
+ decoded_len
- colon
- 6 - 1);
2244 /* }}} public API */
2251 * vim600: noet sw=4 ts=4 fdm=marker
2252 * vim<600: noet sw=4 ts=4