ae27b5ea7f213ad46bb174b6a70c060b933c7ff1
[m6w6/ext-http] / http_functions.c
1 /*
2 +----------------------------------------------------------------------+
3 | PECL :: http |
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 +----------------------------------------------------------------------+
14 */
15
16 /* $Id$ */
17
18 #ifdef HAVE_CONFIG_H
19 # include "config.h"
20 #endif
21 #include "php.h"
22
23 #include "SAPI.h"
24 #include "php_ini.h"
25 #include "ext/standard/info.h"
26 #include "ext/standard/php_string.h"
27 #if defined(HAVE_PHP_SESSION) && !defined(COMPILE_DL_SESSION)
28 # include "ext/session/php_session.h"
29 #endif
30
31 #include "php_http.h"
32 #include "php_http_std_defs.h"
33 #include "php_http_api.h"
34 #include "php_http_auth_api.h"
35 #include "php_http_request_api.h"
36 #include "php_http_cache_api.h"
37 #include "php_http_request_api.h"
38 #include "php_http_date_api.h"
39 #include "php_http_headers_api.h"
40 #include "php_http_message_api.h"
41 #include "php_http_send_api.h"
42 #include "php_http_url_api.h"
43
44 #include "phpstr/phpstr.h"
45
46 ZEND_EXTERN_MODULE_GLOBALS(http)
47
48 /* {{{ proto string http_date([int timestamp])
49 *
50 * This function returns a valid HTTP date regarding RFC 822/1123
51 * looking like: "Wed, 22 Dec 2004 11:34:47 GMT"
52 *
53 */
54 PHP_FUNCTION(http_date)
55 {
56 long t = -1;
57
58 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &t) != SUCCESS) {
59 RETURN_FALSE;
60 }
61
62 if (t == -1) {
63 t = (long) time(NULL);
64 }
65
66 RETURN_STRING(http_date(t), 0);
67 }
68 /* }}} */
69
70 /* {{{ proto string http_absolute_uri(string url[, string proto[, string host[, int port]]])
71 *
72 * This function returns an absolute URI constructed from url.
73 * If the url is already abolute but a different proto was supplied,
74 * only the proto part of the URI will be updated. If url has no
75 * path specified, the path of the current REQUEST_URI will be taken.
76 * The host will be taken either from the Host HTTP header of the client
77 * the SERVER_NAME or just localhost if prior are not available.
78 *
79 * Some examples:
80 * <pre>
81 * url = "page.php" => http://www.example.com/current/path/page.php
82 * url = "/page.php" => http://www.example.com/page.php
83 * url = "/page.php", proto = "https" => https://www.example.com/page.php
84 * </pre>
85 *
86 */
87 PHP_FUNCTION(http_absolute_uri)
88 {
89 char *url = NULL, *proto = NULL, *host = NULL;
90 int url_len = 0, proto_len = 0, host_len = 0;
91 long port = 0;
92
93 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|ssl", &url, &url_len, &proto, &proto_len, &host, &host_len, &port) != SUCCESS) {
94 RETURN_FALSE;
95 }
96
97 RETURN_STRING(http_absolute_uri_ex(url, url_len, proto, proto_len, host, host_len, port), 0);
98 }
99 /* }}} */
100
101 /* {{{ proto string http_negotiate_language(array supported[, string default = 'en-US'])
102 *
103 * This function negotiates the clients preferred language based on its
104 * Accept-Language HTTP header. It returns the negotiated language or
105 * the default language if none match.
106 *
107 * The qualifier is recognized and languages without qualifier are rated highest.
108 *
109 * The supported parameter is expected to be an array having
110 * the supported languages as array values.
111 *
112 * Example:
113 * <pre>
114 * <?php
115 * $langs = array(
116 * 'en-US',// default
117 * 'fr',
118 * 'fr-FR',
119 * 'de',
120 * 'de-DE',
121 * 'de-AT',
122 * 'de-CH',
123 * );
124 * include './langs/'. http_negotiate_language($langs) .'.php';
125 * ?>
126 * </pre>
127 *
128 */
129 PHP_FUNCTION(http_negotiate_language)
130 {
131 zval *supported;
132 char *def = NULL;
133 int def_len = 0;
134
135 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a|s", &supported, &def, &def_len) != SUCCESS) {
136 RETURN_FALSE;
137 }
138
139 if (!def) {
140 def = "en-US";
141 }
142
143 RETURN_STRING(http_negotiate_language(supported, def), 0);
144 }
145 /* }}} */
146
147 /* {{{ proto string http_negotiate_charset(array supported[, string default = 'iso-8859-1'])
148 *
149 * This function negotiates the clients preferred charset based on its
150 * Accept-Charset HTTP header. It returns the negotiated charset or
151 * the default charset if none match.
152 *
153 * The qualifier is recognized and charset without qualifier are rated highest.
154 *
155 * The supported parameter is expected to be an array having
156 * the supported charsets as array values.
157 *
158 * Example:
159 * <pre>
160 * <?php
161 * $charsets = array(
162 * 'iso-8859-1', // default
163 * 'iso-8859-2',
164 * 'iso-8859-15',
165 * 'utf-8'
166 * );
167 * $pref = http_negotiate_charset($charsets);
168 * if (!strcmp($pref, 'iso-8859-1')) {
169 * iconv_set_encoding('internal_encoding', 'iso-8859-1');
170 * iconv_set_encoding('output_encoding', $pref);
171 * ob_start('ob_iconv_handler');
172 * }
173 * ?>
174 * </pre>
175 */
176 PHP_FUNCTION(http_negotiate_charset)
177 {
178 zval *supported;
179 char *def = NULL;
180 int def_len = 0;
181
182 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a|s", &supported, &def, &def_len) != SUCCESS) {
183 RETURN_FALSE;
184 }
185
186 if (!def) {
187 def = "iso-8859-1";
188 }
189
190 RETURN_STRING(http_negotiate_charset(supported, def), 0);
191 }
192 /* }}} */
193
194 /* {{{ proto bool http_send_status(int status)
195 *
196 * Send HTTP status code.
197 *
198 */
199 PHP_FUNCTION(http_send_status)
200 {
201 int status = 0;
202
203 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &status) != SUCCESS) {
204 RETURN_FALSE;
205 }
206 if (status < 100 || status > 510) {
207 http_error_ex(HE_WARNING, HTTP_E_HEADER, "Invalid HTTP status code (100-510): %d", status);
208 RETURN_FALSE;
209 }
210
211 RETURN_SUCCESS(http_send_status(status));
212 }
213 /* }}} */
214
215 /* {{{ proto bool http_send_last_modified([int timestamp])
216 *
217 * This converts the given timestamp to a valid HTTP date and
218 * sends it as "Last-Modified" HTTP header. If timestamp is
219 * omitted, current time is sent.
220 *
221 */
222 PHP_FUNCTION(http_send_last_modified)
223 {
224 long t = -1;
225
226 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &t) != SUCCESS) {
227 RETURN_FALSE;
228 }
229
230 if (t == -1) {
231 t = (long) time(NULL);
232 }
233
234 RETURN_SUCCESS(http_send_last_modified(t));
235 }
236 /* }}} */
237
238 /* {{{ proto bool http_send_content_type([string content_type = 'application/x-octetstream'])
239 *
240 * Sets the content type.
241 *
242 */
243 PHP_FUNCTION(http_send_content_type)
244 {
245 char *ct;
246 int ct_len = 0;
247
248 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &ct, &ct_len) != SUCCESS) {
249 RETURN_FALSE;
250 }
251
252 if (!ct_len) {
253 RETURN_SUCCESS(http_send_content_type("application/x-octetstream", lenof("application/x-octetstream")));
254 }
255 RETURN_SUCCESS(http_send_content_type(ct, ct_len));
256 }
257 /* }}} */
258
259 /* {{{ proto bool http_send_content_disposition(string filename[, bool inline = false])
260 *
261 * Set the Content Disposition. The Content-Disposition header is very useful
262 * if the data actually sent came from a file or something similar, that should
263 * be "saved" by the client/user (i.e. by browsers "Save as..." popup window).
264 *
265 */
266 PHP_FUNCTION(http_send_content_disposition)
267 {
268 char *filename;
269 int f_len;
270 zend_bool send_inline = 0;
271
272 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|b", &filename, &f_len, &send_inline) != SUCCESS) {
273 RETURN_FALSE;
274 }
275 RETURN_SUCCESS(http_send_content_disposition(filename, f_len, send_inline));
276 }
277 /* }}} */
278
279 /* {{{ proto bool http_match_modified([int timestamp[, for_range = false]])
280 *
281 * Matches the given timestamp against the clients "If-Modified-Since" resp.
282 * "If-Unmodified-Since" HTTP headers.
283 *
284 */
285 PHP_FUNCTION(http_match_modified)
286 {
287 long t = -1;
288 zend_bool for_range = 0;
289
290 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|lb", &t, &for_range) != SUCCESS) {
291 RETURN_FALSE;
292 }
293
294 // current time if not supplied (senseless though)
295 if (t == -1) {
296 t = (long) time(NULL);
297 }
298
299 if (for_range) {
300 RETURN_BOOL(http_match_last_modified("HTTP_IF_UNMODIFIED_SINCE", t));
301 }
302 RETURN_BOOL(http_match_last_modified("HTTP_IF_MODIFIED_SINCE", t));
303 }
304 /* }}} */
305
306 /* {{{ proto bool http_match_etag(string etag[, for_range = false])
307 *
308 * This matches the given ETag against the clients
309 * "If-Match" resp. "If-None-Match" HTTP headers.
310 *
311 */
312 PHP_FUNCTION(http_match_etag)
313 {
314 int etag_len;
315 char *etag;
316 zend_bool for_range = 0;
317
318 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|b", &etag, &etag_len, &for_range) != SUCCESS) {
319 RETURN_FALSE;
320 }
321
322 if (for_range) {
323 RETURN_BOOL(http_match_etag("HTTP_IF_MATCH", etag));
324 }
325 RETURN_BOOL(http_match_etag("HTTP_IF_NONE_MATCH", etag));
326 }
327 /* }}} */
328
329 /* {{{ proto bool http_cache_last_modified([int timestamp_or_expires]])
330 *
331 * If timestamp_or_expires is greater than 0, it is handled as timestamp
332 * and will be sent as date of last modification. If it is 0 or omitted,
333 * the current time will be sent as Last-Modified date. If it's negative,
334 * it is handled as expiration time in seconds, which means that if the
335 * requested last modification date is not between the calculated timespan,
336 * the Last-Modified header is updated and the actual body will be sent.
337 *
338 */
339 PHP_FUNCTION(http_cache_last_modified)
340 {
341 long last_modified = 0, send_modified = 0, t;
342 zval *zlm;
343
344 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &last_modified) != SUCCESS) {
345 RETURN_FALSE;
346 }
347
348 t = (long) time(NULL);
349
350 /* 0 or omitted */
351 if (!last_modified) {
352 /* does the client have? (att: caching "forever") */
353 if (zlm = http_get_server_var("HTTP_IF_MODIFIED_SINCE")) {
354 last_modified = send_modified = http_parse_date(Z_STRVAL_P(zlm));
355 /* send current time */
356 } else {
357 send_modified = t;
358 }
359 /* negative value is supposed to be expiration time */
360 } else if (last_modified < 0) {
361 last_modified += t;
362 send_modified = t;
363 /* send supplied time explicitly */
364 } else {
365 send_modified = last_modified;
366 }
367
368 RETURN_SUCCESS(http_cache_last_modified(last_modified, send_modified, HTTP_DEFAULT_CACHECONTROL, lenof(HTTP_DEFAULT_CACHECONTROL)));
369 }
370 /* }}} */
371
372 /* {{{ proto bool http_cache_etag([string etag])
373 *
374 * This function attempts to cache the HTTP body based on an ETag,
375 * either supplied or generated through calculation of the MD5
376 * checksum of the output (uses output buffering).
377 *
378 * If clients "If-None-Match" header matches the supplied/calculated
379 * ETag, the body is considered cached on the clients side and
380 * a "304 Not Modified" status code is issued.
381 *
382 */
383 PHP_FUNCTION(http_cache_etag)
384 {
385 char *etag = NULL;
386 int etag_len = 0;
387
388 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &etag, &etag_len) != SUCCESS) {
389 RETURN_FALSE;
390 }
391
392 RETURN_SUCCESS(http_cache_etag(etag, etag_len, HTTP_DEFAULT_CACHECONTROL, lenof(HTTP_DEFAULT_CACHECONTROL)));
393 }
394 /* }}} */
395
396 /* {{{ proto string ob_etaghandler(string data, int mode)
397 *
398 * For use with ob_start().
399 */
400 PHP_FUNCTION(ob_etaghandler)
401 {
402 char *data;
403 int data_len;
404 long mode;
405
406 if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sl", &data, &data_len, &mode)) {
407 RETURN_FALSE;
408 }
409
410 Z_TYPE_P(return_value) = IS_STRING;
411 http_ob_etaghandler(data, data_len, &Z_STRVAL_P(return_value), &Z_STRLEN_P(return_value), mode);
412 }
413 /* }}} */
414
415 /* {{{ proto void http_throttle(double sec[, long bytes = 2097152])
416 *
417 * Use with http_send() API.
418 *
419 * Example:
420 * <pre>
421 * <?php
422 * // ~ 20 kbyte/s
423 * # http_throttle(1, 20000);
424 * # http_throttle(0.5, 10000);
425 * # http_throttle(0.1, 2000);
426 * http_send_file('document.pdf');
427 * ?>
428 * </pre>
429 */
430 PHP_FUNCTION(http_throttle)
431 {
432 long chunk_size;
433 double interval;
434
435 if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "dl", &interval, &chunk_size)) {
436 return;
437 }
438
439 HTTP_G(send).throttle_delay = interval;
440 HTTP_G(send).buffer_size = chunk_size;
441 }
442 /* }}} */
443
444 /* {{{ proto void http_redirect([string url[, array params[, bool session,[ bool permanent]]]])
445 *
446 * Redirect to a given url.
447 * The supplied url will be expanded with http_absolute_uri(), the params array will
448 * be treated with http_build_query() and the session identification will be appended
449 * if session is true.
450 *
451 * Depending on permanent the redirection will be issued with a permanent
452 * ("301 Moved Permanently") or a temporary ("302 Found") redirection
453 * status code.
454 *
455 * To be RFC compliant, "Redirecting to <a>URI</a>." will be displayed,
456 * if the client doesn't redirect immediatly.
457 */
458 PHP_FUNCTION(http_redirect)
459 {
460 int url_len;
461 size_t query_len = 0;
462 zend_bool session = 0, permanent = 0, free_params = 0;
463 zval *params = NULL;
464 char *query = NULL, *url = NULL, *URI,
465 LOC[HTTP_URI_MAXLEN + sizeof("Location: ")],
466 RED[HTTP_URI_MAXLEN * 2 + sizeof("Redirecting to <a href=\"%s?%s\">%s?%s</a>.\n")];
467
468 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|sa!/bb", &url, &url_len, &params, &session, &permanent) != SUCCESS) {
469 RETURN_FALSE;
470 }
471
472 /* append session info */
473 if (session) {
474 if (!params) {
475 free_params = 1;
476 MAKE_STD_ZVAL(params);
477 array_init(params);
478 }
479 #ifdef HAVE_PHP_SESSION
480 # ifdef COMPILE_DL_SESSION
481 if (SUCCESS == zend_get_module_started("session")) {
482 zval nm_retval, id_retval, func;
483
484 INIT_PZVAL(&func);
485 INIT_PZVAL(&nm_retval);
486 INIT_PZVAL(&id_retval);
487 ZVAL_NULL(&nm_retval);
488 ZVAL_NULL(&id_retval);
489
490 ZVAL_STRINGL(&func, "session_id", lenof("session_id"), 0);
491 call_user_function(EG(function_table), NULL, &func, &id_retval, 0, NULL TSRMLS_CC);
492 ZVAL_STRINGL(&func, "session_name", lenof("session_name"), 0);
493 call_user_function(EG(function_table), NULL, &func, &nm_retval, 0, NULL TSRMLS_CC);
494
495 if ( Z_TYPE(nm_retval) == IS_STRING && Z_STRLEN(nm_retval) &&
496 Z_TYPE(id_retval) == IS_STRING && Z_STRLEN(id_retval)) {
497 if (add_assoc_stringl_ex(params, Z_STRVAL(nm_retval), Z_STRLEN(nm_retval)+1,
498 Z_STRVAL(id_retval), Z_STRLEN(id_retval), 0) != SUCCESS) {
499 http_error(HE_WARNING, HTTP_E_RUNTIME, "Could not append session information");
500 }
501 }
502 }
503 # else
504 if (PS(session_status) == php_session_active) {
505 if (add_assoc_string(params, PS(session_name), PS(id), 1) != SUCCESS) {
506 http_error(HE_WARNING, HTTP_E_RUNTIME, "Could not append session information");
507 }
508 }
509 # endif
510 #endif
511 }
512
513 /* treat params array with http_build_query() */
514 if (params) {
515 if (SUCCESS != http_urlencode_hash_ex(Z_ARRVAL_P(params), 0, NULL, 0, &query, &query_len)) {
516 if (free_params) {
517 zval_dtor(params);
518 FREE_ZVAL(params);
519 }
520 if (query) {
521 efree(query);
522 }
523 RETURN_FALSE;
524 }
525 }
526
527 URI = http_absolute_uri(url);
528
529 if (query_len) {
530 snprintf(LOC, HTTP_URI_MAXLEN + sizeof("Location: "), "Location: %s?%s", URI, query);
531 sprintf(RED, "Redirecting to <a href=\"%s?%s\">%s?%s</a>.\n", URI, query, URI, query);
532 } else {
533 snprintf(LOC, HTTP_URI_MAXLEN + sizeof("Location: "), "Location: %s", URI);
534 sprintf(RED, "Redirecting to <a href=\"%s\">%s</a>.\n", URI, URI);
535 }
536
537 efree(URI);
538 if (query) {
539 efree(query);
540 }
541 if (free_params) {
542 zval_dtor(params);
543 FREE_ZVAL(params);
544 }
545
546 if ((SUCCESS == http_send_header_string(LOC)) && (SUCCESS == http_send_status((permanent ? 301 : 302)))) {
547 if (SG(request_info).request_method && strcmp(SG(request_info).request_method, "HEAD")) {
548 PHPWRITE(RED, strlen(RED));
549 }
550 RETURN_TRUE;
551 }
552 RETURN_FALSE;
553 }
554 /* }}} */
555
556 /* {{{ proto bool http_send_data(string data)
557 *
558 * Sends raw data with support for (multiple) range requests.
559 *
560 */
561 PHP_FUNCTION(http_send_data)
562 {
563 zval *zdata;
564
565 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &zdata) != SUCCESS) {
566 RETURN_FALSE;
567 }
568
569 convert_to_string_ex(&zdata);
570 RETURN_SUCCESS(http_send_data(Z_STRVAL_P(zdata), Z_STRLEN_P(zdata)));
571 }
572 /* }}} */
573
574 /* {{{ proto bool http_send_file(string file)
575 *
576 * Sends a file with support for (multiple) range requests.
577 *
578 */
579 PHP_FUNCTION(http_send_file)
580 {
581 char *file;
582 int flen = 0;
583
584 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &file, &flen) != SUCCESS) {
585 RETURN_FALSE;
586 }
587 if (!flen) {
588 RETURN_FALSE;
589 }
590
591 RETURN_SUCCESS(http_send_file(file));
592 }
593 /* }}} */
594
595 /* {{{ proto bool http_send_stream(resource stream)
596 *
597 * Sends an already opened stream with support for (multiple) range requests.
598 *
599 */
600 PHP_FUNCTION(http_send_stream)
601 {
602 zval *zstream;
603 php_stream *file;
604
605 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zstream) != SUCCESS) {
606 RETURN_FALSE;
607 }
608
609 php_stream_from_zval(file, &zstream);
610 RETURN_SUCCESS(http_send_stream(file));
611 }
612 /* }}} */
613
614 /* {{{ proto string http_chunked_decode(string encoded)
615 *
616 * This function decodes a string that was HTTP-chunked encoded.
617 * Returns false on failure.
618 */
619 PHP_FUNCTION(http_chunked_decode)
620 {
621 char *encoded = NULL, *decoded = NULL;
622 int encoded_len = 0, decoded_len = 0;
623
624 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &encoded, &encoded_len) != SUCCESS) {
625 RETURN_FALSE;
626 }
627
628 if (NULL != http_chunked_decode(encoded, encoded_len, &decoded, &decoded_len)) {
629 RETURN_STRINGL(decoded, decoded_len, 0);
630 } else {
631 RETURN_FALSE;
632 }
633 }
634 /* }}} */
635
636 /* {{{ proto array http_split_response(string http_response)
637 *
638 * This function splits an HTTP response into an array with headers and the
639 * content body. The returned array may look simliar to the following example:
640 *
641 * <pre>
642 * <?php
643 * array(
644 * 0 => array(
645 * 'Response Status' => '200 Ok',
646 * 'Content-Type' => 'text/plain',
647 * 'Content-Language' => 'en-US'
648 * ),
649 * 1 => "Hello World!"
650 * );
651 * ?>
652 * </pre>
653 */
654 PHP_FUNCTION(http_split_response)
655 {
656 char *response, *body;
657 int response_len;
658 size_t body_len;
659 zval *zheaders;
660
661 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &response, &response_len) != SUCCESS) {
662 RETURN_FALSE;
663 }
664
665 MAKE_STD_ZVAL(zheaders);
666 array_init(zheaders);
667
668 if (SUCCESS != http_split_response(response, response_len, Z_ARRVAL_P(zheaders), &body, &body_len)) {
669 RETURN_FALSE;
670 }
671
672 array_init(return_value);
673 add_index_zval(return_value, 0, zheaders);
674 add_index_stringl(return_value, 1, body, body_len, 0);
675 }
676 /* }}} */
677
678 static void http_message_toobject_recursive(http_message *msg, zval *obj TSRMLS_DC)
679 {
680 zval *headers;
681
682 add_property_long(obj, "type", msg->type);
683 switch (msg->type)
684 {
685 case HTTP_MSG_RESPONSE:
686 add_property_double(obj, "httpVersion", msg->info.response.http_version);
687 add_property_long(obj, "responseCode", msg->info.response.code);
688 break;
689
690 case HTTP_MSG_REQUEST:
691 add_property_double(obj, "httpVersion", msg->info.request.http_version);
692 add_property_string(obj, "requestMethod", msg->info.request.method, 1);
693 add_property_string(obj, "requestUri", msg->info.request.URI, 1);
694 break;
695 }
696
697 MAKE_STD_ZVAL(headers);
698 array_init(headers);
699 zend_hash_copy(Z_ARRVAL_P(headers), &msg->hdrs, (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *));
700 add_property_zval(obj, "headers", headers);
701 zval_ptr_dtor(&headers);
702
703 add_property_stringl(obj, "body", PHPSTR_VAL(msg), PHPSTR_LEN(msg), 1);
704
705 if (msg->parent) {
706 zval *parent;
707
708 MAKE_STD_ZVAL(parent);
709 object_init(parent);
710 add_property_zval(obj, "parentMessage", parent);
711 http_message_toobject_recursive(msg->parent, parent TSRMLS_CC);
712 zval_ptr_dtor(&parent);
713 } else {
714 add_property_null(obj, "parentMessage");
715 }
716 http_message_dtor(msg);
717 efree(msg);
718 }
719
720 /* {{{ proto object http_parse_message(string message)
721 *
722 * Parses (a) http_message(s) into a simple recursive object structure:
723 *
724 * <pre>
725 * <?php
726 * print_r(http_parse_message(http_get(URL, array('redirect' => 3)));
727 *
728 * stdClass object
729 * (
730 * [type] => 2
731 * [httpVersion] => 1.1
732 * [responseCode] => 200
733 * [headers] => Array
734 * (
735 * [Content-Length] => 3
736 * [Server] => Apache
737 * )
738 * [body] => Hi!
739 * [parentMessage] => stdClass object
740 * (
741 * [type] => 2
742 * [httpVersion] => 1.1
743 * [responseCode] => 302
744 * [headers] => Array
745 * (
746 * [Content-Length] => 0
747 * [Location] => ...
748 * )
749 * [body] =>
750 * [parentMessage] => ...
751 * )
752 * )
753 * ?>
754 * </pre>
755 */
756 PHP_FUNCTION(http_parse_message)
757 {
758 char *message;
759 int message_len;
760 http_message *msg = NULL;
761
762 if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &message, &message_len)) {
763 RETURN_NULL();
764 }
765
766
767 if (msg = http_message_parse(message, message_len)) {
768 object_init(return_value);
769 http_message_toobject_recursive(msg, return_value TSRMLS_CC);
770 } else {
771 RETURN_NULL();
772 }
773 }
774 /* }}} */
775
776 /* {{{ proto array http_parse_headers(string header)
777 *
778 */
779 PHP_FUNCTION(http_parse_headers)
780 {
781 char *header;
782 int header_len;
783
784 if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &header, &header_len)) {
785 RETURN_FALSE;
786 }
787
788 array_init(return_value);
789 if (SUCCESS != http_parse_headers(header, return_value)) {
790 zval_dtor(return_value);
791 RETURN_FALSE;
792 }
793 }
794 /* }}}*/
795
796 /* {{{ proto array http_get_request_headers(void)
797 *
798 * Get a list of incoming HTTP headers.
799 */
800 PHP_FUNCTION(http_get_request_headers)
801 {
802 NO_ARGS;
803
804 array_init(return_value);
805 http_get_request_headers(return_value);
806 }
807 /* }}} */
808
809 /* {{{ proto string http_get_request_body(void)
810 *
811 * Get the raw request body (e.g. POST or PUT data).
812 */
813 PHP_FUNCTION(http_get_request_body)
814 {
815 char *body;
816 size_t length;
817
818 NO_ARGS;
819
820 if (SUCCESS == http_get_request_body(&body, &length)) {
821 RETURN_STRINGL(body, (int) length, 0);
822 } else {
823 RETURN_NULL();
824 }
825 }
826 /* }}} */
827
828 /* {{{ proto bool http_match_request_header(string header, string value[, bool match_case = false])
829 *
830 * Match an incoming HTTP header.
831 */
832 PHP_FUNCTION(http_match_request_header)
833 {
834 char *header, *value;
835 int header_len, value_len;
836 zend_bool match_case = 0;
837
838 if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|b", &header, &header_len, &value, &value_len, &match_case)) {
839 RETURN_FALSE;
840 }
841
842 RETURN_BOOL(http_match_request_header_ex(header, value, match_case));
843 }
844 /* }}} */
845
846 /* {{{ HAVE_CURL */
847 #ifdef HTTP_HAVE_CURL
848
849 /* {{{ proto string http_get(string url[, array options[, array &info]])
850 *
851 * Performs an HTTP GET request on the supplied url.
852 *
853 * The second parameter is expected to be an associative
854 * array where the following keys will be recognized:
855 * <pre>
856 * - redirect: int, whether and how many redirects to follow
857 * - unrestrictedauth: bool, whether to continue sending credentials on
858 * redirects to a different host
859 * - proxyhost: string, proxy host in "host[:port]" format
860 * - proxyport: int, use another proxy port as specified in proxyhost
861 * - proxyauth: string, proxy credentials in "user:pass" format
862 * - proxyauthtype: int, HTTP_AUTH_BASIC and/or HTTP_AUTH_NTLM
863 * - httpauth: string, http credentials in "user:pass" format
864 * - httpauthtype: int, HTTP_AUTH_BASIC, DIGEST and/or NTLM
865 * - compress: bool, whether to allow gzip/deflate content encoding
866 * (defaults to true)
867 * - port: int, use another port as specified in the url
868 * - referer: string, the referer to sends
869 * - useragent: string, the user agent to send
870 * (defaults to PECL::HTTP/version (PHP/version)))
871 * - headers: array, list of custom headers as associative array
872 * like array("header" => "value")
873 * - cookies: array, list of cookies as associative array
874 * like array("cookie" => "value")
875 * - cookiestore: string, path to a file where cookies are/will be stored
876 * - resume: int, byte offset to start the download from;
877 * if the server supports ranges
878 * - maxfilesize: int, maximum file size that should be downloaded;
879 * has no effect, if the size of the requested entity is not known
880 * - lastmodified: int, timestamp for If-(Un)Modified-Since header
881 * - timeout: int, seconds the request may take
882 * - connecttimeout: int, seconds the connect may take
883 * - onprogress: mixed, progress callback
884 * </pre>
885 *
886 * The optional third parameter will be filled with some additional information
887 * in form af an associative array, if supplied, like the following example:
888 * <pre>
889 * <?php
890 * array (
891 * 'effective_url' => 'http://localhost',
892 * 'response_code' => 403,
893 * 'total_time' => 0.017,
894 * 'namelookup_time' => 0.013,
895 * 'connect_time' => 0.014,
896 * 'pretransfer_time' => 0.014,
897 * 'size_upload' => 0,
898 * 'size_download' => 202,
899 * 'speed_download' => 11882,
900 * 'speed_upload' => 0,
901 * 'header_size' => 145,
902 * 'request_size' => 62,
903 * 'ssl_verifyresult' => 0,
904 * 'filetime' => -1,
905 * 'content_length_download' => 202,
906 * 'content_length_upload' => 0,
907 * 'starttransfer_time' => 0.017,
908 * 'content_type' => 'text/html; charset=iso-8859-1',
909 * 'redirect_time' => 0,
910 * 'redirect_count' => 0,
911 * 'private' => '',
912 * 'http_connectcode' => 0,
913 * 'httpauth_avail' => 0,
914 * 'proxyauth_avail' => 0,
915 * )
916 * ?>
917 * </pre>
918 */
919 PHP_FUNCTION(http_get)
920 {
921 zval *options = NULL, *info = NULL;
922 char *URL;
923 int URL_len;
924 phpstr response;
925
926 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|a/!z", &URL, &URL_len, &options, &info) != SUCCESS) {
927 RETURN_FALSE;
928 }
929
930 if (info) {
931 zval_dtor(info);
932 array_init(info);
933 }
934
935 phpstr_init_ex(&response, HTTP_CURLBUF_SIZE, 0);
936 if (SUCCESS == http_get(URL, options ? Z_ARRVAL_P(options) : NULL, info ? Z_ARRVAL_P(info) : NULL, &response)) {
937 RETURN_PHPSTR_VAL(response);
938 } else {
939 RETURN_FALSE;
940 }
941 }
942 /* }}} */
943
944 /* {{{ proto string http_head(string url[, array options[, array &info]])
945 *
946 * Performs an HTTP HEAD request on the suppied url.
947 * Returns the HTTP response as string.
948 * See http_get() for a full list of available options.
949 */
950 PHP_FUNCTION(http_head)
951 {
952 zval *options = NULL, *info = NULL;
953 char *URL;
954 int URL_len;
955 phpstr response;
956
957 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|a/!z", &URL, &URL_len, &options, &info) != SUCCESS) {
958 RETURN_FALSE;
959 }
960
961 if (info) {
962 zval_dtor(info);
963 array_init(info);
964 }
965
966 phpstr_init_ex(&response, HTTP_CURLBUF_SIZE, 0);
967 if (SUCCESS == http_head(URL, options ? Z_ARRVAL_P(options) : NULL, info ? Z_ARRVAL_P(info) : NULL, &response)) {
968 RETURN_PHPSTR_VAL(response);
969 } else {
970 RETURN_FALSE;
971 }
972 }
973 /* }}} */
974
975 /* {{{ proto string http_post_data(string url, string data[, array options[, &info]])
976 *
977 * Performs an HTTP POST request, posting data.
978 * Returns the HTTP response as string.
979 * See http_get() for a full list of available options.
980 */
981 PHP_FUNCTION(http_post_data)
982 {
983 zval *options = NULL, *info = NULL;
984 char *URL, *postdata;
985 int postdata_len, URL_len;
986 phpstr response;
987 http_request_body body;
988
989 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|a/!z", &URL, &URL_len, &postdata, &postdata_len, &options, &info) != SUCCESS) {
990 RETURN_FALSE;
991 }
992
993 if (info) {
994 zval_dtor(info);
995 array_init(info);
996 }
997
998 body.type = HTTP_REQUEST_BODY_CSTRING;
999 body.data = postdata;
1000 body.size = postdata_len;
1001
1002 phpstr_init_ex(&response, HTTP_CURLBUF_SIZE, 0);
1003 if (SUCCESS == http_post(URL, &body, options ? Z_ARRVAL_P(options) : NULL, info ? Z_ARRVAL_P(info) : NULL, &response)) {
1004 RETVAL_PHPSTR_VAL(response);
1005 } else {
1006 RETVAL_FALSE;
1007 }
1008 }
1009 /* }}} */
1010
1011 /* {{{ proto string http_post_fields(string url, array data[, array files[, array options[, array &info]]])
1012 *
1013 * Performs an HTTP POST request, posting www-form-urlencoded array data.
1014 * Returns the HTTP response as string.
1015 * See http_get() for a full list of available options.
1016 */
1017 PHP_FUNCTION(http_post_fields)
1018 {
1019 zval *options = NULL, *info = NULL, *fields, *files = NULL;
1020 char *URL;
1021 int URL_len;
1022 phpstr response;
1023 http_request_body body;
1024
1025 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sa|aa/!z", &URL, &URL_len, &fields, &files, &options, &info) != SUCCESS) {
1026 RETURN_FALSE;
1027 }
1028
1029 if (SUCCESS != http_request_body_fill(&body, Z_ARRVAL_P(fields), files ? Z_ARRVAL_P(files) : NULL)) {
1030 RETURN_FALSE;
1031 }
1032
1033 if (info) {
1034 zval_dtor(info);
1035 array_init(info);
1036 }
1037
1038 phpstr_init_ex(&response, HTTP_CURLBUF_SIZE, 0);
1039 if (SUCCESS == http_post(URL, &body, options ? Z_ARRVAL_P(options) : NULL, info ? Z_ARRVAL_P(info) : NULL, &response)) {
1040 RETVAL_PHPSTR_VAL(response);
1041 } else {
1042 RETVAL_FALSE;
1043 }
1044 http_request_body_dtor(&body);
1045 }
1046 /* }}} */
1047
1048 /* {{{ proto string http_put_file(string url, string file[, array options[, array &info]])
1049 *
1050 * Performs an HTTP PUT request, uploading file.
1051 * Returns the HTTP response as string.
1052 * See http_get() for a full list of available options.
1053 */
1054 PHP_FUNCTION(http_put_file)
1055 {
1056 char *URL, *file;
1057 int URL_len, f_len;
1058 zval *options = NULL, *info = NULL;
1059 phpstr response;
1060 php_stream *stream;
1061 php_stream_statbuf ssb;
1062 http_request_body body;
1063
1064 if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|a/!z", &URL, &URL_len, &file, &f_len, &options, &info)) {
1065 RETURN_FALSE;
1066 }
1067
1068 if (!(stream = php_stream_open_wrapper(file, "rb", REPORT_ERRORS|ENFORCE_SAFE_MODE, NULL))) {
1069 RETURN_FALSE;
1070 }
1071 if (php_stream_stat(stream, &ssb)) {
1072 php_stream_close(stream);
1073 RETURN_FALSE;
1074 }
1075
1076 if (info) {
1077 zval_dtor(info);
1078 array_init(info);
1079 }
1080
1081 body.type = HTTP_REQUEST_BODY_UPLOADFILE;
1082 body.data = stream;
1083 body.size = ssb.sb.st_size;
1084
1085 phpstr_init_ex(&response, HTTP_CURLBUF_SIZE, 0);
1086 if (SUCCESS == http_put(URL, &body, options ? Z_ARRVAL_P(options) : NULL, info ? Z_ARRVAL_P(info) : NULL, &response)) {
1087 RETVAL_PHPSTR_VAL(response);
1088 } else {
1089 RETVAL_FALSE;
1090 }
1091 http_request_body_dtor(&body);
1092 }
1093 /* }}} */
1094
1095 /* {{{ proto string http_put_stream(string url, resource stream[, array options[, array &info]])
1096 *
1097 * Performs an HTTP PUT request, uploading stream.
1098 * Returns the HTTP response as string.
1099 * See http_get() for a full list of available options.
1100 */
1101 PHP_FUNCTION(http_put_stream)
1102 {
1103 zval *resource, *options = NULL, *info = NULL;
1104 char *URL;
1105 int URL_len;
1106 phpstr response;
1107 php_stream *stream;
1108 php_stream_statbuf ssb;
1109 http_request_body body;
1110
1111 if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sr|a/!z", &URL, &URL_len, &resource, &options, &info)) {
1112 RETURN_FALSE;
1113 }
1114
1115 php_stream_from_zval(stream, &resource);
1116 if (php_stream_stat(stream, &ssb)) {
1117 RETURN_FALSE;
1118 }
1119
1120 if (info) {
1121 zval_dtor(info);
1122 array_init(info);
1123 }
1124
1125 body.type = HTTP_REQUEST_BODY_UPLOADFILE;
1126 body.data = stream;
1127 body.size = ssb.sb.st_size;
1128
1129 phpstr_init_ex(&response, HTTP_CURLBUF_SIZE, 0);
1130 if (SUCCESS == http_put(URL, &body, options ? Z_ARRVAL_P(options) : NULL, info ? Z_ARRVAL_P(info) : NULL, &response)) {
1131 RETURN_PHPSTR_VAL(response);
1132 } else {
1133 RETURN_NULL();
1134 }
1135 }
1136 /* }}} */
1137
1138 /* {{{ proto long http_request_method_register(string method)
1139 *
1140 * Register a custom request method.
1141 */
1142 PHP_FUNCTION(http_request_method_register)
1143 {
1144 char *method;
1145 int *method_len;
1146 unsigned long existing;
1147
1148 if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &method, &method_len)) {
1149 RETURN_FALSE;
1150 }
1151 if (existing = http_request_method_exists(1, 0, method)) {
1152 RETURN_LONG((long) existing);
1153 }
1154
1155 RETVAL_LONG((long) http_request_method_register(method));
1156 }
1157 /* }}} */
1158
1159 /* {{{ proto bool http_request_method_unregister(mixed method)
1160 *
1161 * Unregister a previously registered custom request method.
1162 */
1163 PHP_FUNCTION(http_request_method_unregister)
1164 {
1165 zval *method;
1166
1167 if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z/", &method)) {
1168 RETURN_FALSE;
1169 }
1170
1171 switch (Z_TYPE_P(method))
1172 {
1173 case IS_OBJECT:
1174 convert_to_string(method);
1175 case IS_STRING:
1176 #include "zend_operators.h"
1177 if (is_numeric_string(Z_STRVAL_P(method), Z_STRLEN_P(method), NULL, NULL, 1)) {
1178 convert_to_long(method);
1179 } else {
1180 unsigned long mn;
1181 if (!(mn = http_request_method_exists(1, 0, Z_STRVAL_P(method)))) {
1182 RETURN_FALSE;
1183 }
1184 zval_dtor(method);
1185 ZVAL_LONG(method, (long)mn);
1186 }
1187 case IS_LONG:
1188 RETURN_SUCCESS(http_request_method_unregister(Z_LVAL_P(method)));
1189 default:
1190 RETURN_FALSE;
1191 }
1192 }
1193 /* }}} */
1194
1195 /* {{{ proto long http_request_method_exists(mixed method)
1196 *
1197 * Check if a request method is registered (or available by default).
1198 */
1199 PHP_FUNCTION(http_request_method_exists)
1200 {
1201 IF_RETVAL_USED {
1202 zval *method;
1203
1204 if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z/", &method)) {
1205 RETURN_FALSE;
1206 }
1207
1208 switch (Z_TYPE_P(method))
1209 {
1210 case IS_OBJECT:
1211 convert_to_string(method);
1212 case IS_STRING:
1213 if (is_numeric_string(Z_STRVAL_P(method), Z_STRLEN_P(method), NULL, NULL, 1)) {
1214 convert_to_long(method);
1215 } else {
1216 RETURN_LONG((long) http_request_method_exists(1, 0, Z_STRVAL_P(method)));
1217 }
1218 case IS_LONG:
1219 RETURN_LONG((long) http_request_method_exists(0, Z_LVAL_P(method), NULL));
1220 default:
1221 RETURN_FALSE;
1222 }
1223 }
1224 }
1225 /* }}} */
1226
1227 /* {{{ proto string http_request_method_name(long method)
1228 *
1229 * Get the literal string representation of a standard or registered request method.
1230 */
1231 PHP_FUNCTION(http_request_method_name)
1232 {
1233 IF_RETVAL_USED {
1234 long method;
1235
1236 if ((SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &method)) || (method < 0)) {
1237 RETURN_FALSE;
1238 }
1239
1240 RETURN_STRING(estrdup(http_request_method_name((unsigned long) method)), 0);
1241 }
1242 }
1243 /* }}} */
1244 #endif
1245 /* }}} HAVE_CURL */
1246
1247
1248 /* {{{ proto bool http_auth_basic(string user, string pass[, string realm = "Restricted"])
1249 *
1250 * Example:
1251 * <pre>
1252 * <?php
1253 * if (!http_auth_basic('mike', 's3c|r3t')) {
1254 * die('<h1>Authorization failed!</h1>');
1255 * }
1256 * ?>
1257 * </pre>
1258 */
1259 PHP_FUNCTION(http_auth_basic)
1260 {
1261 char *realm = NULL, *user, *pass, *suser, *spass;
1262 int r_len, u_len, p_len;
1263
1264 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|s", &user, &u_len, &pass, &p_len, &realm, &r_len) != SUCCESS) {
1265 RETURN_FALSE;
1266 }
1267
1268 if (!realm) {
1269 realm = "Restricted";
1270 }
1271
1272 if (SUCCESS != http_auth_basic_credentials(&suser, &spass)) {
1273 http_auth_basic_header(realm);
1274 RETURN_FALSE;
1275 }
1276
1277 if (strcasecmp(suser, user)) {
1278 http_auth_basic_header(realm);
1279 RETURN_FALSE;
1280 }
1281
1282 if (strcmp(spass, pass)) {
1283 http_auth_basic_header(realm);
1284 RETURN_FALSE;
1285 }
1286
1287 RETURN_TRUE;
1288 }
1289 /* }}} */
1290
1291 /* {{{ proto bool http_auth_basic_cb(mixed callback[, string realm = "Restricted"])
1292 *
1293 * Example:
1294 * <pre>
1295 * <?php
1296 * function auth_cb($user, $pass)
1297 * {
1298 * global $db;
1299 * $query = 'SELECT pass FROM users WHERE user='. $db->quoteSmart($user);
1300 * if (strlen($realpass = $db->getOne($query)) {
1301 * return $pass === $realpass;
1302 * }
1303 * return false;
1304 * }
1305 * if (!http_auth_basic_cb('auth_cb')) {
1306 * die('<h1>Authorization failed</h1>');
1307 * }
1308 * ?>
1309 * </pre>
1310 */
1311 PHP_FUNCTION(http_auth_basic_cb)
1312 {
1313 zval *cb;
1314 char *realm = NULL, *user, *pass;
1315 int r_len;
1316
1317 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|s", &cb, &realm, &r_len) != SUCCESS) {
1318 RETURN_FALSE;
1319 }
1320
1321 if (!realm) {
1322 realm = "Restricted";
1323 }
1324
1325 if (SUCCESS != http_auth_basic_credentials(&user, &pass)) {
1326 http_auth_basic_header(realm);
1327 RETURN_FALSE;
1328 }
1329 {
1330 zval *zparams[2] = {NULL, NULL}, retval;
1331 int result = 0;
1332
1333 MAKE_STD_ZVAL(zparams[0]);
1334 MAKE_STD_ZVAL(zparams[1]);
1335 ZVAL_STRING(zparams[0], user, 0);
1336 ZVAL_STRING(zparams[1], pass, 0);
1337
1338 if (SUCCESS == call_user_function(EG(function_table), NULL, cb,
1339 &retval, 2, zparams TSRMLS_CC)) {
1340 result = Z_LVAL(retval);
1341 }
1342
1343 efree(user);
1344 efree(pass);
1345 efree(zparams[0]);
1346 efree(zparams[1]);
1347
1348 if (!result) {
1349 http_auth_basic_header(realm);
1350 }
1351
1352 RETURN_BOOL(result);
1353 }
1354 }
1355 /* }}}*/
1356
1357 /* {{{ Sara Golemons http_build_query() */
1358 #ifndef ZEND_ENGINE_2
1359
1360 /* {{{ proto string http_build_query(mixed formdata [, string prefix[, string arg_separator]])
1361 Generates a form-encoded query string from an associative array or object. */
1362 PHP_FUNCTION(http_build_query)
1363 {
1364 zval *formdata;
1365 char *prefix = NULL, *arg_sep = INI_STR("arg_separator.output");
1366 int prefix_len = 0, arg_sep_len = strlen(arg_sep);
1367 phpstr *formstr;
1368
1369 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|ss", &formdata, &prefix, &prefix_len, &arg_sep, &arg_sep_len) != SUCCESS) {
1370 RETURN_FALSE;
1371 }
1372
1373 if (Z_TYPE_P(formdata) != IS_ARRAY && Z_TYPE_P(formdata) != IS_OBJECT) {
1374 http_error(HE_WARNING, HTTP_E_INVALID_PARAM, "Parameter 1 expected to be Array or Object. Incorrect value given.");
1375 RETURN_FALSE;
1376 }
1377
1378 if (!arg_sep_len) {
1379 arg_sep = HTTP_URL_ARGSEP;
1380 }
1381
1382 formstr = phpstr_new();
1383 if (SUCCESS != http_urlencode_hash_implementation_ex(HASH_OF(formdata), formstr, arg_sep, prefix, prefix_len, NULL, 0, NULL, 0, (Z_TYPE_P(formdata) == IS_OBJECT ? formdata : NULL))) {
1384 phpstr_free(formstr);
1385 RETURN_FALSE;
1386 }
1387
1388 if (!formstr->used) {
1389 phpstr_free(formstr);
1390 RETURN_NULL();
1391 }
1392
1393 RETURN_PHPSTR_PTR(formstr);
1394 }
1395 /* }}} */
1396 #endif /* !ZEND_ENGINE_2 */
1397 /* }}} */
1398
1399 PHP_FUNCTION(http_test)
1400 {
1401 }
1402
1403 /*
1404 * Local variables:
1405 * tab-width: 4
1406 * c-basic-offset: 4
1407 * End:
1408 * vim600: noet sw=4 ts=4 fdm=marker
1409 * vim<600: noet sw=4 ts=4
1410 */
1411