4 +HTTP extension for PHP
7 +++ b/ext/http/KnownIssues.txt
11 +$Id: KnownIssues.txt 292753 2009-12-29 12:30:43Z mike $
14 + HttpResponse::getHeader() does not work with Apache2 SAPIs.
15 + Using an encoding stream filter on a stream you read from doesn't work.
18 + If you keep getting "SSL connect error" when trying to issue
19 + requests, try another (newer) libeay32.dll/ssleay32.dll pair.
22 + Our http_urlencode_hash() does not differentiate between prefixes
23 + for numeric or string keys.
24 + Inflating raw deflated data causes a re-initialization of the inflate
25 + stream where the corresponding window bits are modified to tell libz
26 + to not check for zlib header bytes. This is not preventable AFAICS.
27 + LFS dependant parts of libcurl are left out because of off_t,
28 + respectively off64_t confusion.
29 + Persistent handles and "cookiestore" request option do interfere,
30 + as libcurl saves the cookies to the file on curl_easy_destroy(),
31 + cookies are not saved until the CURL handle will be recycled.
32 + Thus one would either need to
33 + * run PHP with http.persistent.handles.limit = 0
34 + * call http_persistent_handles_clean() every request
35 + * call $HttpRequest->flushCookies(), which is available
36 + since libcurl v7.17.1 and does not work with the
38 + Anyway, none of these options is really perfect.
39 + HTTP and Proxy authentication information (username/password) can not be
40 + unset with NULL prior libcurl v7.19.6 and separate options for setting
41 + username and password--which work--are only available since v7.19.6.
43 +++ b/ext/http/LICENSE
45 +Copyright (c) 2004-2010, Michael Wallner <mike@iworks.at>.
48 +Redistribution and use in source and binary forms, with or without
49 +modification, are permitted provided that the following conditions are met:
51 + * Redistributions of source code must retain the above copyright notice,
52 + this list of conditions and the following disclaimer.
53 + * Redistributions in binary form must reproduce the above copyright
54 + notice, this list of conditions and the following disclaimer in the
55 + documentation and/or other materials provided with the distribution.
57 +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
58 +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
59 +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
60 +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
61 +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
62 +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
63 +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
64 +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
65 +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
66 +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
68 +===============================================================================
70 +The date parser in file http_date_api.c is derived from the implementation
71 +found in the original libcurl source, licensed under the following conditions:
73 +Copyright (c) 1996 - 2006, Daniel Stenberg, <daniel@haxx.se>.
76 +Permission to use, copy, modify, and distribute this software for any purpose
77 +with or without fee is hereby granted, provided that the above copyright
78 +notice and this permission notice appear in all copies.
80 +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
81 +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
82 +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN
83 +NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
84 +DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
85 +OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
86 +OR OTHER DEALINGS IN THE SOFTWARE.
88 +Except as contained in this notice, the name of a copyright holder shall not
89 +be used in advertising or otherwise to promote the sale, use or other dealings
90 +in this Software without prior written authorization of the copyright holder.
93 +++ b/ext/http/Makefile.frag
95 +# vim: noet ts=1 sw=1
97 +phpincludedir=$(prefix)/include/php
99 +install-http: install install-http-headers
101 +install-http-headers:
102 + @echo "Installing HTTP headers: $(INSTALL_ROOT)$(phpincludedir)/ext/http/"
103 + @$(mkinstalldirs) $(INSTALL_ROOT)$(phpincludedir)/ext/http
104 + @for f in $(PHP_HTTP_HEADERS); do \
105 + if test -f "$(top_srcdir)/$$f"; then \
106 + $(INSTALL_DATA) $(top_srcdir)/$$f $(INSTALL_ROOT)$(phpincludedir)/ext/http; \
107 + elif test -f "$(top_builddir)/$$f"; then \
108 + $(INSTALL_DATA) $(top_builddir)/$$f $(INSTALL_ROOT)$(phpincludedir)/ext/http; \
109 + elif test -f "$(top_srcdir)/ext/http/$$f"; then \
110 + $(INSTALL_DATA) $(top_srcdir)/ext/http/$$f $(INSTALL_ROOT)$(phpincludedir)/ext/http; \
111 + elif test -f "$(top_builddir)/ext/http/$$f"; then \
112 + $(INSTALL_DATA) $(top_builddir)/ext/http/$$f $(INSTALL_ROOT)$(phpincludedir)/ext/http; \
119 +++ b/ext/http/ThanksTo.txt
123 +$Id: ThanksTo.txt 275653 2009-02-12 13:11:05Z mike $
125 +People who repeatedly reported issues with this extension in a manner
126 +so they could be fixed in a reasonable way, or suggested useful features
127 +to implement, in alphabetical order:
129 + Ilia Alshanetsky (ilia at php dot net)
130 + Petr Czaderna (petr at hroch dot info)
131 + David James (james82 at gmail dot com)
132 + Thomas Landro Johnsen (thomas dot l dot johnsen at gmail dot com)
133 + Clay Loveless (clay at killersoft dot com)
134 + Felipe Pena (felipe at php dot net)
135 + David Sklar (sklar at sklar dot com)
136 + Travis Swicegood (travis at mashery dot com)
137 + Alexey Zakhlestin (indeyets at gmail dot com)
138 + Alexander Zhuravlev (zaa at zaa dot pp dot ru)
142 +++ b/ext/http/config.m4
144 +dnl phpize stub of config9.m4 for pecl/http
145 +dnl $Id: config.m4 214417 2006-06-07 21:05:34Z mike $
146 +dnl vim: noet ts=1 sw=1
148 +sinclude(config9.m4)
150 +++ b/ext/http/config.w32
152 +// config.w32 for pecl/http
153 +// $Id: config.w32 287971 2009-09-02 14:36:08Z pajoye $
155 +ARG_ENABLE("http", "whether to enable extended HTTP support", "no");
157 +function check_for_main_ext(ext, header)
160 + header = "php_"+ ext +".h";
163 + /* When in configure, we're always in the root of PHP source */
164 + var ext_path = "ext\\" + ext;
166 + STDOUT.Write("Checking for ext/"+ ext +" ... ");
168 + if (FSO.FileExists(ext_path + "\\" + header)) {
169 + STDOUT.WriteLine(ext_path);
173 + STDOUT.WriteLine("<not found>");
177 +function check_for_pecl_ext(ext, header)
180 + header = "php_"+ ext +".h";
184 + var s = ext +"\\"+ header;
186 + STDOUT.Write("Checking for pecl/"+ ext +" ... ");
187 + if ( (g = glob(configure_module_dirname +"\\..\\"+ s)) ||
188 + (g = glob(configure_module_dirname +"\\..\\..\\..\\pecl\\"+ s))) {
189 + var f = g[0].substr(0, g[0].length - header.length - 1);
190 + STDOUT.WriteLine(f);
193 + STDOUT.WriteLine("<not found>");
197 +if (PHP_HTTP != "no") {
200 + "missing.c http.c http_functions.c http_exception_object.c "+
201 + "http_util_object.c http_message_object.c http_requestpool_object.c "+
202 + "http_request_object.c http_response_object.c "+
203 + "http_api.c http_cache_api.c http_request_pool_api.c "+
204 + "http_request_api.c http_date_api.c http_headers_api.c "+
205 + "http_message_api.c http_send_api.c http_url_api.c "+
206 + "http_info_api.c http_request_method_api.c http_encoding_api.c "+
207 + "http_filter_api.c http_request_body_api.c http_querystring_object.c "+
208 + "http_deflatestream_object.c http_inflatestream_object.c "+
209 + "http_cookie_api.c http_querystring_api.c http_request_datashare_api.c "+
210 + "http_requestdatashare_object.c http_request_info.c http_persistent_handle_api.c",
212 + "/I\"" + configure_module_dirname + "/phpstr\"");
213 + ADD_SOURCES(configure_module_dirname + "/phpstr", "phpstr.c", "http");
214 + AC_DEFINE("HAVE_HTTP", 1, "Have extended HTTP support");
215 + AC_DEFINE("HTTP_SHARED_DEPS", 1, "Depend on shared extensions");
217 + AC_DEFINE("HAVE_GETHOSTNAME", 1);
218 + AC_DEFINE("HAVE_GETSERVBYPORT", 1);
219 + AC_DEFINE("HAVE_GETSERVBYNAME", 1);
221 + if (PHP_DEBUG != "no") {
222 + ADD_FLAG("CFLAGS_HTTP", "/W3");
225 + if (CHECK_HEADER_ADD_INCLUDE('zlib.h', 'CFLAGS_HTTP', '..\\zlib;' + php_usual_include_suspects)) {
226 + AC_DEFINE('HTTP_HAVE_ZLIB', 1, "Have zlib library");
227 + ADD_FLAG("LDFLAGS_HTTP", "/FORCE:MULTIPLE");
229 + WARNING("zlib encoding functions not enabled; libraries and headers not found");
232 + if (typeof(PHP_HASH) != "undefined" && PHP_HASH != "no") {
235 + if ((f = check_for_pecl_ext("hash")) || (f = check_for_main_ext("hash"))) {
236 + ADD_FLAG("CFLAGS_HTTP", '/I "' + f + '" /DHTTP_HAVE_PHP_HASH_H=1');
237 + ADD_EXTENSION_DEP("http", "hash", true);
241 + if (PHP_SESSION != "no") {
242 + ADD_EXTENSION_DEP("http", "session", true);
245 + if (PHP_ICONV != "no") {
246 + ADD_EXTENSION_DEP("http", "iconv", true);
249 + CURL_LIB="libcurl_a.lib;libcurl.lib;" + (PHP_DEBUG != "no" ? "libcurld.lib":"libcurl.lib");
250 + if (CHECK_HEADER_ADD_INCLUDE("curl/curl.h", "CFLAGS_HTTP") &&
251 + CHECK_HEADER_ADD_INCLUDE("openssl/crypto.h", "CFLAGS_HTTP") &&
252 + CHECK_LIB(CURL_LIB, "http", PHP_HTTP) &&
253 + CHECK_LIB("ssleay32.lib", "http", PHP_HTTP) &&
254 + CHECK_LIB("libeay32.lib", "http", PHP_HTTP) &&
255 + CHECK_LIB("zlib.lib;zlib_a.lib", "http", PHP_HTTP) &&
256 + CHECK_LIB("winmm.lib", "http", PHP_HTTP)) {
257 + AC_DEFINE("HTTP_HAVE_CURL", 1, "Have CURL library");
258 + AC_DEFINE("HTTP_HAVE_SSL", 1, "Have SSL");
259 + AC_DEFINE("HAVE_CURL_MULTI_STRERROR", 1, "");
260 + AC_DEFINE("HAVE_CURL_SHARE_STRERROR", 1, "");
261 + AC_DEFINE("HAVE_CURL_EASY_STRERROR", 1, "");
262 + AC_DEFINE("HAVE_CURL_EASY_RESET", 1, "");
263 + AC_DEFINE("HAVE_CURL_GETFORMDATA", 1, "");
264 + AC_DEFINE("HAVE_CURL_FORMGET", 1, "");
265 + AC_DEFINE("HAVE_CURL_MULTI_SETOPT", 1, "");
266 + AC_DEFINE("HAVE_CURL_MULTI_TIMEOUT", 1, "");
268 + WARNING("curl convenience functions not enabled; libraries and headers not found");
271 +// MAGIC_LIB = PHP_DEBUG != "no" ? "libmagic-staticd.lib":"libmagic-static.lib";
272 +// if (CHECK_HEADER_ADD_INCLUDE("magic.h", "CFLAGS_HTTP") &&
273 +// CHECK_LIB(MAGIC_LIB, "http", PHP_HTTP)) {
274 +// AC_DEFINE("HTTP_HAVE_MAGIC", 1, "Have magic library");
275 +// AC_DEFINE("USE_MAGIC_STATIC", "", "");
277 +// WARNING("content type guessing not enabled; libraries and headers not found");
282 +++ b/ext/http/config9.m4
284 +dnl config.m4 for pecl/http
285 +dnl $Id: config9.m4 242664 2007-09-18 19:13:37Z mike $
286 +dnl vim: noet ts=1 sw=1
288 +PHP_ARG_ENABLE([http], [whether to enable extended HTTP support],
289 +[ --enable-http Enable extended HTTP support])
290 +PHP_ARG_WITH([http-shared-deps], [whether to depend on extensions which have been built shared],
291 +[ --with-http-shared-deps
292 + HTTP: disable to not depend on extensions like hash,
293 + iconv and session (when built shared)], $PHP_HTTP, $PHP_HTTP)
294 +PHP_ARG_WITH([http-curl-requests], [whether to enable cURL HTTP request support],
295 +[ --with-http-curl-requests[=LIBCURLDIR]
296 + HTTP: with cURL request support], $PHP_HTTP, $PHP_HTTP)
297 +PHP_ARG_WITH([http-curl-libevent], [whether to enable libevent support fur cURL],
298 +[ --with-http-curl-libevent[=LIBEVENTDIR]
299 + HTTP: libevent install directory], $PHP_HTTP_CURL_REQUESTS, "")
300 +PHP_ARG_WITH([http-zlib-compression], [whether to enable zlib encodings support],
301 +[ --with-http-zlib-compression[=LIBZDIR]
302 + HTTP: with zlib encodings support], $PHP_HTTP, $PHP_HTTP)
303 +PHP_ARG_WITH([http-magic-mime], [whether to enable response content type guessing],
304 +[ --with-http-magic-mime[=LIBMAGICDIR]
305 + HTTP: with magic mime response content type guessing], "no", "no")
307 +if test "$PHP_HTTP" != "no"; then
309 + ifdef([AC_PROG_EGREP], [
312 + AC_CHECK_PROG(EGREP, egrep, egrep)
314 + ifdef([AC_PROG_SED], [
317 + ifdef([LT_AC_PROG_SED], [
320 + AC_CHECK_PROG(SED, sed, sed)
326 + if test "$PHP_HTTP_SHARED_DEPS" != "no"; then
327 + AC_DEFINE([HTTP_SHARED_DEPS], [1], [ ])
329 + AC_DEFINE([HTTP_SHARED_DEPS], [0], [ ])
333 + dnl HTTP_SHARED_DEP(name[, code-if-yes[, code-if-not]])
335 + AC_DEFUN([HTTP_SHARED_DEP], [
337 + haveext=$[HTTP_HAVE_EXT_]translit($1,a-z_-,A-Z__)
339 + AC_MSG_CHECKING([whether to add a dependency on ext/$extname])
340 + if test "$PHP_HTTP_SHARED_DEPS" = "no"; then
341 + AC_MSG_RESULT([no])
343 + elif test "$haveext"; then
344 + AC_MSG_RESULT([yes])
345 + ifdef([PHP_ADD_EXTENSION_DEP], [
346 + PHP_ADD_EXTENSION_DEP([http], $1, true)
350 + AC_MSG_RESULT([no])
356 + dnl HTTP_HAVE_PHP_EXT(name[, code-if-yes[, code-if-not]])
358 + AC_DEFUN([HTTP_HAVE_PHP_EXT], [
360 + haveext=$[PHP_]translit($1,a-z_-,A-Z__)
362 + AC_MSG_CHECKING([for ext/$extname support])
363 + if test -x "$PHP_EXECUTABLE"; then
364 + grepext=`$PHP_EXECUTABLE -m | $EGREP ^$extname\$`
365 + if test "$grepext" = "$extname"; then
366 + [HTTP_HAVE_EXT_]translit($1,a-z_-,A-Z__)=1
367 + AC_MSG_RESULT([yes])
370 + [HTTP_HAVE_EXT_]translit($1,a-z_-,A-Z__)=
371 + AC_MSG_RESULT([no])
374 + elif test "$haveext" != "no" && test "x$haveext" != "x"; then
375 + [HTTP_HAVE_EXT_]translit($1,a-z_-,A-Z__)=1
376 + AC_MSG_RESULT([yes])
379 + [HTTP_HAVE_EXT_]translit($1,a-z_-,A-Z__)=
380 + AC_MSG_RESULT([no])
388 + if test "x$PHP_LIBDIR" = "x"; then
395 + AC_CHECK_HEADERS([netdb.h unistd.h])
396 + PHP_CHECK_FUNC(gethostname, nsl)
397 + PHP_CHECK_FUNC(getdomainname, nsl)
398 + PHP_CHECK_FUNC(getservbyport, nsl)
399 + PHP_CHECK_FUNC(getservbyname, nsl)
404 + if test "$PHP_HTTP_ZLIB_COMPRESSION" != "no"; then
405 + AC_MSG_CHECKING([for zlib.h])
407 + for i in "$PHP_HTTP_ZLIB_COMPRESSION" "$PHP_ZLIB_DIR" "$PHP_ZLIB" /usr/local /usr /opt; do
408 + if test -f "$i/include/zlib.h"; then
413 + if test "x$ZLIB_DIR" = "x"; then
414 + AC_MSG_RESULT([not found])
415 + AC_MSG_ERROR([could not find zlib.h])
417 + AC_MSG_RESULT([found in $ZLIB_DIR])
418 + AC_MSG_CHECKING([for zlib version >= 1.2.0.4])
419 + ZLIB_VERSION=`$EGREP "define ZLIB_VERSION" $ZLIB_DIR/include/zlib.h | $SED -e 's/[[^0-9\.]]//g'`
420 + AC_MSG_RESULT([$ZLIB_VERSION])
421 + if test `echo $ZLIB_VERSION | $SED -e 's/[[^0-9]]/ /g' | $AWK '{print $1*1000000 + $2*10000 + $3*100 + $4}'` -lt 1020004; then
422 + AC_MSG_ERROR([libz version greater or equal to 1.2.0.4 required])
424 + PHP_ADD_INCLUDE($ZLIB_DIR/include)
425 + PHP_ADD_LIBRARY_WITH_PATH(z, $ZLIB_DIR/$PHP_LIBDIR, HTTP_SHARED_LIBADD)
426 + AC_DEFINE([HTTP_HAVE_ZLIB], [1], [Have zlib support])
434 + if test "$PHP_HTTP_CURL_REQUESTS" != "no"; then
435 + AC_MSG_CHECKING([for curl/curl.h])
437 + for i in "$PHP_HTTP_CURL_REQUESTS" /usr/local /usr /opt; do
438 + if test -f "$i/include/curl/curl.h"; then
443 + if test "x$CURL_DIR" = "x"; then
444 + AC_MSG_RESULT([not found])
445 + AC_MSG_ERROR([could not find curl/curl.h])
447 + AC_MSG_RESULT([found in $CURL_DIR])
450 + AC_MSG_CHECKING([for curl-config])
452 + for i in "$CURL_DIR/bin/curl-config" "$CURL_DIR/curl-config" `which curl-config`; do
453 + if test -x "$i"; then
458 + if test "x$CURL_CONFIG" = "x"; then
459 + AC_MSG_RESULT([not found])
460 + AC_MSG_ERROR([could not find curl-config])
462 + AC_MSG_RESULT([found: $CURL_CONFIG])
465 + dnl Debian stable has currently 7.13.2 (this is not a typo)
466 + AC_MSG_CHECKING([for curl version >= 7.12.3])
467 + CURL_VERSION=`$CURL_CONFIG --version | $SED -e 's/[[^0-9\.]]//g'`
468 + AC_MSG_RESULT([$CURL_VERSION])
469 + if test `echo $CURL_VERSION | $SED -e 's/[[^0-9]]/ /g' | $AWK '{print $1*10000 + $2*100 + $3}'` -lt 71203; then
470 + AC_MSG_ERROR([libcurl version greater or equal to 7.12.3 required])
477 + save_INCLUDES="$INCLUDES"
481 + save_CFLAGS="$CFLAGS"
482 + CFLAGS=`$CURL_CONFIG --cflags`
483 + save_LDFLAGS="$LDFLAGS"
484 + LDFLAGS=`$CURL_CONFIG --libs`
485 + LDFLAGS="$LDFLAGS $ld_runpath_switch$CURL_DIR/$PHP_LIBDIR"
487 + AC_MSG_CHECKING([for SSL support in libcurl])
488 + CURL_SSL=`$CURL_CONFIG --feature | $EGREP SSL`
489 + if test "$CURL_SSL" = "SSL"; then
490 + AC_MSG_RESULT([yes])
491 + AC_DEFINE([HTTP_HAVE_SSL], [1], [ ])
493 + AC_MSG_CHECKING([for openssl support in libcurl])
495 + #include <curl/curl.h>
496 + int main(int argc, char *argv[]) {
497 + curl_version_info_data *data = curl_version_info(CURLVERSION_NOW);
498 + if (data && data->ssl_version && *data->ssl_version) {
499 + const char *ptr = data->ssl_version;
500 + while(*ptr == ' ') ++ptr;
501 + return strncasecmp(ptr, "OpenSSL", sizeof("OpenSSL")-1);
506 + AC_MSG_RESULT([yes])
507 + AC_CHECK_HEADER([openssl/crypto.h], [
508 + AC_DEFINE([HTTP_HAVE_OPENSSL], [1], [ ])
511 + AC_MSG_RESULT([no])
513 + AC_MSG_RESULT([no])
516 + AC_MSG_CHECKING([for gnutls support in libcurl])
518 + #include <curl/curl.h>
519 + int main(int argc, char *argv[]) {
520 + curl_version_info_data *data = curl_version_info(CURLVERSION_NOW);
521 + if (data && data->ssl_version && *data->ssl_version) {
522 + const char *ptr = data->ssl_version;
523 + while(*ptr == ' ') ++ptr;
524 + return strncasecmp(ptr, "GnuTLS", sizeof("GnuTLS")-1);
529 + AC_MSG_RESULT([yes])
530 + AC_CHECK_HEADER([gcrypt.h], [
531 + AC_DEFINE([HTTP_HAVE_GNUTLS], [1], [ ])
534 + AC_MSG_RESULT([no])
536 + AC_MSG_RESULT([no])
539 + AC_MSG_RESULT([no])
542 + INCLUDES="$save_INCLUDES"
544 + CFLAGS="$save_CFLAGS"
545 + LDFLAGS="$save_LDFLAGS"
547 + dnl end compile tests
549 + AC_MSG_CHECKING([for bundled SSL CA info])
551 + for i in `$CURL_CONFIG --ca` "/etc/ssl/certs/ca-certificates.crt"; do
552 + if test -f "$i"; then
557 + if test "x$CURL_CAINFO" = "x"; then
558 + AC_MSG_RESULT([not found])
560 + AC_MSG_RESULT([$CURL_CAINFO])
561 + AC_DEFINE_UNQUOTED([HTTP_CURL_CAINFO], ["$CURL_CAINFO"], [path to bundled SSL CA info])
564 + PHP_ADD_INCLUDE($CURL_DIR/include)
565 + PHP_ADD_LIBRARY_WITH_PATH(curl, $CURL_DIR/$PHP_LIBDIR, HTTP_SHARED_LIBADD)
566 + PHP_EVAL_LIBLINE(`$CURL_CONFIG --libs`, HTTP_SHARED_LIBADD)
567 + AC_DEFINE([HTTP_HAVE_CURL], [1], [Have cURL support])
569 + PHP_CHECK_LIBRARY(curl, curl_share_strerror,
570 + [AC_DEFINE([HAVE_CURL_SHARE_STRERROR], [1], [ ])], [ ],
571 + [$CURL_LIBS -L$CURL_DIR/$PHP_LIBDIR]
573 + PHP_CHECK_LIBRARY(curl, curl_multi_strerror,
574 + [AC_DEFINE([HAVE_CURL_MULTI_STRERROR], [1], [ ])], [ ],
575 + [$CURL_LIBS -L$CURL_DIR/$PHP_LIBDIR]
577 + PHP_CHECK_LIBRARY(curl, curl_easy_strerror,
578 + [AC_DEFINE([HAVE_CURL_EASY_STRERROR], [1], [ ])], [ ],
579 + [$CURL_LIBS -L$CURL_DIR/$PHP_LIBDIR]
581 + PHP_CHECK_LIBRARY(curl, curl_easy_reset,
582 + [AC_DEFINE([HAVE_CURL_EASY_RESET], [1], [ ])], [ ],
583 + [$CURL_LIBS -L$CURL_DIR/$PHP_LIBDIR]
585 + PHP_CHECK_LIBRARY(curl, curl_formget,
586 + [AC_DEFINE([HAVE_CURL_FORMGET], [1], [ ])], [ ],
587 + [$CURL_LIBS -L$CURL_DIR/$PHP_LIBDIR]
589 + PHP_CHECK_LIBRARY(curl, curl_multi_setopt,
590 + [AC_DEFINE([HAVE_CURL_MULTI_SETOPT], [1], [ ])], [ ],
591 + [$CURL_LIBS -L$CURL_DIR/$PHP_LIBDIR]
593 + PHP_CHECK_LIBRARY(curl, curl_multi_timeout,
594 + [AC_DEFINE([HAVE_CURL_MULTI_TIMEOUT], [1], [ ])], [ ],
595 + [$CURL_LIBS -L$CURL_DIR/$PHP_LIBDIR]
602 + if test "$PHP_HTTP_CURL_LIBEVENT" != "no"; then
603 + HTTP_HAVE_PHP_EXT([event], [
604 + AC_MSG_WARN([event support is incompatible with pecl/event; continuing without libevent support])
606 + AC_MSG_CHECKING([for event.h])
608 + for i in "$PHP_HTTP_CURL_LIBEVENT" /usr/local /usr /opt; do
609 + if test -f "$i/include/event.h"; then
614 + if test "x$EVENT_DIR" = "x"; then
615 + AC_MSG_RESULT([not found])
616 + AC_MSG_WARN([continuing without libevent support])
618 + AC_MSG_RESULT([found in $EVENT_DIR])
620 + AC_MSG_CHECKING([for libevent version, roughly])
621 + EVENT_VER="1.1b or lower"
622 + if test -f "$EVENT_DIR/include/evhttp.h" && test -f "$EVENT_DIR/include/evdns.h"; then
623 + if test -f "$EVENT_DIR/include/evrpc.h"; then
624 + EVENT_VER="1.4 or greater"
626 + EVENT_VER="1.2 or greater"
629 + AC_DEFINE_UNQUOTED([HTTP_EVENT_VERSION], ["$EVENT_VER"], [ ])
630 + AC_MSG_RESULT([$EVENT_VER])
632 + AC_MSG_CHECKING([for libcurl version >= 7.16.0])
633 + AC_MSG_RESULT([$CURL_VERSION])
634 + if test `echo $CURL_VERSION | $SED -e 's/[[^0-9]]/ /g' | $AWK '{print $1*10000 + $2*100 + $3}'` -lt 71600; then
635 + AC_MSG_WARN([libcurl version greater or equal to 7.16.0 required; continuing without libevent support])
637 + PHP_ADD_INCLUDE($EVENT_DIR/include)
638 + PHP_ADD_LIBRARY_WITH_PATH(event, $EVENT_DIR/$PHP_LIBDIR, HTTP_SHARED_LIBADD)
639 + AC_DEFINE([HTTP_HAVE_EVENT], [1], [Have libevent support for cURL])
640 + PHP_CHECK_LIBRARY(curl, curl_multi_socket_action,
641 + [AC_DEFINE([HAVE_CURL_MULTI_SOCKET_ACTION], [1], [ ])], [ ],
642 + [$CURL_LIBS -L$CURL_DIR/$PHP_LIBDIR]
653 + if test "$PHP_HTTP_MAGIC_MIME" != "no"; then
654 + AC_MSG_CHECKING([for magic.h])
656 + for i in "$PHP_HTTP_MAGIC_MIME" /usr/local /usr /opt; do
657 + if test -f "$i/include/magic.h"; then
662 + if test "x$MAGIC_DIR" = "x"; then
663 + AC_MSG_RESULT([not found])
664 + AC_MSG_ERROR([could not find magic.h])
666 + AC_MSG_RESULT([found in $MAGIC_DIR])
669 + PHP_ADD_INCLUDE($MAGIC_DIR/include)
670 + PHP_ADD_LIBRARY_WITH_PATH(magic, $MAGIC_DIR/$PHP_LIBDIR, HTTP_SHARED_LIBADD)
671 + AC_DEFINE([HTTP_HAVE_MAGIC], [1], [Have magic mime support])
677 + HTTP_HAVE_PHP_EXT([hash], [
678 + AC_MSG_CHECKING([for php_hash.h])
679 + HTTP_EXT_HASH_INCDIR=
680 + for i in `echo $INCLUDES | $SED -e's/-I//g'` $abs_srcdir ../hash; do
681 + if test -d $i; then
682 + if test -f $i/php_hash.h; then
683 + HTTP_EXT_HASH_INCDIR=$i
685 + elif test -f $i/ext/hash/php_hash.h; then
686 + HTTP_EXT_HASH_INCDIR=$i/ext/hash
691 + if test "x$HTTP_EXT_HASH_INCDIR" = "x"; then
692 + AC_MSG_RESULT([not found])
694 + AC_MSG_RESULT([$HTTP_EXT_HASH_INCDIR])
695 + AC_DEFINE([HTTP_HAVE_PHP_HASH_H], [1], [Have ext/hash support])
696 + PHP_ADD_INCLUDE([$HTTP_EXT_HASH_INCDIR])
703 + HTTP_HAVE_PHP_EXT([iconv])
708 + HTTP_HAVE_PHP_EXT([session])
713 + PHP_HTTP_SOURCES="missing.c http.c http_functions.c phpstr/phpstr.c \
714 + http_util_object.c http_message_object.c http_request_object.c http_request_pool_api.c \
715 + http_response_object.c http_exception_object.c http_requestpool_object.c \
716 + http_api.c http_cache_api.c http_request_api.c http_request_info.c http_date_api.c \
717 + http_headers_api.c http_message_api.c http_send_api.c http_url_api.c \
718 + http_info_api.c http_request_method_api.c http_encoding_api.c \
719 + http_filter_api.c http_request_body_api.c http_querystring_object.c \
720 + http_deflatestream_object.c http_inflatestream_object.c http_cookie_api.c \
721 + http_querystring_api.c http_request_datashare_api.c http_requestdatashare_object.c \
722 + http_persistent_handle_api.c"
724 + PHP_NEW_EXTENSION([http], $PHP_HTTP_SOURCES, $ext_shared)
726 + dnl shared extension deps
727 + HTTP_SHARED_DEP([hash])
728 + HTTP_SHARED_DEP([iconv])
729 + HTTP_SHARED_DEP([session])
731 + PHP_ADD_BUILD_DIR($ext_builddir/phpstr, 1)
732 + PHP_SUBST([HTTP_SHARED_LIBADD])
734 + PHP_HTTP_HEADERS="php_http_std_defs.h php_http.h php_http_api.h php_http_cache_api.h \
735 + php_http_date_api.h php_http_headers_api.h php_http_info_api.h php_http_message_api.h \
736 + php_http_request_api.h php_http_request_method_api.h php_http_send_api.h php_http_url_api.h \
737 + php_http_encoding_api.h phpstr/phpstr.h missing.h php_http_request_body_api.h \
738 + php_http_exception_object.h php_http_message_object.h php_http_request_object.h \
739 + php_http_requestpool_object.h php_http_response_object.h php_http_util_object.h \
740 + php_http_querystring_object.h php_http_deflatestream_object.h php_http_inflatestream_object.h \
741 + php_http_cookie_api.h php_http_querystring_api.h php_http_request_datashare_api.h php_http_requestdatashare_object.h \
742 + php_http_persistent_handle_api.h"
743 + ifdef([PHP_INSTALL_HEADERS], [
744 + PHP_INSTALL_HEADERS(ext/http, $PHP_HTTP_HEADERS)
746 + PHP_SUBST([PHP_HTTP_HEADERS])
747 + PHP_ADD_MAKEFILE_FRAGMENT
750 + AC_DEFINE([HAVE_HTTP], [1], [Have extended HTTP support])
753 +++ b/ext/http/docs/examples/tutorial.txt
756 +A Beginners Tutorial
757 +--------------------
763 + The HttpRequest class can be used to execute any HTTP request method.
764 + The following example shows a simple GET request where a few query
765 + parameters are supplied. Additionally potential cookies will be
766 + read from and written to a file.
769 +$r = new HttpRequest('http://www.google.com/search');
771 +// store Googles cookies in a dedicated file
772 +touch('google.txt');
774 + array( 'cookiestore' => 'google.txt',
779 + array( 'q' => '+"pecl_http" -msg -cvs -list',
784 +// HttpRequest::send() returns an HttpMessage object
785 +// of type HttpMessage::TYPE_RESPONSE or throws an exception
787 + print $r->send()->getBody();
788 +} catch (HttpException $e) {
795 + The following example shows an multipart POST request, with two form
796 + fields and an image that's supposed to be uploaded to the server.
797 + It's a bad habit as well as common practice to issue a redirect after
798 + an received POST request, so we'll allow a redirect by enabling the
802 +$r = new HttpRequest('http://dev.iworks.at/.print_request.php', HTTP_METH_POST);
804 +// if redirects is set to true, a single redirect is allowed;
805 +// one can set any reasonable count of allowed redirects
807 + array( 'cookies' => array('MyCookie' => 'has a value'),
808 + 'redirect' => true,
814 + array( 'name' => 'Mike',
815 + 'mail' => 'mike@php.net',
818 +// add the file to post (form name, file name, file type)
819 +touch('profile.jpg');
820 +$r->addPostFile('image', 'profile.jpg', 'image/jpeg');
823 + print $r->send()->getBody();
824 +} catch (HttpException $e) {
831 + It's possible to execute several HttpRequests in parallel with the
832 + HttpRequestPool class. HttpRequests to send, do not need to perform
833 + the same request method, but can only be attached to one HttpRequestPool
838 + $p = new HttpRequestPool;
839 + // if you want to set _any_ options of the HttpRequest object,
840 + // you need to do so *prior attaching* to the request pool!
841 + $p->attach(new HttpRequest('http://pear.php.net', HTTP_METH_HEAD));
842 + $p->attach(new HttpRequest('http://pecl.php.net', HTTP_METH_HEAD));
843 +} catch (HttpException $e) {
850 + // HttpRequestPool implements an iterator over attached HttpRequest objects
851 + foreach ($p as $r) {
852 + echo "Checking ", $r->getUrl(), " reported ", $r->getResponseCode(), "\n";
854 +} catch (HttpException $e) {
859 +- Parallel Requests?
861 + You can use a more advanced approach by using the protected interface of
862 + the HttpRequestPool class. This allows you to perform some other tasks
863 + while the requests are executed.
866 +class Pool extends HttpRequestPool
868 + public function __construct()
870 + parent::__construct(
871 + new HttpRequest('http://pear.php.net', HTTP_METH_HEAD),
872 + new HttpRequest('http://pecl.php.net', HTTP_METH_HEAD)
875 + // HttpRequestPool methods socketPerform() and socketSelect() are
876 + // protected; one could use this approach to do something else
877 + // while the requests are being executed
878 + print "Executing requests";
879 + for ($i = 0; $this->socketPerform(); $i++) {
880 + $i % 10 or print ".";
881 + if (!$this->socketSelect()) {
882 + throw new HttpException("Socket error!");
890 + foreach (new Pool as $r) {
891 + echo "Checking ", $r->getUrl(), " reported ", $r->getResponseCode(), "\n";
893 +} catch (HttpException $ex) {
900 + One of the main key features of HttpResponse is HTTP caching. HttpResponse
901 + will calculate an ETag based on the http.etag_mode INI setting as well as
902 + it will determine the last modification time of the sent entity. It uses
903 + those two indicators to decide if the cache entry on the client side is
904 + still valid and will emit an "304 Not Modified" response if applicable.
907 +HttpResponse::setCacheControl('public');
908 +HttpResponse::setCache(true);
909 +HttpResponse::capture();
911 +print "This will be cached until content changes!\n";
912 +print "Note that this approach will only save the clients download time.\n";
915 +- Bandwidth Throttling
917 + HttpResponse supports a basic throttling mechanism, which is enabled by
918 + setting a throttle delay and a buffer size. PHP will sleep the specified
919 + amount of seconds after each sent chunk of specified bytes.
922 +// send 5000 bytes every 0.2 seconds, i.e. max ~25kByte/s
923 +HttpResponse::setThrottleDelay(0.2);
924 +HttpResponse::setBufferSize(5000);
925 +HttpResponse::setCache(true);
926 +HttpResponse::setContentType('application/x-zip');
927 +HttpResponse::setFile('../archive.zip');
928 +HttpResponse::send();
931 +++ b/ext/http/docs/http.ini
933 +; example INI file for pecl/http
934 +; $Id: http.ini 229420 2007-02-09 14:19:40Z mike $
937 +; enable if you want to transform all errors to exceptions (PHP >= 5 only)
938 +;http.only_exceptions = 1
940 +; disable if you don't want php to exit in case of redirects and cache hits;
941 +; a "NULL" output handler will be started instead, which discards all output
942 +;http.force_exit = 0
944 +; disable if you don't want 404 Not found status messages being sent,
945 +; if a file attempted to be sent with http_send_file() etc. cannot be found
946 +;http.send.not_found_404 = 0
948 +; the hashing algorithm with wich ETags are generated (MD5, SHA1, CRC32B);
949 +; if ext/hash is available, this can be set to any hash algorithm ext/hash supports
950 +; MD5 is the default and fallback algorithm
951 +;http.etag.mode = "MD5"
953 +; allowed request methods
954 +; by default PHP ignores unkown request methods
955 +; PHP will exit with a response status of 405 and an Allow header
956 +; if it encounters a request method not contained in the specified list
957 +;http.request.methods.allowed = "HEAD, GET, POST"
959 +; custom request methods
960 +;http.request.methods.custom = "KICK, BANN"
962 +; log file for positive cache hits
965 +; log file for redirects
966 +;http.log.redirect =
968 +; log file for responses with http_send_file() etc. where the file's not been found
969 +;http.log.not_found =
971 +; log file for requests with an unallowed request method
972 +;http.log.allowed_methods =
974 +; composite log file (i.e. log all messages to this file)
975 +;http.log.composite =
977 +; automatically deflate content if requested/supported by client
978 +;http.send.deflate.start_auto = 1
979 +;http.send.deflate.start_flags = HTTP_DEFLATE_LEVEL_DEF
981 +; automatically inflate sent content
982 +;http.send.inflate.start_auto = 0
983 +;http.send.inflate.start_flags =
985 +; global HttpRequestDataShare settings
986 +;http.request.datashare.cookie = 0
987 +;http.request.datashare.dns = 1
989 +; limit of idle persistent handles per provider
990 +;http.persistent.handles.limit = -1
992 +; default ident of persistent handles
993 +;http.persistent.handles.ident = "GLOBAL"
995 +++ b/ext/http/http.c
998 + +--------------------------------------------------------------------+
1000 + +--------------------------------------------------------------------+
1001 + | Redistribution and use in source and binary forms, with or without |
1002 + | modification, are permitted provided that the conditions mentioned |
1003 + | in the accompanying LICENSE file are met. |
1004 + +--------------------------------------------------------------------+
1005 + | Copyright (c) 2004-2010, Michael Wallner <mike@php.net> |
1006 + +--------------------------------------------------------------------+
1009 +/* $Id: http.c 300300 2010-06-09 07:29:35Z mike $ */
1011 +#define HTTP_WANT_SAPI
1012 +#define HTTP_WANT_CURL
1013 +#define HTTP_WANT_EVENT
1014 +#define HTTP_WANT_ZLIB
1015 +#define HTTP_WANT_MAGIC
1016 +#include "php_http.h"
1018 +#include "php_ini.h"
1019 +#include "ext/standard/info.h"
1020 +#include "zend_extensions.h"
1022 +#include "php_http_api.h"
1023 +#include "php_http_cache_api.h"
1024 +#include "php_http_cookie_api.h"
1025 +#include "php_http_encoding_api.h"
1026 +#include "php_http_filter_api.h"
1027 +#include "php_http_message_api.h"
1028 +#include "php_http_persistent_handle_api.h"
1029 +#include "php_http_request_api.h"
1030 +#include "php_http_request_datashare_api.h"
1031 +#include "php_http_request_method_api.h"
1032 +#include "php_http_request_pool_api.h"
1033 +#include "php_http_send_api.h"
1034 +#include "php_http_url_api.h"
1036 +#include "php_http_deflatestream_object.h"
1037 +#include "php_http_exception_object.h"
1038 +#include "php_http_inflatestream_object.h"
1039 +#include "php_http_message_object.h"
1040 +#include "php_http_querystring_object.h"
1041 +#include "php_http_request_object.h"
1042 +#include "php_http_requestdatashare_object.h"
1043 +#include "php_http_requestpool_object.h"
1044 +#include "php_http_response_object.h"
1045 +#include "php_http_util_object.h"
1047 +ZEND_DECLARE_MODULE_GLOBALS(http);
1048 +HTTP_DECLARE_ARG_PASS_INFO();
1050 +#ifdef COMPILE_DL_HTTP
1051 +ZEND_GET_MODULE(http)
1054 +/* {{{ http_functions[] */
1055 +zend_function_entry http_functions[] = {
1056 + PHP_FE(http_date, NULL)
1057 + PHP_FE(http_build_url, http_arg_pass_ref_4)
1058 + PHP_FE(http_build_str, NULL)
1059 +#ifndef ZEND_ENGINE_2
1060 + PHP_FALIAS(http_build_query, http_build_str, NULL)
1062 + PHP_FE(http_negotiate_language, http_arg_pass_ref_2)
1063 + PHP_FE(http_negotiate_charset, http_arg_pass_ref_2)
1064 + PHP_FE(http_negotiate_content_type, http_arg_pass_ref_2)
1065 + PHP_FE(http_negotiate, http_arg_pass_ref_3)
1066 + PHP_FE(http_redirect, NULL)
1067 + PHP_FE(http_throttle, NULL)
1068 + PHP_FE(http_send_status, NULL)
1069 + PHP_FE(http_send_last_modified, NULL)
1070 + PHP_FE(http_send_content_type, NULL)
1071 + PHP_FE(http_send_content_disposition, NULL)
1072 + PHP_FE(http_match_modified, NULL)
1073 + PHP_FE(http_match_etag, NULL)
1074 + PHP_FE(http_cache_last_modified, NULL)
1075 + PHP_FE(http_cache_etag, NULL)
1076 + PHP_FE(http_send_data, NULL)
1077 + PHP_FE(http_send_file, NULL)
1078 + PHP_FE(http_send_stream, NULL)
1079 + PHP_FE(http_chunked_decode, NULL)
1080 + PHP_FE(http_parse_message, NULL)
1081 + PHP_FE(http_parse_headers, NULL)
1082 + PHP_FE(http_parse_cookie, NULL)
1083 + PHP_FE(http_build_cookie, NULL)
1084 + PHP_FE(http_parse_params, NULL)
1085 + PHP_FE(http_get_request_headers, NULL)
1086 + PHP_FE(http_get_request_body, NULL)
1087 + PHP_FE(http_get_request_body_stream, NULL)
1088 + PHP_FE(http_match_request_header, NULL)
1089 + PHP_FE(http_persistent_handles_count, NULL)
1090 + PHP_FE(http_persistent_handles_clean, NULL)
1091 + PHP_FE(http_persistent_handles_ident, NULL)
1092 +#ifdef HTTP_HAVE_CURL
1093 + PHP_FE(http_get, http_arg_pass_ref_3)
1094 + PHP_FE(http_head, http_arg_pass_ref_3)
1095 + PHP_FE(http_post_data, http_arg_pass_ref_4)
1096 + PHP_FE(http_post_fields, http_arg_pass_ref_5)
1097 + PHP_FE(http_put_data, http_arg_pass_ref_4)
1098 + PHP_FE(http_put_file, http_arg_pass_ref_4)
1099 + PHP_FE(http_put_stream, http_arg_pass_ref_4)
1100 + PHP_FE(http_request, http_arg_pass_ref_5)
1101 + PHP_FE(http_request_body_encode, NULL)
1103 + PHP_FE(http_request_method_register, NULL)
1104 + PHP_FE(http_request_method_unregister, NULL)
1105 + PHP_FE(http_request_method_exists, NULL)
1106 + PHP_FE(http_request_method_name, NULL)
1107 + PHP_FE(ob_etaghandler, NULL)
1108 +#ifdef HTTP_HAVE_ZLIB
1109 + PHP_FE(http_deflate, NULL)
1110 + PHP_FE(http_inflate, NULL)
1111 + PHP_FE(ob_deflatehandler, NULL)
1112 + PHP_FE(ob_inflatehandler, NULL)
1114 + PHP_FE(http_support, NULL)
1116 + EMPTY_FUNCTION_ENTRY
1120 +PHP_MINIT_FUNCTION(http);
1121 +PHP_MSHUTDOWN_FUNCTION(http);
1122 +PHP_RINIT_FUNCTION(http);
1123 +PHP_RSHUTDOWN_FUNCTION(http);
1124 +PHP_MINFO_FUNCTION(http);
1126 +/* {{{ http_module_dep */
1127 +#if ZEND_EXTENSION_API_NO >= 220050617
1128 +static zend_module_dep http_module_deps[] = {
1129 +# ifdef HTTP_HAVE_SPL
1130 + ZEND_MOD_REQUIRED("spl")
1132 +# ifdef HTTP_HAVE_HASH
1133 + ZEND_MOD_REQUIRED("hash")
1135 +# ifdef HTTP_HAVE_SESSION
1136 + ZEND_MOD_REQUIRED("session")
1138 +# ifdef HTTP_HAVE_ICONV
1139 + ZEND_MOD_REQUIRED("iconv")
1141 +# ifdef HTTP_HAVE_EVENT
1142 + ZEND_MOD_CONFLICTS("event")
1144 + {NULL, NULL, NULL, 0}
1149 +/* {{{ http_module_entry */
1150 +zend_module_entry http_module_entry = {
1151 +#if ZEND_EXTENSION_API_NO >= 220050617
1152 + STANDARD_MODULE_HEADER_EX, NULL,
1155 + STANDARD_MODULE_HEADER,
1160 + PHP_MSHUTDOWN(http),
1162 + PHP_RSHUTDOWN(http),
1165 + STANDARD_MODULE_PROPERTIES
1169 +int http_module_number;
1171 +/* {{{ http_globals */
1172 +static void http_globals_init_once(zend_http_globals *G)
1174 + memset(G, 0, sizeof(zend_http_globals));
1177 +#define http_globals_init(g) _http_globals_init((g) TSRMLS_CC)
1178 +static inline void _http_globals_init(zend_http_globals *G TSRMLS_DC)
1180 +#ifdef HTTP_HAVE_SAPI_RTIME
1181 + G->request.time = sapi_get_request_time(TSRMLS_C);
1183 + G->request.time = time(NULL);
1185 + G->send.buffer_size = 0;
1186 + G->read_post_data = 0;
1189 +#define http_globals_free(g) _http_globals_free((g) TSRMLS_CC)
1190 +static inline void _http_globals_free(zend_http_globals *G TSRMLS_DC)
1192 + if (G->request.headers) {
1193 + zend_hash_destroy(G->request.headers);
1194 + FREE_HASHTABLE(G->request.headers);
1195 + G->request.headers = NULL;
1197 + STR_SET(G->send.content_type, NULL);
1198 + STR_SET(G->send.unquoted_etag, NULL);
1199 + if (G->server_var) {
1200 + zval_ptr_dtor(&G->server_var);
1201 + G->server_var = NULL;
1205 +#if defined(ZTS) && defined(PHP_DEBUG)
1206 +#if ZTS && PHP_DEBUG
1207 +zend_http_globals *http_globals(void)
1216 +/* {{{ static inline void http_check_allowed_methods(char *) */
1217 +#define http_check_allowed_methods(m) _http_check_allowed_methods((m) TSRMLS_CC)
1218 +static inline void _http_check_allowed_methods(const char *methods TSRMLS_DC)
1220 + if (*methods && SG(request_info).request_method) {
1221 + if (SUCCESS != http_check_method_ex(SG(request_info).request_method, methods)) {
1223 + spprintf(&header, 0, "Allow: %s", methods);
1224 + http_exit(405, header);
1231 +PHP_INI_MH(http_update_allowed_methods)
1234 + http_check_allowed_methods(new_value);
1236 + return OnUpdateString(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC);
1238 +PHP_INI_MH(http_update_persistent_handle_ident)
1240 + HTTP_G->persistent.handles.ident.h = zend_hash_func(new_value, HTTP_G->persistent.handles.ident.l = new_value_length+1);
1241 + return OnUpdateString(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC);
1244 +#ifndef ZEND_ENGINE_2
1245 +# define OnUpdateLong OnUpdateInt
1249 + HTTP_PHP_INI_ENTRY("http.etag.mode", "MD5", PHP_INI_ALL, OnUpdateString, etag.mode)
1250 + HTTP_PHP_INI_ENTRY("http.log.cache", "", PHP_INI_ALL, OnUpdateString, log.cache)
1251 + HTTP_PHP_INI_ENTRY("http.log.redirect", "", PHP_INI_ALL, OnUpdateString, log.redirect)
1252 + HTTP_PHP_INI_ENTRY("http.log.not_found", "", PHP_INI_ALL, OnUpdateString, log.not_found)
1253 + HTTP_PHP_INI_ENTRY("http.log.allowed_methods", "", PHP_INI_ALL, OnUpdateString, log.allowed_methods)
1254 + HTTP_PHP_INI_ENTRY("http.log.composite", "", PHP_INI_ALL, OnUpdateString, log.composite)
1255 + HTTP_PHP_INI_ENTRY("http.request.methods.allowed", "", PHP_INI_ALL, http_update_allowed_methods, request.methods.allowed)
1256 + HTTP_PHP_INI_ENTRY("http.request.methods.custom", "", PHP_INI_PERDIR|PHP_INI_SYSTEM, OnUpdateString, request.methods.custom)
1257 +#if defined(ZEND_ENGINE_2) && defined(HTTP_HAVE_CURL)
1258 + HTTP_PHP_INI_ENTRY("http.request.datashare.cookie", "0", PHP_INI_SYSTEM, OnUpdateBool, request.datashare.cookie)
1259 + HTTP_PHP_INI_ENTRY("http.request.datashare.dns", "1", PHP_INI_SYSTEM, OnUpdateBool, request.datashare.dns)
1260 + HTTP_PHP_INI_ENTRY("http.request.datashare.ssl", "0", PHP_INI_SYSTEM, OnUpdateBool, request.datashare.ssl)
1261 + HTTP_PHP_INI_ENTRY("http.request.datashare.connect", "0", PHP_INI_SYSTEM, OnUpdateBool, request.datashare.connect)
1263 +#ifdef HTTP_HAVE_ZLIB
1264 + HTTP_PHP_INI_ENTRY("http.send.inflate.start_auto", "0", PHP_INI_PERDIR|PHP_INI_SYSTEM, OnUpdateBool, send.inflate.start_auto)
1265 + HTTP_PHP_INI_ENTRY("http.send.inflate.start_flags", "0", PHP_INI_ALL, OnUpdateLong, send.inflate.start_flags)
1266 + HTTP_PHP_INI_ENTRY("http.send.deflate.start_auto", "0", PHP_INI_PERDIR|PHP_INI_SYSTEM, OnUpdateBool, send.deflate.start_auto)
1267 + HTTP_PHP_INI_ENTRY("http.send.deflate.start_flags", "0", PHP_INI_ALL, OnUpdateLong, send.deflate.start_flags)
1269 + HTTP_PHP_INI_ENTRY("http.persistent.handles.limit", "-1", PHP_INI_SYSTEM, OnUpdateLong, persistent.handles.limit)
1270 + HTTP_PHP_INI_ENTRY("http.persistent.handles.ident", "GLOBAL", PHP_INI_ALL, http_update_persistent_handle_ident, persistent.handles.ident.s)
1271 + HTTP_PHP_INI_ENTRY("http.send.not_found_404", "1", PHP_INI_ALL, OnUpdateBool, send.not_found_404)
1272 +#ifdef ZEND_ENGINE_2
1273 + HTTP_PHP_INI_ENTRY("http.only_exceptions", "0", PHP_INI_ALL, OnUpdateBool, only_exceptions)
1275 + HTTP_PHP_INI_ENTRY("http.force_exit", "1", PHP_INI_ALL, OnUpdateBool, force_exit)
1279 +/* {{{ PHP_MINIT_FUNCTION */
1280 +PHP_MINIT_FUNCTION(http)
1282 + http_module_number = module_number;
1283 + ZEND_INIT_MODULE_GLOBALS(http, http_globals_init_once, NULL);
1284 + REGISTER_INI_ENTRIES();
1287 + || SUCCESS != PHP_MINIT_CALL(http_persistent_handle) /* first */
1288 + || SUCCESS != PHP_MINIT_CALL(http_cookie)
1289 +#ifdef HTTP_HAVE_ZLIB
1290 + || SUCCESS != PHP_MINIT_CALL(http_encoding)
1292 +#ifdef HTTP_HAVE_CURL
1293 + || SUCCESS != PHP_MINIT_CALL(http_request)
1294 +# ifdef ZEND_ENGINE_2
1297 + || SUCCESS != PHP_MINIT_CALL(http_request_method)
1298 + || SUCCESS != PHP_MINIT_CALL(http_send)
1299 + || SUCCESS != PHP_MINIT_CALL(http_support)
1300 + || SUCCESS != PHP_MINIT_CALL(http_url)
1302 +#ifdef ZEND_ENGINE_2
1303 + || SUCCESS != PHP_MINIT_CALL(http_filter)
1304 + || SUCCESS != PHP_MINIT_CALL(http_exception_object)
1305 +# ifdef HTTP_HAVE_ZLIB
1306 + || SUCCESS != PHP_MINIT_CALL(http_deflatestream_object)
1307 + || SUCCESS != PHP_MINIT_CALL(http_inflatestream_object)
1309 + || SUCCESS != PHP_MINIT_CALL(http_message_object)
1310 + || SUCCESS != PHP_MINIT_CALL(http_querystring_object)
1311 +# ifdef HTTP_HAVE_CURL
1312 + || SUCCESS != PHP_MINIT_CALL(http_request_datashare)
1313 + || SUCCESS != PHP_MINIT_CALL(http_request_pool)
1314 + || SUCCESS != PHP_MINIT_CALL(http_request_object)
1315 + || SUCCESS != PHP_MINIT_CALL(http_requestdatashare_object)
1316 + || SUCCESS != PHP_MINIT_CALL(http_requestpool_object)
1319 + || SUCCESS != PHP_MINIT_CALL(http_response_object)
1321 + || SUCCESS != PHP_MINIT_CALL(http_util_object)
1331 +/* {{{ PHP_MSHUTDOWN_FUNCTION */
1332 +PHP_MSHUTDOWN_FUNCTION(http)
1334 + UNREGISTER_INI_ENTRIES();
1337 +#ifdef HTTP_HAVE_CURL
1338 + || SUCCESS != PHP_MSHUTDOWN_CALL(http_request)
1339 +# ifdef ZEND_ENGINE_2
1340 + || SUCCESS != PHP_MSHUTDOWN_CALL(http_request_datashare)
1343 + || SUCCESS != PHP_MSHUTDOWN_CALL(http_message_object)
1344 + || SUCCESS != PHP_MSHUTDOWN_CALL(http_persistent_handle) /* last */
1353 +/* {{{ PHP_RINIT_FUNCTION */
1354 +PHP_RINIT_FUNCTION(http)
1356 + http_globals_init(HTTP_G);
1358 + if (HTTP_G->request.methods.allowed && *HTTP_G->request.methods.allowed) {
1359 + http_check_allowed_methods(HTTP_G->request.methods.allowed);
1363 +#ifdef HTTP_HAVE_ZLIB
1364 + || SUCCESS != PHP_RINIT_CALL(http_encoding)
1366 +#ifdef HTTP_HAVE_CURL
1367 +# ifdef ZEND_ENGINE_2
1368 +# ifdef HTTP_HAVE_EVENT
1369 + || SUCCESS != PHP_RINIT_CALL(http_request_pool)
1371 + || SUCCESS != PHP_RINIT_CALL(http_request_datashare)
1374 + || SUCCESS != PHP_RINIT_CALL(http_request_method)
1383 +/* {{{ PHP_RSHUTDOWN_FUNCTION */
1384 +PHP_RSHUTDOWN_FUNCTION(http)
1386 + STATUS status = SUCCESS;
1389 +#ifdef HTTP_HAVE_ZLIB
1390 + || SUCCESS != PHP_RSHUTDOWN_CALL(http_encoding)
1392 +#ifdef HTTP_HAVE_CURL
1393 +# ifdef ZEND_ENGINE_2
1394 + || SUCCESS != PHP_RSHUTDOWN_CALL(http_request_datashare)
1397 + || SUCCESS != PHP_RSHUTDOWN_CALL(http_request_method)
1402 + http_globals_free(HTTP_G);
1407 +/* {{{ PHP_MINFO_FUNCTION */
1408 +PHP_MINFO_FUNCTION(http)
1410 + php_info_print_table_start();
1412 + php_info_print_table_header(2, "HTTP Support", "enabled");
1413 + php_info_print_table_row(2, "Extension Version", PHP_HTTP_VERSION);
1414 + php_info_print_table_row(2, "Registered Classes",
1415 +#ifndef ZEND_ENGINE_2
1420 +# ifdef HTTP_HAVE_CURL
1422 + "HttpRequestPool, "
1423 + "HttpRequestDataShare, "
1425 +# ifdef HTTP_HAVE_ZLIB
1426 + "HttpDeflateStream, "
1427 + "HttpInflateStream, "
1435 + php_info_print_table_row(2, "Output Handlers", "ob_deflatehandler, ob_inflatehandler, ob_etaghandler");
1436 + php_info_print_table_row(2, "Stream Filters",
1437 +#ifndef ZEND_ENGINE_2
1440 + "http.chunked_decode, http.chunked_encode, http.deflate, http.inflate"
1444 + php_info_print_table_end();
1446 + php_info_print_table_start();
1447 + php_info_print_table_header(3, "Used Library", "Compiled", "Linked");
1449 +#ifdef HTTP_HAVE_CURL
1450 + curl_version_info_data *cv = curl_version_info(CURLVERSION_NOW);
1451 + php_info_print_table_row(3, "libcurl", LIBCURL_VERSION, cv->version);
1453 + php_info_print_table_row(2, "libcurl", "disabled", "disabled");
1455 +#ifdef HTTP_HAVE_EVENT
1456 + php_info_print_table_row(3, "libevent", HTTP_EVENT_VERSION, event_get_version());
1458 + php_info_print_table_row(3, "libevent", "disabled", "disabled");
1460 +#ifdef HTTP_HAVE_ZLIB
1461 + php_info_print_table_row(3, "libz", ZLIB_VERSION, zlibVersion());
1463 + php_info_print_table_row(3, "libz", "disabled", "disabled");
1465 +#if defined(HTTP_HAVE_MAGIC)
1466 + php_info_print_table_row(3, "libmagic", "unknown", "unknown");
1468 + php_info_print_table_row(3, "libmagic", "disabled", "disabled");
1471 + php_info_print_table_end();
1473 + php_info_print_table_start();
1474 + php_info_print_table_colspan_header(4, "Persistent Handles");
1475 + php_info_print_table_header(4, "Provider", "Ident", "Used", "Free");
1478 + HashPosition pos1, pos2;
1479 + HashKey provider = initHashKey(0), ident = initHashKey(0);
1480 + zval **val, **sub, **zused, **zfree;
1482 + if ((ht = http_persistent_handle_statall()) && zend_hash_num_elements(ht)) {
1483 + FOREACH_HASH_KEYVAL(pos1, ht, provider, val) {
1484 + if (zend_hash_num_elements(Z_ARRVAL_PP(val))) {
1485 + FOREACH_KEYVAL(pos2, *val, ident, sub) {
1486 + if ( SUCCESS == zend_hash_find(Z_ARRVAL_PP(sub), ZEND_STRS("used"), (void *) &zused) &&
1487 + SUCCESS == zend_hash_find(Z_ARRVAL_PP(sub), ZEND_STRS("free"), (void *) &zfree)) {
1488 + zval *used = http_zsep(IS_STRING, *zused);
1489 + zval *free = http_zsep(IS_STRING, *zfree);
1490 + php_info_print_table_row(4, provider.str, ident.str, Z_STRVAL_P(used), Z_STRVAL_P(free));
1491 + zval_ptr_dtor(&used);
1492 + zval_ptr_dtor(&free);
1494 + php_info_print_table_row(4, provider.str, ident.str, "0", "0");
1498 + php_info_print_table_row(4, provider.str, "N/A", "0", "0");
1502 + php_info_print_table_row(4, "N/A", "N/A", "0", "0");
1505 + zend_hash_destroy(ht);
1506 + FREE_HASHTABLE(ht);
1509 + php_info_print_table_end();
1511 + php_info_print_table_start();
1512 + php_info_print_table_colspan_header(2, "Request Methods");
1515 + phpstr *methods = phpstr_new();
1518 + FOREACH_HASH_VAL(pos, &HTTP_G->request.methods.registered, name) {
1520 + phpstr_appendf(methods, "%s, ", *name);
1523 + phpstr_fix(methods);
1524 + php_info_print_table_row(2, "Registered", PHPSTR_VAL(methods));
1525 + php_info_print_table_row(2, "Allowed", *HTTP_G->request.methods.allowed ? HTTP_G->request.methods.allowed : "(ANY)");
1526 + phpstr_free(&methods);
1528 + php_info_print_table_end();
1530 + DISPLAY_INI_ENTRIES();
1535 + * Local variables:
1537 + * c-basic-offset: 4
1539 + * vim600: noet sw=4 ts=4 fdm=marker
1540 + * vim<600: noet sw=4 ts=4
1544 +++ b/ext/http/http.dsp
1546 +# Microsoft Developer Studio Project File - Name="http" - Package Owner=<4>
1547 +# Microsoft Developer Studio Generated Build File, Format Version 6.00
1548 +# ** DO NOT EDIT **
1550 +# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
1552 +CFG=http - Win32 Release_TS
1553 +!MESSAGE This is not a valid makefile. To build this project using NMAKE,
1554 +!MESSAGE use the Export Makefile command and run
1556 +!MESSAGE NMAKE /f "http.mak".
1558 +!MESSAGE You can specify a configuration when running NMAKE
1559 +!MESSAGE by defining the macro CFG on the command line. For example:
1561 +!MESSAGE NMAKE /f "http.mak" CFG="http - Win32 Release_TS"
1563 +!MESSAGE Possible choices for configuration are:
1565 +!MESSAGE "http - Win32 Release_TS" (based on "Win32 (x86) Dynamic-Link Library")
1566 +!MESSAGE "http - Win32 Debug_TS" (based on "Win32 (x86) Dynamic-Link Library")
1570 +# PROP AllowPerConfigDependencies 0
1571 +# PROP Scc_ProjName ""
1572 +# PROP Scc_LocalPath ""
1577 +!IF "$(CFG)" == "http - Win32 Release_TS"
1579 +# PROP BASE Use_MFC 0
1580 +# PROP BASE Use_Debug_Libraries 0
1581 +# PROP BASE Output_Dir "Release_TS"
1582 +# PROP BASE Intermediate_Dir "Release_TS"
1583 +# PROP BASE Ignore_Export_Lib 0
1584 +# PROP BASE Target_Dir ""
1586 +# PROP Use_Debug_Libraries 0
1587 +# PROP Output_Dir "Release_TS"
1588 +# PROP Intermediate_Dir "Release_TS"
1589 +# PROP Ignore_Export_Lib 0
1590 +# PROP Target_Dir ""
1591 +# ADD BASE CPP /nologo /MT /W3 /GX /O2 /I "..\.." /I "..\..\..\Zend" /I "..\..\..\bindlib_w32" /I "..\..\..\TSRM" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "COMPILE_DL_HTTP" /D ZTS=1 /YX /FD /c
1592 +# ADD CPP /nologo /Gd /MD /W3 /GX /O2 /I "..\.." /I "..\..\main" /I "..\..\Zend" /I "..\..\..\bindlib_w32" /I "..\..\TSRM" /D ZEND_DEBUG=0 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "HTTP_EXPORTS" /D "COMPILE_DL_HTTP" /D ZTS=1 /D "ZEND_WIN32" /D "PHP_WIN32" /D HAVE_HTTP=1 /D HTTP_HAVE_CURL=1 /D HAVE_CURL_EASY_STRERROR=1 /D HAVE_CURL_SHARE_STRERROR=1 /D HAVE_CURL_MULTI_STRERROR=1 /D HAVE_CURL_EASY_RESET=1 /D HAVE_CURL_FORMGET=1 /D HAVE_GETHOSTNAME=1 /D HAVE_GETSERVBYPORT=1 /D HAVE_GETSERVBYNAME=1 /D "_WINSOCKAPI_=" /FR /YX /FD /c
1593 +# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
1594 +# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
1595 +# ADD BASE RSC /l 0x406 /d "NDEBUG"
1596 +# ADD RSC /l 0x406 /d "NDEBUG"
1598 +# ADD BASE BSC32 /nologo
1599 +# ADD BSC32 /nologo
1601 +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib php4ts.lib /nologo /dll /machine:I386
1602 +# ADD LINK32 libcurl.lib ssleay32.lib libeay32.lib zlib.lib winmm.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib php4ts.lib wsock32.lib /nologo /dll /machine:I386 /out:"..\..\Release_TS/php_http.dll" /libpath:"..\..\Release_TS" /libpath:"..\..\Release_TS_Inline" /libpath:"..\..\..\php_build\curl\lib" /libpath:"..\..\..\php4\Release_TS" /libpath:"..\..\..\php4\Release_TS_Inline"
1604 +!ELSEIF "$(CFG)" == "http - Win32 Debug_TS"
1606 +# PROP BASE Use_MFC 0
1607 +# PROP BASE Use_Debug_Libraries 0
1608 +# PROP BASE Output_Dir "Debug_TS"
1609 +# PROP BASE Intermediate_Dir "Debug_TS"
1610 +# PROP BASE Ignore_Export_Lib 0
1611 +# PROP BASE Target_Dir ""
1613 +# PROP Use_Debug_Libraries 0
1614 +# PROP Output_Dir "Debug_TS"
1615 +# PROP Intermediate_Dir "Debug_TS"
1616 +# PROP Ignore_Export_Lib 0
1617 +# PROP Target_Dir ""
1618 +# ADD BASE CPP /nologo /MT /W3 /GX /O2 /I "..\.." /I "..\..\Zend" /I "..\..\..\bindlib_w32" /I "..\..\TSRM" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "COMPILE_DL_HTTP" /D ZTS=1 /YX /FD /c
1619 +# ADD CPP /nologo /MDd /W3 /GX /O2 /I "..\.." /I "..\..\main" /I "..\..\Zend" /I "..\..\..\bindlib_w32" /I "..\..\TSRM" /D ZEND_DEBUG=1 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "HTTP_EXPORTS" /D "COMPILE_DL_HTTP" /D ZTS=1 /D "ZEND_WIN32" /D "PHP_WIN32" /D HAVE_HTTP=1 /D HTTP_HAVE_CURL=1 /D HAVE_CURL_EASY_STRERROR=1 /D HAVE_CURL_SHARE_STRERROR=1 /D HAVE_CURL_MULTI_STRERROR=1 /D HAVE_CURL_EASY_RESET=1 /D HAVE_CURL_FORMGET=1 /D HAVE_GETHOSTNAME=1 /D HAVE_GETSERVBYPORT=1 /D HAVE_GETSERVBYNAME=1 /D "_WINSOCKAPI_=" /YX /FD /c
1620 +# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
1621 +# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
1622 +# ADD BASE RSC /l 0x406 /d "NDEBUG"
1623 +# ADD RSC /l 0x406 /d "NDEBUG"
1625 +# ADD BASE BSC32 /nologo
1626 +# ADD BSC32 /nologo
1628 +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib php4ts.lib /nologo /dll /machine:I386
1629 +# ADD LINK32 libcurl.lib ssleay32.lib libeay32.lib zlib.lib winmm.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib php4ts_debug.lib wsock32.lib /nologo /dll /machine:I386 /out:"..\..\Debug_TS/http.dll" /libpath:"..\..\Debug_TS" /libpath:"..\..\..\php_build\curl\lib" /libpath:"..\..\..\php4\Release_TS" /libpath:"..\..\..\php4\Release_TS_Inline"
1635 +# Name "http - Win32 Release_TS"
1636 +# Name "http - Win32 Debug_TS"
1637 +# Begin Group "Source Files"
1639 +# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
1640 +# Begin Source File
1644 +# Begin Source File
1646 +SOURCE=.\http_api.c
1648 +# Begin Source File
1650 +SOURCE=.\http_encoding_api.c
1652 +# Begin Source File
1654 +SOURCE=.\http_request_api.c
1656 +# Begin Source File
1658 +SOURCE=.\http_request_info.c
1660 +# Begin Source File
1662 +SOURCE=.\http_request_body_api.c
1664 +# Begin Source File
1666 +SOURCE=.\http_request_method_api.c
1668 +# Begin Source File
1670 +SOURCE=.\http_functions.c
1672 +# Begin Source File
1674 +SOURCE=.\http_persistent_handle_api.c
1676 +# Begin Source File
1678 +SOURCE=.\http_cache_api.c
1680 +# Begin Source File
1682 +SOURCE=.\http_cookie_api.c
1684 +# Begin Source File
1686 +SOURCE=.\http_date_api.c
1688 +# Begin Source File
1690 +SOURCE=.\http_headers_api.c
1692 +# Begin Source File
1694 +SOURCE=.\http_message_api.c
1696 +# Begin Source File
1698 +SOURCE=.\http_send_api.c
1700 +# Begin Source File
1702 +SOURCE=.\http_url_api.c
1704 +# Begin Source File
1706 +SOURCE=.\http_querystring_api.c
1708 +# Begin Source File
1710 +SOURCE=.\http_info_api.c
1712 +# Begin Source File
1714 +SOURCE=.\phpstr\phpstr.c
1717 +# Begin Group "Header Files"
1719 +# PROP Default_Filter "h;hpp;hxx;hm;inl"
1720 +# Begin Source File
1722 +SOURCE=.\php_http.h
1724 +# Begin Source File
1726 +SOURCE=.\php_http_api.h
1728 +# Begin Source File
1730 +SOURCE=.\php_http_encoding_api.h
1732 +# Begin Source File
1734 +SOURCE=.\php_http_request_api.h
1736 +# Begin Source File
1738 +SOURCE=.\php_http_request_int.h
1740 +# Begin Source File
1742 +SOURCE=.\php_http_request_body_api.h
1744 +# Begin Source File
1746 +SOURCE=.\php_http_request_method_api.h
1748 +# Begin Source File
1750 +SOURCE=.\php_http_persistent_handle_api.h
1752 +# Begin Source File
1754 +SOURCE=.\php_http_cache_api.h
1756 +# Begin Source File
1758 +SOURCE=.\php_http_cookie_api.h
1760 +# Begin Source File
1762 +SOURCE=.\php_http_date_api.h
1764 +# Begin Source File
1766 +SOURCE=.\php_http_message_api.h
1768 +# Begin Source File
1770 +SOURCE=.\php_http_send_api.h
1772 +# Begin Source File
1774 +SOURCE=.\php_http_headers_api.h
1776 +# Begin Source File
1778 +SOURCE=.\php_http_url_api.h
1780 +# Begin Source File
1782 +SOURCE=.\php_http_querystring_api.h
1784 +# Begin Source File
1786 +SOURCE=.\php_http_info_api.h
1788 +# Begin Source File
1790 +SOURCE=.\php_http_std_defs.h
1792 +# Begin Source File
1794 +SOURCE=.\phpstr\phpstr.h
1797 +# Begin Group "Resource Files"
1799 +# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
1804 +++ b/ext/http/http_api.c
1807 + +--------------------------------------------------------------------+
1809 + +--------------------------------------------------------------------+
1810 + | Redistribution and use in source and binary forms, with or without |
1811 + | modification, are permitted provided that the conditions mentioned |
1812 + | in the accompanying LICENSE file are met. |
1813 + +--------------------------------------------------------------------+
1814 + | Copyright (c) 2004-2010, Michael Wallner <mike@php.net> |
1815 + +--------------------------------------------------------------------+
1818 +/* $Id: http_api.c 323405 2012-02-21 10:05:05Z mike $ */
1820 +#define HTTP_WANT_SAPI
1821 +#include "php_http.h"
1823 +#include "php_output.h"
1824 +#include "ext/standard/url.h"
1825 +#include "ext/standard/php_lcg.h"
1827 +#include "php_http_api.h"
1828 +#include "php_http_send_api.h"
1830 +#ifdef ZEND_ENGINE_2
1831 +# include "php_http_exception_object.h"
1834 +PHP_MINIT_FUNCTION(http_support)
1836 + HTTP_LONG_CONSTANT("HTTP_SUPPORT", HTTP_SUPPORT);
1837 + HTTP_LONG_CONSTANT("HTTP_SUPPORT_REQUESTS", HTTP_SUPPORT_REQUESTS);
1838 + HTTP_LONG_CONSTANT("HTTP_SUPPORT_MAGICMIME", HTTP_SUPPORT_MAGICMIME);
1839 + HTTP_LONG_CONSTANT("HTTP_SUPPORT_ENCODINGS", HTTP_SUPPORT_ENCODINGS);
1840 + HTTP_LONG_CONSTANT("HTTP_SUPPORT_SSLREQUESTS", HTTP_SUPPORT_SSLREQUESTS);
1841 + HTTP_LONG_CONSTANT("HTTP_SUPPORT_EVENTS", HTTP_SUPPORT_EVENTS);
1843 + HTTP_LONG_CONSTANT("HTTP_PARAMS_ALLOW_COMMA", HTTP_PARAMS_ALLOW_COMMA);
1844 + HTTP_LONG_CONSTANT("HTTP_PARAMS_ALLOW_FAILURE", HTTP_PARAMS_ALLOW_FAILURE);
1845 + HTTP_LONG_CONSTANT("HTTP_PARAMS_RAISE_ERROR", HTTP_PARAMS_RAISE_ERROR);
1846 + HTTP_LONG_CONSTANT("HTTP_PARAMS_DEFAULT", HTTP_PARAMS_DEFAULT);
1851 +PHP_HTTP_API long _http_support(long feature)
1853 + long support = HTTP_SUPPORT;
1855 +#ifdef HTTP_HAVE_CURL
1856 + support |= HTTP_SUPPORT_REQUESTS;
1857 +# ifdef HTTP_HAVE_SSL
1858 + support |= HTTP_SUPPORT_SSLREQUESTS;
1860 +# ifdef HTTP_HAVE_EVENT
1861 + support |= HTTP_SUPPORT_EVENTS;
1864 +#ifdef HTTP_HAVE_MAGIC
1865 + support |= HTTP_SUPPORT_MAGICMIME;
1867 +#ifdef HTTP_HAVE_ZLIB
1868 + support |= HTTP_SUPPORT_ENCODINGS;
1872 + return (feature == (support & feature));
1877 +/* char *pretty_key(char *, size_t, zend_bool, zend_bool) */
1878 +char *_http_pretty_key(char *key, size_t key_len, zend_bool uctitle, zend_bool xhyphen)
1883 + if (key && key_len) {
1884 + if ((wasalpha = HTTP_IS_CTYPE(alpha, key[0]))) {
1885 + key[0] = (char) (uctitle ? HTTP_TO_CTYPE(upper, key[0]) : HTTP_TO_CTYPE(lower, key[0]));
1887 + for (i = 1; i < key_len; i++) {
1888 + if (HTTP_IS_CTYPE(alpha, key[i])) {
1889 + key[i] = (char) (((!wasalpha) && uctitle) ? HTTP_TO_CTYPE(upper, key[i]) : HTTP_TO_CTYPE(lower, key[i]));
1892 + if (xhyphen && (key[i] == '_')) {
1903 +/* {{{ http_boundary(char *, size_t) */
1904 +size_t _http_boundary(char *buf, size_t buf_len TSRMLS_DC)
1906 + return snprintf(buf, buf_len, "%lu%0.9f", (ulong) HTTP_G->request.time, (float) php_combined_lcg(TSRMLS_C));
1910 +/* {{{ void http_error(long, long, char*) */
1911 +void _http_error_ex(long type TSRMLS_DC, long code, const char *format, ...)
1915 + va_start(args, format);
1916 +#ifdef ZEND_ENGINE_2
1917 + if ((type == E_THROW) || (GLOBAL_ERROR_HANDLING == EH_THROW)) {
1919 + zend_class_entry *ce = http_exception_get_for_code(code);
1922 + vspprintf(&message, 0, format, args);
1923 + zend_throw_exception(ce, message, code TSRMLS_CC);
1925 + } http_catch(GLOBAL_EXCEPTION_CLASS ? GLOBAL_EXCEPTION_CLASS : HTTP_EX_DEF_CE);
1928 + php_verror(NULL, "", type, format, args TSRMLS_CC);
1933 +#ifdef ZEND_ENGINE_2
1934 +static inline void copy_bt_args(zval *from, zval *to TSRMLS_DC)
1936 + zval **args, **trace_0, *old_trace_0, *trace = NULL;
1938 + if ((trace = zend_read_property(ZEND_EXCEPTION_GET_DEFAULT(), from, "trace", lenof("trace"), 0 TSRMLS_CC))) {
1939 + if (Z_TYPE_P(trace) == IS_ARRAY && SUCCESS == zend_hash_index_find(Z_ARRVAL_P(trace), 0, (void *) &trace_0)) {
1940 + old_trace_0 = *trace_0;
1941 + if (Z_TYPE_PP(trace_0) == IS_ARRAY && SUCCESS == zend_hash_find(Z_ARRVAL_PP(trace_0), "args", sizeof("args"), (void *) &args)) {
1942 + if ((trace = zend_read_property(ZEND_EXCEPTION_GET_DEFAULT(), to, "trace", lenof("trace"), 0 TSRMLS_CC))) {
1943 + if (Z_TYPE_P(trace) == IS_ARRAY && SUCCESS == zend_hash_index_find(Z_ARRVAL_P(trace), 0, (void *) &trace_0)) {
1944 + ZVAL_ADDREF(*args);
1945 + add_assoc_zval(*trace_0, "args", *args);
1953 +/* {{{ zval *http_exception_wrap(zval *, zval *, zend_class_entry *) */
1954 +zval *_http_exception_wrap(zval *old_exception, zval *new_exception, zend_class_entry *ce TSRMLS_DC)
1958 + zval *sub_exception, *tmp_exception;
1960 + if (!new_exception) {
1961 + MAKE_STD_ZVAL(new_exception);
1962 + object_init_ex(new_exception, ce);
1964 + zend_update_property(ce, new_exception, "innerException", lenof("innerException"), old_exception TSRMLS_CC);
1965 + copy_bt_args(old_exception, new_exception TSRMLS_CC);
1967 + sub_exception = old_exception;
1969 + while ((sub_exception = zend_read_property(Z_OBJCE_P(sub_exception), sub_exception, "innerException", lenof("innerException"), 0 TSRMLS_CC)) && Z_TYPE_P(sub_exception) == IS_OBJECT) {
1973 + spprintf(&message, 0, "Exception caused by %d inner exception(s)", inner);
1974 + zend_update_property_string(ZEND_EXCEPTION_GET_DEFAULT(), new_exception, "message", lenof("message"), message TSRMLS_CC);
1977 + sub_exception = new_exception;
1978 + tmp_exception = new_exception;
1980 + while ((tmp_exception = zend_read_property(Z_OBJCE_P(tmp_exception), tmp_exception, "innerException", lenof("innerException"), 0 TSRMLS_CC)) && Z_TYPE_P(tmp_exception) == IS_OBJECT) {
1981 + sub_exception = tmp_exception;
1984 + zend_update_property(Z_OBJCE_P(sub_exception), sub_exception, "innerException", lenof("innerException"), old_exception TSRMLS_CC);
1985 + copy_bt_args(old_exception, new_exception TSRMLS_CC);
1986 + copy_bt_args(old_exception, sub_exception TSRMLS_CC);
1988 +#if PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 3
1989 + Z_ADDREF_P(old_exception);
1990 + zend_exception_set_previous(new_exception, old_exception TSRMLS_CC);
1992 + zval_ptr_dtor(&old_exception);
1993 + return new_exception;
1997 +/* {{{ STATUS http_object_new(zend_object_value *, const char *, uint, http_object_new_t, zend_class_entry *, void *, void **) */
1998 +STATUS _http_object_new(zend_object_value *ov, const char *cname_str, uint cname_len, http_object_new_t create, zend_class_entry *parent_ce, void *intern_ptr, void **obj_ptr TSRMLS_DC)
2000 + zend_class_entry *ce = parent_ce;
2002 + if (cname_str && cname_len) {
2003 + if (!(ce = zend_fetch_class(HTTP_ZAPI_CONST_CAST(char *) cname_str, cname_len, ZEND_FETCH_CLASS_DEFAULT TSRMLS_CC))) {
2006 + if (!instanceof_function(ce, parent_ce TSRMLS_CC)) {
2007 + http_error_ex(HE_WARNING, HTTP_E_RUNTIME, "Class %s does not extend %s", cname_str, parent_ce->name);
2012 + *ov = create(ce, intern_ptr, obj_ptr TSRMLS_CC);
2016 +#endif /* ZEND_ENGINE_2 */
2018 +/* {{{ void http_log(char *, char *, char *) */
2019 +void _http_log_ex(char *file, const char *ident, const char *message TSRMLS_DC)
2023 + char datetime[20] = {0};
2025 + now = HTTP_G->request.time;
2026 + strftime(datetime, sizeof(datetime), "%Y-%m-%d %H:%M:%S", php_localtime_r(&now, &nowtm));
2028 +#define HTTP_LOG_WRITE(file, type, msg) \
2029 + if (file && *file) { \
2030 + php_stream *log = php_stream_open_wrapper_ex(file, "ab", REPORT_ERRORS|ENFORCE_SAFE_MODE, NULL, HTTP_DEFAULT_STREAM_CONTEXT); \
2033 + php_stream_printf(log TSRMLS_CC, "%s\t[%s]\t%s\t<%s>%s", datetime, type, msg, SG(request_info).request_uri, PHP_EOL); \
2034 + php_stream_close(log); \
2039 + HTTP_LOG_WRITE(file, ident, message);
2040 + HTTP_LOG_WRITE(HTTP_G->log.composite, ident, message);
2044 +static void http_ob_blackhole(char *output, uint output_len, char **handled_output, uint *handled_output_len, int mode TSRMLS_DC)
2046 + *handled_output = ecalloc(1,1);
2047 + *handled_output_len = 0;
2050 +/* {{{ STATUS http_exit(int, char*, char*) */
2051 +STATUS _http_exit_ex(int status, char *header, char *body, zend_bool send_header TSRMLS_DC)
2053 + if ( (send_header && (SUCCESS != http_send_status_header(status, header))) ||
2054 + (status && (SUCCESS != http_send_status(status)))) {
2055 + http_error_ex(HE_WARNING, HTTP_E_HEADER, "Failed to exit with status/header: %d - %s", status, STR_PTR(header));
2061 +#ifndef PHP_OUTPUT_NEWAPI
2062 + if (!OG(ob_lock) &&
2063 + !php_ob_handler_used("zlib output compression" TSRMLS_CC) && !php_ob_handler_used("ob_gzhandler" TSRMLS_CC)) {
2064 + php_end_ob_buffers(0 TSRMLS_CC);
2068 + if ((SUCCESS == sapi_send_headers(TSRMLS_C)) && body) {
2069 + PHPWRITE(body, strlen(body));
2073 + case 301: http_log(HTTP_G->log.redirect, "301-REDIRECT", header); break;
2074 + case 302: http_log(HTTP_G->log.redirect, "302-REDIRECT", header); break;
2075 + case 303: http_log(HTTP_G->log.redirect, "303-REDIRECT", header); break;
2076 + case 305: http_log(HTTP_G->log.redirect, "305-REDIRECT", header); break;
2077 + case 307: http_log(HTTP_G->log.redirect, "307-REDIRECT", header); break;
2078 + case 304: http_log(HTTP_G->log.cache, "304-CACHE", header); break;
2079 + case 404: http_log(HTTP_G->log.not_found, "404-NOTFOUND", NULL); break;
2080 + case 405: http_log(HTTP_G->log.allowed_methods, "405-ALLOWED", header); break;
2081 + default: http_log(NULL, header, body); break;
2087 + if (HTTP_G->force_exit) {
2090 +#ifdef PHP_OUTPUT_NEWAPI
2091 + php_output_start_devnull(TSRMLS_C);
2093 + php_ob_set_internal_handler(http_ob_blackhole, 4096, "blackhole", 0 TSRMLS_CC);
2101 +/* {{{ STATUS http_check_method(char *) */
2102 +STATUS _http_check_method_ex(const char *method, const char *methods)
2104 + const char *found;
2106 + if ( (found = strstr(methods, method)) &&
2107 + (found == method || !HTTP_IS_CTYPE(alpha, found[-1])) &&
2108 + (strlen(found) >= strlen(method) && !HTTP_IS_CTYPE(alpha, found[strlen(method)]))) {
2115 +/* {{{ zval *http_get_server_var_ex(char *, size_t) */
2116 +PHP_HTTP_API zval *_http_get_server_var_ex(const char *key, size_t key_len, zend_bool check TSRMLS_DC)
2118 + zval **hsv, **var;
2121 + /* if available, this is a lot faster than accessing $_SERVER */
2122 + if (sapi_module.getenv) {
2123 + if ((!(env = sapi_module.getenv((char *) key, key_len TSRMLS_CC))) || (check && !*env)) {
2126 + if (HTTP_G->server_var) {
2127 + zval_ptr_dtor(&HTTP_G->server_var);
2129 + MAKE_STD_ZVAL(HTTP_G->server_var);
2130 + ZVAL_STRING(HTTP_G->server_var, env, 1);
2131 + return HTTP_G->server_var;
2134 +#ifdef ZEND_ENGINE_2
2135 + zend_is_auto_global("_SERVER", lenof("_SERVER") TSRMLS_CC);
2138 + if ((SUCCESS != zend_hash_find(&EG(symbol_table), "_SERVER", sizeof("_SERVER"), (void *) &hsv)) || (Z_TYPE_PP(hsv) != IS_ARRAY)) {
2141 + if ((SUCCESS != zend_hash_find(Z_ARRVAL_PP(hsv), HTTP_ZAPI_CONST_CAST(char *) key, key_len + 1, (void *) &var))) {
2144 + if (check && !((Z_TYPE_PP(var) == IS_STRING) && Z_STRVAL_PP(var) && Z_STRLEN_PP(var))) {
2151 +/* {{{ STATUS http_get_request_body(char **, size_t *) */
2152 +PHP_HTTP_API STATUS _http_get_request_body_ex(char **body, size_t *length, zend_bool dup TSRMLS_DC)
2157 + if (SG(request_info).raw_post_data) {
2158 + *length = SG(request_info).raw_post_data_length;
2159 + *body = SG(request_info).raw_post_data;
2162 + *body = estrndup(*body, *length);
2165 + } else if (sapi_module.read_post && !HTTP_G->read_post_data) {
2166 + char *buf = emalloc(4096);
2169 + HTTP_G->read_post_data = 1;
2171 + while (0 < (len = sapi_module.read_post(buf, 4096 TSRMLS_CC))) {
2172 + SG(read_post_bytes) += len;
2173 + *body = erealloc(*body, *length + len + 1);
2174 + memcpy(*body + *length, buf, len);
2176 + (*body)[*length] = '\0';
2183 + /* check for error */
2190 + SG(request_info).raw_post_data = *body;
2191 + SG(request_info).raw_post_data_length = *length;
2194 + *body = estrndup(*body, *length);
2203 +/* {{{ php_stream *http_get_request_body_stream(void) */
2204 +PHP_HTTP_API php_stream *_http_get_request_body_stream(TSRMLS_D)
2206 + php_stream *s = NULL;
2208 + if (SG(request_info).raw_post_data) {
2209 + s = php_stream_open_wrapper("php://input", "rb", 0, NULL);
2210 + } else if (sapi_module.read_post && !HTTP_G->read_post_data) {
2211 + HTTP_G->read_post_data = 1;
2213 + if ((s = php_stream_temp_new())) {
2214 + char *buf = emalloc(4096);
2217 + while (0 < (len = sapi_module.read_post(buf, 4096 TSRMLS_CC))) {
2218 + SG(read_post_bytes) += len;
2219 + php_stream_write(s, buf, len);
2227 + php_stream_close(s);
2230 + php_stream_rewind(s);
2239 +/* {{{ void http_parse_params_default_callback(...) */
2240 +PHP_HTTP_API void _http_parse_params_default_callback(void *arg, const char *key, int keylen, const char *val, int vallen TSRMLS_DC)
2244 + HashTable *ht = (HashTable *) arg;
2247 + INIT_ZARR(tmp, ht);
2250 + MAKE_STD_ZVAL(entry);
2251 + array_init(entry);
2253 + kdup = estrndup(key, keylen);
2254 + add_assoc_stringl_ex(entry, kdup, keylen + 1, (char *) val, vallen, 1);
2257 + add_next_index_stringl(entry, (char *) val, vallen, 1);
2259 + add_next_index_zval(&tmp, entry);
2261 + add_next_index_stringl(&tmp, (char *) key, keylen, 1);
2267 +/* {{{ STATUS http_parse_params(const char *, HashTable *) */
2268 +PHP_HTTP_API STATUS _http_parse_params_ex(const char *param, int flags, http_parse_params_callback cb, void *cb_arg TSRMLS_DC)
2273 +#define ST_ASSIGN 4
2276 + int st = ST_KEY, keylen = 0, vallen = 0;
2277 + char *s, *c, *key = NULL, *val = NULL;
2279 + for(c = s = estrdup(param);;) {
2283 + char *tk = NULL, *tv = NULL;
2287 + tk= estrndup(key, keylen);
2289 + tk = ecalloc(1, 7);
2290 + memcpy(tk, key, 3);
2291 + tk[3]='.'; tk[4]='.'; tk[5]='.';
2296 + tv = estrndup(val, vallen);
2298 + tv = ecalloc(1, 7);
2299 + memcpy(tv, val, 3);
2300 + tv[3]='.'; tv[4]='.'; tv[5]='.';
2303 + fprintf(stderr, "[%6s] %c \"%s=%s\"\n",
2305 + st == ST_QUOTE ? "QUOTE" :
2306 + st == ST_VALUE ? "VALUE" :
2307 + st == ST_KEY ? "KEY" :
2308 + st == ST_ASSIGN ? "ASSIGN" :
2309 + st == ST_ADD ? "ADD":
2311 + ), *c?*c:'0', tk, tv
2313 + STR_FREE(tk); STR_FREE(tv);
2320 + if (*(c-1) == '\\') {
2321 + memmove(c-1, c, strlen(c)+1);
2353 + if (flags & HTTP_PARAMS_ALLOW_COMMA) {
2367 + if (flags & HTTP_PARAMS_ALLOW_COMMA) {
2389 + keylen = c-- - key;
2395 + if (!(flags & HTTP_PARAMS_COLON_SEPARATOR)) {
2396 + goto not_separator;
2407 + if (flags & HTTP_PARAMS_COLON_SEPARATOR) {
2408 + goto not_separator;
2430 + } else if (!*c || *c == ';' || ((flags & HTTP_PARAMS_ALLOW_COMMA) && *c == ',')) {
2432 + } else if (*c != ' ') {
2441 + if (st != ST_QUOTE) {
2442 + while (val[vallen-1] == ' ') --vallen;
2449 + cb(cb_arg, key, keylen, val, vallen TSRMLS_CC);
2453 + keylen = vallen = 0;
2458 + } else if (st == ST_ADD) {
2469 + if (flags & HTTP_PARAMS_RAISE_ERROR) {
2470 + http_error_ex(HE_WARNING, HTTP_E_INVALID_PARAM, "Unexpected character (%c) at pos %tu of %zu", *c, c-s, strlen(s));
2472 + if (flags & HTTP_PARAMS_ALLOW_FAILURE) {
2473 + if (st == ST_KEY) {
2490 +/* {{{ array_join */
2491 +int apply_array_append_func(void *pDest HTTP_ZAPI_HASH_TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key)
2496 + zval **data = NULL, **value = (zval **) pDest;
2498 + dst = va_arg(args, HashTable *);
2499 + flags = va_arg(args, int);
2501 + if ((!(flags & ARRAY_JOIN_STRONLY)) || hash_key->nKeyLength) {
2502 + if ((flags & ARRAY_JOIN_PRETTIFY) && hash_key->nKeyLength) {
2503 + key = pretty_key(estrndup(hash_key->arKey, hash_key->nKeyLength - 1), hash_key->nKeyLength - 1, 1, 1);
2504 + zend_hash_find(dst, key, hash_key->nKeyLength, (void *) &data);
2506 + zend_hash_quick_find(dst, hash_key->arKey, hash_key->nKeyLength, hash_key->h, (void *) &data);
2509 + ZVAL_ADDREF(*value);
2511 + add_next_index_zval(http_zset(IS_ARRAY, *data), *value);
2513 + zend_hash_add(dst, key, hash_key->nKeyLength, value, sizeof(zval *), NULL);
2515 + zend_hash_quick_add(dst, hash_key->arKey, hash_key->nKeyLength, hash_key->h, value, sizeof(zval *), NULL);
2523 + return ZEND_HASH_APPLY_KEEP;
2526 +int apply_array_merge_func(void *pDest HTTP_ZAPI_HASH_TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key)
2531 + zval **value = (zval **) pDest;
2533 + dst = va_arg(args, HashTable *);
2534 + flags = va_arg(args, int);
2536 + if ((!(flags & ARRAY_JOIN_STRONLY)) || hash_key->nKeyLength) {
2537 + ZVAL_ADDREF(*value);
2538 + if ((flags & ARRAY_JOIN_PRETTIFY) && hash_key->nKeyLength) {
2539 + key = pretty_key(estrndup(hash_key->arKey, hash_key->nKeyLength - 1), hash_key->nKeyLength - 1, 1, 1);
2540 + zend_hash_update(dst, key, hash_key->nKeyLength, (void *) value, sizeof(zval *), NULL);
2543 + zend_hash_quick_update(dst, hash_key->arKey, hash_key->nKeyLength, hash_key->h, (void *) value, sizeof(zval *), NULL);
2547 + return ZEND_HASH_APPLY_KEEP;
2552 + * Local variables:
2554 + * c-basic-offset: 4
2556 + * vim600: noet sw=4 ts=4 fdm=marker
2557 + * vim<600: noet sw=4 ts=4
2561 +++ b/ext/http/http_cache_api.c
2564 + +--------------------------------------------------------------------+
2566 + +--------------------------------------------------------------------+
2567 + | Redistribution and use in source and binary forms, with or without |
2568 + | modification, are permitted provided that the conditions mentioned |
2569 + | in the accompanying LICENSE file are met. |
2570 + +--------------------------------------------------------------------+
2571 + | Copyright (c) 2004-2010, Michael Wallner <mike@php.net> |
2572 + +--------------------------------------------------------------------+
2575 +/* $Id: http_cache_api.c 323304 2012-02-17 21:13:24Z mike $ */
2577 +#define HTTP_WANT_SAPI
2578 +#include "php_http.h"
2580 +#include "php_output.h"
2581 +#include "php_streams.h"
2583 +#include "php_http_api.h"
2584 +#include "php_http_cache_api.h"
2585 +#include "php_http_date_api.h"
2586 +#include "php_http_send_api.h"
2588 +/* {{{ char *http_etag(void *, size_t, http_send_mode) */
2589 +PHP_HTTP_API char *_http_etag(const void *data_ptr, size_t data_len, http_send_mode data_mode TSRMLS_DC)
2591 + void *ctx = http_etag_init();
2593 + if (data_mode == SEND_DATA) {
2594 + http_etag_update(ctx, data_ptr, data_len);
2596 + STATUS ss = FAILURE;
2597 + php_stream_statbuf ssb;
2599 + if (data_mode == SEND_RSRC) {
2600 + ss = php_stream_stat((php_stream *) data_ptr, &ssb);
2602 + ss = php_stream_stat_path((char *) data_ptr, &ssb);
2605 + if (SUCCESS != ss) {
2610 + char ssb_buf[128];
2612 + ssb_len = snprintf(ssb_buf, sizeof(ssb_buf), "%ld=%ld=%ld", (long) ssb.sb.st_mtime,
2613 + (long) ssb.sb.st_ino,
2614 + (long) ssb.sb.st_size);
2615 + http_etag_update(ctx, ssb_buf, ssb_len);
2619 + return http_etag_finish(ctx);
2623 +/* {{{ time_t http_last_modified(void *, http_send_mode) */
2624 +PHP_HTTP_API time_t _http_last_modified(const void *data_ptr, http_send_mode data_mode TSRMLS_DC)
2626 + php_stream_statbuf ssb;
2628 + switch (data_mode) {
2629 + case SEND_DATA: return HTTP_G->request.time;
2630 + case SEND_RSRC: return php_stream_stat((php_stream *) data_ptr, &ssb) ? 0 : ssb.sb.st_mtime;
2631 + default: return php_stream_stat_path((char *) data_ptr, &ssb) ? 0 : ssb.sb.st_mtime;
2636 +/* {{{ zend_bool http_match_last_modified(char *, time_t) */
2637 +PHP_HTTP_API zend_bool _http_match_last_modified_ex(const char *entry, time_t t, zend_bool enforce_presence TSRMLS_DC)
2641 + char *modified, *chr_ptr;
2643 + if (!(zmodified = http_get_server_var(entry, 1))) {
2644 + return !enforce_presence;
2647 + modified = estrndup(Z_STRVAL_P(zmodified), Z_STRLEN_P(zmodified));
2648 + if ((chr_ptr = strrchr(modified, ';'))) {
2652 + retval = (t <= http_parse_date_ex(modified, 1));
2658 +/* {{{ zend_bool http_match_etag(char *, char *) */
2659 +PHP_HTTP_API zend_bool _http_match_etag_ex(const char *entry, const char *etag, zend_bool enforce_presence TSRMLS_DC)
2662 + char *quoted_etag;
2665 + if (!(zetag = http_get_server_var_ex(entry, strlen(entry)+1, 1))) {
2666 + return !enforce_presence;
2669 + if (NULL != strchr(Z_STRVAL_P(zetag), '*')) {
2673 + spprintf("ed_etag, 0, "\"%s\"", etag);
2674 + if (!strchr(Z_STRVAL_P(zetag), ',')) {
2675 + result = !strcmp(Z_STRVAL_P(zetag), quoted_etag);
2677 + result = (NULL != strstr(Z_STRVAL_P(zetag), quoted_etag));
2679 + efree(quoted_etag);
2685 +/* {{{ STATUS http_cache_last_modified(time_t, time_t, char *, size_t) */
2686 +PHP_HTTP_API STATUS _http_cache_last_modified(time_t last_modified,
2687 + time_t send_modified, const char *cache_control, size_t cc_len TSRMLS_DC)
2689 + char *sent_header = NULL;
2691 + if (SG(headers_sent)) {
2695 + if (cc_len && (SUCCESS != http_send_cache_control(cache_control, cc_len))) {
2699 + if (SUCCESS != http_send_last_modified_ex(send_modified, &sent_header)) {
2703 + if (http_match_last_modified("HTTP_IF_MODIFIED_SINCE", last_modified)) {
2704 + http_exit_ex(304, sent_header, NULL, 0);
2706 + STR_FREE(sent_header);
2713 +/* {{{ STATUS http_cache_etag(char *, size_t, char *, size_t) */
2714 +PHP_HTTP_API STATUS _http_cache_etag(const char *etag, size_t etag_len,
2715 + const char *cache_control, size_t cc_len TSRMLS_DC)
2717 + char *sent_header = NULL;
2719 + if (SG(headers_sent)) {
2723 + if (cc_len && (SUCCESS != http_send_cache_control(cache_control, cc_len))) {
2728 + if (SUCCESS != http_send_etag_ex(etag, etag_len, &sent_header)) {
2731 + if (http_match_etag("HTTP_IF_NONE_MATCH", etag)) {
2732 + http_exit_ex(304, sent_header, NULL, 0);
2734 + STR_FREE(sent_header);
2739 + /* start ob_etaghandler */
2740 + return http_start_ob_etaghandler();
2744 +PHP_HTTP_API STATUS _http_start_ob_etaghandler(TSRMLS_D)
2746 + /* already running? */
2747 +#ifdef PHP_OUTPUT_NEWAPI
2750 + if (php_output_handler_conflict(ZEND_STRL("ob_etaghandler"), ZEND_STRL("ob_etaghandler") TSRMLS_CC)) {
2754 + if (php_ob_handler_used("ob_etaghandler" TSRMLS_CC)) {
2755 + http_error(HE_WARNING, HTTP_E_RUNTIME, "ob_etaghandler can only be used once");
2759 + HTTP_G->etag.started = 1;
2760 +#ifdef PHP_OUTPUT_NEWAPI
2761 + return php_output_start_internal(ZEND_STRL("ob_etaghandler"), _http_ob_etaghandler, HTTP_G->send.buffer_size, 0 TSRMLS_CC);
2763 + return php_start_ob_buffer_named("ob_etaghandler", HTTP_G->send.buffer_size, 0 TSRMLS_CC);
2767 +PHP_HTTP_API zend_bool _http_interrupt_ob_etaghandler(TSRMLS_D)
2769 + if (HTTP_G->etag.started) {
2770 + HTTP_G->etag.started = 0;
2771 + if (HTTP_G->etag.ctx) {
2772 + efree(HTTP_G->etag.ctx);
2773 + HTTP_G->etag.ctx = NULL;
2780 +/* {{{ void http_ob_etaghandler(char *, uint, char **, uint *, int) */
2781 +void _http_ob_etaghandler(char *output, uint output_len,
2782 + char **handled_output, uint *handled_output_len, int mode TSRMLS_DC)
2785 + *handled_output_len = output_len;
2786 + *handled_output = estrndup(output, output_len);
2788 + /* are we supposed to run? */
2789 + if (HTTP_G->etag.started) {
2790 + /* initialize the etag context */
2791 + if (mode & PHP_OUTPUT_HANDLER_START) {
2792 + HTTP_G->etag.ctx = http_etag_init();
2796 + http_etag_update(HTTP_G->etag.ctx, output, output_len);
2799 + if (mode & PHP_OUTPUT_HANDLER_END) {
2800 + char *sent_header = NULL;
2801 + char *etag = http_etag_finish(HTTP_G->etag.ctx);
2803 + HTTP_G->etag.ctx = NULL;
2805 + http_send_cache_control(HTTP_DEFAULT_CACHECONTROL, lenof(HTTP_DEFAULT_CACHECONTROL));
2806 + http_send_etag_ex(etag, strlen(etag), &sent_header);
2808 + if (http_match_etag("HTTP_IF_NONE_MATCH", etag)) {
2809 + /* force exit; ob within ob does not work */
2810 + HTTP_G->force_exit = 1;
2811 + http_exit_ex(304, sent_header, etag, 0);
2814 + STR_FREE(sent_header);
2822 + * Local variables:
2824 + * c-basic-offset: 4
2826 + * vim600: sw=4 ts=4 fdm=marker
2827 + * vim<600: sw=4 ts=4
2831 +++ b/ext/http/http_cookie_api.c
2834 + +--------------------------------------------------------------------+
2836 + +--------------------------------------------------------------------+
2837 + | Redistribution and use in source and binary forms, with or without |
2838 + | modification, are permitted provided that the conditions mentioned |
2839 + | in the accompanying LICENSE file are met. |
2840 + +--------------------------------------------------------------------+
2841 + | Copyright (c) 2004-2010, Michael Wallner <mike@php.net> |
2842 + +--------------------------------------------------------------------+
2845 +/* $Id: http_cookie_api.c 298662 2010-04-27 13:42:32Z mike $ */
2847 +#include "php_http.h"
2848 +#include "php_http_api.h"
2849 +#include "php_http_date_api.h"
2850 +#include "php_http_cookie_api.h"
2852 +#include "ext/standard/url.h"
2854 +/* {{{ PHP_MINIT_FUNCTION(http_cookie) */
2855 +PHP_MINIT_FUNCTION(http_cookie)
2857 + HTTP_LONG_CONSTANT("HTTP_COOKIE_PARSE_RAW", HTTP_COOKIE_PARSE_RAW);
2858 + HTTP_LONG_CONSTANT("HTTP_COOKIE_SECURE", HTTP_COOKIE_SECURE);
2859 + HTTP_LONG_CONSTANT("HTTP_COOKIE_HTTPONLY", HTTP_COOKIE_HTTPONLY);
2865 +/* {{{ http_cookie_list *http_cookie_list_init(http_cookie_list *) */
2866 +PHP_HTTP_API http_cookie_list *_http_cookie_list_init(http_cookie_list *list ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC TSRMLS_DC)
2869 + list = emalloc_rel(sizeof(http_cookie_list));
2872 + zend_hash_init(&list->cookies, 0, NULL, ZVAL_PTR_DTOR, 0);
2873 + zend_hash_init(&list->extras, 0, NULL, ZVAL_PTR_DTOR, 0);
2875 + list->path = NULL;
2876 + list->domain = NULL;
2877 + list->expires = 0;
2884 +/* {{{ void http_cookie_list_dtor(http_cookie_list *) */
2885 +PHP_HTTP_API void _http_cookie_list_dtor(http_cookie_list *list TSRMLS_DC)
2888 + zend_hash_destroy(&list->cookies);
2889 + zend_hash_destroy(&list->extras);
2891 + STR_SET(list->path, NULL);
2892 + STR_SET(list->domain, NULL);
2897 +/* {{{ void http_cookie_list_free(http_cookie_list **) */
2898 +PHP_HTTP_API void _http_cookie_list_free(http_cookie_list **list TSRMLS_DC)
2901 + http_cookie_list_dtor(*list);
2908 +/* {{{ const char *http_cookie_list_get_cookie(http_cookie_list *, const char*, size_t) */
2909 +PHP_HTTP_API const char *_http_cookie_list_get_cookie(http_cookie_list *list, const char *name, size_t name_len TSRMLS_DC)
2911 + zval **cookie = NULL;
2912 + if ((SUCCESS != zend_hash_find(&list->cookies, HTTP_ZAPI_CONST_CAST(char *) name, name_len + 1, (void *) &cookie)) || (Z_TYPE_PP(cookie) != IS_STRING)) {
2915 + return Z_STRVAL_PP(cookie);
2919 +/* {{{ const char *http_cookie_list_get_extra(http_cookie_list *, const char *, size_t) */
2920 +PHP_HTTP_API const char *_http_cookie_list_get_extra(http_cookie_list *list, const char *name, size_t name_len TSRMLS_DC)
2922 + zval **extra = NULL;
2923 + if ((SUCCESS != zend_hash_find(&list->extras, HTTP_ZAPI_CONST_CAST(char *) name, name_len + 1, (void *) &extra)) || (Z_TYPE_PP(extra) != IS_STRING)) {
2926 + return Z_STRVAL_PP(extra);
2930 +/* {{{ void http_cookie_list_add_cookie(http_cookie_list *, const char *, size_t, const char *, size_t) */
2931 +PHP_HTTP_API void _http_cookie_list_add_cookie(http_cookie_list *list, const char *name, size_t name_len, const char *value, size_t value_len TSRMLS_DC)
2933 + zval *cookie_value;
2934 + char *key = estrndup(name, name_len);
2935 + MAKE_STD_ZVAL(cookie_value);
2936 + ZVAL_STRINGL(cookie_value, estrndup(value, value_len), value_len, 0);
2937 + zend_hash_update(&list->cookies, key, name_len + 1, (void *) &cookie_value, sizeof(zval *), NULL);
2942 +/* {{{ void http_cookie_list_add_extr(http_cookie_list *, const char *, size_t, const char *, size_t) */
2943 +PHP_HTTP_API void _http_cookie_list_add_extra(http_cookie_list *list, const char *name, size_t name_len, const char *value, size_t value_len TSRMLS_DC)
2945 + zval *cookie_value;
2946 + char *key = estrndup(name, name_len);
2947 + MAKE_STD_ZVAL(cookie_value);
2948 + ZVAL_STRINGL(cookie_value, estrndup(value, value_len), value_len, 0);
2949 + zend_hash_update(&list->extras, key, name_len + 1, (void *) &cookie_value, sizeof(zval *), NULL);
2954 +typedef struct _http_parse_param_cb_arg_t {
2955 + http_cookie_list *list;
2957 + char **allowed_extras;
2958 +} http_parse_param_cb_arg;
2960 +/* {{{ static void http_parse_cookie_callback */
2961 +static void http_parse_cookie_callback(void *ptr, const char *key, int keylen, const char *val, int vallen TSRMLS_DC)
2963 + http_parse_param_cb_arg *arg = (http_parse_param_cb_arg *) ptr;
2965 +#define _KEY_IS(s) (keylen == lenof(s) && !strncasecmp(key, (s), keylen))
2966 + if _KEY_IS("path") {
2967 + STR_SET(arg->list->path, estrndup(val, vallen));
2968 + } else if _KEY_IS("domain") {
2969 + STR_SET(arg->list->domain, estrndup(val, vallen));
2970 + } else if _KEY_IS("expires") {
2971 + char *date = estrndup(val, vallen);
2972 + arg->list->expires = http_parse_date(date);
2974 + } else if _KEY_IS("secure") {
2975 + arg->list->flags |= HTTP_COOKIE_SECURE;
2976 + } else if _KEY_IS("httpOnly") {
2977 + arg->list->flags |= HTTP_COOKIE_HTTPONLY;
2979 + /* check for extra */
2980 + if (arg->allowed_extras) {
2981 + char **ae = arg->allowed_extras;
2983 + for (; *ae; ++ae) {
2984 + if ((size_t) keylen == strlen(*ae) && !strncasecmp(key, *ae, keylen)) {
2985 + if (arg->flags & HTTP_COOKIE_PARSE_RAW) {
2986 + http_cookie_list_add_extra(arg->list, key, keylen, val, vallen);
2988 + char *dec = estrndup(val, vallen);
2989 + int declen = php_url_decode(dec, vallen);
2991 + http_cookie_list_add_extra(arg->list, key, keylen, dec, declen);
2999 + if (arg->flags & HTTP_COOKIE_PARSE_RAW) {
3000 + http_cookie_list_add_cookie(arg->list, key, keylen, val, vallen);
3002 + char *dec = estrndup(val, vallen);
3003 + int declen = php_url_decode(dec, vallen);
3005 + http_cookie_list_add_cookie(arg->list, key, keylen, dec, declen);
3012 +/* {{{ http_cookie_list *http_parse_cookie(char *, long) */
3013 +PHP_HTTP_API http_cookie_list *_http_parse_cookie_ex(http_cookie_list *list, const char *string, long flags, char **allowed_extras TSRMLS_DC)
3015 + int free_list = !list;
3016 + http_parse_param_cb_arg arg;
3018 + list = http_cookie_list_init(list);
3021 + arg.flags = flags;
3022 + arg.allowed_extras = allowed_extras;
3024 + if (SUCCESS != http_parse_params_ex(string, HTTP_PARAMS_RAISE_ERROR, http_parse_cookie_callback, &arg)) {
3026 + http_cookie_list_free(&list);
3028 + http_cookie_list_dtor(list);
3037 +/* {{{ void http_cookie_list_tostruct(http_cookie_list *, zval *) */
3038 +PHP_HTTP_API void _http_cookie_list_tostruct(http_cookie_list *list, zval *strct TSRMLS_DC)
3040 + zval array, *cookies, *extras;
3042 + INIT_ZARR(array, HASH_OF(strct));
3044 + MAKE_STD_ZVAL(cookies);
3045 + array_init(cookies);
3046 + zend_hash_copy(Z_ARRVAL_P(cookies), &list->cookies, (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *));
3047 + add_assoc_zval(&array, "cookies", cookies);
3049 + MAKE_STD_ZVAL(extras);
3050 + array_init(extras);
3051 + zend_hash_copy(Z_ARRVAL_P(extras), &list->extras, (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *));
3052 + add_assoc_zval(&array, "extras", extras);
3054 + add_assoc_long(&array, "flags", list->flags);
3055 + add_assoc_long(&array, "expires", (long) list->expires);
3056 + add_assoc_string(&array, "path", STR_PTR(list->path), 1);
3057 + add_assoc_string(&array, "domain", STR_PTR(list->domain), 1);
3061 +/* {{{ http_cookie_list *http_cookie_list_fromstruct(http_cookie_list *, zval *strct) */
3062 +PHP_HTTP_API http_cookie_list *_http_cookie_list_fromstruct(http_cookie_list *list, zval *strct TSRMLS_DC)
3065 + HashTable *ht = HASH_OF(strct);
3067 + list = http_cookie_list_init(list);
3069 + if (SUCCESS == zend_hash_find(ht, "cookies", sizeof("cookies"), (void *) &tmp) && Z_TYPE_PP(tmp) == IS_ARRAY) {
3070 + zend_hash_copy(&list->cookies, Z_ARRVAL_PP(tmp), (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *));
3072 + if (SUCCESS == zend_hash_find(ht, "extras", sizeof("extras"), (void *) &tmp) && Z_TYPE_PP(tmp) == IS_ARRAY) {
3073 + zend_hash_copy(&list->extras, Z_ARRVAL_PP(tmp), (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *));
3075 + if (SUCCESS == zend_hash_find(ht, "flags", sizeof("flags"), (void *) &tmp)) {
3076 + switch (Z_TYPE_PP(tmp)) {
3078 + list->flags = Z_LVAL_PP(tmp);
3081 + list->flags = (long) Z_DVAL_PP(tmp);
3084 + cpy = http_zsep(IS_LONG, *tmp);
3085 + list->flags = Z_LVAL_P(cpy);
3086 + zval_ptr_dtor(&cpy);
3092 + if (SUCCESS == zend_hash_find(ht, "expires", sizeof("expires"), (void *) &tmp)) {
3093 + switch (Z_TYPE_PP(tmp)) {
3095 + list->expires = Z_LVAL_PP(tmp);
3098 + list->expires = (long) Z_DVAL_PP(tmp);
3101 + cpy = http_zsep(IS_LONG, *tmp);
3102 + if (Z_LVAL_P(cpy)) {
3103 + list->expires = Z_LVAL_P(cpy);
3105 + time_t expires = http_parse_date(Z_STRVAL_PP(tmp));
3106 + if (expires > 0) {
3107 + list->expires = expires;
3110 + zval_ptr_dtor(&cpy);
3116 + if (SUCCESS == zend_hash_find(ht, "path", sizeof("path"), (void *) &tmp) && Z_TYPE_PP(tmp) == IS_STRING) {
3117 + list->path = estrndup(Z_STRVAL_PP(tmp), Z_STRLEN_PP(tmp));
3119 + if (SUCCESS == zend_hash_find(ht, "domain", sizeof("domain"), (void *) &tmp) && Z_TYPE_PP(tmp) == IS_STRING) {
3120 + list->domain = estrndup(Z_STRVAL_PP(tmp), Z_STRLEN_PP(tmp));
3127 +/* {{{ inline append_encoded */
3128 +static inline void append_encoded(phpstr *buf, const char *key, size_t key_len, const char *val, size_t val_len)
3133 + enc_str[0] = php_url_encode(key, key_len, &enc_len[0]);
3134 + enc_str[1] = php_url_encode(val, val_len, &enc_len[1]);
3136 + phpstr_append(buf, enc_str[0], enc_len[0]);
3137 + phpstr_appends(buf, "=");
3138 + phpstr_append(buf, enc_str[1], enc_len[1]);
3139 + phpstr_appends(buf, "; ");
3141 + efree(enc_str[0]);
3142 + efree(enc_str[1]);
3146 +/* {{{ void http_cookie_list_tostring(http_cookie_list *, char **, size_t *) */
3147 +PHP_HTTP_API void _http_cookie_list_tostring(http_cookie_list *list, char **str, size_t *len TSRMLS_DC)
3151 + HashKey key = initHashKey(0);
3154 + phpstr_init(&buf);
3156 + FOREACH_HASH_KEYVAL(pos, &list->cookies, key, val) {
3157 + if (key.type == HASH_KEY_IS_STRING && key.len) {
3158 + zval *tmp = http_zsep(IS_STRING, *val);
3159 + append_encoded(&buf, key.str, key.len-1, Z_STRVAL_P(tmp), Z_STRLEN_P(tmp));
3160 + zval_ptr_dtor(&tmp);
3164 + if (list->domain && *list->domain) {
3165 + phpstr_appendf(&buf, "domain=%s; ", list->domain);
3167 + if (list->path && *list->path) {
3168 + phpstr_appendf(&buf, "path=%s; ", list->path);
3170 + if (list->expires) {
3171 + char *date = http_date(list->expires);
3172 + phpstr_appendf(&buf, "expires=%s; ", date);
3176 + FOREACH_HASH_KEYVAL(pos, &list->extras, key, val) {
3177 + if (key.type == HASH_KEY_IS_STRING && key.len) {
3178 + zval *tmp = http_zsep(IS_STRING, *val);
3179 + append_encoded(&buf, key.str, key.len-1, Z_STRVAL_P(tmp), Z_STRLEN_P(tmp));
3183 + if (list->flags & HTTP_COOKIE_SECURE) {
3184 + phpstr_appends(&buf, "secure; ");
3186 + if (list->flags & HTTP_COOKIE_HTTPONLY) {
3187 + phpstr_appends(&buf, "httpOnly; ");
3191 + *str = PHPSTR_VAL(&buf);
3192 + *len = PHPSTR_LEN(&buf);
3197 + * Local variables:
3199 + * c-basic-offset: 4
3201 + * vim600: noet sw=4 ts=4 fdm=marker
3202 + * vim<600: noet sw=4 ts=4
3205 +++ b/ext/http/http_date_api.c
3208 + +--------------------------------------------------------------------+
3210 + +--------------------------------------------------------------------+
3211 + | Redistribution and use in source and binary forms, with or without |
3212 + | modification, are permitted provided that the conditions mentioned |
3213 + | in the accompanying LICENSE file are met. |
3214 + +--------------------------------------------------------------------+
3215 + | Copyright (c) 2004-2010, Michael Wallner <mike@php.net> |
3216 + +--------------------------------------------------------------------+
3219 +/* $Id: http_date_api.c 292841 2009-12-31 08:48:57Z mike $ */
3221 +#include "php_http.h"
3223 +#include "php_http_api.h"
3224 +#include "php_http_date_api.h"
3226 +static inline int check_day(const char *day, size_t len);
3227 +static inline int check_month(const char *month);
3228 +static inline int check_tzone(const char *tzone);
3229 +static inline time_t parse_date(const char *month);
3231 +/* {{{ day/month names */
3232 +static const char *days[] = {
3233 + "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
3235 +static const char *wkdays[] = {
3236 + "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"
3238 +static const char *weekdays[] = {
3239 + "Monday", "Tuesday", "Wednesday",
3240 + "Thursday", "Friday", "Saturday", "Sunday"
3242 +static const char *months[] = {
3243 + "Jan", "Feb", "Mar", "Apr", "May", "Jun",
3244 + "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
3252 +static const struct time_zone {
3256 + {"GMT", 0}, /* Greenwich Mean */
3257 + {"UTC", 0}, /* Universal (Coordinated) */
3258 + {"WET", 0}, /* Western European */
3259 + {"BST", 0 DS}, /* British Summer */
3260 + {"WAT", 60}, /* West Africa */
3261 + {"AST", 240}, /* Atlantic Standard */
3262 + {"ADT", 240 DS},/* Atlantic Daylight */
3263 + {"EST", 300}, /* Eastern Standard */
3264 + {"EDT", 300 DS},/* Eastern Daylight */
3265 + {"CST", 360}, /* Central Standard */
3266 + {"CDT", 360 DS},/* Central Daylight */
3267 + {"MST", 420}, /* Mountain Standard */
3268 + {"MDT", 420 DS},/* Mountain Daylight */
3269 + {"PST", 480}, /* Pacific Standard */
3270 + {"PDT", 480 DS},/* Pacific Daylight */
3271 + {"YST", 540}, /* Yukon Standard */
3272 + {"YDT", 540 DS},/* Yukon Daylight */
3273 + {"HST", 600}, /* Hawaii Standard */
3274 + {"HDT", 600 DS},/* Hawaii Daylight */
3275 + {"CAT", 600}, /* Central Alaska */
3276 + {"AHST", 600}, /* Alaska-Hawaii Standard */
3277 + {"NT", 660}, /* Nome */
3278 + {"IDLW", 720}, /* International Date Line West */
3279 + {"CET", -60}, /* Central European */
3280 + {"MET", -60}, /* Middle European */
3281 + {"MEWT", -60}, /* Middle European Winter */
3282 + {"MEST", -60 DS},/* Middle European Summer */
3283 + {"CEST", -60 DS},/* Central European Summer */
3284 + {"MESZ", -60 DS},/* Middle European Summer */
3285 + {"FWT", -60}, /* French Winter */
3286 + {"FST", -60 DS},/* French Summer */
3287 + {"EET", -120}, /* Eastern Europe, USSR Zone 1 */
3288 + {"WAST", -420}, /* West Australian Standard */
3289 + {"WADT", -420 DS},/* West Australian Daylight */
3290 + {"CCT", -480}, /* China Coast, USSR Zone 7 */
3291 + {"JST", -540}, /* Japan Standard, USSR Zone 8 */
3292 + {"EAST", -600}, /* Eastern Australian Standard */
3293 + {"EADT", -600 DS},/* Eastern Australian Daylight */
3294 + {"GST", -600}, /* Guam Standard, USSR Zone 9 */
3295 + {"NZT", -720}, /* New Zealand */
3296 + {"NZST", -720}, /* New Zealand Standard */
3297 + {"NZDT", -720 DS},/* New Zealand Daylight */
3298 + {"IDLE", -720}, /* International Date Line East */
3302 +/* {{{ Day/Month/TZ checks for http_parse_date()
3303 + Originally by libcurl, Copyright (C) 1998 - 2004, Daniel Stenberg, <daniel@haxx.se>, et al. */
3304 +static inline int check_day(const char *day, size_t len)
3307 + const char * const *check = (len > 3) ? &weekdays[0] : &wkdays[0];
3308 + for (i = 0; i < 7; i++) {
3309 + if (!strcmp(day, check[0])) {
3317 +static inline int check_month(const char *month)
3320 + const char * const *check = &months[0];
3321 + for (i = 0; i < 12; i++) {
3322 + if (!strcmp(month, check[0])) {
3330 +/* return the time zone offset between GMT and the input one, in number
3331 + of seconds or -1 if the timezone wasn't found/legal */
3333 +static inline int check_tzone(const char *tzone)
3336 + const struct time_zone *check = time_zones;
3337 + for (i = 0; i < sizeof(time_zones) / sizeof(time_zones[0]); i++) {
3338 + if (!strcmp(tzone, check->name)) {
3339 + return check->offset * 60;
3347 +/* {{{ char *http_date(time_t) */
3348 +PHP_HTTP_API char *_http_date(time_t t TSRMLS_DC)
3350 + char *date = NULL;
3351 + struct tm *gmtime = NULL, tmbuf;
3353 + memset(&tmbuf, 0, sizeof(tmbuf));
3354 + if ((gmtime = php_gmtime_r(&t, &tmbuf))) {
3355 + spprintf(&date, 0,
3356 + "%s, %02d %s %04d %02d:%02d:%02d GMT",
3357 + days[gmtime->tm_wday], gmtime->tm_mday,
3358 + months[gmtime->tm_mon], gmtime->tm_year + 1900,
3359 + gmtime->tm_hour, gmtime->tm_min, gmtime->tm_sec
3367 +/* {{{ time_t http_parse_date(char *) */
3368 +PHP_HTTP_API time_t _http_parse_date_ex(const char *date, zend_bool silent TSRMLS_DC)
3370 + time_t t = parse_date(date);
3372 + if (-1 == t && !silent) {
3373 + http_error_ex(HE_NOTICE, HTTP_E_RUNTIME, "Could not parse date: %s", date);
3380 +/* time_t parse_date(char *)
3381 + Originally by libcurl, Copyright (C) 1998 - 2004, Daniel Stenberg, <daniel@haxx.se>, et al. */
3382 +static inline time_t parse_date(const char *date)
3385 + int tz_offset = -1, year = -1, month = -1, monthday = -1, weekday = -1,
3386 + hours = -1, minutes = -1, seconds = -1;
3388 + enum assume_next dignext = DATE_MDAY;
3389 + const char *indate = date;
3391 + int part = 0; /* max 6 parts */
3393 + while (*date && (part < 6)) {
3396 + while (*date && !HTTP_IS_CTYPE(alnum, *date)) {
3400 + if (HTTP_IS_CTYPE(alpha, *date)) {
3401 + /* a name coming up */
3402 + char buf[32] = "";
3404 + sscanf(date, "%31[A-Za-z]", buf);
3405 + len = strlen(buf);
3407 + if (weekday == -1) {
3408 + weekday = check_day(buf, len);
3409 + if (weekday != -1) {
3414 + if (!found && (month == -1)) {
3415 + month = check_month(buf);
3416 + if (month != -1) {
3421 + if (!found && (tz_offset == -1)) {
3422 + /* this just must be a time zone string */
3423 + tz_offset = check_tzone(buf);
3424 + if (tz_offset != -1) {
3430 + return -1; /* bad string */
3434 + else if (HTTP_IS_CTYPE(digit, *date)) {
3438 + if ((seconds == -1) &&
3439 + (3 == sscanf(date, "%02d:%02d:%02d", &hours, &minutes, &seconds))) {
3445 + val = (int) strtol(date, &end, 10);
3447 + if ((tz_offset == -1) && ((end - date) == 4) && (val < 1300) &&
3448 + (indate < date) && ((date[-1] == '+' || date[-1] == '-'))) {
3449 + /* four digits and a value less than 1300 and it is preceeded with
3450 + a plus or minus. This is a time zone indication. */
3452 + tz_offset = (val / 100 * 60 + val % 100) * 60;
3454 + /* the + and - prefix indicates the local time compared to GMT,
3455 + this we need ther reversed math to get what we want */
3456 + tz_offset = date[-1] == '+' ? -tz_offset : tz_offset;
3459 + if (((end - date) == 8) && (year == -1) && (month == -1) && (monthday == -1)) {
3460 + /* 8 digits, no year, month or day yet. This is YYYYMMDD */
3462 + year = val / 10000;
3463 + month = (val % 10000) / 100 - 1; /* month is 0 - 11 */
3464 + monthday = val % 100;
3467 + if (!found && (dignext == DATE_MDAY) && (monthday == -1)) {
3468 + if ((val > 0) && (val < 32)) {
3472 + dignext = DATE_YEAR;
3475 + if (!found && (dignext == DATE_YEAR) && (year == -1)) {
3478 + if (year < 1900) {
3479 + year += year > 70 ? 1900 : 2000;
3481 + if(monthday == -1) {
3482 + dignext = DATE_MDAY;
3497 + if (-1 == seconds) {
3498 + seconds = minutes = hours = 0; /* no time, make it zero */
3501 + if ((-1 == monthday) || (-1 == month) || (-1 == year)) {
3502 + /* lacks vital info, fail */
3506 + if (sizeof(time_t) < 5) {
3507 + /* 32 bit time_t can only hold dates to the beginning of 2038 */
3508 + if (year > 2037) {
3509 + return 0x7fffffff;
3513 + tm.tm_sec = seconds;
3514 + tm.tm_min = minutes;
3515 + tm.tm_hour = hours;
3516 + tm.tm_mday = monthday;
3517 + tm.tm_mon = month;
3518 + tm.tm_year = year - 1900;
3525 + /* time zone adjust */
3527 + struct tm *gmt, keeptime2;
3531 + if((gmt = php_gmtime_r(&t, &keeptime2))) {
3532 + tm = *gmt; /* MSVC quirks */
3534 + return -1; /* illegal date/time */
3539 + /* Add the time zone diff (between the given timezone and GMT) and the
3540 + diff between the local time zone and GMT. */
3541 + delta = (tz_offset != -1 ? tz_offset : 0) + (t - t2);
3543 + if((delta > 0) && (t + delta < t)) {
3544 + return -1; /* time_t overflow */
3556 + * Local variables:
3558 + * c-basic-offset: 4
3560 + * vim600: sw=4 ts=4 fdm=marker
3561 + * vim<600: sw=4 ts=4
3565 +++ b/ext/http/http_deflatestream_object.c
3568 + +--------------------------------------------------------------------+
3570 + +--------------------------------------------------------------------+
3571 + | Redistribution and use in source and binary forms, with or without |
3572 + | modification, are permitted provided that the conditions mentioned |
3573 + | in the accompanying LICENSE file are met. |
3574 + +--------------------------------------------------------------------+
3575 + | Copyright (c) 2004-2010, Michael Wallner <mike@php.net> |
3576 + +--------------------------------------------------------------------+
3579 +/* $Id: http_deflatestream_object.c 323304 2012-02-17 21:13:24Z mike $ */
3581 +#define HTTP_WANT_ZLIB
3582 +#include "php_http.h"
3584 +#if defined(ZEND_ENGINE_2) && defined(HTTP_HAVE_ZLIB)
3586 +#include "php_http_api.h"
3587 +#include "php_http_encoding_api.h"
3588 +#include "php_http_exception_object.h"
3589 +#include "php_http_deflatestream_object.h"
3591 +#define HTTP_BEGIN_ARGS(method, req_args) HTTP_BEGIN_ARGS_EX(HttpDeflateStream, method, 0, req_args)
3592 +#define HTTP_EMPTY_ARGS(method) HTTP_EMPTY_ARGS_EX(HttpDeflateStream, method, 0)
3593 +#define HTTP_DEFLATE_ME(method, visibility) PHP_ME(HttpDeflateStream, method, HTTP_ARGS(HttpDeflateStream, method), visibility)
3595 +HTTP_BEGIN_ARGS(__construct, 0)
3596 + HTTP_ARG_VAL(flags, 0)
3599 +HTTP_BEGIN_ARGS(factory, 0)
3600 + HTTP_ARG_VAL(flags, 0)
3601 + HTTP_ARG_VAL(class_name, 0)
3604 +HTTP_BEGIN_ARGS(update, 1)
3605 + HTTP_ARG_VAL(data, 0)
3608 +HTTP_BEGIN_ARGS(flush, 0)
3609 + HTTP_ARG_VAL(data, 0)
3612 +HTTP_BEGIN_ARGS(finish, 0)
3613 + HTTP_ARG_VAL(data, 0)
3616 +#define THIS_CE http_deflatestream_object_ce
3617 +zend_class_entry *http_deflatestream_object_ce;
3618 +zend_function_entry http_deflatestream_object_fe[] = {
3619 + HTTP_DEFLATE_ME(__construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
3620 + HTTP_DEFLATE_ME(update, ZEND_ACC_PUBLIC)
3621 + HTTP_DEFLATE_ME(flush, ZEND_ACC_PUBLIC)
3622 + HTTP_DEFLATE_ME(finish, ZEND_ACC_PUBLIC)
3624 + HTTP_DEFLATE_ME(factory, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
3626 + EMPTY_FUNCTION_ENTRY
3628 +static zend_object_handlers http_deflatestream_object_handlers;
3630 +PHP_MINIT_FUNCTION(http_deflatestream_object)
3632 + HTTP_REGISTER_CLASS_EX(HttpDeflateStream, http_deflatestream_object, NULL, 0);
3633 + http_deflatestream_object_handlers.clone_obj = _http_deflatestream_object_clone_obj;
3636 + zend_declare_class_constant_long(THIS_CE, ZEND_STRS("TYPE_GZIP")-1, HTTP_DEFLATE_TYPE_GZIP TSRMLS_CC);
3637 + zend_declare_class_constant_long(THIS_CE, ZEND_STRS("TYPE_ZLIB")-1, HTTP_DEFLATE_TYPE_ZLIB TSRMLS_CC);
3638 + zend_declare_class_constant_long(THIS_CE, ZEND_STRS("TYPE_RAW")-1, HTTP_DEFLATE_TYPE_RAW TSRMLS_CC);
3639 + zend_declare_class_constant_long(THIS_CE, ZEND_STRS("LEVEL_DEF")-1, HTTP_DEFLATE_LEVEL_DEF TSRMLS_CC);
3640 + zend_declare_class_constant_long(THIS_CE, ZEND_STRS("LEVEL_MIN")-1, HTTP_DEFLATE_LEVEL_MIN TSRMLS_CC);
3641 + zend_declare_class_constant_long(THIS_CE, ZEND_STRS("LEVEL_MAX")-1, HTTP_DEFLATE_LEVEL_MAX TSRMLS_CC);
3642 + zend_declare_class_constant_long(THIS_CE, ZEND_STRS("STRATEGY_DEF")-1, HTTP_DEFLATE_STRATEGY_DEF TSRMLS_CC);
3643 + zend_declare_class_constant_long(THIS_CE, ZEND_STRS("STRATEGY_FILT")-1, HTTP_DEFLATE_STRATEGY_FILT TSRMLS_CC);
3644 + zend_declare_class_constant_long(THIS_CE, ZEND_STRS("STRATEGY_HUFF")-1, HTTP_DEFLATE_STRATEGY_HUFF TSRMLS_CC);
3645 + zend_declare_class_constant_long(THIS_CE, ZEND_STRS("STRATEGY_RLE")-1, HTTP_DEFLATE_STRATEGY_RLE TSRMLS_CC);
3646 + zend_declare_class_constant_long(THIS_CE, ZEND_STRS("STRATEGY_FIXED")-1, HTTP_DEFLATE_STRATEGY_FIXED TSRMLS_CC);
3647 + zend_declare_class_constant_long(THIS_CE, ZEND_STRS("FLUSH_NONE")-1, HTTP_ENCODING_STREAM_FLUSH_NONE TSRMLS_CC);
3648 + zend_declare_class_constant_long(THIS_CE, ZEND_STRS("FLUSH_SYNC")-1, HTTP_ENCODING_STREAM_FLUSH_SYNC TSRMLS_CC);
3649 + zend_declare_class_constant_long(THIS_CE, ZEND_STRS("FLUSH_FULL")-1, HTTP_ENCODING_STREAM_FLUSH_FULL TSRMLS_CC);
3655 +zend_object_value _http_deflatestream_object_new(zend_class_entry *ce TSRMLS_DC)
3657 + return http_deflatestream_object_new_ex(ce, NULL, NULL);
3660 +zend_object_value _http_deflatestream_object_new_ex(zend_class_entry *ce, http_encoding_stream *s, http_deflatestream_object **ptr TSRMLS_DC)
3662 + zend_object_value ov;
3663 + http_deflatestream_object *o;
3665 + o = ecalloc(1, sizeof(http_deflatestream_object));
3676 +#ifdef ZEND_ENGINE_2_4
3677 + zend_object_std_init(o, ce TSRMLS_CC);
3678 + object_properties_init(o, ce);
3680 + ALLOC_HASHTABLE(OBJ_PROP(o));
3681 + zend_hash_init(OBJ_PROP(o), zend_hash_num_elements(&ce->default_properties), NULL, ZVAL_PTR_DTOR, 0);
3682 + zend_hash_copy(OBJ_PROP(o), &ce->default_properties, (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *));
3685 + ov.handle = putObject(http_deflatestream_object, o);
3686 + ov.handlers = &http_deflatestream_object_handlers;
3691 +zend_object_value _http_deflatestream_object_clone_obj(zval *this_ptr TSRMLS_DC)
3693 + http_encoding_stream *s;
3694 + zend_object_value new_ov;
3695 + http_deflatestream_object *new_obj = NULL;
3696 + getObject(http_deflatestream_object, old_obj);
3698 + s = ecalloc(1, sizeof(http_encoding_stream));
3699 + s->flags = old_obj->stream->flags;
3700 + deflateCopy(&s->stream, &old_obj->stream->stream);
3701 + s->stream.opaque = phpstr_dup(s->stream.opaque);
3703 + new_ov = http_deflatestream_object_new_ex(old_obj->zo.ce, s, &new_obj);
3704 + zend_objects_clone_members(&new_obj->zo, new_ov, &old_obj->zo, Z_OBJ_HANDLE_P(this_ptr) TSRMLS_CC);
3709 +void _http_deflatestream_object_free(zend_object *object TSRMLS_DC)
3711 + http_deflatestream_object *o = (http_deflatestream_object *) object;
3714 + http_encoding_deflate_stream_free(&o->stream);
3719 +/* {{{ proto void HttpDeflateStream::__construct([int flags = 0])
3720 + Creates a new HttpDeflateStream object instance. */
3721 +PHP_METHOD(HttpDeflateStream, __construct)
3725 + SET_EH_THROW_HTTP();
3726 + if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &flags)) {
3727 + getObject(http_deflatestream_object, obj);
3729 + if (!obj->stream) {
3730 + obj->stream = http_encoding_deflate_stream_init(NULL, flags & 0x0fffffff);
3732 + http_error_ex(HE_WARNING, HTTP_E_ENCODING, "HttpDeflateStream cannot be initialized twice");
3739 +/* {{{ proto HttpDeflateStream HttpDeflateStream::factory([int flags[, string class = "HttpDeflateStream"]])
3740 + Creates a new HttpDeflateStream object instance. */
3741 +PHP_METHOD(HttpDeflateStream, factory)
3747 + SET_EH_THROW_HTTP();
3748 + if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|ls", &flags, &cn, &cl)) {
3749 + zend_object_value ov;
3750 + http_encoding_stream *s = http_encoding_deflate_stream_init(NULL, flags & 0x0fffffff);
3752 + if (SUCCESS == http_object_new(&ov, cn, cl, _http_deflatestream_object_new_ex, http_deflatestream_object_ce, s, NULL)) {
3753 + RETVAL_OBJVAL(ov, 0);
3760 +/* {{{ proto string HttpDeflateStream::update(string data)
3761 + Passes more data through the deflate stream. */
3762 +PHP_METHOD(HttpDeflateStream, update)
3765 + size_t encoded_len = 0;
3766 + char *data, *encoded = NULL;
3767 + getObject(http_deflatestream_object, obj);
3769 + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &data, &data_len)) {
3773 + if (!obj->stream && !(obj->stream = http_encoding_deflate_stream_init(NULL, 0))) {
3777 + if (SUCCESS == http_encoding_deflate_stream_update(obj->stream, data, data_len, &encoded, &encoded_len)) {
3778 + RETURN_STRINGL(encoded, encoded_len, 0);
3785 +/* {{{ proto string HttpDeflateStream::flush([string data])
3786 + Flushes the deflate stream. */
3787 +PHP_METHOD(HttpDeflateStream, flush)
3790 + size_t updated_len = 0, encoded_len = 0;
3791 + char *updated = NULL, *encoded = NULL, *data = NULL;
3792 + getObject(http_deflatestream_object, obj);
3794 + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &data, &data_len)) {
3798 + if (!obj->stream && !(obj->stream = http_encoding_deflate_stream_init(NULL, 0))) {
3803 + if (SUCCESS != http_encoding_deflate_stream_update(obj->stream, data, data_len, &updated, &updated_len)) {
3808 + if (SUCCESS == http_encoding_deflate_stream_flush(obj->stream, &encoded, &encoded_len)) {
3809 + if (updated_len) {
3810 + updated = erealloc(updated, updated_len + encoded_len + 1);
3811 + updated[updated_len + encoded_len] = '\0';
3812 + memcpy(updated + updated_len, encoded, encoded_len);
3813 + STR_FREE(encoded);
3814 + updated_len += encoded_len;
3815 + RETURN_STRINGL(updated, updated_len, 0);
3816 + } else if (encoded) {
3817 + RETVAL_STRINGL(encoded, encoded_len, 0);
3824 + STR_FREE(updated);
3828 +/* {{{ proto string HttpDeflateStream::finish([string data])
3829 + Finalizes the deflate stream. The deflate stream can be reused after finalizing. */
3830 +PHP_METHOD(HttpDeflateStream, finish)
3833 + size_t updated_len = 0, encoded_len = 0;
3834 + char *updated = NULL, *encoded = NULL, *data = NULL;
3835 + getObject(http_deflatestream_object, obj);
3837 + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &data, &data_len)) {
3841 + if (!obj->stream && !(obj->stream = http_encoding_deflate_stream_init(NULL, 0))) {
3846 + if (SUCCESS != http_encoding_deflate_stream_update(obj->stream, data, data_len, &updated, &updated_len)) {
3851 + if (SUCCESS == http_encoding_deflate_stream_finish(obj->stream, &encoded, &encoded_len)) {
3852 + if (updated_len) {
3853 + updated = erealloc(updated, updated_len + encoded_len + 1);
3854 + updated[updated_len + encoded_len] = '\0';
3855 + memcpy(updated + updated_len, encoded, encoded_len);
3856 + STR_FREE(encoded);
3857 + updated_len += encoded_len;
3858 + RETVAL_STRINGL(updated, updated_len, 0);
3860 + STR_FREE(updated);
3861 + RETVAL_STRINGL(encoded, encoded_len, 0);
3864 + STR_FREE(updated);
3868 + http_encoding_deflate_stream_dtor(obj->stream);
3869 + http_encoding_deflate_stream_init(obj->stream, obj->stream->flags);
3873 +#endif /* ZEND_ENGINE_2 && HTTP_HAVE_ZLIB*/
3876 + * Local variables:
3878 + * c-basic-offset: 4
3880 + * vim600: noet sw=4 ts=4 fdm=marker
3881 + * vim<600: noet sw=4 ts=4
3885 +++ b/ext/http/http_encoding_api.c
3888 + +--------------------------------------------------------------------+
3890 + +--------------------------------------------------------------------+
3891 + | Redistribution and use in source and binary forms, with or without |
3892 + | modification, are permitted provided that the conditions mentioned |
3893 + | in the accompanying LICENSE file are met. |
3894 + +--------------------------------------------------------------------+
3895 + | Copyright (c) 2004-2010, Michael Wallner <mike@php.net> |
3896 + +--------------------------------------------------------------------+
3899 +/* $Id: http_encoding_api.c 323304 2012-02-17 21:13:24Z mike $ */
3901 +#define HTTP_WANT_ZLIB
3902 +#include "php_http.h"
3904 +#include "php_http_api.h"
3905 +#include "php_http_encoding_api.h"
3906 +#include "php_http_send_api.h"
3907 +#include "php_http_headers_api.h"
3910 +#ifdef HTTP_HAVE_ZLIB
3911 +PHP_MINIT_FUNCTION(http_encoding)
3913 + HTTP_LONG_CONSTANT("HTTP_DEFLATE_LEVEL_DEF", HTTP_DEFLATE_LEVEL_DEF);
3914 + HTTP_LONG_CONSTANT("HTTP_DEFLATE_LEVEL_MIN", HTTP_DEFLATE_LEVEL_MIN);
3915 + HTTP_LONG_CONSTANT("HTTP_DEFLATE_LEVEL_MAX", HTTP_DEFLATE_LEVEL_MAX);
3916 + HTTP_LONG_CONSTANT("HTTP_DEFLATE_TYPE_ZLIB", HTTP_DEFLATE_TYPE_ZLIB);
3917 + HTTP_LONG_CONSTANT("HTTP_DEFLATE_TYPE_GZIP", HTTP_DEFLATE_TYPE_GZIP);
3918 + HTTP_LONG_CONSTANT("HTTP_DEFLATE_TYPE_RAW", HTTP_DEFLATE_TYPE_RAW);
3919 + HTTP_LONG_CONSTANT("HTTP_DEFLATE_STRATEGY_DEF", HTTP_DEFLATE_STRATEGY_DEF);
3920 + HTTP_LONG_CONSTANT("HTTP_DEFLATE_STRATEGY_FILT", HTTP_DEFLATE_STRATEGY_FILT);
3921 + HTTP_LONG_CONSTANT("HTTP_DEFLATE_STRATEGY_HUFF", HTTP_DEFLATE_STRATEGY_HUFF);
3922 + HTTP_LONG_CONSTANT("HTTP_DEFLATE_STRATEGY_RLE", HTTP_DEFLATE_STRATEGY_RLE);
3923 + HTTP_LONG_CONSTANT("HTTP_DEFLATE_STRATEGY_FIXED", HTTP_DEFLATE_STRATEGY_FIXED);
3925 + HTTP_LONG_CONSTANT("HTTP_ENCODING_STREAM_FLUSH_NONE", HTTP_ENCODING_STREAM_FLUSH_NONE);
3926 + HTTP_LONG_CONSTANT("HTTP_ENCODING_STREAM_FLUSH_SYNC", HTTP_ENCODING_STREAM_FLUSH_SYNC);
3927 + HTTP_LONG_CONSTANT("HTTP_ENCODING_STREAM_FLUSH_FULL", HTTP_ENCODING_STREAM_FLUSH_FULL);
3932 +PHP_RINIT_FUNCTION(http_encoding)
3934 + if (HTTP_G->send.inflate.start_auto) {
3935 +#ifdef PHP_OUTPUT_NEWAPI
3936 + php_output_start_internal(ZEND_STRL("http inflate"), _http_ob_inflatehandler, HTTP_INFLATE_BUFFER_SIZE, 0 TSRMLS_CC);
3938 + php_ob_set_internal_handler(_http_ob_inflatehandler, HTTP_INFLATE_BUFFER_SIZE, "http inflate", 0 TSRMLS_CC);
3941 + if (HTTP_G->send.deflate.start_auto) {
3942 +#ifdef PHP_OUTPUT_NEWAPI
3943 + php_output_start_internal(ZEND_STRL("http deflate"), _http_ob_deflatehandler, HTTP_DEFLATE_BUFFER_SIZE, 0 TSRMLS_CC);
3945 + php_ob_set_internal_handler(_http_ob_deflatehandler, HTTP_DEFLATE_BUFFER_SIZE, "http deflate", 0 TSRMLS_CC);
3951 +PHP_RSHUTDOWN_FUNCTION(http_encoding)
3953 + if (HTTP_G->send.deflate.stream) {
3954 + http_encoding_deflate_stream_free((http_encoding_stream **) &HTTP_G->send.deflate.stream);
3956 + if (HTTP_G->send.inflate.stream) {
3957 + http_encoding_inflate_stream_free((http_encoding_stream **) &HTTP_G->send.inflate.stream);
3964 +/* {{{ eol_match(char **, int *) */
3965 +static inline int eol_match(char **line, int *eol_len)
3967 + char *ptr = *line;
3969 + while (' ' == *ptr) ++ptr;
3971 + if (ptr == http_locate_eol(*line, eol_len)) {
3980 +/* {{{ char *http_encoding_dechunk(char *, size_t, char **, size_t *) */
3981 +PHP_HTTP_API const char *_http_encoding_dechunk(const char *encoded, size_t encoded_len, char **decoded, size_t *decoded_len TSRMLS_DC)
3984 + char *n_ptr = NULL;
3985 + const char *e_ptr = encoded;
3988 + *decoded = ecalloc(1, encoded_len);
3990 + while ((encoded + encoded_len - e_ptr) > 0) {
3991 + ulong chunk_len = 0, rest;
3993 + chunk_len = strtoul(e_ptr, &n_ptr, 16);
3995 + /* we could not read in chunk size */
3996 + if (n_ptr == e_ptr) {
3998 + * if this is the first turn and there doesn't seem to be a chunk
3999 + * size at the begining of the body, do not fail on apparently
4000 + * not encoded data and return a copy
4002 + if (e_ptr == encoded) {
4003 + http_error(HE_NOTICE, HTTP_E_ENCODING, "Data does not seem to be chunked encoded");
4004 + memcpy(*decoded, encoded, encoded_len);
4005 + *decoded_len = encoded_len;
4006 + return encoded + encoded_len;
4009 + http_error_ex(HE_WARNING, HTTP_E_ENCODING, "Expected chunk size at pos %tu of %zu but got trash", n_ptr - encoded, encoded_len);
4014 + /* reached the end */
4016 + /* move over '0' chunked encoding terminator */
4017 + while (*e_ptr == '0') ++e_ptr;
4021 + /* there should be CRLF after the chunk size, but we'll ignore SP+ too */
4022 + if (*n_ptr && !eol_match(&n_ptr, &eol_len)) {
4023 + if (eol_len == 2) {
4024 + http_error_ex(HE_WARNING, HTTP_E_ENCODING, "Expected CRLF at pos %tu of %zu but got 0x%02X 0x%02X", n_ptr - encoded, encoded_len, *n_ptr, *(n_ptr + 1));
4026 + http_error_ex(HE_WARNING, HTTP_E_ENCODING, "Expected LF at pos %tu of %zu but got 0x%02X", n_ptr - encoded, encoded_len, *n_ptr);
4031 + /* chunk size pretends more data than we actually got, so it's probably a truncated message */
4032 + if (chunk_len > (rest = encoded + encoded_len - n_ptr)) {
4033 + http_error_ex(HE_WARNING, HTTP_E_ENCODING, "Truncated message: chunk size %lu exceeds remaining data size %lu at pos %tu of %zu", chunk_len, rest, n_ptr - encoded, encoded_len);
4037 + /* copy the chunk */
4038 + memcpy(*decoded + *decoded_len, n_ptr, chunk_len);
4039 + *decoded_len += chunk_len;
4041 + if (chunk_len == rest) {
4042 + e_ptr = n_ptr + chunk_len;
4045 + /* advance to next chunk */
4046 + e_ptr = n_ptr + chunk_len + eol_len;
4054 +/* {{{ int http_encoding_response_start(size_t) */
4055 +PHP_HTTP_API int _http_encoding_response_start(size_t content_length, zend_bool ignore_http_ohandler TSRMLS_DC)
4057 + int response = HTTP_G->send.deflate.response;
4058 +#ifdef PHP_OUTPUT_NEWAPI
4059 + int ohandler = php_output_handler_started(ZEND_STRL("ob_gzhandler") TSRMLS_CC) || php_output_handler_started(ZEND_STRL("zlib output compression") TSRMLS_CC);
4061 + int ohandler = php_ob_handler_used("ob_gzhandler" TSRMLS_CC) || php_ob_handler_used("zlib output compression" TSRMLS_CC);
4064 + if (!ohandler && !ignore_http_ohandler) {
4065 +#ifdef PHP_OUTPUT_NEWAPI
4066 + ohandler = php_output_handler_started(ZEND_STRL("ob_defaltehandler") TSRMLS_CC) || php_output_handler_started(ZEND_STRL("http deflate") TSRMLS_CC);
4068 + ohandler = php_ob_handler_used("ob_deflatehandler" TSRMLS_CC) || php_ob_handler_used("http deflate" TSRMLS_CC);
4072 + if (response && !ohandler) {
4073 +#ifdef HTTP_HAVE_ZLIB
4074 + HashTable *selected;
4077 + HTTP_G->send.deflate.encoding = 0;
4079 + INIT_PZVAL(&zsupported);
4080 + array_init(&zsupported);
4081 + add_next_index_stringl(&zsupported, "gzip", lenof("gzip"), 1);
4082 + add_next_index_stringl(&zsupported, "x-gzip", lenof("x-gzip"), 1);
4083 + add_next_index_stringl(&zsupported, "deflate", lenof("deflate"), 1);
4085 + if ((selected = http_negotiate_encoding(&zsupported))) {
4086 + STATUS hs = FAILURE;
4087 + char *encoding = NULL;
4090 + if (HASH_KEY_IS_STRING == zend_hash_get_current_key(selected, &encoding, &idx, 0) && encoding) {
4091 + if (!strcmp(encoding, "gzip") || !strcmp(encoding, "x-gzip")) {
4092 + if (SUCCESS == (hs = http_send_header_string("Content-Encoding: gzip"))) {
4093 + HTTP_G->send.deflate.encoding = HTTP_ENCODING_GZIP;
4095 + } else if (!strcmp(encoding, "deflate")) {
4096 + if (SUCCESS == (hs = http_send_header_string("Content-Encoding: deflate"))) {
4097 + HTTP_G->send.deflate.encoding = HTTP_ENCODING_DEFLATE;
4100 + if (SUCCESS == hs) {
4101 + http_send_header_string("Vary: Accept-Encoding");
4105 + zend_hash_destroy(selected);
4106 + FREE_HASHTABLE(selected);
4109 + zval_dtor(&zsupported);
4111 + HTTP_G->send.deflate.encoding = 0;
4112 + php_start_ob_buffer_named("ob_gzhandler", 0, 0 TSRMLS_CC);
4113 +#endif /* HTTP_HAVE_ZLIB */
4114 + } else if (content_length && !ohandler) {
4115 + /* emit a content-length header */
4118 + phpstr_init(&header);
4119 + phpstr_appendf(&header, "Content-Length: %zu", content_length);
4120 + phpstr_fix(&header);
4121 + http_send_header_string_ex(PHPSTR_VAL(&header), PHPSTR_LEN(&header), 1);
4122 + phpstr_dtor(&header);
4124 + HTTP_G->send.deflate.encoding = 0;
4127 + return HTTP_G->send.deflate.encoding;
4131 +#ifdef HTTP_HAVE_ZLIB
4133 +/* {{{ inline int http_inflate_rounds */
4134 +static inline int http_inflate_rounds(z_stream *Z, int flush, char **buf, size_t *len)
4136 + int status = 0, round = 0;
4142 + phpstr_init_ex(&buffer, Z->avail_in, PHPSTR_INIT_PREALLOC);
4145 + if (PHPSTR_NOMEM == phpstr_resize_ex(&buffer, buffer.size, 0, 1)) {
4146 + status = Z_MEM_ERROR;
4148 + Z->avail_out = buffer.free;
4149 + Z->next_out = (Bytef *) buffer.data + buffer.used;
4151 + fprintf(stderr, "\n%3d: %3d PRIOR: size=%7lu,\tfree=%7lu,\tused=%7lu,\tavail_in=%7lu,\tavail_out=%7lu\n", round, status, buffer.size, buffer.free, buffer.used, Z->avail_in, Z->avail_out);
4153 + status = inflate(Z, flush);
4155 + buffer.used += buffer.free - Z->avail_out;
4156 + buffer.free = Z->avail_out;
4158 + fprintf(stderr, "%3d: %3d AFTER: size=%7lu,\tfree=%7lu,\tused=%7lu,\tavail_in=%7lu,\tavail_out=%7lu\n", round, status, buffer.size, buffer.free, buffer.used, Z->avail_in, Z->avail_out);
4160 + HTTP_INFLATE_BUFFER_SIZE_ALIGN(buffer.size);
4162 + } while ((Z_BUF_ERROR == status || (Z_OK == status && Z->avail_in)) && ++round < HTTP_INFLATE_ROUNDS);
4164 + if (status == Z_OK || status == Z_STREAM_END) {
4165 + phpstr_shrink(&buffer);
4166 + phpstr_fix(&buffer);
4167 + *buf = buffer.data;
4168 + *len = buffer.used;
4170 + phpstr_dtor(&buffer);
4177 +/* {{{ STATUS http_encoding_deflate(int, char *, size_t, char **, size_t *) */
4178 +PHP_HTTP_API STATUS _http_encoding_deflate(int flags, const char *data, size_t data_len, char **encoded, size_t *encoded_len ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC TSRMLS_DC)
4180 + int status, level, wbits, strategy;
4183 + HTTP_DEFLATE_LEVEL_SET(flags, level);
4184 + HTTP_DEFLATE_WBITS_SET(flags, wbits);
4185 + HTTP_DEFLATE_STRATEGY_SET(flags, strategy);
4187 + memset(&Z, 0, sizeof(z_stream));
4191 + status = deflateInit2(&Z, level, Z_DEFLATED, wbits, MAX_MEM_LEVEL, strategy);
4192 + if (Z_OK == status) {
4193 + *encoded_len = HTTP_DEFLATE_BUFFER_SIZE_GUESS(data_len);
4194 + *encoded = emalloc_rel(*encoded_len);
4196 + Z.next_in = (Bytef *) data;
4197 + Z.next_out = (Bytef *) *encoded;
4198 + Z.avail_in = data_len;
4199 + Z.avail_out = *encoded_len;
4201 + status = deflate(&Z, Z_FINISH);
4204 + if (Z_STREAM_END == status) {
4205 + /* size buffer down to actual length */
4206 + *encoded = erealloc_rel(*encoded, Z.total_out + 1);
4207 + (*encoded)[*encoded_len = Z.total_out] = '\0';
4210 + STR_SET(*encoded, NULL);
4215 + http_error_ex(HE_WARNING, HTTP_E_ENCODING, "Could not deflate data: %s", zError(status));
4220 +/* {{{ STATUS http_encoding_inflate(char *, size_t, char **, size_t) */
4221 +PHP_HTTP_API STATUS _http_encoding_inflate(const char *data, size_t data_len, char **decoded, size_t *decoded_len ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC TSRMLS_DC)
4224 + int status, wbits = HTTP_WINDOW_BITS_ANY;
4226 + memset(&Z, 0, sizeof(z_stream));
4229 + status = inflateInit2(&Z, wbits);
4230 + if (Z_OK == status) {
4231 + Z.next_in = (Bytef *) data;
4232 + Z.avail_in = data_len;
4234 + switch (status = http_inflate_rounds(&Z, Z_NO_FLUSH, decoded, decoded_len)) {
4235 + case Z_STREAM_END:
4240 + status = Z_DATA_ERROR;
4243 + case Z_DATA_ERROR:
4244 + /* raw deflated data? */
4245 + if (HTTP_WINDOW_BITS_ANY == wbits) {
4247 + wbits = HTTP_WINDOW_BITS_RAW;
4248 + goto retry_raw_inflate;
4254 + http_error_ex(HE_WARNING, HTTP_E_ENCODING, "Could not inflate data: %s", zError(status));
4259 +/* {{{ http_encoding_stream *_http_encoding_deflate_stream_init(http_encoding_stream *, int) */
4260 +PHP_HTTP_API http_encoding_stream *_http_encoding_deflate_stream_init(http_encoding_stream *s, int flags ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC TSRMLS_DC)
4262 + int status, level, wbits, strategy, free_stream;
4264 + if ((free_stream = !s)) {
4265 + s = pemalloc_rel(sizeof(http_encoding_stream), (flags & HTTP_ENCODING_STREAM_PERSISTENT));
4267 + memset(s, 0, sizeof(http_encoding_stream));
4270 + HTTP_DEFLATE_LEVEL_SET(flags, level);
4271 + HTTP_DEFLATE_WBITS_SET(flags, wbits);
4272 + HTTP_DEFLATE_STRATEGY_SET(flags, strategy);
4274 + if (Z_OK == (status = deflateInit2(&s->stream, level, Z_DEFLATED, wbits, MAX_MEM_LEVEL, strategy))) {
4275 + int p = (flags & HTTP_ENCODING_STREAM_PERSISTENT) ? PHPSTR_INIT_PERSISTENT:0;
4277 + if ((s->stream.opaque = phpstr_init_ex(NULL, HTTP_DEFLATE_BUFFER_SIZE, p))) {
4280 + deflateEnd(&s->stream);
4281 + status = Z_MEM_ERROR;
4284 + http_error_ex(HE_WARNING, HTTP_E_ENCODING, "Failed to initialize deflate encoding stream: %s", zError(status));
4285 + if (free_stream) {
4292 +/* {{{ http_encoding_stream *http_encoding_inflate_stream_init(http_encoding_stream *, int) */
4293 +PHP_HTTP_API http_encoding_stream *_http_encoding_inflate_stream_init(http_encoding_stream *s, int flags ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC TSRMLS_DC)
4295 + int status, wbits, free_stream;
4297 + if ((free_stream = !s)) {
4298 + s = pemalloc_rel(sizeof(http_encoding_stream), (flags & HTTP_ENCODING_STREAM_PERSISTENT));
4300 + memset(s, 0, sizeof(http_encoding_stream));
4303 + HTTP_INFLATE_WBITS_SET(flags, wbits);
4305 + if (Z_OK == (status = inflateInit2(&s->stream, wbits))) {
4306 + int p = (flags & HTTP_ENCODING_STREAM_PERSISTENT) ? PHPSTR_INIT_PERSISTENT:0;
4308 + if ((s->stream.opaque = phpstr_init_ex(NULL, HTTP_DEFLATE_BUFFER_SIZE, p))) {
4311 + inflateEnd(&s->stream);
4312 + status = Z_MEM_ERROR;
4315 + http_error_ex(HE_WARNING, HTTP_E_ENCODING, "Failed to initialize inflate stream: %s", zError(status));
4316 + if (free_stream) {
4323 +/* {{{ STATUS http_encoding_deflate_stream_update(http_encoding_stream *, char *, size_t, char **, size_t *) */
4324 +PHP_HTTP_API STATUS _http_encoding_deflate_stream_update(http_encoding_stream *s, const char *data, size_t data_len, char **encoded, size_t *encoded_len ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC TSRMLS_DC)
4328 + /* append input to our buffer */
4329 + phpstr_append(PHPSTR(s->stream.opaque), data, data_len);
4331 + s->stream.next_in = (Bytef *) PHPSTR_VAL(s->stream.opaque);
4332 + s->stream.avail_in = PHPSTR_LEN(s->stream.opaque);
4335 + *encoded_len = HTTP_DEFLATE_BUFFER_SIZE_GUESS(data_len);
4336 + *encoded = emalloc_rel(*encoded_len);
4337 + s->stream.avail_out = *encoded_len;
4338 + s->stream.next_out = (Bytef *) *encoded;
4340 + switch (status = deflate(&s->stream, HTTP_ENCODING_STREAM_FLUSH_FLAG(s->flags))) {
4342 + case Z_STREAM_END:
4343 + /* cut processed chunk off the buffer */
4344 + if (s->stream.avail_in) {
4345 + phpstr_cut(PHPSTR(s->stream.opaque), 0, PHPSTR_LEN(s->stream.opaque) - s->stream.avail_in);
4347 + phpstr_reset(PHPSTR(s->stream.opaque));
4350 + /* size buffer down to actual size */
4351 + *encoded_len -= s->stream.avail_out;
4352 + *encoded = erealloc_rel(*encoded, *encoded_len + 1);
4353 + (*encoded)[*encoded_len] = '\0';
4357 + STR_SET(*encoded, NULL);
4359 + http_error_ex(HE_WARNING, HTTP_E_ENCODING, "Failed to update deflate stream: %s", zError(status));
4364 +/* {{{ STATUS http_encoding_inflate_stream_update(http_encoding_stream *, char *, size_t, char **, size_t *) */
4365 +PHP_HTTP_API STATUS _http_encoding_inflate_stream_update(http_encoding_stream *s, const char *data, size_t data_len, char **decoded, size_t *decoded_len ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC TSRMLS_DC)
4369 + /* append input to buffer */
4370 + phpstr_append(PHPSTR(s->stream.opaque), data, data_len);
4373 + s->stream.next_in = (Bytef *) PHPSTR_VAL(s->stream.opaque);
4374 + s->stream.avail_in = PHPSTR_LEN(s->stream.opaque);
4376 + switch (status = http_inflate_rounds(&s->stream, HTTP_ENCODING_STREAM_FLUSH_FLAG(s->flags), decoded, decoded_len)) {
4378 + case Z_STREAM_END:
4380 + if (s->stream.avail_in) {
4381 + phpstr_cut(PHPSTR(s->stream.opaque), 0, PHPSTR_LEN(s->stream.opaque) - s->stream.avail_in);
4383 + phpstr_reset(PHPSTR(s->stream.opaque));
4387 + case Z_DATA_ERROR:
4388 + /* raw deflated data ? */
4389 + if (!(s->flags & HTTP_INFLATE_TYPE_RAW) && !s->stream.total_out) {
4390 + inflateEnd(&s->stream);
4391 + s->flags |= HTTP_INFLATE_TYPE_RAW;
4392 + inflateInit2(&s->stream, HTTP_WINDOW_BITS_RAW);
4393 + goto retry_raw_inflate;
4397 + http_error_ex(HE_WARNING, HTTP_E_ENCODING, "Failed to update inflate stream: %s", zError(status));
4402 +/* {{{ STATUS http_encoding_deflate_stream_flush(http_encoding_stream *, char **, size_t *) */
4403 +PHP_HTTP_API STATUS _http_encoding_deflate_stream_flush(http_encoding_stream *s, char **encoded, size_t *encoded_len ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC TSRMLS_DC)
4407 + *encoded_len = HTTP_DEFLATE_BUFFER_SIZE;
4408 + *encoded = emalloc_rel(*encoded_len);
4410 + s->stream.avail_in = 0;
4411 + s->stream.next_in = NULL;
4412 + s->stream.avail_out = *encoded_len;
4413 + s->stream.next_out = (Bytef *) *encoded;
4415 + switch (status = deflate(&s->stream, Z_FULL_FLUSH)) {
4417 + case Z_STREAM_END:
4418 + *encoded_len = HTTP_DEFLATE_BUFFER_SIZE - s->stream.avail_out;
4419 + *encoded = erealloc_rel(*encoded, *encoded_len + 1);
4420 + (*encoded)[*encoded_len] = '\0';
4424 + STR_SET(*encoded, NULL);
4426 + http_error_ex(HE_WARNING, HTTP_E_ENCODING, "Failed to flush deflate stream: %s", zError(status));
4431 +/* {{{ STATUS http_encoding_inflate_straem_flush(http_encoding_stream *, char **, size_t *) */
4432 +PHP_HTTP_API STATUS _http_encoding_inflate_stream_flush(http_encoding_stream *s, char **decoded, size_t *decoded_len ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC TSRMLS_DC)
4435 + *decoded = estrndup("", *decoded_len = 0);
4440 +/* {{{ STATUS http_encoding_deflate_stream_finish(http_encoding_stream *, char **, size_t *) */
4441 +PHP_HTTP_API STATUS _http_encoding_deflate_stream_finish(http_encoding_stream *s, char **encoded, size_t *encoded_len ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC TSRMLS_DC)
4445 + *encoded_len = HTTP_DEFLATE_BUFFER_SIZE;
4446 + *encoded = emalloc_rel(*encoded_len);
4448 + /* deflate remaining input */
4449 + s->stream.next_in = (Bytef *) PHPSTR_VAL(s->stream.opaque);
4450 + s->stream.avail_in = PHPSTR_LEN(s->stream.opaque);
4452 + s->stream.avail_out = *encoded_len;
4453 + s->stream.next_out = (Bytef *) *encoded;
4456 + status = deflate(&s->stream, Z_FINISH);
4457 + } while (Z_OK == status);
4459 + if (Z_STREAM_END == status) {
4460 + /* cut processed intp off */
4461 + phpstr_cut(PHPSTR(s->stream.opaque), 0, PHPSTR_LEN(s->stream.opaque) - s->stream.avail_in);
4464 + *encoded_len -= s->stream.avail_out;
4465 + *encoded = erealloc_rel(*encoded, *encoded_len + 1);
4466 + (*encoded)[*encoded_len] = '\0';
4470 + STR_SET(*encoded, NULL);
4472 + http_error_ex(HE_WARNING, HTTP_E_ENCODING, "Failed to finish deflate stream: %s", zError(status));
4477 +/* {{{ STATUS http_encoding_inflate_stream_finish(http_encoding_stream *, char **, size_t *) */
4478 +PHP_HTTP_API STATUS _http_encoding_inflate_stream_finish(http_encoding_stream *s, char **decoded, size_t *decoded_len ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC TSRMLS_DC)
4482 + if (!PHPSTR_LEN(s->stream.opaque)) {
4488 + *decoded_len = (PHPSTR_LEN(s->stream.opaque) + 1) * HTTP_INFLATE_ROUNDS;
4489 + *decoded = emalloc_rel(*decoded_len);
4491 + /* inflate remaining input */
4492 + s->stream.next_in = (Bytef *) PHPSTR_VAL(s->stream.opaque);
4493 + s->stream.avail_in = PHPSTR_LEN(s->stream.opaque);
4495 + s->stream.avail_out = *decoded_len;
4496 + s->stream.next_out = (Bytef *) *decoded;
4498 + if (Z_STREAM_END == (status = inflate(&s->stream, Z_FINISH))) {
4499 + /* cut processed input off */
4500 + phpstr_cut(PHPSTR(s->stream.opaque), 0, PHPSTR_LEN(s->stream.opaque) - s->stream.avail_in);
4503 + *decoded_len -= s->stream.avail_out;
4504 + *decoded = erealloc_rel(*decoded, *decoded_len + 1);
4505 + (*decoded)[*decoded_len] = '\0';
4509 + STR_SET(*decoded, NULL);
4511 + http_error_ex(HE_WARNING, HTTP_E_ENCODING, "Failed to finish inflate stream: %s", zError(status));
4516 +/* {{{ void http_encoding_deflate_stream_dtor(http_encoding_stream *) */
4517 +PHP_HTTP_API void _http_encoding_deflate_stream_dtor(http_encoding_stream *s TSRMLS_DC)
4520 + if (s->stream.opaque) {
4521 + phpstr_free((phpstr **) &s->stream.opaque);
4523 + deflateEnd(&s->stream);
4528 +/* {{{ void http_encoding_inflate_stream_dtor(http_encoding_stream *) */
4529 +PHP_HTTP_API void _http_encoding_inflate_stream_dtor(http_encoding_stream *s TSRMLS_DC)
4532 + if (s->stream.opaque) {
4533 + phpstr_free((phpstr **) &s->stream.opaque);
4535 + inflateEnd(&s->stream);
4540 +/* {{{ void http_encoding_deflate_stream_free(http_encoding_stream **) */
4541 +PHP_HTTP_API void _http_encoding_deflate_stream_free(http_encoding_stream **s TSRMLS_DC)
4544 + http_encoding_deflate_stream_dtor(*s);
4546 + pefree(*s, (*s)->flags & HTTP_ENCODING_STREAM_PERSISTENT);
4553 +/* {{{ void http_encoding_inflate_stream_free(http_encoding_stream **) */
4554 +PHP_HTTP_API void _http_encoding_inflate_stream_free(http_encoding_stream **s TSRMLS_DC)
4557 + http_encoding_inflate_stream_dtor(*s);
4559 + pefree(*s, (*s)->flags & HTTP_ENCODING_STREAM_PERSISTENT);
4566 +/* {{{ void http_ob_deflatehandler(char *, uint, char **, uint *, int) */
4567 +void _http_ob_deflatehandler(char *output, uint output_len, char **handled_output, uint *handled_output_len, int mode TSRMLS_DC)
4571 + *handled_output = NULL;
4572 + *handled_output_len = 0;
4574 + if (mode & PHP_OUTPUT_HANDLER_START) {
4577 + if (HTTP_G->send.deflate.stream) {
4578 + zend_error(E_ERROR, "ob_deflatehandler() can only be used once");
4582 + HTTP_G->send.deflate.response = 1;
4583 + encoding = http_encoding_response_start(0, 1);
4584 + HTTP_G->send.deflate.response = 0;
4586 + switch (encoding) {
4587 + case HTTP_ENCODING_GZIP:
4588 + flags = HTTP_DEFLATE_TYPE_GZIP;
4591 + case HTTP_ENCODING_DEFLATE:
4592 + flags = HTTP_DEFLATE_TYPE_ZLIB;
4596 + goto deflate_passthru_plain;
4599 + flags |= (HTTP_G->send.deflate.start_flags &~ 0xf0);
4600 + HTTP_G->send.deflate.stream = http_encoding_deflate_stream_init(NULL, flags);
4603 + if (HTTP_G->send.deflate.stream) {
4607 + http_encoding_deflate_stream_update((http_encoding_stream *) HTTP_G->send.deflate.stream, output, output_len, handled_output, &tmp_len);
4608 + *handled_output_len = tmp_len;
4611 + if (mode & PHP_OUTPUT_HANDLER_END) {
4612 + char *remaining = NULL;
4613 + size_t remaining_len = 0;
4615 + http_encoding_deflate_stream_finish((http_encoding_stream *) HTTP_G->send.deflate.stream, &remaining, &remaining_len);
4616 + http_encoding_deflate_stream_free((http_encoding_stream **) &HTTP_G->send.deflate.stream);
4618 + *handled_output = erealloc(*handled_output, *handled_output_len + remaining_len + 1);
4619 + memcpy(*handled_output + *handled_output_len, remaining, remaining_len);
4620 + (*handled_output)[*handled_output_len += remaining_len] = '\0';
4625 +deflate_passthru_plain:
4626 + *handled_output = estrndup(output, *handled_output_len = output_len);
4631 +/* {{{ void http_ob_inflatehandler(char *, uint, char **, uint *, int) */
4632 +void _http_ob_inflatehandler(char *output, uint output_len, char **handled_output, uint *handled_output_len, int mode TSRMLS_DC)
4634 + *handled_output = NULL;
4635 + *handled_output_len = 0;
4637 + if (mode & PHP_OUTPUT_HANDLER_START) {
4638 + if (HTTP_G->send.inflate.stream) {
4639 + zend_error(E_ERROR, "ob_inflatehandler() can only be used once");
4642 + HTTP_G->send.inflate.stream = http_encoding_inflate_stream_init(NULL, (HTTP_G->send.inflate.start_flags &~ 0xf0));
4645 + if (HTTP_G->send.inflate.stream) {
4649 + http_encoding_inflate_stream_update((http_encoding_stream *) HTTP_G->send.inflate.stream, output, output_len, handled_output, &tmp_len);
4650 + *handled_output_len = tmp_len;
4653 + if (mode & PHP_OUTPUT_HANDLER_END) {
4654 + char *remaining = NULL;
4655 + size_t remaining_len = 0;
4657 + http_encoding_inflate_stream_finish((http_encoding_stream *) HTTP_G->send.inflate.stream, &remaining, &remaining_len);
4658 + http_encoding_inflate_stream_free((http_encoding_stream **) &HTTP_G->send.inflate.stream);
4660 + *handled_output = erealloc(*handled_output, *handled_output_len + remaining_len + 1);
4661 + memcpy(*handled_output + *handled_output_len, remaining, remaining_len);
4662 + (*handled_output)[*handled_output_len += remaining_len] = '\0';
4667 + *handled_output = estrndup(output, *handled_output_len = output_len);
4672 +#endif /* HTTP_HAVE_ZLIB */
4675 + * Local variables:
4677 + * c-basic-offset: 4
4679 + * vim600: noet sw=4 ts=4 fdm=marker
4680 + * vim<600: noet sw=4 ts=4
4684 +++ b/ext/http/http_exception_object.c
4687 + +--------------------------------------------------------------------+
4689 + +--------------------------------------------------------------------+
4690 + | Redistribution and use in source and binary forms, with or without |
4691 + | modification, are permitted provided that the conditions mentioned |
4692 + | in the accompanying LICENSE file are met. |
4693 + +--------------------------------------------------------------------+
4694 + | Copyright (c) 2004-2010, Michael Wallner <mike@php.net> |
4695 + +--------------------------------------------------------------------+
4698 +/* $Id: http_exception_object.c 292841 2009-12-31 08:48:57Z mike $ */
4700 +#include "php_http.h"
4702 +#ifdef ZEND_ENGINE_2
4704 +#ifndef HTTP_DBG_EXCEPTIONS
4705 +# define HTTP_DBG_EXCEPTIONS 0
4708 +#include "zend_interfaces.h"
4709 +#include "zend_exceptions.h"
4710 +#include "php_http_exception_object.h"
4712 +zend_class_entry *http_exception_object_ce;
4713 +zend_class_entry *HTTP_EX_CE(runtime);
4714 +zend_class_entry *HTTP_EX_CE(header);
4715 +zend_class_entry *HTTP_EX_CE(malformed_headers);
4716 +zend_class_entry *HTTP_EX_CE(request_method);
4717 +zend_class_entry *HTTP_EX_CE(message_type);
4718 +zend_class_entry *HTTP_EX_CE(invalid_param);
4719 +zend_class_entry *HTTP_EX_CE(encoding);
4720 +zend_class_entry *HTTP_EX_CE(request);
4721 +zend_class_entry *HTTP_EX_CE(request_pool);
4722 +zend_class_entry *HTTP_EX_CE(socket);
4723 +zend_class_entry *HTTP_EX_CE(response);
4724 +zend_class_entry *HTTP_EX_CE(url);
4725 +zend_class_entry *HTTP_EX_CE(querystring);
4727 +#define HTTP_EMPTY_ARGS(method) HTTP_EMPTY_ARGS_EX(HttpException, method, 0)
4728 +#define HTTP_EXCEPTION_ME(method, visibility) PHP_ME(HttpException, method, HTTP_ARGS(HttpException, method), visibility)
4730 +HTTP_EMPTY_ARGS(__toString);
4732 +zend_function_entry http_exception_object_fe[] = {
4733 + HTTP_EXCEPTION_ME(__toString, ZEND_ACC_PUBLIC)
4735 + EMPTY_FUNCTION_ENTRY
4738 +#if HTTP_DBG_EXCEPTIONS
4739 +static void http_exception_hook(zval *ex TSRMLS_DC)
4742 + zval *m = zend_read_property(Z_OBJCE_P(ex), ex, "message", lenof("message"), 0 TSRMLS_CC);
4743 + fprintf(stderr, "*** Threw exception '%s'\n", Z_STRVAL_P(m));
4745 + fprintf(stderr, "*** Threw NULL exception\n");
4750 +PHP_MINIT_FUNCTION(http_exception_object)
4752 + HTTP_REGISTER_CLASS(HttpException, http_exception_object, ZEND_EXCEPTION_GET_DEFAULT(), 0);
4754 + zend_declare_property_null(HTTP_EX_DEF_CE, "innerException", lenof("innerException"), ZEND_ACC_PUBLIC TSRMLS_CC);
4756 + HTTP_REGISTER_EXCEPTION(HttpRuntimeException, HTTP_EX_CE(runtime), HTTP_EX_DEF_CE);
4757 + HTTP_REGISTER_EXCEPTION(HttpInvalidParamException, HTTP_EX_CE(invalid_param), HTTP_EX_DEF_CE);
4758 + HTTP_REGISTER_EXCEPTION(HttpHeaderException, HTTP_EX_CE(header), HTTP_EX_DEF_CE);
4759 + HTTP_REGISTER_EXCEPTION(HttpMalformedHeadersException, HTTP_EX_CE(malformed_headers), HTTP_EX_DEF_CE);
4760 + HTTP_REGISTER_EXCEPTION(HttpRequestMethodException, HTTP_EX_CE(request_method), HTTP_EX_DEF_CE);
4761 + HTTP_REGISTER_EXCEPTION(HttpMessageTypeException, HTTP_EX_CE(message_type), HTTP_EX_DEF_CE);
4762 + HTTP_REGISTER_EXCEPTION(HttpEncodingException, HTTP_EX_CE(encoding), HTTP_EX_DEF_CE);
4763 + HTTP_REGISTER_EXCEPTION(HttpRequestException, HTTP_EX_CE(request), HTTP_EX_DEF_CE);
4765 + zend_declare_property_long(HTTP_EX_CE(request), "curlCode", lenof("curlCode"), 0, ZEND_ACC_PUBLIC TSRMLS_CC);
4767 + HTTP_REGISTER_EXCEPTION(HttpRequestPoolException, HTTP_EX_CE(request_pool), HTTP_EX_DEF_CE);
4768 + HTTP_REGISTER_EXCEPTION(HttpSocketException, HTTP_EX_CE(socket), HTTP_EX_DEF_CE);
4769 + HTTP_REGISTER_EXCEPTION(HttpResponseException, HTTP_EX_CE(response), HTTP_EX_DEF_CE);
4770 + HTTP_REGISTER_EXCEPTION(HttpUrlException, HTTP_EX_CE(url), HTTP_EX_DEF_CE);
4771 + HTTP_REGISTER_EXCEPTION(HttpQueryStringException, HTTP_EX_CE(querystring), HTTP_EX_DEF_CE);
4773 + HTTP_LONG_CONSTANT("HTTP_E_RUNTIME", HTTP_E_RUNTIME);
4774 + HTTP_LONG_CONSTANT("HTTP_E_INVALID_PARAM", HTTP_E_INVALID_PARAM);
4775 + HTTP_LONG_CONSTANT("HTTP_E_HEADER", HTTP_E_HEADER);
4776 + HTTP_LONG_CONSTANT("HTTP_E_MALFORMED_HEADERS", HTTP_E_MALFORMED_HEADERS);
4777 + HTTP_LONG_CONSTANT("HTTP_E_REQUEST_METHOD", HTTP_E_REQUEST_METHOD);
4778 + HTTP_LONG_CONSTANT("HTTP_E_MESSAGE_TYPE", HTTP_E_MESSAGE_TYPE);
4779 + HTTP_LONG_CONSTANT("HTTP_E_ENCODING", HTTP_E_ENCODING);
4780 + HTTP_LONG_CONSTANT("HTTP_E_REQUEST", HTTP_E_REQUEST);
4781 + HTTP_LONG_CONSTANT("HTTP_E_REQUEST_POOL", HTTP_E_REQUEST_POOL);
4782 + HTTP_LONG_CONSTANT("HTTP_E_SOCKET", HTTP_E_SOCKET);
4783 + HTTP_LONG_CONSTANT("HTTP_E_RESPONSE", HTTP_E_RESPONSE);
4784 + HTTP_LONG_CONSTANT("HTTP_E_URL", HTTP_E_URL);
4785 + HTTP_LONG_CONSTANT("HTTP_E_QUERYSTRING", HTTP_E_QUERYSTRING);
4787 +#if HTTP_DBG_EXCEPTIONS
4788 + zend_throw_exception_hook=http_exception_hook;
4794 +zend_class_entry *_http_exception_get_default()
4796 + return http_exception_object_ce;
4799 +zend_class_entry *_http_exception_get_for_code(long code)
4801 + zend_class_entry *ex = http_exception_object_ce;
4804 + case HTTP_E_RUNTIME: ex = HTTP_EX_CE(runtime); break;
4805 + case HTTP_E_INVALID_PARAM: ex = HTTP_EX_CE(invalid_param); break;
4806 + case HTTP_E_HEADER: ex = HTTP_EX_CE(header); break;
4807 + case HTTP_E_MALFORMED_HEADERS: ex = HTTP_EX_CE(malformed_headers); break;
4808 + case HTTP_E_REQUEST_METHOD: ex = HTTP_EX_CE(request_method); break;
4809 + case HTTP_E_MESSAGE_TYPE: ex = HTTP_EX_CE(message_type); break;
4810 + case HTTP_E_ENCODING: ex = HTTP_EX_CE(encoding); break;
4811 + case HTTP_E_REQUEST: ex = HTTP_EX_CE(request); break;
4812 + case HTTP_E_REQUEST_POOL: ex = HTTP_EX_CE(request_pool); break;
4813 + case HTTP_E_SOCKET: ex = HTTP_EX_CE(socket); break;
4814 + case HTTP_E_RESPONSE: ex = HTTP_EX_CE(response); break;
4815 + case HTTP_E_URL: ex = HTTP_EX_CE(url); break;
4816 + case HTTP_E_QUERYSTRING: ex = HTTP_EX_CE(querystring); break;
4822 +PHP_METHOD(HttpException, __toString)
4825 + zend_class_entry *ce;
4826 + zval *zobj = getThis(), *retval = NULL, *m, *f, *l;
4828 + phpstr_init(&full_str);
4831 + ce = Z_OBJCE_P(zobj);
4833 + m = zend_read_property(ce, zobj, "message", lenof("message"), 0 TSRMLS_CC);
4834 + f = zend_read_property(ce, zobj, "file", lenof("file"), 0 TSRMLS_CC);
4835 + l = zend_read_property(ce, zobj, "line", lenof("line"), 0 TSRMLS_CC);
4837 + if (m && f && l && Z_TYPE_P(m) == IS_STRING && Z_TYPE_P(f) == IS_STRING && Z_TYPE_P(l) == IS_LONG) {
4838 + if (zobj != getThis()) {
4839 + phpstr_appends(&full_str, " inner ");
4842 + phpstr_appendf(&full_str, "exception '%.*s' with message '%.*s' in %.*s:%ld" PHP_EOL,
4843 + ce->name_length, ce->name, Z_STRLEN_P(m), Z_STRVAL_P(m), Z_STRLEN_P(f), Z_STRVAL_P(f), Z_LVAL_P(l)
4849 + zobj = zend_read_property(ce, zobj, "innerException", lenof("innerException"), 0 TSRMLS_CC);
4850 + } while (Z_TYPE_P(zobj) == IS_OBJECT);
4852 + if (zend_call_method_with_0_params(&getThis(), Z_OBJCE_P(getThis()), NULL, "gettraceasstring", &retval) && Z_TYPE_P(retval) == IS_STRING) {
4853 + phpstr_appends(&full_str, "Stack trace:" PHP_EOL);
4854 + phpstr_append(&full_str, Z_STRVAL_P(retval), Z_STRLEN_P(retval));
4855 + zval_ptr_dtor(&retval);
4858 + RETURN_PHPSTR_VAL(&full_str);
4864 + * Local variables:
4866 + * c-basic-offset: 4
4868 + * vim600: noet sw=4 ts=4 fdm=marker
4869 + * vim<600: noet sw=4 ts=4
4873 +++ b/ext/http/http_filter_api.c
4876 + +--------------------------------------------------------------------+
4878 + +--------------------------------------------------------------------+
4879 + | Redistribution and use in source and binary forms, with or without |
4880 + | modification, are permitted provided that the conditions mentioned |
4881 + | in the accompanying LICENSE file are met. |
4882 + +--------------------------------------------------------------------+
4883 + | Copyright (c) 2004-2010, Michael Wallner <mike@php.net> |
4884 + +--------------------------------------------------------------------+
4887 +/* $Id: http_filter_api.c 292841 2009-12-31 08:48:57Z mike $ */
4889 +#define HTTP_WANT_ZLIB
4890 +#include "php_http.h"
4892 +#ifdef ZEND_ENGINE_2
4894 +#include "php_streams.h"
4895 +#include "php_http_api.h"
4896 +#include "php_http_encoding_api.h"
4897 +#include "php_http_filter_api.h"
4899 +PHP_MINIT_FUNCTION(http_filter)
4901 + php_stream_filter_register_factory("http.*", &http_filter_factory TSRMLS_CC);
4909 +#define HTTP_FILTER_PARAMS \
4910 + php_stream *stream, \
4911 + php_stream_filter *this, \
4912 + php_stream_bucket_brigade *buckets_in, \
4913 + php_stream_bucket_brigade *buckets_out, \
4914 + size_t *bytes_consumed, int flags \
4916 +#define HTTP_FILTER_OP(filter) \
4917 + http_filter_op_ ##filter
4918 +#define HTTP_FILTER_OPS(filter) \
4919 + php_stream_filter_ops HTTP_FILTER_OP(filter)
4920 +#define HTTP_FILTER_DTOR(filter) \
4921 + http_filter_ ##filter## _dtor
4922 +#define HTTP_FILTER_DESTRUCTOR(filter) \
4923 + void HTTP_FILTER_DTOR(filter)(php_stream_filter *this TSRMLS_DC)
4924 +#define HTTP_FILTER_FUNC(filter) \
4925 + http_filter_ ##filter
4926 +#define HTTP_FILTER_FUNCTION(filter) \
4927 + php_stream_filter_status_t HTTP_FILTER_FUNC(filter)(HTTP_FILTER_PARAMS)
4928 +#define HTTP_FILTER_BUFFER(filter) \
4929 + http_filter_ ##filter## _buffer
4931 +#define NEW_BUCKET(data, length) \
4934 + php_stream_bucket *__buck; \
4936 + __data = pemalloc(length, this->is_persistent); \
4938 + return PSFS_ERR_FATAL; \
4940 + memcpy(__data, data, length); \
4942 + __buck = php_stream_bucket_new(stream, __data, length, 1, this->is_persistent TSRMLS_CC); \
4944 + pefree(__data, this->is_persistent); \
4945 + return PSFS_ERR_FATAL; \
4948 + php_stream_bucket_append(buckets_out, __buck TSRMLS_CC); \
4951 +typedef struct _http_chunked_decode_filter_buffer_t {
4954 +} HTTP_FILTER_BUFFER(chunked_decode);
4956 +#ifdef HTTP_HAVE_ZLIB
4957 +typedef http_encoding_stream HTTP_FILTER_BUFFER(deflate);
4958 +typedef http_encoding_stream HTTP_FILTER_BUFFER(inflate);
4959 +#endif /* HTTP_HAVE_ZLIB */
4962 +static HTTP_FILTER_FUNCTION(chunked_decode)
4964 + int out_avail = 0;
4965 + php_stream_bucket *ptr, *nxt;
4966 + HTTP_FILTER_BUFFER(chunked_decode) *buffer = (HTTP_FILTER_BUFFER(chunked_decode) *) (this->abstract);
4968 + if (bytes_consumed) {
4969 + *bytes_consumed = 0;
4972 + /* new data available? */
4973 + if (buckets_in->head) {
4975 + /* fetch available bucket data */
4976 + for (ptr = buckets_in->head; ptr; ptr = nxt) {
4978 + if (bytes_consumed) {
4979 + *bytes_consumed += ptr->buflen;
4982 + if (PHPSTR_NOMEM == phpstr_append(PHPSTR(buffer), ptr->buf, ptr->buflen)) {
4983 + return PSFS_ERR_FATAL;
4986 + php_stream_bucket_unlink(ptr TSRMLS_CC);
4987 + php_stream_bucket_delref(ptr TSRMLS_CC);
4990 + if (!phpstr_fix(PHPSTR(buffer))) {
4991 + return PSFS_ERR_FATAL;
4994 + /* we have data in our buffer */
4995 + while (PHPSTR_LEN(buffer)) {
4997 + /* we already know the size of the chunk and are waiting for data */
4998 + if (buffer->hexlen) {
5000 + /* not enough data buffered */
5001 + if (PHPSTR_LEN(buffer) < buffer->hexlen) {
5003 + /* flush anyway? */
5004 + if (flags & PSFS_FLAG_FLUSH_INC) {
5006 + /* flush all data (should only be chunk data) */
5008 + NEW_BUCKET(PHPSTR_VAL(buffer), PHPSTR_LEN(buffer));
5010 + /* waiting for less data now */
5011 + buffer->hexlen -= PHPSTR_LEN(buffer);
5012 + /* no more buffered data */
5013 + phpstr_reset(PHPSTR(buffer));
5017 + /* we have too less data and don't need to flush */
5023 + /* we seem to have all data of the chunk */
5026 + NEW_BUCKET(PHPSTR_VAL(buffer), buffer->hexlen);
5028 + /* remove outgoing data from the buffer */
5029 + phpstr_cut(PHPSTR(buffer), 0, buffer->hexlen);
5030 + /* reset hexlen */
5031 + buffer->hexlen = 0;
5036 + /* we don't know the length of the chunk yet */
5040 + /* ignore preceeding CRLFs (too loose?) */
5041 + while (off < PHPSTR_LEN(buffer) && (
5042 + PHPSTR_VAL(buffer)[off] == '\n' ||
5043 + PHPSTR_VAL(buffer)[off] == '\r')) {
5047 + phpstr_cut(PHPSTR(buffer), 0, off);
5050 + /* still data there? */
5051 + if (PHPSTR_LEN(buffer)) {
5053 + const char *eolstr;
5055 + /* we need eol, so we can be sure we have all hex digits */
5056 + phpstr_fix(PHPSTR(buffer));
5057 + if ((eolstr = http_locate_eol(PHPSTR_VAL(buffer), &eollen))) {
5058 + char *stop = NULL;
5060 + /* read in chunk size */
5061 + buffer->hexlen = strtoul(PHPSTR_VAL(buffer), &stop, 16);
5063 + /* if strtoul() stops at the beginning of the buffered data
5064 + there's domething oddly wrong, i.e. bad input */
5065 + if (stop == PHPSTR_VAL(buffer)) {
5066 + return PSFS_ERR_FATAL;
5069 + /* cut out <chunk size hex><chunk extension><eol> */
5070 + phpstr_cut(PHPSTR(buffer), 0, eolstr + eollen - PHPSTR_VAL(buffer));
5071 + /* buffer->hexlen is 0 now or contains the size of the next chunk */
5074 + /* we have not enough data buffered to read in chunk size */
5082 + /* flush before close, but only if we are already waiting for more data */
5083 + if ((flags & PSFS_FLAG_FLUSH_CLOSE) && buffer->hexlen && PHPSTR_LEN(buffer)) {
5085 + NEW_BUCKET(PHPSTR_VAL(buffer), PHPSTR_LEN(buffer));
5086 + phpstr_reset(PHPSTR(buffer));
5087 + buffer->hexlen = 0;
5090 + return out_avail ? PSFS_PASS_ON : PSFS_FEED_ME;
5093 +static HTTP_FILTER_DESTRUCTOR(chunked_decode)
5095 + HTTP_FILTER_BUFFER(chunked_decode) *b = (HTTP_FILTER_BUFFER(chunked_decode) *) (this->abstract);
5097 + phpstr_dtor(PHPSTR(b));
5098 + pefree(b, this->is_persistent);
5101 +static HTTP_FILTER_FUNCTION(chunked_encode)
5103 + int out_avail = 0;
5104 + php_stream_bucket *ptr, *nxt;
5106 + if (bytes_consumed) {
5107 + *bytes_consumed = 0;
5110 + /* new data available? */
5111 + if (buckets_in->head) {
5115 + phpstr_init(&buf);
5117 + /* fetch available bucket data */
5118 + for (ptr = buckets_in->head; ptr; ptr = nxt) {
5120 + if (bytes_consumed) {
5121 + *bytes_consumed += ptr->buflen;
5124 + phpstr_appendf(&buf, "%x" HTTP_CRLF, ptr->buflen);
5125 + phpstr_append(&buf, ptr->buf, ptr->buflen);
5126 + phpstr_appends(&buf, HTTP_CRLF);
5128 + /* pass through */
5129 + NEW_BUCKET(PHPSTR_VAL(&buf), PHPSTR_LEN(&buf));
5131 + phpstr_reset(&buf);
5133 + php_stream_bucket_unlink(ptr TSRMLS_CC);
5134 + php_stream_bucket_delref(ptr TSRMLS_CC);
5138 + phpstr_dtor(&buf);
5141 + /* terminate with "0" */
5142 + if (flags & PSFS_FLAG_FLUSH_CLOSE) {
5144 + NEW_BUCKET("0" HTTP_CRLF, lenof("0" HTTP_CRLF));
5147 + return out_avail ? PSFS_PASS_ON : PSFS_FEED_ME;
5150 +static HTTP_FILTER_OPS(chunked_decode) = {
5151 + HTTP_FILTER_FUNC(chunked_decode),
5152 + HTTP_FILTER_DTOR(chunked_decode),
5153 + "http.chunked_decode"
5156 +static HTTP_FILTER_OPS(chunked_encode) = {
5157 + HTTP_FILTER_FUNC(chunked_encode),
5159 + "http.chunked_encode"
5162 +#ifdef HTTP_HAVE_ZLIB
5164 +static HTTP_FILTER_FUNCTION(deflate)
5166 + int out_avail = 0;
5167 + php_stream_bucket *ptr, *nxt;
5168 + HTTP_FILTER_BUFFER(inflate) *buffer = (HTTP_FILTER_BUFFER(deflate) *) this->abstract;
5170 + if (bytes_consumed) {
5171 + *bytes_consumed = 0;
5174 + /* new data available? */
5175 + if (buckets_in->head) {
5177 + /* fetch available bucket data */
5178 + for (ptr = buckets_in->head; ptr; ptr = nxt) {
5179 + char *encoded = NULL;
5180 + size_t encoded_len = 0;
5183 + if (bytes_consumed) {
5184 + *bytes_consumed += ptr->buflen;
5187 + if (ptr->buflen) {
5188 + http_encoding_deflate_stream_update(buffer, ptr->buf, ptr->buflen, &encoded, &encoded_len);
5190 + if (encoded_len) {
5192 + NEW_BUCKET(encoded, encoded_len);
5198 + php_stream_bucket_unlink(ptr TSRMLS_CC);
5199 + php_stream_bucket_delref(ptr TSRMLS_CC);
5203 + /* flush & close */
5204 + if (flags & PSFS_FLAG_FLUSH_INC) {
5205 + char *encoded = NULL;
5206 + size_t encoded_len = 0;
5208 + http_encoding_deflate_stream_flush(buffer, &encoded, &encoded_len);
5210 + if (encoded_len) {
5212 + NEW_BUCKET(encoded, encoded_len);
5218 + if (flags & PSFS_FLAG_FLUSH_CLOSE) {
5219 + char *encoded = NULL;
5220 + size_t encoded_len = 0;
5222 + http_encoding_deflate_stream_finish(buffer, &encoded, &encoded_len);
5224 + if (encoded_len) {
5226 + NEW_BUCKET(encoded, encoded_len);
5232 + return out_avail ? PSFS_PASS_ON : PSFS_FEED_ME;
5235 +static HTTP_FILTER_FUNCTION(inflate)
5237 + int out_avail = 0;
5238 + php_stream_bucket *ptr, *nxt;
5239 + HTTP_FILTER_BUFFER(inflate) *buffer = (HTTP_FILTER_BUFFER(inflate) *) this->abstract;
5241 + if (bytes_consumed) {
5242 + *bytes_consumed = 0;
5245 + /* new data available? */
5246 + if (buckets_in->head) {
5248 + /* fetch available bucket data */
5249 + for (ptr = buckets_in->head; ptr; ptr = nxt) {
5250 + char *decoded = NULL;
5251 + size_t decoded_len = 0;
5254 + if (bytes_consumed) {
5255 + *bytes_consumed += ptr->buflen;
5258 + if (ptr->buflen) {
5259 + http_encoding_inflate_stream_update(buffer, ptr->buf, ptr->buflen, &decoded, &decoded_len);
5261 + if (decoded_len) {
5263 + NEW_BUCKET(decoded, decoded_len);
5269 + php_stream_bucket_unlink(ptr TSRMLS_CC);
5270 + php_stream_bucket_delref(ptr TSRMLS_CC);
5274 + /* flush & close */
5275 + if (flags & PSFS_FLAG_FLUSH_INC) {
5276 + char *decoded = NULL;
5277 + size_t decoded_len = 0;
5279 + http_encoding_inflate_stream_flush(buffer, &decoded, &decoded_len);
5281 + if (decoded_len) {
5283 + NEW_BUCKET(decoded, decoded_len);
5289 + if (flags & PSFS_FLAG_FLUSH_CLOSE) {
5290 + char *decoded = NULL;
5291 + size_t decoded_len = 0;
5293 + http_encoding_inflate_stream_finish(buffer, &decoded, &decoded_len);
5295 + if (decoded_len) {
5297 + NEW_BUCKET(decoded, decoded_len);
5303 + return out_avail ? PSFS_PASS_ON : PSFS_FEED_ME;
5306 +static HTTP_FILTER_DESTRUCTOR(deflate)
5308 + HTTP_FILTER_BUFFER(deflate) *buffer = (HTTP_FILTER_BUFFER(deflate) *) this->abstract;
5309 + http_encoding_deflate_stream_free(&buffer);
5312 +static HTTP_FILTER_DESTRUCTOR(inflate)
5314 + HTTP_FILTER_BUFFER(inflate) *buffer = (HTTP_FILTER_BUFFER(inflate) *) this->abstract;
5315 + http_encoding_inflate_stream_free(&buffer);
5318 +static HTTP_FILTER_OPS(deflate) = {
5319 + HTTP_FILTER_FUNC(deflate),
5320 + HTTP_FILTER_DTOR(deflate),
5324 +static HTTP_FILTER_OPS(inflate) = {
5325 + HTTP_FILTER_FUNC(inflate),
5326 + HTTP_FILTER_DTOR(inflate),
5330 +#endif /* HTTP_HAVE_ZLIB */
5332 +static php_stream_filter *http_filter_create(const char *name, zval *params, int p TSRMLS_DC)
5334 + zval **tmp = ¶ms;
5335 + php_stream_filter *f = NULL;
5337 + if (!strcasecmp(name, "http.chunked_decode")) {
5338 + HTTP_FILTER_BUFFER(chunked_decode) *b = NULL;
5340 + if ((b = pecalloc(1, sizeof(HTTP_FILTER_BUFFER(chunked_decode)), p))) {
5341 + phpstr_init_ex(PHPSTR(b), 4096, p ? PHPSTR_INIT_PERSISTENT : 0);
5342 + if (!(f = php_stream_filter_alloc(&HTTP_FILTER_OP(chunked_decode), b, p))) {
5348 + if (!strcasecmp(name, "http.chunked_encode")) {
5349 + f = php_stream_filter_alloc(&HTTP_FILTER_OP(chunked_encode), NULL, p);
5350 +#ifdef HTTP_HAVE_ZLIB
5353 + if (!strcasecmp(name, "http.inflate")) {
5354 + int flags = p ? HTTP_ENCODING_STREAM_PERSISTENT : 0;
5355 + HTTP_FILTER_BUFFER(inflate) *b = NULL;
5357 + if ((b = http_encoding_inflate_stream_init(NULL, flags))) {
5358 + if (!(f = php_stream_filter_alloc(&HTTP_FILTER_OP(inflate), b, p))) {
5359 + http_encoding_inflate_stream_free(&b);
5364 + if (!strcasecmp(name, "http.deflate")) {
5365 + int flags = p ? HTTP_ENCODING_STREAM_PERSISTENT : 0;
5366 + HTTP_FILTER_BUFFER(deflate) *b = NULL;
5369 + switch (Z_TYPE_P(params)) {
5372 + if (SUCCESS != zend_hash_find(HASH_OF(params), "flags", sizeof("flags"), (void *) &tmp)) {
5377 + zval *num = http_zsep(IS_LONG, *tmp);
5379 + flags |= (Z_LVAL_P(num) & 0x0fffffff);
5380 + zval_ptr_dtor(&num);
5384 + if ((b = http_encoding_deflate_stream_init(NULL, flags))) {
5385 + if (!(f = php_stream_filter_alloc(&HTTP_FILTER_OP(deflate), b, p))) {
5386 + http_encoding_deflate_stream_free(&b);
5389 +#endif /* HTTP_HAVE_ZLIB */
5395 +php_stream_filter_factory http_filter_factory = {
5396 + http_filter_create
5399 +#endif /* ZEND_ENGINE_2 */
5402 + * Local variables:
5404 + * c-basic-offset: 4
5406 + * vim600: noet sw=4 ts=4 fdm=marker
5407 + * vim<600: noet sw=4 ts=4
5410 +++ b/ext/http/http_functions.c
5413 + +--------------------------------------------------------------------+
5415 + +--------------------------------------------------------------------+
5416 + | Redistribution and use in source and binary forms, with or without |
5417 + | modification, are permitted provided that the conditions mentioned |
5418 + | in the accompanying LICENSE file are met. |
5419 + +--------------------------------------------------------------------+
5420 + | Copyright (c) 2004-2010, Michael Wallner <mike@php.net> |
5421 + +--------------------------------------------------------------------+
5424 +/* $Id: http_functions.c 300301 2010-06-09 08:30:34Z mike $ */
5426 +#define HTTP_WANT_SAPI
5427 +#define HTTP_WANT_CURL
5428 +#define HTTP_WANT_ZLIB
5429 +#include "php_http.h"
5431 +#include "php_ini.h"
5432 +#include "ext/standard/php_string.h"
5433 +#include "zend_operators.h"
5435 +#ifdef HTTP_HAVE_SESSION
5436 +# include "ext/session/php_session.h"
5439 +#include "php_http_api.h"
5440 +#include "php_http_cache_api.h"
5441 +#include "php_http_cookie_api.h"
5442 +#include "php_http_date_api.h"
5443 +#include "php_http_encoding_api.h"
5444 +#include "php_http_headers_api.h"
5445 +#include "php_http_message_api.h"
5446 +#include "php_http_request_api.h"
5447 +#include "php_http_request_method_api.h"
5448 +#include "php_http_persistent_handle_api.h"
5449 +#include "php_http_send_api.h"
5450 +#include "php_http_url_api.h"
5452 +/* {{{ proto string http_date([int timestamp])
5453 + Compose a valid HTTP date regarding RFC 1123 looking like: "Wed, 22 Dec 2004 11:34:47 GMT" */
5454 +PHP_FUNCTION(http_date)
5459 + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &t) != SUCCESS) {
5464 + t = HTTP_G->request.time;
5467 + if (!(date = http_date(t))) {
5468 + http_error_ex(HE_WARNING, HTTP_E_INVALID_PARAM, "Could not compose date of timestamp %ld", t);
5472 + RETURN_STRING(date, 0);
5476 +/* {{{ proto string http_build_url([mixed url[, mixed parts[, int flags = HTTP_URL_REPLACE|HTTP_URL_FROM_ENV[, array &new_url]]]])
5478 +PHP_FUNCTION(http_build_url)
5480 + char *url_str = NULL;
5481 + size_t url_len = 0;
5482 + long flags = HTTP_URL_REPLACE|HTTP_URL_FROM_ENV;
5483 + zval *z_old_url = NULL, *z_new_url = NULL, *z_composed_url = NULL;
5484 + php_url *old_url = NULL, *new_url = NULL, *composed_url = NULL;
5486 + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|z!/z!/lz", &z_old_url, &z_new_url, &flags, &z_composed_url) != SUCCESS) {
5491 + if (Z_TYPE_P(z_new_url) == IS_ARRAY || Z_TYPE_P(z_new_url) == IS_OBJECT) {
5492 + new_url = http_url_from_struct(NULL, HASH_OF(z_new_url));
5494 + convert_to_string(z_new_url);
5495 + if (!(new_url = php_url_parse_ex(Z_STRVAL_P(z_new_url), Z_STRLEN_P(z_new_url)))) {
5496 + http_error_ex(HE_WARNING, HTTP_E_URL, "Could not parse URL (%s)", Z_STRVAL_P(z_new_url));
5503 + if (Z_TYPE_P(z_old_url) == IS_ARRAY || Z_TYPE_P(z_old_url) == IS_OBJECT) {
5504 + old_url = http_url_from_struct(NULL, HASH_OF(z_old_url));
5506 + convert_to_string(z_old_url);
5507 + if (!(old_url = php_url_parse_ex(Z_STRVAL_P(z_old_url), Z_STRLEN_P(z_old_url)))) {
5509 + php_url_free(new_url);
5511 + http_error_ex(HE_WARNING, HTTP_E_URL, "Could not parse URL (%s)", Z_STRVAL_P(z_old_url));
5517 + if (z_composed_url) {
5518 + http_build_url(flags, old_url, new_url, &composed_url, &url_str, &url_len);
5519 + http_url_tostruct(composed_url, z_composed_url);
5520 + php_url_free(composed_url);
5522 + http_build_url(flags, old_url, new_url, NULL, &url_str, &url_len);
5526 + php_url_free(new_url);
5529 + php_url_free(old_url);
5532 + RETURN_STRINGL(url_str, url_len, 0);
5536 +/* {{{ proto string http_build_str(array query [, string prefix[, string arg_separator]])
5537 + Opponent to parse_str(). */
5538 +PHP_FUNCTION(http_build_str)
5541 + char *prefix = NULL, *arg_sep = INI_STR("arg_separator.output");
5542 + int prefix_len = 0, arg_sep_len = strlen(arg_sep);
5545 + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a|ss", &formdata, &prefix, &prefix_len, &arg_sep, &arg_sep_len) != SUCCESS) {
5549 + if (!arg_sep_len) {
5550 + arg_sep = HTTP_URL_ARGSEP;
5551 + arg_sep_len = lenof(HTTP_URL_ARGSEP);
5554 + phpstr_init(&formstr);
5555 + if (SUCCESS != http_urlencode_hash_recursive(HASH_OF(formdata), &formstr, arg_sep, arg_sep_len, prefix, prefix_len)) {
5559 + if (!formstr.used) {
5560 + phpstr_dtor(&formstr);
5564 + RETURN_PHPSTR_VAL(&formstr);
5568 +#define HTTP_DO_NEGOTIATE_DEFAULT(supported) \
5572 + zend_hash_internal_pointer_reset(Z_ARRVAL_P(supported)); \
5573 + if (SUCCESS == zend_hash_get_current_data(Z_ARRVAL_P(supported), (void *) &value)) { \
5574 + RETVAL_ZVAL(*value, 1, 0); \
5580 +#define HTTP_DO_NEGOTIATE_HANDLE_DEFAULT(supported, rs_array) \
5581 + HTTP_DO_NEGOTIATE_DEFAULT(supported); \
5583 + HashPosition pos; \
5584 + zval **value_ptr; \
5586 + FOREACH_VAL(pos, supported, value_ptr) { \
5587 + zval *value = http_zsep(IS_STRING, *value_ptr); \
5588 + add_assoc_double(rs_array, Z_STRVAL_P(value), 1.0); \
5589 + zval_ptr_dtor(&value); \
5593 +#define HTTP_DO_NEGOTIATE_HANDLE_RESULT(result, supported, rs_array) \
5599 + if (zend_hash_num_elements(result) && HASH_KEY_IS_STRING == zend_hash_get_current_key_ex(result, &key, &key_len, &idx, 1, NULL)) { \
5600 + RETVAL_STRINGL(key, key_len-1, 0); \
5602 + HTTP_DO_NEGOTIATE_DEFAULT(supported); \
5606 + zend_hash_copy(Z_ARRVAL_P(rs_array), result, (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *)); \
5609 + zend_hash_destroy(result); \
5610 + FREE_HASHTABLE(result); \
5613 +#define HTTP_DO_NEGOTIATE(type, supported, rs_array) \
5615 + HashTable *result; \
5616 + if ((result = http_negotiate_ ##type(supported))) { \
5617 + HTTP_DO_NEGOTIATE_HANDLE_RESULT(result, supported, rs_array); \
5619 + HTTP_DO_NEGOTIATE_HANDLE_DEFAULT(supported, rs_array); \
5623 +/* {{{ proto string http_negotiate_language(array supported[, array &result])
5624 + Negotiate the clients preferred language. */
5625 +PHP_FUNCTION(http_negotiate_language)
5627 + zval *supported, *rs_array = NULL;
5629 + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a|z", &supported, &rs_array) != SUCCESS) {
5634 + zval_dtor(rs_array);
5635 + array_init(rs_array);
5638 + HTTP_DO_NEGOTIATE(language, supported, rs_array);
5642 +/* {{{ proto string http_negotiate_charset(array supported[, array &result])
5643 + Negotiate the clients preferred charset. */
5644 +PHP_FUNCTION(http_negotiate_charset)
5646 + zval *supported, *rs_array = NULL;
5648 + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a|z", &supported, &rs_array) != SUCCESS) {
5653 + zval_dtor(rs_array);
5654 + array_init(rs_array);
5657 + HTTP_DO_NEGOTIATE(charset, supported, rs_array);
5661 +/* {{{ proto string http_negotiate_content_type(array supported[, array &result])
5662 + Negotiate the clients preferred content type. */
5663 +PHP_FUNCTION(http_negotiate_content_type)
5665 + zval *supported, *rs_array = NULL;
5667 + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a|z", &supported, &rs_array)) {
5672 + zval_dtor(rs_array);
5673 + array_init(rs_array);
5676 + HTTP_DO_NEGOTIATE(content_type, supported, rs_array);
5680 +/* {{{ proto string http_negotiate(mixed value, array supported[, array &result])
5681 + Negotiate the user supplied value. */
5682 +PHP_FUNCTION(http_negotiate)
5684 + zval *value, *supported, *rs_array = NULL;
5687 + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "za|z", &value, &supported, &rs_array)) {
5692 + zval_dtor(rs_array);
5693 + array_init(rs_array);
5696 + if ((rs = http_negotiate_z(value, Z_ARRVAL_P(supported), http_negotiate_default_func))) {
5697 + HTTP_DO_NEGOTIATE_HANDLE_RESULT(rs, supported, rs_array);
5699 + HTTP_DO_NEGOTIATE_HANDLE_DEFAULT(supported, rs_array);
5704 +/* {{{ proto bool http_send_status(int status)
5705 + Send HTTP status code. */
5706 +PHP_FUNCTION(http_send_status)
5710 + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &status) != SUCCESS) {
5713 + if (status < 100 || status > 510) {
5714 + http_error_ex(HE_WARNING, HTTP_E_HEADER, "Invalid HTTP status code (100-510): %d", status);
5718 + RETURN_SUCCESS(http_send_status(status));
5722 +/* {{{ proto bool http_send_last_modified([int timestamp])
5723 + Send a "Last-Modified" header with a valid HTTP date. */
5724 +PHP_FUNCTION(http_send_last_modified)
5728 + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &t) != SUCCESS) {
5733 + t = HTTP_G->request.time;
5736 + RETURN_SUCCESS(http_send_last_modified(t));
5740 +/* {{{ proto bool http_send_content_type([string content_type = 'application/x-octetstream'])
5741 + Send the Content-Type of the sent entity. This is particularly important if you use the http_send() API. */
5742 +PHP_FUNCTION(http_send_content_type)
5744 + char *ct = "application/x-octetstream";
5745 + int ct_len = lenof("application/x-octetstream");
5747 + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &ct, &ct_len) != SUCCESS) {
5751 + RETURN_SUCCESS(http_send_content_type(ct, ct_len));
5755 +/* {{{ proto bool http_send_content_disposition(string filename[, bool inline = false])
5756 + Send the Content-Disposition. */
5757 +PHP_FUNCTION(http_send_content_disposition)
5761 + zend_bool send_inline = 0;
5763 + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|b", &filename, &f_len, &send_inline) != SUCCESS) {
5766 + RETURN_SUCCESS(http_send_content_disposition(filename, f_len, send_inline));
5770 +/* {{{ proto bool http_match_modified([int timestamp[, bool for_range = false]])
5771 + Matches the given unix timestamp against the clients "If-Modified-Since" resp. "If-Unmodified-Since" HTTP headers. */
5772 +PHP_FUNCTION(http_match_modified)
5775 + zend_bool for_range = 0;
5777 + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|lb", &t, &for_range) != SUCCESS) {
5781 + // current time if not supplied (senseless though)
5783 + t = HTTP_G->request.time;
5787 + RETURN_BOOL(http_match_last_modified("HTTP_IF_UNMODIFIED_SINCE", t));
5789 + RETURN_BOOL(http_match_last_modified("HTTP_IF_MODIFIED_SINCE", t));
5793 +/* {{{ proto bool http_match_etag(string etag[, bool for_range = false])
5794 + Matches the given ETag against the clients "If-Match" resp. "If-None-Match" HTTP headers. */
5795 +PHP_FUNCTION(http_match_etag)
5799 + zend_bool for_range = 0;
5801 + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|b", &etag, &etag_len, &for_range) != SUCCESS) {
5806 + RETURN_BOOL(http_match_etag("HTTP_IF_MATCH", etag));
5808 + RETURN_BOOL(http_match_etag("HTTP_IF_NONE_MATCH", etag));
5812 +/* {{{ proto bool http_cache_last_modified([int timestamp_or_expires]])
5813 + Attempts to cache the sent entity by its last modification date. */
5814 +PHP_FUNCTION(http_cache_last_modified)
5816 + long last_modified = 0, send_modified = 0, t;
5819 + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &last_modified) != SUCCESS) {
5823 + HTTP_CHECK_HEADERS_SENT(RETURN_FALSE);
5825 + t = HTTP_G->request.time;
5827 + /* 0 or omitted */
5828 + if (!last_modified) {
5829 + /* does the client have? (att: caching "forever") */
5830 + if ((zlm = http_get_server_var("HTTP_IF_MODIFIED_SINCE", 1))) {
5831 + last_modified = send_modified = http_parse_date(Z_STRVAL_P(zlm));
5832 + /* send current time */
5834 + send_modified = t;
5836 + /* negative value is supposed to be expiration time */
5837 + } else if (last_modified < 0) {
5838 + last_modified += t;
5839 + send_modified = t;
5840 + /* send supplied time explicitly */
5842 + send_modified = last_modified;
5845 + RETURN_SUCCESS(http_cache_last_modified(last_modified, send_modified, HTTP_DEFAULT_CACHECONTROL, lenof(HTTP_DEFAULT_CACHECONTROL)));
5849 +/* {{{ proto bool http_cache_etag([string etag])
5850 + Attempts to cache the sent entity by its ETag, either supplied or generated by the hash algorithm specified by the INI setting "http.etag.mode". */
5851 +PHP_FUNCTION(http_cache_etag)
5853 + char *etag = NULL;
5856 + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &etag, &etag_len) != SUCCESS) {
5860 + HTTP_CHECK_HEADERS_SENT(RETURN_FALSE);
5862 + RETURN_SUCCESS(http_cache_etag(etag, etag_len, HTTP_DEFAULT_CACHECONTROL, lenof(HTTP_DEFAULT_CACHECONTROL)));
5866 +/* {{{ proto string ob_etaghandler(string data, int mode)
5867 + For use with ob_start(). Output buffer handler generating an ETag with the hash algorithm specified with the INI setting "http.etag.mode". */
5868 +PHP_FUNCTION(ob_etaghandler)
5874 + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sl", &data, &data_len, &mode)) {
5878 + Z_TYPE_P(return_value) = IS_STRING;
5879 + http_ob_etaghandler(data, data_len, &Z_STRVAL_P(return_value), (uint *) &Z_STRLEN_P(return_value), mode);
5883 +/* {{{ proto void http_throttle(double sec[, int bytes = 40960])
5884 + Sets the throttle delay and send buffer size for use with http_send() API. */
5885 +PHP_FUNCTION(http_throttle)
5887 + long chunk_size = HTTP_SENDBUF_SIZE;
5890 + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "d|l", &interval, &chunk_size)) {
5894 + HTTP_G->send.throttle_delay = interval;
5895 + HTTP_G->send.buffer_size = chunk_size;
5899 +/* {{{ proto void http_redirect([string url[, array params[, bool session = false[, int status = 302]]]])
5900 + Redirect to the given url. */
5901 +PHP_FUNCTION(http_redirect)
5904 + size_t query_len = 0;
5905 + zend_bool session = 0, free_params = 0;
5906 + zval *params = NULL;
5907 + long status = HTTP_REDIRECT;
5908 + char *query = NULL, *url = NULL, *URI, *LOC, *RED = NULL;
5910 + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|sa!/bl", &url, &url_len, ¶ms, &session, &status) != SUCCESS) {
5914 +#ifdef HTTP_HAVE_SESSION
5915 + /* append session info */
5919 + MAKE_STD_ZVAL(params);
5920 + array_init(params);
5922 + if (PS(session_status) == php_session_active) {
5923 + if (add_assoc_string(params, PS(session_name), PS(id), 1) != SUCCESS) {
5924 + http_error(HE_WARNING, HTTP_E_RUNTIME, "Could not append session information");
5930 + /* treat params array with http_build_query() */
5932 + if (SUCCESS != http_urlencode_hash_ex(Z_ARRVAL_P(params), 0, NULL, 0, &query, &query_len)) {
5933 + if (free_params) {
5934 + zval_dtor(params);
5935 + FREE_ZVAL(params);
5944 + URI = http_absolute_url_ex(url, HTTP_URL_FROM_ENV);
5947 + spprintf(&LOC, 0, "Location: %s?%s", URI, query);
5948 + if (status != 300) {
5949 + spprintf(&RED, 0, "Redirecting to <a href=\"%s?%s\">%s?%s</a>.\n", URI, query, URI, query);
5952 + spprintf(&LOC, 0, "Location: %s", URI);
5953 + if (status != 300) {
5954 + spprintf(&RED, 0, "Redirecting to <a href=\"%s\">%s</a>.\n", URI, URI);
5962 + if (free_params) {
5963 + zval_dtor(params);
5964 + FREE_ZVAL(params);
5969 + RETVAL_SUCCESS(http_send_status_header(status, LOC));
5973 + case HTTP_REDIRECT_PERM:
5974 + case HTTP_REDIRECT_FOUND:
5975 + case HTTP_REDIRECT_POST:
5976 + case HTTP_REDIRECT_PROXY:
5977 + case HTTP_REDIRECT_TEMP:
5982 + http_error_ex(HE_NOTICE, HTTP_E_RUNTIME, "Unsupported redirection status code: %ld", status);
5983 + case HTTP_REDIRECT:
5984 + if ( SG(request_info).request_method &&
5985 + strcasecmp(SG(request_info).request_method, "HEAD") &&
5986 + strcasecmp(SG(request_info).request_method, "GET")) {
5987 + status = HTTP_REDIRECT_POST;
5989 + status = HTTP_REDIRECT_FOUND;
5994 + RETURN_SUCCESS(http_exit_ex(status, LOC, RED, 1));
5998 +/* {{{ proto bool http_send_data(string data)
5999 + Sends raw data with support for (multiple) range requests. */
6000 +PHP_FUNCTION(http_send_data)
6005 + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &data_buf, &data_len) != SUCCESS) {
6009 + RETURN_SUCCESS(http_send_data(data_buf, data_len));
6013 +/* {{{ proto bool http_send_file(string file)
6014 + Sends a file with support for (multiple) range requests. */
6015 +PHP_FUNCTION(http_send_file)
6020 + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &file, &flen) != SUCCESS) {
6027 + RETURN_SUCCESS(http_send_file(file));
6031 +/* {{{ proto bool http_send_stream(resource stream)
6032 + Sends an already opened stream with support for (multiple) range requests. */
6033 +PHP_FUNCTION(http_send_stream)
6038 + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zstream) != SUCCESS) {
6042 + php_stream_from_zval(file, &zstream);
6043 + RETURN_SUCCESS(http_send_stream(file));
6047 +/* {{{ proto string http_chunked_decode(string encoded)
6048 + Decodes a string that was HTTP-chunked encoded. */
6049 +PHP_FUNCTION(http_chunked_decode)
6051 + char *encoded = NULL, *decoded = NULL;
6052 + size_t decoded_len = 0;
6053 + int encoded_len = 0;
6055 + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &encoded, &encoded_len) != SUCCESS) {
6059 + if (NULL != http_encoding_dechunk(encoded, encoded_len, &decoded, &decoded_len)) {
6060 + RETURN_STRINGL(decoded, (int) decoded_len, 0);
6067 +/* {{{ proto object http_parse_message(string message)
6068 + Parses (a) http_message(s) into a simple recursive object structure. */
6069 +PHP_FUNCTION(http_parse_message)
6073 + http_message *msg = NULL;
6075 + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &message, &message_len)) {
6079 + if ((msg = http_message_parse(message, message_len))) {
6080 + object_init(return_value);
6081 + http_message_tostruct_recursive(msg, return_value);
6082 + http_message_free(&msg);
6089 +/* {{{ proto array http_parse_headers(string header)
6090 + Parses HTTP headers into an associative array. */
6091 +PHP_FUNCTION(http_parse_headers)
6096 + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &header, &header_len)) {
6100 + array_init(return_value);
6101 + if (SUCCESS != http_parse_headers(header, return_value)) {
6102 + zval_dtor(return_value);
6103 + http_error(HE_WARNING, HTTP_E_MALFORMED_HEADERS, "Failed to parse headers");
6109 +/* {{{ proto object http_parse_cookie(string cookie[, int flags[, array allowed_extras]])
6110 + Parses HTTP cookies like sent in a response into a struct. */
6111 +PHP_FUNCTION(http_parse_cookie)
6113 + char *cookie, **allowed_extras = NULL;
6114 + int i = 0, cookie_len;
6116 + zval *allowed_extras_array = NULL, **entry = NULL;
6118 + http_cookie_list list;
6120 + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|la!", &cookie, &cookie_len, &flags, &allowed_extras_array)) {
6124 + if (allowed_extras_array) {
6125 + allowed_extras = ecalloc(zend_hash_num_elements(Z_ARRVAL_P(allowed_extras_array)) + 1, sizeof(char *));
6126 + FOREACH_VAL(pos, allowed_extras_array, entry) {
6127 + zval *data = http_zsep(IS_STRING, *entry);
6128 + allowed_extras[i++] = estrndup(Z_STRVAL_P(data), Z_STRLEN_P(data));
6129 + zval_ptr_dtor(&data);
6133 + if (http_parse_cookie_ex(&list, cookie, flags, allowed_extras)) {
6134 + object_init(return_value);
6135 + http_cookie_list_tostruct(&list, return_value);
6136 + http_cookie_list_dtor(&list);
6141 + if (allowed_extras) {
6142 + for (i = 0; allowed_extras[i]; ++i) {
6143 + efree(allowed_extras[i]);
6145 + efree(allowed_extras);
6150 +/* {{{ proto string http_build_cookie(array cookie)
6151 + Build a cookie string from an array/object like returned by http_parse_cookie(). */
6152 +PHP_FUNCTION(http_build_cookie)
6157 + http_cookie_list list;
6159 + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a", &strct)) {
6163 + http_cookie_list_fromstruct(&list, strct);
6164 + http_cookie_list_tostring(&list, &str, &len);
6165 + http_cookie_list_dtor(&list);
6167 + RETURN_STRINGL(str, len, 0);
6171 +/* {{{ proto object http_parse_params(string param[, int flags = HTTP_PARAMS_DEFAULT])
6172 + Parse parameter list. */
6173 +PHP_FUNCTION(http_parse_params)
6178 + long flags = HTTP_PARAMS_DEFAULT;
6180 + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", ¶m, ¶m_len, &flags)) {
6184 + MAKE_STD_ZVAL(params);
6185 + array_init(params);
6186 + if (SUCCESS != http_parse_params(param, flags, Z_ARRVAL_P(params))) {
6187 + zval_ptr_dtor(¶ms);
6191 + object_init(return_value);
6192 + add_property_zval(return_value, "params", params);
6193 +#ifdef ZEND_ENGINE_2
6194 + zval_ptr_dtor(¶ms);
6199 +/* {{{ proto array http_get_request_headers(void)
6200 + Get a list of incoming HTTP headers. */
6201 +PHP_FUNCTION(http_get_request_headers)
6205 + array_init(return_value);
6206 + http_get_request_headers(Z_ARRVAL_P(return_value));
6210 +/* {{{ proto string http_get_request_body(void)
6211 + Get the raw request body (e.g. POST or PUT data). */
6212 +PHP_FUNCTION(http_get_request_body)
6219 + if (SUCCESS == http_get_request_body(&body, &length)) {
6220 + RETURN_STRINGL(body, (int) length, 0);
6227 +/* {{{ proto resource http_get_request_body_stream(void)
6228 + Create a stream to read the raw request body (e.g. POST or PUT data). This function can only be used once if the request method was another than POST. */
6229 +PHP_FUNCTION(http_get_request_body_stream)
6235 + if ((s = http_get_request_body_stream())) {
6236 + php_stream_to_zval(s, return_value);
6238 + http_error(HE_WARNING, HTTP_E_RUNTIME, "Failed to create request body stream");
6244 +/* {{{ proto bool http_match_request_header(string header, string value[, bool match_case = false])
6245 + Match an incoming HTTP header. */
6246 +PHP_FUNCTION(http_match_request_header)
6248 + char *header, *value;
6249 + int header_len, value_len;
6250 + zend_bool match_case = 0;
6252 + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|b", &header, &header_len, &value, &value_len, &match_case)) {
6256 + RETURN_BOOL(http_match_request_header_ex(header, value, match_case));
6260 +/* {{{ proto object http_persistent_handles_count() */
6261 +PHP_FUNCTION(http_persistent_handles_count)
6264 + object_init(return_value);
6265 + if (!http_persistent_handle_statall_ex(HASH_OF(return_value))) {
6266 + zval_dtor(return_value);
6272 +/* {{{ proto void http_persistent_handles_clean([string name]) */
6273 +PHP_FUNCTION(http_persistent_handles_clean)
6275 + char *name_str = NULL;
6278 + if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &name_str, &name_len)) {
6279 + http_persistent_handle_cleanup_ex(name_str, name_len, 1);
6284 +/* {{{ proto string http_persistent_handles_ident([string ident]) */
6285 +PHP_FUNCTION(http_persistent_handles_ident)
6287 + char *ident_str = NULL;
6288 + int ident_len = 0;
6290 + if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &ident_str, &ident_len)) {
6291 + RETVAL_STRING(zend_ini_string(ZEND_STRS("http.persistent.handles.ident"), 0), 1);
6292 + if (ident_str && ident_len) {
6293 + zend_alter_ini_entry(ZEND_STRS("http.persistent.handles.ident"), ident_str, ident_len, ZEND_INI_USER, PHP_INI_STAGE_RUNTIME);
6299 +/* {{{ HAVE_CURL */
6300 +#ifdef HTTP_HAVE_CURL
6302 +#define RETVAL_RESPONSE_OR_BODY(request) \
6304 + zval **bodyonly; \
6306 + /* check if only the body should be returned */ \
6307 + if (options && (SUCCESS == zend_hash_find(Z_ARRVAL_P(options), "bodyonly", sizeof("bodyonly"), (void *) &bodyonly)) && i_zend_is_true(*bodyonly)) { \
6308 + http_message *msg = http_message_parse(PHPSTR_VAL(&request.conv.response), PHPSTR_LEN(&request.conv.response)); \
6311 + RETVAL_STRINGL(PHPSTR_VAL(&msg->body), PHPSTR_LEN(&msg->body), 1); \
6312 + http_message_free(&msg); \
6315 + RETVAL_STRINGL(request.conv.response.data, request.conv.response.used, 1); \
6319 +/* {{{ proto string http_get(string url[, array options[, array &info]])
6320 + Performs an HTTP GET request on the supplied url. */
6321 +PHP_FUNCTION(http_get)
6323 + zval *options = NULL, *info = NULL;
6326 + http_request request;
6328 + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|a/!z", &URL, &URL_len, &options, &info) != SUCCESS) {
6339 + http_request_init_ex(&request, NULL, HTTP_GET, URL);
6340 + if (SUCCESS == http_request_prepare(&request, options?Z_ARRVAL_P(options):NULL)) {
6341 + http_request_exec(&request);
6343 + http_request_info(&request, Z_ARRVAL_P(info));
6345 + RETVAL_RESPONSE_OR_BODY(request);
6347 + http_request_dtor(&request);
6351 +/* {{{ proto string http_head(string url[, array options[, array &info]])
6352 + Performs an HTTP HEAD request on the supplied url. */
6353 +PHP_FUNCTION(http_head)
6355 + zval *options = NULL, *info = NULL;
6358 + http_request request;
6360 + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|a/!z", &URL, &URL_len, &options, &info) != SUCCESS) {
6371 + http_request_init_ex(&request, NULL, HTTP_HEAD, URL);
6372 + if (SUCCESS == http_request_prepare(&request, options?Z_ARRVAL_P(options):NULL)) {
6373 + http_request_exec(&request);
6375 + http_request_info(&request, Z_ARRVAL_P(info));
6377 + RETVAL_RESPONSE_OR_BODY(request);
6379 + http_request_dtor(&request);
6383 +/* {{{ proto string http_post_data(string url, string data[, array options[, array &info]])
6384 + Performs an HTTP POST request on the supplied url. */
6385 +PHP_FUNCTION(http_post_data)
6387 + zval *options = NULL, *info = NULL;
6388 + char *URL, *postdata;
6389 + int postdata_len, URL_len;
6390 + http_request_body body;
6391 + http_request request;
6393 + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|a/!z", &URL, &URL_len, &postdata, &postdata_len, &options, &info) != SUCCESS) {
6404 + http_request_init_ex(&request, NULL, HTTP_POST, URL);
6405 + request.body = http_request_body_init_ex(&body, HTTP_REQUEST_BODY_CSTRING, postdata, postdata_len, 0);
6406 + if (SUCCESS == http_request_prepare(&request, options?Z_ARRVAL_P(options):NULL)) {
6407 + http_request_exec(&request);
6409 + http_request_info(&request, Z_ARRVAL_P(info));
6411 + RETVAL_RESPONSE_OR_BODY(request);
6413 + http_request_dtor(&request);
6417 +/* {{{ proto string http_post_fields(string url, array data[, array files[, array options[, array &info]]])
6418 + Performs an HTTP POST request on the supplied url. */
6419 +PHP_FUNCTION(http_post_fields)
6421 + zval *options = NULL, *info = NULL, *fields = NULL, *files = NULL;
6424 + http_request_body body;
6425 + http_request request;
6427 + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sa!|a!a/!z", &URL, &URL_len, &fields, &files, &options, &info) != SUCCESS) {
6431 + if (!http_request_body_fill(&body, fields ? Z_ARRVAL_P(fields) : NULL, files ? Z_ARRVAL_P(files) : NULL)) {
6442 + http_request_init_ex(&request, NULL, HTTP_POST, URL);
6443 + request.body = &body;
6444 + if (SUCCESS == http_request_prepare(&request, options?Z_ARRVAL_P(options):NULL)) {
6445 + http_request_exec(&request);
6447 + http_request_info(&request, Z_ARRVAL_P(info));
6449 + RETVAL_RESPONSE_OR_BODY(request);
6451 + http_request_dtor(&request);
6455 +/* {{{ proto string http_put_file(string url, string file[, array options[, array &info]])
6456 + Performs an HTTP PUT request on the supplied url. */
6457 +PHP_FUNCTION(http_put_file)
6460 + int URL_len, f_len;
6461 + zval *options = NULL, *info = NULL;
6462 + php_stream *stream;
6463 + php_stream_statbuf ssb;
6464 + http_request_body body;
6465 + http_request request;
6467 + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|a/!z", &URL, &URL_len, &file, &f_len, &options, &info)) {
6471 + if (!(stream = php_stream_open_wrapper_ex(file, "rb", REPORT_ERRORS|ENFORCE_SAFE_MODE, NULL, HTTP_DEFAULT_STREAM_CONTEXT))) {
6474 + if (php_stream_stat(stream, &ssb)) {
6475 + php_stream_close(stream);
6486 + http_request_init_ex(&request, NULL, HTTP_PUT, URL);
6487 + request.body = http_request_body_init_ex(&body, HTTP_REQUEST_BODY_UPLOADFILE, stream, ssb.sb.st_size, 1);
6488 + if (SUCCESS == http_request_prepare(&request, options?Z_ARRVAL_P(options):NULL)) {
6489 + http_request_exec(&request);
6491 + http_request_info(&request, Z_ARRVAL_P(info));
6493 + RETVAL_RESPONSE_OR_BODY(request);
6495 + http_request_dtor(&request);
6499 +/* {{{ proto string http_put_stream(string url, resource stream[, array options[, array &info]])
6500 + Performs an HTTP PUT request on the supplied url. */
6501 +PHP_FUNCTION(http_put_stream)
6503 + zval *resource, *options = NULL, *info = NULL;
6506 + php_stream *stream;
6507 + php_stream_statbuf ssb;
6508 + http_request_body body;
6509 + http_request request;
6511 + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sr|a/!z", &URL, &URL_len, &resource, &options, &info)) {
6515 + php_stream_from_zval(stream, &resource);
6516 + if (php_stream_stat(stream, &ssb)) {
6527 + http_request_init_ex(&request, NULL, HTTP_PUT, URL);
6528 + request.body = http_request_body_init_ex(&body, HTTP_REQUEST_BODY_UPLOADFILE, stream, ssb.sb.st_size, 0);
6529 + if (SUCCESS == http_request_prepare(&request, options?Z_ARRVAL_P(options):NULL)) {
6530 + http_request_exec(&request);
6532 + http_request_info(&request, Z_ARRVAL_P(info));
6534 + RETVAL_RESPONSE_OR_BODY(request);
6536 + http_request_dtor(&request);
6540 +/* {{{ proto string http_put_data(string url, string data[, array options[, array &info]])
6541 + Performs an HTTP PUT request on the supplied url. */
6542 +PHP_FUNCTION(http_put_data)
6545 + int URL_len, data_len;
6546 + zval *options = NULL, *info = NULL;
6547 + http_request_body body;
6548 + http_request request;
6550 + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|a/!z", &URL, &URL_len, &data, &data_len, &options, &info)) {
6561 + http_request_init_ex(&request, NULL, HTTP_PUT, URL);
6562 + request.body = http_request_body_init_ex(&body, HTTP_REQUEST_BODY_CSTRING, data, data_len, 0);
6563 + if (SUCCESS == http_request_prepare(&request, options?Z_ARRVAL_P(options):NULL)) {
6564 + http_request_exec(&request);
6566 + http_request_info(&request, Z_ARRVAL_P(info));
6568 + RETVAL_RESPONSE_OR_BODY(request);
6570 + http_request_dtor(&request);
6574 +/* {{{ proto string http_request(int method, string url[, string body[, array options[, array &info]]])
6575 + Performs a custom HTTP request on the supplied url. */
6576 +PHP_FUNCTION(http_request)
6579 + char *URL, *data = NULL;
6580 + int URL_len, data_len = 0;
6581 + zval *options = NULL, *info = NULL;
6582 + http_request_body body;
6583 + http_request request;
6585 + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ls|sa/!z", &meth, &URL, &URL_len, &data, &data_len, &options, &info)) {
6596 + http_request_init_ex(&request, NULL, meth, URL);
6597 + request.body = http_request_body_init_ex(&body, HTTP_REQUEST_BODY_CSTRING, data, data_len, 0);
6598 + if (SUCCESS == http_request_prepare(&request, options?Z_ARRVAL_P(options):NULL)) {
6599 + http_request_exec(&request);
6601 + http_request_info(&request, Z_ARRVAL_P(info));
6603 + RETVAL_RESPONSE_OR_BODY(request);
6605 + http_request_dtor(&request);
6609 +/* {{{ proto string http_request_body_encode(array fields, array files)
6610 + Generate x-www-form-urlencoded resp. form-data encoded request body. */
6611 +PHP_FUNCTION(http_request_body_encode)
6613 + zval *fields = NULL, *files = NULL;
6614 + HashTable *fields_ht, *files_ht;
6615 + http_request_body body;
6619 + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a!a!", &fields, &files)) {
6623 + fields_ht = (fields && Z_TYPE_P(fields) == IS_ARRAY) ? Z_ARRVAL_P(fields) : NULL;
6624 + files_ht = (files && Z_TYPE_P(files) == IS_ARRAY) ? Z_ARRVAL_P(files) : NULL;
6625 + if (http_request_body_fill(&body, fields_ht, files_ht) && (SUCCESS == http_request_body_encode(&body, &buf, &len))) {
6626 + RETVAL_STRINGL(buf, len, 0);
6628 + http_error(HE_WARNING, HTTP_E_RUNTIME, "Could not encode request body");
6631 + http_request_body_dtor(&body);
6633 +#endif /* HTTP_HAVE_CURL */
6634 +/* }}} HAVE_CURL */
6636 +/* {{{ proto int http_request_method_register(string method)
6637 + Register a custom request method. */
6638 +PHP_FUNCTION(http_request_method_register)
6644 + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &method, &method_len)) {
6647 + if ((existing = http_request_method_exists(1, 0, method))) {
6648 + RETURN_LONG((long) existing);
6651 + RETVAL_LONG((long) http_request_method_register(method, method_len));
6655 +/* {{{ proto bool http_request_method_unregister(mixed method)
6656 + Unregister a previously registered custom request method. */
6657 +PHP_FUNCTION(http_request_method_unregister)
6661 + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z/", &method)) {
6665 + switch (Z_TYPE_P(method)) {
6667 + convert_to_string(method);
6669 + if (is_numeric_string(Z_STRVAL_P(method), Z_STRLEN_P(method), NULL, NULL, 1)) {
6670 + convert_to_long(method);
6673 + if (!(mn = http_request_method_exists(1, 0, Z_STRVAL_P(method)))) {
6676 + zval_dtor(method);
6677 + ZVAL_LONG(method, (long)mn);
6680 + RETURN_SUCCESS(http_request_method_unregister(Z_LVAL_P(method)));
6687 +/* {{{ proto int http_request_method_exists(mixed method)
6688 + Check if a request method is registered (or available by default). */
6689 +PHP_FUNCTION(http_request_method_exists)
6691 + if (return_value_used) {
6694 + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z/", &method)) {
6698 + switch (Z_TYPE_P(method)) {
6700 + convert_to_string(method);
6702 + if (is_numeric_string(Z_STRVAL_P(method), Z_STRLEN_P(method), NULL, NULL, 1)) {
6703 + convert_to_long(method);
6705 + RETURN_LONG((long) http_request_method_exists(1, 0, Z_STRVAL_P(method)));
6708 + RETURN_LONG((long) http_request_method_exists(0, (int) Z_LVAL_P(method), NULL));
6716 +/* {{{ proto string http_request_method_name(int method)
6717 + Get the literal string representation of a standard or registered request method. */
6718 +PHP_FUNCTION(http_request_method_name)
6720 + if (return_value_used) {
6723 + if ((SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &method)) || (method < 0)) {
6727 + RETURN_STRING(estrdup(http_request_method_name((int) method)), 0);
6733 +#ifdef HTTP_HAVE_ZLIB
6735 +/* {{{ proto string http_deflate(string data[, int flags = 0])
6736 + Compress data with gzip, zlib AKA deflate or raw deflate encoding. */
6737 +PHP_FUNCTION(http_deflate)
6745 + if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &data, &data_len, &flags)) {
6747 + size_t encoded_len;
6749 + if (SUCCESS == http_encoding_deflate(flags, data, data_len, &encoded, &encoded_len)) {
6750 + RETURN_STRINGL(encoded, (int) encoded_len, 0);
6756 +/* {{{ proto string http_inflate(string data)
6757 + Decompress data compressed with either gzip, deflate AKA zlib or raw deflate encoding. */
6758 +PHP_FUNCTION(http_inflate)
6765 + if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &data, &data_len)) {
6767 + size_t decoded_len;
6769 + if (SUCCESS == http_encoding_inflate(data, data_len, &decoded, &decoded_len)) {
6770 + RETURN_STRINGL(decoded, (int) decoded_len, 0);
6776 +/* {{{ proto string ob_deflatehandler(string data, int mode)
6777 + For use with ob_start(). The deflate output buffer handler can only be used once. */
6778 +PHP_FUNCTION(ob_deflatehandler)
6784 + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sl", &data, &data_len, &mode)) {
6788 + http_ob_deflatehandler(data, data_len, &Z_STRVAL_P(return_value), (uint *) &Z_STRLEN_P(return_value), mode);
6789 + Z_TYPE_P(return_value) = Z_STRVAL_P(return_value) ? IS_STRING : IS_NULL;
6793 +/* {{{ proto string ob_inflatehandler(string data, int mode)
6794 + For use with ob_start(). Same restrictions as with ob_deflatehandler apply. */
6795 +PHP_FUNCTION(ob_inflatehandler)
6801 + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sl", &data, &data_len, &mode)) {
6805 + http_ob_inflatehandler(data, data_len, &Z_STRVAL_P(return_value), (uint *) &Z_STRLEN_P(return_value), mode);
6806 + Z_TYPE_P(return_value) = Z_STRVAL_P(return_value) ? IS_STRING : IS_NULL;
6810 +#endif /* HTTP_HAVE_ZLIB */
6813 +/* {{{ proto int http_support([int feature = 0])
6814 + Check for feature that require external libraries. */
6815 +PHP_FUNCTION(http_support)
6821 + if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &feature)) {
6822 + RETVAL_LONG(http_support(feature));
6828 + * Local variables:
6830 + * c-basic-offset: 4
6832 + * vim600: noet sw=4 ts=4 fdm=marker
6833 + * vim<600: noet sw=4 ts=4
6837 +++ b/ext/http/http_headers_api.c
6840 + +--------------------------------------------------------------------+
6842 + +--------------------------------------------------------------------+
6843 + | Redistribution and use in source and binary forms, with or without |
6844 + | modification, are permitted provided that the conditions mentioned |
6845 + | in the accompanying LICENSE file are met. |
6846 + +--------------------------------------------------------------------+
6847 + | Copyright (c) 2004-2010, Michael Wallner <mike@php.net> |
6848 + +--------------------------------------------------------------------+
6851 +/* $Id: http_headers_api.c 300300 2010-06-09 07:29:35Z mike $ */
6853 +#define HTTP_WANT_SAPI
6854 +#include "php_http.h"
6856 +#include "ext/standard/url.h"
6857 +#include "ext/standard/php_string.h"
6859 +#include "php_http_api.h"
6860 +#include "php_http_headers_api.h"
6862 +#ifndef HTTP_DBG_NEG
6863 +# define HTTP_DBG_NEG 0
6866 +/* {{{ static void http_grab_response_headers(void *, void *) */
6867 +static void http_grab_response_headers(void *data, void *arg TSRMLS_DC)
6869 + phpstr_appendl(PHPSTR(arg), ((sapi_header_struct *)data)->header);
6870 + phpstr_appends(PHPSTR(arg), HTTP_CRLF);
6874 +/* {{{ static int http_sort_q(const void *, const void *) */
6875 +static int http_sort_q(const void *a, const void *b TSRMLS_DC)
6878 + zval result, *first, *second;
6880 + f = *((Bucket **) a);
6881 + s = *((Bucket **) b);
6883 + first = *((zval **) f->pData);
6884 + second= *((zval **) s->pData);
6886 + if (numeric_compare_function(&result, first, second TSRMLS_CC) != SUCCESS) {
6889 + return (Z_LVAL(result) > 0 ? -1 : (Z_LVAL(result) < 0 ? 1 : 0));
6893 +/* {{{ char *http_negotiate_language_func */
6894 +char *_http_negotiate_language_func(const char *test, double *quality, HashTable *supported TSRMLS_DC)
6898 + const char *dash_test;
6900 + FOREACH_HASH_VAL(pos, supported, value) {
6902 + fprintf(stderr, "strcasecmp('%s', '%s')\n", Z_STRVAL_PP(value), test);
6904 + if (!strcasecmp(Z_STRVAL_PP(value), test)) {
6905 + return Z_STRVAL_PP(value);
6909 + /* no distinct match found, so try primaries */
6910 + if ((dash_test = strchr(test, '-'))) {
6911 + FOREACH_HASH_VAL(pos, supported, value) {
6912 + int len = dash_test - test;
6914 + fprintf(stderr, "strncasecmp('%s', '%s', %d)\n", Z_STRVAL_PP(value), test, len);
6916 + if ( (!strncasecmp(Z_STRVAL_PP(value), test, len)) &&
6917 + ( (Z_STRVAL_PP(value)[len] == '\0') ||
6918 + (Z_STRVAL_PP(value)[len] == '-'))) {
6920 + return Z_STRVAL_PP(value);
6929 +/* {{{ char *http_negotiate_default_func */
6930 +char *_http_negotiate_default_func(const char *test, double *quality, HashTable *supported TSRMLS_DC)
6935 + FOREACH_HASH_VAL(pos, supported, value) {
6937 + fprintf(stderr, "strcasecmp('%s', '%s')\n", Z_STRVAL_PP(value), test);
6939 + if (!strcasecmp(Z_STRVAL_PP(value), test)) {
6940 + return Z_STRVAL_PP(value);
6948 +/* {{{ HashTable *http_negotiate_z(zval *, HashTable *, negotiate_func_t) */
6949 +PHP_HTTP_API HashTable *_http_negotiate_z(zval *value, HashTable *supported, negotiate_func_t neg TSRMLS_DC)
6951 + zval *accept = http_zsep(IS_STRING, value);
6952 + HashTable *result = NULL;
6954 + if (Z_STRLEN_P(accept)) {
6955 + zval ex_arr, ex_del;
6957 + INIT_PZVAL(&ex_del);
6958 + INIT_PZVAL(&ex_arr);
6959 + ZVAL_STRINGL(&ex_del, ",", 1, 0);
6960 + array_init(&ex_arr);
6962 + php_explode(&ex_del, accept, &ex_arr, INT_MAX);
6964 + if (zend_hash_num_elements(Z_ARRVAL(ex_arr)) > 0) {
6967 + zval **entry, array;
6969 + INIT_PZVAL(&array);
6970 + array_init(&array);
6972 + FOREACH_HASH_VAL(pos, Z_ARRVAL(ex_arr), entry) {
6975 + char *selected, *identifier, *freeme;
6976 + const char *separator;
6979 + fprintf(stderr, "Checking %s\n", Z_STRVAL_PP(entry));
6982 + if ((separator = strchr(Z_STRVAL_PP(entry), ';'))) {
6983 + const char *ptr = separator;
6985 + while (*++ptr && !HTTP_IS_CTYPE(digit, *ptr) && '.' != *ptr);
6987 + quality = zend_strtod(ptr, NULL);
6988 + identifier = estrndup(Z_STRVAL_PP(entry), ident_len = separator - Z_STRVAL_PP(entry));
6990 + quality = 1000.0 - i++;
6991 + identifier = estrndup(Z_STRVAL_PP(entry), ident_len = Z_STRLEN_PP(entry));
6993 + freeme = identifier;
6995 + while (HTTP_IS_CTYPE(space, *identifier)) {
6999 + while (ident_len && HTTP_IS_CTYPE(space, identifier[ident_len - 1])) {
7000 + identifier[--ident_len] = '\0';
7003 + if ((selected = neg(identifier, &quality, supported TSRMLS_CC))) {
7004 + /* don't overwrite previously set with higher quality */
7005 + if (!zend_hash_exists(Z_ARRVAL(array), selected, strlen(selected) + 1)) {
7006 + add_assoc_double(&array, selected, quality);
7013 + result = Z_ARRVAL(array);
7014 + zend_hash_sort(result, zend_qsort, http_sort_q, 0 TSRMLS_CC);
7017 + zval_dtor(&ex_arr);
7020 + zval_ptr_dtor(&accept);
7026 +/* {{{ HashTable *http_negotiate_q(const char *, HashTable *, negotiate_func_t) */
7027 +PHP_HTTP_API HashTable *_http_negotiate_q(const char *header, HashTable *supported, negotiate_func_t neg TSRMLS_DC)
7032 + fprintf(stderr, "Reading header %s: ", header);
7034 + if (!(accept = http_get_server_var(header, 1))) {
7038 + fprintf(stderr, "%s\n", Z_STRVAL_P(accept));
7041 + return http_negotiate_z(accept, supported, neg);
7045 +/* {{{ http_range_status http_get_request_ranges(HashTable *ranges, size_t) */
7046 +PHP_HTTP_API http_range_status _http_get_request_ranges(HashTable *ranges, size_t length TSRMLS_DC)
7050 + long begin = -1, end = -1, *ptr;
7052 + if ( !(zrange = http_get_server_var("HTTP_RANGE", 1)) ||
7053 + (size_t) Z_STRLEN_P(zrange) < lenof("bytes=") || strncmp(Z_STRVAL_P(zrange), "bytes=", lenof("bytes="))) {
7056 + range = Z_STRVAL_P(zrange) + lenof("bytes=");
7060 + switch (c = *(range++)) {
7062 + /* allow 000... - shall we? */
7063 + if (*ptr != -10) {
7068 + case '1': case '2': case '3':
7069 + case '4': case '5': case '6':
7070 + case '7': case '8': case '9':
7072 + * If the value of the pointer is already set (non-negative)
7073 + * then multiply its value by ten and add the current value,
7074 + * else initialise the pointers value with the current value
7076 + * This let us recognize empty fields when validating the
7077 + * ranges, i.e. a "-10" for begin and "12345" for the end
7078 + * was the following range request: "Range: bytes=0-12345";
7079 + * While a "-1" for begin and "12345" for the end would
7080 + * have been: "Range: bytes=-12345".
7101 + /* validate ranges */
7116 + if (length <= (size_t) end) {
7126 + /* "-", "-0" or overflow */
7127 + if (end == -1 || end == -10 || length <= (size_t) end) {
7130 + begin = length - end;
7134 + /* "12345-(xxx)" */
7143 + if (length <= (size_t) begin) {
7149 + /* "12345-67890" */
7151 + if ( (length <= (size_t) begin) ||
7152 + (length <= (size_t) end) ||
7163 + MAKE_STD_ZVAL(zentry);
7164 + array_init(zentry);
7165 + add_index_long(zentry, 0, begin);
7166 + add_index_long(zentry, 1, end);
7167 + zend_hash_next_index_insert(ranges, &zentry, sizeof(zval *), NULL);
7184 +/* {{{ STATUS http_parse_headers(char *, HashTable *, zend_bool) */
7185 +PHP_HTTP_API STATUS _http_parse_headers_ex(const char *header, HashTable *headers, zend_bool prettify,
7186 + http_info_callback callback_func, void **callback_data TSRMLS_DC)
7188 + const char *colon = NULL, *line = NULL;
7191 + INIT_ZARR(array, headers);
7193 + /* skip leading ws */
7194 + while (HTTP_IS_CTYPE(space, *header)) ++header;
7197 +#define MORE_HEADERS (*(line-1) && !(*(line-1) == '\n' && (*line == '\n' || *line == '\r')))
7199 + int value_len = 0;
7201 + switch (*line++) {
7209 + --value_len; /* we don't have CR so value length is one char less */
7211 + if ((!*(line - 1)) || ((*line != ' ') && (*line != '\t'))) {
7214 + if (SUCCESS == http_info_parse(header, &i)) {
7215 + /* response/request line */
7216 + callback_func(callback_data, &headers, &i TSRMLS_CC);
7217 + http_info_dtor(&i);
7218 + Z_ARRVAL(array) = headers;
7219 + } else if (colon) {
7220 + /* "header: value" pair */
7221 + if (header != colon) {
7222 + int keylen = colon - header;
7223 + const char *key = header;
7225 + /* skip leading ws */
7226 + while (keylen && HTTP_IS_CTYPE(space, *key)) --keylen, ++key;
7227 + /* skip trailing ws */
7228 + while (keylen && HTTP_IS_CTYPE(space, key[keylen - 1])) --keylen;
7231 + zval **previous = NULL;
7233 + char *keydup = estrndup(key, keylen);
7236 + keydup = pretty_key(keydup, keylen, 1, 1);
7239 + value_len += line - colon - 1;
7241 + /* skip leading ws */
7242 + while (HTTP_IS_CTYPE(space, *(++colon))) --value_len;
7243 + /* skip trailing ws */
7244 + while (HTTP_IS_CTYPE(space, colon[value_len - 1])) --value_len;
7246 + if (value_len > 0) {
7247 + value = estrndup(colon, value_len);
7249 + value = estrdup("");
7253 + /* if we already have got such a header make an array of those */
7254 + if (SUCCESS == zend_hash_find(headers, keydup, keylen + 1, (void *) &previous)) {
7255 + /* convert to array */
7256 + if (Z_TYPE_PP(previous) != IS_ARRAY) {
7257 + convert_to_array(*previous);
7259 + add_next_index_stringl(*previous, value, value_len, 0);
7261 + add_assoc_stringl(&array, keydup, value, value_len, 0);
7265 + /* empty key (" : ...") */
7269 + /* empty key (": ...") */
7272 + } else if (MORE_HEADERS) {
7273 + /* a line without a colon */
7278 + header += line - header;
7282 + } while (MORE_HEADERS);
7288 +/* {{{ void http_get_request_headers(HashTable *) */
7289 +PHP_HTTP_API void _http_get_request_headers(HashTable *headers TSRMLS_DC)
7291 + HashKey key = initHashKey(0);
7292 + zval **hsv, **header;
7295 + if (!HTTP_G->request.headers) {
7296 + ALLOC_HASHTABLE(HTTP_G->request.headers);
7297 + zend_hash_init(HTTP_G->request.headers, 0, NULL, ZVAL_PTR_DTOR, 0);
7299 +#ifdef ZEND_ENGINE_2
7300 + zend_is_auto_global("_SERVER", lenof("_SERVER") TSRMLS_CC);
7303 + if (SUCCESS == zend_hash_find(&EG(symbol_table), "_SERVER", sizeof("_SERVER"), (void *) &hsv) && Z_TYPE_PP(hsv) == IS_ARRAY) {
7304 + FOREACH_KEY(pos, *hsv, key) {
7305 + if (key.type == HASH_KEY_IS_STRING && key.len > 6 && !strncmp(key.str, "HTTP_", 5)) {
7307 + key.str = pretty_key(estrndup(key.str + 5, key.len - 1), key.len - 1, 1, 1);
7309 + zend_hash_get_current_data_ex(Z_ARRVAL_PP(hsv), (void *) &header, &pos);
7310 + ZVAL_ADDREF(*header);
7311 + zend_hash_add(HTTP_G->request.headers, key.str, key.len, (void *) header, sizeof(zval *), NULL);
7320 + zend_hash_copy(headers, HTTP_G->request.headers, (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *));
7325 +/* {{{ STATUS http_get_response_headers(HashTable *) */
7326 +PHP_HTTP_API STATUS _http_get_response_headers(HashTable *headers_ht TSRMLS_DC)
7331 + phpstr_init(&headers);
7332 + zend_llist_apply_with_argument(&SG(sapi_headers).headers, http_grab_response_headers, &headers TSRMLS_CC);
7333 + phpstr_fix(&headers);
7335 + status = http_parse_headers_ex(PHPSTR_VAL(&headers), headers_ht, 1);
7336 + phpstr_dtor(&headers);
7342 +/* {{{ zend_bool http_match_request_header(char *, char *) */
7343 +PHP_HTTP_API zend_bool _http_match_request_header_ex(const char *header, const char *value, zend_bool match_case TSRMLS_DC)
7346 + uint name_len = strlen(header);
7347 + zend_bool result = 0;
7348 + zval **data, *zvalue;
7350 + http_get_request_headers(NULL);
7351 + name = pretty_key(estrndup(header, name_len), name_len, 1, 1);
7352 + if (SUCCESS == zend_hash_find(HTTP_G->request.headers, name, name_len+1, (void *) &data)) {
7353 + zvalue = http_zsep(IS_STRING, *data);
7354 + result = (match_case ? strcmp(Z_STRVAL_P(zvalue), value) : strcasecmp(Z_STRVAL_P(zvalue), value)) ? 0 : 1;
7355 + zval_ptr_dtor(&zvalue);
7365 + * Local variables:
7367 + * c-basic-offset: 4
7369 + * vim600: noet sw=4 ts=4 fdm=marker
7370 + * vim<600: noet sw=4 ts=4
7374 +++ b/ext/http/http_inflatestream_object.c
7377 + +--------------------------------------------------------------------+
7379 + +--------------------------------------------------------------------+
7380 + | Redistribution and use in source and binary forms, with or without |
7381 + | modification, are permitted provided that the conditions mentioned |
7382 + | in the accompanying LICENSE file are met. |
7383 + +--------------------------------------------------------------------+
7384 + | Copyright (c) 2004-2010, Michael Wallner <mike@php.net> |
7385 + +--------------------------------------------------------------------+
7388 +/* $Id: http_inflatestream_object.c 323304 2012-02-17 21:13:24Z mike $ */
7390 +#define HTTP_WANT_ZLIB
7391 +#include "php_http.h"
7393 +#if defined(ZEND_ENGINE_2) && defined(HTTP_HAVE_ZLIB)
7395 +#include "php_http_api.h"
7396 +#include "php_http_encoding_api.h"
7397 +#include "php_http_exception_object.h"
7398 +#include "php_http_inflatestream_object.h"
7400 +#define HTTP_BEGIN_ARGS(method, req_args) HTTP_BEGIN_ARGS_EX(HttpInflateStream, method, 0, req_args)
7401 +#define HTTP_EMPTY_ARGS(method) HTTP_EMPTY_ARGS_EX(HttpInflateStream, method, 0)
7402 +#define HTTP_INFLATE_ME(method, visibility) PHP_ME(HttpInflateStream, method, HTTP_ARGS(HttpInflateStream, method), visibility)
7404 +HTTP_BEGIN_ARGS(__construct, 0)
7405 + HTTP_ARG_VAL(flags, 0)
7408 +HTTP_BEGIN_ARGS(factory, 0)
7409 + HTTP_ARG_VAL(flags, 0)
7410 + HTTP_ARG_VAL(class_name, 0)
7413 +HTTP_BEGIN_ARGS(update, 1)
7414 + HTTP_ARG_VAL(data, 0)
7417 +HTTP_BEGIN_ARGS(flush, 0)
7418 + HTTP_ARG_VAL(data, 0)
7421 +HTTP_BEGIN_ARGS(finish, 0)
7422 + HTTP_ARG_VAL(data, 0)
7425 +#define THIS_CE http_inflatestream_object_ce
7426 +zend_class_entry *http_inflatestream_object_ce;
7427 +zend_function_entry http_inflatestream_object_fe[] = {
7428 + HTTP_INFLATE_ME(__construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
7429 + HTTP_INFLATE_ME(update, ZEND_ACC_PUBLIC)
7430 + HTTP_INFLATE_ME(flush, ZEND_ACC_PUBLIC)
7431 + HTTP_INFLATE_ME(finish, ZEND_ACC_PUBLIC)
7433 + HTTP_INFLATE_ME(factory, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
7435 + EMPTY_FUNCTION_ENTRY
7437 +static zend_object_handlers http_inflatestream_object_handlers;
7439 +PHP_MINIT_FUNCTION(http_inflatestream_object)
7441 + HTTP_REGISTER_CLASS_EX(HttpInflateStream, http_inflatestream_object, NULL, 0);
7442 + http_inflatestream_object_handlers.clone_obj = _http_inflatestream_object_clone_obj;
7445 + zend_declare_class_constant_long(THIS_CE, ZEND_STRS("FLUSH_NONE")-1, HTTP_ENCODING_STREAM_FLUSH_NONE TSRMLS_CC);
7446 + zend_declare_class_constant_long(THIS_CE, ZEND_STRS("FLUSH_SYNC")-1, HTTP_ENCODING_STREAM_FLUSH_SYNC TSRMLS_CC);
7447 + zend_declare_class_constant_long(THIS_CE, ZEND_STRS("FLUSH_FULL")-1, HTTP_ENCODING_STREAM_FLUSH_FULL TSRMLS_CC);
7453 +zend_object_value _http_inflatestream_object_new(zend_class_entry *ce TSRMLS_DC)
7455 + return http_inflatestream_object_new_ex(ce, NULL, NULL);
7458 +zend_object_value _http_inflatestream_object_new_ex(zend_class_entry *ce, http_encoding_stream *s, http_inflatestream_object **ptr TSRMLS_DC)
7460 + zend_object_value ov;
7461 + http_inflatestream_object *o;
7463 + o = ecalloc(1, sizeof(http_inflatestream_object));
7474 +#ifdef ZEND_ENGINE_2_4
7475 + zend_object_std_init(o, ce TSRMLS_CC);
7476 + object_properties_init(o, ce);
7478 + ALLOC_HASHTABLE(OBJ_PROP(o));
7479 + zend_hash_init(OBJ_PROP(o), zend_hash_num_elements(&ce->default_properties), NULL, ZVAL_PTR_DTOR, 0);
7480 + zend_hash_copy(OBJ_PROP(o), &ce->default_properties, (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *));
7483 + ov.handle = putObject(http_inflatestream_object, o);
7484 + ov.handlers = &http_inflatestream_object_handlers;
7489 +zend_object_value _http_inflatestream_object_clone_obj(zval *this_ptr TSRMLS_DC)
7491 + http_encoding_stream *s;
7492 + zend_object_value new_ov;
7493 + http_inflatestream_object *new_obj = NULL;
7494 + getObject(http_inflatestream_object, old_obj);
7496 + s = ecalloc(1, sizeof(http_encoding_stream));
7497 + s->flags = old_obj->stream->flags;
7498 + inflateCopy(&s->stream, &old_obj->stream->stream);
7499 + s->stream.opaque = phpstr_dup(s->stream.opaque);
7501 + new_ov = http_inflatestream_object_new_ex(old_obj->zo.ce, s, &new_obj);
7502 + zend_objects_clone_members(&new_obj->zo, new_ov, &old_obj->zo, Z_OBJ_HANDLE_P(this_ptr) TSRMLS_CC);
7507 +void _http_inflatestream_object_free(zend_object *object TSRMLS_DC)
7509 + http_inflatestream_object *o = (http_inflatestream_object *) object;
7512 + http_encoding_inflate_stream_free(&o->stream);
7517 +/* {{{ proto void HttpInflateStream::__construct([int flags = 0])
7518 + Creates a new HttpInflateStream object instance. */
7519 +PHP_METHOD(HttpInflateStream, __construct)
7523 + SET_EH_THROW_HTTP();
7524 + if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &flags)) {
7525 + getObject(http_inflatestream_object, obj);
7527 + if (!obj->stream) {
7528 + obj->stream = http_encoding_inflate_stream_init(NULL, flags & 0x0fffffff);
7530 + http_error_ex(HE_WARNING, HTTP_E_ENCODING, "HttpInflateStream cannot be initialized twice");
7537 +/* {{{ proto HttpInflateStream HttpInflateStream::factory([int flags[, string class = "HttpInflateStream"]])
7538 + Creates a new HttpInflateStream object instance. */
7539 +PHP_METHOD(HttpInflateStream, factory)
7545 + SET_EH_THROW_HTTP();
7546 + if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|ls", &flags, &cn, &cl)) {
7547 + zend_object_value ov;
7548 + http_encoding_stream *s = http_encoding_inflate_stream_init(NULL, flags & 0x0fffffff);
7550 + if (SUCCESS == http_object_new(&ov, cn, cl, _http_inflatestream_object_new_ex, http_inflatestream_object_ce, s, NULL)) {
7551 + RETVAL_OBJVAL(ov, 0);
7558 +/* {{{ proto string HttpInflateStream::update(string data)
7559 + Passes more data through the inflate stream. */
7560 +PHP_METHOD(HttpInflateStream, update)
7563 + size_t decoded_len = 0;
7564 + char *data, *decoded = NULL;
7565 + getObject(http_inflatestream_object, obj);
7567 + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &data, &data_len)) {
7572 + RETURN_STRING("", 1);
7575 + if (!obj->stream && !(obj->stream = http_encoding_inflate_stream_init(NULL, 0))) {
7579 + if (SUCCESS == http_encoding_inflate_stream_update(obj->stream, data, data_len, &decoded, &decoded_len)) {
7580 + RETURN_STRINGL(decoded, decoded_len, 0);
7587 +/* {{{ proto string HttpInflateStream::flush([string data])
7588 + Flush the inflate stream. */
7589 +PHP_METHOD(HttpInflateStream, flush)
7592 + size_t decoded_len = 0;
7593 + char *decoded = NULL, *data = NULL;
7594 + getObject(http_inflatestream_object, obj);
7596 + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &data, &data_len)) {
7600 + if (!obj->stream && !(obj->stream = http_encoding_inflate_stream_init(NULL, 0))) {
7604 + /* flushing the inflate stream is a no-op */
7606 + RETURN_STRINGL("", 0, 1);
7607 + } else if (SUCCESS == http_encoding_inflate_stream_update(obj->stream, data, data_len, &decoded, &decoded_len)) {
7608 + RETURN_STRINGL(decoded, decoded_len, 0);
7615 +/* {{{ proto string HttpInflateStream::finish([string data])
7616 + Finalizes the inflate stream. The inflate stream can be reused after finalizing. */
7617 +PHP_METHOD(HttpInflateStream, finish)
7620 + size_t updated_len = 0, decoded_len = 0;
7621 + char *updated = NULL, *decoded = NULL, *data = NULL;
7622 + getObject(http_inflatestream_object, obj);
7624 + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &data, &data_len)) {
7628 + if (!obj->stream && !(obj->stream = http_encoding_inflate_stream_init(NULL, 0))) {
7633 + if (SUCCESS != http_encoding_inflate_stream_update(obj->stream, data, data_len, &updated, &updated_len)) {
7638 + if (SUCCESS == http_encoding_inflate_stream_finish(obj->stream, &decoded, &decoded_len)) {
7639 + if (updated_len) {
7640 + updated = erealloc(updated, updated_len + decoded_len + 1);
7641 + updated[updated_len + decoded_len] = '\0';
7642 + memcpy(updated + updated_len, decoded, decoded_len);
7643 + STR_FREE(decoded);
7644 + updated_len += decoded_len;
7645 + RETVAL_STRINGL(updated, updated_len, 0);
7646 + } else if (decoded) {
7647 + STR_FREE(updated);
7648 + RETVAL_STRINGL(decoded, decoded_len, 0);
7653 + STR_FREE(updated);
7657 + http_encoding_inflate_stream_dtor(obj->stream);
7658 + http_encoding_inflate_stream_init(obj->stream, obj->stream->flags);
7662 +#endif /* ZEND_ENGINE_2 && HTTP_HAVE_ZLIB*/
7665 + * Local variables:
7667 + * c-basic-offset: 4
7669 + * vim600: noet sw=4 ts=4 fdm=marker
7670 + * vim<600: noet sw=4 ts=4
7674 +++ b/ext/http/http_info_api.c
7677 + +--------------------------------------------------------------------+
7679 + +--------------------------------------------------------------------+
7680 + | Redistribution and use in source and binary forms, with or without |
7681 + | modification, are permitted provided that the conditions mentioned |
7682 + | in the accompanying LICENSE file are met. |
7683 + +--------------------------------------------------------------------+
7684 + | Copyright (c) 2004-2010, Michael Wallner <mike@php.net> |
7685 + +--------------------------------------------------------------------+
7688 +/* $Id: http_info_api.c 304921 2010-10-26 15:27:36Z iliaa $ */
7690 +#include "php_http.h"
7692 +#include "php_http_api.h"
7693 +#include "php_http_info_api.h"
7695 +PHP_HTTP_API void _http_info_default_callback(void **nothing, HashTable **headers, http_info *info TSRMLS_DC)
7699 + INIT_ZARR(array, *headers);
7701 + switch (info->type) {
7702 + case IS_HTTP_REQUEST:
7703 + add_assoc_string(&array, "Request Method", HTTP_INFO(info).request.method, 1);
7704 + add_assoc_string(&array, "Request Url", HTTP_INFO(info).request.url, 1);
7707 + case IS_HTTP_RESPONSE:
7708 + add_assoc_long(&array, "Response Code", (long) HTTP_INFO(info).response.code);
7709 + if (HTTP_INFO(info).response.status) {
7710 + add_assoc_string(&array, "Response Status", HTTP_INFO(info).response.status, 1);
7716 +PHP_HTTP_API void _http_info_dtor(http_info *i)
7718 + switch (i->type) {
7719 + case IS_HTTP_REQUEST:
7720 + STR_SET(HTTP_INFO(i).request.method, NULL);
7721 + STR_SET(HTTP_INFO(i).request.url, NULL);
7724 + case IS_HTTP_RESPONSE:
7725 + STR_SET(HTTP_INFO(i).response.status, NULL);
7733 +PHP_HTTP_API STATUS _http_info_parse_ex(const char *pre_header, http_info *info, zend_bool silent TSRMLS_DC)
7735 + const char *end, *http;
7737 + /* sane parameter */
7738 + if ((!pre_header) || (!*pre_header)) {
7742 + /* where's the end of the line */
7743 + if (!(end = http_locate_eol(pre_header, NULL))) {
7744 + end = pre_header + strlen(pre_header);
7747 + /* there must be HTTP/1.x in the line */
7748 + if (!(http = http_locate_str(pre_header, end - pre_header, "HTTP/1.", lenof("HTTP/1.")))) {
7752 + /* and nothing than SPACE or NUL after HTTP/1.x */
7753 + if ( (!HTTP_IS_CTYPE(digit, http[lenof("HTTP/1.")])) ||
7754 + (http[lenof("HTTP/1.1")] && (!HTTP_IS_CTYPE(space, http[lenof("HTTP/1.1")])))) {
7756 + http_error(HE_WARNING, HTTP_E_MALFORMED_HEADERS, "Invalid HTTP/1.x protocol identification");
7763 + char *line = estrndup(pre_header, end - pre_header);
7764 + fprintf(stderr, "http_parse_info('%s')\n", line);
7769 + info->http.version = zend_strtod(http + lenof("HTTP/"), NULL);
7772 + if (pre_header == http) {
7773 + char *status = NULL;
7774 + const char *code = http + sizeof("HTTP/1.1");
7776 + info->type = IS_HTTP_RESPONSE;
7777 + while (' ' == *code) ++code;
7778 + if (code && end > code) {
7779 + HTTP_INFO(info).response.code = strtol(code, &status, 10);
7781 + HTTP_INFO(info).response.code = 0;
7783 + if (status && end > status) {
7784 + while (' ' == *status) ++status;
7785 + HTTP_INFO(info).response.status = estrndup(status, end - status);
7787 + HTTP_INFO(info).response.status = NULL;
7794 + else if (!http[lenof("HTTP/1.x")] || http[lenof("HTTP/1.x")] == '\r' || http[lenof("HTTP/1.x")] == '\n') {
7795 + const char *url = strchr(pre_header, ' ');
7797 + info->type = IS_HTTP_REQUEST;
7798 + if (url && http > url) {
7799 + HTTP_INFO(info).request.method = estrndup(pre_header, url - pre_header);
7800 + while (' ' == *url) ++url;
7801 + while (' ' == *(http-1)) --http;
7803 + HTTP_INFO(info).request.url = estrndup(url, http - url);
7805 + efree(HTTP_INFO(info).request.method);
7809 + HTTP_INFO(info).request.method = NULL;
7810 + HTTP_INFO(info).request.url = NULL;
7816 + /* some darn header containing HTTP/1.x */
7823 + * Local variables:
7825 + * c-basic-offset: 4
7827 + * vim600: noet sw=4 ts=4 fdm=marker
7828 + * vim<600: noet sw=4 ts=4
7832 +++ b/ext/http/http_message_api.c
7835 + +--------------------------------------------------------------------+
7837 + +--------------------------------------------------------------------+
7838 + | Redistribution and use in source and binary forms, with or without |
7839 + | modification, are permitted provided that the conditions mentioned |
7840 + | in the accompanying LICENSE file are met. |
7841 + +--------------------------------------------------------------------+
7842 + | Copyright (c) 2004-2010, Michael Wallner <mike@php.net> |
7843 + +--------------------------------------------------------------------+
7846 +/* $Id: http_message_api.c 323304 2012-02-17 21:13:24Z mike $ */
7848 +#define HTTP_WANT_SAPI
7849 +#define HTTP_WANT_CURL
7850 +#define HTTP_WANT_ZLIB
7851 +#include "php_http.h"
7853 +#include "php_http_api.h"
7854 +#include "php_http_encoding_api.h"
7855 +#include "php_http_headers_api.h"
7856 +#include "php_http_message_api.h"
7857 +#include "php_http_request_api.h"
7858 +#include "php_http_send_api.h"
7859 +#include "php_http_url_api.h"
7861 +#define http_message_info_callback _http_message_info_callback
7862 +static void _http_message_info_callback(http_message **message, HashTable **headers, http_info *info TSRMLS_DC)
7864 + http_message *old = *message;
7866 + /* advance message */
7867 + if (old->type || zend_hash_num_elements(&old->hdrs) || PHPSTR_LEN(old)) {
7868 + (*message) = http_message_new();
7869 + (*message)->parent = old;
7870 + (*headers) = &((*message)->hdrs);
7873 + http_message_set_info(*message, info);
7876 +#define http_message_init_type _http_message_init_type
7877 +static inline void _http_message_init_type(http_message *message, http_message_type type)
7879 + message->http.version = .0;
7881 + switch (message->type = type) {
7882 + case HTTP_MSG_RESPONSE:
7883 + message->http.info.response.code = 0;
7884 + message->http.info.response.status = NULL;
7887 + case HTTP_MSG_REQUEST:
7888 + message->http.info.request.method = NULL;
7889 + message->http.info.request.url = NULL;
7892 + case HTTP_MSG_NONE:
7898 +PHP_HTTP_API http_message *_http_message_init_ex(http_message *message, http_message_type type ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC)
7901 + message = ecalloc_rel(1, sizeof(http_message));
7904 + http_message_init_type(message, type);
7905 + message->parent = NULL;
7906 + phpstr_init(&message->body);
7907 + zend_hash_init(&message->hdrs, 0, NULL, ZVAL_PTR_DTOR, 0);
7912 +PHP_HTTP_API http_message *_http_message_init_env(http_message *message, http_message_type type TSRMLS_DC ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC)
7920 + if ((free_msg = !message)) {
7921 + message = http_message_init_rel(NULL, HTTP_MSG_NONE);
7924 + memset(&inf, 0, sizeof(http_info));
7925 + switch (inf.type = type) {
7926 + case HTTP_MSG_REQUEST:
7927 + if ((sval = http_get_server_var("SERVER_PROTOCOL", 1)) && !strncmp(Z_STRVAL_P(sval), "HTTP/", lenof("HTTP/"))) {
7928 + inf.http.version = zend_strtod(Z_STRVAL_P(sval) + lenof("HTTP/"), NULL);
7930 + inf.http.version = 1.1;
7932 + if ((sval = http_get_server_var("REQUEST_METHOD", 1))) {
7933 + inf.http.info.request.method = estrdup(Z_STRVAL_P(sval));
7935 + if ((sval = http_get_server_var("REQUEST_URI", 1))) {
7936 + inf.http.info.request.url = estrdup(Z_STRVAL_P(sval));
7939 + http_message_set_info(message, &inf);
7940 + http_get_request_headers(&message->hdrs);
7941 + if (SUCCESS == http_get_request_body_ex(&body_str, &body_len, 0)) {
7942 + phpstr_from_string_ex(&message->body, body_str, body_len);
7946 + case HTTP_MSG_RESPONSE:
7947 + if (!SG(sapi_headers).http_status_line || SUCCESS != http_info_parse_ex(SG(sapi_headers).http_status_line, &inf, 0)) {
7948 + inf.http.version = 1.1;
7949 + inf.http.info.response.code = 200;
7950 + inf.http.info.response.status = estrdup("Ok");
7953 + http_message_set_info(message, &inf);
7954 + http_get_response_headers(&message->hdrs);
7955 +#ifdef PHP_OUTPUT_NEWAPI
7956 + if (SUCCESS == php_output_get_contents(&tval TSRMLS_CC)) {
7958 + if (SUCCESS == php_ob_get_buffer(&tval TSRMLS_CC)) {
7960 + message->body.data = Z_STRVAL(tval);
7961 + message->body.used = Z_STRLEN(tval);
7962 + message->body.free = 1; /* "\0" */
7968 + http_message_free(&message);
7974 + http_info_dtor(&inf);
7979 +PHP_HTTP_API void _http_message_set_type(http_message *message, http_message_type type)
7981 + /* just act if different */
7982 + if (type != message->type) {
7984 + /* free request info */
7985 + switch (message->type) {
7986 + case HTTP_MSG_REQUEST:
7987 + STR_FREE(message->http.info.request.method);
7988 + STR_FREE(message->http.info.request.url);
7991 + case HTTP_MSG_RESPONSE:
7992 + STR_FREE(message->http.info.response.status);
8000 + http_message_init_type(message, type);
8004 +PHP_HTTP_API void _http_message_set_info(http_message *message, http_info *info)
8006 + http_message_set_type(message, info->type);
8007 + message->http.version = info->http.version;
8008 + switch (message->type) {
8009 + case IS_HTTP_REQUEST:
8010 + STR_SET(HTTP_INFO(message).request.url, HTTP_INFO(info).request.url ? estrdup(HTTP_INFO(info).request.url) : NULL);
8011 + STR_SET(HTTP_INFO(message).request.method, HTTP_INFO(info).request.method ? estrdup(HTTP_INFO(info).request.method) : NULL);
8014 + case IS_HTTP_RESPONSE:
8015 + HTTP_INFO(message).response.code = HTTP_INFO(info).response.code;
8016 + STR_SET(HTTP_INFO(message).response.status, HTTP_INFO(info).response.status ? estrdup(HTTP_INFO(info).response.status) : NULL);
8024 +#define http_message_body_parse(m, ms, ml, c) _http_message_body_parse((m), (ms), (ml), (c) TSRMLS_CC)
8025 +static inline void _http_message_body_parse(http_message *msg, const char *message, size_t message_length, const char **continue_at TSRMLS_DC)
8031 + *continue_at = NULL;
8032 + if ((body = http_locate_body(message))) {
8033 + remaining = message + message_length - body;
8035 + if ((c = http_message_header(msg, "Transfer-Encoding"))) {
8036 + if (strstr(Z_STRVAL_P(c), "chunked")) {
8037 + /* message has chunked transfer encoding */
8039 + size_t decoded_len;
8041 + /* decode and replace Transfer-Encoding with Content-Length header */
8042 + if ((*continue_at = http_encoding_dechunk(body, message + message_length - body, &decoded, &decoded_len))) {
8047 + tmp_len = (int) spprintf(&tmp, 0, "%zu", decoded_len);
8048 + MAKE_STD_ZVAL(len);
8049 + ZVAL_STRINGL(len, tmp, tmp_len, 0);
8052 + zend_hash_update(&msg->hdrs, "X-Original-Transfer-Encoding", sizeof("X-Original-Transfer-Encoding"), (void *) &c, sizeof(zval *), NULL);
8053 + zend_hash_del(&msg->hdrs, "Transfer-Encoding", sizeof("Transfer-Encoding"));
8054 + zend_hash_del(&msg->hdrs, "Content-Length", sizeof("Content-Length"));
8055 + zend_hash_update(&msg->hdrs, "Content-Length", sizeof("Content-Length"), (void *) &len, sizeof(zval *), NULL);
8057 + phpstr_from_string_ex(PHPSTR(msg), decoded, decoded_len);
8061 + zval_ptr_dtor(&c);
8064 + if (!*continue_at && (c = http_message_header(msg, "Content-Length"))) {
8065 + /* message has content-length header */
8066 + ulong len = strtoul(Z_STRVAL_P(c), NULL, 10);
8067 + if (len > remaining) {
8068 + http_error_ex(HE_NOTICE, HTTP_E_MALFORMED_HEADERS, "The Content-Length header pretends a larger body than actually received (expected %lu bytes; got %lu bytes)", len, remaining);
8071 + phpstr_from_string_ex(PHPSTR(msg), body, len);
8072 + *continue_at = body + len;
8073 + zval_ptr_dtor(&c);
8076 + if (!*continue_at && (c = http_message_header(msg, "Content-Range"))) {
8077 + /* message has content-range header */
8078 + ulong total = 0, start = 0, end = 0, len = 0;
8080 + if (!strncasecmp(Z_STRVAL_P(c), "bytes", lenof("bytes")) &&
8081 + ( Z_STRVAL_P(c)[lenof("bytes")] == ':' ||
8082 + Z_STRVAL_P(c)[lenof("bytes")] == ' ' ||
8083 + Z_STRVAL_P(c)[lenof("bytes")] == '=')) {
8084 + char *total_at = NULL, *end_at = NULL;
8085 + char *start_at = Z_STRVAL_P(c) + sizeof("bytes");
8087 + start = strtoul(start_at, &end_at, 10);
8089 + end = strtoul(end_at + 1, &total_at, 10);
8090 + if (total_at && strncmp(total_at + 1, "*", 1)) {
8091 + total = strtoul(total_at + 1, NULL, 10);
8093 + if ((len = (end + 1 - start)) > remaining) {
8094 + http_error_ex(HE_NOTICE, HTTP_E_MALFORMED_HEADERS, "The Content-Range header pretends a larger body than actually received (expected %lu bytes; got %lu bytes)", len, remaining);
8097 + if (end >= start && (!total || end < total)) {
8098 + phpstr_from_string_ex(PHPSTR(msg), body, len);
8099 + *continue_at = body + len;
8104 + if (!*continue_at) {
8105 + http_error_ex(HE_WARNING, HTTP_E_MALFORMED_HEADERS, "Invalid Content-Range header: %s", Z_STRVAL_P(c));
8107 + zval_ptr_dtor(&c);
8110 + if (!*continue_at) {
8111 + /* no headers that indicate content length */
8112 + if (HTTP_MSG_TYPE(RESPONSE, msg)) {
8113 + phpstr_from_string_ex(PHPSTR(msg), body, remaining);
8115 + *continue_at = body;
8119 +#ifdef HTTP_HAVE_ZLIB
8120 + /* check for compressed data */
8121 + if ((c = http_message_header(msg, "Content-Encoding"))) {
8122 + char *decoded = NULL;
8123 + size_t decoded_len = 0;
8125 + if ( !strcasecmp(Z_STRVAL_P(c), "gzip") ||
8126 + !strcasecmp(Z_STRVAL_P(c), "x-gzip") ||
8127 + !strcasecmp(Z_STRVAL_P(c), "deflate")) {
8128 + http_encoding_inflate(PHPSTR_VAL(msg), PHPSTR_LEN(msg), &decoded, &decoded_len);
8132 + zval *len, **original_len;
8136 + tmp_len = (int) spprintf(&tmp, 0, "%zu", decoded_len);
8137 + MAKE_STD_ZVAL(len);
8138 + ZVAL_STRINGL(len, tmp, tmp_len, 0);
8141 + zend_hash_update(&msg->hdrs, "X-Original-Content-Encoding", sizeof("X-Original-Content-Encoding"), (void *) &c, sizeof(zval *), NULL);
8142 + zend_hash_del(&msg->hdrs, "Content-Encoding", sizeof("Content-Encoding"));
8143 + if (SUCCESS == zend_hash_find(&msg->hdrs, "Content-Length", sizeof("Content-Length"), (void *) &original_len)) {
8144 + ZVAL_ADDREF(*original_len);
8145 + zend_hash_update(&msg->hdrs, "X-Original-Content-Length", sizeof("X-Original-Content-Length"), (void *) original_len, sizeof(zval *), NULL);
8146 + zend_hash_update(&msg->hdrs, "Content-Length", sizeof("Content-Length"), (void *) &len, sizeof(zval *), NULL);
8148 + zend_hash_update(&msg->hdrs, "Content-Length", sizeof("Content-Length"), (void *) &len, sizeof(zval *), NULL);
8151 + phpstr_dtor(PHPSTR(msg));
8152 + PHPSTR(msg)->data = decoded;
8153 + PHPSTR(msg)->used = decoded_len;
8154 + PHPSTR(msg)->free = 1;
8157 + zval_ptr_dtor(&c);
8159 +#endif /* HTTP_HAVE_ZLIB */
8163 +PHP_HTTP_API http_message *_http_message_parse_ex(http_message *msg, const char *message, size_t message_length ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC TSRMLS_DC)
8165 + const char *continue_at;
8166 + zend_bool free_msg = msg ? 0 : 1;
8168 + if ((!message) || (message_length < HTTP_MSG_MIN_SIZE)) {
8169 + http_error_ex(HE_WARNING, HTTP_E_INVALID_PARAM, "Empty or too short HTTP message: '%s'", message);
8173 + msg = http_message_init_rel(msg, 0);
8175 + if (SUCCESS != http_parse_headers_cb(message, &msg->hdrs, 1, (http_info_callback) http_message_info_callback, (void *) &msg)) {
8177 + http_message_free(&msg);
8179 + http_error(HE_WARNING, HTTP_E_MALFORMED_HEADERS, "Failed to parse message headers");
8183 + http_message_body_parse(msg, message, message_length, &continue_at);
8185 + /* check for following messages */
8186 + if (continue_at && (continue_at < (message + message_length))) {
8187 + while (HTTP_IS_CTYPE(space, *continue_at)) ++continue_at;
8188 + if (continue_at < (message + message_length)) {
8189 + http_message *next = NULL, *most = NULL;
8191 + /* set current message to parent of most parent following messages and return deepest */
8192 + if ((most = next = http_message_parse_rel(NULL, continue_at, message + message_length - continue_at))) {
8193 + while (most->parent) most = most->parent;
8194 + most->parent = msg;
8203 +PHP_HTTP_API void _http_message_tostring(http_message *msg, char **string, size_t *length)
8206 + HashKey key = initHashKey(0);
8209 + HashPosition pos1;
8211 + phpstr_init_ex(&str, 4096, 0);
8213 + switch (msg->type) {
8214 + case HTTP_MSG_REQUEST:
8215 + phpstr_appendf(&str, HTTP_INFO_REQUEST_FMT_ARGS(&msg->http, HTTP_CRLF));
8218 + case HTTP_MSG_RESPONSE:
8219 + phpstr_appendf(&str, HTTP_INFO_RESPONSE_FMT_ARGS(&msg->http, HTTP_CRLF));
8222 + case HTTP_MSG_NONE:
8227 + FOREACH_HASH_KEYVAL(pos1, &msg->hdrs, key, header) {
8228 + if (key.type == HASH_KEY_IS_STRING) {
8229 + HashPosition pos2;
8230 + zval **single_header;
8232 + switch (Z_TYPE_PP(header)) {
8234 + phpstr_appendf(&str, "%s: %s" HTTP_CRLF, key.str, Z_BVAL_PP(header)?"true":"false");
8238 + phpstr_appendf(&str, "%s: %ld" HTTP_CRLF, key.str, Z_LVAL_PP(header));
8242 + phpstr_appendf(&str, "%s: %f" HTTP_CRLF, key.str, Z_DVAL_PP(header));
8246 + phpstr_appendf(&str, "%s: %s" HTTP_CRLF, key.str, Z_STRVAL_PP(header));
8250 + FOREACH_VAL(pos2, *header, single_header) {
8251 + switch (Z_TYPE_PP(single_header)) {
8253 + phpstr_appendf(&str, "%s: %s" HTTP_CRLF, key.str, Z_BVAL_PP(single_header)?"true":"false");
8257 + phpstr_appendf(&str, "%s: %ld" HTTP_CRLF, key.str, Z_LVAL_PP(single_header));
8261 + phpstr_appendf(&str, "%s: %f" HTTP_CRLF, key.str, Z_DVAL_PP(single_header));
8265 + phpstr_appendf(&str, "%s: %s" HTTP_CRLF, key.str, Z_STRVAL_PP(single_header));
8274 + if (PHPSTR_LEN(msg)) {
8275 + phpstr_appends(&str, HTTP_CRLF);
8276 + phpstr_append(&str, PHPSTR_VAL(msg), PHPSTR_LEN(msg));
8277 + phpstr_appends(&str, HTTP_CRLF);
8280 + data = phpstr_data(&str, string, length);
8285 + phpstr_dtor(&str);
8288 +PHP_HTTP_API void _http_message_serialize(http_message *message, char **string, size_t *length)
8294 + phpstr_init(&str);
8297 + http_message_tostring(message, &buf, &len);
8298 + phpstr_prepend(&str, buf, len);
8300 + } while ((message = message->parent));
8302 + buf = phpstr_data(&str, string, length);
8307 + phpstr_dtor(&str);
8310 +PHP_HTTP_API http_message *_http_message_reverse(http_message *msg)
8314 + http_message_count(c, msg);
8317 + http_message *tmp = msg, **arr = ecalloc(c, sizeof(http_message *));
8319 + for (i = 0; i < c; ++i) {
8321 + tmp = tmp->parent;
8323 + arr[0]->parent = NULL;
8324 + for (i = 0; i < c-1; ++i) {
8325 + arr[i+1]->parent = arr[i];
8335 +PHP_HTTP_API http_message *_http_message_interconnect(http_message *m1, http_message *m2)
8338 + int i = 0, c1, c2;
8339 + http_message *t1 = m1, *t2 = m2, *p1, *p2;
8341 + http_message_count(c1, m1);
8342 + http_message_count(c2, m2);
8344 + while (i++ < (c1 - c2)) {
8347 + while (i++ <= c1) {
8355 + } else if (!m1 && m2) {
8361 +PHP_HTTP_API void _http_message_tostruct_recursive(http_message *msg, zval *obj TSRMLS_DC)
8366 + INIT_ZARR(strct, HASH_OF(obj));
8368 + add_assoc_long(&strct, "type", msg->type);
8369 + add_assoc_double(&strct, "httpVersion", msg->http.version);
8370 + switch (msg->type)
8372 + case HTTP_MSG_RESPONSE:
8373 + add_assoc_long(&strct, "responseCode", msg->http.info.response.code);
8374 + add_assoc_string(&strct, "responseStatus", STR_PTR(msg->http.info.response.status), 1);
8377 + case HTTP_MSG_REQUEST:
8378 + add_assoc_string(&strct, "requestMethod", STR_PTR(msg->http.info.request.method), 1);
8379 + add_assoc_string(&strct, "requestUrl", STR_PTR(msg->http.info.request.url), 1);
8382 + case HTTP_MSG_NONE:
8383 + /* avoid compiler warning */
8387 + MAKE_STD_ZVAL(headers);
8388 + array_init(headers);
8389 + zend_hash_copy(Z_ARRVAL_P(headers), &msg->hdrs, (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *));
8390 + add_assoc_zval(&strct, "headers", headers);
8392 + add_assoc_stringl(&strct, "body", PHPSTR_VAL(msg), PHPSTR_LEN(msg), 1);
8394 + if (msg->parent) {
8397 + MAKE_STD_ZVAL(parent);
8398 + if (Z_TYPE_P(obj) == IS_ARRAY) {
8399 + array_init(parent);
8401 + object_init(parent);
8403 + add_assoc_zval(&strct, "parentMessage", parent);
8404 + http_message_tostruct_recursive(msg->parent, parent);
8406 + add_assoc_null(&strct, "parentMessage");
8410 +PHP_HTTP_API STATUS _http_message_send(http_message *message TSRMLS_DC)
8412 + STATUS rs = FAILURE;
8414 + switch (message->type) {
8415 + case HTTP_MSG_RESPONSE:
8417 + HashKey key = initHashKey(0);
8421 + FOREACH_HASH_KEYVAL(pos, &message->hdrs, key, val) {
8422 + if (key.type == HASH_KEY_IS_STRING) {
8423 + http_send_header_zval_ex(key.str, key.len-1, val, 1);
8426 + rs = SUCCESS == http_send_status(message->http.info.response.code) &&
8427 + SUCCESS == http_send_data(PHPSTR_VAL(message), PHPSTR_LEN(message)) ?
8428 + SUCCESS : FAILURE;
8432 + case HTTP_MSG_REQUEST:
8434 +#ifdef HTTP_HAVE_CURL
8436 + http_request request;
8437 + zval **zhost, *options, *headers;
8439 + MAKE_STD_ZVAL(options);
8440 + MAKE_STD_ZVAL(headers);
8441 + array_init(options);
8442 + array_init(headers);
8443 + zend_hash_copy(Z_ARRVAL_P(headers), &message->hdrs, (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *));
8444 + add_assoc_zval(options, "headers", headers);
8446 + /* check host header */
8447 + if (SUCCESS == zend_hash_find(&message->hdrs, "Host", sizeof("Host"), (void *) &zhost) && Z_TYPE_PP(zhost) == IS_STRING) {
8448 + char *colon = NULL;
8449 + php_url parts, *url = php_url_parse(message->http.info.request.url);
8451 + memset(&parts, 0, sizeof(php_url));
8453 + /* check for port */
8454 + if ((colon = strchr(Z_STRVAL_PP(zhost), ':'))) {
8455 + parts.port = atoi(colon + 1);
8456 + parts.host = estrndup(Z_STRVAL_PP(zhost), (Z_STRVAL_PP(zhost) - colon - 1));
8458 + parts.host = estrndup(Z_STRVAL_PP(zhost), Z_STRLEN_PP(zhost));
8461 + http_build_url(HTTP_URL_REPLACE, url, &parts, NULL, &uri, NULL);
8462 + php_url_free(url);
8463 + efree(parts.host);
8465 + uri = http_absolute_url(message->http.info.request.url);
8468 + if ((request.meth = http_request_method_exists(1, 0, message->http.info.request.method))) {
8469 + http_request_body body;
8471 + http_request_init_ex(&request, NULL, request.meth, uri);
8472 + request.body = http_request_body_init_ex(&body, HTTP_REQUEST_BODY_CSTRING, PHPSTR_VAL(message), PHPSTR_LEN(message), 0);
8473 + if (SUCCESS == (rs = http_request_prepare(&request, Z_ARRVAL_P(options)))) {
8474 + http_request_exec(&request);
8476 + http_request_dtor(&request);
8478 + http_error_ex(HE_WARNING, HTTP_E_REQUEST_METHOD,
8479 + "Cannot send HttpMessage. Request method %s not supported",
8480 + message->http.info.request.method);
8483 + zval_ptr_dtor(&options);
8485 + http_error(HE_WARNING, HTTP_E_RUNTIME, "HTTP requests not supported - ext/http was not linked against libcurl.");
8490 + case HTTP_MSG_NONE:
8492 + http_error(HE_WARNING, HTTP_E_MESSAGE_TYPE, "HttpMessage is neither of type HTTP_MSG_REQUEST nor HTTP_MSG_RESPONSE");
8499 +PHP_HTTP_API http_message *_http_message_dup(http_message *orig TSRMLS_DC)
8501 + http_message *temp, *copy = NULL;
8505 + info.type = orig->type;
8506 + info.http = orig->http;
8508 + copy = temp = http_message_new();
8509 + http_message_set_info(temp, &info);
8510 + zend_hash_copy(&temp->hdrs, &orig->hdrs, (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *));
8511 + phpstr_append(&temp->body, orig->body.data, orig->body.used);
8513 + while (orig->parent) {
8514 + info.type = orig->parent->type;
8515 + info.http = orig->parent->http;
8517 + temp->parent = http_message_new();
8518 + http_message_set_info(temp->parent, &info);
8519 + zend_hash_copy(&temp->parent->hdrs, &orig->parent->hdrs, (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *));
8520 + phpstr_append(&temp->parent->body, orig->parent->body.data, orig->parent->body.used);
8522 + temp = temp->parent;
8523 + orig = orig->parent;
8530 +PHP_HTTP_API void _http_message_dtor(http_message *message)
8533 + zend_hash_destroy(&message->hdrs);
8534 + phpstr_dtor(PHPSTR(message));
8536 + switch (message->type) {
8537 + case HTTP_MSG_REQUEST:
8538 + STR_SET(message->http.info.request.method, NULL);
8539 + STR_SET(message->http.info.request.url, NULL);
8542 + case HTTP_MSG_RESPONSE:
8543 + STR_SET(message->http.info.response.status, NULL);
8552 +PHP_HTTP_API void _http_message_free(http_message **message)
8555 + if ((*message)->parent) {
8556 + http_message_free(&(*message)->parent);
8558 + http_message_dtor(*message);
8565 + * Local variables:
8567 + * c-basic-offset: 4
8569 + * vim600: noet sw=4 ts=4 fdm=marker
8570 + * vim<600: noet sw=4 ts=4
8574 +++ b/ext/http/http_message_object.c
8577 + +--------------------------------------------------------------------+
8579 + +--------------------------------------------------------------------+
8580 + | Redistribution and use in source and binary forms, with or without |
8581 + | modification, are permitted provided that the conditions mentioned |
8582 + | in the accompanying LICENSE file are met. |
8583 + +--------------------------------------------------------------------+
8584 + | Copyright (c) 2004-2010, Michael Wallner <mike@php.net> |
8585 + +--------------------------------------------------------------------+
8588 +/* $Id: http_message_object.c 323304 2012-02-17 21:13:24Z mike $ */
8590 +#define HTTP_WANT_SAPI
8591 +#define HTTP_WANT_CURL
8592 +#define HTTP_WANT_MAGIC
8593 +#include "php_http.h"
8595 +#ifdef ZEND_ENGINE_2
8597 +#include "zend_interfaces.h"
8598 +#include "ext/standard/url.h"
8599 +#include "php_variables.h"
8601 +#include "php_http_api.h"
8602 +#include "php_http_send_api.h"
8603 +#include "php_http_url_api.h"
8604 +#include "php_http_message_api.h"
8605 +#include "php_http_message_object.h"
8606 +#include "php_http_exception_object.h"
8607 +#include "php_http_response_object.h"
8608 +#include "php_http_request_method_api.h"
8609 +#include "php_http_request_api.h"
8610 +#include "php_http_request_object.h"
8611 +#include "php_http_headers_api.h"
8613 +#if defined(HTTP_HAVE_SPL) && !defined(WONKY)
8614 +/* SPL doesn't install its headers */
8615 +extern PHPAPI zend_class_entry *spl_ce_Countable;
8618 +#define HTTP_BEGIN_ARGS(method, req_args) HTTP_BEGIN_ARGS_EX(HttpMessage, method, 0, req_args)
8619 +#define HTTP_EMPTY_ARGS(method) HTTP_EMPTY_ARGS_EX(HttpMessage, method, 0)
8620 +#define HTTP_MESSAGE_ME(method, visibility) PHP_ME(HttpMessage, method, HTTP_ARGS(HttpMessage, method), visibility)
8622 +HTTP_BEGIN_ARGS(__construct, 0)
8623 + HTTP_ARG_VAL(message, 0)
8626 +HTTP_BEGIN_ARGS(factory, 0)
8627 + HTTP_ARG_VAL(message, 0)
8628 + HTTP_ARG_VAL(class_name, 0)
8631 +HTTP_BEGIN_ARGS(fromEnv, 1)
8632 + HTTP_ARG_VAL(type, 0)
8633 + HTTP_ARG_VAL(class_name, 0)
8636 +HTTP_EMPTY_ARGS(getBody);
8637 +HTTP_BEGIN_ARGS(setBody, 1)
8638 + HTTP_ARG_VAL(body, 0)
8641 +HTTP_BEGIN_ARGS(getHeader, 1)
8642 + HTTP_ARG_VAL(header, 0)
8645 +HTTP_EMPTY_ARGS(getHeaders);
8646 +HTTP_BEGIN_ARGS(setHeaders, 1)
8647 + HTTP_ARG_VAL(headers, 0)
8650 +HTTP_BEGIN_ARGS(addHeaders, 1)
8651 + HTTP_ARG_VAL(headers, 0)
8652 + HTTP_ARG_VAL(append, 0)
8655 +HTTP_EMPTY_ARGS(getType);
8656 +HTTP_BEGIN_ARGS(setType, 1)
8657 + HTTP_ARG_VAL(type, 0)
8660 +HTTP_EMPTY_ARGS(getInfo);
8661 +HTTP_BEGIN_ARGS(setInfo, 1)
8662 + HTTP_ARG_VAL(http_info, 0)
8665 +HTTP_EMPTY_ARGS(getResponseCode);
8666 +HTTP_BEGIN_ARGS(setResponseCode, 1)
8667 + HTTP_ARG_VAL(response_code, 0)
8670 +HTTP_EMPTY_ARGS(getResponseStatus);
8671 +HTTP_BEGIN_ARGS(setResponseStatus, 1)
8672 + HTTP_ARG_VAL(response_status, 0)
8675 +HTTP_EMPTY_ARGS(getRequestMethod);
8676 +HTTP_BEGIN_ARGS(setRequestMethod, 1)
8677 + HTTP_ARG_VAL(request_method, 0)
8680 +HTTP_EMPTY_ARGS(getRequestUrl);
8681 +HTTP_BEGIN_ARGS(setRequestUrl, 1)
8682 + HTTP_ARG_VAL(url, 0)
8685 +HTTP_EMPTY_ARGS(getHttpVersion);
8686 +HTTP_BEGIN_ARGS(setHttpVersion, 1)
8687 + HTTP_ARG_VAL(http_version, 0)
8690 +HTTP_BEGIN_ARGS(guessContentType, 1)
8691 + HTTP_ARG_VAL(magic_file, 0)
8692 + HTTP_ARG_VAL(magic_mode, 0)
8695 +HTTP_EMPTY_ARGS(getParentMessage);
8696 +HTTP_EMPTY_ARGS(send);
8697 +HTTP_EMPTY_ARGS(__toString);
8698 +HTTP_BEGIN_ARGS(toString, 0)
8699 + HTTP_ARG_VAL(include_parent, 0)
8702 +HTTP_EMPTY_ARGS(toMessageTypeObject);
8704 +HTTP_EMPTY_ARGS(count);
8706 +HTTP_EMPTY_ARGS(serialize);
8707 +HTTP_BEGIN_ARGS(unserialize, 1)
8708 + HTTP_ARG_VAL(serialized, 0)
8711 +HTTP_EMPTY_ARGS(rewind);
8712 +HTTP_EMPTY_ARGS(valid);
8713 +HTTP_EMPTY_ARGS(key);
8714 +HTTP_EMPTY_ARGS(current);
8715 +HTTP_EMPTY_ARGS(next);
8717 +HTTP_EMPTY_ARGS(detach);
8718 +HTTP_BEGIN_ARGS(prepend, 1)
8719 + HTTP_ARG_OBJ(HttpMessage, message, 0)
8721 +HTTP_EMPTY_ARGS(reverse);
8723 +#define http_message_object_read_prop _http_message_object_read_prop
8724 +static zval *_http_message_object_read_prop(zval *object, zval *member, int type ZEND_LITERAL_KEY_DC TSRMLS_DC);
8725 +#define http_message_object_write_prop _http_message_object_write_prop
8726 +static void _http_message_object_write_prop(zval *object, zval *member, zval *value ZEND_LITERAL_KEY_DC TSRMLS_DC);
8727 +#define http_message_object_get_prop_ptr _http_message_object_get_prop_ptr
8728 +static zval **_http_message_object_get_prop_ptr(zval *object, zval *member ZEND_LITERAL_KEY_DC TSRMLS_DC);
8729 +#define http_message_object_get_props _http_message_object_get_props
8730 +static HashTable *_http_message_object_get_props(zval *object TSRMLS_DC);
8732 +#define THIS_CE http_message_object_ce
8733 +zend_class_entry *http_message_object_ce;
8734 +zend_function_entry http_message_object_fe[] = {
8735 + HTTP_MESSAGE_ME(__construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
8736 + HTTP_MESSAGE_ME(getBody, ZEND_ACC_PUBLIC)
8737 + HTTP_MESSAGE_ME(setBody, ZEND_ACC_PUBLIC)
8738 + HTTP_MESSAGE_ME(getHeader, ZEND_ACC_PUBLIC)
8739 + HTTP_MESSAGE_ME(getHeaders, ZEND_ACC_PUBLIC)
8740 + HTTP_MESSAGE_ME(setHeaders, ZEND_ACC_PUBLIC)
8741 + HTTP_MESSAGE_ME(addHeaders, ZEND_ACC_PUBLIC)
8742 + HTTP_MESSAGE_ME(getType, ZEND_ACC_PUBLIC)
8743 + HTTP_MESSAGE_ME(setType, ZEND_ACC_PUBLIC)
8744 + HTTP_MESSAGE_ME(getInfo, ZEND_ACC_PUBLIC)
8745 + HTTP_MESSAGE_ME(setInfo, ZEND_ACC_PUBLIC)
8746 + HTTP_MESSAGE_ME(getResponseCode, ZEND_ACC_PUBLIC)
8747 + HTTP_MESSAGE_ME(setResponseCode, ZEND_ACC_PUBLIC)
8748 + HTTP_MESSAGE_ME(getResponseStatus, ZEND_ACC_PUBLIC)
8749 + HTTP_MESSAGE_ME(setResponseStatus, ZEND_ACC_PUBLIC)
8750 + HTTP_MESSAGE_ME(getRequestMethod, ZEND_ACC_PUBLIC)
8751 + HTTP_MESSAGE_ME(setRequestMethod, ZEND_ACC_PUBLIC)
8752 + HTTP_MESSAGE_ME(getRequestUrl, ZEND_ACC_PUBLIC)
8753 + HTTP_MESSAGE_ME(setRequestUrl, ZEND_ACC_PUBLIC)
8754 + HTTP_MESSAGE_ME(getHttpVersion, ZEND_ACC_PUBLIC)
8755 + HTTP_MESSAGE_ME(setHttpVersion, ZEND_ACC_PUBLIC)
8756 + HTTP_MESSAGE_ME(guessContentType, ZEND_ACC_PUBLIC)
8757 + HTTP_MESSAGE_ME(getParentMessage, ZEND_ACC_PUBLIC)
8758 + HTTP_MESSAGE_ME(send, ZEND_ACC_PUBLIC)
8759 + HTTP_MESSAGE_ME(toString, ZEND_ACC_PUBLIC)
8760 + HTTP_MESSAGE_ME(toMessageTypeObject, ZEND_ACC_PUBLIC)
8762 + /* implements Countable */
8763 + HTTP_MESSAGE_ME(count, ZEND_ACC_PUBLIC)
8765 + /* implements Serializable */
8766 + HTTP_MESSAGE_ME(serialize, ZEND_ACC_PUBLIC)
8767 + HTTP_MESSAGE_ME(unserialize, ZEND_ACC_PUBLIC)
8769 + /* implements Iterator */
8770 + HTTP_MESSAGE_ME(rewind, ZEND_ACC_PUBLIC)
8771 + HTTP_MESSAGE_ME(valid, ZEND_ACC_PUBLIC)
8772 + HTTP_MESSAGE_ME(current, ZEND_ACC_PUBLIC)
8773 + HTTP_MESSAGE_ME(key, ZEND_ACC_PUBLIC)
8774 + HTTP_MESSAGE_ME(next, ZEND_ACC_PUBLIC)
8776 + ZEND_MALIAS(HttpMessage, __toString, toString, HTTP_ARGS(HttpMessage, __toString), ZEND_ACC_PUBLIC)
8778 + HTTP_MESSAGE_ME(factory, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
8779 + ZEND_MALIAS(HttpMessage, fromString, factory, HTTP_ARGS(HttpMessage, factory), ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
8780 + HTTP_MESSAGE_ME(fromEnv, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
8782 + HTTP_MESSAGE_ME(detach, ZEND_ACC_PUBLIC)
8783 + HTTP_MESSAGE_ME(prepend, ZEND_ACC_PUBLIC)
8784 + HTTP_MESSAGE_ME(reverse, ZEND_ACC_PUBLIC)
8786 + EMPTY_FUNCTION_ENTRY
8788 +static zend_object_handlers http_message_object_handlers;
8790 +static HashTable http_message_object_prophandlers;
8792 +typedef void (*http_message_object_prophandler_func)(http_message_object *o, zval *v TSRMLS_DC);
8794 +typedef struct _http_message_object_prophandler {
8795 + http_message_object_prophandler_func read;
8796 + http_message_object_prophandler_func write;
8797 +} http_message_object_prophandler;
8799 +static STATUS http_message_object_add_prophandler(const char *prop_str, size_t prop_len, http_message_object_prophandler_func read, http_message_object_prophandler_func write) {
8800 + http_message_object_prophandler h = { read, write };
8801 + return zend_hash_add(&http_message_object_prophandlers, prop_str, prop_len, (void *) &h, sizeof(h), NULL);
8803 +static STATUS http_message_object_get_prophandler(const char *prop_str, size_t prop_len, http_message_object_prophandler **handler) {
8804 + return zend_hash_find(&http_message_object_prophandlers, prop_str, prop_len, (void *) handler);
8806 +static void http_message_object_prophandler_get_type(http_message_object *obj, zval *return_value TSRMLS_DC) {
8807 + RETVAL_LONG(obj->message->type);
8809 +static void http_message_object_prophandler_set_type(http_message_object *obj, zval *value TSRMLS_DC) {
8810 + zval *cpy = http_zsep(IS_LONG, value);
8811 + http_message_set_type(obj->message, Z_LVAL_P(cpy));
8812 + zval_ptr_dtor(&cpy);
8814 +static void http_message_object_prophandler_get_body(http_message_object *obj, zval *return_value TSRMLS_DC) {
8815 + phpstr_fix(PHPSTR(obj->message));
8816 + RETVAL_PHPSTR(PHPSTR(obj->message), 0, 1);
8818 +static void http_message_object_prophandler_set_body(http_message_object *obj, zval *value TSRMLS_DC) {
8819 + zval *cpy = http_zsep(IS_STRING, value);
8820 + phpstr_dtor(PHPSTR(obj->message));
8821 + phpstr_from_string_ex(PHPSTR(obj->message), Z_STRVAL_P(cpy), Z_STRLEN_P(cpy));
8822 + zval_ptr_dtor(&cpy);
8824 +static void http_message_object_prophandler_get_request_method(http_message_object *obj, zval *return_value TSRMLS_DC) {
8825 + if (HTTP_MSG_TYPE(REQUEST, obj->message) && obj->message->http.info.request.method) {
8826 + RETVAL_STRING(obj->message->http.info.request.method, 1);
8831 +static void http_message_object_prophandler_set_request_method(http_message_object *obj, zval *value TSRMLS_DC) {
8832 + if (HTTP_MSG_TYPE(REQUEST, obj->message)) {
8833 + zval *cpy = http_zsep(IS_STRING, value);
8834 + STR_SET(obj->message->http.info.request.method, estrndup(Z_STRVAL_P(cpy), Z_STRLEN_P(cpy)));
8835 + zval_ptr_dtor(&cpy);
8838 +static void http_message_object_prophandler_get_request_url(http_message_object *obj, zval *return_value TSRMLS_DC) {
8839 + if (HTTP_MSG_TYPE(REQUEST, obj->message) && obj->message->http.info.request.url) {
8840 + RETVAL_STRING(obj->message->http.info.request.url, 1);
8845 +static void http_message_object_prophandler_set_request_url(http_message_object *obj, zval *value TSRMLS_DC) {
8846 + if (HTTP_MSG_TYPE(REQUEST, obj->message)) {
8847 + zval *cpy = http_zsep(IS_STRING, value);
8848 + STR_SET(obj->message->http.info.request.url, estrndup(Z_STRVAL_P(cpy), Z_STRLEN_P(cpy)));
8849 + zval_ptr_dtor(&cpy);
8852 +static void http_message_object_prophandler_get_response_status(http_message_object *obj, zval *return_value TSRMLS_DC) {
8853 + if (HTTP_MSG_TYPE(RESPONSE, obj->message) && obj->message->http.info.response.status) {
8854 + RETVAL_STRING(obj->message->http.info.response.status, 1);
8859 +static void http_message_object_prophandler_set_response_status(http_message_object *obj, zval *value TSRMLS_DC) {
8860 + if (HTTP_MSG_TYPE(RESPONSE, obj->message)) {
8861 + zval *cpy = http_zsep(IS_STRING, value);
8862 + STR_SET(obj->message->http.info.response.status, estrndup(Z_STRVAL_P(cpy), Z_STRLEN_P(cpy)));
8863 + zval_ptr_dtor(&cpy);
8866 +static void http_message_object_prophandler_get_response_code(http_message_object *obj, zval *return_value TSRMLS_DC) {
8867 + if (HTTP_MSG_TYPE(RESPONSE, obj->message)) {
8868 + RETVAL_LONG(obj->message->http.info.response.code);
8873 +static void http_message_object_prophandler_set_response_code(http_message_object *obj, zval *value TSRMLS_DC) {
8874 + if (HTTP_MSG_TYPE(RESPONSE, obj->message)) {
8875 + zval *cpy = http_zsep(IS_LONG, value);
8876 + obj->message->http.info.response.code = Z_LVAL_P(cpy);
8877 + zval_ptr_dtor(&cpy);
8880 +static void http_message_object_prophandler_get_http_version(http_message_object *obj, zval *return_value TSRMLS_DC) {
8881 + RETVAL_DOUBLE(obj->message->http.version);
8883 +static void http_message_object_prophandler_set_http_version(http_message_object *obj, zval *value TSRMLS_DC) {
8884 + zval *cpy = http_zsep(IS_DOUBLE, value);
8885 + obj->message->http.version = Z_DVAL_P(cpy);
8886 + zval_ptr_dtor(&cpy);
8888 +static void http_message_object_prophandler_get_headers(http_message_object *obj, zval *return_value TSRMLS_DC) {
8889 + array_init(return_value);
8890 + zend_hash_copy(Z_ARRVAL_P(return_value), &obj->message->hdrs, (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *));
8892 +static void http_message_object_prophandler_set_headers(http_message_object *obj, zval *value TSRMLS_DC) {
8893 + zval *cpy = http_zsep(IS_ARRAY, value);
8894 + zend_hash_clean(&obj->message->hdrs);
8895 + zend_hash_copy(&obj->message->hdrs, Z_ARRVAL_P(cpy), (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *));
8896 + zval_ptr_dtor(&cpy);
8898 +static void http_message_object_prophandler_get_parent_message(http_message_object *obj, zval *return_value TSRMLS_DC) {
8899 + if (obj->message->parent) {
8900 + RETVAL_OBJVAL(obj->parent, 1);
8905 +static void http_message_object_prophandler_set_parent_message(http_message_object *obj, zval *value TSRMLS_DC) {
8906 + if (Z_TYPE_P(value) == IS_OBJECT && instanceof_function(Z_OBJCE_P(value), http_message_object_ce TSRMLS_CC)) {
8907 + if (obj->message->parent) {
8909 + tmp.value.obj = obj->parent;
8910 + Z_OBJ_DELREF(tmp);
8912 + Z_OBJ_ADDREF_P(value);
8913 + obj->parent = value->value.obj;
8917 +PHP_MINIT_FUNCTION(http_message_object)
8919 + HTTP_REGISTER_CLASS_EX(HttpMessage, http_message_object, NULL, 0);
8922 +# ifdef HTTP_HAVE_SPL
8923 + zend_class_implements(http_message_object_ce TSRMLS_CC, 3, spl_ce_Countable, zend_ce_serializable, zend_ce_iterator);
8925 + zend_class_implements(http_message_object_ce TSRMLS_CC, 2, zend_ce_serializable, zend_ce_iterator);
8928 + zend_class_implements(http_message_object_ce TSRMLS_CC, 1, zend_ce_iterator);
8931 + http_message_object_handlers.clone_obj = _http_message_object_clone_obj;
8932 + http_message_object_handlers.read_property = http_message_object_read_prop;
8933 + http_message_object_handlers.write_property = http_message_object_write_prop;
8934 + http_message_object_handlers.get_properties = http_message_object_get_props;
8935 + http_message_object_handlers.get_property_ptr_ptr = http_message_object_get_prop_ptr;
8937 + zend_hash_init(&http_message_object_prophandlers, 9, NULL, NULL, 1);
8938 + zend_declare_property_long(THIS_CE, ZEND_STRS("type")-1, HTTP_MSG_NONE, ZEND_ACC_PROTECTED TSRMLS_CC);
8939 + http_message_object_add_prophandler(ZEND_STRS("type")-1, http_message_object_prophandler_get_type, http_message_object_prophandler_set_type);
8940 + zend_declare_property_string(THIS_CE, ZEND_STRS("body")-1, "", ZEND_ACC_PROTECTED TSRMLS_CC);
8941 + http_message_object_add_prophandler(ZEND_STRS("body")-1, http_message_object_prophandler_get_body, http_message_object_prophandler_set_body);
8942 + zend_declare_property_string(THIS_CE, ZEND_STRS("requestMethod")-1, "", ZEND_ACC_PROTECTED TSRMLS_CC);
8943 + http_message_object_add_prophandler(ZEND_STRS("requestMethod")-1, http_message_object_prophandler_get_request_method, http_message_object_prophandler_set_request_method);
8944 + zend_declare_property_string(THIS_CE, ZEND_STRS("requestUrl")-1, "", ZEND_ACC_PROTECTED TSRMLS_CC);
8945 + http_message_object_add_prophandler(ZEND_STRS("requestUrl")-1, http_message_object_prophandler_get_request_url, http_message_object_prophandler_set_request_url);
8946 + zend_declare_property_string(THIS_CE, ZEND_STRS("responseStatus")-1, "", ZEND_ACC_PROTECTED TSRMLS_CC);
8947 + http_message_object_add_prophandler(ZEND_STRS("responseStatus")-1, http_message_object_prophandler_get_response_status, http_message_object_prophandler_set_response_status);
8948 + zend_declare_property_long(THIS_CE, ZEND_STRS("responseCode")-1, 0, ZEND_ACC_PROTECTED TSRMLS_CC);
8949 + http_message_object_add_prophandler(ZEND_STRS("responseCode")-1, http_message_object_prophandler_get_response_code, http_message_object_prophandler_set_response_code);
8950 + zend_declare_property_null(THIS_CE, ZEND_STRS("httpVersion")-1, ZEND_ACC_PROTECTED TSRMLS_CC);
8951 + http_message_object_add_prophandler(ZEND_STRS("httpVersion")-1, http_message_object_prophandler_get_http_version, http_message_object_prophandler_set_http_version);
8952 + zend_declare_property_null(THIS_CE, ZEND_STRS("headers")-1, ZEND_ACC_PROTECTED TSRMLS_CC);
8953 + http_message_object_add_prophandler(ZEND_STRS("headers")-1, http_message_object_prophandler_get_headers, http_message_object_prophandler_set_headers);
8954 + zend_declare_property_null(THIS_CE, ZEND_STRS("parentMessage")-1, ZEND_ACC_PROTECTED TSRMLS_CC);
8955 + http_message_object_add_prophandler(ZEND_STRS("parentMessage")-1, http_message_object_prophandler_get_parent_message, http_message_object_prophandler_set_parent_message);
8958 + zend_declare_class_constant_long(THIS_CE, ZEND_STRS("TYPE_NONE")-1, HTTP_MSG_NONE TSRMLS_CC);
8959 + zend_declare_class_constant_long(THIS_CE, ZEND_STRS("TYPE_REQUEST")-1, HTTP_MSG_REQUEST TSRMLS_CC);
8960 + zend_declare_class_constant_long(THIS_CE, ZEND_STRS("TYPE_RESPONSE")-1, HTTP_MSG_RESPONSE TSRMLS_CC);
8963 + HTTP_LONG_CONSTANT("HTTP_MSG_NONE", HTTP_MSG_NONE);
8964 + HTTP_LONG_CONSTANT("HTTP_MSG_REQUEST", HTTP_MSG_REQUEST);
8965 + HTTP_LONG_CONSTANT("HTTP_MSG_RESPONSE", HTTP_MSG_RESPONSE);
8970 +PHP_MSHUTDOWN_FUNCTION(http_message_object)
8972 + zend_hash_destroy(&http_message_object_prophandlers);
8977 +void _http_message_object_reverse(zval *this_ptr, zval *return_value TSRMLS_DC)
8980 + getObject(http_message_object, obj);
8983 + http_message_count(i, obj->message);
8987 + zend_object_value *ovalues = NULL;
8988 + http_message_object **objects = NULL;
8991 + objects = ecalloc(i, sizeof(http_message_object *));
8992 + ovalues = ecalloc(i, sizeof(zend_object_value));
8994 + /* we are the first message */
8996 + ovalues[0] = getThis()->value.obj;
8998 + /* fetch parents */
9000 + o.type = IS_OBJECT;
9001 + for (i = 1; obj->parent.handle; ++i) {
9002 + o.value.obj = obj->parent;
9003 + ovalues[i] = o.value.obj;
9004 + objects[i] = obj = zend_object_store_get_object(&o TSRMLS_CC);
9007 + /* reorder parents */
9008 + for (last = --i; i; --i) {
9009 + objects[i]->message->parent = objects[i-1]->message;
9010 + objects[i]->parent = ovalues[i-1];
9012 + objects[0]->message->parent = NULL;
9013 + objects[0]->parent.handle = 0;
9014 + objects[0]->parent.handlers = NULL;
9016 + /* add ref (why?) */
9017 + Z_OBJ_ADDREF_P(getThis());
9018 + RETVAL_OBJVAL(ovalues[last], 1);
9023 + RETURN_ZVAL(getThis(), 1, 0);
9027 +void _http_message_object_prepend_ex(zval *this_ptr, zval *prepend, zend_bool top TSRMLS_DC)
9030 + http_message *save_parent_msg = NULL;
9031 + zend_object_value save_parent_obj = {0, NULL};
9032 + getObject(http_message_object, obj);
9033 + getObjectEx(http_message_object, prepend_obj, prepend);
9036 + m.type = IS_OBJECT;
9039 + save_parent_obj = obj->parent;
9040 + save_parent_msg = obj->message->parent;
9042 + /* iterate to the most parent object */
9043 + while (obj->parent.handle) {
9044 + m.value.obj = obj->parent;
9045 + obj = zend_object_store_get_object(&m TSRMLS_CC);
9050 + obj->parent = prepend->value.obj;
9051 + obj->message->parent = prepend_obj->message;
9054 + zend_objects_store_add_ref(prepend TSRMLS_CC);
9055 + while (prepend_obj->parent.handle) {
9056 + m.value.obj = prepend_obj->parent;
9057 + zend_objects_store_add_ref(&m TSRMLS_CC);
9058 + prepend_obj = zend_object_store_get_object(&m TSRMLS_CC);
9062 + prepend_obj->parent = save_parent_obj;
9063 + prepend_obj->message->parent = save_parent_msg;
9067 +zend_object_value _http_message_object_new(zend_class_entry *ce TSRMLS_DC)
9069 + return http_message_object_new_ex(ce, NULL, NULL);
9072 +zend_object_value _http_message_object_new_ex(zend_class_entry *ce, http_message *msg, http_message_object **ptr TSRMLS_DC)
9074 + zend_object_value ov;
9075 + http_message_object *o;
9077 + o = ecalloc(1, sizeof(http_message_object));
9086 + if (msg->parent) {
9087 + o->parent = http_message_object_new_ex(ce, msg->parent, NULL);
9092 +#ifdef ZEND_ENGINE_2_4
9093 + zend_object_std_init(o, ce TSRMLS_CC);
9094 + object_properties_init(o, ce);
9096 + ALLOC_HASHTABLE(OBJ_PROP(o));
9097 + zend_hash_init(OBJ_PROP(o), zend_hash_num_elements(&ce->default_properties), NULL, ZVAL_PTR_DTOR, 0);
9098 + zend_hash_copy(OBJ_PROP(o), &ce->default_properties, (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *));
9101 + ov.handle = putObject(http_message_object, o);
9102 + ov.handlers = &http_message_object_handlers;
9107 +zend_object_value _http_message_object_clone_obj(zval *this_ptr TSRMLS_DC)
9109 + zend_object_value new_ov;
9110 + http_message_object *new_obj = NULL;
9111 + getObject(http_message_object, old_obj);
9113 + new_ov = http_message_object_new_ex(old_obj->zo.ce, http_message_dup(old_obj->message), &new_obj);
9114 + zend_objects_clone_members(&new_obj->zo, new_ov, &old_obj->zo, Z_OBJ_HANDLE_P(this_ptr) TSRMLS_CC);
9119 +void _http_message_object_free(zend_object *object TSRMLS_DC)
9121 + http_message_object *o = (http_message_object *) object;
9123 + if (o->iterator) {
9124 + zval_ptr_dtor(&o->iterator);
9125 + o->iterator = NULL;
9128 + http_message_dtor(o->message);
9129 + efree(o->message);
9131 + if (o->parent.handle) {
9135 + p.type = IS_OBJECT;
9136 + p.value.obj = o->parent;
9137 + zend_objects_store_del_ref(&p TSRMLS_CC);
9142 +static zval **_http_message_object_get_prop_ptr(zval *object, zval *member ZEND_LITERAL_KEY_DC TSRMLS_DC) {
9143 + getObjectEx(http_message_object, obj, object);
9144 + http_message_object_prophandler *handler;
9146 + if (SUCCESS == http_message_object_get_prophandler(Z_STRVAL_P(member), Z_STRLEN_P(member), &handler)) {
9147 + zend_error(E_ERROR, "Cannot access HttpMessage properties by reference or array key/index");
9151 + return zend_get_std_object_handlers()->get_property_ptr_ptr(object, member ZEND_LITERAL_KEY_CC TSRMLS_CC);
9154 +static zval *_http_message_object_read_prop(zval *object, zval *member, int type ZEND_LITERAL_KEY_DC TSRMLS_DC)
9156 + getObjectEx(http_message_object, obj, object);
9157 + http_message_object_prophandler *handler;
9158 + zval *return_value;
9160 + if (SUCCESS == http_message_object_get_prophandler(Z_STRVAL_P(member), Z_STRLEN_P(member), &handler)) {
9161 + if (type == BP_VAR_W) {
9162 + zend_error(E_ERROR, "Cannot access HttpMessage properties by reference or array key/index");
9166 + ALLOC_ZVAL(return_value);
9167 +#ifdef Z_SET_REFCOUNT
9168 + Z_SET_REFCOUNT_P(return_value, 0);
9169 + Z_UNSET_ISREF_P(return_value);
9171 + return_value->refcount = 0;
9172 + return_value->is_ref = 0;
9175 + handler->read(obj, return_value TSRMLS_CC);
9178 + return_value = zend_get_std_object_handlers()->read_property(object, member, type ZEND_LITERAL_KEY_CC TSRMLS_CC);
9181 + return return_value;
9184 +static void _http_message_object_write_prop(zval *object, zval *member, zval *value ZEND_LITERAL_KEY_DC TSRMLS_DC)
9186 + getObjectEx(http_message_object, obj, object);
9187 + http_message_object_prophandler *handler;
9189 + if (SUCCESS == http_message_object_get_prophandler(Z_STRVAL_P(member), Z_STRLEN_P(member), &handler)) {
9190 + handler->write(obj, value TSRMLS_CC);
9192 + zend_get_std_object_handlers()->write_property(object, member, value ZEND_LITERAL_KEY_CC TSRMLS_CC);
9196 +static HashTable *_http_message_object_get_props(zval *object TSRMLS_DC)
9199 + getObjectEx(http_message_object, obj, object);
9200 + http_message *msg = obj->message;
9201 + zval array, *parent;
9202 +#ifdef ZEND_ENGINE_2_4
9203 + HashTable *props = zend_get_std_object_handlers()->get_properties(object TSRMLS_CC);
9205 + HashTable *props = OBJ_PROP(obj);
9207 + INIT_ZARR(array, props);
9209 +#define ASSOC_PROP(array, ptype, name, val) \
9211 + char *m_prop_name; \
9213 + zend_mangle_property_name(&m_prop_name, &m_prop_len, "*", 1, name, lenof(name), 0); \
9214 + add_assoc_ ##ptype## _ex(&array, m_prop_name, sizeof(name)+3, val); \
9215 + efree(m_prop_name); \
9217 +#define ASSOC_STRING(array, name, val) ASSOC_STRINGL(array, name, val, strlen(val))
9218 +#define ASSOC_STRINGL(array, name, val, len) \
9220 + char *m_prop_name; \
9222 + zend_mangle_property_name(&m_prop_name, &m_prop_len, "*", 1, name, lenof(name), 0); \
9223 + add_assoc_stringl_ex(&array, m_prop_name, sizeof(name)+3, val, len, 1); \
9224 + efree(m_prop_name); \
9227 + ASSOC_PROP(array, long, "type", msg->type);
9228 + ASSOC_PROP(array, double, "httpVersion", msg->http.version);
9230 + switch (msg->type) {
9231 + case HTTP_MSG_REQUEST:
9232 + ASSOC_PROP(array, long, "responseCode", 0);
9233 + ASSOC_STRINGL(array, "responseStatus", "", 0);
9234 + ASSOC_STRING(array, "requestMethod", STR_PTR(msg->http.info.request.method));
9235 + ASSOC_STRING(array, "requestUrl", STR_PTR(msg->http.info.request.url));
9238 + case HTTP_MSG_RESPONSE:
9239 + ASSOC_PROP(array, long, "responseCode", msg->http.info.response.code);
9240 + ASSOC_STRING(array, "responseStatus", STR_PTR(msg->http.info.response.status));
9241 + ASSOC_STRINGL(array, "requestMethod", "", 0);
9242 + ASSOC_STRINGL(array, "requestUrl", "", 0);
9245 + case HTTP_MSG_NONE:
9247 + ASSOC_PROP(array, long, "responseCode", 0);
9248 + ASSOC_STRINGL(array, "responseStatus", "", 0);
9249 + ASSOC_STRINGL(array, "requestMethod", "", 0);
9250 + ASSOC_STRINGL(array, "requestUrl", "", 0);
9254 + MAKE_STD_ZVAL(headers);
9255 + array_init(headers);
9256 + zend_hash_copy(Z_ARRVAL_P(headers), &msg->hdrs, (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *));
9257 + ASSOC_PROP(array, zval, "headers", headers);
9258 + ASSOC_STRINGL(array, "body", PHPSTR_VAL(msg), PHPSTR_LEN(msg));
9260 + MAKE_STD_ZVAL(parent);
9261 + if (msg->parent) {
9262 + ZVAL_OBJVAL(parent, obj->parent, 1);
9264 + ZVAL_NULL(parent);
9266 + ASSOC_PROP(array, zval, "parentMessage", parent);
9271 +/* ### USERLAND ### */
9273 +/* {{{ proto void HttpMessage::__construct([string message])
9274 + Create a new HttpMessage object instance. */
9275 +PHP_METHOD(HttpMessage, __construct)
9278 + char *message = NULL;
9280 + getObject(http_message_object, obj);
9282 + SET_EH_THROW_HTTP();
9283 + if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &message, &length) && message && length) {
9284 + http_message *msg = obj->message;
9286 + http_message_dtor(msg);
9287 + if ((obj->message = http_message_parse_ex(msg, message, length))) {
9288 + if (obj->message->parent) {
9289 + obj->parent = http_message_object_new_ex(Z_OBJCE_P(getThis()), obj->message->parent, NULL);
9292 + obj->message = http_message_init(msg);
9295 + if (!obj->message) {
9296 + obj->message = http_message_new();
9302 +/* {{{ proto static HttpMessage HttpMessage::factory([string raw_message[, string class_name = "HttpMessage"]])
9303 + Create a new HttpMessage object instance. */
9304 +PHP_METHOD(HttpMessage, factory)
9306 + char *string = NULL, *cn = NULL;
9307 + int length = 0, cl = 0;
9308 + http_message *msg = NULL;
9309 + zend_object_value ov;
9310 + http_message_object *obj = NULL;
9314 + SET_EH_THROW_HTTP();
9315 + if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|ss", &string, &length, &cn, &cl)) {
9317 + msg = http_message_parse(string, length);
9319 + if ((msg || !length) && SUCCESS == http_object_new(&ov, cn, cl, _http_message_object_new_ex, http_message_object_ce, msg, &obj)) {
9320 + RETVAL_OBJVAL(ov, 0);
9322 + if (obj && !obj->message) {
9323 + obj->message = http_message_new();
9330 +/* {{{ proto static HttpMessage HttpMessage::fromEnv(int type[, string class_name = "HttpMessage"])
9331 + Create a new HttpMessage object from environment representing either current request or response */
9332 +PHP_METHOD(HttpMessage, fromEnv)
9337 + http_message_object *obj = NULL;
9338 + zend_object_value ov;
9341 + SET_EH_THROW_HTTP();
9342 + if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|s", &type, &cn, &cl)) {
9343 + if (SUCCESS == http_object_new(&ov, cn, cl, _http_message_object_new_ex, http_message_object_ce, http_message_init_env(NULL, type), &obj)) {
9344 + RETVAL_OBJVAL(ov, 0);
9346 + if (obj && !obj->message) {
9347 + obj->message = http_message_new();
9354 +/* {{{ proto string HttpMessage::getBody()
9355 + Get the body of the parsed HttpMessage. */
9356 +PHP_METHOD(HttpMessage, getBody)
9360 + if (return_value_used) {
9361 + getObject(http_message_object, obj);
9362 + RETURN_PHPSTR(&obj->message->body, PHPSTR_FREE_NOT, 1);
9367 +/* {{{ proto void HttpMessage::setBody(string body)
9368 + Set the body of the HttpMessage. NOTE: Don't forget to update any headers accordingly. */
9369 +PHP_METHOD(HttpMessage, setBody)
9373 + getObject(http_message_object, obj);
9375 + if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &body, &len)) {
9376 + phpstr_dtor(PHPSTR(obj->message));
9377 + phpstr_from_string_ex(PHPSTR(obj->message), body, len);
9382 +/* {{{ proto string HttpMessage::getHeader(string header)
9383 + Get message header. */
9384 +PHP_METHOD(HttpMessage, getHeader)
9387 + char *orig_header, *nice_header;
9389 + getObject(http_message_object, obj);
9391 + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &orig_header, &header_len)) {
9395 + nice_header = pretty_key(estrndup(orig_header, header_len), header_len, 1, 1);
9396 + if ((header = http_message_header_ex(obj->message, nice_header, header_len + 1, 0))) {
9397 + RETVAL_ZVAL(header, 1, 1);
9399 + efree(nice_header);
9403 +/* {{{ proto array HttpMessage::getHeaders()
9404 + Get Message Headers. */
9405 +PHP_METHOD(HttpMessage, getHeaders)
9409 + if (return_value_used) {
9410 + getObject(http_message_object, obj);
9412 + array_init(return_value);
9413 + array_copy(&obj->message->hdrs, Z_ARRVAL_P(return_value));
9418 +/* {{{ proto void HttpMessage::setHeaders(array headers)
9419 + Sets new headers. */
9420 +PHP_METHOD(HttpMessage, setHeaders)
9422 + zval *new_headers = NULL;
9423 + getObject(http_message_object, obj);
9425 + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a/!", &new_headers)) {
9429 + zend_hash_clean(&obj->message->hdrs);
9430 + if (new_headers) {
9431 + array_copy(Z_ARRVAL_P(new_headers), &obj->message->hdrs);
9436 +/* {{{ proto void HttpMessage::addHeaders(array headers[, bool append = false])
9437 + Add headers. If append is true, headers with the same name will be separated, else overwritten. */
9438 +PHP_METHOD(HttpMessage, addHeaders)
9440 + zval *new_headers;
9441 + zend_bool append = 0;
9442 + getObject(http_message_object, obj);
9444 + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a|b", &new_headers, &append)) {
9448 + array_join(Z_ARRVAL_P(new_headers), &obj->message->hdrs, append, ARRAY_JOIN_STRONLY|ARRAY_JOIN_PRETTIFY);
9452 +/* {{{ proto int HttpMessage::getType()
9453 + Get Message Type. (HTTP_MSG_NONE|HTTP_MSG_REQUEST|HTTP_MSG_RESPONSE) */
9454 +PHP_METHOD(HttpMessage, getType)
9458 + if (return_value_used) {
9459 + getObject(http_message_object, obj);
9460 + RETURN_LONG(obj->message->type);
9465 +/* {{{ proto void HttpMessage::setType(int type)
9466 + Set Message Type. (HTTP_MSG_NONE|HTTP_MSG_REQUEST|HTTP_MSG_RESPONSE) */
9467 +PHP_METHOD(HttpMessage, setType)
9470 + getObject(http_message_object, obj);
9472 + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &type)) {
9475 + http_message_set_type(obj->message, type);
9479 +/* {{{ proto string HttpMessage::getInfo(void)
9480 + Get the HTTP request/response line */
9481 +PHP_METHOD(HttpMessage, getInfo)
9485 + if (return_value_used) {
9486 + getObject(http_message_object, obj);
9488 + switch (obj->message->type) {
9489 + case HTTP_MSG_REQUEST:
9490 + Z_STRLEN_P(return_value) = spprintf(&Z_STRVAL_P(return_value), 0, HTTP_INFO_REQUEST_FMT_ARGS(&obj->message->http, ""));
9492 + case HTTP_MSG_RESPONSE:
9493 + Z_STRLEN_P(return_value) = spprintf(&Z_STRVAL_P(return_value), 0, HTTP_INFO_RESPONSE_FMT_ARGS(&obj->message->http, ""));
9499 + Z_TYPE_P(return_value) = IS_STRING;
9504 +/* {{{ proto bool HttpMessage::setInfo(string http_info)
9505 + Set type and request or response info with a standard HTTP request or response line */
9506 +PHP_METHOD(HttpMessage, setInfo)
9512 + if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &str, &len) && SUCCESS == http_info_parse_ex(str, &inf, 0)) {
9513 + getObject(http_message_object, obj);
9515 + http_message_set_info(obj->message, &inf);
9516 + http_info_dtor(&inf);
9523 +/* {{{ proto int HttpMessage::getResponseCode()
9524 + Get the Response Code of the Message. */
9525 +PHP_METHOD(HttpMessage, getResponseCode)
9529 + if (return_value_used) {
9530 + getObject(http_message_object, obj);
9531 + HTTP_CHECK_MESSAGE_TYPE_RESPONSE(obj->message, RETURN_FALSE);
9532 + RETURN_LONG(obj->message->http.info.response.code);
9537 +/* {{{ proto bool HttpMessage::setResponseCode(int code)
9538 + Set the response code of an HTTP Response Message. */
9539 +PHP_METHOD(HttpMessage, setResponseCode)
9542 + getObject(http_message_object, obj);
9544 + HTTP_CHECK_MESSAGE_TYPE_RESPONSE(obj->message, RETURN_FALSE);
9546 + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &code)) {
9549 + if (code < 100 || code > 599) {
9550 + http_error_ex(HE_WARNING, HTTP_E_INVALID_PARAM, "Invalid response code (100-599): %ld", code);
9554 + obj->message->http.info.response.code = code;
9559 +/* {{{ proto string HttpMessage::getResponseStatus()
9560 + Get the Response Status of the message (i.e. the string following the response code). */
9561 +PHP_METHOD(HttpMessage, getResponseStatus)
9565 + if (return_value_used) {
9566 + getObject(http_message_object, obj);
9567 + HTTP_CHECK_MESSAGE_TYPE_RESPONSE(obj->message, RETURN_FALSE);
9568 + if (obj->message->http.info.response.status) {
9569 + RETURN_STRING(obj->message->http.info.response.status, 1);
9571 + RETURN_EMPTY_STRING();
9577 +/* {{{ proto bool HttpMessage::setResponseStatus(string status)
9578 + Set the Response Status of the HTTP message (i.e. the string following the response code). */
9579 +PHP_METHOD(HttpMessage, setResponseStatus)
9583 + getObject(http_message_object, obj);
9585 + HTTP_CHECK_MESSAGE_TYPE_RESPONSE(obj->message, RETURN_FALSE);
9587 + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &status, &status_len)) {
9590 + STR_SET(obj->message->http.info.response.status, estrndup(status, status_len));
9595 +/* {{{ proto string HttpMessage::getRequestMethod()
9596 + Get the Request Method of the Message. */
9597 +PHP_METHOD(HttpMessage, getRequestMethod)
9601 + if (return_value_used) {
9602 + getObject(http_message_object, obj);
9603 + HTTP_CHECK_MESSAGE_TYPE_REQUEST(obj->message, RETURN_FALSE);
9604 + if (obj->message->http.info.request.method) {
9605 + RETURN_STRING(obj->message->http.info.request.method, 1);
9607 + RETURN_EMPTY_STRING();
9613 +/* {{{ proto bool HttpMessage::setRequestMethod(string method)
9614 + Set the Request Method of the HTTP Message. */
9615 +PHP_METHOD(HttpMessage, setRequestMethod)
9619 + getObject(http_message_object, obj);
9621 + HTTP_CHECK_MESSAGE_TYPE_REQUEST(obj->message, RETURN_FALSE);
9623 + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &method, &method_len)) {
9626 + if (method_len < 1) {
9627 + http_error(HE_WARNING, HTTP_E_INVALID_PARAM, "Cannot set HttpMessage::requestMethod to an empty string");
9630 + if (!http_request_method_exists(1, 0, method)) {
9631 + http_error_ex(HE_WARNING, HTTP_E_REQUEST_METHOD, "Unknown request method: %s", method);
9635 + STR_SET(obj->message->http.info.request.method, estrndup(method, method_len));
9640 +/* {{{ proto string HttpMessage::getRequestUrl()
9641 + Get the Request URL of the Message. */
9642 +PHP_METHOD(HttpMessage, getRequestUrl)
9646 + if (return_value_used) {
9647 + getObject(http_message_object, obj);
9648 + HTTP_CHECK_MESSAGE_TYPE_REQUEST(obj->message, RETURN_FALSE);
9649 + if (obj->message->http.info.request.url) {
9650 + RETURN_STRING(obj->message->http.info.request.url, 1);
9652 + RETURN_EMPTY_STRING();
9658 +/* {{{ proto bool HttpMessage::setRequestUrl(string url)
9659 + Set the Request URL of the HTTP Message. */
9660 +PHP_METHOD(HttpMessage, setRequestUrl)
9664 + getObject(http_message_object, obj);
9666 + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &URI, &URIlen)) {
9669 + HTTP_CHECK_MESSAGE_TYPE_REQUEST(obj->message, RETURN_FALSE);
9671 + http_error(HE_WARNING, HTTP_E_INVALID_PARAM, "Cannot set HttpMessage::requestUrl to an empty string");
9675 + STR_SET(obj->message->http.info.request.url, estrndup(URI, URIlen));
9680 +/* {{{ proto string HttpMessage::getHttpVersion()
9681 + Get the HTTP Protocol Version of the Message. */
9682 +PHP_METHOD(HttpMessage, getHttpVersion)
9686 + if (return_value_used) {
9688 + getObject(http_message_object, obj);
9690 + spprintf(&version, 0, "%1.1F", obj->message->http.version);
9691 + RETURN_STRING(version, 0);
9696 +/* {{{ proto bool HttpMessage::setHttpVersion(string version)
9697 + Set the HTTP Protocol version of the Message. */
9698 +PHP_METHOD(HttpMessage, setHttpVersion)
9702 + getObject(http_message_object, obj);
9704 + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z/", &zv)) {
9708 + convert_to_double(zv);
9709 + spprintf(&version, 0, "%1.1F", Z_DVAL_P(zv));
9710 + if (strcmp(version, "1.0") && strcmp(version, "1.1")) {
9712 + http_error_ex(HE_WARNING, HTTP_E_INVALID_PARAM, "Invalid HTTP protocol version (1.0 or 1.1): %g", Z_DVAL_P(zv));
9716 + obj->message->http.version = Z_DVAL_P(zv);
9721 +/* {{{ proto string HttpMessage::guessContentType(string magic_file[, int magic_mode = MAGIC_MIME])
9722 + Attempts to guess the content type of supplied payload through libmagic. */
9723 +PHP_METHOD(HttpMessage, guessContentType)
9725 +#ifdef HTTP_HAVE_MAGIC
9726 + char *magic_file, *ct = NULL;
9727 + int magic_file_len;
9728 + long magic_mode = MAGIC_MIME;
9731 + SET_EH_THROW_HTTP();
9732 + if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &magic_file, &magic_file_len, &magic_mode)) {
9733 + getObject(http_message_object, obj);
9734 + if ((ct = http_guess_content_type(magic_file, magic_mode, PHPSTR_VAL(&obj->message->body), PHPSTR_LEN(&obj->message->body), SEND_DATA))) {
9735 + RETVAL_STRING(ct, 0);
9740 + http_error(HE_THROW, HTTP_E_RUNTIME, "Cannot guess Content-Type; libmagic not available");
9746 +/* {{{ proto HttpMessage HttpMessage::getParentMessage()
9747 + Get parent Message. */
9748 +PHP_METHOD(HttpMessage, getParentMessage)
9750 + SET_EH_THROW_HTTP();
9752 + getObject(http_message_object, obj);
9754 + if (obj->message->parent) {
9755 + RETVAL_OBJVAL(obj->parent, 1);
9757 + http_error(HE_WARNING, HTTP_E_RUNTIME, "HttpMessage does not have a parent message");
9764 +/* {{{ proto bool HttpMessage::send()
9765 + Send the Message according to its type as Response or Request. */
9766 +PHP_METHOD(HttpMessage, send)
9768 + getObject(http_message_object, obj);
9772 + RETURN_SUCCESS(http_message_send(obj->message));
9776 +/* {{{ proto string HttpMessage::toString([bool include_parent = false])
9777 + Get the string representation of the Message. */
9778 +PHP_METHOD(HttpMessage, toString)
9780 + if (return_value_used) {
9783 + zend_bool include_parent = 0;
9784 + getObject(http_message_object, obj);
9786 + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &include_parent)) {
9790 + if (include_parent) {
9791 + http_message_serialize(obj->message, &string, &length);
9793 + http_message_tostring(obj->message, &string, &length);
9795 + RETURN_STRINGL(string, length, 0);
9800 +/* {{{ proto HttpRequest|HttpResponse HttpMessage::toMessageTypeObject(void)
9801 + Creates an object regarding to the type of the message. Returns either an HttpRequest or HttpResponse object on success, or NULL on failure. */
9802 +PHP_METHOD(HttpMessage, toMessageTypeObject)
9804 + SET_EH_THROW_HTTP();
9808 + if (return_value_used) {
9809 + getObject(http_message_object, obj);
9811 + switch (obj->message->type) {
9812 + case HTTP_MSG_REQUEST:
9814 +#ifdef HTTP_HAVE_CURL
9817 + zval post, body, *array, *headers, *host = http_message_header(obj->message, "Host");
9818 + php_url hurl, *purl = php_url_parse(STR_PTR(obj->message->http.info.request.url));
9820 + MAKE_STD_ZVAL(array);
9821 + array_init(array);
9823 + memset(&hurl, 0, sizeof(php_url));
9825 + hurl.host = Z_STRVAL_P(host);
9826 + zval_ptr_dtor(&host);
9828 + http_build_url(HTTP_URL_REPLACE, purl, &hurl, NULL, &url, NULL);
9829 + php_url_free(purl);
9830 + add_assoc_string(array, "url", url, 0);
9832 + if ( obj->message->http.info.request.method &&
9833 + ((method = http_request_method_exists(1, 0, obj->message->http.info.request.method)) ||
9834 + (method = http_request_method_register(obj->message->http.info.request.method, strlen(obj->message->http.info.request.method))))) {
9835 + add_assoc_long(array, "method", method);
9838 + if (10 == (int) (obj->message->http.version * 10)) {
9839 + add_assoc_long(array, "protocol", CURL_HTTP_VERSION_1_0);
9842 + MAKE_STD_ZVAL(headers);
9843 + array_init(headers);
9844 + array_copy(&obj->message->hdrs, Z_ARRVAL_P(headers));
9845 + add_assoc_zval(array, "headers", headers);
9847 + object_init_ex(return_value, http_request_object_ce);
9848 + zend_call_method_with_1_params(&return_value, http_request_object_ce, NULL, "setoptions", NULL, array);
9849 + zval_ptr_dtor(&array);
9851 + if (PHPSTR_VAL(obj->message) && PHPSTR_LEN(obj->message)) {
9852 + phpstr_fix(PHPSTR(obj->message));
9853 + INIT_PZVAL(&body);
9854 + ZVAL_STRINGL(&body, PHPSTR_VAL(obj->message), PHPSTR_LEN(obj->message), 0);
9855 + if (method != HTTP_POST) {
9856 + zend_call_method_with_1_params(&return_value, http_request_object_ce, NULL, "setbody", NULL, &body);
9858 + INIT_PZVAL(&post);
9859 + array_init(&post);
9861 + zval_copy_ctor(&body);
9862 + sapi_module.treat_data(PARSE_STRING, Z_STRVAL(body), &post TSRMLS_CC);
9863 + zend_call_method_with_1_params(&return_value, http_request_object_ce, NULL, "setpostfields", NULL, &post);
9868 + http_error(HE_WARNING, HTTP_E_RUNTIME, "Cannot transform HttpMessage to HttpRequest (missing curl support)");
9873 + case HTTP_MSG_RESPONSE:
9876 + HashPosition pos1, pos2;
9877 + HashKey key = initHashKey(0);
9878 + zval **header, **h, *body;
9880 + if (obj->message->http.info.response.code) {
9881 + http_send_status(obj->message->http.info.response.code);
9884 + object_init_ex(return_value, http_response_object_ce);
9886 + FOREACH_HASH_KEYVAL(pos1, &obj->message->hdrs, key, header) {
9887 + if (key.type == HASH_KEY_IS_STRING) {
9890 + MAKE_STD_ZVAL(zkey);
9891 + ZVAL_STRINGL(zkey, key.str, key.len - 1, 1);
9893 + switch (Z_TYPE_PP(header)) {
9896 + FOREACH_HASH_VAL(pos2, HASH_OF(*header), h) {
9898 + zend_call_method_with_2_params(&return_value, http_response_object_ce, NULL, "setheader", NULL, zkey, *h);
9904 + ZVAL_ADDREF(*header);
9905 + zend_call_method_with_2_params(&return_value, http_response_object_ce, NULL, "setheader", NULL, zkey, *header);
9906 + zval_ptr_dtor(header);
9909 + zval_ptr_dtor(&zkey);
9913 + MAKE_STD_ZVAL(body);
9914 + ZVAL_STRINGL(body, PHPSTR_VAL(obj->message), PHPSTR_LEN(obj->message), 1);
9915 + zend_call_method_with_1_params(&return_value, http_response_object_ce, NULL, "setdata", NULL, body);
9916 + zval_ptr_dtor(&body);
9918 + http_error(HE_WARNING, HTTP_E_RUNTIME, "Cannot transform HttpMessage to HttpResponse (need PHP 5.1+)");
9924 + http_error(HE_WARNING, HTTP_E_MESSAGE_TYPE, "HttpMessage is neither of type HttpMessage::TYPE_REQUEST nor HttpMessage::TYPE_RESPONSE");
9932 +/* {{{ proto int HttpMessage::count()
9933 + Implements Countable::count(). Returns the number of parent messages + 1. */
9934 +PHP_METHOD(HttpMessage, count)
9938 + getObject(http_message_object, obj);
9940 + http_message_count(i, obj->message);
9946 +/* {{{ proto string HttpMessage::serialize()
9947 + Implements Serializable::serialize(). Returns the serialized representation of the HttpMessage. */
9948 +PHP_METHOD(HttpMessage, serialize)
9953 + getObject(http_message_object, obj);
9955 + http_message_serialize(obj->message, &string, &length);
9956 + RETURN_STRINGL(string, length, 0);
9961 +/* {{{ proto void HttpMessage::unserialize(string serialized)
9962 + Implements Serializable::unserialize(). Re-constructs the HttpMessage based upon the serialized string. */
9963 +PHP_METHOD(HttpMessage, unserialize)
9967 + getObject(http_message_object, obj);
9969 + if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &serialized, &length)) {
9970 + http_message *msg;
9972 + http_message_dtor(obj->message);
9973 + if ((msg = http_message_parse_ex(obj->message, serialized, (size_t) length))) {
9974 + obj->message = msg;
9976 + http_message_init(obj->message);
9977 + http_error(HE_ERROR, HTTP_E_RUNTIME, "Could not unserialize HttpMessage");
9983 +/* {{{ proto HttpMessage HttpMessage::detach(void)
9984 + Returns a clone of an HttpMessage object detached from any parent messages. */
9985 +PHP_METHOD(HttpMessage, detach)
9988 + http_message *msg;
9989 + getObject(http_message_object, obj);
9993 + info.type = obj->message->type;
9994 + memcpy(&HTTP_INFO(&info), &HTTP_INFO(obj->message), sizeof(struct http_info));
9996 + msg = http_message_new();
9997 + http_message_set_info(msg, &info);
9999 + zend_hash_copy(&msg->hdrs, &obj->message->hdrs, (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *));
10000 + phpstr_append(&msg->body, PHPSTR_VAL(obj->message), PHPSTR_LEN(obj->message));
10002 + RETVAL_OBJVAL(http_message_object_new_ex(Z_OBJCE_P(getThis()), msg, NULL), 0);
10006 +/* {{{ proto void HttpMessage::prepend(HttpMessage message[, bool top = true])
10007 + Prepends message(s) to the HTTP message. Throws HttpInvalidParamException if the message is located within the same message chain. */
10008 +PHP_METHOD(HttpMessage, prepend)
10011 + zend_bool top = 1;
10013 + if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O|b", &prepend, http_message_object_ce, &top)) {
10014 + http_message *msg[2];
10015 + getObject(http_message_object, obj);
10016 + getObjectEx(http_message_object, prepend_obj, prepend);
10018 + /* safety check */
10019 + for (msg[0] = obj->message; msg[0]; msg[0] = msg[0]->parent) {
10020 + for (msg[1] = prepend_obj->message; msg[1]; msg[1] = msg[1]->parent) {
10021 + if (msg[0] == msg[1]) {
10022 + http_error(HE_THROW, HTTP_E_INVALID_PARAM, "Cannot prepend a message located within the same message chain");
10028 + http_message_object_prepend_ex(getThis(), prepend, top);
10033 +/* {{{ proto HttpMessage HttpMessage::reverse()
10034 + Reorders the message chain in reverse order. Returns the most parent HttpMessage object. */
10035 +PHP_METHOD(HttpMessage, reverse)
10038 + http_message_object_reverse(getThis(), return_value);
10043 +/* {{{ proto void HttpMessage::rewind(void)
10044 + Implements Iterator::rewind(). */
10045 +PHP_METHOD(HttpMessage, rewind)
10048 + getObject(http_message_object, obj);
10050 + if (obj->iterator) {
10051 + zval_ptr_dtor(&obj->iterator);
10053 + ZVAL_ADDREF(getThis());
10054 + obj->iterator = getThis();
10059 +/* {{{ proto bool HttpMessage::valid(void)
10060 + Implements Iterator::valid(). */
10061 +PHP_METHOD(HttpMessage, valid)
10064 + getObject(http_message_object, obj);
10066 + RETURN_BOOL(obj->iterator != NULL);
10071 +/* {{{ proto void HttpMessage::next(void)
10072 + Implements Iterator::next(). */
10073 +PHP_METHOD(HttpMessage, next)
10076 + getObject(http_message_object, obj);
10077 + if (obj->iterator) {
10078 + getObjectEx(http_message_object, itr, obj->iterator);
10080 + if (itr && itr->parent.handle) {
10081 + zval *old = obj->iterator;
10082 + MAKE_STD_ZVAL(obj->iterator);
10083 + ZVAL_OBJVAL(obj->iterator, itr->parent, 1);
10084 + zval_ptr_dtor(&old);
10086 + zval_ptr_dtor(&obj->iterator);
10087 + obj->iterator = NULL;
10094 +/* {{{ proto int HttpMessage::key(void)
10095 + Implements Iterator::key(). */
10096 +PHP_METHOD(HttpMessage, key)
10099 + getObject(http_message_object, obj);
10101 + RETURN_LONG(obj->iterator ? obj->iterator->value.obj.handle:0);
10106 +/* {{{ proto HttpMessage HttpMessage::current(void)
10107 + Implements Iterator::current(). */
10108 +PHP_METHOD(HttpMessage, current)
10111 + getObject(http_message_object, obj);
10113 + if (obj->iterator) {
10114 + RETURN_ZVAL(obj->iterator, 1, 0);
10120 +#endif /* ZEND_ENGINE_2 */
10123 + * Local variables:
10125 + * c-basic-offset: 4
10127 + * vim600: noet sw=4 ts=4 fdm=marker
10128 + * vim<600: noet sw=4 ts=4
10132 +++ b/ext/http/http_persistent_handle_api.c
10135 + +--------------------------------------------------------------------+
10137 + +--------------------------------------------------------------------+
10138 + | Redistribution and use in source and binary forms, with or without |
10139 + | modification, are permitted provided that the conditions mentioned |
10140 + | in the accompanying LICENSE file are met. |
10141 + +--------------------------------------------------------------------+
10142 + | Copyright (c) 2004-2010, Michael Wallner <mike@php.net> |
10143 + +--------------------------------------------------------------------+
10146 +/* $Id: http_persistent_handle_api.c 292841 2009-12-31 08:48:57Z mike $ */
10148 +#include "php_http.h"
10149 +#include "php_http_api.h"
10151 +#include "php_http_persistent_handle_api.h"
10153 +#ifndef HTTP_DEBUG_PHANDLES
10154 +# define HTTP_DEBUG_PHANDLES 0
10156 +#if HTTP_DEBUG_PHANDLES
10161 +static HashTable http_persistent_handles_hash;
10163 +# define LOCK() tsrm_mutex_lock(http_persistent_handles_lock)
10164 +# define UNLOCK() tsrm_mutex_unlock(http_persistent_handles_lock)
10165 +static MUTEX_T http_persistent_handles_lock;
10171 +typedef struct _http_persistent_handle_list_t {
10174 +} http_persistent_handle_list;
10176 +typedef struct _http_persistent_handle_provider_t {
10177 + http_persistent_handle_list list; /* "ident" => array(handles) entries */
10178 + http_persistent_handle_ctor ctor;
10179 + http_persistent_handle_dtor dtor;
10180 + http_persistent_handle_copy copy;
10181 +} http_persistent_handle_provider;
10183 +static inline http_persistent_handle_list *http_persistent_handle_list_init(http_persistent_handle_list *list)
10187 + if ((free_list = !list)) {
10188 + list = pemalloc(sizeof(http_persistent_handle_list), 1);
10193 + if (SUCCESS != zend_hash_init(&list->free, 0, NULL, NULL, 1)) {
10203 +static inline void http_persistent_handle_list_dtor(http_persistent_handle_list *list, http_persistent_handle_dtor dtor)
10205 + HashPosition pos;
10208 +#if HTTP_DEBUG_PHANDLES
10209 + fprintf(stderr, "LSTDTOR: %p\n", list);
10211 + FOREACH_HASH_VAL(pos, &list->free, handle) {
10212 +#if HTTP_DEBUG_PHANDLES
10213 + fprintf(stderr, "DESTROY: %p\n", *handle);
10218 + zend_hash_destroy(&list->free);
10221 +static inline void http_persistent_handle_list_free(http_persistent_handle_list **list, http_persistent_handle_dtor dtor)
10223 + http_persistent_handle_list_dtor(*list, dtor);
10224 +#if HTTP_DEBUG_PHANDLES
10225 + fprintf(stderr, "LSTFREE: %p\n", *list);
10227 + pefree(*list, 1);
10231 +static inline http_persistent_handle_list *http_persistent_handle_list_find(http_persistent_handle_provider *provider TSRMLS_DC)
10233 + http_persistent_handle_list **list, *new_list;
10235 + if (SUCCESS == zend_hash_quick_find(&provider->list.free, HTTP_G->persistent.handles.ident.s, HTTP_G->persistent.handles.ident.l, HTTP_G->persistent.handles.ident.h, (void *) &list)) {
10236 +#if HTTP_DEBUG_PHANDLES
10237 + fprintf(stderr, "LSTFIND: %p\n", *list);
10242 + if ((new_list = http_persistent_handle_list_init(NULL))) {
10243 + if (SUCCESS == zend_hash_quick_add(&provider->list.free, HTTP_G->persistent.handles.ident.s, HTTP_G->persistent.handles.ident.l, HTTP_G->persistent.handles.ident.h, (void *) &new_list, sizeof(http_persistent_handle_list *), (void *) &list)) {
10244 +#if HTTP_DEBUG_PHANDLES
10245 + fprintf(stderr, "LSTFIND: %p (new)\n", *list);
10249 + http_persistent_handle_list_free(&new_list, provider->dtor);
10255 +static inline STATUS http_persistent_handle_do_acquire(http_persistent_handle_provider *provider, void **handle TSRMLS_DC)
10258 + void **handle_ptr;
10259 + http_persistent_handle_list *list;
10261 + if ((list = http_persistent_handle_list_find(provider TSRMLS_CC))) {
10262 + zend_hash_internal_pointer_end(&list->free);
10263 + if (HASH_KEY_NON_EXISTANT != zend_hash_get_current_key(&list->free, NULL, &index, 0) && SUCCESS == zend_hash_get_current_data(&list->free, (void *) &handle_ptr)) {
10264 + *handle = *handle_ptr;
10265 + zend_hash_index_del(&list->free, index);
10267 + *handle = provider->ctor();
10271 + ++provider->list.used;
10282 +static inline STATUS http_persistent_handle_do_release(http_persistent_handle_provider *provider, void **handle TSRMLS_DC)
10284 + http_persistent_handle_list *list;
10286 + if ((list = http_persistent_handle_list_find(provider TSRMLS_CC))) {
10287 + if (provider->list.used >= HTTP_G->persistent.handles.limit) {
10288 + provider->dtor(*handle);
10290 + if (SUCCESS != zend_hash_next_index_insert(&list->free, (void *) handle, sizeof(void *), NULL)) {
10296 + --provider->list.used;
10304 +static inline STATUS http_persistent_handle_do_accrete(http_persistent_handle_provider *provider, void *old_handle, void **new_handle TSRMLS_DC)
10306 + http_persistent_handle_list *list;
10308 + if (provider->copy && (*new_handle = provider->copy(old_handle))) {
10309 + if ((list = http_persistent_handle_list_find(provider TSRMLS_CC))) {
10312 + ++provider->list.used;
10318 +static void http_persistent_handles_hash_dtor(void *p)
10320 + http_persistent_handle_provider *provider = (http_persistent_handle_provider *) p;
10321 + http_persistent_handle_list **list, *list_tmp;
10322 + HashPosition pos;
10324 + FOREACH_HASH_VAL(pos, &provider->list.free, list) {
10325 + /* fix shutdown crash in PHP4 */
10326 + list_tmp = *list;
10327 + http_persistent_handle_list_free(&list_tmp, provider->dtor);
10330 + zend_hash_destroy(&provider->list.free);
10333 +PHP_MINIT_FUNCTION(http_persistent_handle)
10335 + zend_hash_init(&http_persistent_handles_hash, 0, NULL, http_persistent_handles_hash_dtor, 1);
10337 + http_persistent_handles_lock = tsrm_mutex_alloc();
10342 +PHP_MSHUTDOWN_FUNCTION(http_persistent_handle)
10344 + zend_hash_destroy(&http_persistent_handles_hash);
10346 + tsrm_mutex_free(http_persistent_handles_lock);
10351 +PHP_HTTP_API STATUS _http_persistent_handle_provide_ex(const char *name_str, size_t name_len, http_persistent_handle_ctor ctor, http_persistent_handle_dtor dtor, http_persistent_handle_copy copy)
10353 + STATUS status = FAILURE;
10354 + http_persistent_handle_provider provider;
10357 + if (http_persistent_handle_list_init(&provider.list)) {
10358 + provider.ctor = ctor;
10359 + provider.dtor = dtor;
10360 + provider.copy = copy;
10362 +#if HTTP_DEBUG_PHANDLES
10363 + fprintf(stderr, "PROVIDE: %s\n", name_str);
10366 + if (SUCCESS == zend_hash_add(&http_persistent_handles_hash, HTTP_ZAPI_CONST_CAST(char *) name_str, name_len+1, (void *) &provider, sizeof(http_persistent_handle_provider), NULL)) {
10367 + status = SUCCESS;
10375 +PHP_HTTP_API STATUS _http_persistent_handle_acquire_ex(const char *name_str, size_t name_len, void **handle TSRMLS_DC)
10377 + STATUS status = FAILURE;
10378 + http_persistent_handle_provider *provider;
10382 + if (SUCCESS == zend_hash_find(&http_persistent_handles_hash, HTTP_ZAPI_CONST_CAST(char *) name_str, name_len+1, (void *) &provider)) {
10383 + status = http_persistent_handle_do_acquire(provider, handle TSRMLS_CC);
10387 +#if HTTP_DEBUG_PHANDLES
10388 + fprintf(stderr, "ACQUIRE: %p (%s)\n", *handle, name_str);
10394 +PHP_HTTP_API STATUS _http_persistent_handle_release_ex(const char *name_str, size_t name_len, void **handle TSRMLS_DC)
10396 + STATUS status = FAILURE;
10397 + http_persistent_handle_provider *provider;
10398 +#if HTTP_DEBUG_PHANDLES
10399 + void *handle_tmp = *handle;
10403 + if (SUCCESS == zend_hash_find(&http_persistent_handles_hash, HTTP_ZAPI_CONST_CAST(char *) name_str, name_len+1, (void *) &provider)) {
10404 + status = http_persistent_handle_do_release(provider, handle TSRMLS_CC);
10408 +#if HTTP_DEBUG_PHANDLES
10409 + fprintf(stderr, "RELEASE: %p (%s)\n", handle_tmp, name_str);
10415 +PHP_HTTP_API STATUS _http_persistent_handle_accrete_ex(const char *name_str, size_t name_len, void *old_handle, void **new_handle TSRMLS_DC)
10417 + STATUS status = FAILURE;
10418 + http_persistent_handle_provider *provider;
10420 + *new_handle = NULL;
10422 + if (SUCCESS == zend_hash_find(&http_persistent_handles_hash, HTTP_ZAPI_CONST_CAST(char *) name_str, name_len+1, (void *) &provider)) {
10423 + status = http_persistent_handle_do_accrete(provider, old_handle, new_handle TSRMLS_CC);
10427 +#if HTTP_DEBUG_PHANDLES
10428 + fprintf(stderr, "ACCRETE: %p > %p (%s)\n", old_handle, *new_handle, name_str);
10434 +PHP_HTTP_API void _http_persistent_handle_cleanup_ex(const char *name_str, size_t name_len, int current_ident_only TSRMLS_DC)
10436 + http_persistent_handle_provider *provider;
10437 + http_persistent_handle_list *list, **listp;
10438 + HashPosition pos1, pos2;
10441 + if (name_str && name_len) {
10442 + if (SUCCESS == zend_hash_find(&http_persistent_handles_hash, HTTP_ZAPI_CONST_CAST(char *) name_str, name_len+1, (void *) &provider)) {
10443 + if (current_ident_only) {
10444 + if ((list = http_persistent_handle_list_find(provider TSRMLS_CC))) {
10445 + http_persistent_handle_list_dtor(list, provider->dtor);
10446 + http_persistent_handle_list_init(list);
10449 + FOREACH_HASH_VAL(pos1, &provider->list.free, listp) {
10450 + http_persistent_handle_list_dtor(*listp, provider->dtor);
10451 + http_persistent_handle_list_init(*listp);
10456 + FOREACH_HASH_VAL(pos1, &http_persistent_handles_hash, provider) {
10457 + if (current_ident_only) {
10458 + if ((list = http_persistent_handle_list_find(provider TSRMLS_CC))) {
10459 + http_persistent_handle_list_dtor(list, provider->dtor);
10460 + http_persistent_handle_list_init(list);
10463 + FOREACH_HASH_VAL(pos2, &provider->list.free, listp) {
10464 + http_persistent_handle_list_dtor(*listp, provider->dtor);
10465 + http_persistent_handle_list_init(*listp);
10473 +PHP_HTTP_API HashTable *_http_persistent_handle_statall_ex(HashTable *ht TSRMLS_DC)
10476 + HashPosition pos1, pos2;
10477 + HashKey key1 = initHashKey(0), key2 = initHashKey(0);
10478 + http_persistent_handle_provider *provider;
10479 + http_persistent_handle_list **list;
10482 + if (zend_hash_num_elements(&http_persistent_handles_hash)) {
10484 + ALLOC_HASHTABLE(ht);
10485 + zend_hash_init(ht, 0, NULL, ZVAL_PTR_DTOR, 0);
10488 + FOREACH_HASH_KEYVAL(pos1, &http_persistent_handles_hash, key1, provider) {
10489 + MAKE_STD_ZVAL(zentry[0]);
10490 + array_init(zentry[0]);
10492 + FOREACH_HASH_KEYVAL(pos2, &provider->list.free, key2, list) {
10493 + MAKE_STD_ZVAL(zentry[1]);
10494 + array_init(zentry[1]);
10495 + add_assoc_long_ex(zentry[1], ZEND_STRS("used"), (*list)->used);
10496 + add_assoc_long_ex(zentry[1], ZEND_STRS("free"), zend_hash_num_elements(&(*list)->free));
10498 + /* use zend_hash_* not add_assoc_* (which is zend_symtable_*) as we want a string even for numbers */
10499 + zend_hash_add(Z_ARRVAL_P(zentry[0]), key2.str, key2.len, &zentry[1], sizeof(zval *), NULL);
10502 + zend_hash_add(ht, key1.str, key1.len, &zentry[0], sizeof(zval *), NULL);
10514 + * Local variables:
10516 + * c-basic-offset: 4
10518 + * vim600: noet sw=4 ts=4 fdm=marker
10519 + * vim<600: noet sw=4 ts=4
10523 +++ b/ext/http/http_querystring_api.c
10526 + +--------------------------------------------------------------------+
10528 + +--------------------------------------------------------------------+
10529 + | Redistribution and use in source and binary forms, with or without |
10530 + | modification, are permitted provided that the conditions mentioned |
10531 + | in the accompanying LICENSE file are met. |
10532 + +--------------------------------------------------------------------+
10533 + | Copyright (c) 2004-2010, Michael Wallner <mike@php.net> |
10534 + +--------------------------------------------------------------------+
10537 +/* $Id: http_querystring_api.c 292841 2009-12-31 08:48:57Z mike $ */
10539 +#define HTTP_WANT_SAPI
10540 +#include "php_http.h"
10542 +#include "php_variables.h"
10543 +#ifdef HTTP_HAVE_ICONV
10544 +# undef PHP_ATOM_INC
10545 +# include "ext/iconv/php_iconv.h"
10546 +# include "ext/standard/url.h"
10549 +#include "php_http_api.h"
10550 +#include "php_http_url_api.h"
10551 +#include "php_http_querystring_api.h"
10553 +#ifdef ZEND_ENGINE_2
10554 +#define THIS_CE http_querystring_object_ce
10555 +extern zend_class_entry *http_querystring_object_ce;
10559 +#define http_querystring_modify_array_ex(q, t, k, kl, i, pe) _http_querystring_modify_array_ex((q), (t), (k), (kl), (i), (pe) TSRMLS_CC)
10560 +static inline int _http_querystring_modify_array_ex(zval *qarray, int key_type, char *key, int keylen, ulong idx, zval *params_entry TSRMLS_DC);
10561 +#define http_querystring_modify_array(q, p) _http_querystring_modify_array((q), (p) TSRMLS_CC)
10562 +static inline int _http_querystring_modify_array(zval *qarray, zval *params TSRMLS_DC);
10565 +#ifdef HTTP_HAVE_ICONV
10566 +PHP_HTTP_API int _http_querystring_xlate(zval *array, zval *param, const char *ie, const char *oe TSRMLS_DC)
10568 + HashPosition pos;
10569 + zval **entry = NULL;
10570 + char *xlate_str = NULL, *xkey;
10571 + size_t xlate_len = 0, xlen;
10572 + HashKey key = initHashKey(0);
10574 + FOREACH_KEYVAL(pos, param, key, entry) {
10575 + if (key.type == HASH_KEY_IS_STRING) {
10576 + if (PHP_ICONV_ERR_SUCCESS != php_iconv_string(key.str, key.len-1, &xkey, &xlen, oe, ie)) {
10577 + http_error_ex(HE_WARNING, HTTP_E_QUERYSTRING, "Failed to convert '%.*s' from '%s' to '%s'", key.len-1, key.str, ie, oe);
10582 + if (Z_TYPE_PP(entry) == IS_STRING) {
10583 + if (PHP_ICONV_ERR_SUCCESS != php_iconv_string(Z_STRVAL_PP(entry), Z_STRLEN_PP(entry), &xlate_str, &xlate_len, oe, ie)) {
10584 + if (key.type == HASH_KEY_IS_STRING) {
10587 + http_error_ex(HE_WARNING, HTTP_E_QUERYSTRING, "Failed to convert '%.*s' from '%s' to '%s'", Z_STRLEN_PP(entry), Z_STRVAL_PP(entry), ie, oe);
10590 + if (key.type == HASH_KEY_IS_STRING) {
10591 + add_assoc_stringl_ex(array, xkey, xlen+1, xlate_str, xlate_len, 0);
10593 + add_index_stringl(array, key.num, xlate_str, xlate_len, 0);
10595 + } else if (Z_TYPE_PP(entry) == IS_ARRAY) {
10598 + MAKE_STD_ZVAL(subarray);
10599 + array_init(subarray);
10600 + if (key.type == HASH_KEY_IS_STRING) {
10601 + add_assoc_zval_ex(array, xkey, xlen+1, subarray);
10603 + add_index_zval(array, key.num, subarray);
10605 + if (SUCCESS != http_querystring_xlate(subarray, *entry, ie, oe)) {
10606 + if (key.type == HASH_KEY_IS_STRING) {
10613 + if (key.type == HASH_KEY_IS_STRING) {
10619 +#endif /* HAVE_ICONV */
10621 +PHP_HTTP_API void _http_querystring_update(zval *qarray, zval *qstring TSRMLS_DC)
10626 + if (Z_TYPE_P(qarray) != IS_ARRAY) {
10627 + convert_to_array(qarray);
10629 + if (SUCCESS == http_urlencode_hash_ex(Z_ARRVAL_P(qarray), 0, NULL, 0, &s, &l)) {
10630 + zval_dtor(qstring);
10631 + ZVAL_STRINGL(qstring, s, l, 0);
10633 + http_error(HE_WARNING, HTTP_E_QUERYSTRING, "Failed to update query string");
10637 +PHP_HTTP_API int _http_querystring_modify(zval *qarray, zval *params TSRMLS_DC)
10639 + if (Z_TYPE_P(params) == IS_ARRAY) {
10640 + return http_querystring_modify_array(qarray, params);
10641 + } else if (Z_TYPE_P(params) == IS_OBJECT) {
10642 +#ifdef ZEND_ENGINE_2
10643 + if (instanceof_function(Z_OBJCE_P(params), http_querystring_object_ce TSRMLS_CC)) {
10644 + return http_querystring_modify_array(qarray, zend_read_property(THIS_CE, params, ZEND_STRS("queryArray")-1, 0 TSRMLS_CC));
10647 + return http_querystring_modify_array(qarray, params);
10648 +#ifdef ZEND_ENGINE_2
10654 + zval *qstring = http_zsep(IS_STRING, params);
10656 + INIT_PZVAL(&array);
10657 + array_init(&array);
10659 + sapi_module.treat_data(PARSE_STRING, estrdup(Z_STRVAL_P(qstring)), &array TSRMLS_CC);
10660 + zval_ptr_dtor(&qstring);
10662 + rv = http_querystring_modify_array(qarray, &array);
10663 + zval_dtor(&array);
10668 +static inline int _http_querystring_modify_array(zval *qarray, zval *params TSRMLS_DC)
10671 + HashKey key = initHashKey(0);
10672 + HashPosition pos;
10673 + zval **params_entry = NULL;
10675 + FOREACH_HASH_KEYVAL(pos, HASH_OF(params), key, params_entry) {
10676 + /* only public properties */
10677 + if ((key.type != HASH_KEY_IS_STRING || *key.str) && http_querystring_modify_array_ex(qarray, key.type, key.str, key.len, key.num, *params_entry)) {
10685 +static inline int _http_querystring_modify_array_ex(zval *qarray, int key_type, char *key, int keylen, ulong idx, zval *params_entry TSRMLS_DC)
10687 + zval **qarray_entry;
10689 + /* ensure array type */
10690 + if (Z_TYPE_P(qarray) != IS_ARRAY) {
10691 + convert_to_array(qarray);
10695 + if (Z_TYPE_P(params_entry) == IS_NULL) {
10696 + if (key_type == HASH_KEY_IS_STRING) {
10697 + return (SUCCESS == zend_hash_del(Z_ARRVAL_P(qarray), key, keylen));
10699 + return (SUCCESS == zend_hash_index_del(Z_ARRVAL_P(qarray), idx));
10704 + if ( ((key_type == HASH_KEY_IS_STRING) && (SUCCESS == zend_hash_find(Z_ARRVAL_P(qarray), key, keylen, (void *) &qarray_entry))) ||
10705 + ((key_type == HASH_KEY_IS_LONG) && (SUCCESS == zend_hash_index_find(Z_ARRVAL_P(qarray), idx, (void *) &qarray_entry)))) {
10709 + if (Z_TYPE_P(params_entry) == IS_ARRAY || Z_TYPE_P(params_entry) == IS_OBJECT) {
10710 + return http_querystring_modify(*qarray_entry, params_entry);
10713 + if ((SUCCESS == is_equal_function(&equal, *qarray_entry, params_entry TSRMLS_CC)) && Z_BVAL(equal)) {
10719 + if (Z_TYPE_P(params_entry) == IS_OBJECT) {
10722 + MAKE_STD_ZVAL(new_array);
10723 + array_init(new_array);
10724 + http_querystring_modify_array(new_array, params_entry);
10725 + params_entry = new_array;
10727 + ZVAL_ADDREF(params_entry);
10729 + if (key_type == HASH_KEY_IS_STRING) {
10730 + add_assoc_zval_ex(qarray, key, keylen, params_entry);
10732 + add_index_zval(qarray, idx, params_entry);
10738 + * Local variables:
10740 + * c-basic-offset: 4
10742 + * vim600: noet sw=4 ts=4 fdm=marker
10743 + * vim<600: noet sw=4 ts=4
10746 +++ b/ext/http/http_querystring_object.c
10749 + +--------------------------------------------------------------------+
10751 + +--------------------------------------------------------------------+
10752 + | Redistribution and use in source and binary forms, with or without |
10753 + | modification, are permitted provided that the conditions mentioned |
10754 + | in the accompanying LICENSE file are met. |
10755 + +--------------------------------------------------------------------+
10756 + | Copyright (c) 2004-2010, Michael Wallner <mike@php.net> |
10757 + +--------------------------------------------------------------------+
10760 +/* $Id: http_querystring_object.c 323304 2012-02-17 21:13:24Z mike $ */
10762 +#define HTTP_WANT_SAPI
10763 +#include "php_http.h"
10765 +#ifdef ZEND_ENGINE_2
10767 +#include "php_variables.h"
10768 +#include "zend_interfaces.h"
10770 +#include "php_http_api.h"
10771 +#include "php_http_querystring_api.h"
10772 +#include "php_http_querystring_object.h"
10773 +#include "php_http_exception_object.h"
10775 +#define HTTP_BEGIN_ARGS(method, req_args) HTTP_BEGIN_ARGS_EX(HttpQueryString, method, 0, req_args)
10776 +#define HTTP_EMPTY_ARGS(method) HTTP_EMPTY_ARGS_EX(HttpQueryString, method, 0)
10777 +#define HTTP_QUERYSTRING_ME(method, visibility) PHP_ME(HttpQueryString, method, HTTP_ARGS(HttpQueryString, method), visibility)
10778 +#define HTTP_QUERYSTRING_GME(method, visibility) PHP_ME(HttpQueryString, method, HTTP_ARGS(HttpQueryString, __getter), visibility)
10780 +HTTP_BEGIN_ARGS(__construct, 0)
10781 + HTTP_ARG_VAL(global, 0)
10782 + HTTP_ARG_VAL(params, 0)
10786 +HTTP_BEGIN_ARGS(singleton, 0)
10787 + HTTP_ARG_VAL(global, 0)
10791 +HTTP_BEGIN_ARGS(factory, 0)
10792 + HTTP_ARG_VAL(global, 0)
10793 + HTTP_ARG_VAL(params, 0)
10794 + HTTP_ARG_VAL(class_name, 0)
10797 +HTTP_EMPTY_ARGS(toArray);
10798 +HTTP_EMPTY_ARGS(toString);
10800 +HTTP_BEGIN_ARGS(get, 0)
10801 + HTTP_ARG_VAL(name, 0)
10802 + HTTP_ARG_VAL(type, 0)
10803 + HTTP_ARG_VAL(defval, 0)
10804 + HTTP_ARG_VAL(delete, 0)
10807 +HTTP_BEGIN_ARGS(set, 1)
10808 + HTTP_ARG_VAL(params, 0)
10811 +HTTP_BEGIN_ARGS(mod, 0)
10812 + HTTP_ARG_VAL(params, 0)
10815 +HTTP_BEGIN_ARGS(__getter, 1)
10816 + HTTP_ARG_VAL(name, 0)
10817 + HTTP_ARG_VAL(defval, 0)
10818 + HTTP_ARG_VAL(delete, 0)
10821 +#ifdef HTTP_HAVE_ICONV
10822 +HTTP_BEGIN_ARGS(xlate, 2)
10823 + HTTP_ARG_VAL(from_encoding, 0)
10824 + HTTP_ARG_VAL(to_encoding, 0)
10828 +HTTP_EMPTY_ARGS(serialize);
10829 +HTTP_BEGIN_ARGS(unserialize, 1)
10830 + HTTP_ARG_VAL(serialized, 0)
10833 +HTTP_BEGIN_ARGS(offsetGet, 1)
10834 + HTTP_ARG_VAL(offset, 0)
10837 +HTTP_BEGIN_ARGS(offsetSet, 2)
10838 + HTTP_ARG_VAL(offset, 0)
10839 + HTTP_ARG_VAL(value, 0)
10842 +HTTP_BEGIN_ARGS(offsetExists, 1)
10843 + HTTP_ARG_VAL(offset, 0)
10846 +HTTP_BEGIN_ARGS(offsetUnset, 1)
10847 + HTTP_ARG_VAL(offset, 0)
10851 +#define THIS_CE http_querystring_object_ce
10852 +zend_class_entry *http_querystring_object_ce;
10853 +zend_function_entry http_querystring_object_fe[] = {
10854 + HTTP_QUERYSTRING_ME(__construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR|ZEND_ACC_FINAL)
10856 + HTTP_QUERYSTRING_ME(toArray, ZEND_ACC_PUBLIC)
10857 + HTTP_QUERYSTRING_ME(toString, ZEND_ACC_PUBLIC)
10858 + ZEND_MALIAS(HttpQueryString, __toString, toString, HTTP_ARGS(HttpQueryString, toString), ZEND_ACC_PUBLIC)
10860 + HTTP_QUERYSTRING_ME(get, ZEND_ACC_PUBLIC)
10861 + HTTP_QUERYSTRING_ME(set, ZEND_ACC_PUBLIC)
10862 + HTTP_QUERYSTRING_ME(mod, ZEND_ACC_PUBLIC)
10864 + HTTP_QUERYSTRING_GME(getBool, ZEND_ACC_PUBLIC)
10865 + HTTP_QUERYSTRING_GME(getInt, ZEND_ACC_PUBLIC)
10866 + HTTP_QUERYSTRING_GME(getFloat, ZEND_ACC_PUBLIC)
10867 + HTTP_QUERYSTRING_GME(getString, ZEND_ACC_PUBLIC)
10868 + HTTP_QUERYSTRING_GME(getArray, ZEND_ACC_PUBLIC)
10869 + HTTP_QUERYSTRING_GME(getObject, ZEND_ACC_PUBLIC)
10871 + HTTP_QUERYSTRING_ME(factory, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
10873 + HTTP_QUERYSTRING_ME(singleton, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
10875 +#ifdef HTTP_HAVE_ICONV
10876 + HTTP_QUERYSTRING_ME(xlate, ZEND_ACC_PUBLIC)
10879 + /* Implements Serializable */
10880 + HTTP_QUERYSTRING_ME(serialize, ZEND_ACC_PUBLIC)
10881 + HTTP_QUERYSTRING_ME(unserialize, ZEND_ACC_PUBLIC)
10883 + /* Implements ArrayAccess */
10884 + HTTP_QUERYSTRING_ME(offsetGet, ZEND_ACC_PUBLIC)
10885 + HTTP_QUERYSTRING_ME(offsetSet, ZEND_ACC_PUBLIC)
10886 + HTTP_QUERYSTRING_ME(offsetExists, ZEND_ACC_PUBLIC)
10887 + HTTP_QUERYSTRING_ME(offsetUnset, ZEND_ACC_PUBLIC)
10889 + EMPTY_FUNCTION_ENTRY
10891 +static zend_object_handlers http_querystring_object_handlers;
10893 +PHP_MINIT_FUNCTION(http_querystring_object)
10895 + HTTP_REGISTER_CLASS_EX(HttpQueryString, http_querystring_object, NULL, 0);
10898 + zend_class_implements(http_querystring_object_ce TSRMLS_CC, 2, zend_ce_serializable, zend_ce_arrayaccess);
10901 + zend_declare_property_null(THIS_CE, ZEND_STRS("instance")-1, (ZEND_ACC_STATIC|ZEND_ACC_PRIVATE) TSRMLS_CC);
10902 + zend_declare_property_null(THIS_CE, ZEND_STRS("queryArray")-1, ZEND_ACC_PRIVATE TSRMLS_CC);
10903 + zend_declare_property_string(THIS_CE, ZEND_STRS("queryString")-1, "", ZEND_ACC_PRIVATE TSRMLS_CC);
10906 + zend_declare_class_constant_long(THIS_CE, ZEND_STRS("TYPE_BOOL")-1, HTTP_QUERYSTRING_TYPE_BOOL TSRMLS_CC);
10907 + zend_declare_class_constant_long(THIS_CE, ZEND_STRS("TYPE_INT")-1, HTTP_QUERYSTRING_TYPE_INT TSRMLS_CC);
10908 + zend_declare_class_constant_long(THIS_CE, ZEND_STRS("TYPE_FLOAT")-1, HTTP_QUERYSTRING_TYPE_FLOAT TSRMLS_CC);
10909 + zend_declare_class_constant_long(THIS_CE, ZEND_STRS("TYPE_STRING")-1, HTTP_QUERYSTRING_TYPE_STRING TSRMLS_CC);
10910 + zend_declare_class_constant_long(THIS_CE, ZEND_STRS("TYPE_ARRAY")-1, HTTP_QUERYSTRING_TYPE_ARRAY TSRMLS_CC);
10911 + zend_declare_class_constant_long(THIS_CE, ZEND_STRS("TYPE_OBJECT")-1, HTTP_QUERYSTRING_TYPE_OBJECT TSRMLS_CC);
10914 + HTTP_LONG_CONSTANT("HTTP_QUERYSTRING_TYPE_BOOL", HTTP_QUERYSTRING_TYPE_BOOL);
10915 + HTTP_LONG_CONSTANT("HTTP_QUERYSTRING_TYPE_INT", HTTP_QUERYSTRING_TYPE_INT);
10916 + HTTP_LONG_CONSTANT("HTTP_QUERYSTRING_TYPE_FLOAT", HTTP_QUERYSTRING_TYPE_FLOAT);
10917 + HTTP_LONG_CONSTANT("HTTP_QUERYSTRING_TYPE_STRING", HTTP_QUERYSTRING_TYPE_STRING);
10918 + HTTP_LONG_CONSTANT("HTTP_QUERYSTRING_TYPE_ARRAY", HTTP_QUERYSTRING_TYPE_ARRAY);
10919 + HTTP_LONG_CONSTANT("HTTP_QUERYSTRING_TYPE_OBJECT", HTTP_QUERYSTRING_TYPE_OBJECT);
10924 +zend_object_value _http_querystring_object_new(zend_class_entry *ce TSRMLS_DC)
10926 + return http_querystring_object_new_ex(ce, NULL, NULL);
10929 +zend_object_value _http_querystring_object_new_ex(zend_class_entry *ce, void *nothing, http_querystring_object **ptr TSRMLS_DC)
10931 + zend_object_value ov;
10932 + http_querystring_object *o;
10934 + o = ecalloc(1, sizeof(http_querystring_object));
10941 +#ifdef ZEND_ENGINE_2_4
10942 + zend_object_std_init(o, ce TSRMLS_CC);
10943 + object_properties_init(o, ce);
10945 + ALLOC_HASHTABLE(OBJ_PROP(o));
10946 + zend_hash_init(OBJ_PROP(o), zend_hash_num_elements(&ce->default_properties), NULL, ZVAL_PTR_DTOR, 0);
10947 + zend_hash_copy(OBJ_PROP(o), &ce->default_properties, (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *));
10950 + ov.handle = putObject(http_querystring_object, o);
10951 + ov.handlers = &http_querystring_object_handlers;
10956 +void _http_querystring_object_free(zend_object *object TSRMLS_DC)
10958 + http_querystring_object *o = (http_querystring_object *) object;
10963 +/* {{{ querystring helpers */
10964 +#define http_querystring_instantiate(t, g, p, u) _http_querystring_instantiate((t), (g), (p), (u) TSRMLS_CC)
10965 +static inline zval *_http_querystring_instantiate(zval *this_ptr, zend_bool global, zval *params, zend_bool defer_update TSRMLS_DC)
10967 + zval *qarray = NULL, *qstring = NULL, **_SERVER = NULL, **_GET = NULL, **QUERY_STRING = NULL;;
10970 + MAKE_STD_ZVAL(this_ptr);
10971 + Z_TYPE_P(this_ptr) = IS_OBJECT;
10972 + this_ptr->value.obj = http_querystring_object_new(http_querystring_object_ce);
10975 +#ifdef ZEND_ENGINE_2
10976 + zend_is_auto_global("_SERVER", lenof("_SERVER") TSRMLS_CC);
10978 + if ( (SUCCESS == zend_hash_find(&EG(symbol_table), "_SERVER", sizeof("_SERVER"), (void *) &_SERVER)) &&
10979 + (Z_TYPE_PP(_SERVER) == IS_ARRAY) &&
10980 + (SUCCESS == zend_hash_find(Z_ARRVAL_PP(_SERVER), "QUERY_STRING", sizeof("QUERY_STRING"), (void *) &QUERY_STRING))) {
10982 + qstring = *QUERY_STRING;
10983 +#ifdef ZEND_ENGINE_2
10984 + zend_is_auto_global("_GET", lenof("_GET") TSRMLS_CC);
10986 + if ((SUCCESS == zend_hash_find(&EG(symbol_table), "_GET", sizeof("_GET"), (void *) &_GET)) && (Z_TYPE_PP(_GET) == IS_ARRAY)) {
10989 + http_error(HE_WARNING, HTTP_E_QUERYSTRING, "Could not acquire reference to superglobal GET array");
10992 + http_error(HE_WARNING, HTTP_E_QUERYSTRING, "Could not acquire reference to QUERY_STRING");
10995 + if (qarray && qstring) {
10996 + if (Z_TYPE_P(qstring) != IS_STRING) {
10997 + convert_to_string(qstring);
11000 + zend_update_property(THIS_CE, getThis(), ZEND_STRS("queryArray")-1, qarray TSRMLS_CC);
11001 + zend_update_property(THIS_CE, getThis(), ZEND_STRS("queryString")-1, qstring TSRMLS_CC);
11002 +#ifdef Z_SET_ISREF
11003 + Z_SET_ISREF_P(zend_read_property(THIS_CE, getThis(), ZEND_STRS("queryArray")-1, 0 TSRMLS_CC));
11004 + Z_SET_ISREF_P(zend_read_property(THIS_CE, getThis(), ZEND_STRS("queryString")-1, 0 TSRMLS_CC));
11006 + zend_read_property(THIS_CE, getThis(), ZEND_STRS("queryArray")-1, 0 TSRMLS_CC)->is_ref = 1;
11007 + zend_read_property(THIS_CE, getThis(), ZEND_STRS("queryString")-1, 0 TSRMLS_CC)->is_ref = 1;
11011 + http_querystring_modify(zend_read_property(THIS_CE, getThis(), ZEND_STRS("queryArray")-1, 0 TSRMLS_CC), params);
11013 + if (!defer_update) {
11014 + http_querystring_update(zend_read_property(THIS_CE, getThis(), ZEND_STRS("queryArray")-1, 0 TSRMLS_CC), zend_read_property(THIS_CE, getThis(), ZEND_STRS("queryString")-1, 0 TSRMLS_CC));
11018 + MAKE_STD_ZVAL(qarray);
11019 + array_init(qarray);
11021 + zend_update_property(THIS_CE, getThis(), ZEND_STRS("queryArray")-1, qarray TSRMLS_CC);
11022 + zend_update_property_stringl(THIS_CE, getThis(), ZEND_STRS("queryString")-1, "", 0 TSRMLS_CC);
11024 + if (params && http_querystring_modify(qarray, params) && !defer_update) {
11025 + http_querystring_update(qarray, zend_read_property(THIS_CE, getThis(), ZEND_STRS("queryString")-1, 0 TSRMLS_CC));
11028 + zval_ptr_dtor(&qarray);
11034 +#define http_querystring_get(o, t, n, l, def, del, r) _http_querystring_get((o), (t), (n), (l), (def), (del), (r) TSRMLS_CC)
11035 +static inline void _http_querystring_get(zval *this_ptr, int type, char *name, uint name_len, zval *defval, zend_bool del, zval *return_value TSRMLS_DC)
11037 + zval **arrval, *qarray = zend_read_property(THIS_CE, getThis(), ZEND_STRS("queryArray")-1, 0 TSRMLS_CC);
11039 + if ((Z_TYPE_P(qarray) == IS_ARRAY) && (SUCCESS == zend_hash_find(Z_ARRVAL_P(qarray), name, name_len + 1, (void *) &arrval))) {
11041 + zval *value = http_zsep(type, *arrval);
11042 + RETVAL_ZVAL(value, 1, 1);
11044 + RETVAL_ZVAL(*arrval, 1, 0);
11047 + if (del && (SUCCESS == zend_hash_del(Z_ARRVAL_P(qarray), name, name_len + 1))) {
11048 + http_querystring_update(qarray, zend_read_property(THIS_CE, getThis(), ZEND_STRS("queryString")-1, 0 TSRMLS_CC));
11050 + } else if(defval) {
11051 + RETURN_ZVAL(defval, 1, 0);
11056 +/* {{{ proto final void HttpQueryString::__construct([bool global = true[, mixed add])
11057 + Creates a new HttpQueryString object instance. Operates on and modifies $_GET and $_SERVER['QUERY_STRING'] if global is TRUE. */
11058 +PHP_METHOD(HttpQueryString, __construct)
11060 + zend_bool global = 1;
11061 + zval *params = NULL;
11063 + SET_EH_THROW_HTTP();
11064 + if (!sapi_module.treat_data) {
11065 + http_error(HE_ERROR, HTTP_E_QUERYSTRING, "The SAPI does not have a treat_data function registered");
11066 + } else if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|bz", &global, ¶ms)) {
11067 + http_querystring_instantiate(getThis(), global, params, 0);
11073 +/* {{{ proto HttpQueryString HttpQueryString::factory([bool global = TRUE[, mixed params[, string class_name = "HttpQueryString"])
11074 + Creates a new HttpQueryString object instance. */
11075 +PHP_METHOD(HttpQueryString, factory)
11077 + zend_bool global = 1;
11078 + zval *params = NULL;
11081 + zend_object_value ov;
11083 + SET_EH_THROW_HTTP();
11084 + if (!sapi_module.treat_data) {
11085 + http_error(HE_ERROR, HTTP_E_QUERYSTRING, "The SAPI does not have a treat_data function registered");
11086 + } else if ( SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|bzs", &global, ¶ms, &cn, &cl) &&
11087 + SUCCESS == http_object_new(&ov, cn, cl, _http_querystring_object_new_ex, http_querystring_object_ce, NULL, NULL)) {
11088 + RETVAL_OBJVAL(ov, 0);
11089 + http_querystring_instantiate(return_value, global, params, 0);
11095 +/* {{{ proto string HttpQueryString::toString()
11096 + Returns the string representation. */
11097 +PHP_METHOD(HttpQueryString, toString)
11100 + RETURN_PROP(queryString);
11104 +/* {{{ proto array HttpQueryString::toArray()
11105 + Returns the array representation. */
11106 +PHP_METHOD(HttpQueryString, toArray)
11109 + RETURN_PROP(queryArray);
11113 +/* {{{ proto mixed HttpQueryString::get([string key[, mixed type = 0[, mixed defval = NULL[, bool delete = false]]]])
11114 + Get (part of) the query string. The type parameter is either one of the HttpQueryString::TYPE_* constants or a type abbreviation like "b" for bool, "i" for int, "f" for float, "s" for string, "a" for array and "o" for a stdClass object. */
11115 +PHP_METHOD(HttpQueryString, get)
11117 + char *name = NULL;
11118 + int name_len = 0;
11120 + zend_bool del = 0;
11121 + zval *ztype = NULL, *defval = NULL;
11123 + if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|szzb", &name, &name_len, &ztype, &defval, &del)) {
11124 + if (name && name_len) {
11126 + if (Z_TYPE_P(ztype) == IS_LONG) {
11127 + type = Z_LVAL_P(ztype);
11128 + } else if(Z_TYPE_P(ztype) == IS_STRING) {
11129 + switch (Z_STRVAL_P(ztype)[0]) {
11131 + case 'b': type = HTTP_QUERYSTRING_TYPE_BOOL; break;
11133 + case 'i': type = HTTP_QUERYSTRING_TYPE_INT; break;
11135 + case 'f': type = HTTP_QUERYSTRING_TYPE_FLOAT; break;
11137 + case 's': type = HTTP_QUERYSTRING_TYPE_STRING; break;
11139 + case 'a': type = HTTP_QUERYSTRING_TYPE_ARRAY; break;
11141 + case 'o': type = HTTP_QUERYSTRING_TYPE_OBJECT; break;
11145 + http_querystring_get(getThis(), type, name, name_len, defval, del, return_value);
11147 + RETURN_PROP(queryString);
11153 +/* {{{ proto string HttpQueryString::set(mixed params)
11154 + Set query string entry/entries. NULL values will unset the variable. */
11155 +PHP_METHOD(HttpQueryString, set)
11159 + if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", ¶ms)) {
11160 + zval *qarray = zend_read_property(THIS_CE, getThis(), ZEND_STRS("queryArray")-1, 0 TSRMLS_CC);
11161 + if (http_querystring_modify(qarray, params)) {
11162 + http_querystring_update(qarray, zend_read_property(THIS_CE, getThis(), ZEND_STRS("queryString")-1, 0 TSRMLS_CC));
11166 + if (return_value_used) {
11167 + RETURN_PROP(queryString);
11172 +/* {{{ proto HttpQueryString HttpQueryString::mod(mixed params)
11173 + Copies the query string object and sets provided params at the clone. */
11174 +PHP_METHOD(HttpQueryString, mod)
11176 + zval *zobj, *qarr, *qstr, *params;
11178 + if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", ¶ms)) {
11179 + zobj = http_querystring_instantiate(NULL, 0, zend_read_property(THIS_CE, getThis(), ZEND_STRS("queryArray")-1, 0 TSRMLS_CC), 1);
11180 + qarr = zend_read_property(THIS_CE, zobj, ZEND_STRS("queryArray")-1, 0 TSRMLS_CC);
11181 + qstr = zend_read_property(THIS_CE, zobj, ZEND_STRS("queryString")-1, 0 TSRMLS_CC);
11183 + http_querystring_modify(qarr, params);
11184 + http_querystring_update(qarr, qstr);
11186 + RETURN_ZVAL(zobj, 1, 1);
11192 +/* {{{ proto static HttpQueryString HttpQueryString::singleton([bool global = true])
11193 + Get a single instance (differentiates between the global setting). */
11194 +PHP_METHOD(HttpQueryString, singleton)
11196 + zend_bool global = 1;
11197 + zval *instance = *zend_std_get_static_property(THIS_CE, ZEND_STRS("instance")-1, 0 ZEND_LITERAL_NIL_CC TSRMLS_CC);
11199 + SET_EH_THROW_HTTP();
11200 + if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &global)) {
11201 + zval **zobj_ptr = NULL, *zobj = NULL;
11203 + if (Z_TYPE_P(instance) == IS_ARRAY) {
11204 + if (SUCCESS == zend_hash_index_find(Z_ARRVAL_P(instance), global, (void *) &zobj_ptr)) {
11205 + RETVAL_ZVAL(*zobj_ptr, 1, 0);
11207 + zobj = http_querystring_instantiate(NULL, global, NULL, (zend_bool) !global);
11208 + add_index_zval(instance, global, zobj);
11209 + RETVAL_OBJECT(zobj, 1);
11212 + MAKE_STD_ZVAL(instance);
11213 + array_init(instance);
11215 + zobj = http_querystring_instantiate(NULL, global, NULL, (zend_bool) !global);
11216 + add_index_zval(instance, global, zobj);
11217 + RETVAL_OBJECT(zobj, 1);
11219 + zend_update_static_property(THIS_CE, ZEND_STRS("instance")-1, instance TSRMLS_CC);
11220 + zval_ptr_dtor(&instance);
11228 +/* {{{ Getters by type */
11229 +#define HTTP_QUERYSTRING_GETTER(method, TYPE) \
11230 +PHP_METHOD(HttpQueryString, method) \
11234 + zval *defval = NULL; \
11235 + zend_bool del = 0; \
11236 + if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|zb", &name, &name_len, &defval, &del)) { \
11237 + http_querystring_get(getThis(), TYPE, name, name_len, defval, del, return_value); \
11240 +HTTP_QUERYSTRING_GETTER(getBool, IS_BOOL);
11241 +HTTP_QUERYSTRING_GETTER(getInt, IS_LONG);
11242 +HTTP_QUERYSTRING_GETTER(getFloat, IS_DOUBLE);
11243 +HTTP_QUERYSTRING_GETTER(getString, IS_STRING);
11244 +HTTP_QUERYSTRING_GETTER(getArray, IS_ARRAY);
11245 +HTTP_QUERYSTRING_GETTER(getObject, IS_OBJECT);
11248 +#ifdef HTTP_HAVE_ICONV
11249 +/* {{{ proto bool HttpQueryString::xlate(string ie, string oe)
11250 + Converts the query string from the source encoding ie to the target encoding oe. WARNING: Don't use any character set that can contain NUL bytes like UTF-16. */
11251 +PHP_METHOD(HttpQueryString, xlate)
11254 + int ie_len, oe_len;
11255 + zval xa, *qa, *qs;
11258 + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &ie, &ie_len, &oe, &oe_len)) {
11262 + qa = zend_read_property(THIS_CE, getThis(), ZEND_STRS("queryArray")-1, 0 TSRMLS_CC);
11263 + qs = zend_read_property(THIS_CE, getThis(), ZEND_STRS("queryString")-1, 0 TSRMLS_CC);
11267 + if (SUCCESS == (rs = http_querystring_xlate(&xa, qa, ie, oe))) {
11268 + zend_hash_clean(Z_ARRVAL_P(qa));
11269 + zend_hash_copy(Z_ARRVAL_P(qa), Z_ARRVAL(xa), (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *));
11270 + http_querystring_update(qa, qs);
11274 + RETURN_SUCCESS(rs);
11277 +#endif /* HAVE_ICONV */
11279 +/* {{{ proto string HttpQueryString::serialize()
11280 + Implements Serializable::serialize(). */
11281 +PHP_METHOD(HttpQueryString, serialize)
11284 + RETURN_PROP(queryString);
11288 +/* {{{ proto void HttpQueryString::unserialize(string serialized)
11289 + Implements Serializable::unserialize(). */
11290 +PHP_METHOD(HttpQueryString, unserialize)
11292 + zval *serialized;
11294 + SET_EH_THROW_HTTP();
11295 + if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &serialized)) {
11296 + if (Z_TYPE_P(serialized) == IS_STRING) {
11297 + http_querystring_instantiate(getThis(), 0, serialized, 0);
11299 + http_error(HE_WARNING, HTTP_E_QUERYSTRING, "Expected a string as parameter");
11306 +/* {{{ proto mixed HttpQueryString::offsetGet(string offset)
11307 + Implements ArrayAccess::offsetGet(). */
11308 +PHP_METHOD(HttpQueryString, offsetGet)
11310 + char *offset_str;
11314 + if ( (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &offset_str, &offset_len)) &&
11315 + (SUCCESS == zend_hash_find(Z_ARRVAL_P(zend_read_property(THIS_CE, getThis(), ZEND_STRS("queryArray")-1, 0 TSRMLS_CC)), offset_str, offset_len + 1, (void *) &value))) {
11316 + RETVAL_ZVAL(*value, 1, 0);
11321 +/* {{{ proto void HttpQueryString::offsetSet(string offset, mixed value)
11322 + Implements ArrayAccess::offsetGet(). */
11323 +PHP_METHOD(HttpQueryString, offsetSet)
11325 + char *offset_str;
11329 + if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz", &offset_str, &offset_len, &value)) {
11330 + zval *qarr = zend_read_property(THIS_CE, getThis(), ZEND_STRS("queryArray")-1, 0 TSRMLS_CC), *qstr = zend_read_property(THIS_CE, getThis(), ZEND_STRS("queryString")-1, 0 TSRMLS_CC);
11332 + ZVAL_ADDREF(value);
11333 + add_assoc_zval_ex(qarr, offset_str, offset_len + 1, value);
11334 + http_querystring_update(qarr, qstr);
11339 +/* {{{ proto bool HttpQueryString::offsetExists(string offset)
11340 + Implements ArrayAccess::offsetExists(). */
11341 +PHP_METHOD(HttpQueryString, offsetExists)
11343 + char *offset_str;
11347 + if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &offset_str, &offset_len)) {
11348 + RETURN_BOOL((SUCCESS == zend_hash_find(Z_ARRVAL_P(zend_read_property(THIS_CE, getThis(), ZEND_STRS("queryArray")-1, 0 TSRMLS_CC)), offset_str, offset_len + 1, (void *) &value)) && (Z_TYPE_PP(value) != IS_NULL));
11353 +/* {{{ proto void HttpQueryString::offsetUnset(string offset)
11354 + Implements ArrayAccess::offsetUnset(). */
11355 +PHP_METHOD(HttpQueryString, offsetUnset)
11357 + char *offset_str;
11360 + if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &offset_str, &offset_len)) {
11361 + zval *qarr = zend_read_property(THIS_CE, getThis(), ZEND_STRS("queryArray")-1, 0 TSRMLS_CC);
11363 + if (SUCCESS == zend_hash_del(Z_ARRVAL_P(qarr), offset_str, offset_len + 1)) {
11364 + http_querystring_update(qarr, zend_read_property(THIS_CE, getThis(), ZEND_STRS("queryString")-1, 0 TSRMLS_CC));
11370 +#endif /* ZEND_ENGINE_2 */
11373 + * Local variables:
11375 + * c-basic-offset: 4
11377 + * vim600: noet sw=4 ts=4 fdm=marker
11378 + * vim<600: noet sw=4 ts=4
11382 +++ b/ext/http/http_request_api.c
11385 + +--------------------------------------------------------------------+
11387 + +--------------------------------------------------------------------+
11388 + | Redistribution and use in source and binary forms, with or without |
11389 + | modification, are permitted provided that the conditions mentioned |
11390 + | in the accompanying LICENSE file are met. |
11391 + +--------------------------------------------------------------------+
11392 + | Copyright (c) 2004-2010, Michael Wallner <mike@php.net> |
11393 + +--------------------------------------------------------------------+
11396 +/* $Id: http_request_api.c 310775 2011-05-05 06:02:50Z mike $ */
11398 +#define HTTP_WANT_SAPI
11399 +#define HTTP_WANT_CURL
11400 +#include "php_http.h"
11402 +#ifdef HTTP_HAVE_CURL
11404 +#include "php_http_api.h"
11405 +#include "php_http_persistent_handle_api.h"
11406 +#include "php_http_request_api.h"
11407 +#include "php_http_url_api.h"
11409 +#ifdef ZEND_ENGINE_2
11410 +# include "php_http_request_object.h"
11413 +#include "php_http_request_int.h"
11415 +/* {{{ cruft for thread safe SSL crypto locks */
11416 +#ifdef HTTP_NEED_OPENSSL_TSL
11417 +static MUTEX_T *http_openssl_tsl = NULL;
11419 +static void http_openssl_thread_lock(int mode, int n, const char * file, int line)
11421 + if (mode & CRYPTO_LOCK) {
11422 + tsrm_mutex_lock(http_openssl_tsl[n]);
11424 + tsrm_mutex_unlock(http_openssl_tsl[n]);
11428 +static ulong http_openssl_thread_id(void)
11430 + return (ulong) tsrm_thread_id();
11433 +#ifdef HTTP_NEED_GNUTLS_TSL
11434 +static int http_gnutls_mutex_create(void **m)
11436 + if (*((MUTEX_T *) m) = tsrm_mutex_alloc()) {
11443 +static int http_gnutls_mutex_destroy(void **m)
11445 + tsrm_mutex_free(*((MUTEX_T *) m));
11449 +static int http_gnutls_mutex_lock(void **m)
11451 + return tsrm_mutex_lock(*((MUTEX_T *) m));
11454 +static int http_gnutls_mutex_unlock(void **m)
11456 + return tsrm_mutex_unlock(*((MUTEX_T *) m));
11459 +static struct gcry_thread_cbs http_gnutls_tsl = {
11460 + GCRY_THREAD_OPTION_USER,
11462 + http_gnutls_mutex_create,
11463 + http_gnutls_mutex_destroy,
11464 + http_gnutls_mutex_lock,
11465 + http_gnutls_mutex_unlock
11470 +/* safe curl wrappers */
11471 +#define init_curl_storage(ch) \
11473 + http_request_storage *st = pecalloc(1, sizeof(http_request_storage), 1); \
11474 + curl_easy_setopt(ch, CURLOPT_PRIVATE, st); \
11475 + curl_easy_setopt(ch, CURLOPT_ERRORBUFFER, st->errorbuffer); \
11478 +static void *safe_curl_init(void)
11482 + if ((ch = curl_easy_init())) {
11483 + init_curl_storage(ch);
11488 +static void *safe_curl_copy(void *p)
11492 + if ((ch = curl_easy_duphandle(p))) {
11493 + init_curl_storage(ch);
11498 +static void safe_curl_dtor(void *p) {
11499 + http_request_storage *st = http_request_storage_get(p);
11501 + curl_easy_cleanup(p);
11505 + pefree(st->url, 1);
11507 + if (st->cookiestore) {
11508 + pefree(st->cookiestore, 1);
11516 +PHP_MINIT_FUNCTION(http_request)
11518 +#ifdef HTTP_NEED_OPENSSL_TSL
11519 + /* mod_ssl, libpq or ext/curl might already have set thread lock callbacks */
11520 + if (!CRYPTO_get_id_callback()) {
11521 + int i, c = CRYPTO_num_locks();
11523 + http_openssl_tsl = malloc(c * sizeof(MUTEX_T));
11525 + for (i = 0; i < c; ++i) {
11526 + http_openssl_tsl[i] = tsrm_mutex_alloc();
11529 + CRYPTO_set_id_callback(http_openssl_thread_id);
11530 + CRYPTO_set_locking_callback(http_openssl_thread_lock);
11533 +#ifdef HTTP_NEED_GNUTLS_TSL
11534 + gcry_control(GCRYCTL_SET_THREAD_CBS, &http_gnutls_tsl);
11537 + if (CURLE_OK != curl_global_init(CURL_GLOBAL_ALL)) {
11541 + if (SUCCESS != http_persistent_handle_provide("http_request", safe_curl_init, safe_curl_dtor, safe_curl_copy)) {
11545 + HTTP_LONG_CONSTANT("HTTP_AUTH_BASIC", CURLAUTH_BASIC);
11546 + HTTP_LONG_CONSTANT("HTTP_AUTH_DIGEST", CURLAUTH_DIGEST);
11547 +#if HTTP_CURL_VERSION(7,19,3)
11548 + HTTP_LONG_CONSTANT("HTTP_AUTH_DIGEST_IE", CURLAUTH_DIGEST_IE);
11550 + HTTP_LONG_CONSTANT("HTTP_AUTH_NTLM", CURLAUTH_NTLM);
11551 + HTTP_LONG_CONSTANT("HTTP_AUTH_GSSNEG", CURLAUTH_GSSNEGOTIATE);
11552 + HTTP_LONG_CONSTANT("HTTP_AUTH_ANY", CURLAUTH_ANY);
11554 + HTTP_LONG_CONSTANT("HTTP_VERSION_NONE", CURL_HTTP_VERSION_NONE); /* to be removed */
11555 + HTTP_LONG_CONSTANT("HTTP_VERSION_1_0", CURL_HTTP_VERSION_1_0);
11556 + HTTP_LONG_CONSTANT("HTTP_VERSION_1_1", CURL_HTTP_VERSION_1_1);
11557 + HTTP_LONG_CONSTANT("HTTP_VERSION_ANY", CURL_HTTP_VERSION_NONE);
11559 + HTTP_LONG_CONSTANT("HTTP_SSL_VERSION_TLSv1", CURL_SSLVERSION_TLSv1);
11560 + HTTP_LONG_CONSTANT("HTTP_SSL_VERSION_SSLv2", CURL_SSLVERSION_SSLv2);
11561 + HTTP_LONG_CONSTANT("HTTP_SSL_VERSION_SSLv3", CURL_SSLVERSION_SSLv3);
11562 + HTTP_LONG_CONSTANT("HTTP_SSL_VERSION_ANY", CURL_SSLVERSION_DEFAULT);
11564 + HTTP_LONG_CONSTANT("HTTP_IPRESOLVE_V4", CURL_IPRESOLVE_V4);
11565 + HTTP_LONG_CONSTANT("HTTP_IPRESOLVE_V6", CURL_IPRESOLVE_V6);
11566 + HTTP_LONG_CONSTANT("HTTP_IPRESOLVE_ANY", CURL_IPRESOLVE_WHATEVER);
11568 +#if HTTP_CURL_VERSION(7,15,2)
11569 + HTTP_LONG_CONSTANT("HTTP_PROXY_SOCKS4", CURLPROXY_SOCKS4);
11571 +#if HTTP_CURL_VERSION(7,18,0)
11572 + HTTP_LONG_CONSTANT("HTTP_PROXY_SOCKS4A", CURLPROXY_SOCKS4A);
11573 + HTTP_LONG_CONSTANT("HTTP_PROXY_SOCKS5_HOSTNAME", CURLPROXY_SOCKS5_HOSTNAME);
11575 + HTTP_LONG_CONSTANT("HTTP_PROXY_SOCKS5", CURLPROXY_SOCKS5);
11576 + HTTP_LONG_CONSTANT("HTTP_PROXY_HTTP", CURLPROXY_HTTP);
11577 +#if HTTP_CURL_VERSION(7,19,4)
11578 + HTTP_LONG_CONSTANT("HTTP_PROXY_HTTP_1_0", CURLPROXY_HTTP_1_0);
11581 +#if HTTP_CURL_VERSION(7,19,1)
11582 + HTTP_LONG_CONSTANT("HTTP_POSTREDIR_301", CURL_REDIR_POST_301);
11583 + HTTP_LONG_CONSTANT("HTTP_POSTREDIR_302", CURL_REDIR_POST_302);
11584 + HTTP_LONG_CONSTANT("HTTP_POSTREDIR_ALL", CURL_REDIR_POST_ALL);
11590 +/* {{{ MSHUTDOWN */
11591 +PHP_MSHUTDOWN_FUNCTION(http_request)
11593 + curl_global_cleanup();
11594 +#ifdef HTTP_NEED_OPENSSL_TSL
11595 + if (http_openssl_tsl) {
11596 + int i, c = CRYPTO_num_locks();
11598 + CRYPTO_set_id_callback(NULL);
11599 + CRYPTO_set_locking_callback(NULL);
11601 + for (i = 0; i < c; ++i) {
11602 + tsrm_mutex_free(http_openssl_tsl[i]);
11605 + free(http_openssl_tsl);
11606 + http_openssl_tsl = NULL;
11613 +/* {{{ forward declarations */
11614 +#define http_request_option(r, o, k, t) _http_request_option_ex((r), (o), (k), sizeof(k), (t) TSRMLS_CC)
11615 +#define http_request_option_ex(r, o, k, l, t) _http_request_option_ex((r), (o), (k), (l), (t) TSRMLS_CC)
11616 +static inline zval *_http_request_option_ex(http_request *request, HashTable *options, char *key, size_t keylen, int type TSRMLS_DC);
11617 +#define http_request_option_cache(r, k, z) _http_request_option_cache_ex((r), (k), sizeof(k), 0, (z) TSRMLS_CC)
11618 +#define http_request_option_cache_ex(r, k, kl, h, z) _http_request_option_cache_ex((r), (k), (kl), (h), (z) TSRMLS_CC)
11619 +static inline zval *_http_request_option_cache_ex(http_request *r, char *key, size_t keylen, ulong h, zval *opt TSRMLS_DC);
11621 +#define http_request_cookies_enabled(r) _http_request_cookies_enabled((r))
11622 +static inline int _http_request_cookies_enabled(http_request *r);
11624 +static size_t http_curl_read_callback(void *, size_t, size_t, void *);
11625 +static int http_curl_progress_callback(void *, double, double, double, double);
11626 +static int http_curl_raw_callback(CURL *, curl_infotype, char *, size_t, void *);
11627 +static int http_curl_dummy_callback(char *data, size_t n, size_t l, void *s) { return n*l; }
11628 +static curlioerr http_curl_ioctl_callback(CURL *, curliocmd, void *);
11631 +/* {{{ CURL *http_curl_init(http_request *) */
11632 +PHP_HTTP_API CURL * _http_curl_init_ex(CURL *ch, http_request *request TSRMLS_DC)
11634 + if (ch || (SUCCESS == http_persistent_handle_acquire("http_request", &ch))) {
11636 + curl_easy_setopt(ch, CURLOPT_NOSIGNAL, 1L);
11638 + curl_easy_setopt(ch, CURLOPT_HEADER, 0L);
11639 + curl_easy_setopt(ch, CURLOPT_FILETIME, 1L);
11640 + curl_easy_setopt(ch, CURLOPT_AUTOREFERER, 1L);
11641 + curl_easy_setopt(ch, CURLOPT_VERBOSE, 1L);
11642 + curl_easy_setopt(ch, CURLOPT_HEADERFUNCTION, NULL);
11643 + curl_easy_setopt(ch, CURLOPT_DEBUGFUNCTION, http_curl_raw_callback);
11644 + curl_easy_setopt(ch, CURLOPT_READFUNCTION, http_curl_read_callback);
11645 + curl_easy_setopt(ch, CURLOPT_IOCTLFUNCTION, http_curl_ioctl_callback);
11646 + curl_easy_setopt(ch, CURLOPT_WRITEFUNCTION, http_curl_dummy_callback);
11648 + /* set context */
11650 + curl_easy_setopt(ch, CURLOPT_DEBUGDATA, request);
11652 + /* attach curl handle */
11653 + request->ch = ch;
11654 + /* set defaults (also in http_request_reset()) */
11655 + http_request_defaults(request);
11663 +/* {{{ CURL *http_curl_copy(CURL *) */
11664 +PHP_HTTP_API CURL *_http_curl_copy(CURL *ch TSRMLS_DC)
11668 + if (SUCCESS == http_persistent_handle_accrete("http_request", ch, ©)) {
11675 +/* {{{ void http_curl_free(CURL **) */
11676 +PHP_HTTP_API void _http_curl_free(CURL **ch TSRMLS_DC)
11679 + curl_easy_setopt(*ch, CURLOPT_NOPROGRESS, 1L);
11680 + curl_easy_setopt(*ch, CURLOPT_PROGRESSFUNCTION, NULL);
11681 + curl_easy_setopt(*ch, CURLOPT_VERBOSE, 0L);
11682 + curl_easy_setopt(*ch, CURLOPT_DEBUGFUNCTION, NULL);
11684 + http_persistent_handle_release("http_request", ch);
11689 +/* {{{ http_request *http_request_init(http_request *) */
11690 +PHP_HTTP_API http_request *_http_request_init_ex(http_request *request, CURL *ch, http_request_method meth, const char *url ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC TSRMLS_DC)
11697 + r = emalloc_rel(sizeof(http_request));
11699 + memset(r, 0, sizeof(http_request));
11702 + r->url = (url) ? http_absolute_url(url) : NULL;
11703 + r->meth = (meth > 0) ? meth : HTTP_GET;
11705 + phpstr_init(&r->conv.request);
11706 + phpstr_init_ex(&r->conv.response, HTTP_CURLBUF_SIZE, 0);
11707 + phpstr_init(&r->_cache.cookies);
11708 + zend_hash_init(&r->_cache.options, 0, NULL, ZVAL_PTR_DTOR, 0);
11710 + TSRMLS_SET_CTX(r->tsrm_ls);
11716 +/* {{{ void http_request_dtor(http_request *) */
11717 +PHP_HTTP_API void _http_request_dtor(http_request *request)
11719 + TSRMLS_FETCH_FROM_CTX(request->tsrm_ls);
11721 + http_request_reset(request);
11722 + http_curl_free(&request->ch);
11724 + phpstr_dtor(&request->_cache.cookies);
11725 + zend_hash_destroy(&request->_cache.options);
11726 + if (request->_cache.headers) {
11727 + curl_slist_free_all(request->_cache.headers);
11728 + request->_cache.headers = NULL;
11730 + if (request->_progress_callback) {
11731 + zval_ptr_dtor(&request->_progress_callback);
11732 + request->_progress_callback = NULL;
11737 +/* {{{ void http_request_free(http_request **) */
11738 +PHP_HTTP_API void _http_request_free(http_request **request)
11741 + TSRMLS_FETCH_FROM_CTX((*request)->tsrm_ls);
11742 + http_request_body_free(&(*request)->body);
11743 + http_request_dtor(*request);
11750 +/* {{{ void http_request_reset(http_request *) */
11751 +PHP_HTTP_API void _http_request_reset(http_request *request)
11753 + TSRMLS_FETCH_FROM_CTX(request->tsrm_ls);
11754 + STR_SET(request->url, NULL);
11755 + request->conv.last_type = 0;
11756 + phpstr_dtor(&request->conv.request);
11757 + phpstr_dtor(&request->conv.response);
11758 + http_request_body_dtor(request->body);
11759 + http_request_defaults(request);
11761 + if (request->ch) {
11762 + http_request_storage *st = http_request_storage_get(request->ch);
11766 + pefree(st->url, 1);
11769 + if (st->cookiestore) {
11770 + pefree(st->cookiestore, 1);
11771 + st->cookiestore = NULL;
11773 + st->errorbuffer[0] = '\0';
11779 +/* {{{ STATUS http_request_enable_cookies(http_request *) */
11780 +PHP_HTTP_API STATUS _http_request_enable_cookies(http_request *request)
11782 + int initialized = 1;
11783 + TSRMLS_FETCH_FROM_CTX(request->tsrm_ls);
11785 + HTTP_CHECK_CURL_INIT(request->ch, http_curl_init_ex(request->ch, request), initialized = 0);
11786 + if (initialized && (http_request_cookies_enabled(request) || (CURLE_OK == curl_easy_setopt(request->ch, CURLOPT_COOKIEFILE, "")))) {
11789 + http_error(HE_WARNING, HTTP_E_REQUEST, "Could not enable cookies for this session");
11794 +/* {{{ STATUS http_request_reset_cookies(http_request *, int) */
11795 +PHP_HTTP_API STATUS _http_request_reset_cookies(http_request *request, int session_only)
11797 + int initialized = 1;
11798 + TSRMLS_FETCH_FROM_CTX(request->tsrm_ls);
11800 + HTTP_CHECK_CURL_INIT(request->ch, http_curl_init_ex(request->ch, request), initialized = 0);
11801 + if (initialized) {
11802 + if (!http_request_cookies_enabled(request)) {
11803 + if (SUCCESS != http_request_enable_cookies(request)) {
11807 + if (session_only) {
11808 +#if HTTP_CURL_VERSION(7,15,4)
11809 + if (CURLE_OK == curl_easy_setopt(request->ch, CURLOPT_COOKIELIST, "SESS")) {
11813 + http_error(HE_WARNING, HTTP_E_REQUEST, "Could not reset session cookies (need libcurl >= v7.15.4)");
11816 +#if HTTP_CURL_VERSION(7,14,1)
11817 + if (CURLE_OK == curl_easy_setopt(request->ch, CURLOPT_COOKIELIST, "ALL")) {
11821 + http_error(HE_WARNING, HTTP_E_REQUEST, "Could not reset cookies (need libcurl >= v7.14.1)");
11829 +PHP_HTTP_API STATUS _http_request_flush_cookies(http_request *request)
11831 + int initialized = 1;
11832 + TSRMLS_FETCH_FROM_CTX(request->tsrm_ls);
11834 + HTTP_CHECK_CURL_INIT(request->ch, http_curl_init_ex(request->ch, request), initialized = 0);
11835 + if (initialized) {
11836 + if (!http_request_cookies_enabled(request)) {
11839 +#if HTTP_CURL_VERSION(7,17,1)
11840 + if (CURLE_OK == curl_easy_setopt(request->ch, CURLOPT_COOKIELIST, "FLUSH")) {
11844 + http_error(HE_WARNING, HTTP_E_REQUEST, "Could not flush cookies (need libcurl >= v7.17.1)");
11850 +/* {{{ void http_request_defaults(http_request *) */
11851 +PHP_HTTP_API void _http_request_defaults(http_request *request)
11853 + if (request->ch) {
11854 + HTTP_CURL_OPT(CURLOPT_PROGRESSFUNCTION, NULL);
11855 + HTTP_CURL_OPT(CURLOPT_URL, NULL);
11856 + HTTP_CURL_OPT(CURLOPT_NOPROGRESS, 1L);
11857 +#if HTTP_CURL_VERSION(7,19,4)
11858 + HTTP_CURL_OPT(CURLOPT_NOPROXY, NULL);
11860 + HTTP_CURL_OPT(CURLOPT_PROXY, NULL);
11861 + HTTP_CURL_OPT(CURLOPT_PROXYPORT, 0L);
11862 + HTTP_CURL_OPT(CURLOPT_PROXYTYPE, 0L);
11863 + /* libcurl < 7.19.6 does not clear auth info with USERPWD set to NULL */
11864 +#if HTTP_CURL_VERSION(7,19,1)
11865 + HTTP_CURL_OPT(CURLOPT_PROXYUSERNAME, NULL);
11866 + HTTP_CURL_OPT(CURLOPT_PROXYPASSWORD, NULL);
11868 + HTTP_CURL_OPT(CURLOPT_PROXYAUTH, 0L);
11869 + HTTP_CURL_OPT(CURLOPT_HTTPPROXYTUNNEL, 0L);
11870 + HTTP_CURL_OPT(CURLOPT_DNS_CACHE_TIMEOUT, 60L);
11871 + HTTP_CURL_OPT(CURLOPT_IPRESOLVE, 0);
11872 + HTTP_CURL_OPT(CURLOPT_LOW_SPEED_LIMIT, 0L);
11873 + HTTP_CURL_OPT(CURLOPT_LOW_SPEED_TIME, 0L);
11874 +#if HTTP_CURL_VERSION(7,15,5)
11876 + HTTP_CURL_OPT(CURLOPT_MAX_SEND_SPEED_LARGE, (curl_off_t) 0);
11877 + HTTP_CURL_OPT(CURLOPT_MAX_RECV_SPEED_LARGE, (curl_off_t) 0);
11881 + HTTP_CURL_OPT(CURLOPT_MAXCONNECTS, 5L); */
11882 + HTTP_CURL_OPT(CURLOPT_FRESH_CONNECT, 0L);
11883 + HTTP_CURL_OPT(CURLOPT_FORBID_REUSE, 0L);
11884 + HTTP_CURL_OPT(CURLOPT_INTERFACE, NULL);
11885 + HTTP_CURL_OPT(CURLOPT_PORT, 0L);
11886 +#if HTTP_CURL_VERSION(7,19,0)
11887 + HTTP_CURL_OPT(CURLOPT_ADDRESS_SCOPE, 0L);
11889 +#if HTTP_CURL_VERSION(7,15,2)
11890 + HTTP_CURL_OPT(CURLOPT_LOCALPORT, 0L);
11891 + HTTP_CURL_OPT(CURLOPT_LOCALPORTRANGE, 0L);
11893 + /* libcurl < 7.19.6 does not clear auth info with USERPWD set to NULL */
11894 +#if HTTP_CURL_VERSION(7,19,1)
11895 + HTTP_CURL_OPT(CURLOPT_USERNAME, NULL);
11896 + HTTP_CURL_OPT(CURLOPT_PASSWORD, NULL);
11898 + HTTP_CURL_OPT(CURLOPT_HTTPAUTH, 0L);
11899 + HTTP_CURL_OPT(CURLOPT_ENCODING, NULL);
11900 +#if HTTP_CURL_VERSION(7,16,2)
11901 + /* we do this ourself anyway */
11902 + HTTP_CURL_OPT(CURLOPT_HTTP_CONTENT_DECODING, 0L);
11903 + HTTP_CURL_OPT(CURLOPT_HTTP_TRANSFER_DECODING, 0L);
11905 + HTTP_CURL_OPT(CURLOPT_FOLLOWLOCATION, 0L);
11906 +#if HTTP_CURL_VERSION(7,19,1)
11907 + HTTP_CURL_OPT(CURLOPT_POSTREDIR, 0L);
11908 +#elif HTTP_CURL_VERSION(7,17,1)
11909 + HTTP_CURL_OPT(CURLOPT_POST301, 0L);
11911 + HTTP_CURL_OPT(CURLOPT_UNRESTRICTED_AUTH, 0L);
11912 + HTTP_CURL_OPT(CURLOPT_REFERER, NULL);
11913 + HTTP_CURL_OPT(CURLOPT_USERAGENT, "PECL::HTTP/" PHP_HTTP_VERSION " (PHP/" PHP_VERSION ")");
11914 + HTTP_CURL_OPT(CURLOPT_HTTPHEADER, NULL);
11915 + HTTP_CURL_OPT(CURLOPT_COOKIE, NULL);
11916 + HTTP_CURL_OPT(CURLOPT_COOKIESESSION, 0L);
11917 + /* these options would enable curl's cookie engine by default which we don't want
11918 + HTTP_CURL_OPT(CURLOPT_COOKIEFILE, NULL);
11919 + HTTP_CURL_OPT(CURLOPT_COOKIEJAR, NULL); */
11920 +#if HTTP_CURL_VERSION(7,14,1)
11921 + HTTP_CURL_OPT(CURLOPT_COOKIELIST, NULL);
11923 + HTTP_CURL_OPT(CURLOPT_RANGE, NULL);
11924 + HTTP_CURL_OPT(CURLOPT_RESUME_FROM, 0L);
11925 + HTTP_CURL_OPT(CURLOPT_MAXFILESIZE, 0L);
11926 + HTTP_CURL_OPT(CURLOPT_TIMECONDITION, 0L);
11927 + HTTP_CURL_OPT(CURLOPT_TIMEVALUE, 0L);
11928 + HTTP_CURL_OPT(CURLOPT_TIMEOUT, 0L);
11929 + HTTP_CURL_OPT(CURLOPT_CONNECTTIMEOUT, 3);
11930 + HTTP_CURL_OPT(CURLOPT_SSLCERT, NULL);
11931 + HTTP_CURL_OPT(CURLOPT_SSLCERTTYPE, NULL);
11932 + HTTP_CURL_OPT(CURLOPT_SSLCERTPASSWD, NULL);
11933 + HTTP_CURL_OPT(CURLOPT_SSLKEY, NULL);
11934 + HTTP_CURL_OPT(CURLOPT_SSLKEYTYPE, NULL);
11935 + HTTP_CURL_OPT(CURLOPT_SSLKEYPASSWD, NULL);
11936 + HTTP_CURL_OPT(CURLOPT_SSLENGINE, NULL);
11937 + HTTP_CURL_OPT(CURLOPT_SSLVERSION, 0L);
11938 + HTTP_CURL_OPT(CURLOPT_SSL_VERIFYPEER, 0L);
11939 + HTTP_CURL_OPT(CURLOPT_SSL_VERIFYHOST, 0L);
11940 + HTTP_CURL_OPT(CURLOPT_SSL_CIPHER_LIST, NULL);
11941 +#if HTTP_CURL_VERSION(7,19,0)
11942 + HTTP_CURL_OPT(CURLOPT_ISSUERCERT, NULL);
11943 + #if defined(HTTP_HAVE_OPENSSL)
11944 + HTTP_CURL_OPT(CURLOPT_CRLFILE, NULL);
11947 +#if HTTP_CURL_VERSION(7,19,1) && defined(HTTP_HAVE_OPENSSL)
11948 + HTTP_CURL_OPT(CURLOPT_CERTINFO, NULL);
11950 +#ifdef HTTP_CURL_CAINFO
11951 + HTTP_CURL_OPT(CURLOPT_CAINFO, HTTP_CURL_CAINFO);
11953 + HTTP_CURL_OPT(CURLOPT_CAINFO, NULL);
11955 + HTTP_CURL_OPT(CURLOPT_CAPATH, NULL);
11956 + HTTP_CURL_OPT(CURLOPT_RANDOM_FILE, NULL);
11957 + HTTP_CURL_OPT(CURLOPT_EGDSOCKET, NULL);
11958 + HTTP_CURL_OPT(CURLOPT_POSTFIELDS, NULL);
11959 + HTTP_CURL_OPT(CURLOPT_POSTFIELDSIZE, 0L);
11960 + HTTP_CURL_OPT(CURLOPT_HTTPPOST, NULL);
11961 + HTTP_CURL_OPT(CURLOPT_IOCTLDATA, NULL);
11962 + HTTP_CURL_OPT(CURLOPT_READDATA, NULL);
11963 + HTTP_CURL_OPT(CURLOPT_INFILESIZE, 0L);
11964 + HTTP_CURL_OPT(CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_NONE);
11965 + HTTP_CURL_OPT(CURLOPT_CUSTOMREQUEST, NULL);
11966 + HTTP_CURL_OPT(CURLOPT_NOBODY, 0L);
11967 + HTTP_CURL_OPT(CURLOPT_POST, 0L);
11968 + HTTP_CURL_OPT(CURLOPT_UPLOAD, 0L);
11969 + HTTP_CURL_OPT(CURLOPT_HTTPGET, 1L);
11974 +PHP_HTTP_API void _http_request_set_progress_callback(http_request *request, zval *cb)
11976 + if (request->_progress_callback) {
11977 + zval_ptr_dtor(&request->_progress_callback);
11979 + if ((request->_progress_callback = cb)) {
11981 + HTTP_CURL_OPT(CURLOPT_NOPROGRESS, 0);
11982 + HTTP_CURL_OPT(CURLOPT_PROGRESSDATA, request);
11983 + HTTP_CURL_OPT(CURLOPT_PROGRESSFUNCTION, http_curl_progress_callback);
11985 + HTTP_CURL_OPT(CURLOPT_NOPROGRESS, 1);
11986 + HTTP_CURL_OPT(CURLOPT_PROGRESSDATA, NULL);
11987 + HTTP_CURL_OPT(CURLOPT_PROGRESSFUNCTION, NULL);
11991 +/* {{{ STATUS http_request_prepare(http_request *, HashTable *) */
11992 +PHP_HTTP_API STATUS _http_request_prepare(http_request *request, HashTable *options)
11995 + zend_bool range_req = 0;
11996 + http_request_storage *storage;
11998 + TSRMLS_FETCH_FROM_CTX(request->tsrm_ls);
12000 + HTTP_CHECK_CURL_INIT(request->ch, http_curl_init(request), return FAILURE);
12002 + if (!request->url) {
12005 + if (!(storage = http_request_storage_get(request->ch))) {
12008 + storage->errorbuffer[0] = '\0';
12009 + /* set options */
12010 + if (storage->url) {
12011 + pefree(storage->url, 1);
12013 + storage->url = pestrdup(request->url, 1);
12014 + HTTP_CURL_OPT(CURLOPT_URL, storage->url);
12016 + /* progress callback */
12017 + if ((zoption = http_request_option(request, options, "onprogress", -1))) {
12018 + http_request_set_progress_callback(request, zoption);
12022 + if ((zoption = http_request_option(request, options, "proxyhost", IS_STRING))) {
12023 + HTTP_CURL_OPT(CURLOPT_PROXY, Z_STRVAL_P(zoption));
12025 + if ((zoption = http_request_option(request, options, "proxytype", IS_LONG))) {
12026 + HTTP_CURL_OPT(CURLOPT_PROXYTYPE, Z_LVAL_P(zoption));
12029 + if ((zoption = http_request_option(request, options, "proxyport", IS_LONG))) {
12030 + HTTP_CURL_OPT(CURLOPT_PROXYPORT, Z_LVAL_P(zoption));
12033 + if ((zoption = http_request_option(request, options, "proxyauth", IS_STRING)) && Z_STRLEN_P(zoption)) {
12034 + HTTP_CURL_OPT(CURLOPT_PROXYUSERPWD, Z_STRVAL_P(zoption));
12036 + /* auth method */
12037 + if ((zoption = http_request_option(request, options, "proxyauthtype", IS_LONG))) {
12038 + HTTP_CURL_OPT(CURLOPT_PROXYAUTH, Z_LVAL_P(zoption));
12041 + if ((zoption = http_request_option(request, options, "proxytunnel", IS_BOOL)) && Z_BVAL_P(zoption)) {
12042 + HTTP_CURL_OPT(CURLOPT_HTTPPROXYTUNNEL, 1L);
12045 +#if HTTP_CURL_VERSION(7,19,4)
12046 + if ((zoption = http_request_option(request, options, "noproxy", IS_STRING))) {
12047 + HTTP_CURL_OPT(CURLOPT_NOPROXY, Z_STRVAL_P(zoption));
12052 + if ((zoption = http_request_option(request, options, "dns_cache_timeout", IS_LONG))) {
12053 + HTTP_CURL_OPT(CURLOPT_DNS_CACHE_TIMEOUT, Z_LVAL_P(zoption));
12055 + if ((zoption = http_request_option(request, options, "ipresolve", IS_LONG)) && Z_LVAL_P(zoption)) {
12056 + HTTP_CURL_OPT(CURLOPT_IPRESOLVE, Z_LVAL_P(zoption));
12060 + if ((zoption = http_request_option(request, options, "low_speed_limit", IS_LONG))) {
12061 + HTTP_CURL_OPT(CURLOPT_LOW_SPEED_LIMIT, Z_LVAL_P(zoption));
12063 + if ((zoption = http_request_option(request, options, "low_speed_time", IS_LONG))) {
12064 + HTTP_CURL_OPT(CURLOPT_LOW_SPEED_TIME, Z_LVAL_P(zoption));
12066 +#if HTTP_CURL_VERSION(7,15,5)
12068 + if ((zoption = http_request_option(request, options, "max_send_speed", IS_LONG))) {
12069 + HTTP_CURL_OPT(CURLOPT_MAX_SEND_SPEED_LARGE, (curl_off_t) Z_LVAL_P(zoption));
12071 + if ((zoption = http_request_option(request, options, "max_recv_speed", IS_LONG))) {
12072 + HTTP_CURL_OPT(CURLOPT_MAX_RECV_SPEED_LARGE, (curl_off_t) Z_LVAL_P(zoption));
12077 + if ((zoption = http_request_option(request, options, "maxconnects", IS_LONG))) {
12078 + HTTP_CURL_OPT(CURLOPT_MAXCONNECTS, Z_LVAL_P(zoption));
12080 + if ((zoption = http_request_option(request, options, "fresh_connect", IS_BOOL)) && Z_BVAL_P(zoption)) {
12081 + HTTP_CURL_OPT(CURLOPT_FRESH_CONNECT, 1L);
12083 + if ((zoption = http_request_option(request, options, "forbid_reuse", IS_BOOL)) && Z_BVAL_P(zoption)) {
12084 + HTTP_CURL_OPT(CURLOPT_FORBID_REUSE, 1L);
12087 + /* outgoing interface */
12088 + if ((zoption = http_request_option(request, options, "interface", IS_STRING))) {
12089 + HTTP_CURL_OPT(CURLOPT_INTERFACE, Z_STRVAL_P(zoption));
12091 +#if HTTP_CURL_VERSION(7,15,2)
12092 + if ((zoption = http_request_option(request, options, "portrange", IS_ARRAY))) {
12093 + zval **prs, **pre;
12095 + zend_hash_internal_pointer_reset(Z_ARRVAL_P(zoption));
12096 + if (SUCCESS == zend_hash_get_current_data(Z_ARRVAL_P(zoption), (void *) &prs)) {
12097 + zend_hash_move_forward(Z_ARRVAL_P(zoption));
12098 + if (SUCCESS == zend_hash_get_current_data(Z_ARRVAL_P(zoption), (void *) &pre)) {
12099 + zval *prs_cpy = http_zsep(IS_LONG, *prs);
12100 + zval *pre_cpy = http_zsep(IS_LONG, *pre);
12102 + if (Z_LVAL_P(prs_cpy) && Z_LVAL_P(pre_cpy)) {
12103 + HTTP_CURL_OPT(CURLOPT_LOCALPORT, MIN(Z_LVAL_P(prs_cpy), Z_LVAL_P(pre_cpy)));
12104 + HTTP_CURL_OPT(CURLOPT_LOCALPORTRANGE, labs(Z_LVAL_P(prs_cpy)-Z_LVAL_P(pre_cpy))+1L);
12106 + zval_ptr_dtor(&prs_cpy);
12107 + zval_ptr_dtor(&pre_cpy);
12114 + /* another port */
12115 + if ((zoption = http_request_option(request, options, "port", IS_LONG))) {
12116 + HTTP_CURL_OPT(CURLOPT_PORT, Z_LVAL_P(zoption));
12119 + /* RFC4007 zone_id */
12120 +#if HTTP_CURL_VERSION(7,19,0)
12121 + if ((zoption = http_request_option(request, options, "address_scope", IS_LONG))) {
12122 + HTTP_CURL_OPT(CURLOPT_ADDRESS_SCOPE, Z_LVAL_P(zoption));
12127 + if ((zoption = http_request_option(request, options, "httpauth", IS_STRING)) && Z_STRLEN_P(zoption)) {
12128 + HTTP_CURL_OPT(CURLOPT_USERPWD, Z_STRVAL_P(zoption));
12130 + if ((zoption = http_request_option(request, options, "httpauthtype", IS_LONG))) {
12131 + HTTP_CURL_OPT(CURLOPT_HTTPAUTH, Z_LVAL_P(zoption));
12134 + /* redirects, defaults to 0 */
12135 + if ((zoption = http_request_option(request, options, "redirect", IS_LONG))) {
12136 + HTTP_CURL_OPT(CURLOPT_FOLLOWLOCATION, Z_LVAL_P(zoption) ? 1L : 0L);
12137 + HTTP_CURL_OPT(CURLOPT_MAXREDIRS, Z_LVAL_P(zoption));
12138 + if ((zoption = http_request_option(request, options, "unrestrictedauth", IS_BOOL))) {
12139 + HTTP_CURL_OPT(CURLOPT_UNRESTRICTED_AUTH, Z_LVAL_P(zoption));
12141 +#if HTTP_CURL_VERSION(7,17,1)
12142 + if ((zoption = http_request_option(request, options, "postredir", IS_BOOL))) {
12143 +# if HTTP_CURL_VERSION(7,19,1)
12144 + HTTP_CURL_OPT(CURLOPT_POSTREDIR, Z_BVAL_P(zoption) ? 1L : 0L);
12146 + HTTP_CURL_OPT(CURLOPT_POST301, Z_BVAL_P(zoption) ? 1L : 0L);
12152 + /* retries, defaults to 0 */
12153 + if ((zoption = http_request_option(request, options, "retrycount", IS_LONG))) {
12154 + request->_retry.count = Z_LVAL_P(zoption);
12155 + if ((zoption = http_request_option(request, options, "retrydelay", IS_DOUBLE))) {
12156 + request->_retry.delay = Z_DVAL_P(zoption);
12158 + request->_retry.delay = 0;
12161 + request->_retry.count = 0;
12165 + if ((zoption = http_request_option(request, options, "referer", IS_STRING)) && Z_STRLEN_P(zoption)) {
12166 + HTTP_CURL_OPT(CURLOPT_REFERER, Z_STRVAL_P(zoption));
12169 + /* useragent, default "PECL::HTTP/version (PHP/version)" */
12170 + if ((zoption = http_request_option(request, options, "useragent", IS_STRING))) {
12171 + /* allow to send no user agent, not even default one */
12172 + if (Z_STRLEN_P(zoption)) {
12173 + HTTP_CURL_OPT(CURLOPT_USERAGENT, Z_STRVAL_P(zoption));
12175 + HTTP_CURL_OPT(CURLOPT_USERAGENT, NULL);
12180 + if ((zoption = http_request_option(request, options, "resume", IS_LONG)) && (Z_LVAL_P(zoption) > 0)) {
12182 + HTTP_CURL_OPT(CURLOPT_RESUME_FROM, Z_LVAL_P(zoption));
12184 + /* or range of kind array(array(0,499), array(100,1499)) */
12185 + else if ((zoption = http_request_option(request, options, "range", IS_ARRAY)) && zend_hash_num_elements(Z_ARRVAL_P(zoption))) {
12186 + HashPosition pos1, pos2;
12187 + zval **rr, **rb, **re;
12190 + phpstr_init(&rs);
12191 + FOREACH_VAL(pos1, zoption, rr) {
12192 + if (Z_TYPE_PP(rr) == IS_ARRAY) {
12193 + zend_hash_internal_pointer_reset_ex(Z_ARRVAL_PP(rr), &pos2);
12194 + if (SUCCESS == zend_hash_get_current_data_ex(Z_ARRVAL_PP(rr), (void *) &rb, &pos2)) {
12195 + zend_hash_move_forward_ex(Z_ARRVAL_PP(rr), &pos2);
12196 + if (SUCCESS == zend_hash_get_current_data_ex(Z_ARRVAL_PP(rr), (void *) &re, &pos2)) {
12197 + if ( ((Z_TYPE_PP(rb) == IS_LONG) || ((Z_TYPE_PP(rb) == IS_STRING) && is_numeric_string(Z_STRVAL_PP(rb), Z_STRLEN_PP(rb), NULL, NULL, 1))) &&
12198 + ((Z_TYPE_PP(re) == IS_LONG) || ((Z_TYPE_PP(re) == IS_STRING) && is_numeric_string(Z_STRVAL_PP(re), Z_STRLEN_PP(re), NULL, NULL, 1)))) {
12199 + zval *rbl = http_zsep(IS_LONG, *rb);
12200 + zval *rel = http_zsep(IS_LONG, *re);
12202 + if ((Z_LVAL_P(rbl) >= 0) && (Z_LVAL_P(rel) >= 0)) {
12203 + phpstr_appendf(&rs, "%ld-%ld,", Z_LVAL_P(rbl), Z_LVAL_P(rel));
12205 + zval_ptr_dtor(&rbl);
12206 + zval_ptr_dtor(&rel);
12213 + if (PHPSTR_LEN(&rs)) {
12214 + zval *cached_range;
12216 + /* ditch last comma */
12217 + PHPSTR_VAL(&rs)[PHPSTR_LEN(&rs)-- -1] = '\0';
12218 + /* cache string */
12219 + MAKE_STD_ZVAL(cached_range);
12220 + ZVAL_STRINGL(cached_range, PHPSTR_VAL(&rs), PHPSTR_LEN(&rs), 0);
12221 + HTTP_CURL_OPT(CURLOPT_RANGE, Z_STRVAL_P(http_request_option_cache(request, "range", cached_range)));
12222 + zval_ptr_dtor(&cached_range);
12226 + /* additional headers, array('name' => 'value') */
12227 + if (request->_cache.headers) {
12228 + curl_slist_free_all(request->_cache.headers);
12229 + request->_cache.headers = NULL;
12231 + if ((zoption = http_request_option(request, options, "headers", IS_ARRAY))) {
12232 + HashKey header_key = initHashKey(0);
12233 + zval **header_val;
12234 + HashPosition pos;
12237 + phpstr_init(&header);
12238 + FOREACH_KEYVAL(pos, zoption, header_key, header_val) {
12239 + if (header_key.type == HASH_KEY_IS_STRING) {
12240 + zval *header_cpy = http_zsep(IS_STRING, *header_val);
12242 + if (!strcasecmp(header_key.str, "range")) {
12246 + phpstr_appendf(&header, "%s: %s", header_key.str, Z_STRVAL_P(header_cpy));
12247 + phpstr_fix(&header);
12248 + request->_cache.headers = curl_slist_append(request->_cache.headers, PHPSTR_VAL(&header));
12249 + phpstr_reset(&header);
12251 + zval_ptr_dtor(&header_cpy);
12254 + phpstr_dtor(&header);
12257 + if ((zoption = http_request_option(request, options, "etag", IS_STRING)) && Z_STRLEN_P(zoption)) {
12258 + zend_bool is_quoted = !((Z_STRVAL_P(zoption)[0] != '"') || (Z_STRVAL_P(zoption)[Z_STRLEN_P(zoption)-1] != '"'));
12261 + phpstr_init(&header);
12262 + phpstr_appendf(&header, is_quoted?"%s: %s":"%s: \"%s\"", range_req?"If-Match":"If-None-Match", Z_STRVAL_P(zoption));
12263 + phpstr_fix(&header);
12264 + request->_cache.headers = curl_slist_append(request->_cache.headers, PHPSTR_VAL(&header));
12265 + phpstr_dtor(&header);
12267 + /* compression */
12268 + if ((zoption = http_request_option(request, options, "compress", IS_BOOL)) && Z_LVAL_P(zoption)) {
12269 + request->_cache.headers = curl_slist_append(request->_cache.headers, "Accept-Encoding: gzip;q=1.0,deflate;q=0.5");
12271 + HTTP_CURL_OPT(CURLOPT_HTTPHEADER, request->_cache.headers);
12273 + /* lastmodified */
12274 + if ((zoption = http_request_option(request, options, "lastmodified", IS_LONG))) {
12275 + if (Z_LVAL_P(zoption)) {
12276 + if (Z_LVAL_P(zoption) > 0) {
12277 + HTTP_CURL_OPT(CURLOPT_TIMEVALUE, Z_LVAL_P(zoption));
12279 + HTTP_CURL_OPT(CURLOPT_TIMEVALUE, (long) HTTP_G->request.time + Z_LVAL_P(zoption));
12281 + HTTP_CURL_OPT(CURLOPT_TIMECONDITION, (long) (range_req ? CURL_TIMECOND_IFUNMODSINCE : CURL_TIMECOND_IFMODSINCE));
12283 + HTTP_CURL_OPT(CURLOPT_TIMECONDITION, CURL_TIMECOND_NONE);
12287 + /* cookies, array('name' => 'value') */
12288 + if ((zoption = http_request_option(request, options, "cookies", IS_ARRAY))) {
12289 + phpstr_dtor(&request->_cache.cookies);
12290 + if (zend_hash_num_elements(Z_ARRVAL_P(zoption))) {
12291 + zval *urlenc_cookies = NULL;
12292 + /* check whether cookies should not be urlencoded; default is to urlencode them */
12293 + if ((!(urlenc_cookies = http_request_option(request, options, "encodecookies", IS_BOOL))) || Z_BVAL_P(urlenc_cookies)) {
12294 + if (SUCCESS == http_urlencode_hash_recursive(HASH_OF(zoption), &request->_cache.cookies, "; ", lenof("; "), NULL, 0)) {
12295 + phpstr_fix(&request->_cache.cookies);
12296 + HTTP_CURL_OPT(CURLOPT_COOKIE, request->_cache.cookies.data);
12299 + HashPosition pos;
12300 + HashKey cookie_key = initHashKey(0);
12301 + zval **cookie_val;
12303 + FOREACH_KEYVAL(pos, zoption, cookie_key, cookie_val) {
12304 + if (cookie_key.type == HASH_KEY_IS_STRING) {
12305 + zval *val = http_zsep(IS_STRING, *cookie_val);
12306 + phpstr_appendf(&request->_cache.cookies, "%s=%s; ", cookie_key.str, Z_STRVAL_P(val));
12307 + zval_ptr_dtor(&val);
12311 + phpstr_fix(&request->_cache.cookies);
12312 + if (PHPSTR_LEN(&request->_cache.cookies)) {
12313 + HTTP_CURL_OPT(CURLOPT_COOKIE, PHPSTR_VAL(&request->_cache.cookies));
12319 + /* don't load session cookies from cookiestore */
12320 + if ((zoption = http_request_option(request, options, "cookiesession", IS_BOOL)) && Z_BVAL_P(zoption)) {
12321 + HTTP_CURL_OPT(CURLOPT_COOKIESESSION, 1L);
12324 + /* cookiestore, read initial cookies from that file and store cookies back into that file */
12325 + if ((zoption = http_request_option(request, options, "cookiestore", IS_STRING))) {
12326 + if (Z_STRLEN_P(zoption)) {
12327 + HTTP_CHECK_OPEN_BASEDIR(Z_STRVAL_P(zoption), return FAILURE);
12329 + if (storage->cookiestore) {
12330 + pefree(storage->cookiestore, 1);
12332 + storage->cookiestore = pestrndup(Z_STRVAL_P(zoption), Z_STRLEN_P(zoption), 1);
12333 + HTTP_CURL_OPT(CURLOPT_COOKIEFILE, storage->cookiestore);
12334 + HTTP_CURL_OPT(CURLOPT_COOKIEJAR, storage->cookiestore);
12337 + /* maxfilesize */
12338 + if ((zoption = http_request_option(request, options, "maxfilesize", IS_LONG))) {
12339 + HTTP_CURL_OPT(CURLOPT_MAXFILESIZE, Z_LVAL_P(zoption));
12342 + /* http protocol */
12343 + if ((zoption = http_request_option(request, options, "protocol", IS_LONG))) {
12344 + HTTP_CURL_OPT(CURLOPT_HTTP_VERSION, Z_LVAL_P(zoption));
12347 +#if HTTP_CURL_VERSION(7,16,2)
12348 + /* timeout, defaults to 0 */
12349 + if ((zoption = http_request_option(request, options, "timeout", IS_DOUBLE))) {
12350 + HTTP_CURL_OPT(CURLOPT_TIMEOUT_MS, (long)(Z_DVAL_P(zoption)*1000));
12352 + /* connecttimeout, defaults to 0 */
12353 + if ((zoption = http_request_option(request, options, "connecttimeout", IS_DOUBLE))) {
12354 + HTTP_CURL_OPT(CURLOPT_CONNECTTIMEOUT_MS, (long)(Z_DVAL_P(zoption)*1000));
12357 + /* timeout, defaults to 0 */
12358 + if ((zoption = http_request_option(request, options, "timeout", IS_LONG))) {
12359 + HTTP_CURL_OPT(CURLOPT_TIMEOUT, Z_LVAL_P(zoption));
12361 + /* connecttimeout, defaults to 0 */
12362 + if ((zoption = http_request_option(request, options, "connecttimeout", IS_LONG))) {
12363 + HTTP_CURL_OPT(CURLOPT_CONNECTTIMEOUT, Z_LVAL_P(zoption));
12368 + if ((zoption = http_request_option(request, options, "ssl", IS_ARRAY))) {
12369 + HashKey key = initHashKey(0);
12371 + HashPosition pos;
12373 + FOREACH_KEYVAL(pos, zoption, key, param) {
12374 + if (key.type == HASH_KEY_IS_STRING) {
12375 + HTTP_CURL_OPT_STRING(CURLOPT_SSLCERT, 0, 1);
12376 + HTTP_CURL_OPT_STRING(CURLOPT_SSLCERTTYPE, 0, 0);
12377 + HTTP_CURL_OPT_STRING(CURLOPT_SSLCERTPASSWD, 0, 0);
12379 + HTTP_CURL_OPT_STRING(CURLOPT_SSLKEY, 0, 0);
12380 + HTTP_CURL_OPT_STRING(CURLOPT_SSLKEYTYPE, 0, 0);
12381 + HTTP_CURL_OPT_STRING(CURLOPT_SSLKEYPASSWD, 0, 0);
12383 + HTTP_CURL_OPT_STRING(CURLOPT_SSLENGINE, 0, 0);
12384 + HTTP_CURL_OPT_LONG(CURLOPT_SSLVERSION, 0);
12386 + HTTP_CURL_OPT_LONG(CURLOPT_SSL_VERIFYPEER, 1);
12387 + HTTP_CURL_OPT_LONG(CURLOPT_SSL_VERIFYHOST, 1);
12388 + HTTP_CURL_OPT_STRING(CURLOPT_SSL_CIPHER_LIST, 1, 0);
12390 + HTTP_CURL_OPT_STRING(CURLOPT_CAINFO, -3, 1);
12391 + HTTP_CURL_OPT_STRING(CURLOPT_CAPATH, -3, 1);
12392 + HTTP_CURL_OPT_STRING(CURLOPT_RANDOM_FILE, -3, 1);
12393 + HTTP_CURL_OPT_STRING(CURLOPT_EGDSOCKET, -3, 1);
12394 +#if HTTP_CURL_VERSION(7,19,0)
12395 + HTTP_CURL_OPT_STRING(CURLOPT_ISSUERCERT, -3, 1);
12396 + #if defined(HTTP_HAVE_OPENSSL)
12397 + HTTP_CURL_OPT_STRING(CURLOPT_CRLFILE, -3, 1);
12400 +#if HTTP_CURL_VERSION(7,19,1) && defined(HTTP_HAVE_OPENSSL)
12401 + HTTP_CURL_OPT_LONG(CURLOPT_CERTINFO, -3);
12407 + /* request method */
12408 + switch (request->meth) {
12410 + HTTP_CURL_OPT(CURLOPT_HTTPGET, 1L);
12414 + HTTP_CURL_OPT(CURLOPT_NOBODY, 1L);
12418 + HTTP_CURL_OPT(CURLOPT_POST, 1L);
12422 + HTTP_CURL_OPT(CURLOPT_UPLOAD, 1L);
12426 + if (http_request_method_exists(0, request->meth, NULL)) {
12427 + HTTP_CURL_OPT(CURLOPT_CUSTOMREQUEST, http_request_method_name(request->meth));
12429 + http_error_ex(HE_WARNING, HTTP_E_REQUEST_METHOD, "Unsupported request method: %d (%s)", request->meth, request->url);
12435 + /* attach request body */
12436 + if (request->body && (request->meth != HTTP_GET) && (request->meth != HTTP_HEAD) && (request->meth != HTTP_OPTIONS)) {
12437 + switch (request->body->type) {
12438 + case HTTP_REQUEST_BODY_EMPTY:
12442 + case HTTP_REQUEST_BODY_CURLPOST:
12443 + HTTP_CURL_OPT(CURLOPT_HTTPPOST, (struct curl_httppost *) request->body->data);
12446 + case HTTP_REQUEST_BODY_CSTRING:
12447 + if (request->meth != HTTP_PUT) {
12448 + HTTP_CURL_OPT(CURLOPT_POSTFIELDS, request->body->data);
12449 + HTTP_CURL_OPT(CURLOPT_POSTFIELDSIZE, request->body->size);
12452 + /* fallthrough, PUT/UPLOAD _needs_ READDATA */
12453 + case HTTP_REQUEST_BODY_UPLOADFILE:
12454 + HTTP_CURL_OPT(CURLOPT_IOCTLDATA, request);
12455 + HTTP_CURL_OPT(CURLOPT_READDATA, request);
12456 + HTTP_CURL_OPT(CURLOPT_INFILESIZE, request->body->size);
12460 + /* shouldn't ever happen */
12461 + http_error_ex(HE_ERROR, 0, "Unknown request body type: %d (%s)", request->body->type, request->url);
12470 +/* {{{ void http_request_exec(http_request *) */
12471 +PHP_HTTP_API void _http_request_exec(http_request *request)
12475 + TSRMLS_FETCH_FROM_CTX(request->tsrm_ls);
12478 + if (CURLE_OK != (result = curl_easy_perform(request->ch))) {
12479 + http_error_ex(HE_WARNING, HTTP_E_REQUEST, "%s; %s (%s)", curl_easy_strerror(result), http_request_storage_get(request->ch)->errorbuffer, request->url);
12480 +#ifdef ZEND_ENGINE_2
12481 + if ((HTTP_G->only_exceptions || GLOBAL_ERROR_HANDLING == EH_THROW) && EG(exception)) {
12482 + add_property_long(EG(exception), "curlCode", result);
12486 + if (request->_retry.count > tries++) {
12487 + switch (result) {
12488 + case CURLE_COULDNT_RESOLVE_PROXY:
12489 + case CURLE_COULDNT_RESOLVE_HOST:
12490 + case CURLE_COULDNT_CONNECT:
12491 + case CURLE_WRITE_ERROR:
12492 + case CURLE_READ_ERROR:
12493 + case CURLE_OPERATION_TIMEDOUT:
12494 + case CURLE_SSL_CONNECT_ERROR:
12495 + case CURLE_GOT_NOTHING:
12496 + case CURLE_SSL_ENGINE_SETFAILED:
12497 + case CURLE_SEND_ERROR:
12498 + case CURLE_RECV_ERROR:
12499 + case CURLE_SSL_ENGINE_INITFAILED:
12500 + case CURLE_LOGIN_DENIED:
12501 + if (request->_retry.delay >= HTTP_DIFFSEC) {
12502 + http_sleep(request->_retry.delay);
12513 +/* {{{ static size_t http_curl_read_callback(void *, size_t, size_t, void *) */
12514 +static size_t http_curl_read_callback(void *data, size_t len, size_t n, void *ctx)
12516 + http_request *request = (http_request *) ctx;
12517 + TSRMLS_FETCH_FROM_CTX(request->tsrm_ls);
12519 + if (request->body) {
12520 + switch (request->body->type) {
12521 + case HTTP_REQUEST_BODY_CSTRING:
12523 + size_t out = MIN(len * n, request->body->size - request->body->priv);
12526 + memcpy(data, ((char *) request->body->data) + request->body->priv, out);
12527 + request->body->priv += out;
12533 + case HTTP_REQUEST_BODY_UPLOADFILE:
12534 + return php_stream_read((php_stream *) request->body->data, data, len * n);
12541 +/* {{{ static int http_curl_progress_callback(void *, double, double, double, double) */
12542 +static int http_curl_progress_callback(void *ctx, double dltotal, double dlnow, double ultotal, double ulnow)
12544 + zval *param, retval;
12545 + http_request *request = (http_request *) ctx;
12546 + TSRMLS_FETCH_FROM_CTX(request->tsrm_ls);
12548 + INIT_PZVAL(&retval);
12549 + ZVAL_NULL(&retval);
12551 + MAKE_STD_ZVAL(param);
12552 + array_init(param);
12553 + add_assoc_double(param, "dltotal", dltotal);
12554 + add_assoc_double(param, "dlnow", dlnow);
12555 + add_assoc_double(param, "ultotal", ultotal);
12556 + add_assoc_double(param, "ulnow", ulnow);
12558 + with_error_handling(EH_NORMAL, NULL) {
12559 + request->_in_progress_cb = 1;
12560 + call_user_function(EG(function_table), NULL, request->_progress_callback, &retval, 1, ¶m TSRMLS_CC);
12561 + request->_in_progress_cb = 0;
12562 + } end_error_handling();
12564 + zval_ptr_dtor(¶m);
12565 + zval_dtor(&retval);
12571 +/* {{{ static curlioerr http_curl_ioctl_callback(CURL *, curliocmd, void *) */
12572 +static curlioerr http_curl_ioctl_callback(CURL *ch, curliocmd cmd, void *ctx)
12574 + http_request *request = (http_request *) ctx;
12575 + TSRMLS_FETCH_FROM_CTX(request->tsrm_ls);
12577 + if (cmd != CURLIOCMD_RESTARTREAD) {
12578 + return CURLIOE_UNKNOWNCMD;
12581 + if (request->body) {
12582 + switch (request->body->type) {
12583 + case HTTP_REQUEST_BODY_CSTRING:
12584 + request->body->priv = 0;
12585 + return CURLIOE_OK;
12588 + case HTTP_REQUEST_BODY_UPLOADFILE:
12589 + if (SUCCESS == php_stream_rewind((php_stream *) request->body->data)) {
12590 + return CURLIOE_OK;
12596 + return CURLIOE_FAILRESTART;
12600 +/* {{{ static int http_curl_raw_callback(CURL *, curl_infotype, char *, size_t, void *) */
12601 +static int http_curl_raw_callback(CURL *ch, curl_infotype type, char *data, size_t length, void *ctx)
12603 + http_request *request = (http_request *) ctx;
12605 +#define EMPTY_HEADER(d, l) (!l || (l == 1 && d[0] == '\n') || (l == 2 && d[0] == '\r' && d[1] == '\n'))
12607 + case CURLINFO_DATA_IN:
12608 + if (request->conv.last_type == CURLINFO_HEADER_IN) {
12609 + phpstr_appends(&request->conv.response, HTTP_CRLF);
12611 + phpstr_append(&request->conv.response, data, length);
12613 + case CURLINFO_HEADER_IN:
12614 + if (!EMPTY_HEADER(data, length)) {
12615 + phpstr_append(&request->conv.response, data, length);
12618 + case CURLINFO_DATA_OUT:
12619 + case CURLINFO_HEADER_OUT:
12620 + phpstr_append(&request->conv.request, data, length);
12628 + const char _sym[] = "><><><";
12630 + for (fprintf(stderr, "%c ", _sym[type-1]); length--; data++) {
12631 + fprintf(stderr, HTTP_IS_CTYPE(print, *data)?"%c":"\\x%02X", (int) *data);
12632 + if (*data == '\n' && length) {
12633 + fprintf(stderr, "\n%c ", _sym[type-1]);
12636 + fprintf(stderr, "\n");
12638 + fprintf(stderr, "# %s", data);
12644 + request->conv.last_type = type;
12650 +/* {{{ static inline zval *http_request_option(http_request *, HashTable *, char *, size_t, int) */
12651 +static inline zval *_http_request_option_ex(http_request *r, HashTable *options, char *key, size_t keylen, int type TSRMLS_DC)
12655 + ulong h = zend_hash_func(key, keylen);
12657 + if (SUCCESS == zend_hash_quick_find(options, key, keylen, h, (void *) &zoption)) {
12658 + zval *option, *cached;
12660 + option = http_zsep(type, *zoption);
12661 + cached = http_request_option_cache_ex(r, key, keylen, h, option);
12663 + zval_ptr_dtor(&option);
12672 +/* {{{ static inline zval *http_request_option_cache(http_request *, char *key, zval *) */
12673 +static inline zval *_http_request_option_cache_ex(http_request *r, char *key, size_t keylen, ulong h, zval *opt TSRMLS_DC)
12675 + ZVAL_ADDREF(opt);
12678 + zend_hash_quick_update(&r->_cache.options, key, keylen, h, &opt, sizeof(zval *), NULL);
12680 + zend_hash_update(&r->_cache.options, key, keylen, &opt, sizeof(zval *), NULL);
12687 +/* {{{ static inline int http_request_cookies_enabled(http_request *) */
12688 +static inline int _http_request_cookies_enabled(http_request *request) {
12689 + http_request_storage *st;
12691 + if (request->ch && (st = http_request_storage_get(request->ch)) && st->cookiestore) {
12692 + /* cookies are enabled */
12699 +#endif /* HTTP_HAVE_CURL */
12702 + * Local variables:
12704 + * c-basic-offset: 4
12706 + * vim600: noet sw=4 ts=4 fdm=marker
12707 + * vim<600: noet sw=4 ts=4
12711 +++ b/ext/http/http_request_body_api.c
12714 + +--------------------------------------------------------------------+
12716 + +--------------------------------------------------------------------+
12717 + | Redistribution and use in source and binary forms, with or without |
12718 + | modification, are permitted provided that the conditions mentioned |
12719 + | in the accompanying LICENSE file are met. |
12720 + +--------------------------------------------------------------------+
12721 + | Copyright (c) 2004-2010, Michael Wallner <mike@php.net> |
12722 + +--------------------------------------------------------------------+
12725 +/* $Id: http_request_body_api.c 292841 2009-12-31 08:48:57Z mike $ */
12727 +#define HTTP_WANT_CURL
12728 +#include "php_http.h"
12730 +#ifdef HTTP_HAVE_CURL
12732 +#include "php_http_api.h"
12733 +#include "php_http_url_api.h"
12734 +#include "php_http_request_body_api.h"
12737 +typedef struct curl_httppost *post_data[2];
12738 +static STATUS recursive_fields(post_data http_post_data, HashTable *fields, const char *prefix TSRMLS_DC);
12739 +static STATUS recursive_files(post_data http_post_data, HashTable *files, const char *prefix TSRMLS_DC);
12742 +/* {{{ http_request_body *http_request_body_new() */
12743 +PHP_HTTP_API http_request_body *_http_request_body_init_ex(http_request_body *body, int type, void *data, size_t size, zend_bool free ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC TSRMLS_DC)
12746 + body = emalloc_rel(sizeof(http_request_body));
12749 + body->type = type;
12750 + body->free = free;
12752 + body->data = data;
12753 + body->size = size;
12759 +/* {{{ http_request_body *http_request_body_fill(http_request_body *body, HashTable *, HashTable *) */
12760 +PHP_HTTP_API http_request_body *_http_request_body_fill(http_request_body *body, HashTable *fields, HashTable *files ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC TSRMLS_DC)
12762 + if (files && (zend_hash_num_elements(files) > 0)) {
12763 + struct curl_httppost *http_post_data[2] = {NULL, NULL};
12765 + if (fields && SUCCESS != recursive_fields(http_post_data, fields, NULL TSRMLS_CC)) {
12768 + if (SUCCESS != recursive_files(http_post_data, files, NULL TSRMLS_CC)) {
12771 + return http_request_body_init_rel(body, HTTP_REQUEST_BODY_CURLPOST, http_post_data[0], 0, 1);
12772 + } else if (fields) {
12774 + size_t encoded_len;
12776 + if (SUCCESS != http_urlencode_hash_ex(fields, 1, NULL, 0, &encoded, &encoded_len)) {
12777 + http_error(HE_WARNING, HTTP_E_ENCODING, "Could not encode post data");
12781 + return http_request_body_init_rel(body, HTTP_REQUEST_BODY_CSTRING, encoded, encoded_len, 1);
12783 + return http_request_body_init_rel(body, HTTP_REQUEST_BODY_CSTRING, estrndup("", 0), 0, 1);
12787 +/* STATUS http_request_body_encode(http_request_body *, char**, size_t *) */
12788 +PHP_HTTP_API STATUS _http_request_body_encode(http_request_body *body, char **buf, size_t *len TSRMLS_DC)
12790 + switch (body->type) {
12791 + case HTTP_REQUEST_BODY_CURLPOST:
12793 +#ifdef HAVE_CURL_FORMGET
12796 + phpstr_init_ex(&str, 0x8000, 0);
12797 + if (curl_formget(body->data, &str, (curl_formget_callback) phpstr_append)) {
12798 + phpstr_dtor(&str);
12800 + phpstr_fix(&str);
12801 + *buf = PHPSTR_VAL(&str);
12802 + *len = PHPSTR_LEN(&str);
12809 + case HTTP_REQUEST_BODY_CSTRING:
12810 + *buf = estrndup(body->data, *len = body->size);
12820 +/* {{{ void http_request_body_dtor(http_request_body *) */
12821 +PHP_HTTP_API void _http_request_body_dtor(http_request_body *body TSRMLS_DC)
12824 + if (body->free) {
12825 + switch (body->type) {
12826 + case HTTP_REQUEST_BODY_CSTRING:
12827 + if (body->data) {
12828 + efree(body->data);
12832 + case HTTP_REQUEST_BODY_CURLPOST:
12833 + curl_formfree(body->data);
12836 + case HTTP_REQUEST_BODY_UPLOADFILE:
12837 + php_stream_close(body->data);
12841 + memset(body, 0, sizeof(http_request_body));
12846 +/* {{{ void http_request_body_free(http_request_body *) */
12847 +PHP_HTTP_API void _http_request_body_free(http_request_body **body TSRMLS_DC)
12850 + http_request_body_dtor(*body);
12857 +static inline char *format_key(uint type, char *str, ulong num, const char *prefix, int numeric_key_for_empty_prefix) {
12858 + char *new_key = NULL;
12860 + if (prefix && *prefix) {
12861 + if (type == HASH_KEY_IS_STRING) {
12862 + spprintf(&new_key, 0, "%s[%s]", prefix, str);
12864 + spprintf(&new_key, 0, "%s[%lu]", prefix, num);
12866 + } else if (type == HASH_KEY_IS_STRING) {
12867 + new_key = estrdup(str);
12868 + } else if (numeric_key_for_empty_prefix) {
12869 + spprintf(&new_key, 0, "%lu", num);
12875 +/* {{{ static STATUS recursive_fields(post_data d, HashTable *f, const char *p TSRMLS_DC) */
12876 +static STATUS recursive_fields(post_data http_post_data, HashTable *fields, const char *prefix TSRMLS_DC) {
12877 + HashKey key = initHashKey(0);
12879 + HashPosition pos;
12880 + char *new_key = NULL;
12881 + CURLcode err = 0;
12883 + if (fields && !fields->nApplyCount) {
12884 + FOREACH_HASH_KEYVAL(pos, fields, key, data_ptr) {
12885 + if (key.type != HASH_KEY_IS_STRING || *key.str) {
12886 + new_key = format_key(key.type, key.str, key.num, prefix, 1);
12888 + switch (Z_TYPE_PP(data_ptr)) {
12890 + case IS_OBJECT: {
12893 + ++fields->nApplyCount;
12894 + status = recursive_fields(http_post_data, HASH_OF(*data_ptr), new_key TSRMLS_CC);
12895 + --fields->nApplyCount;
12897 + if (SUCCESS != status) {
12904 + zval *data = http_zsep(IS_STRING, *data_ptr);
12906 + err = curl_formadd(&http_post_data[0], &http_post_data[1],
12907 + CURLFORM_COPYNAME, new_key,
12908 + CURLFORM_COPYCONTENTS, Z_STRVAL_P(data),
12909 + CURLFORM_CONTENTSLENGTH, (long) Z_STRLEN_P(data),
12913 + zval_ptr_dtor(&data);
12915 + if (CURLE_OK != err) {
12921 + STR_FREE(new_key);
12932 + if (http_post_data[0]) {
12933 + curl_formfree(http_post_data[0]);
12936 + http_error_ex(HE_WARNING, HTTP_E_ENCODING, "Could not encode post fields: %s", curl_easy_strerror(err));
12938 + http_error_ex(HE_WARNING, HTTP_E_ENCODING, "Could not encode post fields: unknown error");
12944 +/* {{{ static STATUS recursive_files(post_data d, HashTable *f, const char *p TSRMLS_DC) */
12945 +static STATUS recursive_files(post_data http_post_data, HashTable *files, const char *prefix TSRMLS_DC) {
12946 + HashKey key = initHashKey(0);
12948 + HashPosition pos;
12949 + char *new_key = NULL;
12950 + CURLcode err = 0;
12952 + if (files && !files->nApplyCount) {
12953 + FOREACH_HASH_KEYVAL(pos, files, key, data_ptr) {
12954 + zval **file_ptr, **type_ptr, **name_ptr;
12956 + if (key.type != HASH_KEY_IS_STRING || *key.str) {
12957 + new_key = format_key(key.type, key.str, key.num, prefix, 0);
12959 + if (Z_TYPE_PP(data_ptr) != IS_ARRAY && Z_TYPE_PP(data_ptr) != IS_OBJECT) {
12960 + if (new_key || key.type == HASH_KEY_IS_STRING) {
12961 + http_error_ex(HE_NOTICE, HTTP_E_INVALID_PARAM, "Unrecognized type of post file array entry '%s'", new_key ? new_key : key.str);
12963 + http_error_ex(HE_NOTICE, HTTP_E_INVALID_PARAM, "Unrecognized type of post file array entry '%lu'", key.num);
12965 + } else if ( SUCCESS != zend_hash_find(HASH_OF(*data_ptr), "name", sizeof("name"), (void *) &name_ptr) ||
12966 + SUCCESS != zend_hash_find(HASH_OF(*data_ptr), "type", sizeof("type"), (void *) &type_ptr) ||
12967 + SUCCESS != zend_hash_find(HASH_OF(*data_ptr), "file", sizeof("file"), (void *) &file_ptr)) {
12970 + ++files->nApplyCount;
12971 + status = recursive_files(http_post_data, HASH_OF(*data_ptr), new_key TSRMLS_CC);
12972 + --files->nApplyCount;
12974 + if (SUCCESS != status) {
12978 + const char *path;
12979 + zval *file = http_zsep(IS_STRING, *file_ptr);
12980 + zval *type = http_zsep(IS_STRING, *type_ptr);
12981 + zval *name = http_zsep(IS_STRING, *name_ptr);
12983 + HTTP_CHECK_OPEN_BASEDIR(Z_STRVAL_P(file), goto error);
12985 + /* this is blatant but should be sufficient for most cases */
12986 + if (strncasecmp(Z_STRVAL_P(file), "file://", lenof("file://"))) {
12987 + path = Z_STRVAL_P(file);
12989 + path = Z_STRVAL_P(file) + lenof("file://");
12993 + char *tmp_key = format_key(HASH_KEY_IS_STRING, Z_STRVAL_P(name), 0, new_key, 0);
12994 + STR_SET(new_key, tmp_key);
12997 + err = curl_formadd(&http_post_data[0], &http_post_data[1],
12998 + CURLFORM_COPYNAME, new_key ? new_key : Z_STRVAL_P(name),
12999 + CURLFORM_FILE, path,
13000 + CURLFORM_CONTENTTYPE, Z_STRVAL_P(type),
13004 + zval_ptr_dtor(&file);
13005 + zval_ptr_dtor(&type);
13006 + zval_ptr_dtor(&name);
13008 + if (CURLE_OK != err) {
13012 + STR_FREE(new_key);
13023 + if (http_post_data[0]) {
13024 + curl_formfree(http_post_data[0]);
13027 + http_error_ex(HE_WARNING, HTTP_E_ENCODING, "Could not encode post files: %s", curl_easy_strerror(err));
13029 + http_error(HE_WARNING, HTTP_E_ENCODING, "Could not encode post files: unknown error");
13035 +#endif /* HTTP_HAVE_CURL */
13038 + * Local variables:
13040 + * c-basic-offset: 4
13042 + * vim600: noet sw=4 ts=4 fdm=marker
13043 + * vim<600: noet sw=4 ts=4
13046 +++ b/ext/http/http_request_datashare_api.c
13049 + +--------------------------------------------------------------------+
13051 + +--------------------------------------------------------------------+
13052 + | Redistribution and use in source and binary forms, with or without |
13053 + | modification, are permitted provided that the conditions mentioned |
13054 + | in the accompanying LICENSE file are met. |
13055 + +--------------------------------------------------------------------+
13056 + | Copyright (c) 2004-2010, Michael Wallner <mike@php.net> |
13057 + +--------------------------------------------------------------------+
13060 +/* $Id: http_request_datashare_api.c 292841 2009-12-31 08:48:57Z mike $ */
13062 +#define HTTP_WANT_CURL
13063 +#include "php_http.h"
13065 +#if defined(ZEND_ENGINE_2) && defined(HTTP_HAVE_CURL)
13067 +#include "php_http_api.h"
13068 +#include "php_http_persistent_handle_api.h"
13069 +#include "php_http_request_datashare_api.h"
13070 +#include "php_http_request_api.h"
13071 +#include "php_http_request_object.h"
13073 +static HashTable http_request_datashare_options;
13074 +static http_request_datashare http_request_datashare_global;
13075 +static int http_request_datashare_compare_handles(void *h1, void *h2);
13076 +static void http_request_datashare_destroy_handles(void *el);
13078 +static void *http_request_datashare_locks_init(void);
13079 +static void http_request_datashare_locks_dtor(void *l);
13080 +static void http_request_datashare_lock_func(CURL *handle, curl_lock_data data, curl_lock_access locktype, void *userptr);
13081 +static void http_request_datashare_unlock_func(CURL *handle, curl_lock_data data, void *userptr);
13084 +http_request_datashare *_http_request_datashare_global_get(void)
13086 + return &http_request_datashare_global;
13089 +PHP_MINIT_FUNCTION(http_request_datashare)
13091 + curl_lock_data val;
13093 + if (SUCCESS != http_persistent_handle_provide("http_request_datashare", curl_share_init, (http_persistent_handle_dtor) curl_share_cleanup, NULL)) {
13097 + if (SUCCESS != http_persistent_handle_provide("http_request_datashare_lock", http_request_datashare_locks_init, http_request_datashare_locks_dtor, NULL)) {
13102 + if (!http_request_datashare_init_ex(&http_request_datashare_global, 1)) {
13106 + zend_hash_init(&http_request_datashare_options, 4, NULL, NULL, 1);
13107 +#define ADD_DATASHARE_OPT(name, opt) \
13109 + zend_hash_add(&http_request_datashare_options, name, sizeof(name), &val, sizeof(curl_lock_data), NULL)
13110 + ADD_DATASHARE_OPT("cookie", CURL_LOCK_DATA_COOKIE);
13111 + ADD_DATASHARE_OPT("dns", CURL_LOCK_DATA_DNS);
13112 + ADD_DATASHARE_OPT("ssl", CURL_LOCK_DATA_SSL_SESSION);
13113 + ADD_DATASHARE_OPT("connect", CURL_LOCK_DATA_CONNECT);
13118 +PHP_MSHUTDOWN_FUNCTION(http_request_datashare)
13120 + http_request_datashare_dtor(&http_request_datashare_global);
13121 + zend_hash_destroy(&http_request_datashare_options);
13126 +PHP_RINIT_FUNCTION(http_request_datashare)
13128 + zend_llist_init(&HTTP_G->request.datashare.handles, sizeof(zval *), http_request_datashare_destroy_handles, 0);
13133 +PHP_RSHUTDOWN_FUNCTION(http_request_datashare)
13135 + zend_llist_destroy(&HTTP_G->request.datashare.handles);
13140 +PHP_HTTP_API http_request_datashare *_http_request_datashare_init_ex(http_request_datashare *share, zend_bool persistent TSRMLS_DC)
13142 + zend_bool free_share;
13144 + if ((free_share = !share)) {
13145 + share = pemalloc(sizeof(http_request_datashare), persistent);
13147 + memset(share, 0, sizeof(http_request_datashare));
13149 + if (SUCCESS != http_persistent_handle_acquire("http_request_datashare", &share->ch)) {
13150 + if (free_share) {
13151 + pefree(share, persistent);
13156 + if (!(share->persistent = persistent)) {
13157 + share->handle.list = emalloc(sizeof(zend_llist));
13158 + zend_llist_init(share->handle.list, sizeof(zval *), ZVAL_PTR_DTOR, 0);
13161 + if (SUCCESS == http_persistent_handle_acquire("http_request_datashare_lock", (void *) &share->handle.locks)) {
13162 + curl_share_setopt(share->ch, CURLSHOPT_LOCKFUNC, http_request_datashare_lock_func);
13163 + curl_share_setopt(share->ch, CURLSHOPT_UNLOCKFUNC, http_request_datashare_unlock_func);
13164 + curl_share_setopt(share->ch, CURLSHOPT_USERDATA, share->handle.locks);
13172 +PHP_HTTP_API STATUS _http_request_datashare_attach(http_request_datashare *share, zval *request TSRMLS_DC)
13175 + getObjectEx(http_request_object, obj, request);
13177 + if (obj->share) {
13178 + if (obj->share == share) {
13180 + } else if (SUCCESS != http_request_datashare_detach(obj->share, request)) {
13185 + HTTP_CHECK_CURL_INIT(obj->request->ch, http_curl_init_ex(obj->request->ch, obj->request), return FAILURE);
13186 + if (CURLE_OK != (rc = curl_easy_setopt(obj->request->ch, CURLOPT_SHARE, share->ch))) {
13187 + http_error_ex(HE_WARNING, HTTP_E_REQUEST, "Could not attach HttpRequest object(#%d) to the HttpRequestDataShare: %s", Z_OBJ_HANDLE_P(request), curl_easy_strerror(rc));
13191 + obj->share = share;
13192 + ZVAL_ADDREF(request);
13193 + zend_llist_add_element(HTTP_RSHARE_HANDLES(share), (void *) &request);
13198 +PHP_HTTP_API STATUS _http_request_datashare_detach(http_request_datashare *share, zval *request TSRMLS_DC)
13201 + getObjectEx(http_request_object, obj, request);
13203 + if (!obj->share) {
13204 + http_error_ex(HE_WARNING, HTTP_E_REQUEST, "HttpRequest object(#%d) is not attached to any HttpRequestDataShare", Z_OBJ_HANDLE_P(request));
13205 + } else if (obj->share != share) {
13206 + http_error_ex(HE_WARNING, HTTP_E_REQUEST, "HttpRequest object(#%d) is not attached to this HttpRequestDataShare", Z_OBJ_HANDLE_P(request));
13207 + } else if (CURLE_OK != (rc = curl_easy_setopt(obj->request->ch, CURLOPT_SHARE, NULL))) {
13208 + http_error_ex(HE_WARNING, HTTP_E_REQUEST, "Could not detach HttpRequest object(#%d) from the HttpRequestDataShare: %s", Z_OBJ_HANDLE_P(request), curl_share_strerror(rc));
13210 + obj->share = NULL;
13211 + zend_llist_del_element(HTTP_RSHARE_HANDLES(share), request, http_request_datashare_compare_handles);
13217 +PHP_HTTP_API void _http_request_datashare_detach_all(http_request_datashare *share TSRMLS_DC)
13221 + while ((r = zend_llist_get_first(HTTP_RSHARE_HANDLES(share)))) {
13222 + http_request_datashare_detach(share, *r);
13226 +PHP_HTTP_API void _http_request_datashare_dtor(http_request_datashare *share TSRMLS_DC)
13228 + if (!share->persistent) {
13229 + zend_llist_destroy(share->handle.list);
13230 + efree(share->handle.list);
13232 + http_persistent_handle_release("http_request_datashare", &share->ch);
13234 + if (share->persistent) {
13235 + http_persistent_handle_release("http_request_datashare_lock", (void *) &share->handle.locks);
13240 +PHP_HTTP_API void _http_request_datashare_free(http_request_datashare **share TSRMLS_DC)
13242 + http_request_datashare_dtor(*share);
13243 + pefree(*share, (*share)->persistent);
13247 +PHP_HTTP_API STATUS _http_request_datashare_set(http_request_datashare *share, const char *option, size_t option_len, zend_bool enable TSRMLS_DC)
13249 + curl_lock_data *opt;
13252 + if (SUCCESS == zend_hash_find(&http_request_datashare_options, (char *) option, option_len + 1, (void *) &opt)) {
13253 + if (CURLSHE_OK == (rc = curl_share_setopt(share->ch, enable ? CURLSHOPT_SHARE : CURLSHOPT_UNSHARE, *opt))) {
13256 + http_error_ex(HE_WARNING, HTTP_E_REQUEST, "Could not %s sharing of %s data: %s", enable ? "enable" : "disable", option, curl_share_strerror(rc));
13261 +static int http_request_datashare_compare_handles(void *h1, void *h2)
13263 + return (Z_OBJ_HANDLE_PP((zval **) h1) == Z_OBJ_HANDLE_P((zval *) h2));
13266 +static void http_request_datashare_destroy_handles(void *el)
13268 + zval **r = (zval **) el;
13271 + { /* gcc 2.95 needs these braces */
13272 + getObjectEx(http_request_object, obj, *r);
13274 + curl_easy_setopt(obj->request->ch, CURLOPT_SHARE, NULL);
13275 + zval_ptr_dtor(r);
13280 +static void *http_request_datashare_locks_init(void)
13283 + http_request_datashare_lock *locks = pecalloc(CURL_LOCK_DATA_LAST, sizeof(http_request_datashare_lock), 1);
13286 + for (i = 0; i < CURL_LOCK_DATA_LAST; ++i) {
13287 + locks[i].mx = tsrm_mutex_alloc();
13294 +static void http_request_datashare_locks_dtor(void *l)
13297 + http_request_datashare_lock *locks = (http_request_datashare_lock *) l;
13299 + for (i = 0; i < CURL_LOCK_DATA_LAST; ++i) {
13300 + tsrm_mutex_free(locks[i].mx);
13302 + pefree(locks, 1);
13305 +static void http_request_datashare_lock_func(CURL *handle, curl_lock_data data, curl_lock_access locktype, void *userptr)
13307 + http_request_datashare_lock *locks = (http_request_datashare_lock *) userptr;
13309 + /* TSRM can't distinguish shared/exclusive locks */
13310 + tsrm_mutex_lock(locks[data].mx);
13311 + locks[data].ch = handle;
13314 +static void http_request_datashare_unlock_func(CURL *handle, curl_lock_data data, void *userptr)
13316 + http_request_datashare_lock *locks = (http_request_datashare_lock *) userptr;
13318 + if (locks[data].ch == handle) {
13319 + tsrm_mutex_unlock(locks[data].mx);
13324 +#endif /* ZEND_ENGINE_2 && HTTP_HAVE_CURL */
13328 + * Local variables:
13330 + * c-basic-offset: 4
13332 + * vim600: noet sw=4 ts=4 fdm=marker
13333 + * vim<600: noet sw=4 ts=4
13337 +++ b/ext/http/http_request_info.c
13340 + +--------------------------------------------------------------------+
13342 + +--------------------------------------------------------------------+
13343 + | Redistribution and use in source and binary forms, with or without |
13344 + | modification, are permitted provided that the conditions mentioned |
13345 + | in the accompanying LICENSE file are met. |
13346 + +--------------------------------------------------------------------+
13347 + | Copyright (c) 2004-2010, Michael Wallner <mike@php.net> |
13348 + +--------------------------------------------------------------------+
13351 +/* $Id: http_request_info.c 323304 2012-02-17 21:13:24Z mike $ */
13353 +#define HTTP_WANT_CURL
13354 +#include "php_http.h"
13356 +#ifdef HTTP_HAVE_CURL
13357 +#include "php_http_request_api.h"
13359 +/* {{{ void http_request_info(http_request *, HashTable *) */
13360 +PHP_HTTP_API void _http_request_info(http_request *request, HashTable *info)
13365 + struct curl_slist *s, *p;
13366 + zval *subarray, array;
13367 + INIT_ZARR(array, info);
13370 + if (CURLE_OK == curl_easy_getinfo(request->ch, CURLINFO_EFFECTIVE_URL, &c)) {
13371 + add_assoc_string_ex(&array, "effective_url", sizeof("effective_url"), c ? c : "", 1);
13373 + if (CURLE_OK == curl_easy_getinfo(request->ch, CURLINFO_RESPONSE_CODE, &l)) {
13374 + add_assoc_long_ex(&array, "response_code", sizeof("response_code"), l);
13376 + if (CURLE_OK == curl_easy_getinfo(request->ch, CURLINFO_TOTAL_TIME, &d)) {
13377 + add_assoc_double_ex(&array, "total_time", sizeof("total_time"), d);
13379 + if (CURLE_OK == curl_easy_getinfo(request->ch, CURLINFO_NAMELOOKUP_TIME, &d)) {
13380 + add_assoc_double_ex(&array, "namelookup_time", sizeof("namelookup_time"), d);
13382 + if (CURLE_OK == curl_easy_getinfo(request->ch, CURLINFO_CONNECT_TIME, &d)) {
13383 + add_assoc_double_ex(&array, "connect_time", sizeof("connect_time"), d);
13385 + if (CURLE_OK == curl_easy_getinfo(request->ch, CURLINFO_PRETRANSFER_TIME, &d)) {
13386 + add_assoc_double_ex(&array, "pretransfer_time", sizeof("pretransfer_time"), d);
13388 + if (CURLE_OK == curl_easy_getinfo(request->ch, CURLINFO_SIZE_UPLOAD, &d)) {
13389 + add_assoc_double_ex(&array, "size_upload", sizeof("size_upload"), d);
13391 + if (CURLE_OK == curl_easy_getinfo(request->ch, CURLINFO_SIZE_DOWNLOAD, &d)) {
13392 + add_assoc_double_ex(&array, "size_download", sizeof("size_download"), d);
13394 + if (CURLE_OK == curl_easy_getinfo(request->ch, CURLINFO_SPEED_DOWNLOAD, &d)) {
13395 + add_assoc_double_ex(&array, "speed_download", sizeof("speed_download"), d);
13397 + if (CURLE_OK == curl_easy_getinfo(request->ch, CURLINFO_SPEED_UPLOAD, &d)) {
13398 + add_assoc_double_ex(&array, "speed_upload", sizeof("speed_upload"), d);
13400 + if (CURLE_OK == curl_easy_getinfo(request->ch, CURLINFO_HEADER_SIZE, &l)) {
13401 + add_assoc_long_ex(&array, "header_size", sizeof("header_size"), l);
13403 + if (CURLE_OK == curl_easy_getinfo(request->ch, CURLINFO_REQUEST_SIZE, &l)) {
13404 + add_assoc_long_ex(&array, "request_size", sizeof("request_size"), l);
13406 + if (CURLE_OK == curl_easy_getinfo(request->ch, CURLINFO_SSL_VERIFYRESULT, &l)) {
13407 + add_assoc_long_ex(&array, "ssl_verifyresult", sizeof("ssl_verifyresult"), l);
13409 + if (CURLE_OK == curl_easy_getinfo(request->ch, CURLINFO_FILETIME, &l)) {
13410 + add_assoc_long_ex(&array, "filetime", sizeof("filetime"), l);
13412 + if (CURLE_OK == curl_easy_getinfo(request->ch, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &d)) {
13413 + add_assoc_double_ex(&array, "content_length_download", sizeof("content_length_download"), d);
13415 + if (CURLE_OK == curl_easy_getinfo(request->ch, CURLINFO_CONTENT_LENGTH_UPLOAD, &d)) {
13416 + add_assoc_double_ex(&array, "content_length_upload", sizeof("content_length_upload"), d);
13418 + if (CURLE_OK == curl_easy_getinfo(request->ch, CURLINFO_STARTTRANSFER_TIME, &d)) {
13419 + add_assoc_double_ex(&array, "starttransfer_time", sizeof("starttransfer_time"), d);
13421 + if (CURLE_OK == curl_easy_getinfo(request->ch, CURLINFO_CONTENT_TYPE, &c)) {
13422 + add_assoc_string_ex(&array, "content_type", sizeof("content_type"), c ? c : "", 1);
13424 + if (CURLE_OK == curl_easy_getinfo(request->ch, CURLINFO_REDIRECT_TIME, &d)) {
13425 + add_assoc_double_ex(&array, "redirect_time", sizeof("redirect_time"), d);
13427 + if (CURLE_OK == curl_easy_getinfo(request->ch, CURLINFO_REDIRECT_COUNT, &l)) {
13428 + add_assoc_long_ex(&array, "redirect_count", sizeof("redirect_count"), l);
13430 + if (CURLE_OK == curl_easy_getinfo(request->ch, CURLINFO_HTTP_CONNECTCODE, &l)) {
13431 + add_assoc_long_ex(&array, "connect_code", sizeof("connect_code"), l);
13433 + if (CURLE_OK == curl_easy_getinfo(request->ch, CURLINFO_HTTPAUTH_AVAIL, &l)) {
13434 + add_assoc_long_ex(&array, "httpauth_avail", sizeof("httpauth_avail"), l);
13436 + if (CURLE_OK == curl_easy_getinfo(request->ch, CURLINFO_PROXYAUTH_AVAIL, &l)) {
13437 + add_assoc_long_ex(&array, "proxyauth_avail", sizeof("proxyauth_avail"), l);
13439 + if (CURLE_OK == curl_easy_getinfo(request->ch, CURLINFO_OS_ERRNO, &l)) {
13440 + add_assoc_long_ex(&array, "os_errno", sizeof("os_errno"), l);
13442 + if (CURLE_OK == curl_easy_getinfo(request->ch, CURLINFO_NUM_CONNECTS, &l)) {
13443 + add_assoc_long_ex(&array, "num_connects", sizeof("num_connects"), l);
13445 + if (CURLE_OK == curl_easy_getinfo(request->ch, CURLINFO_SSL_ENGINES, &s)) {
13446 + MAKE_STD_ZVAL(subarray);
13447 + array_init(subarray);
13448 + for (p = s; p; p = p->next) {
13450 + add_next_index_string(subarray, p->data, 1);
13453 + add_assoc_zval_ex(&array, "ssl_engines", sizeof("ssl_engines"), subarray);
13454 + curl_slist_free_all(s);
13456 +#if HTTP_CURL_VERSION(7,14,1)
13457 + if (CURLE_OK == curl_easy_getinfo(request->ch, CURLINFO_COOKIELIST, &s)) {
13458 + MAKE_STD_ZVAL(subarray);
13459 + array_init(subarray);
13460 + for (p = s; p; p = p->next) {
13462 + add_next_index_string(subarray, p->data, 1);
13465 + add_assoc_zval_ex(&array, "cookies", sizeof("cookies"), subarray);
13466 + curl_slist_free_all(s);
13469 +#if HTTP_CURL_VERSION(7,18,2)
13470 + if (CURLE_OK == curl_easy_getinfo(request->ch, CURLINFO_REDIRECT_URL, &c)) {
13471 + add_assoc_string_ex(&array, "redirect_url", sizeof("redirect_url"), c ? c : "", 1);
13474 +#if HTTP_CURL_VERSION(7,19,0)
13475 + if (CURLE_OK == curl_easy_getinfo(request->ch, CURLINFO_PRIMARY_IP, &c)) {
13476 + add_assoc_string_ex(&array, "primary_ip", sizeof("primary_ip"), c ? c : "", 1);
13479 +#if HTTP_CURL_VERSION(7,19,0)
13480 + if (CURLE_OK == curl_easy_getinfo(request->ch, CURLINFO_APPCONNECT_TIME, &d)) {
13481 + add_assoc_double_ex(&array, "appconnect_time", sizeof("appconnect_time"), d);
13484 +#if HTTP_CURL_VERSION(7,19,4)
13485 + if (CURLE_OK == curl_easy_getinfo(request->ch, CURLINFO_CONDITION_UNMET, &l)) {
13486 + add_assoc_long_ex(&array, "condition_unmet", sizeof("condition_unmet"), l);
13489 +#if HTTP_CURL_VERSION(7,21,0)
13490 + if (CURLE_OK == curl_easy_getinfo(request->ch, CURLINFO_PRIMARY_PORT, &l)) {
13491 + add_assoc_long_ex(&array, "primary_port", sizeof("primary_port"), l);
13494 +#if HTTP_CURL_VERSION(7,21,0)
13495 + if (CURLE_OK == curl_easy_getinfo(request->ch, CURLINFO_LOCAL_IP, &c)) {
13496 + add_assoc_string_ex(&array, "local_ip", sizeof("local_ip"), c ? c : "", 1);
13499 +#if HTTP_CURL_VERSION(7,21,0)
13500 + if (CURLE_OK == curl_easy_getinfo(request->ch, CURLINFO_LOCAL_PORT, &l)) {
13501 + add_assoc_long_ex(&array, "local_port", sizeof("local_port"), l);
13505 +#if HTTP_CURL_VERSION(7,19,1) && defined(HTTP_HAVE_OPENSSL)
13509 + struct curl_certinfo *ci;
13510 + char *colon, *keyname;
13512 + if (CURLE_OK == curl_easy_getinfo(request->ch, CURLINFO_CERTINFO, &ci)) {
13513 + MAKE_STD_ZVAL(ci_array);
13514 + array_init(ci_array);
13516 + for (i = 0; i < ci->num_of_certs; ++i) {
13517 + s = ci->certinfo[i];
13519 + MAKE_STD_ZVAL(subarray);
13520 + array_init(subarray);
13521 + for (p = s; p; p = p->next) {
13523 + if ((colon = strchr(p->data, ':'))) {
13524 + keyname = estrndup(p->data, colon - p->data);
13525 + add_assoc_string_ex(subarray, keyname, colon - p->data + 1, colon + 1, 1);
13528 + add_next_index_string(subarray, p->data, 1);
13532 + add_next_index_zval(ci_array, subarray);
13534 + add_assoc_zval_ex(&array, "certinfo", sizeof("certinfo"), ci_array);
13538 + add_assoc_string_ex(&array, "error", sizeof("error"), http_request_storage_get(request->ch)->errorbuffer, 1);
13542 +#endif /* HTTP_HAVE_CURL */
13545 + * Local variables:
13547 + * c-basic-offset: 4
13549 + * vim600: noet sw=4 ts=4 fdm=marker
13550 + * vim<600: noet sw=4 ts=4
13553 +++ b/ext/http/http_request_method_api.c
13556 + +--------------------------------------------------------------------+
13558 + +--------------------------------------------------------------------+
13559 + | Redistribution and use in source and binary forms, with or without |
13560 + | modification, are permitted provided that the conditions mentioned |
13561 + | in the accompanying LICENSE file are met. |
13562 + +--------------------------------------------------------------------+
13563 + | Copyright (c) 2004-2010, Michael Wallner <mike@php.net> |
13564 + +--------------------------------------------------------------------+
13567 +/* $Id: http_request_method_api.c 323406 2012-02-21 10:05:52Z mike $ */
13569 +#define HTTP_WANT_CURL
13570 +#include "php_http.h"
13572 +#include "php_http_api.h"
13573 +#include "php_http_request_api.h"
13574 +#include "php_http_request_method_api.h"
13576 +#if defined(ZEND_ENGINE_2) && defined(HTTP_HAVE_CURL) && !defined(WONKY)
13577 +# include "php_http_request_object.h"
13580 +/* {{{ char *http_request_methods[] */
13581 +static const char *const http_request_methods[] = {
13592 + /* WebDAV - RFC 2518 */
13600 + /* WebDAV Versioning - RFC 3253 */
13601 + "VERSION-CONTROL",
13610 + "BASELINE-CONTROL",
13612 + /* WebDAV Access Control - RFC 3744 */
13619 +PHP_MINIT_FUNCTION(http_request_method)
13622 + HTTP_LONG_CONSTANT("HTTP_METH_GET", HTTP_GET);
13623 + HTTP_LONG_CONSTANT("HTTP_METH_HEAD", HTTP_HEAD);
13624 + HTTP_LONG_CONSTANT("HTTP_METH_POST", HTTP_POST);
13625 + HTTP_LONG_CONSTANT("HTTP_METH_PUT", HTTP_PUT);
13626 + HTTP_LONG_CONSTANT("HTTP_METH_DELETE", HTTP_DELETE);
13627 + HTTP_LONG_CONSTANT("HTTP_METH_OPTIONS", HTTP_OPTIONS);
13628 + HTTP_LONG_CONSTANT("HTTP_METH_TRACE", HTTP_TRACE);
13629 + HTTP_LONG_CONSTANT("HTTP_METH_CONNECT", HTTP_CONNECT);
13630 + /* WebDAV - RFC 2518 */
13631 + HTTP_LONG_CONSTANT("HTTP_METH_PROPFIND", HTTP_PROPFIND);
13632 + HTTP_LONG_CONSTANT("HTTP_METH_PROPPATCH", HTTP_PROPPATCH);
13633 + HTTP_LONG_CONSTANT("HTTP_METH_MKCOL", HTTP_MKCOL);
13634 + HTTP_LONG_CONSTANT("HTTP_METH_COPY", HTTP_COPY);
13635 + HTTP_LONG_CONSTANT("HTTP_METH_MOVE", HTTP_MOVE);
13636 + HTTP_LONG_CONSTANT("HTTP_METH_LOCK", HTTP_LOCK);
13637 + HTTP_LONG_CONSTANT("HTTP_METH_UNLOCK", HTTP_UNLOCK);
13638 + /* WebDAV Versioning - RFC 3253 */
13639 + HTTP_LONG_CONSTANT("HTTP_METH_VERSION_CONTROL", HTTP_VERSION_CONTROL);
13640 + HTTP_LONG_CONSTANT("HTTP_METH_REPORT", HTTP_REPORT);
13641 + HTTP_LONG_CONSTANT("HTTP_METH_CHECKOUT", HTTP_CHECKOUT);
13642 + HTTP_LONG_CONSTANT("HTTP_METH_CHECKIN", HTTP_CHECKIN);
13643 + HTTP_LONG_CONSTANT("HTTP_METH_UNCHECKOUT", HTTP_UNCHECKOUT);
13644 + HTTP_LONG_CONSTANT("HTTP_METH_MKWORKSPACE", HTTP_MKWORKSPACE);
13645 + HTTP_LONG_CONSTANT("HTTP_METH_UPDATE", HTTP_UPDATE);
13646 + HTTP_LONG_CONSTANT("HTTP_METH_LABEL", HTTP_LABEL);
13647 + HTTP_LONG_CONSTANT("HTTP_METH_MERGE", HTTP_MERGE);
13648 + HTTP_LONG_CONSTANT("HTTP_METH_BASELINE_CONTROL", HTTP_BASELINE_CONTROL);
13649 + HTTP_LONG_CONSTANT("HTTP_METH_MKACTIVITY", HTTP_MKACTIVITY);
13650 + /* WebDAV Access Control - RFC 3744 */
13651 + HTTP_LONG_CONSTANT("HTTP_METH_ACL", HTTP_ACL);
13656 +static void free_method(void *el)
13658 + efree(*(char **)el);
13661 +static void unregister_method(const char *name TSRMLS_DC)
13663 + char *ptr, tmp[sizeof("HTTP_METH_") + HTTP_REQUEST_METHOD_MAXLEN] = "HTTP_METH_";
13665 + strlcpy(tmp + lenof("HTTP_METH_"), name, HTTP_REQUEST_METHOD_MAXLEN);
13666 + for (ptr = tmp + lenof("HTTP_METH_"); *ptr; ++ptr) {
13667 + if (*ptr == '-') {
13672 +#if defined(ZEND_ENGINE_2) && defined(HTTP_HAVE_CURL) && !defined(WONKY)
13673 + if (SUCCESS != zend_hash_del(&http_request_object_ce->constants_table, tmp + lenof("HTTP_"), strlen(tmp + lenof("HTTP_")) + 1)) {
13674 + http_error_ex(HE_NOTICE, HTTP_E_REQUEST_METHOD, "Could not unregister request method: HttpRequest::%s", tmp + lenof("HTTP_"));
13677 + if (SUCCESS != zend_hash_del(EG(zend_constants), tmp, strlen(tmp) + 1)) {
13678 + http_error_ex(HE_NOTICE, HTTP_E_REQUEST_METHOD, "Could not unregister request method: %s", tmp);
13682 +PHP_RINIT_FUNCTION(http_request_method)
13686 + zend_hash_init(&HTTP_G->request.methods.registered, 0, NULL, free_method, 0);
13687 +#define HTTP_METH_REG(m) \
13689 + char *_m=estrdup(m); \
13690 + zend_hash_next_index_insert(&HTTP_G->request.methods.registered, (void *) &_m, sizeof(char *), NULL); \
13692 + HTTP_METH_REG("UNKNOWN");
13694 + HTTP_METH_REG("GET");
13695 + HTTP_METH_REG("HEAD");
13696 + HTTP_METH_REG("POST");
13697 + HTTP_METH_REG("PUT");
13698 + HTTP_METH_REG("DELETE");
13699 + HTTP_METH_REG("OPTIONS");
13700 + HTTP_METH_REG("TRACE");
13701 + HTTP_METH_REG("CONNECT");
13702 + /* WebDAV - RFC 2518 */
13703 + HTTP_METH_REG("PROPFIND");
13704 + HTTP_METH_REG("PROPPATCH");
13705 + HTTP_METH_REG("MKCOL");
13706 + HTTP_METH_REG("COPY");
13707 + HTTP_METH_REG("MOVE");
13708 + HTTP_METH_REG("LOCK");
13709 + HTTP_METH_REG("UNLOCK");
13710 + /* WebDAV Versioning - RFC 3253 */
13711 + HTTP_METH_REG("VERSION-CONTROL");
13712 + HTTP_METH_REG("REPORT");
13713 + HTTP_METH_REG("CHECKOUT");
13714 + HTTP_METH_REG("CHECKIN");
13715 + HTTP_METH_REG("UNCHECKOUT");
13716 + HTTP_METH_REG("MKWORKSPACE");
13717 + HTTP_METH_REG("UPDATE");
13718 + HTTP_METH_REG("LABEL");
13719 + HTTP_METH_REG("MERGE");
13720 + HTTP_METH_REG("BASELINE-CONTROL");
13721 + HTTP_METH_REG("MKACTIVITY");
13722 + /* WebDAV Access Control - RFC 3744 */
13723 + HTTP_METH_REG("ACL");
13725 + zend_hash_init(&ht, 0, NULL, ZVAL_PTR_DTOR, 0);
13726 + if (*HTTP_G->request.methods.custom && SUCCESS == http_parse_params(HTTP_G->request.methods.custom, HTTP_PARAMS_DEFAULT, &ht)) {
13727 + HashPosition pos;
13730 + FOREACH_HASH_VAL(pos, &ht, val) {
13731 + if (Z_TYPE_PP(val) == IS_STRING) {
13732 + http_request_method_register(Z_STRVAL_PP(val), Z_STRLEN_PP(val));
13736 + zend_hash_destroy(&ht);
13741 +PHP_RSHUTDOWN_FUNCTION(http_request_method)
13744 + int i, c = zend_hash_next_free_element(&HTTP_G->request.methods.registered);
13746 + for (i = HTTP_MAX_REQUEST_METHOD; i < c; ++i) {
13747 + if (SUCCESS == zend_hash_index_find(&HTTP_G->request.methods.registered, i, (void *) &name)) {
13748 + unregister_method(*name TSRMLS_CC);
13752 + zend_hash_destroy(&HTTP_G->request.methods.registered);
13756 +#define http_request_method_cncl(m, c) _http_request_method_cncl_ex((m), strlen(m), (c) TSRMLS_CC)
13757 +#define http_request_method_cncl_ex(m, l, c) _http_request_method_cncl_ex((m), (l), (c) TSRMLS_CC)
13758 +static STATUS _http_request_method_cncl_ex(const char *method_name, int method_name_len, char **cnst TSRMLS_DC)
13763 + if (method_name_len >= HTTP_REQUEST_METHOD_MAXLEN) {
13764 + http_error_ex(HE_WARNING, HTTP_E_REQUEST_METHOD, "Request method too long (%s)", method_name);
13766 + cncl = emalloc(method_name_len + 1);
13768 + for (i = 0; i < method_name_len; ++i) {
13769 + switch (method_name[i]) {
13772 + cncl[i] = method_name[i];
13776 + if (!HTTP_IS_CTYPE(alnum, method_name[i])) {
13778 + http_error_ex(HE_WARNING, HTTP_E_REQUEST_METHOD, "Request method contains illegal characters (%s)", method_name);
13781 + cncl[i] = HTTP_TO_CTYPE(upper, method_name[i]);
13785 + cncl[method_name_len] = '\0';
13791 +PHP_HTTP_API const char *_http_request_method_name(http_request_method m TSRMLS_DC)
13795 + if (SUCCESS == zend_hash_index_find(&HTTP_G->request.methods.registered, m, (void *) &name)) {
13798 + return "UNKNOWN";
13801 +PHP_HTTP_API int _http_request_method_exists(int by_name, http_request_method id_num, const char *id_str TSRMLS_DC)
13805 + if (by_name && (SUCCESS == http_request_method_cncl(id_str, &id_dup))) {
13807 + HashPosition pos;
13808 + HashKey key = initHashKey(0);
13810 + FOREACH_HASH_KEYVAL(pos, &HTTP_G->request.methods.registered, key, name) {
13811 + if (key.type == HASH_KEY_IS_LONG && !strcmp(*name, id_dup)) {
13817 + } else if (zend_hash_index_exists(&HTTP_G->request.methods.registered, id_num)){
13823 +PHP_HTTP_API int _http_request_method_register(const char *method_str, int method_len TSRMLS_DC)
13825 + char *method_dup, *ptr, tmp[sizeof("HTTP_METH_") + HTTP_REQUEST_METHOD_MAXLEN] = "HTTP_METH_";
13826 + int method_num = http_request_method_exists(1, 0, method_str);
13828 + if (!method_num && (SUCCESS == http_request_method_cncl_ex(method_str, method_len, &method_dup))) {
13829 + method_num = zend_hash_next_free_element(&HTTP_G->request.methods.registered);
13830 + zend_hash_index_update(&HTTP_G->request.methods.registered, method_num, (void *) &method_dup, sizeof(char *), NULL);
13832 + strlcpy(tmp + lenof("HTTP_METH_"), method_dup, HTTP_REQUEST_METHOD_MAXLEN);
13833 + for (ptr = tmp + lenof("HTTP_METH_"); *ptr; ++ptr) {
13834 + if (*ptr == '-') {
13839 + zend_register_long_constant(tmp, strlen(tmp) + 1, method_num, CONST_CS, http_module_number TSRMLS_CC);
13840 +#if defined(ZEND_ENGINE_2) && defined(HTTP_HAVE_CURL) && !defined(WONKY)
13841 + zend_declare_class_constant_long(http_request_object_ce, tmp + lenof("HTTP_"), strlen(tmp + lenof("HTTP_")), method_num TSRMLS_CC);
13845 + return method_num;
13848 +PHP_HTTP_API STATUS _http_request_method_unregister(int method TSRMLS_DC)
13852 + if (HTTP_STD_REQUEST_METHOD(method)) {
13853 + http_error_ex(HE_WARNING, HTTP_E_REQUEST_METHOD, "Standard request methods cannot be unregistered");
13857 + if (SUCCESS != zend_hash_index_find(&HTTP_G->request.methods.registered, method, (void *) &name)) {
13858 + http_error_ex(HE_NOTICE, HTTP_E_REQUEST_METHOD, "Custom request method with id %d does not exist", method);
13862 + unregister_method(*name TSRMLS_CC);
13864 + zend_hash_index_del(&HTTP_G->request.methods.registered, method);
13869 + * Local variables:
13871 + * c-basic-offset: 4
13873 + * vim600: noet sw=4 ts=4 fdm=marker
13874 + * vim<600: noet sw=4 ts=4
13878 +++ b/ext/http/http_request_object.c
13881 + +--------------------------------------------------------------------+
13883 + +--------------------------------------------------------------------+
13884 + | Redistribution and use in source and binary forms, with or without |
13885 + | modification, are permitted provided that the conditions mentioned |
13886 + | in the accompanying LICENSE file are met. |
13887 + +--------------------------------------------------------------------+
13888 + | Copyright (c) 2004-2010, Michael Wallner <mike@php.net> |
13889 + +--------------------------------------------------------------------+
13892 +/* $Id: http_request_object.c 323304 2012-02-17 21:13:24Z mike $ */
13894 +#define HTTP_WANT_CURL
13895 +#include "php_http.h"
13897 +#if defined(ZEND_ENGINE_2) && defined(HTTP_HAVE_CURL)
13899 +#include "zend_interfaces.h"
13901 +#include "php_http_api.h"
13902 +#include "php_http_cookie_api.h"
13903 +#include "php_http_exception_object.h"
13904 +#include "php_http_message_api.h"
13905 +#include "php_http_message_object.h"
13906 +#include "php_http_request_api.h"
13907 +#include "php_http_request_object.h"
13908 +#include "php_http_request_pool_api.h"
13909 +#include "php_http_url_api.h"
13911 +#define HTTP_BEGIN_ARGS(method, req_args) HTTP_BEGIN_ARGS_EX(HttpRequest, method, 0, req_args)
13912 +#define HTTP_EMPTY_ARGS(method) HTTP_EMPTY_ARGS_EX(HttpRequest, method, 0)
13913 +#define HTTP_REQUEST_ME(method, visibility) PHP_ME(HttpRequest, method, HTTP_ARGS(HttpRequest, method), visibility)
13914 +#define HTTP_REQUEST_ALIAS(method, func) HTTP_STATIC_ME_ALIAS(method, func, HTTP_ARGS(HttpRequest, method))
13915 +#define HTTP_REQUEST_MALIAS(me, al, vis) ZEND_FENTRY(me, ZEND_MN(HttpRequest_##al), HTTP_ARGS(HttpRequest, al), vis)
13917 +HTTP_BEGIN_ARGS(__construct, 0)
13918 + HTTP_ARG_VAL(url, 0)
13919 + HTTP_ARG_VAL(method, 0)
13920 + HTTP_ARG_VAL(options, 0)
13923 +HTTP_BEGIN_ARGS(factory, 0)
13924 + HTTP_ARG_VAL(url, 0)
13925 + HTTP_ARG_VAL(method, 0)
13926 + HTTP_ARG_VAL(options, 0)
13927 + HTTP_ARG_VAL(class_name, 0)
13930 +HTTP_EMPTY_ARGS(getOptions);
13931 +HTTP_BEGIN_ARGS(setOptions, 0)
13932 + HTTP_ARG_VAL(options, 0)
13935 +HTTP_EMPTY_ARGS(getSslOptions);
13936 +HTTP_BEGIN_ARGS(setSslOptions, 0)
13937 + HTTP_ARG_VAL(ssl_options, 0)
13940 +HTTP_BEGIN_ARGS(addSslOptions, 0)
13941 + HTTP_ARG_VAL(ssl_optins, 0)
13944 +HTTP_EMPTY_ARGS(getHeaders);
13945 +HTTP_BEGIN_ARGS(setHeaders, 0)
13946 + HTTP_ARG_VAL(headers, 0)
13949 +HTTP_BEGIN_ARGS(addHeaders, 1)
13950 + HTTP_ARG_VAL(headers, 0)
13953 +HTTP_EMPTY_ARGS(getCookies);
13954 +HTTP_BEGIN_ARGS(setCookies, 0)
13955 + HTTP_ARG_VAL(cookies, 0)
13958 +HTTP_BEGIN_ARGS(addCookies, 1)
13959 + HTTP_ARG_VAL(cookies, 0)
13962 +HTTP_EMPTY_ARGS(enableCookies);
13963 +HTTP_BEGIN_ARGS(resetCookies, 0)
13964 + HTTP_ARG_VAL(session_only, 0)
13966 +HTTP_EMPTY_ARGS(flushCookies);
13968 +HTTP_EMPTY_ARGS(getUrl);
13969 +HTTP_BEGIN_ARGS(setUrl, 1)
13970 + HTTP_ARG_VAL(url, 0)
13973 +HTTP_EMPTY_ARGS(getMethod);
13974 +HTTP_BEGIN_ARGS(setMethod, 1)
13975 + HTTP_ARG_VAL(request_method, 0)
13978 +HTTP_EMPTY_ARGS(getContentType);
13979 +HTTP_BEGIN_ARGS(setContentType, 1)
13980 + HTTP_ARG_VAL(content_type, 0)
13983 +HTTP_EMPTY_ARGS(getQueryData);
13984 +HTTP_BEGIN_ARGS(setQueryData, 0)
13985 + HTTP_ARG_VAL(query_data, 0)
13988 +HTTP_BEGIN_ARGS(addQueryData, 1)
13989 + HTTP_ARG_VAL(query_data, 0)
13992 +HTTP_EMPTY_ARGS(getPostFields);
13993 +HTTP_BEGIN_ARGS(setPostFields, 0)
13994 + HTTP_ARG_VAL(post_fields, 0)
13997 +HTTP_BEGIN_ARGS(addPostFields, 1)
13998 + HTTP_ARG_VAL(post_fields, 0)
14001 +HTTP_EMPTY_ARGS(getPostFiles);
14002 +HTTP_BEGIN_ARGS(setPostFiles, 0)
14003 + HTTP_ARG_VAL(post_files, 0)
14006 +HTTP_BEGIN_ARGS(addPostFile, 2)
14007 + HTTP_ARG_VAL(formname, 0)
14008 + HTTP_ARG_VAL(filename, 0)
14009 + HTTP_ARG_VAL(content_type, 0)
14012 +HTTP_EMPTY_ARGS(getBody);
14013 +HTTP_BEGIN_ARGS(setBody, 0)
14014 + HTTP_ARG_VAL(request_body_data, 0)
14017 +HTTP_BEGIN_ARGS(addBody, 1)
14018 + HTTP_ARG_VAL(request_body_data, 0)
14021 +HTTP_EMPTY_ARGS(getPutFile);
14022 +HTTP_BEGIN_ARGS(setPutFile, 0)
14023 + HTTP_ARG_VAL(filename, 0)
14026 +HTTP_EMPTY_ARGS(getPutData);
14027 +HTTP_BEGIN_ARGS(setPutData, 0)
14028 + HTTP_ARG_VAL(put_data, 0)
14031 +HTTP_BEGIN_ARGS(addPutData, 1)
14032 + HTTP_ARG_VAL(put_data, 0)
14035 +HTTP_EMPTY_ARGS(getResponseData);
14036 +HTTP_BEGIN_ARGS(getResponseHeader, 0)
14037 + HTTP_ARG_VAL(name, 0)
14040 +HTTP_BEGIN_ARGS(getResponseCookies, 0)
14041 + HTTP_ARG_VAL(flags, 0)
14042 + HTTP_ARG_VAL(allowed_extras, 0)
14045 +HTTP_EMPTY_ARGS(getResponseBody);
14046 +HTTP_EMPTY_ARGS(getResponseCode);
14047 +HTTP_EMPTY_ARGS(getResponseStatus);
14048 +HTTP_BEGIN_ARGS(getResponseInfo, 0)
14049 + HTTP_ARG_VAL(name, 0)
14052 +HTTP_EMPTY_ARGS(getMessageClass);
14053 +HTTP_BEGIN_ARGS(setMessageClass, 1)
14054 + HTTP_ARG_VAL(message_class_name, 0)
14057 +HTTP_EMPTY_ARGS(getResponseMessage);
14058 +HTTP_EMPTY_ARGS(getRawResponseMessage);
14059 +HTTP_EMPTY_ARGS(getRequestMessage);
14060 +HTTP_EMPTY_ARGS(getRawRequestMessage);
14061 +HTTP_EMPTY_ARGS(getHistory);
14062 +HTTP_EMPTY_ARGS(clearHistory);
14063 +HTTP_EMPTY_ARGS(send);
14065 +HTTP_BEGIN_ARGS(get, 1)
14066 + HTTP_ARG_VAL(url, 0)
14067 + HTTP_ARG_VAL(options, 0)
14068 + HTTP_ARG_VAL(info, 1)
14071 +HTTP_BEGIN_ARGS(head, 1)
14072 + HTTP_ARG_VAL(url, 0)
14073 + HTTP_ARG_VAL(options, 0)
14074 + HTTP_ARG_VAL(info, 1)
14077 +HTTP_BEGIN_ARGS(postData, 2)
14078 + HTTP_ARG_VAL(url, 0)
14079 + HTTP_ARG_VAL(data, 0)
14080 + HTTP_ARG_VAL(options, 0)
14081 + HTTP_ARG_VAL(info, 1)
14084 +HTTP_BEGIN_ARGS(postFields, 2)
14085 + HTTP_ARG_VAL(url, 0)
14086 + HTTP_ARG_VAL(data, 0)
14087 + HTTP_ARG_VAL(options, 0)
14088 + HTTP_ARG_VAL(info, 1)
14091 +HTTP_BEGIN_ARGS(putData, 2)
14092 + HTTP_ARG_VAL(url, 0)
14093 + HTTP_ARG_VAL(data, 0)
14094 + HTTP_ARG_VAL(options, 0)
14095 + HTTP_ARG_VAL(info, 1)
14098 +HTTP_BEGIN_ARGS(putFile, 2)
14099 + HTTP_ARG_VAL(url, 0)
14100 + HTTP_ARG_VAL(file, 0)
14101 + HTTP_ARG_VAL(options, 0)
14102 + HTTP_ARG_VAL(info, 1)
14105 +HTTP_BEGIN_ARGS(putStream, 2)
14106 + HTTP_ARG_VAL(url, 0)
14107 + HTTP_ARG_VAL(stream, 0)
14108 + HTTP_ARG_VAL(options, 0)
14109 + HTTP_ARG_VAL(info, 1)
14112 +HTTP_BEGIN_ARGS(methodRegister, 1)
14113 + HTTP_ARG_VAL(method_name, 0)
14116 +HTTP_BEGIN_ARGS(methodUnregister, 1)
14117 + HTTP_ARG_VAL(method, 0)
14120 +HTTP_BEGIN_ARGS(methodName, 1)
14121 + HTTP_ARG_VAL(method_id, 0)
14124 +HTTP_BEGIN_ARGS(methodExists, 1)
14125 + HTTP_ARG_VAL(method, 0)
14128 +#ifdef HAVE_CURL_FORMGET
14129 +HTTP_BEGIN_ARGS(encodeBody, 2)
14130 + HTTP_ARG_VAL(fields, 0)
14131 + HTTP_ARG_VAL(files, 0)
14135 +#define THIS_CE http_request_object_ce
14136 +zend_class_entry *http_request_object_ce;
14137 +zend_function_entry http_request_object_fe[] = {
14138 + HTTP_REQUEST_ME(__construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
14140 + HTTP_REQUEST_ME(setOptions, ZEND_ACC_PUBLIC)
14141 + HTTP_REQUEST_ME(getOptions, ZEND_ACC_PUBLIC)
14142 + HTTP_REQUEST_ME(setSslOptions, ZEND_ACC_PUBLIC)
14143 + HTTP_REQUEST_ME(getSslOptions, ZEND_ACC_PUBLIC)
14144 + HTTP_REQUEST_ME(addSslOptions, ZEND_ACC_PUBLIC)
14146 + HTTP_REQUEST_ME(addHeaders, ZEND_ACC_PUBLIC)
14147 + HTTP_REQUEST_ME(getHeaders, ZEND_ACC_PUBLIC)
14148 + HTTP_REQUEST_ME(setHeaders, ZEND_ACC_PUBLIC)
14150 + HTTP_REQUEST_ME(addCookies, ZEND_ACC_PUBLIC)
14151 + HTTP_REQUEST_ME(getCookies, ZEND_ACC_PUBLIC)
14152 + HTTP_REQUEST_ME(setCookies, ZEND_ACC_PUBLIC)
14154 + HTTP_REQUEST_ME(enableCookies, ZEND_ACC_PUBLIC)
14155 + HTTP_REQUEST_ME(resetCookies, ZEND_ACC_PUBLIC)
14156 + HTTP_REQUEST_ME(flushCookies, ZEND_ACC_PUBLIC)
14158 + HTTP_REQUEST_ME(setMethod, ZEND_ACC_PUBLIC)
14159 + HTTP_REQUEST_ME(getMethod, ZEND_ACC_PUBLIC)
14161 + HTTP_REQUEST_ME(setUrl, ZEND_ACC_PUBLIC)
14162 + HTTP_REQUEST_ME(getUrl, ZEND_ACC_PUBLIC)
14164 + HTTP_REQUEST_ME(setContentType, ZEND_ACC_PUBLIC)
14165 + HTTP_REQUEST_ME(getContentType, ZEND_ACC_PUBLIC)
14167 + HTTP_REQUEST_ME(setQueryData, ZEND_ACC_PUBLIC)
14168 + HTTP_REQUEST_ME(getQueryData, ZEND_ACC_PUBLIC)
14169 + HTTP_REQUEST_ME(addQueryData, ZEND_ACC_PUBLIC)
14171 + HTTP_REQUEST_ME(setPostFields, ZEND_ACC_PUBLIC)
14172 + HTTP_REQUEST_ME(getPostFields, ZEND_ACC_PUBLIC)
14173 + HTTP_REQUEST_ME(addPostFields, ZEND_ACC_PUBLIC)
14175 + HTTP_REQUEST_ME(setBody, ZEND_ACC_PUBLIC)
14176 + HTTP_REQUEST_ME(getBody, ZEND_ACC_PUBLIC)
14177 + HTTP_REQUEST_ME(addBody, ZEND_ACC_PUBLIC)
14178 + HTTP_REQUEST_MALIAS(setRawPostData, setBody, ZEND_ACC_PUBLIC|ZEND_ACC_DEPRECATED)
14179 + HTTP_REQUEST_MALIAS(getRawPostData, getBody, ZEND_ACC_PUBLIC|ZEND_ACC_DEPRECATED)
14180 + HTTP_REQUEST_MALIAS(addRawPostData, addBody, ZEND_ACC_PUBLIC|ZEND_ACC_DEPRECATED)
14182 + HTTP_REQUEST_ME(setPostFiles, ZEND_ACC_PUBLIC)
14183 + HTTP_REQUEST_ME(addPostFile, ZEND_ACC_PUBLIC)
14184 + HTTP_REQUEST_ME(getPostFiles, ZEND_ACC_PUBLIC)
14186 + HTTP_REQUEST_ME(setPutFile, ZEND_ACC_PUBLIC)
14187 + HTTP_REQUEST_ME(getPutFile, ZEND_ACC_PUBLIC)
14189 + HTTP_REQUEST_ME(setPutData, ZEND_ACC_PUBLIC)
14190 + HTTP_REQUEST_ME(getPutData, ZEND_ACC_PUBLIC)
14191 + HTTP_REQUEST_ME(addPutData, ZEND_ACC_PUBLIC)
14193 + HTTP_REQUEST_ME(send, ZEND_ACC_PUBLIC)
14195 + HTTP_REQUEST_ME(getResponseData, ZEND_ACC_PUBLIC)
14196 + HTTP_REQUEST_ME(getResponseHeader, ZEND_ACC_PUBLIC)
14197 + HTTP_REQUEST_ME(getResponseCookies, ZEND_ACC_PUBLIC)
14198 + HTTP_REQUEST_ME(getResponseCode, ZEND_ACC_PUBLIC)
14199 + HTTP_REQUEST_ME(getResponseStatus, ZEND_ACC_PUBLIC)
14200 + HTTP_REQUEST_ME(getResponseBody, ZEND_ACC_PUBLIC)
14201 + HTTP_REQUEST_ME(getResponseInfo, ZEND_ACC_PUBLIC)
14202 + HTTP_REQUEST_ME(getResponseMessage, ZEND_ACC_PUBLIC)
14203 + HTTP_REQUEST_ME(getRawResponseMessage, ZEND_ACC_PUBLIC)
14204 + HTTP_REQUEST_ME(getRequestMessage, ZEND_ACC_PUBLIC)
14205 + HTTP_REQUEST_ME(getRawRequestMessage, ZEND_ACC_PUBLIC)
14206 + HTTP_REQUEST_ME(getHistory, ZEND_ACC_PUBLIC)
14207 + HTTP_REQUEST_ME(clearHistory, ZEND_ACC_PUBLIC)
14209 + HTTP_REQUEST_ME(getMessageClass, ZEND_ACC_PUBLIC)
14210 + HTTP_REQUEST_ME(setMessageClass, ZEND_ACC_PUBLIC)
14212 + HTTP_REQUEST_ME(factory, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
14214 + HTTP_REQUEST_ALIAS(get, http_get)
14215 + HTTP_REQUEST_ALIAS(head, http_head)
14216 + HTTP_REQUEST_ALIAS(postData, http_post_data)
14217 + HTTP_REQUEST_ALIAS(postFields, http_post_fields)
14218 + HTTP_REQUEST_ALIAS(putData, http_put_data)
14219 + HTTP_REQUEST_ALIAS(putFile, http_put_file)
14220 + HTTP_REQUEST_ALIAS(putStream, http_put_stream)
14222 + HTTP_REQUEST_ALIAS(methodRegister, http_request_method_register)
14223 + HTTP_REQUEST_ALIAS(methodUnregister, http_request_method_unregister)
14224 + HTTP_REQUEST_ALIAS(methodName, http_request_method_name)
14225 + HTTP_REQUEST_ALIAS(methodExists, http_request_method_exists)
14226 +#ifdef HAVE_CURL_FORMGET
14227 + HTTP_REQUEST_ALIAS(encodeBody, http_request_body_encode)
14229 + EMPTY_FUNCTION_ENTRY
14231 +static zend_object_handlers http_request_object_handlers;
14233 +PHP_MINIT_FUNCTION(http_request_object)
14235 + HTTP_REGISTER_CLASS_EX(HttpRequest, http_request_object, NULL, 0);
14236 + http_request_object_handlers.clone_obj = _http_request_object_clone_obj;
14238 + zend_declare_property_null(THIS_CE, ZEND_STRS("options")-1, ZEND_ACC_PRIVATE TSRMLS_CC);
14239 + zend_declare_property_null(THIS_CE, ZEND_STRS("postFields")-1, ZEND_ACC_PRIVATE TSRMLS_CC);
14240 + zend_declare_property_null(THIS_CE, ZEND_STRS("postFiles")-1, ZEND_ACC_PRIVATE TSRMLS_CC);
14241 + zend_declare_property_null(THIS_CE, ZEND_STRS("responseInfo")-1, ZEND_ACC_PRIVATE TSRMLS_CC);
14242 + zend_declare_property_null(THIS_CE, ZEND_STRS("responseMessage")-1, ZEND_ACC_PRIVATE TSRMLS_CC);
14243 + zend_declare_property_long(THIS_CE, ZEND_STRS("responseCode")-1, 0, ZEND_ACC_PRIVATE TSRMLS_CC);
14244 + zend_declare_property_string(THIS_CE, ZEND_STRS("responseStatus")-1, "", ZEND_ACC_PRIVATE TSRMLS_CC);
14245 + zend_declare_property_long(THIS_CE, ZEND_STRS("method")-1, HTTP_GET, ZEND_ACC_PRIVATE TSRMLS_CC);
14246 + zend_declare_property_string(THIS_CE, ZEND_STRS("url")-1, "", ZEND_ACC_PRIVATE TSRMLS_CC);
14247 + zend_declare_property_string(THIS_CE, ZEND_STRS("contentType")-1, "", ZEND_ACC_PRIVATE TSRMLS_CC);
14248 + zend_declare_property_string(THIS_CE, ZEND_STRS("requestBody")-1, "", ZEND_ACC_PRIVATE TSRMLS_CC);
14249 + zend_declare_property_string(THIS_CE, ZEND_STRS("queryData")-1, "", ZEND_ACC_PRIVATE TSRMLS_CC);
14250 + zend_declare_property_string(THIS_CE, ZEND_STRS("putFile")-1, "", ZEND_ACC_PRIVATE TSRMLS_CC);
14251 + zend_declare_property_string(THIS_CE, ZEND_STRS("putData")-1, "", ZEND_ACC_PRIVATE TSRMLS_CC);
14252 + zend_declare_property_null(THIS_CE, ZEND_STRS("history")-1, ZEND_ACC_PRIVATE TSRMLS_CC);
14253 + zend_declare_property_bool(THIS_CE, ZEND_STRS("recordHistory")-1, 0, ZEND_ACC_PUBLIC TSRMLS_CC);
14254 + zend_declare_property_string(THIS_CE, ZEND_STRS("messageClass")-1, "", ZEND_ACC_PRIVATE TSRMLS_CC);
14258 + * Request Method Constants
14261 + zend_declare_class_constant_long(THIS_CE, ZEND_STRS("METH_GET")-1, HTTP_GET TSRMLS_CC);
14262 + zend_declare_class_constant_long(THIS_CE, ZEND_STRS("METH_HEAD")-1, HTTP_HEAD TSRMLS_CC);
14263 + zend_declare_class_constant_long(THIS_CE, ZEND_STRS("METH_POST")-1, HTTP_POST TSRMLS_CC);
14264 + zend_declare_class_constant_long(THIS_CE, ZEND_STRS("METH_PUT")-1, HTTP_PUT TSRMLS_CC);
14265 + zend_declare_class_constant_long(THIS_CE, ZEND_STRS("METH_DELETE")-1, HTTP_DELETE TSRMLS_CC);
14266 + zend_declare_class_constant_long(THIS_CE, ZEND_STRS("METH_OPTIONS")-1, HTTP_OPTIONS TSRMLS_CC);
14267 + zend_declare_class_constant_long(THIS_CE, ZEND_STRS("METH_TRACE")-1, HTTP_TRACE TSRMLS_CC);
14268 + zend_declare_class_constant_long(THIS_CE, ZEND_STRS("METH_CONNECT")-1, HTTP_CONNECT TSRMLS_CC);
14269 + /* WebDAV - RFC 2518 */
14270 + zend_declare_class_constant_long(THIS_CE, ZEND_STRS("METH_PROPFIND")-1, HTTP_PROPFIND TSRMLS_CC);
14271 + zend_declare_class_constant_long(THIS_CE, ZEND_STRS("METH_PROPPATCH")-1, HTTP_PROPPATCH TSRMLS_CC);
14272 + zend_declare_class_constant_long(THIS_CE, ZEND_STRS("METH_MKCOL")-1, HTTP_MKCOL TSRMLS_CC);
14273 + zend_declare_class_constant_long(THIS_CE, ZEND_STRS("METH_COPY")-1, HTTP_COPY TSRMLS_CC);
14274 + zend_declare_class_constant_long(THIS_CE, ZEND_STRS("METH_MOVE")-1, HTTP_MOVE TSRMLS_CC);
14275 + zend_declare_class_constant_long(THIS_CE, ZEND_STRS("METH_LOCK")-1, HTTP_LOCK TSRMLS_CC);
14276 + zend_declare_class_constant_long(THIS_CE, ZEND_STRS("METH_UNLOCK")-1, HTTP_UNLOCK TSRMLS_CC);
14277 + /* WebDAV Versioning - RFC 3253 */
14278 + zend_declare_class_constant_long(THIS_CE, ZEND_STRS("METH_VERSION_CONTROL")-1, HTTP_VERSION_CONTROL TSRMLS_CC);
14279 + zend_declare_class_constant_long(THIS_CE, ZEND_STRS("METH_REPORT")-1, HTTP_REPORT TSRMLS_CC);
14280 + zend_declare_class_constant_long(THIS_CE, ZEND_STRS("METH_CHECKOUT")-1, HTTP_CHECKOUT TSRMLS_CC);
14281 + zend_declare_class_constant_long(THIS_CE, ZEND_STRS("METH_CHECKIN")-1, HTTP_CHECKIN TSRMLS_CC);
14282 + zend_declare_class_constant_long(THIS_CE, ZEND_STRS("METH_UNCHECKOUT")-1, HTTP_UNCHECKOUT TSRMLS_CC);
14283 + zend_declare_class_constant_long(THIS_CE, ZEND_STRS("METH_MKWORKSPACE")-1, HTTP_MKWORKSPACE TSRMLS_CC);
14284 + zend_declare_class_constant_long(THIS_CE, ZEND_STRS("METH_UPDATE")-1, HTTP_UPDATE TSRMLS_CC);
14285 + zend_declare_class_constant_long(THIS_CE, ZEND_STRS("METH_LABEL")-1, HTTP_LABEL TSRMLS_CC);
14286 + zend_declare_class_constant_long(THIS_CE, ZEND_STRS("METH_MERGE")-1, HTTP_MERGE TSRMLS_CC);
14287 + zend_declare_class_constant_long(THIS_CE, ZEND_STRS("METH_BASELINE_CONTROL")-1, HTTP_BASELINE_CONTROL TSRMLS_CC);
14288 + zend_declare_class_constant_long(THIS_CE, ZEND_STRS("METH_MKACTIVITY")-1, HTTP_MKACTIVITY TSRMLS_CC);
14289 + /* WebDAV Access Control - RFC 3744 */
14290 + zend_declare_class_constant_long(THIS_CE, ZEND_STRS("METH_ACL")-1, HTTP_ACL TSRMLS_CC);
14293 + * HTTP Protocol Version Constants
14295 + zend_declare_class_constant_long(THIS_CE, ZEND_STRS("VERSION_1_0")-1, CURL_HTTP_VERSION_1_0 TSRMLS_CC);
14296 + zend_declare_class_constant_long(THIS_CE, ZEND_STRS("VERSION_1_1")-1, CURL_HTTP_VERSION_1_1 TSRMLS_CC);
14297 + zend_declare_class_constant_long(THIS_CE, ZEND_STRS("VERSION_NONE")-1, CURL_HTTP_VERSION_NONE TSRMLS_CC); /* to be removed */
14298 + zend_declare_class_constant_long(THIS_CE, ZEND_STRS("VERSION_ANY")-1, CURL_HTTP_VERSION_NONE TSRMLS_CC);
14301 + * SSL Version Constants
14303 + zend_declare_class_constant_long(THIS_CE, ZEND_STRS("SSL_VERSION_TLSv1")-1, CURL_SSLVERSION_TLSv1 TSRMLS_CC);
14304 + zend_declare_class_constant_long(THIS_CE, ZEND_STRS("SSL_VERSION_SSLv2")-1, CURL_SSLVERSION_SSLv2 TSRMLS_CC);
14305 + zend_declare_class_constant_long(THIS_CE, ZEND_STRS("SSL_VERSION_SSLv3")-1, CURL_SSLVERSION_SSLv3 TSRMLS_CC);
14306 + zend_declare_class_constant_long(THIS_CE, ZEND_STRS("SSL_VERSION_ANY")-1, CURL_SSLVERSION_DEFAULT TSRMLS_CC);
14309 + * DNS IPvX resolving
14311 + zend_declare_class_constant_long(THIS_CE, ZEND_STRS("IPRESOLVE_V4")-1, CURL_IPRESOLVE_V4 TSRMLS_CC);
14312 + zend_declare_class_constant_long(THIS_CE, ZEND_STRS("IPRESOLVE_V6")-1, CURL_IPRESOLVE_V6 TSRMLS_CC);
14313 + zend_declare_class_constant_long(THIS_CE, ZEND_STRS("IPRESOLVE_ANY")-1, CURL_IPRESOLVE_WHATEVER TSRMLS_CC);
14318 + zend_declare_class_constant_long(THIS_CE, ZEND_STRS("AUTH_BASIC")-1, CURLAUTH_BASIC TSRMLS_CC);
14319 + zend_declare_class_constant_long(THIS_CE, ZEND_STRS("AUTH_DIGEST")-1, CURLAUTH_DIGEST TSRMLS_CC);
14320 +#if HTTP_CURL_VERSION(7,19,3)
14321 + zend_declare_class_constant_long(THIS_CE, ZEND_STRS("AUTH_DIGEST_IE")-1, CURLAUTH_DIGEST_IE TSRMLS_CC);
14323 + zend_declare_class_constant_long(THIS_CE, ZEND_STRS("AUTH_NTLM")-1, CURLAUTH_NTLM TSRMLS_CC);
14324 + zend_declare_class_constant_long(THIS_CE, ZEND_STRS("AUTH_GSSNEG")-1, CURLAUTH_GSSNEGOTIATE TSRMLS_CC);
14325 + zend_declare_class_constant_long(THIS_CE, ZEND_STRS("AUTH_ANY")-1, CURLAUTH_ANY TSRMLS_CC);
14328 + * Proxy Type Constants
14330 +# if HTTP_CURL_VERSION(7,15,2)
14331 + zend_declare_class_constant_long(THIS_CE, ZEND_STRS("PROXY_SOCKS4")-1, CURLPROXY_SOCKS4 TSRMLS_CC);
14333 +#if HTTP_CURL_VERSION(7,18,0)
14334 + zend_declare_class_constant_long(THIS_CE, ZEND_STRS("PROXY_SOCKS4A")-1, CURLPROXY_SOCKS5 TSRMLS_CC);
14335 + zend_declare_class_constant_long(THIS_CE, ZEND_STRS("PROXY_SOCKS5_HOSTNAME")-1, CURLPROXY_SOCKS5 TSRMLS_CC);
14337 + zend_declare_class_constant_long(THIS_CE, ZEND_STRS("PROXY_SOCKS5")-1, CURLPROXY_SOCKS5 TSRMLS_CC);
14338 + zend_declare_class_constant_long(THIS_CE, ZEND_STRS("PROXY_HTTP")-1, CURLPROXY_HTTP TSRMLS_CC);
14339 +# if HTTP_CURL_VERSION(7,19,4)
14340 + zend_declare_class_constant_long(THIS_CE, ZEND_STRS("PROXY_HTTP_1_0")-1, CURLPROXY_HTTP_1_0 TSRMLS_CC);
14342 +#endif /* WONKY */
14345 + * Post Redirection Constants
14347 +#if HTTP_CURL_VERSION(7,19,1)
14348 + zend_declare_class_constant_long(THIS_CE, ZEND_STRS("POSTREDIR_301")-1, CURL_REDIR_POST_301 TSRMLS_CC);
14349 + zend_declare_class_constant_long(THIS_CE, ZEND_STRS("POSTREDIR_302")-1, CURL_REDIR_POST_302 TSRMLS_CC);
14350 + zend_declare_class_constant_long(THIS_CE, ZEND_STRS("POSTREDIR_ALL")-1, CURL_REDIR_POST_ALL TSRMLS_CC);
14356 +zend_object_value _http_request_object_new(zend_class_entry *ce TSRMLS_DC)
14358 + return http_request_object_new_ex(ce, NULL, NULL);
14361 +zend_object_value _http_request_object_new_ex(zend_class_entry *ce, CURL *ch, http_request_object **ptr TSRMLS_DC)
14363 + zend_object_value ov;
14364 + http_request_object *o;
14366 + o = ecalloc(1, sizeof(http_request_object));
14368 + o->request = http_request_init_ex(NULL, ch, 0, NULL);
14374 +#ifdef ZEND_ENGINE_2_4
14375 + zend_object_std_init(o, ce TSRMLS_CC);
14376 + object_properties_init(o, ce);
14378 + ALLOC_HASHTABLE(OBJ_PROP(o));
14379 + zend_hash_init(OBJ_PROP(o), zend_hash_num_elements(&ce->default_properties), NULL, ZVAL_PTR_DTOR, 0);
14380 + zend_hash_copy(OBJ_PROP(o), &ce->default_properties, (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *));
14383 + ov.handle = putObject(http_request_object, o);
14384 + ov.handlers = &http_request_object_handlers;
14389 +zend_object_value _http_request_object_clone_obj(zval *this_ptr TSRMLS_DC)
14391 + zend_object_value new_ov;
14392 + http_request_object *new_obj;
14393 + getObject(http_request_object, old_obj);
14395 + new_ov = http_request_object_new_ex(old_obj->zo.ce, NULL, &new_obj);
14396 + if (old_obj->request->ch) {
14397 + http_curl_init_ex(http_curl_copy(old_obj->request->ch), new_obj->request);
14400 + zend_objects_clone_members(&new_obj->zo, new_ov, &old_obj->zo, Z_OBJ_HANDLE_P(this_ptr) TSRMLS_CC);
14401 + phpstr_append(&new_obj->request->conv.request, old_obj->request->conv.request.data, old_obj->request->conv.request.used);
14402 + phpstr_append(&new_obj->request->conv.response, old_obj->request->conv.response.data, old_obj->request->conv.response.used);
14407 +void _http_request_object_free(zend_object *object TSRMLS_DC)
14409 + http_request_object *o = (http_request_object *) object;
14411 + http_request_free(&o->request);
14415 +#define http_request_object_check_request_content_type(t) _http_request_object_check_request_content_type((t) TSRMLS_CC)
14416 +static inline void _http_request_object_check_request_content_type(zval *this_ptr TSRMLS_DC)
14418 + zval *ctype = zend_read_property(THIS_CE, getThis(), ZEND_STRS("contentType")-1, 0 TSRMLS_CC);
14420 + if (Z_STRLEN_P(ctype)) {
14421 + zval **headers, *opts = zend_read_property(THIS_CE, getThis(), ZEND_STRS("options")-1, 0 TSRMLS_CC);
14423 + if ( (Z_TYPE_P(opts) == IS_ARRAY) &&
14424 + (SUCCESS == zend_hash_find(Z_ARRVAL_P(opts), "headers", sizeof("headers"), (void *) &headers)) &&
14425 + (Z_TYPE_PP(headers) == IS_ARRAY)) {
14426 + zval **ct_header;
14428 + /* only override if not already set */
14429 + if ((SUCCESS != zend_hash_find(Z_ARRVAL_PP(headers), "Content-Type", sizeof("Content-Type"), (void *) &ct_header))) {
14430 + add_assoc_stringl(*headers, "Content-Type", Z_STRVAL_P(ctype), Z_STRLEN_P(ctype), 1);
14432 + /* or not a string, zero length string or a string of spaces */
14433 + if ((Z_TYPE_PP(ct_header) != IS_STRING) || !Z_STRLEN_PP(ct_header)) {
14434 + add_assoc_stringl(*headers, "Content-Type", Z_STRVAL_P(ctype), Z_STRLEN_P(ctype), 1);
14436 + int i, only_space = 1;
14438 + /* check for spaces only */
14439 + for (i = 0; i < Z_STRLEN_PP(ct_header); ++i) {
14440 + if (!HTTP_IS_CTYPE(space, Z_STRVAL_PP(ct_header)[i])) {
14445 + if (only_space) {
14446 + add_assoc_stringl(*headers, "Content-Type", Z_STRVAL_P(ctype), Z_STRLEN_P(ctype), 1);
14452 + MAKE_STD_ZVAL(headers);
14453 + array_init(headers);
14454 + add_assoc_stringl(headers, "Content-Type", Z_STRVAL_P(ctype), Z_STRLEN_P(ctype), 1);
14455 + zend_call_method_with_1_params(&getThis(), Z_OBJCE_P(getThis()), NULL, "addheaders", NULL, headers);
14456 + zval_ptr_dtor(&headers);
14461 +#define http_request_object_message(zo, msg) _http_request_object_message((zo), (msg) TSRMLS_CC)
14462 +static inline zend_object_value _http_request_object_message(zval *this_ptr, http_message *msg TSRMLS_DC)
14464 + zend_object_value ov;
14465 + zval *zcn = zend_read_property(THIS_CE, getThis(), ZEND_STRS("messageClass")-1, 0 TSRMLS_CC);
14467 + if (Z_STRLEN_P(zcn) && (SUCCESS == http_object_new(&ov, Z_STRVAL_P(zcn), Z_STRLEN_P(zcn), _http_message_object_new_ex, http_message_object_ce, msg, NULL))) {
14470 + return http_message_object_new_ex(http_message_object_ce, msg, NULL);
14474 +STATUS _http_request_object_requesthandler(http_request_object *obj, zval *this_ptr TSRMLS_DC)
14476 + STATUS status = SUCCESS;
14477 + char *url = http_absolute_url(Z_STRVAL_P(zend_read_property(THIS_CE, getThis(), ZEND_STRS("url")-1, 0 TSRMLS_CC)));
14483 + http_request_reset(obj->request);
14484 + obj->request->url = url;
14485 + HTTP_CHECK_CURL_INIT(obj->request->ch, http_curl_init(obj->request), return FAILURE);
14487 + switch (obj->request->meth = Z_LVAL_P(zend_read_property(THIS_CE, getThis(), ZEND_STRS("method")-1, 0 TSRMLS_CC)))
14495 + zval *put_file = zend_read_property(THIS_CE, getThis(), ZEND_STRS("putFile")-1, 0 TSRMLS_CC);
14497 + http_request_object_check_request_content_type(getThis());
14499 + if (Z_STRLEN_P(put_file)) {
14500 + php_stream_statbuf ssb;
14501 + php_stream *stream = php_stream_open_wrapper_ex(Z_STRVAL_P(put_file), "rb", REPORT_ERRORS|ENFORCE_SAFE_MODE, NULL, HTTP_DEFAULT_STREAM_CONTEXT);
14503 + if (stream && SUCCESS == php_stream_stat(stream, &ssb)) {
14504 + obj->request->body = http_request_body_init_ex(obj->request->body, HTTP_REQUEST_BODY_UPLOADFILE, stream, ssb.sb.st_size, 1);
14506 + status = FAILURE;
14509 + zval *put_data = zend_read_property(THIS_CE, getThis(), ZEND_STRS("putData")-1, 0 TSRMLS_CC);
14510 + obj->request->body = http_request_body_init_ex(obj->request->body, HTTP_REQUEST_BODY_CSTRING,
14511 + estrndup(Z_STRVAL_P(put_data), Z_STRLEN_P(put_data)), Z_STRLEN_P(put_data), 1);
14519 + /* check for raw request body */
14520 + zval *raw_data = zend_read_property(THIS_CE, getThis(), ZEND_STRS("requestBody")-1, 0 TSRMLS_CC);
14522 + if (Z_STRLEN_P(raw_data)) {
14523 + http_request_object_check_request_content_type(getThis());
14524 + obj->request->body = http_request_body_init_ex(obj->request->body, HTTP_REQUEST_BODY_CSTRING,
14525 + estrndup(Z_STRVAL_P(raw_data), Z_STRLEN_P(raw_data)), Z_STRLEN_P(raw_data), 1);
14527 + zval *zfields = zend_read_property(THIS_CE, getThis(), ZEND_STRS("postFields")-1, 0 TSRMLS_CC), *zfiles = zend_read_property(THIS_CE, getThis(), ZEND_STRS("postFiles")-1, 0 TSRMLS_CC);
14528 + HashTable *fields;
14529 + HashTable *files;
14531 + fields = (Z_TYPE_P(zfields) == IS_ARRAY) ? Z_ARRVAL_P(zfields) : NULL;
14532 + files = (Z_TYPE_P(zfiles) == IS_ARRAY) ? Z_ARRVAL_P(zfiles) : NULL;
14534 + if ((fields && zend_hash_num_elements(fields)) || (files && zend_hash_num_elements(files))) {
14535 + if (!(obj->request->body = http_request_body_fill(obj->request->body, fields, files))) {
14536 + status = FAILURE;
14544 + if (status == SUCCESS) {
14545 + zval *qdata = zend_read_property(THIS_CE, getThis(), ZEND_STRS("queryData")-1, 0 TSRMLS_CC);
14546 + zval *options = zend_read_property(THIS_CE, getThis(), ZEND_STRS("options")-1, 0 TSRMLS_CC);
14548 + if (Z_STRLEN_P(qdata)) {
14549 + if (!strchr(obj->request->url, '?')) {
14550 + strlcat(obj->request->url, "?", HTTP_URL_MAXLEN);
14552 + strlcat(obj->request->url, "&", HTTP_URL_MAXLEN);
14554 + strlcat(obj->request->url, Z_STRVAL_P(qdata), HTTP_URL_MAXLEN);
14557 + http_request_prepare(obj->request, Z_ARRVAL_P(options));
14559 + /* check if there's a onProgress method and add it as progress callback if one isn't already set */
14560 + if (zend_hash_exists(&Z_OBJCE_P(getThis())->function_table, "onprogress", sizeof("onprogress"))) {
14561 + zval **entry, *pcb;
14563 + if ( (Z_TYPE_P(options) != IS_ARRAY)
14564 + || (SUCCESS != zend_hash_find(Z_ARRVAL_P(options), "onprogress", sizeof("onprogress"), (void *) &entry)
14565 + || (!HTTP_IS_CALLABLE(*entry, 0, NULL)))) {
14566 + MAKE_STD_ZVAL(pcb);
14568 + ZVAL_ADDREF(getThis());
14569 + add_next_index_zval(pcb, getThis());
14570 + add_next_index_stringl(pcb, "onprogress", lenof("onprogress"), 1);
14571 + http_request_set_progress_callback(obj->request, pcb);
14572 + zval_ptr_dtor(&pcb);
14580 +STATUS _http_request_object_responsehandler(http_request_object *obj, zval *this_ptr TSRMLS_DC)
14584 + http_message *msg;
14586 + /* always fetch info */
14587 + MAKE_STD_ZVAL(info);
14588 + array_init(info);
14589 + http_request_info(obj->request, Z_ARRVAL_P(info));
14590 + zend_update_property(THIS_CE, getThis(), ZEND_STRS("responseInfo")-1, info TSRMLS_CC);
14591 + zval_ptr_dtor(&info);
14593 + /* parse response message */
14594 + phpstr_fix(&obj->request->conv.request);
14595 + phpstr_fix(&obj->request->conv.response);
14597 + if ((msg = http_message_parse(PHPSTR_VAL(&obj->request->conv.response), PHPSTR_LEN(&obj->request->conv.response)))) {
14600 + if (i_zend_is_true(zend_read_property(THIS_CE, getThis(), ZEND_STRS("recordHistory")-1, 0 TSRMLS_CC))) {
14601 + zval *hist, *history = zend_read_property(THIS_CE, getThis(), ZEND_STRS("history")-1, 0 TSRMLS_CC);
14602 + http_message *response = http_message_parse(PHPSTR_VAL(&obj->request->conv.response), PHPSTR_LEN(&obj->request->conv.response));
14603 + http_message *request = http_message_parse(PHPSTR_VAL(&obj->request->conv.request), PHPSTR_LEN(&obj->request->conv.request));
14605 + MAKE_STD_ZVAL(hist);
14606 + ZVAL_OBJVAL(hist, http_request_object_message(getThis(), http_message_interconnect(response, request)), 0);
14607 + if (Z_TYPE_P(history) == IS_OBJECT) {
14608 + http_message_object_prepend(hist, history);
14610 + zend_update_property(THIS_CE, getThis(), ZEND_STRS("history")-1, hist TSRMLS_CC);
14611 + zval_ptr_dtor(&hist);
14614 + zend_update_property_long(THIS_CE, getThis(), ZEND_STRS("responseCode")-1, msg->http.info.response.code TSRMLS_CC);
14615 + zend_update_property_string(THIS_CE, getThis(), ZEND_STRS("responseStatus")-1, STR_PTR(msg->http.info.response.status) TSRMLS_CC);
14617 + MAKE_STD_ZVAL(message);
14618 + ZVAL_OBJVAL(message, http_request_object_message(getThis(), msg), 0);
14619 + zend_update_property(THIS_CE, getThis(), ZEND_STRS("responseMessage")-1, message TSRMLS_CC);
14620 + zval_ptr_dtor(&message);
14624 + /* update properties with empty values*/
14627 + MAKE_STD_ZVAL(znull);
14628 + ZVAL_NULL(znull);
14629 + zend_update_property(THIS_CE, getThis(), ZEND_STRS("responseMessage")-1, znull TSRMLS_CC);
14630 + zval_ptr_dtor(&znull);
14632 + zend_update_property_long(THIS_CE, getThis(), ZEND_STRS("responseCode")-1, 0 TSRMLS_CC);
14633 + zend_update_property_string(THIS_CE, getThis(), ZEND_STRS("responseStatus")-1, "" TSRMLS_CC);
14635 + /* append request message to history */
14636 + if (i_zend_is_true(zend_read_property(THIS_CE, getThis(), ZEND_STRS("recordHistory")-1, 0 TSRMLS_CC))) {
14637 + http_message *request;
14639 + if ((request = http_message_parse(PHPSTR_VAL(&obj->request->conv.request), PHPSTR_LEN(&obj->request->conv.request)))) {
14640 + zval *hist, *history = zend_read_property(THIS_CE, getThis(), ZEND_STRS("history")-1, 0 TSRMLS_CC);
14642 + MAKE_STD_ZVAL(hist);
14643 + ZVAL_OBJVAL(hist, http_request_object_message(getThis(), request), 0);
14644 + if (Z_TYPE_P(history) == IS_OBJECT) {
14645 + http_message_object_prepend(hist, history);
14647 + zend_update_property(THIS_CE, getThis(), ZEND_STRS("history")-1, hist TSRMLS_CC);
14648 + zval_ptr_dtor(&hist);
14655 + http_request_set_progress_callback(obj->request, NULL);
14657 + if (!EG(exception) && zend_hash_exists(&Z_OBJCE_P(getThis())->function_table, "onfinish", sizeof("onfinish"))) {
14660 + MAKE_STD_ZVAL(param);
14661 + ZVAL_BOOL(param, ret == SUCCESS);
14662 + with_error_handling(EH_NORMAL, NULL) {
14663 + zend_call_method_with_1_params(&getThis(), Z_OBJCE_P(getThis()), NULL, "onfinish", NULL, param);
14664 + } end_error_handling();
14665 + zval_ptr_dtor(¶m);
14670 +#ifdef ZEND_ENGINE_2_4
14671 +# define APK_DC TSRMLS_DC
14675 +static int apply_pretty_key(void *pDest APK_DC, int num_args, va_list args, zend_hash_key *hash_key)
14677 + if (hash_key->arKey && hash_key->nKeyLength > 1) {
14678 + hash_key->h = zend_hash_func(pretty_key(hash_key->arKey, hash_key->nKeyLength - 1, 1, 0), hash_key->nKeyLength);
14680 + return ZEND_HASH_APPLY_KEEP;
14683 +#define http_request_object_set_options_subr(key, ow, pk) \
14684 + _http_request_object_set_options_subr(INTERNAL_FUNCTION_PARAM_PASSTHRU, (key), sizeof(key), (ow), (pk))
14685 +static inline void _http_request_object_set_options_subr(INTERNAL_FUNCTION_PARAMETERS, char *key, size_t len, int overwrite, int prettify_keys)
14687 + zval *old_opts, *new_opts, *opts = NULL, **entry = NULL;
14689 + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|a/!", &opts)) {
14693 + MAKE_STD_ZVAL(new_opts);
14694 + array_init(new_opts);
14695 + old_opts = zend_read_property(THIS_CE, getThis(), ZEND_STRS("options")-1, 0 TSRMLS_CC);
14696 + if (Z_TYPE_P(old_opts) == IS_ARRAY) {
14697 + array_copy(Z_ARRVAL_P(old_opts), Z_ARRVAL_P(new_opts));
14700 + if (SUCCESS == zend_hash_find(Z_ARRVAL_P(new_opts), key, len, (void *) &entry)) {
14702 + zend_hash_clean(Z_ARRVAL_PP(entry));
14704 + if (opts && zend_hash_num_elements(Z_ARRVAL_P(opts))) {
14706 + array_copy(Z_ARRVAL_P(opts), Z_ARRVAL_PP(entry));
14708 + array_join(Z_ARRVAL_P(opts), Z_ARRVAL_PP(entry), 0, prettify_keys ? ARRAY_JOIN_PRETTIFY : 0);
14711 + } else if (opts) {
14712 + if (prettify_keys) {
14713 + zend_hash_apply_with_arguments(Z_ARRVAL_P(opts) HTTP_ZAPI_HASH_TSRMLS_CC, apply_pretty_key, 0, NULL);
14715 + ZVAL_ADDREF(opts);
14716 + add_assoc_zval_ex(new_opts, key, len, opts);
14718 + zend_update_property(THIS_CE, getThis(), ZEND_STRS("options")-1, new_opts TSRMLS_CC);
14719 + zval_ptr_dtor(&new_opts);
14724 +#define http_request_object_get_options_subr(key) \
14725 + _http_request_get_options_subr(INTERNAL_FUNCTION_PARAM_PASSTHRU, (key), sizeof(key))
14726 +static inline void _http_request_get_options_subr(INTERNAL_FUNCTION_PARAMETERS, char *key, size_t len)
14730 + if (return_value_used) {
14731 + zval *opts, **options;
14733 + opts = zend_read_property(THIS_CE, getThis(), ZEND_STRS("options")-1, 0 TSRMLS_CC);
14734 + array_init(return_value);
14736 + if ( (Z_TYPE_P(opts) == IS_ARRAY) &&
14737 + (SUCCESS == zend_hash_find(Z_ARRVAL_P(opts), key, len, (void *) &options))) {
14738 + convert_to_array(*options);
14739 + array_copy(Z_ARRVAL_PP(options), Z_ARRVAL_P(return_value));
14745 +/* ### USERLAND ### */
14747 +/* {{{ proto void HttpRequest::__construct([string url[, int request_method = HTTP_METH_GET[, array options]]])
14748 + Create a new HttpRequest object instance. */
14749 +PHP_METHOD(HttpRequest, __construct)
14751 + char *URL = NULL;
14754 + zval *options = NULL;
14756 + SET_EH_THROW_HTTP();
14757 + if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|sla!", &URL, &URL_len, &meth, &options)) {
14759 + zend_update_property_stringl(THIS_CE, getThis(), ZEND_STRS("url")-1, URL, URL_len TSRMLS_CC);
14762 + zend_update_property_long(THIS_CE, getThis(), ZEND_STRS("method")-1, meth TSRMLS_CC);
14765 + zend_call_method_with_1_params(&getThis(), Z_OBJCE_P(getThis()), NULL, "setoptions", NULL, options);
14772 +/* {{{ proto HttpRequest HttpRequest::factory([string url[, int request_method HTTP_METH_GET[, array options[, string class_name = "HttpRequest"]]]])
14773 + Create a new HttpRequest object instance. */
14774 +PHP_METHOD(HttpRequest, factory)
14776 + char *cn = NULL, *URL = NULL;
14777 + int cl = 0, URL_len = 0;
14779 + zval *options = NULL;
14780 + zend_object_value ov;
14782 + SET_EH_THROW_HTTP();
14783 + if ( SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|sla!s", &URL, &URL_len, &meth, &options, &cn, &cl) &&
14784 + SUCCESS == http_object_new(&ov, cn, cl, _http_request_object_new_ex, http_request_object_ce, NULL, NULL)) {
14785 + RETVAL_OBJVAL(ov, 0);
14786 + getThis() = return_value;
14788 + zend_update_property_stringl(THIS_CE, getThis(), ZEND_STRS("url")-1, URL, URL_len TSRMLS_CC);
14791 + zend_update_property_long(THIS_CE, getThis(), ZEND_STRS("method")-1, meth TSRMLS_CC);
14794 + zend_call_method_with_1_params(&getThis(), Z_OBJCE_P(getThis()), NULL, "setoptions", NULL, options);
14801 +/* {{{ proto bool HttpRequest::setOptions([array options])
14802 + Set the request options to use. See http_get() for a full list of available options. */
14803 +PHP_METHOD(HttpRequest, setOptions)
14805 + HashKey key = initHashKey(0);
14806 + HashPosition pos;
14807 + zval *opts = NULL, *old_opts, *new_opts, *add_opts, **opt;
14809 + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|a!/", &opts)) {
14813 + MAKE_STD_ZVAL(new_opts);
14814 + array_init(new_opts);
14816 + if (!opts || !zend_hash_num_elements(Z_ARRVAL_P(opts))) {
14817 + zend_update_property(THIS_CE, getThis(), ZEND_STRS("options")-1, new_opts TSRMLS_CC);
14818 + zval_ptr_dtor(&new_opts);
14822 + MAKE_STD_ZVAL(add_opts);
14823 + array_init(add_opts);
14824 + /* some options need extra attention -- thus cannot use array_merge() directly */
14825 + FOREACH_KEYVAL(pos, opts, key, opt) {
14826 + if (key.type == HASH_KEY_IS_STRING) {
14827 +#define KEYMATCH(k, s) ((sizeof(s)==k.len) && !strcasecmp(k.str, s))
14828 + if (KEYMATCH(key, "headers")) {
14829 + zend_call_method_with_1_params(&getThis(), Z_OBJCE_P(getThis()), NULL, "addheaders", NULL, *opt);
14830 + } else if (KEYMATCH(key, "cookies")) {
14831 + zend_call_method_with_1_params(&getThis(), Z_OBJCE_P(getThis()), NULL, "addcookies", NULL, *opt);
14832 + } else if (KEYMATCH(key, "ssl")) {
14833 + zend_call_method_with_1_params(&getThis(), Z_OBJCE_P(getThis()), NULL, "addssloptions", NULL, *opt);
14834 + } else if (KEYMATCH(key, "url") || KEYMATCH(key, "uri")) {
14835 + zend_call_method_with_1_params(&getThis(), Z_OBJCE_P(getThis()), NULL, "seturl", NULL, *opt);
14836 + } else if (KEYMATCH(key, "method")) {
14837 + zend_call_method_with_1_params(&getThis(), Z_OBJCE_P(getThis()), NULL, "setmethod", NULL, *opt);
14838 + } else if (KEYMATCH(key, "flushcookies")) {
14839 + getObject(http_request_object, obj);
14840 + if (i_zend_is_true(*opt)) {
14841 + http_request_flush_cookies(obj->request);
14843 + } else if (KEYMATCH(key, "resetcookies")) {
14844 + getObject(http_request_object, obj);
14845 + http_request_reset_cookies(obj->request, (zend_bool) i_zend_is_true(*opt));
14846 + } else if (KEYMATCH(key, "enablecookies")) {
14847 + getObject(http_request_object, obj);
14848 + http_request_enable_cookies(obj->request);
14849 + } else if (KEYMATCH(key, "recordHistory")) {
14850 + zend_update_property(THIS_CE, getThis(), ZEND_STRS("recordHistory")-1, *opt TSRMLS_CC);
14851 + } else if (KEYMATCH(key, "messageClass")) {
14852 + zend_call_method_with_1_params(&getThis(), Z_OBJCE_P(getThis()), NULL, "setmessageclass", NULL, *opt);
14853 + } else if (Z_TYPE_PP(opt) == IS_NULL) {
14854 + old_opts = zend_read_property(THIS_CE, getThis(), ZEND_STRS("options")-1, 0 TSRMLS_CC);
14855 + if (Z_TYPE_P(old_opts) == IS_ARRAY) {
14856 + zend_hash_del(Z_ARRVAL_P(old_opts), key.str, key.len);
14859 + ZVAL_ADDREF(*opt);
14860 + add_assoc_zval_ex(add_opts, key.str, key.len, *opt);
14865 + old_opts = zend_read_property(THIS_CE, getThis(), ZEND_STRS("options")-1, 0 TSRMLS_CC);
14866 + if (Z_TYPE_P(old_opts) == IS_ARRAY) {
14867 + array_copy(Z_ARRVAL_P(old_opts), Z_ARRVAL_P(new_opts));
14869 + array_join(Z_ARRVAL_P(add_opts), Z_ARRVAL_P(new_opts), 0, 0);
14870 + zend_update_property(THIS_CE, getThis(), ZEND_STRS("options")-1, new_opts TSRMLS_CC);
14871 + zval_ptr_dtor(&new_opts);
14872 + zval_ptr_dtor(&add_opts);
14878 +/* {{{ proto array HttpRequest::getOptions()
14879 + Get currently set options. */
14880 +PHP_METHOD(HttpRequest, getOptions)
14884 + if (return_value_used) {
14885 + RETURN_PROP(options);
14890 +/* {{{ proto bool HttpRequest::setSslOptions([array options])
14891 + Set SSL options. */
14892 +PHP_METHOD(HttpRequest, setSslOptions)
14894 + http_request_object_set_options_subr("ssl", 1, 0);
14898 +/* {{{ proto bool HttpRequest::addSslOptions(array options)
14899 + Set additional SSL options. */
14900 +PHP_METHOD(HttpRequest, addSslOptions)
14902 + http_request_object_set_options_subr("ssl", 0, 0);
14906 +/* {{{ proto array HttpRequest::getSslOtpions()
14907 + Get previously set SSL options. */
14908 +PHP_METHOD(HttpRequest, getSslOptions)
14910 + http_request_object_get_options_subr("ssl");
14914 +/* {{{ proto bool HttpRequest::addHeaders(array headers)
14915 + Add request header name/value pairs. */
14916 +PHP_METHOD(HttpRequest, addHeaders)
14918 + http_request_object_set_options_subr("headers", 0, 1);
14921 +/* {{{ proto bool HttpRequest::setHeaders([array headers])
14922 + Set request header name/value pairs. */
14923 +PHP_METHOD(HttpRequest, setHeaders)
14925 + http_request_object_set_options_subr("headers", 1, 1);
14929 +/* {{{ proto array HttpRequest::getHeaders()
14930 + Get previously set request headers. */
14931 +PHP_METHOD(HttpRequest, getHeaders)
14933 + http_request_object_get_options_subr("headers");
14937 +/* {{{ proto bool HttpRequest::setCookies([array cookies])
14939 +PHP_METHOD(HttpRequest, setCookies)
14941 + http_request_object_set_options_subr("cookies", 1, 0);
14945 +/* {{{ proto bool HttpRequest::addCookies(array cookies)
14947 +PHP_METHOD(HttpRequest, addCookies)
14949 + http_request_object_set_options_subr("cookies", 0, 0);
14953 +/* {{{ proto array HttpRequest::getCookies()
14954 + Get previously set cookies. */
14955 +PHP_METHOD(HttpRequest, getCookies)
14957 + http_request_object_get_options_subr("cookies");
14961 +/* {{{ proto bool HttpRequest::enableCookies()
14962 + Enable automatic sending of received cookies. Note that customly set cookies will be sent anyway. */
14963 +PHP_METHOD(HttpRequest, enableCookies)
14966 + getObject(http_request_object, obj);
14967 + RETURN_SUCCESS(http_request_enable_cookies(obj->request));
14973 +/* {{{ proto bool HttpRequest::resetCookies([bool session_only = FALSE])
14974 + Reset all automatically received/sent cookies. Note that customly set cookies are not affected. */
14975 +PHP_METHOD(HttpRequest, resetCookies)
14977 + zend_bool session_only = 0;
14978 + getObject(http_request_object, obj);
14980 + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &session_only)) {
14983 + RETURN_SUCCESS(http_request_reset_cookies(obj->request, session_only));
14987 +/* {{{ proto bool HttpRequest::flushCookies()
14988 + Flush internal cookies to the cookiestore file */
14989 +PHP_METHOD(HttpRequest, flushCookies)
14992 + getObject(http_request_object, obj);
14993 + RETURN_SUCCESS(http_request_flush_cookies(obj->request));
14998 +/* {{{ proto bool HttpRequest::setUrl(string url)
14999 + Set the request URL. */
15000 +PHP_METHOD(HttpRequest, setUrl)
15002 + char *URL = NULL;
15005 + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &URL, &URL_len)) {
15009 + zend_update_property_stringl(THIS_CE, getThis(), ZEND_STRS("url")-1, URL, URL_len TSRMLS_CC);
15014 +/* {{{ proto string HttpRequest::getUrl()
15015 + Get the previously set request URL. */
15016 +PHP_METHOD(HttpRequest, getUrl)
15020 + if (return_value_used) {
15021 + RETURN_PROP(url);
15026 +/* {{{ proto bool HttpRequest::setMethod(int request_method)
15027 + Set the request method. */
15028 +PHP_METHOD(HttpRequest, setMethod)
15032 + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &meth)) {
15036 + zend_update_property_long(THIS_CE, getThis(), ZEND_STRS("method")-1, meth TSRMLS_CC);
15041 +/* {{{ proto int HttpRequest::getMethod()
15042 + Get the previously set request method. */
15043 +PHP_METHOD(HttpRequest, getMethod)
15047 + if (return_value_used) {
15048 + RETURN_PROP(method);
15053 +/* {{{ proto bool HttpRequest::setContentType(string content_type)
15054 + Set the content type the post request should have. */
15055 +PHP_METHOD(HttpRequest, setContentType)
15060 + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &ctype, &ct_len)) {
15065 + HTTP_CHECK_CONTENT_TYPE(ctype, RETURN_FALSE);
15067 + zend_update_property_stringl(THIS_CE, getThis(), ZEND_STRS("contentType")-1, ctype, ct_len TSRMLS_CC);
15072 +/* {{{ proto string HttpRequest::getContentType()
15073 + Get the previously content type. */
15074 +PHP_METHOD(HttpRequest, getContentType)
15078 + if (return_value_used) {
15079 + RETURN_PROP(contentType);
15084 +/* {{{ proto bool HttpRequest::setQueryData([mixed query_data])
15085 + Set the URL query parameters to use, overwriting previously set query parameters. */
15086 +PHP_METHOD(HttpRequest, setQueryData)
15088 + zval *qdata = NULL;
15090 + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z!", &qdata)) {
15094 + if ((!qdata) || Z_TYPE_P(qdata) == IS_NULL) {
15095 + zend_update_property_stringl(THIS_CE, getThis(), ZEND_STRS("queryData")-1, "", 0 TSRMLS_CC);
15096 + } else if ((Z_TYPE_P(qdata) == IS_ARRAY) || (Z_TYPE_P(qdata) == IS_OBJECT)) {
15097 + char *query_data = NULL;
15099 + if (SUCCESS != http_urlencode_hash(HASH_OF(qdata), &query_data)) {
15103 + zend_update_property_string(THIS_CE, getThis(), ZEND_STRS("queryData")-1, query_data TSRMLS_CC);
15104 + efree(query_data);
15106 + zval *data = http_zsep(IS_STRING, qdata);
15108 + zend_update_property_stringl(THIS_CE, getThis(), ZEND_STRS("queryData")-1, Z_STRVAL_P(data), Z_STRLEN_P(data) TSRMLS_CC);
15109 + zval_ptr_dtor(&data);
15115 +/* {{{ proto string HttpRequest::getQueryData()
15116 + Get the current query data in form of an urlencoded query string. */
15117 +PHP_METHOD(HttpRequest, getQueryData)
15121 + if (return_value_used) {
15122 + RETURN_PROP(queryData);
15127 +/* {{{ proto bool HttpRequest::addQueryData(array query_params)
15128 + Add parameters to the query parameter list, leaving previously set unchanged. */
15129 +PHP_METHOD(HttpRequest, addQueryData)
15131 + zval *qdata, *old_qdata;
15132 + char *query_data = NULL;
15133 + size_t query_data_len = 0;
15135 + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a/", &qdata)) {
15139 + old_qdata = zend_read_property(THIS_CE, getThis(), ZEND_STRS("queryData")-1, 0 TSRMLS_CC);
15141 + if (SUCCESS != http_urlencode_hash_ex(HASH_OF(qdata), 1, Z_STRVAL_P(old_qdata), Z_STRLEN_P(old_qdata), &query_data, &query_data_len)) {
15145 + zend_update_property_stringl(THIS_CE, getThis(), ZEND_STRS("queryData")-1, query_data, query_data_len TSRMLS_CC);
15146 + efree(query_data);
15152 +/* {{{ proto bool HttpRequest::addPostFields(array post_data)
15153 + Adds POST data entries, leaving previously set unchanged, unless a post entry with the same name already exists. */
15154 +PHP_METHOD(HttpRequest, addPostFields)
15156 + zval *post_data, *old_post, *new_post;
15158 + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a/", &post_data)) {
15162 + if (zend_hash_num_elements(Z_ARRVAL_P(post_data))) {
15163 + MAKE_STD_ZVAL(new_post);
15164 + array_init(new_post);
15165 + old_post = zend_read_property(THIS_CE, getThis(), ZEND_STRS("postFields")-1, 0 TSRMLS_CC);
15166 + if (Z_TYPE_P(old_post) == IS_ARRAY) {
15167 + array_copy(Z_ARRVAL_P(old_post), Z_ARRVAL_P(new_post));
15169 + array_join(Z_ARRVAL_P(post_data), Z_ARRVAL_P(new_post), 0, 0);
15170 + zend_update_property(THIS_CE, getThis(), ZEND_STRS("postFields")-1, new_post TSRMLS_CC);
15171 + zval_ptr_dtor(&new_post);
15178 +/* {{{ proto bool HttpRequest::setPostFields([array post_data])
15179 + Set the POST data entries, overwriting previously set POST data. */
15180 +PHP_METHOD(HttpRequest, setPostFields)
15182 + zval *post, *post_data = NULL;
15184 + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a/!", &post_data)) {
15188 + MAKE_STD_ZVAL(post);
15189 + array_init(post);
15190 + if (post_data && zend_hash_num_elements(Z_ARRVAL_P(post_data))) {
15191 + array_copy(Z_ARRVAL_P(post_data), Z_ARRVAL_P(post));
15193 + zend_update_property(THIS_CE, getThis(), ZEND_STRS("postFields")-1, post TSRMLS_CC);
15194 + zval_ptr_dtor(&post);
15200 +/* {{{ proto array HttpRequest::getPostFields()
15201 + Get previously set POST data. */
15202 +PHP_METHOD(HttpRequest, getPostFields)
15206 + if (return_value_used) {
15207 + RETURN_PROP(postFields);
15212 +/* {{{ proto bool HttpRequest::setBody([string request_body_data])
15213 + Set request body to send, overwriting previously set request body. Don't forget to specify a content type. */
15214 +PHP_METHOD(HttpRequest, setBody)
15216 + char *raw_data = NULL;
15217 + int data_len = 0;
15219 + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &raw_data, &data_len)) {
15227 + zend_update_property_stringl(THIS_CE, getThis(), ZEND_STRS("requestBody")-1, raw_data, data_len TSRMLS_CC);
15232 +/* {{{ proto bool HttpRequest::addBody(string request_body_data)
15233 + Add request body data, leaving previously set request body data unchanged. */
15234 +PHP_METHOD(HttpRequest, addBody)
15239 + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &raw_data, &data_len)) {
15244 + zval *data = zend_read_property(THIS_CE, getThis(), ZEND_STRS("requestBody")-1, 0 TSRMLS_CC);
15246 + if (Z_STRLEN_P(data)) {
15247 + Z_STRVAL_P(data) = erealloc(Z_STRVAL_P(data), (Z_STRLEN_P(data) += data_len) + 1);
15248 + Z_STRVAL_P(data)[Z_STRLEN_P(data)] = '\0';
15249 + memcpy(Z_STRVAL_P(data) + Z_STRLEN_P(data) - data_len, raw_data, data_len);
15251 + zend_update_property_stringl(THIS_CE, getThis(), ZEND_STRS("requestBody")-1, raw_data, data_len TSRMLS_CC);
15259 +/* {{{ proto string HttpRequest::getBody()
15260 + Get previously set request body data. */
15261 +PHP_METHOD(HttpRequest, getBody)
15265 + if (return_value_used) {
15266 + RETURN_PROP(requestBody);
15271 +/* {{{ proto bool HttpRequest::addPostFile(string name, string file[, string content_type = "application/x-octetstream"])
15272 + Add a file to the POST request, leaving previously set files unchanged. */
15273 +PHP_METHOD(HttpRequest, addPostFile)
15275 + zval *entry, *old_post, *new_post;
15276 + char *name, *file, *type = NULL;
15277 + int name_len, file_len, type_len = 0;
15279 + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|s", &name, &name_len, &file, &file_len, &type, &type_len)) {
15284 + HTTP_CHECK_CONTENT_TYPE(type, RETURN_FALSE);
15286 + type = "application/x-octetstream";
15287 + type_len = sizeof("application/x-octetstream") - 1;
15290 + MAKE_STD_ZVAL(entry);
15291 + array_init(entry);
15293 + add_assoc_stringl(entry, "name", name, name_len, 1);
15294 + add_assoc_stringl(entry, "type", type, type_len, 1);
15295 + add_assoc_stringl(entry, "file", file, file_len, 1);
15297 + MAKE_STD_ZVAL(new_post);
15298 + array_init(new_post);
15299 + old_post = zend_read_property(THIS_CE, getThis(), ZEND_STRS("postFiles")-1, 0 TSRMLS_CC);
15300 + if (Z_TYPE_P(old_post) == IS_ARRAY) {
15301 + array_copy(Z_ARRVAL_P(old_post), Z_ARRVAL_P(new_post));
15303 + add_next_index_zval(new_post, entry);
15304 + zend_update_property(THIS_CE, getThis(), ZEND_STRS("postFiles")-1, new_post TSRMLS_CC);
15305 + zval_ptr_dtor(&new_post);
15311 +/* {{{ proto bool HttpRequest::setPostFiles([array post_files])
15312 + Set files to post, overwriting previously set post files. */
15313 +PHP_METHOD(HttpRequest, setPostFiles)
15315 + zval *files = NULL, *post;
15317 + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a!/", &files)) {
15321 + MAKE_STD_ZVAL(post);
15322 + array_init(post);
15323 + if (files && (Z_TYPE_P(files) == IS_ARRAY)) {
15324 + array_copy(Z_ARRVAL_P(files), Z_ARRVAL_P(post));
15326 + zend_update_property(THIS_CE, getThis(), ZEND_STRS("postFiles")-1, post TSRMLS_CC);
15327 + zval_ptr_dtor(&post);
15333 +/* {{{ proto array HttpRequest::getPostFiles()
15334 + Get all previously added POST files. */
15335 +PHP_METHOD(HttpRequest, getPostFiles)
15339 + if (return_value_used) {
15340 + RETURN_PROP(postFiles);
15345 +/* {{{ proto bool HttpRequest::setPutFile([string file])
15346 + Set file to put. Affects only PUT requests. */
15347 +PHP_METHOD(HttpRequest, setPutFile)
15350 + int file_len = 0;
15352 + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &file, &file_len)) {
15356 + zend_update_property_stringl(THIS_CE, getThis(), ZEND_STRS("putFile")-1, file, file_len TSRMLS_CC);
15361 +/* {{{ proto string HttpRequest::getPutFile()
15362 + Get previously set put file. */
15363 +PHP_METHOD(HttpRequest, getPutFile)
15367 + if (return_value_used) {
15368 + RETURN_PROP(putFile);
15373 +/* {{{ proto bool HttpRequest::setPutData([string put_data])
15374 + Set PUT data to send, overwriting previously set PUT data. */
15375 +PHP_METHOD(HttpRequest, setPutData)
15377 + char *put_data = NULL;
15378 + int data_len = 0;
15380 + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &put_data, &data_len)) {
15388 + zend_update_property_stringl(THIS_CE, getThis(), ZEND_STRS("putData")-1, put_data, data_len TSRMLS_CC);
15393 +/* {{{ proto bool HttpRequest::addPutData(string put_data)
15394 + Add PUT data, leaving previously set PUT data unchanged. */
15395 +PHP_METHOD(HttpRequest, addPutData)
15400 + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &put_data, &data_len)) {
15405 + zval *data = zend_read_property(THIS_CE, getThis(), ZEND_STRS("putData")-1, 0 TSRMLS_CC);
15407 + if (Z_STRLEN_P(data)) {
15408 + Z_STRVAL_P(data) = erealloc(Z_STRVAL_P(data), (Z_STRLEN_P(data) += data_len) + 1);
15409 + Z_STRVAL_P(data)[Z_STRLEN_P(data)] = '\0';
15410 + memcpy(Z_STRVAL_P(data) + Z_STRLEN_P(data) - data_len, put_data, data_len);
15412 + zend_update_property_stringl(THIS_CE, getThis(), ZEND_STRS("putData")-1, put_data, data_len TSRMLS_CC);
15420 +/* {{{ proto string HttpRequest::getPutData()
15421 + Get previously set PUT data. */
15422 +PHP_METHOD(HttpRequest, getPutData)
15426 + if (return_value_used) {
15427 + RETURN_PROP(putData);
15432 +/* {{{ proto array HttpRequest::getResponseData()
15433 + Get all response data after the request has been sent. */
15434 +PHP_METHOD(HttpRequest, getResponseData)
15438 + if (return_value_used) {
15441 + zval *headers, *message = zend_read_property(THIS_CE, getThis(), ZEND_STRS("responseMessage")-1, 0 TSRMLS_CC);
15443 + if (Z_TYPE_P(message) == IS_OBJECT) {
15444 + getObjectEx(http_message_object, msg, message);
15446 + array_init(return_value);
15448 + MAKE_STD_ZVAL(headers);
15449 + array_init(headers);
15450 + zend_hash_copy(Z_ARRVAL_P(headers), &msg->message->hdrs, (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *));
15451 + add_assoc_zval(return_value, "headers", headers);
15453 + phpstr_data(PHPSTR(msg->message), &body, &body_len);
15454 + add_assoc_stringl(return_value, "body", body, body_len, 0);
15460 +/* {{{ proto mixed HttpRequest::getResponseHeader([string name])
15461 + Get response header(s) after the request has been sent. */
15462 +PHP_METHOD(HttpRequest, getResponseHeader)
15464 + if (return_value_used) {
15466 + char *header_name = NULL;
15467 + int header_len = 0;
15469 + if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &header_name, &header_len)) {
15470 + zval *message = zend_read_property(THIS_CE, getThis(), ZEND_STRS("responseMessage")-1, 0 TSRMLS_CC);
15472 + if (Z_TYPE_P(message) == IS_OBJECT) {
15473 + getObjectEx(http_message_object, msg, message);
15475 + if (header_len) {
15476 + if ((header = http_message_header_ex(msg->message, pretty_key(header_name, header_len, 1, 1), header_len + 1, 0))) {
15477 + RETURN_ZVAL(header, 1, 1);
15480 + array_init(return_value);
15481 + zend_hash_copy(Z_ARRVAL_P(return_value), &msg->message->hdrs, (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *));
15491 +/* {{{ proto array HttpRequest::getResponseCookies([int flags[, array allowed_extras]])
15492 + Get response cookie(s) after the request has been sent. */
15493 +PHP_METHOD(HttpRequest, getResponseCookies)
15495 + if (return_value_used) {
15497 + zval *allowed_extras_array = NULL;
15499 + if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|la!", &flags, &allowed_extras_array)) {
15501 + HashKey key = initHashKey(0);
15502 + char **allowed_extras = NULL;
15503 + zval **header = NULL, **entry = NULL, *message = zend_read_property(THIS_CE, getThis(), ZEND_STRS("responseMessage")-1, 0 TSRMLS_CC);
15504 + HashPosition pos, pos1, pos2;
15506 + if (Z_TYPE_P(message) == IS_OBJECT) {
15507 + getObjectEx(http_message_object, msg, message);
15509 + array_init(return_value);
15511 + if (allowed_extras_array) {
15512 + allowed_extras = ecalloc(zend_hash_num_elements(Z_ARRVAL_P(allowed_extras_array)) + 1, sizeof(char *));
15513 + FOREACH_VAL(pos, allowed_extras_array, entry) {
15514 + zval *data = http_zsep(IS_STRING, *entry);
15515 + allowed_extras[i++] = estrndup(Z_STRVAL_P(data), Z_STRLEN_P(data));
15516 + zval_ptr_dtor(&data);
15520 + FOREACH_HASH_KEYVAL(pos1, &msg->message->hdrs, key, header) {
15521 + if (key.type == HASH_KEY_IS_STRING && !strcasecmp(key.str, "Set-Cookie")) {
15522 + http_cookie_list list;
15524 + if (Z_TYPE_PP(header) == IS_ARRAY) {
15525 + zval **single_header;
15527 + FOREACH_VAL(pos2, *header, single_header) {
15528 + zval *data = http_zsep(IS_STRING, *single_header);
15530 + if (http_parse_cookie_ex(&list, Z_STRVAL_P(data), flags, allowed_extras)) {
15533 + MAKE_STD_ZVAL(cookie);
15534 + object_init(cookie);
15535 + http_cookie_list_tostruct(&list, cookie);
15536 + add_next_index_zval(return_value, cookie);
15537 + http_cookie_list_dtor(&list);
15539 + zval_ptr_dtor(&data);
15542 + zval *data = http_zsep(IS_STRING, *header);
15543 + if (http_parse_cookie_ex(&list, Z_STRVAL_P(data), flags, allowed_extras)) {
15546 + MAKE_STD_ZVAL(cookie);
15547 + object_init(cookie);
15548 + http_cookie_list_tostruct(&list, cookie);
15549 + add_next_index_zval(return_value, cookie);
15550 + http_cookie_list_dtor(&list);
15552 + zval_ptr_dtor(&data);
15557 + if (allowed_extras) {
15558 + for (i = 0; allowed_extras[i]; ++i) {
15559 + efree(allowed_extras[i]);
15561 + efree(allowed_extras);
15572 +/* {{{ proto string HttpRequest::getResponseBody()
15573 + Get the response body after the request has been sent. */
15574 +PHP_METHOD(HttpRequest, getResponseBody)
15578 + if (return_value_used) {
15579 + zval *message = zend_read_property(THIS_CE, getThis(), ZEND_STRS("responseMessage")-1, 0 TSRMLS_CC);
15581 + if (Z_TYPE_P(message) == IS_OBJECT) {
15582 + getObjectEx(http_message_object, msg, message);
15583 + RETURN_PHPSTR_DUP(&msg->message->body);
15591 +/* {{{ proto int HttpRequest::getResponseCode()
15592 + Get the response code after the request has been sent. */
15593 +PHP_METHOD(HttpRequest, getResponseCode)
15597 + if (return_value_used) {
15598 + RETURN_PROP(responseCode);
15603 +/* {{{ proto string HttpRequest::getResponseStatus()
15604 + Get the response status (i.e. the string after the response code) after the message has been sent. */
15605 +PHP_METHOD(HttpRequest, getResponseStatus)
15609 + if (return_value_used) {
15610 + RETURN_PROP(responseStatus);
15615 +/* {{{ proto mixed HttpRequest::getResponseInfo([string name])
15616 + Get response info after the request has been sent. */
15617 +PHP_METHOD(HttpRequest, getResponseInfo)
15619 + if (return_value_used) {
15620 + zval *info, **infop;
15621 + char *info_name = NULL;
15622 + int info_len = 0;
15624 + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &info_name, &info_len)) {
15628 + info = zend_read_property(THIS_CE, getThis(), ZEND_STRS("responseInfo")-1, 0 TSRMLS_CC);
15630 + if (Z_TYPE_P(info) != IS_ARRAY) {
15634 + if (info_len && info_name) {
15635 + if (SUCCESS == zend_hash_find(Z_ARRVAL_P(info), pretty_key(info_name, info_len, 0, 0), info_len + 1, (void *) &infop)) {
15636 + RETURN_ZVAL(*infop, 1, 0);
15638 + http_error_ex(HE_NOTICE, HTTP_E_INVALID_PARAM, "Could not find response info named %s", info_name);
15642 + RETURN_ZVAL(info, 1, 0);
15648 +/* {{{ proto HttpMessage HttpRequest::getResponseMessage()
15649 + Get the full response as HttpMessage object after the request has been sent. */
15650 +PHP_METHOD(HttpRequest, getResponseMessage)
15655 + SET_EH_THROW_HTTP();
15656 + message = zend_read_property(THIS_CE, getThis(), ZEND_STRS("responseMessage")-1, 0 TSRMLS_CC);
15657 + if (Z_TYPE_P(message) == IS_OBJECT) {
15658 + RETVAL_OBJECT(message, 1);
15660 + http_error(HE_WARNING, HTTP_E_RUNTIME, "HttpRequest does not contain a response message");
15667 +/* {{{ proto HttpMessage HttpRequest::getRequestMessage()
15668 + Get sent HTTP message. */
15669 +PHP_METHOD(HttpRequest, getRequestMessage)
15673 + if (return_value_used) {
15674 + http_message *msg;
15675 + getObject(http_request_object, obj);
15677 + SET_EH_THROW_HTTP();
15678 + if ((msg = http_message_parse(PHPSTR_VAL(&obj->request->conv.request), PHPSTR_LEN(&obj->request->conv.request)))) {
15679 + RETVAL_OBJVAL(http_request_object_message(getThis(), msg), 0);
15686 +/* {{{ proto string HttpRequest::getRawRequestMessage()
15687 + Get sent HTTP message. */
15688 +PHP_METHOD(HttpRequest, getRawRequestMessage)
15692 + if (return_value_used) {
15693 + getObject(http_request_object, obj);
15695 + RETURN_PHPSTR_DUP(&obj->request->conv.request);
15700 +/* {{{ proto string HttpRequest::getRawResponseMessage()
15701 + Get the entire HTTP response. */
15702 +PHP_METHOD(HttpRequest, getRawResponseMessage)
15706 + if (return_value_used) {
15707 + getObject(http_request_object, obj);
15709 + RETURN_PHPSTR_DUP(&obj->request->conv.response);
15714 +/* {{{ proto HttpMessage HttpRequest::getHistory()
15715 + Get all sent requests and received responses as an HttpMessage object. */
15716 +PHP_METHOD(HttpRequest, getHistory)
15720 + if (return_value_used) {
15723 + SET_EH_THROW_HTTP();
15724 + hist = zend_read_property(THIS_CE, getThis(), ZEND_STRS("history")-1, 0 TSRMLS_CC);
15725 + if (Z_TYPE_P(hist) == IS_OBJECT) {
15726 + RETVAL_OBJECT(hist, 1);
15728 + http_error(HE_WARNING, HTTP_E_RUNTIME, "The history is empty");
15735 +/* {{{ proto void HttpRequest::clearHistory()
15736 + Clear the history. */
15737 +PHP_METHOD(HttpRequest, clearHistory)
15742 + MAKE_STD_ZVAL(hist);
15744 + zend_update_property(THIS_CE, getThis(), ZEND_STRS("history")-1, hist TSRMLS_CC);
15745 + zval_ptr_dtor(&hist);
15750 +/* {{{ proto string HttpRequest::getMessageClass()
15751 + Get the message class name. */
15752 +PHP_METHOD(HttpRequest, getMessageClass)
15756 + if (return_value_used) {
15757 + RETURN_PROP("messageClass");
15762 +/* {{{ proto void setMessageClass(string class_name)
15763 + Set the message class name. */
15764 +PHP_METHOD(HttpRequest, setMessageClass)
15769 + if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &cn, &cl)) {
15770 + zend_update_property_stringl(THIS_CE, getThis(), ZEND_STRS("messageClass")-1, cn, cl TSRMLS_CC);
15775 +/* {{{ proto HttpMessage HttpRequest::send()
15776 + Send the HTTP request. */
15777 +PHP_METHOD(HttpRequest, send)
15779 + getObject(http_request_object, obj);
15783 + SET_EH_THROW_HTTP();
15788 + http_error(HE_WARNING, HTTP_E_RUNTIME, "Cannot perform HttpRequest::send() while attached to an HttpRequestPool");
15789 + } else if (SUCCESS == http_request_object_requesthandler(obj, getThis())) {
15790 + http_request_exec(obj->request);
15791 + if (SUCCESS == http_request_object_responsehandler(obj, getThis())) {
15792 + RETVAL_OBJECT(zend_read_property(THIS_CE, getThis(), ZEND_STRS("responseMessage")-1, 0 TSRMLS_CC), 1);
15800 +#endif /* ZEND_ENGINE_2 && HTTP_HAVE_CURL */
15803 + * Local variables:
15805 + * c-basic-offset: 4
15807 + * vim600: noet sw=4 ts=4 fdm=marker
15808 + * vim<600: noet sw=4 ts=4
15812 +++ b/ext/http/http_request_pool_api.c
15815 + +--------------------------------------------------------------------+
15817 + +--------------------------------------------------------------------+
15818 + | Redistribution and use in source and binary forms, with or without |
15819 + | modification, are permitted provided that the conditions mentioned |
15820 + | in the accompanying LICENSE file are met. |
15821 + +--------------------------------------------------------------------+
15822 + | Copyright (c) 2004-2010, Michael Wallner <mike@php.net> |
15823 + +--------------------------------------------------------------------+
15826 +/* $Id: http_request_pool_api.c 292841 2009-12-31 08:48:57Z mike $ */
15828 +#define HTTP_WANT_CURL
15829 +#define HTTP_WANT_EVENT
15830 +#include "php_http.h"
15832 +#if defined(ZEND_ENGINE_2) && defined(HTTP_HAVE_CURL)
15834 +#include "php_http_api.h"
15835 +#include "php_http_exception_object.h"
15836 +#include "php_http_persistent_handle_api.h"
15837 +#include "php_http_request_api.h"
15838 +#include "php_http_request_object.h"
15839 +#include "php_http_request_pool_api.h"
15840 +#include "php_http_requestpool_object.h"
15842 +#ifndef HTTP_DEBUG_REQPOOLS
15843 +# define HTTP_DEBUG_REQPOOLS 0
15846 +#ifdef HTTP_HAVE_EVENT
15847 +typedef struct _http_request_pool_event_t {
15848 + struct event evnt;
15849 + http_request_pool *pool;
15850 +} http_request_pool_event;
15852 +static void http_request_pool_timeout_callback(int socket, short action, void *event_data);
15853 +static void http_request_pool_event_callback(int socket, short action, void *event_data);
15854 +static int http_request_pool_socket_callback(CURL *easy, curl_socket_t s, int action, void *, void *);
15855 +static void http_request_pool_timer_callback(CURLM *multi, long timeout_ms, void *timer_data);
15858 +static int http_request_pool_compare_handles(void *h1, void *h2);
15860 +PHP_MINIT_FUNCTION(http_request_pool)
15862 + if (SUCCESS != http_persistent_handle_provide("http_request_pool", curl_multi_init, (http_persistent_handle_dtor) curl_multi_cleanup, NULL)) {
15868 +#ifdef HTTP_HAVE_EVENT
15869 +PHP_RINIT_FUNCTION(http_request_pool)
15871 + if (!HTTP_G->request.pool.event.base && !(HTTP_G->request.pool.event.base = event_init())) {
15879 +/* {{{ http_request_pool *http_request_pool_init(http_request_pool *) */
15880 +PHP_HTTP_API http_request_pool *_http_request_pool_init(http_request_pool *pool TSRMLS_DC)
15882 + zend_bool free_pool;
15884 +#if HTTP_DEBUG_REQPOOLS
15885 + fprintf(stderr, "Initializing request pool %p\n", pool);
15888 + if ((free_pool = (!pool))) {
15889 + pool = emalloc(sizeof(http_request_pool));
15893 + if (SUCCESS != http_persistent_handle_acquire("http_request_pool", &pool->ch)) {
15900 + TSRMLS_SET_CTX(pool->tsrm_ls);
15902 +#ifdef HTTP_HAVE_EVENT
15903 + pool->timeout = ecalloc(1, sizeof(struct event));
15904 + curl_multi_setopt(pool->ch, CURLMOPT_SOCKETDATA, pool);
15905 + curl_multi_setopt(pool->ch, CURLMOPT_SOCKETFUNCTION, http_request_pool_socket_callback);
15906 + curl_multi_setopt(pool->ch, CURLMOPT_TIMERDATA, pool);
15907 + curl_multi_setopt(pool->ch, CURLMOPT_TIMERFUNCTION, http_request_pool_timer_callback);
15910 + pool->unfinished = 0;
15911 + zend_llist_init(&pool->finished, sizeof(zval *), (llist_dtor_func_t) ZVAL_PTR_DTOR, 0);
15912 + zend_llist_init(&pool->handles, sizeof(zval *), (llist_dtor_func_t) ZVAL_PTR_DTOR, 0);
15914 +#if HTTP_DEBUG_REQPOOLS
15915 + fprintf(stderr, "Initialized request pool %p\n", pool);
15922 +/* {{{ STATUS http_request_pool_attach(http_request_pool *, zval *) */
15923 +PHP_HTTP_API STATUS _http_request_pool_attach(http_request_pool *pool, zval *request)
15926 + TSRMLS_FETCH_FROM_CTX(pool->tsrm_ls);
15928 + getObjectEx(http_request_object, req, request);
15930 +#if HTTP_DEBUG_REQPOOLS
15931 + fprintf(stderr, "Attaching HttpRequest(#%d) %p to pool %p\n", Z_OBJ_HANDLE_P(request), req, pool);
15935 + http_error_ex(HE_WARNING, HTTP_E_INVALID_PARAM, "HttpRequest object(#%d) is already member of %s HttpRequestPool", Z_OBJ_HANDLE_P(request), req->pool == pool ? "this" : "another");
15936 + } else if (SUCCESS != http_request_object_requesthandler(req, request)) {
15937 + http_error_ex(HE_WARNING, HTTP_E_REQUEST, "Could not initialize HttpRequest object(#%d) for attaching to the HttpRequestPool", Z_OBJ_HANDLE_P(request));
15939 + CURLMcode code = curl_multi_add_handle(pool->ch, req->request->ch);
15941 + if (CURLM_OK != code) {
15942 + http_error_ex(HE_WARNING, HTTP_E_REQUEST_POOL, "Could not attach HttpRequest object(#%d) to the HttpRequestPool: %s", Z_OBJ_HANDLE_P(request), curl_multi_strerror(code));
15944 + req->pool = pool;
15946 + ZVAL_ADDREF(request);
15947 + zend_llist_add_element(&pool->handles, &request);
15948 + ++pool->unfinished;
15950 +#if HTTP_DEBUG_REQPOOLS
15951 + fprintf(stderr, "> %d HttpRequests attached to pool %p\n", zend_llist_count(&pool->handles), pool);
15960 +/* {{{ STATUS http_request_pool_detach(http_request_pool *, zval *) */
15961 +PHP_HTTP_API STATUS _http_request_pool_detach(http_request_pool *pool, zval *request)
15965 + TSRMLS_FETCH_FROM_CTX(pool->tsrm_ls);
15967 + getObjectEx(http_request_object, req, request);
15969 +#if HTTP_DEBUG_REQPOOLS
15970 + fprintf(stderr, "Detaching HttpRequest(#%d) %p from pool %p\n", Z_OBJ_HANDLE_P(request), req, pool);
15973 + if (!req->pool) {
15974 + /* not attached to any pool */
15975 +#if HTTP_DEBUG_REQPOOLS
15976 + fprintf(stderr, "HttpRequest object(#%d) %p is not attached to any HttpRequestPool\n", Z_OBJ_HANDLE_P(request), req);
15978 + } else if (req->pool != pool) {
15979 + http_error_ex(HE_WARNING, HTTP_E_INVALID_PARAM, "HttpRequest object(#%d) is not attached to this HttpRequestPool", Z_OBJ_HANDLE_P(request));
15980 + } else if (req->request->_in_progress_cb) {
15981 + http_error_ex(HE_WARNING, HTTP_E_REQUEST_POOL, "HttpRequest object(#%d) cannot be detached from the HttpRequestPool while executing the progress callback", Z_OBJ_HANDLE_P(request));
15982 + } else if (CURLM_OK != (code = curl_multi_remove_handle(pool->ch, req->request->ch))) {
15983 + http_error_ex(HE_WARNING, HTTP_E_REQUEST_POOL, "Could not detach HttpRequest object(#%d) from the HttpRequestPool: %s", Z_OBJ_HANDLE_P(request), curl_multi_strerror(code));
15985 + req->pool = NULL;
15986 + zend_llist_del_element(&pool->finished, request, http_request_pool_compare_handles);
15987 + zend_llist_del_element(&pool->handles, request, http_request_pool_compare_handles);
15989 +#if HTTP_DEBUG_REQPOOLS
15990 + fprintf(stderr, "> %d HttpRequests remaining in pool %p\n", zend_llist_count(&pool->handles), pool);
15999 +/* {{{ void http_request_pool_apply(http_request_pool *, http_request_pool_apply_func) */
16000 +PHP_HTTP_API void _http_request_pool_apply(http_request_pool *pool, http_request_pool_apply_func cb)
16002 + int count = zend_llist_count(&pool->handles);
16006 + zend_llist_position pos;
16007 + zval **handle, **handles = emalloc(count * sizeof(zval *));
16009 + for (handle = zend_llist_get_first_ex(&pool->handles, &pos); handle; handle = zend_llist_get_next_ex(&pool->handles, &pos)) {
16010 + handles[i++] = *handle;
16013 + /* should never happen */
16014 + if (i != count) {
16015 + zend_error(E_ERROR, "number of fetched request handles do not match overall count");
16019 + for (i = 0; i < count; ++i) {
16020 + if (cb(pool, handles[i])) {
16029 +/* {{{ void http_request_pool_apply_with_arg(http_request_pool *, http_request_pool_apply_with_arg_func, void *) */
16030 +PHP_HTTP_API void _http_request_pool_apply_with_arg(http_request_pool *pool, http_request_pool_apply_with_arg_func cb, void *arg)
16032 + int count = zend_llist_count(&pool->handles);
16036 + zend_llist_position pos;
16037 + zval **handle, **handles = emalloc(count * sizeof(zval *));
16039 + for (handle = zend_llist_get_first_ex(&pool->handles, &pos); handle; handle = zend_llist_get_next_ex(&pool->handles, &pos)) {
16040 + handles[i++] = *handle;
16043 + /* should never happen */
16044 + if (i != count) {
16045 + zend_error(E_ERROR, "number of fetched request handles do not match overall count");
16049 + for (i = 0; i < count; ++i) {
16050 + if (cb(pool, handles[i], arg)) {
16059 +/* {{{ void http_request_pool_detach_all(http_request_pool *) */
16060 +PHP_HTTP_API void _http_request_pool_detach_all(http_request_pool *pool)
16062 +#if HTTP_DEBUG_REQPOOLS
16063 + fprintf(stderr, "Detaching %d requests from pool %p\n", zend_llist_count(&pool->handles), pool);
16065 + http_request_pool_apply(pool, _http_request_pool_detach);
16069 +/* {{{ STATUS http_request_pool_send(http_request_pool *) */
16070 +PHP_HTTP_API STATUS _http_request_pool_send(http_request_pool *pool)
16072 + TSRMLS_FETCH_FROM_CTX(pool->tsrm_ls);
16074 +#if HTTP_DEBUG_REQPOOLS
16075 + fprintf(stderr, "Attempt to send %d requests of pool %p\n", zend_llist_count(&pool->handles), pool);
16078 +#ifdef HTTP_HAVE_EVENT
16079 + if (pool->useevents) {
16081 +#if HTTP_DEBUG_REQPOOLS
16082 + fprintf(stderr, "& Starting event dispatcher of pool %p\n", pool);
16084 + event_base_dispatch(HTTP_G->request.pool.event.base);
16085 + } while (pool->unfinished);
16089 + while (http_request_pool_perform(pool)) {
16090 + if (SUCCESS != http_request_pool_select(pool)) {
16092 + /* see http://msdn.microsoft.com/library/en-us/winsock/winsock/windows_sockets_error_codes_2.asp */
16093 + http_error_ex(HE_WARNING, HTTP_E_SOCKET, "WinSock error: %d", WSAGetLastError());
16095 + http_error(HE_WARNING, HTTP_E_SOCKET, strerror(errno));
16102 +#if HTTP_DEBUG_REQPOOLS
16103 + fprintf(stderr, "Finished sending %d HttpRequests of pool %p (still unfinished: %d)\n", zend_llist_count(&pool->handles), pool, pool->unfinished);
16110 +/* {{{ void http_request_pool_dtor(http_request_pool *) */
16111 +PHP_HTTP_API void _http_request_pool_dtor(http_request_pool *pool)
16113 + TSRMLS_FETCH_FROM_CTX(pool->tsrm_ls);
16115 +#if HTTP_DEBUG_REQPOOLS
16116 + fprintf(stderr, "Destructing request pool %p\n", pool);
16119 +#ifdef HTTP_HAVE_EVENT
16120 + efree(pool->timeout);
16123 + http_request_pool_detach_all(pool);
16125 + pool->unfinished = 0;
16126 + zend_llist_clean(&pool->finished);
16127 + zend_llist_clean(&pool->handles);
16128 + http_persistent_handle_release("http_request_pool", &pool->ch);
16133 +# define SELECT_ERROR SOCKET_ERROR
16135 +# define SELECT_ERROR -1
16138 +/* {{{ STATUS http_request_pool_select(http_request_pool *) */
16139 +PHP_HTTP_API STATUS _http_request_pool_select(http_request_pool *pool)
16141 + return http_request_pool_select_ex(pool, NULL);
16145 +/* {{{ STATUS http_request_pool_select_ex(http_request_pool *, struct timeval *) */
16146 +PHP_HTTP_API STATUS _http_request_pool_select_ex(http_request_pool *pool, struct timeval *custom_timeout)
16150 + struct timeval timeout;
16152 +#ifdef HTTP_HAVE_EVENT
16153 + if (pool->useevents) {
16154 + TSRMLS_FETCH_FROM_CTX(pool->tsrm_ls);
16155 + http_error(HE_WARNING, HTTP_E_RUNTIME, "not implemented; use HttpRequest callbacks");
16160 + if (custom_timeout && timerisset(custom_timeout)) {
16161 + timeout = *custom_timeout;
16163 + http_request_pool_timeout(pool, &timeout);
16170 + if (CURLM_OK == curl_multi_fdset(pool->ch, &R, &W, &E, &MAX)) {
16172 + http_sleep((double) timeout.tv_sec + (double) (timeout.tv_usec / HTTP_MCROSEC));
16174 + } else if (SELECT_ERROR != select(MAX + 1, &R, &W, &E, &timeout)) {
16182 +/* {{{ int http_request_pool_perform(http_request_pool *) */
16183 +PHP_HTTP_API int _http_request_pool_perform(http_request_pool *pool)
16185 + TSRMLS_FETCH_FROM_CTX(pool->tsrm_ls);
16187 +#ifdef HTTP_HAVE_EVENT
16188 + if (pool->useevents) {
16189 + http_error(HE_WARNING, HTTP_E_RUNTIME, "not implemented; use HttpRequest callbacks");
16194 + while (CURLM_CALL_MULTI_PERFORM == curl_multi_perform(pool->ch, &pool->unfinished));
16196 +#if HTTP_DEBUG_REQPOOLS
16197 + fprintf(stderr, "%u unfinished requests of pool %p remaining\n", pool->unfinished, pool);
16200 + http_request_pool_responsehandler(pool);
16202 + return pool->unfinished;
16206 +/* {{{ void http_request_pool_responsehandler(http_request_pool *) */
16207 +void _http_request_pool_responsehandler(http_request_pool *pool)
16210 + int remaining = 0;
16211 + TSRMLS_FETCH_FROM_CTX(pool->tsrm_ls);
16214 + msg = curl_multi_info_read(pool->ch, &remaining);
16215 + if (msg && CURLMSG_DONE == msg->msg) {
16216 + if (CURLE_OK != msg->data.result) {
16217 + http_request_storage *st = http_request_storage_get(msg->easy_handle);
16218 + http_error_ex(HE_WARNING, HTTP_E_REQUEST, "%s; %s (%s)", curl_easy_strerror(msg->data.result), st?st->errorbuffer:"", st?st->url:"");
16220 + http_request_pool_apply_with_arg(pool, _http_request_pool_apply_responsehandler, msg->easy_handle);
16222 + } while (remaining);
16226 +/* {{{ int http_request_pool_apply_responsehandler(http_request_pool *, zval *, void *) */
16227 +int _http_request_pool_apply_responsehandler(http_request_pool *pool, zval *req, void *ch)
16230 + TSRMLS_FETCH_FROM_CTX(pool->tsrm_ls);
16232 + getObjectEx(http_request_object, obj, req);
16234 + if ((!ch) || obj->request->ch == (CURL *) ch) {
16236 +#if HTTP_DEBUG_REQPOOLS
16237 + fprintf(stderr, "Fetching data from HttpRequest(#%d) %p of pool %p\n", Z_OBJ_HANDLE_P(req), obj, obj->pool);
16240 + ZVAL_ADDREF(req);
16241 + zend_llist_add_element(&obj->pool->finished, &req);
16242 + http_request_object_responsehandler(obj, req);
16249 +/* {{{ struct timeval *_http_request_pool_timeout(http_request_pool *, struct timeval *) */
16250 +struct timeval *_http_request_pool_timeout(http_request_pool *pool, struct timeval *timeout)
16252 +#ifdef HAVE_CURL_MULTI_TIMEOUT
16253 + long max_tout = 1000;
16255 + if ((CURLM_OK == curl_multi_timeout(pool->ch, &max_tout)) && (max_tout > 0)) {
16256 + timeout->tv_sec = max_tout / 1000;
16257 + timeout->tv_usec = (max_tout % 1000) * 1000;
16260 + timeout->tv_sec = 0;
16261 + timeout->tv_usec = 1000;
16262 +#ifdef HAVE_CURL_MULTI_TIMEOUT
16266 +#if HTTP_DEBUG_REQPOOLS
16267 + fprintf(stderr, "Calculating timeout (%lu, %lu) of pool %p\n", (ulong) timeout->tv_sec, (ulong) timeout->tv_usec, pool);
16276 +/* {{{ static int http_request_pool_compare_handles(void *, void *) */
16277 +static int http_request_pool_compare_handles(void *h1, void *h2)
16279 + return (Z_OBJ_HANDLE_PP((zval **) h1) == Z_OBJ_HANDLE_P((zval *) h2));
16283 +#ifdef HTTP_HAVE_EVENT
16284 +/* {{{ static void http_request_pool_timeout_callback(int, short, void *) */
16285 +static void http_request_pool_timeout_callback(int socket, short action, void *event_data)
16287 + http_request_pool *pool = event_data;
16289 + if (pool->useevents) {
16291 + TSRMLS_FETCH_FROM_CTX(pool->tsrm_ls);
16293 +#if HTTP_DEBUG_REQPOOLS
16294 + fprintf(stderr, "Timeout occurred of pool %p\n", pool);
16297 + while (CURLM_CALL_MULTI_PERFORM == (rc = curl_multi_socket(pool->ch, CURL_SOCKET_TIMEOUT, &pool->unfinished)));
16299 + if (CURLM_OK != rc) {
16300 + http_error(HE_WARNING, HTTP_E_SOCKET, curl_multi_strerror(rc));
16303 + http_request_pool_responsehandler(pool);
16308 +/* {{{ static void http_request_pool_event_callback(int, short, void *) */
16309 +static void http_request_pool_event_callback(int socket, short action, void *event_data)
16311 + http_request_pool_event *ev = event_data;
16312 + http_request_pool *pool = ev->pool;
16314 + if (pool->useevents) {
16315 + CURLMcode rc = CURLE_OK;
16316 + TSRMLS_FETCH_FROM_CTX(ev->pool->tsrm_ls);
16318 +#if HTTP_DEBUG_REQPOOLS
16320 + static const char event_strings[][20] = {"NONE","TIMEOUT","READ","TIMEOUT|READ","WRITE","TIMEOUT|WRITE","READ|WRITE","TIMEOUT|READ|WRITE","SIGNAL"};
16321 + fprintf(stderr, "Event on socket %d (%s) event %p of pool %p\n", socket, event_strings[action], ev, pool);
16325 + /* don't use 'ev' below this loop as it might 've been freed in the socket callback */
16327 +#ifdef HAVE_CURL_MULTI_SOCKET_ACTION
16328 + switch (action & (EV_READ|EV_WRITE)) {
16330 + rc = curl_multi_socket_action(pool->ch, socket, CURL_CSELECT_IN, &pool->unfinished);
16333 + rc = curl_multi_socket_action(pool->ch, socket, CURL_CSELECT_OUT, &pool->unfinished);
16335 + case EV_READ|EV_WRITE:
16336 + rc = curl_multi_socket_action(pool->ch, socket, CURL_CSELECT_IN|CURL_CSELECT_OUT, &pool->unfinished);
16339 + http_error_ex(HE_WARNING, HTTP_E_SOCKET, "Unknown event %d", (int) action);
16343 + rc = curl_multi_socket(pool->ch, socket, &pool->unfinished);
16345 + } while (CURLM_CALL_MULTI_PERFORM == rc);
16348 + case CURLM_BAD_SOCKET:
16350 + fprintf(stderr, "!!! Bad socket: %d (%d)\n", socket, (int) action);
16355 + http_error(HE_WARNING, HTTP_E_SOCKET, curl_multi_strerror(rc));
16359 + http_request_pool_responsehandler(pool);
16361 + /* remove timeout if there are no transfers left */
16362 + if (!pool->unfinished && event_initialized(pool->timeout) && event_pending(pool->timeout, EV_TIMEOUT, NULL)) {
16363 + event_del(pool->timeout);
16364 +#if HTTP_DEBUG_REQPOOLS
16365 + fprintf(stderr, "Removed timeout of pool %p\n", pool);
16372 +/* {{{ static int http_request_pool_socket_callback(CURL *, curl_socket_t, int, void *, void *) */
16373 +static int http_request_pool_socket_callback(CURL *easy, curl_socket_t sock, int action, void *socket_data, void *assign_data)
16375 + http_request_pool *pool = socket_data;
16377 + if (pool->useevents) {
16378 + int events = EV_PERSIST;
16379 + http_request_pool_event *ev = assign_data;
16380 + TSRMLS_FETCH_FROM_CTX(pool->tsrm_ls);
16383 + ev = ecalloc(1, sizeof(http_request_pool_event));
16385 + curl_multi_assign(pool->ch, sock, ev);
16386 + event_base_set(HTTP_G->request.pool.event.base, &ev->evnt);
16388 + event_del(&ev->evnt);
16391 +#if HTTP_DEBUG_REQPOOLS
16393 + static const char action_strings[][8] = {"NONE", "IN", "OUT", "INOUT", "REMOVE"};
16395 + curl_easy_getinfo(easy, CURLINFO_PRIVATE, &r);
16396 + fprintf(stderr, "Callback on socket %2d (%8s) event %p of pool %p (%d)\n", (int) sock, action_strings[action], ev, pool, pool->unfinished);
16400 + switch (action) {
16401 + case CURL_POLL_IN:
16402 + events |= EV_READ;
16404 + case CURL_POLL_OUT:
16405 + events |= EV_WRITE;
16407 + case CURL_POLL_INOUT:
16408 + events |= EV_READ|EV_WRITE;
16411 + case CURL_POLL_REMOVE:
16413 + case CURL_POLL_NONE:
16417 + http_error_ex(HE_WARNING, HTTP_E_SOCKET, "Unknown socket action %d", action);
16421 + event_set(&ev->evnt, sock, events, http_request_pool_event_callback, ev);
16422 + event_add(&ev->evnt, NULL);
16429 +/* {{{ static void http_request_pool_timer_callback(CURLM *, long, void*) */
16430 +static void http_request_pool_timer_callback(CURLM *multi, long timeout_ms, void *timer_data)
16432 + http_request_pool *pool = timer_data;
16434 + if (pool->useevents) {
16435 + TSRMLS_FETCH_FROM_CTX(pool->tsrm_ls);
16436 + struct timeval timeout;
16438 + if (!event_initialized(pool->timeout)) {
16439 + event_set(pool->timeout, -1, 0, http_request_pool_timeout_callback, pool);
16440 + event_base_set(HTTP_G->request.pool.event.base, pool->timeout);
16441 + } else if (event_pending(pool->timeout, EV_TIMEOUT, NULL)) {
16442 + event_del(pool->timeout);
16445 + if (timeout_ms > 0) {
16446 + timeout.tv_sec = timeout_ms / 1000;
16447 + timeout.tv_usec = (timeout_ms % 1000) * 1000;
16449 + http_request_pool_timeout(pool, &timeout);
16452 + event_add(pool->timeout, &timeout);
16454 +#if HTTP_DEBUG_REQPOOLS
16455 + fprintf(stderr, "Updating timeout %lu (%lu, %lu) of pool %p\n", (ulong) timeout_ms, (ulong) timeout.tv_sec, (ulong) timeout.tv_usec, pool);
16460 +#endif /* HTTP_HAVE_EVENT */
16462 +#endif /* ZEND_ENGINE_2 && HTTP_HAVE_CURL */
16466 + * Local variables:
16468 + * c-basic-offset: 4
16470 + * vim600: noet sw=4 ts=4 fdm=marker
16471 + * vim<600: noet sw=4 ts=4
16475 +++ b/ext/http/http_requestdatashare_object.c
16478 + +--------------------------------------------------------------------+
16480 + +--------------------------------------------------------------------+
16481 + | Redistribution and use in source and binary forms, with or without |
16482 + | modification, are permitted provided that the conditions mentioned |
16483 + | in the accompanying LICENSE file are met. |
16484 + +--------------------------------------------------------------------+
16485 + | Copyright (c) 2004-2010, Michael Wallner <mike@php.net> |
16486 + +--------------------------------------------------------------------+
16489 +/* $Id: http_requestdatashare_object.c 323304 2012-02-17 21:13:24Z mike $ */
16491 +#define HTTP_WANT_CURL
16492 +#include "php_http.h"
16494 +#if defined(ZEND_ENGINE_2) && defined(HTTP_HAVE_CURL)
16496 +#include "zend_interfaces.h"
16498 +#include "php_http_api.h"
16499 +#include "php_http_exception_object.h"
16500 +#include "php_http_request_api.h"
16501 +#include "php_http_request_object.h"
16502 +#include "php_http_request_datashare_api.h"
16503 +#include "php_http_requestdatashare_object.h"
16505 +#define HTTP_BEGIN_ARGS(method, req_args) HTTP_BEGIN_ARGS_EX(HttpRequestDataShare, method, 0, req_args)
16506 +#define HTTP_EMPTY_ARGS(method) HTTP_EMPTY_ARGS_EX(HttpRequestDataShare, method, 0)
16507 +#define HTTP_RSHARE_ME(method, visibility) PHP_ME(HttpRequestDataShare, method, HTTP_ARGS(HttpRequestDataShare, method), visibility)
16509 +#if defined(HAVE_SPL) && !defined(WONKY)
16510 +/* SPL doesn't install its headers */
16511 +extern PHPAPI zend_class_entry *spl_ce_Countable;
16514 +HTTP_EMPTY_ARGS(__destruct);
16515 +HTTP_EMPTY_ARGS(count);
16517 +HTTP_BEGIN_ARGS(attach, 1)
16518 + HTTP_ARG_OBJ(HttpRequest, request, 0)
16520 +HTTP_BEGIN_ARGS(detach, 1)
16521 + HTTP_ARG_OBJ(HttpRequest, request, 0)
16524 +HTTP_EMPTY_ARGS(reset);
16526 +HTTP_BEGIN_ARGS(factory, 0)
16527 + HTTP_ARG_VAL(global, 0)
16528 + HTTP_ARG_VAL(class_name, 0)
16532 +HTTP_BEGIN_ARGS(singleton, 0)
16533 + HTTP_ARG_VAL(global, 0)
16538 +#define http_requestdatashare_object_read_prop _http_requestdatashare_object_read_prop
16539 +static zval *_http_requestdatashare_object_read_prop(zval *object, zval *member, int type ZEND_LITERAL_KEY_DC TSRMLS_DC);
16540 +#define http_requestdatashare_object_write_prop _http_requestdatashare_object_write_prop
16541 +static void _http_requestdatashare_object_write_prop(zval *object, zval *member, zval *value ZEND_LITERAL_KEY_DC TSRMLS_DC);
16542 +#define http_requestdatashare_instantiate(t, g) _http_requestdatashare_instantiate((t), (g) TSRMLS_CC)
16543 +static inline zval *_http_requestdatashare_instantiate(zval *this_ptr, zend_bool global TSRMLS_DC);
16545 +#define THIS_CE http_requestdatashare_object_ce
16546 +zend_class_entry *http_requestdatashare_object_ce;
16547 +zend_function_entry http_requestdatashare_object_fe[] = {
16548 + HTTP_RSHARE_ME(__destruct, ZEND_ACC_PUBLIC|ZEND_ACC_DTOR)
16549 + HTTP_RSHARE_ME(count, ZEND_ACC_PUBLIC)
16550 + HTTP_RSHARE_ME(attach, ZEND_ACC_PUBLIC)
16551 + HTTP_RSHARE_ME(detach, ZEND_ACC_PUBLIC)
16552 + HTTP_RSHARE_ME(reset, ZEND_ACC_PUBLIC)
16553 + HTTP_RSHARE_ME(factory, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
16555 + HTTP_RSHARE_ME(singleton, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
16557 + EMPTY_FUNCTION_ENTRY
16559 +static zend_object_handlers http_requestdatashare_object_handlers;
16561 +PHP_MINIT_FUNCTION(http_requestdatashare_object)
16563 + HTTP_REGISTER_CLASS_EX(HttpRequestDataShare, http_requestdatashare_object, NULL, 0);
16564 + http_requestdatashare_object_handlers.clone_obj = NULL;
16565 + http_requestdatashare_object_handlers.read_property = http_requestdatashare_object_read_prop;
16566 + http_requestdatashare_object_handlers.write_property = http_requestdatashare_object_write_prop;
16568 +#if defined(HAVE_SPL) && !defined(WONKY)
16569 + zend_class_implements(http_requestdatashare_object_ce TSRMLS_CC, 1, spl_ce_Countable);
16572 + zend_declare_property_null(THIS_CE, ZEND_STRS("instance")-1, (ZEND_ACC_STATIC|ZEND_ACC_PRIVATE) TSRMLS_CC);
16573 + zend_declare_property_bool(THIS_CE, ZEND_STRS("cookie")-1, 0, ZEND_ACC_PUBLIC TSRMLS_CC);
16574 + zend_declare_property_bool(THIS_CE, ZEND_STRS("dns")-1, 0, ZEND_ACC_PUBLIC TSRMLS_CC);
16575 + zend_declare_property_bool(THIS_CE, ZEND_STRS("ssl")-1, 0, ZEND_ACC_PUBLIC TSRMLS_CC);
16576 + zend_declare_property_bool(THIS_CE, ZEND_STRS("connect")-1, 0, ZEND_ACC_PUBLIC TSRMLS_CC);
16581 +zend_object_value _http_requestdatashare_object_new(zend_class_entry *ce TSRMLS_DC)
16583 + return http_requestdatashare_object_new_ex(ce, NULL, NULL);
16586 +zend_object_value _http_requestdatashare_object_new_ex(zend_class_entry *ce, http_request_datashare *share, http_requestdatashare_object **ptr TSRMLS_DC)
16588 + zend_object_value ov;
16589 + http_requestdatashare_object *o;
16591 + o = ecalloc(1, sizeof(http_requestdatashare_object));
16595 + o->share = share;
16597 + o->share = http_request_datashare_new();
16604 +#ifdef ZEND_ENGINE_2_4
16605 + zend_object_std_init(o, ce TSRMLS_CC);
16606 + object_properties_init(o, ce);
16608 + ALLOC_HASHTABLE(OBJ_PROP(o));
16609 + zend_hash_init(OBJ_PROP(o), zend_hash_num_elements(&ce->default_properties), NULL, ZVAL_PTR_DTOR, 0);
16610 + zend_hash_copy(OBJ_PROP(o), &ce->default_properties, (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *));
16613 + ov.handle = putObject(http_requestdatashare_object, o);
16614 + ov.handlers = &http_requestdatashare_object_handlers;
16619 +void _http_requestdatashare_object_free(zend_object *object TSRMLS_DC)
16621 + http_requestdatashare_object *o = (http_requestdatashare_object *) object;
16623 + if (!o->share->persistent) {
16624 + http_request_datashare_free(&o->share);
16629 +static zval *_http_requestdatashare_object_read_prop(zval *object, zval *member, int type ZEND_LITERAL_KEY_DC TSRMLS_DC)
16631 + if (type == BP_VAR_W &&
16632 +#ifdef ZEND_ENGINE_2_4
16633 + zend_hash_exists(&THIS_CE->properties_info, Z_STRVAL_P(member), Z_STRLEN_P(member)+1)
16635 + zend_hash_exists(&THIS_CE->default_properties, Z_STRVAL_P(member), Z_STRLEN_P(member)+1)
16638 + zend_error(E_ERROR, "Cannot access HttpRequestDataShare default properties by reference or array key/index");
16642 + return zend_get_std_object_handlers()->read_property(object, member, type ZEND_LITERAL_KEY_CC TSRMLS_CC);
16645 +static void _http_requestdatashare_object_write_prop(zval *object, zval *member, zval *value ZEND_LITERAL_KEY_DC TSRMLS_DC)
16648 +#ifdef ZEND_ENGINE_2_4
16649 + zend_hash_exists(&THIS_CE->properties_info, Z_STRVAL_P(member), Z_STRLEN_P(member)+1)
16651 + zend_hash_exists(&THIS_CE->default_properties, Z_STRVAL_P(member), Z_STRLEN_P(member)+1)
16655 + getObjectEx(http_requestdatashare_object, obj, object);
16657 + status = http_request_datashare_set(obj->share, Z_STRVAL_P(member), Z_STRLEN_P(member), (zend_bool) i_zend_is_true(value));
16658 + if (SUCCESS != status) {
16663 + zend_get_std_object_handlers()->write_property(object, member, value ZEND_LITERAL_KEY_CC TSRMLS_CC);
16666 +/* {{{ proto void HttpRequestDataShare::__destruct()
16667 + Clean up HttpRequestDataShare object. */
16668 +PHP_METHOD(HttpRequestDataShare, __destruct)
16671 + getObject(http_requestdatashare_object, obj);
16672 + http_request_datashare_detach_all(obj->share);
16677 +/* {{{ proto int HttpRequestDataShare::count()
16678 + Implements Countable::count(). */
16679 +PHP_METHOD(HttpRequestDataShare, count)
16681 + getObject(http_requestdatashare_object, obj);
16685 + RETURN_LONG(zend_llist_count(HTTP_RSHARE_HANDLES(obj->share)));
16689 +PHP_METHOD(HttpRequestDataShare, attach)
16692 + getObject(http_requestdatashare_object, obj);
16694 + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &request, http_request_object_ce)) {
16698 + RETURN_SUCCESS(http_request_datashare_attach(obj->share, request));
16701 +PHP_METHOD(HttpRequestDataShare, detach)
16704 + getObject(http_requestdatashare_object, obj);
16706 + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &request, http_request_object_ce)) {
16710 + RETURN_SUCCESS(http_request_datashare_detach(obj->share, request));
16713 +PHP_METHOD(HttpRequestDataShare, reset)
16716 + getObject(http_requestdatashare_object, obj);
16717 + http_request_datashare_detach_all(obj->share);
16721 +PHP_METHOD(HttpRequestDataShare, factory)
16723 + zend_bool global = 0;
16726 + zend_object_value ov;
16728 + SET_EH_THROW_HTTP();
16729 + if ( SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|bs", &global, &cn, &cl) &&
16730 + SUCCESS == http_object_new(&ov, cn, cl, _http_requestdatashare_object_new_ex, http_requestdatashare_object_ce, NULL, NULL)) {
16731 + RETVAL_OBJVAL(ov, 0);
16732 + http_requestdatashare_instantiate(return_value, global);
16738 +/* {{{ proto static HttpRequestDataShare HttpRequestDataShare::singleton([bool global = false])
16739 + Get a single instance (differentiates between the global setting). */
16740 +PHP_METHOD(HttpRequestDataShare, singleton)
16742 + zend_bool global = 0;
16743 + zval *instance = *zend_std_get_static_property(THIS_CE, ZEND_STRS("instance")-1, 0 ZEND_LITERAL_NIL_CC TSRMLS_CC);
16745 + SET_EH_THROW_HTTP();
16746 + if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &global)) {
16747 + zval **zobj_ptr = NULL, *zobj = NULL;
16749 + if (Z_TYPE_P(instance) == IS_ARRAY) {
16750 + if (SUCCESS == zend_hash_index_find(Z_ARRVAL_P(instance), global, (void *) &zobj_ptr)) {
16751 + RETVAL_ZVAL(*zobj_ptr, 1, 0);
16753 + zobj = http_requestdatashare_instantiate(NULL, global);
16754 + add_index_zval(instance, global, zobj);
16755 + RETVAL_OBJECT(zobj, 1);
16758 + MAKE_STD_ZVAL(instance);
16759 + array_init(instance);
16761 + zobj = http_requestdatashare_instantiate(NULL, global);
16762 + add_index_zval(instance, global, zobj);
16763 + RETVAL_OBJECT(zobj, 1);
16765 + zend_update_static_property(THIS_CE, ZEND_STRS("instance")-1, instance TSRMLS_CC);
16766 + zval_ptr_dtor(&instance);
16772 +#endif /* !WONKY */
16774 +static inline zval *_http_requestdatashare_instantiate(zval *this_ptr, zend_bool global TSRMLS_DC)
16777 + MAKE_STD_ZVAL(this_ptr);
16778 + Z_TYPE_P(this_ptr) = IS_OBJECT;
16779 + this_ptr->value.obj = http_requestdatashare_object_new_ex(http_requestdatashare_object_ce, global ? http_request_datashare_global_get() : NULL, NULL);
16782 + if (HTTP_G->request.datashare.cookie) {
16783 + zend_update_property_bool(THIS_CE, getThis(), ZEND_STRS("cookie")-1, HTTP_G->request.datashare.cookie TSRMLS_CC);
16785 + if (HTTP_G->request.datashare.dns) {
16786 + zend_update_property_bool(THIS_CE, getThis(), ZEND_STRS("dns")-1, HTTP_G->request.datashare.dns TSRMLS_CC);
16788 + if (HTTP_G->request.datashare.ssl) {
16789 + zend_update_property_bool(THIS_CE, getThis(), ZEND_STRS("ssl")-1, HTTP_G->request.datashare.ssl TSRMLS_CC);
16791 + if (HTTP_G->request.datashare.connect) {
16792 + zend_update_property_bool(THIS_CE, getThis(), ZEND_STRS("connect")-1, HTTP_G->request.datashare.connect TSRMLS_CC);
16798 +#endif /* ZEND_ENGINE_2 && HTTP_HAVE_CURL */
16801 + * Local variables:
16803 + * c-basic-offset: 4
16805 + * vim600: noet sw=4 ts=4 fdm=marker
16806 + * vim<600: noet sw=4 ts=4
16810 +++ b/ext/http/http_requestpool_object.c
16813 + +--------------------------------------------------------------------+
16815 + +--------------------------------------------------------------------+
16816 + | Redistribution and use in source and binary forms, with or without |
16817 + | modification, are permitted provided that the conditions mentioned |
16818 + | in the accompanying LICENSE file are met. |
16819 + +--------------------------------------------------------------------+
16820 + | Copyright (c) 2004-2010, Michael Wallner <mike@php.net> |
16821 + +--------------------------------------------------------------------+
16824 +/* $Id: http_requestpool_object.c 323304 2012-02-17 21:13:24Z mike $ */
16826 +#define HTTP_WANT_CURL
16827 +#include "php_http.h"
16829 +#if defined(ZEND_ENGINE_2) && defined(HTTP_HAVE_CURL)
16831 +#include "zend_interfaces.h"
16833 +#include "php_http_api.h"
16834 +#include "php_http_exception_object.h"
16835 +#include "php_http_request_api.h"
16836 +#include "php_http_request_object.h"
16837 +#include "php_http_request_pool_api.h"
16838 +#include "php_http_requestpool_object.h"
16840 +#if defined(HAVE_SPL) && !defined(WONKY)
16841 +/* SPL doesn't install its headers */
16842 +extern PHPAPI zend_class_entry *spl_ce_Countable;
16845 +#define HTTP_BEGIN_ARGS(method, req_args) HTTP_BEGIN_ARGS_EX(HttpRequestPool, method, 0, req_args)
16846 +#define HTTP_EMPTY_ARGS(method) HTTP_EMPTY_ARGS_EX(HttpRequestPool, method, 0)
16847 +#define HTTP_REQPOOL_ME(method, visibility) PHP_ME(HttpRequestPool, method, HTTP_ARGS(HttpRequestPool, method), visibility)
16849 +HTTP_EMPTY_ARGS(__construct);
16851 +HTTP_EMPTY_ARGS(__destruct);
16852 +HTTP_EMPTY_ARGS(reset);
16854 +HTTP_BEGIN_ARGS(attach, 1)
16855 + HTTP_ARG_OBJ(HttpRequest, request, 0)
16858 +HTTP_BEGIN_ARGS(detach, 1)
16859 + HTTP_ARG_OBJ(HttpRequest, request, 0)
16862 +HTTP_EMPTY_ARGS(send);
16863 +HTTP_EMPTY_ARGS(socketPerform);
16864 +HTTP_BEGIN_ARGS(socketSelect, 0)
16865 + HTTP_ARG_VAL(timeout, 0)
16868 +HTTP_EMPTY_ARGS(valid);
16869 +HTTP_EMPTY_ARGS(current);
16870 +HTTP_EMPTY_ARGS(key);
16871 +HTTP_EMPTY_ARGS(next);
16872 +HTTP_EMPTY_ARGS(rewind);
16874 +HTTP_EMPTY_ARGS(count);
16876 +HTTP_EMPTY_ARGS(getAttachedRequests);
16877 +HTTP_EMPTY_ARGS(getFinishedRequests);
16879 +HTTP_BEGIN_ARGS(enablePipelining, 0)
16880 + HTTP_ARG_VAL(enable, 0)
16883 +HTTP_BEGIN_ARGS(enableEvents, 0)
16884 + HTTP_ARG_VAL(enable, 0)
16887 +zend_class_entry *http_requestpool_object_ce;
16888 +zend_function_entry http_requestpool_object_fe[] = {
16889 + HTTP_REQPOOL_ME(__construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
16890 + HTTP_REQPOOL_ME(__destruct, ZEND_ACC_PUBLIC|ZEND_ACC_DTOR)
16891 + HTTP_REQPOOL_ME(attach, ZEND_ACC_PUBLIC)
16892 + HTTP_REQPOOL_ME(detach, ZEND_ACC_PUBLIC)
16893 + HTTP_REQPOOL_ME(send, ZEND_ACC_PUBLIC)
16894 + HTTP_REQPOOL_ME(reset, ZEND_ACC_PUBLIC)
16896 + HTTP_REQPOOL_ME(socketPerform, ZEND_ACC_PROTECTED)
16897 + HTTP_REQPOOL_ME(socketSelect, ZEND_ACC_PROTECTED)
16899 + /* implements Iterator */
16900 + HTTP_REQPOOL_ME(valid, ZEND_ACC_PUBLIC)
16901 + HTTP_REQPOOL_ME(current, ZEND_ACC_PUBLIC)
16902 + HTTP_REQPOOL_ME(key, ZEND_ACC_PUBLIC)
16903 + HTTP_REQPOOL_ME(next, ZEND_ACC_PUBLIC)
16904 + HTTP_REQPOOL_ME(rewind, ZEND_ACC_PUBLIC)
16906 + /* implmenents Countable */
16907 + HTTP_REQPOOL_ME(count, ZEND_ACC_PUBLIC)
16909 + HTTP_REQPOOL_ME(getAttachedRequests, ZEND_ACC_PUBLIC)
16910 + HTTP_REQPOOL_ME(getFinishedRequests, ZEND_ACC_PUBLIC)
16912 + HTTP_REQPOOL_ME(enablePipelining, ZEND_ACC_PUBLIC)
16913 + HTTP_REQPOOL_ME(enableEvents, ZEND_ACC_PUBLIC)
16915 + EMPTY_FUNCTION_ENTRY
16917 +static zend_object_handlers http_requestpool_object_handlers;
16919 +PHP_MINIT_FUNCTION(http_requestpool_object)
16921 + HTTP_REGISTER_CLASS_EX(HttpRequestPool, http_requestpool_object, NULL, 0);
16922 + http_requestpool_object_handlers.clone_obj = NULL;
16924 +#if defined(HAVE_SPL) && !defined(WONKY)
16925 + zend_class_implements(http_requestpool_object_ce TSRMLS_CC, 2, spl_ce_Countable, zend_ce_iterator);
16927 + zend_class_implements(http_requestpool_object_ce TSRMLS_CC, 1, zend_ce_iterator);
16933 +zend_object_value _http_requestpool_object_new(zend_class_entry *ce TSRMLS_DC)
16935 + zend_object_value ov;
16936 + http_requestpool_object *o;
16938 + o = ecalloc(1, sizeof(http_requestpool_object));
16941 + http_request_pool_init(&o->pool);
16943 +#ifdef ZEND_ENGINE_2_4
16944 + zend_object_std_init(o, ce TSRMLS_CC);
16945 + object_properties_init(o, ce);
16947 + ALLOC_HASHTABLE(OBJ_PROP(o));
16948 + zend_hash_init(OBJ_PROP(o), zend_hash_num_elements(&ce->default_properties), NULL, ZVAL_PTR_DTOR, 0);
16949 + zend_hash_copy(OBJ_PROP(o), &ce->default_properties, (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *));
16952 + ov.handle = putObject(http_requestpool_object, o);
16953 + ov.handlers = &http_requestpool_object_handlers;
16958 +void _http_requestpool_object_free(zend_object *object TSRMLS_DC)
16960 + http_requestpool_object *o = (http_requestpool_object *) object;
16962 + http_request_pool_dtor(&o->pool);
16966 +#define http_requestpool_object_llist2array _http_requestpool_object_llist2array
16967 +static void _http_requestpool_object_llist2array(zval **req, zval *array TSRMLS_DC)
16969 + ZVAL_ADDREF(*req);
16970 + add_next_index_zval(array, *req);
16973 +/* ### USERLAND ### */
16975 +/* {{{ proto void HttpRequestPool::__construct([HttpRequest request[, ...]])
16976 + Creates a new HttpRequestPool object instance. */
16977 +PHP_METHOD(HttpRequestPool, __construct)
16979 + int argc = ZEND_NUM_ARGS();
16980 + zval ***argv = safe_emalloc(argc, sizeof(zval *), 0);
16981 + getObject(http_requestpool_object, obj);
16983 + SET_EH_THROW_HTTP();
16984 + if (SUCCESS == zend_get_parameters_array_ex(argc, argv)) {
16987 + for (i = 0; i < argc; ++i) {
16988 + if (Z_TYPE_PP(argv[i]) == IS_OBJECT && instanceof_function(Z_OBJCE_PP(argv[i]), http_request_object_ce TSRMLS_CC)) {
16989 + http_request_pool_attach(&obj->pool, *(argv[i]));
16994 + http_final(HTTP_EX_CE(request_pool));
16999 +/* {{{ proto void HttpRequestPool::__destruct()
17000 + Clean up HttpRequestPool object. */
17001 +PHP_METHOD(HttpRequestPool, __destruct)
17003 + getObject(http_requestpool_object, obj);
17007 + http_request_pool_detach_all(&obj->pool);
17011 +/* {{{ proto void HttpRequestPool::reset()
17012 + Detach all attached HttpRequest objects. */
17013 +PHP_METHOD(HttpRequestPool, reset)
17015 + getObject(http_requestpool_object, obj);
17019 + obj->iterator.pos = 0;
17020 + http_request_pool_detach_all(&obj->pool);
17023 +/* {{{ proto bool HttpRequestPool::attach(HttpRequest request)
17024 + Attach an HttpRequest object to this HttpRequestPool. WARNING: set all options prior attaching! */
17025 +PHP_METHOD(HttpRequestPool, attach)
17028 + STATUS status = FAILURE;
17029 + getObject(http_requestpool_object, obj);
17031 + SET_EH_THROW_HTTP();
17032 + if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &request, http_request_object_ce)) {
17033 + if (obj->iterator.pos > 0 && obj->iterator.pos < zend_llist_count(&obj->pool.handles)) {
17034 + http_error(HE_THROW, HTTP_E_REQUEST_POOL, "Cannot attach to the HttpRequestPool while the iterator is active");
17036 + status = http_request_pool_attach(&obj->pool, request);
17040 + RETURN_SUCCESS(status);
17044 +/* {{{ proto bool HttpRequestPool::detach(HttpRequest request)
17045 + Detach an HttpRequest object from this HttpRequestPool. */
17046 +PHP_METHOD(HttpRequestPool, detach)
17049 + STATUS status = FAILURE;
17050 + getObject(http_requestpool_object, obj);
17052 + SET_EH_THROW_HTTP();
17053 + if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &request, http_request_object_ce)) {
17054 + obj->iterator.pos = -1;
17055 + status = http_request_pool_detach(&obj->pool, request);
17058 + RETURN_SUCCESS(status);
17062 +/* {{{ proto bool HttpRequestPool::send()
17063 + Send all attached HttpRequest objects in parallel. */
17064 +PHP_METHOD(HttpRequestPool, send)
17067 + getObject(http_requestpool_object, obj);
17071 + SET_EH_THROW_HTTP();
17072 + status = http_request_pool_send(&obj->pool);
17075 + /* rethrow as HttpRequestPoolException */
17076 + http_final(HTTP_EX_CE(request_pool));
17078 + RETURN_SUCCESS(status);
17082 +/* {{{ proto protected bool HttpRequestPool::socketPerform()
17083 + Returns TRUE until each request has finished its transaction. */
17084 +PHP_METHOD(HttpRequestPool, socketPerform)
17086 + getObject(http_requestpool_object, obj);
17090 + if (0 < http_request_pool_perform(&obj->pool)) {
17098 +/* {{{ proto protected bool HttpRequestPool::socketSelect([double timeout]) */
17099 +PHP_METHOD(HttpRequestPool, socketSelect)
17101 + double timeout = 0;
17102 + struct timeval custom_timeout, *custom_timeout_ptr = NULL;
17103 + getObject(http_requestpool_object, obj);
17105 + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|d", &timeout)) {
17108 + if (ZEND_NUM_ARGS() && timeout > 0) {
17109 + custom_timeout.tv_sec = (time_t) timeout;
17110 + custom_timeout.tv_usec = HTTP_USEC(timeout) % HTTP_MCROSEC;
17111 + custom_timeout_ptr = &custom_timeout;
17114 + RETURN_SUCCESS(http_request_pool_select_ex(&obj->pool, custom_timeout_ptr));
17118 +/* {{{ proto bool HttpRequestPool::valid()
17119 + Implements Iterator::valid(). */
17120 +PHP_METHOD(HttpRequestPool, valid)
17124 + if (return_value_used) {
17125 + getObject(http_requestpool_object, obj);
17126 + RETURN_BOOL(obj->iterator.pos >= 0 && obj->iterator.pos < zend_llist_count(&obj->pool.handles));
17131 +/* {{{ proto HttpRequest HttpRequestPool::current()
17132 + Implements Iterator::current(). */
17133 +PHP_METHOD(HttpRequestPool, current)
17137 + if (return_value_used) {
17139 + zval **current = NULL;
17140 + zend_llist_position lpos;
17141 + getObject(http_requestpool_object, obj);
17143 + if (obj->iterator.pos < zend_llist_count(&obj->pool.handles)) {
17144 + for ( current = zend_llist_get_first_ex(&obj->pool.handles, &lpos);
17145 + current && obj->iterator.pos != pos++;
17146 + current = zend_llist_get_next_ex(&obj->pool.handles, &lpos));
17148 + RETURN_OBJECT(*current, 1);
17156 +/* {{{ proto int HttpRequestPool::key()
17157 + Implements Iterator::key(). */
17158 +PHP_METHOD(HttpRequestPool, key)
17162 + if (return_value_used) {
17163 + getObject(http_requestpool_object, obj);
17164 + RETURN_LONG(obj->iterator.pos);
17169 +/* {{{ proto void HttpRequestPool::next()
17170 + Implements Iterator::next(). */
17171 +PHP_METHOD(HttpRequestPool, next)
17174 + getObject(http_requestpool_object, obj);
17175 + ++(obj->iterator.pos);
17180 +/* {{{ proto void HttpRequestPool::rewind()
17181 + Implements Iterator::rewind(). */
17182 +PHP_METHOD(HttpRequestPool, rewind)
17185 + getObject(http_requestpool_object, obj);
17186 + obj->iterator.pos = 0;
17191 +/* {{{ proto int HttpRequestPool::count()
17192 + Implements Countable::count(). */
17193 +PHP_METHOD(HttpRequestPool, count)
17196 + getObject(http_requestpool_object, obj);
17197 + RETURN_LONG((long) zend_llist_count(&obj->pool.handles));
17202 +/* {{{ proto array HttpRequestPool::getAttachedRequests()
17203 + Get attached HttpRequest objects. */
17204 +PHP_METHOD(HttpRequestPool, getAttachedRequests)
17206 + getObject(http_requestpool_object, obj);
17210 + array_init(return_value);
17211 + zend_llist_apply_with_argument(&obj->pool.handles,
17212 + (llist_apply_with_arg_func_t) http_requestpool_object_llist2array,
17213 + return_value TSRMLS_CC);
17217 +/* {{{ proto array HttpRequestPool::getFinishedRequests()
17218 + Get attached HttpRequest objects that already have finished their work. */
17219 +PHP_METHOD(HttpRequestPool, getFinishedRequests)
17221 + getObject(http_requestpool_object, obj);
17225 + array_init(return_value);
17226 + zend_llist_apply_with_argument(&obj->pool.finished,
17227 + (llist_apply_with_arg_func_t) http_requestpool_object_llist2array,
17228 + return_value TSRMLS_CC);
17232 +/* {{{ proto bool HttpRequestPool::enablePipelining([bool enable = true])
17233 + Enables pipelining support for all attached requests if support in libcurl is given. */
17234 +PHP_METHOD(HttpRequestPool, enablePipelining)
17236 + zend_bool enable = 1;
17237 +#if defined(HAVE_CURL_MULTI_SETOPT) && HTTP_CURL_VERSION(7,16,0)
17238 + getObject(http_requestpool_object, obj);
17241 + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &enable)) {
17244 +#if defined(HAVE_CURL_MULTI_SETOPT) && HTTP_CURL_VERSION(7,16,0)
17245 + if (CURLM_OK == curl_multi_setopt(obj->pool.ch, CURLMOPT_PIPELINING, (long) enable)) {
17253 +/* {{{ proto bool HttpRequestPool::enableEvents([bool enable = true])
17254 + Enables event-driven I/O if support in libcurl is given. */
17255 +PHP_METHOD(HttpRequestPool, enableEvents)
17257 + zend_bool enable = 1;
17258 +#if defined(HTTP_HAVE_EVENT)
17259 + getObject(http_requestpool_object, obj);
17262 + if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &enable)) {
17263 +#if defined(HTTP_HAVE_EVENT)
17264 + obj->pool.useevents = enable;
17272 +#endif /* ZEND_ENGINE_2 && HTTP_HAVE_CURL */
17275 + * Local variables:
17277 + * c-basic-offset: 4
17279 + * vim600: noet sw=4 ts=4 fdm=marker
17280 + * vim<600: noet sw=4 ts=4
17284 +++ b/ext/http/http_response_object.c
17287 + +--------------------------------------------------------------------+
17289 + +--------------------------------------------------------------------+
17290 + | Redistribution and use in source and binary forms, with or without |
17291 + | modification, are permitted provided that the conditions mentioned |
17292 + | in the accompanying LICENSE file are met. |
17293 + +--------------------------------------------------------------------+
17294 + | Copyright (c) 2004-2010, Michael Wallner <mike@php.net> |
17295 + +--------------------------------------------------------------------+
17298 +/* $Id: http_response_object.c 323304 2012-02-17 21:13:24Z mike $ */
17300 +#define HTTP_WANT_SAPI
17301 +#define HTTP_WANT_MAGIC
17302 +#include "php_http.h"
17304 +/* broken static properties in PHP 5.0 */
17305 +#if defined(ZEND_ENGINE_2) && !defined(WONKY)
17307 +#include "php_ini.h"
17309 +#include "php_http_api.h"
17310 +#include "php_http_cache_api.h"
17311 +#include "php_http_exception_object.h"
17312 +#include "php_http_headers_api.h"
17313 +#include "php_http_response_object.h"
17314 +#include "php_http_send_api.h"
17316 +#define HTTP_BEGIN_ARGS(method, req_args) HTTP_BEGIN_ARGS_EX(HttpResponse, method, 0, req_args)
17317 +#define HTTP_EMPTY_ARGS(method) HTTP_EMPTY_ARGS_EX(HttpResponse, method, 0)
17318 +#define HTTP_RESPONSE_ME(method, visibility) PHP_ME(HttpResponse, method, HTTP_ARGS(HttpResponse, method), visibility|ZEND_ACC_STATIC)
17319 +#define HTTP_RESPONSE_ALIAS(method, func) HTTP_STATIC_ME_ALIAS(method, func, HTTP_ARGS(HttpResponse, method))
17321 +HTTP_BEGIN_ARGS(setHeader, 1)
17322 + HTTP_ARG_VAL(name, 0)
17323 + HTTP_ARG_VAL(value, 0)
17324 + HTTP_ARG_VAL(replace, 0)
17327 +HTTP_BEGIN_ARGS(getHeader, 0)
17328 + HTTP_ARG_VAL(name, 0)
17331 +HTTP_EMPTY_ARGS(getETag);
17332 +HTTP_BEGIN_ARGS(setETag, 1)
17333 + HTTP_ARG_VAL(etag, 0)
17336 +HTTP_EMPTY_ARGS(getLastModified);
17337 +HTTP_BEGIN_ARGS(setLastModified, 1)
17338 + HTTP_ARG_VAL(timestamp, 0)
17341 +HTTP_EMPTY_ARGS(getCache);
17342 +HTTP_BEGIN_ARGS(setCache, 1)
17343 + HTTP_ARG_VAL(cache, 0)
17346 +HTTP_EMPTY_ARGS(getGzip);
17347 +HTTP_BEGIN_ARGS(setGzip, 1)
17348 + HTTP_ARG_VAL(gzip, 0)
17351 +HTTP_EMPTY_ARGS(getCacheControl);
17352 +HTTP_BEGIN_ARGS(setCacheControl, 1)
17353 + HTTP_ARG_VAL(cache_control, 0)
17354 + HTTP_ARG_VAL(max_age, 0)
17355 + HTTP_ARG_VAL(must_revalidate, 0)
17358 +HTTP_EMPTY_ARGS(getContentType);
17359 +HTTP_BEGIN_ARGS(setContentType, 1)
17360 + HTTP_ARG_VAL(content_type, 0)
17363 +HTTP_BEGIN_ARGS(guessContentType, 1)
17364 + HTTP_ARG_VAL(magic_file, 0)
17365 + HTTP_ARG_VAL(magic_mode, 0)
17368 +HTTP_EMPTY_ARGS(getContentDisposition);
17369 +HTTP_BEGIN_ARGS(setContentDisposition, 1)
17370 + HTTP_ARG_VAL(filename, 0)
17371 + HTTP_ARG_VAL(send_inline, 0)
17374 +HTTP_EMPTY_ARGS(getThrottleDelay);
17375 +HTTP_BEGIN_ARGS(setThrottleDelay, 1)
17376 + HTTP_ARG_VAL(seconds, 0)
17379 +HTTP_EMPTY_ARGS(getBufferSize);
17380 +HTTP_BEGIN_ARGS(setBufferSize, 1)
17381 + HTTP_ARG_VAL(bytes, 0)
17384 +HTTP_EMPTY_ARGS(getData);
17385 +HTTP_BEGIN_ARGS(setData, 1)
17386 + HTTP_ARG_VAL(data, 0)
17389 +HTTP_EMPTY_ARGS(getStream);
17390 +HTTP_BEGIN_ARGS(setStream, 1)
17391 + HTTP_ARG_VAL(stream, 0)
17394 +HTTP_EMPTY_ARGS(getFile);
17395 +HTTP_BEGIN_ARGS(setFile, 1)
17396 + HTTP_ARG_VAL(filepath, 0)
17399 +HTTP_BEGIN_ARGS(send, 0)
17400 + HTTP_ARG_VAL(clean_ob, 0)
17403 +HTTP_EMPTY_ARGS(capture);
17405 +HTTP_BEGIN_ARGS(redirect, 0)
17406 + HTTP_ARG_VAL(url, 0)
17407 + HTTP_ARG_VAL(params, 0)
17408 + HTTP_ARG_VAL(session, 0)
17409 + HTTP_ARG_VAL(permanent, 0)
17412 +HTTP_BEGIN_ARGS(status, 1)
17413 + HTTP_ARG_VAL(code, 0)
17416 +HTTP_EMPTY_ARGS(getRequestHeaders);
17417 +HTTP_EMPTY_ARGS(getRequestBody);
17418 +HTTP_EMPTY_ARGS(getRequestBodyStream);
17420 +#define THIS_CE http_response_object_ce
17421 +zend_class_entry *http_response_object_ce;
17422 +zend_function_entry http_response_object_fe[] = {
17424 + HTTP_RESPONSE_ME(setHeader, ZEND_ACC_PUBLIC)
17425 + HTTP_RESPONSE_ME(getHeader, ZEND_ACC_PUBLIC)
17427 + HTTP_RESPONSE_ME(setETag, ZEND_ACC_PUBLIC)
17428 + HTTP_RESPONSE_ME(getETag, ZEND_ACC_PUBLIC)
17430 + HTTP_RESPONSE_ME(setLastModified, ZEND_ACC_PUBLIC)
17431 + HTTP_RESPONSE_ME(getLastModified, ZEND_ACC_PUBLIC)
17433 + HTTP_RESPONSE_ME(setContentDisposition, ZEND_ACC_PUBLIC)
17434 + HTTP_RESPONSE_ME(getContentDisposition, ZEND_ACC_PUBLIC)
17436 + HTTP_RESPONSE_ME(setContentType, ZEND_ACC_PUBLIC)
17437 + HTTP_RESPONSE_ME(getContentType, ZEND_ACC_PUBLIC)
17439 + HTTP_RESPONSE_ME(guessContentType, ZEND_ACC_PUBLIC)
17441 + HTTP_RESPONSE_ME(setCache, ZEND_ACC_PUBLIC)
17442 + HTTP_RESPONSE_ME(getCache, ZEND_ACC_PUBLIC)
17444 + HTTP_RESPONSE_ME(setCacheControl, ZEND_ACC_PUBLIC)
17445 + HTTP_RESPONSE_ME(getCacheControl, ZEND_ACC_PUBLIC)
17447 + HTTP_RESPONSE_ME(setGzip, ZEND_ACC_PUBLIC)
17448 + HTTP_RESPONSE_ME(getGzip, ZEND_ACC_PUBLIC)
17450 + HTTP_RESPONSE_ME(setThrottleDelay, ZEND_ACC_PUBLIC)
17451 + HTTP_RESPONSE_ME(getThrottleDelay, ZEND_ACC_PUBLIC)
17453 + HTTP_RESPONSE_ME(setBufferSize, ZEND_ACC_PUBLIC)
17454 + HTTP_RESPONSE_ME(getBufferSize, ZEND_ACC_PUBLIC)
17456 + HTTP_RESPONSE_ME(setData, ZEND_ACC_PUBLIC)
17457 + HTTP_RESPONSE_ME(getData, ZEND_ACC_PUBLIC)
17459 + HTTP_RESPONSE_ME(setFile, ZEND_ACC_PUBLIC)
17460 + HTTP_RESPONSE_ME(getFile, ZEND_ACC_PUBLIC)
17462 + HTTP_RESPONSE_ME(setStream, ZEND_ACC_PUBLIC)
17463 + HTTP_RESPONSE_ME(getStream, ZEND_ACC_PUBLIC)
17465 + HTTP_RESPONSE_ME(send, ZEND_ACC_PUBLIC)
17466 + HTTP_RESPONSE_ME(capture, ZEND_ACC_PUBLIC)
17468 + HTTP_RESPONSE_ALIAS(redirect, http_redirect)
17469 + HTTP_RESPONSE_ALIAS(status, http_send_status)
17470 + HTTP_RESPONSE_ALIAS(getRequestHeaders, http_get_request_headers)
17471 + HTTP_RESPONSE_ALIAS(getRequestBody, http_get_request_body)
17472 + HTTP_RESPONSE_ALIAS(getRequestBodyStream, http_get_request_body_stream)
17474 + EMPTY_FUNCTION_ENTRY
17477 +PHP_MINIT_FUNCTION(http_response_object)
17479 + HTTP_REGISTER_CLASS(HttpResponse, http_response_object, NULL, 0);
17481 + zend_declare_property_bool(THIS_CE, ZEND_STRS("sent")-1, 0, (ZEND_ACC_STATIC|ZEND_ACC_PRIVATE) TSRMLS_CC);
17482 + zend_declare_property_bool(THIS_CE, ZEND_STRS("catch")-1, 0, (ZEND_ACC_STATIC|ZEND_ACC_PRIVATE) TSRMLS_CC);
17483 + zend_declare_property_long(THIS_CE, ZEND_STRS("mode")-1, -1, (ZEND_ACC_STATIC|ZEND_ACC_PRIVATE) TSRMLS_CC);
17484 + zend_declare_property_long(THIS_CE, ZEND_STRS("stream")-1, 0, (ZEND_ACC_STATIC|ZEND_ACC_PRIVATE) TSRMLS_CC);
17485 + zend_declare_property_null(THIS_CE, ZEND_STRS("file")-1, (ZEND_ACC_STATIC|ZEND_ACC_PRIVATE) TSRMLS_CC);
17486 + zend_declare_property_null(THIS_CE, ZEND_STRS("data")-1, (ZEND_ACC_STATIC|ZEND_ACC_PRIVATE) TSRMLS_CC);
17487 + zend_declare_property_bool(THIS_CE, ZEND_STRS("cache")-1, 0, (ZEND_ACC_STATIC|ZEND_ACC_PROTECTED) TSRMLS_CC);
17488 + zend_declare_property_bool(THIS_CE, ZEND_STRS("gzip")-1, 0, (ZEND_ACC_STATIC|ZEND_ACC_PROTECTED) TSRMLS_CC);
17489 + zend_declare_property_null(THIS_CE, ZEND_STRS("eTag")-1, (ZEND_ACC_STATIC|ZEND_ACC_PROTECTED) TSRMLS_CC);
17490 + zend_declare_property_long(THIS_CE, ZEND_STRS("lastModified")-1, 0, (ZEND_ACC_STATIC|ZEND_ACC_PROTECTED) TSRMLS_CC);
17491 + zend_declare_property_null(THIS_CE, ZEND_STRS("cacheControl")-1, (ZEND_ACC_STATIC|ZEND_ACC_PROTECTED) TSRMLS_CC);
17492 + zend_declare_property_null(THIS_CE, ZEND_STRS("contentType")-1, (ZEND_ACC_STATIC|ZEND_ACC_PROTECTED) TSRMLS_CC);
17493 + zend_declare_property_null(THIS_CE, ZEND_STRS("contentDisposition")-1, (ZEND_ACC_STATIC|ZEND_ACC_PROTECTED) TSRMLS_CC);
17494 + zend_declare_property_long(THIS_CE, ZEND_STRS("bufferSize")-1, 0, (ZEND_ACC_STATIC|ZEND_ACC_PROTECTED) TSRMLS_CC);
17495 + zend_declare_property_double(THIS_CE, ZEND_STRS("throttleDelay")-1, 0.0, (ZEND_ACC_STATIC|ZEND_ACC_PROTECTED) TSRMLS_CC);
17498 + zend_declare_class_constant_long(THIS_CE, ZEND_STRS("REDIRECT")-1, HTTP_REDIRECT TSRMLS_CC);
17499 + zend_declare_class_constant_long(THIS_CE, ZEND_STRS("REDIRECT_PERM")-1, HTTP_REDIRECT_PERM TSRMLS_CC);
17500 + zend_declare_class_constant_long(THIS_CE, ZEND_STRS("REDIRECT_FOUND")-1, HTTP_REDIRECT_FOUND TSRMLS_CC);
17501 + zend_declare_class_constant_long(THIS_CE, ZEND_STRS("REDIRECT_POST")-1, HTTP_REDIRECT_POST TSRMLS_CC);
17502 + zend_declare_class_constant_long(THIS_CE, ZEND_STRS("REDIRECT_PROXY")-1, HTTP_REDIRECT_PROXY TSRMLS_CC);
17503 + zend_declare_class_constant_long(THIS_CE, ZEND_STRS("REDIRECT_TEMP")-1, HTTP_REDIRECT_TEMP TSRMLS_CC);
17504 +#endif /* WONKY */
17509 +/* ### USERLAND ### */
17511 +/* {{{ proto static bool HttpResponse::setHeader(string name[, mixed value[, bool replace = true]])
17512 + Send an HTTP header. */
17513 +PHP_METHOD(HttpResponse, setHeader)
17515 + zend_bool replace = 1;
17517 + int name_len = 0;
17518 + zval *value = NULL;
17520 + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|z/!b", &name, &name_len, &value, &replace)) {
17523 + if (SG(headers_sent)) {
17524 + http_error(HE_WARNING, HTTP_E_HEADER, "Cannot add another header when headers have already been sent");
17528 + http_error(HE_WARNING, HTTP_E_HEADER, "Cannot send anonymous headers");
17531 + http_send_header_zval_ex(name, name_len, &value, replace);
17536 +/* {{{ proto static mixed HttpResponse::getHeader([string name])
17537 + Get header(s) about to be sent. */
17538 +PHP_METHOD(HttpResponse, getHeader)
17540 + char *name = NULL;
17541 + int name_len = 0;
17543 + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &name, &name_len)) {
17547 + if (name && name_len) {
17549 + HashTable headers_ht;
17551 + zend_hash_init(&headers_ht, sizeof(zval *), NULL, ZVAL_PTR_DTOR, 0);
17552 + if ( (SUCCESS == http_get_response_headers(&headers_ht)) &&
17553 + (SUCCESS == zend_hash_find(&headers_ht, name, name_len + 1, (void *) &header))) {
17554 + RETVAL_ZVAL(*header, 1, 0);
17558 + zend_hash_destroy(&headers_ht);
17560 + array_init(return_value);
17561 + http_get_response_headers(Z_ARRVAL_P(return_value));
17566 +/* {{{ proto static bool HttpResponse::setCache(bool cache)
17567 + Whether it should be attempted to cache the entity. */
17568 +PHP_METHOD(HttpResponse, setCache)
17570 + zend_bool do_cache = 0;
17572 + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "b", &do_cache)) {
17576 + RETURN_SUCCESS(zend_update_static_property_bool(THIS_CE, ZEND_STRS("cache")-1, do_cache TSRMLS_CC));
17580 +/* {{{ proto static bool HttpResponse::getCache()
17581 + Get current caching setting. */
17582 +PHP_METHOD(HttpResponse, getCache)
17586 + if (return_value_used) {
17587 + zval *cache = http_zsep(IS_BOOL, *(zend_std_get_static_property(THIS_CE, ZEND_STRS("cache")-1, 0 ZEND_LITERAL_NIL_CC TSRMLS_CC)));
17588 + RETVAL_ZVAL(cache, 1, 1);
17593 +/* {{{ proto static bool HttpResponse::setGzip(bool gzip)
17594 + Enable on-thy-fly gzipping of the sent entity. */
17595 +PHP_METHOD(HttpResponse, setGzip)
17597 + zend_bool do_gzip = 0;
17599 + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "b", &do_gzip)) {
17603 + RETURN_SUCCESS(zend_update_static_property_bool(THIS_CE, ZEND_STRS("gzip")-1, do_gzip TSRMLS_CC));
17607 +/* {{{ proto static bool HttpResponse::getGzip()
17608 + Get current gzipping setting. */
17609 +PHP_METHOD(HttpResponse, getGzip)
17613 + if (return_value_used) {
17614 + zval *gzip = http_zsep(IS_BOOL, *(zend_std_get_static_property(THIS_CE, ZEND_STRS("gzip")-1, 0 ZEND_LITERAL_NIL_CC TSRMLS_CC)));
17615 + RETVAL_ZVAL(gzip, 1, 1);
17620 +/* {{{ proto static bool HttpResponse::setCacheControl(string control[, int max_age = 0[, bool must_revalidate = true]])
17621 + Set a custom cache-control header, usually being "private" or "public"; The max_age parameter controls how long the cache entry is valid on the client side. */
17622 +PHP_METHOD(HttpResponse, setCacheControl)
17624 + char *ccontrol, *cctl;
17626 + long max_age = 0;
17627 + zend_bool must_revalidate = 1;
17629 + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|lb", &ccontrol, &cc_len, &max_age, &must_revalidate)) {
17633 + if (strcmp(ccontrol, "public") && strcmp(ccontrol, "private") && strcmp(ccontrol, "no-cache")) {
17634 + http_error_ex(HE_WARNING, HTTP_E_INVALID_PARAM, "Cache-Control '%s' doesn't match public, private or no-cache", ccontrol);
17637 + size_t cctl_len = spprintf(&cctl, 0, "%s,%s max-age=%ld", ccontrol, must_revalidate?" must-revalidate,":"", max_age);
17638 + RETVAL_SUCCESS(zend_update_static_property_stringl(THIS_CE, ZEND_STRS("cacheControl")-1, cctl, cctl_len TSRMLS_CC));
17644 +/* {{{ proto static string HttpResponse::getCacheControl()
17645 + Get current Cache-Control header setting. */
17646 +PHP_METHOD(HttpResponse, getCacheControl)
17650 + if (return_value_used) {
17651 + zval *cctl = http_zsep(IS_STRING, *(zend_std_get_static_property(THIS_CE, ZEND_STRS("cacheControl")-1, 0 ZEND_LITERAL_NIL_CC TSRMLS_CC)));
17652 + RETVAL_ZVAL(cctl, 1, 1);
17657 +/* {{{ proto static bool HttpResponse::setContentType(string content_type)
17658 + Set the content-type of the sent entity. */
17659 +PHP_METHOD(HttpResponse, setContentType)
17664 + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &ctype, &ctype_len)) {
17668 + HTTP_CHECK_CONTENT_TYPE(ctype, RETURN_FALSE);
17669 + RETURN_SUCCESS(zend_update_static_property_stringl(THIS_CE, ZEND_STRS("contentType")-1, ctype, ctype_len TSRMLS_CC));
17673 +/* {{{ proto static string HttpResponse::getContentType()
17674 + Get current Content-Type header setting. */
17675 +PHP_METHOD(HttpResponse, getContentType)
17679 + if (return_value_used) {
17680 + zval *ctype = http_zsep(IS_STRING, *(zend_std_get_static_property(THIS_CE, ZEND_STRS("contentType")-1, 0 ZEND_LITERAL_NIL_CC TSRMLS_CC)));
17681 + RETVAL_ZVAL(ctype, 1, 1);
17686 +/* {{{ proto static string HttpResponse::guessContentType(string magic_file[, int magic_mode = MAGIC_MIME])
17687 + Attempts to guess the content type of supplied payload through libmagic. */
17688 +PHP_METHOD(HttpResponse, guessContentType)
17690 +#ifdef HTTP_HAVE_MAGIC
17691 + char *magic_file, *ct = NULL;
17692 + int magic_file_len;
17693 + long magic_mode = MAGIC_MIME;
17696 + SET_EH_THROW_HTTP();
17697 + if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &magic_file, &magic_file_len, &magic_mode)) {
17698 + switch (Z_LVAL_P(*zend_std_get_static_property(THIS_CE, ZEND_STRS("mode")-1, 0 ZEND_LITERAL_NIL_CC TSRMLS_CC))) {
17701 + zval *data = *zend_std_get_static_property(THIS_CE, ZEND_STRS("data")-1, 0 ZEND_LITERAL_NIL_CC TSRMLS_CC);
17702 + ct = http_guess_content_type(magic_file, magic_mode, Z_STRVAL_P(data), Z_STRLEN_P(data), SEND_DATA);
17709 + zval *z = *zend_std_get_static_property(THIS_CE, ZEND_STRS("stream")-1, 0 ZEND_LITERAL_NIL_CC TSRMLS_CC);
17710 + z->type = IS_RESOURCE;
17711 + php_stream_from_zval(s, &z);
17712 + ct = http_guess_content_type(magic_file, magic_mode, s, 0, SEND_RSRC);
17717 + ct = http_guess_content_type(magic_file, magic_mode, Z_STRVAL_P(*zend_std_get_static_property(THIS_CE, ZEND_STRS("file")-1, 0 ZEND_LITERAL_NIL_CC TSRMLS_CC)), 0, -1);
17721 + zend_update_static_property_string(THIS_CE, ZEND_STRS("contentType")-1, ct TSRMLS_CC);
17722 + RETVAL_STRING(ct, 0);
17727 + http_error(HE_THROW, HTTP_E_RUNTIME, "Cannot guess Content-Type; libmagic not available");
17733 +/* {{{ proto static bool HttpResponse::setContentDisposition(string filename[, bool inline = false])
17734 + Set the Content-Disposition. */
17735 +PHP_METHOD(HttpResponse, setContentDisposition)
17740 + zend_bool send_inline = 0;
17742 + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|b", &file, &file_len, &send_inline)) {
17746 + cd_len = spprintf(&cd, 0, "%s; filename=\"%s\"", send_inline ? "inline" : "attachment", file);
17747 + RETVAL_SUCCESS(zend_update_static_property_stringl(THIS_CE, ZEND_STRS("contentDisposition")-1, cd, cd_len TSRMLS_CC));
17752 +/* {{{ proto static string HttpResponse::getContentDisposition()
17753 + Get current Content-Disposition setting. */
17754 +PHP_METHOD(HttpResponse, getContentDisposition)
17758 + if (return_value_used) {
17759 + zval *cdisp = http_zsep(IS_STRING, *(zend_std_get_static_property(THIS_CE, ZEND_STRS("contentDisposition")-1, 0 ZEND_LITERAL_NIL_CC TSRMLS_CC)));
17760 + RETVAL_ZVAL(cdisp, 1, 1);
17765 +/* {{{ proto static bool HttpResponse::setETag(string etag)
17766 + Set a custom ETag. Use this only if you know what you're doing. */
17767 +PHP_METHOD(HttpResponse, setETag)
17772 + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &etag, &etag_len)) {
17776 + RETURN_SUCCESS(zend_update_static_property_stringl(THIS_CE, ZEND_STRS("eTag")-1, etag, etag_len TSRMLS_CC));
17780 +/* {{{ proto static string HttpResponse::getETag()
17781 + Get calculated or previously set custom ETag. */
17782 +PHP_METHOD(HttpResponse, getETag)
17786 + if (return_value_used) {
17787 + zval *etag = http_zsep(IS_STRING, *(zend_std_get_static_property(THIS_CE, ZEND_STRS("eTag")-1, 0 ZEND_LITERAL_NIL_CC TSRMLS_CC)));
17788 + RETVAL_ZVAL(etag, 1, 1);
17793 +/* {{{ proto static bool HttpResponse::setLastModified(int timestamp)
17794 + Set a custom Last-Modified date. */
17795 +PHP_METHOD(HttpResponse, setLastModified)
17799 + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &lm)) {
17803 + RETURN_SUCCESS(zend_update_static_property_long(THIS_CE, ZEND_STRS("lastModified")-1, lm TSRMLS_CC));
17807 +/* {{{ proto static int HttpResponse::getLastModified()
17808 + Get calculated or previously set custom Last-Modified date. */
17809 +PHP_METHOD(HttpResponse, getLastModified)
17813 + if (return_value_used) {
17814 + zval *lmod = http_zsep(IS_LONG, *(zend_std_get_static_property(THIS_CE, ZEND_STRS("lastModified")-1, 0 ZEND_LITERAL_NIL_CC TSRMLS_CC)));
17815 + RETVAL_ZVAL(lmod, 1, 1);
17820 +/* {{{ proto static bool HttpResponse::setThrottleDelay(double seconds)
17821 + Sets the throttle delay for use with HttpResponse::setBufferSize(). */
17822 +PHP_METHOD(HttpResponse, setThrottleDelay)
17826 + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "d", &seconds)) {
17829 + RETURN_SUCCESS(zend_update_static_property_double(THIS_CE, ZEND_STRS("throttleDelay")-1, seconds TSRMLS_CC));
17833 +/* {{{ proto static double HttpResponse::getThrottleDelay()
17834 + Get the current throttle delay. */
17835 +PHP_METHOD(HttpResponse, getThrottleDelay)
17839 + if (return_value_used) {
17840 + zval *tdel = http_zsep(IS_DOUBLE, *(zend_std_get_static_property(THIS_CE, ZEND_STRS("throttleDelay")-1, 0 ZEND_LITERAL_NIL_CC TSRMLS_CC)));
17841 + RETVAL_ZVAL(tdel, 1, 1);
17846 +/* {{{ proto static bool HttpResponse::setBufferSize(int bytes)
17847 + Sets the send buffer size for use with HttpResponse::setThrottleDelay(). */
17848 +PHP_METHOD(HttpResponse, setBufferSize)
17852 + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &bytes)) {
17855 + RETURN_SUCCESS(zend_update_static_property_long(THIS_CE, ZEND_STRS("bufferSize")-1, bytes TSRMLS_CC));
17859 +/* {{{ proto static int HttpResponse::getBufferSize()
17860 + Get current buffer size. */
17861 +PHP_METHOD(HttpResponse, getBufferSize)
17865 + if (return_value_used) {
17866 + zval *bsize = http_zsep(IS_LONG, *(zend_std_get_static_property(THIS_CE, ZEND_STRS("bufferSize")-1, 0 ZEND_LITERAL_NIL_CC TSRMLS_CC)));
17867 + RETVAL_ZVAL(bsize, 1, 1);
17872 +/* {{{ proto static bool HttpResponse::setData(mixed data)
17873 + Set the data to be sent. */
17874 +PHP_METHOD(HttpResponse, setData)
17879 + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z/", &the_data)) {
17882 + if (Z_TYPE_P(the_data) != IS_STRING) {
17883 + convert_to_string(the_data);
17886 + if ( (SUCCESS != zend_update_static_property(THIS_CE, ZEND_STRS("data")-1, the_data TSRMLS_CC)) ||
17887 + (SUCCESS != zend_update_static_property_long(THIS_CE, ZEND_STRS("mode")-1, SEND_DATA TSRMLS_CC))) {
17891 + zend_update_static_property_long(THIS_CE, ZEND_STRS("lastModified")-1, http_last_modified(the_data, SEND_DATA) TSRMLS_CC);
17892 + if ((etag = http_etag(Z_STRVAL_P(the_data), Z_STRLEN_P(the_data), SEND_DATA))) {
17893 + zend_update_static_property_string(THIS_CE, ZEND_STRS("eTag")-1, etag TSRMLS_CC);
17901 +/* {{{ proto static string HttpResponse::getData()
17902 + Get the previously set data to be sent. */
17903 +PHP_METHOD(HttpResponse, getData)
17907 + if (return_value_used) {
17908 + zval *the_data = *zend_std_get_static_property(THIS_CE, ZEND_STRS("data")-1, 0 ZEND_LITERAL_NIL_CC TSRMLS_CC);
17910 + RETURN_ZVAL(the_data, 1, 0);
17915 +/* {{{ proto static bool HttpResponse::setStream(resource stream)
17916 + Set the resource to be sent. */
17917 +PHP_METHOD(HttpResponse, setStream)
17920 + zval *the_stream;
17921 + php_stream *the_real_stream;
17922 + php_stream_statbuf ssb;
17924 + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &the_stream)) {
17928 + php_stream_from_zval(the_real_stream, &the_stream);
17929 + if (php_stream_stat(the_real_stream, &ssb)) {
17933 + if ( (SUCCESS != zend_update_static_property_long(THIS_CE, ZEND_STRS("stream")-1, Z_LVAL_P(the_stream) TSRMLS_CC)) ||
17934 + (SUCCESS != zend_update_static_property_long(THIS_CE, ZEND_STRS("mode")-1, SEND_RSRC TSRMLS_CC))) {
17937 + zend_list_addref(Z_LVAL_P(the_stream));
17939 + zend_update_static_property_long(THIS_CE, ZEND_STRS("lastModified")-1, http_last_modified(the_real_stream, SEND_RSRC) TSRMLS_CC);
17940 + if ((etag = http_etag(the_real_stream, 0, SEND_RSRC))) {
17941 + zend_update_static_property_string(THIS_CE, ZEND_STRS("eTag")-1, etag TSRMLS_CC);
17949 +/* {{{ proto static resource HttpResponse::getStream()
17950 + Get the previously set resource to be sent. */
17951 +PHP_METHOD(HttpResponse, getStream)
17955 + if (return_value_used) {
17956 + zval *stream = http_zsep(IS_LONG, *(zend_std_get_static_property(THIS_CE, ZEND_STRS("stream")-1, 0 ZEND_LITERAL_NIL_CC TSRMLS_CC)));
17957 + RETVAL_RESOURCE(Z_LVAL_P(stream));
17958 + zval_ptr_dtor(&stream);
17963 +/* {{{ proto static bool HttpResponse::setFile(string file)
17964 + Set the file to be sent. */
17965 +PHP_METHOD(HttpResponse, setFile)
17967 + char *the_file, *etag;
17969 + php_stream_statbuf ssb;
17971 + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &the_file, &file_len)) {
17975 + if (php_stream_stat_path(the_file, &ssb)) {
17979 + if ( (SUCCESS != zend_update_static_property_stringl(THIS_CE, ZEND_STRS("file")-1, the_file, file_len TSRMLS_CC)) ||
17980 + (SUCCESS != zend_update_static_property_long(THIS_CE, ZEND_STRS("mode")-1, -1 TSRMLS_CC))) {
17984 + zend_update_static_property_long(THIS_CE, ZEND_STRS("lastModified")-1, http_last_modified(the_file, -1) TSRMLS_CC);
17985 + if ((etag = http_etag(the_file, 0, -1))) {
17986 + zend_update_static_property_string(THIS_CE, ZEND_STRS("eTag")-1, etag TSRMLS_CC);
17994 +/* {{{ proto static string HttpResponse::getFile()
17995 + Get the previously set file to be sent. */
17996 +PHP_METHOD(HttpResponse, getFile)
18000 + if (return_value_used) {
18001 + zval *file = http_zsep(IS_STRING, *(zend_std_get_static_property(THIS_CE, ZEND_STRS("file")-1, 0 ZEND_LITERAL_NIL_CC TSRMLS_CC)));
18002 + RETVAL_ZVAL(file, 1, 1);
18007 +/* {{{ proto static bool HttpResponse::send([bool clean_ob = true])
18008 + Finally send the entity. */
18009 +PHP_METHOD(HttpResponse, send)
18012 + zend_bool clean_ob = 1;
18014 + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &clean_ob)) {
18018 + HTTP_CHECK_HEADERS_SENT(RETURN_FALSE);
18020 + sent = *zend_std_get_static_property(THIS_CE, ZEND_STRS("sent")-1, 0 ZEND_LITERAL_NIL_CC TSRMLS_CC);
18021 + if (Z_LVAL_P(sent)) {
18022 + http_error(HE_WARNING, HTTP_E_RESPONSE, "Cannot send HttpResponse, response has already been sent");
18025 + Z_LVAL_P(sent) = 1;
18028 + /* capture mode */
18029 + if (i_zend_is_true(*zend_std_get_static_property(THIS_CE, ZEND_STRS("catch")-1, 0 ZEND_LITERAL_NIL_CC TSRMLS_CC))) {
18030 + zval *zetag, *the_data;
18032 + MAKE_STD_ZVAL(the_data);
18033 +#ifdef PHP_OUTPUT_NEWAPI
18034 + php_output_get_contents(the_data TSRMLS_CC);
18036 + php_ob_get_buffer(the_data TSRMLS_CC);
18038 + zend_update_static_property(THIS_CE, ZEND_STRS("data")-1, the_data TSRMLS_CC);
18039 + ZVAL_LONG(*zend_std_get_static_property(THIS_CE, ZEND_STRS("mode")-1, 0 ZEND_LITERAL_NIL_CC TSRMLS_CC), SEND_DATA);
18041 + zetag = http_zsep(IS_STRING, *(zend_std_get_static_property(THIS_CE, ZEND_STRS("eTag")-1, 0 ZEND_LITERAL_NIL_CC TSRMLS_CC)));
18042 + if (!Z_STRLEN_P(zetag)) {
18043 + char *etag = http_etag(Z_STRVAL_P(the_data), Z_STRLEN_P(the_data), SEND_DATA);
18045 + zend_update_static_property_string(THIS_CE, ZEND_STRS("eTag")-1, etag TSRMLS_CC);
18049 + zval_ptr_dtor(&the_data);
18050 + zval_ptr_dtor(&zetag);
18056 + /* interrupt on-the-fly etag generation */
18057 + HTTP_G->etag.started = 0;
18058 + /* discard previous output buffers */
18059 +#ifdef PHP_OUTPUT_NEWAPI
18060 + php_output_discard_all(TSRMLS_C);
18062 + php_end_ob_buffers(0 TSRMLS_CC);
18067 + if (i_zend_is_true(*zend_std_get_static_property(THIS_CE, ZEND_STRS("cache")-1, 0 ZEND_LITERAL_NIL_CC TSRMLS_CC))) {
18068 + zval *cctl, *etag, *lmod;
18070 + lmod = http_zsep(IS_LONG, *(zend_std_get_static_property(THIS_CE, ZEND_STRS("lastModified")-1, 0 ZEND_LITERAL_NIL_CC TSRMLS_CC)));
18071 + etag = http_zsep(IS_STRING, *(zend_std_get_static_property(THIS_CE, ZEND_STRS("eTag")-1, 0 ZEND_LITERAL_NIL_CC TSRMLS_CC)));
18072 + cctl = http_zsep(IS_STRING, *(zend_std_get_static_property(THIS_CE, ZEND_STRS("cacheControl")-1, 0 ZEND_LITERAL_NIL_CC TSRMLS_CC)));
18074 + if (Z_LVAL_P(lmod) || Z_STRLEN_P(etag)) {
18075 + if (Z_STRLEN_P(cctl)) {
18076 + http_send_cache_control(Z_STRVAL_P(cctl), Z_STRLEN_P(cctl));
18078 + http_send_cache_control(HTTP_DEFAULT_CACHECONTROL, lenof(HTTP_DEFAULT_CACHECONTROL));
18080 + if (Z_STRLEN_P(etag)) {
18081 + http_send_etag(Z_STRVAL_P(etag), Z_STRLEN_P(etag));
18083 + if (Z_LVAL_P(lmod)) {
18084 + http_send_last_modified(Z_LVAL_P(lmod));
18088 + zval_ptr_dtor(&etag);
18089 + zval_ptr_dtor(&lmod);
18090 + zval_ptr_dtor(&cctl);
18093 + /* content type */
18095 + zval *ctype = http_zsep(IS_STRING, *(zend_std_get_static_property(THIS_CE, ZEND_STRS("contentType")-1, 0 ZEND_LITERAL_NIL_CC TSRMLS_CC)));
18096 + if (Z_STRLEN_P(ctype)) {
18097 + http_send_content_type(Z_STRVAL_P(ctype), Z_STRLEN_P(ctype));
18099 + char *ctypes = INI_STR("default_mimetype");
18100 + size_t ctlen = ctypes ? strlen(ctypes) : 0;
18103 + http_send_content_type(ctypes, ctlen);
18105 + http_send_content_type("application/x-octetstream", lenof("application/x-octetstream"));
18108 + zval_ptr_dtor(&ctype);
18111 + /* content disposition */
18113 + zval *cd = http_zsep(IS_STRING, *(zend_std_get_static_property(THIS_CE, ZEND_STRS("contentDisposition")-1, 0 ZEND_LITERAL_NIL_CC TSRMLS_CC)));
18114 + if (Z_STRLEN_P(cd)) {
18115 + http_send_header_ex("Content-Disposition", lenof("Content-Disposition"), Z_STRVAL_P(cd), Z_STRLEN_P(cd), 1, NULL);
18117 + zval_ptr_dtor(&cd);
18122 + zval *bsize = http_zsep(IS_LONG, *(zend_std_get_static_property(THIS_CE, ZEND_STRS("bufferSize")-1, 0 ZEND_LITERAL_NIL_CC TSRMLS_CC)));
18123 + zval *delay = http_zsep(IS_DOUBLE, *(zend_std_get_static_property(THIS_CE, ZEND_STRS("throttleDelay")-1, 0 ZEND_LITERAL_NIL_CC TSRMLS_CC)));
18124 + HTTP_G->send.buffer_size = Z_LVAL_P(bsize);
18125 + HTTP_G->send.throttle_delay = Z_DVAL_P(delay);
18126 + zval_ptr_dtor(&bsize);
18127 + zval_ptr_dtor(&delay);
18131 + HTTP_G->send.deflate.response = i_zend_is_true(*zend_std_get_static_property(THIS_CE, ZEND_STRS("gzip")-1, 0 ZEND_LITERAL_NIL_CC TSRMLS_CC));
18134 + switch (Z_LVAL_P(*zend_std_get_static_property(THIS_CE, ZEND_STRS("mode")-1, 0 ZEND_LITERAL_NIL_CC TSRMLS_CC))) {
18137 + zval *zdata = http_zsep(IS_STRING, *(zend_std_get_static_property(THIS_CE, ZEND_STRS("data")-1, 0 ZEND_LITERAL_NIL_CC TSRMLS_CC)));
18138 + RETVAL_SUCCESS(http_send_data(Z_STRVAL_P(zdata), Z_STRLEN_P(zdata)));
18139 + zval_ptr_dtor(&zdata);
18145 + php_stream *the_real_stream;
18146 + zval *the_stream = http_zsep(IS_LONG, *(zend_std_get_static_property(THIS_CE, ZEND_STRS("stream")-1, 0 ZEND_LITERAL_NIL_CC TSRMLS_CC)));
18147 + the_stream->type = IS_RESOURCE;
18148 + php_stream_from_zval(the_real_stream, &the_stream);
18149 + RETVAL_SUCCESS(http_send_stream(the_real_stream));
18150 + zval_ptr_dtor(&the_stream);
18156 + zval *file = http_zsep(IS_STRING, *(zend_std_get_static_property(THIS_CE, ZEND_STRS("file")-1, 0 ZEND_LITERAL_NIL_CC TSRMLS_CC)));
18157 + RETVAL_SUCCESS(http_send_file(Z_STRVAL_P(file)));
18158 + zval_ptr_dtor(&file);
18165 +/* {{{ proto static void HttpResponse::capture()
18166 + Capture script output.
18168 +PHP_METHOD(HttpResponse, capture)
18172 + HTTP_CHECK_HEADERS_SENT(RETURN_FALSE);
18174 + zend_update_static_property_long(THIS_CE, ZEND_STRS("catch")-1, 1 TSRMLS_CC);
18175 +#ifdef PHP_OUTPUT_NEWAPI
18176 + php_output_discard_all(TSRMLS_C);
18177 + php_output_start_default(TSRMLS_C);
18179 + php_end_ob_buffers(0 TSRMLS_CC);
18180 + php_start_ob_buffer(NULL, 0, 0 TSRMLS_CC);
18183 + /* register shutdown function */
18185 + zval func, retval, arg, *argp[1];
18187 + INIT_PZVAL(&arg);
18188 + INIT_PZVAL(&func);
18189 + INIT_PZVAL(&retval);
18190 + ZVAL_STRINGL(&func, "register_shutdown_function", lenof("register_shutdown_function"), 0);
18192 + array_init(&arg);
18193 + add_next_index_stringl(&arg, "HttpResponse", lenof("HttpResponse"), 1);
18194 + add_next_index_stringl(&arg, "send", lenof("send"), 1);
18196 + call_user_function(EG(function_table), NULL, &func, &retval, 1, argp TSRMLS_CC);
18202 +#endif /* ZEND_ENGINE_2 && !WONKY */
18205 + * Local variables:
18207 + * c-basic-offset: 4
18209 + * vim600: noet sw=4 ts=4 fdm=marker
18210 + * vim<600: noet sw=4 ts=4
18214 +++ b/ext/http/http_send_api.c
18217 + +--------------------------------------------------------------------+
18219 + +--------------------------------------------------------------------+
18220 + | Redistribution and use in source and binary forms, with or without |
18221 + | modification, are permitted provided that the conditions mentioned |
18222 + | in the accompanying LICENSE file are met. |
18223 + +--------------------------------------------------------------------+
18224 + | Copyright (c) 2004-2010, Michael Wallner <mike@php.net> |
18225 + +--------------------------------------------------------------------+
18228 +/* $Id: http_send_api.c 312028 2011-06-10 22:03:12Z felipe $ */
18230 +#define HTTP_WANT_SAPI
18231 +#define HTTP_WANT_ZLIB
18232 +#define HTTP_WANT_MAGIC
18233 +#include "php_http.h"
18235 +#include "php_streams.h"
18237 +#include "php_http_api.h"
18238 +#include "php_http_cache_api.h"
18239 +#include "php_http_date_api.h"
18240 +#include "php_http_encoding_api.h"
18241 +#include "php_http_headers_api.h"
18242 +#include "php_http_send_api.h"
18244 +/* {{{ http_flush() */
18245 +#define http_flush(d, l) _http_flush(NULL, (d), (l) TSRMLS_CC)
18246 +static inline void _http_flush(void *nothing, const char *data, size_t data_len TSRMLS_DC)
18248 + PHPWRITE(data, data_len);
18249 + /* we really only need to flush when throttling is enabled,
18250 + because we push the data as fast as possible anyway if not */
18251 + if (HTTP_G->send.throttle_delay >= HTTP_DIFFSEC) {
18252 +#if defined(PHP_VERSION_ID) && (PHP_VERSION_ID >= 50399)
18253 + php_output_end_all(TSRMLS_C);
18255 + if (OG(ob_nesting_level)) {
18256 + php_end_ob_buffer(1, 1 TSRMLS_CC);
18258 + if (!OG(implicit_flush)) {
18259 + sapi_flush(TSRMLS_C);
18262 + http_sleep(HTTP_G->send.throttle_delay);
18267 +/* {{{ http_send_response_start */
18268 +#define http_send_response_start(b, cl) _http_send_response_start((b), (cl) TSRMLS_CC)
18269 +static inline void _http_send_response_start(void **buffer, size_t content_length TSRMLS_DC)
18273 + if ((encoding = http_encoding_response_start(content_length, 0))) {
18274 +#ifdef HTTP_HAVE_ZLIB
18275 + *((http_encoding_stream **) buffer) = http_encoding_deflate_stream_init(NULL,
18276 + (encoding == HTTP_ENCODING_GZIP) ?
18277 + HTTP_DEFLATE_TYPE_GZIP : HTTP_DEFLATE_TYPE_ZLIB);
18280 + /* flush headers */
18281 + sapi_flush(TSRMLS_C);
18285 +/* {{{ http_send_response_data_plain */
18286 +#define http_send_response_data_plain(b, d, dl) _http_send_response_data_plain((b), (d), (dl) TSRMLS_CC)
18287 +static inline void _http_send_response_data_plain(void **buffer, const char *data, size_t data_len TSRMLS_DC)
18289 + if (HTTP_G->send.deflate.response && HTTP_G->send.deflate.encoding) {
18290 +#ifdef HTTP_HAVE_ZLIB
18292 + size_t encoded_len;
18293 + http_encoding_stream *s = *((http_encoding_stream **) buffer);
18295 + http_encoding_deflate_stream_update(s, data, data_len, &encoded, &encoded_len);
18296 + if (HTTP_G->send.buffer_size) {
18297 + phpstr_chunked_output((phpstr **) &s->storage, encoded, encoded_len, HTTP_G->send.buffer_size, _http_flush, NULL TSRMLS_CC);
18299 + http_flush(encoded, encoded_len);
18303 + http_error(HE_ERROR, HTTP_E_RESPONSE, "Attempt to send GZIP response despite being able to do so; please report this bug");
18305 + } else if (HTTP_G->send.buffer_size) {
18306 + phpstr_chunked_output((phpstr **) buffer, data, data_len, HTTP_G->send.buffer_size, _http_flush, NULL TSRMLS_CC);
18308 + http_flush(data, data_len);
18313 +/* {{{ http_send_response_data_fetch */
18314 +#define http_send_response_data_fetch(b, d, l, m, s, e) _http_send_response_data_fetch((b), (d), (l), (m), (s), (e) TSRMLS_CC)
18315 +static inline void _http_send_response_data_fetch(void **buffer, const void *data, size_t data_len, http_send_mode mode, size_t begin, size_t end TSRMLS_DC)
18317 + long bsz, got, len = end - begin;
18319 + if (!(bsz = HTTP_G->send.buffer_size)) {
18320 + bsz = HTTP_SENDBUF_SIZE;
18324 + case SEND_RSRC: {
18325 + php_stream *s = (php_stream *) data;
18326 + if (SUCCESS == php_stream_seek(s, begin, SEEK_SET)) {
18327 + char *buf = emalloc(bsz);
18329 + while (len > 0) {
18330 + got = php_stream_read(s, buf, MIN(len, bsz));
18331 + http_send_response_data_plain(buffer, buf, got);
18339 + case SEND_DATA: {
18340 + const char *buf = ((const char *) data) + begin;
18341 + while (len > 0) {
18342 + got = MIN(len, bsz);
18343 + http_send_response_data_plain(buffer, buf, got);
18349 + EMPTY_SWITCH_DEFAULT_CASE();
18354 +/* {{{ http_send_response_finish */
18355 +#define http_send_response_finish(b) _http_send_response_finish((b) TSRMLS_CC)
18356 +static inline void _http_send_response_finish(void **buffer TSRMLS_DC)
18358 + if (HTTP_G->send.deflate.response && HTTP_G->send.deflate.encoding) {
18359 +#ifdef HTTP_HAVE_ZLIB
18360 + char *encoded = NULL;
18361 + size_t encoded_len = 0;
18362 + http_encoding_stream *s = *((http_encoding_stream **) buffer);
18364 + http_encoding_deflate_stream_finish(s, &encoded, &encoded_len);
18365 + if (HTTP_G->send.buffer_size) {
18366 + phpstr_chunked_output((phpstr **) &s->storage, encoded, encoded_len, 0, _http_flush, NULL TSRMLS_CC);
18368 + http_flush(encoded, encoded_len);
18370 + http_encoding_deflate_stream_free(&s);
18371 + STR_FREE(encoded);
18373 + http_error(HE_ERROR, HTTP_E_RESPONSE, "Attempt to send GZIP response despite being able to do so; please report this bug");
18375 + } else if (HTTP_G->send.buffer_size) {
18376 + phpstr_chunked_output((phpstr **) buffer, NULL, 0, 0, _http_flush, NULL TSRMLS_CC);
18382 +PHP_MINIT_FUNCTION(http_send)
18384 + HTTP_LONG_CONSTANT("HTTP_REDIRECT", HTTP_REDIRECT);
18385 + HTTP_LONG_CONSTANT("HTTP_REDIRECT_PERM", HTTP_REDIRECT_PERM);
18386 + HTTP_LONG_CONSTANT("HTTP_REDIRECT_FOUND", HTTP_REDIRECT_FOUND);
18387 + HTTP_LONG_CONSTANT("HTTP_REDIRECT_POST", HTTP_REDIRECT_POST);
18388 + HTTP_LONG_CONSTANT("HTTP_REDIRECT_PROXY", HTTP_REDIRECT_PROXY);
18389 + HTTP_LONG_CONSTANT("HTTP_REDIRECT_TEMP", HTTP_REDIRECT_TEMP);
18395 +/* {{{ http_find_header */
18399 +} http_response_header_t;
18401 +static int http_find_header(void *data, void *arg)
18403 + http_response_header_t *h = arg;
18404 + sapi_header_struct *s = data;
18406 + return (!strncasecmp(s->header, h->h, h->l)) && s->header[h->l] == ':';
18410 +/* {{{ void http_hide_header(char *) */
18411 +PHP_HTTP_API void _http_hide_header_ex(const char *name, size_t name_len TSRMLS_DC)
18413 + http_response_header_t h = {name, name_len};
18414 + zend_llist_del_element(&SG(sapi_headers).headers, (void *) &h, http_find_header);
18418 +/* {{{ void http_send_header_zval(char*, zval **, zend_bool) */
18419 +PHP_HTTP_API void _http_send_header_zval_ex(const char *name, size_t name_len, zval **val, zend_bool replace TSRMLS_DC)
18421 + if (!val || !*val || Z_TYPE_PP(val) == IS_NULL || (Z_TYPE_PP(val) == IS_STRING && !Z_STRLEN_PP(val))) {
18422 + http_hide_header_ex(name, name_len);
18423 + } else if (Z_TYPE_PP(val) == IS_ARRAY || Z_TYPE_PP(val) == IS_OBJECT) {
18424 + zend_bool first = replace;
18426 + HashPosition pos;
18428 + FOREACH_HASH_VAL(pos, HASH_OF(*val), data_ptr) {
18429 + zval *data = http_zsep(IS_STRING, *data_ptr);
18431 + http_send_header_ex(name, name_len, Z_STRVAL_P(data), Z_STRLEN_P(data), first, NULL);
18432 + zval_ptr_dtor(&data);
18436 + zval *data = http_zsep(IS_STRING, *val);
18438 + http_send_header_ex(name, name_len, Z_STRVAL_P(data), Z_STRLEN_P(data), replace, NULL);
18439 + zval_ptr_dtor(&data);
18444 +/* {{{ STATUS http_send_header(char *, char *, zend_bool) */
18445 +PHP_HTTP_API STATUS _http_send_header_ex(const char *name, size_t name_len, const char *value, size_t value_len, zend_bool replace, char **sent_header TSRMLS_DC)
18449 + if (value && value_len) {
18450 + size_t header_len = sizeof(": ") + name_len + value_len + 1;
18451 + char *header = emalloc(header_len + 1);
18453 + header[header_len] = '\0';
18454 + header_len = snprintf(header, header_len, "%s: %s", name, value);
18455 + ret = http_send_header_string_ex(header, header_len, replace);
18456 + if (sent_header) {
18457 + *sent_header = header;
18462 + http_hide_header_ex(name, name_len);
18469 +/* {{{ STATUS http_send_status_header(int, char *) */
18470 +PHP_HTTP_API STATUS _http_send_status_header_ex(int status, const char *header, size_t header_len, zend_bool replace TSRMLS_DC)
18473 + sapi_header_line h = {(char *) header, header_len, status};
18474 + if (SUCCESS != (ret = sapi_header_op(replace ? SAPI_HEADER_REPLACE : SAPI_HEADER_ADD, &h TSRMLS_CC))) {
18475 + http_error_ex(HE_WARNING, HTTP_E_HEADER, "Could not send header: %s (%d)", header, status);
18481 +/* {{{ STATUS http_send_last_modified(int) */
18482 +PHP_HTTP_API STATUS _http_send_last_modified_ex(time_t t, char **sent_header TSRMLS_DC)
18485 + char *date = http_date(t);
18491 + ret = http_send_header_ex("Last-Modified", lenof("Last-Modified"), date, strlen(date), 1, sent_header);
18495 + HTTP_G->send.last_modified = t;
18501 +/* {{{ STATUS http_send_etag(char *, size_t) */
18502 +PHP_HTTP_API STATUS _http_send_etag_ex(const char *etag, size_t etag_len, char **sent_header TSRMLS_DC)
18505 + char *etag_header;
18506 + size_t etag_header_len;
18509 + http_error_ex(HE_WARNING, HTTP_E_HEADER, "Attempt to send empty ETag (previous: %s)\n", HTTP_G->send.unquoted_etag);
18513 + etag_header_len = spprintf(&etag_header, 0, "ETag: \"%s\"", etag);
18514 + status = http_send_header_string_ex(etag_header, etag_header_len, 1);
18517 + STR_SET(HTTP_G->send.unquoted_etag, estrndup(etag, etag_len));
18519 + if (sent_header) {
18520 + *sent_header = etag_header;
18522 + efree(etag_header);
18529 +/* {{{ STATUS http_send_content_type(char *, size_t) */
18530 +PHP_HTTP_API STATUS _http_send_content_type(const char *content_type, size_t ct_len TSRMLS_DC)
18532 + HTTP_CHECK_CONTENT_TYPE(content_type, return FAILURE);
18534 + /* remember for multiple ranges */
18535 + STR_FREE(HTTP_G->send.content_type);
18536 + HTTP_G->send.content_type = estrndup(content_type, ct_len);
18538 + return http_send_header_ex("Content-Type", lenof("Content-Type"), content_type, ct_len, 1, NULL);
18542 +/* {{{ STATUS http_send_content_disposition(char *, size_t, zend_bool) */
18543 +PHP_HTTP_API STATUS _http_send_content_disposition(const char *filename, size_t f_len, zend_bool send_inline TSRMLS_DC)
18548 + if (send_inline) {
18549 + cd_header = ecalloc(1, sizeof("Content-Disposition: inline; filename=\"\"") + f_len);
18550 + sprintf(cd_header, "Content-Disposition: inline; filename=\"%s\"", filename);
18552 + cd_header = ecalloc(1, sizeof("Content-Disposition: attachment; filename=\"\"") + f_len);
18553 + sprintf(cd_header, "Content-Disposition: attachment; filename=\"%s\"", filename);
18556 + status = http_send_header_string(cd_header);
18557 + efree(cd_header);
18562 +/* {{{ STATUS http_send(void *, size_t, http_send_mode) */
18563 +PHP_HTTP_API STATUS _http_send_ex(const void *data_ptr, size_t data_size, http_send_mode data_mode, zend_bool no_cache TSRMLS_DC)
18566 + HashTable ranges;
18567 + http_range_status range_status;
18572 + if (!data_size) {
18576 + /* enable partial dl and resume */
18577 + http_send_header_string("Accept-Ranges: bytes");
18579 + zend_hash_init(&ranges, 0, NULL, ZVAL_PTR_DTOR, 0);
18580 + range_status = http_get_request_ranges(&ranges, data_size);
18582 + switch (range_status) {
18585 + zend_hash_destroy(&ranges);
18586 + http_send_status(416);
18591 + /* Range Request - only send ranges if entity hasn't changed */
18592 + if ( http_got_server_var("HTTP_IF_RANGE") &&
18593 + !http_match_etag("HTTP_IF_RANGE", HTTP_G->send.unquoted_etag) &&
18594 + !http_match_last_modified("HTTP_IF_RANGE", HTTP_G->send.last_modified)) {
18595 + /* fallthrough to send full entity with 200 Ok */
18597 + } else if ( !http_match_etag_ex("HTTP_IF_MATCH", HTTP_G->send.unquoted_etag, 0) ||
18598 + !http_match_last_modified_ex("HTTP_IF_UNMODIFIED_SINCE", HTTP_G->send.last_modified, 0) ||
18599 + !http_match_last_modified_ex("HTTP_UNLESS_MODIFIED_SINCE", HTTP_G->send.last_modified, 0)) {
18600 + /* 412 Precondition failed */
18601 + zend_hash_destroy(&ranges);
18602 + http_send_status(412);
18604 + } else if (zend_hash_num_elements(&ranges) == 1) {
18605 + /* single range */
18606 + zval **range, **begin, **end;
18608 + if ( SUCCESS != zend_hash_index_find(&ranges, 0, (void *) &range) ||
18609 + SUCCESS != zend_hash_index_find(Z_ARRVAL_PP(range), 0, (void *) &begin) ||
18610 + SUCCESS != zend_hash_index_find(Z_ARRVAL_PP(range), 1, (void *) &end)) {
18611 + /* this should never happen */
18612 + zend_hash_destroy(&ranges);
18613 + http_send_status(500);
18618 + phpstr_init(&header);
18619 + phpstr_appendf(&header, "Content-Range: bytes %ld-%ld/%zu", Z_LVAL_PP(begin), Z_LVAL_PP(end), data_size);
18620 + phpstr_fix(&header);
18621 + http_send_status_header_ex(206, PHPSTR_VAL(&header), PHPSTR_LEN(&header), 1);
18622 + phpstr_dtor(&header);
18623 + http_send_response_start(&s, Z_LVAL_PP(end)-Z_LVAL_PP(begin)+1);
18624 + http_send_response_data_fetch(&s, data_ptr, data_size, data_mode, Z_LVAL_PP(begin), Z_LVAL_PP(end) + 1);
18625 + http_send_response_finish(&s);
18626 + zend_hash_destroy(&ranges);
18630 + /* multi range */
18631 + HashPosition pos;
18632 + zval **range, **begin, **end;
18633 + const char *content_type = HTTP_G->send.content_type;
18634 + char boundary_str[32];
18635 + size_t boundary_len;
18636 + phpstr header, preface;
18638 + boundary_len = http_boundary(boundary_str, sizeof(boundary_str));
18639 + phpstr_init(&header);
18640 + phpstr_appendf(&header, "Content-Type: multipart/byteranges; boundary=%s", boundary_str);
18641 + phpstr_fix(&header);
18642 + http_send_status_header_ex(206, PHPSTR_VAL(&header), PHPSTR_LEN(&header), 1);
18643 + phpstr_dtor(&header);
18644 + http_send_response_start(&s, 0);
18646 + if (!content_type) {
18647 + content_type = "application/x-octetstream";
18650 + phpstr_init(&preface);
18651 + FOREACH_HASH_VAL(pos, &ranges, range) {
18652 + if ( SUCCESS == zend_hash_index_find(Z_ARRVAL_PP(range), 0, (void *) &begin) &&
18653 + SUCCESS == zend_hash_index_find(Z_ARRVAL_PP(range), 1, (void *) &end)) {
18655 +#define HTTP_RANGE_PREFACE \
18656 + HTTP_CRLF "--%s" \
18657 + HTTP_CRLF "Content-Type: %s" \
18658 + HTTP_CRLF "Content-Range: bytes %ld-%ld/%zu" \
18659 + HTTP_CRLF HTTP_CRLF
18661 + phpstr_appendf(&preface, HTTP_RANGE_PREFACE, boundary_str, content_type, Z_LVAL_PP(begin), Z_LVAL_PP(end), data_size);
18662 + phpstr_fix(&preface);
18663 + http_send_response_data_plain(&s, PHPSTR_VAL(&preface), PHPSTR_LEN(&preface));
18664 + phpstr_reset(&preface);
18665 + http_send_response_data_fetch(&s, data_ptr, data_size, data_mode, Z_LVAL_PP(begin), Z_LVAL_PP(end) + 1);
18668 + phpstr_dtor(&preface);
18670 + http_send_response_data_plain(&s, HTTP_CRLF "--", lenof(HTTP_CRLF "--"));
18671 + http_send_response_data_plain(&s, boundary_str, boundary_len);
18672 + http_send_response_data_plain(&s, "--", lenof("--"));
18674 + http_send_response_finish(&s);
18675 + zend_hash_destroy(&ranges);
18681 + zend_hash_destroy(&ranges);
18683 + /* send 304 Not Modified if etag matches - DON'T return on ETag generation failure */
18684 + if (!no_cache && (http_interrupt_ob_etaghandler() || (HTTP_G->send.unquoted_etag != NULL))) {
18685 + char *etag = NULL;
18687 + if (HTTP_G->send.unquoted_etag) {
18688 + etag = estrdup(HTTP_G->send.unquoted_etag);
18691 + if (etag || (etag = http_etag(data_ptr, data_size, data_mode))) {
18692 + char *sent_header = NULL;
18694 + http_send_etag_ex(etag, strlen(etag), &sent_header);
18695 + if (http_match_etag("HTTP_IF_NONE_MATCH", etag)) {
18696 + return http_exit_ex(304, sent_header, NULL, 0);
18698 + STR_FREE(sent_header);
18699 + /* no caching for Last-Modified if ETags really don't match */
18700 + no_cache = http_got_server_var("HTTP_IF_NONE_MATCH");
18706 + /* send 304 Not Modified if last modified matches */
18707 + if (!no_cache && HTTP_G->send.last_modified && http_match_last_modified("HTTP_IF_MODIFIED_SINCE", HTTP_G->send.last_modified)) {
18708 + char *sent_header = NULL;
18709 + http_send_last_modified_ex(HTTP_G->send.last_modified, &sent_header);
18710 + return http_exit_ex(304, sent_header, NULL, 0);
18713 + /* send full response */
18714 + http_send_response_start(&s, data_size);
18715 + http_send_response_data_fetch(&s, data_ptr, data_size, data_mode, 0, data_size);
18716 + http_send_response_finish(&s);
18724 +/* {{{ STATUS http_send_stream(php_stream *) */
18725 +PHP_HTTP_API STATUS _http_send_stream_ex(php_stream *file, zend_bool close_stream, zend_bool no_cache TSRMLS_DC)
18728 + php_stream_statbuf ssb;
18731 + if ((!file) || php_stream_stat(file, &ssb)) {
18732 + char *defct = sapi_get_default_content_type(TSRMLS_C);
18734 + http_hide_header("Content-Disposition");
18735 + http_send_content_type(defct, strlen(defct));
18736 + http_error(HE_WARNING, HTTP_E_RESPONSE, "File not found; stat failed");
18739 + if (HTTP_G->send.not_found_404) {
18740 + http_exit_ex(404, NULL, estrdup("File not found\n"), 0);
18745 + orig_flags = file->flags;
18746 + file->flags |= PHP_STREAM_FLAG_NO_BUFFER;
18747 + status = http_send_ex(file, ssb.sb.st_size, SEND_RSRC, no_cache);
18748 + file->flags = orig_flags;
18750 + if (close_stream) {
18751 + php_stream_close(file);
18758 +/* {{{ char *http_guess_content_type(char *magic_file, long magic_mode, void *data, size_t size, http_send_mode mode) */
18759 +PHP_HTTP_API char *_http_guess_content_type(const char *magicfile, long magicmode, void *data_ptr, size_t data_len, http_send_mode data_mode TSRMLS_DC)
18763 +#ifdef HTTP_HAVE_MAGIC
18764 + struct magic_set *magic = NULL;
18766 + HTTP_CHECK_OPEN_BASEDIR(magicfile, return NULL);
18769 + http_error(HE_WARNING, HTTP_E_INVALID_PARAM, "Supplied payload is empty");
18770 + } else if (!(magic = magic_open(magicmode &~ MAGIC_MIME))) {
18771 + http_error_ex(HE_WARNING, HTTP_E_INVALID_PARAM, "Invalid magic mode: %ld", magicmode);
18772 + } else if (-1 == magic_load(magic, magicfile)) {
18773 + http_error_ex(HE_WARNING, HTTP_E_RUNTIME, "Failed to load magic database '%s' (%s)", magicfile, magic_error(magic));
18775 + const char *ctype = NULL;
18777 + magic_setflags(magic, magicmode);
18779 + switch (data_mode) {
18785 + b_len = php_stream_copy_to_mem(data_ptr, &buffer, 65536, 0);
18786 + ctype = magic_buffer(magic, buffer, b_len);
18792 + ctype = magic_buffer(magic, data_ptr, data_len);
18796 + HTTP_CHECK_OPEN_BASEDIR(data_ptr, magic_close(magic); return NULL);
18797 + ctype = magic_file(magic, data_ptr);
18802 + ct = estrdup(ctype);
18804 + http_error_ex(HE_WARNING, HTTP_E_RUNTIME, "Failed to guess Content-Type: %s", magic_error(magic));
18808 + magic_close(magic);
18811 + http_error(HE_WARNING, HTTP_E_RUNTIME, "Cannot guess Content-Type; libmagic not available");
18819 + * Local variables:
18821 + * c-basic-offset: 4
18823 + * vim600: sw=4 ts=4 fdm=marker
18824 + * vim<600: sw=4 ts=4
18828 +++ b/ext/http/http_url_api.c
18831 + +--------------------------------------------------------------------+
18833 + +--------------------------------------------------------------------+
18834 + | Redistribution and use in source and binary forms, with or without |
18835 + | modification, are permitted provided that the conditions mentioned |
18836 + | in the accompanying LICENSE file are met. |
18837 + +--------------------------------------------------------------------+
18838 + | Copyright (c) 2004-2010, Michael Wallner <mike@php.net> |
18839 + +--------------------------------------------------------------------+
18842 +/* $Id: http_url_api.c 292841 2009-12-31 08:48:57Z mike $ */
18844 +#define HTTP_WANT_SAPI
18845 +#define HTTP_WANT_NETDB
18846 +#include "php_http.h"
18848 +#include "zend_ini.h"
18849 +#include "php_output.h"
18850 +#include "ext/standard/php_string.h"
18852 +#include "php_http_api.h"
18853 +#include "php_http_querystring_api.h"
18854 +#include "php_http_url_api.h"
18856 +static inline char *localhostname(void)
18858 + char hostname[1024] = {0};
18861 + if (SUCCESS == gethostname(hostname, lenof(hostname))) {
18862 + return estrdup(hostname);
18864 +#elif defined(HAVE_GETHOSTNAME)
18865 + if (SUCCESS == gethostname(hostname, lenof(hostname))) {
18866 +# if defined(HAVE_GETDOMAINNAME)
18867 + size_t hlen = strlen(hostname);
18868 + if (hlen <= lenof(hostname) - lenof("(none)")) {
18869 + hostname[hlen++] = '.';
18870 + if (SUCCESS == getdomainname(&hostname[hlen], lenof(hostname) - hlen)) {
18871 + if (!strcmp(&hostname[hlen], "(none)")) {
18872 + hostname[hlen - 1] = '\0';
18874 + return estrdup(hostname);
18878 + if (strcmp(hostname, "(none)")) {
18879 + return estrdup(hostname);
18883 + return estrndup("localhost", lenof("localhost"));
18886 +PHP_MINIT_FUNCTION(http_url)
18888 + HTTP_LONG_CONSTANT("HTTP_URL_REPLACE", HTTP_URL_REPLACE);
18889 + HTTP_LONG_CONSTANT("HTTP_URL_JOIN_PATH", HTTP_URL_JOIN_PATH);
18890 + HTTP_LONG_CONSTANT("HTTP_URL_JOIN_QUERY", HTTP_URL_JOIN_QUERY);
18891 + HTTP_LONG_CONSTANT("HTTP_URL_STRIP_USER", HTTP_URL_STRIP_USER);
18892 + HTTP_LONG_CONSTANT("HTTP_URL_STRIP_PASS", HTTP_URL_STRIP_PASS);
18893 + HTTP_LONG_CONSTANT("HTTP_URL_STRIP_AUTH", HTTP_URL_STRIP_AUTH);
18894 + HTTP_LONG_CONSTANT("HTTP_URL_STRIP_PORT", HTTP_URL_STRIP_PORT);
18895 + HTTP_LONG_CONSTANT("HTTP_URL_STRIP_PATH", HTTP_URL_STRIP_PATH);
18896 + HTTP_LONG_CONSTANT("HTTP_URL_STRIP_QUERY", HTTP_URL_STRIP_QUERY);
18897 + HTTP_LONG_CONSTANT("HTTP_URL_STRIP_FRAGMENT", HTTP_URL_STRIP_FRAGMENT);
18898 + HTTP_LONG_CONSTANT("HTTP_URL_STRIP_ALL", HTTP_URL_STRIP_ALL);
18899 + HTTP_LONG_CONSTANT("HTTP_URL_FROM_ENV", HTTP_URL_FROM_ENV);
18903 +PHP_HTTP_API char *_http_absolute_url_ex(const char *url, int flags TSRMLS_DC)
18905 + char *abs = NULL;
18906 + php_url *purl = NULL;
18909 + purl = php_url_parse(abs = estrdup(url));
18910 + STR_SET(abs, NULL);
18912 + http_error_ex(HE_WARNING, HTTP_E_URL, "Could not parse URL (%s)", url);
18917 + http_build_url(flags, purl, NULL, NULL, &abs, NULL);
18920 + php_url_free(purl);
18926 +/* {{{ void http_build_url(int flags, const php_url *, const php_url *, php_url **, char **, size_t *) */
18927 +PHP_HTTP_API void _http_build_url(int flags, const php_url *old_url, const php_url *new_url, php_url **url_ptr, char **url_str, size_t *url_len TSRMLS_DC)
18929 +#if defined(HAVE_GETSERVBYPORT) || defined(HAVE_GETSERVBYNAME)
18930 + struct servent *se;
18932 + php_url *url = ecalloc(1, sizeof(php_url));
18934 +#define __URLSET(u,n) \
18936 +#define __URLCPY(n) \
18937 + url->n = __URLSET(new_url,n) ? estrdup(new_url->n) : (__URLSET(old_url,n) ? estrdup(old_url->n) : NULL)
18939 + if (!(flags & HTTP_URL_STRIP_PORT)) {
18940 + url->port = __URLSET(new_url, port) ? new_url->port : ((old_url) ? old_url->port : 0);
18942 + if (!(flags & HTTP_URL_STRIP_USER)) {
18945 + if (!(flags & HTTP_URL_STRIP_PASS)) {
18949 + __URLCPY(scheme);
18952 + if (!(flags & HTTP_URL_STRIP_PATH)) {
18953 + if ((flags & HTTP_URL_JOIN_PATH) && __URLSET(old_url, path) && __URLSET(new_url, path) && *new_url->path != '/') {
18954 + size_t old_path_len = strlen(old_url->path), new_path_len = strlen(new_url->path);
18956 + url->path = ecalloc(1, old_path_len + new_path_len + 1 + 1);
18958 + strcat(url->path, old_url->path);
18959 + if (url->path[old_path_len - 1] != '/') {
18960 + php_dirname(url->path, old_path_len);
18961 + strcat(url->path, "/");
18963 + strcat(url->path, new_url->path);
18968 + if (!(flags & HTTP_URL_STRIP_QUERY)) {
18969 + if ((flags & HTTP_URL_JOIN_QUERY) && __URLSET(new_url, query) && __URLSET(old_url, query)) {
18972 + INIT_PZVAL(&qstr);
18973 + INIT_PZVAL(&qarr);
18974 + array_init(&qarr);
18976 + ZVAL_STRING(&qstr, old_url->query, 0);
18977 + http_querystring_modify(&qarr, &qstr);
18978 + ZVAL_STRING(&qstr, new_url->query, 0);
18979 + http_querystring_modify(&qarr, &qstr);
18981 + ZVAL_NULL(&qstr);
18982 + http_querystring_update(&qarr, &qstr);
18983 + url->query = Z_STRVAL(qstr);
18984 + zval_dtor(&qarr);
18989 + if (!(flags & HTTP_URL_STRIP_FRAGMENT)) {
18990 + __URLCPY(fragment);
18993 + if (!url->scheme) {
18994 + if (flags & HTTP_URL_FROM_ENV) {
18995 + zval *https = http_get_server_var("HTTPS", 1);
18996 + if (https && !strcasecmp(Z_STRVAL_P(https), "ON")) {
18997 + url->scheme = estrndup("https", lenof("https"));
18998 + } else switch (url->port) {
19000 + url->scheme = estrndup("https", lenof("https"));
19003 +#ifndef HAVE_GETSERVBYPORT
19008 + url->scheme = estrndup("http", lenof("http"));
19011 +#ifdef HAVE_GETSERVBYPORT
19013 + if ((se = getservbyport(htons(url->port), "tcp")) && se->s_name) {
19014 + url->scheme = estrdup(se->s_name);
19016 + url->scheme = estrndup("http", lenof("http"));
19022 + url->scheme = estrndup("http", lenof("http"));
19026 + if (!url->host) {
19027 + if (flags & HTTP_URL_FROM_ENV) {
19030 + if ((((zhost = http_get_server_var("HTTP_HOST", 1)) ||
19031 + (zhost = http_get_server_var("SERVER_NAME", 1)))) && Z_STRLEN_P(zhost)) {
19032 + url->host = estrndup(Z_STRVAL_P(zhost), Z_STRLEN_P(zhost));
19034 + url->host = localhostname();
19037 + url->host = estrndup("localhost", lenof("localhost"));
19041 + if (!url->path) {
19042 + if ((flags & HTTP_URL_FROM_ENV) && SG(request_info).request_uri && SG(request_info).request_uri[0]) {
19043 + const char *q = strchr(SG(request_info).request_uri, '?');
19046 + url->path = estrndup(SG(request_info).request_uri, q - SG(request_info).request_uri);
19048 + url->path = estrdup(SG(request_info).request_uri);
19051 + url->path = estrndup("/", 1);
19053 + } else if (url->path[0] != '/') {
19054 + if ((flags & HTTP_URL_FROM_ENV) && SG(request_info).request_uri && SG(request_info).request_uri[0]) {
19055 + size_t ulen = strlen(SG(request_info).request_uri);
19056 + size_t plen = strlen(url->path);
19059 + if (SG(request_info).request_uri[ulen-1] != '/') {
19060 + for (--ulen; ulen && SG(request_info).request_uri[ulen - 1] != '/'; --ulen);
19063 + path = emalloc(ulen + plen + 1);
19064 + memcpy(path, SG(request_info).request_uri, ulen);
19065 + memcpy(path + ulen, url->path, plen);
19066 + path[ulen + plen] = '\0';
19067 + STR_SET(url->path, path);
19069 + size_t plen = strlen(url->path);
19070 + char *path = emalloc(plen + 1 + 1);
19073 + memcpy(&path[1], url->path, plen + 1);
19074 + STR_SET(url->path, path);
19077 + /* replace directory references if path is not a single slash */
19078 + if (url->path[0] && (url->path[0] != '/' || url->path[1])) {
19079 + char *ptr, *end = url->path + strlen(url->path) + 1;
19081 + for (ptr = strstr(url->path, "/."); ptr; ptr = strstr(ptr, "/.")) {
19082 + switch (ptr[2]) {
19088 + memmove(&ptr[1], &ptr[3], end - &ptr[3]);
19092 + if (ptr[3] == '/') {
19093 + char *pos = &ptr[4];
19094 + while (ptr != url->path) {
19095 + if (*--ptr == '/') {
19099 + memmove(&ptr[1], pos, end - pos);
19101 + } else if (!ptr[3]) {
19102 + /* .. at the end */
19105 + /* fallthrough */
19108 + /* something else */
19116 + if ( ((url->port == 80) && !strcmp(url->scheme, "http"))
19117 + || ((url->port ==443) && !strcmp(url->scheme, "https"))
19118 +#ifdef HAVE_GETSERVBYNAME
19119 + || ((se = getservbyname(url->scheme, "tcp")) && se->s_port &&
19120 + (url->port == ntohs(se->s_port)))
19130 + *url_str = emalloc(HTTP_URL_MAXLEN + 1);
19132 + **url_str = '\0';
19133 + strlcat(*url_str, url->scheme, HTTP_URL_MAXLEN);
19134 + strlcat(*url_str, "://", HTTP_URL_MAXLEN);
19136 + if (url->user && *url->user) {
19137 + strlcat(*url_str, url->user, HTTP_URL_MAXLEN);
19138 + if (url->pass && *url->pass) {
19139 + strlcat(*url_str, ":", HTTP_URL_MAXLEN);
19140 + strlcat(*url_str, url->pass, HTTP_URL_MAXLEN);
19142 + strlcat(*url_str, "@", HTTP_URL_MAXLEN);
19145 + strlcat(*url_str, url->host, HTTP_URL_MAXLEN);
19148 + char port_str[8];
19150 + snprintf(port_str, sizeof(port_str), "%d", (int) url->port);
19151 + strlcat(*url_str, ":", HTTP_URL_MAXLEN);
19152 + strlcat(*url_str, port_str, HTTP_URL_MAXLEN);
19155 + strlcat(*url_str, url->path, HTTP_URL_MAXLEN);
19157 + if (url->query && *url->query) {
19158 + strlcat(*url_str, "?", HTTP_URL_MAXLEN);
19159 + strlcat(*url_str, url->query, HTTP_URL_MAXLEN);
19162 + if (url->fragment && *url->fragment) {
19163 + strlcat(*url_str, "#", HTTP_URL_MAXLEN);
19164 + strlcat(*url_str, url->fragment, HTTP_URL_MAXLEN);
19167 + if (HTTP_URL_MAXLEN == (len = strlen(*url_str))) {
19168 + http_error(HE_NOTICE, HTTP_E_URL, "Length of URL exceeds HTTP_URL_MAXLEN");
19178 + php_url_free(url);
19183 +/* {{{ STATUS http_urlencode_hash_ex(HashTable *, zend_bool, char *, size_t, char **, size_t *) */
19184 +PHP_HTTP_API STATUS _http_urlencode_hash_ex(HashTable *hash, zend_bool override_argsep,
19185 + char *pre_encoded_data, size_t pre_encoded_len,
19186 + char **encoded_data, size_t *encoded_len TSRMLS_DC)
19189 + size_t arg_sep_len;
19190 + phpstr *qstr = phpstr_new();
19192 + if (override_argsep || !(arg_sep_len = strlen(arg_sep = INI_STR("arg_separator.output")))) {
19193 + arg_sep = HTTP_URL_ARGSEP;
19194 + arg_sep_len = lenof(HTTP_URL_ARGSEP);
19197 + if (pre_encoded_len && pre_encoded_data) {
19198 + phpstr_append(qstr, pre_encoded_data, pre_encoded_len);
19201 + if (SUCCESS != http_urlencode_hash_recursive(hash, qstr, arg_sep, arg_sep_len, NULL, 0)) {
19202 + phpstr_free(&qstr);
19206 + phpstr_data(qstr, encoded_data, encoded_len);
19207 + phpstr_free(&qstr);
19213 +/* {{{ http_urlencode_hash_recursive */
19214 +PHP_HTTP_API STATUS _http_urlencode_hash_recursive(HashTable *ht, phpstr *str, const char *arg_sep, size_t arg_sep_len, const char *prefix, size_t prefix_len TSRMLS_DC)
19216 + HashKey key = initHashKey(0);
19217 + zval **data = NULL;
19218 + HashPosition pos;
19220 + if (!ht || !str) {
19221 + http_error(HE_WARNING, HTTP_E_INVALID_PARAM, "Invalid parameters");
19224 + if (ht->nApplyCount > 0) {
19228 + FOREACH_HASH_KEYVAL(pos, ht, key, data) {
19229 + char *encoded_key;
19231 + phpstr new_prefix;
19233 + if (!data || !*data) {
19234 + phpstr_dtor(str);
19238 + if (key.type == HASH_KEY_IS_STRING) {
19240 + /* only public properties */
19243 + if (key.len && key.str[key.len - 1] == '\0') {
19246 + encoded_key = php_url_encode(key.str, key.len, &encoded_len);
19248 + encoded_len = spprintf(&encoded_key, 0, "%ld", key.num);
19252 + phpstr_init(&new_prefix);
19253 + if (prefix && prefix_len) {
19254 + phpstr_append(&new_prefix, prefix, prefix_len);
19255 + phpstr_appends(&new_prefix, "%5B");
19258 + phpstr_append(&new_prefix, encoded_key, encoded_len);
19259 + efree(encoded_key);
19261 + if (prefix && prefix_len) {
19262 + phpstr_appends(&new_prefix, "%5D");
19264 + phpstr_fix(&new_prefix);
19267 + if (Z_TYPE_PP(data) == IS_ARRAY || Z_TYPE_PP(data) == IS_OBJECT) {
19269 + ++ht->nApplyCount;
19270 + status = http_urlencode_hash_recursive(HASH_OF(*data), str, arg_sep, arg_sep_len, PHPSTR_VAL(&new_prefix), PHPSTR_LEN(&new_prefix));
19271 + --ht->nApplyCount;
19272 + if (SUCCESS != status) {
19273 + phpstr_dtor(&new_prefix);
19274 + phpstr_dtor(str);
19278 + zval *val = http_zsep(IS_STRING, *data);
19280 + if (PHPSTR_LEN(str)) {
19281 + phpstr_append(str, arg_sep, arg_sep_len);
19283 + phpstr_append(str, PHPSTR_VAL(&new_prefix), PHPSTR_LEN(&new_prefix));
19284 + phpstr_appends(str, "=");
19286 + if (Z_STRLEN_P(val) && Z_STRVAL_P(val)) {
19287 + char *encoded_val;
19290 + encoded_val = php_url_encode(Z_STRVAL_P(val), Z_STRLEN_P(val), &encoded_len);
19291 + phpstr_append(str, encoded_val, encoded_len);
19292 + efree(encoded_val);
19295 + zval_ptr_dtor(&val);
19297 + phpstr_dtor(&new_prefix);
19304 + * Local variables:
19306 + * c-basic-offset: 4
19308 + * vim600: noet sw=4 ts=4 fdm=marker
19309 + * vim<600: noet sw=4 ts=4
19313 +++ b/ext/http/http_util_object.c
19316 + +--------------------------------------------------------------------+
19318 + +--------------------------------------------------------------------+
19319 + | Redistribution and use in source and binary forms, with or without |
19320 + | modification, are permitted provided that the conditions mentioned |
19321 + | in the accompanying LICENSE file are met. |
19322 + +--------------------------------------------------------------------+
19323 + | Copyright (c) 2004-2010, Michael Wallner <mike@php.net> |
19324 + +--------------------------------------------------------------------+
19327 +/* $Id: http_util_object.c 292841 2009-12-31 08:48:57Z mike $ */
19329 +#include "php_http.h"
19331 +#ifdef ZEND_ENGINE_2
19333 +#include "ext/standard/php_http.h"
19335 +#include "php_http_util_object.h"
19337 +#define HTTP_BEGIN_ARGS(method, req_args) HTTP_BEGIN_ARGS_EX(HttpUtil, method, 0, req_args)
19338 +#define HTTP_EMPTY_ARGS(method) HTTP_EMPTY_ARGS_EX(HttpUtil, method, 0)
19340 +#define HTTP_UTIL_ALIAS(method, func) HTTP_STATIC_ME_ALIAS(method, func, HTTP_ARGS(HttpUtil, method))
19342 +HTTP_BEGIN_ARGS(date, 0)
19343 + HTTP_ARG_VAL(timestamp, 0)
19346 +HTTP_BEGIN_ARGS(buildStr, 1)
19347 + HTTP_ARG_VAL(query, 0)
19348 + HTTP_ARG_VAL(prefix, 0)
19349 + HTTP_ARG_VAL(arg_sep, 0)
19352 +HTTP_BEGIN_ARGS(buildUrl, 1)
19353 + HTTP_ARG_VAL(url, 0)
19354 + HTTP_ARG_VAL(parts, 0)
19355 + HTTP_ARG_VAL(flags, 0)
19356 + HTTP_ARG_VAL(composed, 1)
19359 +HTTP_BEGIN_ARGS(negotiateLanguage, 1)
19360 + HTTP_ARG_VAL(supported, 0)
19361 + HTTP_ARG_VAL(result, 1)
19364 +HTTP_BEGIN_ARGS(negotiateCharset, 1)
19365 + HTTP_ARG_VAL(supported, 0)
19366 + HTTP_ARG_VAL(result, 1)
19369 +HTTP_BEGIN_ARGS(negotiateContentType, 1)
19370 + HTTP_ARG_VAL(supported, 0)
19371 + HTTP_ARG_VAL(result, 1)
19374 +HTTP_BEGIN_ARGS(matchModified, 1)
19375 + HTTP_ARG_VAL(last_modified, 0)
19376 + HTTP_ARG_VAL(for_range, 0)
19379 +HTTP_BEGIN_ARGS(matchEtag, 1)
19380 + HTTP_ARG_VAL(plain_etag, 0)
19381 + HTTP_ARG_VAL(for_range, 0)
19384 +HTTP_BEGIN_ARGS(matchRequestHeader, 2)
19385 + HTTP_ARG_VAL(header_name, 0)
19386 + HTTP_ARG_VAL(header_value, 0)
19387 + HTTP_ARG_VAL(case_sensitive, 0)
19390 +HTTP_BEGIN_ARGS(parseMessage, 1)
19391 + HTTP_ARG_VAL(message_string, 0)
19394 +HTTP_BEGIN_ARGS(parseHeaders, 1)
19395 + HTTP_ARG_VAL(headers_string, 0)
19398 +HTTP_BEGIN_ARGS(parseCookie, 1)
19399 + HTTP_ARG_VAL(cookie_string, 0)
19402 +HTTP_BEGIN_ARGS(buildCookie, 1)
19403 + HTTP_ARG_VAL(cookie_array, 0)
19406 +HTTP_BEGIN_ARGS(parseParams, 1)
19407 + HTTP_ARG_VAL(param_string, 0)
19408 + HTTP_ARG_VAL(flags, 0)
19411 +HTTP_BEGIN_ARGS(chunkedDecode, 1)
19412 + HTTP_ARG_VAL(encoded_string, 0)
19415 +#ifdef HTTP_HAVE_ZLIB
19416 +HTTP_BEGIN_ARGS(deflate, 1)
19417 + HTTP_ARG_VAL(plain, 0)
19418 + HTTP_ARG_VAL(flags, 0)
19421 +HTTP_BEGIN_ARGS(inflate, 1)
19422 + HTTP_ARG_VAL(encoded, 0)
19426 +HTTP_BEGIN_ARGS(support, 0)
19427 + HTTP_ARG_VAL(feature, 0)
19430 +zend_class_entry *http_util_object_ce;
19431 +zend_function_entry http_util_object_fe[] = {
19432 + HTTP_UTIL_ALIAS(date, http_date)
19433 + HTTP_UTIL_ALIAS(buildUrl, http_build_url)
19434 + HTTP_UTIL_ALIAS(buildStr, http_build_str)
19435 + HTTP_UTIL_ALIAS(negotiateLanguage, http_negotiate_language)
19436 + HTTP_UTIL_ALIAS(negotiateCharset, http_negotiate_charset)
19437 + HTTP_UTIL_ALIAS(negotiateContentType, http_negotiate_content_type)
19438 + HTTP_UTIL_ALIAS(matchModified, http_match_modified)
19439 + HTTP_UTIL_ALIAS(matchEtag, http_match_etag)
19440 + HTTP_UTIL_ALIAS(matchRequestHeader, http_match_request_header)
19441 + HTTP_UTIL_ALIAS(parseMessage, http_parse_message)
19442 + HTTP_UTIL_ALIAS(parseHeaders, http_parse_headers)
19443 + HTTP_UTIL_ALIAS(parseCookie, http_parse_cookie)
19444 + HTTP_UTIL_ALIAS(buildCookie, http_build_cookie)
19445 + HTTP_UTIL_ALIAS(parseParams, http_parse_params)
19446 + HTTP_UTIL_ALIAS(chunkedDecode, http_chunked_decode)
19447 +#ifdef HTTP_HAVE_ZLIB
19448 + HTTP_UTIL_ALIAS(deflate, http_deflate)
19449 + HTTP_UTIL_ALIAS(inflate, http_inflate)
19450 +#endif /* HTTP_HAVE_ZLIB */
19451 + HTTP_UTIL_ALIAS(support, http_support)
19453 + EMPTY_FUNCTION_ENTRY
19456 +PHP_MINIT_FUNCTION(http_util_object)
19458 + HTTP_REGISTER_CLASS(HttpUtil, http_util_object, NULL, 0);
19462 +#endif /* ZEND_ENGINE_2 */
19465 + * Local variables:
19467 + * c-basic-offset: 4
19469 + * vim600: noet sw=4 ts=4 fdm=marker
19470 + * vim<600: noet sw=4 ts=4
19474 +++ b/ext/http/lib/BigGet.php
19479 + * BigGet - download big files efficiently
19480 + * $Id: BigGet.php 220502 2006-09-25 08:27:32Z mike $
19482 + * @copyright Michael Wallner, <mike@iworks.at>
19483 + * @license BSD, revised
19484 + * @version $Revision: 220502 $
19486 +class BigGet extends HttpRequestPool
19489 + * File split size
19491 + const SIZE = 1048576;
19494 + * Parallel Request count
19499 + * Whether to output debug messages
19503 + public $dbg = false;
19513 + * Temp file prefix
19520 + * Size of requested resource
19527 + * Whether the requests have been sent
19531 + private $sent = false;
19534 + * Request counter
19538 + private $count = 0;
19541 + * Static constructor
19543 + * @param string $url
19544 + * @param string $tmp
19546 + * @throws Exception
19548 + public static function url($url, $tmp = '/tmp')
19550 + $head = new HttpRequest($url, HttpRequest::METH_HEAD);
19551 + $headers = $head->send()->getHeaders();
19553 + if (200 != $head->getResponseCode()) {
19554 + throw new HttpException("Did not receive '200 Ok' from HEAD $url");
19556 + if (!isset($headers['Accept-Ranges'])) {
19557 + throw new HttpException("Did not receive an Accept-Ranges header from HEAD $url");
19559 + if (!isset($headers['Content-Length'])) {
19560 + throw new HttpException("Did not receive a Content-Length header from HEAD $url");
19563 + $bigget = new BigGet;
19564 + $bigget->url = $url;
19565 + $bigget->tmp = tempnam($tmp, 'BigGet.');
19566 + $bigget->size = $headers['Content-Length'];
19571 + * Save the resource to a file
19573 + * @param string $file
19575 + * @throws Exception
19577 + public function saveTo($file)
19579 + $this->sent or $this->send();
19581 + if ($w = fopen($this->tmp, 'wb')) {
19583 + $this->dbg && print "\nCopying temp files to $file ...\n";
19585 + foreach (glob($this->tmp .".????") as $tmp) {
19587 + $this->dbg && print "\t$tmp\n";
19589 + if ($r = fopen($tmp, 'rb')) {
19590 + stream_copy_to_stream($r, $w);
19596 + rename($this->tmp, $file);
19598 + $this->dbg && print "\nDone.\n";
19606 + * Overrides HttpRequestPool::send()
19609 + * @throws Exception
19611 + public function send()
19613 + $this->sent = true;
19615 + // use max RMAX simultanous requests with a req size of SIZE
19616 + while ($this->count < self::RMAX && -1 != $offset = $this->getRangeOffset()) {
19617 + $this->attachNew($offset);
19620 + while ($this->socketPerform()) {
19621 + if (!$this->socketSelect()) {
19622 + throw new HttpSocketException;
19628 + * Overrides HttpRequestPool::socketPerform()
19632 + protected function socketPerform()
19634 + $rs = parent::socketPerform();
19636 + foreach ($this->getFinishedRequests() as $r) {
19637 + $this->detach($r);
19639 + if (206 != $rc = $r->getResponseCode()) {
19640 + throw new HttpException("Unexpected response code: $rc");
19643 + file_put_contents(sprintf("%s.%04d", $this->tmp, $r->id), $r->getResponseBody());
19645 + if (-1 != $offset = $this->getRangeOffset()) {
19646 + $this->attachNew($offset);
19653 + private function attachNew($offset)
19655 + $stop = min($this->count * self::SIZE + self::SIZE, $this->size) - 1;
19657 + $this->dbg && print "Attaching new request to get range: $offset-$stop\n";
19659 + $req = new BigGetRequest(
19661 + HttpRequest::METH_GET,
19663 + 'headers' => array(
19664 + 'Range' => "bytes=$offset-$stop"
19668 + $this->attach($req);
19669 + $req->id = $this->count++;
19672 + private function getRangeOffset()
19674 + return ($this->size >= $start = $this->count * self::SIZE) ? $start : -1;
19683 +class BigGetRequest extends HttpRequest
19690 +++ b/ext/http/lib/FeedAggregator.php
19695 + * Simple Feed Aggregator
19696 + * $Id: FeedAggregator.php 208774 2006-03-06 16:07:19Z mike $
19698 + * @copyright Michael Wallner, <mike@iworks.at>
19699 + * @license BSD, revised
19700 + * @package pecl/http
19701 + * @version $Revision: 208774 $
19703 +class FeedAggregator
19706 + * Cache directory
19710 + public $directory;
19717 + protected $feeds = array();
19722 + * @param string $directory
19724 + public function __construct($directory = 'feeds')
19726 + $this->setDirectory($directory);
19730 + * Set cache directory
19732 + * @param string $directory
19734 + public function setDirectory($directory)
19736 + $this->directory = $directory;
19737 + foreach (glob($this->directory .'/*.xml') as $feed) {
19738 + $this->feeds[basename($feed, '.xml')] = filemtime($feed);
19743 + * Strips all special chars
19745 + * @param string $url
19748 + public function url2name($url)
19750 + return preg_replace('/[^\w\.-]+/', '_', $url);
19754 + * Checks if $url is a known feed
19756 + * @param string $url
19759 + public function hasFeed($url)
19761 + return isset($this->feeds[$this->url2name($url)]);
19765 + * Add an URL as feed
19767 + * @param string $url
19769 + * @throws Exception
19771 + public function addFeed($url)
19773 + $r = $this->setupRequest($url);
19775 + $this->handleResponse($r);
19779 + * Add several URLs as feeds
19781 + * @param array $urls
19783 + * @throws Exception
19785 + public function addFeeds(array $urls)
19787 + $pool = new HttpRequestPool;
19788 + foreach ($urls as $url) {
19789 + $pool->attach($r = $this->setupRequest($url));
19793 + foreach ($pool as $request) {
19794 + $this->handleResponse($request);
19799 + * Load a feed (from cache)
19801 + * @param string $url
19803 + * @throws Exception
19805 + public function getFeed($url)
19807 + $this->addFeed($url);
19808 + return $this->loadFeed($this->url2name($url));
19812 + * Load several feeds (from cache)
19814 + * @param array $urls
19816 + * @throws Exception
19818 + public function getFeeds(array $urls)
19820 + $feeds = array();
19821 + $this->addFeeds($urls);
19822 + foreach ($urls as $url) {
19823 + $feeds[] = $this->loadFeed($this->url2name($url));
19828 + protected function saveFeed($file, $contents)
19830 + if (file_put_contents($this->directory .'/'. $file .'.xml', $contents)) {
19831 + $this->feeds[$file] = time();
19833 + throw new Exception("Could not save feed contents to $file.xml");
19837 + protected function loadFeed($file)
19839 + if (isset($this->feeds[$file])) {
19840 + if ($data = file_get_contents($this->directory .'/'. $file .'.xml')) {
19843 + throw new Exception("Could not load feed contents from $file.xml");
19846 + throw new Exception("Unknown feed/file $file.xml");
19850 + protected function setupRequest($url, $escape = true)
19852 + $r = new HttpRequest($url);
19853 + $r->setOptions(array('redirect' => true));
19855 + $file = $escape ? $this->url2name($url) : $url;
19857 + if (isset($this->feeds[$file])) {
19858 + $r->setOptions(array('lastmodified' => $this->feeds[$file]));
19864 + protected function handleResponse(HttpRequest $r)
19866 + if ($r->getResponseCode() != 304) {
19867 + if ($r->getResponseCode() != 200) {
19868 + throw new Exception("Unexpected response code ". $r->getResponseCode());
19870 + if (!strlen($body = $r->getResponseBody())) {
19871 + throw new Exception("Received empty feed from ". $r->getUrl());
19873 + $this->saveFeed($this->url2name($r->getUrl()), $body);
19880 +++ b/ext/http/lib/PgLobStream.php
19885 + * PostgreSQL LOB stream
19886 + * $Id: PgLobStream.php 210232 2006-03-27 17:41:25Z mike $
19890 + * // GET /image.php?image=1234
19891 + * if (PgLobStream::$loId = (int) $_GET['image']) {
19892 + * if ($lob = fopen('pglob://dbname=database user=mike', 'r')) {
19893 + * HttpResponse::setContentType('image/jpeg');
19894 + * HttpResponse::setStream($lob);
19895 + * HttpResponse::send();
19900 + * @copyright Michael Wallner, <mike@iworks.at>
19901 + * @license BSD, revised
19902 + * @package pecl/http
19903 + * @version $Revision: 210232 $
19910 + private $size = 0;
19912 + public static $loId;
19914 + function stream_open($path, $mode)
19916 + $path = trim(parse_url($path, PHP_URL_HOST));
19919 + if ($this->dbh = pg_connect($path)) {
19920 + if (pg_query($this->dbh, 'BEGIN')) {
19921 + if (is_resource($this->loh = pg_lo_open($this->dbh, $this->lon = self::$loId, $mode))) {
19922 + pg_lo_seek($this->loh, 0, PGSQL_SEEK_END);
19923 + $this->size = (int) pg_lo_tell($this->loh);
19924 + pg_lo_seek($this->loh, 0, PGSQL_SEEK_SET);
19933 + function stream_read($length)
19935 + return pg_lo_read($this->loh, $length);
19938 + function stream_seek($offset, $whence = PGSQL_SEEK_SET)
19940 + return pg_lo_seek($this->loh, $offset, $whence);
19943 + function stream_tell()
19945 + return pg_lo_tell($this->loh);
19948 + function stream_eof()
19950 + return pg_lo_tell($this->loh) >= $this->size;
19953 + function stream_flush()
19958 + function stream_stat()
19960 + return array('size' => $this->size, 'ino' => $this->lon);
19963 + function stream_write($data)
19965 + return pg_lo_write($this->loh, $data);
19968 + function stream_close()
19970 + if (pg_lo_close($this->loh)) {
19971 + return pg_query($this->dbh, 'COMMIT');
19973 + pg_query($this->dbh, 'ROLLBACK');
19979 +stream_register_wrapper('pglob', 'PgLobStream');
19983 +++ b/ext/http/lib/XmlRpcClient.php
19988 + * XMLRPC Client, very KISS
19989 + * $Id: XmlRpcClient.php 227268 2007-01-15 08:01:35Z mike $
19991 + * NOTE: requires ext/xmlrpc
19996 + * $rpc = new XmlRpcClient('http://mike:secret@example.com/cgi-bin/vpop-xmlrpc');
19997 + * $rpc->__request->setOptions(array('compress' => true));
19999 + * print_r($rpc->vpop->listdomain(array('domain' => 'example.com')));
20000 + * } catch (Exception $ex) {
20006 + * @copyright Michael Wallner, <mike@iworks.at>
20007 + * @license BSD, revised
20008 + * @package pecl/http
20009 + * @version $Revision: 227268 $
20011 +class XmlRpcClient
20018 + public $__namespace;
20021 + * HttpRequest instance
20023 + * @var HttpRequest
20025 + public $__request;
20032 + public $__encoding = "iso-8859-1";
20039 + public $__options;
20044 + * @param string $url RPC endpoint
20045 + * @param string $namespace RPC namespace
20046 + * @param array $options HttpRequest options
20048 + public function __construct($url, $namespace = '', array $options = null)
20050 + $this->__request = new HttpRequest($url, HttpRequest::METH_POST, (array) $options);
20051 + $this->__namespace = $namespace;
20055 + * RPC method proxy
20057 + * @param string $method RPC method name
20058 + * @param array $params RPC method arguments
20059 + * @return mixed decoded RPC response
20060 + * @throws Exception
20062 + public function __call($method, array $params)
20064 + if (strlen($this->__namespace)) {
20065 + $method = $this->__namespace .'.'. $method;
20067 + $this->__request->setContentType("text/xml");
20068 + $this->__request->setRawPostData(
20069 + xmlrpc_encode_request($method, $params,
20070 + array("encoding" => $this->__encoding) + (array) $this->__options));
20071 + $response = $this->__request->send();
20072 + if ($response->getResponseCode() != 200) {
20073 + throw new Exception(
20074 + $response->getResponseStatus(),
20075 + $response->getResponseCode()
20079 + $data = xmlrpc_decode($response->getBody(), $this->__encoding);
20080 + if (xmlrpc_is_fault($data)) {
20081 + throw new Exception(
20082 + (string) $data['faultString'],
20083 + (int) $data['faultCode']
20091 + * Returns self, where namespace is set to variable name
20093 + * @param string $ns
20094 + * @return XmlRpcRequest
20096 + public function __get($ns)
20098 + $this->__namespace = $ns;
20105 +++ b/ext/http/lib/XmlRpcServer.php
20109 +XmlRpcServer::setContentType("text/xml");
20110 +XmlRpcServer::capture();
20113 + * XMLRPC Server, very KISS
20114 + * $Id: XmlRpcServer.php 227268 2007-01-15 08:01:35Z mike $
20116 + * NOTE: requires ext/xmlrpc
20121 + * class Handler extends XmlRpcRequestHandlerStub {
20122 + * public function xmlrpcPing(array $values) {
20127 + * XmlRpcServer::factory("namespace")->registerHandler(new Handler);
20128 + * XmlRpcServer::run();
20129 + * } catch (Exception $ex) {
20130 + * XmlRpcServer::error($ex->getCode(), $ex->getMessage());
20134 + * @copyright Michael Wallner, <mike@iworks.at>
20135 + * @license BSD, revised
20136 + * @package pecl/http
20137 + * @version $Revision: 227268 $
20140 +class XmlRpcServer extends HttpResponse
20147 + public static $encoding = "iso-8859-1";
20154 + public $namespace;
20157 + * RPC handler attached to this server instance
20159 + * @var XmlRpcRequestHandler
20161 + protected $handler;
20163 + private static $xmlreq;
20164 + private static $xmlrpc;
20165 + private static $refcnt = 0;
20166 + private static $handle = array();
20169 + * Create a new XmlRpcServer instance
20171 + * @param string $namespace
20172 + * @param string $encoding
20174 + public function __construct($namespace)
20176 + $this->namespace = $namespace;
20177 + self::initialize();
20183 + public function __destruct()
20185 + if (self::$refcnt && !--self::$refcnt) {
20186 + xmlrpc_server_destroy(self::$xmlrpc);
20193 + * @param string $namespace
20194 + * @return XmlRpcServer
20196 + public static function factory($namespace)
20198 + return new XmlRpcServer($namespace);
20202 + * Run all servers and send response
20204 + * @param array $options
20206 + public static function run(array $options = null)
20208 + self::initialize(false, true);
20209 + self::setContentType("text/xml; charset=". self::$encoding);
20210 + echo xmlrpc_server_call_method(self::$xmlrpc, self::$xmlreq, null,
20211 + array("encoding" => self::$encoding) + (array) $options);
20215 + * Test hook; call instead of XmlRpcServer::run()
20217 + * @param string $method
20218 + * @param array $params
20219 + * @param array $request_options
20220 + * @param array $response_options
20222 + public static function test($method, array $params, array $request_options = null, array $response_options = null)
20224 + self::$xmlreq = xmlrpc_encode_request($method, $params, $request_options);
20225 + self::run($response_options);
20229 + * Optional XMLRPC error handler
20231 + * @param int $code
20232 + * @param string $msg
20234 + public static function error($code, $msg, array $options = null)
20236 + echo xmlrpc_encode(array("faultCode" => $code, "faultString" => $msg),
20237 + array("encoding" => self::$encoding) + (array) $options);
20241 + * Register a single method
20243 + * @param string $name
20244 + * @param mixed $callback
20245 + * @param mixed $dispatch
20246 + * @param array $spec
20248 + public function registerMethod($name, $callback, $dispatch = null, array $spec = null)
20250 + if (!is_callable($callback, false, $cb_name)) {
20251 + throw new Exception("$cb_name is not a valid callback");
20253 + if (isset($dispatch)) {
20254 + if (!is_callable($dispatch, false, $cb_name)) {
20255 + throw new Exception("$cb_name is not a valid callback");
20257 + xmlrpc_server_register_method(self::$xmlrpc, $name, $dispatch);
20258 + self::$handle[$name] = $callback;
20260 + xmlrpc_server_register_method(self::$xmlrpc, $name, $callback);
20263 + if (isset($spec)) {
20264 + xmlrpc_server_add_introspection_data(self::$xmlrpc, $spec);
20269 + * Register an XmlRpcRequestHandler for this server instance
20271 + * @param XmlRpcRequestHandler $handler
20273 + public function registerHandler(XmlRpcRequestHandler $handler)
20275 + $this->handler = $handler;
20277 + foreach (get_class_methods($handler) as $method) {
20278 + if (!strncmp($method, "xmlrpc", 6)) {
20279 + $this->registerMethod(
20280 + $this->method($method, $handler->getNamespace()),
20281 + array($handler, $method), array($this, "dispatch"));
20285 + $handler->getIntrospectionData($spec);
20286 + if (is_array($spec)) {
20287 + xmlrpc_server_add_introspection_data(self::$xmlrpc, $spec);
20291 + private function method($method, $namespace = null)
20293 + if (!strlen($namespace)) {
20294 + $namespace = strlen($this->namespace) ? $this->namespace : "xmlrpc";
20296 + return $namespace .".". strtolower($method[6]) . substr($method, 7);
20299 + private function dispatch($method, array $params = null)
20301 + if (array_key_exists($method, self::$handle)) {
20302 + return call_user_func(self::$handle[$method], $params);
20304 + throw new Exception("Unknown XMLRPC method: $method");
20307 + private static function initialize($server = true, $data = false)
20310 + if (!self::$xmlreq && !(self::$xmlreq = http_get_request_body())) {
20311 + throw new Exception("Failed to fetch XMLRPC request body");
20315 + if (!self::$xmlrpc && !(self::$xmlrpc = xmlrpc_server_create())) {
20316 + throw new Exception("Failed to initialize XMLRPC server");
20324 + * XmlRpcRequestHandler
20326 + * Define XMLRPC methods with an "xmlrpc" prefix, eg:
20328 + * class IntOp implements XmlRpcRequestHandler {
20329 + * public function getNamespace() {
20332 + * public function getInstrospectionData(array &$spec = null) {
20334 + * // XMLRPC method name: int.sumValues
20335 + * public function xmlrpcSumValues(array $values) {
20336 + * return array_sum($values);
20341 +interface XmlRpcRequestHandler
20343 + public function getNamespace();
20344 + public function getIntrospectionData(array &$spec = null);
20348 + * XmlRpcRequestHandlerStub
20350 +abstract class XmlRpcRequestHandlerStub implements XmlRpcRequestHandler
20352 + public function getNamespace()
20355 + public function getIntrospectionData(array &$spec = null)
20362 +++ b/ext/http/missing.c
20365 + +--------------------------------------------------------------------+
20367 + +--------------------------------------------------------------------+
20368 + | Redistribution and use in source and binary forms, with or without |
20369 + | modification, are permitted provided that the conditions mentioned |
20370 + | in the accompanying LICENSE file are met. |
20371 + +--------------------------------------------------------------------+
20372 + | Copyright (c) 2004-2010, Michael Wallner <mike@php.net> |
20373 + +--------------------------------------------------------------------+
20376 +/* $Id: missing.c 292841 2009-12-31 08:48:57Z mike $ */
20378 +#ifdef HAVE_CONFIG_H
20379 +# include "config.h"
20383 +#include "missing.h"
20386 +int zend_declare_property_double(zend_class_entry *ce, char *name, int name_length, double value, int access_type TSRMLS_DC)
20388 + zval *property = pemalloc(sizeof(zval), ce->type & ZEND_INTERNAL_CLASS);
20389 + INIT_PZVAL(property);
20390 + ZVAL_DOUBLE(property, value);
20391 + return zend_declare_property(ce, name, name_length, property, access_type TSRMLS_CC);
20394 +void zend_update_property_double(zend_class_entry *scope, zval *object, char *name, int name_length, double value TSRMLS_DC)
20396 + zval *tmp = ecalloc(1, sizeof(zval));
20397 + ZVAL_DOUBLE(tmp, value);
20398 + zend_update_property(scope, object, name, name_length, tmp TSRMLS_CC);
20401 +int zend_declare_property_bool(zend_class_entry *ce, char *name, int name_length, long value, int access_type TSRMLS_DC)
20403 + zval *property = pemalloc(sizeof(zval), ce->type & ZEND_INTERNAL_CLASS);
20404 + INIT_PZVAL(property);
20405 + ZVAL_BOOL(property, value);
20406 + return zend_declare_property(ce, name, name_length, property, access_type TSRMLS_CC);
20409 +void zend_update_property_bool(zend_class_entry *scope, zval *object, char *name, int name_length, long value TSRMLS_DC)
20411 + zval *tmp = ecalloc(1, sizeof(zval));
20412 + ZVAL_BOOL(tmp, value);
20413 + zend_update_property(scope, object, name, name_length, tmp TSRMLS_CC);
20416 +void zend_update_property_stringl(zend_class_entry *scope, zval *object, char *name, int name_length, char *value, int value_len TSRMLS_DC)
20422 + tmp->refcount = 0;
20423 + ZVAL_STRINGL(tmp, value, value_len, 1);
20424 + zend_update_property(scope, object, name, name_length, tmp TSRMLS_CC);
20430 + * Local variables:
20432 + * c-basic-offset: 4
20434 + * vim600: noet sw=4 ts=4 fdm=marker
20435 + * vim<600: noet sw=4 ts=4
20439 +++ b/ext/http/missing.h
20442 + +--------------------------------------------------------------------+
20444 + +--------------------------------------------------------------------+
20445 + | Redistribution and use in source and binary forms, with or without |
20446 + | modification, are permitted provided that the conditions mentioned |
20447 + | in the accompanying LICENSE file are met. |
20448 + +--------------------------------------------------------------------+
20449 + | Copyright (c) 2004-2010, Michael Wallner <mike@php.net> |
20450 + +--------------------------------------------------------------------+
20453 +/* $Id: missing.h 323304 2012-02-17 21:13:24Z mike $ */
20455 +#ifndef PHP_HTTP_MISSING
20456 +#define PHP_HTTP_MISSING
20458 +#include "php_version.h"
20460 +#if ZEND_MODULE_API_NO >= 20100409
20461 +#define ZEND_ENGINE_2_4
20464 +#if defined(PHP_VERSION_ID) && (PHP_VERSION_ID >= 50399)
20465 +# define ZEND_LITERAL_KEY_DC , const zend_literal *_zend_literal_key
20466 +# define ZEND_LITERAL_KEY_CC , _zend_literal_key
20467 +# define ZEND_LITERAL_NIL_CC , NULL
20468 +# define HTTP_CHECK_OPEN_BASEDIR(file, act) \
20469 + if ((PG(open_basedir) && *PG(open_basedir))) \
20471 + const char *tmp = file; \
20473 + if (!strncasecmp(tmp, "file:", lenof("file:"))) { \
20474 + tmp += lenof("file:"); \
20475 + while ((tmp - (const char *)file < 7) && (*tmp == '/' || *tmp == '\\')) ++tmp; \
20478 + if ( (tmp != file || !strstr(file, "://")) && \
20479 + (!*tmp || php_check_open_basedir(tmp TSRMLS_CC))) { \
20485 +# define ZEND_LITERAL_KEY_DC
20486 +# define ZEND_LITERAL_KEY_CC
20487 +# define ZEND_LITERAL_NIL_CC
20488 +# define HTTP_CHECK_OPEN_BASEDIR(file, act) \
20489 + if ((PG(open_basedir) && *PG(open_basedir)) || PG(safe_mode)) \
20491 + const char *tmp = file; \
20493 + if (!strncasecmp(tmp, "file:", lenof("file:"))) { \
20494 + tmp += lenof("file:"); \
20495 + while ((tmp - (const char *)file < 7) && (*tmp == '/' || *tmp == '\\')) ++tmp; \
20498 + if ( (tmp != file || !strstr(file, "://")) && \
20499 + (!*tmp || php_check_open_basedir(tmp TSRMLS_CC) || \
20500 + (PG(safe_mode) && !php_checkuid(tmp, "rb+", CHECKUID_CHECK_MODE_PARAM)))) { \
20507 +#if (PHP_MAJOR_VERSION == 5) && (PHP_MINOR_VERSION >= 3)
20508 +# define HTTP_ZAPI_HASH_TSRMLS_CC TSRMLS_CC
20509 +# define HTTP_ZAPI_HASH_TSRMLS_DC TSRMLS_DC
20510 +# define HTTP_ZAPI_CONST_CAST(t) (const t)
20511 +# define GLOBAL_ERROR_HANDLING EG(error_handling)
20512 +# define GLOBAL_EXCEPTION_CLASS EG(exception_class)
20513 +# define HTTP_IS_CALLABLE(cb_zv, flags, cb_sp) zend_is_callable((cb_zv), (flags), (cb_sp) TSRMLS_CC)
20514 +# define HTTP_STATIC_ARG_INFO
20516 +# define HTTP_ZAPI_HASH_TSRMLS_CC
20517 +# define HTTP_ZAPI_HASH_TSRMLS_DC
20518 +# define HTTP_ZAPI_CONST_CAST(t) (t)
20519 +# define GLOBAL_ERROR_HANDLING PG(error_handling)
20520 +# define GLOBAL_EXCEPTION_CLASS PG(exception_class)
20521 +# define HTTP_IS_CALLABLE(cb_zv, flags, cb_sp) zend_is_callable((cb_zv), (flags), (cb_sp))
20522 +# define HTTP_STATIC_ARG_INFO static
20525 +#if (PHP_MAJOR_VERSION == 5) && (PHP_MINOR_VERSION == 0)
20529 +#ifndef pemalloc_rel
20530 +# define pemalloc_rel(size, persistent) ((persistent)?malloc(size):emalloc_rel(size))
20533 +#ifndef ZEND_ACC_DEPRECATED
20534 +# define ZEND_ACC_DEPRECATED 0
20537 +#if PHP_MAJOR_VERSION == 4 && PHP_MINOR_VERSION == 3 && PHP_RELEASE_VERSION < 10
20538 +# define php_url_parse_ex(u, l) php_url_parse(u)
20541 +#ifndef TSRMLS_FETCH_FROM_CTX
20543 +# define TSRMLS_FETCH_FROM_CTX(ctx) void ***tsrm_ls = (void ***) ctx
20545 +# define TSRMLS_FETCH_FROM_CTX(ctx)
20549 +#ifndef TSRMLS_SET_CTX
20551 +# define TSRMLS_SET_CTX(ctx) ctx = (void ***) tsrm_ls
20553 +# define TSRMLS_SET_CTX(ctx)
20557 +#ifndef ZVAL_ADDREF
20558 +# define ZVAL_ADDREF Z_ADDREF_P
20561 +#ifndef SEPARATE_ARG_IF_REF
20562 +#define SEPARATE_ARG_IF_REF(zv) \
20563 + if (PZVAL_IS_REF(zv)) { \
20565 + ALLOC_INIT_ZVAL(zv); \
20566 + Z_TYPE_P(zv) = Z_TYPE_P(ov); \
20567 + zv->value = ov->value; \
20568 + zval_copy_ctor(zv); \
20570 + ZVAL_ADDREF(zv); \
20575 +#define ZVAL_ZVAL(z, zv, copy, dtor) { \
20576 + int is_ref, refcount; \
20577 + is_ref = (z)->is_ref; \
20578 + refcount = (z)->refcount; \
20581 + zval_copy_ctor(z); \
20587 + zval_ptr_dtor(&zv); \
20589 + (z)->is_ref = is_ref; \
20590 + (z)->refcount = refcount; \
20593 +#ifndef RETVAL_ZVAL
20594 +# define RETVAL_ZVAL(zv, copy, dtor) ZVAL_ZVAL(return_value, zv, copy, dtor)
20596 +#ifndef RETURN_ZVAL
20597 +# define RETURN_ZVAL(zv, copy, dtor) { RETVAL_ZVAL(zv, copy, dtor); return; }
20601 +# define ZEND_MN(name) ZEND_FN(name)
20605 +extern int zend_declare_property_double(zend_class_entry *ce, char *name, int name_length, double value, int access_type TSRMLS_DC);
20606 +extern void zend_update_property_double(zend_class_entry *scope, zval *object, char *name, int name_length, double value TSRMLS_DC);
20608 +extern int zend_declare_property_bool(zend_class_entry *ce, char *name, int name_length, long value, int access_type TSRMLS_DC);
20609 +extern void zend_update_property_bool(zend_class_entry *scope, zval *object, char *name, int name_length, long value TSRMLS_DC);
20611 +extern void zend_update_property_stringl(zend_class_entry *scope, zval *object, char *name, int name_length, char *value, int value_len TSRMLS_DC);
20617 + * Local variables:
20619 + * c-basic-offset: 4
20621 + * vim600: noet sw=4 ts=4 fdm=marker
20622 + * vim<600: noet sw=4 ts=4
20626 +++ b/ext/http/php_http.h
20629 + +--------------------------------------------------------------------+
20631 + +--------------------------------------------------------------------+
20632 + | Redistribution and use in source and binary forms, with or without |
20633 + | modification, are permitted provided that the conditions mentioned |
20634 + | in the accompanying LICENSE file are met. |
20635 + +--------------------------------------------------------------------+
20636 + | Copyright (c) 2004-2010, Michael Wallner <mike@php.net> |
20637 + +--------------------------------------------------------------------+
20640 +/* $Id: php_http.h 324012 2012-03-08 08:44:32Z mike $ */
20642 +#ifndef PHP_EXT_HTTP_H
20643 +#define PHP_EXT_HTTP_H
20645 +#define PHP_HTTP_VERSION "1.7.4"
20647 +#ifdef HAVE_CONFIG_H
20648 +# include "config.h"
20650 +# ifndef PHP_WIN32
20651 +# include "php_config.h"
20656 +#include "missing.h"
20657 +#include "php_http_std_defs.h"
20658 +#include "phpstr/phpstr.h"
20660 +#ifdef HTTP_WANT_SAPI
20661 +# if PHP_API_VERSION > 20041225
20662 +# define HTTP_HAVE_SAPI_RTIME
20664 +# include "SAPI.h"
20667 +#ifdef HTTP_WANT_NETDB
20669 +# define HTTP_HAVE_NETDB
20670 +# include <winsock2.h>
20671 +# elif defined(HAVE_NETDB_H)
20672 +# define HTTP_HAVE_NETDB
20673 +# include <netdb.h>
20674 +# ifdef HAVE_UNISTD_H
20675 +# include <unistd.h>
20680 +#if defined(HTTP_WANT_CURL) && defined(HTTP_HAVE_CURL)
20682 +# include <winsock2.h>
20683 +# define CURL_STATICLIB
20685 +# include <curl/curl.h>
20686 +# define HTTP_CURL_VERSION(x, y, z) (LIBCURL_VERSION_NUM >= (((x)<<16) + ((y)<<8) + (z)))
20688 +# if defined(HTTP_WANT_EVENT) && defined(HTTP_HAVE_EVENT)
20689 +# include <event.h>
20693 +#if defined(HTTP_WANT_MAGIC) && defined(HTTP_HAVE_MAGIC)
20694 +# if defined(PHP_WIN32) && !defined(USE_MAGIC_DLL) && !defined(USE_MAGIC_STATIC)
20695 +# define USE_MAGIC_STATIC
20697 +# include <magic.h>
20700 +#if defined(HTTP_WANT_ZLIB) && defined(HTTP_HAVE_ZLIB)
20701 +# include <zlib.h>
20704 +#include <ctype.h>
20705 +#define HTTP_IS_CTYPE(type, c) is##type((int) (unsigned char) (c))
20706 +#define HTTP_TO_CTYPE(type, c) to##type((int) (unsigned char) (c))
20708 +extern zend_module_entry http_module_entry;
20709 +#define phpext_http_ptr &http_module_entry
20711 +extern int http_module_number;
20713 +ZEND_BEGIN_MODULE_GLOBALS(http)
20715 + struct _http_globals_etag {
20718 + zend_bool started;
20721 + struct _http_globals_log {
20725 + char *allowed_methods;
20729 + struct _http_globals_send {
20730 + double throttle_delay;
20731 + size_t buffer_size;
20732 + char *content_type;
20733 + char *unquoted_etag;
20734 + time_t last_modified;
20735 + struct _http_globals_send_deflate {
20736 + zend_bool response;
20737 + zend_bool start_auto;
20738 + long start_flags;
20742 + struct _http_globals_send_inflate {
20743 + zend_bool start_auto;
20744 + long start_flags;
20747 + zend_bool not_found_404;
20750 + struct _http_globals_request {
20752 + HashTable *headers;
20753 + struct _http_globals_request_methods {
20754 + HashTable registered;
20758 +#if defined(ZEND_ENGINE_2) && defined(HTTP_HAVE_CURL)
20759 + struct _http_globals_request_datashare {
20760 + zend_llist handles;
20761 + zend_bool cookie;
20764 + zend_bool connect;
20767 +#if defined(ZEND_ENGINE_2) && defined(HTTP_HAVE_EVENT)
20768 + struct _http_globals_request_pool {
20769 + struct _http_globals_request_pool_event {
20776 + struct _http_globals_persistent {
20777 + struct _http_globals_persistent_handles {
20779 + struct _http_globals_persistent_handles_ident {
20787 +#ifdef ZEND_ENGINE_2
20788 + zend_bool only_exceptions;
20791 + zend_bool force_exit;
20792 + zend_bool read_post_data;
20793 + zval *server_var;
20795 +ZEND_END_MODULE_GLOBALS(http)
20797 +ZEND_EXTERN_MODULE_GLOBALS(http);
20800 +# include "TSRM.h"
20801 +# define HTTP_G ((zend_http_globals *) (*((void ***) tsrm_ls))[TSRM_UNSHUFFLE_RSRC_ID(http_globals_id)])
20803 +# define HTTP_G (&http_globals)
20806 +#if defined(HAVE_ICONV) && (HTTP_SHARED_DEPS || !defined(COMPILE_DL_ICONV))
20807 +# define HTTP_HAVE_ICONV
20810 +#if defined(HAVE_PHP_SESSION) && (HTTP_SHARED_DEPS || !defined(COMPILE_DL_SESSION))
20811 +# define HTTP_HAVE_SESSION
20814 +#if defined(HAVE_HASH_EXT) && (HTTP_SHARED_DEPS || !defined(COMPILE_DL_HASH)) && defined(HTTP_HAVE_PHP_HASH_H)
20815 +# define HTTP_HAVE_HASH
20818 +#if defined(HAVE_SPL)
20819 +# define HTTP_HAVE_SPL
20822 +PHP_FUNCTION(http_date);
20823 +PHP_FUNCTION(http_build_url);
20824 +PHP_FUNCTION(http_build_str);
20825 +PHP_FUNCTION(http_negotiate_language);
20826 +PHP_FUNCTION(http_negotiate_charset);
20827 +PHP_FUNCTION(http_negotiate_content_type);
20828 +PHP_FUNCTION(http_negotiate);
20829 +PHP_FUNCTION(http_redirect);
20830 +PHP_FUNCTION(http_throttle);
20831 +PHP_FUNCTION(http_send_status);
20832 +PHP_FUNCTION(http_send_last_modified);
20833 +PHP_FUNCTION(http_send_content_type);
20834 +PHP_FUNCTION(http_send_content_disposition);
20835 +PHP_FUNCTION(http_match_modified);
20836 +PHP_FUNCTION(http_match_etag);
20837 +PHP_FUNCTION(http_cache_last_modified);
20838 +PHP_FUNCTION(http_cache_etag);
20839 +PHP_FUNCTION(http_send_data);
20840 +PHP_FUNCTION(http_send_file);
20841 +PHP_FUNCTION(http_send_stream);
20842 +PHP_FUNCTION(http_chunked_decode);
20843 +PHP_FUNCTION(http_parse_message);
20844 +PHP_FUNCTION(http_parse_headers);
20845 +PHP_FUNCTION(http_parse_cookie);
20846 +PHP_FUNCTION(http_build_cookie);
20847 +PHP_FUNCTION(http_parse_params);
20848 +PHP_FUNCTION(http_get_request_headers);
20849 +PHP_FUNCTION(http_get_request_body);
20850 +PHP_FUNCTION(http_get_request_body_stream);
20851 +PHP_FUNCTION(http_match_request_header);
20852 +PHP_FUNCTION(http_persistent_handles_count);
20853 +PHP_FUNCTION(http_persistent_handles_clean);
20854 +PHP_FUNCTION(http_persistent_handles_ident);
20855 +#ifdef HTTP_HAVE_CURL
20856 +PHP_FUNCTION(http_get);
20857 +PHP_FUNCTION(http_head);
20858 +PHP_FUNCTION(http_post_data);
20859 +PHP_FUNCTION(http_post_fields);
20860 +PHP_FUNCTION(http_put_data);
20861 +PHP_FUNCTION(http_put_file);
20862 +PHP_FUNCTION(http_put_stream);
20863 +PHP_FUNCTION(http_request);
20864 +PHP_FUNCTION(http_request_body_encode);
20865 +#endif /* HTTP_HAVE_CURL */
20866 +PHP_FUNCTION(http_request_method_register);
20867 +PHP_FUNCTION(http_request_method_unregister);
20868 +PHP_FUNCTION(http_request_method_exists);
20869 +PHP_FUNCTION(http_request_method_name);
20870 +PHP_FUNCTION(ob_etaghandler);
20871 +#ifdef HTTP_HAVE_ZLIB
20872 +PHP_FUNCTION(http_deflate);
20873 +PHP_FUNCTION(http_inflate);
20874 +PHP_FUNCTION(ob_deflatehandler);
20875 +PHP_FUNCTION(ob_inflatehandler);
20877 +PHP_FUNCTION(http_support);
20879 +#endif /* PHP_HTTP_H */
20882 + * Local variables:
20884 + * c-basic-offset: 4
20886 + * vim600: noet sw=4 ts=4 fdm=marker
20887 + * vim<600: noet sw=4 ts=4
20891 +++ b/ext/http/php_http_api.h
20894 + +--------------------------------------------------------------------+
20896 + +--------------------------------------------------------------------+
20897 + | Redistribution and use in source and binary forms, with or without |
20898 + | modification, are permitted provided that the conditions mentioned |
20899 + | in the accompanying LICENSE file are met. |
20900 + +--------------------------------------------------------------------+
20901 + | Copyright (c) 2004-2010, Michael Wallner <mike@php.net> |
20902 + +--------------------------------------------------------------------+
20905 +/* $Id: php_http_api.h 323304 2012-02-17 21:13:24Z mike $ */
20907 +#ifndef PHP_HTTP_API_H
20908 +#define PHP_HTTP_API_H
20910 +#define HTTP_SUPPORT 0x01L
20911 +#define HTTP_SUPPORT_REQUESTS 0x02L
20912 +#define HTTP_SUPPORT_MAGICMIME 0x04L
20913 +#define HTTP_SUPPORT_ENCODINGS 0x08L
20914 +#define HTTP_SUPPORT_SSLREQUESTS 0x20L
20915 +#define HTTP_SUPPORT_PERSISTENCE 0x40L
20916 +#define HTTP_SUPPORT_EVENTS 0x80L
20918 +#define HTTP_PARAMS_ALLOW_COMMA 0x01
20919 +#define HTTP_PARAMS_ALLOW_FAILURE 0x02
20920 +#define HTTP_PARAMS_RAISE_ERROR 0x04
20921 +#define HTTP_PARAMS_DEFAULT (HTTP_PARAMS_ALLOW_COMMA|HTTP_PARAMS_ALLOW_FAILURE|HTTP_PARAMS_RAISE_ERROR)
20922 +#define HTTP_PARAMS_COLON_SEPARATOR 0x10
20924 +extern PHP_MINIT_FUNCTION(http_support);
20926 +#define http_support(f) _http_support(f)
20927 +PHP_HTTP_API long _http_support(long feature);
20929 +#define pretty_key(key, key_len, uctitle, xhyphen) _http_pretty_key(key, key_len, uctitle, xhyphen)
20930 +extern char *_http_pretty_key(char *key, size_t key_len, zend_bool uctitle, zend_bool xhyphen);
20932 +#define http_boundary(b, l) _http_boundary((b), (l) TSRMLS_CC)
20933 +extern size_t _http_boundary(char *buf, size_t len TSRMLS_DC);
20935 +#define http_error(type, code, string) _http_error_ex(type, code, "%s", string)
20936 +#define http_error_ex _http_error_ex
20937 +extern void _http_error_ex(long type TSRMLS_DC, long code, const char *format, ...);
20940 +#ifdef ZEND_ENGINE_2
20941 +#define http_exception_wrap(o, n, ce) _http_exception_wrap((o), (n), (ce) TSRMLS_CC)
20942 +extern zval *_http_exception_wrap(zval *old_exception, zval *new_exception, zend_class_entry *ce TSRMLS_DC);
20944 +#define http_try \
20946 + zval *old_exception = EG(exception); \
20947 + EG(exception) = NULL;
20948 +#define http_catch(ex_ce) \
20949 + if (EG(exception) && old_exception) { \
20950 + EG(exception) = http_exception_wrap(old_exception, EG(exception), ex_ce); \
20953 +#define http_final(ex_ce) \
20954 + if (EG(exception)) { \
20955 + EG(exception) = http_exception_wrap(EG(exception), NULL, ex_ce); \
20958 +typedef zend_object_value (*http_object_new_t)(zend_class_entry *ce, void *, void ** TSRMLS_DC);
20960 +#define http_object_new(ov, cn, cl, co, ce, i, pp) _http_object_new((ov), (cn), (cl), (http_object_new_t) (co), (ce), (i), (void *) (pp) TSRMLS_CC)
20961 +extern STATUS _http_object_new(zend_object_value *ov, const char *cname_str, uint cname_len, http_object_new_t create, zend_class_entry *parent_ce, void *intern_ptr, void **obj_ptr TSRMLS_DC);
20962 +#endif /* ZEND_ENGINE_2 */
20965 +#define HTTP_CHECK_CURL_INIT(ch, init, action) \
20966 + if ((!(ch)) && (!((ch) = init))) { \
20967 + http_error(HE_WARNING, HTTP_E_REQUEST, "Could not initialize curl"); \
20970 +#define HTTP_CHECK_CONTENT_TYPE(ct, action) \
20971 + if (!strchr((ct), '/')) { \
20972 + http_error_ex(HE_WARNING, HTTP_E_INVALID_PARAM, \
20973 + "Content type \"%s\" does not seem to contain a primary and a secondary part", (ct)); \
20976 +#define HTTP_CHECK_MESSAGE_TYPE_RESPONSE(msg, action) \
20977 + if (!HTTP_MSG_TYPE(RESPONSE, (msg))) { \
20978 + http_error(HE_NOTICE, HTTP_E_MESSAGE_TYPE, "HttpMessage is not of type HTTP_MSG_RESPONSE"); \
20981 +#define HTTP_CHECK_MESSAGE_TYPE_REQUEST(msg, action) \
20982 + if (!HTTP_MSG_TYPE(REQUEST, (msg))) { \
20983 + http_error(HE_NOTICE, HTTP_E_MESSAGE_TYPE, "HttpMessage is not of type HTTP_MSG_REQUEST"); \
20986 +#define HTTP_CHECK_GZIP_LEVEL(level, action) \
20987 + if (level < -1 || level > 9) { \
20988 + http_error_ex(HE_WARNING, HTTP_E_INVALID_PARAM, "Invalid compression level (-1 to 9): %d", level); \
20991 +#ifndef PHP_OUTPUT_NEWAPI
20992 +# define HTTP_GET_OUTPUT_START() \
20993 + char *output_start_filename = php_get_output_start_filename(TSRMLS_C); \
20994 + int output_start_lineno = php_get_output_start_lineno(TSRMLS_C)
20996 +# define HTTP_GET_OUTPUT_START() \
20997 + char *output_start_filename = php_output_get_start_filename(TSRMLS_C); \
20998 + int output_start_lineno = php_output_get_start_lineno(TSRMLS_C)
21000 +#define HTTP_CHECK_HEADERS_SENT(action) \
21001 + if (SG(headers_sent) && !SG(request_info).no_headers) { \
21002 + HTTP_GET_OUTPUT_START(); \
21003 + if (output_start_filename) { \
21004 + http_error_ex(HE_WARNING, HTTP_E_HEADER, "Cannot modify header information - headers already sent by (output started at %s:%d)", \
21005 + output_start_filename, output_start_lineno); \
21007 + http_error(HE_WARNING, HTTP_E_HEADER, "Cannot modify header information - headers already sent"); \
21012 +#define http_log(f, i, m) _http_log_ex((f), (i), (m) TSRMLS_CC)
21013 +extern void _http_log_ex(char *file, const char *ident, const char *message TSRMLS_DC);
21015 +#define http_exit(s, h) http_exit_ex((s), (h), NULL, 1)
21016 +#define http_exit_ex(s, h, b, e) _http_exit_ex((s), (h), (b), (e) TSRMLS_CC)
21017 +extern STATUS _http_exit_ex(int status, char *header, char *body, zend_bool send_header TSRMLS_DC);
21019 +#define http_check_method(m) http_check_method_ex((m), HTTP_KNOWN_METHODS)
21020 +#define http_check_method_ex(m, a) _http_check_method_ex((m), (a))
21021 +extern STATUS _http_check_method_ex(const char *method, const char *methods);
21023 +#define http_got_server_var(v) (NULL != http_get_server_var_ex((v), strlen(v), 1))
21024 +#define http_get_server_var(v, c) http_get_server_var_ex((v), strlen(v), (c))
21025 +#define http_get_server_var_ex(v, l, c) _http_get_server_var_ex((v), (l), (c) TSRMLS_CC)
21026 +PHP_HTTP_API zval *_http_get_server_var_ex(const char *key, size_t key_len, zend_bool check TSRMLS_DC);
21028 +#define http_get_request_body(b, l) _http_get_request_body_ex((b), (l), 1 TSRMLS_CC)
21029 +#define http_get_request_body_ex(b, l, d) _http_get_request_body_ex((b), (l), (d) TSRMLS_CC)
21030 +PHP_HTTP_API STATUS _http_get_request_body_ex(char **body, size_t *length, zend_bool dup TSRMLS_DC);
21032 +#define http_get_request_body_stream() _http_get_request_body_stream(TSRMLS_C)
21033 +PHP_HTTP_API php_stream *_http_get_request_body_stream(TSRMLS_D);
21036 +typedef void (*http_parse_params_callback)(void *cb_arg, const char *key, int keylen, const char *val, int vallen TSRMLS_DC);
21038 +#define http_parse_params_default_callback _http_parse_params_default_callback
21039 +PHP_HTTP_API void _http_parse_params_default_callback(void *ht, const char *key, int keylen, const char *val, int vallen TSRMLS_DC);
21041 +#define http_parse_params(s, f, ht) _http_parse_params_ex((s), (f), _http_parse_params_default_callback, (ht) TSRMLS_CC)
21042 +#define http_parse_params_ex(s, f, cb, a) _http_parse_params_ex((s), (f), (cb), (a) TSRMLS_CC)
21043 +PHP_HTTP_API STATUS _http_parse_params_ex(const char *params, int flags, http_parse_params_callback cb, void *cb_arg TSRMLS_DC);
21046 +#define http_sleep(s) _http_sleep(s)
21047 +static inline void _http_sleep(double s)
21049 +#define HTTP_DIFFSEC (0.001)
21050 +#define HTTP_MLLISEC (1000)
21051 +#define HTTP_MCROSEC (1000 * 1000)
21052 +#define HTTP_NANOSEC (1000 * 1000 * 1000)
21053 +#define HTTP_MSEC(s) ((long)(s * HTTP_MLLISEC))
21054 +#define HTTP_USEC(s) ((long)(s * HTTP_MCROSEC))
21055 +#define HTTP_NSEC(s) ((long)(s * HTTP_NANOSEC))
21057 +#if defined(PHP_WIN32)
21058 + Sleep((DWORD) HTTP_MSEC(s));
21059 +#elif defined(HAVE_USLEEP)
21060 + usleep(HTTP_USEC(s));
21061 +#elif defined(HAVE_NANOSLEEP)
21062 + struct timespec req, rem;
21064 + req.tv_sec = (time_t) s;
21065 + req.tv_nsec = HTTP_NSEC(s) % HTTP_NANOSEC;
21067 + while (nanosleep(&req, &rem) && (errno == EINTR) && (HTTP_NSEC(rem.tv_sec) + rem.tv_nsec) > HTTP_NSEC(HTTP_DIFFSEC))) {
21068 + req.tv_sec = rem.tv_sec;
21069 + req.tv_nsec = rem.tv_nsec;
21072 + struct timeval timeout;
21074 + timeout.tv.sec = (time_t) s;
21075 + timeout.tv_usec = HTTP_USEC(s) % HTTP_MCROSEC;
21077 + select(0, NULL, NULL, NULL, &timeout);
21081 +#define http_locate_str _http_locate_str
21082 +static inline const char *_http_locate_str(const char *h, size_t h_len, const char *n, size_t n_len)
21084 + const char *p, *e;
21086 + if (n_len && h_len) {
21090 + for (p = n; *p == h[p-n]; ++p) {
21091 + if (p == n+n_len-1) {
21096 + } while (h++ != e);
21102 +#define http_locate_body _http_locate_body
21103 +static inline const char *_http_locate_body(const char *message)
21105 + const char *body = NULL, *msg = message;
21108 + if (*msg == '\n') {
21109 + if (*(msg+1) == '\n') {
21112 + } else if (*(msg+1) == '\r' && *(msg+2) == '\n') {
21122 +#define http_locate_eol _http_locate_eol
21123 +static inline const char *_http_locate_eol(const char *line, int *eol_len)
21125 + const char *eol = strpbrk(line, "\r\n");
21128 + *eol_len = eol ? ((eol[0] == '\r' && eol[1] == '\n') ? 2 : 1) : 0;
21133 +#define http_zset(t, z) _http_zset((t), (z))
21134 +static inline zval *_http_zset(int type, zval *z)
21136 + if (Z_TYPE_P(z) != type) {
21138 + case IS_NULL: convert_to_null(z); break;
21139 + case IS_BOOL: convert_to_boolean(z); break;
21140 + case IS_LONG: convert_to_long(z); break;
21141 + case IS_DOUBLE: convert_to_double(z); break;
21142 + case IS_STRING: convert_to_string(z); break;
21143 + case IS_ARRAY: convert_to_array(z); break;
21144 + case IS_OBJECT: convert_to_object(z); break;
21149 +#define http_zsep(t, z) _http_zsep_ex((t), (z), NULL)
21150 +#define http_zsep_ex(t, z, p) _http_zsep_ex((t), (z), (p))
21151 +static inline zval *_http_zsep_ex(int type, zval *z, zval **p) {
21153 + if (Z_TYPE_P(z) != type) {
21155 + case IS_NULL: convert_to_null_ex(&z); break;
21156 + case IS_BOOL: convert_to_boolean_ex(&z); break;
21157 + case IS_LONG: convert_to_long_ex(&z); break;
21158 + case IS_DOUBLE: convert_to_double_ex(&z); break;
21159 + case IS_STRING: convert_to_string_ex(&z); break;
21160 + case IS_ARRAY: convert_to_array_ex(&z); break;
21161 + case IS_OBJECT: convert_to_object_ex(&z); break;
21164 + SEPARATE_ZVAL_IF_NOT_REF(&z);
21172 +typedef struct _HashKey {
21179 +#define initHashKey(dup) {NULL, 0, 0, (dup), 0}
21181 +#define FOREACH_VAL(pos, array, val) FOREACH_HASH_VAL(pos, Z_ARRVAL_P(array), val)
21182 +#define FOREACH_HASH_VAL(pos, hash, val) \
21183 + for ( zend_hash_internal_pointer_reset_ex(hash, &pos); \
21184 + zend_hash_get_current_data_ex(hash, (void *) &val, &pos) == SUCCESS; \
21185 + zend_hash_move_forward_ex(hash, &pos))
21187 +#define FOREACH_KEY(pos, array, key) FOREACH_HASH_KEY(pos, Z_ARRVAL_P(array), key)
21188 +#define FOREACH_HASH_KEY(pos, hash, _key) \
21189 + for ( zend_hash_internal_pointer_reset_ex(hash, &pos); \
21190 + ((_key).type = zend_hash_get_current_key_ex(hash, &(_key).str, &(_key).len, &(_key).num, (zend_bool) (_key).dup, &pos)) != HASH_KEY_NON_EXISTANT; \
21191 + zend_hash_move_forward_ex(hash, &pos)) \
21193 +#define FOREACH_KEYVAL(pos, array, key, val) FOREACH_HASH_KEYVAL(pos, Z_ARRVAL_P(array), key, val)
21194 +#define FOREACH_HASH_KEYVAL(pos, hash, _key, val) \
21195 + for ( zend_hash_internal_pointer_reset_ex(hash, &pos); \
21196 + ((_key).type = zend_hash_get_current_key_ex(hash, &(_key).str, &(_key).len, &(_key).num, (zend_bool) (_key).dup, &pos)) != HASH_KEY_NON_EXISTANT && \
21197 + zend_hash_get_current_data_ex(hash, (void *) &val, &pos) == SUCCESS; \
21198 + zend_hash_move_forward_ex(hash, &pos))
21200 +#define array_copy(src, dst) zend_hash_copy(dst, src, (copy_ctor_func_t) zval_add_ref, NULL, sizeof(zval *))
21201 +#define ARRAY_JOIN_STRONLY 1
21202 +#define ARRAY_JOIN_PRETTIFY 2
21203 +#define array_join(src, dst, append, flags) zend_hash_apply_with_arguments(src HTTP_ZAPI_HASH_TSRMLS_CC, (append)?apply_array_append_func:apply_array_merge_func, 2, dst, (int)flags)
21205 +extern int apply_array_append_func(void *pDest HTTP_ZAPI_HASH_TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key);
21206 +extern int apply_array_merge_func(void *pDest HTTP_ZAPI_HASH_TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key);
21211 + * Local variables:
21213 + * c-basic-offset: 4
21215 + * vim600: noet sw=4 ts=4 fdm=marker
21216 + * vim<600: noet sw=4 ts=4
21220 +++ b/ext/http/php_http_cache_api.h
21223 + +--------------------------------------------------------------------+
21225 + +--------------------------------------------------------------------+
21226 + | Redistribution and use in source and binary forms, with or without |
21227 + | modification, are permitted provided that the conditions mentioned |
21228 + | in the accompanying LICENSE file are met. |
21229 + +--------------------------------------------------------------------+
21230 + | Copyright (c) 2004-2010, Michael Wallner <mike@php.net> |
21231 + +--------------------------------------------------------------------+
21234 +/* $Id: php_http_cache_api.h 292841 2009-12-31 08:48:57Z mike $ */
21236 +#ifndef PHP_HTTP_CACHE_API_H
21237 +#define PHP_HTTP_CACHE_API_H
21239 +#include "php_http_send_api.h"
21241 +#include "ext/standard/crc32.h"
21242 +#include "ext/standard/sha1.h"
21243 +#include "ext/standard/md5.h"
21245 +#ifdef HTTP_HAVE_HASH
21246 +# include "php_hash.h"
21249 +#define http_etag_digest(d, l) _http_etag_digest((d), (l))
21250 +static inline char *_http_etag_digest(const unsigned char *digest, int len)
21252 + static const char hexdigits[17] = "0123456789abcdef";
21254 + char *hex = emalloc(len * 2 + 1);
21257 + for (i = 0; i < len; ++i) {
21258 + *ptr++ = hexdigits[digest[i] >> 4];
21259 + *ptr++ = hexdigits[digest[i] & 0xF];
21266 +#define http_etag_init() _http_etag_init(TSRMLS_C)
21267 +static inline void *_http_etag_init(TSRMLS_D)
21269 + void *ctx = NULL;
21270 + char *mode = HTTP_G->etag.mode;
21272 +#ifdef HTTP_HAVE_HASH
21273 + const php_hash_ops *eho = NULL;
21275 + if (mode && (eho = php_hash_fetch_ops(mode, strlen(mode)))) {
21276 + ctx = emalloc(eho->context_size);
21277 + eho->hash_init(ctx);
21280 + if (mode && ((!strcasecmp(mode, "crc32")) || (!strcasecmp(mode, "crc32b")))) {
21281 + ctx = emalloc(sizeof(uint));
21282 + *((uint *) ctx) = ~0;
21283 + } else if (mode && !strcasecmp(mode, "sha1")) {
21284 + PHP_SHA1Init(ctx = emalloc(sizeof(PHP_SHA1_CTX)));
21286 + PHP_MD5Init(ctx = emalloc(sizeof(PHP_MD5_CTX)));
21292 +#define http_etag_finish(c) _http_etag_finish((c) TSRMLS_CC)
21293 +static inline char *_http_etag_finish(void *ctx TSRMLS_DC)
21295 + unsigned char digest[128] = {0};
21296 + char *etag = NULL, *mode = HTTP_G->etag.mode;
21298 +#ifdef HTTP_HAVE_HASH
21299 + const php_hash_ops *eho = NULL;
21301 + if (mode && (eho = php_hash_fetch_ops(mode, strlen(mode)))) {
21302 + eho->hash_final(digest, ctx);
21303 + etag = http_etag_digest(digest, eho->digest_size);
21306 + if (mode && ((!strcasecmp(mode, "crc32")) || (!strcasecmp(mode, "crc32b")))) {
21307 + *((uint *) ctx) = ~*((uint *) ctx);
21308 + etag = http_etag_digest((const unsigned char *) ctx, sizeof(uint));
21309 + } else if (mode && (!strcasecmp(mode, "sha1"))) {
21310 + PHP_SHA1Final(digest, ctx);
21311 + etag = http_etag_digest(digest, 20);
21313 + PHP_MD5Final(digest, ctx);
21314 + etag = http_etag_digest(digest, 16);
21321 +#define http_etag_update(c, d, l) _http_etag_update((c), (d), (l) TSRMLS_CC)
21322 +static inline void _http_etag_update(void *ctx, const char *data_ptr, size_t data_len TSRMLS_DC)
21324 + char *mode = HTTP_G->etag.mode;
21325 +#ifdef HTTP_HAVE_HASH
21326 + const php_hash_ops *eho = NULL;
21328 + if (mode && (eho = php_hash_fetch_ops(mode, strlen(mode)))) {
21329 + eho->hash_update(ctx, (const unsigned char *) data_ptr, data_len);
21332 + if (mode && ((!strcasecmp(mode, "crc32")) || (!strcasecmp(mode, "crc32b")))) {
21333 + uint i, c = *((uint *) ctx);
21334 + for (i = 0; i < data_len; ++i) {
21335 + CRC32(c, data_ptr[i]);
21337 + *((uint *)ctx) = c;
21338 + } else if (mode && (!strcasecmp(mode, "sha1"))) {
21339 + PHP_SHA1Update(ctx, (const unsigned char *) data_ptr, data_len);
21341 + PHP_MD5Update(ctx, (const unsigned char *) data_ptr, data_len);
21345 +#define http_ob_etaghandler(o, l, ho, hl, m) _http_ob_etaghandler((o), (l), (ho), (hl), (m) TSRMLS_CC)
21346 +extern void _http_ob_etaghandler(char *output, uint output_len, char **handled_output, uint *handled_output_len, int mode TSRMLS_DC);
21348 +#define http_etag(p, l, m) _http_etag((p), (l), (m) TSRMLS_CC)
21349 +PHP_HTTP_API char *_http_etag(const void *data_ptr, size_t data_len, http_send_mode data_mode TSRMLS_DC);
21351 +#define http_last_modified(p, m) _http_last_modified((p), (m) TSRMLS_CC)
21352 +PHP_HTTP_API time_t _http_last_modified(const void *data_ptr, http_send_mode data_mode TSRMLS_DC);
21354 +#define http_match_last_modified(entry, modified) _http_match_last_modified_ex((entry), (modified), 1 TSRMLS_CC)
21355 +#define http_match_last_modified_ex(entry, modified, ep) _http_match_last_modified_ex((entry), (modified), (ep) TSRMLS_CC)
21356 +PHP_HTTP_API zend_bool _http_match_last_modified_ex(const char *entry, time_t t, zend_bool enforce_presence TSRMLS_DC);
21358 +#define http_match_etag(entry, etag) _http_match_etag_ex((entry), (etag), 1 TSRMLS_CC)
21359 +#define http_match_etag_ex(entry, etag, ep) _http_match_etag_ex((entry), (etag), (ep) TSRMLS_CC)
21360 +PHP_HTTP_API zend_bool _http_match_etag_ex(const char *entry, const char *etag, zend_bool enforce_presence TSRMLS_DC);
21362 +#define http_cache_last_modified(l, s, cc, ccl) _http_cache_last_modified((l), (s), (cc), (ccl) TSRMLS_CC)
21363 +PHP_HTTP_API STATUS _http_cache_last_modified(time_t last_modified, time_t send_modified, const char *cache_control, size_t cc_len TSRMLS_DC);
21365 +#define http_cache_etag(e, el, cc, ccl) _http_cache_etag((e), (el), (cc), (ccl) TSRMLS_CC)
21366 +PHP_HTTP_API STATUS _http_cache_etag(const char *etag, size_t etag_len, const char *cache_control, size_t cc_len TSRMLS_DC);
21368 +#define http_start_ob_etaghandler() _http_start_ob_etaghandler(TSRMLS_C)
21369 +PHP_HTTP_API STATUS _http_start_ob_etaghandler(TSRMLS_D);
21370 +#define http_interrupt_ob_etaghandler() _http_interrupt_ob_etaghandler(TSRMLS_C)
21371 +PHP_HTTP_API zend_bool _http_interrupt_ob_etaghandler(TSRMLS_D);
21376 + * Local variables:
21378 + * c-basic-offset: 4
21380 + * vim600: noet sw=4 ts=4 fdm=marker
21381 + * vim<600: noet sw=4 ts=4
21385 +++ b/ext/http/php_http_cookie_api.h
21388 + +--------------------------------------------------------------------+
21390 + +--------------------------------------------------------------------+
21391 + | Redistribution and use in source and binary forms, with or without |
21392 + | modification, are permitted provided that the conditions mentioned |
21393 + | in the accompanying LICENSE file are met. |
21394 + +--------------------------------------------------------------------+
21395 + | Copyright (c) 2004-2010, Michael Wallner <mike@php.net> |
21396 + +--------------------------------------------------------------------+
21399 +/* $Id: php_http_cookie_api.h 292841 2009-12-31 08:48:57Z mike $ */
21401 +#ifndef PHP_HTTP_COOKIE_API_H
21402 +#define PHP_HTTP_COOKIE_API_H
21404 +#define HTTP_COOKIE_SECURE 0x10L
21405 +#define HTTP_COOKIE_HTTPONLY 0x20L
21407 +#define HTTP_COOKIE_PARSE_RAW 0x01L
21409 +extern PHP_MINIT_FUNCTION(http_cookie);
21412 + generally a netscape cookie compliant struct, recognizing httpOnly attribute, too;
21413 + cookie params like those from rfc2109 and rfc2965 are just put into extras, if
21414 + one specifies them in allowed extras, else they're treated like cookies themself
21416 +typedef struct _http_cookie_list_t {
21417 + HashTable cookies;
21418 + HashTable extras;
21423 +} http_cookie_list;
21425 +#define http_cookie_list_new() _http_cookie_list_init(NULL ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC TSRMLS_CC)
21426 +#define http_cookie_list_init(l) _http_cookie_list_init((l) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC TSRMLS_CC)
21427 +PHP_HTTP_API http_cookie_list *_http_cookie_list_init(http_cookie_list *list ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC TSRMLS_DC);
21429 +#define http_cookie_list_dtor(l) _http_cookie_list_dtor((l) TSRMLS_CC)
21430 +PHP_HTTP_API void _http_cookie_list_dtor(http_cookie_list *list TSRMLS_DC);
21432 +#define http_cookie_list_free(l) _http_cookie_list_free((l) TSRMLS_CC)
21433 +PHP_HTTP_API void _http_cookie_list_free(http_cookie_list **list TSRMLS_DC);
21435 +#define http_cookie_list_has_cookie(list, name, name_len) zend_hash_exists(&(list)->cookies, (name), (name_len)+1)
21436 +#define http_cookie_list_has_extra(list, name, name_len) zend_hash_exists(&(list)->extras, (name), (name_len)+1)
21438 +#define http_cookie_list_add_cookie(l, n, nl, v, vl) _http_cookie_list_add_cookie((l), (n), (nl), (v), (vl) TSRMLS_CC)
21439 +PHP_HTTP_API void _http_cookie_list_add_cookie(http_cookie_list *list, const char *name, size_t name_len, const char *value, size_t value_len TSRMLS_DC);
21441 +#define http_cookie_list_add_extra(l, n , nl, v, vl) _http_cookie_list_add_extra((l), (n), (nl), (v), (vl) TSRMLS_CC)
21442 +PHP_HTTP_API void _http_cookie_list_add_extra(http_cookie_list *list, const char *name, size_t name_len, const char *value, size_t value_len TSRMLS_DC);
21444 +#define http_cookie_list_get_cookie(l, n, nl) _http_cookie_list_get_cookie((l), (n), (nl) TSRMLS_CC)
21445 +PHP_HTTP_API const char *_http_cookie_list_get_cookie(http_cookie_list *list, const char *name, size_t name_len TSRMLS_DC);
21447 +#define http_cookie_list_get_extra(l, n, nl) _http_cookie_list_get_extra((l), (n), (nl) TSRMLS_CC)
21448 +PHP_HTTP_API const char *_http_cookie_list_get_extra(http_cookie_list *list, const char *name, size_t name_len TSRMLS_DC);
21450 +#define http_parse_cookie(s) _http_parse_cookie_ex(NULL, (s), 0, NULL TSRMLS_CC)
21451 +#define http_parse_cookie_ex(l, s, f, a) _http_parse_cookie_ex((l), (s), (f), (a) TSRMLS_CC)
21452 +PHP_HTTP_API http_cookie_list *_http_parse_cookie_ex(http_cookie_list * list, const char *string, long flags, char **allowed_extras TSRMLS_DC);
21454 +#define http_cookie_list_tostruct(l, s) _http_cookie_list_tostruct((l), (s) TSRMLS_CC)
21455 +PHP_HTTP_API void _http_cookie_list_tostruct(http_cookie_list *list, zval *strct TSRMLS_DC);
21457 +#define http_cookie_list_fromstruct(l, s) _http_cookie_list_fromstruct((l), (s) TSRMLS_CC)
21458 +PHP_HTTP_API http_cookie_list *_http_cookie_list_fromstruct(http_cookie_list *list, zval *strct TSRMLS_DC);
21460 +#define http_cookie_list_tostring(l, str, len) _http_cookie_list_tostring((l), (str), (len) TSRMLS_CC)
21461 +PHP_HTTP_API void _http_cookie_list_tostring(http_cookie_list *list, char **str, size_t *len TSRMLS_DC);
21466 + * Local variables:
21468 + * c-basic-offset: 4
21470 + * vim600: noet sw=4 ts=4 fdm=marker
21471 + * vim<600: noet sw=4 ts=4
21474 +++ b/ext/http/php_http_date_api.h
21477 + +--------------------------------------------------------------------+
21479 + +--------------------------------------------------------------------+
21480 + | Redistribution and use in source and binary forms, with or without |
21481 + | modification, are permitted provided that the conditions mentioned |
21482 + | in the accompanying LICENSE file are met. |
21483 + +--------------------------------------------------------------------+
21484 + | Copyright (c) 2004-2010, Michael Wallner <mike@php.net> |
21485 + +--------------------------------------------------------------------+
21488 +/* $Id: php_http_date_api.h 292841 2009-12-31 08:48:57Z mike $ */
21490 +#ifndef PHP_HTTP_DATE_API_H
21491 +#define PHP_HTTP_DATE_API_H
21493 +#define http_date(t) _http_date((t) TSRMLS_CC)
21494 +PHP_HTTP_API char *_http_date(time_t t TSRMLS_DC);
21496 +#define http_parse_date(d) _http_parse_date_ex((d), 0 TSRMLS_CC)
21497 +#define http_parse_date_ex(d, s) _http_parse_date_ex((d), (s) TSRMLS_CC)
21498 +PHP_HTTP_API time_t _http_parse_date_ex(const char *date, zend_bool silent TSRMLS_DC);
21503 + * Local variables:
21505 + * c-basic-offset: 4
21507 + * vim600: noet sw=4 ts=4 fdm=marker
21508 + * vim<600: noet sw=4 ts=4
21512 +++ b/ext/http/php_http_deflatestream_object.h
21515 + +--------------------------------------------------------------------+
21517 + +--------------------------------------------------------------------+
21518 + | Redistribution and use in source and binary forms, with or without |
21519 + | modification, are permitted provided that the conditions mentioned |
21520 + | in the accompanying LICENSE file are met. |
21521 + +--------------------------------------------------------------------+
21522 + | Copyright (c) 2004-2010, Michael Wallner <mike@php.net> |
21523 + +--------------------------------------------------------------------+
21526 +/* $Id: php_http_deflatestream_object.h 292841 2009-12-31 08:48:57Z mike $ */
21528 +#ifndef PHP_HTTP_DEFLATESTREAM_OBJECT_H
21529 +#define PHP_HTTP_DEFLATESTREAM_OBJECT_H
21530 +#ifdef HTTP_HAVE_ZLIB
21531 +#ifdef ZEND_ENGINE_2
21533 +typedef struct _http_deflatestream_object_t {
21535 + http_encoding_stream *stream;
21536 +} http_deflatestream_object;
21538 +extern zend_class_entry *http_deflatestream_object_ce;
21539 +extern zend_function_entry http_deflatestream_object_fe[];
21541 +extern PHP_MINIT_FUNCTION(http_deflatestream_object);
21543 +#define http_deflatestream_object_new(ce) _http_deflatestream_object_new((ce) TSRMLS_CC)
21544 +extern zend_object_value _http_deflatestream_object_new(zend_class_entry *ce TSRMLS_DC);
21545 +#define http_deflatestream_object_new_ex(ce, s, ptr) _http_deflatestream_object_new_ex((ce), (s), (ptr) TSRMLS_CC)
21546 +extern zend_object_value _http_deflatestream_object_new_ex(zend_class_entry *ce, http_encoding_stream *s, http_deflatestream_object **ptr TSRMLS_DC);
21547 +#define http_deflatestream_object_clone(zobj) _http_deflatestream_object_clone_obj(zobj TSRMLS_CC)
21548 +extern zend_object_value _http_deflatestream_object_clone_obj(zval *object TSRMLS_DC);
21549 +#define http_deflatestream_object_free(o) _http_deflatestream_object_free((o) TSRMLS_CC)
21550 +extern void _http_deflatestream_object_free(zend_object *object TSRMLS_DC);
21552 +PHP_METHOD(HttpDeflateStream, __construct);
21553 +PHP_METHOD(HttpDeflateStream, factory);
21554 +PHP_METHOD(HttpDeflateStream, update);
21555 +PHP_METHOD(HttpDeflateStream, flush);
21556 +PHP_METHOD(HttpDeflateStream, finish);
21563 + * Local variables:
21565 + * c-basic-offset: 4
21567 + * vim600: noet sw=4 ts=4 fdm=marker
21568 + * vim<600: noet sw=4 ts=4
21572 +++ b/ext/http/php_http_encoding_api.h
21575 + +--------------------------------------------------------------------+
21577 + +--------------------------------------------------------------------+
21578 + | Redistribution and use in source and binary forms, with or without |
21579 + | modification, are permitted provided that the conditions mentioned |
21580 + | in the accompanying LICENSE file are met. |
21581 + +--------------------------------------------------------------------+
21582 + | Copyright (c) 2004-2010, Michael Wallner <mike@php.net> |
21583 + +--------------------------------------------------------------------+
21586 +/* $Id: php_http_encoding_api.h 292841 2009-12-31 08:48:57Z mike $ */
21588 +#ifndef PHP_HTTP_ENCODING_API_H
21589 +#define PHP_HTTP_ENCODING_API_H
21591 +#define http_encoding_dechunk(e, el, d, dl) _http_encoding_dechunk((e), (el), (d), (dl) TSRMLS_CC)
21592 +PHP_HTTP_API const char *_http_encoding_dechunk(const char *encoded, size_t encoded_len, char **decoded, size_t *decoded_len TSRMLS_DC);
21594 +#define http_encoding_response_start(cl, i) _http_encoding_response_start((cl), (i) TSRMLS_CC)
21595 +PHP_HTTP_API int _http_encoding_response_start(size_t content_length, zend_bool ignore_http_ohandler TSRMLS_DC);
21597 +#ifdef HTTP_HAVE_ZLIB
21599 +extern PHP_MINIT_FUNCTION(http_encoding);
21600 +extern PHP_RINIT_FUNCTION(http_encoding);
21601 +extern PHP_RSHUTDOWN_FUNCTION(http_encoding);
21603 +typedef enum _http_encoding_type_t {
21604 + HTTP_ENCODING_NONE,
21605 + HTTP_ENCODING_GZIP,
21606 + HTTP_ENCODING_DEFLATE,
21607 +} http_encoding_type;
21609 +#define HTTP_INFLATE_ROUNDS 100
21611 +#define HTTP_DEFLATE_BUFFER_SIZE_GUESS(S) \
21612 + (((size_t) ((double) S * (double) 1.015)) + 10 + 8 + 4 + 1)
21613 +#define HTTP_INFLATE_BUFFER_SIZE_GUESS(S) \
21615 +#define HTTP_INFLATE_BUFFER_SIZE_ALIGN(S) \
21616 + ((S) += (S) >> (3))
21618 +#define HTTP_DEFLATE_BUFFER_SIZE 0x8000
21619 +#define HTTP_INFLATE_BUFFER_SIZE 0x1000
21621 +#define HTTP_DEFLATE_LEVEL_DEF 0x00000000
21622 +#define HTTP_DEFLATE_LEVEL_MIN 0x00000001
21623 +#define HTTP_DEFLATE_LEVEL_MAX 0x00000009
21624 +#define HTTP_DEFLATE_TYPE_ZLIB 0x00000000
21625 +#define HTTP_DEFLATE_TYPE_GZIP 0x00000010
21626 +#define HTTP_DEFLATE_TYPE_RAW 0x00000020
21627 +#define HTTP_DEFLATE_STRATEGY_DEF 0x00000000
21628 +#define HTTP_DEFLATE_STRATEGY_FILT 0x00000100
21629 +#define HTTP_DEFLATE_STRATEGY_HUFF 0x00000200
21630 +#define HTTP_DEFLATE_STRATEGY_RLE 0x00000300
21631 +#define HTTP_DEFLATE_STRATEGY_FIXED 0x00000400
21633 +#define HTTP_DEFLATE_LEVEL_SET(flags, level) \
21634 + switch (flags & 0xf) \
21637 + if ((flags & 0xf) < 10) { \
21638 + level = flags & 0xf; \
21641 + case HTTP_DEFLATE_LEVEL_DEF: \
21642 + level = Z_DEFAULT_COMPRESSION; \
21646 +#define HTTP_DEFLATE_WBITS_SET(flags, wbits) \
21647 + switch (flags & 0xf0) \
21649 + case HTTP_DEFLATE_TYPE_GZIP: \
21650 + wbits = HTTP_WINDOW_BITS_GZIP; \
21652 + case HTTP_DEFLATE_TYPE_RAW: \
21653 + wbits = HTTP_WINDOW_BITS_RAW; \
21656 + wbits = HTTP_WINDOW_BITS_ZLIB; \
21660 +#define HTTP_INFLATE_WBITS_SET(flags, wbits) \
21661 + if (flags & HTTP_INFLATE_TYPE_RAW) { \
21662 + wbits = HTTP_WINDOW_BITS_RAW; \
21664 + wbits = HTTP_WINDOW_BITS_ANY; \
21667 +#define HTTP_DEFLATE_STRATEGY_SET(flags, strategy) \
21668 + switch (flags & 0xf00) \
21670 + case HTTP_DEFLATE_STRATEGY_FILT: \
21671 + strategy = Z_FILTERED; \
21673 + case HTTP_DEFLATE_STRATEGY_HUFF: \
21674 + strategy = Z_HUFFMAN_ONLY; \
21676 + case HTTP_DEFLATE_STRATEGY_RLE: \
21677 + strategy = Z_RLE; \
21679 + case HTTP_DEFLATE_STRATEGY_FIXED: \
21680 + strategy = Z_FIXED; \
21683 + strategy = Z_DEFAULT_STRATEGY; \
21687 +#define HTTP_WINDOW_BITS_ZLIB 0x0000000f
21688 +#define HTTP_WINDOW_BITS_GZIP 0x0000001f
21689 +#define HTTP_WINDOW_BITS_ANY 0x0000002f
21690 +#define HTTP_WINDOW_BITS_RAW -0x000000f
21693 +/* Z_FIXED does not exist prior 1.2.2.2 */
21694 +# define Z_FIXED 0
21697 +#define HTTP_INFLATE_TYPE_ZLIB 0x00000000
21698 +#define HTTP_INFLATE_TYPE_GZIP 0x00000000
21699 +#define HTTP_INFLATE_TYPE_RAW 0x00000001
21701 +#define HTTP_ENCODING_STREAM_FLUSH_NONE 0x00000000
21702 +#define HTTP_ENCODING_STREAM_FLUSH_SYNC 0x00100000
21703 +#define HTTP_ENCODING_STREAM_FLUSH_FULL 0x00200000
21705 +#define HTTP_ENCODING_STREAM_FLUSH_FLAG(f) \
21706 + (((f) & HTTP_ENCODING_STREAM_FLUSH_FULL) ? Z_FULL_FLUSH : \
21707 + (((f) & HTTP_ENCODING_STREAM_FLUSH_SYNC) ? Z_SYNC_FLUSH : Z_NO_FLUSH))
21709 +#define HTTP_ENCODING_STREAM_PERSISTENT 0x01000000
21711 +typedef struct _http_encoding_stream_t {
21715 +} http_encoding_stream;
21717 +#define http_encoding_deflate(f, d, dl, r, rl) _http_encoding_deflate((f), (d), (dl), (r), (rl) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC TSRMLS_CC)
21718 +PHP_HTTP_API STATUS _http_encoding_deflate(int flags, const char *data, size_t data_len, char **encoded, size_t *encoded_len ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC TSRMLS_DC);
21719 +#define http_encoding_inflate(d, dl, r, rl) _http_encoding_inflate((d), (dl), (r), (rl) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC TSRMLS_CC)
21720 +PHP_HTTP_API STATUS _http_encoding_inflate(const char *data, size_t data_len, char **decoded, size_t *decoded_len ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC TSRMLS_DC);
21722 +#define http_encoding_deflate_stream_init(s, f) _http_encoding_deflate_stream_init((s), (f) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC TSRMLS_CC)
21723 +PHP_HTTP_API http_encoding_stream *_http_encoding_deflate_stream_init(http_encoding_stream *s, int flags ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC TSRMLS_DC);
21724 +#define http_encoding_deflate_stream_update(s, d, dl, e, el) _http_encoding_deflate_stream_update((s), (d), (dl), (e), (el) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC TSRMLS_CC)
21725 +PHP_HTTP_API STATUS _http_encoding_deflate_stream_update(http_encoding_stream *s, const char *data, size_t data_len, char **encoded, size_t *encoded_len ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC TSRMLS_DC);
21726 +#define http_encoding_deflate_stream_flush(s, e, el) _http_encoding_deflate_stream_flush((s), (e), (el) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC TSRMLS_CC)
21727 +PHP_HTTP_API STATUS _http_encoding_deflate_stream_flush(http_encoding_stream *s, char **encoded, size_t *encoded_len ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC TSRMLS_DC);
21728 +#define http_encoding_deflate_stream_finish(s, e, el) _http_encoding_deflate_stream_finish((s), (e), (el) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC TSRMLS_CC)
21729 +PHP_HTTP_API STATUS _http_encoding_deflate_stream_finish(http_encoding_stream *s, char **encoded, size_t *encoded_len ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC TSRMLS_DC);
21730 +#define http_encoding_deflate_stream_dtor(s) _http_encoding_deflate_stream_dtor((s) TSRMLS_CC)
21731 +PHP_HTTP_API void _http_encoding_deflate_stream_dtor(http_encoding_stream *s TSRMLS_DC);
21732 +#define http_encoding_deflate_stream_free(s) _http_encoding_deflate_stream_free((s) TSRMLS_CC)
21733 +PHP_HTTP_API void _http_encoding_deflate_stream_free(http_encoding_stream **s TSRMLS_DC);
21735 +#define http_encoding_inflate_stream_init(s, f) _http_encoding_inflate_stream_init((s), (f) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC TSRMLS_CC)
21736 +PHP_HTTP_API http_encoding_stream *_http_encoding_inflate_stream_init(http_encoding_stream *s, int flags ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC TSRMLS_DC);
21737 +#define http_encoding_inflate_stream_update(s, d, dl, e, el) _http_encoding_inflate_stream_update((s), (d), (dl), (e), (el) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC TSRMLS_CC)
21738 +PHP_HTTP_API STATUS _http_encoding_inflate_stream_update(http_encoding_stream *s, const char *data, size_t data_len, char **decoded, size_t *decoded_len ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC TSRMLS_DC);
21739 +#define http_encoding_inflate_stream_flush(s, d, dl) _http_encoding_inflate_stream_flush((s), (d), (dl) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC TSRMLS_CC)
21740 +PHP_HTTP_API STATUS _http_encoding_inflate_stream_flush(http_encoding_stream *s, char **decoded, size_t *decoded_len ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC TSRMLS_DC);
21741 +#define http_encoding_inflate_stream_finish(s, e, el) _http_encoding_inflate_stream_finish((s), (e), (el) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC TSRMLS_CC)
21742 +PHP_HTTP_API STATUS _http_encoding_inflate_stream_finish(http_encoding_stream *s, char **decoded, size_t *decoded_len ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC TSRMLS_DC);
21743 +#define http_encoding_inflate_stream_dtor(s) _http_encoding_inflate_stream_dtor((s) TSRMLS_CC)
21744 +PHP_HTTP_API void _http_encoding_inflate_stream_dtor(http_encoding_stream *s TSRMLS_DC);
21745 +#define http_encoding_inflate_stream_free(s) _http_encoding_inflate_stream_free((s) TSRMLS_CC)
21746 +PHP_HTTP_API void _http_encoding_inflate_stream_free(http_encoding_stream **s TSRMLS_DC);
21748 +#define http_ob_deflatehandler(o, ol, h, hl, m) _http_ob_deflatehandler((o), (ol), (h), (hl), (m) TSRMLS_CC)
21749 +extern void _http_ob_deflatehandler(char *, uint, char **, uint *, int TSRMLS_DC);
21751 +#define http_ob_inflatehandler(o, ol, h, hl, m) _http_ob_inflatehandler((o), (ol), (h), (hl), (m) TSRMLS_CC)
21752 +extern void _http_ob_inflatehandler(char *, uint, char **, uint *, int TSRMLS_DC);
21754 +#endif /* HTTP_HAVE_ZLIB */
21759 + * Local variables:
21761 + * c-basic-offset: 4
21763 + * vim600: noet sw=4 ts=4 fdm=marker
21764 + * vim<600: noet sw=4 ts=4
21767 +++ b/ext/http/php_http_exception_object.h
21770 + +--------------------------------------------------------------------+
21772 + +--------------------------------------------------------------------+
21773 + | Redistribution and use in source and binary forms, with or without |
21774 + | modification, are permitted provided that the conditions mentioned |
21775 + | in the accompanying LICENSE file are met. |
21776 + +--------------------------------------------------------------------+
21777 + | Copyright (c) 2004-2010, Michael Wallner <mike@php.net> |
21778 + +--------------------------------------------------------------------+
21781 +/* $Id: php_http_exception_object.h 292841 2009-12-31 08:48:57Z mike $ */
21783 +#ifndef PHP_HTTP_EXCEPTION_OBJECT_H
21784 +#define PHP_HTTP_EXCEPTION_OBJECT_H
21785 +#ifdef ZEND_ENGINE_2
21787 +#include "zend_exceptions.h"
21789 +PHP_MINIT_FUNCTION(http_exception_object);
21791 +#define HTTP_EX_DEF_CE http_exception_object_ce
21792 +#define HTTP_EX_CE(name) http_ ##name## _exception_object_ce
21794 +extern zend_class_entry *http_exception_object_ce;
21795 +extern zend_class_entry *HTTP_EX_CE(runtime);
21796 +extern zend_class_entry *HTTP_EX_CE(header);
21797 +extern zend_class_entry *HTTP_EX_CE(malformed_headers);
21798 +extern zend_class_entry *HTTP_EX_CE(request_method);
21799 +extern zend_class_entry *HTTP_EX_CE(message_type);
21800 +extern zend_class_entry *HTTP_EX_CE(invalid_param);
21801 +extern zend_class_entry *HTTP_EX_CE(encoding);
21802 +extern zend_class_entry *HTTP_EX_CE(request);
21803 +extern zend_class_entry *HTTP_EX_CE(request_pool);
21804 +extern zend_class_entry *HTTP_EX_CE(socket);
21805 +extern zend_class_entry *HTTP_EX_CE(response);
21806 +extern zend_class_entry *HTTP_EX_CE(url);
21807 +extern zend_function_entry http_exception_object_fe[];
21809 +#define http_exception_get_default _http_exception_get_default
21810 +extern zend_class_entry *_http_exception_get_default();
21812 +#define http_exception_get_for_code(c) _http_exception_get_for_code(c)
21813 +extern zend_class_entry *_http_exception_get_for_code(long code);
21815 +PHP_METHOD(HttpException, __toString);
21821 + * Local variables:
21823 + * c-basic-offset: 4
21825 + * vim600: noet sw=4 ts=4 fdm=marker
21826 + * vim<600: noet sw=4 ts=4
21830 +++ b/ext/http/php_http_filter_api.h
21833 + +--------------------------------------------------------------------+
21835 + +--------------------------------------------------------------------+
21836 + | Redistribution and use in source and binary forms, with or without |
21837 + | modification, are permitted provided that the conditions mentioned |
21838 + | in the accompanying LICENSE file are met. |
21839 + +--------------------------------------------------------------------+
21840 + | Copyright (c) 2004-2010, Michael Wallner <mike@php.net> |
21841 + +--------------------------------------------------------------------+
21844 +/* $Id: php_http_filter_api.h 292841 2009-12-31 08:48:57Z mike $ */
21846 +#ifndef PHP_HTTP_FILTER_API_H
21847 +#define PHP_HTTP_FILTER_API_H
21848 +#ifdef ZEND_ENGINE_2
21850 +extern php_stream_filter_factory http_filter_factory;
21851 +PHP_MINIT_FUNCTION(http_filter);
21857 + * Local variables:
21859 + * c-basic-offset: 4
21861 + * vim600: noet sw=4 ts=4 fdm=marker
21862 + * vim<600: noet sw=4 ts=4
21866 +++ b/ext/http/php_http_headers_api.h
21869 + +--------------------------------------------------------------------+
21871 + +--------------------------------------------------------------------+
21872 + | Redistribution and use in source and binary forms, with or without |
21873 + | modification, are permitted provided that the conditions mentioned |
21874 + | in the accompanying LICENSE file are met. |
21875 + +--------------------------------------------------------------------+
21876 + | Copyright (c) 2004-2010, Michael Wallner <mike@php.net> |
21877 + +--------------------------------------------------------------------+
21880 +/* $Id: php_http_headers_api.h 300300 2010-06-09 07:29:35Z mike $ */
21882 +#ifndef PHP_HTTP_HEADERS_API_H
21883 +#define PHP_HTTP_HEADERS_API_H
21885 +#include "php_http_info_api.h"
21887 +typedef enum http_range_status_t {
21891 +} http_range_status;
21893 +#define http_parse_headers(h, a) _http_parse_headers_ex((h), Z_ARRVAL_P(a), 1, http_info_default_callback, NULL TSRMLS_CC)
21894 +#define http_parse_headers_ex(h, ht, p) _http_parse_headers_ex((h), (ht), (p), http_info_default_callback, NULL TSRMLS_CC)
21895 +#define http_parse_headers_cb(h, ht, p, f, d) _http_parse_headers_ex((h), (ht), (p), (f), (d) TSRMLS_CC)
21896 +PHP_HTTP_API STATUS _http_parse_headers_ex(const char *header, HashTable *headers, zend_bool prettify, http_info_callback callback_func, void **callback_data TSRMLS_DC);
21898 +typedef char *(*negotiate_func_t)(const char *test, double *quality, HashTable *supported TSRMLS_DC);
21900 +#define http_negotiate_language_func _http_negotiate_language_func
21901 +extern char *_http_negotiate_language_func(const char *test, double *quality, HashTable *supported TSRMLS_DC);
21902 +#define http_negotiate_content_type_func _http_negotiate_default_func
21903 +#define http_negotiate_encoding_func _http_negotiate_default_func
21904 +#define http_negotiate_charset_func _http_negotiate_default_func
21905 +#define http_negotiate_default_func _http_negotiate_default_func
21906 +extern char *_http_negotiate_default_func(const char *test, double *quality, HashTable *supported TSRMLS_DC);
21908 +#define http_negotiate_language(zsupported) http_negotiate_language_ex(Z_ARRVAL_P(zsupported))
21909 +#define http_negotiate_language_ex(supported) http_negotiate_q("HTTP_ACCEPT_LANGUAGE", (supported), http_negotiate_language_func)
21910 +#define http_negotiate_charset(zsupported) http_negotiate_charset_ex(Z_ARRVAL_P(zsupported))
21911 +#define http_negotiate_charset_ex(supported) http_negotiate_q("HTTP_ACCEPT_CHARSET", (supported), http_negotiate_charset_func)
21912 +#define http_negotiate_encoding(zsupported) http_negotiate_encoding_ex(Z_ARRVAL_P(zsupported))
21913 +#define http_negotiate_encoding_ex(supported) http_negotiate_q("HTTP_ACCEPT_ENCODING", (supported), http_negotiate_encoding_func)
21914 +#define http_negotiate_content_type(zsupported) http_negotiate_content_type_ex(Z_ARRVAL_P(zsupported))
21915 +#define http_negotiate_content_type_ex(supported) http_negotiate_q("HTTP_ACCEPT", (supported), http_negotiate_content_type_func)
21916 +#define http_negotiate_q(e, s, n) _http_negotiate_q((e), (s), (n) TSRMLS_CC)
21917 +PHP_HTTP_API HashTable *_http_negotiate_q(const char *header, HashTable *supported, negotiate_func_t neg TSRMLS_DC);
21918 +#define http_negotiate_z(z, s, n) _http_negotiate_z((z), (s), (n) TSRMLS_CC)
21919 +PHP_HTTP_API HashTable *_http_negotiate_z(zval *value, HashTable *supported, negotiate_func_t neg TSRMLS_DC);
21921 +#define http_get_request_ranges(r, l) _http_get_request_ranges((r), (l) TSRMLS_CC)
21922 +PHP_HTTP_API http_range_status _http_get_request_ranges(HashTable *ranges, size_t length TSRMLS_DC);
21924 +#define http_get_request_headers(h) _http_get_request_headers((h) TSRMLS_CC)
21925 +PHP_HTTP_API void _http_get_request_headers(HashTable *headers TSRMLS_DC);
21927 +#define http_get_response_headers(h) _http_get_response_headers((h) TSRMLS_CC)
21928 +PHP_HTTP_API STATUS _http_get_response_headers(HashTable *headers_ht TSRMLS_DC);
21930 +#define http_match_request_header(h, v) http_match_request_header_ex((h), (v), 0)
21931 +#define http_match_request_header_ex(h, v, c) _http_match_request_header_ex((h), (v), (c) TSRMLS_CC)
21932 +PHP_HTTP_API zend_bool _http_match_request_header_ex(const char *header, const char *value, zend_bool match_case TSRMLS_DC);
21937 + * Local variables:
21939 + * c-basic-offset: 4
21941 + * vim600: noet sw=4 ts=4 fdm=marker
21942 + * vim<600: noet sw=4 ts=4
21946 +++ b/ext/http/php_http_inflatestream_object.h
21949 + +--------------------------------------------------------------------+
21951 + +--------------------------------------------------------------------+
21952 + | Redistribution and use in source and binary forms, with or without |
21953 + | modification, are permitted provided that the conditions mentioned |
21954 + | in the accompanying LICENSE file are met. |
21955 + +--------------------------------------------------------------------+
21956 + | Copyright (c) 2004-2010, Michael Wallner <mike@php.net> |
21957 + +--------------------------------------------------------------------+
21960 +/* $Id: php_http_inflatestream_object.h 292841 2009-12-31 08:48:57Z mike $ */
21962 +#ifndef PHP_HTTP_INFLATESTREAM_OBJECT_H
21963 +#define PHP_HTTP_INFLATESTREAM_OBJECT_H
21964 +#ifdef HTTP_HAVE_ZLIB
21965 +#ifdef ZEND_ENGINE_2
21967 +typedef struct _http_inflatestream_object_t {
21969 + http_encoding_stream *stream;
21970 +} http_inflatestream_object;
21972 +extern zend_class_entry *http_inflatestream_object_ce;
21973 +extern zend_function_entry http_inflatestream_object_fe[];
21975 +extern PHP_MINIT_FUNCTION(http_inflatestream_object);
21977 +#define http_inflatestream_object_new(ce) _http_inflatestream_object_new((ce) TSRMLS_CC)
21978 +extern zend_object_value _http_inflatestream_object_new(zend_class_entry *ce TSRMLS_DC);
21979 +#define http_inflatestream_object_new_ex(ce, s, ptr) _http_inflatestream_object_new_ex((ce), (s), (ptr) TSRMLS_CC)
21980 +extern zend_object_value _http_inflatestream_object_new_ex(zend_class_entry *ce, http_encoding_stream *s, http_inflatestream_object **ptr TSRMLS_DC);
21981 +#define http_inflatestream_object_clone(zobj) _http_inflatestream_object_clone_obj(zobj TSRMLS_CC)
21982 +extern zend_object_value _http_inflatestream_object_clone_obj(zval *object TSRMLS_DC);
21983 +#define http_inflatestream_object_free(o) _http_inflatestream_object_free((o) TSRMLS_CC)
21984 +extern void _http_inflatestream_object_free(zend_object *object TSRMLS_DC);
21986 +PHP_METHOD(HttpInflateStream, __construct);
21987 +PHP_METHOD(HttpInflateStream, factory);
21988 +PHP_METHOD(HttpInflateStream, update);
21989 +PHP_METHOD(HttpInflateStream, flush);
21990 +PHP_METHOD(HttpInflateStream, finish);
21997 + * Local variables:
21999 + * c-basic-offset: 4
22001 + * vim600: noet sw=4 ts=4 fdm=marker
22002 + * vim<600: noet sw=4 ts=4
22006 +++ b/ext/http/php_http_info_api.h
22009 + +--------------------------------------------------------------------+
22011 + +--------------------------------------------------------------------+
22012 + | Redistribution and use in source and binary forms, with or without |
22013 + | modification, are permitted provided that the conditions mentioned |
22014 + | in the accompanying LICENSE file are met. |
22015 + +--------------------------------------------------------------------+
22016 + | Copyright (c) 2004-2010, Michael Wallner <mike@php.net> |
22017 + +--------------------------------------------------------------------+
22020 +/* $Id: php_http_info_api.h 292841 2009-12-31 08:48:57Z mike $ */
22022 +#ifndef PHP_HTTP_INFO_API_H
22023 +#define PHP_HTTP_INFO_API_H
22025 +#define IS_HTTP_REQUEST 1
22026 +#define IS_HTTP_RESPONSE 2
22028 +#define HTTP_INFO(ptr) (ptr)->http.info
22030 +#define HTTP_INFO_REQUEST_FMT_ARGS(_http_ptr, _EOL) "%s %s HTTP/%1.1f" _EOL, \
22031 + (_http_ptr)->info.request.method?(_http_ptr)->info.request.method:"UNKNOWN", \
22032 + (_http_ptr)->info.request.url?(_http_ptr)->info.request.url:"/", \
22033 + (_http_ptr)->version>0.0?(_http_ptr)->version:1.1
22035 +#define HTTP_INFO_RESPONSE_FMT_ARGS(_http_ptr, _EOL) "HTTP/%1.1f %d%s%s" _EOL, \
22036 + (_http_ptr)->version>0.0?(_http_ptr)->version:1.1, \
22037 + (_http_ptr)->info.response.code?(_http_ptr)->info.response.code:200, \
22038 + (_http_ptr)->info.response.status&&*(_http_ptr)->info.response.status ? " ":"", \
22039 + STR_PTR((_http_ptr)->info.response.status)
22041 +typedef struct _http_request_info_t {
22044 +} http_request_info;
22046 +typedef struct _http_response_info_t {
22049 +} http_response_info;
22051 +typedef union _http_info_union_t {
22052 + http_request_info request;
22053 + http_response_info response;
22054 +} http_info_union;
22056 +struct http_info {
22057 + http_info_union info;
22061 +typedef struct _http_info_t {
22062 + struct http_info http;
22066 +typedef void (*http_info_callback)(void **callback_data, HashTable **headers, http_info *info TSRMLS_DC);
22068 +#define http_info_default_callback _http_info_default_callback
22069 +PHP_HTTP_API void _http_info_default_callback(void **nothing, HashTable **headers, http_info *info TSRMLS_DC);
22070 +#define http_info_dtor _http_info_dtor
22071 +PHP_HTTP_API void _http_info_dtor(http_info *info);
22072 +#define http_info_parse(p, i) _http_info_parse_ex((p), (i), 1 TSRMLS_CC)
22073 +#define http_info_parse_ex(p, i, s) _http_info_parse_ex((p), (i), (s) TSRMLS_CC)
22074 +PHP_HTTP_API STATUS _http_info_parse_ex(const char *pre_header, http_info *info , zend_bool silent TSRMLS_DC);
22079 + * Local variables:
22081 + * c-basic-offset: 4
22083 + * vim600: noet sw=4 ts=4 fdm=marker
22084 + * vim<600: noet sw=4 ts=4
22088 +++ b/ext/http/php_http_message_api.h
22091 + +--------------------------------------------------------------------+
22093 + +--------------------------------------------------------------------+
22094 + | Redistribution and use in source and binary forms, with or without |
22095 + | modification, are permitted provided that the conditions mentioned |
22096 + | in the accompanying LICENSE file are met. |
22097 + +--------------------------------------------------------------------+
22098 + | Copyright (c) 2004-2010, Michael Wallner <mike@php.net> |
22099 + +--------------------------------------------------------------------+
22102 +/* $Id: php_http_message_api.h 292841 2009-12-31 08:48:57Z mike $ */
22104 +#ifndef PHP_HTTP_MESSAGE_API_H
22105 +#define PHP_HTTP_MESSAGE_API_H
22107 +#include "php_http_info_api.h"
22109 +typedef enum _http_message_type_t {
22110 + HTTP_MSG_NONE = 0,
22111 + HTTP_MSG_REQUEST = IS_HTTP_REQUEST,
22112 + HTTP_MSG_RESPONSE = IS_HTTP_RESPONSE,
22113 +} http_message_type;
22115 +typedef struct _http_message_t http_message;
22117 +struct _http_message_t {
22120 + http_message_type type;
22121 + struct http_info http;
22122 + http_message *parent;
22125 +/* required minimum length of an HTTP message "HTTP/1.1" */
22126 +#define HTTP_MSG_MIN_SIZE 8
22128 +/* shorthand for type checks */
22129 +#define HTTP_MSG_TYPE(TYPE, msg) ((msg) && ((msg)->type == HTTP_MSG_ ##TYPE))
22131 +#define http_message_new() http_message_init_ex(NULL, 0)
22132 +#define http_message_init(m) http_message_init_ex((m), 0)
22133 +#define http_message_init_ex(m, t) _http_message_init_ex((m), (t) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)
22134 +#define http_message_init_rel(m, t) _http_message_init_ex((m), (t) ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC)
22135 +PHP_HTTP_API http_message *_http_message_init_ex(http_message *m, http_message_type t ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC);
22136 +#define http_message_init_env(m, t) _http_message_init_env((m), (t) TSRMLS_CC ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)
22137 +PHP_HTTP_API http_message *_http_message_init_env(http_message *m, http_message_type t TSRMLS_DC ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC);
22139 +#define http_message_set_type(m, t) _http_message_set_type((m), (t))
22140 +PHP_HTTP_API void _http_message_set_type(http_message *m, http_message_type t);
22142 +#define http_message_set_info(m, i) _http_message_set_info((m), (i))
22143 +PHP_HTTP_API void _http_message_set_info(http_message *message, http_info *info);
22145 +#define http_message_header(m, h) _http_message_header_ex((m), (h), sizeof(h), 1)
22146 +#define http_message_header_ex _http_message_header_ex
22147 +static inline zval *_http_message_header_ex(http_message *msg, char *key_str, size_t key_len, int join)
22150 + if (SUCCESS == zend_hash_find(&msg->hdrs, key_str, key_len, (void *) &header)) {
22151 + if (join && Z_TYPE_PP(header) == IS_ARRAY) {
22152 + zval *header_str, **val;
22153 + HashPosition pos;
22156 + phpstr_init(&str);
22157 + MAKE_STD_ZVAL(header_str);
22158 + FOREACH_VAL(pos, *header, val) {
22159 + phpstr_appendf(&str, PHPSTR_LEN(&str) ? ", %s":"%s", Z_STRVAL_PP(val));
22161 + phpstr_fix(&str);
22162 + ZVAL_STRINGL(header_str, PHPSTR_VAL(&str), PHPSTR_LEN(&str), 0);
22163 + return header_str;
22165 + ZVAL_ADDREF(*header);
22172 +#define http_message_count(c, m) \
22174 + http_message *__tmp_msg = (m); \
22175 + for (c = 0; __tmp_msg; __tmp_msg = __tmp_msg->parent, ++(c)); \
22178 +#define http_message_parse(m, l) http_message_parse_ex(NULL, (m), (l))
22179 +#define http_message_parse_ex(h, m, l) _http_message_parse_ex((h), (m), (l) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC TSRMLS_CC)
22180 +#define http_message_parse_rel(h, m, l) _http_message_parse_ex((h), (m), (l) ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC TSRMLS_CC)
22181 +PHP_HTTP_API http_message *_http_message_parse_ex(http_message *msg, const char *message, size_t length ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC TSRMLS_DC);
22183 +#define http_message_tostring(m, s, l) _http_message_tostring((m), (s), (l))
22184 +PHP_HTTP_API void _http_message_tostring(http_message *msg, char **string, size_t *length);
22186 +#define http_message_serialize(m, s, l) _http_message_serialize((m), (s), (l))
22187 +PHP_HTTP_API void _http_message_serialize(http_message *message, char **string, size_t *length);
22189 +#define http_message_reverse(m) _http_message_reverse(m)
22190 +PHP_HTTP_API http_message *_http_message_reverse(http_message *msg);
22192 +#define http_message_interconnect(m1, m2) _http_message_interconnect((m1), (m2))
22193 +PHP_HTTP_API http_message *_http_message_interconnect(http_message *m1, http_message *m2);
22195 +#define http_message_tostruct_recursive(m, s) _http_message_tostruct_recursive((m), (s) TSRMLS_CC)
22196 +PHP_HTTP_API void _http_message_tostruct_recursive(http_message *msg, zval *strct TSRMLS_DC);
22198 +#define http_message_send(m) _http_message_send((m) TSRMLS_CC)
22199 +PHP_HTTP_API STATUS _http_message_send(http_message *message TSRMLS_DC);
22201 +#define http_message_dup(m) _http_message_dup((m) TSRMLS_CC)
22202 +PHP_HTTP_API http_message *_http_message_dup(http_message *msg TSRMLS_DC);
22204 +#define http_message_dtor(m) _http_message_dtor((m))
22205 +PHP_HTTP_API void _http_message_dtor(http_message *message);
22207 +#define http_message_free(m) _http_message_free((m))
22208 +PHP_HTTP_API void _http_message_free(http_message **message);
22213 + * Local variables:
22215 + * c-basic-offset: 4
22217 + * vim600: noet sw=4 ts=4 fdm=marker
22218 + * vim<600: noet sw=4 ts=4
22222 +++ b/ext/http/php_http_message_object.h
22225 + +--------------------------------------------------------------------+
22227 + +--------------------------------------------------------------------+
22228 + | Redistribution and use in source and binary forms, with or without |
22229 + | modification, are permitted provided that the conditions mentioned |
22230 + | in the accompanying LICENSE file are met. |
22231 + +--------------------------------------------------------------------+
22232 + | Copyright (c) 2004-2010, Michael Wallner <mike@php.net> |
22233 + +--------------------------------------------------------------------+
22236 +/* $Id: php_http_message_object.h 298590 2010-04-26 11:46:35Z mike $ */
22238 +#ifndef PHP_HTTP_MESSAGE_OBJECT_H
22239 +#define PHP_HTTP_MESSAGE_OBJECT_H
22240 +#ifdef ZEND_ENGINE_2
22242 +typedef struct _http_message_object_t {
22244 + http_message *message;
22245 + zend_object_value parent;
22247 +} http_message_object;
22249 +extern zend_class_entry *http_message_object_ce;
22250 +extern zend_function_entry http_message_object_fe[];
22252 +extern PHP_MINIT_FUNCTION(http_message_object);
22253 +extern PHP_MSHUTDOWN_FUNCTION(http_message_object);
22255 +#define http_message_object_prepend(o, p) http_message_object_prepend_ex((o), (p), 1)
22256 +#define http_message_object_prepend_ex(o, p, t) _http_message_object_prepend_ex((o), (p), (t) TSRMLS_CC)
22257 +extern void _http_message_object_prepend_ex(zval *this_ptr, zval *prepend, zend_bool top TSRMLS_DC);
22259 +#define http_message_object_reverse(t, r) _http_message_object_reverse((t), (r) TSRMLS_CC)
22260 +extern void _http_message_object_reverse(zval *this_ptr, zval *return_value TSRMLS_DC);
22262 +#define http_message_object_new(ce) _http_message_object_new((ce) TSRMLS_CC)
22263 +extern zend_object_value _http_message_object_new(zend_class_entry *ce TSRMLS_DC);
22264 +#define http_message_object_new_ex(ce, msg, ptr) _http_message_object_new_ex((ce), (msg), (ptr) TSRMLS_CC)
22265 +extern zend_object_value _http_message_object_new_ex(zend_class_entry *ce, http_message *msg, http_message_object **ptr TSRMLS_DC);
22266 +#define http_message_object_clone(zobj) _http_message_object_clone_obj(zobj TSRMLS_CC)
22267 +extern zend_object_value _http_message_object_clone_obj(zval *object TSRMLS_DC);
22268 +#define http_message_object_free(o) _http_message_object_free((o) TSRMLS_CC)
22269 +extern void _http_message_object_free(zend_object *object TSRMLS_DC);
22271 +#define HTTP_MSG_CHECK_OBJ(obj, dofail) \
22272 + if (!(obj)->message) { \
22273 + http_error(E_WARNING, HTTP_E_MSG, "HttpMessage is empty"); \
22276 +#define HTTP_MSG_CHECK_STD() HTTP_MSG_CHECK_OBJ(obj, RETURN_FALSE)
22278 +#define HTTP_MSG_INIT_OBJ(obj) \
22279 + if (!(obj)->message) { \
22280 + (obj)->message = http_message_new(); \
22282 +#define HTTP_MSG_INIT_STD() HTTP_MSG_INIT_OBJ(obj)
22284 +PHP_METHOD(HttpMessage, __construct);
22285 +PHP_METHOD(HttpMessage, getBody);
22286 +PHP_METHOD(HttpMessage, setBody);
22287 +PHP_METHOD(HttpMessage, getHeader);
22288 +PHP_METHOD(HttpMessage, getHeaders);
22289 +PHP_METHOD(HttpMessage, setHeaders);
22290 +PHP_METHOD(HttpMessage, addHeaders);
22291 +PHP_METHOD(HttpMessage, getType);
22292 +PHP_METHOD(HttpMessage, setType);
22293 +PHP_METHOD(HttpMessage, getInfo);
22294 +PHP_METHOD(HttpMessage, setInfo);
22295 +PHP_METHOD(HttpMessage, getResponseCode);
22296 +PHP_METHOD(HttpMessage, setResponseCode);
22297 +PHP_METHOD(HttpMessage, getResponseStatus);
22298 +PHP_METHOD(HttpMessage, setResponseStatus);
22299 +PHP_METHOD(HttpMessage, getRequestMethod);
22300 +PHP_METHOD(HttpMessage, setRequestMethod);
22301 +PHP_METHOD(HttpMessage, getRequestUrl);
22302 +PHP_METHOD(HttpMessage, setRequestUrl);
22303 +PHP_METHOD(HttpMessage, getHttpVersion);
22304 +PHP_METHOD(HttpMessage, setHttpVersion);
22305 +PHP_METHOD(HttpMessage, guessContentType);
22306 +PHP_METHOD(HttpMessage, getParentMessage);
22307 +PHP_METHOD(HttpMessage, send);
22308 +PHP_METHOD(HttpMessage, toString);
22309 +PHP_METHOD(HttpMessage, toMessageTypeObject);
22311 +PHP_METHOD(HttpMessage, count);
22312 +PHP_METHOD(HttpMessage, serialize);
22313 +PHP_METHOD(HttpMessage, unserialize);
22314 +PHP_METHOD(HttpMessage, rewind);
22315 +PHP_METHOD(HttpMessage, valid);
22316 +PHP_METHOD(HttpMessage, current);
22317 +PHP_METHOD(HttpMessage, key);
22318 +PHP_METHOD(HttpMessage, next);
22320 +PHP_METHOD(HttpMessage, factory);
22321 +PHP_METHOD(HttpMessage, fromEnv);
22323 +PHP_METHOD(HttpMessage, detach);
22324 +PHP_METHOD(HttpMessage, prepend);
22325 +PHP_METHOD(HttpMessage, reverse);
22331 + * Local variables:
22333 + * c-basic-offset: 4
22335 + * vim600: noet sw=4 ts=4 fdm=marker
22336 + * vim<600: noet sw=4 ts=4
22340 +++ b/ext/http/php_http_persistent_handle_api.h
22343 + +--------------------------------------------------------------------+
22345 + +--------------------------------------------------------------------+
22346 + | Redistribution and use in source and binary forms, with or without |
22347 + | modification, are permitted provided that the conditions mentioned |
22348 + | in the accompanying LICENSE file are met. |
22349 + +--------------------------------------------------------------------+
22350 + | Copyright (c) 2004-2010, Michael Wallner <mike@php.net> |
22351 + +--------------------------------------------------------------------+
22354 +/* $Id: php_http_persistent_handle_api.h 292841 2009-12-31 08:48:57Z mike $ */
22356 +#ifndef HTTP_PERSISTENT_HANDLE_H
22357 +#define HTTP_PERSISTENT_HANDLE_H
22359 +typedef void *(*http_persistent_handle_ctor)(void);
22360 +typedef void (*http_persistent_handle_dtor)(void *handle);
22361 +typedef void *(*http_persistent_handle_copy)(void *handle);
22363 +PHP_MINIT_FUNCTION(http_persistent_handle);
22364 +PHP_MSHUTDOWN_FUNCTION(http_persistent_handle);
22366 +#define http_persistent_handle_provide(n, c, d, cc) _http_persistent_handle_provide_ex((n), strlen(n), (c), (d), (cc))
22367 +#define http_persistent_handle_provide_ex(n, l, c, d, cc) _http_persistent_handle_provide_ex((n), (l), (c), (d), (cc))
22368 +PHP_HTTP_API STATUS _http_persistent_handle_provide_ex(const char *name_str, size_t name_len, http_persistent_handle_ctor ctor, http_persistent_handle_dtor dtor, http_persistent_handle_copy copy);
22370 +#define http_persistent_handle_cleanup(n, c) _http_persistent_handle_cleanup_ex((n), strlen(n), (c) TSRMLS_CC)
22371 +#define http_persistent_handle_cleanup_ex(n, l,c ) _http_persistent_handle_cleanup_ex((n), (l), (c) TSRMLS_CC)
22372 +PHP_HTTP_API void _http_persistent_handle_cleanup_ex(const char *name_str, size_t name_len, int current_ident_only TSRMLS_DC);
22374 +#define http_persistent_handle_statall() _http_persistent_handle_statall_ex(NULL TSRMLS_CC)
22375 +#define http_persistent_handle_statall_ex(ht) _http_persistent_handle_statall_ex((ht) TSRMLS_CC)
22376 +PHP_HTTP_API HashTable *_http_persistent_handle_statall_ex(HashTable *ht TSRMLS_DC);
22378 +#define http_persistent_handle_acquire(n, h) _http_persistent_handle_acquire_ex((n), strlen(n), (h) TSRMLS_CC)
22379 +#define http_persistent_handle_acquire_ex(n, l, h) _http_persistent_handle_acquire_ex((n), (l), (h) TSRMLS_CC)
22380 +PHP_HTTP_API STATUS _http_persistent_handle_acquire_ex(const char *name_str, size_t name_len, void **handle TSRMLS_DC);
22382 +#define http_persistent_handle_release(n, h) _http_persistent_handle_release_ex((n), strlen(n), (h) TSRMLS_CC)
22383 +#define http_persistent_handle_release_ex(n, l, h) _http_persistent_handle_release_ex((n), (l), (h) TSRMLS_CC)
22384 +PHP_HTTP_API STATUS _http_persistent_handle_release_ex(const char *name_str, size_t name_len, void **handle TSRMLS_DC);
22386 +#define http_persistent_handle_accrete(n, oh, nh) _http_persistent_handle_accrete_ex((n), strlen(n), (oh), (nh) TSRMLS_CC)
22387 +#define http_persistent_handle_accrete_ex(n, l, oh, nh) _http_persistent_handle_accrete_ex((n), (l), (oh), (nh) TSRMLS_CC)
22388 +PHP_HTTP_API STATUS _http_persistent_handle_accrete_ex(const char *name_str, size_t name_len, void *old_handle, void **new_handle TSRMLS_DC);
22390 +#endif /* HTTP_PERSISTENT_HANDLE_H */
22393 + * Local variables:
22395 + * c-basic-offset: 4
22397 + * vim600: noet sw=4 ts=4 fdm=marker
22398 + * vim<600: noet sw=4 ts=4
22401 +++ b/ext/http/php_http_querystring_api.h
22404 + +--------------------------------------------------------------------+
22406 + +--------------------------------------------------------------------+
22407 + | Redistribution and use in source and binary forms, with or without |
22408 + | modification, are permitted provided that the conditions mentioned |
22409 + | in the accompanying LICENSE file are met. |
22410 + +--------------------------------------------------------------------+
22411 + | Copyright (c) 2004-2010, Michael Wallner <mike@php.net> |
22412 + +--------------------------------------------------------------------+
22415 +/* $Id: php_http_querystring_api.h 292841 2009-12-31 08:48:57Z mike $ */
22417 +#ifndef PHP_HTTP_QUERYSTRING_API_H
22418 +#define PHP_HTTP_QUERYSTRING_API_H
22420 +#ifdef HTTP_HAVE_ICONV
22421 +#define http_querystring_xlate(a, p, ie, oe) _http_querystring_xlate((a), (p), (ie), (oe) TSRMLS_CC)
22422 +PHP_HTTP_API int _http_querystring_xlate(zval *array, zval *param, const char *ie, const char *oe TSRMLS_DC);
22425 +#define http_querystring_update(qa, qs) _http_querystring_update((qa), (qs) TSRMLS_CC)
22426 +PHP_HTTP_API void _http_querystring_update(zval *qarray, zval *qstring TSRMLS_DC);
22428 +#define http_querystring_modify(q, p) _http_querystring_modify((q), (p) TSRMLS_CC)
22429 +PHP_HTTP_API int _http_querystring_modify(zval *qarray, zval *params TSRMLS_DC);
22434 + * Local variables:
22436 + * c-basic-offset: 4
22438 + * vim600: noet sw=4 ts=4 fdm=marker
22439 + * vim<600: noet sw=4 ts=4
22442 +++ b/ext/http/php_http_querystring_object.h
22445 + +--------------------------------------------------------------------+
22447 + +--------------------------------------------------------------------+
22448 + | Redistribution and use in source and binary forms, with or without |
22449 + | modification, are permitted provided that the conditions mentioned |
22450 + | in the accompanying LICENSE file are met. |
22451 + +--------------------------------------------------------------------+
22452 + | Copyright (c) 2004-2010, Michael Wallner <mike@php.net> |
22453 + +--------------------------------------------------------------------+
22456 +/* $Id: php_http_querystring_object.h 292841 2009-12-31 08:48:57Z mike $ */
22458 +#ifndef PHP_HTTP_QUERYSTRING_OBJECT_H
22459 +#define PHP_HTTP_QUERYSTRING_OBJECT_H
22460 +#ifdef ZEND_ENGINE_2
22462 +typedef struct _http_querystring_object_t {
22464 +} http_querystring_object;
22466 +#define HTTP_QUERYSTRING_TYPE_BOOL IS_BOOL
22467 +#define HTTP_QUERYSTRING_TYPE_INT IS_LONG
22468 +#define HTTP_QUERYSTRING_TYPE_FLOAT IS_DOUBLE
22469 +#define HTTP_QUERYSTRING_TYPE_STRING IS_STRING
22470 +#define HTTP_QUERYSTRING_TYPE_ARRAY IS_ARRAY
22471 +#define HTTP_QUERYSTRING_TYPE_OBJECT IS_OBJECT
22473 +extern zend_class_entry *http_querystring_object_ce;
22474 +extern zend_function_entry http_querystring_object_fe[];
22476 +extern PHP_MINIT_FUNCTION(http_querystring_object);
22478 +#define http_querystring_object_new(ce) _http_querystring_object_new((ce) TSRMLS_CC)
22479 +extern zend_object_value _http_querystring_object_new(zend_class_entry *ce TSRMLS_DC);
22480 +#define http_querystring_object_new_ex(ce, n, ptr) _http_querystring_object_new_ex((ce), (n), (ptr) TSRMLS_CC)
22481 +extern zend_object_value _http_querystring_object_new_ex(zend_class_entry *ce, void *nothing, http_querystring_object **ptr TSRMLS_DC);
22482 +#define http_querystring_object_free(o) _http_querystring_object_free((o) TSRMLS_CC)
22483 +extern void _http_querystring_object_free(zend_object *object TSRMLS_DC);
22485 +PHP_METHOD(HttpQueryString, __construct);
22486 +PHP_METHOD(HttpQueryString, toString);
22487 +PHP_METHOD(HttpQueryString, toArray);
22488 +PHP_METHOD(HttpQueryString, get);
22489 +PHP_METHOD(HttpQueryString, set);
22490 +PHP_METHOD(HttpQueryString, mod);
22491 +PHP_METHOD(HttpQueryString, getBool);
22492 +PHP_METHOD(HttpQueryString, getInt);
22493 +PHP_METHOD(HttpQueryString, getFloat);
22494 +PHP_METHOD(HttpQueryString, getString);
22495 +PHP_METHOD(HttpQueryString, getArray);
22496 +PHP_METHOD(HttpQueryString, getObject);
22497 +#ifdef HTTP_HAVE_ICONV
22498 +PHP_METHOD(HttpQueryString, xlate);
22500 +PHP_METHOD(HttpQueryString, factory);
22502 +PHP_METHOD(HttpQueryString, singleton);
22504 +PHP_METHOD(HttpQueryString, serialize);
22505 +PHP_METHOD(HttpQueryString, unserialize);
22506 +PHP_METHOD(HttpQueryString, offsetGet);
22507 +PHP_METHOD(HttpQueryString, offsetSet);
22508 +PHP_METHOD(HttpQueryString, offsetExists);
22509 +PHP_METHOD(HttpQueryString, offsetUnset);
22514 + * Local variables:
22516 + * c-basic-offset: 4
22518 + * vim600: noet sw=4 ts=4 fdm=marker
22519 + * vim<600: noet sw=4 ts=4
22523 +++ b/ext/http/php_http_request_api.h
22526 + +--------------------------------------------------------------------+
22528 + +--------------------------------------------------------------------+
22529 + | Redistribution and use in source and binary forms, with or without |
22530 + | modification, are permitted provided that the conditions mentioned |
22531 + | in the accompanying LICENSE file are met. |
22532 + +--------------------------------------------------------------------+
22533 + | Copyright (c) 2004-2010, Michael Wallner <mike@php.net> |
22534 + +--------------------------------------------------------------------+
22537 +/* $Id: php_http_request_api.h 292841 2009-12-31 08:48:57Z mike $ */
22539 +#ifndef PHP_HTTP_REQUEST_API_H
22540 +#define PHP_HTTP_REQUEST_API_H
22542 +#ifdef HTTP_HAVE_CURL
22544 +#include "php_http_request_body_api.h"
22545 +#include "php_http_request_method_api.h"
22547 +extern PHP_MINIT_FUNCTION(http_request);
22548 +extern PHP_MSHUTDOWN_FUNCTION(http_request);
22550 +typedef struct _http_request_t {
22553 + http_request_method meth;
22554 + http_request_body *body;
22557 + curl_infotype last_type;
22564 + HashTable options;
22565 + struct curl_slist *headers;
22573 + char _error[CURL_ERROR_SIZE+1];
22574 + zval *_progress_callback;
22580 + uint _in_progress_cb:1;
22585 +# define pestrndup(s,l,p) _pestrndup((s),(l),(p))
22586 +static inline void *_pestrndup(const void *s, size_t l, int p)
22588 + void *d = pemalloc(l+1, p);
22590 + ((char *) d)[l] = '\0';
22595 +/* CURLOPT_PRIVATE storage living as long as a CURL handle */
22596 +typedef struct _http_request_storage_t {
22598 + char *cookiestore;
22599 + char errorbuffer[CURL_ERROR_SIZE];
22600 +} http_request_storage;
22602 +static inline http_request_storage *http_request_storage_get(CURL *ch)
22604 + http_request_storage *st = NULL;
22605 + curl_easy_getinfo(ch, CURLINFO_PRIVATE, &st);
22609 +#define http_curl_init(r) http_curl_init_ex(NULL, (r))
22610 +#define http_curl_init_ex(c, r) _http_curl_init_ex((c), (r) TSRMLS_CC)
22611 +PHP_HTTP_API CURL *_http_curl_init_ex(CURL *ch, http_request *request TSRMLS_DC);
22613 +#define http_curl_free(c) _http_curl_free((c) TSRMLS_CC)
22614 +PHP_HTTP_API void _http_curl_free(CURL **ch TSRMLS_DC);
22616 +#define http_curl_copy(c) _http_curl_copy((c) TSRMLS_CC)
22617 +PHP_HTTP_API CURL *_http_curl_copy(CURL *ch TSRMLS_DC);
22619 +#define http_request_new() _http_request_init_ex(NULL, NULL, 0, NULL ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC TSRMLS_CC)
22620 +#define http_request_init(r) _http_request_init_ex((r), NULL, 0, NULL ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC TSRMLS_CC)
22621 +#define http_request_init_ex(r, c, m, u) _http_request_init_ex((r), (c), (m), (u) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC TSRMLS_CC)
22622 +PHP_HTTP_API http_request *_http_request_init_ex(http_request *request, CURL *ch, http_request_method meth, const char *url ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC TSRMLS_DC);
22624 +#define http_request_dtor(r) _http_request_dtor((r))
22625 +PHP_HTTP_API void _http_request_dtor(http_request *request);
22627 +#define http_request_free(r) _http_request_free((r))
22628 +PHP_HTTP_API void _http_request_free(http_request **request);
22630 +#define http_request_reset(r) _http_request_reset(r)
22631 +PHP_HTTP_API void _http_request_reset(http_request *r);
22633 +#define http_request_enable_cookies(r) _http_request_enable_cookies(r)
22634 +PHP_HTTP_API STATUS _http_request_enable_cookies(http_request *request);
22636 +#define http_request_reset_cookies(r, s) _http_request_reset_cookies((r), (s))
22637 +PHP_HTTP_API STATUS _http_request_reset_cookies(http_request *request, int session_only);
22639 +#define http_request_flush_cookies(r) _http_request_flush_cookies(r)
22640 +PHP_HTTP_API STATUS _http_request_flush_cookies(http_request *request);
22642 +#define http_request_defaults(r) _http_request_defaults(r)
22643 +PHP_HTTP_API void _http_request_defaults(http_request *request);
22645 +#define http_request_prepare(r, o) _http_request_prepare((r), (o))
22646 +PHP_HTTP_API STATUS _http_request_prepare(http_request *request, HashTable *options);
22648 +#define http_request_exec(r) _http_request_exec((r))
22649 +PHP_HTTP_API void _http_request_exec(http_request *request);
22651 +#define http_request_info(r, i) _http_request_info((r), (i))
22652 +PHP_HTTP_API void _http_request_info(http_request *request, HashTable *info);
22654 +#define http_request_set_progress_callback(r, cb) _http_request_set_progress_callback((r), (cb))
22655 +PHP_HTTP_API void _http_request_set_progress_callback(http_request *request, zval *cb);
22661 + * Local variables:
22663 + * c-basic-offset: 4
22665 + * vim600: noet sw=4 ts=4 fdm=marker
22666 + * vim<600: noet sw=4 ts=4
22670 +++ b/ext/http/php_http_request_body_api.h
22673 + +--------------------------------------------------------------------+
22675 + +--------------------------------------------------------------------+
22676 + | Redistribution and use in source and binary forms, with or without |
22677 + | modification, are permitted provided that the conditions mentioned |
22678 + | in the accompanying LICENSE file are met. |
22679 + +--------------------------------------------------------------------+
22680 + | Copyright (c) 2004-2010, Michael Wallner <mike@php.net> |
22681 + +--------------------------------------------------------------------+
22684 +/* $Id: php_http_request_body_api.h 292841 2009-12-31 08:48:57Z mike $ */
22686 +#ifndef PHP_HTTP_REQUEST_BODY_API_H
22687 +#define PHP_HTTP_REQUEST_BODY_API_H
22689 +#ifdef HTTP_HAVE_CURL
22691 +#define HTTP_REQUEST_BODY_EMPTY 0
22692 +#define HTTP_REQUEST_BODY_CSTRING 1
22693 +#define HTTP_REQUEST_BODY_CURLPOST 2
22694 +#define HTTP_REQUEST_BODY_UPLOADFILE 3
22695 +typedef struct _http_request_body_t {
22701 +} http_request_body;
22704 +#define http_request_body_new() http_request_body_init(NULL)
22705 +#define http_request_body_init(b) http_request_body_init_ex((b), 0, NULL, 0, 0)
22706 +#define http_request_body_init_ex(b, t, d, l, f) _http_request_body_init_ex((b), (t), (d), (l), (f) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC TSRMLS_CC)
22707 +#define http_request_body_init_rel(b, t, d, l, f) _http_request_body_init_ex((b), (t), (d), (l), (f) ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC TSRMLS_CC)
22708 +PHP_HTTP_API http_request_body *_http_request_body_init_ex(http_request_body *body, int type, void *data, size_t len, zend_bool free ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC TSRMLS_DC);
22710 +#define http_request_body_fill(b, fields, files) _http_request_body_fill((b), (fields), (files) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC TSRMLS_CC)
22711 +PHP_HTTP_API http_request_body *_http_request_body_fill(http_request_body *body, HashTable *fields, HashTable *files ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC TSRMLS_DC);
22713 +#define http_request_body_encode(b, s, l) _http_request_body_encode((b), (s), (l) TSRMLS_CC)
22714 +PHP_HTTP_API STATUS _http_request_body_encode(http_request_body *body, char **buf, size_t *len TSRMLS_DC);
22716 +#define http_request_body_dtor(b) _http_request_body_dtor((b) TSRMLS_CC)
22717 +PHP_HTTP_API void _http_request_body_dtor(http_request_body *body TSRMLS_DC);
22719 +#define http_request_body_free(b) _http_request_body_free((b) TSRMLS_CC)
22720 +PHP_HTTP_API void _http_request_body_free(http_request_body **body TSRMLS_DC);
22726 + * Local variables:
22728 + * c-basic-offset: 4
22730 + * vim600: noet sw=4 ts=4 fdm=marker
22731 + * vim<600: noet sw=4 ts=4
22735 +++ b/ext/http/php_http_request_datashare_api.h
22738 + +--------------------------------------------------------------------+
22740 + +--------------------------------------------------------------------+
22741 + | Redistribution and use in source and binary forms, with or without |
22742 + | modification, are permitted provided that the conditions mentioned |
22743 + | in the accompanying LICENSE file are met. |
22744 + +--------------------------------------------------------------------+
22745 + | Copyright (c) 2004-2010, Michael Wallner <mike@php.net> |
22746 + +--------------------------------------------------------------------+
22749 +/* $Id: php_http_request_datashare_api.h 292841 2009-12-31 08:48:57Z mike $ */
22751 +#ifndef PHP_HTTP_REQUEST_DATASHARE_API_H
22752 +#define PHP_HTTP_REQUEST_DATASHARE_API_H
22753 +#ifdef HTTP_HAVE_CURL
22754 +#ifdef ZEND_ENGINE_2
22757 +typedef struct _http_request_datashare_lock_t {
22760 +} http_request_datashare_lock;
22762 +typedef union _http_request_datashare_handle_t {
22763 + zend_llist *list;
22764 + http_request_datashare_lock *locks;
22765 +} http_request_datashare_handle;
22767 +typedef struct _http_request_datashare_handle_t {
22768 + zend_llist *list;
22769 +} http_request_datashare_handle;
22772 +typedef struct _http_request_datashare_t {
22774 + zend_bool persistent;
22775 + http_request_datashare_handle handle;
22776 +} http_request_datashare;
22778 +#define HTTP_RSHARE_HANDLES(s) ((s)->persistent ? &HTTP_G->request.datashare.handles : (s)->handle.list)
22780 +#define http_request_datashare_global_get _http_request_datashare_global_get
22781 +extern http_request_datashare *_http_request_datashare_global_get(void);
22783 +extern PHP_MINIT_FUNCTION(http_request_datashare);
22784 +extern PHP_MSHUTDOWN_FUNCTION(http_request_datashare);
22785 +extern PHP_RINIT_FUNCTION(http_request_datashare);
22786 +extern PHP_RSHUTDOWN_FUNCTION(http_request_datashare);
22788 +#define http_request_datashare_new() _http_request_datashare_init_ex(NULL, 0 TSRMLS_CC)
22789 +#define http_request_datashare_init(s) _http_request_datashare_init_ex((s), 0 TSRMLS_CC)
22790 +#define http_request_datashare_init_ex(s, p) _http_request_datashare_init_ex((s), (p) TSRMLS_CC)
22791 +PHP_HTTP_API http_request_datashare *_http_request_datashare_init_ex(http_request_datashare *share, zend_bool persistent TSRMLS_DC);
22793 +#define http_request_datashare_attach(s, r) _http_request_datashare_attach((s), (r) TSRMLS_CC)
22794 +PHP_HTTP_API STATUS _http_request_datashare_attach(http_request_datashare *share, zval *request TSRMLS_DC);
22796 +#define http_request_datashare_detach(s, r) _http_request_datashare_detach((s), (r) TSRMLS_CC)
22797 +PHP_HTTP_API STATUS _http_request_datashare_detach(http_request_datashare *share, zval *request TSRMLS_DC);
22799 +#define http_request_datashare_detach_all(s) _http_request_datashare_detach_all((s) TSRMLS_CC)
22800 +PHP_HTTP_API void _http_request_datashare_detach_all(http_request_datashare *share TSRMLS_DC);
22802 +#define http_request_datashare_dtor(s) _http_request_datashare_dtor((s) TSRMLS_CC)
22803 +PHP_HTTP_API void _http_request_datashare_dtor(http_request_datashare *share TSRMLS_DC);
22805 +#define http_request_datashare_free(s) _http_request_datashare_free((s) TSRMLS_CC)
22806 +PHP_HTTP_API void _http_request_datashare_free(http_request_datashare **share TSRMLS_DC);
22808 +#define http_request_datashare_set(s, o, l, e) _http_request_datashare_set((s), (o), (l), (e) TSRMLS_CC)
22809 +PHP_HTTP_API STATUS _http_request_datashare_set(http_request_datashare *share, const char *option, size_t option_len, zend_bool enable TSRMLS_DC);
22817 + * Local variables:
22819 + * c-basic-offset: 4
22821 + * vim600: noet sw=4 ts=4 fdm=marker
22822 + * vim<600: noet sw=4 ts=4
22826 +++ b/ext/http/php_http_request_int.h
22829 + +--------------------------------------------------------------------+
22831 + +--------------------------------------------------------------------+
22832 + | Redistribution and use in source and binary forms, with or without |
22833 + | modification, are permitted provided that the conditions mentioned |
22834 + | in the accompanying LICENSE file are met. |
22835 + +--------------------------------------------------------------------+
22836 + | Copyright (c) 2004-2010, Michael Wallner <mike@php.net> |
22837 + +--------------------------------------------------------------------+
22840 +/* $Id: php_http_request_int.h 292841 2009-12-31 08:48:57Z mike $ */
22842 +#if defined(ZTS) && defined(HTTP_HAVE_SSL)
22844 +# define HTTP_NEED_OPENSSL_TSL
22845 +# include <openssl/crypto.h>
22846 +# else /* !PHP_WIN32 */
22847 +# if defined(HTTP_HAVE_OPENSSL)
22848 +# define HTTP_NEED_OPENSSL_TSL
22849 +# include <openssl/crypto.h>
22850 +# elif defined(HTTP_HAVE_GNUTLS)
22851 +# define HTTP_NEED_GNUTLS_TSL
22852 +# include <gcrypt.h>
22855 + "libcurl was compiled with SSL support, but configure could not determine which" \
22856 + "library was used; thus no SSL crypto locking callbacks will be set, which may " \
22857 + "cause random crashes on SSL requests"
22858 +# endif /* HTTP_HAVE_OPENSSL || HTTP_HAVE_GNUTLS */
22859 +# endif /* PHP_WIN32 */
22860 +#endif /* ZTS && HTTP_HAVE_SSL */
22862 +#define HTTP_CURL_OPT(OPTION, p) curl_easy_setopt((request->ch), OPTION, (p))
22864 +#define HTTP_CURL_OPT_STRING(OPTION, ldiff, obdc) \
22866 + char *K = #OPTION; \
22867 + HTTP_CURL_OPT_STRING_EX(K+lenof("CURLOPT_KEY")+ldiff, OPTION, obdc); \
22869 +#define HTTP_CURL_OPT_STRING_EX(keyname, optname, obdc) \
22870 + if (!strcasecmp(key.str, keyname)) { \
22871 + zval *copy = http_request_option_cache_ex(request, keyname, strlen(keyname)+1, 0, http_zsep(IS_STRING, *param)); \
22873 + HTTP_CHECK_OPEN_BASEDIR(Z_STRVAL_P(copy), return FAILURE); \
22875 + HTTP_CURL_OPT(optname, Z_STRVAL_P(copy)); \
22876 + zval_ptr_dtor(©); \
22879 +#define HTTP_CURL_OPT_LONG(OPTION, ldiff) \
22881 + char *K = #OPTION; \
22882 + HTTP_CURL_OPT_LONG_EX(K+lenof("CURLOPT_KEY")+ldiff, OPTION); \
22884 +#define HTTP_CURL_OPT_LONG_EX(keyname, optname) \
22885 + if (!strcasecmp(key.str, keyname)) { \
22886 + zval *copy = http_zsep(IS_LONG, *param); \
22887 + HTTP_CURL_OPT(optname, Z_LVAL_P(copy)); \
22888 + zval_ptr_dtor(©); \
22893 + * Local variables:
22895 + * c-basic-offset: 4
22897 + * vim600: noet sw=4 ts=4 fdm=marker
22898 + * vim<600: noet sw=4 ts=4
22901 +++ b/ext/http/php_http_request_method_api.h
22904 + +--------------------------------------------------------------------+
22906 + +--------------------------------------------------------------------+
22907 + | Redistribution and use in source and binary forms, with or without |
22908 + | modification, are permitted provided that the conditions mentioned |
22909 + | in the accompanying LICENSE file are met. |
22910 + +--------------------------------------------------------------------+
22911 + | Copyright (c) 2004-2010, Michael Wallner <mike@php.net> |
22912 + +--------------------------------------------------------------------+
22915 +/* $Id: php_http_request_method_api.h 292841 2009-12-31 08:48:57Z mike $ */
22917 +#ifndef PHP_HTTP_REQUEST_METHOD_API_H
22918 +#define PHP_HTTP_REQUEST_METHOD_API_H
22920 +typedef enum _http_request_method_t {
22921 + /* force the enum to be signed */
22922 + HTTP_NEG_REQUEST_METHOD =-1,
22923 + HTTP_NO_REQUEST_METHOD = 0,
22930 + HTTP_OPTIONS = 6,
22932 + HTTP_CONNECT = 8,
22933 + /* WebDAV - RFC 2518 */
22934 + HTTP_PROPFIND = 9,
22935 + HTTP_PROPPATCH = 10,
22940 + HTTP_UNLOCK = 15,
22941 + /* WebDAV Versioning - RFC 3253 */
22942 + HTTP_VERSION_CONTROL = 16,
22943 + HTTP_REPORT = 17,
22944 + HTTP_CHECKOUT = 18,
22945 + HTTP_CHECKIN = 19,
22946 + HTTP_UNCHECKOUT = 20,
22947 + HTTP_MKWORKSPACE = 21,
22948 + HTTP_UPDATE = 22,
22951 + HTTP_BASELINE_CONTROL = 25,
22952 + HTTP_MKACTIVITY = 26,
22953 + /* WebDAV Access Control - RFC 3744 */
22955 + HTTP_MAX_REQUEST_METHOD = 28
22956 +} http_request_method;
22958 +#define HTTP_MIN_REQUEST_METHOD (HTTP_NO_REQUEST_METHOD + 1)
22959 +#define HTTP_STD_REQUEST_METHOD(m) ((m > HTTP_NO_REQUEST_METHOD) && (m < HTTP_MAX_REQUEST_METHOD))
22961 +extern PHP_MINIT_FUNCTION(http_request_method);
22962 +extern PHP_RINIT_FUNCTION(http_request_method);
22963 +extern PHP_RSHUTDOWN_FUNCTION(http_request_method);
22965 +#define http_request_method_name(m) _http_request_method_name((m) TSRMLS_CC)
22966 +PHP_HTTP_API const char *_http_request_method_name(http_request_method m TSRMLS_DC);
22968 +#define http_request_method_exists(u, l, c) _http_request_method_exists((u), (l), (c) TSRMLS_CC)
22969 +PHP_HTTP_API int _http_request_method_exists(int by_name, http_request_method id, const char *name TSRMLS_DC);
22971 +#define http_request_method_register(m, l) _http_request_method_register((m), (l) TSRMLS_CC)
22972 +PHP_HTTP_API int _http_request_method_register(const char *method, int method_name_len TSRMLS_DC);
22974 +#define http_request_method_unregister(mn) _http_request_method_unregister((mn) TSRMLS_CC)
22975 +PHP_HTTP_API STATUS _http_request_method_unregister(int method TSRMLS_DC);
22980 + * Local variables:
22982 + * c-basic-offset: 4
22984 + * vim600: noet sw=4 ts=4 fdm=marker
22985 + * vim<600: noet sw=4 ts=4
22989 +++ b/ext/http/php_http_request_object.h
22992 + +--------------------------------------------------------------------+
22994 + +--------------------------------------------------------------------+
22995 + | Redistribution and use in source and binary forms, with or without |
22996 + | modification, are permitted provided that the conditions mentioned |
22997 + | in the accompanying LICENSE file are met. |
22998 + +--------------------------------------------------------------------+
22999 + | Copyright (c) 2004-2010, Michael Wallner <mike@php.net> |
23000 + +--------------------------------------------------------------------+
23003 +/* $Id: php_http_request_object.h 292841 2009-12-31 08:48:57Z mike $ */
23005 +#ifndef PHP_HTTP_REQUEST_OBJECT_H
23006 +#define PHP_HTTP_REQUEST_OBJECT_H
23007 +#ifdef HTTP_HAVE_CURL
23008 +#ifdef ZEND_ENGINE_2
23010 +#include "php_http_request_api.h"
23011 +#include "php_http_request_pool_api.h"
23012 +#include "php_http_request_datashare_api.h"
23014 +typedef struct _http_request_object_t {
23016 + http_request *request;
23017 + http_request_pool *pool;
23018 + http_request_datashare *share;
23019 +} http_request_object;
23021 +extern zend_class_entry *http_request_object_ce;
23022 +extern zend_function_entry http_request_object_fe[];
23024 +extern PHP_MINIT_FUNCTION(http_request_object);
23026 +#define http_request_object_new(ce) _http_request_object_new((ce) TSRMLS_CC)
23027 +extern zend_object_value _http_request_object_new(zend_class_entry *ce TSRMLS_DC);
23028 +#define http_request_object_new_ex(ce, ch, ptr) _http_request_object_new_ex((ce), (ch), (ptr) TSRMLS_CC)
23029 +extern zend_object_value _http_request_object_new_ex(zend_class_entry *ce, CURL *ch, http_request_object **ptr TSRMLS_DC);
23030 +#define http_request_object_clone(zv) _http_request_object_clone_obj((zv) TSRMLS_CC)
23031 +extern zend_object_value _http_request_object_clone_obj(zval *zobject TSRMLS_DC);
23032 +#define http_request_object_free(o) _http_request_object_free((o) TSRMLS_CC)
23033 +extern void _http_request_object_free(zend_object *object TSRMLS_DC);
23035 +#define http_request_object_requesthandler(req, this) _http_request_object_requesthandler((req), (this) TSRMLS_CC)
23036 +extern STATUS _http_request_object_requesthandler(http_request_object *obj, zval *this_ptr TSRMLS_DC);
23037 +#define http_request_object_responsehandler(req, this) _http_request_object_responsehandler((req), (this) TSRMLS_CC)
23038 +extern STATUS _http_request_object_responsehandler(http_request_object *obj, zval *this_ptr TSRMLS_DC);
23040 +PHP_METHOD(HttpRequest, __construct);
23041 +PHP_METHOD(HttpRequest, setOptions);
23042 +PHP_METHOD(HttpRequest, getOptions);
23043 +PHP_METHOD(HttpRequest, addSslOptions);
23044 +PHP_METHOD(HttpRequest, setSslOptions);
23045 +PHP_METHOD(HttpRequest, getSslOptions);
23046 +PHP_METHOD(HttpRequest, addHeaders);
23047 +PHP_METHOD(HttpRequest, getHeaders);
23048 +PHP_METHOD(HttpRequest, setHeaders);
23049 +PHP_METHOD(HttpRequest, addCookies);
23050 +PHP_METHOD(HttpRequest, getCookies);
23051 +PHP_METHOD(HttpRequest, setCookies);
23052 +PHP_METHOD(HttpRequest, enableCookies);
23053 +PHP_METHOD(HttpRequest, resetCookies);
23054 +PHP_METHOD(HttpRequest, flushCookies);
23055 +PHP_METHOD(HttpRequest, setMethod);
23056 +PHP_METHOD(HttpRequest, getMethod);
23057 +PHP_METHOD(HttpRequest, setUrl);
23058 +PHP_METHOD(HttpRequest, getUrl);
23059 +PHP_METHOD(HttpRequest, setContentType);
23060 +PHP_METHOD(HttpRequest, getContentType);
23061 +PHP_METHOD(HttpRequest, setQueryData);
23062 +PHP_METHOD(HttpRequest, getQueryData);
23063 +PHP_METHOD(HttpRequest, addQueryData);
23064 +PHP_METHOD(HttpRequest, setPostFields);
23065 +PHP_METHOD(HttpRequest, getPostFields);
23066 +PHP_METHOD(HttpRequest, addPostFields);
23067 +PHP_METHOD(HttpRequest, getBody);
23068 +PHP_METHOD(HttpRequest, setBody);
23069 +PHP_METHOD(HttpRequest, addBody);
23070 +PHP_METHOD(HttpRequest, addPostFile);
23071 +PHP_METHOD(HttpRequest, setPostFiles);
23072 +PHP_METHOD(HttpRequest, getPostFiles);
23073 +PHP_METHOD(HttpRequest, setPutFile);
23074 +PHP_METHOD(HttpRequest, getPutFile);
23075 +PHP_METHOD(HttpRequest, getPutData);
23076 +PHP_METHOD(HttpRequest, setPutData);
23077 +PHP_METHOD(HttpRequest, addPutData);
23078 +PHP_METHOD(HttpRequest, send);
23079 +PHP_METHOD(HttpRequest, getResponseData);
23080 +PHP_METHOD(HttpRequest, getResponseHeader);
23081 +PHP_METHOD(HttpRequest, getResponseCookies);
23082 +PHP_METHOD(HttpRequest, getResponseCode);
23083 +PHP_METHOD(HttpRequest, getResponseStatus);
23084 +PHP_METHOD(HttpRequest, getResponseBody);
23085 +PHP_METHOD(HttpRequest, getResponseInfo);
23086 +PHP_METHOD(HttpRequest, getResponseMessage);
23087 +PHP_METHOD(HttpRequest, getRawResponseMessage);
23088 +PHP_METHOD(HttpRequest, getRequestMessage);
23089 +PHP_METHOD(HttpRequest, getRawRequestMessage);
23090 +PHP_METHOD(HttpRequest, getHistory);
23091 +PHP_METHOD(HttpRequest, clearHistory);
23092 +PHP_METHOD(HttpRequest, getMessageClass);
23093 +PHP_METHOD(HttpRequest, setMessageClass);
23094 +PHP_METHOD(HttpRequest, factory);
23101 + * Local variables:
23103 + * c-basic-offset: 4
23105 + * vim600: noet sw=4 ts=4 fdm=marker
23106 + * vim<600: noet sw=4 ts=4
23110 +++ b/ext/http/php_http_request_pool_api.h
23113 + +--------------------------------------------------------------------+
23115 + +--------------------------------------------------------------------+
23116 + | Redistribution and use in source and binary forms, with or without |
23117 + | modification, are permitted provided that the conditions mentioned |
23118 + | in the accompanying LICENSE file are met. |
23119 + +--------------------------------------------------------------------+
23120 + | Copyright (c) 2004-2010, Michael Wallner <mike@php.net> |
23121 + +--------------------------------------------------------------------+
23124 +/* $Id: php_http_request_pool_api.h 292841 2009-12-31 08:48:57Z mike $ */
23126 +#ifndef PHP_HTTP_REQUEST_POOL_API_H
23127 +#define PHP_HTTP_REQUEST_POOL_API_H
23128 +#ifdef HTTP_HAVE_CURL
23129 +#ifdef ZEND_ENGINE_2
23131 +typedef struct _http_request_pool_t {
23133 + zend_llist finished;
23134 + zend_llist handles;
23139 +#ifdef HTTP_HAVE_EVENT
23140 + struct event *timeout;
23141 + unsigned useevents:1;
23142 + unsigned runsocket:1;
23144 +} http_request_pool;
23146 +typedef int (*http_request_pool_apply_func)(http_request_pool *pool, zval *request);
23147 +typedef int (*http_request_pool_apply_with_arg_func)(http_request_pool *pool, zval *request, void *arg);
23149 +PHP_MINIT_FUNCTION(http_request_pool);
23150 +#ifdef HTTP_HAVE_EVENT
23151 +PHP_RINIT_FUNCTION(http_request_pool);
23154 +#define http_request_pool_timeout _http_request_pool_timeout
23155 +extern struct timeval *_http_request_pool_timeout(http_request_pool *pool, struct timeval *timeout);
23157 +#define http_request_pool_responsehandler _http_request_pool_responsehandler
23158 +extern void _http_request_pool_responsehandler(http_request_pool *pool);
23160 +#define http_request_pool_apply_responsehandler _http_request_pool_responsehandler
23161 +extern int _http_request_pool_apply_responsehandler(http_request_pool *pool, zval *req, void *ch);
23163 +#define http_request_pool_init(p) _http_request_pool_init((p) TSRMLS_CC)
23164 +PHP_HTTP_API http_request_pool *_http_request_pool_init(http_request_pool *pool TSRMLS_DC);
23166 +#define http_request_pool_attach(p, r) _http_request_pool_attach((p), (r))
23167 +PHP_HTTP_API STATUS _http_request_pool_attach(http_request_pool *pool, zval *request);
23169 +#define http_request_pool_detach(p, r) _http_request_pool_detach((p), (r))
23170 +PHP_HTTP_API STATUS _http_request_pool_detach(http_request_pool *pool, zval *request);
23172 +#define http_request_pool_apply(p, f) _http_request_pool_apply((p), (f))
23173 +PHP_HTTP_API void _http_request_pool_apply(http_request_pool *pool, http_request_pool_apply_func cb);
23175 +#define http_request_pool_apply_with_arg(p, f, a) _http_request_pool_apply_with_arg((p), (f), (a))
23176 +PHP_HTTP_API void _http_request_pool_apply_with_arg(http_request_pool *pool, http_request_pool_apply_with_arg_func cb, void *arg);
23178 +#define http_request_pool_detach_all(p) _http_request_pool_detach_all((p))
23179 +PHP_HTTP_API void _http_request_pool_detach_all(http_request_pool *pool);
23181 +#define http_request_pool_send(p) _http_request_pool_send((p))
23182 +PHP_HTTP_API STATUS _http_request_pool_send(http_request_pool *pool);
23184 +#define http_request_pool_select _http_request_pool_select
23185 +PHP_HTTP_API STATUS _http_request_pool_select(http_request_pool *pool);
23187 +#define http_request_pool_select_ex _http_request_pool_select_ex
23188 +PHP_HTTP_API STATUS _http_request_pool_select_ex(http_request_pool *pool, struct timeval *custom_timeout);
23190 +#define http_request_pool_perform(p) _http_request_pool_perform((p))
23191 +PHP_HTTP_API int _http_request_pool_perform(http_request_pool *pool);
23193 +#define http_request_pool_dtor(p) _http_request_pool_dtor((p))
23194 +PHP_HTTP_API void _http_request_pool_dtor(http_request_pool *pool);
23201 + * Local variables:
23203 + * c-basic-offset: 4
23205 + * vim600: noet sw=4 ts=4 fdm=marker
23206 + * vim<600: noet sw=4 ts=4
23210 +++ b/ext/http/php_http_requestdatashare_object.h
23213 + +--------------------------------------------------------------------+
23215 + +--------------------------------------------------------------------+
23216 + | Redistribution and use in source and binary forms, with or without |
23217 + | modification, are permitted provided that the conditions mentioned |
23218 + | in the accompanying LICENSE file are met. |
23219 + +--------------------------------------------------------------------+
23220 + | Copyright (c) 2004-2010, Michael Wallner <mike@php.net> |
23221 + +--------------------------------------------------------------------+
23224 +/* $Id: php_http_requestdatashare_object.h 292841 2009-12-31 08:48:57Z mike $ */
23226 +#ifndef PHP_HTTP_REQUEST_DATASHARE_OBJECT_H
23227 +#define PHP_HTTP_REQUEST_DATASHARE_OBJECT_H
23228 +#ifdef HTTP_HAVE_CURL
23229 +#ifdef ZEND_ENGINE_2
23231 +typedef struct _http_requestdatashare_object_t {
23233 + http_request_datashare *share;
23234 +} http_requestdatashare_object;
23236 +extern zend_class_entry *http_requestdatashare_object_ce;
23237 +extern zend_function_entry http_requestdatashare_object_fe[];
23239 +extern PHP_MINIT_FUNCTION(http_requestdatashare_object);
23241 +#define http_requestdatashare_object_new(ce) _http_requestdatashare_object_new((ce) TSRMLS_CC)
23242 +extern zend_object_value _http_requestdatashare_object_new(zend_class_entry *ce TSRMLS_DC);
23243 +#define http_requestdatashare_object_new_ex(ce, s, ptr) _http_requestdatashare_object_new_ex((ce), (s), (ptr) TSRMLS_CC)
23244 +extern zend_object_value _http_requestdatashare_object_new_ex(zend_class_entry *ce, http_request_datashare *share, http_requestdatashare_object **ptr TSRMLS_DC);
23245 +#define http_requestdatashare_object_free(o) _http_requestdatashare_object_free((o) TSRMLS_CC)
23246 +extern void _http_requestdatashare_object_free(zend_object *object TSRMLS_DC);
23248 +PHP_METHOD(HttpRequestDataShare, __destruct);
23249 +PHP_METHOD(HttpRequestDataShare, count);
23250 +PHP_METHOD(HttpRequestDataShare, attach);
23251 +PHP_METHOD(HttpRequestDataShare, detach);
23252 +PHP_METHOD(HttpRequestDataShare, reset);
23253 +PHP_METHOD(HttpRequestDataShare, factory);
23255 +PHP_METHOD(HttpRequestDataShare, singleton);
23263 + * Local variables:
23265 + * c-basic-offset: 4
23267 + * vim600: noet sw=4 ts=4 fdm=marker
23268 + * vim<600: noet sw=4 ts=4
23272 +++ b/ext/http/php_http_requestpool_object.h
23275 + +--------------------------------------------------------------------+
23277 + +--------------------------------------------------------------------+
23278 + | Redistribution and use in source and binary forms, with or without |
23279 + | modification, are permitted provided that the conditions mentioned |
23280 + | in the accompanying LICENSE file are met. |
23281 + +--------------------------------------------------------------------+
23282 + | Copyright (c) 2004-2010, Michael Wallner <mike@php.net> |
23283 + +--------------------------------------------------------------------+
23286 +/* $Id: php_http_requestpool_object.h 292841 2009-12-31 08:48:57Z mike $ */
23288 +#ifndef PHP_HTTP_REQUESTPOOL_OBJECT_H
23289 +#define PHP_HTTP_REQUESTPOOL_OBJECT_H
23290 +#ifdef HTTP_HAVE_CURL
23291 +#ifdef ZEND_ENGINE_2
23293 +typedef struct _http_requestpool_object_t {
23295 + http_request_pool pool;
23299 +} http_requestpool_object;
23301 +extern zend_class_entry *http_requestpool_object_ce;
23302 +extern zend_function_entry http_requestpool_object_fe[];
23304 +extern PHP_MINIT_FUNCTION(http_requestpool_object);
23306 +#define http_requestpool_object_new(ce) _http_requestpool_object_new(ce TSRMLS_CC)
23307 +extern zend_object_value _http_requestpool_object_new(zend_class_entry *ce TSRMLS_DC);
23308 +#define http_requestpool_object_free(o) _http_requestpool_object_free(o TSRMLS_CC)
23309 +extern void _http_requestpool_object_free(zend_object *object TSRMLS_DC);
23311 +PHP_METHOD(HttpRequestPool, __construct);
23312 +PHP_METHOD(HttpRequestPool, __destruct);
23313 +PHP_METHOD(HttpRequestPool, attach);
23314 +PHP_METHOD(HttpRequestPool, detach);
23315 +PHP_METHOD(HttpRequestPool, send);
23316 +PHP_METHOD(HttpRequestPool, reset);
23317 +PHP_METHOD(HttpRequestPool, socketPerform);
23318 +PHP_METHOD(HttpRequestPool, socketSelect);
23319 +PHP_METHOD(HttpRequestPool, valid);
23320 +PHP_METHOD(HttpRequestPool, current);
23321 +PHP_METHOD(HttpRequestPool, key);
23322 +PHP_METHOD(HttpRequestPool, next);
23323 +PHP_METHOD(HttpRequestPool, rewind);
23324 +PHP_METHOD(HttpRequestPool, count);
23325 +PHP_METHOD(HttpRequestPool, getAttachedRequests);
23326 +PHP_METHOD(HttpRequestPool, getFinishedRequests);
23327 +PHP_METHOD(HttpRequestPool, enablePipelining);
23328 +PHP_METHOD(HttpRequestPool, enableEvents);
23335 + * Local variables:
23337 + * c-basic-offset: 4
23339 + * vim600: noet sw=4 ts=4 fdm=marker
23340 + * vim<600: noet sw=4 ts=4
23344 +++ b/ext/http/php_http_response_object.h
23347 + +--------------------------------------------------------------------+
23349 + +--------------------------------------------------------------------+
23350 + | Redistribution and use in source and binary forms, with or without |
23351 + | modification, are permitted provided that the conditions mentioned |
23352 + | in the accompanying LICENSE file are met. |
23353 + +--------------------------------------------------------------------+
23354 + | Copyright (c) 2004-2010, Michael Wallner <mike@php.net> |
23355 + +--------------------------------------------------------------------+
23358 +/* $Id: php_http_response_object.h 292841 2009-12-31 08:48:57Z mike $ */
23360 +#ifndef PHP_HTTP_RESPONSE_OBJECT_H
23361 +#define PHP_HTTP_RESPONSE_OBJECT_H
23362 +#ifdef ZEND_ENGINE_2
23365 +extern zend_class_entry *http_response_object_ce;
23366 +extern zend_function_entry http_response_object_fe[];
23368 +extern PHP_MINIT_FUNCTION(http_response_object);
23370 +PHP_METHOD(HttpResponse, setHeader);
23371 +PHP_METHOD(HttpResponse, getHeader);
23372 +PHP_METHOD(HttpResponse, setETag);
23373 +PHP_METHOD(HttpResponse, getETag);
23374 +PHP_METHOD(HttpResponse, setLastModified);
23375 +PHP_METHOD(HttpResponse, getLastModified);
23376 +PHP_METHOD(HttpResponse, setContentDisposition);
23377 +PHP_METHOD(HttpResponse, getContentDisposition);
23378 +PHP_METHOD(HttpResponse, setContentType);
23379 +PHP_METHOD(HttpResponse, getContentType);
23380 +PHP_METHOD(HttpResponse, guessContentType);
23381 +PHP_METHOD(HttpResponse, setCache);
23382 +PHP_METHOD(HttpResponse, getCache);
23383 +PHP_METHOD(HttpResponse, setCacheControl);
23384 +PHP_METHOD(HttpResponse, getCacheControl);
23385 +PHP_METHOD(HttpResponse, setGzip);
23386 +PHP_METHOD(HttpResponse, getGzip);
23387 +PHP_METHOD(HttpResponse, setThrottleDelay);
23388 +PHP_METHOD(HttpResponse, getThrottleDelay);
23389 +PHP_METHOD(HttpResponse, setBufferSize);
23390 +PHP_METHOD(HttpResponse, getBufferSize);
23391 +PHP_METHOD(HttpResponse, setData);
23392 +PHP_METHOD(HttpResponse, getData);
23393 +PHP_METHOD(HttpResponse, setFile);
23394 +PHP_METHOD(HttpResponse, getFile);
23395 +PHP_METHOD(HttpResponse, setStream);
23396 +PHP_METHOD(HttpResponse, getStream);
23397 +PHP_METHOD(HttpResponse, send);
23398 +PHP_METHOD(HttpResponse, capture);
23405 + * Local variables:
23407 + * c-basic-offset: 4
23409 + * vim600: noet sw=4 ts=4 fdm=marker
23410 + * vim<600: noet sw=4 ts=4
23414 +++ b/ext/http/php_http_send_api.h
23417 + +--------------------------------------------------------------------+
23419 + +--------------------------------------------------------------------+
23420 + | Redistribution and use in source and binary forms, with or without |
23421 + | modification, are permitted provided that the conditions mentioned |
23422 + | in the accompanying LICENSE file are met. |
23423 + +--------------------------------------------------------------------+
23424 + | Copyright (c) 2004-2010, Michael Wallner <mike@php.net> |
23425 + +--------------------------------------------------------------------+
23428 +/* $Id: php_http_send_api.h 292841 2009-12-31 08:48:57Z mike $ */
23430 +#ifndef PHP_HTTP_SEND_API_H
23431 +#define PHP_HTTP_SEND_API_H
23433 +typedef enum _http_send_mode_t {
23438 +#define HTTP_REDIRECT 0L
23439 +#define HTTP_REDIRECT_PERM 301L
23440 +#define HTTP_REDIRECT_FOUND 302L
23441 +#define HTTP_REDIRECT_POST 303L
23442 +#define HTTP_REDIRECT_PROXY 305L
23443 +#define HTTP_REDIRECT_TEMP 307L
23445 +extern PHP_MINIT_FUNCTION(http_send);
23447 +#define http_send_status(s) sapi_header_op(SAPI_HEADER_SET_STATUS, (void *) (long) (s) TSRMLS_CC)
23448 +#define http_send_header(n, v, r) _http_send_header_ex((n), strlen(n), (v), strlen(v), (r), NULL TSRMLS_CC)
23449 +#define http_send_header_ex(n, nl, v, vl, r, s) _http_send_header_ex((n), (nl), (v), (vl), (r), (s) TSRMLS_CC)
23450 +PHP_HTTP_API STATUS _http_send_header_ex(const char *name, size_t name_len, const char *value, size_t value_len, zend_bool replace, char **sent_header TSRMLS_DC);
23451 +#define http_send_header_string(h) _http_send_status_header_ex(0, (h), strlen(h), 1 TSRMLS_CC)
23452 +#define http_send_header_string_ex(h, l, r) _http_send_status_header_ex(0, (h), (l), (r) TSRMLS_CC)
23453 +#define http_send_status_header(s, h) _http_send_status_header_ex((s), (h), (h)?strlen(h):0, 1 TSRMLS_CC)
23454 +#define http_send_status_header_ex(s, h, l, r) _http_send_status_header_ex((s), (h), (l), (r) TSRMLS_CC)
23455 +PHP_HTTP_API STATUS _http_send_status_header_ex(int status, const char *header, size_t header_len, zend_bool replace TSRMLS_DC);
23457 +#define http_send_header_zval(n, z, r) http_send_header_zval_ex((n), strlen(n), (z), (r))
23458 +#define http_send_header_zval_ex(n, l, z, r) _http_send_header_zval_ex((n), (l), (z), (r) TSRMLS_CC)
23459 +PHP_HTTP_API void _http_send_header_zval_ex(const char *name, size_t name_len, zval **val, zend_bool replace TSRMLS_DC);
23461 +#define http_hide_header(h) http_hide_header_ex((h), strlen(h))
23462 +#define http_hide_header_ex(h, l) _http_hide_header_ex((h), (l) TSRMLS_CC)
23463 +PHP_HTTP_API void _http_hide_header_ex(const char *name, size_t name_len TSRMLS_DC);
23465 +#define http_send_last_modified(t) _http_send_last_modified_ex((t), NULL TSRMLS_CC)
23466 +#define http_send_last_modified_ex(t, s) _http_send_last_modified_ex((t), (s) TSRMLS_CC)
23467 +PHP_HTTP_API STATUS _http_send_last_modified_ex(time_t t, char **sent_header TSRMLS_DC);
23469 +#define http_send_etag(e, l) _http_send_etag_ex((e), (l), NULL TSRMLS_CC)
23470 +#define http_send_etag_ex(e, l, s) _http_send_etag_ex((e), (l), (s) TSRMLS_CC)
23471 +PHP_HTTP_API STATUS _http_send_etag_ex(const char *etag, size_t etag_len, char **sent_header TSRMLS_DC);
23473 +#define http_send_cache_control(cc, cl) http_send_header_ex("Cache-Control", lenof("Cache-Control"), (cc), (cl), 1, NULL)
23475 +#define http_send_content_type(c, l) _http_send_content_type((c), (l) TSRMLS_CC)
23476 +PHP_HTTP_API STATUS _http_send_content_type(const char *content_type, size_t ct_len TSRMLS_DC);
23478 +#define http_send_content_disposition(f, l, i) _http_send_content_disposition((f), (l), (i) TSRMLS_CC)
23479 +PHP_HTTP_API STATUS _http_send_content_disposition(const char *filename, size_t f_len, zend_bool send_inline TSRMLS_DC);
23481 +#define http_send_data(d, l) http_send((d), (l), SEND_DATA)
23482 +#define http_send_data_ex(d, l, nc) http_send_ex((d), (l), SEND_DATA, (nc))
23483 +#define http_send(d, s, m) _http_send_ex((d), (s), (m), 0 TSRMLS_CC)
23484 +#define http_send_ex(d, s, m, nc) _http_send_ex((d), (s), (m), (nc) TSRMLS_CC)
23485 +PHP_HTTP_API STATUS _http_send_ex(const void *data, size_t data_size, http_send_mode mode, zend_bool no_cache TSRMLS_DC);
23487 +#define http_send_file(f) http_send_stream_ex(php_stream_open_wrapper_ex(f, "rb", REPORT_ERRORS|ENFORCE_SAFE_MODE, NULL, HTTP_DEFAULT_STREAM_CONTEXT), 1, 0)
23488 +#define http_send_file_ex(f, nc) http_send_stream_ex(php_stream_open_wrapper_ex(f, "rb", REPORT_ERRORS|ENFORCE_SAFE_MODE, NULL, HTTP_DEFAULT_STREAM_CONTEXT), 1, (nc))
23489 +#define http_send_stream(s) http_send_stream_ex((s), 0, 0)
23490 +#define http_send_stream_ex(s, c, nc) _http_send_stream_ex((s), (c), (nc) TSRMLS_CC)
23491 +PHP_HTTP_API STATUS _http_send_stream_ex(php_stream *s, zend_bool close_stream, zend_bool no_cache TSRMLS_DC);
23493 +#define http_guess_content_type(mf, mm, d, l, m) _http_guess_content_type((mf), (mm), (d), (l), (m) TSRMLS_CC)
23494 +PHP_HTTP_API char *_http_guess_content_type(const char *magic_file, long magic_mode, void *data_ptr, size_t data_len, http_send_mode mode TSRMLS_DC);
23499 + * Local variables:
23501 + * c-basic-offset: 4
23503 + * vim600: noet sw=4 ts=4 fdm=marker
23504 + * vim<600: noet sw=4 ts=4
23508 +++ b/ext/http/php_http_std_defs.h
23511 + +--------------------------------------------------------------------+
23513 + +--------------------------------------------------------------------+
23514 + | Redistribution and use in source and binary forms, with or without |
23515 + | modification, are permitted provided that the conditions mentioned |
23516 + | in the accompanying LICENSE file are met. |
23517 + +--------------------------------------------------------------------+
23518 + | Copyright (c) 2004-2010, Michael Wallner <mike@php.net> |
23519 + +--------------------------------------------------------------------+
23522 +/* $Id: php_http_std_defs.h 323304 2012-02-17 21:13:24Z mike $ */
23524 +#ifndef PHP_HTTP_STD_DEFS_H
23525 +#define PHP_HTTP_STD_DEFS_H
23527 +#if defined(PHP_WIN32)
23528 +# if defined(HTTP_EXPORTS)
23529 +# define PHP_HTTP_API __declspec(dllexport)
23530 +# elif defined(COMPILE_DL_HTTP)
23531 +# define PHP_HTTP_API __declspec(dllimport)
23533 +# define PHP_HTTP_API
23536 +# define PHP_HTTP_API
23539 +/* make functions that return SUCCESS|FAILURE more obvious */
23540 +typedef int STATUS;
23543 +#define lenof(S) (sizeof(S) - 1)
23546 +# define MIN(a,b) (a<b?a:b)
23549 +# define MAX(a,b) (a>b?a:b)
23554 +# define STR_SET(STR, SET) \
23561 +#define STR_PTR(s) (s?s:"")
23563 +#define INIT_ZARR(zv, ht) \
23565 + INIT_PZVAL(&(zv)); \
23566 + Z_TYPE(zv) = IS_ARRAY; \
23567 + Z_ARRVAL(zv) = (ht); \
23570 +/* return bool (v == SUCCESS) */
23571 +#define RETVAL_SUCCESS(v) RETVAL_BOOL(SUCCESS == (v))
23572 +#define RETURN_SUCCESS(v) RETURN_BOOL(SUCCESS == (v))
23573 +/* return object(values) */
23574 +#define RETVAL_OBJECT(o, addref) \
23575 + RETVAL_OBJVAL((o)->value.obj, addref)
23576 +#define RETURN_OBJECT(o, addref) \
23577 + RETVAL_OBJECT(o, addref); \
23579 +#define RETVAL_OBJVAL(ov, addref) \
23580 + ZVAL_OBJVAL(return_value, ov, addref)
23581 +#define RETURN_OBJVAL(ov, addref) \
23582 + RETVAL_OBJVAL(ov, addref); \
23584 +#define ZVAL_OBJVAL(zv, ov, addref) \
23585 + (zv)->type = IS_OBJECT; \
23586 + (zv)->value.obj = (ov);\
23587 + if (addref && Z_OBJ_HT_P(zv)->add_ref) { \
23588 + Z_OBJ_HT_P(zv)->add_ref((zv) TSRMLS_CC); \
23590 +/* return property */
23591 +#define RETVAL_PROP(n) RETVAL_PROP_EX(getThis(), n)
23592 +#define RETURN_PROP(n) RETURN_PROP_EX(getThis(), n)
23593 +#define RETVAL_PROP_EX(this, n) \
23595 + zval *__prop = zend_read_property(THIS_CE, this, ZEND_STRS(#n)-1, 0 TSRMLS_CC); \
23596 + RETVAL_ZVAL(__prop, 1, 0); \
23598 +#define RETURN_PROP_EX(this, n) \
23600 + zval *__prop = zend_read_property(THIS_CE, this, ZEND_STRS(#n)-1, 0 TSRMLS_CC); \
23601 + RETURN_ZVAL(__prop, 1, 0); \
23604 +/* function accepts no args */
23605 +#define NO_ARGS zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "");
23608 +#define HTTP_CRLF "\r\n"
23610 +/* default cache control */
23611 +#define HTTP_DEFAULT_CACHECONTROL "private, must-revalidate, max-age=0"
23613 +/* max URL length */
23614 +#define HTTP_URL_MAXLEN 4096
23616 +/* max request method length */
23617 +#define HTTP_REQUEST_METHOD_MAXLEN 31
23619 +/* def URL arg separator */
23620 +#define HTTP_URL_ARGSEP "&"
23622 +/* send buffer size */
23623 +#define HTTP_SENDBUF_SIZE 40960
23625 +/* CURL buffer size */
23626 +#define HTTP_CURLBUF_SIZE 16384
23628 +/* known methods */
23629 +#define HTTP_KNOWN_METHODS \
23631 + "GET, HEAD, POST, PUT, DELETE, OPTIONS, TRACE, CONNECT, " \
23632 + /* WebDAV - RFC 2518 */ \
23633 + "PROPFIND, PROPPATCH, MKCOL, COPY, MOVE, LOCK, UNLOCK, " \
23634 + /* WebDAV Versioning - RFC 3253 */ \
23635 + "VERSION-CONTROL, REPORT, CHECKOUT, CHECKIN, UNCHECKOUT, " \
23636 + "MKWORKSPACE, UPDATE, LABEL, MERGE, BASELINE-CONTROL, MKACTIVITY, " \
23637 + /* WebDAV Access Control - RFC 3744 */ \
23641 +#ifdef ZEND_ENGINE_2
23642 +# include "ext/standard/file.h"
23643 +# define HTTP_DEFAULT_STREAM_CONTEXT FG(default_context)
23645 +# define HTTP_DEFAULT_STREAM_CONTEXT NULL
23648 +#define HTTP_PHP_INI_ENTRY(entry, default, scope, updater, global) \
23649 + STD_PHP_INI_ENTRY(entry, default, scope, updater, global, zend_http_globals, http_globals)
23650 +#define HTTP_PHP_INI_ENTRY_EX(entry, default, scope, updater, displayer, global) \
23651 + STD_PHP_INI_ENTRY_EX(entry, default, scope, updater, global, zend_http_globals, http_globals, displayer)
23654 +#define HTTP_LONG_CONSTANT(name, const) REGISTER_LONG_CONSTANT(name, const, CONST_CS | CONST_PERSISTENT)
23656 +/* {{{ objects & properties */
23657 +#ifdef ZEND_ENGINE_2
23659 +# define HTTP_STATIC_ME_ALIAS(me, al, ai) ZEND_FENTRY(me, ZEND_FN(al), ai, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
23661 +# define HTTP_REGISTER_CLASS_EX(classname, name, parent, flags) \
23663 + zend_class_entry ce; \
23664 + memset(&ce, 0, sizeof(zend_class_entry)); \
23665 + INIT_CLASS_ENTRY(ce, #classname, name## _fe); \
23666 + ce.create_object = _ ##name## _new; \
23667 + name## _ce = zend_register_internal_class_ex(&ce, parent, NULL TSRMLS_CC); \
23668 + name## _ce->ce_flags |= flags; \
23669 + memcpy(& name## _handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); \
23672 +# define HTTP_REGISTER_CLASS(classname, name, parent, flags) \
23674 + zend_class_entry ce; \
23675 + memset(&ce, 0, sizeof(zend_class_entry)); \
23676 + INIT_CLASS_ENTRY(ce, #classname, name## _fe); \
23677 + ce.create_object = NULL; \
23678 + name## _ce = zend_register_internal_class_ex(&ce, parent, NULL TSRMLS_CC); \
23679 + name## _ce->ce_flags |= flags; \
23682 +# define HTTP_REGISTER_EXCEPTION(classname, cename, parent) \
23684 + zend_class_entry ce; \
23685 + memset(&ce, 0, sizeof(zend_class_entry)); \
23686 + INIT_CLASS_ENTRY(ce, #classname, NULL); \
23687 + ce.create_object = NULL; \
23688 + cename = zend_register_internal_class_ex(&ce, parent, NULL TSRMLS_CC); \
23691 +# define getObject(t, o) getObjectEx(t, o, getThis())
23692 +# define getObjectEx(t, o, v) t * o = ((t *) zend_object_store_get_object(v TSRMLS_CC))
23693 +# define putObject(t, o) zend_objects_store_put(o, (zend_objects_store_dtor_t) zend_objects_destroy_object, (zend_objects_free_object_storage_t) _ ##t## _free, NULL TSRMLS_CC);
23694 +# if defined(ZEND_ENGINE_2_4)
23695 +# define freeObject(o) \
23696 + zend_object_std_dtor(o TSRMLS_CC); \
23698 +# elif !defined(WONKY)
23699 +# define freeObject(o) \
23700 + if (OBJ_GUARDS(o)) { \
23701 + zend_hash_destroy(OBJ_GUARDS(o)); \
23702 + FREE_HASHTABLE(OBJ_GUARDS(o)); \
23704 + if (OBJ_PROP(o)) { \
23705 + zend_hash_destroy(OBJ_PROP(o)); \
23706 + FREE_HASHTABLE(OBJ_PROP(o)); \
23710 +# define freeObject(o) \
23711 + if (OBJ_PROP(o)) { \
23712 + zend_hash_destroy(OBJ_PROP(o)); \
23713 + FREE_HASHTABLE(OBJ_PROP(o)); \
23717 +# define OBJ_PROP(o) (o)->zo.properties
23718 +# define OBJ_GUARDS(o) (o)->zo.guards
23720 +# define ACC_PROP_PRIVATE(ce, flags) ((flags & ZEND_ACC_PRIVATE) && (EG(scope) && ce == EG(scope))
23721 +# define ACC_PROP_PROTECTED(ce, flags) ((flags & ZEND_ACC_PROTECTED) && (zend_check_protected(ce, EG(scope))))
23722 +# define ACC_PROP_PUBLIC(flags) (flags & ZEND_ACC_PUBLIC)
23723 +# define ACC_PROP(ce, flags) (ACC_PROP_PUBLIC(flags) || ACC_PROP_PRIVATE(ce, flags) || ACC_PROP_PROTECTED(ce, flags))
23725 +# define SET_EH_THROW_HTTP() SET_EH_THROW_EX(http_exception_get_default())
23726 +# define SET_EH_THROW_EX(ex) php_set_error_handling(EH_THROW, ex TSRMLS_CC)
23727 +# define SET_EH_NORMAL() php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC)
23729 +#endif /* ZEND_ENGINE_2 */
23732 +#ifdef ZEND_ENGINE_2
23733 +# define with_error_handling(eh, ec) \
23735 + error_handling_t __eh = GLOBAL_ERROR_HANDLING; \
23736 + zend_class_entry *__ec= GLOBAL_EXCEPTION_CLASS; \
23737 + php_set_error_handling(eh, ec TSRMLS_CC);
23738 +# define end_error_handling() \
23739 + php_set_error_handling(__eh, __ec TSRMLS_CC); \
23742 +# define with_error_handling(eh, ec)
23743 +# define end_error_handling()
23746 +#if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 2) || PHP_MAJOR_VERSION > 5
23747 +# define ZEND_EXCEPTION_GET_DEFAULT() zend_exception_get_default(TSRMLS_C)
23749 +# define ZEND_EXCEPTION_GET_DEFAULT() zend_exception_get_default()
23753 +# define E_THROW 0
23755 +#ifdef ZEND_ENGINE_2
23756 +# define HE_THROW E_THROW TSRMLS_CC
23757 +# define HE_NOTICE (HTTP_G->only_exceptions ? E_THROW : E_NOTICE) TSRMLS_CC
23758 +# define HE_WARNING (HTTP_G->only_exceptions ? E_THROW : E_WARNING) TSRMLS_CC
23759 +# define HE_ERROR (HTTP_G->only_exceptions ? E_THROW : E_ERROR) TSRMLS_CC
23761 +# define HE_THROW E_WARNING TSRMLS_CC
23762 +# define HE_NOTICE E_NOTICE TSRMLS_CC
23763 +# define HE_WARNING E_WARNING TSRMLS_CC
23764 +# define HE_ERROR E_ERROR TSRMLS_CC
23767 +#define HTTP_E_RUNTIME 1L
23768 +#define HTTP_E_INVALID_PARAM 2L
23769 +#define HTTP_E_HEADER 3L
23770 +#define HTTP_E_MALFORMED_HEADERS 4L
23771 +#define HTTP_E_REQUEST_METHOD 5L
23772 +#define HTTP_E_MESSAGE_TYPE 6L
23773 +#define HTTP_E_ENCODING 7L
23774 +#define HTTP_E_REQUEST 8L
23775 +#define HTTP_E_REQUEST_POOL 9L
23776 +#define HTTP_E_SOCKET 10L
23777 +#define HTTP_E_RESPONSE 11L
23778 +#define HTTP_E_URL 12L
23779 +#define HTTP_E_QUERYSTRING 13L
23781 +#ifdef ZEND_ENGINE_2
23782 +# define HTTP_BEGIN_ARGS_EX(class, method, ret_ref, req_args) HTTP_STATIC_ARG_INFO ZEND_BEGIN_ARG_INFO_EX(args_for_ ##class## _ ##method , 0, ret_ref, req_args)
23783 +# define HTTP_BEGIN_ARGS_AR(class, method, ret_ref, req_args) HTTP_STATIC_ARG_INFO ZEND_BEGIN_ARG_INFO_EX(args_for_ ##class## _ ##method , 1, ret_ref, req_args)
23784 +# define HTTP_END_ARGS }
23785 +# define HTTP_EMPTY_ARGS_EX(class, method, ret_ref) HTTP_BEGIN_ARGS_EX(class, method, ret_ref, 0) HTTP_END_ARGS
23786 +# define HTTP_ARGS(class, method) args_for_ ##class## _ ##method
23787 +# define HTTP_ARG_VAL(name, pass_ref) ZEND_ARG_INFO(pass_ref, name)
23788 +# define HTTP_ARG_OBJ(class, name, allow_null) ZEND_ARG_OBJ_INFO(0, name, class, allow_null)
23791 +#ifdef ZEND_ENGINE_2
23792 +# define EMPTY_FUNCTION_ENTRY {NULL, NULL, NULL, 0, 0}
23794 +# define EMPTY_FUNCTION_ENTRY {NULL, NULL, NULL}
23797 +#ifdef HTTP_HAVE_CURL
23798 +# ifdef ZEND_ENGINE_2
23799 +# define HTTP_DECLARE_ARG_PASS_INFO() \
23800 + HTTP_STATIC_ARG_INFO \
23801 + ZEND_BEGIN_ARG_INFO(http_arg_pass_ref_2, 0) \
23802 + ZEND_ARG_PASS_INFO(0) \
23803 + ZEND_ARG_PASS_INFO(1) \
23804 + ZEND_END_ARG_INFO(); \
23806 + HTTP_STATIC_ARG_INFO \
23807 + ZEND_BEGIN_ARG_INFO(http_arg_pass_ref_3, 0) \
23808 + ZEND_ARG_PASS_INFO(0) \
23809 + ZEND_ARG_PASS_INFO(0) \
23810 + ZEND_ARG_PASS_INFO(1) \
23811 + ZEND_END_ARG_INFO(); \
23813 + HTTP_STATIC_ARG_INFO \
23814 + ZEND_BEGIN_ARG_INFO(http_arg_pass_ref_4, 0) \
23815 + ZEND_ARG_PASS_INFO(0) \
23816 + ZEND_ARG_PASS_INFO(0) \
23817 + ZEND_ARG_PASS_INFO(0) \
23818 + ZEND_ARG_PASS_INFO(1) \
23819 + ZEND_END_ARG_INFO(); \
23821 + HTTP_STATIC_ARG_INFO \
23822 + ZEND_BEGIN_ARG_INFO(http_arg_pass_ref_5, 0) \
23823 + ZEND_ARG_PASS_INFO(0) \
23824 + ZEND_ARG_PASS_INFO(0) \
23825 + ZEND_ARG_PASS_INFO(0) \
23826 + ZEND_ARG_PASS_INFO(0) \
23827 + ZEND_ARG_PASS_INFO(1) \
23828 + ZEND_END_ARG_INFO();
23831 +# define HTTP_DECLARE_ARG_PASS_INFO() \
23832 + static unsigned char http_arg_pass_ref_2[] = {2, BYREF_NONE, BYREF_FORCE}; \
23833 + static unsigned char http_arg_pass_ref_3[] = {3, BYREF_NONE, BYREF_NONE, BYREF_FORCE}; \
23834 + static unsigned char http_arg_pass_ref_4[] = {4, BYREF_NONE, BYREF_NONE, BYREF_NONE, BYREF_FORCE}; \
23835 + static unsigned char http_arg_pass_ref_5[] = {5, BYREF_NONE, BYREF_NONE, BYREF_NONE, BYREF_NONE, BYREF_FORCE};
23836 +# endif /* ZEND_ENGINE_2 */
23838 +# ifdef ZEND_ENGINE_2
23839 +# define HTTP_DECLARE_ARG_PASS_INFO() \
23840 + HTTP_STATIC_ARG_INFO \
23841 + ZEND_BEGIN_ARG_INFO(http_arg_pass_ref_2, 0) \
23842 + ZEND_ARG_PASS_INFO(0) \
23843 + ZEND_ARG_PASS_INFO(1) \
23844 + ZEND_END_ARG_INFO(); \
23846 + HTTP_STATIC_ARG_INFO \
23847 + ZEND_BEGIN_ARG_INFO(http_arg_pass_ref_3, 0) \
23848 + ZEND_ARG_PASS_INFO(0) \
23849 + ZEND_ARG_PASS_INFO(0) \
23850 + ZEND_ARG_PASS_INFO(1) \
23851 + ZEND_END_ARG_INFO(); \
23853 + HTTP_STATIC_ARG_INFO \
23854 + ZEND_BEGIN_ARG_INFO(http_arg_pass_ref_4, 0) \
23855 + ZEND_ARG_PASS_INFO(0) \
23856 + ZEND_ARG_PASS_INFO(0) \
23857 + ZEND_ARG_PASS_INFO(0) \
23858 + ZEND_ARG_PASS_INFO(1) \
23859 + ZEND_END_ARG_INFO();
23861 +# define HTTP_DECLARE_ARG_PASS_INFO() \
23862 + static unsigned char http_arg_pass_ref_2[] = {2, BYREF_NONE, BYREF_FORCE}; \
23863 + static unsigned char http_arg_pass_ref_3[] = {3, BYREF_NONE, BYREF_NONE, BYREF_FORCE}; \
23864 + static unsigned char http_arg_pass_ref_4[] = {4, BYREF_NONE, BYREF_NONE, BYREF_NONE, BYREF_FORCE};
23865 +# endif /* ZEND_ENGINE_2 */
23866 +#endif /* HTTP_HAVE_CURL */
23869 +#ifndef HAVE_CURL_SHARE_STRERROR
23870 +# define curl_share_strerror(dummy) "unknown error"
23872 +#ifndef HAVE_CURL_EASY_STRERROR
23873 +# define curl_easy_strerror(dummy) "unknown error"
23875 +#ifndef HAVE_CURL_MULTI_STRERROR
23876 +# define curl_multi_strerror(dummy) "unknown error"
23879 +#define PHP_MINIT_CALL(func) PHP_MINIT(func)(INIT_FUNC_ARGS_PASSTHRU)
23880 +#define PHP_RINIT_CALL(func) PHP_RINIT(func)(INIT_FUNC_ARGS_PASSTHRU)
23881 +#define PHP_MSHUTDOWN_CALL(func) PHP_MSHUTDOWN(func)(SHUTDOWN_FUNC_ARGS_PASSTHRU)
23882 +#define PHP_RSHUTDOWN_CALL(func) PHP_RSHUTDOWN(func)(SHUTDOWN_FUNC_ARGS_PASSTHRU)
23884 +#define Z_OBJ_DELREF(z) \
23885 + if (Z_OBJ_HT(z)->del_ref) { \
23886 + Z_OBJ_HT(z)->del_ref(&(z) TSRMLS_CC); \
23888 +#define Z_OBJ_ADDREF(z) \
23889 + if (Z_OBJ_HT(z)->add_ref) { \
23890 + Z_OBJ_HT(z)->add_ref(&(z) TSRMLS_CC); \
23892 +#define Z_OBJ_DELREF_P(z) \
23893 + if (Z_OBJ_HT_P(z)->del_ref) { \
23894 + Z_OBJ_HT_P(z)->del_ref((z) TSRMLS_CC); \
23896 +#define Z_OBJ_ADDREF_P(z) \
23897 + if (Z_OBJ_HT_P(z)->add_ref) { \
23898 + Z_OBJ_HT_P(z)->add_ref((z) TSRMLS_CC); \
23900 +#define Z_OBJ_DELREF_PP(z) \
23901 + if (Z_OBJ_HT_PP(z)->del_ref) { \
23902 + Z_OBJ_HT_PP(z)->del_ref(*(z) TSRMLS_CC); \
23904 +#define Z_OBJ_ADDREF_PP(z) \
23905 + if (Z_OBJ_HT_PP(z)->add_ref) { \
23906 + Z_OBJ_HT_PP(z)->add_ref(*(z) TSRMLS_CC); \
23909 +#endif /* PHP_HTTP_STD_DEFS_H */
23912 + * Local variables:
23914 + * c-basic-offset: 4
23916 + * vim600: noet sw=4 ts=4 fdm=marker
23917 + * vim<600: noet sw=4 ts=4
23921 +++ b/ext/http/php_http_url_api.h
23924 + +--------------------------------------------------------------------+
23926 + +--------------------------------------------------------------------+
23927 + | Redistribution and use in source and binary forms, with or without |
23928 + | modification, are permitted provided that the conditions mentioned |
23929 + | in the accompanying LICENSE file are met. |
23930 + +--------------------------------------------------------------------+
23931 + | Copyright (c) 2004-2010, Michael Wallner <mike@php.net> |
23932 + +--------------------------------------------------------------------+
23935 +/* $Id: php_http_url_api.h 292841 2009-12-31 08:48:57Z mike $ */
23937 +#ifndef PHP_HTTP_URL_API_H
23938 +#define PHP_HTTP_URL_API_H
23940 +#include "ext/standard/url.h"
23942 +extern PHP_MINIT_FUNCTION(http_url);
23944 +#define http_absolute_url(u) _http_absolute_url_ex((u), HTTP_URL_REPLACE TSRMLS_CC)
23945 +#define http_absolute_url_ex(u, f) _http_absolute_url_ex((u), (f) TSRMLS_CC)
23946 +PHP_HTTP_API char *_http_absolute_url_ex(const char *url, int flags TSRMLS_DC);
23948 +#define HTTP_URL_REPLACE 0x000
23949 +#define HTTP_URL_JOIN_PATH 0x001
23950 +#define HTTP_URL_JOIN_QUERY 0x002
23951 +#define HTTP_URL_STRIP_USER 0x004
23952 +#define HTTP_URL_STRIP_PASS 0x008
23953 +#define HTTP_URL_STRIP_AUTH (HTTP_URL_STRIP_USER|HTTP_URL_STRIP_PASS)
23954 +#define HTTP_URL_STRIP_PORT 0x020
23955 +#define HTTP_URL_STRIP_PATH 0x040
23956 +#define HTTP_URL_STRIP_QUERY 0x080
23957 +#define HTTP_URL_STRIP_FRAGMENT 0x100
23958 +#define HTTP_URL_STRIP_ALL ( \
23959 + HTTP_URL_STRIP_AUTH | \
23960 + HTTP_URL_STRIP_PORT | \
23961 + HTTP_URL_STRIP_PATH | \
23962 + HTTP_URL_STRIP_QUERY | \
23963 + HTTP_URL_STRIP_FRAGMENT \
23965 +#define HTTP_URL_FROM_ENV 0x1000
23967 +#define http_build_url(f, o, n, p, s, l) _http_build_url((f), (o), (n), (p), (s), (l) TSRMLS_CC)
23968 +PHP_HTTP_API void _http_build_url(int flags, const php_url *old_url, const php_url *new_url, php_url **url_ptr, char **url_str, size_t *url_len TSRMLS_DC);
23970 +#define http_urlencode_hash(h, q) _http_urlencode_hash_ex((h), 1, NULL, 0, (q), NULL TSRMLS_CC)
23971 +#define http_urlencode_hash_ex(h, o, p, pl, q, ql) _http_urlencode_hash_ex((h), (o), (p), (pl), (q), (ql) TSRMLS_CC)
23972 +PHP_HTTP_API STATUS _http_urlencode_hash_ex(HashTable *hash, zend_bool override_argsep, char *pre_encoded_data, size_t pre_encoded_len, char **encoded_data, size_t *encoded_len TSRMLS_DC);
23974 +#define http_urlencode_hash_recursive(ht, s, as, al, pr, pl) _http_urlencode_hash_recursive((ht), (s), (as), (al), (pr), (pl) TSRMLS_CC)
23975 +PHP_HTTP_API STATUS _http_urlencode_hash_recursive(HashTable *ht, phpstr *str, const char *arg_sep, size_t arg_sep_len, const char *prefix, size_t prefix_len TSRMLS_DC);
23977 +#define http_url_from_struct(u, ht) _http_url_from_struct((u), (ht) TSRMLS_CC)
23978 +static inline php_url *_http_url_from_struct(php_url *url, HashTable *ht TSRMLS_DC)
23983 + url = ecalloc(1, sizeof(php_url));
23986 + if ((SUCCESS == zend_hash_find(ht, "scheme", sizeof("scheme"), (void *) &e))
23987 + && (Z_TYPE_PP(e) == IS_STRING) && Z_STRLEN_PP(e)) {
23988 + url->scheme = estrndup(Z_STRVAL_PP(e), Z_STRLEN_PP(e));
23990 + if ((SUCCESS == zend_hash_find(ht, "user", sizeof("user"), (void *) &e))
23991 + && (Z_TYPE_PP(e) == IS_STRING) && Z_STRLEN_PP(e)) {
23992 + url->user = estrndup(Z_STRVAL_PP(e), Z_STRLEN_PP(e));
23994 + if ((SUCCESS == zend_hash_find(ht, "pass", sizeof("pass"), (void *) &e))
23995 + && (Z_TYPE_PP(e) == IS_STRING) && Z_STRLEN_PP(e)) {
23996 + url->pass = estrndup(Z_STRVAL_PP(e), Z_STRLEN_PP(e));
23998 + if ((SUCCESS == zend_hash_find(ht, "host", sizeof("host"), (void *) &e))
23999 + && (Z_TYPE_PP(e) == IS_STRING) && Z_STRLEN_PP(e)) {
24000 + url->host = estrndup(Z_STRVAL_PP(e), Z_STRLEN_PP(e));
24002 + if ((SUCCESS == zend_hash_find(ht, "path", sizeof("path"), (void *) &e))
24003 + && (Z_TYPE_PP(e) == IS_STRING) && Z_STRLEN_PP(e)) {
24004 + url->path = estrndup(Z_STRVAL_PP(e), Z_STRLEN_PP(e));
24006 + if ((SUCCESS == zend_hash_find(ht, "query", sizeof("query"), (void *) &e))
24007 + && (Z_TYPE_PP(e) == IS_STRING) && Z_STRLEN_PP(e)) {
24008 + url->query = estrndup(Z_STRVAL_PP(e), Z_STRLEN_PP(e));
24010 + if ((SUCCESS == zend_hash_find(ht, "fragment", sizeof("fragment"), (void *) &e))
24011 + && (Z_TYPE_PP(e) == IS_STRING) && Z_STRLEN_PP(e)) {
24012 + url->fragment = estrndup(Z_STRVAL_PP(e), Z_STRLEN_PP(e));
24014 + if (SUCCESS == zend_hash_find(ht, "port", sizeof("port"), (void *) &e)) {
24015 + if (Z_TYPE_PP(e) == IS_LONG) {
24016 + url->port = (unsigned short) Z_LVAL_PP(e);
24018 + zval *o = http_zsep(IS_LONG, *e);
24020 + url->port = (unsigned short) Z_LVAL_P(o);
24021 + zval_ptr_dtor(&o);
24028 +#define http_url_tostruct(u, strct) _http_url_tostruct((u), (strct) TSRMLS_CC)
24029 +static inline HashTable *_http_url_tostruct(php_url *url, zval *strct TSRMLS_DC)
24034 + switch (Z_TYPE_P(strct)) {
24036 + zval_dtor(strct);
24037 + array_init(strct);
24040 + INIT_ZARR(arr, HASH_OF(strct));
24043 + INIT_PZVAL(&arr);
24044 + array_init(&arr);
24048 + if (url->scheme) {
24049 + add_assoc_string(&arr, "scheme", url->scheme, 1);
24052 + add_assoc_string(&arr, "user", url->user, 1);
24055 + add_assoc_string(&arr, "pass", url->pass, 1);
24058 + add_assoc_string(&arr, "host", url->host, 1);
24061 + add_assoc_long(&arr, "port", (long) url->port);
24064 + add_assoc_string(&arr, "path", url->path, 1);
24066 + if (url->query) {
24067 + add_assoc_string(&arr, "query", url->query, 1);
24069 + if (url->fragment) {
24070 + add_assoc_string(&arr, "fragment", url->fragment, 1);
24074 + return Z_ARRVAL(arr);
24080 + * Local variables:
24082 + * c-basic-offset: 4
24084 + * vim600: noet sw=4 ts=4 fdm=marker
24085 + * vim<600: noet sw=4 ts=4
24089 +++ b/ext/http/php_http_util_object.h
24092 + +--------------------------------------------------------------------+
24094 + +--------------------------------------------------------------------+
24095 + | Redistribution and use in source and binary forms, with or without |
24096 + | modification, are permitted provided that the conditions mentioned |
24097 + | in the accompanying LICENSE file are met. |
24098 + +--------------------------------------------------------------------+
24099 + | Copyright (c) 2004-2010, Michael Wallner <mike@php.net> |
24100 + +--------------------------------------------------------------------+
24103 +/* $Id: php_http_util_object.h 292841 2009-12-31 08:48:57Z mike $ */
24105 +#ifndef PHP_HTTP_UTIL_OBJECT_H
24106 +#define PHP_HTTP_UTIL_OBJECT_H
24107 +#ifdef ZEND_ENGINE_2
24109 +extern zend_class_entry *http_util_object_ce;
24110 +extern zend_function_entry http_util_object_fe[];
24112 +extern PHP_MINIT_FUNCTION(http_util_object);
24118 + * Local variables:
24120 + * c-basic-offset: 4
24122 + * vim600: noet sw=4 ts=4 fdm=marker
24123 + * vim<600: noet sw=4 ts=4
24127 +++ b/ext/http/phpstr/phpstr.c
24130 +/* $Id: phpstr.c 211942 2006-04-24 17:17:09Z mike $ */
24133 +#include "phpstr.h"
24135 +PHPSTR_API phpstr *phpstr_init_ex(phpstr *buf, size_t chunk_size, int flags)
24138 + buf = pemalloc(sizeof(phpstr), flags & PHPSTR_INIT_PERSISTENT);
24142 + buf->size = (chunk_size) ? chunk_size : PHPSTR_DEFAULT_SIZE;
24143 + buf->pmem = (flags & PHPSTR_INIT_PERSISTENT) ? 1 : 0;
24144 + buf->data = (flags & PHPSTR_INIT_PREALLOC) ? pemalloc(buf->size, buf->pmem) : NULL;
24145 + buf->free = (flags & PHPSTR_INIT_PREALLOC) ? buf->size : 0;
24152 +PHPSTR_API phpstr *phpstr_from_string_ex(phpstr *buf, const char *string, size_t length)
24154 + if ((buf = phpstr_init(buf))) {
24155 + if (PHPSTR_NOMEM == phpstr_append(buf, string, length)) {
24156 + pefree(buf, buf->pmem);
24163 +PHPSTR_API size_t phpstr_resize_ex(phpstr *buf, size_t len, size_t override_size, int allow_error)
24165 + char *ptr = NULL;
24167 + fprintf(stderr, "RESIZE: size=%lu, used=%lu, free=%lu\n", buf->size, buf->used, buf->free);
24169 + if (buf->free < len) {
24170 + size_t size = override_size ? override_size : buf->size;
24172 + while ((size + buf->free) < len) {
24176 + if (allow_error) {
24177 + ptr = perealloc_recoverable(buf->data, buf->used + buf->free + size, buf->pmem);
24179 + ptr = perealloc(buf->data, buf->used + buf->free + size, buf->pmem);
24185 + return PHPSTR_NOMEM;
24188 + buf->free += size;
24194 +PHPSTR_API size_t phpstr_shrink(phpstr *buf)
24196 + /* avoid another realloc on fixation */
24197 + if (buf->free > 1) {
24198 + char *ptr = perealloc(buf->data, buf->used + 1, buf->pmem);
24203 + return PHPSTR_NOMEM;
24207 + return buf->used;
24210 +PHPSTR_API size_t phpstr_append(phpstr *buf, const char *append, size_t append_len)
24212 + if (PHPSTR_NOMEM == phpstr_resize(buf, append_len)) {
24213 + return PHPSTR_NOMEM;
24215 + memcpy(buf->data + buf->used, append, append_len);
24216 + buf->used += append_len;
24217 + buf->free -= append_len;
24218 + return append_len;
24221 +PHPSTR_API size_t phpstr_appendf(phpstr *buf, const char *format, ...)
24225 + size_t append_len, alloc;
24227 + va_start(argv, format);
24228 + append_len = vspprintf(&append, 0, format, argv);
24231 + alloc = phpstr_append(buf, append, append_len);
24234 + if (PHPSTR_NOMEM == alloc) {
24235 + return PHPSTR_NOMEM;
24237 + return append_len;
24240 +PHPSTR_API size_t phpstr_insert(phpstr *buf, const char *insert, size_t insert_len, size_t offset)
24242 + if (PHPSTR_NOMEM == phpstr_resize(buf, insert_len)) {
24243 + return PHPSTR_NOMEM;
24245 + memmove(buf->data + offset + insert_len, buf->data + offset, insert_len);
24246 + memcpy(buf->data + offset, insert, insert_len);
24247 + buf->used += insert_len;
24248 + buf->free -= insert_len;
24249 + return insert_len;
24252 +PHPSTR_API size_t phpstr_insertf(phpstr *buf, size_t offset, const char *format, ...)
24256 + size_t insert_len, alloc;
24258 + va_start(argv, format);
24259 + insert_len = vspprintf(&insert, 0, format, argv);
24262 + alloc = phpstr_insert(buf, insert, insert_len, offset);
24265 + if (PHPSTR_NOMEM == alloc) {
24266 + return PHPSTR_NOMEM;
24268 + return insert_len;
24271 +PHPSTR_API size_t phpstr_prepend(phpstr *buf, const char *prepend, size_t prepend_len)
24273 + if (PHPSTR_NOMEM == phpstr_resize(buf, prepend_len)) {
24274 + return PHPSTR_NOMEM;
24276 + memmove(buf->data + prepend_len, buf->data, buf->used);
24277 + memcpy(buf->data, prepend, prepend_len);
24278 + buf->used += prepend_len;
24279 + buf->free -= prepend_len;
24280 + return prepend_len;
24283 +PHPSTR_API size_t phpstr_prependf(phpstr *buf, const char *format, ...)
24287 + size_t prepend_len, alloc;
24289 + va_start(argv, format);
24290 + prepend_len = vspprintf(&prepend, 0, format, argv);
24293 + alloc = phpstr_prepend(buf, prepend, prepend_len);
24296 + if (PHPSTR_NOMEM == alloc) {
24297 + return PHPSTR_NOMEM;
24299 + return prepend_len;
24302 +PHPSTR_API char *phpstr_data(const phpstr *buf, char **into, size_t *len)
24304 + char *copy = ecalloc(1, buf->used + 1);
24305 + memcpy(copy, buf->data, buf->used);
24310 + *len = buf->used;
24315 +PHPSTR_API phpstr *phpstr_dup(const phpstr *buf)
24317 + phpstr *dup = phpstr_clone(buf);
24318 + if (PHPSTR_NOMEM == phpstr_append(dup, buf->data, buf->used)) {
24319 + phpstr_free(&dup);
24324 +PHPSTR_API size_t phpstr_cut(phpstr *buf, size_t offset, size_t length)
24326 + if (offset >= buf->used) {
24329 + if (offset + length > buf->used) {
24330 + length = buf->used - offset;
24332 + memmove(buf->data + offset, buf->data + offset + length, buf->used - length);
24333 + buf->used -= length;
24334 + buf->free += length;
24338 +PHPSTR_API phpstr *phpstr_sub(const phpstr *buf, size_t offset, size_t length)
24340 + if (offset >= buf->used) {
24343 + size_t need = 1 + ((length + offset) > buf->used ? (buf->used - offset) : (length - offset));
24344 + phpstr *sub = phpstr_init_ex(NULL, need, PHPSTR_INIT_PREALLOC | (buf->pmem ? PHPSTR_INIT_PERSISTENT:0));
24346 + if (PHPSTR_NOMEM == phpstr_append(sub, buf->data + offset, need)) {
24347 + phpstr_free(&sub);
24349 + sub->size = buf->size;
24356 +PHPSTR_API phpstr *phpstr_right(const phpstr *buf, size_t length)
24358 + if (length < buf->used) {
24359 + return phpstr_sub(buf, buf->used - length, length);
24361 + return phpstr_sub(buf, 0, buf->used);
24366 +PHPSTR_API phpstr *phpstr_merge_va(phpstr *buf, unsigned argc, va_list argv)
24369 + buf = phpstr_init(buf);
24372 + while (argc > i++) {
24373 + phpstr_free_t f = va_arg(argv, phpstr_free_t);
24374 + phpstr *current = va_arg(argv, phpstr *);
24375 + phpstr_append(buf, current->data, current->used);
24376 + FREE_PHPSTR(f, current);
24383 +PHPSTR_API phpstr *phpstr_merge_ex(phpstr *buf, unsigned argc, ...)
24388 + va_start(argv, argc);
24389 + ret = phpstr_merge_va(buf, argc, argv);
24394 +PHPSTR_API phpstr *phpstr_merge(unsigned argc, ...)
24399 + va_start(argv, argc);
24400 + ret = phpstr_merge_va(NULL, argc, argv);
24405 +PHPSTR_API phpstr *phpstr_fix(phpstr *buf)
24407 + if (PHPSTR_NOMEM == phpstr_resize_ex(buf, 1, 1, 0)) {
24410 + buf->data[buf->used] = '\0';
24414 +PHPSTR_API int phpstr_cmp(phpstr *left, phpstr *right)
24416 + if (left->used > right->used) {
24418 + } else if (right->used > left->used) {
24421 + return memcmp(left->data, right->data, left->used);
24425 +PHPSTR_API void phpstr_reset(phpstr *buf)
24427 + buf->free += buf->used;
24431 +PHPSTR_API void phpstr_dtor(phpstr *buf)
24434 + pefree(buf->data, buf->pmem);
24435 + buf->data = NULL;
24441 +PHPSTR_API void phpstr_free(phpstr **buf)
24444 + phpstr_dtor(*buf);
24445 + pefree(*buf, (*buf)->pmem);
24450 +PHPSTR_API size_t phpstr_chunk_buffer(phpstr **s, const char *data, size_t data_len, char **chunk, size_t chunk_size)
24457 + *s = phpstr_init_ex(NULL, chunk_size << 1, chunk_size ? PHPSTR_INIT_PREALLOC : 0);
24462 + phpstr_append(storage, data, data_len);
24465 + if (!chunk_size) {
24466 + phpstr_data(storage, chunk, &chunk_size);
24468 + return chunk_size;
24471 + if (storage->used >= (chunk_size = storage->size >> 1)) {
24472 + *chunk = estrndup(storage->data, chunk_size);
24473 + phpstr_cut(storage, 0, chunk_size);
24474 + return chunk_size;
24480 +PHPSTR_API void phpstr_chunked_output(phpstr **s, const char *data, size_t data_len, size_t chunk_len, phpstr_passthru_func passthru, void *opaque TSRMLS_DC)
24482 + char *chunk = NULL;
24485 + while ((got = phpstr_chunk_buffer(s, data, data_len, &chunk, chunk_len))) {
24486 + passthru(opaque, chunk, got TSRMLS_CC);
24487 + if (!chunk_len) {
24488 + /* we already got the last chunk,
24489 + and freed all resources */
24494 + STR_SET(chunk, NULL);
24500 + * Local variables:
24502 + * c-basic-offset: 4
24504 + * vim600: sw=4 ts=4 fdm=marker
24505 + * vim<600: sw=4 ts=4
24509 +++ b/ext/http/phpstr/phpstr.h
24512 +/* $Id: phpstr.h 229282 2007-02-07 15:31:50Z mike $ */
24514 +#ifndef _PHPSTR_H_
24515 +#define _PHPSTR_H_
24517 +#ifndef PHPSTR_DEFAULT_SIZE
24518 +# define PHPSTR_DEFAULT_SIZE 256
24521 +#define PHPSTR_NOMEM ((size_t) -1)
24524 +# define STR_FREE(STR) \
24532 +# define STR_SET(STR, SET) \
24540 +# define TSRMLS_DC
24541 +# define TSRMLS_CC
24544 +#ifdef PHP_ATTRIBUTE_FORMAT
24545 +# define PHPSTR_ATTRIBUTE_FORMAT(f, a, b) PHP_ATTRIBUTE_FORMAT(f, a, b)
24547 +# define PHPSTR_ATTRIBUTE_FORMAT(f, a, b)
24550 +# define pemalloc(s,p) malloc(s)
24551 +# define pefree(x,p) free(x)
24552 +# define perealloc(x,s,p) realloc(x,s)
24553 +# define perealloc_recoverable perealloc
24554 +# define ecalloc calloc
24555 +static inline void *estrndup(void *p, size_t s)
24557 + char *r = (char *) malloc(s+1);
24558 + if (r) memcpy((void *) r, p, s), r[s] = '\0';
24559 + return (void *) r;
24563 +#if defined(PHP_WIN32)
24564 +# if defined(PHPSTR_EXPORTS)
24565 +# define PHPSTR_API __declspec(dllexport)
24566 +# elif defined(COMPILE_DL_PHPSTR)
24567 +# define PHPSTR_API __declspec(dllimport)
24569 +# define PHPSTR_API
24572 +# define PHPSTR_API
24575 +#define PHPSTR(p) ((phpstr *) (p))
24576 +#define PHPSTR_VAL(p) (PHPSTR(p))->data
24577 +#define PHPSTR_LEN(p) (PHPSTR(p))->used
24579 +#define FREE_PHPSTR_PTR(STR) pefree(STR, STR->pmem)
24580 +#define FREE_PHPSTR_VAL(STR) phpstr_dtor(STR)
24581 +#define FREE_PHPSTR_ALL(STR) phpstr_free(&(STR))
24582 +#define FREE_PHPSTR(free, STR) \
24585 + case PHPSTR_FREE_NOT: break; \
24586 + case PHPSTR_FREE_PTR: pefree(STR, STR->pmem); break; \
24587 + case PHPSTR_FREE_VAL: phpstr_dtor(STR); break; \
24588 + case PHPSTR_FREE_ALL: \
24590 + phpstr *PTR = (STR); \
24591 + phpstr_free(&PTR); \
24594 + default: break; \
24597 +#define RETURN_PHPSTR_PTR(STR) RETURN_PHPSTR((STR), PHPSTR_FREE_PTR, 0)
24598 +#define RETURN_PHPSTR_VAL(STR) RETURN_PHPSTR((STR), PHPSTR_FREE_NOT, 0)
24599 +#define RETURN_PHPSTR_DUP(STR) RETURN_PHPSTR((STR), PHPSTR_FREE_NOT, 1)
24600 +#define RETVAL_PHPSTR_PTR(STR) RETVAL_PHPSTR((STR), PHPSTR_FREE_PTR, 0)
24601 +#define RETVAL_PHPSTR_VAL(STR) RETVAL_PHPSTR((STR), PHPSTR_FREE_NOT, 0)
24602 +#define RETVAL_PHPSTR_DUP(STR) RETVAL_PHPSTR((STR), PHPSTR_FREE_NOT, 1)
24603 +/* RETURN_PHPSTR(buf, PHPSTR_FREE_PTR, 0) */
24604 +#define RETURN_PHPSTR(STR, free, dup) \
24605 + RETVAL_PHPSTR((STR), (free), (dup)); \
24608 +#define RETVAL_PHPSTR(STR, free, dup) \
24609 + phpstr_fix(STR); \
24610 + RETVAL_STRINGL((STR)->data, (STR)->used, (dup)); \
24611 + FREE_PHPSTR((free), (STR));
24613 +typedef struct _phpstr_t {
24619 + unsigned reserved:31;
24622 +typedef enum _phpstr_free_t {
24623 + PHPSTR_FREE_NOT = 0,
24624 + PHPSTR_FREE_PTR, /* pefree() */
24625 + PHPSTR_FREE_VAL, /* phpstr_dtor() */
24626 + PHPSTR_FREE_ALL /* phpstr_free() */
24629 +#define PHPSTR_ALL_FREE(STR) PHPSTR_FREE_ALL,(STR)
24630 +#define PHPSTR_PTR_FREE(STR) PHPSTR_FREE_PTR,(STR)
24631 +#define PHPSTR_VAL_FREE(STR) PHPSTR_FREE_VAL,(STR)
24632 +#define PHPSTR_NOT_FREE(STR) PHPSTR_FREE_NOT,(STR)
24634 +#define PHPSTR_INIT_PREALLOC 0x01
24635 +#define PHPSTR_INIT_PERSISTENT 0x02
24637 +/* create a new phpstr */
24638 +#define phpstr_new() phpstr_init(NULL)
24639 +#define phpstr_init(b) phpstr_init_ex(b, PHPSTR_DEFAULT_SIZE, 0)
24640 +#define phpstr_clone(phpstr_pointer) phpstr_init_ex(NULL, (phpstr_pointer)->size, (phpstr_pointer)->pmem ? PHPSTR_INIT_PERSISTENT:0)
24641 +PHPSTR_API phpstr *phpstr_init_ex(phpstr *buf, size_t chunk_size, int flags);
24643 +/* create a phpstr from a zval or c-string */
24644 +#define phpstr_from_zval(z) phpstr_from_string(Z_STRVAL(z), Z_STRLEN(z))
24645 +#define phpstr_from_zval_ex(b, z) phpstr_from_string_ex(b, Z_STRVAL(z), Z_STRLEN(z))
24646 +#define phpstr_from_string(s, l) phpstr_from_string_ex(NULL, (s), (l))
24647 +PHPSTR_API phpstr *phpstr_from_string_ex(phpstr *buf, const char *string, size_t length);
24649 +/* usually only called from within the internal functions */
24650 +#define phpstr_resize(b, s) phpstr_resize_ex((b), (s), 0, 0)
24651 +PHPSTR_API size_t phpstr_resize_ex(phpstr *buf, size_t len, size_t override_size, int allow_error);
24653 +/* shrink memory chunk to actually used size (+1) */
24654 +PHPSTR_API size_t phpstr_shrink(phpstr *buf);
24656 +/* append data to the phpstr */
24657 +#define phpstr_appends(b, a) phpstr_append((b), (a), sizeof(a)-1)
24658 +#define phpstr_appendl(b, a) phpstr_append((b), (a), strlen(a))
24659 +PHPSTR_API size_t phpstr_append(phpstr *buf, const char *append, size_t append_len);
24660 +PHPSTR_API size_t phpstr_appendf(phpstr *buf, const char *format, ...) PHPSTR_ATTRIBUTE_FORMAT(printf, 2, 3);
24662 +/* insert data at a specific position of the phpstr */
24663 +#define phpstr_inserts(b, i, o) phpstr_insert((b), (i), sizeof(i)-1, (o))
24664 +#define phpstr_insertl(b, i, o) phpstr_insert((b), (i), strlen(i), (o))
24665 +PHPSTR_API size_t phpstr_insert(phpstr *buf, const char *insert, size_t insert_len, size_t offset);
24666 +PHPSTR_API size_t phpstr_insertf(phpstr *buf, size_t offset, const char *format, ...) PHPSTR_ATTRIBUTE_FORMAT(printf, 3, 4);
24668 +/* prepend data */
24669 +#define phpstr_prepends(b, p) phpstr_prepend((b), (p), sizeof(p)-1)
24670 +#define phpstr_prependl(b, p) phpstr_prepend((b), (p), strlen(p))
24671 +PHPSTR_API size_t phpstr_prepend(phpstr *buf, const char *prepend, size_t prepend_len);
24672 +PHPSTR_API size_t phpstr_prependf(phpstr *buf, const char *format, ...) PHPSTR_ATTRIBUTE_FORMAT(printf, 2, 3);
24674 +/* get a zero-terminated string */
24675 +PHPSTR_API char *phpstr_data(const phpstr *buf, char **into, size_t *len);
24677 +/* get a part of the phpstr */
24678 +#define phpstr_mid(b, o, l) phpstr_sub((b), (o), (l))
24679 +#define phpstr_left(b, l) phpstr_sub((b), 0, (l))
24680 +PHPSTR_API phpstr *phpstr_right(const phpstr *buf, size_t length);
24681 +PHPSTR_API phpstr *phpstr_sub(const phpstr *buf, size_t offset, size_t len);
24683 +/* remove a substring */
24684 +PHPSTR_API size_t phpstr_cut(phpstr *buf, size_t offset, size_t length);
24686 +/* get a complete phpstr duplicate */
24687 +PHPSTR_API phpstr *phpstr_dup(const phpstr *buf);
24689 +/* merge several phpstr objects
24692 + phpstr *final = phpstr_merge(3,
24693 + PHPSTR_NOT_FREE(&keep),
24694 + PHPSTR_ALL_FREE(middle_ptr),
24695 + PHPSTR_VAL_FREE(&local);
24697 +PHPSTR_API phpstr *phpstr_merge(unsigned argc, ...);
24698 +PHPSTR_API phpstr *phpstr_merge_ex(phpstr *buf, unsigned argc, ...);
24699 +PHPSTR_API phpstr *phpstr_merge_va(phpstr *buf, unsigned argc, va_list argv);
24701 +/* sets a trailing NUL byte */
24702 +PHPSTR_API phpstr *phpstr_fix(phpstr *buf);
24704 +/* memcmp for phpstr objects */
24705 +PHPSTR_API int phpstr_cmp(phpstr *left, phpstr *right);
24707 +/* reset phpstr object */
24708 +PHPSTR_API void phpstr_reset(phpstr *buf);
24710 +/* free a phpstr objects contents */
24711 +PHPSTR_API void phpstr_dtor(phpstr *buf);
24713 +/* free a phpstr object completely */
24714 +PHPSTR_API void phpstr_free(phpstr **buf);
24716 +/* stores data in a phpstr until it reaches chunk_size */
24717 +PHPSTR_API size_t phpstr_chunk_buffer(phpstr **s, const char *data, size_t data_len, char **chunk, size_t chunk_size);
24719 +typedef void (*phpstr_passthru_func)(void *opaque, const char *, size_t TSRMLS_DC);
24721 +/* wrapper around phpstr_chunk_buffer, which passes available chunks to passthru() */
24722 +PHPSTR_API void phpstr_chunked_output(phpstr **s, const char *data, size_t data_len, size_t chunk_size, phpstr_passthru_func passthru, void *opaque TSRMLS_DC);
24728 + * Local variables:
24730 + * c-basic-offset: 4
24732 + * vim600: sw=4 ts=4 fdm=marker
24733 + * vim<600: sw=4 ts=4
24736 +++ b/ext/http/tests/HttpMessage_001.phpt
24742 +include 'skip.inc';
24743 +checkmin("5.2.5");
24748 +$m = new HttpMessage(
24749 + "HTTP/1.1 301\r\n".
24750 + "Location: /anywhere\r\n".
24751 + "HTTP/1.1 302\r\n".
24752 + "Location: /somewhere\r\n".
24753 + "HTTP/1.1 206 Partial content\r\n".
24754 + "Content-Range: bytes=2-3\r\n".
24755 + "Transfer-Encoding: chunked\r\n".
24762 +var_dump($m->getResponseStatus());
24764 +$x = $m->getParentMessage();
24765 +$x = $m->getParentMessage();
24766 +$x = $m->getParentMessage();
24768 +var_dump($m->getBody());
24769 +var_dump(HttpMessage::fromString($m->toString(true))->toString(true));
24772 + var_dump($m->toString());
24773 + } while ($m = $m->getParentMessage());
24774 +} catch (HttpException $ex) {
24781 +string(15) "Partial content"
24783 +string(190) "HTTP/1.1 301
24784 +Location: /anywhere
24786 +Location: /somewhere
24787 +HTTP/1.1 206 Partial content
24788 +Content-Range: bytes=2-3
24789 +X-Original-Transfer-Encoding: chunked
24794 +string(119) "HTTP/1.1 206 Partial content
24795 +Content-Range: bytes=2-3
24796 +X-Original-Transfer-Encoding: chunked
24801 +string(36) "HTTP/1.1 302
24802 +Location: /somewhere
24804 +string(35) "HTTP/1.1 301
24805 +Location: /anywhere
24809 +++ b/ext/http/tests/HttpMessage_002.phpt
24812 +HttpMessage properties
24815 +include 'skip.inc';
24816 +checkmin("5.2.5");
24817 +checkcls('HttpMessage');
24821 +class Message extends HttpMessage
24823 + var $var_property = 'var';
24824 + public $public_property = 'public';
24825 + protected $protected_property = 'protected';
24826 + private $private_property = 'private';
24828 + public function test()
24830 + var_dump($this->var_property);
24831 + var_dump($this->public_property);
24832 + var_dump($this->protected_property);
24833 + var_dump($this->private_property);
24834 + var_dump($this->non_ex_property);
24835 + $this->var_property.='_property';
24836 + $this->public_property.='_property';
24837 + $this->protected_property.='_property';
24838 + $this->private_property.='_property';
24839 + $this->non_ex_property = 'non_ex';
24840 + var_dump($this->var_property);
24841 + var_dump($this->public_property);
24842 + var_dump($this->protected_property);
24843 + var_dump($this->private_property);
24844 + var_dump($this->non_ex_property);
24846 + print_r($this->headers);
24847 + $this->headers['Foo'] = 'Bar';
24851 +error_reporting(E_ALL|E_STRICT);
24861 +string(6) "public"
24862 +string(9) "protected"
24863 +string(7) "private"
24865 +Notice: Undefined property: Message::$non_ex_property in %s
24867 +string(12) "var_property"
24868 +string(15) "public_property"
24869 +string(18) "protected_property"
24870 +string(16) "private_property"
24871 +string(6) "non_ex"
24875 +%aFatal error%sCannot access HttpMessage properties by reference or array key/index in%s
24877 +++ b/ext/http/tests/HttpMessage_003.phpt
24880 +HttpMessage implements Serializable, Countable
24883 +include 'skip.inc';
24884 +checkmin("5.2.5");
24890 +$m = new HttpMessage(
24891 + "HTTP/1.1 301\r\n".
24892 + "Location: /anywhere\r\n".
24893 + "HTTP/1.1 302\r\n".
24894 + "Location: /somewhere\r\n".
24895 + "HTTP/1.1 200\r\n".
24896 + "Transfer-Encoding: chunked\r\n".
24903 +var_dump($m->count());
24904 +var_dump($m->serialize());
24905 +$m->unserialize("HTTP/1.1 200 Ok\r\nServer: Funky/1.0");
24907 +var_dump($m->count());
24914 +string(148) "HTTP/1.1 301
24915 +Location: /anywhere
24917 +Location: /somewhere
24919 +X-Original-Transfer-Encoding: chunked
24924 +object(HttpMessage)#%d (%d) {
24929 + ["requestMethod%s]=>
24931 + ["requestUrl%s]=>
24933 + ["responseStatus%s]=>
24935 + ["responseCode%s]=>
24937 + ["httpVersion%s]=>
24942 + string(9) "Funky/1.0"
24944 + ["parentMessage%s]=>
24950 +++ b/ext/http/tests/HttpMessage_004.phpt
24953 +HttpMessage::detach()
24956 +include 'skip.inc';
24963 +$m = new HttpMessage("
24970 +Content-Type: text/plain
24976 +$d = $m->detach();
24977 +$d->addHeaders(array('Server'=>'Funky/2.0'));
24978 +var_dump($d->getHeaders() == $m->getHeaders());
24979 +var_dump($d->getBody());
24988 \ No newline at end of file
24990 +++ b/ext/http/tests/HttpMessage_005.phpt
24993 +HttpMessage::prepend()
24996 +include 'skip.inc';
25003 +$m1 = new HttpMessage("
25010 +Content-Type: text/plain
25016 +$m2 = new HttpMessage("
25017 +GET http://example.com/ HTTP/1.0
25020 +Content-Type: text/html
25026 +$m1->prepend($m2);
25028 +echo $m1->toString(true);
25030 +$m1->prepend($m1->detach(), false);
25031 +echo $m1->toString(true);
25037 +GET http://example.com/ HTTP/1.0
25040 +Content-Type: text/html
25050 +Content-Type: text/plain
25054 +GET http://example.com/ HTTP/1.0
25057 +Content-Type: text/html
25067 +Content-Type: text/plain
25073 +Content-Type: text/plain
25078 \ No newline at end of file
25080 +++ b/ext/http/tests/HttpMessage_006.phpt
25083 +HttpMessage iterator
25086 +include 'skip.inc';
25093 +$m = new HttpMessage("
25097 +HTTP/1.1 304 Not Modified
25100 +foreach ($m as $msg) {
25101 + echo "==\n", $msg;
25109 +HTTP/1.1 304 Not Modified
25117 \ No newline at end of file
25119 +++ b/ext/http/tests/HttpMessage_007.phpt
25122 +HttpMessage::reverse()
25125 +include 'skip.inc';
25131 +$s = "GET /first HTTP/1.1\nHTTP/1.1 200 Ok-first\nGET /second HTTP/1.1\nHTTP/1.1 200 Ok-second\nGET /third HTTP/1.1\nHTTP/1.1 200 Ok-third\n";
25132 +echo HttpMessage::fromString($s)->toString(true);
25134 +echo HttpMessage::fromString($s)->reverse()->toString(true);
25136 +$m = new HttpMessage($s);
25137 +$r = $m->reverse();
25139 +var_dump($r->count());
25140 +echo $r->toString(true);
25146 +GET /first HTTP/1.1
25147 +HTTP/1.1 200 Ok-first
25148 +GET /second HTTP/1.1
25149 +HTTP/1.1 200 Ok-second
25150 +GET /third HTTP/1.1
25151 +HTTP/1.1 200 Ok-third
25153 +HTTP/1.1 200 Ok-third
25154 +GET /third HTTP/1.1
25155 +HTTP/1.1 200 Ok-second
25156 +GET /second HTTP/1.1
25157 +HTTP/1.1 200 Ok-first
25158 +GET /first HTTP/1.1
25160 +HTTP/1.1 200 Ok-third
25161 +GET /third HTTP/1.1
25162 +HTTP/1.1 200 Ok-second
25163 +GET /second HTTP/1.1
25164 +HTTP/1.1 200 Ok-first
25165 +GET /first HTTP/1.1
25168 +++ b/ext/http/tests/HttpMessage_008.phpt
25171 +HttpMessage::toMessageTypeObject()
25174 +include 'skip.inc';
25176 +checkcls('HttpRequest');
25182 +$b = HttpRequest::encodeBody(array("a"=>"b",1=>2),null);
25184 +$m = new HttpMessage;
25185 +$m->setType(HttpMessage::TYPE_REQUEST);
25186 +$m->setRequestMethod('POST');
25187 +$m->setRequestUrl("http://www.example.com");
25188 +$m->setHttpVersion('1.1');
25191 + "Content-Type" => "application/x-www-form-urlencoded",
25192 + "Host" => "www.example.com",
25193 + "Content-Length"=> strlen($b),
25197 +$r = $m->toMessageTypeObject();
25203 +POST http://www.example.com HTTP/1.1
25204 +Content-Type: application/x-www-form-urlencoded
25205 +Host: www.example.com
25212 +++ b/ext/http/tests/HttpMessage_009_bug16700.phpt
25215 +Bug #16700 - child classes of HttpMessage cannot not have array properties
25218 +include 'skip.inc';
25225 +class ChildMessage extends HttpMessage {
25226 + public $properties = array();
25229 +$child = new ChildMessage;
25230 +$child->properties['foo'] = 'bar';
25231 +echo $child->properties['foo'], "\n";
25239 +++ b/ext/http/tests/HttpQueryString_001.phpt
25242 +HttpQueryString global
25245 +include 'skip.inc';
25246 +checkmin("5.2.5");
25252 +$_GET = array('a'=>'b','c'=>'3.4','r'=>array(1,2,3));
25253 +$_SERVER['QUERY_STRING'] = 'a=b&c=3.4&r[0]=1&r[1]=2&r[2]=3';
25255 +var_dump(HttpQueryString::singleton()->get());
25256 +var_dump(HttpQueryString::singleton()->get('n'));
25257 +var_dump(HttpQueryString::singleton()->get('a'));
25258 +var_dump(HttpQueryString::singleton()->get('a', "i", 0, true));
25259 +var_dump(HttpQueryString::singleton()->get('a', "string", 'hi!'));
25260 +var_dump(HttpQueryString::singleton()->get('c'));
25261 +var_dump(HttpQueryString::singleton()->get('c', HttpQueryString::TYPE_INT));
25262 +var_dump(HttpQueryString::singleton()->get('c', HttpQueryString::TYPE_FLOAT));
25263 +var_dump(HttpQueryString::singleton()->get('c', HttpQueryString::TYPE_BOOL));
25264 +var_dump(HttpQueryString::singleton()->get('r'));
25265 +var_dump(HttpQueryString::singleton()->get('r', HttpQueryString::TYPE_ARRAY));
25266 +var_dump(HttpQueryString::singleton()->get('r', HttpQueryString::TYPE_OBJECT));
25268 +HttpQueryString::singleton()->set(new HttpQueryString(false, 'z[0]=2'));
25270 +HttpQueryString::singleton()->set(array('a'=>'b', 'c'=> "3.4"));
25271 +HttpQueryString::singleton()->set(array('a' => NULL));
25273 +var_dump(HttpQueryString::singleton());
25275 +var_dump($_SERVER['QUERY_STRING']);
25281 +string(42) "a=b&c=3.4&r%5B0%5D=1&r%5B1%5D=2&r%5B2%5D=3"
25306 +object(stdClass)#%d (%d) {
25314 +object(HttpQueryString)#1 (2) {
25315 + ["queryArray%s]=>
25334 + ["queryString%s]=>
25335 + &string(49) "c=3.4&r%5B0%5D=1&r%5B1%5D=2&r%5B2%5D=3&z%5B0%5D=2"
25355 +string(49) "c=3.4&r%5B0%5D=1&r%5B1%5D=2&r%5B2%5D=3&z%5B0%5D=2"
25357 \ No newline at end of file
25359 +++ b/ext/http/tests/HttpQueryString_002.phpt
25362 +HttpQueryString local
25365 +include 'skip.inc';
25366 +checkmin("5.2.5");
25372 +$q = new HttpQueryString(false, $array = array('a'=>'b','c'=>'3.4','r'=>array(1,2,3)));
25373 +var_dump($q->get());
25374 +var_dump($q->get('n'));
25375 +var_dump($q->get('a'));
25376 +var_dump($q->get('a', "i", 0, true));
25377 +var_dump($q->get('a', "string", 'hi!'));
25378 +var_dump($q->get('c'));
25379 +var_dump($q->get('c', HttpQueryString::TYPE_INT));
25380 +var_dump($q->get('c', HttpQueryString::TYPE_FLOAT));
25381 +var_dump($q->get('c', HttpQueryString::TYPE_BOOL));
25382 +var_dump($q->get('r'));
25383 +var_dump($q->get('r', HttpQueryString::TYPE_ARRAY));
25384 +var_dump($q->get('r', HttpQueryString::TYPE_OBJECT));
25386 +$q->set('z[0]=2');
25387 +$q->set(array('a'=>'b', 'c'=> "3.4"));
25388 +$q->set(array('a' => NULL));
25397 +string(42) "a=b&c=3.4&r%5B0%5D=1&r%5B1%5D=2&r%5B2%5D=3"
25422 +object(stdClass)#%d (%d) {
25430 +object(HttpQueryString)#1 (2) {
25431 + ["queryArray%s]=>
25450 + ["queryString%s]=>
25451 + string(49) "c=3.4&r%5B0%5D=1&r%5B1%5D=2&r%5B2%5D=3&z%5B0%5D=2"
25469 \ No newline at end of file
25471 +++ b/ext/http/tests/HttpQueryString_003.phpt
25474 +HttpQueryString xlate
25477 +include 'skip.inc';
25478 +checkmin("5.2.5");
25479 +checkext('iconv');
25484 +$qs = new HttpQueryString(false, "ä[0]=ü&ö[a]=ß");
25485 +var_dump($qs->get());
25486 +$qs->xlate("latin1", "utf8");
25487 +var_dump($qs->get());
25488 +$qs->xlate("utf8", "latin1");
25489 +var_dump($qs->get());
25493 +string(29) "%E4%5B0%5D=%FC&%F6%5Ba%5D=%DF"
25494 +string(41) "%C3%A4%5B0%5D=%C3%BC&%C3%B6%5Ba%5D=%C3%9F"
25495 +string(29) "%E4%5B0%5D=%FC&%F6%5Ba%5D=%DF"
25498 +++ b/ext/http/tests/HttpQueryString_004.phpt
25501 +HttpQueryString w/ objects
25504 +include 'skip.inc';
25505 +checkmin("5.2.5");
25510 +class test_props {
25513 + protected $dont_show;
25514 + private $dont_show2;
25515 + function __construct() {
25516 + $this->bar = (object) array("baz"=>1);
25517 + $this->dont_show = 'xxx';
25518 + $this->dont_show2 = 'zzz';
25521 +$foo = new test_props;
25522 +var_dump($q = new HttpQueryString(false, $foo));
25523 +$foo->bar->baz = 0;
25524 +var_dump($q->mod($foo));
25529 +object(HttpQueryString)#3 (2) {
25530 + ["queryArray%s]=>
25538 + ["queryString%s]=>
25539 + string(14) "bar%5Bbaz%5D=1"
25541 +object(HttpQueryString)#4 (2) {
25542 + ["queryArray%s]=>
25550 + ["queryString%s]=>
25551 + string(14) "bar%5Bbaz%5D=0"
25555 +++ b/ext/http/tests/HttpRequestDataShare_001.phpt
25558 +HttpRequestDataShare
25561 +include "skip.inc";
25562 +checkurl("www.google.com");
25563 +checkcls("HttpRequestDataShare");
25569 +$s = new HttpRequestDataShare;
25571 +$s->cookie = true;
25573 +$r1 = new HttpRequest("http://www.google.com/");
25574 +$r2 = new HttpRequest("http://www.google.com/");
25576 +$r1->enableCookies();
25577 +$r2->enableCookies();
25587 +var_dump(current($r1->getResponseCookies())->cookies["PREF"] === HttpUtil::parseCookie($r2->getRequestMessage()->getHeader("Cookie"))->cookies["PREF"]);
25596 +++ b/ext/http/tests/HttpRequestDataShare_002.phpt
25599 +HttpRequestDataShare global
25602 +include "skip.inc";
25603 +checkurl("www.google.com");
25604 +checkcls("HttpRequestDataShare");
25610 +$s = HttpRequestDataShare::singleton(true);
25611 +$s->cookie = true;
25614 +$r1 = new HttpRequest("http://www.google.com/");
25615 +$r2 = new HttpRequest("http://www.google.com/");
25617 +$r1->enableCookies();
25618 +$r2->enableCookies();
25628 +if (current($r1->getResponseCookies())->cookies["PREF"] !== HttpUtil::parseCookie($r2->getRequestMessage()->getHeader("Cookie"))->cookies["PREF"]) {
25630 + current($r1->getResponseCookies())->cookies["PREF"],
25631 + HttpUtil::parseCookie($r2->getRequestMessage()->getHeader("Cookie"))->cookies["PREF"]
25639 +object(HttpRequestDataShare)#1 (4) {
25651 +++ b/ext/http/tests/HttpRequestPool_001.phpt
25657 +include 'skip.inc';
25658 +checkmin("5.2.5");
25659 +checkcls('HttpRequestPool');
25660 +checkurl('www.php.net');
25661 +checkurl('dev.iworks.at');
25666 +$post = new HttpRequest('http://dev.iworks.at/ext-http/.print_request.php', HTTP_METH_POST);
25667 +$post->addPostFields(array('a'=>1,'b'=>2)) ;
25669 +$pool = new HttpRequestPool(
25670 + new HttpRequest('http://www.php.net/', HTTP_METH_HEAD),
25676 +foreach ($pool as $req) {
25677 + echo $req->getUrl(), '=',
25678 + $req->getResponseCode(), ':',
25679 + $req->getResponseMessage()->getResponseCode(), "\n";
25682 +foreach ($pool as $req) {
25684 + $pool->attach(new HttpRequest('http://foo.bar'));
25685 + } catch (HttpRequestPoolException $x) {
25690 +foreach ($pool as $req) {
25691 + $pool->detach($req);
25699 +http://www.php.net/=200:200
25700 +http://dev.iworks.at/ext-http/.print_request.php=200:200
25705 +++ b/ext/http/tests/HttpRequestPool_002.phpt
25708 +extending HttpRequestPool
25711 +include 'skip.inc';
25712 +checkcls('HttpRequestPool');
25713 +checkurl('www.php.net');
25719 +class MyPool extends HttpRequestPool
25721 + public function send()
25723 + while ($this->socketPerform()) {
25724 + if (!$this->socketSelect()) {
25725 + throw new HttpSocketException;
25730 + protected final function socketPerform()
25732 + $result = parent::socketPerform();
25735 + foreach ($this->getFinishedRequests() as $r) {
25736 + echo "=", $r->getResponseCode(), "=";
25737 + $this->detach($r);
25744 +$pool = new MyPool(
25745 + new HttpRequest('http://www.php.net/', HTTP_METH_HEAD),
25746 + new HttpRequest('http://www.php.net/', HTTP_METH_HEAD),
25747 + new HttpRequest('http://www.php.net/', HTTP_METH_HEAD)
25756 +\.*=200=\.*=200=\.*=200=
25759 +++ b/ext/http/tests/HttpRequestPool_003.phpt
25762 +HttpRequestPool chain
25765 +include 'skip.inc';
25766 +checkcls('HttpRequest');
25767 +checkcls('HttpRequestPool');
25774 +set_time_limit(0);
25775 +ini_set('error_reporting', E_ALL);
25776 +ini_set('html_errors', 0);
25778 +class Pool extends HttpRequestPool
25784 + public final function __construct($urls_file = 'urls.txt', $cache_dir = 'HttpRequestPool_cache')
25786 + $this->dir = (is_dir($cache_dir) or @mkdir($cache_dir)) ? $cache_dir : null;
25788 + foreach (array_map('trim', file($urls_file)) as $url) {
25789 + $this->all[$url] = $this->dir ? $this->dir .'/'. md5($url) : null;
25795 + public final function send()
25798 + $now = array_slice($this->all, 0, RMAX);
25799 + $this->rem = array_slice($this->all, RMAX);
25802 + $this->rem = array();
25805 + foreach ($now as $url => $file) {
25809 + HttpRequest::METH_GET,
25812 + 'compress' => GZIP,
25813 + 'timeout' => TOUT,
25814 + 'connecttimeout' => TOUT,
25815 + 'lastmodified' => is_file($file)?filemtime($file):0
25821 + while ($this->socketPerform()) {
25822 + if (!$this->socketSelect()) {
25823 + throw new HttpSocketException;
25828 + protected final function socketPerform()
25831 + $rc = parent::socketPerform();
25832 + } catch (HttpRequestException $x) {
25833 + // a request may have thrown an exception,
25834 + // but it is still save to continue
25835 + echo $x->getMessage(), "\n";
25838 + foreach ($this->getFinishedRequests() as $r) {
25839 + $this->detach($r);
25841 + $u = $r->getUrl();
25842 + $c = $r->getResponseCode();
25843 + $b = $r->getResponseBody();
25845 + printf("%d %s %d\n", $c, $u, strlen($b));
25847 + if ($c == 200 && $this->dir) {
25848 + file_put_contents($this->all[$u], $b);
25851 + if ($a = each($this->rem)) {
25852 + list($url, $file) = $a;
25856 + HttpRequest::METH_GET,
25859 + 'compress' => GZIP,
25860 + 'timeout' => TOUT,
25861 + 'connecttimeout' => TOUT,
25862 + 'lastmodified' => is_file($file)?filemtime($file):0
25872 +define('GZIP', true);
25873 +define('TOUT', 50);
25874 +define('RMAX', 10);
25875 +chdir(dirname(__FILE__));
25877 +$time = microtime(true);
25878 +$pool = new Pool();
25879 +printf("Elapsed: %0.3fs\n", microtime(true)-$time);
25937 +++ b/ext/http/tests/HttpRequestPool_004.phpt
25940 +HttpRequestPool::__destruct() invalid curl handle
25943 +include 'skip.inc';
25944 +checkmin("5.2.5");
25945 +checkcls('HttpRequest');
25946 +checkcls('HttpRequestPool');
25951 +$p = new HttpRequestPool(new HttpRequest('http://example.com'));
25959 +++ b/ext/http/tests/HttpRequestPool_005.phpt
25962 +HttpRequestPool exception
25965 +include 'skip.inc';
25966 +checkmin("5.2.5");
25967 +checkcls('HttpRequestPool');
25973 +$p = new HttpRequestPool(new HttpRequest('http://_____'));
25976 +} catch (HttpRequestPoolException $x) {
25977 + for ($i=0; $x; ++$i, $x = @$x->innerException) {
25978 + printf("%s%s: %s\n", str_repeat("\t", $i), get_class($x), $x->getMessage());
25982 +$p = new HttpRequestPool(new HttpRequest('http://_____'), new HttpRequest('http://_____'));
25985 +} catch (HttpRequestPoolException $x) {
25986 + for ($i=0; $x; ++$i, $x = @$x->innerException) {
25987 + printf("%s%s: %s\n", str_repeat("\t", $i), get_class($x), $x->getMessage());
25995 +HttpRequestPoolException: Exception caused by 2 inner exception(s)
25996 + HttpInvalidParamException: Empty or too short HTTP message: ''
25997 + HttpRequestException: %souldn't resolve host name; %s (http://_____/)
25999 +HttpRequestPoolException: Exception caused by 4 inner exception(s)
26000 + HttpInvalidParamException: Empty or too short HTTP message: ''
26001 + HttpRequestException: %souldn't resolve host name; %s (http://_____/)
26002 + HttpInvalidParamException: Empty or too short HTTP message: ''
26003 + HttpRequestException: %souldn't resolve host name; %s (http://_____/)
26008 +++ b/ext/http/tests/HttpRequestPool_006.phpt
26011 +HttpRequestPool detaching in callbacks
26014 +include 'skip.inc';
26015 +checkcls("HttpRequestPool");
26016 +checkurl("at.php.net");
26017 +checkurl("de.php.net");
26022 +class r extends HttpRequest {
26023 + function onProgress() {
26024 + static $i = array();
26025 + if (empty($i[$this->getUrl()])) {
26026 + $i[$this->getUrl()] = true;
26028 + $GLOBALS['p']->detach($this);
26029 + } catch (Exception $ex) {
26034 + function onFinish() {
26035 + $GLOBALS['p']->detach($this);
26038 +$p = new HttpRequestPool(new r("http://at.php.net"), new r("http://de.php.net"));
26040 +var_dump($p->getAttachedRequests());
26045 +exception 'HttpRequestPoolException' with message 'HttpRequest object(#%d) cannot be detached from the HttpRequestPool while executing the progress callback' in %aHttpRequestPool_006.php:%d
26047 +#0 %aHttpRequestPool_006.php(%d): HttpRequestPool->detach(Object(r))
26048 +#1 [internal function]: r->onProgress(Array)
26049 +#2 %aHttpRequestPool_006.php(%d): HttpRequestPool->send()
26051 +exception 'HttpRequestPoolException' with message 'HttpRequest object(#%d) cannot be detached from the HttpRequestPool while executing the progress callback' in %aHttpRequestPool_006.php:%d
26053 +#0 %aHttpRequestPool_006.php(%d): HttpRequestPool->detach(Object(r))
26054 +#1 [internal function]: r->onProgress(Array)
26055 +#2 %aHttpRequestPool_006.php(%d): HttpRequestPool->send()
26061 +++ b/ext/http/tests/HttpRequest_001.phpt
26064 +HttpRequest options
26067 +include 'skip.inc';
26068 +checkmin("5.2.5");
26069 +checkcls('HttpRequest');
26074 +$r1 = new HttpRequest(null, 0, array('redirect'=>11, 'headers'=>array('X-Foo'=>'Bar')));
26075 +$r2 = new HttpRequest;
26076 +$r2->setOptions(array('redirect'=>99, 'headers'=>array('X-Bar'=>'Foo')));
26077 +$o1 = $r1->getOptions();
26078 +$o2 = $r2->getOptions();
26079 +$r1->setOptions($o2);
26080 +$r2->setOptions($o1);
26081 +print_r(array($o1, $o2));
26082 +var_dump(serialize($r1->getOptions()) === serialize($r2->getOptions()));
26092 + [headers] => Array
26103 + [headers] => Array
26115 +++ b/ext/http/tests/HttpRequest_002.phpt
26118 +HttpRequest GET/POST
26121 +include 'skip.inc';
26122 +checkmin("5.2.5");
26123 +checkcls('HttpRequest');
26124 +checkurl('www.google.com');
26125 +checkurl('dev.iworks.at');
26131 +$r = new HttpRequest('http://www.google.com', HttpRequest::METH_GET);
26133 +print_r($r->getResponseInfo());
26135 +$r = new HttpRequest('http://dev.iworks.at/ext-http/.print_request.php', HTTP_METH_POST);
26136 +$r->addCookies(array('MyCookie' => 'foobar'));
26137 +$r->addQueryData(array('gq'=>'foobar','gi'=>10));
26138 +$r->addPostFields(array('pq'=>'foobar','pi'=>10));
26139 +$r->addPostFile('upload', dirname(__FILE__).'/data.txt', 'text/plain');
26141 +echo $r->getResponseBody();
26142 +var_dump($r->getResponseMessage()->getResponseCode());
26150 + [effective_url] => http://www.google.com/
26151 + [response_code] => 302
26152 + [total_time] => %f
26153 + [namelookup_time] => %f
26154 + [connect_time] => %f
26155 + [pretransfer_time] => %f
26156 + [size_upload] => %d
26157 + [size_download] => %d
26158 + [speed_download] => %d
26159 + [speed_upload] => %d
26160 + [header_size] => %d
26161 + [request_size] => %d
26162 + [ssl_verifyresult] => %d
26164 + [content_length_download] => %d
26165 + [content_length_upload] => %d
26166 + [starttransfer_time] => %f
26167 + [content_type] => %s
26168 + [redirect_time] => %d
26169 + [redirect_count] => %d
26170 + [connect_code] => %d
26171 + [httpauth_avail] => %d
26172 + [proxyauth_avail] => %d
26174 + [num_connects] => %d
26175 + [ssl_engines] => Array
26177 + [cookies] => Array
26187 + [MyCookie] => foobar
26191 + [upload] => Array
26193 + [name] => data.txt
26194 + [type] => text/plain
26204 +++ b/ext/http/tests/HttpRequest_003.phpt
26210 +include 'skip.inc';
26211 +checkmin("5.2.5");
26212 +checkurl('arweb.info');
26213 +skipif(!http_support(HTTP_SUPPORT_SSLREQUESTS), 'need ssl-request support')
26218 +$o = array('redirect' => '3', 'ssl' => array('version' => '3', 'verifyhost' => '1'));
26219 +$r = new HttpRequest('https://ssl.irmler.at/iworks/data.txt');
26220 +$r->setOptions($o);
26222 +var_dump($r->getResponseBody());
26223 +var_dump(is_object($r->getResponseMessage()));
26224 +var_dump(is_object($r->getResponseMessage()));
26225 +var_dump(is_object($r->getResponseMessage()));
26227 +$r->setOptions($o);
26233 +string(10) "1234567890"
26261 +++ b/ext/http/tests/HttpRequest_004.phpt
26264 +HttpRequest multiple posts
26267 +include 'skip.inc';
26268 +checkcls('HttpRequest');
26275 + array('int' => 1, 'dbl' => M_PI),
26276 + array('str' => 'something', 'nil' => null)
26279 +echo "\nFirst Request\n";
26280 +$r = new HttpRequest('http://dev.iworks.at/ext-http/.print_request.php', HttpRequest::METH_POST);
26281 +$r->setPostFields($fields[0]);
26282 +$r->addPostFields($fields[1]);
26283 +var_dump($r->send()->getBody());
26284 +var_dump($fields);
26286 +echo "\nSecond Request\n";
26287 +$r->setPostFields($fields);
26288 +var_dump($r->send()->getBody());
26289 +var_dump($fields);
26291 +echo "\nThird Request\n";
26292 +$r->addPostFields(array('x' => 'X'));
26293 +var_dump($r->send()->getBody());
26294 +var_dump($fields);
26296 +echo "\nFourth Request\n";
26297 +$r->setPostFields(array());
26298 +var_dump($r->send()->getBody());
26299 +var_dump($fields);
26310 + [dbl] => 3.1415926535898
26311 + [str] => something
26314 +string(44) "int=1&dbl=3.1415926535898&str=something&nil="
26322 + float(3.1415926535898)
26327 + string(9) "something"
26339 + [dbl] => 3.1415926535898
26344 + [str] => something
26349 +string(72) "0%5Bint%5D=1&0%5Bdbl%5D=3.1415926535898&1%5Bstr%5D=something&1%5Bnil%5D="
26357 + float(3.1415926535898)
26362 + string(9) "something"
26374 + [dbl] => 3.1415926535898
26379 + [str] => something
26385 +string(76) "0%5Bint%5D=1&0%5Bdbl%5D=3.1415926535898&1%5Bstr%5D=something&1%5Bnil%5D=&x=X"
26393 + float(3.1415926535898)
26398 + string(9) "something"
26405 +string(13) "string(0) ""
26413 + float(3.1415926535898)
26418 + string(9) "something"
26426 +++ b/ext/http/tests/HttpRequest_005.phpt
26429 +HttpRequest accessors
26432 +include 'skip.inc';
26433 +checkcls('HttpRequest');
26438 +error_reporting(0);
26439 +$r = new HttpRequest;
26440 +foreach (get_class_methods('HttpRequest') as $method) {
26442 + if (strlen($method) > 3 && substr($method, 0, 3) == 'get')
26443 + $x = $r->$method();
26444 + } catch (HttpException $e) {
26453 +++ b/ext/http/tests/HttpRequest_006.phpt
26456 +HttpRequest XMLRPC
26459 +include 'skip.inc';
26460 +checkext('xmlrpc');
26461 +checkcls('HttpRequest');
26467 +$r = new HttpRequest('http://dev.iworks.at/ext-http/.print_request.php', HTTP_METH_POST);
26468 +$r->setContentType('text/xml');
26469 +$r->setBody(xmlrpc_encode_request('testMethod', array('foo' => 'bar')));
26470 +var_dump($r->send());
26471 +var_dump($r->send());
26472 +var_dump($r->send());
26478 +object(HttpMessage)#%d (%d) {
26479 + ["type:protected"]=>
26481 + ["body:protected"]=>
26482 + string(309) "string(294) "<?xml version="1.0" encoding="iso-8859-1%s]>
26484 +<methodName>testMethod</methodName>
26492 + <string>bar</string>
26502 + ["requestMethod:protected"]=>
26504 + ["requestUrl:protected"]=>
26506 + ["responseStatus:protected"]=>
26508 + ["responseCode:protected"]=>
26510 + ["httpVersion:protected"]=>
26512 + ["headers:protected"]=>
26516 + ["parentMessage:protected"]=>
26519 +object(HttpMessage)#%d (%d) {
26520 + ["type:protected"]=>
26522 + ["body:protected"]=>
26523 + string(309) "string(294) "<?xml version="1.0" encoding="iso-8859-1%s]>
26525 +<methodName>testMethod</methodName>
26533 + <string>bar</string>
26543 + ["requestMethod:protected"]=>
26545 + ["requestUrl:protected"]=>
26547 + ["responseStatus:protected"]=>
26549 + ["responseCode:protected"]=>
26551 + ["httpVersion:protected"]=>
26553 + ["headers:protected"]=>
26557 + ["parentMessage:protected"]=>
26560 +object(HttpMessage)#%d (%d) {
26561 + ["type:protected"]=>
26563 + ["body:protected"]=>
26564 + string(309) "string(294) "<?xml version="1.0" encoding="iso-8859-1%s]>
26566 +<methodName>testMethod</methodName>
26574 + <string>bar</string>
26584 + ["requestMethod:protected"]=>
26586 + ["requestUrl:protected"]=>
26588 + ["responseStatus:protected"]=>
26590 + ["responseCode:protected"]=>
26592 + ["httpVersion:protected"]=>
26594 + ["headers:protected"]=>
26598 + ["parentMessage:protected"]=>
26603 +++ b/ext/http/tests/HttpRequest_007.phpt
26609 +include 'skip.inc';
26610 +checkcls('HttpRequest');
26616 +$r = new HttpRequest('http://dev.iworks.at/ext-http/.print_put.php5', HTTP_METH_PUT);
26617 +$r->recordHistory = true;
26618 +$r->addHeaders(array('content-type' => 'text/plain'));
26619 +$r->setPutFile(__FILE__);
26621 +var_dump($r->getHistory()->toString(true));
26626 +string(%d) "PUT /ext-http/.print_put.php5 HTTP/1.1
26627 +User-Agent: PECL::HTTP/%a
26628 +Host: dev.iworks.at
26630 +Content-Type: text/plain
26631 +Content-Length: %d
26632 +Expect: 100-continue
26637 +$r = new HttpRequest('http://dev.iworks.at/ext-http/.print_put.php5', HTTP_METH_PUT);
26638 +$r->recordHistory = true;
26639 +$r->addHeaders(array('content-type' => 'text/plain'));
26640 +$r->setPutFile(__FILE__);
26642 +var_dump($r->getHistory()->toString(true));
26646 +HTTP/1.1 100 Continue
26650 +Vary: Accept-Encoding
26651 +Content-Length: %d
26652 +Content-Type: text/html
26657 +$r = new HttpRequest('http://dev.iworks.at/ext-http/.print_put.php5', HTTP_METH_PUT);
26658 +$r->recordHistory = true;
26659 +$r->addHeaders(array('content-type' => 'text/plain'));
26660 +$r->setPutFile(__FILE__);
26662 +var_dump($r->getHistory()->toString(true));
26669 +++ b/ext/http/tests/HttpRequest_008.phpt
26672 +HttpRequest custom request method
26675 +include 'skip.inc';
26676 +checkcls('HttpRequest');
26682 +HttpRequest::methodRegister('foobar');
26683 +$r = new HttpRequest('http://dev.iworks.at/ext-http/.print_request.php', HttpRequest::METH_FOOBAR);
26684 +$r->setContentType('text/plain');
26685 +$r->setBody('Yep, this is FOOBAR!');
26686 +var_dump($r->send()->getResponseCode());
26687 +var_dump($r->getRawRequestMessage());
26694 +string(%d) "FOOBAR /ext-http/.print_request.php HTTP/1.1
26696 +Host: dev.iworks.at
26698 +Content-Type: text/plain
26699 +Content-Length: 20
26701 +Yep, this is FOOBAR!"
26704 +++ b/ext/http/tests/HttpRequest_009.phpt
26707 +HttpRequest callbacks
26710 +include 'skip.inc';
26711 +checkcls('HttpRequest');
26717 +class _R extends HttpRequest
26719 + function onProgress($progress)
26721 + print_r($progress);
26724 + function onFinish()
26726 + var_dump($this->getResponseCode());
26730 +$r = new _R('http://dev.iworks.at/ext-http/.print_request.php', HTTP_METH_POST);
26731 +$r->addPostFile('upload', __FILE__, 'text/plain');
26755 +++ b/ext/http/tests/HttpRequest_010.phpt
26758 +HttpRequest cookie API
26761 +include 'skip.inc';
26762 +checkmin("5.2.5");
26763 +checkcls("HttpRequest");
26769 +$r = new HttpRequest("http://dev.iworks.at/ext-http/.cookie.php");
26772 +$c[0] = $r->getResponseInfo("cookies");
26773 +if (!empty($c[0])) {
26774 + var_dump('$c[0]', $c[0]);
26777 +var_dump($r->enableCookies());
26780 +$c[1] = $r->getResponseInfo("cookies");
26781 +if (empty($c[1])) {
26782 + var_dump('$c[1]', $c[1]);
26785 +var_dump($r->resetCookies());
26788 +$c[2] = $r->getResponseInfo("cookies");
26789 +if ($c[1] === $c[2]) {
26790 + var_dump('$c[1]', $c[1], '$c[2]', $c[2]);
26794 +$c[3] = $r->getResponseInfo("cookies");
26795 +if ($c[2] !== $c[3]) {
26796 + var_dump('$c[2]', $c[2], '$c[3]', $c[3]);
26806 +++ b/ext/http/tests/HttpResponse_001.phpt
26809 +HttpResponse - send data with caching headers
26812 +include 'skip.inc';
26813 +checkmin("5.2.5");
26818 +HttpResponse::setCache(true);
26819 +HttpResponse::setCacheControl('public', 3600);
26820 +HttpResponse::setData('foobar');
26821 +HttpResponse::send();
26824 +X-Powered-By: PHP/%a
26825 +Cache-Control: public, must-revalidate, max-age=3600
26826 +Last-Modified: %a, %d %a 20%d %d:%d:%d GMT
26828 +Accept-Ranges: bytes
26829 +ETag: "3858f62230ac3c915f300c664312c63f"
26834 +++ b/ext/http/tests/HttpResponse_002.phpt
26837 +HttpResponse - send gzipped file
26840 +include 'skip.inc';
26841 +checkmin("5.2.5");
26843 +skipif(!http_support(HTTP_SUPPORT_ENCODINGS), "need zlib support");
26846 +HTTP_ACCEPT_ENCODING=gzip
26849 +HttpResponse::setGzip(true);
26850 +HttpResponse::setFile(__FILE__);
26851 +HttpResponse::send();
26854 +X-Powered-By: PHP/%a
26856 +Accept-Ranges: bytes
26857 +Content-Encoding: gzip
26858 +Vary: Accept-Encoding
26862 +++ b/ext/http/tests/HttpResponse_003.phpt
26865 +HttpResponse - send gzipped file with caching headers
26868 +include 'skip.inc';
26869 +checkmin("5.2.5");
26871 +skipif(!http_support(HTTP_SUPPORT_ENCODINGS), "need zlib support");
26874 +HTTP_ACCEPT_ENCODING=gzip
26877 +HttpResponse::setGzip(true);
26878 +HttpResponse::setCache(true);
26879 +HttpResponse::setCacheControl('public', 3600);
26880 +HttpResponse::setFile(__FILE__);
26881 +HttpResponse::send();
26884 +X-Powered-By: PHP/%a
26885 +Cache-Control: public, must-revalidate, max-age=3600
26886 +Last-Modified: %a, %d %a 20%d %d:%d:%d GMT
26888 +Accept-Ranges: bytes
26890 +Content-Encoding: gzip
26891 +Vary: Accept-Encoding
26895 +++ b/ext/http/tests/HttpResponse_004.phpt
26898 +HttpResponse - send cached gzipped data
26901 +include 'skip.inc';
26903 +checkmin("5.2.7");
26904 +skipif(!http_support(HTTP_SUPPORT_ENCODINGS), "need zlib support");
26907 +HTTP_IF_NONE_MATCH="900150983cd24fb0d6963f7d28e17f72"
26908 +HTTP_ACCEPT_ENCODING=gzip
26911 +HttpResponse::setGzip(true);
26912 +HttpResponse::setCache(true);
26913 +HttpResponse::setCacheControl('public', 3600);
26914 +HttpResponse::setData("abc");
26915 +HttpResponse::send();
26919 +X-Powered-By: PHP/%s
26920 +Cache-Control: public, must-revalidate, max-age=3600
26922 +Accept-Ranges: bytes
26923 +ETag: "900150983cd24fb0d6963f7d28e17f72"
26925 +++ b/ext/http/tests/HttpResponse_005.phpt
26928 +HttpResponse file not found
26931 +include 'skip.inc';
26933 +checkmin("5.2.5");
26937 +ini_set("error_reporting", 0);
26938 +ini_set("default_mimetype", "text/plain");
26940 +HttpResponse::setContentType("application/pdf");
26941 +HttpResponse::setContentDisposition("doc.pdf");
26942 +HttpResponse::setFile("__nonexistant__.pdf");
26943 +HttpResponse::send();
26947 +X-Powered-By: PHP/%s
26948 +Content-Type: text/plain
26952 +++ b/ext/http/tests/allowed_methods_002.phpt
26958 +include 'skip.inc';
26960 +checkmin("5.2.5");
26964 +include 'log.inc';
26965 +log_prepare(_AMETH_LOG);
26966 +ini_set('http.request.methods.allowed', 'POST');
26971 +X-Powered-By: PHP/%a
26976 +++ b/ext/http/tests/allowed_methods_002_logging.phpt
26979 +logging allowed methods
26982 +include 'skip.inc';
26984 +checkmin("5.2.5");
26987 +HTTP_HOST=example.com
26991 +include 'log.inc';
26992 +log_content(_AMETH_LOG);
26997 +%d%d%d%d-%d%d-%d%d %d%d:%d%d:%d%d [405-ALLOWED] Allow: POST <%a>
27000 +++ b/ext/http/tests/bug_15800.phpt
27003 +Bug #15800 Double free when zval is separated in convert_to_*
27006 +include 'skip.inc';
27007 +checkmin("5.2.5");
27008 +checkcls('HttpRequest');
27009 +skipif(!function_exists('debug_zval_dump'), "need DEBUG version of PHP");
27014 +$o = array('ssl' => array('verifypeer'=>'1'));
27015 +debug_zval_dump($o);
27017 +$r = new HttpRequest('http://www.google.com');
27018 +$r->setOptions($o);
27020 +debug_zval_dump($o);
27023 +debug_zval_dump($o);
27029 +array(1) refcount(2){
27031 + array(1) refcount(1){
27033 + string(1) "1" refcount(1)
27036 +array(1) refcount(2){
27038 + array(1) refcount(1){
27040 + string(1) "1" refcount(3)
27043 +array(1) refcount(2){
27045 + array(1) refcount(1){
27047 + string(1) "1" refcount(1)
27052 +++ b/ext/http/tests/build_str_001.phpt
27058 +include 'skip.inc';
27064 +parse_str("a=b", $q);
27065 +echo http_build_str($q, null, "&"), "\n";
27067 +parse_str("a=b&c[0]=1", $q);
27068 +echo http_build_str($q, null, "&"), "\n";
27070 +parse_str("a=b&c[0]=1&d[e]=f", $q);
27071 +echo http_build_str($q, null, "&"), "\n";
27073 +echo http_build_str(array(1,2,array(3)), "foo", "&"), "\n";
27081 +a=b&c%5B0%5D=1&d%5Be%5D=f
27082 +foo%5B0%5D=1&foo%5B1%5D=2&foo%5B2%5D%5B0%5D=3
27085 +++ b/ext/http/tests/build_url_001.phpt
27088 +http_build_url() with relative paths
27091 +include 'skip.inc';
27096 +echo http_build_url('page'), "\n";
27097 +echo http_build_url('with/some/path/'), "\n";
27103 +http://%a/with/some/path/
27106 +++ b/ext/http/tests/build_url_002.phpt
27109 +http_build_url() with parse_url()
27112 +include 'skip.inc';
27117 +echo http_build_url(parse_url("http://example.org/orig?q=1#f"),
27118 + parse_url("https://www.example.com:9999/replaced#n")), "\n";
27119 +echo http_build_url(("http://example.org/orig?q=1#f"),
27120 + ("https://www.example.com:9999/replaced#n"), 0, $u), "\n";
27126 +https://www.example.com:9999/replaced?q=1#n
27127 +https://www.example.com:9999/replaced?q=1#n
27130 + [scheme] => https
27131 + [host] => www.example.com
27133 + [path] => /replaced
27139 +++ b/ext/http/tests/build_url_003.phpt
27145 +include 'skip.inc';
27146 +checkmin("5.2.5");
27149 +HTTP_HOST=www.example.com
27152 +$url = '/path/?query#anchor';
27154 +printf("-%s-\n", http_build_url($url));
27155 +printf("-%s-\n", http_build_url($url, array('scheme' => 'https')));
27156 +printf("-%s-\n", http_build_url($url, array('scheme' => 'https', 'host' => 'ssl.example.com')));
27157 +printf("-%s-\n", http_build_url($url, array('scheme' => 'ftp', 'host' => 'ftp.example.com', 'port' => 21)));
27162 +-http://www.example.com/path/?query#anchor-
27163 +-https://www.example.com/path/?query#anchor-
27164 +-https://ssl.example.com/path/?query#anchor-
27165 +-ftp://ftp.example.com/path/?query#anchor-
27168 +++ b/ext/http/tests/build_url_004.phpt
27171 +http_build_url flags
27174 +include 'skip.inc';
27179 +echo http_build_url("http://mike@www.example.com/foo/bar", "./baz", HTTP_URL_STRIP_AUTH|HTTP_URL_JOIN_PATH), "\n";
27180 +echo http_build_url("http://mike@www.example.com/foo/bar/", "../baz", HTTP_URL_STRIP_USER|HTTP_URL_JOIN_PATH), "\n";
27181 +echo http_build_url("http://mike:1234@www.example.com/foo/bar/", "./../baz", HTTP_URL_STRIP_PASS|HTTP_URL_JOIN_PATH), "\n";
27182 +echo http_build_url("http://www.example.com:8080/foo?a[0]=b#frag", "?a[0]=1&b=c&a[1]=b", HTTP_URL_JOIN_QUERY|HTTP_URL_STRIP_PORT|HTTP_URL_STRIP_FRAGMENT|HTTP_URL_STRIP_PATH), "\n";
27187 +http://www.example.com/foo/baz
27188 +http://www.example.com/foo/baz
27189 +http://mike@www.example.com/foo/baz
27190 +http://www.example.com/?a%5B0%5D=1&a%5B1%5D=b&b=c
27193 +++ b/ext/http/tests/chunked_decode_001.phpt
27196 +http_chunked_decode() "\r\n"
27199 +include 'skip.inc';
27213 +var_dump(http_chunked_decode($data));
27221 +++ b/ext/http/tests/chunked_decode_002.phpt
27224 +http_chunked_decode() "\n"
27227 +include 'skip.inc';
27241 +var_dump(http_chunked_decode($data));
27249 +++ b/ext/http/tests/chunked_decode_003.phpt
27252 +http_chunked_decode() truncated message
27255 +include 'skip.inc';
27269 +var_dump(http_chunked_decode($data));
27273 +%aWarning%ahttp_chunked_decode()%aTruncated message: chunk size 255 exceeds remaining data size 12 at pos 34 of 46 in%a
27279 +++ b/ext/http/tests/chunked_decode_004.phpt
27282 +http_chunked_decode() truncated message ending with NUL after a chunk
27285 +include 'skip.inc';
27299 +var_dump(http_chunked_decode($data));
27308 +++ b/ext/http/tests/cloning_001.phpt
27314 +include 'skip.inc';
27315 +checkmin("5.2.5");
27316 +checkcls('HttpRequest');
27322 +$r1 = new HttpRequest;
27324 +$r1->setOptions(array('redirect' => 3));
27325 +var_dump($r1->getOptions() == $r2->getOptions());
27326 +$r1->setUrl('http://www.google.com/');
27327 +var_dump($r1->getUrl() == $r2->getUrl());
27329 +var_dump($r1->getResponseInfo() == $r2->getResponseInfo());
27340 +++ b/ext/http/tests/data.txt
27342 +0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
27343 +0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
27344 +0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
27345 +0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
27346 +0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
27347 +0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
27348 +0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
27349 +0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
27350 +0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
27351 +0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
27353 +++ b/ext/http/tests/date_001.phpt
27356 +http_date() with timestamp
27359 +include 'skip.inc';
27364 +echo http_date(1), "\n";
27365 +echo http_date(1234567890), "\n";
27369 +Thu, 01 Jan 1970 00:00:01 GMT
27370 +Fri, 13 Feb 2009 23:31:30 GMT
27373 +++ b/ext/http/tests/date_002.phpt
27376 +http_date() without timestamp
27379 +include 'skip.inc';
27384 +ini_set('date.timezone', 'GMT');
27386 +$t = strtotime($d);
27388 +echo "$t\n$d\nDone\n";
27394 +%a, %d %a %d %d:%d:%d GMT
27397 +++ b/ext/http/tests/encoding_objects_001.phpt
27400 +encoding stream objects
27403 +include 'skip.inc';
27405 +skipif(!http_support(HTTP_SUPPORT_ENCODINGS), "need zlib");
27410 +$d = new HttpDeflateStream;
27411 +$i = new HttpInflateStream;
27412 +echo $i->flush($d->flush("Hi "));
27413 +echo $i->finish($d->finish("there!\n"));
27414 +echo $i->finish($d->finish("Yo...\n"));
27416 +$id = $i->update($d->update($pd = file_get_contents(__FILE__)));
27417 +foreach (glob('*.phpt') as $f) {
27418 + $id .= $i->update($d->update($tmp = file_get_contents($f)));
27421 +$id .= $i->finish($d->finish());
27423 +var_dump($id == $pd);
27435 +++ b/ext/http/tests/encodings.phpt
27441 +include 'skip.inc';
27442 +skipif(!function_exists('http_deflate'), 'need zlib');
27448 +set_time_limit(0);
27449 +error_reporting(E_ALL);
27453 +for ($i = 0; $i < 5000; ++$i) {
27454 + $s .= chr(rand(0,255));
27457 +var_dump($s == http_inflate(http_deflate($s, HTTP_DEFLATE_TYPE_ZLIB)));
27458 +var_dump($s == http_inflate(http_deflate($s, HTTP_DEFLATE_TYPE_GZIP)));
27459 +var_dump($s == http_inflate(http_deflate($s, HTTP_DEFLATE_TYPE_RAW)));
27461 +if (extension_loaded('zlib')) {
27463 + $s = "A simple test string, which won't blow up ext/zlib.\n";
27465 + ($s == http_inflate(gzencode($s))) or print "GZIP Failed\n";
27466 + ($s == http_inflate(gzdeflate($s))) or print "DEFLATE Failed\n";
27467 + ($s == http_inflate(gzcompress($s))) or print "COMPRESS Failed\n";
27469 + ($s == gzinflate(http_deflate($s, HTTP_DEFLATE_TYPE_RAW))) or print "INFLATE Failed\n";
27470 + ($s == gzuncompress(http_deflate($s, HTTP_DEFLATE_TYPE_ZLIB))) or print "UNCOMPRESS Failed\n";
27482 +++ b/ext/http/tests/etag_mode_031.phpt
27485 +crc32 etag (may fail because PHPs crc32 is actually crc32b)
27488 +include 'skip.inc';
27490 +checkmin("5.2.5");
27494 +ini_set('http.etag.mode', extension_loaded('hash')?'crc32b':'crc32');
27495 +http_cache_etag();
27496 +http_send_data("abc\n");
27499 +X-Powered-By: PHP/%a
27500 +Cache-Control: private, must-revalidate, max-age=0
27501 +Accept-Ranges: bytes
27508 +++ b/ext/http/tests/etag_mode_032.phpt
27514 +include 'skip.inc';
27516 +checkmin("5.2.5");
27520 +ini_set('http.etag.mode', 'SHA1');
27521 +http_cache_etag();
27522 +http_send_data("abc\n");
27525 +X-Powered-By: PHP/%a
27526 +Cache-Control: private, must-revalidate, max-age=0
27527 +Accept-Ranges: bytes
27528 +ETag: "03cfd743661f07975fa2f1220c5194cbaff48451"
27534 +++ b/ext/http/tests/etag_mode_033.phpt
27540 +include 'skip.inc';
27542 +checkmin("5.2.5");
27546 +ini_set('http.etag.mode', 'MD5');
27547 +http_cache_etag();
27548 +http_send_data("abc\n");
27551 +X-Powered-By: PHP/%a
27552 +Cache-Control: private, must-revalidate, max-age=0
27553 +Accept-Ranges: bytes
27554 +ETag: "0bee89b07a248e27c83fc3d5951213c1"
27560 +++ b/ext/http/tests/etag_mode_034.phpt
27566 +include 'skip.inc';
27568 +checkmin("5.2.5");
27569 +skipif(!extension_loaded('hash'), 'need ext/hash support');
27573 +ini_set('http.etag.mode', 'sha256');
27574 +http_cache_etag();
27575 +http_send_data("abc\n");
27578 +X-Powered-By: PHP/%a
27579 +Cache-Control: private, must-revalidate, max-age=0
27580 +Accept-Ranges: bytes
27581 +ETag: "edeaaff3f1774ad2888673770c6d64097e391bc362d7d6fb34982ddf0efd18cb"
27587 +++ b/ext/http/tests/etag_mode_041.phpt
27590 +ob crc32 etag (may fail because PHPs crc32 is actually crc32b)
27593 +include 'skip.inc';
27595 +checkmin("5.2.5");
27599 +ini_set('http.etag.mode', extension_loaded('hash')?'crc32b':'crc32');
27600 +http_cache_etag();
27604 +X-Powered-By: PHP/%a
27605 +Cache-Control: private, must-revalidate, max-age=0
27611 +++ b/ext/http/tests/etag_mode_042.phpt
27617 +include 'skip.inc';
27619 +checkmin("5.2.5");
27623 +ini_set('http.etag.mode', 'SHA1');
27624 +http_cache_etag();
27628 +X-Powered-By: PHP/%a
27629 +Cache-Control: private, must-revalidate, max-age=0
27630 +ETag: "03cfd743661f07975fa2f1220c5194cbaff48451"
27635 +++ b/ext/http/tests/etag_mode_043.phpt
27641 +include 'skip.inc';
27643 +checkmin("5.2.5");
27647 +ini_set('http.etag.mode', 'bogus');
27648 +http_cache_etag();
27652 +X-Powered-By: PHP/%a
27653 +Cache-Control: private, must-revalidate, max-age=0
27654 +ETag: "0bee89b07a248e27c83fc3d5951213c1"
27659 +++ b/ext/http/tests/etag_mode_044.phpt
27665 +include 'skip.inc';
27667 +checkmin("5.2.5");
27668 +skipif(!extension_loaded('hash'), 'need ext/hash support');
27672 +ini_set('http.etag.mode', 'sha256');
27673 +http_cache_etag();
27677 +X-Powered-By: PHP/%a
27678 +Cache-Control: private, must-revalidate, max-age=0
27679 +ETag: "edeaaff3f1774ad2888673770c6d64097e391bc362d7d6fb34982ddf0efd18cb"
27684 +++ b/ext/http/tests/exceptions.phpt
27690 +include 'skip.inc';
27691 +checkmin("5.2.5");
27697 +ini_set('http.only_exceptions', true);
27700 + HTTP_E_RUNTIME => 'Runtime',
27701 + HTTP_E_INVALID_PARAM => 'InvalidParam',
27702 + HTTP_E_HEADER => 'Header',
27703 + HTTP_E_MALFORMED_HEADERS => 'MalformedHeaders',
27704 + HTTP_E_REQUEST_METHOD => 'RequestMethod',
27705 + HTTP_E_MESSAGE_TYPE => 'MessageType',
27706 + HTTP_E_ENCODING => 'Encoding',
27707 + HTTP_E_REQUEST => 'Request',
27708 + HTTP_E_REQUEST_POOL => 'RequestPool',
27709 + HTTP_E_SOCKET => 'Socket',
27710 + HTTP_E_RESPONSE => 'Response',
27711 + HTTP_E_URL => 'Url',
27714 +foreach ($e as $i => $c) {
27716 + $n = "Http{$c}Exception";
27718 + } catch (HttpException $x) {
27719 + printf("%2d: %s\n", $i, get_class($x));
27726 + 1: HttpRuntimeException
27727 + 2: HttpInvalidParamException
27728 + 3: HttpHeaderException
27729 + 4: HttpMalformedHeadersException
27730 + 5: HttpRequestMethodException
27731 + 6: HttpMessageTypeException
27732 + 7: HttpEncodingException
27733 + 8: HttpRequestException
27734 + 9: HttpRequestPoolException
27735 +10: HttpSocketException
27736 +11: HttpResponseException
27737 +12: HttpUrlException
27740 +++ b/ext/http/tests/get_request_data_001.phpt
27746 +include 'skip.inc';
27754 +$_SERVER['HTTP_ACCEPT_CHARSET'] = 'iso-8859-1, *';
27755 +$_SERVER['HTTP_ACCEPT_ENCODING'] = 'none';
27756 +$_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0';
27757 +$_SERVER['HTTP_HOST'] = 'localhost';
27759 +$h = http_get_request_headers();
27762 +var_dump(http_get_request_body());
27763 +var_dump(http_get_request_body());
27764 +var_dump(http_get_request_body());
27765 +var_dump(fread(http_get_request_body_stream(), 4096));
27772 + [Accept-Charset] => iso-8859-1, *
27773 + [Accept-Encoding] => none
27774 + [Host] => localhost
27775 + [User-Agent] => Mozilla/5.0
27777 +string(7) "a=b&c=d"
27778 +string(7) "a=b&c=d"
27779 +string(7) "a=b&c=d"
27780 +string(7) "a=b&c=d"
27783 +++ b/ext/http/tests/log.inc
27786 +define('_REDIR_LOG', '__r_log');
27787 +define('_CACHE_LOG', '__c_log');
27788 +define('_AMETH_LOG', '__m_log');
27789 +define('_CMPST_LOG', '__a_log');
27791 +function log_prepare($log)
27793 + is_file($log) and @unlink($log);
27796 + case _REDIR_LOG: ini_set('http.log.redirect', _REDIR_LOG); break;
27797 + case _CACHE_LOG: ini_set('http.log.cache', _CACHE_LOG); break;
27798 + case _AMETH_LOG: ini_set('http.log.allowed_methods', _AMETH_LOG); break;
27799 + case _CMPTS_LOG: ini_set('http.log.composite', _CMPST_LOG); break;
27802 +function log_content($log)
27804 + echo file_get_contents($log);
27809 +++ b/ext/http/tests/match_request_header_001.phpt
27812 +http_match_request_header()
27815 +include 'skip.inc';
27816 +checkmin("5.2.5");
27823 +var_dump(http_match_request_header("Foo", "bar", 1));
27824 +var_dump(http_match_request_header("fOO", "BAR", 0));
27825 +var_dump(http_match_request_header("foo", "BAR", 1));
27835 +++ b/ext/http/tests/negotiation_001.phpt
27841 +include 'skip.inc';
27842 +checkmin("5.2.5");
27845 +HTTP_ACCEPT=application/xml, application/xhtml+xml, text/html ; q = .8
27846 +HTTP_ACCEPT_LANGUAGE=de-AT,de-DE;q=0.8,en-GB;q=0.3,en-US;q=0.2
27847 +HTTP_ACCEPT_CHARSET=ISO-8859-1,utf-8;q=0.7,*;q=0.7
27852 + array('de', 'en', 'es'),
27855 + array('utf-8', 'iso-8859-1'),
27858 + array('foo/bar', 'application/xhtml+xml', 'text/html')
27860 +var_dump(http_negotiate_language($langs[0]));
27861 +var_dump(http_negotiate_language($langs[0], $lresult));
27862 +var_dump(http_negotiate_charset($csets[0]));
27863 +var_dump(http_negotiate_charset($csets[0], $cresult));
27864 +var_dump(http_negotiate_content_type($ctype[0]));
27865 +var_dump(http_negotiate_content_type($ctype[0], $tresult));
27866 +var_dump(http_negotiate_language(array("unknown")));
27867 +var_dump(http_negotiate_charset(array("unknown")));
27868 +var_dump(http_negotiate_content_type(array("unknown")));
27869 +print_r($lresult);
27870 +print_r($cresult);
27871 +print_r($tresult);
27878 +string(10) "iso-8859-1"
27879 +string(10) "iso-8859-1"
27880 +string(21) "application/xhtml+xml"
27881 +string(21) "application/xhtml+xml"
27882 +string(7) "unknown"
27883 +string(7) "unknown"
27884 +string(7) "unknown"
27892 + [iso-8859-1] => 1000
27897 + [application/xhtml+xml] => 999
27898 + [text/html] => 0.8
27902 +++ b/ext/http/tests/ob_deflatehandler_001.phpt
27908 +include 'skip.inc';
27910 +checkmin("5.2.5");
27911 +skipif(!http_support(HTTP_SUPPORT_ENCODINGS), "need zlib");
27914 +HTTP_ACCEPT_ENCODING=gzip
27917 +ob_start('ob_deflatehandler');
27923 +Content-Encoding: gzip
27924 +Vary: Accept-Encoding
27928 +++ b/ext/http/tests/ob_inflatehandler_001.phpt
27934 +include 'skip.inc';
27936 +skipif(!http_support(HTTP_SUPPORT_ENCODINGS), "need zlib");
27940 +ob_start('ob_inflatehandler');
27941 +echo http_deflate("TEST\n");
27947 +++ b/ext/http/tests/parse_cookie_001.phpt
27953 +include 'skip.inc';
27959 +var_dump(http_parse_cookie('name="value"; foo="bar\"baz"; hey=got"it ; path=/ ; comment=; expires='.http_date(1).' secure ; httpOnly', 0, array("comment")));
27965 +object(stdClass)%a {
27969 + string(5) "value"
27971 + string(7) "bar"baz"
27973 + string(6) "got"it"
27991 +++ b/ext/http/tests/parse_cookie_002.phpt
27997 +include 'skip.inc';
27998 +checkmin("5.2.5");
28004 +var_dump(http_parse_cookie('foo')->cookies['foo']);
28005 +var_dump(http_parse_cookie('foo;')->cookies['foo']);
28006 +var_dump(http_parse_cookie('foo ')->cookies['foo']);
28007 +var_dump(http_parse_cookie('foo ;')->cookies['foo']);
28008 +var_dump(http_parse_cookie('foo ; ')->cookies['foo']);
28009 +var_dump(http_parse_cookie('foo=')->cookies['foo']);
28010 +var_dump(http_parse_cookie('foo=;')->cookies['foo']);
28011 +var_dump(http_parse_cookie('foo =')->cookies['foo']);
28012 +var_dump(http_parse_cookie('foo =;')->cookies['foo']);
28013 +var_dump(http_parse_cookie('foo= ')->cookies['foo']);
28014 +var_dump(http_parse_cookie('foo= ;')->cookies['foo']);
28016 +var_dump(http_parse_cookie('foo=1')->cookies['foo']);
28017 +var_dump(http_parse_cookie('foo=1;')->cookies['foo']);
28018 +var_dump(http_parse_cookie('foo=1 ;')->cookies['foo']);
28019 +var_dump(http_parse_cookie('foo= 1;')->cookies['foo']);
28020 +var_dump(http_parse_cookie('foo = 1;')->cookies['foo']);
28021 +var_dump(http_parse_cookie('foo = 1 ;')->cookies['foo']);
28022 +var_dump(http_parse_cookie('foo=1')->cookies['foo']);
28023 +var_dump(http_parse_cookie('foo= 1')->cookies['foo']);
28025 +var_dump(http_parse_cookie('foo="1"')->cookies['foo']);
28026 +var_dump(http_parse_cookie('foo="1" ')->cookies['foo']);
28027 +var_dump(http_parse_cookie('foo="1";')->cookies['foo']);
28028 +var_dump(http_parse_cookie('foo = "1" ;')->cookies['foo']);
28029 +var_dump(http_parse_cookie('foo= "1" ')->cookies['foo']);
28031 +var_dump(http_parse_cookie('foo=""')->cookies['foo']);
28032 +var_dump(http_parse_cookie('foo="\""')->cookies['foo']);
28033 +var_dump(http_parse_cookie('foo=" "')->cookies['foo']);
28034 +var_dump(http_parse_cookie('foo= "')->cookies['foo']);
28035 +var_dump(http_parse_cookie('foo=" ')->cookies['foo']);
28036 +var_dump(http_parse_cookie('foo= " ')->cookies['foo']);
28074 +++ b/ext/http/tests/parse_headers_001.phpt
28077 +http_parse_headers()
28080 +include 'skip.inc';
28085 +print_r(http_parse_headers(
28086 +"Host: localhost\r\n".
28087 +"Host: ambigious\r\n".
28088 +"Nospace:here\r\n".
28089 +"Muchspace: there \r\n".
28092 +"Folded: one\r\n".
28108 + [Nospace] => here
28109 + [Muchspace] => there
28118 +++ b/ext/http/tests/parse_message_001.phpt
28121 +http_parse_message()
28124 +include 'skip.inc';
28125 +checkurl('www.google.com');
28126 +skipif(!http_support(HTTP_SUPPORT_REQUESTS), 'need curl support');
28131 +$m = http_parse_message(http_get('http://www.google.com'));
28136 +<HTML>%aThe document has moved%a</HTML>
28139 +++ b/ext/http/tests/parse_message_002.phpt
28142 +identity encoding trap
28145 +include 'skip.inc';
28152 +"HTTP/1.1 200 Ok\n".
28153 +"Transfer-Encoding: identity\n".
28154 +"Content-Length: 3\n".
28155 +"Content-Type: text/plain\n\n".
28158 +print_r(http_parse_message($message));
28166 + [httpVersion] => 1.1
28167 + [responseCode] => 200
28168 + [responseStatus] => Ok
28169 + [headers] => Array
28171 + [Transfer-Encoding] => identity
28172 + [Content-Length] => 3
28173 + [Content-Type] => text/plain
28177 + [parentMessage] =>
28181 +++ b/ext/http/tests/parse_message_003.phpt
28184 +content range message
28187 +include 'skip.inc';
28194 +"HTTP/1.1 200 Ok\n".
28195 +"Content-Range: bytes: 0-1/5\n\n".
28198 +$msg = http_parse_message($message);
28199 +var_dump($msg->body);
28202 +"HTTP/1.1 200 Ok\n".
28203 +"Content-Range: bytes 0-1/1\n\n".
28206 +$msg = http_parse_message($message);
28212 +%a Invalid Content-Range header: bytes 0-1/1 in%a
28215 +++ b/ext/http/tests/parse_message_004.phpt
28218 +http_parse_message() recursive
28221 +include 'skip.inc';
28229 +Host: www.example.com
28233 +Content-Length: 10
28235 +Host: www.example.com
28239 +Content-Length: 10
28244 +var_dump(http_parse_message($message));
28250 +object(stdClass)%a {
28253 + ["httpVersion"]=>
28255 + ["responseCode"]=>
28257 + ["responseStatus"]=>
28262 + string(9) "Funky/1.0"
28263 + ["Content-Length"]=>
28267 + string(10) "1234567890"
28268 + ["parentMessage"]=>
28269 + object(stdClass)%a {
28272 + ["httpVersion"]=>
28274 + ["requestMethod"]=>
28281 + string(15) "www.example.com"
28287 + ["parentMessage"]=>
28288 + object(stdClass)%a {
28291 + ["httpVersion"]=>
28293 + ["responseCode"]=>
28295 + ["responseStatus"]=>
28300 + string(9) "Funky/1.0"
28301 + ["Content-Length"]=>
28306 + ["parentMessage"]=>
28307 + object(stdClass)%a {
28310 + ["httpVersion"]=>
28312 + ["requestMethod"]=>
28319 + string(15) "www.example.com"
28325 + ["parentMessage"]=>
28333 +++ b/ext/http/tests/parse_message_005.phpt
28336 +http_parse_message() content range header w/(o) =
28339 +include 'skip.inc';
28344 +print_r(http_parse_message(
28348 +Content-Range: bytes: 0-0/100
28354 +Content-Range: bytes 0-0/100
28367 + [httpVersion] => 1.1
28368 + [responseCode] => 206
28369 + [responseStatus] =>
28370 + [headers] => Array
28372 + [Server] => Funky/1.0
28373 + [Content-Range] => bytes 0-0/100
28377 + [parentMessage] => stdClass Object
28380 + [httpVersion] => 1.1
28381 + [responseCode] => 206
28382 + [responseStatus] =>
28383 + [headers] => Array
28385 + [Server] => Funky/1.0
28386 + [Content-Range] => bytes: 0-0/100
28390 + [parentMessage] =>
28396 +++ b/ext/http/tests/parse_message_006.phpt
28402 +include 'skip.inc';
28409 +"HTTP/1.1 200 Ok\n".
28410 +"Header: Value\r\n".
28411 +"Connection: close\r\n".
28415 +print_r(http_parse_message($message));
28423 + [httpVersion] => 1.1
28424 + [responseCode] => 200
28425 + [responseStatus] => Ok
28426 + [headers] => Array
28428 + [Header] => Value
28429 + [Connection] => close
28433 + [parentMessage] =>
28437 +++ b/ext/http/tests/parse_params_001.phpt
28443 +include 'skip.inc';
28448 +var_dump(http_parse_params('text/html; charset=iso-8859-1'));
28449 +var_dump(http_parse_params('text/html; charset="iso-8859-1"'));
28450 +var_dump(http_parse_params('attachment; filename="gol;got,a.ext"'));
28451 +var_dump(http_parse_params('public, must-revalidate, max-age=0'));
28452 +$p = http_parse_params('a'); var_dump($p->params[0]);
28453 +$p = http_parse_params('a=b'); var_dump($p->params[0]);
28458 +object(stdClass)%a {
28462 + string(9) "text/html"
28466 + string(10) "iso-8859-1"
28470 +object(stdClass)%a {
28474 + string(9) "text/html"
28478 + string(10) "iso-8859-1"
28482 +object(stdClass)%a {
28486 + string(10) "attachment"
28490 + string(13) "gol;got,a.ext"
28494 +object(stdClass)%a {
28498 + string(6) "public"
28500 + string(15) "must-revalidate"
28515 +++ b/ext/http/tests/persistent_handles_001.phpt
28518 +persistent handles
28521 +include 'skip.inc';
28522 +skipif(!http_support(HTTP_SUPPORT_REQUESTS), "need request support");
28523 +skipif(!function_exists('zend_thread_id'), "need ZTS build");
28526 +http.persistent.handles.limit=-1
28527 +http.persistent.handles.ident=GLOBAL
28532 +echo "No free handles!\n";
28533 +foreach (http_persistent_handles_count() as $provider => $idents) {
28534 + foreach ((array)$idents as $ident => $counts) {
28535 + if (!empty($counts["free"])) {
28536 + printf("%a, %a, %a\n", $provider, $ident, $counts["free"]);
28541 +http_get("http://www.google.com/", null, $info[]);
28543 +echo "One free request handle within GLOBAL: ";
28544 +var_dump(http_persistent_handles_count()->http_request["GLOBAL"]["free"]);
28546 +echo "Reusing request handle: ";
28547 +http_get("http://www.google.com/", null, $info[]);
28548 +var_dump($info[0]["pretransfer_time"] > 10 * $info[1]["pretransfer_time"], $info[0]["pretransfer_time"], $info[1]["pretransfer_time"]);
28550 +echo "Handles' been cleaned up:\n";
28551 +http_persistent_handles_clean();
28552 +print_r(http_persistent_handles_count());
28559 +One free request handle within GLOBAL: int(1)
28560 +Reusing request handle: bool(true)
28563 +Handles' been cleaned up:
28566 + [http_request] => Array
28568 + [GLOBAL] => Array
28576 + [http_request_datashare] => Array
28578 + [GLOBAL] => Array
28586 + [http_request_datashare_lock] => Array
28588 + [GLOBAL] => Array
28596 + [http_request_pool] => Array
28598 + [GLOBAL] => Array
28609 +++ b/ext/http/tests/persistent_handles_002.phpt
28612 +persistent handles
28615 +include 'skip.inc';
28616 +checkmin("5.2.5");
28617 +skipif(!http_support(HTTP_SUPPORT_REQUESTS), "need request support");
28618 +skipif(function_exists('zend_thread_id'), "need non-ZTS build");
28621 +http.persistent.handles.limit=-1
28622 +http.persistent.handles.ident=GLOBAL
28627 +echo "No free handles!\n";
28628 +foreach (http_persistent_handles_count() as $provider => $idents) {
28629 + foreach ((array)$idents as $ident => $counts) {
28630 + if (!empty($counts["free"])) {
28631 + printf("%a, %a, %a\n", $provider, $ident, $counts["free"]);
28636 +http_get("http://www.google.com/", null, $info[]);
28638 +echo "One free request handle within GLOBAL: ";
28639 +$h = http_persistent_handles_count();
28640 +var_dump($h->http_request["GLOBAL"]["free"]);
28642 +echo "Reusing request handle: ";
28643 +http_get("http://www.google.com/", null, $info[]);
28644 +var_dump($info[0]["pretransfer_time"] > 10 * $info[1]["pretransfer_time"], $info[0]["pretransfer_time"], $info[1]["pretransfer_time"]);
28646 +echo "Handles' been cleaned up:\n";
28647 +http_persistent_handles_clean();
28648 +print_r(http_persistent_handles_count());
28655 +One free request handle within GLOBAL: int(1)
28656 +Reusing request handle: bool(true)
28659 +Handles' been cleaned up:
28662 + [http_request] => Array
28664 + [GLOBAL] => Array
28672 + [http_request_datashare] => Array
28674 + [GLOBAL] => Array
28682 + [http_request_pool] => Array
28684 + [GLOBAL] => Array
28695 +++ b/ext/http/tests/persistent_handles_003.phpt
28698 +persistent handles
28701 +include 'skip.inc';
28703 +skipif(!http_support(HTTP_SUPPORT_REQUESTS), "need request support");
28706 +http.persistent.handles.limit=-1
28707 +http.persistent.handles.ident=GLOBAL
28712 +echo "No free handles!\n";
28713 +foreach (http_persistent_handles_count() as $provider => $idents) {
28714 + foreach ((array)$idents as $ident => $counts) {
28715 + if (!empty($counts["free"])) {
28716 + printf("%a, %a, %a\n", $provider, $ident, $counts["free"]);
28721 +http_get("http://www.google.com/", null, $info[]);
28723 +echo "One free request handle within GLOBAL: ";
28724 +$h = http_persistent_handles_count();
28725 +var_dump($h->http_request["GLOBAL"]["free"]);
28727 +echo "Reusing request handle: ";
28728 +http_get("http://www.google.com/", null, $info[]);
28729 +var_dump($info[0]["pretransfer_time"] > 10 * $info[1]["pretransfer_time"], $info[0]["pretransfer_time"], $info[1]["pretransfer_time"]);
28731 +echo "Handles' been cleaned up:\n";
28732 +http_persistent_handles_clean();
28733 +print_r(http_persistent_handles_count());
28740 +One free request handle within GLOBAL: int(1)
28741 +Reusing request handle: bool(true)
28744 +Handles' been cleaned up:
28747 + [http_request] => Array
28749 + [GLOBAL] => Array
28760 +++ b/ext/http/tests/redirect_011.phpt
28763 +http_redirect() with params
28766 +include 'skip.inc';
28768 +checkmin("5.2.5");
28771 +HTTP_HOST=localhost
28774 +include 'log.inc';
28775 +log_prepare(_REDIR_LOG);
28776 +http_redirect('redirect', array('a' => 1, 'b' => 2));
28780 +X-Powered-By: PHP/%a
28781 +Location: http://localhost/redirect?a=1&b=2
28784 +Redirecting to <a href="http://localhost/redirect?a=1&b=2">http://localhost/redirect?a=1&b=2</a>.
28787 +++ b/ext/http/tests/redirect_011_logging.phpt
28793 +include 'skip.inc';
28795 +checkmin("5.2.5");
28798 +HTTP_HOST=example.com
28802 +include 'log.inc';
28803 +log_content(_REDIR_LOG);
28808 +%d%d%d%d-%d%d-%d%d %d%d:%d%d:%d%d [302-REDIRECT] Location: http%a <%a>
28811 +++ b/ext/http/tests/redirect_012.phpt
28814 +http_redirect() with session
28817 +include 'skip.inc';
28819 +checkmin("5.2.5");
28820 +checkext('session');
28823 +HTTP_HOST=localhost
28826 +include 'log.inc';
28827 +log_prepare(_REDIR_LOG);
28829 +http_redirect('redirect', array('a' => 1), true);
28833 +X-Powered-By: PHP/%a
28834 +Set-Cookie: PHPSESSID=%a; path=/
28838 +Location: http://localhost/redirect?a=1&PHPSESSID=%a
28841 +++ b/ext/http/tests/redirect_012_logging.phpt
28847 +include 'skip.inc';
28849 +checkmin("5.2.5");
28850 +checkext("session");
28853 +HTTP_HOST=example.com
28857 +include 'log.inc';
28858 +log_content(_REDIR_LOG);
28863 +%d%d%d%d-%d%d-%d%d %d%d:%d%d:%d%d [302-REDIRECT] Location: http%a <%a>
28866 +++ b/ext/http/tests/redirect_013.phpt
28869 +http_redirect() permanent
28872 +include 'skip.inc';
28874 +checkmin("5.2.5");
28877 +HTTP_HOST=localhost
28880 +include 'log.inc';
28881 +log_prepare(_REDIR_LOG);
28882 +http_redirect('redirect', null, false, HTTP_REDIRECT_PERM);
28886 +X-Powered-By: PHP/%a
28887 +Location: http://localhost/redirect
28890 +Redirecting to <a href="http://localhost/redirect">http://localhost/redirect</a>.
28893 +++ b/ext/http/tests/redirect_013_logging.phpt
28899 +include 'skip.inc';
28901 +checkmin("5.2.5");
28904 +HTTP_HOST=example.com
28908 +include 'log.inc';
28909 +log_content(_REDIR_LOG);
28914 +%d%d%d%d-%d%d-%d%d %d%d:%d%d:%d%d [301-REDIRECT] Location: http%a <%a>
28917 +++ b/ext/http/tests/request_cookies.phpt
28920 +urlencoded cookies
28923 +include 'skip.inc';
28925 +skipif(!http_support(HTTP_SUPPORT_REQUESTS), "need request support");
28931 +$cookies = array("name" => "val=ue");
28933 +$r = new HttpRequest("http://dev.iworks.at/ext-http/.print_request.php", HTTP_METH_GET, array("cookies" => $cookies));
28934 +$r->recordHistory = true;
28936 +$r->setOptions(array('encodecookies' => false));
28938 +echo $r->getHistory()->toString(true);
28944 +GET /ext-http/.print_request.php HTTP/1.1
28946 +Host: dev.iworks.at
28948 +Cookie: name=val%3Due
28957 +GET /ext-http/.print_request.php HTTP/1.1
28959 +Host: dev.iworks.at
28961 +Cookie: name=val=ue;
28972 +++ b/ext/http/tests/request_etag.phpt
28978 +include 'skip.inc';
28979 +skipif(!http_support(HTTP_SUPPORT_REQUESTS), "need request support");
28984 +var_dump(http_get("http://dev.iworks.at/ext-http/etag", array("etag" => '"26ad3a-5-95eb19c0"')));
28989 +string(%d) "HTTP/1.1 304 Not Modified
28992 +ETag: "26ad3a-5-95eb19c0"
28995 \ No newline at end of file
28997 +++ b/ext/http/tests/request_gzip.phpt
29003 +include 'skip.inc';
29004 +checkurl('dev.iworks.at');
29005 +skipif(!http_support(HTTP_SUPPORT_REQUESTS), 'need curl support');
29011 +var_dump(http_parse_message(http_get('http://dev.iworks.at/ext-http/.print_request.php?gzip=1', array('compress' => true))));
29016 +object(stdClass)%a {
29019 + ["httpVersion"]=>
29021 + ["responseCode"]=>
29023 + ["responseStatus"]=>
29029 + string(15) "Accept-Encoding"
29030 + ["Content-Length"]=>
29032 + ["Content-Type"]=>
29033 + string(9) "text/html"
29034 + ["X-Original-Content-Encoding"]=>
29036 + ["X-Original-Content-Length"]=>
29040 + string(26) "Array
29045 + ["parentMessage"]=>
29051 +++ b/ext/http/tests/request_methods.phpt
29057 +include 'skip.inc';
29063 +for ($i = 0; $i <= HTTP_METH_ACL+1; ++$i) {
29064 + var_dump(http_request_method_exists($i));
29065 + echo $name = http_request_method_name($i), "\n";
29066 + var_dump(http_request_method_exists($name));
29069 +for ($i = 0; $i < 5; ++$i) {
29070 + $n = http_request_method_register("M$i");
29071 + var_dump(http_request_method_exists($n));
29072 + var_dump(http_request_method_exists("M$i"));
29074 +for ($i = 0; $i < 5; ++$i) {
29075 + var_dump(http_request_method_unregister("M$i"));
29076 + var_dump(http_request_method_exists("M$i"));
29077 + var_dump(http_request_method_exists($i+HTTP_METH_ACL+1));
29198 +++ b/ext/http/tests/request_put_data.phpt
29204 +include 'skip.inc';
29205 +skipif(!http_support(HTTP_SUPPORT_REQUESTS), "need request support");
29211 +$data = str_repeat("abc", 6000/* > CURLBUF_SIZE */);
29212 +$resp = http_put_data("http://dev.iworks.at/ext-http/.print_put.php5", $data);
29213 +$mess = http_parse_message($resp);
29214 +var_dump($data === $mess->body);
29223 +++ b/ext/http/tests/send_data_001.phpt
29226 +http_send_data() NIL-NUM range
29229 +include 'skip.inc';
29231 +checkmin("5.2.5");
29234 +HTTP_RANGE=bytes=-5
29237 +http_send_content_type('text/plain');
29238 +http_send_data(str_repeat('123abc', 1000));
29242 +X-Powered-By: PHP/%s
29243 +Content-Type: text/plain
29244 +Accept-Ranges: bytes
29245 +Content-Range: bytes 5995-5999/6000
29250 +++ b/ext/http/tests/send_data_002.phpt
29253 +http_send_data() NUM-NUM range
29256 +include 'skip.inc';
29258 +checkmin("5.2.5");
29261 +HTTP_RANGE=bytes=5-6
29264 +http_send_content_type('text/plain');
29265 +http_send_data(str_repeat('123abc', 1000));
29269 +X-Powered-By: PHP/%s
29270 +Content-Type: text/plain
29271 +Accept-Ranges: bytes
29272 +Content-Range: bytes 5-6/6000
29277 +++ b/ext/http/tests/send_data_003.phpt
29280 +http_send_data() NUM-NIL range
29283 +include 'skip.inc';
29285 +checkmin("5.2.5");
29288 +HTTP_RANGE=bytes=5981-
29291 +http_send_content_type('text/plain');
29292 +http_send_data(str_repeat('123abc', 1000));
29296 +X-Powered-By: PHP/%s
29297 +Content-Type: text/plain
29298 +Accept-Ranges: bytes
29299 +Content-Range: bytes 5981-5999/6000
29300 +Content-Length: 19
29302 +c123abc123abc123abc
29304 +++ b/ext/http/tests/send_data_004.phpt
29307 +http_send_data() syntactically invalid range
29310 +include 'skip.inc';
29315 +HTTP_RANGE=bytes=123,-wtf ?
29318 +http_send_content_type('text/plain');
29319 +http_send_data(str_repeat('123abc', 1000));
29322 +X-Powered-By: PHP/%s
29323 +Content-Type: text/plain
29324 +Accept-Ranges: bytes
29325 +Content-Length: 6000
29327 +123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc
29328 \ No newline at end of file
29330 +++ b/ext/http/tests/send_data_005.phpt
29333 +http_send_data() oversized range
29336 +include 'skip.inc';
29338 +checkmin("5.2.5");
29341 +HTTP_RANGE=bytes=5990-6000
29344 +http_send_content_type('text/plain');
29345 +http_send_data(str_repeat('123abc', 1000));
29349 \ No newline at end of file
29351 +++ b/ext/http/tests/send_data_006.phpt
29354 +http_send_data() multiple ranges
29357 +include 'skip.inc';
29359 +checkmin("5.2.5");
29362 +HTTP_RANGE=bytes=0-3, 4-5,9-11
29365 +http_send_content_type('text/plain');
29366 +http_send_data(str_repeat('123abc', 1000));
29370 +X-Powered-By: PHP/%s
29371 +Accept-Ranges: bytes
29372 +Content-Type: multipart/byteranges; boundary=%d.%d
29376 +Content-Type: text/plain
29377 +Content-Range: bytes 0-3/6000
29381 +Content-Type: text/plain
29382 +Content-Range: bytes 4-5/6000
29386 +Content-Type: text/plain
29387 +Content-Range: bytes 9-11/6000
29392 +++ b/ext/http/tests/send_data_010.phpt
29395 +http_send_data() HTTP_SENDBUF_SIZE long string
29398 +include 'skip.inc';
29404 +http_throttle(0.01, 1);
29405 +http_send_data('00000000000000000000');
29408 +X-Powered-By: PHP/%s
29409 +Accept-Ranges: bytes
29410 +Content-Length: 20
29413 +00000000000000000000
29415 +++ b/ext/http/tests/send_data_011.phpt
29418 +http_send_data() last modified caching
29421 +include 'skip.inc';
29427 +http_cache_last_modified(-5);
29428 +http_send_data("abc\n");
29431 +X-Powered-By: PHP/%s
29432 +Cache-Control: private, must-revalidate, max-age=0
29433 +Last-Modified: %s, %d %s %d %d:%d:%d GMT
29434 +Accept-Ranges: bytes
29440 +++ b/ext/http/tests/send_failed_precond_001.phpt
29443 +http_send() failed precondition
29446 +include 'skip.inc';
29451 +HTTP_RANGE=bytes=0-1
29452 +HTTP_IF_UNMODIFIED_SINCE=Thu, 01 Jan 1970 00:16:40 GMT
29455 +http_cache_last_modified();
29456 +http_send_file(__FILE__);
29461 +Cache-Control: private, must-revalidate, max-age=0
29463 +Accept-Ranges: bytes
29464 +Content-type: text/html
29466 +++ b/ext/http/tests/send_file_005.phpt
29469 +http_send_file() multiple ranges
29472 +include 'skip.inc';
29474 +checkmin("5.2.5");
29477 +HTTP_RANGE=bytes=0-3, 4-5,9-11
29480 +http_send_content_type('text/plain');
29481 +http_send_file('data.txt');
29485 +X-Powered-By: PHP/%s
29486 +Accept-Ranges: bytes
29487 +Content-Type: multipart/byteranges; boundary=%d.%d
29491 +Content-Type: text/plain
29492 +Content-Range: bytes 0-3/1010
29496 +Content-Type: text/plain
29497 +Content-Range: bytes 4-5/1010
29501 +Content-Type: text/plain
29502 +Content-Range: bytes 9-11/1010
29507 +++ b/ext/http/tests/send_file_008.phpt
29513 +include 'skip.inc';
29519 +http_send_file('data.txt');
29522 +X-Powered-By: PHP/%s
29523 +Accept-Ranges: bytes
29524 +Content-Length: 1010
29527 +0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
29528 +0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
29529 +0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
29530 +0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
29531 +0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
29532 +0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
29533 +0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
29534 +0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
29535 +0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
29536 +0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
29538 +++ b/ext/http/tests/send_file_009.phpt
29541 +http_send_file() NUM-NUM range
29544 +include 'skip.inc';
29546 +checkmin("5.2.5");
29549 +HTTP_RANGE=bytes=5-9
29552 +http_send_file('data.txt');
29556 +X-Powered-By: PHP/%s
29557 +Accept-Ranges: bytes
29558 +Content-Range: bytes 5-9/1010
29564 +++ b/ext/http/tests/send_file_010.phpt
29567 +http_send_file() NIL-NUM range
29570 +include 'skip.inc';
29572 +checkmin("5.2.5");
29575 +HTTP_RANGE=bytes=-9
29578 +http_send_file('data.txt');
29582 +X-Powered-By: PHP/%s
29583 +Accept-Ranges: bytes
29584 +Content-Range: bytes 1001-1009/1010
29590 +++ b/ext/http/tests/send_file_011.phpt
29593 +http_send_file() NUM-NIL range
29596 +include 'skip.inc';
29598 +checkmin("5.2.5");
29601 +HTTP_RANGE=bytes=1000-
29604 +http_send_file('data.txt');
29608 +X-Powered-By: PHP/%s
29609 +Accept-Ranges: bytes
29610 +Content-Range: bytes 1000-1009/1010
29611 +Content-Length: 10
29616 +++ b/ext/http/tests/send_file_012.phpt
29619 +http_send_file() syntactically invalid range
29622 +include 'skip.inc';
29627 +HTTP_RANGE=bytes=xxx
29630 +http_send_file('data.txt');
29633 +X-Powered-By: PHP/%s
29634 +Accept-Ranges: bytes
29635 +Content-Length: 1010
29638 +0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
29639 +0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
29640 +0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
29641 +0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
29642 +0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
29643 +0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
29644 +0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
29645 +0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
29646 +0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
29647 +0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
29649 +++ b/ext/http/tests/send_file_013.phpt
29652 +http_send_file() oversized range
29655 +include 'skip.inc';
29657 +checkmin("5.2.5");
29660 +HTTP_RANGE=bytes=-1111
29663 +http_send_file('data.txt');
29667 +X-Powered-By: PHP/%s
29668 +Accept-Ranges: bytes
29671 +++ b/ext/http/tests/send_ifrange_001.phpt
29674 +http_send() If-Range
29677 +include 'skip.inc';
29679 +checkmin("5.2.5");
29682 +HTTP_RANGE=bytes=0-1
29683 +HTTP_IF_RANGE="abc"
29686 +http_cache_etag('abc');
29687 +http_send_file(__FILE__);
29692 +Cache-Control: private, must-revalidate, max-age=0
29694 +Accept-Ranges: bytes
29695 +Content-Range: bytes 0-1/%d
29697 +Content-type: text/html
29701 +++ b/ext/http/tests/send_ifrange_003.phpt
29704 +http_send() If-Range
29707 +include 'skip.inc';
29709 +checkmin("5.2.5");
29712 +HTTP_RANGE=bytes=0-1
29713 +HTTP_IF_RANGE="abcd"
29716 +http_cache_etag('abc');
29717 +http_send_file(__FILE__);
29721 +Cache-Control: private, must-revalidate, max-age=0
29723 +Accept-Ranges: bytes
29724 +Content-Length: %d
29725 +Content-type: text/html
29729 +++ b/ext/http/tests/skip.inc
29732 +defined('STDOUT') or define('STDOUT', fopen('php://stdout', 'w'));
29733 +if (!function_exists('fprintf')) {
29734 + function fprintf(){ $a=func_get_args(); $s=array_shift($a); return fwrite($s, call_user_func_array('sprintf',$a)); }
29736 +function skipif($if, $skip) { if ($if) { fprintf(STDOUT, "skip $skip"); exit(); }}
29737 +function checkcgi() { skipif(!strncasecmp('CLI', PHP_SAPI, 3), 'need CGI SAPI'); }
29738 +function checkext($ext) { skipif(!extension_loaded($ext), "need ext/$ext"); }
29739 +function checkmin($ver) { skipif(version_compare(PHP_VERSION, $ver) < 0, sprintf("need PHP >= v%s",$ver)); }
29740 +function checkmax($ver) { skipif(version_compare(PHP_VERSION, $ver) > 0, sprintf("need PHP <= v%s",$ver)); }
29741 +function checkurl($url) { skipif(!@fsockopen($url, 80), "$url not responsive"); }
29742 +function checkcls($cls) { skipif(!class_exists($cls), "need class $cls"); }
29743 +function checkver($ver) { checkmin($ver); }
29747 +++ b/ext/http/tests/stream_filters_001.phpt
29753 +include 'skip.inc';
29754 +checkmin("5.2.5");
29760 +define('F', 'http.test_stream_filters');
29762 +$f = fopen(F, 'w');
29763 +stream_filter_append($f, 'http.chunked_encode');
29765 +fwrite($f, "Here ");
29767 +fwrite($f, " go!\n");
29770 +var_dump(file_get_contents(F));
29772 +$f = fopen(F, 'r');
29773 +stream_filter_append($f, 'http.chunked_decode');
29774 +var_dump(fread($f, 256));
29791 +string(12) "Here we go!
29795 +++ b/ext/http/tests/stream_filters_002.phpt
29798 +gzip stream filters
29801 +include 'skip.inc';
29803 +skipif(!http_support(HTTP_SUPPORT_ENCODINGS), "need zlib support");
29810 +$d = file_get_contents(__FILE__);
29811 +$n = tempnam(dirname(__FILE__), 'hsf');
29813 +$f = fopen($n, 'wb');
29814 +stream_filter_append($f, 'http.deflate', STREAM_FILTER_WRITE, HTTP_DEFLATE_TYPE_GZIP);
29819 +var_dump($d.$d == http_inflate(file_get_contents($n)));
29821 +$f = fopen($n, 'wb');
29822 +stream_filter_append($f, 'http.deflate', STREAM_FILTER_WRITE);
29827 +var_dump($d.$d == http_inflate(file_get_contents($n)));
29829 +$f = fopen($n, 'wb');
29830 +stream_filter_append($f, 'http.deflate', STREAM_FILTER_WRITE, HTTP_DEFLATE_TYPE_RAW);
29835 +var_dump($d.$d == http_inflate(file_get_contents($n)));
29848 +++ b/ext/http/tests/stream_filters_003.phpt
29854 +include 'skip.inc';
29855 +checkmin("5.2.5");
29856 +skipif(!http_support(HTTP_SUPPORT_ENCODINGS), "need zlib");
29862 +define('OUT', fopen('php://output', 'w'));
29864 +stream_filter_append(OUT, 'http.chunked_encode');
29865 +stream_filter_append(OUT, 'http.deflate');
29866 +stream_filter_append(OUT, 'http.chunked_encode');
29867 +stream_filter_append(OUT, 'http.deflate');
29868 +stream_filter_append(OUT, 'http.inflate');
29869 +stream_filter_append(OUT, 'http.chunked_decode');
29870 +stream_filter_append(OUT, 'http.inflate');
29871 +stream_filter_append(OUT, 'http.chunked_decode');
29873 +$text = <<<SOME_TEXT
29874 +This is some stream filter fun; we'll see if it bails out or not.
29875 +The text should come out at the other end of the stream exactly like written to it.
29880 +foreach (str_split($text, 5) as $part) {
29881 + fwrite(OUT, $part);
29882 + if (rand(0, 1)) {
29889 +This is some stream filter fun; we'll see if it bails out or not.
29890 +The text should come out at the other end of the stream exactly like written to it.
29893 +++ b/ext/http/tests/urls.txt
29895 +http://www.microsoft.com
29896 +http://www.opensource.org
29897 +http://www.google.com
29898 +http://www.yahoo.com
29899 +http://www.ibm.com
29900 +http://www.mysql.com
29901 +http://www.oracle.com
29902 +http://www.ripe.net
29903 +http://www.iana.org
29904 +http://www.amazon.com
29905 +http://www.netcraft.com
29906 +http://www.heise.de
29907 +http://www.chip.de
29909 +http://www.cnet.com
29910 +http://www.news.com
29911 +http://www.cnn.com
29912 +http://www.wikipedia.org
29913 +http://www.dell.com
29915 +http://www.cert.org
29916 +http://www.mit.edu
29917 +http://www.nist.gov
29918 +http://www.ebay.com
29919 +http://www.playstation.com
29920 +http://www.uefa.com
29921 +http://www.ieee.org
29922 +http://www.apple.com
29923 +http://www.sony.com
29924 +http://www.symantec.com
29925 +http://www.zdnet.com
29926 +http://www.fujitsu.com
29927 +http://www.supermicro.com
29928 +http://www.hotmail.com
29929 +http://www.ecma.com
29930 +http://www.bbc.co.uk
29931 +http://news.google.com
29932 +http://www.foxnews.com
29933 +http://www.msn.com
29934 +http://www.wired.com
29935 +http://www.sky.com
29936 +http://www.usatoday.com
29937 +http://www.cbs.com
29938 +http://www.nbc.com
29939 +http://slashdot.org
29940 +http://www.bloglines.com
29941 +http://www.techweb.com
29942 +http://www.newslink.org
29944 \ No newline at end of file